1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Atree; use Atree;
33 with Casing; use Casing;
34 with Checks; use Checks;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Elists; use Elists;
39 with Errout; use Errout;
40 with Exp_Ch7; use Exp_Ch7;
41 with Exp_Dist; use Exp_Dist;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet.Sp; use Namet.Sp;
46 with Nlists; use Nlists;
47 with Nmake; use Nmake;
49 with Output; use Output;
50 with Par_SCO; use Par_SCO;
51 with Restrict; use Restrict;
52 with Rident; use Rident;
53 with Rtsfind; use Rtsfind;
55 with Sem_Aux; use Sem_Aux;
56 with Sem_Ch3; use Sem_Ch3;
57 with Sem_Ch6; use Sem_Ch6;
58 with Sem_Ch8; use Sem_Ch8;
59 with Sem_Ch12; use Sem_Ch12;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Disp; use Sem_Disp;
62 with Sem_Dist; use Sem_Dist;
63 with Sem_Elim; use Sem_Elim;
64 with Sem_Eval; use Sem_Eval;
65 with Sem_Intr; use Sem_Intr;
66 with Sem_Mech; use Sem_Mech;
67 with Sem_Res; use Sem_Res;
68 with Sem_Type; use Sem_Type;
69 with Sem_Util; use Sem_Util;
70 with Sem_VFpt; use Sem_VFpt;
71 with Sem_Warn; use Sem_Warn;
72 with Stand; use Stand;
73 with Sinfo; use Sinfo;
74 with Sinfo.CN; use Sinfo.CN;
75 with Sinput; use Sinput;
76 with Snames; use Snames;
77 with Stringt; use Stringt;
78 with Stylesw; use Stylesw;
80 with Targparm; use Targparm;
81 with Tbuild; use Tbuild;
83 with Uintp; use Uintp;
84 with Uname; use Uname;
85 with Urealp; use Urealp;
86 with Validsw; use Validsw;
87 with Warnsw; use Warnsw;
89 package body Sem_Prag is
91 ----------------------------------------------
92 -- Common Handling of Import-Export Pragmas --
93 ----------------------------------------------
95 -- In the following section, a number of Import_xxx and Export_xxx pragmas
96 -- are defined by GNAT. These are compatible with the DEC pragmas of the
97 -- same name, and all have the following common form and processing:
100 -- [Internal =>] LOCAL_NAME
101 -- [, [External =>] EXTERNAL_SYMBOL]
102 -- [, other optional parameters ]);
105 -- [Internal =>] LOCAL_NAME
106 -- [, [External =>] EXTERNAL_SYMBOL]
107 -- [, other optional parameters ]);
109 -- EXTERNAL_SYMBOL ::=
111 -- | static_string_EXPRESSION
113 -- The internal LOCAL_NAME designates the entity that is imported or
114 -- exported, and must refer to an entity in the current declarative
115 -- part (as required by the rules for LOCAL_NAME).
117 -- The external linker name is designated by the External parameter if
118 -- given, or the Internal parameter if not (if there is no External
119 -- parameter, the External parameter is a copy of the Internal name).
121 -- If the External parameter is given as a string, then this string is
122 -- treated as an external name (exactly as though it had been given as an
123 -- External_Name parameter for a normal Import pragma).
125 -- If the External parameter is given as an identifier (or there is no
126 -- External parameter, so that the Internal identifier is used), then
127 -- the external name is the characters of the identifier, translated
128 -- to all upper case letters for OpenVMS versions of GNAT, and to all
129 -- lower case letters for all other versions
131 -- Note: the external name specified or implied by any of these special
132 -- Import_xxx or Export_xxx pragmas override an external or link name
133 -- specified in a previous Import or Export pragma.
135 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
136 -- named notation, following the standard rules for subprogram calls, i.e.
137 -- parameters can be given in any order if named notation is used, and
138 -- positional and named notation can be mixed, subject to the rule that all
139 -- positional parameters must appear first.
141 -- Note: All these pragmas are implemented exactly following the DEC design
142 -- and implementation and are intended to be fully compatible with the use
143 -- of these pragmas in the DEC Ada compiler.
145 --------------------------------------------
146 -- Checking for Duplicated External Names --
147 --------------------------------------------
149 -- It is suspicious if two separate Export pragmas use the same external
150 -- name. The following table is used to diagnose this situation so that
151 -- an appropriate warning can be issued.
153 -- The Node_Id stored is for the N_String_Literal node created to hold
154 -- the value of the external name. The Sloc of this node is used to
155 -- cross-reference the location of the duplication.
157 package Externals is new Table.Table (
158 Table_Component_Type => Node_Id,
159 Table_Index_Type => Int,
160 Table_Low_Bound => 0,
161 Table_Initial => 100,
162 Table_Increment => 100,
163 Table_Name => "Name_Externals");
165 -------------------------------------
166 -- Local Subprograms and Variables --
167 -------------------------------------
169 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
170 -- This routine is used for possible casing adjustment of an explicit
171 -- external name supplied as a string literal (the node N), according to
172 -- the casing requirement of Opt.External_Name_Casing. If this is set to
173 -- As_Is, then the string literal is returned unchanged, but if it is set
174 -- to Uppercase or Lowercase, then a new string literal with appropriate
175 -- casing is constructed.
177 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
178 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
179 -- original one, following the renaming chain) is returned. Otherwise the
180 -- entity is returned unchanged. Should be in Einfo???
183 -- This is a dummy function called by the processing for pragma Reviewable.
184 -- It is there for assisting front end debugging. By placing a Reviewable
185 -- pragma in the source program, a breakpoint on rv catches this place in
186 -- the source, allowing convenient stepping to the point of interest.
188 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
189 -- Place semantic information on the argument of an Elaborate/Elaborate_All
190 -- pragma. Entity name for unit and its parents is taken from item in
191 -- previous with_clause that mentions the unit.
193 -------------------------------
194 -- Adjust_External_Name_Case --
195 -------------------------------
197 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
201 -- Adjust case of literal if required
203 if Opt.External_Name_Exp_Casing = As_Is then
207 -- Copy existing string
213 for J in 1 .. String_Length (Strval (N)) loop
214 CC := Get_String_Char (Strval (N), J);
216 if Opt.External_Name_Exp_Casing = Uppercase
217 and then CC >= Get_Char_Code ('a')
218 and then CC <= Get_Char_Code ('z')
220 Store_String_Char (CC - 32);
222 elsif Opt.External_Name_Exp_Casing = Lowercase
223 and then CC >= Get_Char_Code ('A')
224 and then CC <= Get_Char_Code ('Z')
226 Store_String_Char (CC + 32);
229 Store_String_Char (CC);
234 Make_String_Literal (Sloc (N),
235 Strval => End_String);
237 end Adjust_External_Name_Case;
239 ------------------------------
240 -- Analyze_PPC_In_Decl_Part --
241 ------------------------------
243 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
244 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
247 -- Install formals and push subprogram spec onto scope stack so that we
248 -- can see the formals from the pragma.
253 -- Preanalyze the boolean expression, we treat this as a spec expression
254 -- (i.e. similar to a default expression).
256 Preanalyze_Spec_Expression
257 (Get_Pragma_Arg (Arg1), Standard_Boolean);
259 -- Remove the subprogram from the scope stack now that the pre-analysis
260 -- of the precondition/postcondition is done.
263 end Analyze_PPC_In_Decl_Part;
269 procedure Analyze_Pragma (N : Node_Id) is
270 Loc : constant Source_Ptr := Sloc (N);
271 Pname : constant Name_Id := Pragma_Name (N);
274 Pragma_Exit : exception;
275 -- This exception is used to exit pragma processing completely. It is
276 -- used when an error is detected, and no further processing is
277 -- required. It is also used if an earlier error has left the tree in
278 -- a state where the pragma should not be processed.
281 -- Number of pragma argument associations
287 -- First four pragma arguments (pragma argument association nodes, or
288 -- Empty if the corresponding argument does not exist).
290 type Name_List is array (Natural range <>) of Name_Id;
291 type Args_List is array (Natural range <>) of Node_Id;
292 -- Types used for arguments to Check_Arg_Order and Gather_Associations
294 procedure Ada_2005_Pragma;
295 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
296 -- Ada 95 mode, these are implementation defined pragmas, so should be
297 -- caught by the No_Implementation_Pragmas restriction.
299 procedure Ada_2012_Pragma;
300 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
301 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
302 -- should be caught by the No_Implementation_Pragmas restriction.
304 procedure Check_Ada_83_Warning;
305 -- Issues a warning message for the current pragma if operating in Ada
306 -- 83 mode (used for language pragmas that are not a standard part of
307 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
310 procedure Check_Arg_Count (Required : Nat);
311 -- Check argument count for pragma is equal to given parameter. If not,
312 -- then issue an error message and raise Pragma_Exit.
314 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
315 -- Arg which can either be a pragma argument association, in which case
316 -- the check is applied to the expression of the association or an
317 -- expression directly.
319 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
320 -- Check that an argument has the right form for an EXTERNAL_NAME
321 -- parameter of an extended import/export pragma. The rule is that the
322 -- name must be an identifier or string literal (in Ada 83 mode) or a
323 -- static string expression (in Ada 95 mode).
325 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
326 -- Check the specified argument Arg to make sure that it is an
327 -- identifier. If not give error and raise Pragma_Exit.
329 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
330 -- Check the specified argument Arg to make sure that it is an integer
331 -- literal. If not give error and raise Pragma_Exit.
333 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
334 -- Check the specified argument Arg to make sure that it has the proper
335 -- syntactic form for a local name and meets the semantic requirements
336 -- for a local name. The local name is analyzed as part of the
337 -- processing for this call. In addition, the local name is required
338 -- to represent an entity at the library level.
340 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
341 -- Check the specified argument Arg to make sure that it has the proper
342 -- syntactic form for a local name and meets the semantic requirements
343 -- for a local name. The local name is analyzed as part of the
344 -- processing for this call.
346 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
347 -- Check the specified argument Arg to make sure that it is a valid
348 -- locking policy name. If not give error and raise Pragma_Exit.
350 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
351 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
352 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
353 -- Check the specified argument Arg to make sure that it is an
354 -- identifier whose name matches either N1 or N2 (or N3 if present).
355 -- If not then give error and raise Pragma_Exit.
357 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
358 -- Check the specified argument Arg to make sure that it is a valid
359 -- queuing policy name. If not give error and raise Pragma_Exit.
361 procedure Check_Arg_Is_Static_Expression
363 Typ : Entity_Id := Empty);
364 -- Check the specified argument Arg to make sure that it is a static
365 -- expression of the given type (i.e. it will be analyzed and resolved
366 -- using this type, which can be any valid argument to Resolve, e.g.
367 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
368 -- Typ is left Empty, then any static expression is allowed.
370 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
371 -- Check the specified argument Arg to make sure that it is a valid task
372 -- dispatching policy name. If not give error and raise Pragma_Exit.
374 procedure Check_Arg_Order (Names : Name_List);
375 -- Checks for an instance of two arguments with identifiers for the
376 -- current pragma which are not in the sequence indicated by Names,
377 -- and if so, generates a fatal message about bad order of arguments.
379 procedure Check_At_Least_N_Arguments (N : Nat);
380 -- Check there are at least N arguments present
382 procedure Check_At_Most_N_Arguments (N : Nat);
383 -- Check there are no more than N arguments present
385 procedure Check_Component
388 In_Variant_Part : Boolean := False);
389 -- Examine an Unchecked_Union component for correct use of per-object
390 -- constrained subtypes, and for restrictions on finalizable components.
391 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
392 -- should be set when Comp comes from a record variant.
394 procedure Check_Duplicate_Pragma (E : Entity_Id);
395 -- Check if a pragma of the same name as the current pragma is already
396 -- chained as a rep pragma to the given entity. If so give a message
397 -- about the duplicate, and then raise Pragma_Exit so does not return.
398 -- Also checks for delayed aspect specification node in the chain.
400 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
401 -- Nam is an N_String_Literal node containing the external name set by
402 -- an Import or Export pragma (or extended Import or Export pragma).
403 -- This procedure checks for possible duplications if this is the export
404 -- case, and if found, issues an appropriate error message.
406 procedure Check_First_Subtype (Arg : Node_Id);
407 -- Checks that Arg, whose expression is an entity name, references a
410 procedure Check_In_Main_Program;
411 -- Common checks for pragmas that appear within a main program
412 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
414 procedure Check_Interrupt_Or_Attach_Handler;
415 -- Common processing for first argument of pragma Interrupt_Handler or
416 -- pragma Attach_Handler.
418 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
419 -- Check that pragma appears in a declarative part, or in a package
420 -- specification, i.e. that it does not occur in a statement sequence
423 procedure Check_No_Identifier (Arg : Node_Id);
424 -- Checks that the given argument does not have an identifier. If
425 -- an identifier is present, then an error message is issued, and
426 -- Pragma_Exit is raised.
428 procedure Check_No_Identifiers;
429 -- Checks that none of the arguments to the pragma has an identifier.
430 -- If any argument has an identifier, then an error message is issued,
431 -- and Pragma_Exit is raised.
433 procedure Check_No_Link_Name;
434 -- Checks that no link name is specified
436 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
437 -- Checks if the given argument has an identifier, and if so, requires
438 -- it to match the given identifier name. If there is a non-matching
439 -- identifier, then an error message is given and Error_Pragmas raised.
441 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
442 -- Checks if the given argument has an identifier, and if so, requires
443 -- it to match the given identifier name. If there is a non-matching
444 -- identifier, then an error message is given and Error_Pragmas raised.
445 -- In this version of the procedure, the identifier name is given as
446 -- a string with lower case letters.
448 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
449 -- Called to process a precondition or postcondition pragma. There are
452 -- The pragma appears after a subprogram spec
454 -- If the corresponding check is not enabled, the pragma is analyzed
455 -- but otherwise ignored and control returns with In_Body set False.
457 -- If the check is enabled, then the first step is to analyze the
458 -- pragma, but this is skipped if the subprogram spec appears within
459 -- a package specification (because this is the case where we delay
460 -- analysis till the end of the spec). Then (whether or not it was
461 -- analyzed), the pragma is chained to the subprogram in question
462 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
463 -- caller with In_Body set False.
465 -- The pragma appears at the start of subprogram body declarations
467 -- In this case an immediate return to the caller is made with
468 -- In_Body set True, and the pragma is NOT analyzed.
470 -- In all other cases, an error message for bad placement is given
472 procedure Check_Static_Constraint (Constr : Node_Id);
473 -- Constr is a constraint from an N_Subtype_Indication node from a
474 -- component constraint in an Unchecked_Union type. This routine checks
475 -- that the constraint is static as required by the restrictions for
478 procedure Check_Valid_Configuration_Pragma;
479 -- Legality checks for placement of a configuration pragma
481 procedure Check_Valid_Library_Unit_Pragma;
482 -- Legality checks for library unit pragmas. A special case arises for
483 -- pragmas in generic instances that come from copies of the original
484 -- library unit pragmas in the generic templates. In the case of other
485 -- than library level instantiations these can appear in contexts which
486 -- would normally be invalid (they only apply to the original template
487 -- and to library level instantiations), and they are simply ignored,
488 -- which is implemented by rewriting them as null statements.
490 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
491 -- Check an Unchecked_Union variant for lack of nested variants and
492 -- presence of at least one component. UU_Typ is the related Unchecked_
495 procedure Error_Pragma (Msg : String);
496 pragma No_Return (Error_Pragma);
497 -- Outputs error message for current pragma. The message contains a %
498 -- that will be replaced with the pragma name, and the flag is placed
499 -- on the pragma itself. Pragma_Exit is then raised.
501 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
502 pragma No_Return (Error_Pragma_Arg);
503 -- Outputs error message for current pragma. The message may contain
504 -- a % that will be replaced with the pragma name. The parameter Arg
505 -- may either be a pragma argument association, in which case the flag
506 -- is placed on the expression of this association, or an expression,
507 -- in which case the flag is placed directly on the expression. The
508 -- message is placed using Error_Msg_N, so the message may also contain
509 -- an & insertion character which will reference the given Arg value.
510 -- After placing the message, Pragma_Exit is raised.
512 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
513 pragma No_Return (Error_Pragma_Arg);
514 -- Similar to above form of Error_Pragma_Arg except that two messages
515 -- are provided, the second is a continuation comment starting with \.
517 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
518 pragma No_Return (Error_Pragma_Arg_Ident);
519 -- Outputs error message for current pragma. The message may contain
520 -- a % that will be replaced with the pragma name. The parameter Arg
521 -- must be a pragma argument association with a non-empty identifier
522 -- (i.e. its Chars field must be set), and the error message is placed
523 -- on the identifier. The message is placed using Error_Msg_N so
524 -- the message may also contain an & insertion character which will
525 -- reference the identifier. After placing the message, Pragma_Exit
528 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
529 pragma No_Return (Error_Pragma_Ref);
530 -- Outputs error message for current pragma. The message may contain
531 -- a % that will be replaced with the pragma name. The parameter Ref
532 -- must be an entity whose name can be referenced by & and sloc by #.
533 -- After placing the message, Pragma_Exit is raised.
535 function Find_Lib_Unit_Name return Entity_Id;
536 -- Used for a library unit pragma to find the entity to which the
537 -- library unit pragma applies, returns the entity found.
539 procedure Find_Program_Unit_Name (Id : Node_Id);
540 -- If the pragma is a compilation unit pragma, the id must denote the
541 -- compilation unit in the same compilation, and the pragma must appear
542 -- in the list of preceding or trailing pragmas. If it is a program
543 -- unit pragma that is not a compilation unit pragma, then the
544 -- identifier must be visible.
546 function Find_Unique_Parameterless_Procedure
548 Arg : Node_Id) return Entity_Id;
549 -- Used for a procedure pragma to find the unique parameterless
550 -- procedure identified by Name, returns it if it exists, otherwise
551 -- errors out and uses Arg as the pragma argument for the message.
553 procedure Fix_Error (Msg : in out String);
554 -- This is called prior to issuing an error message. Msg is a string
555 -- which typically contains the substring pragma. If the current pragma
556 -- comes from an aspect, each such "pragma" substring is replaced with
557 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
558 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
560 procedure Gather_Associations
562 Args : out Args_List);
563 -- This procedure is used to gather the arguments for a pragma that
564 -- permits arbitrary ordering of parameters using the normal rules
565 -- for named and positional parameters. The Names argument is a list
566 -- of Name_Id values that corresponds to the allowed pragma argument
567 -- association identifiers in order. The result returned in Args is
568 -- a list of corresponding expressions that are the pragma arguments.
569 -- Note that this is a list of expressions, not of pragma argument
570 -- associations (Gather_Associations has completely checked all the
571 -- optional identifiers when it returns). An entry in Args is Empty
572 -- on return if the corresponding argument is not present.
574 procedure GNAT_Pragma;
575 -- Called for all GNAT defined pragmas to check the relevant restriction
576 -- (No_Implementation_Pragmas).
578 function Is_Before_First_Decl
579 (Pragma_Node : Node_Id;
580 Decls : List_Id) return Boolean;
581 -- Return True if Pragma_Node is before the first declarative item in
582 -- Decls where Decls is the list of declarative items.
584 function Is_Configuration_Pragma return Boolean;
585 -- Determines if the placement of the current pragma is appropriate
586 -- for a configuration pragma.
588 function Is_In_Context_Clause return Boolean;
589 -- Returns True if pragma appears within the context clause of a unit,
590 -- and False for any other placement (does not generate any messages).
592 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
593 -- Analyzes the argument, and determines if it is a static string
594 -- expression, returns True if so, False if non-static or not String.
596 procedure Pragma_Misplaced;
597 pragma No_Return (Pragma_Misplaced);
598 -- Issue fatal error message for misplaced pragma
600 procedure Process_Atomic_Shared_Volatile;
601 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
602 -- Shared is an obsolete Ada 83 pragma, treated as being identical
603 -- in effect to pragma Atomic.
605 procedure Process_Compile_Time_Warning_Or_Error;
606 -- Common processing for Compile_Time_Error and Compile_Time_Warning
608 procedure Process_Convention
609 (C : out Convention_Id;
610 Ent : out Entity_Id);
611 -- Common processing for Convention, Interface, Import and Export.
612 -- Checks first two arguments of pragma, and sets the appropriate
613 -- convention value in the specified entity or entities. On return
614 -- C is the convention, Ent is the referenced entity.
616 procedure Process_Extended_Import_Export_Exception_Pragma
617 (Arg_Internal : Node_Id;
618 Arg_External : Node_Id;
621 -- Common processing for the pragmas Import/Export_Exception. The three
622 -- arguments correspond to the three named parameters of the pragma. An
623 -- argument is empty if the corresponding parameter is not present in
626 procedure Process_Extended_Import_Export_Object_Pragma
627 (Arg_Internal : Node_Id;
628 Arg_External : Node_Id;
630 -- Common processing for the pragmas Import/Export_Object. The three
631 -- arguments correspond to the three named parameters of the pragmas. An
632 -- argument is empty if the corresponding parameter is not present in
635 procedure Process_Extended_Import_Export_Internal_Arg
636 (Arg_Internal : Node_Id := Empty);
637 -- Common processing for all extended Import and Export pragmas. The
638 -- argument is the pragma parameter for the Internal argument. If
639 -- Arg_Internal is empty or inappropriate, an error message is posted.
640 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
641 -- set to identify the referenced entity.
643 procedure Process_Extended_Import_Export_Subprogram_Pragma
644 (Arg_Internal : Node_Id;
645 Arg_External : Node_Id;
646 Arg_Parameter_Types : Node_Id;
647 Arg_Result_Type : Node_Id := Empty;
648 Arg_Mechanism : Node_Id;
649 Arg_Result_Mechanism : Node_Id := Empty;
650 Arg_First_Optional_Parameter : Node_Id := Empty);
651 -- Common processing for all extended Import and Export pragmas applying
652 -- to subprograms. The caller omits any arguments that do not apply to
653 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
654 -- only in the Import_Function and Export_Function cases). The argument
655 -- names correspond to the allowed pragma association identifiers.
657 procedure Process_Generic_List;
658 -- Common processing for Share_Generic and Inline_Generic
660 procedure Process_Import_Or_Interface;
661 -- Common processing for Import of Interface
663 procedure Process_Import_Predefined_Type;
664 -- Processing for completing a type with pragma Import. This is used
665 -- to declare types that match predefined C types, especially for cases
666 -- without corresponding Ada predefined type.
668 procedure Process_Inline (Active : Boolean);
669 -- Common processing for Inline and Inline_Always. The parameter
670 -- indicates if the inline pragma is active, i.e. if it should actually
671 -- cause inlining to occur.
673 procedure Process_Interface_Name
674 (Subprogram_Def : Entity_Id;
677 -- Given the last two arguments of pragma Import, pragma Export, or
678 -- pragma Interface_Name, performs validity checks and sets the
679 -- Interface_Name field of the given subprogram entity to the
680 -- appropriate external or link name, depending on the arguments given.
681 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
682 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
683 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
684 -- nor Link_Arg is present, the interface name is set to the default
685 -- from the subprogram name.
687 procedure Process_Interrupt_Or_Attach_Handler;
688 -- Common processing for Interrupt and Attach_Handler pragmas
690 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
691 -- Common processing for Restrictions and Restriction_Warnings pragmas.
692 -- Warn is True for Restriction_Warnings, or for Restrictions if the
693 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
694 -- is not set in the Restrictions case.
696 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
697 -- Common processing for Suppress and Unsuppress. The boolean parameter
698 -- Suppress_Case is True for the Suppress case, and False for the
701 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
702 -- This procedure sets the Is_Exported flag for the given entity,
703 -- checking that the entity was not previously imported. Arg is
704 -- the argument that specified the entity. A check is also made
705 -- for exporting inappropriate entities.
707 procedure Set_Extended_Import_Export_External_Name
708 (Internal_Ent : Entity_Id;
709 Arg_External : Node_Id);
710 -- Common processing for all extended import export pragmas. The first
711 -- argument, Internal_Ent, is the internal entity, which has already
712 -- been checked for validity by the caller. Arg_External is from the
713 -- Import or Export pragma, and may be null if no External parameter
714 -- was present. If Arg_External is present and is a non-null string
715 -- (a null string is treated as the default), then the Interface_Name
716 -- field of Internal_Ent is set appropriately.
718 procedure Set_Imported (E : Entity_Id);
719 -- This procedure sets the Is_Imported flag for the given entity,
720 -- checking that it is not previously exported or imported.
722 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
723 -- Mech is a parameter passing mechanism (see Import_Function syntax
724 -- for MECHANISM_NAME). This routine checks that the mechanism argument
725 -- has the right form, and if not issues an error message. If the
726 -- argument has the right form then the Mechanism field of Ent is
727 -- set appropriately.
729 procedure Set_Ravenscar_Profile (N : Node_Id);
730 -- Activate the set of configuration pragmas and restrictions that make
731 -- up the Ravenscar Profile. N is the corresponding pragma node, which
732 -- is used for error messages on any constructs that violate the
735 ---------------------
736 -- Ada_2005_Pragma --
737 ---------------------
739 procedure Ada_2005_Pragma is
741 if Ada_Version <= Ada_95 then
742 Check_Restriction (No_Implementation_Pragmas, N);
746 ---------------------
747 -- Ada_2012_Pragma --
748 ---------------------
750 procedure Ada_2012_Pragma is
752 if Ada_Version <= Ada_2005 then
753 Check_Restriction (No_Implementation_Pragmas, N);
757 --------------------------
758 -- Check_Ada_83_Warning --
759 --------------------------
761 procedure Check_Ada_83_Warning is
763 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
764 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
766 end Check_Ada_83_Warning;
768 ---------------------
769 -- Check_Arg_Count --
770 ---------------------
772 procedure Check_Arg_Count (Required : Nat) is
774 if Arg_Count /= Required then
775 Error_Pragma ("wrong number of arguments for pragma%");
779 --------------------------------
780 -- Check_Arg_Is_External_Name --
781 --------------------------------
783 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
784 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
787 if Nkind (Argx) = N_Identifier then
791 Analyze_And_Resolve (Argx, Standard_String);
793 if Is_OK_Static_Expression (Argx) then
796 elsif Etype (Argx) = Any_Type then
799 -- An interesting special case, if we have a string literal and
800 -- we are in Ada 83 mode, then we allow it even though it will
801 -- not be flagged as static. This allows expected Ada 83 mode
802 -- use of external names which are string literals, even though
803 -- technically these are not static in Ada 83.
805 elsif Ada_Version = Ada_83
806 and then Nkind (Argx) = N_String_Literal
810 -- Static expression that raises Constraint_Error. This has
811 -- already been flagged, so just exit from pragma processing.
813 elsif Is_Static_Expression (Argx) then
816 -- Here we have a real error (non-static expression)
819 Error_Msg_Name_1 := Pname;
823 "argument for pragma% must be a identifier or "
824 & "static string expression!";
827 Flag_Non_Static_Expr (Msg, Argx);
832 end Check_Arg_Is_External_Name;
834 -----------------------------
835 -- Check_Arg_Is_Identifier --
836 -----------------------------
838 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
839 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
841 if Nkind (Argx) /= N_Identifier then
843 ("argument for pragma% must be identifier", Argx);
845 end Check_Arg_Is_Identifier;
847 ----------------------------------
848 -- Check_Arg_Is_Integer_Literal --
849 ----------------------------------
851 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
852 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
854 if Nkind (Argx) /= N_Integer_Literal then
856 ("argument for pragma% must be integer literal", Argx);
858 end Check_Arg_Is_Integer_Literal;
860 -------------------------------------------
861 -- Check_Arg_Is_Library_Level_Local_Name --
862 -------------------------------------------
866 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
867 -- | library_unit_NAME
869 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
871 Check_Arg_Is_Local_Name (Arg);
873 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
874 and then Comes_From_Source (N)
877 ("argument for pragma% must be library level entity", Arg);
879 end Check_Arg_Is_Library_Level_Local_Name;
881 -----------------------------
882 -- Check_Arg_Is_Local_Name --
883 -----------------------------
887 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
888 -- | library_unit_NAME
890 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
891 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
896 if Nkind (Argx) not in N_Direct_Name
897 and then (Nkind (Argx) /= N_Attribute_Reference
898 or else Present (Expressions (Argx))
899 or else Nkind (Prefix (Argx)) /= N_Identifier)
900 and then (not Is_Entity_Name (Argx)
901 or else not Is_Compilation_Unit (Entity (Argx)))
903 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
906 -- No further check required if not an entity name
908 if not Is_Entity_Name (Argx) then
914 Ent : constant Entity_Id := Entity (Argx);
915 Scop : constant Entity_Id := Scope (Ent);
917 -- Case of a pragma applied to a compilation unit: pragma must
918 -- occur immediately after the program unit in the compilation.
920 if Is_Compilation_Unit (Ent) then
922 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
924 -- Case of pragma placed immediately after spec
926 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
929 -- Case of pragma placed immediately after body
931 elsif Nkind (Decl) = N_Subprogram_Declaration
932 and then Present (Corresponding_Body (Decl))
936 (Parent (Unit_Declaration_Node
937 (Corresponding_Body (Decl))));
939 -- All other cases are illegal
946 -- Special restricted placement rule from 10.2.1(11.8/2)
948 elsif Is_Generic_Formal (Ent)
949 and then Prag_Id = Pragma_Preelaborable_Initialization
951 OK := List_Containing (N) =
952 Generic_Formal_Declarations
953 (Unit_Declaration_Node (Scop));
955 -- Default case, just check that the pragma occurs in the scope
956 -- of the entity denoted by the name.
959 OK := Current_Scope = Scop;
964 ("pragma% argument must be in same declarative part", Arg);
968 end Check_Arg_Is_Local_Name;
970 ---------------------------------
971 -- Check_Arg_Is_Locking_Policy --
972 ---------------------------------
974 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
975 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
978 Check_Arg_Is_Identifier (Argx);
980 if not Is_Locking_Policy_Name (Chars (Argx)) then
981 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
983 end Check_Arg_Is_Locking_Policy;
985 -------------------------
986 -- Check_Arg_Is_One_Of --
987 -------------------------
989 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
990 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
993 Check_Arg_Is_Identifier (Argx);
995 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
996 Error_Msg_Name_2 := N1;
997 Error_Msg_Name_3 := N2;
998 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1000 end Check_Arg_Is_One_Of;
1002 procedure Check_Arg_Is_One_Of
1004 N1, N2, N3 : Name_Id)
1006 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1009 Check_Arg_Is_Identifier (Argx);
1011 if Chars (Argx) /= N1
1012 and then Chars (Argx) /= N2
1013 and then Chars (Argx) /= N3
1015 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1017 end Check_Arg_Is_One_Of;
1019 procedure Check_Arg_Is_One_Of
1021 N1, N2, N3, N4 : Name_Id)
1023 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1026 Check_Arg_Is_Identifier (Argx);
1028 if Chars (Argx) /= N1
1029 and then Chars (Argx) /= N2
1030 and then Chars (Argx) /= N3
1031 and then Chars (Argx) /= N4
1033 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1035 end Check_Arg_Is_One_Of;
1036 ---------------------------------
1037 -- Check_Arg_Is_Queuing_Policy --
1038 ---------------------------------
1040 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1041 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1044 Check_Arg_Is_Identifier (Argx);
1046 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1047 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1049 end Check_Arg_Is_Queuing_Policy;
1051 ------------------------------------
1052 -- Check_Arg_Is_Static_Expression --
1053 ------------------------------------
1055 procedure Check_Arg_Is_Static_Expression
1057 Typ : Entity_Id := Empty)
1059 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1062 if Present (Typ) then
1063 Analyze_And_Resolve (Argx, Typ);
1065 Analyze_And_Resolve (Argx);
1068 if Is_OK_Static_Expression (Argx) then
1071 elsif Etype (Argx) = Any_Type then
1074 -- An interesting special case, if we have a string literal and we
1075 -- are in Ada 83 mode, then we allow it even though it will not be
1076 -- flagged as static. This allows the use of Ada 95 pragmas like
1077 -- Import in Ada 83 mode. They will of course be flagged with
1078 -- warnings as usual, but will not cause errors.
1080 elsif Ada_Version = Ada_83
1081 and then Nkind (Argx) = N_String_Literal
1085 -- Static expression that raises Constraint_Error. This has already
1086 -- been flagged, so just exit from pragma processing.
1088 elsif Is_Static_Expression (Argx) then
1091 -- Finally, we have a real error
1094 Error_Msg_Name_1 := Pname;
1098 "argument for pragma% must be a static expression!";
1101 Flag_Non_Static_Expr (Msg, Argx);
1106 end Check_Arg_Is_Static_Expression;
1108 ------------------------------------------
1109 -- Check_Arg_Is_Task_Dispatching_Policy --
1110 ------------------------------------------
1112 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1113 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1116 Check_Arg_Is_Identifier (Argx);
1118 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1120 ("& is not a valid task dispatching policy name", Argx);
1122 end Check_Arg_Is_Task_Dispatching_Policy;
1124 ---------------------
1125 -- Check_Arg_Order --
1126 ---------------------
1128 procedure Check_Arg_Order (Names : Name_List) is
1131 Highest_So_Far : Natural := 0;
1132 -- Highest index in Names seen do far
1136 for J in 1 .. Arg_Count loop
1137 if Chars (Arg) /= No_Name then
1138 for K in Names'Range loop
1139 if Chars (Arg) = Names (K) then
1140 if K < Highest_So_Far then
1141 Error_Msg_Name_1 := Pname;
1143 ("parameters out of order for pragma%", Arg);
1144 Error_Msg_Name_1 := Names (K);
1145 Error_Msg_Name_2 := Names (Highest_So_Far);
1146 Error_Msg_N ("\% must appear before %", Arg);
1150 Highest_So_Far := K;
1158 end Check_Arg_Order;
1160 --------------------------------
1161 -- Check_At_Least_N_Arguments --
1162 --------------------------------
1164 procedure Check_At_Least_N_Arguments (N : Nat) is
1166 if Arg_Count < N then
1167 Error_Pragma ("too few arguments for pragma%");
1169 end Check_At_Least_N_Arguments;
1171 -------------------------------
1172 -- Check_At_Most_N_Arguments --
1173 -------------------------------
1175 procedure Check_At_Most_N_Arguments (N : Nat) is
1178 if Arg_Count > N then
1180 for J in 1 .. N loop
1182 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1185 end Check_At_Most_N_Arguments;
1187 ---------------------
1188 -- Check_Component --
1189 ---------------------
1191 procedure Check_Component
1194 In_Variant_Part : Boolean := False)
1196 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1197 Sindic : constant Node_Id :=
1198 Subtype_Indication (Component_Definition (Comp));
1199 Typ : constant Entity_Id := Etype (Comp_Id);
1201 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1202 -- Determine whether entity Id appears inside a generic body.
1203 -- Shouldn't this be in a more general place ???
1205 -------------------------
1206 -- Inside_Generic_Body --
1207 -------------------------
1209 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1214 while Present (S) and then S /= Standard_Standard loop
1215 if Ekind (S) = E_Generic_Package
1216 and then In_Package_Body (S)
1225 end Inside_Generic_Body;
1227 -- Start of processing for Check_Component
1230 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1231 -- object constraint, then the component type shall be an Unchecked_
1234 if Nkind (Sindic) = N_Subtype_Indication
1235 and then Has_Per_Object_Constraint (Comp_Id)
1236 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1239 ("component subtype subject to per-object constraint " &
1240 "must be an Unchecked_Union", Comp);
1242 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1243 -- the body of a generic unit, or within the body of any of its
1244 -- descendant library units, no part of the type of a component
1245 -- declared in a variant_part of the unchecked union type shall be of
1246 -- a formal private type or formal private extension declared within
1247 -- the formal part of the generic unit.
1249 elsif Ada_Version >= Ada_2012
1250 and then Inside_Generic_Body (UU_Typ)
1251 and then In_Variant_Part
1252 and then Is_Private_Type (Typ)
1253 and then Is_Generic_Type (Typ)
1256 ("component of Unchecked_Union cannot be of generic type", Comp);
1258 elsif Needs_Finalization (Typ) then
1260 ("component of Unchecked_Union cannot be controlled", Comp);
1262 elsif Has_Task (Typ) then
1264 ("component of Unchecked_Union cannot have tasks", Comp);
1266 end Check_Component;
1268 ----------------------------
1269 -- Check_Duplicate_Pragma --
1270 ----------------------------
1272 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1276 -- Nothing to do if this pragma comes from an aspect specification,
1277 -- since we could not be duplicating a pragma, and we dealt with the
1278 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1280 if From_Aspect_Specification (N) then
1284 -- Otherwise current pragma may duplicate previous pragma or a
1285 -- previously given aspect specification for the same pragma.
1287 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1290 Error_Msg_Name_1 := Pragma_Name (N);
1291 Error_Msg_Sloc := Sloc (P);
1293 if Nkind (P) = N_Aspect_Specification
1294 or else From_Aspect_Specification (P)
1296 Error_Msg_NE ("aspect% for & previously given#", N, E);
1298 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1303 end Check_Duplicate_Pragma;
1305 ----------------------------------
1306 -- Check_Duplicated_Export_Name --
1307 ----------------------------------
1309 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1310 String_Val : constant String_Id := Strval (Nam);
1313 -- We are only interested in the export case, and in the case of
1314 -- generics, it is the instance, not the template, that is the
1315 -- problem (the template will generate a warning in any case).
1317 if not Inside_A_Generic
1318 and then (Prag_Id = Pragma_Export
1320 Prag_Id = Pragma_Export_Procedure
1322 Prag_Id = Pragma_Export_Valued_Procedure
1324 Prag_Id = Pragma_Export_Function)
1326 for J in Externals.First .. Externals.Last loop
1327 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1328 Error_Msg_Sloc := Sloc (Externals.Table (J));
1329 Error_Msg_N ("external name duplicates name given#", Nam);
1334 Externals.Append (Nam);
1336 end Check_Duplicated_Export_Name;
1338 -------------------------
1339 -- Check_First_Subtype --
1340 -------------------------
1342 procedure Check_First_Subtype (Arg : Node_Id) is
1343 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1344 Ent : constant Entity_Id := Entity (Argx);
1347 if Is_First_Subtype (Ent) then
1350 elsif Is_Type (Ent) then
1352 ("pragma% cannot apply to subtype", Argx);
1354 elsif Is_Object (Ent) then
1356 ("pragma% cannot apply to object, requires a type", Argx);
1360 ("pragma% cannot apply to&, requires a type", Argx);
1362 end Check_First_Subtype;
1364 ---------------------------
1365 -- Check_In_Main_Program --
1366 ---------------------------
1368 procedure Check_In_Main_Program is
1369 P : constant Node_Id := Parent (N);
1372 -- Must be at in subprogram body
1374 if Nkind (P) /= N_Subprogram_Body then
1375 Error_Pragma ("% pragma allowed only in subprogram");
1377 -- Otherwise warn if obviously not main program
1379 elsif Present (Parameter_Specifications (Specification (P)))
1380 or else not Is_Compilation_Unit (Defining_Entity (P))
1382 Error_Msg_Name_1 := Pname;
1384 ("?pragma% is only effective in main program", N);
1386 end Check_In_Main_Program;
1388 ---------------------------------------
1389 -- Check_Interrupt_Or_Attach_Handler --
1390 ---------------------------------------
1392 procedure Check_Interrupt_Or_Attach_Handler is
1393 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1394 Handler_Proc, Proc_Scope : Entity_Id;
1399 if Prag_Id = Pragma_Interrupt_Handler then
1400 Check_Restriction (No_Dynamic_Attachment, N);
1403 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1404 Proc_Scope := Scope (Handler_Proc);
1406 -- On AAMP only, a pragma Interrupt_Handler is supported for
1407 -- nonprotected parameterless procedures.
1409 if not AAMP_On_Target
1410 or else Prag_Id = Pragma_Attach_Handler
1412 if Ekind (Proc_Scope) /= E_Protected_Type then
1414 ("argument of pragma% must be protected procedure", Arg1);
1417 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1418 Error_Pragma ("pragma% must be in protected definition");
1422 if not Is_Library_Level_Entity (Proc_Scope)
1423 or else (AAMP_On_Target
1424 and then not Is_Library_Level_Entity (Handler_Proc))
1427 ("argument for pragma% must be library level entity", Arg1);
1430 -- AI05-0033: A pragma cannot appear within a generic body, because
1431 -- instance can be in a nested scope. The check that protected type
1432 -- is itself a library-level declaration is done elsewhere.
1434 -- Note: we omit this check in Codepeer mode to properly handle code
1435 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1437 if Inside_A_Generic then
1438 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1439 and then In_Package_Body (Scope (Current_Scope))
1440 and then not CodePeer_Mode
1442 Error_Pragma ("pragma% cannot be used inside a generic");
1445 end Check_Interrupt_Or_Attach_Handler;
1447 -------------------------------------------
1448 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1449 -------------------------------------------
1451 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1460 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1463 elsif Nkind_In (P, N_Package_Specification,
1468 -- Note: the following tests seem a little peculiar, because
1469 -- they test for bodies, but if we were in the statement part
1470 -- of the body, we would already have hit the handled statement
1471 -- sequence, so the only way we get here is by being in the
1472 -- declarative part of the body.
1474 elsif Nkind_In (P, N_Subprogram_Body,
1485 Error_Pragma ("pragma% is not in declarative part or package spec");
1486 end Check_Is_In_Decl_Part_Or_Package_Spec;
1488 -------------------------
1489 -- Check_No_Identifier --
1490 -------------------------
1492 procedure Check_No_Identifier (Arg : Node_Id) is
1494 if Nkind (Arg) = N_Pragma_Argument_Association
1495 and then Chars (Arg) /= No_Name
1497 Error_Pragma_Arg_Ident
1498 ("pragma% does not permit identifier& here", Arg);
1500 end Check_No_Identifier;
1502 --------------------------
1503 -- Check_No_Identifiers --
1504 --------------------------
1506 procedure Check_No_Identifiers is
1509 if Arg_Count > 0 then
1511 while Present (Arg_Node) loop
1512 Check_No_Identifier (Arg_Node);
1516 end Check_No_Identifiers;
1518 ------------------------
1519 -- Check_No_Link_Name --
1520 ------------------------
1522 procedure Check_No_Link_Name is
1525 and then Chars (Arg3) = Name_Link_Name
1530 if Present (Arg4) then
1532 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1534 end Check_No_Link_Name;
1536 -------------------------------
1537 -- Check_Optional_Identifier --
1538 -------------------------------
1540 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1543 and then Nkind (Arg) = N_Pragma_Argument_Association
1544 and then Chars (Arg) /= No_Name
1546 if Chars (Arg) /= Id then
1547 Error_Msg_Name_1 := Pname;
1548 Error_Msg_Name_2 := Id;
1549 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1553 end Check_Optional_Identifier;
1555 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1557 Name_Buffer (1 .. Id'Length) := Id;
1558 Name_Len := Id'Length;
1559 Check_Optional_Identifier (Arg, Name_Find);
1560 end Check_Optional_Identifier;
1562 --------------------------------------
1563 -- Check_Precondition_Postcondition --
1564 --------------------------------------
1566 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1570 procedure Chain_PPC (PO : Node_Id);
1571 -- If PO is a subprogram declaration node (or a generic subprogram
1572 -- declaration node), then the precondition/postcondition applies
1573 -- to this subprogram and the processing for the pragma is completed.
1574 -- Otherwise the pragma is misplaced.
1580 procedure Chain_PPC (PO : Node_Id) is
1585 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1586 if not From_Aspect_Specification (N) then
1588 ("pragma% cannot be applied to abstract subprogram");
1590 elsif Class_Present (N) then
1595 ("aspect % requires ''Class for abstract subprogram");
1598 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1599 N_Generic_Subprogram_Declaration,
1600 N_Entry_Declaration)
1605 -- Here if we have [generic] subprogram or entry declaration
1607 if Nkind (PO) = N_Entry_Declaration then
1608 S := Defining_Entity (PO);
1610 S := Defining_Unit_Name (Specification (PO));
1613 -- Make sure we do not have the case of a precondition pragma when
1614 -- the Pre'Class aspect is present.
1616 -- We do this by looking at pragmas already chained to the entity
1617 -- since the aspect derived pragma will be put on this list first.
1619 if Pragma_Name (N) = Name_Precondition then
1620 if not From_Aspect_Specification (N) then
1621 P := Spec_PPC_List (S);
1622 while Present (P) loop
1623 if Pragma_Name (P) = Name_Precondition
1624 and then From_Aspect_Specification (P)
1625 and then Class_Present (P)
1627 Error_Msg_Sloc := Sloc (P);
1629 ("pragma% not allowed, `Pre''Class` aspect given#");
1632 P := Next_Pragma (P);
1637 -- Similarly check for Pre with inherited Pre'Class. Note that
1638 -- we cover the aspect case as well here.
1640 if Pragma_Name (N) = Name_Precondition
1641 and then not Class_Present (N)
1644 Inherited : constant Subprogram_List :=
1645 Inherited_Subprograms (S);
1649 for J in Inherited'Range loop
1650 P := Spec_PPC_List (Inherited (J));
1651 while Present (P) loop
1652 if Pragma_Name (P) = Name_Precondition
1653 and then Class_Present (P)
1655 Error_Msg_Sloc := Sloc (P);
1657 ("pragma% not allowed, `Pre''Class` "
1658 & "aspect inherited from#");
1661 P := Next_Pragma (P);
1667 -- Note: we do not analyze the pragma at this point. Instead we
1668 -- delay this analysis until the end of the declarative part in
1669 -- which the pragma appears. This implements the required delay
1670 -- in this analysis, allowing forward references. The analysis
1671 -- happens at the end of Analyze_Declarations.
1673 -- Chain spec PPC pragma to list for subprogram
1675 Set_Next_Pragma (N, Spec_PPC_List (S));
1676 Set_Spec_PPC_List (S, N);
1678 -- Return indicating spec case
1684 -- Start of processing for Check_Precondition_Postcondition
1687 if not Is_List_Member (N) then
1691 -- Preanalyze message argument if present. Visibility in this
1692 -- argument is established at the point of pragma occurrence.
1694 if Arg_Count = 2 then
1695 Check_Optional_Identifier (Arg2, Name_Message);
1696 Preanalyze_Spec_Expression
1697 (Get_Pragma_Arg (Arg2), Standard_String);
1700 -- Record if pragma is enabled
1702 if Check_Enabled (Pname) then
1703 Set_Pragma_Enabled (N);
1704 Set_SCO_Pragma_Enabled (Loc);
1707 -- If we are within an inlined body, the legality of the pragma
1708 -- has been checked already.
1710 if In_Inlined_Body then
1715 -- Search prior declarations
1718 while Present (Prev (P)) loop
1721 -- If the previous node is a generic subprogram, do not go to to
1722 -- the original node, which is the unanalyzed tree: we need to
1723 -- attach the pre/postconditions to the analyzed version at this
1724 -- point. They get propagated to the original tree when analyzing
1725 -- the corresponding body.
1727 if Nkind (P) not in N_Generic_Declaration then
1728 PO := Original_Node (P);
1733 -- Skip past prior pragma
1735 if Nkind (PO) = N_Pragma then
1738 -- Skip stuff not coming from source
1740 elsif not Comes_From_Source (PO) then
1743 -- Only remaining possibility is subprogram declaration
1751 -- If we fall through loop, pragma is at start of list, so see if it
1752 -- is at the start of declarations of a subprogram body.
1754 if Nkind (Parent (N)) = N_Subprogram_Body
1755 and then List_Containing (N) = Declarations (Parent (N))
1757 if Operating_Mode /= Generate_Code
1758 or else Inside_A_Generic
1760 -- Analyze pragma expression for correctness and for ASIS use
1762 Preanalyze_Spec_Expression
1763 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1769 -- See if it is in the pragmas after a library level subprogram
1771 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1772 Chain_PPC (Unit (Parent (Parent (N))));
1776 -- If we fall through, pragma was misplaced
1779 end Check_Precondition_Postcondition;
1781 -----------------------------
1782 -- Check_Static_Constraint --
1783 -----------------------------
1785 -- Note: for convenience in writing this procedure, in addition to
1786 -- the officially (i.e. by spec) allowed argument which is always a
1787 -- constraint, it also allows ranges and discriminant associations.
1788 -- Above is not clear ???
1790 procedure Check_Static_Constraint (Constr : Node_Id) is
1792 procedure Require_Static (E : Node_Id);
1793 -- Require given expression to be static expression
1795 --------------------
1796 -- Require_Static --
1797 --------------------
1799 procedure Require_Static (E : Node_Id) is
1801 if not Is_OK_Static_Expression (E) then
1802 Flag_Non_Static_Expr
1803 ("non-static constraint not allowed in Unchecked_Union!", E);
1808 -- Start of processing for Check_Static_Constraint
1811 case Nkind (Constr) is
1812 when N_Discriminant_Association =>
1813 Require_Static (Expression (Constr));
1816 Require_Static (Low_Bound (Constr));
1817 Require_Static (High_Bound (Constr));
1819 when N_Attribute_Reference =>
1820 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1821 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1823 when N_Range_Constraint =>
1824 Check_Static_Constraint (Range_Expression (Constr));
1826 when N_Index_Or_Discriminant_Constraint =>
1830 IDC := First (Constraints (Constr));
1831 while Present (IDC) loop
1832 Check_Static_Constraint (IDC);
1840 end Check_Static_Constraint;
1842 --------------------------------------
1843 -- Check_Valid_Configuration_Pragma --
1844 --------------------------------------
1846 -- A configuration pragma must appear in the context clause of a
1847 -- compilation unit, and only other pragmas may precede it. Note that
1848 -- the test also allows use in a configuration pragma file.
1850 procedure Check_Valid_Configuration_Pragma is
1852 if not Is_Configuration_Pragma then
1853 Error_Pragma ("incorrect placement for configuration pragma%");
1855 end Check_Valid_Configuration_Pragma;
1857 -------------------------------------
1858 -- Check_Valid_Library_Unit_Pragma --
1859 -------------------------------------
1861 procedure Check_Valid_Library_Unit_Pragma is
1863 Parent_Node : Node_Id;
1864 Unit_Name : Entity_Id;
1865 Unit_Kind : Node_Kind;
1866 Unit_Node : Node_Id;
1867 Sindex : Source_File_Index;
1870 if not Is_List_Member (N) then
1874 Plist := List_Containing (N);
1875 Parent_Node := Parent (Plist);
1877 if Parent_Node = Empty then
1880 -- Case of pragma appearing after a compilation unit. In this case
1881 -- it must have an argument with the corresponding name and must
1882 -- be part of the following pragmas of its parent.
1884 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1885 if Plist /= Pragmas_After (Parent_Node) then
1888 elsif Arg_Count = 0 then
1890 ("argument required if outside compilation unit");
1893 Check_No_Identifiers;
1894 Check_Arg_Count (1);
1895 Unit_Node := Unit (Parent (Parent_Node));
1896 Unit_Kind := Nkind (Unit_Node);
1898 Analyze (Get_Pragma_Arg (Arg1));
1900 if Unit_Kind = N_Generic_Subprogram_Declaration
1901 or else Unit_Kind = N_Subprogram_Declaration
1903 Unit_Name := Defining_Entity (Unit_Node);
1905 elsif Unit_Kind in N_Generic_Instantiation then
1906 Unit_Name := Defining_Entity (Unit_Node);
1909 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1912 if Chars (Unit_Name) /=
1913 Chars (Entity (Get_Pragma_Arg (Arg1)))
1916 ("pragma% argument is not current unit name", Arg1);
1919 if Ekind (Unit_Name) = E_Package
1920 and then Present (Renamed_Entity (Unit_Name))
1922 Error_Pragma ("pragma% not allowed for renamed package");
1926 -- Pragma appears other than after a compilation unit
1929 -- Here we check for the generic instantiation case and also
1930 -- for the case of processing a generic formal package. We
1931 -- detect these cases by noting that the Sloc on the node
1932 -- does not belong to the current compilation unit.
1934 Sindex := Source_Index (Current_Sem_Unit);
1936 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1937 Rewrite (N, Make_Null_Statement (Loc));
1940 -- If before first declaration, the pragma applies to the
1941 -- enclosing unit, and the name if present must be this name.
1943 elsif Is_Before_First_Decl (N, Plist) then
1944 Unit_Node := Unit_Declaration_Node (Current_Scope);
1945 Unit_Kind := Nkind (Unit_Node);
1947 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1950 elsif Unit_Kind = N_Subprogram_Body
1951 and then not Acts_As_Spec (Unit_Node)
1955 elsif Nkind (Parent_Node) = N_Package_Body then
1958 elsif Nkind (Parent_Node) = N_Package_Specification
1959 and then Plist = Private_Declarations (Parent_Node)
1963 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1964 or else Nkind (Parent_Node) =
1965 N_Generic_Subprogram_Declaration)
1966 and then Plist = Generic_Formal_Declarations (Parent_Node)
1970 elsif Arg_Count > 0 then
1971 Analyze (Get_Pragma_Arg (Arg1));
1973 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
1975 ("name in pragma% must be enclosing unit", Arg1);
1978 -- It is legal to have no argument in this context
1984 -- Error if not before first declaration. This is because a
1985 -- library unit pragma argument must be the name of a library
1986 -- unit (RM 10.1.5(7)), but the only names permitted in this
1987 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1988 -- generic subprogram declarations or generic instantiations.
1992 ("pragma% misplaced, must be before first declaration");
1996 end Check_Valid_Library_Unit_Pragma;
2002 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2003 Clist : constant Node_Id := Component_List (Variant);
2007 if not Is_Non_Empty_List (Component_Items (Clist)) then
2009 ("Unchecked_Union may not have empty component list",
2014 Comp := First (Component_Items (Clist));
2015 while Present (Comp) loop
2016 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2025 procedure Error_Pragma (Msg : String) is
2026 MsgF : String := Msg;
2028 Error_Msg_Name_1 := Pname;
2030 Error_Msg_N (MsgF, N);
2034 ----------------------
2035 -- Error_Pragma_Arg --
2036 ----------------------
2038 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2039 MsgF : String := Msg;
2041 Error_Msg_Name_1 := Pname;
2043 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2045 end Error_Pragma_Arg;
2047 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2048 MsgF : String := Msg1;
2050 Error_Msg_Name_1 := Pname;
2052 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2053 Error_Pragma_Arg (Msg2, Arg);
2054 end Error_Pragma_Arg;
2056 ----------------------------
2057 -- Error_Pragma_Arg_Ident --
2058 ----------------------------
2060 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2061 MsgF : String := Msg;
2063 Error_Msg_Name_1 := Pname;
2065 Error_Msg_N (MsgF, Arg);
2067 end Error_Pragma_Arg_Ident;
2069 ----------------------
2070 -- Error_Pragma_Ref --
2071 ----------------------
2073 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2074 MsgF : String := Msg;
2076 Error_Msg_Name_1 := Pname;
2078 Error_Msg_Sloc := Sloc (Ref);
2079 Error_Msg_NE (MsgF, N, Ref);
2081 end Error_Pragma_Ref;
2083 ------------------------
2084 -- Find_Lib_Unit_Name --
2085 ------------------------
2087 function Find_Lib_Unit_Name return Entity_Id is
2089 -- Return inner compilation unit entity, for case of nested
2090 -- categorization pragmas. This happens in generic unit.
2092 if Nkind (Parent (N)) = N_Package_Specification
2093 and then Defining_Entity (Parent (N)) /= Current_Scope
2095 return Defining_Entity (Parent (N));
2097 return Current_Scope;
2099 end Find_Lib_Unit_Name;
2101 ----------------------------
2102 -- Find_Program_Unit_Name --
2103 ----------------------------
2105 procedure Find_Program_Unit_Name (Id : Node_Id) is
2106 Unit_Name : Entity_Id;
2107 Unit_Kind : Node_Kind;
2108 P : constant Node_Id := Parent (N);
2111 if Nkind (P) = N_Compilation_Unit then
2112 Unit_Kind := Nkind (Unit (P));
2114 if Unit_Kind = N_Subprogram_Declaration
2115 or else Unit_Kind = N_Package_Declaration
2116 or else Unit_Kind in N_Generic_Declaration
2118 Unit_Name := Defining_Entity (Unit (P));
2120 if Chars (Id) = Chars (Unit_Name) then
2121 Set_Entity (Id, Unit_Name);
2122 Set_Etype (Id, Etype (Unit_Name));
2124 Set_Etype (Id, Any_Type);
2126 ("cannot find program unit referenced by pragma%");
2130 Set_Etype (Id, Any_Type);
2131 Error_Pragma ("pragma% inapplicable to this unit");
2137 end Find_Program_Unit_Name;
2139 -----------------------------------------
2140 -- Find_Unique_Parameterless_Procedure --
2141 -----------------------------------------
2143 function Find_Unique_Parameterless_Procedure
2145 Arg : Node_Id) return Entity_Id
2147 Proc : Entity_Id := Empty;
2150 -- The body of this procedure needs some comments ???
2152 if not Is_Entity_Name (Name) then
2154 ("argument of pragma% must be entity name", Arg);
2156 elsif not Is_Overloaded (Name) then
2157 Proc := Entity (Name);
2159 if Ekind (Proc) /= E_Procedure
2160 or else Present (First_Formal (Proc))
2163 ("argument of pragma% must be parameterless procedure", Arg);
2168 Found : Boolean := False;
2170 Index : Interp_Index;
2173 Get_First_Interp (Name, Index, It);
2174 while Present (It.Nam) loop
2177 if Ekind (Proc) = E_Procedure
2178 and then No (First_Formal (Proc))
2182 Set_Entity (Name, Proc);
2183 Set_Is_Overloaded (Name, False);
2186 ("ambiguous handler name for pragma% ", Arg);
2190 Get_Next_Interp (Index, It);
2195 ("argument of pragma% must be parameterless procedure",
2198 Proc := Entity (Name);
2204 end Find_Unique_Parameterless_Procedure;
2210 procedure Fix_Error (Msg : in out String) is
2212 if From_Aspect_Specification (N) then
2213 for J in Msg'First .. Msg'Last - 5 loop
2214 if Msg (J .. J + 5) = "pragma" then
2215 Msg (J .. J + 5) := "aspect";
2219 if Error_Msg_Name_1 = Name_Precondition then
2220 Error_Msg_Name_1 := Name_Pre;
2221 elsif Error_Msg_Name_1 = Name_Postcondition then
2222 Error_Msg_Name_1 := Name_Post;
2227 -------------------------
2228 -- Gather_Associations --
2229 -------------------------
2231 procedure Gather_Associations
2233 Args : out Args_List)
2238 -- Initialize all parameters to Empty
2240 for J in Args'Range loop
2244 -- That's all we have to do if there are no argument associations
2246 if No (Pragma_Argument_Associations (N)) then
2250 -- Otherwise first deal with any positional parameters present
2252 Arg := First (Pragma_Argument_Associations (N));
2253 for Index in Args'Range loop
2254 exit when No (Arg) or else Chars (Arg) /= No_Name;
2255 Args (Index) := Get_Pragma_Arg (Arg);
2259 -- Positional parameters all processed, if any left, then we
2260 -- have too many positional parameters.
2262 if Present (Arg) and then Chars (Arg) = No_Name then
2264 ("too many positional associations for pragma%", Arg);
2267 -- Process named parameters if any are present
2269 while Present (Arg) loop
2270 if Chars (Arg) = No_Name then
2272 ("positional association cannot follow named association",
2276 for Index in Names'Range loop
2277 if Names (Index) = Chars (Arg) then
2278 if Present (Args (Index)) then
2280 ("duplicate argument association for pragma%", Arg);
2282 Args (Index) := Get_Pragma_Arg (Arg);
2287 if Index = Names'Last then
2288 Error_Msg_Name_1 := Pname;
2289 Error_Msg_N ("pragma% does not allow & argument", Arg);
2291 -- Check for possible misspelling
2293 for Index1 in Names'Range loop
2294 if Is_Bad_Spelling_Of
2295 (Chars (Arg), Names (Index1))
2297 Error_Msg_Name_1 := Names (Index1);
2298 Error_Msg_N -- CODEFIX
2299 ("\possible misspelling of%", Arg);
2311 end Gather_Associations;
2317 procedure GNAT_Pragma is
2319 Check_Restriction (No_Implementation_Pragmas, N);
2322 --------------------------
2323 -- Is_Before_First_Decl --
2324 --------------------------
2326 function Is_Before_First_Decl
2327 (Pragma_Node : Node_Id;
2328 Decls : List_Id) return Boolean
2330 Item : Node_Id := First (Decls);
2333 -- Only other pragmas can come before this pragma
2336 if No (Item) or else Nkind (Item) /= N_Pragma then
2339 elsif Item = Pragma_Node then
2345 end Is_Before_First_Decl;
2347 -----------------------------
2348 -- Is_Configuration_Pragma --
2349 -----------------------------
2351 -- A configuration pragma must appear in the context clause of a
2352 -- compilation unit, and only other pragmas may precede it. Note that
2353 -- the test below also permits use in a configuration pragma file.
2355 function Is_Configuration_Pragma return Boolean is
2356 Lis : constant List_Id := List_Containing (N);
2357 Par : constant Node_Id := Parent (N);
2361 -- If no parent, then we are in the configuration pragma file,
2362 -- so the placement is definitely appropriate.
2367 -- Otherwise we must be in the context clause of a compilation unit
2368 -- and the only thing allowed before us in the context list is more
2369 -- configuration pragmas.
2371 elsif Nkind (Par) = N_Compilation_Unit
2372 and then Context_Items (Par) = Lis
2379 elsif Nkind (Prg) /= N_Pragma then
2389 end Is_Configuration_Pragma;
2391 --------------------------
2392 -- Is_In_Context_Clause --
2393 --------------------------
2395 function Is_In_Context_Clause return Boolean is
2397 Parent_Node : Node_Id;
2400 if not Is_List_Member (N) then
2404 Plist := List_Containing (N);
2405 Parent_Node := Parent (Plist);
2407 if Parent_Node = Empty
2408 or else Nkind (Parent_Node) /= N_Compilation_Unit
2409 or else Context_Items (Parent_Node) /= Plist
2416 end Is_In_Context_Clause;
2418 ---------------------------------
2419 -- Is_Static_String_Expression --
2420 ---------------------------------
2422 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2423 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2426 Analyze_And_Resolve (Argx);
2427 return Is_OK_Static_Expression (Argx)
2428 and then Nkind (Argx) = N_String_Literal;
2429 end Is_Static_String_Expression;
2431 ----------------------
2432 -- Pragma_Misplaced --
2433 ----------------------
2435 procedure Pragma_Misplaced is
2437 Error_Pragma ("incorrect placement of pragma%");
2438 end Pragma_Misplaced;
2440 ------------------------------------
2441 -- Process Atomic_Shared_Volatile --
2442 ------------------------------------
2444 procedure Process_Atomic_Shared_Volatile is
2451 procedure Set_Atomic (E : Entity_Id);
2452 -- Set given type as atomic, and if no explicit alignment was given,
2453 -- set alignment to unknown, since back end knows what the alignment
2454 -- requirements are for atomic arrays. Note: this step is necessary
2455 -- for derived types.
2461 procedure Set_Atomic (E : Entity_Id) is
2465 if not Has_Alignment_Clause (E) then
2466 Set_Alignment (E, Uint_0);
2470 -- Start of processing for Process_Atomic_Shared_Volatile
2473 Check_Ada_83_Warning;
2474 Check_No_Identifiers;
2475 Check_Arg_Count (1);
2476 Check_Arg_Is_Local_Name (Arg1);
2477 E_Id := Get_Pragma_Arg (Arg1);
2479 if Etype (E_Id) = Any_Type then
2484 D := Declaration_Node (E);
2487 -- Check duplicate before we chain ourselves!
2489 Check_Duplicate_Pragma (E);
2491 -- Now check appropriateness of the entity
2494 if Rep_Item_Too_Early (E, N)
2496 Rep_Item_Too_Late (E, N)
2500 Check_First_Subtype (Arg1);
2503 if Prag_Id /= Pragma_Volatile then
2505 Set_Atomic (Underlying_Type (E));
2506 Set_Atomic (Base_Type (E));
2509 -- Attribute belongs on the base type. If the view of the type is
2510 -- currently private, it also belongs on the underlying type.
2512 Set_Is_Volatile (Base_Type (E));
2513 Set_Is_Volatile (Underlying_Type (E));
2515 Set_Treat_As_Volatile (E);
2516 Set_Treat_As_Volatile (Underlying_Type (E));
2518 elsif K = N_Object_Declaration
2519 or else (K = N_Component_Declaration
2520 and then Original_Record_Component (E) = E)
2522 if Rep_Item_Too_Late (E, N) then
2526 if Prag_Id /= Pragma_Volatile then
2529 -- If the object declaration has an explicit initialization, a
2530 -- temporary may have to be created to hold the expression, to
2531 -- ensure that access to the object remain atomic.
2533 if Nkind (Parent (E)) = N_Object_Declaration
2534 and then Present (Expression (Parent (E)))
2536 Set_Has_Delayed_Freeze (E);
2539 -- An interesting improvement here. If an object of type X is
2540 -- declared atomic, and the type X is not atomic, that's a
2541 -- pity, since it may not have appropriate alignment etc. We
2542 -- can rescue this in the special case where the object and
2543 -- type are in the same unit by just setting the type as
2544 -- atomic, so that the back end will process it as atomic.
2546 Utyp := Underlying_Type (Etype (E));
2549 and then Sloc (E) > No_Location
2550 and then Sloc (Utyp) > No_Location
2552 Get_Source_File_Index (Sloc (E)) =
2553 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2555 Set_Is_Atomic (Underlying_Type (Etype (E)));
2559 Set_Is_Volatile (E);
2560 Set_Treat_As_Volatile (E);
2564 ("inappropriate entity for pragma%", Arg1);
2566 end Process_Atomic_Shared_Volatile;
2568 -------------------------------------------
2569 -- Process_Compile_Time_Warning_Or_Error --
2570 -------------------------------------------
2572 procedure Process_Compile_Time_Warning_Or_Error is
2573 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2576 Check_Arg_Count (2);
2577 Check_No_Identifiers;
2578 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2579 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2581 if Compile_Time_Known_Value (Arg1x) then
2582 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2584 Str : constant String_Id :=
2585 Strval (Get_Pragma_Arg (Arg2));
2586 Len : constant Int := String_Length (Str);
2591 Cent : constant Entity_Id :=
2592 Cunit_Entity (Current_Sem_Unit);
2594 Force : constant Boolean :=
2595 Prag_Id = Pragma_Compile_Time_Warning
2597 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2598 and then (Ekind (Cent) /= E_Package
2599 or else not In_Private_Part (Cent));
2600 -- Set True if this is the warning case, and we are in the
2601 -- visible part of a package spec, or in a subprogram spec,
2602 -- in which case we want to force the client to see the
2603 -- warning, even though it is not in the main unit.
2606 -- Loop through segments of message separated by line feeds.
2607 -- We output these segments as separate messages with
2608 -- continuation marks for all but the first.
2613 Error_Msg_Strlen := 0;
2615 -- Loop to copy characters from argument to error message
2619 exit when Ptr > Len;
2620 CC := Get_String_Char (Str, Ptr);
2623 -- Ignore wide chars ??? else store character
2625 if In_Character_Range (CC) then
2626 C := Get_Character (CC);
2627 exit when C = ASCII.LF;
2628 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2629 Error_Msg_String (Error_Msg_Strlen) := C;
2633 -- Here with one line ready to go
2635 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2637 -- If this is a warning in a spec, then we want clients
2638 -- to see the warning, so mark the message with the
2639 -- special sequence !! to force the warning. In the case
2640 -- of a package spec, we do not force this if we are in
2641 -- the private part of the spec.
2644 if Cont = False then
2645 Error_Msg_N ("<~!!", Arg1);
2648 Error_Msg_N ("\<~!!", Arg1);
2651 -- Error, rather than warning, or in a body, so we do not
2652 -- need to force visibility for client (error will be
2653 -- output in any case, and this is the situation in which
2654 -- we do not want a client to get a warning, since the
2655 -- warning is in the body or the spec private part).
2658 if Cont = False then
2659 Error_Msg_N ("<~", Arg1);
2662 Error_Msg_N ("\<~", Arg1);
2666 exit when Ptr > Len;
2671 end Process_Compile_Time_Warning_Or_Error;
2673 ------------------------
2674 -- Process_Convention --
2675 ------------------------
2677 procedure Process_Convention
2678 (C : out Convention_Id;
2679 Ent : out Entity_Id)
2685 Comp_Unit : Unit_Number_Type;
2687 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2688 -- Called if we have more than one Export/Import/Convention pragma.
2689 -- This is generally illegal, but we have a special case of allowing
2690 -- Import and Interface to coexist if they specify the convention in
2691 -- a consistent manner. We are allowed to do this, since Interface is
2692 -- an implementation defined pragma, and we choose to do it since we
2693 -- know Rational allows this combination. S is the entity id of the
2694 -- subprogram in question. This procedure also sets the special flag
2695 -- Import_Interface_Present in both pragmas in the case where we do
2696 -- have matching Import and Interface pragmas.
2698 procedure Set_Convention_From_Pragma (E : Entity_Id);
2699 -- Set convention in entity E, and also flag that the entity has a
2700 -- convention pragma. If entity is for a private or incomplete type,
2701 -- also set convention and flag on underlying type. This procedure
2702 -- also deals with the special case of C_Pass_By_Copy convention.
2704 -------------------------------
2705 -- Diagnose_Multiple_Pragmas --
2706 -------------------------------
2708 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2709 Pdec : constant Node_Id := Declaration_Node (S);
2713 function Same_Convention (Decl : Node_Id) return Boolean;
2714 -- Decl is a pragma node. This function returns True if this
2715 -- pragma has a first argument that is an identifier with a
2716 -- Chars field corresponding to the Convention_Id C.
2718 function Same_Name (Decl : Node_Id) return Boolean;
2719 -- Decl is a pragma node. This function returns True if this
2720 -- pragma has a second argument that is an identifier with a
2721 -- Chars field that matches the Chars of the current subprogram.
2723 ---------------------
2724 -- Same_Convention --
2725 ---------------------
2727 function Same_Convention (Decl : Node_Id) return Boolean is
2728 Arg1 : constant Node_Id :=
2729 First (Pragma_Argument_Associations (Decl));
2732 if Present (Arg1) then
2734 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2736 if Nkind (Arg) = N_Identifier
2737 and then Is_Convention_Name (Chars (Arg))
2738 and then Get_Convention_Id (Chars (Arg)) = C
2746 end Same_Convention;
2752 function Same_Name (Decl : Node_Id) return Boolean is
2753 Arg1 : constant Node_Id :=
2754 First (Pragma_Argument_Associations (Decl));
2762 Arg2 := Next (Arg1);
2769 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2771 if Nkind (Arg) = N_Identifier
2772 and then Chars (Arg) = Chars (S)
2781 -- Start of processing for Diagnose_Multiple_Pragmas
2786 -- Definitely give message if we have Convention/Export here
2788 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2791 -- If we have an Import or Export, scan back from pragma to
2792 -- find any previous pragma applying to the same procedure.
2793 -- The scan will be terminated by the start of the list, or
2794 -- hitting the subprogram declaration. This won't allow one
2795 -- pragma to appear in the public part and one in the private
2796 -- part, but that seems very unlikely in practice.
2800 while Present (Decl) and then Decl /= Pdec loop
2802 -- Look for pragma with same name as us
2804 if Nkind (Decl) = N_Pragma
2805 and then Same_Name (Decl)
2807 -- Give error if same as our pragma or Export/Convention
2809 if Pragma_Name (Decl) = Name_Export
2811 Pragma_Name (Decl) = Name_Convention
2813 Pragma_Name (Decl) = Pragma_Name (N)
2817 -- Case of Import/Interface or the other way round
2819 elsif Pragma_Name (Decl) = Name_Interface
2821 Pragma_Name (Decl) = Name_Import
2823 -- Here we know that we have Import and Interface. It
2824 -- doesn't matter which way round they are. See if
2825 -- they specify the same convention. If so, all OK,
2826 -- and set special flags to stop other messages
2828 if Same_Convention (Decl) then
2829 Set_Import_Interface_Present (N);
2830 Set_Import_Interface_Present (Decl);
2833 -- If different conventions, special message
2836 Error_Msg_Sloc := Sloc (Decl);
2838 ("convention differs from that given#", Arg1);
2848 -- Give message if needed if we fall through those tests
2852 ("at most one Convention/Export/Import pragma is allowed",
2855 end Diagnose_Multiple_Pragmas;
2857 --------------------------------
2858 -- Set_Convention_From_Pragma --
2859 --------------------------------
2861 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2863 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2864 -- for an overridden dispatching operation. Technically this is
2865 -- an amendment and should only be done in Ada 2005 mode. However,
2866 -- this is clearly a mistake, since the problem that is addressed
2867 -- by this AI is that there is a clear gap in the RM!
2869 if Is_Dispatching_Operation (E)
2870 and then Present (Overridden_Operation (E))
2871 and then C /= Convention (Overridden_Operation (E))
2874 ("cannot change convention for " &
2875 "overridden dispatching operation",
2879 -- Set the convention
2881 Set_Convention (E, C);
2882 Set_Has_Convention_Pragma (E);
2884 if Is_Incomplete_Or_Private_Type (E)
2885 and then Present (Underlying_Type (E))
2887 Set_Convention (Underlying_Type (E), C);
2888 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2891 -- A class-wide type should inherit the convention of the specific
2892 -- root type (although this isn't specified clearly by the RM).
2894 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2895 Set_Convention (Class_Wide_Type (E), C);
2898 -- If the entity is a record type, then check for special case of
2899 -- C_Pass_By_Copy, which is treated the same as C except that the
2900 -- special record flag is set. This convention is only permitted
2901 -- on record types (see AI95-00131).
2903 if Cname = Name_C_Pass_By_Copy then
2904 if Is_Record_Type (E) then
2905 Set_C_Pass_By_Copy (Base_Type (E));
2906 elsif Is_Incomplete_Or_Private_Type (E)
2907 and then Is_Record_Type (Underlying_Type (E))
2909 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2912 ("C_Pass_By_Copy convention allowed only for record type",
2917 -- If the entity is a derived boolean type, check for the special
2918 -- case of convention C, C++, or Fortran, where we consider any
2919 -- nonzero value to represent true.
2921 if Is_Discrete_Type (E)
2922 and then Root_Type (Etype (E)) = Standard_Boolean
2928 C = Convention_Fortran)
2930 Set_Nonzero_Is_True (Base_Type (E));
2932 end Set_Convention_From_Pragma;
2934 -- Start of processing for Process_Convention
2937 Check_At_Least_N_Arguments (2);
2938 Check_Optional_Identifier (Arg1, Name_Convention);
2939 Check_Arg_Is_Identifier (Arg1);
2940 Cname := Chars (Get_Pragma_Arg (Arg1));
2942 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2943 -- tested again below to set the critical flag).
2945 if Cname = Name_C_Pass_By_Copy then
2948 -- Otherwise we must have something in the standard convention list
2950 elsif Is_Convention_Name (Cname) then
2951 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
2953 -- In DEC VMS, it seems that there is an undocumented feature that
2954 -- any unrecognized convention is treated as the default, which for
2955 -- us is convention C. It does not seem so terrible to do this
2956 -- unconditionally, silently in the VMS case, and with a warning
2957 -- in the non-VMS case.
2960 if Warn_On_Export_Import and not OpenVMS_On_Target then
2962 ("?unrecognized convention name, C assumed",
2963 Get_Pragma_Arg (Arg1));
2969 Check_Optional_Identifier (Arg2, Name_Entity);
2970 Check_Arg_Is_Local_Name (Arg2);
2972 Id := Get_Pragma_Arg (Arg2);
2975 if not Is_Entity_Name (Id) then
2976 Error_Pragma_Arg ("entity name required", Arg2);
2981 -- Set entity to return
2985 -- Go to renamed subprogram if present, since convention applies to
2986 -- the actual renamed entity, not to the renaming entity. If the
2987 -- subprogram is inherited, go to parent subprogram.
2989 if Is_Subprogram (E)
2990 and then Present (Alias (E))
2992 if Nkind (Parent (Declaration_Node (E))) =
2993 N_Subprogram_Renaming_Declaration
2995 if Scope (E) /= Scope (Alias (E)) then
2997 ("cannot apply pragma% to non-local entity&#", E);
3002 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3003 N_Private_Extension_Declaration)
3004 and then Scope (E) = Scope (Alias (E))
3008 -- Return the parent subprogram the entity was inherited from
3014 -- Check that we are not applying this to a specless body
3016 if Is_Subprogram (E)
3017 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3020 ("pragma% requires separate spec and must come before body");
3023 -- Check that we are not applying this to a named constant
3025 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3026 Error_Msg_Name_1 := Pname;
3028 ("cannot apply pragma% to named constant!",
3029 Get_Pragma_Arg (Arg2));
3031 ("\supply appropriate type for&!", Arg2);
3034 if Ekind (E) = E_Enumeration_Literal then
3035 Error_Pragma ("enumeration literal not allowed for pragma%");
3038 -- Check for rep item appearing too early or too late
3040 if Etype (E) = Any_Type
3041 or else Rep_Item_Too_Early (E, N)
3045 elsif Present (Underlying_Type (E)) then
3046 E := Underlying_Type (E);
3049 if Rep_Item_Too_Late (E, N) then
3053 if Has_Convention_Pragma (E) then
3054 Diagnose_Multiple_Pragmas (E);
3056 elsif Convention (E) = Convention_Protected
3057 or else Ekind (Scope (E)) = E_Protected_Type
3060 ("a protected operation cannot be given a different convention",
3064 -- For Intrinsic, a subprogram is required
3066 if C = Convention_Intrinsic
3067 and then not Is_Subprogram (E)
3068 and then not Is_Generic_Subprogram (E)
3071 ("second argument of pragma% must be a subprogram", Arg2);
3074 -- For Stdcall, a subprogram, variable or subprogram type is required
3076 if C = Convention_Stdcall
3077 and then not Is_Subprogram (E)
3078 and then not Is_Generic_Subprogram (E)
3079 and then Ekind (E) /= E_Variable
3082 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3085 ("second argument of pragma% must be subprogram (type)",
3089 if not Is_Subprogram (E)
3090 and then not Is_Generic_Subprogram (E)
3092 Set_Convention_From_Pragma (E);
3095 Check_First_Subtype (Arg2);
3096 Set_Convention_From_Pragma (Base_Type (E));
3098 -- For subprograms, we must set the convention on the
3099 -- internally generated directly designated type as well.
3101 if Ekind (E) = E_Access_Subprogram_Type then
3102 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3106 -- For the subprogram case, set proper convention for all homonyms
3107 -- in same scope and the same declarative part, i.e. the same
3108 -- compilation unit.
3111 Comp_Unit := Get_Source_Unit (E);
3112 Set_Convention_From_Pragma (E);
3114 -- Treat a pragma Import as an implicit body, for GPS use
3116 if Prag_Id = Pragma_Import then
3117 Generate_Reference (E, Id, 'b');
3120 -- Loop through the homonyms of the pragma argument's entity
3125 exit when No (E1) or else Scope (E1) /= Current_Scope;
3127 -- Do not set the pragma on inherited operations or on formal
3130 if Comes_From_Source (E1)
3131 and then Comp_Unit = Get_Source_Unit (E1)
3132 and then not Is_Formal_Subprogram (E1)
3133 and then Nkind (Original_Node (Parent (E1))) /=
3134 N_Full_Type_Declaration
3136 if Present (Alias (E1))
3137 and then Scope (E1) /= Scope (Alias (E1))
3140 ("cannot apply pragma% to non-local entity& declared#",
3144 Set_Convention_From_Pragma (E1);
3146 if Prag_Id = Pragma_Import then
3147 Generate_Reference (E1, Id, 'b');
3151 -- For aspect case, do NOT apply to homonyms
3153 exit when From_Aspect_Specification (N);
3156 end Process_Convention;
3158 -----------------------------------------------------
3159 -- Process_Extended_Import_Export_Exception_Pragma --
3160 -----------------------------------------------------
3162 procedure Process_Extended_Import_Export_Exception_Pragma
3163 (Arg_Internal : Node_Id;
3164 Arg_External : Node_Id;
3172 if not OpenVMS_On_Target then
3174 ("?pragma% ignored (applies only to Open'V'M'S)");
3177 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3178 Def_Id := Entity (Arg_Internal);
3180 if Ekind (Def_Id) /= E_Exception then
3182 ("pragma% must refer to declared exception", Arg_Internal);
3185 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3187 if Present (Arg_Form) then
3188 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3191 if Present (Arg_Form)
3192 and then Chars (Arg_Form) = Name_Ada
3196 Set_Is_VMS_Exception (Def_Id);
3197 Set_Exception_Code (Def_Id, No_Uint);
3200 if Present (Arg_Code) then
3201 if not Is_VMS_Exception (Def_Id) then
3203 ("Code option for pragma% not allowed for Ada case",
3207 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3208 Code_Val := Expr_Value (Arg_Code);
3210 if not UI_Is_In_Int_Range (Code_Val) then
3212 ("Code option for pragma% must be in 32-bit range",
3216 Set_Exception_Code (Def_Id, Code_Val);
3219 end Process_Extended_Import_Export_Exception_Pragma;
3221 -------------------------------------------------
3222 -- Process_Extended_Import_Export_Internal_Arg --
3223 -------------------------------------------------
3225 procedure Process_Extended_Import_Export_Internal_Arg
3226 (Arg_Internal : Node_Id := Empty)
3229 if No (Arg_Internal) then
3230 Error_Pragma ("Internal parameter required for pragma%");
3233 if Nkind (Arg_Internal) = N_Identifier then
3236 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3237 and then (Prag_Id = Pragma_Import_Function
3239 Prag_Id = Pragma_Export_Function)
3245 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3248 Check_Arg_Is_Local_Name (Arg_Internal);
3249 end Process_Extended_Import_Export_Internal_Arg;
3251 --------------------------------------------------
3252 -- Process_Extended_Import_Export_Object_Pragma --
3253 --------------------------------------------------
3255 procedure Process_Extended_Import_Export_Object_Pragma
3256 (Arg_Internal : Node_Id;
3257 Arg_External : Node_Id;
3263 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3264 Def_Id := Entity (Arg_Internal);
3266 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3268 ("pragma% must designate an object", Arg_Internal);
3271 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3273 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3276 ("previous Common/Psect_Object applies, pragma % not permitted",
3280 if Rep_Item_Too_Late (Def_Id, N) then
3284 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3286 if Present (Arg_Size) then
3287 Check_Arg_Is_External_Name (Arg_Size);
3290 -- Export_Object case
3292 if Prag_Id = Pragma_Export_Object then
3293 if not Is_Library_Level_Entity (Def_Id) then
3295 ("argument for pragma% must be library level entity",
3299 if Ekind (Current_Scope) = E_Generic_Package then
3300 Error_Pragma ("pragma& cannot appear in a generic unit");
3303 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3305 ("exported object must have compile time known size",
3309 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3310 Error_Msg_N ("?duplicate Export_Object pragma", N);
3312 Set_Exported (Def_Id, Arg_Internal);
3315 -- Import_Object case
3318 if Is_Concurrent_Type (Etype (Def_Id)) then
3320 ("cannot use pragma% for task/protected object",
3324 if Ekind (Def_Id) = E_Constant then
3326 ("cannot import a constant", Arg_Internal);
3329 if Warn_On_Export_Import
3330 and then Has_Discriminants (Etype (Def_Id))
3333 ("imported value must be initialized?", Arg_Internal);
3336 if Warn_On_Export_Import
3337 and then Is_Access_Type (Etype (Def_Id))
3340 ("cannot import object of an access type?", Arg_Internal);
3343 if Warn_On_Export_Import
3344 and then Is_Imported (Def_Id)
3347 ("?duplicate Import_Object pragma", N);
3349 -- Check for explicit initialization present. Note that an
3350 -- initialization generated by the code generator, e.g. for an
3351 -- access type, does not count here.
3353 elsif Present (Expression (Parent (Def_Id)))
3356 (Original_Node (Expression (Parent (Def_Id))))
3358 Error_Msg_Sloc := Sloc (Def_Id);
3360 ("imported entities cannot be initialized (RM B.1(24))",
3361 "\no initialization allowed for & declared#", Arg1);
3363 Set_Imported (Def_Id);
3364 Note_Possible_Modification (Arg_Internal, Sure => False);
3367 end Process_Extended_Import_Export_Object_Pragma;
3369 ------------------------------------------------------
3370 -- Process_Extended_Import_Export_Subprogram_Pragma --
3371 ------------------------------------------------------
3373 procedure Process_Extended_Import_Export_Subprogram_Pragma
3374 (Arg_Internal : Node_Id;
3375 Arg_External : Node_Id;
3376 Arg_Parameter_Types : Node_Id;
3377 Arg_Result_Type : Node_Id := Empty;
3378 Arg_Mechanism : Node_Id;
3379 Arg_Result_Mechanism : Node_Id := Empty;
3380 Arg_First_Optional_Parameter : Node_Id := Empty)
3386 Ambiguous : Boolean;
3390 function Same_Base_Type
3392 Formal : Entity_Id) return Boolean;
3393 -- Determines if Ptype references the type of Formal. Note that only
3394 -- the base types need to match according to the spec. Ptype here is
3395 -- the argument from the pragma, which is either a type name, or an
3396 -- access attribute.
3398 --------------------
3399 -- Same_Base_Type --
3400 --------------------
3402 function Same_Base_Type
3404 Formal : Entity_Id) return Boolean
3406 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3410 -- Case where pragma argument is typ'Access
3412 if Nkind (Ptype) = N_Attribute_Reference
3413 and then Attribute_Name (Ptype) = Name_Access
3415 Pref := Prefix (Ptype);
3418 if not Is_Entity_Name (Pref)
3419 or else Entity (Pref) = Any_Type
3424 -- We have a match if the corresponding argument is of an
3425 -- anonymous access type, and its designated type matches the
3426 -- type of the prefix of the access attribute
3428 return Ekind (Ftyp) = E_Anonymous_Access_Type
3429 and then Base_Type (Entity (Pref)) =
3430 Base_Type (Etype (Designated_Type (Ftyp)));
3432 -- Case where pragma argument is a type name
3437 if not Is_Entity_Name (Ptype)
3438 or else Entity (Ptype) = Any_Type
3443 -- We have a match if the corresponding argument is of the type
3444 -- given in the pragma (comparing base types)
3446 return Base_Type (Entity (Ptype)) = Ftyp;
3450 -- Start of processing for
3451 -- Process_Extended_Import_Export_Subprogram_Pragma
3454 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3458 -- Loop through homonyms (overloadings) of the entity
3460 Hom_Id := Entity (Arg_Internal);
3461 while Present (Hom_Id) loop
3462 Def_Id := Get_Base_Subprogram (Hom_Id);
3464 -- We need a subprogram in the current scope
3466 if not Is_Subprogram (Def_Id)
3467 or else Scope (Def_Id) /= Current_Scope
3474 -- Pragma cannot apply to subprogram body
3476 if Is_Subprogram (Def_Id)
3477 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3481 ("pragma% requires separate spec"
3482 & " and must come before body");
3485 -- Test result type if given, note that the result type
3486 -- parameter can only be present for the function cases.
3488 if Present (Arg_Result_Type)
3489 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3493 elsif Etype (Def_Id) /= Standard_Void_Type
3495 (Pname = Name_Export_Procedure
3497 Pname = Name_Import_Procedure)
3501 -- Test parameter types if given. Note that this parameter
3502 -- has not been analyzed (and must not be, since it is
3503 -- semantic nonsense), so we get it as the parser left it.
3505 elsif Present (Arg_Parameter_Types) then
3506 Check_Matching_Types : declare
3511 Formal := First_Formal (Def_Id);
3513 if Nkind (Arg_Parameter_Types) = N_Null then
3514 if Present (Formal) then
3518 -- A list of one type, e.g. (List) is parsed as
3519 -- a parenthesized expression.
3521 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3522 and then Paren_Count (Arg_Parameter_Types) = 1
3525 or else Present (Next_Formal (Formal))
3530 Same_Base_Type (Arg_Parameter_Types, Formal);
3533 -- A list of more than one type is parsed as a aggregate
3535 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3536 and then Paren_Count (Arg_Parameter_Types) = 0
3538 Ptype := First (Expressions (Arg_Parameter_Types));
3539 while Present (Ptype) or else Present (Formal) loop
3542 or else not Same_Base_Type (Ptype, Formal)
3547 Next_Formal (Formal);
3552 -- Anything else is of the wrong form
3556 ("wrong form for Parameter_Types parameter",
3557 Arg_Parameter_Types);
3559 end Check_Matching_Types;
3562 -- Match is now False if the entry we found did not match
3563 -- either a supplied Parameter_Types or Result_Types argument
3569 -- Ambiguous case, the flag Ambiguous shows if we already
3570 -- detected this and output the initial messages.
3573 if not Ambiguous then
3575 Error_Msg_Name_1 := Pname;
3577 ("pragma% does not uniquely identify subprogram!",
3579 Error_Msg_Sloc := Sloc (Ent);
3580 Error_Msg_N ("matching subprogram #!", N);
3584 Error_Msg_Sloc := Sloc (Def_Id);
3585 Error_Msg_N ("matching subprogram #!", N);
3590 Hom_Id := Homonym (Hom_Id);
3593 -- See if we found an entry
3596 if not Ambiguous then
3597 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3599 ("pragma% cannot be given for generic subprogram");
3602 ("pragma% does not identify local subprogram");
3609 -- Import pragmas must be for imported entities
3611 if Prag_Id = Pragma_Import_Function
3613 Prag_Id = Pragma_Import_Procedure
3615 Prag_Id = Pragma_Import_Valued_Procedure
3617 if not Is_Imported (Ent) then
3619 ("pragma Import or Interface must precede pragma%");
3622 -- Here we have the Export case which can set the entity as exported
3624 -- But does not do so if the specified external name is null, since
3625 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3626 -- compatible) to request no external name.
3628 elsif Nkind (Arg_External) = N_String_Literal
3629 and then String_Length (Strval (Arg_External)) = 0
3633 -- In all other cases, set entity as exported
3636 Set_Exported (Ent, Arg_Internal);
3639 -- Special processing for Valued_Procedure cases
3641 if Prag_Id = Pragma_Import_Valued_Procedure
3643 Prag_Id = Pragma_Export_Valued_Procedure
3645 Formal := First_Formal (Ent);
3648 Error_Pragma ("at least one parameter required for pragma%");
3650 elsif Ekind (Formal) /= E_Out_Parameter then
3651 Error_Pragma ("first parameter must have mode out for pragma%");
3654 Set_Is_Valued_Procedure (Ent);
3658 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3660 -- Process Result_Mechanism argument if present. We have already
3661 -- checked that this is only allowed for the function case.
3663 if Present (Arg_Result_Mechanism) then
3664 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3667 -- Process Mechanism parameter if present. Note that this parameter
3668 -- is not analyzed, and must not be analyzed since it is semantic
3669 -- nonsense, so we get it in exactly as the parser left it.
3671 if Present (Arg_Mechanism) then
3679 -- A single mechanism association without a formal parameter
3680 -- name is parsed as a parenthesized expression. All other
3681 -- cases are parsed as aggregates, so we rewrite the single
3682 -- parameter case as an aggregate for consistency.
3684 if Nkind (Arg_Mechanism) /= N_Aggregate
3685 and then Paren_Count (Arg_Mechanism) = 1
3687 Rewrite (Arg_Mechanism,
3688 Make_Aggregate (Sloc (Arg_Mechanism),
3689 Expressions => New_List (
3690 Relocate_Node (Arg_Mechanism))));
3693 -- Case of only mechanism name given, applies to all formals
3695 if Nkind (Arg_Mechanism) /= N_Aggregate then
3696 Formal := First_Formal (Ent);
3697 while Present (Formal) loop
3698 Set_Mechanism_Value (Formal, Arg_Mechanism);
3699 Next_Formal (Formal);
3702 -- Case of list of mechanism associations given
3705 if Null_Record_Present (Arg_Mechanism) then
3707 ("inappropriate form for Mechanism parameter",
3711 -- Deal with positional ones first
3713 Formal := First_Formal (Ent);
3715 if Present (Expressions (Arg_Mechanism)) then
3716 Mname := First (Expressions (Arg_Mechanism));
3717 while Present (Mname) loop
3720 ("too many mechanism associations", Mname);
3723 Set_Mechanism_Value (Formal, Mname);
3724 Next_Formal (Formal);
3729 -- Deal with named entries
3731 if Present (Component_Associations (Arg_Mechanism)) then
3732 Massoc := First (Component_Associations (Arg_Mechanism));
3733 while Present (Massoc) loop
3734 Choice := First (Choices (Massoc));
3736 if Nkind (Choice) /= N_Identifier
3737 or else Present (Next (Choice))
3740 ("incorrect form for mechanism association",
3744 Formal := First_Formal (Ent);
3748 ("parameter name & not present", Choice);
3751 if Chars (Choice) = Chars (Formal) then
3753 (Formal, Expression (Massoc));
3755 -- Set entity on identifier (needed by ASIS)
3757 Set_Entity (Choice, Formal);
3762 Next_Formal (Formal);
3772 -- Process First_Optional_Parameter argument if present. We have
3773 -- already checked that this is only allowed for the Import case.
3775 if Present (Arg_First_Optional_Parameter) then
3776 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3778 ("first optional parameter must be formal parameter name",
3779 Arg_First_Optional_Parameter);
3782 Formal := First_Formal (Ent);
3786 ("specified formal parameter& not found",
3787 Arg_First_Optional_Parameter);
3790 exit when Chars (Formal) =
3791 Chars (Arg_First_Optional_Parameter);
3793 Next_Formal (Formal);
3796 Set_First_Optional_Parameter (Ent, Formal);
3798 -- Check specified and all remaining formals have right form
3800 while Present (Formal) loop
3801 if Ekind (Formal) /= E_In_Parameter then
3803 ("optional formal& is not of mode in!",
3804 Arg_First_Optional_Parameter, Formal);
3807 Dval := Default_Value (Formal);
3811 ("optional formal& does not have default value!",
3812 Arg_First_Optional_Parameter, Formal);
3814 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3819 ("default value for optional formal& is non-static!",
3820 Arg_First_Optional_Parameter, Formal);
3824 Set_Is_Optional_Parameter (Formal);
3825 Next_Formal (Formal);
3828 end Process_Extended_Import_Export_Subprogram_Pragma;
3830 --------------------------
3831 -- Process_Generic_List --
3832 --------------------------
3834 procedure Process_Generic_List is
3839 Check_No_Identifiers;
3840 Check_At_Least_N_Arguments (1);
3843 while Present (Arg) loop
3844 Exp := Get_Pragma_Arg (Arg);
3847 if not Is_Entity_Name (Exp)
3849 (not Is_Generic_Instance (Entity (Exp))
3851 not Is_Generic_Unit (Entity (Exp)))
3854 ("pragma% argument must be name of generic unit/instance",
3860 end Process_Generic_List;
3862 ------------------------------------
3863 -- Process_Import_Predefined_Type --
3864 ------------------------------------
3866 procedure Process_Import_Predefined_Type is
3867 Loc : constant Source_Ptr := Sloc (N);
3869 Ftyp : Node_Id := Empty;
3875 String_To_Name_Buffer (Strval (Expression (Arg3)));
3878 Elmt := First_Elmt (Predefined_Float_Types);
3879 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
3883 Ftyp := Node (Elmt);
3885 if Present (Ftyp) then
3887 -- Don't build a derived type declaration, because predefined C
3888 -- types have no declaration anywhere, so cannot really be named.
3889 -- Instead build a full type declaration, starting with an
3890 -- appropriate type definition is built
3892 if Is_Floating_Point_Type (Ftyp) then
3893 Def := Make_Floating_Point_Definition (Loc,
3894 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
3895 Make_Real_Range_Specification (Loc,
3896 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
3897 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
3899 -- Should never have a predefined type we cannot handle
3902 raise Program_Error;
3905 -- Build and insert a Full_Type_Declaration, which will be
3906 -- analyzed as soon as this list entry has been analyzed.
3908 Decl := Make_Full_Type_Declaration (Loc,
3909 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
3910 Type_Definition => Def);
3912 Insert_After (N, Decl);
3913 Mark_Rewrite_Insertion (Decl);
3916 Error_Pragma_Arg ("no matching type found for pragma%",
3919 end Process_Import_Predefined_Type;
3921 ---------------------------------
3922 -- Process_Import_Or_Interface --
3923 ---------------------------------
3925 procedure Process_Import_Or_Interface is
3931 Process_Convention (C, Def_Id);
3932 Kill_Size_Check_Code (Def_Id);
3933 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
3935 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3937 -- We do not permit Import to apply to a renaming declaration
3939 if Present (Renamed_Object (Def_Id)) then
3941 ("pragma% not allowed for object renaming", Arg2);
3943 -- User initialization is not allowed for imported object, but
3944 -- the object declaration may contain a default initialization,
3945 -- that will be discarded. Note that an explicit initialization
3946 -- only counts if it comes from source, otherwise it is simply
3947 -- the code generator making an implicit initialization explicit.
3949 elsif Present (Expression (Parent (Def_Id)))
3950 and then Comes_From_Source (Expression (Parent (Def_Id)))
3952 Error_Msg_Sloc := Sloc (Def_Id);
3954 ("no initialization allowed for declaration of& #",
3955 "\imported entities cannot be initialized (RM B.1(24))",
3959 Set_Imported (Def_Id);
3960 Process_Interface_Name (Def_Id, Arg3, Arg4);
3962 -- Note that we do not set Is_Public here. That's because we
3963 -- only want to set it if there is no address clause, and we
3964 -- don't know that yet, so we delay that processing till
3967 -- pragma Import completes deferred constants
3969 if Ekind (Def_Id) = E_Constant then
3970 Set_Has_Completion (Def_Id);
3973 -- It is not possible to import a constant of an unconstrained
3974 -- array type (e.g. string) because there is no simple way to
3975 -- write a meaningful subtype for it.
3977 if Is_Array_Type (Etype (Def_Id))
3978 and then not Is_Constrained (Etype (Def_Id))
3981 ("imported constant& must have a constrained subtype",
3986 elsif Is_Subprogram (Def_Id)
3987 or else Is_Generic_Subprogram (Def_Id)
3989 -- If the name is overloaded, pragma applies to all of the denoted
3990 -- entities in the same declarative part.
3993 while Present (Hom_Id) loop
3994 Def_Id := Get_Base_Subprogram (Hom_Id);
3996 -- Ignore inherited subprograms because the pragma will apply
3997 -- to the parent operation, which is the one called.
3999 if Is_Overloadable (Def_Id)
4000 and then Present (Alias (Def_Id))
4004 -- If it is not a subprogram, it must be in an outer scope and
4005 -- pragma does not apply.
4007 elsif not Is_Subprogram (Def_Id)
4008 and then not Is_Generic_Subprogram (Def_Id)
4012 -- The pragma does not apply to primitives of interfaces
4014 elsif Is_Dispatching_Operation (Def_Id)
4015 and then Present (Find_Dispatching_Type (Def_Id))
4016 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4020 -- Verify that the homonym is in the same declarative part (not
4021 -- just the same scope).
4023 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4024 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4029 Set_Imported (Def_Id);
4031 -- Reject an Import applied to an abstract subprogram
4033 if Is_Subprogram (Def_Id)
4034 and then Is_Abstract_Subprogram (Def_Id)
4036 Error_Msg_Sloc := Sloc (Def_Id);
4038 ("cannot import abstract subprogram& declared#",
4042 -- Special processing for Convention_Intrinsic
4044 if C = Convention_Intrinsic then
4046 -- Link_Name argument not allowed for intrinsic
4050 Set_Is_Intrinsic_Subprogram (Def_Id);
4052 -- If no external name is present, then check that this
4053 -- is a valid intrinsic subprogram. If an external name
4054 -- is present, then this is handled by the back end.
4057 Check_Intrinsic_Subprogram
4058 (Def_Id, Get_Pragma_Arg (Arg2));
4062 -- All interfaced procedures need an external symbol created
4063 -- for them since they are always referenced from another
4066 Set_Is_Public (Def_Id);
4068 -- Verify that the subprogram does not have a completion
4069 -- through a renaming declaration. For other completions the
4070 -- pragma appears as a too late representation.
4073 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4077 and then Nkind (Decl) = N_Subprogram_Declaration
4078 and then Present (Corresponding_Body (Decl))
4079 and then Nkind (Unit_Declaration_Node
4080 (Corresponding_Body (Decl))) =
4081 N_Subprogram_Renaming_Declaration
4083 Error_Msg_Sloc := Sloc (Def_Id);
4085 ("cannot import&, renaming already provided for " &
4086 "declaration #", N, Def_Id);
4090 Set_Has_Completion (Def_Id);
4091 Process_Interface_Name (Def_Id, Arg3, Arg4);
4094 if Is_Compilation_Unit (Hom_Id) then
4096 -- Its possible homonyms are not affected by the pragma.
4097 -- Such homonyms might be present in the context of other
4098 -- units being compiled.
4103 Hom_Id := Homonym (Hom_Id);
4107 -- When the convention is Java or CIL, we also allow Import to be
4108 -- given for packages, generic packages, exceptions, record
4109 -- components, and access to subprograms.
4111 elsif (C = Convention_Java or else C = Convention_CIL)
4113 (Is_Package_Or_Generic_Package (Def_Id)
4114 or else Ekind (Def_Id) = E_Exception
4115 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4116 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4118 Set_Imported (Def_Id);
4119 Set_Is_Public (Def_Id);
4120 Process_Interface_Name (Def_Id, Arg3, Arg4);
4122 -- Import a CPP class
4124 elsif Is_Record_Type (Def_Id)
4125 and then C = Convention_CPP
4127 -- Types treated as CPP classes are treated as limited, but we
4128 -- don't require them to be declared this way. A warning is issued
4129 -- to encourage the user to declare them as limited. This is not
4130 -- an error, for compatibility reasons, because these types have
4131 -- been supported this way for some time.
4133 if not Is_Limited_Type (Def_Id) then
4135 ("imported 'C'P'P type should be " &
4136 "explicitly declared limited?",
4137 Get_Pragma_Arg (Arg2));
4139 ("\type will be considered limited",
4140 Get_Pragma_Arg (Arg2));
4143 Set_Is_CPP_Class (Def_Id);
4144 Set_Is_Limited_Record (Def_Id);
4146 -- Imported CPP types must not have discriminants (because C++
4147 -- classes do not have discriminants).
4149 if Has_Discriminants (Def_Id) then
4151 ("imported 'C'P'P type cannot have discriminants",
4152 First (Discriminant_Specifications
4153 (Declaration_Node (Def_Id))));
4156 -- Components of imported CPP types must not have default
4157 -- expressions because the constructor (if any) is on the
4161 Tdef : constant Node_Id :=
4162 Type_Definition (Declaration_Node (Def_Id));
4167 if Nkind (Tdef) = N_Record_Definition then
4168 Clist := Component_List (Tdef);
4171 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4172 Clist := Component_List (Record_Extension_Part (Tdef));
4175 if Present (Clist) then
4176 Comp := First (Component_Items (Clist));
4177 while Present (Comp) loop
4178 if Present (Expression (Comp)) then
4180 ("component of imported 'C'P'P type cannot have" &
4181 " default expression", Expression (Comp));
4189 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4191 Check_Arg_Count (3);
4192 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4194 Process_Import_Predefined_Type;
4198 ("second argument of pragma% must be object, subprogram" &
4199 " or incomplete type",
4203 -- If this pragma applies to a compilation unit, then the unit, which
4204 -- is a subprogram, does not require (or allow) a body. We also do
4205 -- not need to elaborate imported procedures.
4207 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4209 Cunit : constant Node_Id := Parent (Parent (N));
4211 Set_Body_Required (Cunit, False);
4214 end Process_Import_Or_Interface;
4216 --------------------
4217 -- Process_Inline --
4218 --------------------
4220 procedure Process_Inline (Active : Boolean) is
4227 Effective : Boolean := False;
4228 -- Set True if inline has some effect, i.e. if there is at least one
4229 -- subprogram set as inlined as a result of the use of the pragma.
4231 procedure Make_Inline (Subp : Entity_Id);
4232 -- Subp is the defining unit name of the subprogram declaration. Set
4233 -- the flag, as well as the flag in the corresponding body, if there
4236 procedure Set_Inline_Flags (Subp : Entity_Id);
4237 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4238 -- Has_Pragma_Inline_Always for the Inline_Always case.
4240 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4241 -- Returns True if it can be determined at this stage that inlining
4242 -- is not possible, for example if the body is available and contains
4243 -- exception handlers, we prevent inlining, since otherwise we can
4244 -- get undefined symbols at link time. This function also emits a
4245 -- warning if front-end inlining is enabled and the pragma appears
4248 -- ??? is business with link symbols still valid, or does it relate
4249 -- to front end ZCX which is being phased out ???
4251 ---------------------------
4252 -- Inlining_Not_Possible --
4253 ---------------------------
4255 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4256 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4260 if Nkind (Decl) = N_Subprogram_Body then
4261 Stats := Handled_Statement_Sequence (Decl);
4262 return Present (Exception_Handlers (Stats))
4263 or else Present (At_End_Proc (Stats));
4265 elsif Nkind (Decl) = N_Subprogram_Declaration
4266 and then Present (Corresponding_Body (Decl))
4268 if Front_End_Inlining
4269 and then Analyzed (Corresponding_Body (Decl))
4271 Error_Msg_N ("pragma appears too late, ignored?", N);
4274 -- If the subprogram is a renaming as body, the body is just a
4275 -- call to the renamed subprogram, and inlining is trivially
4279 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4280 N_Subprogram_Renaming_Declaration
4286 Handled_Statement_Sequence
4287 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4290 Present (Exception_Handlers (Stats))
4291 or else Present (At_End_Proc (Stats));
4295 -- If body is not available, assume the best, the check is
4296 -- performed again when compiling enclosing package bodies.
4300 end Inlining_Not_Possible;
4306 procedure Make_Inline (Subp : Entity_Id) is
4307 Kind : constant Entity_Kind := Ekind (Subp);
4308 Inner_Subp : Entity_Id := Subp;
4311 -- Ignore if bad type, avoid cascaded error
4313 if Etype (Subp) = Any_Type then
4317 -- Ignore if all inlining is suppressed
4319 elsif Suppress_All_Inlining then
4323 -- If inlining is not possible, for now do not treat as an error
4325 elsif Inlining_Not_Possible (Subp) then
4329 -- Here we have a candidate for inlining, but we must exclude
4330 -- derived operations. Otherwise we would end up trying to inline
4331 -- a phantom declaration, and the result would be to drag in a
4332 -- body which has no direct inlining associated with it. That
4333 -- would not only be inefficient but would also result in the
4334 -- backend doing cross-unit inlining in cases where it was
4335 -- definitely inappropriate to do so.
4337 -- However, a simple Comes_From_Source test is insufficient, since
4338 -- we do want to allow inlining of generic instances which also do
4339 -- not come from source. We also need to recognize specs generated
4340 -- by the front-end for bodies that carry the pragma. Finally,
4341 -- predefined operators do not come from source but are not
4342 -- inlineable either.
4344 elsif Is_Generic_Instance (Subp)
4345 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4349 elsif not Comes_From_Source (Subp)
4350 and then Scope (Subp) /= Standard_Standard
4356 -- The referenced entity must either be the enclosing entity, or
4357 -- an entity declared within the current open scope.
4359 if Present (Scope (Subp))
4360 and then Scope (Subp) /= Current_Scope
4361 and then Subp /= Current_Scope
4364 ("argument of% must be entity in current scope", Assoc);
4368 -- Processing for procedure, operator or function. If subprogram
4369 -- is aliased (as for an instance) indicate that the renamed
4370 -- entity (if declared in the same unit) is inlined.
4372 if Is_Subprogram (Subp) then
4373 Inner_Subp := Ultimate_Alias (Inner_Subp);
4375 if In_Same_Source_Unit (Subp, Inner_Subp) then
4376 Set_Inline_Flags (Inner_Subp);
4378 Decl := Parent (Parent (Inner_Subp));
4380 if Nkind (Decl) = N_Subprogram_Declaration
4381 and then Present (Corresponding_Body (Decl))
4383 Set_Inline_Flags (Corresponding_Body (Decl));
4385 elsif Is_Generic_Instance (Subp) then
4387 -- Indicate that the body needs to be created for
4388 -- inlining subsequent calls. The instantiation node
4389 -- follows the declaration of the wrapper package
4392 if Scope (Subp) /= Standard_Standard
4394 Need_Subprogram_Instance_Body
4395 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4405 -- For a generic subprogram set flag as well, for use at the point
4406 -- of instantiation, to determine whether the body should be
4409 elsif Is_Generic_Subprogram (Subp) then
4410 Set_Inline_Flags (Subp);
4413 -- Literals are by definition inlined
4415 elsif Kind = E_Enumeration_Literal then
4418 -- Anything else is an error
4422 ("expect subprogram name for pragma%", Assoc);
4426 ----------------------
4427 -- Set_Inline_Flags --
4428 ----------------------
4430 procedure Set_Inline_Flags (Subp : Entity_Id) is
4433 Set_Is_Inlined (Subp);
4436 if not Has_Pragma_Inline (Subp) then
4437 Set_Has_Pragma_Inline (Subp);
4441 if Prag_Id = Pragma_Inline_Always then
4442 Set_Has_Pragma_Inline_Always (Subp);
4444 end Set_Inline_Flags;
4446 -- Start of processing for Process_Inline
4449 Check_No_Identifiers;
4450 Check_At_Least_N_Arguments (1);
4453 Inline_Processing_Required := True;
4457 while Present (Assoc) loop
4458 Subp_Id := Get_Pragma_Arg (Assoc);
4462 if Is_Entity_Name (Subp_Id) then
4463 Subp := Entity (Subp_Id);
4465 if Subp = Any_Id then
4467 -- If previous error, avoid cascaded errors
4475 -- For the pragma case, climb homonym chain. This is
4476 -- what implements allowing the pragma in the renaming
4477 -- case, with the result applying to the ancestors.
4479 if not From_Aspect_Specification (N) then
4480 while Present (Homonym (Subp))
4481 and then Scope (Homonym (Subp)) = Current_Scope
4483 Make_Inline (Homonym (Subp));
4484 Subp := Homonym (Subp);
4492 ("inappropriate argument for pragma%", Assoc);
4495 and then Warn_On_Redundant_Constructs
4496 and then not Suppress_All_Inlining
4498 if Inlining_Not_Possible (Subp) then
4500 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4503 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4511 ----------------------------
4512 -- Process_Interface_Name --
4513 ----------------------------
4515 procedure Process_Interface_Name
4516 (Subprogram_Def : Entity_Id;
4522 String_Val : String_Id;
4524 procedure Check_Form_Of_Interface_Name
4526 Ext_Name_Case : Boolean);
4527 -- SN is a string literal node for an interface name. This routine
4528 -- performs some minimal checks that the name is reasonable. In
4529 -- particular that no spaces or other obviously incorrect characters
4530 -- appear. This is only a warning, since any characters are allowed.
4531 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4533 ----------------------------------
4534 -- Check_Form_Of_Interface_Name --
4535 ----------------------------------
4537 procedure Check_Form_Of_Interface_Name
4539 Ext_Name_Case : Boolean)
4541 S : constant String_Id := Strval (Expr_Value_S (SN));
4542 SL : constant Nat := String_Length (S);
4547 Error_Msg_N ("interface name cannot be null string", SN);
4550 for J in 1 .. SL loop
4551 C := Get_String_Char (S, J);
4553 -- Look for dubious character and issue unconditional warning.
4554 -- Definitely dubious if not in character range.
4556 if not In_Character_Range (C)
4558 -- For all cases except CLI target,
4559 -- commas, spaces and slashes are dubious (in CLI, we use
4560 -- commas and backslashes in external names to specify
4561 -- assembly version and public key, while slashes and spaces
4562 -- can be used in names to mark nested classes and
4565 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4566 and then (Get_Character (C) = ','
4568 Get_Character (C) = '\'))
4569 or else (VM_Target /= CLI_Target
4570 and then (Get_Character (C) = ' '
4572 Get_Character (C) = '/'))
4575 ("?interface name contains illegal character",
4576 Sloc (SN) + Source_Ptr (J));
4579 end Check_Form_Of_Interface_Name;
4581 -- Start of processing for Process_Interface_Name
4584 if No (Link_Arg) then
4585 if No (Ext_Arg) then
4586 if VM_Target = CLI_Target
4587 and then Ekind (Subprogram_Def) = E_Package
4588 and then Nkind (Parent (Subprogram_Def)) =
4589 N_Package_Specification
4590 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4595 (Generic_Parent (Parent (Subprogram_Def))));
4600 elsif Chars (Ext_Arg) = Name_Link_Name then
4602 Link_Nam := Expression (Ext_Arg);
4605 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4606 Ext_Nam := Expression (Ext_Arg);
4611 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4612 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4613 Ext_Nam := Expression (Ext_Arg);
4614 Link_Nam := Expression (Link_Arg);
4617 -- Check expressions for external name and link name are static
4619 if Present (Ext_Nam) then
4620 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4621 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4623 -- Verify that external name is not the name of a local entity,
4624 -- which would hide the imported one and could lead to run-time
4625 -- surprises. The problem can only arise for entities declared in
4626 -- a package body (otherwise the external name is fully qualified
4627 -- and will not conflict).
4635 if Prag_Id = Pragma_Import then
4636 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4638 E := Entity_Id (Get_Name_Table_Info (Nam));
4640 if Nam /= Chars (Subprogram_Def)
4641 and then Present (E)
4642 and then not Is_Overloadable (E)
4643 and then Is_Immediately_Visible (E)
4644 and then not Is_Imported (E)
4645 and then Ekind (Scope (E)) = E_Package
4648 while Present (Par) loop
4649 if Nkind (Par) = N_Package_Body then
4650 Error_Msg_Sloc := Sloc (E);
4652 ("imported entity is hidden by & declared#",
4657 Par := Parent (Par);
4664 if Present (Link_Nam) then
4665 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4666 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4669 -- If there is no link name, just set the external name
4671 if No (Link_Nam) then
4672 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4674 -- For the Link_Name case, the given literal is preceded by an
4675 -- asterisk, which indicates to GCC that the given name should be
4676 -- taken literally, and in particular that no prepending of
4677 -- underlines should occur, even in systems where this is the
4683 if VM_Target = No_VM then
4684 Store_String_Char (Get_Char_Code ('*'));
4687 String_Val := Strval (Expr_Value_S (Link_Nam));
4688 Store_String_Chars (String_Val);
4690 Make_String_Literal (Sloc (Link_Nam),
4691 Strval => End_String);
4694 Set_Encoded_Interface_Name
4695 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4697 -- We allow duplicated export names in CIL, as they are always
4698 -- enclosed in a namespace that differentiates them, and overloaded
4699 -- entities are supported by the VM.
4701 if Convention (Subprogram_Def) /= Convention_CIL then
4702 Check_Duplicated_Export_Name (Link_Nam);
4704 end Process_Interface_Name;
4706 -----------------------------------------
4707 -- Process_Interrupt_Or_Attach_Handler --
4708 -----------------------------------------
4710 procedure Process_Interrupt_Or_Attach_Handler is
4711 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4712 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4713 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4716 Set_Is_Interrupt_Handler (Handler_Proc);
4718 -- If the pragma is not associated with a handler procedure within a
4719 -- protected type, then it must be for a nonprotected procedure for
4720 -- the AAMP target, in which case we don't associate a representation
4721 -- item with the procedure's scope.
4723 if Ekind (Proc_Scope) = E_Protected_Type then
4724 if Prag_Id = Pragma_Interrupt_Handler
4726 Prag_Id = Pragma_Attach_Handler
4728 Record_Rep_Item (Proc_Scope, N);
4731 end Process_Interrupt_Or_Attach_Handler;
4733 --------------------------------------------------
4734 -- Process_Restrictions_Or_Restriction_Warnings --
4735 --------------------------------------------------
4737 -- Note: some of the simple identifier cases were handled in par-prag,
4738 -- but it is harmless (and more straightforward) to simply handle all
4739 -- cases here, even if it means we repeat a bit of work in some cases.
4741 procedure Process_Restrictions_Or_Restriction_Warnings
4745 R_Id : Restriction_Id;
4750 procedure Check_Unit_Name (N : Node_Id);
4751 -- Checks unit name parameter for No_Dependence. Returns if it has
4752 -- an appropriate form, otherwise raises pragma argument error.
4754 ---------------------
4755 -- Check_Unit_Name --
4756 ---------------------
4758 procedure Check_Unit_Name (N : Node_Id) is
4760 if Nkind (N) = N_Selected_Component then
4761 Check_Unit_Name (Prefix (N));
4762 Check_Unit_Name (Selector_Name (N));
4764 elsif Nkind (N) = N_Identifier then
4769 ("wrong form for unit name for No_Dependence", N);
4771 end Check_Unit_Name;
4773 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4776 -- Ignore all Restrictions pragma in CodePeer mode
4778 if CodePeer_Mode then
4782 Check_Ada_83_Warning;
4783 Check_At_Least_N_Arguments (1);
4784 Check_Valid_Configuration_Pragma;
4787 while Present (Arg) loop
4789 Expr := Get_Pragma_Arg (Arg);
4791 -- Case of no restriction identifier present
4793 if Id = No_Name then
4794 if Nkind (Expr) /= N_Identifier then
4796 ("invalid form for restriction", Arg);
4801 (Process_Restriction_Synonyms (Expr));
4803 if R_Id not in All_Boolean_Restrictions then
4804 Error_Msg_Name_1 := Pname;
4806 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4808 -- Check for possible misspelling
4810 for J in Restriction_Id loop
4812 Rnm : constant String := Restriction_Id'Image (J);
4815 Name_Buffer (1 .. Rnm'Length) := Rnm;
4816 Name_Len := Rnm'Length;
4817 Set_Casing (All_Lower_Case);
4819 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4821 (Identifier_Casing (Current_Source_File));
4822 Error_Msg_String (1 .. Rnm'Length) :=
4823 Name_Buffer (1 .. Name_Len);
4824 Error_Msg_Strlen := Rnm'Length;
4825 Error_Msg_N -- CODEFIX
4826 ("\possible misspelling of ""~""",
4827 Get_Pragma_Arg (Arg));
4836 if Implementation_Restriction (R_Id) then
4837 Check_Restriction (No_Implementation_Restrictions, Arg);
4840 -- If this is a warning, then set the warning unless we already
4841 -- have a real restriction active (we never want a warning to
4842 -- override a real restriction).
4845 if not Restriction_Active (R_Id) then
4846 Set_Restriction (R_Id, N);
4847 Restriction_Warnings (R_Id) := True;
4850 -- If real restriction case, then set it and make sure that the
4851 -- restriction warning flag is off, since a real restriction
4852 -- always overrides a warning.
4855 Set_Restriction (R_Id, N);
4856 Restriction_Warnings (R_Id) := False;
4859 -- Check for obsolescent restrictions in Ada 2005 mode
4862 and then Ada_Version >= Ada_2005
4863 and then (R_Id = No_Asynchronous_Control
4865 R_Id = No_Unchecked_Deallocation
4867 R_Id = No_Unchecked_Conversion)
4869 Check_Restriction (No_Obsolescent_Features, N);
4872 -- A very special case that must be processed here: pragma
4873 -- Restrictions (No_Exceptions) turns off all run-time
4874 -- checking. This is a bit dubious in terms of the formal
4875 -- language definition, but it is what is intended by RM
4876 -- H.4(12). Restriction_Warnings never affects generated code
4877 -- so this is done only in the real restriction case.
4879 if R_Id = No_Exceptions and then not Warn then
4880 Scope_Suppress := (others => True);
4883 -- Case of No_Dependence => unit-name. Note that the parser
4884 -- already made the necessary entry in the No_Dependence table.
4886 elsif Id = Name_No_Dependence then
4887 Check_Unit_Name (Expr);
4889 -- All other cases of restriction identifier present
4892 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4893 Analyze_And_Resolve (Expr, Any_Integer);
4895 if R_Id not in All_Parameter_Restrictions then
4897 ("invalid restriction parameter identifier", Arg);
4899 elsif not Is_OK_Static_Expression (Expr) then
4900 Flag_Non_Static_Expr
4901 ("value must be static expression!", Expr);
4904 elsif not Is_Integer_Type (Etype (Expr))
4905 or else Expr_Value (Expr) < 0
4908 ("value must be non-negative integer", Arg);
4911 -- Restriction pragma is active
4913 Val := Expr_Value (Expr);
4915 if not UI_Is_In_Int_Range (Val) then
4917 ("pragma ignored, value too large?", Arg);
4920 -- Warning case. If the real restriction is active, then we
4921 -- ignore the request, since warning never overrides a real
4922 -- restriction. Otherwise we set the proper warning. Note that
4923 -- this circuit sets the warning again if it is already set,
4924 -- which is what we want, since the constant may have changed.
4927 if not Restriction_Active (R_Id) then
4929 (R_Id, N, Integer (UI_To_Int (Val)));
4930 Restriction_Warnings (R_Id) := True;
4933 -- Real restriction case, set restriction and make sure warning
4934 -- flag is off since real restriction always overrides warning.
4937 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4938 Restriction_Warnings (R_Id) := False;
4944 end Process_Restrictions_Or_Restriction_Warnings;
4946 ---------------------------------
4947 -- Process_Suppress_Unsuppress --
4948 ---------------------------------
4950 -- Note: this procedure makes entries in the check suppress data
4951 -- structures managed by Sem. See spec of package Sem for full
4952 -- details on how we handle recording of check suppression.
4954 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4959 In_Package_Spec : constant Boolean :=
4960 Is_Package_Or_Generic_Package (Current_Scope)
4961 and then not In_Package_Body (Current_Scope);
4963 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4964 -- Used to suppress a single check on the given entity
4966 --------------------------------
4967 -- Suppress_Unsuppress_Echeck --
4968 --------------------------------
4970 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4972 Set_Checks_May_Be_Suppressed (E);
4974 if In_Package_Spec then
4975 Push_Global_Suppress_Stack_Entry
4978 Suppress => Suppress_Case);
4981 Push_Local_Suppress_Stack_Entry
4984 Suppress => Suppress_Case);
4987 -- If this is a first subtype, and the base type is distinct,
4988 -- then also set the suppress flags on the base type.
4990 if Is_First_Subtype (E)
4991 and then Etype (E) /= E
4993 Suppress_Unsuppress_Echeck (Etype (E), C);
4995 end Suppress_Unsuppress_Echeck;
4997 -- Start of processing for Process_Suppress_Unsuppress
5000 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
5001 -- we want to generate checks for analysis purposes, as set by -gnatC
5003 if CodePeer_Mode and then Comes_From_Source (N) then
5007 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5008 -- declarative part or a package spec (RM 11.5(5)).
5010 if not Is_Configuration_Pragma then
5011 Check_Is_In_Decl_Part_Or_Package_Spec;
5014 Check_At_Least_N_Arguments (1);
5015 Check_At_Most_N_Arguments (2);
5016 Check_No_Identifier (Arg1);
5017 Check_Arg_Is_Identifier (Arg1);
5019 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5021 if C = No_Check_Id then
5023 ("argument of pragma% is not valid check name", Arg1);
5026 if not Suppress_Case
5027 and then (C = All_Checks or else C = Overflow_Check)
5029 Opt.Overflow_Checks_Unsuppressed := True;
5032 if Arg_Count = 1 then
5034 -- Make an entry in the local scope suppress table. This is the
5035 -- table that directly shows the current value of the scope
5036 -- suppress check for any check id value.
5038 if C = All_Checks then
5040 -- For All_Checks, we set all specific predefined checks with
5041 -- the exception of Elaboration_Check, which is handled
5042 -- specially because of not wanting All_Checks to have the
5043 -- effect of deactivating static elaboration order processing.
5045 for J in Scope_Suppress'Range loop
5046 if J /= Elaboration_Check then
5047 Scope_Suppress (J) := Suppress_Case;
5051 -- If not All_Checks, and predefined check, then set appropriate
5052 -- scope entry. Note that we will set Elaboration_Check if this
5053 -- is explicitly specified.
5055 elsif C in Predefined_Check_Id then
5056 Scope_Suppress (C) := Suppress_Case;
5059 -- Also make an entry in the Local_Entity_Suppress table
5061 Push_Local_Suppress_Stack_Entry
5064 Suppress => Suppress_Case);
5066 -- Case of two arguments present, where the check is suppressed for
5067 -- a specified entity (given as the second argument of the pragma)
5070 -- This is obsolescent in Ada 2005 mode
5072 if Ada_Version >= Ada_2005 then
5073 Check_Restriction (No_Obsolescent_Features, Arg2);
5076 Check_Optional_Identifier (Arg2, Name_On);
5077 E_Id := Get_Pragma_Arg (Arg2);
5080 if not Is_Entity_Name (E_Id) then
5082 ("second argument of pragma% must be entity name", Arg2);
5091 -- Enforce RM 11.5(7) which requires that for a pragma that
5092 -- appears within a package spec, the named entity must be
5093 -- within the package spec. We allow the package name itself
5094 -- to be mentioned since that makes sense, although it is not
5095 -- strictly allowed by 11.5(7).
5098 and then E /= Current_Scope
5099 and then Scope (E) /= Current_Scope
5102 ("entity in pragma% is not in package spec (RM 11.5(7))",
5106 -- Loop through homonyms. As noted below, in the case of a package
5107 -- spec, only homonyms within the package spec are considered.
5110 Suppress_Unsuppress_Echeck (E, C);
5112 if Is_Generic_Instance (E)
5113 and then Is_Subprogram (E)
5114 and then Present (Alias (E))
5116 Suppress_Unsuppress_Echeck (Alias (E), C);
5119 -- Move to next homonym if not aspect spec case
5121 exit when From_Aspect_Specification (N);
5125 -- If we are within a package specification, the pragma only
5126 -- applies to homonyms in the same scope.
5128 exit when In_Package_Spec
5129 and then Scope (E) /= Current_Scope;
5132 end Process_Suppress_Unsuppress;
5138 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5140 if Is_Imported (E) then
5142 ("cannot export entity& that was previously imported", Arg);
5144 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5146 ("cannot export entity& that has an address clause", Arg);
5149 Set_Is_Exported (E);
5151 -- Generate a reference for entity explicitly, because the
5152 -- identifier may be overloaded and name resolution will not
5155 Generate_Reference (E, Arg);
5157 -- Deal with exporting non-library level entity
5159 if not Is_Library_Level_Entity (E) then
5161 -- Not allowed at all for subprograms
5163 if Is_Subprogram (E) then
5164 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5166 -- Otherwise set public and statically allocated
5170 Set_Is_Statically_Allocated (E);
5172 -- Warn if the corresponding W flag is set and the pragma comes
5173 -- from source. The latter may not be true e.g. on VMS where we
5174 -- expand export pragmas for exception codes associated with
5175 -- imported or exported exceptions. We do not want to generate
5176 -- a warning for something that the user did not write.
5178 if Warn_On_Export_Import
5179 and then Comes_From_Source (Arg)
5182 ("?& has been made static as a result of Export", Arg, E);
5184 ("\this usage is non-standard and non-portable", Arg);
5189 if Warn_On_Export_Import and then Is_Type (E) then
5190 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5193 if Warn_On_Export_Import and Inside_A_Generic then
5195 ("all instances of& will have the same external name?", Arg, E);
5199 ----------------------------------------------
5200 -- Set_Extended_Import_Export_External_Name --
5201 ----------------------------------------------
5203 procedure Set_Extended_Import_Export_External_Name
5204 (Internal_Ent : Entity_Id;
5205 Arg_External : Node_Id)
5207 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5211 if No (Arg_External) then
5215 Check_Arg_Is_External_Name (Arg_External);
5217 if Nkind (Arg_External) = N_String_Literal then
5218 if String_Length (Strval (Arg_External)) = 0 then
5221 New_Name := Adjust_External_Name_Case (Arg_External);
5224 elsif Nkind (Arg_External) = N_Identifier then
5225 New_Name := Get_Default_External_Name (Arg_External);
5227 -- Check_Arg_Is_External_Name should let through only identifiers and
5228 -- string literals or static string expressions (which are folded to
5229 -- string literals).
5232 raise Program_Error;
5235 -- If we already have an external name set (by a prior normal Import
5236 -- or Export pragma), then the external names must match
5238 if Present (Interface_Name (Internal_Ent)) then
5239 Check_Matching_Internal_Names : declare
5240 S1 : constant String_Id := Strval (Old_Name);
5241 S2 : constant String_Id := Strval (New_Name);
5244 -- Called if names do not match
5250 procedure Mismatch is
5252 Error_Msg_Sloc := Sloc (Old_Name);
5254 ("external name does not match that given #",
5258 -- Start of processing for Check_Matching_Internal_Names
5261 if String_Length (S1) /= String_Length (S2) then
5265 for J in 1 .. String_Length (S1) loop
5266 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5271 end Check_Matching_Internal_Names;
5273 -- Otherwise set the given name
5276 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5277 Check_Duplicated_Export_Name (New_Name);
5279 end Set_Extended_Import_Export_External_Name;
5285 procedure Set_Imported (E : Entity_Id) is
5287 -- Error message if already imported or exported
5289 if Is_Exported (E) or else Is_Imported (E) then
5291 -- Error if being set Exported twice
5293 if Is_Exported (E) then
5294 Error_Msg_NE ("entity& was previously exported", N, E);
5296 -- OK if Import/Interface case
5298 elsif Import_Interface_Present (N) then
5301 -- Error if being set Imported twice
5304 Error_Msg_NE ("entity& was previously imported", N, E);
5307 Error_Msg_Name_1 := Pname;
5309 ("\(pragma% applies to all previous entities)", N);
5311 Error_Msg_Sloc := Sloc (E);
5312 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5314 -- Here if not previously imported or exported, OK to import
5317 Set_Is_Imported (E);
5319 -- If the entity is an object that is not at the library level,
5320 -- then it is statically allocated. We do not worry about objects
5321 -- with address clauses in this context since they are not really
5322 -- imported in the linker sense.
5325 and then not Is_Library_Level_Entity (E)
5326 and then No (Address_Clause (E))
5328 Set_Is_Statically_Allocated (E);
5335 -------------------------
5336 -- Set_Mechanism_Value --
5337 -------------------------
5339 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5340 -- analyzed, since it is semantic nonsense), so we get it in the exact
5341 -- form created by the parser.
5343 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5346 Mech_Name_Id : Name_Id;
5348 procedure Bad_Class;
5349 -- Signal bad descriptor class name
5351 procedure Bad_Mechanism;
5352 -- Signal bad mechanism name
5358 procedure Bad_Class is
5360 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5363 -------------------------
5364 -- Bad_Mechanism_Value --
5365 -------------------------
5367 procedure Bad_Mechanism is
5369 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5372 -- Start of processing for Set_Mechanism_Value
5375 if Mechanism (Ent) /= Default_Mechanism then
5377 ("mechanism for & has already been set", Mech_Name, Ent);
5380 -- MECHANISM_NAME ::= value | reference | descriptor |
5383 if Nkind (Mech_Name) = N_Identifier then
5384 if Chars (Mech_Name) = Name_Value then
5385 Set_Mechanism (Ent, By_Copy);
5388 elsif Chars (Mech_Name) = Name_Reference then
5389 Set_Mechanism (Ent, By_Reference);
5392 elsif Chars (Mech_Name) = Name_Descriptor then
5393 Check_VMS (Mech_Name);
5395 -- Descriptor => Short_Descriptor if pragma was given
5397 if Short_Descriptors then
5398 Set_Mechanism (Ent, By_Short_Descriptor);
5400 Set_Mechanism (Ent, By_Descriptor);
5405 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5406 Check_VMS (Mech_Name);
5407 Set_Mechanism (Ent, By_Short_Descriptor);
5410 elsif Chars (Mech_Name) = Name_Copy then
5412 ("bad mechanism name, Value assumed", Mech_Name);
5418 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5419 -- short_descriptor (CLASS_NAME)
5420 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5422 -- Note: this form is parsed as an indexed component
5424 elsif Nkind (Mech_Name) = N_Indexed_Component then
5425 Class := First (Expressions (Mech_Name));
5427 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5428 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5429 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5430 or else Present (Next (Class))
5434 Mech_Name_Id := Chars (Prefix (Mech_Name));
5436 -- Change Descriptor => Short_Descriptor if pragma was given
5438 if Mech_Name_Id = Name_Descriptor
5439 and then Short_Descriptors
5441 Mech_Name_Id := Name_Short_Descriptor;
5445 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5446 -- short_descriptor (Class => CLASS_NAME)
5447 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5449 -- Note: this form is parsed as a function call
5451 elsif Nkind (Mech_Name) = N_Function_Call then
5452 Param := First (Parameter_Associations (Mech_Name));
5454 if Nkind (Name (Mech_Name)) /= N_Identifier
5455 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5456 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5457 or else Present (Next (Param))
5458 or else No (Selector_Name (Param))
5459 or else Chars (Selector_Name (Param)) /= Name_Class
5463 Class := Explicit_Actual_Parameter (Param);
5464 Mech_Name_Id := Chars (Name (Mech_Name));
5471 -- Fall through here with Class set to descriptor class name
5473 Check_VMS (Mech_Name);
5475 if Nkind (Class) /= N_Identifier then
5478 elsif Mech_Name_Id = Name_Descriptor
5479 and then Chars (Class) = Name_UBS
5481 Set_Mechanism (Ent, By_Descriptor_UBS);
5483 elsif Mech_Name_Id = Name_Descriptor
5484 and then Chars (Class) = Name_UBSB
5486 Set_Mechanism (Ent, By_Descriptor_UBSB);
5488 elsif Mech_Name_Id = Name_Descriptor
5489 and then Chars (Class) = Name_UBA
5491 Set_Mechanism (Ent, By_Descriptor_UBA);
5493 elsif Mech_Name_Id = Name_Descriptor
5494 and then Chars (Class) = Name_S
5496 Set_Mechanism (Ent, By_Descriptor_S);
5498 elsif Mech_Name_Id = Name_Descriptor
5499 and then Chars (Class) = Name_SB
5501 Set_Mechanism (Ent, By_Descriptor_SB);
5503 elsif Mech_Name_Id = Name_Descriptor
5504 and then Chars (Class) = Name_A
5506 Set_Mechanism (Ent, By_Descriptor_A);
5508 elsif Mech_Name_Id = Name_Descriptor
5509 and then Chars (Class) = Name_NCA
5511 Set_Mechanism (Ent, By_Descriptor_NCA);
5513 elsif Mech_Name_Id = Name_Short_Descriptor
5514 and then Chars (Class) = Name_UBS
5516 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5518 elsif Mech_Name_Id = Name_Short_Descriptor
5519 and then Chars (Class) = Name_UBSB
5521 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5523 elsif Mech_Name_Id = Name_Short_Descriptor
5524 and then Chars (Class) = Name_UBA
5526 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5528 elsif Mech_Name_Id = Name_Short_Descriptor
5529 and then Chars (Class) = Name_S
5531 Set_Mechanism (Ent, By_Short_Descriptor_S);
5533 elsif Mech_Name_Id = Name_Short_Descriptor
5534 and then Chars (Class) = Name_SB
5536 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5538 elsif Mech_Name_Id = Name_Short_Descriptor
5539 and then Chars (Class) = Name_A
5541 Set_Mechanism (Ent, By_Short_Descriptor_A);
5543 elsif Mech_Name_Id = Name_Short_Descriptor
5544 and then Chars (Class) = Name_NCA
5546 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5551 end Set_Mechanism_Value;
5553 ---------------------------
5554 -- Set_Ravenscar_Profile --
5555 ---------------------------
5557 -- The tasks to be done here are
5559 -- Set required policies
5561 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5562 -- pragma Locking_Policy (Ceiling_Locking)
5564 -- Set Detect_Blocking mode
5566 -- Set required restrictions (see System.Rident for detailed list)
5568 -- Set the No_Dependence rules
5569 -- No_Dependence => Ada.Asynchronous_Task_Control
5570 -- No_Dependence => Ada.Calendar
5571 -- No_Dependence => Ada.Execution_Time.Group_Budget
5572 -- No_Dependence => Ada.Execution_Time.Timers
5573 -- No_Dependence => Ada.Task_Attributes
5574 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5576 procedure Set_Ravenscar_Profile (N : Node_Id) is
5577 Prefix_Entity : Entity_Id;
5578 Selector_Entity : Entity_Id;
5579 Prefix_Node : Node_Id;
5583 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5585 if Task_Dispatching_Policy /= ' '
5586 and then Task_Dispatching_Policy /= 'F'
5588 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5589 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5591 -- Set the FIFO_Within_Priorities policy, but always preserve
5592 -- System_Location since we like the error message with the run time
5596 Task_Dispatching_Policy := 'F';
5598 if Task_Dispatching_Policy_Sloc /= System_Location then
5599 Task_Dispatching_Policy_Sloc := Loc;
5603 -- pragma Locking_Policy (Ceiling_Locking)
5605 if Locking_Policy /= ' '
5606 and then Locking_Policy /= 'C'
5608 Error_Msg_Sloc := Locking_Policy_Sloc;
5609 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5611 -- Set the Ceiling_Locking policy, but preserve System_Location since
5612 -- we like the error message with the run time name.
5615 Locking_Policy := 'C';
5617 if Locking_Policy_Sloc /= System_Location then
5618 Locking_Policy_Sloc := Loc;
5622 -- pragma Detect_Blocking
5624 Detect_Blocking := True;
5626 -- Set the corresponding restrictions
5628 Set_Profile_Restrictions
5629 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5631 -- Set the No_Dependence restrictions
5633 -- The following No_Dependence restrictions:
5634 -- No_Dependence => Ada.Asynchronous_Task_Control
5635 -- No_Dependence => Ada.Calendar
5636 -- No_Dependence => Ada.Task_Attributes
5637 -- are already set by previous call to Set_Profile_Restrictions.
5639 -- Set the following restrictions which were added to Ada 2005:
5640 -- No_Dependence => Ada.Execution_Time.Group_Budget
5641 -- No_Dependence => Ada.Execution_Time.Timers
5643 if Ada_Version >= Ada_2005 then
5644 Name_Buffer (1 .. 3) := "ada";
5647 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5649 Name_Buffer (1 .. 14) := "execution_time";
5652 Selector_Entity := Make_Identifier (Loc, Name_Find);
5655 Make_Selected_Component
5657 Prefix => Prefix_Entity,
5658 Selector_Name => Selector_Entity);
5660 Name_Buffer (1 .. 13) := "group_budgets";
5663 Selector_Entity := Make_Identifier (Loc, Name_Find);
5666 Make_Selected_Component
5668 Prefix => Prefix_Node,
5669 Selector_Name => Selector_Entity);
5671 Set_Restriction_No_Dependence
5673 Warn => Treat_Restrictions_As_Warnings,
5674 Profile => Ravenscar);
5676 Name_Buffer (1 .. 6) := "timers";
5679 Selector_Entity := Make_Identifier (Loc, Name_Find);
5682 Make_Selected_Component
5684 Prefix => Prefix_Node,
5685 Selector_Name => Selector_Entity);
5687 Set_Restriction_No_Dependence
5689 Warn => Treat_Restrictions_As_Warnings,
5690 Profile => Ravenscar);
5693 -- Set the following restrictions which was added to Ada 2012 (see
5695 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5697 if Ada_Version >= Ada_2012 then
5698 Name_Buffer (1 .. 6) := "system";
5701 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5703 Name_Buffer (1 .. 15) := "multiprocessors";
5706 Selector_Entity := Make_Identifier (Loc, Name_Find);
5709 Make_Selected_Component
5711 Prefix => Prefix_Entity,
5712 Selector_Name => Selector_Entity);
5714 Name_Buffer (1 .. 19) := "dispatching_domains";
5717 Selector_Entity := Make_Identifier (Loc, Name_Find);
5720 Make_Selected_Component
5722 Prefix => Prefix_Node,
5723 Selector_Name => Selector_Entity);
5725 Set_Restriction_No_Dependence
5727 Warn => Treat_Restrictions_As_Warnings,
5728 Profile => Ravenscar);
5730 end Set_Ravenscar_Profile;
5732 -- Start of processing for Analyze_Pragma
5735 -- The following code is a defense against recursion. Not clear that
5736 -- this can happen legitimately, but perhaps some error situations
5737 -- can cause it, and we did see this recursion during testing.
5739 if Analyzed (N) then
5742 Set_Analyzed (N, True);
5745 -- Deal with unrecognized pragma
5747 if not Is_Pragma_Name (Pname) then
5748 if Warn_On_Unrecognized_Pragma then
5749 Error_Msg_Name_1 := Pname;
5750 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5752 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5753 if Is_Bad_Spelling_Of (Pname, PN) then
5754 Error_Msg_Name_1 := PN;
5755 Error_Msg_N -- CODEFIX
5756 ("\?possible misspelling of %!", Pragma_Identifier (N));
5765 -- Here to start processing for recognized pragma
5767 Prag_Id := Get_Pragma_Id (Pname);
5777 if Present (Pragma_Argument_Associations (N)) then
5778 Arg_Count := List_Length (Pragma_Argument_Associations (N));
5779 Arg1 := First (Pragma_Argument_Associations (N));
5781 if Present (Arg1) then
5782 Arg2 := Next (Arg1);
5784 if Present (Arg2) then
5785 Arg3 := Next (Arg2);
5787 if Present (Arg3) then
5788 Arg4 := Next (Arg3);
5794 -- An enumeration type defines the pragmas that are supported by the
5795 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5796 -- into the corresponding enumeration value for the following case.
5804 -- pragma Abort_Defer;
5806 when Pragma_Abort_Defer =>
5808 Check_Arg_Count (0);
5810 -- The only required semantic processing is to check the
5811 -- placement. This pragma must appear at the start of the
5812 -- statement sequence of a handled sequence of statements.
5814 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5815 or else N /= First (Statements (Parent (N)))
5826 -- Note: this pragma also has some specific processing in Par.Prag
5827 -- because we want to set the Ada version mode during parsing.
5829 when Pragma_Ada_83 =>
5831 Check_Arg_Count (0);
5833 -- We really should check unconditionally for proper configuration
5834 -- pragma placement, since we really don't want mixed Ada modes
5835 -- within a single unit, and the GNAT reference manual has always
5836 -- said this was a configuration pragma, but we did not check and
5837 -- are hesitant to add the check now.
5839 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5840 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5841 -- or Ada 2012 mode.
5843 if Ada_Version >= Ada_2005 then
5844 Check_Valid_Configuration_Pragma;
5847 -- Now set Ada 83 mode
5849 Ada_Version := Ada_83;
5850 Ada_Version_Explicit := Ada_Version;
5858 -- Note: this pragma also has some specific processing in Par.Prag
5859 -- because we want to set the Ada 83 version mode during parsing.
5861 when Pragma_Ada_95 =>
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 with Ada 83
5872 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5874 if Ada_Version >= Ada_2005 then
5875 Check_Valid_Configuration_Pragma;
5878 -- Now set Ada 95 mode
5880 Ada_Version := Ada_95;
5881 Ada_Version_Explicit := Ada_Version;
5883 ---------------------
5884 -- Ada_05/Ada_2005 --
5885 ---------------------
5888 -- pragma Ada_05 (LOCAL_NAME);
5891 -- pragma Ada_2005 (LOCAL_NAME):
5893 -- Note: these pragmas also have some specific processing in Par.Prag
5894 -- because we want to set the Ada 2005 version mode during parsing.
5896 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5902 if Arg_Count = 1 then
5903 Check_Arg_Is_Local_Name (Arg1);
5904 E_Id := Get_Pragma_Arg (Arg1);
5906 if Etype (E_Id) = Any_Type then
5910 Set_Is_Ada_2005_Only (Entity (E_Id));
5913 Check_Arg_Count (0);
5915 -- For Ada_2005 we unconditionally enforce the documented
5916 -- configuration pragma placement, since we do not want to
5917 -- tolerate mixed modes in a unit involving Ada 2005. That
5918 -- would cause real difficulties for those cases where there
5919 -- are incompatibilities between Ada 95 and Ada 2005.
5921 Check_Valid_Configuration_Pragma;
5923 -- Now set appropriate Ada mode
5925 Ada_Version := Ada_2005;
5926 Ada_Version_Explicit := Ada_2005;
5930 ---------------------
5931 -- Ada_12/Ada_2012 --
5932 ---------------------
5935 -- pragma Ada_12 (LOCAL_NAME);
5938 -- pragma Ada_2012 (LOCAL_NAME):
5940 -- Note: these pragmas also have some specific processing in Par.Prag
5941 -- because we want to set the Ada 2012 version mode during parsing.
5943 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5949 if Arg_Count = 1 then
5950 Check_Arg_Is_Local_Name (Arg1);
5951 E_Id := Get_Pragma_Arg (Arg1);
5953 if Etype (E_Id) = Any_Type then
5957 Set_Is_Ada_2012_Only (Entity (E_Id));
5960 Check_Arg_Count (0);
5962 -- For Ada_2012 we unconditionally enforce the documented
5963 -- configuration pragma placement, since we do not want to
5964 -- tolerate mixed modes in a unit involving Ada 2012. That
5965 -- would cause real difficulties for those cases where there
5966 -- are incompatibilities between Ada 95 and Ada 2012. We could
5967 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5969 Check_Valid_Configuration_Pragma;
5971 -- Now set appropriate Ada mode
5973 Ada_Version := Ada_2012;
5974 Ada_Version_Explicit := Ada_2012;
5978 ----------------------
5979 -- All_Calls_Remote --
5980 ----------------------
5982 -- pragma All_Calls_Remote [(library_package_NAME)];
5984 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5985 Lib_Entity : Entity_Id;
5988 Check_Ada_83_Warning;
5989 Check_Valid_Library_Unit_Pragma;
5991 if Nkind (N) = N_Null_Statement then
5995 Lib_Entity := Find_Lib_Unit_Name;
5997 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5999 if Present (Lib_Entity)
6000 and then not Debug_Flag_U
6002 if not Is_Remote_Call_Interface (Lib_Entity) then
6003 Error_Pragma ("pragma% only apply to rci unit");
6005 -- Set flag for entity of the library unit
6008 Set_Has_All_Calls_Remote (Lib_Entity);
6012 end All_Calls_Remote;
6018 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6019 -- ARG ::= NAME | EXPRESSION
6021 -- The first two arguments are by convention intended to refer to an
6022 -- external tool and a tool-specific function. These arguments are
6025 when Pragma_Annotate => Annotate : begin
6027 Check_At_Least_N_Arguments (1);
6028 Check_Arg_Is_Identifier (Arg1);
6029 Check_No_Identifiers;
6037 -- Second unanalyzed parameter is optional
6043 while Present (Arg) loop
6044 Exp := Get_Pragma_Arg (Arg);
6047 if Is_Entity_Name (Exp) then
6050 -- For string literals, we assume Standard_String as the
6051 -- type, unless the string contains wide or wide_wide
6054 elsif Nkind (Exp) = N_String_Literal then
6055 if Has_Wide_Wide_Character (Exp) then
6056 Resolve (Exp, Standard_Wide_Wide_String);
6057 elsif Has_Wide_Character (Exp) then
6058 Resolve (Exp, Standard_Wide_String);
6060 Resolve (Exp, Standard_String);
6063 elsif Is_Overloaded (Exp) then
6065 ("ambiguous argument for pragma%", Exp);
6081 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6082 -- [, [Message =>] Static_String_EXPRESSION]);
6084 when Pragma_Assert => Assert : declare
6090 Check_At_Least_N_Arguments (1);
6091 Check_At_Most_N_Arguments (2);
6092 Check_Arg_Order ((Name_Check, Name_Message));
6093 Check_Optional_Identifier (Arg1, Name_Check);
6095 -- We treat pragma Assert as equivalent to:
6097 -- pragma Check (Assertion, condition [, msg]);
6099 -- So rewrite pragma in this manner, and analyze the result
6101 Expr := Get_Pragma_Arg (Arg1);
6103 Make_Pragma_Argument_Association (Loc,
6104 Expression => Make_Identifier (Loc, Name_Assertion)),
6106 Make_Pragma_Argument_Association (Sloc (Expr),
6107 Expression => Expr));
6109 if Arg_Count > 1 then
6110 Check_Optional_Identifier (Arg2, Name_Message);
6111 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6112 Append_To (Newa, Relocate_Node (Arg2));
6117 Chars => Name_Check,
6118 Pragma_Argument_Associations => Newa));
6122 ----------------------
6123 -- Assertion_Policy --
6124 ----------------------
6126 -- pragma Assertion_Policy (Check | Ignore)
6128 when Pragma_Assertion_Policy => Assertion_Policy : declare
6133 Check_Valid_Configuration_Pragma;
6134 Check_Arg_Count (1);
6135 Check_No_Identifiers;
6136 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6138 -- We treat pragma Assertion_Policy as equivalent to:
6140 -- pragma Check_Policy (Assertion, policy)
6142 -- So rewrite the pragma in that manner and link on to the chain
6143 -- of Check_Policy pragmas, marking the pragma as analyzed.
6145 Policy := Get_Pragma_Arg (Arg1);
6149 Chars => Name_Check_Policy,
6151 Pragma_Argument_Associations => New_List (
6152 Make_Pragma_Argument_Association (Loc,
6153 Expression => Make_Identifier (Loc, Name_Assertion)),
6155 Make_Pragma_Argument_Association (Loc,
6157 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6160 Set_Next_Pragma (N, Opt.Check_Policy_List);
6161 Opt.Check_Policy_List := N;
6162 end Assertion_Policy;
6164 ------------------------------
6165 -- Assume_No_Invalid_Values --
6166 ------------------------------
6168 -- pragma Assume_No_Invalid_Values (On | Off);
6170 when Pragma_Assume_No_Invalid_Values =>
6172 Check_Valid_Configuration_Pragma;
6173 Check_Arg_Count (1);
6174 Check_No_Identifiers;
6175 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6177 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6178 Assume_No_Invalid_Values := True;
6180 Assume_No_Invalid_Values := False;
6187 -- pragma AST_Entry (entry_IDENTIFIER);
6189 when Pragma_AST_Entry => AST_Entry : declare
6195 Check_Arg_Count (1);
6196 Check_No_Identifiers;
6197 Check_Arg_Is_Local_Name (Arg1);
6198 Ent := Entity (Get_Pragma_Arg (Arg1));
6200 -- Note: the implementation of the AST_Entry pragma could handle
6201 -- the entry family case fine, but for now we are consistent with
6202 -- the DEC rules, and do not allow the pragma, which of course
6203 -- has the effect of also forbidding the attribute.
6205 if Ekind (Ent) /= E_Entry then
6207 ("pragma% argument must be simple entry name", Arg1);
6209 elsif Is_AST_Entry (Ent) then
6211 ("duplicate % pragma for entry", Arg1);
6213 elsif Has_Homonym (Ent) then
6215 ("pragma% argument cannot specify overloaded entry", Arg1);
6219 FF : constant Entity_Id := First_Formal (Ent);
6222 if Present (FF) then
6223 if Present (Next_Formal (FF)) then
6225 ("entry for pragma% can have only one argument",
6228 elsif Parameter_Mode (FF) /= E_In_Parameter then
6230 ("entry parameter for pragma% must have mode IN",
6236 Set_Is_AST_Entry (Ent);
6244 -- pragma Asynchronous (LOCAL_NAME);
6246 when Pragma_Asynchronous => Asynchronous : declare
6254 procedure Process_Async_Pragma;
6255 -- Common processing for procedure and access-to-procedure case
6257 --------------------------
6258 -- Process_Async_Pragma --
6259 --------------------------
6261 procedure Process_Async_Pragma is
6264 Set_Is_Asynchronous (Nm);
6268 -- The formals should be of mode IN (RM E.4.1(6))
6271 while Present (S) loop
6272 Formal := Defining_Identifier (S);
6274 if Nkind (Formal) = N_Defining_Identifier
6275 and then Ekind (Formal) /= E_In_Parameter
6278 ("pragma% procedure can only have IN parameter",
6285 Set_Is_Asynchronous (Nm);
6286 end Process_Async_Pragma;
6288 -- Start of processing for pragma Asynchronous
6291 Check_Ada_83_Warning;
6292 Check_No_Identifiers;
6293 Check_Arg_Count (1);
6294 Check_Arg_Is_Local_Name (Arg1);
6296 if Debug_Flag_U then
6300 C_Ent := Cunit_Entity (Current_Sem_Unit);
6301 Analyze (Get_Pragma_Arg (Arg1));
6302 Nm := Entity (Get_Pragma_Arg (Arg1));
6304 if not Is_Remote_Call_Interface (C_Ent)
6305 and then not Is_Remote_Types (C_Ent)
6307 -- This pragma should only appear in an RCI or Remote Types
6308 -- unit (RM E.4.1(4)).
6311 ("pragma% not in Remote_Call_Interface or " &
6312 "Remote_Types unit");
6315 if Ekind (Nm) = E_Procedure
6316 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6318 if not Is_Remote_Call_Interface (Nm) then
6320 ("pragma% cannot be applied on non-remote procedure",
6324 L := Parameter_Specifications (Parent (Nm));
6325 Process_Async_Pragma;
6328 elsif Ekind (Nm) = E_Function then
6330 ("pragma% cannot be applied to function", Arg1);
6332 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6334 if Is_Record_Type (Nm) then
6336 -- A record type that is the Equivalent_Type for a remote
6337 -- access-to-subprogram type.
6339 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6342 -- A non-expanded RAS type (distribution is not enabled)
6344 N := Declaration_Node (Nm);
6347 if Nkind (N) = N_Full_Type_Declaration
6348 and then Nkind (Type_Definition (N)) =
6349 N_Access_Procedure_Definition
6351 L := Parameter_Specifications (Type_Definition (N));
6352 Process_Async_Pragma;
6354 if Is_Asynchronous (Nm)
6355 and then Expander_Active
6356 and then Get_PCS_Name /= Name_No_DSA
6358 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6363 ("pragma% cannot reference access-to-function type",
6367 -- Only other possibility is Access-to-class-wide type
6369 elsif Is_Access_Type (Nm)
6370 and then Is_Class_Wide_Type (Designated_Type (Nm))
6372 Check_First_Subtype (Arg1);
6373 Set_Is_Asynchronous (Nm);
6374 if Expander_Active then
6375 RACW_Type_Is_Asynchronous (Nm);
6379 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6387 -- pragma Atomic (LOCAL_NAME);
6389 when Pragma_Atomic =>
6390 Process_Atomic_Shared_Volatile;
6392 -----------------------
6393 -- Atomic_Components --
6394 -----------------------
6396 -- pragma Atomic_Components (array_LOCAL_NAME);
6398 -- This processing is shared by Volatile_Components
6400 when Pragma_Atomic_Components |
6401 Pragma_Volatile_Components =>
6403 Atomic_Components : declare
6410 Check_Ada_83_Warning;
6411 Check_No_Identifiers;
6412 Check_Arg_Count (1);
6413 Check_Arg_Is_Local_Name (Arg1);
6414 E_Id := Get_Pragma_Arg (Arg1);
6416 if Etype (E_Id) = Any_Type then
6422 Check_Duplicate_Pragma (E);
6424 if Rep_Item_Too_Early (E, N)
6426 Rep_Item_Too_Late (E, N)
6431 D := Declaration_Node (E);
6434 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6436 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6437 and then Nkind (D) = N_Object_Declaration
6438 and then Nkind (Object_Definition (D)) =
6439 N_Constrained_Array_Definition)
6441 -- The flag is set on the object, or on the base type
6443 if Nkind (D) /= N_Object_Declaration then
6447 Set_Has_Volatile_Components (E);
6449 if Prag_Id = Pragma_Atomic_Components then
6450 Set_Has_Atomic_Components (E);
6454 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6456 end Atomic_Components;
6458 --------------------
6459 -- Attach_Handler --
6460 --------------------
6462 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6464 when Pragma_Attach_Handler =>
6465 Check_Ada_83_Warning;
6466 Check_No_Identifiers;
6467 Check_Arg_Count (2);
6469 if No_Run_Time_Mode then
6470 Error_Msg_CRT ("Attach_Handler pragma", N);
6472 Check_Interrupt_Or_Attach_Handler;
6474 -- The expression that designates the attribute may depend on a
6475 -- discriminant, and is therefore a per- object expression, to
6476 -- be expanded in the init proc. If expansion is enabled, then
6477 -- perform semantic checks on a copy only.
6479 if Expander_Active then
6481 Temp : constant Node_Id :=
6482 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6484 Set_Parent (Temp, N);
6485 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6489 Analyze (Get_Pragma_Arg (Arg2));
6490 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6493 Process_Interrupt_Or_Attach_Handler;
6496 --------------------
6497 -- C_Pass_By_Copy --
6498 --------------------
6500 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6502 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6508 Check_Valid_Configuration_Pragma;
6509 Check_Arg_Count (1);
6510 Check_Optional_Identifier (Arg1, "max_size");
6512 Arg := Get_Pragma_Arg (Arg1);
6513 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6515 Val := Expr_Value (Arg);
6519 ("maximum size for pragma% must be positive", Arg1);
6521 elsif UI_Is_In_Int_Range (Val) then
6522 Default_C_Record_Mechanism := UI_To_Int (Val);
6524 -- If a giant value is given, Int'Last will do well enough.
6525 -- If sometime someone complains that a record larger than
6526 -- two gigabytes is not copied, we will worry about it then!
6529 Default_C_Record_Mechanism := Mechanism_Type'Last;
6537 -- pragma Check ([Name =>] Identifier,
6538 -- [Check =>] Boolean_Expression
6539 -- [,[Message =>] String_Expression]);
6541 when Pragma_Check => Check : declare
6546 -- Set True if category of assertions referenced by Name enabled
6550 Check_At_Least_N_Arguments (2);
6551 Check_At_Most_N_Arguments (3);
6552 Check_Optional_Identifier (Arg1, Name_Name);
6553 Check_Optional_Identifier (Arg2, Name_Check);
6555 if Arg_Count = 3 then
6556 Check_Optional_Identifier (Arg3, Name_Message);
6557 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6560 Check_Arg_Is_Identifier (Arg1);
6562 -- Indicate if pragma is enabled. The Original_Node reference here
6563 -- is to deal with pragma Assert rewritten as a Check pragma.
6565 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6568 Set_Pragma_Enabled (N);
6569 Set_Pragma_Enabled (Original_Node (N));
6570 Set_SCO_Pragma_Enabled (Loc);
6573 -- If expansion is active and the check is not enabled then we
6574 -- rewrite the Check as:
6576 -- if False and then condition then
6580 -- The reason we do this rewriting during semantic analysis rather
6581 -- than as part of normal expansion is that we cannot analyze and
6582 -- expand the code for the boolean expression directly, or it may
6583 -- cause insertion of actions that would escape the attempt to
6584 -- suppress the check code.
6586 -- Note that the Sloc for the if statement corresponds to the
6587 -- argument condition, not the pragma itself. The reason for this
6588 -- is that we may generate a warning if the condition is False at
6589 -- compile time, and we do not want to delete this warning when we
6590 -- delete the if statement.
6592 Expr := Get_Pragma_Arg (Arg2);
6594 if Expander_Active and then not Check_On then
6595 Eloc := Sloc (Expr);
6598 Make_If_Statement (Eloc,
6600 Make_And_Then (Eloc,
6601 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6602 Right_Opnd => Expr),
6603 Then_Statements => New_List (
6604 Make_Null_Statement (Eloc))));
6611 Analyze_And_Resolve (Expr, Any_Boolean);
6619 -- pragma Check_Name (check_IDENTIFIER);
6621 when Pragma_Check_Name =>
6622 Check_No_Identifiers;
6624 Check_Valid_Configuration_Pragma;
6625 Check_Arg_Count (1);
6626 Check_Arg_Is_Identifier (Arg1);
6629 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6632 for J in Check_Names.First .. Check_Names.Last loop
6633 if Check_Names.Table (J) = Nam then
6638 Check_Names.Append (Nam);
6645 -- pragma Check_Policy (
6646 -- [Name =>] IDENTIFIER,
6647 -- [Policy =>] POLICY_IDENTIFIER);
6649 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6651 -- Note: this is a configuration pragma, but it is allowed to appear
6654 when Pragma_Check_Policy =>
6656 Check_Arg_Count (2);
6657 Check_Optional_Identifier (Arg1, Name_Name);
6658 Check_Optional_Identifier (Arg2, Name_Policy);
6660 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6662 -- A Check_Policy pragma can appear either as a configuration
6663 -- pragma, or in a declarative part or a package spec (see RM
6664 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6665 -- followed for Check_Policy).
6667 if not Is_Configuration_Pragma then
6668 Check_Is_In_Decl_Part_Or_Package_Spec;
6671 Set_Next_Pragma (N, Opt.Check_Policy_List);
6672 Opt.Check_Policy_List := N;
6674 ---------------------
6675 -- CIL_Constructor --
6676 ---------------------
6678 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6680 -- Processing for this pragma is shared with Java_Constructor
6686 -- pragma Comment (static_string_EXPRESSION)
6688 -- Processing for pragma Comment shares the circuitry for pragma
6689 -- Ident. The only differences are that Ident enforces a limit of 31
6690 -- characters on its argument, and also enforces limitations on
6691 -- placement for DEC compatibility. Pragma Comment shares neither of
6692 -- these restrictions.
6698 -- pragma Common_Object (
6699 -- [Internal =>] LOCAL_NAME
6700 -- [, [External =>] EXTERNAL_SYMBOL]
6701 -- [, [Size =>] EXTERNAL_SYMBOL]);
6703 -- Processing for this pragma is shared with Psect_Object
6705 ------------------------
6706 -- Compile_Time_Error --
6707 ------------------------
6709 -- pragma Compile_Time_Error
6710 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6712 when Pragma_Compile_Time_Error =>
6714 Process_Compile_Time_Warning_Or_Error;
6716 --------------------------
6717 -- Compile_Time_Warning --
6718 --------------------------
6720 -- pragma Compile_Time_Warning
6721 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6723 when Pragma_Compile_Time_Warning =>
6725 Process_Compile_Time_Warning_Or_Error;
6731 when Pragma_Compiler_Unit =>
6733 Check_Arg_Count (0);
6734 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6736 -----------------------------
6737 -- Complete_Representation --
6738 -----------------------------
6740 -- pragma Complete_Representation;
6742 when Pragma_Complete_Representation =>
6744 Check_Arg_Count (0);
6746 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6748 ("pragma & must appear within record representation clause");
6751 ----------------------------
6752 -- Complex_Representation --
6753 ----------------------------
6755 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6757 when Pragma_Complex_Representation => Complex_Representation : declare
6764 Check_Arg_Count (1);
6765 Check_Optional_Identifier (Arg1, Name_Entity);
6766 Check_Arg_Is_Local_Name (Arg1);
6767 E_Id := Get_Pragma_Arg (Arg1);
6769 if Etype (E_Id) = Any_Type then
6775 if not Is_Record_Type (E) then
6777 ("argument for pragma% must be record type", Arg1);
6780 Ent := First_Entity (E);
6783 or else No (Next_Entity (Ent))
6784 or else Present (Next_Entity (Next_Entity (Ent)))
6785 or else not Is_Floating_Point_Type (Etype (Ent))
6786 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6789 ("record for pragma% must have two fields of the same "
6790 & "floating-point type", Arg1);
6793 Set_Has_Complex_Representation (Base_Type (E));
6795 -- We need to treat the type has having a non-standard
6796 -- representation, for back-end purposes, even though in
6797 -- general a complex will have the default representation
6798 -- of a record with two real components.
6800 Set_Has_Non_Standard_Rep (Base_Type (E));
6802 end Complex_Representation;
6804 -------------------------
6805 -- Component_Alignment --
6806 -------------------------
6808 -- pragma Component_Alignment (
6809 -- [Form =>] ALIGNMENT_CHOICE
6810 -- [, [Name =>] type_LOCAL_NAME]);
6812 -- ALIGNMENT_CHOICE ::=
6814 -- | Component_Size_4
6818 when Pragma_Component_Alignment => Component_AlignmentP : declare
6819 Args : Args_List (1 .. 2);
6820 Names : constant Name_List (1 .. 2) := (
6824 Form : Node_Id renames Args (1);
6825 Name : Node_Id renames Args (2);
6827 Atype : Component_Alignment_Kind;
6832 Gather_Associations (Names, Args);
6835 Error_Pragma ("missing Form argument for pragma%");
6838 Check_Arg_Is_Identifier (Form);
6840 -- Get proper alignment, note that Default = Component_Size on all
6841 -- machines we have so far, and we want to set this value rather
6842 -- than the default value to indicate that it has been explicitly
6843 -- set (and thus will not get overridden by the default component
6844 -- alignment for the current scope)
6846 if Chars (Form) = Name_Component_Size then
6847 Atype := Calign_Component_Size;
6849 elsif Chars (Form) = Name_Component_Size_4 then
6850 Atype := Calign_Component_Size_4;
6852 elsif Chars (Form) = Name_Default then
6853 Atype := Calign_Component_Size;
6855 elsif Chars (Form) = Name_Storage_Unit then
6856 Atype := Calign_Storage_Unit;
6860 ("invalid Form parameter for pragma%", Form);
6863 -- Case with no name, supplied, affects scope table entry
6867 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6869 -- Case of name supplied
6872 Check_Arg_Is_Local_Name (Name);
6874 Typ := Entity (Name);
6877 or else Rep_Item_Too_Early (Typ, N)
6881 Typ := Underlying_Type (Typ);
6884 if not Is_Record_Type (Typ)
6885 and then not Is_Array_Type (Typ)
6888 ("Name parameter of pragma% must identify record or " &
6889 "array type", Name);
6892 -- An explicit Component_Alignment pragma overrides an
6893 -- implicit pragma Pack, but not an explicit one.
6895 if not Has_Pragma_Pack (Base_Type (Typ)) then
6896 Set_Is_Packed (Base_Type (Typ), False);
6897 Set_Component_Alignment (Base_Type (Typ), Atype);
6900 end Component_AlignmentP;
6906 -- pragma Controlled (first_subtype_LOCAL_NAME);
6908 when Pragma_Controlled => Controlled : declare
6912 Check_No_Identifiers;
6913 Check_Arg_Count (1);
6914 Check_Arg_Is_Local_Name (Arg1);
6915 Arg := Get_Pragma_Arg (Arg1);
6917 if not Is_Entity_Name (Arg)
6918 or else not Is_Access_Type (Entity (Arg))
6920 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6922 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6930 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6931 -- [Entity =>] LOCAL_NAME);
6933 when Pragma_Convention => Convention : declare
6936 pragma Warnings (Off, C);
6937 pragma Warnings (Off, E);
6939 Check_Arg_Order ((Name_Convention, Name_Entity));
6940 Check_Ada_83_Warning;
6941 Check_Arg_Count (2);
6942 Process_Convention (C, E);
6945 ---------------------------
6946 -- Convention_Identifier --
6947 ---------------------------
6949 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6950 -- [Convention =>] convention_IDENTIFIER);
6952 when Pragma_Convention_Identifier => Convention_Identifier : declare
6958 Check_Arg_Order ((Name_Name, Name_Convention));
6959 Check_Arg_Count (2);
6960 Check_Optional_Identifier (Arg1, Name_Name);
6961 Check_Optional_Identifier (Arg2, Name_Convention);
6962 Check_Arg_Is_Identifier (Arg1);
6963 Check_Arg_Is_Identifier (Arg2);
6964 Idnam := Chars (Get_Pragma_Arg (Arg1));
6965 Cname := Chars (Get_Pragma_Arg (Arg2));
6967 if Is_Convention_Name (Cname) then
6968 Record_Convention_Identifier
6969 (Idnam, Get_Convention_Id (Cname));
6972 ("second arg for % pragma must be convention", Arg2);
6974 end Convention_Identifier;
6980 -- pragma CPP_Class ([Entity =>] local_NAME)
6982 when Pragma_CPP_Class => CPP_Class : declare
6987 if Warn_On_Obsolescent_Feature then
6989 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6990 " by pragma import?", N);
6994 Check_Arg_Count (1);
6995 Check_Optional_Identifier (Arg1, Name_Entity);
6996 Check_Arg_Is_Local_Name (Arg1);
6998 Arg := Get_Pragma_Arg (Arg1);
7001 if Etype (Arg) = Any_Type then
7005 if not Is_Entity_Name (Arg)
7006 or else not Is_Type (Entity (Arg))
7008 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7011 Typ := Entity (Arg);
7013 if not Is_Tagged_Type (Typ) then
7014 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7017 -- Types treated as CPP classes are treated as limited, but we
7018 -- don't require them to be declared this way. A warning is issued
7019 -- to encourage the user to declare them as limited. This is not
7020 -- an error, for compatibility reasons, because these types have
7021 -- been supported this way for some time.
7023 if not Is_Limited_Type (Typ) then
7025 ("imported 'C'P'P type should be " &
7026 "explicitly declared limited?",
7027 Get_Pragma_Arg (Arg1));
7029 ("\type will be considered limited",
7030 Get_Pragma_Arg (Arg1));
7033 Set_Is_CPP_Class (Typ);
7034 Set_Is_Limited_Record (Typ);
7035 Set_Convention (Typ, Convention_CPP);
7037 -- Imported CPP types must not have discriminants (because C++
7038 -- classes do not have discriminants).
7040 if Has_Discriminants (Typ) then
7042 ("imported 'C'P'P type cannot have discriminants",
7043 First (Discriminant_Specifications
7044 (Declaration_Node (Typ))));
7047 -- Components of imported CPP types must not have default
7048 -- expressions because the constructor (if any) is in the
7051 if Is_Incomplete_Or_Private_Type (Typ)
7052 and then No (Underlying_Type (Typ))
7054 -- It should be an error to apply pragma CPP to a private
7055 -- type if the underlying type is not visible (as it is
7056 -- for any representation item). For now, for backward
7057 -- compatibility we do nothing but we cannot check components
7058 -- because they are not available at this stage. All this code
7059 -- will be removed when we cleanup this obsolete GNAT pragma???
7065 Tdef : constant Node_Id :=
7066 Type_Definition (Declaration_Node (Typ));
7071 if Nkind (Tdef) = N_Record_Definition then
7072 Clist := Component_List (Tdef);
7074 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7075 Clist := Component_List (Record_Extension_Part (Tdef));
7078 if Present (Clist) then
7079 Comp := First (Component_Items (Clist));
7080 while Present (Comp) loop
7081 if Present (Expression (Comp)) then
7083 ("component of imported 'C'P'P type cannot have" &
7084 " default expression", Expression (Comp));
7094 ---------------------
7095 -- CPP_Constructor --
7096 ---------------------
7098 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7099 -- [, [External_Name =>] static_string_EXPRESSION ]
7100 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7102 when Pragma_CPP_Constructor => CPP_Constructor : declare
7106 Tag_Typ : Entity_Id;
7110 Check_At_Least_N_Arguments (1);
7111 Check_At_Most_N_Arguments (3);
7112 Check_Optional_Identifier (Arg1, Name_Entity);
7113 Check_Arg_Is_Local_Name (Arg1);
7115 Id := Get_Pragma_Arg (Arg1);
7116 Find_Program_Unit_Name (Id);
7118 -- If we did not find the name, we are done
7120 if Etype (Id) = Any_Type then
7124 Def_Id := Entity (Id);
7126 -- Check if already defined as constructor
7128 if Is_Constructor (Def_Id) then
7130 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7134 if Ekind (Def_Id) = E_Function
7135 and then (Is_CPP_Class (Etype (Def_Id))
7136 or else (Is_Class_Wide_Type (Etype (Def_Id))
7138 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7140 if Arg_Count >= 2 then
7141 Set_Imported (Def_Id);
7142 Set_Is_Public (Def_Id);
7143 Process_Interface_Name (Def_Id, Arg2, Arg3);
7146 Set_Has_Completion (Def_Id);
7147 Set_Is_Constructor (Def_Id);
7149 -- Imported C++ constructors are not dispatching primitives
7150 -- because in C++ they don't have a dispatch table slot.
7151 -- However, in Ada the constructor has the profile of a
7152 -- function that returns a tagged type and therefore it has
7153 -- been treated as a primitive operation during semantic
7154 -- analysis. We now remove it from the list of primitive
7155 -- operations of the type.
7157 if Is_Tagged_Type (Etype (Def_Id))
7158 and then not Is_Class_Wide_Type (Etype (Def_Id))
7160 pragma Assert (Is_Dispatching_Operation (Def_Id));
7161 Tag_Typ := Etype (Def_Id);
7163 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7164 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7168 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7169 Set_Is_Dispatching_Operation (Def_Id, False);
7172 -- For backward compatibility, if the constructor returns a
7173 -- class wide type, and we internally change the return type to
7174 -- the corresponding root type.
7176 if Is_Class_Wide_Type (Etype (Def_Id)) then
7177 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7181 ("pragma% requires function returning a 'C'P'P_Class type",
7184 end CPP_Constructor;
7190 when Pragma_CPP_Virtual => CPP_Virtual : declare
7194 if Warn_On_Obsolescent_Feature then
7196 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7205 when Pragma_CPP_Vtable => CPP_Vtable : declare
7209 if Warn_On_Obsolescent_Feature then
7211 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7220 -- pragma CPU (EXPRESSION);
7222 when Pragma_CPU => CPU : declare
7223 P : constant Node_Id := Parent (N);
7228 Check_No_Identifiers;
7229 Check_Arg_Count (1);
7233 if Nkind (P) = N_Subprogram_Body then
7234 Check_In_Main_Program;
7236 Arg := Get_Pragma_Arg (Arg1);
7237 Analyze_And_Resolve (Arg, Any_Integer);
7241 if not Is_Static_Expression (Arg) then
7242 Flag_Non_Static_Expr
7243 ("main subprogram affinity is not static!", Arg);
7246 -- If constraint error, then we already signalled an error
7248 elsif Raises_Constraint_Error (Arg) then
7251 -- Otherwise check in range
7255 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7256 -- This is the entity System.Multiprocessors.CPU_Range;
7258 Val : constant Uint := Expr_Value (Arg);
7261 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7263 Val > Expr_Value (Type_High_Bound (CPU_Id))
7266 ("main subprogram CPU is out of range", Arg1);
7272 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7276 elsif Nkind (P) = N_Task_Definition then
7277 Arg := Get_Pragma_Arg (Arg1);
7279 -- The expression must be analyzed in the special manner
7280 -- described in "Handling of Default and Per-Object
7281 -- Expressions" in sem.ads.
7283 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7285 -- Anything else is incorrect
7291 if Has_Pragma_CPU (P) then
7292 Error_Pragma ("duplicate pragma% not allowed");
7294 Set_Has_Pragma_CPU (P, True);
7296 if Nkind (P) = N_Task_Definition then
7297 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7306 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7308 when Pragma_Debug => Debug : declare
7316 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7319 if Arg_Count = 2 then
7322 Left_Opnd => Relocate_Node (Cond),
7323 Right_Opnd => Get_Pragma_Arg (Arg1));
7326 -- Rewrite into a conditional with an appropriate condition. We
7327 -- wrap the procedure call in a block so that overhead from e.g.
7328 -- use of the secondary stack does not generate execution overhead
7329 -- for suppressed conditions.
7331 Rewrite (N, Make_Implicit_If_Statement (N,
7333 Then_Statements => New_List (
7334 Make_Block_Statement (Loc,
7335 Handled_Statement_Sequence =>
7336 Make_Handled_Sequence_Of_Statements (Loc,
7337 Statements => New_List (
7338 Relocate_Node (Debug_Statement (N))))))));
7346 -- pragma Debug_Policy (Check | Ignore)
7348 when Pragma_Debug_Policy =>
7350 Check_Arg_Count (1);
7351 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7352 Debug_Pragmas_Enabled :=
7353 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7355 ---------------------
7356 -- Detect_Blocking --
7357 ---------------------
7359 -- pragma Detect_Blocking;
7361 when Pragma_Detect_Blocking =>
7363 Check_Arg_Count (0);
7364 Check_Valid_Configuration_Pragma;
7365 Detect_Blocking := True;
7367 --------------------------
7368 -- Default_Storage_Pool --
7369 --------------------------
7371 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7373 when Pragma_Default_Storage_Pool =>
7375 Check_Arg_Count (1);
7377 -- Default_Storage_Pool can appear as a configuration pragma, or
7378 -- in a declarative part or a package spec.
7380 if not Is_Configuration_Pragma then
7381 Check_Is_In_Decl_Part_Or_Package_Spec;
7384 -- Case of Default_Storage_Pool (null);
7386 if Nkind (Expression (Arg1)) = N_Null then
7387 Analyze (Expression (Arg1));
7389 -- This is an odd case, this is not really an expression, so
7390 -- we don't have a type for it. So just set the type to Empty.
7392 Set_Etype (Expression (Arg1), Empty);
7394 -- Case of Default_Storage_Pool (storage_pool_NAME);
7397 -- If it's a configuration pragma, then the only allowed
7398 -- argument is "null".
7400 if Is_Configuration_Pragma then
7401 Error_Pragma_Arg ("NULL expected", Arg1);
7404 -- The expected type for a non-"null" argument is
7405 -- Root_Storage_Pool'Class.
7408 (Get_Pragma_Arg (Arg1),
7409 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7412 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7413 -- for an access type will use this information to set the
7414 -- appropriate attributes of the access type.
7416 Default_Pool := Expression (Arg1);
7422 when Pragma_Dimension =>
7424 Check_Arg_Count (4);
7425 Check_No_Identifiers;
7426 Check_Arg_Is_Local_Name (Arg1);
7428 if not Is_Type (Arg1) then
7429 Error_Pragma ("first argument for pragma% must be subtype");
7432 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7433 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7434 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7440 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7442 when Pragma_Discard_Names => Discard_Names : declare
7447 Check_Ada_83_Warning;
7449 -- Deal with configuration pragma case
7451 if Arg_Count = 0 and then Is_Configuration_Pragma then
7452 Global_Discard_Names := True;
7455 -- Otherwise, check correct appropriate context
7458 Check_Is_In_Decl_Part_Or_Package_Spec;
7460 if Arg_Count = 0 then
7462 -- If there is no parameter, then from now on this pragma
7463 -- applies to any enumeration, exception or tagged type
7464 -- defined in the current declarative part, and recursively
7465 -- to any nested scope.
7467 Set_Discard_Names (Current_Scope);
7471 Check_Arg_Count (1);
7472 Check_Optional_Identifier (Arg1, Name_On);
7473 Check_Arg_Is_Local_Name (Arg1);
7475 E_Id := Get_Pragma_Arg (Arg1);
7477 if Etype (E_Id) = Any_Type then
7483 if (Is_First_Subtype (E)
7485 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7486 or else Ekind (E) = E_Exception
7488 Set_Discard_Names (E);
7491 ("inappropriate entity for pragma%", Arg1);
7502 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7504 when Pragma_Elaborate => Elaborate : declare
7509 -- Pragma must be in context items list of a compilation unit
7511 if not Is_In_Context_Clause then
7515 -- Must be at least one argument
7517 if Arg_Count = 0 then
7518 Error_Pragma ("pragma% requires at least one argument");
7521 -- In Ada 83 mode, there can be no items following it in the
7522 -- context list except other pragmas and implicit with clauses
7523 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7524 -- placement rule does not apply.
7526 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7528 while Present (Citem) loop
7529 if Nkind (Citem) = N_Pragma
7530 or else (Nkind (Citem) = N_With_Clause
7531 and then Implicit_With (Citem))
7536 ("(Ada 83) pragma% must be at end of context clause");
7543 -- Finally, the arguments must all be units mentioned in a with
7544 -- clause in the same context clause. Note we already checked (in
7545 -- Par.Prag) that the arguments are all identifiers or selected
7549 Outer : while Present (Arg) loop
7550 Citem := First (List_Containing (N));
7551 Inner : while Citem /= N loop
7552 if Nkind (Citem) = N_With_Clause
7553 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7555 Set_Elaborate_Present (Citem, True);
7556 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7558 -- With the pragma present, elaboration calls on
7559 -- subprograms from the named unit need no further
7560 -- checks, as long as the pragma appears in the current
7561 -- compilation unit. If the pragma appears in some unit
7562 -- in the context, there might still be a need for an
7563 -- Elaborate_All_Desirable from the current compilation
7564 -- to the named unit, so we keep the check enabled.
7566 if In_Extended_Main_Source_Unit (N) then
7567 Set_Suppress_Elaboration_Warnings
7568 (Entity (Name (Citem)));
7579 ("argument of pragma% is not with'ed unit", Arg);
7585 -- Give a warning if operating in static mode with -gnatwl
7586 -- (elaboration warnings enabled) switch set.
7588 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7590 ("?use of pragma Elaborate may not be safe", N);
7592 ("?use pragma Elaborate_All instead if possible", N);
7600 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7602 when Pragma_Elaborate_All => Elaborate_All : declare
7607 Check_Ada_83_Warning;
7609 -- Pragma must be in context items list of a compilation unit
7611 if not Is_In_Context_Clause then
7615 -- Must be at least one argument
7617 if Arg_Count = 0 then
7618 Error_Pragma ("pragma% requires at least one argument");
7621 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7622 -- have to appear at the end of the context clause, but may
7623 -- appear mixed in with other items, even in Ada 83 mode.
7625 -- Final check: the arguments must all be units mentioned in
7626 -- a with clause in the same context clause. Note that we
7627 -- already checked (in Par.Prag) that all the arguments are
7628 -- either identifiers or selected components.
7631 Outr : while Present (Arg) loop
7632 Citem := First (List_Containing (N));
7633 Innr : while Citem /= N loop
7634 if Nkind (Citem) = N_With_Clause
7635 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7637 Set_Elaborate_All_Present (Citem, True);
7638 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7640 -- Suppress warnings and elaboration checks on the named
7641 -- unit if the pragma is in the current compilation, as
7642 -- for pragma Elaborate.
7644 if In_Extended_Main_Source_Unit (N) then
7645 Set_Suppress_Elaboration_Warnings
7646 (Entity (Name (Citem)));
7655 Set_Error_Posted (N);
7657 ("argument of pragma% is not with'ed unit", Arg);
7664 --------------------
7665 -- Elaborate_Body --
7666 --------------------
7668 -- pragma Elaborate_Body [( library_unit_NAME )];
7670 when Pragma_Elaborate_Body => Elaborate_Body : declare
7671 Cunit_Node : Node_Id;
7672 Cunit_Ent : Entity_Id;
7675 Check_Ada_83_Warning;
7676 Check_Valid_Library_Unit_Pragma;
7678 if Nkind (N) = N_Null_Statement then
7682 Cunit_Node := Cunit (Current_Sem_Unit);
7683 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7685 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7688 Error_Pragma ("pragma% must refer to a spec, not a body");
7690 Set_Body_Required (Cunit_Node, True);
7691 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7693 -- If we are in dynamic elaboration mode, then we suppress
7694 -- elaboration warnings for the unit, since it is definitely
7695 -- fine NOT to do dynamic checks at the first level (and such
7696 -- checks will be suppressed because no elaboration boolean
7697 -- is created for Elaborate_Body packages).
7699 -- But in the static model of elaboration, Elaborate_Body is
7700 -- definitely NOT good enough to ensure elaboration safety on
7701 -- its own, since the body may WITH other units that are not
7702 -- safe from an elaboration point of view, so a client must
7703 -- still do an Elaborate_All on such units.
7705 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7706 -- Elaborate_Body always suppressed elab warnings.
7708 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7709 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7714 ------------------------
7715 -- Elaboration_Checks --
7716 ------------------------
7718 -- pragma Elaboration_Checks (Static | Dynamic);
7720 when Pragma_Elaboration_Checks =>
7722 Check_Arg_Count (1);
7723 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7724 Dynamic_Elaboration_Checks :=
7725 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7731 -- pragma Eliminate (
7732 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7733 -- [,[Entity =>] IDENTIFIER |
7734 -- SELECTED_COMPONENT |
7736 -- [, OVERLOADING_RESOLUTION]);
7738 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7741 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7744 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7746 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7747 -- Result_Type => result_SUBTYPE_NAME]
7749 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7750 -- SUBTYPE_NAME ::= STRING_LITERAL
7752 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7753 -- SOURCE_TRACE ::= STRING_LITERAL
7755 when Pragma_Eliminate => Eliminate : declare
7756 Args : Args_List (1 .. 5);
7757 Names : constant Name_List (1 .. 5) := (
7760 Name_Parameter_Types,
7762 Name_Source_Location);
7764 Unit_Name : Node_Id renames Args (1);
7765 Entity : Node_Id renames Args (2);
7766 Parameter_Types : Node_Id renames Args (3);
7767 Result_Type : Node_Id renames Args (4);
7768 Source_Location : Node_Id renames Args (5);
7772 Check_Valid_Configuration_Pragma;
7773 Gather_Associations (Names, Args);
7775 if No (Unit_Name) then
7776 Error_Pragma ("missing Unit_Name argument for pragma%");
7780 and then (Present (Parameter_Types)
7782 Present (Result_Type)
7784 Present (Source_Location))
7786 Error_Pragma ("missing Entity argument for pragma%");
7789 if (Present (Parameter_Types)
7791 Present (Result_Type))
7793 Present (Source_Location)
7796 ("parameter profile and source location cannot " &
7797 "be used together in pragma%");
7800 Process_Eliminate_Pragma
7814 -- [ Convention =>] convention_IDENTIFIER,
7815 -- [ Entity =>] local_NAME
7816 -- [, [External_Name =>] static_string_EXPRESSION ]
7817 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7819 when Pragma_Export => Export : declare
7823 pragma Warnings (Off, C);
7826 Check_Ada_83_Warning;
7832 Check_At_Least_N_Arguments (2);
7833 Check_At_Most_N_Arguments (4);
7834 Process_Convention (C, Def_Id);
7836 if Ekind (Def_Id) /= E_Constant then
7837 Note_Possible_Modification
7838 (Get_Pragma_Arg (Arg2), Sure => False);
7841 Process_Interface_Name (Def_Id, Arg3, Arg4);
7842 Set_Exported (Def_Id, Arg2);
7844 -- If the entity is a deferred constant, propagate the information
7845 -- to the full view, because gigi elaborates the full view only.
7847 if Ekind (Def_Id) = E_Constant
7848 and then Present (Full_View (Def_Id))
7851 Id2 : constant Entity_Id := Full_View (Def_Id);
7853 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7854 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7855 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7860 ----------------------
7861 -- Export_Exception --
7862 ----------------------
7864 -- pragma Export_Exception (
7865 -- [Internal =>] LOCAL_NAME
7866 -- [, [External =>] EXTERNAL_SYMBOL]
7867 -- [, [Form =>] Ada | VMS]
7868 -- [, [Code =>] static_integer_EXPRESSION]);
7870 when Pragma_Export_Exception => Export_Exception : declare
7871 Args : Args_List (1 .. 4);
7872 Names : constant Name_List (1 .. 4) := (
7878 Internal : Node_Id renames Args (1);
7879 External : Node_Id renames Args (2);
7880 Form : Node_Id renames Args (3);
7881 Code : Node_Id renames Args (4);
7886 if Inside_A_Generic then
7887 Error_Pragma ("pragma% cannot be used for generic entities");
7890 Gather_Associations (Names, Args);
7891 Process_Extended_Import_Export_Exception_Pragma (
7892 Arg_Internal => Internal,
7893 Arg_External => External,
7897 if not Is_VMS_Exception (Entity (Internal)) then
7898 Set_Exported (Entity (Internal), Internal);
7900 end Export_Exception;
7902 ---------------------
7903 -- Export_Function --
7904 ---------------------
7906 -- pragma Export_Function (
7907 -- [Internal =>] LOCAL_NAME
7908 -- [, [External =>] EXTERNAL_SYMBOL]
7909 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7910 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7911 -- [, [Mechanism =>] MECHANISM]
7912 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7914 -- EXTERNAL_SYMBOL ::=
7916 -- | static_string_EXPRESSION
7918 -- PARAMETER_TYPES ::=
7920 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7922 -- TYPE_DESIGNATOR ::=
7924 -- | subtype_Name ' Access
7928 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7930 -- MECHANISM_ASSOCIATION ::=
7931 -- [formal_parameter_NAME =>] MECHANISM_NAME
7933 -- MECHANISM_NAME ::=
7936 -- | Descriptor [([Class =>] CLASS_NAME)]
7938 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7940 when Pragma_Export_Function => Export_Function : declare
7941 Args : Args_List (1 .. 6);
7942 Names : constant Name_List (1 .. 6) := (
7945 Name_Parameter_Types,
7948 Name_Result_Mechanism);
7950 Internal : Node_Id renames Args (1);
7951 External : Node_Id renames Args (2);
7952 Parameter_Types : Node_Id renames Args (3);
7953 Result_Type : Node_Id renames Args (4);
7954 Mechanism : Node_Id renames Args (5);
7955 Result_Mechanism : Node_Id renames Args (6);
7959 Gather_Associations (Names, Args);
7960 Process_Extended_Import_Export_Subprogram_Pragma (
7961 Arg_Internal => Internal,
7962 Arg_External => External,
7963 Arg_Parameter_Types => Parameter_Types,
7964 Arg_Result_Type => Result_Type,
7965 Arg_Mechanism => Mechanism,
7966 Arg_Result_Mechanism => Result_Mechanism);
7967 end Export_Function;
7973 -- pragma Export_Object (
7974 -- [Internal =>] LOCAL_NAME
7975 -- [, [External =>] EXTERNAL_SYMBOL]
7976 -- [, [Size =>] EXTERNAL_SYMBOL]);
7978 -- EXTERNAL_SYMBOL ::=
7980 -- | static_string_EXPRESSION
7982 -- PARAMETER_TYPES ::=
7984 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7986 -- TYPE_DESIGNATOR ::=
7988 -- | subtype_Name ' Access
7992 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7994 -- MECHANISM_ASSOCIATION ::=
7995 -- [formal_parameter_NAME =>] MECHANISM_NAME
7997 -- MECHANISM_NAME ::=
8000 -- | Descriptor [([Class =>] CLASS_NAME)]
8002 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8004 when Pragma_Export_Object => Export_Object : declare
8005 Args : Args_List (1 .. 3);
8006 Names : constant Name_List (1 .. 3) := (
8011 Internal : Node_Id renames Args (1);
8012 External : Node_Id renames Args (2);
8013 Size : Node_Id renames Args (3);
8017 Gather_Associations (Names, Args);
8018 Process_Extended_Import_Export_Object_Pragma (
8019 Arg_Internal => Internal,
8020 Arg_External => External,
8024 ----------------------
8025 -- Export_Procedure --
8026 ----------------------
8028 -- pragma Export_Procedure (
8029 -- [Internal =>] LOCAL_NAME
8030 -- [, [External =>] EXTERNAL_SYMBOL]
8031 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8032 -- [, [Mechanism =>] MECHANISM]);
8034 -- EXTERNAL_SYMBOL ::=
8036 -- | static_string_EXPRESSION
8038 -- PARAMETER_TYPES ::=
8040 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8042 -- TYPE_DESIGNATOR ::=
8044 -- | subtype_Name ' Access
8048 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8050 -- MECHANISM_ASSOCIATION ::=
8051 -- [formal_parameter_NAME =>] MECHANISM_NAME
8053 -- MECHANISM_NAME ::=
8056 -- | Descriptor [([Class =>] CLASS_NAME)]
8058 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8060 when Pragma_Export_Procedure => Export_Procedure : declare
8061 Args : Args_List (1 .. 4);
8062 Names : constant Name_List (1 .. 4) := (
8065 Name_Parameter_Types,
8068 Internal : Node_Id renames Args (1);
8069 External : Node_Id renames Args (2);
8070 Parameter_Types : Node_Id renames Args (3);
8071 Mechanism : Node_Id renames Args (4);
8075 Gather_Associations (Names, Args);
8076 Process_Extended_Import_Export_Subprogram_Pragma (
8077 Arg_Internal => Internal,
8078 Arg_External => External,
8079 Arg_Parameter_Types => Parameter_Types,
8080 Arg_Mechanism => Mechanism);
8081 end Export_Procedure;
8087 -- pragma Export_Value (
8088 -- [Value =>] static_integer_EXPRESSION,
8089 -- [Link_Name =>] static_string_EXPRESSION);
8091 when Pragma_Export_Value =>
8093 Check_Arg_Order ((Name_Value, Name_Link_Name));
8094 Check_Arg_Count (2);
8096 Check_Optional_Identifier (Arg1, Name_Value);
8097 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8099 Check_Optional_Identifier (Arg2, Name_Link_Name);
8100 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8102 -----------------------------
8103 -- Export_Valued_Procedure --
8104 -----------------------------
8106 -- pragma Export_Valued_Procedure (
8107 -- [Internal =>] LOCAL_NAME
8108 -- [, [External =>] EXTERNAL_SYMBOL,]
8109 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8110 -- [, [Mechanism =>] MECHANISM]);
8112 -- EXTERNAL_SYMBOL ::=
8114 -- | static_string_EXPRESSION
8116 -- PARAMETER_TYPES ::=
8118 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8120 -- TYPE_DESIGNATOR ::=
8122 -- | subtype_Name ' Access
8126 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8128 -- MECHANISM_ASSOCIATION ::=
8129 -- [formal_parameter_NAME =>] MECHANISM_NAME
8131 -- MECHANISM_NAME ::=
8134 -- | Descriptor [([Class =>] CLASS_NAME)]
8136 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8138 when Pragma_Export_Valued_Procedure =>
8139 Export_Valued_Procedure : declare
8140 Args : Args_List (1 .. 4);
8141 Names : constant Name_List (1 .. 4) := (
8144 Name_Parameter_Types,
8147 Internal : Node_Id renames Args (1);
8148 External : Node_Id renames Args (2);
8149 Parameter_Types : Node_Id renames Args (3);
8150 Mechanism : Node_Id renames Args (4);
8154 Gather_Associations (Names, Args);
8155 Process_Extended_Import_Export_Subprogram_Pragma (
8156 Arg_Internal => Internal,
8157 Arg_External => External,
8158 Arg_Parameter_Types => Parameter_Types,
8159 Arg_Mechanism => Mechanism);
8160 end Export_Valued_Procedure;
8166 -- pragma Extend_System ([Name =>] Identifier);
8168 when Pragma_Extend_System => Extend_System : declare
8171 Check_Valid_Configuration_Pragma;
8172 Check_Arg_Count (1);
8173 Check_Optional_Identifier (Arg1, Name_Name);
8174 Check_Arg_Is_Identifier (Arg1);
8176 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8179 and then Name_Buffer (1 .. 4) = "aux_"
8181 if Present (System_Extend_Pragma_Arg) then
8182 if Chars (Get_Pragma_Arg (Arg1)) =
8183 Chars (Expression (System_Extend_Pragma_Arg))
8187 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8188 Error_Pragma ("pragma% conflicts with that #");
8192 System_Extend_Pragma_Arg := Arg1;
8194 if not GNAT_Mode then
8195 System_Extend_Unit := Arg1;
8199 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8203 ------------------------
8204 -- Extensions_Allowed --
8205 ------------------------
8207 -- pragma Extensions_Allowed (ON | OFF);
8209 when Pragma_Extensions_Allowed =>
8211 Check_Arg_Count (1);
8212 Check_No_Identifiers;
8213 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8215 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8216 Extensions_Allowed := True;
8217 Ada_Version := Ada_Version_Type'Last;
8220 Extensions_Allowed := False;
8221 Ada_Version := Ada_Version_Explicit;
8228 -- pragma External (
8229 -- [ Convention =>] convention_IDENTIFIER,
8230 -- [ Entity =>] local_NAME
8231 -- [, [External_Name =>] static_string_EXPRESSION ]
8232 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8234 when Pragma_External => External : declare
8238 pragma Warnings (Off, C);
8247 Check_At_Least_N_Arguments (2);
8248 Check_At_Most_N_Arguments (4);
8249 Process_Convention (C, Def_Id);
8250 Note_Possible_Modification
8251 (Get_Pragma_Arg (Arg2), Sure => False);
8252 Process_Interface_Name (Def_Id, Arg3, Arg4);
8253 Set_Exported (Def_Id, Arg2);
8256 --------------------------
8257 -- External_Name_Casing --
8258 --------------------------
8260 -- pragma External_Name_Casing (
8261 -- UPPERCASE | LOWERCASE
8262 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8264 when Pragma_External_Name_Casing => External_Name_Casing : declare
8267 Check_No_Identifiers;
8269 if Arg_Count = 2 then
8271 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8273 case Chars (Get_Pragma_Arg (Arg2)) is
8275 Opt.External_Name_Exp_Casing := As_Is;
8277 when Name_Uppercase =>
8278 Opt.External_Name_Exp_Casing := Uppercase;
8280 when Name_Lowercase =>
8281 Opt.External_Name_Exp_Casing := Lowercase;
8288 Check_Arg_Count (1);
8291 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8293 case Chars (Get_Pragma_Arg (Arg1)) is
8294 when Name_Uppercase =>
8295 Opt.External_Name_Imp_Casing := Uppercase;
8297 when Name_Lowercase =>
8298 Opt.External_Name_Imp_Casing := Lowercase;
8303 end External_Name_Casing;
8305 --------------------------
8306 -- Favor_Top_Level --
8307 --------------------------
8309 -- pragma Favor_Top_Level (type_NAME);
8311 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8312 Named_Entity : Entity_Id;
8316 Check_No_Identifiers;
8317 Check_Arg_Count (1);
8318 Check_Arg_Is_Local_Name (Arg1);
8319 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8321 -- If it's an access-to-subprogram type (in particular, not a
8322 -- subtype), set the flag on that type.
8324 if Is_Access_Subprogram_Type (Named_Entity) then
8325 Set_Can_Use_Internal_Rep (Named_Entity, False);
8327 -- Otherwise it's an error (name denotes the wrong sort of entity)
8331 ("access-to-subprogram type expected",
8332 Get_Pragma_Arg (Arg1));
8334 end Favor_Top_Level;
8340 -- pragma Fast_Math;
8342 when Pragma_Fast_Math =>
8344 Check_No_Identifiers;
8345 Check_Valid_Configuration_Pragma;
8348 ---------------------------
8349 -- Finalize_Storage_Only --
8350 ---------------------------
8352 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8354 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8355 Assoc : constant Node_Id := Arg1;
8356 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8361 Check_No_Identifiers;
8362 Check_Arg_Count (1);
8363 Check_Arg_Is_Local_Name (Arg1);
8365 Find_Type (Type_Id);
8366 Typ := Entity (Type_Id);
8369 or else Rep_Item_Too_Early (Typ, N)
8373 Typ := Underlying_Type (Typ);
8376 if not Is_Controlled (Typ) then
8377 Error_Pragma ("pragma% must specify controlled type");
8380 Check_First_Subtype (Arg1);
8382 if Finalize_Storage_Only (Typ) then
8383 Error_Pragma ("duplicate pragma%, only one allowed");
8385 elsif not Rep_Item_Too_Late (Typ, N) then
8386 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8388 end Finalize_Storage;
8390 --------------------------
8391 -- Float_Representation --
8392 --------------------------
8394 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8396 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8398 when Pragma_Float_Representation => Float_Representation : declare
8406 if Arg_Count = 1 then
8407 Check_Valid_Configuration_Pragma;
8409 Check_Arg_Count (2);
8410 Check_Optional_Identifier (Arg2, Name_Entity);
8411 Check_Arg_Is_Local_Name (Arg2);
8414 Check_No_Identifier (Arg1);
8415 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8417 if not OpenVMS_On_Target then
8418 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8420 ("?pragma% ignored (applies only to Open'V'M'S)");
8426 -- One argument case
8428 if Arg_Count = 1 then
8429 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8430 if Opt.Float_Format = 'I' then
8431 Error_Pragma ("'I'E'E'E format previously specified");
8434 Opt.Float_Format := 'V';
8437 if Opt.Float_Format = 'V' then
8438 Error_Pragma ("'V'A'X format previously specified");
8441 Opt.Float_Format := 'I';
8444 Set_Standard_Fpt_Formats;
8446 -- Two argument case
8449 Argx := Get_Pragma_Arg (Arg2);
8451 if not Is_Entity_Name (Argx)
8452 or else not Is_Floating_Point_Type (Entity (Argx))
8455 ("second argument of% pragma must be floating-point type",
8459 Ent := Entity (Argx);
8460 Digs := UI_To_Int (Digits_Value (Ent));
8462 -- Two arguments, VAX_Float case
8464 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8466 when 6 => Set_F_Float (Ent);
8467 when 9 => Set_D_Float (Ent);
8468 when 15 => Set_G_Float (Ent);
8472 ("wrong digits value, must be 6,9 or 15", Arg2);
8475 -- Two arguments, IEEE_Float case
8479 when 6 => Set_IEEE_Short (Ent);
8480 when 15 => Set_IEEE_Long (Ent);
8484 ("wrong digits value, must be 6 or 15", Arg2);
8488 end Float_Representation;
8494 -- pragma Ident (static_string_EXPRESSION)
8496 -- Note: pragma Comment shares this processing. Pragma Comment is
8497 -- identical to Ident, except that the restriction of the argument to
8498 -- 31 characters and the placement restrictions are not enforced for
8501 when Pragma_Ident | Pragma_Comment => Ident : declare
8506 Check_Arg_Count (1);
8507 Check_No_Identifiers;
8508 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8511 -- For pragma Ident, preserve DEC compatibility by requiring the
8512 -- pragma to appear in a declarative part or package spec.
8514 if Prag_Id = Pragma_Ident then
8515 Check_Is_In_Decl_Part_Or_Package_Spec;
8518 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8525 GP := Parent (Parent (N));
8527 if Nkind_In (GP, N_Package_Declaration,
8528 N_Generic_Package_Declaration)
8533 -- If we have a compilation unit, then record the ident value,
8534 -- checking for improper duplication.
8536 if Nkind (GP) = N_Compilation_Unit then
8537 CS := Ident_String (Current_Sem_Unit);
8539 if Present (CS) then
8541 -- For Ident, we do not permit multiple instances
8543 if Prag_Id = Pragma_Ident then
8544 Error_Pragma ("duplicate% pragma not permitted");
8546 -- For Comment, we concatenate the string, unless we want
8547 -- to preserve the tree structure for ASIS.
8549 elsif not ASIS_Mode then
8550 Start_String (Strval (CS));
8551 Store_String_Char (' ');
8552 Store_String_Chars (Strval (Str));
8553 Set_Strval (CS, End_String);
8557 -- In VMS, the effect of IDENT is achieved by passing
8558 -- --identification=name as a --for-linker switch.
8560 if OpenVMS_On_Target then
8563 ("--for-linker=--identification=");
8564 String_To_Name_Buffer (Strval (Str));
8565 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8567 -- Only the last processed IDENT is saved. The main
8568 -- purpose is so an IDENT associated with a main
8569 -- procedure will be used in preference to an IDENT
8570 -- associated with a with'd package.
8572 Replace_Linker_Option_String
8573 (End_String, "--for-linker=--identification=");
8576 Set_Ident_String (Current_Sem_Unit, Str);
8579 -- For subunits, we just ignore the Ident, since in GNAT these
8580 -- are not separate object files, and hence not separate units
8581 -- in the unit table.
8583 elsif Nkind (GP) = N_Subunit then
8586 -- Otherwise we have a misplaced pragma Ident, but we ignore
8587 -- this if we are in an instantiation, since it comes from
8588 -- a generic, and has no relevance to the instantiation.
8590 elsif Prag_Id = Pragma_Ident then
8591 if Instantiation_Location (Loc) = No_Location then
8592 Error_Pragma ("pragma% only allowed at outer level");
8602 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8603 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8605 when Pragma_Implemented => Implemented : declare
8606 Proc_Id : Entity_Id;
8611 Check_Arg_Count (2);
8612 Check_No_Identifiers;
8613 Check_Arg_Is_Identifier (Arg1);
8614 Check_Arg_Is_Local_Name (Arg1);
8616 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8618 -- Extract the name of the local procedure
8620 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8622 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8623 -- primitive procedure of a synchronized tagged type.
8625 if Ekind (Proc_Id) = E_Procedure
8626 and then Is_Primitive (Proc_Id)
8627 and then Present (First_Formal (Proc_Id))
8629 Typ := Etype (First_Formal (Proc_Id));
8631 if Is_Tagged_Type (Typ)
8634 -- Check for a protected, a synchronized or a task interface
8636 ((Is_Interface (Typ)
8637 and then Is_Synchronized_Interface (Typ))
8639 -- Check for a protected type or a task type that implements
8643 (Is_Concurrent_Record_Type (Typ)
8644 and then Present (Interfaces (Typ)))
8646 -- Check for a private record extension with keyword
8650 (Ekind_In (Typ, E_Record_Type_With_Private,
8651 E_Record_Subtype_With_Private)
8652 and then Synchronized_Present (Parent (Typ))))
8657 ("controlling formal must be of synchronized " &
8658 "tagged type", Arg1);
8662 -- Procedures declared inside a protected type must be accepted
8664 elsif Ekind (Proc_Id) = E_Procedure
8665 and then Is_Protected_Type (Scope (Proc_Id))
8669 -- The first argument is not a primitive procedure
8673 ("pragma % must be applied to a primitive procedure", Arg1);
8677 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8678 -- By_Protected_Procedure to the primitive procedure of a task
8681 if Chars (Arg2) = Name_By_Protected_Procedure
8682 and then Is_Interface (Typ)
8683 and then Is_Task_Interface (Typ)
8686 ("implementation kind By_Protected_Procedure cannot be " &
8687 "applied to a task interface primitive", Arg2);
8691 Record_Rep_Item (Proc_Id, N);
8694 ----------------------
8695 -- Implicit_Packing --
8696 ----------------------
8698 -- pragma Implicit_Packing;
8700 when Pragma_Implicit_Packing =>
8702 Check_Arg_Count (0);
8703 Implicit_Packing := True;
8710 -- [Convention =>] convention_IDENTIFIER,
8711 -- [Entity =>] local_NAME
8712 -- [, [External_Name =>] static_string_EXPRESSION ]
8713 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8715 when Pragma_Import =>
8716 Check_Ada_83_Warning;
8722 Check_At_Least_N_Arguments (2);
8723 Check_At_Most_N_Arguments (4);
8724 Process_Import_Or_Interface;
8726 ----------------------
8727 -- Import_Exception --
8728 ----------------------
8730 -- pragma Import_Exception (
8731 -- [Internal =>] LOCAL_NAME
8732 -- [, [External =>] EXTERNAL_SYMBOL]
8733 -- [, [Form =>] Ada | VMS]
8734 -- [, [Code =>] static_integer_EXPRESSION]);
8736 when Pragma_Import_Exception => Import_Exception : declare
8737 Args : Args_List (1 .. 4);
8738 Names : constant Name_List (1 .. 4) := (
8744 Internal : Node_Id renames Args (1);
8745 External : Node_Id renames Args (2);
8746 Form : Node_Id renames Args (3);
8747 Code : Node_Id renames Args (4);
8751 Gather_Associations (Names, Args);
8753 if Present (External) and then Present (Code) then
8755 ("cannot give both External and Code options for pragma%");
8758 Process_Extended_Import_Export_Exception_Pragma (
8759 Arg_Internal => Internal,
8760 Arg_External => External,
8764 if not Is_VMS_Exception (Entity (Internal)) then
8765 Set_Imported (Entity (Internal));
8767 end Import_Exception;
8769 ---------------------
8770 -- Import_Function --
8771 ---------------------
8773 -- pragma Import_Function (
8774 -- [Internal =>] LOCAL_NAME,
8775 -- [, [External =>] EXTERNAL_SYMBOL]
8776 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8777 -- [, [Result_Type =>] SUBTYPE_MARK]
8778 -- [, [Mechanism =>] MECHANISM]
8779 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8780 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8782 -- EXTERNAL_SYMBOL ::=
8784 -- | static_string_EXPRESSION
8786 -- PARAMETER_TYPES ::=
8788 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8790 -- TYPE_DESIGNATOR ::=
8792 -- | subtype_Name ' Access
8796 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8798 -- MECHANISM_ASSOCIATION ::=
8799 -- [formal_parameter_NAME =>] MECHANISM_NAME
8801 -- MECHANISM_NAME ::=
8804 -- | Descriptor [([Class =>] CLASS_NAME)]
8806 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8808 when Pragma_Import_Function => Import_Function : declare
8809 Args : Args_List (1 .. 7);
8810 Names : constant Name_List (1 .. 7) := (
8813 Name_Parameter_Types,
8816 Name_Result_Mechanism,
8817 Name_First_Optional_Parameter);
8819 Internal : Node_Id renames Args (1);
8820 External : Node_Id renames Args (2);
8821 Parameter_Types : Node_Id renames Args (3);
8822 Result_Type : Node_Id renames Args (4);
8823 Mechanism : Node_Id renames Args (5);
8824 Result_Mechanism : Node_Id renames Args (6);
8825 First_Optional_Parameter : Node_Id renames Args (7);
8829 Gather_Associations (Names, Args);
8830 Process_Extended_Import_Export_Subprogram_Pragma (
8831 Arg_Internal => Internal,
8832 Arg_External => External,
8833 Arg_Parameter_Types => Parameter_Types,
8834 Arg_Result_Type => Result_Type,
8835 Arg_Mechanism => Mechanism,
8836 Arg_Result_Mechanism => Result_Mechanism,
8837 Arg_First_Optional_Parameter => First_Optional_Parameter);
8838 end Import_Function;
8844 -- pragma Import_Object (
8845 -- [Internal =>] LOCAL_NAME
8846 -- [, [External =>] EXTERNAL_SYMBOL]
8847 -- [, [Size =>] EXTERNAL_SYMBOL]);
8849 -- EXTERNAL_SYMBOL ::=
8851 -- | static_string_EXPRESSION
8853 when Pragma_Import_Object => Import_Object : declare
8854 Args : Args_List (1 .. 3);
8855 Names : constant Name_List (1 .. 3) := (
8860 Internal : Node_Id renames Args (1);
8861 External : Node_Id renames Args (2);
8862 Size : Node_Id renames Args (3);
8866 Gather_Associations (Names, Args);
8867 Process_Extended_Import_Export_Object_Pragma (
8868 Arg_Internal => Internal,
8869 Arg_External => External,
8873 ----------------------
8874 -- Import_Procedure --
8875 ----------------------
8877 -- pragma Import_Procedure (
8878 -- [Internal =>] LOCAL_NAME
8879 -- [, [External =>] EXTERNAL_SYMBOL]
8880 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8881 -- [, [Mechanism =>] MECHANISM]
8882 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8884 -- EXTERNAL_SYMBOL ::=
8886 -- | static_string_EXPRESSION
8888 -- PARAMETER_TYPES ::=
8890 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8892 -- TYPE_DESIGNATOR ::=
8894 -- | subtype_Name ' Access
8898 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8900 -- MECHANISM_ASSOCIATION ::=
8901 -- [formal_parameter_NAME =>] MECHANISM_NAME
8903 -- MECHANISM_NAME ::=
8906 -- | Descriptor [([Class =>] CLASS_NAME)]
8908 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8910 when Pragma_Import_Procedure => Import_Procedure : declare
8911 Args : Args_List (1 .. 5);
8912 Names : constant Name_List (1 .. 5) := (
8915 Name_Parameter_Types,
8917 Name_First_Optional_Parameter);
8919 Internal : Node_Id renames Args (1);
8920 External : Node_Id renames Args (2);
8921 Parameter_Types : Node_Id renames Args (3);
8922 Mechanism : Node_Id renames Args (4);
8923 First_Optional_Parameter : Node_Id renames Args (5);
8927 Gather_Associations (Names, Args);
8928 Process_Extended_Import_Export_Subprogram_Pragma (
8929 Arg_Internal => Internal,
8930 Arg_External => External,
8931 Arg_Parameter_Types => Parameter_Types,
8932 Arg_Mechanism => Mechanism,
8933 Arg_First_Optional_Parameter => First_Optional_Parameter);
8934 end Import_Procedure;
8936 -----------------------------
8937 -- Import_Valued_Procedure --
8938 -----------------------------
8940 -- pragma Import_Valued_Procedure (
8941 -- [Internal =>] LOCAL_NAME
8942 -- [, [External =>] EXTERNAL_SYMBOL]
8943 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8944 -- [, [Mechanism =>] MECHANISM]
8945 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8947 -- EXTERNAL_SYMBOL ::=
8949 -- | static_string_EXPRESSION
8951 -- PARAMETER_TYPES ::=
8953 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8955 -- TYPE_DESIGNATOR ::=
8957 -- | subtype_Name ' Access
8961 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8963 -- MECHANISM_ASSOCIATION ::=
8964 -- [formal_parameter_NAME =>] MECHANISM_NAME
8966 -- MECHANISM_NAME ::=
8969 -- | Descriptor [([Class =>] CLASS_NAME)]
8971 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8973 when Pragma_Import_Valued_Procedure =>
8974 Import_Valued_Procedure : declare
8975 Args : Args_List (1 .. 5);
8976 Names : constant Name_List (1 .. 5) := (
8979 Name_Parameter_Types,
8981 Name_First_Optional_Parameter);
8983 Internal : Node_Id renames Args (1);
8984 External : Node_Id renames Args (2);
8985 Parameter_Types : Node_Id renames Args (3);
8986 Mechanism : Node_Id renames Args (4);
8987 First_Optional_Parameter : Node_Id renames Args (5);
8991 Gather_Associations (Names, Args);
8992 Process_Extended_Import_Export_Subprogram_Pragma (
8993 Arg_Internal => Internal,
8994 Arg_External => External,
8995 Arg_Parameter_Types => Parameter_Types,
8996 Arg_Mechanism => Mechanism,
8997 Arg_First_Optional_Parameter => First_Optional_Parameter);
8998 end Import_Valued_Procedure;
9004 -- pragma Independent (LOCAL_NAME);
9006 when Pragma_Independent => Independent : declare
9013 Check_Ada_83_Warning;
9015 Check_No_Identifiers;
9016 Check_Arg_Count (1);
9017 Check_Arg_Is_Local_Name (Arg1);
9018 E_Id := Get_Pragma_Arg (Arg1);
9020 if Etype (E_Id) = Any_Type then
9025 D := Declaration_Node (E);
9028 -- Check duplicate before we chain ourselves!
9030 Check_Duplicate_Pragma (E);
9032 -- Check appropriate entity
9035 if Rep_Item_Too_Early (E, N)
9037 Rep_Item_Too_Late (E, N)
9041 Check_First_Subtype (Arg1);
9044 elsif K = N_Object_Declaration
9045 or else (K = N_Component_Declaration
9046 and then Original_Record_Component (E) = E)
9048 if Rep_Item_Too_Late (E, N) then
9054 ("inappropriate entity for pragma%", Arg1);
9057 Independence_Checks.Append ((N, E));
9060 ----------------------------
9061 -- Independent_Components --
9062 ----------------------------
9064 -- pragma Atomic_Components (array_LOCAL_NAME);
9066 -- This processing is shared by Volatile_Components
9068 when Pragma_Independent_Components => Independent_Components : declare
9075 Check_Ada_83_Warning;
9077 Check_No_Identifiers;
9078 Check_Arg_Count (1);
9079 Check_Arg_Is_Local_Name (Arg1);
9080 E_Id := Get_Pragma_Arg (Arg1);
9082 if Etype (E_Id) = Any_Type then
9088 -- Check duplicate before we chain ourselves!
9090 Check_Duplicate_Pragma (E);
9092 -- Check appropriate entity
9094 if Rep_Item_Too_Early (E, N)
9096 Rep_Item_Too_Late (E, N)
9101 D := Declaration_Node (E);
9104 if (K = N_Full_Type_Declaration
9105 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9107 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9108 and then Nkind (D) = N_Object_Declaration
9109 and then Nkind (Object_Definition (D)) =
9110 N_Constrained_Array_Definition)
9112 Independence_Checks.Append ((N, E));
9115 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9117 end Independent_Components;
9119 ------------------------
9120 -- Initialize_Scalars --
9121 ------------------------
9123 -- pragma Initialize_Scalars;
9125 when Pragma_Initialize_Scalars =>
9127 Check_Arg_Count (0);
9128 Check_Valid_Configuration_Pragma;
9129 Check_Restriction (No_Initialize_Scalars, N);
9131 -- Initialize_Scalars creates false positives in CodePeer,
9132 -- so ignore this pragma in this mode.
9134 if not Restriction_Active (No_Initialize_Scalars)
9135 and then not CodePeer_Mode
9137 Init_Or_Norm_Scalars := True;
9138 Initialize_Scalars := True;
9145 -- pragma Inline ( NAME {, NAME} );
9147 when Pragma_Inline =>
9149 -- Pragma is active if inlining option is active
9151 Process_Inline (Inline_Active);
9157 -- pragma Inline_Always ( NAME {, NAME} );
9159 when Pragma_Inline_Always =>
9162 -- Pragma always active unless in CodePeer mode, since this causes
9163 -- walk order issues.
9165 if not CodePeer_Mode then
9166 Process_Inline (True);
9169 --------------------
9170 -- Inline_Generic --
9171 --------------------
9173 -- pragma Inline_Generic (NAME {, NAME});
9175 when Pragma_Inline_Generic =>
9177 Process_Generic_List;
9179 ----------------------
9180 -- Inspection_Point --
9181 ----------------------
9183 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9185 when Pragma_Inspection_Point => Inspection_Point : declare
9190 if Arg_Count > 0 then
9193 Exp := Get_Pragma_Arg (Arg);
9196 if not Is_Entity_Name (Exp)
9197 or else not Is_Object (Entity (Exp))
9199 Error_Pragma_Arg ("object name required", Arg);
9206 end Inspection_Point;
9212 -- pragma Interface (
9213 -- [ Convention =>] convention_IDENTIFIER,
9214 -- [ Entity =>] local_NAME
9215 -- [, [External_Name =>] static_string_EXPRESSION ]
9216 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9218 when Pragma_Interface =>
9225 Check_At_Least_N_Arguments (2);
9226 Check_At_Most_N_Arguments (4);
9227 Process_Import_Or_Interface;
9229 -- In Ada 2005, the permission to use Interface (a reserved word)
9230 -- as a pragma name is considered an obsolescent feature.
9232 if Ada_Version >= Ada_2005 then
9234 (No_Obsolescent_Features, Pragma_Identifier (N));
9237 --------------------
9238 -- Interface_Name --
9239 --------------------
9241 -- pragma Interface_Name (
9242 -- [ Entity =>] local_NAME
9243 -- [,[External_Name =>] static_string_EXPRESSION ]
9244 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9246 when Pragma_Interface_Name => Interface_Name : declare
9255 ((Name_Entity, Name_External_Name, Name_Link_Name));
9256 Check_At_Least_N_Arguments (2);
9257 Check_At_Most_N_Arguments (3);
9258 Id := Get_Pragma_Arg (Arg1);
9261 if not Is_Entity_Name (Id) then
9263 ("first argument for pragma% must be entity name", Arg1);
9264 elsif Etype (Id) = Any_Type then
9267 Def_Id := Entity (Id);
9270 -- Special DEC-compatible processing for the object case, forces
9271 -- object to be imported.
9273 if Ekind (Def_Id) = E_Variable then
9274 Kill_Size_Check_Code (Def_Id);
9275 Note_Possible_Modification (Id, Sure => False);
9277 -- Initialization is not allowed for imported variable
9279 if Present (Expression (Parent (Def_Id)))
9280 and then Comes_From_Source (Expression (Parent (Def_Id)))
9282 Error_Msg_Sloc := Sloc (Def_Id);
9284 ("no initialization allowed for declaration of& #",
9288 -- For compatibility, support VADS usage of providing both
9289 -- pragmas Interface and Interface_Name to obtain the effect
9290 -- of a single Import pragma.
9292 if Is_Imported (Def_Id)
9293 and then Present (First_Rep_Item (Def_Id))
9294 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9296 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9300 Set_Imported (Def_Id);
9303 Set_Is_Public (Def_Id);
9304 Process_Interface_Name (Def_Id, Arg2, Arg3);
9307 -- Otherwise must be subprogram
9309 elsif not Is_Subprogram (Def_Id) then
9311 ("argument of pragma% is not subprogram", Arg1);
9314 Check_At_Most_N_Arguments (3);
9318 -- Loop through homonyms
9321 Def_Id := Get_Base_Subprogram (Hom_Id);
9323 if Is_Imported (Def_Id) then
9324 Process_Interface_Name (Def_Id, Arg2, Arg3);
9328 exit when From_Aspect_Specification (N);
9329 Hom_Id := Homonym (Hom_Id);
9331 exit when No (Hom_Id)
9332 or else Scope (Hom_Id) /= Current_Scope;
9337 ("argument of pragma% is not imported subprogram",
9343 -----------------------
9344 -- Interrupt_Handler --
9345 -----------------------
9347 -- pragma Interrupt_Handler (handler_NAME);
9349 when Pragma_Interrupt_Handler =>
9350 Check_Ada_83_Warning;
9351 Check_Arg_Count (1);
9352 Check_No_Identifiers;
9354 if No_Run_Time_Mode then
9355 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9357 Check_Interrupt_Or_Attach_Handler;
9358 Process_Interrupt_Or_Attach_Handler;
9361 ------------------------
9362 -- Interrupt_Priority --
9363 ------------------------
9365 -- pragma Interrupt_Priority [(EXPRESSION)];
9367 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9368 P : constant Node_Id := Parent (N);
9372 Check_Ada_83_Warning;
9374 if Arg_Count /= 0 then
9375 Arg := Get_Pragma_Arg (Arg1);
9376 Check_Arg_Count (1);
9377 Check_No_Identifiers;
9379 -- The expression must be analyzed in the special manner
9380 -- described in "Handling of Default and Per-Object
9381 -- Expressions" in sem.ads.
9383 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9386 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9390 elsif Has_Pragma_Priority (P) then
9391 Error_Pragma ("duplicate pragma% not allowed");
9394 Set_Has_Pragma_Priority (P, True);
9395 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9397 end Interrupt_Priority;
9399 ---------------------
9400 -- Interrupt_State --
9401 ---------------------
9403 -- pragma Interrupt_State (
9404 -- [Name =>] INTERRUPT_ID,
9405 -- [State =>] INTERRUPT_STATE);
9407 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9408 -- INTERRUPT_STATE => System | Runtime | User
9410 -- Note: if the interrupt id is given as an identifier, then it must
9411 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9412 -- given as a static integer expression which must be in the range of
9413 -- Ada.Interrupts.Interrupt_ID.
9415 when Pragma_Interrupt_State => Interrupt_State : declare
9417 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9418 -- This is the entity Ada.Interrupts.Interrupt_ID;
9420 State_Type : Character;
9421 -- Set to 's'/'r'/'u' for System/Runtime/User
9424 -- Index to entry in Interrupt_States table
9427 -- Value of interrupt
9429 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9430 -- The first argument to the pragma
9432 Int_Ent : Entity_Id;
9433 -- Interrupt entity in Ada.Interrupts.Names
9437 Check_Arg_Order ((Name_Name, Name_State));
9438 Check_Arg_Count (2);
9440 Check_Optional_Identifier (Arg1, Name_Name);
9441 Check_Optional_Identifier (Arg2, Name_State);
9442 Check_Arg_Is_Identifier (Arg2);
9444 -- First argument is identifier
9446 if Nkind (Arg1X) = N_Identifier then
9448 -- Search list of names in Ada.Interrupts.Names
9450 Int_Ent := First_Entity (RTE (RE_Names));
9452 if No (Int_Ent) then
9453 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9455 elsif Chars (Int_Ent) = Chars (Arg1X) then
9456 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9460 Next_Entity (Int_Ent);
9463 -- First argument is not an identifier, so it must be a static
9464 -- expression of type Ada.Interrupts.Interrupt_ID.
9467 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9468 Int_Val := Expr_Value (Arg1X);
9470 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9472 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9475 ("value not in range of type " &
9476 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9482 case Chars (Get_Pragma_Arg (Arg2)) is
9483 when Name_Runtime => State_Type := 'r';
9484 when Name_System => State_Type := 's';
9485 when Name_User => State_Type := 'u';
9488 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9491 -- Check if entry is already stored
9493 IST_Num := Interrupt_States.First;
9495 -- If entry not found, add it
9497 if IST_Num > Interrupt_States.Last then
9498 Interrupt_States.Append
9499 ((Interrupt_Number => UI_To_Int (Int_Val),
9500 Interrupt_State => State_Type,
9501 Pragma_Loc => Loc));
9504 -- Case of entry for the same entry
9506 elsif Int_Val = Interrupt_States.Table (IST_Num).
9509 -- If state matches, done, no need to make redundant entry
9512 State_Type = Interrupt_States.Table (IST_Num).
9515 -- Otherwise if state does not match, error
9518 Interrupt_States.Table (IST_Num).Pragma_Loc;
9520 ("state conflicts with that given #", Arg2);
9524 IST_Num := IST_Num + 1;
9526 end Interrupt_State;
9533 -- ([Entity =>] type_LOCAL_NAME,
9534 -- [Check =>] EXPRESSION
9535 -- [,[Message =>] String_Expression]);
9537 when Pragma_Invariant => Invariant : declare
9542 pragma Unreferenced (Discard);
9546 Check_At_Least_N_Arguments (2);
9547 Check_At_Most_N_Arguments (3);
9548 Check_Optional_Identifier (Arg1, Name_Entity);
9549 Check_Optional_Identifier (Arg2, Name_Check);
9551 if Arg_Count = 3 then
9552 Check_Optional_Identifier (Arg3, Name_Message);
9553 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9556 Check_Arg_Is_Local_Name (Arg1);
9558 Type_Id := Get_Pragma_Arg (Arg1);
9559 Find_Type (Type_Id);
9560 Typ := Entity (Type_Id);
9562 if Typ = Any_Type then
9565 elsif not Ekind_In (Typ, E_Private_Type,
9566 E_Record_Type_With_Private,
9567 E_Limited_Private_Type)
9570 ("pragma% only allowed for private type", Arg1);
9573 -- Note that the type has at least one invariant, and also that
9574 -- it has inheritable invariants if we have Invariant'Class.
9576 Set_Has_Invariants (Typ);
9578 if Class_Present (N) then
9579 Set_Has_Inheritable_Invariants (Typ);
9582 -- The remaining processing is simply to link the pragma on to
9583 -- the rep item chain, for processing when the type is frozen.
9584 -- This is accomplished by a call to Rep_Item_Too_Late.
9586 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9589 ----------------------
9590 -- Java_Constructor --
9591 ----------------------
9593 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9595 -- Also handles pragma CIL_Constructor
9597 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9598 Java_Constructor : declare
9599 Convention : Convention_Id;
9603 This_Formal : Entity_Id;
9607 Check_Arg_Count (1);
9608 Check_Optional_Identifier (Arg1, Name_Entity);
9609 Check_Arg_Is_Local_Name (Arg1);
9611 Id := Get_Pragma_Arg (Arg1);
9612 Find_Program_Unit_Name (Id);
9614 -- If we did not find the name, we are done
9616 if Etype (Id) = Any_Type then
9620 -- Check wrong use of pragma in wrong VM target
9622 if VM_Target = No_VM then
9625 elsif VM_Target = CLI_Target
9626 and then Prag_Id = Pragma_Java_Constructor
9628 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9630 elsif VM_Target = JVM_Target
9631 and then Prag_Id = Pragma_CIL_Constructor
9633 Error_Pragma ("must use pragma 'Java_'Constructor");
9637 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9638 when Pragma_Java_Constructor => Convention := Convention_Java;
9639 when others => null;
9642 Hom_Id := Entity (Id);
9644 -- Loop through homonyms
9647 Def_Id := Get_Base_Subprogram (Hom_Id);
9649 -- The constructor is required to be a function
9651 if Ekind (Def_Id) /= E_Function then
9652 if VM_Target = JVM_Target then
9654 ("pragma% requires function returning a " &
9655 "'Java access type", Def_Id);
9658 ("pragma% requires function returning a " &
9659 "'C'I'L access type", Def_Id);
9663 -- Check arguments: For tagged type the first formal must be
9664 -- named "this" and its type must be a named access type
9665 -- designating a class-wide tagged type that has convention
9666 -- CIL/Java. The first formal must also have a null default
9667 -- value. For example:
9669 -- type Typ is tagged ...
9670 -- type Ref is access all Typ;
9671 -- pragma Convention (CIL, Typ);
9673 -- function New_Typ (This : Ref) return Ref;
9674 -- function New_Typ (This : Ref; I : Integer) return Ref;
9675 -- pragma Cil_Constructor (New_Typ);
9677 -- Reason: The first formal must NOT be a primitive of the
9680 -- This rule also applies to constructors of delegates used
9681 -- to interface with standard target libraries. For example:
9683 -- type Delegate is access procedure ...
9684 -- pragma Import (CIL, Delegate, ...);
9686 -- function new_Delegate
9687 -- (This : Delegate := null; ... ) return Delegate;
9689 -- For value-types this rule does not apply.
9691 if not Is_Value_Type (Etype (Def_Id)) then
9692 if No (First_Formal (Def_Id)) then
9693 Error_Msg_Name_1 := Pname;
9694 Error_Msg_N ("% function must have parameters", Def_Id);
9698 -- In the JRE library we have several occurrences in which
9699 -- the "this" parameter is not the first formal.
9701 This_Formal := First_Formal (Def_Id);
9703 -- In the JRE library we have several occurrences in which
9704 -- the "this" parameter is not the first formal. Search for
9707 if VM_Target = JVM_Target then
9708 while Present (This_Formal)
9709 and then Get_Name_String (Chars (This_Formal)) /= "this"
9711 Next_Formal (This_Formal);
9714 if No (This_Formal) then
9715 This_Formal := First_Formal (Def_Id);
9719 -- Warning: The first parameter should be named "this".
9720 -- We temporarily allow it because we have the following
9721 -- case in the Java runtime (file s-osinte.ads) ???
9723 -- function new_Thread
9724 -- (Self_Id : System.Address) return Thread_Id;
9725 -- pragma Java_Constructor (new_Thread);
9727 if VM_Target = JVM_Target
9728 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9730 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9734 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9735 Error_Msg_Name_1 := Pname;
9737 ("first formal of % function must be named `this`",
9738 Parent (This_Formal));
9740 elsif not Is_Access_Type (Etype (This_Formal)) then
9741 Error_Msg_Name_1 := Pname;
9743 ("first formal of % function must be an access type",
9744 Parameter_Type (Parent (This_Formal)));
9746 -- For delegates the type of the first formal must be a
9747 -- named access-to-subprogram type (see previous example)
9749 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9750 and then Ekind (Etype (This_Formal))
9751 /= E_Access_Subprogram_Type
9753 Error_Msg_Name_1 := Pname;
9755 ("first formal of % function must be a named access" &
9756 " to subprogram type",
9757 Parameter_Type (Parent (This_Formal)));
9759 -- Warning: We should reject anonymous access types because
9760 -- the constructor must not be handled as a primitive of the
9761 -- tagged type. We temporarily allow it because this profile
9762 -- is currently generated by cil2ada???
9764 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9765 and then not Ekind_In (Etype (This_Formal),
9767 E_General_Access_Type,
9768 E_Anonymous_Access_Type)
9770 Error_Msg_Name_1 := Pname;
9772 ("first formal of % function must be a named access" &
9774 Parameter_Type (Parent (This_Formal)));
9776 elsif Atree.Convention
9777 (Designated_Type (Etype (This_Formal))) /= Convention
9779 Error_Msg_Name_1 := Pname;
9781 if Convention = Convention_Java then
9783 ("pragma% requires convention 'Cil in designated" &
9785 Parameter_Type (Parent (This_Formal)));
9788 ("pragma% requires convention 'Java in designated" &
9790 Parameter_Type (Parent (This_Formal)));
9793 elsif No (Expression (Parent (This_Formal)))
9794 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9796 Error_Msg_Name_1 := Pname;
9798 ("pragma% requires first formal with default `null`",
9799 Parameter_Type (Parent (This_Formal)));
9803 -- Check result type: the constructor must be a function
9805 -- * a value type (only allowed in the CIL compiler)
9806 -- * an access-to-subprogram type with convention Java/CIL
9807 -- * an access-type designating a type that has convention
9810 if Is_Value_Type (Etype (Def_Id)) then
9813 -- Access-to-subprogram type with convention Java/CIL
9815 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9816 if Atree.Convention (Etype (Def_Id)) /= Convention then
9817 if Convention = Convention_Java then
9819 ("pragma% requires function returning a " &
9820 "'Java access type", Arg1);
9822 pragma Assert (Convention = Convention_CIL);
9824 ("pragma% requires function returning a " &
9825 "'C'I'L access type", Arg1);
9829 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9830 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9831 E_General_Access_Type)
9834 (Designated_Type (Etype (Def_Id))) /= Convention
9836 Error_Msg_Name_1 := Pname;
9838 if Convention = Convention_Java then
9840 ("pragma% requires function returning a named" &
9841 "'Java access type", Arg1);
9844 ("pragma% requires function returning a named" &
9845 "'C'I'L access type", Arg1);
9850 Set_Is_Constructor (Def_Id);
9851 Set_Convention (Def_Id, Convention);
9852 Set_Is_Imported (Def_Id);
9854 exit when From_Aspect_Specification (N);
9855 Hom_Id := Homonym (Hom_Id);
9857 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9859 end Java_Constructor;
9861 ----------------------
9862 -- Java_Interface --
9863 ----------------------
9865 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9867 when Pragma_Java_Interface => Java_Interface : declare
9873 Check_Arg_Count (1);
9874 Check_Optional_Identifier (Arg1, Name_Entity);
9875 Check_Arg_Is_Local_Name (Arg1);
9877 Arg := Get_Pragma_Arg (Arg1);
9880 if Etype (Arg) = Any_Type then
9884 if not Is_Entity_Name (Arg)
9885 or else not Is_Type (Entity (Arg))
9887 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9890 Typ := Underlying_Type (Entity (Arg));
9892 -- For now simply check some of the semantic constraints on the
9893 -- type. This currently leaves out some restrictions on interface
9894 -- types, namely that the parent type must be java.lang.Object.Typ
9895 -- and that all primitives of the type should be declared
9898 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9899 Error_Pragma_Arg ("pragma% requires an abstract "
9900 & "tagged type", Arg1);
9902 elsif not Has_Discriminants (Typ)
9903 or else Ekind (Etype (First_Discriminant (Typ)))
9904 /= E_Anonymous_Access_Type
9906 not Is_Class_Wide_Type
9907 (Designated_Type (Etype (First_Discriminant (Typ))))
9910 ("type must have a class-wide access discriminant", Arg1);
9918 -- pragma Keep_Names ([On => ] local_NAME);
9920 when Pragma_Keep_Names => Keep_Names : declare
9925 Check_Arg_Count (1);
9926 Check_Optional_Identifier (Arg1, Name_On);
9927 Check_Arg_Is_Local_Name (Arg1);
9929 Arg := Get_Pragma_Arg (Arg1);
9932 if Etype (Arg) = Any_Type then
9936 if not Is_Entity_Name (Arg)
9937 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
9940 ("pragma% requires a local enumeration type", Arg1);
9943 Set_Discard_Names (Entity (Arg), False);
9950 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
9952 when Pragma_License =>
9954 Check_Arg_Count (1);
9955 Check_No_Identifiers;
9956 Check_Valid_Configuration_Pragma;
9957 Check_Arg_Is_Identifier (Arg1);
9960 Sind : constant Source_File_Index :=
9961 Source_Index (Current_Sem_Unit);
9964 case Chars (Get_Pragma_Arg (Arg1)) is
9966 Set_License (Sind, GPL);
9968 when Name_Modified_GPL =>
9969 Set_License (Sind, Modified_GPL);
9971 when Name_Restricted =>
9972 Set_License (Sind, Restricted);
9974 when Name_Unrestricted =>
9975 Set_License (Sind, Unrestricted);
9978 Error_Pragma_Arg ("invalid license name", Arg1);
9986 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
9988 when Pragma_Link_With => Link_With : declare
9994 if Operating_Mode = Generate_Code
9995 and then In_Extended_Main_Source_Unit (N)
9997 Check_At_Least_N_Arguments (1);
9998 Check_No_Identifiers;
9999 Check_Is_In_Decl_Part_Or_Package_Spec;
10000 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10004 while Present (Arg) loop
10005 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10007 -- Store argument, converting sequences of spaces to a
10008 -- single null character (this is one of the differences
10009 -- in processing between Link_With and Linker_Options).
10011 Arg_Store : declare
10012 C : constant Char_Code := Get_Char_Code (' ');
10013 S : constant String_Id :=
10014 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10015 L : constant Nat := String_Length (S);
10018 procedure Skip_Spaces;
10019 -- Advance F past any spaces
10025 procedure Skip_Spaces is
10027 while F <= L and then Get_String_Char (S, F) = C loop
10032 -- Start of processing for Arg_Store
10035 Skip_Spaces; -- skip leading spaces
10037 -- Loop through characters, changing any embedded
10038 -- sequence of spaces to a single null character (this
10039 -- is how Link_With/Linker_Options differ)
10042 if Get_String_Char (S, F) = C then
10045 Store_String_Char (ASCII.NUL);
10048 Store_String_Char (Get_String_Char (S, F));
10056 if Present (Arg) then
10057 Store_String_Char (ASCII.NUL);
10061 Store_Linker_Option_String (End_String);
10069 -- pragma Linker_Alias (
10070 -- [Entity =>] LOCAL_NAME
10071 -- [Target =>] static_string_EXPRESSION);
10073 when Pragma_Linker_Alias =>
10075 Check_Arg_Order ((Name_Entity, Name_Target));
10076 Check_Arg_Count (2);
10077 Check_Optional_Identifier (Arg1, Name_Entity);
10078 Check_Optional_Identifier (Arg2, Name_Target);
10079 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10080 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10082 -- The only processing required is to link this item on to the
10083 -- list of rep items for the given entity. This is accomplished
10084 -- by the call to Rep_Item_Too_Late (when no error is detected
10085 -- and False is returned).
10087 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10090 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10093 ------------------------
10094 -- Linker_Constructor --
10095 ------------------------
10097 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10099 -- Code is shared with Linker_Destructor
10101 -----------------------
10102 -- Linker_Destructor --
10103 -----------------------
10105 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10107 when Pragma_Linker_Constructor |
10108 Pragma_Linker_Destructor =>
10109 Linker_Constructor : declare
10115 Check_Arg_Count (1);
10116 Check_No_Identifiers;
10117 Check_Arg_Is_Local_Name (Arg1);
10118 Arg1_X := Get_Pragma_Arg (Arg1);
10120 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10122 if not Is_Library_Level_Entity (Proc) then
10124 ("argument for pragma% must be library level entity", Arg1);
10127 -- The only processing required is to link this item on to the
10128 -- list of rep items for the given entity. This is accomplished
10129 -- by the call to Rep_Item_Too_Late (when no error is detected
10130 -- and False is returned).
10132 if Rep_Item_Too_Late (Proc, N) then
10135 Set_Has_Gigi_Rep_Item (Proc);
10137 end Linker_Constructor;
10139 --------------------
10140 -- Linker_Options --
10141 --------------------
10143 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10145 when Pragma_Linker_Options => Linker_Options : declare
10149 Check_Ada_83_Warning;
10150 Check_No_Identifiers;
10151 Check_Arg_Count (1);
10152 Check_Is_In_Decl_Part_Or_Package_Spec;
10153 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10154 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10157 while Present (Arg) loop
10158 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10159 Store_String_Char (ASCII.NUL);
10161 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10165 if Operating_Mode = Generate_Code
10166 and then In_Extended_Main_Source_Unit (N)
10168 Store_Linker_Option_String (End_String);
10170 end Linker_Options;
10172 --------------------
10173 -- Linker_Section --
10174 --------------------
10176 -- pragma Linker_Section (
10177 -- [Entity =>] LOCAL_NAME
10178 -- [Section =>] static_string_EXPRESSION);
10180 when Pragma_Linker_Section =>
10182 Check_Arg_Order ((Name_Entity, Name_Section));
10183 Check_Arg_Count (2);
10184 Check_Optional_Identifier (Arg1, Name_Entity);
10185 Check_Optional_Identifier (Arg2, Name_Section);
10186 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10187 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10189 -- This pragma applies only to objects
10191 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10192 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10195 -- The only processing required is to link this item on to the
10196 -- list of rep items for the given entity. This is accomplished
10197 -- by the call to Rep_Item_Too_Late (when no error is detected
10198 -- and False is returned).
10200 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10203 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10210 -- pragma List (On | Off)
10212 -- There is nothing to do here, since we did all the processing for
10213 -- this pragma in Par.Prag (so that it works properly even in syntax
10216 when Pragma_List =>
10219 --------------------
10220 -- Locking_Policy --
10221 --------------------
10223 -- pragma Locking_Policy (policy_IDENTIFIER);
10225 when Pragma_Locking_Policy => declare
10229 Check_Ada_83_Warning;
10230 Check_Arg_Count (1);
10231 Check_No_Identifiers;
10232 Check_Arg_Is_Locking_Policy (Arg1);
10233 Check_Valid_Configuration_Pragma;
10234 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10235 LP := Fold_Upper (Name_Buffer (1));
10237 if Locking_Policy /= ' '
10238 and then Locking_Policy /= LP
10240 Error_Msg_Sloc := Locking_Policy_Sloc;
10241 Error_Pragma ("locking policy incompatible with policy#");
10243 -- Set new policy, but always preserve System_Location since we
10244 -- like the error message with the run time name.
10247 Locking_Policy := LP;
10249 if Locking_Policy_Sloc /= System_Location then
10250 Locking_Policy_Sloc := Loc;
10259 -- pragma Long_Float (D_Float | G_Float);
10261 when Pragma_Long_Float =>
10263 Check_Valid_Configuration_Pragma;
10264 Check_Arg_Count (1);
10265 Check_No_Identifier (Arg1);
10266 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10268 if not OpenVMS_On_Target then
10269 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10274 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10275 if Opt.Float_Format_Long = 'G' then
10276 Error_Pragma ("G_Float previously specified");
10279 Opt.Float_Format_Long := 'D';
10281 -- G_Float case (this is the default, does not need overriding)
10284 if Opt.Float_Format_Long = 'D' then
10285 Error_Pragma ("D_Float previously specified");
10288 Opt.Float_Format_Long := 'G';
10291 Set_Standard_Fpt_Formats;
10293 -----------------------
10294 -- Machine_Attribute --
10295 -----------------------
10297 -- pragma Machine_Attribute (
10298 -- [Entity =>] LOCAL_NAME,
10299 -- [Attribute_Name =>] static_string_EXPRESSION
10300 -- [, [Info =>] static_EXPRESSION] );
10302 when Pragma_Machine_Attribute => Machine_Attribute : declare
10303 Def_Id : Entity_Id;
10307 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10309 if Arg_Count = 3 then
10310 Check_Optional_Identifier (Arg3, Name_Info);
10311 Check_Arg_Is_Static_Expression (Arg3);
10313 Check_Arg_Count (2);
10316 Check_Optional_Identifier (Arg1, Name_Entity);
10317 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10318 Check_Arg_Is_Local_Name (Arg1);
10319 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10320 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10322 if Is_Access_Type (Def_Id) then
10323 Def_Id := Designated_Type (Def_Id);
10326 if Rep_Item_Too_Early (Def_Id, N) then
10330 Def_Id := Underlying_Type (Def_Id);
10332 -- The only processing required is to link this item on to the
10333 -- list of rep items for the given entity. This is accomplished
10334 -- by the call to Rep_Item_Too_Late (when no error is detected
10335 -- and False is returned).
10337 if Rep_Item_Too_Late (Def_Id, N) then
10340 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10342 end Machine_Attribute;
10349 -- (MAIN_OPTION [, MAIN_OPTION]);
10352 -- [STACK_SIZE =>] static_integer_EXPRESSION
10353 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10354 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10356 when Pragma_Main => Main : declare
10357 Args : Args_List (1 .. 3);
10358 Names : constant Name_List (1 .. 3) := (
10360 Name_Task_Stack_Size_Default,
10361 Name_Time_Slicing_Enabled);
10367 Gather_Associations (Names, Args);
10369 for J in 1 .. 2 loop
10370 if Present (Args (J)) then
10371 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10375 if Present (Args (3)) then
10376 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10380 while Present (Nod) loop
10381 if Nkind (Nod) = N_Pragma
10382 and then Pragma_Name (Nod) = Name_Main
10384 Error_Msg_Name_1 := Pname;
10385 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10396 -- pragma Main_Storage
10397 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10399 -- MAIN_STORAGE_OPTION ::=
10400 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10401 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10403 when Pragma_Main_Storage => Main_Storage : declare
10404 Args : Args_List (1 .. 2);
10405 Names : constant Name_List (1 .. 2) := (
10406 Name_Working_Storage,
10413 Gather_Associations (Names, Args);
10415 for J in 1 .. 2 loop
10416 if Present (Args (J)) then
10417 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10421 Check_In_Main_Program;
10424 while Present (Nod) loop
10425 if Nkind (Nod) = N_Pragma
10426 and then Pragma_Name (Nod) = Name_Main_Storage
10428 Error_Msg_Name_1 := Pname;
10429 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10440 -- pragma Memory_Size (NUMERIC_LITERAL)
10442 when Pragma_Memory_Size =>
10445 -- Memory size is simply ignored
10447 Check_No_Identifiers;
10448 Check_Arg_Count (1);
10449 Check_Arg_Is_Integer_Literal (Arg1);
10457 -- The only correct use of this pragma is on its own in a file, in
10458 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10459 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10460 -- check for a file containing nothing but a No_Body pragma). If we
10461 -- attempt to process it during normal semantics processing, it means
10462 -- it was misplaced.
10464 when Pragma_No_Body =>
10472 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10474 when Pragma_No_Return => No_Return : declare
10482 Check_At_Least_N_Arguments (1);
10484 -- Loop through arguments of pragma
10487 while Present (Arg) loop
10488 Check_Arg_Is_Local_Name (Arg);
10489 Id := Get_Pragma_Arg (Arg);
10492 if not Is_Entity_Name (Id) then
10493 Error_Pragma_Arg ("entity name required", Arg);
10496 if Etype (Id) = Any_Type then
10500 -- Loop to find matching procedures
10505 and then Scope (E) = Current_Scope
10507 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10510 -- Set flag on any alias as well
10512 if Is_Overloadable (E) and then Present (Alias (E)) then
10513 Set_No_Return (Alias (E));
10519 exit when From_Aspect_Specification (N);
10524 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10535 -- pragma No_Run_Time;
10537 -- Note: this pragma is retained for backwards compatibility. See
10538 -- body of Rtsfind for full details on its handling.
10540 when Pragma_No_Run_Time =>
10542 Check_Valid_Configuration_Pragma;
10543 Check_Arg_Count (0);
10545 No_Run_Time_Mode := True;
10546 Configurable_Run_Time_Mode := True;
10548 -- Set Duration to 32 bits if word size is 32
10550 if Ttypes.System_Word_Size = 32 then
10551 Duration_32_Bits_On_Target := True;
10554 -- Set appropriate restrictions
10556 Set_Restriction (No_Finalization, N);
10557 Set_Restriction (No_Exception_Handlers, N);
10558 Set_Restriction (Max_Tasks, N, 0);
10559 Set_Restriction (No_Tasking, N);
10561 ------------------------
10562 -- No_Strict_Aliasing --
10563 ------------------------
10565 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10567 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10572 Check_At_Most_N_Arguments (1);
10574 if Arg_Count = 0 then
10575 Check_Valid_Configuration_Pragma;
10576 Opt.No_Strict_Aliasing := True;
10579 Check_Optional_Identifier (Arg2, Name_Entity);
10580 Check_Arg_Is_Local_Name (Arg1);
10581 E_Id := Entity (Get_Pragma_Arg (Arg1));
10583 if E_Id = Any_Type then
10585 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10586 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10589 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10591 end No_Strict_Aliasing;
10593 -----------------------
10594 -- Normalize_Scalars --
10595 -----------------------
10597 -- pragma Normalize_Scalars;
10599 when Pragma_Normalize_Scalars =>
10600 Check_Ada_83_Warning;
10601 Check_Arg_Count (0);
10602 Check_Valid_Configuration_Pragma;
10604 -- Normalize_Scalars creates false positives in CodePeer, so
10605 -- ignore this pragma in this mode.
10607 if not CodePeer_Mode then
10608 Normalize_Scalars := True;
10609 Init_Or_Norm_Scalars := True;
10616 -- pragma Obsolescent;
10618 -- pragma Obsolescent (
10619 -- [Message =>] static_string_EXPRESSION
10620 -- [,[Version =>] Ada_05]]);
10622 -- pragma Obsolescent (
10623 -- [Entity =>] NAME
10624 -- [,[Message =>] static_string_EXPRESSION
10625 -- [,[Version =>] Ada_05]] );
10627 when Pragma_Obsolescent => Obsolescent : declare
10631 procedure Set_Obsolescent (E : Entity_Id);
10632 -- Given an entity Ent, mark it as obsolescent if appropriate
10634 ---------------------
10635 -- Set_Obsolescent --
10636 ---------------------
10638 procedure Set_Obsolescent (E : Entity_Id) is
10647 -- Entity name was given
10649 if Present (Ename) then
10651 -- If entity name matches, we are fine. Save entity in
10652 -- pragma argument, for ASIS use.
10654 if Chars (Ename) = Chars (Ent) then
10655 Set_Entity (Ename, Ent);
10656 Generate_Reference (Ent, Ename);
10658 -- If entity name does not match, only possibility is an
10659 -- enumeration literal from an enumeration type declaration.
10661 elsif Ekind (Ent) /= E_Enumeration_Type then
10663 ("pragma % entity name does not match declaration");
10666 Ent := First_Literal (E);
10670 ("pragma % entity name does not match any " &
10671 "enumeration literal");
10673 elsif Chars (Ent) = Chars (Ename) then
10674 Set_Entity (Ename, Ent);
10675 Generate_Reference (Ent, Ename);
10679 Ent := Next_Literal (Ent);
10685 -- Ent points to entity to be marked
10687 if Arg_Count >= 1 then
10689 -- Deal with static string argument
10691 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10692 S := Strval (Get_Pragma_Arg (Arg1));
10694 for J in 1 .. String_Length (S) loop
10695 if not In_Character_Range (Get_String_Char (S, J)) then
10697 ("pragma% argument does not allow wide characters",
10702 Obsolescent_Warnings.Append
10703 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10705 -- Check for Ada_05 parameter
10707 if Arg_Count /= 1 then
10708 Check_Arg_Count (2);
10711 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10714 Check_Arg_Is_Identifier (Argx);
10716 if Chars (Argx) /= Name_Ada_05 then
10717 Error_Msg_Name_2 := Name_Ada_05;
10719 ("only allowed argument for pragma% is %", Argx);
10722 if Ada_Version_Explicit < Ada_2005
10723 or else not Warn_On_Ada_2005_Compatibility
10731 -- Set flag if pragma active
10734 Set_Is_Obsolescent (Ent);
10738 end Set_Obsolescent;
10740 -- Start of processing for pragma Obsolescent
10745 Check_At_Most_N_Arguments (3);
10747 -- See if first argument specifies an entity name
10751 (Chars (Arg1) = Name_Entity
10753 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10755 N_Operator_Symbol))
10757 Ename := Get_Pragma_Arg (Arg1);
10759 -- Eliminate first argument, so we can share processing
10763 Arg_Count := Arg_Count - 1;
10765 -- No Entity name argument given
10771 if Arg_Count >= 1 then
10772 Check_Optional_Identifier (Arg1, Name_Message);
10774 if Arg_Count = 2 then
10775 Check_Optional_Identifier (Arg2, Name_Version);
10779 -- Get immediately preceding declaration
10782 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10786 -- Cases where we do not follow anything other than another pragma
10790 -- First case: library level compilation unit declaration with
10791 -- the pragma immediately following the declaration.
10793 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10795 (Defining_Entity (Unit (Parent (Parent (N)))));
10798 -- Case 2: library unit placement for package
10802 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10804 if Is_Package_Or_Generic_Package (Ent) then
10805 Set_Obsolescent (Ent);
10811 -- Cases where we must follow a declaration
10814 if Nkind (Decl) not in N_Declaration
10815 and then Nkind (Decl) not in N_Later_Decl_Item
10816 and then Nkind (Decl) not in N_Generic_Declaration
10817 and then Nkind (Decl) not in N_Renaming_Declaration
10820 ("pragma% misplaced, "
10821 & "must immediately follow a declaration");
10824 Set_Obsolescent (Defining_Entity (Decl));
10834 -- pragma Optimize (Time | Space | Off);
10836 -- The actual check for optimize is done in Gigi. Note that this
10837 -- pragma does not actually change the optimization setting, it
10838 -- simply checks that it is consistent with the pragma.
10840 when Pragma_Optimize =>
10841 Check_No_Identifiers;
10842 Check_Arg_Count (1);
10843 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10845 ------------------------
10846 -- Optimize_Alignment --
10847 ------------------------
10849 -- pragma Optimize_Alignment (Time | Space | Off);
10851 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10853 Check_No_Identifiers;
10854 Check_Arg_Count (1);
10855 Check_Valid_Configuration_Pragma;
10858 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10862 Opt.Optimize_Alignment := 'T';
10864 Opt.Optimize_Alignment := 'S';
10866 Opt.Optimize_Alignment := 'O';
10868 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10872 -- Set indication that mode is set locally. If we are in fact in a
10873 -- configuration pragma file, this setting is harmless since the
10874 -- switch will get reset anyway at the start of each unit.
10876 Optimize_Alignment_Local := True;
10877 end Optimize_Alignment;
10883 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10885 when Pragma_Ordered => Ordered : declare
10886 Assoc : constant Node_Id := Arg1;
10892 Check_No_Identifiers;
10893 Check_Arg_Count (1);
10894 Check_Arg_Is_Local_Name (Arg1);
10896 Type_Id := Get_Pragma_Arg (Assoc);
10897 Find_Type (Type_Id);
10898 Typ := Entity (Type_Id);
10900 if Typ = Any_Type then
10903 Typ := Underlying_Type (Typ);
10906 if not Is_Enumeration_Type (Typ) then
10907 Error_Pragma ("pragma% must specify enumeration type");
10910 Check_First_Subtype (Arg1);
10911 Set_Has_Pragma_Ordered (Base_Type (Typ));
10918 -- pragma Pack (first_subtype_LOCAL_NAME);
10920 when Pragma_Pack => Pack : declare
10921 Assoc : constant Node_Id := Arg1;
10925 Ignore : Boolean := False;
10928 Check_No_Identifiers;
10929 Check_Arg_Count (1);
10930 Check_Arg_Is_Local_Name (Arg1);
10932 Type_Id := Get_Pragma_Arg (Assoc);
10933 Find_Type (Type_Id);
10934 Typ := Entity (Type_Id);
10937 or else Rep_Item_Too_Early (Typ, N)
10941 Typ := Underlying_Type (Typ);
10944 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
10945 Error_Pragma ("pragma% must specify array or record type");
10948 Check_First_Subtype (Arg1);
10949 Check_Duplicate_Pragma (Typ);
10953 if Is_Array_Type (Typ) then
10954 Ctyp := Component_Type (Typ);
10956 -- Ignore pack that does nothing
10958 if Known_Static_Esize (Ctyp)
10959 and then Known_Static_RM_Size (Ctyp)
10960 and then Esize (Ctyp) = RM_Size (Ctyp)
10961 and then Addressable (Esize (Ctyp))
10966 -- Process OK pragma Pack. Note that if there is a separate
10967 -- component clause present, the Pack will be cancelled. This
10968 -- processing is in Freeze.
10970 if not Rep_Item_Too_Late (Typ, N) then
10972 -- In the context of static code analysis, we do not need
10973 -- complex front-end expansions related to pragma Pack,
10974 -- so disable handling of pragma Pack in this case.
10976 if CodePeer_Mode then
10979 -- Don't attempt any packing for VM targets. We possibly
10980 -- could deal with some cases of array bit-packing, but we
10981 -- don't bother, since this is not a typical kind of
10982 -- representation in the VM context anyway (and would not
10983 -- for example work nicely with the debugger).
10985 elsif VM_Target /= No_VM then
10986 if not GNAT_Mode then
10988 ("?pragma% ignored in this configuration");
10991 -- Normal case where we do the pack action
10995 Set_Is_Packed (Base_Type (Typ));
10996 Set_Has_Non_Standard_Rep (Base_Type (Typ));
10999 Set_Has_Pragma_Pack (Base_Type (Typ));
11003 -- For record types, the pack is always effective
11005 else pragma Assert (Is_Record_Type (Typ));
11006 if not Rep_Item_Too_Late (Typ, N) then
11008 -- Ignore pack request with warning in VM mode (skip warning
11009 -- if we are compiling GNAT run time library).
11011 if VM_Target /= No_VM then
11012 if not GNAT_Mode then
11014 ("?pragma% ignored in this configuration");
11017 -- Normal case of pack request active
11020 Set_Is_Packed (Base_Type (Typ));
11021 Set_Has_Pragma_Pack (Base_Type (Typ));
11022 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11034 -- There is nothing to do here, since we did all the processing for
11035 -- this pragma in Par.Prag (so that it works properly even in syntax
11038 when Pragma_Page =>
11045 -- pragma Passive [(PASSIVE_FORM)];
11047 -- PASSIVE_FORM ::= Semaphore | No
11049 when Pragma_Passive =>
11052 if Nkind (Parent (N)) /= N_Task_Definition then
11053 Error_Pragma ("pragma% must be within task definition");
11056 if Arg_Count /= 0 then
11057 Check_Arg_Count (1);
11058 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11061 ----------------------------------
11062 -- Preelaborable_Initialization --
11063 ----------------------------------
11065 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11067 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11072 Check_Arg_Count (1);
11073 Check_No_Identifiers;
11074 Check_Arg_Is_Identifier (Arg1);
11075 Check_Arg_Is_Local_Name (Arg1);
11076 Check_First_Subtype (Arg1);
11077 Ent := Entity (Get_Pragma_Arg (Arg1));
11079 if not (Is_Private_Type (Ent)
11081 Is_Protected_Type (Ent)
11083 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11086 ("pragma % can only be applied to private, formal derived or "
11087 & "protected type",
11091 -- Give an error if the pragma is applied to a protected type that
11092 -- does not qualify (due to having entries, or due to components
11093 -- that do not qualify).
11095 if Is_Protected_Type (Ent)
11096 and then not Has_Preelaborable_Initialization (Ent)
11099 ("protected type & does not have preelaborable " &
11100 "initialization", Ent);
11102 -- Otherwise mark the type as definitely having preelaborable
11106 Set_Known_To_Have_Preelab_Init (Ent);
11109 if Has_Pragma_Preelab_Init (Ent)
11110 and then Warn_On_Redundant_Constructs
11112 Error_Pragma ("?duplicate pragma%!");
11114 Set_Has_Pragma_Preelab_Init (Ent);
11118 --------------------
11119 -- Persistent_BSS --
11120 --------------------
11122 -- pragma Persistent_BSS [(object_NAME)];
11124 when Pragma_Persistent_BSS => Persistent_BSS : declare
11131 Check_At_Most_N_Arguments (1);
11133 -- Case of application to specific object (one argument)
11135 if Arg_Count = 1 then
11136 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11138 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11140 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11143 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11146 Ent := Entity (Get_Pragma_Arg (Arg1));
11147 Decl := Parent (Ent);
11149 if Rep_Item_Too_Late (Ent, N) then
11153 if Present (Expression (Decl)) then
11155 ("object for pragma% cannot have initialization", Arg1);
11158 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11160 ("object type for pragma% is not potentially persistent",
11164 Check_Duplicate_Pragma (Ent);
11167 Make_Linker_Section_Pragma
11168 (Ent, Sloc (N), ".persistent.bss");
11169 Insert_After (N, Prag);
11172 -- Case of use as configuration pragma with no arguments
11175 Check_Valid_Configuration_Pragma;
11176 Persistent_BSS_Mode := True;
11178 end Persistent_BSS;
11184 -- pragma Polling (ON | OFF);
11186 when Pragma_Polling =>
11188 Check_Arg_Count (1);
11189 Check_No_Identifiers;
11190 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11191 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11193 -------------------
11194 -- Postcondition --
11195 -------------------
11197 -- pragma Postcondition ([Check =>] Boolean_Expression
11198 -- [,[Message =>] String_Expression]);
11200 when Pragma_Postcondition => Postcondition : declare
11202 pragma Warnings (Off, In_Body);
11206 Check_At_Least_N_Arguments (1);
11207 Check_At_Most_N_Arguments (2);
11208 Check_Optional_Identifier (Arg1, Name_Check);
11210 -- All we need to do here is call the common check procedure,
11211 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11213 Check_Precondition_Postcondition (In_Body);
11220 -- pragma Precondition ([Check =>] Boolean_Expression
11221 -- [,[Message =>] String_Expression]);
11223 when Pragma_Precondition => Precondition : declare
11228 Check_At_Least_N_Arguments (1);
11229 Check_At_Most_N_Arguments (2);
11230 Check_Optional_Identifier (Arg1, Name_Check);
11231 Check_Precondition_Postcondition (In_Body);
11233 -- If in spec, nothing more to do. If in body, then we convert the
11234 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11235 -- this whether or not precondition checks are enabled. That works
11236 -- fine since pragma Check will do this check, and will also
11237 -- analyze the condition itself in the proper context.
11242 Chars => Name_Check,
11243 Pragma_Argument_Associations => New_List (
11244 Make_Pragma_Argument_Association (Loc,
11245 Expression => Make_Identifier (Loc, Name_Precondition)),
11247 Make_Pragma_Argument_Association (Sloc (Arg1),
11248 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11250 if Arg_Count = 2 then
11251 Append_To (Pragma_Argument_Associations (N),
11252 Make_Pragma_Argument_Association (Sloc (Arg2),
11253 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11264 -- pragma Predicate
11265 -- ([Entity =>] type_LOCAL_NAME,
11266 -- [Check =>] EXPRESSION);
11268 when Pragma_Predicate => Predicate : declare
11273 pragma Unreferenced (Discard);
11277 Check_Arg_Count (2);
11278 Check_Optional_Identifier (Arg1, Name_Entity);
11279 Check_Optional_Identifier (Arg2, Name_Check);
11281 Check_Arg_Is_Local_Name (Arg1);
11283 Type_Id := Get_Pragma_Arg (Arg1);
11284 Find_Type (Type_Id);
11285 Typ := Entity (Type_Id);
11287 if Typ = Any_Type then
11291 -- The remaining processing is simply to link the pragma on to
11292 -- the rep item chain, for processing when the type is frozen.
11293 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11294 -- mark the type as having predicates.
11296 Set_Has_Predicates (Typ);
11297 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11304 -- pragma Preelaborate [(library_unit_NAME)];
11306 -- Set the flag Is_Preelaborated of program unit name entity
11308 when Pragma_Preelaborate => Preelaborate : declare
11309 Pa : constant Node_Id := Parent (N);
11310 Pk : constant Node_Kind := Nkind (Pa);
11314 Check_Ada_83_Warning;
11315 Check_Valid_Library_Unit_Pragma;
11317 if Nkind (N) = N_Null_Statement then
11321 Ent := Find_Lib_Unit_Name;
11322 Check_Duplicate_Pragma (Ent);
11324 -- This filters out pragmas inside generic parent then
11325 -- show up inside instantiation
11328 and then not (Pk = N_Package_Specification
11329 and then Present (Generic_Parent (Pa)))
11331 if not Debug_Flag_U then
11332 Set_Is_Preelaborated (Ent);
11333 Set_Suppress_Elaboration_Warnings (Ent);
11338 ---------------------
11339 -- Preelaborate_05 --
11340 ---------------------
11342 -- pragma Preelaborate_05 [(library_unit_NAME)];
11344 -- This pragma is useable only in GNAT_Mode, where it is used like
11345 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11346 -- (otherwise it is ignored). This is used to implement AI-362 which
11347 -- recategorizes some run-time packages in Ada 2005 mode.
11349 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11354 Check_Valid_Library_Unit_Pragma;
11356 if not GNAT_Mode then
11357 Error_Pragma ("pragma% only available in GNAT mode");
11360 if Nkind (N) = N_Null_Statement then
11364 -- This is one of the few cases where we need to test the value of
11365 -- Ada_Version_Explicit rather than Ada_Version (which is always
11366 -- set to Ada_2012 in a predefined unit), we need to know the
11367 -- explicit version set to know if this pragma is active.
11369 if Ada_Version_Explicit >= Ada_2005 then
11370 Ent := Find_Lib_Unit_Name;
11371 Set_Is_Preelaborated (Ent);
11372 Set_Suppress_Elaboration_Warnings (Ent);
11374 end Preelaborate_05;
11380 -- pragma Priority (EXPRESSION);
11382 when Pragma_Priority => Priority : declare
11383 P : constant Node_Id := Parent (N);
11387 Check_No_Identifiers;
11388 Check_Arg_Count (1);
11392 if Nkind (P) = N_Subprogram_Body then
11393 Check_In_Main_Program;
11395 Arg := Get_Pragma_Arg (Arg1);
11396 Analyze_And_Resolve (Arg, Standard_Integer);
11400 if not Is_Static_Expression (Arg) then
11401 Flag_Non_Static_Expr
11402 ("main subprogram priority is not static!", Arg);
11405 -- If constraint error, then we already signalled an error
11407 elsif Raises_Constraint_Error (Arg) then
11410 -- Otherwise check in range
11414 Val : constant Uint := Expr_Value (Arg);
11418 or else Val > Expr_Value (Expression
11419 (Parent (RTE (RE_Max_Priority))))
11422 ("main subprogram priority is out of range", Arg1);
11428 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11430 -- Load an arbitrary entity from System.Tasking to make sure
11431 -- this package is implicitly with'ed, since we need to have
11432 -- the tasking run-time active for the pragma Priority to have
11436 Discard : Entity_Id;
11437 pragma Warnings (Off, Discard);
11439 Discard := RTE (RE_Task_List);
11442 -- Task or Protected, must be of type Integer
11444 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11445 Arg := Get_Pragma_Arg (Arg1);
11447 -- The expression must be analyzed in the special manner
11448 -- described in "Handling of Default and Per-Object
11449 -- Expressions" in sem.ads.
11451 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11453 if not Is_Static_Expression (Arg) then
11454 Check_Restriction (Static_Priorities, Arg);
11457 -- Anything else is incorrect
11463 if Has_Pragma_Priority (P) then
11464 Error_Pragma ("duplicate pragma% not allowed");
11466 Set_Has_Pragma_Priority (P, True);
11468 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11469 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11470 -- exp_ch9 should use this ???
11475 -----------------------------------
11476 -- Priority_Specific_Dispatching --
11477 -----------------------------------
11479 -- pragma Priority_Specific_Dispatching (
11480 -- policy_IDENTIFIER,
11481 -- first_priority_EXPRESSION,
11482 -- last_priority_EXPRESSION);
11484 when Pragma_Priority_Specific_Dispatching =>
11485 Priority_Specific_Dispatching : declare
11486 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11487 -- This is the entity System.Any_Priority;
11490 Lower_Bound : Node_Id;
11491 Upper_Bound : Node_Id;
11497 Check_Arg_Count (3);
11498 Check_No_Identifiers;
11499 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11500 Check_Valid_Configuration_Pragma;
11501 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11502 DP := Fold_Upper (Name_Buffer (1));
11504 Lower_Bound := Get_Pragma_Arg (Arg2);
11505 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11506 Lower_Val := Expr_Value (Lower_Bound);
11508 Upper_Bound := Get_Pragma_Arg (Arg3);
11509 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11510 Upper_Val := Expr_Value (Upper_Bound);
11512 -- It is not allowed to use Task_Dispatching_Policy and
11513 -- Priority_Specific_Dispatching in the same partition.
11515 if Task_Dispatching_Policy /= ' ' then
11516 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11518 ("pragma% incompatible with Task_Dispatching_Policy#");
11520 -- Check lower bound in range
11522 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11524 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11527 ("first_priority is out of range", Arg2);
11529 -- Check upper bound in range
11531 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11533 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11536 ("last_priority is out of range", Arg3);
11538 -- Check that the priority range is valid
11540 elsif Lower_Val > Upper_Val then
11542 ("last_priority_expression must be greater than" &
11543 " or equal to first_priority_expression");
11545 -- Store the new policy, but always preserve System_Location since
11546 -- we like the error message with the run-time name.
11549 -- Check overlapping in the priority ranges specified in other
11550 -- Priority_Specific_Dispatching pragmas within the same
11551 -- partition. We can only check those we know about!
11554 Specific_Dispatching.First .. Specific_Dispatching.Last
11556 if Specific_Dispatching.Table (J).First_Priority in
11557 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11558 or else Specific_Dispatching.Table (J).Last_Priority in
11559 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11562 Specific_Dispatching.Table (J).Pragma_Loc;
11564 ("priority range overlaps with "
11565 & "Priority_Specific_Dispatching#");
11569 -- The use of Priority_Specific_Dispatching is incompatible
11570 -- with Task_Dispatching_Policy.
11572 if Task_Dispatching_Policy /= ' ' then
11573 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11575 ("Priority_Specific_Dispatching incompatible "
11576 & "with Task_Dispatching_Policy#");
11579 -- The use of Priority_Specific_Dispatching forces ceiling
11582 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11583 Error_Msg_Sloc := Locking_Policy_Sloc;
11585 ("Priority_Specific_Dispatching incompatible "
11586 & "with Locking_Policy#");
11588 -- Set the Ceiling_Locking policy, but preserve System_Location
11589 -- since we like the error message with the run time name.
11592 Locking_Policy := 'C';
11594 if Locking_Policy_Sloc /= System_Location then
11595 Locking_Policy_Sloc := Loc;
11599 -- Add entry in the table
11601 Specific_Dispatching.Append
11602 ((Dispatching_Policy => DP,
11603 First_Priority => UI_To_Int (Lower_Val),
11604 Last_Priority => UI_To_Int (Upper_Val),
11605 Pragma_Loc => Loc));
11607 end Priority_Specific_Dispatching;
11613 -- pragma Profile (profile_IDENTIFIER);
11615 -- profile_IDENTIFIER => Restricted | Ravenscar
11617 when Pragma_Profile =>
11619 Check_Arg_Count (1);
11620 Check_Valid_Configuration_Pragma;
11621 Check_No_Identifiers;
11624 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11626 if Chars (Argx) = Name_Ravenscar then
11627 Set_Ravenscar_Profile (N);
11628 elsif Chars (Argx) = Name_Restricted then
11629 Set_Profile_Restrictions
11630 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11632 Error_Pragma_Arg ("& is not a valid profile", Argx);
11636 ----------------------
11637 -- Profile_Warnings --
11638 ----------------------
11640 -- pragma Profile_Warnings (profile_IDENTIFIER);
11642 -- profile_IDENTIFIER => Restricted | Ravenscar
11644 when Pragma_Profile_Warnings =>
11646 Check_Arg_Count (1);
11647 Check_Valid_Configuration_Pragma;
11648 Check_No_Identifiers;
11651 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11653 if Chars (Argx) = Name_Ravenscar then
11654 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11655 elsif Chars (Argx) = Name_Restricted then
11656 Set_Profile_Restrictions (Restricted, N, Warn => True);
11658 Error_Pragma_Arg ("& is not a valid profile", Argx);
11662 --------------------------
11663 -- Propagate_Exceptions --
11664 --------------------------
11666 -- pragma Propagate_Exceptions;
11668 -- Note: this pragma is obsolete and has no effect
11670 when Pragma_Propagate_Exceptions =>
11672 Check_Arg_Count (0);
11674 if In_Extended_Main_Source_Unit (N) then
11675 Propagate_Exceptions := True;
11682 -- pragma Psect_Object (
11683 -- [Internal =>] LOCAL_NAME,
11684 -- [, [External =>] EXTERNAL_SYMBOL]
11685 -- [, [Size =>] EXTERNAL_SYMBOL]);
11687 when Pragma_Psect_Object | Pragma_Common_Object =>
11688 Psect_Object : declare
11689 Args : Args_List (1 .. 3);
11690 Names : constant Name_List (1 .. 3) := (
11695 Internal : Node_Id renames Args (1);
11696 External : Node_Id renames Args (2);
11697 Size : Node_Id renames Args (3);
11699 Def_Id : Entity_Id;
11701 procedure Check_Too_Long (Arg : Node_Id);
11702 -- Posts message if the argument is an identifier with more
11703 -- than 31 characters, or a string literal with more than
11704 -- 31 characters, and we are operating under VMS
11706 --------------------
11707 -- Check_Too_Long --
11708 --------------------
11710 procedure Check_Too_Long (Arg : Node_Id) is
11711 X : constant Node_Id := Original_Node (Arg);
11714 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11716 ("inappropriate argument for pragma %", Arg);
11719 if OpenVMS_On_Target then
11720 if (Nkind (X) = N_String_Literal
11721 and then String_Length (Strval (X)) > 31)
11723 (Nkind (X) = N_Identifier
11724 and then Length_Of_Name (Chars (X)) > 31)
11727 ("argument for pragma % is longer than 31 characters",
11731 end Check_Too_Long;
11733 -- Start of processing for Common_Object/Psect_Object
11737 Gather_Associations (Names, Args);
11738 Process_Extended_Import_Export_Internal_Arg (Internal);
11740 Def_Id := Entity (Internal);
11742 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11744 ("pragma% must designate an object", Internal);
11747 Check_Too_Long (Internal);
11749 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11751 ("cannot use pragma% for imported/exported object",
11755 if Is_Concurrent_Type (Etype (Internal)) then
11757 ("cannot specify pragma % for task/protected object",
11761 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11763 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11765 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11768 if Ekind (Def_Id) = E_Constant then
11770 ("cannot specify pragma % for a constant", Internal);
11773 if Is_Record_Type (Etype (Internal)) then
11779 Ent := First_Entity (Etype (Internal));
11780 while Present (Ent) loop
11781 Decl := Declaration_Node (Ent);
11783 if Ekind (Ent) = E_Component
11784 and then Nkind (Decl) = N_Component_Declaration
11785 and then Present (Expression (Decl))
11786 and then Warn_On_Export_Import
11789 ("?object for pragma % has defaults", Internal);
11799 if Present (Size) then
11800 Check_Too_Long (Size);
11803 if Present (External) then
11804 Check_Arg_Is_External_Name (External);
11805 Check_Too_Long (External);
11808 -- If all error tests pass, link pragma on to the rep item chain
11810 Record_Rep_Item (Def_Id, N);
11817 -- pragma Pure [(library_unit_NAME)];
11819 when Pragma_Pure => Pure : declare
11823 Check_Ada_83_Warning;
11824 Check_Valid_Library_Unit_Pragma;
11826 if Nkind (N) = N_Null_Statement then
11830 Ent := Find_Lib_Unit_Name;
11832 Set_Has_Pragma_Pure (Ent);
11833 Set_Suppress_Elaboration_Warnings (Ent);
11840 -- pragma Pure_05 [(library_unit_NAME)];
11842 -- This pragma is useable only in GNAT_Mode, where it is used like
11843 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11844 -- it is ignored). It may be used after a pragma Preelaborate, in
11845 -- which case it overrides the effect of the pragma Preelaborate.
11846 -- This is used to implement AI-362 which recategorizes some run-time
11847 -- packages in Ada 2005 mode.
11849 when Pragma_Pure_05 => Pure_05 : declare
11854 Check_Valid_Library_Unit_Pragma;
11856 if not GNAT_Mode then
11857 Error_Pragma ("pragma% only available in GNAT mode");
11860 if Nkind (N) = N_Null_Statement then
11864 -- This is one of the few cases where we need to test the value of
11865 -- Ada_Version_Explicit rather than Ada_Version (which is always
11866 -- set to Ada_2012 in a predefined unit), we need to know the
11867 -- explicit version set to know if this pragma is active.
11869 if Ada_Version_Explicit >= Ada_2005 then
11870 Ent := Find_Lib_Unit_Name;
11871 Set_Is_Preelaborated (Ent, False);
11873 Set_Suppress_Elaboration_Warnings (Ent);
11877 -------------------
11878 -- Pure_Function --
11879 -------------------
11881 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11883 when Pragma_Pure_Function => Pure_Function : declare
11886 Def_Id : Entity_Id;
11887 Effective : Boolean := False;
11891 Check_Arg_Count (1);
11892 Check_Optional_Identifier (Arg1, Name_Entity);
11893 Check_Arg_Is_Local_Name (Arg1);
11894 E_Id := Get_Pragma_Arg (Arg1);
11896 if Error_Posted (E_Id) then
11900 -- Loop through homonyms (overloadings) of referenced entity
11902 E := Entity (E_Id);
11904 if Present (E) then
11906 Def_Id := Get_Base_Subprogram (E);
11908 if not Ekind_In (Def_Id, E_Function,
11909 E_Generic_Function,
11913 ("pragma% requires a function name", Arg1);
11916 Set_Is_Pure (Def_Id);
11918 if not Has_Pragma_Pure_Function (Def_Id) then
11919 Set_Has_Pragma_Pure_Function (Def_Id);
11923 exit when From_Aspect_Specification (N);
11925 exit when No (E) or else Scope (E) /= Current_Scope;
11929 and then Warn_On_Redundant_Constructs
11932 ("pragma Pure_Function on& is redundant?",
11938 --------------------
11939 -- Queuing_Policy --
11940 --------------------
11942 -- pragma Queuing_Policy (policy_IDENTIFIER);
11944 when Pragma_Queuing_Policy => declare
11948 Check_Ada_83_Warning;
11949 Check_Arg_Count (1);
11950 Check_No_Identifiers;
11951 Check_Arg_Is_Queuing_Policy (Arg1);
11952 Check_Valid_Configuration_Pragma;
11953 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11954 QP := Fold_Upper (Name_Buffer (1));
11956 if Queuing_Policy /= ' '
11957 and then Queuing_Policy /= QP
11959 Error_Msg_Sloc := Queuing_Policy_Sloc;
11960 Error_Pragma ("queuing policy incompatible with policy#");
11962 -- Set new policy, but always preserve System_Location since we
11963 -- like the error message with the run time name.
11966 Queuing_Policy := QP;
11968 if Queuing_Policy_Sloc /= System_Location then
11969 Queuing_Policy_Sloc := Loc;
11974 -----------------------
11975 -- Relative_Deadline --
11976 -----------------------
11978 -- pragma Relative_Deadline (time_span_EXPRESSION);
11980 when Pragma_Relative_Deadline => Relative_Deadline : declare
11981 P : constant Node_Id := Parent (N);
11986 Check_No_Identifiers;
11987 Check_Arg_Count (1);
11989 Arg := Get_Pragma_Arg (Arg1);
11991 -- The expression must be analyzed in the special manner described
11992 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
11994 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
11998 if Nkind (P) = N_Subprogram_Body then
11999 Check_In_Main_Program;
12003 elsif Nkind (P) = N_Task_Definition then
12006 -- Anything else is incorrect
12012 if Has_Relative_Deadline_Pragma (P) then
12013 Error_Pragma ("duplicate pragma% not allowed");
12015 Set_Has_Relative_Deadline_Pragma (P, True);
12017 if Nkind (P) = N_Task_Definition then
12018 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12021 end Relative_Deadline;
12023 ---------------------------
12024 -- Remote_Call_Interface --
12025 ---------------------------
12027 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12029 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12030 Cunit_Node : Node_Id;
12031 Cunit_Ent : Entity_Id;
12035 Check_Ada_83_Warning;
12036 Check_Valid_Library_Unit_Pragma;
12038 if Nkind (N) = N_Null_Statement then
12042 Cunit_Node := Cunit (Current_Sem_Unit);
12043 K := Nkind (Unit (Cunit_Node));
12044 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12046 if K = N_Package_Declaration
12047 or else K = N_Generic_Package_Declaration
12048 or else K = N_Subprogram_Declaration
12049 or else K = N_Generic_Subprogram_Declaration
12050 or else (K = N_Subprogram_Body
12051 and then Acts_As_Spec (Unit (Cunit_Node)))
12056 "pragma% must apply to package or subprogram declaration");
12059 Set_Is_Remote_Call_Interface (Cunit_Ent);
12060 end Remote_Call_Interface;
12066 -- pragma Remote_Types [(library_unit_NAME)];
12068 when Pragma_Remote_Types => Remote_Types : declare
12069 Cunit_Node : Node_Id;
12070 Cunit_Ent : Entity_Id;
12073 Check_Ada_83_Warning;
12074 Check_Valid_Library_Unit_Pragma;
12076 if Nkind (N) = N_Null_Statement then
12080 Cunit_Node := Cunit (Current_Sem_Unit);
12081 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12083 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12084 N_Generic_Package_Declaration)
12087 ("pragma% can only apply to a package declaration");
12090 Set_Is_Remote_Types (Cunit_Ent);
12097 -- pragma Ravenscar;
12099 when Pragma_Ravenscar =>
12101 Check_Arg_Count (0);
12102 Check_Valid_Configuration_Pragma;
12103 Set_Ravenscar_Profile (N);
12105 if Warn_On_Obsolescent_Feature then
12106 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12107 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12110 -------------------------
12111 -- Restricted_Run_Time --
12112 -------------------------
12114 -- pragma Restricted_Run_Time;
12116 when Pragma_Restricted_Run_Time =>
12118 Check_Arg_Count (0);
12119 Check_Valid_Configuration_Pragma;
12120 Set_Profile_Restrictions
12121 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12123 if Warn_On_Obsolescent_Feature then
12125 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12126 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12133 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12136 -- restriction_IDENTIFIER
12137 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12139 when Pragma_Restrictions =>
12140 Process_Restrictions_Or_Restriction_Warnings
12141 (Warn => Treat_Restrictions_As_Warnings);
12143 --------------------------
12144 -- Restriction_Warnings --
12145 --------------------------
12147 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12150 -- restriction_IDENTIFIER
12151 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12153 when Pragma_Restriction_Warnings =>
12155 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12161 -- pragma Reviewable;
12163 when Pragma_Reviewable =>
12164 Check_Ada_83_Warning;
12165 Check_Arg_Count (0);
12167 -- Call dummy debugging function rv. This is done to assist front
12168 -- end debugging. By placing a Reviewable pragma in the source
12169 -- program, a breakpoint on rv catches this place in the source,
12170 -- allowing convenient stepping to the point of interest.
12174 --------------------------
12175 -- Short_Circuit_And_Or --
12176 --------------------------
12178 when Pragma_Short_Circuit_And_Or =>
12180 Check_Arg_Count (0);
12181 Check_Valid_Configuration_Pragma;
12182 Short_Circuit_And_Or := True;
12184 -------------------
12185 -- Share_Generic --
12186 -------------------
12188 -- pragma Share_Generic (NAME {, NAME});
12190 when Pragma_Share_Generic =>
12192 Process_Generic_List;
12198 -- pragma Shared (LOCAL_NAME);
12200 when Pragma_Shared =>
12202 Process_Atomic_Shared_Volatile;
12204 --------------------
12205 -- Shared_Passive --
12206 --------------------
12208 -- pragma Shared_Passive [(library_unit_NAME)];
12210 -- Set the flag Is_Shared_Passive of program unit name entity
12212 when Pragma_Shared_Passive => Shared_Passive : declare
12213 Cunit_Node : Node_Id;
12214 Cunit_Ent : Entity_Id;
12217 Check_Ada_83_Warning;
12218 Check_Valid_Library_Unit_Pragma;
12220 if Nkind (N) = N_Null_Statement then
12224 Cunit_Node := Cunit (Current_Sem_Unit);
12225 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12227 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12228 N_Generic_Package_Declaration)
12231 ("pragma% can only apply to a package declaration");
12234 Set_Is_Shared_Passive (Cunit_Ent);
12235 end Shared_Passive;
12237 -----------------------
12238 -- Short_Descriptors --
12239 -----------------------
12241 -- pragma Short_Descriptors;
12243 when Pragma_Short_Descriptors =>
12245 Check_Arg_Count (0);
12246 Check_Valid_Configuration_Pragma;
12247 Short_Descriptors := True;
12249 ----------------------
12250 -- Source_File_Name --
12251 ----------------------
12253 -- There are five forms for this pragma:
12255 -- pragma Source_File_Name (
12256 -- [UNIT_NAME =>] unit_NAME,
12257 -- BODY_FILE_NAME => STRING_LITERAL
12258 -- [, [INDEX =>] INTEGER_LITERAL]);
12260 -- pragma Source_File_Name (
12261 -- [UNIT_NAME =>] unit_NAME,
12262 -- SPEC_FILE_NAME => STRING_LITERAL
12263 -- [, [INDEX =>] INTEGER_LITERAL]);
12265 -- pragma Source_File_Name (
12266 -- BODY_FILE_NAME => STRING_LITERAL
12267 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12268 -- [, CASING => CASING_SPEC]);
12270 -- pragma Source_File_Name (
12271 -- SPEC_FILE_NAME => STRING_LITERAL
12272 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12273 -- [, CASING => CASING_SPEC]);
12275 -- pragma Source_File_Name (
12276 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12277 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12278 -- [, CASING => CASING_SPEC]);
12280 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12282 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12283 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12284 -- only be used when no project file is used, while SFNP can only be
12285 -- used when a project file is used.
12287 -- No processing here. Processing was completed during parsing, since
12288 -- we need to have file names set as early as possible. Units are
12289 -- loaded well before semantic processing starts.
12291 -- The only processing we defer to this point is the check for
12292 -- correct placement.
12294 when Pragma_Source_File_Name =>
12296 Check_Valid_Configuration_Pragma;
12298 ------------------------------
12299 -- Source_File_Name_Project --
12300 ------------------------------
12302 -- See Source_File_Name for syntax
12304 -- No processing here. Processing was completed during parsing, since
12305 -- we need to have file names set as early as possible. Units are
12306 -- loaded well before semantic processing starts.
12308 -- The only processing we defer to this point is the check for
12309 -- correct placement.
12311 when Pragma_Source_File_Name_Project =>
12313 Check_Valid_Configuration_Pragma;
12315 -- Check that a pragma Source_File_Name_Project is used only in a
12316 -- configuration pragmas file.
12318 -- Pragmas Source_File_Name_Project should only be generated by
12319 -- the Project Manager in configuration pragmas files.
12321 -- This is really an ugly test. It seems to depend on some
12322 -- accidental and undocumented property. At the very least it
12323 -- needs to be documented, but it would be better to have a
12324 -- clean way of testing if we are in a configuration file???
12326 if Present (Parent (N)) then
12328 ("pragma% can only appear in a configuration pragmas file");
12331 ----------------------
12332 -- Source_Reference --
12333 ----------------------
12335 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12337 -- Nothing to do, all processing completed in Par.Prag, since we need
12338 -- the information for possible parser messages that are output.
12340 when Pragma_Source_Reference =>
12343 --------------------------------
12344 -- Static_Elaboration_Desired --
12345 --------------------------------
12347 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12349 when Pragma_Static_Elaboration_Desired =>
12351 Check_At_Most_N_Arguments (1);
12353 if Is_Compilation_Unit (Current_Scope)
12354 and then Ekind (Current_Scope) = E_Package
12356 Set_Static_Elaboration_Desired (Current_Scope, True);
12358 Error_Pragma ("pragma% must apply to a library-level package");
12365 -- pragma Storage_Size (EXPRESSION);
12367 when Pragma_Storage_Size => Storage_Size : declare
12368 P : constant Node_Id := Parent (N);
12372 Check_No_Identifiers;
12373 Check_Arg_Count (1);
12375 -- The expression must be analyzed in the special manner described
12376 -- in "Handling of Default Expressions" in sem.ads.
12378 Arg := Get_Pragma_Arg (Arg1);
12379 Preanalyze_Spec_Expression (Arg, Any_Integer);
12381 if not Is_Static_Expression (Arg) then
12382 Check_Restriction (Static_Storage_Size, Arg);
12385 if Nkind (P) /= N_Task_Definition then
12390 if Has_Storage_Size_Pragma (P) then
12391 Error_Pragma ("duplicate pragma% not allowed");
12393 Set_Has_Storage_Size_Pragma (P, True);
12396 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12397 -- ??? exp_ch9 should use this!
12405 -- pragma Storage_Unit (NUMERIC_LITERAL);
12407 -- Only permitted argument is System'Storage_Unit value
12409 when Pragma_Storage_Unit =>
12410 Check_No_Identifiers;
12411 Check_Arg_Count (1);
12412 Check_Arg_Is_Integer_Literal (Arg1);
12414 if Intval (Get_Pragma_Arg (Arg1)) /=
12415 UI_From_Int (Ttypes.System_Storage_Unit)
12417 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12419 ("the only allowed argument for pragma% is ^", Arg1);
12422 --------------------
12423 -- Stream_Convert --
12424 --------------------
12426 -- pragma Stream_Convert (
12427 -- [Entity =>] type_LOCAL_NAME,
12428 -- [Read =>] function_NAME,
12429 -- [Write =>] function NAME);
12431 when Pragma_Stream_Convert => Stream_Convert : declare
12433 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12434 -- Check that the given argument is the name of a local function
12435 -- of one argument that is not overloaded earlier in the current
12436 -- local scope. A check is also made that the argument is a
12437 -- function with one parameter.
12439 --------------------------------------
12440 -- Check_OK_Stream_Convert_Function --
12441 --------------------------------------
12443 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12447 Check_Arg_Is_Local_Name (Arg);
12448 Ent := Entity (Get_Pragma_Arg (Arg));
12450 if Has_Homonym (Ent) then
12452 ("argument for pragma% may not be overloaded", Arg);
12455 if Ekind (Ent) /= E_Function
12456 or else No (First_Formal (Ent))
12457 or else Present (Next_Formal (First_Formal (Ent)))
12460 ("argument for pragma% must be" &
12461 " function of one argument", Arg);
12463 end Check_OK_Stream_Convert_Function;
12465 -- Start of processing for Stream_Convert
12469 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12470 Check_Arg_Count (3);
12471 Check_Optional_Identifier (Arg1, Name_Entity);
12472 Check_Optional_Identifier (Arg2, Name_Read);
12473 Check_Optional_Identifier (Arg3, Name_Write);
12474 Check_Arg_Is_Local_Name (Arg1);
12475 Check_OK_Stream_Convert_Function (Arg2);
12476 Check_OK_Stream_Convert_Function (Arg3);
12479 Typ : constant Entity_Id :=
12480 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12481 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12482 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12485 Check_First_Subtype (Arg1);
12487 -- Check for too early or too late. Note that we don't enforce
12488 -- the rule about primitive operations in this case, since, as
12489 -- is the case for explicit stream attributes themselves, these
12490 -- restrictions are not appropriate. Note that the chaining of
12491 -- the pragma by Rep_Item_Too_Late is actually the critical
12492 -- processing done for this pragma.
12494 if Rep_Item_Too_Early (Typ, N)
12496 Rep_Item_Too_Late (Typ, N, FOnly => True)
12501 -- Return if previous error
12503 if Etype (Typ) = Any_Type
12505 Etype (Read) = Any_Type
12507 Etype (Write) = Any_Type
12514 if Underlying_Type (Etype (Read)) /= Typ then
12516 ("incorrect return type for function&", Arg2);
12519 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12521 ("incorrect parameter type for function&", Arg3);
12524 if Underlying_Type (Etype (First_Formal (Read))) /=
12525 Underlying_Type (Etype (Write))
12528 ("result type of & does not match Read parameter type",
12532 end Stream_Convert;
12534 -------------------------
12535 -- Style_Checks (GNAT) --
12536 -------------------------
12538 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12540 -- This is processed by the parser since some of the style checks
12541 -- take place during source scanning and parsing. This means that
12542 -- we don't need to issue error messages here.
12544 when Pragma_Style_Checks => Style_Checks : declare
12545 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12551 Check_No_Identifiers;
12553 -- Two argument form
12555 if Arg_Count = 2 then
12556 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12563 E_Id := Get_Pragma_Arg (Arg2);
12566 if not Is_Entity_Name (E_Id) then
12568 ("second argument of pragma% must be entity name",
12572 E := Entity (E_Id);
12578 Set_Suppress_Style_Checks (E,
12579 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12580 exit when No (Homonym (E));
12586 -- One argument form
12589 Check_Arg_Count (1);
12591 if Nkind (A) = N_String_Literal then
12595 Slen : constant Natural := Natural (String_Length (S));
12596 Options : String (1 .. Slen);
12602 C := Get_String_Char (S, Int (J));
12603 exit when not In_Character_Range (C);
12604 Options (J) := Get_Character (C);
12606 -- If at end of string, set options. As per discussion
12607 -- above, no need to check for errors, since we issued
12608 -- them in the parser.
12611 Set_Style_Check_Options (Options);
12619 elsif Nkind (A) = N_Identifier then
12620 if Chars (A) = Name_All_Checks then
12622 Set_GNAT_Style_Check_Options;
12624 Set_Default_Style_Check_Options;
12627 elsif Chars (A) = Name_On then
12628 Style_Check := True;
12630 elsif Chars (A) = Name_Off then
12631 Style_Check := False;
12641 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12643 when Pragma_Subtitle =>
12645 Check_Arg_Count (1);
12646 Check_Optional_Identifier (Arg1, Name_Subtitle);
12647 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12654 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12656 when Pragma_Suppress =>
12657 Process_Suppress_Unsuppress (True);
12663 -- pragma Suppress_All;
12665 -- The only check made here is that the pragma has no arguments.
12666 -- There are no placement rules, and the processing required (setting
12667 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12668 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12669 -- then creates and inserts a pragma Suppress (All_Checks).
12671 when Pragma_Suppress_All =>
12673 Check_Arg_Count (0);
12675 -------------------------
12676 -- Suppress_Debug_Info --
12677 -------------------------
12679 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12681 when Pragma_Suppress_Debug_Info =>
12683 Check_Arg_Count (1);
12684 Check_Optional_Identifier (Arg1, Name_Entity);
12685 Check_Arg_Is_Local_Name (Arg1);
12686 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
12688 ----------------------------------
12689 -- Suppress_Exception_Locations --
12690 ----------------------------------
12692 -- pragma Suppress_Exception_Locations;
12694 when Pragma_Suppress_Exception_Locations =>
12696 Check_Arg_Count (0);
12697 Check_Valid_Configuration_Pragma;
12698 Exception_Locations_Suppressed := True;
12700 -----------------------------
12701 -- Suppress_Initialization --
12702 -----------------------------
12704 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12706 when Pragma_Suppress_Initialization => Suppress_Init : declare
12712 Check_Arg_Count (1);
12713 Check_Optional_Identifier (Arg1, Name_Entity);
12714 Check_Arg_Is_Local_Name (Arg1);
12716 E_Id := Get_Pragma_Arg (Arg1);
12718 if Etype (E_Id) = Any_Type then
12722 E := Entity (E_Id);
12724 if Is_Type (E) then
12725 if Is_Incomplete_Or_Private_Type (E) then
12726 if No (Full_View (Base_Type (E))) then
12728 ("argument of pragma% cannot be an incomplete type",
12731 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12734 Set_Suppress_Init_Proc (Base_Type (E));
12739 ("pragma% requires argument that is a type name", Arg1);
12747 -- pragma System_Name (DIRECT_NAME);
12749 -- Syntax check: one argument, which must be the identifier GNAT or
12750 -- the identifier GCC, no other identifiers are acceptable.
12752 when Pragma_System_Name =>
12754 Check_No_Identifiers;
12755 Check_Arg_Count (1);
12756 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12758 -----------------------------
12759 -- Task_Dispatching_Policy --
12760 -----------------------------
12762 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12764 when Pragma_Task_Dispatching_Policy => declare
12768 Check_Ada_83_Warning;
12769 Check_Arg_Count (1);
12770 Check_No_Identifiers;
12771 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12772 Check_Valid_Configuration_Pragma;
12773 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12774 DP := Fold_Upper (Name_Buffer (1));
12776 if Task_Dispatching_Policy /= ' '
12777 and then Task_Dispatching_Policy /= DP
12779 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12781 ("task dispatching policy incompatible with policy#");
12783 -- Set new policy, but always preserve System_Location since we
12784 -- like the error message with the run time name.
12787 Task_Dispatching_Policy := DP;
12789 if Task_Dispatching_Policy_Sloc /= System_Location then
12790 Task_Dispatching_Policy_Sloc := Loc;
12799 -- pragma Task_Info (EXPRESSION);
12801 when Pragma_Task_Info => Task_Info : declare
12802 P : constant Node_Id := Parent (N);
12807 if Nkind (P) /= N_Task_Definition then
12808 Error_Pragma ("pragma% must appear in task definition");
12811 Check_No_Identifiers;
12812 Check_Arg_Count (1);
12814 Analyze_And_Resolve
12815 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12817 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12821 if Has_Task_Info_Pragma (P) then
12822 Error_Pragma ("duplicate pragma% not allowed");
12824 Set_Has_Task_Info_Pragma (P, True);
12832 -- pragma Task_Name (string_EXPRESSION);
12834 when Pragma_Task_Name => Task_Name : declare
12835 P : constant Node_Id := Parent (N);
12839 Check_No_Identifiers;
12840 Check_Arg_Count (1);
12842 Arg := Get_Pragma_Arg (Arg1);
12844 -- The expression is used in the call to Create_Task, and must be
12845 -- expanded there, not in the context of the current spec. It must
12846 -- however be analyzed to capture global references, in case it
12847 -- appears in a generic context.
12849 Preanalyze_And_Resolve (Arg, Standard_String);
12851 if Nkind (P) /= N_Task_Definition then
12855 if Has_Task_Name_Pragma (P) then
12856 Error_Pragma ("duplicate pragma% not allowed");
12858 Set_Has_Task_Name_Pragma (P, True);
12859 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12867 -- pragma Task_Storage (
12868 -- [Task_Type =>] LOCAL_NAME,
12869 -- [Top_Guard =>] static_integer_EXPRESSION);
12871 when Pragma_Task_Storage => Task_Storage : declare
12872 Args : Args_List (1 .. 2);
12873 Names : constant Name_List (1 .. 2) := (
12877 Task_Type : Node_Id renames Args (1);
12878 Top_Guard : Node_Id renames Args (2);
12884 Gather_Associations (Names, Args);
12886 if No (Task_Type) then
12888 ("missing task_type argument for pragma%");
12891 Check_Arg_Is_Local_Name (Task_Type);
12893 Ent := Entity (Task_Type);
12895 if not Is_Task_Type (Ent) then
12897 ("argument for pragma% must be task type", Task_Type);
12900 if No (Top_Guard) then
12902 ("pragma% takes two arguments", Task_Type);
12904 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12907 Check_First_Subtype (Task_Type);
12909 if Rep_Item_Too_Late (Ent, N) then
12914 --------------------------
12915 -- Thread_Local_Storage --
12916 --------------------------
12918 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12920 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
12926 Check_Arg_Count (1);
12927 Check_Optional_Identifier (Arg1, Name_Entity);
12928 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12930 Id := Get_Pragma_Arg (Arg1);
12933 if not Is_Entity_Name (Id)
12934 or else Ekind (Entity (Id)) /= E_Variable
12936 Error_Pragma_Arg ("local variable name required", Arg1);
12941 if Rep_Item_Too_Early (E, N)
12942 or else Rep_Item_Too_Late (E, N)
12947 Set_Has_Pragma_Thread_Local_Storage (E);
12948 Set_Has_Gigi_Rep_Item (E);
12949 end Thread_Local_Storage;
12955 -- pragma Time_Slice (static_duration_EXPRESSION);
12957 when Pragma_Time_Slice => Time_Slice : declare
12963 Check_Arg_Count (1);
12964 Check_No_Identifiers;
12965 Check_In_Main_Program;
12966 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
12968 if not Error_Posted (Arg1) then
12970 while Present (Nod) loop
12971 if Nkind (Nod) = N_Pragma
12972 and then Pragma_Name (Nod) = Name_Time_Slice
12974 Error_Msg_Name_1 := Pname;
12975 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12982 -- Process only if in main unit
12984 if Get_Source_Unit (Loc) = Main_Unit then
12985 Opt.Time_Slice_Set := True;
12986 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
12988 if Val <= Ureal_0 then
12989 Opt.Time_Slice_Value := 0;
12991 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
12992 Opt.Time_Slice_Value := 1_000_000_000;
12995 Opt.Time_Slice_Value :=
12996 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13005 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13007 -- TITLING_OPTION ::=
13008 -- [Title =>] STRING_LITERAL
13009 -- | [Subtitle =>] STRING_LITERAL
13011 when Pragma_Title => Title : declare
13012 Args : Args_List (1 .. 2);
13013 Names : constant Name_List (1 .. 2) := (
13019 Gather_Associations (Names, Args);
13022 for J in 1 .. 2 loop
13023 if Present (Args (J)) then
13024 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13029 ---------------------
13030 -- Unchecked_Union --
13031 ---------------------
13033 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13035 when Pragma_Unchecked_Union => Unchecked_Union : declare
13036 Assoc : constant Node_Id := Arg1;
13037 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13048 Check_No_Identifiers;
13049 Check_Arg_Count (1);
13050 Check_Arg_Is_Local_Name (Arg1);
13052 Find_Type (Type_Id);
13053 Typ := Entity (Type_Id);
13056 or else Rep_Item_Too_Early (Typ, N)
13060 Typ := Underlying_Type (Typ);
13063 if Rep_Item_Too_Late (Typ, N) then
13067 Check_First_Subtype (Arg1);
13069 -- Note remaining cases are references to a type in the current
13070 -- declarative part. If we find an error, we post the error on
13071 -- the relevant type declaration at an appropriate point.
13073 if not Is_Record_Type (Typ) then
13074 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13077 elsif Is_Tagged_Type (Typ) then
13078 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13081 elsif Is_Limited_Type (Typ) then
13083 ("Unchecked_Union must not be limited record type", Typ);
13084 Explain_Limited_Type (Typ, Typ);
13088 if not Has_Discriminants (Typ) then
13090 ("Unchecked_Union must have one discriminant", Typ);
13094 Discr := First_Discriminant (Typ);
13095 while Present (Discr) loop
13096 if No (Discriminant_Default_Value (Discr)) then
13098 ("Unchecked_Union discriminant must have default value",
13102 Next_Discriminant (Discr);
13105 Tdef := Type_Definition (Declaration_Node (Typ));
13106 Clist := Component_List (Tdef);
13108 Comp := First (Component_Items (Clist));
13109 while Present (Comp) loop
13110 Check_Component (Comp, Typ);
13114 if No (Clist) or else No (Variant_Part (Clist)) then
13116 ("Unchecked_Union must have variant part",
13121 Vpart := Variant_Part (Clist);
13123 Variant := First (Variants (Vpart));
13124 while Present (Variant) loop
13125 Check_Variant (Variant, Typ);
13130 Set_Is_Unchecked_Union (Typ);
13131 Set_Convention (Typ, Convention_C);
13132 Set_Has_Unchecked_Union (Base_Type (Typ));
13133 Set_Is_Unchecked_Union (Base_Type (Typ));
13134 end Unchecked_Union;
13136 ------------------------
13137 -- Unimplemented_Unit --
13138 ------------------------
13140 -- pragma Unimplemented_Unit;
13142 -- Note: this only gives an error if we are generating code, or if
13143 -- we are in a generic library unit (where the pragma appears in the
13144 -- body, not in the spec).
13146 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13147 Cunitent : constant Entity_Id :=
13148 Cunit_Entity (Get_Source_Unit (Loc));
13149 Ent_Kind : constant Entity_Kind :=
13154 Check_Arg_Count (0);
13156 if Operating_Mode = Generate_Code
13157 or else Ent_Kind = E_Generic_Function
13158 or else Ent_Kind = E_Generic_Procedure
13159 or else Ent_Kind = E_Generic_Package
13161 Get_Name_String (Chars (Cunitent));
13162 Set_Casing (Mixed_Case);
13163 Write_Str (Name_Buffer (1 .. Name_Len));
13164 Write_Str (" is not supported in this configuration");
13166 raise Unrecoverable_Error;
13168 end Unimplemented_Unit;
13170 ------------------------
13171 -- Universal_Aliasing --
13172 ------------------------
13174 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13176 when Pragma_Universal_Aliasing => Universal_Alias : declare
13181 Check_Arg_Count (1);
13182 Check_Optional_Identifier (Arg2, Name_Entity);
13183 Check_Arg_Is_Local_Name (Arg1);
13184 E_Id := Entity (Get_Pragma_Arg (Arg1));
13186 if E_Id = Any_Type then
13188 elsif No (E_Id) or else not Is_Type (E_Id) then
13189 Error_Pragma_Arg ("pragma% requires type", Arg1);
13192 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13193 end Universal_Alias;
13195 --------------------
13196 -- Universal_Data --
13197 --------------------
13199 -- pragma Universal_Data [(library_unit_NAME)];
13201 when Pragma_Universal_Data =>
13204 -- If this is a configuration pragma, then set the universal
13205 -- addressing option, otherwise confirm that the pragma satisfies
13206 -- the requirements of library unit pragma placement and leave it
13207 -- to the GNAAMP back end to detect the pragma (avoids transitive
13208 -- setting of the option due to withed units).
13210 if Is_Configuration_Pragma then
13211 Universal_Addressing_On_AAMP := True;
13213 Check_Valid_Library_Unit_Pragma;
13216 if not AAMP_On_Target then
13217 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13224 -- pragma Unmodified (local_Name {, local_Name});
13226 when Pragma_Unmodified => Unmodified : declare
13227 Arg_Node : Node_Id;
13228 Arg_Expr : Node_Id;
13229 Arg_Ent : Entity_Id;
13233 Check_At_Least_N_Arguments (1);
13235 -- Loop through arguments
13238 while Present (Arg_Node) loop
13239 Check_No_Identifier (Arg_Node);
13241 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13242 -- in fact generate reference, so that the entity will have a
13243 -- reference, which will inhibit any warnings about it not
13244 -- being referenced, and also properly show up in the ali file
13245 -- as a reference. But this reference is recorded before the
13246 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13247 -- generated for this reference.
13249 Check_Arg_Is_Local_Name (Arg_Node);
13250 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13252 if Is_Entity_Name (Arg_Expr) then
13253 Arg_Ent := Entity (Arg_Expr);
13255 if not Is_Assignable (Arg_Ent) then
13257 ("pragma% can only be applied to a variable",
13260 Set_Has_Pragma_Unmodified (Arg_Ent);
13272 -- pragma Unreferenced (local_Name {, local_Name});
13274 -- or when used in a context clause:
13276 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13278 when Pragma_Unreferenced => Unreferenced : declare
13279 Arg_Node : Node_Id;
13280 Arg_Expr : Node_Id;
13281 Arg_Ent : Entity_Id;
13286 Check_At_Least_N_Arguments (1);
13288 -- Check case of appearing within context clause
13290 if Is_In_Context_Clause then
13292 -- The arguments must all be units mentioned in a with clause
13293 -- in the same context clause. Note we already checked (in
13294 -- Par.Prag) that the arguments are either identifiers or
13295 -- selected components.
13298 while Present (Arg_Node) loop
13299 Citem := First (List_Containing (N));
13300 while Citem /= N loop
13301 if Nkind (Citem) = N_With_Clause
13303 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13305 Set_Has_Pragma_Unreferenced
13308 (Library_Unit (Citem))));
13310 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13319 ("argument of pragma% is not with'ed unit", Arg_Node);
13325 -- Case of not in list of context items
13329 while Present (Arg_Node) loop
13330 Check_No_Identifier (Arg_Node);
13332 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13333 -- will in fact generate reference, so that the entity will
13334 -- have a reference, which will inhibit any warnings about
13335 -- it not being referenced, and also properly show up in the
13336 -- ali file as a reference. But this reference is recorded
13337 -- before the Has_Pragma_Unreferenced flag is set, so that
13338 -- no warning is generated for this reference.
13340 Check_Arg_Is_Local_Name (Arg_Node);
13341 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13343 if Is_Entity_Name (Arg_Expr) then
13344 Arg_Ent := Entity (Arg_Expr);
13346 -- If the entity is overloaded, the pragma applies to the
13347 -- most recent overloading, as documented. In this case,
13348 -- name resolution does not generate a reference, so it
13349 -- must be done here explicitly.
13351 if Is_Overloaded (Arg_Expr) then
13352 Generate_Reference (Arg_Ent, N);
13355 Set_Has_Pragma_Unreferenced (Arg_Ent);
13363 --------------------------
13364 -- Unreferenced_Objects --
13365 --------------------------
13367 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13369 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13370 Arg_Node : Node_Id;
13371 Arg_Expr : Node_Id;
13375 Check_At_Least_N_Arguments (1);
13378 while Present (Arg_Node) loop
13379 Check_No_Identifier (Arg_Node);
13380 Check_Arg_Is_Local_Name (Arg_Node);
13381 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13383 if not Is_Entity_Name (Arg_Expr)
13384 or else not Is_Type (Entity (Arg_Expr))
13387 ("argument for pragma% must be type or subtype", Arg_Node);
13390 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13393 end Unreferenced_Objects;
13395 ------------------------------
13396 -- Unreserve_All_Interrupts --
13397 ------------------------------
13399 -- pragma Unreserve_All_Interrupts;
13401 when Pragma_Unreserve_All_Interrupts =>
13403 Check_Arg_Count (0);
13405 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13406 Unreserve_All_Interrupts := True;
13413 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13415 when Pragma_Unsuppress =>
13417 Process_Suppress_Unsuppress (False);
13419 -------------------
13420 -- Use_VADS_Size --
13421 -------------------
13423 -- pragma Use_VADS_Size;
13425 when Pragma_Use_VADS_Size =>
13427 Check_Arg_Count (0);
13428 Check_Valid_Configuration_Pragma;
13429 Use_VADS_Size := True;
13431 ---------------------
13432 -- Validity_Checks --
13433 ---------------------
13435 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13437 when Pragma_Validity_Checks => Validity_Checks : declare
13438 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13444 Check_Arg_Count (1);
13445 Check_No_Identifiers;
13447 if Nkind (A) = N_String_Literal then
13451 Slen : constant Natural := Natural (String_Length (S));
13452 Options : String (1 .. Slen);
13458 C := Get_String_Char (S, Int (J));
13459 exit when not In_Character_Range (C);
13460 Options (J) := Get_Character (C);
13463 Set_Validity_Check_Options (Options);
13471 elsif Nkind (A) = N_Identifier then
13473 if Chars (A) = Name_All_Checks then
13474 Set_Validity_Check_Options ("a");
13476 elsif Chars (A) = Name_On then
13477 Validity_Checks_On := True;
13479 elsif Chars (A) = Name_Off then
13480 Validity_Checks_On := False;
13484 end Validity_Checks;
13490 -- pragma Volatile (LOCAL_NAME);
13492 when Pragma_Volatile =>
13493 Process_Atomic_Shared_Volatile;
13495 -------------------------
13496 -- Volatile_Components --
13497 -------------------------
13499 -- pragma Volatile_Components (array_LOCAL_NAME);
13501 -- Volatile is handled by the same circuit as Atomic_Components
13507 -- pragma Warnings (On | Off);
13508 -- pragma Warnings (On | Off, LOCAL_NAME);
13509 -- pragma Warnings (static_string_EXPRESSION);
13510 -- pragma Warnings (On | Off, STRING_LITERAL);
13512 when Pragma_Warnings => Warnings : begin
13514 Check_At_Least_N_Arguments (1);
13515 Check_No_Identifiers;
13517 -- If debug flag -gnatd.i is set, pragma is ignored
13519 if Debug_Flag_Dot_I then
13523 -- Process various forms of the pragma
13526 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13529 -- One argument case
13531 if Arg_Count = 1 then
13533 -- On/Off one argument case was processed by parser
13535 if Nkind (Argx) = N_Identifier
13537 (Chars (Argx) = Name_On
13539 Chars (Argx) = Name_Off)
13543 -- One argument case must be ON/OFF or static string expr
13545 elsif not Is_Static_String_Expression (Arg1) then
13547 ("argument of pragma% must be On/Off or " &
13548 "static string expression", Arg1);
13550 -- One argument string expression case
13554 Lit : constant Node_Id := Expr_Value_S (Argx);
13555 Str : constant String_Id := Strval (Lit);
13556 Len : constant Nat := String_Length (Str);
13564 while J <= Len loop
13565 C := Get_String_Char (Str, J);
13566 OK := In_Character_Range (C);
13569 Chr := Get_Character (C);
13573 if J < Len and then Chr = '.' then
13575 C := Get_String_Char (Str, J);
13576 Chr := Get_Character (C);
13578 if not Set_Dot_Warning_Switch (Chr) then
13580 ("invalid warning switch character " &
13587 OK := Set_Warning_Switch (Chr);
13593 ("invalid warning switch character " & Chr,
13602 -- Two or more arguments (must be two)
13605 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13606 Check_At_Most_N_Arguments (2);
13614 E_Id := Get_Pragma_Arg (Arg2);
13617 -- In the expansion of an inlined body, a reference to
13618 -- the formal may be wrapped in a conversion if the
13619 -- actual is a conversion. Retrieve the real entity name.
13621 if (In_Instance_Body
13622 or else In_Inlined_Body)
13623 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13625 E_Id := Expression (E_Id);
13628 -- Entity name case
13630 if Is_Entity_Name (E_Id) then
13631 E := Entity (E_Id);
13638 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13641 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13642 and then Warn_On_Warnings_Off
13644 Warnings_Off_Pragmas.Append ((N, E));
13647 if Is_Enumeration_Type (E) then
13651 Lit := First_Literal (E);
13652 while Present (Lit) loop
13653 Set_Warnings_Off (Lit);
13654 Next_Literal (Lit);
13659 exit when No (Homonym (E));
13664 -- Error if not entity or static string literal case
13666 elsif not Is_Static_String_Expression (Arg2) then
13668 ("second argument of pragma% must be entity " &
13669 "name or static string expression", Arg2);
13671 -- String literal case
13674 String_To_Name_Buffer
13675 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13677 -- Note on configuration pragma case: If this is a
13678 -- configuration pragma, then for an OFF pragma, we
13679 -- just set Config True in the call, which is all
13680 -- that needs to be done. For the case of ON, this
13681 -- is normally an error, unless it is canceling the
13682 -- effect of a previous OFF pragma in the same file.
13683 -- In any other case, an error will be signalled (ON
13684 -- with no matching OFF).
13686 if Chars (Argx) = Name_Off then
13687 Set_Specific_Warning_Off
13688 (Loc, Name_Buffer (1 .. Name_Len),
13689 Config => Is_Configuration_Pragma);
13691 elsif Chars (Argx) = Name_On then
13692 Set_Specific_Warning_On
13693 (Loc, Name_Buffer (1 .. Name_Len), Err);
13697 ("?pragma Warnings On with no " &
13698 "matching Warnings Off",
13708 -------------------
13709 -- Weak_External --
13710 -------------------
13712 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13714 when Pragma_Weak_External => Weak_External : declare
13719 Check_Arg_Count (1);
13720 Check_Optional_Identifier (Arg1, Name_Entity);
13721 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13722 Ent := Entity (Get_Pragma_Arg (Arg1));
13724 if Rep_Item_Too_Early (Ent, N) then
13727 Ent := Underlying_Type (Ent);
13730 -- The only processing required is to link this item on to the
13731 -- list of rep items for the given entity. This is accomplished
13732 -- by the call to Rep_Item_Too_Late (when no error is detected
13733 -- and False is returned).
13735 if Rep_Item_Too_Late (Ent, N) then
13738 Set_Has_Gigi_Rep_Item (Ent);
13742 -----------------------------
13743 -- Wide_Character_Encoding --
13744 -----------------------------
13746 -- pragma Wide_Character_Encoding (IDENTIFIER);
13748 when Pragma_Wide_Character_Encoding =>
13751 -- Nothing to do, handled in parser. Note that we do not enforce
13752 -- configuration pragma placement, this pragma can appear at any
13753 -- place in the source, allowing mixed encodings within a single
13758 --------------------
13759 -- Unknown_Pragma --
13760 --------------------
13762 -- Should be impossible, since the case of an unknown pragma is
13763 -- separately processed before the case statement is entered.
13765 when Unknown_Pragma =>
13766 raise Program_Error;
13769 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13770 -- until AI is formally approved.
13772 -- Check_Order_Dependence;
13775 when Pragma_Exit => null;
13776 end Analyze_Pragma;
13778 -------------------
13779 -- Check_Enabled --
13780 -------------------
13782 function Check_Enabled (Nam : Name_Id) return Boolean is
13786 -- Loop through entries in check policy list
13788 PP := Opt.Check_Policy_List;
13790 -- If there are no specific entries that matched, then we let the
13791 -- setting of assertions govern. Note that this provides the needed
13792 -- compatibility with the RM for the cases of assertion, invariant,
13793 -- precondition, predicate, and postcondition.
13796 return Assertions_Enabled;
13798 -- Here we have an entry see if it matches
13802 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13805 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13806 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13807 when Name_On | Name_Check =>
13809 when Name_Off | Name_Ignore =>
13812 raise Program_Error;
13816 PP := Next_Pragma (PP);
13823 ---------------------------------
13824 -- Delay_Config_Pragma_Analyze --
13825 ---------------------------------
13827 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13829 return Pragma_Name (N) = Name_Interrupt_State
13831 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13832 end Delay_Config_Pragma_Analyze;
13834 -------------------------
13835 -- Get_Base_Subprogram --
13836 -------------------------
13838 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13839 Result : Entity_Id;
13842 -- Follow subprogram renaming chain
13845 while Is_Subprogram (Result)
13847 (Is_Generic_Instance (Result)
13848 or else Nkind (Parent (Declaration_Node (Result))) =
13849 N_Subprogram_Renaming_Declaration)
13850 and then Present (Alias (Result))
13852 Result := Alias (Result);
13856 end Get_Base_Subprogram;
13862 procedure Initialize is
13867 -----------------------------
13868 -- Is_Config_Static_String --
13869 -----------------------------
13871 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13873 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13874 -- This is an internal recursive function that is just like the outer
13875 -- function except that it adds the string to the name buffer rather
13876 -- than placing the string in the name buffer.
13878 ------------------------------
13879 -- Add_Config_Static_String --
13880 ------------------------------
13882 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13889 if Nkind (N) = N_Op_Concat then
13890 if Add_Config_Static_String (Left_Opnd (N)) then
13891 N := Right_Opnd (N);
13897 if Nkind (N) /= N_String_Literal then
13898 Error_Msg_N ("string literal expected for pragma argument", N);
13902 for J in 1 .. String_Length (Strval (N)) loop
13903 C := Get_String_Char (Strval (N), J);
13905 if not In_Character_Range (C) then
13907 ("string literal contains invalid wide character",
13908 Sloc (N) + 1 + Source_Ptr (J));
13912 Add_Char_To_Name_Buffer (Get_Character (C));
13917 end Add_Config_Static_String;
13919 -- Start of processing for Is_Config_Static_String
13924 return Add_Config_Static_String (Arg);
13925 end Is_Config_Static_String;
13927 -----------------------------------------
13928 -- Is_Non_Significant_Pragma_Reference --
13929 -----------------------------------------
13931 -- This function makes use of the following static table which indicates
13932 -- whether a given pragma is significant.
13934 -- -1 indicates that references in any argument position are significant
13935 -- 0 indicates that appearance in any argument is not significant
13936 -- +n indicates that appearance as argument n is significant, but all
13937 -- other arguments are not significant
13938 -- 99 special processing required (e.g. for pragma Check)
13940 Sig_Flags : constant array (Pragma_Id) of Int :=
13941 (Pragma_AST_Entry => -1,
13942 Pragma_Abort_Defer => -1,
13943 Pragma_Ada_83 => -1,
13944 Pragma_Ada_95 => -1,
13945 Pragma_Ada_05 => -1,
13946 Pragma_Ada_2005 => -1,
13947 Pragma_Ada_12 => -1,
13948 Pragma_Ada_2012 => -1,
13949 Pragma_All_Calls_Remote => -1,
13950 Pragma_Annotate => -1,
13951 Pragma_Assert => -1,
13952 Pragma_Assertion_Policy => 0,
13953 Pragma_Assume_No_Invalid_Values => 0,
13954 Pragma_Asynchronous => -1,
13955 Pragma_Atomic => 0,
13956 Pragma_Atomic_Components => 0,
13957 Pragma_Attach_Handler => -1,
13958 Pragma_Check => 99,
13959 Pragma_Check_Name => 0,
13960 Pragma_Check_Policy => 0,
13961 Pragma_CIL_Constructor => -1,
13962 Pragma_CPP_Class => 0,
13963 Pragma_CPP_Constructor => 0,
13964 Pragma_CPP_Virtual => 0,
13965 Pragma_CPP_Vtable => 0,
13967 Pragma_C_Pass_By_Copy => 0,
13968 Pragma_Comment => 0,
13969 Pragma_Common_Object => -1,
13970 Pragma_Compile_Time_Error => -1,
13971 Pragma_Compile_Time_Warning => -1,
13972 Pragma_Compiler_Unit => 0,
13973 Pragma_Complete_Representation => 0,
13974 Pragma_Complex_Representation => 0,
13975 Pragma_Component_Alignment => -1,
13976 Pragma_Controlled => 0,
13977 Pragma_Convention => 0,
13978 Pragma_Convention_Identifier => 0,
13979 Pragma_Debug => -1,
13980 Pragma_Debug_Policy => 0,
13981 Pragma_Detect_Blocking => -1,
13982 Pragma_Default_Storage_Pool => -1,
13983 Pragma_Dimension => -1,
13984 Pragma_Discard_Names => 0,
13985 Pragma_Elaborate => -1,
13986 Pragma_Elaborate_All => -1,
13987 Pragma_Elaborate_Body => -1,
13988 Pragma_Elaboration_Checks => -1,
13989 Pragma_Eliminate => -1,
13990 Pragma_Export => -1,
13991 Pragma_Export_Exception => -1,
13992 Pragma_Export_Function => -1,
13993 Pragma_Export_Object => -1,
13994 Pragma_Export_Procedure => -1,
13995 Pragma_Export_Value => -1,
13996 Pragma_Export_Valued_Procedure => -1,
13997 Pragma_Extend_System => -1,
13998 Pragma_Extensions_Allowed => -1,
13999 Pragma_External => -1,
14000 Pragma_Favor_Top_Level => -1,
14001 Pragma_External_Name_Casing => -1,
14002 Pragma_Fast_Math => -1,
14003 Pragma_Finalize_Storage_Only => 0,
14004 Pragma_Float_Representation => 0,
14005 Pragma_Ident => -1,
14006 Pragma_Implemented => -1,
14007 Pragma_Implicit_Packing => 0,
14008 Pragma_Import => +2,
14009 Pragma_Import_Exception => 0,
14010 Pragma_Import_Function => 0,
14011 Pragma_Import_Object => 0,
14012 Pragma_Import_Procedure => 0,
14013 Pragma_Import_Valued_Procedure => 0,
14014 Pragma_Independent => 0,
14015 Pragma_Independent_Components => 0,
14016 Pragma_Initialize_Scalars => -1,
14017 Pragma_Inline => 0,
14018 Pragma_Inline_Always => 0,
14019 Pragma_Inline_Generic => 0,
14020 Pragma_Inspection_Point => -1,
14021 Pragma_Interface => +2,
14022 Pragma_Interface_Name => +2,
14023 Pragma_Interrupt_Handler => -1,
14024 Pragma_Interrupt_Priority => -1,
14025 Pragma_Interrupt_State => -1,
14026 Pragma_Invariant => -1,
14027 Pragma_Java_Constructor => -1,
14028 Pragma_Java_Interface => -1,
14029 Pragma_Keep_Names => 0,
14030 Pragma_License => -1,
14031 Pragma_Link_With => -1,
14032 Pragma_Linker_Alias => -1,
14033 Pragma_Linker_Constructor => -1,
14034 Pragma_Linker_Destructor => -1,
14035 Pragma_Linker_Options => -1,
14036 Pragma_Linker_Section => -1,
14038 Pragma_Locking_Policy => -1,
14039 Pragma_Long_Float => -1,
14040 Pragma_Machine_Attribute => -1,
14042 Pragma_Main_Storage => -1,
14043 Pragma_Memory_Size => -1,
14044 Pragma_No_Return => 0,
14045 Pragma_No_Body => 0,
14046 Pragma_No_Run_Time => -1,
14047 Pragma_No_Strict_Aliasing => -1,
14048 Pragma_Normalize_Scalars => -1,
14049 Pragma_Obsolescent => 0,
14050 Pragma_Optimize => -1,
14051 Pragma_Optimize_Alignment => -1,
14052 Pragma_Ordered => 0,
14055 Pragma_Passive => -1,
14056 Pragma_Preelaborable_Initialization => -1,
14057 Pragma_Polling => -1,
14058 Pragma_Persistent_BSS => 0,
14059 Pragma_Postcondition => -1,
14060 Pragma_Precondition => -1,
14061 Pragma_Predicate => -1,
14062 Pragma_Preelaborate => -1,
14063 Pragma_Preelaborate_05 => -1,
14064 Pragma_Priority => -1,
14065 Pragma_Priority_Specific_Dispatching => -1,
14066 Pragma_Profile => 0,
14067 Pragma_Profile_Warnings => 0,
14068 Pragma_Propagate_Exceptions => -1,
14069 Pragma_Psect_Object => -1,
14071 Pragma_Pure_05 => -1,
14072 Pragma_Pure_Function => -1,
14073 Pragma_Queuing_Policy => -1,
14074 Pragma_Ravenscar => -1,
14075 Pragma_Relative_Deadline => -1,
14076 Pragma_Remote_Call_Interface => -1,
14077 Pragma_Remote_Types => -1,
14078 Pragma_Restricted_Run_Time => -1,
14079 Pragma_Restriction_Warnings => -1,
14080 Pragma_Restrictions => -1,
14081 Pragma_Reviewable => -1,
14082 Pragma_Short_Circuit_And_Or => -1,
14083 Pragma_Share_Generic => -1,
14084 Pragma_Shared => -1,
14085 Pragma_Shared_Passive => -1,
14086 Pragma_Short_Descriptors => 0,
14087 Pragma_Source_File_Name => -1,
14088 Pragma_Source_File_Name_Project => -1,
14089 Pragma_Source_Reference => -1,
14090 Pragma_Storage_Size => -1,
14091 Pragma_Storage_Unit => -1,
14092 Pragma_Static_Elaboration_Desired => -1,
14093 Pragma_Stream_Convert => -1,
14094 Pragma_Style_Checks => -1,
14095 Pragma_Subtitle => -1,
14096 Pragma_Suppress => 0,
14097 Pragma_Suppress_Exception_Locations => 0,
14098 Pragma_Suppress_All => -1,
14099 Pragma_Suppress_Debug_Info => 0,
14100 Pragma_Suppress_Initialization => 0,
14101 Pragma_System_Name => -1,
14102 Pragma_Task_Dispatching_Policy => -1,
14103 Pragma_Task_Info => -1,
14104 Pragma_Task_Name => -1,
14105 Pragma_Task_Storage => 0,
14106 Pragma_Thread_Local_Storage => 0,
14107 Pragma_Time_Slice => -1,
14108 Pragma_Title => -1,
14109 Pragma_Unchecked_Union => 0,
14110 Pragma_Unimplemented_Unit => -1,
14111 Pragma_Universal_Aliasing => -1,
14112 Pragma_Universal_Data => -1,
14113 Pragma_Unmodified => -1,
14114 Pragma_Unreferenced => -1,
14115 Pragma_Unreferenced_Objects => -1,
14116 Pragma_Unreserve_All_Interrupts => -1,
14117 Pragma_Unsuppress => 0,
14118 Pragma_Use_VADS_Size => -1,
14119 Pragma_Validity_Checks => -1,
14120 Pragma_Volatile => 0,
14121 Pragma_Volatile_Components => 0,
14122 Pragma_Warnings => -1,
14123 Pragma_Weak_External => -1,
14124 Pragma_Wide_Character_Encoding => 0,
14125 Unknown_Pragma => 0);
14127 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14136 if Nkind (P) /= N_Pragma_Argument_Association then
14140 Id := Get_Pragma_Id (Parent (P));
14141 C := Sig_Flags (Id);
14153 -- For pragma Check, the first argument is not significant,
14154 -- the second and the third (if present) arguments are
14157 when Pragma_Check =>
14159 P = First (Pragma_Argument_Associations (Parent (P)));
14162 raise Program_Error;
14166 A := First (Pragma_Argument_Associations (Parent (P)));
14167 for J in 1 .. C - 1 loop
14175 return A = P; -- is this wrong way round ???
14178 end Is_Non_Significant_Pragma_Reference;
14180 ------------------------------
14181 -- Is_Pragma_String_Literal --
14182 ------------------------------
14184 -- This function returns true if the corresponding pragma argument is a
14185 -- static string expression. These are the only cases in which string
14186 -- literals can appear as pragma arguments. We also allow a string literal
14187 -- as the first argument to pragma Assert (although it will of course
14188 -- always generate a type error).
14190 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14191 Pragn : constant Node_Id := Parent (Par);
14192 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14193 Pname : constant Name_Id := Pragma_Name (Pragn);
14199 N := First (Assoc);
14206 if Pname = Name_Assert then
14209 elsif Pname = Name_Export then
14212 elsif Pname = Name_Ident then
14215 elsif Pname = Name_Import then
14218 elsif Pname = Name_Interface_Name then
14221 elsif Pname = Name_Linker_Alias then
14224 elsif Pname = Name_Linker_Section then
14227 elsif Pname = Name_Machine_Attribute then
14230 elsif Pname = Name_Source_File_Name then
14233 elsif Pname = Name_Source_Reference then
14236 elsif Pname = Name_Title then
14239 elsif Pname = Name_Subtitle then
14245 end Is_Pragma_String_Literal;
14247 --------------------------------------
14248 -- Process_Compilation_Unit_Pragmas --
14249 --------------------------------------
14251 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14253 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14254 -- strange because it comes at the end of the unit. Rational has the
14255 -- same name for a pragma, but treats it as a program unit pragma, In
14256 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14257 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14258 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14259 -- the context clause to ensure the correct processing.
14261 if Has_Pragma_Suppress_All (N) then
14262 Prepend_To (Context_Items (N),
14263 Make_Pragma (Sloc (N),
14264 Chars => Name_Suppress,
14265 Pragma_Argument_Associations => New_List (
14266 Make_Pragma_Argument_Association (Sloc (N),
14267 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14270 -- Nothing else to do at the current time!
14272 end Process_Compilation_Unit_Pragmas;
14283 --------------------------------
14284 -- Set_Encoded_Interface_Name --
14285 --------------------------------
14287 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14288 Str : constant String_Id := Strval (S);
14289 Len : constant Int := String_Length (Str);
14294 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14297 -- Stores encoded value of character code CC. The encoding we use an
14298 -- underscore followed by four lower case hex digits.
14304 procedure Encode is
14306 Store_String_Char (Get_Char_Code ('_'));
14308 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14310 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14312 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14314 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14317 -- Start of processing for Set_Encoded_Interface_Name
14320 -- If first character is asterisk, this is a link name, and we leave it
14321 -- completely unmodified. We also ignore null strings (the latter case
14322 -- happens only in error cases) and no encoding should occur for Java or
14323 -- AAMP interface names.
14326 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14327 or else VM_Target /= No_VM
14328 or else AAMP_On_Target
14330 Set_Interface_Name (E, S);
14335 CC := Get_String_Char (Str, J);
14337 exit when not In_Character_Range (CC);
14339 C := Get_Character (CC);
14341 exit when C /= '_' and then C /= '$'
14342 and then C not in '0' .. '9'
14343 and then C not in 'a' .. 'z'
14344 and then C not in 'A' .. 'Z';
14347 Set_Interface_Name (E, S);
14355 -- Here we need to encode. The encoding we use as follows:
14356 -- three underscores + four hex digits (lower case)
14360 for J in 1 .. String_Length (Str) loop
14361 CC := Get_String_Char (Str, J);
14363 if not In_Character_Range (CC) then
14366 C := Get_Character (CC);
14368 if C = '_' or else C = '$'
14369 or else C in '0' .. '9'
14370 or else C in 'a' .. 'z'
14371 or else C in 'A' .. 'Z'
14373 Store_String_Char (CC);
14380 Set_Interface_Name (E,
14381 Make_String_Literal (Sloc (S),
14382 Strval => End_String));
14384 end Set_Encoded_Interface_Name;
14386 -------------------
14387 -- Set_Unit_Name --
14388 -------------------
14390 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14395 if Nkind (N) = N_Identifier
14396 and then Nkind (With_Item) = N_Identifier
14398 Set_Entity (N, Entity (With_Item));
14400 elsif Nkind (N) = N_Selected_Component then
14401 Change_Selected_Component_To_Expanded_Name (N);
14402 Set_Entity (N, Entity (With_Item));
14403 Set_Entity (Selector_Name (N), Entity (N));
14405 Pref := Prefix (N);
14406 Scop := Scope (Entity (N));
14407 while Nkind (Pref) = N_Selected_Component loop
14408 Change_Selected_Component_To_Expanded_Name (Pref);
14409 Set_Entity (Selector_Name (Pref), Scop);
14410 Set_Entity (Pref, Scop);
14411 Pref := Prefix (Pref);
14412 Scop := Scope (Scop);
14415 Set_Entity (Pref, Scop);