1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Atree; use Atree;
33 with Casing; use Casing;
34 with Checks; use Checks;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Elists; use Elists;
39 with Errout; use Errout;
40 with Exp_Ch7; use Exp_Ch7;
41 with Exp_Dist; use Exp_Dist;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet.Sp; use Namet.Sp;
46 with Nlists; use Nlists;
47 with Nmake; use Nmake;
49 with Output; use Output;
50 with Par_SCO; use Par_SCO;
51 with Restrict; use Restrict;
52 with Rident; use Rident;
53 with Rtsfind; use Rtsfind;
55 with Sem_Aux; use Sem_Aux;
56 with Sem_Ch3; use Sem_Ch3;
57 with Sem_Ch6; use Sem_Ch6;
58 with Sem_Ch8; use Sem_Ch8;
59 with Sem_Ch12; use Sem_Ch12;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Disp; use Sem_Disp;
62 with Sem_Dist; use Sem_Dist;
63 with Sem_Elim; use Sem_Elim;
64 with Sem_Eval; use Sem_Eval;
65 with Sem_Intr; use Sem_Intr;
66 with Sem_Mech; use Sem_Mech;
67 with Sem_Res; use Sem_Res;
68 with Sem_Type; use Sem_Type;
69 with Sem_Util; use Sem_Util;
70 with Sem_VFpt; use Sem_VFpt;
71 with Sem_Warn; use Sem_Warn;
72 with Stand; use Stand;
73 with Sinfo; use Sinfo;
74 with Sinfo.CN; use Sinfo.CN;
75 with Sinput; use Sinput;
76 with Snames; use Snames;
77 with Stringt; use Stringt;
78 with Stylesw; use Stylesw;
80 with Targparm; use Targparm;
81 with Tbuild; use Tbuild;
83 with Uintp; use Uintp;
84 with Uname; use Uname;
85 with Urealp; use Urealp;
86 with Validsw; use Validsw;
87 with Warnsw; use Warnsw;
89 package body Sem_Prag is
91 ----------------------------------------------
92 -- Common Handling of Import-Export Pragmas --
93 ----------------------------------------------
95 -- In the following section, a number of Import_xxx and Export_xxx pragmas
96 -- are defined by GNAT. These are compatible with the DEC pragmas of the
97 -- same name, and all have the following common form and processing:
100 -- [Internal =>] LOCAL_NAME
101 -- [, [External =>] EXTERNAL_SYMBOL]
102 -- [, other optional parameters ]);
105 -- [Internal =>] LOCAL_NAME
106 -- [, [External =>] EXTERNAL_SYMBOL]
107 -- [, other optional parameters ]);
109 -- EXTERNAL_SYMBOL ::=
111 -- | static_string_EXPRESSION
113 -- The internal LOCAL_NAME designates the entity that is imported or
114 -- exported, and must refer to an entity in the current declarative
115 -- part (as required by the rules for LOCAL_NAME).
117 -- The external linker name is designated by the External parameter if
118 -- given, or the Internal parameter if not (if there is no External
119 -- parameter, the External parameter is a copy of the Internal name).
121 -- If the External parameter is given as a string, then this string is
122 -- treated as an external name (exactly as though it had been given as an
123 -- External_Name parameter for a normal Import pragma).
125 -- If the External parameter is given as an identifier (or there is no
126 -- External parameter, so that the Internal identifier is used), then
127 -- the external name is the characters of the identifier, translated
128 -- to all upper case letters for OpenVMS versions of GNAT, and to all
129 -- lower case letters for all other versions
131 -- Note: the external name specified or implied by any of these special
132 -- Import_xxx or Export_xxx pragmas override an external or link name
133 -- specified in a previous Import or Export pragma.
135 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
136 -- named notation, following the standard rules for subprogram calls, i.e.
137 -- parameters can be given in any order if named notation is used, and
138 -- positional and named notation can be mixed, subject to the rule that all
139 -- positional parameters must appear first.
141 -- Note: All these pragmas are implemented exactly following the DEC design
142 -- and implementation and are intended to be fully compatible with the use
143 -- of these pragmas in the DEC Ada compiler.
145 --------------------------------------------
146 -- Checking for Duplicated External Names --
147 --------------------------------------------
149 -- It is suspicious if two separate Export pragmas use the same external
150 -- name. The following table is used to diagnose this situation so that
151 -- an appropriate warning can be issued.
153 -- The Node_Id stored is for the N_String_Literal node created to hold
154 -- the value of the external name. The Sloc of this node is used to
155 -- cross-reference the location of the duplication.
157 package Externals is new Table.Table (
158 Table_Component_Type => Node_Id,
159 Table_Index_Type => Int,
160 Table_Low_Bound => 0,
161 Table_Initial => 100,
162 Table_Increment => 100,
163 Table_Name => "Name_Externals");
165 -------------------------------------
166 -- Local Subprograms and Variables --
167 -------------------------------------
169 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
170 -- This routine is used for possible casing adjustment of an explicit
171 -- external name supplied as a string literal (the node N), according to
172 -- the casing requirement of Opt.External_Name_Casing. If this is set to
173 -- As_Is, then the string literal is returned unchanged, but if it is set
174 -- to Uppercase or Lowercase, then a new string literal with appropriate
175 -- casing is constructed.
177 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
178 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
179 -- original one, following the renaming chain) is returned. Otherwise the
180 -- entity is returned unchanged. Should be in Einfo???
183 -- This is a dummy function called by the processing for pragma Reviewable.
184 -- It is there for assisting front end debugging. By placing a Reviewable
185 -- pragma in the source program, a breakpoint on rv catches this place in
186 -- the source, allowing convenient stepping to the point of interest.
188 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
189 -- Place semantic information on the argument of an Elaborate/Elaborate_All
190 -- pragma. Entity name for unit and its parents is taken from item in
191 -- previous with_clause that mentions the unit.
193 -------------------------------
194 -- Adjust_External_Name_Case --
195 -------------------------------
197 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
201 -- Adjust case of literal if required
203 if Opt.External_Name_Exp_Casing = As_Is then
207 -- Copy existing string
213 for J in 1 .. String_Length (Strval (N)) loop
214 CC := Get_String_Char (Strval (N), J);
216 if Opt.External_Name_Exp_Casing = Uppercase
217 and then CC >= Get_Char_Code ('a')
218 and then CC <= Get_Char_Code ('z')
220 Store_String_Char (CC - 32);
222 elsif Opt.External_Name_Exp_Casing = Lowercase
223 and then CC >= Get_Char_Code ('A')
224 and then CC <= Get_Char_Code ('Z')
226 Store_String_Char (CC + 32);
229 Store_String_Char (CC);
234 Make_String_Literal (Sloc (N),
235 Strval => End_String);
237 end Adjust_External_Name_Case;
239 ------------------------------
240 -- Analyze_PPC_In_Decl_Part --
241 ------------------------------
243 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
244 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
247 -- Install formals and push subprogram spec onto scope stack so that we
248 -- can see the formals from the pragma.
253 -- Preanalyze the boolean expression, we treat this as a spec expression
254 -- (i.e. similar to a default expression).
256 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 -- Go to renamed subprogram if present, since convention applies to
3018 -- the actual renamed entity, not to the renaming entity. If the
3019 -- subprogram is inherited, go to parent subprogram.
3021 if Is_Subprogram (E)
3022 and then Present (Alias (E))
3024 if Nkind (Parent (Declaration_Node (E))) =
3025 N_Subprogram_Renaming_Declaration
3027 if Scope (E) /= Scope (Alias (E)) then
3029 ("cannot apply pragma% to non-local entity&#", E);
3034 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3035 N_Private_Extension_Declaration)
3036 and then Scope (E) = Scope (Alias (E))
3040 -- Return the parent subprogram the entity was inherited from
3046 -- Check that we are not applying this to a specless body
3048 if Is_Subprogram (E)
3049 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3052 ("pragma% requires separate spec and must come before body");
3055 -- Check that we are not applying this to a named constant
3057 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3058 Error_Msg_Name_1 := Pname;
3060 ("cannot apply pragma% to named constant!",
3061 Get_Pragma_Arg (Arg2));
3063 ("\supply appropriate type for&!", Arg2);
3066 if Ekind (E) = E_Enumeration_Literal then
3067 Error_Pragma ("enumeration literal not allowed for pragma%");
3070 -- Check for rep item appearing too early or too late
3072 if Etype (E) = Any_Type
3073 or else Rep_Item_Too_Early (E, N)
3077 elsif Present (Underlying_Type (E)) then
3078 E := Underlying_Type (E);
3081 if Rep_Item_Too_Late (E, N) then
3085 if Has_Convention_Pragma (E) then
3086 Diagnose_Multiple_Pragmas (E);
3088 elsif Convention (E) = Convention_Protected
3089 or else Ekind (Scope (E)) = E_Protected_Type
3092 ("a protected operation cannot be given a different convention",
3096 -- For Intrinsic, a subprogram is required
3098 if C = Convention_Intrinsic
3099 and then not Is_Subprogram (E)
3100 and then not Is_Generic_Subprogram (E)
3103 ("second argument of pragma% must be a subprogram", Arg2);
3106 -- For Stdcall, a subprogram, variable or subprogram type is required
3108 if C = Convention_Stdcall
3109 and then not Is_Subprogram (E)
3110 and then not Is_Generic_Subprogram (E)
3111 and then Ekind (E) /= E_Variable
3114 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3117 ("second argument of pragma% must be subprogram (type)",
3121 if not Is_Subprogram (E)
3122 and then not Is_Generic_Subprogram (E)
3124 Set_Convention_From_Pragma (E);
3127 Check_First_Subtype (Arg2);
3128 Set_Convention_From_Pragma (Base_Type (E));
3130 -- For subprograms, we must set the convention on the
3131 -- internally generated directly designated type as well.
3133 if Ekind (E) = E_Access_Subprogram_Type then
3134 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3138 -- For the subprogram case, set proper convention for all homonyms
3139 -- in same scope and the same declarative part, i.e. the same
3140 -- compilation unit.
3143 Comp_Unit := Get_Source_Unit (E);
3144 Set_Convention_From_Pragma (E);
3146 -- Treat a pragma Import as an implicit body, for GPS use
3148 if Prag_Id = Pragma_Import then
3149 Generate_Reference (E, Id, 'b');
3152 -- Loop through the homonyms of the pragma argument's entity
3157 exit when No (E1) or else Scope (E1) /= Current_Scope;
3159 -- Do not set the pragma on inherited operations or on formal
3162 if Comes_From_Source (E1)
3163 and then Comp_Unit = Get_Source_Unit (E1)
3164 and then not Is_Formal_Subprogram (E1)
3165 and then Nkind (Original_Node (Parent (E1))) /=
3166 N_Full_Type_Declaration
3168 if Present (Alias (E1))
3169 and then Scope (E1) /= Scope (Alias (E1))
3172 ("cannot apply pragma% to non-local entity& declared#",
3176 Set_Convention_From_Pragma (E1);
3178 if Prag_Id = Pragma_Import then
3179 Generate_Reference (E1, Id, 'b');
3183 -- For aspect case, do NOT apply to homonyms
3185 exit when From_Aspect_Specification (N);
3188 end Process_Convention;
3190 -----------------------------------------------------
3191 -- Process_Extended_Import_Export_Exception_Pragma --
3192 -----------------------------------------------------
3194 procedure Process_Extended_Import_Export_Exception_Pragma
3195 (Arg_Internal : Node_Id;
3196 Arg_External : Node_Id;
3204 if not OpenVMS_On_Target then
3206 ("?pragma% ignored (applies only to Open'V'M'S)");
3209 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3210 Def_Id := Entity (Arg_Internal);
3212 if Ekind (Def_Id) /= E_Exception then
3214 ("pragma% must refer to declared exception", Arg_Internal);
3217 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3219 if Present (Arg_Form) then
3220 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3223 if Present (Arg_Form)
3224 and then Chars (Arg_Form) = Name_Ada
3228 Set_Is_VMS_Exception (Def_Id);
3229 Set_Exception_Code (Def_Id, No_Uint);
3232 if Present (Arg_Code) then
3233 if not Is_VMS_Exception (Def_Id) then
3235 ("Code option for pragma% not allowed for Ada case",
3239 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3240 Code_Val := Expr_Value (Arg_Code);
3242 if not UI_Is_In_Int_Range (Code_Val) then
3244 ("Code option for pragma% must be in 32-bit range",
3248 Set_Exception_Code (Def_Id, Code_Val);
3251 end Process_Extended_Import_Export_Exception_Pragma;
3253 -------------------------------------------------
3254 -- Process_Extended_Import_Export_Internal_Arg --
3255 -------------------------------------------------
3257 procedure Process_Extended_Import_Export_Internal_Arg
3258 (Arg_Internal : Node_Id := Empty)
3261 if No (Arg_Internal) then
3262 Error_Pragma ("Internal parameter required for pragma%");
3265 if Nkind (Arg_Internal) = N_Identifier then
3268 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3269 and then (Prag_Id = Pragma_Import_Function
3271 Prag_Id = Pragma_Export_Function)
3277 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3280 Check_Arg_Is_Local_Name (Arg_Internal);
3281 end Process_Extended_Import_Export_Internal_Arg;
3283 --------------------------------------------------
3284 -- Process_Extended_Import_Export_Object_Pragma --
3285 --------------------------------------------------
3287 procedure Process_Extended_Import_Export_Object_Pragma
3288 (Arg_Internal : Node_Id;
3289 Arg_External : Node_Id;
3295 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3296 Def_Id := Entity (Arg_Internal);
3298 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3300 ("pragma% must designate an object", Arg_Internal);
3303 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3305 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3308 ("previous Common/Psect_Object applies, pragma % not permitted",
3312 if Rep_Item_Too_Late (Def_Id, N) then
3316 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3318 if Present (Arg_Size) then
3319 Check_Arg_Is_External_Name (Arg_Size);
3322 -- Export_Object case
3324 if Prag_Id = Pragma_Export_Object then
3325 if not Is_Library_Level_Entity (Def_Id) then
3327 ("argument for pragma% must be library level entity",
3331 if Ekind (Current_Scope) = E_Generic_Package then
3332 Error_Pragma ("pragma& cannot appear in a generic unit");
3335 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3337 ("exported object must have compile time known size",
3341 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3342 Error_Msg_N ("?duplicate Export_Object pragma", N);
3344 Set_Exported (Def_Id, Arg_Internal);
3347 -- Import_Object case
3350 if Is_Concurrent_Type (Etype (Def_Id)) then
3352 ("cannot use pragma% for task/protected object",
3356 if Ekind (Def_Id) = E_Constant then
3358 ("cannot import a constant", Arg_Internal);
3361 if Warn_On_Export_Import
3362 and then Has_Discriminants (Etype (Def_Id))
3365 ("imported value must be initialized?", Arg_Internal);
3368 if Warn_On_Export_Import
3369 and then Is_Access_Type (Etype (Def_Id))
3372 ("cannot import object of an access type?", Arg_Internal);
3375 if Warn_On_Export_Import
3376 and then Is_Imported (Def_Id)
3379 ("?duplicate Import_Object pragma", N);
3381 -- Check for explicit initialization present. Note that an
3382 -- initialization generated by the code generator, e.g. for an
3383 -- access type, does not count here.
3385 elsif Present (Expression (Parent (Def_Id)))
3388 (Original_Node (Expression (Parent (Def_Id))))
3390 Error_Msg_Sloc := Sloc (Def_Id);
3392 ("imported entities cannot be initialized (RM B.1(24))",
3393 "\no initialization allowed for & declared#", Arg1);
3395 Set_Imported (Def_Id);
3396 Note_Possible_Modification (Arg_Internal, Sure => False);
3399 end Process_Extended_Import_Export_Object_Pragma;
3401 ------------------------------------------------------
3402 -- Process_Extended_Import_Export_Subprogram_Pragma --
3403 ------------------------------------------------------
3405 procedure Process_Extended_Import_Export_Subprogram_Pragma
3406 (Arg_Internal : Node_Id;
3407 Arg_External : Node_Id;
3408 Arg_Parameter_Types : Node_Id;
3409 Arg_Result_Type : Node_Id := Empty;
3410 Arg_Mechanism : Node_Id;
3411 Arg_Result_Mechanism : Node_Id := Empty;
3412 Arg_First_Optional_Parameter : Node_Id := Empty)
3418 Ambiguous : Boolean;
3422 function Same_Base_Type
3424 Formal : Entity_Id) return Boolean;
3425 -- Determines if Ptype references the type of Formal. Note that only
3426 -- the base types need to match according to the spec. Ptype here is
3427 -- the argument from the pragma, which is either a type name, or an
3428 -- access attribute.
3430 --------------------
3431 -- Same_Base_Type --
3432 --------------------
3434 function Same_Base_Type
3436 Formal : Entity_Id) return Boolean
3438 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3442 -- Case where pragma argument is typ'Access
3444 if Nkind (Ptype) = N_Attribute_Reference
3445 and then Attribute_Name (Ptype) = Name_Access
3447 Pref := Prefix (Ptype);
3450 if not Is_Entity_Name (Pref)
3451 or else Entity (Pref) = Any_Type
3456 -- We have a match if the corresponding argument is of an
3457 -- anonymous access type, and its designated type matches the
3458 -- type of the prefix of the access attribute
3460 return Ekind (Ftyp) = E_Anonymous_Access_Type
3461 and then Base_Type (Entity (Pref)) =
3462 Base_Type (Etype (Designated_Type (Ftyp)));
3464 -- Case where pragma argument is a type name
3469 if not Is_Entity_Name (Ptype)
3470 or else Entity (Ptype) = Any_Type
3475 -- We have a match if the corresponding argument is of the type
3476 -- given in the pragma (comparing base types)
3478 return Base_Type (Entity (Ptype)) = Ftyp;
3482 -- Start of processing for
3483 -- Process_Extended_Import_Export_Subprogram_Pragma
3486 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3490 -- Loop through homonyms (overloadings) of the entity
3492 Hom_Id := Entity (Arg_Internal);
3493 while Present (Hom_Id) loop
3494 Def_Id := Get_Base_Subprogram (Hom_Id);
3496 -- We need a subprogram in the current scope
3498 if not Is_Subprogram (Def_Id)
3499 or else Scope (Def_Id) /= Current_Scope
3506 -- Pragma cannot apply to subprogram body
3508 if Is_Subprogram (Def_Id)
3509 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3513 ("pragma% requires separate spec"
3514 & " and must come before body");
3517 -- Test result type if given, note that the result type
3518 -- parameter can only be present for the function cases.
3520 if Present (Arg_Result_Type)
3521 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3525 elsif Etype (Def_Id) /= Standard_Void_Type
3527 (Pname = Name_Export_Procedure
3529 Pname = Name_Import_Procedure)
3533 -- Test parameter types if given. Note that this parameter
3534 -- has not been analyzed (and must not be, since it is
3535 -- semantic nonsense), so we get it as the parser left it.
3537 elsif Present (Arg_Parameter_Types) then
3538 Check_Matching_Types : declare
3543 Formal := First_Formal (Def_Id);
3545 if Nkind (Arg_Parameter_Types) = N_Null then
3546 if Present (Formal) then
3550 -- A list of one type, e.g. (List) is parsed as
3551 -- a parenthesized expression.
3553 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3554 and then Paren_Count (Arg_Parameter_Types) = 1
3557 or else Present (Next_Formal (Formal))
3562 Same_Base_Type (Arg_Parameter_Types, Formal);
3565 -- A list of more than one type is parsed as a aggregate
3567 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3568 and then Paren_Count (Arg_Parameter_Types) = 0
3570 Ptype := First (Expressions (Arg_Parameter_Types));
3571 while Present (Ptype) or else Present (Formal) loop
3574 or else not Same_Base_Type (Ptype, Formal)
3579 Next_Formal (Formal);
3584 -- Anything else is of the wrong form
3588 ("wrong form for Parameter_Types parameter",
3589 Arg_Parameter_Types);
3591 end Check_Matching_Types;
3594 -- Match is now False if the entry we found did not match
3595 -- either a supplied Parameter_Types or Result_Types argument
3601 -- Ambiguous case, the flag Ambiguous shows if we already
3602 -- detected this and output the initial messages.
3605 if not Ambiguous then
3607 Error_Msg_Name_1 := Pname;
3609 ("pragma% does not uniquely identify subprogram!",
3611 Error_Msg_Sloc := Sloc (Ent);
3612 Error_Msg_N ("matching subprogram #!", N);
3616 Error_Msg_Sloc := Sloc (Def_Id);
3617 Error_Msg_N ("matching subprogram #!", N);
3622 Hom_Id := Homonym (Hom_Id);
3625 -- See if we found an entry
3628 if not Ambiguous then
3629 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3631 ("pragma% cannot be given for generic subprogram");
3634 ("pragma% does not identify local subprogram");
3641 -- Import pragmas must be for imported entities
3643 if Prag_Id = Pragma_Import_Function
3645 Prag_Id = Pragma_Import_Procedure
3647 Prag_Id = Pragma_Import_Valued_Procedure
3649 if not Is_Imported (Ent) then
3651 ("pragma Import or Interface must precede pragma%");
3654 -- Here we have the Export case which can set the entity as exported
3656 -- But does not do so if the specified external name is null, since
3657 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3658 -- compatible) to request no external name.
3660 elsif Nkind (Arg_External) = N_String_Literal
3661 and then String_Length (Strval (Arg_External)) = 0
3665 -- In all other cases, set entity as exported
3668 Set_Exported (Ent, Arg_Internal);
3671 -- Special processing for Valued_Procedure cases
3673 if Prag_Id = Pragma_Import_Valued_Procedure
3675 Prag_Id = Pragma_Export_Valued_Procedure
3677 Formal := First_Formal (Ent);
3680 Error_Pragma ("at least one parameter required for pragma%");
3682 elsif Ekind (Formal) /= E_Out_Parameter then
3683 Error_Pragma ("first parameter must have mode out for pragma%");
3686 Set_Is_Valued_Procedure (Ent);
3690 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3692 -- Process Result_Mechanism argument if present. We have already
3693 -- checked that this is only allowed for the function case.
3695 if Present (Arg_Result_Mechanism) then
3696 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3699 -- Process Mechanism parameter if present. Note that this parameter
3700 -- is not analyzed, and must not be analyzed since it is semantic
3701 -- nonsense, so we get it in exactly as the parser left it.
3703 if Present (Arg_Mechanism) then
3711 -- A single mechanism association without a formal parameter
3712 -- name is parsed as a parenthesized expression. All other
3713 -- cases are parsed as aggregates, so we rewrite the single
3714 -- parameter case as an aggregate for consistency.
3716 if Nkind (Arg_Mechanism) /= N_Aggregate
3717 and then Paren_Count (Arg_Mechanism) = 1
3719 Rewrite (Arg_Mechanism,
3720 Make_Aggregate (Sloc (Arg_Mechanism),
3721 Expressions => New_List (
3722 Relocate_Node (Arg_Mechanism))));
3725 -- Case of only mechanism name given, applies to all formals
3727 if Nkind (Arg_Mechanism) /= N_Aggregate then
3728 Formal := First_Formal (Ent);
3729 while Present (Formal) loop
3730 Set_Mechanism_Value (Formal, Arg_Mechanism);
3731 Next_Formal (Formal);
3734 -- Case of list of mechanism associations given
3737 if Null_Record_Present (Arg_Mechanism) then
3739 ("inappropriate form for Mechanism parameter",
3743 -- Deal with positional ones first
3745 Formal := First_Formal (Ent);
3747 if Present (Expressions (Arg_Mechanism)) then
3748 Mname := First (Expressions (Arg_Mechanism));
3749 while Present (Mname) loop
3752 ("too many mechanism associations", Mname);
3755 Set_Mechanism_Value (Formal, Mname);
3756 Next_Formal (Formal);
3761 -- Deal with named entries
3763 if Present (Component_Associations (Arg_Mechanism)) then
3764 Massoc := First (Component_Associations (Arg_Mechanism));
3765 while Present (Massoc) loop
3766 Choice := First (Choices (Massoc));
3768 if Nkind (Choice) /= N_Identifier
3769 or else Present (Next (Choice))
3772 ("incorrect form for mechanism association",
3776 Formal := First_Formal (Ent);
3780 ("parameter name & not present", Choice);
3783 if Chars (Choice) = Chars (Formal) then
3785 (Formal, Expression (Massoc));
3787 -- Set entity on identifier (needed by ASIS)
3789 Set_Entity (Choice, Formal);
3794 Next_Formal (Formal);
3804 -- Process First_Optional_Parameter argument if present. We have
3805 -- already checked that this is only allowed for the Import case.
3807 if Present (Arg_First_Optional_Parameter) then
3808 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3810 ("first optional parameter must be formal parameter name",
3811 Arg_First_Optional_Parameter);
3814 Formal := First_Formal (Ent);
3818 ("specified formal parameter& not found",
3819 Arg_First_Optional_Parameter);
3822 exit when Chars (Formal) =
3823 Chars (Arg_First_Optional_Parameter);
3825 Next_Formal (Formal);
3828 Set_First_Optional_Parameter (Ent, Formal);
3830 -- Check specified and all remaining formals have right form
3832 while Present (Formal) loop
3833 if Ekind (Formal) /= E_In_Parameter then
3835 ("optional formal& is not of mode in!",
3836 Arg_First_Optional_Parameter, Formal);
3839 Dval := Default_Value (Formal);
3843 ("optional formal& does not have default value!",
3844 Arg_First_Optional_Parameter, Formal);
3846 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3851 ("default value for optional formal& is non-static!",
3852 Arg_First_Optional_Parameter, Formal);
3856 Set_Is_Optional_Parameter (Formal);
3857 Next_Formal (Formal);
3860 end Process_Extended_Import_Export_Subprogram_Pragma;
3862 --------------------------
3863 -- Process_Generic_List --
3864 --------------------------
3866 procedure Process_Generic_List is
3871 Check_No_Identifiers;
3872 Check_At_Least_N_Arguments (1);
3875 while Present (Arg) loop
3876 Exp := Get_Pragma_Arg (Arg);
3879 if not Is_Entity_Name (Exp)
3881 (not Is_Generic_Instance (Entity (Exp))
3883 not Is_Generic_Unit (Entity (Exp)))
3886 ("pragma% argument must be name of generic unit/instance",
3892 end Process_Generic_List;
3894 ------------------------------------
3895 -- Process_Import_Predefined_Type --
3896 ------------------------------------
3898 procedure Process_Import_Predefined_Type is
3899 Loc : constant Source_Ptr := Sloc (N);
3901 Ftyp : Node_Id := Empty;
3907 String_To_Name_Buffer (Strval (Expression (Arg3)));
3910 Elmt := First_Elmt (Predefined_Float_Types);
3911 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
3915 Ftyp := Node (Elmt);
3917 if Present (Ftyp) then
3919 -- Don't build a derived type declaration, because predefined C
3920 -- types have no declaration anywhere, so cannot really be named.
3921 -- Instead build a full type declaration, starting with an
3922 -- appropriate type definition is built
3924 if Is_Floating_Point_Type (Ftyp) then
3925 Def := Make_Floating_Point_Definition (Loc,
3926 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
3927 Make_Real_Range_Specification (Loc,
3928 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
3929 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
3931 -- Should never have a predefined type we cannot handle
3934 raise Program_Error;
3937 -- Build and insert a Full_Type_Declaration, which will be
3938 -- analyzed as soon as this list entry has been analyzed.
3940 Decl := Make_Full_Type_Declaration (Loc,
3941 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
3942 Type_Definition => Def);
3944 Insert_After (N, Decl);
3945 Mark_Rewrite_Insertion (Decl);
3948 Error_Pragma_Arg ("no matching type found for pragma%",
3951 end Process_Import_Predefined_Type;
3953 ---------------------------------
3954 -- Process_Import_Or_Interface --
3955 ---------------------------------
3957 procedure Process_Import_Or_Interface is
3963 Process_Convention (C, Def_Id);
3964 Kill_Size_Check_Code (Def_Id);
3965 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
3967 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3969 -- We do not permit Import to apply to a renaming declaration
3971 if Present (Renamed_Object (Def_Id)) then
3973 ("pragma% not allowed for object renaming", Arg2);
3975 -- User initialization is not allowed for imported object, but
3976 -- the object declaration may contain a default initialization,
3977 -- that will be discarded. Note that an explicit initialization
3978 -- only counts if it comes from source, otherwise it is simply
3979 -- the code generator making an implicit initialization explicit.
3981 elsif Present (Expression (Parent (Def_Id)))
3982 and then Comes_From_Source (Expression (Parent (Def_Id)))
3984 Error_Msg_Sloc := Sloc (Def_Id);
3986 ("no initialization allowed for declaration of& #",
3987 "\imported entities cannot be initialized (RM B.1(24))",
3991 Set_Imported (Def_Id);
3992 Process_Interface_Name (Def_Id, Arg3, Arg4);
3994 -- Note that we do not set Is_Public here. That's because we
3995 -- only want to set it if there is no address clause, and we
3996 -- don't know that yet, so we delay that processing till
3999 -- pragma Import completes deferred constants
4001 if Ekind (Def_Id) = E_Constant then
4002 Set_Has_Completion (Def_Id);
4005 -- It is not possible to import a constant of an unconstrained
4006 -- array type (e.g. string) because there is no simple way to
4007 -- write a meaningful subtype for it.
4009 if Is_Array_Type (Etype (Def_Id))
4010 and then not Is_Constrained (Etype (Def_Id))
4013 ("imported constant& must have a constrained subtype",
4018 elsif Is_Subprogram (Def_Id)
4019 or else Is_Generic_Subprogram (Def_Id)
4021 -- If the name is overloaded, pragma applies to all of the denoted
4022 -- entities in the same declarative part.
4025 while Present (Hom_Id) loop
4026 Def_Id := Get_Base_Subprogram (Hom_Id);
4028 -- Ignore inherited subprograms because the pragma will apply
4029 -- to the parent operation, which is the one called.
4031 if Is_Overloadable (Def_Id)
4032 and then Present (Alias (Def_Id))
4036 -- If it is not a subprogram, it must be in an outer scope and
4037 -- pragma does not apply.
4039 elsif not Is_Subprogram (Def_Id)
4040 and then not Is_Generic_Subprogram (Def_Id)
4044 -- The pragma does not apply to primitives of interfaces
4046 elsif Is_Dispatching_Operation (Def_Id)
4047 and then Present (Find_Dispatching_Type (Def_Id))
4048 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4052 -- Verify that the homonym is in the same declarative part (not
4053 -- just the same scope).
4055 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4056 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4061 Set_Imported (Def_Id);
4063 -- Reject an Import applied to an abstract subprogram
4065 if Is_Subprogram (Def_Id)
4066 and then Is_Abstract_Subprogram (Def_Id)
4068 Error_Msg_Sloc := Sloc (Def_Id);
4070 ("cannot import abstract subprogram& declared#",
4074 -- Special processing for Convention_Intrinsic
4076 if C = Convention_Intrinsic then
4078 -- Link_Name argument not allowed for intrinsic
4082 Set_Is_Intrinsic_Subprogram (Def_Id);
4084 -- If no external name is present, then check that this
4085 -- is a valid intrinsic subprogram. If an external name
4086 -- is present, then this is handled by the back end.
4089 Check_Intrinsic_Subprogram
4090 (Def_Id, Get_Pragma_Arg (Arg2));
4094 -- All interfaced procedures need an external symbol created
4095 -- for them since they are always referenced from another
4098 Set_Is_Public (Def_Id);
4100 -- Verify that the subprogram does not have a completion
4101 -- through a renaming declaration. For other completions the
4102 -- pragma appears as a too late representation.
4105 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4109 and then Nkind (Decl) = N_Subprogram_Declaration
4110 and then Present (Corresponding_Body (Decl))
4111 and then Nkind (Unit_Declaration_Node
4112 (Corresponding_Body (Decl))) =
4113 N_Subprogram_Renaming_Declaration
4115 Error_Msg_Sloc := Sloc (Def_Id);
4117 ("cannot import&, renaming already provided for " &
4118 "declaration #", N, Def_Id);
4122 Set_Has_Completion (Def_Id);
4123 Process_Interface_Name (Def_Id, Arg3, Arg4);
4126 if Is_Compilation_Unit (Hom_Id) then
4128 -- Its possible homonyms are not affected by the pragma.
4129 -- Such homonyms might be present in the context of other
4130 -- units being compiled.
4135 Hom_Id := Homonym (Hom_Id);
4139 -- When the convention is Java or CIL, we also allow Import to be
4140 -- given for packages, generic packages, exceptions, record
4141 -- components, and access to subprograms.
4143 elsif (C = Convention_Java or else C = Convention_CIL)
4145 (Is_Package_Or_Generic_Package (Def_Id)
4146 or else Ekind (Def_Id) = E_Exception
4147 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4148 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4150 Set_Imported (Def_Id);
4151 Set_Is_Public (Def_Id);
4152 Process_Interface_Name (Def_Id, Arg3, Arg4);
4154 -- Import a CPP class
4156 elsif Is_Record_Type (Def_Id)
4157 and then C = Convention_CPP
4159 -- Types treated as CPP classes are treated as limited, but we
4160 -- don't require them to be declared this way. A warning is issued
4161 -- to encourage the user to declare them as limited. This is not
4162 -- an error, for compatibility reasons, because these types have
4163 -- been supported this way for some time.
4165 if not Is_Limited_Type (Def_Id) then
4167 ("imported 'C'P'P type should be " &
4168 "explicitly declared limited?",
4169 Get_Pragma_Arg (Arg2));
4171 ("\type will be considered limited",
4172 Get_Pragma_Arg (Arg2));
4175 Set_Is_CPP_Class (Def_Id);
4176 Set_Is_Limited_Record (Def_Id);
4178 -- Imported CPP types must not have discriminants (because C++
4179 -- classes do not have discriminants).
4181 if Has_Discriminants (Def_Id) then
4183 ("imported 'C'P'P type cannot have discriminants",
4184 First (Discriminant_Specifications
4185 (Declaration_Node (Def_Id))));
4188 -- Components of imported CPP types must not have default
4189 -- expressions because the constructor (if any) is on the
4193 Tdef : constant Node_Id :=
4194 Type_Definition (Declaration_Node (Def_Id));
4199 if Nkind (Tdef) = N_Record_Definition then
4200 Clist := Component_List (Tdef);
4203 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4204 Clist := Component_List (Record_Extension_Part (Tdef));
4207 if Present (Clist) then
4208 Comp := First (Component_Items (Clist));
4209 while Present (Comp) loop
4210 if Present (Expression (Comp)) then
4212 ("component of imported 'C'P'P type cannot have" &
4213 " default expression", Expression (Comp));
4221 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4223 Check_Arg_Count (3);
4224 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4226 Process_Import_Predefined_Type;
4230 ("second argument of pragma% must be object, subprogram" &
4231 " or incomplete type",
4235 -- If this pragma applies to a compilation unit, then the unit, which
4236 -- is a subprogram, does not require (or allow) a body. We also do
4237 -- not need to elaborate imported procedures.
4239 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4241 Cunit : constant Node_Id := Parent (Parent (N));
4243 Set_Body_Required (Cunit, False);
4246 end Process_Import_Or_Interface;
4248 --------------------
4249 -- Process_Inline --
4250 --------------------
4252 procedure Process_Inline (Active : Boolean) is
4259 Effective : Boolean := False;
4260 -- Set True if inline has some effect, i.e. if there is at least one
4261 -- subprogram set as inlined as a result of the use of the pragma.
4263 procedure Make_Inline (Subp : Entity_Id);
4264 -- Subp is the defining unit name of the subprogram declaration. Set
4265 -- the flag, as well as the flag in the corresponding body, if there
4268 procedure Set_Inline_Flags (Subp : Entity_Id);
4269 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4270 -- Has_Pragma_Inline_Always for the Inline_Always case.
4272 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4273 -- Returns True if it can be determined at this stage that inlining
4274 -- is not possible, for example if the body is available and contains
4275 -- exception handlers, we prevent inlining, since otherwise we can
4276 -- get undefined symbols at link time. This function also emits a
4277 -- warning if front-end inlining is enabled and the pragma appears
4280 -- ??? is business with link symbols still valid, or does it relate
4281 -- to front end ZCX which is being phased out ???
4283 ---------------------------
4284 -- Inlining_Not_Possible --
4285 ---------------------------
4287 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4288 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4292 if Nkind (Decl) = N_Subprogram_Body then
4293 Stats := Handled_Statement_Sequence (Decl);
4294 return Present (Exception_Handlers (Stats))
4295 or else Present (At_End_Proc (Stats));
4297 elsif Nkind (Decl) = N_Subprogram_Declaration
4298 and then Present (Corresponding_Body (Decl))
4300 if Front_End_Inlining
4301 and then Analyzed (Corresponding_Body (Decl))
4303 Error_Msg_N ("pragma appears too late, ignored?", N);
4306 -- If the subprogram is a renaming as body, the body is just a
4307 -- call to the renamed subprogram, and inlining is trivially
4311 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4312 N_Subprogram_Renaming_Declaration
4318 Handled_Statement_Sequence
4319 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4322 Present (Exception_Handlers (Stats))
4323 or else Present (At_End_Proc (Stats));
4327 -- If body is not available, assume the best, the check is
4328 -- performed again when compiling enclosing package bodies.
4332 end Inlining_Not_Possible;
4338 procedure Make_Inline (Subp : Entity_Id) is
4339 Kind : constant Entity_Kind := Ekind (Subp);
4340 Inner_Subp : Entity_Id := Subp;
4343 -- Ignore if bad type, avoid cascaded error
4345 if Etype (Subp) = Any_Type then
4349 -- Ignore if all inlining is suppressed
4351 elsif Suppress_All_Inlining then
4355 -- If inlining is not possible, for now do not treat as an error
4357 elsif Inlining_Not_Possible (Subp) then
4361 -- Here we have a candidate for inlining, but we must exclude
4362 -- derived operations. Otherwise we would end up trying to inline
4363 -- a phantom declaration, and the result would be to drag in a
4364 -- body which has no direct inlining associated with it. That
4365 -- would not only be inefficient but would also result in the
4366 -- backend doing cross-unit inlining in cases where it was
4367 -- definitely inappropriate to do so.
4369 -- However, a simple Comes_From_Source test is insufficient, since
4370 -- we do want to allow inlining of generic instances which also do
4371 -- not come from source. We also need to recognize specs generated
4372 -- by the front-end for bodies that carry the pragma. Finally,
4373 -- predefined operators do not come from source but are not
4374 -- inlineable either.
4376 elsif Is_Generic_Instance (Subp)
4377 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4381 elsif not Comes_From_Source (Subp)
4382 and then Scope (Subp) /= Standard_Standard
4388 -- The referenced entity must either be the enclosing entity, or
4389 -- an entity declared within the current open scope.
4391 if Present (Scope (Subp))
4392 and then Scope (Subp) /= Current_Scope
4393 and then Subp /= Current_Scope
4396 ("argument of% must be entity in current scope", Assoc);
4400 -- Processing for procedure, operator or function. If subprogram
4401 -- is aliased (as for an instance) indicate that the renamed
4402 -- entity (if declared in the same unit) is inlined.
4404 if Is_Subprogram (Subp) then
4405 Inner_Subp := Ultimate_Alias (Inner_Subp);
4407 if In_Same_Source_Unit (Subp, Inner_Subp) then
4408 Set_Inline_Flags (Inner_Subp);
4410 Decl := Parent (Parent (Inner_Subp));
4412 if Nkind (Decl) = N_Subprogram_Declaration
4413 and then Present (Corresponding_Body (Decl))
4415 Set_Inline_Flags (Corresponding_Body (Decl));
4417 elsif Is_Generic_Instance (Subp) then
4419 -- Indicate that the body needs to be created for
4420 -- inlining subsequent calls. The instantiation node
4421 -- follows the declaration of the wrapper package
4424 if Scope (Subp) /= Standard_Standard
4426 Need_Subprogram_Instance_Body
4427 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4437 -- For a generic subprogram set flag as well, for use at the point
4438 -- of instantiation, to determine whether the body should be
4441 elsif Is_Generic_Subprogram (Subp) then
4442 Set_Inline_Flags (Subp);
4445 -- Literals are by definition inlined
4447 elsif Kind = E_Enumeration_Literal then
4450 -- Anything else is an error
4454 ("expect subprogram name for pragma%", Assoc);
4458 ----------------------
4459 -- Set_Inline_Flags --
4460 ----------------------
4462 procedure Set_Inline_Flags (Subp : Entity_Id) is
4465 Set_Is_Inlined (Subp);
4468 if not Has_Pragma_Inline (Subp) then
4469 Set_Has_Pragma_Inline (Subp);
4473 if Prag_Id = Pragma_Inline_Always then
4474 Set_Has_Pragma_Inline_Always (Subp);
4476 end Set_Inline_Flags;
4478 -- Start of processing for Process_Inline
4481 Check_No_Identifiers;
4482 Check_At_Least_N_Arguments (1);
4485 Inline_Processing_Required := True;
4489 while Present (Assoc) loop
4490 Subp_Id := Get_Pragma_Arg (Assoc);
4494 if Is_Entity_Name (Subp_Id) then
4495 Subp := Entity (Subp_Id);
4497 if Subp = Any_Id then
4499 -- If previous error, avoid cascaded errors
4507 -- For the pragma case, climb homonym chain. This is
4508 -- what implements allowing the pragma in the renaming
4509 -- case, with the result applying to the ancestors.
4511 if not From_Aspect_Specification (N) then
4512 while Present (Homonym (Subp))
4513 and then Scope (Homonym (Subp)) = Current_Scope
4515 Make_Inline (Homonym (Subp));
4516 Subp := Homonym (Subp);
4524 ("inappropriate argument for pragma%", Assoc);
4527 and then Warn_On_Redundant_Constructs
4528 and then not Suppress_All_Inlining
4530 if Inlining_Not_Possible (Subp) then
4532 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4535 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4543 ----------------------------
4544 -- Process_Interface_Name --
4545 ----------------------------
4547 procedure Process_Interface_Name
4548 (Subprogram_Def : Entity_Id;
4554 String_Val : String_Id;
4556 procedure Check_Form_Of_Interface_Name
4558 Ext_Name_Case : Boolean);
4559 -- SN is a string literal node for an interface name. This routine
4560 -- performs some minimal checks that the name is reasonable. In
4561 -- particular that no spaces or other obviously incorrect characters
4562 -- appear. This is only a warning, since any characters are allowed.
4563 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4565 ----------------------------------
4566 -- Check_Form_Of_Interface_Name --
4567 ----------------------------------
4569 procedure Check_Form_Of_Interface_Name
4571 Ext_Name_Case : Boolean)
4573 S : constant String_Id := Strval (Expr_Value_S (SN));
4574 SL : constant Nat := String_Length (S);
4579 Error_Msg_N ("interface name cannot be null string", SN);
4582 for J in 1 .. SL loop
4583 C := Get_String_Char (S, J);
4585 -- Look for dubious character and issue unconditional warning.
4586 -- Definitely dubious if not in character range.
4588 if not In_Character_Range (C)
4590 -- For all cases except CLI target,
4591 -- commas, spaces and slashes are dubious (in CLI, we use
4592 -- commas and backslashes in external names to specify
4593 -- assembly version and public key, while slashes and spaces
4594 -- can be used in names to mark nested classes and
4597 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4598 and then (Get_Character (C) = ','
4600 Get_Character (C) = '\'))
4601 or else (VM_Target /= CLI_Target
4602 and then (Get_Character (C) = ' '
4604 Get_Character (C) = '/'))
4607 ("?interface name contains illegal character",
4608 Sloc (SN) + Source_Ptr (J));
4611 end Check_Form_Of_Interface_Name;
4613 -- Start of processing for Process_Interface_Name
4616 if No (Link_Arg) then
4617 if No (Ext_Arg) then
4618 if VM_Target = CLI_Target
4619 and then Ekind (Subprogram_Def) = E_Package
4620 and then Nkind (Parent (Subprogram_Def)) =
4621 N_Package_Specification
4622 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4627 (Generic_Parent (Parent (Subprogram_Def))));
4632 elsif Chars (Ext_Arg) = Name_Link_Name then
4634 Link_Nam := Expression (Ext_Arg);
4637 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4638 Ext_Nam := Expression (Ext_Arg);
4643 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4644 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4645 Ext_Nam := Expression (Ext_Arg);
4646 Link_Nam := Expression (Link_Arg);
4649 -- Check expressions for external name and link name are static
4651 if Present (Ext_Nam) then
4652 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4653 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4655 -- Verify that external name is not the name of a local entity,
4656 -- which would hide the imported one and could lead to run-time
4657 -- surprises. The problem can only arise for entities declared in
4658 -- a package body (otherwise the external name is fully qualified
4659 -- and will not conflict).
4667 if Prag_Id = Pragma_Import then
4668 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4670 E := Entity_Id (Get_Name_Table_Info (Nam));
4672 if Nam /= Chars (Subprogram_Def)
4673 and then Present (E)
4674 and then not Is_Overloadable (E)
4675 and then Is_Immediately_Visible (E)
4676 and then not Is_Imported (E)
4677 and then Ekind (Scope (E)) = E_Package
4680 while Present (Par) loop
4681 if Nkind (Par) = N_Package_Body then
4682 Error_Msg_Sloc := Sloc (E);
4684 ("imported entity is hidden by & declared#",
4689 Par := Parent (Par);
4696 if Present (Link_Nam) then
4697 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4698 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4701 -- If there is no link name, just set the external name
4703 if No (Link_Nam) then
4704 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4706 -- For the Link_Name case, the given literal is preceded by an
4707 -- asterisk, which indicates to GCC that the given name should be
4708 -- taken literally, and in particular that no prepending of
4709 -- underlines should occur, even in systems where this is the
4715 if VM_Target = No_VM then
4716 Store_String_Char (Get_Char_Code ('*'));
4719 String_Val := Strval (Expr_Value_S (Link_Nam));
4720 Store_String_Chars (String_Val);
4722 Make_String_Literal (Sloc (Link_Nam),
4723 Strval => End_String);
4726 Set_Encoded_Interface_Name
4727 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4729 -- We allow duplicated export names in CIL, as they are always
4730 -- enclosed in a namespace that differentiates them, and overloaded
4731 -- entities are supported by the VM.
4733 if Convention (Subprogram_Def) /= Convention_CIL then
4734 Check_Duplicated_Export_Name (Link_Nam);
4736 end Process_Interface_Name;
4738 -----------------------------------------
4739 -- Process_Interrupt_Or_Attach_Handler --
4740 -----------------------------------------
4742 procedure Process_Interrupt_Or_Attach_Handler is
4743 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4744 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4745 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4748 Set_Is_Interrupt_Handler (Handler_Proc);
4750 -- If the pragma is not associated with a handler procedure within a
4751 -- protected type, then it must be for a nonprotected procedure for
4752 -- the AAMP target, in which case we don't associate a representation
4753 -- item with the procedure's scope.
4755 if Ekind (Proc_Scope) = E_Protected_Type then
4756 if Prag_Id = Pragma_Interrupt_Handler
4758 Prag_Id = Pragma_Attach_Handler
4760 Record_Rep_Item (Proc_Scope, N);
4763 end Process_Interrupt_Or_Attach_Handler;
4765 --------------------------------------------------
4766 -- Process_Restrictions_Or_Restriction_Warnings --
4767 --------------------------------------------------
4769 -- Note: some of the simple identifier cases were handled in par-prag,
4770 -- but it is harmless (and more straightforward) to simply handle all
4771 -- cases here, even if it means we repeat a bit of work in some cases.
4773 procedure Process_Restrictions_Or_Restriction_Warnings
4777 R_Id : Restriction_Id;
4782 procedure Check_Unit_Name (N : Node_Id);
4783 -- Checks unit name parameter for No_Dependence. Returns if it has
4784 -- an appropriate form, otherwise raises pragma argument error.
4786 ---------------------
4787 -- Check_Unit_Name --
4788 ---------------------
4790 procedure Check_Unit_Name (N : Node_Id) is
4792 if Nkind (N) = N_Selected_Component then
4793 Check_Unit_Name (Prefix (N));
4794 Check_Unit_Name (Selector_Name (N));
4796 elsif Nkind (N) = N_Identifier then
4801 ("wrong form for unit name for No_Dependence", N);
4803 end Check_Unit_Name;
4805 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4808 -- Ignore all Restrictions pragma in CodePeer mode
4810 if CodePeer_Mode then
4814 Check_Ada_83_Warning;
4815 Check_At_Least_N_Arguments (1);
4816 Check_Valid_Configuration_Pragma;
4819 while Present (Arg) loop
4821 Expr := Get_Pragma_Arg (Arg);
4823 -- Case of no restriction identifier present
4825 if Id = No_Name then
4826 if Nkind (Expr) /= N_Identifier then
4828 ("invalid form for restriction", Arg);
4833 (Process_Restriction_Synonyms (Expr));
4835 if R_Id not in All_Boolean_Restrictions then
4836 Error_Msg_Name_1 := Pname;
4838 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4840 -- Check for possible misspelling
4842 for J in Restriction_Id loop
4844 Rnm : constant String := Restriction_Id'Image (J);
4847 Name_Buffer (1 .. Rnm'Length) := Rnm;
4848 Name_Len := Rnm'Length;
4849 Set_Casing (All_Lower_Case);
4851 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4853 (Identifier_Casing (Current_Source_File));
4854 Error_Msg_String (1 .. Rnm'Length) :=
4855 Name_Buffer (1 .. Name_Len);
4856 Error_Msg_Strlen := Rnm'Length;
4857 Error_Msg_N -- CODEFIX
4858 ("\possible misspelling of ""~""",
4859 Get_Pragma_Arg (Arg));
4868 if Implementation_Restriction (R_Id) then
4869 Check_Restriction (No_Implementation_Restrictions, Arg);
4872 -- If this is a warning, then set the warning unless we already
4873 -- have a real restriction active (we never want a warning to
4874 -- override a real restriction).
4877 if not Restriction_Active (R_Id) then
4878 Set_Restriction (R_Id, N);
4879 Restriction_Warnings (R_Id) := True;
4882 -- If real restriction case, then set it and make sure that the
4883 -- restriction warning flag is off, since a real restriction
4884 -- always overrides a warning.
4887 Set_Restriction (R_Id, N);
4888 Restriction_Warnings (R_Id) := False;
4891 -- Check for obsolescent restrictions in Ada 2005 mode
4894 and then Ada_Version >= Ada_2005
4895 and then (R_Id = No_Asynchronous_Control
4897 R_Id = No_Unchecked_Deallocation
4899 R_Id = No_Unchecked_Conversion)
4901 Check_Restriction (No_Obsolescent_Features, N);
4904 -- A very special case that must be processed here: pragma
4905 -- Restrictions (No_Exceptions) turns off all run-time
4906 -- checking. This is a bit dubious in terms of the formal
4907 -- language definition, but it is what is intended by RM
4908 -- H.4(12). Restriction_Warnings never affects generated code
4909 -- so this is done only in the real restriction case.
4911 if R_Id = No_Exceptions and then not Warn then
4912 Scope_Suppress := (others => True);
4915 -- Case of No_Dependence => unit-name. Note that the parser
4916 -- already made the necessary entry in the No_Dependence table.
4918 elsif Id = Name_No_Dependence then
4919 Check_Unit_Name (Expr);
4921 -- All other cases of restriction identifier present
4924 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4925 Analyze_And_Resolve (Expr, Any_Integer);
4927 if R_Id not in All_Parameter_Restrictions then
4929 ("invalid restriction parameter identifier", Arg);
4931 elsif not Is_OK_Static_Expression (Expr) then
4932 Flag_Non_Static_Expr
4933 ("value must be static expression!", Expr);
4936 elsif not Is_Integer_Type (Etype (Expr))
4937 or else Expr_Value (Expr) < 0
4940 ("value must be non-negative integer", Arg);
4943 -- Restriction pragma is active
4945 Val := Expr_Value (Expr);
4947 if not UI_Is_In_Int_Range (Val) then
4949 ("pragma ignored, value too large?", Arg);
4952 -- Warning case. If the real restriction is active, then we
4953 -- ignore the request, since warning never overrides a real
4954 -- restriction. Otherwise we set the proper warning. Note that
4955 -- this circuit sets the warning again if it is already set,
4956 -- which is what we want, since the constant may have changed.
4959 if not Restriction_Active (R_Id) then
4961 (R_Id, N, Integer (UI_To_Int (Val)));
4962 Restriction_Warnings (R_Id) := True;
4965 -- Real restriction case, set restriction and make sure warning
4966 -- flag is off since real restriction always overrides warning.
4969 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4970 Restriction_Warnings (R_Id) := False;
4976 end Process_Restrictions_Or_Restriction_Warnings;
4978 ---------------------------------
4979 -- Process_Suppress_Unsuppress --
4980 ---------------------------------
4982 -- Note: this procedure makes entries in the check suppress data
4983 -- structures managed by Sem. See spec of package Sem for full
4984 -- details on how we handle recording of check suppression.
4986 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4991 In_Package_Spec : constant Boolean :=
4992 Is_Package_Or_Generic_Package (Current_Scope)
4993 and then not In_Package_Body (Current_Scope);
4995 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4996 -- Used to suppress a single check on the given entity
4998 --------------------------------
4999 -- Suppress_Unsuppress_Echeck --
5000 --------------------------------
5002 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5004 Set_Checks_May_Be_Suppressed (E);
5006 if In_Package_Spec then
5007 Push_Global_Suppress_Stack_Entry
5010 Suppress => Suppress_Case);
5013 Push_Local_Suppress_Stack_Entry
5016 Suppress => Suppress_Case);
5019 -- If this is a first subtype, and the base type is distinct,
5020 -- then also set the suppress flags on the base type.
5022 if Is_First_Subtype (E)
5023 and then Etype (E) /= E
5025 Suppress_Unsuppress_Echeck (Etype (E), C);
5027 end Suppress_Unsuppress_Echeck;
5029 -- Start of processing for Process_Suppress_Unsuppress
5032 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
5033 -- we want to generate checks for analysis purposes, as set by -gnatC
5035 if CodePeer_Mode and then Comes_From_Source (N) then
5039 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5040 -- declarative part or a package spec (RM 11.5(5)).
5042 if not Is_Configuration_Pragma then
5043 Check_Is_In_Decl_Part_Or_Package_Spec;
5046 Check_At_Least_N_Arguments (1);
5047 Check_At_Most_N_Arguments (2);
5048 Check_No_Identifier (Arg1);
5049 Check_Arg_Is_Identifier (Arg1);
5051 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5053 if C = No_Check_Id then
5055 ("argument of pragma% is not valid check name", Arg1);
5058 if not Suppress_Case
5059 and then (C = All_Checks or else C = Overflow_Check)
5061 Opt.Overflow_Checks_Unsuppressed := True;
5064 if Arg_Count = 1 then
5066 -- Make an entry in the local scope suppress table. This is the
5067 -- table that directly shows the current value of the scope
5068 -- suppress check for any check id value.
5070 if C = All_Checks then
5072 -- For All_Checks, we set all specific predefined checks with
5073 -- the exception of Elaboration_Check, which is handled
5074 -- specially because of not wanting All_Checks to have the
5075 -- effect of deactivating static elaboration order processing.
5077 for J in Scope_Suppress'Range loop
5078 if J /= Elaboration_Check then
5079 Scope_Suppress (J) := Suppress_Case;
5083 -- If not All_Checks, and predefined check, then set appropriate
5084 -- scope entry. Note that we will set Elaboration_Check if this
5085 -- is explicitly specified.
5087 elsif C in Predefined_Check_Id then
5088 Scope_Suppress (C) := Suppress_Case;
5091 -- Also make an entry in the Local_Entity_Suppress table
5093 Push_Local_Suppress_Stack_Entry
5096 Suppress => Suppress_Case);
5098 -- Case of two arguments present, where the check is suppressed for
5099 -- a specified entity (given as the second argument of the pragma)
5102 -- This is obsolescent in Ada 2005 mode
5104 if Ada_Version >= Ada_2005 then
5105 Check_Restriction (No_Obsolescent_Features, Arg2);
5108 Check_Optional_Identifier (Arg2, Name_On);
5109 E_Id := Get_Pragma_Arg (Arg2);
5112 if not Is_Entity_Name (E_Id) then
5114 ("second argument of pragma% must be entity name", Arg2);
5123 -- Enforce RM 11.5(7) which requires that for a pragma that
5124 -- appears within a package spec, the named entity must be
5125 -- within the package spec. We allow the package name itself
5126 -- to be mentioned since that makes sense, although it is not
5127 -- strictly allowed by 11.5(7).
5130 and then E /= Current_Scope
5131 and then Scope (E) /= Current_Scope
5134 ("entity in pragma% is not in package spec (RM 11.5(7))",
5138 -- Loop through homonyms. As noted below, in the case of a package
5139 -- spec, only homonyms within the package spec are considered.
5142 Suppress_Unsuppress_Echeck (E, C);
5144 if Is_Generic_Instance (E)
5145 and then Is_Subprogram (E)
5146 and then Present (Alias (E))
5148 Suppress_Unsuppress_Echeck (Alias (E), C);
5151 -- Move to next homonym if not aspect spec case
5153 exit when From_Aspect_Specification (N);
5157 -- If we are within a package specification, the pragma only
5158 -- applies to homonyms in the same scope.
5160 exit when In_Package_Spec
5161 and then Scope (E) /= Current_Scope;
5164 end Process_Suppress_Unsuppress;
5170 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5172 if Is_Imported (E) then
5174 ("cannot export entity& that was previously imported", Arg);
5176 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5178 ("cannot export entity& that has an address clause", Arg);
5181 Set_Is_Exported (E);
5183 -- Generate a reference for entity explicitly, because the
5184 -- identifier may be overloaded and name resolution will not
5187 Generate_Reference (E, Arg);
5189 -- Deal with exporting non-library level entity
5191 if not Is_Library_Level_Entity (E) then
5193 -- Not allowed at all for subprograms
5195 if Is_Subprogram (E) then
5196 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5198 -- Otherwise set public and statically allocated
5202 Set_Is_Statically_Allocated (E);
5204 -- Warn if the corresponding W flag is set and the pragma comes
5205 -- from source. The latter may not be true e.g. on VMS where we
5206 -- expand export pragmas for exception codes associated with
5207 -- imported or exported exceptions. We do not want to generate
5208 -- a warning for something that the user did not write.
5210 if Warn_On_Export_Import
5211 and then Comes_From_Source (Arg)
5214 ("?& has been made static as a result of Export", Arg, E);
5216 ("\this usage is non-standard and non-portable", Arg);
5221 if Warn_On_Export_Import and then Is_Type (E) then
5222 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5225 if Warn_On_Export_Import and Inside_A_Generic then
5227 ("all instances of& will have the same external name?", Arg, E);
5231 ----------------------------------------------
5232 -- Set_Extended_Import_Export_External_Name --
5233 ----------------------------------------------
5235 procedure Set_Extended_Import_Export_External_Name
5236 (Internal_Ent : Entity_Id;
5237 Arg_External : Node_Id)
5239 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5243 if No (Arg_External) then
5247 Check_Arg_Is_External_Name (Arg_External);
5249 if Nkind (Arg_External) = N_String_Literal then
5250 if String_Length (Strval (Arg_External)) = 0 then
5253 New_Name := Adjust_External_Name_Case (Arg_External);
5256 elsif Nkind (Arg_External) = N_Identifier then
5257 New_Name := Get_Default_External_Name (Arg_External);
5259 -- Check_Arg_Is_External_Name should let through only identifiers and
5260 -- string literals or static string expressions (which are folded to
5261 -- string literals).
5264 raise Program_Error;
5267 -- If we already have an external name set (by a prior normal Import
5268 -- or Export pragma), then the external names must match
5270 if Present (Interface_Name (Internal_Ent)) then
5271 Check_Matching_Internal_Names : declare
5272 S1 : constant String_Id := Strval (Old_Name);
5273 S2 : constant String_Id := Strval (New_Name);
5276 -- Called if names do not match
5282 procedure Mismatch is
5284 Error_Msg_Sloc := Sloc (Old_Name);
5286 ("external name does not match that given #",
5290 -- Start of processing for Check_Matching_Internal_Names
5293 if String_Length (S1) /= String_Length (S2) then
5297 for J in 1 .. String_Length (S1) loop
5298 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5303 end Check_Matching_Internal_Names;
5305 -- Otherwise set the given name
5308 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5309 Check_Duplicated_Export_Name (New_Name);
5311 end Set_Extended_Import_Export_External_Name;
5317 procedure Set_Imported (E : Entity_Id) is
5319 -- Error message if already imported or exported
5321 if Is_Exported (E) or else Is_Imported (E) then
5323 -- Error if being set Exported twice
5325 if Is_Exported (E) then
5326 Error_Msg_NE ("entity& was previously exported", N, E);
5328 -- OK if Import/Interface case
5330 elsif Import_Interface_Present (N) then
5333 -- Error if being set Imported twice
5336 Error_Msg_NE ("entity& was previously imported", N, E);
5339 Error_Msg_Name_1 := Pname;
5341 ("\(pragma% applies to all previous entities)", N);
5343 Error_Msg_Sloc := Sloc (E);
5344 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5346 -- Here if not previously imported or exported, OK to import
5349 Set_Is_Imported (E);
5351 -- If the entity is an object that is not at the library level,
5352 -- then it is statically allocated. We do not worry about objects
5353 -- with address clauses in this context since they are not really
5354 -- imported in the linker sense.
5357 and then not Is_Library_Level_Entity (E)
5358 and then No (Address_Clause (E))
5360 Set_Is_Statically_Allocated (E);
5367 -------------------------
5368 -- Set_Mechanism_Value --
5369 -------------------------
5371 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5372 -- analyzed, since it is semantic nonsense), so we get it in the exact
5373 -- form created by the parser.
5375 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5378 Mech_Name_Id : Name_Id;
5380 procedure Bad_Class;
5381 -- Signal bad descriptor class name
5383 procedure Bad_Mechanism;
5384 -- Signal bad mechanism name
5390 procedure Bad_Class is
5392 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5395 -------------------------
5396 -- Bad_Mechanism_Value --
5397 -------------------------
5399 procedure Bad_Mechanism is
5401 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5404 -- Start of processing for Set_Mechanism_Value
5407 if Mechanism (Ent) /= Default_Mechanism then
5409 ("mechanism for & has already been set", Mech_Name, Ent);
5412 -- MECHANISM_NAME ::= value | reference | descriptor |
5415 if Nkind (Mech_Name) = N_Identifier then
5416 if Chars (Mech_Name) = Name_Value then
5417 Set_Mechanism (Ent, By_Copy);
5420 elsif Chars (Mech_Name) = Name_Reference then
5421 Set_Mechanism (Ent, By_Reference);
5424 elsif Chars (Mech_Name) = Name_Descriptor then
5425 Check_VMS (Mech_Name);
5427 -- Descriptor => Short_Descriptor if pragma was given
5429 if Short_Descriptors then
5430 Set_Mechanism (Ent, By_Short_Descriptor);
5432 Set_Mechanism (Ent, By_Descriptor);
5437 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5438 Check_VMS (Mech_Name);
5439 Set_Mechanism (Ent, By_Short_Descriptor);
5442 elsif Chars (Mech_Name) = Name_Copy then
5444 ("bad mechanism name, Value assumed", Mech_Name);
5450 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5451 -- short_descriptor (CLASS_NAME)
5452 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5454 -- Note: this form is parsed as an indexed component
5456 elsif Nkind (Mech_Name) = N_Indexed_Component then
5457 Class := First (Expressions (Mech_Name));
5459 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5460 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5461 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5462 or else Present (Next (Class))
5466 Mech_Name_Id := Chars (Prefix (Mech_Name));
5468 -- Change Descriptor => Short_Descriptor if pragma was given
5470 if Mech_Name_Id = Name_Descriptor
5471 and then Short_Descriptors
5473 Mech_Name_Id := Name_Short_Descriptor;
5477 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5478 -- short_descriptor (Class => CLASS_NAME)
5479 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5481 -- Note: this form is parsed as a function call
5483 elsif Nkind (Mech_Name) = N_Function_Call then
5484 Param := First (Parameter_Associations (Mech_Name));
5486 if Nkind (Name (Mech_Name)) /= N_Identifier
5487 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5488 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5489 or else Present (Next (Param))
5490 or else No (Selector_Name (Param))
5491 or else Chars (Selector_Name (Param)) /= Name_Class
5495 Class := Explicit_Actual_Parameter (Param);
5496 Mech_Name_Id := Chars (Name (Mech_Name));
5503 -- Fall through here with Class set to descriptor class name
5505 Check_VMS (Mech_Name);
5507 if Nkind (Class) /= N_Identifier then
5510 elsif Mech_Name_Id = Name_Descriptor
5511 and then Chars (Class) = Name_UBS
5513 Set_Mechanism (Ent, By_Descriptor_UBS);
5515 elsif Mech_Name_Id = Name_Descriptor
5516 and then Chars (Class) = Name_UBSB
5518 Set_Mechanism (Ent, By_Descriptor_UBSB);
5520 elsif Mech_Name_Id = Name_Descriptor
5521 and then Chars (Class) = Name_UBA
5523 Set_Mechanism (Ent, By_Descriptor_UBA);
5525 elsif Mech_Name_Id = Name_Descriptor
5526 and then Chars (Class) = Name_S
5528 Set_Mechanism (Ent, By_Descriptor_S);
5530 elsif Mech_Name_Id = Name_Descriptor
5531 and then Chars (Class) = Name_SB
5533 Set_Mechanism (Ent, By_Descriptor_SB);
5535 elsif Mech_Name_Id = Name_Descriptor
5536 and then Chars (Class) = Name_A
5538 Set_Mechanism (Ent, By_Descriptor_A);
5540 elsif Mech_Name_Id = Name_Descriptor
5541 and then Chars (Class) = Name_NCA
5543 Set_Mechanism (Ent, By_Descriptor_NCA);
5545 elsif Mech_Name_Id = Name_Short_Descriptor
5546 and then Chars (Class) = Name_UBS
5548 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5550 elsif Mech_Name_Id = Name_Short_Descriptor
5551 and then Chars (Class) = Name_UBSB
5553 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5555 elsif Mech_Name_Id = Name_Short_Descriptor
5556 and then Chars (Class) = Name_UBA
5558 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5560 elsif Mech_Name_Id = Name_Short_Descriptor
5561 and then Chars (Class) = Name_S
5563 Set_Mechanism (Ent, By_Short_Descriptor_S);
5565 elsif Mech_Name_Id = Name_Short_Descriptor
5566 and then Chars (Class) = Name_SB
5568 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5570 elsif Mech_Name_Id = Name_Short_Descriptor
5571 and then Chars (Class) = Name_A
5573 Set_Mechanism (Ent, By_Short_Descriptor_A);
5575 elsif Mech_Name_Id = Name_Short_Descriptor
5576 and then Chars (Class) = Name_NCA
5578 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5583 end Set_Mechanism_Value;
5585 ---------------------------
5586 -- Set_Ravenscar_Profile --
5587 ---------------------------
5589 -- The tasks to be done here are
5591 -- Set required policies
5593 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5594 -- pragma Locking_Policy (Ceiling_Locking)
5596 -- Set Detect_Blocking mode
5598 -- Set required restrictions (see System.Rident for detailed list)
5600 -- Set the No_Dependence rules
5601 -- No_Dependence => Ada.Asynchronous_Task_Control
5602 -- No_Dependence => Ada.Calendar
5603 -- No_Dependence => Ada.Execution_Time.Group_Budget
5604 -- No_Dependence => Ada.Execution_Time.Timers
5605 -- No_Dependence => Ada.Task_Attributes
5606 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5608 procedure Set_Ravenscar_Profile (N : Node_Id) is
5609 Prefix_Entity : Entity_Id;
5610 Selector_Entity : Entity_Id;
5611 Prefix_Node : Node_Id;
5615 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5617 if Task_Dispatching_Policy /= ' '
5618 and then Task_Dispatching_Policy /= 'F'
5620 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5621 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5623 -- Set the FIFO_Within_Priorities policy, but always preserve
5624 -- System_Location since we like the error message with the run time
5628 Task_Dispatching_Policy := 'F';
5630 if Task_Dispatching_Policy_Sloc /= System_Location then
5631 Task_Dispatching_Policy_Sloc := Loc;
5635 -- pragma Locking_Policy (Ceiling_Locking)
5637 if Locking_Policy /= ' '
5638 and then Locking_Policy /= 'C'
5640 Error_Msg_Sloc := Locking_Policy_Sloc;
5641 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5643 -- Set the Ceiling_Locking policy, but preserve System_Location since
5644 -- we like the error message with the run time name.
5647 Locking_Policy := 'C';
5649 if Locking_Policy_Sloc /= System_Location then
5650 Locking_Policy_Sloc := Loc;
5654 -- pragma Detect_Blocking
5656 Detect_Blocking := True;
5658 -- Set the corresponding restrictions
5660 Set_Profile_Restrictions
5661 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5663 -- Set the No_Dependence restrictions
5665 -- The following No_Dependence restrictions:
5666 -- No_Dependence => Ada.Asynchronous_Task_Control
5667 -- No_Dependence => Ada.Calendar
5668 -- No_Dependence => Ada.Task_Attributes
5669 -- are already set by previous call to Set_Profile_Restrictions.
5671 -- Set the following restrictions which were added to Ada 2005:
5672 -- No_Dependence => Ada.Execution_Time.Group_Budget
5673 -- No_Dependence => Ada.Execution_Time.Timers
5675 if Ada_Version >= Ada_2005 then
5676 Name_Buffer (1 .. 3) := "ada";
5679 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5681 Name_Buffer (1 .. 14) := "execution_time";
5684 Selector_Entity := Make_Identifier (Loc, Name_Find);
5687 Make_Selected_Component
5689 Prefix => Prefix_Entity,
5690 Selector_Name => Selector_Entity);
5692 Name_Buffer (1 .. 13) := "group_budgets";
5695 Selector_Entity := Make_Identifier (Loc, Name_Find);
5698 Make_Selected_Component
5700 Prefix => Prefix_Node,
5701 Selector_Name => Selector_Entity);
5703 Set_Restriction_No_Dependence
5705 Warn => Treat_Restrictions_As_Warnings,
5706 Profile => Ravenscar);
5708 Name_Buffer (1 .. 6) := "timers";
5711 Selector_Entity := Make_Identifier (Loc, Name_Find);
5714 Make_Selected_Component
5716 Prefix => Prefix_Node,
5717 Selector_Name => Selector_Entity);
5719 Set_Restriction_No_Dependence
5721 Warn => Treat_Restrictions_As_Warnings,
5722 Profile => Ravenscar);
5725 -- Set the following restrictions which was added to Ada 2012 (see
5727 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5729 if Ada_Version >= Ada_2012 then
5730 Name_Buffer (1 .. 6) := "system";
5733 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5735 Name_Buffer (1 .. 15) := "multiprocessors";
5738 Selector_Entity := Make_Identifier (Loc, Name_Find);
5741 Make_Selected_Component
5743 Prefix => Prefix_Entity,
5744 Selector_Name => Selector_Entity);
5746 Name_Buffer (1 .. 19) := "dispatching_domains";
5749 Selector_Entity := Make_Identifier (Loc, Name_Find);
5752 Make_Selected_Component
5754 Prefix => Prefix_Node,
5755 Selector_Name => Selector_Entity);
5757 Set_Restriction_No_Dependence
5759 Warn => Treat_Restrictions_As_Warnings,
5760 Profile => Ravenscar);
5762 end Set_Ravenscar_Profile;
5764 -- Start of processing for Analyze_Pragma
5767 -- The following code is a defense against recursion. Not clear that
5768 -- this can happen legitimately, but perhaps some error situations
5769 -- can cause it, and we did see this recursion during testing.
5771 if Analyzed (N) then
5774 Set_Analyzed (N, True);
5777 -- Deal with unrecognized pragma
5779 if not Is_Pragma_Name (Pname) then
5780 if Warn_On_Unrecognized_Pragma then
5781 Error_Msg_Name_1 := Pname;
5782 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5784 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5785 if Is_Bad_Spelling_Of (Pname, PN) then
5786 Error_Msg_Name_1 := PN;
5787 Error_Msg_N -- CODEFIX
5788 ("\?possible misspelling of %!", Pragma_Identifier (N));
5797 -- Here to start processing for recognized pragma
5799 Prag_Id := Get_Pragma_Id (Pname);
5809 if Present (Pragma_Argument_Associations (N)) then
5810 Arg_Count := List_Length (Pragma_Argument_Associations (N));
5811 Arg1 := First (Pragma_Argument_Associations (N));
5813 if Present (Arg1) then
5814 Arg2 := Next (Arg1);
5816 if Present (Arg2) then
5817 Arg3 := Next (Arg2);
5819 if Present (Arg3) then
5820 Arg4 := Next (Arg3);
5826 -- An enumeration type defines the pragmas that are supported by the
5827 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5828 -- into the corresponding enumeration value for the following case.
5836 -- pragma Abort_Defer;
5838 when Pragma_Abort_Defer =>
5840 Check_Arg_Count (0);
5842 -- The only required semantic processing is to check the
5843 -- placement. This pragma must appear at the start of the
5844 -- statement sequence of a handled sequence of statements.
5846 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5847 or else N /= First (Statements (Parent (N)))
5858 -- Note: this pragma also has some specific processing in Par.Prag
5859 -- because we want to set the Ada version mode during parsing.
5861 when Pragma_Ada_83 =>
5863 Check_Arg_Count (0);
5865 -- We really should check unconditionally for proper configuration
5866 -- pragma placement, since we really don't want mixed Ada modes
5867 -- within a single unit, and the GNAT reference manual has always
5868 -- said this was a configuration pragma, but we did not check and
5869 -- are hesitant to add the check now.
5871 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5872 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5873 -- or Ada 2012 mode.
5875 if Ada_Version >= Ada_2005 then
5876 Check_Valid_Configuration_Pragma;
5879 -- Now set Ada 83 mode
5881 Ada_Version := Ada_83;
5882 Ada_Version_Explicit := Ada_Version;
5890 -- Note: this pragma also has some specific processing in Par.Prag
5891 -- because we want to set the Ada 83 version mode during parsing.
5893 when Pragma_Ada_95 =>
5895 Check_Arg_Count (0);
5897 -- We really should check unconditionally for proper configuration
5898 -- pragma placement, since we really don't want mixed Ada modes
5899 -- within a single unit, and the GNAT reference manual has always
5900 -- said this was a configuration pragma, but we did not check and
5901 -- are hesitant to add the check now.
5903 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5904 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5906 if Ada_Version >= Ada_2005 then
5907 Check_Valid_Configuration_Pragma;
5910 -- Now set Ada 95 mode
5912 Ada_Version := Ada_95;
5913 Ada_Version_Explicit := Ada_Version;
5915 ---------------------
5916 -- Ada_05/Ada_2005 --
5917 ---------------------
5920 -- pragma Ada_05 (LOCAL_NAME);
5923 -- pragma Ada_2005 (LOCAL_NAME):
5925 -- Note: these pragmas also have some specific processing in Par.Prag
5926 -- because we want to set the Ada 2005 version mode during parsing.
5928 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5934 if Arg_Count = 1 then
5935 Check_Arg_Is_Local_Name (Arg1);
5936 E_Id := Get_Pragma_Arg (Arg1);
5938 if Etype (E_Id) = Any_Type then
5942 Set_Is_Ada_2005_Only (Entity (E_Id));
5945 Check_Arg_Count (0);
5947 -- For Ada_2005 we unconditionally enforce the documented
5948 -- configuration pragma placement, since we do not want to
5949 -- tolerate mixed modes in a unit involving Ada 2005. That
5950 -- would cause real difficulties for those cases where there
5951 -- are incompatibilities between Ada 95 and Ada 2005.
5953 Check_Valid_Configuration_Pragma;
5955 -- Now set appropriate Ada mode
5957 Ada_Version := Ada_2005;
5958 Ada_Version_Explicit := Ada_2005;
5962 ---------------------
5963 -- Ada_12/Ada_2012 --
5964 ---------------------
5967 -- pragma Ada_12 (LOCAL_NAME);
5970 -- pragma Ada_2012 (LOCAL_NAME):
5972 -- Note: these pragmas also have some specific processing in Par.Prag
5973 -- because we want to set the Ada 2012 version mode during parsing.
5975 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5981 if Arg_Count = 1 then
5982 Check_Arg_Is_Local_Name (Arg1);
5983 E_Id := Get_Pragma_Arg (Arg1);
5985 if Etype (E_Id) = Any_Type then
5989 Set_Is_Ada_2012_Only (Entity (E_Id));
5992 Check_Arg_Count (0);
5994 -- For Ada_2012 we unconditionally enforce the documented
5995 -- configuration pragma placement, since we do not want to
5996 -- tolerate mixed modes in a unit involving Ada 2012. That
5997 -- would cause real difficulties for those cases where there
5998 -- are incompatibilities between Ada 95 and Ada 2012. We could
5999 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6001 Check_Valid_Configuration_Pragma;
6003 -- Now set appropriate Ada mode
6005 Ada_Version := Ada_2012;
6006 Ada_Version_Explicit := Ada_2012;
6010 ----------------------
6011 -- All_Calls_Remote --
6012 ----------------------
6014 -- pragma All_Calls_Remote [(library_package_NAME)];
6016 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6017 Lib_Entity : Entity_Id;
6020 Check_Ada_83_Warning;
6021 Check_Valid_Library_Unit_Pragma;
6023 if Nkind (N) = N_Null_Statement then
6027 Lib_Entity := Find_Lib_Unit_Name;
6029 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6031 if Present (Lib_Entity)
6032 and then not Debug_Flag_U
6034 if not Is_Remote_Call_Interface (Lib_Entity) then
6035 Error_Pragma ("pragma% only apply to rci unit");
6037 -- Set flag for entity of the library unit
6040 Set_Has_All_Calls_Remote (Lib_Entity);
6044 end All_Calls_Remote;
6050 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6051 -- ARG ::= NAME | EXPRESSION
6053 -- The first two arguments are by convention intended to refer to an
6054 -- external tool and a tool-specific function. These arguments are
6057 when Pragma_Annotate => Annotate : begin
6059 Check_At_Least_N_Arguments (1);
6060 Check_Arg_Is_Identifier (Arg1);
6061 Check_No_Identifiers;
6069 -- Second unanalyzed parameter is optional
6075 while Present (Arg) loop
6076 Exp := Get_Pragma_Arg (Arg);
6079 if Is_Entity_Name (Exp) then
6082 -- For string literals, we assume Standard_String as the
6083 -- type, unless the string contains wide or wide_wide
6086 elsif Nkind (Exp) = N_String_Literal then
6087 if Has_Wide_Wide_Character (Exp) then
6088 Resolve (Exp, Standard_Wide_Wide_String);
6089 elsif Has_Wide_Character (Exp) then
6090 Resolve (Exp, Standard_Wide_String);
6092 Resolve (Exp, Standard_String);
6095 elsif Is_Overloaded (Exp) then
6097 ("ambiguous argument for pragma%", Exp);
6113 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6114 -- [, [Message =>] Static_String_EXPRESSION]);
6116 when Pragma_Assert => Assert : declare
6122 Check_At_Least_N_Arguments (1);
6123 Check_At_Most_N_Arguments (2);
6124 Check_Arg_Order ((Name_Check, Name_Message));
6125 Check_Optional_Identifier (Arg1, Name_Check);
6127 -- We treat pragma Assert as equivalent to:
6129 -- pragma Check (Assertion, condition [, msg]);
6131 -- So rewrite pragma in this manner, and analyze the result
6133 Expr := Get_Pragma_Arg (Arg1);
6135 Make_Pragma_Argument_Association (Loc,
6136 Expression => Make_Identifier (Loc, Name_Assertion)),
6138 Make_Pragma_Argument_Association (Sloc (Expr),
6139 Expression => Expr));
6141 if Arg_Count > 1 then
6142 Check_Optional_Identifier (Arg2, Name_Message);
6143 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6144 Append_To (Newa, Relocate_Node (Arg2));
6149 Chars => Name_Check,
6150 Pragma_Argument_Associations => Newa));
6154 ----------------------
6155 -- Assertion_Policy --
6156 ----------------------
6158 -- pragma Assertion_Policy (Check | Ignore)
6160 when Pragma_Assertion_Policy => Assertion_Policy : declare
6165 Check_Valid_Configuration_Pragma;
6166 Check_Arg_Count (1);
6167 Check_No_Identifiers;
6168 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6170 -- We treat pragma Assertion_Policy as equivalent to:
6172 -- pragma Check_Policy (Assertion, policy)
6174 -- So rewrite the pragma in that manner and link on to the chain
6175 -- of Check_Policy pragmas, marking the pragma as analyzed.
6177 Policy := Get_Pragma_Arg (Arg1);
6181 Chars => Name_Check_Policy,
6183 Pragma_Argument_Associations => New_List (
6184 Make_Pragma_Argument_Association (Loc,
6185 Expression => Make_Identifier (Loc, Name_Assertion)),
6187 Make_Pragma_Argument_Association (Loc,
6189 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6192 Set_Next_Pragma (N, Opt.Check_Policy_List);
6193 Opt.Check_Policy_List := N;
6194 end Assertion_Policy;
6196 ------------------------------
6197 -- Assume_No_Invalid_Values --
6198 ------------------------------
6200 -- pragma Assume_No_Invalid_Values (On | Off);
6202 when Pragma_Assume_No_Invalid_Values =>
6204 Check_Valid_Configuration_Pragma;
6205 Check_Arg_Count (1);
6206 Check_No_Identifiers;
6207 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6209 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6210 Assume_No_Invalid_Values := True;
6212 Assume_No_Invalid_Values := False;
6219 -- pragma AST_Entry (entry_IDENTIFIER);
6221 when Pragma_AST_Entry => AST_Entry : declare
6227 Check_Arg_Count (1);
6228 Check_No_Identifiers;
6229 Check_Arg_Is_Local_Name (Arg1);
6230 Ent := Entity (Get_Pragma_Arg (Arg1));
6232 -- Note: the implementation of the AST_Entry pragma could handle
6233 -- the entry family case fine, but for now we are consistent with
6234 -- the DEC rules, and do not allow the pragma, which of course
6235 -- has the effect of also forbidding the attribute.
6237 if Ekind (Ent) /= E_Entry then
6239 ("pragma% argument must be simple entry name", Arg1);
6241 elsif Is_AST_Entry (Ent) then
6243 ("duplicate % pragma for entry", Arg1);
6245 elsif Has_Homonym (Ent) then
6247 ("pragma% argument cannot specify overloaded entry", Arg1);
6251 FF : constant Entity_Id := First_Formal (Ent);
6254 if Present (FF) then
6255 if Present (Next_Formal (FF)) then
6257 ("entry for pragma% can have only one argument",
6260 elsif Parameter_Mode (FF) /= E_In_Parameter then
6262 ("entry parameter for pragma% must have mode IN",
6268 Set_Is_AST_Entry (Ent);
6276 -- pragma Asynchronous (LOCAL_NAME);
6278 when Pragma_Asynchronous => Asynchronous : declare
6286 procedure Process_Async_Pragma;
6287 -- Common processing for procedure and access-to-procedure case
6289 --------------------------
6290 -- Process_Async_Pragma --
6291 --------------------------
6293 procedure Process_Async_Pragma is
6296 Set_Is_Asynchronous (Nm);
6300 -- The formals should be of mode IN (RM E.4.1(6))
6303 while Present (S) loop
6304 Formal := Defining_Identifier (S);
6306 if Nkind (Formal) = N_Defining_Identifier
6307 and then Ekind (Formal) /= E_In_Parameter
6310 ("pragma% procedure can only have IN parameter",
6317 Set_Is_Asynchronous (Nm);
6318 end Process_Async_Pragma;
6320 -- Start of processing for pragma Asynchronous
6323 Check_Ada_83_Warning;
6324 Check_No_Identifiers;
6325 Check_Arg_Count (1);
6326 Check_Arg_Is_Local_Name (Arg1);
6328 if Debug_Flag_U then
6332 C_Ent := Cunit_Entity (Current_Sem_Unit);
6333 Analyze (Get_Pragma_Arg (Arg1));
6334 Nm := Entity (Get_Pragma_Arg (Arg1));
6336 if not Is_Remote_Call_Interface (C_Ent)
6337 and then not Is_Remote_Types (C_Ent)
6339 -- This pragma should only appear in an RCI or Remote Types
6340 -- unit (RM E.4.1(4)).
6343 ("pragma% not in Remote_Call_Interface or " &
6344 "Remote_Types unit");
6347 if Ekind (Nm) = E_Procedure
6348 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6350 if not Is_Remote_Call_Interface (Nm) then
6352 ("pragma% cannot be applied on non-remote procedure",
6356 L := Parameter_Specifications (Parent (Nm));
6357 Process_Async_Pragma;
6360 elsif Ekind (Nm) = E_Function then
6362 ("pragma% cannot be applied to function", Arg1);
6364 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6365 if Is_Record_Type (Nm) then
6367 -- A record type that is the Equivalent_Type for a remote
6368 -- access-to-subprogram type.
6370 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6373 -- A non-expanded RAS type (distribution is not enabled)
6375 N := Declaration_Node (Nm);
6378 if Nkind (N) = N_Full_Type_Declaration
6379 and then Nkind (Type_Definition (N)) =
6380 N_Access_Procedure_Definition
6382 L := Parameter_Specifications (Type_Definition (N));
6383 Process_Async_Pragma;
6385 if Is_Asynchronous (Nm)
6386 and then Expander_Active
6387 and then Get_PCS_Name /= Name_No_DSA
6389 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6394 ("pragma% cannot reference access-to-function type",
6398 -- Only other possibility is Access-to-class-wide type
6400 elsif Is_Access_Type (Nm)
6401 and then Is_Class_Wide_Type (Designated_Type (Nm))
6403 Check_First_Subtype (Arg1);
6404 Set_Is_Asynchronous (Nm);
6405 if Expander_Active then
6406 RACW_Type_Is_Asynchronous (Nm);
6410 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6418 -- pragma Atomic (LOCAL_NAME);
6420 when Pragma_Atomic =>
6421 Process_Atomic_Shared_Volatile;
6423 -----------------------
6424 -- Atomic_Components --
6425 -----------------------
6427 -- pragma Atomic_Components (array_LOCAL_NAME);
6429 -- This processing is shared by Volatile_Components
6431 when Pragma_Atomic_Components |
6432 Pragma_Volatile_Components =>
6434 Atomic_Components : declare
6441 Check_Ada_83_Warning;
6442 Check_No_Identifiers;
6443 Check_Arg_Count (1);
6444 Check_Arg_Is_Local_Name (Arg1);
6445 E_Id := Get_Pragma_Arg (Arg1);
6447 if Etype (E_Id) = Any_Type then
6453 Check_Duplicate_Pragma (E);
6455 if Rep_Item_Too_Early (E, N)
6457 Rep_Item_Too_Late (E, N)
6462 D := Declaration_Node (E);
6465 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6467 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6468 and then Nkind (D) = N_Object_Declaration
6469 and then Nkind (Object_Definition (D)) =
6470 N_Constrained_Array_Definition)
6472 -- The flag is set on the object, or on the base type
6474 if Nkind (D) /= N_Object_Declaration then
6478 Set_Has_Volatile_Components (E);
6480 if Prag_Id = Pragma_Atomic_Components then
6481 Set_Has_Atomic_Components (E);
6485 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6487 end Atomic_Components;
6489 --------------------
6490 -- Attach_Handler --
6491 --------------------
6493 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6495 when Pragma_Attach_Handler =>
6496 Check_Ada_83_Warning;
6497 Check_No_Identifiers;
6498 Check_Arg_Count (2);
6500 if No_Run_Time_Mode then
6501 Error_Msg_CRT ("Attach_Handler pragma", N);
6503 Check_Interrupt_Or_Attach_Handler;
6505 -- The expression that designates the attribute may depend on a
6506 -- discriminant, and is therefore a per- object expression, to
6507 -- be expanded in the init proc. If expansion is enabled, then
6508 -- perform semantic checks on a copy only.
6510 if Expander_Active then
6512 Temp : constant Node_Id :=
6513 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6515 Set_Parent (Temp, N);
6516 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6520 Analyze (Get_Pragma_Arg (Arg2));
6521 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6524 Process_Interrupt_Or_Attach_Handler;
6527 --------------------
6528 -- C_Pass_By_Copy --
6529 --------------------
6531 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6533 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6539 Check_Valid_Configuration_Pragma;
6540 Check_Arg_Count (1);
6541 Check_Optional_Identifier (Arg1, "max_size");
6543 Arg := Get_Pragma_Arg (Arg1);
6544 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6546 Val := Expr_Value (Arg);
6550 ("maximum size for pragma% must be positive", Arg1);
6552 elsif UI_Is_In_Int_Range (Val) then
6553 Default_C_Record_Mechanism := UI_To_Int (Val);
6555 -- If a giant value is given, Int'Last will do well enough.
6556 -- If sometime someone complains that a record larger than
6557 -- two gigabytes is not copied, we will worry about it then!
6560 Default_C_Record_Mechanism := Mechanism_Type'Last;
6568 -- pragma Check ([Name =>] Identifier,
6569 -- [Check =>] Boolean_Expression
6570 -- [,[Message =>] String_Expression]);
6572 when Pragma_Check => Check : declare
6577 -- Set True if category of assertions referenced by Name enabled
6581 Check_At_Least_N_Arguments (2);
6582 Check_At_Most_N_Arguments (3);
6583 Check_Optional_Identifier (Arg1, Name_Name);
6584 Check_Optional_Identifier (Arg2, Name_Check);
6586 if Arg_Count = 3 then
6587 Check_Optional_Identifier (Arg3, Name_Message);
6588 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6591 Check_Arg_Is_Identifier (Arg1);
6593 -- Indicate if pragma is enabled. The Original_Node reference here
6594 -- is to deal with pragma Assert rewritten as a Check pragma.
6596 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6599 Set_Pragma_Enabled (N);
6600 Set_Pragma_Enabled (Original_Node (N));
6601 Set_SCO_Pragma_Enabled (Loc);
6604 -- If expansion is active and the check is not enabled then we
6605 -- rewrite the Check as:
6607 -- if False and then condition then
6611 -- The reason we do this rewriting during semantic analysis rather
6612 -- than as part of normal expansion is that we cannot analyze and
6613 -- expand the code for the boolean expression directly, or it may
6614 -- cause insertion of actions that would escape the attempt to
6615 -- suppress the check code.
6617 -- Note that the Sloc for the if statement corresponds to the
6618 -- argument condition, not the pragma itself. The reason for this
6619 -- is that we may generate a warning if the condition is False at
6620 -- compile time, and we do not want to delete this warning when we
6621 -- delete the if statement.
6623 Expr := Get_Pragma_Arg (Arg2);
6625 if Expander_Active and then not Check_On then
6626 Eloc := Sloc (Expr);
6629 Make_If_Statement (Eloc,
6631 Make_And_Then (Eloc,
6632 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6633 Right_Opnd => Expr),
6634 Then_Statements => New_List (
6635 Make_Null_Statement (Eloc))));
6642 Analyze_And_Resolve (Expr, Any_Boolean);
6650 -- pragma Check_Name (check_IDENTIFIER);
6652 when Pragma_Check_Name =>
6653 Check_No_Identifiers;
6655 Check_Valid_Configuration_Pragma;
6656 Check_Arg_Count (1);
6657 Check_Arg_Is_Identifier (Arg1);
6660 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6663 for J in Check_Names.First .. Check_Names.Last loop
6664 if Check_Names.Table (J) = Nam then
6669 Check_Names.Append (Nam);
6676 -- pragma Check_Policy (
6677 -- [Name =>] IDENTIFIER,
6678 -- [Policy =>] POLICY_IDENTIFIER);
6680 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6682 -- Note: this is a configuration pragma, but it is allowed to appear
6685 when Pragma_Check_Policy =>
6687 Check_Arg_Count (2);
6688 Check_Optional_Identifier (Arg1, Name_Name);
6689 Check_Optional_Identifier (Arg2, Name_Policy);
6691 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6693 -- A Check_Policy pragma can appear either as a configuration
6694 -- pragma, or in a declarative part or a package spec (see RM
6695 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6696 -- followed for Check_Policy).
6698 if not Is_Configuration_Pragma then
6699 Check_Is_In_Decl_Part_Or_Package_Spec;
6702 Set_Next_Pragma (N, Opt.Check_Policy_List);
6703 Opt.Check_Policy_List := N;
6705 ---------------------
6706 -- CIL_Constructor --
6707 ---------------------
6709 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6711 -- Processing for this pragma is shared with Java_Constructor
6717 -- pragma Comment (static_string_EXPRESSION)
6719 -- Processing for pragma Comment shares the circuitry for pragma
6720 -- Ident. The only differences are that Ident enforces a limit of 31
6721 -- characters on its argument, and also enforces limitations on
6722 -- placement for DEC compatibility. Pragma Comment shares neither of
6723 -- these restrictions.
6729 -- pragma Common_Object (
6730 -- [Internal =>] LOCAL_NAME
6731 -- [, [External =>] EXTERNAL_SYMBOL]
6732 -- [, [Size =>] EXTERNAL_SYMBOL]);
6734 -- Processing for this pragma is shared with Psect_Object
6736 ------------------------
6737 -- Compile_Time_Error --
6738 ------------------------
6740 -- pragma Compile_Time_Error
6741 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6743 when Pragma_Compile_Time_Error =>
6745 Process_Compile_Time_Warning_Or_Error;
6747 --------------------------
6748 -- Compile_Time_Warning --
6749 --------------------------
6751 -- pragma Compile_Time_Warning
6752 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6754 when Pragma_Compile_Time_Warning =>
6756 Process_Compile_Time_Warning_Or_Error;
6762 when Pragma_Compiler_Unit =>
6764 Check_Arg_Count (0);
6765 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6767 -----------------------------
6768 -- Complete_Representation --
6769 -----------------------------
6771 -- pragma Complete_Representation;
6773 when Pragma_Complete_Representation =>
6775 Check_Arg_Count (0);
6777 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6779 ("pragma & must appear within record representation clause");
6782 ----------------------------
6783 -- Complex_Representation --
6784 ----------------------------
6786 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6788 when Pragma_Complex_Representation => Complex_Representation : declare
6795 Check_Arg_Count (1);
6796 Check_Optional_Identifier (Arg1, Name_Entity);
6797 Check_Arg_Is_Local_Name (Arg1);
6798 E_Id := Get_Pragma_Arg (Arg1);
6800 if Etype (E_Id) = Any_Type then
6806 if not Is_Record_Type (E) then
6808 ("argument for pragma% must be record type", Arg1);
6811 Ent := First_Entity (E);
6814 or else No (Next_Entity (Ent))
6815 or else Present (Next_Entity (Next_Entity (Ent)))
6816 or else not Is_Floating_Point_Type (Etype (Ent))
6817 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6820 ("record for pragma% must have two fields of the same "
6821 & "floating-point type", Arg1);
6824 Set_Has_Complex_Representation (Base_Type (E));
6826 -- We need to treat the type has having a non-standard
6827 -- representation, for back-end purposes, even though in
6828 -- general a complex will have the default representation
6829 -- of a record with two real components.
6831 Set_Has_Non_Standard_Rep (Base_Type (E));
6833 end Complex_Representation;
6835 -------------------------
6836 -- Component_Alignment --
6837 -------------------------
6839 -- pragma Component_Alignment (
6840 -- [Form =>] ALIGNMENT_CHOICE
6841 -- [, [Name =>] type_LOCAL_NAME]);
6843 -- ALIGNMENT_CHOICE ::=
6845 -- | Component_Size_4
6849 when Pragma_Component_Alignment => Component_AlignmentP : declare
6850 Args : Args_List (1 .. 2);
6851 Names : constant Name_List (1 .. 2) := (
6855 Form : Node_Id renames Args (1);
6856 Name : Node_Id renames Args (2);
6858 Atype : Component_Alignment_Kind;
6863 Gather_Associations (Names, Args);
6866 Error_Pragma ("missing Form argument for pragma%");
6869 Check_Arg_Is_Identifier (Form);
6871 -- Get proper alignment, note that Default = Component_Size on all
6872 -- machines we have so far, and we want to set this value rather
6873 -- than the default value to indicate that it has been explicitly
6874 -- set (and thus will not get overridden by the default component
6875 -- alignment for the current scope)
6877 if Chars (Form) = Name_Component_Size then
6878 Atype := Calign_Component_Size;
6880 elsif Chars (Form) = Name_Component_Size_4 then
6881 Atype := Calign_Component_Size_4;
6883 elsif Chars (Form) = Name_Default then
6884 Atype := Calign_Component_Size;
6886 elsif Chars (Form) = Name_Storage_Unit then
6887 Atype := Calign_Storage_Unit;
6891 ("invalid Form parameter for pragma%", Form);
6894 -- Case with no name, supplied, affects scope table entry
6898 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6900 -- Case of name supplied
6903 Check_Arg_Is_Local_Name (Name);
6905 Typ := Entity (Name);
6908 or else Rep_Item_Too_Early (Typ, N)
6912 Typ := Underlying_Type (Typ);
6915 if not Is_Record_Type (Typ)
6916 and then not Is_Array_Type (Typ)
6919 ("Name parameter of pragma% must identify record or " &
6920 "array type", Name);
6923 -- An explicit Component_Alignment pragma overrides an
6924 -- implicit pragma Pack, but not an explicit one.
6926 if not Has_Pragma_Pack (Base_Type (Typ)) then
6927 Set_Is_Packed (Base_Type (Typ), False);
6928 Set_Component_Alignment (Base_Type (Typ), Atype);
6931 end Component_AlignmentP;
6937 -- pragma Controlled (first_subtype_LOCAL_NAME);
6939 when Pragma_Controlled => Controlled : declare
6943 Check_No_Identifiers;
6944 Check_Arg_Count (1);
6945 Check_Arg_Is_Local_Name (Arg1);
6946 Arg := Get_Pragma_Arg (Arg1);
6948 if not Is_Entity_Name (Arg)
6949 or else not Is_Access_Type (Entity (Arg))
6951 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6953 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6961 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6962 -- [Entity =>] LOCAL_NAME);
6964 when Pragma_Convention => Convention : declare
6967 pragma Warnings (Off, C);
6968 pragma Warnings (Off, E);
6970 Check_Arg_Order ((Name_Convention, Name_Entity));
6971 Check_Ada_83_Warning;
6972 Check_Arg_Count (2);
6973 Process_Convention (C, E);
6976 ---------------------------
6977 -- Convention_Identifier --
6978 ---------------------------
6980 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6981 -- [Convention =>] convention_IDENTIFIER);
6983 when Pragma_Convention_Identifier => Convention_Identifier : declare
6989 Check_Arg_Order ((Name_Name, Name_Convention));
6990 Check_Arg_Count (2);
6991 Check_Optional_Identifier (Arg1, Name_Name);
6992 Check_Optional_Identifier (Arg2, Name_Convention);
6993 Check_Arg_Is_Identifier (Arg1);
6994 Check_Arg_Is_Identifier (Arg2);
6995 Idnam := Chars (Get_Pragma_Arg (Arg1));
6996 Cname := Chars (Get_Pragma_Arg (Arg2));
6998 if Is_Convention_Name (Cname) then
6999 Record_Convention_Identifier
7000 (Idnam, Get_Convention_Id (Cname));
7003 ("second arg for % pragma must be convention", Arg2);
7005 end Convention_Identifier;
7011 -- pragma CPP_Class ([Entity =>] local_NAME)
7013 when Pragma_CPP_Class => CPP_Class : declare
7018 if Warn_On_Obsolescent_Feature then
7020 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7021 " by pragma import?", N);
7025 Check_Arg_Count (1);
7026 Check_Optional_Identifier (Arg1, Name_Entity);
7027 Check_Arg_Is_Local_Name (Arg1);
7029 Arg := Get_Pragma_Arg (Arg1);
7032 if Etype (Arg) = Any_Type then
7036 if not Is_Entity_Name (Arg)
7037 or else not Is_Type (Entity (Arg))
7039 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7042 Typ := Entity (Arg);
7044 if not Is_Tagged_Type (Typ) then
7045 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7048 -- Types treated as CPP classes are treated as limited, but we
7049 -- don't require them to be declared this way. A warning is issued
7050 -- to encourage the user to declare them as limited. This is not
7051 -- an error, for compatibility reasons, because these types have
7052 -- been supported this way for some time.
7054 if not Is_Limited_Type (Typ) then
7056 ("imported 'C'P'P type should be " &
7057 "explicitly declared limited?",
7058 Get_Pragma_Arg (Arg1));
7060 ("\type will be considered limited",
7061 Get_Pragma_Arg (Arg1));
7064 Set_Is_CPP_Class (Typ);
7065 Set_Is_Limited_Record (Typ);
7066 Set_Convention (Typ, Convention_CPP);
7068 -- Imported CPP types must not have discriminants (because C++
7069 -- classes do not have discriminants).
7071 if Has_Discriminants (Typ) then
7073 ("imported 'C'P'P type cannot have discriminants",
7074 First (Discriminant_Specifications
7075 (Declaration_Node (Typ))));
7078 -- Components of imported CPP types must not have default
7079 -- expressions because the constructor (if any) is in the
7082 if Is_Incomplete_Or_Private_Type (Typ)
7083 and then No (Underlying_Type (Typ))
7085 -- It should be an error to apply pragma CPP to a private
7086 -- type if the underlying type is not visible (as it is
7087 -- for any representation item). For now, for backward
7088 -- compatibility we do nothing but we cannot check components
7089 -- because they are not available at this stage. All this code
7090 -- will be removed when we cleanup this obsolete GNAT pragma???
7096 Tdef : constant Node_Id :=
7097 Type_Definition (Declaration_Node (Typ));
7102 if Nkind (Tdef) = N_Record_Definition then
7103 Clist := Component_List (Tdef);
7105 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7106 Clist := Component_List (Record_Extension_Part (Tdef));
7109 if Present (Clist) then
7110 Comp := First (Component_Items (Clist));
7111 while Present (Comp) loop
7112 if Present (Expression (Comp)) then
7114 ("component of imported 'C'P'P type cannot have" &
7115 " default expression", Expression (Comp));
7125 ---------------------
7126 -- CPP_Constructor --
7127 ---------------------
7129 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7130 -- [, [External_Name =>] static_string_EXPRESSION ]
7131 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7133 when Pragma_CPP_Constructor => CPP_Constructor : declare
7137 Tag_Typ : Entity_Id;
7141 Check_At_Least_N_Arguments (1);
7142 Check_At_Most_N_Arguments (3);
7143 Check_Optional_Identifier (Arg1, Name_Entity);
7144 Check_Arg_Is_Local_Name (Arg1);
7146 Id := Get_Pragma_Arg (Arg1);
7147 Find_Program_Unit_Name (Id);
7149 -- If we did not find the name, we are done
7151 if Etype (Id) = Any_Type then
7155 Def_Id := Entity (Id);
7157 -- Check if already defined as constructor
7159 if Is_Constructor (Def_Id) then
7161 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7165 if Ekind (Def_Id) = E_Function
7166 and then (Is_CPP_Class (Etype (Def_Id))
7167 or else (Is_Class_Wide_Type (Etype (Def_Id))
7169 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7171 if Arg_Count >= 2 then
7172 Set_Imported (Def_Id);
7173 Set_Is_Public (Def_Id);
7174 Process_Interface_Name (Def_Id, Arg2, Arg3);
7177 Set_Has_Completion (Def_Id);
7178 Set_Is_Constructor (Def_Id);
7180 -- Imported C++ constructors are not dispatching primitives
7181 -- because in C++ they don't have a dispatch table slot.
7182 -- However, in Ada the constructor has the profile of a
7183 -- function that returns a tagged type and therefore it has
7184 -- been treated as a primitive operation during semantic
7185 -- analysis. We now remove it from the list of primitive
7186 -- operations of the type.
7188 if Is_Tagged_Type (Etype (Def_Id))
7189 and then not Is_Class_Wide_Type (Etype (Def_Id))
7191 pragma Assert (Is_Dispatching_Operation (Def_Id));
7192 Tag_Typ := Etype (Def_Id);
7194 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7195 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7199 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7200 Set_Is_Dispatching_Operation (Def_Id, False);
7203 -- For backward compatibility, if the constructor returns a
7204 -- class wide type, and we internally change the return type to
7205 -- the corresponding root type.
7207 if Is_Class_Wide_Type (Etype (Def_Id)) then
7208 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7212 ("pragma% requires function returning a 'C'P'P_Class type",
7215 end CPP_Constructor;
7221 when Pragma_CPP_Virtual => CPP_Virtual : declare
7225 if Warn_On_Obsolescent_Feature then
7227 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7236 when Pragma_CPP_Vtable => CPP_Vtable : declare
7240 if Warn_On_Obsolescent_Feature then
7242 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7251 -- pragma CPU (EXPRESSION);
7253 when Pragma_CPU => CPU : declare
7254 P : constant Node_Id := Parent (N);
7259 Check_No_Identifiers;
7260 Check_Arg_Count (1);
7264 if Nkind (P) = N_Subprogram_Body then
7265 Check_In_Main_Program;
7267 Arg := Get_Pragma_Arg (Arg1);
7268 Analyze_And_Resolve (Arg, Any_Integer);
7272 if not Is_Static_Expression (Arg) then
7273 Flag_Non_Static_Expr
7274 ("main subprogram affinity is not static!", Arg);
7277 -- If constraint error, then we already signalled an error
7279 elsif Raises_Constraint_Error (Arg) then
7282 -- Otherwise check in range
7286 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7287 -- This is the entity System.Multiprocessors.CPU_Range;
7289 Val : constant Uint := Expr_Value (Arg);
7292 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7294 Val > Expr_Value (Type_High_Bound (CPU_Id))
7297 ("main subprogram CPU is out of range", Arg1);
7303 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7307 elsif Nkind (P) = N_Task_Definition then
7308 Arg := Get_Pragma_Arg (Arg1);
7310 -- The expression must be analyzed in the special manner
7311 -- described in "Handling of Default and Per-Object
7312 -- Expressions" in sem.ads.
7314 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7316 -- Anything else is incorrect
7322 if Has_Pragma_CPU (P) then
7323 Error_Pragma ("duplicate pragma% not allowed");
7325 Set_Has_Pragma_CPU (P, True);
7327 if Nkind (P) = N_Task_Definition then
7328 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7337 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7339 when Pragma_Debug => Debug : declare
7347 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7350 if Arg_Count = 2 then
7353 Left_Opnd => Relocate_Node (Cond),
7354 Right_Opnd => Get_Pragma_Arg (Arg1));
7357 -- Rewrite into a conditional with an appropriate condition. We
7358 -- wrap the procedure call in a block so that overhead from e.g.
7359 -- use of the secondary stack does not generate execution overhead
7360 -- for suppressed conditions.
7362 Rewrite (N, Make_Implicit_If_Statement (N,
7364 Then_Statements => New_List (
7365 Make_Block_Statement (Loc,
7366 Handled_Statement_Sequence =>
7367 Make_Handled_Sequence_Of_Statements (Loc,
7368 Statements => New_List (
7369 Relocate_Node (Debug_Statement (N))))))));
7377 -- pragma Debug_Policy (Check | Ignore)
7379 when Pragma_Debug_Policy =>
7381 Check_Arg_Count (1);
7382 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7383 Debug_Pragmas_Enabled :=
7384 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7386 ---------------------
7387 -- Detect_Blocking --
7388 ---------------------
7390 -- pragma Detect_Blocking;
7392 when Pragma_Detect_Blocking =>
7394 Check_Arg_Count (0);
7395 Check_Valid_Configuration_Pragma;
7396 Detect_Blocking := True;
7398 --------------------------
7399 -- Default_Storage_Pool --
7400 --------------------------
7402 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7404 when Pragma_Default_Storage_Pool =>
7406 Check_Arg_Count (1);
7408 -- Default_Storage_Pool can appear as a configuration pragma, or
7409 -- in a declarative part or a package spec.
7411 if not Is_Configuration_Pragma then
7412 Check_Is_In_Decl_Part_Or_Package_Spec;
7415 -- Case of Default_Storage_Pool (null);
7417 if Nkind (Expression (Arg1)) = N_Null then
7418 Analyze (Expression (Arg1));
7420 -- This is an odd case, this is not really an expression, so
7421 -- we don't have a type for it. So just set the type to Empty.
7423 Set_Etype (Expression (Arg1), Empty);
7425 -- Case of Default_Storage_Pool (storage_pool_NAME);
7428 -- If it's a configuration pragma, then the only allowed
7429 -- argument is "null".
7431 if Is_Configuration_Pragma then
7432 Error_Pragma_Arg ("NULL expected", Arg1);
7435 -- The expected type for a non-"null" argument is
7436 -- Root_Storage_Pool'Class.
7439 (Get_Pragma_Arg (Arg1),
7440 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7443 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7444 -- for an access type will use this information to set the
7445 -- appropriate attributes of the access type.
7447 Default_Pool := Expression (Arg1);
7453 when Pragma_Dimension =>
7455 Check_Arg_Count (4);
7456 Check_No_Identifiers;
7457 Check_Arg_Is_Local_Name (Arg1);
7459 if not Is_Type (Arg1) then
7460 Error_Pragma ("first argument for pragma% must be subtype");
7463 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7464 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7465 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7471 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7473 when Pragma_Discard_Names => Discard_Names : declare
7478 Check_Ada_83_Warning;
7480 -- Deal with configuration pragma case
7482 if Arg_Count = 0 and then Is_Configuration_Pragma then
7483 Global_Discard_Names := True;
7486 -- Otherwise, check correct appropriate context
7489 Check_Is_In_Decl_Part_Or_Package_Spec;
7491 if Arg_Count = 0 then
7493 -- If there is no parameter, then from now on this pragma
7494 -- applies to any enumeration, exception or tagged type
7495 -- defined in the current declarative part, and recursively
7496 -- to any nested scope.
7498 Set_Discard_Names (Current_Scope);
7502 Check_Arg_Count (1);
7503 Check_Optional_Identifier (Arg1, Name_On);
7504 Check_Arg_Is_Local_Name (Arg1);
7506 E_Id := Get_Pragma_Arg (Arg1);
7508 if Etype (E_Id) = Any_Type then
7514 if (Is_First_Subtype (E)
7516 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7517 or else Ekind (E) = E_Exception
7519 Set_Discard_Names (E);
7522 ("inappropriate entity for pragma%", Arg1);
7533 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7535 when Pragma_Elaborate => Elaborate : declare
7540 -- Pragma must be in context items list of a compilation unit
7542 if not Is_In_Context_Clause then
7546 -- Must be at least one argument
7548 if Arg_Count = 0 then
7549 Error_Pragma ("pragma% requires at least one argument");
7552 -- In Ada 83 mode, there can be no items following it in the
7553 -- context list except other pragmas and implicit with clauses
7554 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7555 -- placement rule does not apply.
7557 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7559 while Present (Citem) loop
7560 if Nkind (Citem) = N_Pragma
7561 or else (Nkind (Citem) = N_With_Clause
7562 and then Implicit_With (Citem))
7567 ("(Ada 83) pragma% must be at end of context clause");
7574 -- Finally, the arguments must all be units mentioned in a with
7575 -- clause in the same context clause. Note we already checked (in
7576 -- Par.Prag) that the arguments are all identifiers or selected
7580 Outer : while Present (Arg) loop
7581 Citem := First (List_Containing (N));
7582 Inner : while Citem /= N loop
7583 if Nkind (Citem) = N_With_Clause
7584 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7586 Set_Elaborate_Present (Citem, True);
7587 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7588 Generate_Reference (Entity (Name (Citem)), Citem);
7590 -- With the pragma present, elaboration calls on
7591 -- subprograms from the named unit need no further
7592 -- checks, as long as the pragma appears in the current
7593 -- compilation unit. If the pragma appears in some unit
7594 -- in the context, there might still be a need for an
7595 -- Elaborate_All_Desirable from the current compilation
7596 -- to the named unit, so we keep the check enabled.
7598 if In_Extended_Main_Source_Unit (N) then
7599 Set_Suppress_Elaboration_Warnings
7600 (Entity (Name (Citem)));
7611 ("argument of pragma% is not with'ed unit", Arg);
7617 -- Give a warning if operating in static mode with -gnatwl
7618 -- (elaboration warnings enabled) switch set.
7620 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7622 ("?use of pragma Elaborate may not be safe", N);
7624 ("?use pragma Elaborate_All instead if possible", N);
7632 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7634 when Pragma_Elaborate_All => Elaborate_All : declare
7639 Check_Ada_83_Warning;
7641 -- Pragma must be in context items list of a compilation unit
7643 if not Is_In_Context_Clause then
7647 -- Must be at least one argument
7649 if Arg_Count = 0 then
7650 Error_Pragma ("pragma% requires at least one argument");
7653 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7654 -- have to appear at the end of the context clause, but may
7655 -- appear mixed in with other items, even in Ada 83 mode.
7657 -- Final check: the arguments must all be units mentioned in
7658 -- a with clause in the same context clause. Note that we
7659 -- already checked (in Par.Prag) that all the arguments are
7660 -- either identifiers or selected components.
7663 Outr : while Present (Arg) loop
7664 Citem := First (List_Containing (N));
7665 Innr : while Citem /= N loop
7666 if Nkind (Citem) = N_With_Clause
7667 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7669 Set_Elaborate_All_Present (Citem, True);
7670 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7672 -- Suppress warnings and elaboration checks on the named
7673 -- unit if the pragma is in the current compilation, as
7674 -- for pragma Elaborate.
7676 if In_Extended_Main_Source_Unit (N) then
7677 Set_Suppress_Elaboration_Warnings
7678 (Entity (Name (Citem)));
7687 Set_Error_Posted (N);
7689 ("argument of pragma% is not with'ed unit", Arg);
7696 --------------------
7697 -- Elaborate_Body --
7698 --------------------
7700 -- pragma Elaborate_Body [( library_unit_NAME )];
7702 when Pragma_Elaborate_Body => Elaborate_Body : declare
7703 Cunit_Node : Node_Id;
7704 Cunit_Ent : Entity_Id;
7707 Check_Ada_83_Warning;
7708 Check_Valid_Library_Unit_Pragma;
7710 if Nkind (N) = N_Null_Statement then
7714 Cunit_Node := Cunit (Current_Sem_Unit);
7715 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7717 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7720 Error_Pragma ("pragma% must refer to a spec, not a body");
7722 Set_Body_Required (Cunit_Node, True);
7723 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7725 -- If we are in dynamic elaboration mode, then we suppress
7726 -- elaboration warnings for the unit, since it is definitely
7727 -- fine NOT to do dynamic checks at the first level (and such
7728 -- checks will be suppressed because no elaboration boolean
7729 -- is created for Elaborate_Body packages).
7731 -- But in the static model of elaboration, Elaborate_Body is
7732 -- definitely NOT good enough to ensure elaboration safety on
7733 -- its own, since the body may WITH other units that are not
7734 -- safe from an elaboration point of view, so a client must
7735 -- still do an Elaborate_All on such units.
7737 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7738 -- Elaborate_Body always suppressed elab warnings.
7740 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7741 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7746 ------------------------
7747 -- Elaboration_Checks --
7748 ------------------------
7750 -- pragma Elaboration_Checks (Static | Dynamic);
7752 when Pragma_Elaboration_Checks =>
7754 Check_Arg_Count (1);
7755 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7756 Dynamic_Elaboration_Checks :=
7757 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7763 -- pragma Eliminate (
7764 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7765 -- [,[Entity =>] IDENTIFIER |
7766 -- SELECTED_COMPONENT |
7768 -- [, OVERLOADING_RESOLUTION]);
7770 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7773 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7776 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7778 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7779 -- Result_Type => result_SUBTYPE_NAME]
7781 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7782 -- SUBTYPE_NAME ::= STRING_LITERAL
7784 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7785 -- SOURCE_TRACE ::= STRING_LITERAL
7787 when Pragma_Eliminate => Eliminate : declare
7788 Args : Args_List (1 .. 5);
7789 Names : constant Name_List (1 .. 5) := (
7792 Name_Parameter_Types,
7794 Name_Source_Location);
7796 Unit_Name : Node_Id renames Args (1);
7797 Entity : Node_Id renames Args (2);
7798 Parameter_Types : Node_Id renames Args (3);
7799 Result_Type : Node_Id renames Args (4);
7800 Source_Location : Node_Id renames Args (5);
7804 Check_Valid_Configuration_Pragma;
7805 Gather_Associations (Names, Args);
7807 if No (Unit_Name) then
7808 Error_Pragma ("missing Unit_Name argument for pragma%");
7812 and then (Present (Parameter_Types)
7814 Present (Result_Type)
7816 Present (Source_Location))
7818 Error_Pragma ("missing Entity argument for pragma%");
7821 if (Present (Parameter_Types)
7823 Present (Result_Type))
7825 Present (Source_Location)
7828 ("parameter profile and source location cannot " &
7829 "be used together in pragma%");
7832 Process_Eliminate_Pragma
7846 -- [ Convention =>] convention_IDENTIFIER,
7847 -- [ Entity =>] local_NAME
7848 -- [, [External_Name =>] static_string_EXPRESSION ]
7849 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7851 when Pragma_Export => Export : declare
7855 pragma Warnings (Off, C);
7858 Check_Ada_83_Warning;
7864 Check_At_Least_N_Arguments (2);
7865 Check_At_Most_N_Arguments (4);
7866 Process_Convention (C, Def_Id);
7868 if Ekind (Def_Id) /= E_Constant then
7869 Note_Possible_Modification
7870 (Get_Pragma_Arg (Arg2), Sure => False);
7873 Process_Interface_Name (Def_Id, Arg3, Arg4);
7874 Set_Exported (Def_Id, Arg2);
7876 -- If the entity is a deferred constant, propagate the information
7877 -- to the full view, because gigi elaborates the full view only.
7879 if Ekind (Def_Id) = E_Constant
7880 and then Present (Full_View (Def_Id))
7883 Id2 : constant Entity_Id := Full_View (Def_Id);
7885 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7886 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7887 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7892 ----------------------
7893 -- Export_Exception --
7894 ----------------------
7896 -- pragma Export_Exception (
7897 -- [Internal =>] LOCAL_NAME
7898 -- [, [External =>] EXTERNAL_SYMBOL]
7899 -- [, [Form =>] Ada | VMS]
7900 -- [, [Code =>] static_integer_EXPRESSION]);
7902 when Pragma_Export_Exception => Export_Exception : declare
7903 Args : Args_List (1 .. 4);
7904 Names : constant Name_List (1 .. 4) := (
7910 Internal : Node_Id renames Args (1);
7911 External : Node_Id renames Args (2);
7912 Form : Node_Id renames Args (3);
7913 Code : Node_Id renames Args (4);
7918 if Inside_A_Generic then
7919 Error_Pragma ("pragma% cannot be used for generic entities");
7922 Gather_Associations (Names, Args);
7923 Process_Extended_Import_Export_Exception_Pragma (
7924 Arg_Internal => Internal,
7925 Arg_External => External,
7929 if not Is_VMS_Exception (Entity (Internal)) then
7930 Set_Exported (Entity (Internal), Internal);
7932 end Export_Exception;
7934 ---------------------
7935 -- Export_Function --
7936 ---------------------
7938 -- pragma Export_Function (
7939 -- [Internal =>] LOCAL_NAME
7940 -- [, [External =>] EXTERNAL_SYMBOL]
7941 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7942 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7943 -- [, [Mechanism =>] MECHANISM]
7944 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7946 -- EXTERNAL_SYMBOL ::=
7948 -- | static_string_EXPRESSION
7950 -- PARAMETER_TYPES ::=
7952 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7954 -- TYPE_DESIGNATOR ::=
7956 -- | subtype_Name ' Access
7960 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7962 -- MECHANISM_ASSOCIATION ::=
7963 -- [formal_parameter_NAME =>] MECHANISM_NAME
7965 -- MECHANISM_NAME ::=
7968 -- | Descriptor [([Class =>] CLASS_NAME)]
7970 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7972 when Pragma_Export_Function => Export_Function : declare
7973 Args : Args_List (1 .. 6);
7974 Names : constant Name_List (1 .. 6) := (
7977 Name_Parameter_Types,
7980 Name_Result_Mechanism);
7982 Internal : Node_Id renames Args (1);
7983 External : Node_Id renames Args (2);
7984 Parameter_Types : Node_Id renames Args (3);
7985 Result_Type : Node_Id renames Args (4);
7986 Mechanism : Node_Id renames Args (5);
7987 Result_Mechanism : Node_Id renames Args (6);
7991 Gather_Associations (Names, Args);
7992 Process_Extended_Import_Export_Subprogram_Pragma (
7993 Arg_Internal => Internal,
7994 Arg_External => External,
7995 Arg_Parameter_Types => Parameter_Types,
7996 Arg_Result_Type => Result_Type,
7997 Arg_Mechanism => Mechanism,
7998 Arg_Result_Mechanism => Result_Mechanism);
7999 end Export_Function;
8005 -- pragma Export_Object (
8006 -- [Internal =>] LOCAL_NAME
8007 -- [, [External =>] EXTERNAL_SYMBOL]
8008 -- [, [Size =>] EXTERNAL_SYMBOL]);
8010 -- EXTERNAL_SYMBOL ::=
8012 -- | static_string_EXPRESSION
8014 -- PARAMETER_TYPES ::=
8016 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8018 -- TYPE_DESIGNATOR ::=
8020 -- | subtype_Name ' Access
8024 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8026 -- MECHANISM_ASSOCIATION ::=
8027 -- [formal_parameter_NAME =>] MECHANISM_NAME
8029 -- MECHANISM_NAME ::=
8032 -- | Descriptor [([Class =>] CLASS_NAME)]
8034 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8036 when Pragma_Export_Object => Export_Object : declare
8037 Args : Args_List (1 .. 3);
8038 Names : constant Name_List (1 .. 3) := (
8043 Internal : Node_Id renames Args (1);
8044 External : Node_Id renames Args (2);
8045 Size : Node_Id renames Args (3);
8049 Gather_Associations (Names, Args);
8050 Process_Extended_Import_Export_Object_Pragma (
8051 Arg_Internal => Internal,
8052 Arg_External => External,
8056 ----------------------
8057 -- Export_Procedure --
8058 ----------------------
8060 -- pragma Export_Procedure (
8061 -- [Internal =>] LOCAL_NAME
8062 -- [, [External =>] EXTERNAL_SYMBOL]
8063 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8064 -- [, [Mechanism =>] MECHANISM]);
8066 -- EXTERNAL_SYMBOL ::=
8068 -- | static_string_EXPRESSION
8070 -- PARAMETER_TYPES ::=
8072 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8074 -- TYPE_DESIGNATOR ::=
8076 -- | subtype_Name ' Access
8080 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8082 -- MECHANISM_ASSOCIATION ::=
8083 -- [formal_parameter_NAME =>] MECHANISM_NAME
8085 -- MECHANISM_NAME ::=
8088 -- | Descriptor [([Class =>] CLASS_NAME)]
8090 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8092 when Pragma_Export_Procedure => Export_Procedure : declare
8093 Args : Args_List (1 .. 4);
8094 Names : constant Name_List (1 .. 4) := (
8097 Name_Parameter_Types,
8100 Internal : Node_Id renames Args (1);
8101 External : Node_Id renames Args (2);
8102 Parameter_Types : Node_Id renames Args (3);
8103 Mechanism : Node_Id renames Args (4);
8107 Gather_Associations (Names, Args);
8108 Process_Extended_Import_Export_Subprogram_Pragma (
8109 Arg_Internal => Internal,
8110 Arg_External => External,
8111 Arg_Parameter_Types => Parameter_Types,
8112 Arg_Mechanism => Mechanism);
8113 end Export_Procedure;
8119 -- pragma Export_Value (
8120 -- [Value =>] static_integer_EXPRESSION,
8121 -- [Link_Name =>] static_string_EXPRESSION);
8123 when Pragma_Export_Value =>
8125 Check_Arg_Order ((Name_Value, Name_Link_Name));
8126 Check_Arg_Count (2);
8128 Check_Optional_Identifier (Arg1, Name_Value);
8129 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8131 Check_Optional_Identifier (Arg2, Name_Link_Name);
8132 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8134 -----------------------------
8135 -- Export_Valued_Procedure --
8136 -----------------------------
8138 -- pragma Export_Valued_Procedure (
8139 -- [Internal =>] LOCAL_NAME
8140 -- [, [External =>] EXTERNAL_SYMBOL,]
8141 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8142 -- [, [Mechanism =>] MECHANISM]);
8144 -- EXTERNAL_SYMBOL ::=
8146 -- | static_string_EXPRESSION
8148 -- PARAMETER_TYPES ::=
8150 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8152 -- TYPE_DESIGNATOR ::=
8154 -- | subtype_Name ' Access
8158 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8160 -- MECHANISM_ASSOCIATION ::=
8161 -- [formal_parameter_NAME =>] MECHANISM_NAME
8163 -- MECHANISM_NAME ::=
8166 -- | Descriptor [([Class =>] CLASS_NAME)]
8168 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8170 when Pragma_Export_Valued_Procedure =>
8171 Export_Valued_Procedure : declare
8172 Args : Args_List (1 .. 4);
8173 Names : constant Name_List (1 .. 4) := (
8176 Name_Parameter_Types,
8179 Internal : Node_Id renames Args (1);
8180 External : Node_Id renames Args (2);
8181 Parameter_Types : Node_Id renames Args (3);
8182 Mechanism : Node_Id renames Args (4);
8186 Gather_Associations (Names, Args);
8187 Process_Extended_Import_Export_Subprogram_Pragma (
8188 Arg_Internal => Internal,
8189 Arg_External => External,
8190 Arg_Parameter_Types => Parameter_Types,
8191 Arg_Mechanism => Mechanism);
8192 end Export_Valued_Procedure;
8198 -- pragma Extend_System ([Name =>] Identifier);
8200 when Pragma_Extend_System => Extend_System : declare
8203 Check_Valid_Configuration_Pragma;
8204 Check_Arg_Count (1);
8205 Check_Optional_Identifier (Arg1, Name_Name);
8206 Check_Arg_Is_Identifier (Arg1);
8208 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8211 and then Name_Buffer (1 .. 4) = "aux_"
8213 if Present (System_Extend_Pragma_Arg) then
8214 if Chars (Get_Pragma_Arg (Arg1)) =
8215 Chars (Expression (System_Extend_Pragma_Arg))
8219 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8220 Error_Pragma ("pragma% conflicts with that #");
8224 System_Extend_Pragma_Arg := Arg1;
8226 if not GNAT_Mode then
8227 System_Extend_Unit := Arg1;
8231 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8235 ------------------------
8236 -- Extensions_Allowed --
8237 ------------------------
8239 -- pragma Extensions_Allowed (ON | OFF);
8241 when Pragma_Extensions_Allowed =>
8243 Check_Arg_Count (1);
8244 Check_No_Identifiers;
8245 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8247 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8248 Extensions_Allowed := True;
8249 Ada_Version := Ada_Version_Type'Last;
8252 Extensions_Allowed := False;
8253 Ada_Version := Ada_Version_Explicit;
8260 -- pragma External (
8261 -- [ Convention =>] convention_IDENTIFIER,
8262 -- [ Entity =>] local_NAME
8263 -- [, [External_Name =>] static_string_EXPRESSION ]
8264 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8266 when Pragma_External => External : declare
8270 pragma Warnings (Off, C);
8279 Check_At_Least_N_Arguments (2);
8280 Check_At_Most_N_Arguments (4);
8281 Process_Convention (C, Def_Id);
8282 Note_Possible_Modification
8283 (Get_Pragma_Arg (Arg2), Sure => False);
8284 Process_Interface_Name (Def_Id, Arg3, Arg4);
8285 Set_Exported (Def_Id, Arg2);
8288 --------------------------
8289 -- External_Name_Casing --
8290 --------------------------
8292 -- pragma External_Name_Casing (
8293 -- UPPERCASE | LOWERCASE
8294 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8296 when Pragma_External_Name_Casing => External_Name_Casing : declare
8299 Check_No_Identifiers;
8301 if Arg_Count = 2 then
8303 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8305 case Chars (Get_Pragma_Arg (Arg2)) is
8307 Opt.External_Name_Exp_Casing := As_Is;
8309 when Name_Uppercase =>
8310 Opt.External_Name_Exp_Casing := Uppercase;
8312 when Name_Lowercase =>
8313 Opt.External_Name_Exp_Casing := Lowercase;
8320 Check_Arg_Count (1);
8323 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8325 case Chars (Get_Pragma_Arg (Arg1)) is
8326 when Name_Uppercase =>
8327 Opt.External_Name_Imp_Casing := Uppercase;
8329 when Name_Lowercase =>
8330 Opt.External_Name_Imp_Casing := Lowercase;
8335 end External_Name_Casing;
8337 --------------------------
8338 -- Favor_Top_Level --
8339 --------------------------
8341 -- pragma Favor_Top_Level (type_NAME);
8343 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8344 Named_Entity : Entity_Id;
8348 Check_No_Identifiers;
8349 Check_Arg_Count (1);
8350 Check_Arg_Is_Local_Name (Arg1);
8351 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8353 -- If it's an access-to-subprogram type (in particular, not a
8354 -- subtype), set the flag on that type.
8356 if Is_Access_Subprogram_Type (Named_Entity) then
8357 Set_Can_Use_Internal_Rep (Named_Entity, False);
8359 -- Otherwise it's an error (name denotes the wrong sort of entity)
8363 ("access-to-subprogram type expected",
8364 Get_Pragma_Arg (Arg1));
8366 end Favor_Top_Level;
8372 -- pragma Fast_Math;
8374 when Pragma_Fast_Math =>
8376 Check_No_Identifiers;
8377 Check_Valid_Configuration_Pragma;
8380 ---------------------------
8381 -- Finalize_Storage_Only --
8382 ---------------------------
8384 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8386 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8387 Assoc : constant Node_Id := Arg1;
8388 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8393 Check_No_Identifiers;
8394 Check_Arg_Count (1);
8395 Check_Arg_Is_Local_Name (Arg1);
8397 Find_Type (Type_Id);
8398 Typ := Entity (Type_Id);
8401 or else Rep_Item_Too_Early (Typ, N)
8405 Typ := Underlying_Type (Typ);
8408 if not Is_Controlled (Typ) then
8409 Error_Pragma ("pragma% must specify controlled type");
8412 Check_First_Subtype (Arg1);
8414 if Finalize_Storage_Only (Typ) then
8415 Error_Pragma ("duplicate pragma%, only one allowed");
8417 elsif not Rep_Item_Too_Late (Typ, N) then
8418 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8420 end Finalize_Storage;
8422 --------------------------
8423 -- Float_Representation --
8424 --------------------------
8426 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8428 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8430 when Pragma_Float_Representation => Float_Representation : declare
8438 if Arg_Count = 1 then
8439 Check_Valid_Configuration_Pragma;
8441 Check_Arg_Count (2);
8442 Check_Optional_Identifier (Arg2, Name_Entity);
8443 Check_Arg_Is_Local_Name (Arg2);
8446 Check_No_Identifier (Arg1);
8447 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8449 if not OpenVMS_On_Target then
8450 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8452 ("?pragma% ignored (applies only to Open'V'M'S)");
8458 -- One argument case
8460 if Arg_Count = 1 then
8461 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8462 if Opt.Float_Format = 'I' then
8463 Error_Pragma ("'I'E'E'E format previously specified");
8466 Opt.Float_Format := 'V';
8469 if Opt.Float_Format = 'V' then
8470 Error_Pragma ("'V'A'X format previously specified");
8473 Opt.Float_Format := 'I';
8476 Set_Standard_Fpt_Formats;
8478 -- Two argument case
8481 Argx := Get_Pragma_Arg (Arg2);
8483 if not Is_Entity_Name (Argx)
8484 or else not Is_Floating_Point_Type (Entity (Argx))
8487 ("second argument of% pragma must be floating-point type",
8491 Ent := Entity (Argx);
8492 Digs := UI_To_Int (Digits_Value (Ent));
8494 -- Two arguments, VAX_Float case
8496 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8498 when 6 => Set_F_Float (Ent);
8499 when 9 => Set_D_Float (Ent);
8500 when 15 => Set_G_Float (Ent);
8504 ("wrong digits value, must be 6,9 or 15", Arg2);
8507 -- Two arguments, IEEE_Float case
8511 when 6 => Set_IEEE_Short (Ent);
8512 when 15 => Set_IEEE_Long (Ent);
8516 ("wrong digits value, must be 6 or 15", Arg2);
8520 end Float_Representation;
8526 -- pragma Ident (static_string_EXPRESSION)
8528 -- Note: pragma Comment shares this processing. Pragma Comment is
8529 -- identical to Ident, except that the restriction of the argument to
8530 -- 31 characters and the placement restrictions are not enforced for
8533 when Pragma_Ident | Pragma_Comment => Ident : declare
8538 Check_Arg_Count (1);
8539 Check_No_Identifiers;
8540 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8543 -- For pragma Ident, preserve DEC compatibility by requiring the
8544 -- pragma to appear in a declarative part or package spec.
8546 if Prag_Id = Pragma_Ident then
8547 Check_Is_In_Decl_Part_Or_Package_Spec;
8550 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8557 GP := Parent (Parent (N));
8559 if Nkind_In (GP, N_Package_Declaration,
8560 N_Generic_Package_Declaration)
8565 -- If we have a compilation unit, then record the ident value,
8566 -- checking for improper duplication.
8568 if Nkind (GP) = N_Compilation_Unit then
8569 CS := Ident_String (Current_Sem_Unit);
8571 if Present (CS) then
8573 -- For Ident, we do not permit multiple instances
8575 if Prag_Id = Pragma_Ident then
8576 Error_Pragma ("duplicate% pragma not permitted");
8578 -- For Comment, we concatenate the string, unless we want
8579 -- to preserve the tree structure for ASIS.
8581 elsif not ASIS_Mode then
8582 Start_String (Strval (CS));
8583 Store_String_Char (' ');
8584 Store_String_Chars (Strval (Str));
8585 Set_Strval (CS, End_String);
8589 -- In VMS, the effect of IDENT is achieved by passing
8590 -- --identification=name as a --for-linker switch.
8592 if OpenVMS_On_Target then
8595 ("--for-linker=--identification=");
8596 String_To_Name_Buffer (Strval (Str));
8597 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8599 -- Only the last processed IDENT is saved. The main
8600 -- purpose is so an IDENT associated with a main
8601 -- procedure will be used in preference to an IDENT
8602 -- associated with a with'd package.
8604 Replace_Linker_Option_String
8605 (End_String, "--for-linker=--identification=");
8608 Set_Ident_String (Current_Sem_Unit, Str);
8611 -- For subunits, we just ignore the Ident, since in GNAT these
8612 -- are not separate object files, and hence not separate units
8613 -- in the unit table.
8615 elsif Nkind (GP) = N_Subunit then
8618 -- Otherwise we have a misplaced pragma Ident, but we ignore
8619 -- this if we are in an instantiation, since it comes from
8620 -- a generic, and has no relevance to the instantiation.
8622 elsif Prag_Id = Pragma_Ident then
8623 if Instantiation_Location (Loc) = No_Location then
8624 Error_Pragma ("pragma% only allowed at outer level");
8634 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8635 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8637 when Pragma_Implemented => Implemented : declare
8638 Proc_Id : Entity_Id;
8643 Check_Arg_Count (2);
8644 Check_No_Identifiers;
8645 Check_Arg_Is_Identifier (Arg1);
8646 Check_Arg_Is_Local_Name (Arg1);
8648 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8650 -- Extract the name of the local procedure
8652 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8654 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8655 -- primitive procedure of a synchronized tagged type.
8657 if Ekind (Proc_Id) = E_Procedure
8658 and then Is_Primitive (Proc_Id)
8659 and then Present (First_Formal (Proc_Id))
8661 Typ := Etype (First_Formal (Proc_Id));
8663 if Is_Tagged_Type (Typ)
8666 -- Check for a protected, a synchronized or a task interface
8668 ((Is_Interface (Typ)
8669 and then Is_Synchronized_Interface (Typ))
8671 -- Check for a protected type or a task type that implements
8675 (Is_Concurrent_Record_Type (Typ)
8676 and then Present (Interfaces (Typ)))
8678 -- Check for a private record extension with keyword
8682 (Ekind_In (Typ, E_Record_Type_With_Private,
8683 E_Record_Subtype_With_Private)
8684 and then Synchronized_Present (Parent (Typ))))
8689 ("controlling formal must be of synchronized " &
8690 "tagged type", Arg1);
8694 -- Procedures declared inside a protected type must be accepted
8696 elsif Ekind (Proc_Id) = E_Procedure
8697 and then Is_Protected_Type (Scope (Proc_Id))
8701 -- The first argument is not a primitive procedure
8705 ("pragma % must be applied to a primitive procedure", Arg1);
8709 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8710 -- By_Protected_Procedure to the primitive procedure of a task
8713 if Chars (Arg2) = Name_By_Protected_Procedure
8714 and then Is_Interface (Typ)
8715 and then Is_Task_Interface (Typ)
8718 ("implementation kind By_Protected_Procedure cannot be " &
8719 "applied to a task interface primitive", Arg2);
8723 Record_Rep_Item (Proc_Id, N);
8726 ----------------------
8727 -- Implicit_Packing --
8728 ----------------------
8730 -- pragma Implicit_Packing;
8732 when Pragma_Implicit_Packing =>
8734 Check_Arg_Count (0);
8735 Implicit_Packing := True;
8742 -- [Convention =>] convention_IDENTIFIER,
8743 -- [Entity =>] local_NAME
8744 -- [, [External_Name =>] static_string_EXPRESSION ]
8745 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8747 when Pragma_Import =>
8748 Check_Ada_83_Warning;
8754 Check_At_Least_N_Arguments (2);
8755 Check_At_Most_N_Arguments (4);
8756 Process_Import_Or_Interface;
8758 ----------------------
8759 -- Import_Exception --
8760 ----------------------
8762 -- pragma Import_Exception (
8763 -- [Internal =>] LOCAL_NAME
8764 -- [, [External =>] EXTERNAL_SYMBOL]
8765 -- [, [Form =>] Ada | VMS]
8766 -- [, [Code =>] static_integer_EXPRESSION]);
8768 when Pragma_Import_Exception => Import_Exception : declare
8769 Args : Args_List (1 .. 4);
8770 Names : constant Name_List (1 .. 4) := (
8776 Internal : Node_Id renames Args (1);
8777 External : Node_Id renames Args (2);
8778 Form : Node_Id renames Args (3);
8779 Code : Node_Id renames Args (4);
8783 Gather_Associations (Names, Args);
8785 if Present (External) and then Present (Code) then
8787 ("cannot give both External and Code options for pragma%");
8790 Process_Extended_Import_Export_Exception_Pragma (
8791 Arg_Internal => Internal,
8792 Arg_External => External,
8796 if not Is_VMS_Exception (Entity (Internal)) then
8797 Set_Imported (Entity (Internal));
8799 end Import_Exception;
8801 ---------------------
8802 -- Import_Function --
8803 ---------------------
8805 -- pragma Import_Function (
8806 -- [Internal =>] LOCAL_NAME,
8807 -- [, [External =>] EXTERNAL_SYMBOL]
8808 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8809 -- [, [Result_Type =>] SUBTYPE_MARK]
8810 -- [, [Mechanism =>] MECHANISM]
8811 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8812 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8814 -- EXTERNAL_SYMBOL ::=
8816 -- | static_string_EXPRESSION
8818 -- PARAMETER_TYPES ::=
8820 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8822 -- TYPE_DESIGNATOR ::=
8824 -- | subtype_Name ' Access
8828 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8830 -- MECHANISM_ASSOCIATION ::=
8831 -- [formal_parameter_NAME =>] MECHANISM_NAME
8833 -- MECHANISM_NAME ::=
8836 -- | Descriptor [([Class =>] CLASS_NAME)]
8838 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8840 when Pragma_Import_Function => Import_Function : declare
8841 Args : Args_List (1 .. 7);
8842 Names : constant Name_List (1 .. 7) := (
8845 Name_Parameter_Types,
8848 Name_Result_Mechanism,
8849 Name_First_Optional_Parameter);
8851 Internal : Node_Id renames Args (1);
8852 External : Node_Id renames Args (2);
8853 Parameter_Types : Node_Id renames Args (3);
8854 Result_Type : Node_Id renames Args (4);
8855 Mechanism : Node_Id renames Args (5);
8856 Result_Mechanism : Node_Id renames Args (6);
8857 First_Optional_Parameter : Node_Id renames Args (7);
8861 Gather_Associations (Names, Args);
8862 Process_Extended_Import_Export_Subprogram_Pragma (
8863 Arg_Internal => Internal,
8864 Arg_External => External,
8865 Arg_Parameter_Types => Parameter_Types,
8866 Arg_Result_Type => Result_Type,
8867 Arg_Mechanism => Mechanism,
8868 Arg_Result_Mechanism => Result_Mechanism,
8869 Arg_First_Optional_Parameter => First_Optional_Parameter);
8870 end Import_Function;
8876 -- pragma Import_Object (
8877 -- [Internal =>] LOCAL_NAME
8878 -- [, [External =>] EXTERNAL_SYMBOL]
8879 -- [, [Size =>] EXTERNAL_SYMBOL]);
8881 -- EXTERNAL_SYMBOL ::=
8883 -- | static_string_EXPRESSION
8885 when Pragma_Import_Object => Import_Object : declare
8886 Args : Args_List (1 .. 3);
8887 Names : constant Name_List (1 .. 3) := (
8892 Internal : Node_Id renames Args (1);
8893 External : Node_Id renames Args (2);
8894 Size : Node_Id renames Args (3);
8898 Gather_Associations (Names, Args);
8899 Process_Extended_Import_Export_Object_Pragma (
8900 Arg_Internal => Internal,
8901 Arg_External => External,
8905 ----------------------
8906 -- Import_Procedure --
8907 ----------------------
8909 -- pragma Import_Procedure (
8910 -- [Internal =>] LOCAL_NAME
8911 -- [, [External =>] EXTERNAL_SYMBOL]
8912 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8913 -- [, [Mechanism =>] MECHANISM]
8914 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8916 -- EXTERNAL_SYMBOL ::=
8918 -- | static_string_EXPRESSION
8920 -- PARAMETER_TYPES ::=
8922 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8924 -- TYPE_DESIGNATOR ::=
8926 -- | subtype_Name ' Access
8930 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8932 -- MECHANISM_ASSOCIATION ::=
8933 -- [formal_parameter_NAME =>] MECHANISM_NAME
8935 -- MECHANISM_NAME ::=
8938 -- | Descriptor [([Class =>] CLASS_NAME)]
8940 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8942 when Pragma_Import_Procedure => Import_Procedure : declare
8943 Args : Args_List (1 .. 5);
8944 Names : constant Name_List (1 .. 5) := (
8947 Name_Parameter_Types,
8949 Name_First_Optional_Parameter);
8951 Internal : Node_Id renames Args (1);
8952 External : Node_Id renames Args (2);
8953 Parameter_Types : Node_Id renames Args (3);
8954 Mechanism : Node_Id renames Args (4);
8955 First_Optional_Parameter : Node_Id renames Args (5);
8959 Gather_Associations (Names, Args);
8960 Process_Extended_Import_Export_Subprogram_Pragma (
8961 Arg_Internal => Internal,
8962 Arg_External => External,
8963 Arg_Parameter_Types => Parameter_Types,
8964 Arg_Mechanism => Mechanism,
8965 Arg_First_Optional_Parameter => First_Optional_Parameter);
8966 end Import_Procedure;
8968 -----------------------------
8969 -- Import_Valued_Procedure --
8970 -----------------------------
8972 -- pragma Import_Valued_Procedure (
8973 -- [Internal =>] LOCAL_NAME
8974 -- [, [External =>] EXTERNAL_SYMBOL]
8975 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8976 -- [, [Mechanism =>] MECHANISM]
8977 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8979 -- EXTERNAL_SYMBOL ::=
8981 -- | static_string_EXPRESSION
8983 -- PARAMETER_TYPES ::=
8985 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8987 -- TYPE_DESIGNATOR ::=
8989 -- | subtype_Name ' Access
8993 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8995 -- MECHANISM_ASSOCIATION ::=
8996 -- [formal_parameter_NAME =>] MECHANISM_NAME
8998 -- MECHANISM_NAME ::=
9001 -- | Descriptor [([Class =>] CLASS_NAME)]
9003 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9005 when Pragma_Import_Valued_Procedure =>
9006 Import_Valued_Procedure : declare
9007 Args : Args_List (1 .. 5);
9008 Names : constant Name_List (1 .. 5) := (
9011 Name_Parameter_Types,
9013 Name_First_Optional_Parameter);
9015 Internal : Node_Id renames Args (1);
9016 External : Node_Id renames Args (2);
9017 Parameter_Types : Node_Id renames Args (3);
9018 Mechanism : Node_Id renames Args (4);
9019 First_Optional_Parameter : Node_Id renames Args (5);
9023 Gather_Associations (Names, Args);
9024 Process_Extended_Import_Export_Subprogram_Pragma (
9025 Arg_Internal => Internal,
9026 Arg_External => External,
9027 Arg_Parameter_Types => Parameter_Types,
9028 Arg_Mechanism => Mechanism,
9029 Arg_First_Optional_Parameter => First_Optional_Parameter);
9030 end Import_Valued_Procedure;
9036 -- pragma Independent (LOCAL_NAME);
9038 when Pragma_Independent => Independent : declare
9045 Check_Ada_83_Warning;
9047 Check_No_Identifiers;
9048 Check_Arg_Count (1);
9049 Check_Arg_Is_Local_Name (Arg1);
9050 E_Id := Get_Pragma_Arg (Arg1);
9052 if Etype (E_Id) = Any_Type then
9057 D := Declaration_Node (E);
9060 -- Check duplicate before we chain ourselves!
9062 Check_Duplicate_Pragma (E);
9064 -- Check appropriate entity
9067 if Rep_Item_Too_Early (E, N)
9069 Rep_Item_Too_Late (E, N)
9073 Check_First_Subtype (Arg1);
9076 elsif K = N_Object_Declaration
9077 or else (K = N_Component_Declaration
9078 and then Original_Record_Component (E) = E)
9080 if Rep_Item_Too_Late (E, N) then
9086 ("inappropriate entity for pragma%", Arg1);
9089 Independence_Checks.Append ((N, E));
9092 ----------------------------
9093 -- Independent_Components --
9094 ----------------------------
9096 -- pragma Atomic_Components (array_LOCAL_NAME);
9098 -- This processing is shared by Volatile_Components
9100 when Pragma_Independent_Components => Independent_Components : declare
9107 Check_Ada_83_Warning;
9109 Check_No_Identifiers;
9110 Check_Arg_Count (1);
9111 Check_Arg_Is_Local_Name (Arg1);
9112 E_Id := Get_Pragma_Arg (Arg1);
9114 if Etype (E_Id) = Any_Type then
9120 -- Check duplicate before we chain ourselves!
9122 Check_Duplicate_Pragma (E);
9124 -- Check appropriate entity
9126 if Rep_Item_Too_Early (E, N)
9128 Rep_Item_Too_Late (E, N)
9133 D := Declaration_Node (E);
9136 if (K = N_Full_Type_Declaration
9137 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9139 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9140 and then Nkind (D) = N_Object_Declaration
9141 and then Nkind (Object_Definition (D)) =
9142 N_Constrained_Array_Definition)
9144 Independence_Checks.Append ((N, E));
9147 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9149 end Independent_Components;
9151 ------------------------
9152 -- Initialize_Scalars --
9153 ------------------------
9155 -- pragma Initialize_Scalars;
9157 when Pragma_Initialize_Scalars =>
9159 Check_Arg_Count (0);
9160 Check_Valid_Configuration_Pragma;
9161 Check_Restriction (No_Initialize_Scalars, N);
9163 -- Initialize_Scalars creates false positives in CodePeer,
9164 -- so ignore this pragma in this mode.
9166 if not Restriction_Active (No_Initialize_Scalars)
9167 and then not CodePeer_Mode
9169 Init_Or_Norm_Scalars := True;
9170 Initialize_Scalars := True;
9177 -- pragma Inline ( NAME {, NAME} );
9179 when Pragma_Inline =>
9181 -- Pragma is active if inlining option is active
9183 Process_Inline (Inline_Active);
9189 -- pragma Inline_Always ( NAME {, NAME} );
9191 when Pragma_Inline_Always =>
9194 -- Pragma always active unless in CodePeer mode, since this causes
9195 -- walk order issues.
9197 if not CodePeer_Mode then
9198 Process_Inline (True);
9201 --------------------
9202 -- Inline_Generic --
9203 --------------------
9205 -- pragma Inline_Generic (NAME {, NAME});
9207 when Pragma_Inline_Generic =>
9209 Process_Generic_List;
9211 ----------------------
9212 -- Inspection_Point --
9213 ----------------------
9215 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9217 when Pragma_Inspection_Point => Inspection_Point : declare
9222 if Arg_Count > 0 then
9225 Exp := Get_Pragma_Arg (Arg);
9228 if not Is_Entity_Name (Exp)
9229 or else not Is_Object (Entity (Exp))
9231 Error_Pragma_Arg ("object name required", Arg);
9238 end Inspection_Point;
9244 -- pragma Interface (
9245 -- [ Convention =>] convention_IDENTIFIER,
9246 -- [ Entity =>] local_NAME
9247 -- [, [External_Name =>] static_string_EXPRESSION ]
9248 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9250 when Pragma_Interface =>
9257 Check_At_Least_N_Arguments (2);
9258 Check_At_Most_N_Arguments (4);
9259 Process_Import_Or_Interface;
9261 -- In Ada 2005, the permission to use Interface (a reserved word)
9262 -- as a pragma name is considered an obsolescent feature.
9264 if Ada_Version >= Ada_2005 then
9266 (No_Obsolescent_Features, Pragma_Identifier (N));
9269 --------------------
9270 -- Interface_Name --
9271 --------------------
9273 -- pragma Interface_Name (
9274 -- [ Entity =>] local_NAME
9275 -- [,[External_Name =>] static_string_EXPRESSION ]
9276 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9278 when Pragma_Interface_Name => Interface_Name : declare
9287 ((Name_Entity, Name_External_Name, Name_Link_Name));
9288 Check_At_Least_N_Arguments (2);
9289 Check_At_Most_N_Arguments (3);
9290 Id := Get_Pragma_Arg (Arg1);
9293 if not Is_Entity_Name (Id) then
9295 ("first argument for pragma% must be entity name", Arg1);
9296 elsif Etype (Id) = Any_Type then
9299 Def_Id := Entity (Id);
9302 -- Special DEC-compatible processing for the object case, forces
9303 -- object to be imported.
9305 if Ekind (Def_Id) = E_Variable then
9306 Kill_Size_Check_Code (Def_Id);
9307 Note_Possible_Modification (Id, Sure => False);
9309 -- Initialization is not allowed for imported variable
9311 if Present (Expression (Parent (Def_Id)))
9312 and then Comes_From_Source (Expression (Parent (Def_Id)))
9314 Error_Msg_Sloc := Sloc (Def_Id);
9316 ("no initialization allowed for declaration of& #",
9320 -- For compatibility, support VADS usage of providing both
9321 -- pragmas Interface and Interface_Name to obtain the effect
9322 -- of a single Import pragma.
9324 if Is_Imported (Def_Id)
9325 and then Present (First_Rep_Item (Def_Id))
9326 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9328 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9332 Set_Imported (Def_Id);
9335 Set_Is_Public (Def_Id);
9336 Process_Interface_Name (Def_Id, Arg2, Arg3);
9339 -- Otherwise must be subprogram
9341 elsif not Is_Subprogram (Def_Id) then
9343 ("argument of pragma% is not subprogram", Arg1);
9346 Check_At_Most_N_Arguments (3);
9350 -- Loop through homonyms
9353 Def_Id := Get_Base_Subprogram (Hom_Id);
9355 if Is_Imported (Def_Id) then
9356 Process_Interface_Name (Def_Id, Arg2, Arg3);
9360 exit when From_Aspect_Specification (N);
9361 Hom_Id := Homonym (Hom_Id);
9363 exit when No (Hom_Id)
9364 or else Scope (Hom_Id) /= Current_Scope;
9369 ("argument of pragma% is not imported subprogram",
9375 -----------------------
9376 -- Interrupt_Handler --
9377 -----------------------
9379 -- pragma Interrupt_Handler (handler_NAME);
9381 when Pragma_Interrupt_Handler =>
9382 Check_Ada_83_Warning;
9383 Check_Arg_Count (1);
9384 Check_No_Identifiers;
9386 if No_Run_Time_Mode then
9387 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9389 Check_Interrupt_Or_Attach_Handler;
9390 Process_Interrupt_Or_Attach_Handler;
9393 ------------------------
9394 -- Interrupt_Priority --
9395 ------------------------
9397 -- pragma Interrupt_Priority [(EXPRESSION)];
9399 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9400 P : constant Node_Id := Parent (N);
9404 Check_Ada_83_Warning;
9406 if Arg_Count /= 0 then
9407 Arg := Get_Pragma_Arg (Arg1);
9408 Check_Arg_Count (1);
9409 Check_No_Identifiers;
9411 -- The expression must be analyzed in the special manner
9412 -- described in "Handling of Default and Per-Object
9413 -- Expressions" in sem.ads.
9415 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9418 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9422 elsif Has_Pragma_Priority (P) then
9423 Error_Pragma ("duplicate pragma% not allowed");
9426 Set_Has_Pragma_Priority (P, True);
9427 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9429 end Interrupt_Priority;
9431 ---------------------
9432 -- Interrupt_State --
9433 ---------------------
9435 -- pragma Interrupt_State (
9436 -- [Name =>] INTERRUPT_ID,
9437 -- [State =>] INTERRUPT_STATE);
9439 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9440 -- INTERRUPT_STATE => System | Runtime | User
9442 -- Note: if the interrupt id is given as an identifier, then it must
9443 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9444 -- given as a static integer expression which must be in the range of
9445 -- Ada.Interrupts.Interrupt_ID.
9447 when Pragma_Interrupt_State => Interrupt_State : declare
9449 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9450 -- This is the entity Ada.Interrupts.Interrupt_ID;
9452 State_Type : Character;
9453 -- Set to 's'/'r'/'u' for System/Runtime/User
9456 -- Index to entry in Interrupt_States table
9459 -- Value of interrupt
9461 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9462 -- The first argument to the pragma
9464 Int_Ent : Entity_Id;
9465 -- Interrupt entity in Ada.Interrupts.Names
9469 Check_Arg_Order ((Name_Name, Name_State));
9470 Check_Arg_Count (2);
9472 Check_Optional_Identifier (Arg1, Name_Name);
9473 Check_Optional_Identifier (Arg2, Name_State);
9474 Check_Arg_Is_Identifier (Arg2);
9476 -- First argument is identifier
9478 if Nkind (Arg1X) = N_Identifier then
9480 -- Search list of names in Ada.Interrupts.Names
9482 Int_Ent := First_Entity (RTE (RE_Names));
9484 if No (Int_Ent) then
9485 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9487 elsif Chars (Int_Ent) = Chars (Arg1X) then
9488 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9492 Next_Entity (Int_Ent);
9495 -- First argument is not an identifier, so it must be a static
9496 -- expression of type Ada.Interrupts.Interrupt_ID.
9499 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9500 Int_Val := Expr_Value (Arg1X);
9502 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9504 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9507 ("value not in range of type " &
9508 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9514 case Chars (Get_Pragma_Arg (Arg2)) is
9515 when Name_Runtime => State_Type := 'r';
9516 when Name_System => State_Type := 's';
9517 when Name_User => State_Type := 'u';
9520 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9523 -- Check if entry is already stored
9525 IST_Num := Interrupt_States.First;
9527 -- If entry not found, add it
9529 if IST_Num > Interrupt_States.Last then
9530 Interrupt_States.Append
9531 ((Interrupt_Number => UI_To_Int (Int_Val),
9532 Interrupt_State => State_Type,
9533 Pragma_Loc => Loc));
9536 -- Case of entry for the same entry
9538 elsif Int_Val = Interrupt_States.Table (IST_Num).
9541 -- If state matches, done, no need to make redundant entry
9544 State_Type = Interrupt_States.Table (IST_Num).
9547 -- Otherwise if state does not match, error
9550 Interrupt_States.Table (IST_Num).Pragma_Loc;
9552 ("state conflicts with that given #", Arg2);
9556 IST_Num := IST_Num + 1;
9558 end Interrupt_State;
9565 -- ([Entity =>] type_LOCAL_NAME,
9566 -- [Check =>] EXPRESSION
9567 -- [,[Message =>] String_Expression]);
9569 when Pragma_Invariant => Invariant : declare
9574 pragma Unreferenced (Discard);
9578 Check_At_Least_N_Arguments (2);
9579 Check_At_Most_N_Arguments (3);
9580 Check_Optional_Identifier (Arg1, Name_Entity);
9581 Check_Optional_Identifier (Arg2, Name_Check);
9583 if Arg_Count = 3 then
9584 Check_Optional_Identifier (Arg3, Name_Message);
9585 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9588 Check_Arg_Is_Local_Name (Arg1);
9590 Type_Id := Get_Pragma_Arg (Arg1);
9591 Find_Type (Type_Id);
9592 Typ := Entity (Type_Id);
9594 if Typ = Any_Type then
9597 elsif not Ekind_In (Typ, E_Private_Type,
9598 E_Record_Type_With_Private,
9599 E_Limited_Private_Type)
9602 ("pragma% only allowed for private type", Arg1);
9605 -- Note that the type has at least one invariant, and also that
9606 -- it has inheritable invariants if we have Invariant'Class.
9608 Set_Has_Invariants (Typ);
9610 if Class_Present (N) then
9611 Set_Has_Inheritable_Invariants (Typ);
9614 -- The remaining processing is simply to link the pragma on to
9615 -- the rep item chain, for processing when the type is frozen.
9616 -- This is accomplished by a call to Rep_Item_Too_Late.
9618 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9621 ----------------------
9622 -- Java_Constructor --
9623 ----------------------
9625 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9627 -- Also handles pragma CIL_Constructor
9629 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9630 Java_Constructor : declare
9631 Convention : Convention_Id;
9635 This_Formal : Entity_Id;
9639 Check_Arg_Count (1);
9640 Check_Optional_Identifier (Arg1, Name_Entity);
9641 Check_Arg_Is_Local_Name (Arg1);
9643 Id := Get_Pragma_Arg (Arg1);
9644 Find_Program_Unit_Name (Id);
9646 -- If we did not find the name, we are done
9648 if Etype (Id) = Any_Type then
9652 -- Check wrong use of pragma in wrong VM target
9654 if VM_Target = No_VM then
9657 elsif VM_Target = CLI_Target
9658 and then Prag_Id = Pragma_Java_Constructor
9660 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9662 elsif VM_Target = JVM_Target
9663 and then Prag_Id = Pragma_CIL_Constructor
9665 Error_Pragma ("must use pragma 'Java_'Constructor");
9669 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9670 when Pragma_Java_Constructor => Convention := Convention_Java;
9671 when others => null;
9674 Hom_Id := Entity (Id);
9676 -- Loop through homonyms
9679 Def_Id := Get_Base_Subprogram (Hom_Id);
9681 -- The constructor is required to be a function
9683 if Ekind (Def_Id) /= E_Function then
9684 if VM_Target = JVM_Target then
9686 ("pragma% requires function returning a " &
9687 "'Java access type", Def_Id);
9690 ("pragma% requires function returning a " &
9691 "'C'I'L access type", Def_Id);
9695 -- Check arguments: For tagged type the first formal must be
9696 -- named "this" and its type must be a named access type
9697 -- designating a class-wide tagged type that has convention
9698 -- CIL/Java. The first formal must also have a null default
9699 -- value. For example:
9701 -- type Typ is tagged ...
9702 -- type Ref is access all Typ;
9703 -- pragma Convention (CIL, Typ);
9705 -- function New_Typ (This : Ref) return Ref;
9706 -- function New_Typ (This : Ref; I : Integer) return Ref;
9707 -- pragma Cil_Constructor (New_Typ);
9709 -- Reason: The first formal must NOT be a primitive of the
9712 -- This rule also applies to constructors of delegates used
9713 -- to interface with standard target libraries. For example:
9715 -- type Delegate is access procedure ...
9716 -- pragma Import (CIL, Delegate, ...);
9718 -- function new_Delegate
9719 -- (This : Delegate := null; ... ) return Delegate;
9721 -- For value-types this rule does not apply.
9723 if not Is_Value_Type (Etype (Def_Id)) then
9724 if No (First_Formal (Def_Id)) then
9725 Error_Msg_Name_1 := Pname;
9726 Error_Msg_N ("% function must have parameters", Def_Id);
9730 -- In the JRE library we have several occurrences in which
9731 -- the "this" parameter is not the first formal.
9733 This_Formal := First_Formal (Def_Id);
9735 -- In the JRE library we have several occurrences in which
9736 -- the "this" parameter is not the first formal. Search for
9739 if VM_Target = JVM_Target then
9740 while Present (This_Formal)
9741 and then Get_Name_String (Chars (This_Formal)) /= "this"
9743 Next_Formal (This_Formal);
9746 if No (This_Formal) then
9747 This_Formal := First_Formal (Def_Id);
9751 -- Warning: The first parameter should be named "this".
9752 -- We temporarily allow it because we have the following
9753 -- case in the Java runtime (file s-osinte.ads) ???
9755 -- function new_Thread
9756 -- (Self_Id : System.Address) return Thread_Id;
9757 -- pragma Java_Constructor (new_Thread);
9759 if VM_Target = JVM_Target
9760 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9762 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9766 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9767 Error_Msg_Name_1 := Pname;
9769 ("first formal of % function must be named `this`",
9770 Parent (This_Formal));
9772 elsif not Is_Access_Type (Etype (This_Formal)) then
9773 Error_Msg_Name_1 := Pname;
9775 ("first formal of % function must be an access type",
9776 Parameter_Type (Parent (This_Formal)));
9778 -- For delegates the type of the first formal must be a
9779 -- named access-to-subprogram type (see previous example)
9781 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9782 and then Ekind (Etype (This_Formal))
9783 /= E_Access_Subprogram_Type
9785 Error_Msg_Name_1 := Pname;
9787 ("first formal of % function must be a named access" &
9788 " to subprogram type",
9789 Parameter_Type (Parent (This_Formal)));
9791 -- Warning: We should reject anonymous access types because
9792 -- the constructor must not be handled as a primitive of the
9793 -- tagged type. We temporarily allow it because this profile
9794 -- is currently generated by cil2ada???
9796 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9797 and then not Ekind_In (Etype (This_Formal),
9799 E_General_Access_Type,
9800 E_Anonymous_Access_Type)
9802 Error_Msg_Name_1 := Pname;
9804 ("first formal of % function must be a named access" &
9806 Parameter_Type (Parent (This_Formal)));
9808 elsif Atree.Convention
9809 (Designated_Type (Etype (This_Formal))) /= Convention
9811 Error_Msg_Name_1 := Pname;
9813 if Convention = Convention_Java then
9815 ("pragma% requires convention 'Cil in designated" &
9817 Parameter_Type (Parent (This_Formal)));
9820 ("pragma% requires convention 'Java in designated" &
9822 Parameter_Type (Parent (This_Formal)));
9825 elsif No (Expression (Parent (This_Formal)))
9826 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9828 Error_Msg_Name_1 := Pname;
9830 ("pragma% requires first formal with default `null`",
9831 Parameter_Type (Parent (This_Formal)));
9835 -- Check result type: the constructor must be a function
9837 -- * a value type (only allowed in the CIL compiler)
9838 -- * an access-to-subprogram type with convention Java/CIL
9839 -- * an access-type designating a type that has convention
9842 if Is_Value_Type (Etype (Def_Id)) then
9845 -- Access-to-subprogram type with convention Java/CIL
9847 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9848 if Atree.Convention (Etype (Def_Id)) /= Convention then
9849 if Convention = Convention_Java then
9851 ("pragma% requires function returning a " &
9852 "'Java access type", Arg1);
9854 pragma Assert (Convention = Convention_CIL);
9856 ("pragma% requires function returning a " &
9857 "'C'I'L access type", Arg1);
9861 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9862 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9863 E_General_Access_Type)
9866 (Designated_Type (Etype (Def_Id))) /= Convention
9868 Error_Msg_Name_1 := Pname;
9870 if Convention = Convention_Java then
9872 ("pragma% requires function returning a named" &
9873 "'Java access type", Arg1);
9876 ("pragma% requires function returning a named" &
9877 "'C'I'L access type", Arg1);
9882 Set_Is_Constructor (Def_Id);
9883 Set_Convention (Def_Id, Convention);
9884 Set_Is_Imported (Def_Id);
9886 exit when From_Aspect_Specification (N);
9887 Hom_Id := Homonym (Hom_Id);
9889 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9891 end Java_Constructor;
9893 ----------------------
9894 -- Java_Interface --
9895 ----------------------
9897 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9899 when Pragma_Java_Interface => Java_Interface : declare
9905 Check_Arg_Count (1);
9906 Check_Optional_Identifier (Arg1, Name_Entity);
9907 Check_Arg_Is_Local_Name (Arg1);
9909 Arg := Get_Pragma_Arg (Arg1);
9912 if Etype (Arg) = Any_Type then
9916 if not Is_Entity_Name (Arg)
9917 or else not Is_Type (Entity (Arg))
9919 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9922 Typ := Underlying_Type (Entity (Arg));
9924 -- For now simply check some of the semantic constraints on the
9925 -- type. This currently leaves out some restrictions on interface
9926 -- types, namely that the parent type must be java.lang.Object.Typ
9927 -- and that all primitives of the type should be declared
9930 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9931 Error_Pragma_Arg ("pragma% requires an abstract "
9932 & "tagged type", Arg1);
9934 elsif not Has_Discriminants (Typ)
9935 or else Ekind (Etype (First_Discriminant (Typ)))
9936 /= E_Anonymous_Access_Type
9938 not Is_Class_Wide_Type
9939 (Designated_Type (Etype (First_Discriminant (Typ))))
9942 ("type must have a class-wide access discriminant", Arg1);
9950 -- pragma Keep_Names ([On => ] local_NAME);
9952 when Pragma_Keep_Names => Keep_Names : declare
9957 Check_Arg_Count (1);
9958 Check_Optional_Identifier (Arg1, Name_On);
9959 Check_Arg_Is_Local_Name (Arg1);
9961 Arg := Get_Pragma_Arg (Arg1);
9964 if Etype (Arg) = Any_Type then
9968 if not Is_Entity_Name (Arg)
9969 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
9972 ("pragma% requires a local enumeration type", Arg1);
9975 Set_Discard_Names (Entity (Arg), False);
9982 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
9984 when Pragma_License =>
9986 Check_Arg_Count (1);
9987 Check_No_Identifiers;
9988 Check_Valid_Configuration_Pragma;
9989 Check_Arg_Is_Identifier (Arg1);
9992 Sind : constant Source_File_Index :=
9993 Source_Index (Current_Sem_Unit);
9996 case Chars (Get_Pragma_Arg (Arg1)) is
9998 Set_License (Sind, GPL);
10000 when Name_Modified_GPL =>
10001 Set_License (Sind, Modified_GPL);
10003 when Name_Restricted =>
10004 Set_License (Sind, Restricted);
10006 when Name_Unrestricted =>
10007 Set_License (Sind, Unrestricted);
10010 Error_Pragma_Arg ("invalid license name", Arg1);
10018 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10020 when Pragma_Link_With => Link_With : declare
10026 if Operating_Mode = Generate_Code
10027 and then In_Extended_Main_Source_Unit (N)
10029 Check_At_Least_N_Arguments (1);
10030 Check_No_Identifiers;
10031 Check_Is_In_Decl_Part_Or_Package_Spec;
10032 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10036 while Present (Arg) loop
10037 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10039 -- Store argument, converting sequences of spaces to a
10040 -- single null character (this is one of the differences
10041 -- in processing between Link_With and Linker_Options).
10043 Arg_Store : declare
10044 C : constant Char_Code := Get_Char_Code (' ');
10045 S : constant String_Id :=
10046 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10047 L : constant Nat := String_Length (S);
10050 procedure Skip_Spaces;
10051 -- Advance F past any spaces
10057 procedure Skip_Spaces is
10059 while F <= L and then Get_String_Char (S, F) = C loop
10064 -- Start of processing for Arg_Store
10067 Skip_Spaces; -- skip leading spaces
10069 -- Loop through characters, changing any embedded
10070 -- sequence of spaces to a single null character (this
10071 -- is how Link_With/Linker_Options differ)
10074 if Get_String_Char (S, F) = C then
10077 Store_String_Char (ASCII.NUL);
10080 Store_String_Char (Get_String_Char (S, F));
10088 if Present (Arg) then
10089 Store_String_Char (ASCII.NUL);
10093 Store_Linker_Option_String (End_String);
10101 -- pragma Linker_Alias (
10102 -- [Entity =>] LOCAL_NAME
10103 -- [Target =>] static_string_EXPRESSION);
10105 when Pragma_Linker_Alias =>
10107 Check_Arg_Order ((Name_Entity, Name_Target));
10108 Check_Arg_Count (2);
10109 Check_Optional_Identifier (Arg1, Name_Entity);
10110 Check_Optional_Identifier (Arg2, Name_Target);
10111 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10112 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10114 -- The only processing required is to link this item on to the
10115 -- list of rep items for the given entity. This is accomplished
10116 -- by the call to Rep_Item_Too_Late (when no error is detected
10117 -- and False is returned).
10119 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10122 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10125 ------------------------
10126 -- Linker_Constructor --
10127 ------------------------
10129 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10131 -- Code is shared with Linker_Destructor
10133 -----------------------
10134 -- Linker_Destructor --
10135 -----------------------
10137 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10139 when Pragma_Linker_Constructor |
10140 Pragma_Linker_Destructor =>
10141 Linker_Constructor : declare
10147 Check_Arg_Count (1);
10148 Check_No_Identifiers;
10149 Check_Arg_Is_Local_Name (Arg1);
10150 Arg1_X := Get_Pragma_Arg (Arg1);
10152 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10154 if not Is_Library_Level_Entity (Proc) then
10156 ("argument for pragma% must be library level entity", Arg1);
10159 -- The only processing required is to link this item on to the
10160 -- list of rep items for the given entity. This is accomplished
10161 -- by the call to Rep_Item_Too_Late (when no error is detected
10162 -- and False is returned).
10164 if Rep_Item_Too_Late (Proc, N) then
10167 Set_Has_Gigi_Rep_Item (Proc);
10169 end Linker_Constructor;
10171 --------------------
10172 -- Linker_Options --
10173 --------------------
10175 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10177 when Pragma_Linker_Options => Linker_Options : declare
10181 Check_Ada_83_Warning;
10182 Check_No_Identifiers;
10183 Check_Arg_Count (1);
10184 Check_Is_In_Decl_Part_Or_Package_Spec;
10185 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10186 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10189 while Present (Arg) loop
10190 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10191 Store_String_Char (ASCII.NUL);
10193 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10197 if Operating_Mode = Generate_Code
10198 and then In_Extended_Main_Source_Unit (N)
10200 Store_Linker_Option_String (End_String);
10202 end Linker_Options;
10204 --------------------
10205 -- Linker_Section --
10206 --------------------
10208 -- pragma Linker_Section (
10209 -- [Entity =>] LOCAL_NAME
10210 -- [Section =>] static_string_EXPRESSION);
10212 when Pragma_Linker_Section =>
10214 Check_Arg_Order ((Name_Entity, Name_Section));
10215 Check_Arg_Count (2);
10216 Check_Optional_Identifier (Arg1, Name_Entity);
10217 Check_Optional_Identifier (Arg2, Name_Section);
10218 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10219 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10221 -- This pragma applies only to objects
10223 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10224 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10227 -- The only processing required is to link this item on to the
10228 -- list of rep items for the given entity. This is accomplished
10229 -- by the call to Rep_Item_Too_Late (when no error is detected
10230 -- and False is returned).
10232 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10235 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10242 -- pragma List (On | Off)
10244 -- There is nothing to do here, since we did all the processing for
10245 -- this pragma in Par.Prag (so that it works properly even in syntax
10248 when Pragma_List =>
10251 --------------------
10252 -- Locking_Policy --
10253 --------------------
10255 -- pragma Locking_Policy (policy_IDENTIFIER);
10257 when Pragma_Locking_Policy => declare
10261 Check_Ada_83_Warning;
10262 Check_Arg_Count (1);
10263 Check_No_Identifiers;
10264 Check_Arg_Is_Locking_Policy (Arg1);
10265 Check_Valid_Configuration_Pragma;
10266 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10267 LP := Fold_Upper (Name_Buffer (1));
10269 if Locking_Policy /= ' '
10270 and then Locking_Policy /= LP
10272 Error_Msg_Sloc := Locking_Policy_Sloc;
10273 Error_Pragma ("locking policy incompatible with policy#");
10275 -- Set new policy, but always preserve System_Location since we
10276 -- like the error message with the run time name.
10279 Locking_Policy := LP;
10281 if Locking_Policy_Sloc /= System_Location then
10282 Locking_Policy_Sloc := Loc;
10291 -- pragma Long_Float (D_Float | G_Float);
10293 when Pragma_Long_Float =>
10295 Check_Valid_Configuration_Pragma;
10296 Check_Arg_Count (1);
10297 Check_No_Identifier (Arg1);
10298 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10300 if not OpenVMS_On_Target then
10301 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10306 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10307 if Opt.Float_Format_Long = 'G' then
10308 Error_Pragma ("G_Float previously specified");
10311 Opt.Float_Format_Long := 'D';
10313 -- G_Float case (this is the default, does not need overriding)
10316 if Opt.Float_Format_Long = 'D' then
10317 Error_Pragma ("D_Float previously specified");
10320 Opt.Float_Format_Long := 'G';
10323 Set_Standard_Fpt_Formats;
10325 -----------------------
10326 -- Machine_Attribute --
10327 -----------------------
10329 -- pragma Machine_Attribute (
10330 -- [Entity =>] LOCAL_NAME,
10331 -- [Attribute_Name =>] static_string_EXPRESSION
10332 -- [, [Info =>] static_EXPRESSION] );
10334 when Pragma_Machine_Attribute => Machine_Attribute : declare
10335 Def_Id : Entity_Id;
10339 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10341 if Arg_Count = 3 then
10342 Check_Optional_Identifier (Arg3, Name_Info);
10343 Check_Arg_Is_Static_Expression (Arg3);
10345 Check_Arg_Count (2);
10348 Check_Optional_Identifier (Arg1, Name_Entity);
10349 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10350 Check_Arg_Is_Local_Name (Arg1);
10351 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10352 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10354 if Is_Access_Type (Def_Id) then
10355 Def_Id := Designated_Type (Def_Id);
10358 if Rep_Item_Too_Early (Def_Id, N) then
10362 Def_Id := Underlying_Type (Def_Id);
10364 -- The only processing required is to link this item on to the
10365 -- list of rep items for the given entity. This is accomplished
10366 -- by the call to Rep_Item_Too_Late (when no error is detected
10367 -- and False is returned).
10369 if Rep_Item_Too_Late (Def_Id, N) then
10372 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10374 end Machine_Attribute;
10381 -- (MAIN_OPTION [, MAIN_OPTION]);
10384 -- [STACK_SIZE =>] static_integer_EXPRESSION
10385 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10386 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10388 when Pragma_Main => Main : declare
10389 Args : Args_List (1 .. 3);
10390 Names : constant Name_List (1 .. 3) := (
10392 Name_Task_Stack_Size_Default,
10393 Name_Time_Slicing_Enabled);
10399 Gather_Associations (Names, Args);
10401 for J in 1 .. 2 loop
10402 if Present (Args (J)) then
10403 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10407 if Present (Args (3)) then
10408 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10412 while Present (Nod) loop
10413 if Nkind (Nod) = N_Pragma
10414 and then Pragma_Name (Nod) = Name_Main
10416 Error_Msg_Name_1 := Pname;
10417 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10428 -- pragma Main_Storage
10429 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10431 -- MAIN_STORAGE_OPTION ::=
10432 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10433 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10435 when Pragma_Main_Storage => Main_Storage : declare
10436 Args : Args_List (1 .. 2);
10437 Names : constant Name_List (1 .. 2) := (
10438 Name_Working_Storage,
10445 Gather_Associations (Names, Args);
10447 for J in 1 .. 2 loop
10448 if Present (Args (J)) then
10449 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10453 Check_In_Main_Program;
10456 while Present (Nod) loop
10457 if Nkind (Nod) = N_Pragma
10458 and then Pragma_Name (Nod) = Name_Main_Storage
10460 Error_Msg_Name_1 := Pname;
10461 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10472 -- pragma Memory_Size (NUMERIC_LITERAL)
10474 when Pragma_Memory_Size =>
10477 -- Memory size is simply ignored
10479 Check_No_Identifiers;
10480 Check_Arg_Count (1);
10481 Check_Arg_Is_Integer_Literal (Arg1);
10489 -- The only correct use of this pragma is on its own in a file, in
10490 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10491 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10492 -- check for a file containing nothing but a No_Body pragma). If we
10493 -- attempt to process it during normal semantics processing, it means
10494 -- it was misplaced.
10496 when Pragma_No_Body =>
10504 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10506 when Pragma_No_Return => No_Return : declare
10514 Check_At_Least_N_Arguments (1);
10516 -- Loop through arguments of pragma
10519 while Present (Arg) loop
10520 Check_Arg_Is_Local_Name (Arg);
10521 Id := Get_Pragma_Arg (Arg);
10524 if not Is_Entity_Name (Id) then
10525 Error_Pragma_Arg ("entity name required", Arg);
10528 if Etype (Id) = Any_Type then
10532 -- Loop to find matching procedures
10537 and then Scope (E) = Current_Scope
10539 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10542 -- Set flag on any alias as well
10544 if Is_Overloadable (E) and then Present (Alias (E)) then
10545 Set_No_Return (Alias (E));
10551 exit when From_Aspect_Specification (N);
10556 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10567 -- pragma No_Run_Time;
10569 -- Note: this pragma is retained for backwards compatibility. See
10570 -- body of Rtsfind for full details on its handling.
10572 when Pragma_No_Run_Time =>
10574 Check_Valid_Configuration_Pragma;
10575 Check_Arg_Count (0);
10577 No_Run_Time_Mode := True;
10578 Configurable_Run_Time_Mode := True;
10580 -- Set Duration to 32 bits if word size is 32
10582 if Ttypes.System_Word_Size = 32 then
10583 Duration_32_Bits_On_Target := True;
10586 -- Set appropriate restrictions
10588 Set_Restriction (No_Finalization, N);
10589 Set_Restriction (No_Exception_Handlers, N);
10590 Set_Restriction (Max_Tasks, N, 0);
10591 Set_Restriction (No_Tasking, N);
10593 ------------------------
10594 -- No_Strict_Aliasing --
10595 ------------------------
10597 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10599 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10604 Check_At_Most_N_Arguments (1);
10606 if Arg_Count = 0 then
10607 Check_Valid_Configuration_Pragma;
10608 Opt.No_Strict_Aliasing := True;
10611 Check_Optional_Identifier (Arg2, Name_Entity);
10612 Check_Arg_Is_Local_Name (Arg1);
10613 E_Id := Entity (Get_Pragma_Arg (Arg1));
10615 if E_Id = Any_Type then
10617 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10618 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10621 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10623 end No_Strict_Aliasing;
10625 -----------------------
10626 -- Normalize_Scalars --
10627 -----------------------
10629 -- pragma Normalize_Scalars;
10631 when Pragma_Normalize_Scalars =>
10632 Check_Ada_83_Warning;
10633 Check_Arg_Count (0);
10634 Check_Valid_Configuration_Pragma;
10636 -- Normalize_Scalars creates false positives in CodePeer, so
10637 -- ignore this pragma in this mode.
10639 if not CodePeer_Mode then
10640 Normalize_Scalars := True;
10641 Init_Or_Norm_Scalars := True;
10648 -- pragma Obsolescent;
10650 -- pragma Obsolescent (
10651 -- [Message =>] static_string_EXPRESSION
10652 -- [,[Version =>] Ada_05]]);
10654 -- pragma Obsolescent (
10655 -- [Entity =>] NAME
10656 -- [,[Message =>] static_string_EXPRESSION
10657 -- [,[Version =>] Ada_05]] );
10659 when Pragma_Obsolescent => Obsolescent : declare
10663 procedure Set_Obsolescent (E : Entity_Id);
10664 -- Given an entity Ent, mark it as obsolescent if appropriate
10666 ---------------------
10667 -- Set_Obsolescent --
10668 ---------------------
10670 procedure Set_Obsolescent (E : Entity_Id) is
10679 -- Entity name was given
10681 if Present (Ename) then
10683 -- If entity name matches, we are fine. Save entity in
10684 -- pragma argument, for ASIS use.
10686 if Chars (Ename) = Chars (Ent) then
10687 Set_Entity (Ename, Ent);
10688 Generate_Reference (Ent, Ename);
10690 -- If entity name does not match, only possibility is an
10691 -- enumeration literal from an enumeration type declaration.
10693 elsif Ekind (Ent) /= E_Enumeration_Type then
10695 ("pragma % entity name does not match declaration");
10698 Ent := First_Literal (E);
10702 ("pragma % entity name does not match any " &
10703 "enumeration literal");
10705 elsif Chars (Ent) = Chars (Ename) then
10706 Set_Entity (Ename, Ent);
10707 Generate_Reference (Ent, Ename);
10711 Ent := Next_Literal (Ent);
10717 -- Ent points to entity to be marked
10719 if Arg_Count >= 1 then
10721 -- Deal with static string argument
10723 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10724 S := Strval (Get_Pragma_Arg (Arg1));
10726 for J in 1 .. String_Length (S) loop
10727 if not In_Character_Range (Get_String_Char (S, J)) then
10729 ("pragma% argument does not allow wide characters",
10734 Obsolescent_Warnings.Append
10735 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10737 -- Check for Ada_05 parameter
10739 if Arg_Count /= 1 then
10740 Check_Arg_Count (2);
10743 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10746 Check_Arg_Is_Identifier (Argx);
10748 if Chars (Argx) /= Name_Ada_05 then
10749 Error_Msg_Name_2 := Name_Ada_05;
10751 ("only allowed argument for pragma% is %", Argx);
10754 if Ada_Version_Explicit < Ada_2005
10755 or else not Warn_On_Ada_2005_Compatibility
10763 -- Set flag if pragma active
10766 Set_Is_Obsolescent (Ent);
10770 end Set_Obsolescent;
10772 -- Start of processing for pragma Obsolescent
10777 Check_At_Most_N_Arguments (3);
10779 -- See if first argument specifies an entity name
10783 (Chars (Arg1) = Name_Entity
10785 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10787 N_Operator_Symbol))
10789 Ename := Get_Pragma_Arg (Arg1);
10791 -- Eliminate first argument, so we can share processing
10795 Arg_Count := Arg_Count - 1;
10797 -- No Entity name argument given
10803 if Arg_Count >= 1 then
10804 Check_Optional_Identifier (Arg1, Name_Message);
10806 if Arg_Count = 2 then
10807 Check_Optional_Identifier (Arg2, Name_Version);
10811 -- Get immediately preceding declaration
10814 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10818 -- Cases where we do not follow anything other than another pragma
10822 -- First case: library level compilation unit declaration with
10823 -- the pragma immediately following the declaration.
10825 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10827 (Defining_Entity (Unit (Parent (Parent (N)))));
10830 -- Case 2: library unit placement for package
10834 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10836 if Is_Package_Or_Generic_Package (Ent) then
10837 Set_Obsolescent (Ent);
10843 -- Cases where we must follow a declaration
10846 if Nkind (Decl) not in N_Declaration
10847 and then Nkind (Decl) not in N_Later_Decl_Item
10848 and then Nkind (Decl) not in N_Generic_Declaration
10849 and then Nkind (Decl) not in N_Renaming_Declaration
10852 ("pragma% misplaced, "
10853 & "must immediately follow a declaration");
10856 Set_Obsolescent (Defining_Entity (Decl));
10866 -- pragma Optimize (Time | Space | Off);
10868 -- The actual check for optimize is done in Gigi. Note that this
10869 -- pragma does not actually change the optimization setting, it
10870 -- simply checks that it is consistent with the pragma.
10872 when Pragma_Optimize =>
10873 Check_No_Identifiers;
10874 Check_Arg_Count (1);
10875 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10877 ------------------------
10878 -- Optimize_Alignment --
10879 ------------------------
10881 -- pragma Optimize_Alignment (Time | Space | Off);
10883 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10885 Check_No_Identifiers;
10886 Check_Arg_Count (1);
10887 Check_Valid_Configuration_Pragma;
10890 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10894 Opt.Optimize_Alignment := 'T';
10896 Opt.Optimize_Alignment := 'S';
10898 Opt.Optimize_Alignment := 'O';
10900 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10904 -- Set indication that mode is set locally. If we are in fact in a
10905 -- configuration pragma file, this setting is harmless since the
10906 -- switch will get reset anyway at the start of each unit.
10908 Optimize_Alignment_Local := True;
10909 end Optimize_Alignment;
10915 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10917 when Pragma_Ordered => Ordered : declare
10918 Assoc : constant Node_Id := Arg1;
10924 Check_No_Identifiers;
10925 Check_Arg_Count (1);
10926 Check_Arg_Is_Local_Name (Arg1);
10928 Type_Id := Get_Pragma_Arg (Assoc);
10929 Find_Type (Type_Id);
10930 Typ := Entity (Type_Id);
10932 if Typ = Any_Type then
10935 Typ := Underlying_Type (Typ);
10938 if not Is_Enumeration_Type (Typ) then
10939 Error_Pragma ("pragma% must specify enumeration type");
10942 Check_First_Subtype (Arg1);
10943 Set_Has_Pragma_Ordered (Base_Type (Typ));
10950 -- pragma Pack (first_subtype_LOCAL_NAME);
10952 when Pragma_Pack => Pack : declare
10953 Assoc : constant Node_Id := Arg1;
10957 Ignore : Boolean := False;
10960 Check_No_Identifiers;
10961 Check_Arg_Count (1);
10962 Check_Arg_Is_Local_Name (Arg1);
10964 Type_Id := Get_Pragma_Arg (Assoc);
10965 Find_Type (Type_Id);
10966 Typ := Entity (Type_Id);
10969 or else Rep_Item_Too_Early (Typ, N)
10973 Typ := Underlying_Type (Typ);
10976 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
10977 Error_Pragma ("pragma% must specify array or record type");
10980 Check_First_Subtype (Arg1);
10981 Check_Duplicate_Pragma (Typ);
10985 if Is_Array_Type (Typ) then
10986 Ctyp := Component_Type (Typ);
10988 -- Ignore pack that does nothing
10990 if Known_Static_Esize (Ctyp)
10991 and then Known_Static_RM_Size (Ctyp)
10992 and then Esize (Ctyp) = RM_Size (Ctyp)
10993 and then Addressable (Esize (Ctyp))
10998 -- Process OK pragma Pack. Note that if there is a separate
10999 -- component clause present, the Pack will be cancelled. This
11000 -- processing is in Freeze.
11002 if not Rep_Item_Too_Late (Typ, N) then
11004 -- In the context of static code analysis, we do not need
11005 -- complex front-end expansions related to pragma Pack,
11006 -- so disable handling of pragma Pack in this case.
11008 if CodePeer_Mode then
11011 -- Don't attempt any packing for VM targets. We possibly
11012 -- could deal with some cases of array bit-packing, but we
11013 -- don't bother, since this is not a typical kind of
11014 -- representation in the VM context anyway (and would not
11015 -- for example work nicely with the debugger).
11017 elsif VM_Target /= No_VM then
11018 if not GNAT_Mode then
11020 ("?pragma% ignored in this configuration");
11023 -- Normal case where we do the pack action
11027 Set_Is_Packed (Base_Type (Typ));
11028 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11031 Set_Has_Pragma_Pack (Base_Type (Typ));
11035 -- For record types, the pack is always effective
11037 else pragma Assert (Is_Record_Type (Typ));
11038 if not Rep_Item_Too_Late (Typ, N) then
11040 -- Ignore pack request with warning in VM mode (skip warning
11041 -- if we are compiling GNAT run time library).
11043 if VM_Target /= No_VM then
11044 if not GNAT_Mode then
11046 ("?pragma% ignored in this configuration");
11049 -- Normal case of pack request active
11052 Set_Is_Packed (Base_Type (Typ));
11053 Set_Has_Pragma_Pack (Base_Type (Typ));
11054 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11066 -- There is nothing to do here, since we did all the processing for
11067 -- this pragma in Par.Prag (so that it works properly even in syntax
11070 when Pragma_Page =>
11077 -- pragma Passive [(PASSIVE_FORM)];
11079 -- PASSIVE_FORM ::= Semaphore | No
11081 when Pragma_Passive =>
11084 if Nkind (Parent (N)) /= N_Task_Definition then
11085 Error_Pragma ("pragma% must be within task definition");
11088 if Arg_Count /= 0 then
11089 Check_Arg_Count (1);
11090 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11093 ----------------------------------
11094 -- Preelaborable_Initialization --
11095 ----------------------------------
11097 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11099 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11104 Check_Arg_Count (1);
11105 Check_No_Identifiers;
11106 Check_Arg_Is_Identifier (Arg1);
11107 Check_Arg_Is_Local_Name (Arg1);
11108 Check_First_Subtype (Arg1);
11109 Ent := Entity (Get_Pragma_Arg (Arg1));
11111 if not (Is_Private_Type (Ent)
11113 Is_Protected_Type (Ent)
11115 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11118 ("pragma % can only be applied to private, formal derived or "
11119 & "protected type",
11123 -- Give an error if the pragma is applied to a protected type that
11124 -- does not qualify (due to having entries, or due to components
11125 -- that do not qualify).
11127 if Is_Protected_Type (Ent)
11128 and then not Has_Preelaborable_Initialization (Ent)
11131 ("protected type & does not have preelaborable " &
11132 "initialization", Ent);
11134 -- Otherwise mark the type as definitely having preelaborable
11138 Set_Known_To_Have_Preelab_Init (Ent);
11141 if Has_Pragma_Preelab_Init (Ent)
11142 and then Warn_On_Redundant_Constructs
11144 Error_Pragma ("?duplicate pragma%!");
11146 Set_Has_Pragma_Preelab_Init (Ent);
11150 --------------------
11151 -- Persistent_BSS --
11152 --------------------
11154 -- pragma Persistent_BSS [(object_NAME)];
11156 when Pragma_Persistent_BSS => Persistent_BSS : declare
11163 Check_At_Most_N_Arguments (1);
11165 -- Case of application to specific object (one argument)
11167 if Arg_Count = 1 then
11168 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11170 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11172 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11175 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11178 Ent := Entity (Get_Pragma_Arg (Arg1));
11179 Decl := Parent (Ent);
11181 if Rep_Item_Too_Late (Ent, N) then
11185 if Present (Expression (Decl)) then
11187 ("object for pragma% cannot have initialization", Arg1);
11190 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11192 ("object type for pragma% is not potentially persistent",
11196 Check_Duplicate_Pragma (Ent);
11199 Make_Linker_Section_Pragma
11200 (Ent, Sloc (N), ".persistent.bss");
11201 Insert_After (N, Prag);
11204 -- Case of use as configuration pragma with no arguments
11207 Check_Valid_Configuration_Pragma;
11208 Persistent_BSS_Mode := True;
11210 end Persistent_BSS;
11216 -- pragma Polling (ON | OFF);
11218 when Pragma_Polling =>
11220 Check_Arg_Count (1);
11221 Check_No_Identifiers;
11222 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11223 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11225 -------------------
11226 -- Postcondition --
11227 -------------------
11229 -- pragma Postcondition ([Check =>] Boolean_Expression
11230 -- [,[Message =>] String_Expression]);
11232 when Pragma_Postcondition => Postcondition : declare
11234 pragma Warnings (Off, In_Body);
11238 Check_At_Least_N_Arguments (1);
11239 Check_At_Most_N_Arguments (2);
11240 Check_Optional_Identifier (Arg1, Name_Check);
11242 -- All we need to do here is call the common check procedure,
11243 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11245 Check_Precondition_Postcondition (In_Body);
11252 -- pragma Precondition ([Check =>] Boolean_Expression
11253 -- [,[Message =>] String_Expression]);
11255 when Pragma_Precondition => Precondition : declare
11260 Check_At_Least_N_Arguments (1);
11261 Check_At_Most_N_Arguments (2);
11262 Check_Optional_Identifier (Arg1, Name_Check);
11263 Check_Precondition_Postcondition (In_Body);
11265 -- If in spec, nothing more to do. If in body, then we convert the
11266 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11267 -- this whether or not precondition checks are enabled. That works
11268 -- fine since pragma Check will do this check, and will also
11269 -- analyze the condition itself in the proper context.
11274 Chars => Name_Check,
11275 Pragma_Argument_Associations => New_List (
11276 Make_Pragma_Argument_Association (Loc,
11277 Expression => Make_Identifier (Loc, Name_Precondition)),
11279 Make_Pragma_Argument_Association (Sloc (Arg1),
11280 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11282 if Arg_Count = 2 then
11283 Append_To (Pragma_Argument_Associations (N),
11284 Make_Pragma_Argument_Association (Sloc (Arg2),
11285 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11296 -- pragma Predicate
11297 -- ([Entity =>] type_LOCAL_NAME,
11298 -- [Check =>] EXPRESSION);
11300 when Pragma_Predicate => Predicate : declare
11305 pragma Unreferenced (Discard);
11309 Check_Arg_Count (2);
11310 Check_Optional_Identifier (Arg1, Name_Entity);
11311 Check_Optional_Identifier (Arg2, Name_Check);
11313 Check_Arg_Is_Local_Name (Arg1);
11315 Type_Id := Get_Pragma_Arg (Arg1);
11316 Find_Type (Type_Id);
11317 Typ := Entity (Type_Id);
11319 if Typ = Any_Type then
11323 -- The remaining processing is simply to link the pragma on to
11324 -- the rep item chain, for processing when the type is frozen.
11325 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11326 -- mark the type as having predicates.
11328 Set_Has_Predicates (Typ);
11329 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11336 -- pragma Preelaborate [(library_unit_NAME)];
11338 -- Set the flag Is_Preelaborated of program unit name entity
11340 when Pragma_Preelaborate => Preelaborate : declare
11341 Pa : constant Node_Id := Parent (N);
11342 Pk : constant Node_Kind := Nkind (Pa);
11346 Check_Ada_83_Warning;
11347 Check_Valid_Library_Unit_Pragma;
11349 if Nkind (N) = N_Null_Statement then
11353 Ent := Find_Lib_Unit_Name;
11354 Check_Duplicate_Pragma (Ent);
11356 -- This filters out pragmas inside generic parent then
11357 -- show up inside instantiation
11360 and then not (Pk = N_Package_Specification
11361 and then Present (Generic_Parent (Pa)))
11363 if not Debug_Flag_U then
11364 Set_Is_Preelaborated (Ent);
11365 Set_Suppress_Elaboration_Warnings (Ent);
11370 ---------------------
11371 -- Preelaborate_05 --
11372 ---------------------
11374 -- pragma Preelaborate_05 [(library_unit_NAME)];
11376 -- This pragma is useable only in GNAT_Mode, where it is used like
11377 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11378 -- (otherwise it is ignored). This is used to implement AI-362 which
11379 -- recategorizes some run-time packages in Ada 2005 mode.
11381 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11386 Check_Valid_Library_Unit_Pragma;
11388 if not GNAT_Mode then
11389 Error_Pragma ("pragma% only available in GNAT mode");
11392 if Nkind (N) = N_Null_Statement then
11396 -- This is one of the few cases where we need to test the value of
11397 -- Ada_Version_Explicit rather than Ada_Version (which is always
11398 -- set to Ada_2012 in a predefined unit), we need to know the
11399 -- explicit version set to know if this pragma is active.
11401 if Ada_Version_Explicit >= Ada_2005 then
11402 Ent := Find_Lib_Unit_Name;
11403 Set_Is_Preelaborated (Ent);
11404 Set_Suppress_Elaboration_Warnings (Ent);
11406 end Preelaborate_05;
11412 -- pragma Priority (EXPRESSION);
11414 when Pragma_Priority => Priority : declare
11415 P : constant Node_Id := Parent (N);
11419 Check_No_Identifiers;
11420 Check_Arg_Count (1);
11424 if Nkind (P) = N_Subprogram_Body then
11425 Check_In_Main_Program;
11427 Arg := Get_Pragma_Arg (Arg1);
11428 Analyze_And_Resolve (Arg, Standard_Integer);
11432 if not Is_Static_Expression (Arg) then
11433 Flag_Non_Static_Expr
11434 ("main subprogram priority is not static!", Arg);
11437 -- If constraint error, then we already signalled an error
11439 elsif Raises_Constraint_Error (Arg) then
11442 -- Otherwise check in range
11446 Val : constant Uint := Expr_Value (Arg);
11450 or else Val > Expr_Value (Expression
11451 (Parent (RTE (RE_Max_Priority))))
11454 ("main subprogram priority is out of range", Arg1);
11460 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11462 -- Load an arbitrary entity from System.Tasking to make sure
11463 -- this package is implicitly with'ed, since we need to have
11464 -- the tasking run-time active for the pragma Priority to have
11468 Discard : Entity_Id;
11469 pragma Warnings (Off, Discard);
11471 Discard := RTE (RE_Task_List);
11474 -- Task or Protected, must be of type Integer
11476 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11477 Arg := Get_Pragma_Arg (Arg1);
11479 -- The expression must be analyzed in the special manner
11480 -- described in "Handling of Default and Per-Object
11481 -- Expressions" in sem.ads.
11483 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11485 if not Is_Static_Expression (Arg) then
11486 Check_Restriction (Static_Priorities, Arg);
11489 -- Anything else is incorrect
11495 if Has_Pragma_Priority (P) then
11496 Error_Pragma ("duplicate pragma% not allowed");
11498 Set_Has_Pragma_Priority (P, True);
11500 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11501 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11502 -- exp_ch9 should use this ???
11507 -----------------------------------
11508 -- Priority_Specific_Dispatching --
11509 -----------------------------------
11511 -- pragma Priority_Specific_Dispatching (
11512 -- policy_IDENTIFIER,
11513 -- first_priority_EXPRESSION,
11514 -- last_priority_EXPRESSION);
11516 when Pragma_Priority_Specific_Dispatching =>
11517 Priority_Specific_Dispatching : declare
11518 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11519 -- This is the entity System.Any_Priority;
11522 Lower_Bound : Node_Id;
11523 Upper_Bound : Node_Id;
11529 Check_Arg_Count (3);
11530 Check_No_Identifiers;
11531 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11532 Check_Valid_Configuration_Pragma;
11533 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11534 DP := Fold_Upper (Name_Buffer (1));
11536 Lower_Bound := Get_Pragma_Arg (Arg2);
11537 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11538 Lower_Val := Expr_Value (Lower_Bound);
11540 Upper_Bound := Get_Pragma_Arg (Arg3);
11541 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11542 Upper_Val := Expr_Value (Upper_Bound);
11544 -- It is not allowed to use Task_Dispatching_Policy and
11545 -- Priority_Specific_Dispatching in the same partition.
11547 if Task_Dispatching_Policy /= ' ' then
11548 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11550 ("pragma% incompatible with Task_Dispatching_Policy#");
11552 -- Check lower bound in range
11554 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11556 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11559 ("first_priority is out of range", Arg2);
11561 -- Check upper bound in range
11563 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11565 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11568 ("last_priority is out of range", Arg3);
11570 -- Check that the priority range is valid
11572 elsif Lower_Val > Upper_Val then
11574 ("last_priority_expression must be greater than" &
11575 " or equal to first_priority_expression");
11577 -- Store the new policy, but always preserve System_Location since
11578 -- we like the error message with the run-time name.
11581 -- Check overlapping in the priority ranges specified in other
11582 -- Priority_Specific_Dispatching pragmas within the same
11583 -- partition. We can only check those we know about!
11586 Specific_Dispatching.First .. Specific_Dispatching.Last
11588 if Specific_Dispatching.Table (J).First_Priority in
11589 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11590 or else Specific_Dispatching.Table (J).Last_Priority in
11591 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11594 Specific_Dispatching.Table (J).Pragma_Loc;
11596 ("priority range overlaps with "
11597 & "Priority_Specific_Dispatching#");
11601 -- The use of Priority_Specific_Dispatching is incompatible
11602 -- with Task_Dispatching_Policy.
11604 if Task_Dispatching_Policy /= ' ' then
11605 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11607 ("Priority_Specific_Dispatching incompatible "
11608 & "with Task_Dispatching_Policy#");
11611 -- The use of Priority_Specific_Dispatching forces ceiling
11614 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11615 Error_Msg_Sloc := Locking_Policy_Sloc;
11617 ("Priority_Specific_Dispatching incompatible "
11618 & "with Locking_Policy#");
11620 -- Set the Ceiling_Locking policy, but preserve System_Location
11621 -- since we like the error message with the run time name.
11624 Locking_Policy := 'C';
11626 if Locking_Policy_Sloc /= System_Location then
11627 Locking_Policy_Sloc := Loc;
11631 -- Add entry in the table
11633 Specific_Dispatching.Append
11634 ((Dispatching_Policy => DP,
11635 First_Priority => UI_To_Int (Lower_Val),
11636 Last_Priority => UI_To_Int (Upper_Val),
11637 Pragma_Loc => Loc));
11639 end Priority_Specific_Dispatching;
11645 -- pragma Profile (profile_IDENTIFIER);
11647 -- profile_IDENTIFIER => Restricted | Ravenscar
11649 when Pragma_Profile =>
11651 Check_Arg_Count (1);
11652 Check_Valid_Configuration_Pragma;
11653 Check_No_Identifiers;
11656 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11658 if Chars (Argx) = Name_Ravenscar then
11659 Set_Ravenscar_Profile (N);
11660 elsif Chars (Argx) = Name_Restricted then
11661 Set_Profile_Restrictions
11662 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11664 Error_Pragma_Arg ("& is not a valid profile", Argx);
11668 ----------------------
11669 -- Profile_Warnings --
11670 ----------------------
11672 -- pragma Profile_Warnings (profile_IDENTIFIER);
11674 -- profile_IDENTIFIER => Restricted | Ravenscar
11676 when Pragma_Profile_Warnings =>
11678 Check_Arg_Count (1);
11679 Check_Valid_Configuration_Pragma;
11680 Check_No_Identifiers;
11683 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11685 if Chars (Argx) = Name_Ravenscar then
11686 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11687 elsif Chars (Argx) = Name_Restricted then
11688 Set_Profile_Restrictions (Restricted, N, Warn => True);
11690 Error_Pragma_Arg ("& is not a valid profile", Argx);
11694 --------------------------
11695 -- Propagate_Exceptions --
11696 --------------------------
11698 -- pragma Propagate_Exceptions;
11700 -- Note: this pragma is obsolete and has no effect
11702 when Pragma_Propagate_Exceptions =>
11704 Check_Arg_Count (0);
11706 if In_Extended_Main_Source_Unit (N) then
11707 Propagate_Exceptions := True;
11714 -- pragma Psect_Object (
11715 -- [Internal =>] LOCAL_NAME,
11716 -- [, [External =>] EXTERNAL_SYMBOL]
11717 -- [, [Size =>] EXTERNAL_SYMBOL]);
11719 when Pragma_Psect_Object | Pragma_Common_Object =>
11720 Psect_Object : declare
11721 Args : Args_List (1 .. 3);
11722 Names : constant Name_List (1 .. 3) := (
11727 Internal : Node_Id renames Args (1);
11728 External : Node_Id renames Args (2);
11729 Size : Node_Id renames Args (3);
11731 Def_Id : Entity_Id;
11733 procedure Check_Too_Long (Arg : Node_Id);
11734 -- Posts message if the argument is an identifier with more
11735 -- than 31 characters, or a string literal with more than
11736 -- 31 characters, and we are operating under VMS
11738 --------------------
11739 -- Check_Too_Long --
11740 --------------------
11742 procedure Check_Too_Long (Arg : Node_Id) is
11743 X : constant Node_Id := Original_Node (Arg);
11746 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11748 ("inappropriate argument for pragma %", Arg);
11751 if OpenVMS_On_Target then
11752 if (Nkind (X) = N_String_Literal
11753 and then String_Length (Strval (X)) > 31)
11755 (Nkind (X) = N_Identifier
11756 and then Length_Of_Name (Chars (X)) > 31)
11759 ("argument for pragma % is longer than 31 characters",
11763 end Check_Too_Long;
11765 -- Start of processing for Common_Object/Psect_Object
11769 Gather_Associations (Names, Args);
11770 Process_Extended_Import_Export_Internal_Arg (Internal);
11772 Def_Id := Entity (Internal);
11774 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11776 ("pragma% must designate an object", Internal);
11779 Check_Too_Long (Internal);
11781 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11783 ("cannot use pragma% for imported/exported object",
11787 if Is_Concurrent_Type (Etype (Internal)) then
11789 ("cannot specify pragma % for task/protected object",
11793 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11795 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11797 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11800 if Ekind (Def_Id) = E_Constant then
11802 ("cannot specify pragma % for a constant", Internal);
11805 if Is_Record_Type (Etype (Internal)) then
11811 Ent := First_Entity (Etype (Internal));
11812 while Present (Ent) loop
11813 Decl := Declaration_Node (Ent);
11815 if Ekind (Ent) = E_Component
11816 and then Nkind (Decl) = N_Component_Declaration
11817 and then Present (Expression (Decl))
11818 and then Warn_On_Export_Import
11821 ("?object for pragma % has defaults", Internal);
11831 if Present (Size) then
11832 Check_Too_Long (Size);
11835 if Present (External) then
11836 Check_Arg_Is_External_Name (External);
11837 Check_Too_Long (External);
11840 -- If all error tests pass, link pragma on to the rep item chain
11842 Record_Rep_Item (Def_Id, N);
11849 -- pragma Pure [(library_unit_NAME)];
11851 when Pragma_Pure => Pure : declare
11855 Check_Ada_83_Warning;
11856 Check_Valid_Library_Unit_Pragma;
11858 if Nkind (N) = N_Null_Statement then
11862 Ent := Find_Lib_Unit_Name;
11864 Set_Has_Pragma_Pure (Ent);
11865 Set_Suppress_Elaboration_Warnings (Ent);
11872 -- pragma Pure_05 [(library_unit_NAME)];
11874 -- This pragma is useable only in GNAT_Mode, where it is used like
11875 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11876 -- it is ignored). It may be used after a pragma Preelaborate, in
11877 -- which case it overrides the effect of the pragma Preelaborate.
11878 -- This is used to implement AI-362 which recategorizes some run-time
11879 -- packages in Ada 2005 mode.
11881 when Pragma_Pure_05 => Pure_05 : declare
11886 Check_Valid_Library_Unit_Pragma;
11888 if not GNAT_Mode then
11889 Error_Pragma ("pragma% only available in GNAT mode");
11892 if Nkind (N) = N_Null_Statement then
11896 -- This is one of the few cases where we need to test the value of
11897 -- Ada_Version_Explicit rather than Ada_Version (which is always
11898 -- set to Ada_2012 in a predefined unit), we need to know the
11899 -- explicit version set to know if this pragma is active.
11901 if Ada_Version_Explicit >= Ada_2005 then
11902 Ent := Find_Lib_Unit_Name;
11903 Set_Is_Preelaborated (Ent, False);
11905 Set_Suppress_Elaboration_Warnings (Ent);
11909 -------------------
11910 -- Pure_Function --
11911 -------------------
11913 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11915 when Pragma_Pure_Function => Pure_Function : declare
11918 Def_Id : Entity_Id;
11919 Effective : Boolean := False;
11923 Check_Arg_Count (1);
11924 Check_Optional_Identifier (Arg1, Name_Entity);
11925 Check_Arg_Is_Local_Name (Arg1);
11926 E_Id := Get_Pragma_Arg (Arg1);
11928 if Error_Posted (E_Id) then
11932 -- Loop through homonyms (overloadings) of referenced entity
11934 E := Entity (E_Id);
11936 if Present (E) then
11938 Def_Id := Get_Base_Subprogram (E);
11940 if not Ekind_In (Def_Id, E_Function,
11941 E_Generic_Function,
11945 ("pragma% requires a function name", Arg1);
11948 Set_Is_Pure (Def_Id);
11950 if not Has_Pragma_Pure_Function (Def_Id) then
11951 Set_Has_Pragma_Pure_Function (Def_Id);
11955 exit when From_Aspect_Specification (N);
11957 exit when No (E) or else Scope (E) /= Current_Scope;
11961 and then Warn_On_Redundant_Constructs
11964 ("pragma Pure_Function on& is redundant?",
11970 --------------------
11971 -- Queuing_Policy --
11972 --------------------
11974 -- pragma Queuing_Policy (policy_IDENTIFIER);
11976 when Pragma_Queuing_Policy => declare
11980 Check_Ada_83_Warning;
11981 Check_Arg_Count (1);
11982 Check_No_Identifiers;
11983 Check_Arg_Is_Queuing_Policy (Arg1);
11984 Check_Valid_Configuration_Pragma;
11985 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11986 QP := Fold_Upper (Name_Buffer (1));
11988 if Queuing_Policy /= ' '
11989 and then Queuing_Policy /= QP
11991 Error_Msg_Sloc := Queuing_Policy_Sloc;
11992 Error_Pragma ("queuing policy incompatible with policy#");
11994 -- Set new policy, but always preserve System_Location since we
11995 -- like the error message with the run time name.
11998 Queuing_Policy := QP;
12000 if Queuing_Policy_Sloc /= System_Location then
12001 Queuing_Policy_Sloc := Loc;
12006 -----------------------
12007 -- Relative_Deadline --
12008 -----------------------
12010 -- pragma Relative_Deadline (time_span_EXPRESSION);
12012 when Pragma_Relative_Deadline => Relative_Deadline : declare
12013 P : constant Node_Id := Parent (N);
12018 Check_No_Identifiers;
12019 Check_Arg_Count (1);
12021 Arg := Get_Pragma_Arg (Arg1);
12023 -- The expression must be analyzed in the special manner described
12024 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12026 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12030 if Nkind (P) = N_Subprogram_Body then
12031 Check_In_Main_Program;
12035 elsif Nkind (P) = N_Task_Definition then
12038 -- Anything else is incorrect
12044 if Has_Relative_Deadline_Pragma (P) then
12045 Error_Pragma ("duplicate pragma% not allowed");
12047 Set_Has_Relative_Deadline_Pragma (P, True);
12049 if Nkind (P) = N_Task_Definition then
12050 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12053 end Relative_Deadline;
12055 ---------------------------
12056 -- Remote_Call_Interface --
12057 ---------------------------
12059 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12061 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12062 Cunit_Node : Node_Id;
12063 Cunit_Ent : Entity_Id;
12067 Check_Ada_83_Warning;
12068 Check_Valid_Library_Unit_Pragma;
12070 if Nkind (N) = N_Null_Statement then
12074 Cunit_Node := Cunit (Current_Sem_Unit);
12075 K := Nkind (Unit (Cunit_Node));
12076 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12078 if K = N_Package_Declaration
12079 or else K = N_Generic_Package_Declaration
12080 or else K = N_Subprogram_Declaration
12081 or else K = N_Generic_Subprogram_Declaration
12082 or else (K = N_Subprogram_Body
12083 and then Acts_As_Spec (Unit (Cunit_Node)))
12088 "pragma% must apply to package or subprogram declaration");
12091 Set_Is_Remote_Call_Interface (Cunit_Ent);
12092 end Remote_Call_Interface;
12098 -- pragma Remote_Types [(library_unit_NAME)];
12100 when Pragma_Remote_Types => Remote_Types : declare
12101 Cunit_Node : Node_Id;
12102 Cunit_Ent : Entity_Id;
12105 Check_Ada_83_Warning;
12106 Check_Valid_Library_Unit_Pragma;
12108 if Nkind (N) = N_Null_Statement then
12112 Cunit_Node := Cunit (Current_Sem_Unit);
12113 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12115 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12116 N_Generic_Package_Declaration)
12119 ("pragma% can only apply to a package declaration");
12122 Set_Is_Remote_Types (Cunit_Ent);
12129 -- pragma Ravenscar;
12131 when Pragma_Ravenscar =>
12133 Check_Arg_Count (0);
12134 Check_Valid_Configuration_Pragma;
12135 Set_Ravenscar_Profile (N);
12137 if Warn_On_Obsolescent_Feature then
12138 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12139 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12142 -------------------------
12143 -- Restricted_Run_Time --
12144 -------------------------
12146 -- pragma Restricted_Run_Time;
12148 when Pragma_Restricted_Run_Time =>
12150 Check_Arg_Count (0);
12151 Check_Valid_Configuration_Pragma;
12152 Set_Profile_Restrictions
12153 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12155 if Warn_On_Obsolescent_Feature then
12157 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12158 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12165 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12168 -- restriction_IDENTIFIER
12169 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12171 when Pragma_Restrictions =>
12172 Process_Restrictions_Or_Restriction_Warnings
12173 (Warn => Treat_Restrictions_As_Warnings);
12175 --------------------------
12176 -- Restriction_Warnings --
12177 --------------------------
12179 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12182 -- restriction_IDENTIFIER
12183 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12185 when Pragma_Restriction_Warnings =>
12187 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12193 -- pragma Reviewable;
12195 when Pragma_Reviewable =>
12196 Check_Ada_83_Warning;
12197 Check_Arg_Count (0);
12199 -- Call dummy debugging function rv. This is done to assist front
12200 -- end debugging. By placing a Reviewable pragma in the source
12201 -- program, a breakpoint on rv catches this place in the source,
12202 -- allowing convenient stepping to the point of interest.
12206 --------------------------
12207 -- Short_Circuit_And_Or --
12208 --------------------------
12210 when Pragma_Short_Circuit_And_Or =>
12212 Check_Arg_Count (0);
12213 Check_Valid_Configuration_Pragma;
12214 Short_Circuit_And_Or := True;
12216 -------------------
12217 -- Share_Generic --
12218 -------------------
12220 -- pragma Share_Generic (NAME {, NAME});
12222 when Pragma_Share_Generic =>
12224 Process_Generic_List;
12230 -- pragma Shared (LOCAL_NAME);
12232 when Pragma_Shared =>
12234 Process_Atomic_Shared_Volatile;
12236 --------------------
12237 -- Shared_Passive --
12238 --------------------
12240 -- pragma Shared_Passive [(library_unit_NAME)];
12242 -- Set the flag Is_Shared_Passive of program unit name entity
12244 when Pragma_Shared_Passive => Shared_Passive : declare
12245 Cunit_Node : Node_Id;
12246 Cunit_Ent : Entity_Id;
12249 Check_Ada_83_Warning;
12250 Check_Valid_Library_Unit_Pragma;
12252 if Nkind (N) = N_Null_Statement then
12256 Cunit_Node := Cunit (Current_Sem_Unit);
12257 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12259 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12260 N_Generic_Package_Declaration)
12263 ("pragma% can only apply to a package declaration");
12266 Set_Is_Shared_Passive (Cunit_Ent);
12267 end Shared_Passive;
12269 -----------------------
12270 -- Short_Descriptors --
12271 -----------------------
12273 -- pragma Short_Descriptors;
12275 when Pragma_Short_Descriptors =>
12277 Check_Arg_Count (0);
12278 Check_Valid_Configuration_Pragma;
12279 Short_Descriptors := True;
12281 ----------------------
12282 -- Source_File_Name --
12283 ----------------------
12285 -- There are five forms for this pragma:
12287 -- pragma Source_File_Name (
12288 -- [UNIT_NAME =>] unit_NAME,
12289 -- BODY_FILE_NAME => STRING_LITERAL
12290 -- [, [INDEX =>] INTEGER_LITERAL]);
12292 -- pragma Source_File_Name (
12293 -- [UNIT_NAME =>] unit_NAME,
12294 -- SPEC_FILE_NAME => STRING_LITERAL
12295 -- [, [INDEX =>] INTEGER_LITERAL]);
12297 -- pragma Source_File_Name (
12298 -- BODY_FILE_NAME => STRING_LITERAL
12299 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12300 -- [, CASING => CASING_SPEC]);
12302 -- pragma Source_File_Name (
12303 -- SPEC_FILE_NAME => STRING_LITERAL
12304 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12305 -- [, CASING => CASING_SPEC]);
12307 -- pragma Source_File_Name (
12308 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12309 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12310 -- [, CASING => CASING_SPEC]);
12312 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12314 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12315 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12316 -- only be used when no project file is used, while SFNP can only be
12317 -- used when a project file is used.
12319 -- No processing here. Processing was completed during parsing, since
12320 -- we need to have file names set as early as possible. Units are
12321 -- loaded well before semantic processing starts.
12323 -- The only processing we defer to this point is the check for
12324 -- correct placement.
12326 when Pragma_Source_File_Name =>
12328 Check_Valid_Configuration_Pragma;
12330 ------------------------------
12331 -- Source_File_Name_Project --
12332 ------------------------------
12334 -- See Source_File_Name for syntax
12336 -- No processing here. Processing was completed during parsing, since
12337 -- we need to have file names set as early as possible. Units are
12338 -- loaded well before semantic processing starts.
12340 -- The only processing we defer to this point is the check for
12341 -- correct placement.
12343 when Pragma_Source_File_Name_Project =>
12345 Check_Valid_Configuration_Pragma;
12347 -- Check that a pragma Source_File_Name_Project is used only in a
12348 -- configuration pragmas file.
12350 -- Pragmas Source_File_Name_Project should only be generated by
12351 -- the Project Manager in configuration pragmas files.
12353 -- This is really an ugly test. It seems to depend on some
12354 -- accidental and undocumented property. At the very least it
12355 -- needs to be documented, but it would be better to have a
12356 -- clean way of testing if we are in a configuration file???
12358 if Present (Parent (N)) then
12360 ("pragma% can only appear in a configuration pragmas file");
12363 ----------------------
12364 -- Source_Reference --
12365 ----------------------
12367 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12369 -- Nothing to do, all processing completed in Par.Prag, since we need
12370 -- the information for possible parser messages that are output.
12372 when Pragma_Source_Reference =>
12375 --------------------------------
12376 -- Static_Elaboration_Desired --
12377 --------------------------------
12379 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12381 when Pragma_Static_Elaboration_Desired =>
12383 Check_At_Most_N_Arguments (1);
12385 if Is_Compilation_Unit (Current_Scope)
12386 and then Ekind (Current_Scope) = E_Package
12388 Set_Static_Elaboration_Desired (Current_Scope, True);
12390 Error_Pragma ("pragma% must apply to a library-level package");
12397 -- pragma Storage_Size (EXPRESSION);
12399 when Pragma_Storage_Size => Storage_Size : declare
12400 P : constant Node_Id := Parent (N);
12404 Check_No_Identifiers;
12405 Check_Arg_Count (1);
12407 -- The expression must be analyzed in the special manner described
12408 -- in "Handling of Default Expressions" in sem.ads.
12410 Arg := Get_Pragma_Arg (Arg1);
12411 Preanalyze_Spec_Expression (Arg, Any_Integer);
12413 if not Is_Static_Expression (Arg) then
12414 Check_Restriction (Static_Storage_Size, Arg);
12417 if Nkind (P) /= N_Task_Definition then
12422 if Has_Storage_Size_Pragma (P) then
12423 Error_Pragma ("duplicate pragma% not allowed");
12425 Set_Has_Storage_Size_Pragma (P, True);
12428 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12429 -- ??? exp_ch9 should use this!
12437 -- pragma Storage_Unit (NUMERIC_LITERAL);
12439 -- Only permitted argument is System'Storage_Unit value
12441 when Pragma_Storage_Unit =>
12442 Check_No_Identifiers;
12443 Check_Arg_Count (1);
12444 Check_Arg_Is_Integer_Literal (Arg1);
12446 if Intval (Get_Pragma_Arg (Arg1)) /=
12447 UI_From_Int (Ttypes.System_Storage_Unit)
12449 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12451 ("the only allowed argument for pragma% is ^", Arg1);
12454 --------------------
12455 -- Stream_Convert --
12456 --------------------
12458 -- pragma Stream_Convert (
12459 -- [Entity =>] type_LOCAL_NAME,
12460 -- [Read =>] function_NAME,
12461 -- [Write =>] function NAME);
12463 when Pragma_Stream_Convert => Stream_Convert : declare
12465 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12466 -- Check that the given argument is the name of a local function
12467 -- of one argument that is not overloaded earlier in the current
12468 -- local scope. A check is also made that the argument is a
12469 -- function with one parameter.
12471 --------------------------------------
12472 -- Check_OK_Stream_Convert_Function --
12473 --------------------------------------
12475 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12479 Check_Arg_Is_Local_Name (Arg);
12480 Ent := Entity (Get_Pragma_Arg (Arg));
12482 if Has_Homonym (Ent) then
12484 ("argument for pragma% may not be overloaded", Arg);
12487 if Ekind (Ent) /= E_Function
12488 or else No (First_Formal (Ent))
12489 or else Present (Next_Formal (First_Formal (Ent)))
12492 ("argument for pragma% must be" &
12493 " function of one argument", Arg);
12495 end Check_OK_Stream_Convert_Function;
12497 -- Start of processing for Stream_Convert
12501 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12502 Check_Arg_Count (3);
12503 Check_Optional_Identifier (Arg1, Name_Entity);
12504 Check_Optional_Identifier (Arg2, Name_Read);
12505 Check_Optional_Identifier (Arg3, Name_Write);
12506 Check_Arg_Is_Local_Name (Arg1);
12507 Check_OK_Stream_Convert_Function (Arg2);
12508 Check_OK_Stream_Convert_Function (Arg3);
12511 Typ : constant Entity_Id :=
12512 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12513 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12514 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12517 Check_First_Subtype (Arg1);
12519 -- Check for too early or too late. Note that we don't enforce
12520 -- the rule about primitive operations in this case, since, as
12521 -- is the case for explicit stream attributes themselves, these
12522 -- restrictions are not appropriate. Note that the chaining of
12523 -- the pragma by Rep_Item_Too_Late is actually the critical
12524 -- processing done for this pragma.
12526 if Rep_Item_Too_Early (Typ, N)
12528 Rep_Item_Too_Late (Typ, N, FOnly => True)
12533 -- Return if previous error
12535 if Etype (Typ) = Any_Type
12537 Etype (Read) = Any_Type
12539 Etype (Write) = Any_Type
12546 if Underlying_Type (Etype (Read)) /= Typ then
12548 ("incorrect return type for function&", Arg2);
12551 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12553 ("incorrect parameter type for function&", Arg3);
12556 if Underlying_Type (Etype (First_Formal (Read))) /=
12557 Underlying_Type (Etype (Write))
12560 ("result type of & does not match Read parameter type",
12564 end Stream_Convert;
12566 -------------------------
12567 -- Style_Checks (GNAT) --
12568 -------------------------
12570 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12572 -- This is processed by the parser since some of the style checks
12573 -- take place during source scanning and parsing. This means that
12574 -- we don't need to issue error messages here.
12576 when Pragma_Style_Checks => Style_Checks : declare
12577 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12583 Check_No_Identifiers;
12585 -- Two argument form
12587 if Arg_Count = 2 then
12588 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12595 E_Id := Get_Pragma_Arg (Arg2);
12598 if not Is_Entity_Name (E_Id) then
12600 ("second argument of pragma% must be entity name",
12604 E := Entity (E_Id);
12610 Set_Suppress_Style_Checks (E,
12611 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12612 exit when No (Homonym (E));
12618 -- One argument form
12621 Check_Arg_Count (1);
12623 if Nkind (A) = N_String_Literal then
12627 Slen : constant Natural := Natural (String_Length (S));
12628 Options : String (1 .. Slen);
12634 C := Get_String_Char (S, Int (J));
12635 exit when not In_Character_Range (C);
12636 Options (J) := Get_Character (C);
12638 -- If at end of string, set options. As per discussion
12639 -- above, no need to check for errors, since we issued
12640 -- them in the parser.
12643 Set_Style_Check_Options (Options);
12651 elsif Nkind (A) = N_Identifier then
12652 if Chars (A) = Name_All_Checks then
12654 Set_GNAT_Style_Check_Options;
12656 Set_Default_Style_Check_Options;
12659 elsif Chars (A) = Name_On then
12660 Style_Check := True;
12662 elsif Chars (A) = Name_Off then
12663 Style_Check := False;
12673 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12675 when Pragma_Subtitle =>
12677 Check_Arg_Count (1);
12678 Check_Optional_Identifier (Arg1, Name_Subtitle);
12679 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12686 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12688 when Pragma_Suppress =>
12689 Process_Suppress_Unsuppress (True);
12695 -- pragma Suppress_All;
12697 -- The only check made here is that the pragma has no arguments.
12698 -- There are no placement rules, and the processing required (setting
12699 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12700 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12701 -- then creates and inserts a pragma Suppress (All_Checks).
12703 when Pragma_Suppress_All =>
12705 Check_Arg_Count (0);
12707 -------------------------
12708 -- Suppress_Debug_Info --
12709 -------------------------
12711 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12713 when Pragma_Suppress_Debug_Info =>
12715 Check_Arg_Count (1);
12716 Check_Optional_Identifier (Arg1, Name_Entity);
12717 Check_Arg_Is_Local_Name (Arg1);
12718 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
12720 ----------------------------------
12721 -- Suppress_Exception_Locations --
12722 ----------------------------------
12724 -- pragma Suppress_Exception_Locations;
12726 when Pragma_Suppress_Exception_Locations =>
12728 Check_Arg_Count (0);
12729 Check_Valid_Configuration_Pragma;
12730 Exception_Locations_Suppressed := True;
12732 -----------------------------
12733 -- Suppress_Initialization --
12734 -----------------------------
12736 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12738 when Pragma_Suppress_Initialization => Suppress_Init : declare
12744 Check_Arg_Count (1);
12745 Check_Optional_Identifier (Arg1, Name_Entity);
12746 Check_Arg_Is_Local_Name (Arg1);
12748 E_Id := Get_Pragma_Arg (Arg1);
12750 if Etype (E_Id) = Any_Type then
12754 E := Entity (E_Id);
12756 if not Is_Type (E) then
12757 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
12760 if Rep_Item_Too_Early (E, N)
12762 Rep_Item_Too_Late (E, N, FOnly => True)
12767 -- For incomplete/private type, set flag on full view
12769 if Is_Incomplete_Or_Private_Type (E) then
12770 if No (Full_View (Base_Type (E))) then
12772 ("argument of pragma% cannot be an incomplete type", Arg1);
12774 Set_Suppress_Initialization (Full_View (Base_Type (E)));
12777 -- For first subtype, set flag on base type
12779 elsif Is_First_Subtype (E) then
12780 Set_Suppress_Initialization (Base_Type (E));
12782 -- For other than first subtype, set flag on subtype itself
12785 Set_Suppress_Initialization (E);
12793 -- pragma System_Name (DIRECT_NAME);
12795 -- Syntax check: one argument, which must be the identifier GNAT or
12796 -- the identifier GCC, no other identifiers are acceptable.
12798 when Pragma_System_Name =>
12800 Check_No_Identifiers;
12801 Check_Arg_Count (1);
12802 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12804 -----------------------------
12805 -- Task_Dispatching_Policy --
12806 -----------------------------
12808 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12810 when Pragma_Task_Dispatching_Policy => declare
12814 Check_Ada_83_Warning;
12815 Check_Arg_Count (1);
12816 Check_No_Identifiers;
12817 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12818 Check_Valid_Configuration_Pragma;
12819 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12820 DP := Fold_Upper (Name_Buffer (1));
12822 if Task_Dispatching_Policy /= ' '
12823 and then Task_Dispatching_Policy /= DP
12825 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12827 ("task dispatching policy incompatible with policy#");
12829 -- Set new policy, but always preserve System_Location since we
12830 -- like the error message with the run time name.
12833 Task_Dispatching_Policy := DP;
12835 if Task_Dispatching_Policy_Sloc /= System_Location then
12836 Task_Dispatching_Policy_Sloc := Loc;
12845 -- pragma Task_Info (EXPRESSION);
12847 when Pragma_Task_Info => Task_Info : declare
12848 P : constant Node_Id := Parent (N);
12853 if Nkind (P) /= N_Task_Definition then
12854 Error_Pragma ("pragma% must appear in task definition");
12857 Check_No_Identifiers;
12858 Check_Arg_Count (1);
12860 Analyze_And_Resolve
12861 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12863 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12867 if Has_Task_Info_Pragma (P) then
12868 Error_Pragma ("duplicate pragma% not allowed");
12870 Set_Has_Task_Info_Pragma (P, True);
12878 -- pragma Task_Name (string_EXPRESSION);
12880 when Pragma_Task_Name => Task_Name : declare
12881 P : constant Node_Id := Parent (N);
12885 Check_No_Identifiers;
12886 Check_Arg_Count (1);
12888 Arg := Get_Pragma_Arg (Arg1);
12890 -- The expression is used in the call to Create_Task, and must be
12891 -- expanded there, not in the context of the current spec. It must
12892 -- however be analyzed to capture global references, in case it
12893 -- appears in a generic context.
12895 Preanalyze_And_Resolve (Arg, Standard_String);
12897 if Nkind (P) /= N_Task_Definition then
12901 if Has_Task_Name_Pragma (P) then
12902 Error_Pragma ("duplicate pragma% not allowed");
12904 Set_Has_Task_Name_Pragma (P, True);
12905 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12913 -- pragma Task_Storage (
12914 -- [Task_Type =>] LOCAL_NAME,
12915 -- [Top_Guard =>] static_integer_EXPRESSION);
12917 when Pragma_Task_Storage => Task_Storage : declare
12918 Args : Args_List (1 .. 2);
12919 Names : constant Name_List (1 .. 2) := (
12923 Task_Type : Node_Id renames Args (1);
12924 Top_Guard : Node_Id renames Args (2);
12930 Gather_Associations (Names, Args);
12932 if No (Task_Type) then
12934 ("missing task_type argument for pragma%");
12937 Check_Arg_Is_Local_Name (Task_Type);
12939 Ent := Entity (Task_Type);
12941 if not Is_Task_Type (Ent) then
12943 ("argument for pragma% must be task type", Task_Type);
12946 if No (Top_Guard) then
12948 ("pragma% takes two arguments", Task_Type);
12950 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12953 Check_First_Subtype (Task_Type);
12955 if Rep_Item_Too_Late (Ent, N) then
12960 --------------------------
12961 -- Thread_Local_Storage --
12962 --------------------------
12964 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12966 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
12972 Check_Arg_Count (1);
12973 Check_Optional_Identifier (Arg1, Name_Entity);
12974 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12976 Id := Get_Pragma_Arg (Arg1);
12979 if not Is_Entity_Name (Id)
12980 or else Ekind (Entity (Id)) /= E_Variable
12982 Error_Pragma_Arg ("local variable name required", Arg1);
12987 if Rep_Item_Too_Early (E, N)
12988 or else Rep_Item_Too_Late (E, N)
12993 Set_Has_Pragma_Thread_Local_Storage (E);
12994 Set_Has_Gigi_Rep_Item (E);
12995 end Thread_Local_Storage;
13001 -- pragma Time_Slice (static_duration_EXPRESSION);
13003 when Pragma_Time_Slice => Time_Slice : declare
13009 Check_Arg_Count (1);
13010 Check_No_Identifiers;
13011 Check_In_Main_Program;
13012 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13014 if not Error_Posted (Arg1) then
13016 while Present (Nod) loop
13017 if Nkind (Nod) = N_Pragma
13018 and then Pragma_Name (Nod) = Name_Time_Slice
13020 Error_Msg_Name_1 := Pname;
13021 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13028 -- Process only if in main unit
13030 if Get_Source_Unit (Loc) = Main_Unit then
13031 Opt.Time_Slice_Set := True;
13032 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13034 if Val <= Ureal_0 then
13035 Opt.Time_Slice_Value := 0;
13037 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13038 Opt.Time_Slice_Value := 1_000_000_000;
13041 Opt.Time_Slice_Value :=
13042 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13051 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13053 -- TITLING_OPTION ::=
13054 -- [Title =>] STRING_LITERAL
13055 -- | [Subtitle =>] STRING_LITERAL
13057 when Pragma_Title => Title : declare
13058 Args : Args_List (1 .. 2);
13059 Names : constant Name_List (1 .. 2) := (
13065 Gather_Associations (Names, Args);
13068 for J in 1 .. 2 loop
13069 if Present (Args (J)) then
13070 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13075 ---------------------
13076 -- Unchecked_Union --
13077 ---------------------
13079 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13081 when Pragma_Unchecked_Union => Unchecked_Union : declare
13082 Assoc : constant Node_Id := Arg1;
13083 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13094 Check_No_Identifiers;
13095 Check_Arg_Count (1);
13096 Check_Arg_Is_Local_Name (Arg1);
13098 Find_Type (Type_Id);
13099 Typ := Entity (Type_Id);
13102 or else Rep_Item_Too_Early (Typ, N)
13106 Typ := Underlying_Type (Typ);
13109 if Rep_Item_Too_Late (Typ, N) then
13113 Check_First_Subtype (Arg1);
13115 -- Note remaining cases are references to a type in the current
13116 -- declarative part. If we find an error, we post the error on
13117 -- the relevant type declaration at an appropriate point.
13119 if not Is_Record_Type (Typ) then
13120 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13123 elsif Is_Tagged_Type (Typ) then
13124 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13127 elsif Is_Limited_Type (Typ) then
13129 ("Unchecked_Union must not be limited record type", Typ);
13130 Explain_Limited_Type (Typ, Typ);
13134 if not Has_Discriminants (Typ) then
13136 ("Unchecked_Union must have one discriminant", Typ);
13140 Discr := First_Discriminant (Typ);
13141 while Present (Discr) loop
13142 if No (Discriminant_Default_Value (Discr)) then
13144 ("Unchecked_Union discriminant must have default value",
13148 Next_Discriminant (Discr);
13151 Tdef := Type_Definition (Declaration_Node (Typ));
13152 Clist := Component_List (Tdef);
13154 Comp := First (Component_Items (Clist));
13155 while Present (Comp) loop
13156 Check_Component (Comp, Typ);
13160 if No (Clist) or else No (Variant_Part (Clist)) then
13162 ("Unchecked_Union must have variant part",
13167 Vpart := Variant_Part (Clist);
13169 Variant := First (Variants (Vpart));
13170 while Present (Variant) loop
13171 Check_Variant (Variant, Typ);
13176 Set_Is_Unchecked_Union (Typ);
13177 Set_Convention (Typ, Convention_C);
13178 Set_Has_Unchecked_Union (Base_Type (Typ));
13179 Set_Is_Unchecked_Union (Base_Type (Typ));
13180 end Unchecked_Union;
13182 ------------------------
13183 -- Unimplemented_Unit --
13184 ------------------------
13186 -- pragma Unimplemented_Unit;
13188 -- Note: this only gives an error if we are generating code, or if
13189 -- we are in a generic library unit (where the pragma appears in the
13190 -- body, not in the spec).
13192 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13193 Cunitent : constant Entity_Id :=
13194 Cunit_Entity (Get_Source_Unit (Loc));
13195 Ent_Kind : constant Entity_Kind :=
13200 Check_Arg_Count (0);
13202 if Operating_Mode = Generate_Code
13203 or else Ent_Kind = E_Generic_Function
13204 or else Ent_Kind = E_Generic_Procedure
13205 or else Ent_Kind = E_Generic_Package
13207 Get_Name_String (Chars (Cunitent));
13208 Set_Casing (Mixed_Case);
13209 Write_Str (Name_Buffer (1 .. Name_Len));
13210 Write_Str (" is not supported in this configuration");
13212 raise Unrecoverable_Error;
13214 end Unimplemented_Unit;
13216 ------------------------
13217 -- Universal_Aliasing --
13218 ------------------------
13220 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13222 when Pragma_Universal_Aliasing => Universal_Alias : declare
13227 Check_Arg_Count (1);
13228 Check_Optional_Identifier (Arg2, Name_Entity);
13229 Check_Arg_Is_Local_Name (Arg1);
13230 E_Id := Entity (Get_Pragma_Arg (Arg1));
13232 if E_Id = Any_Type then
13234 elsif No (E_Id) or else not Is_Type (E_Id) then
13235 Error_Pragma_Arg ("pragma% requires type", Arg1);
13238 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13239 end Universal_Alias;
13241 --------------------
13242 -- Universal_Data --
13243 --------------------
13245 -- pragma Universal_Data [(library_unit_NAME)];
13247 when Pragma_Universal_Data =>
13250 -- If this is a configuration pragma, then set the universal
13251 -- addressing option, otherwise confirm that the pragma satisfies
13252 -- the requirements of library unit pragma placement and leave it
13253 -- to the GNAAMP back end to detect the pragma (avoids transitive
13254 -- setting of the option due to withed units).
13256 if Is_Configuration_Pragma then
13257 Universal_Addressing_On_AAMP := True;
13259 Check_Valid_Library_Unit_Pragma;
13262 if not AAMP_On_Target then
13263 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13270 -- pragma Unmodified (local_Name {, local_Name});
13272 when Pragma_Unmodified => Unmodified : declare
13273 Arg_Node : Node_Id;
13274 Arg_Expr : Node_Id;
13275 Arg_Ent : Entity_Id;
13279 Check_At_Least_N_Arguments (1);
13281 -- Loop through arguments
13284 while Present (Arg_Node) loop
13285 Check_No_Identifier (Arg_Node);
13287 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13288 -- in fact generate reference, so that the entity will have a
13289 -- reference, which will inhibit any warnings about it not
13290 -- being referenced, and also properly show up in the ali file
13291 -- as a reference. But this reference is recorded before the
13292 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13293 -- generated for this reference.
13295 Check_Arg_Is_Local_Name (Arg_Node);
13296 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13298 if Is_Entity_Name (Arg_Expr) then
13299 Arg_Ent := Entity (Arg_Expr);
13301 if not Is_Assignable (Arg_Ent) then
13303 ("pragma% can only be applied to a variable",
13306 Set_Has_Pragma_Unmodified (Arg_Ent);
13318 -- pragma Unreferenced (local_Name {, local_Name});
13320 -- or when used in a context clause:
13322 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13324 when Pragma_Unreferenced => Unreferenced : declare
13325 Arg_Node : Node_Id;
13326 Arg_Expr : Node_Id;
13327 Arg_Ent : Entity_Id;
13332 Check_At_Least_N_Arguments (1);
13334 -- Check case of appearing within context clause
13336 if Is_In_Context_Clause then
13338 -- The arguments must all be units mentioned in a with clause
13339 -- in the same context clause. Note we already checked (in
13340 -- Par.Prag) that the arguments are either identifiers or
13341 -- selected components.
13344 while Present (Arg_Node) loop
13345 Citem := First (List_Containing (N));
13346 while Citem /= N loop
13347 if Nkind (Citem) = N_With_Clause
13349 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13351 Set_Has_Pragma_Unreferenced
13354 (Library_Unit (Citem))));
13356 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13365 ("argument of pragma% is not with'ed unit", Arg_Node);
13371 -- Case of not in list of context items
13375 while Present (Arg_Node) loop
13376 Check_No_Identifier (Arg_Node);
13378 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13379 -- will in fact generate reference, so that the entity will
13380 -- have a reference, which will inhibit any warnings about
13381 -- it not being referenced, and also properly show up in the
13382 -- ali file as a reference. But this reference is recorded
13383 -- before the Has_Pragma_Unreferenced flag is set, so that
13384 -- no warning is generated for this reference.
13386 Check_Arg_Is_Local_Name (Arg_Node);
13387 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13389 if Is_Entity_Name (Arg_Expr) then
13390 Arg_Ent := Entity (Arg_Expr);
13392 -- If the entity is overloaded, the pragma applies to the
13393 -- most recent overloading, as documented. In this case,
13394 -- name resolution does not generate a reference, so it
13395 -- must be done here explicitly.
13397 if Is_Overloaded (Arg_Expr) then
13398 Generate_Reference (Arg_Ent, N);
13401 Set_Has_Pragma_Unreferenced (Arg_Ent);
13409 --------------------------
13410 -- Unreferenced_Objects --
13411 --------------------------
13413 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13415 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13416 Arg_Node : Node_Id;
13417 Arg_Expr : Node_Id;
13421 Check_At_Least_N_Arguments (1);
13424 while Present (Arg_Node) loop
13425 Check_No_Identifier (Arg_Node);
13426 Check_Arg_Is_Local_Name (Arg_Node);
13427 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13429 if not Is_Entity_Name (Arg_Expr)
13430 or else not Is_Type (Entity (Arg_Expr))
13433 ("argument for pragma% must be type or subtype", Arg_Node);
13436 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13439 end Unreferenced_Objects;
13441 ------------------------------
13442 -- Unreserve_All_Interrupts --
13443 ------------------------------
13445 -- pragma Unreserve_All_Interrupts;
13447 when Pragma_Unreserve_All_Interrupts =>
13449 Check_Arg_Count (0);
13451 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13452 Unreserve_All_Interrupts := True;
13459 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13461 when Pragma_Unsuppress =>
13463 Process_Suppress_Unsuppress (False);
13465 -------------------
13466 -- Use_VADS_Size --
13467 -------------------
13469 -- pragma Use_VADS_Size;
13471 when Pragma_Use_VADS_Size =>
13473 Check_Arg_Count (0);
13474 Check_Valid_Configuration_Pragma;
13475 Use_VADS_Size := True;
13477 ---------------------
13478 -- Validity_Checks --
13479 ---------------------
13481 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13483 when Pragma_Validity_Checks => Validity_Checks : declare
13484 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13490 Check_Arg_Count (1);
13491 Check_No_Identifiers;
13493 if Nkind (A) = N_String_Literal then
13497 Slen : constant Natural := Natural (String_Length (S));
13498 Options : String (1 .. Slen);
13504 C := Get_String_Char (S, Int (J));
13505 exit when not In_Character_Range (C);
13506 Options (J) := Get_Character (C);
13509 Set_Validity_Check_Options (Options);
13517 elsif Nkind (A) = N_Identifier then
13519 if Chars (A) = Name_All_Checks then
13520 Set_Validity_Check_Options ("a");
13522 elsif Chars (A) = Name_On then
13523 Validity_Checks_On := True;
13525 elsif Chars (A) = Name_Off then
13526 Validity_Checks_On := False;
13530 end Validity_Checks;
13536 -- pragma Volatile (LOCAL_NAME);
13538 when Pragma_Volatile =>
13539 Process_Atomic_Shared_Volatile;
13541 -------------------------
13542 -- Volatile_Components --
13543 -------------------------
13545 -- pragma Volatile_Components (array_LOCAL_NAME);
13547 -- Volatile is handled by the same circuit as Atomic_Components
13553 -- pragma Warnings (On | Off);
13554 -- pragma Warnings (On | Off, LOCAL_NAME);
13555 -- pragma Warnings (static_string_EXPRESSION);
13556 -- pragma Warnings (On | Off, STRING_LITERAL);
13558 when Pragma_Warnings => Warnings : begin
13560 Check_At_Least_N_Arguments (1);
13561 Check_No_Identifiers;
13563 -- If debug flag -gnatd.i is set, pragma is ignored
13565 if Debug_Flag_Dot_I then
13569 -- Process various forms of the pragma
13572 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13575 -- One argument case
13577 if Arg_Count = 1 then
13579 -- On/Off one argument case was processed by parser
13581 if Nkind (Argx) = N_Identifier
13583 (Chars (Argx) = Name_On
13585 Chars (Argx) = Name_Off)
13589 -- One argument case must be ON/OFF or static string expr
13591 elsif not Is_Static_String_Expression (Arg1) then
13593 ("argument of pragma% must be On/Off or " &
13594 "static string expression", Arg1);
13596 -- One argument string expression case
13600 Lit : constant Node_Id := Expr_Value_S (Argx);
13601 Str : constant String_Id := Strval (Lit);
13602 Len : constant Nat := String_Length (Str);
13610 while J <= Len loop
13611 C := Get_String_Char (Str, J);
13612 OK := In_Character_Range (C);
13615 Chr := Get_Character (C);
13619 if J < Len and then Chr = '.' then
13621 C := Get_String_Char (Str, J);
13622 Chr := Get_Character (C);
13624 if not Set_Dot_Warning_Switch (Chr) then
13626 ("invalid warning switch character " &
13633 OK := Set_Warning_Switch (Chr);
13639 ("invalid warning switch character " & Chr,
13648 -- Two or more arguments (must be two)
13651 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13652 Check_At_Most_N_Arguments (2);
13660 E_Id := Get_Pragma_Arg (Arg2);
13663 -- In the expansion of an inlined body, a reference to
13664 -- the formal may be wrapped in a conversion if the
13665 -- actual is a conversion. Retrieve the real entity name.
13667 if (In_Instance_Body
13668 or else In_Inlined_Body)
13669 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13671 E_Id := Expression (E_Id);
13674 -- Entity name case
13676 if Is_Entity_Name (E_Id) then
13677 E := Entity (E_Id);
13684 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13687 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13688 and then Warn_On_Warnings_Off
13690 Warnings_Off_Pragmas.Append ((N, E));
13693 if Is_Enumeration_Type (E) then
13697 Lit := First_Literal (E);
13698 while Present (Lit) loop
13699 Set_Warnings_Off (Lit);
13700 Next_Literal (Lit);
13705 exit when No (Homonym (E));
13710 -- Error if not entity or static string literal case
13712 elsif not Is_Static_String_Expression (Arg2) then
13714 ("second argument of pragma% must be entity " &
13715 "name or static string expression", Arg2);
13717 -- String literal case
13720 String_To_Name_Buffer
13721 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13723 -- Note on configuration pragma case: If this is a
13724 -- configuration pragma, then for an OFF pragma, we
13725 -- just set Config True in the call, which is all
13726 -- that needs to be done. For the case of ON, this
13727 -- is normally an error, unless it is canceling the
13728 -- effect of a previous OFF pragma in the same file.
13729 -- In any other case, an error will be signalled (ON
13730 -- with no matching OFF).
13732 if Chars (Argx) = Name_Off then
13733 Set_Specific_Warning_Off
13734 (Loc, Name_Buffer (1 .. Name_Len),
13735 Config => Is_Configuration_Pragma);
13737 elsif Chars (Argx) = Name_On then
13738 Set_Specific_Warning_On
13739 (Loc, Name_Buffer (1 .. Name_Len), Err);
13743 ("?pragma Warnings On with no " &
13744 "matching Warnings Off",
13754 -------------------
13755 -- Weak_External --
13756 -------------------
13758 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13760 when Pragma_Weak_External => Weak_External : declare
13765 Check_Arg_Count (1);
13766 Check_Optional_Identifier (Arg1, Name_Entity);
13767 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13768 Ent := Entity (Get_Pragma_Arg (Arg1));
13770 if Rep_Item_Too_Early (Ent, N) then
13773 Ent := Underlying_Type (Ent);
13776 -- The only processing required is to link this item on to the
13777 -- list of rep items for the given entity. This is accomplished
13778 -- by the call to Rep_Item_Too_Late (when no error is detected
13779 -- and False is returned).
13781 if Rep_Item_Too_Late (Ent, N) then
13784 Set_Has_Gigi_Rep_Item (Ent);
13788 -----------------------------
13789 -- Wide_Character_Encoding --
13790 -----------------------------
13792 -- pragma Wide_Character_Encoding (IDENTIFIER);
13794 when Pragma_Wide_Character_Encoding =>
13797 -- Nothing to do, handled in parser. Note that we do not enforce
13798 -- configuration pragma placement, this pragma can appear at any
13799 -- place in the source, allowing mixed encodings within a single
13804 --------------------
13805 -- Unknown_Pragma --
13806 --------------------
13808 -- Should be impossible, since the case of an unknown pragma is
13809 -- separately processed before the case statement is entered.
13811 when Unknown_Pragma =>
13812 raise Program_Error;
13815 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13816 -- until AI is formally approved.
13818 -- Check_Order_Dependence;
13821 when Pragma_Exit => null;
13822 end Analyze_Pragma;
13824 -------------------
13825 -- Check_Enabled --
13826 -------------------
13828 function Check_Enabled (Nam : Name_Id) return Boolean is
13832 -- Loop through entries in check policy list
13834 PP := Opt.Check_Policy_List;
13836 -- If there are no specific entries that matched, then we let the
13837 -- setting of assertions govern. Note that this provides the needed
13838 -- compatibility with the RM for the cases of assertion, invariant,
13839 -- precondition, predicate, and postcondition.
13842 return Assertions_Enabled;
13844 -- Here we have an entry see if it matches
13848 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13851 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13852 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13853 when Name_On | Name_Check =>
13855 when Name_Off | Name_Ignore =>
13858 raise Program_Error;
13862 PP := Next_Pragma (PP);
13869 ---------------------------------
13870 -- Delay_Config_Pragma_Analyze --
13871 ---------------------------------
13873 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13875 return Pragma_Name (N) = Name_Interrupt_State
13877 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13878 end Delay_Config_Pragma_Analyze;
13880 -------------------------
13881 -- Get_Base_Subprogram --
13882 -------------------------
13884 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13885 Result : Entity_Id;
13888 -- Follow subprogram renaming chain
13891 while Is_Subprogram (Result)
13893 (Is_Generic_Instance (Result)
13894 or else Nkind (Parent (Declaration_Node (Result))) =
13895 N_Subprogram_Renaming_Declaration)
13896 and then Present (Alias (Result))
13898 Result := Alias (Result);
13902 end Get_Base_Subprogram;
13908 procedure Initialize is
13913 -----------------------------
13914 -- Is_Config_Static_String --
13915 -----------------------------
13917 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13919 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13920 -- This is an internal recursive function that is just like the outer
13921 -- function except that it adds the string to the name buffer rather
13922 -- than placing the string in the name buffer.
13924 ------------------------------
13925 -- Add_Config_Static_String --
13926 ------------------------------
13928 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13935 if Nkind (N) = N_Op_Concat then
13936 if Add_Config_Static_String (Left_Opnd (N)) then
13937 N := Right_Opnd (N);
13943 if Nkind (N) /= N_String_Literal then
13944 Error_Msg_N ("string literal expected for pragma argument", N);
13948 for J in 1 .. String_Length (Strval (N)) loop
13949 C := Get_String_Char (Strval (N), J);
13951 if not In_Character_Range (C) then
13953 ("string literal contains invalid wide character",
13954 Sloc (N) + 1 + Source_Ptr (J));
13958 Add_Char_To_Name_Buffer (Get_Character (C));
13963 end Add_Config_Static_String;
13965 -- Start of processing for Is_Config_Static_String
13970 return Add_Config_Static_String (Arg);
13971 end Is_Config_Static_String;
13973 -----------------------------------------
13974 -- Is_Non_Significant_Pragma_Reference --
13975 -----------------------------------------
13977 -- This function makes use of the following static table which indicates
13978 -- whether a given pragma is significant.
13980 -- -1 indicates that references in any argument position are significant
13981 -- 0 indicates that appearance in any argument is not significant
13982 -- +n indicates that appearance as argument n is significant, but all
13983 -- other arguments are not significant
13984 -- 99 special processing required (e.g. for pragma Check)
13986 Sig_Flags : constant array (Pragma_Id) of Int :=
13987 (Pragma_AST_Entry => -1,
13988 Pragma_Abort_Defer => -1,
13989 Pragma_Ada_83 => -1,
13990 Pragma_Ada_95 => -1,
13991 Pragma_Ada_05 => -1,
13992 Pragma_Ada_2005 => -1,
13993 Pragma_Ada_12 => -1,
13994 Pragma_Ada_2012 => -1,
13995 Pragma_All_Calls_Remote => -1,
13996 Pragma_Annotate => -1,
13997 Pragma_Assert => -1,
13998 Pragma_Assertion_Policy => 0,
13999 Pragma_Assume_No_Invalid_Values => 0,
14000 Pragma_Asynchronous => -1,
14001 Pragma_Atomic => 0,
14002 Pragma_Atomic_Components => 0,
14003 Pragma_Attach_Handler => -1,
14004 Pragma_Check => 99,
14005 Pragma_Check_Name => 0,
14006 Pragma_Check_Policy => 0,
14007 Pragma_CIL_Constructor => -1,
14008 Pragma_CPP_Class => 0,
14009 Pragma_CPP_Constructor => 0,
14010 Pragma_CPP_Virtual => 0,
14011 Pragma_CPP_Vtable => 0,
14013 Pragma_C_Pass_By_Copy => 0,
14014 Pragma_Comment => 0,
14015 Pragma_Common_Object => -1,
14016 Pragma_Compile_Time_Error => -1,
14017 Pragma_Compile_Time_Warning => -1,
14018 Pragma_Compiler_Unit => 0,
14019 Pragma_Complete_Representation => 0,
14020 Pragma_Complex_Representation => 0,
14021 Pragma_Component_Alignment => -1,
14022 Pragma_Controlled => 0,
14023 Pragma_Convention => 0,
14024 Pragma_Convention_Identifier => 0,
14025 Pragma_Debug => -1,
14026 Pragma_Debug_Policy => 0,
14027 Pragma_Detect_Blocking => -1,
14028 Pragma_Default_Storage_Pool => -1,
14029 Pragma_Dimension => -1,
14030 Pragma_Discard_Names => 0,
14031 Pragma_Elaborate => -1,
14032 Pragma_Elaborate_All => -1,
14033 Pragma_Elaborate_Body => -1,
14034 Pragma_Elaboration_Checks => -1,
14035 Pragma_Eliminate => -1,
14036 Pragma_Export => -1,
14037 Pragma_Export_Exception => -1,
14038 Pragma_Export_Function => -1,
14039 Pragma_Export_Object => -1,
14040 Pragma_Export_Procedure => -1,
14041 Pragma_Export_Value => -1,
14042 Pragma_Export_Valued_Procedure => -1,
14043 Pragma_Extend_System => -1,
14044 Pragma_Extensions_Allowed => -1,
14045 Pragma_External => -1,
14046 Pragma_Favor_Top_Level => -1,
14047 Pragma_External_Name_Casing => -1,
14048 Pragma_Fast_Math => -1,
14049 Pragma_Finalize_Storage_Only => 0,
14050 Pragma_Float_Representation => 0,
14051 Pragma_Ident => -1,
14052 Pragma_Implemented => -1,
14053 Pragma_Implicit_Packing => 0,
14054 Pragma_Import => +2,
14055 Pragma_Import_Exception => 0,
14056 Pragma_Import_Function => 0,
14057 Pragma_Import_Object => 0,
14058 Pragma_Import_Procedure => 0,
14059 Pragma_Import_Valued_Procedure => 0,
14060 Pragma_Independent => 0,
14061 Pragma_Independent_Components => 0,
14062 Pragma_Initialize_Scalars => -1,
14063 Pragma_Inline => 0,
14064 Pragma_Inline_Always => 0,
14065 Pragma_Inline_Generic => 0,
14066 Pragma_Inspection_Point => -1,
14067 Pragma_Interface => +2,
14068 Pragma_Interface_Name => +2,
14069 Pragma_Interrupt_Handler => -1,
14070 Pragma_Interrupt_Priority => -1,
14071 Pragma_Interrupt_State => -1,
14072 Pragma_Invariant => -1,
14073 Pragma_Java_Constructor => -1,
14074 Pragma_Java_Interface => -1,
14075 Pragma_Keep_Names => 0,
14076 Pragma_License => -1,
14077 Pragma_Link_With => -1,
14078 Pragma_Linker_Alias => -1,
14079 Pragma_Linker_Constructor => -1,
14080 Pragma_Linker_Destructor => -1,
14081 Pragma_Linker_Options => -1,
14082 Pragma_Linker_Section => -1,
14084 Pragma_Locking_Policy => -1,
14085 Pragma_Long_Float => -1,
14086 Pragma_Machine_Attribute => -1,
14088 Pragma_Main_Storage => -1,
14089 Pragma_Memory_Size => -1,
14090 Pragma_No_Return => 0,
14091 Pragma_No_Body => 0,
14092 Pragma_No_Run_Time => -1,
14093 Pragma_No_Strict_Aliasing => -1,
14094 Pragma_Normalize_Scalars => -1,
14095 Pragma_Obsolescent => 0,
14096 Pragma_Optimize => -1,
14097 Pragma_Optimize_Alignment => -1,
14098 Pragma_Ordered => 0,
14101 Pragma_Passive => -1,
14102 Pragma_Preelaborable_Initialization => -1,
14103 Pragma_Polling => -1,
14104 Pragma_Persistent_BSS => 0,
14105 Pragma_Postcondition => -1,
14106 Pragma_Precondition => -1,
14107 Pragma_Predicate => -1,
14108 Pragma_Preelaborate => -1,
14109 Pragma_Preelaborate_05 => -1,
14110 Pragma_Priority => -1,
14111 Pragma_Priority_Specific_Dispatching => -1,
14112 Pragma_Profile => 0,
14113 Pragma_Profile_Warnings => 0,
14114 Pragma_Propagate_Exceptions => -1,
14115 Pragma_Psect_Object => -1,
14117 Pragma_Pure_05 => -1,
14118 Pragma_Pure_Function => -1,
14119 Pragma_Queuing_Policy => -1,
14120 Pragma_Ravenscar => -1,
14121 Pragma_Relative_Deadline => -1,
14122 Pragma_Remote_Call_Interface => -1,
14123 Pragma_Remote_Types => -1,
14124 Pragma_Restricted_Run_Time => -1,
14125 Pragma_Restriction_Warnings => -1,
14126 Pragma_Restrictions => -1,
14127 Pragma_Reviewable => -1,
14128 Pragma_Short_Circuit_And_Or => -1,
14129 Pragma_Share_Generic => -1,
14130 Pragma_Shared => -1,
14131 Pragma_Shared_Passive => -1,
14132 Pragma_Short_Descriptors => 0,
14133 Pragma_Source_File_Name => -1,
14134 Pragma_Source_File_Name_Project => -1,
14135 Pragma_Source_Reference => -1,
14136 Pragma_Storage_Size => -1,
14137 Pragma_Storage_Unit => -1,
14138 Pragma_Static_Elaboration_Desired => -1,
14139 Pragma_Stream_Convert => -1,
14140 Pragma_Style_Checks => -1,
14141 Pragma_Subtitle => -1,
14142 Pragma_Suppress => 0,
14143 Pragma_Suppress_Exception_Locations => 0,
14144 Pragma_Suppress_All => -1,
14145 Pragma_Suppress_Debug_Info => 0,
14146 Pragma_Suppress_Initialization => 0,
14147 Pragma_System_Name => -1,
14148 Pragma_Task_Dispatching_Policy => -1,
14149 Pragma_Task_Info => -1,
14150 Pragma_Task_Name => -1,
14151 Pragma_Task_Storage => 0,
14152 Pragma_Thread_Local_Storage => 0,
14153 Pragma_Time_Slice => -1,
14154 Pragma_Title => -1,
14155 Pragma_Unchecked_Union => 0,
14156 Pragma_Unimplemented_Unit => -1,
14157 Pragma_Universal_Aliasing => -1,
14158 Pragma_Universal_Data => -1,
14159 Pragma_Unmodified => -1,
14160 Pragma_Unreferenced => -1,
14161 Pragma_Unreferenced_Objects => -1,
14162 Pragma_Unreserve_All_Interrupts => -1,
14163 Pragma_Unsuppress => 0,
14164 Pragma_Use_VADS_Size => -1,
14165 Pragma_Validity_Checks => -1,
14166 Pragma_Volatile => 0,
14167 Pragma_Volatile_Components => 0,
14168 Pragma_Warnings => -1,
14169 Pragma_Weak_External => -1,
14170 Pragma_Wide_Character_Encoding => 0,
14171 Unknown_Pragma => 0);
14173 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14182 if Nkind (P) /= N_Pragma_Argument_Association then
14186 Id := Get_Pragma_Id (Parent (P));
14187 C := Sig_Flags (Id);
14199 -- For pragma Check, the first argument is not significant,
14200 -- the second and the third (if present) arguments are
14203 when Pragma_Check =>
14205 P = First (Pragma_Argument_Associations (Parent (P)));
14208 raise Program_Error;
14212 A := First (Pragma_Argument_Associations (Parent (P)));
14213 for J in 1 .. C - 1 loop
14221 return A = P; -- is this wrong way round ???
14224 end Is_Non_Significant_Pragma_Reference;
14226 ------------------------------
14227 -- Is_Pragma_String_Literal --
14228 ------------------------------
14230 -- This function returns true if the corresponding pragma argument is a
14231 -- static string expression. These are the only cases in which string
14232 -- literals can appear as pragma arguments. We also allow a string literal
14233 -- as the first argument to pragma Assert (although it will of course
14234 -- always generate a type error).
14236 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14237 Pragn : constant Node_Id := Parent (Par);
14238 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14239 Pname : constant Name_Id := Pragma_Name (Pragn);
14245 N := First (Assoc);
14252 if Pname = Name_Assert then
14255 elsif Pname = Name_Export then
14258 elsif Pname = Name_Ident then
14261 elsif Pname = Name_Import then
14264 elsif Pname = Name_Interface_Name then
14267 elsif Pname = Name_Linker_Alias then
14270 elsif Pname = Name_Linker_Section then
14273 elsif Pname = Name_Machine_Attribute then
14276 elsif Pname = Name_Source_File_Name then
14279 elsif Pname = Name_Source_Reference then
14282 elsif Pname = Name_Title then
14285 elsif Pname = Name_Subtitle then
14291 end Is_Pragma_String_Literal;
14293 --------------------------------------
14294 -- Process_Compilation_Unit_Pragmas --
14295 --------------------------------------
14297 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14299 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14300 -- strange because it comes at the end of the unit. Rational has the
14301 -- same name for a pragma, but treats it as a program unit pragma, In
14302 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14303 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14304 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14305 -- the context clause to ensure the correct processing.
14307 if Has_Pragma_Suppress_All (N) then
14308 Prepend_To (Context_Items (N),
14309 Make_Pragma (Sloc (N),
14310 Chars => Name_Suppress,
14311 Pragma_Argument_Associations => New_List (
14312 Make_Pragma_Argument_Association (Sloc (N),
14313 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14316 -- Nothing else to do at the current time!
14318 end Process_Compilation_Unit_Pragmas;
14329 --------------------------------
14330 -- Set_Encoded_Interface_Name --
14331 --------------------------------
14333 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14334 Str : constant String_Id := Strval (S);
14335 Len : constant Int := String_Length (Str);
14340 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14343 -- Stores encoded value of character code CC. The encoding we use an
14344 -- underscore followed by four lower case hex digits.
14350 procedure Encode is
14352 Store_String_Char (Get_Char_Code ('_'));
14354 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14356 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14358 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14360 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14363 -- Start of processing for Set_Encoded_Interface_Name
14366 -- If first character is asterisk, this is a link name, and we leave it
14367 -- completely unmodified. We also ignore null strings (the latter case
14368 -- happens only in error cases) and no encoding should occur for Java or
14369 -- AAMP interface names.
14372 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14373 or else VM_Target /= No_VM
14374 or else AAMP_On_Target
14376 Set_Interface_Name (E, S);
14381 CC := Get_String_Char (Str, J);
14383 exit when not In_Character_Range (CC);
14385 C := Get_Character (CC);
14387 exit when C /= '_' and then C /= '$'
14388 and then C not in '0' .. '9'
14389 and then C not in 'a' .. 'z'
14390 and then C not in 'A' .. 'Z';
14393 Set_Interface_Name (E, S);
14401 -- Here we need to encode. The encoding we use as follows:
14402 -- three underscores + four hex digits (lower case)
14406 for J in 1 .. String_Length (Str) loop
14407 CC := Get_String_Char (Str, J);
14409 if not In_Character_Range (CC) then
14412 C := Get_Character (CC);
14414 if C = '_' or else C = '$'
14415 or else C in '0' .. '9'
14416 or else C in 'a' .. 'z'
14417 or else C in 'A' .. 'Z'
14419 Store_String_Char (CC);
14426 Set_Interface_Name (E,
14427 Make_String_Literal (Sloc (S),
14428 Strval => End_String));
14430 end Set_Encoded_Interface_Name;
14432 -------------------
14433 -- Set_Unit_Name --
14434 -------------------
14436 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14441 if Nkind (N) = N_Identifier
14442 and then Nkind (With_Item) = N_Identifier
14444 Set_Entity (N, Entity (With_Item));
14446 elsif Nkind (N) = N_Selected_Component then
14447 Change_Selected_Component_To_Expanded_Name (N);
14448 Set_Entity (N, Entity (With_Item));
14449 Set_Entity (Selector_Name (N), Entity (N));
14451 Pref := Prefix (N);
14452 Scop := Scope (Entity (N));
14453 while Nkind (Pref) = N_Selected_Component loop
14454 Change_Selected_Component_To_Expanded_Name (Pref);
14455 Set_Entity (Selector_Name (Pref), Scop);
14456 Set_Entity (Pref, Scop);
14457 Pref := Prefix (Pref);
14458 Scop := Scope (Scop);
14461 Set_Entity (Pref, Scop);