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 Elmt : Elmt_Id := First_Elmt (Predefined_Float_Types);
3869 Ftyp : Node_Id := Empty;
3874 String_To_Name_Buffer (Strval (Expression (Arg3)));
3877 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
3881 Ftyp := Node (Elmt);
3883 if Present (Ftyp) then
3884 -- Don't build a derived type declaration, because predefined C
3885 -- types have no declaration anywhere, so cannot really be named.
3886 -- Instead build a full type declaration, starting with an
3887 -- appropriate type definition is built
3889 if Is_Floating_Point_Type (Ftyp) then
3890 Def := Make_Floating_Point_Definition (Loc,
3891 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
3892 Make_Real_Range_Specification (Loc,
3893 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
3894 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
3897 -- Should never have a predefined type we cannot handle
3898 raise Program_Error;
3901 -- Build and insert a Full_Type_Declaration, which will be
3902 -- analyzed as soon as this list entry has been analyzed.
3904 Decl := Make_Full_Type_Declaration (Loc,
3905 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
3906 Type_Definition => Def);
3908 Insert_After (N, Decl);
3909 Mark_Rewrite_Insertion (Decl);
3912 Error_Pragma_Arg ("no matching type found for pragma%",
3915 end Process_Import_Predefined_Type;
3917 ---------------------------------
3918 -- Process_Import_Or_Interface --
3919 ---------------------------------
3921 procedure Process_Import_Or_Interface is
3927 Process_Convention (C, Def_Id);
3928 Kill_Size_Check_Code (Def_Id);
3929 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
3931 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3933 -- We do not permit Import to apply to a renaming declaration
3935 if Present (Renamed_Object (Def_Id)) then
3937 ("pragma% not allowed for object renaming", Arg2);
3939 -- User initialization is not allowed for imported object, but
3940 -- the object declaration may contain a default initialization,
3941 -- that will be discarded. Note that an explicit initialization
3942 -- only counts if it comes from source, otherwise it is simply
3943 -- the code generator making an implicit initialization explicit.
3945 elsif Present (Expression (Parent (Def_Id)))
3946 and then Comes_From_Source (Expression (Parent (Def_Id)))
3948 Error_Msg_Sloc := Sloc (Def_Id);
3950 ("no initialization allowed for declaration of& #",
3951 "\imported entities cannot be initialized (RM B.1(24))",
3955 Set_Imported (Def_Id);
3956 Process_Interface_Name (Def_Id, Arg3, Arg4);
3958 -- Note that we do not set Is_Public here. That's because we
3959 -- only want to set it if there is no address clause, and we
3960 -- don't know that yet, so we delay that processing till
3963 -- pragma Import completes deferred constants
3965 if Ekind (Def_Id) = E_Constant then
3966 Set_Has_Completion (Def_Id);
3969 -- It is not possible to import a constant of an unconstrained
3970 -- array type (e.g. string) because there is no simple way to
3971 -- write a meaningful subtype for it.
3973 if Is_Array_Type (Etype (Def_Id))
3974 and then not Is_Constrained (Etype (Def_Id))
3977 ("imported constant& must have a constrained subtype",
3982 elsif Is_Subprogram (Def_Id)
3983 or else Is_Generic_Subprogram (Def_Id)
3985 -- If the name is overloaded, pragma applies to all of the denoted
3986 -- entities in the same declarative part.
3989 while Present (Hom_Id) loop
3990 Def_Id := Get_Base_Subprogram (Hom_Id);
3992 -- Ignore inherited subprograms because the pragma will apply
3993 -- to the parent operation, which is the one called.
3995 if Is_Overloadable (Def_Id)
3996 and then Present (Alias (Def_Id))
4000 -- If it is not a subprogram, it must be in an outer scope and
4001 -- pragma does not apply.
4003 elsif not Is_Subprogram (Def_Id)
4004 and then not Is_Generic_Subprogram (Def_Id)
4008 -- The pragma does not apply to primitives of interfaces
4010 elsif Is_Dispatching_Operation (Def_Id)
4011 and then Present (Find_Dispatching_Type (Def_Id))
4012 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4016 -- Verify that the homonym is in the same declarative part (not
4017 -- just the same scope).
4019 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4020 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4025 Set_Imported (Def_Id);
4027 -- Reject an Import applied to an abstract subprogram
4029 if Is_Subprogram (Def_Id)
4030 and then Is_Abstract_Subprogram (Def_Id)
4032 Error_Msg_Sloc := Sloc (Def_Id);
4034 ("cannot import abstract subprogram& declared#",
4038 -- Special processing for Convention_Intrinsic
4040 if C = Convention_Intrinsic then
4042 -- Link_Name argument not allowed for intrinsic
4046 Set_Is_Intrinsic_Subprogram (Def_Id);
4048 -- If no external name is present, then check that this
4049 -- is a valid intrinsic subprogram. If an external name
4050 -- is present, then this is handled by the back end.
4053 Check_Intrinsic_Subprogram
4054 (Def_Id, Get_Pragma_Arg (Arg2));
4058 -- All interfaced procedures need an external symbol created
4059 -- for them since they are always referenced from another
4062 Set_Is_Public (Def_Id);
4064 -- Verify that the subprogram does not have a completion
4065 -- through a renaming declaration. For other completions the
4066 -- pragma appears as a too late representation.
4069 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4073 and then Nkind (Decl) = N_Subprogram_Declaration
4074 and then Present (Corresponding_Body (Decl))
4075 and then Nkind (Unit_Declaration_Node
4076 (Corresponding_Body (Decl))) =
4077 N_Subprogram_Renaming_Declaration
4079 Error_Msg_Sloc := Sloc (Def_Id);
4081 ("cannot import&, renaming already provided for " &
4082 "declaration #", N, Def_Id);
4086 Set_Has_Completion (Def_Id);
4087 Process_Interface_Name (Def_Id, Arg3, Arg4);
4090 if Is_Compilation_Unit (Hom_Id) then
4092 -- Its possible homonyms are not affected by the pragma.
4093 -- Such homonyms might be present in the context of other
4094 -- units being compiled.
4099 Hom_Id := Homonym (Hom_Id);
4103 -- When the convention is Java or CIL, we also allow Import to be
4104 -- given for packages, generic packages, exceptions, record
4105 -- components, and access to subprograms.
4107 elsif (C = Convention_Java or else C = Convention_CIL)
4109 (Is_Package_Or_Generic_Package (Def_Id)
4110 or else Ekind (Def_Id) = E_Exception
4111 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4112 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4114 Set_Imported (Def_Id);
4115 Set_Is_Public (Def_Id);
4116 Process_Interface_Name (Def_Id, Arg3, Arg4);
4118 -- Import a CPP class
4120 elsif Is_Record_Type (Def_Id)
4121 and then C = Convention_CPP
4123 -- Types treated as CPP classes are treated as limited, but we
4124 -- don't require them to be declared this way. A warning is issued
4125 -- to encourage the user to declare them as limited. This is not
4126 -- an error, for compatibility reasons, because these types have
4127 -- been supported this way for some time.
4129 if not Is_Limited_Type (Def_Id) then
4131 ("imported 'C'P'P type should be " &
4132 "explicitly declared limited?",
4133 Get_Pragma_Arg (Arg2));
4135 ("\type will be considered limited",
4136 Get_Pragma_Arg (Arg2));
4139 Set_Is_CPP_Class (Def_Id);
4140 Set_Is_Limited_Record (Def_Id);
4142 -- Imported CPP types must not have discriminants (because C++
4143 -- classes do not have discriminants).
4145 if Has_Discriminants (Def_Id) then
4147 ("imported 'C'P'P type cannot have discriminants",
4148 First (Discriminant_Specifications
4149 (Declaration_Node (Def_Id))));
4152 -- Components of imported CPP types must not have default
4153 -- expressions because the constructor (if any) is on the
4157 Tdef : constant Node_Id :=
4158 Type_Definition (Declaration_Node (Def_Id));
4163 if Nkind (Tdef) = N_Record_Definition then
4164 Clist := Component_List (Tdef);
4167 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4168 Clist := Component_List (Record_Extension_Part (Tdef));
4171 if Present (Clist) then
4172 Comp := First (Component_Items (Clist));
4173 while Present (Comp) loop
4174 if Present (Expression (Comp)) then
4176 ("component of imported 'C'P'P type cannot have" &
4177 " default expression", Expression (Comp));
4185 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4187 Check_Arg_Count (3);
4188 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4190 Process_Import_Predefined_Type;
4194 ("second argument of pragma% must be object, subprogram" &
4195 " or incomplete type",
4199 -- If this pragma applies to a compilation unit, then the unit, which
4200 -- is a subprogram, does not require (or allow) a body. We also do
4201 -- not need to elaborate imported procedures.
4203 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4205 Cunit : constant Node_Id := Parent (Parent (N));
4207 Set_Body_Required (Cunit, False);
4210 end Process_Import_Or_Interface;
4212 --------------------
4213 -- Process_Inline --
4214 --------------------
4216 procedure Process_Inline (Active : Boolean) is
4223 Effective : Boolean := False;
4224 -- Set True if inline has some effect, i.e. if there is at least one
4225 -- subprogram set as inlined as a result of the use of the pragma.
4227 procedure Make_Inline (Subp : Entity_Id);
4228 -- Subp is the defining unit name of the subprogram declaration. Set
4229 -- the flag, as well as the flag in the corresponding body, if there
4232 procedure Set_Inline_Flags (Subp : Entity_Id);
4233 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4234 -- Has_Pragma_Inline_Always for the Inline_Always case.
4236 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4237 -- Returns True if it can be determined at this stage that inlining
4238 -- is not possible, for example if the body is available and contains
4239 -- exception handlers, we prevent inlining, since otherwise we can
4240 -- get undefined symbols at link time. This function also emits a
4241 -- warning if front-end inlining is enabled and the pragma appears
4244 -- ??? is business with link symbols still valid, or does it relate
4245 -- to front end ZCX which is being phased out ???
4247 ---------------------------
4248 -- Inlining_Not_Possible --
4249 ---------------------------
4251 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4252 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4256 if Nkind (Decl) = N_Subprogram_Body then
4257 Stats := Handled_Statement_Sequence (Decl);
4258 return Present (Exception_Handlers (Stats))
4259 or else Present (At_End_Proc (Stats));
4261 elsif Nkind (Decl) = N_Subprogram_Declaration
4262 and then Present (Corresponding_Body (Decl))
4264 if Front_End_Inlining
4265 and then Analyzed (Corresponding_Body (Decl))
4267 Error_Msg_N ("pragma appears too late, ignored?", N);
4270 -- If the subprogram is a renaming as body, the body is just a
4271 -- call to the renamed subprogram, and inlining is trivially
4275 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4276 N_Subprogram_Renaming_Declaration
4282 Handled_Statement_Sequence
4283 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4286 Present (Exception_Handlers (Stats))
4287 or else Present (At_End_Proc (Stats));
4291 -- If body is not available, assume the best, the check is
4292 -- performed again when compiling enclosing package bodies.
4296 end Inlining_Not_Possible;
4302 procedure Make_Inline (Subp : Entity_Id) is
4303 Kind : constant Entity_Kind := Ekind (Subp);
4304 Inner_Subp : Entity_Id := Subp;
4307 -- Ignore if bad type, avoid cascaded error
4309 if Etype (Subp) = Any_Type then
4313 -- Ignore if all inlining is suppressed
4315 elsif Suppress_All_Inlining then
4319 -- If inlining is not possible, for now do not treat as an error
4321 elsif Inlining_Not_Possible (Subp) then
4325 -- Here we have a candidate for inlining, but we must exclude
4326 -- derived operations. Otherwise we would end up trying to inline
4327 -- a phantom declaration, and the result would be to drag in a
4328 -- body which has no direct inlining associated with it. That
4329 -- would not only be inefficient but would also result in the
4330 -- backend doing cross-unit inlining in cases where it was
4331 -- definitely inappropriate to do so.
4333 -- However, a simple Comes_From_Source test is insufficient, since
4334 -- we do want to allow inlining of generic instances which also do
4335 -- not come from source. We also need to recognize specs generated
4336 -- by the front-end for bodies that carry the pragma. Finally,
4337 -- predefined operators do not come from source but are not
4338 -- inlineable either.
4340 elsif Is_Generic_Instance (Subp)
4341 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4345 elsif not Comes_From_Source (Subp)
4346 and then Scope (Subp) /= Standard_Standard
4352 -- The referenced entity must either be the enclosing entity, or
4353 -- an entity declared within the current open scope.
4355 if Present (Scope (Subp))
4356 and then Scope (Subp) /= Current_Scope
4357 and then Subp /= Current_Scope
4360 ("argument of% must be entity in current scope", Assoc);
4364 -- Processing for procedure, operator or function. If subprogram
4365 -- is aliased (as for an instance) indicate that the renamed
4366 -- entity (if declared in the same unit) is inlined.
4368 if Is_Subprogram (Subp) then
4369 Inner_Subp := Ultimate_Alias (Inner_Subp);
4371 if In_Same_Source_Unit (Subp, Inner_Subp) then
4372 Set_Inline_Flags (Inner_Subp);
4374 Decl := Parent (Parent (Inner_Subp));
4376 if Nkind (Decl) = N_Subprogram_Declaration
4377 and then Present (Corresponding_Body (Decl))
4379 Set_Inline_Flags (Corresponding_Body (Decl));
4381 elsif Is_Generic_Instance (Subp) then
4383 -- Indicate that the body needs to be created for
4384 -- inlining subsequent calls. The instantiation node
4385 -- follows the declaration of the wrapper package
4388 if Scope (Subp) /= Standard_Standard
4390 Need_Subprogram_Instance_Body
4391 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4401 -- For a generic subprogram set flag as well, for use at the point
4402 -- of instantiation, to determine whether the body should be
4405 elsif Is_Generic_Subprogram (Subp) then
4406 Set_Inline_Flags (Subp);
4409 -- Literals are by definition inlined
4411 elsif Kind = E_Enumeration_Literal then
4414 -- Anything else is an error
4418 ("expect subprogram name for pragma%", Assoc);
4422 ----------------------
4423 -- Set_Inline_Flags --
4424 ----------------------
4426 procedure Set_Inline_Flags (Subp : Entity_Id) is
4429 Set_Is_Inlined (Subp);
4432 if not Has_Pragma_Inline (Subp) then
4433 Set_Has_Pragma_Inline (Subp);
4437 if Prag_Id = Pragma_Inline_Always then
4438 Set_Has_Pragma_Inline_Always (Subp);
4440 end Set_Inline_Flags;
4442 -- Start of processing for Process_Inline
4445 Check_No_Identifiers;
4446 Check_At_Least_N_Arguments (1);
4449 Inline_Processing_Required := True;
4453 while Present (Assoc) loop
4454 Subp_Id := Get_Pragma_Arg (Assoc);
4458 if Is_Entity_Name (Subp_Id) then
4459 Subp := Entity (Subp_Id);
4461 if Subp = Any_Id then
4463 -- If previous error, avoid cascaded errors
4471 -- For the pragma case, climb homonym chain. This is
4472 -- what implements allowing the pragma in the renaming
4473 -- case, with the result applying to the ancestors.
4475 if not From_Aspect_Specification (N) then
4476 while Present (Homonym (Subp))
4477 and then Scope (Homonym (Subp)) = Current_Scope
4479 Make_Inline (Homonym (Subp));
4480 Subp := Homonym (Subp);
4488 ("inappropriate argument for pragma%", Assoc);
4491 and then Warn_On_Redundant_Constructs
4492 and then not Suppress_All_Inlining
4494 if Inlining_Not_Possible (Subp) then
4496 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4499 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4507 ----------------------------
4508 -- Process_Interface_Name --
4509 ----------------------------
4511 procedure Process_Interface_Name
4512 (Subprogram_Def : Entity_Id;
4518 String_Val : String_Id;
4520 procedure Check_Form_Of_Interface_Name
4522 Ext_Name_Case : Boolean);
4523 -- SN is a string literal node for an interface name. This routine
4524 -- performs some minimal checks that the name is reasonable. In
4525 -- particular that no spaces or other obviously incorrect characters
4526 -- appear. This is only a warning, since any characters are allowed.
4527 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4529 ----------------------------------
4530 -- Check_Form_Of_Interface_Name --
4531 ----------------------------------
4533 procedure Check_Form_Of_Interface_Name
4535 Ext_Name_Case : Boolean)
4537 S : constant String_Id := Strval (Expr_Value_S (SN));
4538 SL : constant Nat := String_Length (S);
4543 Error_Msg_N ("interface name cannot be null string", SN);
4546 for J in 1 .. SL loop
4547 C := Get_String_Char (S, J);
4549 -- Look for dubious character and issue unconditional warning.
4550 -- Definitely dubious if not in character range.
4552 if not In_Character_Range (C)
4554 -- For all cases except CLI target,
4555 -- commas, spaces and slashes are dubious (in CLI, we use
4556 -- commas and backslashes in external names to specify
4557 -- assembly version and public key, while slashes and spaces
4558 -- can be used in names to mark nested classes and
4561 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4562 and then (Get_Character (C) = ','
4564 Get_Character (C) = '\'))
4565 or else (VM_Target /= CLI_Target
4566 and then (Get_Character (C) = ' '
4568 Get_Character (C) = '/'))
4571 ("?interface name contains illegal character",
4572 Sloc (SN) + Source_Ptr (J));
4575 end Check_Form_Of_Interface_Name;
4577 -- Start of processing for Process_Interface_Name
4580 if No (Link_Arg) then
4581 if No (Ext_Arg) then
4582 if VM_Target = CLI_Target
4583 and then Ekind (Subprogram_Def) = E_Package
4584 and then Nkind (Parent (Subprogram_Def)) =
4585 N_Package_Specification
4586 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4591 (Generic_Parent (Parent (Subprogram_Def))));
4596 elsif Chars (Ext_Arg) = Name_Link_Name then
4598 Link_Nam := Expression (Ext_Arg);
4601 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4602 Ext_Nam := Expression (Ext_Arg);
4607 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4608 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4609 Ext_Nam := Expression (Ext_Arg);
4610 Link_Nam := Expression (Link_Arg);
4613 -- Check expressions for external name and link name are static
4615 if Present (Ext_Nam) then
4616 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4617 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4619 -- Verify that external name is not the name of a local entity,
4620 -- which would hide the imported one and could lead to run-time
4621 -- surprises. The problem can only arise for entities declared in
4622 -- a package body (otherwise the external name is fully qualified
4623 -- and will not conflict).
4631 if Prag_Id = Pragma_Import then
4632 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4634 E := Entity_Id (Get_Name_Table_Info (Nam));
4636 if Nam /= Chars (Subprogram_Def)
4637 and then Present (E)
4638 and then not Is_Overloadable (E)
4639 and then Is_Immediately_Visible (E)
4640 and then not Is_Imported (E)
4641 and then Ekind (Scope (E)) = E_Package
4644 while Present (Par) loop
4645 if Nkind (Par) = N_Package_Body then
4646 Error_Msg_Sloc := Sloc (E);
4648 ("imported entity is hidden by & declared#",
4653 Par := Parent (Par);
4660 if Present (Link_Nam) then
4661 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4662 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4665 -- If there is no link name, just set the external name
4667 if No (Link_Nam) then
4668 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4670 -- For the Link_Name case, the given literal is preceded by an
4671 -- asterisk, which indicates to GCC that the given name should be
4672 -- taken literally, and in particular that no prepending of
4673 -- underlines should occur, even in systems where this is the
4679 if VM_Target = No_VM then
4680 Store_String_Char (Get_Char_Code ('*'));
4683 String_Val := Strval (Expr_Value_S (Link_Nam));
4684 Store_String_Chars (String_Val);
4686 Make_String_Literal (Sloc (Link_Nam),
4687 Strval => End_String);
4690 Set_Encoded_Interface_Name
4691 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4693 -- We allow duplicated export names in CIL, as they are always
4694 -- enclosed in a namespace that differentiates them, and overloaded
4695 -- entities are supported by the VM.
4697 if Convention (Subprogram_Def) /= Convention_CIL then
4698 Check_Duplicated_Export_Name (Link_Nam);
4700 end Process_Interface_Name;
4702 -----------------------------------------
4703 -- Process_Interrupt_Or_Attach_Handler --
4704 -----------------------------------------
4706 procedure Process_Interrupt_Or_Attach_Handler is
4707 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4708 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4709 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4712 Set_Is_Interrupt_Handler (Handler_Proc);
4714 -- If the pragma is not associated with a handler procedure within a
4715 -- protected type, then it must be for a nonprotected procedure for
4716 -- the AAMP target, in which case we don't associate a representation
4717 -- item with the procedure's scope.
4719 if Ekind (Proc_Scope) = E_Protected_Type then
4720 if Prag_Id = Pragma_Interrupt_Handler
4722 Prag_Id = Pragma_Attach_Handler
4724 Record_Rep_Item (Proc_Scope, N);
4727 end Process_Interrupt_Or_Attach_Handler;
4729 --------------------------------------------------
4730 -- Process_Restrictions_Or_Restriction_Warnings --
4731 --------------------------------------------------
4733 -- Note: some of the simple identifier cases were handled in par-prag,
4734 -- but it is harmless (and more straightforward) to simply handle all
4735 -- cases here, even if it means we repeat a bit of work in some cases.
4737 procedure Process_Restrictions_Or_Restriction_Warnings
4741 R_Id : Restriction_Id;
4746 procedure Check_Unit_Name (N : Node_Id);
4747 -- Checks unit name parameter for No_Dependence. Returns if it has
4748 -- an appropriate form, otherwise raises pragma argument error.
4750 ---------------------
4751 -- Check_Unit_Name --
4752 ---------------------
4754 procedure Check_Unit_Name (N : Node_Id) is
4756 if Nkind (N) = N_Selected_Component then
4757 Check_Unit_Name (Prefix (N));
4758 Check_Unit_Name (Selector_Name (N));
4760 elsif Nkind (N) = N_Identifier then
4765 ("wrong form for unit name for No_Dependence", N);
4767 end Check_Unit_Name;
4769 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4772 -- Ignore all Restrictions pragma in CodePeer mode
4774 if CodePeer_Mode then
4778 Check_Ada_83_Warning;
4779 Check_At_Least_N_Arguments (1);
4780 Check_Valid_Configuration_Pragma;
4783 while Present (Arg) loop
4785 Expr := Get_Pragma_Arg (Arg);
4787 -- Case of no restriction identifier present
4789 if Id = No_Name then
4790 if Nkind (Expr) /= N_Identifier then
4792 ("invalid form for restriction", Arg);
4797 (Process_Restriction_Synonyms (Expr));
4799 if R_Id not in All_Boolean_Restrictions then
4800 Error_Msg_Name_1 := Pname;
4802 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4804 -- Check for possible misspelling
4806 for J in Restriction_Id loop
4808 Rnm : constant String := Restriction_Id'Image (J);
4811 Name_Buffer (1 .. Rnm'Length) := Rnm;
4812 Name_Len := Rnm'Length;
4813 Set_Casing (All_Lower_Case);
4815 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4817 (Identifier_Casing (Current_Source_File));
4818 Error_Msg_String (1 .. Rnm'Length) :=
4819 Name_Buffer (1 .. Name_Len);
4820 Error_Msg_Strlen := Rnm'Length;
4821 Error_Msg_N -- CODEFIX
4822 ("\possible misspelling of ""~""",
4823 Get_Pragma_Arg (Arg));
4832 if Implementation_Restriction (R_Id) then
4833 Check_Restriction (No_Implementation_Restrictions, Arg);
4836 -- If this is a warning, then set the warning unless we already
4837 -- have a real restriction active (we never want a warning to
4838 -- override a real restriction).
4841 if not Restriction_Active (R_Id) then
4842 Set_Restriction (R_Id, N);
4843 Restriction_Warnings (R_Id) := True;
4846 -- If real restriction case, then set it and make sure that the
4847 -- restriction warning flag is off, since a real restriction
4848 -- always overrides a warning.
4851 Set_Restriction (R_Id, N);
4852 Restriction_Warnings (R_Id) := False;
4855 -- Check for obsolescent restrictions in Ada 2005 mode
4858 and then Ada_Version >= Ada_2005
4859 and then (R_Id = No_Asynchronous_Control
4861 R_Id = No_Unchecked_Deallocation
4863 R_Id = No_Unchecked_Conversion)
4865 Check_Restriction (No_Obsolescent_Features, N);
4868 -- A very special case that must be processed here: pragma
4869 -- Restrictions (No_Exceptions) turns off all run-time
4870 -- checking. This is a bit dubious in terms of the formal
4871 -- language definition, but it is what is intended by RM
4872 -- H.4(12). Restriction_Warnings never affects generated code
4873 -- so this is done only in the real restriction case.
4875 if R_Id = No_Exceptions and then not Warn then
4876 Scope_Suppress := (others => True);
4879 -- Case of No_Dependence => unit-name. Note that the parser
4880 -- already made the necessary entry in the No_Dependence table.
4882 elsif Id = Name_No_Dependence then
4883 Check_Unit_Name (Expr);
4885 -- All other cases of restriction identifier present
4888 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4889 Analyze_And_Resolve (Expr, Any_Integer);
4891 if R_Id not in All_Parameter_Restrictions then
4893 ("invalid restriction parameter identifier", Arg);
4895 elsif not Is_OK_Static_Expression (Expr) then
4896 Flag_Non_Static_Expr
4897 ("value must be static expression!", Expr);
4900 elsif not Is_Integer_Type (Etype (Expr))
4901 or else Expr_Value (Expr) < 0
4904 ("value must be non-negative integer", Arg);
4907 -- Restriction pragma is active
4909 Val := Expr_Value (Expr);
4911 if not UI_Is_In_Int_Range (Val) then
4913 ("pragma ignored, value too large?", Arg);
4916 -- Warning case. If the real restriction is active, then we
4917 -- ignore the request, since warning never overrides a real
4918 -- restriction. Otherwise we set the proper warning. Note that
4919 -- this circuit sets the warning again if it is already set,
4920 -- which is what we want, since the constant may have changed.
4923 if not Restriction_Active (R_Id) then
4925 (R_Id, N, Integer (UI_To_Int (Val)));
4926 Restriction_Warnings (R_Id) := True;
4929 -- Real restriction case, set restriction and make sure warning
4930 -- flag is off since real restriction always overrides warning.
4933 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4934 Restriction_Warnings (R_Id) := False;
4940 end Process_Restrictions_Or_Restriction_Warnings;
4942 ---------------------------------
4943 -- Process_Suppress_Unsuppress --
4944 ---------------------------------
4946 -- Note: this procedure makes entries in the check suppress data
4947 -- structures managed by Sem. See spec of package Sem for full
4948 -- details on how we handle recording of check suppression.
4950 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4955 In_Package_Spec : constant Boolean :=
4956 Is_Package_Or_Generic_Package (Current_Scope)
4957 and then not In_Package_Body (Current_Scope);
4959 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4960 -- Used to suppress a single check on the given entity
4962 --------------------------------
4963 -- Suppress_Unsuppress_Echeck --
4964 --------------------------------
4966 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4968 Set_Checks_May_Be_Suppressed (E);
4970 if In_Package_Spec then
4971 Push_Global_Suppress_Stack_Entry
4974 Suppress => Suppress_Case);
4977 Push_Local_Suppress_Stack_Entry
4980 Suppress => Suppress_Case);
4983 -- If this is a first subtype, and the base type is distinct,
4984 -- then also set the suppress flags on the base type.
4986 if Is_First_Subtype (E)
4987 and then Etype (E) /= E
4989 Suppress_Unsuppress_Echeck (Etype (E), C);
4991 end Suppress_Unsuppress_Echeck;
4993 -- Start of processing for Process_Suppress_Unsuppress
4996 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
4997 -- we want to generate checks for analysis purposes, as set by -gnatC
4999 if CodePeer_Mode and then Comes_From_Source (N) then
5003 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5004 -- declarative part or a package spec (RM 11.5(5)).
5006 if not Is_Configuration_Pragma then
5007 Check_Is_In_Decl_Part_Or_Package_Spec;
5010 Check_At_Least_N_Arguments (1);
5011 Check_At_Most_N_Arguments (2);
5012 Check_No_Identifier (Arg1);
5013 Check_Arg_Is_Identifier (Arg1);
5015 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5017 if C = No_Check_Id then
5019 ("argument of pragma% is not valid check name", Arg1);
5022 if not Suppress_Case
5023 and then (C = All_Checks or else C = Overflow_Check)
5025 Opt.Overflow_Checks_Unsuppressed := True;
5028 if Arg_Count = 1 then
5030 -- Make an entry in the local scope suppress table. This is the
5031 -- table that directly shows the current value of the scope
5032 -- suppress check for any check id value.
5034 if C = All_Checks then
5036 -- For All_Checks, we set all specific predefined checks with
5037 -- the exception of Elaboration_Check, which is handled
5038 -- specially because of not wanting All_Checks to have the
5039 -- effect of deactivating static elaboration order processing.
5041 for J in Scope_Suppress'Range loop
5042 if J /= Elaboration_Check then
5043 Scope_Suppress (J) := Suppress_Case;
5047 -- If not All_Checks, and predefined check, then set appropriate
5048 -- scope entry. Note that we will set Elaboration_Check if this
5049 -- is explicitly specified.
5051 elsif C in Predefined_Check_Id then
5052 Scope_Suppress (C) := Suppress_Case;
5055 -- Also make an entry in the Local_Entity_Suppress table
5057 Push_Local_Suppress_Stack_Entry
5060 Suppress => Suppress_Case);
5062 -- Case of two arguments present, where the check is suppressed for
5063 -- a specified entity (given as the second argument of the pragma)
5066 -- This is obsolescent in Ada 2005 mode
5068 if Ada_Version >= Ada_2005 then
5069 Check_Restriction (No_Obsolescent_Features, Arg2);
5072 Check_Optional_Identifier (Arg2, Name_On);
5073 E_Id := Get_Pragma_Arg (Arg2);
5076 if not Is_Entity_Name (E_Id) then
5078 ("second argument of pragma% must be entity name", Arg2);
5087 -- Enforce RM 11.5(7) which requires that for a pragma that
5088 -- appears within a package spec, the named entity must be
5089 -- within the package spec. We allow the package name itself
5090 -- to be mentioned since that makes sense, although it is not
5091 -- strictly allowed by 11.5(7).
5094 and then E /= Current_Scope
5095 and then Scope (E) /= Current_Scope
5098 ("entity in pragma% is not in package spec (RM 11.5(7))",
5102 -- Loop through homonyms. As noted below, in the case of a package
5103 -- spec, only homonyms within the package spec are considered.
5106 Suppress_Unsuppress_Echeck (E, C);
5108 if Is_Generic_Instance (E)
5109 and then Is_Subprogram (E)
5110 and then Present (Alias (E))
5112 Suppress_Unsuppress_Echeck (Alias (E), C);
5115 -- Move to next homonym if not aspect spec case
5117 exit when From_Aspect_Specification (N);
5121 -- If we are within a package specification, the pragma only
5122 -- applies to homonyms in the same scope.
5124 exit when In_Package_Spec
5125 and then Scope (E) /= Current_Scope;
5128 end Process_Suppress_Unsuppress;
5134 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5136 if Is_Imported (E) then
5138 ("cannot export entity& that was previously imported", Arg);
5140 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5142 ("cannot export entity& that has an address clause", Arg);
5145 Set_Is_Exported (E);
5147 -- Generate a reference for entity explicitly, because the
5148 -- identifier may be overloaded and name resolution will not
5151 Generate_Reference (E, Arg);
5153 -- Deal with exporting non-library level entity
5155 if not Is_Library_Level_Entity (E) then
5157 -- Not allowed at all for subprograms
5159 if Is_Subprogram (E) then
5160 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5162 -- Otherwise set public and statically allocated
5166 Set_Is_Statically_Allocated (E);
5168 -- Warn if the corresponding W flag is set and the pragma comes
5169 -- from source. The latter may not be true e.g. on VMS where we
5170 -- expand export pragmas for exception codes associated with
5171 -- imported or exported exceptions. We do not want to generate
5172 -- a warning for something that the user did not write.
5174 if Warn_On_Export_Import
5175 and then Comes_From_Source (Arg)
5178 ("?& has been made static as a result of Export", Arg, E);
5180 ("\this usage is non-standard and non-portable", Arg);
5185 if Warn_On_Export_Import and then Is_Type (E) then
5186 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5189 if Warn_On_Export_Import and Inside_A_Generic then
5191 ("all instances of& will have the same external name?", Arg, E);
5195 ----------------------------------------------
5196 -- Set_Extended_Import_Export_External_Name --
5197 ----------------------------------------------
5199 procedure Set_Extended_Import_Export_External_Name
5200 (Internal_Ent : Entity_Id;
5201 Arg_External : Node_Id)
5203 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5207 if No (Arg_External) then
5211 Check_Arg_Is_External_Name (Arg_External);
5213 if Nkind (Arg_External) = N_String_Literal then
5214 if String_Length (Strval (Arg_External)) = 0 then
5217 New_Name := Adjust_External_Name_Case (Arg_External);
5220 elsif Nkind (Arg_External) = N_Identifier then
5221 New_Name := Get_Default_External_Name (Arg_External);
5223 -- Check_Arg_Is_External_Name should let through only identifiers and
5224 -- string literals or static string expressions (which are folded to
5225 -- string literals).
5228 raise Program_Error;
5231 -- If we already have an external name set (by a prior normal Import
5232 -- or Export pragma), then the external names must match
5234 if Present (Interface_Name (Internal_Ent)) then
5235 Check_Matching_Internal_Names : declare
5236 S1 : constant String_Id := Strval (Old_Name);
5237 S2 : constant String_Id := Strval (New_Name);
5240 -- Called if names do not match
5246 procedure Mismatch is
5248 Error_Msg_Sloc := Sloc (Old_Name);
5250 ("external name does not match that given #",
5254 -- Start of processing for Check_Matching_Internal_Names
5257 if String_Length (S1) /= String_Length (S2) then
5261 for J in 1 .. String_Length (S1) loop
5262 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5267 end Check_Matching_Internal_Names;
5269 -- Otherwise set the given name
5272 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5273 Check_Duplicated_Export_Name (New_Name);
5275 end Set_Extended_Import_Export_External_Name;
5281 procedure Set_Imported (E : Entity_Id) is
5283 -- Error message if already imported or exported
5285 if Is_Exported (E) or else Is_Imported (E) then
5287 -- Error if being set Exported twice
5289 if Is_Exported (E) then
5290 Error_Msg_NE ("entity& was previously exported", N, E);
5292 -- OK if Import/Interface case
5294 elsif Import_Interface_Present (N) then
5297 -- Error if being set Imported twice
5300 Error_Msg_NE ("entity& was previously imported", N, E);
5303 Error_Msg_Name_1 := Pname;
5305 ("\(pragma% applies to all previous entities)", N);
5307 Error_Msg_Sloc := Sloc (E);
5308 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5310 -- Here if not previously imported or exported, OK to import
5313 Set_Is_Imported (E);
5315 -- If the entity is an object that is not at the library level,
5316 -- then it is statically allocated. We do not worry about objects
5317 -- with address clauses in this context since they are not really
5318 -- imported in the linker sense.
5321 and then not Is_Library_Level_Entity (E)
5322 and then No (Address_Clause (E))
5324 Set_Is_Statically_Allocated (E);
5331 -------------------------
5332 -- Set_Mechanism_Value --
5333 -------------------------
5335 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5336 -- analyzed, since it is semantic nonsense), so we get it in the exact
5337 -- form created by the parser.
5339 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5342 Mech_Name_Id : Name_Id;
5344 procedure Bad_Class;
5345 -- Signal bad descriptor class name
5347 procedure Bad_Mechanism;
5348 -- Signal bad mechanism name
5354 procedure Bad_Class is
5356 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5359 -------------------------
5360 -- Bad_Mechanism_Value --
5361 -------------------------
5363 procedure Bad_Mechanism is
5365 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5368 -- Start of processing for Set_Mechanism_Value
5371 if Mechanism (Ent) /= Default_Mechanism then
5373 ("mechanism for & has already been set", Mech_Name, Ent);
5376 -- MECHANISM_NAME ::= value | reference | descriptor |
5379 if Nkind (Mech_Name) = N_Identifier then
5380 if Chars (Mech_Name) = Name_Value then
5381 Set_Mechanism (Ent, By_Copy);
5384 elsif Chars (Mech_Name) = Name_Reference then
5385 Set_Mechanism (Ent, By_Reference);
5388 elsif Chars (Mech_Name) = Name_Descriptor then
5389 Check_VMS (Mech_Name);
5391 -- Descriptor => Short_Descriptor if pragma was given
5393 if Short_Descriptors then
5394 Set_Mechanism (Ent, By_Short_Descriptor);
5396 Set_Mechanism (Ent, By_Descriptor);
5401 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5402 Check_VMS (Mech_Name);
5403 Set_Mechanism (Ent, By_Short_Descriptor);
5406 elsif Chars (Mech_Name) = Name_Copy then
5408 ("bad mechanism name, Value assumed", Mech_Name);
5414 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5415 -- short_descriptor (CLASS_NAME)
5416 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5418 -- Note: this form is parsed as an indexed component
5420 elsif Nkind (Mech_Name) = N_Indexed_Component then
5421 Class := First (Expressions (Mech_Name));
5423 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5424 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5425 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5426 or else Present (Next (Class))
5430 Mech_Name_Id := Chars (Prefix (Mech_Name));
5432 -- Change Descriptor => Short_Descriptor if pragma was given
5434 if Mech_Name_Id = Name_Descriptor
5435 and then Short_Descriptors
5437 Mech_Name_Id := Name_Short_Descriptor;
5441 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5442 -- short_descriptor (Class => CLASS_NAME)
5443 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5445 -- Note: this form is parsed as a function call
5447 elsif Nkind (Mech_Name) = N_Function_Call then
5448 Param := First (Parameter_Associations (Mech_Name));
5450 if Nkind (Name (Mech_Name)) /= N_Identifier
5451 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5452 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5453 or else Present (Next (Param))
5454 or else No (Selector_Name (Param))
5455 or else Chars (Selector_Name (Param)) /= Name_Class
5459 Class := Explicit_Actual_Parameter (Param);
5460 Mech_Name_Id := Chars (Name (Mech_Name));
5467 -- Fall through here with Class set to descriptor class name
5469 Check_VMS (Mech_Name);
5471 if Nkind (Class) /= N_Identifier then
5474 elsif Mech_Name_Id = Name_Descriptor
5475 and then Chars (Class) = Name_UBS
5477 Set_Mechanism (Ent, By_Descriptor_UBS);
5479 elsif Mech_Name_Id = Name_Descriptor
5480 and then Chars (Class) = Name_UBSB
5482 Set_Mechanism (Ent, By_Descriptor_UBSB);
5484 elsif Mech_Name_Id = Name_Descriptor
5485 and then Chars (Class) = Name_UBA
5487 Set_Mechanism (Ent, By_Descriptor_UBA);
5489 elsif Mech_Name_Id = Name_Descriptor
5490 and then Chars (Class) = Name_S
5492 Set_Mechanism (Ent, By_Descriptor_S);
5494 elsif Mech_Name_Id = Name_Descriptor
5495 and then Chars (Class) = Name_SB
5497 Set_Mechanism (Ent, By_Descriptor_SB);
5499 elsif Mech_Name_Id = Name_Descriptor
5500 and then Chars (Class) = Name_A
5502 Set_Mechanism (Ent, By_Descriptor_A);
5504 elsif Mech_Name_Id = Name_Descriptor
5505 and then Chars (Class) = Name_NCA
5507 Set_Mechanism (Ent, By_Descriptor_NCA);
5509 elsif Mech_Name_Id = Name_Short_Descriptor
5510 and then Chars (Class) = Name_UBS
5512 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5514 elsif Mech_Name_Id = Name_Short_Descriptor
5515 and then Chars (Class) = Name_UBSB
5517 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5519 elsif Mech_Name_Id = Name_Short_Descriptor
5520 and then Chars (Class) = Name_UBA
5522 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5524 elsif Mech_Name_Id = Name_Short_Descriptor
5525 and then Chars (Class) = Name_S
5527 Set_Mechanism (Ent, By_Short_Descriptor_S);
5529 elsif Mech_Name_Id = Name_Short_Descriptor
5530 and then Chars (Class) = Name_SB
5532 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5534 elsif Mech_Name_Id = Name_Short_Descriptor
5535 and then Chars (Class) = Name_A
5537 Set_Mechanism (Ent, By_Short_Descriptor_A);
5539 elsif Mech_Name_Id = Name_Short_Descriptor
5540 and then Chars (Class) = Name_NCA
5542 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5547 end Set_Mechanism_Value;
5549 ---------------------------
5550 -- Set_Ravenscar_Profile --
5551 ---------------------------
5553 -- The tasks to be done here are
5555 -- Set required policies
5557 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5558 -- pragma Locking_Policy (Ceiling_Locking)
5560 -- Set Detect_Blocking mode
5562 -- Set required restrictions (see System.Rident for detailed list)
5564 -- Set the No_Dependence rules
5565 -- No_Dependence => Ada.Asynchronous_Task_Control
5566 -- No_Dependence => Ada.Calendar
5567 -- No_Dependence => Ada.Execution_Time.Group_Budget
5568 -- No_Dependence => Ada.Execution_Time.Timers
5569 -- No_Dependence => Ada.Task_Attributes
5570 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5572 procedure Set_Ravenscar_Profile (N : Node_Id) is
5573 Prefix_Entity : Entity_Id;
5574 Selector_Entity : Entity_Id;
5575 Prefix_Node : Node_Id;
5579 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5581 if Task_Dispatching_Policy /= ' '
5582 and then Task_Dispatching_Policy /= 'F'
5584 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5585 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5587 -- Set the FIFO_Within_Priorities policy, but always preserve
5588 -- System_Location since we like the error message with the run time
5592 Task_Dispatching_Policy := 'F';
5594 if Task_Dispatching_Policy_Sloc /= System_Location then
5595 Task_Dispatching_Policy_Sloc := Loc;
5599 -- pragma Locking_Policy (Ceiling_Locking)
5601 if Locking_Policy /= ' '
5602 and then Locking_Policy /= 'C'
5604 Error_Msg_Sloc := Locking_Policy_Sloc;
5605 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5607 -- Set the Ceiling_Locking policy, but preserve System_Location since
5608 -- we like the error message with the run time name.
5611 Locking_Policy := 'C';
5613 if Locking_Policy_Sloc /= System_Location then
5614 Locking_Policy_Sloc := Loc;
5618 -- pragma Detect_Blocking
5620 Detect_Blocking := True;
5622 -- Set the corresponding restrictions
5624 Set_Profile_Restrictions
5625 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5627 -- Set the No_Dependence restrictions
5629 -- The following No_Dependence restrictions:
5630 -- No_Dependence => Ada.Asynchronous_Task_Control
5631 -- No_Dependence => Ada.Calendar
5632 -- No_Dependence => Ada.Task_Attributes
5633 -- are already set by previous call to Set_Profile_Restrictions.
5635 -- Set the following restrictions which were added to Ada 2005:
5636 -- No_Dependence => Ada.Execution_Time.Group_Budget
5637 -- No_Dependence => Ada.Execution_Time.Timers
5639 if Ada_Version >= Ada_2005 then
5640 Name_Buffer (1 .. 3) := "ada";
5643 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5645 Name_Buffer (1 .. 14) := "execution_time";
5648 Selector_Entity := Make_Identifier (Loc, Name_Find);
5651 Make_Selected_Component
5653 Prefix => Prefix_Entity,
5654 Selector_Name => Selector_Entity);
5656 Name_Buffer (1 .. 13) := "group_budgets";
5659 Selector_Entity := Make_Identifier (Loc, Name_Find);
5662 Make_Selected_Component
5664 Prefix => Prefix_Node,
5665 Selector_Name => Selector_Entity);
5667 Set_Restriction_No_Dependence
5669 Warn => Treat_Restrictions_As_Warnings,
5670 Profile => Ravenscar);
5672 Name_Buffer (1 .. 6) := "timers";
5675 Selector_Entity := Make_Identifier (Loc, Name_Find);
5678 Make_Selected_Component
5680 Prefix => Prefix_Node,
5681 Selector_Name => Selector_Entity);
5683 Set_Restriction_No_Dependence
5685 Warn => Treat_Restrictions_As_Warnings,
5686 Profile => Ravenscar);
5689 -- Set the following restrictions which was added to Ada 2012 (see
5691 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5693 if Ada_Version >= Ada_2012 then
5694 Name_Buffer (1 .. 6) := "system";
5697 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5699 Name_Buffer (1 .. 15) := "multiprocessors";
5702 Selector_Entity := Make_Identifier (Loc, Name_Find);
5705 Make_Selected_Component
5707 Prefix => Prefix_Entity,
5708 Selector_Name => Selector_Entity);
5710 Name_Buffer (1 .. 19) := "dispatching_domains";
5713 Selector_Entity := Make_Identifier (Loc, Name_Find);
5716 Make_Selected_Component
5718 Prefix => Prefix_Node,
5719 Selector_Name => Selector_Entity);
5721 Set_Restriction_No_Dependence
5723 Warn => Treat_Restrictions_As_Warnings,
5724 Profile => Ravenscar);
5726 end Set_Ravenscar_Profile;
5728 -- Start of processing for Analyze_Pragma
5731 -- The following code is a defense against recursion. Not clear that
5732 -- this can happen legitimately, but perhaps some error situations
5733 -- can cause it, and we did see this recursion during testing.
5735 if Analyzed (N) then
5738 Set_Analyzed (N, True);
5741 -- Deal with unrecognized pragma
5743 if not Is_Pragma_Name (Pname) then
5744 if Warn_On_Unrecognized_Pragma then
5745 Error_Msg_Name_1 := Pname;
5746 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5748 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5749 if Is_Bad_Spelling_Of (Pname, PN) then
5750 Error_Msg_Name_1 := PN;
5751 Error_Msg_N -- CODEFIX
5752 ("\?possible misspelling of %!", Pragma_Identifier (N));
5761 -- Here to start processing for recognized pragma
5763 Prag_Id := Get_Pragma_Id (Pname);
5773 if Present (Pragma_Argument_Associations (N)) then
5774 Arg_Count := List_Length (Pragma_Argument_Associations (N));
5775 Arg1 := First (Pragma_Argument_Associations (N));
5777 if Present (Arg1) then
5778 Arg2 := Next (Arg1);
5780 if Present (Arg2) then
5781 Arg3 := Next (Arg2);
5783 if Present (Arg3) then
5784 Arg4 := Next (Arg3);
5790 -- An enumeration type defines the pragmas that are supported by the
5791 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5792 -- into the corresponding enumeration value for the following case.
5800 -- pragma Abort_Defer;
5802 when Pragma_Abort_Defer =>
5804 Check_Arg_Count (0);
5806 -- The only required semantic processing is to check the
5807 -- placement. This pragma must appear at the start of the
5808 -- statement sequence of a handled sequence of statements.
5810 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5811 or else N /= First (Statements (Parent (N)))
5822 -- Note: this pragma also has some specific processing in Par.Prag
5823 -- because we want to set the Ada version mode during parsing.
5825 when Pragma_Ada_83 =>
5827 Check_Arg_Count (0);
5829 -- We really should check unconditionally for proper configuration
5830 -- pragma placement, since we really don't want mixed Ada modes
5831 -- within a single unit, and the GNAT reference manual has always
5832 -- said this was a configuration pragma, but we did not check and
5833 -- are hesitant to add the check now.
5835 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5836 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5837 -- or Ada 2012 mode.
5839 if Ada_Version >= Ada_2005 then
5840 Check_Valid_Configuration_Pragma;
5843 -- Now set Ada 83 mode
5845 Ada_Version := Ada_83;
5846 Ada_Version_Explicit := Ada_Version;
5854 -- Note: this pragma also has some specific processing in Par.Prag
5855 -- because we want to set the Ada 83 version mode during parsing.
5857 when Pragma_Ada_95 =>
5859 Check_Arg_Count (0);
5861 -- We really should check unconditionally for proper configuration
5862 -- pragma placement, since we really don't want mixed Ada modes
5863 -- within a single unit, and the GNAT reference manual has always
5864 -- said this was a configuration pragma, but we did not check and
5865 -- are hesitant to add the check now.
5867 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5868 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5870 if Ada_Version >= Ada_2005 then
5871 Check_Valid_Configuration_Pragma;
5874 -- Now set Ada 95 mode
5876 Ada_Version := Ada_95;
5877 Ada_Version_Explicit := Ada_Version;
5879 ---------------------
5880 -- Ada_05/Ada_2005 --
5881 ---------------------
5884 -- pragma Ada_05 (LOCAL_NAME);
5887 -- pragma Ada_2005 (LOCAL_NAME):
5889 -- Note: these pragmas also have some specific processing in Par.Prag
5890 -- because we want to set the Ada 2005 version mode during parsing.
5892 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5898 if Arg_Count = 1 then
5899 Check_Arg_Is_Local_Name (Arg1);
5900 E_Id := Get_Pragma_Arg (Arg1);
5902 if Etype (E_Id) = Any_Type then
5906 Set_Is_Ada_2005_Only (Entity (E_Id));
5909 Check_Arg_Count (0);
5911 -- For Ada_2005 we unconditionally enforce the documented
5912 -- configuration pragma placement, since we do not want to
5913 -- tolerate mixed modes in a unit involving Ada 2005. That
5914 -- would cause real difficulties for those cases where there
5915 -- are incompatibilities between Ada 95 and Ada 2005.
5917 Check_Valid_Configuration_Pragma;
5919 -- Now set appropriate Ada mode
5921 Ada_Version := Ada_2005;
5922 Ada_Version_Explicit := Ada_2005;
5926 ---------------------
5927 -- Ada_12/Ada_2012 --
5928 ---------------------
5931 -- pragma Ada_12 (LOCAL_NAME);
5934 -- pragma Ada_2012 (LOCAL_NAME):
5936 -- Note: these pragmas also have some specific processing in Par.Prag
5937 -- because we want to set the Ada 2012 version mode during parsing.
5939 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5945 if Arg_Count = 1 then
5946 Check_Arg_Is_Local_Name (Arg1);
5947 E_Id := Get_Pragma_Arg (Arg1);
5949 if Etype (E_Id) = Any_Type then
5953 Set_Is_Ada_2012_Only (Entity (E_Id));
5956 Check_Arg_Count (0);
5958 -- For Ada_2012 we unconditionally enforce the documented
5959 -- configuration pragma placement, since we do not want to
5960 -- tolerate mixed modes in a unit involving Ada 2012. That
5961 -- would cause real difficulties for those cases where there
5962 -- are incompatibilities between Ada 95 and Ada 2012. We could
5963 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5965 Check_Valid_Configuration_Pragma;
5967 -- Now set appropriate Ada mode
5969 Ada_Version := Ada_2012;
5970 Ada_Version_Explicit := Ada_2012;
5974 ----------------------
5975 -- All_Calls_Remote --
5976 ----------------------
5978 -- pragma All_Calls_Remote [(library_package_NAME)];
5980 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5981 Lib_Entity : Entity_Id;
5984 Check_Ada_83_Warning;
5985 Check_Valid_Library_Unit_Pragma;
5987 if Nkind (N) = N_Null_Statement then
5991 Lib_Entity := Find_Lib_Unit_Name;
5993 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5995 if Present (Lib_Entity)
5996 and then not Debug_Flag_U
5998 if not Is_Remote_Call_Interface (Lib_Entity) then
5999 Error_Pragma ("pragma% only apply to rci unit");
6001 -- Set flag for entity of the library unit
6004 Set_Has_All_Calls_Remote (Lib_Entity);
6008 end All_Calls_Remote;
6014 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6015 -- ARG ::= NAME | EXPRESSION
6017 -- The first two arguments are by convention intended to refer to an
6018 -- external tool and a tool-specific function. These arguments are
6021 when Pragma_Annotate => Annotate : begin
6023 Check_At_Least_N_Arguments (1);
6024 Check_Arg_Is_Identifier (Arg1);
6025 Check_No_Identifiers;
6033 -- Second unanalyzed parameter is optional
6039 while Present (Arg) loop
6040 Exp := Get_Pragma_Arg (Arg);
6043 if Is_Entity_Name (Exp) then
6046 -- For string literals, we assume Standard_String as the
6047 -- type, unless the string contains wide or wide_wide
6050 elsif Nkind (Exp) = N_String_Literal then
6051 if Has_Wide_Wide_Character (Exp) then
6052 Resolve (Exp, Standard_Wide_Wide_String);
6053 elsif Has_Wide_Character (Exp) then
6054 Resolve (Exp, Standard_Wide_String);
6056 Resolve (Exp, Standard_String);
6059 elsif Is_Overloaded (Exp) then
6061 ("ambiguous argument for pragma%", Exp);
6077 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6078 -- [, [Message =>] Static_String_EXPRESSION]);
6080 when Pragma_Assert => Assert : declare
6086 Check_At_Least_N_Arguments (1);
6087 Check_At_Most_N_Arguments (2);
6088 Check_Arg_Order ((Name_Check, Name_Message));
6089 Check_Optional_Identifier (Arg1, Name_Check);
6091 -- We treat pragma Assert as equivalent to:
6093 -- pragma Check (Assertion, condition [, msg]);
6095 -- So rewrite pragma in this manner, and analyze the result
6097 Expr := Get_Pragma_Arg (Arg1);
6099 Make_Pragma_Argument_Association (Loc,
6100 Expression => Make_Identifier (Loc, Name_Assertion)),
6102 Make_Pragma_Argument_Association (Sloc (Expr),
6103 Expression => Expr));
6105 if Arg_Count > 1 then
6106 Check_Optional_Identifier (Arg2, Name_Message);
6107 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6108 Append_To (Newa, Relocate_Node (Arg2));
6113 Chars => Name_Check,
6114 Pragma_Argument_Associations => Newa));
6118 ----------------------
6119 -- Assertion_Policy --
6120 ----------------------
6122 -- pragma Assertion_Policy (Check | Ignore)
6124 when Pragma_Assertion_Policy => Assertion_Policy : declare
6129 Check_Valid_Configuration_Pragma;
6130 Check_Arg_Count (1);
6131 Check_No_Identifiers;
6132 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6134 -- We treat pragma Assertion_Policy as equivalent to:
6136 -- pragma Check_Policy (Assertion, policy)
6138 -- So rewrite the pragma in that manner and link on to the chain
6139 -- of Check_Policy pragmas, marking the pragma as analyzed.
6141 Policy := Get_Pragma_Arg (Arg1);
6145 Chars => Name_Check_Policy,
6147 Pragma_Argument_Associations => New_List (
6148 Make_Pragma_Argument_Association (Loc,
6149 Expression => Make_Identifier (Loc, Name_Assertion)),
6151 Make_Pragma_Argument_Association (Loc,
6153 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6156 Set_Next_Pragma (N, Opt.Check_Policy_List);
6157 Opt.Check_Policy_List := N;
6158 end Assertion_Policy;
6160 ------------------------------
6161 -- Assume_No_Invalid_Values --
6162 ------------------------------
6164 -- pragma Assume_No_Invalid_Values (On | Off);
6166 when Pragma_Assume_No_Invalid_Values =>
6168 Check_Valid_Configuration_Pragma;
6169 Check_Arg_Count (1);
6170 Check_No_Identifiers;
6171 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6173 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6174 Assume_No_Invalid_Values := True;
6176 Assume_No_Invalid_Values := False;
6183 -- pragma AST_Entry (entry_IDENTIFIER);
6185 when Pragma_AST_Entry => AST_Entry : declare
6191 Check_Arg_Count (1);
6192 Check_No_Identifiers;
6193 Check_Arg_Is_Local_Name (Arg1);
6194 Ent := Entity (Get_Pragma_Arg (Arg1));
6196 -- Note: the implementation of the AST_Entry pragma could handle
6197 -- the entry family case fine, but for now we are consistent with
6198 -- the DEC rules, and do not allow the pragma, which of course
6199 -- has the effect of also forbidding the attribute.
6201 if Ekind (Ent) /= E_Entry then
6203 ("pragma% argument must be simple entry name", Arg1);
6205 elsif Is_AST_Entry (Ent) then
6207 ("duplicate % pragma for entry", Arg1);
6209 elsif Has_Homonym (Ent) then
6211 ("pragma% argument cannot specify overloaded entry", Arg1);
6215 FF : constant Entity_Id := First_Formal (Ent);
6218 if Present (FF) then
6219 if Present (Next_Formal (FF)) then
6221 ("entry for pragma% can have only one argument",
6224 elsif Parameter_Mode (FF) /= E_In_Parameter then
6226 ("entry parameter for pragma% must have mode IN",
6232 Set_Is_AST_Entry (Ent);
6240 -- pragma Asynchronous (LOCAL_NAME);
6242 when Pragma_Asynchronous => Asynchronous : declare
6250 procedure Process_Async_Pragma;
6251 -- Common processing for procedure and access-to-procedure case
6253 --------------------------
6254 -- Process_Async_Pragma --
6255 --------------------------
6257 procedure Process_Async_Pragma is
6260 Set_Is_Asynchronous (Nm);
6264 -- The formals should be of mode IN (RM E.4.1(6))
6267 while Present (S) loop
6268 Formal := Defining_Identifier (S);
6270 if Nkind (Formal) = N_Defining_Identifier
6271 and then Ekind (Formal) /= E_In_Parameter
6274 ("pragma% procedure can only have IN parameter",
6281 Set_Is_Asynchronous (Nm);
6282 end Process_Async_Pragma;
6284 -- Start of processing for pragma Asynchronous
6287 Check_Ada_83_Warning;
6288 Check_No_Identifiers;
6289 Check_Arg_Count (1);
6290 Check_Arg_Is_Local_Name (Arg1);
6292 if Debug_Flag_U then
6296 C_Ent := Cunit_Entity (Current_Sem_Unit);
6297 Analyze (Get_Pragma_Arg (Arg1));
6298 Nm := Entity (Get_Pragma_Arg (Arg1));
6300 if not Is_Remote_Call_Interface (C_Ent)
6301 and then not Is_Remote_Types (C_Ent)
6303 -- This pragma should only appear in an RCI or Remote Types
6304 -- unit (RM E.4.1(4)).
6307 ("pragma% not in Remote_Call_Interface or " &
6308 "Remote_Types unit");
6311 if Ekind (Nm) = E_Procedure
6312 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6314 if not Is_Remote_Call_Interface (Nm) then
6316 ("pragma% cannot be applied on non-remote procedure",
6320 L := Parameter_Specifications (Parent (Nm));
6321 Process_Async_Pragma;
6324 elsif Ekind (Nm) = E_Function then
6326 ("pragma% cannot be applied to function", Arg1);
6328 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6330 if Is_Record_Type (Nm) then
6332 -- A record type that is the Equivalent_Type for a remote
6333 -- access-to-subprogram type.
6335 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6338 -- A non-expanded RAS type (distribution is not enabled)
6340 N := Declaration_Node (Nm);
6343 if Nkind (N) = N_Full_Type_Declaration
6344 and then Nkind (Type_Definition (N)) =
6345 N_Access_Procedure_Definition
6347 L := Parameter_Specifications (Type_Definition (N));
6348 Process_Async_Pragma;
6350 if Is_Asynchronous (Nm)
6351 and then Expander_Active
6352 and then Get_PCS_Name /= Name_No_DSA
6354 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6359 ("pragma% cannot reference access-to-function type",
6363 -- Only other possibility is Access-to-class-wide type
6365 elsif Is_Access_Type (Nm)
6366 and then Is_Class_Wide_Type (Designated_Type (Nm))
6368 Check_First_Subtype (Arg1);
6369 Set_Is_Asynchronous (Nm);
6370 if Expander_Active then
6371 RACW_Type_Is_Asynchronous (Nm);
6375 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6383 -- pragma Atomic (LOCAL_NAME);
6385 when Pragma_Atomic =>
6386 Process_Atomic_Shared_Volatile;
6388 -----------------------
6389 -- Atomic_Components --
6390 -----------------------
6392 -- pragma Atomic_Components (array_LOCAL_NAME);
6394 -- This processing is shared by Volatile_Components
6396 when Pragma_Atomic_Components |
6397 Pragma_Volatile_Components =>
6399 Atomic_Components : declare
6406 Check_Ada_83_Warning;
6407 Check_No_Identifiers;
6408 Check_Arg_Count (1);
6409 Check_Arg_Is_Local_Name (Arg1);
6410 E_Id := Get_Pragma_Arg (Arg1);
6412 if Etype (E_Id) = Any_Type then
6418 Check_Duplicate_Pragma (E);
6420 if Rep_Item_Too_Early (E, N)
6422 Rep_Item_Too_Late (E, N)
6427 D := Declaration_Node (E);
6430 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6432 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6433 and then Nkind (D) = N_Object_Declaration
6434 and then Nkind (Object_Definition (D)) =
6435 N_Constrained_Array_Definition)
6437 -- The flag is set on the object, or on the base type
6439 if Nkind (D) /= N_Object_Declaration then
6443 Set_Has_Volatile_Components (E);
6445 if Prag_Id = Pragma_Atomic_Components then
6446 Set_Has_Atomic_Components (E);
6450 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6452 end Atomic_Components;
6454 --------------------
6455 -- Attach_Handler --
6456 --------------------
6458 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6460 when Pragma_Attach_Handler =>
6461 Check_Ada_83_Warning;
6462 Check_No_Identifiers;
6463 Check_Arg_Count (2);
6465 if No_Run_Time_Mode then
6466 Error_Msg_CRT ("Attach_Handler pragma", N);
6468 Check_Interrupt_Or_Attach_Handler;
6470 -- The expression that designates the attribute may depend on a
6471 -- discriminant, and is therefore a per- object expression, to
6472 -- be expanded in the init proc. If expansion is enabled, then
6473 -- perform semantic checks on a copy only.
6475 if Expander_Active then
6477 Temp : constant Node_Id :=
6478 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6480 Set_Parent (Temp, N);
6481 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6485 Analyze (Get_Pragma_Arg (Arg2));
6486 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6489 Process_Interrupt_Or_Attach_Handler;
6492 --------------------
6493 -- C_Pass_By_Copy --
6494 --------------------
6496 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6498 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6504 Check_Valid_Configuration_Pragma;
6505 Check_Arg_Count (1);
6506 Check_Optional_Identifier (Arg1, "max_size");
6508 Arg := Get_Pragma_Arg (Arg1);
6509 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6511 Val := Expr_Value (Arg);
6515 ("maximum size for pragma% must be positive", Arg1);
6517 elsif UI_Is_In_Int_Range (Val) then
6518 Default_C_Record_Mechanism := UI_To_Int (Val);
6520 -- If a giant value is given, Int'Last will do well enough.
6521 -- If sometime someone complains that a record larger than
6522 -- two gigabytes is not copied, we will worry about it then!
6525 Default_C_Record_Mechanism := Mechanism_Type'Last;
6533 -- pragma Check ([Name =>] Identifier,
6534 -- [Check =>] Boolean_Expression
6535 -- [,[Message =>] String_Expression]);
6537 when Pragma_Check => Check : declare
6542 -- Set True if category of assertions referenced by Name enabled
6546 Check_At_Least_N_Arguments (2);
6547 Check_At_Most_N_Arguments (3);
6548 Check_Optional_Identifier (Arg1, Name_Name);
6549 Check_Optional_Identifier (Arg2, Name_Check);
6551 if Arg_Count = 3 then
6552 Check_Optional_Identifier (Arg3, Name_Message);
6553 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6556 Check_Arg_Is_Identifier (Arg1);
6558 -- Indicate if pragma is enabled. The Original_Node reference here
6559 -- is to deal with pragma Assert rewritten as a Check pragma.
6561 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6564 Set_Pragma_Enabled (N);
6565 Set_Pragma_Enabled (Original_Node (N));
6566 Set_SCO_Pragma_Enabled (Loc);
6569 -- If expansion is active and the check is not enabled then we
6570 -- rewrite the Check as:
6572 -- if False and then condition then
6576 -- The reason we do this rewriting during semantic analysis rather
6577 -- than as part of normal expansion is that we cannot analyze and
6578 -- expand the code for the boolean expression directly, or it may
6579 -- cause insertion of actions that would escape the attempt to
6580 -- suppress the check code.
6582 -- Note that the Sloc for the if statement corresponds to the
6583 -- argument condition, not the pragma itself. The reason for this
6584 -- is that we may generate a warning if the condition is False at
6585 -- compile time, and we do not want to delete this warning when we
6586 -- delete the if statement.
6588 Expr := Get_Pragma_Arg (Arg2);
6590 if Expander_Active and then not Check_On then
6591 Eloc := Sloc (Expr);
6594 Make_If_Statement (Eloc,
6596 Make_And_Then (Eloc,
6597 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6598 Right_Opnd => Expr),
6599 Then_Statements => New_List (
6600 Make_Null_Statement (Eloc))));
6607 Analyze_And_Resolve (Expr, Any_Boolean);
6615 -- pragma Check_Name (check_IDENTIFIER);
6617 when Pragma_Check_Name =>
6618 Check_No_Identifiers;
6620 Check_Valid_Configuration_Pragma;
6621 Check_Arg_Count (1);
6622 Check_Arg_Is_Identifier (Arg1);
6625 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6628 for J in Check_Names.First .. Check_Names.Last loop
6629 if Check_Names.Table (J) = Nam then
6634 Check_Names.Append (Nam);
6641 -- pragma Check_Policy (
6642 -- [Name =>] IDENTIFIER,
6643 -- [Policy =>] POLICY_IDENTIFIER);
6645 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6647 -- Note: this is a configuration pragma, but it is allowed to appear
6650 when Pragma_Check_Policy =>
6652 Check_Arg_Count (2);
6653 Check_Optional_Identifier (Arg1, Name_Name);
6654 Check_Optional_Identifier (Arg2, Name_Policy);
6656 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6658 -- A Check_Policy pragma can appear either as a configuration
6659 -- pragma, or in a declarative part or a package spec (see RM
6660 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6661 -- followed for Check_Policy).
6663 if not Is_Configuration_Pragma then
6664 Check_Is_In_Decl_Part_Or_Package_Spec;
6667 Set_Next_Pragma (N, Opt.Check_Policy_List);
6668 Opt.Check_Policy_List := N;
6670 ---------------------
6671 -- CIL_Constructor --
6672 ---------------------
6674 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6676 -- Processing for this pragma is shared with Java_Constructor
6682 -- pragma Comment (static_string_EXPRESSION)
6684 -- Processing for pragma Comment shares the circuitry for pragma
6685 -- Ident. The only differences are that Ident enforces a limit of 31
6686 -- characters on its argument, and also enforces limitations on
6687 -- placement for DEC compatibility. Pragma Comment shares neither of
6688 -- these restrictions.
6694 -- pragma Common_Object (
6695 -- [Internal =>] LOCAL_NAME
6696 -- [, [External =>] EXTERNAL_SYMBOL]
6697 -- [, [Size =>] EXTERNAL_SYMBOL]);
6699 -- Processing for this pragma is shared with Psect_Object
6701 ------------------------
6702 -- Compile_Time_Error --
6703 ------------------------
6705 -- pragma Compile_Time_Error
6706 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6708 when Pragma_Compile_Time_Error =>
6710 Process_Compile_Time_Warning_Or_Error;
6712 --------------------------
6713 -- Compile_Time_Warning --
6714 --------------------------
6716 -- pragma Compile_Time_Warning
6717 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6719 when Pragma_Compile_Time_Warning =>
6721 Process_Compile_Time_Warning_Or_Error;
6727 when Pragma_Compiler_Unit =>
6729 Check_Arg_Count (0);
6730 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6732 -----------------------------
6733 -- Complete_Representation --
6734 -----------------------------
6736 -- pragma Complete_Representation;
6738 when Pragma_Complete_Representation =>
6740 Check_Arg_Count (0);
6742 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6744 ("pragma & must appear within record representation clause");
6747 ----------------------------
6748 -- Complex_Representation --
6749 ----------------------------
6751 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6753 when Pragma_Complex_Representation => Complex_Representation : declare
6760 Check_Arg_Count (1);
6761 Check_Optional_Identifier (Arg1, Name_Entity);
6762 Check_Arg_Is_Local_Name (Arg1);
6763 E_Id := Get_Pragma_Arg (Arg1);
6765 if Etype (E_Id) = Any_Type then
6771 if not Is_Record_Type (E) then
6773 ("argument for pragma% must be record type", Arg1);
6776 Ent := First_Entity (E);
6779 or else No (Next_Entity (Ent))
6780 or else Present (Next_Entity (Next_Entity (Ent)))
6781 or else not Is_Floating_Point_Type (Etype (Ent))
6782 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6785 ("record for pragma% must have two fields of the same "
6786 & "floating-point type", Arg1);
6789 Set_Has_Complex_Representation (Base_Type (E));
6791 -- We need to treat the type has having a non-standard
6792 -- representation, for back-end purposes, even though in
6793 -- general a complex will have the default representation
6794 -- of a record with two real components.
6796 Set_Has_Non_Standard_Rep (Base_Type (E));
6798 end Complex_Representation;
6800 -------------------------
6801 -- Component_Alignment --
6802 -------------------------
6804 -- pragma Component_Alignment (
6805 -- [Form =>] ALIGNMENT_CHOICE
6806 -- [, [Name =>] type_LOCAL_NAME]);
6808 -- ALIGNMENT_CHOICE ::=
6810 -- | Component_Size_4
6814 when Pragma_Component_Alignment => Component_AlignmentP : declare
6815 Args : Args_List (1 .. 2);
6816 Names : constant Name_List (1 .. 2) := (
6820 Form : Node_Id renames Args (1);
6821 Name : Node_Id renames Args (2);
6823 Atype : Component_Alignment_Kind;
6828 Gather_Associations (Names, Args);
6831 Error_Pragma ("missing Form argument for pragma%");
6834 Check_Arg_Is_Identifier (Form);
6836 -- Get proper alignment, note that Default = Component_Size on all
6837 -- machines we have so far, and we want to set this value rather
6838 -- than the default value to indicate that it has been explicitly
6839 -- set (and thus will not get overridden by the default component
6840 -- alignment for the current scope)
6842 if Chars (Form) = Name_Component_Size then
6843 Atype := Calign_Component_Size;
6845 elsif Chars (Form) = Name_Component_Size_4 then
6846 Atype := Calign_Component_Size_4;
6848 elsif Chars (Form) = Name_Default then
6849 Atype := Calign_Component_Size;
6851 elsif Chars (Form) = Name_Storage_Unit then
6852 Atype := Calign_Storage_Unit;
6856 ("invalid Form parameter for pragma%", Form);
6859 -- Case with no name, supplied, affects scope table entry
6863 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6865 -- Case of name supplied
6868 Check_Arg_Is_Local_Name (Name);
6870 Typ := Entity (Name);
6873 or else Rep_Item_Too_Early (Typ, N)
6877 Typ := Underlying_Type (Typ);
6880 if not Is_Record_Type (Typ)
6881 and then not Is_Array_Type (Typ)
6884 ("Name parameter of pragma% must identify record or " &
6885 "array type", Name);
6888 -- An explicit Component_Alignment pragma overrides an
6889 -- implicit pragma Pack, but not an explicit one.
6891 if not Has_Pragma_Pack (Base_Type (Typ)) then
6892 Set_Is_Packed (Base_Type (Typ), False);
6893 Set_Component_Alignment (Base_Type (Typ), Atype);
6896 end Component_AlignmentP;
6902 -- pragma Controlled (first_subtype_LOCAL_NAME);
6904 when Pragma_Controlled => Controlled : declare
6908 Check_No_Identifiers;
6909 Check_Arg_Count (1);
6910 Check_Arg_Is_Local_Name (Arg1);
6911 Arg := Get_Pragma_Arg (Arg1);
6913 if not Is_Entity_Name (Arg)
6914 or else not Is_Access_Type (Entity (Arg))
6916 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6918 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6926 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6927 -- [Entity =>] LOCAL_NAME);
6929 when Pragma_Convention => Convention : declare
6932 pragma Warnings (Off, C);
6933 pragma Warnings (Off, E);
6935 Check_Arg_Order ((Name_Convention, Name_Entity));
6936 Check_Ada_83_Warning;
6937 Check_Arg_Count (2);
6938 Process_Convention (C, E);
6941 ---------------------------
6942 -- Convention_Identifier --
6943 ---------------------------
6945 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6946 -- [Convention =>] convention_IDENTIFIER);
6948 when Pragma_Convention_Identifier => Convention_Identifier : declare
6954 Check_Arg_Order ((Name_Name, Name_Convention));
6955 Check_Arg_Count (2);
6956 Check_Optional_Identifier (Arg1, Name_Name);
6957 Check_Optional_Identifier (Arg2, Name_Convention);
6958 Check_Arg_Is_Identifier (Arg1);
6959 Check_Arg_Is_Identifier (Arg2);
6960 Idnam := Chars (Get_Pragma_Arg (Arg1));
6961 Cname := Chars (Get_Pragma_Arg (Arg2));
6963 if Is_Convention_Name (Cname) then
6964 Record_Convention_Identifier
6965 (Idnam, Get_Convention_Id (Cname));
6968 ("second arg for % pragma must be convention", Arg2);
6970 end Convention_Identifier;
6976 -- pragma CPP_Class ([Entity =>] local_NAME)
6978 when Pragma_CPP_Class => CPP_Class : declare
6983 if Warn_On_Obsolescent_Feature then
6985 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6986 " by pragma import?", N);
6990 Check_Arg_Count (1);
6991 Check_Optional_Identifier (Arg1, Name_Entity);
6992 Check_Arg_Is_Local_Name (Arg1);
6994 Arg := Get_Pragma_Arg (Arg1);
6997 if Etype (Arg) = Any_Type then
7001 if not Is_Entity_Name (Arg)
7002 or else not Is_Type (Entity (Arg))
7004 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7007 Typ := Entity (Arg);
7009 if not Is_Tagged_Type (Typ) then
7010 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7013 -- Types treated as CPP classes are treated as limited, but we
7014 -- don't require them to be declared this way. A warning is issued
7015 -- to encourage the user to declare them as limited. This is not
7016 -- an error, for compatibility reasons, because these types have
7017 -- been supported this way for some time.
7019 if not Is_Limited_Type (Typ) then
7021 ("imported 'C'P'P type should be " &
7022 "explicitly declared limited?",
7023 Get_Pragma_Arg (Arg1));
7025 ("\type will be considered limited",
7026 Get_Pragma_Arg (Arg1));
7029 Set_Is_CPP_Class (Typ);
7030 Set_Is_Limited_Record (Typ);
7031 Set_Convention (Typ, Convention_CPP);
7033 -- Imported CPP types must not have discriminants (because C++
7034 -- classes do not have discriminants).
7036 if Has_Discriminants (Typ) then
7038 ("imported 'C'P'P type cannot have discriminants",
7039 First (Discriminant_Specifications
7040 (Declaration_Node (Typ))));
7043 -- Components of imported CPP types must not have default
7044 -- expressions because the constructor (if any) is in the
7047 if Is_Incomplete_Or_Private_Type (Typ)
7048 and then No (Underlying_Type (Typ))
7050 -- It should be an error to apply pragma CPP to a private
7051 -- type if the underlying type is not visible (as it is
7052 -- for any representation item). For now, for backward
7053 -- compatibility we do nothing but we cannot check components
7054 -- because they are not available at this stage. All this code
7055 -- will be removed when we cleanup this obsolete GNAT pragma???
7061 Tdef : constant Node_Id :=
7062 Type_Definition (Declaration_Node (Typ));
7067 if Nkind (Tdef) = N_Record_Definition then
7068 Clist := Component_List (Tdef);
7070 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7071 Clist := Component_List (Record_Extension_Part (Tdef));
7074 if Present (Clist) then
7075 Comp := First (Component_Items (Clist));
7076 while Present (Comp) loop
7077 if Present (Expression (Comp)) then
7079 ("component of imported 'C'P'P type cannot have" &
7080 " default expression", Expression (Comp));
7090 ---------------------
7091 -- CPP_Constructor --
7092 ---------------------
7094 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7095 -- [, [External_Name =>] static_string_EXPRESSION ]
7096 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7098 when Pragma_CPP_Constructor => CPP_Constructor : declare
7102 Tag_Typ : Entity_Id;
7106 Check_At_Least_N_Arguments (1);
7107 Check_At_Most_N_Arguments (3);
7108 Check_Optional_Identifier (Arg1, Name_Entity);
7109 Check_Arg_Is_Local_Name (Arg1);
7111 Id := Get_Pragma_Arg (Arg1);
7112 Find_Program_Unit_Name (Id);
7114 -- If we did not find the name, we are done
7116 if Etype (Id) = Any_Type then
7120 Def_Id := Entity (Id);
7122 -- Check if already defined as constructor
7124 if Is_Constructor (Def_Id) then
7126 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7130 if Ekind (Def_Id) = E_Function
7131 and then (Is_CPP_Class (Etype (Def_Id))
7132 or else (Is_Class_Wide_Type (Etype (Def_Id))
7134 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7136 if Arg_Count >= 2 then
7137 Set_Imported (Def_Id);
7138 Set_Is_Public (Def_Id);
7139 Process_Interface_Name (Def_Id, Arg2, Arg3);
7142 Set_Has_Completion (Def_Id);
7143 Set_Is_Constructor (Def_Id);
7145 -- Imported C++ constructors are not dispatching primitives
7146 -- because in C++ they don't have a dispatch table slot.
7147 -- However, in Ada the constructor has the profile of a
7148 -- function that returns a tagged type and therefore it has
7149 -- been treated as a primitive operation during semantic
7150 -- analysis. We now remove it from the list of primitive
7151 -- operations of the type.
7153 if Is_Tagged_Type (Etype (Def_Id))
7154 and then not Is_Class_Wide_Type (Etype (Def_Id))
7156 pragma Assert (Is_Dispatching_Operation (Def_Id));
7157 Tag_Typ := Etype (Def_Id);
7159 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7160 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7164 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7165 Set_Is_Dispatching_Operation (Def_Id, False);
7168 -- For backward compatibility, if the constructor returns a
7169 -- class wide type, and we internally change the return type to
7170 -- the corresponding root type.
7172 if Is_Class_Wide_Type (Etype (Def_Id)) then
7173 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7177 ("pragma% requires function returning a 'C'P'P_Class type",
7180 end CPP_Constructor;
7186 when Pragma_CPP_Virtual => CPP_Virtual : declare
7190 if Warn_On_Obsolescent_Feature then
7192 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7201 when Pragma_CPP_Vtable => CPP_Vtable : declare
7205 if Warn_On_Obsolescent_Feature then
7207 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7216 -- pragma CPU (EXPRESSION);
7218 when Pragma_CPU => CPU : declare
7219 P : constant Node_Id := Parent (N);
7224 Check_No_Identifiers;
7225 Check_Arg_Count (1);
7229 if Nkind (P) = N_Subprogram_Body then
7230 Check_In_Main_Program;
7232 Arg := Get_Pragma_Arg (Arg1);
7233 Analyze_And_Resolve (Arg, Any_Integer);
7237 if not Is_Static_Expression (Arg) then
7238 Flag_Non_Static_Expr
7239 ("main subprogram affinity is not static!", Arg);
7242 -- If constraint error, then we already signalled an error
7244 elsif Raises_Constraint_Error (Arg) then
7247 -- Otherwise check in range
7251 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7252 -- This is the entity System.Multiprocessors.CPU_Range;
7254 Val : constant Uint := Expr_Value (Arg);
7257 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7259 Val > Expr_Value (Type_High_Bound (CPU_Id))
7262 ("main subprogram CPU is out of range", Arg1);
7268 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7272 elsif Nkind (P) = N_Task_Definition then
7273 Arg := Get_Pragma_Arg (Arg1);
7275 -- The expression must be analyzed in the special manner
7276 -- described in "Handling of Default and Per-Object
7277 -- Expressions" in sem.ads.
7279 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7281 -- Anything else is incorrect
7287 if Has_Pragma_CPU (P) then
7288 Error_Pragma ("duplicate pragma% not allowed");
7290 Set_Has_Pragma_CPU (P, True);
7292 if Nkind (P) = N_Task_Definition then
7293 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7302 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7304 when Pragma_Debug => Debug : declare
7312 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7315 if Arg_Count = 2 then
7318 Left_Opnd => Relocate_Node (Cond),
7319 Right_Opnd => Get_Pragma_Arg (Arg1));
7322 -- Rewrite into a conditional with an appropriate condition. We
7323 -- wrap the procedure call in a block so that overhead from e.g.
7324 -- use of the secondary stack does not generate execution overhead
7325 -- for suppressed conditions.
7327 Rewrite (N, Make_Implicit_If_Statement (N,
7329 Then_Statements => New_List (
7330 Make_Block_Statement (Loc,
7331 Handled_Statement_Sequence =>
7332 Make_Handled_Sequence_Of_Statements (Loc,
7333 Statements => New_List (
7334 Relocate_Node (Debug_Statement (N))))))));
7342 -- pragma Debug_Policy (Check | Ignore)
7344 when Pragma_Debug_Policy =>
7346 Check_Arg_Count (1);
7347 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7348 Debug_Pragmas_Enabled :=
7349 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7351 -----------------------------
7352 -- Default_Component_Value --
7353 -----------------------------
7355 when Pragma_Default_Component_Value => declare
7361 Check_Arg_Count (2);
7362 Check_Arg_Is_Local_Name (Arg1);
7364 Arg := Get_Pragma_Arg (Arg1);
7367 if Etype (Arg) = Any_Type then
7371 if not Is_Entity_Name (Arg)
7372 or else not Is_Array_Type (Entity (Arg))
7374 Error_Pragma_Arg ("pragma% requires an array type", Arg1);
7377 Check_First_Subtype (Arg1);
7380 Check_Duplicate_Pragma (E);
7382 -- Check for rep item too early or too late, but skip this if
7383 -- the pragma comes from the corresponding aspect, since we do
7384 -- not need the checks, and more importantly, the pragma is on
7385 -- the rep item chain alreay, and must not be put there twice!
7387 if not From_Aspect_Specification (N) then
7388 if Rep_Item_Too_Early (E, N)
7390 Rep_Item_Too_Late (E, N)
7396 -- Analyze the default value
7398 Arg := Get_Pragma_Arg (Arg2);
7399 Analyze_And_Resolve (Arg, Component_Type (E));
7401 if not Is_OK_Static_Expression (Arg) then
7402 Flag_Non_Static_Expr
7403 ("non-static expression not allowed for " &
7404 "Default_Component_Value",
7409 -- Set the flag on the root type and then check for Rep_Item too
7410 -- early or too late, the latter call chains the pragma onto the
7413 Set_Has_Default_Component_Value (Base_Type (E));
7420 when Pragma_Default_Value => declare
7428 Check_Arg_Count (2);
7429 Check_Arg_Is_Local_Name (Arg1);
7431 Arg := Get_Pragma_Arg (Arg1);
7434 if Etype (Arg) = Any_Type then
7438 if not Is_Entity_Name (Arg)
7439 or else not Is_Scalar_Type (Entity (Arg))
7441 Error_Pragma_Arg ("pragma% requires a scalar type", Arg1);
7444 Check_First_Subtype (Arg1);
7447 Check_Duplicate_Pragma (E);
7449 -- Check for rep item too early or too late, but skip this if
7450 -- the pragma comes from the corresponding aspect, since we do
7451 -- not need the checks, and more importantly, the pragma is on
7452 -- the rep item chain alreay, and must not be put there twice!
7454 if not From_Aspect_Specification (N) then
7455 if Rep_Item_Too_Early (E, N)
7457 Rep_Item_Too_Late (E, N)
7463 -- Analyze the default value. Note that we must do that after
7464 -- checking for Rep_Item_Too_Late since this resolution will
7465 -- freeze the type involved.
7467 Arg := Get_Pragma_Arg (Arg2);
7468 Analyze_And_Resolve (Arg, E);
7470 if not Is_OK_Static_Expression (Arg) then
7471 Flag_Non_Static_Expr
7472 ("non-static expression not allowed for Default_Value",
7477 -- Set the flag on the root type and then check for Rep_Item too
7478 -- early or too late, the latter call chains the pragma onto the
7481 Set_Has_Default_Value (Base_Type (E));
7484 ---------------------
7485 -- Detect_Blocking --
7486 ---------------------
7488 -- pragma Detect_Blocking;
7490 when Pragma_Detect_Blocking =>
7492 Check_Arg_Count (0);
7493 Check_Valid_Configuration_Pragma;
7494 Detect_Blocking := True;
7496 --------------------------
7497 -- Default_Storage_Pool --
7498 --------------------------
7500 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7502 when Pragma_Default_Storage_Pool =>
7504 Check_Arg_Count (1);
7506 -- Default_Storage_Pool can appear as a configuration pragma, or
7507 -- in a declarative part or a package spec.
7509 if not Is_Configuration_Pragma then
7510 Check_Is_In_Decl_Part_Or_Package_Spec;
7513 -- Case of Default_Storage_Pool (null);
7515 if Nkind (Expression (Arg1)) = N_Null then
7516 Analyze (Expression (Arg1));
7518 -- This is an odd case, this is not really an expression, so
7519 -- we don't have a type for it. So just set the type to Empty.
7521 Set_Etype (Expression (Arg1), Empty);
7523 -- Case of Default_Storage_Pool (storage_pool_NAME);
7526 -- If it's a configuration pragma, then the only allowed
7527 -- argument is "null".
7529 if Is_Configuration_Pragma then
7530 Error_Pragma_Arg ("NULL expected", Arg1);
7533 -- The expected type for a non-"null" argument is
7534 -- Root_Storage_Pool'Class.
7537 (Get_Pragma_Arg (Arg1),
7538 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7541 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7542 -- for an access type will use this information to set the
7543 -- appropriate attributes of the access type.
7545 Default_Pool := Expression (Arg1);
7551 when Pragma_Dimension =>
7553 Check_Arg_Count (4);
7554 Check_No_Identifiers;
7555 Check_Arg_Is_Local_Name (Arg1);
7557 if not Is_Type (Arg1) then
7558 Error_Pragma ("first argument for pragma% must be subtype");
7561 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7562 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7563 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7569 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7571 when Pragma_Discard_Names => Discard_Names : declare
7576 Check_Ada_83_Warning;
7578 -- Deal with configuration pragma case
7580 if Arg_Count = 0 and then Is_Configuration_Pragma then
7581 Global_Discard_Names := True;
7584 -- Otherwise, check correct appropriate context
7587 Check_Is_In_Decl_Part_Or_Package_Spec;
7589 if Arg_Count = 0 then
7591 -- If there is no parameter, then from now on this pragma
7592 -- applies to any enumeration, exception or tagged type
7593 -- defined in the current declarative part, and recursively
7594 -- to any nested scope.
7596 Set_Discard_Names (Current_Scope);
7600 Check_Arg_Count (1);
7601 Check_Optional_Identifier (Arg1, Name_On);
7602 Check_Arg_Is_Local_Name (Arg1);
7604 E_Id := Get_Pragma_Arg (Arg1);
7606 if Etype (E_Id) = Any_Type then
7612 if (Is_First_Subtype (E)
7614 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7615 or else Ekind (E) = E_Exception
7617 Set_Discard_Names (E);
7620 ("inappropriate entity for pragma%", Arg1);
7631 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7633 when Pragma_Elaborate => Elaborate : declare
7638 -- Pragma must be in context items list of a compilation unit
7640 if not Is_In_Context_Clause then
7644 -- Must be at least one argument
7646 if Arg_Count = 0 then
7647 Error_Pragma ("pragma% requires at least one argument");
7650 -- In Ada 83 mode, there can be no items following it in the
7651 -- context list except other pragmas and implicit with clauses
7652 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7653 -- placement rule does not apply.
7655 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7657 while Present (Citem) loop
7658 if Nkind (Citem) = N_Pragma
7659 or else (Nkind (Citem) = N_With_Clause
7660 and then Implicit_With (Citem))
7665 ("(Ada 83) pragma% must be at end of context clause");
7672 -- Finally, the arguments must all be units mentioned in a with
7673 -- clause in the same context clause. Note we already checked (in
7674 -- Par.Prag) that the arguments are all identifiers or selected
7678 Outer : while Present (Arg) loop
7679 Citem := First (List_Containing (N));
7680 Inner : while Citem /= N loop
7681 if Nkind (Citem) = N_With_Clause
7682 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7684 Set_Elaborate_Present (Citem, True);
7685 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7687 -- With the pragma present, elaboration calls on
7688 -- subprograms from the named unit need no further
7689 -- checks, as long as the pragma appears in the current
7690 -- compilation unit. If the pragma appears in some unit
7691 -- in the context, there might still be a need for an
7692 -- Elaborate_All_Desirable from the current compilation
7693 -- to the named unit, so we keep the check enabled.
7695 if In_Extended_Main_Source_Unit (N) then
7696 Set_Suppress_Elaboration_Warnings
7697 (Entity (Name (Citem)));
7708 ("argument of pragma% is not with'ed unit", Arg);
7714 -- Give a warning if operating in static mode with -gnatwl
7715 -- (elaboration warnings enabled) switch set.
7717 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7719 ("?use of pragma Elaborate may not be safe", N);
7721 ("?use pragma Elaborate_All instead if possible", N);
7729 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7731 when Pragma_Elaborate_All => Elaborate_All : declare
7736 Check_Ada_83_Warning;
7738 -- Pragma must be in context items list of a compilation unit
7740 if not Is_In_Context_Clause then
7744 -- Must be at least one argument
7746 if Arg_Count = 0 then
7747 Error_Pragma ("pragma% requires at least one argument");
7750 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7751 -- have to appear at the end of the context clause, but may
7752 -- appear mixed in with other items, even in Ada 83 mode.
7754 -- Final check: the arguments must all be units mentioned in
7755 -- a with clause in the same context clause. Note that we
7756 -- already checked (in Par.Prag) that all the arguments are
7757 -- either identifiers or selected components.
7760 Outr : while Present (Arg) loop
7761 Citem := First (List_Containing (N));
7762 Innr : while Citem /= N loop
7763 if Nkind (Citem) = N_With_Clause
7764 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7766 Set_Elaborate_All_Present (Citem, True);
7767 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7769 -- Suppress warnings and elaboration checks on the named
7770 -- unit if the pragma is in the current compilation, as
7771 -- for pragma Elaborate.
7773 if In_Extended_Main_Source_Unit (N) then
7774 Set_Suppress_Elaboration_Warnings
7775 (Entity (Name (Citem)));
7784 Set_Error_Posted (N);
7786 ("argument of pragma% is not with'ed unit", Arg);
7793 --------------------
7794 -- Elaborate_Body --
7795 --------------------
7797 -- pragma Elaborate_Body [( library_unit_NAME )];
7799 when Pragma_Elaborate_Body => Elaborate_Body : declare
7800 Cunit_Node : Node_Id;
7801 Cunit_Ent : Entity_Id;
7804 Check_Ada_83_Warning;
7805 Check_Valid_Library_Unit_Pragma;
7807 if Nkind (N) = N_Null_Statement then
7811 Cunit_Node := Cunit (Current_Sem_Unit);
7812 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7814 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7817 Error_Pragma ("pragma% must refer to a spec, not a body");
7819 Set_Body_Required (Cunit_Node, True);
7820 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7822 -- If we are in dynamic elaboration mode, then we suppress
7823 -- elaboration warnings for the unit, since it is definitely
7824 -- fine NOT to do dynamic checks at the first level (and such
7825 -- checks will be suppressed because no elaboration boolean
7826 -- is created for Elaborate_Body packages).
7828 -- But in the static model of elaboration, Elaborate_Body is
7829 -- definitely NOT good enough to ensure elaboration safety on
7830 -- its own, since the body may WITH other units that are not
7831 -- safe from an elaboration point of view, so a client must
7832 -- still do an Elaborate_All on such units.
7834 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7835 -- Elaborate_Body always suppressed elab warnings.
7837 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7838 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7843 ------------------------
7844 -- Elaboration_Checks --
7845 ------------------------
7847 -- pragma Elaboration_Checks (Static | Dynamic);
7849 when Pragma_Elaboration_Checks =>
7851 Check_Arg_Count (1);
7852 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7853 Dynamic_Elaboration_Checks :=
7854 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7860 -- pragma Eliminate (
7861 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7862 -- [,[Entity =>] IDENTIFIER |
7863 -- SELECTED_COMPONENT |
7865 -- [, OVERLOADING_RESOLUTION]);
7867 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7870 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7873 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7875 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7876 -- Result_Type => result_SUBTYPE_NAME]
7878 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7879 -- SUBTYPE_NAME ::= STRING_LITERAL
7881 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7882 -- SOURCE_TRACE ::= STRING_LITERAL
7884 when Pragma_Eliminate => Eliminate : declare
7885 Args : Args_List (1 .. 5);
7886 Names : constant Name_List (1 .. 5) := (
7889 Name_Parameter_Types,
7891 Name_Source_Location);
7893 Unit_Name : Node_Id renames Args (1);
7894 Entity : Node_Id renames Args (2);
7895 Parameter_Types : Node_Id renames Args (3);
7896 Result_Type : Node_Id renames Args (4);
7897 Source_Location : Node_Id renames Args (5);
7901 Check_Valid_Configuration_Pragma;
7902 Gather_Associations (Names, Args);
7904 if No (Unit_Name) then
7905 Error_Pragma ("missing Unit_Name argument for pragma%");
7909 and then (Present (Parameter_Types)
7911 Present (Result_Type)
7913 Present (Source_Location))
7915 Error_Pragma ("missing Entity argument for pragma%");
7918 if (Present (Parameter_Types)
7920 Present (Result_Type))
7922 Present (Source_Location)
7925 ("parameter profile and source location cannot " &
7926 "be used together in pragma%");
7929 Process_Eliminate_Pragma
7943 -- [ Convention =>] convention_IDENTIFIER,
7944 -- [ Entity =>] local_NAME
7945 -- [, [External_Name =>] static_string_EXPRESSION ]
7946 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7948 when Pragma_Export => Export : declare
7952 pragma Warnings (Off, C);
7955 Check_Ada_83_Warning;
7961 Check_At_Least_N_Arguments (2);
7962 Check_At_Most_N_Arguments (4);
7963 Process_Convention (C, Def_Id);
7965 if Ekind (Def_Id) /= E_Constant then
7966 Note_Possible_Modification
7967 (Get_Pragma_Arg (Arg2), Sure => False);
7970 Process_Interface_Name (Def_Id, Arg3, Arg4);
7971 Set_Exported (Def_Id, Arg2);
7973 -- If the entity is a deferred constant, propagate the information
7974 -- to the full view, because gigi elaborates the full view only.
7976 if Ekind (Def_Id) = E_Constant
7977 and then Present (Full_View (Def_Id))
7980 Id2 : constant Entity_Id := Full_View (Def_Id);
7982 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7983 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7984 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7989 ----------------------
7990 -- Export_Exception --
7991 ----------------------
7993 -- pragma Export_Exception (
7994 -- [Internal =>] LOCAL_NAME
7995 -- [, [External =>] EXTERNAL_SYMBOL]
7996 -- [, [Form =>] Ada | VMS]
7997 -- [, [Code =>] static_integer_EXPRESSION]);
7999 when Pragma_Export_Exception => Export_Exception : declare
8000 Args : Args_List (1 .. 4);
8001 Names : constant Name_List (1 .. 4) := (
8007 Internal : Node_Id renames Args (1);
8008 External : Node_Id renames Args (2);
8009 Form : Node_Id renames Args (3);
8010 Code : Node_Id renames Args (4);
8015 if Inside_A_Generic then
8016 Error_Pragma ("pragma% cannot be used for generic entities");
8019 Gather_Associations (Names, Args);
8020 Process_Extended_Import_Export_Exception_Pragma (
8021 Arg_Internal => Internal,
8022 Arg_External => External,
8026 if not Is_VMS_Exception (Entity (Internal)) then
8027 Set_Exported (Entity (Internal), Internal);
8029 end Export_Exception;
8031 ---------------------
8032 -- Export_Function --
8033 ---------------------
8035 -- pragma Export_Function (
8036 -- [Internal =>] LOCAL_NAME
8037 -- [, [External =>] EXTERNAL_SYMBOL]
8038 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8039 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8040 -- [, [Mechanism =>] MECHANISM]
8041 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8043 -- EXTERNAL_SYMBOL ::=
8045 -- | static_string_EXPRESSION
8047 -- PARAMETER_TYPES ::=
8049 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8051 -- TYPE_DESIGNATOR ::=
8053 -- | subtype_Name ' Access
8057 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8059 -- MECHANISM_ASSOCIATION ::=
8060 -- [formal_parameter_NAME =>] MECHANISM_NAME
8062 -- MECHANISM_NAME ::=
8065 -- | Descriptor [([Class =>] CLASS_NAME)]
8067 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8069 when Pragma_Export_Function => Export_Function : declare
8070 Args : Args_List (1 .. 6);
8071 Names : constant Name_List (1 .. 6) := (
8074 Name_Parameter_Types,
8077 Name_Result_Mechanism);
8079 Internal : Node_Id renames Args (1);
8080 External : Node_Id renames Args (2);
8081 Parameter_Types : Node_Id renames Args (3);
8082 Result_Type : Node_Id renames Args (4);
8083 Mechanism : Node_Id renames Args (5);
8084 Result_Mechanism : Node_Id renames Args (6);
8088 Gather_Associations (Names, Args);
8089 Process_Extended_Import_Export_Subprogram_Pragma (
8090 Arg_Internal => Internal,
8091 Arg_External => External,
8092 Arg_Parameter_Types => Parameter_Types,
8093 Arg_Result_Type => Result_Type,
8094 Arg_Mechanism => Mechanism,
8095 Arg_Result_Mechanism => Result_Mechanism);
8096 end Export_Function;
8102 -- pragma Export_Object (
8103 -- [Internal =>] LOCAL_NAME
8104 -- [, [External =>] EXTERNAL_SYMBOL]
8105 -- [, [Size =>] EXTERNAL_SYMBOL]);
8107 -- EXTERNAL_SYMBOL ::=
8109 -- | static_string_EXPRESSION
8111 -- PARAMETER_TYPES ::=
8113 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8115 -- TYPE_DESIGNATOR ::=
8117 -- | subtype_Name ' Access
8121 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8123 -- MECHANISM_ASSOCIATION ::=
8124 -- [formal_parameter_NAME =>] MECHANISM_NAME
8126 -- MECHANISM_NAME ::=
8129 -- | Descriptor [([Class =>] CLASS_NAME)]
8131 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8133 when Pragma_Export_Object => Export_Object : declare
8134 Args : Args_List (1 .. 3);
8135 Names : constant Name_List (1 .. 3) := (
8140 Internal : Node_Id renames Args (1);
8141 External : Node_Id renames Args (2);
8142 Size : Node_Id renames Args (3);
8146 Gather_Associations (Names, Args);
8147 Process_Extended_Import_Export_Object_Pragma (
8148 Arg_Internal => Internal,
8149 Arg_External => External,
8153 ----------------------
8154 -- Export_Procedure --
8155 ----------------------
8157 -- pragma Export_Procedure (
8158 -- [Internal =>] LOCAL_NAME
8159 -- [, [External =>] EXTERNAL_SYMBOL]
8160 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8161 -- [, [Mechanism =>] MECHANISM]);
8163 -- EXTERNAL_SYMBOL ::=
8165 -- | static_string_EXPRESSION
8167 -- PARAMETER_TYPES ::=
8169 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8171 -- TYPE_DESIGNATOR ::=
8173 -- | subtype_Name ' Access
8177 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8179 -- MECHANISM_ASSOCIATION ::=
8180 -- [formal_parameter_NAME =>] MECHANISM_NAME
8182 -- MECHANISM_NAME ::=
8185 -- | Descriptor [([Class =>] CLASS_NAME)]
8187 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8189 when Pragma_Export_Procedure => Export_Procedure : declare
8190 Args : Args_List (1 .. 4);
8191 Names : constant Name_List (1 .. 4) := (
8194 Name_Parameter_Types,
8197 Internal : Node_Id renames Args (1);
8198 External : Node_Id renames Args (2);
8199 Parameter_Types : Node_Id renames Args (3);
8200 Mechanism : Node_Id renames Args (4);
8204 Gather_Associations (Names, Args);
8205 Process_Extended_Import_Export_Subprogram_Pragma (
8206 Arg_Internal => Internal,
8207 Arg_External => External,
8208 Arg_Parameter_Types => Parameter_Types,
8209 Arg_Mechanism => Mechanism);
8210 end Export_Procedure;
8216 -- pragma Export_Value (
8217 -- [Value =>] static_integer_EXPRESSION,
8218 -- [Link_Name =>] static_string_EXPRESSION);
8220 when Pragma_Export_Value =>
8222 Check_Arg_Order ((Name_Value, Name_Link_Name));
8223 Check_Arg_Count (2);
8225 Check_Optional_Identifier (Arg1, Name_Value);
8226 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8228 Check_Optional_Identifier (Arg2, Name_Link_Name);
8229 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8231 -----------------------------
8232 -- Export_Valued_Procedure --
8233 -----------------------------
8235 -- pragma Export_Valued_Procedure (
8236 -- [Internal =>] LOCAL_NAME
8237 -- [, [External =>] EXTERNAL_SYMBOL,]
8238 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8239 -- [, [Mechanism =>] MECHANISM]);
8241 -- EXTERNAL_SYMBOL ::=
8243 -- | static_string_EXPRESSION
8245 -- PARAMETER_TYPES ::=
8247 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8249 -- TYPE_DESIGNATOR ::=
8251 -- | subtype_Name ' Access
8255 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8257 -- MECHANISM_ASSOCIATION ::=
8258 -- [formal_parameter_NAME =>] MECHANISM_NAME
8260 -- MECHANISM_NAME ::=
8263 -- | Descriptor [([Class =>] CLASS_NAME)]
8265 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8267 when Pragma_Export_Valued_Procedure =>
8268 Export_Valued_Procedure : declare
8269 Args : Args_List (1 .. 4);
8270 Names : constant Name_List (1 .. 4) := (
8273 Name_Parameter_Types,
8276 Internal : Node_Id renames Args (1);
8277 External : Node_Id renames Args (2);
8278 Parameter_Types : Node_Id renames Args (3);
8279 Mechanism : Node_Id renames Args (4);
8283 Gather_Associations (Names, Args);
8284 Process_Extended_Import_Export_Subprogram_Pragma (
8285 Arg_Internal => Internal,
8286 Arg_External => External,
8287 Arg_Parameter_Types => Parameter_Types,
8288 Arg_Mechanism => Mechanism);
8289 end Export_Valued_Procedure;
8295 -- pragma Extend_System ([Name =>] Identifier);
8297 when Pragma_Extend_System => Extend_System : declare
8300 Check_Valid_Configuration_Pragma;
8301 Check_Arg_Count (1);
8302 Check_Optional_Identifier (Arg1, Name_Name);
8303 Check_Arg_Is_Identifier (Arg1);
8305 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8308 and then Name_Buffer (1 .. 4) = "aux_"
8310 if Present (System_Extend_Pragma_Arg) then
8311 if Chars (Get_Pragma_Arg (Arg1)) =
8312 Chars (Expression (System_Extend_Pragma_Arg))
8316 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8317 Error_Pragma ("pragma% conflicts with that #");
8321 System_Extend_Pragma_Arg := Arg1;
8323 if not GNAT_Mode then
8324 System_Extend_Unit := Arg1;
8328 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8332 ------------------------
8333 -- Extensions_Allowed --
8334 ------------------------
8336 -- pragma Extensions_Allowed (ON | OFF);
8338 when Pragma_Extensions_Allowed =>
8340 Check_Arg_Count (1);
8341 Check_No_Identifiers;
8342 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8344 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8345 Extensions_Allowed := True;
8346 Ada_Version := Ada_Version_Type'Last;
8349 Extensions_Allowed := False;
8350 Ada_Version := Ada_Version_Explicit;
8357 -- pragma External (
8358 -- [ Convention =>] convention_IDENTIFIER,
8359 -- [ Entity =>] local_NAME
8360 -- [, [External_Name =>] static_string_EXPRESSION ]
8361 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8363 when Pragma_External => External : declare
8367 pragma Warnings (Off, C);
8376 Check_At_Least_N_Arguments (2);
8377 Check_At_Most_N_Arguments (4);
8378 Process_Convention (C, Def_Id);
8379 Note_Possible_Modification
8380 (Get_Pragma_Arg (Arg2), Sure => False);
8381 Process_Interface_Name (Def_Id, Arg3, Arg4);
8382 Set_Exported (Def_Id, Arg2);
8385 --------------------------
8386 -- External_Name_Casing --
8387 --------------------------
8389 -- pragma External_Name_Casing (
8390 -- UPPERCASE | LOWERCASE
8391 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8393 when Pragma_External_Name_Casing => External_Name_Casing : declare
8396 Check_No_Identifiers;
8398 if Arg_Count = 2 then
8400 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8402 case Chars (Get_Pragma_Arg (Arg2)) is
8404 Opt.External_Name_Exp_Casing := As_Is;
8406 when Name_Uppercase =>
8407 Opt.External_Name_Exp_Casing := Uppercase;
8409 when Name_Lowercase =>
8410 Opt.External_Name_Exp_Casing := Lowercase;
8417 Check_Arg_Count (1);
8420 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8422 case Chars (Get_Pragma_Arg (Arg1)) is
8423 when Name_Uppercase =>
8424 Opt.External_Name_Imp_Casing := Uppercase;
8426 when Name_Lowercase =>
8427 Opt.External_Name_Imp_Casing := Lowercase;
8432 end External_Name_Casing;
8434 --------------------------
8435 -- Favor_Top_Level --
8436 --------------------------
8438 -- pragma Favor_Top_Level (type_NAME);
8440 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8441 Named_Entity : Entity_Id;
8445 Check_No_Identifiers;
8446 Check_Arg_Count (1);
8447 Check_Arg_Is_Local_Name (Arg1);
8448 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8450 -- If it's an access-to-subprogram type (in particular, not a
8451 -- subtype), set the flag on that type.
8453 if Is_Access_Subprogram_Type (Named_Entity) then
8454 Set_Can_Use_Internal_Rep (Named_Entity, False);
8456 -- Otherwise it's an error (name denotes the wrong sort of entity)
8460 ("access-to-subprogram type expected",
8461 Get_Pragma_Arg (Arg1));
8463 end Favor_Top_Level;
8469 -- pragma Fast_Math;
8471 when Pragma_Fast_Math =>
8473 Check_No_Identifiers;
8474 Check_Valid_Configuration_Pragma;
8477 ---------------------------
8478 -- Finalize_Storage_Only --
8479 ---------------------------
8481 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8483 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8484 Assoc : constant Node_Id := Arg1;
8485 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8490 Check_No_Identifiers;
8491 Check_Arg_Count (1);
8492 Check_Arg_Is_Local_Name (Arg1);
8494 Find_Type (Type_Id);
8495 Typ := Entity (Type_Id);
8498 or else Rep_Item_Too_Early (Typ, N)
8502 Typ := Underlying_Type (Typ);
8505 if not Is_Controlled (Typ) then
8506 Error_Pragma ("pragma% must specify controlled type");
8509 Check_First_Subtype (Arg1);
8511 if Finalize_Storage_Only (Typ) then
8512 Error_Pragma ("duplicate pragma%, only one allowed");
8514 elsif not Rep_Item_Too_Late (Typ, N) then
8515 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8517 end Finalize_Storage;
8519 --------------------------
8520 -- Float_Representation --
8521 --------------------------
8523 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8525 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8527 when Pragma_Float_Representation => Float_Representation : declare
8535 if Arg_Count = 1 then
8536 Check_Valid_Configuration_Pragma;
8538 Check_Arg_Count (2);
8539 Check_Optional_Identifier (Arg2, Name_Entity);
8540 Check_Arg_Is_Local_Name (Arg2);
8543 Check_No_Identifier (Arg1);
8544 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8546 if not OpenVMS_On_Target then
8547 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8549 ("?pragma% ignored (applies only to Open'V'M'S)");
8555 -- One argument case
8557 if Arg_Count = 1 then
8558 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8559 if Opt.Float_Format = 'I' then
8560 Error_Pragma ("'I'E'E'E format previously specified");
8563 Opt.Float_Format := 'V';
8566 if Opt.Float_Format = 'V' then
8567 Error_Pragma ("'V'A'X format previously specified");
8570 Opt.Float_Format := 'I';
8573 Set_Standard_Fpt_Formats;
8575 -- Two argument case
8578 Argx := Get_Pragma_Arg (Arg2);
8580 if not Is_Entity_Name (Argx)
8581 or else not Is_Floating_Point_Type (Entity (Argx))
8584 ("second argument of% pragma must be floating-point type",
8588 Ent := Entity (Argx);
8589 Digs := UI_To_Int (Digits_Value (Ent));
8591 -- Two arguments, VAX_Float case
8593 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8595 when 6 => Set_F_Float (Ent);
8596 when 9 => Set_D_Float (Ent);
8597 when 15 => Set_G_Float (Ent);
8601 ("wrong digits value, must be 6,9 or 15", Arg2);
8604 -- Two arguments, IEEE_Float case
8608 when 6 => Set_IEEE_Short (Ent);
8609 when 15 => Set_IEEE_Long (Ent);
8613 ("wrong digits value, must be 6 or 15", Arg2);
8617 end Float_Representation;
8623 -- pragma Ident (static_string_EXPRESSION)
8625 -- Note: pragma Comment shares this processing. Pragma Comment is
8626 -- identical to Ident, except that the restriction of the argument to
8627 -- 31 characters and the placement restrictions are not enforced for
8630 when Pragma_Ident | Pragma_Comment => Ident : declare
8635 Check_Arg_Count (1);
8636 Check_No_Identifiers;
8637 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8640 -- For pragma Ident, preserve DEC compatibility by requiring the
8641 -- pragma to appear in a declarative part or package spec.
8643 if Prag_Id = Pragma_Ident then
8644 Check_Is_In_Decl_Part_Or_Package_Spec;
8647 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8654 GP := Parent (Parent (N));
8656 if Nkind_In (GP, N_Package_Declaration,
8657 N_Generic_Package_Declaration)
8662 -- If we have a compilation unit, then record the ident value,
8663 -- checking for improper duplication.
8665 if Nkind (GP) = N_Compilation_Unit then
8666 CS := Ident_String (Current_Sem_Unit);
8668 if Present (CS) then
8670 -- For Ident, we do not permit multiple instances
8672 if Prag_Id = Pragma_Ident then
8673 Error_Pragma ("duplicate% pragma not permitted");
8675 -- For Comment, we concatenate the string, unless we want
8676 -- to preserve the tree structure for ASIS.
8678 elsif not ASIS_Mode then
8679 Start_String (Strval (CS));
8680 Store_String_Char (' ');
8681 Store_String_Chars (Strval (Str));
8682 Set_Strval (CS, End_String);
8686 -- In VMS, the effect of IDENT is achieved by passing
8687 -- --identification=name as a --for-linker switch.
8689 if OpenVMS_On_Target then
8692 ("--for-linker=--identification=");
8693 String_To_Name_Buffer (Strval (Str));
8694 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8696 -- Only the last processed IDENT is saved. The main
8697 -- purpose is so an IDENT associated with a main
8698 -- procedure will be used in preference to an IDENT
8699 -- associated with a with'd package.
8701 Replace_Linker_Option_String
8702 (End_String, "--for-linker=--identification=");
8705 Set_Ident_String (Current_Sem_Unit, Str);
8708 -- For subunits, we just ignore the Ident, since in GNAT these
8709 -- are not separate object files, and hence not separate units
8710 -- in the unit table.
8712 elsif Nkind (GP) = N_Subunit then
8715 -- Otherwise we have a misplaced pragma Ident, but we ignore
8716 -- this if we are in an instantiation, since it comes from
8717 -- a generic, and has no relevance to the instantiation.
8719 elsif Prag_Id = Pragma_Ident then
8720 if Instantiation_Location (Loc) = No_Location then
8721 Error_Pragma ("pragma% only allowed at outer level");
8731 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8732 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8734 when Pragma_Implemented => Implemented : declare
8735 Proc_Id : Entity_Id;
8740 Check_Arg_Count (2);
8741 Check_No_Identifiers;
8742 Check_Arg_Is_Identifier (Arg1);
8743 Check_Arg_Is_Local_Name (Arg1);
8745 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8747 -- Extract the name of the local procedure
8749 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8751 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8752 -- primitive procedure of a synchronized tagged type.
8754 if Ekind (Proc_Id) = E_Procedure
8755 and then Is_Primitive (Proc_Id)
8756 and then Present (First_Formal (Proc_Id))
8758 Typ := Etype (First_Formal (Proc_Id));
8760 if Is_Tagged_Type (Typ)
8763 -- Check for a protected, a synchronized or a task interface
8765 ((Is_Interface (Typ)
8766 and then Is_Synchronized_Interface (Typ))
8768 -- Check for a protected type or a task type that implements
8772 (Is_Concurrent_Record_Type (Typ)
8773 and then Present (Interfaces (Typ)))
8775 -- Check for a private record extension with keyword
8779 (Ekind_In (Typ, E_Record_Type_With_Private,
8780 E_Record_Subtype_With_Private)
8781 and then Synchronized_Present (Parent (Typ))))
8786 ("controlling formal must be of synchronized " &
8787 "tagged type", Arg1);
8791 -- Procedures declared inside a protected type must be accepted
8793 elsif Ekind (Proc_Id) = E_Procedure
8794 and then Is_Protected_Type (Scope (Proc_Id))
8798 -- The first argument is not a primitive procedure
8802 ("pragma % must be applied to a primitive procedure", Arg1);
8806 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8807 -- By_Protected_Procedure to the primitive procedure of a task
8810 if Chars (Arg2) = Name_By_Protected_Procedure
8811 and then Is_Interface (Typ)
8812 and then Is_Task_Interface (Typ)
8815 ("implementation kind By_Protected_Procedure cannot be " &
8816 "applied to a task interface primitive", Arg2);
8820 Record_Rep_Item (Proc_Id, N);
8823 ----------------------
8824 -- Implicit_Packing --
8825 ----------------------
8827 -- pragma Implicit_Packing;
8829 when Pragma_Implicit_Packing =>
8831 Check_Arg_Count (0);
8832 Implicit_Packing := True;
8839 -- [Convention =>] convention_IDENTIFIER,
8840 -- [Entity =>] local_NAME
8841 -- [, [External_Name =>] static_string_EXPRESSION ]
8842 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8844 when Pragma_Import =>
8845 Check_Ada_83_Warning;
8851 Check_At_Least_N_Arguments (2);
8852 Check_At_Most_N_Arguments (4);
8853 Process_Import_Or_Interface;
8855 ----------------------
8856 -- Import_Exception --
8857 ----------------------
8859 -- pragma Import_Exception (
8860 -- [Internal =>] LOCAL_NAME
8861 -- [, [External =>] EXTERNAL_SYMBOL]
8862 -- [, [Form =>] Ada | VMS]
8863 -- [, [Code =>] static_integer_EXPRESSION]);
8865 when Pragma_Import_Exception => Import_Exception : declare
8866 Args : Args_List (1 .. 4);
8867 Names : constant Name_List (1 .. 4) := (
8873 Internal : Node_Id renames Args (1);
8874 External : Node_Id renames Args (2);
8875 Form : Node_Id renames Args (3);
8876 Code : Node_Id renames Args (4);
8880 Gather_Associations (Names, Args);
8882 if Present (External) and then Present (Code) then
8884 ("cannot give both External and Code options for pragma%");
8887 Process_Extended_Import_Export_Exception_Pragma (
8888 Arg_Internal => Internal,
8889 Arg_External => External,
8893 if not Is_VMS_Exception (Entity (Internal)) then
8894 Set_Imported (Entity (Internal));
8896 end Import_Exception;
8898 ---------------------
8899 -- Import_Function --
8900 ---------------------
8902 -- pragma Import_Function (
8903 -- [Internal =>] LOCAL_NAME,
8904 -- [, [External =>] EXTERNAL_SYMBOL]
8905 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8906 -- [, [Result_Type =>] SUBTYPE_MARK]
8907 -- [, [Mechanism =>] MECHANISM]
8908 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8909 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8911 -- EXTERNAL_SYMBOL ::=
8913 -- | static_string_EXPRESSION
8915 -- PARAMETER_TYPES ::=
8917 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8919 -- TYPE_DESIGNATOR ::=
8921 -- | subtype_Name ' Access
8925 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8927 -- MECHANISM_ASSOCIATION ::=
8928 -- [formal_parameter_NAME =>] MECHANISM_NAME
8930 -- MECHANISM_NAME ::=
8933 -- | Descriptor [([Class =>] CLASS_NAME)]
8935 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8937 when Pragma_Import_Function => Import_Function : declare
8938 Args : Args_List (1 .. 7);
8939 Names : constant Name_List (1 .. 7) := (
8942 Name_Parameter_Types,
8945 Name_Result_Mechanism,
8946 Name_First_Optional_Parameter);
8948 Internal : Node_Id renames Args (1);
8949 External : Node_Id renames Args (2);
8950 Parameter_Types : Node_Id renames Args (3);
8951 Result_Type : Node_Id renames Args (4);
8952 Mechanism : Node_Id renames Args (5);
8953 Result_Mechanism : Node_Id renames Args (6);
8954 First_Optional_Parameter : Node_Id renames Args (7);
8958 Gather_Associations (Names, Args);
8959 Process_Extended_Import_Export_Subprogram_Pragma (
8960 Arg_Internal => Internal,
8961 Arg_External => External,
8962 Arg_Parameter_Types => Parameter_Types,
8963 Arg_Result_Type => Result_Type,
8964 Arg_Mechanism => Mechanism,
8965 Arg_Result_Mechanism => Result_Mechanism,
8966 Arg_First_Optional_Parameter => First_Optional_Parameter);
8967 end Import_Function;
8973 -- pragma Import_Object (
8974 -- [Internal =>] LOCAL_NAME
8975 -- [, [External =>] EXTERNAL_SYMBOL]
8976 -- [, [Size =>] EXTERNAL_SYMBOL]);
8978 -- EXTERNAL_SYMBOL ::=
8980 -- | static_string_EXPRESSION
8982 when Pragma_Import_Object => Import_Object : declare
8983 Args : Args_List (1 .. 3);
8984 Names : constant Name_List (1 .. 3) := (
8989 Internal : Node_Id renames Args (1);
8990 External : Node_Id renames Args (2);
8991 Size : Node_Id renames Args (3);
8995 Gather_Associations (Names, Args);
8996 Process_Extended_Import_Export_Object_Pragma (
8997 Arg_Internal => Internal,
8998 Arg_External => External,
9002 ----------------------
9003 -- Import_Procedure --
9004 ----------------------
9006 -- pragma Import_Procedure (
9007 -- [Internal =>] LOCAL_NAME
9008 -- [, [External =>] EXTERNAL_SYMBOL]
9009 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9010 -- [, [Mechanism =>] MECHANISM]
9011 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9013 -- EXTERNAL_SYMBOL ::=
9015 -- | static_string_EXPRESSION
9017 -- PARAMETER_TYPES ::=
9019 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9021 -- TYPE_DESIGNATOR ::=
9023 -- | subtype_Name ' Access
9027 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9029 -- MECHANISM_ASSOCIATION ::=
9030 -- [formal_parameter_NAME =>] MECHANISM_NAME
9032 -- MECHANISM_NAME ::=
9035 -- | Descriptor [([Class =>] CLASS_NAME)]
9037 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9039 when Pragma_Import_Procedure => Import_Procedure : declare
9040 Args : Args_List (1 .. 5);
9041 Names : constant Name_List (1 .. 5) := (
9044 Name_Parameter_Types,
9046 Name_First_Optional_Parameter);
9048 Internal : Node_Id renames Args (1);
9049 External : Node_Id renames Args (2);
9050 Parameter_Types : Node_Id renames Args (3);
9051 Mechanism : Node_Id renames Args (4);
9052 First_Optional_Parameter : Node_Id renames Args (5);
9056 Gather_Associations (Names, Args);
9057 Process_Extended_Import_Export_Subprogram_Pragma (
9058 Arg_Internal => Internal,
9059 Arg_External => External,
9060 Arg_Parameter_Types => Parameter_Types,
9061 Arg_Mechanism => Mechanism,
9062 Arg_First_Optional_Parameter => First_Optional_Parameter);
9063 end Import_Procedure;
9065 -----------------------------
9066 -- Import_Valued_Procedure --
9067 -----------------------------
9069 -- pragma Import_Valued_Procedure (
9070 -- [Internal =>] LOCAL_NAME
9071 -- [, [External =>] EXTERNAL_SYMBOL]
9072 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9073 -- [, [Mechanism =>] MECHANISM]
9074 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9076 -- EXTERNAL_SYMBOL ::=
9078 -- | static_string_EXPRESSION
9080 -- PARAMETER_TYPES ::=
9082 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9084 -- TYPE_DESIGNATOR ::=
9086 -- | subtype_Name ' Access
9090 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9092 -- MECHANISM_ASSOCIATION ::=
9093 -- [formal_parameter_NAME =>] MECHANISM_NAME
9095 -- MECHANISM_NAME ::=
9098 -- | Descriptor [([Class =>] CLASS_NAME)]
9100 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9102 when Pragma_Import_Valued_Procedure =>
9103 Import_Valued_Procedure : declare
9104 Args : Args_List (1 .. 5);
9105 Names : constant Name_List (1 .. 5) := (
9108 Name_Parameter_Types,
9110 Name_First_Optional_Parameter);
9112 Internal : Node_Id renames Args (1);
9113 External : Node_Id renames Args (2);
9114 Parameter_Types : Node_Id renames Args (3);
9115 Mechanism : Node_Id renames Args (4);
9116 First_Optional_Parameter : Node_Id renames Args (5);
9120 Gather_Associations (Names, Args);
9121 Process_Extended_Import_Export_Subprogram_Pragma (
9122 Arg_Internal => Internal,
9123 Arg_External => External,
9124 Arg_Parameter_Types => Parameter_Types,
9125 Arg_Mechanism => Mechanism,
9126 Arg_First_Optional_Parameter => First_Optional_Parameter);
9127 end Import_Valued_Procedure;
9133 -- pragma Independent (LOCAL_NAME);
9135 when Pragma_Independent => Independent : declare
9142 Check_Ada_83_Warning;
9144 Check_No_Identifiers;
9145 Check_Arg_Count (1);
9146 Check_Arg_Is_Local_Name (Arg1);
9147 E_Id := Get_Pragma_Arg (Arg1);
9149 if Etype (E_Id) = Any_Type then
9154 D := Declaration_Node (E);
9157 -- Check duplicate before we chain ourselves!
9159 Check_Duplicate_Pragma (E);
9161 -- Check appropriate entity
9164 if Rep_Item_Too_Early (E, N)
9166 Rep_Item_Too_Late (E, N)
9170 Check_First_Subtype (Arg1);
9173 elsif K = N_Object_Declaration
9174 or else (K = N_Component_Declaration
9175 and then Original_Record_Component (E) = E)
9177 if Rep_Item_Too_Late (E, N) then
9183 ("inappropriate entity for pragma%", Arg1);
9186 Independence_Checks.Append ((N, E));
9189 ----------------------------
9190 -- Independent_Components --
9191 ----------------------------
9193 -- pragma Atomic_Components (array_LOCAL_NAME);
9195 -- This processing is shared by Volatile_Components
9197 when Pragma_Independent_Components => Independent_Components : declare
9204 Check_Ada_83_Warning;
9206 Check_No_Identifiers;
9207 Check_Arg_Count (1);
9208 Check_Arg_Is_Local_Name (Arg1);
9209 E_Id := Get_Pragma_Arg (Arg1);
9211 if Etype (E_Id) = Any_Type then
9217 -- Check duplicate before we chain ourselves!
9219 Check_Duplicate_Pragma (E);
9221 -- Check appropriate entity
9223 if Rep_Item_Too_Early (E, N)
9225 Rep_Item_Too_Late (E, N)
9230 D := Declaration_Node (E);
9233 if (K = N_Full_Type_Declaration
9234 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9236 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9237 and then Nkind (D) = N_Object_Declaration
9238 and then Nkind (Object_Definition (D)) =
9239 N_Constrained_Array_Definition)
9241 Independence_Checks.Append ((N, E));
9244 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9246 end Independent_Components;
9248 ------------------------
9249 -- Initialize_Scalars --
9250 ------------------------
9252 -- pragma Initialize_Scalars;
9254 when Pragma_Initialize_Scalars =>
9256 Check_Arg_Count (0);
9257 Check_Valid_Configuration_Pragma;
9258 Check_Restriction (No_Initialize_Scalars, N);
9260 -- Initialize_Scalars creates false positives in CodePeer,
9261 -- so ignore this pragma in this mode.
9263 if not Restriction_Active (No_Initialize_Scalars)
9264 and then not CodePeer_Mode
9266 Init_Or_Norm_Scalars := True;
9267 Initialize_Scalars := True;
9274 -- pragma Inline ( NAME {, NAME} );
9276 when Pragma_Inline =>
9278 -- Pragma is active if inlining option is active
9280 Process_Inline (Inline_Active);
9286 -- pragma Inline_Always ( NAME {, NAME} );
9288 when Pragma_Inline_Always =>
9291 -- Pragma always active unless in CodePeer mode, since this causes
9292 -- walk order issues.
9294 if not CodePeer_Mode then
9295 Process_Inline (True);
9298 --------------------
9299 -- Inline_Generic --
9300 --------------------
9302 -- pragma Inline_Generic (NAME {, NAME});
9304 when Pragma_Inline_Generic =>
9306 Process_Generic_List;
9308 ----------------------
9309 -- Inspection_Point --
9310 ----------------------
9312 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9314 when Pragma_Inspection_Point => Inspection_Point : declare
9319 if Arg_Count > 0 then
9322 Exp := Get_Pragma_Arg (Arg);
9325 if not Is_Entity_Name (Exp)
9326 or else not Is_Object (Entity (Exp))
9328 Error_Pragma_Arg ("object name required", Arg);
9335 end Inspection_Point;
9341 -- pragma Interface (
9342 -- [ Convention =>] convention_IDENTIFIER,
9343 -- [ Entity =>] local_NAME
9344 -- [, [External_Name =>] static_string_EXPRESSION ]
9345 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9347 when Pragma_Interface =>
9354 Check_At_Least_N_Arguments (2);
9355 Check_At_Most_N_Arguments (4);
9356 Process_Import_Or_Interface;
9358 -- In Ada 2005, the permission to use Interface (a reserved word)
9359 -- as a pragma name is considered an obsolescent feature.
9361 if Ada_Version >= Ada_2005 then
9363 (No_Obsolescent_Features, Pragma_Identifier (N));
9366 --------------------
9367 -- Interface_Name --
9368 --------------------
9370 -- pragma Interface_Name (
9371 -- [ Entity =>] local_NAME
9372 -- [,[External_Name =>] static_string_EXPRESSION ]
9373 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9375 when Pragma_Interface_Name => Interface_Name : declare
9384 ((Name_Entity, Name_External_Name, Name_Link_Name));
9385 Check_At_Least_N_Arguments (2);
9386 Check_At_Most_N_Arguments (3);
9387 Id := Get_Pragma_Arg (Arg1);
9390 if not Is_Entity_Name (Id) then
9392 ("first argument for pragma% must be entity name", Arg1);
9393 elsif Etype (Id) = Any_Type then
9396 Def_Id := Entity (Id);
9399 -- Special DEC-compatible processing for the object case, forces
9400 -- object to be imported.
9402 if Ekind (Def_Id) = E_Variable then
9403 Kill_Size_Check_Code (Def_Id);
9404 Note_Possible_Modification (Id, Sure => False);
9406 -- Initialization is not allowed for imported variable
9408 if Present (Expression (Parent (Def_Id)))
9409 and then Comes_From_Source (Expression (Parent (Def_Id)))
9411 Error_Msg_Sloc := Sloc (Def_Id);
9413 ("no initialization allowed for declaration of& #",
9417 -- For compatibility, support VADS usage of providing both
9418 -- pragmas Interface and Interface_Name to obtain the effect
9419 -- of a single Import pragma.
9421 if Is_Imported (Def_Id)
9422 and then Present (First_Rep_Item (Def_Id))
9423 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9425 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9429 Set_Imported (Def_Id);
9432 Set_Is_Public (Def_Id);
9433 Process_Interface_Name (Def_Id, Arg2, Arg3);
9436 -- Otherwise must be subprogram
9438 elsif not Is_Subprogram (Def_Id) then
9440 ("argument of pragma% is not subprogram", Arg1);
9443 Check_At_Most_N_Arguments (3);
9447 -- Loop through homonyms
9450 Def_Id := Get_Base_Subprogram (Hom_Id);
9452 if Is_Imported (Def_Id) then
9453 Process_Interface_Name (Def_Id, Arg2, Arg3);
9457 exit when From_Aspect_Specification (N);
9458 Hom_Id := Homonym (Hom_Id);
9460 exit when No (Hom_Id)
9461 or else Scope (Hom_Id) /= Current_Scope;
9466 ("argument of pragma% is not imported subprogram",
9472 -----------------------
9473 -- Interrupt_Handler --
9474 -----------------------
9476 -- pragma Interrupt_Handler (handler_NAME);
9478 when Pragma_Interrupt_Handler =>
9479 Check_Ada_83_Warning;
9480 Check_Arg_Count (1);
9481 Check_No_Identifiers;
9483 if No_Run_Time_Mode then
9484 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9486 Check_Interrupt_Or_Attach_Handler;
9487 Process_Interrupt_Or_Attach_Handler;
9490 ------------------------
9491 -- Interrupt_Priority --
9492 ------------------------
9494 -- pragma Interrupt_Priority [(EXPRESSION)];
9496 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9497 P : constant Node_Id := Parent (N);
9501 Check_Ada_83_Warning;
9503 if Arg_Count /= 0 then
9504 Arg := Get_Pragma_Arg (Arg1);
9505 Check_Arg_Count (1);
9506 Check_No_Identifiers;
9508 -- The expression must be analyzed in the special manner
9509 -- described in "Handling of Default and Per-Object
9510 -- Expressions" in sem.ads.
9512 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9515 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9519 elsif Has_Pragma_Priority (P) then
9520 Error_Pragma ("duplicate pragma% not allowed");
9523 Set_Has_Pragma_Priority (P, True);
9524 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9526 end Interrupt_Priority;
9528 ---------------------
9529 -- Interrupt_State --
9530 ---------------------
9532 -- pragma Interrupt_State (
9533 -- [Name =>] INTERRUPT_ID,
9534 -- [State =>] INTERRUPT_STATE);
9536 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9537 -- INTERRUPT_STATE => System | Runtime | User
9539 -- Note: if the interrupt id is given as an identifier, then it must
9540 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9541 -- given as a static integer expression which must be in the range of
9542 -- Ada.Interrupts.Interrupt_ID.
9544 when Pragma_Interrupt_State => Interrupt_State : declare
9546 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9547 -- This is the entity Ada.Interrupts.Interrupt_ID;
9549 State_Type : Character;
9550 -- Set to 's'/'r'/'u' for System/Runtime/User
9553 -- Index to entry in Interrupt_States table
9556 -- Value of interrupt
9558 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9559 -- The first argument to the pragma
9561 Int_Ent : Entity_Id;
9562 -- Interrupt entity in Ada.Interrupts.Names
9566 Check_Arg_Order ((Name_Name, Name_State));
9567 Check_Arg_Count (2);
9569 Check_Optional_Identifier (Arg1, Name_Name);
9570 Check_Optional_Identifier (Arg2, Name_State);
9571 Check_Arg_Is_Identifier (Arg2);
9573 -- First argument is identifier
9575 if Nkind (Arg1X) = N_Identifier then
9577 -- Search list of names in Ada.Interrupts.Names
9579 Int_Ent := First_Entity (RTE (RE_Names));
9581 if No (Int_Ent) then
9582 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9584 elsif Chars (Int_Ent) = Chars (Arg1X) then
9585 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9589 Next_Entity (Int_Ent);
9592 -- First argument is not an identifier, so it must be a static
9593 -- expression of type Ada.Interrupts.Interrupt_ID.
9596 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9597 Int_Val := Expr_Value (Arg1X);
9599 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9601 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9604 ("value not in range of type " &
9605 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9611 case Chars (Get_Pragma_Arg (Arg2)) is
9612 when Name_Runtime => State_Type := 'r';
9613 when Name_System => State_Type := 's';
9614 when Name_User => State_Type := 'u';
9617 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9620 -- Check if entry is already stored
9622 IST_Num := Interrupt_States.First;
9624 -- If entry not found, add it
9626 if IST_Num > Interrupt_States.Last then
9627 Interrupt_States.Append
9628 ((Interrupt_Number => UI_To_Int (Int_Val),
9629 Interrupt_State => State_Type,
9630 Pragma_Loc => Loc));
9633 -- Case of entry for the same entry
9635 elsif Int_Val = Interrupt_States.Table (IST_Num).
9638 -- If state matches, done, no need to make redundant entry
9641 State_Type = Interrupt_States.Table (IST_Num).
9644 -- Otherwise if state does not match, error
9647 Interrupt_States.Table (IST_Num).Pragma_Loc;
9649 ("state conflicts with that given #", Arg2);
9653 IST_Num := IST_Num + 1;
9655 end Interrupt_State;
9662 -- ([Entity =>] type_LOCAL_NAME,
9663 -- [Check =>] EXPRESSION
9664 -- [,[Message =>] String_Expression]);
9666 when Pragma_Invariant => Invariant : declare
9671 pragma Unreferenced (Discard);
9675 Check_At_Least_N_Arguments (2);
9676 Check_At_Most_N_Arguments (3);
9677 Check_Optional_Identifier (Arg1, Name_Entity);
9678 Check_Optional_Identifier (Arg2, Name_Check);
9680 if Arg_Count = 3 then
9681 Check_Optional_Identifier (Arg3, Name_Message);
9682 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9685 Check_Arg_Is_Local_Name (Arg1);
9687 Type_Id := Get_Pragma_Arg (Arg1);
9688 Find_Type (Type_Id);
9689 Typ := Entity (Type_Id);
9691 if Typ = Any_Type then
9694 elsif not Ekind_In (Typ, E_Private_Type,
9695 E_Record_Type_With_Private,
9696 E_Limited_Private_Type)
9699 ("pragma% only allowed for private type", Arg1);
9702 -- Note that the type has at least one invariant, and also that
9703 -- it has inheritable invariants if we have Invariant'Class.
9705 Set_Has_Invariants (Typ);
9707 if Class_Present (N) then
9708 Set_Has_Inheritable_Invariants (Typ);
9711 -- The remaining processing is simply to link the pragma on to
9712 -- the rep item chain, for processing when the type is frozen.
9713 -- This is accomplished by a call to Rep_Item_Too_Late.
9715 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9718 ----------------------
9719 -- Java_Constructor --
9720 ----------------------
9722 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9724 -- Also handles pragma CIL_Constructor
9726 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9727 Java_Constructor : declare
9728 Convention : Convention_Id;
9732 This_Formal : Entity_Id;
9736 Check_Arg_Count (1);
9737 Check_Optional_Identifier (Arg1, Name_Entity);
9738 Check_Arg_Is_Local_Name (Arg1);
9740 Id := Get_Pragma_Arg (Arg1);
9741 Find_Program_Unit_Name (Id);
9743 -- If we did not find the name, we are done
9745 if Etype (Id) = Any_Type then
9749 -- Check wrong use of pragma in wrong VM target
9751 if VM_Target = No_VM then
9754 elsif VM_Target = CLI_Target
9755 and then Prag_Id = Pragma_Java_Constructor
9757 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9759 elsif VM_Target = JVM_Target
9760 and then Prag_Id = Pragma_CIL_Constructor
9762 Error_Pragma ("must use pragma 'Java_'Constructor");
9766 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9767 when Pragma_Java_Constructor => Convention := Convention_Java;
9768 when others => null;
9771 Hom_Id := Entity (Id);
9773 -- Loop through homonyms
9776 Def_Id := Get_Base_Subprogram (Hom_Id);
9778 -- The constructor is required to be a function
9780 if Ekind (Def_Id) /= E_Function then
9781 if VM_Target = JVM_Target then
9783 ("pragma% requires function returning a " &
9784 "'Java access type", Def_Id);
9787 ("pragma% requires function returning a " &
9788 "'C'I'L access type", Def_Id);
9792 -- Check arguments: For tagged type the first formal must be
9793 -- named "this" and its type must be a named access type
9794 -- designating a class-wide tagged type that has convention
9795 -- CIL/Java. The first formal must also have a null default
9796 -- value. For example:
9798 -- type Typ is tagged ...
9799 -- type Ref is access all Typ;
9800 -- pragma Convention (CIL, Typ);
9802 -- function New_Typ (This : Ref) return Ref;
9803 -- function New_Typ (This : Ref; I : Integer) return Ref;
9804 -- pragma Cil_Constructor (New_Typ);
9806 -- Reason: The first formal must NOT be a primitive of the
9809 -- This rule also applies to constructors of delegates used
9810 -- to interface with standard target libraries. For example:
9812 -- type Delegate is access procedure ...
9813 -- pragma Import (CIL, Delegate, ...);
9815 -- function new_Delegate
9816 -- (This : Delegate := null; ... ) return Delegate;
9818 -- For value-types this rule does not apply.
9820 if not Is_Value_Type (Etype (Def_Id)) then
9821 if No (First_Formal (Def_Id)) then
9822 Error_Msg_Name_1 := Pname;
9823 Error_Msg_N ("% function must have parameters", Def_Id);
9827 -- In the JRE library we have several occurrences in which
9828 -- the "this" parameter is not the first formal.
9830 This_Formal := First_Formal (Def_Id);
9832 -- In the JRE library we have several occurrences in which
9833 -- the "this" parameter is not the first formal. Search for
9836 if VM_Target = JVM_Target then
9837 while Present (This_Formal)
9838 and then Get_Name_String (Chars (This_Formal)) /= "this"
9840 Next_Formal (This_Formal);
9843 if No (This_Formal) then
9844 This_Formal := First_Formal (Def_Id);
9848 -- Warning: The first parameter should be named "this".
9849 -- We temporarily allow it because we have the following
9850 -- case in the Java runtime (file s-osinte.ads) ???
9852 -- function new_Thread
9853 -- (Self_Id : System.Address) return Thread_Id;
9854 -- pragma Java_Constructor (new_Thread);
9856 if VM_Target = JVM_Target
9857 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9859 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9863 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9864 Error_Msg_Name_1 := Pname;
9866 ("first formal of % function must be named `this`",
9867 Parent (This_Formal));
9869 elsif not Is_Access_Type (Etype (This_Formal)) then
9870 Error_Msg_Name_1 := Pname;
9872 ("first formal of % function must be an access type",
9873 Parameter_Type (Parent (This_Formal)));
9875 -- For delegates the type of the first formal must be a
9876 -- named access-to-subprogram type (see previous example)
9878 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9879 and then Ekind (Etype (This_Formal))
9880 /= E_Access_Subprogram_Type
9882 Error_Msg_Name_1 := Pname;
9884 ("first formal of % function must be a named access" &
9885 " to subprogram type",
9886 Parameter_Type (Parent (This_Formal)));
9888 -- Warning: We should reject anonymous access types because
9889 -- the constructor must not be handled as a primitive of the
9890 -- tagged type. We temporarily allow it because this profile
9891 -- is currently generated by cil2ada???
9893 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9894 and then not Ekind_In (Etype (This_Formal),
9896 E_General_Access_Type,
9897 E_Anonymous_Access_Type)
9899 Error_Msg_Name_1 := Pname;
9901 ("first formal of % function must be a named access" &
9903 Parameter_Type (Parent (This_Formal)));
9905 elsif Atree.Convention
9906 (Designated_Type (Etype (This_Formal))) /= Convention
9908 Error_Msg_Name_1 := Pname;
9910 if Convention = Convention_Java then
9912 ("pragma% requires convention 'Cil in designated" &
9914 Parameter_Type (Parent (This_Formal)));
9917 ("pragma% requires convention 'Java in designated" &
9919 Parameter_Type (Parent (This_Formal)));
9922 elsif No (Expression (Parent (This_Formal)))
9923 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9925 Error_Msg_Name_1 := Pname;
9927 ("pragma% requires first formal with default `null`",
9928 Parameter_Type (Parent (This_Formal)));
9932 -- Check result type: the constructor must be a function
9934 -- * a value type (only allowed in the CIL compiler)
9935 -- * an access-to-subprogram type with convention Java/CIL
9936 -- * an access-type designating a type that has convention
9939 if Is_Value_Type (Etype (Def_Id)) then
9942 -- Access-to-subprogram type with convention Java/CIL
9944 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9945 if Atree.Convention (Etype (Def_Id)) /= Convention then
9946 if Convention = Convention_Java then
9948 ("pragma% requires function returning a " &
9949 "'Java access type", Arg1);
9951 pragma Assert (Convention = Convention_CIL);
9953 ("pragma% requires function returning a " &
9954 "'C'I'L access type", Arg1);
9958 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9959 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9960 E_General_Access_Type)
9963 (Designated_Type (Etype (Def_Id))) /= Convention
9965 Error_Msg_Name_1 := Pname;
9967 if Convention = Convention_Java then
9969 ("pragma% requires function returning a named" &
9970 "'Java access type", Arg1);
9973 ("pragma% requires function returning a named" &
9974 "'C'I'L access type", Arg1);
9979 Set_Is_Constructor (Def_Id);
9980 Set_Convention (Def_Id, Convention);
9981 Set_Is_Imported (Def_Id);
9983 exit when From_Aspect_Specification (N);
9984 Hom_Id := Homonym (Hom_Id);
9986 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9988 end Java_Constructor;
9990 ----------------------
9991 -- Java_Interface --
9992 ----------------------
9994 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9996 when Pragma_Java_Interface => Java_Interface : declare
10002 Check_Arg_Count (1);
10003 Check_Optional_Identifier (Arg1, Name_Entity);
10004 Check_Arg_Is_Local_Name (Arg1);
10006 Arg := Get_Pragma_Arg (Arg1);
10009 if Etype (Arg) = Any_Type then
10013 if not Is_Entity_Name (Arg)
10014 or else not Is_Type (Entity (Arg))
10016 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10019 Typ := Underlying_Type (Entity (Arg));
10021 -- For now simply check some of the semantic constraints on the
10022 -- type. This currently leaves out some restrictions on interface
10023 -- types, namely that the parent type must be java.lang.Object.Typ
10024 -- and that all primitives of the type should be declared
10027 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10028 Error_Pragma_Arg ("pragma% requires an abstract "
10029 & "tagged type", Arg1);
10031 elsif not Has_Discriminants (Typ)
10032 or else Ekind (Etype (First_Discriminant (Typ)))
10033 /= E_Anonymous_Access_Type
10035 not Is_Class_Wide_Type
10036 (Designated_Type (Etype (First_Discriminant (Typ))))
10039 ("type must have a class-wide access discriminant", Arg1);
10041 end Java_Interface;
10047 -- pragma Keep_Names ([On => ] local_NAME);
10049 when Pragma_Keep_Names => Keep_Names : declare
10054 Check_Arg_Count (1);
10055 Check_Optional_Identifier (Arg1, Name_On);
10056 Check_Arg_Is_Local_Name (Arg1);
10058 Arg := Get_Pragma_Arg (Arg1);
10061 if Etype (Arg) = Any_Type then
10065 if not Is_Entity_Name (Arg)
10066 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10069 ("pragma% requires a local enumeration type", Arg1);
10072 Set_Discard_Names (Entity (Arg), False);
10079 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10081 when Pragma_License =>
10083 Check_Arg_Count (1);
10084 Check_No_Identifiers;
10085 Check_Valid_Configuration_Pragma;
10086 Check_Arg_Is_Identifier (Arg1);
10089 Sind : constant Source_File_Index :=
10090 Source_Index (Current_Sem_Unit);
10093 case Chars (Get_Pragma_Arg (Arg1)) is
10095 Set_License (Sind, GPL);
10097 when Name_Modified_GPL =>
10098 Set_License (Sind, Modified_GPL);
10100 when Name_Restricted =>
10101 Set_License (Sind, Restricted);
10103 when Name_Unrestricted =>
10104 Set_License (Sind, Unrestricted);
10107 Error_Pragma_Arg ("invalid license name", Arg1);
10115 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10117 when Pragma_Link_With => Link_With : declare
10123 if Operating_Mode = Generate_Code
10124 and then In_Extended_Main_Source_Unit (N)
10126 Check_At_Least_N_Arguments (1);
10127 Check_No_Identifiers;
10128 Check_Is_In_Decl_Part_Or_Package_Spec;
10129 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10133 while Present (Arg) loop
10134 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10136 -- Store argument, converting sequences of spaces to a
10137 -- single null character (this is one of the differences
10138 -- in processing between Link_With and Linker_Options).
10140 Arg_Store : declare
10141 C : constant Char_Code := Get_Char_Code (' ');
10142 S : constant String_Id :=
10143 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10144 L : constant Nat := String_Length (S);
10147 procedure Skip_Spaces;
10148 -- Advance F past any spaces
10154 procedure Skip_Spaces is
10156 while F <= L and then Get_String_Char (S, F) = C loop
10161 -- Start of processing for Arg_Store
10164 Skip_Spaces; -- skip leading spaces
10166 -- Loop through characters, changing any embedded
10167 -- sequence of spaces to a single null character (this
10168 -- is how Link_With/Linker_Options differ)
10171 if Get_String_Char (S, F) = C then
10174 Store_String_Char (ASCII.NUL);
10177 Store_String_Char (Get_String_Char (S, F));
10185 if Present (Arg) then
10186 Store_String_Char (ASCII.NUL);
10190 Store_Linker_Option_String (End_String);
10198 -- pragma Linker_Alias (
10199 -- [Entity =>] LOCAL_NAME
10200 -- [Target =>] static_string_EXPRESSION);
10202 when Pragma_Linker_Alias =>
10204 Check_Arg_Order ((Name_Entity, Name_Target));
10205 Check_Arg_Count (2);
10206 Check_Optional_Identifier (Arg1, Name_Entity);
10207 Check_Optional_Identifier (Arg2, Name_Target);
10208 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10209 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10211 -- The only processing required is to link this item on to the
10212 -- list of rep items for the given entity. This is accomplished
10213 -- by the call to Rep_Item_Too_Late (when no error is detected
10214 -- and False is returned).
10216 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10219 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10222 ------------------------
10223 -- Linker_Constructor --
10224 ------------------------
10226 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10228 -- Code is shared with Linker_Destructor
10230 -----------------------
10231 -- Linker_Destructor --
10232 -----------------------
10234 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10236 when Pragma_Linker_Constructor |
10237 Pragma_Linker_Destructor =>
10238 Linker_Constructor : declare
10244 Check_Arg_Count (1);
10245 Check_No_Identifiers;
10246 Check_Arg_Is_Local_Name (Arg1);
10247 Arg1_X := Get_Pragma_Arg (Arg1);
10249 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10251 if not Is_Library_Level_Entity (Proc) then
10253 ("argument for pragma% must be library level entity", Arg1);
10256 -- The only processing required is to link this item on to the
10257 -- list of rep items for the given entity. This is accomplished
10258 -- by the call to Rep_Item_Too_Late (when no error is detected
10259 -- and False is returned).
10261 if Rep_Item_Too_Late (Proc, N) then
10264 Set_Has_Gigi_Rep_Item (Proc);
10266 end Linker_Constructor;
10268 --------------------
10269 -- Linker_Options --
10270 --------------------
10272 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10274 when Pragma_Linker_Options => Linker_Options : declare
10278 Check_Ada_83_Warning;
10279 Check_No_Identifiers;
10280 Check_Arg_Count (1);
10281 Check_Is_In_Decl_Part_Or_Package_Spec;
10282 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10283 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10286 while Present (Arg) loop
10287 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10288 Store_String_Char (ASCII.NUL);
10290 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10294 if Operating_Mode = Generate_Code
10295 and then In_Extended_Main_Source_Unit (N)
10297 Store_Linker_Option_String (End_String);
10299 end Linker_Options;
10301 --------------------
10302 -- Linker_Section --
10303 --------------------
10305 -- pragma Linker_Section (
10306 -- [Entity =>] LOCAL_NAME
10307 -- [Section =>] static_string_EXPRESSION);
10309 when Pragma_Linker_Section =>
10311 Check_Arg_Order ((Name_Entity, Name_Section));
10312 Check_Arg_Count (2);
10313 Check_Optional_Identifier (Arg1, Name_Entity);
10314 Check_Optional_Identifier (Arg2, Name_Section);
10315 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10316 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10318 -- This pragma applies only to objects
10320 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10321 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10324 -- The only processing required is to link this item on to the
10325 -- list of rep items for the given entity. This is accomplished
10326 -- by the call to Rep_Item_Too_Late (when no error is detected
10327 -- and False is returned).
10329 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10332 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10339 -- pragma List (On | Off)
10341 -- There is nothing to do here, since we did all the processing for
10342 -- this pragma in Par.Prag (so that it works properly even in syntax
10345 when Pragma_List =>
10348 --------------------
10349 -- Locking_Policy --
10350 --------------------
10352 -- pragma Locking_Policy (policy_IDENTIFIER);
10354 when Pragma_Locking_Policy => declare
10358 Check_Ada_83_Warning;
10359 Check_Arg_Count (1);
10360 Check_No_Identifiers;
10361 Check_Arg_Is_Locking_Policy (Arg1);
10362 Check_Valid_Configuration_Pragma;
10363 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10364 LP := Fold_Upper (Name_Buffer (1));
10366 if Locking_Policy /= ' '
10367 and then Locking_Policy /= LP
10369 Error_Msg_Sloc := Locking_Policy_Sloc;
10370 Error_Pragma ("locking policy incompatible with policy#");
10372 -- Set new policy, but always preserve System_Location since we
10373 -- like the error message with the run time name.
10376 Locking_Policy := LP;
10378 if Locking_Policy_Sloc /= System_Location then
10379 Locking_Policy_Sloc := Loc;
10388 -- pragma Long_Float (D_Float | G_Float);
10390 when Pragma_Long_Float =>
10392 Check_Valid_Configuration_Pragma;
10393 Check_Arg_Count (1);
10394 Check_No_Identifier (Arg1);
10395 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10397 if not OpenVMS_On_Target then
10398 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10403 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10404 if Opt.Float_Format_Long = 'G' then
10405 Error_Pragma ("G_Float previously specified");
10408 Opt.Float_Format_Long := 'D';
10410 -- G_Float case (this is the default, does not need overriding)
10413 if Opt.Float_Format_Long = 'D' then
10414 Error_Pragma ("D_Float previously specified");
10417 Opt.Float_Format_Long := 'G';
10420 Set_Standard_Fpt_Formats;
10422 -----------------------
10423 -- Machine_Attribute --
10424 -----------------------
10426 -- pragma Machine_Attribute (
10427 -- [Entity =>] LOCAL_NAME,
10428 -- [Attribute_Name =>] static_string_EXPRESSION
10429 -- [, [Info =>] static_EXPRESSION] );
10431 when Pragma_Machine_Attribute => Machine_Attribute : declare
10432 Def_Id : Entity_Id;
10436 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10438 if Arg_Count = 3 then
10439 Check_Optional_Identifier (Arg3, Name_Info);
10440 Check_Arg_Is_Static_Expression (Arg3);
10442 Check_Arg_Count (2);
10445 Check_Optional_Identifier (Arg1, Name_Entity);
10446 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10447 Check_Arg_Is_Local_Name (Arg1);
10448 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10449 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10451 if Is_Access_Type (Def_Id) then
10452 Def_Id := Designated_Type (Def_Id);
10455 if Rep_Item_Too_Early (Def_Id, N) then
10459 Def_Id := Underlying_Type (Def_Id);
10461 -- The only processing required is to link this item on to the
10462 -- list of rep items for the given entity. This is accomplished
10463 -- by the call to Rep_Item_Too_Late (when no error is detected
10464 -- and False is returned).
10466 if Rep_Item_Too_Late (Def_Id, N) then
10469 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10471 end Machine_Attribute;
10478 -- (MAIN_OPTION [, MAIN_OPTION]);
10481 -- [STACK_SIZE =>] static_integer_EXPRESSION
10482 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10483 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10485 when Pragma_Main => Main : declare
10486 Args : Args_List (1 .. 3);
10487 Names : constant Name_List (1 .. 3) := (
10489 Name_Task_Stack_Size_Default,
10490 Name_Time_Slicing_Enabled);
10496 Gather_Associations (Names, Args);
10498 for J in 1 .. 2 loop
10499 if Present (Args (J)) then
10500 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10504 if Present (Args (3)) then
10505 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10509 while Present (Nod) loop
10510 if Nkind (Nod) = N_Pragma
10511 and then Pragma_Name (Nod) = Name_Main
10513 Error_Msg_Name_1 := Pname;
10514 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10525 -- pragma Main_Storage
10526 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10528 -- MAIN_STORAGE_OPTION ::=
10529 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10530 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10532 when Pragma_Main_Storage => Main_Storage : declare
10533 Args : Args_List (1 .. 2);
10534 Names : constant Name_List (1 .. 2) := (
10535 Name_Working_Storage,
10542 Gather_Associations (Names, Args);
10544 for J in 1 .. 2 loop
10545 if Present (Args (J)) then
10546 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10550 Check_In_Main_Program;
10553 while Present (Nod) loop
10554 if Nkind (Nod) = N_Pragma
10555 and then Pragma_Name (Nod) = Name_Main_Storage
10557 Error_Msg_Name_1 := Pname;
10558 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10569 -- pragma Memory_Size (NUMERIC_LITERAL)
10571 when Pragma_Memory_Size =>
10574 -- Memory size is simply ignored
10576 Check_No_Identifiers;
10577 Check_Arg_Count (1);
10578 Check_Arg_Is_Integer_Literal (Arg1);
10586 -- The only correct use of this pragma is on its own in a file, in
10587 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10588 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10589 -- check for a file containing nothing but a No_Body pragma). If we
10590 -- attempt to process it during normal semantics processing, it means
10591 -- it was misplaced.
10593 when Pragma_No_Body =>
10601 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10603 when Pragma_No_Return => No_Return : declare
10611 Check_At_Least_N_Arguments (1);
10613 -- Loop through arguments of pragma
10616 while Present (Arg) loop
10617 Check_Arg_Is_Local_Name (Arg);
10618 Id := Get_Pragma_Arg (Arg);
10621 if not Is_Entity_Name (Id) then
10622 Error_Pragma_Arg ("entity name required", Arg);
10625 if Etype (Id) = Any_Type then
10629 -- Loop to find matching procedures
10634 and then Scope (E) = Current_Scope
10636 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10639 -- Set flag on any alias as well
10641 if Is_Overloadable (E) and then Present (Alias (E)) then
10642 Set_No_Return (Alias (E));
10648 exit when From_Aspect_Specification (N);
10653 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10664 -- pragma No_Run_Time;
10666 -- Note: this pragma is retained for backwards compatibility. See
10667 -- body of Rtsfind for full details on its handling.
10669 when Pragma_No_Run_Time =>
10671 Check_Valid_Configuration_Pragma;
10672 Check_Arg_Count (0);
10674 No_Run_Time_Mode := True;
10675 Configurable_Run_Time_Mode := True;
10677 -- Set Duration to 32 bits if word size is 32
10679 if Ttypes.System_Word_Size = 32 then
10680 Duration_32_Bits_On_Target := True;
10683 -- Set appropriate restrictions
10685 Set_Restriction (No_Finalization, N);
10686 Set_Restriction (No_Exception_Handlers, N);
10687 Set_Restriction (Max_Tasks, N, 0);
10688 Set_Restriction (No_Tasking, N);
10690 ------------------------
10691 -- No_Strict_Aliasing --
10692 ------------------------
10694 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10696 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10701 Check_At_Most_N_Arguments (1);
10703 if Arg_Count = 0 then
10704 Check_Valid_Configuration_Pragma;
10705 Opt.No_Strict_Aliasing := True;
10708 Check_Optional_Identifier (Arg2, Name_Entity);
10709 Check_Arg_Is_Local_Name (Arg1);
10710 E_Id := Entity (Get_Pragma_Arg (Arg1));
10712 if E_Id = Any_Type then
10714 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10715 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10718 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10720 end No_Strict_Aliasing;
10722 -----------------------
10723 -- Normalize_Scalars --
10724 -----------------------
10726 -- pragma Normalize_Scalars;
10728 when Pragma_Normalize_Scalars =>
10729 Check_Ada_83_Warning;
10730 Check_Arg_Count (0);
10731 Check_Valid_Configuration_Pragma;
10733 -- Normalize_Scalars creates false positives in CodePeer, so
10734 -- ignore this pragma in this mode.
10736 if not CodePeer_Mode then
10737 Normalize_Scalars := True;
10738 Init_Or_Norm_Scalars := True;
10745 -- pragma Obsolescent;
10747 -- pragma Obsolescent (
10748 -- [Message =>] static_string_EXPRESSION
10749 -- [,[Version =>] Ada_05]]);
10751 -- pragma Obsolescent (
10752 -- [Entity =>] NAME
10753 -- [,[Message =>] static_string_EXPRESSION
10754 -- [,[Version =>] Ada_05]] );
10756 when Pragma_Obsolescent => Obsolescent : declare
10760 procedure Set_Obsolescent (E : Entity_Id);
10761 -- Given an entity Ent, mark it as obsolescent if appropriate
10763 ---------------------
10764 -- Set_Obsolescent --
10765 ---------------------
10767 procedure Set_Obsolescent (E : Entity_Id) is
10776 -- Entity name was given
10778 if Present (Ename) then
10780 -- If entity name matches, we are fine. Save entity in
10781 -- pragma argument, for ASIS use.
10783 if Chars (Ename) = Chars (Ent) then
10784 Set_Entity (Ename, Ent);
10785 Generate_Reference (Ent, Ename);
10787 -- If entity name does not match, only possibility is an
10788 -- enumeration literal from an enumeration type declaration.
10790 elsif Ekind (Ent) /= E_Enumeration_Type then
10792 ("pragma % entity name does not match declaration");
10795 Ent := First_Literal (E);
10799 ("pragma % entity name does not match any " &
10800 "enumeration literal");
10802 elsif Chars (Ent) = Chars (Ename) then
10803 Set_Entity (Ename, Ent);
10804 Generate_Reference (Ent, Ename);
10808 Ent := Next_Literal (Ent);
10814 -- Ent points to entity to be marked
10816 if Arg_Count >= 1 then
10818 -- Deal with static string argument
10820 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10821 S := Strval (Get_Pragma_Arg (Arg1));
10823 for J in 1 .. String_Length (S) loop
10824 if not In_Character_Range (Get_String_Char (S, J)) then
10826 ("pragma% argument does not allow wide characters",
10831 Obsolescent_Warnings.Append
10832 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10834 -- Check for Ada_05 parameter
10836 if Arg_Count /= 1 then
10837 Check_Arg_Count (2);
10840 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10843 Check_Arg_Is_Identifier (Argx);
10845 if Chars (Argx) /= Name_Ada_05 then
10846 Error_Msg_Name_2 := Name_Ada_05;
10848 ("only allowed argument for pragma% is %", Argx);
10851 if Ada_Version_Explicit < Ada_2005
10852 or else not Warn_On_Ada_2005_Compatibility
10860 -- Set flag if pragma active
10863 Set_Is_Obsolescent (Ent);
10867 end Set_Obsolescent;
10869 -- Start of processing for pragma Obsolescent
10874 Check_At_Most_N_Arguments (3);
10876 -- See if first argument specifies an entity name
10880 (Chars (Arg1) = Name_Entity
10882 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10884 N_Operator_Symbol))
10886 Ename := Get_Pragma_Arg (Arg1);
10888 -- Eliminate first argument, so we can share processing
10892 Arg_Count := Arg_Count - 1;
10894 -- No Entity name argument given
10900 if Arg_Count >= 1 then
10901 Check_Optional_Identifier (Arg1, Name_Message);
10903 if Arg_Count = 2 then
10904 Check_Optional_Identifier (Arg2, Name_Version);
10908 -- Get immediately preceding declaration
10911 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10915 -- Cases where we do not follow anything other than another pragma
10919 -- First case: library level compilation unit declaration with
10920 -- the pragma immediately following the declaration.
10922 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10924 (Defining_Entity (Unit (Parent (Parent (N)))));
10927 -- Case 2: library unit placement for package
10931 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10933 if Is_Package_Or_Generic_Package (Ent) then
10934 Set_Obsolescent (Ent);
10940 -- Cases where we must follow a declaration
10943 if Nkind (Decl) not in N_Declaration
10944 and then Nkind (Decl) not in N_Later_Decl_Item
10945 and then Nkind (Decl) not in N_Generic_Declaration
10946 and then Nkind (Decl) not in N_Renaming_Declaration
10949 ("pragma% misplaced, "
10950 & "must immediately follow a declaration");
10953 Set_Obsolescent (Defining_Entity (Decl));
10963 -- pragma Optimize (Time | Space | Off);
10965 -- The actual check for optimize is done in Gigi. Note that this
10966 -- pragma does not actually change the optimization setting, it
10967 -- simply checks that it is consistent with the pragma.
10969 when Pragma_Optimize =>
10970 Check_No_Identifiers;
10971 Check_Arg_Count (1);
10972 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10974 ------------------------
10975 -- Optimize_Alignment --
10976 ------------------------
10978 -- pragma Optimize_Alignment (Time | Space | Off);
10980 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10982 Check_No_Identifiers;
10983 Check_Arg_Count (1);
10984 Check_Valid_Configuration_Pragma;
10987 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10991 Opt.Optimize_Alignment := 'T';
10993 Opt.Optimize_Alignment := 'S';
10995 Opt.Optimize_Alignment := 'O';
10997 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11001 -- Set indication that mode is set locally. If we are in fact in a
11002 -- configuration pragma file, this setting is harmless since the
11003 -- switch will get reset anyway at the start of each unit.
11005 Optimize_Alignment_Local := True;
11006 end Optimize_Alignment;
11012 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11014 when Pragma_Ordered => Ordered : declare
11015 Assoc : constant Node_Id := Arg1;
11021 Check_No_Identifiers;
11022 Check_Arg_Count (1);
11023 Check_Arg_Is_Local_Name (Arg1);
11025 Type_Id := Get_Pragma_Arg (Assoc);
11026 Find_Type (Type_Id);
11027 Typ := Entity (Type_Id);
11029 if Typ = Any_Type then
11032 Typ := Underlying_Type (Typ);
11035 if not Is_Enumeration_Type (Typ) then
11036 Error_Pragma ("pragma% must specify enumeration type");
11039 Check_First_Subtype (Arg1);
11040 Set_Has_Pragma_Ordered (Base_Type (Typ));
11047 -- pragma Pack (first_subtype_LOCAL_NAME);
11049 when Pragma_Pack => Pack : declare
11050 Assoc : constant Node_Id := Arg1;
11054 Ignore : Boolean := False;
11057 Check_No_Identifiers;
11058 Check_Arg_Count (1);
11059 Check_Arg_Is_Local_Name (Arg1);
11061 Type_Id := Get_Pragma_Arg (Assoc);
11062 Find_Type (Type_Id);
11063 Typ := Entity (Type_Id);
11066 or else Rep_Item_Too_Early (Typ, N)
11070 Typ := Underlying_Type (Typ);
11073 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11074 Error_Pragma ("pragma% must specify array or record type");
11077 Check_First_Subtype (Arg1);
11078 Check_Duplicate_Pragma (Typ);
11082 if Is_Array_Type (Typ) then
11083 Ctyp := Component_Type (Typ);
11085 -- Ignore pack that does nothing
11087 if Known_Static_Esize (Ctyp)
11088 and then Known_Static_RM_Size (Ctyp)
11089 and then Esize (Ctyp) = RM_Size (Ctyp)
11090 and then Addressable (Esize (Ctyp))
11095 -- Process OK pragma Pack. Note that if there is a separate
11096 -- component clause present, the Pack will be cancelled. This
11097 -- processing is in Freeze.
11099 if not Rep_Item_Too_Late (Typ, N) then
11101 -- In the context of static code analysis, we do not need
11102 -- complex front-end expansions related to pragma Pack,
11103 -- so disable handling of pragma Pack in this case.
11105 if CodePeer_Mode then
11108 -- Don't attempt any packing for VM targets. We possibly
11109 -- could deal with some cases of array bit-packing, but we
11110 -- don't bother, since this is not a typical kind of
11111 -- representation in the VM context anyway (and would not
11112 -- for example work nicely with the debugger).
11114 elsif VM_Target /= No_VM then
11115 if not GNAT_Mode then
11117 ("?pragma% ignored in this configuration");
11120 -- Normal case where we do the pack action
11124 Set_Is_Packed (Base_Type (Typ));
11125 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11128 Set_Has_Pragma_Pack (Base_Type (Typ));
11132 -- For record types, the pack is always effective
11134 else pragma Assert (Is_Record_Type (Typ));
11135 if not Rep_Item_Too_Late (Typ, N) then
11137 -- Ignore pack request with warning in VM mode (skip warning
11138 -- if we are compiling GNAT run time library).
11140 if VM_Target /= No_VM then
11141 if not GNAT_Mode then
11143 ("?pragma% ignored in this configuration");
11146 -- Normal case of pack request active
11149 Set_Is_Packed (Base_Type (Typ));
11150 Set_Has_Pragma_Pack (Base_Type (Typ));
11151 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11163 -- There is nothing to do here, since we did all the processing for
11164 -- this pragma in Par.Prag (so that it works properly even in syntax
11167 when Pragma_Page =>
11174 -- pragma Passive [(PASSIVE_FORM)];
11176 -- PASSIVE_FORM ::= Semaphore | No
11178 when Pragma_Passive =>
11181 if Nkind (Parent (N)) /= N_Task_Definition then
11182 Error_Pragma ("pragma% must be within task definition");
11185 if Arg_Count /= 0 then
11186 Check_Arg_Count (1);
11187 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11190 ----------------------------------
11191 -- Preelaborable_Initialization --
11192 ----------------------------------
11194 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11196 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11201 Check_Arg_Count (1);
11202 Check_No_Identifiers;
11203 Check_Arg_Is_Identifier (Arg1);
11204 Check_Arg_Is_Local_Name (Arg1);
11205 Check_First_Subtype (Arg1);
11206 Ent := Entity (Get_Pragma_Arg (Arg1));
11208 if not (Is_Private_Type (Ent)
11210 Is_Protected_Type (Ent)
11212 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11215 ("pragma % can only be applied to private, formal derived or "
11216 & "protected type",
11220 -- Give an error if the pragma is applied to a protected type that
11221 -- does not qualify (due to having entries, or due to components
11222 -- that do not qualify).
11224 if Is_Protected_Type (Ent)
11225 and then not Has_Preelaborable_Initialization (Ent)
11228 ("protected type & does not have preelaborable " &
11229 "initialization", Ent);
11231 -- Otherwise mark the type as definitely having preelaborable
11235 Set_Known_To_Have_Preelab_Init (Ent);
11238 if Has_Pragma_Preelab_Init (Ent)
11239 and then Warn_On_Redundant_Constructs
11241 Error_Pragma ("?duplicate pragma%!");
11243 Set_Has_Pragma_Preelab_Init (Ent);
11247 --------------------
11248 -- Persistent_BSS --
11249 --------------------
11251 -- pragma Persistent_BSS [(object_NAME)];
11253 when Pragma_Persistent_BSS => Persistent_BSS : declare
11260 Check_At_Most_N_Arguments (1);
11262 -- Case of application to specific object (one argument)
11264 if Arg_Count = 1 then
11265 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11267 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11269 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11272 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11275 Ent := Entity (Get_Pragma_Arg (Arg1));
11276 Decl := Parent (Ent);
11278 if Rep_Item_Too_Late (Ent, N) then
11282 if Present (Expression (Decl)) then
11284 ("object for pragma% cannot have initialization", Arg1);
11287 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11289 ("object type for pragma% is not potentially persistent",
11293 Check_Duplicate_Pragma (Ent);
11296 Make_Linker_Section_Pragma
11297 (Ent, Sloc (N), ".persistent.bss");
11298 Insert_After (N, Prag);
11301 -- Case of use as configuration pragma with no arguments
11304 Check_Valid_Configuration_Pragma;
11305 Persistent_BSS_Mode := True;
11307 end Persistent_BSS;
11313 -- pragma Polling (ON | OFF);
11315 when Pragma_Polling =>
11317 Check_Arg_Count (1);
11318 Check_No_Identifiers;
11319 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11320 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11322 -------------------
11323 -- Postcondition --
11324 -------------------
11326 -- pragma Postcondition ([Check =>] Boolean_Expression
11327 -- [,[Message =>] String_Expression]);
11329 when Pragma_Postcondition => Postcondition : declare
11331 pragma Warnings (Off, In_Body);
11335 Check_At_Least_N_Arguments (1);
11336 Check_At_Most_N_Arguments (2);
11337 Check_Optional_Identifier (Arg1, Name_Check);
11339 -- All we need to do here is call the common check procedure,
11340 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11342 Check_Precondition_Postcondition (In_Body);
11349 -- pragma Precondition ([Check =>] Boolean_Expression
11350 -- [,[Message =>] String_Expression]);
11352 when Pragma_Precondition => Precondition : declare
11357 Check_At_Least_N_Arguments (1);
11358 Check_At_Most_N_Arguments (2);
11359 Check_Optional_Identifier (Arg1, Name_Check);
11360 Check_Precondition_Postcondition (In_Body);
11362 -- If in spec, nothing more to do. If in body, then we convert the
11363 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11364 -- this whether or not precondition checks are enabled. That works
11365 -- fine since pragma Check will do this check, and will also
11366 -- analyze the condition itself in the proper context.
11371 Chars => Name_Check,
11372 Pragma_Argument_Associations => New_List (
11373 Make_Pragma_Argument_Association (Loc,
11374 Expression => Make_Identifier (Loc, Name_Precondition)),
11376 Make_Pragma_Argument_Association (Sloc (Arg1),
11377 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11379 if Arg_Count = 2 then
11380 Append_To (Pragma_Argument_Associations (N),
11381 Make_Pragma_Argument_Association (Sloc (Arg2),
11382 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11393 -- pragma Predicate
11394 -- ([Entity =>] type_LOCAL_NAME,
11395 -- [Check =>] EXPRESSION);
11397 when Pragma_Predicate => Predicate : declare
11402 pragma Unreferenced (Discard);
11406 Check_Arg_Count (2);
11407 Check_Optional_Identifier (Arg1, Name_Entity);
11408 Check_Optional_Identifier (Arg2, Name_Check);
11410 Check_Arg_Is_Local_Name (Arg1);
11412 Type_Id := Get_Pragma_Arg (Arg1);
11413 Find_Type (Type_Id);
11414 Typ := Entity (Type_Id);
11416 if Typ = Any_Type then
11420 -- The remaining processing is simply to link the pragma on to
11421 -- the rep item chain, for processing when the type is frozen.
11422 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11423 -- mark the type as having predicates.
11425 Set_Has_Predicates (Typ);
11426 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11433 -- pragma Preelaborate [(library_unit_NAME)];
11435 -- Set the flag Is_Preelaborated of program unit name entity
11437 when Pragma_Preelaborate => Preelaborate : declare
11438 Pa : constant Node_Id := Parent (N);
11439 Pk : constant Node_Kind := Nkind (Pa);
11443 Check_Ada_83_Warning;
11444 Check_Valid_Library_Unit_Pragma;
11446 if Nkind (N) = N_Null_Statement then
11450 Ent := Find_Lib_Unit_Name;
11451 Check_Duplicate_Pragma (Ent);
11453 -- This filters out pragmas inside generic parent then
11454 -- show up inside instantiation
11457 and then not (Pk = N_Package_Specification
11458 and then Present (Generic_Parent (Pa)))
11460 if not Debug_Flag_U then
11461 Set_Is_Preelaborated (Ent);
11462 Set_Suppress_Elaboration_Warnings (Ent);
11467 ---------------------
11468 -- Preelaborate_05 --
11469 ---------------------
11471 -- pragma Preelaborate_05 [(library_unit_NAME)];
11473 -- This pragma is useable only in GNAT_Mode, where it is used like
11474 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11475 -- (otherwise it is ignored). This is used to implement AI-362 which
11476 -- recategorizes some run-time packages in Ada 2005 mode.
11478 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11483 Check_Valid_Library_Unit_Pragma;
11485 if not GNAT_Mode then
11486 Error_Pragma ("pragma% only available in GNAT mode");
11489 if Nkind (N) = N_Null_Statement then
11493 -- This is one of the few cases where we need to test the value of
11494 -- Ada_Version_Explicit rather than Ada_Version (which is always
11495 -- set to Ada_2012 in a predefined unit), we need to know the
11496 -- explicit version set to know if this pragma is active.
11498 if Ada_Version_Explicit >= Ada_2005 then
11499 Ent := Find_Lib_Unit_Name;
11500 Set_Is_Preelaborated (Ent);
11501 Set_Suppress_Elaboration_Warnings (Ent);
11503 end Preelaborate_05;
11509 -- pragma Priority (EXPRESSION);
11511 when Pragma_Priority => Priority : declare
11512 P : constant Node_Id := Parent (N);
11516 Check_No_Identifiers;
11517 Check_Arg_Count (1);
11521 if Nkind (P) = N_Subprogram_Body then
11522 Check_In_Main_Program;
11524 Arg := Get_Pragma_Arg (Arg1);
11525 Analyze_And_Resolve (Arg, Standard_Integer);
11529 if not Is_Static_Expression (Arg) then
11530 Flag_Non_Static_Expr
11531 ("main subprogram priority is not static!", Arg);
11534 -- If constraint error, then we already signalled an error
11536 elsif Raises_Constraint_Error (Arg) then
11539 -- Otherwise check in range
11543 Val : constant Uint := Expr_Value (Arg);
11547 or else Val > Expr_Value (Expression
11548 (Parent (RTE (RE_Max_Priority))))
11551 ("main subprogram priority is out of range", Arg1);
11557 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11559 -- Load an arbitrary entity from System.Tasking to make sure
11560 -- this package is implicitly with'ed, since we need to have
11561 -- the tasking run-time active for the pragma Priority to have
11565 Discard : Entity_Id;
11566 pragma Warnings (Off, Discard);
11568 Discard := RTE (RE_Task_List);
11571 -- Task or Protected, must be of type Integer
11573 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11574 Arg := Get_Pragma_Arg (Arg1);
11576 -- The expression must be analyzed in the special manner
11577 -- described in "Handling of Default and Per-Object
11578 -- Expressions" in sem.ads.
11580 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11582 if not Is_Static_Expression (Arg) then
11583 Check_Restriction (Static_Priorities, Arg);
11586 -- Anything else is incorrect
11592 if Has_Pragma_Priority (P) then
11593 Error_Pragma ("duplicate pragma% not allowed");
11595 Set_Has_Pragma_Priority (P, True);
11597 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11598 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11599 -- exp_ch9 should use this ???
11604 -----------------------------------
11605 -- Priority_Specific_Dispatching --
11606 -----------------------------------
11608 -- pragma Priority_Specific_Dispatching (
11609 -- policy_IDENTIFIER,
11610 -- first_priority_EXPRESSION,
11611 -- last_priority_EXPRESSION);
11613 when Pragma_Priority_Specific_Dispatching =>
11614 Priority_Specific_Dispatching : declare
11615 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11616 -- This is the entity System.Any_Priority;
11619 Lower_Bound : Node_Id;
11620 Upper_Bound : Node_Id;
11626 Check_Arg_Count (3);
11627 Check_No_Identifiers;
11628 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11629 Check_Valid_Configuration_Pragma;
11630 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11631 DP := Fold_Upper (Name_Buffer (1));
11633 Lower_Bound := Get_Pragma_Arg (Arg2);
11634 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11635 Lower_Val := Expr_Value (Lower_Bound);
11637 Upper_Bound := Get_Pragma_Arg (Arg3);
11638 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11639 Upper_Val := Expr_Value (Upper_Bound);
11641 -- It is not allowed to use Task_Dispatching_Policy and
11642 -- Priority_Specific_Dispatching in the same partition.
11644 if Task_Dispatching_Policy /= ' ' then
11645 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11647 ("pragma% incompatible with Task_Dispatching_Policy#");
11649 -- Check lower bound in range
11651 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11653 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11656 ("first_priority is out of range", Arg2);
11658 -- Check upper bound in range
11660 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11662 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11665 ("last_priority is out of range", Arg3);
11667 -- Check that the priority range is valid
11669 elsif Lower_Val > Upper_Val then
11671 ("last_priority_expression must be greater than" &
11672 " or equal to first_priority_expression");
11674 -- Store the new policy, but always preserve System_Location since
11675 -- we like the error message with the run-time name.
11678 -- Check overlapping in the priority ranges specified in other
11679 -- Priority_Specific_Dispatching pragmas within the same
11680 -- partition. We can only check those we know about!
11683 Specific_Dispatching.First .. Specific_Dispatching.Last
11685 if Specific_Dispatching.Table (J).First_Priority in
11686 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11687 or else Specific_Dispatching.Table (J).Last_Priority in
11688 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11691 Specific_Dispatching.Table (J).Pragma_Loc;
11693 ("priority range overlaps with "
11694 & "Priority_Specific_Dispatching#");
11698 -- The use of Priority_Specific_Dispatching is incompatible
11699 -- with Task_Dispatching_Policy.
11701 if Task_Dispatching_Policy /= ' ' then
11702 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11704 ("Priority_Specific_Dispatching incompatible "
11705 & "with Task_Dispatching_Policy#");
11708 -- The use of Priority_Specific_Dispatching forces ceiling
11711 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11712 Error_Msg_Sloc := Locking_Policy_Sloc;
11714 ("Priority_Specific_Dispatching incompatible "
11715 & "with Locking_Policy#");
11717 -- Set the Ceiling_Locking policy, but preserve System_Location
11718 -- since we like the error message with the run time name.
11721 Locking_Policy := 'C';
11723 if Locking_Policy_Sloc /= System_Location then
11724 Locking_Policy_Sloc := Loc;
11728 -- Add entry in the table
11730 Specific_Dispatching.Append
11731 ((Dispatching_Policy => DP,
11732 First_Priority => UI_To_Int (Lower_Val),
11733 Last_Priority => UI_To_Int (Upper_Val),
11734 Pragma_Loc => Loc));
11736 end Priority_Specific_Dispatching;
11742 -- pragma Profile (profile_IDENTIFIER);
11744 -- profile_IDENTIFIER => Restricted | Ravenscar
11746 when Pragma_Profile =>
11748 Check_Arg_Count (1);
11749 Check_Valid_Configuration_Pragma;
11750 Check_No_Identifiers;
11753 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11755 if Chars (Argx) = Name_Ravenscar then
11756 Set_Ravenscar_Profile (N);
11757 elsif Chars (Argx) = Name_Restricted then
11758 Set_Profile_Restrictions
11759 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11761 Error_Pragma_Arg ("& is not a valid profile", Argx);
11765 ----------------------
11766 -- Profile_Warnings --
11767 ----------------------
11769 -- pragma Profile_Warnings (profile_IDENTIFIER);
11771 -- profile_IDENTIFIER => Restricted | Ravenscar
11773 when Pragma_Profile_Warnings =>
11775 Check_Arg_Count (1);
11776 Check_Valid_Configuration_Pragma;
11777 Check_No_Identifiers;
11780 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11782 if Chars (Argx) = Name_Ravenscar then
11783 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11784 elsif Chars (Argx) = Name_Restricted then
11785 Set_Profile_Restrictions (Restricted, N, Warn => True);
11787 Error_Pragma_Arg ("& is not a valid profile", Argx);
11791 --------------------------
11792 -- Propagate_Exceptions --
11793 --------------------------
11795 -- pragma Propagate_Exceptions;
11797 -- Note: this pragma is obsolete and has no effect
11799 when Pragma_Propagate_Exceptions =>
11801 Check_Arg_Count (0);
11803 if In_Extended_Main_Source_Unit (N) then
11804 Propagate_Exceptions := True;
11811 -- pragma Psect_Object (
11812 -- [Internal =>] LOCAL_NAME,
11813 -- [, [External =>] EXTERNAL_SYMBOL]
11814 -- [, [Size =>] EXTERNAL_SYMBOL]);
11816 when Pragma_Psect_Object | Pragma_Common_Object =>
11817 Psect_Object : declare
11818 Args : Args_List (1 .. 3);
11819 Names : constant Name_List (1 .. 3) := (
11824 Internal : Node_Id renames Args (1);
11825 External : Node_Id renames Args (2);
11826 Size : Node_Id renames Args (3);
11828 Def_Id : Entity_Id;
11830 procedure Check_Too_Long (Arg : Node_Id);
11831 -- Posts message if the argument is an identifier with more
11832 -- than 31 characters, or a string literal with more than
11833 -- 31 characters, and we are operating under VMS
11835 --------------------
11836 -- Check_Too_Long --
11837 --------------------
11839 procedure Check_Too_Long (Arg : Node_Id) is
11840 X : constant Node_Id := Original_Node (Arg);
11843 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11845 ("inappropriate argument for pragma %", Arg);
11848 if OpenVMS_On_Target then
11849 if (Nkind (X) = N_String_Literal
11850 and then String_Length (Strval (X)) > 31)
11852 (Nkind (X) = N_Identifier
11853 and then Length_Of_Name (Chars (X)) > 31)
11856 ("argument for pragma % is longer than 31 characters",
11860 end Check_Too_Long;
11862 -- Start of processing for Common_Object/Psect_Object
11866 Gather_Associations (Names, Args);
11867 Process_Extended_Import_Export_Internal_Arg (Internal);
11869 Def_Id := Entity (Internal);
11871 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11873 ("pragma% must designate an object", Internal);
11876 Check_Too_Long (Internal);
11878 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11880 ("cannot use pragma% for imported/exported object",
11884 if Is_Concurrent_Type (Etype (Internal)) then
11886 ("cannot specify pragma % for task/protected object",
11890 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11892 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11894 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11897 if Ekind (Def_Id) = E_Constant then
11899 ("cannot specify pragma % for a constant", Internal);
11902 if Is_Record_Type (Etype (Internal)) then
11908 Ent := First_Entity (Etype (Internal));
11909 while Present (Ent) loop
11910 Decl := Declaration_Node (Ent);
11912 if Ekind (Ent) = E_Component
11913 and then Nkind (Decl) = N_Component_Declaration
11914 and then Present (Expression (Decl))
11915 and then Warn_On_Export_Import
11918 ("?object for pragma % has defaults", Internal);
11928 if Present (Size) then
11929 Check_Too_Long (Size);
11932 if Present (External) then
11933 Check_Arg_Is_External_Name (External);
11934 Check_Too_Long (External);
11937 -- If all error tests pass, link pragma on to the rep item chain
11939 Record_Rep_Item (Def_Id, N);
11946 -- pragma Pure [(library_unit_NAME)];
11948 when Pragma_Pure => Pure : declare
11952 Check_Ada_83_Warning;
11953 Check_Valid_Library_Unit_Pragma;
11955 if Nkind (N) = N_Null_Statement then
11959 Ent := Find_Lib_Unit_Name;
11961 Set_Has_Pragma_Pure (Ent);
11962 Set_Suppress_Elaboration_Warnings (Ent);
11969 -- pragma Pure_05 [(library_unit_NAME)];
11971 -- This pragma is useable only in GNAT_Mode, where it is used like
11972 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11973 -- it is ignored). It may be used after a pragma Preelaborate, in
11974 -- which case it overrides the effect of the pragma Preelaborate.
11975 -- This is used to implement AI-362 which recategorizes some run-time
11976 -- packages in Ada 2005 mode.
11978 when Pragma_Pure_05 => Pure_05 : declare
11983 Check_Valid_Library_Unit_Pragma;
11985 if not GNAT_Mode then
11986 Error_Pragma ("pragma% only available in GNAT mode");
11989 if Nkind (N) = N_Null_Statement then
11993 -- This is one of the few cases where we need to test the value of
11994 -- Ada_Version_Explicit rather than Ada_Version (which is always
11995 -- set to Ada_2012 in a predefined unit), we need to know the
11996 -- explicit version set to know if this pragma is active.
11998 if Ada_Version_Explicit >= Ada_2005 then
11999 Ent := Find_Lib_Unit_Name;
12000 Set_Is_Preelaborated (Ent, False);
12002 Set_Suppress_Elaboration_Warnings (Ent);
12006 -------------------
12007 -- Pure_Function --
12008 -------------------
12010 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12012 when Pragma_Pure_Function => Pure_Function : declare
12015 Def_Id : Entity_Id;
12016 Effective : Boolean := False;
12020 Check_Arg_Count (1);
12021 Check_Optional_Identifier (Arg1, Name_Entity);
12022 Check_Arg_Is_Local_Name (Arg1);
12023 E_Id := Get_Pragma_Arg (Arg1);
12025 if Error_Posted (E_Id) then
12029 -- Loop through homonyms (overloadings) of referenced entity
12031 E := Entity (E_Id);
12033 if Present (E) then
12035 Def_Id := Get_Base_Subprogram (E);
12037 if not Ekind_In (Def_Id, E_Function,
12038 E_Generic_Function,
12042 ("pragma% requires a function name", Arg1);
12045 Set_Is_Pure (Def_Id);
12047 if not Has_Pragma_Pure_Function (Def_Id) then
12048 Set_Has_Pragma_Pure_Function (Def_Id);
12052 exit when From_Aspect_Specification (N);
12054 exit when No (E) or else Scope (E) /= Current_Scope;
12058 and then Warn_On_Redundant_Constructs
12061 ("pragma Pure_Function on& is redundant?",
12067 --------------------
12068 -- Queuing_Policy --
12069 --------------------
12071 -- pragma Queuing_Policy (policy_IDENTIFIER);
12073 when Pragma_Queuing_Policy => declare
12077 Check_Ada_83_Warning;
12078 Check_Arg_Count (1);
12079 Check_No_Identifiers;
12080 Check_Arg_Is_Queuing_Policy (Arg1);
12081 Check_Valid_Configuration_Pragma;
12082 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12083 QP := Fold_Upper (Name_Buffer (1));
12085 if Queuing_Policy /= ' '
12086 and then Queuing_Policy /= QP
12088 Error_Msg_Sloc := Queuing_Policy_Sloc;
12089 Error_Pragma ("queuing policy incompatible with policy#");
12091 -- Set new policy, but always preserve System_Location since we
12092 -- like the error message with the run time name.
12095 Queuing_Policy := QP;
12097 if Queuing_Policy_Sloc /= System_Location then
12098 Queuing_Policy_Sloc := Loc;
12103 -----------------------
12104 -- Relative_Deadline --
12105 -----------------------
12107 -- pragma Relative_Deadline (time_span_EXPRESSION);
12109 when Pragma_Relative_Deadline => Relative_Deadline : declare
12110 P : constant Node_Id := Parent (N);
12115 Check_No_Identifiers;
12116 Check_Arg_Count (1);
12118 Arg := Get_Pragma_Arg (Arg1);
12120 -- The expression must be analyzed in the special manner described
12121 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12123 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12127 if Nkind (P) = N_Subprogram_Body then
12128 Check_In_Main_Program;
12132 elsif Nkind (P) = N_Task_Definition then
12135 -- Anything else is incorrect
12141 if Has_Relative_Deadline_Pragma (P) then
12142 Error_Pragma ("duplicate pragma% not allowed");
12144 Set_Has_Relative_Deadline_Pragma (P, True);
12146 if Nkind (P) = N_Task_Definition then
12147 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12150 end Relative_Deadline;
12152 ---------------------------
12153 -- Remote_Call_Interface --
12154 ---------------------------
12156 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12158 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12159 Cunit_Node : Node_Id;
12160 Cunit_Ent : Entity_Id;
12164 Check_Ada_83_Warning;
12165 Check_Valid_Library_Unit_Pragma;
12167 if Nkind (N) = N_Null_Statement then
12171 Cunit_Node := Cunit (Current_Sem_Unit);
12172 K := Nkind (Unit (Cunit_Node));
12173 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12175 if K = N_Package_Declaration
12176 or else K = N_Generic_Package_Declaration
12177 or else K = N_Subprogram_Declaration
12178 or else K = N_Generic_Subprogram_Declaration
12179 or else (K = N_Subprogram_Body
12180 and then Acts_As_Spec (Unit (Cunit_Node)))
12185 "pragma% must apply to package or subprogram declaration");
12188 Set_Is_Remote_Call_Interface (Cunit_Ent);
12189 end Remote_Call_Interface;
12195 -- pragma Remote_Types [(library_unit_NAME)];
12197 when Pragma_Remote_Types => Remote_Types : declare
12198 Cunit_Node : Node_Id;
12199 Cunit_Ent : Entity_Id;
12202 Check_Ada_83_Warning;
12203 Check_Valid_Library_Unit_Pragma;
12205 if Nkind (N) = N_Null_Statement then
12209 Cunit_Node := Cunit (Current_Sem_Unit);
12210 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12212 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12213 N_Generic_Package_Declaration)
12216 ("pragma% can only apply to a package declaration");
12219 Set_Is_Remote_Types (Cunit_Ent);
12226 -- pragma Ravenscar;
12228 when Pragma_Ravenscar =>
12230 Check_Arg_Count (0);
12231 Check_Valid_Configuration_Pragma;
12232 Set_Ravenscar_Profile (N);
12234 if Warn_On_Obsolescent_Feature then
12235 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12236 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12239 -------------------------
12240 -- Restricted_Run_Time --
12241 -------------------------
12243 -- pragma Restricted_Run_Time;
12245 when Pragma_Restricted_Run_Time =>
12247 Check_Arg_Count (0);
12248 Check_Valid_Configuration_Pragma;
12249 Set_Profile_Restrictions
12250 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12252 if Warn_On_Obsolescent_Feature then
12254 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12255 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12262 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12265 -- restriction_IDENTIFIER
12266 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12268 when Pragma_Restrictions =>
12269 Process_Restrictions_Or_Restriction_Warnings
12270 (Warn => Treat_Restrictions_As_Warnings);
12272 --------------------------
12273 -- Restriction_Warnings --
12274 --------------------------
12276 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12279 -- restriction_IDENTIFIER
12280 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12282 when Pragma_Restriction_Warnings =>
12284 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12290 -- pragma Reviewable;
12292 when Pragma_Reviewable =>
12293 Check_Ada_83_Warning;
12294 Check_Arg_Count (0);
12296 -- Call dummy debugging function rv. This is done to assist front
12297 -- end debugging. By placing a Reviewable pragma in the source
12298 -- program, a breakpoint on rv catches this place in the source,
12299 -- allowing convenient stepping to the point of interest.
12303 --------------------------
12304 -- Short_Circuit_And_Or --
12305 --------------------------
12307 when Pragma_Short_Circuit_And_Or =>
12309 Check_Arg_Count (0);
12310 Check_Valid_Configuration_Pragma;
12311 Short_Circuit_And_Or := True;
12313 -------------------
12314 -- Share_Generic --
12315 -------------------
12317 -- pragma Share_Generic (NAME {, NAME});
12319 when Pragma_Share_Generic =>
12321 Process_Generic_List;
12327 -- pragma Shared (LOCAL_NAME);
12329 when Pragma_Shared =>
12331 Process_Atomic_Shared_Volatile;
12333 --------------------
12334 -- Shared_Passive --
12335 --------------------
12337 -- pragma Shared_Passive [(library_unit_NAME)];
12339 -- Set the flag Is_Shared_Passive of program unit name entity
12341 when Pragma_Shared_Passive => Shared_Passive : declare
12342 Cunit_Node : Node_Id;
12343 Cunit_Ent : Entity_Id;
12346 Check_Ada_83_Warning;
12347 Check_Valid_Library_Unit_Pragma;
12349 if Nkind (N) = N_Null_Statement then
12353 Cunit_Node := Cunit (Current_Sem_Unit);
12354 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12356 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12357 N_Generic_Package_Declaration)
12360 ("pragma% can only apply to a package declaration");
12363 Set_Is_Shared_Passive (Cunit_Ent);
12364 end Shared_Passive;
12366 -----------------------
12367 -- Short_Descriptors --
12368 -----------------------
12370 -- pragma Short_Descriptors;
12372 when Pragma_Short_Descriptors =>
12374 Check_Arg_Count (0);
12375 Check_Valid_Configuration_Pragma;
12376 Short_Descriptors := True;
12378 ----------------------
12379 -- Source_File_Name --
12380 ----------------------
12382 -- There are five forms for this pragma:
12384 -- pragma Source_File_Name (
12385 -- [UNIT_NAME =>] unit_NAME,
12386 -- BODY_FILE_NAME => STRING_LITERAL
12387 -- [, [INDEX =>] INTEGER_LITERAL]);
12389 -- pragma Source_File_Name (
12390 -- [UNIT_NAME =>] unit_NAME,
12391 -- SPEC_FILE_NAME => STRING_LITERAL
12392 -- [, [INDEX =>] INTEGER_LITERAL]);
12394 -- pragma Source_File_Name (
12395 -- BODY_FILE_NAME => STRING_LITERAL
12396 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12397 -- [, CASING => CASING_SPEC]);
12399 -- pragma Source_File_Name (
12400 -- SPEC_FILE_NAME => STRING_LITERAL
12401 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12402 -- [, CASING => CASING_SPEC]);
12404 -- pragma Source_File_Name (
12405 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12406 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12407 -- [, CASING => CASING_SPEC]);
12409 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12411 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12412 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12413 -- only be used when no project file is used, while SFNP can only be
12414 -- used when a project file is used.
12416 -- No processing here. Processing was completed during parsing, since
12417 -- we need to have file names set as early as possible. Units are
12418 -- loaded well before semantic processing starts.
12420 -- The only processing we defer to this point is the check for
12421 -- correct placement.
12423 when Pragma_Source_File_Name =>
12425 Check_Valid_Configuration_Pragma;
12427 ------------------------------
12428 -- Source_File_Name_Project --
12429 ------------------------------
12431 -- See Source_File_Name for syntax
12433 -- No processing here. Processing was completed during parsing, since
12434 -- we need to have file names set as early as possible. Units are
12435 -- loaded well before semantic processing starts.
12437 -- The only processing we defer to this point is the check for
12438 -- correct placement.
12440 when Pragma_Source_File_Name_Project =>
12442 Check_Valid_Configuration_Pragma;
12444 -- Check that a pragma Source_File_Name_Project is used only in a
12445 -- configuration pragmas file.
12447 -- Pragmas Source_File_Name_Project should only be generated by
12448 -- the Project Manager in configuration pragmas files.
12450 -- This is really an ugly test. It seems to depend on some
12451 -- accidental and undocumented property. At the very least it
12452 -- needs to be documented, but it would be better to have a
12453 -- clean way of testing if we are in a configuration file???
12455 if Present (Parent (N)) then
12457 ("pragma% can only appear in a configuration pragmas file");
12460 ----------------------
12461 -- Source_Reference --
12462 ----------------------
12464 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12466 -- Nothing to do, all processing completed in Par.Prag, since we need
12467 -- the information for possible parser messages that are output.
12469 when Pragma_Source_Reference =>
12472 --------------------------------
12473 -- Static_Elaboration_Desired --
12474 --------------------------------
12476 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12478 when Pragma_Static_Elaboration_Desired =>
12480 Check_At_Most_N_Arguments (1);
12482 if Is_Compilation_Unit (Current_Scope)
12483 and then Ekind (Current_Scope) = E_Package
12485 Set_Static_Elaboration_Desired (Current_Scope, True);
12487 Error_Pragma ("pragma% must apply to a library-level package");
12494 -- pragma Storage_Size (EXPRESSION);
12496 when Pragma_Storage_Size => Storage_Size : declare
12497 P : constant Node_Id := Parent (N);
12501 Check_No_Identifiers;
12502 Check_Arg_Count (1);
12504 -- The expression must be analyzed in the special manner described
12505 -- in "Handling of Default Expressions" in sem.ads.
12507 Arg := Get_Pragma_Arg (Arg1);
12508 Preanalyze_Spec_Expression (Arg, Any_Integer);
12510 if not Is_Static_Expression (Arg) then
12511 Check_Restriction (Static_Storage_Size, Arg);
12514 if Nkind (P) /= N_Task_Definition then
12519 if Has_Storage_Size_Pragma (P) then
12520 Error_Pragma ("duplicate pragma% not allowed");
12522 Set_Has_Storage_Size_Pragma (P, True);
12525 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12526 -- ??? exp_ch9 should use this!
12534 -- pragma Storage_Unit (NUMERIC_LITERAL);
12536 -- Only permitted argument is System'Storage_Unit value
12538 when Pragma_Storage_Unit =>
12539 Check_No_Identifiers;
12540 Check_Arg_Count (1);
12541 Check_Arg_Is_Integer_Literal (Arg1);
12543 if Intval (Get_Pragma_Arg (Arg1)) /=
12544 UI_From_Int (Ttypes.System_Storage_Unit)
12546 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12548 ("the only allowed argument for pragma% is ^", Arg1);
12551 --------------------
12552 -- Stream_Convert --
12553 --------------------
12555 -- pragma Stream_Convert (
12556 -- [Entity =>] type_LOCAL_NAME,
12557 -- [Read =>] function_NAME,
12558 -- [Write =>] function NAME);
12560 when Pragma_Stream_Convert => Stream_Convert : declare
12562 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12563 -- Check that the given argument is the name of a local function
12564 -- of one argument that is not overloaded earlier in the current
12565 -- local scope. A check is also made that the argument is a
12566 -- function with one parameter.
12568 --------------------------------------
12569 -- Check_OK_Stream_Convert_Function --
12570 --------------------------------------
12572 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12576 Check_Arg_Is_Local_Name (Arg);
12577 Ent := Entity (Get_Pragma_Arg (Arg));
12579 if Has_Homonym (Ent) then
12581 ("argument for pragma% may not be overloaded", Arg);
12584 if Ekind (Ent) /= E_Function
12585 or else No (First_Formal (Ent))
12586 or else Present (Next_Formal (First_Formal (Ent)))
12589 ("argument for pragma% must be" &
12590 " function of one argument", Arg);
12592 end Check_OK_Stream_Convert_Function;
12594 -- Start of processing for Stream_Convert
12598 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12599 Check_Arg_Count (3);
12600 Check_Optional_Identifier (Arg1, Name_Entity);
12601 Check_Optional_Identifier (Arg2, Name_Read);
12602 Check_Optional_Identifier (Arg3, Name_Write);
12603 Check_Arg_Is_Local_Name (Arg1);
12604 Check_OK_Stream_Convert_Function (Arg2);
12605 Check_OK_Stream_Convert_Function (Arg3);
12608 Typ : constant Entity_Id :=
12609 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12610 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12611 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12614 Check_First_Subtype (Arg1);
12616 -- Check for too early or too late. Note that we don't enforce
12617 -- the rule about primitive operations in this case, since, as
12618 -- is the case for explicit stream attributes themselves, these
12619 -- restrictions are not appropriate. Note that the chaining of
12620 -- the pragma by Rep_Item_Too_Late is actually the critical
12621 -- processing done for this pragma.
12623 if Rep_Item_Too_Early (Typ, N)
12625 Rep_Item_Too_Late (Typ, N, FOnly => True)
12630 -- Return if previous error
12632 if Etype (Typ) = Any_Type
12634 Etype (Read) = Any_Type
12636 Etype (Write) = Any_Type
12643 if Underlying_Type (Etype (Read)) /= Typ then
12645 ("incorrect return type for function&", Arg2);
12648 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12650 ("incorrect parameter type for function&", Arg3);
12653 if Underlying_Type (Etype (First_Formal (Read))) /=
12654 Underlying_Type (Etype (Write))
12657 ("result type of & does not match Read parameter type",
12661 end Stream_Convert;
12663 -------------------------
12664 -- Style_Checks (GNAT) --
12665 -------------------------
12667 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12669 -- This is processed by the parser since some of the style checks
12670 -- take place during source scanning and parsing. This means that
12671 -- we don't need to issue error messages here.
12673 when Pragma_Style_Checks => Style_Checks : declare
12674 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12680 Check_No_Identifiers;
12682 -- Two argument form
12684 if Arg_Count = 2 then
12685 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12692 E_Id := Get_Pragma_Arg (Arg2);
12695 if not Is_Entity_Name (E_Id) then
12697 ("second argument of pragma% must be entity name",
12701 E := Entity (E_Id);
12707 Set_Suppress_Style_Checks (E,
12708 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12709 exit when No (Homonym (E));
12715 -- One argument form
12718 Check_Arg_Count (1);
12720 if Nkind (A) = N_String_Literal then
12724 Slen : constant Natural := Natural (String_Length (S));
12725 Options : String (1 .. Slen);
12731 C := Get_String_Char (S, Int (J));
12732 exit when not In_Character_Range (C);
12733 Options (J) := Get_Character (C);
12735 -- If at end of string, set options. As per discussion
12736 -- above, no need to check for errors, since we issued
12737 -- them in the parser.
12740 Set_Style_Check_Options (Options);
12748 elsif Nkind (A) = N_Identifier then
12749 if Chars (A) = Name_All_Checks then
12751 Set_GNAT_Style_Check_Options;
12753 Set_Default_Style_Check_Options;
12756 elsif Chars (A) = Name_On then
12757 Style_Check := True;
12759 elsif Chars (A) = Name_Off then
12760 Style_Check := False;
12770 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12772 when Pragma_Subtitle =>
12774 Check_Arg_Count (1);
12775 Check_Optional_Identifier (Arg1, Name_Subtitle);
12776 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12783 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12785 when Pragma_Suppress =>
12786 Process_Suppress_Unsuppress (True);
12792 -- pragma Suppress_All;
12794 -- The only check made here is that the pragma has no arguments.
12795 -- There are no placement rules, and the processing required (setting
12796 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12797 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12798 -- then creates and inserts a pragma Suppress (All_Checks).
12800 when Pragma_Suppress_All =>
12802 Check_Arg_Count (0);
12804 -------------------------
12805 -- Suppress_Debug_Info --
12806 -------------------------
12808 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12810 when Pragma_Suppress_Debug_Info =>
12812 Check_Arg_Count (1);
12813 Check_Optional_Identifier (Arg1, Name_Entity);
12814 Check_Arg_Is_Local_Name (Arg1);
12815 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
12817 ----------------------------------
12818 -- Suppress_Exception_Locations --
12819 ----------------------------------
12821 -- pragma Suppress_Exception_Locations;
12823 when Pragma_Suppress_Exception_Locations =>
12825 Check_Arg_Count (0);
12826 Check_Valid_Configuration_Pragma;
12827 Exception_Locations_Suppressed := True;
12829 -----------------------------
12830 -- Suppress_Initialization --
12831 -----------------------------
12833 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12835 when Pragma_Suppress_Initialization => Suppress_Init : declare
12841 Check_Arg_Count (1);
12842 Check_Optional_Identifier (Arg1, Name_Entity);
12843 Check_Arg_Is_Local_Name (Arg1);
12845 E_Id := Get_Pragma_Arg (Arg1);
12847 if Etype (E_Id) = Any_Type then
12851 E := Entity (E_Id);
12853 if Is_Type (E) then
12854 if Is_Incomplete_Or_Private_Type (E) then
12855 if No (Full_View (Base_Type (E))) then
12857 ("argument of pragma% cannot be an incomplete type",
12860 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12863 Set_Suppress_Init_Proc (Base_Type (E));
12868 ("pragma% requires argument that is a type name", Arg1);
12876 -- pragma System_Name (DIRECT_NAME);
12878 -- Syntax check: one argument, which must be the identifier GNAT or
12879 -- the identifier GCC, no other identifiers are acceptable.
12881 when Pragma_System_Name =>
12883 Check_No_Identifiers;
12884 Check_Arg_Count (1);
12885 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12887 -----------------------------
12888 -- Task_Dispatching_Policy --
12889 -----------------------------
12891 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12893 when Pragma_Task_Dispatching_Policy => declare
12897 Check_Ada_83_Warning;
12898 Check_Arg_Count (1);
12899 Check_No_Identifiers;
12900 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12901 Check_Valid_Configuration_Pragma;
12902 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12903 DP := Fold_Upper (Name_Buffer (1));
12905 if Task_Dispatching_Policy /= ' '
12906 and then Task_Dispatching_Policy /= DP
12908 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12910 ("task dispatching policy incompatible with policy#");
12912 -- Set new policy, but always preserve System_Location since we
12913 -- like the error message with the run time name.
12916 Task_Dispatching_Policy := DP;
12918 if Task_Dispatching_Policy_Sloc /= System_Location then
12919 Task_Dispatching_Policy_Sloc := Loc;
12928 -- pragma Task_Info (EXPRESSION);
12930 when Pragma_Task_Info => Task_Info : declare
12931 P : constant Node_Id := Parent (N);
12936 if Nkind (P) /= N_Task_Definition then
12937 Error_Pragma ("pragma% must appear in task definition");
12940 Check_No_Identifiers;
12941 Check_Arg_Count (1);
12943 Analyze_And_Resolve
12944 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12946 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12950 if Has_Task_Info_Pragma (P) then
12951 Error_Pragma ("duplicate pragma% not allowed");
12953 Set_Has_Task_Info_Pragma (P, True);
12961 -- pragma Task_Name (string_EXPRESSION);
12963 when Pragma_Task_Name => Task_Name : declare
12964 P : constant Node_Id := Parent (N);
12968 Check_No_Identifiers;
12969 Check_Arg_Count (1);
12971 Arg := Get_Pragma_Arg (Arg1);
12973 -- The expression is used in the call to Create_Task, and must be
12974 -- expanded there, not in the context of the current spec. It must
12975 -- however be analyzed to capture global references, in case it
12976 -- appears in a generic context.
12978 Preanalyze_And_Resolve (Arg, Standard_String);
12980 if Nkind (P) /= N_Task_Definition then
12984 if Has_Task_Name_Pragma (P) then
12985 Error_Pragma ("duplicate pragma% not allowed");
12987 Set_Has_Task_Name_Pragma (P, True);
12988 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12996 -- pragma Task_Storage (
12997 -- [Task_Type =>] LOCAL_NAME,
12998 -- [Top_Guard =>] static_integer_EXPRESSION);
13000 when Pragma_Task_Storage => Task_Storage : declare
13001 Args : Args_List (1 .. 2);
13002 Names : constant Name_List (1 .. 2) := (
13006 Task_Type : Node_Id renames Args (1);
13007 Top_Guard : Node_Id renames Args (2);
13013 Gather_Associations (Names, Args);
13015 if No (Task_Type) then
13017 ("missing task_type argument for pragma%");
13020 Check_Arg_Is_Local_Name (Task_Type);
13022 Ent := Entity (Task_Type);
13024 if not Is_Task_Type (Ent) then
13026 ("argument for pragma% must be task type", Task_Type);
13029 if No (Top_Guard) then
13031 ("pragma% takes two arguments", Task_Type);
13033 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13036 Check_First_Subtype (Task_Type);
13038 if Rep_Item_Too_Late (Ent, N) then
13043 --------------------------
13044 -- Thread_Local_Storage --
13045 --------------------------
13047 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13049 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13055 Check_Arg_Count (1);
13056 Check_Optional_Identifier (Arg1, Name_Entity);
13057 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13059 Id := Get_Pragma_Arg (Arg1);
13062 if not Is_Entity_Name (Id)
13063 or else Ekind (Entity (Id)) /= E_Variable
13065 Error_Pragma_Arg ("local variable name required", Arg1);
13070 if Rep_Item_Too_Early (E, N)
13071 or else Rep_Item_Too_Late (E, N)
13076 Set_Has_Pragma_Thread_Local_Storage (E);
13077 Set_Has_Gigi_Rep_Item (E);
13078 end Thread_Local_Storage;
13084 -- pragma Time_Slice (static_duration_EXPRESSION);
13086 when Pragma_Time_Slice => Time_Slice : declare
13092 Check_Arg_Count (1);
13093 Check_No_Identifiers;
13094 Check_In_Main_Program;
13095 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13097 if not Error_Posted (Arg1) then
13099 while Present (Nod) loop
13100 if Nkind (Nod) = N_Pragma
13101 and then Pragma_Name (Nod) = Name_Time_Slice
13103 Error_Msg_Name_1 := Pname;
13104 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13111 -- Process only if in main unit
13113 if Get_Source_Unit (Loc) = Main_Unit then
13114 Opt.Time_Slice_Set := True;
13115 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13117 if Val <= Ureal_0 then
13118 Opt.Time_Slice_Value := 0;
13120 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13121 Opt.Time_Slice_Value := 1_000_000_000;
13124 Opt.Time_Slice_Value :=
13125 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13134 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13136 -- TITLING_OPTION ::=
13137 -- [Title =>] STRING_LITERAL
13138 -- | [Subtitle =>] STRING_LITERAL
13140 when Pragma_Title => Title : declare
13141 Args : Args_List (1 .. 2);
13142 Names : constant Name_List (1 .. 2) := (
13148 Gather_Associations (Names, Args);
13151 for J in 1 .. 2 loop
13152 if Present (Args (J)) then
13153 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13158 ---------------------
13159 -- Unchecked_Union --
13160 ---------------------
13162 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13164 when Pragma_Unchecked_Union => Unchecked_Union : declare
13165 Assoc : constant Node_Id := Arg1;
13166 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13177 Check_No_Identifiers;
13178 Check_Arg_Count (1);
13179 Check_Arg_Is_Local_Name (Arg1);
13181 Find_Type (Type_Id);
13182 Typ := Entity (Type_Id);
13185 or else Rep_Item_Too_Early (Typ, N)
13189 Typ := Underlying_Type (Typ);
13192 if Rep_Item_Too_Late (Typ, N) then
13196 Check_First_Subtype (Arg1);
13198 -- Note remaining cases are references to a type in the current
13199 -- declarative part. If we find an error, we post the error on
13200 -- the relevant type declaration at an appropriate point.
13202 if not Is_Record_Type (Typ) then
13203 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13206 elsif Is_Tagged_Type (Typ) then
13207 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13210 elsif Is_Limited_Type (Typ) then
13212 ("Unchecked_Union must not be limited record type", Typ);
13213 Explain_Limited_Type (Typ, Typ);
13217 if not Has_Discriminants (Typ) then
13219 ("Unchecked_Union must have one discriminant", Typ);
13223 Discr := First_Discriminant (Typ);
13224 while Present (Discr) loop
13225 if No (Discriminant_Default_Value (Discr)) then
13227 ("Unchecked_Union discriminant must have default value",
13231 Next_Discriminant (Discr);
13234 Tdef := Type_Definition (Declaration_Node (Typ));
13235 Clist := Component_List (Tdef);
13237 Comp := First (Component_Items (Clist));
13238 while Present (Comp) loop
13239 Check_Component (Comp, Typ);
13243 if No (Clist) or else No (Variant_Part (Clist)) then
13245 ("Unchecked_Union must have variant part",
13250 Vpart := Variant_Part (Clist);
13252 Variant := First (Variants (Vpart));
13253 while Present (Variant) loop
13254 Check_Variant (Variant, Typ);
13259 Set_Is_Unchecked_Union (Typ);
13260 Set_Convention (Typ, Convention_C);
13261 Set_Has_Unchecked_Union (Base_Type (Typ));
13262 Set_Is_Unchecked_Union (Base_Type (Typ));
13263 end Unchecked_Union;
13265 ------------------------
13266 -- Unimplemented_Unit --
13267 ------------------------
13269 -- pragma Unimplemented_Unit;
13271 -- Note: this only gives an error if we are generating code, or if
13272 -- we are in a generic library unit (where the pragma appears in the
13273 -- body, not in the spec).
13275 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13276 Cunitent : constant Entity_Id :=
13277 Cunit_Entity (Get_Source_Unit (Loc));
13278 Ent_Kind : constant Entity_Kind :=
13283 Check_Arg_Count (0);
13285 if Operating_Mode = Generate_Code
13286 or else Ent_Kind = E_Generic_Function
13287 or else Ent_Kind = E_Generic_Procedure
13288 or else Ent_Kind = E_Generic_Package
13290 Get_Name_String (Chars (Cunitent));
13291 Set_Casing (Mixed_Case);
13292 Write_Str (Name_Buffer (1 .. Name_Len));
13293 Write_Str (" is not supported in this configuration");
13295 raise Unrecoverable_Error;
13297 end Unimplemented_Unit;
13299 ------------------------
13300 -- Universal_Aliasing --
13301 ------------------------
13303 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13305 when Pragma_Universal_Aliasing => Universal_Alias : declare
13310 Check_Arg_Count (1);
13311 Check_Optional_Identifier (Arg2, Name_Entity);
13312 Check_Arg_Is_Local_Name (Arg1);
13313 E_Id := Entity (Get_Pragma_Arg (Arg1));
13315 if E_Id = Any_Type then
13317 elsif No (E_Id) or else not Is_Type (E_Id) then
13318 Error_Pragma_Arg ("pragma% requires type", Arg1);
13321 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13322 end Universal_Alias;
13324 --------------------
13325 -- Universal_Data --
13326 --------------------
13328 -- pragma Universal_Data [(library_unit_NAME)];
13330 when Pragma_Universal_Data =>
13333 -- If this is a configuration pragma, then set the universal
13334 -- addressing option, otherwise confirm that the pragma satisfies
13335 -- the requirements of library unit pragma placement and leave it
13336 -- to the GNAAMP back end to detect the pragma (avoids transitive
13337 -- setting of the option due to withed units).
13339 if Is_Configuration_Pragma then
13340 Universal_Addressing_On_AAMP := True;
13342 Check_Valid_Library_Unit_Pragma;
13345 if not AAMP_On_Target then
13346 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13353 -- pragma Unmodified (local_Name {, local_Name});
13355 when Pragma_Unmodified => Unmodified : declare
13356 Arg_Node : Node_Id;
13357 Arg_Expr : Node_Id;
13358 Arg_Ent : Entity_Id;
13362 Check_At_Least_N_Arguments (1);
13364 -- Loop through arguments
13367 while Present (Arg_Node) loop
13368 Check_No_Identifier (Arg_Node);
13370 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13371 -- in fact generate reference, so that the entity will have a
13372 -- reference, which will inhibit any warnings about it not
13373 -- being referenced, and also properly show up in the ali file
13374 -- as a reference. But this reference is recorded before the
13375 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13376 -- generated for this reference.
13378 Check_Arg_Is_Local_Name (Arg_Node);
13379 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13381 if Is_Entity_Name (Arg_Expr) then
13382 Arg_Ent := Entity (Arg_Expr);
13384 if not Is_Assignable (Arg_Ent) then
13386 ("pragma% can only be applied to a variable",
13389 Set_Has_Pragma_Unmodified (Arg_Ent);
13401 -- pragma Unreferenced (local_Name {, local_Name});
13403 -- or when used in a context clause:
13405 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13407 when Pragma_Unreferenced => Unreferenced : declare
13408 Arg_Node : Node_Id;
13409 Arg_Expr : Node_Id;
13410 Arg_Ent : Entity_Id;
13415 Check_At_Least_N_Arguments (1);
13417 -- Check case of appearing within context clause
13419 if Is_In_Context_Clause then
13421 -- The arguments must all be units mentioned in a with clause
13422 -- in the same context clause. Note we already checked (in
13423 -- Par.Prag) that the arguments are either identifiers or
13424 -- selected components.
13427 while Present (Arg_Node) loop
13428 Citem := First (List_Containing (N));
13429 while Citem /= N loop
13430 if Nkind (Citem) = N_With_Clause
13432 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13434 Set_Has_Pragma_Unreferenced
13437 (Library_Unit (Citem))));
13439 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13448 ("argument of pragma% is not with'ed unit", Arg_Node);
13454 -- Case of not in list of context items
13458 while Present (Arg_Node) loop
13459 Check_No_Identifier (Arg_Node);
13461 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13462 -- will in fact generate reference, so that the entity will
13463 -- have a reference, which will inhibit any warnings about
13464 -- it not being referenced, and also properly show up in the
13465 -- ali file as a reference. But this reference is recorded
13466 -- before the Has_Pragma_Unreferenced flag is set, so that
13467 -- no warning is generated for this reference.
13469 Check_Arg_Is_Local_Name (Arg_Node);
13470 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13472 if Is_Entity_Name (Arg_Expr) then
13473 Arg_Ent := Entity (Arg_Expr);
13475 -- If the entity is overloaded, the pragma applies to the
13476 -- most recent overloading, as documented. In this case,
13477 -- name resolution does not generate a reference, so it
13478 -- must be done here explicitly.
13480 if Is_Overloaded (Arg_Expr) then
13481 Generate_Reference (Arg_Ent, N);
13484 Set_Has_Pragma_Unreferenced (Arg_Ent);
13492 --------------------------
13493 -- Unreferenced_Objects --
13494 --------------------------
13496 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13498 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13499 Arg_Node : Node_Id;
13500 Arg_Expr : Node_Id;
13504 Check_At_Least_N_Arguments (1);
13507 while Present (Arg_Node) loop
13508 Check_No_Identifier (Arg_Node);
13509 Check_Arg_Is_Local_Name (Arg_Node);
13510 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13512 if not Is_Entity_Name (Arg_Expr)
13513 or else not Is_Type (Entity (Arg_Expr))
13516 ("argument for pragma% must be type or subtype", Arg_Node);
13519 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13522 end Unreferenced_Objects;
13524 ------------------------------
13525 -- Unreserve_All_Interrupts --
13526 ------------------------------
13528 -- pragma Unreserve_All_Interrupts;
13530 when Pragma_Unreserve_All_Interrupts =>
13532 Check_Arg_Count (0);
13534 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13535 Unreserve_All_Interrupts := True;
13542 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13544 when Pragma_Unsuppress =>
13546 Process_Suppress_Unsuppress (False);
13548 -------------------
13549 -- Use_VADS_Size --
13550 -------------------
13552 -- pragma Use_VADS_Size;
13554 when Pragma_Use_VADS_Size =>
13556 Check_Arg_Count (0);
13557 Check_Valid_Configuration_Pragma;
13558 Use_VADS_Size := True;
13560 ---------------------
13561 -- Validity_Checks --
13562 ---------------------
13564 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13566 when Pragma_Validity_Checks => Validity_Checks : declare
13567 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13573 Check_Arg_Count (1);
13574 Check_No_Identifiers;
13576 if Nkind (A) = N_String_Literal then
13580 Slen : constant Natural := Natural (String_Length (S));
13581 Options : String (1 .. Slen);
13587 C := Get_String_Char (S, Int (J));
13588 exit when not In_Character_Range (C);
13589 Options (J) := Get_Character (C);
13592 Set_Validity_Check_Options (Options);
13600 elsif Nkind (A) = N_Identifier then
13602 if Chars (A) = Name_All_Checks then
13603 Set_Validity_Check_Options ("a");
13605 elsif Chars (A) = Name_On then
13606 Validity_Checks_On := True;
13608 elsif Chars (A) = Name_Off then
13609 Validity_Checks_On := False;
13613 end Validity_Checks;
13619 -- pragma Volatile (LOCAL_NAME);
13621 when Pragma_Volatile =>
13622 Process_Atomic_Shared_Volatile;
13624 -------------------------
13625 -- Volatile_Components --
13626 -------------------------
13628 -- pragma Volatile_Components (array_LOCAL_NAME);
13630 -- Volatile is handled by the same circuit as Atomic_Components
13636 -- pragma Warnings (On | Off);
13637 -- pragma Warnings (On | Off, LOCAL_NAME);
13638 -- pragma Warnings (static_string_EXPRESSION);
13639 -- pragma Warnings (On | Off, STRING_LITERAL);
13641 when Pragma_Warnings => Warnings : begin
13643 Check_At_Least_N_Arguments (1);
13644 Check_No_Identifiers;
13646 -- If debug flag -gnatd.i is set, pragma is ignored
13648 if Debug_Flag_Dot_I then
13652 -- Process various forms of the pragma
13655 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13658 -- One argument case
13660 if Arg_Count = 1 then
13662 -- On/Off one argument case was processed by parser
13664 if Nkind (Argx) = N_Identifier
13666 (Chars (Argx) = Name_On
13668 Chars (Argx) = Name_Off)
13672 -- One argument case must be ON/OFF or static string expr
13674 elsif not Is_Static_String_Expression (Arg1) then
13676 ("argument of pragma% must be On/Off or " &
13677 "static string expression", Arg1);
13679 -- One argument string expression case
13683 Lit : constant Node_Id := Expr_Value_S (Argx);
13684 Str : constant String_Id := Strval (Lit);
13685 Len : constant Nat := String_Length (Str);
13693 while J <= Len loop
13694 C := Get_String_Char (Str, J);
13695 OK := In_Character_Range (C);
13698 Chr := Get_Character (C);
13702 if J < Len and then Chr = '.' then
13704 C := Get_String_Char (Str, J);
13705 Chr := Get_Character (C);
13707 if not Set_Dot_Warning_Switch (Chr) then
13709 ("invalid warning switch character " &
13716 OK := Set_Warning_Switch (Chr);
13722 ("invalid warning switch character " & Chr,
13731 -- Two or more arguments (must be two)
13734 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13735 Check_At_Most_N_Arguments (2);
13743 E_Id := Get_Pragma_Arg (Arg2);
13746 -- In the expansion of an inlined body, a reference to
13747 -- the formal may be wrapped in a conversion if the
13748 -- actual is a conversion. Retrieve the real entity name.
13750 if (In_Instance_Body
13751 or else In_Inlined_Body)
13752 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13754 E_Id := Expression (E_Id);
13757 -- Entity name case
13759 if Is_Entity_Name (E_Id) then
13760 E := Entity (E_Id);
13767 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13770 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13771 and then Warn_On_Warnings_Off
13773 Warnings_Off_Pragmas.Append ((N, E));
13776 if Is_Enumeration_Type (E) then
13780 Lit := First_Literal (E);
13781 while Present (Lit) loop
13782 Set_Warnings_Off (Lit);
13783 Next_Literal (Lit);
13788 exit when No (Homonym (E));
13793 -- Error if not entity or static string literal case
13795 elsif not Is_Static_String_Expression (Arg2) then
13797 ("second argument of pragma% must be entity " &
13798 "name or static string expression", Arg2);
13800 -- String literal case
13803 String_To_Name_Buffer
13804 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13806 -- Note on configuration pragma case: If this is a
13807 -- configuration pragma, then for an OFF pragma, we
13808 -- just set Config True in the call, which is all
13809 -- that needs to be done. For the case of ON, this
13810 -- is normally an error, unless it is canceling the
13811 -- effect of a previous OFF pragma in the same file.
13812 -- In any other case, an error will be signalled (ON
13813 -- with no matching OFF).
13815 if Chars (Argx) = Name_Off then
13816 Set_Specific_Warning_Off
13817 (Loc, Name_Buffer (1 .. Name_Len),
13818 Config => Is_Configuration_Pragma);
13820 elsif Chars (Argx) = Name_On then
13821 Set_Specific_Warning_On
13822 (Loc, Name_Buffer (1 .. Name_Len), Err);
13826 ("?pragma Warnings On with no " &
13827 "matching Warnings Off",
13837 -------------------
13838 -- Weak_External --
13839 -------------------
13841 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13843 when Pragma_Weak_External => Weak_External : declare
13848 Check_Arg_Count (1);
13849 Check_Optional_Identifier (Arg1, Name_Entity);
13850 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13851 Ent := Entity (Get_Pragma_Arg (Arg1));
13853 if Rep_Item_Too_Early (Ent, N) then
13856 Ent := Underlying_Type (Ent);
13859 -- The only processing required is to link this item on to the
13860 -- list of rep items for the given entity. This is accomplished
13861 -- by the call to Rep_Item_Too_Late (when no error is detected
13862 -- and False is returned).
13864 if Rep_Item_Too_Late (Ent, N) then
13867 Set_Has_Gigi_Rep_Item (Ent);
13871 -----------------------------
13872 -- Wide_Character_Encoding --
13873 -----------------------------
13875 -- pragma Wide_Character_Encoding (IDENTIFIER);
13877 when Pragma_Wide_Character_Encoding =>
13880 -- Nothing to do, handled in parser. Note that we do not enforce
13881 -- configuration pragma placement, this pragma can appear at any
13882 -- place in the source, allowing mixed encodings within a single
13887 --------------------
13888 -- Unknown_Pragma --
13889 --------------------
13891 -- Should be impossible, since the case of an unknown pragma is
13892 -- separately processed before the case statement is entered.
13894 when Unknown_Pragma =>
13895 raise Program_Error;
13898 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13899 -- until AI is formally approved.
13901 -- Check_Order_Dependence;
13904 when Pragma_Exit => null;
13905 end Analyze_Pragma;
13907 -------------------
13908 -- Check_Enabled --
13909 -------------------
13911 function Check_Enabled (Nam : Name_Id) return Boolean is
13915 -- Loop through entries in check policy list
13917 PP := Opt.Check_Policy_List;
13919 -- If there are no specific entries that matched, then we let the
13920 -- setting of assertions govern. Note that this provides the needed
13921 -- compatibility with the RM for the cases of assertion, invariant,
13922 -- precondition, predicate, and postcondition.
13925 return Assertions_Enabled;
13927 -- Here we have an entry see if it matches
13931 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13934 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13935 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13936 when Name_On | Name_Check =>
13938 when Name_Off | Name_Ignore =>
13941 raise Program_Error;
13945 PP := Next_Pragma (PP);
13952 ---------------------------------
13953 -- Delay_Config_Pragma_Analyze --
13954 ---------------------------------
13956 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13958 return Pragma_Name (N) = Name_Interrupt_State
13960 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13961 end Delay_Config_Pragma_Analyze;
13963 -------------------------
13964 -- Get_Base_Subprogram --
13965 -------------------------
13967 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13968 Result : Entity_Id;
13971 -- Follow subprogram renaming chain
13974 while Is_Subprogram (Result)
13976 (Is_Generic_Instance (Result)
13977 or else Nkind (Parent (Declaration_Node (Result))) =
13978 N_Subprogram_Renaming_Declaration)
13979 and then Present (Alias (Result))
13981 Result := Alias (Result);
13985 end Get_Base_Subprogram;
13991 procedure Initialize is
13996 -----------------------------
13997 -- Is_Config_Static_String --
13998 -----------------------------
14000 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14002 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14003 -- This is an internal recursive function that is just like the outer
14004 -- function except that it adds the string to the name buffer rather
14005 -- than placing the string in the name buffer.
14007 ------------------------------
14008 -- Add_Config_Static_String --
14009 ------------------------------
14011 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14018 if Nkind (N) = N_Op_Concat then
14019 if Add_Config_Static_String (Left_Opnd (N)) then
14020 N := Right_Opnd (N);
14026 if Nkind (N) /= N_String_Literal then
14027 Error_Msg_N ("string literal expected for pragma argument", N);
14031 for J in 1 .. String_Length (Strval (N)) loop
14032 C := Get_String_Char (Strval (N), J);
14034 if not In_Character_Range (C) then
14036 ("string literal contains invalid wide character",
14037 Sloc (N) + 1 + Source_Ptr (J));
14041 Add_Char_To_Name_Buffer (Get_Character (C));
14046 end Add_Config_Static_String;
14048 -- Start of processing for Is_Config_Static_String
14053 return Add_Config_Static_String (Arg);
14054 end Is_Config_Static_String;
14056 -----------------------------------------
14057 -- Is_Non_Significant_Pragma_Reference --
14058 -----------------------------------------
14060 -- This function makes use of the following static table which indicates
14061 -- whether a given pragma is significant.
14063 -- -1 indicates that references in any argument position are significant
14064 -- 0 indicates that appearance in any argument is not significant
14065 -- +n indicates that appearance as argument n is significant, but all
14066 -- other arguments are not significant
14067 -- 99 special processing required (e.g. for pragma Check)
14069 Sig_Flags : constant array (Pragma_Id) of Int :=
14070 (Pragma_AST_Entry => -1,
14071 Pragma_Abort_Defer => -1,
14072 Pragma_Ada_83 => -1,
14073 Pragma_Ada_95 => -1,
14074 Pragma_Ada_05 => -1,
14075 Pragma_Ada_2005 => -1,
14076 Pragma_Ada_12 => -1,
14077 Pragma_Ada_2012 => -1,
14078 Pragma_All_Calls_Remote => -1,
14079 Pragma_Annotate => -1,
14080 Pragma_Assert => -1,
14081 Pragma_Assertion_Policy => 0,
14082 Pragma_Assume_No_Invalid_Values => 0,
14083 Pragma_Asynchronous => -1,
14084 Pragma_Atomic => 0,
14085 Pragma_Atomic_Components => 0,
14086 Pragma_Attach_Handler => -1,
14087 Pragma_Check => 99,
14088 Pragma_Check_Name => 0,
14089 Pragma_Check_Policy => 0,
14090 Pragma_CIL_Constructor => -1,
14091 Pragma_CPP_Class => 0,
14092 Pragma_CPP_Constructor => 0,
14093 Pragma_CPP_Virtual => 0,
14094 Pragma_CPP_Vtable => 0,
14096 Pragma_C_Pass_By_Copy => 0,
14097 Pragma_Comment => 0,
14098 Pragma_Common_Object => -1,
14099 Pragma_Compile_Time_Error => -1,
14100 Pragma_Compile_Time_Warning => -1,
14101 Pragma_Compiler_Unit => 0,
14102 Pragma_Complete_Representation => 0,
14103 Pragma_Complex_Representation => 0,
14104 Pragma_Component_Alignment => -1,
14105 Pragma_Controlled => 0,
14106 Pragma_Convention => 0,
14107 Pragma_Convention_Identifier => 0,
14108 Pragma_Debug => -1,
14109 Pragma_Debug_Policy => 0,
14110 Pragma_Default_Value => -1,
14111 Pragma_Default_Component_Value => -1,
14112 Pragma_Detect_Blocking => -1,
14113 Pragma_Default_Storage_Pool => -1,
14114 Pragma_Dimension => -1,
14115 Pragma_Discard_Names => 0,
14116 Pragma_Elaborate => -1,
14117 Pragma_Elaborate_All => -1,
14118 Pragma_Elaborate_Body => -1,
14119 Pragma_Elaboration_Checks => -1,
14120 Pragma_Eliminate => -1,
14121 Pragma_Export => -1,
14122 Pragma_Export_Exception => -1,
14123 Pragma_Export_Function => -1,
14124 Pragma_Export_Object => -1,
14125 Pragma_Export_Procedure => -1,
14126 Pragma_Export_Value => -1,
14127 Pragma_Export_Valued_Procedure => -1,
14128 Pragma_Extend_System => -1,
14129 Pragma_Extensions_Allowed => -1,
14130 Pragma_External => -1,
14131 Pragma_Favor_Top_Level => -1,
14132 Pragma_External_Name_Casing => -1,
14133 Pragma_Fast_Math => -1,
14134 Pragma_Finalize_Storage_Only => 0,
14135 Pragma_Float_Representation => 0,
14136 Pragma_Ident => -1,
14137 Pragma_Implemented => -1,
14138 Pragma_Implicit_Packing => 0,
14139 Pragma_Import => +2,
14140 Pragma_Import_Exception => 0,
14141 Pragma_Import_Function => 0,
14142 Pragma_Import_Object => 0,
14143 Pragma_Import_Procedure => 0,
14144 Pragma_Import_Valued_Procedure => 0,
14145 Pragma_Independent => 0,
14146 Pragma_Independent_Components => 0,
14147 Pragma_Initialize_Scalars => -1,
14148 Pragma_Inline => 0,
14149 Pragma_Inline_Always => 0,
14150 Pragma_Inline_Generic => 0,
14151 Pragma_Inspection_Point => -1,
14152 Pragma_Interface => +2,
14153 Pragma_Interface_Name => +2,
14154 Pragma_Interrupt_Handler => -1,
14155 Pragma_Interrupt_Priority => -1,
14156 Pragma_Interrupt_State => -1,
14157 Pragma_Invariant => -1,
14158 Pragma_Java_Constructor => -1,
14159 Pragma_Java_Interface => -1,
14160 Pragma_Keep_Names => 0,
14161 Pragma_License => -1,
14162 Pragma_Link_With => -1,
14163 Pragma_Linker_Alias => -1,
14164 Pragma_Linker_Constructor => -1,
14165 Pragma_Linker_Destructor => -1,
14166 Pragma_Linker_Options => -1,
14167 Pragma_Linker_Section => -1,
14169 Pragma_Locking_Policy => -1,
14170 Pragma_Long_Float => -1,
14171 Pragma_Machine_Attribute => -1,
14173 Pragma_Main_Storage => -1,
14174 Pragma_Memory_Size => -1,
14175 Pragma_No_Return => 0,
14176 Pragma_No_Body => 0,
14177 Pragma_No_Run_Time => -1,
14178 Pragma_No_Strict_Aliasing => -1,
14179 Pragma_Normalize_Scalars => -1,
14180 Pragma_Obsolescent => 0,
14181 Pragma_Optimize => -1,
14182 Pragma_Optimize_Alignment => -1,
14183 Pragma_Ordered => 0,
14186 Pragma_Passive => -1,
14187 Pragma_Preelaborable_Initialization => -1,
14188 Pragma_Polling => -1,
14189 Pragma_Persistent_BSS => 0,
14190 Pragma_Postcondition => -1,
14191 Pragma_Precondition => -1,
14192 Pragma_Predicate => -1,
14193 Pragma_Preelaborate => -1,
14194 Pragma_Preelaborate_05 => -1,
14195 Pragma_Priority => -1,
14196 Pragma_Priority_Specific_Dispatching => -1,
14197 Pragma_Profile => 0,
14198 Pragma_Profile_Warnings => 0,
14199 Pragma_Propagate_Exceptions => -1,
14200 Pragma_Psect_Object => -1,
14202 Pragma_Pure_05 => -1,
14203 Pragma_Pure_Function => -1,
14204 Pragma_Queuing_Policy => -1,
14205 Pragma_Ravenscar => -1,
14206 Pragma_Relative_Deadline => -1,
14207 Pragma_Remote_Call_Interface => -1,
14208 Pragma_Remote_Types => -1,
14209 Pragma_Restricted_Run_Time => -1,
14210 Pragma_Restriction_Warnings => -1,
14211 Pragma_Restrictions => -1,
14212 Pragma_Reviewable => -1,
14213 Pragma_Short_Circuit_And_Or => -1,
14214 Pragma_Share_Generic => -1,
14215 Pragma_Shared => -1,
14216 Pragma_Shared_Passive => -1,
14217 Pragma_Short_Descriptors => 0,
14218 Pragma_Source_File_Name => -1,
14219 Pragma_Source_File_Name_Project => -1,
14220 Pragma_Source_Reference => -1,
14221 Pragma_Storage_Size => -1,
14222 Pragma_Storage_Unit => -1,
14223 Pragma_Static_Elaboration_Desired => -1,
14224 Pragma_Stream_Convert => -1,
14225 Pragma_Style_Checks => -1,
14226 Pragma_Subtitle => -1,
14227 Pragma_Suppress => 0,
14228 Pragma_Suppress_Exception_Locations => 0,
14229 Pragma_Suppress_All => -1,
14230 Pragma_Suppress_Debug_Info => 0,
14231 Pragma_Suppress_Initialization => 0,
14232 Pragma_System_Name => -1,
14233 Pragma_Task_Dispatching_Policy => -1,
14234 Pragma_Task_Info => -1,
14235 Pragma_Task_Name => -1,
14236 Pragma_Task_Storage => 0,
14237 Pragma_Thread_Local_Storage => 0,
14238 Pragma_Time_Slice => -1,
14239 Pragma_Title => -1,
14240 Pragma_Unchecked_Union => 0,
14241 Pragma_Unimplemented_Unit => -1,
14242 Pragma_Universal_Aliasing => -1,
14243 Pragma_Universal_Data => -1,
14244 Pragma_Unmodified => -1,
14245 Pragma_Unreferenced => -1,
14246 Pragma_Unreferenced_Objects => -1,
14247 Pragma_Unreserve_All_Interrupts => -1,
14248 Pragma_Unsuppress => 0,
14249 Pragma_Use_VADS_Size => -1,
14250 Pragma_Validity_Checks => -1,
14251 Pragma_Volatile => 0,
14252 Pragma_Volatile_Components => 0,
14253 Pragma_Warnings => -1,
14254 Pragma_Weak_External => -1,
14255 Pragma_Wide_Character_Encoding => 0,
14256 Unknown_Pragma => 0);
14258 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14267 if Nkind (P) /= N_Pragma_Argument_Association then
14271 Id := Get_Pragma_Id (Parent (P));
14272 C := Sig_Flags (Id);
14284 -- For pragma Check, the first argument is not significant,
14285 -- the second and the third (if present) arguments are
14288 when Pragma_Check =>
14290 P = First (Pragma_Argument_Associations (Parent (P)));
14293 raise Program_Error;
14297 A := First (Pragma_Argument_Associations (Parent (P)));
14298 for J in 1 .. C - 1 loop
14306 return A = P; -- is this wrong way round ???
14309 end Is_Non_Significant_Pragma_Reference;
14311 ------------------------------
14312 -- Is_Pragma_String_Literal --
14313 ------------------------------
14315 -- This function returns true if the corresponding pragma argument is a
14316 -- static string expression. These are the only cases in which string
14317 -- literals can appear as pragma arguments. We also allow a string literal
14318 -- as the first argument to pragma Assert (although it will of course
14319 -- always generate a type error).
14321 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14322 Pragn : constant Node_Id := Parent (Par);
14323 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14324 Pname : constant Name_Id := Pragma_Name (Pragn);
14330 N := First (Assoc);
14337 if Pname = Name_Assert then
14340 elsif Pname = Name_Export then
14343 elsif Pname = Name_Ident then
14346 elsif Pname = Name_Import then
14349 elsif Pname = Name_Interface_Name then
14352 elsif Pname = Name_Linker_Alias then
14355 elsif Pname = Name_Linker_Section then
14358 elsif Pname = Name_Machine_Attribute then
14361 elsif Pname = Name_Source_File_Name then
14364 elsif Pname = Name_Source_Reference then
14367 elsif Pname = Name_Title then
14370 elsif Pname = Name_Subtitle then
14376 end Is_Pragma_String_Literal;
14378 --------------------------------------
14379 -- Process_Compilation_Unit_Pragmas --
14380 --------------------------------------
14382 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14384 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14385 -- strange because it comes at the end of the unit. Rational has the
14386 -- same name for a pragma, but treats it as a program unit pragma, In
14387 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14388 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14389 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14390 -- the context clause to ensure the correct processing.
14392 if Has_Pragma_Suppress_All (N) then
14393 Prepend_To (Context_Items (N),
14394 Make_Pragma (Sloc (N),
14395 Chars => Name_Suppress,
14396 Pragma_Argument_Associations => New_List (
14397 Make_Pragma_Argument_Association (Sloc (N),
14398 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14401 -- Nothing else to do at the current time!
14403 end Process_Compilation_Unit_Pragmas;
14414 --------------------------------
14415 -- Set_Encoded_Interface_Name --
14416 --------------------------------
14418 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14419 Str : constant String_Id := Strval (S);
14420 Len : constant Int := String_Length (Str);
14425 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14428 -- Stores encoded value of character code CC. The encoding we use an
14429 -- underscore followed by four lower case hex digits.
14435 procedure Encode is
14437 Store_String_Char (Get_Char_Code ('_'));
14439 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14441 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14443 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14445 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14448 -- Start of processing for Set_Encoded_Interface_Name
14451 -- If first character is asterisk, this is a link name, and we leave it
14452 -- completely unmodified. We also ignore null strings (the latter case
14453 -- happens only in error cases) and no encoding should occur for Java or
14454 -- AAMP interface names.
14457 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14458 or else VM_Target /= No_VM
14459 or else AAMP_On_Target
14461 Set_Interface_Name (E, S);
14466 CC := Get_String_Char (Str, J);
14468 exit when not In_Character_Range (CC);
14470 C := Get_Character (CC);
14472 exit when C /= '_' and then C /= '$'
14473 and then C not in '0' .. '9'
14474 and then C not in 'a' .. 'z'
14475 and then C not in 'A' .. 'Z';
14478 Set_Interface_Name (E, S);
14486 -- Here we need to encode. The encoding we use as follows:
14487 -- three underscores + four hex digits (lower case)
14491 for J in 1 .. String_Length (Str) loop
14492 CC := Get_String_Char (Str, J);
14494 if not In_Character_Range (CC) then
14497 C := Get_Character (CC);
14499 if C = '_' or else C = '$'
14500 or else C in '0' .. '9'
14501 or else C in 'a' .. 'z'
14502 or else C in 'A' .. 'Z'
14504 Store_String_Char (CC);
14511 Set_Interface_Name (E,
14512 Make_String_Literal (Sloc (S),
14513 Strval => End_String));
14515 end Set_Encoded_Interface_Name;
14517 -------------------
14518 -- Set_Unit_Name --
14519 -------------------
14521 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14526 if Nkind (N) = N_Identifier
14527 and then Nkind (With_Item) = N_Identifier
14529 Set_Entity (N, Entity (With_Item));
14531 elsif Nkind (N) = N_Selected_Component then
14532 Change_Selected_Component_To_Expanded_Name (N);
14533 Set_Entity (N, Entity (With_Item));
14534 Set_Entity (Selector_Name (N), Entity (N));
14536 Pref := Prefix (N);
14537 Scop := Scope (Entity (N));
14538 while Nkind (Pref) = N_Selected_Component loop
14539 Change_Selected_Component_To_Expanded_Name (Pref);
14540 Set_Entity (Selector_Name (Pref), Scop);
14541 Set_Entity (Pref, Scop);
14542 Pref := Prefix (Pref);
14543 Scop := Scope (Scop);
14546 Set_Entity (Pref, Scop);