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_Pragma_Enabled (N);
1723 Set_SCO_Pragma_Enabled (Loc);
1726 -- If we are within an inlined body, the legality of the pragma
1727 -- has been checked already.
1729 if In_Inlined_Body then
1734 -- Search prior declarations
1737 while Present (Prev (P)) loop
1740 -- If the previous node is a generic subprogram, do not go to to
1741 -- the original node, which is the unanalyzed tree: we need to
1742 -- attach the pre/postconditions to the analyzed version at this
1743 -- point. They get propagated to the original tree when analyzing
1744 -- the corresponding body.
1746 if Nkind (P) not in N_Generic_Declaration then
1747 PO := Original_Node (P);
1752 -- Skip past prior pragma
1754 if Nkind (PO) = N_Pragma then
1757 -- Skip stuff not coming from source
1759 elsif not Comes_From_Source (PO) then
1761 -- The condition may apply to a subprogram instantiation
1763 if Nkind (PO) = N_Subprogram_Declaration
1764 and then Present (Generic_Parent (Specification (PO)))
1769 -- For all other cases of non source code, do nothing
1775 -- Only remaining possibility is subprogram declaration
1783 -- If we fall through loop, pragma is at start of list, so see if it
1784 -- is at the start of declarations of a subprogram body.
1786 if Nkind (Parent (N)) = N_Subprogram_Body
1787 and then List_Containing (N) = Declarations (Parent (N))
1789 if Operating_Mode /= Generate_Code
1790 or else Inside_A_Generic
1792 -- Analyze pragma expression for correctness and for ASIS use
1794 Preanalyze_Spec_Expression
1795 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1801 -- See if it is in the pragmas after a library level subprogram
1803 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1804 Chain_PPC (Unit (Parent (Parent (N))));
1808 -- If we fall through, pragma was misplaced
1811 end Check_Precondition_Postcondition;
1813 -----------------------------
1814 -- Check_Static_Constraint --
1815 -----------------------------
1817 -- Note: for convenience in writing this procedure, in addition to
1818 -- the officially (i.e. by spec) allowed argument which is always a
1819 -- constraint, it also allows ranges and discriminant associations.
1820 -- Above is not clear ???
1822 procedure Check_Static_Constraint (Constr : Node_Id) is
1824 procedure Require_Static (E : Node_Id);
1825 -- Require given expression to be static expression
1827 --------------------
1828 -- Require_Static --
1829 --------------------
1831 procedure Require_Static (E : Node_Id) is
1833 if not Is_OK_Static_Expression (E) then
1834 Flag_Non_Static_Expr
1835 ("non-static constraint not allowed in Unchecked_Union!", E);
1840 -- Start of processing for Check_Static_Constraint
1843 case Nkind (Constr) is
1844 when N_Discriminant_Association =>
1845 Require_Static (Expression (Constr));
1848 Require_Static (Low_Bound (Constr));
1849 Require_Static (High_Bound (Constr));
1851 when N_Attribute_Reference =>
1852 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1853 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1855 when N_Range_Constraint =>
1856 Check_Static_Constraint (Range_Expression (Constr));
1858 when N_Index_Or_Discriminant_Constraint =>
1862 IDC := First (Constraints (Constr));
1863 while Present (IDC) loop
1864 Check_Static_Constraint (IDC);
1872 end Check_Static_Constraint;
1874 --------------------------------------
1875 -- Check_Valid_Configuration_Pragma --
1876 --------------------------------------
1878 -- A configuration pragma must appear in the context clause of a
1879 -- compilation unit, and only other pragmas may precede it. Note that
1880 -- the test also allows use in a configuration pragma file.
1882 procedure Check_Valid_Configuration_Pragma is
1884 if not Is_Configuration_Pragma then
1885 Error_Pragma ("incorrect placement for configuration pragma%");
1887 end Check_Valid_Configuration_Pragma;
1889 -------------------------------------
1890 -- Check_Valid_Library_Unit_Pragma --
1891 -------------------------------------
1893 procedure Check_Valid_Library_Unit_Pragma is
1895 Parent_Node : Node_Id;
1896 Unit_Name : Entity_Id;
1897 Unit_Kind : Node_Kind;
1898 Unit_Node : Node_Id;
1899 Sindex : Source_File_Index;
1902 if not Is_List_Member (N) then
1906 Plist := List_Containing (N);
1907 Parent_Node := Parent (Plist);
1909 if Parent_Node = Empty then
1912 -- Case of pragma appearing after a compilation unit. In this case
1913 -- it must have an argument with the corresponding name and must
1914 -- be part of the following pragmas of its parent.
1916 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1917 if Plist /= Pragmas_After (Parent_Node) then
1920 elsif Arg_Count = 0 then
1922 ("argument required if outside compilation unit");
1925 Check_No_Identifiers;
1926 Check_Arg_Count (1);
1927 Unit_Node := Unit (Parent (Parent_Node));
1928 Unit_Kind := Nkind (Unit_Node);
1930 Analyze (Get_Pragma_Arg (Arg1));
1932 if Unit_Kind = N_Generic_Subprogram_Declaration
1933 or else Unit_Kind = N_Subprogram_Declaration
1935 Unit_Name := Defining_Entity (Unit_Node);
1937 elsif Unit_Kind in N_Generic_Instantiation then
1938 Unit_Name := Defining_Entity (Unit_Node);
1941 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1944 if Chars (Unit_Name) /=
1945 Chars (Entity (Get_Pragma_Arg (Arg1)))
1948 ("pragma% argument is not current unit name", Arg1);
1951 if Ekind (Unit_Name) = E_Package
1952 and then Present (Renamed_Entity (Unit_Name))
1954 Error_Pragma ("pragma% not allowed for renamed package");
1958 -- Pragma appears other than after a compilation unit
1961 -- Here we check for the generic instantiation case and also
1962 -- for the case of processing a generic formal package. We
1963 -- detect these cases by noting that the Sloc on the node
1964 -- does not belong to the current compilation unit.
1966 Sindex := Source_Index (Current_Sem_Unit);
1968 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1969 Rewrite (N, Make_Null_Statement (Loc));
1972 -- If before first declaration, the pragma applies to the
1973 -- enclosing unit, and the name if present must be this name.
1975 elsif Is_Before_First_Decl (N, Plist) then
1976 Unit_Node := Unit_Declaration_Node (Current_Scope);
1977 Unit_Kind := Nkind (Unit_Node);
1979 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1982 elsif Unit_Kind = N_Subprogram_Body
1983 and then not Acts_As_Spec (Unit_Node)
1987 elsif Nkind (Parent_Node) = N_Package_Body then
1990 elsif Nkind (Parent_Node) = N_Package_Specification
1991 and then Plist = Private_Declarations (Parent_Node)
1995 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1996 or else Nkind (Parent_Node) =
1997 N_Generic_Subprogram_Declaration)
1998 and then Plist = Generic_Formal_Declarations (Parent_Node)
2002 elsif Arg_Count > 0 then
2003 Analyze (Get_Pragma_Arg (Arg1));
2005 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2007 ("name in pragma% must be enclosing unit", Arg1);
2010 -- It is legal to have no argument in this context
2016 -- Error if not before first declaration. This is because a
2017 -- library unit pragma argument must be the name of a library
2018 -- unit (RM 10.1.5(7)), but the only names permitted in this
2019 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2020 -- generic subprogram declarations or generic instantiations.
2024 ("pragma% misplaced, must be before first declaration");
2028 end Check_Valid_Library_Unit_Pragma;
2034 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2035 Clist : constant Node_Id := Component_List (Variant);
2039 if not Is_Non_Empty_List (Component_Items (Clist)) then
2041 ("Unchecked_Union may not have empty component list",
2046 Comp := First (Component_Items (Clist));
2047 while Present (Comp) loop
2048 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2057 procedure Error_Pragma (Msg : String) is
2058 MsgF : String := Msg;
2060 Error_Msg_Name_1 := Pname;
2062 Error_Msg_N (MsgF, N);
2066 ----------------------
2067 -- Error_Pragma_Arg --
2068 ----------------------
2070 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2071 MsgF : String := Msg;
2073 Error_Msg_Name_1 := Pname;
2075 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2077 end Error_Pragma_Arg;
2079 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2080 MsgF : String := Msg1;
2082 Error_Msg_Name_1 := Pname;
2084 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2085 Error_Pragma_Arg (Msg2, Arg);
2086 end Error_Pragma_Arg;
2088 ----------------------------
2089 -- Error_Pragma_Arg_Ident --
2090 ----------------------------
2092 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2093 MsgF : String := Msg;
2095 Error_Msg_Name_1 := Pname;
2097 Error_Msg_N (MsgF, Arg);
2099 end Error_Pragma_Arg_Ident;
2101 ----------------------
2102 -- Error_Pragma_Ref --
2103 ----------------------
2105 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2106 MsgF : String := Msg;
2108 Error_Msg_Name_1 := Pname;
2110 Error_Msg_Sloc := Sloc (Ref);
2111 Error_Msg_NE (MsgF, N, Ref);
2113 end Error_Pragma_Ref;
2115 ------------------------
2116 -- Find_Lib_Unit_Name --
2117 ------------------------
2119 function Find_Lib_Unit_Name return Entity_Id is
2121 -- Return inner compilation unit entity, for case of nested
2122 -- categorization pragmas. This happens in generic unit.
2124 if Nkind (Parent (N)) = N_Package_Specification
2125 and then Defining_Entity (Parent (N)) /= Current_Scope
2127 return Defining_Entity (Parent (N));
2129 return Current_Scope;
2131 end Find_Lib_Unit_Name;
2133 ----------------------------
2134 -- Find_Program_Unit_Name --
2135 ----------------------------
2137 procedure Find_Program_Unit_Name (Id : Node_Id) is
2138 Unit_Name : Entity_Id;
2139 Unit_Kind : Node_Kind;
2140 P : constant Node_Id := Parent (N);
2143 if Nkind (P) = N_Compilation_Unit then
2144 Unit_Kind := Nkind (Unit (P));
2146 if Unit_Kind = N_Subprogram_Declaration
2147 or else Unit_Kind = N_Package_Declaration
2148 or else Unit_Kind in N_Generic_Declaration
2150 Unit_Name := Defining_Entity (Unit (P));
2152 if Chars (Id) = Chars (Unit_Name) then
2153 Set_Entity (Id, Unit_Name);
2154 Set_Etype (Id, Etype (Unit_Name));
2156 Set_Etype (Id, Any_Type);
2158 ("cannot find program unit referenced by pragma%");
2162 Set_Etype (Id, Any_Type);
2163 Error_Pragma ("pragma% inapplicable to this unit");
2169 end Find_Program_Unit_Name;
2171 -----------------------------------------
2172 -- Find_Unique_Parameterless_Procedure --
2173 -----------------------------------------
2175 function Find_Unique_Parameterless_Procedure
2177 Arg : Node_Id) return Entity_Id
2179 Proc : Entity_Id := Empty;
2182 -- The body of this procedure needs some comments ???
2184 if not Is_Entity_Name (Name) then
2186 ("argument of pragma% must be entity name", Arg);
2188 elsif not Is_Overloaded (Name) then
2189 Proc := Entity (Name);
2191 if Ekind (Proc) /= E_Procedure
2192 or else Present (First_Formal (Proc))
2195 ("argument of pragma% must be parameterless procedure", Arg);
2200 Found : Boolean := False;
2202 Index : Interp_Index;
2205 Get_First_Interp (Name, Index, It);
2206 while Present (It.Nam) loop
2209 if Ekind (Proc) = E_Procedure
2210 and then No (First_Formal (Proc))
2214 Set_Entity (Name, Proc);
2215 Set_Is_Overloaded (Name, False);
2218 ("ambiguous handler name for pragma% ", Arg);
2222 Get_Next_Interp (Index, It);
2227 ("argument of pragma% must be parameterless procedure",
2230 Proc := Entity (Name);
2236 end Find_Unique_Parameterless_Procedure;
2242 procedure Fix_Error (Msg : in out String) is
2244 if From_Aspect_Specification (N) then
2245 for J in Msg'First .. Msg'Last - 5 loop
2246 if Msg (J .. J + 5) = "pragma" then
2247 Msg (J .. J + 5) := "aspect";
2251 if Error_Msg_Name_1 = Name_Precondition then
2252 Error_Msg_Name_1 := Name_Pre;
2253 elsif Error_Msg_Name_1 = Name_Postcondition then
2254 Error_Msg_Name_1 := Name_Post;
2259 -------------------------
2260 -- Gather_Associations --
2261 -------------------------
2263 procedure Gather_Associations
2265 Args : out Args_List)
2270 -- Initialize all parameters to Empty
2272 for J in Args'Range loop
2276 -- That's all we have to do if there are no argument associations
2278 if No (Pragma_Argument_Associations (N)) then
2282 -- Otherwise first deal with any positional parameters present
2284 Arg := First (Pragma_Argument_Associations (N));
2285 for Index in Args'Range loop
2286 exit when No (Arg) or else Chars (Arg) /= No_Name;
2287 Args (Index) := Get_Pragma_Arg (Arg);
2291 -- Positional parameters all processed, if any left, then we
2292 -- have too many positional parameters.
2294 if Present (Arg) and then Chars (Arg) = No_Name then
2296 ("too many positional associations for pragma%", Arg);
2299 -- Process named parameters if any are present
2301 while Present (Arg) loop
2302 if Chars (Arg) = No_Name then
2304 ("positional association cannot follow named association",
2308 for Index in Names'Range loop
2309 if Names (Index) = Chars (Arg) then
2310 if Present (Args (Index)) then
2312 ("duplicate argument association for pragma%", Arg);
2314 Args (Index) := Get_Pragma_Arg (Arg);
2319 if Index = Names'Last then
2320 Error_Msg_Name_1 := Pname;
2321 Error_Msg_N ("pragma% does not allow & argument", Arg);
2323 -- Check for possible misspelling
2325 for Index1 in Names'Range loop
2326 if Is_Bad_Spelling_Of
2327 (Chars (Arg), Names (Index1))
2329 Error_Msg_Name_1 := Names (Index1);
2330 Error_Msg_N -- CODEFIX
2331 ("\possible misspelling of%", Arg);
2343 end Gather_Associations;
2349 procedure GNAT_Pragma is
2351 Check_Restriction (No_Implementation_Pragmas, N);
2354 --------------------------
2355 -- Is_Before_First_Decl --
2356 --------------------------
2358 function Is_Before_First_Decl
2359 (Pragma_Node : Node_Id;
2360 Decls : List_Id) return Boolean
2362 Item : Node_Id := First (Decls);
2365 -- Only other pragmas can come before this pragma
2368 if No (Item) or else Nkind (Item) /= N_Pragma then
2371 elsif Item = Pragma_Node then
2377 end Is_Before_First_Decl;
2379 -----------------------------
2380 -- Is_Configuration_Pragma --
2381 -----------------------------
2383 -- A configuration pragma must appear in the context clause of a
2384 -- compilation unit, and only other pragmas may precede it. Note that
2385 -- the test below also permits use in a configuration pragma file.
2387 function Is_Configuration_Pragma return Boolean is
2388 Lis : constant List_Id := List_Containing (N);
2389 Par : constant Node_Id := Parent (N);
2393 -- If no parent, then we are in the configuration pragma file,
2394 -- so the placement is definitely appropriate.
2399 -- Otherwise we must be in the context clause of a compilation unit
2400 -- and the only thing allowed before us in the context list is more
2401 -- configuration pragmas.
2403 elsif Nkind (Par) = N_Compilation_Unit
2404 and then Context_Items (Par) = Lis
2411 elsif Nkind (Prg) /= N_Pragma then
2421 end Is_Configuration_Pragma;
2423 --------------------------
2424 -- Is_In_Context_Clause --
2425 --------------------------
2427 function Is_In_Context_Clause return Boolean is
2429 Parent_Node : Node_Id;
2432 if not Is_List_Member (N) then
2436 Plist := List_Containing (N);
2437 Parent_Node := Parent (Plist);
2439 if Parent_Node = Empty
2440 or else Nkind (Parent_Node) /= N_Compilation_Unit
2441 or else Context_Items (Parent_Node) /= Plist
2448 end Is_In_Context_Clause;
2450 ---------------------------------
2451 -- Is_Static_String_Expression --
2452 ---------------------------------
2454 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2455 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2458 Analyze_And_Resolve (Argx);
2459 return Is_OK_Static_Expression (Argx)
2460 and then Nkind (Argx) = N_String_Literal;
2461 end Is_Static_String_Expression;
2463 ----------------------
2464 -- Pragma_Misplaced --
2465 ----------------------
2467 procedure Pragma_Misplaced is
2469 Error_Pragma ("incorrect placement of pragma%");
2470 end Pragma_Misplaced;
2472 ------------------------------------
2473 -- Process Atomic_Shared_Volatile --
2474 ------------------------------------
2476 procedure Process_Atomic_Shared_Volatile is
2483 procedure Set_Atomic (E : Entity_Id);
2484 -- Set given type as atomic, and if no explicit alignment was given,
2485 -- set alignment to unknown, since back end knows what the alignment
2486 -- requirements are for atomic arrays. Note: this step is necessary
2487 -- for derived types.
2493 procedure Set_Atomic (E : Entity_Id) is
2497 if not Has_Alignment_Clause (E) then
2498 Set_Alignment (E, Uint_0);
2502 -- Start of processing for Process_Atomic_Shared_Volatile
2505 Check_Ada_83_Warning;
2506 Check_No_Identifiers;
2507 Check_Arg_Count (1);
2508 Check_Arg_Is_Local_Name (Arg1);
2509 E_Id := Get_Pragma_Arg (Arg1);
2511 if Etype (E_Id) = Any_Type then
2516 D := Declaration_Node (E);
2519 -- Check duplicate before we chain ourselves!
2521 Check_Duplicate_Pragma (E);
2523 -- Now check appropriateness of the entity
2526 if Rep_Item_Too_Early (E, N)
2528 Rep_Item_Too_Late (E, N)
2532 Check_First_Subtype (Arg1);
2535 if Prag_Id /= Pragma_Volatile then
2537 Set_Atomic (Underlying_Type (E));
2538 Set_Atomic (Base_Type (E));
2541 -- Attribute belongs on the base type. If the view of the type is
2542 -- currently private, it also belongs on the underlying type.
2544 Set_Is_Volatile (Base_Type (E));
2545 Set_Is_Volatile (Underlying_Type (E));
2547 Set_Treat_As_Volatile (E);
2548 Set_Treat_As_Volatile (Underlying_Type (E));
2550 elsif K = N_Object_Declaration
2551 or else (K = N_Component_Declaration
2552 and then Original_Record_Component (E) = E)
2554 if Rep_Item_Too_Late (E, N) then
2558 if Prag_Id /= Pragma_Volatile then
2561 -- If the object declaration has an explicit initialization, a
2562 -- temporary may have to be created to hold the expression, to
2563 -- ensure that access to the object remain atomic.
2565 if Nkind (Parent (E)) = N_Object_Declaration
2566 and then Present (Expression (Parent (E)))
2568 Set_Has_Delayed_Freeze (E);
2571 -- An interesting improvement here. If an object of type X is
2572 -- declared atomic, and the type X is not atomic, that's a
2573 -- pity, since it may not have appropriate alignment etc. We
2574 -- can rescue this in the special case where the object and
2575 -- type are in the same unit by just setting the type as
2576 -- atomic, so that the back end will process it as atomic.
2578 Utyp := Underlying_Type (Etype (E));
2581 and then Sloc (E) > No_Location
2582 and then Sloc (Utyp) > No_Location
2584 Get_Source_File_Index (Sloc (E)) =
2585 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2587 Set_Is_Atomic (Underlying_Type (Etype (E)));
2591 Set_Is_Volatile (E);
2592 Set_Treat_As_Volatile (E);
2596 ("inappropriate entity for pragma%", Arg1);
2598 end Process_Atomic_Shared_Volatile;
2600 -------------------------------------------
2601 -- Process_Compile_Time_Warning_Or_Error --
2602 -------------------------------------------
2604 procedure Process_Compile_Time_Warning_Or_Error is
2605 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2608 Check_Arg_Count (2);
2609 Check_No_Identifiers;
2610 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2611 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2613 if Compile_Time_Known_Value (Arg1x) then
2614 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2616 Str : constant String_Id :=
2617 Strval (Get_Pragma_Arg (Arg2));
2618 Len : constant Int := String_Length (Str);
2623 Cent : constant Entity_Id :=
2624 Cunit_Entity (Current_Sem_Unit);
2626 Force : constant Boolean :=
2627 Prag_Id = Pragma_Compile_Time_Warning
2629 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2630 and then (Ekind (Cent) /= E_Package
2631 or else not In_Private_Part (Cent));
2632 -- Set True if this is the warning case, and we are in the
2633 -- visible part of a package spec, or in a subprogram spec,
2634 -- in which case we want to force the client to see the
2635 -- warning, even though it is not in the main unit.
2638 -- Loop through segments of message separated by line feeds.
2639 -- We output these segments as separate messages with
2640 -- continuation marks for all but the first.
2645 Error_Msg_Strlen := 0;
2647 -- Loop to copy characters from argument to error message
2651 exit when Ptr > Len;
2652 CC := Get_String_Char (Str, Ptr);
2655 -- Ignore wide chars ??? else store character
2657 if In_Character_Range (CC) then
2658 C := Get_Character (CC);
2659 exit when C = ASCII.LF;
2660 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2661 Error_Msg_String (Error_Msg_Strlen) := C;
2665 -- Here with one line ready to go
2667 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2669 -- If this is a warning in a spec, then we want clients
2670 -- to see the warning, so mark the message with the
2671 -- special sequence !! to force the warning. In the case
2672 -- of a package spec, we do not force this if we are in
2673 -- the private part of the spec.
2676 if Cont = False then
2677 Error_Msg_N ("<~!!", Arg1);
2680 Error_Msg_N ("\<~!!", Arg1);
2683 -- Error, rather than warning, or in a body, so we do not
2684 -- need to force visibility for client (error will be
2685 -- output in any case, and this is the situation in which
2686 -- we do not want a client to get a warning, since the
2687 -- warning is in the body or the spec private part).
2690 if Cont = False then
2691 Error_Msg_N ("<~", Arg1);
2694 Error_Msg_N ("\<~", Arg1);
2698 exit when Ptr > Len;
2703 end Process_Compile_Time_Warning_Or_Error;
2705 ------------------------
2706 -- Process_Convention --
2707 ------------------------
2709 procedure Process_Convention
2710 (C : out Convention_Id;
2711 Ent : out Entity_Id)
2717 Comp_Unit : Unit_Number_Type;
2719 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2720 -- Called if we have more than one Export/Import/Convention pragma.
2721 -- This is generally illegal, but we have a special case of allowing
2722 -- Import and Interface to coexist if they specify the convention in
2723 -- a consistent manner. We are allowed to do this, since Interface is
2724 -- an implementation defined pragma, and we choose to do it since we
2725 -- know Rational allows this combination. S is the entity id of the
2726 -- subprogram in question. This procedure also sets the special flag
2727 -- Import_Interface_Present in both pragmas in the case where we do
2728 -- have matching Import and Interface pragmas.
2730 procedure Set_Convention_From_Pragma (E : Entity_Id);
2731 -- Set convention in entity E, and also flag that the entity has a
2732 -- convention pragma. If entity is for a private or incomplete type,
2733 -- also set convention and flag on underlying type. This procedure
2734 -- also deals with the special case of C_Pass_By_Copy convention.
2736 -------------------------------
2737 -- Diagnose_Multiple_Pragmas --
2738 -------------------------------
2740 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2741 Pdec : constant Node_Id := Declaration_Node (S);
2745 function Same_Convention (Decl : Node_Id) return Boolean;
2746 -- Decl is a pragma node. This function returns True if this
2747 -- pragma has a first argument that is an identifier with a
2748 -- Chars field corresponding to the Convention_Id C.
2750 function Same_Name (Decl : Node_Id) return Boolean;
2751 -- Decl is a pragma node. This function returns True if this
2752 -- pragma has a second argument that is an identifier with a
2753 -- Chars field that matches the Chars of the current subprogram.
2755 ---------------------
2756 -- Same_Convention --
2757 ---------------------
2759 function Same_Convention (Decl : Node_Id) return Boolean is
2760 Arg1 : constant Node_Id :=
2761 First (Pragma_Argument_Associations (Decl));
2764 if Present (Arg1) then
2766 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2768 if Nkind (Arg) = N_Identifier
2769 and then Is_Convention_Name (Chars (Arg))
2770 and then Get_Convention_Id (Chars (Arg)) = C
2778 end Same_Convention;
2784 function Same_Name (Decl : Node_Id) return Boolean is
2785 Arg1 : constant Node_Id :=
2786 First (Pragma_Argument_Associations (Decl));
2794 Arg2 := Next (Arg1);
2801 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2803 if Nkind (Arg) = N_Identifier
2804 and then Chars (Arg) = Chars (S)
2813 -- Start of processing for Diagnose_Multiple_Pragmas
2818 -- Definitely give message if we have Convention/Export here
2820 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2823 -- If we have an Import or Export, scan back from pragma to
2824 -- find any previous pragma applying to the same procedure.
2825 -- The scan will be terminated by the start of the list, or
2826 -- hitting the subprogram declaration. This won't allow one
2827 -- pragma to appear in the public part and one in the private
2828 -- part, but that seems very unlikely in practice.
2832 while Present (Decl) and then Decl /= Pdec loop
2834 -- Look for pragma with same name as us
2836 if Nkind (Decl) = N_Pragma
2837 and then Same_Name (Decl)
2839 -- Give error if same as our pragma or Export/Convention
2841 if Pragma_Name (Decl) = Name_Export
2843 Pragma_Name (Decl) = Name_Convention
2845 Pragma_Name (Decl) = Pragma_Name (N)
2849 -- Case of Import/Interface or the other way round
2851 elsif Pragma_Name (Decl) = Name_Interface
2853 Pragma_Name (Decl) = Name_Import
2855 -- Here we know that we have Import and Interface. It
2856 -- doesn't matter which way round they are. See if
2857 -- they specify the same convention. If so, all OK,
2858 -- and set special flags to stop other messages
2860 if Same_Convention (Decl) then
2861 Set_Import_Interface_Present (N);
2862 Set_Import_Interface_Present (Decl);
2865 -- If different conventions, special message
2868 Error_Msg_Sloc := Sloc (Decl);
2870 ("convention differs from that given#", Arg1);
2880 -- Give message if needed if we fall through those tests
2884 ("at most one Convention/Export/Import pragma is allowed",
2887 end Diagnose_Multiple_Pragmas;
2889 --------------------------------
2890 -- Set_Convention_From_Pragma --
2891 --------------------------------
2893 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2895 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2896 -- for an overridden dispatching operation. Technically this is
2897 -- an amendment and should only be done in Ada 2005 mode. However,
2898 -- this is clearly a mistake, since the problem that is addressed
2899 -- by this AI is that there is a clear gap in the RM!
2901 if Is_Dispatching_Operation (E)
2902 and then Present (Overridden_Operation (E))
2903 and then C /= Convention (Overridden_Operation (E))
2906 ("cannot change convention for " &
2907 "overridden dispatching operation",
2911 -- Set the convention
2913 Set_Convention (E, C);
2914 Set_Has_Convention_Pragma (E);
2916 if Is_Incomplete_Or_Private_Type (E)
2917 and then Present (Underlying_Type (E))
2919 Set_Convention (Underlying_Type (E), C);
2920 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2923 -- A class-wide type should inherit the convention of the specific
2924 -- root type (although this isn't specified clearly by the RM).
2926 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2927 Set_Convention (Class_Wide_Type (E), C);
2930 -- If the entity is a record type, then check for special case of
2931 -- C_Pass_By_Copy, which is treated the same as C except that the
2932 -- special record flag is set. This convention is only permitted
2933 -- on record types (see AI95-00131).
2935 if Cname = Name_C_Pass_By_Copy then
2936 if Is_Record_Type (E) then
2937 Set_C_Pass_By_Copy (Base_Type (E));
2938 elsif Is_Incomplete_Or_Private_Type (E)
2939 and then Is_Record_Type (Underlying_Type (E))
2941 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2944 ("C_Pass_By_Copy convention allowed only for record type",
2949 -- If the entity is a derived boolean type, check for the special
2950 -- case of convention C, C++, or Fortran, where we consider any
2951 -- nonzero value to represent true.
2953 if Is_Discrete_Type (E)
2954 and then Root_Type (Etype (E)) = Standard_Boolean
2960 C = Convention_Fortran)
2962 Set_Nonzero_Is_True (Base_Type (E));
2964 end Set_Convention_From_Pragma;
2966 -- Start of processing for Process_Convention
2969 Check_At_Least_N_Arguments (2);
2970 Check_Optional_Identifier (Arg1, Name_Convention);
2971 Check_Arg_Is_Identifier (Arg1);
2972 Cname := Chars (Get_Pragma_Arg (Arg1));
2974 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2975 -- tested again below to set the critical flag).
2977 if Cname = Name_C_Pass_By_Copy then
2980 -- Otherwise we must have something in the standard convention list
2982 elsif Is_Convention_Name (Cname) then
2983 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
2985 -- In DEC VMS, it seems that there is an undocumented feature that
2986 -- any unrecognized convention is treated as the default, which for
2987 -- us is convention C. It does not seem so terrible to do this
2988 -- unconditionally, silently in the VMS case, and with a warning
2989 -- in the non-VMS case.
2992 if Warn_On_Export_Import and not OpenVMS_On_Target then
2994 ("?unrecognized convention name, C assumed",
2995 Get_Pragma_Arg (Arg1));
3001 Check_Optional_Identifier (Arg2, Name_Entity);
3002 Check_Arg_Is_Local_Name (Arg2);
3004 Id := Get_Pragma_Arg (Arg2);
3007 if not Is_Entity_Name (Id) then
3008 Error_Pragma_Arg ("entity name required", Arg2);
3013 -- Set entity to return
3017 -- Ada_Pass_By_Copy special checking
3019 if C = Convention_Ada_Pass_By_Copy then
3020 if not Is_First_Subtype (E) then
3022 ("convention `Ada_Pass_By_Copy` only "
3023 & "allowed for types", Arg2);
3026 if Is_By_Reference_Type (E) then
3028 ("convention `Ada_Pass_By_Copy` not allowed for "
3029 & "by-reference type", Arg1);
3033 -- Ada_Pass_By_Reference special checking
3035 if C = Convention_Ada_Pass_By_Reference then
3036 if not Is_First_Subtype (E) then
3038 ("convention `Ada_Pass_By_Reference` only "
3039 & "allowed for types", Arg2);
3042 if Is_By_Copy_Type (E) then
3044 ("convention `Ada_Pass_By_Reference` not allowed for "
3045 & "by-copy type", Arg1);
3049 -- Go to renamed subprogram if present, since convention applies to
3050 -- the actual renamed entity, not to the renaming entity. If the
3051 -- subprogram is inherited, go to parent subprogram.
3053 if Is_Subprogram (E)
3054 and then Present (Alias (E))
3056 if Nkind (Parent (Declaration_Node (E))) =
3057 N_Subprogram_Renaming_Declaration
3059 if Scope (E) /= Scope (Alias (E)) then
3061 ("cannot apply pragma% to non-local entity&#", E);
3066 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3067 N_Private_Extension_Declaration)
3068 and then Scope (E) = Scope (Alias (E))
3072 -- Return the parent subprogram the entity was inherited from
3078 -- Check that we are not applying this to a specless body
3080 if Is_Subprogram (E)
3081 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3084 ("pragma% requires separate spec and must come before body");
3087 -- Check that we are not applying this to a named constant
3089 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3090 Error_Msg_Name_1 := Pname;
3092 ("cannot apply pragma% to named constant!",
3093 Get_Pragma_Arg (Arg2));
3095 ("\supply appropriate type for&!", Arg2);
3098 if Ekind (E) = E_Enumeration_Literal then
3099 Error_Pragma ("enumeration literal not allowed for pragma%");
3102 -- Check for rep item appearing too early or too late
3104 if Etype (E) = Any_Type
3105 or else Rep_Item_Too_Early (E, N)
3109 elsif Present (Underlying_Type (E)) then
3110 E := Underlying_Type (E);
3113 if Rep_Item_Too_Late (E, N) then
3117 if Has_Convention_Pragma (E) then
3118 Diagnose_Multiple_Pragmas (E);
3120 elsif Convention (E) = Convention_Protected
3121 or else Ekind (Scope (E)) = E_Protected_Type
3124 ("a protected operation cannot be given a different convention",
3128 -- For Intrinsic, a subprogram is required
3130 if C = Convention_Intrinsic
3131 and then not Is_Subprogram (E)
3132 and then not Is_Generic_Subprogram (E)
3135 ("second argument of pragma% must be a subprogram", Arg2);
3138 -- For Stdcall, a subprogram, variable or subprogram type is required
3140 if C = Convention_Stdcall
3141 and then not Is_Subprogram (E)
3142 and then not Is_Generic_Subprogram (E)
3143 and then Ekind (E) /= E_Variable
3146 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3149 ("second argument of pragma% must be subprogram (type)",
3153 if not Is_Subprogram (E)
3154 and then not Is_Generic_Subprogram (E)
3156 Set_Convention_From_Pragma (E);
3159 Check_First_Subtype (Arg2);
3160 Set_Convention_From_Pragma (Base_Type (E));
3162 -- For subprograms, we must set the convention on the
3163 -- internally generated directly designated type as well.
3165 if Ekind (E) = E_Access_Subprogram_Type then
3166 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3170 -- For the subprogram case, set proper convention for all homonyms
3171 -- in same scope and the same declarative part, i.e. the same
3172 -- compilation unit.
3175 Comp_Unit := Get_Source_Unit (E);
3176 Set_Convention_From_Pragma (E);
3178 -- Treat a pragma Import as an implicit body, for GPS use
3180 if Prag_Id = Pragma_Import then
3181 Generate_Reference (E, Id, 'b');
3184 -- Loop through the homonyms of the pragma argument's entity
3189 exit when No (E1) or else Scope (E1) /= Current_Scope;
3191 -- Do not set the pragma on inherited operations or on formal
3194 if Comes_From_Source (E1)
3195 and then Comp_Unit = Get_Source_Unit (E1)
3196 and then not Is_Formal_Subprogram (E1)
3197 and then Nkind (Original_Node (Parent (E1))) /=
3198 N_Full_Type_Declaration
3200 if Present (Alias (E1))
3201 and then Scope (E1) /= Scope (Alias (E1))
3204 ("cannot apply pragma% to non-local entity& declared#",
3208 Set_Convention_From_Pragma (E1);
3210 if Prag_Id = Pragma_Import then
3211 Generate_Reference (E1, Id, 'b');
3215 -- For aspect case, do NOT apply to homonyms
3217 exit when From_Aspect_Specification (N);
3220 end Process_Convention;
3222 -----------------------------------------------------
3223 -- Process_Extended_Import_Export_Exception_Pragma --
3224 -----------------------------------------------------
3226 procedure Process_Extended_Import_Export_Exception_Pragma
3227 (Arg_Internal : Node_Id;
3228 Arg_External : Node_Id;
3236 if not OpenVMS_On_Target then
3238 ("?pragma% ignored (applies only to Open'V'M'S)");
3241 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3242 Def_Id := Entity (Arg_Internal);
3244 if Ekind (Def_Id) /= E_Exception then
3246 ("pragma% must refer to declared exception", Arg_Internal);
3249 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3251 if Present (Arg_Form) then
3252 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3255 if Present (Arg_Form)
3256 and then Chars (Arg_Form) = Name_Ada
3260 Set_Is_VMS_Exception (Def_Id);
3261 Set_Exception_Code (Def_Id, No_Uint);
3264 if Present (Arg_Code) then
3265 if not Is_VMS_Exception (Def_Id) then
3267 ("Code option for pragma% not allowed for Ada case",
3271 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3272 Code_Val := Expr_Value (Arg_Code);
3274 if not UI_Is_In_Int_Range (Code_Val) then
3276 ("Code option for pragma% must be in 32-bit range",
3280 Set_Exception_Code (Def_Id, Code_Val);
3283 end Process_Extended_Import_Export_Exception_Pragma;
3285 -------------------------------------------------
3286 -- Process_Extended_Import_Export_Internal_Arg --
3287 -------------------------------------------------
3289 procedure Process_Extended_Import_Export_Internal_Arg
3290 (Arg_Internal : Node_Id := Empty)
3293 if No (Arg_Internal) then
3294 Error_Pragma ("Internal parameter required for pragma%");
3297 if Nkind (Arg_Internal) = N_Identifier then
3300 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3301 and then (Prag_Id = Pragma_Import_Function
3303 Prag_Id = Pragma_Export_Function)
3309 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3312 Check_Arg_Is_Local_Name (Arg_Internal);
3313 end Process_Extended_Import_Export_Internal_Arg;
3315 --------------------------------------------------
3316 -- Process_Extended_Import_Export_Object_Pragma --
3317 --------------------------------------------------
3319 procedure Process_Extended_Import_Export_Object_Pragma
3320 (Arg_Internal : Node_Id;
3321 Arg_External : Node_Id;
3327 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3328 Def_Id := Entity (Arg_Internal);
3330 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3332 ("pragma% must designate an object", Arg_Internal);
3335 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3337 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3340 ("previous Common/Psect_Object applies, pragma % not permitted",
3344 if Rep_Item_Too_Late (Def_Id, N) then
3348 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3350 if Present (Arg_Size) then
3351 Check_Arg_Is_External_Name (Arg_Size);
3354 -- Export_Object case
3356 if Prag_Id = Pragma_Export_Object then
3357 if not Is_Library_Level_Entity (Def_Id) then
3359 ("argument for pragma% must be library level entity",
3363 if Ekind (Current_Scope) = E_Generic_Package then
3364 Error_Pragma ("pragma& cannot appear in a generic unit");
3367 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3369 ("exported object must have compile time known size",
3373 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3374 Error_Msg_N ("?duplicate Export_Object pragma", N);
3376 Set_Exported (Def_Id, Arg_Internal);
3379 -- Import_Object case
3382 if Is_Concurrent_Type (Etype (Def_Id)) then
3384 ("cannot use pragma% for task/protected object",
3388 if Ekind (Def_Id) = E_Constant then
3390 ("cannot import a constant", Arg_Internal);
3393 if Warn_On_Export_Import
3394 and then Has_Discriminants (Etype (Def_Id))
3397 ("imported value must be initialized?", Arg_Internal);
3400 if Warn_On_Export_Import
3401 and then Is_Access_Type (Etype (Def_Id))
3404 ("cannot import object of an access type?", Arg_Internal);
3407 if Warn_On_Export_Import
3408 and then Is_Imported (Def_Id)
3411 ("?duplicate Import_Object pragma", N);
3413 -- Check for explicit initialization present. Note that an
3414 -- initialization generated by the code generator, e.g. for an
3415 -- access type, does not count here.
3417 elsif Present (Expression (Parent (Def_Id)))
3420 (Original_Node (Expression (Parent (Def_Id))))
3422 Error_Msg_Sloc := Sloc (Def_Id);
3424 ("imported entities cannot be initialized (RM B.1(24))",
3425 "\no initialization allowed for & declared#", Arg1);
3427 Set_Imported (Def_Id);
3428 Note_Possible_Modification (Arg_Internal, Sure => False);
3431 end Process_Extended_Import_Export_Object_Pragma;
3433 ------------------------------------------------------
3434 -- Process_Extended_Import_Export_Subprogram_Pragma --
3435 ------------------------------------------------------
3437 procedure Process_Extended_Import_Export_Subprogram_Pragma
3438 (Arg_Internal : Node_Id;
3439 Arg_External : Node_Id;
3440 Arg_Parameter_Types : Node_Id;
3441 Arg_Result_Type : Node_Id := Empty;
3442 Arg_Mechanism : Node_Id;
3443 Arg_Result_Mechanism : Node_Id := Empty;
3444 Arg_First_Optional_Parameter : Node_Id := Empty)
3450 Ambiguous : Boolean;
3454 function Same_Base_Type
3456 Formal : Entity_Id) return Boolean;
3457 -- Determines if Ptype references the type of Formal. Note that only
3458 -- the base types need to match according to the spec. Ptype here is
3459 -- the argument from the pragma, which is either a type name, or an
3460 -- access attribute.
3462 --------------------
3463 -- Same_Base_Type --
3464 --------------------
3466 function Same_Base_Type
3468 Formal : Entity_Id) return Boolean
3470 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3474 -- Case where pragma argument is typ'Access
3476 if Nkind (Ptype) = N_Attribute_Reference
3477 and then Attribute_Name (Ptype) = Name_Access
3479 Pref := Prefix (Ptype);
3482 if not Is_Entity_Name (Pref)
3483 or else Entity (Pref) = Any_Type
3488 -- We have a match if the corresponding argument is of an
3489 -- anonymous access type, and its designated type matches the
3490 -- type of the prefix of the access attribute
3492 return Ekind (Ftyp) = E_Anonymous_Access_Type
3493 and then Base_Type (Entity (Pref)) =
3494 Base_Type (Etype (Designated_Type (Ftyp)));
3496 -- Case where pragma argument is a type name
3501 if not Is_Entity_Name (Ptype)
3502 or else Entity (Ptype) = Any_Type
3507 -- We have a match if the corresponding argument is of the type
3508 -- given in the pragma (comparing base types)
3510 return Base_Type (Entity (Ptype)) = Ftyp;
3514 -- Start of processing for
3515 -- Process_Extended_Import_Export_Subprogram_Pragma
3518 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3522 -- Loop through homonyms (overloadings) of the entity
3524 Hom_Id := Entity (Arg_Internal);
3525 while Present (Hom_Id) loop
3526 Def_Id := Get_Base_Subprogram (Hom_Id);
3528 -- We need a subprogram in the current scope
3530 if not Is_Subprogram (Def_Id)
3531 or else Scope (Def_Id) /= Current_Scope
3538 -- Pragma cannot apply to subprogram body
3540 if Is_Subprogram (Def_Id)
3541 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3545 ("pragma% requires separate spec"
3546 & " and must come before body");
3549 -- Test result type if given, note that the result type
3550 -- parameter can only be present for the function cases.
3552 if Present (Arg_Result_Type)
3553 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3557 elsif Etype (Def_Id) /= Standard_Void_Type
3559 (Pname = Name_Export_Procedure
3561 Pname = Name_Import_Procedure)
3565 -- Test parameter types if given. Note that this parameter
3566 -- has not been analyzed (and must not be, since it is
3567 -- semantic nonsense), so we get it as the parser left it.
3569 elsif Present (Arg_Parameter_Types) then
3570 Check_Matching_Types : declare
3575 Formal := First_Formal (Def_Id);
3577 if Nkind (Arg_Parameter_Types) = N_Null then
3578 if Present (Formal) then
3582 -- A list of one type, e.g. (List) is parsed as
3583 -- a parenthesized expression.
3585 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3586 and then Paren_Count (Arg_Parameter_Types) = 1
3589 or else Present (Next_Formal (Formal))
3594 Same_Base_Type (Arg_Parameter_Types, Formal);
3597 -- A list of more than one type is parsed as a aggregate
3599 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3600 and then Paren_Count (Arg_Parameter_Types) = 0
3602 Ptype := First (Expressions (Arg_Parameter_Types));
3603 while Present (Ptype) or else Present (Formal) loop
3606 or else not Same_Base_Type (Ptype, Formal)
3611 Next_Formal (Formal);
3616 -- Anything else is of the wrong form
3620 ("wrong form for Parameter_Types parameter",
3621 Arg_Parameter_Types);
3623 end Check_Matching_Types;
3626 -- Match is now False if the entry we found did not match
3627 -- either a supplied Parameter_Types or Result_Types argument
3633 -- Ambiguous case, the flag Ambiguous shows if we already
3634 -- detected this and output the initial messages.
3637 if not Ambiguous then
3639 Error_Msg_Name_1 := Pname;
3641 ("pragma% does not uniquely identify subprogram!",
3643 Error_Msg_Sloc := Sloc (Ent);
3644 Error_Msg_N ("matching subprogram #!", N);
3648 Error_Msg_Sloc := Sloc (Def_Id);
3649 Error_Msg_N ("matching subprogram #!", N);
3654 Hom_Id := Homonym (Hom_Id);
3657 -- See if we found an entry
3660 if not Ambiguous then
3661 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3663 ("pragma% cannot be given for generic subprogram");
3666 ("pragma% does not identify local subprogram");
3673 -- Import pragmas must be for imported entities
3675 if Prag_Id = Pragma_Import_Function
3677 Prag_Id = Pragma_Import_Procedure
3679 Prag_Id = Pragma_Import_Valued_Procedure
3681 if not Is_Imported (Ent) then
3683 ("pragma Import or Interface must precede pragma%");
3686 -- Here we have the Export case which can set the entity as exported
3688 -- But does not do so if the specified external name is null, since
3689 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3690 -- compatible) to request no external name.
3692 elsif Nkind (Arg_External) = N_String_Literal
3693 and then String_Length (Strval (Arg_External)) = 0
3697 -- In all other cases, set entity as exported
3700 Set_Exported (Ent, Arg_Internal);
3703 -- Special processing for Valued_Procedure cases
3705 if Prag_Id = Pragma_Import_Valued_Procedure
3707 Prag_Id = Pragma_Export_Valued_Procedure
3709 Formal := First_Formal (Ent);
3712 Error_Pragma ("at least one parameter required for pragma%");
3714 elsif Ekind (Formal) /= E_Out_Parameter then
3715 Error_Pragma ("first parameter must have mode out for pragma%");
3718 Set_Is_Valued_Procedure (Ent);
3722 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3724 -- Process Result_Mechanism argument if present. We have already
3725 -- checked that this is only allowed for the function case.
3727 if Present (Arg_Result_Mechanism) then
3728 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3731 -- Process Mechanism parameter if present. Note that this parameter
3732 -- is not analyzed, and must not be analyzed since it is semantic
3733 -- nonsense, so we get it in exactly as the parser left it.
3735 if Present (Arg_Mechanism) then
3743 -- A single mechanism association without a formal parameter
3744 -- name is parsed as a parenthesized expression. All other
3745 -- cases are parsed as aggregates, so we rewrite the single
3746 -- parameter case as an aggregate for consistency.
3748 if Nkind (Arg_Mechanism) /= N_Aggregate
3749 and then Paren_Count (Arg_Mechanism) = 1
3751 Rewrite (Arg_Mechanism,
3752 Make_Aggregate (Sloc (Arg_Mechanism),
3753 Expressions => New_List (
3754 Relocate_Node (Arg_Mechanism))));
3757 -- Case of only mechanism name given, applies to all formals
3759 if Nkind (Arg_Mechanism) /= N_Aggregate then
3760 Formal := First_Formal (Ent);
3761 while Present (Formal) loop
3762 Set_Mechanism_Value (Formal, Arg_Mechanism);
3763 Next_Formal (Formal);
3766 -- Case of list of mechanism associations given
3769 if Null_Record_Present (Arg_Mechanism) then
3771 ("inappropriate form for Mechanism parameter",
3775 -- Deal with positional ones first
3777 Formal := First_Formal (Ent);
3779 if Present (Expressions (Arg_Mechanism)) then
3780 Mname := First (Expressions (Arg_Mechanism));
3781 while Present (Mname) loop
3784 ("too many mechanism associations", Mname);
3787 Set_Mechanism_Value (Formal, Mname);
3788 Next_Formal (Formal);
3793 -- Deal with named entries
3795 if Present (Component_Associations (Arg_Mechanism)) then
3796 Massoc := First (Component_Associations (Arg_Mechanism));
3797 while Present (Massoc) loop
3798 Choice := First (Choices (Massoc));
3800 if Nkind (Choice) /= N_Identifier
3801 or else Present (Next (Choice))
3804 ("incorrect form for mechanism association",
3808 Formal := First_Formal (Ent);
3812 ("parameter name & not present", Choice);
3815 if Chars (Choice) = Chars (Formal) then
3817 (Formal, Expression (Massoc));
3819 -- Set entity on identifier (needed by ASIS)
3821 Set_Entity (Choice, Formal);
3826 Next_Formal (Formal);
3836 -- Process First_Optional_Parameter argument if present. We have
3837 -- already checked that this is only allowed for the Import case.
3839 if Present (Arg_First_Optional_Parameter) then
3840 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3842 ("first optional parameter must be formal parameter name",
3843 Arg_First_Optional_Parameter);
3846 Formal := First_Formal (Ent);
3850 ("specified formal parameter& not found",
3851 Arg_First_Optional_Parameter);
3854 exit when Chars (Formal) =
3855 Chars (Arg_First_Optional_Parameter);
3857 Next_Formal (Formal);
3860 Set_First_Optional_Parameter (Ent, Formal);
3862 -- Check specified and all remaining formals have right form
3864 while Present (Formal) loop
3865 if Ekind (Formal) /= E_In_Parameter then
3867 ("optional formal& is not of mode in!",
3868 Arg_First_Optional_Parameter, Formal);
3871 Dval := Default_Value (Formal);
3875 ("optional formal& does not have default value!",
3876 Arg_First_Optional_Parameter, Formal);
3878 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3883 ("default value for optional formal& is non-static!",
3884 Arg_First_Optional_Parameter, Formal);
3888 Set_Is_Optional_Parameter (Formal);
3889 Next_Formal (Formal);
3892 end Process_Extended_Import_Export_Subprogram_Pragma;
3894 --------------------------
3895 -- Process_Generic_List --
3896 --------------------------
3898 procedure Process_Generic_List is
3903 Check_No_Identifiers;
3904 Check_At_Least_N_Arguments (1);
3907 while Present (Arg) loop
3908 Exp := Get_Pragma_Arg (Arg);
3911 if not Is_Entity_Name (Exp)
3913 (not Is_Generic_Instance (Entity (Exp))
3915 not Is_Generic_Unit (Entity (Exp)))
3918 ("pragma% argument must be name of generic unit/instance",
3924 end Process_Generic_List;
3926 ------------------------------------
3927 -- Process_Import_Predefined_Type --
3928 ------------------------------------
3930 procedure Process_Import_Predefined_Type is
3931 Loc : constant Source_Ptr := Sloc (N);
3933 Ftyp : Node_Id := Empty;
3939 String_To_Name_Buffer (Strval (Expression (Arg3)));
3942 Elmt := First_Elmt (Predefined_Float_Types);
3943 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
3947 Ftyp := Node (Elmt);
3949 if Present (Ftyp) then
3951 -- Don't build a derived type declaration, because predefined C
3952 -- types have no declaration anywhere, so cannot really be named.
3953 -- Instead build a full type declaration, starting with an
3954 -- appropriate type definition is built
3956 if Is_Floating_Point_Type (Ftyp) then
3957 Def := Make_Floating_Point_Definition (Loc,
3958 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
3959 Make_Real_Range_Specification (Loc,
3960 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
3961 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
3963 -- Should never have a predefined type we cannot handle
3966 raise Program_Error;
3969 -- Build and insert a Full_Type_Declaration, which will be
3970 -- analyzed as soon as this list entry has been analyzed.
3972 Decl := Make_Full_Type_Declaration (Loc,
3973 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
3974 Type_Definition => Def);
3976 Insert_After (N, Decl);
3977 Mark_Rewrite_Insertion (Decl);
3980 Error_Pragma_Arg ("no matching type found for pragma%",
3983 end Process_Import_Predefined_Type;
3985 ---------------------------------
3986 -- Process_Import_Or_Interface --
3987 ---------------------------------
3989 procedure Process_Import_Or_Interface is
3995 Process_Convention (C, Def_Id);
3996 Kill_Size_Check_Code (Def_Id);
3997 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
3999 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4001 -- We do not permit Import to apply to a renaming declaration
4003 if Present (Renamed_Object (Def_Id)) then
4005 ("pragma% not allowed for object renaming", Arg2);
4007 -- User initialization is not allowed for imported object, but
4008 -- the object declaration may contain a default initialization,
4009 -- that will be discarded. Note that an explicit initialization
4010 -- only counts if it comes from source, otherwise it is simply
4011 -- the code generator making an implicit initialization explicit.
4013 elsif Present (Expression (Parent (Def_Id)))
4014 and then Comes_From_Source (Expression (Parent (Def_Id)))
4016 Error_Msg_Sloc := Sloc (Def_Id);
4018 ("no initialization allowed for declaration of& #",
4019 "\imported entities cannot be initialized (RM B.1(24))",
4023 Set_Imported (Def_Id);
4024 Process_Interface_Name (Def_Id, Arg3, Arg4);
4026 -- Note that we do not set Is_Public here. That's because we
4027 -- only want to set it if there is no address clause, and we
4028 -- don't know that yet, so we delay that processing till
4031 -- pragma Import completes deferred constants
4033 if Ekind (Def_Id) = E_Constant then
4034 Set_Has_Completion (Def_Id);
4037 -- It is not possible to import a constant of an unconstrained
4038 -- array type (e.g. string) because there is no simple way to
4039 -- write a meaningful subtype for it.
4041 if Is_Array_Type (Etype (Def_Id))
4042 and then not Is_Constrained (Etype (Def_Id))
4045 ("imported constant& must have a constrained subtype",
4050 elsif Is_Subprogram (Def_Id)
4051 or else Is_Generic_Subprogram (Def_Id)
4053 -- If the name is overloaded, pragma applies to all of the denoted
4054 -- entities in the same declarative part.
4057 while Present (Hom_Id) loop
4058 Def_Id := Get_Base_Subprogram (Hom_Id);
4060 -- Ignore inherited subprograms because the pragma will apply
4061 -- to the parent operation, which is the one called.
4063 if Is_Overloadable (Def_Id)
4064 and then Present (Alias (Def_Id))
4068 -- If it is not a subprogram, it must be in an outer scope and
4069 -- pragma does not apply.
4071 elsif not Is_Subprogram (Def_Id)
4072 and then not Is_Generic_Subprogram (Def_Id)
4076 -- The pragma does not apply to primitives of interfaces
4078 elsif Is_Dispatching_Operation (Def_Id)
4079 and then Present (Find_Dispatching_Type (Def_Id))
4080 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4084 -- Verify that the homonym is in the same declarative part (not
4085 -- just the same scope).
4087 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4088 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4093 Set_Imported (Def_Id);
4095 -- Reject an Import applied to an abstract subprogram
4097 if Is_Subprogram (Def_Id)
4098 and then Is_Abstract_Subprogram (Def_Id)
4100 Error_Msg_Sloc := Sloc (Def_Id);
4102 ("cannot import abstract subprogram& declared#",
4106 -- Special processing for Convention_Intrinsic
4108 if C = Convention_Intrinsic then
4110 -- Link_Name argument not allowed for intrinsic
4114 Set_Is_Intrinsic_Subprogram (Def_Id);
4116 -- If no external name is present, then check that this
4117 -- is a valid intrinsic subprogram. If an external name
4118 -- is present, then this is handled by the back end.
4121 Check_Intrinsic_Subprogram
4122 (Def_Id, Get_Pragma_Arg (Arg2));
4126 -- All interfaced procedures need an external symbol created
4127 -- for them since they are always referenced from another
4130 Set_Is_Public (Def_Id);
4132 -- Verify that the subprogram does not have a completion
4133 -- through a renaming declaration. For other completions the
4134 -- pragma appears as a too late representation.
4137 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4141 and then Nkind (Decl) = N_Subprogram_Declaration
4142 and then Present (Corresponding_Body (Decl))
4143 and then Nkind (Unit_Declaration_Node
4144 (Corresponding_Body (Decl))) =
4145 N_Subprogram_Renaming_Declaration
4147 Error_Msg_Sloc := Sloc (Def_Id);
4149 ("cannot import&, renaming already provided for " &
4150 "declaration #", N, Def_Id);
4154 Set_Has_Completion (Def_Id);
4155 Process_Interface_Name (Def_Id, Arg3, Arg4);
4158 if Is_Compilation_Unit (Hom_Id) then
4160 -- Its possible homonyms are not affected by the pragma.
4161 -- Such homonyms might be present in the context of other
4162 -- units being compiled.
4167 Hom_Id := Homonym (Hom_Id);
4171 -- When the convention is Java or CIL, we also allow Import to be
4172 -- given for packages, generic packages, exceptions, record
4173 -- components, and access to subprograms.
4175 elsif (C = Convention_Java or else C = Convention_CIL)
4177 (Is_Package_Or_Generic_Package (Def_Id)
4178 or else Ekind (Def_Id) = E_Exception
4179 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4180 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4182 Set_Imported (Def_Id);
4183 Set_Is_Public (Def_Id);
4184 Process_Interface_Name (Def_Id, Arg3, Arg4);
4186 -- Import a CPP class
4188 elsif Is_Record_Type (Def_Id)
4189 and then C = Convention_CPP
4191 -- Types treated as CPP classes must be declared limited (note:
4192 -- this used to be a warning but there is no real benefit to it
4193 -- since we did effectively intend to treat the type as limited
4196 if not Is_Limited_Type (Def_Id) then
4198 ("imported 'C'P'P type must be limited",
4199 Get_Pragma_Arg (Arg2));
4202 Set_Is_CPP_Class (Def_Id);
4204 -- Imported CPP types must not have discriminants (because C++
4205 -- classes do not have discriminants).
4207 if Has_Discriminants (Def_Id) then
4209 ("imported 'C'P'P type cannot have discriminants",
4210 First (Discriminant_Specifications
4211 (Declaration_Node (Def_Id))));
4214 -- Components of imported CPP types must not have default
4215 -- expressions because the constructor (if any) is on the
4219 Tdef : constant Node_Id :=
4220 Type_Definition (Declaration_Node (Def_Id));
4225 if Nkind (Tdef) = N_Record_Definition then
4226 Clist := Component_List (Tdef);
4229 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4230 Clist := Component_List (Record_Extension_Part (Tdef));
4233 if Present (Clist) then
4234 Comp := First (Component_Items (Clist));
4235 while Present (Comp) loop
4236 if Present (Expression (Comp)) then
4238 ("component of imported 'C'P'P type cannot have" &
4239 " default expression", Expression (Comp));
4247 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4249 Check_Arg_Count (3);
4250 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4252 Process_Import_Predefined_Type;
4256 ("second argument of pragma% must be object, subprogram" &
4257 " or incomplete type",
4261 -- If this pragma applies to a compilation unit, then the unit, which
4262 -- is a subprogram, does not require (or allow) a body. We also do
4263 -- not need to elaborate imported procedures.
4265 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4267 Cunit : constant Node_Id := Parent (Parent (N));
4269 Set_Body_Required (Cunit, False);
4272 end Process_Import_Or_Interface;
4274 --------------------
4275 -- Process_Inline --
4276 --------------------
4278 procedure Process_Inline (Active : Boolean) is
4285 Effective : Boolean := False;
4286 -- Set True if inline has some effect, i.e. if there is at least one
4287 -- subprogram set as inlined as a result of the use of the pragma.
4289 procedure Make_Inline (Subp : Entity_Id);
4290 -- Subp is the defining unit name of the subprogram declaration. Set
4291 -- the flag, as well as the flag in the corresponding body, if there
4294 procedure Set_Inline_Flags (Subp : Entity_Id);
4295 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4296 -- Has_Pragma_Inline_Always for the Inline_Always case.
4298 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4299 -- Returns True if it can be determined at this stage that inlining
4300 -- is not possible, for example if the body is available and contains
4301 -- exception handlers, we prevent inlining, since otherwise we can
4302 -- get undefined symbols at link time. This function also emits a
4303 -- warning if front-end inlining is enabled and the pragma appears
4306 -- ??? is business with link symbols still valid, or does it relate
4307 -- to front end ZCX which is being phased out ???
4309 ---------------------------
4310 -- Inlining_Not_Possible --
4311 ---------------------------
4313 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4314 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4318 if Nkind (Decl) = N_Subprogram_Body then
4319 Stats := Handled_Statement_Sequence (Decl);
4320 return Present (Exception_Handlers (Stats))
4321 or else Present (At_End_Proc (Stats));
4323 elsif Nkind (Decl) = N_Subprogram_Declaration
4324 and then Present (Corresponding_Body (Decl))
4326 if Front_End_Inlining
4327 and then Analyzed (Corresponding_Body (Decl))
4329 Error_Msg_N ("pragma appears too late, ignored?", N);
4332 -- If the subprogram is a renaming as body, the body is just a
4333 -- call to the renamed subprogram, and inlining is trivially
4337 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4338 N_Subprogram_Renaming_Declaration
4344 Handled_Statement_Sequence
4345 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4348 Present (Exception_Handlers (Stats))
4349 or else Present (At_End_Proc (Stats));
4353 -- If body is not available, assume the best, the check is
4354 -- performed again when compiling enclosing package bodies.
4358 end Inlining_Not_Possible;
4364 procedure Make_Inline (Subp : Entity_Id) is
4365 Kind : constant Entity_Kind := Ekind (Subp);
4366 Inner_Subp : Entity_Id := Subp;
4369 -- Ignore if bad type, avoid cascaded error
4371 if Etype (Subp) = Any_Type then
4375 -- Ignore if all inlining is suppressed
4377 elsif Suppress_All_Inlining then
4381 -- If inlining is not possible, for now do not treat as an error
4383 elsif Inlining_Not_Possible (Subp) then
4387 -- Here we have a candidate for inlining, but we must exclude
4388 -- derived operations. Otherwise we would end up trying to inline
4389 -- a phantom declaration, and the result would be to drag in a
4390 -- body which has no direct inlining associated with it. That
4391 -- would not only be inefficient but would also result in the
4392 -- backend doing cross-unit inlining in cases where it was
4393 -- definitely inappropriate to do so.
4395 -- However, a simple Comes_From_Source test is insufficient, since
4396 -- we do want to allow inlining of generic instances which also do
4397 -- not come from source. We also need to recognize specs generated
4398 -- by the front-end for bodies that carry the pragma. Finally,
4399 -- predefined operators do not come from source but are not
4400 -- inlineable either.
4402 elsif Is_Generic_Instance (Subp)
4403 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4407 elsif not Comes_From_Source (Subp)
4408 and then Scope (Subp) /= Standard_Standard
4414 -- The referenced entity must either be the enclosing entity, or
4415 -- an entity declared within the current open scope.
4417 if Present (Scope (Subp))
4418 and then Scope (Subp) /= Current_Scope
4419 and then Subp /= Current_Scope
4422 ("argument of% must be entity in current scope", Assoc);
4426 -- Processing for procedure, operator or function. If subprogram
4427 -- is aliased (as for an instance) indicate that the renamed
4428 -- entity (if declared in the same unit) is inlined.
4430 if Is_Subprogram (Subp) then
4431 Inner_Subp := Ultimate_Alias (Inner_Subp);
4433 if In_Same_Source_Unit (Subp, Inner_Subp) then
4434 Set_Inline_Flags (Inner_Subp);
4436 Decl := Parent (Parent (Inner_Subp));
4438 if Nkind (Decl) = N_Subprogram_Declaration
4439 and then Present (Corresponding_Body (Decl))
4441 Set_Inline_Flags (Corresponding_Body (Decl));
4443 elsif Is_Generic_Instance (Subp) then
4445 -- Indicate that the body needs to be created for
4446 -- inlining subsequent calls. The instantiation node
4447 -- follows the declaration of the wrapper package
4450 if Scope (Subp) /= Standard_Standard
4452 Need_Subprogram_Instance_Body
4453 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4463 -- For a generic subprogram set flag as well, for use at the point
4464 -- of instantiation, to determine whether the body should be
4467 elsif Is_Generic_Subprogram (Subp) then
4468 Set_Inline_Flags (Subp);
4471 -- Literals are by definition inlined
4473 elsif Kind = E_Enumeration_Literal then
4476 -- Anything else is an error
4480 ("expect subprogram name for pragma%", Assoc);
4484 ----------------------
4485 -- Set_Inline_Flags --
4486 ----------------------
4488 procedure Set_Inline_Flags (Subp : Entity_Id) is
4491 Set_Is_Inlined (Subp);
4494 if not Has_Pragma_Inline (Subp) then
4495 Set_Has_Pragma_Inline (Subp);
4499 if Prag_Id = Pragma_Inline_Always then
4500 Set_Has_Pragma_Inline_Always (Subp);
4502 end Set_Inline_Flags;
4504 -- Start of processing for Process_Inline
4507 Check_No_Identifiers;
4508 Check_At_Least_N_Arguments (1);
4511 Inline_Processing_Required := True;
4515 while Present (Assoc) loop
4516 Subp_Id := Get_Pragma_Arg (Assoc);
4520 if Is_Entity_Name (Subp_Id) then
4521 Subp := Entity (Subp_Id);
4523 if Subp = Any_Id then
4525 -- If previous error, avoid cascaded errors
4533 -- For the pragma case, climb homonym chain. This is
4534 -- what implements allowing the pragma in the renaming
4535 -- case, with the result applying to the ancestors.
4537 if not From_Aspect_Specification (N) then
4538 while Present (Homonym (Subp))
4539 and then Scope (Homonym (Subp)) = Current_Scope
4541 Make_Inline (Homonym (Subp));
4542 Subp := Homonym (Subp);
4550 ("inappropriate argument for pragma%", Assoc);
4553 and then Warn_On_Redundant_Constructs
4554 and then not Suppress_All_Inlining
4556 if Inlining_Not_Possible (Subp) then
4558 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4561 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4569 ----------------------------
4570 -- Process_Interface_Name --
4571 ----------------------------
4573 procedure Process_Interface_Name
4574 (Subprogram_Def : Entity_Id;
4580 String_Val : String_Id;
4582 procedure Check_Form_Of_Interface_Name
4584 Ext_Name_Case : Boolean);
4585 -- SN is a string literal node for an interface name. This routine
4586 -- performs some minimal checks that the name is reasonable. In
4587 -- particular that no spaces or other obviously incorrect characters
4588 -- appear. This is only a warning, since any characters are allowed.
4589 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4591 ----------------------------------
4592 -- Check_Form_Of_Interface_Name --
4593 ----------------------------------
4595 procedure Check_Form_Of_Interface_Name
4597 Ext_Name_Case : Boolean)
4599 S : constant String_Id := Strval (Expr_Value_S (SN));
4600 SL : constant Nat := String_Length (S);
4605 Error_Msg_N ("interface name cannot be null string", SN);
4608 for J in 1 .. SL loop
4609 C := Get_String_Char (S, J);
4611 -- Look for dubious character and issue unconditional warning.
4612 -- Definitely dubious if not in character range.
4614 if not In_Character_Range (C)
4616 -- For all cases except CLI target,
4617 -- commas, spaces and slashes are dubious (in CLI, we use
4618 -- commas and backslashes in external names to specify
4619 -- assembly version and public key, while slashes and spaces
4620 -- can be used in names to mark nested classes and
4623 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4624 and then (Get_Character (C) = ','
4626 Get_Character (C) = '\'))
4627 or else (VM_Target /= CLI_Target
4628 and then (Get_Character (C) = ' '
4630 Get_Character (C) = '/'))
4633 ("?interface name contains illegal character",
4634 Sloc (SN) + Source_Ptr (J));
4637 end Check_Form_Of_Interface_Name;
4639 -- Start of processing for Process_Interface_Name
4642 if No (Link_Arg) then
4643 if No (Ext_Arg) then
4644 if VM_Target = CLI_Target
4645 and then Ekind (Subprogram_Def) = E_Package
4646 and then Nkind (Parent (Subprogram_Def)) =
4647 N_Package_Specification
4648 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4653 (Generic_Parent (Parent (Subprogram_Def))));
4658 elsif Chars (Ext_Arg) = Name_Link_Name then
4660 Link_Nam := Expression (Ext_Arg);
4663 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4664 Ext_Nam := Expression (Ext_Arg);
4669 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4670 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4671 Ext_Nam := Expression (Ext_Arg);
4672 Link_Nam := Expression (Link_Arg);
4675 -- Check expressions for external name and link name are static
4677 if Present (Ext_Nam) then
4678 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4679 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4681 -- Verify that external name is not the name of a local entity,
4682 -- which would hide the imported one and could lead to run-time
4683 -- surprises. The problem can only arise for entities declared in
4684 -- a package body (otherwise the external name is fully qualified
4685 -- and will not conflict).
4693 if Prag_Id = Pragma_Import then
4694 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4696 E := Entity_Id (Get_Name_Table_Info (Nam));
4698 if Nam /= Chars (Subprogram_Def)
4699 and then Present (E)
4700 and then not Is_Overloadable (E)
4701 and then Is_Immediately_Visible (E)
4702 and then not Is_Imported (E)
4703 and then Ekind (Scope (E)) = E_Package
4706 while Present (Par) loop
4707 if Nkind (Par) = N_Package_Body then
4708 Error_Msg_Sloc := Sloc (E);
4710 ("imported entity is hidden by & declared#",
4715 Par := Parent (Par);
4722 if Present (Link_Nam) then
4723 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4724 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4727 -- If there is no link name, just set the external name
4729 if No (Link_Nam) then
4730 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4732 -- For the Link_Name case, the given literal is preceded by an
4733 -- asterisk, which indicates to GCC that the given name should be
4734 -- taken literally, and in particular that no prepending of
4735 -- underlines should occur, even in systems where this is the
4741 if VM_Target = No_VM then
4742 Store_String_Char (Get_Char_Code ('*'));
4745 String_Val := Strval (Expr_Value_S (Link_Nam));
4746 Store_String_Chars (String_Val);
4748 Make_String_Literal (Sloc (Link_Nam),
4749 Strval => End_String);
4752 -- Set the interface name. If the entity is a generic instance, use
4753 -- its alias, which is the callable entity.
4755 if Is_Generic_Instance (Subprogram_Def) then
4756 Set_Encoded_Interface_Name
4757 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
4759 Set_Encoded_Interface_Name
4760 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4763 -- We allow duplicated export names in CIL/Java, as they are always
4764 -- enclosed in a namespace that differentiates them, and overloaded
4765 -- entities are supported by the VM.
4767 if Convention (Subprogram_Def) /= Convention_CIL
4768 and then 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 when Pragma_Annotate => Annotate : begin
6095 Check_At_Least_N_Arguments (1);
6096 Check_Arg_Is_Identifier (Arg1);
6097 Check_No_Identifiers;
6105 -- Second unanalyzed parameter is optional
6111 while Present (Arg) loop
6112 Exp := Get_Pragma_Arg (Arg);
6115 if Is_Entity_Name (Exp) then
6118 -- For string literals, we assume Standard_String as the
6119 -- type, unless the string contains wide or wide_wide
6122 elsif Nkind (Exp) = N_String_Literal then
6123 if Has_Wide_Wide_Character (Exp) then
6124 Resolve (Exp, Standard_Wide_Wide_String);
6125 elsif Has_Wide_Character (Exp) then
6126 Resolve (Exp, Standard_Wide_String);
6128 Resolve (Exp, Standard_String);
6131 elsif Is_Overloaded (Exp) then
6133 ("ambiguous argument for pragma%", Exp);
6149 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6150 -- [, [Message =>] Static_String_EXPRESSION]);
6152 when Pragma_Assert => Assert : declare
6158 Check_At_Least_N_Arguments (1);
6159 Check_At_Most_N_Arguments (2);
6160 Check_Arg_Order ((Name_Check, Name_Message));
6161 Check_Optional_Identifier (Arg1, Name_Check);
6163 -- We treat pragma Assert as equivalent to:
6165 -- pragma Check (Assertion, condition [, msg]);
6167 -- So rewrite pragma in this manner, and analyze the result
6169 Expr := Get_Pragma_Arg (Arg1);
6171 Make_Pragma_Argument_Association (Loc,
6172 Expression => Make_Identifier (Loc, Name_Assertion)),
6174 Make_Pragma_Argument_Association (Sloc (Expr),
6175 Expression => Expr));
6177 if Arg_Count > 1 then
6178 Check_Optional_Identifier (Arg2, Name_Message);
6179 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6180 Append_To (Newa, Relocate_Node (Arg2));
6185 Chars => Name_Check,
6186 Pragma_Argument_Associations => Newa));
6190 ----------------------
6191 -- Assertion_Policy --
6192 ----------------------
6194 -- pragma Assertion_Policy (Check | Ignore)
6196 when Pragma_Assertion_Policy => Assertion_Policy : declare
6201 Check_Valid_Configuration_Pragma;
6202 Check_Arg_Count (1);
6203 Check_No_Identifiers;
6204 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6206 -- We treat pragma Assertion_Policy as equivalent to:
6208 -- pragma Check_Policy (Assertion, policy)
6210 -- So rewrite the pragma in that manner and link on to the chain
6211 -- of Check_Policy pragmas, marking the pragma as analyzed.
6213 Policy := Get_Pragma_Arg (Arg1);
6217 Chars => Name_Check_Policy,
6219 Pragma_Argument_Associations => New_List (
6220 Make_Pragma_Argument_Association (Loc,
6221 Expression => Make_Identifier (Loc, Name_Assertion)),
6223 Make_Pragma_Argument_Association (Loc,
6225 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6228 Set_Next_Pragma (N, Opt.Check_Policy_List);
6229 Opt.Check_Policy_List := N;
6230 end Assertion_Policy;
6232 ------------------------------
6233 -- Assume_No_Invalid_Values --
6234 ------------------------------
6236 -- pragma Assume_No_Invalid_Values (On | Off);
6238 when Pragma_Assume_No_Invalid_Values =>
6240 Check_Valid_Configuration_Pragma;
6241 Check_Arg_Count (1);
6242 Check_No_Identifiers;
6243 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6245 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6246 Assume_No_Invalid_Values := True;
6248 Assume_No_Invalid_Values := False;
6255 -- pragma AST_Entry (entry_IDENTIFIER);
6257 when Pragma_AST_Entry => AST_Entry : declare
6263 Check_Arg_Count (1);
6264 Check_No_Identifiers;
6265 Check_Arg_Is_Local_Name (Arg1);
6266 Ent := Entity (Get_Pragma_Arg (Arg1));
6268 -- Note: the implementation of the AST_Entry pragma could handle
6269 -- the entry family case fine, but for now we are consistent with
6270 -- the DEC rules, and do not allow the pragma, which of course
6271 -- has the effect of also forbidding the attribute.
6273 if Ekind (Ent) /= E_Entry then
6275 ("pragma% argument must be simple entry name", Arg1);
6277 elsif Is_AST_Entry (Ent) then
6279 ("duplicate % pragma for entry", Arg1);
6281 elsif Has_Homonym (Ent) then
6283 ("pragma% argument cannot specify overloaded entry", Arg1);
6287 FF : constant Entity_Id := First_Formal (Ent);
6290 if Present (FF) then
6291 if Present (Next_Formal (FF)) then
6293 ("entry for pragma% can have only one argument",
6296 elsif Parameter_Mode (FF) /= E_In_Parameter then
6298 ("entry parameter for pragma% must have mode IN",
6304 Set_Is_AST_Entry (Ent);
6312 -- pragma Asynchronous (LOCAL_NAME);
6314 when Pragma_Asynchronous => Asynchronous : declare
6322 procedure Process_Async_Pragma;
6323 -- Common processing for procedure and access-to-procedure case
6325 --------------------------
6326 -- Process_Async_Pragma --
6327 --------------------------
6329 procedure Process_Async_Pragma is
6332 Set_Is_Asynchronous (Nm);
6336 -- The formals should be of mode IN (RM E.4.1(6))
6339 while Present (S) loop
6340 Formal := Defining_Identifier (S);
6342 if Nkind (Formal) = N_Defining_Identifier
6343 and then Ekind (Formal) /= E_In_Parameter
6346 ("pragma% procedure can only have IN parameter",
6353 Set_Is_Asynchronous (Nm);
6354 end Process_Async_Pragma;
6356 -- Start of processing for pragma Asynchronous
6359 Check_Ada_83_Warning;
6360 Check_No_Identifiers;
6361 Check_Arg_Count (1);
6362 Check_Arg_Is_Local_Name (Arg1);
6364 if Debug_Flag_U then
6368 C_Ent := Cunit_Entity (Current_Sem_Unit);
6369 Analyze (Get_Pragma_Arg (Arg1));
6370 Nm := Entity (Get_Pragma_Arg (Arg1));
6372 if not Is_Remote_Call_Interface (C_Ent)
6373 and then not Is_Remote_Types (C_Ent)
6375 -- This pragma should only appear in an RCI or Remote Types
6376 -- unit (RM E.4.1(4)).
6379 ("pragma% not in Remote_Call_Interface or " &
6380 "Remote_Types unit");
6383 if Ekind (Nm) = E_Procedure
6384 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6386 if not Is_Remote_Call_Interface (Nm) then
6388 ("pragma% cannot be applied on non-remote procedure",
6392 L := Parameter_Specifications (Parent (Nm));
6393 Process_Async_Pragma;
6396 elsif Ekind (Nm) = E_Function then
6398 ("pragma% cannot be applied to function", Arg1);
6400 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6401 if Is_Record_Type (Nm) then
6403 -- A record type that is the Equivalent_Type for a remote
6404 -- access-to-subprogram type.
6406 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6409 -- A non-expanded RAS type (distribution is not enabled)
6411 N := Declaration_Node (Nm);
6414 if Nkind (N) = N_Full_Type_Declaration
6415 and then Nkind (Type_Definition (N)) =
6416 N_Access_Procedure_Definition
6418 L := Parameter_Specifications (Type_Definition (N));
6419 Process_Async_Pragma;
6421 if Is_Asynchronous (Nm)
6422 and then Expander_Active
6423 and then Get_PCS_Name /= Name_No_DSA
6425 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6430 ("pragma% cannot reference access-to-function type",
6434 -- Only other possibility is Access-to-class-wide type
6436 elsif Is_Access_Type (Nm)
6437 and then Is_Class_Wide_Type (Designated_Type (Nm))
6439 Check_First_Subtype (Arg1);
6440 Set_Is_Asynchronous (Nm);
6441 if Expander_Active then
6442 RACW_Type_Is_Asynchronous (Nm);
6446 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6454 -- pragma Atomic (LOCAL_NAME);
6456 when Pragma_Atomic =>
6457 Process_Atomic_Shared_Volatile;
6459 -----------------------
6460 -- Atomic_Components --
6461 -----------------------
6463 -- pragma Atomic_Components (array_LOCAL_NAME);
6465 -- This processing is shared by Volatile_Components
6467 when Pragma_Atomic_Components |
6468 Pragma_Volatile_Components =>
6470 Atomic_Components : declare
6477 Check_Ada_83_Warning;
6478 Check_No_Identifiers;
6479 Check_Arg_Count (1);
6480 Check_Arg_Is_Local_Name (Arg1);
6481 E_Id := Get_Pragma_Arg (Arg1);
6483 if Etype (E_Id) = Any_Type then
6489 Check_Duplicate_Pragma (E);
6491 if Rep_Item_Too_Early (E, N)
6493 Rep_Item_Too_Late (E, N)
6498 D := Declaration_Node (E);
6501 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6503 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6504 and then Nkind (D) = N_Object_Declaration
6505 and then Nkind (Object_Definition (D)) =
6506 N_Constrained_Array_Definition)
6508 -- The flag is set on the object, or on the base type
6510 if Nkind (D) /= N_Object_Declaration then
6514 Set_Has_Volatile_Components (E);
6516 if Prag_Id = Pragma_Atomic_Components then
6517 Set_Has_Atomic_Components (E);
6521 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6523 end Atomic_Components;
6525 --------------------
6526 -- Attach_Handler --
6527 --------------------
6529 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6531 when Pragma_Attach_Handler =>
6532 Check_Ada_83_Warning;
6533 Check_No_Identifiers;
6534 Check_Arg_Count (2);
6536 if No_Run_Time_Mode then
6537 Error_Msg_CRT ("Attach_Handler pragma", N);
6539 Check_Interrupt_Or_Attach_Handler;
6541 -- The expression that designates the attribute may depend on a
6542 -- discriminant, and is therefore a per- object expression, to
6543 -- be expanded in the init proc. If expansion is enabled, then
6544 -- perform semantic checks on a copy only.
6546 if Expander_Active then
6548 Temp : constant Node_Id :=
6549 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6551 Set_Parent (Temp, N);
6552 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6556 Analyze (Get_Pragma_Arg (Arg2));
6557 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6560 Process_Interrupt_Or_Attach_Handler;
6563 --------------------
6564 -- C_Pass_By_Copy --
6565 --------------------
6567 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6569 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6575 Check_Valid_Configuration_Pragma;
6576 Check_Arg_Count (1);
6577 Check_Optional_Identifier (Arg1, "max_size");
6579 Arg := Get_Pragma_Arg (Arg1);
6580 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6582 Val := Expr_Value (Arg);
6586 ("maximum size for pragma% must be positive", Arg1);
6588 elsif UI_Is_In_Int_Range (Val) then
6589 Default_C_Record_Mechanism := UI_To_Int (Val);
6591 -- If a giant value is given, Int'Last will do well enough.
6592 -- If sometime someone complains that a record larger than
6593 -- two gigabytes is not copied, we will worry about it then!
6596 Default_C_Record_Mechanism := Mechanism_Type'Last;
6604 -- pragma Check ([Name =>] Identifier,
6605 -- [Check =>] Boolean_Expression
6606 -- [,[Message =>] String_Expression]);
6608 when Pragma_Check => Check : declare
6613 -- Set True if category of assertions referenced by Name enabled
6617 Check_At_Least_N_Arguments (2);
6618 Check_At_Most_N_Arguments (3);
6619 Check_Optional_Identifier (Arg1, Name_Name);
6620 Check_Optional_Identifier (Arg2, Name_Check);
6622 if Arg_Count = 3 then
6623 Check_Optional_Identifier (Arg3, Name_Message);
6624 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6627 Check_Arg_Is_Identifier (Arg1);
6629 -- Indicate if pragma is enabled. The Original_Node reference here
6630 -- is to deal with pragma Assert rewritten as a Check pragma.
6632 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6635 Set_Pragma_Enabled (N);
6636 Set_Pragma_Enabled (Original_Node (N));
6637 Set_SCO_Pragma_Enabled (Loc);
6640 -- If expansion is active and the check is not enabled then we
6641 -- rewrite the Check as:
6643 -- if False and then condition then
6647 -- The reason we do this rewriting during semantic analysis rather
6648 -- than as part of normal expansion is that we cannot analyze and
6649 -- expand the code for the boolean expression directly, or it may
6650 -- cause insertion of actions that would escape the attempt to
6651 -- suppress the check code.
6653 -- Note that the Sloc for the if statement corresponds to the
6654 -- argument condition, not the pragma itself. The reason for this
6655 -- is that we may generate a warning if the condition is False at
6656 -- compile time, and we do not want to delete this warning when we
6657 -- delete the if statement.
6659 Expr := Get_Pragma_Arg (Arg2);
6661 if Expander_Active and then not Check_On then
6662 Eloc := Sloc (Expr);
6665 Make_If_Statement (Eloc,
6667 Make_And_Then (Eloc,
6668 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6669 Right_Opnd => Expr),
6670 Then_Statements => New_List (
6671 Make_Null_Statement (Eloc))));
6678 Analyze_And_Resolve (Expr, Any_Boolean);
6686 -- pragma Check_Name (check_IDENTIFIER);
6688 when Pragma_Check_Name =>
6689 Check_No_Identifiers;
6691 Check_Valid_Configuration_Pragma;
6692 Check_Arg_Count (1);
6693 Check_Arg_Is_Identifier (Arg1);
6696 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6699 for J in Check_Names.First .. Check_Names.Last loop
6700 if Check_Names.Table (J) = Nam then
6705 Check_Names.Append (Nam);
6712 -- pragma Check_Policy (
6713 -- [Name =>] IDENTIFIER,
6714 -- [Policy =>] POLICY_IDENTIFIER);
6716 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6718 -- Note: this is a configuration pragma, but it is allowed to appear
6721 when Pragma_Check_Policy =>
6723 Check_Arg_Count (2);
6724 Check_Optional_Identifier (Arg1, Name_Name);
6725 Check_Optional_Identifier (Arg2, Name_Policy);
6727 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6729 -- A Check_Policy pragma can appear either as a configuration
6730 -- pragma, or in a declarative part or a package spec (see RM
6731 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6732 -- followed for Check_Policy).
6734 if not Is_Configuration_Pragma then
6735 Check_Is_In_Decl_Part_Or_Package_Spec;
6738 Set_Next_Pragma (N, Opt.Check_Policy_List);
6739 Opt.Check_Policy_List := N;
6741 ---------------------
6742 -- CIL_Constructor --
6743 ---------------------
6745 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6747 -- Processing for this pragma is shared with Java_Constructor
6753 -- pragma Comment (static_string_EXPRESSION)
6755 -- Processing for pragma Comment shares the circuitry for pragma
6756 -- Ident. The only differences are that Ident enforces a limit of 31
6757 -- characters on its argument, and also enforces limitations on
6758 -- placement for DEC compatibility. Pragma Comment shares neither of
6759 -- these restrictions.
6765 -- pragma Common_Object (
6766 -- [Internal =>] LOCAL_NAME
6767 -- [, [External =>] EXTERNAL_SYMBOL]
6768 -- [, [Size =>] EXTERNAL_SYMBOL]);
6770 -- Processing for this pragma is shared with Psect_Object
6772 ------------------------
6773 -- Compile_Time_Error --
6774 ------------------------
6776 -- pragma Compile_Time_Error
6777 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6779 when Pragma_Compile_Time_Error =>
6781 Process_Compile_Time_Warning_Or_Error;
6783 --------------------------
6784 -- Compile_Time_Warning --
6785 --------------------------
6787 -- pragma Compile_Time_Warning
6788 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6790 when Pragma_Compile_Time_Warning =>
6792 Process_Compile_Time_Warning_Or_Error;
6798 when Pragma_Compiler_Unit =>
6800 Check_Arg_Count (0);
6801 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6803 -----------------------------
6804 -- Complete_Representation --
6805 -----------------------------
6807 -- pragma Complete_Representation;
6809 when Pragma_Complete_Representation =>
6811 Check_Arg_Count (0);
6813 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6815 ("pragma & must appear within record representation clause");
6818 ----------------------------
6819 -- Complex_Representation --
6820 ----------------------------
6822 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6824 when Pragma_Complex_Representation => Complex_Representation : declare
6831 Check_Arg_Count (1);
6832 Check_Optional_Identifier (Arg1, Name_Entity);
6833 Check_Arg_Is_Local_Name (Arg1);
6834 E_Id := Get_Pragma_Arg (Arg1);
6836 if Etype (E_Id) = Any_Type then
6842 if not Is_Record_Type (E) then
6844 ("argument for pragma% must be record type", Arg1);
6847 Ent := First_Entity (E);
6850 or else No (Next_Entity (Ent))
6851 or else Present (Next_Entity (Next_Entity (Ent)))
6852 or else not Is_Floating_Point_Type (Etype (Ent))
6853 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6856 ("record for pragma% must have two fields of the same "
6857 & "floating-point type", Arg1);
6860 Set_Has_Complex_Representation (Base_Type (E));
6862 -- We need to treat the type has having a non-standard
6863 -- representation, for back-end purposes, even though in
6864 -- general a complex will have the default representation
6865 -- of a record with two real components.
6867 Set_Has_Non_Standard_Rep (Base_Type (E));
6869 end Complex_Representation;
6871 -------------------------
6872 -- Component_Alignment --
6873 -------------------------
6875 -- pragma Component_Alignment (
6876 -- [Form =>] ALIGNMENT_CHOICE
6877 -- [, [Name =>] type_LOCAL_NAME]);
6879 -- ALIGNMENT_CHOICE ::=
6881 -- | Component_Size_4
6885 when Pragma_Component_Alignment => Component_AlignmentP : declare
6886 Args : Args_List (1 .. 2);
6887 Names : constant Name_List (1 .. 2) := (
6891 Form : Node_Id renames Args (1);
6892 Name : Node_Id renames Args (2);
6894 Atype : Component_Alignment_Kind;
6899 Gather_Associations (Names, Args);
6902 Error_Pragma ("missing Form argument for pragma%");
6905 Check_Arg_Is_Identifier (Form);
6907 -- Get proper alignment, note that Default = Component_Size on all
6908 -- machines we have so far, and we want to set this value rather
6909 -- than the default value to indicate that it has been explicitly
6910 -- set (and thus will not get overridden by the default component
6911 -- alignment for the current scope)
6913 if Chars (Form) = Name_Component_Size then
6914 Atype := Calign_Component_Size;
6916 elsif Chars (Form) = Name_Component_Size_4 then
6917 Atype := Calign_Component_Size_4;
6919 elsif Chars (Form) = Name_Default then
6920 Atype := Calign_Component_Size;
6922 elsif Chars (Form) = Name_Storage_Unit then
6923 Atype := Calign_Storage_Unit;
6927 ("invalid Form parameter for pragma%", Form);
6930 -- Case with no name, supplied, affects scope table entry
6934 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6936 -- Case of name supplied
6939 Check_Arg_Is_Local_Name (Name);
6941 Typ := Entity (Name);
6944 or else Rep_Item_Too_Early (Typ, N)
6948 Typ := Underlying_Type (Typ);
6951 if not Is_Record_Type (Typ)
6952 and then not Is_Array_Type (Typ)
6955 ("Name parameter of pragma% must identify record or " &
6956 "array type", Name);
6959 -- An explicit Component_Alignment pragma overrides an
6960 -- implicit pragma Pack, but not an explicit one.
6962 if not Has_Pragma_Pack (Base_Type (Typ)) then
6963 Set_Is_Packed (Base_Type (Typ), False);
6964 Set_Component_Alignment (Base_Type (Typ), Atype);
6967 end Component_AlignmentP;
6973 -- pragma Controlled (first_subtype_LOCAL_NAME);
6975 when Pragma_Controlled => Controlled : declare
6979 Check_No_Identifiers;
6980 Check_Arg_Count (1);
6981 Check_Arg_Is_Local_Name (Arg1);
6982 Arg := Get_Pragma_Arg (Arg1);
6984 if not Is_Entity_Name (Arg)
6985 or else not Is_Access_Type (Entity (Arg))
6987 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6989 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6997 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6998 -- [Entity =>] LOCAL_NAME);
7000 when Pragma_Convention => Convention : declare
7003 pragma Warnings (Off, C);
7004 pragma Warnings (Off, E);
7006 Check_Arg_Order ((Name_Convention, Name_Entity));
7007 Check_Ada_83_Warning;
7008 Check_Arg_Count (2);
7009 Process_Convention (C, E);
7012 ---------------------------
7013 -- Convention_Identifier --
7014 ---------------------------
7016 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7017 -- [Convention =>] convention_IDENTIFIER);
7019 when Pragma_Convention_Identifier => Convention_Identifier : declare
7025 Check_Arg_Order ((Name_Name, Name_Convention));
7026 Check_Arg_Count (2);
7027 Check_Optional_Identifier (Arg1, Name_Name);
7028 Check_Optional_Identifier (Arg2, Name_Convention);
7029 Check_Arg_Is_Identifier (Arg1);
7030 Check_Arg_Is_Identifier (Arg2);
7031 Idnam := Chars (Get_Pragma_Arg (Arg1));
7032 Cname := Chars (Get_Pragma_Arg (Arg2));
7034 if Is_Convention_Name (Cname) then
7035 Record_Convention_Identifier
7036 (Idnam, Get_Convention_Id (Cname));
7039 ("second arg for % pragma must be convention", Arg2);
7041 end Convention_Identifier;
7047 -- pragma CPP_Class ([Entity =>] local_NAME)
7049 when Pragma_CPP_Class => CPP_Class : declare
7054 if Warn_On_Obsolescent_Feature then
7056 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7057 " by pragma import?", N);
7061 Check_Arg_Count (1);
7062 Check_Optional_Identifier (Arg1, Name_Entity);
7063 Check_Arg_Is_Local_Name (Arg1);
7065 Arg := Get_Pragma_Arg (Arg1);
7068 if Etype (Arg) = Any_Type then
7072 if not Is_Entity_Name (Arg)
7073 or else not Is_Type (Entity (Arg))
7075 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7078 Typ := Entity (Arg);
7080 if not Is_Tagged_Type (Typ) then
7081 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7084 -- Types treated as CPP classes must be declared limited (note:
7085 -- this used to be a warning but there is no real benefit to it
7086 -- since we did effectively intend to treat the type as limited
7089 if not Is_Limited_Type (Typ) then
7091 ("imported 'C'P'P type must be limited",
7092 Get_Pragma_Arg (Arg1));
7095 Set_Is_CPP_Class (Typ);
7096 Set_Convention (Typ, Convention_CPP);
7098 -- Imported CPP types must not have discriminants (because C++
7099 -- classes do not have discriminants).
7101 if Has_Discriminants (Typ) then
7103 ("imported 'C'P'P type cannot have discriminants",
7104 First (Discriminant_Specifications
7105 (Declaration_Node (Typ))));
7108 -- Components of imported CPP types must not have default
7109 -- expressions because the constructor (if any) is in the
7112 if Is_Incomplete_Or_Private_Type (Typ)
7113 and then No (Underlying_Type (Typ))
7115 -- It should be an error to apply pragma CPP to a private
7116 -- type if the underlying type is not visible (as it is
7117 -- for any representation item). For now, for backward
7118 -- compatibility we do nothing but we cannot check components
7119 -- because they are not available at this stage. All this code
7120 -- will be removed when we cleanup this obsolete GNAT pragma???
7126 Tdef : constant Node_Id :=
7127 Type_Definition (Declaration_Node (Typ));
7132 if Nkind (Tdef) = N_Record_Definition then
7133 Clist := Component_List (Tdef);
7135 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7136 Clist := Component_List (Record_Extension_Part (Tdef));
7139 if Present (Clist) then
7140 Comp := First (Component_Items (Clist));
7141 while Present (Comp) loop
7142 if Present (Expression (Comp)) then
7144 ("component of imported 'C'P'P type cannot have" &
7145 " default expression", Expression (Comp));
7155 ---------------------
7156 -- CPP_Constructor --
7157 ---------------------
7159 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7160 -- [, [External_Name =>] static_string_EXPRESSION ]
7161 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7163 when Pragma_CPP_Constructor => CPP_Constructor : declare
7167 Tag_Typ : Entity_Id;
7171 Check_At_Least_N_Arguments (1);
7172 Check_At_Most_N_Arguments (3);
7173 Check_Optional_Identifier (Arg1, Name_Entity);
7174 Check_Arg_Is_Local_Name (Arg1);
7176 Id := Get_Pragma_Arg (Arg1);
7177 Find_Program_Unit_Name (Id);
7179 -- If we did not find the name, we are done
7181 if Etype (Id) = Any_Type then
7185 Def_Id := Entity (Id);
7187 -- Check if already defined as constructor
7189 if Is_Constructor (Def_Id) then
7191 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7195 if Ekind (Def_Id) = E_Function
7196 and then (Is_CPP_Class (Etype (Def_Id))
7197 or else (Is_Class_Wide_Type (Etype (Def_Id))
7199 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7201 if Arg_Count >= 2 then
7202 Set_Imported (Def_Id);
7203 Set_Is_Public (Def_Id);
7204 Process_Interface_Name (Def_Id, Arg2, Arg3);
7207 Set_Has_Completion (Def_Id);
7208 Set_Is_Constructor (Def_Id);
7210 -- Imported C++ constructors are not dispatching primitives
7211 -- because in C++ they don't have a dispatch table slot.
7212 -- However, in Ada the constructor has the profile of a
7213 -- function that returns a tagged type and therefore it has
7214 -- been treated as a primitive operation during semantic
7215 -- analysis. We now remove it from the list of primitive
7216 -- operations of the type.
7218 if Is_Tagged_Type (Etype (Def_Id))
7219 and then not Is_Class_Wide_Type (Etype (Def_Id))
7221 pragma Assert (Is_Dispatching_Operation (Def_Id));
7222 Tag_Typ := Etype (Def_Id);
7224 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7225 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7229 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7230 Set_Is_Dispatching_Operation (Def_Id, False);
7233 -- For backward compatibility, if the constructor returns a
7234 -- class wide type, and we internally change the return type to
7235 -- the corresponding root type.
7237 if Is_Class_Wide_Type (Etype (Def_Id)) then
7238 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7242 ("pragma% requires function returning a 'C'P'P_Class type",
7245 end CPP_Constructor;
7251 when Pragma_CPP_Virtual => CPP_Virtual : declare
7255 if Warn_On_Obsolescent_Feature then
7257 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7266 when Pragma_CPP_Vtable => CPP_Vtable : declare
7270 if Warn_On_Obsolescent_Feature then
7272 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7281 -- pragma CPU (EXPRESSION);
7283 when Pragma_CPU => CPU : declare
7284 P : constant Node_Id := Parent (N);
7289 Check_No_Identifiers;
7290 Check_Arg_Count (1);
7294 if Nkind (P) = N_Subprogram_Body then
7295 Check_In_Main_Program;
7297 Arg := Get_Pragma_Arg (Arg1);
7298 Analyze_And_Resolve (Arg, Any_Integer);
7302 if not Is_Static_Expression (Arg) then
7303 Flag_Non_Static_Expr
7304 ("main subprogram affinity is not static!", Arg);
7307 -- If constraint error, then we already signalled an error
7309 elsif Raises_Constraint_Error (Arg) then
7312 -- Otherwise check in range
7316 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7317 -- This is the entity System.Multiprocessors.CPU_Range;
7319 Val : constant Uint := Expr_Value (Arg);
7322 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7324 Val > Expr_Value (Type_High_Bound (CPU_Id))
7327 ("main subprogram CPU is out of range", Arg1);
7333 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7337 elsif Nkind (P) = N_Task_Definition then
7338 Arg := Get_Pragma_Arg (Arg1);
7340 -- The expression must be analyzed in the special manner
7341 -- described in "Handling of Default and Per-Object
7342 -- Expressions" in sem.ads.
7344 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7346 -- Anything else is incorrect
7352 if Has_Pragma_CPU (P) then
7353 Error_Pragma ("duplicate pragma% not allowed");
7355 Set_Has_Pragma_CPU (P, True);
7357 if Nkind (P) = N_Task_Definition then
7358 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7367 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7369 when Pragma_Debug => Debug : declare
7377 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7380 if Arg_Count = 2 then
7383 Left_Opnd => Relocate_Node (Cond),
7384 Right_Opnd => Get_Pragma_Arg (Arg1));
7387 -- Rewrite into a conditional with an appropriate condition. We
7388 -- wrap the procedure call in a block so that overhead from e.g.
7389 -- use of the secondary stack does not generate execution overhead
7390 -- for suppressed conditions.
7392 Rewrite (N, Make_Implicit_If_Statement (N,
7394 Then_Statements => New_List (
7395 Make_Block_Statement (Loc,
7396 Handled_Statement_Sequence =>
7397 Make_Handled_Sequence_Of_Statements (Loc,
7398 Statements => New_List (
7399 Relocate_Node (Debug_Statement (N))))))));
7407 -- pragma Debug_Policy (Check | Ignore)
7409 when Pragma_Debug_Policy =>
7411 Check_Arg_Count (1);
7412 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7413 Debug_Pragmas_Enabled :=
7414 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7416 ---------------------
7417 -- Detect_Blocking --
7418 ---------------------
7420 -- pragma Detect_Blocking;
7422 when Pragma_Detect_Blocking =>
7424 Check_Arg_Count (0);
7425 Check_Valid_Configuration_Pragma;
7426 Detect_Blocking := True;
7428 --------------------------
7429 -- Default_Storage_Pool --
7430 --------------------------
7432 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7434 when Pragma_Default_Storage_Pool =>
7436 Check_Arg_Count (1);
7438 -- Default_Storage_Pool can appear as a configuration pragma, or
7439 -- in a declarative part or a package spec.
7441 if not Is_Configuration_Pragma then
7442 Check_Is_In_Decl_Part_Or_Package_Spec;
7445 -- Case of Default_Storage_Pool (null);
7447 if Nkind (Expression (Arg1)) = N_Null then
7448 Analyze (Expression (Arg1));
7450 -- This is an odd case, this is not really an expression, so
7451 -- we don't have a type for it. So just set the type to Empty.
7453 Set_Etype (Expression (Arg1), Empty);
7455 -- Case of Default_Storage_Pool (storage_pool_NAME);
7458 -- If it's a configuration pragma, then the only allowed
7459 -- argument is "null".
7461 if Is_Configuration_Pragma then
7462 Error_Pragma_Arg ("NULL expected", Arg1);
7465 -- The expected type for a non-"null" argument is
7466 -- Root_Storage_Pool'Class.
7469 (Get_Pragma_Arg (Arg1),
7470 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7473 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7474 -- for an access type will use this information to set the
7475 -- appropriate attributes of the access type.
7477 Default_Pool := Expression (Arg1);
7483 when Pragma_Dimension =>
7485 Check_Arg_Count (4);
7486 Check_No_Identifiers;
7487 Check_Arg_Is_Local_Name (Arg1);
7489 if not Is_Type (Arg1) then
7490 Error_Pragma ("first argument for pragma% must be subtype");
7493 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7494 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7495 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7501 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7503 when Pragma_Discard_Names => Discard_Names : declare
7508 Check_Ada_83_Warning;
7510 -- Deal with configuration pragma case
7512 if Arg_Count = 0 and then Is_Configuration_Pragma then
7513 Global_Discard_Names := True;
7516 -- Otherwise, check correct appropriate context
7519 Check_Is_In_Decl_Part_Or_Package_Spec;
7521 if Arg_Count = 0 then
7523 -- If there is no parameter, then from now on this pragma
7524 -- applies to any enumeration, exception or tagged type
7525 -- defined in the current declarative part, and recursively
7526 -- to any nested scope.
7528 Set_Discard_Names (Current_Scope);
7532 Check_Arg_Count (1);
7533 Check_Optional_Identifier (Arg1, Name_On);
7534 Check_Arg_Is_Local_Name (Arg1);
7536 E_Id := Get_Pragma_Arg (Arg1);
7538 if Etype (E_Id) = Any_Type then
7544 if (Is_First_Subtype (E)
7546 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7547 or else Ekind (E) = E_Exception
7549 Set_Discard_Names (E);
7552 ("inappropriate entity for pragma%", Arg1);
7563 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7565 when Pragma_Elaborate => Elaborate : declare
7570 -- Pragma must be in context items list of a compilation unit
7572 if not Is_In_Context_Clause then
7576 -- Must be at least one argument
7578 if Arg_Count = 0 then
7579 Error_Pragma ("pragma% requires at least one argument");
7582 -- In Ada 83 mode, there can be no items following it in the
7583 -- context list except other pragmas and implicit with clauses
7584 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7585 -- placement rule does not apply.
7587 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7589 while Present (Citem) loop
7590 if Nkind (Citem) = N_Pragma
7591 or else (Nkind (Citem) = N_With_Clause
7592 and then Implicit_With (Citem))
7597 ("(Ada 83) pragma% must be at end of context clause");
7604 -- Finally, the arguments must all be units mentioned in a with
7605 -- clause in the same context clause. Note we already checked (in
7606 -- Par.Prag) that the arguments are all identifiers or selected
7610 Outer : while Present (Arg) loop
7611 Citem := First (List_Containing (N));
7612 Inner : while Citem /= N loop
7613 if Nkind (Citem) = N_With_Clause
7614 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7616 Set_Elaborate_Present (Citem, True);
7617 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7618 Generate_Reference (Entity (Name (Citem)), Citem);
7620 -- With the pragma present, elaboration calls on
7621 -- subprograms from the named unit need no further
7622 -- checks, as long as the pragma appears in the current
7623 -- compilation unit. If the pragma appears in some unit
7624 -- in the context, there might still be a need for an
7625 -- Elaborate_All_Desirable from the current compilation
7626 -- to the named unit, so we keep the check enabled.
7628 if In_Extended_Main_Source_Unit (N) then
7629 Set_Suppress_Elaboration_Warnings
7630 (Entity (Name (Citem)));
7641 ("argument of pragma% is not with'ed unit", Arg);
7647 -- Give a warning if operating in static mode with -gnatwl
7648 -- (elaboration warnings enabled) switch set.
7650 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7652 ("?use of pragma Elaborate may not be safe", N);
7654 ("?use pragma Elaborate_All instead if possible", N);
7662 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7664 when Pragma_Elaborate_All => Elaborate_All : declare
7669 Check_Ada_83_Warning;
7671 -- Pragma must be in context items list of a compilation unit
7673 if not Is_In_Context_Clause then
7677 -- Must be at least one argument
7679 if Arg_Count = 0 then
7680 Error_Pragma ("pragma% requires at least one argument");
7683 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7684 -- have to appear at the end of the context clause, but may
7685 -- appear mixed in with other items, even in Ada 83 mode.
7687 -- Final check: the arguments must all be units mentioned in
7688 -- a with clause in the same context clause. Note that we
7689 -- already checked (in Par.Prag) that all the arguments are
7690 -- either identifiers or selected components.
7693 Outr : while Present (Arg) loop
7694 Citem := First (List_Containing (N));
7695 Innr : while Citem /= N loop
7696 if Nkind (Citem) = N_With_Clause
7697 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7699 Set_Elaborate_All_Present (Citem, True);
7700 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7702 -- Suppress warnings and elaboration checks on the named
7703 -- unit if the pragma is in the current compilation, as
7704 -- for pragma Elaborate.
7706 if In_Extended_Main_Source_Unit (N) then
7707 Set_Suppress_Elaboration_Warnings
7708 (Entity (Name (Citem)));
7717 Set_Error_Posted (N);
7719 ("argument of pragma% is not with'ed unit", Arg);
7726 --------------------
7727 -- Elaborate_Body --
7728 --------------------
7730 -- pragma Elaborate_Body [( library_unit_NAME )];
7732 when Pragma_Elaborate_Body => Elaborate_Body : declare
7733 Cunit_Node : Node_Id;
7734 Cunit_Ent : Entity_Id;
7737 Check_Ada_83_Warning;
7738 Check_Valid_Library_Unit_Pragma;
7740 if Nkind (N) = N_Null_Statement then
7744 Cunit_Node := Cunit (Current_Sem_Unit);
7745 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7747 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7750 Error_Pragma ("pragma% must refer to a spec, not a body");
7752 Set_Body_Required (Cunit_Node, True);
7753 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7755 -- If we are in dynamic elaboration mode, then we suppress
7756 -- elaboration warnings for the unit, since it is definitely
7757 -- fine NOT to do dynamic checks at the first level (and such
7758 -- checks will be suppressed because no elaboration boolean
7759 -- is created for Elaborate_Body packages).
7761 -- But in the static model of elaboration, Elaborate_Body is
7762 -- definitely NOT good enough to ensure elaboration safety on
7763 -- its own, since the body may WITH other units that are not
7764 -- safe from an elaboration point of view, so a client must
7765 -- still do an Elaborate_All on such units.
7767 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7768 -- Elaborate_Body always suppressed elab warnings.
7770 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7771 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7776 ------------------------
7777 -- Elaboration_Checks --
7778 ------------------------
7780 -- pragma Elaboration_Checks (Static | Dynamic);
7782 when Pragma_Elaboration_Checks =>
7784 Check_Arg_Count (1);
7785 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7786 Dynamic_Elaboration_Checks :=
7787 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7793 -- pragma Eliminate (
7794 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7795 -- [,[Entity =>] IDENTIFIER |
7796 -- SELECTED_COMPONENT |
7798 -- [, OVERLOADING_RESOLUTION]);
7800 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7803 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7806 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7808 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7809 -- Result_Type => result_SUBTYPE_NAME]
7811 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7812 -- SUBTYPE_NAME ::= STRING_LITERAL
7814 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7815 -- SOURCE_TRACE ::= STRING_LITERAL
7817 when Pragma_Eliminate => Eliminate : declare
7818 Args : Args_List (1 .. 5);
7819 Names : constant Name_List (1 .. 5) := (
7822 Name_Parameter_Types,
7824 Name_Source_Location);
7826 Unit_Name : Node_Id renames Args (1);
7827 Entity : Node_Id renames Args (2);
7828 Parameter_Types : Node_Id renames Args (3);
7829 Result_Type : Node_Id renames Args (4);
7830 Source_Location : Node_Id renames Args (5);
7834 Check_Valid_Configuration_Pragma;
7835 Gather_Associations (Names, Args);
7837 if No (Unit_Name) then
7838 Error_Pragma ("missing Unit_Name argument for pragma%");
7842 and then (Present (Parameter_Types)
7844 Present (Result_Type)
7846 Present (Source_Location))
7848 Error_Pragma ("missing Entity argument for pragma%");
7851 if (Present (Parameter_Types)
7853 Present (Result_Type))
7855 Present (Source_Location)
7858 ("parameter profile and source location cannot " &
7859 "be used together in pragma%");
7862 Process_Eliminate_Pragma
7876 -- [ Convention =>] convention_IDENTIFIER,
7877 -- [ Entity =>] local_NAME
7878 -- [, [External_Name =>] static_string_EXPRESSION ]
7879 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7881 when Pragma_Export => Export : declare
7885 pragma Warnings (Off, C);
7888 Check_Ada_83_Warning;
7894 Check_At_Least_N_Arguments (2);
7895 Check_At_Most_N_Arguments (4);
7896 Process_Convention (C, Def_Id);
7898 if Ekind (Def_Id) /= E_Constant then
7899 Note_Possible_Modification
7900 (Get_Pragma_Arg (Arg2), Sure => False);
7903 Process_Interface_Name (Def_Id, Arg3, Arg4);
7904 Set_Exported (Def_Id, Arg2);
7906 -- If the entity is a deferred constant, propagate the information
7907 -- to the full view, because gigi elaborates the full view only.
7909 if Ekind (Def_Id) = E_Constant
7910 and then Present (Full_View (Def_Id))
7913 Id2 : constant Entity_Id := Full_View (Def_Id);
7915 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7916 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7917 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7922 ----------------------
7923 -- Export_Exception --
7924 ----------------------
7926 -- pragma Export_Exception (
7927 -- [Internal =>] LOCAL_NAME
7928 -- [, [External =>] EXTERNAL_SYMBOL]
7929 -- [, [Form =>] Ada | VMS]
7930 -- [, [Code =>] static_integer_EXPRESSION]);
7932 when Pragma_Export_Exception => Export_Exception : declare
7933 Args : Args_List (1 .. 4);
7934 Names : constant Name_List (1 .. 4) := (
7940 Internal : Node_Id renames Args (1);
7941 External : Node_Id renames Args (2);
7942 Form : Node_Id renames Args (3);
7943 Code : Node_Id renames Args (4);
7948 if Inside_A_Generic then
7949 Error_Pragma ("pragma% cannot be used for generic entities");
7952 Gather_Associations (Names, Args);
7953 Process_Extended_Import_Export_Exception_Pragma (
7954 Arg_Internal => Internal,
7955 Arg_External => External,
7959 if not Is_VMS_Exception (Entity (Internal)) then
7960 Set_Exported (Entity (Internal), Internal);
7962 end Export_Exception;
7964 ---------------------
7965 -- Export_Function --
7966 ---------------------
7968 -- pragma Export_Function (
7969 -- [Internal =>] LOCAL_NAME
7970 -- [, [External =>] EXTERNAL_SYMBOL]
7971 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7972 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7973 -- [, [Mechanism =>] MECHANISM]
7974 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7976 -- EXTERNAL_SYMBOL ::=
7978 -- | static_string_EXPRESSION
7980 -- PARAMETER_TYPES ::=
7982 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7984 -- TYPE_DESIGNATOR ::=
7986 -- | subtype_Name ' Access
7990 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7992 -- MECHANISM_ASSOCIATION ::=
7993 -- [formal_parameter_NAME =>] MECHANISM_NAME
7995 -- MECHANISM_NAME ::=
7998 -- | Descriptor [([Class =>] CLASS_NAME)]
8000 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8002 when Pragma_Export_Function => Export_Function : declare
8003 Args : Args_List (1 .. 6);
8004 Names : constant Name_List (1 .. 6) := (
8007 Name_Parameter_Types,
8010 Name_Result_Mechanism);
8012 Internal : Node_Id renames Args (1);
8013 External : Node_Id renames Args (2);
8014 Parameter_Types : Node_Id renames Args (3);
8015 Result_Type : Node_Id renames Args (4);
8016 Mechanism : Node_Id renames Args (5);
8017 Result_Mechanism : Node_Id renames Args (6);
8021 Gather_Associations (Names, Args);
8022 Process_Extended_Import_Export_Subprogram_Pragma (
8023 Arg_Internal => Internal,
8024 Arg_External => External,
8025 Arg_Parameter_Types => Parameter_Types,
8026 Arg_Result_Type => Result_Type,
8027 Arg_Mechanism => Mechanism,
8028 Arg_Result_Mechanism => Result_Mechanism);
8029 end Export_Function;
8035 -- pragma Export_Object (
8036 -- [Internal =>] LOCAL_NAME
8037 -- [, [External =>] EXTERNAL_SYMBOL]
8038 -- [, [Size =>] EXTERNAL_SYMBOL]);
8040 -- EXTERNAL_SYMBOL ::=
8042 -- | static_string_EXPRESSION
8044 -- PARAMETER_TYPES ::=
8046 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8048 -- TYPE_DESIGNATOR ::=
8050 -- | subtype_Name ' Access
8054 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8056 -- MECHANISM_ASSOCIATION ::=
8057 -- [formal_parameter_NAME =>] MECHANISM_NAME
8059 -- MECHANISM_NAME ::=
8062 -- | Descriptor [([Class =>] CLASS_NAME)]
8064 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8066 when Pragma_Export_Object => Export_Object : declare
8067 Args : Args_List (1 .. 3);
8068 Names : constant Name_List (1 .. 3) := (
8073 Internal : Node_Id renames Args (1);
8074 External : Node_Id renames Args (2);
8075 Size : Node_Id renames Args (3);
8079 Gather_Associations (Names, Args);
8080 Process_Extended_Import_Export_Object_Pragma (
8081 Arg_Internal => Internal,
8082 Arg_External => External,
8086 ----------------------
8087 -- Export_Procedure --
8088 ----------------------
8090 -- pragma Export_Procedure (
8091 -- [Internal =>] LOCAL_NAME
8092 -- [, [External =>] EXTERNAL_SYMBOL]
8093 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8094 -- [, [Mechanism =>] MECHANISM]);
8096 -- EXTERNAL_SYMBOL ::=
8098 -- | static_string_EXPRESSION
8100 -- PARAMETER_TYPES ::=
8102 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8104 -- TYPE_DESIGNATOR ::=
8106 -- | subtype_Name ' Access
8110 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8112 -- MECHANISM_ASSOCIATION ::=
8113 -- [formal_parameter_NAME =>] MECHANISM_NAME
8115 -- MECHANISM_NAME ::=
8118 -- | Descriptor [([Class =>] CLASS_NAME)]
8120 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8122 when Pragma_Export_Procedure => Export_Procedure : declare
8123 Args : Args_List (1 .. 4);
8124 Names : constant Name_List (1 .. 4) := (
8127 Name_Parameter_Types,
8130 Internal : Node_Id renames Args (1);
8131 External : Node_Id renames Args (2);
8132 Parameter_Types : Node_Id renames Args (3);
8133 Mechanism : Node_Id renames Args (4);
8137 Gather_Associations (Names, Args);
8138 Process_Extended_Import_Export_Subprogram_Pragma (
8139 Arg_Internal => Internal,
8140 Arg_External => External,
8141 Arg_Parameter_Types => Parameter_Types,
8142 Arg_Mechanism => Mechanism);
8143 end Export_Procedure;
8149 -- pragma Export_Value (
8150 -- [Value =>] static_integer_EXPRESSION,
8151 -- [Link_Name =>] static_string_EXPRESSION);
8153 when Pragma_Export_Value =>
8155 Check_Arg_Order ((Name_Value, Name_Link_Name));
8156 Check_Arg_Count (2);
8158 Check_Optional_Identifier (Arg1, Name_Value);
8159 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8161 Check_Optional_Identifier (Arg2, Name_Link_Name);
8162 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8164 -----------------------------
8165 -- Export_Valued_Procedure --
8166 -----------------------------
8168 -- pragma Export_Valued_Procedure (
8169 -- [Internal =>] LOCAL_NAME
8170 -- [, [External =>] EXTERNAL_SYMBOL,]
8171 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8172 -- [, [Mechanism =>] MECHANISM]);
8174 -- EXTERNAL_SYMBOL ::=
8176 -- | static_string_EXPRESSION
8178 -- PARAMETER_TYPES ::=
8180 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8182 -- TYPE_DESIGNATOR ::=
8184 -- | subtype_Name ' Access
8188 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8190 -- MECHANISM_ASSOCIATION ::=
8191 -- [formal_parameter_NAME =>] MECHANISM_NAME
8193 -- MECHANISM_NAME ::=
8196 -- | Descriptor [([Class =>] CLASS_NAME)]
8198 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8200 when Pragma_Export_Valued_Procedure =>
8201 Export_Valued_Procedure : declare
8202 Args : Args_List (1 .. 4);
8203 Names : constant Name_List (1 .. 4) := (
8206 Name_Parameter_Types,
8209 Internal : Node_Id renames Args (1);
8210 External : Node_Id renames Args (2);
8211 Parameter_Types : Node_Id renames Args (3);
8212 Mechanism : Node_Id renames Args (4);
8216 Gather_Associations (Names, Args);
8217 Process_Extended_Import_Export_Subprogram_Pragma (
8218 Arg_Internal => Internal,
8219 Arg_External => External,
8220 Arg_Parameter_Types => Parameter_Types,
8221 Arg_Mechanism => Mechanism);
8222 end Export_Valued_Procedure;
8228 -- pragma Extend_System ([Name =>] Identifier);
8230 when Pragma_Extend_System => Extend_System : declare
8233 Check_Valid_Configuration_Pragma;
8234 Check_Arg_Count (1);
8235 Check_Optional_Identifier (Arg1, Name_Name);
8236 Check_Arg_Is_Identifier (Arg1);
8238 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8241 and then Name_Buffer (1 .. 4) = "aux_"
8243 if Present (System_Extend_Pragma_Arg) then
8244 if Chars (Get_Pragma_Arg (Arg1)) =
8245 Chars (Expression (System_Extend_Pragma_Arg))
8249 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8250 Error_Pragma ("pragma% conflicts with that #");
8254 System_Extend_Pragma_Arg := Arg1;
8256 if not GNAT_Mode then
8257 System_Extend_Unit := Arg1;
8261 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8265 ------------------------
8266 -- Extensions_Allowed --
8267 ------------------------
8269 -- pragma Extensions_Allowed (ON | OFF);
8271 when Pragma_Extensions_Allowed =>
8273 Check_Arg_Count (1);
8274 Check_No_Identifiers;
8275 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8277 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8278 Extensions_Allowed := True;
8279 Ada_Version := Ada_Version_Type'Last;
8282 Extensions_Allowed := False;
8283 Ada_Version := Ada_Version_Explicit;
8290 -- pragma External (
8291 -- [ Convention =>] convention_IDENTIFIER,
8292 -- [ Entity =>] local_NAME
8293 -- [, [External_Name =>] static_string_EXPRESSION ]
8294 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8296 when Pragma_External => External : declare
8300 pragma Warnings (Off, C);
8309 Check_At_Least_N_Arguments (2);
8310 Check_At_Most_N_Arguments (4);
8311 Process_Convention (C, Def_Id);
8312 Note_Possible_Modification
8313 (Get_Pragma_Arg (Arg2), Sure => False);
8314 Process_Interface_Name (Def_Id, Arg3, Arg4);
8315 Set_Exported (Def_Id, Arg2);
8318 --------------------------
8319 -- External_Name_Casing --
8320 --------------------------
8322 -- pragma External_Name_Casing (
8323 -- UPPERCASE | LOWERCASE
8324 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8326 when Pragma_External_Name_Casing => External_Name_Casing : declare
8329 Check_No_Identifiers;
8331 if Arg_Count = 2 then
8333 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8335 case Chars (Get_Pragma_Arg (Arg2)) is
8337 Opt.External_Name_Exp_Casing := As_Is;
8339 when Name_Uppercase =>
8340 Opt.External_Name_Exp_Casing := Uppercase;
8342 when Name_Lowercase =>
8343 Opt.External_Name_Exp_Casing := Lowercase;
8350 Check_Arg_Count (1);
8353 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8355 case Chars (Get_Pragma_Arg (Arg1)) is
8356 when Name_Uppercase =>
8357 Opt.External_Name_Imp_Casing := Uppercase;
8359 when Name_Lowercase =>
8360 Opt.External_Name_Imp_Casing := Lowercase;
8365 end External_Name_Casing;
8367 --------------------------
8368 -- Favor_Top_Level --
8369 --------------------------
8371 -- pragma Favor_Top_Level (type_NAME);
8373 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8374 Named_Entity : Entity_Id;
8378 Check_No_Identifiers;
8379 Check_Arg_Count (1);
8380 Check_Arg_Is_Local_Name (Arg1);
8381 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8383 -- If it's an access-to-subprogram type (in particular, not a
8384 -- subtype), set the flag on that type.
8386 if Is_Access_Subprogram_Type (Named_Entity) then
8387 Set_Can_Use_Internal_Rep (Named_Entity, False);
8389 -- Otherwise it's an error (name denotes the wrong sort of entity)
8393 ("access-to-subprogram type expected",
8394 Get_Pragma_Arg (Arg1));
8396 end Favor_Top_Level;
8402 -- pragma Fast_Math;
8404 when Pragma_Fast_Math =>
8406 Check_No_Identifiers;
8407 Check_Valid_Configuration_Pragma;
8410 ---------------------------
8411 -- Finalize_Storage_Only --
8412 ---------------------------
8414 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8416 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8417 Assoc : constant Node_Id := Arg1;
8418 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8423 Check_No_Identifiers;
8424 Check_Arg_Count (1);
8425 Check_Arg_Is_Local_Name (Arg1);
8427 Find_Type (Type_Id);
8428 Typ := Entity (Type_Id);
8431 or else Rep_Item_Too_Early (Typ, N)
8435 Typ := Underlying_Type (Typ);
8438 if not Is_Controlled (Typ) then
8439 Error_Pragma ("pragma% must specify controlled type");
8442 Check_First_Subtype (Arg1);
8444 if Finalize_Storage_Only (Typ) then
8445 Error_Pragma ("duplicate pragma%, only one allowed");
8447 elsif not Rep_Item_Too_Late (Typ, N) then
8448 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8450 end Finalize_Storage;
8452 --------------------------
8453 -- Float_Representation --
8454 --------------------------
8456 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8458 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8460 when Pragma_Float_Representation => Float_Representation : declare
8468 if Arg_Count = 1 then
8469 Check_Valid_Configuration_Pragma;
8471 Check_Arg_Count (2);
8472 Check_Optional_Identifier (Arg2, Name_Entity);
8473 Check_Arg_Is_Local_Name (Arg2);
8476 Check_No_Identifier (Arg1);
8477 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8479 if not OpenVMS_On_Target then
8480 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8482 ("?pragma% ignored (applies only to Open'V'M'S)");
8488 -- One argument case
8490 if Arg_Count = 1 then
8491 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8492 if Opt.Float_Format = 'I' then
8493 Error_Pragma ("'I'E'E'E format previously specified");
8496 Opt.Float_Format := 'V';
8499 if Opt.Float_Format = 'V' then
8500 Error_Pragma ("'V'A'X format previously specified");
8503 Opt.Float_Format := 'I';
8506 Set_Standard_Fpt_Formats;
8508 -- Two argument case
8511 Argx := Get_Pragma_Arg (Arg2);
8513 if not Is_Entity_Name (Argx)
8514 or else not Is_Floating_Point_Type (Entity (Argx))
8517 ("second argument of% pragma must be floating-point type",
8521 Ent := Entity (Argx);
8522 Digs := UI_To_Int (Digits_Value (Ent));
8524 -- Two arguments, VAX_Float case
8526 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8528 when 6 => Set_F_Float (Ent);
8529 when 9 => Set_D_Float (Ent);
8530 when 15 => Set_G_Float (Ent);
8534 ("wrong digits value, must be 6,9 or 15", Arg2);
8537 -- Two arguments, IEEE_Float case
8541 when 6 => Set_IEEE_Short (Ent);
8542 when 15 => Set_IEEE_Long (Ent);
8546 ("wrong digits value, must be 6 or 15", Arg2);
8550 end Float_Representation;
8556 -- pragma Ident (static_string_EXPRESSION)
8558 -- Note: pragma Comment shares this processing. Pragma Comment is
8559 -- identical to Ident, except that the restriction of the argument to
8560 -- 31 characters and the placement restrictions are not enforced for
8563 when Pragma_Ident | Pragma_Comment => Ident : declare
8568 Check_Arg_Count (1);
8569 Check_No_Identifiers;
8570 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8573 -- For pragma Ident, preserve DEC compatibility by requiring the
8574 -- pragma to appear in a declarative part or package spec.
8576 if Prag_Id = Pragma_Ident then
8577 Check_Is_In_Decl_Part_Or_Package_Spec;
8580 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8587 GP := Parent (Parent (N));
8589 if Nkind_In (GP, N_Package_Declaration,
8590 N_Generic_Package_Declaration)
8595 -- If we have a compilation unit, then record the ident value,
8596 -- checking for improper duplication.
8598 if Nkind (GP) = N_Compilation_Unit then
8599 CS := Ident_String (Current_Sem_Unit);
8601 if Present (CS) then
8603 -- For Ident, we do not permit multiple instances
8605 if Prag_Id = Pragma_Ident then
8606 Error_Pragma ("duplicate% pragma not permitted");
8608 -- For Comment, we concatenate the string, unless we want
8609 -- to preserve the tree structure for ASIS.
8611 elsif not ASIS_Mode then
8612 Start_String (Strval (CS));
8613 Store_String_Char (' ');
8614 Store_String_Chars (Strval (Str));
8615 Set_Strval (CS, End_String);
8619 -- In VMS, the effect of IDENT is achieved by passing
8620 -- --identification=name as a --for-linker switch.
8622 if OpenVMS_On_Target then
8625 ("--for-linker=--identification=");
8626 String_To_Name_Buffer (Strval (Str));
8627 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8629 -- Only the last processed IDENT is saved. The main
8630 -- purpose is so an IDENT associated with a main
8631 -- procedure will be used in preference to an IDENT
8632 -- associated with a with'd package.
8634 Replace_Linker_Option_String
8635 (End_String, "--for-linker=--identification=");
8638 Set_Ident_String (Current_Sem_Unit, Str);
8641 -- For subunits, we just ignore the Ident, since in GNAT these
8642 -- are not separate object files, and hence not separate units
8643 -- in the unit table.
8645 elsif Nkind (GP) = N_Subunit then
8648 -- Otherwise we have a misplaced pragma Ident, but we ignore
8649 -- this if we are in an instantiation, since it comes from
8650 -- a generic, and has no relevance to the instantiation.
8652 elsif Prag_Id = Pragma_Ident then
8653 if Instantiation_Location (Loc) = No_Location then
8654 Error_Pragma ("pragma% only allowed at outer level");
8664 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8665 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8667 when Pragma_Implemented => Implemented : declare
8668 Proc_Id : Entity_Id;
8673 Check_Arg_Count (2);
8674 Check_No_Identifiers;
8675 Check_Arg_Is_Identifier (Arg1);
8676 Check_Arg_Is_Local_Name (Arg1);
8678 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8680 -- Extract the name of the local procedure
8682 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8684 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8685 -- primitive procedure of a synchronized tagged type.
8687 if Ekind (Proc_Id) = E_Procedure
8688 and then Is_Primitive (Proc_Id)
8689 and then Present (First_Formal (Proc_Id))
8691 Typ := Etype (First_Formal (Proc_Id));
8693 if Is_Tagged_Type (Typ)
8696 -- Check for a protected, a synchronized or a task interface
8698 ((Is_Interface (Typ)
8699 and then Is_Synchronized_Interface (Typ))
8701 -- Check for a protected type or a task type that implements
8705 (Is_Concurrent_Record_Type (Typ)
8706 and then Present (Interfaces (Typ)))
8708 -- Check for a private record extension with keyword
8712 (Ekind_In (Typ, E_Record_Type_With_Private,
8713 E_Record_Subtype_With_Private)
8714 and then Synchronized_Present (Parent (Typ))))
8719 ("controlling formal must be of synchronized " &
8720 "tagged type", Arg1);
8724 -- Procedures declared inside a protected type must be accepted
8726 elsif Ekind (Proc_Id) = E_Procedure
8727 and then Is_Protected_Type (Scope (Proc_Id))
8731 -- The first argument is not a primitive procedure
8735 ("pragma % must be applied to a primitive procedure", Arg1);
8739 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8740 -- By_Protected_Procedure to the primitive procedure of a task
8743 if Chars (Arg2) = Name_By_Protected_Procedure
8744 and then Is_Interface (Typ)
8745 and then Is_Task_Interface (Typ)
8748 ("implementation kind By_Protected_Procedure cannot be " &
8749 "applied to a task interface primitive", Arg2);
8753 Record_Rep_Item (Proc_Id, N);
8756 ----------------------
8757 -- Implicit_Packing --
8758 ----------------------
8760 -- pragma Implicit_Packing;
8762 when Pragma_Implicit_Packing =>
8764 Check_Arg_Count (0);
8765 Implicit_Packing := True;
8772 -- [Convention =>] convention_IDENTIFIER,
8773 -- [Entity =>] local_NAME
8774 -- [, [External_Name =>] static_string_EXPRESSION ]
8775 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8777 when Pragma_Import =>
8778 Check_Ada_83_Warning;
8784 Check_At_Least_N_Arguments (2);
8785 Check_At_Most_N_Arguments (4);
8786 Process_Import_Or_Interface;
8788 ----------------------
8789 -- Import_Exception --
8790 ----------------------
8792 -- pragma Import_Exception (
8793 -- [Internal =>] LOCAL_NAME
8794 -- [, [External =>] EXTERNAL_SYMBOL]
8795 -- [, [Form =>] Ada | VMS]
8796 -- [, [Code =>] static_integer_EXPRESSION]);
8798 when Pragma_Import_Exception => Import_Exception : declare
8799 Args : Args_List (1 .. 4);
8800 Names : constant Name_List (1 .. 4) := (
8806 Internal : Node_Id renames Args (1);
8807 External : Node_Id renames Args (2);
8808 Form : Node_Id renames Args (3);
8809 Code : Node_Id renames Args (4);
8813 Gather_Associations (Names, Args);
8815 if Present (External) and then Present (Code) then
8817 ("cannot give both External and Code options for pragma%");
8820 Process_Extended_Import_Export_Exception_Pragma (
8821 Arg_Internal => Internal,
8822 Arg_External => External,
8826 if not Is_VMS_Exception (Entity (Internal)) then
8827 Set_Imported (Entity (Internal));
8829 end Import_Exception;
8831 ---------------------
8832 -- Import_Function --
8833 ---------------------
8835 -- pragma Import_Function (
8836 -- [Internal =>] LOCAL_NAME,
8837 -- [, [External =>] EXTERNAL_SYMBOL]
8838 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8839 -- [, [Result_Type =>] SUBTYPE_MARK]
8840 -- [, [Mechanism =>] MECHANISM]
8841 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8842 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8844 -- EXTERNAL_SYMBOL ::=
8846 -- | static_string_EXPRESSION
8848 -- PARAMETER_TYPES ::=
8850 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8852 -- TYPE_DESIGNATOR ::=
8854 -- | subtype_Name ' Access
8858 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8860 -- MECHANISM_ASSOCIATION ::=
8861 -- [formal_parameter_NAME =>] MECHANISM_NAME
8863 -- MECHANISM_NAME ::=
8866 -- | Descriptor [([Class =>] CLASS_NAME)]
8868 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8870 when Pragma_Import_Function => Import_Function : declare
8871 Args : Args_List (1 .. 7);
8872 Names : constant Name_List (1 .. 7) := (
8875 Name_Parameter_Types,
8878 Name_Result_Mechanism,
8879 Name_First_Optional_Parameter);
8881 Internal : Node_Id renames Args (1);
8882 External : Node_Id renames Args (2);
8883 Parameter_Types : Node_Id renames Args (3);
8884 Result_Type : Node_Id renames Args (4);
8885 Mechanism : Node_Id renames Args (5);
8886 Result_Mechanism : Node_Id renames Args (6);
8887 First_Optional_Parameter : Node_Id renames Args (7);
8891 Gather_Associations (Names, Args);
8892 Process_Extended_Import_Export_Subprogram_Pragma (
8893 Arg_Internal => Internal,
8894 Arg_External => External,
8895 Arg_Parameter_Types => Parameter_Types,
8896 Arg_Result_Type => Result_Type,
8897 Arg_Mechanism => Mechanism,
8898 Arg_Result_Mechanism => Result_Mechanism,
8899 Arg_First_Optional_Parameter => First_Optional_Parameter);
8900 end Import_Function;
8906 -- pragma Import_Object (
8907 -- [Internal =>] LOCAL_NAME
8908 -- [, [External =>] EXTERNAL_SYMBOL]
8909 -- [, [Size =>] EXTERNAL_SYMBOL]);
8911 -- EXTERNAL_SYMBOL ::=
8913 -- | static_string_EXPRESSION
8915 when Pragma_Import_Object => Import_Object : declare
8916 Args : Args_List (1 .. 3);
8917 Names : constant Name_List (1 .. 3) := (
8922 Internal : Node_Id renames Args (1);
8923 External : Node_Id renames Args (2);
8924 Size : Node_Id renames Args (3);
8928 Gather_Associations (Names, Args);
8929 Process_Extended_Import_Export_Object_Pragma (
8930 Arg_Internal => Internal,
8931 Arg_External => External,
8935 ----------------------
8936 -- Import_Procedure --
8937 ----------------------
8939 -- pragma Import_Procedure (
8940 -- [Internal =>] LOCAL_NAME
8941 -- [, [External =>] EXTERNAL_SYMBOL]
8942 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8943 -- [, [Mechanism =>] MECHANISM]
8944 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8946 -- EXTERNAL_SYMBOL ::=
8948 -- | static_string_EXPRESSION
8950 -- PARAMETER_TYPES ::=
8952 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8954 -- TYPE_DESIGNATOR ::=
8956 -- | subtype_Name ' Access
8960 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8962 -- MECHANISM_ASSOCIATION ::=
8963 -- [formal_parameter_NAME =>] MECHANISM_NAME
8965 -- MECHANISM_NAME ::=
8968 -- | Descriptor [([Class =>] CLASS_NAME)]
8970 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8972 when Pragma_Import_Procedure => Import_Procedure : declare
8973 Args : Args_List (1 .. 5);
8974 Names : constant Name_List (1 .. 5) := (
8977 Name_Parameter_Types,
8979 Name_First_Optional_Parameter);
8981 Internal : Node_Id renames Args (1);
8982 External : Node_Id renames Args (2);
8983 Parameter_Types : Node_Id renames Args (3);
8984 Mechanism : Node_Id renames Args (4);
8985 First_Optional_Parameter : Node_Id renames Args (5);
8989 Gather_Associations (Names, Args);
8990 Process_Extended_Import_Export_Subprogram_Pragma (
8991 Arg_Internal => Internal,
8992 Arg_External => External,
8993 Arg_Parameter_Types => Parameter_Types,
8994 Arg_Mechanism => Mechanism,
8995 Arg_First_Optional_Parameter => First_Optional_Parameter);
8996 end Import_Procedure;
8998 -----------------------------
8999 -- Import_Valued_Procedure --
9000 -----------------------------
9002 -- pragma Import_Valued_Procedure (
9003 -- [Internal =>] LOCAL_NAME
9004 -- [, [External =>] EXTERNAL_SYMBOL]
9005 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9006 -- [, [Mechanism =>] MECHANISM]
9007 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9009 -- EXTERNAL_SYMBOL ::=
9011 -- | static_string_EXPRESSION
9013 -- PARAMETER_TYPES ::=
9015 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9017 -- TYPE_DESIGNATOR ::=
9019 -- | subtype_Name ' Access
9023 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9025 -- MECHANISM_ASSOCIATION ::=
9026 -- [formal_parameter_NAME =>] MECHANISM_NAME
9028 -- MECHANISM_NAME ::=
9031 -- | Descriptor [([Class =>] CLASS_NAME)]
9033 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9035 when Pragma_Import_Valued_Procedure =>
9036 Import_Valued_Procedure : declare
9037 Args : Args_List (1 .. 5);
9038 Names : constant Name_List (1 .. 5) := (
9041 Name_Parameter_Types,
9043 Name_First_Optional_Parameter);
9045 Internal : Node_Id renames Args (1);
9046 External : Node_Id renames Args (2);
9047 Parameter_Types : Node_Id renames Args (3);
9048 Mechanism : Node_Id renames Args (4);
9049 First_Optional_Parameter : Node_Id renames Args (5);
9053 Gather_Associations (Names, Args);
9054 Process_Extended_Import_Export_Subprogram_Pragma (
9055 Arg_Internal => Internal,
9056 Arg_External => External,
9057 Arg_Parameter_Types => Parameter_Types,
9058 Arg_Mechanism => Mechanism,
9059 Arg_First_Optional_Parameter => First_Optional_Parameter);
9060 end Import_Valued_Procedure;
9066 -- pragma Independent (LOCAL_NAME);
9068 when Pragma_Independent => Independent : declare
9075 Check_Ada_83_Warning;
9077 Check_No_Identifiers;
9078 Check_Arg_Count (1);
9079 Check_Arg_Is_Local_Name (Arg1);
9080 E_Id := Get_Pragma_Arg (Arg1);
9082 if Etype (E_Id) = Any_Type then
9087 D := Declaration_Node (E);
9090 -- Check duplicate before we chain ourselves!
9092 Check_Duplicate_Pragma (E);
9094 -- Check appropriate entity
9097 if Rep_Item_Too_Early (E, N)
9099 Rep_Item_Too_Late (E, N)
9103 Check_First_Subtype (Arg1);
9106 elsif K = N_Object_Declaration
9107 or else (K = N_Component_Declaration
9108 and then Original_Record_Component (E) = E)
9110 if Rep_Item_Too_Late (E, N) then
9116 ("inappropriate entity for pragma%", Arg1);
9119 Independence_Checks.Append ((N, E));
9122 ----------------------------
9123 -- Independent_Components --
9124 ----------------------------
9126 -- pragma Atomic_Components (array_LOCAL_NAME);
9128 -- This processing is shared by Volatile_Components
9130 when Pragma_Independent_Components => Independent_Components : declare
9137 Check_Ada_83_Warning;
9139 Check_No_Identifiers;
9140 Check_Arg_Count (1);
9141 Check_Arg_Is_Local_Name (Arg1);
9142 E_Id := Get_Pragma_Arg (Arg1);
9144 if Etype (E_Id) = Any_Type then
9150 -- Check duplicate before we chain ourselves!
9152 Check_Duplicate_Pragma (E);
9154 -- Check appropriate entity
9156 if Rep_Item_Too_Early (E, N)
9158 Rep_Item_Too_Late (E, N)
9163 D := Declaration_Node (E);
9166 if (K = N_Full_Type_Declaration
9167 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9169 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9170 and then Nkind (D) = N_Object_Declaration
9171 and then Nkind (Object_Definition (D)) =
9172 N_Constrained_Array_Definition)
9174 Independence_Checks.Append ((N, E));
9177 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9179 end Independent_Components;
9181 ------------------------
9182 -- Initialize_Scalars --
9183 ------------------------
9185 -- pragma Initialize_Scalars;
9187 when Pragma_Initialize_Scalars =>
9189 Check_Arg_Count (0);
9190 Check_Valid_Configuration_Pragma;
9191 Check_Restriction (No_Initialize_Scalars, N);
9193 -- Initialize_Scalars creates false positives in CodePeer,
9194 -- so ignore this pragma in this mode.
9196 if not Restriction_Active (No_Initialize_Scalars)
9197 and then not CodePeer_Mode
9199 Init_Or_Norm_Scalars := True;
9200 Initialize_Scalars := True;
9207 -- pragma Inline ( NAME {, NAME} );
9209 when Pragma_Inline =>
9211 -- Pragma is active if inlining option is active
9213 Process_Inline (Inline_Active);
9219 -- pragma Inline_Always ( NAME {, NAME} );
9221 when Pragma_Inline_Always =>
9224 -- Pragma always active unless in CodePeer mode, since this causes
9225 -- walk order issues.
9227 if not CodePeer_Mode then
9228 Process_Inline (True);
9231 --------------------
9232 -- Inline_Generic --
9233 --------------------
9235 -- pragma Inline_Generic (NAME {, NAME});
9237 when Pragma_Inline_Generic =>
9239 Process_Generic_List;
9241 ----------------------
9242 -- Inspection_Point --
9243 ----------------------
9245 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9247 when Pragma_Inspection_Point => Inspection_Point : declare
9252 if Arg_Count > 0 then
9255 Exp := Get_Pragma_Arg (Arg);
9258 if not Is_Entity_Name (Exp)
9259 or else not Is_Object (Entity (Exp))
9261 Error_Pragma_Arg ("object name required", Arg);
9268 end Inspection_Point;
9274 -- pragma Interface (
9275 -- [ Convention =>] convention_IDENTIFIER,
9276 -- [ Entity =>] local_NAME
9277 -- [, [External_Name =>] static_string_EXPRESSION ]
9278 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9280 when Pragma_Interface =>
9287 Check_At_Least_N_Arguments (2);
9288 Check_At_Most_N_Arguments (4);
9289 Process_Import_Or_Interface;
9291 -- In Ada 2005, the permission to use Interface (a reserved word)
9292 -- as a pragma name is considered an obsolescent feature.
9294 if Ada_Version >= Ada_2005 then
9296 (No_Obsolescent_Features, Pragma_Identifier (N));
9299 --------------------
9300 -- Interface_Name --
9301 --------------------
9303 -- pragma Interface_Name (
9304 -- [ Entity =>] local_NAME
9305 -- [,[External_Name =>] static_string_EXPRESSION ]
9306 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9308 when Pragma_Interface_Name => Interface_Name : declare
9317 ((Name_Entity, Name_External_Name, Name_Link_Name));
9318 Check_At_Least_N_Arguments (2);
9319 Check_At_Most_N_Arguments (3);
9320 Id := Get_Pragma_Arg (Arg1);
9323 if not Is_Entity_Name (Id) then
9325 ("first argument for pragma% must be entity name", Arg1);
9326 elsif Etype (Id) = Any_Type then
9329 Def_Id := Entity (Id);
9332 -- Special DEC-compatible processing for the object case, forces
9333 -- object to be imported.
9335 if Ekind (Def_Id) = E_Variable then
9336 Kill_Size_Check_Code (Def_Id);
9337 Note_Possible_Modification (Id, Sure => False);
9339 -- Initialization is not allowed for imported variable
9341 if Present (Expression (Parent (Def_Id)))
9342 and then Comes_From_Source (Expression (Parent (Def_Id)))
9344 Error_Msg_Sloc := Sloc (Def_Id);
9346 ("no initialization allowed for declaration of& #",
9350 -- For compatibility, support VADS usage of providing both
9351 -- pragmas Interface and Interface_Name to obtain the effect
9352 -- of a single Import pragma.
9354 if Is_Imported (Def_Id)
9355 and then Present (First_Rep_Item (Def_Id))
9356 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9358 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9362 Set_Imported (Def_Id);
9365 Set_Is_Public (Def_Id);
9366 Process_Interface_Name (Def_Id, Arg2, Arg3);
9369 -- Otherwise must be subprogram
9371 elsif not Is_Subprogram (Def_Id) then
9373 ("argument of pragma% is not subprogram", Arg1);
9376 Check_At_Most_N_Arguments (3);
9380 -- Loop through homonyms
9383 Def_Id := Get_Base_Subprogram (Hom_Id);
9385 if Is_Imported (Def_Id) then
9386 Process_Interface_Name (Def_Id, Arg2, Arg3);
9390 exit when From_Aspect_Specification (N);
9391 Hom_Id := Homonym (Hom_Id);
9393 exit when No (Hom_Id)
9394 or else Scope (Hom_Id) /= Current_Scope;
9399 ("argument of pragma% is not imported subprogram",
9405 -----------------------
9406 -- Interrupt_Handler --
9407 -----------------------
9409 -- pragma Interrupt_Handler (handler_NAME);
9411 when Pragma_Interrupt_Handler =>
9412 Check_Ada_83_Warning;
9413 Check_Arg_Count (1);
9414 Check_No_Identifiers;
9416 if No_Run_Time_Mode then
9417 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9419 Check_Interrupt_Or_Attach_Handler;
9420 Process_Interrupt_Or_Attach_Handler;
9423 ------------------------
9424 -- Interrupt_Priority --
9425 ------------------------
9427 -- pragma Interrupt_Priority [(EXPRESSION)];
9429 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9430 P : constant Node_Id := Parent (N);
9434 Check_Ada_83_Warning;
9436 if Arg_Count /= 0 then
9437 Arg := Get_Pragma_Arg (Arg1);
9438 Check_Arg_Count (1);
9439 Check_No_Identifiers;
9441 -- The expression must be analyzed in the special manner
9442 -- described in "Handling of Default and Per-Object
9443 -- Expressions" in sem.ads.
9445 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9448 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9452 elsif Has_Pragma_Priority (P) then
9453 Error_Pragma ("duplicate pragma% not allowed");
9456 Set_Has_Pragma_Priority (P, True);
9457 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9459 end Interrupt_Priority;
9461 ---------------------
9462 -- Interrupt_State --
9463 ---------------------
9465 -- pragma Interrupt_State (
9466 -- [Name =>] INTERRUPT_ID,
9467 -- [State =>] INTERRUPT_STATE);
9469 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9470 -- INTERRUPT_STATE => System | Runtime | User
9472 -- Note: if the interrupt id is given as an identifier, then it must
9473 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9474 -- given as a static integer expression which must be in the range of
9475 -- Ada.Interrupts.Interrupt_ID.
9477 when Pragma_Interrupt_State => Interrupt_State : declare
9479 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9480 -- This is the entity Ada.Interrupts.Interrupt_ID;
9482 State_Type : Character;
9483 -- Set to 's'/'r'/'u' for System/Runtime/User
9486 -- Index to entry in Interrupt_States table
9489 -- Value of interrupt
9491 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9492 -- The first argument to the pragma
9494 Int_Ent : Entity_Id;
9495 -- Interrupt entity in Ada.Interrupts.Names
9499 Check_Arg_Order ((Name_Name, Name_State));
9500 Check_Arg_Count (2);
9502 Check_Optional_Identifier (Arg1, Name_Name);
9503 Check_Optional_Identifier (Arg2, Name_State);
9504 Check_Arg_Is_Identifier (Arg2);
9506 -- First argument is identifier
9508 if Nkind (Arg1X) = N_Identifier then
9510 -- Search list of names in Ada.Interrupts.Names
9512 Int_Ent := First_Entity (RTE (RE_Names));
9514 if No (Int_Ent) then
9515 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9517 elsif Chars (Int_Ent) = Chars (Arg1X) then
9518 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9522 Next_Entity (Int_Ent);
9525 -- First argument is not an identifier, so it must be a static
9526 -- expression of type Ada.Interrupts.Interrupt_ID.
9529 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9530 Int_Val := Expr_Value (Arg1X);
9532 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9534 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9537 ("value not in range of type " &
9538 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9544 case Chars (Get_Pragma_Arg (Arg2)) is
9545 when Name_Runtime => State_Type := 'r';
9546 when Name_System => State_Type := 's';
9547 when Name_User => State_Type := 'u';
9550 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9553 -- Check if entry is already stored
9555 IST_Num := Interrupt_States.First;
9557 -- If entry not found, add it
9559 if IST_Num > Interrupt_States.Last then
9560 Interrupt_States.Append
9561 ((Interrupt_Number => UI_To_Int (Int_Val),
9562 Interrupt_State => State_Type,
9563 Pragma_Loc => Loc));
9566 -- Case of entry for the same entry
9568 elsif Int_Val = Interrupt_States.Table (IST_Num).
9571 -- If state matches, done, no need to make redundant entry
9574 State_Type = Interrupt_States.Table (IST_Num).
9577 -- Otherwise if state does not match, error
9580 Interrupt_States.Table (IST_Num).Pragma_Loc;
9582 ("state conflicts with that given #", Arg2);
9586 IST_Num := IST_Num + 1;
9588 end Interrupt_State;
9595 -- ([Entity =>] type_LOCAL_NAME,
9596 -- [Check =>] EXPRESSION
9597 -- [,[Message =>] String_Expression]);
9599 when Pragma_Invariant => Invariant : declare
9604 pragma Unreferenced (Discard);
9608 Check_At_Least_N_Arguments (2);
9609 Check_At_Most_N_Arguments (3);
9610 Check_Optional_Identifier (Arg1, Name_Entity);
9611 Check_Optional_Identifier (Arg2, Name_Check);
9613 if Arg_Count = 3 then
9614 Check_Optional_Identifier (Arg3, Name_Message);
9615 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9618 Check_Arg_Is_Local_Name (Arg1);
9620 Type_Id := Get_Pragma_Arg (Arg1);
9621 Find_Type (Type_Id);
9622 Typ := Entity (Type_Id);
9624 if Typ = Any_Type then
9627 elsif not Ekind_In (Typ, E_Private_Type,
9628 E_Record_Type_With_Private,
9629 E_Limited_Private_Type)
9632 ("pragma% only allowed for private type", Arg1);
9635 -- Note that the type has at least one invariant, and also that
9636 -- it has inheritable invariants if we have Invariant'Class.
9638 Set_Has_Invariants (Typ);
9640 if Class_Present (N) then
9641 Set_Has_Inheritable_Invariants (Typ);
9644 -- The remaining processing is simply to link the pragma on to
9645 -- the rep item chain, for processing when the type is frozen.
9646 -- This is accomplished by a call to Rep_Item_Too_Late.
9648 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9651 ----------------------
9652 -- Java_Constructor --
9653 ----------------------
9655 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9657 -- Also handles pragma CIL_Constructor
9659 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9660 Java_Constructor : declare
9661 Convention : Convention_Id;
9665 This_Formal : Entity_Id;
9669 Check_Arg_Count (1);
9670 Check_Optional_Identifier (Arg1, Name_Entity);
9671 Check_Arg_Is_Local_Name (Arg1);
9673 Id := Get_Pragma_Arg (Arg1);
9674 Find_Program_Unit_Name (Id);
9676 -- If we did not find the name, we are done
9678 if Etype (Id) = Any_Type then
9682 -- Check wrong use of pragma in wrong VM target
9684 if VM_Target = No_VM then
9687 elsif VM_Target = CLI_Target
9688 and then Prag_Id = Pragma_Java_Constructor
9690 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9692 elsif VM_Target = JVM_Target
9693 and then Prag_Id = Pragma_CIL_Constructor
9695 Error_Pragma ("must use pragma 'Java_'Constructor");
9699 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9700 when Pragma_Java_Constructor => Convention := Convention_Java;
9701 when others => null;
9704 Hom_Id := Entity (Id);
9706 -- Loop through homonyms
9709 Def_Id := Get_Base_Subprogram (Hom_Id);
9711 -- The constructor is required to be a function
9713 if Ekind (Def_Id) /= E_Function then
9714 if VM_Target = JVM_Target then
9716 ("pragma% requires function returning a " &
9717 "'Java access type", Def_Id);
9720 ("pragma% requires function returning a " &
9721 "'C'I'L access type", Def_Id);
9725 -- Check arguments: For tagged type the first formal must be
9726 -- named "this" and its type must be a named access type
9727 -- designating a class-wide tagged type that has convention
9728 -- CIL/Java. The first formal must also have a null default
9729 -- value. For example:
9731 -- type Typ is tagged ...
9732 -- type Ref is access all Typ;
9733 -- pragma Convention (CIL, Typ);
9735 -- function New_Typ (This : Ref) return Ref;
9736 -- function New_Typ (This : Ref; I : Integer) return Ref;
9737 -- pragma Cil_Constructor (New_Typ);
9739 -- Reason: The first formal must NOT be a primitive of the
9742 -- This rule also applies to constructors of delegates used
9743 -- to interface with standard target libraries. For example:
9745 -- type Delegate is access procedure ...
9746 -- pragma Import (CIL, Delegate, ...);
9748 -- function new_Delegate
9749 -- (This : Delegate := null; ... ) return Delegate;
9751 -- For value-types this rule does not apply.
9753 if not Is_Value_Type (Etype (Def_Id)) then
9754 if No (First_Formal (Def_Id)) then
9755 Error_Msg_Name_1 := Pname;
9756 Error_Msg_N ("% function must have parameters", Def_Id);
9760 -- In the JRE library we have several occurrences in which
9761 -- the "this" parameter is not the first formal.
9763 This_Formal := First_Formal (Def_Id);
9765 -- In the JRE library we have several occurrences in which
9766 -- the "this" parameter is not the first formal. Search for
9769 if VM_Target = JVM_Target then
9770 while Present (This_Formal)
9771 and then Get_Name_String (Chars (This_Formal)) /= "this"
9773 Next_Formal (This_Formal);
9776 if No (This_Formal) then
9777 This_Formal := First_Formal (Def_Id);
9781 -- Warning: The first parameter should be named "this".
9782 -- We temporarily allow it because we have the following
9783 -- case in the Java runtime (file s-osinte.ads) ???
9785 -- function new_Thread
9786 -- (Self_Id : System.Address) return Thread_Id;
9787 -- pragma Java_Constructor (new_Thread);
9789 if VM_Target = JVM_Target
9790 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9792 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9796 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9797 Error_Msg_Name_1 := Pname;
9799 ("first formal of % function must be named `this`",
9800 Parent (This_Formal));
9802 elsif not Is_Access_Type (Etype (This_Formal)) then
9803 Error_Msg_Name_1 := Pname;
9805 ("first formal of % function must be an access type",
9806 Parameter_Type (Parent (This_Formal)));
9808 -- For delegates the type of the first formal must be a
9809 -- named access-to-subprogram type (see previous example)
9811 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9812 and then Ekind (Etype (This_Formal))
9813 /= E_Access_Subprogram_Type
9815 Error_Msg_Name_1 := Pname;
9817 ("first formal of % function must be a named access" &
9818 " to subprogram type",
9819 Parameter_Type (Parent (This_Formal)));
9821 -- Warning: We should reject anonymous access types because
9822 -- the constructor must not be handled as a primitive of the
9823 -- tagged type. We temporarily allow it because this profile
9824 -- is currently generated by cil2ada???
9826 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9827 and then not Ekind_In (Etype (This_Formal),
9829 E_General_Access_Type,
9830 E_Anonymous_Access_Type)
9832 Error_Msg_Name_1 := Pname;
9834 ("first formal of % function must be a named access" &
9836 Parameter_Type (Parent (This_Formal)));
9838 elsif Atree.Convention
9839 (Designated_Type (Etype (This_Formal))) /= Convention
9841 Error_Msg_Name_1 := Pname;
9843 if Convention = Convention_Java then
9845 ("pragma% requires convention 'Cil in designated" &
9847 Parameter_Type (Parent (This_Formal)));
9850 ("pragma% requires convention 'Java in designated" &
9852 Parameter_Type (Parent (This_Formal)));
9855 elsif No (Expression (Parent (This_Formal)))
9856 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9858 Error_Msg_Name_1 := Pname;
9860 ("pragma% requires first formal with default `null`",
9861 Parameter_Type (Parent (This_Formal)));
9865 -- Check result type: the constructor must be a function
9867 -- * a value type (only allowed in the CIL compiler)
9868 -- * an access-to-subprogram type with convention Java/CIL
9869 -- * an access-type designating a type that has convention
9872 if Is_Value_Type (Etype (Def_Id)) then
9875 -- Access-to-subprogram type with convention Java/CIL
9877 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9878 if Atree.Convention (Etype (Def_Id)) /= Convention then
9879 if Convention = Convention_Java then
9881 ("pragma% requires function returning a " &
9882 "'Java access type", Arg1);
9884 pragma Assert (Convention = Convention_CIL);
9886 ("pragma% requires function returning a " &
9887 "'C'I'L access type", Arg1);
9891 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9892 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9893 E_General_Access_Type)
9896 (Designated_Type (Etype (Def_Id))) /= Convention
9898 Error_Msg_Name_1 := Pname;
9900 if Convention = Convention_Java then
9902 ("pragma% requires function returning a named" &
9903 "'Java access type", Arg1);
9906 ("pragma% requires function returning a named" &
9907 "'C'I'L access type", Arg1);
9912 Set_Is_Constructor (Def_Id);
9913 Set_Convention (Def_Id, Convention);
9914 Set_Is_Imported (Def_Id);
9916 exit when From_Aspect_Specification (N);
9917 Hom_Id := Homonym (Hom_Id);
9919 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9921 end Java_Constructor;
9923 ----------------------
9924 -- Java_Interface --
9925 ----------------------
9927 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9929 when Pragma_Java_Interface => Java_Interface : declare
9935 Check_Arg_Count (1);
9936 Check_Optional_Identifier (Arg1, Name_Entity);
9937 Check_Arg_Is_Local_Name (Arg1);
9939 Arg := Get_Pragma_Arg (Arg1);
9942 if Etype (Arg) = Any_Type then
9946 if not Is_Entity_Name (Arg)
9947 or else not Is_Type (Entity (Arg))
9949 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9952 Typ := Underlying_Type (Entity (Arg));
9954 -- For now simply check some of the semantic constraints on the
9955 -- type. This currently leaves out some restrictions on interface
9956 -- types, namely that the parent type must be java.lang.Object.Typ
9957 -- and that all primitives of the type should be declared
9960 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9961 Error_Pragma_Arg ("pragma% requires an abstract "
9962 & "tagged type", Arg1);
9964 elsif not Has_Discriminants (Typ)
9965 or else Ekind (Etype (First_Discriminant (Typ)))
9966 /= E_Anonymous_Access_Type
9968 not Is_Class_Wide_Type
9969 (Designated_Type (Etype (First_Discriminant (Typ))))
9972 ("type must have a class-wide access discriminant", Arg1);
9980 -- pragma Keep_Names ([On => ] local_NAME);
9982 when Pragma_Keep_Names => Keep_Names : declare
9987 Check_Arg_Count (1);
9988 Check_Optional_Identifier (Arg1, Name_On);
9989 Check_Arg_Is_Local_Name (Arg1);
9991 Arg := Get_Pragma_Arg (Arg1);
9994 if Etype (Arg) = Any_Type then
9998 if not Is_Entity_Name (Arg)
9999 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10002 ("pragma% requires a local enumeration type", Arg1);
10005 Set_Discard_Names (Entity (Arg), False);
10012 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10014 when Pragma_License =>
10016 Check_Arg_Count (1);
10017 Check_No_Identifiers;
10018 Check_Valid_Configuration_Pragma;
10019 Check_Arg_Is_Identifier (Arg1);
10022 Sind : constant Source_File_Index :=
10023 Source_Index (Current_Sem_Unit);
10026 case Chars (Get_Pragma_Arg (Arg1)) is
10028 Set_License (Sind, GPL);
10030 when Name_Modified_GPL =>
10031 Set_License (Sind, Modified_GPL);
10033 when Name_Restricted =>
10034 Set_License (Sind, Restricted);
10036 when Name_Unrestricted =>
10037 Set_License (Sind, Unrestricted);
10040 Error_Pragma_Arg ("invalid license name", Arg1);
10048 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10050 when Pragma_Link_With => Link_With : declare
10056 if Operating_Mode = Generate_Code
10057 and then In_Extended_Main_Source_Unit (N)
10059 Check_At_Least_N_Arguments (1);
10060 Check_No_Identifiers;
10061 Check_Is_In_Decl_Part_Or_Package_Spec;
10062 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10066 while Present (Arg) loop
10067 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10069 -- Store argument, converting sequences of spaces to a
10070 -- single null character (this is one of the differences
10071 -- in processing between Link_With and Linker_Options).
10073 Arg_Store : declare
10074 C : constant Char_Code := Get_Char_Code (' ');
10075 S : constant String_Id :=
10076 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10077 L : constant Nat := String_Length (S);
10080 procedure Skip_Spaces;
10081 -- Advance F past any spaces
10087 procedure Skip_Spaces is
10089 while F <= L and then Get_String_Char (S, F) = C loop
10094 -- Start of processing for Arg_Store
10097 Skip_Spaces; -- skip leading spaces
10099 -- Loop through characters, changing any embedded
10100 -- sequence of spaces to a single null character (this
10101 -- is how Link_With/Linker_Options differ)
10104 if Get_String_Char (S, F) = C then
10107 Store_String_Char (ASCII.NUL);
10110 Store_String_Char (Get_String_Char (S, F));
10118 if Present (Arg) then
10119 Store_String_Char (ASCII.NUL);
10123 Store_Linker_Option_String (End_String);
10131 -- pragma Linker_Alias (
10132 -- [Entity =>] LOCAL_NAME
10133 -- [Target =>] static_string_EXPRESSION);
10135 when Pragma_Linker_Alias =>
10137 Check_Arg_Order ((Name_Entity, Name_Target));
10138 Check_Arg_Count (2);
10139 Check_Optional_Identifier (Arg1, Name_Entity);
10140 Check_Optional_Identifier (Arg2, Name_Target);
10141 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10142 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10144 -- The only processing required is to link this item on to the
10145 -- list of rep items for the given entity. This is accomplished
10146 -- by the call to Rep_Item_Too_Late (when no error is detected
10147 -- and False is returned).
10149 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10152 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10155 ------------------------
10156 -- Linker_Constructor --
10157 ------------------------
10159 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10161 -- Code is shared with Linker_Destructor
10163 -----------------------
10164 -- Linker_Destructor --
10165 -----------------------
10167 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10169 when Pragma_Linker_Constructor |
10170 Pragma_Linker_Destructor =>
10171 Linker_Constructor : declare
10177 Check_Arg_Count (1);
10178 Check_No_Identifiers;
10179 Check_Arg_Is_Local_Name (Arg1);
10180 Arg1_X := Get_Pragma_Arg (Arg1);
10182 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10184 if not Is_Library_Level_Entity (Proc) then
10186 ("argument for pragma% must be library level entity", Arg1);
10189 -- The only processing required is to link this item on to the
10190 -- list of rep items for the given entity. This is accomplished
10191 -- by the call to Rep_Item_Too_Late (when no error is detected
10192 -- and False is returned).
10194 if Rep_Item_Too_Late (Proc, N) then
10197 Set_Has_Gigi_Rep_Item (Proc);
10199 end Linker_Constructor;
10201 --------------------
10202 -- Linker_Options --
10203 --------------------
10205 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10207 when Pragma_Linker_Options => Linker_Options : declare
10211 Check_Ada_83_Warning;
10212 Check_No_Identifiers;
10213 Check_Arg_Count (1);
10214 Check_Is_In_Decl_Part_Or_Package_Spec;
10215 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10216 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10219 while Present (Arg) loop
10220 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10221 Store_String_Char (ASCII.NUL);
10223 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10227 if Operating_Mode = Generate_Code
10228 and then In_Extended_Main_Source_Unit (N)
10230 Store_Linker_Option_String (End_String);
10232 end Linker_Options;
10234 --------------------
10235 -- Linker_Section --
10236 --------------------
10238 -- pragma Linker_Section (
10239 -- [Entity =>] LOCAL_NAME
10240 -- [Section =>] static_string_EXPRESSION);
10242 when Pragma_Linker_Section =>
10244 Check_Arg_Order ((Name_Entity, Name_Section));
10245 Check_Arg_Count (2);
10246 Check_Optional_Identifier (Arg1, Name_Entity);
10247 Check_Optional_Identifier (Arg2, Name_Section);
10248 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10249 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10251 -- This pragma applies only to objects
10253 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10254 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10257 -- The only processing required is to link this item on to the
10258 -- list of rep items for the given entity. This is accomplished
10259 -- by the call to Rep_Item_Too_Late (when no error is detected
10260 -- and False is returned).
10262 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10265 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10272 -- pragma List (On | Off)
10274 -- There is nothing to do here, since we did all the processing for
10275 -- this pragma in Par.Prag (so that it works properly even in syntax
10278 when Pragma_List =>
10281 --------------------
10282 -- Locking_Policy --
10283 --------------------
10285 -- pragma Locking_Policy (policy_IDENTIFIER);
10287 when Pragma_Locking_Policy => declare
10291 Check_Ada_83_Warning;
10292 Check_Arg_Count (1);
10293 Check_No_Identifiers;
10294 Check_Arg_Is_Locking_Policy (Arg1);
10295 Check_Valid_Configuration_Pragma;
10296 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10297 LP := Fold_Upper (Name_Buffer (1));
10299 if Locking_Policy /= ' '
10300 and then Locking_Policy /= LP
10302 Error_Msg_Sloc := Locking_Policy_Sloc;
10303 Error_Pragma ("locking policy incompatible with policy#");
10305 -- Set new policy, but always preserve System_Location since we
10306 -- like the error message with the run time name.
10309 Locking_Policy := LP;
10311 if Locking_Policy_Sloc /= System_Location then
10312 Locking_Policy_Sloc := Loc;
10321 -- pragma Long_Float (D_Float | G_Float);
10323 when Pragma_Long_Float =>
10325 Check_Valid_Configuration_Pragma;
10326 Check_Arg_Count (1);
10327 Check_No_Identifier (Arg1);
10328 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10330 if not OpenVMS_On_Target then
10331 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10336 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10337 if Opt.Float_Format_Long = 'G' then
10338 Error_Pragma ("G_Float previously specified");
10341 Opt.Float_Format_Long := 'D';
10343 -- G_Float case (this is the default, does not need overriding)
10346 if Opt.Float_Format_Long = 'D' then
10347 Error_Pragma ("D_Float previously specified");
10350 Opt.Float_Format_Long := 'G';
10353 Set_Standard_Fpt_Formats;
10355 -----------------------
10356 -- Machine_Attribute --
10357 -----------------------
10359 -- pragma Machine_Attribute (
10360 -- [Entity =>] LOCAL_NAME,
10361 -- [Attribute_Name =>] static_string_EXPRESSION
10362 -- [, [Info =>] static_EXPRESSION] );
10364 when Pragma_Machine_Attribute => Machine_Attribute : declare
10365 Def_Id : Entity_Id;
10369 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10371 if Arg_Count = 3 then
10372 Check_Optional_Identifier (Arg3, Name_Info);
10373 Check_Arg_Is_Static_Expression (Arg3);
10375 Check_Arg_Count (2);
10378 Check_Optional_Identifier (Arg1, Name_Entity);
10379 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10380 Check_Arg_Is_Local_Name (Arg1);
10381 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10382 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10384 if Is_Access_Type (Def_Id) then
10385 Def_Id := Designated_Type (Def_Id);
10388 if Rep_Item_Too_Early (Def_Id, N) then
10392 Def_Id := Underlying_Type (Def_Id);
10394 -- The only processing required is to link this item on to the
10395 -- list of rep items for the given entity. This is accomplished
10396 -- by the call to Rep_Item_Too_Late (when no error is detected
10397 -- and False is returned).
10399 if Rep_Item_Too_Late (Def_Id, N) then
10402 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10404 end Machine_Attribute;
10411 -- (MAIN_OPTION [, MAIN_OPTION]);
10414 -- [STACK_SIZE =>] static_integer_EXPRESSION
10415 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10416 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10418 when Pragma_Main => Main : declare
10419 Args : Args_List (1 .. 3);
10420 Names : constant Name_List (1 .. 3) := (
10422 Name_Task_Stack_Size_Default,
10423 Name_Time_Slicing_Enabled);
10429 Gather_Associations (Names, Args);
10431 for J in 1 .. 2 loop
10432 if Present (Args (J)) then
10433 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10437 if Present (Args (3)) then
10438 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10442 while Present (Nod) loop
10443 if Nkind (Nod) = N_Pragma
10444 and then Pragma_Name (Nod) = Name_Main
10446 Error_Msg_Name_1 := Pname;
10447 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10458 -- pragma Main_Storage
10459 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10461 -- MAIN_STORAGE_OPTION ::=
10462 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10463 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10465 when Pragma_Main_Storage => Main_Storage : declare
10466 Args : Args_List (1 .. 2);
10467 Names : constant Name_List (1 .. 2) := (
10468 Name_Working_Storage,
10475 Gather_Associations (Names, Args);
10477 for J in 1 .. 2 loop
10478 if Present (Args (J)) then
10479 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10483 Check_In_Main_Program;
10486 while Present (Nod) loop
10487 if Nkind (Nod) = N_Pragma
10488 and then Pragma_Name (Nod) = Name_Main_Storage
10490 Error_Msg_Name_1 := Pname;
10491 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10502 -- pragma Memory_Size (NUMERIC_LITERAL)
10504 when Pragma_Memory_Size =>
10507 -- Memory size is simply ignored
10509 Check_No_Identifiers;
10510 Check_Arg_Count (1);
10511 Check_Arg_Is_Integer_Literal (Arg1);
10519 -- The only correct use of this pragma is on its own in a file, in
10520 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10521 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10522 -- check for a file containing nothing but a No_Body pragma). If we
10523 -- attempt to process it during normal semantics processing, it means
10524 -- it was misplaced.
10526 when Pragma_No_Body =>
10534 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10536 when Pragma_No_Return => No_Return : declare
10544 Check_At_Least_N_Arguments (1);
10546 -- Loop through arguments of pragma
10549 while Present (Arg) loop
10550 Check_Arg_Is_Local_Name (Arg);
10551 Id := Get_Pragma_Arg (Arg);
10554 if not Is_Entity_Name (Id) then
10555 Error_Pragma_Arg ("entity name required", Arg);
10558 if Etype (Id) = Any_Type then
10562 -- Loop to find matching procedures
10567 and then Scope (E) = Current_Scope
10569 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10572 -- Set flag on any alias as well
10574 if Is_Overloadable (E) and then Present (Alias (E)) then
10575 Set_No_Return (Alias (E));
10581 exit when From_Aspect_Specification (N);
10586 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10597 -- pragma No_Run_Time;
10599 -- Note: this pragma is retained for backwards compatibility. See
10600 -- body of Rtsfind for full details on its handling.
10602 when Pragma_No_Run_Time =>
10604 Check_Valid_Configuration_Pragma;
10605 Check_Arg_Count (0);
10607 No_Run_Time_Mode := True;
10608 Configurable_Run_Time_Mode := True;
10610 -- Set Duration to 32 bits if word size is 32
10612 if Ttypes.System_Word_Size = 32 then
10613 Duration_32_Bits_On_Target := True;
10616 -- Set appropriate restrictions
10618 Set_Restriction (No_Finalization, N);
10619 Set_Restriction (No_Exception_Handlers, N);
10620 Set_Restriction (Max_Tasks, N, 0);
10621 Set_Restriction (No_Tasking, N);
10623 ------------------------
10624 -- No_Strict_Aliasing --
10625 ------------------------
10627 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10629 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10634 Check_At_Most_N_Arguments (1);
10636 if Arg_Count = 0 then
10637 Check_Valid_Configuration_Pragma;
10638 Opt.No_Strict_Aliasing := True;
10641 Check_Optional_Identifier (Arg2, Name_Entity);
10642 Check_Arg_Is_Local_Name (Arg1);
10643 E_Id := Entity (Get_Pragma_Arg (Arg1));
10645 if E_Id = Any_Type then
10647 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10648 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10651 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10653 end No_Strict_Aliasing;
10655 -----------------------
10656 -- Normalize_Scalars --
10657 -----------------------
10659 -- pragma Normalize_Scalars;
10661 when Pragma_Normalize_Scalars =>
10662 Check_Ada_83_Warning;
10663 Check_Arg_Count (0);
10664 Check_Valid_Configuration_Pragma;
10666 -- Normalize_Scalars creates false positives in CodePeer, so
10667 -- ignore this pragma in this mode.
10669 if not CodePeer_Mode then
10670 Normalize_Scalars := True;
10671 Init_Or_Norm_Scalars := True;
10678 -- pragma Obsolescent;
10680 -- pragma Obsolescent (
10681 -- [Message =>] static_string_EXPRESSION
10682 -- [,[Version =>] Ada_05]]);
10684 -- pragma Obsolescent (
10685 -- [Entity =>] NAME
10686 -- [,[Message =>] static_string_EXPRESSION
10687 -- [,[Version =>] Ada_05]] );
10689 when Pragma_Obsolescent => Obsolescent : declare
10693 procedure Set_Obsolescent (E : Entity_Id);
10694 -- Given an entity Ent, mark it as obsolescent if appropriate
10696 ---------------------
10697 -- Set_Obsolescent --
10698 ---------------------
10700 procedure Set_Obsolescent (E : Entity_Id) is
10709 -- Entity name was given
10711 if Present (Ename) then
10713 -- If entity name matches, we are fine. Save entity in
10714 -- pragma argument, for ASIS use.
10716 if Chars (Ename) = Chars (Ent) then
10717 Set_Entity (Ename, Ent);
10718 Generate_Reference (Ent, Ename);
10720 -- If entity name does not match, only possibility is an
10721 -- enumeration literal from an enumeration type declaration.
10723 elsif Ekind (Ent) /= E_Enumeration_Type then
10725 ("pragma % entity name does not match declaration");
10728 Ent := First_Literal (E);
10732 ("pragma % entity name does not match any " &
10733 "enumeration literal");
10735 elsif Chars (Ent) = Chars (Ename) then
10736 Set_Entity (Ename, Ent);
10737 Generate_Reference (Ent, Ename);
10741 Ent := Next_Literal (Ent);
10747 -- Ent points to entity to be marked
10749 if Arg_Count >= 1 then
10751 -- Deal with static string argument
10753 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10754 S := Strval (Get_Pragma_Arg (Arg1));
10756 for J in 1 .. String_Length (S) loop
10757 if not In_Character_Range (Get_String_Char (S, J)) then
10759 ("pragma% argument does not allow wide characters",
10764 Obsolescent_Warnings.Append
10765 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10767 -- Check for Ada_05 parameter
10769 if Arg_Count /= 1 then
10770 Check_Arg_Count (2);
10773 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10776 Check_Arg_Is_Identifier (Argx);
10778 if Chars (Argx) /= Name_Ada_05 then
10779 Error_Msg_Name_2 := Name_Ada_05;
10781 ("only allowed argument for pragma% is %", Argx);
10784 if Ada_Version_Explicit < Ada_2005
10785 or else not Warn_On_Ada_2005_Compatibility
10793 -- Set flag if pragma active
10796 Set_Is_Obsolescent (Ent);
10800 end Set_Obsolescent;
10802 -- Start of processing for pragma Obsolescent
10807 Check_At_Most_N_Arguments (3);
10809 -- See if first argument specifies an entity name
10813 (Chars (Arg1) = Name_Entity
10815 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10817 N_Operator_Symbol))
10819 Ename := Get_Pragma_Arg (Arg1);
10821 -- Eliminate first argument, so we can share processing
10825 Arg_Count := Arg_Count - 1;
10827 -- No Entity name argument given
10833 if Arg_Count >= 1 then
10834 Check_Optional_Identifier (Arg1, Name_Message);
10836 if Arg_Count = 2 then
10837 Check_Optional_Identifier (Arg2, Name_Version);
10841 -- Get immediately preceding declaration
10844 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10848 -- Cases where we do not follow anything other than another pragma
10852 -- First case: library level compilation unit declaration with
10853 -- the pragma immediately following the declaration.
10855 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10857 (Defining_Entity (Unit (Parent (Parent (N)))));
10860 -- Case 2: library unit placement for package
10864 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10866 if Is_Package_Or_Generic_Package (Ent) then
10867 Set_Obsolescent (Ent);
10873 -- Cases where we must follow a declaration
10876 if Nkind (Decl) not in N_Declaration
10877 and then Nkind (Decl) not in N_Later_Decl_Item
10878 and then Nkind (Decl) not in N_Generic_Declaration
10879 and then Nkind (Decl) not in N_Renaming_Declaration
10882 ("pragma% misplaced, "
10883 & "must immediately follow a declaration");
10886 Set_Obsolescent (Defining_Entity (Decl));
10896 -- pragma Optimize (Time | Space | Off);
10898 -- The actual check for optimize is done in Gigi. Note that this
10899 -- pragma does not actually change the optimization setting, it
10900 -- simply checks that it is consistent with the pragma.
10902 when Pragma_Optimize =>
10903 Check_No_Identifiers;
10904 Check_Arg_Count (1);
10905 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10907 ------------------------
10908 -- Optimize_Alignment --
10909 ------------------------
10911 -- pragma Optimize_Alignment (Time | Space | Off);
10913 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10915 Check_No_Identifiers;
10916 Check_Arg_Count (1);
10917 Check_Valid_Configuration_Pragma;
10920 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10924 Opt.Optimize_Alignment := 'T';
10926 Opt.Optimize_Alignment := 'S';
10928 Opt.Optimize_Alignment := 'O';
10930 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10934 -- Set indication that mode is set locally. If we are in fact in a
10935 -- configuration pragma file, this setting is harmless since the
10936 -- switch will get reset anyway at the start of each unit.
10938 Optimize_Alignment_Local := True;
10939 end Optimize_Alignment;
10945 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10947 when Pragma_Ordered => Ordered : declare
10948 Assoc : constant Node_Id := Arg1;
10954 Check_No_Identifiers;
10955 Check_Arg_Count (1);
10956 Check_Arg_Is_Local_Name (Arg1);
10958 Type_Id := Get_Pragma_Arg (Assoc);
10959 Find_Type (Type_Id);
10960 Typ := Entity (Type_Id);
10962 if Typ = Any_Type then
10965 Typ := Underlying_Type (Typ);
10968 if not Is_Enumeration_Type (Typ) then
10969 Error_Pragma ("pragma% must specify enumeration type");
10972 Check_First_Subtype (Arg1);
10973 Set_Has_Pragma_Ordered (Base_Type (Typ));
10980 -- pragma Pack (first_subtype_LOCAL_NAME);
10982 when Pragma_Pack => Pack : declare
10983 Assoc : constant Node_Id := Arg1;
10987 Ignore : Boolean := False;
10990 Check_No_Identifiers;
10991 Check_Arg_Count (1);
10992 Check_Arg_Is_Local_Name (Arg1);
10994 Type_Id := Get_Pragma_Arg (Assoc);
10995 Find_Type (Type_Id);
10996 Typ := Entity (Type_Id);
10999 or else Rep_Item_Too_Early (Typ, N)
11003 Typ := Underlying_Type (Typ);
11006 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11007 Error_Pragma ("pragma% must specify array or record type");
11010 Check_First_Subtype (Arg1);
11011 Check_Duplicate_Pragma (Typ);
11015 if Is_Array_Type (Typ) then
11016 Ctyp := Component_Type (Typ);
11018 -- Ignore pack that does nothing
11020 if Known_Static_Esize (Ctyp)
11021 and then Known_Static_RM_Size (Ctyp)
11022 and then Esize (Ctyp) = RM_Size (Ctyp)
11023 and then Addressable (Esize (Ctyp))
11028 -- Process OK pragma Pack. Note that if there is a separate
11029 -- component clause present, the Pack will be cancelled. This
11030 -- processing is in Freeze.
11032 if not Rep_Item_Too_Late (Typ, N) then
11034 -- In the context of static code analysis, we do not need
11035 -- complex front-end expansions related to pragma Pack,
11036 -- so disable handling of pragma Pack in this case.
11038 if CodePeer_Mode then
11041 -- Don't attempt any packing for VM targets. We possibly
11042 -- could deal with some cases of array bit-packing, but we
11043 -- don't bother, since this is not a typical kind of
11044 -- representation in the VM context anyway (and would not
11045 -- for example work nicely with the debugger).
11047 elsif VM_Target /= No_VM then
11048 if not GNAT_Mode then
11050 ("?pragma% ignored in this configuration");
11053 -- Normal case where we do the pack action
11057 Set_Is_Packed (Base_Type (Typ));
11058 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11061 Set_Has_Pragma_Pack (Base_Type (Typ));
11065 -- For record types, the pack is always effective
11067 else pragma Assert (Is_Record_Type (Typ));
11068 if not Rep_Item_Too_Late (Typ, N) then
11070 -- Ignore pack request with warning in VM mode (skip warning
11071 -- if we are compiling GNAT run time library).
11073 if VM_Target /= No_VM then
11074 if not GNAT_Mode then
11076 ("?pragma% ignored in this configuration");
11079 -- Normal case of pack request active
11082 Set_Is_Packed (Base_Type (Typ));
11083 Set_Has_Pragma_Pack (Base_Type (Typ));
11084 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11096 -- There is nothing to do here, since we did all the processing for
11097 -- this pragma in Par.Prag (so that it works properly even in syntax
11100 when Pragma_Page =>
11107 -- pragma Passive [(PASSIVE_FORM)];
11109 -- PASSIVE_FORM ::= Semaphore | No
11111 when Pragma_Passive =>
11114 if Nkind (Parent (N)) /= N_Task_Definition then
11115 Error_Pragma ("pragma% must be within task definition");
11118 if Arg_Count /= 0 then
11119 Check_Arg_Count (1);
11120 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11123 ----------------------------------
11124 -- Preelaborable_Initialization --
11125 ----------------------------------
11127 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11129 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11134 Check_Arg_Count (1);
11135 Check_No_Identifiers;
11136 Check_Arg_Is_Identifier (Arg1);
11137 Check_Arg_Is_Local_Name (Arg1);
11138 Check_First_Subtype (Arg1);
11139 Ent := Entity (Get_Pragma_Arg (Arg1));
11141 if not (Is_Private_Type (Ent)
11143 Is_Protected_Type (Ent)
11145 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11148 ("pragma % can only be applied to private, formal derived or "
11149 & "protected type",
11153 -- Give an error if the pragma is applied to a protected type that
11154 -- does not qualify (due to having entries, or due to components
11155 -- that do not qualify).
11157 if Is_Protected_Type (Ent)
11158 and then not Has_Preelaborable_Initialization (Ent)
11161 ("protected type & does not have preelaborable " &
11162 "initialization", Ent);
11164 -- Otherwise mark the type as definitely having preelaborable
11168 Set_Known_To_Have_Preelab_Init (Ent);
11171 if Has_Pragma_Preelab_Init (Ent)
11172 and then Warn_On_Redundant_Constructs
11174 Error_Pragma ("?duplicate pragma%!");
11176 Set_Has_Pragma_Preelab_Init (Ent);
11180 --------------------
11181 -- Persistent_BSS --
11182 --------------------
11184 -- pragma Persistent_BSS [(object_NAME)];
11186 when Pragma_Persistent_BSS => Persistent_BSS : declare
11193 Check_At_Most_N_Arguments (1);
11195 -- Case of application to specific object (one argument)
11197 if Arg_Count = 1 then
11198 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11200 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11202 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11205 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11208 Ent := Entity (Get_Pragma_Arg (Arg1));
11209 Decl := Parent (Ent);
11211 if Rep_Item_Too_Late (Ent, N) then
11215 if Present (Expression (Decl)) then
11217 ("object for pragma% cannot have initialization", Arg1);
11220 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11222 ("object type for pragma% is not potentially persistent",
11226 Check_Duplicate_Pragma (Ent);
11229 Make_Linker_Section_Pragma
11230 (Ent, Sloc (N), ".persistent.bss");
11231 Insert_After (N, Prag);
11234 -- Case of use as configuration pragma with no arguments
11237 Check_Valid_Configuration_Pragma;
11238 Persistent_BSS_Mode := True;
11240 end Persistent_BSS;
11246 -- pragma Polling (ON | OFF);
11248 when Pragma_Polling =>
11250 Check_Arg_Count (1);
11251 Check_No_Identifiers;
11252 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11253 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11255 -------------------
11256 -- Postcondition --
11257 -------------------
11259 -- pragma Postcondition ([Check =>] Boolean_Expression
11260 -- [,[Message =>] String_Expression]);
11262 when Pragma_Postcondition => Postcondition : declare
11264 pragma Warnings (Off, In_Body);
11268 Check_At_Least_N_Arguments (1);
11269 Check_At_Most_N_Arguments (2);
11270 Check_Optional_Identifier (Arg1, Name_Check);
11272 -- All we need to do here is call the common check procedure,
11273 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11275 Check_Precondition_Postcondition (In_Body);
11282 -- pragma Precondition ([Check =>] Boolean_Expression
11283 -- [,[Message =>] String_Expression]);
11285 when Pragma_Precondition => Precondition : declare
11290 Check_At_Least_N_Arguments (1);
11291 Check_At_Most_N_Arguments (2);
11292 Check_Optional_Identifier (Arg1, Name_Check);
11293 Check_Precondition_Postcondition (In_Body);
11295 -- If in spec, nothing more to do. If in body, then we convert the
11296 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11297 -- this whether or not precondition checks are enabled. That works
11298 -- fine since pragma Check will do this check, and will also
11299 -- analyze the condition itself in the proper context.
11304 Chars => Name_Check,
11305 Pragma_Argument_Associations => New_List (
11306 Make_Pragma_Argument_Association (Loc,
11307 Expression => Make_Identifier (Loc, Name_Precondition)),
11309 Make_Pragma_Argument_Association (Sloc (Arg1),
11310 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11312 if Arg_Count = 2 then
11313 Append_To (Pragma_Argument_Associations (N),
11314 Make_Pragma_Argument_Association (Sloc (Arg2),
11315 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11326 -- pragma Predicate
11327 -- ([Entity =>] type_LOCAL_NAME,
11328 -- [Check =>] EXPRESSION);
11330 when Pragma_Predicate => Predicate : declare
11335 pragma Unreferenced (Discard);
11339 Check_Arg_Count (2);
11340 Check_Optional_Identifier (Arg1, Name_Entity);
11341 Check_Optional_Identifier (Arg2, Name_Check);
11343 Check_Arg_Is_Local_Name (Arg1);
11345 Type_Id := Get_Pragma_Arg (Arg1);
11346 Find_Type (Type_Id);
11347 Typ := Entity (Type_Id);
11349 if Typ = Any_Type then
11353 -- The remaining processing is simply to link the pragma on to
11354 -- the rep item chain, for processing when the type is frozen.
11355 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11356 -- mark the type as having predicates.
11358 Set_Has_Predicates (Typ);
11359 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11366 -- pragma Preelaborate [(library_unit_NAME)];
11368 -- Set the flag Is_Preelaborated of program unit name entity
11370 when Pragma_Preelaborate => Preelaborate : declare
11371 Pa : constant Node_Id := Parent (N);
11372 Pk : constant Node_Kind := Nkind (Pa);
11376 Check_Ada_83_Warning;
11377 Check_Valid_Library_Unit_Pragma;
11379 if Nkind (N) = N_Null_Statement then
11383 Ent := Find_Lib_Unit_Name;
11384 Check_Duplicate_Pragma (Ent);
11386 -- This filters out pragmas inside generic parent then
11387 -- show up inside instantiation
11390 and then not (Pk = N_Package_Specification
11391 and then Present (Generic_Parent (Pa)))
11393 if not Debug_Flag_U then
11394 Set_Is_Preelaborated (Ent);
11395 Set_Suppress_Elaboration_Warnings (Ent);
11400 ---------------------
11401 -- Preelaborate_05 --
11402 ---------------------
11404 -- pragma Preelaborate_05 [(library_unit_NAME)];
11406 -- This pragma is useable only in GNAT_Mode, where it is used like
11407 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11408 -- (otherwise it is ignored). This is used to implement AI-362 which
11409 -- recategorizes some run-time packages in Ada 2005 mode.
11411 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11416 Check_Valid_Library_Unit_Pragma;
11418 if not GNAT_Mode then
11419 Error_Pragma ("pragma% only available in GNAT mode");
11422 if Nkind (N) = N_Null_Statement then
11426 -- This is one of the few cases where we need to test the value of
11427 -- Ada_Version_Explicit rather than Ada_Version (which is always
11428 -- set to Ada_2012 in a predefined unit), we need to know the
11429 -- explicit version set to know if this pragma is active.
11431 if Ada_Version_Explicit >= Ada_2005 then
11432 Ent := Find_Lib_Unit_Name;
11433 Set_Is_Preelaborated (Ent);
11434 Set_Suppress_Elaboration_Warnings (Ent);
11436 end Preelaborate_05;
11442 -- pragma Priority (EXPRESSION);
11444 when Pragma_Priority => Priority : declare
11445 P : constant Node_Id := Parent (N);
11449 Check_No_Identifiers;
11450 Check_Arg_Count (1);
11454 if Nkind (P) = N_Subprogram_Body then
11455 Check_In_Main_Program;
11457 Arg := Get_Pragma_Arg (Arg1);
11458 Analyze_And_Resolve (Arg, Standard_Integer);
11462 if not Is_Static_Expression (Arg) then
11463 Flag_Non_Static_Expr
11464 ("main subprogram priority is not static!", Arg);
11467 -- If constraint error, then we already signalled an error
11469 elsif Raises_Constraint_Error (Arg) then
11472 -- Otherwise check in range
11476 Val : constant Uint := Expr_Value (Arg);
11480 or else Val > Expr_Value (Expression
11481 (Parent (RTE (RE_Max_Priority))))
11484 ("main subprogram priority is out of range", Arg1);
11490 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11492 -- Load an arbitrary entity from System.Tasking to make sure
11493 -- this package is implicitly with'ed, since we need to have
11494 -- the tasking run-time active for the pragma Priority to have
11498 Discard : Entity_Id;
11499 pragma Warnings (Off, Discard);
11501 Discard := RTE (RE_Task_List);
11504 -- Task or Protected, must be of type Integer
11506 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11507 Arg := Get_Pragma_Arg (Arg1);
11509 -- The expression must be analyzed in the special manner
11510 -- described in "Handling of Default and Per-Object
11511 -- Expressions" in sem.ads.
11513 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11515 if not Is_Static_Expression (Arg) then
11516 Check_Restriction (Static_Priorities, Arg);
11519 -- Anything else is incorrect
11525 if Has_Pragma_Priority (P) then
11526 Error_Pragma ("duplicate pragma% not allowed");
11528 Set_Has_Pragma_Priority (P, True);
11530 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11531 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11532 -- exp_ch9 should use this ???
11537 -----------------------------------
11538 -- Priority_Specific_Dispatching --
11539 -----------------------------------
11541 -- pragma Priority_Specific_Dispatching (
11542 -- policy_IDENTIFIER,
11543 -- first_priority_EXPRESSION,
11544 -- last_priority_EXPRESSION);
11546 when Pragma_Priority_Specific_Dispatching =>
11547 Priority_Specific_Dispatching : declare
11548 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11549 -- This is the entity System.Any_Priority;
11552 Lower_Bound : Node_Id;
11553 Upper_Bound : Node_Id;
11559 Check_Arg_Count (3);
11560 Check_No_Identifiers;
11561 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11562 Check_Valid_Configuration_Pragma;
11563 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11564 DP := Fold_Upper (Name_Buffer (1));
11566 Lower_Bound := Get_Pragma_Arg (Arg2);
11567 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11568 Lower_Val := Expr_Value (Lower_Bound);
11570 Upper_Bound := Get_Pragma_Arg (Arg3);
11571 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11572 Upper_Val := Expr_Value (Upper_Bound);
11574 -- It is not allowed to use Task_Dispatching_Policy and
11575 -- Priority_Specific_Dispatching in the same partition.
11577 if Task_Dispatching_Policy /= ' ' then
11578 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11580 ("pragma% incompatible with Task_Dispatching_Policy#");
11582 -- Check lower bound in range
11584 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11586 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11589 ("first_priority is out of range", Arg2);
11591 -- Check upper bound in range
11593 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11595 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11598 ("last_priority is out of range", Arg3);
11600 -- Check that the priority range is valid
11602 elsif Lower_Val > Upper_Val then
11604 ("last_priority_expression must be greater than" &
11605 " or equal to first_priority_expression");
11607 -- Store the new policy, but always preserve System_Location since
11608 -- we like the error message with the run-time name.
11611 -- Check overlapping in the priority ranges specified in other
11612 -- Priority_Specific_Dispatching pragmas within the same
11613 -- partition. We can only check those we know about!
11616 Specific_Dispatching.First .. Specific_Dispatching.Last
11618 if Specific_Dispatching.Table (J).First_Priority in
11619 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11620 or else Specific_Dispatching.Table (J).Last_Priority in
11621 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11624 Specific_Dispatching.Table (J).Pragma_Loc;
11626 ("priority range overlaps with "
11627 & "Priority_Specific_Dispatching#");
11631 -- The use of Priority_Specific_Dispatching is incompatible
11632 -- with Task_Dispatching_Policy.
11634 if Task_Dispatching_Policy /= ' ' then
11635 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11637 ("Priority_Specific_Dispatching incompatible "
11638 & "with Task_Dispatching_Policy#");
11641 -- The use of Priority_Specific_Dispatching forces ceiling
11644 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11645 Error_Msg_Sloc := Locking_Policy_Sloc;
11647 ("Priority_Specific_Dispatching incompatible "
11648 & "with Locking_Policy#");
11650 -- Set the Ceiling_Locking policy, but preserve System_Location
11651 -- since we like the error message with the run time name.
11654 Locking_Policy := 'C';
11656 if Locking_Policy_Sloc /= System_Location then
11657 Locking_Policy_Sloc := Loc;
11661 -- Add entry in the table
11663 Specific_Dispatching.Append
11664 ((Dispatching_Policy => DP,
11665 First_Priority => UI_To_Int (Lower_Val),
11666 Last_Priority => UI_To_Int (Upper_Val),
11667 Pragma_Loc => Loc));
11669 end Priority_Specific_Dispatching;
11675 -- pragma Profile (profile_IDENTIFIER);
11677 -- profile_IDENTIFIER => Restricted | Ravenscar
11679 when Pragma_Profile =>
11681 Check_Arg_Count (1);
11682 Check_Valid_Configuration_Pragma;
11683 Check_No_Identifiers;
11686 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11688 if Chars (Argx) = Name_Ravenscar then
11689 Set_Ravenscar_Profile (N);
11690 elsif Chars (Argx) = Name_Restricted then
11691 Set_Profile_Restrictions
11692 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11694 Error_Pragma_Arg ("& is not a valid profile", Argx);
11698 ----------------------
11699 -- Profile_Warnings --
11700 ----------------------
11702 -- pragma Profile_Warnings (profile_IDENTIFIER);
11704 -- profile_IDENTIFIER => Restricted | Ravenscar
11706 when Pragma_Profile_Warnings =>
11708 Check_Arg_Count (1);
11709 Check_Valid_Configuration_Pragma;
11710 Check_No_Identifiers;
11713 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11715 if Chars (Argx) = Name_Ravenscar then
11716 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11717 elsif Chars (Argx) = Name_Restricted then
11718 Set_Profile_Restrictions (Restricted, N, Warn => True);
11720 Error_Pragma_Arg ("& is not a valid profile", Argx);
11724 --------------------------
11725 -- Propagate_Exceptions --
11726 --------------------------
11728 -- pragma Propagate_Exceptions;
11730 -- Note: this pragma is obsolete and has no effect
11732 when Pragma_Propagate_Exceptions =>
11734 Check_Arg_Count (0);
11736 if In_Extended_Main_Source_Unit (N) then
11737 Propagate_Exceptions := True;
11744 -- pragma Psect_Object (
11745 -- [Internal =>] LOCAL_NAME,
11746 -- [, [External =>] EXTERNAL_SYMBOL]
11747 -- [, [Size =>] EXTERNAL_SYMBOL]);
11749 when Pragma_Psect_Object | Pragma_Common_Object =>
11750 Psect_Object : declare
11751 Args : Args_List (1 .. 3);
11752 Names : constant Name_List (1 .. 3) := (
11757 Internal : Node_Id renames Args (1);
11758 External : Node_Id renames Args (2);
11759 Size : Node_Id renames Args (3);
11761 Def_Id : Entity_Id;
11763 procedure Check_Too_Long (Arg : Node_Id);
11764 -- Posts message if the argument is an identifier with more
11765 -- than 31 characters, or a string literal with more than
11766 -- 31 characters, and we are operating under VMS
11768 --------------------
11769 -- Check_Too_Long --
11770 --------------------
11772 procedure Check_Too_Long (Arg : Node_Id) is
11773 X : constant Node_Id := Original_Node (Arg);
11776 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11778 ("inappropriate argument for pragma %", Arg);
11781 if OpenVMS_On_Target then
11782 if (Nkind (X) = N_String_Literal
11783 and then String_Length (Strval (X)) > 31)
11785 (Nkind (X) = N_Identifier
11786 and then Length_Of_Name (Chars (X)) > 31)
11789 ("argument for pragma % is longer than 31 characters",
11793 end Check_Too_Long;
11795 -- Start of processing for Common_Object/Psect_Object
11799 Gather_Associations (Names, Args);
11800 Process_Extended_Import_Export_Internal_Arg (Internal);
11802 Def_Id := Entity (Internal);
11804 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11806 ("pragma% must designate an object", Internal);
11809 Check_Too_Long (Internal);
11811 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11813 ("cannot use pragma% for imported/exported object",
11817 if Is_Concurrent_Type (Etype (Internal)) then
11819 ("cannot specify pragma % for task/protected object",
11823 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11825 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11827 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11830 if Ekind (Def_Id) = E_Constant then
11832 ("cannot specify pragma % for a constant", Internal);
11835 if Is_Record_Type (Etype (Internal)) then
11841 Ent := First_Entity (Etype (Internal));
11842 while Present (Ent) loop
11843 Decl := Declaration_Node (Ent);
11845 if Ekind (Ent) = E_Component
11846 and then Nkind (Decl) = N_Component_Declaration
11847 and then Present (Expression (Decl))
11848 and then Warn_On_Export_Import
11851 ("?object for pragma % has defaults", Internal);
11861 if Present (Size) then
11862 Check_Too_Long (Size);
11865 if Present (External) then
11866 Check_Arg_Is_External_Name (External);
11867 Check_Too_Long (External);
11870 -- If all error tests pass, link pragma on to the rep item chain
11872 Record_Rep_Item (Def_Id, N);
11879 -- pragma Pure [(library_unit_NAME)];
11881 when Pragma_Pure => Pure : declare
11885 Check_Ada_83_Warning;
11886 Check_Valid_Library_Unit_Pragma;
11888 if Nkind (N) = N_Null_Statement then
11892 Ent := Find_Lib_Unit_Name;
11894 Set_Has_Pragma_Pure (Ent);
11895 Set_Suppress_Elaboration_Warnings (Ent);
11902 -- pragma Pure_05 [(library_unit_NAME)];
11904 -- This pragma is useable only in GNAT_Mode, where it is used like
11905 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11906 -- it is ignored). It may be used after a pragma Preelaborate, in
11907 -- which case it overrides the effect of the pragma Preelaborate.
11908 -- This is used to implement AI-362 which recategorizes some run-time
11909 -- packages in Ada 2005 mode.
11911 when Pragma_Pure_05 => Pure_05 : declare
11916 Check_Valid_Library_Unit_Pragma;
11918 if not GNAT_Mode then
11919 Error_Pragma ("pragma% only available in GNAT mode");
11922 if Nkind (N) = N_Null_Statement then
11926 -- This is one of the few cases where we need to test the value of
11927 -- Ada_Version_Explicit rather than Ada_Version (which is always
11928 -- set to Ada_2012 in a predefined unit), we need to know the
11929 -- explicit version set to know if this pragma is active.
11931 if Ada_Version_Explicit >= Ada_2005 then
11932 Ent := Find_Lib_Unit_Name;
11933 Set_Is_Preelaborated (Ent, False);
11935 Set_Suppress_Elaboration_Warnings (Ent);
11939 -------------------
11940 -- Pure_Function --
11941 -------------------
11943 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11945 when Pragma_Pure_Function => Pure_Function : declare
11948 Def_Id : Entity_Id;
11949 Effective : Boolean := False;
11953 Check_Arg_Count (1);
11954 Check_Optional_Identifier (Arg1, Name_Entity);
11955 Check_Arg_Is_Local_Name (Arg1);
11956 E_Id := Get_Pragma_Arg (Arg1);
11958 if Error_Posted (E_Id) then
11962 -- Loop through homonyms (overloadings) of referenced entity
11964 E := Entity (E_Id);
11966 if Present (E) then
11968 Def_Id := Get_Base_Subprogram (E);
11970 if not Ekind_In (Def_Id, E_Function,
11971 E_Generic_Function,
11975 ("pragma% requires a function name", Arg1);
11978 Set_Is_Pure (Def_Id);
11980 if not Has_Pragma_Pure_Function (Def_Id) then
11981 Set_Has_Pragma_Pure_Function (Def_Id);
11985 exit when From_Aspect_Specification (N);
11987 exit when No (E) or else Scope (E) /= Current_Scope;
11991 and then Warn_On_Redundant_Constructs
11994 ("pragma Pure_Function on& is redundant?",
12000 --------------------
12001 -- Queuing_Policy --
12002 --------------------
12004 -- pragma Queuing_Policy (policy_IDENTIFIER);
12006 when Pragma_Queuing_Policy => declare
12010 Check_Ada_83_Warning;
12011 Check_Arg_Count (1);
12012 Check_No_Identifiers;
12013 Check_Arg_Is_Queuing_Policy (Arg1);
12014 Check_Valid_Configuration_Pragma;
12015 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12016 QP := Fold_Upper (Name_Buffer (1));
12018 if Queuing_Policy /= ' '
12019 and then Queuing_Policy /= QP
12021 Error_Msg_Sloc := Queuing_Policy_Sloc;
12022 Error_Pragma ("queuing policy incompatible with policy#");
12024 -- Set new policy, but always preserve System_Location since we
12025 -- like the error message with the run time name.
12028 Queuing_Policy := QP;
12030 if Queuing_Policy_Sloc /= System_Location then
12031 Queuing_Policy_Sloc := Loc;
12036 -----------------------
12037 -- Relative_Deadline --
12038 -----------------------
12040 -- pragma Relative_Deadline (time_span_EXPRESSION);
12042 when Pragma_Relative_Deadline => Relative_Deadline : declare
12043 P : constant Node_Id := Parent (N);
12048 Check_No_Identifiers;
12049 Check_Arg_Count (1);
12051 Arg := Get_Pragma_Arg (Arg1);
12053 -- The expression must be analyzed in the special manner described
12054 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12056 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12060 if Nkind (P) = N_Subprogram_Body then
12061 Check_In_Main_Program;
12065 elsif Nkind (P) = N_Task_Definition then
12068 -- Anything else is incorrect
12074 if Has_Relative_Deadline_Pragma (P) then
12075 Error_Pragma ("duplicate pragma% not allowed");
12077 Set_Has_Relative_Deadline_Pragma (P, True);
12079 if Nkind (P) = N_Task_Definition then
12080 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12083 end Relative_Deadline;
12085 ---------------------------
12086 -- Remote_Call_Interface --
12087 ---------------------------
12089 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12091 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12092 Cunit_Node : Node_Id;
12093 Cunit_Ent : Entity_Id;
12097 Check_Ada_83_Warning;
12098 Check_Valid_Library_Unit_Pragma;
12100 if Nkind (N) = N_Null_Statement then
12104 Cunit_Node := Cunit (Current_Sem_Unit);
12105 K := Nkind (Unit (Cunit_Node));
12106 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12108 if K = N_Package_Declaration
12109 or else K = N_Generic_Package_Declaration
12110 or else K = N_Subprogram_Declaration
12111 or else K = N_Generic_Subprogram_Declaration
12112 or else (K = N_Subprogram_Body
12113 and then Acts_As_Spec (Unit (Cunit_Node)))
12118 "pragma% must apply to package or subprogram declaration");
12121 Set_Is_Remote_Call_Interface (Cunit_Ent);
12122 end Remote_Call_Interface;
12128 -- pragma Remote_Types [(library_unit_NAME)];
12130 when Pragma_Remote_Types => Remote_Types : declare
12131 Cunit_Node : Node_Id;
12132 Cunit_Ent : Entity_Id;
12135 Check_Ada_83_Warning;
12136 Check_Valid_Library_Unit_Pragma;
12138 if Nkind (N) = N_Null_Statement then
12142 Cunit_Node := Cunit (Current_Sem_Unit);
12143 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12145 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12146 N_Generic_Package_Declaration)
12149 ("pragma% can only apply to a package declaration");
12152 Set_Is_Remote_Types (Cunit_Ent);
12159 -- pragma Ravenscar;
12161 when Pragma_Ravenscar =>
12163 Check_Arg_Count (0);
12164 Check_Valid_Configuration_Pragma;
12165 Set_Ravenscar_Profile (N);
12167 if Warn_On_Obsolescent_Feature then
12168 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12169 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12172 -------------------------
12173 -- Restricted_Run_Time --
12174 -------------------------
12176 -- pragma Restricted_Run_Time;
12178 when Pragma_Restricted_Run_Time =>
12180 Check_Arg_Count (0);
12181 Check_Valid_Configuration_Pragma;
12182 Set_Profile_Restrictions
12183 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12185 if Warn_On_Obsolescent_Feature then
12187 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12188 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12195 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12198 -- restriction_IDENTIFIER
12199 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12201 when Pragma_Restrictions =>
12202 Process_Restrictions_Or_Restriction_Warnings
12203 (Warn => Treat_Restrictions_As_Warnings);
12205 --------------------------
12206 -- Restriction_Warnings --
12207 --------------------------
12209 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12212 -- restriction_IDENTIFIER
12213 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12215 when Pragma_Restriction_Warnings =>
12217 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12223 -- pragma Reviewable;
12225 when Pragma_Reviewable =>
12226 Check_Ada_83_Warning;
12227 Check_Arg_Count (0);
12229 -- Call dummy debugging function rv. This is done to assist front
12230 -- end debugging. By placing a Reviewable pragma in the source
12231 -- program, a breakpoint on rv catches this place in the source,
12232 -- allowing convenient stepping to the point of interest.
12236 --------------------------
12237 -- Short_Circuit_And_Or --
12238 --------------------------
12240 when Pragma_Short_Circuit_And_Or =>
12242 Check_Arg_Count (0);
12243 Check_Valid_Configuration_Pragma;
12244 Short_Circuit_And_Or := True;
12246 -------------------
12247 -- Share_Generic --
12248 -------------------
12250 -- pragma Share_Generic (NAME {, NAME});
12252 when Pragma_Share_Generic =>
12254 Process_Generic_List;
12260 -- pragma Shared (LOCAL_NAME);
12262 when Pragma_Shared =>
12264 Process_Atomic_Shared_Volatile;
12266 --------------------
12267 -- Shared_Passive --
12268 --------------------
12270 -- pragma Shared_Passive [(library_unit_NAME)];
12272 -- Set the flag Is_Shared_Passive of program unit name entity
12274 when Pragma_Shared_Passive => Shared_Passive : declare
12275 Cunit_Node : Node_Id;
12276 Cunit_Ent : Entity_Id;
12279 Check_Ada_83_Warning;
12280 Check_Valid_Library_Unit_Pragma;
12282 if Nkind (N) = N_Null_Statement then
12286 Cunit_Node := Cunit (Current_Sem_Unit);
12287 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12289 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12290 N_Generic_Package_Declaration)
12293 ("pragma% can only apply to a package declaration");
12296 Set_Is_Shared_Passive (Cunit_Ent);
12297 end Shared_Passive;
12299 -----------------------
12300 -- Short_Descriptors --
12301 -----------------------
12303 -- pragma Short_Descriptors;
12305 when Pragma_Short_Descriptors =>
12307 Check_Arg_Count (0);
12308 Check_Valid_Configuration_Pragma;
12309 Short_Descriptors := True;
12311 ----------------------
12312 -- Source_File_Name --
12313 ----------------------
12315 -- There are five forms for this pragma:
12317 -- pragma Source_File_Name (
12318 -- [UNIT_NAME =>] unit_NAME,
12319 -- BODY_FILE_NAME => STRING_LITERAL
12320 -- [, [INDEX =>] INTEGER_LITERAL]);
12322 -- pragma Source_File_Name (
12323 -- [UNIT_NAME =>] unit_NAME,
12324 -- SPEC_FILE_NAME => STRING_LITERAL
12325 -- [, [INDEX =>] INTEGER_LITERAL]);
12327 -- pragma Source_File_Name (
12328 -- BODY_FILE_NAME => STRING_LITERAL
12329 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12330 -- [, CASING => CASING_SPEC]);
12332 -- pragma Source_File_Name (
12333 -- SPEC_FILE_NAME => STRING_LITERAL
12334 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12335 -- [, CASING => CASING_SPEC]);
12337 -- pragma Source_File_Name (
12338 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12339 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12340 -- [, CASING => CASING_SPEC]);
12342 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12344 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12345 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12346 -- only be used when no project file is used, while SFNP can only be
12347 -- used when a project file is used.
12349 -- No processing here. Processing was completed during parsing, since
12350 -- we need to have file names set as early as possible. Units are
12351 -- loaded well before semantic processing starts.
12353 -- The only processing we defer to this point is the check for
12354 -- correct placement.
12356 when Pragma_Source_File_Name =>
12358 Check_Valid_Configuration_Pragma;
12360 ------------------------------
12361 -- Source_File_Name_Project --
12362 ------------------------------
12364 -- See Source_File_Name for syntax
12366 -- No processing here. Processing was completed during parsing, since
12367 -- we need to have file names set as early as possible. Units are
12368 -- loaded well before semantic processing starts.
12370 -- The only processing we defer to this point is the check for
12371 -- correct placement.
12373 when Pragma_Source_File_Name_Project =>
12375 Check_Valid_Configuration_Pragma;
12377 -- Check that a pragma Source_File_Name_Project is used only in a
12378 -- configuration pragmas file.
12380 -- Pragmas Source_File_Name_Project should only be generated by
12381 -- the Project Manager in configuration pragmas files.
12383 -- This is really an ugly test. It seems to depend on some
12384 -- accidental and undocumented property. At the very least it
12385 -- needs to be documented, but it would be better to have a
12386 -- clean way of testing if we are in a configuration file???
12388 if Present (Parent (N)) then
12390 ("pragma% can only appear in a configuration pragmas file");
12393 ----------------------
12394 -- Source_Reference --
12395 ----------------------
12397 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12399 -- Nothing to do, all processing completed in Par.Prag, since we need
12400 -- the information for possible parser messages that are output.
12402 when Pragma_Source_Reference =>
12405 --------------------------------
12406 -- Static_Elaboration_Desired --
12407 --------------------------------
12409 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12411 when Pragma_Static_Elaboration_Desired =>
12413 Check_At_Most_N_Arguments (1);
12415 if Is_Compilation_Unit (Current_Scope)
12416 and then Ekind (Current_Scope) = E_Package
12418 Set_Static_Elaboration_Desired (Current_Scope, True);
12420 Error_Pragma ("pragma% must apply to a library-level package");
12427 -- pragma Storage_Size (EXPRESSION);
12429 when Pragma_Storage_Size => Storage_Size : declare
12430 P : constant Node_Id := Parent (N);
12434 Check_No_Identifiers;
12435 Check_Arg_Count (1);
12437 -- The expression must be analyzed in the special manner described
12438 -- in "Handling of Default Expressions" in sem.ads.
12440 Arg := Get_Pragma_Arg (Arg1);
12441 Preanalyze_Spec_Expression (Arg, Any_Integer);
12443 if not Is_Static_Expression (Arg) then
12444 Check_Restriction (Static_Storage_Size, Arg);
12447 if Nkind (P) /= N_Task_Definition then
12452 if Has_Storage_Size_Pragma (P) then
12453 Error_Pragma ("duplicate pragma% not allowed");
12455 Set_Has_Storage_Size_Pragma (P, True);
12458 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12459 -- ??? exp_ch9 should use this!
12467 -- pragma Storage_Unit (NUMERIC_LITERAL);
12469 -- Only permitted argument is System'Storage_Unit value
12471 when Pragma_Storage_Unit =>
12472 Check_No_Identifiers;
12473 Check_Arg_Count (1);
12474 Check_Arg_Is_Integer_Literal (Arg1);
12476 if Intval (Get_Pragma_Arg (Arg1)) /=
12477 UI_From_Int (Ttypes.System_Storage_Unit)
12479 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12481 ("the only allowed argument for pragma% is ^", Arg1);
12484 --------------------
12485 -- Stream_Convert --
12486 --------------------
12488 -- pragma Stream_Convert (
12489 -- [Entity =>] type_LOCAL_NAME,
12490 -- [Read =>] function_NAME,
12491 -- [Write =>] function NAME);
12493 when Pragma_Stream_Convert => Stream_Convert : declare
12495 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12496 -- Check that the given argument is the name of a local function
12497 -- of one argument that is not overloaded earlier in the current
12498 -- local scope. A check is also made that the argument is a
12499 -- function with one parameter.
12501 --------------------------------------
12502 -- Check_OK_Stream_Convert_Function --
12503 --------------------------------------
12505 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12509 Check_Arg_Is_Local_Name (Arg);
12510 Ent := Entity (Get_Pragma_Arg (Arg));
12512 if Has_Homonym (Ent) then
12514 ("argument for pragma% may not be overloaded", Arg);
12517 if Ekind (Ent) /= E_Function
12518 or else No (First_Formal (Ent))
12519 or else Present (Next_Formal (First_Formal (Ent)))
12522 ("argument for pragma% must be" &
12523 " function of one argument", Arg);
12525 end Check_OK_Stream_Convert_Function;
12527 -- Start of processing for Stream_Convert
12531 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12532 Check_Arg_Count (3);
12533 Check_Optional_Identifier (Arg1, Name_Entity);
12534 Check_Optional_Identifier (Arg2, Name_Read);
12535 Check_Optional_Identifier (Arg3, Name_Write);
12536 Check_Arg_Is_Local_Name (Arg1);
12537 Check_OK_Stream_Convert_Function (Arg2);
12538 Check_OK_Stream_Convert_Function (Arg3);
12541 Typ : constant Entity_Id :=
12542 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12543 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12544 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12547 Check_First_Subtype (Arg1);
12549 -- Check for too early or too late. Note that we don't enforce
12550 -- the rule about primitive operations in this case, since, as
12551 -- is the case for explicit stream attributes themselves, these
12552 -- restrictions are not appropriate. Note that the chaining of
12553 -- the pragma by Rep_Item_Too_Late is actually the critical
12554 -- processing done for this pragma.
12556 if Rep_Item_Too_Early (Typ, N)
12558 Rep_Item_Too_Late (Typ, N, FOnly => True)
12563 -- Return if previous error
12565 if Etype (Typ) = Any_Type
12567 Etype (Read) = Any_Type
12569 Etype (Write) = Any_Type
12576 if Underlying_Type (Etype (Read)) /= Typ then
12578 ("incorrect return type for function&", Arg2);
12581 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12583 ("incorrect parameter type for function&", Arg3);
12586 if Underlying_Type (Etype (First_Formal (Read))) /=
12587 Underlying_Type (Etype (Write))
12590 ("result type of & does not match Read parameter type",
12594 end Stream_Convert;
12596 -------------------------
12597 -- Style_Checks (GNAT) --
12598 -------------------------
12600 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12602 -- This is processed by the parser since some of the style checks
12603 -- take place during source scanning and parsing. This means that
12604 -- we don't need to issue error messages here.
12606 when Pragma_Style_Checks => Style_Checks : declare
12607 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12613 Check_No_Identifiers;
12615 -- Two argument form
12617 if Arg_Count = 2 then
12618 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12625 E_Id := Get_Pragma_Arg (Arg2);
12628 if not Is_Entity_Name (E_Id) then
12630 ("second argument of pragma% must be entity name",
12634 E := Entity (E_Id);
12640 Set_Suppress_Style_Checks (E,
12641 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12642 exit when No (Homonym (E));
12648 -- One argument form
12651 Check_Arg_Count (1);
12653 if Nkind (A) = N_String_Literal then
12657 Slen : constant Natural := Natural (String_Length (S));
12658 Options : String (1 .. Slen);
12664 C := Get_String_Char (S, Int (J));
12665 exit when not In_Character_Range (C);
12666 Options (J) := Get_Character (C);
12668 -- If at end of string, set options. As per discussion
12669 -- above, no need to check for errors, since we issued
12670 -- them in the parser.
12673 Set_Style_Check_Options (Options);
12681 elsif Nkind (A) = N_Identifier then
12682 if Chars (A) = Name_All_Checks then
12684 Set_GNAT_Style_Check_Options;
12686 Set_Default_Style_Check_Options;
12689 elsif Chars (A) = Name_On then
12690 Style_Check := True;
12692 elsif Chars (A) = Name_Off then
12693 Style_Check := False;
12703 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12705 when Pragma_Subtitle =>
12707 Check_Arg_Count (1);
12708 Check_Optional_Identifier (Arg1, Name_Subtitle);
12709 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12716 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12718 when Pragma_Suppress =>
12719 Process_Suppress_Unsuppress (True);
12725 -- pragma Suppress_All;
12727 -- The only check made here is that the pragma has no arguments.
12728 -- There are no placement rules, and the processing required (setting
12729 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12730 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12731 -- then creates and inserts a pragma Suppress (All_Checks).
12733 when Pragma_Suppress_All =>
12735 Check_Arg_Count (0);
12737 -------------------------
12738 -- Suppress_Debug_Info --
12739 -------------------------
12741 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12743 when Pragma_Suppress_Debug_Info =>
12745 Check_Arg_Count (1);
12746 Check_Optional_Identifier (Arg1, Name_Entity);
12747 Check_Arg_Is_Local_Name (Arg1);
12748 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
12750 ----------------------------------
12751 -- Suppress_Exception_Locations --
12752 ----------------------------------
12754 -- pragma Suppress_Exception_Locations;
12756 when Pragma_Suppress_Exception_Locations =>
12758 Check_Arg_Count (0);
12759 Check_Valid_Configuration_Pragma;
12760 Exception_Locations_Suppressed := True;
12762 -----------------------------
12763 -- Suppress_Initialization --
12764 -----------------------------
12766 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12768 when Pragma_Suppress_Initialization => Suppress_Init : declare
12774 Check_Arg_Count (1);
12775 Check_Optional_Identifier (Arg1, Name_Entity);
12776 Check_Arg_Is_Local_Name (Arg1);
12778 E_Id := Get_Pragma_Arg (Arg1);
12780 if Etype (E_Id) = Any_Type then
12784 E := Entity (E_Id);
12786 if not Is_Type (E) then
12787 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
12790 if Rep_Item_Too_Early (E, N)
12792 Rep_Item_Too_Late (E, N, FOnly => True)
12797 -- For incomplete/private type, set flag on full view
12799 if Is_Incomplete_Or_Private_Type (E) then
12800 if No (Full_View (Base_Type (E))) then
12802 ("argument of pragma% cannot be an incomplete type", Arg1);
12804 Set_Suppress_Initialization (Full_View (Base_Type (E)));
12807 -- For first subtype, set flag on base type
12809 elsif Is_First_Subtype (E) then
12810 Set_Suppress_Initialization (Base_Type (E));
12812 -- For other than first subtype, set flag on subtype itself
12815 Set_Suppress_Initialization (E);
12823 -- pragma System_Name (DIRECT_NAME);
12825 -- Syntax check: one argument, which must be the identifier GNAT or
12826 -- the identifier GCC, no other identifiers are acceptable.
12828 when Pragma_System_Name =>
12830 Check_No_Identifiers;
12831 Check_Arg_Count (1);
12832 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12834 -----------------------------
12835 -- Task_Dispatching_Policy --
12836 -----------------------------
12838 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12840 when Pragma_Task_Dispatching_Policy => declare
12844 Check_Ada_83_Warning;
12845 Check_Arg_Count (1);
12846 Check_No_Identifiers;
12847 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12848 Check_Valid_Configuration_Pragma;
12849 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12850 DP := Fold_Upper (Name_Buffer (1));
12852 if Task_Dispatching_Policy /= ' '
12853 and then Task_Dispatching_Policy /= DP
12855 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12857 ("task dispatching policy incompatible with policy#");
12859 -- Set new policy, but always preserve System_Location since we
12860 -- like the error message with the run time name.
12863 Task_Dispatching_Policy := DP;
12865 if Task_Dispatching_Policy_Sloc /= System_Location then
12866 Task_Dispatching_Policy_Sloc := Loc;
12875 -- pragma Task_Info (EXPRESSION);
12877 when Pragma_Task_Info => Task_Info : declare
12878 P : constant Node_Id := Parent (N);
12883 if Nkind (P) /= N_Task_Definition then
12884 Error_Pragma ("pragma% must appear in task definition");
12887 Check_No_Identifiers;
12888 Check_Arg_Count (1);
12890 Analyze_And_Resolve
12891 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12893 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12897 if Has_Task_Info_Pragma (P) then
12898 Error_Pragma ("duplicate pragma% not allowed");
12900 Set_Has_Task_Info_Pragma (P, True);
12908 -- pragma Task_Name (string_EXPRESSION);
12910 when Pragma_Task_Name => Task_Name : declare
12911 P : constant Node_Id := Parent (N);
12915 Check_No_Identifiers;
12916 Check_Arg_Count (1);
12918 Arg := Get_Pragma_Arg (Arg1);
12920 -- The expression is used in the call to Create_Task, and must be
12921 -- expanded there, not in the context of the current spec. It must
12922 -- however be analyzed to capture global references, in case it
12923 -- appears in a generic context.
12925 Preanalyze_And_Resolve (Arg, Standard_String);
12927 if Nkind (P) /= N_Task_Definition then
12931 if Has_Task_Name_Pragma (P) then
12932 Error_Pragma ("duplicate pragma% not allowed");
12934 Set_Has_Task_Name_Pragma (P, True);
12935 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12943 -- pragma Task_Storage (
12944 -- [Task_Type =>] LOCAL_NAME,
12945 -- [Top_Guard =>] static_integer_EXPRESSION);
12947 when Pragma_Task_Storage => Task_Storage : declare
12948 Args : Args_List (1 .. 2);
12949 Names : constant Name_List (1 .. 2) := (
12953 Task_Type : Node_Id renames Args (1);
12954 Top_Guard : Node_Id renames Args (2);
12960 Gather_Associations (Names, Args);
12962 if No (Task_Type) then
12964 ("missing task_type argument for pragma%");
12967 Check_Arg_Is_Local_Name (Task_Type);
12969 Ent := Entity (Task_Type);
12971 if not Is_Task_Type (Ent) then
12973 ("argument for pragma% must be task type", Task_Type);
12976 if No (Top_Guard) then
12978 ("pragma% takes two arguments", Task_Type);
12980 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12983 Check_First_Subtype (Task_Type);
12985 if Rep_Item_Too_Late (Ent, N) then
12990 --------------------------
12991 -- Thread_Local_Storage --
12992 --------------------------
12994 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12996 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13002 Check_Arg_Count (1);
13003 Check_Optional_Identifier (Arg1, Name_Entity);
13004 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13006 Id := Get_Pragma_Arg (Arg1);
13009 if not Is_Entity_Name (Id)
13010 or else Ekind (Entity (Id)) /= E_Variable
13012 Error_Pragma_Arg ("local variable name required", Arg1);
13017 if Rep_Item_Too_Early (E, N)
13018 or else Rep_Item_Too_Late (E, N)
13023 Set_Has_Pragma_Thread_Local_Storage (E);
13024 Set_Has_Gigi_Rep_Item (E);
13025 end Thread_Local_Storage;
13031 -- pragma Time_Slice (static_duration_EXPRESSION);
13033 when Pragma_Time_Slice => Time_Slice : declare
13039 Check_Arg_Count (1);
13040 Check_No_Identifiers;
13041 Check_In_Main_Program;
13042 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13044 if not Error_Posted (Arg1) then
13046 while Present (Nod) loop
13047 if Nkind (Nod) = N_Pragma
13048 and then Pragma_Name (Nod) = Name_Time_Slice
13050 Error_Msg_Name_1 := Pname;
13051 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13058 -- Process only if in main unit
13060 if Get_Source_Unit (Loc) = Main_Unit then
13061 Opt.Time_Slice_Set := True;
13062 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13064 if Val <= Ureal_0 then
13065 Opt.Time_Slice_Value := 0;
13067 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13068 Opt.Time_Slice_Value := 1_000_000_000;
13071 Opt.Time_Slice_Value :=
13072 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13081 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13083 -- TITLING_OPTION ::=
13084 -- [Title =>] STRING_LITERAL
13085 -- | [Subtitle =>] STRING_LITERAL
13087 when Pragma_Title => Title : declare
13088 Args : Args_List (1 .. 2);
13089 Names : constant Name_List (1 .. 2) := (
13095 Gather_Associations (Names, Args);
13098 for J in 1 .. 2 loop
13099 if Present (Args (J)) then
13100 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13105 ---------------------
13106 -- Unchecked_Union --
13107 ---------------------
13109 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13111 when Pragma_Unchecked_Union => Unchecked_Union : declare
13112 Assoc : constant Node_Id := Arg1;
13113 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13124 Check_No_Identifiers;
13125 Check_Arg_Count (1);
13126 Check_Arg_Is_Local_Name (Arg1);
13128 Find_Type (Type_Id);
13129 Typ := Entity (Type_Id);
13132 or else Rep_Item_Too_Early (Typ, N)
13136 Typ := Underlying_Type (Typ);
13139 if Rep_Item_Too_Late (Typ, N) then
13143 Check_First_Subtype (Arg1);
13145 -- Note remaining cases are references to a type in the current
13146 -- declarative part. If we find an error, we post the error on
13147 -- the relevant type declaration at an appropriate point.
13149 if not Is_Record_Type (Typ) then
13150 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13153 elsif Is_Tagged_Type (Typ) then
13154 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13157 elsif Is_Limited_Type (Typ) then
13159 ("Unchecked_Union must not be limited record type", Typ);
13160 Explain_Limited_Type (Typ, Typ);
13164 if not Has_Discriminants (Typ) then
13166 ("Unchecked_Union must have one discriminant", Typ);
13170 Discr := First_Discriminant (Typ);
13171 while Present (Discr) loop
13172 if No (Discriminant_Default_Value (Discr)) then
13174 ("Unchecked_Union discriminant must have default value",
13178 Next_Discriminant (Discr);
13181 Tdef := Type_Definition (Declaration_Node (Typ));
13182 Clist := Component_List (Tdef);
13184 Comp := First (Component_Items (Clist));
13185 while Present (Comp) loop
13186 Check_Component (Comp, Typ);
13190 if No (Clist) or else No (Variant_Part (Clist)) then
13192 ("Unchecked_Union must have variant part",
13197 Vpart := Variant_Part (Clist);
13199 Variant := First (Variants (Vpart));
13200 while Present (Variant) loop
13201 Check_Variant (Variant, Typ);
13206 Set_Is_Unchecked_Union (Typ);
13207 Set_Convention (Typ, Convention_C);
13208 Set_Has_Unchecked_Union (Base_Type (Typ));
13209 Set_Is_Unchecked_Union (Base_Type (Typ));
13210 end Unchecked_Union;
13212 ------------------------
13213 -- Unimplemented_Unit --
13214 ------------------------
13216 -- pragma Unimplemented_Unit;
13218 -- Note: this only gives an error if we are generating code, or if
13219 -- we are in a generic library unit (where the pragma appears in the
13220 -- body, not in the spec).
13222 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13223 Cunitent : constant Entity_Id :=
13224 Cunit_Entity (Get_Source_Unit (Loc));
13225 Ent_Kind : constant Entity_Kind :=
13230 Check_Arg_Count (0);
13232 if Operating_Mode = Generate_Code
13233 or else Ent_Kind = E_Generic_Function
13234 or else Ent_Kind = E_Generic_Procedure
13235 or else Ent_Kind = E_Generic_Package
13237 Get_Name_String (Chars (Cunitent));
13238 Set_Casing (Mixed_Case);
13239 Write_Str (Name_Buffer (1 .. Name_Len));
13240 Write_Str (" is not supported in this configuration");
13242 raise Unrecoverable_Error;
13244 end Unimplemented_Unit;
13246 ------------------------
13247 -- Universal_Aliasing --
13248 ------------------------
13250 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13252 when Pragma_Universal_Aliasing => Universal_Alias : declare
13257 Check_Arg_Count (1);
13258 Check_Optional_Identifier (Arg2, Name_Entity);
13259 Check_Arg_Is_Local_Name (Arg1);
13260 E_Id := Entity (Get_Pragma_Arg (Arg1));
13262 if E_Id = Any_Type then
13264 elsif No (E_Id) or else not Is_Type (E_Id) then
13265 Error_Pragma_Arg ("pragma% requires type", Arg1);
13268 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13269 end Universal_Alias;
13271 --------------------
13272 -- Universal_Data --
13273 --------------------
13275 -- pragma Universal_Data [(library_unit_NAME)];
13277 when Pragma_Universal_Data =>
13280 -- If this is a configuration pragma, then set the universal
13281 -- addressing option, otherwise confirm that the pragma satisfies
13282 -- the requirements of library unit pragma placement and leave it
13283 -- to the GNAAMP back end to detect the pragma (avoids transitive
13284 -- setting of the option due to withed units).
13286 if Is_Configuration_Pragma then
13287 Universal_Addressing_On_AAMP := True;
13289 Check_Valid_Library_Unit_Pragma;
13292 if not AAMP_On_Target then
13293 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13300 -- pragma Unmodified (local_Name {, local_Name});
13302 when Pragma_Unmodified => Unmodified : declare
13303 Arg_Node : Node_Id;
13304 Arg_Expr : Node_Id;
13305 Arg_Ent : Entity_Id;
13309 Check_At_Least_N_Arguments (1);
13311 -- Loop through arguments
13314 while Present (Arg_Node) loop
13315 Check_No_Identifier (Arg_Node);
13317 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13318 -- in fact generate reference, so that the entity will have a
13319 -- reference, which will inhibit any warnings about it not
13320 -- being referenced, and also properly show up in the ali file
13321 -- as a reference. But this reference is recorded before the
13322 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13323 -- generated for this reference.
13325 Check_Arg_Is_Local_Name (Arg_Node);
13326 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13328 if Is_Entity_Name (Arg_Expr) then
13329 Arg_Ent := Entity (Arg_Expr);
13331 if not Is_Assignable (Arg_Ent) then
13333 ("pragma% can only be applied to a variable",
13336 Set_Has_Pragma_Unmodified (Arg_Ent);
13348 -- pragma Unreferenced (local_Name {, local_Name});
13350 -- or when used in a context clause:
13352 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13354 when Pragma_Unreferenced => Unreferenced : declare
13355 Arg_Node : Node_Id;
13356 Arg_Expr : Node_Id;
13357 Arg_Ent : Entity_Id;
13362 Check_At_Least_N_Arguments (1);
13364 -- Check case of appearing within context clause
13366 if Is_In_Context_Clause then
13368 -- The arguments must all be units mentioned in a with clause
13369 -- in the same context clause. Note we already checked (in
13370 -- Par.Prag) that the arguments are either identifiers or
13371 -- selected components.
13374 while Present (Arg_Node) loop
13375 Citem := First (List_Containing (N));
13376 while Citem /= N loop
13377 if Nkind (Citem) = N_With_Clause
13379 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13381 Set_Has_Pragma_Unreferenced
13384 (Library_Unit (Citem))));
13386 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13395 ("argument of pragma% is not with'ed unit", Arg_Node);
13401 -- Case of not in list of context items
13405 while Present (Arg_Node) loop
13406 Check_No_Identifier (Arg_Node);
13408 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13409 -- will in fact generate reference, so that the entity will
13410 -- have a reference, which will inhibit any warnings about
13411 -- it not being referenced, and also properly show up in the
13412 -- ali file as a reference. But this reference is recorded
13413 -- before the Has_Pragma_Unreferenced flag is set, so that
13414 -- no warning is 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 the entity is overloaded, the pragma applies to the
13423 -- most recent overloading, as documented. In this case,
13424 -- name resolution does not generate a reference, so it
13425 -- must be done here explicitly.
13427 if Is_Overloaded (Arg_Expr) then
13428 Generate_Reference (Arg_Ent, N);
13431 Set_Has_Pragma_Unreferenced (Arg_Ent);
13439 --------------------------
13440 -- Unreferenced_Objects --
13441 --------------------------
13443 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13445 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13446 Arg_Node : Node_Id;
13447 Arg_Expr : Node_Id;
13451 Check_At_Least_N_Arguments (1);
13454 while Present (Arg_Node) loop
13455 Check_No_Identifier (Arg_Node);
13456 Check_Arg_Is_Local_Name (Arg_Node);
13457 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13459 if not Is_Entity_Name (Arg_Expr)
13460 or else not Is_Type (Entity (Arg_Expr))
13463 ("argument for pragma% must be type or subtype", Arg_Node);
13466 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13469 end Unreferenced_Objects;
13471 ------------------------------
13472 -- Unreserve_All_Interrupts --
13473 ------------------------------
13475 -- pragma Unreserve_All_Interrupts;
13477 when Pragma_Unreserve_All_Interrupts =>
13479 Check_Arg_Count (0);
13481 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13482 Unreserve_All_Interrupts := True;
13489 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13491 when Pragma_Unsuppress =>
13493 Process_Suppress_Unsuppress (False);
13495 -------------------
13496 -- Use_VADS_Size --
13497 -------------------
13499 -- pragma Use_VADS_Size;
13501 when Pragma_Use_VADS_Size =>
13503 Check_Arg_Count (0);
13504 Check_Valid_Configuration_Pragma;
13505 Use_VADS_Size := True;
13507 ---------------------
13508 -- Validity_Checks --
13509 ---------------------
13511 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13513 when Pragma_Validity_Checks => Validity_Checks : declare
13514 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13520 Check_Arg_Count (1);
13521 Check_No_Identifiers;
13523 if Nkind (A) = N_String_Literal then
13527 Slen : constant Natural := Natural (String_Length (S));
13528 Options : String (1 .. Slen);
13534 C := Get_String_Char (S, Int (J));
13535 exit when not In_Character_Range (C);
13536 Options (J) := Get_Character (C);
13539 Set_Validity_Check_Options (Options);
13547 elsif Nkind (A) = N_Identifier then
13549 if Chars (A) = Name_All_Checks then
13550 Set_Validity_Check_Options ("a");
13552 elsif Chars (A) = Name_On then
13553 Validity_Checks_On := True;
13555 elsif Chars (A) = Name_Off then
13556 Validity_Checks_On := False;
13560 end Validity_Checks;
13566 -- pragma Volatile (LOCAL_NAME);
13568 when Pragma_Volatile =>
13569 Process_Atomic_Shared_Volatile;
13571 -------------------------
13572 -- Volatile_Components --
13573 -------------------------
13575 -- pragma Volatile_Components (array_LOCAL_NAME);
13577 -- Volatile is handled by the same circuit as Atomic_Components
13583 -- pragma Warnings (On | Off);
13584 -- pragma Warnings (On | Off, LOCAL_NAME);
13585 -- pragma Warnings (static_string_EXPRESSION);
13586 -- pragma Warnings (On | Off, STRING_LITERAL);
13588 when Pragma_Warnings => Warnings : begin
13590 Check_At_Least_N_Arguments (1);
13591 Check_No_Identifiers;
13593 -- If debug flag -gnatd.i is set, pragma is ignored
13595 if Debug_Flag_Dot_I then
13599 -- Process various forms of the pragma
13602 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13605 -- One argument case
13607 if Arg_Count = 1 then
13609 -- On/Off one argument case was processed by parser
13611 if Nkind (Argx) = N_Identifier
13613 (Chars (Argx) = Name_On
13615 Chars (Argx) = Name_Off)
13619 -- One argument case must be ON/OFF or static string expr
13621 elsif not Is_Static_String_Expression (Arg1) then
13623 ("argument of pragma% must be On/Off or " &
13624 "static string expression", Arg1);
13626 -- One argument string expression case
13630 Lit : constant Node_Id := Expr_Value_S (Argx);
13631 Str : constant String_Id := Strval (Lit);
13632 Len : constant Nat := String_Length (Str);
13640 while J <= Len loop
13641 C := Get_String_Char (Str, J);
13642 OK := In_Character_Range (C);
13645 Chr := Get_Character (C);
13649 if J < Len and then Chr = '.' then
13651 C := Get_String_Char (Str, J);
13652 Chr := Get_Character (C);
13654 if not Set_Dot_Warning_Switch (Chr) then
13656 ("invalid warning switch character " &
13663 OK := Set_Warning_Switch (Chr);
13669 ("invalid warning switch character " & Chr,
13678 -- Two or more arguments (must be two)
13681 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13682 Check_At_Most_N_Arguments (2);
13690 E_Id := Get_Pragma_Arg (Arg2);
13693 -- In the expansion of an inlined body, a reference to
13694 -- the formal may be wrapped in a conversion if the
13695 -- actual is a conversion. Retrieve the real entity name.
13697 if (In_Instance_Body
13698 or else In_Inlined_Body)
13699 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13701 E_Id := Expression (E_Id);
13704 -- Entity name case
13706 if Is_Entity_Name (E_Id) then
13707 E := Entity (E_Id);
13714 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13717 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13718 and then Warn_On_Warnings_Off
13720 Warnings_Off_Pragmas.Append ((N, E));
13723 if Is_Enumeration_Type (E) then
13727 Lit := First_Literal (E);
13728 while Present (Lit) loop
13729 Set_Warnings_Off (Lit);
13730 Next_Literal (Lit);
13735 exit when No (Homonym (E));
13740 -- Error if not entity or static string literal case
13742 elsif not Is_Static_String_Expression (Arg2) then
13744 ("second argument of pragma% must be entity " &
13745 "name or static string expression", Arg2);
13747 -- String literal case
13750 String_To_Name_Buffer
13751 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13753 -- Note on configuration pragma case: If this is a
13754 -- configuration pragma, then for an OFF pragma, we
13755 -- just set Config True in the call, which is all
13756 -- that needs to be done. For the case of ON, this
13757 -- is normally an error, unless it is canceling the
13758 -- effect of a previous OFF pragma in the same file.
13759 -- In any other case, an error will be signalled (ON
13760 -- with no matching OFF).
13762 if Chars (Argx) = Name_Off then
13763 Set_Specific_Warning_Off
13764 (Loc, Name_Buffer (1 .. Name_Len),
13765 Config => Is_Configuration_Pragma);
13767 elsif Chars (Argx) = Name_On then
13768 Set_Specific_Warning_On
13769 (Loc, Name_Buffer (1 .. Name_Len), Err);
13773 ("?pragma Warnings On with no " &
13774 "matching Warnings Off",
13784 -------------------
13785 -- Weak_External --
13786 -------------------
13788 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13790 when Pragma_Weak_External => Weak_External : declare
13795 Check_Arg_Count (1);
13796 Check_Optional_Identifier (Arg1, Name_Entity);
13797 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13798 Ent := Entity (Get_Pragma_Arg (Arg1));
13800 if Rep_Item_Too_Early (Ent, N) then
13803 Ent := Underlying_Type (Ent);
13806 -- The only processing required is to link this item on to the
13807 -- list of rep items for the given entity. This is accomplished
13808 -- by the call to Rep_Item_Too_Late (when no error is detected
13809 -- and False is returned).
13811 if Rep_Item_Too_Late (Ent, N) then
13814 Set_Has_Gigi_Rep_Item (Ent);
13818 -----------------------------
13819 -- Wide_Character_Encoding --
13820 -----------------------------
13822 -- pragma Wide_Character_Encoding (IDENTIFIER);
13824 when Pragma_Wide_Character_Encoding =>
13827 -- Nothing to do, handled in parser. Note that we do not enforce
13828 -- configuration pragma placement, this pragma can appear at any
13829 -- place in the source, allowing mixed encodings within a single
13834 --------------------
13835 -- Unknown_Pragma --
13836 --------------------
13838 -- Should be impossible, since the case of an unknown pragma is
13839 -- separately processed before the case statement is entered.
13841 when Unknown_Pragma =>
13842 raise Program_Error;
13845 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13846 -- until AI is formally approved.
13848 -- Check_Order_Dependence;
13851 when Pragma_Exit => null;
13852 end Analyze_Pragma;
13854 -------------------
13855 -- Check_Enabled --
13856 -------------------
13858 function Check_Enabled (Nam : Name_Id) return Boolean is
13862 -- Loop through entries in check policy list
13864 PP := Opt.Check_Policy_List;
13866 -- If there are no specific entries that matched, then we let the
13867 -- setting of assertions govern. Note that this provides the needed
13868 -- compatibility with the RM for the cases of assertion, invariant,
13869 -- precondition, predicate, and postcondition.
13872 return Assertions_Enabled;
13874 -- Here we have an entry see if it matches
13878 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13881 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13882 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13883 when Name_On | Name_Check =>
13885 when Name_Off | Name_Ignore =>
13888 raise Program_Error;
13892 PP := Next_Pragma (PP);
13899 ---------------------------------
13900 -- Delay_Config_Pragma_Analyze --
13901 ---------------------------------
13903 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13905 return Pragma_Name (N) = Name_Interrupt_State
13907 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13908 end Delay_Config_Pragma_Analyze;
13910 -------------------------
13911 -- Get_Base_Subprogram --
13912 -------------------------
13914 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13915 Result : Entity_Id;
13918 -- Follow subprogram renaming chain
13921 while Is_Subprogram (Result)
13923 Nkind (Parent (Declaration_Node (Result))) =
13924 N_Subprogram_Renaming_Declaration
13925 and then Present (Alias (Result))
13927 Result := Alias (Result);
13931 end Get_Base_Subprogram;
13937 procedure Initialize is
13942 -----------------------------
13943 -- Is_Config_Static_String --
13944 -----------------------------
13946 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13948 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13949 -- This is an internal recursive function that is just like the outer
13950 -- function except that it adds the string to the name buffer rather
13951 -- than placing the string in the name buffer.
13953 ------------------------------
13954 -- Add_Config_Static_String --
13955 ------------------------------
13957 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13964 if Nkind (N) = N_Op_Concat then
13965 if Add_Config_Static_String (Left_Opnd (N)) then
13966 N := Right_Opnd (N);
13972 if Nkind (N) /= N_String_Literal then
13973 Error_Msg_N ("string literal expected for pragma argument", N);
13977 for J in 1 .. String_Length (Strval (N)) loop
13978 C := Get_String_Char (Strval (N), J);
13980 if not In_Character_Range (C) then
13982 ("string literal contains invalid wide character",
13983 Sloc (N) + 1 + Source_Ptr (J));
13987 Add_Char_To_Name_Buffer (Get_Character (C));
13992 end Add_Config_Static_String;
13994 -- Start of processing for Is_Config_Static_String
13999 return Add_Config_Static_String (Arg);
14000 end Is_Config_Static_String;
14002 -----------------------------------------
14003 -- Is_Non_Significant_Pragma_Reference --
14004 -----------------------------------------
14006 -- This function makes use of the following static table which indicates
14007 -- whether a given pragma is significant.
14009 -- -1 indicates that references in any argument position are significant
14010 -- 0 indicates that appearance in any argument is not significant
14011 -- +n indicates that appearance as argument n is significant, but all
14012 -- other arguments are not significant
14013 -- 99 special processing required (e.g. for pragma Check)
14015 Sig_Flags : constant array (Pragma_Id) of Int :=
14016 (Pragma_AST_Entry => -1,
14017 Pragma_Abort_Defer => -1,
14018 Pragma_Ada_83 => -1,
14019 Pragma_Ada_95 => -1,
14020 Pragma_Ada_05 => -1,
14021 Pragma_Ada_2005 => -1,
14022 Pragma_Ada_12 => -1,
14023 Pragma_Ada_2012 => -1,
14024 Pragma_All_Calls_Remote => -1,
14025 Pragma_Annotate => -1,
14026 Pragma_Assert => -1,
14027 Pragma_Assertion_Policy => 0,
14028 Pragma_Assume_No_Invalid_Values => 0,
14029 Pragma_Asynchronous => -1,
14030 Pragma_Atomic => 0,
14031 Pragma_Atomic_Components => 0,
14032 Pragma_Attach_Handler => -1,
14033 Pragma_Check => 99,
14034 Pragma_Check_Name => 0,
14035 Pragma_Check_Policy => 0,
14036 Pragma_CIL_Constructor => -1,
14037 Pragma_CPP_Class => 0,
14038 Pragma_CPP_Constructor => 0,
14039 Pragma_CPP_Virtual => 0,
14040 Pragma_CPP_Vtable => 0,
14042 Pragma_C_Pass_By_Copy => 0,
14043 Pragma_Comment => 0,
14044 Pragma_Common_Object => -1,
14045 Pragma_Compile_Time_Error => -1,
14046 Pragma_Compile_Time_Warning => -1,
14047 Pragma_Compiler_Unit => 0,
14048 Pragma_Complete_Representation => 0,
14049 Pragma_Complex_Representation => 0,
14050 Pragma_Component_Alignment => -1,
14051 Pragma_Controlled => 0,
14052 Pragma_Convention => 0,
14053 Pragma_Convention_Identifier => 0,
14054 Pragma_Debug => -1,
14055 Pragma_Debug_Policy => 0,
14056 Pragma_Detect_Blocking => -1,
14057 Pragma_Default_Storage_Pool => -1,
14058 Pragma_Dimension => -1,
14059 Pragma_Discard_Names => 0,
14060 Pragma_Elaborate => -1,
14061 Pragma_Elaborate_All => -1,
14062 Pragma_Elaborate_Body => -1,
14063 Pragma_Elaboration_Checks => -1,
14064 Pragma_Eliminate => -1,
14065 Pragma_Export => -1,
14066 Pragma_Export_Exception => -1,
14067 Pragma_Export_Function => -1,
14068 Pragma_Export_Object => -1,
14069 Pragma_Export_Procedure => -1,
14070 Pragma_Export_Value => -1,
14071 Pragma_Export_Valued_Procedure => -1,
14072 Pragma_Extend_System => -1,
14073 Pragma_Extensions_Allowed => -1,
14074 Pragma_External => -1,
14075 Pragma_Favor_Top_Level => -1,
14076 Pragma_External_Name_Casing => -1,
14077 Pragma_Fast_Math => -1,
14078 Pragma_Finalize_Storage_Only => 0,
14079 Pragma_Float_Representation => 0,
14080 Pragma_Ident => -1,
14081 Pragma_Implemented => -1,
14082 Pragma_Implicit_Packing => 0,
14083 Pragma_Import => +2,
14084 Pragma_Import_Exception => 0,
14085 Pragma_Import_Function => 0,
14086 Pragma_Import_Object => 0,
14087 Pragma_Import_Procedure => 0,
14088 Pragma_Import_Valued_Procedure => 0,
14089 Pragma_Independent => 0,
14090 Pragma_Independent_Components => 0,
14091 Pragma_Initialize_Scalars => -1,
14092 Pragma_Inline => 0,
14093 Pragma_Inline_Always => 0,
14094 Pragma_Inline_Generic => 0,
14095 Pragma_Inspection_Point => -1,
14096 Pragma_Interface => +2,
14097 Pragma_Interface_Name => +2,
14098 Pragma_Interrupt_Handler => -1,
14099 Pragma_Interrupt_Priority => -1,
14100 Pragma_Interrupt_State => -1,
14101 Pragma_Invariant => -1,
14102 Pragma_Java_Constructor => -1,
14103 Pragma_Java_Interface => -1,
14104 Pragma_Keep_Names => 0,
14105 Pragma_License => -1,
14106 Pragma_Link_With => -1,
14107 Pragma_Linker_Alias => -1,
14108 Pragma_Linker_Constructor => -1,
14109 Pragma_Linker_Destructor => -1,
14110 Pragma_Linker_Options => -1,
14111 Pragma_Linker_Section => -1,
14113 Pragma_Locking_Policy => -1,
14114 Pragma_Long_Float => -1,
14115 Pragma_Machine_Attribute => -1,
14117 Pragma_Main_Storage => -1,
14118 Pragma_Memory_Size => -1,
14119 Pragma_No_Return => 0,
14120 Pragma_No_Body => 0,
14121 Pragma_No_Run_Time => -1,
14122 Pragma_No_Strict_Aliasing => -1,
14123 Pragma_Normalize_Scalars => -1,
14124 Pragma_Obsolescent => 0,
14125 Pragma_Optimize => -1,
14126 Pragma_Optimize_Alignment => -1,
14127 Pragma_Ordered => 0,
14130 Pragma_Passive => -1,
14131 Pragma_Preelaborable_Initialization => -1,
14132 Pragma_Polling => -1,
14133 Pragma_Persistent_BSS => 0,
14134 Pragma_Postcondition => -1,
14135 Pragma_Precondition => -1,
14136 Pragma_Predicate => -1,
14137 Pragma_Preelaborate => -1,
14138 Pragma_Preelaborate_05 => -1,
14139 Pragma_Priority => -1,
14140 Pragma_Priority_Specific_Dispatching => -1,
14141 Pragma_Profile => 0,
14142 Pragma_Profile_Warnings => 0,
14143 Pragma_Propagate_Exceptions => -1,
14144 Pragma_Psect_Object => -1,
14146 Pragma_Pure_05 => -1,
14147 Pragma_Pure_Function => -1,
14148 Pragma_Queuing_Policy => -1,
14149 Pragma_Ravenscar => -1,
14150 Pragma_Relative_Deadline => -1,
14151 Pragma_Remote_Call_Interface => -1,
14152 Pragma_Remote_Types => -1,
14153 Pragma_Restricted_Run_Time => -1,
14154 Pragma_Restriction_Warnings => -1,
14155 Pragma_Restrictions => -1,
14156 Pragma_Reviewable => -1,
14157 Pragma_Short_Circuit_And_Or => -1,
14158 Pragma_Share_Generic => -1,
14159 Pragma_Shared => -1,
14160 Pragma_Shared_Passive => -1,
14161 Pragma_Short_Descriptors => 0,
14162 Pragma_Source_File_Name => -1,
14163 Pragma_Source_File_Name_Project => -1,
14164 Pragma_Source_Reference => -1,
14165 Pragma_Storage_Size => -1,
14166 Pragma_Storage_Unit => -1,
14167 Pragma_Static_Elaboration_Desired => -1,
14168 Pragma_Stream_Convert => -1,
14169 Pragma_Style_Checks => -1,
14170 Pragma_Subtitle => -1,
14171 Pragma_Suppress => 0,
14172 Pragma_Suppress_Exception_Locations => 0,
14173 Pragma_Suppress_All => -1,
14174 Pragma_Suppress_Debug_Info => 0,
14175 Pragma_Suppress_Initialization => 0,
14176 Pragma_System_Name => -1,
14177 Pragma_Task_Dispatching_Policy => -1,
14178 Pragma_Task_Info => -1,
14179 Pragma_Task_Name => -1,
14180 Pragma_Task_Storage => 0,
14181 Pragma_Thread_Local_Storage => 0,
14182 Pragma_Time_Slice => -1,
14183 Pragma_Title => -1,
14184 Pragma_Unchecked_Union => 0,
14185 Pragma_Unimplemented_Unit => -1,
14186 Pragma_Universal_Aliasing => -1,
14187 Pragma_Universal_Data => -1,
14188 Pragma_Unmodified => -1,
14189 Pragma_Unreferenced => -1,
14190 Pragma_Unreferenced_Objects => -1,
14191 Pragma_Unreserve_All_Interrupts => -1,
14192 Pragma_Unsuppress => 0,
14193 Pragma_Use_VADS_Size => -1,
14194 Pragma_Validity_Checks => -1,
14195 Pragma_Volatile => 0,
14196 Pragma_Volatile_Components => 0,
14197 Pragma_Warnings => -1,
14198 Pragma_Weak_External => -1,
14199 Pragma_Wide_Character_Encoding => 0,
14200 Unknown_Pragma => 0);
14202 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14211 if Nkind (P) /= N_Pragma_Argument_Association then
14215 Id := Get_Pragma_Id (Parent (P));
14216 C := Sig_Flags (Id);
14228 -- For pragma Check, the first argument is not significant,
14229 -- the second and the third (if present) arguments are
14232 when Pragma_Check =>
14234 P = First (Pragma_Argument_Associations (Parent (P)));
14237 raise Program_Error;
14241 A := First (Pragma_Argument_Associations (Parent (P)));
14242 for J in 1 .. C - 1 loop
14250 return A = P; -- is this wrong way round ???
14253 end Is_Non_Significant_Pragma_Reference;
14255 ------------------------------
14256 -- Is_Pragma_String_Literal --
14257 ------------------------------
14259 -- This function returns true if the corresponding pragma argument is a
14260 -- static string expression. These are the only cases in which string
14261 -- literals can appear as pragma arguments. We also allow a string literal
14262 -- as the first argument to pragma Assert (although it will of course
14263 -- always generate a type error).
14265 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14266 Pragn : constant Node_Id := Parent (Par);
14267 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14268 Pname : constant Name_Id := Pragma_Name (Pragn);
14274 N := First (Assoc);
14281 if Pname = Name_Assert then
14284 elsif Pname = Name_Export then
14287 elsif Pname = Name_Ident then
14290 elsif Pname = Name_Import then
14293 elsif Pname = Name_Interface_Name then
14296 elsif Pname = Name_Linker_Alias then
14299 elsif Pname = Name_Linker_Section then
14302 elsif Pname = Name_Machine_Attribute then
14305 elsif Pname = Name_Source_File_Name then
14308 elsif Pname = Name_Source_Reference then
14311 elsif Pname = Name_Title then
14314 elsif Pname = Name_Subtitle then
14320 end Is_Pragma_String_Literal;
14322 --------------------------------------
14323 -- Process_Compilation_Unit_Pragmas --
14324 --------------------------------------
14326 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14328 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14329 -- strange because it comes at the end of the unit. Rational has the
14330 -- same name for a pragma, but treats it as a program unit pragma, In
14331 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14332 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14333 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14334 -- the context clause to ensure the correct processing.
14336 if Has_Pragma_Suppress_All (N) then
14337 Prepend_To (Context_Items (N),
14338 Make_Pragma (Sloc (N),
14339 Chars => Name_Suppress,
14340 Pragma_Argument_Associations => New_List (
14341 Make_Pragma_Argument_Association (Sloc (N),
14342 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14345 -- Nothing else to do at the current time!
14347 end Process_Compilation_Unit_Pragmas;
14358 --------------------------------
14359 -- Set_Encoded_Interface_Name --
14360 --------------------------------
14362 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14363 Str : constant String_Id := Strval (S);
14364 Len : constant Int := String_Length (Str);
14369 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14372 -- Stores encoded value of character code CC. The encoding we use an
14373 -- underscore followed by four lower case hex digits.
14379 procedure Encode is
14381 Store_String_Char (Get_Char_Code ('_'));
14383 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14385 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14387 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14389 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14392 -- Start of processing for Set_Encoded_Interface_Name
14395 -- If first character is asterisk, this is a link name, and we leave it
14396 -- completely unmodified. We also ignore null strings (the latter case
14397 -- happens only in error cases) and no encoding should occur for Java or
14398 -- AAMP interface names.
14401 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14402 or else VM_Target /= No_VM
14403 or else AAMP_On_Target
14405 Set_Interface_Name (E, S);
14410 CC := Get_String_Char (Str, J);
14412 exit when not In_Character_Range (CC);
14414 C := Get_Character (CC);
14416 exit when C /= '_' and then C /= '$'
14417 and then C not in '0' .. '9'
14418 and then C not in 'a' .. 'z'
14419 and then C not in 'A' .. 'Z';
14422 Set_Interface_Name (E, S);
14430 -- Here we need to encode. The encoding we use as follows:
14431 -- three underscores + four hex digits (lower case)
14435 for J in 1 .. String_Length (Str) loop
14436 CC := Get_String_Char (Str, J);
14438 if not In_Character_Range (CC) then
14441 C := Get_Character (CC);
14443 if C = '_' or else C = '$'
14444 or else C in '0' .. '9'
14445 or else C in 'a' .. 'z'
14446 or else C in 'A' .. 'Z'
14448 Store_String_Char (CC);
14455 Set_Interface_Name (E,
14456 Make_String_Literal (Sloc (S),
14457 Strval => End_String));
14459 end Set_Encoded_Interface_Name;
14461 -------------------
14462 -- Set_Unit_Name --
14463 -------------------
14465 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14470 if Nkind (N) = N_Identifier
14471 and then Nkind (With_Item) = N_Identifier
14473 Set_Entity (N, Entity (With_Item));
14475 elsif Nkind (N) = N_Selected_Component then
14476 Change_Selected_Component_To_Expanded_Name (N);
14477 Set_Entity (N, Entity (With_Item));
14478 Set_Entity (Selector_Name (N), Entity (N));
14480 Pref := Prefix (N);
14481 Scop := Scope (Entity (N));
14482 while Nkind (Pref) = N_Selected_Component loop
14483 Change_Selected_Component_To_Expanded_Name (Pref);
14484 Set_Entity (Selector_Name (Pref), Scop);
14485 Set_Entity (Pref, Scop);
14486 Pref := Prefix (Pref);
14487 Scop := Scope (Scop);
14490 Set_Entity (Pref, Scop);