1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, 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 Aspects; use Aspects;
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Checks; use Checks;
36 with Csets; use Csets;
37 with Debug; use Debug;
38 with Einfo; use Einfo;
39 with Elists; use Elists;
40 with Errout; use Errout;
41 with Exp_Dist; use Exp_Dist;
42 with Exp_Util; use Exp_Util;
43 with Freeze; use Freeze;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet.Sp; use Namet.Sp;
48 with Nlists; use Nlists;
49 with Nmake; use Nmake;
51 with Output; use Output;
52 with Par_SCO; use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident; use Rident;
55 with Rtsfind; use Rtsfind;
57 with Sem_Aux; use Sem_Aux;
58 with Sem_Ch3; use Sem_Ch3;
59 with Sem_Ch6; use Sem_Ch6;
60 with Sem_Ch8; use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res; use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_VFpt; use Sem_VFpt;
73 with Sem_Warn; use Sem_Warn;
74 with Stand; use Stand;
75 with Sinfo; use Sinfo;
76 with Sinfo.CN; use Sinfo.CN;
77 with Sinput; use Sinput;
78 with Snames; use Snames;
79 with Stringt; use Stringt;
80 with Stylesw; use Stylesw;
82 with Targparm; use Targparm;
83 with Tbuild; use Tbuild;
85 with Uintp; use Uintp;
86 with Uname; use Uname;
87 with Urealp; use Urealp;
88 with Validsw; use Validsw;
89 with Warnsw; use Warnsw;
91 package body Sem_Prag is
93 ----------------------------------------------
94 -- Common Handling of Import-Export Pragmas --
95 ----------------------------------------------
97 -- In the following section, a number of Import_xxx and Export_xxx pragmas
98 -- are defined by GNAT. These are compatible with the DEC pragmas of the
99 -- same name, and all have the following common form and processing:
102 -- [Internal =>] LOCAL_NAME
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
107 -- [Internal =>] LOCAL_NAME
108 -- [, [External =>] EXTERNAL_SYMBOL]
109 -- [, other optional parameters ]);
111 -- EXTERNAL_SYMBOL ::=
113 -- | static_string_EXPRESSION
115 -- The internal LOCAL_NAME designates the entity that is imported or
116 -- exported, and must refer to an entity in the current declarative
117 -- part (as required by the rules for LOCAL_NAME).
119 -- The external linker name is designated by the External parameter if
120 -- given, or the Internal parameter if not (if there is no External
121 -- parameter, the External parameter is a copy of the Internal name).
123 -- If the External parameter is given as a string, then this string is
124 -- treated as an external name (exactly as though it had been given as an
125 -- External_Name parameter for a normal Import pragma).
127 -- If the External parameter is given as an identifier (or there is no
128 -- External parameter, so that the Internal identifier is used), then
129 -- the external name is the characters of the identifier, translated
130 -- to all upper case letters for OpenVMS versions of GNAT, and to all
131 -- lower case letters for all other versions
133 -- Note: the external name specified or implied by any of these special
134 -- Import_xxx or Export_xxx pragmas override an external or link name
135 -- specified in a previous Import or Export pragma.
137 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
138 -- named notation, following the standard rules for subprogram calls, i.e.
139 -- parameters can be given in any order if named notation is used, and
140 -- positional and named notation can be mixed, subject to the rule that all
141 -- positional parameters must appear first.
143 -- Note: All these pragmas are implemented exactly following the DEC design
144 -- and implementation and are intended to be fully compatible with the use
145 -- of these pragmas in the DEC Ada compiler.
147 --------------------------------------------
148 -- Checking for Duplicated External Names --
149 --------------------------------------------
151 -- It is suspicious if two separate Export pragmas use the same external
152 -- name. The following table is used to diagnose this situation so that
153 -- an appropriate warning can be issued.
155 -- The Node_Id stored is for the N_String_Literal node created to hold
156 -- the value of the external name. The Sloc of this node is used to
157 -- cross-reference the location of the duplication.
159 package Externals is new Table.Table (
160 Table_Component_Type => Node_Id,
161 Table_Index_Type => Int,
162 Table_Low_Bound => 0,
163 Table_Initial => 100,
164 Table_Increment => 100,
165 Table_Name => "Name_Externals");
167 -------------------------------------
168 -- Local Subprograms and Variables --
169 -------------------------------------
171 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
172 -- This routine is used for possible casing adjustment of an explicit
173 -- external name supplied as a string literal (the node N), according to
174 -- the casing requirement of Opt.External_Name_Casing. If this is set to
175 -- As_Is, then the string literal is returned unchanged, but if it is set
176 -- to Uppercase or Lowercase, then a new string literal with appropriate
177 -- casing is constructed.
179 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
180 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
181 -- original one, following the renaming chain) is returned. Otherwise the
182 -- entity is returned unchanged. Should be in Einfo???
184 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id);
185 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
186 -- of a Contract_Case or Test_Case pragma if present (possibly Empty). We
187 -- treat these as spec expressions (i.e. similar to a default expression).
190 -- This is a dummy function called by the processing for pragma Reviewable.
191 -- It is there for assisting front end debugging. By placing a Reviewable
192 -- pragma in the source program, a breakpoint on rv catches this place in
193 -- the source, allowing convenient stepping to the point of interest.
195 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
196 -- Place semantic information on the argument of an Elaborate/Elaborate_All
197 -- pragma. Entity name for unit and its parents is taken from item in
198 -- previous with_clause that mentions the unit.
200 -------------------------------
201 -- Adjust_External_Name_Case --
202 -------------------------------
204 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
208 -- Adjust case of literal if required
210 if Opt.External_Name_Exp_Casing = As_Is then
214 -- Copy existing string
220 for J in 1 .. String_Length (Strval (N)) loop
221 CC := Get_String_Char (Strval (N), J);
223 if Opt.External_Name_Exp_Casing = Uppercase
224 and then CC >= Get_Char_Code ('a')
225 and then CC <= Get_Char_Code ('z')
227 Store_String_Char (CC - 32);
229 elsif Opt.External_Name_Exp_Casing = Lowercase
230 and then CC >= Get_Char_Code ('A')
231 and then CC <= Get_Char_Code ('Z')
233 Store_String_Char (CC + 32);
236 Store_String_Char (CC);
241 Make_String_Literal (Sloc (N),
242 Strval => End_String);
244 end Adjust_External_Name_Case;
246 ------------------------------
247 -- Analyze_CTC_In_Decl_Part --
248 ------------------------------
250 procedure Analyze_CTC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
252 -- Install formals and push subprogram spec onto scope stack so that we
253 -- can see the formals from the pragma.
258 -- Preanalyze the boolean expressions, we treat these as spec
259 -- expressions (i.e. similar to a default expression).
263 Get_Requires_From_CTC_Pragma (N),
264 Get_Ensures_From_CTC_Pragma (N));
266 -- Remove the subprogram from the scope stack now that the pre-analysis
267 -- of the expressions in the contract case or test case is done.
270 end Analyze_CTC_In_Decl_Part;
272 ------------------------------
273 -- Analyze_PPC_In_Decl_Part --
274 ------------------------------
276 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
277 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
280 -- Install formals and push subprogram spec onto scope stack so that we
281 -- can see the formals from the pragma.
286 -- Preanalyze the boolean expression, we treat this as a spec expression
287 -- (i.e. similar to a default expression).
289 Preanalyze_Assert_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
291 -- In ASIS mode, for a pragma generated from a source aspect, also
292 -- analyze the original aspect expression.
295 and then Present (Corresponding_Aspect (N))
297 Preanalyze_Assert_Expression
298 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
301 -- For a class-wide condition, a reference to a controlling formal must
302 -- be interpreted as having the class-wide type (or an access to such)
303 -- so that the inherited condition can be properly applied to any
304 -- overriding operation (see ARM12 6.6.1 (7)).
306 if Class_Present (N) then
307 Class_Wide_Condition : declare
308 T : constant Entity_Id := Find_Dispatching_Type (S);
310 ACW : Entity_Id := Empty;
311 -- Access to T'class, created if there is a controlling formal
312 -- that is an access parameter.
314 function Get_ACW return Entity_Id;
315 -- If the expression has a reference to an controlling access
316 -- parameter, create an access to T'class for the necessary
317 -- conversions if one does not exist.
319 function Process (N : Node_Id) return Traverse_Result;
320 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
321 -- aspect for a primitive subprogram of a tagged type T, a name
322 -- that denotes a formal parameter of type T is interpreted as
323 -- having type T'Class. Similarly, a name that denotes a formal
324 -- accessparameter of type access-to-T is interpreted as having
325 -- type access-to-T'Class. This ensures the expression is well-
326 -- defined for a primitive subprogram of a type descended from T.
332 function Get_ACW return Entity_Id is
333 Loc : constant Source_Ptr := Sloc (N);
338 Decl := Make_Full_Type_Declaration (Loc,
339 Defining_Identifier => Make_Temporary (Loc, 'T'),
341 Make_Access_To_Object_Definition (Loc,
342 Subtype_Indication =>
343 New_Occurrence_Of (Class_Wide_Type (T), Loc),
344 All_Present => True));
346 Insert_Before (Unit_Declaration_Node (S), Decl);
348 ACW := Defining_Identifier (Decl);
349 Freeze_Before (Unit_Declaration_Node (S), ACW);
359 function Process (N : Node_Id) return Traverse_Result is
360 Loc : constant Source_Ptr := Sloc (N);
364 if Is_Entity_Name (N)
365 and then Is_Formal (Entity (N))
366 and then Nkind (Parent (N)) /= N_Type_Conversion
368 if Etype (Entity (N)) = T then
369 Typ := Class_Wide_Type (T);
371 elsif Is_Access_Type (Etype (Entity (N)))
372 and then Designated_Type (Etype (Entity (N))) = T
379 if Present (Typ) then
381 Make_Type_Conversion (Loc,
383 New_Occurrence_Of (Typ, Loc),
384 Expression => New_Occurrence_Of (Entity (N), Loc)));
392 procedure Replace_Type is new Traverse_Proc (Process);
394 -- Start of processing for Class_Wide_Condition
397 if not Present (T) then
399 Chars (Identifier (Corresponding_Aspect (N)));
401 Error_Msg_Name_2 := Name_Class;
404 ("aspect `%''%` can only be specified for a primitive " &
405 "operation of a tagged type",
406 Corresponding_Aspect (N));
409 Replace_Type (Get_Pragma_Arg (Arg1));
410 end Class_Wide_Condition;
413 -- Remove the subprogram from the scope stack now that the pre-analysis
414 -- of the precondition/postcondition is done.
417 end Analyze_PPC_In_Decl_Part;
423 procedure Analyze_Pragma (N : Node_Id) is
424 Loc : constant Source_Ptr := Sloc (N);
428 -- Name of the source pragma, or name of the corresponding aspect for
429 -- pragmas which originate in a source aspect. In the latter case, the
430 -- name may be different from the pragma name.
432 Pragma_Exit : exception;
433 -- This exception is used to exit pragma processing completely. It is
434 -- used when an error is detected, and no further processing is
435 -- required. It is also used if an earlier error has left the tree in
436 -- a state where the pragma should not be processed.
439 -- Number of pragma argument associations
445 -- First four pragma arguments (pragma argument association nodes, or
446 -- Empty if the corresponding argument does not exist).
448 type Name_List is array (Natural range <>) of Name_Id;
449 type Args_List is array (Natural range <>) of Node_Id;
450 -- Types used for arguments to Check_Arg_Order and Gather_Associations
452 procedure Ada_2005_Pragma;
453 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
454 -- Ada 95 mode, these are implementation defined pragmas, so should be
455 -- caught by the No_Implementation_Pragmas restriction.
457 procedure Ada_2012_Pragma;
458 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
459 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
460 -- should be caught by the No_Implementation_Pragmas restriction.
462 procedure Check_Ada_83_Warning;
463 -- Issues a warning message for the current pragma if operating in Ada
464 -- 83 mode (used for language pragmas that are not a standard part of
465 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
468 procedure Check_Arg_Count (Required : Nat);
469 -- Check argument count for pragma is equal to given parameter. If not,
470 -- then issue an error message and raise Pragma_Exit.
472 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
473 -- Arg which can either be a pragma argument association, in which case
474 -- the check is applied to the expression of the association or an
475 -- expression directly.
477 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
478 -- Check that an argument has the right form for an EXTERNAL_NAME
479 -- parameter of an extended import/export pragma. The rule is that the
480 -- name must be an identifier or string literal (in Ada 83 mode) or a
481 -- static string expression (in Ada 95 mode).
483 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
484 -- Check the specified argument Arg to make sure that it is an
485 -- identifier. If not give error and raise Pragma_Exit.
487 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
488 -- Check the specified argument Arg to make sure that it is an integer
489 -- literal. If not give error and raise Pragma_Exit.
491 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
492 -- Check the specified argument Arg to make sure that it has the proper
493 -- syntactic form for a local name and meets the semantic requirements
494 -- for a local name. The local name is analyzed as part of the
495 -- processing for this call. In addition, the local name is required
496 -- to represent an entity at the library level.
498 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
499 -- Check the specified argument Arg to make sure that it has the proper
500 -- syntactic form for a local name and meets the semantic requirements
501 -- for a local name. The local name is analyzed as part of the
502 -- processing for this call.
504 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
505 -- Check the specified argument Arg to make sure that it is a valid
506 -- locking policy name. If not give error and raise Pragma_Exit.
508 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
509 -- Check the specified argument Arg to make sure that it is a valid
510 -- elaboration policy name. If not give error and raise Pragma_Exit.
512 procedure Check_Arg_Is_One_Of
515 procedure Check_Arg_Is_One_Of
517 N1, N2, N3 : Name_Id);
518 procedure Check_Arg_Is_One_Of
520 N1, N2, N3, N4 : Name_Id);
521 procedure Check_Arg_Is_One_Of
523 N1, N2, N3, N4, N5 : Name_Id);
524 -- Check the specified argument Arg to make sure that it is an
525 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
526 -- present). If not then give error and raise Pragma_Exit.
528 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
529 -- Check the specified argument Arg to make sure that it is a valid
530 -- queuing policy name. If not give error and raise Pragma_Exit.
532 procedure Check_Arg_Is_Static_Expression
534 Typ : Entity_Id := Empty);
535 -- Check the specified argument Arg to make sure that it is a static
536 -- expression of the given type (i.e. it will be analyzed and resolved
537 -- using this type, which can be any valid argument to Resolve, e.g.
538 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
539 -- Typ is left Empty, then any static expression is allowed.
541 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
542 -- Check the specified argument Arg to make sure that it is a valid task
543 -- dispatching policy name. If not give error and raise Pragma_Exit.
545 procedure Check_Arg_Order (Names : Name_List);
546 -- Checks for an instance of two arguments with identifiers for the
547 -- current pragma which are not in the sequence indicated by Names,
548 -- and if so, generates a fatal message about bad order of arguments.
550 procedure Check_At_Least_N_Arguments (N : Nat);
551 -- Check there are at least N arguments present
553 procedure Check_At_Most_N_Arguments (N : Nat);
554 -- Check there are no more than N arguments present
556 procedure Check_Component
559 In_Variant_Part : Boolean := False);
560 -- Examine an Unchecked_Union component for correct use of per-object
561 -- constrained subtypes, and for restrictions on finalizable components.
562 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
563 -- should be set when Comp comes from a record variant.
565 procedure Check_Contract_Or_Test_Case;
566 -- Called to process a contract-case or test-case pragma. It
567 -- starts with checking pragma arguments, and the rest of the
568 -- treatment is similar to the one for pre- and postcondition in
569 -- Check_Precondition_Postcondition, except the placement rules for the
570 -- contract-case and test-case pragmas are stricter. These pragmas may
571 -- only occur after a subprogram spec declared directly in a package
572 -- spec unit. In this case, the pragma is chained to the subprogram in
573 -- question (using Spec_CTC_List and Next_Pragma) and analysis of the
574 -- pragma is delayed till the end of the spec. In all other cases, an
575 -- error message for bad placement is given.
577 procedure Check_Duplicate_Pragma (E : Entity_Id);
578 -- Check if a rep item of the same name as the current pragma is already
579 -- chained as a rep pragma to the given entity. If so give a message
580 -- about the duplicate, and then raise Pragma_Exit so does not return.
582 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
583 -- Nam is an N_String_Literal node containing the external name set by
584 -- an Import or Export pragma (or extended Import or Export pragma).
585 -- This procedure checks for possible duplications if this is the export
586 -- case, and if found, issues an appropriate error message.
588 procedure Check_Expr_Is_Static_Expression
590 Typ : Entity_Id := Empty);
591 -- Check the specified expression Expr to make sure that it is a static
592 -- expression of the given type (i.e. it will be analyzed and resolved
593 -- using this type, which can be any valid argument to Resolve, e.g.
594 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
595 -- Typ is left Empty, then any static expression is allowed.
597 procedure Check_First_Subtype (Arg : Node_Id);
598 -- Checks that Arg, whose expression is an entity name, references a
601 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
602 -- Checks that the given argument has an identifier, and if so, requires
603 -- it to match the given identifier name. If there is no identifier, or
604 -- a non-matching identifier, then an error message is given and
605 -- Pragma_Exit is raised.
607 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
608 -- Checks that the given argument has an identifier, and if so, requires
609 -- it to match one of the given identifier names. If there is no
610 -- identifier, or a non-matching identifier, then an error message is
611 -- given and Pragma_Exit is raised.
613 procedure Check_In_Main_Program;
614 -- Common checks for pragmas that appear within a main program
615 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
617 procedure Check_Interrupt_Or_Attach_Handler;
618 -- Common processing for first argument of pragma Interrupt_Handler or
619 -- pragma Attach_Handler.
621 procedure Check_Loop_Invariant_Variant_Placement;
622 -- Verify whether pragma Loop_Invariant or pragma Loop_Variant appear
623 -- immediately within a construct restricted to loops.
625 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
626 -- Check that pragma appears in a declarative part, or in a package
627 -- specification, i.e. that it does not occur in a statement sequence
630 procedure Check_No_Identifier (Arg : Node_Id);
631 -- Checks that the given argument does not have an identifier. If
632 -- an identifier is present, then an error message is issued, and
633 -- Pragma_Exit is raised.
635 procedure Check_No_Identifiers;
636 -- Checks that none of the arguments to the pragma has an identifier.
637 -- If any argument has an identifier, then an error message is issued,
638 -- and Pragma_Exit is raised.
640 procedure Check_No_Link_Name;
641 -- Checks that no link name is specified
643 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
644 -- Checks if the given argument has an identifier, and if so, requires
645 -- it to match the given identifier name. If there is a non-matching
646 -- identifier, then an error message is given and Pragma_Exit is raised.
648 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
649 -- Checks if the given argument has an identifier, and if so, requires
650 -- it to match the given identifier name. If there is a non-matching
651 -- identifier, then an error message is given and Pragma_Exit is raised.
652 -- In this version of the procedure, the identifier name is given as
653 -- a string with lower case letters.
655 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
656 -- Called to process a precondition or postcondition pragma. There are
659 -- The pragma appears after a subprogram spec
661 -- If the corresponding check is not enabled, the pragma is analyzed
662 -- but otherwise ignored and control returns with In_Body set False.
664 -- If the check is enabled, then the first step is to analyze the
665 -- pragma, but this is skipped if the subprogram spec appears within
666 -- a package specification (because this is the case where we delay
667 -- analysis till the end of the spec). Then (whether or not it was
668 -- analyzed), the pragma is chained to the subprogram in question
669 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
670 -- caller with In_Body set False.
672 -- The pragma appears at the start of subprogram body declarations
674 -- In this case an immediate return to the caller is made with
675 -- In_Body set True, and the pragma is NOT analyzed.
677 -- In all other cases, an error message for bad placement is given
679 procedure Check_Static_Constraint (Constr : Node_Id);
680 -- Constr is a constraint from an N_Subtype_Indication node from a
681 -- component constraint in an Unchecked_Union type. This routine checks
682 -- that the constraint is static as required by the restrictions for
685 procedure Check_Valid_Configuration_Pragma;
686 -- Legality checks for placement of a configuration pragma
688 procedure Check_Valid_Library_Unit_Pragma;
689 -- Legality checks for library unit pragmas. A special case arises for
690 -- pragmas in generic instances that come from copies of the original
691 -- library unit pragmas in the generic templates. In the case of other
692 -- than library level instantiations these can appear in contexts which
693 -- would normally be invalid (they only apply to the original template
694 -- and to library level instantiations), and they are simply ignored,
695 -- which is implemented by rewriting them as null statements.
697 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
698 -- Check an Unchecked_Union variant for lack of nested variants and
699 -- presence of at least one component. UU_Typ is the related Unchecked_
702 procedure Error_Pragma (Msg : String);
703 pragma No_Return (Error_Pragma);
704 -- Outputs error message for current pragma. The message contains a %
705 -- that will be replaced with the pragma name, and the flag is placed
706 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
707 -- calls Fix_Error (see spec of that function for details).
709 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
710 pragma No_Return (Error_Pragma_Arg);
711 -- Outputs error message for current pragma. The message may contain
712 -- a % that will be replaced with the pragma name. The parameter Arg
713 -- may either be a pragma argument association, in which case the flag
714 -- is placed on the expression of this association, or an expression,
715 -- in which case the flag is placed directly on the expression. The
716 -- message is placed using Error_Msg_N, so the message may also contain
717 -- an & insertion character which will reference the given Arg value.
718 -- After placing the message, Pragma_Exit is raised. Note: this routine
719 -- calls Fix_Error (see spec of that function for details).
721 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
722 pragma No_Return (Error_Pragma_Arg);
723 -- Similar to above form of Error_Pragma_Arg except that two messages
724 -- are provided, the second is a continuation comment starting with \.
726 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
727 pragma No_Return (Error_Pragma_Arg_Ident);
728 -- Outputs error message for current pragma. The message may contain
729 -- a % that will be replaced with the pragma name. The parameter Arg
730 -- must be a pragma argument association with a non-empty identifier
731 -- (i.e. its Chars field must be set), and the error message is placed
732 -- on the identifier. The message is placed using Error_Msg_N so
733 -- the message may also contain an & insertion character which will
734 -- reference the identifier. After placing the message, Pragma_Exit
735 -- is raised. Note: this routine calls Fix_Error (see spec of that
736 -- function for details).
738 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
739 pragma No_Return (Error_Pragma_Ref);
740 -- Outputs error message for current pragma. The message may contain
741 -- a % that will be replaced with the pragma name. The parameter Ref
742 -- must be an entity whose name can be referenced by & and sloc by #.
743 -- After placing the message, Pragma_Exit is raised. Note: this routine
744 -- calls Fix_Error (see spec of that function for details).
746 function Find_Lib_Unit_Name return Entity_Id;
747 -- Used for a library unit pragma to find the entity to which the
748 -- library unit pragma applies, returns the entity found.
750 procedure Find_Program_Unit_Name (Id : Node_Id);
751 -- If the pragma is a compilation unit pragma, the id must denote the
752 -- compilation unit in the same compilation, and the pragma must appear
753 -- in the list of preceding or trailing pragmas. If it is a program
754 -- unit pragma that is not a compilation unit pragma, then the
755 -- identifier must be visible.
757 function Find_Unique_Parameterless_Procedure
759 Arg : Node_Id) return Entity_Id;
760 -- Used for a procedure pragma to find the unique parameterless
761 -- procedure identified by Name, returns it if it exists, otherwise
762 -- errors out and uses Arg as the pragma argument for the message.
764 procedure Fix_Error (Msg : in out String);
765 -- This is called prior to issuing an error message. Msg is a string
766 -- that typically contains the substring "pragma". If the current pragma
767 -- comes from an aspect, each such "pragma" substring is replaced with
768 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
769 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
771 procedure Gather_Associations
773 Args : out Args_List);
774 -- This procedure is used to gather the arguments for a pragma that
775 -- permits arbitrary ordering of parameters using the normal rules
776 -- for named and positional parameters. The Names argument is a list
777 -- of Name_Id values that corresponds to the allowed pragma argument
778 -- association identifiers in order. The result returned in Args is
779 -- a list of corresponding expressions that are the pragma arguments.
780 -- Note that this is a list of expressions, not of pragma argument
781 -- associations (Gather_Associations has completely checked all the
782 -- optional identifiers when it returns). An entry in Args is Empty
783 -- on return if the corresponding argument is not present.
785 procedure GNAT_Pragma;
786 -- Called for all GNAT defined pragmas to check the relevant restriction
787 -- (No_Implementation_Pragmas).
789 procedure S14_Pragma;
790 -- Called for all pragmas defined for formal verification to check that
791 -- the S14_Extensions flag is set.
793 function Is_Before_First_Decl
794 (Pragma_Node : Node_Id;
795 Decls : List_Id) return Boolean;
796 -- Return True if Pragma_Node is before the first declarative item in
797 -- Decls where Decls is the list of declarative items.
799 function Is_Configuration_Pragma return Boolean;
800 -- Determines if the placement of the current pragma is appropriate
801 -- for a configuration pragma.
803 function Is_In_Context_Clause return Boolean;
804 -- Returns True if pragma appears within the context clause of a unit,
805 -- and False for any other placement (does not generate any messages).
807 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
808 -- Analyzes the argument, and determines if it is a static string
809 -- expression, returns True if so, False if non-static or not String.
811 procedure Pragma_Misplaced;
812 pragma No_Return (Pragma_Misplaced);
813 -- Issue fatal error message for misplaced pragma
815 procedure Process_Atomic_Shared_Volatile;
816 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
817 -- Shared is an obsolete Ada 83 pragma, treated as being identical
818 -- in effect to pragma Atomic.
820 procedure Process_Compile_Time_Warning_Or_Error;
821 -- Common processing for Compile_Time_Error and Compile_Time_Warning
823 procedure Process_Convention
824 (C : out Convention_Id;
825 Ent : out Entity_Id);
826 -- Common processing for Convention, Interface, Import and Export.
827 -- Checks first two arguments of pragma, and sets the appropriate
828 -- convention value in the specified entity or entities. On return
829 -- C is the convention, Ent is the referenced entity.
831 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
832 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
833 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
835 procedure Process_Extended_Import_Export_Exception_Pragma
836 (Arg_Internal : Node_Id;
837 Arg_External : Node_Id;
840 -- Common processing for the pragmas Import/Export_Exception. The three
841 -- arguments correspond to the three named parameters of the pragma. An
842 -- argument is empty if the corresponding parameter is not present in
845 procedure Process_Extended_Import_Export_Object_Pragma
846 (Arg_Internal : Node_Id;
847 Arg_External : Node_Id;
849 -- Common processing for the pragmas Import/Export_Object. The three
850 -- arguments correspond to the three named parameters of the pragmas. An
851 -- argument is empty if the corresponding parameter is not present in
854 procedure Process_Extended_Import_Export_Internal_Arg
855 (Arg_Internal : Node_Id := Empty);
856 -- Common processing for all extended Import and Export pragmas. The
857 -- argument is the pragma parameter for the Internal argument. If
858 -- Arg_Internal is empty or inappropriate, an error message is posted.
859 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
860 -- set to identify the referenced entity.
862 procedure Process_Extended_Import_Export_Subprogram_Pragma
863 (Arg_Internal : Node_Id;
864 Arg_External : Node_Id;
865 Arg_Parameter_Types : Node_Id;
866 Arg_Result_Type : Node_Id := Empty;
867 Arg_Mechanism : Node_Id;
868 Arg_Result_Mechanism : Node_Id := Empty;
869 Arg_First_Optional_Parameter : Node_Id := Empty);
870 -- Common processing for all extended Import and Export pragmas applying
871 -- to subprograms. The caller omits any arguments that do not apply to
872 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
873 -- only in the Import_Function and Export_Function cases). The argument
874 -- names correspond to the allowed pragma association identifiers.
876 procedure Process_Generic_List;
877 -- Common processing for Share_Generic and Inline_Generic
879 procedure Process_Import_Or_Interface;
880 -- Common processing for Import of Interface
882 procedure Process_Import_Predefined_Type;
883 -- Processing for completing a type with pragma Import. This is used
884 -- to declare types that match predefined C types, especially for cases
885 -- without corresponding Ada predefined type.
887 procedure Process_Inline (Active : Boolean);
888 -- Common processing for Inline and Inline_Always. The parameter
889 -- indicates if the inline pragma is active, i.e. if it should actually
890 -- cause inlining to occur.
892 procedure Process_Interface_Name
893 (Subprogram_Def : Entity_Id;
896 -- Given the last two arguments of pragma Import, pragma Export, or
897 -- pragma Interface_Name, performs validity checks and sets the
898 -- Interface_Name field of the given subprogram entity to the
899 -- appropriate external or link name, depending on the arguments given.
900 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
901 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
902 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
903 -- nor Link_Arg is present, the interface name is set to the default
904 -- from the subprogram name.
906 procedure Process_Interrupt_Or_Attach_Handler;
907 -- Common processing for Interrupt and Attach_Handler pragmas
909 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
910 -- Common processing for Restrictions and Restriction_Warnings pragmas.
911 -- Warn is True for Restriction_Warnings, or for Restrictions if the
912 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
913 -- is not set in the Restrictions case.
915 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
916 -- Common processing for Suppress and Unsuppress. The boolean parameter
917 -- Suppress_Case is True for the Suppress case, and False for the
920 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
921 -- This procedure sets the Is_Exported flag for the given entity,
922 -- checking that the entity was not previously imported. Arg is
923 -- the argument that specified the entity. A check is also made
924 -- for exporting inappropriate entities.
926 procedure Set_Extended_Import_Export_External_Name
927 (Internal_Ent : Entity_Id;
928 Arg_External : Node_Id);
929 -- Common processing for all extended import export pragmas. The first
930 -- argument, Internal_Ent, is the internal entity, which has already
931 -- been checked for validity by the caller. Arg_External is from the
932 -- Import or Export pragma, and may be null if no External parameter
933 -- was present. If Arg_External is present and is a non-null string
934 -- (a null string is treated as the default), then the Interface_Name
935 -- field of Internal_Ent is set appropriately.
937 procedure Set_Imported (E : Entity_Id);
938 -- This procedure sets the Is_Imported flag for the given entity,
939 -- checking that it is not previously exported or imported.
941 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
942 -- Mech is a parameter passing mechanism (see Import_Function syntax
943 -- for MECHANISM_NAME). This routine checks that the mechanism argument
944 -- has the right form, and if not issues an error message. If the
945 -- argument has the right form then the Mechanism field of Ent is
946 -- set appropriately.
948 procedure Set_Ravenscar_Profile (N : Node_Id);
949 -- Activate the set of configuration pragmas and restrictions that make
950 -- up the Ravenscar Profile. N is the corresponding pragma node, which
951 -- is used for error messages on any constructs that violate the
954 ---------------------
955 -- Ada_2005_Pragma --
956 ---------------------
958 procedure Ada_2005_Pragma is
960 if Ada_Version <= Ada_95 then
961 Check_Restriction (No_Implementation_Pragmas, N);
965 ---------------------
966 -- Ada_2012_Pragma --
967 ---------------------
969 procedure Ada_2012_Pragma is
971 if Ada_Version <= Ada_2005 then
972 Check_Restriction (No_Implementation_Pragmas, N);
976 --------------------------
977 -- Check_Ada_83_Warning --
978 --------------------------
980 procedure Check_Ada_83_Warning is
982 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
983 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
985 end Check_Ada_83_Warning;
987 ---------------------
988 -- Check_Arg_Count --
989 ---------------------
991 procedure Check_Arg_Count (Required : Nat) is
993 if Arg_Count /= Required then
994 Error_Pragma ("wrong number of arguments for pragma%");
998 --------------------------------
999 -- Check_Arg_Is_External_Name --
1000 --------------------------------
1002 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
1003 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1006 if Nkind (Argx) = N_Identifier then
1010 Analyze_And_Resolve (Argx, Standard_String);
1012 if Is_OK_Static_Expression (Argx) then
1015 elsif Etype (Argx) = Any_Type then
1018 -- An interesting special case, if we have a string literal and
1019 -- we are in Ada 83 mode, then we allow it even though it will
1020 -- not be flagged as static. This allows expected Ada 83 mode
1021 -- use of external names which are string literals, even though
1022 -- technically these are not static in Ada 83.
1024 elsif Ada_Version = Ada_83
1025 and then Nkind (Argx) = N_String_Literal
1029 -- Static expression that raises Constraint_Error. This has
1030 -- already been flagged, so just exit from pragma processing.
1032 elsif Is_Static_Expression (Argx) then
1035 -- Here we have a real error (non-static expression)
1038 Error_Msg_Name_1 := Pname;
1042 "argument for pragma% must be a identifier or "
1043 & "static string expression!";
1046 Flag_Non_Static_Expr (Msg, Argx);
1051 end Check_Arg_Is_External_Name;
1053 -----------------------------
1054 -- Check_Arg_Is_Identifier --
1055 -----------------------------
1057 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
1058 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1060 if Nkind (Argx) /= N_Identifier then
1062 ("argument for pragma% must be identifier", Argx);
1064 end Check_Arg_Is_Identifier;
1066 ----------------------------------
1067 -- Check_Arg_Is_Integer_Literal --
1068 ----------------------------------
1070 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1071 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1073 if Nkind (Argx) /= N_Integer_Literal then
1075 ("argument for pragma% must be integer literal", Argx);
1077 end Check_Arg_Is_Integer_Literal;
1079 -------------------------------------------
1080 -- Check_Arg_Is_Library_Level_Local_Name --
1081 -------------------------------------------
1085 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1086 -- | library_unit_NAME
1088 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1090 Check_Arg_Is_Local_Name (Arg);
1092 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1093 and then Comes_From_Source (N)
1096 ("argument for pragma% must be library level entity", Arg);
1098 end Check_Arg_Is_Library_Level_Local_Name;
1100 -----------------------------
1101 -- Check_Arg_Is_Local_Name --
1102 -----------------------------
1106 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1107 -- | library_unit_NAME
1109 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1110 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1115 if Nkind (Argx) not in N_Direct_Name
1116 and then (Nkind (Argx) /= N_Attribute_Reference
1117 or else Present (Expressions (Argx))
1118 or else Nkind (Prefix (Argx)) /= N_Identifier)
1119 and then (not Is_Entity_Name (Argx)
1120 or else not Is_Compilation_Unit (Entity (Argx)))
1122 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1125 -- No further check required if not an entity name
1127 if not Is_Entity_Name (Argx) then
1133 Ent : constant Entity_Id := Entity (Argx);
1134 Scop : constant Entity_Id := Scope (Ent);
1136 -- Case of a pragma applied to a compilation unit: pragma must
1137 -- occur immediately after the program unit in the compilation.
1139 if Is_Compilation_Unit (Ent) then
1141 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1144 -- Case of pragma placed immediately after spec
1146 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1149 -- Case of pragma placed immediately after body
1151 elsif Nkind (Decl) = N_Subprogram_Declaration
1152 and then Present (Corresponding_Body (Decl))
1156 (Parent (Unit_Declaration_Node
1157 (Corresponding_Body (Decl))));
1159 -- All other cases are illegal
1166 -- Special restricted placement rule from 10.2.1(11.8/2)
1168 elsif Is_Generic_Formal (Ent)
1169 and then Prag_Id = Pragma_Preelaborable_Initialization
1171 OK := List_Containing (N) =
1172 Generic_Formal_Declarations
1173 (Unit_Declaration_Node (Scop));
1175 -- Default case, just check that the pragma occurs in the scope
1176 -- of the entity denoted by the name.
1179 OK := Current_Scope = Scop;
1184 ("pragma% argument must be in same declarative part", Arg);
1188 end Check_Arg_Is_Local_Name;
1190 ---------------------------------
1191 -- Check_Arg_Is_Locking_Policy --
1192 ---------------------------------
1194 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1195 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1198 Check_Arg_Is_Identifier (Argx);
1200 if not Is_Locking_Policy_Name (Chars (Argx)) then
1201 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1203 end Check_Arg_Is_Locking_Policy;
1205 -----------------------------------------------
1206 -- Check_Arg_Is_Partition_Elaboration_Policy --
1207 -----------------------------------------------
1209 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
1210 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1213 Check_Arg_Is_Identifier (Argx);
1215 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
1217 ("& is not a valid partition elaboration policy name", Argx);
1219 end Check_Arg_Is_Partition_Elaboration_Policy;
1221 -------------------------
1222 -- Check_Arg_Is_One_Of --
1223 -------------------------
1225 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1226 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1229 Check_Arg_Is_Identifier (Argx);
1231 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1232 Error_Msg_Name_2 := N1;
1233 Error_Msg_Name_3 := N2;
1234 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1236 end Check_Arg_Is_One_Of;
1238 procedure Check_Arg_Is_One_Of
1240 N1, N2, N3 : Name_Id)
1242 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1245 Check_Arg_Is_Identifier (Argx);
1247 if Chars (Argx) /= N1
1248 and then Chars (Argx) /= N2
1249 and then Chars (Argx) /= N3
1251 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1253 end Check_Arg_Is_One_Of;
1255 procedure Check_Arg_Is_One_Of
1257 N1, N2, N3, N4 : Name_Id)
1259 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1262 Check_Arg_Is_Identifier (Argx);
1264 if Chars (Argx) /= N1
1265 and then Chars (Argx) /= N2
1266 and then Chars (Argx) /= N3
1267 and then Chars (Argx) /= N4
1269 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1271 end Check_Arg_Is_One_Of;
1273 procedure Check_Arg_Is_One_Of
1275 N1, N2, N3, N4, N5 : Name_Id)
1277 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1280 Check_Arg_Is_Identifier (Argx);
1282 if Chars (Argx) /= N1
1283 and then Chars (Argx) /= N2
1284 and then Chars (Argx) /= N3
1285 and then Chars (Argx) /= N4
1286 and then Chars (Argx) /= N5
1288 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1290 end Check_Arg_Is_One_Of;
1292 ---------------------------------
1293 -- Check_Arg_Is_Queuing_Policy --
1294 ---------------------------------
1296 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1297 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1300 Check_Arg_Is_Identifier (Argx);
1302 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1303 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1305 end Check_Arg_Is_Queuing_Policy;
1307 ------------------------------------
1308 -- Check_Arg_Is_Static_Expression --
1309 ------------------------------------
1311 procedure Check_Arg_Is_Static_Expression
1313 Typ : Entity_Id := Empty)
1316 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1317 end Check_Arg_Is_Static_Expression;
1319 ------------------------------------------
1320 -- Check_Arg_Is_Task_Dispatching_Policy --
1321 ------------------------------------------
1323 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1324 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1327 Check_Arg_Is_Identifier (Argx);
1329 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1331 ("& is not a valid task dispatching policy name", Argx);
1333 end Check_Arg_Is_Task_Dispatching_Policy;
1335 ---------------------
1336 -- Check_Arg_Order --
1337 ---------------------
1339 procedure Check_Arg_Order (Names : Name_List) is
1342 Highest_So_Far : Natural := 0;
1343 -- Highest index in Names seen do far
1347 for J in 1 .. Arg_Count loop
1348 if Chars (Arg) /= No_Name then
1349 for K in Names'Range loop
1350 if Chars (Arg) = Names (K) then
1351 if K < Highest_So_Far then
1352 Error_Msg_Name_1 := Pname;
1354 ("parameters out of order for pragma%", Arg);
1355 Error_Msg_Name_1 := Names (K);
1356 Error_Msg_Name_2 := Names (Highest_So_Far);
1357 Error_Msg_N ("\% must appear before %", Arg);
1361 Highest_So_Far := K;
1369 end Check_Arg_Order;
1371 --------------------------------
1372 -- Check_At_Least_N_Arguments --
1373 --------------------------------
1375 procedure Check_At_Least_N_Arguments (N : Nat) is
1377 if Arg_Count < N then
1378 Error_Pragma ("too few arguments for pragma%");
1380 end Check_At_Least_N_Arguments;
1382 -------------------------------
1383 -- Check_At_Most_N_Arguments --
1384 -------------------------------
1386 procedure Check_At_Most_N_Arguments (N : Nat) is
1389 if Arg_Count > N then
1391 for J in 1 .. N loop
1393 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1396 end Check_At_Most_N_Arguments;
1398 ---------------------
1399 -- Check_Component --
1400 ---------------------
1402 procedure Check_Component
1405 In_Variant_Part : Boolean := False)
1407 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1408 Sindic : constant Node_Id :=
1409 Subtype_Indication (Component_Definition (Comp));
1410 Typ : constant Entity_Id := Etype (Comp_Id);
1413 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1414 -- object constraint, then the component type shall be an Unchecked_
1417 if Nkind (Sindic) = N_Subtype_Indication
1418 and then Has_Per_Object_Constraint (Comp_Id)
1419 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1422 ("component subtype subject to per-object constraint " &
1423 "must be an Unchecked_Union", Comp);
1425 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1426 -- the body of a generic unit, or within the body of any of its
1427 -- descendant library units, no part of the type of a component
1428 -- declared in a variant_part of the unchecked union type shall be of
1429 -- a formal private type or formal private extension declared within
1430 -- the formal part of the generic unit.
1432 elsif Ada_Version >= Ada_2012
1433 and then In_Generic_Body (UU_Typ)
1434 and then In_Variant_Part
1435 and then Is_Private_Type (Typ)
1436 and then Is_Generic_Type (Typ)
1439 ("component of unchecked union cannot be of generic type", Comp);
1441 elsif Needs_Finalization (Typ) then
1443 ("component of unchecked union cannot be controlled", Comp);
1445 elsif Has_Task (Typ) then
1447 ("component of unchecked union cannot have tasks", Comp);
1449 end Check_Component;
1451 ---------------------------------
1452 -- Check_Contract_Or_Test_Case --
1453 ---------------------------------
1455 procedure Check_Contract_Or_Test_Case is
1459 procedure Chain_CTC (PO : Node_Id);
1460 -- If PO is a [generic] subprogram declaration node, then the
1461 -- contract-case or test-case applies to this subprogram and the
1462 -- processing for the pragma is completed. Otherwise the pragma
1469 procedure Chain_CTC (PO : Node_Id) is
1473 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1475 ("pragma% cannot be applied to abstract subprogram");
1477 elsif Nkind (PO) = N_Entry_Declaration then
1478 Error_Pragma ("pragma% cannot be applied to entry");
1480 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1481 N_Generic_Subprogram_Declaration)
1486 -- Here if we have [generic] subprogram declaration
1488 S := Defining_Unit_Name (Specification (PO));
1490 -- Note: we do not analyze the pragma at this point. Instead we
1491 -- delay this analysis until the end of the declarative part in
1492 -- which the pragma appears. This implements the required delay
1493 -- in this analysis, allowing forward references. The analysis
1494 -- happens at the end of Analyze_Declarations.
1496 -- There should not be another contract-case or test-case with the
1497 -- same name associated to this subprogram.
1500 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
1504 CTC := Spec_CTC_List (Contract (S));
1505 while Present (CTC) loop
1507 -- Omit pragma Contract_Cases because it does not introduce
1508 -- a unique case name and it does not follow the syntax of
1509 -- Contract_Case and Test_Case.
1511 if Pragma_Name (CTC) = Name_Contract_Cases then
1515 (Name, Get_Name_From_CTC_Pragma (CTC))
1517 Error_Msg_Sloc := Sloc (CTC);
1518 Error_Pragma ("name for pragma% is already used#");
1521 CTC := Next_Pragma (CTC);
1525 -- Chain spec CTC pragma to list for subprogram
1527 Set_Next_Pragma (N, Spec_CTC_List (Contract (S)));
1528 Set_Spec_CTC_List (Contract (S), N);
1531 -- Start of processing for Check_Contract_Or_Test_Case
1534 -- First check pragma arguments
1537 Check_At_Least_N_Arguments (2);
1538 Check_At_Most_N_Arguments (4);
1540 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
1542 Check_Optional_Identifier (Arg1, Name_Name);
1543 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
1545 -- In ASIS mode, for a pragma generated from a source aspect, also
1546 -- analyze the original aspect expression.
1549 and then Present (Corresponding_Aspect (N))
1551 Check_Expr_Is_Static_Expression
1552 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
1555 Check_Optional_Identifier (Arg2, Name_Mode);
1556 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
1558 if Arg_Count = 4 then
1559 Check_Identifier (Arg3, Name_Requires);
1560 Check_Identifier (Arg4, Name_Ensures);
1562 elsif Arg_Count = 3 then
1563 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
1566 -- Check pragma placement
1568 if not Is_List_Member (N) then
1572 -- Contract-case or test-case should only appear in package spec unit
1574 if Get_Source_Unit (N) = No_Unit
1575 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
1576 N_Package_Declaration,
1577 N_Generic_Package_Declaration)
1582 -- Search prior declarations
1585 while Present (Prev (P)) loop
1588 -- If the previous node is a generic subprogram, do not go to to
1589 -- the original node, which is the unanalyzed tree: we need to
1590 -- attach the contract-case or test-case to the analyzed version
1591 -- at this point. They get propagated to the original tree when
1592 -- analyzing the corresponding body.
1594 if Nkind (P) not in N_Generic_Declaration then
1595 PO := Original_Node (P);
1600 -- Skip past prior pragma
1602 if Nkind (PO) = N_Pragma then
1605 -- Skip stuff not coming from source
1607 elsif not Comes_From_Source (PO) then
1610 -- Only remaining possibility is subprogram declaration. First
1611 -- check that it is declared directly in a package declaration.
1612 -- This may be either the package declaration for the current unit
1613 -- being defined or a local package declaration.
1615 elsif not Present (Parent (Parent (PO)))
1616 or else not Present (Parent (Parent (Parent (PO))))
1617 or else not Nkind_In (Parent (Parent (PO)),
1618 N_Package_Declaration,
1619 N_Generic_Package_Declaration)
1629 -- If we fall through, pragma was misplaced
1632 end Check_Contract_Or_Test_Case;
1634 ----------------------------
1635 -- Check_Duplicate_Pragma --
1636 ----------------------------
1638 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1639 Id : Entity_Id := E;
1643 -- Nothing to do if this pragma comes from an aspect specification,
1644 -- since we could not be duplicating a pragma, and we dealt with the
1645 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1647 if From_Aspect_Specification (N) then
1651 -- Otherwise current pragma may duplicate previous pragma or a
1652 -- previously given aspect specification or attribute definition
1653 -- clause for the same pragma.
1655 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
1658 Error_Msg_Name_1 := Pragma_Name (N);
1659 Error_Msg_Sloc := Sloc (P);
1661 -- For a single protected or a single task object, the error is
1662 -- issued on the original entity.
1664 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
1665 Id := Defining_Identifier (Original_Node (Parent (Id)));
1668 if Nkind (P) = N_Aspect_Specification
1669 or else From_Aspect_Specification (P)
1671 Error_Msg_NE ("aspect% for & previously given#", N, Id);
1673 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
1678 end Check_Duplicate_Pragma;
1680 ----------------------------------
1681 -- Check_Duplicated_Export_Name --
1682 ----------------------------------
1684 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1685 String_Val : constant String_Id := Strval (Nam);
1688 -- We are only interested in the export case, and in the case of
1689 -- generics, it is the instance, not the template, that is the
1690 -- problem (the template will generate a warning in any case).
1692 if not Inside_A_Generic
1693 and then (Prag_Id = Pragma_Export
1695 Prag_Id = Pragma_Export_Procedure
1697 Prag_Id = Pragma_Export_Valued_Procedure
1699 Prag_Id = Pragma_Export_Function)
1701 for J in Externals.First .. Externals.Last loop
1702 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1703 Error_Msg_Sloc := Sloc (Externals.Table (J));
1704 Error_Msg_N ("external name duplicates name given#", Nam);
1709 Externals.Append (Nam);
1711 end Check_Duplicated_Export_Name;
1713 -------------------------------------
1714 -- Check_Expr_Is_Static_Expression --
1715 -------------------------------------
1717 procedure Check_Expr_Is_Static_Expression
1719 Typ : Entity_Id := Empty)
1722 if Present (Typ) then
1723 Analyze_And_Resolve (Expr, Typ);
1725 Analyze_And_Resolve (Expr);
1728 if Is_OK_Static_Expression (Expr) then
1731 elsif Etype (Expr) = Any_Type then
1734 -- An interesting special case, if we have a string literal and we
1735 -- are in Ada 83 mode, then we allow it even though it will not be
1736 -- flagged as static. This allows the use of Ada 95 pragmas like
1737 -- Import in Ada 83 mode. They will of course be flagged with
1738 -- warnings as usual, but will not cause errors.
1740 elsif Ada_Version = Ada_83
1741 and then Nkind (Expr) = N_String_Literal
1745 -- Static expression that raises Constraint_Error. This has already
1746 -- been flagged, so just exit from pragma processing.
1748 elsif Is_Static_Expression (Expr) then
1751 -- Finally, we have a real error
1754 Error_Msg_Name_1 := Pname;
1758 "argument for pragma% must be a static expression!";
1761 Flag_Non_Static_Expr (Msg, Expr);
1766 end Check_Expr_Is_Static_Expression;
1768 -------------------------
1769 -- Check_First_Subtype --
1770 -------------------------
1772 procedure Check_First_Subtype (Arg : Node_Id) is
1773 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1774 Ent : constant Entity_Id := Entity (Argx);
1777 if Is_First_Subtype (Ent) then
1780 elsif Is_Type (Ent) then
1782 ("pragma% cannot apply to subtype", Argx);
1784 elsif Is_Object (Ent) then
1786 ("pragma% cannot apply to object, requires a type", Argx);
1790 ("pragma% cannot apply to&, requires a type", Argx);
1792 end Check_First_Subtype;
1794 ----------------------
1795 -- Check_Identifier --
1796 ----------------------
1798 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1801 and then Nkind (Arg) = N_Pragma_Argument_Association
1803 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1804 Error_Msg_Name_1 := Pname;
1805 Error_Msg_Name_2 := Id;
1806 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1810 end Check_Identifier;
1812 --------------------------------
1813 -- Check_Identifier_Is_One_Of --
1814 --------------------------------
1816 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1819 and then Nkind (Arg) = N_Pragma_Argument_Association
1821 if Chars (Arg) = No_Name then
1822 Error_Msg_Name_1 := Pname;
1823 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1826 elsif Chars (Arg) /= N1
1827 and then Chars (Arg) /= N2
1829 Error_Msg_Name_1 := Pname;
1830 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1834 end Check_Identifier_Is_One_Of;
1836 ---------------------------
1837 -- Check_In_Main_Program --
1838 ---------------------------
1840 procedure Check_In_Main_Program is
1841 P : constant Node_Id := Parent (N);
1844 -- Must be at in subprogram body
1846 if Nkind (P) /= N_Subprogram_Body then
1847 Error_Pragma ("% pragma allowed only in subprogram");
1849 -- Otherwise warn if obviously not main program
1851 elsif Present (Parameter_Specifications (Specification (P)))
1852 or else not Is_Compilation_Unit (Defining_Entity (P))
1854 Error_Msg_Name_1 := Pname;
1856 ("?pragma% is only effective in main program", N);
1858 end Check_In_Main_Program;
1860 ---------------------------------------
1861 -- Check_Interrupt_Or_Attach_Handler --
1862 ---------------------------------------
1864 procedure Check_Interrupt_Or_Attach_Handler is
1865 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1866 Handler_Proc, Proc_Scope : Entity_Id;
1871 if Prag_Id = Pragma_Interrupt_Handler then
1872 Check_Restriction (No_Dynamic_Attachment, N);
1875 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1876 Proc_Scope := Scope (Handler_Proc);
1878 -- On AAMP only, a pragma Interrupt_Handler is supported for
1879 -- nonprotected parameterless procedures.
1881 if not AAMP_On_Target
1882 or else Prag_Id = Pragma_Attach_Handler
1884 if Ekind (Proc_Scope) /= E_Protected_Type then
1886 ("argument of pragma% must be protected procedure", Arg1);
1889 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1890 Error_Pragma ("pragma% must be in protected definition");
1894 if not Is_Library_Level_Entity (Proc_Scope)
1895 or else (AAMP_On_Target
1896 and then not Is_Library_Level_Entity (Handler_Proc))
1899 ("argument for pragma% must be library level entity", Arg1);
1902 -- AI05-0033: A pragma cannot appear within a generic body, because
1903 -- instance can be in a nested scope. The check that protected type
1904 -- is itself a library-level declaration is done elsewhere.
1906 -- Note: we omit this check in Codepeer mode to properly handle code
1907 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1909 if Inside_A_Generic then
1910 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1911 and then In_Package_Body (Scope (Current_Scope))
1912 and then not CodePeer_Mode
1914 Error_Pragma ("pragma% cannot be used inside a generic");
1917 end Check_Interrupt_Or_Attach_Handler;
1919 --------------------------------------------
1920 -- Check_Loop_Invariant_Variant_Placement --
1921 --------------------------------------------
1923 procedure Check_Loop_Invariant_Variant_Placement is
1924 procedure Placement_Error (Constr : Node_Id);
1925 -- Node Constr denotes the last loop restricted construct before we
1926 -- encountered an illegal relation between enclosing constructs. Emit
1927 -- an error depending on what Constr was.
1929 ---------------------
1930 -- Placement_Error --
1931 ---------------------
1933 procedure Placement_Error (Constr : Node_Id) is
1935 if Nkind (Constr) = N_Pragma then
1937 ("pragma % must appear immediately within the statements " &
1941 ("block containing pragma % must appear immediately within " &
1942 "the statements of a loop", Constr);
1944 end Placement_Error;
1946 -- Local declarations
1951 -- Start of processing for Check_Loop_Invariant_Variant_Placement
1956 while Present (Stmt) loop
1958 -- The pragma or previous block must appear immediately within the
1959 -- current block's declarative or statement part.
1961 if Nkind (Stmt) = N_Block_Statement then
1962 if (No (Declarations (Stmt))
1963 or else List_Containing (Prev) /= Declarations (Stmt))
1965 List_Containing (Prev) /=
1966 Statements (Handled_Statement_Sequence (Stmt))
1968 Placement_Error (Prev);
1971 -- Keep inspecting the parents because we are now within a
1972 -- chain of nested blocks.
1976 Stmt := Parent (Stmt);
1979 -- The pragma or previous block must appear immediately within the
1980 -- statements of the loop.
1982 elsif Nkind (Stmt) = N_Loop_Statement then
1983 if List_Containing (Prev) /= Statements (Stmt) then
1984 Placement_Error (Prev);
1987 -- Stop the traversal because we reached the innermost loop
1988 -- regardless of whether we encountered an error or not.
1992 -- Ignore a handled statement sequence. Note that this node may
1993 -- be related to a subprogram body in which case we will emit an
1994 -- error on the next iteration of the search.
1996 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
1997 Stmt := Parent (Stmt);
1999 -- Any other statement breaks the chain from the pragma to the
2003 Placement_Error (Prev);
2007 end Check_Loop_Invariant_Variant_Placement;
2009 -------------------------------------------
2010 -- Check_Is_In_Decl_Part_Or_Package_Spec --
2011 -------------------------------------------
2013 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
2022 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
2025 elsif Nkind_In (P, N_Package_Specification,
2030 -- Note: the following tests seem a little peculiar, because
2031 -- they test for bodies, but if we were in the statement part
2032 -- of the body, we would already have hit the handled statement
2033 -- sequence, so the only way we get here is by being in the
2034 -- declarative part of the body.
2036 elsif Nkind_In (P, N_Subprogram_Body,
2047 Error_Pragma ("pragma% is not in declarative part or package spec");
2048 end Check_Is_In_Decl_Part_Or_Package_Spec;
2050 -------------------------
2051 -- Check_No_Identifier --
2052 -------------------------
2054 procedure Check_No_Identifier (Arg : Node_Id) is
2056 if Nkind (Arg) = N_Pragma_Argument_Association
2057 and then Chars (Arg) /= No_Name
2059 Error_Pragma_Arg_Ident
2060 ("pragma% does not permit identifier& here", Arg);
2062 end Check_No_Identifier;
2064 --------------------------
2065 -- Check_No_Identifiers --
2066 --------------------------
2068 procedure Check_No_Identifiers is
2071 if Arg_Count > 0 then
2073 while Present (Arg_Node) loop
2074 Check_No_Identifier (Arg_Node);
2078 end Check_No_Identifiers;
2080 ------------------------
2081 -- Check_No_Link_Name --
2082 ------------------------
2084 procedure Check_No_Link_Name is
2087 and then Chars (Arg3) = Name_Link_Name
2092 if Present (Arg4) then
2094 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
2096 end Check_No_Link_Name;
2098 -------------------------------
2099 -- Check_Optional_Identifier --
2100 -------------------------------
2102 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
2105 and then Nkind (Arg) = N_Pragma_Argument_Association
2106 and then Chars (Arg) /= No_Name
2108 if Chars (Arg) /= Id then
2109 Error_Msg_Name_1 := Pname;
2110 Error_Msg_Name_2 := Id;
2111 Error_Msg_N ("pragma% argument expects identifier%", Arg);
2115 end Check_Optional_Identifier;
2117 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
2119 Name_Buffer (1 .. Id'Length) := Id;
2120 Name_Len := Id'Length;
2121 Check_Optional_Identifier (Arg, Name_Find);
2122 end Check_Optional_Identifier;
2124 --------------------------------------
2125 -- Check_Precondition_Postcondition --
2126 --------------------------------------
2128 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
2132 procedure Chain_PPC (PO : Node_Id);
2133 -- If PO is an entry or a [generic] subprogram declaration node, then
2134 -- the precondition/postcondition applies to this subprogram and the
2135 -- processing for the pragma is completed. Otherwise the pragma is
2142 procedure Chain_PPC (PO : Node_Id) is
2146 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2147 if not From_Aspect_Specification (N) then
2149 ("pragma% cannot be applied to abstract subprogram");
2151 elsif Class_Present (N) then
2156 ("aspect % requires ''Class for abstract subprogram");
2159 -- AI05-0230: The same restriction applies to null procedures. For
2160 -- compatibility with earlier uses of the Ada pragma, apply this
2161 -- rule only to aspect specifications.
2163 -- The above discrpency needs documentation. Robert is dubious
2164 -- about whether it is a good idea ???
2166 elsif Nkind (PO) = N_Subprogram_Declaration
2167 and then Nkind (Specification (PO)) = N_Procedure_Specification
2168 and then Null_Present (Specification (PO))
2169 and then From_Aspect_Specification (N)
2170 and then not Class_Present (N)
2173 ("aspect % requires ''Class for null procedure");
2175 -- Pre/postconditions are legal on a subprogram body if it is not
2176 -- a completion of a declaration.
2178 elsif Nkind (PO) = N_Subprogram_Body
2179 and then Acts_As_Spec (PO)
2183 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2184 N_Expression_Function,
2185 N_Generic_Subprogram_Declaration,
2186 N_Entry_Declaration)
2191 -- Here if we have [generic] subprogram or entry declaration
2193 if Nkind (PO) = N_Entry_Declaration then
2194 S := Defining_Entity (PO);
2196 S := Defining_Unit_Name (Specification (PO));
2198 if Nkind (S) = N_Defining_Program_Unit_Name then
2199 S := Defining_Identifier (S);
2203 -- Note: we do not analyze the pragma at this point. Instead we
2204 -- delay this analysis until the end of the declarative part in
2205 -- which the pragma appears. This implements the required delay
2206 -- in this analysis, allowing forward references. The analysis
2207 -- happens at the end of Analyze_Declarations.
2209 -- Chain spec PPC pragma to list for subprogram
2211 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
2212 Set_Spec_PPC_List (Contract (S), N);
2214 -- Return indicating spec case
2220 -- Start of processing for Check_Precondition_Postcondition
2223 if not Is_List_Member (N) then
2227 -- Preanalyze message argument if present. Visibility in this
2228 -- argument is established at the point of pragma occurrence.
2230 if Arg_Count = 2 then
2231 Check_Optional_Identifier (Arg2, Name_Message);
2232 Preanalyze_Spec_Expression
2233 (Get_Pragma_Arg (Arg2), Standard_String);
2236 -- For a pragma PPC in the extended main source unit, record enabled
2239 -- This may seem redundant with the call to Check_Enabled occurring
2240 -- later on when the pragma is rewritten into a pragma Check but
2241 -- is actually required in the case of a postcondition within a
2244 if Check_Enabled (Pname) and then not Split_PPC (N) then
2245 Set_SCO_Pragma_Enabled (Loc);
2248 -- If we are within an inlined body, the legality of the pragma
2249 -- has been checked already.
2251 if In_Inlined_Body then
2256 -- Search prior declarations
2259 while Present (Prev (P)) loop
2262 -- If the previous node is a generic subprogram, do not go to to
2263 -- the original node, which is the unanalyzed tree: we need to
2264 -- attach the pre/postconditions to the analyzed version at this
2265 -- point. They get propagated to the original tree when analyzing
2266 -- the corresponding body.
2268 if Nkind (P) not in N_Generic_Declaration then
2269 PO := Original_Node (P);
2274 -- Skip past prior pragma
2276 if Nkind (PO) = N_Pragma then
2279 -- Skip stuff not coming from source
2281 elsif not Comes_From_Source (PO) then
2283 -- The condition may apply to a subprogram instantiation
2285 if Nkind (PO) = N_Subprogram_Declaration
2286 and then Present (Generic_Parent (Specification (PO)))
2291 elsif Nkind (PO) = N_Subprogram_Declaration
2292 and then In_Instance
2297 -- For all other cases of non source code, do nothing
2303 -- Only remaining possibility is subprogram declaration
2311 -- If we fall through loop, pragma is at start of list, so see if it
2312 -- is at the start of declarations of a subprogram body.
2314 if Nkind (Parent (N)) = N_Subprogram_Body
2315 and then List_Containing (N) = Declarations (Parent (N))
2317 if Operating_Mode /= Generate_Code
2318 or else Inside_A_Generic
2320 -- Analyze pragma expression for correctness and for ASIS use
2322 Preanalyze_Assert_Expression
2323 (Get_Pragma_Arg (Arg1), Standard_Boolean);
2325 -- In ASIS mode, for a pragma generated from a source aspect,
2326 -- also analyze the original aspect expression.
2329 and then Present (Corresponding_Aspect (N))
2331 Preanalyze_Assert_Expression
2332 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2339 -- See if it is in the pragmas after a library level subprogram
2341 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2343 -- In formal verification mode, analyze pragma expression for
2344 -- correctness, as it is not expanded later.
2347 Analyze_PPC_In_Decl_Part
2348 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2351 Chain_PPC (Unit (Parent (Parent (N))));
2355 -- If we fall through, pragma was misplaced
2358 end Check_Precondition_Postcondition;
2360 -----------------------------
2361 -- Check_Static_Constraint --
2362 -----------------------------
2364 -- Note: for convenience in writing this procedure, in addition to
2365 -- the officially (i.e. by spec) allowed argument which is always a
2366 -- constraint, it also allows ranges and discriminant associations.
2367 -- Above is not clear ???
2369 procedure Check_Static_Constraint (Constr : Node_Id) is
2371 procedure Require_Static (E : Node_Id);
2372 -- Require given expression to be static expression
2374 --------------------
2375 -- Require_Static --
2376 --------------------
2378 procedure Require_Static (E : Node_Id) is
2380 if not Is_OK_Static_Expression (E) then
2381 Flag_Non_Static_Expr
2382 ("non-static constraint not allowed in Unchecked_Union!", E);
2387 -- Start of processing for Check_Static_Constraint
2390 case Nkind (Constr) is
2391 when N_Discriminant_Association =>
2392 Require_Static (Expression (Constr));
2395 Require_Static (Low_Bound (Constr));
2396 Require_Static (High_Bound (Constr));
2398 when N_Attribute_Reference =>
2399 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2400 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2402 when N_Range_Constraint =>
2403 Check_Static_Constraint (Range_Expression (Constr));
2405 when N_Index_Or_Discriminant_Constraint =>
2409 IDC := First (Constraints (Constr));
2410 while Present (IDC) loop
2411 Check_Static_Constraint (IDC);
2419 end Check_Static_Constraint;
2421 --------------------------------------
2422 -- Check_Valid_Configuration_Pragma --
2423 --------------------------------------
2425 -- A configuration pragma must appear in the context clause of a
2426 -- compilation unit, and only other pragmas may precede it. Note that
2427 -- the test also allows use in a configuration pragma file.
2429 procedure Check_Valid_Configuration_Pragma is
2431 if not Is_Configuration_Pragma then
2432 Error_Pragma ("incorrect placement for configuration pragma%");
2434 end Check_Valid_Configuration_Pragma;
2436 -------------------------------------
2437 -- Check_Valid_Library_Unit_Pragma --
2438 -------------------------------------
2440 procedure Check_Valid_Library_Unit_Pragma is
2442 Parent_Node : Node_Id;
2443 Unit_Name : Entity_Id;
2444 Unit_Kind : Node_Kind;
2445 Unit_Node : Node_Id;
2446 Sindex : Source_File_Index;
2449 if not Is_List_Member (N) then
2453 Plist := List_Containing (N);
2454 Parent_Node := Parent (Plist);
2456 if Parent_Node = Empty then
2459 -- Case of pragma appearing after a compilation unit. In this case
2460 -- it must have an argument with the corresponding name and must
2461 -- be part of the following pragmas of its parent.
2463 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2464 if Plist /= Pragmas_After (Parent_Node) then
2467 elsif Arg_Count = 0 then
2469 ("argument required if outside compilation unit");
2472 Check_No_Identifiers;
2473 Check_Arg_Count (1);
2474 Unit_Node := Unit (Parent (Parent_Node));
2475 Unit_Kind := Nkind (Unit_Node);
2477 Analyze (Get_Pragma_Arg (Arg1));
2479 if Unit_Kind = N_Generic_Subprogram_Declaration
2480 or else Unit_Kind = N_Subprogram_Declaration
2482 Unit_Name := Defining_Entity (Unit_Node);
2484 elsif Unit_Kind in N_Generic_Instantiation then
2485 Unit_Name := Defining_Entity (Unit_Node);
2488 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2491 if Chars (Unit_Name) /=
2492 Chars (Entity (Get_Pragma_Arg (Arg1)))
2495 ("pragma% argument is not current unit name", Arg1);
2498 if Ekind (Unit_Name) = E_Package
2499 and then Present (Renamed_Entity (Unit_Name))
2501 Error_Pragma ("pragma% not allowed for renamed package");
2505 -- Pragma appears other than after a compilation unit
2508 -- Here we check for the generic instantiation case and also
2509 -- for the case of processing a generic formal package. We
2510 -- detect these cases by noting that the Sloc on the node
2511 -- does not belong to the current compilation unit.
2513 Sindex := Source_Index (Current_Sem_Unit);
2515 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2516 Rewrite (N, Make_Null_Statement (Loc));
2519 -- If before first declaration, the pragma applies to the
2520 -- enclosing unit, and the name if present must be this name.
2522 elsif Is_Before_First_Decl (N, Plist) then
2523 Unit_Node := Unit_Declaration_Node (Current_Scope);
2524 Unit_Kind := Nkind (Unit_Node);
2526 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2529 elsif Unit_Kind = N_Subprogram_Body
2530 and then not Acts_As_Spec (Unit_Node)
2534 elsif Nkind (Parent_Node) = N_Package_Body then
2537 elsif Nkind (Parent_Node) = N_Package_Specification
2538 and then Plist = Private_Declarations (Parent_Node)
2542 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2543 or else Nkind (Parent_Node) =
2544 N_Generic_Subprogram_Declaration)
2545 and then Plist = Generic_Formal_Declarations (Parent_Node)
2549 elsif Arg_Count > 0 then
2550 Analyze (Get_Pragma_Arg (Arg1));
2552 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2554 ("name in pragma% must be enclosing unit", Arg1);
2557 -- It is legal to have no argument in this context
2563 -- Error if not before first declaration. This is because a
2564 -- library unit pragma argument must be the name of a library
2565 -- unit (RM 10.1.5(7)), but the only names permitted in this
2566 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2567 -- generic subprogram declarations or generic instantiations.
2571 ("pragma% misplaced, must be before first declaration");
2575 end Check_Valid_Library_Unit_Pragma;
2581 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2582 Clist : constant Node_Id := Component_List (Variant);
2586 Comp := First (Component_Items (Clist));
2587 while Present (Comp) loop
2588 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2597 procedure Error_Pragma (Msg : String) is
2598 MsgF : String := Msg;
2600 Error_Msg_Name_1 := Pname;
2602 Error_Msg_N (MsgF, N);
2606 ----------------------
2607 -- Error_Pragma_Arg --
2608 ----------------------
2610 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2611 MsgF : String := Msg;
2613 Error_Msg_Name_1 := Pname;
2615 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2617 end Error_Pragma_Arg;
2619 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2620 MsgF : String := Msg1;
2622 Error_Msg_Name_1 := Pname;
2624 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2625 Error_Pragma_Arg (Msg2, Arg);
2626 end Error_Pragma_Arg;
2628 ----------------------------
2629 -- Error_Pragma_Arg_Ident --
2630 ----------------------------
2632 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2633 MsgF : String := Msg;
2635 Error_Msg_Name_1 := Pname;
2637 Error_Msg_N (MsgF, Arg);
2639 end Error_Pragma_Arg_Ident;
2641 ----------------------
2642 -- Error_Pragma_Ref --
2643 ----------------------
2645 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2646 MsgF : String := Msg;
2648 Error_Msg_Name_1 := Pname;
2650 Error_Msg_Sloc := Sloc (Ref);
2651 Error_Msg_NE (MsgF, N, Ref);
2653 end Error_Pragma_Ref;
2655 ------------------------
2656 -- Find_Lib_Unit_Name --
2657 ------------------------
2659 function Find_Lib_Unit_Name return Entity_Id is
2661 -- Return inner compilation unit entity, for case of nested
2662 -- categorization pragmas. This happens in generic unit.
2664 if Nkind (Parent (N)) = N_Package_Specification
2665 and then Defining_Entity (Parent (N)) /= Current_Scope
2667 return Defining_Entity (Parent (N));
2669 return Current_Scope;
2671 end Find_Lib_Unit_Name;
2673 ----------------------------
2674 -- Find_Program_Unit_Name --
2675 ----------------------------
2677 procedure Find_Program_Unit_Name (Id : Node_Id) is
2678 Unit_Name : Entity_Id;
2679 Unit_Kind : Node_Kind;
2680 P : constant Node_Id := Parent (N);
2683 if Nkind (P) = N_Compilation_Unit then
2684 Unit_Kind := Nkind (Unit (P));
2686 if Unit_Kind = N_Subprogram_Declaration
2687 or else Unit_Kind = N_Package_Declaration
2688 or else Unit_Kind in N_Generic_Declaration
2690 Unit_Name := Defining_Entity (Unit (P));
2692 if Chars (Id) = Chars (Unit_Name) then
2693 Set_Entity (Id, Unit_Name);
2694 Set_Etype (Id, Etype (Unit_Name));
2696 Set_Etype (Id, Any_Type);
2698 ("cannot find program unit referenced by pragma%");
2702 Set_Etype (Id, Any_Type);
2703 Error_Pragma ("pragma% inapplicable to this unit");
2709 end Find_Program_Unit_Name;
2711 -----------------------------------------
2712 -- Find_Unique_Parameterless_Procedure --
2713 -----------------------------------------
2715 function Find_Unique_Parameterless_Procedure
2717 Arg : Node_Id) return Entity_Id
2719 Proc : Entity_Id := Empty;
2722 -- The body of this procedure needs some comments ???
2724 if not Is_Entity_Name (Name) then
2726 ("argument of pragma% must be entity name", Arg);
2728 elsif not Is_Overloaded (Name) then
2729 Proc := Entity (Name);
2731 if Ekind (Proc) /= E_Procedure
2732 or else Present (First_Formal (Proc))
2735 ("argument of pragma% must be parameterless procedure", Arg);
2740 Found : Boolean := False;
2742 Index : Interp_Index;
2745 Get_First_Interp (Name, Index, It);
2746 while Present (It.Nam) loop
2749 if Ekind (Proc) = E_Procedure
2750 and then No (First_Formal (Proc))
2754 Set_Entity (Name, Proc);
2755 Set_Is_Overloaded (Name, False);
2758 ("ambiguous handler name for pragma% ", Arg);
2762 Get_Next_Interp (Index, It);
2767 ("argument of pragma% must be parameterless procedure",
2770 Proc := Entity (Name);
2776 end Find_Unique_Parameterless_Procedure;
2782 procedure Fix_Error (Msg : in out String) is
2784 if From_Aspect_Specification (N) then
2785 for J in Msg'First .. Msg'Last - 5 loop
2786 if Msg (J .. J + 5) = "pragma" then
2787 Msg (J .. J + 5) := "aspect";
2791 if Error_Msg_Name_1 = Name_Precondition then
2792 Error_Msg_Name_1 := Name_Pre;
2793 elsif Error_Msg_Name_1 = Name_Postcondition then
2794 Error_Msg_Name_1 := Name_Post;
2799 -------------------------
2800 -- Gather_Associations --
2801 -------------------------
2803 procedure Gather_Associations
2805 Args : out Args_List)
2810 -- Initialize all parameters to Empty
2812 for J in Args'Range loop
2816 -- That's all we have to do if there are no argument associations
2818 if No (Pragma_Argument_Associations (N)) then
2822 -- Otherwise first deal with any positional parameters present
2824 Arg := First (Pragma_Argument_Associations (N));
2825 for Index in Args'Range loop
2826 exit when No (Arg) or else Chars (Arg) /= No_Name;
2827 Args (Index) := Get_Pragma_Arg (Arg);
2831 -- Positional parameters all processed, if any left, then we
2832 -- have too many positional parameters.
2834 if Present (Arg) and then Chars (Arg) = No_Name then
2836 ("too many positional associations for pragma%", Arg);
2839 -- Process named parameters if any are present
2841 while Present (Arg) loop
2842 if Chars (Arg) = No_Name then
2844 ("positional association cannot follow named association",
2848 for Index in Names'Range loop
2849 if Names (Index) = Chars (Arg) then
2850 if Present (Args (Index)) then
2852 ("duplicate argument association for pragma%", Arg);
2854 Args (Index) := Get_Pragma_Arg (Arg);
2859 if Index = Names'Last then
2860 Error_Msg_Name_1 := Pname;
2861 Error_Msg_N ("pragma% does not allow & argument", Arg);
2863 -- Check for possible misspelling
2865 for Index1 in Names'Range loop
2866 if Is_Bad_Spelling_Of
2867 (Chars (Arg), Names (Index1))
2869 Error_Msg_Name_1 := Names (Index1);
2870 Error_Msg_N -- CODEFIX
2871 ("\possible misspelling of%", Arg);
2883 end Gather_Associations;
2889 procedure GNAT_Pragma is
2891 -- We need to check the No_Implementation_Pragmas restriction for
2892 -- the case of a pragma from source. Note that the case of aspects
2893 -- generating corresponding pragmas marks these pragmas as not being
2894 -- from source, so this test also catches that case.
2896 if Comes_From_Source (N) then
2897 Check_Restriction (No_Implementation_Pragmas, N);
2901 --------------------------
2902 -- Is_Before_First_Decl --
2903 --------------------------
2905 function Is_Before_First_Decl
2906 (Pragma_Node : Node_Id;
2907 Decls : List_Id) return Boolean
2909 Item : Node_Id := First (Decls);
2912 -- Only other pragmas can come before this pragma
2915 if No (Item) or else Nkind (Item) /= N_Pragma then
2918 elsif Item = Pragma_Node then
2924 end Is_Before_First_Decl;
2926 -----------------------------
2927 -- Is_Configuration_Pragma --
2928 -----------------------------
2930 -- A configuration pragma must appear in the context clause of a
2931 -- compilation unit, and only other pragmas may precede it. Note that
2932 -- the test below also permits use in a configuration pragma file.
2934 function Is_Configuration_Pragma return Boolean is
2935 Lis : constant List_Id := List_Containing (N);
2936 Par : constant Node_Id := Parent (N);
2940 -- If no parent, then we are in the configuration pragma file,
2941 -- so the placement is definitely appropriate.
2946 -- Otherwise we must be in the context clause of a compilation unit
2947 -- and the only thing allowed before us in the context list is more
2948 -- configuration pragmas.
2950 elsif Nkind (Par) = N_Compilation_Unit
2951 and then Context_Items (Par) = Lis
2958 elsif Nkind (Prg) /= N_Pragma then
2968 end Is_Configuration_Pragma;
2970 --------------------------
2971 -- Is_In_Context_Clause --
2972 --------------------------
2974 function Is_In_Context_Clause return Boolean is
2976 Parent_Node : Node_Id;
2979 if not Is_List_Member (N) then
2983 Plist := List_Containing (N);
2984 Parent_Node := Parent (Plist);
2986 if Parent_Node = Empty
2987 or else Nkind (Parent_Node) /= N_Compilation_Unit
2988 or else Context_Items (Parent_Node) /= Plist
2995 end Is_In_Context_Clause;
2997 ---------------------------------
2998 -- Is_Static_String_Expression --
2999 ---------------------------------
3001 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
3002 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3005 Analyze_And_Resolve (Argx);
3006 return Is_OK_Static_Expression (Argx)
3007 and then Nkind (Argx) = N_String_Literal;
3008 end Is_Static_String_Expression;
3010 ----------------------
3011 -- Pragma_Misplaced --
3012 ----------------------
3014 procedure Pragma_Misplaced is
3016 Error_Pragma ("incorrect placement of pragma%");
3017 end Pragma_Misplaced;
3019 ------------------------------------
3020 -- Process_Atomic_Shared_Volatile --
3021 ------------------------------------
3023 procedure Process_Atomic_Shared_Volatile is
3030 procedure Set_Atomic (E : Entity_Id);
3031 -- Set given type as atomic, and if no explicit alignment was given,
3032 -- set alignment to unknown, since back end knows what the alignment
3033 -- requirements are for atomic arrays. Note: this step is necessary
3034 -- for derived types.
3040 procedure Set_Atomic (E : Entity_Id) is
3044 if not Has_Alignment_Clause (E) then
3045 Set_Alignment (E, Uint_0);
3049 -- Start of processing for Process_Atomic_Shared_Volatile
3052 Check_Ada_83_Warning;
3053 Check_No_Identifiers;
3054 Check_Arg_Count (1);
3055 Check_Arg_Is_Local_Name (Arg1);
3056 E_Id := Get_Pragma_Arg (Arg1);
3058 if Etype (E_Id) = Any_Type then
3063 D := Declaration_Node (E);
3066 -- Check duplicate before we chain ourselves!
3068 Check_Duplicate_Pragma (E);
3070 -- Now check appropriateness of the entity
3073 if Rep_Item_Too_Early (E, N)
3075 Rep_Item_Too_Late (E, N)
3079 Check_First_Subtype (Arg1);
3082 if Prag_Id /= Pragma_Volatile then
3084 Set_Atomic (Underlying_Type (E));
3085 Set_Atomic (Base_Type (E));
3088 -- Attribute belongs on the base type. If the view of the type is
3089 -- currently private, it also belongs on the underlying type.
3091 Set_Is_Volatile (Base_Type (E));
3092 Set_Is_Volatile (Underlying_Type (E));
3094 Set_Treat_As_Volatile (E);
3095 Set_Treat_As_Volatile (Underlying_Type (E));
3097 elsif K = N_Object_Declaration
3098 or else (K = N_Component_Declaration
3099 and then Original_Record_Component (E) = E)
3101 if Rep_Item_Too_Late (E, N) then
3105 if Prag_Id /= Pragma_Volatile then
3108 -- If the object declaration has an explicit initialization, a
3109 -- temporary may have to be created to hold the expression, to
3110 -- ensure that access to the object remain atomic.
3112 if Nkind (Parent (E)) = N_Object_Declaration
3113 and then Present (Expression (Parent (E)))
3115 Set_Has_Delayed_Freeze (E);
3118 -- An interesting improvement here. If an object of composite
3119 -- type X is declared atomic, and the type X isn't, that's a
3120 -- pity, since it may not have appropriate alignment etc. We
3121 -- can rescue this in the special case where the object and
3122 -- type are in the same unit by just setting the type as
3123 -- atomic, so that the back end will process it as atomic.
3125 -- Note: we used to do this for elementary types as well,
3126 -- but that turns out to be a bad idea and can have unwanted
3127 -- effects, most notably if the type is elementary, the object
3128 -- a simple component within a record, and both are in a spec:
3129 -- every object of this type in the entire program will be
3130 -- treated as atomic, thus incurring a potentially costly
3131 -- synchronization operation for every access.
3133 -- Of course it would be best if the back end could just adjust
3134 -- the alignment etc for the specific object, but that's not
3135 -- something we are capable of doing at this point.
3137 Utyp := Underlying_Type (Etype (E));
3140 and then Is_Composite_Type (Utyp)
3141 and then Sloc (E) > No_Location
3142 and then Sloc (Utyp) > No_Location
3144 Get_Source_File_Index (Sloc (E)) =
3145 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
3147 Set_Is_Atomic (Underlying_Type (Etype (E)));
3151 Set_Is_Volatile (E);
3152 Set_Treat_As_Volatile (E);
3156 ("inappropriate entity for pragma%", Arg1);
3158 end Process_Atomic_Shared_Volatile;
3160 -------------------------------------------
3161 -- Process_Compile_Time_Warning_Or_Error --
3162 -------------------------------------------
3164 procedure Process_Compile_Time_Warning_Or_Error is
3165 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
3168 Check_Arg_Count (2);
3169 Check_No_Identifiers;
3170 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3171 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3173 if Compile_Time_Known_Value (Arg1x) then
3174 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3176 Str : constant String_Id :=
3177 Strval (Get_Pragma_Arg (Arg2));
3178 Len : constant Int := String_Length (Str);
3183 Cent : constant Entity_Id :=
3184 Cunit_Entity (Current_Sem_Unit);
3186 Force : constant Boolean :=
3187 Prag_Id = Pragma_Compile_Time_Warning
3189 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3190 and then (Ekind (Cent) /= E_Package
3191 or else not In_Private_Part (Cent));
3192 -- Set True if this is the warning case, and we are in the
3193 -- visible part of a package spec, or in a subprogram spec,
3194 -- in which case we want to force the client to see the
3195 -- warning, even though it is not in the main unit.
3198 -- Loop through segments of message separated by line feeds.
3199 -- We output these segments as separate messages with
3200 -- continuation marks for all but the first.
3205 Error_Msg_Strlen := 0;
3207 -- Loop to copy characters from argument to error message
3211 exit when Ptr > Len;
3212 CC := Get_String_Char (Str, Ptr);
3215 -- Ignore wide chars ??? else store character
3217 if In_Character_Range (CC) then
3218 C := Get_Character (CC);
3219 exit when C = ASCII.LF;
3220 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3221 Error_Msg_String (Error_Msg_Strlen) := C;
3225 -- Here with one line ready to go
3227 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3229 -- If this is a warning in a spec, then we want clients
3230 -- to see the warning, so mark the message with the
3231 -- special sequence !! to force the warning. In the case
3232 -- of a package spec, we do not force this if we are in
3233 -- the private part of the spec.
3236 if Cont = False then
3237 Error_Msg_N ("<~!!", Arg1);
3240 Error_Msg_N ("\<~!!", Arg1);
3243 -- Error, rather than warning, or in a body, so we do not
3244 -- need to force visibility for client (error will be
3245 -- output in any case, and this is the situation in which
3246 -- we do not want a client to get a warning, since the
3247 -- warning is in the body or the spec private part).
3250 if Cont = False then
3251 Error_Msg_N ("<~", Arg1);
3254 Error_Msg_N ("\<~", Arg1);
3258 exit when Ptr > Len;
3263 end Process_Compile_Time_Warning_Or_Error;
3265 ------------------------
3266 -- Process_Convention --
3267 ------------------------
3269 procedure Process_Convention
3270 (C : out Convention_Id;
3271 Ent : out Entity_Id)
3277 Comp_Unit : Unit_Number_Type;
3279 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3280 -- Called if we have more than one Export/Import/Convention pragma.
3281 -- This is generally illegal, but we have a special case of allowing
3282 -- Import and Interface to coexist if they specify the convention in
3283 -- a consistent manner. We are allowed to do this, since Interface is
3284 -- an implementation defined pragma, and we choose to do it since we
3285 -- know Rational allows this combination. S is the entity id of the
3286 -- subprogram in question. This procedure also sets the special flag
3287 -- Import_Interface_Present in both pragmas in the case where we do
3288 -- have matching Import and Interface pragmas.
3290 procedure Set_Convention_From_Pragma (E : Entity_Id);
3291 -- Set convention in entity E, and also flag that the entity has a
3292 -- convention pragma. If entity is for a private or incomplete type,
3293 -- also set convention and flag on underlying type. This procedure
3294 -- also deals with the special case of C_Pass_By_Copy convention.
3296 -------------------------------
3297 -- Diagnose_Multiple_Pragmas --
3298 -------------------------------
3300 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3301 Pdec : constant Node_Id := Declaration_Node (S);
3305 function Same_Convention (Decl : Node_Id) return Boolean;
3306 -- Decl is a pragma node. This function returns True if this
3307 -- pragma has a first argument that is an identifier with a
3308 -- Chars field corresponding to the Convention_Id C.
3310 function Same_Name (Decl : Node_Id) return Boolean;
3311 -- Decl is a pragma node. This function returns True if this
3312 -- pragma has a second argument that is an identifier with a
3313 -- Chars field that matches the Chars of the current subprogram.
3315 ---------------------
3316 -- Same_Convention --
3317 ---------------------
3319 function Same_Convention (Decl : Node_Id) return Boolean is
3320 Arg1 : constant Node_Id :=
3321 First (Pragma_Argument_Associations (Decl));
3324 if Present (Arg1) then
3326 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3328 if Nkind (Arg) = N_Identifier
3329 and then Is_Convention_Name (Chars (Arg))
3330 and then Get_Convention_Id (Chars (Arg)) = C
3338 end Same_Convention;
3344 function Same_Name (Decl : Node_Id) return Boolean is
3345 Arg1 : constant Node_Id :=
3346 First (Pragma_Argument_Associations (Decl));
3354 Arg2 := Next (Arg1);
3361 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3363 if Nkind (Arg) = N_Identifier
3364 and then Chars (Arg) = Chars (S)
3373 -- Start of processing for Diagnose_Multiple_Pragmas
3378 -- Definitely give message if we have Convention/Export here
3380 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3383 -- If we have an Import or Export, scan back from pragma to
3384 -- find any previous pragma applying to the same procedure.
3385 -- The scan will be terminated by the start of the list, or
3386 -- hitting the subprogram declaration. This won't allow one
3387 -- pragma to appear in the public part and one in the private
3388 -- part, but that seems very unlikely in practice.
3392 while Present (Decl) and then Decl /= Pdec loop
3394 -- Look for pragma with same name as us
3396 if Nkind (Decl) = N_Pragma
3397 and then Same_Name (Decl)
3399 -- Give error if same as our pragma or Export/Convention
3401 if Pragma_Name (Decl) = Name_Export
3403 Pragma_Name (Decl) = Name_Convention
3405 Pragma_Name (Decl) = Pragma_Name (N)
3409 -- Case of Import/Interface or the other way round
3411 elsif Pragma_Name (Decl) = Name_Interface
3413 Pragma_Name (Decl) = Name_Import
3415 -- Here we know that we have Import and Interface. It
3416 -- doesn't matter which way round they are. See if
3417 -- they specify the same convention. If so, all OK,
3418 -- and set special flags to stop other messages
3420 if Same_Convention (Decl) then
3421 Set_Import_Interface_Present (N);
3422 Set_Import_Interface_Present (Decl);
3425 -- If different conventions, special message
3428 Error_Msg_Sloc := Sloc (Decl);
3430 ("convention differs from that given#", Arg1);
3440 -- Give message if needed if we fall through those tests
3444 ("at most one Convention/Export/Import pragma is allowed",
3447 end Diagnose_Multiple_Pragmas;
3449 --------------------------------
3450 -- Set_Convention_From_Pragma --
3451 --------------------------------
3453 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3455 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3456 -- for an overridden dispatching operation. Technically this is
3457 -- an amendment and should only be done in Ada 2005 mode. However,
3458 -- this is clearly a mistake, since the problem that is addressed
3459 -- by this AI is that there is a clear gap in the RM!
3461 if Is_Dispatching_Operation (E)
3462 and then Present (Overridden_Operation (E))
3463 and then C /= Convention (Overridden_Operation (E))
3466 ("cannot change convention for " &
3467 "overridden dispatching operation",
3471 -- Set the convention
3473 Set_Convention (E, C);
3474 Set_Has_Convention_Pragma (E);
3476 if Is_Incomplete_Or_Private_Type (E)
3477 and then Present (Underlying_Type (E))
3479 Set_Convention (Underlying_Type (E), C);
3480 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3483 -- A class-wide type should inherit the convention of the specific
3484 -- root type (although this isn't specified clearly by the RM).
3486 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3487 Set_Convention (Class_Wide_Type (E), C);
3490 -- If the entity is a record type, then check for special case of
3491 -- C_Pass_By_Copy, which is treated the same as C except that the
3492 -- special record flag is set. This convention is only permitted
3493 -- on record types (see AI95-00131).
3495 if Cname = Name_C_Pass_By_Copy then
3496 if Is_Record_Type (E) then
3497 Set_C_Pass_By_Copy (Base_Type (E));
3498 elsif Is_Incomplete_Or_Private_Type (E)
3499 and then Is_Record_Type (Underlying_Type (E))
3501 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3504 ("C_Pass_By_Copy convention allowed only for record type",
3509 -- If the entity is a derived boolean type, check for the special
3510 -- case of convention C, C++, or Fortran, where we consider any
3511 -- nonzero value to represent true.
3513 if Is_Discrete_Type (E)
3514 and then Root_Type (Etype (E)) = Standard_Boolean
3520 C = Convention_Fortran)
3522 Set_Nonzero_Is_True (Base_Type (E));
3524 end Set_Convention_From_Pragma;
3526 -- Start of processing for Process_Convention
3529 Check_At_Least_N_Arguments (2);
3530 Check_Optional_Identifier (Arg1, Name_Convention);
3531 Check_Arg_Is_Identifier (Arg1);
3532 Cname := Chars (Get_Pragma_Arg (Arg1));
3534 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3535 -- tested again below to set the critical flag).
3537 if Cname = Name_C_Pass_By_Copy then
3540 -- Otherwise we must have something in the standard convention list
3542 elsif Is_Convention_Name (Cname) then
3543 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3545 -- In DEC VMS, it seems that there is an undocumented feature that
3546 -- any unrecognized convention is treated as the default, which for
3547 -- us is convention C. It does not seem so terrible to do this
3548 -- unconditionally, silently in the VMS case, and with a warning
3549 -- in the non-VMS case.
3552 if Warn_On_Export_Import and not OpenVMS_On_Target then
3554 ("?unrecognized convention name, C assumed",
3555 Get_Pragma_Arg (Arg1));
3561 Check_Optional_Identifier (Arg2, Name_Entity);
3562 Check_Arg_Is_Local_Name (Arg2);
3564 Id := Get_Pragma_Arg (Arg2);
3567 if not Is_Entity_Name (Id) then
3568 Error_Pragma_Arg ("entity name required", Arg2);
3573 -- Set entity to return
3577 -- Ada_Pass_By_Copy special checking
3579 if C = Convention_Ada_Pass_By_Copy then
3580 if not Is_First_Subtype (E) then
3582 ("convention `Ada_Pass_By_Copy` only "
3583 & "allowed for types", Arg2);
3586 if Is_By_Reference_Type (E) then
3588 ("convention `Ada_Pass_By_Copy` not allowed for "
3589 & "by-reference type", Arg1);
3593 -- Ada_Pass_By_Reference special checking
3595 if C = Convention_Ada_Pass_By_Reference then
3596 if not Is_First_Subtype (E) then
3598 ("convention `Ada_Pass_By_Reference` only "
3599 & "allowed for types", Arg2);
3602 if Is_By_Copy_Type (E) then
3604 ("convention `Ada_Pass_By_Reference` not allowed for "
3605 & "by-copy type", Arg1);
3609 -- Go to renamed subprogram if present, since convention applies to
3610 -- the actual renamed entity, not to the renaming entity. If the
3611 -- subprogram is inherited, go to parent subprogram.
3613 if Is_Subprogram (E)
3614 and then Present (Alias (E))
3616 if Nkind (Parent (Declaration_Node (E))) =
3617 N_Subprogram_Renaming_Declaration
3619 if Scope (E) /= Scope (Alias (E)) then
3621 ("cannot apply pragma% to non-local entity&#", E);
3626 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3627 N_Private_Extension_Declaration)
3628 and then Scope (E) = Scope (Alias (E))
3632 -- Return the parent subprogram the entity was inherited from
3638 -- Check that we are not applying this to a specless body
3640 if Is_Subprogram (E)
3641 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3644 ("pragma% requires separate spec and must come before body");
3647 -- Check that we are not applying this to a named constant
3649 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3650 Error_Msg_Name_1 := Pname;
3652 ("cannot apply pragma% to named constant!",
3653 Get_Pragma_Arg (Arg2));
3655 ("\supply appropriate type for&!", Arg2);
3658 if Ekind (E) = E_Enumeration_Literal then
3659 Error_Pragma ("enumeration literal not allowed for pragma%");
3662 -- Check for rep item appearing too early or too late
3664 if Etype (E) = Any_Type
3665 or else Rep_Item_Too_Early (E, N)
3669 elsif Present (Underlying_Type (E)) then
3670 E := Underlying_Type (E);
3673 if Rep_Item_Too_Late (E, N) then
3677 if Has_Convention_Pragma (E) then
3678 Diagnose_Multiple_Pragmas (E);
3680 elsif Convention (E) = Convention_Protected
3681 or else Ekind (Scope (E)) = E_Protected_Type
3684 ("a protected operation cannot be given a different convention",
3688 -- For Intrinsic, a subprogram is required
3690 if C = Convention_Intrinsic
3691 and then not Is_Subprogram (E)
3692 and then not Is_Generic_Subprogram (E)
3695 ("second argument of pragma% must be a subprogram", Arg2);
3700 if C = Convention_Stdcall then
3702 -- A dispatching call is not allowed. A dispatching subprogram
3703 -- cannot be used to interface to the Win32 API, so in fact this
3704 -- check does not impose any effective restriction.
3706 if Is_Dispatching_Operation (E) then
3709 ("dispatching subprograms cannot use Stdcall convention");
3711 -- Subprogram is allowed, but not a generic subprogram, and not a
3712 -- dispatching operation.
3714 elsif not Is_Subprogram (E)
3715 and then not Is_Generic_Subprogram (E)
3719 and then Ekind (E) /= E_Variable
3721 -- An access to subprogram is also allowed
3725 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3728 ("second argument of pragma% must be subprogram (type)",
3733 if not Is_Subprogram (E)
3734 and then not Is_Generic_Subprogram (E)
3736 Set_Convention_From_Pragma (E);
3739 Check_First_Subtype (Arg2);
3740 Set_Convention_From_Pragma (Base_Type (E));
3742 -- For subprograms, we must set the convention on the
3743 -- internally generated directly designated type as well.
3745 if Ekind (E) = E_Access_Subprogram_Type then
3746 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3750 -- For the subprogram case, set proper convention for all homonyms
3751 -- in same scope and the same declarative part, i.e. the same
3752 -- compilation unit.
3755 Comp_Unit := Get_Source_Unit (E);
3756 Set_Convention_From_Pragma (E);
3758 -- Treat a pragma Import as an implicit body, and pragma import
3759 -- as implicit reference (for navigation in GPS).
3761 if Prag_Id = Pragma_Import then
3762 Generate_Reference (E, Id, 'b');
3764 -- For exported entities we restrict the generation of references
3765 -- to entities exported to foreign languages since entities
3766 -- exported to Ada do not provide further information to GPS and
3767 -- add undesired references to the output of the gnatxref tool.
3769 elsif Prag_Id = Pragma_Export
3770 and then Convention (E) /= Convention_Ada
3772 Generate_Reference (E, Id, 'i');
3775 -- If the pragma comes from from an aspect, it only applies
3776 -- to the given entity, not its homonyms.
3778 if From_Aspect_Specification (N) then
3782 -- Otherwise Loop through the homonyms of the pragma argument's
3783 -- entity, an apply convention to those in the current scope.
3789 exit when No (E1) or else Scope (E1) /= Current_Scope;
3791 -- Do not set the pragma on inherited operations or on formal
3794 if Comes_From_Source (E1)
3795 and then Comp_Unit = Get_Source_Unit (E1)
3796 and then not Is_Formal_Subprogram (E1)
3797 and then Nkind (Original_Node (Parent (E1))) /=
3798 N_Full_Type_Declaration
3800 if Present (Alias (E1))
3801 and then Scope (E1) /= Scope (Alias (E1))
3804 ("cannot apply pragma% to non-local entity& declared#",
3808 Set_Convention_From_Pragma (E1);
3810 if Prag_Id = Pragma_Import then
3811 Generate_Reference (E1, Id, 'b');
3816 end Process_Convention;
3818 ----------------------------------------
3819 -- Process_Disable_Enable_Atomic_Sync --
3820 ----------------------------------------
3822 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3825 Check_No_Identifiers;
3826 Check_At_Most_N_Arguments (1);
3828 -- Modeled internally as
3829 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
3833 Pragma_Identifier =>
3834 Make_Identifier (Loc, Nam),
3835 Pragma_Argument_Associations => New_List (
3836 Make_Pragma_Argument_Association (Loc,
3838 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3840 if Present (Arg1) then
3841 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3845 end Process_Disable_Enable_Atomic_Sync;
3847 -----------------------------------------------------
3848 -- Process_Extended_Import_Export_Exception_Pragma --
3849 -----------------------------------------------------
3851 procedure Process_Extended_Import_Export_Exception_Pragma
3852 (Arg_Internal : Node_Id;
3853 Arg_External : Node_Id;
3861 if not OpenVMS_On_Target then
3863 ("?pragma% ignored (applies only to Open'V'M'S)");
3866 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3867 Def_Id := Entity (Arg_Internal);
3869 if Ekind (Def_Id) /= E_Exception then
3871 ("pragma% must refer to declared exception", Arg_Internal);
3874 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3876 if Present (Arg_Form) then
3877 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3880 if Present (Arg_Form)
3881 and then Chars (Arg_Form) = Name_Ada
3885 Set_Is_VMS_Exception (Def_Id);
3886 Set_Exception_Code (Def_Id, No_Uint);
3889 if Present (Arg_Code) then
3890 if not Is_VMS_Exception (Def_Id) then
3892 ("Code option for pragma% not allowed for Ada case",
3896 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3897 Code_Val := Expr_Value (Arg_Code);
3899 if not UI_Is_In_Int_Range (Code_Val) then
3901 ("Code option for pragma% must be in 32-bit range",
3905 Set_Exception_Code (Def_Id, Code_Val);
3908 end Process_Extended_Import_Export_Exception_Pragma;
3910 -------------------------------------------------
3911 -- Process_Extended_Import_Export_Internal_Arg --
3912 -------------------------------------------------
3914 procedure Process_Extended_Import_Export_Internal_Arg
3915 (Arg_Internal : Node_Id := Empty)
3918 if No (Arg_Internal) then
3919 Error_Pragma ("Internal parameter required for pragma%");
3922 if Nkind (Arg_Internal) = N_Identifier then
3925 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3926 and then (Prag_Id = Pragma_Import_Function
3928 Prag_Id = Pragma_Export_Function)
3934 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3937 Check_Arg_Is_Local_Name (Arg_Internal);
3938 end Process_Extended_Import_Export_Internal_Arg;
3940 --------------------------------------------------
3941 -- Process_Extended_Import_Export_Object_Pragma --
3942 --------------------------------------------------
3944 procedure Process_Extended_Import_Export_Object_Pragma
3945 (Arg_Internal : Node_Id;
3946 Arg_External : Node_Id;
3952 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3953 Def_Id := Entity (Arg_Internal);
3955 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3957 ("pragma% must designate an object", Arg_Internal);
3960 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3962 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3965 ("previous Common/Psect_Object applies, pragma % not permitted",
3969 if Rep_Item_Too_Late (Def_Id, N) then
3973 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3975 if Present (Arg_Size) then
3976 Check_Arg_Is_External_Name (Arg_Size);
3979 -- Export_Object case
3981 if Prag_Id = Pragma_Export_Object then
3982 if not Is_Library_Level_Entity (Def_Id) then
3984 ("argument for pragma% must be library level entity",
3988 if Ekind (Current_Scope) = E_Generic_Package then
3989 Error_Pragma ("pragma& cannot appear in a generic unit");
3992 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3994 ("exported object must have compile time known size",
3998 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3999 Error_Msg_N ("?duplicate Export_Object pragma", N);
4001 Set_Exported (Def_Id, Arg_Internal);
4004 -- Import_Object case
4007 if Is_Concurrent_Type (Etype (Def_Id)) then
4009 ("cannot use pragma% for task/protected object",
4013 if Ekind (Def_Id) = E_Constant then
4015 ("cannot import a constant", Arg_Internal);
4018 if Warn_On_Export_Import
4019 and then Has_Discriminants (Etype (Def_Id))
4022 ("imported value must be initialized?", Arg_Internal);
4025 if Warn_On_Export_Import
4026 and then Is_Access_Type (Etype (Def_Id))
4029 ("cannot import object of an access type?", Arg_Internal);
4032 if Warn_On_Export_Import
4033 and then Is_Imported (Def_Id)
4036 ("?duplicate Import_Object pragma", N);
4038 -- Check for explicit initialization present. Note that an
4039 -- initialization generated by the code generator, e.g. for an
4040 -- access type, does not count here.
4042 elsif Present (Expression (Parent (Def_Id)))
4045 (Original_Node (Expression (Parent (Def_Id))))
4047 Error_Msg_Sloc := Sloc (Def_Id);
4049 ("imported entities cannot be initialized (RM B.1(24))",
4050 "\no initialization allowed for & declared#", Arg1);
4052 Set_Imported (Def_Id);
4053 Note_Possible_Modification (Arg_Internal, Sure => False);
4056 end Process_Extended_Import_Export_Object_Pragma;
4058 ------------------------------------------------------
4059 -- Process_Extended_Import_Export_Subprogram_Pragma --
4060 ------------------------------------------------------
4062 procedure Process_Extended_Import_Export_Subprogram_Pragma
4063 (Arg_Internal : Node_Id;
4064 Arg_External : Node_Id;
4065 Arg_Parameter_Types : Node_Id;
4066 Arg_Result_Type : Node_Id := Empty;
4067 Arg_Mechanism : Node_Id;
4068 Arg_Result_Mechanism : Node_Id := Empty;
4069 Arg_First_Optional_Parameter : Node_Id := Empty)
4075 Ambiguous : Boolean;
4079 function Same_Base_Type
4081 Formal : Entity_Id) return Boolean;
4082 -- Determines if Ptype references the type of Formal. Note that only
4083 -- the base types need to match according to the spec. Ptype here is
4084 -- the argument from the pragma, which is either a type name, or an
4085 -- access attribute.
4087 --------------------
4088 -- Same_Base_Type --
4089 --------------------
4091 function Same_Base_Type
4093 Formal : Entity_Id) return Boolean
4095 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
4099 -- Case where pragma argument is typ'Access
4101 if Nkind (Ptype) = N_Attribute_Reference
4102 and then Attribute_Name (Ptype) = Name_Access
4104 Pref := Prefix (Ptype);
4107 if not Is_Entity_Name (Pref)
4108 or else Entity (Pref) = Any_Type
4113 -- We have a match if the corresponding argument is of an
4114 -- anonymous access type, and its designated type matches the
4115 -- type of the prefix of the access attribute
4117 return Ekind (Ftyp) = E_Anonymous_Access_Type
4118 and then Base_Type (Entity (Pref)) =
4119 Base_Type (Etype (Designated_Type (Ftyp)));
4121 -- Case where pragma argument is a type name
4126 if not Is_Entity_Name (Ptype)
4127 or else Entity (Ptype) = Any_Type
4132 -- We have a match if the corresponding argument is of the type
4133 -- given in the pragma (comparing base types)
4135 return Base_Type (Entity (Ptype)) = Ftyp;
4139 -- Start of processing for
4140 -- Process_Extended_Import_Export_Subprogram_Pragma
4143 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
4147 -- Loop through homonyms (overloadings) of the entity
4149 Hom_Id := Entity (Arg_Internal);
4150 while Present (Hom_Id) loop
4151 Def_Id := Get_Base_Subprogram (Hom_Id);
4153 -- We need a subprogram in the current scope
4155 if not Is_Subprogram (Def_Id)
4156 or else Scope (Def_Id) /= Current_Scope
4163 -- Pragma cannot apply to subprogram body
4165 if Is_Subprogram (Def_Id)
4166 and then Nkind (Parent (Declaration_Node (Def_Id))) =
4170 ("pragma% requires separate spec"
4171 & " and must come before body");
4174 -- Test result type if given, note that the result type
4175 -- parameter can only be present for the function cases.
4177 if Present (Arg_Result_Type)
4178 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
4182 elsif Etype (Def_Id) /= Standard_Void_Type
4184 (Pname = Name_Export_Procedure
4186 Pname = Name_Import_Procedure)
4190 -- Test parameter types if given. Note that this parameter
4191 -- has not been analyzed (and must not be, since it is
4192 -- semantic nonsense), so we get it as the parser left it.
4194 elsif Present (Arg_Parameter_Types) then
4195 Check_Matching_Types : declare
4200 Formal := First_Formal (Def_Id);
4202 if Nkind (Arg_Parameter_Types) = N_Null then
4203 if Present (Formal) then
4207 -- A list of one type, e.g. (List) is parsed as
4208 -- a parenthesized expression.
4210 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4211 and then Paren_Count (Arg_Parameter_Types) = 1
4214 or else Present (Next_Formal (Formal))
4219 Same_Base_Type (Arg_Parameter_Types, Formal);
4222 -- A list of more than one type is parsed as a aggregate
4224 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4225 and then Paren_Count (Arg_Parameter_Types) = 0
4227 Ptype := First (Expressions (Arg_Parameter_Types));
4228 while Present (Ptype) or else Present (Formal) loop
4231 or else not Same_Base_Type (Ptype, Formal)
4236 Next_Formal (Formal);
4241 -- Anything else is of the wrong form
4245 ("wrong form for Parameter_Types parameter",
4246 Arg_Parameter_Types);
4248 end Check_Matching_Types;
4251 -- Match is now False if the entry we found did not match
4252 -- either a supplied Parameter_Types or Result_Types argument
4258 -- Ambiguous case, the flag Ambiguous shows if we already
4259 -- detected this and output the initial messages.
4262 if not Ambiguous then
4264 Error_Msg_Name_1 := Pname;
4266 ("pragma% does not uniquely identify subprogram!",
4268 Error_Msg_Sloc := Sloc (Ent);
4269 Error_Msg_N ("matching subprogram #!", N);
4273 Error_Msg_Sloc := Sloc (Def_Id);
4274 Error_Msg_N ("matching subprogram #!", N);
4279 Hom_Id := Homonym (Hom_Id);
4282 -- See if we found an entry
4285 if not Ambiguous then
4286 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4288 ("pragma% cannot be given for generic subprogram");
4291 ("pragma% does not identify local subprogram");
4298 -- Import pragmas must be for imported entities
4300 if Prag_Id = Pragma_Import_Function
4302 Prag_Id = Pragma_Import_Procedure
4304 Prag_Id = Pragma_Import_Valued_Procedure
4306 if not Is_Imported (Ent) then
4308 ("pragma Import or Interface must precede pragma%");
4311 -- Here we have the Export case which can set the entity as exported
4313 -- But does not do so if the specified external name is null, since
4314 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4315 -- compatible) to request no external name.
4317 elsif Nkind (Arg_External) = N_String_Literal
4318 and then String_Length (Strval (Arg_External)) = 0
4322 -- In all other cases, set entity as exported
4325 Set_Exported (Ent, Arg_Internal);
4328 -- Special processing for Valued_Procedure cases
4330 if Prag_Id = Pragma_Import_Valued_Procedure
4332 Prag_Id = Pragma_Export_Valued_Procedure
4334 Formal := First_Formal (Ent);
4337 Error_Pragma ("at least one parameter required for pragma%");
4339 elsif Ekind (Formal) /= E_Out_Parameter then
4340 Error_Pragma ("first parameter must have mode out for pragma%");
4343 Set_Is_Valued_Procedure (Ent);
4347 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4349 -- Process Result_Mechanism argument if present. We have already
4350 -- checked that this is only allowed for the function case.
4352 if Present (Arg_Result_Mechanism) then
4353 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4356 -- Process Mechanism parameter if present. Note that this parameter
4357 -- is not analyzed, and must not be analyzed since it is semantic
4358 -- nonsense, so we get it in exactly as the parser left it.
4360 if Present (Arg_Mechanism) then
4368 -- A single mechanism association without a formal parameter
4369 -- name is parsed as a parenthesized expression. All other
4370 -- cases are parsed as aggregates, so we rewrite the single
4371 -- parameter case as an aggregate for consistency.
4373 if Nkind (Arg_Mechanism) /= N_Aggregate
4374 and then Paren_Count (Arg_Mechanism) = 1
4376 Rewrite (Arg_Mechanism,
4377 Make_Aggregate (Sloc (Arg_Mechanism),
4378 Expressions => New_List (
4379 Relocate_Node (Arg_Mechanism))));
4382 -- Case of only mechanism name given, applies to all formals
4384 if Nkind (Arg_Mechanism) /= N_Aggregate then
4385 Formal := First_Formal (Ent);
4386 while Present (Formal) loop
4387 Set_Mechanism_Value (Formal, Arg_Mechanism);
4388 Next_Formal (Formal);
4391 -- Case of list of mechanism associations given
4394 if Null_Record_Present (Arg_Mechanism) then
4396 ("inappropriate form for Mechanism parameter",
4400 -- Deal with positional ones first
4402 Formal := First_Formal (Ent);
4404 if Present (Expressions (Arg_Mechanism)) then
4405 Mname := First (Expressions (Arg_Mechanism));
4406 while Present (Mname) loop
4409 ("too many mechanism associations", Mname);
4412 Set_Mechanism_Value (Formal, Mname);
4413 Next_Formal (Formal);
4418 -- Deal with named entries
4420 if Present (Component_Associations (Arg_Mechanism)) then
4421 Massoc := First (Component_Associations (Arg_Mechanism));
4422 while Present (Massoc) loop
4423 Choice := First (Choices (Massoc));
4425 if Nkind (Choice) /= N_Identifier
4426 or else Present (Next (Choice))
4429 ("incorrect form for mechanism association",
4433 Formal := First_Formal (Ent);
4437 ("parameter name & not present", Choice);
4440 if Chars (Choice) = Chars (Formal) then
4442 (Formal, Expression (Massoc));
4444 -- Set entity on identifier (needed by ASIS)
4446 Set_Entity (Choice, Formal);
4451 Next_Formal (Formal);
4461 -- Process First_Optional_Parameter argument if present. We have
4462 -- already checked that this is only allowed for the Import case.
4464 if Present (Arg_First_Optional_Parameter) then
4465 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4467 ("first optional parameter must be formal parameter name",
4468 Arg_First_Optional_Parameter);
4471 Formal := First_Formal (Ent);
4475 ("specified formal parameter& not found",
4476 Arg_First_Optional_Parameter);
4479 exit when Chars (Formal) =
4480 Chars (Arg_First_Optional_Parameter);
4482 Next_Formal (Formal);
4485 Set_First_Optional_Parameter (Ent, Formal);
4487 -- Check specified and all remaining formals have right form
4489 while Present (Formal) loop
4490 if Ekind (Formal) /= E_In_Parameter then
4492 ("optional formal& is not of mode in!",
4493 Arg_First_Optional_Parameter, Formal);
4496 Dval := Default_Value (Formal);
4500 ("optional formal& does not have default value!",
4501 Arg_First_Optional_Parameter, Formal);
4503 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4508 ("default value for optional formal& is non-static!",
4509 Arg_First_Optional_Parameter, Formal);
4513 Set_Is_Optional_Parameter (Formal);
4514 Next_Formal (Formal);
4517 end Process_Extended_Import_Export_Subprogram_Pragma;
4519 --------------------------
4520 -- Process_Generic_List --
4521 --------------------------
4523 procedure Process_Generic_List is
4528 Check_No_Identifiers;
4529 Check_At_Least_N_Arguments (1);
4532 while Present (Arg) loop
4533 Exp := Get_Pragma_Arg (Arg);
4536 if not Is_Entity_Name (Exp)
4538 (not Is_Generic_Instance (Entity (Exp))
4540 not Is_Generic_Unit (Entity (Exp)))
4543 ("pragma% argument must be name of generic unit/instance",
4549 end Process_Generic_List;
4551 ------------------------------------
4552 -- Process_Import_Predefined_Type --
4553 ------------------------------------
4555 procedure Process_Import_Predefined_Type is
4556 Loc : constant Source_Ptr := Sloc (N);
4558 Ftyp : Node_Id := Empty;
4564 String_To_Name_Buffer (Strval (Expression (Arg3)));
4567 Elmt := First_Elmt (Predefined_Float_Types);
4568 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4572 Ftyp := Node (Elmt);
4574 if Present (Ftyp) then
4576 -- Don't build a derived type declaration, because predefined C
4577 -- types have no declaration anywhere, so cannot really be named.
4578 -- Instead build a full type declaration, starting with an
4579 -- appropriate type definition is built
4581 if Is_Floating_Point_Type (Ftyp) then
4582 Def := Make_Floating_Point_Definition (Loc,
4583 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4584 Make_Real_Range_Specification (Loc,
4585 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4586 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4588 -- Should never have a predefined type we cannot handle
4591 raise Program_Error;
4594 -- Build and insert a Full_Type_Declaration, which will be
4595 -- analyzed as soon as this list entry has been analyzed.
4597 Decl := Make_Full_Type_Declaration (Loc,
4598 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4599 Type_Definition => Def);
4601 Insert_After (N, Decl);
4602 Mark_Rewrite_Insertion (Decl);
4605 Error_Pragma_Arg ("no matching type found for pragma%",
4608 end Process_Import_Predefined_Type;
4610 ---------------------------------
4611 -- Process_Import_Or_Interface --
4612 ---------------------------------
4614 procedure Process_Import_Or_Interface is
4620 Process_Convention (C, Def_Id);
4621 Kill_Size_Check_Code (Def_Id);
4622 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4624 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4626 -- We do not permit Import to apply to a renaming declaration
4628 if Present (Renamed_Object (Def_Id)) then
4630 ("pragma% not allowed for object renaming", Arg2);
4632 -- User initialization is not allowed for imported object, but
4633 -- the object declaration may contain a default initialization,
4634 -- that will be discarded. Note that an explicit initialization
4635 -- only counts if it comes from source, otherwise it is simply
4636 -- the code generator making an implicit initialization explicit.
4638 elsif Present (Expression (Parent (Def_Id)))
4639 and then Comes_From_Source (Expression (Parent (Def_Id)))
4641 Error_Msg_Sloc := Sloc (Def_Id);
4643 ("no initialization allowed for declaration of& #",
4644 "\imported entities cannot be initialized (RM B.1(24))",
4648 Set_Imported (Def_Id);
4649 Process_Interface_Name (Def_Id, Arg3, Arg4);
4651 -- Note that we do not set Is_Public here. That's because we
4652 -- only want to set it if there is no address clause, and we
4653 -- don't know that yet, so we delay that processing till
4656 -- pragma Import completes deferred constants
4658 if Ekind (Def_Id) = E_Constant then
4659 Set_Has_Completion (Def_Id);
4662 -- It is not possible to import a constant of an unconstrained
4663 -- array type (e.g. string) because there is no simple way to
4664 -- write a meaningful subtype for it.
4666 if Is_Array_Type (Etype (Def_Id))
4667 and then not Is_Constrained (Etype (Def_Id))
4670 ("imported constant& must have a constrained subtype",
4675 elsif Is_Subprogram (Def_Id)
4676 or else Is_Generic_Subprogram (Def_Id)
4678 -- If the name is overloaded, pragma applies to all of the denoted
4679 -- entities in the same declarative part, unless the pragma comes
4680 -- from an aspect specification.
4683 while Present (Hom_Id) loop
4685 Def_Id := Get_Base_Subprogram (Hom_Id);
4687 -- Ignore inherited subprograms because the pragma will apply
4688 -- to the parent operation, which is the one called.
4690 if Is_Overloadable (Def_Id)
4691 and then Present (Alias (Def_Id))
4695 -- If it is not a subprogram, it must be in an outer scope and
4696 -- pragma does not apply.
4698 elsif not Is_Subprogram (Def_Id)
4699 and then not Is_Generic_Subprogram (Def_Id)
4703 -- The pragma does not apply to primitives of interfaces
4705 elsif Is_Dispatching_Operation (Def_Id)
4706 and then Present (Find_Dispatching_Type (Def_Id))
4707 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4711 -- Verify that the homonym is in the same declarative part (not
4712 -- just the same scope). If the pragma comes from an aspect
4713 -- specification we know that it is part of the declaration.
4715 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4716 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4717 and then not From_Aspect_Specification (N)
4722 Set_Imported (Def_Id);
4724 -- Reject an Import applied to an abstract subprogram
4726 if Is_Subprogram (Def_Id)
4727 and then Is_Abstract_Subprogram (Def_Id)
4729 Error_Msg_Sloc := Sloc (Def_Id);
4731 ("cannot import abstract subprogram& declared#",
4735 -- Special processing for Convention_Intrinsic
4737 if C = Convention_Intrinsic then
4739 -- Link_Name argument not allowed for intrinsic
4743 Set_Is_Intrinsic_Subprogram (Def_Id);
4745 -- If no external name is present, then check that this
4746 -- is a valid intrinsic subprogram. If an external name
4747 -- is present, then this is handled by the back end.
4750 Check_Intrinsic_Subprogram
4751 (Def_Id, Get_Pragma_Arg (Arg2));
4755 -- All interfaced procedures need an external symbol created
4756 -- for them since they are always referenced from another
4759 Set_Is_Public (Def_Id);
4761 -- Verify that the subprogram does not have a completion
4762 -- through a renaming declaration. For other completions the
4763 -- pragma appears as a too late representation.
4766 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4770 and then Nkind (Decl) = N_Subprogram_Declaration
4771 and then Present (Corresponding_Body (Decl))
4772 and then Nkind (Unit_Declaration_Node
4773 (Corresponding_Body (Decl))) =
4774 N_Subprogram_Renaming_Declaration
4776 Error_Msg_Sloc := Sloc (Def_Id);
4778 ("cannot import&, renaming already provided for " &
4779 "declaration #", N, Def_Id);
4783 Set_Has_Completion (Def_Id);
4784 Process_Interface_Name (Def_Id, Arg3, Arg4);
4787 if Is_Compilation_Unit (Hom_Id) then
4789 -- Its possible homonyms are not affected by the pragma.
4790 -- Such homonyms might be present in the context of other
4791 -- units being compiled.
4795 elsif From_Aspect_Specification (N) then
4799 Hom_Id := Homonym (Hom_Id);
4803 -- When the convention is Java or CIL, we also allow Import to be
4804 -- given for packages, generic packages, exceptions, record
4805 -- components, and access to subprograms.
4807 elsif (C = Convention_Java or else C = Convention_CIL)
4809 (Is_Package_Or_Generic_Package (Def_Id)
4810 or else Ekind (Def_Id) = E_Exception
4811 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4812 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4814 Set_Imported (Def_Id);
4815 Set_Is_Public (Def_Id);
4816 Process_Interface_Name (Def_Id, Arg3, Arg4);
4818 -- Import a CPP class
4820 elsif C = Convention_CPP
4821 and then (Is_Record_Type (Def_Id)
4822 or else Ekind (Def_Id) = E_Incomplete_Type)
4824 if Ekind (Def_Id) = E_Incomplete_Type then
4825 if Present (Full_View (Def_Id)) then
4826 Def_Id := Full_View (Def_Id);
4830 ("cannot import 'C'P'P type before full declaration seen",
4831 Get_Pragma_Arg (Arg2));
4833 -- Although we have reported the error we decorate it as
4834 -- CPP_Class to avoid reporting spurious errors
4836 Set_Is_CPP_Class (Def_Id);
4841 -- Types treated as CPP classes must be declared limited (note:
4842 -- this used to be a warning but there is no real benefit to it
4843 -- since we did effectively intend to treat the type as limited
4846 if not Is_Limited_Type (Def_Id) then
4848 ("imported 'C'P'P type must be limited",
4849 Get_Pragma_Arg (Arg2));
4852 if Etype (Def_Id) /= Def_Id
4853 and then not Is_CPP_Class (Root_Type (Def_Id))
4855 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
4858 Set_Is_CPP_Class (Def_Id);
4860 -- Imported CPP types must not have discriminants (because C++
4861 -- classes do not have discriminants).
4863 if Has_Discriminants (Def_Id) then
4865 ("imported 'C'P'P type cannot have discriminants",
4866 First (Discriminant_Specifications
4867 (Declaration_Node (Def_Id))));
4870 -- Check that components of imported CPP types do not have default
4871 -- expressions. For private types this check is performed when the
4872 -- full view is analyzed (see Process_Full_View).
4874 if not Is_Private_Type (Def_Id) then
4875 Check_CPP_Type_Has_No_Defaults (Def_Id);
4878 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4880 Check_Arg_Count (3);
4881 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4883 Process_Import_Predefined_Type;
4887 ("second argument of pragma% must be object, subprogram "
4888 & "or incomplete type",
4892 -- If this pragma applies to a compilation unit, then the unit, which
4893 -- is a subprogram, does not require (or allow) a body. We also do
4894 -- not need to elaborate imported procedures.
4896 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4898 Cunit : constant Node_Id := Parent (Parent (N));
4900 Set_Body_Required (Cunit, False);
4903 end Process_Import_Or_Interface;
4905 --------------------
4906 -- Process_Inline --
4907 --------------------
4909 procedure Process_Inline (Active : Boolean) is
4916 Effective : Boolean := False;
4917 -- Set True if inline has some effect, i.e. if there is at least one
4918 -- subprogram set as inlined as a result of the use of the pragma.
4920 procedure Make_Inline (Subp : Entity_Id);
4921 -- Subp is the defining unit name of the subprogram declaration. Set
4922 -- the flag, as well as the flag in the corresponding body, if there
4925 procedure Set_Inline_Flags (Subp : Entity_Id);
4926 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4927 -- Has_Pragma_Inline_Always for the Inline_Always case.
4929 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4930 -- Returns True if it can be determined at this stage that inlining
4931 -- is not possible, for example if the body is available and contains
4932 -- exception handlers, we prevent inlining, since otherwise we can
4933 -- get undefined symbols at link time. This function also emits a
4934 -- warning if front-end inlining is enabled and the pragma appears
4937 -- ??? is business with link symbols still valid, or does it relate
4938 -- to front end ZCX which is being phased out ???
4940 ---------------------------
4941 -- Inlining_Not_Possible --
4942 ---------------------------
4944 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4945 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4949 if Nkind (Decl) = N_Subprogram_Body then
4950 Stats := Handled_Statement_Sequence (Decl);
4951 return Present (Exception_Handlers (Stats))
4952 or else Present (At_End_Proc (Stats));
4954 elsif Nkind (Decl) = N_Subprogram_Declaration
4955 and then Present (Corresponding_Body (Decl))
4957 if Front_End_Inlining
4958 and then Analyzed (Corresponding_Body (Decl))
4960 Error_Msg_N ("pragma appears too late, ignored?", N);
4963 -- If the subprogram is a renaming as body, the body is just a
4964 -- call to the renamed subprogram, and inlining is trivially
4968 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4969 N_Subprogram_Renaming_Declaration
4975 Handled_Statement_Sequence
4976 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4979 Present (Exception_Handlers (Stats))
4980 or else Present (At_End_Proc (Stats));
4984 -- If body is not available, assume the best, the check is
4985 -- performed again when compiling enclosing package bodies.
4989 end Inlining_Not_Possible;
4995 procedure Make_Inline (Subp : Entity_Id) is
4996 Kind : constant Entity_Kind := Ekind (Subp);
4997 Inner_Subp : Entity_Id := Subp;
5000 -- Ignore if bad type, avoid cascaded error
5002 if Etype (Subp) = Any_Type then
5006 -- Ignore if all inlining is suppressed
5008 elsif Suppress_All_Inlining then
5012 -- If inlining is not possible, for now do not treat as an error
5014 elsif Inlining_Not_Possible (Subp) then
5018 -- Here we have a candidate for inlining, but we must exclude
5019 -- derived operations. Otherwise we would end up trying to inline
5020 -- a phantom declaration, and the result would be to drag in a
5021 -- body which has no direct inlining associated with it. That
5022 -- would not only be inefficient but would also result in the
5023 -- backend doing cross-unit inlining in cases where it was
5024 -- definitely inappropriate to do so.
5026 -- However, a simple Comes_From_Source test is insufficient, since
5027 -- we do want to allow inlining of generic instances which also do
5028 -- not come from source. We also need to recognize specs generated
5029 -- by the front-end for bodies that carry the pragma. Finally,
5030 -- predefined operators do not come from source but are not
5031 -- inlineable either.
5033 elsif Is_Generic_Instance (Subp)
5034 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
5038 elsif not Comes_From_Source (Subp)
5039 and then Scope (Subp) /= Standard_Standard
5045 -- The referenced entity must either be the enclosing entity, or
5046 -- an entity declared within the current open scope.
5048 if Present (Scope (Subp))
5049 and then Scope (Subp) /= Current_Scope
5050 and then Subp /= Current_Scope
5053 ("argument of% must be entity in current scope", Assoc);
5057 -- Processing for procedure, operator or function. If subprogram
5058 -- is aliased (as for an instance) indicate that the renamed
5059 -- entity (if declared in the same unit) is inlined.
5061 if Is_Subprogram (Subp) then
5062 Inner_Subp := Ultimate_Alias (Inner_Subp);
5064 if In_Same_Source_Unit (Subp, Inner_Subp) then
5065 Set_Inline_Flags (Inner_Subp);
5067 Decl := Parent (Parent (Inner_Subp));
5069 if Nkind (Decl) = N_Subprogram_Declaration
5070 and then Present (Corresponding_Body (Decl))
5072 Set_Inline_Flags (Corresponding_Body (Decl));
5074 elsif Is_Generic_Instance (Subp) then
5076 -- Indicate that the body needs to be created for
5077 -- inlining subsequent calls. The instantiation node
5078 -- follows the declaration of the wrapper package
5081 if Scope (Subp) /= Standard_Standard
5083 Need_Subprogram_Instance_Body
5084 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
5090 -- Inline is a program unit pragma (RM 10.1.5) and cannot
5091 -- appear in a formal part to apply to a formal subprogram.
5092 -- Do not apply check within an instance or a formal package
5093 -- the test will have been applied to the original generic.
5095 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
5096 and then List_Containing (Decl) = List_Containing (N)
5097 and then not In_Instance
5100 ("Inline cannot apply to a formal subprogram", N);
5102 -- If Subp is a renaming, it is the renamed entity that
5103 -- will appear in any call, and be inlined. However, for
5104 -- ASIS uses it is convenient to indicate that the renaming
5105 -- itself is an inlined subprogram, so that some gnatcheck
5106 -- rules can be applied in the absence of expansion.
5108 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
5109 Set_Inline_Flags (Subp);
5115 -- For a generic subprogram set flag as well, for use at the point
5116 -- of instantiation, to determine whether the body should be
5119 elsif Is_Generic_Subprogram (Subp) then
5120 Set_Inline_Flags (Subp);
5123 -- Literals are by definition inlined
5125 elsif Kind = E_Enumeration_Literal then
5128 -- Anything else is an error
5132 ("expect subprogram name for pragma%", Assoc);
5136 ----------------------
5137 -- Set_Inline_Flags --
5138 ----------------------
5140 procedure Set_Inline_Flags (Subp : Entity_Id) is
5143 Set_Is_Inlined (Subp);
5146 if not Has_Pragma_Inline (Subp) then
5147 Set_Has_Pragma_Inline (Subp);
5151 if Prag_Id = Pragma_Inline_Always then
5152 Set_Has_Pragma_Inline_Always (Subp);
5154 end Set_Inline_Flags;
5156 -- Start of processing for Process_Inline
5159 Check_No_Identifiers;
5160 Check_At_Least_N_Arguments (1);
5163 Inline_Processing_Required := True;
5167 while Present (Assoc) loop
5168 Subp_Id := Get_Pragma_Arg (Assoc);
5172 if Is_Entity_Name (Subp_Id) then
5173 Subp := Entity (Subp_Id);
5175 if Subp = Any_Id then
5177 -- If previous error, avoid cascaded errors
5179 Check_Error_Detected;
5186 -- For the pragma case, climb homonym chain. This is
5187 -- what implements allowing the pragma in the renaming
5188 -- case, with the result applying to the ancestors, and
5189 -- also allows Inline to apply to all previous homonyms.
5191 if not From_Aspect_Specification (N) then
5192 while Present (Homonym (Subp))
5193 and then Scope (Homonym (Subp)) = Current_Scope
5195 Make_Inline (Homonym (Subp));
5196 Subp := Homonym (Subp);
5204 ("inappropriate argument for pragma%", Assoc);
5207 and then Warn_On_Redundant_Constructs
5208 and then not Suppress_All_Inlining
5210 if Inlining_Not_Possible (Subp) then
5212 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
5215 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
5223 ----------------------------
5224 -- Process_Interface_Name --
5225 ----------------------------
5227 procedure Process_Interface_Name
5228 (Subprogram_Def : Entity_Id;
5234 String_Val : String_Id;
5236 procedure Check_Form_Of_Interface_Name
5238 Ext_Name_Case : Boolean);
5239 -- SN is a string literal node for an interface name. This routine
5240 -- performs some minimal checks that the name is reasonable. In
5241 -- particular that no spaces or other obviously incorrect characters
5242 -- appear. This is only a warning, since any characters are allowed.
5243 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5245 ----------------------------------
5246 -- Check_Form_Of_Interface_Name --
5247 ----------------------------------
5249 procedure Check_Form_Of_Interface_Name
5251 Ext_Name_Case : Boolean)
5253 S : constant String_Id := Strval (Expr_Value_S (SN));
5254 SL : constant Nat := String_Length (S);
5259 Error_Msg_N ("interface name cannot be null string", SN);
5262 for J in 1 .. SL loop
5263 C := Get_String_Char (S, J);
5265 -- Look for dubious character and issue unconditional warning.
5266 -- Definitely dubious if not in character range.
5268 if not In_Character_Range (C)
5270 -- For all cases except CLI target,
5271 -- commas, spaces and slashes are dubious (in CLI, we use
5272 -- commas and backslashes in external names to specify
5273 -- assembly version and public key, while slashes and spaces
5274 -- can be used in names to mark nested classes and
5277 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5278 and then (Get_Character (C) = ','
5280 Get_Character (C) = '\'))
5281 or else (VM_Target /= CLI_Target
5282 and then (Get_Character (C) = ' '
5284 Get_Character (C) = '/'))
5287 ("?interface name contains illegal character",
5288 Sloc (SN) + Source_Ptr (J));
5291 end Check_Form_Of_Interface_Name;
5293 -- Start of processing for Process_Interface_Name
5296 if No (Link_Arg) then
5297 if No (Ext_Arg) then
5298 if VM_Target = CLI_Target
5299 and then Ekind (Subprogram_Def) = E_Package
5300 and then Nkind (Parent (Subprogram_Def)) =
5301 N_Package_Specification
5302 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5307 (Generic_Parent (Parent (Subprogram_Def))));
5312 elsif Chars (Ext_Arg) = Name_Link_Name then
5314 Link_Nam := Expression (Ext_Arg);
5317 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5318 Ext_Nam := Expression (Ext_Arg);
5323 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5324 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5325 Ext_Nam := Expression (Ext_Arg);
5326 Link_Nam := Expression (Link_Arg);
5329 -- Check expressions for external name and link name are static
5331 if Present (Ext_Nam) then
5332 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5333 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5335 -- Verify that external name is not the name of a local entity,
5336 -- which would hide the imported one and could lead to run-time
5337 -- surprises. The problem can only arise for entities declared in
5338 -- a package body (otherwise the external name is fully qualified
5339 -- and will not conflict).
5347 if Prag_Id = Pragma_Import then
5348 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5350 E := Entity_Id (Get_Name_Table_Info (Nam));
5352 if Nam /= Chars (Subprogram_Def)
5353 and then Present (E)
5354 and then not Is_Overloadable (E)
5355 and then Is_Immediately_Visible (E)
5356 and then not Is_Imported (E)
5357 and then Ekind (Scope (E)) = E_Package
5360 while Present (Par) loop
5361 if Nkind (Par) = N_Package_Body then
5362 Error_Msg_Sloc := Sloc (E);
5364 ("imported entity is hidden by & declared#",
5369 Par := Parent (Par);
5376 if Present (Link_Nam) then
5377 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5378 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5381 -- If there is no link name, just set the external name
5383 if No (Link_Nam) then
5384 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5386 -- For the Link_Name case, the given literal is preceded by an
5387 -- asterisk, which indicates to GCC that the given name should be
5388 -- taken literally, and in particular that no prepending of
5389 -- underlines should occur, even in systems where this is the
5395 if VM_Target = No_VM then
5396 Store_String_Char (Get_Char_Code ('*'));
5399 String_Val := Strval (Expr_Value_S (Link_Nam));
5400 Store_String_Chars (String_Val);
5402 Make_String_Literal (Sloc (Link_Nam),
5403 Strval => End_String);
5406 -- Set the interface name. If the entity is a generic instance, use
5407 -- its alias, which is the callable entity.
5409 if Is_Generic_Instance (Subprogram_Def) then
5410 Set_Encoded_Interface_Name
5411 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5413 Set_Encoded_Interface_Name
5414 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5417 -- We allow duplicated export names in CIL/Java, as they are always
5418 -- enclosed in a namespace that differentiates them, and overloaded
5419 -- entities are supported by the VM.
5421 if Convention (Subprogram_Def) /= Convention_CIL
5423 Convention (Subprogram_Def) /= Convention_Java
5425 Check_Duplicated_Export_Name (Link_Nam);
5427 end Process_Interface_Name;
5429 -----------------------------------------
5430 -- Process_Interrupt_Or_Attach_Handler --
5431 -----------------------------------------
5433 procedure Process_Interrupt_Or_Attach_Handler is
5434 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5435 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5436 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5439 Set_Is_Interrupt_Handler (Handler_Proc);
5441 -- If the pragma is not associated with a handler procedure within a
5442 -- protected type, then it must be for a nonprotected procedure for
5443 -- the AAMP target, in which case we don't associate a representation
5444 -- item with the procedure's scope.
5446 if Ekind (Proc_Scope) = E_Protected_Type then
5447 if Prag_Id = Pragma_Interrupt_Handler
5449 Prag_Id = Pragma_Attach_Handler
5451 Record_Rep_Item (Proc_Scope, N);
5454 end Process_Interrupt_Or_Attach_Handler;
5456 --------------------------------------------------
5457 -- Process_Restrictions_Or_Restriction_Warnings --
5458 --------------------------------------------------
5460 -- Note: some of the simple identifier cases were handled in par-prag,
5461 -- but it is harmless (and more straightforward) to simply handle all
5462 -- cases here, even if it means we repeat a bit of work in some cases.
5464 procedure Process_Restrictions_Or_Restriction_Warnings
5468 R_Id : Restriction_Id;
5473 procedure Check_Unit_Name (N : Node_Id);
5474 -- Checks unit name parameter for No_Dependence. Returns if it has
5475 -- an appropriate form, otherwise raises pragma argument error.
5477 ---------------------
5478 -- Check_Unit_Name --
5479 ---------------------
5481 procedure Check_Unit_Name (N : Node_Id) is
5483 if Nkind (N) = N_Selected_Component then
5484 Check_Unit_Name (Prefix (N));
5485 Check_Unit_Name (Selector_Name (N));
5487 elsif Nkind (N) = N_Identifier then
5492 ("wrong form for unit name for No_Dependence", N);
5494 end Check_Unit_Name;
5496 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5499 -- Ignore all Restrictions pragma in CodePeer mode
5501 if CodePeer_Mode then
5505 Check_Ada_83_Warning;
5506 Check_At_Least_N_Arguments (1);
5507 Check_Valid_Configuration_Pragma;
5510 while Present (Arg) loop
5512 Expr := Get_Pragma_Arg (Arg);
5514 -- Case of no restriction identifier present
5516 if Id = No_Name then
5517 if Nkind (Expr) /= N_Identifier then
5519 ("invalid form for restriction", Arg);
5524 (Process_Restriction_Synonyms (Expr));
5526 if R_Id not in All_Boolean_Restrictions then
5527 Error_Msg_Name_1 := Pname;
5529 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5531 -- Check for possible misspelling
5533 for J in Restriction_Id loop
5535 Rnm : constant String := Restriction_Id'Image (J);
5538 Name_Buffer (1 .. Rnm'Length) := Rnm;
5539 Name_Len := Rnm'Length;
5540 Set_Casing (All_Lower_Case);
5542 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5544 (Identifier_Casing (Current_Source_File));
5545 Error_Msg_String (1 .. Rnm'Length) :=
5546 Name_Buffer (1 .. Name_Len);
5547 Error_Msg_Strlen := Rnm'Length;
5548 Error_Msg_N -- CODEFIX
5549 ("\possible misspelling of ""~""",
5550 Get_Pragma_Arg (Arg));
5559 if Implementation_Restriction (R_Id) then
5560 Check_Restriction (No_Implementation_Restrictions, Arg);
5563 -- Special processing for No_Elaboration_Code restriction
5565 if R_Id = No_Elaboration_Code then
5567 -- Restriction is only recognized within a configuration
5568 -- pragma file, or within a unit of the main extended
5569 -- program. Note: the test for Main_Unit is needed to
5570 -- properly include the case of configuration pragma files.
5572 if not (Current_Sem_Unit = Main_Unit
5573 or else In_Extended_Main_Source_Unit (N))
5577 -- Don't allow in a subunit unless already specified in
5580 elsif Nkind (Parent (N)) = N_Compilation_Unit
5581 and then Nkind (Unit (Parent (N))) = N_Subunit
5582 and then not Restriction_Active (No_Elaboration_Code)
5585 ("invalid specification of ""No_Elaboration_Code""",
5588 ("\restriction cannot be specified in a subunit", N);
5590 ("\unless also specified in body or spec", N);
5593 -- If we have a No_Elaboration_Code pragma that we
5594 -- accept, then it needs to be added to the configuration
5595 -- restrcition set so that we get proper application to
5596 -- other units in the main extended source as required.
5599 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
5603 -- If this is a warning, then set the warning unless we already
5604 -- have a real restriction active (we never want a warning to
5605 -- override a real restriction).
5608 if not Restriction_Active (R_Id) then
5609 Set_Restriction (R_Id, N);
5610 Restriction_Warnings (R_Id) := True;
5613 -- If real restriction case, then set it and make sure that the
5614 -- restriction warning flag is off, since a real restriction
5615 -- always overrides a warning.
5618 Set_Restriction (R_Id, N);
5619 Restriction_Warnings (R_Id) := False;
5622 -- Check for obsolescent restrictions in Ada 2005 mode
5625 and then Ada_Version >= Ada_2005
5626 and then (R_Id = No_Asynchronous_Control
5628 R_Id = No_Unchecked_Deallocation
5630 R_Id = No_Unchecked_Conversion)
5632 Check_Restriction (No_Obsolescent_Features, N);
5635 -- A very special case that must be processed here: pragma
5636 -- Restrictions (No_Exceptions) turns off all run-time
5637 -- checking. This is a bit dubious in terms of the formal
5638 -- language definition, but it is what is intended by RM
5639 -- H.4(12). Restriction_Warnings never affects generated code
5640 -- so this is done only in the real restriction case.
5642 -- Atomic_Synchronization is not a real check, so it is not
5643 -- affected by this processing).
5645 if R_Id = No_Exceptions and then not Warn then
5646 for J in Scope_Suppress.Suppress'Range loop
5647 if J /= Atomic_Synchronization then
5648 Scope_Suppress.Suppress (J) := True;
5653 -- Case of No_Dependence => unit-name. Note that the parser
5654 -- already made the necessary entry in the No_Dependence table.
5656 elsif Id = Name_No_Dependence then
5657 Check_Unit_Name (Expr);
5659 -- Case of No_Specification_Of_Aspect => Identifier.
5661 elsif Id = Name_No_Specification_Of_Aspect then
5666 if Nkind (Expr) /= N_Identifier then
5669 A_Id := Get_Aspect_Id (Chars (Expr));
5672 if A_Id = No_Aspect then
5673 Error_Pragma_Arg ("invalid restriction name", Arg);
5675 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5679 -- All other cases of restriction identifier present
5682 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5683 Analyze_And_Resolve (Expr, Any_Integer);
5685 if R_Id not in All_Parameter_Restrictions then
5687 ("invalid restriction parameter identifier", Arg);
5689 elsif not Is_OK_Static_Expression (Expr) then
5690 Flag_Non_Static_Expr
5691 ("value must be static expression!", Expr);
5694 elsif not Is_Integer_Type (Etype (Expr))
5695 or else Expr_Value (Expr) < 0
5698 ("value must be non-negative integer", Arg);
5701 -- Restriction pragma is active
5703 Val := Expr_Value (Expr);
5705 if not UI_Is_In_Int_Range (Val) then
5707 ("pragma ignored, value too large?", Arg);
5710 -- Warning case. If the real restriction is active, then we
5711 -- ignore the request, since warning never overrides a real
5712 -- restriction. Otherwise we set the proper warning. Note that
5713 -- this circuit sets the warning again if it is already set,
5714 -- which is what we want, since the constant may have changed.
5717 if not Restriction_Active (R_Id) then
5719 (R_Id, N, Integer (UI_To_Int (Val)));
5720 Restriction_Warnings (R_Id) := True;
5723 -- Real restriction case, set restriction and make sure warning
5724 -- flag is off since real restriction always overrides warning.
5727 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5728 Restriction_Warnings (R_Id) := False;
5734 end Process_Restrictions_Or_Restriction_Warnings;
5736 ---------------------------------
5737 -- Process_Suppress_Unsuppress --
5738 ---------------------------------
5740 -- Note: this procedure makes entries in the check suppress data
5741 -- structures managed by Sem. See spec of package Sem for full
5742 -- details on how we handle recording of check suppression.
5744 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5749 In_Package_Spec : constant Boolean :=
5750 Is_Package_Or_Generic_Package (Current_Scope)
5751 and then not In_Package_Body (Current_Scope);
5753 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5754 -- Used to suppress a single check on the given entity
5756 --------------------------------
5757 -- Suppress_Unsuppress_Echeck --
5758 --------------------------------
5760 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5762 -- Check for error of trying to set atomic synchronization for
5763 -- a non-atomic variable.
5765 if C = Atomic_Synchronization
5766 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5769 ("pragma & requires atomic type or variable",
5770 Pragma_Identifier (Original_Node (N)));
5773 Set_Checks_May_Be_Suppressed (E);
5775 if In_Package_Spec then
5776 Push_Global_Suppress_Stack_Entry
5779 Suppress => Suppress_Case);
5781 Push_Local_Suppress_Stack_Entry
5784 Suppress => Suppress_Case);
5787 -- If this is a first subtype, and the base type is distinct,
5788 -- then also set the suppress flags on the base type.
5790 if Is_First_Subtype (E) and then Etype (E) /= E then
5791 Suppress_Unsuppress_Echeck (Etype (E), C);
5793 end Suppress_Unsuppress_Echeck;
5795 -- Start of processing for Process_Suppress_Unsuppress
5798 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5799 -- user code: we want to generate checks for analysis purposes, as
5800 -- set respectively by -gnatC and -gnatd.F
5802 if (CodePeer_Mode or Alfa_Mode) and then Comes_From_Source (N) then
5806 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5807 -- declarative part or a package spec (RM 11.5(5)).
5809 if not Is_Configuration_Pragma then
5810 Check_Is_In_Decl_Part_Or_Package_Spec;
5813 Check_At_Least_N_Arguments (1);
5814 Check_At_Most_N_Arguments (2);
5815 Check_No_Identifier (Arg1);
5816 Check_Arg_Is_Identifier (Arg1);
5818 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5820 if C = No_Check_Id then
5822 ("argument of pragma% is not valid check name", Arg1);
5825 if Arg_Count = 1 then
5827 -- Make an entry in the local scope suppress table. This is the
5828 -- table that directly shows the current value of the scope
5829 -- suppress check for any check id value.
5831 if C = All_Checks then
5833 -- For All_Checks, we set all specific predefined checks with
5834 -- the exception of Elaboration_Check, which is handled
5835 -- specially because of not wanting All_Checks to have the
5836 -- effect of deactivating static elaboration order processing.
5837 -- Atomic_Synchronization is also not affected, since this is
5838 -- not a real check.
5840 for J in Scope_Suppress.Suppress'Range loop
5841 if J /= Elaboration_Check
5843 J /= Atomic_Synchronization
5845 Scope_Suppress.Suppress (J) := Suppress_Case;
5849 -- If not All_Checks, and predefined check, then set appropriate
5850 -- scope entry. Note that we will set Elaboration_Check if this
5851 -- is explicitly specified. Atomic_Synchronization is allowed
5852 -- only if internally generated and entity is atomic.
5854 elsif C in Predefined_Check_Id
5855 and then (not Comes_From_Source (N)
5856 or else C /= Atomic_Synchronization)
5858 Scope_Suppress.Suppress (C) := Suppress_Case;
5861 -- Also make an entry in the Local_Entity_Suppress table
5863 Push_Local_Suppress_Stack_Entry
5866 Suppress => Suppress_Case);
5868 -- Case of two arguments present, where the check is suppressed for
5869 -- a specified entity (given as the second argument of the pragma)
5872 -- This is obsolescent in Ada 2005 mode
5874 if Ada_Version >= Ada_2005 then
5875 Check_Restriction (No_Obsolescent_Features, Arg2);
5878 Check_Optional_Identifier (Arg2, Name_On);
5879 E_Id := Get_Pragma_Arg (Arg2);
5882 if not Is_Entity_Name (E_Id) then
5884 ("second argument of pragma% must be entity name", Arg2);
5893 -- Enforce RM 11.5(7) which requires that for a pragma that
5894 -- appears within a package spec, the named entity must be
5895 -- within the package spec. We allow the package name itself
5896 -- to be mentioned since that makes sense, although it is not
5897 -- strictly allowed by 11.5(7).
5900 and then E /= Current_Scope
5901 and then Scope (E) /= Current_Scope
5904 ("entity in pragma% is not in package spec (RM 11.5(7))",
5908 -- Loop through homonyms. As noted below, in the case of a package
5909 -- spec, only homonyms within the package spec are considered.
5912 Suppress_Unsuppress_Echeck (E, C);
5914 if Is_Generic_Instance (E)
5915 and then Is_Subprogram (E)
5916 and then Present (Alias (E))
5918 Suppress_Unsuppress_Echeck (Alias (E), C);
5921 -- Move to next homonym if not aspect spec case
5923 exit when From_Aspect_Specification (N);
5927 -- If we are within a package specification, the pragma only
5928 -- applies to homonyms in the same scope.
5930 exit when In_Package_Spec
5931 and then Scope (E) /= Current_Scope;
5934 end Process_Suppress_Unsuppress;
5940 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5942 if Is_Imported (E) then
5944 ("cannot export entity& that was previously imported", Arg);
5946 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5948 ("cannot export entity& that has an address clause", Arg);
5951 Set_Is_Exported (E);
5953 -- Generate a reference for entity explicitly, because the
5954 -- identifier may be overloaded and name resolution will not
5957 Generate_Reference (E, Arg);
5959 -- Deal with exporting non-library level entity
5961 if not Is_Library_Level_Entity (E) then
5963 -- Not allowed at all for subprograms
5965 if Is_Subprogram (E) then
5966 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5968 -- Otherwise set public and statically allocated
5972 Set_Is_Statically_Allocated (E);
5974 -- Warn if the corresponding W flag is set and the pragma comes
5975 -- from source. The latter may not be true e.g. on VMS where we
5976 -- expand export pragmas for exception codes associated with
5977 -- imported or exported exceptions. We do not want to generate
5978 -- a warning for something that the user did not write.
5980 if Warn_On_Export_Import
5981 and then Comes_From_Source (Arg)
5984 ("?& has been made static as a result of Export", Arg, E);
5986 ("\this usage is non-standard and non-portable", Arg);
5991 if Warn_On_Export_Import and then Is_Type (E) then
5992 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5995 if Warn_On_Export_Import and Inside_A_Generic then
5997 ("all instances of& will have the same external name?", Arg, E);
6001 ----------------------------------------------
6002 -- Set_Extended_Import_Export_External_Name --
6003 ----------------------------------------------
6005 procedure Set_Extended_Import_Export_External_Name
6006 (Internal_Ent : Entity_Id;
6007 Arg_External : Node_Id)
6009 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
6013 if No (Arg_External) then
6017 Check_Arg_Is_External_Name (Arg_External);
6019 if Nkind (Arg_External) = N_String_Literal then
6020 if String_Length (Strval (Arg_External)) = 0 then
6023 New_Name := Adjust_External_Name_Case (Arg_External);
6026 elsif Nkind (Arg_External) = N_Identifier then
6027 New_Name := Get_Default_External_Name (Arg_External);
6029 -- Check_Arg_Is_External_Name should let through only identifiers and
6030 -- string literals or static string expressions (which are folded to
6031 -- string literals).
6034 raise Program_Error;
6037 -- If we already have an external name set (by a prior normal Import
6038 -- or Export pragma), then the external names must match
6040 if Present (Interface_Name (Internal_Ent)) then
6041 Check_Matching_Internal_Names : declare
6042 S1 : constant String_Id := Strval (Old_Name);
6043 S2 : constant String_Id := Strval (New_Name);
6046 -- Called if names do not match
6052 procedure Mismatch is
6054 Error_Msg_Sloc := Sloc (Old_Name);
6056 ("external name does not match that given #",
6060 -- Start of processing for Check_Matching_Internal_Names
6063 if String_Length (S1) /= String_Length (S2) then
6067 for J in 1 .. String_Length (S1) loop
6068 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
6073 end Check_Matching_Internal_Names;
6075 -- Otherwise set the given name
6078 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
6079 Check_Duplicated_Export_Name (New_Name);
6081 end Set_Extended_Import_Export_External_Name;
6087 procedure Set_Imported (E : Entity_Id) is
6089 -- Error message if already imported or exported
6091 if Is_Exported (E) or else Is_Imported (E) then
6093 -- Error if being set Exported twice
6095 if Is_Exported (E) then
6096 Error_Msg_NE ("entity& was previously exported", N, E);
6098 -- OK if Import/Interface case
6100 elsif Import_Interface_Present (N) then
6103 -- Error if being set Imported twice
6106 Error_Msg_NE ("entity& was previously imported", N, E);
6109 Error_Msg_Name_1 := Pname;
6111 ("\(pragma% applies to all previous entities)", N);
6113 Error_Msg_Sloc := Sloc (E);
6114 Error_Msg_NE ("\import not allowed for& declared#", N, E);
6116 -- Here if not previously imported or exported, OK to import
6119 Set_Is_Imported (E);
6121 -- If the entity is an object that is not at the library level,
6122 -- then it is statically allocated. We do not worry about objects
6123 -- with address clauses in this context since they are not really
6124 -- imported in the linker sense.
6127 and then not Is_Library_Level_Entity (E)
6128 and then No (Address_Clause (E))
6130 Set_Is_Statically_Allocated (E);
6137 -------------------------
6138 -- Set_Mechanism_Value --
6139 -------------------------
6141 -- Note: the mechanism name has not been analyzed (and cannot indeed be
6142 -- analyzed, since it is semantic nonsense), so we get it in the exact
6143 -- form created by the parser.
6145 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
6148 Mech_Name_Id : Name_Id;
6150 procedure Bad_Class;
6151 -- Signal bad descriptor class name
6153 procedure Bad_Mechanism;
6154 -- Signal bad mechanism name
6160 procedure Bad_Class is
6162 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
6165 -------------------------
6166 -- Bad_Mechanism_Value --
6167 -------------------------
6169 procedure Bad_Mechanism is
6171 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
6174 -- Start of processing for Set_Mechanism_Value
6177 if Mechanism (Ent) /= Default_Mechanism then
6179 ("mechanism for & has already been set", Mech_Name, Ent);
6182 -- MECHANISM_NAME ::= value | reference | descriptor |
6185 if Nkind (Mech_Name) = N_Identifier then
6186 if Chars (Mech_Name) = Name_Value then
6187 Set_Mechanism (Ent, By_Copy);
6190 elsif Chars (Mech_Name) = Name_Reference then
6191 Set_Mechanism (Ent, By_Reference);
6194 elsif Chars (Mech_Name) = Name_Descriptor then
6195 Check_VMS (Mech_Name);
6197 -- Descriptor => Short_Descriptor if pragma was given
6199 if Short_Descriptors then
6200 Set_Mechanism (Ent, By_Short_Descriptor);
6202 Set_Mechanism (Ent, By_Descriptor);
6207 elsif Chars (Mech_Name) = Name_Short_Descriptor then
6208 Check_VMS (Mech_Name);
6209 Set_Mechanism (Ent, By_Short_Descriptor);
6212 elsif Chars (Mech_Name) = Name_Copy then
6214 ("bad mechanism name, Value assumed", Mech_Name);
6220 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
6221 -- short_descriptor (CLASS_NAME)
6222 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6224 -- Note: this form is parsed as an indexed component
6226 elsif Nkind (Mech_Name) = N_Indexed_Component then
6227 Class := First (Expressions (Mech_Name));
6229 if Nkind (Prefix (Mech_Name)) /= N_Identifier
6230 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
6231 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
6232 or else Present (Next (Class))
6236 Mech_Name_Id := Chars (Prefix (Mech_Name));
6238 -- Change Descriptor => Short_Descriptor if pragma was given
6240 if Mech_Name_Id = Name_Descriptor
6241 and then Short_Descriptors
6243 Mech_Name_Id := Name_Short_Descriptor;
6247 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6248 -- short_descriptor (Class => CLASS_NAME)
6249 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6251 -- Note: this form is parsed as a function call
6253 elsif Nkind (Mech_Name) = N_Function_Call then
6254 Param := First (Parameter_Associations (Mech_Name));
6256 if Nkind (Name (Mech_Name)) /= N_Identifier
6257 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6258 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6259 or else Present (Next (Param))
6260 or else No (Selector_Name (Param))
6261 or else Chars (Selector_Name (Param)) /= Name_Class
6265 Class := Explicit_Actual_Parameter (Param);
6266 Mech_Name_Id := Chars (Name (Mech_Name));
6273 -- Fall through here with Class set to descriptor class name
6275 Check_VMS (Mech_Name);
6277 if Nkind (Class) /= N_Identifier then
6280 elsif Mech_Name_Id = Name_Descriptor
6281 and then Chars (Class) = Name_UBS
6283 Set_Mechanism (Ent, By_Descriptor_UBS);
6285 elsif Mech_Name_Id = Name_Descriptor
6286 and then Chars (Class) = Name_UBSB
6288 Set_Mechanism (Ent, By_Descriptor_UBSB);
6290 elsif Mech_Name_Id = Name_Descriptor
6291 and then Chars (Class) = Name_UBA
6293 Set_Mechanism (Ent, By_Descriptor_UBA);
6295 elsif Mech_Name_Id = Name_Descriptor
6296 and then Chars (Class) = Name_S
6298 Set_Mechanism (Ent, By_Descriptor_S);
6300 elsif Mech_Name_Id = Name_Descriptor
6301 and then Chars (Class) = Name_SB
6303 Set_Mechanism (Ent, By_Descriptor_SB);
6305 elsif Mech_Name_Id = Name_Descriptor
6306 and then Chars (Class) = Name_A
6308 Set_Mechanism (Ent, By_Descriptor_A);
6310 elsif Mech_Name_Id = Name_Descriptor
6311 and then Chars (Class) = Name_NCA
6313 Set_Mechanism (Ent, By_Descriptor_NCA);
6315 elsif Mech_Name_Id = Name_Short_Descriptor
6316 and then Chars (Class) = Name_UBS
6318 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6320 elsif Mech_Name_Id = Name_Short_Descriptor
6321 and then Chars (Class) = Name_UBSB
6323 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6325 elsif Mech_Name_Id = Name_Short_Descriptor
6326 and then Chars (Class) = Name_UBA
6328 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6330 elsif Mech_Name_Id = Name_Short_Descriptor
6331 and then Chars (Class) = Name_S
6333 Set_Mechanism (Ent, By_Short_Descriptor_S);
6335 elsif Mech_Name_Id = Name_Short_Descriptor
6336 and then Chars (Class) = Name_SB
6338 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6340 elsif Mech_Name_Id = Name_Short_Descriptor
6341 and then Chars (Class) = Name_A
6343 Set_Mechanism (Ent, By_Short_Descriptor_A);
6345 elsif Mech_Name_Id = Name_Short_Descriptor
6346 and then Chars (Class) = Name_NCA
6348 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6353 end Set_Mechanism_Value;
6355 ---------------------------
6356 -- Set_Ravenscar_Profile --
6357 ---------------------------
6359 -- The tasks to be done here are
6361 -- Set required policies
6363 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6364 -- pragma Locking_Policy (Ceiling_Locking)
6366 -- Set Detect_Blocking mode
6368 -- Set required restrictions (see System.Rident for detailed list)
6370 -- Set the No_Dependence rules
6371 -- No_Dependence => Ada.Asynchronous_Task_Control
6372 -- No_Dependence => Ada.Calendar
6373 -- No_Dependence => Ada.Execution_Time.Group_Budget
6374 -- No_Dependence => Ada.Execution_Time.Timers
6375 -- No_Dependence => Ada.Task_Attributes
6376 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6378 procedure Set_Ravenscar_Profile (N : Node_Id) is
6379 Prefix_Entity : Entity_Id;
6380 Selector_Entity : Entity_Id;
6381 Prefix_Node : Node_Id;
6385 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6387 if Task_Dispatching_Policy /= ' '
6388 and then Task_Dispatching_Policy /= 'F'
6390 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6391 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6393 -- Set the FIFO_Within_Priorities policy, but always preserve
6394 -- System_Location since we like the error message with the run time
6398 Task_Dispatching_Policy := 'F';
6400 if Task_Dispatching_Policy_Sloc /= System_Location then
6401 Task_Dispatching_Policy_Sloc := Loc;
6405 -- pragma Locking_Policy (Ceiling_Locking)
6407 if Locking_Policy /= ' '
6408 and then Locking_Policy /= 'C'
6410 Error_Msg_Sloc := Locking_Policy_Sloc;
6411 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6413 -- Set the Ceiling_Locking policy, but preserve System_Location since
6414 -- we like the error message with the run time name.
6417 Locking_Policy := 'C';
6419 if Locking_Policy_Sloc /= System_Location then
6420 Locking_Policy_Sloc := Loc;
6424 -- pragma Detect_Blocking
6426 Detect_Blocking := True;
6428 -- Set the corresponding restrictions
6430 Set_Profile_Restrictions
6431 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6433 -- Set the No_Dependence restrictions
6435 -- The following No_Dependence restrictions:
6436 -- No_Dependence => Ada.Asynchronous_Task_Control
6437 -- No_Dependence => Ada.Calendar
6438 -- No_Dependence => Ada.Task_Attributes
6439 -- are already set by previous call to Set_Profile_Restrictions.
6441 -- Set the following restrictions which were added to Ada 2005:
6442 -- No_Dependence => Ada.Execution_Time.Group_Budget
6443 -- No_Dependence => Ada.Execution_Time.Timers
6445 if Ada_Version >= Ada_2005 then
6446 Name_Buffer (1 .. 3) := "ada";
6449 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6451 Name_Buffer (1 .. 14) := "execution_time";
6454 Selector_Entity := Make_Identifier (Loc, Name_Find);
6457 Make_Selected_Component
6459 Prefix => Prefix_Entity,
6460 Selector_Name => Selector_Entity);
6462 Name_Buffer (1 .. 13) := "group_budgets";
6465 Selector_Entity := Make_Identifier (Loc, Name_Find);
6468 Make_Selected_Component
6470 Prefix => Prefix_Node,
6471 Selector_Name => Selector_Entity);
6473 Set_Restriction_No_Dependence
6475 Warn => Treat_Restrictions_As_Warnings,
6476 Profile => Ravenscar);
6478 Name_Buffer (1 .. 6) := "timers";
6481 Selector_Entity := Make_Identifier (Loc, Name_Find);
6484 Make_Selected_Component
6486 Prefix => Prefix_Node,
6487 Selector_Name => Selector_Entity);
6489 Set_Restriction_No_Dependence
6491 Warn => Treat_Restrictions_As_Warnings,
6492 Profile => Ravenscar);
6495 -- Set the following restrictions which was added to Ada 2012 (see
6497 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6499 if Ada_Version >= Ada_2012 then
6500 Name_Buffer (1 .. 6) := "system";
6503 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6505 Name_Buffer (1 .. 15) := "multiprocessors";
6508 Selector_Entity := Make_Identifier (Loc, Name_Find);
6511 Make_Selected_Component
6513 Prefix => Prefix_Entity,
6514 Selector_Name => Selector_Entity);
6516 Name_Buffer (1 .. 19) := "dispatching_domains";
6519 Selector_Entity := Make_Identifier (Loc, Name_Find);
6522 Make_Selected_Component
6524 Prefix => Prefix_Node,
6525 Selector_Name => Selector_Entity);
6527 Set_Restriction_No_Dependence
6529 Warn => Treat_Restrictions_As_Warnings,
6530 Profile => Ravenscar);
6532 end Set_Ravenscar_Profile;
6538 procedure S14_Pragma is
6540 if not Formal_Extensions then
6541 Error_Pragma ("pragma% requires the use of debug switch -gnatd.V");
6545 -- Start of processing for Analyze_Pragma
6548 -- The following code is a defense against recursion. Not clear that
6549 -- this can happen legitimately, but perhaps some error situations
6550 -- can cause it, and we did see this recursion during testing.
6552 if Analyzed (N) then
6555 Set_Analyzed (N, True);
6558 -- Deal with unrecognized pragma
6560 Pname := Pragma_Name (N);
6562 if not Is_Pragma_Name (Pname) then
6563 if Warn_On_Unrecognized_Pragma then
6564 Error_Msg_Name_1 := Pname;
6565 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6567 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6568 if Is_Bad_Spelling_Of (Pname, PN) then
6569 Error_Msg_Name_1 := PN;
6570 Error_Msg_N -- CODEFIX
6571 ("\?possible misspelling of %!", Pragma_Identifier (N));
6580 -- Here to start processing for recognized pragma
6582 Prag_Id := Get_Pragma_Id (Pname);
6584 if Present (Corresponding_Aspect (N)) then
6585 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6596 if Present (Pragma_Argument_Associations (N)) then
6597 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6598 Arg1 := First (Pragma_Argument_Associations (N));
6600 if Present (Arg1) then
6601 Arg2 := Next (Arg1);
6603 if Present (Arg2) then
6604 Arg3 := Next (Arg2);
6606 if Present (Arg3) then
6607 Arg4 := Next (Arg3);
6613 -- An enumeration type defines the pragmas that are supported by the
6614 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6615 -- into the corresponding enumeration value for the following case.
6623 -- pragma Abort_Defer;
6625 when Pragma_Abort_Defer =>
6627 Check_Arg_Count (0);
6629 -- The only required semantic processing is to check the
6630 -- placement. This pragma must appear at the start of the
6631 -- statement sequence of a handled sequence of statements.
6633 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6634 or else N /= First (Statements (Parent (N)))
6645 -- Note: this pragma also has some specific processing in Par.Prag
6646 -- because we want to set the Ada version mode during parsing.
6648 when Pragma_Ada_83 =>
6650 Check_Arg_Count (0);
6652 -- We really should check unconditionally for proper configuration
6653 -- pragma placement, since we really don't want mixed Ada modes
6654 -- within a single unit, and the GNAT reference manual has always
6655 -- said this was a configuration pragma, but we did not check and
6656 -- are hesitant to add the check now.
6658 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6659 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6660 -- or Ada 2012 mode.
6662 if Ada_Version >= Ada_2005 then
6663 Check_Valid_Configuration_Pragma;
6666 -- Now set Ada 83 mode
6668 Ada_Version := Ada_83;
6669 Ada_Version_Explicit := Ada_Version;
6677 -- Note: this pragma also has some specific processing in Par.Prag
6678 -- because we want to set the Ada 83 version mode during parsing.
6680 when Pragma_Ada_95 =>
6682 Check_Arg_Count (0);
6684 -- We really should check unconditionally for proper configuration
6685 -- pragma placement, since we really don't want mixed Ada modes
6686 -- within a single unit, and the GNAT reference manual has always
6687 -- said this was a configuration pragma, but we did not check and
6688 -- are hesitant to add the check now.
6690 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6691 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6693 if Ada_Version >= Ada_2005 then
6694 Check_Valid_Configuration_Pragma;
6697 -- Now set Ada 95 mode
6699 Ada_Version := Ada_95;
6700 Ada_Version_Explicit := Ada_Version;
6702 ---------------------
6703 -- Ada_05/Ada_2005 --
6704 ---------------------
6707 -- pragma Ada_05 (LOCAL_NAME);
6710 -- pragma Ada_2005 (LOCAL_NAME):
6712 -- Note: these pragmas also have some specific processing in Par.Prag
6713 -- because we want to set the Ada 2005 version mode during parsing.
6715 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6721 if Arg_Count = 1 then
6722 Check_Arg_Is_Local_Name (Arg1);
6723 E_Id := Get_Pragma_Arg (Arg1);
6725 if Etype (E_Id) = Any_Type then
6729 Set_Is_Ada_2005_Only (Entity (E_Id));
6730 Record_Rep_Item (Entity (E_Id), N);
6733 Check_Arg_Count (0);
6735 -- For Ada_2005 we unconditionally enforce the documented
6736 -- configuration pragma placement, since we do not want to
6737 -- tolerate mixed modes in a unit involving Ada 2005. That
6738 -- would cause real difficulties for those cases where there
6739 -- are incompatibilities between Ada 95 and Ada 2005.
6741 Check_Valid_Configuration_Pragma;
6743 -- Now set appropriate Ada mode
6745 Ada_Version := Ada_2005;
6746 Ada_Version_Explicit := Ada_2005;
6750 ---------------------
6751 -- Ada_12/Ada_2012 --
6752 ---------------------
6755 -- pragma Ada_12 (LOCAL_NAME);
6758 -- pragma Ada_2012 (LOCAL_NAME):
6760 -- Note: these pragmas also have some specific processing in Par.Prag
6761 -- because we want to set the Ada 2012 version mode during parsing.
6763 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6769 if Arg_Count = 1 then
6770 Check_Arg_Is_Local_Name (Arg1);
6771 E_Id := Get_Pragma_Arg (Arg1);
6773 if Etype (E_Id) = Any_Type then
6777 Set_Is_Ada_2012_Only (Entity (E_Id));
6778 Record_Rep_Item (Entity (E_Id), N);
6781 Check_Arg_Count (0);
6783 -- For Ada_2012 we unconditionally enforce the documented
6784 -- configuration pragma placement, since we do not want to
6785 -- tolerate mixed modes in a unit involving Ada 2012. That
6786 -- would cause real difficulties for those cases where there
6787 -- are incompatibilities between Ada 95 and Ada 2012. We could
6788 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6790 Check_Valid_Configuration_Pragma;
6792 -- Now set appropriate Ada mode
6794 Ada_Version := Ada_2012;
6795 Ada_Version_Explicit := Ada_2012;
6799 ----------------------
6800 -- All_Calls_Remote --
6801 ----------------------
6803 -- pragma All_Calls_Remote [(library_package_NAME)];
6805 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6806 Lib_Entity : Entity_Id;
6809 Check_Ada_83_Warning;
6810 Check_Valid_Library_Unit_Pragma;
6812 if Nkind (N) = N_Null_Statement then
6816 Lib_Entity := Find_Lib_Unit_Name;
6818 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6820 if Present (Lib_Entity)
6821 and then not Debug_Flag_U
6823 if not Is_Remote_Call_Interface (Lib_Entity) then
6824 Error_Pragma ("pragma% only apply to rci unit");
6826 -- Set flag for entity of the library unit
6829 Set_Has_All_Calls_Remote (Lib_Entity);
6833 end All_Calls_Remote;
6839 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6840 -- ARG ::= NAME | EXPRESSION
6842 -- The first two arguments are by convention intended to refer to an
6843 -- external tool and a tool-specific function. These arguments are
6846 when Pragma_Annotate => Annotate : declare
6852 Check_At_Least_N_Arguments (1);
6853 Check_Arg_Is_Identifier (Arg1);
6854 Check_No_Identifiers;
6857 -- Second parameter is optional, it is never analyzed
6862 -- Here if we have a second parameter
6865 -- Second parameter must be identifier
6867 Check_Arg_Is_Identifier (Arg2);
6869 -- Process remaining parameters if any
6872 while Present (Arg) loop
6873 Exp := Get_Pragma_Arg (Arg);
6876 if Is_Entity_Name (Exp) then
6879 -- For string literals, we assume Standard_String as the
6880 -- type, unless the string contains wide or wide_wide
6883 elsif Nkind (Exp) = N_String_Literal then
6884 if Has_Wide_Wide_Character (Exp) then
6885 Resolve (Exp, Standard_Wide_Wide_String);
6886 elsif Has_Wide_Character (Exp) then
6887 Resolve (Exp, Standard_Wide_String);
6889 Resolve (Exp, Standard_String);
6892 elsif Is_Overloaded (Exp) then
6894 ("ambiguous argument for pragma%", Exp);
6905 ---------------------------
6906 -- Assert/Assert_And_Cut --
6907 ---------------------------
6910 -- ( [Check => ] Boolean_EXPRESSION
6911 -- [, [Message =>] Static_String_EXPRESSION]);
6913 -- pragma Assert_And_Cut
6914 -- ( [Check => ] Boolean_EXPRESSION
6915 -- [, [Message =>] Static_String_EXPRESSION]);
6917 when Pragma_Assert | Pragma_Assert_And_Cut => Assert : declare
6922 if Prag_Id = Pragma_Assert then
6924 else -- Pragma_Assert_And_Cut
6929 Check_At_Least_N_Arguments (1);
6930 Check_At_Most_N_Arguments (2);
6931 Check_Arg_Order ((Name_Check, Name_Message));
6932 Check_Optional_Identifier (Arg1, Name_Check);
6934 -- We treat pragma Assert as equivalent to:
6936 -- pragma Check (Assertion, condition [, msg]);
6938 -- So rewrite pragma in this manner, transfer the message
6939 -- argument if present, and analyze the result
6941 -- Pragma Assert_And_Cut is treated exactly like pragma Assert by
6942 -- the frontend. Formal verification tools may use it to "cut" the
6943 -- paths through the code, to make verification tractable. When
6944 -- dealing with a semantically analyzed tree, the information that
6945 -- a Check node N corresponds to a source Assert_And_Cut pragma
6946 -- can be retrieved from the pragma kind of Original_Node(N).
6948 Expr := Get_Pragma_Arg (Arg1);
6950 Make_Pragma_Argument_Association (Loc,
6951 Expression => Make_Identifier (Loc, Name_Assertion)),
6953 Make_Pragma_Argument_Association (Sloc (Expr),
6954 Expression => Expr));
6956 if Arg_Count > 1 then
6957 Check_Optional_Identifier (Arg2, Name_Message);
6958 Append_To (Newa, New_Copy_Tree (Arg2));
6963 Chars => Name_Check,
6964 Pragma_Argument_Associations => Newa));
6968 ----------------------
6969 -- Assertion_Policy --
6970 ----------------------
6972 -- pragma Assertion_Policy (Check | Disable | Ignore)
6974 when Pragma_Assertion_Policy => Assertion_Policy : declare
6979 Check_Valid_Configuration_Pragma;
6980 Check_Arg_Count (1);
6981 Check_No_Identifiers;
6982 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6984 -- We treat pragma Assertion_Policy as equivalent to:
6986 -- pragma Check_Policy (Assertion, policy)
6988 -- So rewrite the pragma in that manner and link on to the chain
6989 -- of Check_Policy pragmas, marking the pragma as analyzed.
6991 Policy := Get_Pragma_Arg (Arg1);
6995 Chars => Name_Check_Policy,
6997 Pragma_Argument_Associations => New_List (
6998 Make_Pragma_Argument_Association (Loc,
6999 Expression => Make_Identifier (Loc, Name_Assertion)),
7001 Make_Pragma_Argument_Association (Loc,
7003 Make_Identifier (Sloc (Policy), Chars (Policy))))));
7006 Set_Next_Pragma (N, Opt.Check_Policy_List);
7007 Opt.Check_Policy_List := N;
7008 end Assertion_Policy;
7014 -- pragma Assume (boolean_EXPRESSION);
7016 when Pragma_Assume => Assume : declare
7020 Check_Arg_Count (1);
7022 -- Pragma Assume is transformed into pragma Check in the following
7025 -- pragma Check (Assume, Expr);
7029 Chars => Name_Check,
7030 Pragma_Argument_Associations => New_List (
7031 Make_Pragma_Argument_Association (Loc,
7032 Expression => Make_Identifier (Loc, Name_Assume)),
7034 Make_Pragma_Argument_Association (Loc,
7035 Expression => Relocate_Node (Expression (Arg1))))));
7039 ------------------------------
7040 -- Assume_No_Invalid_Values --
7041 ------------------------------
7043 -- pragma Assume_No_Invalid_Values (On | Off);
7045 when Pragma_Assume_No_Invalid_Values =>
7047 Check_Valid_Configuration_Pragma;
7048 Check_Arg_Count (1);
7049 Check_No_Identifiers;
7050 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7052 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
7053 Assume_No_Invalid_Values := True;
7055 Assume_No_Invalid_Values := False;
7058 --------------------------
7059 -- Attribute_Definition --
7060 --------------------------
7062 -- pragma Attribute_Definition
7063 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
7064 -- [Entity =>] LOCAL_NAME,
7065 -- [Expression =>] EXPRESSION | NAME);
7067 when Pragma_Attribute_Definition => Attribute_Definition : declare
7068 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
7073 Check_Arg_Count (3);
7074 Check_Optional_Identifier (Arg1, "attribute");
7075 Check_Optional_Identifier (Arg2, "entity");
7076 Check_Optional_Identifier (Arg3, "expression");
7078 if Nkind (Attribute_Designator) /= N_Identifier then
7079 Error_Msg_N ("attribute name expected", Attribute_Designator);
7083 Check_Arg_Is_Local_Name (Arg2);
7085 -- If the attribute is not recognized, then issue a warning (not
7086 -- an error), and ignore the pragma.
7088 Aname := Chars (Attribute_Designator);
7090 if not Is_Attribute_Name (Aname) then
7091 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
7095 -- Otherwise, rewrite the pragma as an attribute definition clause
7098 Make_Attribute_Definition_Clause (Loc,
7099 Name => Get_Pragma_Arg (Arg2),
7101 Expression => Get_Pragma_Arg (Arg3)));
7103 end Attribute_Definition;
7109 -- pragma AST_Entry (entry_IDENTIFIER);
7111 when Pragma_AST_Entry => AST_Entry : declare
7117 Check_Arg_Count (1);
7118 Check_No_Identifiers;
7119 Check_Arg_Is_Local_Name (Arg1);
7120 Ent := Entity (Get_Pragma_Arg (Arg1));
7122 -- Note: the implementation of the AST_Entry pragma could handle
7123 -- the entry family case fine, but for now we are consistent with
7124 -- the DEC rules, and do not allow the pragma, which of course
7125 -- has the effect of also forbidding the attribute.
7127 if Ekind (Ent) /= E_Entry then
7129 ("pragma% argument must be simple entry name", Arg1);
7131 elsif Is_AST_Entry (Ent) then
7133 ("duplicate % pragma for entry", Arg1);
7135 elsif Has_Homonym (Ent) then
7137 ("pragma% argument cannot specify overloaded entry", Arg1);
7141 FF : constant Entity_Id := First_Formal (Ent);
7144 if Present (FF) then
7145 if Present (Next_Formal (FF)) then
7147 ("entry for pragma% can have only one argument",
7150 elsif Parameter_Mode (FF) /= E_In_Parameter then
7152 ("entry parameter for pragma% must have mode IN",
7158 Set_Is_AST_Entry (Ent);
7166 -- pragma Asynchronous (LOCAL_NAME);
7168 when Pragma_Asynchronous => Asynchronous : declare
7176 procedure Process_Async_Pragma;
7177 -- Common processing for procedure and access-to-procedure case
7179 --------------------------
7180 -- Process_Async_Pragma --
7181 --------------------------
7183 procedure Process_Async_Pragma is
7186 Set_Is_Asynchronous (Nm);
7190 -- The formals should be of mode IN (RM E.4.1(6))
7193 while Present (S) loop
7194 Formal := Defining_Identifier (S);
7196 if Nkind (Formal) = N_Defining_Identifier
7197 and then Ekind (Formal) /= E_In_Parameter
7200 ("pragma% procedure can only have IN parameter",
7207 Set_Is_Asynchronous (Nm);
7208 end Process_Async_Pragma;
7210 -- Start of processing for pragma Asynchronous
7213 Check_Ada_83_Warning;
7214 Check_No_Identifiers;
7215 Check_Arg_Count (1);
7216 Check_Arg_Is_Local_Name (Arg1);
7218 if Debug_Flag_U then
7222 C_Ent := Cunit_Entity (Current_Sem_Unit);
7223 Analyze (Get_Pragma_Arg (Arg1));
7224 Nm := Entity (Get_Pragma_Arg (Arg1));
7226 if not Is_Remote_Call_Interface (C_Ent)
7227 and then not Is_Remote_Types (C_Ent)
7229 -- This pragma should only appear in an RCI or Remote Types
7230 -- unit (RM E.4.1(4)).
7233 ("pragma% not in Remote_Call_Interface or " &
7234 "Remote_Types unit");
7237 if Ekind (Nm) = E_Procedure
7238 and then Nkind (Parent (Nm)) = N_Procedure_Specification
7240 if not Is_Remote_Call_Interface (Nm) then
7242 ("pragma% cannot be applied on non-remote procedure",
7246 L := Parameter_Specifications (Parent (Nm));
7247 Process_Async_Pragma;
7250 elsif Ekind (Nm) = E_Function then
7252 ("pragma% cannot be applied to function", Arg1);
7254 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
7255 if Is_Record_Type (Nm) then
7257 -- A record type that is the Equivalent_Type for a remote
7258 -- access-to-subprogram type.
7260 N := Declaration_Node (Corresponding_Remote_Type (Nm));
7263 -- A non-expanded RAS type (distribution is not enabled)
7265 N := Declaration_Node (Nm);
7268 if Nkind (N) = N_Full_Type_Declaration
7269 and then Nkind (Type_Definition (N)) =
7270 N_Access_Procedure_Definition
7272 L := Parameter_Specifications (Type_Definition (N));
7273 Process_Async_Pragma;
7275 if Is_Asynchronous (Nm)
7276 and then Expander_Active
7277 and then Get_PCS_Name /= Name_No_DSA
7279 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
7284 ("pragma% cannot reference access-to-function type",
7288 -- Only other possibility is Access-to-class-wide type
7290 elsif Is_Access_Type (Nm)
7291 and then Is_Class_Wide_Type (Designated_Type (Nm))
7293 Check_First_Subtype (Arg1);
7294 Set_Is_Asynchronous (Nm);
7295 if Expander_Active then
7296 RACW_Type_Is_Asynchronous (Nm);
7300 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
7308 -- pragma Atomic (LOCAL_NAME);
7310 when Pragma_Atomic =>
7311 Process_Atomic_Shared_Volatile;
7313 -----------------------
7314 -- Atomic_Components --
7315 -----------------------
7317 -- pragma Atomic_Components (array_LOCAL_NAME);
7319 -- This processing is shared by Volatile_Components
7321 when Pragma_Atomic_Components |
7322 Pragma_Volatile_Components =>
7324 Atomic_Components : declare
7331 Check_Ada_83_Warning;
7332 Check_No_Identifiers;
7333 Check_Arg_Count (1);
7334 Check_Arg_Is_Local_Name (Arg1);
7335 E_Id := Get_Pragma_Arg (Arg1);
7337 if Etype (E_Id) = Any_Type then
7343 Check_Duplicate_Pragma (E);
7345 if Rep_Item_Too_Early (E, N)
7347 Rep_Item_Too_Late (E, N)
7352 D := Declaration_Node (E);
7355 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7357 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7358 and then Nkind (D) = N_Object_Declaration
7359 and then Nkind (Object_Definition (D)) =
7360 N_Constrained_Array_Definition)
7362 -- The flag is set on the object, or on the base type
7364 if Nkind (D) /= N_Object_Declaration then
7368 Set_Has_Volatile_Components (E);
7370 if Prag_Id = Pragma_Atomic_Components then
7371 Set_Has_Atomic_Components (E);
7375 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7377 end Atomic_Components;
7379 --------------------
7380 -- Attach_Handler --
7381 --------------------
7383 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7385 when Pragma_Attach_Handler =>
7386 Check_Ada_83_Warning;
7387 Check_No_Identifiers;
7388 Check_Arg_Count (2);
7390 if No_Run_Time_Mode then
7391 Error_Msg_CRT ("Attach_Handler pragma", N);
7393 Check_Interrupt_Or_Attach_Handler;
7395 -- The expression that designates the attribute may depend on a
7396 -- discriminant, and is therefore a per-object expression, to
7397 -- be expanded in the init proc. If expansion is enabled, then
7398 -- perform semantic checks on a copy only.
7400 if Expander_Active then
7402 Temp : constant Node_Id :=
7403 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7405 Set_Parent (Temp, N);
7406 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7410 Analyze (Get_Pragma_Arg (Arg2));
7411 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7414 Process_Interrupt_Or_Attach_Handler;
7417 --------------------
7418 -- C_Pass_By_Copy --
7419 --------------------
7421 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7423 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7429 Check_Valid_Configuration_Pragma;
7430 Check_Arg_Count (1);
7431 Check_Optional_Identifier (Arg1, "max_size");
7433 Arg := Get_Pragma_Arg (Arg1);
7434 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7436 Val := Expr_Value (Arg);
7440 ("maximum size for pragma% must be positive", Arg1);
7442 elsif UI_Is_In_Int_Range (Val) then
7443 Default_C_Record_Mechanism := UI_To_Int (Val);
7445 -- If a giant value is given, Int'Last will do well enough.
7446 -- If sometime someone complains that a record larger than
7447 -- two gigabytes is not copied, we will worry about it then!
7450 Default_C_Record_Mechanism := Mechanism_Type'Last;
7458 -- pragma Check ([Name =>] IDENTIFIER,
7459 -- [Check =>] Boolean_EXPRESSION
7460 -- [,[Message =>] String_EXPRESSION]);
7462 when Pragma_Check => Check : declare
7468 -- Set True if category of assertions referenced by Name enabled
7472 Check_At_Least_N_Arguments (2);
7473 Check_At_Most_N_Arguments (3);
7474 Check_Optional_Identifier (Arg1, Name_Name);
7475 Check_Optional_Identifier (Arg2, Name_Check);
7477 if Arg_Count = 3 then
7478 Check_Optional_Identifier (Arg3, Name_Message);
7479 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7482 Check_Arg_Is_Identifier (Arg1);
7484 -- Completely ignore if disabled
7486 if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7487 Rewrite (N, Make_Null_Statement (Loc));
7492 Cname := Chars (Get_Pragma_Arg (Arg1));
7493 Check_On := Check_Enabled (Cname);
7496 when Name_Predicate |
7499 -- Nothing to do: since checks occur in client units,
7500 -- the SCO for the aspect in the declaration unit is
7501 -- conservatively always enabled.
7507 if Check_On and then not Split_PPC (N) then
7509 -- Mark pragma/aspect SCO as enabled
7511 Set_SCO_Pragma_Enabled (Loc);
7515 -- If expansion is active and the check is not enabled then we
7516 -- rewrite the Check as:
7518 -- if False and then condition then
7522 -- The reason we do this rewriting during semantic analysis rather
7523 -- than as part of normal expansion is that we cannot analyze and
7524 -- expand the code for the boolean expression directly, or it may
7525 -- cause insertion of actions that would escape the attempt to
7526 -- suppress the check code.
7528 -- Note that the Sloc for the if statement corresponds to the
7529 -- argument condition, not the pragma itself. The reason for this
7530 -- is that we may generate a warning if the condition is False at
7531 -- compile time, and we do not want to delete this warning when we
7532 -- delete the if statement.
7534 Expr := Get_Pragma_Arg (Arg2);
7536 if Expander_Active and then not Check_On then
7537 Eloc := Sloc (Expr);
7540 Make_If_Statement (Eloc,
7542 Make_And_Then (Eloc,
7543 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7544 Right_Opnd => Expr),
7545 Then_Statements => New_List (
7546 Make_Null_Statement (Eloc))));
7553 In_Assertion_Expr := In_Assertion_Expr + 1;
7554 Analyze_And_Resolve (Expr, Any_Boolean);
7555 In_Assertion_Expr := In_Assertion_Expr - 1;
7563 -- pragma Check_Name (check_IDENTIFIER);
7565 when Pragma_Check_Name =>
7566 Check_No_Identifiers;
7568 Check_Valid_Configuration_Pragma;
7569 Check_Arg_Count (1);
7570 Check_Arg_Is_Identifier (Arg1);
7573 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7576 for J in Check_Names.First .. Check_Names.Last loop
7577 if Check_Names.Table (J) = Nam then
7582 Check_Names.Append (Nam);
7589 -- pragma Check_Policy (
7590 -- [Name =>] IDENTIFIER,
7591 -- [Policy =>] POLICY_IDENTIFIER);
7593 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7595 -- Note: this is a configuration pragma, but it is allowed to appear
7598 when Pragma_Check_Policy =>
7600 Check_Arg_Count (2);
7601 Check_Optional_Identifier (Arg1, Name_Name);
7602 Check_Optional_Identifier (Arg2, Name_Policy);
7604 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7606 -- A Check_Policy pragma can appear either as a configuration
7607 -- pragma, or in a declarative part or a package spec (see RM
7608 -- 11.5(5) for rules for Suppress/Unsuppress which are also
7609 -- followed for Check_Policy).
7611 if not Is_Configuration_Pragma then
7612 Check_Is_In_Decl_Part_Or_Package_Spec;
7615 Set_Next_Pragma (N, Opt.Check_Policy_List);
7616 Opt.Check_Policy_List := N;
7618 ---------------------
7619 -- CIL_Constructor --
7620 ---------------------
7622 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7624 -- Processing for this pragma is shared with Java_Constructor
7630 -- pragma Comment (static_string_EXPRESSION)
7632 -- Processing for pragma Comment shares the circuitry for pragma
7633 -- Ident. The only differences are that Ident enforces a limit of 31
7634 -- characters on its argument, and also enforces limitations on
7635 -- placement for DEC compatibility. Pragma Comment shares neither of
7636 -- these restrictions.
7642 -- pragma Common_Object (
7643 -- [Internal =>] LOCAL_NAME
7644 -- [, [External =>] EXTERNAL_SYMBOL]
7645 -- [, [Size =>] EXTERNAL_SYMBOL]);
7647 -- Processing for this pragma is shared with Psect_Object
7649 ------------------------
7650 -- Compile_Time_Error --
7651 ------------------------
7653 -- pragma Compile_Time_Error
7654 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7656 when Pragma_Compile_Time_Error =>
7658 Process_Compile_Time_Warning_Or_Error;
7660 --------------------------
7661 -- Compile_Time_Warning --
7662 --------------------------
7664 -- pragma Compile_Time_Warning
7665 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7667 when Pragma_Compile_Time_Warning =>
7669 Process_Compile_Time_Warning_Or_Error;
7675 when Pragma_Compiler_Unit =>
7677 Check_Arg_Count (0);
7678 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7680 -----------------------------
7681 -- Complete_Representation --
7682 -----------------------------
7684 -- pragma Complete_Representation;
7686 when Pragma_Complete_Representation =>
7688 Check_Arg_Count (0);
7690 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7692 ("pragma & must appear within record representation clause");
7695 ----------------------------
7696 -- Complex_Representation --
7697 ----------------------------
7699 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7701 when Pragma_Complex_Representation => Complex_Representation : declare
7708 Check_Arg_Count (1);
7709 Check_Optional_Identifier (Arg1, Name_Entity);
7710 Check_Arg_Is_Local_Name (Arg1);
7711 E_Id := Get_Pragma_Arg (Arg1);
7713 if Etype (E_Id) = Any_Type then
7719 if not Is_Record_Type (E) then
7721 ("argument for pragma% must be record type", Arg1);
7724 Ent := First_Entity (E);
7727 or else No (Next_Entity (Ent))
7728 or else Present (Next_Entity (Next_Entity (Ent)))
7729 or else not Is_Floating_Point_Type (Etype (Ent))
7730 or else Etype (Ent) /= Etype (Next_Entity (Ent))
7733 ("record for pragma% must have two fields of the same "
7734 & "floating-point type", Arg1);
7737 Set_Has_Complex_Representation (Base_Type (E));
7739 -- We need to treat the type has having a non-standard
7740 -- representation, for back-end purposes, even though in
7741 -- general a complex will have the default representation
7742 -- of a record with two real components.
7744 Set_Has_Non_Standard_Rep (Base_Type (E));
7746 end Complex_Representation;
7748 -------------------------
7749 -- Component_Alignment --
7750 -------------------------
7752 -- pragma Component_Alignment (
7753 -- [Form =>] ALIGNMENT_CHOICE
7754 -- [, [Name =>] type_LOCAL_NAME]);
7756 -- ALIGNMENT_CHOICE ::=
7758 -- | Component_Size_4
7762 when Pragma_Component_Alignment => Component_AlignmentP : declare
7763 Args : Args_List (1 .. 2);
7764 Names : constant Name_List (1 .. 2) := (
7768 Form : Node_Id renames Args (1);
7769 Name : Node_Id renames Args (2);
7771 Atype : Component_Alignment_Kind;
7776 Gather_Associations (Names, Args);
7779 Error_Pragma ("missing Form argument for pragma%");
7782 Check_Arg_Is_Identifier (Form);
7784 -- Get proper alignment, note that Default = Component_Size on all
7785 -- machines we have so far, and we want to set this value rather
7786 -- than the default value to indicate that it has been explicitly
7787 -- set (and thus will not get overridden by the default component
7788 -- alignment for the current scope)
7790 if Chars (Form) = Name_Component_Size then
7791 Atype := Calign_Component_Size;
7793 elsif Chars (Form) = Name_Component_Size_4 then
7794 Atype := Calign_Component_Size_4;
7796 elsif Chars (Form) = Name_Default then
7797 Atype := Calign_Component_Size;
7799 elsif Chars (Form) = Name_Storage_Unit then
7800 Atype := Calign_Storage_Unit;
7804 ("invalid Form parameter for pragma%", Form);
7807 -- Case with no name, supplied, affects scope table entry
7811 (Scope_Stack.Last).Component_Alignment_Default := Atype;
7813 -- Case of name supplied
7816 Check_Arg_Is_Local_Name (Name);
7818 Typ := Entity (Name);
7821 or else Rep_Item_Too_Early (Typ, N)
7825 Typ := Underlying_Type (Typ);
7828 if not Is_Record_Type (Typ)
7829 and then not Is_Array_Type (Typ)
7832 ("Name parameter of pragma% must identify record or " &
7833 "array type", Name);
7836 -- An explicit Component_Alignment pragma overrides an
7837 -- implicit pragma Pack, but not an explicit one.
7839 if not Has_Pragma_Pack (Base_Type (Typ)) then
7840 Set_Is_Packed (Base_Type (Typ), False);
7841 Set_Component_Alignment (Base_Type (Typ), Atype);
7844 end Component_AlignmentP;
7850 -- pragma Contract_Case
7851 -- ([Name =>] Static_String_EXPRESSION
7852 -- ,[Mode =>] MODE_TYPE
7853 -- [, Requires => Boolean_EXPRESSION]
7854 -- [, Ensures => Boolean_EXPRESSION]);
7856 -- MODE_TYPE ::= Nominal | Robustness
7858 when Pragma_Contract_Case =>
7859 Check_Contract_Or_Test_Case;
7861 --------------------
7862 -- Contract_Cases --
7863 --------------------
7865 -- pragma Contract_Cases (CONTRACT_CASE_LIST);
7867 -- CONTRACT_CASE_LIST ::= CONTRACT_CASE {, CONTRACT_CASE}
7869 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
7871 -- CASE_GUARD ::= boolean_EXPRESSION | others
7873 -- CONSEQUENCE ::= boolean_EXPRESSION
7875 when Pragma_Contract_Cases => Contract_Cases : declare
7876 procedure Chain_Contract_Cases (Subp_Decl : Node_Id);
7877 -- Chain pragma Contract_Cases to the contract of a subprogram.
7878 -- Subp_Decl is the declaration of the subprogram.
7880 --------------------------
7881 -- Chain_Contract_Cases --
7882 --------------------------
7884 procedure Chain_Contract_Cases (Subp_Decl : Node_Id) is
7885 Subp : constant Entity_Id :=
7886 Defining_Unit_Name (Specification (Subp_Decl));
7890 Check_Duplicate_Pragma (Subp);
7891 CTC := Spec_CTC_List (Contract (Subp));
7892 while Present (CTC) loop
7893 if Chars (Pragma_Identifier (CTC)) = Pname then
7894 Error_Msg_Name_1 := Pname;
7895 Error_Msg_Sloc := Sloc (CTC);
7897 if From_Aspect_Specification (CTC) then
7899 ("aspect% for & previously given#", N, Subp);
7902 ("pragma% for & duplicates pragma#", N, Subp);
7908 CTC := Next_Pragma (CTC);
7911 -- Prepend pragma Contract_Cases to the contract
7913 Set_Next_Pragma (N, Spec_CTC_List (Contract (Subp)));
7914 Set_Spec_CTC_List (Contract (Subp), N);
7915 end Chain_Contract_Cases;
7919 Case_Guard : Node_Id;
7922 Others_Seen : Boolean := False;
7923 Contract_Case : Node_Id;
7924 Subp_Decl : Node_Id;
7926 -- Start of processing for Contract_Cases
7931 Check_Arg_Count (1);
7933 -- Completely ignore if disabled
7935 if Check_Disabled (Pname) then
7936 Rewrite (N, Make_Null_Statement (Loc));
7941 -- Check the placement of the pragma
7943 if not Is_List_Member (N) then
7947 -- Pragma Contract_Cases must be associated with a subprogram
7950 while Present (Prev (Decl)) loop
7951 Decl := Prev (Decl);
7953 if Nkind (Decl) in N_Generic_Declaration then
7956 Subp_Decl := Original_Node (Decl);
7959 -- Skip prior pragmas
7961 if Nkind (Subp_Decl) = N_Pragma then
7964 -- Skip internally generated code
7966 elsif not Comes_From_Source (Subp_Decl) then
7969 -- We have found the related subprogram
7971 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
7972 N_Subprogram_Declaration)
7981 -- All contract cases must appear as an aggregate
7983 if Nkind (Expression (Arg1)) /= N_Aggregate then
7984 Error_Pragma ("wrong syntax for pragma %");
7988 -- Verify the legality of individual contract cases
7991 First (Component_Associations (Expression (Arg1)));
7992 while Present (Contract_Case) loop
7993 if Nkind (Contract_Case) /= N_Component_Association then
7995 ("wrong syntax in contract case", Contract_Case);
7999 Case_Guard := First (Choices (Contract_Case));
8001 -- Each contract case must have exactly on case guard
8003 Extra := Next (Case_Guard);
8004 if Present (Extra) then
8006 ("contract case may have only one case guard", Extra);
8010 -- Check the placement of "others" (if available)
8012 if Nkind (Case_Guard) = N_Others_Choice then
8015 ("only one others choice allowed in pragma %",
8019 Others_Seen := True;
8022 elsif Others_Seen then
8024 ("others must be the last choice in pragma %", N);
8028 Next (Contract_Case);
8031 Chain_Contract_Cases (Subp_Decl);
8038 -- pragma Controlled (first_subtype_LOCAL_NAME);
8040 when Pragma_Controlled => Controlled : declare
8044 Check_No_Identifiers;
8045 Check_Arg_Count (1);
8046 Check_Arg_Is_Local_Name (Arg1);
8047 Arg := Get_Pragma_Arg (Arg1);
8049 if not Is_Entity_Name (Arg)
8050 or else not Is_Access_Type (Entity (Arg))
8052 Error_Pragma_Arg ("pragma% requires access type", Arg1);
8054 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
8062 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
8063 -- [Entity =>] LOCAL_NAME);
8065 when Pragma_Convention => Convention : declare
8068 pragma Warnings (Off, C);
8069 pragma Warnings (Off, E);
8071 Check_Arg_Order ((Name_Convention, Name_Entity));
8072 Check_Ada_83_Warning;
8073 Check_Arg_Count (2);
8074 Process_Convention (C, E);
8077 ---------------------------
8078 -- Convention_Identifier --
8079 ---------------------------
8081 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
8082 -- [Convention =>] convention_IDENTIFIER);
8084 when Pragma_Convention_Identifier => Convention_Identifier : declare
8090 Check_Arg_Order ((Name_Name, Name_Convention));
8091 Check_Arg_Count (2);
8092 Check_Optional_Identifier (Arg1, Name_Name);
8093 Check_Optional_Identifier (Arg2, Name_Convention);
8094 Check_Arg_Is_Identifier (Arg1);
8095 Check_Arg_Is_Identifier (Arg2);
8096 Idnam := Chars (Get_Pragma_Arg (Arg1));
8097 Cname := Chars (Get_Pragma_Arg (Arg2));
8099 if Is_Convention_Name (Cname) then
8100 Record_Convention_Identifier
8101 (Idnam, Get_Convention_Id (Cname));
8104 ("second arg for % pragma must be convention", Arg2);
8106 end Convention_Identifier;
8112 -- pragma CPP_Class ([Entity =>] local_NAME)
8114 when Pragma_CPP_Class => CPP_Class : declare
8118 if Warn_On_Obsolescent_Feature then
8119 -- Following message is obsolete ???
8121 ("'G'N'A'T pragma cpp'_class is now obsolete and has no " &
8122 "effect; replace it by pragma import?", N);
8125 Check_Arg_Count (1);
8129 Chars => Name_Import,
8130 Pragma_Argument_Associations =>
8132 Make_Pragma_Argument_Association (Loc,
8133 Expression => Make_Identifier (Loc, Name_CPP)),
8134 New_Copy (First (Pragma_Argument_Associations (N))))));
8138 ---------------------
8139 -- CPP_Constructor --
8140 ---------------------
8142 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
8143 -- [, [External_Name =>] static_string_EXPRESSION ]
8144 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8146 when Pragma_CPP_Constructor => CPP_Constructor : declare
8150 Tag_Typ : Entity_Id;
8154 Check_At_Least_N_Arguments (1);
8155 Check_At_Most_N_Arguments (3);
8156 Check_Optional_Identifier (Arg1, Name_Entity);
8157 Check_Arg_Is_Local_Name (Arg1);
8159 Id := Get_Pragma_Arg (Arg1);
8160 Find_Program_Unit_Name (Id);
8162 -- If we did not find the name, we are done
8164 if Etype (Id) = Any_Type then
8168 Def_Id := Entity (Id);
8170 -- Check if already defined as constructor
8172 if Is_Constructor (Def_Id) then
8174 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
8178 if Ekind (Def_Id) = E_Function
8179 and then (Is_CPP_Class (Etype (Def_Id))
8180 or else (Is_Class_Wide_Type (Etype (Def_Id))
8182 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
8184 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
8186 ("'C'P'P constructor must be defined in the scope of " &
8187 "its returned type", Arg1);
8190 if Arg_Count >= 2 then
8191 Set_Imported (Def_Id);
8192 Set_Is_Public (Def_Id);
8193 Process_Interface_Name (Def_Id, Arg2, Arg3);
8196 Set_Has_Completion (Def_Id);
8197 Set_Is_Constructor (Def_Id);
8198 Set_Convention (Def_Id, Convention_CPP);
8200 -- Imported C++ constructors are not dispatching primitives
8201 -- because in C++ they don't have a dispatch table slot.
8202 -- However, in Ada the constructor has the profile of a
8203 -- function that returns a tagged type and therefore it has
8204 -- been treated as a primitive operation during semantic
8205 -- analysis. We now remove it from the list of primitive
8206 -- operations of the type.
8208 if Is_Tagged_Type (Etype (Def_Id))
8209 and then not Is_Class_Wide_Type (Etype (Def_Id))
8210 and then Is_Dispatching_Operation (Def_Id)
8212 Tag_Typ := Etype (Def_Id);
8214 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
8215 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
8219 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
8220 Set_Is_Dispatching_Operation (Def_Id, False);
8223 -- For backward compatibility, if the constructor returns a
8224 -- class wide type, and we internally change the return type to
8225 -- the corresponding root type.
8227 if Is_Class_Wide_Type (Etype (Def_Id)) then
8228 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
8232 ("pragma% requires function returning a 'C'P'P_Class type",
8235 end CPP_Constructor;
8241 when Pragma_CPP_Virtual => CPP_Virtual : declare
8245 if Warn_On_Obsolescent_Feature then
8247 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
8256 when Pragma_CPP_Vtable => CPP_Vtable : declare
8260 if Warn_On_Obsolescent_Feature then
8262 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
8271 -- pragma CPU (EXPRESSION);
8273 when Pragma_CPU => CPU : declare
8274 P : constant Node_Id := Parent (N);
8280 Check_No_Identifiers;
8281 Check_Arg_Count (1);
8285 if Nkind (P) = N_Subprogram_Body then
8286 Check_In_Main_Program;
8288 Arg := Get_Pragma_Arg (Arg1);
8289 Analyze_And_Resolve (Arg, Any_Integer);
8291 Ent := Defining_Unit_Name (Specification (P));
8293 if Nkind (Ent) = N_Defining_Program_Unit_Name then
8294 Ent := Defining_Identifier (Ent);
8299 if not Is_Static_Expression (Arg) then
8300 Flag_Non_Static_Expr
8301 ("main subprogram affinity is not static!", Arg);
8304 -- If constraint error, then we already signalled an error
8306 elsif Raises_Constraint_Error (Arg) then
8309 -- Otherwise check in range
8313 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
8314 -- This is the entity System.Multiprocessors.CPU_Range;
8316 Val : constant Uint := Expr_Value (Arg);
8319 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
8321 Val > Expr_Value (Type_High_Bound (CPU_Id))
8324 ("main subprogram CPU is out of range", Arg1);
8330 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8334 elsif Nkind (P) = N_Task_Definition then
8335 Arg := Get_Pragma_Arg (Arg1);
8336 Ent := Defining_Identifier (Parent (P));
8338 -- The expression must be analyzed in the special manner
8339 -- described in "Handling of Default and Per-Object
8340 -- Expressions" in sem.ads.
8342 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
8344 -- Anything else is incorrect
8350 -- Check duplicate pragma before we chain the pragma in the Rep
8351 -- Item chain of Ent.
8353 Check_Duplicate_Pragma (Ent);
8354 Record_Rep_Item (Ent, N);
8361 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
8363 when Pragma_Debug => Debug : declare
8370 -- Skip analysis if disabled
8372 if Debug_Pragmas_Disabled then
8373 Rewrite (N, Make_Null_Statement (Loc));
8380 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
8383 if Debug_Pragmas_Enabled then
8384 Set_SCO_Pragma_Enabled (Loc);
8387 if Arg_Count = 2 then
8390 Left_Opnd => Relocate_Node (Cond),
8391 Right_Opnd => Get_Pragma_Arg (Arg1));
8392 Call := Get_Pragma_Arg (Arg2);
8394 Call := Get_Pragma_Arg (Arg1);
8398 N_Indexed_Component,
8402 N_Selected_Component)
8404 -- If this pragma Debug comes from source, its argument was
8405 -- parsed as a name form (which is syntactically identical).
8406 -- In a generic context a parameterless call will be left as
8407 -- an expanded name (if global) or selected_component if local.
8408 -- Change it to a procedure call statement now.
8410 Change_Name_To_Procedure_Call_Statement (Call);
8412 elsif Nkind (Call) = N_Procedure_Call_Statement then
8414 -- Already in the form of a procedure call statement: nothing
8415 -- to do (could happen in case of an internally generated
8421 -- All other cases: diagnose error
8424 ("argument of pragma ""Debug"" is not procedure call",
8429 -- Rewrite into a conditional with an appropriate condition. We
8430 -- wrap the procedure call in a block so that overhead from e.g.
8431 -- use of the secondary stack does not generate execution overhead
8432 -- for suppressed conditions.
8434 -- Normally the analysis that follows will freeze the subprogram
8435 -- being called. However, if the call is to a null procedure,
8436 -- we want to freeze it before creating the block, because the
8437 -- analysis that follows may be done with expansion disabled, in
8438 -- which case the body will not be generated, leading to spurious
8441 if Nkind (Call) = N_Procedure_Call_Statement
8442 and then Is_Entity_Name (Name (Call))
8444 Analyze (Name (Call));
8445 Freeze_Before (N, Entity (Name (Call)));
8448 Rewrite (N, Make_Implicit_If_Statement (N,
8450 Then_Statements => New_List (
8451 Make_Block_Statement (Loc,
8452 Handled_Statement_Sequence =>
8453 Make_Handled_Sequence_Of_Statements (Loc,
8454 Statements => New_List (Relocate_Node (Call)))))));
8462 -- pragma Debug_Policy (Check | Ignore)
8464 when Pragma_Debug_Policy =>
8466 Check_Arg_Count (1);
8467 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
8468 Debug_Pragmas_Enabled :=
8469 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
8470 Debug_Pragmas_Disabled :=
8471 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
8473 ---------------------
8474 -- Detect_Blocking --
8475 ---------------------
8477 -- pragma Detect_Blocking;
8479 when Pragma_Detect_Blocking =>
8481 Check_Arg_Count (0);
8482 Check_Valid_Configuration_Pragma;
8483 Detect_Blocking := True;
8485 --------------------------
8486 -- Default_Storage_Pool --
8487 --------------------------
8489 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
8491 when Pragma_Default_Storage_Pool =>
8493 Check_Arg_Count (1);
8495 -- Default_Storage_Pool can appear as a configuration pragma, or
8496 -- in a declarative part or a package spec.
8498 if not Is_Configuration_Pragma then
8499 Check_Is_In_Decl_Part_Or_Package_Spec;
8502 -- Case of Default_Storage_Pool (null);
8504 if Nkind (Expression (Arg1)) = N_Null then
8505 Analyze (Expression (Arg1));
8507 -- This is an odd case, this is not really an expression, so
8508 -- we don't have a type for it. So just set the type to Empty.
8510 Set_Etype (Expression (Arg1), Empty);
8512 -- Case of Default_Storage_Pool (storage_pool_NAME);
8515 -- If it's a configuration pragma, then the only allowed
8516 -- argument is "null".
8518 if Is_Configuration_Pragma then
8519 Error_Pragma_Arg ("NULL expected", Arg1);
8522 -- The expected type for a non-"null" argument is
8523 -- Root_Storage_Pool'Class.
8526 (Get_Pragma_Arg (Arg1),
8527 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8530 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
8531 -- for an access type will use this information to set the
8532 -- appropriate attributes of the access type.
8534 Default_Pool := Expression (Arg1);
8536 ------------------------------------
8537 -- Disable_Atomic_Synchronization --
8538 ------------------------------------
8540 -- pragma Disable_Atomic_Synchronization [(Entity)];
8542 when Pragma_Disable_Atomic_Synchronization =>
8543 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8549 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
8551 when Pragma_Discard_Names => Discard_Names : declare
8556 Check_Ada_83_Warning;
8558 -- Deal with configuration pragma case
8560 if Arg_Count = 0 and then Is_Configuration_Pragma then
8561 Global_Discard_Names := True;
8564 -- Otherwise, check correct appropriate context
8567 Check_Is_In_Decl_Part_Or_Package_Spec;
8569 if Arg_Count = 0 then
8571 -- If there is no parameter, then from now on this pragma
8572 -- applies to any enumeration, exception or tagged type
8573 -- defined in the current declarative part, and recursively
8574 -- to any nested scope.
8576 Set_Discard_Names (Current_Scope);
8580 Check_Arg_Count (1);
8581 Check_Optional_Identifier (Arg1, Name_On);
8582 Check_Arg_Is_Local_Name (Arg1);
8584 E_Id := Get_Pragma_Arg (Arg1);
8586 if Etype (E_Id) = Any_Type then
8592 if (Is_First_Subtype (E)
8594 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8595 or else Ekind (E) = E_Exception
8597 Set_Discard_Names (E);
8598 Record_Rep_Item (E, N);
8602 ("inappropriate entity for pragma%", Arg1);
8609 ------------------------
8610 -- Dispatching_Domain --
8611 ------------------------
8613 -- pragma Dispatching_Domain (EXPRESSION);
8615 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8616 P : constant Node_Id := Parent (N);
8622 Check_No_Identifiers;
8623 Check_Arg_Count (1);
8625 -- This pragma is born obsolete, but not the aspect
8627 if not From_Aspect_Specification (N) then
8629 (No_Obsolescent_Features, Pragma_Identifier (N));
8632 if Nkind (P) = N_Task_Definition then
8633 Arg := Get_Pragma_Arg (Arg1);
8634 Ent := Defining_Identifier (Parent (P));
8636 -- The expression must be analyzed in the special manner
8637 -- described in "Handling of Default and Per-Object
8638 -- Expressions" in sem.ads.
8640 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8642 -- Check duplicate pragma before we chain the pragma in the Rep
8643 -- Item chain of Ent.
8645 Check_Duplicate_Pragma (Ent);
8646 Record_Rep_Item (Ent, N);
8648 -- Anything else is incorrect
8653 end Dispatching_Domain;
8659 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8661 when Pragma_Elaborate => Elaborate : declare
8666 -- Pragma must be in context items list of a compilation unit
8668 if not Is_In_Context_Clause then
8672 -- Must be at least one argument
8674 if Arg_Count = 0 then
8675 Error_Pragma ("pragma% requires at least one argument");
8678 -- In Ada 83 mode, there can be no items following it in the
8679 -- context list except other pragmas and implicit with clauses
8680 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8681 -- placement rule does not apply.
8683 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8685 while Present (Citem) loop
8686 if Nkind (Citem) = N_Pragma
8687 or else (Nkind (Citem) = N_With_Clause
8688 and then Implicit_With (Citem))
8693 ("(Ada 83) pragma% must be at end of context clause");
8700 -- Finally, the arguments must all be units mentioned in a with
8701 -- clause in the same context clause. Note we already checked (in
8702 -- Par.Prag) that the arguments are all identifiers or selected
8706 Outer : while Present (Arg) loop
8707 Citem := First (List_Containing (N));
8708 Inner : while Citem /= N loop
8709 if Nkind (Citem) = N_With_Clause
8710 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8712 Set_Elaborate_Present (Citem, True);
8713 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8714 Generate_Reference (Entity (Name (Citem)), Citem);
8716 -- With the pragma present, elaboration calls on
8717 -- subprograms from the named unit need no further
8718 -- checks, as long as the pragma appears in the current
8719 -- compilation unit. If the pragma appears in some unit
8720 -- in the context, there might still be a need for an
8721 -- Elaborate_All_Desirable from the current compilation
8722 -- to the named unit, so we keep the check enabled.
8724 if In_Extended_Main_Source_Unit (N) then
8725 Set_Suppress_Elaboration_Warnings
8726 (Entity (Name (Citem)));
8737 ("argument of pragma% is not withed unit", Arg);
8743 -- Give a warning if operating in static mode with -gnatwl
8744 -- (elaboration warnings enabled) switch set.
8746 if Elab_Warnings and not Dynamic_Elaboration_Checks then
8748 ("?use of pragma Elaborate may not be safe", N);
8750 ("?use pragma Elaborate_All instead if possible", N);
8758 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8760 when Pragma_Elaborate_All => Elaborate_All : declare
8765 Check_Ada_83_Warning;
8767 -- Pragma must be in context items list of a compilation unit
8769 if not Is_In_Context_Clause then
8773 -- Must be at least one argument
8775 if Arg_Count = 0 then
8776 Error_Pragma ("pragma% requires at least one argument");
8779 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
8780 -- have to appear at the end of the context clause, but may
8781 -- appear mixed in with other items, even in Ada 83 mode.
8783 -- Final check: the arguments must all be units mentioned in
8784 -- a with clause in the same context clause. Note that we
8785 -- already checked (in Par.Prag) that all the arguments are
8786 -- either identifiers or selected components.
8789 Outr : while Present (Arg) loop
8790 Citem := First (List_Containing (N));
8791 Innr : while Citem /= N loop
8792 if Nkind (Citem) = N_With_Clause
8793 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8795 Set_Elaborate_All_Present (Citem, True);
8796 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8798 -- Suppress warnings and elaboration checks on the named
8799 -- unit if the pragma is in the current compilation, as
8800 -- for pragma Elaborate.
8802 if In_Extended_Main_Source_Unit (N) then
8803 Set_Suppress_Elaboration_Warnings
8804 (Entity (Name (Citem)));
8813 Set_Error_Posted (N);
8815 ("argument of pragma% is not withed unit", Arg);
8822 --------------------
8823 -- Elaborate_Body --
8824 --------------------
8826 -- pragma Elaborate_Body [( library_unit_NAME )];
8828 when Pragma_Elaborate_Body => Elaborate_Body : declare
8829 Cunit_Node : Node_Id;
8830 Cunit_Ent : Entity_Id;
8833 Check_Ada_83_Warning;
8834 Check_Valid_Library_Unit_Pragma;
8836 if Nkind (N) = N_Null_Statement then
8840 Cunit_Node := Cunit (Current_Sem_Unit);
8841 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8843 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8846 Error_Pragma ("pragma% must refer to a spec, not a body");
8848 Set_Body_Required (Cunit_Node, True);
8849 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8851 -- If we are in dynamic elaboration mode, then we suppress
8852 -- elaboration warnings for the unit, since it is definitely
8853 -- fine NOT to do dynamic checks at the first level (and such
8854 -- checks will be suppressed because no elaboration boolean
8855 -- is created for Elaborate_Body packages).
8857 -- But in the static model of elaboration, Elaborate_Body is
8858 -- definitely NOT good enough to ensure elaboration safety on
8859 -- its own, since the body may WITH other units that are not
8860 -- safe from an elaboration point of view, so a client must
8861 -- still do an Elaborate_All on such units.
8863 -- Debug flag -gnatdD restores the old behavior of 3.13, where
8864 -- Elaborate_Body always suppressed elab warnings.
8866 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8867 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8872 ------------------------
8873 -- Elaboration_Checks --
8874 ------------------------
8876 -- pragma Elaboration_Checks (Static | Dynamic);
8878 when Pragma_Elaboration_Checks =>
8880 Check_Arg_Count (1);
8881 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8882 Dynamic_Elaboration_Checks :=
8883 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8889 -- pragma Eliminate (
8890 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
8891 -- [,[Entity =>] IDENTIFIER |
8892 -- SELECTED_COMPONENT |
8894 -- [, OVERLOADING_RESOLUTION]);
8896 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8899 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8902 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8904 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8905 -- Result_Type => result_SUBTYPE_NAME]
8907 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8908 -- SUBTYPE_NAME ::= STRING_LITERAL
8910 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8911 -- SOURCE_TRACE ::= STRING_LITERAL
8913 when Pragma_Eliminate => Eliminate : declare
8914 Args : Args_List (1 .. 5);
8915 Names : constant Name_List (1 .. 5) := (
8918 Name_Parameter_Types,
8920 Name_Source_Location);
8922 Unit_Name : Node_Id renames Args (1);
8923 Entity : Node_Id renames Args (2);
8924 Parameter_Types : Node_Id renames Args (3);
8925 Result_Type : Node_Id renames Args (4);
8926 Source_Location : Node_Id renames Args (5);
8930 Check_Valid_Configuration_Pragma;
8931 Gather_Associations (Names, Args);
8933 if No (Unit_Name) then
8934 Error_Pragma ("missing Unit_Name argument for pragma%");
8938 and then (Present (Parameter_Types)
8940 Present (Result_Type)
8942 Present (Source_Location))
8944 Error_Pragma ("missing Entity argument for pragma%");
8947 if (Present (Parameter_Types)
8949 Present (Result_Type))
8951 Present (Source_Location)
8954 ("parameter profile and source location cannot " &
8955 "be used together in pragma%");
8958 Process_Eliminate_Pragma
8967 -----------------------------------
8968 -- Enable_Atomic_Synchronization --
8969 -----------------------------------
8971 -- pragma Enable_Atomic_Synchronization [(Entity)];
8973 when Pragma_Enable_Atomic_Synchronization =>
8974 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
8981 -- [ Convention =>] convention_IDENTIFIER,
8982 -- [ Entity =>] local_NAME
8983 -- [, [External_Name =>] static_string_EXPRESSION ]
8984 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8986 when Pragma_Export => Export : declare
8990 pragma Warnings (Off, C);
8993 Check_Ada_83_Warning;
9000 Check_At_Least_N_Arguments (2);
9002 Check_At_Most_N_Arguments (4);
9003 Process_Convention (C, Def_Id);
9005 if Ekind (Def_Id) /= E_Constant then
9006 Note_Possible_Modification
9007 (Get_Pragma_Arg (Arg2), Sure => False);
9010 Process_Interface_Name (Def_Id, Arg3, Arg4);
9011 Set_Exported (Def_Id, Arg2);
9013 -- If the entity is a deferred constant, propagate the information
9014 -- to the full view, because gigi elaborates the full view only.
9016 if Ekind (Def_Id) = E_Constant
9017 and then Present (Full_View (Def_Id))
9020 Id2 : constant Entity_Id := Full_View (Def_Id);
9022 Set_Is_Exported (Id2, Is_Exported (Def_Id));
9023 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
9024 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
9029 ----------------------
9030 -- Export_Exception --
9031 ----------------------
9033 -- pragma Export_Exception (
9034 -- [Internal =>] LOCAL_NAME
9035 -- [, [External =>] EXTERNAL_SYMBOL]
9036 -- [, [Form =>] Ada | VMS]
9037 -- [, [Code =>] static_integer_EXPRESSION]);
9039 when Pragma_Export_Exception => Export_Exception : declare
9040 Args : Args_List (1 .. 4);
9041 Names : constant Name_List (1 .. 4) := (
9047 Internal : Node_Id renames Args (1);
9048 External : Node_Id renames Args (2);
9049 Form : Node_Id renames Args (3);
9050 Code : Node_Id renames Args (4);
9055 if Inside_A_Generic then
9056 Error_Pragma ("pragma% cannot be used for generic entities");
9059 Gather_Associations (Names, Args);
9060 Process_Extended_Import_Export_Exception_Pragma (
9061 Arg_Internal => Internal,
9062 Arg_External => External,
9066 if not Is_VMS_Exception (Entity (Internal)) then
9067 Set_Exported (Entity (Internal), Internal);
9069 end Export_Exception;
9071 ---------------------
9072 -- Export_Function --
9073 ---------------------
9075 -- pragma Export_Function (
9076 -- [Internal =>] LOCAL_NAME
9077 -- [, [External =>] EXTERNAL_SYMBOL]
9078 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9079 -- [, [Result_Type =>] TYPE_DESIGNATOR]
9080 -- [, [Mechanism =>] MECHANISM]
9081 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
9083 -- EXTERNAL_SYMBOL ::=
9085 -- | static_string_EXPRESSION
9087 -- PARAMETER_TYPES ::=
9089 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9091 -- TYPE_DESIGNATOR ::=
9093 -- | subtype_Name ' Access
9097 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9099 -- MECHANISM_ASSOCIATION ::=
9100 -- [formal_parameter_NAME =>] MECHANISM_NAME
9102 -- MECHANISM_NAME ::=
9105 -- | Descriptor [([Class =>] CLASS_NAME)]
9107 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9109 when Pragma_Export_Function => Export_Function : declare
9110 Args : Args_List (1 .. 6);
9111 Names : constant Name_List (1 .. 6) := (
9114 Name_Parameter_Types,
9117 Name_Result_Mechanism);
9119 Internal : Node_Id renames Args (1);
9120 External : Node_Id renames Args (2);
9121 Parameter_Types : Node_Id renames Args (3);
9122 Result_Type : Node_Id renames Args (4);
9123 Mechanism : Node_Id renames Args (5);
9124 Result_Mechanism : Node_Id renames Args (6);
9128 Gather_Associations (Names, Args);
9129 Process_Extended_Import_Export_Subprogram_Pragma (
9130 Arg_Internal => Internal,
9131 Arg_External => External,
9132 Arg_Parameter_Types => Parameter_Types,
9133 Arg_Result_Type => Result_Type,
9134 Arg_Mechanism => Mechanism,
9135 Arg_Result_Mechanism => Result_Mechanism);
9136 end Export_Function;
9142 -- pragma Export_Object (
9143 -- [Internal =>] LOCAL_NAME
9144 -- [, [External =>] EXTERNAL_SYMBOL]
9145 -- [, [Size =>] EXTERNAL_SYMBOL]);
9147 -- EXTERNAL_SYMBOL ::=
9149 -- | static_string_EXPRESSION
9151 -- PARAMETER_TYPES ::=
9153 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9155 -- TYPE_DESIGNATOR ::=
9157 -- | subtype_Name ' Access
9161 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9163 -- MECHANISM_ASSOCIATION ::=
9164 -- [formal_parameter_NAME =>] MECHANISM_NAME
9166 -- MECHANISM_NAME ::=
9169 -- | Descriptor [([Class =>] CLASS_NAME)]
9171 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9173 when Pragma_Export_Object => Export_Object : declare
9174 Args : Args_List (1 .. 3);
9175 Names : constant Name_List (1 .. 3) := (
9180 Internal : Node_Id renames Args (1);
9181 External : Node_Id renames Args (2);
9182 Size : Node_Id renames Args (3);
9186 Gather_Associations (Names, Args);
9187 Process_Extended_Import_Export_Object_Pragma (
9188 Arg_Internal => Internal,
9189 Arg_External => External,
9193 ----------------------
9194 -- Export_Procedure --
9195 ----------------------
9197 -- pragma Export_Procedure (
9198 -- [Internal =>] LOCAL_NAME
9199 -- [, [External =>] EXTERNAL_SYMBOL]
9200 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9201 -- [, [Mechanism =>] MECHANISM]);
9203 -- EXTERNAL_SYMBOL ::=
9205 -- | static_string_EXPRESSION
9207 -- PARAMETER_TYPES ::=
9209 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9211 -- TYPE_DESIGNATOR ::=
9213 -- | subtype_Name ' Access
9217 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9219 -- MECHANISM_ASSOCIATION ::=
9220 -- [formal_parameter_NAME =>] MECHANISM_NAME
9222 -- MECHANISM_NAME ::=
9225 -- | Descriptor [([Class =>] CLASS_NAME)]
9227 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9229 when Pragma_Export_Procedure => Export_Procedure : declare
9230 Args : Args_List (1 .. 4);
9231 Names : constant Name_List (1 .. 4) := (
9234 Name_Parameter_Types,
9237 Internal : Node_Id renames Args (1);
9238 External : Node_Id renames Args (2);
9239 Parameter_Types : Node_Id renames Args (3);
9240 Mechanism : Node_Id renames Args (4);
9244 Gather_Associations (Names, Args);
9245 Process_Extended_Import_Export_Subprogram_Pragma (
9246 Arg_Internal => Internal,
9247 Arg_External => External,
9248 Arg_Parameter_Types => Parameter_Types,
9249 Arg_Mechanism => Mechanism);
9250 end Export_Procedure;
9256 -- pragma Export_Value (
9257 -- [Value =>] static_integer_EXPRESSION,
9258 -- [Link_Name =>] static_string_EXPRESSION);
9260 when Pragma_Export_Value =>
9262 Check_Arg_Order ((Name_Value, Name_Link_Name));
9263 Check_Arg_Count (2);
9265 Check_Optional_Identifier (Arg1, Name_Value);
9266 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9268 Check_Optional_Identifier (Arg2, Name_Link_Name);
9269 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9271 -----------------------------
9272 -- Export_Valued_Procedure --
9273 -----------------------------
9275 -- pragma Export_Valued_Procedure (
9276 -- [Internal =>] LOCAL_NAME
9277 -- [, [External =>] EXTERNAL_SYMBOL,]
9278 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9279 -- [, [Mechanism =>] MECHANISM]);
9281 -- EXTERNAL_SYMBOL ::=
9283 -- | static_string_EXPRESSION
9285 -- PARAMETER_TYPES ::=
9287 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9289 -- TYPE_DESIGNATOR ::=
9291 -- | subtype_Name ' Access
9295 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9297 -- MECHANISM_ASSOCIATION ::=
9298 -- [formal_parameter_NAME =>] MECHANISM_NAME
9300 -- MECHANISM_NAME ::=
9303 -- | Descriptor [([Class =>] CLASS_NAME)]
9305 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9307 when Pragma_Export_Valued_Procedure =>
9308 Export_Valued_Procedure : declare
9309 Args : Args_List (1 .. 4);
9310 Names : constant Name_List (1 .. 4) := (
9313 Name_Parameter_Types,
9316 Internal : Node_Id renames Args (1);
9317 External : Node_Id renames Args (2);
9318 Parameter_Types : Node_Id renames Args (3);
9319 Mechanism : Node_Id renames Args (4);
9323 Gather_Associations (Names, Args);
9324 Process_Extended_Import_Export_Subprogram_Pragma (
9325 Arg_Internal => Internal,
9326 Arg_External => External,
9327 Arg_Parameter_Types => Parameter_Types,
9328 Arg_Mechanism => Mechanism);
9329 end Export_Valued_Procedure;
9335 -- pragma Extend_System ([Name =>] Identifier);
9337 when Pragma_Extend_System => Extend_System : declare
9340 Check_Valid_Configuration_Pragma;
9341 Check_Arg_Count (1);
9342 Check_Optional_Identifier (Arg1, Name_Name);
9343 Check_Arg_Is_Identifier (Arg1);
9345 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
9348 and then Name_Buffer (1 .. 4) = "aux_"
9350 if Present (System_Extend_Pragma_Arg) then
9351 if Chars (Get_Pragma_Arg (Arg1)) =
9352 Chars (Expression (System_Extend_Pragma_Arg))
9356 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
9357 Error_Pragma ("pragma% conflicts with that #");
9361 System_Extend_Pragma_Arg := Arg1;
9363 if not GNAT_Mode then
9364 System_Extend_Unit := Arg1;
9368 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
9372 ------------------------
9373 -- Extensions_Allowed --
9374 ------------------------
9376 -- pragma Extensions_Allowed (ON | OFF);
9378 when Pragma_Extensions_Allowed =>
9380 Check_Arg_Count (1);
9381 Check_No_Identifiers;
9382 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9384 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
9385 Extensions_Allowed := True;
9386 Ada_Version := Ada_Version_Type'Last;
9389 Extensions_Allowed := False;
9390 Ada_Version := Ada_Version_Explicit;
9397 -- pragma External (
9398 -- [ Convention =>] convention_IDENTIFIER,
9399 -- [ Entity =>] local_NAME
9400 -- [, [External_Name =>] static_string_EXPRESSION ]
9401 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9403 when Pragma_External => External : declare
9407 pragma Warnings (Off, C);
9416 Check_At_Least_N_Arguments (2);
9417 Check_At_Most_N_Arguments (4);
9418 Process_Convention (C, Def_Id);
9419 Note_Possible_Modification
9420 (Get_Pragma_Arg (Arg2), Sure => False);
9421 Process_Interface_Name (Def_Id, Arg3, Arg4);
9422 Set_Exported (Def_Id, Arg2);
9425 --------------------------
9426 -- External_Name_Casing --
9427 --------------------------
9429 -- pragma External_Name_Casing (
9430 -- UPPERCASE | LOWERCASE
9431 -- [, AS_IS | UPPERCASE | LOWERCASE]);
9433 when Pragma_External_Name_Casing => External_Name_Casing : declare
9436 Check_No_Identifiers;
9438 if Arg_Count = 2 then
9440 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
9442 case Chars (Get_Pragma_Arg (Arg2)) is
9444 Opt.External_Name_Exp_Casing := As_Is;
9446 when Name_Uppercase =>
9447 Opt.External_Name_Exp_Casing := Uppercase;
9449 when Name_Lowercase =>
9450 Opt.External_Name_Exp_Casing := Lowercase;
9457 Check_Arg_Count (1);
9460 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
9462 case Chars (Get_Pragma_Arg (Arg1)) is
9463 when Name_Uppercase =>
9464 Opt.External_Name_Imp_Casing := Uppercase;
9466 when Name_Lowercase =>
9467 Opt.External_Name_Imp_Casing := Lowercase;
9472 end External_Name_Casing;
9474 --------------------------
9475 -- Favor_Top_Level --
9476 --------------------------
9478 -- pragma Favor_Top_Level (type_NAME);
9480 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
9481 Named_Entity : Entity_Id;
9485 Check_No_Identifiers;
9486 Check_Arg_Count (1);
9487 Check_Arg_Is_Local_Name (Arg1);
9488 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
9490 -- If it's an access-to-subprogram type (in particular, not a
9491 -- subtype), set the flag on that type.
9493 if Is_Access_Subprogram_Type (Named_Entity) then
9494 Set_Can_Use_Internal_Rep (Named_Entity, False);
9496 -- Otherwise it's an error (name denotes the wrong sort of entity)
9500 ("access-to-subprogram type expected",
9501 Get_Pragma_Arg (Arg1));
9503 end Favor_Top_Level;
9509 -- pragma Fast_Math;
9511 when Pragma_Fast_Math =>
9513 Check_No_Identifiers;
9514 Check_Valid_Configuration_Pragma;
9517 ---------------------------
9518 -- Finalize_Storage_Only --
9519 ---------------------------
9521 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9523 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9524 Assoc : constant Node_Id := Arg1;
9525 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9530 Check_No_Identifiers;
9531 Check_Arg_Count (1);
9532 Check_Arg_Is_Local_Name (Arg1);
9534 Find_Type (Type_Id);
9535 Typ := Entity (Type_Id);
9538 or else Rep_Item_Too_Early (Typ, N)
9542 Typ := Underlying_Type (Typ);
9545 if not Is_Controlled (Typ) then
9546 Error_Pragma ("pragma% must specify controlled type");
9549 Check_First_Subtype (Arg1);
9551 if Finalize_Storage_Only (Typ) then
9552 Error_Pragma ("duplicate pragma%, only one allowed");
9554 elsif not Rep_Item_Too_Late (Typ, N) then
9555 Set_Finalize_Storage_Only (Base_Type (Typ), True);
9557 end Finalize_Storage;
9559 --------------------------
9560 -- Float_Representation --
9561 --------------------------
9563 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9565 -- FLOAT_REP ::= VAX_Float | IEEE_Float
9567 when Pragma_Float_Representation => Float_Representation : declare
9575 if Arg_Count = 1 then
9576 Check_Valid_Configuration_Pragma;
9578 Check_Arg_Count (2);
9579 Check_Optional_Identifier (Arg2, Name_Entity);
9580 Check_Arg_Is_Local_Name (Arg2);
9583 Check_No_Identifier (Arg1);
9584 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9586 if not OpenVMS_On_Target then
9587 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9589 ("?pragma% ignored (applies only to Open'V'M'S)");
9595 -- One argument case
9597 if Arg_Count = 1 then
9598 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9599 if Opt.Float_Format = 'I' then
9600 Error_Pragma ("'I'E'E'E format previously specified");
9603 Opt.Float_Format := 'V';
9606 if Opt.Float_Format = 'V' then
9607 Error_Pragma ("'V'A'X format previously specified");
9610 Opt.Float_Format := 'I';
9613 Set_Standard_Fpt_Formats;
9615 -- Two argument case
9618 Argx := Get_Pragma_Arg (Arg2);
9620 if not Is_Entity_Name (Argx)
9621 or else not Is_Floating_Point_Type (Entity (Argx))
9624 ("second argument of% pragma must be floating-point type",
9628 Ent := Entity (Argx);
9629 Digs := UI_To_Int (Digits_Value (Ent));
9631 -- Two arguments, VAX_Float case
9633 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9635 when 6 => Set_F_Float (Ent);
9636 when 9 => Set_D_Float (Ent);
9637 when 15 => Set_G_Float (Ent);
9641 ("wrong digits value, must be 6,9 or 15", Arg2);
9644 -- Two arguments, IEEE_Float case
9648 when 6 => Set_IEEE_Short (Ent);
9649 when 15 => Set_IEEE_Long (Ent);
9653 ("wrong digits value, must be 6 or 15", Arg2);
9657 end Float_Representation;
9663 -- pragma Ident (static_string_EXPRESSION)
9665 -- Note: pragma Comment shares this processing. Pragma Comment is
9666 -- identical to Ident, except that the restriction of the argument to
9667 -- 31 characters and the placement restrictions are not enforced for
9670 when Pragma_Ident | Pragma_Comment => Ident : declare
9675 Check_Arg_Count (1);
9676 Check_No_Identifiers;
9677 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9680 -- For pragma Ident, preserve DEC compatibility by requiring the
9681 -- pragma to appear in a declarative part or package spec.
9683 if Prag_Id = Pragma_Ident then
9684 Check_Is_In_Decl_Part_Or_Package_Spec;
9687 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9694 GP := Parent (Parent (N));
9696 if Nkind_In (GP, N_Package_Declaration,
9697 N_Generic_Package_Declaration)
9702 -- If we have a compilation unit, then record the ident value,
9703 -- checking for improper duplication.
9705 if Nkind (GP) = N_Compilation_Unit then
9706 CS := Ident_String (Current_Sem_Unit);
9708 if Present (CS) then
9710 -- For Ident, we do not permit multiple instances
9712 if Prag_Id = Pragma_Ident then
9713 Error_Pragma ("duplicate% pragma not permitted");
9715 -- For Comment, we concatenate the string, unless we want
9716 -- to preserve the tree structure for ASIS.
9718 elsif not ASIS_Mode then
9719 Start_String (Strval (CS));
9720 Store_String_Char (' ');
9721 Store_String_Chars (Strval (Str));
9722 Set_Strval (CS, End_String);
9726 -- In VMS, the effect of IDENT is achieved by passing
9727 -- --identification=name as a --for-linker switch.
9729 if OpenVMS_On_Target then
9732 ("--for-linker=--identification=");
9733 String_To_Name_Buffer (Strval (Str));
9734 Store_String_Chars (Name_Buffer (1 .. Name_Len));
9736 -- Only the last processed IDENT is saved. The main
9737 -- purpose is so an IDENT associated with a main
9738 -- procedure will be used in preference to an IDENT
9739 -- associated with a with'd package.
9741 Replace_Linker_Option_String
9742 (End_String, "--for-linker=--identification=");
9745 Set_Ident_String (Current_Sem_Unit, Str);
9748 -- For subunits, we just ignore the Ident, since in GNAT these
9749 -- are not separate object files, and hence not separate units
9750 -- in the unit table.
9752 elsif Nkind (GP) = N_Subunit then
9755 -- Otherwise we have a misplaced pragma Ident, but we ignore
9756 -- this if we are in an instantiation, since it comes from
9757 -- a generic, and has no relevance to the instantiation.
9759 elsif Prag_Id = Pragma_Ident then
9760 if Instantiation_Location (Loc) = No_Location then
9761 Error_Pragma ("pragma% only allowed at outer level");
9767 ----------------------------
9768 -- Implementation_Defined --
9769 ----------------------------
9771 -- pragma Implementation_Defined (local_NAME);
9773 -- Marks previously declared entity as implementation defined. For
9774 -- an overloaded entity, applies to the most recent homonym.
9776 -- pragma Implementation_Defined;
9778 -- The form with no arguments appears anywhere within a scope, most
9779 -- typically a package spec, and indicates that all entities that are
9780 -- defined within the package spec are Implementation_Defined.
9782 when Pragma_Implementation_Defined => Implementation_Defined : declare
9786 Check_No_Identifiers;
9788 -- Form with no arguments
9790 if Arg_Count = 0 then
9791 Set_Is_Implementation_Defined (Current_Scope);
9793 -- Form with one argument
9796 Check_Arg_Count (1);
9797 Check_Arg_Is_Local_Name (Arg1);
9798 Ent := Entity (Get_Pragma_Arg (Arg1));
9799 Set_Is_Implementation_Defined (Ent);
9801 end Implementation_Defined;
9807 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9808 -- implementation_kind ::=
9809 -- By_Entry | By_Protected_Procedure | By_Any | Optional
9811 -- "By_Any" and "Optional" are treated as synonyms in order to
9812 -- support Ada 2012 aspect Synchronization.
9814 when Pragma_Implemented => Implemented : declare
9815 Proc_Id : Entity_Id;
9820 Check_Arg_Count (2);
9821 Check_No_Identifiers;
9822 Check_Arg_Is_Identifier (Arg1);
9823 Check_Arg_Is_Local_Name (Arg1);
9824 Check_Arg_Is_One_Of (Arg2,
9827 Name_By_Protected_Procedure,
9830 -- Extract the name of the local procedure
9832 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9834 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9835 -- primitive procedure of a synchronized tagged type.
9837 if Ekind (Proc_Id) = E_Procedure
9838 and then Is_Primitive (Proc_Id)
9839 and then Present (First_Formal (Proc_Id))
9841 Typ := Etype (First_Formal (Proc_Id));
9843 if Is_Tagged_Type (Typ)
9846 -- Check for a protected, a synchronized or a task interface
9848 ((Is_Interface (Typ)
9849 and then Is_Synchronized_Interface (Typ))
9851 -- Check for a protected type or a task type that implements
9855 (Is_Concurrent_Record_Type (Typ)
9856 and then Present (Interfaces (Typ)))
9858 -- Check for a private record extension with keyword
9862 (Ekind_In (Typ, E_Record_Type_With_Private,
9863 E_Record_Subtype_With_Private)
9864 and then Synchronized_Present (Parent (Typ))))
9869 ("controlling formal must be of synchronized " &
9870 "tagged type", Arg1);
9874 -- Procedures declared inside a protected type must be accepted
9876 elsif Ekind (Proc_Id) = E_Procedure
9877 and then Is_Protected_Type (Scope (Proc_Id))
9881 -- The first argument is not a primitive procedure
9885 ("pragma % must be applied to a primitive procedure", Arg1);
9889 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9890 -- By_Protected_Procedure to the primitive procedure of a task
9893 if Chars (Arg2) = Name_By_Protected_Procedure
9894 and then Is_Interface (Typ)
9895 and then Is_Task_Interface (Typ)
9898 ("implementation kind By_Protected_Procedure cannot be " &
9899 "applied to a task interface primitive", Arg2);
9903 Record_Rep_Item (Proc_Id, N);
9906 ----------------------
9907 -- Implicit_Packing --
9908 ----------------------
9910 -- pragma Implicit_Packing;
9912 when Pragma_Implicit_Packing =>
9914 Check_Arg_Count (0);
9915 Implicit_Packing := True;
9922 -- [Convention =>] convention_IDENTIFIER,
9923 -- [Entity =>] local_NAME
9924 -- [, [External_Name =>] static_string_EXPRESSION ]
9925 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9927 when Pragma_Import =>
9928 Check_Ada_83_Warning;
9935 Check_At_Least_N_Arguments (2);
9936 Check_At_Most_N_Arguments (4);
9937 Process_Import_Or_Interface;
9939 ----------------------
9940 -- Import_Exception --
9941 ----------------------
9943 -- pragma Import_Exception (
9944 -- [Internal =>] LOCAL_NAME
9945 -- [, [External =>] EXTERNAL_SYMBOL]
9946 -- [, [Form =>] Ada | VMS]
9947 -- [, [Code =>] static_integer_EXPRESSION]);
9949 when Pragma_Import_Exception => Import_Exception : declare
9950 Args : Args_List (1 .. 4);
9951 Names : constant Name_List (1 .. 4) := (
9957 Internal : Node_Id renames Args (1);
9958 External : Node_Id renames Args (2);
9959 Form : Node_Id renames Args (3);
9960 Code : Node_Id renames Args (4);
9964 Gather_Associations (Names, Args);
9966 if Present (External) and then Present (Code) then
9968 ("cannot give both External and Code options for pragma%");
9971 Process_Extended_Import_Export_Exception_Pragma (
9972 Arg_Internal => Internal,
9973 Arg_External => External,
9977 if not Is_VMS_Exception (Entity (Internal)) then
9978 Set_Imported (Entity (Internal));
9980 end Import_Exception;
9982 ---------------------
9983 -- Import_Function --
9984 ---------------------
9986 -- pragma Import_Function (
9987 -- [Internal =>] LOCAL_NAME,
9988 -- [, [External =>] EXTERNAL_SYMBOL]
9989 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9990 -- [, [Result_Type =>] SUBTYPE_MARK]
9991 -- [, [Mechanism =>] MECHANISM]
9992 -- [, [Result_Mechanism =>] MECHANISM_NAME]
9993 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9995 -- EXTERNAL_SYMBOL ::=
9997 -- | static_string_EXPRESSION
9999 -- PARAMETER_TYPES ::=
10001 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10003 -- TYPE_DESIGNATOR ::=
10005 -- | subtype_Name ' Access
10009 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10011 -- MECHANISM_ASSOCIATION ::=
10012 -- [formal_parameter_NAME =>] MECHANISM_NAME
10014 -- MECHANISM_NAME ::=
10017 -- | Descriptor [([Class =>] CLASS_NAME)]
10019 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10021 when Pragma_Import_Function => Import_Function : declare
10022 Args : Args_List (1 .. 7);
10023 Names : constant Name_List (1 .. 7) := (
10026 Name_Parameter_Types,
10029 Name_Result_Mechanism,
10030 Name_First_Optional_Parameter);
10032 Internal : Node_Id renames Args (1);
10033 External : Node_Id renames Args (2);
10034 Parameter_Types : Node_Id renames Args (3);
10035 Result_Type : Node_Id renames Args (4);
10036 Mechanism : Node_Id renames Args (5);
10037 Result_Mechanism : Node_Id renames Args (6);
10038 First_Optional_Parameter : Node_Id renames Args (7);
10042 Gather_Associations (Names, Args);
10043 Process_Extended_Import_Export_Subprogram_Pragma (
10044 Arg_Internal => Internal,
10045 Arg_External => External,
10046 Arg_Parameter_Types => Parameter_Types,
10047 Arg_Result_Type => Result_Type,
10048 Arg_Mechanism => Mechanism,
10049 Arg_Result_Mechanism => Result_Mechanism,
10050 Arg_First_Optional_Parameter => First_Optional_Parameter);
10051 end Import_Function;
10053 -------------------
10054 -- Import_Object --
10055 -------------------
10057 -- pragma Import_Object (
10058 -- [Internal =>] LOCAL_NAME
10059 -- [, [External =>] EXTERNAL_SYMBOL]
10060 -- [, [Size =>] EXTERNAL_SYMBOL]);
10062 -- EXTERNAL_SYMBOL ::=
10064 -- | static_string_EXPRESSION
10066 when Pragma_Import_Object => Import_Object : declare
10067 Args : Args_List (1 .. 3);
10068 Names : constant Name_List (1 .. 3) := (
10073 Internal : Node_Id renames Args (1);
10074 External : Node_Id renames Args (2);
10075 Size : Node_Id renames Args (3);
10079 Gather_Associations (Names, Args);
10080 Process_Extended_Import_Export_Object_Pragma (
10081 Arg_Internal => Internal,
10082 Arg_External => External,
10086 ----------------------
10087 -- Import_Procedure --
10088 ----------------------
10090 -- pragma Import_Procedure (
10091 -- [Internal =>] LOCAL_NAME
10092 -- [, [External =>] EXTERNAL_SYMBOL]
10093 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10094 -- [, [Mechanism =>] MECHANISM]
10095 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10097 -- EXTERNAL_SYMBOL ::=
10099 -- | static_string_EXPRESSION
10101 -- PARAMETER_TYPES ::=
10103 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10105 -- TYPE_DESIGNATOR ::=
10107 -- | subtype_Name ' Access
10111 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10113 -- MECHANISM_ASSOCIATION ::=
10114 -- [formal_parameter_NAME =>] MECHANISM_NAME
10116 -- MECHANISM_NAME ::=
10119 -- | Descriptor [([Class =>] CLASS_NAME)]
10121 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10123 when Pragma_Import_Procedure => Import_Procedure : declare
10124 Args : Args_List (1 .. 5);
10125 Names : constant Name_List (1 .. 5) := (
10128 Name_Parameter_Types,
10130 Name_First_Optional_Parameter);
10132 Internal : Node_Id renames Args (1);
10133 External : Node_Id renames Args (2);
10134 Parameter_Types : Node_Id renames Args (3);
10135 Mechanism : Node_Id renames Args (4);
10136 First_Optional_Parameter : Node_Id renames Args (5);
10140 Gather_Associations (Names, Args);
10141 Process_Extended_Import_Export_Subprogram_Pragma (
10142 Arg_Internal => Internal,
10143 Arg_External => External,
10144 Arg_Parameter_Types => Parameter_Types,
10145 Arg_Mechanism => Mechanism,
10146 Arg_First_Optional_Parameter => First_Optional_Parameter);
10147 end Import_Procedure;
10149 -----------------------------
10150 -- Import_Valued_Procedure --
10151 -----------------------------
10153 -- pragma Import_Valued_Procedure (
10154 -- [Internal =>] LOCAL_NAME
10155 -- [, [External =>] EXTERNAL_SYMBOL]
10156 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10157 -- [, [Mechanism =>] MECHANISM]
10158 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10160 -- EXTERNAL_SYMBOL ::=
10162 -- | static_string_EXPRESSION
10164 -- PARAMETER_TYPES ::=
10166 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10168 -- TYPE_DESIGNATOR ::=
10170 -- | subtype_Name ' Access
10174 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10176 -- MECHANISM_ASSOCIATION ::=
10177 -- [formal_parameter_NAME =>] MECHANISM_NAME
10179 -- MECHANISM_NAME ::=
10182 -- | Descriptor [([Class =>] CLASS_NAME)]
10184 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10186 when Pragma_Import_Valued_Procedure =>
10187 Import_Valued_Procedure : declare
10188 Args : Args_List (1 .. 5);
10189 Names : constant Name_List (1 .. 5) := (
10192 Name_Parameter_Types,
10194 Name_First_Optional_Parameter);
10196 Internal : Node_Id renames Args (1);
10197 External : Node_Id renames Args (2);
10198 Parameter_Types : Node_Id renames Args (3);
10199 Mechanism : Node_Id renames Args (4);
10200 First_Optional_Parameter : Node_Id renames Args (5);
10204 Gather_Associations (Names, Args);
10205 Process_Extended_Import_Export_Subprogram_Pragma (
10206 Arg_Internal => Internal,
10207 Arg_External => External,
10208 Arg_Parameter_Types => Parameter_Types,
10209 Arg_Mechanism => Mechanism,
10210 Arg_First_Optional_Parameter => First_Optional_Parameter);
10211 end Import_Valued_Procedure;
10217 -- pragma Independent (LOCAL_NAME);
10219 when Pragma_Independent => Independent : declare
10226 Check_Ada_83_Warning;
10228 Check_No_Identifiers;
10229 Check_Arg_Count (1);
10230 Check_Arg_Is_Local_Name (Arg1);
10231 E_Id := Get_Pragma_Arg (Arg1);
10233 if Etype (E_Id) = Any_Type then
10237 E := Entity (E_Id);
10238 D := Declaration_Node (E);
10241 -- Check duplicate before we chain ourselves!
10243 Check_Duplicate_Pragma (E);
10245 -- Check appropriate entity
10247 if Is_Type (E) then
10248 if Rep_Item_Too_Early (E, N)
10250 Rep_Item_Too_Late (E, N)
10254 Check_First_Subtype (Arg1);
10257 elsif K = N_Object_Declaration
10258 or else (K = N_Component_Declaration
10259 and then Original_Record_Component (E) = E)
10261 if Rep_Item_Too_Late (E, N) then
10267 ("inappropriate entity for pragma%", Arg1);
10270 Independence_Checks.Append ((N, E));
10273 ----------------------------
10274 -- Independent_Components --
10275 ----------------------------
10277 -- pragma Atomic_Components (array_LOCAL_NAME);
10279 -- This processing is shared by Volatile_Components
10281 when Pragma_Independent_Components => Independent_Components : declare
10288 Check_Ada_83_Warning;
10290 Check_No_Identifiers;
10291 Check_Arg_Count (1);
10292 Check_Arg_Is_Local_Name (Arg1);
10293 E_Id := Get_Pragma_Arg (Arg1);
10295 if Etype (E_Id) = Any_Type then
10299 E := Entity (E_Id);
10301 -- Check duplicate before we chain ourselves!
10303 Check_Duplicate_Pragma (E);
10305 -- Check appropriate entity
10307 if Rep_Item_Too_Early (E, N)
10309 Rep_Item_Too_Late (E, N)
10314 D := Declaration_Node (E);
10317 if (K = N_Full_Type_Declaration
10318 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
10320 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
10321 and then Nkind (D) = N_Object_Declaration
10322 and then Nkind (Object_Definition (D)) =
10323 N_Constrained_Array_Definition)
10325 Independence_Checks.Append ((N, E));
10328 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
10330 end Independent_Components;
10332 ------------------------
10333 -- Initialize_Scalars --
10334 ------------------------
10336 -- pragma Initialize_Scalars;
10338 when Pragma_Initialize_Scalars =>
10340 Check_Arg_Count (0);
10341 Check_Valid_Configuration_Pragma;
10342 Check_Restriction (No_Initialize_Scalars, N);
10344 -- Initialize_Scalars creates false positives in CodePeer, and
10345 -- incorrect negative results in Alfa mode, so ignore this pragma
10348 if not Restriction_Active (No_Initialize_Scalars)
10349 and then not (CodePeer_Mode or Alfa_Mode)
10351 Init_Or_Norm_Scalars := True;
10352 Initialize_Scalars := True;
10359 -- pragma Inline ( NAME {, NAME} );
10361 when Pragma_Inline =>
10363 -- Pragma is active if inlining option is active
10365 Process_Inline (Inline_Active);
10367 -------------------
10368 -- Inline_Always --
10369 -------------------
10371 -- pragma Inline_Always ( NAME {, NAME} );
10373 when Pragma_Inline_Always =>
10376 -- Pragma always active unless in CodePeer or Alfa mode, since
10377 -- this causes walk order issues.
10379 if not (CodePeer_Mode or Alfa_Mode) then
10380 Process_Inline (True);
10383 --------------------
10384 -- Inline_Generic --
10385 --------------------
10387 -- pragma Inline_Generic (NAME {, NAME});
10389 when Pragma_Inline_Generic =>
10391 Process_Generic_List;
10393 ----------------------
10394 -- Inspection_Point --
10395 ----------------------
10397 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
10399 when Pragma_Inspection_Point => Inspection_Point : declare
10404 if Arg_Count > 0 then
10407 Exp := Get_Pragma_Arg (Arg);
10410 if not Is_Entity_Name (Exp)
10411 or else not Is_Object (Entity (Exp))
10413 Error_Pragma_Arg ("object name required", Arg);
10417 exit when No (Arg);
10420 end Inspection_Point;
10426 -- pragma Interface (
10427 -- [ Convention =>] convention_IDENTIFIER,
10428 -- [ Entity =>] local_NAME
10429 -- [, [External_Name =>] static_string_EXPRESSION ]
10430 -- [, [Link_Name =>] static_string_EXPRESSION ]);
10432 when Pragma_Interface =>
10437 Name_External_Name,
10439 Check_At_Least_N_Arguments (2);
10440 Check_At_Most_N_Arguments (4);
10441 Process_Import_Or_Interface;
10443 -- In Ada 2005, the permission to use Interface (a reserved word)
10444 -- as a pragma name is considered an obsolescent feature.
10446 if Ada_Version >= Ada_2005 then
10448 (No_Obsolescent_Features, Pragma_Identifier (N));
10451 --------------------
10452 -- Interface_Name --
10453 --------------------
10455 -- pragma Interface_Name (
10456 -- [ Entity =>] local_NAME
10457 -- [,[External_Name =>] static_string_EXPRESSION ]
10458 -- [,[Link_Name =>] static_string_EXPRESSION ]);
10460 when Pragma_Interface_Name => Interface_Name : declare
10462 Def_Id : Entity_Id;
10463 Hom_Id : Entity_Id;
10469 ((Name_Entity, Name_External_Name, Name_Link_Name));
10470 Check_At_Least_N_Arguments (2);
10471 Check_At_Most_N_Arguments (3);
10472 Id := Get_Pragma_Arg (Arg1);
10475 if not Is_Entity_Name (Id) then
10477 ("first argument for pragma% must be entity name", Arg1);
10478 elsif Etype (Id) = Any_Type then
10481 Def_Id := Entity (Id);
10484 -- Special DEC-compatible processing for the object case, forces
10485 -- object to be imported.
10487 if Ekind (Def_Id) = E_Variable then
10488 Kill_Size_Check_Code (Def_Id);
10489 Note_Possible_Modification (Id, Sure => False);
10491 -- Initialization is not allowed for imported variable
10493 if Present (Expression (Parent (Def_Id)))
10494 and then Comes_From_Source (Expression (Parent (Def_Id)))
10496 Error_Msg_Sloc := Sloc (Def_Id);
10498 ("no initialization allowed for declaration of& #",
10502 -- For compatibility, support VADS usage of providing both
10503 -- pragmas Interface and Interface_Name to obtain the effect
10504 -- of a single Import pragma.
10506 if Is_Imported (Def_Id)
10507 and then Present (First_Rep_Item (Def_Id))
10508 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
10510 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
10514 Set_Imported (Def_Id);
10517 Set_Is_Public (Def_Id);
10518 Process_Interface_Name (Def_Id, Arg2, Arg3);
10521 -- Otherwise must be subprogram
10523 elsif not Is_Subprogram (Def_Id) then
10525 ("argument of pragma% is not subprogram", Arg1);
10528 Check_At_Most_N_Arguments (3);
10532 -- Loop through homonyms
10535 Def_Id := Get_Base_Subprogram (Hom_Id);
10537 if Is_Imported (Def_Id) then
10538 Process_Interface_Name (Def_Id, Arg2, Arg3);
10542 exit when From_Aspect_Specification (N);
10543 Hom_Id := Homonym (Hom_Id);
10545 exit when No (Hom_Id)
10546 or else Scope (Hom_Id) /= Current_Scope;
10551 ("argument of pragma% is not imported subprogram",
10555 end Interface_Name;
10557 -----------------------
10558 -- Interrupt_Handler --
10559 -----------------------
10561 -- pragma Interrupt_Handler (handler_NAME);
10563 when Pragma_Interrupt_Handler =>
10564 Check_Ada_83_Warning;
10565 Check_Arg_Count (1);
10566 Check_No_Identifiers;
10568 if No_Run_Time_Mode then
10569 Error_Msg_CRT ("Interrupt_Handler pragma", N);
10571 Check_Interrupt_Or_Attach_Handler;
10572 Process_Interrupt_Or_Attach_Handler;
10575 ------------------------
10576 -- Interrupt_Priority --
10577 ------------------------
10579 -- pragma Interrupt_Priority [(EXPRESSION)];
10581 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
10582 P : constant Node_Id := Parent (N);
10587 Check_Ada_83_Warning;
10589 if Arg_Count /= 0 then
10590 Arg := Get_Pragma_Arg (Arg1);
10591 Check_Arg_Count (1);
10592 Check_No_Identifiers;
10594 -- The expression must be analyzed in the special manner
10595 -- described in "Handling of Default and Per-Object
10596 -- Expressions" in sem.ads.
10598 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
10601 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
10606 Ent := Defining_Identifier (Parent (P));
10608 -- Check duplicate pragma before we chain the pragma in the Rep
10609 -- Item chain of Ent.
10611 Check_Duplicate_Pragma (Ent);
10612 Record_Rep_Item (Ent, N);
10614 end Interrupt_Priority;
10616 ---------------------
10617 -- Interrupt_State --
10618 ---------------------
10620 -- pragma Interrupt_State (
10621 -- [Name =>] INTERRUPT_ID,
10622 -- [State =>] INTERRUPT_STATE);
10624 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
10625 -- INTERRUPT_STATE => System | Runtime | User
10627 -- Note: if the interrupt id is given as an identifier, then it must
10628 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
10629 -- given as a static integer expression which must be in the range of
10630 -- Ada.Interrupts.Interrupt_ID.
10632 when Pragma_Interrupt_State => Interrupt_State : declare
10634 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
10635 -- This is the entity Ada.Interrupts.Interrupt_ID;
10637 State_Type : Character;
10638 -- Set to 's'/'r'/'u' for System/Runtime/User
10641 -- Index to entry in Interrupt_States table
10644 -- Value of interrupt
10646 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
10647 -- The first argument to the pragma
10649 Int_Ent : Entity_Id;
10650 -- Interrupt entity in Ada.Interrupts.Names
10654 Check_Arg_Order ((Name_Name, Name_State));
10655 Check_Arg_Count (2);
10657 Check_Optional_Identifier (Arg1, Name_Name);
10658 Check_Optional_Identifier (Arg2, Name_State);
10659 Check_Arg_Is_Identifier (Arg2);
10661 -- First argument is identifier
10663 if Nkind (Arg1X) = N_Identifier then
10665 -- Search list of names in Ada.Interrupts.Names
10667 Int_Ent := First_Entity (RTE (RE_Names));
10669 if No (Int_Ent) then
10670 Error_Pragma_Arg ("invalid interrupt name", Arg1);
10672 elsif Chars (Int_Ent) = Chars (Arg1X) then
10673 Int_Val := Expr_Value (Constant_Value (Int_Ent));
10677 Next_Entity (Int_Ent);
10680 -- First argument is not an identifier, so it must be a static
10681 -- expression of type Ada.Interrupts.Interrupt_ID.
10684 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10685 Int_Val := Expr_Value (Arg1X);
10687 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
10689 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10692 ("value not in range of type " &
10693 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10699 case Chars (Get_Pragma_Arg (Arg2)) is
10700 when Name_Runtime => State_Type := 'r';
10701 when Name_System => State_Type := 's';
10702 when Name_User => State_Type := 'u';
10705 Error_Pragma_Arg ("invalid interrupt state", Arg2);
10708 -- Check if entry is already stored
10710 IST_Num := Interrupt_States.First;
10712 -- If entry not found, add it
10714 if IST_Num > Interrupt_States.Last then
10715 Interrupt_States.Append
10716 ((Interrupt_Number => UI_To_Int (Int_Val),
10717 Interrupt_State => State_Type,
10718 Pragma_Loc => Loc));
10721 -- Case of entry for the same entry
10723 elsif Int_Val = Interrupt_States.Table (IST_Num).
10726 -- If state matches, done, no need to make redundant entry
10729 State_Type = Interrupt_States.Table (IST_Num).
10732 -- Otherwise if state does not match, error
10735 Interrupt_States.Table (IST_Num).Pragma_Loc;
10737 ("state conflicts with that given #", Arg2);
10741 IST_Num := IST_Num + 1;
10743 end Interrupt_State;
10749 -- pragma Invariant
10750 -- ([Entity =>] type_LOCAL_NAME,
10751 -- [Check =>] EXPRESSION
10752 -- [,[Message =>] String_Expression]);
10754 when Pragma_Invariant => Invariant : declare
10760 pragma Unreferenced (Discard);
10764 Check_At_Least_N_Arguments (2);
10765 Check_At_Most_N_Arguments (3);
10766 Check_Optional_Identifier (Arg1, Name_Entity);
10767 Check_Optional_Identifier (Arg2, Name_Check);
10769 if Arg_Count = 3 then
10770 Check_Optional_Identifier (Arg3, Name_Message);
10771 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10774 Check_Arg_Is_Local_Name (Arg1);
10776 Type_Id := Get_Pragma_Arg (Arg1);
10777 Find_Type (Type_Id);
10778 Typ := Entity (Type_Id);
10780 if Typ = Any_Type then
10783 -- An invariant must apply to a private type, or appear in the
10784 -- private part of a package spec and apply to a completion.
10786 elsif Ekind_In (Typ, E_Private_Type,
10787 E_Record_Type_With_Private,
10788 E_Limited_Private_Type)
10792 elsif In_Private_Part (Current_Scope)
10793 and then Has_Private_Declaration (Typ)
10797 elsif In_Private_Part (Current_Scope) then
10799 ("pragma% only allowed for private type " &
10800 "declared in visible part", Arg1);
10804 ("pragma% only allowed for private type", Arg1);
10807 -- Note that the type has at least one invariant, and also that
10808 -- it has inheritable invariants if we have Invariant'Class.
10809 -- Build the corresponding invariant procedure declaration, so
10810 -- that calls to it can be generated before the body is built
10811 -- (for example wihin an expression function).
10813 PDecl := Build_Invariant_Procedure_Declaration (Typ);
10814 Insert_After (N, PDecl);
10817 if Class_Present (N) then
10818 Set_Has_Inheritable_Invariants (Typ);
10821 -- The remaining processing is simply to link the pragma on to
10822 -- the rep item chain, for processing when the type is frozen.
10823 -- This is accomplished by a call to Rep_Item_Too_Late.
10825 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10828 ----------------------
10829 -- Java_Constructor --
10830 ----------------------
10832 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10834 -- Also handles pragma CIL_Constructor
10836 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10837 Java_Constructor : declare
10838 Convention : Convention_Id;
10839 Def_Id : Entity_Id;
10840 Hom_Id : Entity_Id;
10842 This_Formal : Entity_Id;
10846 Check_Arg_Count (1);
10847 Check_Optional_Identifier (Arg1, Name_Entity);
10848 Check_Arg_Is_Local_Name (Arg1);
10850 Id := Get_Pragma_Arg (Arg1);
10851 Find_Program_Unit_Name (Id);
10853 -- If we did not find the name, we are done
10855 if Etype (Id) = Any_Type then
10859 -- Check wrong use of pragma in wrong VM target
10861 if VM_Target = No_VM then
10864 elsif VM_Target = CLI_Target
10865 and then Prag_Id = Pragma_Java_Constructor
10867 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10869 elsif VM_Target = JVM_Target
10870 and then Prag_Id = Pragma_CIL_Constructor
10872 Error_Pragma ("must use pragma 'Java_'Constructor");
10876 when Pragma_CIL_Constructor => Convention := Convention_CIL;
10877 when Pragma_Java_Constructor => Convention := Convention_Java;
10878 when others => null;
10881 Hom_Id := Entity (Id);
10883 -- Loop through homonyms
10886 Def_Id := Get_Base_Subprogram (Hom_Id);
10888 -- The constructor is required to be a function
10890 if Ekind (Def_Id) /= E_Function then
10891 if VM_Target = JVM_Target then
10893 ("pragma% requires function returning a " &
10894 "'Java access type", Def_Id);
10897 ("pragma% requires function returning a " &
10898 "'C'I'L access type", Def_Id);
10902 -- Check arguments: For tagged type the first formal must be
10903 -- named "this" and its type must be a named access type
10904 -- designating a class-wide tagged type that has convention
10905 -- CIL/Java. The first formal must also have a null default
10906 -- value. For example:
10908 -- type Typ is tagged ...
10909 -- type Ref is access all Typ;
10910 -- pragma Convention (CIL, Typ);
10912 -- function New_Typ (This : Ref) return Ref;
10913 -- function New_Typ (This : Ref; I : Integer) return Ref;
10914 -- pragma Cil_Constructor (New_Typ);
10916 -- Reason: The first formal must NOT be a primitive of the
10919 -- This rule also applies to constructors of delegates used
10920 -- to interface with standard target libraries. For example:
10922 -- type Delegate is access procedure ...
10923 -- pragma Import (CIL, Delegate, ...);
10925 -- function new_Delegate
10926 -- (This : Delegate := null; ... ) return Delegate;
10928 -- For value-types this rule does not apply.
10930 if not Is_Value_Type (Etype (Def_Id)) then
10931 if No (First_Formal (Def_Id)) then
10932 Error_Msg_Name_1 := Pname;
10933 Error_Msg_N ("% function must have parameters", Def_Id);
10937 -- In the JRE library we have several occurrences in which
10938 -- the "this" parameter is not the first formal.
10940 This_Formal := First_Formal (Def_Id);
10942 -- In the JRE library we have several occurrences in which
10943 -- the "this" parameter is not the first formal. Search for
10946 if VM_Target = JVM_Target then
10947 while Present (This_Formal)
10948 and then Get_Name_String (Chars (This_Formal)) /= "this"
10950 Next_Formal (This_Formal);
10953 if No (This_Formal) then
10954 This_Formal := First_Formal (Def_Id);
10958 -- Warning: The first parameter should be named "this".
10959 -- We temporarily allow it because we have the following
10960 -- case in the Java runtime (file s-osinte.ads) ???
10962 -- function new_Thread
10963 -- (Self_Id : System.Address) return Thread_Id;
10964 -- pragma Java_Constructor (new_Thread);
10966 if VM_Target = JVM_Target
10967 and then Get_Name_String (Chars (First_Formal (Def_Id)))
10969 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10973 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10974 Error_Msg_Name_1 := Pname;
10976 ("first formal of % function must be named `this`",
10977 Parent (This_Formal));
10979 elsif not Is_Access_Type (Etype (This_Formal)) then
10980 Error_Msg_Name_1 := Pname;
10982 ("first formal of % function must be an access type",
10983 Parameter_Type (Parent (This_Formal)));
10985 -- For delegates the type of the first formal must be a
10986 -- named access-to-subprogram type (see previous example)
10988 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10989 and then Ekind (Etype (This_Formal))
10990 /= E_Access_Subprogram_Type
10992 Error_Msg_Name_1 := Pname;
10994 ("first formal of % function must be a named access" &
10995 " to subprogram type",
10996 Parameter_Type (Parent (This_Formal)));
10998 -- Warning: We should reject anonymous access types because
10999 -- the constructor must not be handled as a primitive of the
11000 -- tagged type. We temporarily allow it because this profile
11001 -- is currently generated by cil2ada???
11003 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
11004 and then not Ekind_In (Etype (This_Formal),
11006 E_General_Access_Type,
11007 E_Anonymous_Access_Type)
11009 Error_Msg_Name_1 := Pname;
11011 ("first formal of % function must be a named access" &
11013 Parameter_Type (Parent (This_Formal)));
11015 elsif Atree.Convention
11016 (Designated_Type (Etype (This_Formal))) /= Convention
11018 Error_Msg_Name_1 := Pname;
11020 if Convention = Convention_Java then
11022 ("pragma% requires convention 'Cil in designated" &
11024 Parameter_Type (Parent (This_Formal)));
11027 ("pragma% requires convention 'Java in designated" &
11029 Parameter_Type (Parent (This_Formal)));
11032 elsif No (Expression (Parent (This_Formal)))
11033 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
11035 Error_Msg_Name_1 := Pname;
11037 ("pragma% requires first formal with default `null`",
11038 Parameter_Type (Parent (This_Formal)));
11042 -- Check result type: the constructor must be a function
11044 -- * a value type (only allowed in the CIL compiler)
11045 -- * an access-to-subprogram type with convention Java/CIL
11046 -- * an access-type designating a type that has convention
11049 if Is_Value_Type (Etype (Def_Id)) then
11052 -- Access-to-subprogram type with convention Java/CIL
11054 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
11055 if Atree.Convention (Etype (Def_Id)) /= Convention then
11056 if Convention = Convention_Java then
11058 ("pragma% requires function returning a " &
11059 "'Java access type", Arg1);
11061 pragma Assert (Convention = Convention_CIL);
11063 ("pragma% requires function returning a " &
11064 "'C'I'L access type", Arg1);
11068 elsif Ekind (Etype (Def_Id)) in Access_Kind then
11069 if not Ekind_In (Etype (Def_Id), E_Access_Type,
11070 E_General_Access_Type)
11073 (Designated_Type (Etype (Def_Id))) /= Convention
11075 Error_Msg_Name_1 := Pname;
11077 if Convention = Convention_Java then
11079 ("pragma% requires function returning a named" &
11080 "'Java access type", Arg1);
11083 ("pragma% requires function returning a named" &
11084 "'C'I'L access type", Arg1);
11089 Set_Is_Constructor (Def_Id);
11090 Set_Convention (Def_Id, Convention);
11091 Set_Is_Imported (Def_Id);
11093 exit when From_Aspect_Specification (N);
11094 Hom_Id := Homonym (Hom_Id);
11096 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
11098 end Java_Constructor;
11100 ----------------------
11101 -- Java_Interface --
11102 ----------------------
11104 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
11106 when Pragma_Java_Interface => Java_Interface : declare
11112 Check_Arg_Count (1);
11113 Check_Optional_Identifier (Arg1, Name_Entity);
11114 Check_Arg_Is_Local_Name (Arg1);
11116 Arg := Get_Pragma_Arg (Arg1);
11119 if Etype (Arg) = Any_Type then
11123 if not Is_Entity_Name (Arg)
11124 or else not Is_Type (Entity (Arg))
11126 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
11129 Typ := Underlying_Type (Entity (Arg));
11131 -- For now simply check some of the semantic constraints on the
11132 -- type. This currently leaves out some restrictions on interface
11133 -- types, namely that the parent type must be java.lang.Object.Typ
11134 -- and that all primitives of the type should be declared
11137 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
11138 Error_Pragma_Arg ("pragma% requires an abstract "
11139 & "tagged type", Arg1);
11141 elsif not Has_Discriminants (Typ)
11142 or else Ekind (Etype (First_Discriminant (Typ)))
11143 /= E_Anonymous_Access_Type
11145 not Is_Class_Wide_Type
11146 (Designated_Type (Etype (First_Discriminant (Typ))))
11149 ("type must have a class-wide access discriminant", Arg1);
11151 end Java_Interface;
11157 -- pragma Keep_Names ([On => ] local_NAME);
11159 when Pragma_Keep_Names => Keep_Names : declare
11164 Check_Arg_Count (1);
11165 Check_Optional_Identifier (Arg1, Name_On);
11166 Check_Arg_Is_Local_Name (Arg1);
11168 Arg := Get_Pragma_Arg (Arg1);
11171 if Etype (Arg) = Any_Type then
11175 if not Is_Entity_Name (Arg)
11176 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
11179 ("pragma% requires a local enumeration type", Arg1);
11182 Set_Discard_Names (Entity (Arg), False);
11189 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
11191 when Pragma_License =>
11193 Check_Arg_Count (1);
11194 Check_No_Identifiers;
11195 Check_Valid_Configuration_Pragma;
11196 Check_Arg_Is_Identifier (Arg1);
11199 Sind : constant Source_File_Index :=
11200 Source_Index (Current_Sem_Unit);
11203 case Chars (Get_Pragma_Arg (Arg1)) is
11205 Set_License (Sind, GPL);
11207 when Name_Modified_GPL =>
11208 Set_License (Sind, Modified_GPL);
11210 when Name_Restricted =>
11211 Set_License (Sind, Restricted);
11213 when Name_Unrestricted =>
11214 Set_License (Sind, Unrestricted);
11217 Error_Pragma_Arg ("invalid license name", Arg1);
11225 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
11227 when Pragma_Link_With => Link_With : declare
11233 if Operating_Mode = Generate_Code
11234 and then In_Extended_Main_Source_Unit (N)
11236 Check_At_Least_N_Arguments (1);
11237 Check_No_Identifiers;
11238 Check_Is_In_Decl_Part_Or_Package_Spec;
11239 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11243 while Present (Arg) loop
11244 Check_Arg_Is_Static_Expression (Arg, Standard_String);
11246 -- Store argument, converting sequences of spaces to a
11247 -- single null character (this is one of the differences
11248 -- in processing between Link_With and Linker_Options).
11250 Arg_Store : declare
11251 C : constant Char_Code := Get_Char_Code (' ');
11252 S : constant String_Id :=
11253 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
11254 L : constant Nat := String_Length (S);
11257 procedure Skip_Spaces;
11258 -- Advance F past any spaces
11264 procedure Skip_Spaces is
11266 while F <= L and then Get_String_Char (S, F) = C loop
11271 -- Start of processing for Arg_Store
11274 Skip_Spaces; -- skip leading spaces
11276 -- Loop through characters, changing any embedded
11277 -- sequence of spaces to a single null character (this
11278 -- is how Link_With/Linker_Options differ)
11281 if Get_String_Char (S, F) = C then
11284 Store_String_Char (ASCII.NUL);
11287 Store_String_Char (Get_String_Char (S, F));
11295 if Present (Arg) then
11296 Store_String_Char (ASCII.NUL);
11300 Store_Linker_Option_String (End_String);
11308 -- pragma Linker_Alias (
11309 -- [Entity =>] LOCAL_NAME
11310 -- [Target =>] static_string_EXPRESSION);
11312 when Pragma_Linker_Alias =>
11314 Check_Arg_Order ((Name_Entity, Name_Target));
11315 Check_Arg_Count (2);
11316 Check_Optional_Identifier (Arg1, Name_Entity);
11317 Check_Optional_Identifier (Arg2, Name_Target);
11318 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11319 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11321 -- The only processing required is to link this item on to the
11322 -- list of rep items for the given entity. This is accomplished
11323 -- by the call to Rep_Item_Too_Late (when no error is detected
11324 -- and False is returned).
11326 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
11329 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11332 ------------------------
11333 -- Linker_Constructor --
11334 ------------------------
11336 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
11338 -- Code is shared with Linker_Destructor
11340 -----------------------
11341 -- Linker_Destructor --
11342 -----------------------
11344 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
11346 when Pragma_Linker_Constructor |
11347 Pragma_Linker_Destructor =>
11348 Linker_Constructor : declare
11354 Check_Arg_Count (1);
11355 Check_No_Identifiers;
11356 Check_Arg_Is_Local_Name (Arg1);
11357 Arg1_X := Get_Pragma_Arg (Arg1);
11359 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
11361 if not Is_Library_Level_Entity (Proc) then
11363 ("argument for pragma% must be library level entity", Arg1);
11366 -- The only processing required is to link this item on to the
11367 -- list of rep items for the given entity. This is accomplished
11368 -- by the call to Rep_Item_Too_Late (when no error is detected
11369 -- and False is returned).
11371 if Rep_Item_Too_Late (Proc, N) then
11374 Set_Has_Gigi_Rep_Item (Proc);
11376 end Linker_Constructor;
11378 --------------------
11379 -- Linker_Options --
11380 --------------------
11382 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
11384 when Pragma_Linker_Options => Linker_Options : declare
11388 Check_Ada_83_Warning;
11389 Check_No_Identifiers;
11390 Check_Arg_Count (1);
11391 Check_Is_In_Decl_Part_Or_Package_Spec;
11392 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11393 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
11396 while Present (Arg) loop
11397 Check_Arg_Is_Static_Expression (Arg, Standard_String);
11398 Store_String_Char (ASCII.NUL);
11400 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
11404 if Operating_Mode = Generate_Code
11405 and then In_Extended_Main_Source_Unit (N)
11407 Store_Linker_Option_String (End_String);
11409 end Linker_Options;
11411 --------------------
11412 -- Linker_Section --
11413 --------------------
11415 -- pragma Linker_Section (
11416 -- [Entity =>] LOCAL_NAME
11417 -- [Section =>] static_string_EXPRESSION);
11419 when Pragma_Linker_Section =>
11421 Check_Arg_Order ((Name_Entity, Name_Section));
11422 Check_Arg_Count (2);
11423 Check_Optional_Identifier (Arg1, Name_Entity);
11424 Check_Optional_Identifier (Arg2, Name_Section);
11425 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11426 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11428 -- This pragma applies only to objects
11430 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
11431 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
11434 -- The only processing required is to link this item on to the
11435 -- list of rep items for the given entity. This is accomplished
11436 -- by the call to Rep_Item_Too_Late (when no error is detected
11437 -- and False is returned).
11439 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
11442 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11449 -- pragma List (On | Off)
11451 -- There is nothing to do here, since we did all the processing for
11452 -- this pragma in Par.Prag (so that it works properly even in syntax
11455 when Pragma_List =>
11462 -- pragma Lock_Free [(Boolean_EXPRESSION)];
11464 when Pragma_Lock_Free => Lock_Free : declare
11465 P : constant Node_Id := Parent (N);
11471 Check_No_Identifiers;
11472 Check_At_Most_N_Arguments (1);
11474 -- Protected definition case
11476 if Nkind (P) = N_Protected_Definition then
11477 Ent := Defining_Identifier (Parent (P));
11481 if Arg_Count = 1 then
11482 Arg := Get_Pragma_Arg (Arg1);
11483 Val := Is_True (Static_Boolean (Arg));
11485 -- No arguments (expression is considered to be True)
11491 -- Check duplicate pragma before we chain the pragma in the Rep
11492 -- Item chain of Ent.
11494 Check_Duplicate_Pragma (Ent);
11495 Record_Rep_Item (Ent, N);
11496 Set_Uses_Lock_Free (Ent, Val);
11498 -- Anything else is incorrect placement
11505 --------------------
11506 -- Locking_Policy --
11507 --------------------
11509 -- pragma Locking_Policy (policy_IDENTIFIER);
11511 when Pragma_Locking_Policy => declare
11512 subtype LP_Range is Name_Id
11513 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
11518 Check_Ada_83_Warning;
11519 Check_Arg_Count (1);
11520 Check_No_Identifiers;
11521 Check_Arg_Is_Locking_Policy (Arg1);
11522 Check_Valid_Configuration_Pragma;
11523 LP_Val := Chars (Get_Pragma_Arg (Arg1));
11526 when Name_Ceiling_Locking =>
11528 when Name_Inheritance_Locking =>
11530 when Name_Concurrent_Readers_Locking =>
11534 if Locking_Policy /= ' '
11535 and then Locking_Policy /= LP
11537 Error_Msg_Sloc := Locking_Policy_Sloc;
11538 Error_Pragma ("locking policy incompatible with policy#");
11540 -- Set new policy, but always preserve System_Location since we
11541 -- like the error message with the run time name.
11544 Locking_Policy := LP;
11546 if Locking_Policy_Sloc /= System_Location then
11547 Locking_Policy_Sloc := Loc;
11556 -- pragma Long_Float (D_Float | G_Float);
11558 when Pragma_Long_Float => Long_Float : declare
11561 Check_Valid_Configuration_Pragma;
11562 Check_Arg_Count (1);
11563 Check_No_Identifier (Arg1);
11564 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
11566 if not OpenVMS_On_Target then
11567 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
11572 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
11573 if Opt.Float_Format_Long = 'G' then
11575 ("G_Float previously specified", Arg1);
11577 elsif Current_Sem_Unit /= Main_Unit
11578 and then Opt.Float_Format_Long /= 'D'
11581 ("main unit not compiled with pragma Long_Float (D_Float)",
11582 "\pragma% must be used consistently for whole partition",
11586 Opt.Float_Format_Long := 'D';
11589 -- G_Float case (this is the default, does not need overriding)
11592 if Opt.Float_Format_Long = 'D' then
11593 Error_Pragma ("D_Float previously specified");
11595 elsif Current_Sem_Unit /= Main_Unit
11596 and then Opt.Float_Format_Long /= 'G'
11599 ("main unit not compiled with pragma Long_Float (G_Float)",
11600 "\pragma% must be used consistently for whole partition",
11604 Opt.Float_Format_Long := 'G';
11608 Set_Standard_Fpt_Formats;
11611 --------------------
11612 -- Loop_Invariant --
11613 --------------------
11615 -- pragma Loop_Invariant ( boolean_EXPRESSION );
11617 when Pragma_Loop_Invariant => Loop_Invariant : declare
11621 Check_Arg_Count (1);
11622 Check_Loop_Invariant_Variant_Placement;
11624 -- Completely ignore if disabled
11626 if Check_Disabled (Pname) then
11627 Rewrite (N, Make_Null_Statement (Loc));
11632 Preanalyze_And_Resolve (Expression (Arg1), Any_Boolean);
11634 -- Transform pragma Loop_Invariant into equivalent pragma Check
11636 -- pragma Check (Loop_Invaraint, Arg1);
11638 -- Seems completely wrong to hijack pragma Check this way ???
11642 Chars => Name_Check,
11643 Pragma_Argument_Associations => New_List (
11644 Make_Pragma_Argument_Association (Loc,
11645 Expression => Make_Identifier (Loc, Name_Loop_Invariant)),
11646 Relocate_Node (Arg1))));
11649 end Loop_Invariant;
11655 -- pragma Loop_Variant
11656 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
11658 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
11660 -- CHANGE_DIRECTION ::= Increases | Decreases
11662 when Pragma_Loop_Variant => Loop_Variant : declare
11668 Check_At_Least_N_Arguments (1);
11669 Check_Loop_Invariant_Variant_Placement;
11671 -- Completely ignore if disabled
11673 if Check_Disabled (Pname) then
11674 Rewrite (N, Make_Null_Statement (Loc));
11679 -- Process all increasing / decreasing expressions
11681 Variant := First (Pragma_Argument_Associations (N));
11682 while Present (Variant) loop
11683 if Chars (Variant) /= Name_Decreases
11684 and then Chars (Variant) /= Name_Increases
11686 Error_Pragma_Arg ("wrong change modifier", Variant);
11689 Preanalyze_And_Resolve (Expression (Variant), Any_Discrete);
11695 -----------------------
11696 -- Machine_Attribute --
11697 -----------------------
11699 -- pragma Machine_Attribute (
11700 -- [Entity =>] LOCAL_NAME,
11701 -- [Attribute_Name =>] static_string_EXPRESSION
11702 -- [, [Info =>] static_EXPRESSION] );
11704 when Pragma_Machine_Attribute => Machine_Attribute : declare
11705 Def_Id : Entity_Id;
11709 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
11711 if Arg_Count = 3 then
11712 Check_Optional_Identifier (Arg3, Name_Info);
11713 Check_Arg_Is_Static_Expression (Arg3);
11715 Check_Arg_Count (2);
11718 Check_Optional_Identifier (Arg1, Name_Entity);
11719 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
11720 Check_Arg_Is_Local_Name (Arg1);
11721 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11722 Def_Id := Entity (Get_Pragma_Arg (Arg1));
11724 if Is_Access_Type (Def_Id) then
11725 Def_Id := Designated_Type (Def_Id);
11728 if Rep_Item_Too_Early (Def_Id, N) then
11732 Def_Id := Underlying_Type (Def_Id);
11734 -- The only processing required is to link this item on to the
11735 -- list of rep items for the given entity. This is accomplished
11736 -- by the call to Rep_Item_Too_Late (when no error is detected
11737 -- and False is returned).
11739 if Rep_Item_Too_Late (Def_Id, N) then
11742 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11744 end Machine_Attribute;
11751 -- (MAIN_OPTION [, MAIN_OPTION]);
11754 -- [STACK_SIZE =>] static_integer_EXPRESSION
11755 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
11756 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
11758 when Pragma_Main => Main : declare
11759 Args : Args_List (1 .. 3);
11760 Names : constant Name_List (1 .. 3) := (
11762 Name_Task_Stack_Size_Default,
11763 Name_Time_Slicing_Enabled);
11769 Gather_Associations (Names, Args);
11771 for J in 1 .. 2 loop
11772 if Present (Args (J)) then
11773 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11777 if Present (Args (3)) then
11778 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
11782 while Present (Nod) loop
11783 if Nkind (Nod) = N_Pragma
11784 and then Pragma_Name (Nod) = Name_Main
11786 Error_Msg_Name_1 := Pname;
11787 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11798 -- pragma Main_Storage
11799 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
11801 -- MAIN_STORAGE_OPTION ::=
11802 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
11803 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
11805 when Pragma_Main_Storage => Main_Storage : declare
11806 Args : Args_List (1 .. 2);
11807 Names : constant Name_List (1 .. 2) := (
11808 Name_Working_Storage,
11815 Gather_Associations (Names, Args);
11817 for J in 1 .. 2 loop
11818 if Present (Args (J)) then
11819 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11823 Check_In_Main_Program;
11826 while Present (Nod) loop
11827 if Nkind (Nod) = N_Pragma
11828 and then Pragma_Name (Nod) = Name_Main_Storage
11830 Error_Msg_Name_1 := Pname;
11831 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11842 -- pragma Memory_Size (NUMERIC_LITERAL)
11844 when Pragma_Memory_Size =>
11847 -- Memory size is simply ignored
11849 Check_No_Identifiers;
11850 Check_Arg_Count (1);
11851 Check_Arg_Is_Integer_Literal (Arg1);
11859 -- The only correct use of this pragma is on its own in a file, in
11860 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
11861 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
11862 -- check for a file containing nothing but a No_Body pragma). If we
11863 -- attempt to process it during normal semantics processing, it means
11864 -- it was misplaced.
11866 when Pragma_No_Body =>
11874 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
11876 when Pragma_No_Return => No_Return : declare
11884 Check_At_Least_N_Arguments (1);
11886 -- Loop through arguments of pragma
11889 while Present (Arg) loop
11890 Check_Arg_Is_Local_Name (Arg);
11891 Id := Get_Pragma_Arg (Arg);
11894 if not Is_Entity_Name (Id) then
11895 Error_Pragma_Arg ("entity name required", Arg);
11898 if Etype (Id) = Any_Type then
11902 -- Loop to find matching procedures
11907 and then Scope (E) = Current_Scope
11909 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11912 -- Set flag on any alias as well
11914 if Is_Overloadable (E) and then Present (Alias (E)) then
11915 Set_No_Return (Alias (E));
11921 exit when From_Aspect_Specification (N);
11926 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11937 -- pragma No_Run_Time;
11939 -- Note: this pragma is retained for backwards compatibility. See
11940 -- body of Rtsfind for full details on its handling.
11942 when Pragma_No_Run_Time =>
11944 Check_Valid_Configuration_Pragma;
11945 Check_Arg_Count (0);
11947 No_Run_Time_Mode := True;
11948 Configurable_Run_Time_Mode := True;
11950 -- Set Duration to 32 bits if word size is 32
11952 if Ttypes.System_Word_Size = 32 then
11953 Duration_32_Bits_On_Target := True;
11956 -- Set appropriate restrictions
11958 Set_Restriction (No_Finalization, N);
11959 Set_Restriction (No_Exception_Handlers, N);
11960 Set_Restriction (Max_Tasks, N, 0);
11961 Set_Restriction (No_Tasking, N);
11963 ------------------------
11964 -- No_Strict_Aliasing --
11965 ------------------------
11967 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11969 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11974 Check_At_Most_N_Arguments (1);
11976 if Arg_Count = 0 then
11977 Check_Valid_Configuration_Pragma;
11978 Opt.No_Strict_Aliasing := True;
11981 Check_Optional_Identifier (Arg2, Name_Entity);
11982 Check_Arg_Is_Local_Name (Arg1);
11983 E_Id := Entity (Get_Pragma_Arg (Arg1));
11985 if E_Id = Any_Type then
11987 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11988 Error_Pragma_Arg ("pragma% requires access type", Arg1);
11991 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11993 end No_Strict_Aliasing;
11995 -----------------------
11996 -- Normalize_Scalars --
11997 -----------------------
11999 -- pragma Normalize_Scalars;
12001 when Pragma_Normalize_Scalars =>
12002 Check_Ada_83_Warning;
12003 Check_Arg_Count (0);
12004 Check_Valid_Configuration_Pragma;
12006 -- Normalize_Scalars creates false positives in CodePeer, and
12007 -- incorrect negative results in Alfa mode, so ignore this pragma
12010 if not (CodePeer_Mode or Alfa_Mode) then
12011 Normalize_Scalars := True;
12012 Init_Or_Norm_Scalars := True;
12019 -- pragma Obsolescent;
12021 -- pragma Obsolescent (
12022 -- [Message =>] static_string_EXPRESSION
12023 -- [,[Version =>] Ada_05]]);
12025 -- pragma Obsolescent (
12026 -- [Entity =>] NAME
12027 -- [,[Message =>] static_string_EXPRESSION
12028 -- [,[Version =>] Ada_05]] );
12030 when Pragma_Obsolescent => Obsolescent : declare
12034 procedure Set_Obsolescent (E : Entity_Id);
12035 -- Given an entity Ent, mark it as obsolescent if appropriate
12037 ---------------------
12038 -- Set_Obsolescent --
12039 ---------------------
12041 procedure Set_Obsolescent (E : Entity_Id) is
12050 -- Entity name was given
12052 if Present (Ename) then
12054 -- If entity name matches, we are fine. Save entity in
12055 -- pragma argument, for ASIS use.
12057 if Chars (Ename) = Chars (Ent) then
12058 Set_Entity (Ename, Ent);
12059 Generate_Reference (Ent, Ename);
12061 -- If entity name does not match, only possibility is an
12062 -- enumeration literal from an enumeration type declaration.
12064 elsif Ekind (Ent) /= E_Enumeration_Type then
12066 ("pragma % entity name does not match declaration");
12069 Ent := First_Literal (E);
12073 ("pragma % entity name does not match any " &
12074 "enumeration literal");
12076 elsif Chars (Ent) = Chars (Ename) then
12077 Set_Entity (Ename, Ent);
12078 Generate_Reference (Ent, Ename);
12082 Ent := Next_Literal (Ent);
12088 -- Ent points to entity to be marked
12090 if Arg_Count >= 1 then
12092 -- Deal with static string argument
12094 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12095 S := Strval (Get_Pragma_Arg (Arg1));
12097 for J in 1 .. String_Length (S) loop
12098 if not In_Character_Range (Get_String_Char (S, J)) then
12100 ("pragma% argument does not allow wide characters",
12105 Obsolescent_Warnings.Append
12106 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
12108 -- Check for Ada_05 parameter
12110 if Arg_Count /= 1 then
12111 Check_Arg_Count (2);
12114 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
12117 Check_Arg_Is_Identifier (Argx);
12119 if Chars (Argx) /= Name_Ada_05 then
12120 Error_Msg_Name_2 := Name_Ada_05;
12122 ("only allowed argument for pragma% is %", Argx);
12125 if Ada_Version_Explicit < Ada_2005
12126 or else not Warn_On_Ada_2005_Compatibility
12134 -- Set flag if pragma active
12137 Set_Is_Obsolescent (Ent);
12141 end Set_Obsolescent;
12143 -- Start of processing for pragma Obsolescent
12148 Check_At_Most_N_Arguments (3);
12150 -- See if first argument specifies an entity name
12154 (Chars (Arg1) = Name_Entity
12156 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
12158 N_Operator_Symbol))
12160 Ename := Get_Pragma_Arg (Arg1);
12162 -- Eliminate first argument, so we can share processing
12166 Arg_Count := Arg_Count - 1;
12168 -- No Entity name argument given
12174 if Arg_Count >= 1 then
12175 Check_Optional_Identifier (Arg1, Name_Message);
12177 if Arg_Count = 2 then
12178 Check_Optional_Identifier (Arg2, Name_Version);
12182 -- Get immediately preceding declaration
12185 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
12189 -- Cases where we do not follow anything other than another pragma
12193 -- First case: library level compilation unit declaration with
12194 -- the pragma immediately following the declaration.
12196 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
12198 (Defining_Entity (Unit (Parent (Parent (N)))));
12201 -- Case 2: library unit placement for package
12205 Ent : constant Entity_Id := Find_Lib_Unit_Name;
12207 if Is_Package_Or_Generic_Package (Ent) then
12208 Set_Obsolescent (Ent);
12214 -- Cases where we must follow a declaration
12217 if Nkind (Decl) not in N_Declaration
12218 and then Nkind (Decl) not in N_Later_Decl_Item
12219 and then Nkind (Decl) not in N_Generic_Declaration
12220 and then Nkind (Decl) not in N_Renaming_Declaration
12223 ("pragma% misplaced, "
12224 & "must immediately follow a declaration");
12227 Set_Obsolescent (Defining_Entity (Decl));
12237 -- pragma Optimize (Time | Space | Off);
12239 -- The actual check for optimize is done in Gigi. Note that this
12240 -- pragma does not actually change the optimization setting, it
12241 -- simply checks that it is consistent with the pragma.
12243 when Pragma_Optimize =>
12244 Check_No_Identifiers;
12245 Check_Arg_Count (1);
12246 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
12248 ------------------------
12249 -- Optimize_Alignment --
12250 ------------------------
12252 -- pragma Optimize_Alignment (Time | Space | Off);
12254 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
12256 Check_No_Identifiers;
12257 Check_Arg_Count (1);
12258 Check_Valid_Configuration_Pragma;
12261 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
12265 Opt.Optimize_Alignment := 'T';
12267 Opt.Optimize_Alignment := 'S';
12269 Opt.Optimize_Alignment := 'O';
12271 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
12275 -- Set indication that mode is set locally. If we are in fact in a
12276 -- configuration pragma file, this setting is harmless since the
12277 -- switch will get reset anyway at the start of each unit.
12279 Optimize_Alignment_Local := True;
12280 end Optimize_Alignment;
12282 -------------------
12283 -- Overflow_Mode --
12284 -------------------
12286 -- pragma Overflow_Mode
12287 -- ([General => ] MODE [, [Assertions => ] MODE]);
12289 -- MODE := STRICT | MINIMIZED | ELIMINATED
12291 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
12292 -- since System.Bignums makes this assumption. This is true of nearly
12293 -- all (all?) targets.
12295 when Pragma_Overflow_Mode => Overflow_Mode : declare
12296 function Get_Overflow_Mode
12298 Arg : Node_Id) return Overflow_Mode_Type;
12299 -- Function to process one pragma argument, Arg. If an identifier
12300 -- is present, it must be Name. Mode type is returned if a valid
12301 -- argument exists, otherwise an error is signalled.
12303 -----------------------
12304 -- Get_Overflow_Mode --
12305 -----------------------
12307 function Get_Overflow_Mode
12309 Arg : Node_Id) return Overflow_Mode_Type
12311 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
12314 Check_Optional_Identifier (Arg, Name);
12315 Check_Arg_Is_Identifier (Argx);
12317 if Chars (Argx) = Name_Strict then
12320 elsif Chars (Argx) = Name_Minimized then
12323 elsif Chars (Argx) = Name_Eliminated then
12324 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
12326 ("Eliminated not implemented on this target", Argx);
12332 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
12334 end Get_Overflow_Mode;
12336 -- Start of processing for Overflow_Mode
12340 Check_At_Least_N_Arguments (1);
12341 Check_At_Most_N_Arguments (2);
12343 -- Process first argument
12345 Scope_Suppress.Overflow_Mode_General :=
12346 Get_Overflow_Mode (Name_General, Arg1);
12348 -- Case of only one argument
12350 if Arg_Count = 1 then
12351 Scope_Suppress.Overflow_Mode_Assertions :=
12352 Scope_Suppress.Overflow_Mode_General;
12354 -- Case of two arguments present
12357 Scope_Suppress.Overflow_Mode_Assertions :=
12358 Get_Overflow_Mode (Name_Assertions, Arg2);
12366 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
12368 when Pragma_Ordered => Ordered : declare
12369 Assoc : constant Node_Id := Arg1;
12375 Check_No_Identifiers;
12376 Check_Arg_Count (1);
12377 Check_Arg_Is_Local_Name (Arg1);
12379 Type_Id := Get_Pragma_Arg (Assoc);
12380 Find_Type (Type_Id);
12381 Typ := Entity (Type_Id);
12383 if Typ = Any_Type then
12386 Typ := Underlying_Type (Typ);
12389 if not Is_Enumeration_Type (Typ) then
12390 Error_Pragma ("pragma% must specify enumeration type");
12393 Check_First_Subtype (Arg1);
12394 Set_Has_Pragma_Ordered (Base_Type (Typ));
12401 -- pragma Pack (first_subtype_LOCAL_NAME);
12403 when Pragma_Pack => Pack : declare
12404 Assoc : constant Node_Id := Arg1;
12408 Ignore : Boolean := False;
12411 Check_No_Identifiers;
12412 Check_Arg_Count (1);
12413 Check_Arg_Is_Local_Name (Arg1);
12415 Type_Id := Get_Pragma_Arg (Assoc);
12416 Find_Type (Type_Id);
12417 Typ := Entity (Type_Id);
12420 or else Rep_Item_Too_Early (Typ, N)
12424 Typ := Underlying_Type (Typ);
12427 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
12428 Error_Pragma ("pragma% must specify array or record type");
12431 Check_First_Subtype (Arg1);
12432 Check_Duplicate_Pragma (Typ);
12436 if Is_Array_Type (Typ) then
12437 Ctyp := Component_Type (Typ);
12439 -- Ignore pack that does nothing
12441 if Known_Static_Esize (Ctyp)
12442 and then Known_Static_RM_Size (Ctyp)
12443 and then Esize (Ctyp) = RM_Size (Ctyp)
12444 and then Addressable (Esize (Ctyp))
12449 -- Process OK pragma Pack. Note that if there is a separate
12450 -- component clause present, the Pack will be cancelled. This
12451 -- processing is in Freeze.
12453 if not Rep_Item_Too_Late (Typ, N) then
12455 -- In the context of static code analysis, we do not need
12456 -- complex front-end expansions related to pragma Pack,
12457 -- so disable handling of pragma Pack in these cases.
12459 if CodePeer_Mode or Alfa_Mode then
12462 -- Don't attempt any packing for VM targets. We possibly
12463 -- could deal with some cases of array bit-packing, but we
12464 -- don't bother, since this is not a typical kind of
12465 -- representation in the VM context anyway (and would not
12466 -- for example work nicely with the debugger).
12468 elsif VM_Target /= No_VM then
12469 if not GNAT_Mode then
12471 ("?pragma% ignored in this configuration");
12474 -- Normal case where we do the pack action
12478 Set_Is_Packed (Base_Type (Typ));
12479 Set_Has_Non_Standard_Rep (Base_Type (Typ));
12482 Set_Has_Pragma_Pack (Base_Type (Typ));
12486 -- For record types, the pack is always effective
12488 else pragma Assert (Is_Record_Type (Typ));
12489 if not Rep_Item_Too_Late (Typ, N) then
12491 -- Ignore pack request with warning in VM mode (skip warning
12492 -- if we are compiling GNAT run time library).
12494 if VM_Target /= No_VM then
12495 if not GNAT_Mode then
12497 ("?pragma% ignored in this configuration");
12500 -- Normal case of pack request active
12503 Set_Is_Packed (Base_Type (Typ));
12504 Set_Has_Pragma_Pack (Base_Type (Typ));
12505 Set_Has_Non_Standard_Rep (Base_Type (Typ));
12517 -- There is nothing to do here, since we did all the processing for
12518 -- this pragma in Par.Prag (so that it works properly even in syntax
12521 when Pragma_Page =>
12524 ----------------------------------
12525 -- Partition_Elaboration_Policy --
12526 ----------------------------------
12528 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
12530 when Pragma_Partition_Elaboration_Policy => declare
12531 subtype PEP_Range is Name_Id
12532 range First_Partition_Elaboration_Policy_Name
12533 .. Last_Partition_Elaboration_Policy_Name;
12534 PEP_Val : PEP_Range;
12539 Check_Arg_Count (1);
12540 Check_No_Identifiers;
12541 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
12542 Check_Valid_Configuration_Pragma;
12543 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
12546 when Name_Concurrent =>
12548 when Name_Sequential =>
12552 if Partition_Elaboration_Policy /= ' '
12553 and then Partition_Elaboration_Policy /= PEP
12555 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
12557 ("partition elaboration policy incompatible with policy#");
12559 -- Set new policy, but always preserve System_Location since we
12560 -- like the error message with the run time name.
12563 Partition_Elaboration_Policy := PEP;
12565 if Partition_Elaboration_Policy_Sloc /= System_Location then
12566 Partition_Elaboration_Policy_Sloc := Loc;
12575 -- pragma Passive [(PASSIVE_FORM)];
12577 -- PASSIVE_FORM ::= Semaphore | No
12579 when Pragma_Passive =>
12582 if Nkind (Parent (N)) /= N_Task_Definition then
12583 Error_Pragma ("pragma% must be within task definition");
12586 if Arg_Count /= 0 then
12587 Check_Arg_Count (1);
12588 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
12591 ----------------------------------
12592 -- Preelaborable_Initialization --
12593 ----------------------------------
12595 -- pragma Preelaborable_Initialization (DIRECT_NAME);
12597 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
12602 Check_Arg_Count (1);
12603 Check_No_Identifiers;
12604 Check_Arg_Is_Identifier (Arg1);
12605 Check_Arg_Is_Local_Name (Arg1);
12606 Check_First_Subtype (Arg1);
12607 Ent := Entity (Get_Pragma_Arg (Arg1));
12609 if not (Is_Private_Type (Ent)
12611 Is_Protected_Type (Ent)
12613 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
12616 ("pragma % can only be applied to private, formal derived or "
12617 & "protected type",
12621 -- Give an error if the pragma is applied to a protected type that
12622 -- does not qualify (due to having entries, or due to components
12623 -- that do not qualify).
12625 if Is_Protected_Type (Ent)
12626 and then not Has_Preelaborable_Initialization (Ent)
12629 ("protected type & does not have preelaborable " &
12630 "initialization", Ent);
12632 -- Otherwise mark the type as definitely having preelaborable
12636 Set_Known_To_Have_Preelab_Init (Ent);
12639 if Has_Pragma_Preelab_Init (Ent)
12640 and then Warn_On_Redundant_Constructs
12642 Error_Pragma ("?duplicate pragma%!");
12644 Set_Has_Pragma_Preelab_Init (Ent);
12648 --------------------
12649 -- Persistent_BSS --
12650 --------------------
12652 -- pragma Persistent_BSS [(object_NAME)];
12654 when Pragma_Persistent_BSS => Persistent_BSS : declare
12661 Check_At_Most_N_Arguments (1);
12663 -- Case of application to specific object (one argument)
12665 if Arg_Count = 1 then
12666 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12668 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
12670 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
12673 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
12676 Ent := Entity (Get_Pragma_Arg (Arg1));
12677 Decl := Parent (Ent);
12679 -- Check for duplication before inserting in list of
12680 -- representation items.
12682 Check_Duplicate_Pragma (Ent);
12684 if Rep_Item_Too_Late (Ent, N) then
12688 if Present (Expression (Decl)) then
12690 ("object for pragma% cannot have initialization", Arg1);
12693 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
12695 ("object type for pragma% is not potentially persistent",
12700 Make_Linker_Section_Pragma
12701 (Ent, Sloc (N), ".persistent.bss");
12702 Insert_After (N, Prag);
12705 -- Case of use as configuration pragma with no arguments
12708 Check_Valid_Configuration_Pragma;
12709 Persistent_BSS_Mode := True;
12711 end Persistent_BSS;
12717 -- pragma Polling (ON | OFF);
12719 when Pragma_Polling =>
12721 Check_Arg_Count (1);
12722 Check_No_Identifiers;
12723 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12724 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
12726 -------------------
12727 -- Postcondition --
12728 -------------------
12730 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
12731 -- [,[Message =>] String_EXPRESSION]);
12733 when Pragma_Postcondition => Postcondition : declare
12735 pragma Warnings (Off, In_Body);
12739 Check_At_Least_N_Arguments (1);
12740 Check_At_Most_N_Arguments (2);
12741 Check_Optional_Identifier (Arg1, Name_Check);
12743 -- All we need to do here is call the common check procedure,
12744 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
12746 Check_Precondition_Postcondition (In_Body);
12753 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
12754 -- [,[Message =>] String_EXPRESSION]);
12756 when Pragma_Precondition => Precondition : declare
12761 Check_At_Least_N_Arguments (1);
12762 Check_At_Most_N_Arguments (2);
12763 Check_Optional_Identifier (Arg1, Name_Check);
12764 Check_Precondition_Postcondition (In_Body);
12766 -- If in spec, nothing more to do. If in body, then we convert the
12767 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
12768 -- this whether or not precondition checks are enabled. That works
12769 -- fine since pragma Check will do this check, and will also
12770 -- analyze the condition itself in the proper context.
12775 Chars => Name_Check,
12776 Pragma_Argument_Associations => New_List (
12777 Make_Pragma_Argument_Association (Loc,
12778 Expression => Make_Identifier (Loc, Name_Precondition)),
12780 Make_Pragma_Argument_Association (Sloc (Arg1),
12781 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
12783 if Arg_Count = 2 then
12784 Append_To (Pragma_Argument_Associations (N),
12785 Make_Pragma_Argument_Association (Sloc (Arg2),
12786 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
12797 -- pragma Predicate
12798 -- ([Entity =>] type_LOCAL_NAME,
12799 -- [Check =>] EXPRESSION);
12801 when Pragma_Predicate => Predicate : declare
12806 pragma Unreferenced (Discard);
12810 Check_Arg_Count (2);
12811 Check_Optional_Identifier (Arg1, Name_Entity);
12812 Check_Optional_Identifier (Arg2, Name_Check);
12814 Check_Arg_Is_Local_Name (Arg1);
12816 Type_Id := Get_Pragma_Arg (Arg1);
12817 Find_Type (Type_Id);
12818 Typ := Entity (Type_Id);
12820 if Typ = Any_Type then
12824 -- The remaining processing is simply to link the pragma on to
12825 -- the rep item chain, for processing when the type is frozen.
12826 -- This is accomplished by a call to Rep_Item_Too_Late. We also
12827 -- mark the type as having predicates.
12829 Set_Has_Predicates (Typ);
12830 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12837 -- pragma Preelaborate [(library_unit_NAME)];
12839 -- Set the flag Is_Preelaborated of program unit name entity
12841 when Pragma_Preelaborate => Preelaborate : declare
12842 Pa : constant Node_Id := Parent (N);
12843 Pk : constant Node_Kind := Nkind (Pa);
12847 Check_Ada_83_Warning;
12848 Check_Valid_Library_Unit_Pragma;
12850 if Nkind (N) = N_Null_Statement then
12854 Ent := Find_Lib_Unit_Name;
12855 Check_Duplicate_Pragma (Ent);
12857 -- This filters out pragmas inside generic parent then
12858 -- show up inside instantiation
12861 and then not (Pk = N_Package_Specification
12862 and then Present (Generic_Parent (Pa)))
12864 if not Debug_Flag_U then
12865 Set_Is_Preelaborated (Ent);
12866 Set_Suppress_Elaboration_Warnings (Ent);
12871 ---------------------
12872 -- Preelaborate_05 --
12873 ---------------------
12875 -- pragma Preelaborate_05 [(library_unit_NAME)];
12877 -- This pragma is useable only in GNAT_Mode, where it is used like
12878 -- pragma Preelaborate but it is only effective in Ada 2005 mode
12879 -- (otherwise it is ignored). This is used to implement AI-362 which
12880 -- recategorizes some run-time packages in Ada 2005 mode.
12882 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
12887 Check_Valid_Library_Unit_Pragma;
12889 if not GNAT_Mode then
12890 Error_Pragma ("pragma% only available in GNAT mode");
12893 if Nkind (N) = N_Null_Statement then
12897 -- This is one of the few cases where we need to test the value of
12898 -- Ada_Version_Explicit rather than Ada_Version (which is always
12899 -- set to Ada_2012 in a predefined unit), we need to know the
12900 -- explicit version set to know if this pragma is active.
12902 if Ada_Version_Explicit >= Ada_2005 then
12903 Ent := Find_Lib_Unit_Name;
12904 Set_Is_Preelaborated (Ent);
12905 Set_Suppress_Elaboration_Warnings (Ent);
12907 end Preelaborate_05;
12913 -- pragma Priority (EXPRESSION);
12915 when Pragma_Priority => Priority : declare
12916 P : constant Node_Id := Parent (N);
12921 Check_No_Identifiers;
12922 Check_Arg_Count (1);
12926 if Nkind (P) = N_Subprogram_Body then
12927 Check_In_Main_Program;
12929 Ent := Defining_Unit_Name (Specification (P));
12931 if Nkind (Ent) = N_Defining_Program_Unit_Name then
12932 Ent := Defining_Identifier (Ent);
12935 Arg := Get_Pragma_Arg (Arg1);
12936 Analyze_And_Resolve (Arg, Standard_Integer);
12940 if not Is_Static_Expression (Arg) then
12941 Flag_Non_Static_Expr
12942 ("main subprogram priority is not static!", Arg);
12945 -- If constraint error, then we already signalled an error
12947 elsif Raises_Constraint_Error (Arg) then
12950 -- Otherwise check in range
12954 Val : constant Uint := Expr_Value (Arg);
12958 or else Val > Expr_Value (Expression
12959 (Parent (RTE (RE_Max_Priority))))
12962 ("main subprogram priority is out of range", Arg1);
12968 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12970 -- Load an arbitrary entity from System.Tasking to make sure
12971 -- this package is implicitly with'ed, since we need to have
12972 -- the tasking run-time active for the pragma Priority to have
12976 Discard : Entity_Id;
12977 pragma Warnings (Off, Discard);
12979 Discard := RTE (RE_Task_List);
12982 -- Task or Protected, must be of type Integer
12984 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12985 Arg := Get_Pragma_Arg (Arg1);
12986 Ent := Defining_Identifier (Parent (P));
12988 -- The expression must be analyzed in the special manner
12989 -- described in "Handling of Default and Per-Object
12990 -- Expressions" in sem.ads.
12992 Preanalyze_Spec_Expression (Arg, Standard_Integer);
12994 if not Is_Static_Expression (Arg) then
12995 Check_Restriction (Static_Priorities, Arg);
12998 -- Anything else is incorrect
13004 -- Check duplicate pragma before we chain the pragma in the Rep
13005 -- Item chain of Ent.
13007 Check_Duplicate_Pragma (Ent);
13008 Record_Rep_Item (Ent, N);
13011 -----------------------------------
13012 -- Priority_Specific_Dispatching --
13013 -----------------------------------
13015 -- pragma Priority_Specific_Dispatching (
13016 -- policy_IDENTIFIER,
13017 -- first_priority_EXPRESSION,
13018 -- last_priority_EXPRESSION);
13020 when Pragma_Priority_Specific_Dispatching =>
13021 Priority_Specific_Dispatching : declare
13022 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
13023 -- This is the entity System.Any_Priority;
13026 Lower_Bound : Node_Id;
13027 Upper_Bound : Node_Id;
13033 Check_Arg_Count (3);
13034 Check_No_Identifiers;
13035 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13036 Check_Valid_Configuration_Pragma;
13037 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13038 DP := Fold_Upper (Name_Buffer (1));
13040 Lower_Bound := Get_Pragma_Arg (Arg2);
13041 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
13042 Lower_Val := Expr_Value (Lower_Bound);
13044 Upper_Bound := Get_Pragma_Arg (Arg3);
13045 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
13046 Upper_Val := Expr_Value (Upper_Bound);
13048 -- It is not allowed to use Task_Dispatching_Policy and
13049 -- Priority_Specific_Dispatching in the same partition.
13051 if Task_Dispatching_Policy /= ' ' then
13052 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13054 ("pragma% incompatible with Task_Dispatching_Policy#");
13056 -- Check lower bound in range
13058 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
13060 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
13063 ("first_priority is out of range", Arg2);
13065 -- Check upper bound in range
13067 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
13069 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
13072 ("last_priority is out of range", Arg3);
13074 -- Check that the priority range is valid
13076 elsif Lower_Val > Upper_Val then
13078 ("last_priority_expression must be greater than" &
13079 " or equal to first_priority_expression");
13081 -- Store the new policy, but always preserve System_Location since
13082 -- we like the error message with the run-time name.
13085 -- Check overlapping in the priority ranges specified in other
13086 -- Priority_Specific_Dispatching pragmas within the same
13087 -- partition. We can only check those we know about!
13090 Specific_Dispatching.First .. Specific_Dispatching.Last
13092 if Specific_Dispatching.Table (J).First_Priority in
13093 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
13094 or else Specific_Dispatching.Table (J).Last_Priority in
13095 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
13098 Specific_Dispatching.Table (J).Pragma_Loc;
13100 ("priority range overlaps with "
13101 & "Priority_Specific_Dispatching#");
13105 -- The use of Priority_Specific_Dispatching is incompatible
13106 -- with Task_Dispatching_Policy.
13108 if Task_Dispatching_Policy /= ' ' then
13109 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13111 ("Priority_Specific_Dispatching incompatible "
13112 & "with Task_Dispatching_Policy#");
13115 -- The use of Priority_Specific_Dispatching forces ceiling
13118 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
13119 Error_Msg_Sloc := Locking_Policy_Sloc;
13121 ("Priority_Specific_Dispatching incompatible "
13122 & "with Locking_Policy#");
13124 -- Set the Ceiling_Locking policy, but preserve System_Location
13125 -- since we like the error message with the run time name.
13128 Locking_Policy := 'C';
13130 if Locking_Policy_Sloc /= System_Location then
13131 Locking_Policy_Sloc := Loc;
13135 -- Add entry in the table
13137 Specific_Dispatching.Append
13138 ((Dispatching_Policy => DP,
13139 First_Priority => UI_To_Int (Lower_Val),
13140 Last_Priority => UI_To_Int (Upper_Val),
13141 Pragma_Loc => Loc));
13143 end Priority_Specific_Dispatching;
13149 -- pragma Profile (profile_IDENTIFIER);
13151 -- profile_IDENTIFIER => Restricted | Ravenscar
13153 when Pragma_Profile =>
13155 Check_Arg_Count (1);
13156 Check_Valid_Configuration_Pragma;
13157 Check_No_Identifiers;
13160 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13163 if Chars (Argx) = Name_Ravenscar then
13164 Set_Ravenscar_Profile (N);
13166 elsif Chars (Argx) = Name_Restricted then
13167 Set_Profile_Restrictions
13169 N, Warn => Treat_Restrictions_As_Warnings);
13171 elsif Chars (Argx) = Name_No_Implementation_Extensions then
13172 Set_Profile_Restrictions
13173 (No_Implementation_Extensions,
13174 N, Warn => Treat_Restrictions_As_Warnings);
13177 Error_Pragma_Arg ("& is not a valid profile", Argx);
13181 ----------------------
13182 -- Profile_Warnings --
13183 ----------------------
13185 -- pragma Profile_Warnings (profile_IDENTIFIER);
13187 -- profile_IDENTIFIER => Restricted | Ravenscar
13189 when Pragma_Profile_Warnings =>
13191 Check_Arg_Count (1);
13192 Check_Valid_Configuration_Pragma;
13193 Check_No_Identifiers;
13196 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13199 if Chars (Argx) = Name_Ravenscar then
13200 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
13202 elsif Chars (Argx) = Name_Restricted then
13203 Set_Profile_Restrictions (Restricted, N, Warn => True);
13205 elsif Chars (Argx) = Name_No_Implementation_Extensions then
13206 Set_Profile_Restrictions
13207 (No_Implementation_Extensions, N, Warn => True);
13210 Error_Pragma_Arg ("& is not a valid profile", Argx);
13214 --------------------------
13215 -- Propagate_Exceptions --
13216 --------------------------
13218 -- pragma Propagate_Exceptions;
13220 -- Note: this pragma is obsolete and has no effect
13222 when Pragma_Propagate_Exceptions =>
13224 Check_Arg_Count (0);
13226 if In_Extended_Main_Source_Unit (N) then
13227 Propagate_Exceptions := True;
13234 -- pragma Psect_Object (
13235 -- [Internal =>] LOCAL_NAME,
13236 -- [, [External =>] EXTERNAL_SYMBOL]
13237 -- [, [Size =>] EXTERNAL_SYMBOL]);
13239 when Pragma_Psect_Object | Pragma_Common_Object =>
13240 Psect_Object : declare
13241 Args : Args_List (1 .. 3);
13242 Names : constant Name_List (1 .. 3) := (
13247 Internal : Node_Id renames Args (1);
13248 External : Node_Id renames Args (2);
13249 Size : Node_Id renames Args (3);
13251 Def_Id : Entity_Id;
13253 procedure Check_Too_Long (Arg : Node_Id);
13254 -- Posts message if the argument is an identifier with more
13255 -- than 31 characters, or a string literal with more than
13256 -- 31 characters, and we are operating under VMS
13258 --------------------
13259 -- Check_Too_Long --
13260 --------------------
13262 procedure Check_Too_Long (Arg : Node_Id) is
13263 X : constant Node_Id := Original_Node (Arg);
13266 if not Nkind_In (X, N_String_Literal, N_Identifier) then
13268 ("inappropriate argument for pragma %", Arg);
13271 if OpenVMS_On_Target then
13272 if (Nkind (X) = N_String_Literal
13273 and then String_Length (Strval (X)) > 31)
13275 (Nkind (X) = N_Identifier
13276 and then Length_Of_Name (Chars (X)) > 31)
13279 ("argument for pragma % is longer than 31 characters",
13283 end Check_Too_Long;
13285 -- Start of processing for Common_Object/Psect_Object
13289 Gather_Associations (Names, Args);
13290 Process_Extended_Import_Export_Internal_Arg (Internal);
13292 Def_Id := Entity (Internal);
13294 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
13296 ("pragma% must designate an object", Internal);
13299 Check_Too_Long (Internal);
13301 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
13303 ("cannot use pragma% for imported/exported object",
13307 if Is_Concurrent_Type (Etype (Internal)) then
13309 ("cannot specify pragma % for task/protected object",
13313 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
13315 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
13317 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
13320 if Ekind (Def_Id) = E_Constant then
13322 ("cannot specify pragma % for a constant", Internal);
13325 if Is_Record_Type (Etype (Internal)) then
13331 Ent := First_Entity (Etype (Internal));
13332 while Present (Ent) loop
13333 Decl := Declaration_Node (Ent);
13335 if Ekind (Ent) = E_Component
13336 and then Nkind (Decl) = N_Component_Declaration
13337 and then Present (Expression (Decl))
13338 and then Warn_On_Export_Import
13341 ("?object for pragma % has defaults", Internal);
13351 if Present (Size) then
13352 Check_Too_Long (Size);
13355 if Present (External) then
13356 Check_Arg_Is_External_Name (External);
13357 Check_Too_Long (External);
13360 -- If all error tests pass, link pragma on to the rep item chain
13362 Record_Rep_Item (Def_Id, N);
13369 -- pragma Pure [(library_unit_NAME)];
13371 when Pragma_Pure => Pure : declare
13375 Check_Ada_83_Warning;
13376 Check_Valid_Library_Unit_Pragma;
13378 if Nkind (N) = N_Null_Statement then
13382 Ent := Find_Lib_Unit_Name;
13384 Set_Has_Pragma_Pure (Ent);
13385 Set_Suppress_Elaboration_Warnings (Ent);
13392 -- pragma Pure_05 [(library_unit_NAME)];
13394 -- This pragma is useable only in GNAT_Mode, where it is used like
13395 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
13396 -- it is ignored). It may be used after a pragma Preelaborate, in
13397 -- which case it overrides the effect of the pragma Preelaborate.
13398 -- This is used to implement AI-362 which recategorizes some run-time
13399 -- packages in Ada 2005 mode.
13401 when Pragma_Pure_05 => Pure_05 : declare
13406 Check_Valid_Library_Unit_Pragma;
13408 if not GNAT_Mode then
13409 Error_Pragma ("pragma% only available in GNAT mode");
13412 if Nkind (N) = N_Null_Statement then
13416 -- This is one of the few cases where we need to test the value of
13417 -- Ada_Version_Explicit rather than Ada_Version (which is always
13418 -- set to Ada_2012 in a predefined unit), we need to know the
13419 -- explicit version set to know if this pragma is active.
13421 if Ada_Version_Explicit >= Ada_2005 then
13422 Ent := Find_Lib_Unit_Name;
13423 Set_Is_Preelaborated (Ent, False);
13425 Set_Suppress_Elaboration_Warnings (Ent);
13433 -- pragma Pure_12 [(library_unit_NAME)];
13435 -- This pragma is useable only in GNAT_Mode, where it is used like
13436 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
13437 -- it is ignored). It may be used after a pragma Preelaborate, in
13438 -- which case it overrides the effect of the pragma Preelaborate.
13439 -- This is used to implement AI05-0212 which recategorizes some
13440 -- run-time packages in Ada 2012 mode.
13442 when Pragma_Pure_12 => Pure_12 : declare
13447 Check_Valid_Library_Unit_Pragma;
13449 if not GNAT_Mode then
13450 Error_Pragma ("pragma% only available in GNAT mode");
13453 if Nkind (N) = N_Null_Statement then
13457 -- This is one of the few cases where we need to test the value of
13458 -- Ada_Version_Explicit rather than Ada_Version (which is always
13459 -- set to Ada_2012 in a predefined unit), we need to know the
13460 -- explicit version set to know if this pragma is active.
13462 if Ada_Version_Explicit >= Ada_2012 then
13463 Ent := Find_Lib_Unit_Name;
13464 Set_Is_Preelaborated (Ent, False);
13466 Set_Suppress_Elaboration_Warnings (Ent);
13470 -------------------
13471 -- Pure_Function --
13472 -------------------
13474 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
13476 when Pragma_Pure_Function => Pure_Function : declare
13479 Def_Id : Entity_Id;
13480 Effective : Boolean := False;
13484 Check_Arg_Count (1);
13485 Check_Optional_Identifier (Arg1, Name_Entity);
13486 Check_Arg_Is_Local_Name (Arg1);
13487 E_Id := Get_Pragma_Arg (Arg1);
13489 if Error_Posted (E_Id) then
13493 -- Loop through homonyms (overloadings) of referenced entity
13495 E := Entity (E_Id);
13497 if Present (E) then
13499 Def_Id := Get_Base_Subprogram (E);
13501 if not Ekind_In (Def_Id, E_Function,
13502 E_Generic_Function,
13506 ("pragma% requires a function name", Arg1);
13509 Set_Is_Pure (Def_Id);
13511 if not Has_Pragma_Pure_Function (Def_Id) then
13512 Set_Has_Pragma_Pure_Function (Def_Id);
13516 exit when From_Aspect_Specification (N);
13518 exit when No (E) or else Scope (E) /= Current_Scope;
13522 and then Warn_On_Redundant_Constructs
13525 ("pragma Pure_Function on& is redundant?",
13531 --------------------
13532 -- Queuing_Policy --
13533 --------------------
13535 -- pragma Queuing_Policy (policy_IDENTIFIER);
13537 when Pragma_Queuing_Policy => declare
13541 Check_Ada_83_Warning;
13542 Check_Arg_Count (1);
13543 Check_No_Identifiers;
13544 Check_Arg_Is_Queuing_Policy (Arg1);
13545 Check_Valid_Configuration_Pragma;
13546 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13547 QP := Fold_Upper (Name_Buffer (1));
13549 if Queuing_Policy /= ' '
13550 and then Queuing_Policy /= QP
13552 Error_Msg_Sloc := Queuing_Policy_Sloc;
13553 Error_Pragma ("queuing policy incompatible with policy#");
13555 -- Set new policy, but always preserve System_Location since we
13556 -- like the error message with the run time name.
13559 Queuing_Policy := QP;
13561 if Queuing_Policy_Sloc /= System_Location then
13562 Queuing_Policy_Sloc := Loc;
13567 -----------------------
13568 -- Relative_Deadline --
13569 -----------------------
13571 -- pragma Relative_Deadline (time_span_EXPRESSION);
13573 when Pragma_Relative_Deadline => Relative_Deadline : declare
13574 P : constant Node_Id := Parent (N);
13579 Check_No_Identifiers;
13580 Check_Arg_Count (1);
13582 Arg := Get_Pragma_Arg (Arg1);
13584 -- The expression must be analyzed in the special manner described
13585 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
13587 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
13591 if Nkind (P) = N_Subprogram_Body then
13592 Check_In_Main_Program;
13594 -- Only Task and subprogram cases allowed
13596 elsif Nkind (P) /= N_Task_Definition then
13600 -- Check duplicate pragma before we set the corresponding flag
13602 if Has_Relative_Deadline_Pragma (P) then
13603 Error_Pragma ("duplicate pragma% not allowed");
13606 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
13607 -- Relative_Deadline pragma node cannot be inserted in the Rep
13608 -- Item chain of Ent since it is rewritten by the expander as a
13609 -- procedure call statement that will break the chain.
13611 Set_Has_Relative_Deadline_Pragma (P, True);
13612 end Relative_Deadline;
13614 ------------------------
13615 -- Remote_Access_Type --
13616 ------------------------
13618 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
13620 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
13625 Check_Arg_Count (1);
13626 Check_Optional_Identifier (Arg1, Name_Entity);
13627 Check_Arg_Is_Local_Name (Arg1);
13629 E := Entity (Get_Pragma_Arg (Arg1));
13631 if Nkind (Parent (E)) = N_Formal_Type_Declaration
13632 and then Ekind (E) = E_General_Access_Type
13633 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
13634 and then Scope (Root_Type (Directly_Designated_Type (E)))
13636 and then Is_Valid_Remote_Object_Type
13637 (Root_Type (Directly_Designated_Type (E)))
13639 Set_Is_Remote_Types (E);
13643 ("pragma% applies only to formal access to classwide types",
13646 end Remote_Access_Type;
13648 ---------------------------
13649 -- Remote_Call_Interface --
13650 ---------------------------
13652 -- pragma Remote_Call_Interface [(library_unit_NAME)];
13654 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
13655 Cunit_Node : Node_Id;
13656 Cunit_Ent : Entity_Id;
13660 Check_Ada_83_Warning;
13661 Check_Valid_Library_Unit_Pragma;
13663 if Nkind (N) = N_Null_Statement then
13667 Cunit_Node := Cunit (Current_Sem_Unit);
13668 K := Nkind (Unit (Cunit_Node));
13669 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13671 if K = N_Package_Declaration
13672 or else K = N_Generic_Package_Declaration
13673 or else K = N_Subprogram_Declaration
13674 or else K = N_Generic_Subprogram_Declaration
13675 or else (K = N_Subprogram_Body
13676 and then Acts_As_Spec (Unit (Cunit_Node)))
13681 "pragma% must apply to package or subprogram declaration");
13684 Set_Is_Remote_Call_Interface (Cunit_Ent);
13685 end Remote_Call_Interface;
13691 -- pragma Remote_Types [(library_unit_NAME)];
13693 when Pragma_Remote_Types => Remote_Types : declare
13694 Cunit_Node : Node_Id;
13695 Cunit_Ent : Entity_Id;
13698 Check_Ada_83_Warning;
13699 Check_Valid_Library_Unit_Pragma;
13701 if Nkind (N) = N_Null_Statement then
13705 Cunit_Node := Cunit (Current_Sem_Unit);
13706 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13708 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13709 N_Generic_Package_Declaration)
13712 ("pragma% can only apply to a package declaration");
13715 Set_Is_Remote_Types (Cunit_Ent);
13722 -- pragma Ravenscar;
13724 when Pragma_Ravenscar =>
13726 Check_Arg_Count (0);
13727 Check_Valid_Configuration_Pragma;
13728 Set_Ravenscar_Profile (N);
13730 if Warn_On_Obsolescent_Feature then
13731 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
13732 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
13735 -------------------------
13736 -- Restricted_Run_Time --
13737 -------------------------
13739 -- pragma Restricted_Run_Time;
13741 when Pragma_Restricted_Run_Time =>
13743 Check_Arg_Count (0);
13744 Check_Valid_Configuration_Pragma;
13745 Set_Profile_Restrictions
13746 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
13748 if Warn_On_Obsolescent_Feature then
13750 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
13751 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
13758 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
13761 -- restriction_IDENTIFIER
13762 -- | restriction_parameter_IDENTIFIER => EXPRESSION
13764 when Pragma_Restrictions =>
13765 Process_Restrictions_Or_Restriction_Warnings
13766 (Warn => Treat_Restrictions_As_Warnings);
13768 --------------------------
13769 -- Restriction_Warnings --
13770 --------------------------
13772 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
13775 -- restriction_IDENTIFIER
13776 -- | restriction_parameter_IDENTIFIER => EXPRESSION
13778 when Pragma_Restriction_Warnings =>
13780 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
13786 -- pragma Reviewable;
13788 when Pragma_Reviewable =>
13789 Check_Ada_83_Warning;
13790 Check_Arg_Count (0);
13792 -- Call dummy debugging function rv. This is done to assist front
13793 -- end debugging. By placing a Reviewable pragma in the source
13794 -- program, a breakpoint on rv catches this place in the source,
13795 -- allowing convenient stepping to the point of interest.
13799 --------------------------
13800 -- Short_Circuit_And_Or --
13801 --------------------------
13803 when Pragma_Short_Circuit_And_Or =>
13805 Check_Arg_Count (0);
13806 Check_Valid_Configuration_Pragma;
13807 Short_Circuit_And_Or := True;
13809 -------------------
13810 -- Share_Generic --
13811 -------------------
13813 -- pragma Share_Generic (NAME {, NAME});
13815 when Pragma_Share_Generic =>
13817 Process_Generic_List;
13823 -- pragma Shared (LOCAL_NAME);
13825 when Pragma_Shared =>
13827 Process_Atomic_Shared_Volatile;
13829 --------------------
13830 -- Shared_Passive --
13831 --------------------
13833 -- pragma Shared_Passive [(library_unit_NAME)];
13835 -- Set the flag Is_Shared_Passive of program unit name entity
13837 when Pragma_Shared_Passive => Shared_Passive : declare
13838 Cunit_Node : Node_Id;
13839 Cunit_Ent : Entity_Id;
13842 Check_Ada_83_Warning;
13843 Check_Valid_Library_Unit_Pragma;
13845 if Nkind (N) = N_Null_Statement then
13849 Cunit_Node := Cunit (Current_Sem_Unit);
13850 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13852 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13853 N_Generic_Package_Declaration)
13856 ("pragma% can only apply to a package declaration");
13859 Set_Is_Shared_Passive (Cunit_Ent);
13860 end Shared_Passive;
13862 -----------------------
13863 -- Short_Descriptors --
13864 -----------------------
13866 -- pragma Short_Descriptors;
13868 when Pragma_Short_Descriptors =>
13870 Check_Arg_Count (0);
13871 Check_Valid_Configuration_Pragma;
13872 Short_Descriptors := True;
13874 ------------------------------
13875 -- Simple_Storage_Pool_Type --
13876 ------------------------------
13878 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
13880 when Pragma_Simple_Storage_Pool_Type =>
13881 Simple_Storage_Pool_Type : declare
13887 Check_Arg_Count (1);
13888 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13890 Type_Id := Get_Pragma_Arg (Arg1);
13891 Find_Type (Type_Id);
13892 Typ := Entity (Type_Id);
13894 if Typ = Any_Type then
13898 -- We require the pragma to apply to a type declared in a package
13899 -- declaration, but not (immediately) within a package body.
13901 if Ekind (Current_Scope) /= E_Package
13902 or else In_Package_Body (Current_Scope)
13905 ("pragma% can only apply to type declared immediately " &
13906 "within a package declaration");
13909 -- A simple storage pool type must be an immutably limited record
13910 -- or private type. If the pragma is given for a private type,
13911 -- the full type is similarly restricted (which is checked later
13912 -- in Freeze_Entity).
13914 if Is_Record_Type (Typ)
13915 and then not Is_Immutably_Limited_Type (Typ)
13918 ("pragma% can only apply to explicitly limited record type");
13920 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
13922 ("pragma% can only apply to a private type that is limited");
13924 elsif not Is_Record_Type (Typ)
13925 and then not Is_Private_Type (Typ)
13928 ("pragma% can only apply to limited record or private type");
13931 Record_Rep_Item (Typ, N);
13932 end Simple_Storage_Pool_Type;
13934 ----------------------
13935 -- Source_File_Name --
13936 ----------------------
13938 -- There are five forms for this pragma:
13940 -- pragma Source_File_Name (
13941 -- [UNIT_NAME =>] unit_NAME,
13942 -- BODY_FILE_NAME => STRING_LITERAL
13943 -- [, [INDEX =>] INTEGER_LITERAL]);
13945 -- pragma Source_File_Name (
13946 -- [UNIT_NAME =>] unit_NAME,
13947 -- SPEC_FILE_NAME => STRING_LITERAL
13948 -- [, [INDEX =>] INTEGER_LITERAL]);
13950 -- pragma Source_File_Name (
13951 -- BODY_FILE_NAME => STRING_LITERAL
13952 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13953 -- [, CASING => CASING_SPEC]);
13955 -- pragma Source_File_Name (
13956 -- SPEC_FILE_NAME => STRING_LITERAL
13957 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13958 -- [, CASING => CASING_SPEC]);
13960 -- pragma Source_File_Name (
13961 -- SUBUNIT_FILE_NAME => STRING_LITERAL
13962 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13963 -- [, CASING => CASING_SPEC]);
13965 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
13967 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
13968 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
13969 -- only be used when no project file is used, while SFNP can only be
13970 -- used when a project file is used.
13972 -- No processing here. Processing was completed during parsing, since
13973 -- we need to have file names set as early as possible. Units are
13974 -- loaded well before semantic processing starts.
13976 -- The only processing we defer to this point is the check for
13977 -- correct placement.
13979 when Pragma_Source_File_Name =>
13981 Check_Valid_Configuration_Pragma;
13983 ------------------------------
13984 -- Source_File_Name_Project --
13985 ------------------------------
13987 -- See Source_File_Name for syntax
13989 -- No processing here. Processing was completed during parsing, since
13990 -- we need to have file names set as early as possible. Units are
13991 -- loaded well before semantic processing starts.
13993 -- The only processing we defer to this point is the check for
13994 -- correct placement.
13996 when Pragma_Source_File_Name_Project =>
13998 Check_Valid_Configuration_Pragma;
14000 -- Check that a pragma Source_File_Name_Project is used only in a
14001 -- configuration pragmas file.
14003 -- Pragmas Source_File_Name_Project should only be generated by
14004 -- the Project Manager in configuration pragmas files.
14006 -- This is really an ugly test. It seems to depend on some
14007 -- accidental and undocumented property. At the very least it
14008 -- needs to be documented, but it would be better to have a
14009 -- clean way of testing if we are in a configuration file???
14011 if Present (Parent (N)) then
14013 ("pragma% can only appear in a configuration pragmas file");
14016 ----------------------
14017 -- Source_Reference --
14018 ----------------------
14020 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
14022 -- Nothing to do, all processing completed in Par.Prag, since we need
14023 -- the information for possible parser messages that are output.
14025 when Pragma_Source_Reference =>
14028 --------------------------------
14029 -- Static_Elaboration_Desired --
14030 --------------------------------
14032 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
14034 when Pragma_Static_Elaboration_Desired =>
14036 Check_At_Most_N_Arguments (1);
14038 if Is_Compilation_Unit (Current_Scope)
14039 and then Ekind (Current_Scope) = E_Package
14041 Set_Static_Elaboration_Desired (Current_Scope, True);
14043 Error_Pragma ("pragma% must apply to a library-level package");
14050 -- pragma Storage_Size (EXPRESSION);
14052 when Pragma_Storage_Size => Storage_Size : declare
14053 P : constant Node_Id := Parent (N);
14057 Check_No_Identifiers;
14058 Check_Arg_Count (1);
14060 -- The expression must be analyzed in the special manner described
14061 -- in "Handling of Default Expressions" in sem.ads.
14063 Arg := Get_Pragma_Arg (Arg1);
14064 Preanalyze_Spec_Expression (Arg, Any_Integer);
14066 if not Is_Static_Expression (Arg) then
14067 Check_Restriction (Static_Storage_Size, Arg);
14070 if Nkind (P) /= N_Task_Definition then
14075 if Has_Storage_Size_Pragma (P) then
14076 Error_Pragma ("duplicate pragma% not allowed");
14078 Set_Has_Storage_Size_Pragma (P, True);
14081 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
14089 -- pragma Storage_Unit (NUMERIC_LITERAL);
14091 -- Only permitted argument is System'Storage_Unit value
14093 when Pragma_Storage_Unit =>
14094 Check_No_Identifiers;
14095 Check_Arg_Count (1);
14096 Check_Arg_Is_Integer_Literal (Arg1);
14098 if Intval (Get_Pragma_Arg (Arg1)) /=
14099 UI_From_Int (Ttypes.System_Storage_Unit)
14101 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
14103 ("the only allowed argument for pragma% is ^", Arg1);
14106 --------------------
14107 -- Stream_Convert --
14108 --------------------
14110 -- pragma Stream_Convert (
14111 -- [Entity =>] type_LOCAL_NAME,
14112 -- [Read =>] function_NAME,
14113 -- [Write =>] function NAME);
14115 when Pragma_Stream_Convert => Stream_Convert : declare
14117 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
14118 -- Check that the given argument is the name of a local function
14119 -- of one argument that is not overloaded earlier in the current
14120 -- local scope. A check is also made that the argument is a
14121 -- function with one parameter.
14123 --------------------------------------
14124 -- Check_OK_Stream_Convert_Function --
14125 --------------------------------------
14127 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
14131 Check_Arg_Is_Local_Name (Arg);
14132 Ent := Entity (Get_Pragma_Arg (Arg));
14134 if Has_Homonym (Ent) then
14136 ("argument for pragma% may not be overloaded", Arg);
14139 if Ekind (Ent) /= E_Function
14140 or else No (First_Formal (Ent))
14141 or else Present (Next_Formal (First_Formal (Ent)))
14144 ("argument for pragma% must be" &
14145 " function of one argument", Arg);
14147 end Check_OK_Stream_Convert_Function;
14149 -- Start of processing for Stream_Convert
14153 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
14154 Check_Arg_Count (3);
14155 Check_Optional_Identifier (Arg1, Name_Entity);
14156 Check_Optional_Identifier (Arg2, Name_Read);
14157 Check_Optional_Identifier (Arg3, Name_Write);
14158 Check_Arg_Is_Local_Name (Arg1);
14159 Check_OK_Stream_Convert_Function (Arg2);
14160 Check_OK_Stream_Convert_Function (Arg3);
14163 Typ : constant Entity_Id :=
14164 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
14165 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
14166 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
14169 Check_First_Subtype (Arg1);
14171 -- Check for too early or too late. Note that we don't enforce
14172 -- the rule about primitive operations in this case, since, as
14173 -- is the case for explicit stream attributes themselves, these
14174 -- restrictions are not appropriate. Note that the chaining of
14175 -- the pragma by Rep_Item_Too_Late is actually the critical
14176 -- processing done for this pragma.
14178 if Rep_Item_Too_Early (Typ, N)
14180 Rep_Item_Too_Late (Typ, N, FOnly => True)
14185 -- Return if previous error
14187 if Etype (Typ) = Any_Type
14189 Etype (Read) = Any_Type
14191 Etype (Write) = Any_Type
14198 if Underlying_Type (Etype (Read)) /= Typ then
14200 ("incorrect return type for function&", Arg2);
14203 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
14205 ("incorrect parameter type for function&", Arg3);
14208 if Underlying_Type (Etype (First_Formal (Read))) /=
14209 Underlying_Type (Etype (Write))
14212 ("result type of & does not match Read parameter type",
14216 end Stream_Convert;
14222 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14224 -- This is processed by the parser since some of the style checks
14225 -- take place during source scanning and parsing. This means that
14226 -- we don't need to issue error messages here.
14228 when Pragma_Style_Checks => Style_Checks : declare
14229 A : constant Node_Id := Get_Pragma_Arg (Arg1);
14235 Check_No_Identifiers;
14237 -- Two argument form
14239 if Arg_Count = 2 then
14240 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14247 E_Id := Get_Pragma_Arg (Arg2);
14250 if not Is_Entity_Name (E_Id) then
14252 ("second argument of pragma% must be entity name",
14256 E := Entity (E_Id);
14262 Set_Suppress_Style_Checks (E,
14263 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
14264 exit when No (Homonym (E));
14270 -- One argument form
14273 Check_Arg_Count (1);
14275 if Nkind (A) = N_String_Literal then
14279 Slen : constant Natural := Natural (String_Length (S));
14280 Options : String (1 .. Slen);
14286 C := Get_String_Char (S, Int (J));
14287 exit when not In_Character_Range (C);
14288 Options (J) := Get_Character (C);
14290 -- If at end of string, set options. As per discussion
14291 -- above, no need to check for errors, since we issued
14292 -- them in the parser.
14295 Set_Style_Check_Options (Options);
14303 elsif Nkind (A) = N_Identifier then
14304 if Chars (A) = Name_All_Checks then
14306 Set_GNAT_Style_Check_Options;
14308 Set_Default_Style_Check_Options;
14311 elsif Chars (A) = Name_On then
14312 Style_Check := True;
14314 elsif Chars (A) = Name_Off then
14315 Style_Check := False;
14325 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
14327 when Pragma_Subtitle =>
14329 Check_Arg_Count (1);
14330 Check_Optional_Identifier (Arg1, Name_Subtitle);
14331 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
14338 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
14340 when Pragma_Suppress =>
14341 Process_Suppress_Unsuppress (True);
14347 -- pragma Suppress_All;
14349 -- The only check made here is that the pragma has no arguments.
14350 -- There are no placement rules, and the processing required (setting
14351 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
14352 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
14353 -- then creates and inserts a pragma Suppress (All_Checks).
14355 when Pragma_Suppress_All =>
14357 Check_Arg_Count (0);
14359 -------------------------
14360 -- Suppress_Debug_Info --
14361 -------------------------
14363 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
14365 when Pragma_Suppress_Debug_Info =>
14367 Check_Arg_Count (1);
14368 Check_Optional_Identifier (Arg1, Name_Entity);
14369 Check_Arg_Is_Local_Name (Arg1);
14370 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
14372 ----------------------------------
14373 -- Suppress_Exception_Locations --
14374 ----------------------------------
14376 -- pragma Suppress_Exception_Locations;
14378 when Pragma_Suppress_Exception_Locations =>
14380 Check_Arg_Count (0);
14381 Check_Valid_Configuration_Pragma;
14382 Exception_Locations_Suppressed := True;
14384 -----------------------------
14385 -- Suppress_Initialization --
14386 -----------------------------
14388 -- pragma Suppress_Initialization ([Entity =>] type_Name);
14390 when Pragma_Suppress_Initialization => Suppress_Init : declare
14396 Check_Arg_Count (1);
14397 Check_Optional_Identifier (Arg1, Name_Entity);
14398 Check_Arg_Is_Local_Name (Arg1);
14400 E_Id := Get_Pragma_Arg (Arg1);
14402 if Etype (E_Id) = Any_Type then
14406 E := Entity (E_Id);
14408 if not Is_Type (E) then
14409 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
14412 if Rep_Item_Too_Early (E, N)
14414 Rep_Item_Too_Late (E, N, FOnly => True)
14419 -- For incomplete/private type, set flag on full view
14421 if Is_Incomplete_Or_Private_Type (E) then
14422 if No (Full_View (Base_Type (E))) then
14424 ("argument of pragma% cannot be an incomplete type", Arg1);
14426 Set_Suppress_Initialization (Full_View (Base_Type (E)));
14429 -- For first subtype, set flag on base type
14431 elsif Is_First_Subtype (E) then
14432 Set_Suppress_Initialization (Base_Type (E));
14434 -- For other than first subtype, set flag on subtype itself
14437 Set_Suppress_Initialization (E);
14445 -- pragma System_Name (DIRECT_NAME);
14447 -- Syntax check: one argument, which must be the identifier GNAT or
14448 -- the identifier GCC, no other identifiers are acceptable.
14450 when Pragma_System_Name =>
14452 Check_No_Identifiers;
14453 Check_Arg_Count (1);
14454 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
14456 -----------------------------
14457 -- Task_Dispatching_Policy --
14458 -----------------------------
14460 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
14462 when Pragma_Task_Dispatching_Policy => declare
14466 Check_Ada_83_Warning;
14467 Check_Arg_Count (1);
14468 Check_No_Identifiers;
14469 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
14470 Check_Valid_Configuration_Pragma;
14471 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14472 DP := Fold_Upper (Name_Buffer (1));
14474 if Task_Dispatching_Policy /= ' '
14475 and then Task_Dispatching_Policy /= DP
14477 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
14479 ("task dispatching policy incompatible with policy#");
14481 -- Set new policy, but always preserve System_Location since we
14482 -- like the error message with the run time name.
14485 Task_Dispatching_Policy := DP;
14487 if Task_Dispatching_Policy_Sloc /= System_Location then
14488 Task_Dispatching_Policy_Sloc := Loc;
14497 -- pragma Task_Info (EXPRESSION);
14499 when Pragma_Task_Info => Task_Info : declare
14500 P : constant Node_Id := Parent (N);
14506 if Nkind (P) /= N_Task_Definition then
14507 Error_Pragma ("pragma% must appear in task definition");
14510 Check_No_Identifiers;
14511 Check_Arg_Count (1);
14513 Analyze_And_Resolve
14514 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
14516 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
14520 Ent := Defining_Identifier (Parent (P));
14522 -- Check duplicate pragma before we chain the pragma in the Rep
14523 -- Item chain of Ent.
14526 (Ent, Name_Task_Info, Check_Parents => False)
14528 Error_Pragma ("duplicate pragma% not allowed");
14531 Record_Rep_Item (Ent, N);
14538 -- pragma Task_Name (string_EXPRESSION);
14540 when Pragma_Task_Name => Task_Name : declare
14541 P : constant Node_Id := Parent (N);
14546 Check_No_Identifiers;
14547 Check_Arg_Count (1);
14549 Arg := Get_Pragma_Arg (Arg1);
14551 -- The expression is used in the call to Create_Task, and must be
14552 -- expanded there, not in the context of the current spec. It must
14553 -- however be analyzed to capture global references, in case it
14554 -- appears in a generic context.
14556 Preanalyze_And_Resolve (Arg, Standard_String);
14558 if Nkind (P) /= N_Task_Definition then
14562 Ent := Defining_Identifier (Parent (P));
14564 -- Check duplicate pragma before we chain the pragma in the Rep
14565 -- Item chain of Ent.
14568 (Ent, Name_Task_Name, Check_Parents => False)
14570 Error_Pragma ("duplicate pragma% not allowed");
14573 Record_Rep_Item (Ent, N);
14580 -- pragma Task_Storage (
14581 -- [Task_Type =>] LOCAL_NAME,
14582 -- [Top_Guard =>] static_integer_EXPRESSION);
14584 when Pragma_Task_Storage => Task_Storage : declare
14585 Args : Args_List (1 .. 2);
14586 Names : constant Name_List (1 .. 2) := (
14590 Task_Type : Node_Id renames Args (1);
14591 Top_Guard : Node_Id renames Args (2);
14597 Gather_Associations (Names, Args);
14599 if No (Task_Type) then
14601 ("missing task_type argument for pragma%");
14604 Check_Arg_Is_Local_Name (Task_Type);
14606 Ent := Entity (Task_Type);
14608 if not Is_Task_Type (Ent) then
14610 ("argument for pragma% must be task type", Task_Type);
14613 if No (Top_Guard) then
14615 ("pragma% takes two arguments", Task_Type);
14617 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
14620 Check_First_Subtype (Task_Type);
14622 if Rep_Item_Too_Late (Ent, N) then
14631 -- pragma Test_Case
14632 -- ([Name =>] Static_String_EXPRESSION
14633 -- ,[Mode =>] MODE_TYPE
14634 -- [, Requires => Boolean_EXPRESSION]
14635 -- [, Ensures => Boolean_EXPRESSION]);
14637 -- MODE_TYPE ::= Nominal | Robustness
14639 when Pragma_Test_Case =>
14640 Check_Contract_Or_Test_Case;
14642 --------------------------
14643 -- Thread_Local_Storage --
14644 --------------------------
14646 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
14648 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
14654 Check_Arg_Count (1);
14655 Check_Optional_Identifier (Arg1, Name_Entity);
14656 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14658 Id := Get_Pragma_Arg (Arg1);
14661 if not Is_Entity_Name (Id)
14662 or else Ekind (Entity (Id)) /= E_Variable
14664 Error_Pragma_Arg ("local variable name required", Arg1);
14669 if Rep_Item_Too_Early (E, N)
14670 or else Rep_Item_Too_Late (E, N)
14675 Set_Has_Pragma_Thread_Local_Storage (E);
14676 Set_Has_Gigi_Rep_Item (E);
14677 end Thread_Local_Storage;
14683 -- pragma Time_Slice (static_duration_EXPRESSION);
14685 when Pragma_Time_Slice => Time_Slice : declare
14691 Check_Arg_Count (1);
14692 Check_No_Identifiers;
14693 Check_In_Main_Program;
14694 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
14696 if not Error_Posted (Arg1) then
14698 while Present (Nod) loop
14699 if Nkind (Nod) = N_Pragma
14700 and then Pragma_Name (Nod) = Name_Time_Slice
14702 Error_Msg_Name_1 := Pname;
14703 Error_Msg_N ("duplicate pragma% not permitted", Nod);
14710 -- Process only if in main unit
14712 if Get_Source_Unit (Loc) = Main_Unit then
14713 Opt.Time_Slice_Set := True;
14714 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
14716 if Val <= Ureal_0 then
14717 Opt.Time_Slice_Value := 0;
14719 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
14720 Opt.Time_Slice_Value := 1_000_000_000;
14723 Opt.Time_Slice_Value :=
14724 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
14733 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
14735 -- TITLING_OPTION ::=
14736 -- [Title =>] STRING_LITERAL
14737 -- | [Subtitle =>] STRING_LITERAL
14739 when Pragma_Title => Title : declare
14740 Args : Args_List (1 .. 2);
14741 Names : constant Name_List (1 .. 2) := (
14747 Gather_Associations (Names, Args);
14750 for J in 1 .. 2 loop
14751 if Present (Args (J)) then
14752 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
14757 ---------------------
14758 -- Unchecked_Union --
14759 ---------------------
14761 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
14763 when Pragma_Unchecked_Union => Unchecked_Union : declare
14764 Assoc : constant Node_Id := Arg1;
14765 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
14775 Check_No_Identifiers;
14776 Check_Arg_Count (1);
14777 Check_Arg_Is_Local_Name (Arg1);
14779 Find_Type (Type_Id);
14781 Typ := Entity (Type_Id);
14784 or else Rep_Item_Too_Early (Typ, N)
14788 Typ := Underlying_Type (Typ);
14791 if Rep_Item_Too_Late (Typ, N) then
14795 Check_First_Subtype (Arg1);
14797 -- Note remaining cases are references to a type in the current
14798 -- declarative part. If we find an error, we post the error on
14799 -- the relevant type declaration at an appropriate point.
14801 if not Is_Record_Type (Typ) then
14802 Error_Msg_N ("unchecked union must be record type", Typ);
14805 elsif Is_Tagged_Type (Typ) then
14806 Error_Msg_N ("unchecked union must not be tagged", Typ);
14809 elsif not Has_Discriminants (Typ) then
14811 ("unchecked union must have one discriminant", Typ);
14814 -- Note: in previous versions of GNAT we used to check for limited
14815 -- types and give an error, but in fact the standard does allow
14816 -- Unchecked_Union on limited types, so this check was removed.
14818 -- Similarly, GNAT used to require that all discriminants have
14819 -- default values, but this is not mandated by the RM.
14821 -- Proceed with basic error checks completed
14824 Tdef := Type_Definition (Declaration_Node (Typ));
14825 Clist := Component_List (Tdef);
14827 -- Check presence of component list and variant part
14829 if No (Clist) or else No (Variant_Part (Clist)) then
14831 ("unchecked union must have variant part", Tdef);
14835 -- Check components
14837 Comp := First (Component_Items (Clist));
14838 while Present (Comp) loop
14839 Check_Component (Comp, Typ);
14843 -- Check variant part
14845 Vpart := Variant_Part (Clist);
14847 Variant := First (Variants (Vpart));
14848 while Present (Variant) loop
14849 Check_Variant (Variant, Typ);
14854 Set_Is_Unchecked_Union (Typ);
14855 Set_Convention (Typ, Convention_C);
14856 Set_Has_Unchecked_Union (Base_Type (Typ));
14857 Set_Is_Unchecked_Union (Base_Type (Typ));
14858 end Unchecked_Union;
14860 ------------------------
14861 -- Unimplemented_Unit --
14862 ------------------------
14864 -- pragma Unimplemented_Unit;
14866 -- Note: this only gives an error if we are generating code, or if
14867 -- we are in a generic library unit (where the pragma appears in the
14868 -- body, not in the spec).
14870 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
14871 Cunitent : constant Entity_Id :=
14872 Cunit_Entity (Get_Source_Unit (Loc));
14873 Ent_Kind : constant Entity_Kind :=
14878 Check_Arg_Count (0);
14880 if Operating_Mode = Generate_Code
14881 or else Ent_Kind = E_Generic_Function
14882 or else Ent_Kind = E_Generic_Procedure
14883 or else Ent_Kind = E_Generic_Package
14885 Get_Name_String (Chars (Cunitent));
14886 Set_Casing (Mixed_Case);
14887 Write_Str (Name_Buffer (1 .. Name_Len));
14888 Write_Str (" is not supported in this configuration");
14890 raise Unrecoverable_Error;
14892 end Unimplemented_Unit;
14894 ------------------------
14895 -- Universal_Aliasing --
14896 ------------------------
14898 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
14900 when Pragma_Universal_Aliasing => Universal_Alias : declare
14905 Check_Arg_Count (1);
14906 Check_Optional_Identifier (Arg2, Name_Entity);
14907 Check_Arg_Is_Local_Name (Arg1);
14908 E_Id := Entity (Get_Pragma_Arg (Arg1));
14910 if E_Id = Any_Type then
14912 elsif No (E_Id) or else not Is_Type (E_Id) then
14913 Error_Pragma_Arg ("pragma% requires type", Arg1);
14916 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
14917 Record_Rep_Item (E_Id, N);
14918 end Universal_Alias;
14920 --------------------
14921 -- Universal_Data --
14922 --------------------
14924 -- pragma Universal_Data [(library_unit_NAME)];
14926 when Pragma_Universal_Data =>
14929 -- If this is a configuration pragma, then set the universal
14930 -- addressing option, otherwise confirm that the pragma satisfies
14931 -- the requirements of library unit pragma placement and leave it
14932 -- to the GNAAMP back end to detect the pragma (avoids transitive
14933 -- setting of the option due to withed units).
14935 if Is_Configuration_Pragma then
14936 Universal_Addressing_On_AAMP := True;
14938 Check_Valid_Library_Unit_Pragma;
14941 if not AAMP_On_Target then
14942 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
14949 -- pragma Unmodified (local_Name {, local_Name});
14951 when Pragma_Unmodified => Unmodified : declare
14952 Arg_Node : Node_Id;
14953 Arg_Expr : Node_Id;
14954 Arg_Ent : Entity_Id;
14958 Check_At_Least_N_Arguments (1);
14960 -- Loop through arguments
14963 while Present (Arg_Node) loop
14964 Check_No_Identifier (Arg_Node);
14966 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
14967 -- in fact generate reference, so that the entity will have a
14968 -- reference, which will inhibit any warnings about it not
14969 -- being referenced, and also properly show up in the ali file
14970 -- as a reference. But this reference is recorded before the
14971 -- Has_Pragma_Unreferenced flag is set, so that no warning is
14972 -- generated for this reference.
14974 Check_Arg_Is_Local_Name (Arg_Node);
14975 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14977 if Is_Entity_Name (Arg_Expr) then
14978 Arg_Ent := Entity (Arg_Expr);
14980 if not Is_Assignable (Arg_Ent) then
14982 ("pragma% can only be applied to a variable",
14985 Set_Has_Pragma_Unmodified (Arg_Ent);
14997 -- pragma Unreferenced (local_Name {, local_Name});
14999 -- or when used in a context clause:
15001 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
15003 when Pragma_Unreferenced => Unreferenced : declare
15004 Arg_Node : Node_Id;
15005 Arg_Expr : Node_Id;
15006 Arg_Ent : Entity_Id;
15011 Check_At_Least_N_Arguments (1);
15013 -- Check case of appearing within context clause
15015 if Is_In_Context_Clause then
15017 -- The arguments must all be units mentioned in a with clause
15018 -- in the same context clause. Note we already checked (in
15019 -- Par.Prag) that the arguments are either identifiers or
15020 -- selected components.
15023 while Present (Arg_Node) loop
15024 Citem := First (List_Containing (N));
15025 while Citem /= N loop
15026 if Nkind (Citem) = N_With_Clause
15028 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
15030 Set_Has_Pragma_Unreferenced
15033 (Library_Unit (Citem))));
15035 (Get_Pragma_Arg (Arg_Node), Name (Citem));
15044 ("argument of pragma% is not withed unit", Arg_Node);
15050 -- Case of not in list of context items
15054 while Present (Arg_Node) loop
15055 Check_No_Identifier (Arg_Node);
15057 -- Note: the analyze call done by Check_Arg_Is_Local_Name
15058 -- will in fact generate reference, so that the entity will
15059 -- have a reference, which will inhibit any warnings about
15060 -- it not being referenced, and also properly show up in the
15061 -- ali file as a reference. But this reference is recorded
15062 -- before the Has_Pragma_Unreferenced flag is set, so that
15063 -- no warning is generated for this reference.
15065 Check_Arg_Is_Local_Name (Arg_Node);
15066 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15068 if Is_Entity_Name (Arg_Expr) then
15069 Arg_Ent := Entity (Arg_Expr);
15071 -- If the entity is overloaded, the pragma applies to the
15072 -- most recent overloading, as documented. In this case,
15073 -- name resolution does not generate a reference, so it
15074 -- must be done here explicitly.
15076 if Is_Overloaded (Arg_Expr) then
15077 Generate_Reference (Arg_Ent, N);
15080 Set_Has_Pragma_Unreferenced (Arg_Ent);
15088 --------------------------
15089 -- Unreferenced_Objects --
15090 --------------------------
15092 -- pragma Unreferenced_Objects (local_Name {, local_Name});
15094 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
15095 Arg_Node : Node_Id;
15096 Arg_Expr : Node_Id;
15100 Check_At_Least_N_Arguments (1);
15103 while Present (Arg_Node) loop
15104 Check_No_Identifier (Arg_Node);
15105 Check_Arg_Is_Local_Name (Arg_Node);
15106 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15108 if not Is_Entity_Name (Arg_Expr)
15109 or else not Is_Type (Entity (Arg_Expr))
15112 ("argument for pragma% must be type or subtype", Arg_Node);
15115 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
15118 end Unreferenced_Objects;
15120 ------------------------------
15121 -- Unreserve_All_Interrupts --
15122 ------------------------------
15124 -- pragma Unreserve_All_Interrupts;
15126 when Pragma_Unreserve_All_Interrupts =>
15128 Check_Arg_Count (0);
15130 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
15131 Unreserve_All_Interrupts := True;
15138 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
15140 when Pragma_Unsuppress =>
15142 Process_Suppress_Unsuppress (False);
15144 -------------------
15145 -- Use_VADS_Size --
15146 -------------------
15148 -- pragma Use_VADS_Size;
15150 when Pragma_Use_VADS_Size =>
15152 Check_Arg_Count (0);
15153 Check_Valid_Configuration_Pragma;
15154 Use_VADS_Size := True;
15156 ---------------------
15157 -- Validity_Checks --
15158 ---------------------
15160 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
15162 when Pragma_Validity_Checks => Validity_Checks : declare
15163 A : constant Node_Id := Get_Pragma_Arg (Arg1);
15169 Check_Arg_Count (1);
15170 Check_No_Identifiers;
15172 if Nkind (A) = N_String_Literal then
15176 Slen : constant Natural := Natural (String_Length (S));
15177 Options : String (1 .. Slen);
15183 C := Get_String_Char (S, Int (J));
15184 exit when not In_Character_Range (C);
15185 Options (J) := Get_Character (C);
15188 Set_Validity_Check_Options (Options);
15196 elsif Nkind (A) = N_Identifier then
15197 if Chars (A) = Name_All_Checks then
15198 Set_Validity_Check_Options ("a");
15199 elsif Chars (A) = Name_On then
15200 Validity_Checks_On := True;
15201 elsif Chars (A) = Name_Off then
15202 Validity_Checks_On := False;
15205 end Validity_Checks;
15211 -- pragma Volatile (LOCAL_NAME);
15213 when Pragma_Volatile =>
15214 Process_Atomic_Shared_Volatile;
15216 -------------------------
15217 -- Volatile_Components --
15218 -------------------------
15220 -- pragma Volatile_Components (array_LOCAL_NAME);
15222 -- Volatile is handled by the same circuit as Atomic_Components
15228 -- pragma Warnings (On | Off);
15229 -- pragma Warnings (On | Off, LOCAL_NAME);
15230 -- pragma Warnings (static_string_EXPRESSION);
15231 -- pragma Warnings (On | Off, STRING_LITERAL);
15233 when Pragma_Warnings => Warnings : begin
15235 Check_At_Least_N_Arguments (1);
15236 Check_No_Identifiers;
15238 -- If debug flag -gnatd.i is set, pragma is ignored
15240 if Debug_Flag_Dot_I then
15244 -- Process various forms of the pragma
15247 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
15250 -- One argument case
15252 if Arg_Count = 1 then
15254 -- On/Off one argument case was processed by parser
15256 if Nkind (Argx) = N_Identifier
15258 (Chars (Argx) = Name_On
15260 Chars (Argx) = Name_Off)
15264 -- One argument case must be ON/OFF or static string expr
15266 elsif not Is_Static_String_Expression (Arg1) then
15268 ("argument of pragma% must be On/Off or " &
15269 "static string expression", Arg1);
15271 -- One argument string expression case
15275 Lit : constant Node_Id := Expr_Value_S (Argx);
15276 Str : constant String_Id := Strval (Lit);
15277 Len : constant Nat := String_Length (Str);
15285 while J <= Len loop
15286 C := Get_String_Char (Str, J);
15287 OK := In_Character_Range (C);
15290 Chr := Get_Character (C);
15294 if J < Len and then Chr = '.' then
15296 C := Get_String_Char (Str, J);
15297 Chr := Get_Character (C);
15299 if not Set_Dot_Warning_Switch (Chr) then
15301 ("invalid warning switch character " &
15308 OK := Set_Warning_Switch (Chr);
15314 ("invalid warning switch character " & Chr,
15323 -- Two or more arguments (must be two)
15326 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
15327 Check_At_Most_N_Arguments (2);
15335 E_Id := Get_Pragma_Arg (Arg2);
15338 -- In the expansion of an inlined body, a reference to
15339 -- the formal may be wrapped in a conversion if the
15340 -- actual is a conversion. Retrieve the real entity name.
15342 if (In_Instance_Body or In_Inlined_Body)
15343 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
15345 E_Id := Expression (E_Id);
15348 -- Entity name case
15350 if Is_Entity_Name (E_Id) then
15351 E := Entity (E_Id);
15358 (E, (Chars (Get_Pragma_Arg (Arg1)) =
15361 -- For OFF case, make entry in warnings off
15362 -- pragma table for later processing. But we do
15363 -- not do that within an instance, since these
15364 -- warnings are about what is needed in the
15365 -- template, not an instance of it.
15367 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
15368 and then Warn_On_Warnings_Off
15369 and then not In_Instance
15371 Warnings_Off_Pragmas.Append ((N, E));
15374 if Is_Enumeration_Type (E) then
15378 Lit := First_Literal (E);
15379 while Present (Lit) loop
15380 Set_Warnings_Off (Lit);
15381 Next_Literal (Lit);
15386 exit when No (Homonym (E));
15391 -- Error if not entity or static string literal case
15393 elsif not Is_Static_String_Expression (Arg2) then
15395 ("second argument of pragma% must be entity " &
15396 "name or static string expression", Arg2);
15398 -- String literal case
15401 String_To_Name_Buffer
15402 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
15404 -- Note on configuration pragma case: If this is a
15405 -- configuration pragma, then for an OFF pragma, we
15406 -- just set Config True in the call, which is all
15407 -- that needs to be done. For the case of ON, this
15408 -- is normally an error, unless it is canceling the
15409 -- effect of a previous OFF pragma in the same file.
15410 -- In any other case, an error will be signalled (ON
15411 -- with no matching OFF).
15413 -- Note: We set Used if we are inside a generic to
15414 -- disable the test that the non-config case actually
15415 -- cancels a warning. That's because we can't be sure
15416 -- there isn't an instantiation in some other unit
15417 -- where a warning is suppressed.
15419 -- We could do a little better here by checking if the
15420 -- generic unit we are inside is public, but for now
15421 -- we don't bother with that refinement.
15423 if Chars (Argx) = Name_Off then
15424 Set_Specific_Warning_Off
15425 (Loc, Name_Buffer (1 .. Name_Len),
15426 Config => Is_Configuration_Pragma,
15427 Used => Inside_A_Generic or else In_Instance);
15429 elsif Chars (Argx) = Name_On then
15430 Set_Specific_Warning_On
15431 (Loc, Name_Buffer (1 .. Name_Len), Err);
15435 ("?pragma Warnings On with no " &
15436 "matching Warnings Off",
15446 -------------------
15447 -- Weak_External --
15448 -------------------
15450 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
15452 when Pragma_Weak_External => Weak_External : declare
15457 Check_Arg_Count (1);
15458 Check_Optional_Identifier (Arg1, Name_Entity);
15459 Check_Arg_Is_Library_Level_Local_Name (Arg1);
15460 Ent := Entity (Get_Pragma_Arg (Arg1));
15462 if Rep_Item_Too_Early (Ent, N) then
15465 Ent := Underlying_Type (Ent);
15468 -- The only processing required is to link this item on to the
15469 -- list of rep items for the given entity. This is accomplished
15470 -- by the call to Rep_Item_Too_Late (when no error is detected
15471 -- and False is returned).
15473 if Rep_Item_Too_Late (Ent, N) then
15476 Set_Has_Gigi_Rep_Item (Ent);
15480 -----------------------------
15481 -- Wide_Character_Encoding --
15482 -----------------------------
15484 -- pragma Wide_Character_Encoding (IDENTIFIER);
15486 when Pragma_Wide_Character_Encoding =>
15489 -- Nothing to do, handled in parser. Note that we do not enforce
15490 -- configuration pragma placement, this pragma can appear at any
15491 -- place in the source, allowing mixed encodings within a single
15496 --------------------
15497 -- Unknown_Pragma --
15498 --------------------
15500 -- Should be impossible, since the case of an unknown pragma is
15501 -- separately processed before the case statement is entered.
15503 when Unknown_Pragma =>
15504 raise Program_Error;
15507 -- AI05-0144: detect dangerous order dependence. Disabled for now,
15508 -- until AI is formally approved.
15510 -- Check_Order_Dependence;
15513 when Pragma_Exit => null;
15514 end Analyze_Pragma;
15516 --------------------
15517 -- Check_Disabled --
15518 --------------------
15520 function Check_Disabled (Nam : Name_Id) return Boolean is
15524 -- Loop through entries in check policy list
15526 PP := Opt.Check_Policy_List;
15528 -- If there are no specific entries that matched, then nothing is
15529 -- disabled, so return False.
15534 -- Here we have an entry see if it matches
15538 PPA : constant List_Id := Pragma_Argument_Associations (PP);
15540 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
15541 return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
15543 PP := Next_Pragma (PP);
15548 end Check_Disabled;
15550 -------------------
15551 -- Check_Enabled --
15552 -------------------
15554 function Check_Enabled (Nam : Name_Id) return Boolean is
15558 -- Loop through entries in check policy list
15560 PP := Opt.Check_Policy_List;
15562 -- If there are no specific entries that matched, then we let the
15563 -- setting of assertions govern. Note that this provides the needed
15564 -- compatibility with the RM for the cases of assertion, invariant,
15565 -- precondition, predicate, and postcondition.
15568 return Assertions_Enabled;
15570 -- Here we have an entry see if it matches
15574 PPA : constant List_Id := Pragma_Argument_Associations (PP);
15577 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
15578 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
15579 when Name_On | Name_Check =>
15581 when Name_Off | Name_Ignore =>
15584 raise Program_Error;
15588 PP := Next_Pragma (PP);
15595 ---------------------------------
15596 -- Delay_Config_Pragma_Analyze --
15597 ---------------------------------
15599 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
15601 return Pragma_Name (N) = Name_Interrupt_State
15603 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
15604 end Delay_Config_Pragma_Analyze;
15606 -------------------------
15607 -- Get_Base_Subprogram --
15608 -------------------------
15610 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
15611 Result : Entity_Id;
15614 -- Follow subprogram renaming chain
15618 if Is_Subprogram (Result)
15620 Nkind (Parent (Declaration_Node (Result))) =
15621 N_Subprogram_Renaming_Declaration
15622 and then Present (Alias (Result))
15624 Result := Alias (Result);
15628 end Get_Base_Subprogram;
15634 procedure Initialize is
15639 -----------------------------
15640 -- Is_Config_Static_String --
15641 -----------------------------
15643 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
15645 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
15646 -- This is an internal recursive function that is just like the outer
15647 -- function except that it adds the string to the name buffer rather
15648 -- than placing the string in the name buffer.
15650 ------------------------------
15651 -- Add_Config_Static_String --
15652 ------------------------------
15654 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
15661 if Nkind (N) = N_Op_Concat then
15662 if Add_Config_Static_String (Left_Opnd (N)) then
15663 N := Right_Opnd (N);
15669 if Nkind (N) /= N_String_Literal then
15670 Error_Msg_N ("string literal expected for pragma argument", N);
15674 for J in 1 .. String_Length (Strval (N)) loop
15675 C := Get_String_Char (Strval (N), J);
15677 if not In_Character_Range (C) then
15679 ("string literal contains invalid wide character",
15680 Sloc (N) + 1 + Source_Ptr (J));
15684 Add_Char_To_Name_Buffer (Get_Character (C));
15689 end Add_Config_Static_String;
15691 -- Start of processing for Is_Config_Static_String
15696 return Add_Config_Static_String (Arg);
15697 end Is_Config_Static_String;
15699 -----------------------------------------
15700 -- Is_Non_Significant_Pragma_Reference --
15701 -----------------------------------------
15703 -- This function makes use of the following static table which indicates
15704 -- whether appearance of some name in a given pragma is to be considered
15705 -- as a reference for the purposes of warnings about unreferenced objects.
15707 -- -1 indicates that references in any argument position are significant
15708 -- 0 indicates that appearance in any argument is not significant
15709 -- +n indicates that appearance as argument n is significant, but all
15710 -- other arguments are not significant
15711 -- 99 special processing required (e.g. for pragma Check)
15713 Sig_Flags : constant array (Pragma_Id) of Int :=
15714 (Pragma_AST_Entry => -1,
15715 Pragma_Abort_Defer => -1,
15716 Pragma_Ada_83 => -1,
15717 Pragma_Ada_95 => -1,
15718 Pragma_Ada_05 => -1,
15719 Pragma_Ada_2005 => -1,
15720 Pragma_Ada_12 => -1,
15721 Pragma_Ada_2012 => -1,
15722 Pragma_All_Calls_Remote => -1,
15723 Pragma_Annotate => -1,
15724 Pragma_Assert => -1,
15725 Pragma_Assert_And_Cut => -1,
15726 Pragma_Assertion_Policy => 0,
15727 Pragma_Assume => 0,
15728 Pragma_Assume_No_Invalid_Values => 0,
15729 Pragma_Attribute_Definition => +3,
15730 Pragma_Asynchronous => -1,
15731 Pragma_Atomic => 0,
15732 Pragma_Atomic_Components => 0,
15733 Pragma_Attach_Handler => -1,
15734 Pragma_Check => 99,
15735 Pragma_Check_Name => 0,
15736 Pragma_Check_Policy => 0,
15737 Pragma_CIL_Constructor => -1,
15738 Pragma_CPP_Class => 0,
15739 Pragma_CPP_Constructor => 0,
15740 Pragma_CPP_Virtual => 0,
15741 Pragma_CPP_Vtable => 0,
15743 Pragma_C_Pass_By_Copy => 0,
15744 Pragma_Comment => 0,
15745 Pragma_Common_Object => -1,
15746 Pragma_Compile_Time_Error => -1,
15747 Pragma_Compile_Time_Warning => -1,
15748 Pragma_Compiler_Unit => 0,
15749 Pragma_Complete_Representation => 0,
15750 Pragma_Complex_Representation => 0,
15751 Pragma_Component_Alignment => -1,
15752 Pragma_Contract_Case => -1,
15753 Pragma_Contract_Cases => -1,
15754 Pragma_Controlled => 0,
15755 Pragma_Convention => 0,
15756 Pragma_Convention_Identifier => 0,
15757 Pragma_Debug => -1,
15758 Pragma_Debug_Policy => 0,
15759 Pragma_Detect_Blocking => -1,
15760 Pragma_Default_Storage_Pool => -1,
15761 Pragma_Disable_Atomic_Synchronization => -1,
15762 Pragma_Discard_Names => 0,
15763 Pragma_Dispatching_Domain => -1,
15764 Pragma_Elaborate => -1,
15765 Pragma_Elaborate_All => -1,
15766 Pragma_Elaborate_Body => -1,
15767 Pragma_Elaboration_Checks => -1,
15768 Pragma_Eliminate => -1,
15769 Pragma_Enable_Atomic_Synchronization => -1,
15770 Pragma_Export => -1,
15771 Pragma_Export_Exception => -1,
15772 Pragma_Export_Function => -1,
15773 Pragma_Export_Object => -1,
15774 Pragma_Export_Procedure => -1,
15775 Pragma_Export_Value => -1,
15776 Pragma_Export_Valued_Procedure => -1,
15777 Pragma_Extend_System => -1,
15778 Pragma_Extensions_Allowed => -1,
15779 Pragma_External => -1,
15780 Pragma_Favor_Top_Level => -1,
15781 Pragma_External_Name_Casing => -1,
15782 Pragma_Fast_Math => -1,
15783 Pragma_Finalize_Storage_Only => 0,
15784 Pragma_Float_Representation => 0,
15785 Pragma_Ident => -1,
15786 Pragma_Implementation_Defined => -1,
15787 Pragma_Implemented => -1,
15788 Pragma_Implicit_Packing => 0,
15789 Pragma_Import => +2,
15790 Pragma_Import_Exception => 0,
15791 Pragma_Import_Function => 0,
15792 Pragma_Import_Object => 0,
15793 Pragma_Import_Procedure => 0,
15794 Pragma_Import_Valued_Procedure => 0,
15795 Pragma_Independent => 0,
15796 Pragma_Independent_Components => 0,
15797 Pragma_Initialize_Scalars => -1,
15798 Pragma_Inline => 0,
15799 Pragma_Inline_Always => 0,
15800 Pragma_Inline_Generic => 0,
15801 Pragma_Inspection_Point => -1,
15802 Pragma_Interface => +2,
15803 Pragma_Interface_Name => +2,
15804 Pragma_Interrupt_Handler => -1,
15805 Pragma_Interrupt_Priority => -1,
15806 Pragma_Interrupt_State => -1,
15807 Pragma_Invariant => -1,
15808 Pragma_Java_Constructor => -1,
15809 Pragma_Java_Interface => -1,
15810 Pragma_Keep_Names => 0,
15811 Pragma_License => -1,
15812 Pragma_Link_With => -1,
15813 Pragma_Linker_Alias => -1,
15814 Pragma_Linker_Constructor => -1,
15815 Pragma_Linker_Destructor => -1,
15816 Pragma_Linker_Options => -1,
15817 Pragma_Linker_Section => -1,
15819 Pragma_Lock_Free => -1,
15820 Pragma_Locking_Policy => -1,
15821 Pragma_Long_Float => -1,
15822 Pragma_Loop_Invariant => -1,
15823 Pragma_Loop_Variant => -1,
15824 Pragma_Machine_Attribute => -1,
15826 Pragma_Main_Storage => -1,
15827 Pragma_Memory_Size => -1,
15828 Pragma_No_Return => 0,
15829 Pragma_No_Body => 0,
15830 Pragma_No_Run_Time => -1,
15831 Pragma_No_Strict_Aliasing => -1,
15832 Pragma_Normalize_Scalars => -1,
15833 Pragma_Obsolescent => 0,
15834 Pragma_Optimize => -1,
15835 Pragma_Optimize_Alignment => -1,
15836 Pragma_Overflow_Mode => 0,
15837 Pragma_Ordered => 0,
15840 Pragma_Partition_Elaboration_Policy => -1,
15841 Pragma_Passive => -1,
15842 Pragma_Preelaborable_Initialization => -1,
15843 Pragma_Polling => -1,
15844 Pragma_Persistent_BSS => 0,
15845 Pragma_Postcondition => -1,
15846 Pragma_Precondition => -1,
15847 Pragma_Predicate => -1,
15848 Pragma_Preelaborate => -1,
15849 Pragma_Preelaborate_05 => -1,
15850 Pragma_Priority => -1,
15851 Pragma_Priority_Specific_Dispatching => -1,
15852 Pragma_Profile => 0,
15853 Pragma_Profile_Warnings => 0,
15854 Pragma_Propagate_Exceptions => -1,
15855 Pragma_Psect_Object => -1,
15857 Pragma_Pure_05 => -1,
15858 Pragma_Pure_12 => -1,
15859 Pragma_Pure_Function => -1,
15860 Pragma_Queuing_Policy => -1,
15861 Pragma_Ravenscar => -1,
15862 Pragma_Relative_Deadline => -1,
15863 Pragma_Remote_Access_Type => -1,
15864 Pragma_Remote_Call_Interface => -1,
15865 Pragma_Remote_Types => -1,
15866 Pragma_Restricted_Run_Time => -1,
15867 Pragma_Restriction_Warnings => -1,
15868 Pragma_Restrictions => -1,
15869 Pragma_Reviewable => -1,
15870 Pragma_Short_Circuit_And_Or => -1,
15871 Pragma_Share_Generic => -1,
15872 Pragma_Shared => -1,
15873 Pragma_Shared_Passive => -1,
15874 Pragma_Short_Descriptors => 0,
15875 Pragma_Simple_Storage_Pool_Type => 0,
15876 Pragma_Source_File_Name => -1,
15877 Pragma_Source_File_Name_Project => -1,
15878 Pragma_Source_Reference => -1,
15879 Pragma_Storage_Size => -1,
15880 Pragma_Storage_Unit => -1,
15881 Pragma_Static_Elaboration_Desired => -1,
15882 Pragma_Stream_Convert => -1,
15883 Pragma_Style_Checks => -1,
15884 Pragma_Subtitle => -1,
15885 Pragma_Suppress => 0,
15886 Pragma_Suppress_Exception_Locations => 0,
15887 Pragma_Suppress_All => -1,
15888 Pragma_Suppress_Debug_Info => 0,
15889 Pragma_Suppress_Initialization => 0,
15890 Pragma_System_Name => -1,
15891 Pragma_Task_Dispatching_Policy => -1,
15892 Pragma_Task_Info => -1,
15893 Pragma_Task_Name => -1,
15894 Pragma_Task_Storage => 0,
15895 Pragma_Test_Case => -1,
15896 Pragma_Thread_Local_Storage => 0,
15897 Pragma_Time_Slice => -1,
15898 Pragma_Title => -1,
15899 Pragma_Unchecked_Union => 0,
15900 Pragma_Unimplemented_Unit => -1,
15901 Pragma_Universal_Aliasing => -1,
15902 Pragma_Universal_Data => -1,
15903 Pragma_Unmodified => -1,
15904 Pragma_Unreferenced => -1,
15905 Pragma_Unreferenced_Objects => -1,
15906 Pragma_Unreserve_All_Interrupts => -1,
15907 Pragma_Unsuppress => 0,
15908 Pragma_Use_VADS_Size => -1,
15909 Pragma_Validity_Checks => -1,
15910 Pragma_Volatile => 0,
15911 Pragma_Volatile_Components => 0,
15912 Pragma_Warnings => -1,
15913 Pragma_Weak_External => -1,
15914 Pragma_Wide_Character_Encoding => 0,
15915 Unknown_Pragma => 0);
15917 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
15926 if Nkind (P) /= N_Pragma_Argument_Association then
15930 Id := Get_Pragma_Id (Parent (P));
15931 C := Sig_Flags (Id);
15943 -- For pragma Check, the first argument is not significant,
15944 -- the second and the third (if present) arguments are
15947 when Pragma_Check =>
15949 P = First (Pragma_Argument_Associations (Parent (P)));
15952 raise Program_Error;
15956 A := First (Pragma_Argument_Associations (Parent (P)));
15957 for J in 1 .. C - 1 loop
15965 return A = P; -- is this wrong way round ???
15968 end Is_Non_Significant_Pragma_Reference;
15970 ------------------------------
15971 -- Is_Pragma_String_Literal --
15972 ------------------------------
15974 -- This function returns true if the corresponding pragma argument is a
15975 -- static string expression. These are the only cases in which string
15976 -- literals can appear as pragma arguments. We also allow a string literal
15977 -- as the first argument to pragma Assert (although it will of course
15978 -- always generate a type error).
15980 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
15981 Pragn : constant Node_Id := Parent (Par);
15982 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
15983 Pname : constant Name_Id := Pragma_Name (Pragn);
15989 N := First (Assoc);
15996 if Pname = Name_Assert then
15999 elsif Pname = Name_Export then
16002 elsif Pname = Name_Ident then
16005 elsif Pname = Name_Import then
16008 elsif Pname = Name_Interface_Name then
16011 elsif Pname = Name_Linker_Alias then
16014 elsif Pname = Name_Linker_Section then
16017 elsif Pname = Name_Machine_Attribute then
16020 elsif Pname = Name_Source_File_Name then
16023 elsif Pname = Name_Source_Reference then
16026 elsif Pname = Name_Title then
16029 elsif Pname = Name_Subtitle then
16035 end Is_Pragma_String_Literal;
16037 -----------------------------------------
16038 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
16039 -----------------------------------------
16041 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
16042 Aspects : constant List_Id := New_List;
16043 Loc : constant Source_Ptr := Sloc (Decl);
16044 Or_Decl : constant Node_Id := Original_Node (Decl);
16046 Original_Aspects : List_Id;
16047 -- To capture global references, a copy of the created aspects must be
16048 -- inserted in the original tree.
16051 Prag_Arg_Ass : Node_Id;
16052 Prag_Id : Pragma_Id;
16055 -- Check for any PPC pragmas that appear within Decl
16057 Prag := Next (Decl);
16058 while Nkind (Prag) = N_Pragma loop
16059 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
16062 when Pragma_Postcondition | Pragma_Precondition =>
16063 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
16065 -- Make an aspect from any PPC pragma
16067 Append_To (Aspects,
16068 Make_Aspect_Specification (Loc,
16070 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
16072 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
16074 -- Generate the analysis information in the pragma expression
16075 -- and then set the pragma node analyzed to avoid any further
16078 Analyze (Expression (Prag_Arg_Ass));
16079 Set_Analyzed (Prag, True);
16081 when others => null;
16087 -- Set all new aspects into the generic declaration node
16089 if Is_Non_Empty_List (Aspects) then
16091 -- Create the list of aspects to be inserted in the original tree
16093 Original_Aspects := Copy_Separate_List (Aspects);
16095 -- Check if Decl already has aspects
16097 -- Attach the new lists of aspects to both the generic copy and the
16100 if Has_Aspects (Decl) then
16101 Append_List (Aspects, Aspect_Specifications (Decl));
16102 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
16105 Set_Parent (Aspects, Decl);
16106 Set_Aspect_Specifications (Decl, Aspects);
16107 Set_Parent (Original_Aspects, Or_Decl);
16108 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
16111 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
16113 -------------------------
16114 -- Preanalyze_CTC_Args --
16115 -------------------------
16117 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
16119 -- Preanalyze the boolean expressions, we treat these as spec
16120 -- expressions (i.e. similar to a default expression).
16122 if Present (Arg_Req) then
16123 Preanalyze_Assert_Expression
16124 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
16126 -- In ASIS mode, for a pragma generated from a source aspect, also
16127 -- analyze the original aspect expression.
16129 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
16130 Preanalyze_Assert_Expression
16131 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
16135 if Present (Arg_Ens) then
16136 Preanalyze_Assert_Expression
16137 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
16139 -- In ASIS mode, for a pragma generated from a source aspect, also
16140 -- analyze the original aspect expression.
16142 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
16143 Preanalyze_Assert_Expression
16144 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
16147 end Preanalyze_CTC_Args;
16149 --------------------------------------
16150 -- Process_Compilation_Unit_Pragmas --
16151 --------------------------------------
16153 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
16155 -- A special check for pragma Suppress_All, a very strange DEC pragma,
16156 -- strange because it comes at the end of the unit. Rational has the
16157 -- same name for a pragma, but treats it as a program unit pragma, In
16158 -- GNAT we just decide to allow it anywhere at all. If it appeared then
16159 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
16160 -- node, and we insert a pragma Suppress (All_Checks) at the start of
16161 -- the context clause to ensure the correct processing.
16163 if Has_Pragma_Suppress_All (N) then
16164 Prepend_To (Context_Items (N),
16165 Make_Pragma (Sloc (N),
16166 Chars => Name_Suppress,
16167 Pragma_Argument_Associations => New_List (
16168 Make_Pragma_Argument_Association (Sloc (N),
16169 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
16172 -- Nothing else to do at the current time!
16174 end Process_Compilation_Unit_Pragmas;
16185 --------------------------------
16186 -- Set_Encoded_Interface_Name --
16187 --------------------------------
16189 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
16190 Str : constant String_Id := Strval (S);
16191 Len : constant Int := String_Length (Str);
16196 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
16199 -- Stores encoded value of character code CC. The encoding we use an
16200 -- underscore followed by four lower case hex digits.
16206 procedure Encode is
16208 Store_String_Char (Get_Char_Code ('_'));
16210 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
16212 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
16214 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
16216 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
16219 -- Start of processing for Set_Encoded_Interface_Name
16222 -- If first character is asterisk, this is a link name, and we leave it
16223 -- completely unmodified. We also ignore null strings (the latter case
16224 -- happens only in error cases) and no encoding should occur for Java or
16225 -- AAMP interface names.
16228 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
16229 or else VM_Target /= No_VM
16230 or else AAMP_On_Target
16232 Set_Interface_Name (E, S);
16237 CC := Get_String_Char (Str, J);
16239 exit when not In_Character_Range (CC);
16241 C := Get_Character (CC);
16243 exit when C /= '_' and then C /= '$'
16244 and then C not in '0' .. '9'
16245 and then C not in 'a' .. 'z'
16246 and then C not in 'A' .. 'Z';
16249 Set_Interface_Name (E, S);
16257 -- Here we need to encode. The encoding we use as follows:
16258 -- three underscores + four hex digits (lower case)
16262 for J in 1 .. String_Length (Str) loop
16263 CC := Get_String_Char (Str, J);
16265 if not In_Character_Range (CC) then
16268 C := Get_Character (CC);
16270 if C = '_' or else C = '$'
16271 or else C in '0' .. '9'
16272 or else C in 'a' .. 'z'
16273 or else C in 'A' .. 'Z'
16275 Store_String_Char (CC);
16282 Set_Interface_Name (E,
16283 Make_String_Literal (Sloc (S),
16284 Strval => End_String));
16286 end Set_Encoded_Interface_Name;
16288 -------------------
16289 -- Set_Unit_Name --
16290 -------------------
16292 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
16297 if Nkind (N) = N_Identifier
16298 and then Nkind (With_Item) = N_Identifier
16300 Set_Entity (N, Entity (With_Item));
16302 elsif Nkind (N) = N_Selected_Component then
16303 Change_Selected_Component_To_Expanded_Name (N);
16304 Set_Entity (N, Entity (With_Item));
16305 Set_Entity (Selector_Name (N), Entity (N));
16307 Pref := Prefix (N);
16308 Scop := Scope (Entity (N));
16309 while Nkind (Pref) = N_Selected_Component loop
16310 Change_Selected_Component_To_Expanded_Name (Pref);
16311 Set_Entity (Selector_Name (Pref), Scop);
16312 Set_Entity (Pref, Scop);
16313 Pref := Prefix (Pref);
16314 Scop := Scope (Scop);
16317 Set_Entity (Pref, Scop);