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
4769 Convention (Subprogram_Def) /= Convention_Java
4771 Check_Duplicated_Export_Name (Link_Nam);
4773 end Process_Interface_Name;
4775 -----------------------------------------
4776 -- Process_Interrupt_Or_Attach_Handler --
4777 -----------------------------------------
4779 procedure Process_Interrupt_Or_Attach_Handler is
4780 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4781 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4782 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4785 Set_Is_Interrupt_Handler (Handler_Proc);
4787 -- If the pragma is not associated with a handler procedure within a
4788 -- protected type, then it must be for a nonprotected procedure for
4789 -- the AAMP target, in which case we don't associate a representation
4790 -- item with the procedure's scope.
4792 if Ekind (Proc_Scope) = E_Protected_Type then
4793 if Prag_Id = Pragma_Interrupt_Handler
4795 Prag_Id = Pragma_Attach_Handler
4797 Record_Rep_Item (Proc_Scope, N);
4800 end Process_Interrupt_Or_Attach_Handler;
4802 --------------------------------------------------
4803 -- Process_Restrictions_Or_Restriction_Warnings --
4804 --------------------------------------------------
4806 -- Note: some of the simple identifier cases were handled in par-prag,
4807 -- but it is harmless (and more straightforward) to simply handle all
4808 -- cases here, even if it means we repeat a bit of work in some cases.
4810 procedure Process_Restrictions_Or_Restriction_Warnings
4814 R_Id : Restriction_Id;
4819 procedure Check_Unit_Name (N : Node_Id);
4820 -- Checks unit name parameter for No_Dependence. Returns if it has
4821 -- an appropriate form, otherwise raises pragma argument error.
4823 ---------------------
4824 -- Check_Unit_Name --
4825 ---------------------
4827 procedure Check_Unit_Name (N : Node_Id) is
4829 if Nkind (N) = N_Selected_Component then
4830 Check_Unit_Name (Prefix (N));
4831 Check_Unit_Name (Selector_Name (N));
4833 elsif Nkind (N) = N_Identifier then
4838 ("wrong form for unit name for No_Dependence", N);
4840 end Check_Unit_Name;
4842 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4845 -- Ignore all Restrictions pragma in CodePeer mode
4847 if CodePeer_Mode then
4851 Check_Ada_83_Warning;
4852 Check_At_Least_N_Arguments (1);
4853 Check_Valid_Configuration_Pragma;
4856 while Present (Arg) loop
4858 Expr := Get_Pragma_Arg (Arg);
4860 -- Case of no restriction identifier present
4862 if Id = No_Name then
4863 if Nkind (Expr) /= N_Identifier then
4865 ("invalid form for restriction", Arg);
4870 (Process_Restriction_Synonyms (Expr));
4872 if R_Id not in All_Boolean_Restrictions then
4873 Error_Msg_Name_1 := Pname;
4875 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4877 -- Check for possible misspelling
4879 for J in Restriction_Id loop
4881 Rnm : constant String := Restriction_Id'Image (J);
4884 Name_Buffer (1 .. Rnm'Length) := Rnm;
4885 Name_Len := Rnm'Length;
4886 Set_Casing (All_Lower_Case);
4888 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4890 (Identifier_Casing (Current_Source_File));
4891 Error_Msg_String (1 .. Rnm'Length) :=
4892 Name_Buffer (1 .. Name_Len);
4893 Error_Msg_Strlen := Rnm'Length;
4894 Error_Msg_N -- CODEFIX
4895 ("\possible misspelling of ""~""",
4896 Get_Pragma_Arg (Arg));
4905 if Implementation_Restriction (R_Id) then
4906 Check_Restriction (No_Implementation_Restrictions, Arg);
4909 -- If this is a warning, then set the warning unless we already
4910 -- have a real restriction active (we never want a warning to
4911 -- override a real restriction).
4914 if not Restriction_Active (R_Id) then
4915 Set_Restriction (R_Id, N);
4916 Restriction_Warnings (R_Id) := True;
4919 -- If real restriction case, then set it and make sure that the
4920 -- restriction warning flag is off, since a real restriction
4921 -- always overrides a warning.
4924 Set_Restriction (R_Id, N);
4925 Restriction_Warnings (R_Id) := False;
4928 -- Check for obsolescent restrictions in Ada 2005 mode
4931 and then Ada_Version >= Ada_2005
4932 and then (R_Id = No_Asynchronous_Control
4934 R_Id = No_Unchecked_Deallocation
4936 R_Id = No_Unchecked_Conversion)
4938 Check_Restriction (No_Obsolescent_Features, N);
4941 -- A very special case that must be processed here: pragma
4942 -- Restrictions (No_Exceptions) turns off all run-time
4943 -- checking. This is a bit dubious in terms of the formal
4944 -- language definition, but it is what is intended by RM
4945 -- H.4(12). Restriction_Warnings never affects generated code
4946 -- so this is done only in the real restriction case.
4948 if R_Id = No_Exceptions and then not Warn then
4949 Scope_Suppress := (others => True);
4952 -- Case of No_Dependence => unit-name. Note that the parser
4953 -- already made the necessary entry in the No_Dependence table.
4955 elsif Id = Name_No_Dependence then
4956 Check_Unit_Name (Expr);
4958 -- All other cases of restriction identifier present
4961 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4962 Analyze_And_Resolve (Expr, Any_Integer);
4964 if R_Id not in All_Parameter_Restrictions then
4966 ("invalid restriction parameter identifier", Arg);
4968 elsif not Is_OK_Static_Expression (Expr) then
4969 Flag_Non_Static_Expr
4970 ("value must be static expression!", Expr);
4973 elsif not Is_Integer_Type (Etype (Expr))
4974 or else Expr_Value (Expr) < 0
4977 ("value must be non-negative integer", Arg);
4980 -- Restriction pragma is active
4982 Val := Expr_Value (Expr);
4984 if not UI_Is_In_Int_Range (Val) then
4986 ("pragma ignored, value too large?", Arg);
4989 -- Warning case. If the real restriction is active, then we
4990 -- ignore the request, since warning never overrides a real
4991 -- restriction. Otherwise we set the proper warning. Note that
4992 -- this circuit sets the warning again if it is already set,
4993 -- which is what we want, since the constant may have changed.
4996 if not Restriction_Active (R_Id) then
4998 (R_Id, N, Integer (UI_To_Int (Val)));
4999 Restriction_Warnings (R_Id) := True;
5002 -- Real restriction case, set restriction and make sure warning
5003 -- flag is off since real restriction always overrides warning.
5006 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5007 Restriction_Warnings (R_Id) := False;
5013 end Process_Restrictions_Or_Restriction_Warnings;
5015 ---------------------------------
5016 -- Process_Suppress_Unsuppress --
5017 ---------------------------------
5019 -- Note: this procedure makes entries in the check suppress data
5020 -- structures managed by Sem. See spec of package Sem for full
5021 -- details on how we handle recording of check suppression.
5023 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5028 In_Package_Spec : constant Boolean :=
5029 Is_Package_Or_Generic_Package (Current_Scope)
5030 and then not In_Package_Body (Current_Scope);
5032 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5033 -- Used to suppress a single check on the given entity
5035 --------------------------------
5036 -- Suppress_Unsuppress_Echeck --
5037 --------------------------------
5039 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5041 Set_Checks_May_Be_Suppressed (E);
5043 if In_Package_Spec then
5044 Push_Global_Suppress_Stack_Entry
5047 Suppress => Suppress_Case);
5050 Push_Local_Suppress_Stack_Entry
5053 Suppress => Suppress_Case);
5056 -- If this is a first subtype, and the base type is distinct,
5057 -- then also set the suppress flags on the base type.
5059 if Is_First_Subtype (E)
5060 and then Etype (E) /= E
5062 Suppress_Unsuppress_Echeck (Etype (E), C);
5064 end Suppress_Unsuppress_Echeck;
5066 -- Start of processing for Process_Suppress_Unsuppress
5069 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
5070 -- we want to generate checks for analysis purposes, as set by -gnatC
5072 if CodePeer_Mode and then Comes_From_Source (N) then
5076 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5077 -- declarative part or a package spec (RM 11.5(5)).
5079 if not Is_Configuration_Pragma then
5080 Check_Is_In_Decl_Part_Or_Package_Spec;
5083 Check_At_Least_N_Arguments (1);
5084 Check_At_Most_N_Arguments (2);
5085 Check_No_Identifier (Arg1);
5086 Check_Arg_Is_Identifier (Arg1);
5088 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5090 if C = No_Check_Id then
5092 ("argument of pragma% is not valid check name", Arg1);
5095 if not Suppress_Case
5096 and then (C = All_Checks or else C = Overflow_Check)
5098 Opt.Overflow_Checks_Unsuppressed := True;
5101 if Arg_Count = 1 then
5103 -- Make an entry in the local scope suppress table. This is the
5104 -- table that directly shows the current value of the scope
5105 -- suppress check for any check id value.
5107 if C = All_Checks then
5109 -- For All_Checks, we set all specific predefined checks with
5110 -- the exception of Elaboration_Check, which is handled
5111 -- specially because of not wanting All_Checks to have the
5112 -- effect of deactivating static elaboration order processing.
5114 for J in Scope_Suppress'Range loop
5115 if J /= Elaboration_Check then
5116 Scope_Suppress (J) := Suppress_Case;
5120 -- If not All_Checks, and predefined check, then set appropriate
5121 -- scope entry. Note that we will set Elaboration_Check if this
5122 -- is explicitly specified.
5124 elsif C in Predefined_Check_Id then
5125 Scope_Suppress (C) := Suppress_Case;
5128 -- Also make an entry in the Local_Entity_Suppress table
5130 Push_Local_Suppress_Stack_Entry
5133 Suppress => Suppress_Case);
5135 -- Case of two arguments present, where the check is suppressed for
5136 -- a specified entity (given as the second argument of the pragma)
5139 -- This is obsolescent in Ada 2005 mode
5141 if Ada_Version >= Ada_2005 then
5142 Check_Restriction (No_Obsolescent_Features, Arg2);
5145 Check_Optional_Identifier (Arg2, Name_On);
5146 E_Id := Get_Pragma_Arg (Arg2);
5149 if not Is_Entity_Name (E_Id) then
5151 ("second argument of pragma% must be entity name", Arg2);
5160 -- Enforce RM 11.5(7) which requires that for a pragma that
5161 -- appears within a package spec, the named entity must be
5162 -- within the package spec. We allow the package name itself
5163 -- to be mentioned since that makes sense, although it is not
5164 -- strictly allowed by 11.5(7).
5167 and then E /= Current_Scope
5168 and then Scope (E) /= Current_Scope
5171 ("entity in pragma% is not in package spec (RM 11.5(7))",
5175 -- Loop through homonyms. As noted below, in the case of a package
5176 -- spec, only homonyms within the package spec are considered.
5179 Suppress_Unsuppress_Echeck (E, C);
5181 if Is_Generic_Instance (E)
5182 and then Is_Subprogram (E)
5183 and then Present (Alias (E))
5185 Suppress_Unsuppress_Echeck (Alias (E), C);
5188 -- Move to next homonym if not aspect spec case
5190 exit when From_Aspect_Specification (N);
5194 -- If we are within a package specification, the pragma only
5195 -- applies to homonyms in the same scope.
5197 exit when In_Package_Spec
5198 and then Scope (E) /= Current_Scope;
5201 end Process_Suppress_Unsuppress;
5207 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5209 if Is_Imported (E) then
5211 ("cannot export entity& that was previously imported", Arg);
5213 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5215 ("cannot export entity& that has an address clause", Arg);
5218 Set_Is_Exported (E);
5220 -- Generate a reference for entity explicitly, because the
5221 -- identifier may be overloaded and name resolution will not
5224 Generate_Reference (E, Arg);
5226 -- Deal with exporting non-library level entity
5228 if not Is_Library_Level_Entity (E) then
5230 -- Not allowed at all for subprograms
5232 if Is_Subprogram (E) then
5233 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5235 -- Otherwise set public and statically allocated
5239 Set_Is_Statically_Allocated (E);
5241 -- Warn if the corresponding W flag is set and the pragma comes
5242 -- from source. The latter may not be true e.g. on VMS where we
5243 -- expand export pragmas for exception codes associated with
5244 -- imported or exported exceptions. We do not want to generate
5245 -- a warning for something that the user did not write.
5247 if Warn_On_Export_Import
5248 and then Comes_From_Source (Arg)
5251 ("?& has been made static as a result of Export", Arg, E);
5253 ("\this usage is non-standard and non-portable", Arg);
5258 if Warn_On_Export_Import and then Is_Type (E) then
5259 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5262 if Warn_On_Export_Import and Inside_A_Generic then
5264 ("all instances of& will have the same external name?", Arg, E);
5268 ----------------------------------------------
5269 -- Set_Extended_Import_Export_External_Name --
5270 ----------------------------------------------
5272 procedure Set_Extended_Import_Export_External_Name
5273 (Internal_Ent : Entity_Id;
5274 Arg_External : Node_Id)
5276 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5280 if No (Arg_External) then
5284 Check_Arg_Is_External_Name (Arg_External);
5286 if Nkind (Arg_External) = N_String_Literal then
5287 if String_Length (Strval (Arg_External)) = 0 then
5290 New_Name := Adjust_External_Name_Case (Arg_External);
5293 elsif Nkind (Arg_External) = N_Identifier then
5294 New_Name := Get_Default_External_Name (Arg_External);
5296 -- Check_Arg_Is_External_Name should let through only identifiers and
5297 -- string literals or static string expressions (which are folded to
5298 -- string literals).
5301 raise Program_Error;
5304 -- If we already have an external name set (by a prior normal Import
5305 -- or Export pragma), then the external names must match
5307 if Present (Interface_Name (Internal_Ent)) then
5308 Check_Matching_Internal_Names : declare
5309 S1 : constant String_Id := Strval (Old_Name);
5310 S2 : constant String_Id := Strval (New_Name);
5313 -- Called if names do not match
5319 procedure Mismatch is
5321 Error_Msg_Sloc := Sloc (Old_Name);
5323 ("external name does not match that given #",
5327 -- Start of processing for Check_Matching_Internal_Names
5330 if String_Length (S1) /= String_Length (S2) then
5334 for J in 1 .. String_Length (S1) loop
5335 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5340 end Check_Matching_Internal_Names;
5342 -- Otherwise set the given name
5345 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5346 Check_Duplicated_Export_Name (New_Name);
5348 end Set_Extended_Import_Export_External_Name;
5354 procedure Set_Imported (E : Entity_Id) is
5356 -- Error message if already imported or exported
5358 if Is_Exported (E) or else Is_Imported (E) then
5360 -- Error if being set Exported twice
5362 if Is_Exported (E) then
5363 Error_Msg_NE ("entity& was previously exported", N, E);
5365 -- OK if Import/Interface case
5367 elsif Import_Interface_Present (N) then
5370 -- Error if being set Imported twice
5373 Error_Msg_NE ("entity& was previously imported", N, E);
5376 Error_Msg_Name_1 := Pname;
5378 ("\(pragma% applies to all previous entities)", N);
5380 Error_Msg_Sloc := Sloc (E);
5381 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5383 -- Here if not previously imported or exported, OK to import
5386 Set_Is_Imported (E);
5388 -- If the entity is an object that is not at the library level,
5389 -- then it is statically allocated. We do not worry about objects
5390 -- with address clauses in this context since they are not really
5391 -- imported in the linker sense.
5394 and then not Is_Library_Level_Entity (E)
5395 and then No (Address_Clause (E))
5397 Set_Is_Statically_Allocated (E);
5404 -------------------------
5405 -- Set_Mechanism_Value --
5406 -------------------------
5408 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5409 -- analyzed, since it is semantic nonsense), so we get it in the exact
5410 -- form created by the parser.
5412 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5415 Mech_Name_Id : Name_Id;
5417 procedure Bad_Class;
5418 -- Signal bad descriptor class name
5420 procedure Bad_Mechanism;
5421 -- Signal bad mechanism name
5427 procedure Bad_Class is
5429 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5432 -------------------------
5433 -- Bad_Mechanism_Value --
5434 -------------------------
5436 procedure Bad_Mechanism is
5438 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5441 -- Start of processing for Set_Mechanism_Value
5444 if Mechanism (Ent) /= Default_Mechanism then
5446 ("mechanism for & has already been set", Mech_Name, Ent);
5449 -- MECHANISM_NAME ::= value | reference | descriptor |
5452 if Nkind (Mech_Name) = N_Identifier then
5453 if Chars (Mech_Name) = Name_Value then
5454 Set_Mechanism (Ent, By_Copy);
5457 elsif Chars (Mech_Name) = Name_Reference then
5458 Set_Mechanism (Ent, By_Reference);
5461 elsif Chars (Mech_Name) = Name_Descriptor then
5462 Check_VMS (Mech_Name);
5464 -- Descriptor => Short_Descriptor if pragma was given
5466 if Short_Descriptors then
5467 Set_Mechanism (Ent, By_Short_Descriptor);
5469 Set_Mechanism (Ent, By_Descriptor);
5474 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5475 Check_VMS (Mech_Name);
5476 Set_Mechanism (Ent, By_Short_Descriptor);
5479 elsif Chars (Mech_Name) = Name_Copy then
5481 ("bad mechanism name, Value assumed", Mech_Name);
5487 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5488 -- short_descriptor (CLASS_NAME)
5489 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5491 -- Note: this form is parsed as an indexed component
5493 elsif Nkind (Mech_Name) = N_Indexed_Component then
5494 Class := First (Expressions (Mech_Name));
5496 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5497 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5498 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5499 or else Present (Next (Class))
5503 Mech_Name_Id := Chars (Prefix (Mech_Name));
5505 -- Change Descriptor => Short_Descriptor if pragma was given
5507 if Mech_Name_Id = Name_Descriptor
5508 and then Short_Descriptors
5510 Mech_Name_Id := Name_Short_Descriptor;
5514 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5515 -- short_descriptor (Class => CLASS_NAME)
5516 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5518 -- Note: this form is parsed as a function call
5520 elsif Nkind (Mech_Name) = N_Function_Call then
5521 Param := First (Parameter_Associations (Mech_Name));
5523 if Nkind (Name (Mech_Name)) /= N_Identifier
5524 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5525 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5526 or else Present (Next (Param))
5527 or else No (Selector_Name (Param))
5528 or else Chars (Selector_Name (Param)) /= Name_Class
5532 Class := Explicit_Actual_Parameter (Param);
5533 Mech_Name_Id := Chars (Name (Mech_Name));
5540 -- Fall through here with Class set to descriptor class name
5542 Check_VMS (Mech_Name);
5544 if Nkind (Class) /= N_Identifier then
5547 elsif Mech_Name_Id = Name_Descriptor
5548 and then Chars (Class) = Name_UBS
5550 Set_Mechanism (Ent, By_Descriptor_UBS);
5552 elsif Mech_Name_Id = Name_Descriptor
5553 and then Chars (Class) = Name_UBSB
5555 Set_Mechanism (Ent, By_Descriptor_UBSB);
5557 elsif Mech_Name_Id = Name_Descriptor
5558 and then Chars (Class) = Name_UBA
5560 Set_Mechanism (Ent, By_Descriptor_UBA);
5562 elsif Mech_Name_Id = Name_Descriptor
5563 and then Chars (Class) = Name_S
5565 Set_Mechanism (Ent, By_Descriptor_S);
5567 elsif Mech_Name_Id = Name_Descriptor
5568 and then Chars (Class) = Name_SB
5570 Set_Mechanism (Ent, By_Descriptor_SB);
5572 elsif Mech_Name_Id = Name_Descriptor
5573 and then Chars (Class) = Name_A
5575 Set_Mechanism (Ent, By_Descriptor_A);
5577 elsif Mech_Name_Id = Name_Descriptor
5578 and then Chars (Class) = Name_NCA
5580 Set_Mechanism (Ent, By_Descriptor_NCA);
5582 elsif Mech_Name_Id = Name_Short_Descriptor
5583 and then Chars (Class) = Name_UBS
5585 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5587 elsif Mech_Name_Id = Name_Short_Descriptor
5588 and then Chars (Class) = Name_UBSB
5590 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5592 elsif Mech_Name_Id = Name_Short_Descriptor
5593 and then Chars (Class) = Name_UBA
5595 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5597 elsif Mech_Name_Id = Name_Short_Descriptor
5598 and then Chars (Class) = Name_S
5600 Set_Mechanism (Ent, By_Short_Descriptor_S);
5602 elsif Mech_Name_Id = Name_Short_Descriptor
5603 and then Chars (Class) = Name_SB
5605 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5607 elsif Mech_Name_Id = Name_Short_Descriptor
5608 and then Chars (Class) = Name_A
5610 Set_Mechanism (Ent, By_Short_Descriptor_A);
5612 elsif Mech_Name_Id = Name_Short_Descriptor
5613 and then Chars (Class) = Name_NCA
5615 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5620 end Set_Mechanism_Value;
5622 ---------------------------
5623 -- Set_Ravenscar_Profile --
5624 ---------------------------
5626 -- The tasks to be done here are
5628 -- Set required policies
5630 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5631 -- pragma Locking_Policy (Ceiling_Locking)
5633 -- Set Detect_Blocking mode
5635 -- Set required restrictions (see System.Rident for detailed list)
5637 -- Set the No_Dependence rules
5638 -- No_Dependence => Ada.Asynchronous_Task_Control
5639 -- No_Dependence => Ada.Calendar
5640 -- No_Dependence => Ada.Execution_Time.Group_Budget
5641 -- No_Dependence => Ada.Execution_Time.Timers
5642 -- No_Dependence => Ada.Task_Attributes
5643 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5645 procedure Set_Ravenscar_Profile (N : Node_Id) is
5646 Prefix_Entity : Entity_Id;
5647 Selector_Entity : Entity_Id;
5648 Prefix_Node : Node_Id;
5652 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5654 if Task_Dispatching_Policy /= ' '
5655 and then Task_Dispatching_Policy /= 'F'
5657 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5658 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5660 -- Set the FIFO_Within_Priorities policy, but always preserve
5661 -- System_Location since we like the error message with the run time
5665 Task_Dispatching_Policy := 'F';
5667 if Task_Dispatching_Policy_Sloc /= System_Location then
5668 Task_Dispatching_Policy_Sloc := Loc;
5672 -- pragma Locking_Policy (Ceiling_Locking)
5674 if Locking_Policy /= ' '
5675 and then Locking_Policy /= 'C'
5677 Error_Msg_Sloc := Locking_Policy_Sloc;
5678 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5680 -- Set the Ceiling_Locking policy, but preserve System_Location since
5681 -- we like the error message with the run time name.
5684 Locking_Policy := 'C';
5686 if Locking_Policy_Sloc /= System_Location then
5687 Locking_Policy_Sloc := Loc;
5691 -- pragma Detect_Blocking
5693 Detect_Blocking := True;
5695 -- Set the corresponding restrictions
5697 Set_Profile_Restrictions
5698 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5700 -- Set the No_Dependence restrictions
5702 -- The following No_Dependence restrictions:
5703 -- No_Dependence => Ada.Asynchronous_Task_Control
5704 -- No_Dependence => Ada.Calendar
5705 -- No_Dependence => Ada.Task_Attributes
5706 -- are already set by previous call to Set_Profile_Restrictions.
5708 -- Set the following restrictions which were added to Ada 2005:
5709 -- No_Dependence => Ada.Execution_Time.Group_Budget
5710 -- No_Dependence => Ada.Execution_Time.Timers
5712 if Ada_Version >= Ada_2005 then
5713 Name_Buffer (1 .. 3) := "ada";
5716 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5718 Name_Buffer (1 .. 14) := "execution_time";
5721 Selector_Entity := Make_Identifier (Loc, Name_Find);
5724 Make_Selected_Component
5726 Prefix => Prefix_Entity,
5727 Selector_Name => Selector_Entity);
5729 Name_Buffer (1 .. 13) := "group_budgets";
5732 Selector_Entity := Make_Identifier (Loc, Name_Find);
5735 Make_Selected_Component
5737 Prefix => Prefix_Node,
5738 Selector_Name => Selector_Entity);
5740 Set_Restriction_No_Dependence
5742 Warn => Treat_Restrictions_As_Warnings,
5743 Profile => Ravenscar);
5745 Name_Buffer (1 .. 6) := "timers";
5748 Selector_Entity := Make_Identifier (Loc, Name_Find);
5751 Make_Selected_Component
5753 Prefix => Prefix_Node,
5754 Selector_Name => Selector_Entity);
5756 Set_Restriction_No_Dependence
5758 Warn => Treat_Restrictions_As_Warnings,
5759 Profile => Ravenscar);
5762 -- Set the following restrictions which was added to Ada 2012 (see
5764 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5766 if Ada_Version >= Ada_2012 then
5767 Name_Buffer (1 .. 6) := "system";
5770 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5772 Name_Buffer (1 .. 15) := "multiprocessors";
5775 Selector_Entity := Make_Identifier (Loc, Name_Find);
5778 Make_Selected_Component
5780 Prefix => Prefix_Entity,
5781 Selector_Name => Selector_Entity);
5783 Name_Buffer (1 .. 19) := "dispatching_domains";
5786 Selector_Entity := Make_Identifier (Loc, Name_Find);
5789 Make_Selected_Component
5791 Prefix => Prefix_Node,
5792 Selector_Name => Selector_Entity);
5794 Set_Restriction_No_Dependence
5796 Warn => Treat_Restrictions_As_Warnings,
5797 Profile => Ravenscar);
5799 end Set_Ravenscar_Profile;
5801 -- Start of processing for Analyze_Pragma
5804 -- The following code is a defense against recursion. Not clear that
5805 -- this can happen legitimately, but perhaps some error situations
5806 -- can cause it, and we did see this recursion during testing.
5808 if Analyzed (N) then
5811 Set_Analyzed (N, True);
5814 -- Deal with unrecognized pragma
5816 if not Is_Pragma_Name (Pname) then
5817 if Warn_On_Unrecognized_Pragma then
5818 Error_Msg_Name_1 := Pname;
5819 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5821 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5822 if Is_Bad_Spelling_Of (Pname, PN) then
5823 Error_Msg_Name_1 := PN;
5824 Error_Msg_N -- CODEFIX
5825 ("\?possible misspelling of %!", Pragma_Identifier (N));
5834 -- Here to start processing for recognized pragma
5836 Prag_Id := Get_Pragma_Id (Pname);
5846 if Present (Pragma_Argument_Associations (N)) then
5847 Arg_Count := List_Length (Pragma_Argument_Associations (N));
5848 Arg1 := First (Pragma_Argument_Associations (N));
5850 if Present (Arg1) then
5851 Arg2 := Next (Arg1);
5853 if Present (Arg2) then
5854 Arg3 := Next (Arg2);
5856 if Present (Arg3) then
5857 Arg4 := Next (Arg3);
5863 -- An enumeration type defines the pragmas that are supported by the
5864 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5865 -- into the corresponding enumeration value for the following case.
5873 -- pragma Abort_Defer;
5875 when Pragma_Abort_Defer =>
5877 Check_Arg_Count (0);
5879 -- The only required semantic processing is to check the
5880 -- placement. This pragma must appear at the start of the
5881 -- statement sequence of a handled sequence of statements.
5883 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5884 or else N /= First (Statements (Parent (N)))
5895 -- Note: this pragma also has some specific processing in Par.Prag
5896 -- because we want to set the Ada version mode during parsing.
5898 when Pragma_Ada_83 =>
5900 Check_Arg_Count (0);
5902 -- We really should check unconditionally for proper configuration
5903 -- pragma placement, since we really don't want mixed Ada modes
5904 -- within a single unit, and the GNAT reference manual has always
5905 -- said this was a configuration pragma, but we did not check and
5906 -- are hesitant to add the check now.
5908 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5909 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5910 -- or Ada 2012 mode.
5912 if Ada_Version >= Ada_2005 then
5913 Check_Valid_Configuration_Pragma;
5916 -- Now set Ada 83 mode
5918 Ada_Version := Ada_83;
5919 Ada_Version_Explicit := Ada_Version;
5927 -- Note: this pragma also has some specific processing in Par.Prag
5928 -- because we want to set the Ada 83 version mode during parsing.
5930 when Pragma_Ada_95 =>
5932 Check_Arg_Count (0);
5934 -- We really should check unconditionally for proper configuration
5935 -- pragma placement, since we really don't want mixed Ada modes
5936 -- within a single unit, and the GNAT reference manual has always
5937 -- said this was a configuration pragma, but we did not check and
5938 -- are hesitant to add the check now.
5940 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5941 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5943 if Ada_Version >= Ada_2005 then
5944 Check_Valid_Configuration_Pragma;
5947 -- Now set Ada 95 mode
5949 Ada_Version := Ada_95;
5950 Ada_Version_Explicit := Ada_Version;
5952 ---------------------
5953 -- Ada_05/Ada_2005 --
5954 ---------------------
5957 -- pragma Ada_05 (LOCAL_NAME);
5960 -- pragma Ada_2005 (LOCAL_NAME):
5962 -- Note: these pragmas also have some specific processing in Par.Prag
5963 -- because we want to set the Ada 2005 version mode during parsing.
5965 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5971 if Arg_Count = 1 then
5972 Check_Arg_Is_Local_Name (Arg1);
5973 E_Id := Get_Pragma_Arg (Arg1);
5975 if Etype (E_Id) = Any_Type then
5979 Set_Is_Ada_2005_Only (Entity (E_Id));
5982 Check_Arg_Count (0);
5984 -- For Ada_2005 we unconditionally enforce the documented
5985 -- configuration pragma placement, since we do not want to
5986 -- tolerate mixed modes in a unit involving Ada 2005. That
5987 -- would cause real difficulties for those cases where there
5988 -- are incompatibilities between Ada 95 and Ada 2005.
5990 Check_Valid_Configuration_Pragma;
5992 -- Now set appropriate Ada mode
5994 Ada_Version := Ada_2005;
5995 Ada_Version_Explicit := Ada_2005;
5999 ---------------------
6000 -- Ada_12/Ada_2012 --
6001 ---------------------
6004 -- pragma Ada_12 (LOCAL_NAME);
6007 -- pragma Ada_2012 (LOCAL_NAME):
6009 -- Note: these pragmas also have some specific processing in Par.Prag
6010 -- because we want to set the Ada 2012 version mode during parsing.
6012 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6018 if Arg_Count = 1 then
6019 Check_Arg_Is_Local_Name (Arg1);
6020 E_Id := Get_Pragma_Arg (Arg1);
6022 if Etype (E_Id) = Any_Type then
6026 Set_Is_Ada_2012_Only (Entity (E_Id));
6029 Check_Arg_Count (0);
6031 -- For Ada_2012 we unconditionally enforce the documented
6032 -- configuration pragma placement, since we do not want to
6033 -- tolerate mixed modes in a unit involving Ada 2012. That
6034 -- would cause real difficulties for those cases where there
6035 -- are incompatibilities between Ada 95 and Ada 2012. We could
6036 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6038 Check_Valid_Configuration_Pragma;
6040 -- Now set appropriate Ada mode
6042 Ada_Version := Ada_2012;
6043 Ada_Version_Explicit := Ada_2012;
6047 ----------------------
6048 -- All_Calls_Remote --
6049 ----------------------
6051 -- pragma All_Calls_Remote [(library_package_NAME)];
6053 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6054 Lib_Entity : Entity_Id;
6057 Check_Ada_83_Warning;
6058 Check_Valid_Library_Unit_Pragma;
6060 if Nkind (N) = N_Null_Statement then
6064 Lib_Entity := Find_Lib_Unit_Name;
6066 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6068 if Present (Lib_Entity)
6069 and then not Debug_Flag_U
6071 if not Is_Remote_Call_Interface (Lib_Entity) then
6072 Error_Pragma ("pragma% only apply to rci unit");
6074 -- Set flag for entity of the library unit
6077 Set_Has_All_Calls_Remote (Lib_Entity);
6081 end All_Calls_Remote;
6087 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6088 -- ARG ::= NAME | EXPRESSION
6090 -- The first two arguments are by convention intended to refer to an
6091 -- external tool and a tool-specific function. These arguments are
6094 when Pragma_Annotate => Annotate : begin
6096 Check_At_Least_N_Arguments (1);
6097 Check_Arg_Is_Identifier (Arg1);
6098 Check_No_Identifiers;
6106 -- Second unanalyzed parameter is optional
6112 while Present (Arg) loop
6113 Exp := Get_Pragma_Arg (Arg);
6116 if Is_Entity_Name (Exp) then
6119 -- For string literals, we assume Standard_String as the
6120 -- type, unless the string contains wide or wide_wide
6123 elsif Nkind (Exp) = N_String_Literal then
6124 if Has_Wide_Wide_Character (Exp) then
6125 Resolve (Exp, Standard_Wide_Wide_String);
6126 elsif Has_Wide_Character (Exp) then
6127 Resolve (Exp, Standard_Wide_String);
6129 Resolve (Exp, Standard_String);
6132 elsif Is_Overloaded (Exp) then
6134 ("ambiguous argument for pragma%", Exp);
6150 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6151 -- [, [Message =>] Static_String_EXPRESSION]);
6153 when Pragma_Assert => Assert : declare
6159 Check_At_Least_N_Arguments (1);
6160 Check_At_Most_N_Arguments (2);
6161 Check_Arg_Order ((Name_Check, Name_Message));
6162 Check_Optional_Identifier (Arg1, Name_Check);
6164 -- We treat pragma Assert as equivalent to:
6166 -- pragma Check (Assertion, condition [, msg]);
6168 -- So rewrite pragma in this manner, and analyze the result
6170 Expr := Get_Pragma_Arg (Arg1);
6172 Make_Pragma_Argument_Association (Loc,
6173 Expression => Make_Identifier (Loc, Name_Assertion)),
6175 Make_Pragma_Argument_Association (Sloc (Expr),
6176 Expression => Expr));
6178 if Arg_Count > 1 then
6179 Check_Optional_Identifier (Arg2, Name_Message);
6180 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6181 Append_To (Newa, Relocate_Node (Arg2));
6186 Chars => Name_Check,
6187 Pragma_Argument_Associations => Newa));
6191 ----------------------
6192 -- Assertion_Policy --
6193 ----------------------
6195 -- pragma Assertion_Policy (Check | Ignore)
6197 when Pragma_Assertion_Policy => Assertion_Policy : declare
6202 Check_Valid_Configuration_Pragma;
6203 Check_Arg_Count (1);
6204 Check_No_Identifiers;
6205 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6207 -- We treat pragma Assertion_Policy as equivalent to:
6209 -- pragma Check_Policy (Assertion, policy)
6211 -- So rewrite the pragma in that manner and link on to the chain
6212 -- of Check_Policy pragmas, marking the pragma as analyzed.
6214 Policy := Get_Pragma_Arg (Arg1);
6218 Chars => Name_Check_Policy,
6220 Pragma_Argument_Associations => New_List (
6221 Make_Pragma_Argument_Association (Loc,
6222 Expression => Make_Identifier (Loc, Name_Assertion)),
6224 Make_Pragma_Argument_Association (Loc,
6226 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6229 Set_Next_Pragma (N, Opt.Check_Policy_List);
6230 Opt.Check_Policy_List := N;
6231 end Assertion_Policy;
6233 ------------------------------
6234 -- Assume_No_Invalid_Values --
6235 ------------------------------
6237 -- pragma Assume_No_Invalid_Values (On | Off);
6239 when Pragma_Assume_No_Invalid_Values =>
6241 Check_Valid_Configuration_Pragma;
6242 Check_Arg_Count (1);
6243 Check_No_Identifiers;
6244 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6246 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6247 Assume_No_Invalid_Values := True;
6249 Assume_No_Invalid_Values := False;
6256 -- pragma AST_Entry (entry_IDENTIFIER);
6258 when Pragma_AST_Entry => AST_Entry : declare
6264 Check_Arg_Count (1);
6265 Check_No_Identifiers;
6266 Check_Arg_Is_Local_Name (Arg1);
6267 Ent := Entity (Get_Pragma_Arg (Arg1));
6269 -- Note: the implementation of the AST_Entry pragma could handle
6270 -- the entry family case fine, but for now we are consistent with
6271 -- the DEC rules, and do not allow the pragma, which of course
6272 -- has the effect of also forbidding the attribute.
6274 if Ekind (Ent) /= E_Entry then
6276 ("pragma% argument must be simple entry name", Arg1);
6278 elsif Is_AST_Entry (Ent) then
6280 ("duplicate % pragma for entry", Arg1);
6282 elsif Has_Homonym (Ent) then
6284 ("pragma% argument cannot specify overloaded entry", Arg1);
6288 FF : constant Entity_Id := First_Formal (Ent);
6291 if Present (FF) then
6292 if Present (Next_Formal (FF)) then
6294 ("entry for pragma% can have only one argument",
6297 elsif Parameter_Mode (FF) /= E_In_Parameter then
6299 ("entry parameter for pragma% must have mode IN",
6305 Set_Is_AST_Entry (Ent);
6313 -- pragma Asynchronous (LOCAL_NAME);
6315 when Pragma_Asynchronous => Asynchronous : declare
6323 procedure Process_Async_Pragma;
6324 -- Common processing for procedure and access-to-procedure case
6326 --------------------------
6327 -- Process_Async_Pragma --
6328 --------------------------
6330 procedure Process_Async_Pragma is
6333 Set_Is_Asynchronous (Nm);
6337 -- The formals should be of mode IN (RM E.4.1(6))
6340 while Present (S) loop
6341 Formal := Defining_Identifier (S);
6343 if Nkind (Formal) = N_Defining_Identifier
6344 and then Ekind (Formal) /= E_In_Parameter
6347 ("pragma% procedure can only have IN parameter",
6354 Set_Is_Asynchronous (Nm);
6355 end Process_Async_Pragma;
6357 -- Start of processing for pragma Asynchronous
6360 Check_Ada_83_Warning;
6361 Check_No_Identifiers;
6362 Check_Arg_Count (1);
6363 Check_Arg_Is_Local_Name (Arg1);
6365 if Debug_Flag_U then
6369 C_Ent := Cunit_Entity (Current_Sem_Unit);
6370 Analyze (Get_Pragma_Arg (Arg1));
6371 Nm := Entity (Get_Pragma_Arg (Arg1));
6373 if not Is_Remote_Call_Interface (C_Ent)
6374 and then not Is_Remote_Types (C_Ent)
6376 -- This pragma should only appear in an RCI or Remote Types
6377 -- unit (RM E.4.1(4)).
6380 ("pragma% not in Remote_Call_Interface or " &
6381 "Remote_Types unit");
6384 if Ekind (Nm) = E_Procedure
6385 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6387 if not Is_Remote_Call_Interface (Nm) then
6389 ("pragma% cannot be applied on non-remote procedure",
6393 L := Parameter_Specifications (Parent (Nm));
6394 Process_Async_Pragma;
6397 elsif Ekind (Nm) = E_Function then
6399 ("pragma% cannot be applied to function", Arg1);
6401 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6402 if Is_Record_Type (Nm) then
6404 -- A record type that is the Equivalent_Type for a remote
6405 -- access-to-subprogram type.
6407 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6410 -- A non-expanded RAS type (distribution is not enabled)
6412 N := Declaration_Node (Nm);
6415 if Nkind (N) = N_Full_Type_Declaration
6416 and then Nkind (Type_Definition (N)) =
6417 N_Access_Procedure_Definition
6419 L := Parameter_Specifications (Type_Definition (N));
6420 Process_Async_Pragma;
6422 if Is_Asynchronous (Nm)
6423 and then Expander_Active
6424 and then Get_PCS_Name /= Name_No_DSA
6426 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6431 ("pragma% cannot reference access-to-function type",
6435 -- Only other possibility is Access-to-class-wide type
6437 elsif Is_Access_Type (Nm)
6438 and then Is_Class_Wide_Type (Designated_Type (Nm))
6440 Check_First_Subtype (Arg1);
6441 Set_Is_Asynchronous (Nm);
6442 if Expander_Active then
6443 RACW_Type_Is_Asynchronous (Nm);
6447 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6455 -- pragma Atomic (LOCAL_NAME);
6457 when Pragma_Atomic =>
6458 Process_Atomic_Shared_Volatile;
6460 -----------------------
6461 -- Atomic_Components --
6462 -----------------------
6464 -- pragma Atomic_Components (array_LOCAL_NAME);
6466 -- This processing is shared by Volatile_Components
6468 when Pragma_Atomic_Components |
6469 Pragma_Volatile_Components =>
6471 Atomic_Components : declare
6478 Check_Ada_83_Warning;
6479 Check_No_Identifiers;
6480 Check_Arg_Count (1);
6481 Check_Arg_Is_Local_Name (Arg1);
6482 E_Id := Get_Pragma_Arg (Arg1);
6484 if Etype (E_Id) = Any_Type then
6490 Check_Duplicate_Pragma (E);
6492 if Rep_Item_Too_Early (E, N)
6494 Rep_Item_Too_Late (E, N)
6499 D := Declaration_Node (E);
6502 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6504 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6505 and then Nkind (D) = N_Object_Declaration
6506 and then Nkind (Object_Definition (D)) =
6507 N_Constrained_Array_Definition)
6509 -- The flag is set on the object, or on the base type
6511 if Nkind (D) /= N_Object_Declaration then
6515 Set_Has_Volatile_Components (E);
6517 if Prag_Id = Pragma_Atomic_Components then
6518 Set_Has_Atomic_Components (E);
6522 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6524 end Atomic_Components;
6526 --------------------
6527 -- Attach_Handler --
6528 --------------------
6530 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6532 when Pragma_Attach_Handler =>
6533 Check_Ada_83_Warning;
6534 Check_No_Identifiers;
6535 Check_Arg_Count (2);
6537 if No_Run_Time_Mode then
6538 Error_Msg_CRT ("Attach_Handler pragma", N);
6540 Check_Interrupt_Or_Attach_Handler;
6542 -- The expression that designates the attribute may depend on a
6543 -- discriminant, and is therefore a per- object expression, to
6544 -- be expanded in the init proc. If expansion is enabled, then
6545 -- perform semantic checks on a copy only.
6547 if Expander_Active then
6549 Temp : constant Node_Id :=
6550 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6552 Set_Parent (Temp, N);
6553 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6557 Analyze (Get_Pragma_Arg (Arg2));
6558 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6561 Process_Interrupt_Or_Attach_Handler;
6564 --------------------
6565 -- C_Pass_By_Copy --
6566 --------------------
6568 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6570 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6576 Check_Valid_Configuration_Pragma;
6577 Check_Arg_Count (1);
6578 Check_Optional_Identifier (Arg1, "max_size");
6580 Arg := Get_Pragma_Arg (Arg1);
6581 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6583 Val := Expr_Value (Arg);
6587 ("maximum size for pragma% must be positive", Arg1);
6589 elsif UI_Is_In_Int_Range (Val) then
6590 Default_C_Record_Mechanism := UI_To_Int (Val);
6592 -- If a giant value is given, Int'Last will do well enough.
6593 -- If sometime someone complains that a record larger than
6594 -- two gigabytes is not copied, we will worry about it then!
6597 Default_C_Record_Mechanism := Mechanism_Type'Last;
6605 -- pragma Check ([Name =>] Identifier,
6606 -- [Check =>] Boolean_Expression
6607 -- [,[Message =>] String_Expression]);
6609 when Pragma_Check => Check : declare
6614 -- Set True if category of assertions referenced by Name enabled
6618 Check_At_Least_N_Arguments (2);
6619 Check_At_Most_N_Arguments (3);
6620 Check_Optional_Identifier (Arg1, Name_Name);
6621 Check_Optional_Identifier (Arg2, Name_Check);
6623 if Arg_Count = 3 then
6624 Check_Optional_Identifier (Arg3, Name_Message);
6625 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6628 Check_Arg_Is_Identifier (Arg1);
6630 -- Indicate if pragma is enabled. The Original_Node reference here
6631 -- is to deal with pragma Assert rewritten as a Check pragma.
6633 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6636 Set_Pragma_Enabled (N);
6637 Set_Pragma_Enabled (Original_Node (N));
6638 Set_SCO_Pragma_Enabled (Loc);
6641 -- If expansion is active and the check is not enabled then we
6642 -- rewrite the Check as:
6644 -- if False and then condition then
6648 -- The reason we do this rewriting during semantic analysis rather
6649 -- than as part of normal expansion is that we cannot analyze and
6650 -- expand the code for the boolean expression directly, or it may
6651 -- cause insertion of actions that would escape the attempt to
6652 -- suppress the check code.
6654 -- Note that the Sloc for the if statement corresponds to the
6655 -- argument condition, not the pragma itself. The reason for this
6656 -- is that we may generate a warning if the condition is False at
6657 -- compile time, and we do not want to delete this warning when we
6658 -- delete the if statement.
6660 Expr := Get_Pragma_Arg (Arg2);
6662 if Expander_Active and then not Check_On then
6663 Eloc := Sloc (Expr);
6666 Make_If_Statement (Eloc,
6668 Make_And_Then (Eloc,
6669 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6670 Right_Opnd => Expr),
6671 Then_Statements => New_List (
6672 Make_Null_Statement (Eloc))));
6679 Analyze_And_Resolve (Expr, Any_Boolean);
6687 -- pragma Check_Name (check_IDENTIFIER);
6689 when Pragma_Check_Name =>
6690 Check_No_Identifiers;
6692 Check_Valid_Configuration_Pragma;
6693 Check_Arg_Count (1);
6694 Check_Arg_Is_Identifier (Arg1);
6697 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6700 for J in Check_Names.First .. Check_Names.Last loop
6701 if Check_Names.Table (J) = Nam then
6706 Check_Names.Append (Nam);
6713 -- pragma Check_Policy (
6714 -- [Name =>] IDENTIFIER,
6715 -- [Policy =>] POLICY_IDENTIFIER);
6717 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6719 -- Note: this is a configuration pragma, but it is allowed to appear
6722 when Pragma_Check_Policy =>
6724 Check_Arg_Count (2);
6725 Check_Optional_Identifier (Arg1, Name_Name);
6726 Check_Optional_Identifier (Arg2, Name_Policy);
6728 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6730 -- A Check_Policy pragma can appear either as a configuration
6731 -- pragma, or in a declarative part or a package spec (see RM
6732 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6733 -- followed for Check_Policy).
6735 if not Is_Configuration_Pragma then
6736 Check_Is_In_Decl_Part_Or_Package_Spec;
6739 Set_Next_Pragma (N, Opt.Check_Policy_List);
6740 Opt.Check_Policy_List := N;
6742 ---------------------
6743 -- CIL_Constructor --
6744 ---------------------
6746 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6748 -- Processing for this pragma is shared with Java_Constructor
6754 -- pragma Comment (static_string_EXPRESSION)
6756 -- Processing for pragma Comment shares the circuitry for pragma
6757 -- Ident. The only differences are that Ident enforces a limit of 31
6758 -- characters on its argument, and also enforces limitations on
6759 -- placement for DEC compatibility. Pragma Comment shares neither of
6760 -- these restrictions.
6766 -- pragma Common_Object (
6767 -- [Internal =>] LOCAL_NAME
6768 -- [, [External =>] EXTERNAL_SYMBOL]
6769 -- [, [Size =>] EXTERNAL_SYMBOL]);
6771 -- Processing for this pragma is shared with Psect_Object
6773 ------------------------
6774 -- Compile_Time_Error --
6775 ------------------------
6777 -- pragma Compile_Time_Error
6778 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6780 when Pragma_Compile_Time_Error =>
6782 Process_Compile_Time_Warning_Or_Error;
6784 --------------------------
6785 -- Compile_Time_Warning --
6786 --------------------------
6788 -- pragma Compile_Time_Warning
6789 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6791 when Pragma_Compile_Time_Warning =>
6793 Process_Compile_Time_Warning_Or_Error;
6799 when Pragma_Compiler_Unit =>
6801 Check_Arg_Count (0);
6802 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6804 -----------------------------
6805 -- Complete_Representation --
6806 -----------------------------
6808 -- pragma Complete_Representation;
6810 when Pragma_Complete_Representation =>
6812 Check_Arg_Count (0);
6814 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6816 ("pragma & must appear within record representation clause");
6819 ----------------------------
6820 -- Complex_Representation --
6821 ----------------------------
6823 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6825 when Pragma_Complex_Representation => Complex_Representation : declare
6832 Check_Arg_Count (1);
6833 Check_Optional_Identifier (Arg1, Name_Entity);
6834 Check_Arg_Is_Local_Name (Arg1);
6835 E_Id := Get_Pragma_Arg (Arg1);
6837 if Etype (E_Id) = Any_Type then
6843 if not Is_Record_Type (E) then
6845 ("argument for pragma% must be record type", Arg1);
6848 Ent := First_Entity (E);
6851 or else No (Next_Entity (Ent))
6852 or else Present (Next_Entity (Next_Entity (Ent)))
6853 or else not Is_Floating_Point_Type (Etype (Ent))
6854 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6857 ("record for pragma% must have two fields of the same "
6858 & "floating-point type", Arg1);
6861 Set_Has_Complex_Representation (Base_Type (E));
6863 -- We need to treat the type has having a non-standard
6864 -- representation, for back-end purposes, even though in
6865 -- general a complex will have the default representation
6866 -- of a record with two real components.
6868 Set_Has_Non_Standard_Rep (Base_Type (E));
6870 end Complex_Representation;
6872 -------------------------
6873 -- Component_Alignment --
6874 -------------------------
6876 -- pragma Component_Alignment (
6877 -- [Form =>] ALIGNMENT_CHOICE
6878 -- [, [Name =>] type_LOCAL_NAME]);
6880 -- ALIGNMENT_CHOICE ::=
6882 -- | Component_Size_4
6886 when Pragma_Component_Alignment => Component_AlignmentP : declare
6887 Args : Args_List (1 .. 2);
6888 Names : constant Name_List (1 .. 2) := (
6892 Form : Node_Id renames Args (1);
6893 Name : Node_Id renames Args (2);
6895 Atype : Component_Alignment_Kind;
6900 Gather_Associations (Names, Args);
6903 Error_Pragma ("missing Form argument for pragma%");
6906 Check_Arg_Is_Identifier (Form);
6908 -- Get proper alignment, note that Default = Component_Size on all
6909 -- machines we have so far, and we want to set this value rather
6910 -- than the default value to indicate that it has been explicitly
6911 -- set (and thus will not get overridden by the default component
6912 -- alignment for the current scope)
6914 if Chars (Form) = Name_Component_Size then
6915 Atype := Calign_Component_Size;
6917 elsif Chars (Form) = Name_Component_Size_4 then
6918 Atype := Calign_Component_Size_4;
6920 elsif Chars (Form) = Name_Default then
6921 Atype := Calign_Component_Size;
6923 elsif Chars (Form) = Name_Storage_Unit then
6924 Atype := Calign_Storage_Unit;
6928 ("invalid Form parameter for pragma%", Form);
6931 -- Case with no name, supplied, affects scope table entry
6935 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6937 -- Case of name supplied
6940 Check_Arg_Is_Local_Name (Name);
6942 Typ := Entity (Name);
6945 or else Rep_Item_Too_Early (Typ, N)
6949 Typ := Underlying_Type (Typ);
6952 if not Is_Record_Type (Typ)
6953 and then not Is_Array_Type (Typ)
6956 ("Name parameter of pragma% must identify record or " &
6957 "array type", Name);
6960 -- An explicit Component_Alignment pragma overrides an
6961 -- implicit pragma Pack, but not an explicit one.
6963 if not Has_Pragma_Pack (Base_Type (Typ)) then
6964 Set_Is_Packed (Base_Type (Typ), False);
6965 Set_Component_Alignment (Base_Type (Typ), Atype);
6968 end Component_AlignmentP;
6974 -- pragma Controlled (first_subtype_LOCAL_NAME);
6976 when Pragma_Controlled => Controlled : declare
6980 Check_No_Identifiers;
6981 Check_Arg_Count (1);
6982 Check_Arg_Is_Local_Name (Arg1);
6983 Arg := Get_Pragma_Arg (Arg1);
6985 if not Is_Entity_Name (Arg)
6986 or else not Is_Access_Type (Entity (Arg))
6988 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6990 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6998 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6999 -- [Entity =>] LOCAL_NAME);
7001 when Pragma_Convention => Convention : declare
7004 pragma Warnings (Off, C);
7005 pragma Warnings (Off, E);
7007 Check_Arg_Order ((Name_Convention, Name_Entity));
7008 Check_Ada_83_Warning;
7009 Check_Arg_Count (2);
7010 Process_Convention (C, E);
7013 ---------------------------
7014 -- Convention_Identifier --
7015 ---------------------------
7017 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7018 -- [Convention =>] convention_IDENTIFIER);
7020 when Pragma_Convention_Identifier => Convention_Identifier : declare
7026 Check_Arg_Order ((Name_Name, Name_Convention));
7027 Check_Arg_Count (2);
7028 Check_Optional_Identifier (Arg1, Name_Name);
7029 Check_Optional_Identifier (Arg2, Name_Convention);
7030 Check_Arg_Is_Identifier (Arg1);
7031 Check_Arg_Is_Identifier (Arg2);
7032 Idnam := Chars (Get_Pragma_Arg (Arg1));
7033 Cname := Chars (Get_Pragma_Arg (Arg2));
7035 if Is_Convention_Name (Cname) then
7036 Record_Convention_Identifier
7037 (Idnam, Get_Convention_Id (Cname));
7040 ("second arg for % pragma must be convention", Arg2);
7042 end Convention_Identifier;
7048 -- pragma CPP_Class ([Entity =>] local_NAME)
7050 when Pragma_CPP_Class => CPP_Class : declare
7055 if Warn_On_Obsolescent_Feature then
7057 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7058 " by pragma import?", N);
7062 Check_Arg_Count (1);
7063 Check_Optional_Identifier (Arg1, Name_Entity);
7064 Check_Arg_Is_Local_Name (Arg1);
7066 Arg := Get_Pragma_Arg (Arg1);
7069 if Etype (Arg) = Any_Type then
7073 if not Is_Entity_Name (Arg)
7074 or else not Is_Type (Entity (Arg))
7076 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7079 Typ := Entity (Arg);
7081 if not Is_Tagged_Type (Typ) then
7082 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7085 -- Types treated as CPP classes must be declared limited (note:
7086 -- this used to be a warning but there is no real benefit to it
7087 -- since we did effectively intend to treat the type as limited
7090 if not Is_Limited_Type (Typ) then
7092 ("imported 'C'P'P type must be limited",
7093 Get_Pragma_Arg (Arg1));
7096 Set_Is_CPP_Class (Typ);
7097 Set_Convention (Typ, Convention_CPP);
7099 -- Imported CPP types must not have discriminants (because C++
7100 -- classes do not have discriminants).
7102 if Has_Discriminants (Typ) then
7104 ("imported 'C'P'P type cannot have discriminants",
7105 First (Discriminant_Specifications
7106 (Declaration_Node (Typ))));
7109 -- Components of imported CPP types must not have default
7110 -- expressions because the constructor (if any) is in the
7113 if Is_Incomplete_Or_Private_Type (Typ)
7114 and then No (Underlying_Type (Typ))
7116 -- It should be an error to apply pragma CPP to a private
7117 -- type if the underlying type is not visible (as it is
7118 -- for any representation item). For now, for backward
7119 -- compatibility we do nothing but we cannot check components
7120 -- because they are not available at this stage. All this code
7121 -- will be removed when we cleanup this obsolete GNAT pragma???
7127 Tdef : constant Node_Id :=
7128 Type_Definition (Declaration_Node (Typ));
7133 if Nkind (Tdef) = N_Record_Definition then
7134 Clist := Component_List (Tdef);
7136 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7137 Clist := Component_List (Record_Extension_Part (Tdef));
7140 if Present (Clist) then
7141 Comp := First (Component_Items (Clist));
7142 while Present (Comp) loop
7143 if Present (Expression (Comp)) then
7145 ("component of imported 'C'P'P type cannot have" &
7146 " default expression", Expression (Comp));
7156 ---------------------
7157 -- CPP_Constructor --
7158 ---------------------
7160 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7161 -- [, [External_Name =>] static_string_EXPRESSION ]
7162 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7164 when Pragma_CPP_Constructor => CPP_Constructor : declare
7168 Tag_Typ : Entity_Id;
7172 Check_At_Least_N_Arguments (1);
7173 Check_At_Most_N_Arguments (3);
7174 Check_Optional_Identifier (Arg1, Name_Entity);
7175 Check_Arg_Is_Local_Name (Arg1);
7177 Id := Get_Pragma_Arg (Arg1);
7178 Find_Program_Unit_Name (Id);
7180 -- If we did not find the name, we are done
7182 if Etype (Id) = Any_Type then
7186 Def_Id := Entity (Id);
7188 -- Check if already defined as constructor
7190 if Is_Constructor (Def_Id) then
7192 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7196 if Ekind (Def_Id) = E_Function
7197 and then (Is_CPP_Class (Etype (Def_Id))
7198 or else (Is_Class_Wide_Type (Etype (Def_Id))
7200 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7202 if Arg_Count >= 2 then
7203 Set_Imported (Def_Id);
7204 Set_Is_Public (Def_Id);
7205 Process_Interface_Name (Def_Id, Arg2, Arg3);
7208 Set_Has_Completion (Def_Id);
7209 Set_Is_Constructor (Def_Id);
7211 -- Imported C++ constructors are not dispatching primitives
7212 -- because in C++ they don't have a dispatch table slot.
7213 -- However, in Ada the constructor has the profile of a
7214 -- function that returns a tagged type and therefore it has
7215 -- been treated as a primitive operation during semantic
7216 -- analysis. We now remove it from the list of primitive
7217 -- operations of the type.
7219 if Is_Tagged_Type (Etype (Def_Id))
7220 and then not Is_Class_Wide_Type (Etype (Def_Id))
7222 pragma Assert (Is_Dispatching_Operation (Def_Id));
7223 Tag_Typ := Etype (Def_Id);
7225 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7226 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7230 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7231 Set_Is_Dispatching_Operation (Def_Id, False);
7234 -- For backward compatibility, if the constructor returns a
7235 -- class wide type, and we internally change the return type to
7236 -- the corresponding root type.
7238 if Is_Class_Wide_Type (Etype (Def_Id)) then
7239 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7243 ("pragma% requires function returning a 'C'P'P_Class type",
7246 end CPP_Constructor;
7252 when Pragma_CPP_Virtual => CPP_Virtual : declare
7256 if Warn_On_Obsolescent_Feature then
7258 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7267 when Pragma_CPP_Vtable => CPP_Vtable : declare
7271 if Warn_On_Obsolescent_Feature then
7273 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7282 -- pragma CPU (EXPRESSION);
7284 when Pragma_CPU => CPU : declare
7285 P : constant Node_Id := Parent (N);
7290 Check_No_Identifiers;
7291 Check_Arg_Count (1);
7295 if Nkind (P) = N_Subprogram_Body then
7296 Check_In_Main_Program;
7298 Arg := Get_Pragma_Arg (Arg1);
7299 Analyze_And_Resolve (Arg, Any_Integer);
7303 if not Is_Static_Expression (Arg) then
7304 Flag_Non_Static_Expr
7305 ("main subprogram affinity is not static!", Arg);
7308 -- If constraint error, then we already signalled an error
7310 elsif Raises_Constraint_Error (Arg) then
7313 -- Otherwise check in range
7317 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7318 -- This is the entity System.Multiprocessors.CPU_Range;
7320 Val : constant Uint := Expr_Value (Arg);
7323 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7325 Val > Expr_Value (Type_High_Bound (CPU_Id))
7328 ("main subprogram CPU is out of range", Arg1);
7334 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7338 elsif Nkind (P) = N_Task_Definition then
7339 Arg := Get_Pragma_Arg (Arg1);
7341 -- The expression must be analyzed in the special manner
7342 -- described in "Handling of Default and Per-Object
7343 -- Expressions" in sem.ads.
7345 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7347 -- Anything else is incorrect
7353 if Has_Pragma_CPU (P) then
7354 Error_Pragma ("duplicate pragma% not allowed");
7356 Set_Has_Pragma_CPU (P, True);
7358 if Nkind (P) = N_Task_Definition then
7359 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7368 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7370 when Pragma_Debug => Debug : declare
7378 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7381 if Arg_Count = 2 then
7384 Left_Opnd => Relocate_Node (Cond),
7385 Right_Opnd => Get_Pragma_Arg (Arg1));
7388 -- Rewrite into a conditional with an appropriate condition. We
7389 -- wrap the procedure call in a block so that overhead from e.g.
7390 -- use of the secondary stack does not generate execution overhead
7391 -- for suppressed conditions.
7393 Rewrite (N, Make_Implicit_If_Statement (N,
7395 Then_Statements => New_List (
7396 Make_Block_Statement (Loc,
7397 Handled_Statement_Sequence =>
7398 Make_Handled_Sequence_Of_Statements (Loc,
7399 Statements => New_List (
7400 Relocate_Node (Debug_Statement (N))))))));
7408 -- pragma Debug_Policy (Check | Ignore)
7410 when Pragma_Debug_Policy =>
7412 Check_Arg_Count (1);
7413 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7414 Debug_Pragmas_Enabled :=
7415 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7417 ---------------------
7418 -- Detect_Blocking --
7419 ---------------------
7421 -- pragma Detect_Blocking;
7423 when Pragma_Detect_Blocking =>
7425 Check_Arg_Count (0);
7426 Check_Valid_Configuration_Pragma;
7427 Detect_Blocking := True;
7429 --------------------------
7430 -- Default_Storage_Pool --
7431 --------------------------
7433 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7435 when Pragma_Default_Storage_Pool =>
7437 Check_Arg_Count (1);
7439 -- Default_Storage_Pool can appear as a configuration pragma, or
7440 -- in a declarative part or a package spec.
7442 if not Is_Configuration_Pragma then
7443 Check_Is_In_Decl_Part_Or_Package_Spec;
7446 -- Case of Default_Storage_Pool (null);
7448 if Nkind (Expression (Arg1)) = N_Null then
7449 Analyze (Expression (Arg1));
7451 -- This is an odd case, this is not really an expression, so
7452 -- we don't have a type for it. So just set the type to Empty.
7454 Set_Etype (Expression (Arg1), Empty);
7456 -- Case of Default_Storage_Pool (storage_pool_NAME);
7459 -- If it's a configuration pragma, then the only allowed
7460 -- argument is "null".
7462 if Is_Configuration_Pragma then
7463 Error_Pragma_Arg ("NULL expected", Arg1);
7466 -- The expected type for a non-"null" argument is
7467 -- Root_Storage_Pool'Class.
7470 (Get_Pragma_Arg (Arg1),
7471 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7474 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7475 -- for an access type will use this information to set the
7476 -- appropriate attributes of the access type.
7478 Default_Pool := Expression (Arg1);
7484 when Pragma_Dimension =>
7486 Check_Arg_Count (4);
7487 Check_No_Identifiers;
7488 Check_Arg_Is_Local_Name (Arg1);
7490 if not Is_Type (Arg1) then
7491 Error_Pragma ("first argument for pragma% must be subtype");
7494 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7495 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7496 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7502 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7504 when Pragma_Discard_Names => Discard_Names : declare
7509 Check_Ada_83_Warning;
7511 -- Deal with configuration pragma case
7513 if Arg_Count = 0 and then Is_Configuration_Pragma then
7514 Global_Discard_Names := True;
7517 -- Otherwise, check correct appropriate context
7520 Check_Is_In_Decl_Part_Or_Package_Spec;
7522 if Arg_Count = 0 then
7524 -- If there is no parameter, then from now on this pragma
7525 -- applies to any enumeration, exception or tagged type
7526 -- defined in the current declarative part, and recursively
7527 -- to any nested scope.
7529 Set_Discard_Names (Current_Scope);
7533 Check_Arg_Count (1);
7534 Check_Optional_Identifier (Arg1, Name_On);
7535 Check_Arg_Is_Local_Name (Arg1);
7537 E_Id := Get_Pragma_Arg (Arg1);
7539 if Etype (E_Id) = Any_Type then
7545 if (Is_First_Subtype (E)
7547 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7548 or else Ekind (E) = E_Exception
7550 Set_Discard_Names (E);
7553 ("inappropriate entity for pragma%", Arg1);
7564 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7566 when Pragma_Elaborate => Elaborate : declare
7571 -- Pragma must be in context items list of a compilation unit
7573 if not Is_In_Context_Clause then
7577 -- Must be at least one argument
7579 if Arg_Count = 0 then
7580 Error_Pragma ("pragma% requires at least one argument");
7583 -- In Ada 83 mode, there can be no items following it in the
7584 -- context list except other pragmas and implicit with clauses
7585 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7586 -- placement rule does not apply.
7588 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7590 while Present (Citem) loop
7591 if Nkind (Citem) = N_Pragma
7592 or else (Nkind (Citem) = N_With_Clause
7593 and then Implicit_With (Citem))
7598 ("(Ada 83) pragma% must be at end of context clause");
7605 -- Finally, the arguments must all be units mentioned in a with
7606 -- clause in the same context clause. Note we already checked (in
7607 -- Par.Prag) that the arguments are all identifiers or selected
7611 Outer : while Present (Arg) loop
7612 Citem := First (List_Containing (N));
7613 Inner : while Citem /= N loop
7614 if Nkind (Citem) = N_With_Clause
7615 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7617 Set_Elaborate_Present (Citem, True);
7618 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7619 Generate_Reference (Entity (Name (Citem)), Citem);
7621 -- With the pragma present, elaboration calls on
7622 -- subprograms from the named unit need no further
7623 -- checks, as long as the pragma appears in the current
7624 -- compilation unit. If the pragma appears in some unit
7625 -- in the context, there might still be a need for an
7626 -- Elaborate_All_Desirable from the current compilation
7627 -- to the named unit, so we keep the check enabled.
7629 if In_Extended_Main_Source_Unit (N) then
7630 Set_Suppress_Elaboration_Warnings
7631 (Entity (Name (Citem)));
7642 ("argument of pragma% is not with'ed unit", Arg);
7648 -- Give a warning if operating in static mode with -gnatwl
7649 -- (elaboration warnings enabled) switch set.
7651 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7653 ("?use of pragma Elaborate may not be safe", N);
7655 ("?use pragma Elaborate_All instead if possible", N);
7663 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7665 when Pragma_Elaborate_All => Elaborate_All : declare
7670 Check_Ada_83_Warning;
7672 -- Pragma must be in context items list of a compilation unit
7674 if not Is_In_Context_Clause then
7678 -- Must be at least one argument
7680 if Arg_Count = 0 then
7681 Error_Pragma ("pragma% requires at least one argument");
7684 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7685 -- have to appear at the end of the context clause, but may
7686 -- appear mixed in with other items, even in Ada 83 mode.
7688 -- Final check: the arguments must all be units mentioned in
7689 -- a with clause in the same context clause. Note that we
7690 -- already checked (in Par.Prag) that all the arguments are
7691 -- either identifiers or selected components.
7694 Outr : while Present (Arg) loop
7695 Citem := First (List_Containing (N));
7696 Innr : while Citem /= N loop
7697 if Nkind (Citem) = N_With_Clause
7698 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7700 Set_Elaborate_All_Present (Citem, True);
7701 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7703 -- Suppress warnings and elaboration checks on the named
7704 -- unit if the pragma is in the current compilation, as
7705 -- for pragma Elaborate.
7707 if In_Extended_Main_Source_Unit (N) then
7708 Set_Suppress_Elaboration_Warnings
7709 (Entity (Name (Citem)));
7718 Set_Error_Posted (N);
7720 ("argument of pragma% is not with'ed unit", Arg);
7727 --------------------
7728 -- Elaborate_Body --
7729 --------------------
7731 -- pragma Elaborate_Body [( library_unit_NAME )];
7733 when Pragma_Elaborate_Body => Elaborate_Body : declare
7734 Cunit_Node : Node_Id;
7735 Cunit_Ent : Entity_Id;
7738 Check_Ada_83_Warning;
7739 Check_Valid_Library_Unit_Pragma;
7741 if Nkind (N) = N_Null_Statement then
7745 Cunit_Node := Cunit (Current_Sem_Unit);
7746 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7748 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7751 Error_Pragma ("pragma% must refer to a spec, not a body");
7753 Set_Body_Required (Cunit_Node, True);
7754 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7756 -- If we are in dynamic elaboration mode, then we suppress
7757 -- elaboration warnings for the unit, since it is definitely
7758 -- fine NOT to do dynamic checks at the first level (and such
7759 -- checks will be suppressed because no elaboration boolean
7760 -- is created for Elaborate_Body packages).
7762 -- But in the static model of elaboration, Elaborate_Body is
7763 -- definitely NOT good enough to ensure elaboration safety on
7764 -- its own, since the body may WITH other units that are not
7765 -- safe from an elaboration point of view, so a client must
7766 -- still do an Elaborate_All on such units.
7768 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7769 -- Elaborate_Body always suppressed elab warnings.
7771 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7772 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7777 ------------------------
7778 -- Elaboration_Checks --
7779 ------------------------
7781 -- pragma Elaboration_Checks (Static | Dynamic);
7783 when Pragma_Elaboration_Checks =>
7785 Check_Arg_Count (1);
7786 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7787 Dynamic_Elaboration_Checks :=
7788 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7794 -- pragma Eliminate (
7795 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7796 -- [,[Entity =>] IDENTIFIER |
7797 -- SELECTED_COMPONENT |
7799 -- [, OVERLOADING_RESOLUTION]);
7801 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7804 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7807 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7809 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7810 -- Result_Type => result_SUBTYPE_NAME]
7812 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7813 -- SUBTYPE_NAME ::= STRING_LITERAL
7815 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7816 -- SOURCE_TRACE ::= STRING_LITERAL
7818 when Pragma_Eliminate => Eliminate : declare
7819 Args : Args_List (1 .. 5);
7820 Names : constant Name_List (1 .. 5) := (
7823 Name_Parameter_Types,
7825 Name_Source_Location);
7827 Unit_Name : Node_Id renames Args (1);
7828 Entity : Node_Id renames Args (2);
7829 Parameter_Types : Node_Id renames Args (3);
7830 Result_Type : Node_Id renames Args (4);
7831 Source_Location : Node_Id renames Args (5);
7835 Check_Valid_Configuration_Pragma;
7836 Gather_Associations (Names, Args);
7838 if No (Unit_Name) then
7839 Error_Pragma ("missing Unit_Name argument for pragma%");
7843 and then (Present (Parameter_Types)
7845 Present (Result_Type)
7847 Present (Source_Location))
7849 Error_Pragma ("missing Entity argument for pragma%");
7852 if (Present (Parameter_Types)
7854 Present (Result_Type))
7856 Present (Source_Location)
7859 ("parameter profile and source location cannot " &
7860 "be used together in pragma%");
7863 Process_Eliminate_Pragma
7877 -- [ Convention =>] convention_IDENTIFIER,
7878 -- [ Entity =>] local_NAME
7879 -- [, [External_Name =>] static_string_EXPRESSION ]
7880 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7882 when Pragma_Export => Export : declare
7886 pragma Warnings (Off, C);
7889 Check_Ada_83_Warning;
7895 Check_At_Least_N_Arguments (2);
7896 Check_At_Most_N_Arguments (4);
7897 Process_Convention (C, Def_Id);
7899 if Ekind (Def_Id) /= E_Constant then
7900 Note_Possible_Modification
7901 (Get_Pragma_Arg (Arg2), Sure => False);
7904 Process_Interface_Name (Def_Id, Arg3, Arg4);
7905 Set_Exported (Def_Id, Arg2);
7907 -- If the entity is a deferred constant, propagate the information
7908 -- to the full view, because gigi elaborates the full view only.
7910 if Ekind (Def_Id) = E_Constant
7911 and then Present (Full_View (Def_Id))
7914 Id2 : constant Entity_Id := Full_View (Def_Id);
7916 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7917 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7918 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7923 ----------------------
7924 -- Export_Exception --
7925 ----------------------
7927 -- pragma Export_Exception (
7928 -- [Internal =>] LOCAL_NAME
7929 -- [, [External =>] EXTERNAL_SYMBOL]
7930 -- [, [Form =>] Ada | VMS]
7931 -- [, [Code =>] static_integer_EXPRESSION]);
7933 when Pragma_Export_Exception => Export_Exception : declare
7934 Args : Args_List (1 .. 4);
7935 Names : constant Name_List (1 .. 4) := (
7941 Internal : Node_Id renames Args (1);
7942 External : Node_Id renames Args (2);
7943 Form : Node_Id renames Args (3);
7944 Code : Node_Id renames Args (4);
7949 if Inside_A_Generic then
7950 Error_Pragma ("pragma% cannot be used for generic entities");
7953 Gather_Associations (Names, Args);
7954 Process_Extended_Import_Export_Exception_Pragma (
7955 Arg_Internal => Internal,
7956 Arg_External => External,
7960 if not Is_VMS_Exception (Entity (Internal)) then
7961 Set_Exported (Entity (Internal), Internal);
7963 end Export_Exception;
7965 ---------------------
7966 -- Export_Function --
7967 ---------------------
7969 -- pragma Export_Function (
7970 -- [Internal =>] LOCAL_NAME
7971 -- [, [External =>] EXTERNAL_SYMBOL]
7972 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7973 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7974 -- [, [Mechanism =>] MECHANISM]
7975 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7977 -- EXTERNAL_SYMBOL ::=
7979 -- | static_string_EXPRESSION
7981 -- PARAMETER_TYPES ::=
7983 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7985 -- TYPE_DESIGNATOR ::=
7987 -- | subtype_Name ' Access
7991 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7993 -- MECHANISM_ASSOCIATION ::=
7994 -- [formal_parameter_NAME =>] MECHANISM_NAME
7996 -- MECHANISM_NAME ::=
7999 -- | Descriptor [([Class =>] CLASS_NAME)]
8001 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8003 when Pragma_Export_Function => Export_Function : declare
8004 Args : Args_List (1 .. 6);
8005 Names : constant Name_List (1 .. 6) := (
8008 Name_Parameter_Types,
8011 Name_Result_Mechanism);
8013 Internal : Node_Id renames Args (1);
8014 External : Node_Id renames Args (2);
8015 Parameter_Types : Node_Id renames Args (3);
8016 Result_Type : Node_Id renames Args (4);
8017 Mechanism : Node_Id renames Args (5);
8018 Result_Mechanism : Node_Id renames Args (6);
8022 Gather_Associations (Names, Args);
8023 Process_Extended_Import_Export_Subprogram_Pragma (
8024 Arg_Internal => Internal,
8025 Arg_External => External,
8026 Arg_Parameter_Types => Parameter_Types,
8027 Arg_Result_Type => Result_Type,
8028 Arg_Mechanism => Mechanism,
8029 Arg_Result_Mechanism => Result_Mechanism);
8030 end Export_Function;
8036 -- pragma Export_Object (
8037 -- [Internal =>] LOCAL_NAME
8038 -- [, [External =>] EXTERNAL_SYMBOL]
8039 -- [, [Size =>] EXTERNAL_SYMBOL]);
8041 -- EXTERNAL_SYMBOL ::=
8043 -- | static_string_EXPRESSION
8045 -- PARAMETER_TYPES ::=
8047 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8049 -- TYPE_DESIGNATOR ::=
8051 -- | subtype_Name ' Access
8055 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8057 -- MECHANISM_ASSOCIATION ::=
8058 -- [formal_parameter_NAME =>] MECHANISM_NAME
8060 -- MECHANISM_NAME ::=
8063 -- | Descriptor [([Class =>] CLASS_NAME)]
8065 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8067 when Pragma_Export_Object => Export_Object : declare
8068 Args : Args_List (1 .. 3);
8069 Names : constant Name_List (1 .. 3) := (
8074 Internal : Node_Id renames Args (1);
8075 External : Node_Id renames Args (2);
8076 Size : Node_Id renames Args (3);
8080 Gather_Associations (Names, Args);
8081 Process_Extended_Import_Export_Object_Pragma (
8082 Arg_Internal => Internal,
8083 Arg_External => External,
8087 ----------------------
8088 -- Export_Procedure --
8089 ----------------------
8091 -- pragma Export_Procedure (
8092 -- [Internal =>] LOCAL_NAME
8093 -- [, [External =>] EXTERNAL_SYMBOL]
8094 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8095 -- [, [Mechanism =>] MECHANISM]);
8097 -- EXTERNAL_SYMBOL ::=
8099 -- | static_string_EXPRESSION
8101 -- PARAMETER_TYPES ::=
8103 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8105 -- TYPE_DESIGNATOR ::=
8107 -- | subtype_Name ' Access
8111 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8113 -- MECHANISM_ASSOCIATION ::=
8114 -- [formal_parameter_NAME =>] MECHANISM_NAME
8116 -- MECHANISM_NAME ::=
8119 -- | Descriptor [([Class =>] CLASS_NAME)]
8121 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8123 when Pragma_Export_Procedure => Export_Procedure : declare
8124 Args : Args_List (1 .. 4);
8125 Names : constant Name_List (1 .. 4) := (
8128 Name_Parameter_Types,
8131 Internal : Node_Id renames Args (1);
8132 External : Node_Id renames Args (2);
8133 Parameter_Types : Node_Id renames Args (3);
8134 Mechanism : Node_Id renames Args (4);
8138 Gather_Associations (Names, Args);
8139 Process_Extended_Import_Export_Subprogram_Pragma (
8140 Arg_Internal => Internal,
8141 Arg_External => External,
8142 Arg_Parameter_Types => Parameter_Types,
8143 Arg_Mechanism => Mechanism);
8144 end Export_Procedure;
8150 -- pragma Export_Value (
8151 -- [Value =>] static_integer_EXPRESSION,
8152 -- [Link_Name =>] static_string_EXPRESSION);
8154 when Pragma_Export_Value =>
8156 Check_Arg_Order ((Name_Value, Name_Link_Name));
8157 Check_Arg_Count (2);
8159 Check_Optional_Identifier (Arg1, Name_Value);
8160 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8162 Check_Optional_Identifier (Arg2, Name_Link_Name);
8163 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8165 -----------------------------
8166 -- Export_Valued_Procedure --
8167 -----------------------------
8169 -- pragma Export_Valued_Procedure (
8170 -- [Internal =>] LOCAL_NAME
8171 -- [, [External =>] EXTERNAL_SYMBOL,]
8172 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8173 -- [, [Mechanism =>] MECHANISM]);
8175 -- EXTERNAL_SYMBOL ::=
8177 -- | static_string_EXPRESSION
8179 -- PARAMETER_TYPES ::=
8181 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8183 -- TYPE_DESIGNATOR ::=
8185 -- | subtype_Name ' Access
8189 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8191 -- MECHANISM_ASSOCIATION ::=
8192 -- [formal_parameter_NAME =>] MECHANISM_NAME
8194 -- MECHANISM_NAME ::=
8197 -- | Descriptor [([Class =>] CLASS_NAME)]
8199 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8201 when Pragma_Export_Valued_Procedure =>
8202 Export_Valued_Procedure : declare
8203 Args : Args_List (1 .. 4);
8204 Names : constant Name_List (1 .. 4) := (
8207 Name_Parameter_Types,
8210 Internal : Node_Id renames Args (1);
8211 External : Node_Id renames Args (2);
8212 Parameter_Types : Node_Id renames Args (3);
8213 Mechanism : Node_Id renames Args (4);
8217 Gather_Associations (Names, Args);
8218 Process_Extended_Import_Export_Subprogram_Pragma (
8219 Arg_Internal => Internal,
8220 Arg_External => External,
8221 Arg_Parameter_Types => Parameter_Types,
8222 Arg_Mechanism => Mechanism);
8223 end Export_Valued_Procedure;
8229 -- pragma Extend_System ([Name =>] Identifier);
8231 when Pragma_Extend_System => Extend_System : declare
8234 Check_Valid_Configuration_Pragma;
8235 Check_Arg_Count (1);
8236 Check_Optional_Identifier (Arg1, Name_Name);
8237 Check_Arg_Is_Identifier (Arg1);
8239 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8242 and then Name_Buffer (1 .. 4) = "aux_"
8244 if Present (System_Extend_Pragma_Arg) then
8245 if Chars (Get_Pragma_Arg (Arg1)) =
8246 Chars (Expression (System_Extend_Pragma_Arg))
8250 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8251 Error_Pragma ("pragma% conflicts with that #");
8255 System_Extend_Pragma_Arg := Arg1;
8257 if not GNAT_Mode then
8258 System_Extend_Unit := Arg1;
8262 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8266 ------------------------
8267 -- Extensions_Allowed --
8268 ------------------------
8270 -- pragma Extensions_Allowed (ON | OFF);
8272 when Pragma_Extensions_Allowed =>
8274 Check_Arg_Count (1);
8275 Check_No_Identifiers;
8276 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8278 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8279 Extensions_Allowed := True;
8280 Ada_Version := Ada_Version_Type'Last;
8283 Extensions_Allowed := False;
8284 Ada_Version := Ada_Version_Explicit;
8291 -- pragma External (
8292 -- [ Convention =>] convention_IDENTIFIER,
8293 -- [ Entity =>] local_NAME
8294 -- [, [External_Name =>] static_string_EXPRESSION ]
8295 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8297 when Pragma_External => External : declare
8301 pragma Warnings (Off, C);
8310 Check_At_Least_N_Arguments (2);
8311 Check_At_Most_N_Arguments (4);
8312 Process_Convention (C, Def_Id);
8313 Note_Possible_Modification
8314 (Get_Pragma_Arg (Arg2), Sure => False);
8315 Process_Interface_Name (Def_Id, Arg3, Arg4);
8316 Set_Exported (Def_Id, Arg2);
8319 --------------------------
8320 -- External_Name_Casing --
8321 --------------------------
8323 -- pragma External_Name_Casing (
8324 -- UPPERCASE | LOWERCASE
8325 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8327 when Pragma_External_Name_Casing => External_Name_Casing : declare
8330 Check_No_Identifiers;
8332 if Arg_Count = 2 then
8334 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8336 case Chars (Get_Pragma_Arg (Arg2)) is
8338 Opt.External_Name_Exp_Casing := As_Is;
8340 when Name_Uppercase =>
8341 Opt.External_Name_Exp_Casing := Uppercase;
8343 when Name_Lowercase =>
8344 Opt.External_Name_Exp_Casing := Lowercase;
8351 Check_Arg_Count (1);
8354 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8356 case Chars (Get_Pragma_Arg (Arg1)) is
8357 when Name_Uppercase =>
8358 Opt.External_Name_Imp_Casing := Uppercase;
8360 when Name_Lowercase =>
8361 Opt.External_Name_Imp_Casing := Lowercase;
8366 end External_Name_Casing;
8368 --------------------------
8369 -- Favor_Top_Level --
8370 --------------------------
8372 -- pragma Favor_Top_Level (type_NAME);
8374 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8375 Named_Entity : Entity_Id;
8379 Check_No_Identifiers;
8380 Check_Arg_Count (1);
8381 Check_Arg_Is_Local_Name (Arg1);
8382 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8384 -- If it's an access-to-subprogram type (in particular, not a
8385 -- subtype), set the flag on that type.
8387 if Is_Access_Subprogram_Type (Named_Entity) then
8388 Set_Can_Use_Internal_Rep (Named_Entity, False);
8390 -- Otherwise it's an error (name denotes the wrong sort of entity)
8394 ("access-to-subprogram type expected",
8395 Get_Pragma_Arg (Arg1));
8397 end Favor_Top_Level;
8403 -- pragma Fast_Math;
8405 when Pragma_Fast_Math =>
8407 Check_No_Identifiers;
8408 Check_Valid_Configuration_Pragma;
8411 ---------------------------
8412 -- Finalize_Storage_Only --
8413 ---------------------------
8415 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8417 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8418 Assoc : constant Node_Id := Arg1;
8419 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8424 Check_No_Identifiers;
8425 Check_Arg_Count (1);
8426 Check_Arg_Is_Local_Name (Arg1);
8428 Find_Type (Type_Id);
8429 Typ := Entity (Type_Id);
8432 or else Rep_Item_Too_Early (Typ, N)
8436 Typ := Underlying_Type (Typ);
8439 if not Is_Controlled (Typ) then
8440 Error_Pragma ("pragma% must specify controlled type");
8443 Check_First_Subtype (Arg1);
8445 if Finalize_Storage_Only (Typ) then
8446 Error_Pragma ("duplicate pragma%, only one allowed");
8448 elsif not Rep_Item_Too_Late (Typ, N) then
8449 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8451 end Finalize_Storage;
8453 --------------------------
8454 -- Float_Representation --
8455 --------------------------
8457 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8459 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8461 when Pragma_Float_Representation => Float_Representation : declare
8469 if Arg_Count = 1 then
8470 Check_Valid_Configuration_Pragma;
8472 Check_Arg_Count (2);
8473 Check_Optional_Identifier (Arg2, Name_Entity);
8474 Check_Arg_Is_Local_Name (Arg2);
8477 Check_No_Identifier (Arg1);
8478 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8480 if not OpenVMS_On_Target then
8481 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8483 ("?pragma% ignored (applies only to Open'V'M'S)");
8489 -- One argument case
8491 if Arg_Count = 1 then
8492 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8493 if Opt.Float_Format = 'I' then
8494 Error_Pragma ("'I'E'E'E format previously specified");
8497 Opt.Float_Format := 'V';
8500 if Opt.Float_Format = 'V' then
8501 Error_Pragma ("'V'A'X format previously specified");
8504 Opt.Float_Format := 'I';
8507 Set_Standard_Fpt_Formats;
8509 -- Two argument case
8512 Argx := Get_Pragma_Arg (Arg2);
8514 if not Is_Entity_Name (Argx)
8515 or else not Is_Floating_Point_Type (Entity (Argx))
8518 ("second argument of% pragma must be floating-point type",
8522 Ent := Entity (Argx);
8523 Digs := UI_To_Int (Digits_Value (Ent));
8525 -- Two arguments, VAX_Float case
8527 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8529 when 6 => Set_F_Float (Ent);
8530 when 9 => Set_D_Float (Ent);
8531 when 15 => Set_G_Float (Ent);
8535 ("wrong digits value, must be 6,9 or 15", Arg2);
8538 -- Two arguments, IEEE_Float case
8542 when 6 => Set_IEEE_Short (Ent);
8543 when 15 => Set_IEEE_Long (Ent);
8547 ("wrong digits value, must be 6 or 15", Arg2);
8551 end Float_Representation;
8557 -- pragma Ident (static_string_EXPRESSION)
8559 -- Note: pragma Comment shares this processing. Pragma Comment is
8560 -- identical to Ident, except that the restriction of the argument to
8561 -- 31 characters and the placement restrictions are not enforced for
8564 when Pragma_Ident | Pragma_Comment => Ident : declare
8569 Check_Arg_Count (1);
8570 Check_No_Identifiers;
8571 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8574 -- For pragma Ident, preserve DEC compatibility by requiring the
8575 -- pragma to appear in a declarative part or package spec.
8577 if Prag_Id = Pragma_Ident then
8578 Check_Is_In_Decl_Part_Or_Package_Spec;
8581 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8588 GP := Parent (Parent (N));
8590 if Nkind_In (GP, N_Package_Declaration,
8591 N_Generic_Package_Declaration)
8596 -- If we have a compilation unit, then record the ident value,
8597 -- checking for improper duplication.
8599 if Nkind (GP) = N_Compilation_Unit then
8600 CS := Ident_String (Current_Sem_Unit);
8602 if Present (CS) then
8604 -- For Ident, we do not permit multiple instances
8606 if Prag_Id = Pragma_Ident then
8607 Error_Pragma ("duplicate% pragma not permitted");
8609 -- For Comment, we concatenate the string, unless we want
8610 -- to preserve the tree structure for ASIS.
8612 elsif not ASIS_Mode then
8613 Start_String (Strval (CS));
8614 Store_String_Char (' ');
8615 Store_String_Chars (Strval (Str));
8616 Set_Strval (CS, End_String);
8620 -- In VMS, the effect of IDENT is achieved by passing
8621 -- --identification=name as a --for-linker switch.
8623 if OpenVMS_On_Target then
8626 ("--for-linker=--identification=");
8627 String_To_Name_Buffer (Strval (Str));
8628 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8630 -- Only the last processed IDENT is saved. The main
8631 -- purpose is so an IDENT associated with a main
8632 -- procedure will be used in preference to an IDENT
8633 -- associated with a with'd package.
8635 Replace_Linker_Option_String
8636 (End_String, "--for-linker=--identification=");
8639 Set_Ident_String (Current_Sem_Unit, Str);
8642 -- For subunits, we just ignore the Ident, since in GNAT these
8643 -- are not separate object files, and hence not separate units
8644 -- in the unit table.
8646 elsif Nkind (GP) = N_Subunit then
8649 -- Otherwise we have a misplaced pragma Ident, but we ignore
8650 -- this if we are in an instantiation, since it comes from
8651 -- a generic, and has no relevance to the instantiation.
8653 elsif Prag_Id = Pragma_Ident then
8654 if Instantiation_Location (Loc) = No_Location then
8655 Error_Pragma ("pragma% only allowed at outer level");
8665 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8666 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8668 when Pragma_Implemented => Implemented : declare
8669 Proc_Id : Entity_Id;
8674 Check_Arg_Count (2);
8675 Check_No_Identifiers;
8676 Check_Arg_Is_Identifier (Arg1);
8677 Check_Arg_Is_Local_Name (Arg1);
8679 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8681 -- Extract the name of the local procedure
8683 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8685 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8686 -- primitive procedure of a synchronized tagged type.
8688 if Ekind (Proc_Id) = E_Procedure
8689 and then Is_Primitive (Proc_Id)
8690 and then Present (First_Formal (Proc_Id))
8692 Typ := Etype (First_Formal (Proc_Id));
8694 if Is_Tagged_Type (Typ)
8697 -- Check for a protected, a synchronized or a task interface
8699 ((Is_Interface (Typ)
8700 and then Is_Synchronized_Interface (Typ))
8702 -- Check for a protected type or a task type that implements
8706 (Is_Concurrent_Record_Type (Typ)
8707 and then Present (Interfaces (Typ)))
8709 -- Check for a private record extension with keyword
8713 (Ekind_In (Typ, E_Record_Type_With_Private,
8714 E_Record_Subtype_With_Private)
8715 and then Synchronized_Present (Parent (Typ))))
8720 ("controlling formal must be of synchronized " &
8721 "tagged type", Arg1);
8725 -- Procedures declared inside a protected type must be accepted
8727 elsif Ekind (Proc_Id) = E_Procedure
8728 and then Is_Protected_Type (Scope (Proc_Id))
8732 -- The first argument is not a primitive procedure
8736 ("pragma % must be applied to a primitive procedure", Arg1);
8740 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8741 -- By_Protected_Procedure to the primitive procedure of a task
8744 if Chars (Arg2) = Name_By_Protected_Procedure
8745 and then Is_Interface (Typ)
8746 and then Is_Task_Interface (Typ)
8749 ("implementation kind By_Protected_Procedure cannot be " &
8750 "applied to a task interface primitive", Arg2);
8754 Record_Rep_Item (Proc_Id, N);
8757 ----------------------
8758 -- Implicit_Packing --
8759 ----------------------
8761 -- pragma Implicit_Packing;
8763 when Pragma_Implicit_Packing =>
8765 Check_Arg_Count (0);
8766 Implicit_Packing := True;
8773 -- [Convention =>] convention_IDENTIFIER,
8774 -- [Entity =>] local_NAME
8775 -- [, [External_Name =>] static_string_EXPRESSION ]
8776 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8778 when Pragma_Import =>
8779 Check_Ada_83_Warning;
8785 Check_At_Least_N_Arguments (2);
8786 Check_At_Most_N_Arguments (4);
8787 Process_Import_Or_Interface;
8789 ----------------------
8790 -- Import_Exception --
8791 ----------------------
8793 -- pragma Import_Exception (
8794 -- [Internal =>] LOCAL_NAME
8795 -- [, [External =>] EXTERNAL_SYMBOL]
8796 -- [, [Form =>] Ada | VMS]
8797 -- [, [Code =>] static_integer_EXPRESSION]);
8799 when Pragma_Import_Exception => Import_Exception : declare
8800 Args : Args_List (1 .. 4);
8801 Names : constant Name_List (1 .. 4) := (
8807 Internal : Node_Id renames Args (1);
8808 External : Node_Id renames Args (2);
8809 Form : Node_Id renames Args (3);
8810 Code : Node_Id renames Args (4);
8814 Gather_Associations (Names, Args);
8816 if Present (External) and then Present (Code) then
8818 ("cannot give both External and Code options for pragma%");
8821 Process_Extended_Import_Export_Exception_Pragma (
8822 Arg_Internal => Internal,
8823 Arg_External => External,
8827 if not Is_VMS_Exception (Entity (Internal)) then
8828 Set_Imported (Entity (Internal));
8830 end Import_Exception;
8832 ---------------------
8833 -- Import_Function --
8834 ---------------------
8836 -- pragma Import_Function (
8837 -- [Internal =>] LOCAL_NAME,
8838 -- [, [External =>] EXTERNAL_SYMBOL]
8839 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8840 -- [, [Result_Type =>] SUBTYPE_MARK]
8841 -- [, [Mechanism =>] MECHANISM]
8842 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8843 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8845 -- EXTERNAL_SYMBOL ::=
8847 -- | static_string_EXPRESSION
8849 -- PARAMETER_TYPES ::=
8851 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8853 -- TYPE_DESIGNATOR ::=
8855 -- | subtype_Name ' Access
8859 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8861 -- MECHANISM_ASSOCIATION ::=
8862 -- [formal_parameter_NAME =>] MECHANISM_NAME
8864 -- MECHANISM_NAME ::=
8867 -- | Descriptor [([Class =>] CLASS_NAME)]
8869 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8871 when Pragma_Import_Function => Import_Function : declare
8872 Args : Args_List (1 .. 7);
8873 Names : constant Name_List (1 .. 7) := (
8876 Name_Parameter_Types,
8879 Name_Result_Mechanism,
8880 Name_First_Optional_Parameter);
8882 Internal : Node_Id renames Args (1);
8883 External : Node_Id renames Args (2);
8884 Parameter_Types : Node_Id renames Args (3);
8885 Result_Type : Node_Id renames Args (4);
8886 Mechanism : Node_Id renames Args (5);
8887 Result_Mechanism : Node_Id renames Args (6);
8888 First_Optional_Parameter : Node_Id renames Args (7);
8892 Gather_Associations (Names, Args);
8893 Process_Extended_Import_Export_Subprogram_Pragma (
8894 Arg_Internal => Internal,
8895 Arg_External => External,
8896 Arg_Parameter_Types => Parameter_Types,
8897 Arg_Result_Type => Result_Type,
8898 Arg_Mechanism => Mechanism,
8899 Arg_Result_Mechanism => Result_Mechanism,
8900 Arg_First_Optional_Parameter => First_Optional_Parameter);
8901 end Import_Function;
8907 -- pragma Import_Object (
8908 -- [Internal =>] LOCAL_NAME
8909 -- [, [External =>] EXTERNAL_SYMBOL]
8910 -- [, [Size =>] EXTERNAL_SYMBOL]);
8912 -- EXTERNAL_SYMBOL ::=
8914 -- | static_string_EXPRESSION
8916 when Pragma_Import_Object => Import_Object : declare
8917 Args : Args_List (1 .. 3);
8918 Names : constant Name_List (1 .. 3) := (
8923 Internal : Node_Id renames Args (1);
8924 External : Node_Id renames Args (2);
8925 Size : Node_Id renames Args (3);
8929 Gather_Associations (Names, Args);
8930 Process_Extended_Import_Export_Object_Pragma (
8931 Arg_Internal => Internal,
8932 Arg_External => External,
8936 ----------------------
8937 -- Import_Procedure --
8938 ----------------------
8940 -- pragma Import_Procedure (
8941 -- [Internal =>] LOCAL_NAME
8942 -- [, [External =>] EXTERNAL_SYMBOL]
8943 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8944 -- [, [Mechanism =>] MECHANISM]
8945 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8947 -- EXTERNAL_SYMBOL ::=
8949 -- | static_string_EXPRESSION
8951 -- PARAMETER_TYPES ::=
8953 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8955 -- TYPE_DESIGNATOR ::=
8957 -- | subtype_Name ' Access
8961 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8963 -- MECHANISM_ASSOCIATION ::=
8964 -- [formal_parameter_NAME =>] MECHANISM_NAME
8966 -- MECHANISM_NAME ::=
8969 -- | Descriptor [([Class =>] CLASS_NAME)]
8971 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8973 when Pragma_Import_Procedure => Import_Procedure : declare
8974 Args : Args_List (1 .. 5);
8975 Names : constant Name_List (1 .. 5) := (
8978 Name_Parameter_Types,
8980 Name_First_Optional_Parameter);
8982 Internal : Node_Id renames Args (1);
8983 External : Node_Id renames Args (2);
8984 Parameter_Types : Node_Id renames Args (3);
8985 Mechanism : Node_Id renames Args (4);
8986 First_Optional_Parameter : Node_Id renames Args (5);
8990 Gather_Associations (Names, Args);
8991 Process_Extended_Import_Export_Subprogram_Pragma (
8992 Arg_Internal => Internal,
8993 Arg_External => External,
8994 Arg_Parameter_Types => Parameter_Types,
8995 Arg_Mechanism => Mechanism,
8996 Arg_First_Optional_Parameter => First_Optional_Parameter);
8997 end Import_Procedure;
8999 -----------------------------
9000 -- Import_Valued_Procedure --
9001 -----------------------------
9003 -- pragma Import_Valued_Procedure (
9004 -- [Internal =>] LOCAL_NAME
9005 -- [, [External =>] EXTERNAL_SYMBOL]
9006 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9007 -- [, [Mechanism =>] MECHANISM]
9008 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9010 -- EXTERNAL_SYMBOL ::=
9012 -- | static_string_EXPRESSION
9014 -- PARAMETER_TYPES ::=
9016 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9018 -- TYPE_DESIGNATOR ::=
9020 -- | subtype_Name ' Access
9024 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9026 -- MECHANISM_ASSOCIATION ::=
9027 -- [formal_parameter_NAME =>] MECHANISM_NAME
9029 -- MECHANISM_NAME ::=
9032 -- | Descriptor [([Class =>] CLASS_NAME)]
9034 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9036 when Pragma_Import_Valued_Procedure =>
9037 Import_Valued_Procedure : declare
9038 Args : Args_List (1 .. 5);
9039 Names : constant Name_List (1 .. 5) := (
9042 Name_Parameter_Types,
9044 Name_First_Optional_Parameter);
9046 Internal : Node_Id renames Args (1);
9047 External : Node_Id renames Args (2);
9048 Parameter_Types : Node_Id renames Args (3);
9049 Mechanism : Node_Id renames Args (4);
9050 First_Optional_Parameter : Node_Id renames Args (5);
9054 Gather_Associations (Names, Args);
9055 Process_Extended_Import_Export_Subprogram_Pragma (
9056 Arg_Internal => Internal,
9057 Arg_External => External,
9058 Arg_Parameter_Types => Parameter_Types,
9059 Arg_Mechanism => Mechanism,
9060 Arg_First_Optional_Parameter => First_Optional_Parameter);
9061 end Import_Valued_Procedure;
9067 -- pragma Independent (LOCAL_NAME);
9069 when Pragma_Independent => Independent : declare
9076 Check_Ada_83_Warning;
9078 Check_No_Identifiers;
9079 Check_Arg_Count (1);
9080 Check_Arg_Is_Local_Name (Arg1);
9081 E_Id := Get_Pragma_Arg (Arg1);
9083 if Etype (E_Id) = Any_Type then
9088 D := Declaration_Node (E);
9091 -- Check duplicate before we chain ourselves!
9093 Check_Duplicate_Pragma (E);
9095 -- Check appropriate entity
9098 if Rep_Item_Too_Early (E, N)
9100 Rep_Item_Too_Late (E, N)
9104 Check_First_Subtype (Arg1);
9107 elsif K = N_Object_Declaration
9108 or else (K = N_Component_Declaration
9109 and then Original_Record_Component (E) = E)
9111 if Rep_Item_Too_Late (E, N) then
9117 ("inappropriate entity for pragma%", Arg1);
9120 Independence_Checks.Append ((N, E));
9123 ----------------------------
9124 -- Independent_Components --
9125 ----------------------------
9127 -- pragma Atomic_Components (array_LOCAL_NAME);
9129 -- This processing is shared by Volatile_Components
9131 when Pragma_Independent_Components => Independent_Components : declare
9138 Check_Ada_83_Warning;
9140 Check_No_Identifiers;
9141 Check_Arg_Count (1);
9142 Check_Arg_Is_Local_Name (Arg1);
9143 E_Id := Get_Pragma_Arg (Arg1);
9145 if Etype (E_Id) = Any_Type then
9151 -- Check duplicate before we chain ourselves!
9153 Check_Duplicate_Pragma (E);
9155 -- Check appropriate entity
9157 if Rep_Item_Too_Early (E, N)
9159 Rep_Item_Too_Late (E, N)
9164 D := Declaration_Node (E);
9167 if (K = N_Full_Type_Declaration
9168 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9170 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9171 and then Nkind (D) = N_Object_Declaration
9172 and then Nkind (Object_Definition (D)) =
9173 N_Constrained_Array_Definition)
9175 Independence_Checks.Append ((N, E));
9178 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9180 end Independent_Components;
9182 ------------------------
9183 -- Initialize_Scalars --
9184 ------------------------
9186 -- pragma Initialize_Scalars;
9188 when Pragma_Initialize_Scalars =>
9190 Check_Arg_Count (0);
9191 Check_Valid_Configuration_Pragma;
9192 Check_Restriction (No_Initialize_Scalars, N);
9194 -- Initialize_Scalars creates false positives in CodePeer,
9195 -- so ignore this pragma in this mode.
9197 if not Restriction_Active (No_Initialize_Scalars)
9198 and then not CodePeer_Mode
9200 Init_Or_Norm_Scalars := True;
9201 Initialize_Scalars := True;
9208 -- pragma Inline ( NAME {, NAME} );
9210 when Pragma_Inline =>
9212 -- Pragma is active if inlining option is active
9214 Process_Inline (Inline_Active);
9220 -- pragma Inline_Always ( NAME {, NAME} );
9222 when Pragma_Inline_Always =>
9225 -- Pragma always active unless in CodePeer mode, since this causes
9226 -- walk order issues.
9228 if not CodePeer_Mode then
9229 Process_Inline (True);
9232 --------------------
9233 -- Inline_Generic --
9234 --------------------
9236 -- pragma Inline_Generic (NAME {, NAME});
9238 when Pragma_Inline_Generic =>
9240 Process_Generic_List;
9242 ----------------------
9243 -- Inspection_Point --
9244 ----------------------
9246 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9248 when Pragma_Inspection_Point => Inspection_Point : declare
9253 if Arg_Count > 0 then
9256 Exp := Get_Pragma_Arg (Arg);
9259 if not Is_Entity_Name (Exp)
9260 or else not Is_Object (Entity (Exp))
9262 Error_Pragma_Arg ("object name required", Arg);
9269 end Inspection_Point;
9275 -- pragma Interface (
9276 -- [ Convention =>] convention_IDENTIFIER,
9277 -- [ Entity =>] local_NAME
9278 -- [, [External_Name =>] static_string_EXPRESSION ]
9279 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9281 when Pragma_Interface =>
9288 Check_At_Least_N_Arguments (2);
9289 Check_At_Most_N_Arguments (4);
9290 Process_Import_Or_Interface;
9292 -- In Ada 2005, the permission to use Interface (a reserved word)
9293 -- as a pragma name is considered an obsolescent feature.
9295 if Ada_Version >= Ada_2005 then
9297 (No_Obsolescent_Features, Pragma_Identifier (N));
9300 --------------------
9301 -- Interface_Name --
9302 --------------------
9304 -- pragma Interface_Name (
9305 -- [ Entity =>] local_NAME
9306 -- [,[External_Name =>] static_string_EXPRESSION ]
9307 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9309 when Pragma_Interface_Name => Interface_Name : declare
9318 ((Name_Entity, Name_External_Name, Name_Link_Name));
9319 Check_At_Least_N_Arguments (2);
9320 Check_At_Most_N_Arguments (3);
9321 Id := Get_Pragma_Arg (Arg1);
9324 if not Is_Entity_Name (Id) then
9326 ("first argument for pragma% must be entity name", Arg1);
9327 elsif Etype (Id) = Any_Type then
9330 Def_Id := Entity (Id);
9333 -- Special DEC-compatible processing for the object case, forces
9334 -- object to be imported.
9336 if Ekind (Def_Id) = E_Variable then
9337 Kill_Size_Check_Code (Def_Id);
9338 Note_Possible_Modification (Id, Sure => False);
9340 -- Initialization is not allowed for imported variable
9342 if Present (Expression (Parent (Def_Id)))
9343 and then Comes_From_Source (Expression (Parent (Def_Id)))
9345 Error_Msg_Sloc := Sloc (Def_Id);
9347 ("no initialization allowed for declaration of& #",
9351 -- For compatibility, support VADS usage of providing both
9352 -- pragmas Interface and Interface_Name to obtain the effect
9353 -- of a single Import pragma.
9355 if Is_Imported (Def_Id)
9356 and then Present (First_Rep_Item (Def_Id))
9357 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9359 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9363 Set_Imported (Def_Id);
9366 Set_Is_Public (Def_Id);
9367 Process_Interface_Name (Def_Id, Arg2, Arg3);
9370 -- Otherwise must be subprogram
9372 elsif not Is_Subprogram (Def_Id) then
9374 ("argument of pragma% is not subprogram", Arg1);
9377 Check_At_Most_N_Arguments (3);
9381 -- Loop through homonyms
9384 Def_Id := Get_Base_Subprogram (Hom_Id);
9386 if Is_Imported (Def_Id) then
9387 Process_Interface_Name (Def_Id, Arg2, Arg3);
9391 exit when From_Aspect_Specification (N);
9392 Hom_Id := Homonym (Hom_Id);
9394 exit when No (Hom_Id)
9395 or else Scope (Hom_Id) /= Current_Scope;
9400 ("argument of pragma% is not imported subprogram",
9406 -----------------------
9407 -- Interrupt_Handler --
9408 -----------------------
9410 -- pragma Interrupt_Handler (handler_NAME);
9412 when Pragma_Interrupt_Handler =>
9413 Check_Ada_83_Warning;
9414 Check_Arg_Count (1);
9415 Check_No_Identifiers;
9417 if No_Run_Time_Mode then
9418 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9420 Check_Interrupt_Or_Attach_Handler;
9421 Process_Interrupt_Or_Attach_Handler;
9424 ------------------------
9425 -- Interrupt_Priority --
9426 ------------------------
9428 -- pragma Interrupt_Priority [(EXPRESSION)];
9430 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9431 P : constant Node_Id := Parent (N);
9435 Check_Ada_83_Warning;
9437 if Arg_Count /= 0 then
9438 Arg := Get_Pragma_Arg (Arg1);
9439 Check_Arg_Count (1);
9440 Check_No_Identifiers;
9442 -- The expression must be analyzed in the special manner
9443 -- described in "Handling of Default and Per-Object
9444 -- Expressions" in sem.ads.
9446 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9449 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9453 elsif Has_Pragma_Priority (P) then
9454 Error_Pragma ("duplicate pragma% not allowed");
9457 Set_Has_Pragma_Priority (P, True);
9458 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9460 end Interrupt_Priority;
9462 ---------------------
9463 -- Interrupt_State --
9464 ---------------------
9466 -- pragma Interrupt_State (
9467 -- [Name =>] INTERRUPT_ID,
9468 -- [State =>] INTERRUPT_STATE);
9470 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9471 -- INTERRUPT_STATE => System | Runtime | User
9473 -- Note: if the interrupt id is given as an identifier, then it must
9474 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9475 -- given as a static integer expression which must be in the range of
9476 -- Ada.Interrupts.Interrupt_ID.
9478 when Pragma_Interrupt_State => Interrupt_State : declare
9480 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9481 -- This is the entity Ada.Interrupts.Interrupt_ID;
9483 State_Type : Character;
9484 -- Set to 's'/'r'/'u' for System/Runtime/User
9487 -- Index to entry in Interrupt_States table
9490 -- Value of interrupt
9492 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9493 -- The first argument to the pragma
9495 Int_Ent : Entity_Id;
9496 -- Interrupt entity in Ada.Interrupts.Names
9500 Check_Arg_Order ((Name_Name, Name_State));
9501 Check_Arg_Count (2);
9503 Check_Optional_Identifier (Arg1, Name_Name);
9504 Check_Optional_Identifier (Arg2, Name_State);
9505 Check_Arg_Is_Identifier (Arg2);
9507 -- First argument is identifier
9509 if Nkind (Arg1X) = N_Identifier then
9511 -- Search list of names in Ada.Interrupts.Names
9513 Int_Ent := First_Entity (RTE (RE_Names));
9515 if No (Int_Ent) then
9516 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9518 elsif Chars (Int_Ent) = Chars (Arg1X) then
9519 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9523 Next_Entity (Int_Ent);
9526 -- First argument is not an identifier, so it must be a static
9527 -- expression of type Ada.Interrupts.Interrupt_ID.
9530 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9531 Int_Val := Expr_Value (Arg1X);
9533 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9535 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9538 ("value not in range of type " &
9539 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9545 case Chars (Get_Pragma_Arg (Arg2)) is
9546 when Name_Runtime => State_Type := 'r';
9547 when Name_System => State_Type := 's';
9548 when Name_User => State_Type := 'u';
9551 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9554 -- Check if entry is already stored
9556 IST_Num := Interrupt_States.First;
9558 -- If entry not found, add it
9560 if IST_Num > Interrupt_States.Last then
9561 Interrupt_States.Append
9562 ((Interrupt_Number => UI_To_Int (Int_Val),
9563 Interrupt_State => State_Type,
9564 Pragma_Loc => Loc));
9567 -- Case of entry for the same entry
9569 elsif Int_Val = Interrupt_States.Table (IST_Num).
9572 -- If state matches, done, no need to make redundant entry
9575 State_Type = Interrupt_States.Table (IST_Num).
9578 -- Otherwise if state does not match, error
9581 Interrupt_States.Table (IST_Num).Pragma_Loc;
9583 ("state conflicts with that given #", Arg2);
9587 IST_Num := IST_Num + 1;
9589 end Interrupt_State;
9596 -- ([Entity =>] type_LOCAL_NAME,
9597 -- [Check =>] EXPRESSION
9598 -- [,[Message =>] String_Expression]);
9600 when Pragma_Invariant => Invariant : declare
9605 pragma Unreferenced (Discard);
9609 Check_At_Least_N_Arguments (2);
9610 Check_At_Most_N_Arguments (3);
9611 Check_Optional_Identifier (Arg1, Name_Entity);
9612 Check_Optional_Identifier (Arg2, Name_Check);
9614 if Arg_Count = 3 then
9615 Check_Optional_Identifier (Arg3, Name_Message);
9616 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9619 Check_Arg_Is_Local_Name (Arg1);
9621 Type_Id := Get_Pragma_Arg (Arg1);
9622 Find_Type (Type_Id);
9623 Typ := Entity (Type_Id);
9625 if Typ = Any_Type then
9628 elsif not Ekind_In (Typ, E_Private_Type,
9629 E_Record_Type_With_Private,
9630 E_Limited_Private_Type)
9633 ("pragma% only allowed for private type", Arg1);
9636 -- Note that the type has at least one invariant, and also that
9637 -- it has inheritable invariants if we have Invariant'Class.
9639 Set_Has_Invariants (Typ);
9641 if Class_Present (N) then
9642 Set_Has_Inheritable_Invariants (Typ);
9645 -- The remaining processing is simply to link the pragma on to
9646 -- the rep item chain, for processing when the type is frozen.
9647 -- This is accomplished by a call to Rep_Item_Too_Late.
9649 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9652 ----------------------
9653 -- Java_Constructor --
9654 ----------------------
9656 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9658 -- Also handles pragma CIL_Constructor
9660 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9661 Java_Constructor : declare
9662 Convention : Convention_Id;
9666 This_Formal : Entity_Id;
9670 Check_Arg_Count (1);
9671 Check_Optional_Identifier (Arg1, Name_Entity);
9672 Check_Arg_Is_Local_Name (Arg1);
9674 Id := Get_Pragma_Arg (Arg1);
9675 Find_Program_Unit_Name (Id);
9677 -- If we did not find the name, we are done
9679 if Etype (Id) = Any_Type then
9683 -- Check wrong use of pragma in wrong VM target
9685 if VM_Target = No_VM then
9688 elsif VM_Target = CLI_Target
9689 and then Prag_Id = Pragma_Java_Constructor
9691 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9693 elsif VM_Target = JVM_Target
9694 and then Prag_Id = Pragma_CIL_Constructor
9696 Error_Pragma ("must use pragma 'Java_'Constructor");
9700 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9701 when Pragma_Java_Constructor => Convention := Convention_Java;
9702 when others => null;
9705 Hom_Id := Entity (Id);
9707 -- Loop through homonyms
9710 Def_Id := Get_Base_Subprogram (Hom_Id);
9712 -- The constructor is required to be a function
9714 if Ekind (Def_Id) /= E_Function then
9715 if VM_Target = JVM_Target then
9717 ("pragma% requires function returning a " &
9718 "'Java access type", Def_Id);
9721 ("pragma% requires function returning a " &
9722 "'C'I'L access type", Def_Id);
9726 -- Check arguments: For tagged type the first formal must be
9727 -- named "this" and its type must be a named access type
9728 -- designating a class-wide tagged type that has convention
9729 -- CIL/Java. The first formal must also have a null default
9730 -- value. For example:
9732 -- type Typ is tagged ...
9733 -- type Ref is access all Typ;
9734 -- pragma Convention (CIL, Typ);
9736 -- function New_Typ (This : Ref) return Ref;
9737 -- function New_Typ (This : Ref; I : Integer) return Ref;
9738 -- pragma Cil_Constructor (New_Typ);
9740 -- Reason: The first formal must NOT be a primitive of the
9743 -- This rule also applies to constructors of delegates used
9744 -- to interface with standard target libraries. For example:
9746 -- type Delegate is access procedure ...
9747 -- pragma Import (CIL, Delegate, ...);
9749 -- function new_Delegate
9750 -- (This : Delegate := null; ... ) return Delegate;
9752 -- For value-types this rule does not apply.
9754 if not Is_Value_Type (Etype (Def_Id)) then
9755 if No (First_Formal (Def_Id)) then
9756 Error_Msg_Name_1 := Pname;
9757 Error_Msg_N ("% function must have parameters", Def_Id);
9761 -- In the JRE library we have several occurrences in which
9762 -- the "this" parameter is not the first formal.
9764 This_Formal := First_Formal (Def_Id);
9766 -- In the JRE library we have several occurrences in which
9767 -- the "this" parameter is not the first formal. Search for
9770 if VM_Target = JVM_Target then
9771 while Present (This_Formal)
9772 and then Get_Name_String (Chars (This_Formal)) /= "this"
9774 Next_Formal (This_Formal);
9777 if No (This_Formal) then
9778 This_Formal := First_Formal (Def_Id);
9782 -- Warning: The first parameter should be named "this".
9783 -- We temporarily allow it because we have the following
9784 -- case in the Java runtime (file s-osinte.ads) ???
9786 -- function new_Thread
9787 -- (Self_Id : System.Address) return Thread_Id;
9788 -- pragma Java_Constructor (new_Thread);
9790 if VM_Target = JVM_Target
9791 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9793 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9797 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9798 Error_Msg_Name_1 := Pname;
9800 ("first formal of % function must be named `this`",
9801 Parent (This_Formal));
9803 elsif not Is_Access_Type (Etype (This_Formal)) then
9804 Error_Msg_Name_1 := Pname;
9806 ("first formal of % function must be an access type",
9807 Parameter_Type (Parent (This_Formal)));
9809 -- For delegates the type of the first formal must be a
9810 -- named access-to-subprogram type (see previous example)
9812 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9813 and then Ekind (Etype (This_Formal))
9814 /= E_Access_Subprogram_Type
9816 Error_Msg_Name_1 := Pname;
9818 ("first formal of % function must be a named access" &
9819 " to subprogram type",
9820 Parameter_Type (Parent (This_Formal)));
9822 -- Warning: We should reject anonymous access types because
9823 -- the constructor must not be handled as a primitive of the
9824 -- tagged type. We temporarily allow it because this profile
9825 -- is currently generated by cil2ada???
9827 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9828 and then not Ekind_In (Etype (This_Formal),
9830 E_General_Access_Type,
9831 E_Anonymous_Access_Type)
9833 Error_Msg_Name_1 := Pname;
9835 ("first formal of % function must be a named access" &
9837 Parameter_Type (Parent (This_Formal)));
9839 elsif Atree.Convention
9840 (Designated_Type (Etype (This_Formal))) /= Convention
9842 Error_Msg_Name_1 := Pname;
9844 if Convention = Convention_Java then
9846 ("pragma% requires convention 'Cil in designated" &
9848 Parameter_Type (Parent (This_Formal)));
9851 ("pragma% requires convention 'Java in designated" &
9853 Parameter_Type (Parent (This_Formal)));
9856 elsif No (Expression (Parent (This_Formal)))
9857 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9859 Error_Msg_Name_1 := Pname;
9861 ("pragma% requires first formal with default `null`",
9862 Parameter_Type (Parent (This_Formal)));
9866 -- Check result type: the constructor must be a function
9868 -- * a value type (only allowed in the CIL compiler)
9869 -- * an access-to-subprogram type with convention Java/CIL
9870 -- * an access-type designating a type that has convention
9873 if Is_Value_Type (Etype (Def_Id)) then
9876 -- Access-to-subprogram type with convention Java/CIL
9878 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9879 if Atree.Convention (Etype (Def_Id)) /= Convention then
9880 if Convention = Convention_Java then
9882 ("pragma% requires function returning a " &
9883 "'Java access type", Arg1);
9885 pragma Assert (Convention = Convention_CIL);
9887 ("pragma% requires function returning a " &
9888 "'C'I'L access type", Arg1);
9892 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9893 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9894 E_General_Access_Type)
9897 (Designated_Type (Etype (Def_Id))) /= Convention
9899 Error_Msg_Name_1 := Pname;
9901 if Convention = Convention_Java then
9903 ("pragma% requires function returning a named" &
9904 "'Java access type", Arg1);
9907 ("pragma% requires function returning a named" &
9908 "'C'I'L access type", Arg1);
9913 Set_Is_Constructor (Def_Id);
9914 Set_Convention (Def_Id, Convention);
9915 Set_Is_Imported (Def_Id);
9917 exit when From_Aspect_Specification (N);
9918 Hom_Id := Homonym (Hom_Id);
9920 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9922 end Java_Constructor;
9924 ----------------------
9925 -- Java_Interface --
9926 ----------------------
9928 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9930 when Pragma_Java_Interface => Java_Interface : declare
9936 Check_Arg_Count (1);
9937 Check_Optional_Identifier (Arg1, Name_Entity);
9938 Check_Arg_Is_Local_Name (Arg1);
9940 Arg := Get_Pragma_Arg (Arg1);
9943 if Etype (Arg) = Any_Type then
9947 if not Is_Entity_Name (Arg)
9948 or else not Is_Type (Entity (Arg))
9950 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9953 Typ := Underlying_Type (Entity (Arg));
9955 -- For now simply check some of the semantic constraints on the
9956 -- type. This currently leaves out some restrictions on interface
9957 -- types, namely that the parent type must be java.lang.Object.Typ
9958 -- and that all primitives of the type should be declared
9961 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9962 Error_Pragma_Arg ("pragma% requires an abstract "
9963 & "tagged type", Arg1);
9965 elsif not Has_Discriminants (Typ)
9966 or else Ekind (Etype (First_Discriminant (Typ)))
9967 /= E_Anonymous_Access_Type
9969 not Is_Class_Wide_Type
9970 (Designated_Type (Etype (First_Discriminant (Typ))))
9973 ("type must have a class-wide access discriminant", Arg1);
9981 -- pragma Keep_Names ([On => ] local_NAME);
9983 when Pragma_Keep_Names => Keep_Names : declare
9988 Check_Arg_Count (1);
9989 Check_Optional_Identifier (Arg1, Name_On);
9990 Check_Arg_Is_Local_Name (Arg1);
9992 Arg := Get_Pragma_Arg (Arg1);
9995 if Etype (Arg) = Any_Type then
9999 if not Is_Entity_Name (Arg)
10000 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10003 ("pragma% requires a local enumeration type", Arg1);
10006 Set_Discard_Names (Entity (Arg), False);
10013 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10015 when Pragma_License =>
10017 Check_Arg_Count (1);
10018 Check_No_Identifiers;
10019 Check_Valid_Configuration_Pragma;
10020 Check_Arg_Is_Identifier (Arg1);
10023 Sind : constant Source_File_Index :=
10024 Source_Index (Current_Sem_Unit);
10027 case Chars (Get_Pragma_Arg (Arg1)) is
10029 Set_License (Sind, GPL);
10031 when Name_Modified_GPL =>
10032 Set_License (Sind, Modified_GPL);
10034 when Name_Restricted =>
10035 Set_License (Sind, Restricted);
10037 when Name_Unrestricted =>
10038 Set_License (Sind, Unrestricted);
10041 Error_Pragma_Arg ("invalid license name", Arg1);
10049 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10051 when Pragma_Link_With => Link_With : declare
10057 if Operating_Mode = Generate_Code
10058 and then In_Extended_Main_Source_Unit (N)
10060 Check_At_Least_N_Arguments (1);
10061 Check_No_Identifiers;
10062 Check_Is_In_Decl_Part_Or_Package_Spec;
10063 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10067 while Present (Arg) loop
10068 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10070 -- Store argument, converting sequences of spaces to a
10071 -- single null character (this is one of the differences
10072 -- in processing between Link_With and Linker_Options).
10074 Arg_Store : declare
10075 C : constant Char_Code := Get_Char_Code (' ');
10076 S : constant String_Id :=
10077 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10078 L : constant Nat := String_Length (S);
10081 procedure Skip_Spaces;
10082 -- Advance F past any spaces
10088 procedure Skip_Spaces is
10090 while F <= L and then Get_String_Char (S, F) = C loop
10095 -- Start of processing for Arg_Store
10098 Skip_Spaces; -- skip leading spaces
10100 -- Loop through characters, changing any embedded
10101 -- sequence of spaces to a single null character (this
10102 -- is how Link_With/Linker_Options differ)
10105 if Get_String_Char (S, F) = C then
10108 Store_String_Char (ASCII.NUL);
10111 Store_String_Char (Get_String_Char (S, F));
10119 if Present (Arg) then
10120 Store_String_Char (ASCII.NUL);
10124 Store_Linker_Option_String (End_String);
10132 -- pragma Linker_Alias (
10133 -- [Entity =>] LOCAL_NAME
10134 -- [Target =>] static_string_EXPRESSION);
10136 when Pragma_Linker_Alias =>
10138 Check_Arg_Order ((Name_Entity, Name_Target));
10139 Check_Arg_Count (2);
10140 Check_Optional_Identifier (Arg1, Name_Entity);
10141 Check_Optional_Identifier (Arg2, Name_Target);
10142 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10143 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10145 -- The only processing required is to link this item on to the
10146 -- list of rep items for the given entity. This is accomplished
10147 -- by the call to Rep_Item_Too_Late (when no error is detected
10148 -- and False is returned).
10150 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10153 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10156 ------------------------
10157 -- Linker_Constructor --
10158 ------------------------
10160 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10162 -- Code is shared with Linker_Destructor
10164 -----------------------
10165 -- Linker_Destructor --
10166 -----------------------
10168 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10170 when Pragma_Linker_Constructor |
10171 Pragma_Linker_Destructor =>
10172 Linker_Constructor : declare
10178 Check_Arg_Count (1);
10179 Check_No_Identifiers;
10180 Check_Arg_Is_Local_Name (Arg1);
10181 Arg1_X := Get_Pragma_Arg (Arg1);
10183 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10185 if not Is_Library_Level_Entity (Proc) then
10187 ("argument for pragma% must be library level entity", Arg1);
10190 -- The only processing required is to link this item on to the
10191 -- list of rep items for the given entity. This is accomplished
10192 -- by the call to Rep_Item_Too_Late (when no error is detected
10193 -- and False is returned).
10195 if Rep_Item_Too_Late (Proc, N) then
10198 Set_Has_Gigi_Rep_Item (Proc);
10200 end Linker_Constructor;
10202 --------------------
10203 -- Linker_Options --
10204 --------------------
10206 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10208 when Pragma_Linker_Options => Linker_Options : declare
10212 Check_Ada_83_Warning;
10213 Check_No_Identifiers;
10214 Check_Arg_Count (1);
10215 Check_Is_In_Decl_Part_Or_Package_Spec;
10216 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10217 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10220 while Present (Arg) loop
10221 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10222 Store_String_Char (ASCII.NUL);
10224 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10228 if Operating_Mode = Generate_Code
10229 and then In_Extended_Main_Source_Unit (N)
10231 Store_Linker_Option_String (End_String);
10233 end Linker_Options;
10235 --------------------
10236 -- Linker_Section --
10237 --------------------
10239 -- pragma Linker_Section (
10240 -- [Entity =>] LOCAL_NAME
10241 -- [Section =>] static_string_EXPRESSION);
10243 when Pragma_Linker_Section =>
10245 Check_Arg_Order ((Name_Entity, Name_Section));
10246 Check_Arg_Count (2);
10247 Check_Optional_Identifier (Arg1, Name_Entity);
10248 Check_Optional_Identifier (Arg2, Name_Section);
10249 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10250 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10252 -- This pragma applies only to objects
10254 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10255 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10258 -- The only processing required is to link this item on to the
10259 -- list of rep items for the given entity. This is accomplished
10260 -- by the call to Rep_Item_Too_Late (when no error is detected
10261 -- and False is returned).
10263 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10266 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10273 -- pragma List (On | Off)
10275 -- There is nothing to do here, since we did all the processing for
10276 -- this pragma in Par.Prag (so that it works properly even in syntax
10279 when Pragma_List =>
10282 --------------------
10283 -- Locking_Policy --
10284 --------------------
10286 -- pragma Locking_Policy (policy_IDENTIFIER);
10288 when Pragma_Locking_Policy => declare
10292 Check_Ada_83_Warning;
10293 Check_Arg_Count (1);
10294 Check_No_Identifiers;
10295 Check_Arg_Is_Locking_Policy (Arg1);
10296 Check_Valid_Configuration_Pragma;
10297 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10298 LP := Fold_Upper (Name_Buffer (1));
10300 if Locking_Policy /= ' '
10301 and then Locking_Policy /= LP
10303 Error_Msg_Sloc := Locking_Policy_Sloc;
10304 Error_Pragma ("locking policy incompatible with policy#");
10306 -- Set new policy, but always preserve System_Location since we
10307 -- like the error message with the run time name.
10310 Locking_Policy := LP;
10312 if Locking_Policy_Sloc /= System_Location then
10313 Locking_Policy_Sloc := Loc;
10322 -- pragma Long_Float (D_Float | G_Float);
10324 when Pragma_Long_Float =>
10326 Check_Valid_Configuration_Pragma;
10327 Check_Arg_Count (1);
10328 Check_No_Identifier (Arg1);
10329 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10331 if not OpenVMS_On_Target then
10332 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10337 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10338 if Opt.Float_Format_Long = 'G' then
10339 Error_Pragma ("G_Float previously specified");
10342 Opt.Float_Format_Long := 'D';
10344 -- G_Float case (this is the default, does not need overriding)
10347 if Opt.Float_Format_Long = 'D' then
10348 Error_Pragma ("D_Float previously specified");
10351 Opt.Float_Format_Long := 'G';
10354 Set_Standard_Fpt_Formats;
10356 -----------------------
10357 -- Machine_Attribute --
10358 -----------------------
10360 -- pragma Machine_Attribute (
10361 -- [Entity =>] LOCAL_NAME,
10362 -- [Attribute_Name =>] static_string_EXPRESSION
10363 -- [, [Info =>] static_EXPRESSION] );
10365 when Pragma_Machine_Attribute => Machine_Attribute : declare
10366 Def_Id : Entity_Id;
10370 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10372 if Arg_Count = 3 then
10373 Check_Optional_Identifier (Arg3, Name_Info);
10374 Check_Arg_Is_Static_Expression (Arg3);
10376 Check_Arg_Count (2);
10379 Check_Optional_Identifier (Arg1, Name_Entity);
10380 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10381 Check_Arg_Is_Local_Name (Arg1);
10382 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10383 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10385 if Is_Access_Type (Def_Id) then
10386 Def_Id := Designated_Type (Def_Id);
10389 if Rep_Item_Too_Early (Def_Id, N) then
10393 Def_Id := Underlying_Type (Def_Id);
10395 -- The only processing required is to link this item on to the
10396 -- list of rep items for the given entity. This is accomplished
10397 -- by the call to Rep_Item_Too_Late (when no error is detected
10398 -- and False is returned).
10400 if Rep_Item_Too_Late (Def_Id, N) then
10403 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10405 end Machine_Attribute;
10412 -- (MAIN_OPTION [, MAIN_OPTION]);
10415 -- [STACK_SIZE =>] static_integer_EXPRESSION
10416 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10417 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10419 when Pragma_Main => Main : declare
10420 Args : Args_List (1 .. 3);
10421 Names : constant Name_List (1 .. 3) := (
10423 Name_Task_Stack_Size_Default,
10424 Name_Time_Slicing_Enabled);
10430 Gather_Associations (Names, Args);
10432 for J in 1 .. 2 loop
10433 if Present (Args (J)) then
10434 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10438 if Present (Args (3)) then
10439 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10443 while Present (Nod) loop
10444 if Nkind (Nod) = N_Pragma
10445 and then Pragma_Name (Nod) = Name_Main
10447 Error_Msg_Name_1 := Pname;
10448 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10459 -- pragma Main_Storage
10460 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10462 -- MAIN_STORAGE_OPTION ::=
10463 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10464 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10466 when Pragma_Main_Storage => Main_Storage : declare
10467 Args : Args_List (1 .. 2);
10468 Names : constant Name_List (1 .. 2) := (
10469 Name_Working_Storage,
10476 Gather_Associations (Names, Args);
10478 for J in 1 .. 2 loop
10479 if Present (Args (J)) then
10480 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10484 Check_In_Main_Program;
10487 while Present (Nod) loop
10488 if Nkind (Nod) = N_Pragma
10489 and then Pragma_Name (Nod) = Name_Main_Storage
10491 Error_Msg_Name_1 := Pname;
10492 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10503 -- pragma Memory_Size (NUMERIC_LITERAL)
10505 when Pragma_Memory_Size =>
10508 -- Memory size is simply ignored
10510 Check_No_Identifiers;
10511 Check_Arg_Count (1);
10512 Check_Arg_Is_Integer_Literal (Arg1);
10520 -- The only correct use of this pragma is on its own in a file, in
10521 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10522 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10523 -- check for a file containing nothing but a No_Body pragma). If we
10524 -- attempt to process it during normal semantics processing, it means
10525 -- it was misplaced.
10527 when Pragma_No_Body =>
10535 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10537 when Pragma_No_Return => No_Return : declare
10545 Check_At_Least_N_Arguments (1);
10547 -- Loop through arguments of pragma
10550 while Present (Arg) loop
10551 Check_Arg_Is_Local_Name (Arg);
10552 Id := Get_Pragma_Arg (Arg);
10555 if not Is_Entity_Name (Id) then
10556 Error_Pragma_Arg ("entity name required", Arg);
10559 if Etype (Id) = Any_Type then
10563 -- Loop to find matching procedures
10568 and then Scope (E) = Current_Scope
10570 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10573 -- Set flag on any alias as well
10575 if Is_Overloadable (E) and then Present (Alias (E)) then
10576 Set_No_Return (Alias (E));
10582 exit when From_Aspect_Specification (N);
10587 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10598 -- pragma No_Run_Time;
10600 -- Note: this pragma is retained for backwards compatibility. See
10601 -- body of Rtsfind for full details on its handling.
10603 when Pragma_No_Run_Time =>
10605 Check_Valid_Configuration_Pragma;
10606 Check_Arg_Count (0);
10608 No_Run_Time_Mode := True;
10609 Configurable_Run_Time_Mode := True;
10611 -- Set Duration to 32 bits if word size is 32
10613 if Ttypes.System_Word_Size = 32 then
10614 Duration_32_Bits_On_Target := True;
10617 -- Set appropriate restrictions
10619 Set_Restriction (No_Finalization, N);
10620 Set_Restriction (No_Exception_Handlers, N);
10621 Set_Restriction (Max_Tasks, N, 0);
10622 Set_Restriction (No_Tasking, N);
10624 ------------------------
10625 -- No_Strict_Aliasing --
10626 ------------------------
10628 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10630 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10635 Check_At_Most_N_Arguments (1);
10637 if Arg_Count = 0 then
10638 Check_Valid_Configuration_Pragma;
10639 Opt.No_Strict_Aliasing := True;
10642 Check_Optional_Identifier (Arg2, Name_Entity);
10643 Check_Arg_Is_Local_Name (Arg1);
10644 E_Id := Entity (Get_Pragma_Arg (Arg1));
10646 if E_Id = Any_Type then
10648 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10649 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10652 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10654 end No_Strict_Aliasing;
10656 -----------------------
10657 -- Normalize_Scalars --
10658 -----------------------
10660 -- pragma Normalize_Scalars;
10662 when Pragma_Normalize_Scalars =>
10663 Check_Ada_83_Warning;
10664 Check_Arg_Count (0);
10665 Check_Valid_Configuration_Pragma;
10667 -- Normalize_Scalars creates false positives in CodePeer, so
10668 -- ignore this pragma in this mode.
10670 if not CodePeer_Mode then
10671 Normalize_Scalars := True;
10672 Init_Or_Norm_Scalars := True;
10679 -- pragma Obsolescent;
10681 -- pragma Obsolescent (
10682 -- [Message =>] static_string_EXPRESSION
10683 -- [,[Version =>] Ada_05]]);
10685 -- pragma Obsolescent (
10686 -- [Entity =>] NAME
10687 -- [,[Message =>] static_string_EXPRESSION
10688 -- [,[Version =>] Ada_05]] );
10690 when Pragma_Obsolescent => Obsolescent : declare
10694 procedure Set_Obsolescent (E : Entity_Id);
10695 -- Given an entity Ent, mark it as obsolescent if appropriate
10697 ---------------------
10698 -- Set_Obsolescent --
10699 ---------------------
10701 procedure Set_Obsolescent (E : Entity_Id) is
10710 -- Entity name was given
10712 if Present (Ename) then
10714 -- If entity name matches, we are fine. Save entity in
10715 -- pragma argument, for ASIS use.
10717 if Chars (Ename) = Chars (Ent) then
10718 Set_Entity (Ename, Ent);
10719 Generate_Reference (Ent, Ename);
10721 -- If entity name does not match, only possibility is an
10722 -- enumeration literal from an enumeration type declaration.
10724 elsif Ekind (Ent) /= E_Enumeration_Type then
10726 ("pragma % entity name does not match declaration");
10729 Ent := First_Literal (E);
10733 ("pragma % entity name does not match any " &
10734 "enumeration literal");
10736 elsif Chars (Ent) = Chars (Ename) then
10737 Set_Entity (Ename, Ent);
10738 Generate_Reference (Ent, Ename);
10742 Ent := Next_Literal (Ent);
10748 -- Ent points to entity to be marked
10750 if Arg_Count >= 1 then
10752 -- Deal with static string argument
10754 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10755 S := Strval (Get_Pragma_Arg (Arg1));
10757 for J in 1 .. String_Length (S) loop
10758 if not In_Character_Range (Get_String_Char (S, J)) then
10760 ("pragma% argument does not allow wide characters",
10765 Obsolescent_Warnings.Append
10766 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10768 -- Check for Ada_05 parameter
10770 if Arg_Count /= 1 then
10771 Check_Arg_Count (2);
10774 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10777 Check_Arg_Is_Identifier (Argx);
10779 if Chars (Argx) /= Name_Ada_05 then
10780 Error_Msg_Name_2 := Name_Ada_05;
10782 ("only allowed argument for pragma% is %", Argx);
10785 if Ada_Version_Explicit < Ada_2005
10786 or else not Warn_On_Ada_2005_Compatibility
10794 -- Set flag if pragma active
10797 Set_Is_Obsolescent (Ent);
10801 end Set_Obsolescent;
10803 -- Start of processing for pragma Obsolescent
10808 Check_At_Most_N_Arguments (3);
10810 -- See if first argument specifies an entity name
10814 (Chars (Arg1) = Name_Entity
10816 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10818 N_Operator_Symbol))
10820 Ename := Get_Pragma_Arg (Arg1);
10822 -- Eliminate first argument, so we can share processing
10826 Arg_Count := Arg_Count - 1;
10828 -- No Entity name argument given
10834 if Arg_Count >= 1 then
10835 Check_Optional_Identifier (Arg1, Name_Message);
10837 if Arg_Count = 2 then
10838 Check_Optional_Identifier (Arg2, Name_Version);
10842 -- Get immediately preceding declaration
10845 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10849 -- Cases where we do not follow anything other than another pragma
10853 -- First case: library level compilation unit declaration with
10854 -- the pragma immediately following the declaration.
10856 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10858 (Defining_Entity (Unit (Parent (Parent (N)))));
10861 -- Case 2: library unit placement for package
10865 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10867 if Is_Package_Or_Generic_Package (Ent) then
10868 Set_Obsolescent (Ent);
10874 -- Cases where we must follow a declaration
10877 if Nkind (Decl) not in N_Declaration
10878 and then Nkind (Decl) not in N_Later_Decl_Item
10879 and then Nkind (Decl) not in N_Generic_Declaration
10880 and then Nkind (Decl) not in N_Renaming_Declaration
10883 ("pragma% misplaced, "
10884 & "must immediately follow a declaration");
10887 Set_Obsolescent (Defining_Entity (Decl));
10897 -- pragma Optimize (Time | Space | Off);
10899 -- The actual check for optimize is done in Gigi. Note that this
10900 -- pragma does not actually change the optimization setting, it
10901 -- simply checks that it is consistent with the pragma.
10903 when Pragma_Optimize =>
10904 Check_No_Identifiers;
10905 Check_Arg_Count (1);
10906 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10908 ------------------------
10909 -- Optimize_Alignment --
10910 ------------------------
10912 -- pragma Optimize_Alignment (Time | Space | Off);
10914 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10916 Check_No_Identifiers;
10917 Check_Arg_Count (1);
10918 Check_Valid_Configuration_Pragma;
10921 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10925 Opt.Optimize_Alignment := 'T';
10927 Opt.Optimize_Alignment := 'S';
10929 Opt.Optimize_Alignment := 'O';
10931 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10935 -- Set indication that mode is set locally. If we are in fact in a
10936 -- configuration pragma file, this setting is harmless since the
10937 -- switch will get reset anyway at the start of each unit.
10939 Optimize_Alignment_Local := True;
10940 end Optimize_Alignment;
10946 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10948 when Pragma_Ordered => Ordered : declare
10949 Assoc : constant Node_Id := Arg1;
10955 Check_No_Identifiers;
10956 Check_Arg_Count (1);
10957 Check_Arg_Is_Local_Name (Arg1);
10959 Type_Id := Get_Pragma_Arg (Assoc);
10960 Find_Type (Type_Id);
10961 Typ := Entity (Type_Id);
10963 if Typ = Any_Type then
10966 Typ := Underlying_Type (Typ);
10969 if not Is_Enumeration_Type (Typ) then
10970 Error_Pragma ("pragma% must specify enumeration type");
10973 Check_First_Subtype (Arg1);
10974 Set_Has_Pragma_Ordered (Base_Type (Typ));
10981 -- pragma Pack (first_subtype_LOCAL_NAME);
10983 when Pragma_Pack => Pack : declare
10984 Assoc : constant Node_Id := Arg1;
10988 Ignore : Boolean := False;
10991 Check_No_Identifiers;
10992 Check_Arg_Count (1);
10993 Check_Arg_Is_Local_Name (Arg1);
10995 Type_Id := Get_Pragma_Arg (Assoc);
10996 Find_Type (Type_Id);
10997 Typ := Entity (Type_Id);
11000 or else Rep_Item_Too_Early (Typ, N)
11004 Typ := Underlying_Type (Typ);
11007 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11008 Error_Pragma ("pragma% must specify array or record type");
11011 Check_First_Subtype (Arg1);
11012 Check_Duplicate_Pragma (Typ);
11016 if Is_Array_Type (Typ) then
11017 Ctyp := Component_Type (Typ);
11019 -- Ignore pack that does nothing
11021 if Known_Static_Esize (Ctyp)
11022 and then Known_Static_RM_Size (Ctyp)
11023 and then Esize (Ctyp) = RM_Size (Ctyp)
11024 and then Addressable (Esize (Ctyp))
11029 -- Process OK pragma Pack. Note that if there is a separate
11030 -- component clause present, the Pack will be cancelled. This
11031 -- processing is in Freeze.
11033 if not Rep_Item_Too_Late (Typ, N) then
11035 -- In the context of static code analysis, we do not need
11036 -- complex front-end expansions related to pragma Pack,
11037 -- so disable handling of pragma Pack in this case.
11039 if CodePeer_Mode then
11042 -- Don't attempt any packing for VM targets. We possibly
11043 -- could deal with some cases of array bit-packing, but we
11044 -- don't bother, since this is not a typical kind of
11045 -- representation in the VM context anyway (and would not
11046 -- for example work nicely with the debugger).
11048 elsif VM_Target /= No_VM then
11049 if not GNAT_Mode then
11051 ("?pragma% ignored in this configuration");
11054 -- Normal case where we do the pack action
11058 Set_Is_Packed (Base_Type (Typ));
11059 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11062 Set_Has_Pragma_Pack (Base_Type (Typ));
11066 -- For record types, the pack is always effective
11068 else pragma Assert (Is_Record_Type (Typ));
11069 if not Rep_Item_Too_Late (Typ, N) then
11071 -- Ignore pack request with warning in VM mode (skip warning
11072 -- if we are compiling GNAT run time library).
11074 if VM_Target /= No_VM then
11075 if not GNAT_Mode then
11077 ("?pragma% ignored in this configuration");
11080 -- Normal case of pack request active
11083 Set_Is_Packed (Base_Type (Typ));
11084 Set_Has_Pragma_Pack (Base_Type (Typ));
11085 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11097 -- There is nothing to do here, since we did all the processing for
11098 -- this pragma in Par.Prag (so that it works properly even in syntax
11101 when Pragma_Page =>
11108 -- pragma Passive [(PASSIVE_FORM)];
11110 -- PASSIVE_FORM ::= Semaphore | No
11112 when Pragma_Passive =>
11115 if Nkind (Parent (N)) /= N_Task_Definition then
11116 Error_Pragma ("pragma% must be within task definition");
11119 if Arg_Count /= 0 then
11120 Check_Arg_Count (1);
11121 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11124 ----------------------------------
11125 -- Preelaborable_Initialization --
11126 ----------------------------------
11128 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11130 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11135 Check_Arg_Count (1);
11136 Check_No_Identifiers;
11137 Check_Arg_Is_Identifier (Arg1);
11138 Check_Arg_Is_Local_Name (Arg1);
11139 Check_First_Subtype (Arg1);
11140 Ent := Entity (Get_Pragma_Arg (Arg1));
11142 if not (Is_Private_Type (Ent)
11144 Is_Protected_Type (Ent)
11146 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11149 ("pragma % can only be applied to private, formal derived or "
11150 & "protected type",
11154 -- Give an error if the pragma is applied to a protected type that
11155 -- does not qualify (due to having entries, or due to components
11156 -- that do not qualify).
11158 if Is_Protected_Type (Ent)
11159 and then not Has_Preelaborable_Initialization (Ent)
11162 ("protected type & does not have preelaborable " &
11163 "initialization", Ent);
11165 -- Otherwise mark the type as definitely having preelaborable
11169 Set_Known_To_Have_Preelab_Init (Ent);
11172 if Has_Pragma_Preelab_Init (Ent)
11173 and then Warn_On_Redundant_Constructs
11175 Error_Pragma ("?duplicate pragma%!");
11177 Set_Has_Pragma_Preelab_Init (Ent);
11181 --------------------
11182 -- Persistent_BSS --
11183 --------------------
11185 -- pragma Persistent_BSS [(object_NAME)];
11187 when Pragma_Persistent_BSS => Persistent_BSS : declare
11194 Check_At_Most_N_Arguments (1);
11196 -- Case of application to specific object (one argument)
11198 if Arg_Count = 1 then
11199 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11201 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11203 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11206 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11209 Ent := Entity (Get_Pragma_Arg (Arg1));
11210 Decl := Parent (Ent);
11212 if Rep_Item_Too_Late (Ent, N) then
11216 if Present (Expression (Decl)) then
11218 ("object for pragma% cannot have initialization", Arg1);
11221 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11223 ("object type for pragma% is not potentially persistent",
11227 Check_Duplicate_Pragma (Ent);
11230 Make_Linker_Section_Pragma
11231 (Ent, Sloc (N), ".persistent.bss");
11232 Insert_After (N, Prag);
11235 -- Case of use as configuration pragma with no arguments
11238 Check_Valid_Configuration_Pragma;
11239 Persistent_BSS_Mode := True;
11241 end Persistent_BSS;
11247 -- pragma Polling (ON | OFF);
11249 when Pragma_Polling =>
11251 Check_Arg_Count (1);
11252 Check_No_Identifiers;
11253 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11254 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11256 -------------------
11257 -- Postcondition --
11258 -------------------
11260 -- pragma Postcondition ([Check =>] Boolean_Expression
11261 -- [,[Message =>] String_Expression]);
11263 when Pragma_Postcondition => Postcondition : declare
11265 pragma Warnings (Off, In_Body);
11269 Check_At_Least_N_Arguments (1);
11270 Check_At_Most_N_Arguments (2);
11271 Check_Optional_Identifier (Arg1, Name_Check);
11273 -- All we need to do here is call the common check procedure,
11274 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11276 Check_Precondition_Postcondition (In_Body);
11283 -- pragma Precondition ([Check =>] Boolean_Expression
11284 -- [,[Message =>] String_Expression]);
11286 when Pragma_Precondition => Precondition : declare
11291 Check_At_Least_N_Arguments (1);
11292 Check_At_Most_N_Arguments (2);
11293 Check_Optional_Identifier (Arg1, Name_Check);
11294 Check_Precondition_Postcondition (In_Body);
11296 -- If in spec, nothing more to do. If in body, then we convert the
11297 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11298 -- this whether or not precondition checks are enabled. That works
11299 -- fine since pragma Check will do this check, and will also
11300 -- analyze the condition itself in the proper context.
11305 Chars => Name_Check,
11306 Pragma_Argument_Associations => New_List (
11307 Make_Pragma_Argument_Association (Loc,
11308 Expression => Make_Identifier (Loc, Name_Precondition)),
11310 Make_Pragma_Argument_Association (Sloc (Arg1),
11311 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11313 if Arg_Count = 2 then
11314 Append_To (Pragma_Argument_Associations (N),
11315 Make_Pragma_Argument_Association (Sloc (Arg2),
11316 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11327 -- pragma Predicate
11328 -- ([Entity =>] type_LOCAL_NAME,
11329 -- [Check =>] EXPRESSION);
11331 when Pragma_Predicate => Predicate : declare
11336 pragma Unreferenced (Discard);
11340 Check_Arg_Count (2);
11341 Check_Optional_Identifier (Arg1, Name_Entity);
11342 Check_Optional_Identifier (Arg2, Name_Check);
11344 Check_Arg_Is_Local_Name (Arg1);
11346 Type_Id := Get_Pragma_Arg (Arg1);
11347 Find_Type (Type_Id);
11348 Typ := Entity (Type_Id);
11350 if Typ = Any_Type then
11354 -- The remaining processing is simply to link the pragma on to
11355 -- the rep item chain, for processing when the type is frozen.
11356 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11357 -- mark the type as having predicates.
11359 Set_Has_Predicates (Typ);
11360 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11367 -- pragma Preelaborate [(library_unit_NAME)];
11369 -- Set the flag Is_Preelaborated of program unit name entity
11371 when Pragma_Preelaborate => Preelaborate : declare
11372 Pa : constant Node_Id := Parent (N);
11373 Pk : constant Node_Kind := Nkind (Pa);
11377 Check_Ada_83_Warning;
11378 Check_Valid_Library_Unit_Pragma;
11380 if Nkind (N) = N_Null_Statement then
11384 Ent := Find_Lib_Unit_Name;
11385 Check_Duplicate_Pragma (Ent);
11387 -- This filters out pragmas inside generic parent then
11388 -- show up inside instantiation
11391 and then not (Pk = N_Package_Specification
11392 and then Present (Generic_Parent (Pa)))
11394 if not Debug_Flag_U then
11395 Set_Is_Preelaborated (Ent);
11396 Set_Suppress_Elaboration_Warnings (Ent);
11401 ---------------------
11402 -- Preelaborate_05 --
11403 ---------------------
11405 -- pragma Preelaborate_05 [(library_unit_NAME)];
11407 -- This pragma is useable only in GNAT_Mode, where it is used like
11408 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11409 -- (otherwise it is ignored). This is used to implement AI-362 which
11410 -- recategorizes some run-time packages in Ada 2005 mode.
11412 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11417 Check_Valid_Library_Unit_Pragma;
11419 if not GNAT_Mode then
11420 Error_Pragma ("pragma% only available in GNAT mode");
11423 if Nkind (N) = N_Null_Statement then
11427 -- This is one of the few cases where we need to test the value of
11428 -- Ada_Version_Explicit rather than Ada_Version (which is always
11429 -- set to Ada_2012 in a predefined unit), we need to know the
11430 -- explicit version set to know if this pragma is active.
11432 if Ada_Version_Explicit >= Ada_2005 then
11433 Ent := Find_Lib_Unit_Name;
11434 Set_Is_Preelaborated (Ent);
11435 Set_Suppress_Elaboration_Warnings (Ent);
11437 end Preelaborate_05;
11443 -- pragma Priority (EXPRESSION);
11445 when Pragma_Priority => Priority : declare
11446 P : constant Node_Id := Parent (N);
11450 Check_No_Identifiers;
11451 Check_Arg_Count (1);
11455 if Nkind (P) = N_Subprogram_Body then
11456 Check_In_Main_Program;
11458 Arg := Get_Pragma_Arg (Arg1);
11459 Analyze_And_Resolve (Arg, Standard_Integer);
11463 if not Is_Static_Expression (Arg) then
11464 Flag_Non_Static_Expr
11465 ("main subprogram priority is not static!", Arg);
11468 -- If constraint error, then we already signalled an error
11470 elsif Raises_Constraint_Error (Arg) then
11473 -- Otherwise check in range
11477 Val : constant Uint := Expr_Value (Arg);
11481 or else Val > Expr_Value (Expression
11482 (Parent (RTE (RE_Max_Priority))))
11485 ("main subprogram priority is out of range", Arg1);
11491 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11493 -- Load an arbitrary entity from System.Tasking to make sure
11494 -- this package is implicitly with'ed, since we need to have
11495 -- the tasking run-time active for the pragma Priority to have
11499 Discard : Entity_Id;
11500 pragma Warnings (Off, Discard);
11502 Discard := RTE (RE_Task_List);
11505 -- Task or Protected, must be of type Integer
11507 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11508 Arg := Get_Pragma_Arg (Arg1);
11510 -- The expression must be analyzed in the special manner
11511 -- described in "Handling of Default and Per-Object
11512 -- Expressions" in sem.ads.
11514 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11516 if not Is_Static_Expression (Arg) then
11517 Check_Restriction (Static_Priorities, Arg);
11520 -- Anything else is incorrect
11526 if Has_Pragma_Priority (P) then
11527 Error_Pragma ("duplicate pragma% not allowed");
11529 Set_Has_Pragma_Priority (P, True);
11531 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11532 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11533 -- exp_ch9 should use this ???
11538 -----------------------------------
11539 -- Priority_Specific_Dispatching --
11540 -----------------------------------
11542 -- pragma Priority_Specific_Dispatching (
11543 -- policy_IDENTIFIER,
11544 -- first_priority_EXPRESSION,
11545 -- last_priority_EXPRESSION);
11547 when Pragma_Priority_Specific_Dispatching =>
11548 Priority_Specific_Dispatching : declare
11549 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11550 -- This is the entity System.Any_Priority;
11553 Lower_Bound : Node_Id;
11554 Upper_Bound : Node_Id;
11560 Check_Arg_Count (3);
11561 Check_No_Identifiers;
11562 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11563 Check_Valid_Configuration_Pragma;
11564 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11565 DP := Fold_Upper (Name_Buffer (1));
11567 Lower_Bound := Get_Pragma_Arg (Arg2);
11568 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11569 Lower_Val := Expr_Value (Lower_Bound);
11571 Upper_Bound := Get_Pragma_Arg (Arg3);
11572 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11573 Upper_Val := Expr_Value (Upper_Bound);
11575 -- It is not allowed to use Task_Dispatching_Policy and
11576 -- Priority_Specific_Dispatching in the same partition.
11578 if Task_Dispatching_Policy /= ' ' then
11579 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11581 ("pragma% incompatible with Task_Dispatching_Policy#");
11583 -- Check lower bound in range
11585 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11587 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11590 ("first_priority is out of range", Arg2);
11592 -- Check upper bound in range
11594 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11596 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11599 ("last_priority is out of range", Arg3);
11601 -- Check that the priority range is valid
11603 elsif Lower_Val > Upper_Val then
11605 ("last_priority_expression must be greater than" &
11606 " or equal to first_priority_expression");
11608 -- Store the new policy, but always preserve System_Location since
11609 -- we like the error message with the run-time name.
11612 -- Check overlapping in the priority ranges specified in other
11613 -- Priority_Specific_Dispatching pragmas within the same
11614 -- partition. We can only check those we know about!
11617 Specific_Dispatching.First .. Specific_Dispatching.Last
11619 if Specific_Dispatching.Table (J).First_Priority in
11620 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11621 or else Specific_Dispatching.Table (J).Last_Priority in
11622 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11625 Specific_Dispatching.Table (J).Pragma_Loc;
11627 ("priority range overlaps with "
11628 & "Priority_Specific_Dispatching#");
11632 -- The use of Priority_Specific_Dispatching is incompatible
11633 -- with Task_Dispatching_Policy.
11635 if Task_Dispatching_Policy /= ' ' then
11636 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11638 ("Priority_Specific_Dispatching incompatible "
11639 & "with Task_Dispatching_Policy#");
11642 -- The use of Priority_Specific_Dispatching forces ceiling
11645 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11646 Error_Msg_Sloc := Locking_Policy_Sloc;
11648 ("Priority_Specific_Dispatching incompatible "
11649 & "with Locking_Policy#");
11651 -- Set the Ceiling_Locking policy, but preserve System_Location
11652 -- since we like the error message with the run time name.
11655 Locking_Policy := 'C';
11657 if Locking_Policy_Sloc /= System_Location then
11658 Locking_Policy_Sloc := Loc;
11662 -- Add entry in the table
11664 Specific_Dispatching.Append
11665 ((Dispatching_Policy => DP,
11666 First_Priority => UI_To_Int (Lower_Val),
11667 Last_Priority => UI_To_Int (Upper_Val),
11668 Pragma_Loc => Loc));
11670 end Priority_Specific_Dispatching;
11676 -- pragma Profile (profile_IDENTIFIER);
11678 -- profile_IDENTIFIER => Restricted | Ravenscar
11680 when Pragma_Profile =>
11682 Check_Arg_Count (1);
11683 Check_Valid_Configuration_Pragma;
11684 Check_No_Identifiers;
11687 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11689 if Chars (Argx) = Name_Ravenscar then
11690 Set_Ravenscar_Profile (N);
11691 elsif Chars (Argx) = Name_Restricted then
11692 Set_Profile_Restrictions
11693 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11695 Error_Pragma_Arg ("& is not a valid profile", Argx);
11699 ----------------------
11700 -- Profile_Warnings --
11701 ----------------------
11703 -- pragma Profile_Warnings (profile_IDENTIFIER);
11705 -- profile_IDENTIFIER => Restricted | Ravenscar
11707 when Pragma_Profile_Warnings =>
11709 Check_Arg_Count (1);
11710 Check_Valid_Configuration_Pragma;
11711 Check_No_Identifiers;
11714 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11716 if Chars (Argx) = Name_Ravenscar then
11717 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11718 elsif Chars (Argx) = Name_Restricted then
11719 Set_Profile_Restrictions (Restricted, N, Warn => True);
11721 Error_Pragma_Arg ("& is not a valid profile", Argx);
11725 --------------------------
11726 -- Propagate_Exceptions --
11727 --------------------------
11729 -- pragma Propagate_Exceptions;
11731 -- Note: this pragma is obsolete and has no effect
11733 when Pragma_Propagate_Exceptions =>
11735 Check_Arg_Count (0);
11737 if In_Extended_Main_Source_Unit (N) then
11738 Propagate_Exceptions := True;
11745 -- pragma Psect_Object (
11746 -- [Internal =>] LOCAL_NAME,
11747 -- [, [External =>] EXTERNAL_SYMBOL]
11748 -- [, [Size =>] EXTERNAL_SYMBOL]);
11750 when Pragma_Psect_Object | Pragma_Common_Object =>
11751 Psect_Object : declare
11752 Args : Args_List (1 .. 3);
11753 Names : constant Name_List (1 .. 3) := (
11758 Internal : Node_Id renames Args (1);
11759 External : Node_Id renames Args (2);
11760 Size : Node_Id renames Args (3);
11762 Def_Id : Entity_Id;
11764 procedure Check_Too_Long (Arg : Node_Id);
11765 -- Posts message if the argument is an identifier with more
11766 -- than 31 characters, or a string literal with more than
11767 -- 31 characters, and we are operating under VMS
11769 --------------------
11770 -- Check_Too_Long --
11771 --------------------
11773 procedure Check_Too_Long (Arg : Node_Id) is
11774 X : constant Node_Id := Original_Node (Arg);
11777 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11779 ("inappropriate argument for pragma %", Arg);
11782 if OpenVMS_On_Target then
11783 if (Nkind (X) = N_String_Literal
11784 and then String_Length (Strval (X)) > 31)
11786 (Nkind (X) = N_Identifier
11787 and then Length_Of_Name (Chars (X)) > 31)
11790 ("argument for pragma % is longer than 31 characters",
11794 end Check_Too_Long;
11796 -- Start of processing for Common_Object/Psect_Object
11800 Gather_Associations (Names, Args);
11801 Process_Extended_Import_Export_Internal_Arg (Internal);
11803 Def_Id := Entity (Internal);
11805 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11807 ("pragma% must designate an object", Internal);
11810 Check_Too_Long (Internal);
11812 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11814 ("cannot use pragma% for imported/exported object",
11818 if Is_Concurrent_Type (Etype (Internal)) then
11820 ("cannot specify pragma % for task/protected object",
11824 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11826 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11828 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11831 if Ekind (Def_Id) = E_Constant then
11833 ("cannot specify pragma % for a constant", Internal);
11836 if Is_Record_Type (Etype (Internal)) then
11842 Ent := First_Entity (Etype (Internal));
11843 while Present (Ent) loop
11844 Decl := Declaration_Node (Ent);
11846 if Ekind (Ent) = E_Component
11847 and then Nkind (Decl) = N_Component_Declaration
11848 and then Present (Expression (Decl))
11849 and then Warn_On_Export_Import
11852 ("?object for pragma % has defaults", Internal);
11862 if Present (Size) then
11863 Check_Too_Long (Size);
11866 if Present (External) then
11867 Check_Arg_Is_External_Name (External);
11868 Check_Too_Long (External);
11871 -- If all error tests pass, link pragma on to the rep item chain
11873 Record_Rep_Item (Def_Id, N);
11880 -- pragma Pure [(library_unit_NAME)];
11882 when Pragma_Pure => Pure : declare
11886 Check_Ada_83_Warning;
11887 Check_Valid_Library_Unit_Pragma;
11889 if Nkind (N) = N_Null_Statement then
11893 Ent := Find_Lib_Unit_Name;
11895 Set_Has_Pragma_Pure (Ent);
11896 Set_Suppress_Elaboration_Warnings (Ent);
11903 -- pragma Pure_05 [(library_unit_NAME)];
11905 -- This pragma is useable only in GNAT_Mode, where it is used like
11906 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11907 -- it is ignored). It may be used after a pragma Preelaborate, in
11908 -- which case it overrides the effect of the pragma Preelaborate.
11909 -- This is used to implement AI-362 which recategorizes some run-time
11910 -- packages in Ada 2005 mode.
11912 when Pragma_Pure_05 => Pure_05 : declare
11917 Check_Valid_Library_Unit_Pragma;
11919 if not GNAT_Mode then
11920 Error_Pragma ("pragma% only available in GNAT mode");
11923 if Nkind (N) = N_Null_Statement then
11927 -- This is one of the few cases where we need to test the value of
11928 -- Ada_Version_Explicit rather than Ada_Version (which is always
11929 -- set to Ada_2012 in a predefined unit), we need to know the
11930 -- explicit version set to know if this pragma is active.
11932 if Ada_Version_Explicit >= Ada_2005 then
11933 Ent := Find_Lib_Unit_Name;
11934 Set_Is_Preelaborated (Ent, False);
11936 Set_Suppress_Elaboration_Warnings (Ent);
11940 -------------------
11941 -- Pure_Function --
11942 -------------------
11944 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11946 when Pragma_Pure_Function => Pure_Function : declare
11949 Def_Id : Entity_Id;
11950 Effective : Boolean := False;
11954 Check_Arg_Count (1);
11955 Check_Optional_Identifier (Arg1, Name_Entity);
11956 Check_Arg_Is_Local_Name (Arg1);
11957 E_Id := Get_Pragma_Arg (Arg1);
11959 if Error_Posted (E_Id) then
11963 -- Loop through homonyms (overloadings) of referenced entity
11965 E := Entity (E_Id);
11967 if Present (E) then
11969 Def_Id := Get_Base_Subprogram (E);
11971 if not Ekind_In (Def_Id, E_Function,
11972 E_Generic_Function,
11976 ("pragma% requires a function name", Arg1);
11979 Set_Is_Pure (Def_Id);
11981 if not Has_Pragma_Pure_Function (Def_Id) then
11982 Set_Has_Pragma_Pure_Function (Def_Id);
11986 exit when From_Aspect_Specification (N);
11988 exit when No (E) or else Scope (E) /= Current_Scope;
11992 and then Warn_On_Redundant_Constructs
11995 ("pragma Pure_Function on& is redundant?",
12001 --------------------
12002 -- Queuing_Policy --
12003 --------------------
12005 -- pragma Queuing_Policy (policy_IDENTIFIER);
12007 when Pragma_Queuing_Policy => declare
12011 Check_Ada_83_Warning;
12012 Check_Arg_Count (1);
12013 Check_No_Identifiers;
12014 Check_Arg_Is_Queuing_Policy (Arg1);
12015 Check_Valid_Configuration_Pragma;
12016 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12017 QP := Fold_Upper (Name_Buffer (1));
12019 if Queuing_Policy /= ' '
12020 and then Queuing_Policy /= QP
12022 Error_Msg_Sloc := Queuing_Policy_Sloc;
12023 Error_Pragma ("queuing policy incompatible with policy#");
12025 -- Set new policy, but always preserve System_Location since we
12026 -- like the error message with the run time name.
12029 Queuing_Policy := QP;
12031 if Queuing_Policy_Sloc /= System_Location then
12032 Queuing_Policy_Sloc := Loc;
12037 -----------------------
12038 -- Relative_Deadline --
12039 -----------------------
12041 -- pragma Relative_Deadline (time_span_EXPRESSION);
12043 when Pragma_Relative_Deadline => Relative_Deadline : declare
12044 P : constant Node_Id := Parent (N);
12049 Check_No_Identifiers;
12050 Check_Arg_Count (1);
12052 Arg := Get_Pragma_Arg (Arg1);
12054 -- The expression must be analyzed in the special manner described
12055 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12057 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12061 if Nkind (P) = N_Subprogram_Body then
12062 Check_In_Main_Program;
12066 elsif Nkind (P) = N_Task_Definition then
12069 -- Anything else is incorrect
12075 if Has_Relative_Deadline_Pragma (P) then
12076 Error_Pragma ("duplicate pragma% not allowed");
12078 Set_Has_Relative_Deadline_Pragma (P, True);
12080 if Nkind (P) = N_Task_Definition then
12081 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12084 end Relative_Deadline;
12086 ---------------------------
12087 -- Remote_Call_Interface --
12088 ---------------------------
12090 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12092 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12093 Cunit_Node : Node_Id;
12094 Cunit_Ent : Entity_Id;
12098 Check_Ada_83_Warning;
12099 Check_Valid_Library_Unit_Pragma;
12101 if Nkind (N) = N_Null_Statement then
12105 Cunit_Node := Cunit (Current_Sem_Unit);
12106 K := Nkind (Unit (Cunit_Node));
12107 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12109 if K = N_Package_Declaration
12110 or else K = N_Generic_Package_Declaration
12111 or else K = N_Subprogram_Declaration
12112 or else K = N_Generic_Subprogram_Declaration
12113 or else (K = N_Subprogram_Body
12114 and then Acts_As_Spec (Unit (Cunit_Node)))
12119 "pragma% must apply to package or subprogram declaration");
12122 Set_Is_Remote_Call_Interface (Cunit_Ent);
12123 end Remote_Call_Interface;
12129 -- pragma Remote_Types [(library_unit_NAME)];
12131 when Pragma_Remote_Types => Remote_Types : declare
12132 Cunit_Node : Node_Id;
12133 Cunit_Ent : Entity_Id;
12136 Check_Ada_83_Warning;
12137 Check_Valid_Library_Unit_Pragma;
12139 if Nkind (N) = N_Null_Statement then
12143 Cunit_Node := Cunit (Current_Sem_Unit);
12144 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12146 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12147 N_Generic_Package_Declaration)
12150 ("pragma% can only apply to a package declaration");
12153 Set_Is_Remote_Types (Cunit_Ent);
12160 -- pragma Ravenscar;
12162 when Pragma_Ravenscar =>
12164 Check_Arg_Count (0);
12165 Check_Valid_Configuration_Pragma;
12166 Set_Ravenscar_Profile (N);
12168 if Warn_On_Obsolescent_Feature then
12169 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12170 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12173 -------------------------
12174 -- Restricted_Run_Time --
12175 -------------------------
12177 -- pragma Restricted_Run_Time;
12179 when Pragma_Restricted_Run_Time =>
12181 Check_Arg_Count (0);
12182 Check_Valid_Configuration_Pragma;
12183 Set_Profile_Restrictions
12184 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12186 if Warn_On_Obsolescent_Feature then
12188 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12189 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12196 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12199 -- restriction_IDENTIFIER
12200 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12202 when Pragma_Restrictions =>
12203 Process_Restrictions_Or_Restriction_Warnings
12204 (Warn => Treat_Restrictions_As_Warnings);
12206 --------------------------
12207 -- Restriction_Warnings --
12208 --------------------------
12210 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12213 -- restriction_IDENTIFIER
12214 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12216 when Pragma_Restriction_Warnings =>
12218 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12224 -- pragma Reviewable;
12226 when Pragma_Reviewable =>
12227 Check_Ada_83_Warning;
12228 Check_Arg_Count (0);
12230 -- Call dummy debugging function rv. This is done to assist front
12231 -- end debugging. By placing a Reviewable pragma in the source
12232 -- program, a breakpoint on rv catches this place in the source,
12233 -- allowing convenient stepping to the point of interest.
12237 --------------------------
12238 -- Short_Circuit_And_Or --
12239 --------------------------
12241 when Pragma_Short_Circuit_And_Or =>
12243 Check_Arg_Count (0);
12244 Check_Valid_Configuration_Pragma;
12245 Short_Circuit_And_Or := True;
12247 -------------------
12248 -- Share_Generic --
12249 -------------------
12251 -- pragma Share_Generic (NAME {, NAME});
12253 when Pragma_Share_Generic =>
12255 Process_Generic_List;
12261 -- pragma Shared (LOCAL_NAME);
12263 when Pragma_Shared =>
12265 Process_Atomic_Shared_Volatile;
12267 --------------------
12268 -- Shared_Passive --
12269 --------------------
12271 -- pragma Shared_Passive [(library_unit_NAME)];
12273 -- Set the flag Is_Shared_Passive of program unit name entity
12275 when Pragma_Shared_Passive => Shared_Passive : declare
12276 Cunit_Node : Node_Id;
12277 Cunit_Ent : Entity_Id;
12280 Check_Ada_83_Warning;
12281 Check_Valid_Library_Unit_Pragma;
12283 if Nkind (N) = N_Null_Statement then
12287 Cunit_Node := Cunit (Current_Sem_Unit);
12288 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12290 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12291 N_Generic_Package_Declaration)
12294 ("pragma% can only apply to a package declaration");
12297 Set_Is_Shared_Passive (Cunit_Ent);
12298 end Shared_Passive;
12300 -----------------------
12301 -- Short_Descriptors --
12302 -----------------------
12304 -- pragma Short_Descriptors;
12306 when Pragma_Short_Descriptors =>
12308 Check_Arg_Count (0);
12309 Check_Valid_Configuration_Pragma;
12310 Short_Descriptors := True;
12312 ----------------------
12313 -- Source_File_Name --
12314 ----------------------
12316 -- There are five forms for this pragma:
12318 -- pragma Source_File_Name (
12319 -- [UNIT_NAME =>] unit_NAME,
12320 -- BODY_FILE_NAME => STRING_LITERAL
12321 -- [, [INDEX =>] INTEGER_LITERAL]);
12323 -- pragma Source_File_Name (
12324 -- [UNIT_NAME =>] unit_NAME,
12325 -- SPEC_FILE_NAME => STRING_LITERAL
12326 -- [, [INDEX =>] INTEGER_LITERAL]);
12328 -- pragma Source_File_Name (
12329 -- BODY_FILE_NAME => STRING_LITERAL
12330 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12331 -- [, CASING => CASING_SPEC]);
12333 -- pragma Source_File_Name (
12334 -- SPEC_FILE_NAME => STRING_LITERAL
12335 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12336 -- [, CASING => CASING_SPEC]);
12338 -- pragma Source_File_Name (
12339 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12340 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12341 -- [, CASING => CASING_SPEC]);
12343 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12345 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12346 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12347 -- only be used when no project file is used, while SFNP can only be
12348 -- used when a project file is used.
12350 -- No processing here. Processing was completed during parsing, since
12351 -- we need to have file names set as early as possible. Units are
12352 -- loaded well before semantic processing starts.
12354 -- The only processing we defer to this point is the check for
12355 -- correct placement.
12357 when Pragma_Source_File_Name =>
12359 Check_Valid_Configuration_Pragma;
12361 ------------------------------
12362 -- Source_File_Name_Project --
12363 ------------------------------
12365 -- See Source_File_Name for syntax
12367 -- No processing here. Processing was completed during parsing, since
12368 -- we need to have file names set as early as possible. Units are
12369 -- loaded well before semantic processing starts.
12371 -- The only processing we defer to this point is the check for
12372 -- correct placement.
12374 when Pragma_Source_File_Name_Project =>
12376 Check_Valid_Configuration_Pragma;
12378 -- Check that a pragma Source_File_Name_Project is used only in a
12379 -- configuration pragmas file.
12381 -- Pragmas Source_File_Name_Project should only be generated by
12382 -- the Project Manager in configuration pragmas files.
12384 -- This is really an ugly test. It seems to depend on some
12385 -- accidental and undocumented property. At the very least it
12386 -- needs to be documented, but it would be better to have a
12387 -- clean way of testing if we are in a configuration file???
12389 if Present (Parent (N)) then
12391 ("pragma% can only appear in a configuration pragmas file");
12394 ----------------------
12395 -- Source_Reference --
12396 ----------------------
12398 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12400 -- Nothing to do, all processing completed in Par.Prag, since we need
12401 -- the information for possible parser messages that are output.
12403 when Pragma_Source_Reference =>
12406 --------------------------------
12407 -- Static_Elaboration_Desired --
12408 --------------------------------
12410 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12412 when Pragma_Static_Elaboration_Desired =>
12414 Check_At_Most_N_Arguments (1);
12416 if Is_Compilation_Unit (Current_Scope)
12417 and then Ekind (Current_Scope) = E_Package
12419 Set_Static_Elaboration_Desired (Current_Scope, True);
12421 Error_Pragma ("pragma% must apply to a library-level package");
12428 -- pragma Storage_Size (EXPRESSION);
12430 when Pragma_Storage_Size => Storage_Size : declare
12431 P : constant Node_Id := Parent (N);
12435 Check_No_Identifiers;
12436 Check_Arg_Count (1);
12438 -- The expression must be analyzed in the special manner described
12439 -- in "Handling of Default Expressions" in sem.ads.
12441 Arg := Get_Pragma_Arg (Arg1);
12442 Preanalyze_Spec_Expression (Arg, Any_Integer);
12444 if not Is_Static_Expression (Arg) then
12445 Check_Restriction (Static_Storage_Size, Arg);
12448 if Nkind (P) /= N_Task_Definition then
12453 if Has_Storage_Size_Pragma (P) then
12454 Error_Pragma ("duplicate pragma% not allowed");
12456 Set_Has_Storage_Size_Pragma (P, True);
12459 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12460 -- ??? exp_ch9 should use this!
12468 -- pragma Storage_Unit (NUMERIC_LITERAL);
12470 -- Only permitted argument is System'Storage_Unit value
12472 when Pragma_Storage_Unit =>
12473 Check_No_Identifiers;
12474 Check_Arg_Count (1);
12475 Check_Arg_Is_Integer_Literal (Arg1);
12477 if Intval (Get_Pragma_Arg (Arg1)) /=
12478 UI_From_Int (Ttypes.System_Storage_Unit)
12480 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12482 ("the only allowed argument for pragma% is ^", Arg1);
12485 --------------------
12486 -- Stream_Convert --
12487 --------------------
12489 -- pragma Stream_Convert (
12490 -- [Entity =>] type_LOCAL_NAME,
12491 -- [Read =>] function_NAME,
12492 -- [Write =>] function NAME);
12494 when Pragma_Stream_Convert => Stream_Convert : declare
12496 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12497 -- Check that the given argument is the name of a local function
12498 -- of one argument that is not overloaded earlier in the current
12499 -- local scope. A check is also made that the argument is a
12500 -- function with one parameter.
12502 --------------------------------------
12503 -- Check_OK_Stream_Convert_Function --
12504 --------------------------------------
12506 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12510 Check_Arg_Is_Local_Name (Arg);
12511 Ent := Entity (Get_Pragma_Arg (Arg));
12513 if Has_Homonym (Ent) then
12515 ("argument for pragma% may not be overloaded", Arg);
12518 if Ekind (Ent) /= E_Function
12519 or else No (First_Formal (Ent))
12520 or else Present (Next_Formal (First_Formal (Ent)))
12523 ("argument for pragma% must be" &
12524 " function of one argument", Arg);
12526 end Check_OK_Stream_Convert_Function;
12528 -- Start of processing for Stream_Convert
12532 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12533 Check_Arg_Count (3);
12534 Check_Optional_Identifier (Arg1, Name_Entity);
12535 Check_Optional_Identifier (Arg2, Name_Read);
12536 Check_Optional_Identifier (Arg3, Name_Write);
12537 Check_Arg_Is_Local_Name (Arg1);
12538 Check_OK_Stream_Convert_Function (Arg2);
12539 Check_OK_Stream_Convert_Function (Arg3);
12542 Typ : constant Entity_Id :=
12543 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12544 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12545 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12548 Check_First_Subtype (Arg1);
12550 -- Check for too early or too late. Note that we don't enforce
12551 -- the rule about primitive operations in this case, since, as
12552 -- is the case for explicit stream attributes themselves, these
12553 -- restrictions are not appropriate. Note that the chaining of
12554 -- the pragma by Rep_Item_Too_Late is actually the critical
12555 -- processing done for this pragma.
12557 if Rep_Item_Too_Early (Typ, N)
12559 Rep_Item_Too_Late (Typ, N, FOnly => True)
12564 -- Return if previous error
12566 if Etype (Typ) = Any_Type
12568 Etype (Read) = Any_Type
12570 Etype (Write) = Any_Type
12577 if Underlying_Type (Etype (Read)) /= Typ then
12579 ("incorrect return type for function&", Arg2);
12582 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12584 ("incorrect parameter type for function&", Arg3);
12587 if Underlying_Type (Etype (First_Formal (Read))) /=
12588 Underlying_Type (Etype (Write))
12591 ("result type of & does not match Read parameter type",
12595 end Stream_Convert;
12597 -------------------------
12598 -- Style_Checks (GNAT) --
12599 -------------------------
12601 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12603 -- This is processed by the parser since some of the style checks
12604 -- take place during source scanning and parsing. This means that
12605 -- we don't need to issue error messages here.
12607 when Pragma_Style_Checks => Style_Checks : declare
12608 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12614 Check_No_Identifiers;
12616 -- Two argument form
12618 if Arg_Count = 2 then
12619 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12626 E_Id := Get_Pragma_Arg (Arg2);
12629 if not Is_Entity_Name (E_Id) then
12631 ("second argument of pragma% must be entity name",
12635 E := Entity (E_Id);
12641 Set_Suppress_Style_Checks (E,
12642 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12643 exit when No (Homonym (E));
12649 -- One argument form
12652 Check_Arg_Count (1);
12654 if Nkind (A) = N_String_Literal then
12658 Slen : constant Natural := Natural (String_Length (S));
12659 Options : String (1 .. Slen);
12665 C := Get_String_Char (S, Int (J));
12666 exit when not In_Character_Range (C);
12667 Options (J) := Get_Character (C);
12669 -- If at end of string, set options. As per discussion
12670 -- above, no need to check for errors, since we issued
12671 -- them in the parser.
12674 Set_Style_Check_Options (Options);
12682 elsif Nkind (A) = N_Identifier then
12683 if Chars (A) = Name_All_Checks then
12685 Set_GNAT_Style_Check_Options;
12687 Set_Default_Style_Check_Options;
12690 elsif Chars (A) = Name_On then
12691 Style_Check := True;
12693 elsif Chars (A) = Name_Off then
12694 Style_Check := False;
12704 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12706 when Pragma_Subtitle =>
12708 Check_Arg_Count (1);
12709 Check_Optional_Identifier (Arg1, Name_Subtitle);
12710 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12717 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12719 when Pragma_Suppress =>
12720 Process_Suppress_Unsuppress (True);
12726 -- pragma Suppress_All;
12728 -- The only check made here is that the pragma has no arguments.
12729 -- There are no placement rules, and the processing required (setting
12730 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12731 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12732 -- then creates and inserts a pragma Suppress (All_Checks).
12734 when Pragma_Suppress_All =>
12736 Check_Arg_Count (0);
12738 -------------------------
12739 -- Suppress_Debug_Info --
12740 -------------------------
12742 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12744 when Pragma_Suppress_Debug_Info =>
12746 Check_Arg_Count (1);
12747 Check_Optional_Identifier (Arg1, Name_Entity);
12748 Check_Arg_Is_Local_Name (Arg1);
12749 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
12751 ----------------------------------
12752 -- Suppress_Exception_Locations --
12753 ----------------------------------
12755 -- pragma Suppress_Exception_Locations;
12757 when Pragma_Suppress_Exception_Locations =>
12759 Check_Arg_Count (0);
12760 Check_Valid_Configuration_Pragma;
12761 Exception_Locations_Suppressed := True;
12763 -----------------------------
12764 -- Suppress_Initialization --
12765 -----------------------------
12767 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12769 when Pragma_Suppress_Initialization => Suppress_Init : declare
12775 Check_Arg_Count (1);
12776 Check_Optional_Identifier (Arg1, Name_Entity);
12777 Check_Arg_Is_Local_Name (Arg1);
12779 E_Id := Get_Pragma_Arg (Arg1);
12781 if Etype (E_Id) = Any_Type then
12785 E := Entity (E_Id);
12787 if not Is_Type (E) then
12788 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
12791 if Rep_Item_Too_Early (E, N)
12793 Rep_Item_Too_Late (E, N, FOnly => True)
12798 -- For incomplete/private type, set flag on full view
12800 if Is_Incomplete_Or_Private_Type (E) then
12801 if No (Full_View (Base_Type (E))) then
12803 ("argument of pragma% cannot be an incomplete type", Arg1);
12805 Set_Suppress_Initialization (Full_View (Base_Type (E)));
12808 -- For first subtype, set flag on base type
12810 elsif Is_First_Subtype (E) then
12811 Set_Suppress_Initialization (Base_Type (E));
12813 -- For other than first subtype, set flag on subtype itself
12816 Set_Suppress_Initialization (E);
12824 -- pragma System_Name (DIRECT_NAME);
12826 -- Syntax check: one argument, which must be the identifier GNAT or
12827 -- the identifier GCC, no other identifiers are acceptable.
12829 when Pragma_System_Name =>
12831 Check_No_Identifiers;
12832 Check_Arg_Count (1);
12833 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12835 -----------------------------
12836 -- Task_Dispatching_Policy --
12837 -----------------------------
12839 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12841 when Pragma_Task_Dispatching_Policy => declare
12845 Check_Ada_83_Warning;
12846 Check_Arg_Count (1);
12847 Check_No_Identifiers;
12848 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12849 Check_Valid_Configuration_Pragma;
12850 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12851 DP := Fold_Upper (Name_Buffer (1));
12853 if Task_Dispatching_Policy /= ' '
12854 and then Task_Dispatching_Policy /= DP
12856 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12858 ("task dispatching policy incompatible with policy#");
12860 -- Set new policy, but always preserve System_Location since we
12861 -- like the error message with the run time name.
12864 Task_Dispatching_Policy := DP;
12866 if Task_Dispatching_Policy_Sloc /= System_Location then
12867 Task_Dispatching_Policy_Sloc := Loc;
12876 -- pragma Task_Info (EXPRESSION);
12878 when Pragma_Task_Info => Task_Info : declare
12879 P : constant Node_Id := Parent (N);
12884 if Nkind (P) /= N_Task_Definition then
12885 Error_Pragma ("pragma% must appear in task definition");
12888 Check_No_Identifiers;
12889 Check_Arg_Count (1);
12891 Analyze_And_Resolve
12892 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12894 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12898 if Has_Task_Info_Pragma (P) then
12899 Error_Pragma ("duplicate pragma% not allowed");
12901 Set_Has_Task_Info_Pragma (P, True);
12909 -- pragma Task_Name (string_EXPRESSION);
12911 when Pragma_Task_Name => Task_Name : declare
12912 P : constant Node_Id := Parent (N);
12916 Check_No_Identifiers;
12917 Check_Arg_Count (1);
12919 Arg := Get_Pragma_Arg (Arg1);
12921 -- The expression is used in the call to Create_Task, and must be
12922 -- expanded there, not in the context of the current spec. It must
12923 -- however be analyzed to capture global references, in case it
12924 -- appears in a generic context.
12926 Preanalyze_And_Resolve (Arg, Standard_String);
12928 if Nkind (P) /= N_Task_Definition then
12932 if Has_Task_Name_Pragma (P) then
12933 Error_Pragma ("duplicate pragma% not allowed");
12935 Set_Has_Task_Name_Pragma (P, True);
12936 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12944 -- pragma Task_Storage (
12945 -- [Task_Type =>] LOCAL_NAME,
12946 -- [Top_Guard =>] static_integer_EXPRESSION);
12948 when Pragma_Task_Storage => Task_Storage : declare
12949 Args : Args_List (1 .. 2);
12950 Names : constant Name_List (1 .. 2) := (
12954 Task_Type : Node_Id renames Args (1);
12955 Top_Guard : Node_Id renames Args (2);
12961 Gather_Associations (Names, Args);
12963 if No (Task_Type) then
12965 ("missing task_type argument for pragma%");
12968 Check_Arg_Is_Local_Name (Task_Type);
12970 Ent := Entity (Task_Type);
12972 if not Is_Task_Type (Ent) then
12974 ("argument for pragma% must be task type", Task_Type);
12977 if No (Top_Guard) then
12979 ("pragma% takes two arguments", Task_Type);
12981 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12984 Check_First_Subtype (Task_Type);
12986 if Rep_Item_Too_Late (Ent, N) then
12991 --------------------------
12992 -- Thread_Local_Storage --
12993 --------------------------
12995 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12997 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13003 Check_Arg_Count (1);
13004 Check_Optional_Identifier (Arg1, Name_Entity);
13005 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13007 Id := Get_Pragma_Arg (Arg1);
13010 if not Is_Entity_Name (Id)
13011 or else Ekind (Entity (Id)) /= E_Variable
13013 Error_Pragma_Arg ("local variable name required", Arg1);
13018 if Rep_Item_Too_Early (E, N)
13019 or else Rep_Item_Too_Late (E, N)
13024 Set_Has_Pragma_Thread_Local_Storage (E);
13025 Set_Has_Gigi_Rep_Item (E);
13026 end Thread_Local_Storage;
13032 -- pragma Time_Slice (static_duration_EXPRESSION);
13034 when Pragma_Time_Slice => Time_Slice : declare
13040 Check_Arg_Count (1);
13041 Check_No_Identifiers;
13042 Check_In_Main_Program;
13043 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13045 if not Error_Posted (Arg1) then
13047 while Present (Nod) loop
13048 if Nkind (Nod) = N_Pragma
13049 and then Pragma_Name (Nod) = Name_Time_Slice
13051 Error_Msg_Name_1 := Pname;
13052 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13059 -- Process only if in main unit
13061 if Get_Source_Unit (Loc) = Main_Unit then
13062 Opt.Time_Slice_Set := True;
13063 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13065 if Val <= Ureal_0 then
13066 Opt.Time_Slice_Value := 0;
13068 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13069 Opt.Time_Slice_Value := 1_000_000_000;
13072 Opt.Time_Slice_Value :=
13073 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13082 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13084 -- TITLING_OPTION ::=
13085 -- [Title =>] STRING_LITERAL
13086 -- | [Subtitle =>] STRING_LITERAL
13088 when Pragma_Title => Title : declare
13089 Args : Args_List (1 .. 2);
13090 Names : constant Name_List (1 .. 2) := (
13096 Gather_Associations (Names, Args);
13099 for J in 1 .. 2 loop
13100 if Present (Args (J)) then
13101 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13106 ---------------------
13107 -- Unchecked_Union --
13108 ---------------------
13110 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13112 when Pragma_Unchecked_Union => Unchecked_Union : declare
13113 Assoc : constant Node_Id := Arg1;
13114 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13125 Check_No_Identifiers;
13126 Check_Arg_Count (1);
13127 Check_Arg_Is_Local_Name (Arg1);
13129 Find_Type (Type_Id);
13130 Typ := Entity (Type_Id);
13133 or else Rep_Item_Too_Early (Typ, N)
13137 Typ := Underlying_Type (Typ);
13140 if Rep_Item_Too_Late (Typ, N) then
13144 Check_First_Subtype (Arg1);
13146 -- Note remaining cases are references to a type in the current
13147 -- declarative part. If we find an error, we post the error on
13148 -- the relevant type declaration at an appropriate point.
13150 if not Is_Record_Type (Typ) then
13151 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13154 elsif Is_Tagged_Type (Typ) then
13155 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13158 elsif Is_Limited_Type (Typ) then
13160 ("Unchecked_Union must not be limited record type", Typ);
13161 Explain_Limited_Type (Typ, Typ);
13165 if not Has_Discriminants (Typ) then
13167 ("Unchecked_Union must have one discriminant", Typ);
13171 Discr := First_Discriminant (Typ);
13172 while Present (Discr) loop
13173 if No (Discriminant_Default_Value (Discr)) then
13175 ("Unchecked_Union discriminant must have default value",
13179 Next_Discriminant (Discr);
13182 Tdef := Type_Definition (Declaration_Node (Typ));
13183 Clist := Component_List (Tdef);
13185 Comp := First (Component_Items (Clist));
13186 while Present (Comp) loop
13187 Check_Component (Comp, Typ);
13191 if No (Clist) or else No (Variant_Part (Clist)) then
13193 ("Unchecked_Union must have variant part",
13198 Vpart := Variant_Part (Clist);
13200 Variant := First (Variants (Vpart));
13201 while Present (Variant) loop
13202 Check_Variant (Variant, Typ);
13207 Set_Is_Unchecked_Union (Typ);
13208 Set_Convention (Typ, Convention_C);
13209 Set_Has_Unchecked_Union (Base_Type (Typ));
13210 Set_Is_Unchecked_Union (Base_Type (Typ));
13211 end Unchecked_Union;
13213 ------------------------
13214 -- Unimplemented_Unit --
13215 ------------------------
13217 -- pragma Unimplemented_Unit;
13219 -- Note: this only gives an error if we are generating code, or if
13220 -- we are in a generic library unit (where the pragma appears in the
13221 -- body, not in the spec).
13223 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13224 Cunitent : constant Entity_Id :=
13225 Cunit_Entity (Get_Source_Unit (Loc));
13226 Ent_Kind : constant Entity_Kind :=
13231 Check_Arg_Count (0);
13233 if Operating_Mode = Generate_Code
13234 or else Ent_Kind = E_Generic_Function
13235 or else Ent_Kind = E_Generic_Procedure
13236 or else Ent_Kind = E_Generic_Package
13238 Get_Name_String (Chars (Cunitent));
13239 Set_Casing (Mixed_Case);
13240 Write_Str (Name_Buffer (1 .. Name_Len));
13241 Write_Str (" is not supported in this configuration");
13243 raise Unrecoverable_Error;
13245 end Unimplemented_Unit;
13247 ------------------------
13248 -- Universal_Aliasing --
13249 ------------------------
13251 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13253 when Pragma_Universal_Aliasing => Universal_Alias : declare
13258 Check_Arg_Count (1);
13259 Check_Optional_Identifier (Arg2, Name_Entity);
13260 Check_Arg_Is_Local_Name (Arg1);
13261 E_Id := Entity (Get_Pragma_Arg (Arg1));
13263 if E_Id = Any_Type then
13265 elsif No (E_Id) or else not Is_Type (E_Id) then
13266 Error_Pragma_Arg ("pragma% requires type", Arg1);
13269 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13270 end Universal_Alias;
13272 --------------------
13273 -- Universal_Data --
13274 --------------------
13276 -- pragma Universal_Data [(library_unit_NAME)];
13278 when Pragma_Universal_Data =>
13281 -- If this is a configuration pragma, then set the universal
13282 -- addressing option, otherwise confirm that the pragma satisfies
13283 -- the requirements of library unit pragma placement and leave it
13284 -- to the GNAAMP back end to detect the pragma (avoids transitive
13285 -- setting of the option due to withed units).
13287 if Is_Configuration_Pragma then
13288 Universal_Addressing_On_AAMP := True;
13290 Check_Valid_Library_Unit_Pragma;
13293 if not AAMP_On_Target then
13294 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13301 -- pragma Unmodified (local_Name {, local_Name});
13303 when Pragma_Unmodified => Unmodified : declare
13304 Arg_Node : Node_Id;
13305 Arg_Expr : Node_Id;
13306 Arg_Ent : Entity_Id;
13310 Check_At_Least_N_Arguments (1);
13312 -- Loop through arguments
13315 while Present (Arg_Node) loop
13316 Check_No_Identifier (Arg_Node);
13318 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13319 -- in fact generate reference, so that the entity will have a
13320 -- reference, which will inhibit any warnings about it not
13321 -- being referenced, and also properly show up in the ali file
13322 -- as a reference. But this reference is recorded before the
13323 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13324 -- generated for this reference.
13326 Check_Arg_Is_Local_Name (Arg_Node);
13327 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13329 if Is_Entity_Name (Arg_Expr) then
13330 Arg_Ent := Entity (Arg_Expr);
13332 if not Is_Assignable (Arg_Ent) then
13334 ("pragma% can only be applied to a variable",
13337 Set_Has_Pragma_Unmodified (Arg_Ent);
13349 -- pragma Unreferenced (local_Name {, local_Name});
13351 -- or when used in a context clause:
13353 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13355 when Pragma_Unreferenced => Unreferenced : declare
13356 Arg_Node : Node_Id;
13357 Arg_Expr : Node_Id;
13358 Arg_Ent : Entity_Id;
13363 Check_At_Least_N_Arguments (1);
13365 -- Check case of appearing within context clause
13367 if Is_In_Context_Clause then
13369 -- The arguments must all be units mentioned in a with clause
13370 -- in the same context clause. Note we already checked (in
13371 -- Par.Prag) that the arguments are either identifiers or
13372 -- selected components.
13375 while Present (Arg_Node) loop
13376 Citem := First (List_Containing (N));
13377 while Citem /= N loop
13378 if Nkind (Citem) = N_With_Clause
13380 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13382 Set_Has_Pragma_Unreferenced
13385 (Library_Unit (Citem))));
13387 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13396 ("argument of pragma% is not with'ed unit", Arg_Node);
13402 -- Case of not in list of context items
13406 while Present (Arg_Node) loop
13407 Check_No_Identifier (Arg_Node);
13409 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13410 -- will in fact generate reference, so that the entity will
13411 -- have a reference, which will inhibit any warnings about
13412 -- it not being referenced, and also properly show up in the
13413 -- ali file as a reference. But this reference is recorded
13414 -- before the Has_Pragma_Unreferenced flag is set, so that
13415 -- no warning is generated for this reference.
13417 Check_Arg_Is_Local_Name (Arg_Node);
13418 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13420 if Is_Entity_Name (Arg_Expr) then
13421 Arg_Ent := Entity (Arg_Expr);
13423 -- If the entity is overloaded, the pragma applies to the
13424 -- most recent overloading, as documented. In this case,
13425 -- name resolution does not generate a reference, so it
13426 -- must be done here explicitly.
13428 if Is_Overloaded (Arg_Expr) then
13429 Generate_Reference (Arg_Ent, N);
13432 Set_Has_Pragma_Unreferenced (Arg_Ent);
13440 --------------------------
13441 -- Unreferenced_Objects --
13442 --------------------------
13444 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13446 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13447 Arg_Node : Node_Id;
13448 Arg_Expr : Node_Id;
13452 Check_At_Least_N_Arguments (1);
13455 while Present (Arg_Node) loop
13456 Check_No_Identifier (Arg_Node);
13457 Check_Arg_Is_Local_Name (Arg_Node);
13458 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13460 if not Is_Entity_Name (Arg_Expr)
13461 or else not Is_Type (Entity (Arg_Expr))
13464 ("argument for pragma% must be type or subtype", Arg_Node);
13467 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13470 end Unreferenced_Objects;
13472 ------------------------------
13473 -- Unreserve_All_Interrupts --
13474 ------------------------------
13476 -- pragma Unreserve_All_Interrupts;
13478 when Pragma_Unreserve_All_Interrupts =>
13480 Check_Arg_Count (0);
13482 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13483 Unreserve_All_Interrupts := True;
13490 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13492 when Pragma_Unsuppress =>
13494 Process_Suppress_Unsuppress (False);
13496 -------------------
13497 -- Use_VADS_Size --
13498 -------------------
13500 -- pragma Use_VADS_Size;
13502 when Pragma_Use_VADS_Size =>
13504 Check_Arg_Count (0);
13505 Check_Valid_Configuration_Pragma;
13506 Use_VADS_Size := True;
13508 ---------------------
13509 -- Validity_Checks --
13510 ---------------------
13512 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13514 when Pragma_Validity_Checks => Validity_Checks : declare
13515 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13521 Check_Arg_Count (1);
13522 Check_No_Identifiers;
13524 if Nkind (A) = N_String_Literal then
13528 Slen : constant Natural := Natural (String_Length (S));
13529 Options : String (1 .. Slen);
13535 C := Get_String_Char (S, Int (J));
13536 exit when not In_Character_Range (C);
13537 Options (J) := Get_Character (C);
13540 Set_Validity_Check_Options (Options);
13548 elsif Nkind (A) = N_Identifier then
13550 if Chars (A) = Name_All_Checks then
13551 Set_Validity_Check_Options ("a");
13553 elsif Chars (A) = Name_On then
13554 Validity_Checks_On := True;
13556 elsif Chars (A) = Name_Off then
13557 Validity_Checks_On := False;
13561 end Validity_Checks;
13567 -- pragma Volatile (LOCAL_NAME);
13569 when Pragma_Volatile =>
13570 Process_Atomic_Shared_Volatile;
13572 -------------------------
13573 -- Volatile_Components --
13574 -------------------------
13576 -- pragma Volatile_Components (array_LOCAL_NAME);
13578 -- Volatile is handled by the same circuit as Atomic_Components
13584 -- pragma Warnings (On | Off);
13585 -- pragma Warnings (On | Off, LOCAL_NAME);
13586 -- pragma Warnings (static_string_EXPRESSION);
13587 -- pragma Warnings (On | Off, STRING_LITERAL);
13589 when Pragma_Warnings => Warnings : begin
13591 Check_At_Least_N_Arguments (1);
13592 Check_No_Identifiers;
13594 -- If debug flag -gnatd.i is set, pragma is ignored
13596 if Debug_Flag_Dot_I then
13600 -- Process various forms of the pragma
13603 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13606 -- One argument case
13608 if Arg_Count = 1 then
13610 -- On/Off one argument case was processed by parser
13612 if Nkind (Argx) = N_Identifier
13614 (Chars (Argx) = Name_On
13616 Chars (Argx) = Name_Off)
13620 -- One argument case must be ON/OFF or static string expr
13622 elsif not Is_Static_String_Expression (Arg1) then
13624 ("argument of pragma% must be On/Off or " &
13625 "static string expression", Arg1);
13627 -- One argument string expression case
13631 Lit : constant Node_Id := Expr_Value_S (Argx);
13632 Str : constant String_Id := Strval (Lit);
13633 Len : constant Nat := String_Length (Str);
13641 while J <= Len loop
13642 C := Get_String_Char (Str, J);
13643 OK := In_Character_Range (C);
13646 Chr := Get_Character (C);
13650 if J < Len and then Chr = '.' then
13652 C := Get_String_Char (Str, J);
13653 Chr := Get_Character (C);
13655 if not Set_Dot_Warning_Switch (Chr) then
13657 ("invalid warning switch character " &
13664 OK := Set_Warning_Switch (Chr);
13670 ("invalid warning switch character " & Chr,
13679 -- Two or more arguments (must be two)
13682 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13683 Check_At_Most_N_Arguments (2);
13691 E_Id := Get_Pragma_Arg (Arg2);
13694 -- In the expansion of an inlined body, a reference to
13695 -- the formal may be wrapped in a conversion if the
13696 -- actual is a conversion. Retrieve the real entity name.
13698 if (In_Instance_Body
13699 or else In_Inlined_Body)
13700 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13702 E_Id := Expression (E_Id);
13705 -- Entity name case
13707 if Is_Entity_Name (E_Id) then
13708 E := Entity (E_Id);
13715 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13718 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13719 and then Warn_On_Warnings_Off
13721 Warnings_Off_Pragmas.Append ((N, E));
13724 if Is_Enumeration_Type (E) then
13728 Lit := First_Literal (E);
13729 while Present (Lit) loop
13730 Set_Warnings_Off (Lit);
13731 Next_Literal (Lit);
13736 exit when No (Homonym (E));
13741 -- Error if not entity or static string literal case
13743 elsif not Is_Static_String_Expression (Arg2) then
13745 ("second argument of pragma% must be entity " &
13746 "name or static string expression", Arg2);
13748 -- String literal case
13751 String_To_Name_Buffer
13752 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13754 -- Note on configuration pragma case: If this is a
13755 -- configuration pragma, then for an OFF pragma, we
13756 -- just set Config True in the call, which is all
13757 -- that needs to be done. For the case of ON, this
13758 -- is normally an error, unless it is canceling the
13759 -- effect of a previous OFF pragma in the same file.
13760 -- In any other case, an error will be signalled (ON
13761 -- with no matching OFF).
13763 if Chars (Argx) = Name_Off then
13764 Set_Specific_Warning_Off
13765 (Loc, Name_Buffer (1 .. Name_Len),
13766 Config => Is_Configuration_Pragma);
13768 elsif Chars (Argx) = Name_On then
13769 Set_Specific_Warning_On
13770 (Loc, Name_Buffer (1 .. Name_Len), Err);
13774 ("?pragma Warnings On with no " &
13775 "matching Warnings Off",
13785 -------------------
13786 -- Weak_External --
13787 -------------------
13789 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13791 when Pragma_Weak_External => Weak_External : declare
13796 Check_Arg_Count (1);
13797 Check_Optional_Identifier (Arg1, Name_Entity);
13798 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13799 Ent := Entity (Get_Pragma_Arg (Arg1));
13801 if Rep_Item_Too_Early (Ent, N) then
13804 Ent := Underlying_Type (Ent);
13807 -- The only processing required is to link this item on to the
13808 -- list of rep items for the given entity. This is accomplished
13809 -- by the call to Rep_Item_Too_Late (when no error is detected
13810 -- and False is returned).
13812 if Rep_Item_Too_Late (Ent, N) then
13815 Set_Has_Gigi_Rep_Item (Ent);
13819 -----------------------------
13820 -- Wide_Character_Encoding --
13821 -----------------------------
13823 -- pragma Wide_Character_Encoding (IDENTIFIER);
13825 when Pragma_Wide_Character_Encoding =>
13828 -- Nothing to do, handled in parser. Note that we do not enforce
13829 -- configuration pragma placement, this pragma can appear at any
13830 -- place in the source, allowing mixed encodings within a single
13835 --------------------
13836 -- Unknown_Pragma --
13837 --------------------
13839 -- Should be impossible, since the case of an unknown pragma is
13840 -- separately processed before the case statement is entered.
13842 when Unknown_Pragma =>
13843 raise Program_Error;
13846 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13847 -- until AI is formally approved.
13849 -- Check_Order_Dependence;
13852 when Pragma_Exit => null;
13853 end Analyze_Pragma;
13855 -------------------
13856 -- Check_Enabled --
13857 -------------------
13859 function Check_Enabled (Nam : Name_Id) return Boolean is
13863 -- Loop through entries in check policy list
13865 PP := Opt.Check_Policy_List;
13867 -- If there are no specific entries that matched, then we let the
13868 -- setting of assertions govern. Note that this provides the needed
13869 -- compatibility with the RM for the cases of assertion, invariant,
13870 -- precondition, predicate, and postcondition.
13873 return Assertions_Enabled;
13875 -- Here we have an entry see if it matches
13879 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13882 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13883 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13884 when Name_On | Name_Check =>
13886 when Name_Off | Name_Ignore =>
13889 raise Program_Error;
13893 PP := Next_Pragma (PP);
13900 ---------------------------------
13901 -- Delay_Config_Pragma_Analyze --
13902 ---------------------------------
13904 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13906 return Pragma_Name (N) = Name_Interrupt_State
13908 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13909 end Delay_Config_Pragma_Analyze;
13911 -------------------------
13912 -- Get_Base_Subprogram --
13913 -------------------------
13915 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13916 Result : Entity_Id;
13919 -- Follow subprogram renaming chain
13922 while Is_Subprogram (Result)
13924 Nkind (Parent (Declaration_Node (Result))) =
13925 N_Subprogram_Renaming_Declaration
13926 and then Present (Alias (Result))
13928 Result := Alias (Result);
13932 end Get_Base_Subprogram;
13938 procedure Initialize is
13943 -----------------------------
13944 -- Is_Config_Static_String --
13945 -----------------------------
13947 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13949 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13950 -- This is an internal recursive function that is just like the outer
13951 -- function except that it adds the string to the name buffer rather
13952 -- than placing the string in the name buffer.
13954 ------------------------------
13955 -- Add_Config_Static_String --
13956 ------------------------------
13958 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13965 if Nkind (N) = N_Op_Concat then
13966 if Add_Config_Static_String (Left_Opnd (N)) then
13967 N := Right_Opnd (N);
13973 if Nkind (N) /= N_String_Literal then
13974 Error_Msg_N ("string literal expected for pragma argument", N);
13978 for J in 1 .. String_Length (Strval (N)) loop
13979 C := Get_String_Char (Strval (N), J);
13981 if not In_Character_Range (C) then
13983 ("string literal contains invalid wide character",
13984 Sloc (N) + 1 + Source_Ptr (J));
13988 Add_Char_To_Name_Buffer (Get_Character (C));
13993 end Add_Config_Static_String;
13995 -- Start of processing for Is_Config_Static_String
14000 return Add_Config_Static_String (Arg);
14001 end Is_Config_Static_String;
14003 -----------------------------------------
14004 -- Is_Non_Significant_Pragma_Reference --
14005 -----------------------------------------
14007 -- This function makes use of the following static table which indicates
14008 -- whether a given pragma is significant.
14010 -- -1 indicates that references in any argument position are significant
14011 -- 0 indicates that appearance in any argument is not significant
14012 -- +n indicates that appearance as argument n is significant, but all
14013 -- other arguments are not significant
14014 -- 99 special processing required (e.g. for pragma Check)
14016 Sig_Flags : constant array (Pragma_Id) of Int :=
14017 (Pragma_AST_Entry => -1,
14018 Pragma_Abort_Defer => -1,
14019 Pragma_Ada_83 => -1,
14020 Pragma_Ada_95 => -1,
14021 Pragma_Ada_05 => -1,
14022 Pragma_Ada_2005 => -1,
14023 Pragma_Ada_12 => -1,
14024 Pragma_Ada_2012 => -1,
14025 Pragma_All_Calls_Remote => -1,
14026 Pragma_Annotate => -1,
14027 Pragma_Assert => -1,
14028 Pragma_Assertion_Policy => 0,
14029 Pragma_Assume_No_Invalid_Values => 0,
14030 Pragma_Asynchronous => -1,
14031 Pragma_Atomic => 0,
14032 Pragma_Atomic_Components => 0,
14033 Pragma_Attach_Handler => -1,
14034 Pragma_Check => 99,
14035 Pragma_Check_Name => 0,
14036 Pragma_Check_Policy => 0,
14037 Pragma_CIL_Constructor => -1,
14038 Pragma_CPP_Class => 0,
14039 Pragma_CPP_Constructor => 0,
14040 Pragma_CPP_Virtual => 0,
14041 Pragma_CPP_Vtable => 0,
14043 Pragma_C_Pass_By_Copy => 0,
14044 Pragma_Comment => 0,
14045 Pragma_Common_Object => -1,
14046 Pragma_Compile_Time_Error => -1,
14047 Pragma_Compile_Time_Warning => -1,
14048 Pragma_Compiler_Unit => 0,
14049 Pragma_Complete_Representation => 0,
14050 Pragma_Complex_Representation => 0,
14051 Pragma_Component_Alignment => -1,
14052 Pragma_Controlled => 0,
14053 Pragma_Convention => 0,
14054 Pragma_Convention_Identifier => 0,
14055 Pragma_Debug => -1,
14056 Pragma_Debug_Policy => 0,
14057 Pragma_Detect_Blocking => -1,
14058 Pragma_Default_Storage_Pool => -1,
14059 Pragma_Dimension => -1,
14060 Pragma_Discard_Names => 0,
14061 Pragma_Elaborate => -1,
14062 Pragma_Elaborate_All => -1,
14063 Pragma_Elaborate_Body => -1,
14064 Pragma_Elaboration_Checks => -1,
14065 Pragma_Eliminate => -1,
14066 Pragma_Export => -1,
14067 Pragma_Export_Exception => -1,
14068 Pragma_Export_Function => -1,
14069 Pragma_Export_Object => -1,
14070 Pragma_Export_Procedure => -1,
14071 Pragma_Export_Value => -1,
14072 Pragma_Export_Valued_Procedure => -1,
14073 Pragma_Extend_System => -1,
14074 Pragma_Extensions_Allowed => -1,
14075 Pragma_External => -1,
14076 Pragma_Favor_Top_Level => -1,
14077 Pragma_External_Name_Casing => -1,
14078 Pragma_Fast_Math => -1,
14079 Pragma_Finalize_Storage_Only => 0,
14080 Pragma_Float_Representation => 0,
14081 Pragma_Ident => -1,
14082 Pragma_Implemented => -1,
14083 Pragma_Implicit_Packing => 0,
14084 Pragma_Import => +2,
14085 Pragma_Import_Exception => 0,
14086 Pragma_Import_Function => 0,
14087 Pragma_Import_Object => 0,
14088 Pragma_Import_Procedure => 0,
14089 Pragma_Import_Valued_Procedure => 0,
14090 Pragma_Independent => 0,
14091 Pragma_Independent_Components => 0,
14092 Pragma_Initialize_Scalars => -1,
14093 Pragma_Inline => 0,
14094 Pragma_Inline_Always => 0,
14095 Pragma_Inline_Generic => 0,
14096 Pragma_Inspection_Point => -1,
14097 Pragma_Interface => +2,
14098 Pragma_Interface_Name => +2,
14099 Pragma_Interrupt_Handler => -1,
14100 Pragma_Interrupt_Priority => -1,
14101 Pragma_Interrupt_State => -1,
14102 Pragma_Invariant => -1,
14103 Pragma_Java_Constructor => -1,
14104 Pragma_Java_Interface => -1,
14105 Pragma_Keep_Names => 0,
14106 Pragma_License => -1,
14107 Pragma_Link_With => -1,
14108 Pragma_Linker_Alias => -1,
14109 Pragma_Linker_Constructor => -1,
14110 Pragma_Linker_Destructor => -1,
14111 Pragma_Linker_Options => -1,
14112 Pragma_Linker_Section => -1,
14114 Pragma_Locking_Policy => -1,
14115 Pragma_Long_Float => -1,
14116 Pragma_Machine_Attribute => -1,
14118 Pragma_Main_Storage => -1,
14119 Pragma_Memory_Size => -1,
14120 Pragma_No_Return => 0,
14121 Pragma_No_Body => 0,
14122 Pragma_No_Run_Time => -1,
14123 Pragma_No_Strict_Aliasing => -1,
14124 Pragma_Normalize_Scalars => -1,
14125 Pragma_Obsolescent => 0,
14126 Pragma_Optimize => -1,
14127 Pragma_Optimize_Alignment => -1,
14128 Pragma_Ordered => 0,
14131 Pragma_Passive => -1,
14132 Pragma_Preelaborable_Initialization => -1,
14133 Pragma_Polling => -1,
14134 Pragma_Persistent_BSS => 0,
14135 Pragma_Postcondition => -1,
14136 Pragma_Precondition => -1,
14137 Pragma_Predicate => -1,
14138 Pragma_Preelaborate => -1,
14139 Pragma_Preelaborate_05 => -1,
14140 Pragma_Priority => -1,
14141 Pragma_Priority_Specific_Dispatching => -1,
14142 Pragma_Profile => 0,
14143 Pragma_Profile_Warnings => 0,
14144 Pragma_Propagate_Exceptions => -1,
14145 Pragma_Psect_Object => -1,
14147 Pragma_Pure_05 => -1,
14148 Pragma_Pure_Function => -1,
14149 Pragma_Queuing_Policy => -1,
14150 Pragma_Ravenscar => -1,
14151 Pragma_Relative_Deadline => -1,
14152 Pragma_Remote_Call_Interface => -1,
14153 Pragma_Remote_Types => -1,
14154 Pragma_Restricted_Run_Time => -1,
14155 Pragma_Restriction_Warnings => -1,
14156 Pragma_Restrictions => -1,
14157 Pragma_Reviewable => -1,
14158 Pragma_Short_Circuit_And_Or => -1,
14159 Pragma_Share_Generic => -1,
14160 Pragma_Shared => -1,
14161 Pragma_Shared_Passive => -1,
14162 Pragma_Short_Descriptors => 0,
14163 Pragma_Source_File_Name => -1,
14164 Pragma_Source_File_Name_Project => -1,
14165 Pragma_Source_Reference => -1,
14166 Pragma_Storage_Size => -1,
14167 Pragma_Storage_Unit => -1,
14168 Pragma_Static_Elaboration_Desired => -1,
14169 Pragma_Stream_Convert => -1,
14170 Pragma_Style_Checks => -1,
14171 Pragma_Subtitle => -1,
14172 Pragma_Suppress => 0,
14173 Pragma_Suppress_Exception_Locations => 0,
14174 Pragma_Suppress_All => -1,
14175 Pragma_Suppress_Debug_Info => 0,
14176 Pragma_Suppress_Initialization => 0,
14177 Pragma_System_Name => -1,
14178 Pragma_Task_Dispatching_Policy => -1,
14179 Pragma_Task_Info => -1,
14180 Pragma_Task_Name => -1,
14181 Pragma_Task_Storage => 0,
14182 Pragma_Thread_Local_Storage => 0,
14183 Pragma_Time_Slice => -1,
14184 Pragma_Title => -1,
14185 Pragma_Unchecked_Union => 0,
14186 Pragma_Unimplemented_Unit => -1,
14187 Pragma_Universal_Aliasing => -1,
14188 Pragma_Universal_Data => -1,
14189 Pragma_Unmodified => -1,
14190 Pragma_Unreferenced => -1,
14191 Pragma_Unreferenced_Objects => -1,
14192 Pragma_Unreserve_All_Interrupts => -1,
14193 Pragma_Unsuppress => 0,
14194 Pragma_Use_VADS_Size => -1,
14195 Pragma_Validity_Checks => -1,
14196 Pragma_Volatile => 0,
14197 Pragma_Volatile_Components => 0,
14198 Pragma_Warnings => -1,
14199 Pragma_Weak_External => -1,
14200 Pragma_Wide_Character_Encoding => 0,
14201 Unknown_Pragma => 0);
14203 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14212 if Nkind (P) /= N_Pragma_Argument_Association then
14216 Id := Get_Pragma_Id (Parent (P));
14217 C := Sig_Flags (Id);
14229 -- For pragma Check, the first argument is not significant,
14230 -- the second and the third (if present) arguments are
14233 when Pragma_Check =>
14235 P = First (Pragma_Argument_Associations (Parent (P)));
14238 raise Program_Error;
14242 A := First (Pragma_Argument_Associations (Parent (P)));
14243 for J in 1 .. C - 1 loop
14251 return A = P; -- is this wrong way round ???
14254 end Is_Non_Significant_Pragma_Reference;
14256 ------------------------------
14257 -- Is_Pragma_String_Literal --
14258 ------------------------------
14260 -- This function returns true if the corresponding pragma argument is a
14261 -- static string expression. These are the only cases in which string
14262 -- literals can appear as pragma arguments. We also allow a string literal
14263 -- as the first argument to pragma Assert (although it will of course
14264 -- always generate a type error).
14266 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14267 Pragn : constant Node_Id := Parent (Par);
14268 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14269 Pname : constant Name_Id := Pragma_Name (Pragn);
14275 N := First (Assoc);
14282 if Pname = Name_Assert then
14285 elsif Pname = Name_Export then
14288 elsif Pname = Name_Ident then
14291 elsif Pname = Name_Import then
14294 elsif Pname = Name_Interface_Name then
14297 elsif Pname = Name_Linker_Alias then
14300 elsif Pname = Name_Linker_Section then
14303 elsif Pname = Name_Machine_Attribute then
14306 elsif Pname = Name_Source_File_Name then
14309 elsif Pname = Name_Source_Reference then
14312 elsif Pname = Name_Title then
14315 elsif Pname = Name_Subtitle then
14321 end Is_Pragma_String_Literal;
14323 --------------------------------------
14324 -- Process_Compilation_Unit_Pragmas --
14325 --------------------------------------
14327 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14329 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14330 -- strange because it comes at the end of the unit. Rational has the
14331 -- same name for a pragma, but treats it as a program unit pragma, In
14332 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14333 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14334 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14335 -- the context clause to ensure the correct processing.
14337 if Has_Pragma_Suppress_All (N) then
14338 Prepend_To (Context_Items (N),
14339 Make_Pragma (Sloc (N),
14340 Chars => Name_Suppress,
14341 Pragma_Argument_Associations => New_List (
14342 Make_Pragma_Argument_Association (Sloc (N),
14343 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14346 -- Nothing else to do at the current time!
14348 end Process_Compilation_Unit_Pragmas;
14359 --------------------------------
14360 -- Set_Encoded_Interface_Name --
14361 --------------------------------
14363 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14364 Str : constant String_Id := Strval (S);
14365 Len : constant Int := String_Length (Str);
14370 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14373 -- Stores encoded value of character code CC. The encoding we use an
14374 -- underscore followed by four lower case hex digits.
14380 procedure Encode is
14382 Store_String_Char (Get_Char_Code ('_'));
14384 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14386 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14388 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14390 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14393 -- Start of processing for Set_Encoded_Interface_Name
14396 -- If first character is asterisk, this is a link name, and we leave it
14397 -- completely unmodified. We also ignore null strings (the latter case
14398 -- happens only in error cases) and no encoding should occur for Java or
14399 -- AAMP interface names.
14402 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14403 or else VM_Target /= No_VM
14404 or else AAMP_On_Target
14406 Set_Interface_Name (E, S);
14411 CC := Get_String_Char (Str, J);
14413 exit when not In_Character_Range (CC);
14415 C := Get_Character (CC);
14417 exit when C /= '_' and then C /= '$'
14418 and then C not in '0' .. '9'
14419 and then C not in 'a' .. 'z'
14420 and then C not in 'A' .. 'Z';
14423 Set_Interface_Name (E, S);
14431 -- Here we need to encode. The encoding we use as follows:
14432 -- three underscores + four hex digits (lower case)
14436 for J in 1 .. String_Length (Str) loop
14437 CC := Get_String_Char (Str, J);
14439 if not In_Character_Range (CC) then
14442 C := Get_Character (CC);
14444 if C = '_' or else C = '$'
14445 or else C in '0' .. '9'
14446 or else C in 'a' .. 'z'
14447 or else C in 'A' .. 'Z'
14449 Store_String_Char (CC);
14456 Set_Interface_Name (E,
14457 Make_String_Literal (Sloc (S),
14458 Strval => End_String));
14460 end Set_Encoded_Interface_Name;
14462 -------------------
14463 -- Set_Unit_Name --
14464 -------------------
14466 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14471 if Nkind (N) = N_Identifier
14472 and then Nkind (With_Item) = N_Identifier
14474 Set_Entity (N, Entity (With_Item));
14476 elsif Nkind (N) = N_Selected_Component then
14477 Change_Selected_Component_To_Expanded_Name (N);
14478 Set_Entity (N, Entity (With_Item));
14479 Set_Entity (Selector_Name (N), Entity (N));
14481 Pref := Prefix (N);
14482 Scop := Scope (Entity (N));
14483 while Nkind (Pref) = N_Selected_Component loop
14484 Change_Selected_Component_To_Expanded_Name (Pref);
14485 Set_Entity (Selector_Name (Pref), Scop);
14486 Set_Entity (Pref, Scop);
14487 Pref := Prefix (Pref);
14488 Scop := Scope (Scop);
14491 Set_Entity (Pref, Scop);