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);
3868 Ftyp : Node_Id := First (Predefined_Float_Types);
3873 String_To_Name_Buffer (Strval (Expression (Arg3)));
3876 while Present (Ftyp) and then Chars (Ftyp) /= Nam loop
3880 if Present (Ftyp) then
3881 -- Don't build a derived type declaration, because predefined C
3882 -- types have no declaration anywhere, so cannot really be named.
3883 -- Instead build a full type declaration, starting with an
3884 -- appropriate type definition is built
3886 if Is_Floating_Point_Type (Ftyp) then
3887 Def := Make_Floating_Point_Definition (Loc,
3888 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
3889 Make_Real_Range_Specification (Loc,
3890 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
3891 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
3894 -- Should never have a predefined type we cannot handle
3895 raise Program_Error;
3898 -- Build and insert a Full_Type_Declaration, which will be
3899 -- analyzed as soon as this list entry has been analyzed.
3901 Decl := Make_Full_Type_Declaration (Loc,
3902 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
3903 Type_Definition => Def);
3905 Insert_After (N, Decl);
3906 Mark_Rewrite_Insertion (Decl);
3909 Error_Pragma_Arg ("no matching type found for pragma%",
3912 end Process_Import_Predefined_Type;
3914 ---------------------------------
3915 -- Process_Import_Or_Interface --
3916 ---------------------------------
3918 procedure Process_Import_Or_Interface is
3924 Process_Convention (C, Def_Id);
3925 Kill_Size_Check_Code (Def_Id);
3926 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
3928 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3930 -- We do not permit Import to apply to a renaming declaration
3932 if Present (Renamed_Object (Def_Id)) then
3934 ("pragma% not allowed for object renaming", Arg2);
3936 -- User initialization is not allowed for imported object, but
3937 -- the object declaration may contain a default initialization,
3938 -- that will be discarded. Note that an explicit initialization
3939 -- only counts if it comes from source, otherwise it is simply
3940 -- the code generator making an implicit initialization explicit.
3942 elsif Present (Expression (Parent (Def_Id)))
3943 and then Comes_From_Source (Expression (Parent (Def_Id)))
3945 Error_Msg_Sloc := Sloc (Def_Id);
3947 ("no initialization allowed for declaration of& #",
3948 "\imported entities cannot be initialized (RM B.1(24))",
3952 Set_Imported (Def_Id);
3953 Process_Interface_Name (Def_Id, Arg3, Arg4);
3955 -- Note that we do not set Is_Public here. That's because we
3956 -- only want to set it if there is no address clause, and we
3957 -- don't know that yet, so we delay that processing till
3960 -- pragma Import completes deferred constants
3962 if Ekind (Def_Id) = E_Constant then
3963 Set_Has_Completion (Def_Id);
3966 -- It is not possible to import a constant of an unconstrained
3967 -- array type (e.g. string) because there is no simple way to
3968 -- write a meaningful subtype for it.
3970 if Is_Array_Type (Etype (Def_Id))
3971 and then not Is_Constrained (Etype (Def_Id))
3974 ("imported constant& must have a constrained subtype",
3979 elsif Is_Subprogram (Def_Id)
3980 or else Is_Generic_Subprogram (Def_Id)
3982 -- If the name is overloaded, pragma applies to all of the denoted
3983 -- entities in the same declarative part.
3986 while Present (Hom_Id) loop
3987 Def_Id := Get_Base_Subprogram (Hom_Id);
3989 -- Ignore inherited subprograms because the pragma will apply
3990 -- to the parent operation, which is the one called.
3992 if Is_Overloadable (Def_Id)
3993 and then Present (Alias (Def_Id))
3997 -- If it is not a subprogram, it must be in an outer scope and
3998 -- pragma does not apply.
4000 elsif not Is_Subprogram (Def_Id)
4001 and then not Is_Generic_Subprogram (Def_Id)
4005 -- The pragma does not apply to primitives of interfaces
4007 elsif Is_Dispatching_Operation (Def_Id)
4008 and then Present (Find_Dispatching_Type (Def_Id))
4009 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4013 -- Verify that the homonym is in the same declarative part (not
4014 -- just the same scope).
4016 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4017 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4022 Set_Imported (Def_Id);
4024 -- Reject an Import applied to an abstract subprogram
4026 if Is_Subprogram (Def_Id)
4027 and then Is_Abstract_Subprogram (Def_Id)
4029 Error_Msg_Sloc := Sloc (Def_Id);
4031 ("cannot import abstract subprogram& declared#",
4035 -- Special processing for Convention_Intrinsic
4037 if C = Convention_Intrinsic then
4039 -- Link_Name argument not allowed for intrinsic
4043 Set_Is_Intrinsic_Subprogram (Def_Id);
4045 -- If no external name is present, then check that this
4046 -- is a valid intrinsic subprogram. If an external name
4047 -- is present, then this is handled by the back end.
4050 Check_Intrinsic_Subprogram
4051 (Def_Id, Get_Pragma_Arg (Arg2));
4055 -- All interfaced procedures need an external symbol created
4056 -- for them since they are always referenced from another
4059 Set_Is_Public (Def_Id);
4061 -- Verify that the subprogram does not have a completion
4062 -- through a renaming declaration. For other completions the
4063 -- pragma appears as a too late representation.
4066 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4070 and then Nkind (Decl) = N_Subprogram_Declaration
4071 and then Present (Corresponding_Body (Decl))
4072 and then Nkind (Unit_Declaration_Node
4073 (Corresponding_Body (Decl))) =
4074 N_Subprogram_Renaming_Declaration
4076 Error_Msg_Sloc := Sloc (Def_Id);
4078 ("cannot import&, renaming already provided for " &
4079 "declaration #", N, Def_Id);
4083 Set_Has_Completion (Def_Id);
4084 Process_Interface_Name (Def_Id, Arg3, Arg4);
4087 if Is_Compilation_Unit (Hom_Id) then
4089 -- Its possible homonyms are not affected by the pragma.
4090 -- Such homonyms might be present in the context of other
4091 -- units being compiled.
4096 Hom_Id := Homonym (Hom_Id);
4100 -- When the convention is Java or CIL, we also allow Import to be
4101 -- given for packages, generic packages, exceptions, record
4102 -- components, and access to subprograms.
4104 elsif (C = Convention_Java or else C = Convention_CIL)
4106 (Is_Package_Or_Generic_Package (Def_Id)
4107 or else Ekind (Def_Id) = E_Exception
4108 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4109 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4111 Set_Imported (Def_Id);
4112 Set_Is_Public (Def_Id);
4113 Process_Interface_Name (Def_Id, Arg3, Arg4);
4115 -- Import a CPP class
4117 elsif Is_Record_Type (Def_Id)
4118 and then C = Convention_CPP
4120 -- Types treated as CPP classes are treated as limited, but we
4121 -- don't require them to be declared this way. A warning is issued
4122 -- to encourage the user to declare them as limited. This is not
4123 -- an error, for compatibility reasons, because these types have
4124 -- been supported this way for some time.
4126 if not Is_Limited_Type (Def_Id) then
4128 ("imported 'C'P'P type should be " &
4129 "explicitly declared limited?",
4130 Get_Pragma_Arg (Arg2));
4132 ("\type will be considered limited",
4133 Get_Pragma_Arg (Arg2));
4136 Set_Is_CPP_Class (Def_Id);
4137 Set_Is_Limited_Record (Def_Id);
4139 -- Imported CPP types must not have discriminants (because C++
4140 -- classes do not have discriminants).
4142 if Has_Discriminants (Def_Id) then
4144 ("imported 'C'P'P type cannot have discriminants",
4145 First (Discriminant_Specifications
4146 (Declaration_Node (Def_Id))));
4149 -- Components of imported CPP types must not have default
4150 -- expressions because the constructor (if any) is on the
4154 Tdef : constant Node_Id :=
4155 Type_Definition (Declaration_Node (Def_Id));
4160 if Nkind (Tdef) = N_Record_Definition then
4161 Clist := Component_List (Tdef);
4164 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4165 Clist := Component_List (Record_Extension_Part (Tdef));
4168 if Present (Clist) then
4169 Comp := First (Component_Items (Clist));
4170 while Present (Comp) loop
4171 if Present (Expression (Comp)) then
4173 ("component of imported 'C'P'P type cannot have" &
4174 " default expression", Expression (Comp));
4182 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4184 Check_Arg_Count (3);
4185 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4187 Process_Import_Predefined_Type;
4191 ("second argument of pragma% must be object, subprogram" &
4192 " or incomplete type",
4196 -- If this pragma applies to a compilation unit, then the unit, which
4197 -- is a subprogram, does not require (or allow) a body. We also do
4198 -- not need to elaborate imported procedures.
4200 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4202 Cunit : constant Node_Id := Parent (Parent (N));
4204 Set_Body_Required (Cunit, False);
4207 end Process_Import_Or_Interface;
4209 --------------------
4210 -- Process_Inline --
4211 --------------------
4213 procedure Process_Inline (Active : Boolean) is
4220 Effective : Boolean := False;
4221 -- Set True if inline has some effect, i.e. if there is at least one
4222 -- subprogram set as inlined as a result of the use of the pragma.
4224 procedure Make_Inline (Subp : Entity_Id);
4225 -- Subp is the defining unit name of the subprogram declaration. Set
4226 -- the flag, as well as the flag in the corresponding body, if there
4229 procedure Set_Inline_Flags (Subp : Entity_Id);
4230 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4231 -- Has_Pragma_Inline_Always for the Inline_Always case.
4233 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4234 -- Returns True if it can be determined at this stage that inlining
4235 -- is not possible, for example if the body is available and contains
4236 -- exception handlers, we prevent inlining, since otherwise we can
4237 -- get undefined symbols at link time. This function also emits a
4238 -- warning if front-end inlining is enabled and the pragma appears
4241 -- ??? is business with link symbols still valid, or does it relate
4242 -- to front end ZCX which is being phased out ???
4244 ---------------------------
4245 -- Inlining_Not_Possible --
4246 ---------------------------
4248 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4249 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4253 if Nkind (Decl) = N_Subprogram_Body then
4254 Stats := Handled_Statement_Sequence (Decl);
4255 return Present (Exception_Handlers (Stats))
4256 or else Present (At_End_Proc (Stats));
4258 elsif Nkind (Decl) = N_Subprogram_Declaration
4259 and then Present (Corresponding_Body (Decl))
4261 if Front_End_Inlining
4262 and then Analyzed (Corresponding_Body (Decl))
4264 Error_Msg_N ("pragma appears too late, ignored?", N);
4267 -- If the subprogram is a renaming as body, the body is just a
4268 -- call to the renamed subprogram, and inlining is trivially
4272 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4273 N_Subprogram_Renaming_Declaration
4279 Handled_Statement_Sequence
4280 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4283 Present (Exception_Handlers (Stats))
4284 or else Present (At_End_Proc (Stats));
4288 -- If body is not available, assume the best, the check is
4289 -- performed again when compiling enclosing package bodies.
4293 end Inlining_Not_Possible;
4299 procedure Make_Inline (Subp : Entity_Id) is
4300 Kind : constant Entity_Kind := Ekind (Subp);
4301 Inner_Subp : Entity_Id := Subp;
4304 -- Ignore if bad type, avoid cascaded error
4306 if Etype (Subp) = Any_Type then
4310 -- Ignore if all inlining is suppressed
4312 elsif Suppress_All_Inlining then
4316 -- If inlining is not possible, for now do not treat as an error
4318 elsif Inlining_Not_Possible (Subp) then
4322 -- Here we have a candidate for inlining, but we must exclude
4323 -- derived operations. Otherwise we would end up trying to inline
4324 -- a phantom declaration, and the result would be to drag in a
4325 -- body which has no direct inlining associated with it. That
4326 -- would not only be inefficient but would also result in the
4327 -- backend doing cross-unit inlining in cases where it was
4328 -- definitely inappropriate to do so.
4330 -- However, a simple Comes_From_Source test is insufficient, since
4331 -- we do want to allow inlining of generic instances which also do
4332 -- not come from source. We also need to recognize specs generated
4333 -- by the front-end for bodies that carry the pragma. Finally,
4334 -- predefined operators do not come from source but are not
4335 -- inlineable either.
4337 elsif Is_Generic_Instance (Subp)
4338 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4342 elsif not Comes_From_Source (Subp)
4343 and then Scope (Subp) /= Standard_Standard
4349 -- The referenced entity must either be the enclosing entity, or
4350 -- an entity declared within the current open scope.
4352 if Present (Scope (Subp))
4353 and then Scope (Subp) /= Current_Scope
4354 and then Subp /= Current_Scope
4357 ("argument of% must be entity in current scope", Assoc);
4361 -- Processing for procedure, operator or function. If subprogram
4362 -- is aliased (as for an instance) indicate that the renamed
4363 -- entity (if declared in the same unit) is inlined.
4365 if Is_Subprogram (Subp) then
4366 Inner_Subp := Ultimate_Alias (Inner_Subp);
4368 if In_Same_Source_Unit (Subp, Inner_Subp) then
4369 Set_Inline_Flags (Inner_Subp);
4371 Decl := Parent (Parent (Inner_Subp));
4373 if Nkind (Decl) = N_Subprogram_Declaration
4374 and then Present (Corresponding_Body (Decl))
4376 Set_Inline_Flags (Corresponding_Body (Decl));
4378 elsif Is_Generic_Instance (Subp) then
4380 -- Indicate that the body needs to be created for
4381 -- inlining subsequent calls. The instantiation node
4382 -- follows the declaration of the wrapper package
4385 if Scope (Subp) /= Standard_Standard
4387 Need_Subprogram_Instance_Body
4388 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4398 -- For a generic subprogram set flag as well, for use at the point
4399 -- of instantiation, to determine whether the body should be
4402 elsif Is_Generic_Subprogram (Subp) then
4403 Set_Inline_Flags (Subp);
4406 -- Literals are by definition inlined
4408 elsif Kind = E_Enumeration_Literal then
4411 -- Anything else is an error
4415 ("expect subprogram name for pragma%", Assoc);
4419 ----------------------
4420 -- Set_Inline_Flags --
4421 ----------------------
4423 procedure Set_Inline_Flags (Subp : Entity_Id) is
4426 Set_Is_Inlined (Subp);
4429 if not Has_Pragma_Inline (Subp) then
4430 Set_Has_Pragma_Inline (Subp);
4434 if Prag_Id = Pragma_Inline_Always then
4435 Set_Has_Pragma_Inline_Always (Subp);
4437 end Set_Inline_Flags;
4439 -- Start of processing for Process_Inline
4442 Check_No_Identifiers;
4443 Check_At_Least_N_Arguments (1);
4446 Inline_Processing_Required := True;
4450 while Present (Assoc) loop
4451 Subp_Id := Get_Pragma_Arg (Assoc);
4455 if Is_Entity_Name (Subp_Id) then
4456 Subp := Entity (Subp_Id);
4458 if Subp = Any_Id then
4460 -- If previous error, avoid cascaded errors
4468 -- For the pragma case, climb homonym chain. This is
4469 -- what implements allowing the pragma in the renaming
4470 -- case, with the result applying to the ancestors.
4472 if not From_Aspect_Specification (N) then
4473 while Present (Homonym (Subp))
4474 and then Scope (Homonym (Subp)) = Current_Scope
4476 Make_Inline (Homonym (Subp));
4477 Subp := Homonym (Subp);
4485 ("inappropriate argument for pragma%", Assoc);
4488 and then Warn_On_Redundant_Constructs
4489 and then not Suppress_All_Inlining
4491 if Inlining_Not_Possible (Subp) then
4493 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4496 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4504 ----------------------------
4505 -- Process_Interface_Name --
4506 ----------------------------
4508 procedure Process_Interface_Name
4509 (Subprogram_Def : Entity_Id;
4515 String_Val : String_Id;
4517 procedure Check_Form_Of_Interface_Name
4519 Ext_Name_Case : Boolean);
4520 -- SN is a string literal node for an interface name. This routine
4521 -- performs some minimal checks that the name is reasonable. In
4522 -- particular that no spaces or other obviously incorrect characters
4523 -- appear. This is only a warning, since any characters are allowed.
4524 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4526 ----------------------------------
4527 -- Check_Form_Of_Interface_Name --
4528 ----------------------------------
4530 procedure Check_Form_Of_Interface_Name
4532 Ext_Name_Case : Boolean)
4534 S : constant String_Id := Strval (Expr_Value_S (SN));
4535 SL : constant Nat := String_Length (S);
4540 Error_Msg_N ("interface name cannot be null string", SN);
4543 for J in 1 .. SL loop
4544 C := Get_String_Char (S, J);
4546 -- Look for dubious character and issue unconditional warning.
4547 -- Definitely dubious if not in character range.
4549 if not In_Character_Range (C)
4551 -- For all cases except CLI target,
4552 -- commas, spaces and slashes are dubious (in CLI, we use
4553 -- commas and backslashes in external names to specify
4554 -- assembly version and public key, while slashes and spaces
4555 -- can be used in names to mark nested classes and
4558 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4559 and then (Get_Character (C) = ','
4561 Get_Character (C) = '\'))
4562 or else (VM_Target /= CLI_Target
4563 and then (Get_Character (C) = ' '
4565 Get_Character (C) = '/'))
4568 ("?interface name contains illegal character",
4569 Sloc (SN) + Source_Ptr (J));
4572 end Check_Form_Of_Interface_Name;
4574 -- Start of processing for Process_Interface_Name
4577 if No (Link_Arg) then
4578 if No (Ext_Arg) then
4579 if VM_Target = CLI_Target
4580 and then Ekind (Subprogram_Def) = E_Package
4581 and then Nkind (Parent (Subprogram_Def)) =
4582 N_Package_Specification
4583 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4588 (Generic_Parent (Parent (Subprogram_Def))));
4593 elsif Chars (Ext_Arg) = Name_Link_Name then
4595 Link_Nam := Expression (Ext_Arg);
4598 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4599 Ext_Nam := Expression (Ext_Arg);
4604 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4605 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4606 Ext_Nam := Expression (Ext_Arg);
4607 Link_Nam := Expression (Link_Arg);
4610 -- Check expressions for external name and link name are static
4612 if Present (Ext_Nam) then
4613 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4614 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4616 -- Verify that external name is not the name of a local entity,
4617 -- which would hide the imported one and could lead to run-time
4618 -- surprises. The problem can only arise for entities declared in
4619 -- a package body (otherwise the external name is fully qualified
4620 -- and will not conflict).
4628 if Prag_Id = Pragma_Import then
4629 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4631 E := Entity_Id (Get_Name_Table_Info (Nam));
4633 if Nam /= Chars (Subprogram_Def)
4634 and then Present (E)
4635 and then not Is_Overloadable (E)
4636 and then Is_Immediately_Visible (E)
4637 and then not Is_Imported (E)
4638 and then Ekind (Scope (E)) = E_Package
4641 while Present (Par) loop
4642 if Nkind (Par) = N_Package_Body then
4643 Error_Msg_Sloc := Sloc (E);
4645 ("imported entity is hidden by & declared#",
4650 Par := Parent (Par);
4657 if Present (Link_Nam) then
4658 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4659 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4662 -- If there is no link name, just set the external name
4664 if No (Link_Nam) then
4665 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4667 -- For the Link_Name case, the given literal is preceded by an
4668 -- asterisk, which indicates to GCC that the given name should be
4669 -- taken literally, and in particular that no prepending of
4670 -- underlines should occur, even in systems where this is the
4676 if VM_Target = No_VM then
4677 Store_String_Char (Get_Char_Code ('*'));
4680 String_Val := Strval (Expr_Value_S (Link_Nam));
4681 Store_String_Chars (String_Val);
4683 Make_String_Literal (Sloc (Link_Nam),
4684 Strval => End_String);
4687 Set_Encoded_Interface_Name
4688 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4690 -- We allow duplicated export names in CIL, as they are always
4691 -- enclosed in a namespace that differentiates them, and overloaded
4692 -- entities are supported by the VM.
4694 if Convention (Subprogram_Def) /= Convention_CIL then
4695 Check_Duplicated_Export_Name (Link_Nam);
4697 end Process_Interface_Name;
4699 -----------------------------------------
4700 -- Process_Interrupt_Or_Attach_Handler --
4701 -----------------------------------------
4703 procedure Process_Interrupt_Or_Attach_Handler is
4704 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4705 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4706 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4709 Set_Is_Interrupt_Handler (Handler_Proc);
4711 -- If the pragma is not associated with a handler procedure within a
4712 -- protected type, then it must be for a nonprotected procedure for
4713 -- the AAMP target, in which case we don't associate a representation
4714 -- item with the procedure's scope.
4716 if Ekind (Proc_Scope) = E_Protected_Type then
4717 if Prag_Id = Pragma_Interrupt_Handler
4719 Prag_Id = Pragma_Attach_Handler
4721 Record_Rep_Item (Proc_Scope, N);
4724 end Process_Interrupt_Or_Attach_Handler;
4726 --------------------------------------------------
4727 -- Process_Restrictions_Or_Restriction_Warnings --
4728 --------------------------------------------------
4730 -- Note: some of the simple identifier cases were handled in par-prag,
4731 -- but it is harmless (and more straightforward) to simply handle all
4732 -- cases here, even if it means we repeat a bit of work in some cases.
4734 procedure Process_Restrictions_Or_Restriction_Warnings
4738 R_Id : Restriction_Id;
4743 procedure Check_Unit_Name (N : Node_Id);
4744 -- Checks unit name parameter for No_Dependence. Returns if it has
4745 -- an appropriate form, otherwise raises pragma argument error.
4747 ---------------------
4748 -- Check_Unit_Name --
4749 ---------------------
4751 procedure Check_Unit_Name (N : Node_Id) is
4753 if Nkind (N) = N_Selected_Component then
4754 Check_Unit_Name (Prefix (N));
4755 Check_Unit_Name (Selector_Name (N));
4757 elsif Nkind (N) = N_Identifier then
4762 ("wrong form for unit name for No_Dependence", N);
4764 end Check_Unit_Name;
4766 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4769 -- Ignore all Restrictions pragma in CodePeer mode
4771 if CodePeer_Mode then
4775 Check_Ada_83_Warning;
4776 Check_At_Least_N_Arguments (1);
4777 Check_Valid_Configuration_Pragma;
4780 while Present (Arg) loop
4782 Expr := Get_Pragma_Arg (Arg);
4784 -- Case of no restriction identifier present
4786 if Id = No_Name then
4787 if Nkind (Expr) /= N_Identifier then
4789 ("invalid form for restriction", Arg);
4794 (Process_Restriction_Synonyms (Expr));
4796 if R_Id not in All_Boolean_Restrictions then
4797 Error_Msg_Name_1 := Pname;
4799 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4801 -- Check for possible misspelling
4803 for J in Restriction_Id loop
4805 Rnm : constant String := Restriction_Id'Image (J);
4808 Name_Buffer (1 .. Rnm'Length) := Rnm;
4809 Name_Len := Rnm'Length;
4810 Set_Casing (All_Lower_Case);
4812 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4814 (Identifier_Casing (Current_Source_File));
4815 Error_Msg_String (1 .. Rnm'Length) :=
4816 Name_Buffer (1 .. Name_Len);
4817 Error_Msg_Strlen := Rnm'Length;
4818 Error_Msg_N -- CODEFIX
4819 ("\possible misspelling of ""~""",
4820 Get_Pragma_Arg (Arg));
4829 if Implementation_Restriction (R_Id) then
4830 Check_Restriction (No_Implementation_Restrictions, Arg);
4833 -- If this is a warning, then set the warning unless we already
4834 -- have a real restriction active (we never want a warning to
4835 -- override a real restriction).
4838 if not Restriction_Active (R_Id) then
4839 Set_Restriction (R_Id, N);
4840 Restriction_Warnings (R_Id) := True;
4843 -- If real restriction case, then set it and make sure that the
4844 -- restriction warning flag is off, since a real restriction
4845 -- always overrides a warning.
4848 Set_Restriction (R_Id, N);
4849 Restriction_Warnings (R_Id) := False;
4852 -- Check for obsolescent restrictions in Ada 2005 mode
4855 and then Ada_Version >= Ada_2005
4856 and then (R_Id = No_Asynchronous_Control
4858 R_Id = No_Unchecked_Deallocation
4860 R_Id = No_Unchecked_Conversion)
4862 Check_Restriction (No_Obsolescent_Features, N);
4865 -- A very special case that must be processed here: pragma
4866 -- Restrictions (No_Exceptions) turns off all run-time
4867 -- checking. This is a bit dubious in terms of the formal
4868 -- language definition, but it is what is intended by RM
4869 -- H.4(12). Restriction_Warnings never affects generated code
4870 -- so this is done only in the real restriction case.
4872 if R_Id = No_Exceptions and then not Warn then
4873 Scope_Suppress := (others => True);
4876 -- Case of No_Dependence => unit-name. Note that the parser
4877 -- already made the necessary entry in the No_Dependence table.
4879 elsif Id = Name_No_Dependence then
4880 Check_Unit_Name (Expr);
4882 -- All other cases of restriction identifier present
4885 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4886 Analyze_And_Resolve (Expr, Any_Integer);
4888 if R_Id not in All_Parameter_Restrictions then
4890 ("invalid restriction parameter identifier", Arg);
4892 elsif not Is_OK_Static_Expression (Expr) then
4893 Flag_Non_Static_Expr
4894 ("value must be static expression!", Expr);
4897 elsif not Is_Integer_Type (Etype (Expr))
4898 or else Expr_Value (Expr) < 0
4901 ("value must be non-negative integer", Arg);
4904 -- Restriction pragma is active
4906 Val := Expr_Value (Expr);
4908 if not UI_Is_In_Int_Range (Val) then
4910 ("pragma ignored, value too large?", Arg);
4913 -- Warning case. If the real restriction is active, then we
4914 -- ignore the request, since warning never overrides a real
4915 -- restriction. Otherwise we set the proper warning. Note that
4916 -- this circuit sets the warning again if it is already set,
4917 -- which is what we want, since the constant may have changed.
4920 if not Restriction_Active (R_Id) then
4922 (R_Id, N, Integer (UI_To_Int (Val)));
4923 Restriction_Warnings (R_Id) := True;
4926 -- Real restriction case, set restriction and make sure warning
4927 -- flag is off since real restriction always overrides warning.
4930 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4931 Restriction_Warnings (R_Id) := False;
4937 end Process_Restrictions_Or_Restriction_Warnings;
4939 ---------------------------------
4940 -- Process_Suppress_Unsuppress --
4941 ---------------------------------
4943 -- Note: this procedure makes entries in the check suppress data
4944 -- structures managed by Sem. See spec of package Sem for full
4945 -- details on how we handle recording of check suppression.
4947 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4952 In_Package_Spec : constant Boolean :=
4953 Is_Package_Or_Generic_Package (Current_Scope)
4954 and then not In_Package_Body (Current_Scope);
4956 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4957 -- Used to suppress a single check on the given entity
4959 --------------------------------
4960 -- Suppress_Unsuppress_Echeck --
4961 --------------------------------
4963 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4965 Set_Checks_May_Be_Suppressed (E);
4967 if In_Package_Spec then
4968 Push_Global_Suppress_Stack_Entry
4971 Suppress => Suppress_Case);
4974 Push_Local_Suppress_Stack_Entry
4977 Suppress => Suppress_Case);
4980 -- If this is a first subtype, and the base type is distinct,
4981 -- then also set the suppress flags on the base type.
4983 if Is_First_Subtype (E)
4984 and then Etype (E) /= E
4986 Suppress_Unsuppress_Echeck (Etype (E), C);
4988 end Suppress_Unsuppress_Echeck;
4990 -- Start of processing for Process_Suppress_Unsuppress
4993 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
4994 -- we want to generate checks for analysis purposes, as set by -gnatC
4996 if CodePeer_Mode and then Comes_From_Source (N) then
5000 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5001 -- declarative part or a package spec (RM 11.5(5)).
5003 if not Is_Configuration_Pragma then
5004 Check_Is_In_Decl_Part_Or_Package_Spec;
5007 Check_At_Least_N_Arguments (1);
5008 Check_At_Most_N_Arguments (2);
5009 Check_No_Identifier (Arg1);
5010 Check_Arg_Is_Identifier (Arg1);
5012 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5014 if C = No_Check_Id then
5016 ("argument of pragma% is not valid check name", Arg1);
5019 if not Suppress_Case
5020 and then (C = All_Checks or else C = Overflow_Check)
5022 Opt.Overflow_Checks_Unsuppressed := True;
5025 if Arg_Count = 1 then
5027 -- Make an entry in the local scope suppress table. This is the
5028 -- table that directly shows the current value of the scope
5029 -- suppress check for any check id value.
5031 if C = All_Checks then
5033 -- For All_Checks, we set all specific predefined checks with
5034 -- the exception of Elaboration_Check, which is handled
5035 -- specially because of not wanting All_Checks to have the
5036 -- effect of deactivating static elaboration order processing.
5038 for J in Scope_Suppress'Range loop
5039 if J /= Elaboration_Check then
5040 Scope_Suppress (J) := Suppress_Case;
5044 -- If not All_Checks, and predefined check, then set appropriate
5045 -- scope entry. Note that we will set Elaboration_Check if this
5046 -- is explicitly specified.
5048 elsif C in Predefined_Check_Id then
5049 Scope_Suppress (C) := Suppress_Case;
5052 -- Also make an entry in the Local_Entity_Suppress table
5054 Push_Local_Suppress_Stack_Entry
5057 Suppress => Suppress_Case);
5059 -- Case of two arguments present, where the check is suppressed for
5060 -- a specified entity (given as the second argument of the pragma)
5063 -- This is obsolescent in Ada 2005 mode
5065 if Ada_Version >= Ada_2005 then
5066 Check_Restriction (No_Obsolescent_Features, Arg2);
5069 Check_Optional_Identifier (Arg2, Name_On);
5070 E_Id := Get_Pragma_Arg (Arg2);
5073 if not Is_Entity_Name (E_Id) then
5075 ("second argument of pragma% must be entity name", Arg2);
5084 -- Enforce RM 11.5(7) which requires that for a pragma that
5085 -- appears within a package spec, the named entity must be
5086 -- within the package spec. We allow the package name itself
5087 -- to be mentioned since that makes sense, although it is not
5088 -- strictly allowed by 11.5(7).
5091 and then E /= Current_Scope
5092 and then Scope (E) /= Current_Scope
5095 ("entity in pragma% is not in package spec (RM 11.5(7))",
5099 -- Loop through homonyms. As noted below, in the case of a package
5100 -- spec, only homonyms within the package spec are considered.
5103 Suppress_Unsuppress_Echeck (E, C);
5105 if Is_Generic_Instance (E)
5106 and then Is_Subprogram (E)
5107 and then Present (Alias (E))
5109 Suppress_Unsuppress_Echeck (Alias (E), C);
5112 -- Move to next homonym if not aspect spec case
5114 exit when From_Aspect_Specification (N);
5118 -- If we are within a package specification, the pragma only
5119 -- applies to homonyms in the same scope.
5121 exit when In_Package_Spec
5122 and then Scope (E) /= Current_Scope;
5125 end Process_Suppress_Unsuppress;
5131 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5133 if Is_Imported (E) then
5135 ("cannot export entity& that was previously imported", Arg);
5137 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5139 ("cannot export entity& that has an address clause", Arg);
5142 Set_Is_Exported (E);
5144 -- Generate a reference for entity explicitly, because the
5145 -- identifier may be overloaded and name resolution will not
5148 Generate_Reference (E, Arg);
5150 -- Deal with exporting non-library level entity
5152 if not Is_Library_Level_Entity (E) then
5154 -- Not allowed at all for subprograms
5156 if Is_Subprogram (E) then
5157 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5159 -- Otherwise set public and statically allocated
5163 Set_Is_Statically_Allocated (E);
5165 -- Warn if the corresponding W flag is set and the pragma comes
5166 -- from source. The latter may not be true e.g. on VMS where we
5167 -- expand export pragmas for exception codes associated with
5168 -- imported or exported exceptions. We do not want to generate
5169 -- a warning for something that the user did not write.
5171 if Warn_On_Export_Import
5172 and then Comes_From_Source (Arg)
5175 ("?& has been made static as a result of Export", Arg, E);
5177 ("\this usage is non-standard and non-portable", Arg);
5182 if Warn_On_Export_Import and then Is_Type (E) then
5183 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5186 if Warn_On_Export_Import and Inside_A_Generic then
5188 ("all instances of& will have the same external name?", Arg, E);
5192 ----------------------------------------------
5193 -- Set_Extended_Import_Export_External_Name --
5194 ----------------------------------------------
5196 procedure Set_Extended_Import_Export_External_Name
5197 (Internal_Ent : Entity_Id;
5198 Arg_External : Node_Id)
5200 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5204 if No (Arg_External) then
5208 Check_Arg_Is_External_Name (Arg_External);
5210 if Nkind (Arg_External) = N_String_Literal then
5211 if String_Length (Strval (Arg_External)) = 0 then
5214 New_Name := Adjust_External_Name_Case (Arg_External);
5217 elsif Nkind (Arg_External) = N_Identifier then
5218 New_Name := Get_Default_External_Name (Arg_External);
5220 -- Check_Arg_Is_External_Name should let through only identifiers and
5221 -- string literals or static string expressions (which are folded to
5222 -- string literals).
5225 raise Program_Error;
5228 -- If we already have an external name set (by a prior normal Import
5229 -- or Export pragma), then the external names must match
5231 if Present (Interface_Name (Internal_Ent)) then
5232 Check_Matching_Internal_Names : declare
5233 S1 : constant String_Id := Strval (Old_Name);
5234 S2 : constant String_Id := Strval (New_Name);
5237 -- Called if names do not match
5243 procedure Mismatch is
5245 Error_Msg_Sloc := Sloc (Old_Name);
5247 ("external name does not match that given #",
5251 -- Start of processing for Check_Matching_Internal_Names
5254 if String_Length (S1) /= String_Length (S2) then
5258 for J in 1 .. String_Length (S1) loop
5259 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5264 end Check_Matching_Internal_Names;
5266 -- Otherwise set the given name
5269 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5270 Check_Duplicated_Export_Name (New_Name);
5272 end Set_Extended_Import_Export_External_Name;
5278 procedure Set_Imported (E : Entity_Id) is
5280 -- Error message if already imported or exported
5282 if Is_Exported (E) or else Is_Imported (E) then
5284 -- Error if being set Exported twice
5286 if Is_Exported (E) then
5287 Error_Msg_NE ("entity& was previously exported", N, E);
5289 -- OK if Import/Interface case
5291 elsif Import_Interface_Present (N) then
5294 -- Error if being set Imported twice
5297 Error_Msg_NE ("entity& was previously imported", N, E);
5300 Error_Msg_Name_1 := Pname;
5302 ("\(pragma% applies to all previous entities)", N);
5304 Error_Msg_Sloc := Sloc (E);
5305 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5307 -- Here if not previously imported or exported, OK to import
5310 Set_Is_Imported (E);
5312 -- If the entity is an object that is not at the library level,
5313 -- then it is statically allocated. We do not worry about objects
5314 -- with address clauses in this context since they are not really
5315 -- imported in the linker sense.
5318 and then not Is_Library_Level_Entity (E)
5319 and then No (Address_Clause (E))
5321 Set_Is_Statically_Allocated (E);
5328 -------------------------
5329 -- Set_Mechanism_Value --
5330 -------------------------
5332 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5333 -- analyzed, since it is semantic nonsense), so we get it in the exact
5334 -- form created by the parser.
5336 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5339 Mech_Name_Id : Name_Id;
5341 procedure Bad_Class;
5342 -- Signal bad descriptor class name
5344 procedure Bad_Mechanism;
5345 -- Signal bad mechanism name
5351 procedure Bad_Class is
5353 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5356 -------------------------
5357 -- Bad_Mechanism_Value --
5358 -------------------------
5360 procedure Bad_Mechanism is
5362 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5365 -- Start of processing for Set_Mechanism_Value
5368 if Mechanism (Ent) /= Default_Mechanism then
5370 ("mechanism for & has already been set", Mech_Name, Ent);
5373 -- MECHANISM_NAME ::= value | reference | descriptor |
5376 if Nkind (Mech_Name) = N_Identifier then
5377 if Chars (Mech_Name) = Name_Value then
5378 Set_Mechanism (Ent, By_Copy);
5381 elsif Chars (Mech_Name) = Name_Reference then
5382 Set_Mechanism (Ent, By_Reference);
5385 elsif Chars (Mech_Name) = Name_Descriptor then
5386 Check_VMS (Mech_Name);
5388 -- Descriptor => Short_Descriptor if pragma was given
5390 if Short_Descriptors then
5391 Set_Mechanism (Ent, By_Short_Descriptor);
5393 Set_Mechanism (Ent, By_Descriptor);
5398 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5399 Check_VMS (Mech_Name);
5400 Set_Mechanism (Ent, By_Short_Descriptor);
5403 elsif Chars (Mech_Name) = Name_Copy then
5405 ("bad mechanism name, Value assumed", Mech_Name);
5411 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5412 -- short_descriptor (CLASS_NAME)
5413 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5415 -- Note: this form is parsed as an indexed component
5417 elsif Nkind (Mech_Name) = N_Indexed_Component then
5418 Class := First (Expressions (Mech_Name));
5420 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5421 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5422 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5423 or else Present (Next (Class))
5427 Mech_Name_Id := Chars (Prefix (Mech_Name));
5429 -- Change Descriptor => Short_Descriptor if pragma was given
5431 if Mech_Name_Id = Name_Descriptor
5432 and then Short_Descriptors
5434 Mech_Name_Id := Name_Short_Descriptor;
5438 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5439 -- short_descriptor (Class => CLASS_NAME)
5440 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5442 -- Note: this form is parsed as a function call
5444 elsif Nkind (Mech_Name) = N_Function_Call then
5445 Param := First (Parameter_Associations (Mech_Name));
5447 if Nkind (Name (Mech_Name)) /= N_Identifier
5448 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5449 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5450 or else Present (Next (Param))
5451 or else No (Selector_Name (Param))
5452 or else Chars (Selector_Name (Param)) /= Name_Class
5456 Class := Explicit_Actual_Parameter (Param);
5457 Mech_Name_Id := Chars (Name (Mech_Name));
5464 -- Fall through here with Class set to descriptor class name
5466 Check_VMS (Mech_Name);
5468 if Nkind (Class) /= N_Identifier then
5471 elsif Mech_Name_Id = Name_Descriptor
5472 and then Chars (Class) = Name_UBS
5474 Set_Mechanism (Ent, By_Descriptor_UBS);
5476 elsif Mech_Name_Id = Name_Descriptor
5477 and then Chars (Class) = Name_UBSB
5479 Set_Mechanism (Ent, By_Descriptor_UBSB);
5481 elsif Mech_Name_Id = Name_Descriptor
5482 and then Chars (Class) = Name_UBA
5484 Set_Mechanism (Ent, By_Descriptor_UBA);
5486 elsif Mech_Name_Id = Name_Descriptor
5487 and then Chars (Class) = Name_S
5489 Set_Mechanism (Ent, By_Descriptor_S);
5491 elsif Mech_Name_Id = Name_Descriptor
5492 and then Chars (Class) = Name_SB
5494 Set_Mechanism (Ent, By_Descriptor_SB);
5496 elsif Mech_Name_Id = Name_Descriptor
5497 and then Chars (Class) = Name_A
5499 Set_Mechanism (Ent, By_Descriptor_A);
5501 elsif Mech_Name_Id = Name_Descriptor
5502 and then Chars (Class) = Name_NCA
5504 Set_Mechanism (Ent, By_Descriptor_NCA);
5506 elsif Mech_Name_Id = Name_Short_Descriptor
5507 and then Chars (Class) = Name_UBS
5509 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5511 elsif Mech_Name_Id = Name_Short_Descriptor
5512 and then Chars (Class) = Name_UBSB
5514 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5516 elsif Mech_Name_Id = Name_Short_Descriptor
5517 and then Chars (Class) = Name_UBA
5519 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5521 elsif Mech_Name_Id = Name_Short_Descriptor
5522 and then Chars (Class) = Name_S
5524 Set_Mechanism (Ent, By_Short_Descriptor_S);
5526 elsif Mech_Name_Id = Name_Short_Descriptor
5527 and then Chars (Class) = Name_SB
5529 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5531 elsif Mech_Name_Id = Name_Short_Descriptor
5532 and then Chars (Class) = Name_A
5534 Set_Mechanism (Ent, By_Short_Descriptor_A);
5536 elsif Mech_Name_Id = Name_Short_Descriptor
5537 and then Chars (Class) = Name_NCA
5539 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5544 end Set_Mechanism_Value;
5546 ---------------------------
5547 -- Set_Ravenscar_Profile --
5548 ---------------------------
5550 -- The tasks to be done here are
5552 -- Set required policies
5554 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5555 -- pragma Locking_Policy (Ceiling_Locking)
5557 -- Set Detect_Blocking mode
5559 -- Set required restrictions (see System.Rident for detailed list)
5561 -- Set the No_Dependence rules
5562 -- No_Dependence => Ada.Asynchronous_Task_Control
5563 -- No_Dependence => Ada.Calendar
5564 -- No_Dependence => Ada.Execution_Time.Group_Budget
5565 -- No_Dependence => Ada.Execution_Time.Timers
5566 -- No_Dependence => Ada.Task_Attributes
5567 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5569 procedure Set_Ravenscar_Profile (N : Node_Id) is
5570 Prefix_Entity : Entity_Id;
5571 Selector_Entity : Entity_Id;
5572 Prefix_Node : Node_Id;
5576 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5578 if Task_Dispatching_Policy /= ' '
5579 and then Task_Dispatching_Policy /= 'F'
5581 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5582 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5584 -- Set the FIFO_Within_Priorities policy, but always preserve
5585 -- System_Location since we like the error message with the run time
5589 Task_Dispatching_Policy := 'F';
5591 if Task_Dispatching_Policy_Sloc /= System_Location then
5592 Task_Dispatching_Policy_Sloc := Loc;
5596 -- pragma Locking_Policy (Ceiling_Locking)
5598 if Locking_Policy /= ' '
5599 and then Locking_Policy /= 'C'
5601 Error_Msg_Sloc := Locking_Policy_Sloc;
5602 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5604 -- Set the Ceiling_Locking policy, but preserve System_Location since
5605 -- we like the error message with the run time name.
5608 Locking_Policy := 'C';
5610 if Locking_Policy_Sloc /= System_Location then
5611 Locking_Policy_Sloc := Loc;
5615 -- pragma Detect_Blocking
5617 Detect_Blocking := True;
5619 -- Set the corresponding restrictions
5621 Set_Profile_Restrictions
5622 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5624 -- Set the No_Dependence restrictions
5626 -- The following No_Dependence restrictions:
5627 -- No_Dependence => Ada.Asynchronous_Task_Control
5628 -- No_Dependence => Ada.Calendar
5629 -- No_Dependence => Ada.Task_Attributes
5630 -- are already set by previous call to Set_Profile_Restrictions.
5632 -- Set the following restrictions which were added to Ada 2005:
5633 -- No_Dependence => Ada.Execution_Time.Group_Budget
5634 -- No_Dependence => Ada.Execution_Time.Timers
5636 if Ada_Version >= Ada_2005 then
5637 Name_Buffer (1 .. 3) := "ada";
5640 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5642 Name_Buffer (1 .. 14) := "execution_time";
5645 Selector_Entity := Make_Identifier (Loc, Name_Find);
5648 Make_Selected_Component
5650 Prefix => Prefix_Entity,
5651 Selector_Name => Selector_Entity);
5653 Name_Buffer (1 .. 13) := "group_budgets";
5656 Selector_Entity := Make_Identifier (Loc, Name_Find);
5659 Make_Selected_Component
5661 Prefix => Prefix_Node,
5662 Selector_Name => Selector_Entity);
5664 Set_Restriction_No_Dependence
5666 Warn => Treat_Restrictions_As_Warnings,
5667 Profile => Ravenscar);
5669 Name_Buffer (1 .. 6) := "timers";
5672 Selector_Entity := Make_Identifier (Loc, Name_Find);
5675 Make_Selected_Component
5677 Prefix => Prefix_Node,
5678 Selector_Name => Selector_Entity);
5680 Set_Restriction_No_Dependence
5682 Warn => Treat_Restrictions_As_Warnings,
5683 Profile => Ravenscar);
5686 -- Set the following restrictions which was added to Ada 2012 (see
5688 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5690 if Ada_Version >= Ada_2012 then
5691 Name_Buffer (1 .. 6) := "system";
5694 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5696 Name_Buffer (1 .. 15) := "multiprocessors";
5699 Selector_Entity := Make_Identifier (Loc, Name_Find);
5702 Make_Selected_Component
5704 Prefix => Prefix_Entity,
5705 Selector_Name => Selector_Entity);
5707 Name_Buffer (1 .. 19) := "dispatching_domains";
5710 Selector_Entity := Make_Identifier (Loc, Name_Find);
5713 Make_Selected_Component
5715 Prefix => Prefix_Node,
5716 Selector_Name => Selector_Entity);
5718 Set_Restriction_No_Dependence
5720 Warn => Treat_Restrictions_As_Warnings,
5721 Profile => Ravenscar);
5723 end Set_Ravenscar_Profile;
5725 -- Start of processing for Analyze_Pragma
5728 -- The following code is a defense against recursion. Not clear that
5729 -- this can happen legitimately, but perhaps some error situations
5730 -- can cause it, and we did see this recursion during testing.
5732 if Analyzed (N) then
5735 Set_Analyzed (N, True);
5738 -- Deal with unrecognized pragma
5740 if not Is_Pragma_Name (Pname) then
5741 if Warn_On_Unrecognized_Pragma then
5742 Error_Msg_Name_1 := Pname;
5743 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5745 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5746 if Is_Bad_Spelling_Of (Pname, PN) then
5747 Error_Msg_Name_1 := PN;
5748 Error_Msg_N -- CODEFIX
5749 ("\?possible misspelling of %!", Pragma_Identifier (N));
5758 -- Here to start processing for recognized pragma
5760 Prag_Id := Get_Pragma_Id (Pname);
5770 if Present (Pragma_Argument_Associations (N)) then
5771 Arg_Count := List_Length (Pragma_Argument_Associations (N));
5772 Arg1 := First (Pragma_Argument_Associations (N));
5774 if Present (Arg1) then
5775 Arg2 := Next (Arg1);
5777 if Present (Arg2) then
5778 Arg3 := Next (Arg2);
5780 if Present (Arg3) then
5781 Arg4 := Next (Arg3);
5787 -- An enumeration type defines the pragmas that are supported by the
5788 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5789 -- into the corresponding enumeration value for the following case.
5797 -- pragma Abort_Defer;
5799 when Pragma_Abort_Defer =>
5801 Check_Arg_Count (0);
5803 -- The only required semantic processing is to check the
5804 -- placement. This pragma must appear at the start of the
5805 -- statement sequence of a handled sequence of statements.
5807 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5808 or else N /= First (Statements (Parent (N)))
5819 -- Note: this pragma also has some specific processing in Par.Prag
5820 -- because we want to set the Ada version mode during parsing.
5822 when Pragma_Ada_83 =>
5824 Check_Arg_Count (0);
5826 -- We really should check unconditionally for proper configuration
5827 -- pragma placement, since we really don't want mixed Ada modes
5828 -- within a single unit, and the GNAT reference manual has always
5829 -- said this was a configuration pragma, but we did not check and
5830 -- are hesitant to add the check now.
5832 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5833 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5834 -- or Ada 2012 mode.
5836 if Ada_Version >= Ada_2005 then
5837 Check_Valid_Configuration_Pragma;
5840 -- Now set Ada 83 mode
5842 Ada_Version := Ada_83;
5843 Ada_Version_Explicit := Ada_Version;
5851 -- Note: this pragma also has some specific processing in Par.Prag
5852 -- because we want to set the Ada 83 version mode during parsing.
5854 when Pragma_Ada_95 =>
5856 Check_Arg_Count (0);
5858 -- We really should check unconditionally for proper configuration
5859 -- pragma placement, since we really don't want mixed Ada modes
5860 -- within a single unit, and the GNAT reference manual has always
5861 -- said this was a configuration pragma, but we did not check and
5862 -- are hesitant to add the check now.
5864 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5865 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5867 if Ada_Version >= Ada_2005 then
5868 Check_Valid_Configuration_Pragma;
5871 -- Now set Ada 95 mode
5873 Ada_Version := Ada_95;
5874 Ada_Version_Explicit := Ada_Version;
5876 ---------------------
5877 -- Ada_05/Ada_2005 --
5878 ---------------------
5881 -- pragma Ada_05 (LOCAL_NAME);
5884 -- pragma Ada_2005 (LOCAL_NAME):
5886 -- Note: these pragmas also have some specific processing in Par.Prag
5887 -- because we want to set the Ada 2005 version mode during parsing.
5889 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5895 if Arg_Count = 1 then
5896 Check_Arg_Is_Local_Name (Arg1);
5897 E_Id := Get_Pragma_Arg (Arg1);
5899 if Etype (E_Id) = Any_Type then
5903 Set_Is_Ada_2005_Only (Entity (E_Id));
5906 Check_Arg_Count (0);
5908 -- For Ada_2005 we unconditionally enforce the documented
5909 -- configuration pragma placement, since we do not want to
5910 -- tolerate mixed modes in a unit involving Ada 2005. That
5911 -- would cause real difficulties for those cases where there
5912 -- are incompatibilities between Ada 95 and Ada 2005.
5914 Check_Valid_Configuration_Pragma;
5916 -- Now set appropriate Ada mode
5918 Ada_Version := Ada_2005;
5919 Ada_Version_Explicit := Ada_2005;
5923 ---------------------
5924 -- Ada_12/Ada_2012 --
5925 ---------------------
5928 -- pragma Ada_12 (LOCAL_NAME);
5931 -- pragma Ada_2012 (LOCAL_NAME):
5933 -- Note: these pragmas also have some specific processing in Par.Prag
5934 -- because we want to set the Ada 2012 version mode during parsing.
5936 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5942 if Arg_Count = 1 then
5943 Check_Arg_Is_Local_Name (Arg1);
5944 E_Id := Get_Pragma_Arg (Arg1);
5946 if Etype (E_Id) = Any_Type then
5950 Set_Is_Ada_2012_Only (Entity (E_Id));
5953 Check_Arg_Count (0);
5955 -- For Ada_2012 we unconditionally enforce the documented
5956 -- configuration pragma placement, since we do not want to
5957 -- tolerate mixed modes in a unit involving Ada 2012. That
5958 -- would cause real difficulties for those cases where there
5959 -- are incompatibilities between Ada 95 and Ada 2012. We could
5960 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5962 Check_Valid_Configuration_Pragma;
5964 -- Now set appropriate Ada mode
5966 Ada_Version := Ada_2012;
5967 Ada_Version_Explicit := Ada_2012;
5971 ----------------------
5972 -- All_Calls_Remote --
5973 ----------------------
5975 -- pragma All_Calls_Remote [(library_package_NAME)];
5977 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5978 Lib_Entity : Entity_Id;
5981 Check_Ada_83_Warning;
5982 Check_Valid_Library_Unit_Pragma;
5984 if Nkind (N) = N_Null_Statement then
5988 Lib_Entity := Find_Lib_Unit_Name;
5990 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5992 if Present (Lib_Entity)
5993 and then not Debug_Flag_U
5995 if not Is_Remote_Call_Interface (Lib_Entity) then
5996 Error_Pragma ("pragma% only apply to rci unit");
5998 -- Set flag for entity of the library unit
6001 Set_Has_All_Calls_Remote (Lib_Entity);
6005 end All_Calls_Remote;
6011 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6012 -- ARG ::= NAME | EXPRESSION
6014 -- The first two arguments are by convention intended to refer to an
6015 -- external tool and a tool-specific function. These arguments are
6018 when Pragma_Annotate => Annotate : begin
6020 Check_At_Least_N_Arguments (1);
6021 Check_Arg_Is_Identifier (Arg1);
6022 Check_No_Identifiers;
6030 -- Second unanalyzed parameter is optional
6036 while Present (Arg) loop
6037 Exp := Get_Pragma_Arg (Arg);
6040 if Is_Entity_Name (Exp) then
6043 -- For string literals, we assume Standard_String as the
6044 -- type, unless the string contains wide or wide_wide
6047 elsif Nkind (Exp) = N_String_Literal then
6048 if Has_Wide_Wide_Character (Exp) then
6049 Resolve (Exp, Standard_Wide_Wide_String);
6050 elsif Has_Wide_Character (Exp) then
6051 Resolve (Exp, Standard_Wide_String);
6053 Resolve (Exp, Standard_String);
6056 elsif Is_Overloaded (Exp) then
6058 ("ambiguous argument for pragma%", Exp);
6074 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6075 -- [, [Message =>] Static_String_EXPRESSION]);
6077 when Pragma_Assert => Assert : declare
6083 Check_At_Least_N_Arguments (1);
6084 Check_At_Most_N_Arguments (2);
6085 Check_Arg_Order ((Name_Check, Name_Message));
6086 Check_Optional_Identifier (Arg1, Name_Check);
6088 -- We treat pragma Assert as equivalent to:
6090 -- pragma Check (Assertion, condition [, msg]);
6092 -- So rewrite pragma in this manner, and analyze the result
6094 Expr := Get_Pragma_Arg (Arg1);
6096 Make_Pragma_Argument_Association (Loc,
6097 Expression => Make_Identifier (Loc, Name_Assertion)),
6099 Make_Pragma_Argument_Association (Sloc (Expr),
6100 Expression => Expr));
6102 if Arg_Count > 1 then
6103 Check_Optional_Identifier (Arg2, Name_Message);
6104 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6105 Append_To (Newa, Relocate_Node (Arg2));
6110 Chars => Name_Check,
6111 Pragma_Argument_Associations => Newa));
6115 ----------------------
6116 -- Assertion_Policy --
6117 ----------------------
6119 -- pragma Assertion_Policy (Check | Ignore)
6121 when Pragma_Assertion_Policy => Assertion_Policy : declare
6126 Check_Valid_Configuration_Pragma;
6127 Check_Arg_Count (1);
6128 Check_No_Identifiers;
6129 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6131 -- We treat pragma Assertion_Policy as equivalent to:
6133 -- pragma Check_Policy (Assertion, policy)
6135 -- So rewrite the pragma in that manner and link on to the chain
6136 -- of Check_Policy pragmas, marking the pragma as analyzed.
6138 Policy := Get_Pragma_Arg (Arg1);
6142 Chars => Name_Check_Policy,
6144 Pragma_Argument_Associations => New_List (
6145 Make_Pragma_Argument_Association (Loc,
6146 Expression => Make_Identifier (Loc, Name_Assertion)),
6148 Make_Pragma_Argument_Association (Loc,
6150 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6153 Set_Next_Pragma (N, Opt.Check_Policy_List);
6154 Opt.Check_Policy_List := N;
6155 end Assertion_Policy;
6157 ------------------------------
6158 -- Assume_No_Invalid_Values --
6159 ------------------------------
6161 -- pragma Assume_No_Invalid_Values (On | Off);
6163 when Pragma_Assume_No_Invalid_Values =>
6165 Check_Valid_Configuration_Pragma;
6166 Check_Arg_Count (1);
6167 Check_No_Identifiers;
6168 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6170 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6171 Assume_No_Invalid_Values := True;
6173 Assume_No_Invalid_Values := False;
6180 -- pragma AST_Entry (entry_IDENTIFIER);
6182 when Pragma_AST_Entry => AST_Entry : declare
6188 Check_Arg_Count (1);
6189 Check_No_Identifiers;
6190 Check_Arg_Is_Local_Name (Arg1);
6191 Ent := Entity (Get_Pragma_Arg (Arg1));
6193 -- Note: the implementation of the AST_Entry pragma could handle
6194 -- the entry family case fine, but for now we are consistent with
6195 -- the DEC rules, and do not allow the pragma, which of course
6196 -- has the effect of also forbidding the attribute.
6198 if Ekind (Ent) /= E_Entry then
6200 ("pragma% argument must be simple entry name", Arg1);
6202 elsif Is_AST_Entry (Ent) then
6204 ("duplicate % pragma for entry", Arg1);
6206 elsif Has_Homonym (Ent) then
6208 ("pragma% argument cannot specify overloaded entry", Arg1);
6212 FF : constant Entity_Id := First_Formal (Ent);
6215 if Present (FF) then
6216 if Present (Next_Formal (FF)) then
6218 ("entry for pragma% can have only one argument",
6221 elsif Parameter_Mode (FF) /= E_In_Parameter then
6223 ("entry parameter for pragma% must have mode IN",
6229 Set_Is_AST_Entry (Ent);
6237 -- pragma Asynchronous (LOCAL_NAME);
6239 when Pragma_Asynchronous => Asynchronous : declare
6247 procedure Process_Async_Pragma;
6248 -- Common processing for procedure and access-to-procedure case
6250 --------------------------
6251 -- Process_Async_Pragma --
6252 --------------------------
6254 procedure Process_Async_Pragma is
6257 Set_Is_Asynchronous (Nm);
6261 -- The formals should be of mode IN (RM E.4.1(6))
6264 while Present (S) loop
6265 Formal := Defining_Identifier (S);
6267 if Nkind (Formal) = N_Defining_Identifier
6268 and then Ekind (Formal) /= E_In_Parameter
6271 ("pragma% procedure can only have IN parameter",
6278 Set_Is_Asynchronous (Nm);
6279 end Process_Async_Pragma;
6281 -- Start of processing for pragma Asynchronous
6284 Check_Ada_83_Warning;
6285 Check_No_Identifiers;
6286 Check_Arg_Count (1);
6287 Check_Arg_Is_Local_Name (Arg1);
6289 if Debug_Flag_U then
6293 C_Ent := Cunit_Entity (Current_Sem_Unit);
6294 Analyze (Get_Pragma_Arg (Arg1));
6295 Nm := Entity (Get_Pragma_Arg (Arg1));
6297 if not Is_Remote_Call_Interface (C_Ent)
6298 and then not Is_Remote_Types (C_Ent)
6300 -- This pragma should only appear in an RCI or Remote Types
6301 -- unit (RM E.4.1(4)).
6304 ("pragma% not in Remote_Call_Interface or " &
6305 "Remote_Types unit");
6308 if Ekind (Nm) = E_Procedure
6309 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6311 if not Is_Remote_Call_Interface (Nm) then
6313 ("pragma% cannot be applied on non-remote procedure",
6317 L := Parameter_Specifications (Parent (Nm));
6318 Process_Async_Pragma;
6321 elsif Ekind (Nm) = E_Function then
6323 ("pragma% cannot be applied to function", Arg1);
6325 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6327 if Is_Record_Type (Nm) then
6329 -- A record type that is the Equivalent_Type for a remote
6330 -- access-to-subprogram type.
6332 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6335 -- A non-expanded RAS type (distribution is not enabled)
6337 N := Declaration_Node (Nm);
6340 if Nkind (N) = N_Full_Type_Declaration
6341 and then Nkind (Type_Definition (N)) =
6342 N_Access_Procedure_Definition
6344 L := Parameter_Specifications (Type_Definition (N));
6345 Process_Async_Pragma;
6347 if Is_Asynchronous (Nm)
6348 and then Expander_Active
6349 and then Get_PCS_Name /= Name_No_DSA
6351 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6356 ("pragma% cannot reference access-to-function type",
6360 -- Only other possibility is Access-to-class-wide type
6362 elsif Is_Access_Type (Nm)
6363 and then Is_Class_Wide_Type (Designated_Type (Nm))
6365 Check_First_Subtype (Arg1);
6366 Set_Is_Asynchronous (Nm);
6367 if Expander_Active then
6368 RACW_Type_Is_Asynchronous (Nm);
6372 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6380 -- pragma Atomic (LOCAL_NAME);
6382 when Pragma_Atomic =>
6383 Process_Atomic_Shared_Volatile;
6385 -----------------------
6386 -- Atomic_Components --
6387 -----------------------
6389 -- pragma Atomic_Components (array_LOCAL_NAME);
6391 -- This processing is shared by Volatile_Components
6393 when Pragma_Atomic_Components |
6394 Pragma_Volatile_Components =>
6396 Atomic_Components : declare
6403 Check_Ada_83_Warning;
6404 Check_No_Identifiers;
6405 Check_Arg_Count (1);
6406 Check_Arg_Is_Local_Name (Arg1);
6407 E_Id := Get_Pragma_Arg (Arg1);
6409 if Etype (E_Id) = Any_Type then
6415 Check_Duplicate_Pragma (E);
6417 if Rep_Item_Too_Early (E, N)
6419 Rep_Item_Too_Late (E, N)
6424 D := Declaration_Node (E);
6427 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6429 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6430 and then Nkind (D) = N_Object_Declaration
6431 and then Nkind (Object_Definition (D)) =
6432 N_Constrained_Array_Definition)
6434 -- The flag is set on the object, or on the base type
6436 if Nkind (D) /= N_Object_Declaration then
6440 Set_Has_Volatile_Components (E);
6442 if Prag_Id = Pragma_Atomic_Components then
6443 Set_Has_Atomic_Components (E);
6447 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6449 end Atomic_Components;
6451 --------------------
6452 -- Attach_Handler --
6453 --------------------
6455 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6457 when Pragma_Attach_Handler =>
6458 Check_Ada_83_Warning;
6459 Check_No_Identifiers;
6460 Check_Arg_Count (2);
6462 if No_Run_Time_Mode then
6463 Error_Msg_CRT ("Attach_Handler pragma", N);
6465 Check_Interrupt_Or_Attach_Handler;
6467 -- The expression that designates the attribute may depend on a
6468 -- discriminant, and is therefore a per- object expression, to
6469 -- be expanded in the init proc. If expansion is enabled, then
6470 -- perform semantic checks on a copy only.
6472 if Expander_Active then
6474 Temp : constant Node_Id :=
6475 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6477 Set_Parent (Temp, N);
6478 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6482 Analyze (Get_Pragma_Arg (Arg2));
6483 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6486 Process_Interrupt_Or_Attach_Handler;
6489 --------------------
6490 -- C_Pass_By_Copy --
6491 --------------------
6493 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6495 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6501 Check_Valid_Configuration_Pragma;
6502 Check_Arg_Count (1);
6503 Check_Optional_Identifier (Arg1, "max_size");
6505 Arg := Get_Pragma_Arg (Arg1);
6506 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6508 Val := Expr_Value (Arg);
6512 ("maximum size for pragma% must be positive", Arg1);
6514 elsif UI_Is_In_Int_Range (Val) then
6515 Default_C_Record_Mechanism := UI_To_Int (Val);
6517 -- If a giant value is given, Int'Last will do well enough.
6518 -- If sometime someone complains that a record larger than
6519 -- two gigabytes is not copied, we will worry about it then!
6522 Default_C_Record_Mechanism := Mechanism_Type'Last;
6530 -- pragma Check ([Name =>] Identifier,
6531 -- [Check =>] Boolean_Expression
6532 -- [,[Message =>] String_Expression]);
6534 when Pragma_Check => Check : declare
6539 -- Set True if category of assertions referenced by Name enabled
6543 Check_At_Least_N_Arguments (2);
6544 Check_At_Most_N_Arguments (3);
6545 Check_Optional_Identifier (Arg1, Name_Name);
6546 Check_Optional_Identifier (Arg2, Name_Check);
6548 if Arg_Count = 3 then
6549 Check_Optional_Identifier (Arg3, Name_Message);
6550 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6553 Check_Arg_Is_Identifier (Arg1);
6555 -- Indicate if pragma is enabled. The Original_Node reference here
6556 -- is to deal with pragma Assert rewritten as a Check pragma.
6558 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6561 Set_Pragma_Enabled (N);
6562 Set_Pragma_Enabled (Original_Node (N));
6563 Set_SCO_Pragma_Enabled (Loc);
6566 -- If expansion is active and the check is not enabled then we
6567 -- rewrite the Check as:
6569 -- if False and then condition then
6573 -- The reason we do this rewriting during semantic analysis rather
6574 -- than as part of normal expansion is that we cannot analyze and
6575 -- expand the code for the boolean expression directly, or it may
6576 -- cause insertion of actions that would escape the attempt to
6577 -- suppress the check code.
6579 -- Note that the Sloc for the if statement corresponds to the
6580 -- argument condition, not the pragma itself. The reason for this
6581 -- is that we may generate a warning if the condition is False at
6582 -- compile time, and we do not want to delete this warning when we
6583 -- delete the if statement.
6585 Expr := Get_Pragma_Arg (Arg2);
6587 if Expander_Active and then not Check_On then
6588 Eloc := Sloc (Expr);
6591 Make_If_Statement (Eloc,
6593 Make_And_Then (Eloc,
6594 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6595 Right_Opnd => Expr),
6596 Then_Statements => New_List (
6597 Make_Null_Statement (Eloc))));
6604 Analyze_And_Resolve (Expr, Any_Boolean);
6612 -- pragma Check_Name (check_IDENTIFIER);
6614 when Pragma_Check_Name =>
6615 Check_No_Identifiers;
6617 Check_Valid_Configuration_Pragma;
6618 Check_Arg_Count (1);
6619 Check_Arg_Is_Identifier (Arg1);
6622 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6625 for J in Check_Names.First .. Check_Names.Last loop
6626 if Check_Names.Table (J) = Nam then
6631 Check_Names.Append (Nam);
6638 -- pragma Check_Policy (
6639 -- [Name =>] IDENTIFIER,
6640 -- [Policy =>] POLICY_IDENTIFIER);
6642 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6644 -- Note: this is a configuration pragma, but it is allowed to appear
6647 when Pragma_Check_Policy =>
6649 Check_Arg_Count (2);
6650 Check_Optional_Identifier (Arg1, Name_Name);
6651 Check_Optional_Identifier (Arg2, Name_Policy);
6653 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6655 -- A Check_Policy pragma can appear either as a configuration
6656 -- pragma, or in a declarative part or a package spec (see RM
6657 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6658 -- followed for Check_Policy).
6660 if not Is_Configuration_Pragma then
6661 Check_Is_In_Decl_Part_Or_Package_Spec;
6664 Set_Next_Pragma (N, Opt.Check_Policy_List);
6665 Opt.Check_Policy_List := N;
6667 ---------------------
6668 -- CIL_Constructor --
6669 ---------------------
6671 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6673 -- Processing for this pragma is shared with Java_Constructor
6679 -- pragma Comment (static_string_EXPRESSION)
6681 -- Processing for pragma Comment shares the circuitry for pragma
6682 -- Ident. The only differences are that Ident enforces a limit of 31
6683 -- characters on its argument, and also enforces limitations on
6684 -- placement for DEC compatibility. Pragma Comment shares neither of
6685 -- these restrictions.
6691 -- pragma Common_Object (
6692 -- [Internal =>] LOCAL_NAME
6693 -- [, [External =>] EXTERNAL_SYMBOL]
6694 -- [, [Size =>] EXTERNAL_SYMBOL]);
6696 -- Processing for this pragma is shared with Psect_Object
6698 ------------------------
6699 -- Compile_Time_Error --
6700 ------------------------
6702 -- pragma Compile_Time_Error
6703 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6705 when Pragma_Compile_Time_Error =>
6707 Process_Compile_Time_Warning_Or_Error;
6709 --------------------------
6710 -- Compile_Time_Warning --
6711 --------------------------
6713 -- pragma Compile_Time_Warning
6714 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6716 when Pragma_Compile_Time_Warning =>
6718 Process_Compile_Time_Warning_Or_Error;
6724 when Pragma_Compiler_Unit =>
6726 Check_Arg_Count (0);
6727 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6729 -----------------------------
6730 -- Complete_Representation --
6731 -----------------------------
6733 -- pragma Complete_Representation;
6735 when Pragma_Complete_Representation =>
6737 Check_Arg_Count (0);
6739 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6741 ("pragma & must appear within record representation clause");
6744 ----------------------------
6745 -- Complex_Representation --
6746 ----------------------------
6748 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6750 when Pragma_Complex_Representation => Complex_Representation : declare
6757 Check_Arg_Count (1);
6758 Check_Optional_Identifier (Arg1, Name_Entity);
6759 Check_Arg_Is_Local_Name (Arg1);
6760 E_Id := Get_Pragma_Arg (Arg1);
6762 if Etype (E_Id) = Any_Type then
6768 if not Is_Record_Type (E) then
6770 ("argument for pragma% must be record type", Arg1);
6773 Ent := First_Entity (E);
6776 or else No (Next_Entity (Ent))
6777 or else Present (Next_Entity (Next_Entity (Ent)))
6778 or else not Is_Floating_Point_Type (Etype (Ent))
6779 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6782 ("record for pragma% must have two fields of the same "
6783 & "floating-point type", Arg1);
6786 Set_Has_Complex_Representation (Base_Type (E));
6788 -- We need to treat the type has having a non-standard
6789 -- representation, for back-end purposes, even though in
6790 -- general a complex will have the default representation
6791 -- of a record with two real components.
6793 Set_Has_Non_Standard_Rep (Base_Type (E));
6795 end Complex_Representation;
6797 -------------------------
6798 -- Component_Alignment --
6799 -------------------------
6801 -- pragma Component_Alignment (
6802 -- [Form =>] ALIGNMENT_CHOICE
6803 -- [, [Name =>] type_LOCAL_NAME]);
6805 -- ALIGNMENT_CHOICE ::=
6807 -- | Component_Size_4
6811 when Pragma_Component_Alignment => Component_AlignmentP : declare
6812 Args : Args_List (1 .. 2);
6813 Names : constant Name_List (1 .. 2) := (
6817 Form : Node_Id renames Args (1);
6818 Name : Node_Id renames Args (2);
6820 Atype : Component_Alignment_Kind;
6825 Gather_Associations (Names, Args);
6828 Error_Pragma ("missing Form argument for pragma%");
6831 Check_Arg_Is_Identifier (Form);
6833 -- Get proper alignment, note that Default = Component_Size on all
6834 -- machines we have so far, and we want to set this value rather
6835 -- than the default value to indicate that it has been explicitly
6836 -- set (and thus will not get overridden by the default component
6837 -- alignment for the current scope)
6839 if Chars (Form) = Name_Component_Size then
6840 Atype := Calign_Component_Size;
6842 elsif Chars (Form) = Name_Component_Size_4 then
6843 Atype := Calign_Component_Size_4;
6845 elsif Chars (Form) = Name_Default then
6846 Atype := Calign_Component_Size;
6848 elsif Chars (Form) = Name_Storage_Unit then
6849 Atype := Calign_Storage_Unit;
6853 ("invalid Form parameter for pragma%", Form);
6856 -- Case with no name, supplied, affects scope table entry
6860 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6862 -- Case of name supplied
6865 Check_Arg_Is_Local_Name (Name);
6867 Typ := Entity (Name);
6870 or else Rep_Item_Too_Early (Typ, N)
6874 Typ := Underlying_Type (Typ);
6877 if not Is_Record_Type (Typ)
6878 and then not Is_Array_Type (Typ)
6881 ("Name parameter of pragma% must identify record or " &
6882 "array type", Name);
6885 -- An explicit Component_Alignment pragma overrides an
6886 -- implicit pragma Pack, but not an explicit one.
6888 if not Has_Pragma_Pack (Base_Type (Typ)) then
6889 Set_Is_Packed (Base_Type (Typ), False);
6890 Set_Component_Alignment (Base_Type (Typ), Atype);
6893 end Component_AlignmentP;
6899 -- pragma Controlled (first_subtype_LOCAL_NAME);
6901 when Pragma_Controlled => Controlled : declare
6905 Check_No_Identifiers;
6906 Check_Arg_Count (1);
6907 Check_Arg_Is_Local_Name (Arg1);
6908 Arg := Get_Pragma_Arg (Arg1);
6910 if not Is_Entity_Name (Arg)
6911 or else not Is_Access_Type (Entity (Arg))
6913 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6915 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6923 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6924 -- [Entity =>] LOCAL_NAME);
6926 when Pragma_Convention => Convention : declare
6929 pragma Warnings (Off, C);
6930 pragma Warnings (Off, E);
6932 Check_Arg_Order ((Name_Convention, Name_Entity));
6933 Check_Ada_83_Warning;
6934 Check_Arg_Count (2);
6935 Process_Convention (C, E);
6938 ---------------------------
6939 -- Convention_Identifier --
6940 ---------------------------
6942 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6943 -- [Convention =>] convention_IDENTIFIER);
6945 when Pragma_Convention_Identifier => Convention_Identifier : declare
6951 Check_Arg_Order ((Name_Name, Name_Convention));
6952 Check_Arg_Count (2);
6953 Check_Optional_Identifier (Arg1, Name_Name);
6954 Check_Optional_Identifier (Arg2, Name_Convention);
6955 Check_Arg_Is_Identifier (Arg1);
6956 Check_Arg_Is_Identifier (Arg2);
6957 Idnam := Chars (Get_Pragma_Arg (Arg1));
6958 Cname := Chars (Get_Pragma_Arg (Arg2));
6960 if Is_Convention_Name (Cname) then
6961 Record_Convention_Identifier
6962 (Idnam, Get_Convention_Id (Cname));
6965 ("second arg for % pragma must be convention", Arg2);
6967 end Convention_Identifier;
6973 -- pragma CPP_Class ([Entity =>] local_NAME)
6975 when Pragma_CPP_Class => CPP_Class : declare
6980 if Warn_On_Obsolescent_Feature then
6982 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6983 " by pragma import?", N);
6987 Check_Arg_Count (1);
6988 Check_Optional_Identifier (Arg1, Name_Entity);
6989 Check_Arg_Is_Local_Name (Arg1);
6991 Arg := Get_Pragma_Arg (Arg1);
6994 if Etype (Arg) = Any_Type then
6998 if not Is_Entity_Name (Arg)
6999 or else not Is_Type (Entity (Arg))
7001 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7004 Typ := Entity (Arg);
7006 if not Is_Tagged_Type (Typ) then
7007 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7010 -- Types treated as CPP classes are treated as limited, but we
7011 -- don't require them to be declared this way. A warning is issued
7012 -- to encourage the user to declare them as limited. This is not
7013 -- an error, for compatibility reasons, because these types have
7014 -- been supported this way for some time.
7016 if not Is_Limited_Type (Typ) then
7018 ("imported 'C'P'P type should be " &
7019 "explicitly declared limited?",
7020 Get_Pragma_Arg (Arg1));
7022 ("\type will be considered limited",
7023 Get_Pragma_Arg (Arg1));
7026 Set_Is_CPP_Class (Typ);
7027 Set_Is_Limited_Record (Typ);
7028 Set_Convention (Typ, Convention_CPP);
7030 -- Imported CPP types must not have discriminants (because C++
7031 -- classes do not have discriminants).
7033 if Has_Discriminants (Typ) then
7035 ("imported 'C'P'P type cannot have discriminants",
7036 First (Discriminant_Specifications
7037 (Declaration_Node (Typ))));
7040 -- Components of imported CPP types must not have default
7041 -- expressions because the constructor (if any) is in the
7044 if Is_Incomplete_Or_Private_Type (Typ)
7045 and then No (Underlying_Type (Typ))
7047 -- It should be an error to apply pragma CPP to a private
7048 -- type if the underlying type is not visible (as it is
7049 -- for any representation item). For now, for backward
7050 -- compatibility we do nothing but we cannot check components
7051 -- because they are not available at this stage. All this code
7052 -- will be removed when we cleanup this obsolete GNAT pragma???
7058 Tdef : constant Node_Id :=
7059 Type_Definition (Declaration_Node (Typ));
7064 if Nkind (Tdef) = N_Record_Definition then
7065 Clist := Component_List (Tdef);
7067 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7068 Clist := Component_List (Record_Extension_Part (Tdef));
7071 if Present (Clist) then
7072 Comp := First (Component_Items (Clist));
7073 while Present (Comp) loop
7074 if Present (Expression (Comp)) then
7076 ("component of imported 'C'P'P type cannot have" &
7077 " default expression", Expression (Comp));
7087 ---------------------
7088 -- CPP_Constructor --
7089 ---------------------
7091 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7092 -- [, [External_Name =>] static_string_EXPRESSION ]
7093 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7095 when Pragma_CPP_Constructor => CPP_Constructor : declare
7099 Tag_Typ : Entity_Id;
7103 Check_At_Least_N_Arguments (1);
7104 Check_At_Most_N_Arguments (3);
7105 Check_Optional_Identifier (Arg1, Name_Entity);
7106 Check_Arg_Is_Local_Name (Arg1);
7108 Id := Get_Pragma_Arg (Arg1);
7109 Find_Program_Unit_Name (Id);
7111 -- If we did not find the name, we are done
7113 if Etype (Id) = Any_Type then
7117 Def_Id := Entity (Id);
7119 -- Check if already defined as constructor
7121 if Is_Constructor (Def_Id) then
7123 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7127 if Ekind (Def_Id) = E_Function
7128 and then (Is_CPP_Class (Etype (Def_Id))
7129 or else (Is_Class_Wide_Type (Etype (Def_Id))
7131 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7133 if Arg_Count >= 2 then
7134 Set_Imported (Def_Id);
7135 Set_Is_Public (Def_Id);
7136 Process_Interface_Name (Def_Id, Arg2, Arg3);
7139 Set_Has_Completion (Def_Id);
7140 Set_Is_Constructor (Def_Id);
7142 -- Imported C++ constructors are not dispatching primitives
7143 -- because in C++ they don't have a dispatch table slot.
7144 -- However, in Ada the constructor has the profile of a
7145 -- function that returns a tagged type and therefore it has
7146 -- been treated as a primitive operation during semantic
7147 -- analysis. We now remove it from the list of primitive
7148 -- operations of the type.
7150 if Is_Tagged_Type (Etype (Def_Id))
7151 and then not Is_Class_Wide_Type (Etype (Def_Id))
7153 pragma Assert (Is_Dispatching_Operation (Def_Id));
7154 Tag_Typ := Etype (Def_Id);
7156 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7157 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7161 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7162 Set_Is_Dispatching_Operation (Def_Id, False);
7165 -- For backward compatibility, if the constructor returns a
7166 -- class wide type, and we internally change the return type to
7167 -- the corresponding root type.
7169 if Is_Class_Wide_Type (Etype (Def_Id)) then
7170 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7174 ("pragma% requires function returning a 'C'P'P_Class type",
7177 end CPP_Constructor;
7183 when Pragma_CPP_Virtual => CPP_Virtual : declare
7187 if Warn_On_Obsolescent_Feature then
7189 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7198 when Pragma_CPP_Vtable => CPP_Vtable : declare
7202 if Warn_On_Obsolescent_Feature then
7204 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7213 -- pragma CPU (EXPRESSION);
7215 when Pragma_CPU => CPU : declare
7216 P : constant Node_Id := Parent (N);
7221 Check_No_Identifiers;
7222 Check_Arg_Count (1);
7226 if Nkind (P) = N_Subprogram_Body then
7227 Check_In_Main_Program;
7229 Arg := Get_Pragma_Arg (Arg1);
7230 Analyze_And_Resolve (Arg, Any_Integer);
7234 if not Is_Static_Expression (Arg) then
7235 Flag_Non_Static_Expr
7236 ("main subprogram affinity is not static!", Arg);
7239 -- If constraint error, then we already signalled an error
7241 elsif Raises_Constraint_Error (Arg) then
7244 -- Otherwise check in range
7248 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7249 -- This is the entity System.Multiprocessors.CPU_Range;
7251 Val : constant Uint := Expr_Value (Arg);
7254 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7256 Val > Expr_Value (Type_High_Bound (CPU_Id))
7259 ("main subprogram CPU is out of range", Arg1);
7265 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7269 elsif Nkind (P) = N_Task_Definition then
7270 Arg := Get_Pragma_Arg (Arg1);
7272 -- The expression must be analyzed in the special manner
7273 -- described in "Handling of Default and Per-Object
7274 -- Expressions" in sem.ads.
7276 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7278 -- Anything else is incorrect
7284 if Has_Pragma_CPU (P) then
7285 Error_Pragma ("duplicate pragma% not allowed");
7287 Set_Has_Pragma_CPU (P, True);
7289 if Nkind (P) = N_Task_Definition then
7290 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7299 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7301 when Pragma_Debug => Debug : declare
7309 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7312 if Arg_Count = 2 then
7315 Left_Opnd => Relocate_Node (Cond),
7316 Right_Opnd => Get_Pragma_Arg (Arg1));
7319 -- Rewrite into a conditional with an appropriate condition. We
7320 -- wrap the procedure call in a block so that overhead from e.g.
7321 -- use of the secondary stack does not generate execution overhead
7322 -- for suppressed conditions.
7324 Rewrite (N, Make_Implicit_If_Statement (N,
7326 Then_Statements => New_List (
7327 Make_Block_Statement (Loc,
7328 Handled_Statement_Sequence =>
7329 Make_Handled_Sequence_Of_Statements (Loc,
7330 Statements => New_List (
7331 Relocate_Node (Debug_Statement (N))))))));
7339 -- pragma Debug_Policy (Check | Ignore)
7341 when Pragma_Debug_Policy =>
7343 Check_Arg_Count (1);
7344 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7345 Debug_Pragmas_Enabled :=
7346 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7348 -----------------------------
7349 -- Default_Component_Value --
7350 -----------------------------
7352 when Pragma_Default_Component_Value => declare
7358 Check_Arg_Count (2);
7359 Check_Arg_Is_Local_Name (Arg1);
7361 Arg := Get_Pragma_Arg (Arg1);
7364 if Etype (Arg) = Any_Type then
7368 if not Is_Entity_Name (Arg)
7369 or else not Is_Array_Type (Entity (Arg))
7371 Error_Pragma_Arg ("pragma% requires an array type", Arg1);
7374 Check_First_Subtype (Arg1);
7377 Check_Duplicate_Pragma (E);
7379 -- Check for rep item too early or too late, but skip this if
7380 -- the pragma comes from the corresponding aspect, since we do
7381 -- not need the checks, and more importantly, the pragma is on
7382 -- the rep item chain alreay, and must not be put there twice!
7384 if not From_Aspect_Specification (N) then
7385 if Rep_Item_Too_Early (E, N)
7387 Rep_Item_Too_Late (E, N)
7393 -- Analyze the default value
7395 Arg := Get_Pragma_Arg (Arg2);
7396 Analyze_And_Resolve (Arg, Component_Type (E));
7398 if not Is_OK_Static_Expression (Arg) then
7399 Flag_Non_Static_Expr
7400 ("non-static expression not allowed for " &
7401 "Default_Component_Value",
7406 -- Set the flag on the root type and then check for Rep_Item too
7407 -- early or too late, the latter call chains the pragma onto the
7410 Set_Has_Default_Component_Value (Base_Type (E));
7417 when Pragma_Default_Value => declare
7425 Check_Arg_Count (2);
7426 Check_Arg_Is_Local_Name (Arg1);
7428 Arg := Get_Pragma_Arg (Arg1);
7431 if Etype (Arg) = Any_Type then
7435 if not Is_Entity_Name (Arg)
7436 or else not Is_Scalar_Type (Entity (Arg))
7438 Error_Pragma_Arg ("pragma% requires a scalar type", Arg1);
7441 Check_First_Subtype (Arg1);
7444 Check_Duplicate_Pragma (E);
7446 -- Check for rep item too early or too late, but skip this if
7447 -- the pragma comes from the corresponding aspect, since we do
7448 -- not need the checks, and more importantly, the pragma is on
7449 -- the rep item chain alreay, and must not be put there twice!
7451 if not From_Aspect_Specification (N) then
7452 if Rep_Item_Too_Early (E, N)
7454 Rep_Item_Too_Late (E, N)
7460 -- Analyze the default value. Note that we must do that after
7461 -- checking for Rep_Item_Too_Late since this resolution will
7462 -- freeze the type involved.
7464 Arg := Get_Pragma_Arg (Arg2);
7465 Analyze_And_Resolve (Arg, E);
7467 if not Is_OK_Static_Expression (Arg) then
7468 Flag_Non_Static_Expr
7469 ("non-static expression not allowed for Default_Value",
7474 -- Set the flag on the root type and then check for Rep_Item too
7475 -- early or too late, the latter call chains the pragma onto the
7478 Set_Has_Default_Value (Base_Type (E));
7481 ---------------------
7482 -- Detect_Blocking --
7483 ---------------------
7485 -- pragma Detect_Blocking;
7487 when Pragma_Detect_Blocking =>
7489 Check_Arg_Count (0);
7490 Check_Valid_Configuration_Pragma;
7491 Detect_Blocking := True;
7493 --------------------------
7494 -- Default_Storage_Pool --
7495 --------------------------
7497 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7499 when Pragma_Default_Storage_Pool =>
7501 Check_Arg_Count (1);
7503 -- Default_Storage_Pool can appear as a configuration pragma, or
7504 -- in a declarative part or a package spec.
7506 if not Is_Configuration_Pragma then
7507 Check_Is_In_Decl_Part_Or_Package_Spec;
7510 -- Case of Default_Storage_Pool (null);
7512 if Nkind (Expression (Arg1)) = N_Null then
7513 Analyze (Expression (Arg1));
7515 -- This is an odd case, this is not really an expression, so
7516 -- we don't have a type for it. So just set the type to Empty.
7518 Set_Etype (Expression (Arg1), Empty);
7520 -- Case of Default_Storage_Pool (storage_pool_NAME);
7523 -- If it's a configuration pragma, then the only allowed
7524 -- argument is "null".
7526 if Is_Configuration_Pragma then
7527 Error_Pragma_Arg ("NULL expected", Arg1);
7530 -- The expected type for a non-"null" argument is
7531 -- Root_Storage_Pool'Class.
7534 (Get_Pragma_Arg (Arg1),
7535 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7538 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7539 -- for an access type will use this information to set the
7540 -- appropriate attributes of the access type.
7542 Default_Pool := Expression (Arg1);
7548 when Pragma_Dimension =>
7550 Check_Arg_Count (4);
7551 Check_No_Identifiers;
7552 Check_Arg_Is_Local_Name (Arg1);
7554 if not Is_Type (Arg1) then
7555 Error_Pragma ("first argument for pragma% must be subtype");
7558 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7559 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7560 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7566 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7568 when Pragma_Discard_Names => Discard_Names : declare
7573 Check_Ada_83_Warning;
7575 -- Deal with configuration pragma case
7577 if Arg_Count = 0 and then Is_Configuration_Pragma then
7578 Global_Discard_Names := True;
7581 -- Otherwise, check correct appropriate context
7584 Check_Is_In_Decl_Part_Or_Package_Spec;
7586 if Arg_Count = 0 then
7588 -- If there is no parameter, then from now on this pragma
7589 -- applies to any enumeration, exception or tagged type
7590 -- defined in the current declarative part, and recursively
7591 -- to any nested scope.
7593 Set_Discard_Names (Current_Scope);
7597 Check_Arg_Count (1);
7598 Check_Optional_Identifier (Arg1, Name_On);
7599 Check_Arg_Is_Local_Name (Arg1);
7601 E_Id := Get_Pragma_Arg (Arg1);
7603 if Etype (E_Id) = Any_Type then
7609 if (Is_First_Subtype (E)
7611 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7612 or else Ekind (E) = E_Exception
7614 Set_Discard_Names (E);
7617 ("inappropriate entity for pragma%", Arg1);
7628 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7630 when Pragma_Elaborate => Elaborate : declare
7635 -- Pragma must be in context items list of a compilation unit
7637 if not Is_In_Context_Clause then
7641 -- Must be at least one argument
7643 if Arg_Count = 0 then
7644 Error_Pragma ("pragma% requires at least one argument");
7647 -- In Ada 83 mode, there can be no items following it in the
7648 -- context list except other pragmas and implicit with clauses
7649 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7650 -- placement rule does not apply.
7652 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7654 while Present (Citem) loop
7655 if Nkind (Citem) = N_Pragma
7656 or else (Nkind (Citem) = N_With_Clause
7657 and then Implicit_With (Citem))
7662 ("(Ada 83) pragma% must be at end of context clause");
7669 -- Finally, the arguments must all be units mentioned in a with
7670 -- clause in the same context clause. Note we already checked (in
7671 -- Par.Prag) that the arguments are all identifiers or selected
7675 Outer : while Present (Arg) loop
7676 Citem := First (List_Containing (N));
7677 Inner : while Citem /= N loop
7678 if Nkind (Citem) = N_With_Clause
7679 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7681 Set_Elaborate_Present (Citem, True);
7682 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7684 -- With the pragma present, elaboration calls on
7685 -- subprograms from the named unit need no further
7686 -- checks, as long as the pragma appears in the current
7687 -- compilation unit. If the pragma appears in some unit
7688 -- in the context, there might still be a need for an
7689 -- Elaborate_All_Desirable from the current compilation
7690 -- to the named unit, so we keep the check enabled.
7692 if In_Extended_Main_Source_Unit (N) then
7693 Set_Suppress_Elaboration_Warnings
7694 (Entity (Name (Citem)));
7705 ("argument of pragma% is not with'ed unit", Arg);
7711 -- Give a warning if operating in static mode with -gnatwl
7712 -- (elaboration warnings enabled) switch set.
7714 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7716 ("?use of pragma Elaborate may not be safe", N);
7718 ("?use pragma Elaborate_All instead if possible", N);
7726 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7728 when Pragma_Elaborate_All => Elaborate_All : declare
7733 Check_Ada_83_Warning;
7735 -- Pragma must be in context items list of a compilation unit
7737 if not Is_In_Context_Clause then
7741 -- Must be at least one argument
7743 if Arg_Count = 0 then
7744 Error_Pragma ("pragma% requires at least one argument");
7747 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7748 -- have to appear at the end of the context clause, but may
7749 -- appear mixed in with other items, even in Ada 83 mode.
7751 -- Final check: the arguments must all be units mentioned in
7752 -- a with clause in the same context clause. Note that we
7753 -- already checked (in Par.Prag) that all the arguments are
7754 -- either identifiers or selected components.
7757 Outr : while Present (Arg) loop
7758 Citem := First (List_Containing (N));
7759 Innr : while Citem /= N loop
7760 if Nkind (Citem) = N_With_Clause
7761 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7763 Set_Elaborate_All_Present (Citem, True);
7764 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7766 -- Suppress warnings and elaboration checks on the named
7767 -- unit if the pragma is in the current compilation, as
7768 -- for pragma Elaborate.
7770 if In_Extended_Main_Source_Unit (N) then
7771 Set_Suppress_Elaboration_Warnings
7772 (Entity (Name (Citem)));
7781 Set_Error_Posted (N);
7783 ("argument of pragma% is not with'ed unit", Arg);
7790 --------------------
7791 -- Elaborate_Body --
7792 --------------------
7794 -- pragma Elaborate_Body [( library_unit_NAME )];
7796 when Pragma_Elaborate_Body => Elaborate_Body : declare
7797 Cunit_Node : Node_Id;
7798 Cunit_Ent : Entity_Id;
7801 Check_Ada_83_Warning;
7802 Check_Valid_Library_Unit_Pragma;
7804 if Nkind (N) = N_Null_Statement then
7808 Cunit_Node := Cunit (Current_Sem_Unit);
7809 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7811 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7814 Error_Pragma ("pragma% must refer to a spec, not a body");
7816 Set_Body_Required (Cunit_Node, True);
7817 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7819 -- If we are in dynamic elaboration mode, then we suppress
7820 -- elaboration warnings for the unit, since it is definitely
7821 -- fine NOT to do dynamic checks at the first level (and such
7822 -- checks will be suppressed because no elaboration boolean
7823 -- is created for Elaborate_Body packages).
7825 -- But in the static model of elaboration, Elaborate_Body is
7826 -- definitely NOT good enough to ensure elaboration safety on
7827 -- its own, since the body may WITH other units that are not
7828 -- safe from an elaboration point of view, so a client must
7829 -- still do an Elaborate_All on such units.
7831 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7832 -- Elaborate_Body always suppressed elab warnings.
7834 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7835 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7840 ------------------------
7841 -- Elaboration_Checks --
7842 ------------------------
7844 -- pragma Elaboration_Checks (Static | Dynamic);
7846 when Pragma_Elaboration_Checks =>
7848 Check_Arg_Count (1);
7849 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7850 Dynamic_Elaboration_Checks :=
7851 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7857 -- pragma Eliminate (
7858 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7859 -- [,[Entity =>] IDENTIFIER |
7860 -- SELECTED_COMPONENT |
7862 -- [, OVERLOADING_RESOLUTION]);
7864 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7867 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7870 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7872 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7873 -- Result_Type => result_SUBTYPE_NAME]
7875 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7876 -- SUBTYPE_NAME ::= STRING_LITERAL
7878 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7879 -- SOURCE_TRACE ::= STRING_LITERAL
7881 when Pragma_Eliminate => Eliminate : declare
7882 Args : Args_List (1 .. 5);
7883 Names : constant Name_List (1 .. 5) := (
7886 Name_Parameter_Types,
7888 Name_Source_Location);
7890 Unit_Name : Node_Id renames Args (1);
7891 Entity : Node_Id renames Args (2);
7892 Parameter_Types : Node_Id renames Args (3);
7893 Result_Type : Node_Id renames Args (4);
7894 Source_Location : Node_Id renames Args (5);
7898 Check_Valid_Configuration_Pragma;
7899 Gather_Associations (Names, Args);
7901 if No (Unit_Name) then
7902 Error_Pragma ("missing Unit_Name argument for pragma%");
7906 and then (Present (Parameter_Types)
7908 Present (Result_Type)
7910 Present (Source_Location))
7912 Error_Pragma ("missing Entity argument for pragma%");
7915 if (Present (Parameter_Types)
7917 Present (Result_Type))
7919 Present (Source_Location)
7922 ("parameter profile and source location cannot " &
7923 "be used together in pragma%");
7926 Process_Eliminate_Pragma
7940 -- [ Convention =>] convention_IDENTIFIER,
7941 -- [ Entity =>] local_NAME
7942 -- [, [External_Name =>] static_string_EXPRESSION ]
7943 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7945 when Pragma_Export => Export : declare
7949 pragma Warnings (Off, C);
7952 Check_Ada_83_Warning;
7958 Check_At_Least_N_Arguments (2);
7959 Check_At_Most_N_Arguments (4);
7960 Process_Convention (C, Def_Id);
7962 if Ekind (Def_Id) /= E_Constant then
7963 Note_Possible_Modification
7964 (Get_Pragma_Arg (Arg2), Sure => False);
7967 Process_Interface_Name (Def_Id, Arg3, Arg4);
7968 Set_Exported (Def_Id, Arg2);
7970 -- If the entity is a deferred constant, propagate the information
7971 -- to the full view, because gigi elaborates the full view only.
7973 if Ekind (Def_Id) = E_Constant
7974 and then Present (Full_View (Def_Id))
7977 Id2 : constant Entity_Id := Full_View (Def_Id);
7979 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7980 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7981 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7986 ----------------------
7987 -- Export_Exception --
7988 ----------------------
7990 -- pragma Export_Exception (
7991 -- [Internal =>] LOCAL_NAME
7992 -- [, [External =>] EXTERNAL_SYMBOL]
7993 -- [, [Form =>] Ada | VMS]
7994 -- [, [Code =>] static_integer_EXPRESSION]);
7996 when Pragma_Export_Exception => Export_Exception : declare
7997 Args : Args_List (1 .. 4);
7998 Names : constant Name_List (1 .. 4) := (
8004 Internal : Node_Id renames Args (1);
8005 External : Node_Id renames Args (2);
8006 Form : Node_Id renames Args (3);
8007 Code : Node_Id renames Args (4);
8012 if Inside_A_Generic then
8013 Error_Pragma ("pragma% cannot be used for generic entities");
8016 Gather_Associations (Names, Args);
8017 Process_Extended_Import_Export_Exception_Pragma (
8018 Arg_Internal => Internal,
8019 Arg_External => External,
8023 if not Is_VMS_Exception (Entity (Internal)) then
8024 Set_Exported (Entity (Internal), Internal);
8026 end Export_Exception;
8028 ---------------------
8029 -- Export_Function --
8030 ---------------------
8032 -- pragma Export_Function (
8033 -- [Internal =>] LOCAL_NAME
8034 -- [, [External =>] EXTERNAL_SYMBOL]
8035 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8036 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8037 -- [, [Mechanism =>] MECHANISM]
8038 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8040 -- EXTERNAL_SYMBOL ::=
8042 -- | static_string_EXPRESSION
8044 -- PARAMETER_TYPES ::=
8046 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8048 -- TYPE_DESIGNATOR ::=
8050 -- | subtype_Name ' Access
8054 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8056 -- MECHANISM_ASSOCIATION ::=
8057 -- [formal_parameter_NAME =>] MECHANISM_NAME
8059 -- MECHANISM_NAME ::=
8062 -- | Descriptor [([Class =>] CLASS_NAME)]
8064 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8066 when Pragma_Export_Function => Export_Function : declare
8067 Args : Args_List (1 .. 6);
8068 Names : constant Name_List (1 .. 6) := (
8071 Name_Parameter_Types,
8074 Name_Result_Mechanism);
8076 Internal : Node_Id renames Args (1);
8077 External : Node_Id renames Args (2);
8078 Parameter_Types : Node_Id renames Args (3);
8079 Result_Type : Node_Id renames Args (4);
8080 Mechanism : Node_Id renames Args (5);
8081 Result_Mechanism : Node_Id renames Args (6);
8085 Gather_Associations (Names, Args);
8086 Process_Extended_Import_Export_Subprogram_Pragma (
8087 Arg_Internal => Internal,
8088 Arg_External => External,
8089 Arg_Parameter_Types => Parameter_Types,
8090 Arg_Result_Type => Result_Type,
8091 Arg_Mechanism => Mechanism,
8092 Arg_Result_Mechanism => Result_Mechanism);
8093 end Export_Function;
8099 -- pragma Export_Object (
8100 -- [Internal =>] LOCAL_NAME
8101 -- [, [External =>] EXTERNAL_SYMBOL]
8102 -- [, [Size =>] EXTERNAL_SYMBOL]);
8104 -- EXTERNAL_SYMBOL ::=
8106 -- | static_string_EXPRESSION
8108 -- PARAMETER_TYPES ::=
8110 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8112 -- TYPE_DESIGNATOR ::=
8114 -- | subtype_Name ' Access
8118 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8120 -- MECHANISM_ASSOCIATION ::=
8121 -- [formal_parameter_NAME =>] MECHANISM_NAME
8123 -- MECHANISM_NAME ::=
8126 -- | Descriptor [([Class =>] CLASS_NAME)]
8128 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8130 when Pragma_Export_Object => Export_Object : declare
8131 Args : Args_List (1 .. 3);
8132 Names : constant Name_List (1 .. 3) := (
8137 Internal : Node_Id renames Args (1);
8138 External : Node_Id renames Args (2);
8139 Size : Node_Id renames Args (3);
8143 Gather_Associations (Names, Args);
8144 Process_Extended_Import_Export_Object_Pragma (
8145 Arg_Internal => Internal,
8146 Arg_External => External,
8150 ----------------------
8151 -- Export_Procedure --
8152 ----------------------
8154 -- pragma Export_Procedure (
8155 -- [Internal =>] LOCAL_NAME
8156 -- [, [External =>] EXTERNAL_SYMBOL]
8157 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8158 -- [, [Mechanism =>] MECHANISM]);
8160 -- EXTERNAL_SYMBOL ::=
8162 -- | static_string_EXPRESSION
8164 -- PARAMETER_TYPES ::=
8166 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8168 -- TYPE_DESIGNATOR ::=
8170 -- | subtype_Name ' Access
8174 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8176 -- MECHANISM_ASSOCIATION ::=
8177 -- [formal_parameter_NAME =>] MECHANISM_NAME
8179 -- MECHANISM_NAME ::=
8182 -- | Descriptor [([Class =>] CLASS_NAME)]
8184 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8186 when Pragma_Export_Procedure => Export_Procedure : declare
8187 Args : Args_List (1 .. 4);
8188 Names : constant Name_List (1 .. 4) := (
8191 Name_Parameter_Types,
8194 Internal : Node_Id renames Args (1);
8195 External : Node_Id renames Args (2);
8196 Parameter_Types : Node_Id renames Args (3);
8197 Mechanism : Node_Id renames Args (4);
8201 Gather_Associations (Names, Args);
8202 Process_Extended_Import_Export_Subprogram_Pragma (
8203 Arg_Internal => Internal,
8204 Arg_External => External,
8205 Arg_Parameter_Types => Parameter_Types,
8206 Arg_Mechanism => Mechanism);
8207 end Export_Procedure;
8213 -- pragma Export_Value (
8214 -- [Value =>] static_integer_EXPRESSION,
8215 -- [Link_Name =>] static_string_EXPRESSION);
8217 when Pragma_Export_Value =>
8219 Check_Arg_Order ((Name_Value, Name_Link_Name));
8220 Check_Arg_Count (2);
8222 Check_Optional_Identifier (Arg1, Name_Value);
8223 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8225 Check_Optional_Identifier (Arg2, Name_Link_Name);
8226 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8228 -----------------------------
8229 -- Export_Valued_Procedure --
8230 -----------------------------
8232 -- pragma Export_Valued_Procedure (
8233 -- [Internal =>] LOCAL_NAME
8234 -- [, [External =>] EXTERNAL_SYMBOL,]
8235 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8236 -- [, [Mechanism =>] MECHANISM]);
8238 -- EXTERNAL_SYMBOL ::=
8240 -- | static_string_EXPRESSION
8242 -- PARAMETER_TYPES ::=
8244 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8246 -- TYPE_DESIGNATOR ::=
8248 -- | subtype_Name ' Access
8252 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8254 -- MECHANISM_ASSOCIATION ::=
8255 -- [formal_parameter_NAME =>] MECHANISM_NAME
8257 -- MECHANISM_NAME ::=
8260 -- | Descriptor [([Class =>] CLASS_NAME)]
8262 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8264 when Pragma_Export_Valued_Procedure =>
8265 Export_Valued_Procedure : declare
8266 Args : Args_List (1 .. 4);
8267 Names : constant Name_List (1 .. 4) := (
8270 Name_Parameter_Types,
8273 Internal : Node_Id renames Args (1);
8274 External : Node_Id renames Args (2);
8275 Parameter_Types : Node_Id renames Args (3);
8276 Mechanism : Node_Id renames Args (4);
8280 Gather_Associations (Names, Args);
8281 Process_Extended_Import_Export_Subprogram_Pragma (
8282 Arg_Internal => Internal,
8283 Arg_External => External,
8284 Arg_Parameter_Types => Parameter_Types,
8285 Arg_Mechanism => Mechanism);
8286 end Export_Valued_Procedure;
8292 -- pragma Extend_System ([Name =>] Identifier);
8294 when Pragma_Extend_System => Extend_System : declare
8297 Check_Valid_Configuration_Pragma;
8298 Check_Arg_Count (1);
8299 Check_Optional_Identifier (Arg1, Name_Name);
8300 Check_Arg_Is_Identifier (Arg1);
8302 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8305 and then Name_Buffer (1 .. 4) = "aux_"
8307 if Present (System_Extend_Pragma_Arg) then
8308 if Chars (Get_Pragma_Arg (Arg1)) =
8309 Chars (Expression (System_Extend_Pragma_Arg))
8313 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8314 Error_Pragma ("pragma% conflicts with that #");
8318 System_Extend_Pragma_Arg := Arg1;
8320 if not GNAT_Mode then
8321 System_Extend_Unit := Arg1;
8325 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8329 ------------------------
8330 -- Extensions_Allowed --
8331 ------------------------
8333 -- pragma Extensions_Allowed (ON | OFF);
8335 when Pragma_Extensions_Allowed =>
8337 Check_Arg_Count (1);
8338 Check_No_Identifiers;
8339 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8341 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8342 Extensions_Allowed := True;
8343 Ada_Version := Ada_Version_Type'Last;
8346 Extensions_Allowed := False;
8347 Ada_Version := Ada_Version_Explicit;
8354 -- pragma External (
8355 -- [ Convention =>] convention_IDENTIFIER,
8356 -- [ Entity =>] local_NAME
8357 -- [, [External_Name =>] static_string_EXPRESSION ]
8358 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8360 when Pragma_External => External : declare
8364 pragma Warnings (Off, C);
8373 Check_At_Least_N_Arguments (2);
8374 Check_At_Most_N_Arguments (4);
8375 Process_Convention (C, Def_Id);
8376 Note_Possible_Modification
8377 (Get_Pragma_Arg (Arg2), Sure => False);
8378 Process_Interface_Name (Def_Id, Arg3, Arg4);
8379 Set_Exported (Def_Id, Arg2);
8382 --------------------------
8383 -- External_Name_Casing --
8384 --------------------------
8386 -- pragma External_Name_Casing (
8387 -- UPPERCASE | LOWERCASE
8388 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8390 when Pragma_External_Name_Casing => External_Name_Casing : declare
8393 Check_No_Identifiers;
8395 if Arg_Count = 2 then
8397 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8399 case Chars (Get_Pragma_Arg (Arg2)) is
8401 Opt.External_Name_Exp_Casing := As_Is;
8403 when Name_Uppercase =>
8404 Opt.External_Name_Exp_Casing := Uppercase;
8406 when Name_Lowercase =>
8407 Opt.External_Name_Exp_Casing := Lowercase;
8414 Check_Arg_Count (1);
8417 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8419 case Chars (Get_Pragma_Arg (Arg1)) is
8420 when Name_Uppercase =>
8421 Opt.External_Name_Imp_Casing := Uppercase;
8423 when Name_Lowercase =>
8424 Opt.External_Name_Imp_Casing := Lowercase;
8429 end External_Name_Casing;
8431 --------------------------
8432 -- Favor_Top_Level --
8433 --------------------------
8435 -- pragma Favor_Top_Level (type_NAME);
8437 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8438 Named_Entity : Entity_Id;
8442 Check_No_Identifiers;
8443 Check_Arg_Count (1);
8444 Check_Arg_Is_Local_Name (Arg1);
8445 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8447 -- If it's an access-to-subprogram type (in particular, not a
8448 -- subtype), set the flag on that type.
8450 if Is_Access_Subprogram_Type (Named_Entity) then
8451 Set_Can_Use_Internal_Rep (Named_Entity, False);
8453 -- Otherwise it's an error (name denotes the wrong sort of entity)
8457 ("access-to-subprogram type expected",
8458 Get_Pragma_Arg (Arg1));
8460 end Favor_Top_Level;
8466 -- pragma Fast_Math;
8468 when Pragma_Fast_Math =>
8470 Check_No_Identifiers;
8471 Check_Valid_Configuration_Pragma;
8474 ---------------------------
8475 -- Finalize_Storage_Only --
8476 ---------------------------
8478 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8480 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8481 Assoc : constant Node_Id := Arg1;
8482 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8487 Check_No_Identifiers;
8488 Check_Arg_Count (1);
8489 Check_Arg_Is_Local_Name (Arg1);
8491 Find_Type (Type_Id);
8492 Typ := Entity (Type_Id);
8495 or else Rep_Item_Too_Early (Typ, N)
8499 Typ := Underlying_Type (Typ);
8502 if not Is_Controlled (Typ) then
8503 Error_Pragma ("pragma% must specify controlled type");
8506 Check_First_Subtype (Arg1);
8508 if Finalize_Storage_Only (Typ) then
8509 Error_Pragma ("duplicate pragma%, only one allowed");
8511 elsif not Rep_Item_Too_Late (Typ, N) then
8512 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8514 end Finalize_Storage;
8516 --------------------------
8517 -- Float_Representation --
8518 --------------------------
8520 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8522 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8524 when Pragma_Float_Representation => Float_Representation : declare
8532 if Arg_Count = 1 then
8533 Check_Valid_Configuration_Pragma;
8535 Check_Arg_Count (2);
8536 Check_Optional_Identifier (Arg2, Name_Entity);
8537 Check_Arg_Is_Local_Name (Arg2);
8540 Check_No_Identifier (Arg1);
8541 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8543 if not OpenVMS_On_Target then
8544 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8546 ("?pragma% ignored (applies only to Open'V'M'S)");
8552 -- One argument case
8554 if Arg_Count = 1 then
8555 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8556 if Opt.Float_Format = 'I' then
8557 Error_Pragma ("'I'E'E'E format previously specified");
8560 Opt.Float_Format := 'V';
8563 if Opt.Float_Format = 'V' then
8564 Error_Pragma ("'V'A'X format previously specified");
8567 Opt.Float_Format := 'I';
8570 Set_Standard_Fpt_Formats;
8572 -- Two argument case
8575 Argx := Get_Pragma_Arg (Arg2);
8577 if not Is_Entity_Name (Argx)
8578 or else not Is_Floating_Point_Type (Entity (Argx))
8581 ("second argument of% pragma must be floating-point type",
8585 Ent := Entity (Argx);
8586 Digs := UI_To_Int (Digits_Value (Ent));
8588 -- Two arguments, VAX_Float case
8590 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8592 when 6 => Set_F_Float (Ent);
8593 when 9 => Set_D_Float (Ent);
8594 when 15 => Set_G_Float (Ent);
8598 ("wrong digits value, must be 6,9 or 15", Arg2);
8601 -- Two arguments, IEEE_Float case
8605 when 6 => Set_IEEE_Short (Ent);
8606 when 15 => Set_IEEE_Long (Ent);
8610 ("wrong digits value, must be 6 or 15", Arg2);
8614 end Float_Representation;
8620 -- pragma Ident (static_string_EXPRESSION)
8622 -- Note: pragma Comment shares this processing. Pragma Comment is
8623 -- identical to Ident, except that the restriction of the argument to
8624 -- 31 characters and the placement restrictions are not enforced for
8627 when Pragma_Ident | Pragma_Comment => Ident : declare
8632 Check_Arg_Count (1);
8633 Check_No_Identifiers;
8634 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8637 -- For pragma Ident, preserve DEC compatibility by requiring the
8638 -- pragma to appear in a declarative part or package spec.
8640 if Prag_Id = Pragma_Ident then
8641 Check_Is_In_Decl_Part_Or_Package_Spec;
8644 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8651 GP := Parent (Parent (N));
8653 if Nkind_In (GP, N_Package_Declaration,
8654 N_Generic_Package_Declaration)
8659 -- If we have a compilation unit, then record the ident value,
8660 -- checking for improper duplication.
8662 if Nkind (GP) = N_Compilation_Unit then
8663 CS := Ident_String (Current_Sem_Unit);
8665 if Present (CS) then
8667 -- For Ident, we do not permit multiple instances
8669 if Prag_Id = Pragma_Ident then
8670 Error_Pragma ("duplicate% pragma not permitted");
8672 -- For Comment, we concatenate the string, unless we want
8673 -- to preserve the tree structure for ASIS.
8675 elsif not ASIS_Mode then
8676 Start_String (Strval (CS));
8677 Store_String_Char (' ');
8678 Store_String_Chars (Strval (Str));
8679 Set_Strval (CS, End_String);
8683 -- In VMS, the effect of IDENT is achieved by passing
8684 -- --identification=name as a --for-linker switch.
8686 if OpenVMS_On_Target then
8689 ("--for-linker=--identification=");
8690 String_To_Name_Buffer (Strval (Str));
8691 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8693 -- Only the last processed IDENT is saved. The main
8694 -- purpose is so an IDENT associated with a main
8695 -- procedure will be used in preference to an IDENT
8696 -- associated with a with'd package.
8698 Replace_Linker_Option_String
8699 (End_String, "--for-linker=--identification=");
8702 Set_Ident_String (Current_Sem_Unit, Str);
8705 -- For subunits, we just ignore the Ident, since in GNAT these
8706 -- are not separate object files, and hence not separate units
8707 -- in the unit table.
8709 elsif Nkind (GP) = N_Subunit then
8712 -- Otherwise we have a misplaced pragma Ident, but we ignore
8713 -- this if we are in an instantiation, since it comes from
8714 -- a generic, and has no relevance to the instantiation.
8716 elsif Prag_Id = Pragma_Ident then
8717 if Instantiation_Location (Loc) = No_Location then
8718 Error_Pragma ("pragma% only allowed at outer level");
8728 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8729 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8731 when Pragma_Implemented => Implemented : declare
8732 Proc_Id : Entity_Id;
8737 Check_Arg_Count (2);
8738 Check_No_Identifiers;
8739 Check_Arg_Is_Identifier (Arg1);
8740 Check_Arg_Is_Local_Name (Arg1);
8742 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8744 -- Extract the name of the local procedure
8746 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8748 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8749 -- primitive procedure of a synchronized tagged type.
8751 if Ekind (Proc_Id) = E_Procedure
8752 and then Is_Primitive (Proc_Id)
8753 and then Present (First_Formal (Proc_Id))
8755 Typ := Etype (First_Formal (Proc_Id));
8757 if Is_Tagged_Type (Typ)
8760 -- Check for a protected, a synchronized or a task interface
8762 ((Is_Interface (Typ)
8763 and then Is_Synchronized_Interface (Typ))
8765 -- Check for a protected type or a task type that implements
8769 (Is_Concurrent_Record_Type (Typ)
8770 and then Present (Interfaces (Typ)))
8772 -- Check for a private record extension with keyword
8776 (Ekind_In (Typ, E_Record_Type_With_Private,
8777 E_Record_Subtype_With_Private)
8778 and then Synchronized_Present (Parent (Typ))))
8783 ("controlling formal must be of synchronized " &
8784 "tagged type", Arg1);
8788 -- Procedures declared inside a protected type must be accepted
8790 elsif Ekind (Proc_Id) = E_Procedure
8791 and then Is_Protected_Type (Scope (Proc_Id))
8795 -- The first argument is not a primitive procedure
8799 ("pragma % must be applied to a primitive procedure", Arg1);
8803 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8804 -- By_Protected_Procedure to the primitive procedure of a task
8807 if Chars (Arg2) = Name_By_Protected_Procedure
8808 and then Is_Interface (Typ)
8809 and then Is_Task_Interface (Typ)
8812 ("implementation kind By_Protected_Procedure cannot be " &
8813 "applied to a task interface primitive", Arg2);
8817 Record_Rep_Item (Proc_Id, N);
8820 ----------------------
8821 -- Implicit_Packing --
8822 ----------------------
8824 -- pragma Implicit_Packing;
8826 when Pragma_Implicit_Packing =>
8828 Check_Arg_Count (0);
8829 Implicit_Packing := True;
8836 -- [Convention =>] convention_IDENTIFIER,
8837 -- [Entity =>] local_NAME
8838 -- [, [External_Name =>] static_string_EXPRESSION ]
8839 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8841 when Pragma_Import =>
8842 Check_Ada_83_Warning;
8848 Check_At_Least_N_Arguments (2);
8849 Check_At_Most_N_Arguments (4);
8850 Process_Import_Or_Interface;
8852 ----------------------
8853 -- Import_Exception --
8854 ----------------------
8856 -- pragma Import_Exception (
8857 -- [Internal =>] LOCAL_NAME
8858 -- [, [External =>] EXTERNAL_SYMBOL]
8859 -- [, [Form =>] Ada | VMS]
8860 -- [, [Code =>] static_integer_EXPRESSION]);
8862 when Pragma_Import_Exception => Import_Exception : declare
8863 Args : Args_List (1 .. 4);
8864 Names : constant Name_List (1 .. 4) := (
8870 Internal : Node_Id renames Args (1);
8871 External : Node_Id renames Args (2);
8872 Form : Node_Id renames Args (3);
8873 Code : Node_Id renames Args (4);
8877 Gather_Associations (Names, Args);
8879 if Present (External) and then Present (Code) then
8881 ("cannot give both External and Code options for pragma%");
8884 Process_Extended_Import_Export_Exception_Pragma (
8885 Arg_Internal => Internal,
8886 Arg_External => External,
8890 if not Is_VMS_Exception (Entity (Internal)) then
8891 Set_Imported (Entity (Internal));
8893 end Import_Exception;
8895 ---------------------
8896 -- Import_Function --
8897 ---------------------
8899 -- pragma Import_Function (
8900 -- [Internal =>] LOCAL_NAME,
8901 -- [, [External =>] EXTERNAL_SYMBOL]
8902 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8903 -- [, [Result_Type =>] SUBTYPE_MARK]
8904 -- [, [Mechanism =>] MECHANISM]
8905 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8906 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8908 -- EXTERNAL_SYMBOL ::=
8910 -- | static_string_EXPRESSION
8912 -- PARAMETER_TYPES ::=
8914 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8916 -- TYPE_DESIGNATOR ::=
8918 -- | subtype_Name ' Access
8922 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8924 -- MECHANISM_ASSOCIATION ::=
8925 -- [formal_parameter_NAME =>] MECHANISM_NAME
8927 -- MECHANISM_NAME ::=
8930 -- | Descriptor [([Class =>] CLASS_NAME)]
8932 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8934 when Pragma_Import_Function => Import_Function : declare
8935 Args : Args_List (1 .. 7);
8936 Names : constant Name_List (1 .. 7) := (
8939 Name_Parameter_Types,
8942 Name_Result_Mechanism,
8943 Name_First_Optional_Parameter);
8945 Internal : Node_Id renames Args (1);
8946 External : Node_Id renames Args (2);
8947 Parameter_Types : Node_Id renames Args (3);
8948 Result_Type : Node_Id renames Args (4);
8949 Mechanism : Node_Id renames Args (5);
8950 Result_Mechanism : Node_Id renames Args (6);
8951 First_Optional_Parameter : Node_Id renames Args (7);
8955 Gather_Associations (Names, Args);
8956 Process_Extended_Import_Export_Subprogram_Pragma (
8957 Arg_Internal => Internal,
8958 Arg_External => External,
8959 Arg_Parameter_Types => Parameter_Types,
8960 Arg_Result_Type => Result_Type,
8961 Arg_Mechanism => Mechanism,
8962 Arg_Result_Mechanism => Result_Mechanism,
8963 Arg_First_Optional_Parameter => First_Optional_Parameter);
8964 end Import_Function;
8970 -- pragma Import_Object (
8971 -- [Internal =>] LOCAL_NAME
8972 -- [, [External =>] EXTERNAL_SYMBOL]
8973 -- [, [Size =>] EXTERNAL_SYMBOL]);
8975 -- EXTERNAL_SYMBOL ::=
8977 -- | static_string_EXPRESSION
8979 when Pragma_Import_Object => Import_Object : declare
8980 Args : Args_List (1 .. 3);
8981 Names : constant Name_List (1 .. 3) := (
8986 Internal : Node_Id renames Args (1);
8987 External : Node_Id renames Args (2);
8988 Size : Node_Id renames Args (3);
8992 Gather_Associations (Names, Args);
8993 Process_Extended_Import_Export_Object_Pragma (
8994 Arg_Internal => Internal,
8995 Arg_External => External,
8999 ----------------------
9000 -- Import_Procedure --
9001 ----------------------
9003 -- pragma Import_Procedure (
9004 -- [Internal =>] LOCAL_NAME
9005 -- [, [External =>] EXTERNAL_SYMBOL]
9006 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9007 -- [, [Mechanism =>] MECHANISM]
9008 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9010 -- EXTERNAL_SYMBOL ::=
9012 -- | static_string_EXPRESSION
9014 -- PARAMETER_TYPES ::=
9016 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9018 -- TYPE_DESIGNATOR ::=
9020 -- | subtype_Name ' Access
9024 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9026 -- MECHANISM_ASSOCIATION ::=
9027 -- [formal_parameter_NAME =>] MECHANISM_NAME
9029 -- MECHANISM_NAME ::=
9032 -- | Descriptor [([Class =>] CLASS_NAME)]
9034 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9036 when Pragma_Import_Procedure => Import_Procedure : declare
9037 Args : Args_List (1 .. 5);
9038 Names : constant Name_List (1 .. 5) := (
9041 Name_Parameter_Types,
9043 Name_First_Optional_Parameter);
9045 Internal : Node_Id renames Args (1);
9046 External : Node_Id renames Args (2);
9047 Parameter_Types : Node_Id renames Args (3);
9048 Mechanism : Node_Id renames Args (4);
9049 First_Optional_Parameter : Node_Id renames Args (5);
9053 Gather_Associations (Names, Args);
9054 Process_Extended_Import_Export_Subprogram_Pragma (
9055 Arg_Internal => Internal,
9056 Arg_External => External,
9057 Arg_Parameter_Types => Parameter_Types,
9058 Arg_Mechanism => Mechanism,
9059 Arg_First_Optional_Parameter => First_Optional_Parameter);
9060 end Import_Procedure;
9062 -----------------------------
9063 -- Import_Valued_Procedure --
9064 -----------------------------
9066 -- pragma Import_Valued_Procedure (
9067 -- [Internal =>] LOCAL_NAME
9068 -- [, [External =>] EXTERNAL_SYMBOL]
9069 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9070 -- [, [Mechanism =>] MECHANISM]
9071 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9073 -- EXTERNAL_SYMBOL ::=
9075 -- | static_string_EXPRESSION
9077 -- PARAMETER_TYPES ::=
9079 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9081 -- TYPE_DESIGNATOR ::=
9083 -- | subtype_Name ' Access
9087 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9089 -- MECHANISM_ASSOCIATION ::=
9090 -- [formal_parameter_NAME =>] MECHANISM_NAME
9092 -- MECHANISM_NAME ::=
9095 -- | Descriptor [([Class =>] CLASS_NAME)]
9097 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9099 when Pragma_Import_Valued_Procedure =>
9100 Import_Valued_Procedure : declare
9101 Args : Args_List (1 .. 5);
9102 Names : constant Name_List (1 .. 5) := (
9105 Name_Parameter_Types,
9107 Name_First_Optional_Parameter);
9109 Internal : Node_Id renames Args (1);
9110 External : Node_Id renames Args (2);
9111 Parameter_Types : Node_Id renames Args (3);
9112 Mechanism : Node_Id renames Args (4);
9113 First_Optional_Parameter : Node_Id renames Args (5);
9117 Gather_Associations (Names, Args);
9118 Process_Extended_Import_Export_Subprogram_Pragma (
9119 Arg_Internal => Internal,
9120 Arg_External => External,
9121 Arg_Parameter_Types => Parameter_Types,
9122 Arg_Mechanism => Mechanism,
9123 Arg_First_Optional_Parameter => First_Optional_Parameter);
9124 end Import_Valued_Procedure;
9130 -- pragma Independent (LOCAL_NAME);
9132 when Pragma_Independent => Independent : declare
9139 Check_Ada_83_Warning;
9141 Check_No_Identifiers;
9142 Check_Arg_Count (1);
9143 Check_Arg_Is_Local_Name (Arg1);
9144 E_Id := Get_Pragma_Arg (Arg1);
9146 if Etype (E_Id) = Any_Type then
9151 D := Declaration_Node (E);
9154 -- Check duplicate before we chain ourselves!
9156 Check_Duplicate_Pragma (E);
9158 -- Check appropriate entity
9161 if Rep_Item_Too_Early (E, N)
9163 Rep_Item_Too_Late (E, N)
9167 Check_First_Subtype (Arg1);
9170 elsif K = N_Object_Declaration
9171 or else (K = N_Component_Declaration
9172 and then Original_Record_Component (E) = E)
9174 if Rep_Item_Too_Late (E, N) then
9180 ("inappropriate entity for pragma%", Arg1);
9183 Independence_Checks.Append ((N, E));
9186 ----------------------------
9187 -- Independent_Components --
9188 ----------------------------
9190 -- pragma Atomic_Components (array_LOCAL_NAME);
9192 -- This processing is shared by Volatile_Components
9194 when Pragma_Independent_Components => Independent_Components : declare
9201 Check_Ada_83_Warning;
9203 Check_No_Identifiers;
9204 Check_Arg_Count (1);
9205 Check_Arg_Is_Local_Name (Arg1);
9206 E_Id := Get_Pragma_Arg (Arg1);
9208 if Etype (E_Id) = Any_Type then
9214 -- Check duplicate before we chain ourselves!
9216 Check_Duplicate_Pragma (E);
9218 -- Check appropriate entity
9220 if Rep_Item_Too_Early (E, N)
9222 Rep_Item_Too_Late (E, N)
9227 D := Declaration_Node (E);
9230 if (K = N_Full_Type_Declaration
9231 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9233 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9234 and then Nkind (D) = N_Object_Declaration
9235 and then Nkind (Object_Definition (D)) =
9236 N_Constrained_Array_Definition)
9238 Independence_Checks.Append ((N, E));
9241 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9243 end Independent_Components;
9245 ------------------------
9246 -- Initialize_Scalars --
9247 ------------------------
9249 -- pragma Initialize_Scalars;
9251 when Pragma_Initialize_Scalars =>
9253 Check_Arg_Count (0);
9254 Check_Valid_Configuration_Pragma;
9255 Check_Restriction (No_Initialize_Scalars, N);
9257 -- Initialize_Scalars creates false positives in CodePeer,
9258 -- so ignore this pragma in this mode.
9260 if not Restriction_Active (No_Initialize_Scalars)
9261 and then not CodePeer_Mode
9263 Init_Or_Norm_Scalars := True;
9264 Initialize_Scalars := True;
9271 -- pragma Inline ( NAME {, NAME} );
9273 when Pragma_Inline =>
9275 -- Pragma is active if inlining option is active
9277 Process_Inline (Inline_Active);
9283 -- pragma Inline_Always ( NAME {, NAME} );
9285 when Pragma_Inline_Always =>
9288 -- Pragma always active unless in CodePeer mode, since this causes
9289 -- walk order issues.
9291 if not CodePeer_Mode then
9292 Process_Inline (True);
9295 --------------------
9296 -- Inline_Generic --
9297 --------------------
9299 -- pragma Inline_Generic (NAME {, NAME});
9301 when Pragma_Inline_Generic =>
9303 Process_Generic_List;
9305 ----------------------
9306 -- Inspection_Point --
9307 ----------------------
9309 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9311 when Pragma_Inspection_Point => Inspection_Point : declare
9316 if Arg_Count > 0 then
9319 Exp := Get_Pragma_Arg (Arg);
9322 if not Is_Entity_Name (Exp)
9323 or else not Is_Object (Entity (Exp))
9325 Error_Pragma_Arg ("object name required", Arg);
9332 end Inspection_Point;
9338 -- pragma Interface (
9339 -- [ Convention =>] convention_IDENTIFIER,
9340 -- [ Entity =>] local_NAME
9341 -- [, [External_Name =>] static_string_EXPRESSION ]
9342 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9344 when Pragma_Interface =>
9351 Check_At_Least_N_Arguments (2);
9352 Check_At_Most_N_Arguments (4);
9353 Process_Import_Or_Interface;
9355 -- In Ada 2005, the permission to use Interface (a reserved word)
9356 -- as a pragma name is considered an obsolescent feature.
9358 if Ada_Version >= Ada_2005 then
9360 (No_Obsolescent_Features, Pragma_Identifier (N));
9363 --------------------
9364 -- Interface_Name --
9365 --------------------
9367 -- pragma Interface_Name (
9368 -- [ Entity =>] local_NAME
9369 -- [,[External_Name =>] static_string_EXPRESSION ]
9370 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9372 when Pragma_Interface_Name => Interface_Name : declare
9381 ((Name_Entity, Name_External_Name, Name_Link_Name));
9382 Check_At_Least_N_Arguments (2);
9383 Check_At_Most_N_Arguments (3);
9384 Id := Get_Pragma_Arg (Arg1);
9387 if not Is_Entity_Name (Id) then
9389 ("first argument for pragma% must be entity name", Arg1);
9390 elsif Etype (Id) = Any_Type then
9393 Def_Id := Entity (Id);
9396 -- Special DEC-compatible processing for the object case, forces
9397 -- object to be imported.
9399 if Ekind (Def_Id) = E_Variable then
9400 Kill_Size_Check_Code (Def_Id);
9401 Note_Possible_Modification (Id, Sure => False);
9403 -- Initialization is not allowed for imported variable
9405 if Present (Expression (Parent (Def_Id)))
9406 and then Comes_From_Source (Expression (Parent (Def_Id)))
9408 Error_Msg_Sloc := Sloc (Def_Id);
9410 ("no initialization allowed for declaration of& #",
9414 -- For compatibility, support VADS usage of providing both
9415 -- pragmas Interface and Interface_Name to obtain the effect
9416 -- of a single Import pragma.
9418 if Is_Imported (Def_Id)
9419 and then Present (First_Rep_Item (Def_Id))
9420 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9422 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9426 Set_Imported (Def_Id);
9429 Set_Is_Public (Def_Id);
9430 Process_Interface_Name (Def_Id, Arg2, Arg3);
9433 -- Otherwise must be subprogram
9435 elsif not Is_Subprogram (Def_Id) then
9437 ("argument of pragma% is not subprogram", Arg1);
9440 Check_At_Most_N_Arguments (3);
9444 -- Loop through homonyms
9447 Def_Id := Get_Base_Subprogram (Hom_Id);
9449 if Is_Imported (Def_Id) then
9450 Process_Interface_Name (Def_Id, Arg2, Arg3);
9454 exit when From_Aspect_Specification (N);
9455 Hom_Id := Homonym (Hom_Id);
9457 exit when No (Hom_Id)
9458 or else Scope (Hom_Id) /= Current_Scope;
9463 ("argument of pragma% is not imported subprogram",
9469 -----------------------
9470 -- Interrupt_Handler --
9471 -----------------------
9473 -- pragma Interrupt_Handler (handler_NAME);
9475 when Pragma_Interrupt_Handler =>
9476 Check_Ada_83_Warning;
9477 Check_Arg_Count (1);
9478 Check_No_Identifiers;
9480 if No_Run_Time_Mode then
9481 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9483 Check_Interrupt_Or_Attach_Handler;
9484 Process_Interrupt_Or_Attach_Handler;
9487 ------------------------
9488 -- Interrupt_Priority --
9489 ------------------------
9491 -- pragma Interrupt_Priority [(EXPRESSION)];
9493 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9494 P : constant Node_Id := Parent (N);
9498 Check_Ada_83_Warning;
9500 if Arg_Count /= 0 then
9501 Arg := Get_Pragma_Arg (Arg1);
9502 Check_Arg_Count (1);
9503 Check_No_Identifiers;
9505 -- The expression must be analyzed in the special manner
9506 -- described in "Handling of Default and Per-Object
9507 -- Expressions" in sem.ads.
9509 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9512 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9516 elsif Has_Pragma_Priority (P) then
9517 Error_Pragma ("duplicate pragma% not allowed");
9520 Set_Has_Pragma_Priority (P, True);
9521 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9523 end Interrupt_Priority;
9525 ---------------------
9526 -- Interrupt_State --
9527 ---------------------
9529 -- pragma Interrupt_State (
9530 -- [Name =>] INTERRUPT_ID,
9531 -- [State =>] INTERRUPT_STATE);
9533 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9534 -- INTERRUPT_STATE => System | Runtime | User
9536 -- Note: if the interrupt id is given as an identifier, then it must
9537 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9538 -- given as a static integer expression which must be in the range of
9539 -- Ada.Interrupts.Interrupt_ID.
9541 when Pragma_Interrupt_State => Interrupt_State : declare
9543 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9544 -- This is the entity Ada.Interrupts.Interrupt_ID;
9546 State_Type : Character;
9547 -- Set to 's'/'r'/'u' for System/Runtime/User
9550 -- Index to entry in Interrupt_States table
9553 -- Value of interrupt
9555 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9556 -- The first argument to the pragma
9558 Int_Ent : Entity_Id;
9559 -- Interrupt entity in Ada.Interrupts.Names
9563 Check_Arg_Order ((Name_Name, Name_State));
9564 Check_Arg_Count (2);
9566 Check_Optional_Identifier (Arg1, Name_Name);
9567 Check_Optional_Identifier (Arg2, Name_State);
9568 Check_Arg_Is_Identifier (Arg2);
9570 -- First argument is identifier
9572 if Nkind (Arg1X) = N_Identifier then
9574 -- Search list of names in Ada.Interrupts.Names
9576 Int_Ent := First_Entity (RTE (RE_Names));
9578 if No (Int_Ent) then
9579 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9581 elsif Chars (Int_Ent) = Chars (Arg1X) then
9582 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9586 Next_Entity (Int_Ent);
9589 -- First argument is not an identifier, so it must be a static
9590 -- expression of type Ada.Interrupts.Interrupt_ID.
9593 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9594 Int_Val := Expr_Value (Arg1X);
9596 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9598 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9601 ("value not in range of type " &
9602 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9608 case Chars (Get_Pragma_Arg (Arg2)) is
9609 when Name_Runtime => State_Type := 'r';
9610 when Name_System => State_Type := 's';
9611 when Name_User => State_Type := 'u';
9614 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9617 -- Check if entry is already stored
9619 IST_Num := Interrupt_States.First;
9621 -- If entry not found, add it
9623 if IST_Num > Interrupt_States.Last then
9624 Interrupt_States.Append
9625 ((Interrupt_Number => UI_To_Int (Int_Val),
9626 Interrupt_State => State_Type,
9627 Pragma_Loc => Loc));
9630 -- Case of entry for the same entry
9632 elsif Int_Val = Interrupt_States.Table (IST_Num).
9635 -- If state matches, done, no need to make redundant entry
9638 State_Type = Interrupt_States.Table (IST_Num).
9641 -- Otherwise if state does not match, error
9644 Interrupt_States.Table (IST_Num).Pragma_Loc;
9646 ("state conflicts with that given #", Arg2);
9650 IST_Num := IST_Num + 1;
9652 end Interrupt_State;
9659 -- ([Entity =>] type_LOCAL_NAME,
9660 -- [Check =>] EXPRESSION
9661 -- [,[Message =>] String_Expression]);
9663 when Pragma_Invariant => Invariant : declare
9668 pragma Unreferenced (Discard);
9672 Check_At_Least_N_Arguments (2);
9673 Check_At_Most_N_Arguments (3);
9674 Check_Optional_Identifier (Arg1, Name_Entity);
9675 Check_Optional_Identifier (Arg2, Name_Check);
9677 if Arg_Count = 3 then
9678 Check_Optional_Identifier (Arg3, Name_Message);
9679 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9682 Check_Arg_Is_Local_Name (Arg1);
9684 Type_Id := Get_Pragma_Arg (Arg1);
9685 Find_Type (Type_Id);
9686 Typ := Entity (Type_Id);
9688 if Typ = Any_Type then
9691 elsif not Ekind_In (Typ, E_Private_Type,
9692 E_Record_Type_With_Private,
9693 E_Limited_Private_Type)
9696 ("pragma% only allowed for private type", Arg1);
9699 -- Note that the type has at least one invariant, and also that
9700 -- it has inheritable invariants if we have Invariant'Class.
9702 Set_Has_Invariants (Typ);
9704 if Class_Present (N) then
9705 Set_Has_Inheritable_Invariants (Typ);
9708 -- The remaining processing is simply to link the pragma on to
9709 -- the rep item chain, for processing when the type is frozen.
9710 -- This is accomplished by a call to Rep_Item_Too_Late.
9712 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9715 ----------------------
9716 -- Java_Constructor --
9717 ----------------------
9719 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9721 -- Also handles pragma CIL_Constructor
9723 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9724 Java_Constructor : declare
9725 Convention : Convention_Id;
9729 This_Formal : Entity_Id;
9733 Check_Arg_Count (1);
9734 Check_Optional_Identifier (Arg1, Name_Entity);
9735 Check_Arg_Is_Local_Name (Arg1);
9737 Id := Get_Pragma_Arg (Arg1);
9738 Find_Program_Unit_Name (Id);
9740 -- If we did not find the name, we are done
9742 if Etype (Id) = Any_Type then
9746 -- Check wrong use of pragma in wrong VM target
9748 if VM_Target = No_VM then
9751 elsif VM_Target = CLI_Target
9752 and then Prag_Id = Pragma_Java_Constructor
9754 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9756 elsif VM_Target = JVM_Target
9757 and then Prag_Id = Pragma_CIL_Constructor
9759 Error_Pragma ("must use pragma 'Java_'Constructor");
9763 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9764 when Pragma_Java_Constructor => Convention := Convention_Java;
9765 when others => null;
9768 Hom_Id := Entity (Id);
9770 -- Loop through homonyms
9773 Def_Id := Get_Base_Subprogram (Hom_Id);
9775 -- The constructor is required to be a function
9777 if Ekind (Def_Id) /= E_Function then
9778 if VM_Target = JVM_Target then
9780 ("pragma% requires function returning a " &
9781 "'Java access type", Def_Id);
9784 ("pragma% requires function returning a " &
9785 "'C'I'L access type", Def_Id);
9789 -- Check arguments: For tagged type the first formal must be
9790 -- named "this" and its type must be a named access type
9791 -- designating a class-wide tagged type that has convention
9792 -- CIL/Java. The first formal must also have a null default
9793 -- value. For example:
9795 -- type Typ is tagged ...
9796 -- type Ref is access all Typ;
9797 -- pragma Convention (CIL, Typ);
9799 -- function New_Typ (This : Ref) return Ref;
9800 -- function New_Typ (This : Ref; I : Integer) return Ref;
9801 -- pragma Cil_Constructor (New_Typ);
9803 -- Reason: The first formal must NOT be a primitive of the
9806 -- This rule also applies to constructors of delegates used
9807 -- to interface with standard target libraries. For example:
9809 -- type Delegate is access procedure ...
9810 -- pragma Import (CIL, Delegate, ...);
9812 -- function new_Delegate
9813 -- (This : Delegate := null; ... ) return Delegate;
9815 -- For value-types this rule does not apply.
9817 if not Is_Value_Type (Etype (Def_Id)) then
9818 if No (First_Formal (Def_Id)) then
9819 Error_Msg_Name_1 := Pname;
9820 Error_Msg_N ("% function must have parameters", Def_Id);
9824 -- In the JRE library we have several occurrences in which
9825 -- the "this" parameter is not the first formal.
9827 This_Formal := First_Formal (Def_Id);
9829 -- In the JRE library we have several occurrences in which
9830 -- the "this" parameter is not the first formal. Search for
9833 if VM_Target = JVM_Target then
9834 while Present (This_Formal)
9835 and then Get_Name_String (Chars (This_Formal)) /= "this"
9837 Next_Formal (This_Formal);
9840 if No (This_Formal) then
9841 This_Formal := First_Formal (Def_Id);
9845 -- Warning: The first parameter should be named "this".
9846 -- We temporarily allow it because we have the following
9847 -- case in the Java runtime (file s-osinte.ads) ???
9849 -- function new_Thread
9850 -- (Self_Id : System.Address) return Thread_Id;
9851 -- pragma Java_Constructor (new_Thread);
9853 if VM_Target = JVM_Target
9854 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9856 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9860 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9861 Error_Msg_Name_1 := Pname;
9863 ("first formal of % function must be named `this`",
9864 Parent (This_Formal));
9866 elsif not Is_Access_Type (Etype (This_Formal)) then
9867 Error_Msg_Name_1 := Pname;
9869 ("first formal of % function must be an access type",
9870 Parameter_Type (Parent (This_Formal)));
9872 -- For delegates the type of the first formal must be a
9873 -- named access-to-subprogram type (see previous example)
9875 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9876 and then Ekind (Etype (This_Formal))
9877 /= E_Access_Subprogram_Type
9879 Error_Msg_Name_1 := Pname;
9881 ("first formal of % function must be a named access" &
9882 " to subprogram type",
9883 Parameter_Type (Parent (This_Formal)));
9885 -- Warning: We should reject anonymous access types because
9886 -- the constructor must not be handled as a primitive of the
9887 -- tagged type. We temporarily allow it because this profile
9888 -- is currently generated by cil2ada???
9890 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9891 and then not Ekind_In (Etype (This_Formal),
9893 E_General_Access_Type,
9894 E_Anonymous_Access_Type)
9896 Error_Msg_Name_1 := Pname;
9898 ("first formal of % function must be a named access" &
9900 Parameter_Type (Parent (This_Formal)));
9902 elsif Atree.Convention
9903 (Designated_Type (Etype (This_Formal))) /= Convention
9905 Error_Msg_Name_1 := Pname;
9907 if Convention = Convention_Java then
9909 ("pragma% requires convention 'Cil in designated" &
9911 Parameter_Type (Parent (This_Formal)));
9914 ("pragma% requires convention 'Java in designated" &
9916 Parameter_Type (Parent (This_Formal)));
9919 elsif No (Expression (Parent (This_Formal)))
9920 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9922 Error_Msg_Name_1 := Pname;
9924 ("pragma% requires first formal with default `null`",
9925 Parameter_Type (Parent (This_Formal)));
9929 -- Check result type: the constructor must be a function
9931 -- * a value type (only allowed in the CIL compiler)
9932 -- * an access-to-subprogram type with convention Java/CIL
9933 -- * an access-type designating a type that has convention
9936 if Is_Value_Type (Etype (Def_Id)) then
9939 -- Access-to-subprogram type with convention Java/CIL
9941 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9942 if Atree.Convention (Etype (Def_Id)) /= Convention then
9943 if Convention = Convention_Java then
9945 ("pragma% requires function returning a " &
9946 "'Java access type", Arg1);
9948 pragma Assert (Convention = Convention_CIL);
9950 ("pragma% requires function returning a " &
9951 "'C'I'L access type", Arg1);
9955 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9956 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9957 E_General_Access_Type)
9960 (Designated_Type (Etype (Def_Id))) /= Convention
9962 Error_Msg_Name_1 := Pname;
9964 if Convention = Convention_Java then
9966 ("pragma% requires function returning a named" &
9967 "'Java access type", Arg1);
9970 ("pragma% requires function returning a named" &
9971 "'C'I'L access type", Arg1);
9976 Set_Is_Constructor (Def_Id);
9977 Set_Convention (Def_Id, Convention);
9978 Set_Is_Imported (Def_Id);
9980 exit when From_Aspect_Specification (N);
9981 Hom_Id := Homonym (Hom_Id);
9983 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9985 end Java_Constructor;
9987 ----------------------
9988 -- Java_Interface --
9989 ----------------------
9991 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9993 when Pragma_Java_Interface => Java_Interface : declare
9999 Check_Arg_Count (1);
10000 Check_Optional_Identifier (Arg1, Name_Entity);
10001 Check_Arg_Is_Local_Name (Arg1);
10003 Arg := Get_Pragma_Arg (Arg1);
10006 if Etype (Arg) = Any_Type then
10010 if not Is_Entity_Name (Arg)
10011 or else not Is_Type (Entity (Arg))
10013 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10016 Typ := Underlying_Type (Entity (Arg));
10018 -- For now simply check some of the semantic constraints on the
10019 -- type. This currently leaves out some restrictions on interface
10020 -- types, namely that the parent type must be java.lang.Object.Typ
10021 -- and that all primitives of the type should be declared
10024 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10025 Error_Pragma_Arg ("pragma% requires an abstract "
10026 & "tagged type", Arg1);
10028 elsif not Has_Discriminants (Typ)
10029 or else Ekind (Etype (First_Discriminant (Typ)))
10030 /= E_Anonymous_Access_Type
10032 not Is_Class_Wide_Type
10033 (Designated_Type (Etype (First_Discriminant (Typ))))
10036 ("type must have a class-wide access discriminant", Arg1);
10038 end Java_Interface;
10044 -- pragma Keep_Names ([On => ] local_NAME);
10046 when Pragma_Keep_Names => Keep_Names : declare
10051 Check_Arg_Count (1);
10052 Check_Optional_Identifier (Arg1, Name_On);
10053 Check_Arg_Is_Local_Name (Arg1);
10055 Arg := Get_Pragma_Arg (Arg1);
10058 if Etype (Arg) = Any_Type then
10062 if not Is_Entity_Name (Arg)
10063 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10066 ("pragma% requires a local enumeration type", Arg1);
10069 Set_Discard_Names (Entity (Arg), False);
10076 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10078 when Pragma_License =>
10080 Check_Arg_Count (1);
10081 Check_No_Identifiers;
10082 Check_Valid_Configuration_Pragma;
10083 Check_Arg_Is_Identifier (Arg1);
10086 Sind : constant Source_File_Index :=
10087 Source_Index (Current_Sem_Unit);
10090 case Chars (Get_Pragma_Arg (Arg1)) is
10092 Set_License (Sind, GPL);
10094 when Name_Modified_GPL =>
10095 Set_License (Sind, Modified_GPL);
10097 when Name_Restricted =>
10098 Set_License (Sind, Restricted);
10100 when Name_Unrestricted =>
10101 Set_License (Sind, Unrestricted);
10104 Error_Pragma_Arg ("invalid license name", Arg1);
10112 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10114 when Pragma_Link_With => Link_With : declare
10120 if Operating_Mode = Generate_Code
10121 and then In_Extended_Main_Source_Unit (N)
10123 Check_At_Least_N_Arguments (1);
10124 Check_No_Identifiers;
10125 Check_Is_In_Decl_Part_Or_Package_Spec;
10126 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10130 while Present (Arg) loop
10131 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10133 -- Store argument, converting sequences of spaces to a
10134 -- single null character (this is one of the differences
10135 -- in processing between Link_With and Linker_Options).
10137 Arg_Store : declare
10138 C : constant Char_Code := Get_Char_Code (' ');
10139 S : constant String_Id :=
10140 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10141 L : constant Nat := String_Length (S);
10144 procedure Skip_Spaces;
10145 -- Advance F past any spaces
10151 procedure Skip_Spaces is
10153 while F <= L and then Get_String_Char (S, F) = C loop
10158 -- Start of processing for Arg_Store
10161 Skip_Spaces; -- skip leading spaces
10163 -- Loop through characters, changing any embedded
10164 -- sequence of spaces to a single null character (this
10165 -- is how Link_With/Linker_Options differ)
10168 if Get_String_Char (S, F) = C then
10171 Store_String_Char (ASCII.NUL);
10174 Store_String_Char (Get_String_Char (S, F));
10182 if Present (Arg) then
10183 Store_String_Char (ASCII.NUL);
10187 Store_Linker_Option_String (End_String);
10195 -- pragma Linker_Alias (
10196 -- [Entity =>] LOCAL_NAME
10197 -- [Target =>] static_string_EXPRESSION);
10199 when Pragma_Linker_Alias =>
10201 Check_Arg_Order ((Name_Entity, Name_Target));
10202 Check_Arg_Count (2);
10203 Check_Optional_Identifier (Arg1, Name_Entity);
10204 Check_Optional_Identifier (Arg2, Name_Target);
10205 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10206 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10208 -- The only processing required is to link this item on to the
10209 -- list of rep items for the given entity. This is accomplished
10210 -- by the call to Rep_Item_Too_Late (when no error is detected
10211 -- and False is returned).
10213 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10216 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10219 ------------------------
10220 -- Linker_Constructor --
10221 ------------------------
10223 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10225 -- Code is shared with Linker_Destructor
10227 -----------------------
10228 -- Linker_Destructor --
10229 -----------------------
10231 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10233 when Pragma_Linker_Constructor |
10234 Pragma_Linker_Destructor =>
10235 Linker_Constructor : declare
10241 Check_Arg_Count (1);
10242 Check_No_Identifiers;
10243 Check_Arg_Is_Local_Name (Arg1);
10244 Arg1_X := Get_Pragma_Arg (Arg1);
10246 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10248 if not Is_Library_Level_Entity (Proc) then
10250 ("argument for pragma% must be library level entity", Arg1);
10253 -- The only processing required is to link this item on to the
10254 -- list of rep items for the given entity. This is accomplished
10255 -- by the call to Rep_Item_Too_Late (when no error is detected
10256 -- and False is returned).
10258 if Rep_Item_Too_Late (Proc, N) then
10261 Set_Has_Gigi_Rep_Item (Proc);
10263 end Linker_Constructor;
10265 --------------------
10266 -- Linker_Options --
10267 --------------------
10269 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10271 when Pragma_Linker_Options => Linker_Options : declare
10275 Check_Ada_83_Warning;
10276 Check_No_Identifiers;
10277 Check_Arg_Count (1);
10278 Check_Is_In_Decl_Part_Or_Package_Spec;
10279 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10280 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10283 while Present (Arg) loop
10284 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10285 Store_String_Char (ASCII.NUL);
10287 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10291 if Operating_Mode = Generate_Code
10292 and then In_Extended_Main_Source_Unit (N)
10294 Store_Linker_Option_String (End_String);
10296 end Linker_Options;
10298 --------------------
10299 -- Linker_Section --
10300 --------------------
10302 -- pragma Linker_Section (
10303 -- [Entity =>] LOCAL_NAME
10304 -- [Section =>] static_string_EXPRESSION);
10306 when Pragma_Linker_Section =>
10308 Check_Arg_Order ((Name_Entity, Name_Section));
10309 Check_Arg_Count (2);
10310 Check_Optional_Identifier (Arg1, Name_Entity);
10311 Check_Optional_Identifier (Arg2, Name_Section);
10312 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10313 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10315 -- This pragma applies only to objects
10317 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10318 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10321 -- The only processing required is to link this item on to the
10322 -- list of rep items for the given entity. This is accomplished
10323 -- by the call to Rep_Item_Too_Late (when no error is detected
10324 -- and False is returned).
10326 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10329 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10336 -- pragma List (On | Off)
10338 -- There is nothing to do here, since we did all the processing for
10339 -- this pragma in Par.Prag (so that it works properly even in syntax
10342 when Pragma_List =>
10345 --------------------
10346 -- Locking_Policy --
10347 --------------------
10349 -- pragma Locking_Policy (policy_IDENTIFIER);
10351 when Pragma_Locking_Policy => declare
10355 Check_Ada_83_Warning;
10356 Check_Arg_Count (1);
10357 Check_No_Identifiers;
10358 Check_Arg_Is_Locking_Policy (Arg1);
10359 Check_Valid_Configuration_Pragma;
10360 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10361 LP := Fold_Upper (Name_Buffer (1));
10363 if Locking_Policy /= ' '
10364 and then Locking_Policy /= LP
10366 Error_Msg_Sloc := Locking_Policy_Sloc;
10367 Error_Pragma ("locking policy incompatible with policy#");
10369 -- Set new policy, but always preserve System_Location since we
10370 -- like the error message with the run time name.
10373 Locking_Policy := LP;
10375 if Locking_Policy_Sloc /= System_Location then
10376 Locking_Policy_Sloc := Loc;
10385 -- pragma Long_Float (D_Float | G_Float);
10387 when Pragma_Long_Float =>
10389 Check_Valid_Configuration_Pragma;
10390 Check_Arg_Count (1);
10391 Check_No_Identifier (Arg1);
10392 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10394 if not OpenVMS_On_Target then
10395 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10400 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10401 if Opt.Float_Format_Long = 'G' then
10402 Error_Pragma ("G_Float previously specified");
10405 Opt.Float_Format_Long := 'D';
10407 -- G_Float case (this is the default, does not need overriding)
10410 if Opt.Float_Format_Long = 'D' then
10411 Error_Pragma ("D_Float previously specified");
10414 Opt.Float_Format_Long := 'G';
10417 Set_Standard_Fpt_Formats;
10419 -----------------------
10420 -- Machine_Attribute --
10421 -----------------------
10423 -- pragma Machine_Attribute (
10424 -- [Entity =>] LOCAL_NAME,
10425 -- [Attribute_Name =>] static_string_EXPRESSION
10426 -- [, [Info =>] static_EXPRESSION] );
10428 when Pragma_Machine_Attribute => Machine_Attribute : declare
10429 Def_Id : Entity_Id;
10433 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10435 if Arg_Count = 3 then
10436 Check_Optional_Identifier (Arg3, Name_Info);
10437 Check_Arg_Is_Static_Expression (Arg3);
10439 Check_Arg_Count (2);
10442 Check_Optional_Identifier (Arg1, Name_Entity);
10443 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10444 Check_Arg_Is_Local_Name (Arg1);
10445 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10446 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10448 if Is_Access_Type (Def_Id) then
10449 Def_Id := Designated_Type (Def_Id);
10452 if Rep_Item_Too_Early (Def_Id, N) then
10456 Def_Id := Underlying_Type (Def_Id);
10458 -- The only processing required is to link this item on to the
10459 -- list of rep items for the given entity. This is accomplished
10460 -- by the call to Rep_Item_Too_Late (when no error is detected
10461 -- and False is returned).
10463 if Rep_Item_Too_Late (Def_Id, N) then
10466 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10468 end Machine_Attribute;
10475 -- (MAIN_OPTION [, MAIN_OPTION]);
10478 -- [STACK_SIZE =>] static_integer_EXPRESSION
10479 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10480 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10482 when Pragma_Main => Main : declare
10483 Args : Args_List (1 .. 3);
10484 Names : constant Name_List (1 .. 3) := (
10486 Name_Task_Stack_Size_Default,
10487 Name_Time_Slicing_Enabled);
10493 Gather_Associations (Names, Args);
10495 for J in 1 .. 2 loop
10496 if Present (Args (J)) then
10497 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10501 if Present (Args (3)) then
10502 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10506 while Present (Nod) loop
10507 if Nkind (Nod) = N_Pragma
10508 and then Pragma_Name (Nod) = Name_Main
10510 Error_Msg_Name_1 := Pname;
10511 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10522 -- pragma Main_Storage
10523 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10525 -- MAIN_STORAGE_OPTION ::=
10526 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10527 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10529 when Pragma_Main_Storage => Main_Storage : declare
10530 Args : Args_List (1 .. 2);
10531 Names : constant Name_List (1 .. 2) := (
10532 Name_Working_Storage,
10539 Gather_Associations (Names, Args);
10541 for J in 1 .. 2 loop
10542 if Present (Args (J)) then
10543 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10547 Check_In_Main_Program;
10550 while Present (Nod) loop
10551 if Nkind (Nod) = N_Pragma
10552 and then Pragma_Name (Nod) = Name_Main_Storage
10554 Error_Msg_Name_1 := Pname;
10555 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10566 -- pragma Memory_Size (NUMERIC_LITERAL)
10568 when Pragma_Memory_Size =>
10571 -- Memory size is simply ignored
10573 Check_No_Identifiers;
10574 Check_Arg_Count (1);
10575 Check_Arg_Is_Integer_Literal (Arg1);
10583 -- The only correct use of this pragma is on its own in a file, in
10584 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10585 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10586 -- check for a file containing nothing but a No_Body pragma). If we
10587 -- attempt to process it during normal semantics processing, it means
10588 -- it was misplaced.
10590 when Pragma_No_Body =>
10598 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10600 when Pragma_No_Return => No_Return : declare
10608 Check_At_Least_N_Arguments (1);
10610 -- Loop through arguments of pragma
10613 while Present (Arg) loop
10614 Check_Arg_Is_Local_Name (Arg);
10615 Id := Get_Pragma_Arg (Arg);
10618 if not Is_Entity_Name (Id) then
10619 Error_Pragma_Arg ("entity name required", Arg);
10622 if Etype (Id) = Any_Type then
10626 -- Loop to find matching procedures
10631 and then Scope (E) = Current_Scope
10633 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10636 -- Set flag on any alias as well
10638 if Is_Overloadable (E) and then Present (Alias (E)) then
10639 Set_No_Return (Alias (E));
10645 exit when From_Aspect_Specification (N);
10650 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10661 -- pragma No_Run_Time;
10663 -- Note: this pragma is retained for backwards compatibility. See
10664 -- body of Rtsfind for full details on its handling.
10666 when Pragma_No_Run_Time =>
10668 Check_Valid_Configuration_Pragma;
10669 Check_Arg_Count (0);
10671 No_Run_Time_Mode := True;
10672 Configurable_Run_Time_Mode := True;
10674 -- Set Duration to 32 bits if word size is 32
10676 if Ttypes.System_Word_Size = 32 then
10677 Duration_32_Bits_On_Target := True;
10680 -- Set appropriate restrictions
10682 Set_Restriction (No_Finalization, N);
10683 Set_Restriction (No_Exception_Handlers, N);
10684 Set_Restriction (Max_Tasks, N, 0);
10685 Set_Restriction (No_Tasking, N);
10687 ------------------------
10688 -- No_Strict_Aliasing --
10689 ------------------------
10691 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10693 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10698 Check_At_Most_N_Arguments (1);
10700 if Arg_Count = 0 then
10701 Check_Valid_Configuration_Pragma;
10702 Opt.No_Strict_Aliasing := True;
10705 Check_Optional_Identifier (Arg2, Name_Entity);
10706 Check_Arg_Is_Local_Name (Arg1);
10707 E_Id := Entity (Get_Pragma_Arg (Arg1));
10709 if E_Id = Any_Type then
10711 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10712 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10715 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10717 end No_Strict_Aliasing;
10719 -----------------------
10720 -- Normalize_Scalars --
10721 -----------------------
10723 -- pragma Normalize_Scalars;
10725 when Pragma_Normalize_Scalars =>
10726 Check_Ada_83_Warning;
10727 Check_Arg_Count (0);
10728 Check_Valid_Configuration_Pragma;
10730 -- Normalize_Scalars creates false positives in CodePeer, so
10731 -- ignore this pragma in this mode.
10733 if not CodePeer_Mode then
10734 Normalize_Scalars := True;
10735 Init_Or_Norm_Scalars := True;
10742 -- pragma Obsolescent;
10744 -- pragma Obsolescent (
10745 -- [Message =>] static_string_EXPRESSION
10746 -- [,[Version =>] Ada_05]]);
10748 -- pragma Obsolescent (
10749 -- [Entity =>] NAME
10750 -- [,[Message =>] static_string_EXPRESSION
10751 -- [,[Version =>] Ada_05]] );
10753 when Pragma_Obsolescent => Obsolescent : declare
10757 procedure Set_Obsolescent (E : Entity_Id);
10758 -- Given an entity Ent, mark it as obsolescent if appropriate
10760 ---------------------
10761 -- Set_Obsolescent --
10762 ---------------------
10764 procedure Set_Obsolescent (E : Entity_Id) is
10773 -- Entity name was given
10775 if Present (Ename) then
10777 -- If entity name matches, we are fine. Save entity in
10778 -- pragma argument, for ASIS use.
10780 if Chars (Ename) = Chars (Ent) then
10781 Set_Entity (Ename, Ent);
10782 Generate_Reference (Ent, Ename);
10784 -- If entity name does not match, only possibility is an
10785 -- enumeration literal from an enumeration type declaration.
10787 elsif Ekind (Ent) /= E_Enumeration_Type then
10789 ("pragma % entity name does not match declaration");
10792 Ent := First_Literal (E);
10796 ("pragma % entity name does not match any " &
10797 "enumeration literal");
10799 elsif Chars (Ent) = Chars (Ename) then
10800 Set_Entity (Ename, Ent);
10801 Generate_Reference (Ent, Ename);
10805 Ent := Next_Literal (Ent);
10811 -- Ent points to entity to be marked
10813 if Arg_Count >= 1 then
10815 -- Deal with static string argument
10817 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10818 S := Strval (Get_Pragma_Arg (Arg1));
10820 for J in 1 .. String_Length (S) loop
10821 if not In_Character_Range (Get_String_Char (S, J)) then
10823 ("pragma% argument does not allow wide characters",
10828 Obsolescent_Warnings.Append
10829 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10831 -- Check for Ada_05 parameter
10833 if Arg_Count /= 1 then
10834 Check_Arg_Count (2);
10837 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10840 Check_Arg_Is_Identifier (Argx);
10842 if Chars (Argx) /= Name_Ada_05 then
10843 Error_Msg_Name_2 := Name_Ada_05;
10845 ("only allowed argument for pragma% is %", Argx);
10848 if Ada_Version_Explicit < Ada_2005
10849 or else not Warn_On_Ada_2005_Compatibility
10857 -- Set flag if pragma active
10860 Set_Is_Obsolescent (Ent);
10864 end Set_Obsolescent;
10866 -- Start of processing for pragma Obsolescent
10871 Check_At_Most_N_Arguments (3);
10873 -- See if first argument specifies an entity name
10877 (Chars (Arg1) = Name_Entity
10879 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10881 N_Operator_Symbol))
10883 Ename := Get_Pragma_Arg (Arg1);
10885 -- Eliminate first argument, so we can share processing
10889 Arg_Count := Arg_Count - 1;
10891 -- No Entity name argument given
10897 if Arg_Count >= 1 then
10898 Check_Optional_Identifier (Arg1, Name_Message);
10900 if Arg_Count = 2 then
10901 Check_Optional_Identifier (Arg2, Name_Version);
10905 -- Get immediately preceding declaration
10908 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10912 -- Cases where we do not follow anything other than another pragma
10916 -- First case: library level compilation unit declaration with
10917 -- the pragma immediately following the declaration.
10919 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10921 (Defining_Entity (Unit (Parent (Parent (N)))));
10924 -- Case 2: library unit placement for package
10928 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10930 if Is_Package_Or_Generic_Package (Ent) then
10931 Set_Obsolescent (Ent);
10937 -- Cases where we must follow a declaration
10940 if Nkind (Decl) not in N_Declaration
10941 and then Nkind (Decl) not in N_Later_Decl_Item
10942 and then Nkind (Decl) not in N_Generic_Declaration
10943 and then Nkind (Decl) not in N_Renaming_Declaration
10946 ("pragma% misplaced, "
10947 & "must immediately follow a declaration");
10950 Set_Obsolescent (Defining_Entity (Decl));
10960 -- pragma Optimize (Time | Space | Off);
10962 -- The actual check for optimize is done in Gigi. Note that this
10963 -- pragma does not actually change the optimization setting, it
10964 -- simply checks that it is consistent with the pragma.
10966 when Pragma_Optimize =>
10967 Check_No_Identifiers;
10968 Check_Arg_Count (1);
10969 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10971 ------------------------
10972 -- Optimize_Alignment --
10973 ------------------------
10975 -- pragma Optimize_Alignment (Time | Space | Off);
10977 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10979 Check_No_Identifiers;
10980 Check_Arg_Count (1);
10981 Check_Valid_Configuration_Pragma;
10984 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10988 Opt.Optimize_Alignment := 'T';
10990 Opt.Optimize_Alignment := 'S';
10992 Opt.Optimize_Alignment := 'O';
10994 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10998 -- Set indication that mode is set locally. If we are in fact in a
10999 -- configuration pragma file, this setting is harmless since the
11000 -- switch will get reset anyway at the start of each unit.
11002 Optimize_Alignment_Local := True;
11003 end Optimize_Alignment;
11009 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11011 when Pragma_Ordered => Ordered : declare
11012 Assoc : constant Node_Id := Arg1;
11018 Check_No_Identifiers;
11019 Check_Arg_Count (1);
11020 Check_Arg_Is_Local_Name (Arg1);
11022 Type_Id := Get_Pragma_Arg (Assoc);
11023 Find_Type (Type_Id);
11024 Typ := Entity (Type_Id);
11026 if Typ = Any_Type then
11029 Typ := Underlying_Type (Typ);
11032 if not Is_Enumeration_Type (Typ) then
11033 Error_Pragma ("pragma% must specify enumeration type");
11036 Check_First_Subtype (Arg1);
11037 Set_Has_Pragma_Ordered (Base_Type (Typ));
11044 -- pragma Pack (first_subtype_LOCAL_NAME);
11046 when Pragma_Pack => Pack : declare
11047 Assoc : constant Node_Id := Arg1;
11051 Ignore : Boolean := False;
11054 Check_No_Identifiers;
11055 Check_Arg_Count (1);
11056 Check_Arg_Is_Local_Name (Arg1);
11058 Type_Id := Get_Pragma_Arg (Assoc);
11059 Find_Type (Type_Id);
11060 Typ := Entity (Type_Id);
11063 or else Rep_Item_Too_Early (Typ, N)
11067 Typ := Underlying_Type (Typ);
11070 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11071 Error_Pragma ("pragma% must specify array or record type");
11074 Check_First_Subtype (Arg1);
11075 Check_Duplicate_Pragma (Typ);
11079 if Is_Array_Type (Typ) then
11080 Ctyp := Component_Type (Typ);
11082 -- Ignore pack that does nothing
11084 if Known_Static_Esize (Ctyp)
11085 and then Known_Static_RM_Size (Ctyp)
11086 and then Esize (Ctyp) = RM_Size (Ctyp)
11087 and then Addressable (Esize (Ctyp))
11092 -- Process OK pragma Pack. Note that if there is a separate
11093 -- component clause present, the Pack will be cancelled. This
11094 -- processing is in Freeze.
11096 if not Rep_Item_Too_Late (Typ, N) then
11098 -- In the context of static code analysis, we do not need
11099 -- complex front-end expansions related to pragma Pack,
11100 -- so disable handling of pragma Pack in this case.
11102 if CodePeer_Mode then
11105 -- Don't attempt any packing for VM targets. We possibly
11106 -- could deal with some cases of array bit-packing, but we
11107 -- don't bother, since this is not a typical kind of
11108 -- representation in the VM context anyway (and would not
11109 -- for example work nicely with the debugger).
11111 elsif VM_Target /= No_VM then
11112 if not GNAT_Mode then
11114 ("?pragma% ignored in this configuration");
11117 -- Normal case where we do the pack action
11121 Set_Is_Packed (Base_Type (Typ));
11122 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11125 Set_Has_Pragma_Pack (Base_Type (Typ));
11129 -- For record types, the pack is always effective
11131 else pragma Assert (Is_Record_Type (Typ));
11132 if not Rep_Item_Too_Late (Typ, N) then
11134 -- Ignore pack request with warning in VM mode (skip warning
11135 -- if we are compiling GNAT run time library).
11137 if VM_Target /= No_VM then
11138 if not GNAT_Mode then
11140 ("?pragma% ignored in this configuration");
11143 -- Normal case of pack request active
11146 Set_Is_Packed (Base_Type (Typ));
11147 Set_Has_Pragma_Pack (Base_Type (Typ));
11148 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11160 -- There is nothing to do here, since we did all the processing for
11161 -- this pragma in Par.Prag (so that it works properly even in syntax
11164 when Pragma_Page =>
11171 -- pragma Passive [(PASSIVE_FORM)];
11173 -- PASSIVE_FORM ::= Semaphore | No
11175 when Pragma_Passive =>
11178 if Nkind (Parent (N)) /= N_Task_Definition then
11179 Error_Pragma ("pragma% must be within task definition");
11182 if Arg_Count /= 0 then
11183 Check_Arg_Count (1);
11184 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11187 ----------------------------------
11188 -- Preelaborable_Initialization --
11189 ----------------------------------
11191 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11193 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11198 Check_Arg_Count (1);
11199 Check_No_Identifiers;
11200 Check_Arg_Is_Identifier (Arg1);
11201 Check_Arg_Is_Local_Name (Arg1);
11202 Check_First_Subtype (Arg1);
11203 Ent := Entity (Get_Pragma_Arg (Arg1));
11205 if not (Is_Private_Type (Ent)
11207 Is_Protected_Type (Ent)
11209 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11212 ("pragma % can only be applied to private, formal derived or "
11213 & "protected type",
11217 -- Give an error if the pragma is applied to a protected type that
11218 -- does not qualify (due to having entries, or due to components
11219 -- that do not qualify).
11221 if Is_Protected_Type (Ent)
11222 and then not Has_Preelaborable_Initialization (Ent)
11225 ("protected type & does not have preelaborable " &
11226 "initialization", Ent);
11228 -- Otherwise mark the type as definitely having preelaborable
11232 Set_Known_To_Have_Preelab_Init (Ent);
11235 if Has_Pragma_Preelab_Init (Ent)
11236 and then Warn_On_Redundant_Constructs
11238 Error_Pragma ("?duplicate pragma%!");
11240 Set_Has_Pragma_Preelab_Init (Ent);
11244 --------------------
11245 -- Persistent_BSS --
11246 --------------------
11248 -- pragma Persistent_BSS [(object_NAME)];
11250 when Pragma_Persistent_BSS => Persistent_BSS : declare
11257 Check_At_Most_N_Arguments (1);
11259 -- Case of application to specific object (one argument)
11261 if Arg_Count = 1 then
11262 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11264 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11266 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11269 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11272 Ent := Entity (Get_Pragma_Arg (Arg1));
11273 Decl := Parent (Ent);
11275 if Rep_Item_Too_Late (Ent, N) then
11279 if Present (Expression (Decl)) then
11281 ("object for pragma% cannot have initialization", Arg1);
11284 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11286 ("object type for pragma% is not potentially persistent",
11290 Check_Duplicate_Pragma (Ent);
11293 Make_Linker_Section_Pragma
11294 (Ent, Sloc (N), ".persistent.bss");
11295 Insert_After (N, Prag);
11298 -- Case of use as configuration pragma with no arguments
11301 Check_Valid_Configuration_Pragma;
11302 Persistent_BSS_Mode := True;
11304 end Persistent_BSS;
11310 -- pragma Polling (ON | OFF);
11312 when Pragma_Polling =>
11314 Check_Arg_Count (1);
11315 Check_No_Identifiers;
11316 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11317 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11319 -------------------
11320 -- Postcondition --
11321 -------------------
11323 -- pragma Postcondition ([Check =>] Boolean_Expression
11324 -- [,[Message =>] String_Expression]);
11326 when Pragma_Postcondition => Postcondition : declare
11328 pragma Warnings (Off, In_Body);
11332 Check_At_Least_N_Arguments (1);
11333 Check_At_Most_N_Arguments (2);
11334 Check_Optional_Identifier (Arg1, Name_Check);
11336 -- All we need to do here is call the common check procedure,
11337 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11339 Check_Precondition_Postcondition (In_Body);
11346 -- pragma Precondition ([Check =>] Boolean_Expression
11347 -- [,[Message =>] String_Expression]);
11349 when Pragma_Precondition => Precondition : declare
11354 Check_At_Least_N_Arguments (1);
11355 Check_At_Most_N_Arguments (2);
11356 Check_Optional_Identifier (Arg1, Name_Check);
11357 Check_Precondition_Postcondition (In_Body);
11359 -- If in spec, nothing more to do. If in body, then we convert the
11360 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11361 -- this whether or not precondition checks are enabled. That works
11362 -- fine since pragma Check will do this check, and will also
11363 -- analyze the condition itself in the proper context.
11368 Chars => Name_Check,
11369 Pragma_Argument_Associations => New_List (
11370 Make_Pragma_Argument_Association (Loc,
11371 Expression => Make_Identifier (Loc, Name_Precondition)),
11373 Make_Pragma_Argument_Association (Sloc (Arg1),
11374 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11376 if Arg_Count = 2 then
11377 Append_To (Pragma_Argument_Associations (N),
11378 Make_Pragma_Argument_Association (Sloc (Arg2),
11379 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11390 -- pragma Predicate
11391 -- ([Entity =>] type_LOCAL_NAME,
11392 -- [Check =>] EXPRESSION);
11394 when Pragma_Predicate => Predicate : declare
11399 pragma Unreferenced (Discard);
11403 Check_Arg_Count (2);
11404 Check_Optional_Identifier (Arg1, Name_Entity);
11405 Check_Optional_Identifier (Arg2, Name_Check);
11407 Check_Arg_Is_Local_Name (Arg1);
11409 Type_Id := Get_Pragma_Arg (Arg1);
11410 Find_Type (Type_Id);
11411 Typ := Entity (Type_Id);
11413 if Typ = Any_Type then
11417 -- The remaining processing is simply to link the pragma on to
11418 -- the rep item chain, for processing when the type is frozen.
11419 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11420 -- mark the type as having predicates.
11422 Set_Has_Predicates (Typ);
11423 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11430 -- pragma Preelaborate [(library_unit_NAME)];
11432 -- Set the flag Is_Preelaborated of program unit name entity
11434 when Pragma_Preelaborate => Preelaborate : declare
11435 Pa : constant Node_Id := Parent (N);
11436 Pk : constant Node_Kind := Nkind (Pa);
11440 Check_Ada_83_Warning;
11441 Check_Valid_Library_Unit_Pragma;
11443 if Nkind (N) = N_Null_Statement then
11447 Ent := Find_Lib_Unit_Name;
11448 Check_Duplicate_Pragma (Ent);
11450 -- This filters out pragmas inside generic parent then
11451 -- show up inside instantiation
11454 and then not (Pk = N_Package_Specification
11455 and then Present (Generic_Parent (Pa)))
11457 if not Debug_Flag_U then
11458 Set_Is_Preelaborated (Ent);
11459 Set_Suppress_Elaboration_Warnings (Ent);
11464 ---------------------
11465 -- Preelaborate_05 --
11466 ---------------------
11468 -- pragma Preelaborate_05 [(library_unit_NAME)];
11470 -- This pragma is useable only in GNAT_Mode, where it is used like
11471 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11472 -- (otherwise it is ignored). This is used to implement AI-362 which
11473 -- recategorizes some run-time packages in Ada 2005 mode.
11475 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11480 Check_Valid_Library_Unit_Pragma;
11482 if not GNAT_Mode then
11483 Error_Pragma ("pragma% only available in GNAT mode");
11486 if Nkind (N) = N_Null_Statement then
11490 -- This is one of the few cases where we need to test the value of
11491 -- Ada_Version_Explicit rather than Ada_Version (which is always
11492 -- set to Ada_2012 in a predefined unit), we need to know the
11493 -- explicit version set to know if this pragma is active.
11495 if Ada_Version_Explicit >= Ada_2005 then
11496 Ent := Find_Lib_Unit_Name;
11497 Set_Is_Preelaborated (Ent);
11498 Set_Suppress_Elaboration_Warnings (Ent);
11500 end Preelaborate_05;
11506 -- pragma Priority (EXPRESSION);
11508 when Pragma_Priority => Priority : declare
11509 P : constant Node_Id := Parent (N);
11513 Check_No_Identifiers;
11514 Check_Arg_Count (1);
11518 if Nkind (P) = N_Subprogram_Body then
11519 Check_In_Main_Program;
11521 Arg := Get_Pragma_Arg (Arg1);
11522 Analyze_And_Resolve (Arg, Standard_Integer);
11526 if not Is_Static_Expression (Arg) then
11527 Flag_Non_Static_Expr
11528 ("main subprogram priority is not static!", Arg);
11531 -- If constraint error, then we already signalled an error
11533 elsif Raises_Constraint_Error (Arg) then
11536 -- Otherwise check in range
11540 Val : constant Uint := Expr_Value (Arg);
11544 or else Val > Expr_Value (Expression
11545 (Parent (RTE (RE_Max_Priority))))
11548 ("main subprogram priority is out of range", Arg1);
11554 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11556 -- Load an arbitrary entity from System.Tasking to make sure
11557 -- this package is implicitly with'ed, since we need to have
11558 -- the tasking run-time active for the pragma Priority to have
11562 Discard : Entity_Id;
11563 pragma Warnings (Off, Discard);
11565 Discard := RTE (RE_Task_List);
11568 -- Task or Protected, must be of type Integer
11570 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11571 Arg := Get_Pragma_Arg (Arg1);
11573 -- The expression must be analyzed in the special manner
11574 -- described in "Handling of Default and Per-Object
11575 -- Expressions" in sem.ads.
11577 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11579 if not Is_Static_Expression (Arg) then
11580 Check_Restriction (Static_Priorities, Arg);
11583 -- Anything else is incorrect
11589 if Has_Pragma_Priority (P) then
11590 Error_Pragma ("duplicate pragma% not allowed");
11592 Set_Has_Pragma_Priority (P, True);
11594 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11595 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11596 -- exp_ch9 should use this ???
11601 -----------------------------------
11602 -- Priority_Specific_Dispatching --
11603 -----------------------------------
11605 -- pragma Priority_Specific_Dispatching (
11606 -- policy_IDENTIFIER,
11607 -- first_priority_EXPRESSION,
11608 -- last_priority_EXPRESSION);
11610 when Pragma_Priority_Specific_Dispatching =>
11611 Priority_Specific_Dispatching : declare
11612 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11613 -- This is the entity System.Any_Priority;
11616 Lower_Bound : Node_Id;
11617 Upper_Bound : Node_Id;
11623 Check_Arg_Count (3);
11624 Check_No_Identifiers;
11625 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11626 Check_Valid_Configuration_Pragma;
11627 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11628 DP := Fold_Upper (Name_Buffer (1));
11630 Lower_Bound := Get_Pragma_Arg (Arg2);
11631 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11632 Lower_Val := Expr_Value (Lower_Bound);
11634 Upper_Bound := Get_Pragma_Arg (Arg3);
11635 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11636 Upper_Val := Expr_Value (Upper_Bound);
11638 -- It is not allowed to use Task_Dispatching_Policy and
11639 -- Priority_Specific_Dispatching in the same partition.
11641 if Task_Dispatching_Policy /= ' ' then
11642 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11644 ("pragma% incompatible with Task_Dispatching_Policy#");
11646 -- Check lower bound in range
11648 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11650 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11653 ("first_priority is out of range", Arg2);
11655 -- Check upper bound in range
11657 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11659 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11662 ("last_priority is out of range", Arg3);
11664 -- Check that the priority range is valid
11666 elsif Lower_Val > Upper_Val then
11668 ("last_priority_expression must be greater than" &
11669 " or equal to first_priority_expression");
11671 -- Store the new policy, but always preserve System_Location since
11672 -- we like the error message with the run-time name.
11675 -- Check overlapping in the priority ranges specified in other
11676 -- Priority_Specific_Dispatching pragmas within the same
11677 -- partition. We can only check those we know about!
11680 Specific_Dispatching.First .. Specific_Dispatching.Last
11682 if Specific_Dispatching.Table (J).First_Priority in
11683 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11684 or else Specific_Dispatching.Table (J).Last_Priority in
11685 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11688 Specific_Dispatching.Table (J).Pragma_Loc;
11690 ("priority range overlaps with "
11691 & "Priority_Specific_Dispatching#");
11695 -- The use of Priority_Specific_Dispatching is incompatible
11696 -- with Task_Dispatching_Policy.
11698 if Task_Dispatching_Policy /= ' ' then
11699 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11701 ("Priority_Specific_Dispatching incompatible "
11702 & "with Task_Dispatching_Policy#");
11705 -- The use of Priority_Specific_Dispatching forces ceiling
11708 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11709 Error_Msg_Sloc := Locking_Policy_Sloc;
11711 ("Priority_Specific_Dispatching incompatible "
11712 & "with Locking_Policy#");
11714 -- Set the Ceiling_Locking policy, but preserve System_Location
11715 -- since we like the error message with the run time name.
11718 Locking_Policy := 'C';
11720 if Locking_Policy_Sloc /= System_Location then
11721 Locking_Policy_Sloc := Loc;
11725 -- Add entry in the table
11727 Specific_Dispatching.Append
11728 ((Dispatching_Policy => DP,
11729 First_Priority => UI_To_Int (Lower_Val),
11730 Last_Priority => UI_To_Int (Upper_Val),
11731 Pragma_Loc => Loc));
11733 end Priority_Specific_Dispatching;
11739 -- pragma Profile (profile_IDENTIFIER);
11741 -- profile_IDENTIFIER => Restricted | Ravenscar
11743 when Pragma_Profile =>
11745 Check_Arg_Count (1);
11746 Check_Valid_Configuration_Pragma;
11747 Check_No_Identifiers;
11750 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11752 if Chars (Argx) = Name_Ravenscar then
11753 Set_Ravenscar_Profile (N);
11754 elsif Chars (Argx) = Name_Restricted then
11755 Set_Profile_Restrictions
11756 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11758 Error_Pragma_Arg ("& is not a valid profile", Argx);
11762 ----------------------
11763 -- Profile_Warnings --
11764 ----------------------
11766 -- pragma Profile_Warnings (profile_IDENTIFIER);
11768 -- profile_IDENTIFIER => Restricted | Ravenscar
11770 when Pragma_Profile_Warnings =>
11772 Check_Arg_Count (1);
11773 Check_Valid_Configuration_Pragma;
11774 Check_No_Identifiers;
11777 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11779 if Chars (Argx) = Name_Ravenscar then
11780 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11781 elsif Chars (Argx) = Name_Restricted then
11782 Set_Profile_Restrictions (Restricted, N, Warn => True);
11784 Error_Pragma_Arg ("& is not a valid profile", Argx);
11788 --------------------------
11789 -- Propagate_Exceptions --
11790 --------------------------
11792 -- pragma Propagate_Exceptions;
11794 -- Note: this pragma is obsolete and has no effect
11796 when Pragma_Propagate_Exceptions =>
11798 Check_Arg_Count (0);
11800 if In_Extended_Main_Source_Unit (N) then
11801 Propagate_Exceptions := True;
11808 -- pragma Psect_Object (
11809 -- [Internal =>] LOCAL_NAME,
11810 -- [, [External =>] EXTERNAL_SYMBOL]
11811 -- [, [Size =>] EXTERNAL_SYMBOL]);
11813 when Pragma_Psect_Object | Pragma_Common_Object =>
11814 Psect_Object : declare
11815 Args : Args_List (1 .. 3);
11816 Names : constant Name_List (1 .. 3) := (
11821 Internal : Node_Id renames Args (1);
11822 External : Node_Id renames Args (2);
11823 Size : Node_Id renames Args (3);
11825 Def_Id : Entity_Id;
11827 procedure Check_Too_Long (Arg : Node_Id);
11828 -- Posts message if the argument is an identifier with more
11829 -- than 31 characters, or a string literal with more than
11830 -- 31 characters, and we are operating under VMS
11832 --------------------
11833 -- Check_Too_Long --
11834 --------------------
11836 procedure Check_Too_Long (Arg : Node_Id) is
11837 X : constant Node_Id := Original_Node (Arg);
11840 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11842 ("inappropriate argument for pragma %", Arg);
11845 if OpenVMS_On_Target then
11846 if (Nkind (X) = N_String_Literal
11847 and then String_Length (Strval (X)) > 31)
11849 (Nkind (X) = N_Identifier
11850 and then Length_Of_Name (Chars (X)) > 31)
11853 ("argument for pragma % is longer than 31 characters",
11857 end Check_Too_Long;
11859 -- Start of processing for Common_Object/Psect_Object
11863 Gather_Associations (Names, Args);
11864 Process_Extended_Import_Export_Internal_Arg (Internal);
11866 Def_Id := Entity (Internal);
11868 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11870 ("pragma% must designate an object", Internal);
11873 Check_Too_Long (Internal);
11875 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11877 ("cannot use pragma% for imported/exported object",
11881 if Is_Concurrent_Type (Etype (Internal)) then
11883 ("cannot specify pragma % for task/protected object",
11887 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11889 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11891 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11894 if Ekind (Def_Id) = E_Constant then
11896 ("cannot specify pragma % for a constant", Internal);
11899 if Is_Record_Type (Etype (Internal)) then
11905 Ent := First_Entity (Etype (Internal));
11906 while Present (Ent) loop
11907 Decl := Declaration_Node (Ent);
11909 if Ekind (Ent) = E_Component
11910 and then Nkind (Decl) = N_Component_Declaration
11911 and then Present (Expression (Decl))
11912 and then Warn_On_Export_Import
11915 ("?object for pragma % has defaults", Internal);
11925 if Present (Size) then
11926 Check_Too_Long (Size);
11929 if Present (External) then
11930 Check_Arg_Is_External_Name (External);
11931 Check_Too_Long (External);
11934 -- If all error tests pass, link pragma on to the rep item chain
11936 Record_Rep_Item (Def_Id, N);
11943 -- pragma Pure [(library_unit_NAME)];
11945 when Pragma_Pure => Pure : declare
11949 Check_Ada_83_Warning;
11950 Check_Valid_Library_Unit_Pragma;
11952 if Nkind (N) = N_Null_Statement then
11956 Ent := Find_Lib_Unit_Name;
11958 Set_Has_Pragma_Pure (Ent);
11959 Set_Suppress_Elaboration_Warnings (Ent);
11966 -- pragma Pure_05 [(library_unit_NAME)];
11968 -- This pragma is useable only in GNAT_Mode, where it is used like
11969 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11970 -- it is ignored). It may be used after a pragma Preelaborate, in
11971 -- which case it overrides the effect of the pragma Preelaborate.
11972 -- This is used to implement AI-362 which recategorizes some run-time
11973 -- packages in Ada 2005 mode.
11975 when Pragma_Pure_05 => Pure_05 : declare
11980 Check_Valid_Library_Unit_Pragma;
11982 if not GNAT_Mode then
11983 Error_Pragma ("pragma% only available in GNAT mode");
11986 if Nkind (N) = N_Null_Statement then
11990 -- This is one of the few cases where we need to test the value of
11991 -- Ada_Version_Explicit rather than Ada_Version (which is always
11992 -- set to Ada_2012 in a predefined unit), we need to know the
11993 -- explicit version set to know if this pragma is active.
11995 if Ada_Version_Explicit >= Ada_2005 then
11996 Ent := Find_Lib_Unit_Name;
11997 Set_Is_Preelaborated (Ent, False);
11999 Set_Suppress_Elaboration_Warnings (Ent);
12003 -------------------
12004 -- Pure_Function --
12005 -------------------
12007 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12009 when Pragma_Pure_Function => Pure_Function : declare
12012 Def_Id : Entity_Id;
12013 Effective : Boolean := False;
12017 Check_Arg_Count (1);
12018 Check_Optional_Identifier (Arg1, Name_Entity);
12019 Check_Arg_Is_Local_Name (Arg1);
12020 E_Id := Get_Pragma_Arg (Arg1);
12022 if Error_Posted (E_Id) then
12026 -- Loop through homonyms (overloadings) of referenced entity
12028 E := Entity (E_Id);
12030 if Present (E) then
12032 Def_Id := Get_Base_Subprogram (E);
12034 if not Ekind_In (Def_Id, E_Function,
12035 E_Generic_Function,
12039 ("pragma% requires a function name", Arg1);
12042 Set_Is_Pure (Def_Id);
12044 if not Has_Pragma_Pure_Function (Def_Id) then
12045 Set_Has_Pragma_Pure_Function (Def_Id);
12049 exit when From_Aspect_Specification (N);
12051 exit when No (E) or else Scope (E) /= Current_Scope;
12055 and then Warn_On_Redundant_Constructs
12058 ("pragma Pure_Function on& is redundant?",
12064 --------------------
12065 -- Queuing_Policy --
12066 --------------------
12068 -- pragma Queuing_Policy (policy_IDENTIFIER);
12070 when Pragma_Queuing_Policy => declare
12074 Check_Ada_83_Warning;
12075 Check_Arg_Count (1);
12076 Check_No_Identifiers;
12077 Check_Arg_Is_Queuing_Policy (Arg1);
12078 Check_Valid_Configuration_Pragma;
12079 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12080 QP := Fold_Upper (Name_Buffer (1));
12082 if Queuing_Policy /= ' '
12083 and then Queuing_Policy /= QP
12085 Error_Msg_Sloc := Queuing_Policy_Sloc;
12086 Error_Pragma ("queuing policy incompatible with policy#");
12088 -- Set new policy, but always preserve System_Location since we
12089 -- like the error message with the run time name.
12092 Queuing_Policy := QP;
12094 if Queuing_Policy_Sloc /= System_Location then
12095 Queuing_Policy_Sloc := Loc;
12100 -----------------------
12101 -- Relative_Deadline --
12102 -----------------------
12104 -- pragma Relative_Deadline (time_span_EXPRESSION);
12106 when Pragma_Relative_Deadline => Relative_Deadline : declare
12107 P : constant Node_Id := Parent (N);
12112 Check_No_Identifiers;
12113 Check_Arg_Count (1);
12115 Arg := Get_Pragma_Arg (Arg1);
12117 -- The expression must be analyzed in the special manner described
12118 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12120 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12124 if Nkind (P) = N_Subprogram_Body then
12125 Check_In_Main_Program;
12129 elsif Nkind (P) = N_Task_Definition then
12132 -- Anything else is incorrect
12138 if Has_Relative_Deadline_Pragma (P) then
12139 Error_Pragma ("duplicate pragma% not allowed");
12141 Set_Has_Relative_Deadline_Pragma (P, True);
12143 if Nkind (P) = N_Task_Definition then
12144 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12147 end Relative_Deadline;
12149 ---------------------------
12150 -- Remote_Call_Interface --
12151 ---------------------------
12153 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12155 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12156 Cunit_Node : Node_Id;
12157 Cunit_Ent : Entity_Id;
12161 Check_Ada_83_Warning;
12162 Check_Valid_Library_Unit_Pragma;
12164 if Nkind (N) = N_Null_Statement then
12168 Cunit_Node := Cunit (Current_Sem_Unit);
12169 K := Nkind (Unit (Cunit_Node));
12170 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12172 if K = N_Package_Declaration
12173 or else K = N_Generic_Package_Declaration
12174 or else K = N_Subprogram_Declaration
12175 or else K = N_Generic_Subprogram_Declaration
12176 or else (K = N_Subprogram_Body
12177 and then Acts_As_Spec (Unit (Cunit_Node)))
12182 "pragma% must apply to package or subprogram declaration");
12185 Set_Is_Remote_Call_Interface (Cunit_Ent);
12186 end Remote_Call_Interface;
12192 -- pragma Remote_Types [(library_unit_NAME)];
12194 when Pragma_Remote_Types => Remote_Types : declare
12195 Cunit_Node : Node_Id;
12196 Cunit_Ent : Entity_Id;
12199 Check_Ada_83_Warning;
12200 Check_Valid_Library_Unit_Pragma;
12202 if Nkind (N) = N_Null_Statement then
12206 Cunit_Node := Cunit (Current_Sem_Unit);
12207 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12209 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12210 N_Generic_Package_Declaration)
12213 ("pragma% can only apply to a package declaration");
12216 Set_Is_Remote_Types (Cunit_Ent);
12223 -- pragma Ravenscar;
12225 when Pragma_Ravenscar =>
12227 Check_Arg_Count (0);
12228 Check_Valid_Configuration_Pragma;
12229 Set_Ravenscar_Profile (N);
12231 if Warn_On_Obsolescent_Feature then
12232 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12233 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12236 -------------------------
12237 -- Restricted_Run_Time --
12238 -------------------------
12240 -- pragma Restricted_Run_Time;
12242 when Pragma_Restricted_Run_Time =>
12244 Check_Arg_Count (0);
12245 Check_Valid_Configuration_Pragma;
12246 Set_Profile_Restrictions
12247 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12249 if Warn_On_Obsolescent_Feature then
12251 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12252 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12259 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12262 -- restriction_IDENTIFIER
12263 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12265 when Pragma_Restrictions =>
12266 Process_Restrictions_Or_Restriction_Warnings
12267 (Warn => Treat_Restrictions_As_Warnings);
12269 --------------------------
12270 -- Restriction_Warnings --
12271 --------------------------
12273 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12276 -- restriction_IDENTIFIER
12277 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12279 when Pragma_Restriction_Warnings =>
12281 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12287 -- pragma Reviewable;
12289 when Pragma_Reviewable =>
12290 Check_Ada_83_Warning;
12291 Check_Arg_Count (0);
12293 -- Call dummy debugging function rv. This is done to assist front
12294 -- end debugging. By placing a Reviewable pragma in the source
12295 -- program, a breakpoint on rv catches this place in the source,
12296 -- allowing convenient stepping to the point of interest.
12300 --------------------------
12301 -- Short_Circuit_And_Or --
12302 --------------------------
12304 when Pragma_Short_Circuit_And_Or =>
12306 Check_Arg_Count (0);
12307 Check_Valid_Configuration_Pragma;
12308 Short_Circuit_And_Or := True;
12310 -------------------
12311 -- Share_Generic --
12312 -------------------
12314 -- pragma Share_Generic (NAME {, NAME});
12316 when Pragma_Share_Generic =>
12318 Process_Generic_List;
12324 -- pragma Shared (LOCAL_NAME);
12326 when Pragma_Shared =>
12328 Process_Atomic_Shared_Volatile;
12330 --------------------
12331 -- Shared_Passive --
12332 --------------------
12334 -- pragma Shared_Passive [(library_unit_NAME)];
12336 -- Set the flag Is_Shared_Passive of program unit name entity
12338 when Pragma_Shared_Passive => Shared_Passive : declare
12339 Cunit_Node : Node_Id;
12340 Cunit_Ent : Entity_Id;
12343 Check_Ada_83_Warning;
12344 Check_Valid_Library_Unit_Pragma;
12346 if Nkind (N) = N_Null_Statement then
12350 Cunit_Node := Cunit (Current_Sem_Unit);
12351 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12353 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12354 N_Generic_Package_Declaration)
12357 ("pragma% can only apply to a package declaration");
12360 Set_Is_Shared_Passive (Cunit_Ent);
12361 end Shared_Passive;
12363 -----------------------
12364 -- Short_Descriptors --
12365 -----------------------
12367 -- pragma Short_Descriptors;
12369 when Pragma_Short_Descriptors =>
12371 Check_Arg_Count (0);
12372 Check_Valid_Configuration_Pragma;
12373 Short_Descriptors := True;
12375 ----------------------
12376 -- Source_File_Name --
12377 ----------------------
12379 -- There are five forms for this pragma:
12381 -- pragma Source_File_Name (
12382 -- [UNIT_NAME =>] unit_NAME,
12383 -- BODY_FILE_NAME => STRING_LITERAL
12384 -- [, [INDEX =>] INTEGER_LITERAL]);
12386 -- pragma Source_File_Name (
12387 -- [UNIT_NAME =>] unit_NAME,
12388 -- SPEC_FILE_NAME => STRING_LITERAL
12389 -- [, [INDEX =>] INTEGER_LITERAL]);
12391 -- pragma Source_File_Name (
12392 -- BODY_FILE_NAME => STRING_LITERAL
12393 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12394 -- [, CASING => CASING_SPEC]);
12396 -- pragma Source_File_Name (
12397 -- SPEC_FILE_NAME => STRING_LITERAL
12398 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12399 -- [, CASING => CASING_SPEC]);
12401 -- pragma Source_File_Name (
12402 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12403 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12404 -- [, CASING => CASING_SPEC]);
12406 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12408 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12409 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12410 -- only be used when no project file is used, while SFNP can only be
12411 -- used when a project file is used.
12413 -- No processing here. Processing was completed during parsing, since
12414 -- we need to have file names set as early as possible. Units are
12415 -- loaded well before semantic processing starts.
12417 -- The only processing we defer to this point is the check for
12418 -- correct placement.
12420 when Pragma_Source_File_Name =>
12422 Check_Valid_Configuration_Pragma;
12424 ------------------------------
12425 -- Source_File_Name_Project --
12426 ------------------------------
12428 -- See Source_File_Name for syntax
12430 -- No processing here. Processing was completed during parsing, since
12431 -- we need to have file names set as early as possible. Units are
12432 -- loaded well before semantic processing starts.
12434 -- The only processing we defer to this point is the check for
12435 -- correct placement.
12437 when Pragma_Source_File_Name_Project =>
12439 Check_Valid_Configuration_Pragma;
12441 -- Check that a pragma Source_File_Name_Project is used only in a
12442 -- configuration pragmas file.
12444 -- Pragmas Source_File_Name_Project should only be generated by
12445 -- the Project Manager in configuration pragmas files.
12447 -- This is really an ugly test. It seems to depend on some
12448 -- accidental and undocumented property. At the very least it
12449 -- needs to be documented, but it would be better to have a
12450 -- clean way of testing if we are in a configuration file???
12452 if Present (Parent (N)) then
12454 ("pragma% can only appear in a configuration pragmas file");
12457 ----------------------
12458 -- Source_Reference --
12459 ----------------------
12461 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12463 -- Nothing to do, all processing completed in Par.Prag, since we need
12464 -- the information for possible parser messages that are output.
12466 when Pragma_Source_Reference =>
12469 --------------------------------
12470 -- Static_Elaboration_Desired --
12471 --------------------------------
12473 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12475 when Pragma_Static_Elaboration_Desired =>
12477 Check_At_Most_N_Arguments (1);
12479 if Is_Compilation_Unit (Current_Scope)
12480 and then Ekind (Current_Scope) = E_Package
12482 Set_Static_Elaboration_Desired (Current_Scope, True);
12484 Error_Pragma ("pragma% must apply to a library-level package");
12491 -- pragma Storage_Size (EXPRESSION);
12493 when Pragma_Storage_Size => Storage_Size : declare
12494 P : constant Node_Id := Parent (N);
12498 Check_No_Identifiers;
12499 Check_Arg_Count (1);
12501 -- The expression must be analyzed in the special manner described
12502 -- in "Handling of Default Expressions" in sem.ads.
12504 Arg := Get_Pragma_Arg (Arg1);
12505 Preanalyze_Spec_Expression (Arg, Any_Integer);
12507 if not Is_Static_Expression (Arg) then
12508 Check_Restriction (Static_Storage_Size, Arg);
12511 if Nkind (P) /= N_Task_Definition then
12516 if Has_Storage_Size_Pragma (P) then
12517 Error_Pragma ("duplicate pragma% not allowed");
12519 Set_Has_Storage_Size_Pragma (P, True);
12522 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12523 -- ??? exp_ch9 should use this!
12531 -- pragma Storage_Unit (NUMERIC_LITERAL);
12533 -- Only permitted argument is System'Storage_Unit value
12535 when Pragma_Storage_Unit =>
12536 Check_No_Identifiers;
12537 Check_Arg_Count (1);
12538 Check_Arg_Is_Integer_Literal (Arg1);
12540 if Intval (Get_Pragma_Arg (Arg1)) /=
12541 UI_From_Int (Ttypes.System_Storage_Unit)
12543 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12545 ("the only allowed argument for pragma% is ^", Arg1);
12548 --------------------
12549 -- Stream_Convert --
12550 --------------------
12552 -- pragma Stream_Convert (
12553 -- [Entity =>] type_LOCAL_NAME,
12554 -- [Read =>] function_NAME,
12555 -- [Write =>] function NAME);
12557 when Pragma_Stream_Convert => Stream_Convert : declare
12559 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12560 -- Check that the given argument is the name of a local function
12561 -- of one argument that is not overloaded earlier in the current
12562 -- local scope. A check is also made that the argument is a
12563 -- function with one parameter.
12565 --------------------------------------
12566 -- Check_OK_Stream_Convert_Function --
12567 --------------------------------------
12569 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12573 Check_Arg_Is_Local_Name (Arg);
12574 Ent := Entity (Get_Pragma_Arg (Arg));
12576 if Has_Homonym (Ent) then
12578 ("argument for pragma% may not be overloaded", Arg);
12581 if Ekind (Ent) /= E_Function
12582 or else No (First_Formal (Ent))
12583 or else Present (Next_Formal (First_Formal (Ent)))
12586 ("argument for pragma% must be" &
12587 " function of one argument", Arg);
12589 end Check_OK_Stream_Convert_Function;
12591 -- Start of processing for Stream_Convert
12595 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12596 Check_Arg_Count (3);
12597 Check_Optional_Identifier (Arg1, Name_Entity);
12598 Check_Optional_Identifier (Arg2, Name_Read);
12599 Check_Optional_Identifier (Arg3, Name_Write);
12600 Check_Arg_Is_Local_Name (Arg1);
12601 Check_OK_Stream_Convert_Function (Arg2);
12602 Check_OK_Stream_Convert_Function (Arg3);
12605 Typ : constant Entity_Id :=
12606 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12607 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12608 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12611 Check_First_Subtype (Arg1);
12613 -- Check for too early or too late. Note that we don't enforce
12614 -- the rule about primitive operations in this case, since, as
12615 -- is the case for explicit stream attributes themselves, these
12616 -- restrictions are not appropriate. Note that the chaining of
12617 -- the pragma by Rep_Item_Too_Late is actually the critical
12618 -- processing done for this pragma.
12620 if Rep_Item_Too_Early (Typ, N)
12622 Rep_Item_Too_Late (Typ, N, FOnly => True)
12627 -- Return if previous error
12629 if Etype (Typ) = Any_Type
12631 Etype (Read) = Any_Type
12633 Etype (Write) = Any_Type
12640 if Underlying_Type (Etype (Read)) /= Typ then
12642 ("incorrect return type for function&", Arg2);
12645 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12647 ("incorrect parameter type for function&", Arg3);
12650 if Underlying_Type (Etype (First_Formal (Read))) /=
12651 Underlying_Type (Etype (Write))
12654 ("result type of & does not match Read parameter type",
12658 end Stream_Convert;
12660 -------------------------
12661 -- Style_Checks (GNAT) --
12662 -------------------------
12664 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12666 -- This is processed by the parser since some of the style checks
12667 -- take place during source scanning and parsing. This means that
12668 -- we don't need to issue error messages here.
12670 when Pragma_Style_Checks => Style_Checks : declare
12671 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12677 Check_No_Identifiers;
12679 -- Two argument form
12681 if Arg_Count = 2 then
12682 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12689 E_Id := Get_Pragma_Arg (Arg2);
12692 if not Is_Entity_Name (E_Id) then
12694 ("second argument of pragma% must be entity name",
12698 E := Entity (E_Id);
12704 Set_Suppress_Style_Checks (E,
12705 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12706 exit when No (Homonym (E));
12712 -- One argument form
12715 Check_Arg_Count (1);
12717 if Nkind (A) = N_String_Literal then
12721 Slen : constant Natural := Natural (String_Length (S));
12722 Options : String (1 .. Slen);
12728 C := Get_String_Char (S, Int (J));
12729 exit when not In_Character_Range (C);
12730 Options (J) := Get_Character (C);
12732 -- If at end of string, set options. As per discussion
12733 -- above, no need to check for errors, since we issued
12734 -- them in the parser.
12737 Set_Style_Check_Options (Options);
12745 elsif Nkind (A) = N_Identifier then
12746 if Chars (A) = Name_All_Checks then
12748 Set_GNAT_Style_Check_Options;
12750 Set_Default_Style_Check_Options;
12753 elsif Chars (A) = Name_On then
12754 Style_Check := True;
12756 elsif Chars (A) = Name_Off then
12757 Style_Check := False;
12767 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12769 when Pragma_Subtitle =>
12771 Check_Arg_Count (1);
12772 Check_Optional_Identifier (Arg1, Name_Subtitle);
12773 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12780 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12782 when Pragma_Suppress =>
12783 Process_Suppress_Unsuppress (True);
12789 -- pragma Suppress_All;
12791 -- The only check made here is that the pragma has no arguments.
12792 -- There are no placement rules, and the processing required (setting
12793 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12794 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12795 -- then creates and inserts a pragma Suppress (All_Checks).
12797 when Pragma_Suppress_All =>
12799 Check_Arg_Count (0);
12801 -------------------------
12802 -- Suppress_Debug_Info --
12803 -------------------------
12805 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12807 when Pragma_Suppress_Debug_Info =>
12809 Check_Arg_Count (1);
12810 Check_Optional_Identifier (Arg1, Name_Entity);
12811 Check_Arg_Is_Local_Name (Arg1);
12812 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
12814 ----------------------------------
12815 -- Suppress_Exception_Locations --
12816 ----------------------------------
12818 -- pragma Suppress_Exception_Locations;
12820 when Pragma_Suppress_Exception_Locations =>
12822 Check_Arg_Count (0);
12823 Check_Valid_Configuration_Pragma;
12824 Exception_Locations_Suppressed := True;
12826 -----------------------------
12827 -- Suppress_Initialization --
12828 -----------------------------
12830 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12832 when Pragma_Suppress_Initialization => Suppress_Init : declare
12838 Check_Arg_Count (1);
12839 Check_Optional_Identifier (Arg1, Name_Entity);
12840 Check_Arg_Is_Local_Name (Arg1);
12842 E_Id := Get_Pragma_Arg (Arg1);
12844 if Etype (E_Id) = Any_Type then
12848 E := Entity (E_Id);
12850 if Is_Type (E) then
12851 if Is_Incomplete_Or_Private_Type (E) then
12852 if No (Full_View (Base_Type (E))) then
12854 ("argument of pragma% cannot be an incomplete type",
12857 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12860 Set_Suppress_Init_Proc (Base_Type (E));
12865 ("pragma% requires argument that is a type name", Arg1);
12873 -- pragma System_Name (DIRECT_NAME);
12875 -- Syntax check: one argument, which must be the identifier GNAT or
12876 -- the identifier GCC, no other identifiers are acceptable.
12878 when Pragma_System_Name =>
12880 Check_No_Identifiers;
12881 Check_Arg_Count (1);
12882 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12884 -----------------------------
12885 -- Task_Dispatching_Policy --
12886 -----------------------------
12888 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12890 when Pragma_Task_Dispatching_Policy => declare
12894 Check_Ada_83_Warning;
12895 Check_Arg_Count (1);
12896 Check_No_Identifiers;
12897 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12898 Check_Valid_Configuration_Pragma;
12899 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12900 DP := Fold_Upper (Name_Buffer (1));
12902 if Task_Dispatching_Policy /= ' '
12903 and then Task_Dispatching_Policy /= DP
12905 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12907 ("task dispatching policy incompatible with policy#");
12909 -- Set new policy, but always preserve System_Location since we
12910 -- like the error message with the run time name.
12913 Task_Dispatching_Policy := DP;
12915 if Task_Dispatching_Policy_Sloc /= System_Location then
12916 Task_Dispatching_Policy_Sloc := Loc;
12925 -- pragma Task_Info (EXPRESSION);
12927 when Pragma_Task_Info => Task_Info : declare
12928 P : constant Node_Id := Parent (N);
12933 if Nkind (P) /= N_Task_Definition then
12934 Error_Pragma ("pragma% must appear in task definition");
12937 Check_No_Identifiers;
12938 Check_Arg_Count (1);
12940 Analyze_And_Resolve
12941 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12943 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12947 if Has_Task_Info_Pragma (P) then
12948 Error_Pragma ("duplicate pragma% not allowed");
12950 Set_Has_Task_Info_Pragma (P, True);
12958 -- pragma Task_Name (string_EXPRESSION);
12960 when Pragma_Task_Name => Task_Name : declare
12961 P : constant Node_Id := Parent (N);
12965 Check_No_Identifiers;
12966 Check_Arg_Count (1);
12968 Arg := Get_Pragma_Arg (Arg1);
12970 -- The expression is used in the call to Create_Task, and must be
12971 -- expanded there, not in the context of the current spec. It must
12972 -- however be analyzed to capture global references, in case it
12973 -- appears in a generic context.
12975 Preanalyze_And_Resolve (Arg, Standard_String);
12977 if Nkind (P) /= N_Task_Definition then
12981 if Has_Task_Name_Pragma (P) then
12982 Error_Pragma ("duplicate pragma% not allowed");
12984 Set_Has_Task_Name_Pragma (P, True);
12985 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12993 -- pragma Task_Storage (
12994 -- [Task_Type =>] LOCAL_NAME,
12995 -- [Top_Guard =>] static_integer_EXPRESSION);
12997 when Pragma_Task_Storage => Task_Storage : declare
12998 Args : Args_List (1 .. 2);
12999 Names : constant Name_List (1 .. 2) := (
13003 Task_Type : Node_Id renames Args (1);
13004 Top_Guard : Node_Id renames Args (2);
13010 Gather_Associations (Names, Args);
13012 if No (Task_Type) then
13014 ("missing task_type argument for pragma%");
13017 Check_Arg_Is_Local_Name (Task_Type);
13019 Ent := Entity (Task_Type);
13021 if not Is_Task_Type (Ent) then
13023 ("argument for pragma% must be task type", Task_Type);
13026 if No (Top_Guard) then
13028 ("pragma% takes two arguments", Task_Type);
13030 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13033 Check_First_Subtype (Task_Type);
13035 if Rep_Item_Too_Late (Ent, N) then
13040 --------------------------
13041 -- Thread_Local_Storage --
13042 --------------------------
13044 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13046 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13052 Check_Arg_Count (1);
13053 Check_Optional_Identifier (Arg1, Name_Entity);
13054 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13056 Id := Get_Pragma_Arg (Arg1);
13059 if not Is_Entity_Name (Id)
13060 or else Ekind (Entity (Id)) /= E_Variable
13062 Error_Pragma_Arg ("local variable name required", Arg1);
13067 if Rep_Item_Too_Early (E, N)
13068 or else Rep_Item_Too_Late (E, N)
13073 Set_Has_Pragma_Thread_Local_Storage (E);
13074 Set_Has_Gigi_Rep_Item (E);
13075 end Thread_Local_Storage;
13081 -- pragma Time_Slice (static_duration_EXPRESSION);
13083 when Pragma_Time_Slice => Time_Slice : declare
13089 Check_Arg_Count (1);
13090 Check_No_Identifiers;
13091 Check_In_Main_Program;
13092 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13094 if not Error_Posted (Arg1) then
13096 while Present (Nod) loop
13097 if Nkind (Nod) = N_Pragma
13098 and then Pragma_Name (Nod) = Name_Time_Slice
13100 Error_Msg_Name_1 := Pname;
13101 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13108 -- Process only if in main unit
13110 if Get_Source_Unit (Loc) = Main_Unit then
13111 Opt.Time_Slice_Set := True;
13112 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13114 if Val <= Ureal_0 then
13115 Opt.Time_Slice_Value := 0;
13117 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13118 Opt.Time_Slice_Value := 1_000_000_000;
13121 Opt.Time_Slice_Value :=
13122 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13131 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13133 -- TITLING_OPTION ::=
13134 -- [Title =>] STRING_LITERAL
13135 -- | [Subtitle =>] STRING_LITERAL
13137 when Pragma_Title => Title : declare
13138 Args : Args_List (1 .. 2);
13139 Names : constant Name_List (1 .. 2) := (
13145 Gather_Associations (Names, Args);
13148 for J in 1 .. 2 loop
13149 if Present (Args (J)) then
13150 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13155 ---------------------
13156 -- Unchecked_Union --
13157 ---------------------
13159 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13161 when Pragma_Unchecked_Union => Unchecked_Union : declare
13162 Assoc : constant Node_Id := Arg1;
13163 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13174 Check_No_Identifiers;
13175 Check_Arg_Count (1);
13176 Check_Arg_Is_Local_Name (Arg1);
13178 Find_Type (Type_Id);
13179 Typ := Entity (Type_Id);
13182 or else Rep_Item_Too_Early (Typ, N)
13186 Typ := Underlying_Type (Typ);
13189 if Rep_Item_Too_Late (Typ, N) then
13193 Check_First_Subtype (Arg1);
13195 -- Note remaining cases are references to a type in the current
13196 -- declarative part. If we find an error, we post the error on
13197 -- the relevant type declaration at an appropriate point.
13199 if not Is_Record_Type (Typ) then
13200 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13203 elsif Is_Tagged_Type (Typ) then
13204 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13207 elsif Is_Limited_Type (Typ) then
13209 ("Unchecked_Union must not be limited record type", Typ);
13210 Explain_Limited_Type (Typ, Typ);
13214 if not Has_Discriminants (Typ) then
13216 ("Unchecked_Union must have one discriminant", Typ);
13220 Discr := First_Discriminant (Typ);
13221 while Present (Discr) loop
13222 if No (Discriminant_Default_Value (Discr)) then
13224 ("Unchecked_Union discriminant must have default value",
13228 Next_Discriminant (Discr);
13231 Tdef := Type_Definition (Declaration_Node (Typ));
13232 Clist := Component_List (Tdef);
13234 Comp := First (Component_Items (Clist));
13235 while Present (Comp) loop
13236 Check_Component (Comp, Typ);
13240 if No (Clist) or else No (Variant_Part (Clist)) then
13242 ("Unchecked_Union must have variant part",
13247 Vpart := Variant_Part (Clist);
13249 Variant := First (Variants (Vpart));
13250 while Present (Variant) loop
13251 Check_Variant (Variant, Typ);
13256 Set_Is_Unchecked_Union (Typ);
13257 Set_Convention (Typ, Convention_C);
13258 Set_Has_Unchecked_Union (Base_Type (Typ));
13259 Set_Is_Unchecked_Union (Base_Type (Typ));
13260 end Unchecked_Union;
13262 ------------------------
13263 -- Unimplemented_Unit --
13264 ------------------------
13266 -- pragma Unimplemented_Unit;
13268 -- Note: this only gives an error if we are generating code, or if
13269 -- we are in a generic library unit (where the pragma appears in the
13270 -- body, not in the spec).
13272 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13273 Cunitent : constant Entity_Id :=
13274 Cunit_Entity (Get_Source_Unit (Loc));
13275 Ent_Kind : constant Entity_Kind :=
13280 Check_Arg_Count (0);
13282 if Operating_Mode = Generate_Code
13283 or else Ent_Kind = E_Generic_Function
13284 or else Ent_Kind = E_Generic_Procedure
13285 or else Ent_Kind = E_Generic_Package
13287 Get_Name_String (Chars (Cunitent));
13288 Set_Casing (Mixed_Case);
13289 Write_Str (Name_Buffer (1 .. Name_Len));
13290 Write_Str (" is not supported in this configuration");
13292 raise Unrecoverable_Error;
13294 end Unimplemented_Unit;
13296 ------------------------
13297 -- Universal_Aliasing --
13298 ------------------------
13300 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13302 when Pragma_Universal_Aliasing => Universal_Alias : declare
13307 Check_Arg_Count (1);
13308 Check_Optional_Identifier (Arg2, Name_Entity);
13309 Check_Arg_Is_Local_Name (Arg1);
13310 E_Id := Entity (Get_Pragma_Arg (Arg1));
13312 if E_Id = Any_Type then
13314 elsif No (E_Id) or else not Is_Type (E_Id) then
13315 Error_Pragma_Arg ("pragma% requires type", Arg1);
13318 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13319 end Universal_Alias;
13321 --------------------
13322 -- Universal_Data --
13323 --------------------
13325 -- pragma Universal_Data [(library_unit_NAME)];
13327 when Pragma_Universal_Data =>
13330 -- If this is a configuration pragma, then set the universal
13331 -- addressing option, otherwise confirm that the pragma satisfies
13332 -- the requirements of library unit pragma placement and leave it
13333 -- to the GNAAMP back end to detect the pragma (avoids transitive
13334 -- setting of the option due to withed units).
13336 if Is_Configuration_Pragma then
13337 Universal_Addressing_On_AAMP := True;
13339 Check_Valid_Library_Unit_Pragma;
13342 if not AAMP_On_Target then
13343 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13350 -- pragma Unmodified (local_Name {, local_Name});
13352 when Pragma_Unmodified => Unmodified : declare
13353 Arg_Node : Node_Id;
13354 Arg_Expr : Node_Id;
13355 Arg_Ent : Entity_Id;
13359 Check_At_Least_N_Arguments (1);
13361 -- Loop through arguments
13364 while Present (Arg_Node) loop
13365 Check_No_Identifier (Arg_Node);
13367 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13368 -- in fact generate reference, so that the entity will have a
13369 -- reference, which will inhibit any warnings about it not
13370 -- being referenced, and also properly show up in the ali file
13371 -- as a reference. But this reference is recorded before the
13372 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13373 -- generated for this reference.
13375 Check_Arg_Is_Local_Name (Arg_Node);
13376 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13378 if Is_Entity_Name (Arg_Expr) then
13379 Arg_Ent := Entity (Arg_Expr);
13381 if not Is_Assignable (Arg_Ent) then
13383 ("pragma% can only be applied to a variable",
13386 Set_Has_Pragma_Unmodified (Arg_Ent);
13398 -- pragma Unreferenced (local_Name {, local_Name});
13400 -- or when used in a context clause:
13402 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13404 when Pragma_Unreferenced => Unreferenced : declare
13405 Arg_Node : Node_Id;
13406 Arg_Expr : Node_Id;
13407 Arg_Ent : Entity_Id;
13412 Check_At_Least_N_Arguments (1);
13414 -- Check case of appearing within context clause
13416 if Is_In_Context_Clause then
13418 -- The arguments must all be units mentioned in a with clause
13419 -- in the same context clause. Note we already checked (in
13420 -- Par.Prag) that the arguments are either identifiers or
13421 -- selected components.
13424 while Present (Arg_Node) loop
13425 Citem := First (List_Containing (N));
13426 while Citem /= N loop
13427 if Nkind (Citem) = N_With_Clause
13429 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13431 Set_Has_Pragma_Unreferenced
13434 (Library_Unit (Citem))));
13436 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13445 ("argument of pragma% is not with'ed unit", Arg_Node);
13451 -- Case of not in list of context items
13455 while Present (Arg_Node) loop
13456 Check_No_Identifier (Arg_Node);
13458 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13459 -- will in fact generate reference, so that the entity will
13460 -- have a reference, which will inhibit any warnings about
13461 -- it not being referenced, and also properly show up in the
13462 -- ali file as a reference. But this reference is recorded
13463 -- before the Has_Pragma_Unreferenced flag is set, so that
13464 -- no warning is generated for this reference.
13466 Check_Arg_Is_Local_Name (Arg_Node);
13467 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13469 if Is_Entity_Name (Arg_Expr) then
13470 Arg_Ent := Entity (Arg_Expr);
13472 -- If the entity is overloaded, the pragma applies to the
13473 -- most recent overloading, as documented. In this case,
13474 -- name resolution does not generate a reference, so it
13475 -- must be done here explicitly.
13477 if Is_Overloaded (Arg_Expr) then
13478 Generate_Reference (Arg_Ent, N);
13481 Set_Has_Pragma_Unreferenced (Arg_Ent);
13489 --------------------------
13490 -- Unreferenced_Objects --
13491 --------------------------
13493 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13495 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13496 Arg_Node : Node_Id;
13497 Arg_Expr : Node_Id;
13501 Check_At_Least_N_Arguments (1);
13504 while Present (Arg_Node) loop
13505 Check_No_Identifier (Arg_Node);
13506 Check_Arg_Is_Local_Name (Arg_Node);
13507 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13509 if not Is_Entity_Name (Arg_Expr)
13510 or else not Is_Type (Entity (Arg_Expr))
13513 ("argument for pragma% must be type or subtype", Arg_Node);
13516 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13519 end Unreferenced_Objects;
13521 ------------------------------
13522 -- Unreserve_All_Interrupts --
13523 ------------------------------
13525 -- pragma Unreserve_All_Interrupts;
13527 when Pragma_Unreserve_All_Interrupts =>
13529 Check_Arg_Count (0);
13531 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13532 Unreserve_All_Interrupts := True;
13539 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13541 when Pragma_Unsuppress =>
13543 Process_Suppress_Unsuppress (False);
13545 -------------------
13546 -- Use_VADS_Size --
13547 -------------------
13549 -- pragma Use_VADS_Size;
13551 when Pragma_Use_VADS_Size =>
13553 Check_Arg_Count (0);
13554 Check_Valid_Configuration_Pragma;
13555 Use_VADS_Size := True;
13557 ---------------------
13558 -- Validity_Checks --
13559 ---------------------
13561 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13563 when Pragma_Validity_Checks => Validity_Checks : declare
13564 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13570 Check_Arg_Count (1);
13571 Check_No_Identifiers;
13573 if Nkind (A) = N_String_Literal then
13577 Slen : constant Natural := Natural (String_Length (S));
13578 Options : String (1 .. Slen);
13584 C := Get_String_Char (S, Int (J));
13585 exit when not In_Character_Range (C);
13586 Options (J) := Get_Character (C);
13589 Set_Validity_Check_Options (Options);
13597 elsif Nkind (A) = N_Identifier then
13599 if Chars (A) = Name_All_Checks then
13600 Set_Validity_Check_Options ("a");
13602 elsif Chars (A) = Name_On then
13603 Validity_Checks_On := True;
13605 elsif Chars (A) = Name_Off then
13606 Validity_Checks_On := False;
13610 end Validity_Checks;
13616 -- pragma Volatile (LOCAL_NAME);
13618 when Pragma_Volatile =>
13619 Process_Atomic_Shared_Volatile;
13621 -------------------------
13622 -- Volatile_Components --
13623 -------------------------
13625 -- pragma Volatile_Components (array_LOCAL_NAME);
13627 -- Volatile is handled by the same circuit as Atomic_Components
13633 -- pragma Warnings (On | Off);
13634 -- pragma Warnings (On | Off, LOCAL_NAME);
13635 -- pragma Warnings (static_string_EXPRESSION);
13636 -- pragma Warnings (On | Off, STRING_LITERAL);
13638 when Pragma_Warnings => Warnings : begin
13640 Check_At_Least_N_Arguments (1);
13641 Check_No_Identifiers;
13643 -- If debug flag -gnatd.i is set, pragma is ignored
13645 if Debug_Flag_Dot_I then
13649 -- Process various forms of the pragma
13652 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13655 -- One argument case
13657 if Arg_Count = 1 then
13659 -- On/Off one argument case was processed by parser
13661 if Nkind (Argx) = N_Identifier
13663 (Chars (Argx) = Name_On
13665 Chars (Argx) = Name_Off)
13669 -- One argument case must be ON/OFF or static string expr
13671 elsif not Is_Static_String_Expression (Arg1) then
13673 ("argument of pragma% must be On/Off or " &
13674 "static string expression", Arg1);
13676 -- One argument string expression case
13680 Lit : constant Node_Id := Expr_Value_S (Argx);
13681 Str : constant String_Id := Strval (Lit);
13682 Len : constant Nat := String_Length (Str);
13690 while J <= Len loop
13691 C := Get_String_Char (Str, J);
13692 OK := In_Character_Range (C);
13695 Chr := Get_Character (C);
13699 if J < Len and then Chr = '.' then
13701 C := Get_String_Char (Str, J);
13702 Chr := Get_Character (C);
13704 if not Set_Dot_Warning_Switch (Chr) then
13706 ("invalid warning switch character " &
13713 OK := Set_Warning_Switch (Chr);
13719 ("invalid warning switch character " & Chr,
13728 -- Two or more arguments (must be two)
13731 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13732 Check_At_Most_N_Arguments (2);
13740 E_Id := Get_Pragma_Arg (Arg2);
13743 -- In the expansion of an inlined body, a reference to
13744 -- the formal may be wrapped in a conversion if the
13745 -- actual is a conversion. Retrieve the real entity name.
13747 if (In_Instance_Body
13748 or else In_Inlined_Body)
13749 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13751 E_Id := Expression (E_Id);
13754 -- Entity name case
13756 if Is_Entity_Name (E_Id) then
13757 E := Entity (E_Id);
13764 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13767 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13768 and then Warn_On_Warnings_Off
13770 Warnings_Off_Pragmas.Append ((N, E));
13773 if Is_Enumeration_Type (E) then
13777 Lit := First_Literal (E);
13778 while Present (Lit) loop
13779 Set_Warnings_Off (Lit);
13780 Next_Literal (Lit);
13785 exit when No (Homonym (E));
13790 -- Error if not entity or static string literal case
13792 elsif not Is_Static_String_Expression (Arg2) then
13794 ("second argument of pragma% must be entity " &
13795 "name or static string expression", Arg2);
13797 -- String literal case
13800 String_To_Name_Buffer
13801 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13803 -- Note on configuration pragma case: If this is a
13804 -- configuration pragma, then for an OFF pragma, we
13805 -- just set Config True in the call, which is all
13806 -- that needs to be done. For the case of ON, this
13807 -- is normally an error, unless it is canceling the
13808 -- effect of a previous OFF pragma in the same file.
13809 -- In any other case, an error will be signalled (ON
13810 -- with no matching OFF).
13812 if Chars (Argx) = Name_Off then
13813 Set_Specific_Warning_Off
13814 (Loc, Name_Buffer (1 .. Name_Len),
13815 Config => Is_Configuration_Pragma);
13817 elsif Chars (Argx) = Name_On then
13818 Set_Specific_Warning_On
13819 (Loc, Name_Buffer (1 .. Name_Len), Err);
13823 ("?pragma Warnings On with no " &
13824 "matching Warnings Off",
13834 -------------------
13835 -- Weak_External --
13836 -------------------
13838 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13840 when Pragma_Weak_External => Weak_External : declare
13845 Check_Arg_Count (1);
13846 Check_Optional_Identifier (Arg1, Name_Entity);
13847 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13848 Ent := Entity (Get_Pragma_Arg (Arg1));
13850 if Rep_Item_Too_Early (Ent, N) then
13853 Ent := Underlying_Type (Ent);
13856 -- The only processing required is to link this item on to the
13857 -- list of rep items for the given entity. This is accomplished
13858 -- by the call to Rep_Item_Too_Late (when no error is detected
13859 -- and False is returned).
13861 if Rep_Item_Too_Late (Ent, N) then
13864 Set_Has_Gigi_Rep_Item (Ent);
13868 -----------------------------
13869 -- Wide_Character_Encoding --
13870 -----------------------------
13872 -- pragma Wide_Character_Encoding (IDENTIFIER);
13874 when Pragma_Wide_Character_Encoding =>
13877 -- Nothing to do, handled in parser. Note that we do not enforce
13878 -- configuration pragma placement, this pragma can appear at any
13879 -- place in the source, allowing mixed encodings within a single
13884 --------------------
13885 -- Unknown_Pragma --
13886 --------------------
13888 -- Should be impossible, since the case of an unknown pragma is
13889 -- separately processed before the case statement is entered.
13891 when Unknown_Pragma =>
13892 raise Program_Error;
13895 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13896 -- until AI is formally approved.
13898 -- Check_Order_Dependence;
13901 when Pragma_Exit => null;
13902 end Analyze_Pragma;
13904 -------------------
13905 -- Check_Enabled --
13906 -------------------
13908 function Check_Enabled (Nam : Name_Id) return Boolean is
13912 -- Loop through entries in check policy list
13914 PP := Opt.Check_Policy_List;
13916 -- If there are no specific entries that matched, then we let the
13917 -- setting of assertions govern. Note that this provides the needed
13918 -- compatibility with the RM for the cases of assertion, invariant,
13919 -- precondition, predicate, and postcondition.
13922 return Assertions_Enabled;
13924 -- Here we have an entry see if it matches
13928 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13931 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13932 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13933 when Name_On | Name_Check =>
13935 when Name_Off | Name_Ignore =>
13938 raise Program_Error;
13942 PP := Next_Pragma (PP);
13949 ---------------------------------
13950 -- Delay_Config_Pragma_Analyze --
13951 ---------------------------------
13953 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13955 return Pragma_Name (N) = Name_Interrupt_State
13957 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13958 end Delay_Config_Pragma_Analyze;
13960 -------------------------
13961 -- Get_Base_Subprogram --
13962 -------------------------
13964 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13965 Result : Entity_Id;
13968 -- Follow subprogram renaming chain
13971 while Is_Subprogram (Result)
13973 (Is_Generic_Instance (Result)
13974 or else Nkind (Parent (Declaration_Node (Result))) =
13975 N_Subprogram_Renaming_Declaration)
13976 and then Present (Alias (Result))
13978 Result := Alias (Result);
13982 end Get_Base_Subprogram;
13988 procedure Initialize is
13993 -----------------------------
13994 -- Is_Config_Static_String --
13995 -----------------------------
13997 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13999 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14000 -- This is an internal recursive function that is just like the outer
14001 -- function except that it adds the string to the name buffer rather
14002 -- than placing the string in the name buffer.
14004 ------------------------------
14005 -- Add_Config_Static_String --
14006 ------------------------------
14008 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14015 if Nkind (N) = N_Op_Concat then
14016 if Add_Config_Static_String (Left_Opnd (N)) then
14017 N := Right_Opnd (N);
14023 if Nkind (N) /= N_String_Literal then
14024 Error_Msg_N ("string literal expected for pragma argument", N);
14028 for J in 1 .. String_Length (Strval (N)) loop
14029 C := Get_String_Char (Strval (N), J);
14031 if not In_Character_Range (C) then
14033 ("string literal contains invalid wide character",
14034 Sloc (N) + 1 + Source_Ptr (J));
14038 Add_Char_To_Name_Buffer (Get_Character (C));
14043 end Add_Config_Static_String;
14045 -- Start of processing for Is_Config_Static_String
14050 return Add_Config_Static_String (Arg);
14051 end Is_Config_Static_String;
14053 -----------------------------------------
14054 -- Is_Non_Significant_Pragma_Reference --
14055 -----------------------------------------
14057 -- This function makes use of the following static table which indicates
14058 -- whether a given pragma is significant.
14060 -- -1 indicates that references in any argument position are significant
14061 -- 0 indicates that appearance in any argument is not significant
14062 -- +n indicates that appearance as argument n is significant, but all
14063 -- other arguments are not significant
14064 -- 99 special processing required (e.g. for pragma Check)
14066 Sig_Flags : constant array (Pragma_Id) of Int :=
14067 (Pragma_AST_Entry => -1,
14068 Pragma_Abort_Defer => -1,
14069 Pragma_Ada_83 => -1,
14070 Pragma_Ada_95 => -1,
14071 Pragma_Ada_05 => -1,
14072 Pragma_Ada_2005 => -1,
14073 Pragma_Ada_12 => -1,
14074 Pragma_Ada_2012 => -1,
14075 Pragma_All_Calls_Remote => -1,
14076 Pragma_Annotate => -1,
14077 Pragma_Assert => -1,
14078 Pragma_Assertion_Policy => 0,
14079 Pragma_Assume_No_Invalid_Values => 0,
14080 Pragma_Asynchronous => -1,
14081 Pragma_Atomic => 0,
14082 Pragma_Atomic_Components => 0,
14083 Pragma_Attach_Handler => -1,
14084 Pragma_Check => 99,
14085 Pragma_Check_Name => 0,
14086 Pragma_Check_Policy => 0,
14087 Pragma_CIL_Constructor => -1,
14088 Pragma_CPP_Class => 0,
14089 Pragma_CPP_Constructor => 0,
14090 Pragma_CPP_Virtual => 0,
14091 Pragma_CPP_Vtable => 0,
14093 Pragma_C_Pass_By_Copy => 0,
14094 Pragma_Comment => 0,
14095 Pragma_Common_Object => -1,
14096 Pragma_Compile_Time_Error => -1,
14097 Pragma_Compile_Time_Warning => -1,
14098 Pragma_Compiler_Unit => 0,
14099 Pragma_Complete_Representation => 0,
14100 Pragma_Complex_Representation => 0,
14101 Pragma_Component_Alignment => -1,
14102 Pragma_Controlled => 0,
14103 Pragma_Convention => 0,
14104 Pragma_Convention_Identifier => 0,
14105 Pragma_Debug => -1,
14106 Pragma_Debug_Policy => 0,
14107 Pragma_Default_Value => -1,
14108 Pragma_Default_Component_Value => -1,
14109 Pragma_Detect_Blocking => -1,
14110 Pragma_Default_Storage_Pool => -1,
14111 Pragma_Dimension => -1,
14112 Pragma_Discard_Names => 0,
14113 Pragma_Elaborate => -1,
14114 Pragma_Elaborate_All => -1,
14115 Pragma_Elaborate_Body => -1,
14116 Pragma_Elaboration_Checks => -1,
14117 Pragma_Eliminate => -1,
14118 Pragma_Export => -1,
14119 Pragma_Export_Exception => -1,
14120 Pragma_Export_Function => -1,
14121 Pragma_Export_Object => -1,
14122 Pragma_Export_Procedure => -1,
14123 Pragma_Export_Value => -1,
14124 Pragma_Export_Valued_Procedure => -1,
14125 Pragma_Extend_System => -1,
14126 Pragma_Extensions_Allowed => -1,
14127 Pragma_External => -1,
14128 Pragma_Favor_Top_Level => -1,
14129 Pragma_External_Name_Casing => -1,
14130 Pragma_Fast_Math => -1,
14131 Pragma_Finalize_Storage_Only => 0,
14132 Pragma_Float_Representation => 0,
14133 Pragma_Ident => -1,
14134 Pragma_Implemented => -1,
14135 Pragma_Implicit_Packing => 0,
14136 Pragma_Import => +2,
14137 Pragma_Import_Exception => 0,
14138 Pragma_Import_Function => 0,
14139 Pragma_Import_Object => 0,
14140 Pragma_Import_Procedure => 0,
14141 Pragma_Import_Valued_Procedure => 0,
14142 Pragma_Independent => 0,
14143 Pragma_Independent_Components => 0,
14144 Pragma_Initialize_Scalars => -1,
14145 Pragma_Inline => 0,
14146 Pragma_Inline_Always => 0,
14147 Pragma_Inline_Generic => 0,
14148 Pragma_Inspection_Point => -1,
14149 Pragma_Interface => +2,
14150 Pragma_Interface_Name => +2,
14151 Pragma_Interrupt_Handler => -1,
14152 Pragma_Interrupt_Priority => -1,
14153 Pragma_Interrupt_State => -1,
14154 Pragma_Invariant => -1,
14155 Pragma_Java_Constructor => -1,
14156 Pragma_Java_Interface => -1,
14157 Pragma_Keep_Names => 0,
14158 Pragma_License => -1,
14159 Pragma_Link_With => -1,
14160 Pragma_Linker_Alias => -1,
14161 Pragma_Linker_Constructor => -1,
14162 Pragma_Linker_Destructor => -1,
14163 Pragma_Linker_Options => -1,
14164 Pragma_Linker_Section => -1,
14166 Pragma_Locking_Policy => -1,
14167 Pragma_Long_Float => -1,
14168 Pragma_Machine_Attribute => -1,
14170 Pragma_Main_Storage => -1,
14171 Pragma_Memory_Size => -1,
14172 Pragma_No_Return => 0,
14173 Pragma_No_Body => 0,
14174 Pragma_No_Run_Time => -1,
14175 Pragma_No_Strict_Aliasing => -1,
14176 Pragma_Normalize_Scalars => -1,
14177 Pragma_Obsolescent => 0,
14178 Pragma_Optimize => -1,
14179 Pragma_Optimize_Alignment => -1,
14180 Pragma_Ordered => 0,
14183 Pragma_Passive => -1,
14184 Pragma_Preelaborable_Initialization => -1,
14185 Pragma_Polling => -1,
14186 Pragma_Persistent_BSS => 0,
14187 Pragma_Postcondition => -1,
14188 Pragma_Precondition => -1,
14189 Pragma_Predicate => -1,
14190 Pragma_Preelaborate => -1,
14191 Pragma_Preelaborate_05 => -1,
14192 Pragma_Priority => -1,
14193 Pragma_Priority_Specific_Dispatching => -1,
14194 Pragma_Profile => 0,
14195 Pragma_Profile_Warnings => 0,
14196 Pragma_Propagate_Exceptions => -1,
14197 Pragma_Psect_Object => -1,
14199 Pragma_Pure_05 => -1,
14200 Pragma_Pure_Function => -1,
14201 Pragma_Queuing_Policy => -1,
14202 Pragma_Ravenscar => -1,
14203 Pragma_Relative_Deadline => -1,
14204 Pragma_Remote_Call_Interface => -1,
14205 Pragma_Remote_Types => -1,
14206 Pragma_Restricted_Run_Time => -1,
14207 Pragma_Restriction_Warnings => -1,
14208 Pragma_Restrictions => -1,
14209 Pragma_Reviewable => -1,
14210 Pragma_Short_Circuit_And_Or => -1,
14211 Pragma_Share_Generic => -1,
14212 Pragma_Shared => -1,
14213 Pragma_Shared_Passive => -1,
14214 Pragma_Short_Descriptors => 0,
14215 Pragma_Source_File_Name => -1,
14216 Pragma_Source_File_Name_Project => -1,
14217 Pragma_Source_Reference => -1,
14218 Pragma_Storage_Size => -1,
14219 Pragma_Storage_Unit => -1,
14220 Pragma_Static_Elaboration_Desired => -1,
14221 Pragma_Stream_Convert => -1,
14222 Pragma_Style_Checks => -1,
14223 Pragma_Subtitle => -1,
14224 Pragma_Suppress => 0,
14225 Pragma_Suppress_Exception_Locations => 0,
14226 Pragma_Suppress_All => -1,
14227 Pragma_Suppress_Debug_Info => 0,
14228 Pragma_Suppress_Initialization => 0,
14229 Pragma_System_Name => -1,
14230 Pragma_Task_Dispatching_Policy => -1,
14231 Pragma_Task_Info => -1,
14232 Pragma_Task_Name => -1,
14233 Pragma_Task_Storage => 0,
14234 Pragma_Thread_Local_Storage => 0,
14235 Pragma_Time_Slice => -1,
14236 Pragma_Title => -1,
14237 Pragma_Unchecked_Union => 0,
14238 Pragma_Unimplemented_Unit => -1,
14239 Pragma_Universal_Aliasing => -1,
14240 Pragma_Universal_Data => -1,
14241 Pragma_Unmodified => -1,
14242 Pragma_Unreferenced => -1,
14243 Pragma_Unreferenced_Objects => -1,
14244 Pragma_Unreserve_All_Interrupts => -1,
14245 Pragma_Unsuppress => 0,
14246 Pragma_Use_VADS_Size => -1,
14247 Pragma_Validity_Checks => -1,
14248 Pragma_Volatile => 0,
14249 Pragma_Volatile_Components => 0,
14250 Pragma_Warnings => -1,
14251 Pragma_Weak_External => -1,
14252 Pragma_Wide_Character_Encoding => 0,
14253 Unknown_Pragma => 0);
14255 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14264 if Nkind (P) /= N_Pragma_Argument_Association then
14268 Id := Get_Pragma_Id (Parent (P));
14269 C := Sig_Flags (Id);
14281 -- For pragma Check, the first argument is not significant,
14282 -- the second and the third (if present) arguments are
14285 when Pragma_Check =>
14287 P = First (Pragma_Argument_Associations (Parent (P)));
14290 raise Program_Error;
14294 A := First (Pragma_Argument_Associations (Parent (P)));
14295 for J in 1 .. C - 1 loop
14303 return A = P; -- is this wrong way round ???
14306 end Is_Non_Significant_Pragma_Reference;
14308 ------------------------------
14309 -- Is_Pragma_String_Literal --
14310 ------------------------------
14312 -- This function returns true if the corresponding pragma argument is a
14313 -- static string expression. These are the only cases in which string
14314 -- literals can appear as pragma arguments. We also allow a string literal
14315 -- as the first argument to pragma Assert (although it will of course
14316 -- always generate a type error).
14318 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14319 Pragn : constant Node_Id := Parent (Par);
14320 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14321 Pname : constant Name_Id := Pragma_Name (Pragn);
14327 N := First (Assoc);
14334 if Pname = Name_Assert then
14337 elsif Pname = Name_Export then
14340 elsif Pname = Name_Ident then
14343 elsif Pname = Name_Import then
14346 elsif Pname = Name_Interface_Name then
14349 elsif Pname = Name_Linker_Alias then
14352 elsif Pname = Name_Linker_Section then
14355 elsif Pname = Name_Machine_Attribute then
14358 elsif Pname = Name_Source_File_Name then
14361 elsif Pname = Name_Source_Reference then
14364 elsif Pname = Name_Title then
14367 elsif Pname = Name_Subtitle then
14373 end Is_Pragma_String_Literal;
14375 --------------------------------------
14376 -- Process_Compilation_Unit_Pragmas --
14377 --------------------------------------
14379 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14381 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14382 -- strange because it comes at the end of the unit. Rational has the
14383 -- same name for a pragma, but treats it as a program unit pragma, In
14384 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14385 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14386 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14387 -- the context clause to ensure the correct processing.
14389 if Has_Pragma_Suppress_All (N) then
14390 Prepend_To (Context_Items (N),
14391 Make_Pragma (Sloc (N),
14392 Chars => Name_Suppress,
14393 Pragma_Argument_Associations => New_List (
14394 Make_Pragma_Argument_Association (Sloc (N),
14395 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14398 -- Nothing else to do at the current time!
14400 end Process_Compilation_Unit_Pragmas;
14411 --------------------------------
14412 -- Set_Encoded_Interface_Name --
14413 --------------------------------
14415 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14416 Str : constant String_Id := Strval (S);
14417 Len : constant Int := String_Length (Str);
14422 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14425 -- Stores encoded value of character code CC. The encoding we use an
14426 -- underscore followed by four lower case hex digits.
14432 procedure Encode is
14434 Store_String_Char (Get_Char_Code ('_'));
14436 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14438 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14440 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14442 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14445 -- Start of processing for Set_Encoded_Interface_Name
14448 -- If first character is asterisk, this is a link name, and we leave it
14449 -- completely unmodified. We also ignore null strings (the latter case
14450 -- happens only in error cases) and no encoding should occur for Java or
14451 -- AAMP interface names.
14454 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14455 or else VM_Target /= No_VM
14456 or else AAMP_On_Target
14458 Set_Interface_Name (E, S);
14463 CC := Get_String_Char (Str, J);
14465 exit when not In_Character_Range (CC);
14467 C := Get_Character (CC);
14469 exit when C /= '_' and then C /= '$'
14470 and then C not in '0' .. '9'
14471 and then C not in 'a' .. 'z'
14472 and then C not in 'A' .. 'Z';
14475 Set_Interface_Name (E, S);
14483 -- Here we need to encode. The encoding we use as follows:
14484 -- three underscores + four hex digits (lower case)
14488 for J in 1 .. String_Length (Str) loop
14489 CC := Get_String_Char (Str, J);
14491 if not In_Character_Range (CC) then
14494 C := Get_Character (CC);
14496 if C = '_' or else C = '$'
14497 or else C in '0' .. '9'
14498 or else C in 'a' .. 'z'
14499 or else C in 'A' .. 'Z'
14501 Store_String_Char (CC);
14508 Set_Interface_Name (E,
14509 Make_String_Literal (Sloc (S),
14510 Strval => End_String));
14512 end Set_Encoded_Interface_Name;
14514 -------------------
14515 -- Set_Unit_Name --
14516 -------------------
14518 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14523 if Nkind (N) = N_Identifier
14524 and then Nkind (With_Item) = N_Identifier
14526 Set_Entity (N, Entity (With_Item));
14528 elsif Nkind (N) = N_Selected_Component then
14529 Change_Selected_Component_To_Expanded_Name (N);
14530 Set_Entity (N, Entity (With_Item));
14531 Set_Entity (Selector_Name (N), Entity (N));
14533 Pref := Prefix (N);
14534 Scop := Scope (Entity (N));
14535 while Nkind (Pref) = N_Selected_Component loop
14536 Change_Selected_Component_To_Expanded_Name (Pref);
14537 Set_Entity (Selector_Name (Pref), Scop);
14538 Set_Entity (Pref, Scop);
14539 Pref := Prefix (Pref);
14540 Scop := Scope (Scop);
14543 Set_Entity (Pref, Scop);