1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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.
792 -- This name needs fixing ??? There is no such thing as an
793 -- "S14_Extensions" flag ???
795 function Is_Before_First_Decl
796 (Pragma_Node : Node_Id;
797 Decls : List_Id) return Boolean;
798 -- Return True if Pragma_Node is before the first declarative item in
799 -- Decls where Decls is the list of declarative items.
801 function Is_Configuration_Pragma return Boolean;
802 -- Determines if the placement of the current pragma is appropriate
803 -- for a configuration pragma.
805 function Is_In_Context_Clause return Boolean;
806 -- Returns True if pragma appears within the context clause of a unit,
807 -- and False for any other placement (does not generate any messages).
809 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
810 -- Analyzes the argument, and determines if it is a static string
811 -- expression, returns True if so, False if non-static or not String.
813 procedure Pragma_Misplaced;
814 pragma No_Return (Pragma_Misplaced);
815 -- Issue fatal error message for misplaced pragma
817 procedure Process_Atomic_Shared_Volatile;
818 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
819 -- Shared is an obsolete Ada 83 pragma, treated as being identical
820 -- in effect to pragma Atomic.
822 procedure Process_Compile_Time_Warning_Or_Error;
823 -- Common processing for Compile_Time_Error and Compile_Time_Warning
825 procedure Process_Convention
826 (C : out Convention_Id;
827 Ent : out Entity_Id);
828 -- Common processing for Convention, Interface, Import and Export.
829 -- Checks first two arguments of pragma, and sets the appropriate
830 -- convention value in the specified entity or entities. On return
831 -- C is the convention, Ent is the referenced entity.
833 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
834 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
835 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
837 procedure Process_Extended_Import_Export_Exception_Pragma
838 (Arg_Internal : Node_Id;
839 Arg_External : Node_Id;
842 -- Common processing for the pragmas Import/Export_Exception. The three
843 -- arguments correspond to the three named parameters of the pragma. An
844 -- argument is empty if the corresponding parameter is not present in
847 procedure Process_Extended_Import_Export_Object_Pragma
848 (Arg_Internal : Node_Id;
849 Arg_External : Node_Id;
851 -- Common processing for the pragmas Import/Export_Object. The three
852 -- arguments correspond to the three named parameters of the pragmas. An
853 -- argument is empty if the corresponding parameter is not present in
856 procedure Process_Extended_Import_Export_Internal_Arg
857 (Arg_Internal : Node_Id := Empty);
858 -- Common processing for all extended Import and Export pragmas. The
859 -- argument is the pragma parameter for the Internal argument. If
860 -- Arg_Internal is empty or inappropriate, an error message is posted.
861 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
862 -- set to identify the referenced entity.
864 procedure Process_Extended_Import_Export_Subprogram_Pragma
865 (Arg_Internal : Node_Id;
866 Arg_External : Node_Id;
867 Arg_Parameter_Types : Node_Id;
868 Arg_Result_Type : Node_Id := Empty;
869 Arg_Mechanism : Node_Id;
870 Arg_Result_Mechanism : Node_Id := Empty;
871 Arg_First_Optional_Parameter : Node_Id := Empty);
872 -- Common processing for all extended Import and Export pragmas applying
873 -- to subprograms. The caller omits any arguments that do not apply to
874 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
875 -- only in the Import_Function and Export_Function cases). The argument
876 -- names correspond to the allowed pragma association identifiers.
878 procedure Process_Generic_List;
879 -- Common processing for Share_Generic and Inline_Generic
881 procedure Process_Import_Or_Interface;
882 -- Common processing for Import of Interface
884 procedure Process_Import_Predefined_Type;
885 -- Processing for completing a type with pragma Import. This is used
886 -- to declare types that match predefined C types, especially for cases
887 -- without corresponding Ada predefined type.
889 procedure Process_Inline (Active : Boolean);
890 -- Common processing for Inline and Inline_Always. The parameter
891 -- indicates if the inline pragma is active, i.e. if it should actually
892 -- cause inlining to occur.
894 procedure Process_Interface_Name
895 (Subprogram_Def : Entity_Id;
898 -- Given the last two arguments of pragma Import, pragma Export, or
899 -- pragma Interface_Name, performs validity checks and sets the
900 -- Interface_Name field of the given subprogram entity to the
901 -- appropriate external or link name, depending on the arguments given.
902 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
903 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
904 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
905 -- nor Link_Arg is present, the interface name is set to the default
906 -- from the subprogram name.
908 procedure Process_Interrupt_Or_Attach_Handler;
909 -- Common processing for Interrupt and Attach_Handler pragmas
911 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
912 -- Common processing for Restrictions and Restriction_Warnings pragmas.
913 -- Warn is True for Restriction_Warnings, or for Restrictions if the
914 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
915 -- is not set in the Restrictions case.
917 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
918 -- Common processing for Suppress and Unsuppress. The boolean parameter
919 -- Suppress_Case is True for the Suppress case, and False for the
922 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
923 -- This procedure sets the Is_Exported flag for the given entity,
924 -- checking that the entity was not previously imported. Arg is
925 -- the argument that specified the entity. A check is also made
926 -- for exporting inappropriate entities.
928 procedure Set_Extended_Import_Export_External_Name
929 (Internal_Ent : Entity_Id;
930 Arg_External : Node_Id);
931 -- Common processing for all extended import export pragmas. The first
932 -- argument, Internal_Ent, is the internal entity, which has already
933 -- been checked for validity by the caller. Arg_External is from the
934 -- Import or Export pragma, and may be null if no External parameter
935 -- was present. If Arg_External is present and is a non-null string
936 -- (a null string is treated as the default), then the Interface_Name
937 -- field of Internal_Ent is set appropriately.
939 procedure Set_Imported (E : Entity_Id);
940 -- This procedure sets the Is_Imported flag for the given entity,
941 -- checking that it is not previously exported or imported.
943 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
944 -- Mech is a parameter passing mechanism (see Import_Function syntax
945 -- for MECHANISM_NAME). This routine checks that the mechanism argument
946 -- has the right form, and if not issues an error message. If the
947 -- argument has the right form then the Mechanism field of Ent is
948 -- set appropriately.
950 procedure Set_Ravenscar_Profile (N : Node_Id);
951 -- Activate the set of configuration pragmas and restrictions that make
952 -- up the Ravenscar Profile. N is the corresponding pragma node, which
953 -- is used for error messages on any constructs that violate the
956 ---------------------
957 -- Ada_2005_Pragma --
958 ---------------------
960 procedure Ada_2005_Pragma is
962 if Ada_Version <= Ada_95 then
963 Check_Restriction (No_Implementation_Pragmas, N);
967 ---------------------
968 -- Ada_2012_Pragma --
969 ---------------------
971 procedure Ada_2012_Pragma is
973 if Ada_Version <= Ada_2005 then
974 Check_Restriction (No_Implementation_Pragmas, N);
978 --------------------------
979 -- Check_Ada_83_Warning --
980 --------------------------
982 procedure Check_Ada_83_Warning is
984 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
985 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
987 end Check_Ada_83_Warning;
989 ---------------------
990 -- Check_Arg_Count --
991 ---------------------
993 procedure Check_Arg_Count (Required : Nat) is
995 if Arg_Count /= Required then
996 Error_Pragma ("wrong number of arguments for pragma%");
1000 --------------------------------
1001 -- Check_Arg_Is_External_Name --
1002 --------------------------------
1004 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
1005 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1008 if Nkind (Argx) = N_Identifier then
1012 Analyze_And_Resolve (Argx, Standard_String);
1014 if Is_OK_Static_Expression (Argx) then
1017 elsif Etype (Argx) = Any_Type then
1020 -- An interesting special case, if we have a string literal and
1021 -- we are in Ada 83 mode, then we allow it even though it will
1022 -- not be flagged as static. This allows expected Ada 83 mode
1023 -- use of external names which are string literals, even though
1024 -- technically these are not static in Ada 83.
1026 elsif Ada_Version = Ada_83
1027 and then Nkind (Argx) = N_String_Literal
1031 -- Static expression that raises Constraint_Error. This has
1032 -- already been flagged, so just exit from pragma processing.
1034 elsif Is_Static_Expression (Argx) then
1037 -- Here we have a real error (non-static expression)
1040 Error_Msg_Name_1 := Pname;
1044 "argument for pragma% must be a identifier or "
1045 & "static string expression!";
1048 Flag_Non_Static_Expr (Msg, Argx);
1053 end Check_Arg_Is_External_Name;
1055 -----------------------------
1056 -- Check_Arg_Is_Identifier --
1057 -----------------------------
1059 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
1060 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1062 if Nkind (Argx) /= N_Identifier then
1064 ("argument for pragma% must be identifier", Argx);
1066 end Check_Arg_Is_Identifier;
1068 ----------------------------------
1069 -- Check_Arg_Is_Integer_Literal --
1070 ----------------------------------
1072 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1073 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1075 if Nkind (Argx) /= N_Integer_Literal then
1077 ("argument for pragma% must be integer literal", Argx);
1079 end Check_Arg_Is_Integer_Literal;
1081 -------------------------------------------
1082 -- Check_Arg_Is_Library_Level_Local_Name --
1083 -------------------------------------------
1087 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1088 -- | library_unit_NAME
1090 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1092 Check_Arg_Is_Local_Name (Arg);
1094 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1095 and then Comes_From_Source (N)
1098 ("argument for pragma% must be library level entity", Arg);
1100 end Check_Arg_Is_Library_Level_Local_Name;
1102 -----------------------------
1103 -- Check_Arg_Is_Local_Name --
1104 -----------------------------
1108 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1109 -- | library_unit_NAME
1111 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1112 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1117 if Nkind (Argx) not in N_Direct_Name
1118 and then (Nkind (Argx) /= N_Attribute_Reference
1119 or else Present (Expressions (Argx))
1120 or else Nkind (Prefix (Argx)) /= N_Identifier)
1121 and then (not Is_Entity_Name (Argx)
1122 or else not Is_Compilation_Unit (Entity (Argx)))
1124 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1127 -- No further check required if not an entity name
1129 if not Is_Entity_Name (Argx) then
1135 Ent : constant Entity_Id := Entity (Argx);
1136 Scop : constant Entity_Id := Scope (Ent);
1138 -- Case of a pragma applied to a compilation unit: pragma must
1139 -- occur immediately after the program unit in the compilation.
1141 if Is_Compilation_Unit (Ent) then
1143 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1146 -- Case of pragma placed immediately after spec
1148 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1151 -- Case of pragma placed immediately after body
1153 elsif Nkind (Decl) = N_Subprogram_Declaration
1154 and then Present (Corresponding_Body (Decl))
1158 (Parent (Unit_Declaration_Node
1159 (Corresponding_Body (Decl))));
1161 -- All other cases are illegal
1168 -- Special restricted placement rule from 10.2.1(11.8/2)
1170 elsif Is_Generic_Formal (Ent)
1171 and then Prag_Id = Pragma_Preelaborable_Initialization
1173 OK := List_Containing (N) =
1174 Generic_Formal_Declarations
1175 (Unit_Declaration_Node (Scop));
1177 -- Default case, just check that the pragma occurs in the scope
1178 -- of the entity denoted by the name.
1181 OK := Current_Scope = Scop;
1186 ("pragma% argument must be in same declarative part", Arg);
1190 end Check_Arg_Is_Local_Name;
1192 ---------------------------------
1193 -- Check_Arg_Is_Locking_Policy --
1194 ---------------------------------
1196 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1197 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1200 Check_Arg_Is_Identifier (Argx);
1202 if not Is_Locking_Policy_Name (Chars (Argx)) then
1203 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1205 end Check_Arg_Is_Locking_Policy;
1207 -----------------------------------------------
1208 -- Check_Arg_Is_Partition_Elaboration_Policy --
1209 -----------------------------------------------
1211 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
1212 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1215 Check_Arg_Is_Identifier (Argx);
1217 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
1219 ("& is not a valid partition elaboration policy name", Argx);
1221 end Check_Arg_Is_Partition_Elaboration_Policy;
1223 -------------------------
1224 -- Check_Arg_Is_One_Of --
1225 -------------------------
1227 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1228 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1231 Check_Arg_Is_Identifier (Argx);
1233 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1234 Error_Msg_Name_2 := N1;
1235 Error_Msg_Name_3 := N2;
1236 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1238 end Check_Arg_Is_One_Of;
1240 procedure Check_Arg_Is_One_Of
1242 N1, N2, N3 : Name_Id)
1244 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1247 Check_Arg_Is_Identifier (Argx);
1249 if Chars (Argx) /= N1
1250 and then Chars (Argx) /= N2
1251 and then Chars (Argx) /= N3
1253 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1255 end Check_Arg_Is_One_Of;
1257 procedure Check_Arg_Is_One_Of
1259 N1, N2, N3, N4 : Name_Id)
1261 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1264 Check_Arg_Is_Identifier (Argx);
1266 if Chars (Argx) /= N1
1267 and then Chars (Argx) /= N2
1268 and then Chars (Argx) /= N3
1269 and then Chars (Argx) /= N4
1271 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1273 end Check_Arg_Is_One_Of;
1275 procedure Check_Arg_Is_One_Of
1277 N1, N2, N3, N4, N5 : Name_Id)
1279 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1282 Check_Arg_Is_Identifier (Argx);
1284 if Chars (Argx) /= N1
1285 and then Chars (Argx) /= N2
1286 and then Chars (Argx) /= N3
1287 and then Chars (Argx) /= N4
1288 and then Chars (Argx) /= N5
1290 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1292 end Check_Arg_Is_One_Of;
1294 ---------------------------------
1295 -- Check_Arg_Is_Queuing_Policy --
1296 ---------------------------------
1298 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1299 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1302 Check_Arg_Is_Identifier (Argx);
1304 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1305 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1307 end Check_Arg_Is_Queuing_Policy;
1309 ------------------------------------
1310 -- Check_Arg_Is_Static_Expression --
1311 ------------------------------------
1313 procedure Check_Arg_Is_Static_Expression
1315 Typ : Entity_Id := Empty)
1318 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1319 end Check_Arg_Is_Static_Expression;
1321 ------------------------------------------
1322 -- Check_Arg_Is_Task_Dispatching_Policy --
1323 ------------------------------------------
1325 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1326 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1329 Check_Arg_Is_Identifier (Argx);
1331 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1333 ("& is not a valid task dispatching policy name", Argx);
1335 end Check_Arg_Is_Task_Dispatching_Policy;
1337 ---------------------
1338 -- Check_Arg_Order --
1339 ---------------------
1341 procedure Check_Arg_Order (Names : Name_List) is
1344 Highest_So_Far : Natural := 0;
1345 -- Highest index in Names seen do far
1349 for J in 1 .. Arg_Count loop
1350 if Chars (Arg) /= No_Name then
1351 for K in Names'Range loop
1352 if Chars (Arg) = Names (K) then
1353 if K < Highest_So_Far then
1354 Error_Msg_Name_1 := Pname;
1356 ("parameters out of order for pragma%", Arg);
1357 Error_Msg_Name_1 := Names (K);
1358 Error_Msg_Name_2 := Names (Highest_So_Far);
1359 Error_Msg_N ("\% must appear before %", Arg);
1363 Highest_So_Far := K;
1371 end Check_Arg_Order;
1373 --------------------------------
1374 -- Check_At_Least_N_Arguments --
1375 --------------------------------
1377 procedure Check_At_Least_N_Arguments (N : Nat) is
1379 if Arg_Count < N then
1380 Error_Pragma ("too few arguments for pragma%");
1382 end Check_At_Least_N_Arguments;
1384 -------------------------------
1385 -- Check_At_Most_N_Arguments --
1386 -------------------------------
1388 procedure Check_At_Most_N_Arguments (N : Nat) is
1391 if Arg_Count > N then
1393 for J in 1 .. N loop
1395 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1398 end Check_At_Most_N_Arguments;
1400 ---------------------
1401 -- Check_Component --
1402 ---------------------
1404 procedure Check_Component
1407 In_Variant_Part : Boolean := False)
1409 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1410 Sindic : constant Node_Id :=
1411 Subtype_Indication (Component_Definition (Comp));
1412 Typ : constant Entity_Id := Etype (Comp_Id);
1415 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1416 -- object constraint, then the component type shall be an Unchecked_
1419 if Nkind (Sindic) = N_Subtype_Indication
1420 and then Has_Per_Object_Constraint (Comp_Id)
1421 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1424 ("component subtype subject to per-object constraint " &
1425 "must be an Unchecked_Union", Comp);
1427 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1428 -- the body of a generic unit, or within the body of any of its
1429 -- descendant library units, no part of the type of a component
1430 -- declared in a variant_part of the unchecked union type shall be of
1431 -- a formal private type or formal private extension declared within
1432 -- the formal part of the generic unit.
1434 elsif Ada_Version >= Ada_2012
1435 and then In_Generic_Body (UU_Typ)
1436 and then In_Variant_Part
1437 and then Is_Private_Type (Typ)
1438 and then Is_Generic_Type (Typ)
1441 ("component of unchecked union cannot be of generic type", Comp);
1443 elsif Needs_Finalization (Typ) then
1445 ("component of unchecked union cannot be controlled", Comp);
1447 elsif Has_Task (Typ) then
1449 ("component of unchecked union cannot have tasks", Comp);
1451 end Check_Component;
1453 ---------------------------------
1454 -- Check_Contract_Or_Test_Case --
1455 ---------------------------------
1457 procedure Check_Contract_Or_Test_Case is
1461 procedure Chain_CTC (PO : Node_Id);
1462 -- If PO is a [generic] subprogram declaration node, then the
1463 -- contract-case or test-case applies to this subprogram and the
1464 -- processing for the pragma is completed. Otherwise the pragma
1471 procedure Chain_CTC (PO : Node_Id) is
1475 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1477 ("pragma% cannot be applied to abstract subprogram");
1479 elsif Nkind (PO) = N_Entry_Declaration then
1480 Error_Pragma ("pragma% cannot be applied to entry");
1482 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1483 N_Generic_Subprogram_Declaration)
1488 -- Here if we have [generic] subprogram declaration
1490 S := Defining_Unit_Name (Specification (PO));
1492 -- Note: we do not analyze the pragma at this point. Instead we
1493 -- delay this analysis until the end of the declarative part in
1494 -- which the pragma appears. This implements the required delay
1495 -- in this analysis, allowing forward references. The analysis
1496 -- happens at the end of Analyze_Declarations.
1498 -- There should not be another contract-case or test-case with the
1499 -- same name associated to this subprogram.
1502 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
1506 CTC := Spec_CTC_List (Contract (S));
1507 while Present (CTC) loop
1509 -- Omit pragma Contract_Cases because it does not introduce
1510 -- a unique case name and it does not follow the syntax of
1511 -- Contract_Case and Test_Case.
1513 if Pragma_Name (CTC) = Name_Contract_Cases then
1517 (Name, Get_Name_From_CTC_Pragma (CTC))
1519 Error_Msg_Sloc := Sloc (CTC);
1520 Error_Pragma ("name for pragma% is already used#");
1523 CTC := Next_Pragma (CTC);
1527 -- Chain spec CTC pragma to list for subprogram
1529 Set_Next_Pragma (N, Spec_CTC_List (Contract (S)));
1530 Set_Spec_CTC_List (Contract (S), N);
1533 -- Start of processing for Check_Contract_Or_Test_Case
1536 -- First check pragma arguments
1539 Check_At_Least_N_Arguments (2);
1540 Check_At_Most_N_Arguments (4);
1542 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
1544 Check_Optional_Identifier (Arg1, Name_Name);
1545 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
1547 -- In ASIS mode, for a pragma generated from a source aspect, also
1548 -- analyze the original aspect expression.
1551 and then Present (Corresponding_Aspect (N))
1553 Check_Expr_Is_Static_Expression
1554 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
1557 Check_Optional_Identifier (Arg2, Name_Mode);
1558 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
1560 if Arg_Count = 4 then
1561 Check_Identifier (Arg3, Name_Requires);
1562 Check_Identifier (Arg4, Name_Ensures);
1564 elsif Arg_Count = 3 then
1565 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
1568 -- Check pragma placement
1570 if not Is_List_Member (N) then
1574 -- Contract-case or test-case should only appear in package spec unit
1576 if Get_Source_Unit (N) = No_Unit
1577 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
1578 N_Package_Declaration,
1579 N_Generic_Package_Declaration)
1584 -- Search prior declarations
1587 while Present (Prev (P)) loop
1590 -- If the previous node is a generic subprogram, do not go to to
1591 -- the original node, which is the unanalyzed tree: we need to
1592 -- attach the contract-case or test-case to the analyzed version
1593 -- at this point. They get propagated to the original tree when
1594 -- analyzing the corresponding body.
1596 if Nkind (P) not in N_Generic_Declaration then
1597 PO := Original_Node (P);
1602 -- Skip past prior pragma
1604 if Nkind (PO) = N_Pragma then
1607 -- Skip stuff not coming from source
1609 elsif not Comes_From_Source (PO) then
1612 -- Only remaining possibility is subprogram declaration. First
1613 -- check that it is declared directly in a package declaration.
1614 -- This may be either the package declaration for the current unit
1615 -- being defined or a local package declaration.
1617 elsif not Present (Parent (Parent (PO)))
1618 or else not Present (Parent (Parent (Parent (PO))))
1619 or else not Nkind_In (Parent (Parent (PO)),
1620 N_Package_Declaration,
1621 N_Generic_Package_Declaration)
1631 -- If we fall through, pragma was misplaced
1634 end Check_Contract_Or_Test_Case;
1636 ----------------------------
1637 -- Check_Duplicate_Pragma --
1638 ----------------------------
1640 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1641 Id : Entity_Id := E;
1645 -- Nothing to do if this pragma comes from an aspect specification,
1646 -- since we could not be duplicating a pragma, and we dealt with the
1647 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1649 if From_Aspect_Specification (N) then
1653 -- Otherwise current pragma may duplicate previous pragma or a
1654 -- previously given aspect specification or attribute definition
1655 -- clause for the same pragma.
1657 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
1660 Error_Msg_Name_1 := Pragma_Name (N);
1661 Error_Msg_Sloc := Sloc (P);
1663 -- For a single protected or a single task object, the error is
1664 -- issued on the original entity.
1666 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
1667 Id := Defining_Identifier (Original_Node (Parent (Id)));
1670 if Nkind (P) = N_Aspect_Specification
1671 or else From_Aspect_Specification (P)
1673 Error_Msg_NE ("aspect% for & previously given#", N, Id);
1675 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
1680 end Check_Duplicate_Pragma;
1682 ----------------------------------
1683 -- Check_Duplicated_Export_Name --
1684 ----------------------------------
1686 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1687 String_Val : constant String_Id := Strval (Nam);
1690 -- We are only interested in the export case, and in the case of
1691 -- generics, it is the instance, not the template, that is the
1692 -- problem (the template will generate a warning in any case).
1694 if not Inside_A_Generic
1695 and then (Prag_Id = Pragma_Export
1697 Prag_Id = Pragma_Export_Procedure
1699 Prag_Id = Pragma_Export_Valued_Procedure
1701 Prag_Id = Pragma_Export_Function)
1703 for J in Externals.First .. Externals.Last loop
1704 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1705 Error_Msg_Sloc := Sloc (Externals.Table (J));
1706 Error_Msg_N ("external name duplicates name given#", Nam);
1711 Externals.Append (Nam);
1713 end Check_Duplicated_Export_Name;
1715 -------------------------------------
1716 -- Check_Expr_Is_Static_Expression --
1717 -------------------------------------
1719 procedure Check_Expr_Is_Static_Expression
1721 Typ : Entity_Id := Empty)
1724 if Present (Typ) then
1725 Analyze_And_Resolve (Expr, Typ);
1727 Analyze_And_Resolve (Expr);
1730 if Is_OK_Static_Expression (Expr) then
1733 elsif Etype (Expr) = Any_Type then
1736 -- An interesting special case, if we have a string literal and we
1737 -- are in Ada 83 mode, then we allow it even though it will not be
1738 -- flagged as static. This allows the use of Ada 95 pragmas like
1739 -- Import in Ada 83 mode. They will of course be flagged with
1740 -- warnings as usual, but will not cause errors.
1742 elsif Ada_Version = Ada_83
1743 and then Nkind (Expr) = N_String_Literal
1747 -- Static expression that raises Constraint_Error. This has already
1748 -- been flagged, so just exit from pragma processing.
1750 elsif Is_Static_Expression (Expr) then
1753 -- Finally, we have a real error
1756 Error_Msg_Name_1 := Pname;
1760 "argument for pragma% must be a static expression!";
1763 Flag_Non_Static_Expr (Msg, Expr);
1768 end Check_Expr_Is_Static_Expression;
1770 -------------------------
1771 -- Check_First_Subtype --
1772 -------------------------
1774 procedure Check_First_Subtype (Arg : Node_Id) is
1775 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1776 Ent : constant Entity_Id := Entity (Argx);
1779 if Is_First_Subtype (Ent) then
1782 elsif Is_Type (Ent) then
1784 ("pragma% cannot apply to subtype", Argx);
1786 elsif Is_Object (Ent) then
1788 ("pragma% cannot apply to object, requires a type", Argx);
1792 ("pragma% cannot apply to&, requires a type", Argx);
1794 end Check_First_Subtype;
1796 ----------------------
1797 -- Check_Identifier --
1798 ----------------------
1800 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1803 and then Nkind (Arg) = N_Pragma_Argument_Association
1805 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1806 Error_Msg_Name_1 := Pname;
1807 Error_Msg_Name_2 := Id;
1808 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1812 end Check_Identifier;
1814 --------------------------------
1815 -- Check_Identifier_Is_One_Of --
1816 --------------------------------
1818 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1821 and then Nkind (Arg) = N_Pragma_Argument_Association
1823 if Chars (Arg) = No_Name then
1824 Error_Msg_Name_1 := Pname;
1825 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1828 elsif Chars (Arg) /= N1
1829 and then Chars (Arg) /= N2
1831 Error_Msg_Name_1 := Pname;
1832 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1836 end Check_Identifier_Is_One_Of;
1838 ---------------------------
1839 -- Check_In_Main_Program --
1840 ---------------------------
1842 procedure Check_In_Main_Program is
1843 P : constant Node_Id := Parent (N);
1846 -- Must be at in subprogram body
1848 if Nkind (P) /= N_Subprogram_Body then
1849 Error_Pragma ("% pragma allowed only in subprogram");
1851 -- Otherwise warn if obviously not main program
1853 elsif Present (Parameter_Specifications (Specification (P)))
1854 or else not Is_Compilation_Unit (Defining_Entity (P))
1856 Error_Msg_Name_1 := Pname;
1858 ("??pragma% is only effective in main program", N);
1860 end Check_In_Main_Program;
1862 ---------------------------------------
1863 -- Check_Interrupt_Or_Attach_Handler --
1864 ---------------------------------------
1866 procedure Check_Interrupt_Or_Attach_Handler is
1867 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1868 Handler_Proc, Proc_Scope : Entity_Id;
1873 if Prag_Id = Pragma_Interrupt_Handler then
1874 Check_Restriction (No_Dynamic_Attachment, N);
1877 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1878 Proc_Scope := Scope (Handler_Proc);
1880 -- On AAMP only, a pragma Interrupt_Handler is supported for
1881 -- nonprotected parameterless procedures.
1883 if not AAMP_On_Target
1884 or else Prag_Id = Pragma_Attach_Handler
1886 if Ekind (Proc_Scope) /= E_Protected_Type then
1888 ("argument of pragma% must be protected procedure", Arg1);
1891 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1892 Error_Pragma ("pragma% must be in protected definition");
1896 if not Is_Library_Level_Entity (Proc_Scope)
1897 or else (AAMP_On_Target
1898 and then not Is_Library_Level_Entity (Handler_Proc))
1901 ("argument for pragma% must be library level entity", Arg1);
1904 -- AI05-0033: A pragma cannot appear within a generic body, because
1905 -- instance can be in a nested scope. The check that protected type
1906 -- is itself a library-level declaration is done elsewhere.
1908 -- Note: we omit this check in Codepeer mode to properly handle code
1909 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1911 if Inside_A_Generic then
1912 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1913 and then In_Package_Body (Scope (Current_Scope))
1914 and then not CodePeer_Mode
1916 Error_Pragma ("pragma% cannot be used inside a generic");
1919 end Check_Interrupt_Or_Attach_Handler;
1921 --------------------------------------------
1922 -- Check_Loop_Invariant_Variant_Placement --
1923 --------------------------------------------
1925 procedure Check_Loop_Invariant_Variant_Placement is
1926 procedure Placement_Error (Constr : Node_Id);
1927 pragma No_Return (Placement_Error);
1928 -- Node Constr denotes the last loop restricted construct before we
1929 -- encountered an illegal relation between enclosing constructs. Emit
1930 -- an error depending on what Constr was.
1932 ---------------------
1933 -- Placement_Error --
1934 ---------------------
1936 procedure Placement_Error (Constr : Node_Id) is
1938 if Nkind (Constr) = N_Pragma then
1940 ("pragma % must appear immediately within the statements " &
1944 ("block containing pragma % must appear immediately within " &
1945 "the statements of a loop", Constr);
1947 end Placement_Error;
1949 -- Local declarations
1954 -- Start of processing for Check_Loop_Invariant_Variant_Placement
1959 while Present (Stmt) loop
1961 -- The pragma or previous block must appear immediately within the
1962 -- current block's declarative or statement part.
1964 if Nkind (Stmt) = N_Block_Statement then
1965 if (No (Declarations (Stmt))
1966 or else List_Containing (Prev) /= Declarations (Stmt))
1968 List_Containing (Prev) /=
1969 Statements (Handled_Statement_Sequence (Stmt))
1971 Placement_Error (Prev);
1974 -- Keep inspecting the parents because we are now within a
1975 -- chain of nested blocks.
1979 Stmt := Parent (Stmt);
1982 -- The pragma or previous block must appear immediately within the
1983 -- statements of the loop.
1985 elsif Nkind (Stmt) = N_Loop_Statement then
1986 if List_Containing (Prev) /= Statements (Stmt) then
1987 Placement_Error (Prev);
1990 -- Stop the traversal because we reached the innermost loop
1991 -- regardless of whether we encountered an error or not.
1995 -- Ignore a handled statement sequence. Note that this node may
1996 -- be related to a subprogram body in which case we will emit an
1997 -- error on the next iteration of the search.
1999 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
2000 Stmt := Parent (Stmt);
2002 -- Any other statement breaks the chain from the pragma to the
2006 Placement_Error (Prev);
2010 end Check_Loop_Invariant_Variant_Placement;
2012 -------------------------------------------
2013 -- Check_Is_In_Decl_Part_Or_Package_Spec --
2014 -------------------------------------------
2016 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
2025 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
2028 elsif Nkind_In (P, N_Package_Specification,
2033 -- Note: the following tests seem a little peculiar, because
2034 -- they test for bodies, but if we were in the statement part
2035 -- of the body, we would already have hit the handled statement
2036 -- sequence, so the only way we get here is by being in the
2037 -- declarative part of the body.
2039 elsif Nkind_In (P, N_Subprogram_Body,
2050 Error_Pragma ("pragma% is not in declarative part or package spec");
2051 end Check_Is_In_Decl_Part_Or_Package_Spec;
2053 -------------------------
2054 -- Check_No_Identifier --
2055 -------------------------
2057 procedure Check_No_Identifier (Arg : Node_Id) is
2059 if Nkind (Arg) = N_Pragma_Argument_Association
2060 and then Chars (Arg) /= No_Name
2062 Error_Pragma_Arg_Ident
2063 ("pragma% does not permit identifier& here", Arg);
2065 end Check_No_Identifier;
2067 --------------------------
2068 -- Check_No_Identifiers --
2069 --------------------------
2071 procedure Check_No_Identifiers is
2074 if Arg_Count > 0 then
2076 while Present (Arg_Node) loop
2077 Check_No_Identifier (Arg_Node);
2081 end Check_No_Identifiers;
2083 ------------------------
2084 -- Check_No_Link_Name --
2085 ------------------------
2087 procedure Check_No_Link_Name is
2090 and then Chars (Arg3) = Name_Link_Name
2095 if Present (Arg4) then
2097 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
2099 end Check_No_Link_Name;
2101 -------------------------------
2102 -- Check_Optional_Identifier --
2103 -------------------------------
2105 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
2108 and then Nkind (Arg) = N_Pragma_Argument_Association
2109 and then Chars (Arg) /= No_Name
2111 if Chars (Arg) /= Id then
2112 Error_Msg_Name_1 := Pname;
2113 Error_Msg_Name_2 := Id;
2114 Error_Msg_N ("pragma% argument expects identifier%", Arg);
2118 end Check_Optional_Identifier;
2120 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
2122 Name_Buffer (1 .. Id'Length) := Id;
2123 Name_Len := Id'Length;
2124 Check_Optional_Identifier (Arg, Name_Find);
2125 end Check_Optional_Identifier;
2127 --------------------------------------
2128 -- Check_Precondition_Postcondition --
2129 --------------------------------------
2131 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
2135 procedure Chain_PPC (PO : Node_Id);
2136 -- If PO is an entry or a [generic] subprogram declaration node, then
2137 -- the precondition/postcondition applies to this subprogram and the
2138 -- processing for the pragma is completed. Otherwise the pragma is
2145 procedure Chain_PPC (PO : Node_Id) is
2149 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2150 if not From_Aspect_Specification (N) then
2152 ("pragma% cannot be applied to abstract subprogram");
2154 elsif Class_Present (N) then
2159 ("aspect % requires ''Class for abstract subprogram");
2162 -- AI05-0230: The same restriction applies to null procedures. For
2163 -- compatibility with earlier uses of the Ada pragma, apply this
2164 -- rule only to aspect specifications.
2166 -- The above discrpency needs documentation. Robert is dubious
2167 -- about whether it is a good idea ???
2169 elsif Nkind (PO) = N_Subprogram_Declaration
2170 and then Nkind (Specification (PO)) = N_Procedure_Specification
2171 and then Null_Present (Specification (PO))
2172 and then From_Aspect_Specification (N)
2173 and then not Class_Present (N)
2176 ("aspect % requires ''Class for null procedure");
2178 -- Pre/postconditions are legal on a subprogram body if it is not
2179 -- a completion of a declaration.
2181 elsif Nkind (PO) = N_Subprogram_Body
2182 and then Acts_As_Spec (PO)
2186 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2187 N_Expression_Function,
2188 N_Generic_Subprogram_Declaration,
2189 N_Entry_Declaration)
2194 -- Here if we have [generic] subprogram or entry declaration
2196 if Nkind (PO) = N_Entry_Declaration then
2197 S := Defining_Entity (PO);
2199 S := Defining_Unit_Name (Specification (PO));
2201 if Nkind (S) = N_Defining_Program_Unit_Name then
2202 S := Defining_Identifier (S);
2206 -- Note: we do not analyze the pragma at this point. Instead we
2207 -- delay this analysis until the end of the declarative part in
2208 -- which the pragma appears. This implements the required delay
2209 -- in this analysis, allowing forward references. The analysis
2210 -- happens at the end of Analyze_Declarations.
2212 -- Chain spec PPC pragma to list for subprogram
2214 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
2215 Set_Spec_PPC_List (Contract (S), N);
2217 -- Return indicating spec case
2223 -- Start of processing for Check_Precondition_Postcondition
2226 if not Is_List_Member (N) then
2230 -- Preanalyze message argument if present. Visibility in this
2231 -- argument is established at the point of pragma occurrence.
2233 if Arg_Count = 2 then
2234 Check_Optional_Identifier (Arg2, Name_Message);
2235 Preanalyze_Spec_Expression
2236 (Get_Pragma_Arg (Arg2), Standard_String);
2239 -- For a pragma PPC in the extended main source unit, record enabled
2242 -- This may seem redundant with the call to Check_Enabled occurring
2243 -- later on when the pragma is rewritten into a pragma Check but
2244 -- is actually required in the case of a postcondition within a
2247 if Check_Enabled (Pname) and then not Split_PPC (N) then
2248 Set_SCO_Pragma_Enabled (Loc);
2251 -- If we are within an inlined body, the legality of the pragma
2252 -- has been checked already.
2254 if In_Inlined_Body then
2259 -- Search prior declarations
2262 while Present (Prev (P)) loop
2265 -- If the previous node is a generic subprogram, do not go to to
2266 -- the original node, which is the unanalyzed tree: we need to
2267 -- attach the pre/postconditions to the analyzed version at this
2268 -- point. They get propagated to the original tree when analyzing
2269 -- the corresponding body.
2271 if Nkind (P) not in N_Generic_Declaration then
2272 PO := Original_Node (P);
2277 -- Skip past prior pragma
2279 if Nkind (PO) = N_Pragma then
2282 -- Skip stuff not coming from source
2284 elsif not Comes_From_Source (PO) then
2286 -- The condition may apply to a subprogram instantiation
2288 if Nkind (PO) = N_Subprogram_Declaration
2289 and then Present (Generic_Parent (Specification (PO)))
2294 elsif Nkind (PO) = N_Subprogram_Declaration
2295 and then In_Instance
2300 -- For all other cases of non source code, do nothing
2306 -- Only remaining possibility is subprogram declaration
2314 -- If we fall through loop, pragma is at start of list, so see if it
2315 -- is at the start of declarations of a subprogram body.
2317 if Nkind (Parent (N)) = N_Subprogram_Body
2318 and then List_Containing (N) = Declarations (Parent (N))
2320 if Operating_Mode /= Generate_Code
2321 or else Inside_A_Generic
2323 -- Analyze pragma expression for correctness and for ASIS use
2325 Preanalyze_Assert_Expression
2326 (Get_Pragma_Arg (Arg1), Standard_Boolean);
2328 -- In ASIS mode, for a pragma generated from a source aspect,
2329 -- also analyze the original aspect expression.
2332 and then Present (Corresponding_Aspect (N))
2334 Preanalyze_Assert_Expression
2335 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2342 -- See if it is in the pragmas after a library level subprogram
2344 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2346 -- In formal verification mode, analyze pragma expression for
2347 -- correctness, as it is not expanded later.
2350 Analyze_PPC_In_Decl_Part
2351 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2354 Chain_PPC (Unit (Parent (Parent (N))));
2358 -- If we fall through, pragma was misplaced
2361 end Check_Precondition_Postcondition;
2363 -----------------------------
2364 -- Check_Static_Constraint --
2365 -----------------------------
2367 -- Note: for convenience in writing this procedure, in addition to
2368 -- the officially (i.e. by spec) allowed argument which is always a
2369 -- constraint, it also allows ranges and discriminant associations.
2370 -- Above is not clear ???
2372 procedure Check_Static_Constraint (Constr : Node_Id) is
2374 procedure Require_Static (E : Node_Id);
2375 -- Require given expression to be static expression
2377 --------------------
2378 -- Require_Static --
2379 --------------------
2381 procedure Require_Static (E : Node_Id) is
2383 if not Is_OK_Static_Expression (E) then
2384 Flag_Non_Static_Expr
2385 ("non-static constraint not allowed in Unchecked_Union!", E);
2390 -- Start of processing for Check_Static_Constraint
2393 case Nkind (Constr) is
2394 when N_Discriminant_Association =>
2395 Require_Static (Expression (Constr));
2398 Require_Static (Low_Bound (Constr));
2399 Require_Static (High_Bound (Constr));
2401 when N_Attribute_Reference =>
2402 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2403 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2405 when N_Range_Constraint =>
2406 Check_Static_Constraint (Range_Expression (Constr));
2408 when N_Index_Or_Discriminant_Constraint =>
2412 IDC := First (Constraints (Constr));
2413 while Present (IDC) loop
2414 Check_Static_Constraint (IDC);
2422 end Check_Static_Constraint;
2424 --------------------------------------
2425 -- Check_Valid_Configuration_Pragma --
2426 --------------------------------------
2428 -- A configuration pragma must appear in the context clause of a
2429 -- compilation unit, and only other pragmas may precede it. Note that
2430 -- the test also allows use in a configuration pragma file.
2432 procedure Check_Valid_Configuration_Pragma is
2434 if not Is_Configuration_Pragma then
2435 Error_Pragma ("incorrect placement for configuration pragma%");
2437 end Check_Valid_Configuration_Pragma;
2439 -------------------------------------
2440 -- Check_Valid_Library_Unit_Pragma --
2441 -------------------------------------
2443 procedure Check_Valid_Library_Unit_Pragma is
2445 Parent_Node : Node_Id;
2446 Unit_Name : Entity_Id;
2447 Unit_Kind : Node_Kind;
2448 Unit_Node : Node_Id;
2449 Sindex : Source_File_Index;
2452 if not Is_List_Member (N) then
2456 Plist := List_Containing (N);
2457 Parent_Node := Parent (Plist);
2459 if Parent_Node = Empty then
2462 -- Case of pragma appearing after a compilation unit. In this case
2463 -- it must have an argument with the corresponding name and must
2464 -- be part of the following pragmas of its parent.
2466 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2467 if Plist /= Pragmas_After (Parent_Node) then
2470 elsif Arg_Count = 0 then
2472 ("argument required if outside compilation unit");
2475 Check_No_Identifiers;
2476 Check_Arg_Count (1);
2477 Unit_Node := Unit (Parent (Parent_Node));
2478 Unit_Kind := Nkind (Unit_Node);
2480 Analyze (Get_Pragma_Arg (Arg1));
2482 if Unit_Kind = N_Generic_Subprogram_Declaration
2483 or else Unit_Kind = N_Subprogram_Declaration
2485 Unit_Name := Defining_Entity (Unit_Node);
2487 elsif Unit_Kind in N_Generic_Instantiation then
2488 Unit_Name := Defining_Entity (Unit_Node);
2491 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2494 if Chars (Unit_Name) /=
2495 Chars (Entity (Get_Pragma_Arg (Arg1)))
2498 ("pragma% argument is not current unit name", Arg1);
2501 if Ekind (Unit_Name) = E_Package
2502 and then Present (Renamed_Entity (Unit_Name))
2504 Error_Pragma ("pragma% not allowed for renamed package");
2508 -- Pragma appears other than after a compilation unit
2511 -- Here we check for the generic instantiation case and also
2512 -- for the case of processing a generic formal package. We
2513 -- detect these cases by noting that the Sloc on the node
2514 -- does not belong to the current compilation unit.
2516 Sindex := Source_Index (Current_Sem_Unit);
2518 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2519 Rewrite (N, Make_Null_Statement (Loc));
2522 -- If before first declaration, the pragma applies to the
2523 -- enclosing unit, and the name if present must be this name.
2525 elsif Is_Before_First_Decl (N, Plist) then
2526 Unit_Node := Unit_Declaration_Node (Current_Scope);
2527 Unit_Kind := Nkind (Unit_Node);
2529 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2532 elsif Unit_Kind = N_Subprogram_Body
2533 and then not Acts_As_Spec (Unit_Node)
2537 elsif Nkind (Parent_Node) = N_Package_Body then
2540 elsif Nkind (Parent_Node) = N_Package_Specification
2541 and then Plist = Private_Declarations (Parent_Node)
2545 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2546 or else Nkind (Parent_Node) =
2547 N_Generic_Subprogram_Declaration)
2548 and then Plist = Generic_Formal_Declarations (Parent_Node)
2552 elsif Arg_Count > 0 then
2553 Analyze (Get_Pragma_Arg (Arg1));
2555 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2557 ("name in pragma% must be enclosing unit", Arg1);
2560 -- It is legal to have no argument in this context
2566 -- Error if not before first declaration. This is because a
2567 -- library unit pragma argument must be the name of a library
2568 -- unit (RM 10.1.5(7)), but the only names permitted in this
2569 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2570 -- generic subprogram declarations or generic instantiations.
2574 ("pragma% misplaced, must be before first declaration");
2578 end Check_Valid_Library_Unit_Pragma;
2584 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2585 Clist : constant Node_Id := Component_List (Variant);
2589 Comp := First (Component_Items (Clist));
2590 while Present (Comp) loop
2591 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2600 procedure Error_Pragma (Msg : String) is
2601 MsgF : String := Msg;
2603 Error_Msg_Name_1 := Pname;
2605 Error_Msg_N (MsgF, N);
2609 ----------------------
2610 -- Error_Pragma_Arg --
2611 ----------------------
2613 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2614 MsgF : String := Msg;
2616 Error_Msg_Name_1 := Pname;
2618 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2620 end Error_Pragma_Arg;
2622 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2623 MsgF : String := Msg1;
2625 Error_Msg_Name_1 := Pname;
2627 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2628 Error_Pragma_Arg (Msg2, Arg);
2629 end Error_Pragma_Arg;
2631 ----------------------------
2632 -- Error_Pragma_Arg_Ident --
2633 ----------------------------
2635 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2636 MsgF : String := Msg;
2638 Error_Msg_Name_1 := Pname;
2640 Error_Msg_N (MsgF, Arg);
2642 end Error_Pragma_Arg_Ident;
2644 ----------------------
2645 -- Error_Pragma_Ref --
2646 ----------------------
2648 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2649 MsgF : String := Msg;
2651 Error_Msg_Name_1 := Pname;
2653 Error_Msg_Sloc := Sloc (Ref);
2654 Error_Msg_NE (MsgF, N, Ref);
2656 end Error_Pragma_Ref;
2658 ------------------------
2659 -- Find_Lib_Unit_Name --
2660 ------------------------
2662 function Find_Lib_Unit_Name return Entity_Id is
2664 -- Return inner compilation unit entity, for case of nested
2665 -- categorization pragmas. This happens in generic unit.
2667 if Nkind (Parent (N)) = N_Package_Specification
2668 and then Defining_Entity (Parent (N)) /= Current_Scope
2670 return Defining_Entity (Parent (N));
2672 return Current_Scope;
2674 end Find_Lib_Unit_Name;
2676 ----------------------------
2677 -- Find_Program_Unit_Name --
2678 ----------------------------
2680 procedure Find_Program_Unit_Name (Id : Node_Id) is
2681 Unit_Name : Entity_Id;
2682 Unit_Kind : Node_Kind;
2683 P : constant Node_Id := Parent (N);
2686 if Nkind (P) = N_Compilation_Unit then
2687 Unit_Kind := Nkind (Unit (P));
2689 if Unit_Kind = N_Subprogram_Declaration
2690 or else Unit_Kind = N_Package_Declaration
2691 or else Unit_Kind in N_Generic_Declaration
2693 Unit_Name := Defining_Entity (Unit (P));
2695 if Chars (Id) = Chars (Unit_Name) then
2696 Set_Entity (Id, Unit_Name);
2697 Set_Etype (Id, Etype (Unit_Name));
2699 Set_Etype (Id, Any_Type);
2701 ("cannot find program unit referenced by pragma%");
2705 Set_Etype (Id, Any_Type);
2706 Error_Pragma ("pragma% inapplicable to this unit");
2712 end Find_Program_Unit_Name;
2714 -----------------------------------------
2715 -- Find_Unique_Parameterless_Procedure --
2716 -----------------------------------------
2718 function Find_Unique_Parameterless_Procedure
2720 Arg : Node_Id) return Entity_Id
2722 Proc : Entity_Id := Empty;
2725 -- The body of this procedure needs some comments ???
2727 if not Is_Entity_Name (Name) then
2729 ("argument of pragma% must be entity name", Arg);
2731 elsif not Is_Overloaded (Name) then
2732 Proc := Entity (Name);
2734 if Ekind (Proc) /= E_Procedure
2735 or else Present (First_Formal (Proc))
2738 ("argument of pragma% must be parameterless procedure", Arg);
2743 Found : Boolean := False;
2745 Index : Interp_Index;
2748 Get_First_Interp (Name, Index, It);
2749 while Present (It.Nam) loop
2752 if Ekind (Proc) = E_Procedure
2753 and then No (First_Formal (Proc))
2757 Set_Entity (Name, Proc);
2758 Set_Is_Overloaded (Name, False);
2761 ("ambiguous handler name for pragma% ", Arg);
2765 Get_Next_Interp (Index, It);
2770 ("argument of pragma% must be parameterless procedure",
2773 Proc := Entity (Name);
2779 end Find_Unique_Parameterless_Procedure;
2785 procedure Fix_Error (Msg : in out String) is
2787 if From_Aspect_Specification (N) then
2788 for J in Msg'First .. Msg'Last - 5 loop
2789 if Msg (J .. J + 5) = "pragma" then
2790 Msg (J .. J + 5) := "aspect";
2794 if Error_Msg_Name_1 = Name_Precondition then
2795 Error_Msg_Name_1 := Name_Pre;
2796 elsif Error_Msg_Name_1 = Name_Postcondition then
2797 Error_Msg_Name_1 := Name_Post;
2802 -------------------------
2803 -- Gather_Associations --
2804 -------------------------
2806 procedure Gather_Associations
2808 Args : out Args_List)
2813 -- Initialize all parameters to Empty
2815 for J in Args'Range loop
2819 -- That's all we have to do if there are no argument associations
2821 if No (Pragma_Argument_Associations (N)) then
2825 -- Otherwise first deal with any positional parameters present
2827 Arg := First (Pragma_Argument_Associations (N));
2828 for Index in Args'Range loop
2829 exit when No (Arg) or else Chars (Arg) /= No_Name;
2830 Args (Index) := Get_Pragma_Arg (Arg);
2834 -- Positional parameters all processed, if any left, then we
2835 -- have too many positional parameters.
2837 if Present (Arg) and then Chars (Arg) = No_Name then
2839 ("too many positional associations for pragma%", Arg);
2842 -- Process named parameters if any are present
2844 while Present (Arg) loop
2845 if Chars (Arg) = No_Name then
2847 ("positional association cannot follow named association",
2851 for Index in Names'Range loop
2852 if Names (Index) = Chars (Arg) then
2853 if Present (Args (Index)) then
2855 ("duplicate argument association for pragma%", Arg);
2857 Args (Index) := Get_Pragma_Arg (Arg);
2862 if Index = Names'Last then
2863 Error_Msg_Name_1 := Pname;
2864 Error_Msg_N ("pragma% does not allow & argument", Arg);
2866 -- Check for possible misspelling
2868 for Index1 in Names'Range loop
2869 if Is_Bad_Spelling_Of
2870 (Chars (Arg), Names (Index1))
2872 Error_Msg_Name_1 := Names (Index1);
2873 Error_Msg_N -- CODEFIX
2874 ("\possible misspelling of%", Arg);
2886 end Gather_Associations;
2892 procedure GNAT_Pragma is
2894 -- We need to check the No_Implementation_Pragmas restriction for
2895 -- the case of a pragma from source. Note that the case of aspects
2896 -- generating corresponding pragmas marks these pragmas as not being
2897 -- from source, so this test also catches that case.
2899 if Comes_From_Source (N) then
2900 Check_Restriction (No_Implementation_Pragmas, N);
2904 --------------------------
2905 -- Is_Before_First_Decl --
2906 --------------------------
2908 function Is_Before_First_Decl
2909 (Pragma_Node : Node_Id;
2910 Decls : List_Id) return Boolean
2912 Item : Node_Id := First (Decls);
2915 -- Only other pragmas can come before this pragma
2918 if No (Item) or else Nkind (Item) /= N_Pragma then
2921 elsif Item = Pragma_Node then
2927 end Is_Before_First_Decl;
2929 -----------------------------
2930 -- Is_Configuration_Pragma --
2931 -----------------------------
2933 -- A configuration pragma must appear in the context clause of a
2934 -- compilation unit, and only other pragmas may precede it. Note that
2935 -- the test below also permits use in a configuration pragma file.
2937 function Is_Configuration_Pragma return Boolean is
2938 Lis : constant List_Id := List_Containing (N);
2939 Par : constant Node_Id := Parent (N);
2943 -- If no parent, then we are in the configuration pragma file,
2944 -- so the placement is definitely appropriate.
2949 -- Otherwise we must be in the context clause of a compilation unit
2950 -- and the only thing allowed before us in the context list is more
2951 -- configuration pragmas.
2953 elsif Nkind (Par) = N_Compilation_Unit
2954 and then Context_Items (Par) = Lis
2961 elsif Nkind (Prg) /= N_Pragma then
2971 end Is_Configuration_Pragma;
2973 --------------------------
2974 -- Is_In_Context_Clause --
2975 --------------------------
2977 function Is_In_Context_Clause return Boolean is
2979 Parent_Node : Node_Id;
2982 if not Is_List_Member (N) then
2986 Plist := List_Containing (N);
2987 Parent_Node := Parent (Plist);
2989 if Parent_Node = Empty
2990 or else Nkind (Parent_Node) /= N_Compilation_Unit
2991 or else Context_Items (Parent_Node) /= Plist
2998 end Is_In_Context_Clause;
3000 ---------------------------------
3001 -- Is_Static_String_Expression --
3002 ---------------------------------
3004 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
3005 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3008 Analyze_And_Resolve (Argx);
3009 return Is_OK_Static_Expression (Argx)
3010 and then Nkind (Argx) = N_String_Literal;
3011 end Is_Static_String_Expression;
3013 ----------------------
3014 -- Pragma_Misplaced --
3015 ----------------------
3017 procedure Pragma_Misplaced is
3019 Error_Pragma ("incorrect placement of pragma%");
3020 end Pragma_Misplaced;
3022 ------------------------------------
3023 -- Process_Atomic_Shared_Volatile --
3024 ------------------------------------
3026 procedure Process_Atomic_Shared_Volatile is
3033 procedure Set_Atomic (E : Entity_Id);
3034 -- Set given type as atomic, and if no explicit alignment was given,
3035 -- set alignment to unknown, since back end knows what the alignment
3036 -- requirements are for atomic arrays. Note: this step is necessary
3037 -- for derived types.
3043 procedure Set_Atomic (E : Entity_Id) is
3047 if not Has_Alignment_Clause (E) then
3048 Set_Alignment (E, Uint_0);
3052 -- Start of processing for Process_Atomic_Shared_Volatile
3055 Check_Ada_83_Warning;
3056 Check_No_Identifiers;
3057 Check_Arg_Count (1);
3058 Check_Arg_Is_Local_Name (Arg1);
3059 E_Id := Get_Pragma_Arg (Arg1);
3061 if Etype (E_Id) = Any_Type then
3066 D := Declaration_Node (E);
3069 -- Check duplicate before we chain ourselves!
3071 Check_Duplicate_Pragma (E);
3073 -- Now check appropriateness of the entity
3076 if Rep_Item_Too_Early (E, N)
3078 Rep_Item_Too_Late (E, N)
3082 Check_First_Subtype (Arg1);
3085 if Prag_Id /= Pragma_Volatile then
3087 Set_Atomic (Underlying_Type (E));
3088 Set_Atomic (Base_Type (E));
3091 -- Attribute belongs on the base type. If the view of the type is
3092 -- currently private, it also belongs on the underlying type.
3094 Set_Is_Volatile (Base_Type (E));
3095 Set_Is_Volatile (Underlying_Type (E));
3097 Set_Treat_As_Volatile (E);
3098 Set_Treat_As_Volatile (Underlying_Type (E));
3100 elsif K = N_Object_Declaration
3101 or else (K = N_Component_Declaration
3102 and then Original_Record_Component (E) = E)
3104 if Rep_Item_Too_Late (E, N) then
3108 if Prag_Id /= Pragma_Volatile then
3111 -- If the object declaration has an explicit initialization, a
3112 -- temporary may have to be created to hold the expression, to
3113 -- ensure that access to the object remain atomic.
3115 if Nkind (Parent (E)) = N_Object_Declaration
3116 and then Present (Expression (Parent (E)))
3118 Set_Has_Delayed_Freeze (E);
3121 -- An interesting improvement here. If an object of composite
3122 -- type X is declared atomic, and the type X isn't, that's a
3123 -- pity, since it may not have appropriate alignment etc. We
3124 -- can rescue this in the special case where the object and
3125 -- type are in the same unit by just setting the type as
3126 -- atomic, so that the back end will process it as atomic.
3128 -- Note: we used to do this for elementary types as well,
3129 -- but that turns out to be a bad idea and can have unwanted
3130 -- effects, most notably if the type is elementary, the object
3131 -- a simple component within a record, and both are in a spec:
3132 -- every object of this type in the entire program will be
3133 -- treated as atomic, thus incurring a potentially costly
3134 -- synchronization operation for every access.
3136 -- Of course it would be best if the back end could just adjust
3137 -- the alignment etc for the specific object, but that's not
3138 -- something we are capable of doing at this point.
3140 Utyp := Underlying_Type (Etype (E));
3143 and then Is_Composite_Type (Utyp)
3144 and then Sloc (E) > No_Location
3145 and then Sloc (Utyp) > No_Location
3147 Get_Source_File_Index (Sloc (E)) =
3148 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
3150 Set_Is_Atomic (Underlying_Type (Etype (E)));
3154 Set_Is_Volatile (E);
3155 Set_Treat_As_Volatile (E);
3159 ("inappropriate entity for pragma%", Arg1);
3161 end Process_Atomic_Shared_Volatile;
3163 -------------------------------------------
3164 -- Process_Compile_Time_Warning_Or_Error --
3165 -------------------------------------------
3167 procedure Process_Compile_Time_Warning_Or_Error is
3168 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
3171 Check_Arg_Count (2);
3172 Check_No_Identifiers;
3173 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3174 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3176 if Compile_Time_Known_Value (Arg1x) then
3177 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3179 Str : constant String_Id :=
3180 Strval (Get_Pragma_Arg (Arg2));
3181 Len : constant Int := String_Length (Str);
3186 Cent : constant Entity_Id :=
3187 Cunit_Entity (Current_Sem_Unit);
3189 Force : constant Boolean :=
3190 Prag_Id = Pragma_Compile_Time_Warning
3192 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3193 and then (Ekind (Cent) /= E_Package
3194 or else not In_Private_Part (Cent));
3195 -- Set True if this is the warning case, and we are in the
3196 -- visible part of a package spec, or in a subprogram spec,
3197 -- in which case we want to force the client to see the
3198 -- warning, even though it is not in the main unit.
3201 -- Loop through segments of message separated by line feeds.
3202 -- We output these segments as separate messages with
3203 -- continuation marks for all but the first.
3208 Error_Msg_Strlen := 0;
3210 -- Loop to copy characters from argument to error message
3214 exit when Ptr > Len;
3215 CC := Get_String_Char (Str, Ptr);
3218 -- Ignore wide chars ??? else store character
3220 if In_Character_Range (CC) then
3221 C := Get_Character (CC);
3222 exit when C = ASCII.LF;
3223 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3224 Error_Msg_String (Error_Msg_Strlen) := C;
3228 -- Here with one line ready to go
3230 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3232 -- If this is a warning in a spec, then we want clients
3233 -- to see the warning, so mark the message with the
3234 -- special sequence !! to force the warning. In the case
3235 -- of a package spec, we do not force this if we are in
3236 -- the private part of the spec.
3239 if Cont = False then
3240 Error_Msg_N ("<~!!", Arg1);
3243 Error_Msg_N ("\<~!!", Arg1);
3246 -- Error, rather than warning, or in a body, so we do not
3247 -- need to force visibility for client (error will be
3248 -- output in any case, and this is the situation in which
3249 -- we do not want a client to get a warning, since the
3250 -- warning is in the body or the spec private part).
3253 if Cont = False then
3254 Error_Msg_N ("<~", Arg1);
3257 Error_Msg_N ("\<~", Arg1);
3261 exit when Ptr > Len;
3266 end Process_Compile_Time_Warning_Or_Error;
3268 ------------------------
3269 -- Process_Convention --
3270 ------------------------
3272 procedure Process_Convention
3273 (C : out Convention_Id;
3274 Ent : out Entity_Id)
3280 Comp_Unit : Unit_Number_Type;
3282 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3283 -- Called if we have more than one Export/Import/Convention pragma.
3284 -- This is generally illegal, but we have a special case of allowing
3285 -- Import and Interface to coexist if they specify the convention in
3286 -- a consistent manner. We are allowed to do this, since Interface is
3287 -- an implementation defined pragma, and we choose to do it since we
3288 -- know Rational allows this combination. S is the entity id of the
3289 -- subprogram in question. This procedure also sets the special flag
3290 -- Import_Interface_Present in both pragmas in the case where we do
3291 -- have matching Import and Interface pragmas.
3293 procedure Set_Convention_From_Pragma (E : Entity_Id);
3294 -- Set convention in entity E, and also flag that the entity has a
3295 -- convention pragma. If entity is for a private or incomplete type,
3296 -- also set convention and flag on underlying type. This procedure
3297 -- also deals with the special case of C_Pass_By_Copy convention.
3299 -------------------------------
3300 -- Diagnose_Multiple_Pragmas --
3301 -------------------------------
3303 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3304 Pdec : constant Node_Id := Declaration_Node (S);
3308 function Same_Convention (Decl : Node_Id) return Boolean;
3309 -- Decl is a pragma node. This function returns True if this
3310 -- pragma has a first argument that is an identifier with a
3311 -- Chars field corresponding to the Convention_Id C.
3313 function Same_Name (Decl : Node_Id) return Boolean;
3314 -- Decl is a pragma node. This function returns True if this
3315 -- pragma has a second argument that is an identifier with a
3316 -- Chars field that matches the Chars of the current subprogram.
3318 ---------------------
3319 -- Same_Convention --
3320 ---------------------
3322 function Same_Convention (Decl : Node_Id) return Boolean is
3323 Arg1 : constant Node_Id :=
3324 First (Pragma_Argument_Associations (Decl));
3327 if Present (Arg1) then
3329 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3331 if Nkind (Arg) = N_Identifier
3332 and then Is_Convention_Name (Chars (Arg))
3333 and then Get_Convention_Id (Chars (Arg)) = C
3341 end Same_Convention;
3347 function Same_Name (Decl : Node_Id) return Boolean is
3348 Arg1 : constant Node_Id :=
3349 First (Pragma_Argument_Associations (Decl));
3357 Arg2 := Next (Arg1);
3364 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3366 if Nkind (Arg) = N_Identifier
3367 and then Chars (Arg) = Chars (S)
3376 -- Start of processing for Diagnose_Multiple_Pragmas
3381 -- Definitely give message if we have Convention/Export here
3383 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3386 -- If we have an Import or Export, scan back from pragma to
3387 -- find any previous pragma applying to the same procedure.
3388 -- The scan will be terminated by the start of the list, or
3389 -- hitting the subprogram declaration. This won't allow one
3390 -- pragma to appear in the public part and one in the private
3391 -- part, but that seems very unlikely in practice.
3395 while Present (Decl) and then Decl /= Pdec loop
3397 -- Look for pragma with same name as us
3399 if Nkind (Decl) = N_Pragma
3400 and then Same_Name (Decl)
3402 -- Give error if same as our pragma or Export/Convention
3404 if Pragma_Name (Decl) = Name_Export
3406 Pragma_Name (Decl) = Name_Convention
3408 Pragma_Name (Decl) = Pragma_Name (N)
3412 -- Case of Import/Interface or the other way round
3414 elsif Pragma_Name (Decl) = Name_Interface
3416 Pragma_Name (Decl) = Name_Import
3418 -- Here we know that we have Import and Interface. It
3419 -- doesn't matter which way round they are. See if
3420 -- they specify the same convention. If so, all OK,
3421 -- and set special flags to stop other messages
3423 if Same_Convention (Decl) then
3424 Set_Import_Interface_Present (N);
3425 Set_Import_Interface_Present (Decl);
3428 -- If different conventions, special message
3431 Error_Msg_Sloc := Sloc (Decl);
3433 ("convention differs from that given#", Arg1);
3443 -- Give message if needed if we fall through those tests
3447 ("at most one Convention/Export/Import pragma is allowed",
3450 end Diagnose_Multiple_Pragmas;
3452 --------------------------------
3453 -- Set_Convention_From_Pragma --
3454 --------------------------------
3456 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3458 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3459 -- for an overridden dispatching operation. Technically this is
3460 -- an amendment and should only be done in Ada 2005 mode. However,
3461 -- this is clearly a mistake, since the problem that is addressed
3462 -- by this AI is that there is a clear gap in the RM!
3464 if Is_Dispatching_Operation (E)
3465 and then Present (Overridden_Operation (E))
3466 and then C /= Convention (Overridden_Operation (E))
3469 ("cannot change convention for " &
3470 "overridden dispatching operation",
3474 -- Set the convention
3476 Set_Convention (E, C);
3477 Set_Has_Convention_Pragma (E);
3479 if Is_Incomplete_Or_Private_Type (E)
3480 and then Present (Underlying_Type (E))
3482 Set_Convention (Underlying_Type (E), C);
3483 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3486 -- A class-wide type should inherit the convention of the specific
3487 -- root type (although this isn't specified clearly by the RM).
3489 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3490 Set_Convention (Class_Wide_Type (E), C);
3493 -- If the entity is a record type, then check for special case of
3494 -- C_Pass_By_Copy, which is treated the same as C except that the
3495 -- special record flag is set. This convention is only permitted
3496 -- on record types (see AI95-00131).
3498 if Cname = Name_C_Pass_By_Copy then
3499 if Is_Record_Type (E) then
3500 Set_C_Pass_By_Copy (Base_Type (E));
3501 elsif Is_Incomplete_Or_Private_Type (E)
3502 and then Is_Record_Type (Underlying_Type (E))
3504 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3507 ("C_Pass_By_Copy convention allowed only for record type",
3512 -- If the entity is a derived boolean type, check for the special
3513 -- case of convention C, C++, or Fortran, where we consider any
3514 -- nonzero value to represent true.
3516 if Is_Discrete_Type (E)
3517 and then Root_Type (Etype (E)) = Standard_Boolean
3523 C = Convention_Fortran)
3525 Set_Nonzero_Is_True (Base_Type (E));
3527 end Set_Convention_From_Pragma;
3529 -- Start of processing for Process_Convention
3532 Check_At_Least_N_Arguments (2);
3533 Check_Optional_Identifier (Arg1, Name_Convention);
3534 Check_Arg_Is_Identifier (Arg1);
3535 Cname := Chars (Get_Pragma_Arg (Arg1));
3537 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3538 -- tested again below to set the critical flag).
3540 if Cname = Name_C_Pass_By_Copy then
3543 -- Otherwise we must have something in the standard convention list
3545 elsif Is_Convention_Name (Cname) then
3546 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3548 -- In DEC VMS, it seems that there is an undocumented feature that
3549 -- any unrecognized convention is treated as the default, which for
3550 -- us is convention C. It does not seem so terrible to do this
3551 -- unconditionally, silently in the VMS case, and with a warning
3552 -- in the non-VMS case.
3555 if Warn_On_Export_Import and not OpenVMS_On_Target then
3557 ("??unrecognized convention name, C assumed",
3558 Get_Pragma_Arg (Arg1));
3564 Check_Optional_Identifier (Arg2, Name_Entity);
3565 Check_Arg_Is_Local_Name (Arg2);
3567 Id := Get_Pragma_Arg (Arg2);
3570 if not Is_Entity_Name (Id) then
3571 Error_Pragma_Arg ("entity name required", Arg2);
3576 -- Set entity to return
3580 -- Ada_Pass_By_Copy special checking
3582 if C = Convention_Ada_Pass_By_Copy then
3583 if not Is_First_Subtype (E) then
3585 ("convention `Ada_Pass_By_Copy` only "
3586 & "allowed for types", Arg2);
3589 if Is_By_Reference_Type (E) then
3591 ("convention `Ada_Pass_By_Copy` not allowed for "
3592 & "by-reference type", Arg1);
3596 -- Ada_Pass_By_Reference special checking
3598 if C = Convention_Ada_Pass_By_Reference then
3599 if not Is_First_Subtype (E) then
3601 ("convention `Ada_Pass_By_Reference` only "
3602 & "allowed for types", Arg2);
3605 if Is_By_Copy_Type (E) then
3607 ("convention `Ada_Pass_By_Reference` not allowed for "
3608 & "by-copy type", Arg1);
3612 -- Go to renamed subprogram if present, since convention applies to
3613 -- the actual renamed entity, not to the renaming entity. If the
3614 -- subprogram is inherited, go to parent subprogram.
3616 if Is_Subprogram (E)
3617 and then Present (Alias (E))
3619 if Nkind (Parent (Declaration_Node (E))) =
3620 N_Subprogram_Renaming_Declaration
3622 if Scope (E) /= Scope (Alias (E)) then
3624 ("cannot apply pragma% to non-local entity&#", E);
3629 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3630 N_Private_Extension_Declaration)
3631 and then Scope (E) = Scope (Alias (E))
3635 -- Return the parent subprogram the entity was inherited from
3641 -- Check that we are not applying this to a specless body
3643 if Is_Subprogram (E)
3644 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3647 ("pragma% requires separate spec and must come before body");
3650 -- Check that we are not applying this to a named constant
3652 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3653 Error_Msg_Name_1 := Pname;
3655 ("cannot apply pragma% to named constant!",
3656 Get_Pragma_Arg (Arg2));
3658 ("\supply appropriate type for&!", Arg2);
3661 if Ekind (E) = E_Enumeration_Literal then
3662 Error_Pragma ("enumeration literal not allowed for pragma%");
3665 -- Check for rep item appearing too early or too late
3667 if Etype (E) = Any_Type
3668 or else Rep_Item_Too_Early (E, N)
3672 elsif Present (Underlying_Type (E)) then
3673 E := Underlying_Type (E);
3676 if Rep_Item_Too_Late (E, N) then
3680 if Has_Convention_Pragma (E) then
3681 Diagnose_Multiple_Pragmas (E);
3683 elsif Convention (E) = Convention_Protected
3684 or else Ekind (Scope (E)) = E_Protected_Type
3687 ("a protected operation cannot be given a different convention",
3691 -- For Intrinsic, a subprogram is required
3693 if C = Convention_Intrinsic
3694 and then not Is_Subprogram (E)
3695 and then not Is_Generic_Subprogram (E)
3698 ("second argument of pragma% must be a subprogram", Arg2);
3703 if C = Convention_Stdcall then
3705 -- A dispatching call is not allowed. A dispatching subprogram
3706 -- cannot be used to interface to the Win32 API, so in fact this
3707 -- check does not impose any effective restriction.
3709 if Is_Dispatching_Operation (E) then
3712 ("dispatching subprograms cannot use Stdcall convention");
3714 -- Subprogram is allowed, but not a generic subprogram, and not a
3715 -- dispatching operation.
3717 elsif not Is_Subprogram (E)
3718 and then not Is_Generic_Subprogram (E)
3722 and then Ekind (E) /= E_Variable
3724 -- An access to subprogram is also allowed
3728 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3731 ("second argument of pragma% must be subprogram (type)",
3736 if not Is_Subprogram (E)
3737 and then not Is_Generic_Subprogram (E)
3739 Set_Convention_From_Pragma (E);
3742 Check_First_Subtype (Arg2);
3743 Set_Convention_From_Pragma (Base_Type (E));
3745 -- For subprograms, we must set the convention on the
3746 -- internally generated directly designated type as well.
3748 if Ekind (E) = E_Access_Subprogram_Type then
3749 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3753 -- For the subprogram case, set proper convention for all homonyms
3754 -- in same scope and the same declarative part, i.e. the same
3755 -- compilation unit.
3758 Comp_Unit := Get_Source_Unit (E);
3759 Set_Convention_From_Pragma (E);
3761 -- Treat a pragma Import as an implicit body, and pragma import
3762 -- as implicit reference (for navigation in GPS).
3764 if Prag_Id = Pragma_Import then
3765 Generate_Reference (E, Id, 'b');
3767 -- For exported entities we restrict the generation of references
3768 -- to entities exported to foreign languages since entities
3769 -- exported to Ada do not provide further information to GPS and
3770 -- add undesired references to the output of the gnatxref tool.
3772 elsif Prag_Id = Pragma_Export
3773 and then Convention (E) /= Convention_Ada
3775 Generate_Reference (E, Id, 'i');
3778 -- If the pragma comes from from an aspect, it only applies
3779 -- to the given entity, not its homonyms.
3781 if From_Aspect_Specification (N) then
3785 -- Otherwise Loop through the homonyms of the pragma argument's
3786 -- entity, an apply convention to those in the current scope.
3792 exit when No (E1) or else Scope (E1) /= Current_Scope;
3794 -- Do not set the pragma on inherited operations or on formal
3797 if Comes_From_Source (E1)
3798 and then Comp_Unit = Get_Source_Unit (E1)
3799 and then not Is_Formal_Subprogram (E1)
3800 and then Nkind (Original_Node (Parent (E1))) /=
3801 N_Full_Type_Declaration
3803 if Present (Alias (E1))
3804 and then Scope (E1) /= Scope (Alias (E1))
3807 ("cannot apply pragma% to non-local entity& declared#",
3811 Set_Convention_From_Pragma (E1);
3813 if Prag_Id = Pragma_Import then
3814 Generate_Reference (E1, Id, 'b');
3819 end Process_Convention;
3821 ----------------------------------------
3822 -- Process_Disable_Enable_Atomic_Sync --
3823 ----------------------------------------
3825 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3828 Check_No_Identifiers;
3829 Check_At_Most_N_Arguments (1);
3831 -- Modeled internally as
3832 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
3836 Pragma_Identifier =>
3837 Make_Identifier (Loc, Nam),
3838 Pragma_Argument_Associations => New_List (
3839 Make_Pragma_Argument_Association (Loc,
3841 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3843 if Present (Arg1) then
3844 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3848 end Process_Disable_Enable_Atomic_Sync;
3850 -----------------------------------------------------
3851 -- Process_Extended_Import_Export_Exception_Pragma --
3852 -----------------------------------------------------
3854 procedure Process_Extended_Import_Export_Exception_Pragma
3855 (Arg_Internal : Node_Id;
3856 Arg_External : Node_Id;
3864 if not OpenVMS_On_Target then
3866 ("??pragma% ignored (applies only to Open'V'M'S)");
3869 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3870 Def_Id := Entity (Arg_Internal);
3872 if Ekind (Def_Id) /= E_Exception then
3874 ("pragma% must refer to declared exception", Arg_Internal);
3877 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3879 if Present (Arg_Form) then
3880 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3883 if Present (Arg_Form)
3884 and then Chars (Arg_Form) = Name_Ada
3888 Set_Is_VMS_Exception (Def_Id);
3889 Set_Exception_Code (Def_Id, No_Uint);
3892 if Present (Arg_Code) then
3893 if not Is_VMS_Exception (Def_Id) then
3895 ("Code option for pragma% not allowed for Ada case",
3899 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3900 Code_Val := Expr_Value (Arg_Code);
3902 if not UI_Is_In_Int_Range (Code_Val) then
3904 ("Code option for pragma% must be in 32-bit range",
3908 Set_Exception_Code (Def_Id, Code_Val);
3911 end Process_Extended_Import_Export_Exception_Pragma;
3913 -------------------------------------------------
3914 -- Process_Extended_Import_Export_Internal_Arg --
3915 -------------------------------------------------
3917 procedure Process_Extended_Import_Export_Internal_Arg
3918 (Arg_Internal : Node_Id := Empty)
3921 if No (Arg_Internal) then
3922 Error_Pragma ("Internal parameter required for pragma%");
3925 if Nkind (Arg_Internal) = N_Identifier then
3928 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3929 and then (Prag_Id = Pragma_Import_Function
3931 Prag_Id = Pragma_Export_Function)
3937 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3940 Check_Arg_Is_Local_Name (Arg_Internal);
3941 end Process_Extended_Import_Export_Internal_Arg;
3943 --------------------------------------------------
3944 -- Process_Extended_Import_Export_Object_Pragma --
3945 --------------------------------------------------
3947 procedure Process_Extended_Import_Export_Object_Pragma
3948 (Arg_Internal : Node_Id;
3949 Arg_External : Node_Id;
3955 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3956 Def_Id := Entity (Arg_Internal);
3958 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3960 ("pragma% must designate an object", Arg_Internal);
3963 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3965 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3968 ("previous Common/Psect_Object applies, pragma % not permitted",
3972 if Rep_Item_Too_Late (Def_Id, N) then
3976 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3978 if Present (Arg_Size) then
3979 Check_Arg_Is_External_Name (Arg_Size);
3982 -- Export_Object case
3984 if Prag_Id = Pragma_Export_Object then
3985 if not Is_Library_Level_Entity (Def_Id) then
3987 ("argument for pragma% must be library level entity",
3991 if Ekind (Current_Scope) = E_Generic_Package then
3992 Error_Pragma ("pragma& cannot appear in a generic unit");
3995 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3997 ("exported object must have compile time known size",
4001 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
4002 Error_Msg_N ("??duplicate Export_Object pragma", N);
4004 Set_Exported (Def_Id, Arg_Internal);
4007 -- Import_Object case
4010 if Is_Concurrent_Type (Etype (Def_Id)) then
4012 ("cannot use pragma% for task/protected object",
4016 if Ekind (Def_Id) = E_Constant then
4018 ("cannot import a constant", Arg_Internal);
4021 if Warn_On_Export_Import
4022 and then Has_Discriminants (Etype (Def_Id))
4025 ("imported value must be initialized??", Arg_Internal);
4028 if Warn_On_Export_Import
4029 and then Is_Access_Type (Etype (Def_Id))
4032 ("cannot import object of an access type??", Arg_Internal);
4035 if Warn_On_Export_Import
4036 and then Is_Imported (Def_Id)
4038 Error_Msg_N ("??duplicate Import_Object pragma", N);
4040 -- Check for explicit initialization present. Note that an
4041 -- initialization generated by the code generator, e.g. for an
4042 -- access type, does not count here.
4044 elsif Present (Expression (Parent (Def_Id)))
4047 (Original_Node (Expression (Parent (Def_Id))))
4049 Error_Msg_Sloc := Sloc (Def_Id);
4051 ("imported entities cannot be initialized (RM B.1(24))",
4052 "\no initialization allowed for & declared#", Arg1);
4054 Set_Imported (Def_Id);
4055 Note_Possible_Modification (Arg_Internal, Sure => False);
4058 end Process_Extended_Import_Export_Object_Pragma;
4060 ------------------------------------------------------
4061 -- Process_Extended_Import_Export_Subprogram_Pragma --
4062 ------------------------------------------------------
4064 procedure Process_Extended_Import_Export_Subprogram_Pragma
4065 (Arg_Internal : Node_Id;
4066 Arg_External : Node_Id;
4067 Arg_Parameter_Types : Node_Id;
4068 Arg_Result_Type : Node_Id := Empty;
4069 Arg_Mechanism : Node_Id;
4070 Arg_Result_Mechanism : Node_Id := Empty;
4071 Arg_First_Optional_Parameter : Node_Id := Empty)
4077 Ambiguous : Boolean;
4081 function Same_Base_Type
4083 Formal : Entity_Id) return Boolean;
4084 -- Determines if Ptype references the type of Formal. Note that only
4085 -- the base types need to match according to the spec. Ptype here is
4086 -- the argument from the pragma, which is either a type name, or an
4087 -- access attribute.
4089 --------------------
4090 -- Same_Base_Type --
4091 --------------------
4093 function Same_Base_Type
4095 Formal : Entity_Id) return Boolean
4097 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
4101 -- Case where pragma argument is typ'Access
4103 if Nkind (Ptype) = N_Attribute_Reference
4104 and then Attribute_Name (Ptype) = Name_Access
4106 Pref := Prefix (Ptype);
4109 if not Is_Entity_Name (Pref)
4110 or else Entity (Pref) = Any_Type
4115 -- We have a match if the corresponding argument is of an
4116 -- anonymous access type, and its designated type matches the
4117 -- type of the prefix of the access attribute
4119 return Ekind (Ftyp) = E_Anonymous_Access_Type
4120 and then Base_Type (Entity (Pref)) =
4121 Base_Type (Etype (Designated_Type (Ftyp)));
4123 -- Case where pragma argument is a type name
4128 if not Is_Entity_Name (Ptype)
4129 or else Entity (Ptype) = Any_Type
4134 -- We have a match if the corresponding argument is of the type
4135 -- given in the pragma (comparing base types)
4137 return Base_Type (Entity (Ptype)) = Ftyp;
4141 -- Start of processing for
4142 -- Process_Extended_Import_Export_Subprogram_Pragma
4145 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
4149 -- Loop through homonyms (overloadings) of the entity
4151 Hom_Id := Entity (Arg_Internal);
4152 while Present (Hom_Id) loop
4153 Def_Id := Get_Base_Subprogram (Hom_Id);
4155 -- We need a subprogram in the current scope
4157 if not Is_Subprogram (Def_Id)
4158 or else Scope (Def_Id) /= Current_Scope
4165 -- Pragma cannot apply to subprogram body
4167 if Is_Subprogram (Def_Id)
4168 and then Nkind (Parent (Declaration_Node (Def_Id))) =
4172 ("pragma% requires separate spec"
4173 & " and must come before body");
4176 -- Test result type if given, note that the result type
4177 -- parameter can only be present for the function cases.
4179 if Present (Arg_Result_Type)
4180 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
4184 elsif Etype (Def_Id) /= Standard_Void_Type
4186 (Pname = Name_Export_Procedure
4188 Pname = Name_Import_Procedure)
4192 -- Test parameter types if given. Note that this parameter
4193 -- has not been analyzed (and must not be, since it is
4194 -- semantic nonsense), so we get it as the parser left it.
4196 elsif Present (Arg_Parameter_Types) then
4197 Check_Matching_Types : declare
4202 Formal := First_Formal (Def_Id);
4204 if Nkind (Arg_Parameter_Types) = N_Null then
4205 if Present (Formal) then
4209 -- A list of one type, e.g. (List) is parsed as
4210 -- a parenthesized expression.
4212 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4213 and then Paren_Count (Arg_Parameter_Types) = 1
4216 or else Present (Next_Formal (Formal))
4221 Same_Base_Type (Arg_Parameter_Types, Formal);
4224 -- A list of more than one type is parsed as a aggregate
4226 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4227 and then Paren_Count (Arg_Parameter_Types) = 0
4229 Ptype := First (Expressions (Arg_Parameter_Types));
4230 while Present (Ptype) or else Present (Formal) loop
4233 or else not Same_Base_Type (Ptype, Formal)
4238 Next_Formal (Formal);
4243 -- Anything else is of the wrong form
4247 ("wrong form for Parameter_Types parameter",
4248 Arg_Parameter_Types);
4250 end Check_Matching_Types;
4253 -- Match is now False if the entry we found did not match
4254 -- either a supplied Parameter_Types or Result_Types argument
4260 -- Ambiguous case, the flag Ambiguous shows if we already
4261 -- detected this and output the initial messages.
4264 if not Ambiguous then
4266 Error_Msg_Name_1 := Pname;
4268 ("pragma% does not uniquely identify subprogram!",
4270 Error_Msg_Sloc := Sloc (Ent);
4271 Error_Msg_N ("matching subprogram #!", N);
4275 Error_Msg_Sloc := Sloc (Def_Id);
4276 Error_Msg_N ("matching subprogram #!", N);
4281 Hom_Id := Homonym (Hom_Id);
4284 -- See if we found an entry
4287 if not Ambiguous then
4288 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4290 ("pragma% cannot be given for generic subprogram");
4293 ("pragma% does not identify local subprogram");
4300 -- Import pragmas must be for imported entities
4302 if Prag_Id = Pragma_Import_Function
4304 Prag_Id = Pragma_Import_Procedure
4306 Prag_Id = Pragma_Import_Valued_Procedure
4308 if not Is_Imported (Ent) then
4310 ("pragma Import or Interface must precede pragma%");
4313 -- Here we have the Export case which can set the entity as exported
4315 -- But does not do so if the specified external name is null, since
4316 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4317 -- compatible) to request no external name.
4319 elsif Nkind (Arg_External) = N_String_Literal
4320 and then String_Length (Strval (Arg_External)) = 0
4324 -- In all other cases, set entity as exported
4327 Set_Exported (Ent, Arg_Internal);
4330 -- Special processing for Valued_Procedure cases
4332 if Prag_Id = Pragma_Import_Valued_Procedure
4334 Prag_Id = Pragma_Export_Valued_Procedure
4336 Formal := First_Formal (Ent);
4339 Error_Pragma ("at least one parameter required for pragma%");
4341 elsif Ekind (Formal) /= E_Out_Parameter then
4342 Error_Pragma ("first parameter must have mode out for pragma%");
4345 Set_Is_Valued_Procedure (Ent);
4349 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4351 -- Process Result_Mechanism argument if present. We have already
4352 -- checked that this is only allowed for the function case.
4354 if Present (Arg_Result_Mechanism) then
4355 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4358 -- Process Mechanism parameter if present. Note that this parameter
4359 -- is not analyzed, and must not be analyzed since it is semantic
4360 -- nonsense, so we get it in exactly as the parser left it.
4362 if Present (Arg_Mechanism) then
4370 -- A single mechanism association without a formal parameter
4371 -- name is parsed as a parenthesized expression. All other
4372 -- cases are parsed as aggregates, so we rewrite the single
4373 -- parameter case as an aggregate for consistency.
4375 if Nkind (Arg_Mechanism) /= N_Aggregate
4376 and then Paren_Count (Arg_Mechanism) = 1
4378 Rewrite (Arg_Mechanism,
4379 Make_Aggregate (Sloc (Arg_Mechanism),
4380 Expressions => New_List (
4381 Relocate_Node (Arg_Mechanism))));
4384 -- Case of only mechanism name given, applies to all formals
4386 if Nkind (Arg_Mechanism) /= N_Aggregate then
4387 Formal := First_Formal (Ent);
4388 while Present (Formal) loop
4389 Set_Mechanism_Value (Formal, Arg_Mechanism);
4390 Next_Formal (Formal);
4393 -- Case of list of mechanism associations given
4396 if Null_Record_Present (Arg_Mechanism) then
4398 ("inappropriate form for Mechanism parameter",
4402 -- Deal with positional ones first
4404 Formal := First_Formal (Ent);
4406 if Present (Expressions (Arg_Mechanism)) then
4407 Mname := First (Expressions (Arg_Mechanism));
4408 while Present (Mname) loop
4411 ("too many mechanism associations", Mname);
4414 Set_Mechanism_Value (Formal, Mname);
4415 Next_Formal (Formal);
4420 -- Deal with named entries
4422 if Present (Component_Associations (Arg_Mechanism)) then
4423 Massoc := First (Component_Associations (Arg_Mechanism));
4424 while Present (Massoc) loop
4425 Choice := First (Choices (Massoc));
4427 if Nkind (Choice) /= N_Identifier
4428 or else Present (Next (Choice))
4431 ("incorrect form for mechanism association",
4435 Formal := First_Formal (Ent);
4439 ("parameter name & not present", Choice);
4442 if Chars (Choice) = Chars (Formal) then
4444 (Formal, Expression (Massoc));
4446 -- Set entity on identifier (needed by ASIS)
4448 Set_Entity (Choice, Formal);
4453 Next_Formal (Formal);
4463 -- Process First_Optional_Parameter argument if present. We have
4464 -- already checked that this is only allowed for the Import case.
4466 if Present (Arg_First_Optional_Parameter) then
4467 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4469 ("first optional parameter must be formal parameter name",
4470 Arg_First_Optional_Parameter);
4473 Formal := First_Formal (Ent);
4477 ("specified formal parameter& not found",
4478 Arg_First_Optional_Parameter);
4481 exit when Chars (Formal) =
4482 Chars (Arg_First_Optional_Parameter);
4484 Next_Formal (Formal);
4487 Set_First_Optional_Parameter (Ent, Formal);
4489 -- Check specified and all remaining formals have right form
4491 while Present (Formal) loop
4492 if Ekind (Formal) /= E_In_Parameter then
4494 ("optional formal& is not of mode in!",
4495 Arg_First_Optional_Parameter, Formal);
4498 Dval := Default_Value (Formal);
4502 ("optional formal& does not have default value!",
4503 Arg_First_Optional_Parameter, Formal);
4505 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4510 ("default value for optional formal& is non-static!",
4511 Arg_First_Optional_Parameter, Formal);
4515 Set_Is_Optional_Parameter (Formal);
4516 Next_Formal (Formal);
4519 end Process_Extended_Import_Export_Subprogram_Pragma;
4521 --------------------------
4522 -- Process_Generic_List --
4523 --------------------------
4525 procedure Process_Generic_List is
4530 Check_No_Identifiers;
4531 Check_At_Least_N_Arguments (1);
4534 while Present (Arg) loop
4535 Exp := Get_Pragma_Arg (Arg);
4538 if not Is_Entity_Name (Exp)
4540 (not Is_Generic_Instance (Entity (Exp))
4542 not Is_Generic_Unit (Entity (Exp)))
4545 ("pragma% argument must be name of generic unit/instance",
4551 end Process_Generic_List;
4553 ------------------------------------
4554 -- Process_Import_Predefined_Type --
4555 ------------------------------------
4557 procedure Process_Import_Predefined_Type is
4558 Loc : constant Source_Ptr := Sloc (N);
4560 Ftyp : Node_Id := Empty;
4566 String_To_Name_Buffer (Strval (Expression (Arg3)));
4569 Elmt := First_Elmt (Predefined_Float_Types);
4570 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4574 Ftyp := Node (Elmt);
4576 if Present (Ftyp) then
4578 -- Don't build a derived type declaration, because predefined C
4579 -- types have no declaration anywhere, so cannot really be named.
4580 -- Instead build a full type declaration, starting with an
4581 -- appropriate type definition is built
4583 if Is_Floating_Point_Type (Ftyp) then
4584 Def := Make_Floating_Point_Definition (Loc,
4585 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4586 Make_Real_Range_Specification (Loc,
4587 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4588 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4590 -- Should never have a predefined type we cannot handle
4593 raise Program_Error;
4596 -- Build and insert a Full_Type_Declaration, which will be
4597 -- analyzed as soon as this list entry has been analyzed.
4599 Decl := Make_Full_Type_Declaration (Loc,
4600 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4601 Type_Definition => Def);
4603 Insert_After (N, Decl);
4604 Mark_Rewrite_Insertion (Decl);
4607 Error_Pragma_Arg ("no matching type found for pragma%",
4610 end Process_Import_Predefined_Type;
4612 ---------------------------------
4613 -- Process_Import_Or_Interface --
4614 ---------------------------------
4616 procedure Process_Import_Or_Interface is
4622 Process_Convention (C, Def_Id);
4623 Kill_Size_Check_Code (Def_Id);
4624 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4626 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4628 -- We do not permit Import to apply to a renaming declaration
4630 if Present (Renamed_Object (Def_Id)) then
4632 ("pragma% not allowed for object renaming", Arg2);
4634 -- User initialization is not allowed for imported object, but
4635 -- the object declaration may contain a default initialization,
4636 -- that will be discarded. Note that an explicit initialization
4637 -- only counts if it comes from source, otherwise it is simply
4638 -- the code generator making an implicit initialization explicit.
4640 elsif Present (Expression (Parent (Def_Id)))
4641 and then Comes_From_Source (Expression (Parent (Def_Id)))
4643 Error_Msg_Sloc := Sloc (Def_Id);
4645 ("no initialization allowed for declaration of& #",
4646 "\imported entities cannot be initialized (RM B.1(24))",
4650 Set_Imported (Def_Id);
4651 Process_Interface_Name (Def_Id, Arg3, Arg4);
4653 -- Note that we do not set Is_Public here. That's because we
4654 -- only want to set it if there is no address clause, and we
4655 -- don't know that yet, so we delay that processing till
4658 -- pragma Import completes deferred constants
4660 if Ekind (Def_Id) = E_Constant then
4661 Set_Has_Completion (Def_Id);
4664 -- It is not possible to import a constant of an unconstrained
4665 -- array type (e.g. string) because there is no simple way to
4666 -- write a meaningful subtype for it.
4668 if Is_Array_Type (Etype (Def_Id))
4669 and then not Is_Constrained (Etype (Def_Id))
4672 ("imported constant& must have a constrained subtype",
4677 elsif Is_Subprogram (Def_Id)
4678 or else Is_Generic_Subprogram (Def_Id)
4680 -- If the name is overloaded, pragma applies to all of the denoted
4681 -- entities in the same declarative part, unless the pragma comes
4682 -- from an aspect specification.
4685 while Present (Hom_Id) loop
4687 Def_Id := Get_Base_Subprogram (Hom_Id);
4689 -- Ignore inherited subprograms because the pragma will apply
4690 -- to the parent operation, which is the one called.
4692 if Is_Overloadable (Def_Id)
4693 and then Present (Alias (Def_Id))
4697 -- If it is not a subprogram, it must be in an outer scope and
4698 -- pragma does not apply.
4700 elsif not Is_Subprogram (Def_Id)
4701 and then not Is_Generic_Subprogram (Def_Id)
4705 -- The pragma does not apply to primitives of interfaces
4707 elsif Is_Dispatching_Operation (Def_Id)
4708 and then Present (Find_Dispatching_Type (Def_Id))
4709 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4713 -- Verify that the homonym is in the same declarative part (not
4714 -- just the same scope). If the pragma comes from an aspect
4715 -- specification we know that it is part of the declaration.
4717 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4718 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4719 and then not From_Aspect_Specification (N)
4724 Set_Imported (Def_Id);
4726 -- Reject an Import applied to an abstract subprogram
4728 if Is_Subprogram (Def_Id)
4729 and then Is_Abstract_Subprogram (Def_Id)
4731 Error_Msg_Sloc := Sloc (Def_Id);
4733 ("cannot import abstract subprogram& declared#",
4737 -- Special processing for Convention_Intrinsic
4739 if C = Convention_Intrinsic then
4741 -- Link_Name argument not allowed for intrinsic
4745 Set_Is_Intrinsic_Subprogram (Def_Id);
4747 -- If no external name is present, then check that this
4748 -- is a valid intrinsic subprogram. If an external name
4749 -- is present, then this is handled by the back end.
4752 Check_Intrinsic_Subprogram
4753 (Def_Id, Get_Pragma_Arg (Arg2));
4757 -- All interfaced procedures need an external symbol created
4758 -- for them since they are always referenced from another
4761 Set_Is_Public (Def_Id);
4763 -- Verify that the subprogram does not have a completion
4764 -- through a renaming declaration. For other completions the
4765 -- pragma appears as a too late representation.
4768 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4772 and then Nkind (Decl) = N_Subprogram_Declaration
4773 and then Present (Corresponding_Body (Decl))
4774 and then Nkind (Unit_Declaration_Node
4775 (Corresponding_Body (Decl))) =
4776 N_Subprogram_Renaming_Declaration
4778 Error_Msg_Sloc := Sloc (Def_Id);
4780 ("cannot import&, renaming already provided for " &
4781 "declaration #", N, Def_Id);
4785 Set_Has_Completion (Def_Id);
4786 Process_Interface_Name (Def_Id, Arg3, Arg4);
4789 if Is_Compilation_Unit (Hom_Id) then
4791 -- Its possible homonyms are not affected by the pragma.
4792 -- Such homonyms might be present in the context of other
4793 -- units being compiled.
4797 elsif From_Aspect_Specification (N) then
4801 Hom_Id := Homonym (Hom_Id);
4805 -- When the convention is Java or CIL, we also allow Import to be
4806 -- given for packages, generic packages, exceptions, record
4807 -- components, and access to subprograms.
4809 elsif (C = Convention_Java or else C = Convention_CIL)
4811 (Is_Package_Or_Generic_Package (Def_Id)
4812 or else Ekind (Def_Id) = E_Exception
4813 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4814 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4816 Set_Imported (Def_Id);
4817 Set_Is_Public (Def_Id);
4818 Process_Interface_Name (Def_Id, Arg3, Arg4);
4820 -- Import a CPP class
4822 elsif C = Convention_CPP
4823 and then (Is_Record_Type (Def_Id)
4824 or else Ekind (Def_Id) = E_Incomplete_Type)
4826 if Ekind (Def_Id) = E_Incomplete_Type then
4827 if Present (Full_View (Def_Id)) then
4828 Def_Id := Full_View (Def_Id);
4832 ("cannot import 'C'P'P type before full declaration seen",
4833 Get_Pragma_Arg (Arg2));
4835 -- Although we have reported the error we decorate it as
4836 -- CPP_Class to avoid reporting spurious errors
4838 Set_Is_CPP_Class (Def_Id);
4843 -- Types treated as CPP classes must be declared limited (note:
4844 -- this used to be a warning but there is no real benefit to it
4845 -- since we did effectively intend to treat the type as limited
4848 if not Is_Limited_Type (Def_Id) then
4850 ("imported 'C'P'P type must be limited",
4851 Get_Pragma_Arg (Arg2));
4854 if Etype (Def_Id) /= Def_Id
4855 and then not Is_CPP_Class (Root_Type (Def_Id))
4857 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
4860 Set_Is_CPP_Class (Def_Id);
4862 -- Imported CPP types must not have discriminants (because C++
4863 -- classes do not have discriminants).
4865 if Has_Discriminants (Def_Id) then
4867 ("imported 'C'P'P type cannot have discriminants",
4868 First (Discriminant_Specifications
4869 (Declaration_Node (Def_Id))));
4872 -- Check that components of imported CPP types do not have default
4873 -- expressions. For private types this check is performed when the
4874 -- full view is analyzed (see Process_Full_View).
4876 if not Is_Private_Type (Def_Id) then
4877 Check_CPP_Type_Has_No_Defaults (Def_Id);
4880 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4882 Check_Arg_Count (3);
4883 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4885 Process_Import_Predefined_Type;
4889 ("second argument of pragma% must be object, subprogram "
4890 & "or incomplete type",
4894 -- If this pragma applies to a compilation unit, then the unit, which
4895 -- is a subprogram, does not require (or allow) a body. We also do
4896 -- not need to elaborate imported procedures.
4898 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4900 Cunit : constant Node_Id := Parent (Parent (N));
4902 Set_Body_Required (Cunit, False);
4905 end Process_Import_Or_Interface;
4907 --------------------
4908 -- Process_Inline --
4909 --------------------
4911 procedure Process_Inline (Active : Boolean) is
4918 Effective : Boolean := False;
4919 -- Set True if inline has some effect, i.e. if there is at least one
4920 -- subprogram set as inlined as a result of the use of the pragma.
4922 procedure Make_Inline (Subp : Entity_Id);
4923 -- Subp is the defining unit name of the subprogram declaration. Set
4924 -- the flag, as well as the flag in the corresponding body, if there
4927 procedure Set_Inline_Flags (Subp : Entity_Id);
4928 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4929 -- Has_Pragma_Inline_Always for the Inline_Always case.
4931 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4932 -- Returns True if it can be determined at this stage that inlining
4933 -- is not possible, for example if the body is available and contains
4934 -- exception handlers, we prevent inlining, since otherwise we can
4935 -- get undefined symbols at link time. This function also emits a
4936 -- warning if front-end inlining is enabled and the pragma appears
4939 -- ??? is business with link symbols still valid, or does it relate
4940 -- to front end ZCX which is being phased out ???
4942 ---------------------------
4943 -- Inlining_Not_Possible --
4944 ---------------------------
4946 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4947 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4951 if Nkind (Decl) = N_Subprogram_Body then
4952 Stats := Handled_Statement_Sequence (Decl);
4953 return Present (Exception_Handlers (Stats))
4954 or else Present (At_End_Proc (Stats));
4956 elsif Nkind (Decl) = N_Subprogram_Declaration
4957 and then Present (Corresponding_Body (Decl))
4959 if Front_End_Inlining
4960 and then Analyzed (Corresponding_Body (Decl))
4962 Error_Msg_N ("pragma appears too late, ignored??", N);
4965 -- If the subprogram is a renaming as body, the body is just a
4966 -- call to the renamed subprogram, and inlining is trivially
4970 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4971 N_Subprogram_Renaming_Declaration
4977 Handled_Statement_Sequence
4978 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4981 Present (Exception_Handlers (Stats))
4982 or else Present (At_End_Proc (Stats));
4986 -- If body is not available, assume the best, the check is
4987 -- performed again when compiling enclosing package bodies.
4991 end Inlining_Not_Possible;
4997 procedure Make_Inline (Subp : Entity_Id) is
4998 Kind : constant Entity_Kind := Ekind (Subp);
4999 Inner_Subp : Entity_Id := Subp;
5002 -- Ignore if bad type, avoid cascaded error
5004 if Etype (Subp) = Any_Type then
5008 -- Ignore if all inlining is suppressed
5010 elsif Suppress_All_Inlining then
5014 -- If inlining is not possible, for now do not treat as an error
5016 elsif Inlining_Not_Possible (Subp) then
5020 -- Here we have a candidate for inlining, but we must exclude
5021 -- derived operations. Otherwise we would end up trying to inline
5022 -- a phantom declaration, and the result would be to drag in a
5023 -- body which has no direct inlining associated with it. That
5024 -- would not only be inefficient but would also result in the
5025 -- backend doing cross-unit inlining in cases where it was
5026 -- definitely inappropriate to do so.
5028 -- However, a simple Comes_From_Source test is insufficient, since
5029 -- we do want to allow inlining of generic instances which also do
5030 -- not come from source. We also need to recognize specs generated
5031 -- by the front-end for bodies that carry the pragma. Finally,
5032 -- predefined operators do not come from source but are not
5033 -- inlineable either.
5035 elsif Is_Generic_Instance (Subp)
5036 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
5040 elsif not Comes_From_Source (Subp)
5041 and then Scope (Subp) /= Standard_Standard
5047 -- The referenced entity must either be the enclosing entity, or
5048 -- an entity declared within the current open scope.
5050 if Present (Scope (Subp))
5051 and then Scope (Subp) /= Current_Scope
5052 and then Subp /= Current_Scope
5055 ("argument of% must be entity in current scope", Assoc);
5059 -- Processing for procedure, operator or function. If subprogram
5060 -- is aliased (as for an instance) indicate that the renamed
5061 -- entity (if declared in the same unit) is inlined.
5063 if Is_Subprogram (Subp) then
5064 Inner_Subp := Ultimate_Alias (Inner_Subp);
5066 if In_Same_Source_Unit (Subp, Inner_Subp) then
5067 Set_Inline_Flags (Inner_Subp);
5069 Decl := Parent (Parent (Inner_Subp));
5071 if Nkind (Decl) = N_Subprogram_Declaration
5072 and then Present (Corresponding_Body (Decl))
5074 Set_Inline_Flags (Corresponding_Body (Decl));
5076 elsif Is_Generic_Instance (Subp) then
5078 -- Indicate that the body needs to be created for
5079 -- inlining subsequent calls. The instantiation node
5080 -- follows the declaration of the wrapper package
5083 if Scope (Subp) /= Standard_Standard
5085 Need_Subprogram_Instance_Body
5086 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
5092 -- Inline is a program unit pragma (RM 10.1.5) and cannot
5093 -- appear in a formal part to apply to a formal subprogram.
5094 -- Do not apply check within an instance or a formal package
5095 -- the test will have been applied to the original generic.
5097 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
5098 and then List_Containing (Decl) = List_Containing (N)
5099 and then not In_Instance
5102 ("Inline cannot apply to a formal subprogram", N);
5104 -- If Subp is a renaming, it is the renamed entity that
5105 -- will appear in any call, and be inlined. However, for
5106 -- ASIS uses it is convenient to indicate that the renaming
5107 -- itself is an inlined subprogram, so that some gnatcheck
5108 -- rules can be applied in the absence of expansion.
5110 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
5111 Set_Inline_Flags (Subp);
5117 -- For a generic subprogram set flag as well, for use at the point
5118 -- of instantiation, to determine whether the body should be
5121 elsif Is_Generic_Subprogram (Subp) then
5122 Set_Inline_Flags (Subp);
5125 -- Literals are by definition inlined
5127 elsif Kind = E_Enumeration_Literal then
5130 -- Anything else is an error
5134 ("expect subprogram name for pragma%", Assoc);
5138 ----------------------
5139 -- Set_Inline_Flags --
5140 ----------------------
5142 procedure Set_Inline_Flags (Subp : Entity_Id) is
5145 Set_Is_Inlined (Subp);
5148 if not Has_Pragma_Inline (Subp) then
5149 Set_Has_Pragma_Inline (Subp);
5153 if Prag_Id = Pragma_Inline_Always then
5154 Set_Has_Pragma_Inline_Always (Subp);
5156 end Set_Inline_Flags;
5158 -- Start of processing for Process_Inline
5161 Check_No_Identifiers;
5162 Check_At_Least_N_Arguments (1);
5165 Inline_Processing_Required := True;
5169 while Present (Assoc) loop
5170 Subp_Id := Get_Pragma_Arg (Assoc);
5174 if Is_Entity_Name (Subp_Id) then
5175 Subp := Entity (Subp_Id);
5177 if Subp = Any_Id then
5179 -- If previous error, avoid cascaded errors
5181 Check_Error_Detected;
5188 -- For the pragma case, climb homonym chain. This is
5189 -- what implements allowing the pragma in the renaming
5190 -- case, with the result applying to the ancestors, and
5191 -- also allows Inline to apply to all previous homonyms.
5193 if not From_Aspect_Specification (N) then
5194 while Present (Homonym (Subp))
5195 and then Scope (Homonym (Subp)) = Current_Scope
5197 Make_Inline (Homonym (Subp));
5198 Subp := Homonym (Subp);
5206 ("inappropriate argument for pragma%", Assoc);
5209 and then Warn_On_Redundant_Constructs
5210 and then not Suppress_All_Inlining
5212 if Inlining_Not_Possible (Subp) then
5214 ("pragma Inline for& is ignored?r?",
5215 N, Entity (Subp_Id));
5218 ("pragma Inline for& is redundant?r?",
5219 N, Entity (Subp_Id));
5227 ----------------------------
5228 -- Process_Interface_Name --
5229 ----------------------------
5231 procedure Process_Interface_Name
5232 (Subprogram_Def : Entity_Id;
5238 String_Val : String_Id;
5240 procedure Check_Form_Of_Interface_Name
5242 Ext_Name_Case : Boolean);
5243 -- SN is a string literal node for an interface name. This routine
5244 -- performs some minimal checks that the name is reasonable. In
5245 -- particular that no spaces or other obviously incorrect characters
5246 -- appear. This is only a warning, since any characters are allowed.
5247 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5249 ----------------------------------
5250 -- Check_Form_Of_Interface_Name --
5251 ----------------------------------
5253 procedure Check_Form_Of_Interface_Name
5255 Ext_Name_Case : Boolean)
5257 S : constant String_Id := Strval (Expr_Value_S (SN));
5258 SL : constant Nat := String_Length (S);
5263 Error_Msg_N ("interface name cannot be null string", SN);
5266 for J in 1 .. SL loop
5267 C := Get_String_Char (S, J);
5269 -- Look for dubious character and issue unconditional warning.
5270 -- Definitely dubious if not in character range.
5272 if not In_Character_Range (C)
5274 -- For all cases except CLI target,
5275 -- commas, spaces and slashes are dubious (in CLI, we use
5276 -- commas and backslashes in external names to specify
5277 -- assembly version and public key, while slashes and spaces
5278 -- can be used in names to mark nested classes and
5281 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5282 and then (Get_Character (C) = ','
5284 Get_Character (C) = '\'))
5285 or else (VM_Target /= CLI_Target
5286 and then (Get_Character (C) = ' '
5288 Get_Character (C) = '/'))
5291 ("??interface name contains illegal character",
5292 Sloc (SN) + Source_Ptr (J));
5295 end Check_Form_Of_Interface_Name;
5297 -- Start of processing for Process_Interface_Name
5300 if No (Link_Arg) then
5301 if No (Ext_Arg) then
5302 if VM_Target = CLI_Target
5303 and then Ekind (Subprogram_Def) = E_Package
5304 and then Nkind (Parent (Subprogram_Def)) =
5305 N_Package_Specification
5306 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5311 (Generic_Parent (Parent (Subprogram_Def))));
5316 elsif Chars (Ext_Arg) = Name_Link_Name then
5318 Link_Nam := Expression (Ext_Arg);
5321 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5322 Ext_Nam := Expression (Ext_Arg);
5327 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5328 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5329 Ext_Nam := Expression (Ext_Arg);
5330 Link_Nam := Expression (Link_Arg);
5333 -- Check expressions for external name and link name are static
5335 if Present (Ext_Nam) then
5336 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5337 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5339 -- Verify that external name is not the name of a local entity,
5340 -- which would hide the imported one and could lead to run-time
5341 -- surprises. The problem can only arise for entities declared in
5342 -- a package body (otherwise the external name is fully qualified
5343 -- and will not conflict).
5351 if Prag_Id = Pragma_Import then
5352 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5354 E := Entity_Id (Get_Name_Table_Info (Nam));
5356 if Nam /= Chars (Subprogram_Def)
5357 and then Present (E)
5358 and then not Is_Overloadable (E)
5359 and then Is_Immediately_Visible (E)
5360 and then not Is_Imported (E)
5361 and then Ekind (Scope (E)) = E_Package
5364 while Present (Par) loop
5365 if Nkind (Par) = N_Package_Body then
5366 Error_Msg_Sloc := Sloc (E);
5368 ("imported entity is hidden by & declared#",
5373 Par := Parent (Par);
5380 if Present (Link_Nam) then
5381 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5382 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5385 -- If there is no link name, just set the external name
5387 if No (Link_Nam) then
5388 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5390 -- For the Link_Name case, the given literal is preceded by an
5391 -- asterisk, which indicates to GCC that the given name should be
5392 -- taken literally, and in particular that no prepending of
5393 -- underlines should occur, even in systems where this is the
5399 if VM_Target = No_VM then
5400 Store_String_Char (Get_Char_Code ('*'));
5403 String_Val := Strval (Expr_Value_S (Link_Nam));
5404 Store_String_Chars (String_Val);
5406 Make_String_Literal (Sloc (Link_Nam),
5407 Strval => End_String);
5410 -- Set the interface name. If the entity is a generic instance, use
5411 -- its alias, which is the callable entity.
5413 if Is_Generic_Instance (Subprogram_Def) then
5414 Set_Encoded_Interface_Name
5415 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5417 Set_Encoded_Interface_Name
5418 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5421 -- We allow duplicated export names in CIL/Java, as they are always
5422 -- enclosed in a namespace that differentiates them, and overloaded
5423 -- entities are supported by the VM.
5425 if Convention (Subprogram_Def) /= Convention_CIL
5427 Convention (Subprogram_Def) /= Convention_Java
5429 Check_Duplicated_Export_Name (Link_Nam);
5431 end Process_Interface_Name;
5433 -----------------------------------------
5434 -- Process_Interrupt_Or_Attach_Handler --
5435 -----------------------------------------
5437 procedure Process_Interrupt_Or_Attach_Handler is
5438 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5439 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5440 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5443 Set_Is_Interrupt_Handler (Handler_Proc);
5445 -- If the pragma is not associated with a handler procedure within a
5446 -- protected type, then it must be for a nonprotected procedure for
5447 -- the AAMP target, in which case we don't associate a representation
5448 -- item with the procedure's scope.
5450 if Ekind (Proc_Scope) = E_Protected_Type then
5451 if Prag_Id = Pragma_Interrupt_Handler
5453 Prag_Id = Pragma_Attach_Handler
5455 Record_Rep_Item (Proc_Scope, N);
5458 end Process_Interrupt_Or_Attach_Handler;
5460 --------------------------------------------------
5461 -- Process_Restrictions_Or_Restriction_Warnings --
5462 --------------------------------------------------
5464 -- Note: some of the simple identifier cases were handled in par-prag,
5465 -- but it is harmless (and more straightforward) to simply handle all
5466 -- cases here, even if it means we repeat a bit of work in some cases.
5468 procedure Process_Restrictions_Or_Restriction_Warnings
5472 R_Id : Restriction_Id;
5477 procedure Check_Unit_Name (N : Node_Id);
5478 -- Checks unit name parameter for No_Dependence. Returns if it has
5479 -- an appropriate form, otherwise raises pragma argument error.
5481 ---------------------
5482 -- Check_Unit_Name --
5483 ---------------------
5485 procedure Check_Unit_Name (N : Node_Id) is
5487 if Nkind (N) = N_Selected_Component then
5488 Check_Unit_Name (Prefix (N));
5489 Check_Unit_Name (Selector_Name (N));
5491 elsif Nkind (N) = N_Identifier then
5496 ("wrong form for unit name for No_Dependence", N);
5498 end Check_Unit_Name;
5500 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5503 -- Ignore all Restrictions pragma in CodePeer mode
5505 if CodePeer_Mode then
5509 Check_Ada_83_Warning;
5510 Check_At_Least_N_Arguments (1);
5511 Check_Valid_Configuration_Pragma;
5514 while Present (Arg) loop
5516 Expr := Get_Pragma_Arg (Arg);
5518 -- Case of no restriction identifier present
5520 if Id = No_Name then
5521 if Nkind (Expr) /= N_Identifier then
5523 ("invalid form for restriction", Arg);
5528 (Process_Restriction_Synonyms (Expr));
5530 if R_Id not in All_Boolean_Restrictions then
5531 Error_Msg_Name_1 := Pname;
5533 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5535 -- Check for possible misspelling
5537 for J in Restriction_Id loop
5539 Rnm : constant String := Restriction_Id'Image (J);
5542 Name_Buffer (1 .. Rnm'Length) := Rnm;
5543 Name_Len := Rnm'Length;
5544 Set_Casing (All_Lower_Case);
5546 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5548 (Identifier_Casing (Current_Source_File));
5549 Error_Msg_String (1 .. Rnm'Length) :=
5550 Name_Buffer (1 .. Name_Len);
5551 Error_Msg_Strlen := Rnm'Length;
5552 Error_Msg_N -- CODEFIX
5553 ("\possible misspelling of ""~""",
5554 Get_Pragma_Arg (Arg));
5563 if Implementation_Restriction (R_Id) then
5564 Check_Restriction (No_Implementation_Restrictions, Arg);
5567 -- Special processing for No_Elaboration_Code restriction
5569 if R_Id = No_Elaboration_Code then
5571 -- Restriction is only recognized within a configuration
5572 -- pragma file, or within a unit of the main extended
5573 -- program. Note: the test for Main_Unit is needed to
5574 -- properly include the case of configuration pragma files.
5576 if not (Current_Sem_Unit = Main_Unit
5577 or else In_Extended_Main_Source_Unit (N))
5581 -- Don't allow in a subunit unless already specified in
5584 elsif Nkind (Parent (N)) = N_Compilation_Unit
5585 and then Nkind (Unit (Parent (N))) = N_Subunit
5586 and then not Restriction_Active (No_Elaboration_Code)
5589 ("invalid specification of ""No_Elaboration_Code""",
5592 ("\restriction cannot be specified in a subunit", N);
5594 ("\unless also specified in body or spec", N);
5597 -- If we have a No_Elaboration_Code pragma that we
5598 -- accept, then it needs to be added to the configuration
5599 -- restrcition set so that we get proper application to
5600 -- other units in the main extended source as required.
5603 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
5607 -- If this is a warning, then set the warning unless we already
5608 -- have a real restriction active (we never want a warning to
5609 -- override a real restriction).
5612 if not Restriction_Active (R_Id) then
5613 Set_Restriction (R_Id, N);
5614 Restriction_Warnings (R_Id) := True;
5617 -- If real restriction case, then set it and make sure that the
5618 -- restriction warning flag is off, since a real restriction
5619 -- always overrides a warning.
5622 Set_Restriction (R_Id, N);
5623 Restriction_Warnings (R_Id) := False;
5626 -- Check for obsolescent restrictions in Ada 2005 mode
5629 and then Ada_Version >= Ada_2005
5630 and then (R_Id = No_Asynchronous_Control
5632 R_Id = No_Unchecked_Deallocation
5634 R_Id = No_Unchecked_Conversion)
5636 Check_Restriction (No_Obsolescent_Features, N);
5639 -- A very special case that must be processed here: pragma
5640 -- Restrictions (No_Exceptions) turns off all run-time
5641 -- checking. This is a bit dubious in terms of the formal
5642 -- language definition, but it is what is intended by RM
5643 -- H.4(12). Restriction_Warnings never affects generated code
5644 -- so this is done only in the real restriction case.
5646 -- Atomic_Synchronization is not a real check, so it is not
5647 -- affected by this processing).
5649 if R_Id = No_Exceptions and then not Warn then
5650 for J in Scope_Suppress.Suppress'Range loop
5651 if J /= Atomic_Synchronization then
5652 Scope_Suppress.Suppress (J) := True;
5657 -- Case of No_Dependence => unit-name. Note that the parser
5658 -- already made the necessary entry in the No_Dependence table.
5660 elsif Id = Name_No_Dependence then
5661 Check_Unit_Name (Expr);
5663 -- Case of No_Specification_Of_Aspect => Identifier.
5665 elsif Id = Name_No_Specification_Of_Aspect then
5670 if Nkind (Expr) /= N_Identifier then
5673 A_Id := Get_Aspect_Id (Chars (Expr));
5676 if A_Id = No_Aspect then
5677 Error_Pragma_Arg ("invalid restriction name", Arg);
5679 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5683 -- All other cases of restriction identifier present
5686 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5687 Analyze_And_Resolve (Expr, Any_Integer);
5689 if R_Id not in All_Parameter_Restrictions then
5691 ("invalid restriction parameter identifier", Arg);
5693 elsif not Is_OK_Static_Expression (Expr) then
5694 Flag_Non_Static_Expr
5695 ("value must be static expression!", Expr);
5698 elsif not Is_Integer_Type (Etype (Expr))
5699 or else Expr_Value (Expr) < 0
5702 ("value must be non-negative integer", Arg);
5705 -- Restriction pragma is active
5707 Val := Expr_Value (Expr);
5709 if not UI_Is_In_Int_Range (Val) then
5711 ("pragma ignored, value too large??", Arg);
5714 -- Warning case. If the real restriction is active, then we
5715 -- ignore the request, since warning never overrides a real
5716 -- restriction. Otherwise we set the proper warning. Note that
5717 -- this circuit sets the warning again if it is already set,
5718 -- which is what we want, since the constant may have changed.
5721 if not Restriction_Active (R_Id) then
5723 (R_Id, N, Integer (UI_To_Int (Val)));
5724 Restriction_Warnings (R_Id) := True;
5727 -- Real restriction case, set restriction and make sure warning
5728 -- flag is off since real restriction always overrides warning.
5731 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5732 Restriction_Warnings (R_Id) := False;
5738 end Process_Restrictions_Or_Restriction_Warnings;
5740 ---------------------------------
5741 -- Process_Suppress_Unsuppress --
5742 ---------------------------------
5744 -- Note: this procedure makes entries in the check suppress data
5745 -- structures managed by Sem. See spec of package Sem for full
5746 -- details on how we handle recording of check suppression.
5748 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5753 In_Package_Spec : constant Boolean :=
5754 Is_Package_Or_Generic_Package (Current_Scope)
5755 and then not In_Package_Body (Current_Scope);
5757 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5758 -- Used to suppress a single check on the given entity
5760 --------------------------------
5761 -- Suppress_Unsuppress_Echeck --
5762 --------------------------------
5764 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5766 -- Check for error of trying to set atomic synchronization for
5767 -- a non-atomic variable.
5769 if C = Atomic_Synchronization
5770 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5773 ("pragma & requires atomic type or variable",
5774 Pragma_Identifier (Original_Node (N)));
5777 Set_Checks_May_Be_Suppressed (E);
5779 if In_Package_Spec then
5780 Push_Global_Suppress_Stack_Entry
5783 Suppress => Suppress_Case);
5785 Push_Local_Suppress_Stack_Entry
5788 Suppress => Suppress_Case);
5791 -- If this is a first subtype, and the base type is distinct,
5792 -- then also set the suppress flags on the base type.
5794 if Is_First_Subtype (E) and then Etype (E) /= E then
5795 Suppress_Unsuppress_Echeck (Etype (E), C);
5797 end Suppress_Unsuppress_Echeck;
5799 -- Start of processing for Process_Suppress_Unsuppress
5802 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5803 -- user code: we want to generate checks for analysis purposes, as
5804 -- set respectively by -gnatC and -gnatd.F
5806 if (CodePeer_Mode or Alfa_Mode) and then Comes_From_Source (N) then
5810 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5811 -- declarative part or a package spec (RM 11.5(5)).
5813 if not Is_Configuration_Pragma then
5814 Check_Is_In_Decl_Part_Or_Package_Spec;
5817 Check_At_Least_N_Arguments (1);
5818 Check_At_Most_N_Arguments (2);
5819 Check_No_Identifier (Arg1);
5820 Check_Arg_Is_Identifier (Arg1);
5822 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5824 if C = No_Check_Id then
5826 ("argument of pragma% is not valid check name", Arg1);
5829 if Arg_Count = 1 then
5831 -- Make an entry in the local scope suppress table. This is the
5832 -- table that directly shows the current value of the scope
5833 -- suppress check for any check id value.
5835 if C = All_Checks then
5837 -- For All_Checks, we set all specific predefined checks with
5838 -- the exception of Elaboration_Check, which is handled
5839 -- specially because of not wanting All_Checks to have the
5840 -- effect of deactivating static elaboration order processing.
5841 -- Atomic_Synchronization is also not affected, since this is
5842 -- not a real check.
5844 for J in Scope_Suppress.Suppress'Range loop
5845 if J /= Elaboration_Check
5847 J /= Atomic_Synchronization
5849 Scope_Suppress.Suppress (J) := Suppress_Case;
5853 -- If not All_Checks, and predefined check, then set appropriate
5854 -- scope entry. Note that we will set Elaboration_Check if this
5855 -- is explicitly specified. Atomic_Synchronization is allowed
5856 -- only if internally generated and entity is atomic.
5858 elsif C in Predefined_Check_Id
5859 and then (not Comes_From_Source (N)
5860 or else C /= Atomic_Synchronization)
5862 Scope_Suppress.Suppress (C) := Suppress_Case;
5865 -- Also make an entry in the Local_Entity_Suppress table
5867 Push_Local_Suppress_Stack_Entry
5870 Suppress => Suppress_Case);
5872 -- Case of two arguments present, where the check is suppressed for
5873 -- a specified entity (given as the second argument of the pragma)
5876 -- This is obsolescent in Ada 2005 mode
5878 if Ada_Version >= Ada_2005 then
5879 Check_Restriction (No_Obsolescent_Features, Arg2);
5882 Check_Optional_Identifier (Arg2, Name_On);
5883 E_Id := Get_Pragma_Arg (Arg2);
5886 if not Is_Entity_Name (E_Id) then
5888 ("second argument of pragma% must be entity name", Arg2);
5897 -- Enforce RM 11.5(7) which requires that for a pragma that
5898 -- appears within a package spec, the named entity must be
5899 -- within the package spec. We allow the package name itself
5900 -- to be mentioned since that makes sense, although it is not
5901 -- strictly allowed by 11.5(7).
5904 and then E /= Current_Scope
5905 and then Scope (E) /= Current_Scope
5908 ("entity in pragma% is not in package spec (RM 11.5(7))",
5912 -- Loop through homonyms. As noted below, in the case of a package
5913 -- spec, only homonyms within the package spec are considered.
5916 Suppress_Unsuppress_Echeck (E, C);
5918 if Is_Generic_Instance (E)
5919 and then Is_Subprogram (E)
5920 and then Present (Alias (E))
5922 Suppress_Unsuppress_Echeck (Alias (E), C);
5925 -- Move to next homonym if not aspect spec case
5927 exit when From_Aspect_Specification (N);
5931 -- If we are within a package specification, the pragma only
5932 -- applies to homonyms in the same scope.
5934 exit when In_Package_Spec
5935 and then Scope (E) /= Current_Scope;
5938 end Process_Suppress_Unsuppress;
5944 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5946 if Is_Imported (E) then
5948 ("cannot export entity& that was previously imported", Arg);
5950 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5952 ("cannot export entity& that has an address clause", Arg);
5955 Set_Is_Exported (E);
5957 -- Generate a reference for entity explicitly, because the
5958 -- identifier may be overloaded and name resolution will not
5961 Generate_Reference (E, Arg);
5963 -- Deal with exporting non-library level entity
5965 if not Is_Library_Level_Entity (E) then
5967 -- Not allowed at all for subprograms
5969 if Is_Subprogram (E) then
5970 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5972 -- Otherwise set public and statically allocated
5976 Set_Is_Statically_Allocated (E);
5978 -- Warn if the corresponding W flag is set and the pragma comes
5979 -- from source. The latter may not be true e.g. on VMS where we
5980 -- expand export pragmas for exception codes associated with
5981 -- imported or exported exceptions. We do not want to generate
5982 -- a warning for something that the user did not write.
5984 if Warn_On_Export_Import
5985 and then Comes_From_Source (Arg)
5988 ("?x?& has been made static as a result of Export",
5991 ("\?x?this usage is non-standard and non-portable",
5997 if Warn_On_Export_Import and then Is_Type (E) then
5998 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
6001 if Warn_On_Export_Import and Inside_A_Generic then
6003 ("all instances of& will have the same external name?x?",
6008 ----------------------------------------------
6009 -- Set_Extended_Import_Export_External_Name --
6010 ----------------------------------------------
6012 procedure Set_Extended_Import_Export_External_Name
6013 (Internal_Ent : Entity_Id;
6014 Arg_External : Node_Id)
6016 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
6020 if No (Arg_External) then
6024 Check_Arg_Is_External_Name (Arg_External);
6026 if Nkind (Arg_External) = N_String_Literal then
6027 if String_Length (Strval (Arg_External)) = 0 then
6030 New_Name := Adjust_External_Name_Case (Arg_External);
6033 elsif Nkind (Arg_External) = N_Identifier then
6034 New_Name := Get_Default_External_Name (Arg_External);
6036 -- Check_Arg_Is_External_Name should let through only identifiers and
6037 -- string literals or static string expressions (which are folded to
6038 -- string literals).
6041 raise Program_Error;
6044 -- If we already have an external name set (by a prior normal Import
6045 -- or Export pragma), then the external names must match
6047 if Present (Interface_Name (Internal_Ent)) then
6048 Check_Matching_Internal_Names : declare
6049 S1 : constant String_Id := Strval (Old_Name);
6050 S2 : constant String_Id := Strval (New_Name);
6053 pragma No_Return (Mismatch);
6054 -- Called if names do not match
6060 procedure Mismatch is
6062 Error_Msg_Sloc := Sloc (Old_Name);
6064 ("external name does not match that given #",
6068 -- Start of processing for Check_Matching_Internal_Names
6071 if String_Length (S1) /= String_Length (S2) then
6075 for J in 1 .. String_Length (S1) loop
6076 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
6081 end Check_Matching_Internal_Names;
6083 -- Otherwise set the given name
6086 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
6087 Check_Duplicated_Export_Name (New_Name);
6089 end Set_Extended_Import_Export_External_Name;
6095 procedure Set_Imported (E : Entity_Id) is
6097 -- Error message if already imported or exported
6099 if Is_Exported (E) or else Is_Imported (E) then
6101 -- Error if being set Exported twice
6103 if Is_Exported (E) then
6104 Error_Msg_NE ("entity& was previously exported", N, E);
6106 -- OK if Import/Interface case
6108 elsif Import_Interface_Present (N) then
6111 -- Error if being set Imported twice
6114 Error_Msg_NE ("entity& was previously imported", N, E);
6117 Error_Msg_Name_1 := Pname;
6119 ("\(pragma% applies to all previous entities)", N);
6121 Error_Msg_Sloc := Sloc (E);
6122 Error_Msg_NE ("\import not allowed for& declared#", N, E);
6124 -- Here if not previously imported or exported, OK to import
6127 Set_Is_Imported (E);
6129 -- If the entity is an object that is not at the library level,
6130 -- then it is statically allocated. We do not worry about objects
6131 -- with address clauses in this context since they are not really
6132 -- imported in the linker sense.
6135 and then not Is_Library_Level_Entity (E)
6136 and then No (Address_Clause (E))
6138 Set_Is_Statically_Allocated (E);
6145 -------------------------
6146 -- Set_Mechanism_Value --
6147 -------------------------
6149 -- Note: the mechanism name has not been analyzed (and cannot indeed be
6150 -- analyzed, since it is semantic nonsense), so we get it in the exact
6151 -- form created by the parser.
6153 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
6156 Mech_Name_Id : Name_Id;
6158 procedure Bad_Class;
6159 pragma No_Return (Bad_Class);
6160 -- Signal bad descriptor class name
6162 procedure Bad_Mechanism;
6163 pragma No_Return (Bad_Mechanism);
6164 -- Signal bad mechanism name
6170 procedure Bad_Class is
6172 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
6175 -------------------------
6176 -- Bad_Mechanism_Value --
6177 -------------------------
6179 procedure Bad_Mechanism is
6181 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
6184 -- Start of processing for Set_Mechanism_Value
6187 if Mechanism (Ent) /= Default_Mechanism then
6189 ("mechanism for & has already been set", Mech_Name, Ent);
6192 -- MECHANISM_NAME ::= value | reference | descriptor |
6195 if Nkind (Mech_Name) = N_Identifier then
6196 if Chars (Mech_Name) = Name_Value then
6197 Set_Mechanism (Ent, By_Copy);
6200 elsif Chars (Mech_Name) = Name_Reference then
6201 Set_Mechanism (Ent, By_Reference);
6204 elsif Chars (Mech_Name) = Name_Descriptor then
6205 Check_VMS (Mech_Name);
6207 -- Descriptor => Short_Descriptor if pragma was given
6209 if Short_Descriptors then
6210 Set_Mechanism (Ent, By_Short_Descriptor);
6212 Set_Mechanism (Ent, By_Descriptor);
6217 elsif Chars (Mech_Name) = Name_Short_Descriptor then
6218 Check_VMS (Mech_Name);
6219 Set_Mechanism (Ent, By_Short_Descriptor);
6222 elsif Chars (Mech_Name) = Name_Copy then
6224 ("bad mechanism name, Value assumed", Mech_Name);
6230 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
6231 -- short_descriptor (CLASS_NAME)
6232 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6234 -- Note: this form is parsed as an indexed component
6236 elsif Nkind (Mech_Name) = N_Indexed_Component then
6237 Class := First (Expressions (Mech_Name));
6239 if Nkind (Prefix (Mech_Name)) /= N_Identifier
6240 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
6241 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
6242 or else Present (Next (Class))
6246 Mech_Name_Id := Chars (Prefix (Mech_Name));
6248 -- Change Descriptor => Short_Descriptor if pragma was given
6250 if Mech_Name_Id = Name_Descriptor
6251 and then Short_Descriptors
6253 Mech_Name_Id := Name_Short_Descriptor;
6257 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6258 -- short_descriptor (Class => CLASS_NAME)
6259 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6261 -- Note: this form is parsed as a function call
6263 elsif Nkind (Mech_Name) = N_Function_Call then
6264 Param := First (Parameter_Associations (Mech_Name));
6266 if Nkind (Name (Mech_Name)) /= N_Identifier
6267 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6268 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6269 or else Present (Next (Param))
6270 or else No (Selector_Name (Param))
6271 or else Chars (Selector_Name (Param)) /= Name_Class
6275 Class := Explicit_Actual_Parameter (Param);
6276 Mech_Name_Id := Chars (Name (Mech_Name));
6283 -- Fall through here with Class set to descriptor class name
6285 Check_VMS (Mech_Name);
6287 if Nkind (Class) /= N_Identifier then
6290 elsif Mech_Name_Id = Name_Descriptor
6291 and then Chars (Class) = Name_UBS
6293 Set_Mechanism (Ent, By_Descriptor_UBS);
6295 elsif Mech_Name_Id = Name_Descriptor
6296 and then Chars (Class) = Name_UBSB
6298 Set_Mechanism (Ent, By_Descriptor_UBSB);
6300 elsif Mech_Name_Id = Name_Descriptor
6301 and then Chars (Class) = Name_UBA
6303 Set_Mechanism (Ent, By_Descriptor_UBA);
6305 elsif Mech_Name_Id = Name_Descriptor
6306 and then Chars (Class) = Name_S
6308 Set_Mechanism (Ent, By_Descriptor_S);
6310 elsif Mech_Name_Id = Name_Descriptor
6311 and then Chars (Class) = Name_SB
6313 Set_Mechanism (Ent, By_Descriptor_SB);
6315 elsif Mech_Name_Id = Name_Descriptor
6316 and then Chars (Class) = Name_A
6318 Set_Mechanism (Ent, By_Descriptor_A);
6320 elsif Mech_Name_Id = Name_Descriptor
6321 and then Chars (Class) = Name_NCA
6323 Set_Mechanism (Ent, By_Descriptor_NCA);
6325 elsif Mech_Name_Id = Name_Short_Descriptor
6326 and then Chars (Class) = Name_UBS
6328 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6330 elsif Mech_Name_Id = Name_Short_Descriptor
6331 and then Chars (Class) = Name_UBSB
6333 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6335 elsif Mech_Name_Id = Name_Short_Descriptor
6336 and then Chars (Class) = Name_UBA
6338 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6340 elsif Mech_Name_Id = Name_Short_Descriptor
6341 and then Chars (Class) = Name_S
6343 Set_Mechanism (Ent, By_Short_Descriptor_S);
6345 elsif Mech_Name_Id = Name_Short_Descriptor
6346 and then Chars (Class) = Name_SB
6348 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6350 elsif Mech_Name_Id = Name_Short_Descriptor
6351 and then Chars (Class) = Name_A
6353 Set_Mechanism (Ent, By_Short_Descriptor_A);
6355 elsif Mech_Name_Id = Name_Short_Descriptor
6356 and then Chars (Class) = Name_NCA
6358 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6363 end Set_Mechanism_Value;
6365 ---------------------------
6366 -- Set_Ravenscar_Profile --
6367 ---------------------------
6369 -- The tasks to be done here are
6371 -- Set required policies
6373 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6374 -- pragma Locking_Policy (Ceiling_Locking)
6376 -- Set Detect_Blocking mode
6378 -- Set required restrictions (see System.Rident for detailed list)
6380 -- Set the No_Dependence rules
6381 -- No_Dependence => Ada.Asynchronous_Task_Control
6382 -- No_Dependence => Ada.Calendar
6383 -- No_Dependence => Ada.Execution_Time.Group_Budget
6384 -- No_Dependence => Ada.Execution_Time.Timers
6385 -- No_Dependence => Ada.Task_Attributes
6386 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6388 procedure Set_Ravenscar_Profile (N : Node_Id) is
6389 Prefix_Entity : Entity_Id;
6390 Selector_Entity : Entity_Id;
6391 Prefix_Node : Node_Id;
6395 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6397 if Task_Dispatching_Policy /= ' '
6398 and then Task_Dispatching_Policy /= 'F'
6400 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6401 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6403 -- Set the FIFO_Within_Priorities policy, but always preserve
6404 -- System_Location since we like the error message with the run time
6408 Task_Dispatching_Policy := 'F';
6410 if Task_Dispatching_Policy_Sloc /= System_Location then
6411 Task_Dispatching_Policy_Sloc := Loc;
6415 -- pragma Locking_Policy (Ceiling_Locking)
6417 if Locking_Policy /= ' '
6418 and then Locking_Policy /= 'C'
6420 Error_Msg_Sloc := Locking_Policy_Sloc;
6421 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6423 -- Set the Ceiling_Locking policy, but preserve System_Location since
6424 -- we like the error message with the run time name.
6427 Locking_Policy := 'C';
6429 if Locking_Policy_Sloc /= System_Location then
6430 Locking_Policy_Sloc := Loc;
6434 -- pragma Detect_Blocking
6436 Detect_Blocking := True;
6438 -- Set the corresponding restrictions
6440 Set_Profile_Restrictions
6441 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6443 -- Set the No_Dependence restrictions
6445 -- The following No_Dependence restrictions:
6446 -- No_Dependence => Ada.Asynchronous_Task_Control
6447 -- No_Dependence => Ada.Calendar
6448 -- No_Dependence => Ada.Task_Attributes
6449 -- are already set by previous call to Set_Profile_Restrictions.
6451 -- Set the following restrictions which were added to Ada 2005:
6452 -- No_Dependence => Ada.Execution_Time.Group_Budget
6453 -- No_Dependence => Ada.Execution_Time.Timers
6455 if Ada_Version >= Ada_2005 then
6456 Name_Buffer (1 .. 3) := "ada";
6459 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6461 Name_Buffer (1 .. 14) := "execution_time";
6464 Selector_Entity := Make_Identifier (Loc, Name_Find);
6467 Make_Selected_Component
6469 Prefix => Prefix_Entity,
6470 Selector_Name => Selector_Entity);
6472 Name_Buffer (1 .. 13) := "group_budgets";
6475 Selector_Entity := Make_Identifier (Loc, Name_Find);
6478 Make_Selected_Component
6480 Prefix => Prefix_Node,
6481 Selector_Name => Selector_Entity);
6483 Set_Restriction_No_Dependence
6485 Warn => Treat_Restrictions_As_Warnings,
6486 Profile => Ravenscar);
6488 Name_Buffer (1 .. 6) := "timers";
6491 Selector_Entity := Make_Identifier (Loc, Name_Find);
6494 Make_Selected_Component
6496 Prefix => Prefix_Node,
6497 Selector_Name => Selector_Entity);
6499 Set_Restriction_No_Dependence
6501 Warn => Treat_Restrictions_As_Warnings,
6502 Profile => Ravenscar);
6505 -- Set the following restrictions which was added to Ada 2012 (see
6507 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6509 if Ada_Version >= Ada_2012 then
6510 Name_Buffer (1 .. 6) := "system";
6513 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6515 Name_Buffer (1 .. 15) := "multiprocessors";
6518 Selector_Entity := Make_Identifier (Loc, Name_Find);
6521 Make_Selected_Component
6523 Prefix => Prefix_Entity,
6524 Selector_Name => Selector_Entity);
6526 Name_Buffer (1 .. 19) := "dispatching_domains";
6529 Selector_Entity := Make_Identifier (Loc, Name_Find);
6532 Make_Selected_Component
6534 Prefix => Prefix_Node,
6535 Selector_Name => Selector_Entity);
6537 Set_Restriction_No_Dependence
6539 Warn => Treat_Restrictions_As_Warnings,
6540 Profile => Ravenscar);
6542 end Set_Ravenscar_Profile;
6548 procedure S14_Pragma is
6550 if not Formal_Extensions then
6551 Error_Pragma ("pragma% requires the use of debug switch -gnatd.V");
6555 -- Start of processing for Analyze_Pragma
6558 -- The following code is a defense against recursion. Not clear that
6559 -- this can happen legitimately, but perhaps some error situations
6560 -- can cause it, and we did see this recursion during testing.
6562 if Analyzed (N) then
6565 Set_Analyzed (N, True);
6568 -- Deal with unrecognized pragma
6570 Pname := Pragma_Name (N);
6572 if not Is_Pragma_Name (Pname) then
6573 if Warn_On_Unrecognized_Pragma then
6574 Error_Msg_Name_1 := Pname;
6575 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
6577 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6578 if Is_Bad_Spelling_Of (Pname, PN) then
6579 Error_Msg_Name_1 := PN;
6580 Error_Msg_N -- CODEFIX
6581 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
6590 -- Here to start processing for recognized pragma
6592 Prag_Id := Get_Pragma_Id (Pname);
6594 if Present (Corresponding_Aspect (N)) then
6595 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6606 if Present (Pragma_Argument_Associations (N)) then
6607 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6608 Arg1 := First (Pragma_Argument_Associations (N));
6610 if Present (Arg1) then
6611 Arg2 := Next (Arg1);
6613 if Present (Arg2) then
6614 Arg3 := Next (Arg2);
6616 if Present (Arg3) then
6617 Arg4 := Next (Arg3);
6623 -- An enumeration type defines the pragmas that are supported by the
6624 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6625 -- into the corresponding enumeration value for the following case.
6633 -- pragma Abort_Defer;
6635 when Pragma_Abort_Defer =>
6637 Check_Arg_Count (0);
6639 -- The only required semantic processing is to check the
6640 -- placement. This pragma must appear at the start of the
6641 -- statement sequence of a handled sequence of statements.
6643 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6644 or else N /= First (Statements (Parent (N)))
6649 --------------------
6650 -- Abstract_State --
6651 --------------------
6653 -- pragma Abstract_State (ABSTRACT_STATE_LIST)
6655 -- ABSTRACT_STATE_LIST ::=
6657 -- | STATE_NAME_WITH_PROPERTIES {, STATE_NAME_WITH_PROPERTIES}
6659 -- STATE_NAME_WITH_PROPERTIES ::=
6661 -- | (STATE_NAME with PROPERTY_LIST)
6663 -- PROPERTY_LIST ::= PROPERTY {, PROPERTY}
6664 -- PROPERTY ::= SIMPLE_PROPERTY
6665 -- | NAME_VALUE_PROPERTY
6666 -- SIMPLE_PROPERTY ::= IDENTIFIER
6667 -- NAME_VALUE_PROPERTY ::= IDENTIFIER => EXPRESSION
6668 -- STATE_NAME ::= DEFINING_IDENTIFIER
6670 when Pragma_Abstract_State => Abstract_State : declare
6671 Pack_Id : Entity_Id;
6673 -- Flags used to verify the consistency of states
6675 Non_Null_Seen : Boolean := False;
6676 Null_Seen : Boolean := False;
6678 procedure Analyze_Abstract_State (State : Node_Id);
6679 -- Verify the legality of a single state declaration. Create and
6680 -- decorate a state abstraction entity and introduce it into the
6681 -- visibility chain.
6683 ----------------------------
6684 -- Analyze_Abstract_State --
6685 ----------------------------
6687 procedure Analyze_Abstract_State (State : Node_Id) is
6688 procedure Check_Duplicate_Property
6690 Status : in out Boolean);
6691 -- Flag Status denotes whether a particular property has been
6692 -- seen while processing a state. This routine verifies that
6693 -- Prop is not a duplicate property and sets the flag Status.
6695 ------------------------------
6696 -- Check_Duplicate_Property --
6697 ------------------------------
6699 procedure Check_Duplicate_Property
6701 Status : in out Boolean)
6705 Error_Msg_N ("duplicate state property", Prop);
6709 end Check_Duplicate_Property;
6713 Errors : constant Nat := Serious_Errors_Detected;
6714 Loc : constant Source_Ptr := Sloc (State);
6717 Is_Null : Boolean := False;
6718 Level : Uint := Uint_0;
6722 -- Flags used to verify the consistency of properties
6724 Input_Seen : Boolean := False;
6725 Integrity_Seen : Boolean := False;
6726 Output_Seen : Boolean := False;
6727 Volatile_Seen : Boolean := False;
6729 -- Start of processing for Analyze_Abstract_State
6732 -- A package with a null abstract state is not allowed to
6733 -- declare additional states.
6736 Error_Msg_Name_1 := Chars (Pack_Id);
6737 Error_Msg_N ("package % has null abstract state", State);
6739 -- Null states appear as internally generated entities
6741 elsif Nkind (State) = N_Null then
6742 Name := New_Internal_Name ('S');
6746 -- Catch a case where a null state appears in a list of
6749 if Non_Null_Seen then
6750 Error_Msg_Name_1 := Chars (Pack_Id);
6752 ("package % has non-null abstract state", State);
6755 -- Simple state declaration
6757 elsif Nkind (State) = N_Identifier then
6758 Name := Chars (State);
6759 Non_Null_Seen := True;
6761 -- State declaration with various properties. This construct
6762 -- appears as an extension aggregate in the tree.
6764 elsif Nkind (State) = N_Extension_Aggregate then
6765 if Nkind (Ancestor_Part (State)) = N_Identifier then
6766 Name := Chars (Ancestor_Part (State));
6767 Non_Null_Seen := True;
6770 ("state name must be an identifier",
6771 Ancestor_Part (State));
6774 -- Process properties Input, Output and Volatile. Ensure
6775 -- that none of them appear more than once.
6777 Prop := First (Expressions (State));
6778 while Present (Prop) loop
6779 if Nkind (Prop) = N_Identifier then
6780 if Chars (Prop) = Name_Input then
6781 Check_Duplicate_Property (Prop, Input_Seen);
6782 elsif Chars (Prop) = Name_Output then
6783 Check_Duplicate_Property (Prop, Output_Seen);
6784 elsif Chars (Prop) = Name_Volatile then
6785 Check_Duplicate_Property (Prop, Volatile_Seen);
6787 Error_Msg_N ("invalid state property", Prop);
6790 Error_Msg_N ("invalid state property", Prop);
6796 -- Volatile requires exactly one Input or Output
6800 ((Input_Seen and then Output_Seen) -- both
6802 (not Input_Seen and then not Output_Seen)) -- none
6805 ("property Volatile requires exactly one Input or " &
6809 -- Either Input or Output require Volatile
6811 if (Input_Seen or Output_Seen)
6812 and then not Volatile_Seen
6815 ("properties Input and Output require Volatile", State);
6818 -- State property Integrity appears as a component
6821 Assoc := First (Component_Associations (State));
6822 while Present (Assoc) loop
6823 Prop := First (Choices (Assoc));
6824 while Present (Prop) loop
6825 if Nkind (Prop) = N_Identifier
6826 and then Chars (Prop) = Name_Integrity
6828 Check_Duplicate_Property (Prop, Integrity_Seen);
6830 Error_Msg_N ("invalid state property", Prop);
6836 if Nkind (Expression (Assoc)) = N_Integer_Literal then
6837 Level := Intval (Expression (Assoc));
6840 ("integrity level must be an integer literal",
6841 Expression (Assoc));
6847 -- Any other attempt to declare a state is erroneous
6850 Error_Msg_N ("malformed abstract state declaration", State);
6853 -- Do not generate a state abstraction entity if it was not
6854 -- properly declared.
6856 if Serious_Errors_Detected > Errors then
6860 -- The generated state abstraction reuses the same characters
6861 -- from the original state declaration. Decorate the entity.
6863 Id := Make_Defining_Identifier (Loc, New_External_Name (Name));
6864 Set_Comes_From_Source (Id, not Is_Null);
6865 Set_Parent (Id, State);
6866 Set_Ekind (Id, E_Abstract_State);
6867 Set_Etype (Id, Standard_Void_Type);
6868 Set_Integrity_Level (Id, Level);
6869 Set_Refined_State (Id, Empty);
6871 -- Every non-null state must be nameable and resolvable the
6872 -- same way a constant is.
6875 Push_Scope (Pack_Id);
6880 -- Associate the state with its related package
6882 if No (Abstract_States (Pack_Id)) then
6883 Set_Abstract_States (Pack_Id, New_Elmt_List);
6886 Append_Elmt (Id, Abstract_States (Pack_Id));
6887 end Analyze_Abstract_State;
6894 -- Start of processing for Abstract_State
6899 Check_Arg_Count (1);
6901 -- Ensure the proper placement of the pragma. Abstract states must
6902 -- be associated with a package declaration.
6904 if From_Aspect_Specification (N) then
6905 Par := Parent (Corresponding_Aspect (N));
6907 Par := Parent (Parent (N));
6910 if Nkind (Par) = N_Compilation_Unit then
6914 if Nkind (Par) /= N_Package_Declaration then
6919 Pack_Id := Defining_Unit_Name (Specification (Par));
6920 State := Expression (Arg1);
6922 -- Multiple abstract states appear as an aggregate
6924 if Nkind (State) = N_Aggregate then
6925 State := First (Expressions (State));
6926 while Present (State) loop
6927 Analyze_Abstract_State (State);
6932 -- Various forms of a single abstract state. Note that these may
6933 -- include malformed state declarations.
6936 Analyze_Abstract_State (State);
6946 -- Note: this pragma also has some specific processing in Par.Prag
6947 -- because we want to set the Ada version mode during parsing.
6949 when Pragma_Ada_83 =>
6951 Check_Arg_Count (0);
6953 -- We really should check unconditionally for proper configuration
6954 -- pragma placement, since we really don't want mixed Ada modes
6955 -- within a single unit, and the GNAT reference manual has always
6956 -- said this was a configuration pragma, but we did not check and
6957 -- are hesitant to add the check now.
6959 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6960 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6961 -- or Ada 2012 mode.
6963 if Ada_Version >= Ada_2005 then
6964 Check_Valid_Configuration_Pragma;
6967 -- Now set Ada 83 mode
6969 Ada_Version := Ada_83;
6970 Ada_Version_Explicit := Ada_Version;
6978 -- Note: this pragma also has some specific processing in Par.Prag
6979 -- because we want to set the Ada 83 version mode during parsing.
6981 when Pragma_Ada_95 =>
6983 Check_Arg_Count (0);
6985 -- We really should check unconditionally for proper configuration
6986 -- pragma placement, since we really don't want mixed Ada modes
6987 -- within a single unit, and the GNAT reference manual has always
6988 -- said this was a configuration pragma, but we did not check and
6989 -- are hesitant to add the check now.
6991 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6992 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6994 if Ada_Version >= Ada_2005 then
6995 Check_Valid_Configuration_Pragma;
6998 -- Now set Ada 95 mode
7000 Ada_Version := Ada_95;
7001 Ada_Version_Explicit := Ada_Version;
7003 ---------------------
7004 -- Ada_05/Ada_2005 --
7005 ---------------------
7008 -- pragma Ada_05 (LOCAL_NAME);
7011 -- pragma Ada_2005 (LOCAL_NAME):
7013 -- Note: these pragmas also have some specific processing in Par.Prag
7014 -- because we want to set the Ada 2005 version mode during parsing.
7016 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
7022 if Arg_Count = 1 then
7023 Check_Arg_Is_Local_Name (Arg1);
7024 E_Id := Get_Pragma_Arg (Arg1);
7026 if Etype (E_Id) = Any_Type then
7030 Set_Is_Ada_2005_Only (Entity (E_Id));
7031 Record_Rep_Item (Entity (E_Id), N);
7034 Check_Arg_Count (0);
7036 -- For Ada_2005 we unconditionally enforce the documented
7037 -- configuration pragma placement, since we do not want to
7038 -- tolerate mixed modes in a unit involving Ada 2005. That
7039 -- would cause real difficulties for those cases where there
7040 -- are incompatibilities between Ada 95 and Ada 2005.
7042 Check_Valid_Configuration_Pragma;
7044 -- Now set appropriate Ada mode
7046 Ada_Version := Ada_2005;
7047 Ada_Version_Explicit := Ada_2005;
7051 ---------------------
7052 -- Ada_12/Ada_2012 --
7053 ---------------------
7056 -- pragma Ada_12 (LOCAL_NAME);
7059 -- pragma Ada_2012 (LOCAL_NAME):
7061 -- Note: these pragmas also have some specific processing in Par.Prag
7062 -- because we want to set the Ada 2012 version mode during parsing.
7064 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
7070 if Arg_Count = 1 then
7071 Check_Arg_Is_Local_Name (Arg1);
7072 E_Id := Get_Pragma_Arg (Arg1);
7074 if Etype (E_Id) = Any_Type then
7078 Set_Is_Ada_2012_Only (Entity (E_Id));
7079 Record_Rep_Item (Entity (E_Id), N);
7082 Check_Arg_Count (0);
7084 -- For Ada_2012 we unconditionally enforce the documented
7085 -- configuration pragma placement, since we do not want to
7086 -- tolerate mixed modes in a unit involving Ada 2012. That
7087 -- would cause real difficulties for those cases where there
7088 -- are incompatibilities between Ada 95 and Ada 2012. We could
7089 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
7091 Check_Valid_Configuration_Pragma;
7093 -- Now set appropriate Ada mode
7095 Ada_Version := Ada_2012;
7096 Ada_Version_Explicit := Ada_2012;
7100 ----------------------
7101 -- All_Calls_Remote --
7102 ----------------------
7104 -- pragma All_Calls_Remote [(library_package_NAME)];
7106 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
7107 Lib_Entity : Entity_Id;
7110 Check_Ada_83_Warning;
7111 Check_Valid_Library_Unit_Pragma;
7113 if Nkind (N) = N_Null_Statement then
7117 Lib_Entity := Find_Lib_Unit_Name;
7119 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
7121 if Present (Lib_Entity)
7122 and then not Debug_Flag_U
7124 if not Is_Remote_Call_Interface (Lib_Entity) then
7125 Error_Pragma ("pragma% only apply to rci unit");
7127 -- Set flag for entity of the library unit
7130 Set_Has_All_Calls_Remote (Lib_Entity);
7134 end All_Calls_Remote;
7140 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
7141 -- ARG ::= NAME | EXPRESSION
7143 -- The first two arguments are by convention intended to refer to an
7144 -- external tool and a tool-specific function. These arguments are
7147 when Pragma_Annotate => Annotate : declare
7153 Check_At_Least_N_Arguments (1);
7154 Check_Arg_Is_Identifier (Arg1);
7155 Check_No_Identifiers;
7158 -- Second parameter is optional, it is never analyzed
7163 -- Here if we have a second parameter
7166 -- Second parameter must be identifier
7168 Check_Arg_Is_Identifier (Arg2);
7170 -- Process remaining parameters if any
7173 while Present (Arg) loop
7174 Exp := Get_Pragma_Arg (Arg);
7177 if Is_Entity_Name (Exp) then
7180 -- For string literals, we assume Standard_String as the
7181 -- type, unless the string contains wide or wide_wide
7184 elsif Nkind (Exp) = N_String_Literal then
7185 if Has_Wide_Wide_Character (Exp) then
7186 Resolve (Exp, Standard_Wide_Wide_String);
7187 elsif Has_Wide_Character (Exp) then
7188 Resolve (Exp, Standard_Wide_String);
7190 Resolve (Exp, Standard_String);
7193 elsif Is_Overloaded (Exp) then
7195 ("ambiguous argument for pragma%", Exp);
7206 ---------------------------
7207 -- Assert/Assert_And_Cut --
7208 ---------------------------
7211 -- ( [Check => ] Boolean_EXPRESSION
7212 -- [, [Message =>] Static_String_EXPRESSION]);
7214 -- pragma Assert_And_Cut
7215 -- ( [Check => ] Boolean_EXPRESSION
7216 -- [, [Message =>] Static_String_EXPRESSION]);
7218 when Pragma_Assert | Pragma_Assert_And_Cut => Assert : declare
7223 if Prag_Id = Pragma_Assert then
7225 else -- Pragma_Assert_And_Cut
7230 Check_At_Least_N_Arguments (1);
7231 Check_At_Most_N_Arguments (2);
7232 Check_Arg_Order ((Name_Check, Name_Message));
7233 Check_Optional_Identifier (Arg1, Name_Check);
7235 -- We treat pragma Assert as equivalent to:
7237 -- pragma Check (Assertion, condition [, msg]);
7239 -- So rewrite pragma in this manner, transfer the message
7240 -- argument if present, and analyze the result
7242 -- Pragma Assert_And_Cut is treated exactly like pragma Assert by
7243 -- the frontend. Formal verification tools may use it to "cut" the
7244 -- paths through the code, to make verification tractable. When
7245 -- dealing with a semantically analyzed tree, the information that
7246 -- a Check node N corresponds to a source Assert_And_Cut pragma
7247 -- can be retrieved from the pragma kind of Original_Node(N).
7249 Expr := Get_Pragma_Arg (Arg1);
7251 Make_Pragma_Argument_Association (Loc,
7252 Expression => Make_Identifier (Loc, Name_Assertion)),
7254 Make_Pragma_Argument_Association (Sloc (Expr),
7255 Expression => Expr));
7257 if Arg_Count > 1 then
7258 Check_Optional_Identifier (Arg2, Name_Message);
7259 Append_To (Newa, New_Copy_Tree (Arg2));
7264 Chars => Name_Check,
7265 Pragma_Argument_Associations => Newa));
7269 ----------------------
7270 -- Assertion_Policy --
7271 ----------------------
7273 -- pragma Assertion_Policy (Check | Disable | Ignore)
7275 when Pragma_Assertion_Policy => Assertion_Policy : declare
7280 Check_Valid_Configuration_Pragma;
7281 Check_Arg_Count (1);
7282 Check_No_Identifiers;
7283 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7285 -- We treat pragma Assertion_Policy as equivalent to:
7287 -- pragma Check_Policy (Assertion, policy)
7289 -- So rewrite the pragma in that manner and link on to the chain
7290 -- of Check_Policy pragmas, marking the pragma as analyzed.
7292 Policy := Get_Pragma_Arg (Arg1);
7296 Chars => Name_Check_Policy,
7297 Pragma_Argument_Associations => New_List (
7298 Make_Pragma_Argument_Association (Loc,
7299 Expression => Make_Identifier (Loc, Name_Assertion)),
7301 Make_Pragma_Argument_Association (Loc,
7303 Make_Identifier (Sloc (Policy), Chars (Policy))))));
7306 Set_Next_Pragma (N, Opt.Check_Policy_List);
7307 Opt.Check_Policy_List := N;
7308 end Assertion_Policy;
7314 -- pragma Assume (boolean_EXPRESSION);
7316 when Pragma_Assume => Assume : declare
7320 Check_Arg_Count (1);
7322 -- Pragma Assume is transformed into pragma Check in the following
7325 -- pragma Check (Assume, Expr);
7329 Chars => Name_Check,
7330 Pragma_Argument_Associations => New_List (
7331 Make_Pragma_Argument_Association (Loc,
7332 Expression => Make_Identifier (Loc, Name_Assume)),
7334 Make_Pragma_Argument_Association (Loc,
7335 Expression => Relocate_Node (Expression (Arg1))))));
7339 ------------------------------
7340 -- Assume_No_Invalid_Values --
7341 ------------------------------
7343 -- pragma Assume_No_Invalid_Values (On | Off);
7345 when Pragma_Assume_No_Invalid_Values =>
7347 Check_Valid_Configuration_Pragma;
7348 Check_Arg_Count (1);
7349 Check_No_Identifiers;
7350 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7352 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
7353 Assume_No_Invalid_Values := True;
7355 Assume_No_Invalid_Values := False;
7358 --------------------------
7359 -- Attribute_Definition --
7360 --------------------------
7362 -- pragma Attribute_Definition
7363 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
7364 -- [Entity =>] LOCAL_NAME,
7365 -- [Expression =>] EXPRESSION | NAME);
7367 when Pragma_Attribute_Definition => Attribute_Definition : declare
7368 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
7373 Check_Arg_Count (3);
7374 Check_Optional_Identifier (Arg1, "attribute");
7375 Check_Optional_Identifier (Arg2, "entity");
7376 Check_Optional_Identifier (Arg3, "expression");
7378 if Nkind (Attribute_Designator) /= N_Identifier then
7379 Error_Msg_N ("attribute name expected", Attribute_Designator);
7383 Check_Arg_Is_Local_Name (Arg2);
7385 -- If the attribute is not recognized, then issue a warning (not
7386 -- an error), and ignore the pragma.
7388 Aname := Chars (Attribute_Designator);
7390 if not Is_Attribute_Name (Aname) then
7391 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
7395 -- Otherwise, rewrite the pragma as an attribute definition clause
7398 Make_Attribute_Definition_Clause (Loc,
7399 Name => Get_Pragma_Arg (Arg2),
7401 Expression => Get_Pragma_Arg (Arg3)));
7403 end Attribute_Definition;
7409 -- pragma AST_Entry (entry_IDENTIFIER);
7411 when Pragma_AST_Entry => AST_Entry : declare
7417 Check_Arg_Count (1);
7418 Check_No_Identifiers;
7419 Check_Arg_Is_Local_Name (Arg1);
7420 Ent := Entity (Get_Pragma_Arg (Arg1));
7422 -- Note: the implementation of the AST_Entry pragma could handle
7423 -- the entry family case fine, but for now we are consistent with
7424 -- the DEC rules, and do not allow the pragma, which of course
7425 -- has the effect of also forbidding the attribute.
7427 if Ekind (Ent) /= E_Entry then
7429 ("pragma% argument must be simple entry name", Arg1);
7431 elsif Is_AST_Entry (Ent) then
7433 ("duplicate % pragma for entry", Arg1);
7435 elsif Has_Homonym (Ent) then
7437 ("pragma% argument cannot specify overloaded entry", Arg1);
7441 FF : constant Entity_Id := First_Formal (Ent);
7444 if Present (FF) then
7445 if Present (Next_Formal (FF)) then
7447 ("entry for pragma% can have only one argument",
7450 elsif Parameter_Mode (FF) /= E_In_Parameter then
7452 ("entry parameter for pragma% must have mode IN",
7458 Set_Is_AST_Entry (Ent);
7466 -- pragma Asynchronous (LOCAL_NAME);
7468 when Pragma_Asynchronous => Asynchronous : declare
7476 procedure Process_Async_Pragma;
7477 -- Common processing for procedure and access-to-procedure case
7479 --------------------------
7480 -- Process_Async_Pragma --
7481 --------------------------
7483 procedure Process_Async_Pragma is
7486 Set_Is_Asynchronous (Nm);
7490 -- The formals should be of mode IN (RM E.4.1(6))
7493 while Present (S) loop
7494 Formal := Defining_Identifier (S);
7496 if Nkind (Formal) = N_Defining_Identifier
7497 and then Ekind (Formal) /= E_In_Parameter
7500 ("pragma% procedure can only have IN parameter",
7507 Set_Is_Asynchronous (Nm);
7508 end Process_Async_Pragma;
7510 -- Start of processing for pragma Asynchronous
7513 Check_Ada_83_Warning;
7514 Check_No_Identifiers;
7515 Check_Arg_Count (1);
7516 Check_Arg_Is_Local_Name (Arg1);
7518 if Debug_Flag_U then
7522 C_Ent := Cunit_Entity (Current_Sem_Unit);
7523 Analyze (Get_Pragma_Arg (Arg1));
7524 Nm := Entity (Get_Pragma_Arg (Arg1));
7526 if not Is_Remote_Call_Interface (C_Ent)
7527 and then not Is_Remote_Types (C_Ent)
7529 -- This pragma should only appear in an RCI or Remote Types
7530 -- unit (RM E.4.1(4)).
7533 ("pragma% not in Remote_Call_Interface or " &
7534 "Remote_Types unit");
7537 if Ekind (Nm) = E_Procedure
7538 and then Nkind (Parent (Nm)) = N_Procedure_Specification
7540 if not Is_Remote_Call_Interface (Nm) then
7542 ("pragma% cannot be applied on non-remote procedure",
7546 L := Parameter_Specifications (Parent (Nm));
7547 Process_Async_Pragma;
7550 elsif Ekind (Nm) = E_Function then
7552 ("pragma% cannot be applied to function", Arg1);
7554 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
7555 if Is_Record_Type (Nm) then
7557 -- A record type that is the Equivalent_Type for a remote
7558 -- access-to-subprogram type.
7560 N := Declaration_Node (Corresponding_Remote_Type (Nm));
7563 -- A non-expanded RAS type (distribution is not enabled)
7565 N := Declaration_Node (Nm);
7568 if Nkind (N) = N_Full_Type_Declaration
7569 and then Nkind (Type_Definition (N)) =
7570 N_Access_Procedure_Definition
7572 L := Parameter_Specifications (Type_Definition (N));
7573 Process_Async_Pragma;
7575 if Is_Asynchronous (Nm)
7576 and then Expander_Active
7577 and then Get_PCS_Name /= Name_No_DSA
7579 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
7584 ("pragma% cannot reference access-to-function type",
7588 -- Only other possibility is Access-to-class-wide type
7590 elsif Is_Access_Type (Nm)
7591 and then Is_Class_Wide_Type (Designated_Type (Nm))
7593 Check_First_Subtype (Arg1);
7594 Set_Is_Asynchronous (Nm);
7595 if Expander_Active then
7596 RACW_Type_Is_Asynchronous (Nm);
7600 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
7608 -- pragma Atomic (LOCAL_NAME);
7610 when Pragma_Atomic =>
7611 Process_Atomic_Shared_Volatile;
7613 -----------------------
7614 -- Atomic_Components --
7615 -----------------------
7617 -- pragma Atomic_Components (array_LOCAL_NAME);
7619 -- This processing is shared by Volatile_Components
7621 when Pragma_Atomic_Components |
7622 Pragma_Volatile_Components =>
7624 Atomic_Components : declare
7631 Check_Ada_83_Warning;
7632 Check_No_Identifiers;
7633 Check_Arg_Count (1);
7634 Check_Arg_Is_Local_Name (Arg1);
7635 E_Id := Get_Pragma_Arg (Arg1);
7637 if Etype (E_Id) = Any_Type then
7643 Check_Duplicate_Pragma (E);
7645 if Rep_Item_Too_Early (E, N)
7647 Rep_Item_Too_Late (E, N)
7652 D := Declaration_Node (E);
7655 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7657 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7658 and then Nkind (D) = N_Object_Declaration
7659 and then Nkind (Object_Definition (D)) =
7660 N_Constrained_Array_Definition)
7662 -- The flag is set on the object, or on the base type
7664 if Nkind (D) /= N_Object_Declaration then
7668 Set_Has_Volatile_Components (E);
7670 if Prag_Id = Pragma_Atomic_Components then
7671 Set_Has_Atomic_Components (E);
7675 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7677 end Atomic_Components;
7679 --------------------
7680 -- Attach_Handler --
7681 --------------------
7683 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7685 when Pragma_Attach_Handler =>
7686 Check_Ada_83_Warning;
7687 Check_No_Identifiers;
7688 Check_Arg_Count (2);
7690 if No_Run_Time_Mode then
7691 Error_Msg_CRT ("Attach_Handler pragma", N);
7693 Check_Interrupt_Or_Attach_Handler;
7695 -- The expression that designates the attribute may depend on a
7696 -- discriminant, and is therefore a per-object expression, to
7697 -- be expanded in the init proc. If expansion is enabled, then
7698 -- perform semantic checks on a copy only.
7700 if Expander_Active then
7702 Temp : constant Node_Id :=
7703 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7705 Set_Parent (Temp, N);
7706 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7710 Analyze (Get_Pragma_Arg (Arg2));
7711 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7714 Process_Interrupt_Or_Attach_Handler;
7717 --------------------
7718 -- C_Pass_By_Copy --
7719 --------------------
7721 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7723 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7729 Check_Valid_Configuration_Pragma;
7730 Check_Arg_Count (1);
7731 Check_Optional_Identifier (Arg1, "max_size");
7733 Arg := Get_Pragma_Arg (Arg1);
7734 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7736 Val := Expr_Value (Arg);
7740 ("maximum size for pragma% must be positive", Arg1);
7742 elsif UI_Is_In_Int_Range (Val) then
7743 Default_C_Record_Mechanism := UI_To_Int (Val);
7745 -- If a giant value is given, Int'Last will do well enough.
7746 -- If sometime someone complains that a record larger than
7747 -- two gigabytes is not copied, we will worry about it then!
7750 Default_C_Record_Mechanism := Mechanism_Type'Last;
7758 -- pragma Check ([Name =>] IDENTIFIER,
7759 -- [Check =>] Boolean_EXPRESSION
7760 -- [,[Message =>] String_EXPRESSION]);
7762 when Pragma_Check => Check : declare
7768 -- Set True if category of assertions referenced by Name enabled
7772 Check_At_Least_N_Arguments (2);
7773 Check_At_Most_N_Arguments (3);
7774 Check_Optional_Identifier (Arg1, Name_Name);
7775 Check_Optional_Identifier (Arg2, Name_Check);
7777 if Arg_Count = 3 then
7778 Check_Optional_Identifier (Arg3, Name_Message);
7779 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7782 Check_Arg_Is_Identifier (Arg1);
7784 -- Completely ignore if disabled
7786 if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7787 Rewrite (N, Make_Null_Statement (Loc));
7792 Cname := Chars (Get_Pragma_Arg (Arg1));
7793 Check_On := Check_Enabled (Cname);
7796 when Name_Predicate |
7799 -- Nothing to do: since checks occur in client units,
7800 -- the SCO for the aspect in the declaration unit is
7801 -- conservatively always enabled.
7807 if Check_On and then not Split_PPC (N) then
7809 -- Mark pragma/aspect SCO as enabled
7811 Set_SCO_Pragma_Enabled (Loc);
7815 -- If expansion is active and the check is not enabled then we
7816 -- rewrite the Check as:
7818 -- if False and then condition then
7822 -- The reason we do this rewriting during semantic analysis rather
7823 -- than as part of normal expansion is that we cannot analyze and
7824 -- expand the code for the boolean expression directly, or it may
7825 -- cause insertion of actions that would escape the attempt to
7826 -- suppress the check code.
7828 -- Note that the Sloc for the if statement corresponds to the
7829 -- argument condition, not the pragma itself. The reason for this
7830 -- is that we may generate a warning if the condition is False at
7831 -- compile time, and we do not want to delete this warning when we
7832 -- delete the if statement.
7834 Expr := Get_Pragma_Arg (Arg2);
7836 if Expander_Active and then not Check_On then
7837 Eloc := Sloc (Expr);
7840 Make_If_Statement (Eloc,
7842 Make_And_Then (Eloc,
7843 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7844 Right_Opnd => Expr),
7845 Then_Statements => New_List (
7846 Make_Null_Statement (Eloc))));
7853 In_Assertion_Expr := In_Assertion_Expr + 1;
7854 Analyze_And_Resolve (Expr, Any_Boolean);
7855 In_Assertion_Expr := In_Assertion_Expr - 1;
7859 --------------------------
7860 -- Check_Float_Overflow --
7861 --------------------------
7863 -- pragma Check_Float_Overflow;
7865 when Pragma_Check_Float_Overflow =>
7867 Check_Valid_Configuration_Pragma;
7868 Check_Arg_Count (0);
7869 Check_Float_Overflow := True;
7875 -- pragma Check_Name (check_IDENTIFIER);
7877 when Pragma_Check_Name =>
7878 Check_No_Identifiers;
7880 Check_Valid_Configuration_Pragma;
7881 Check_Arg_Count (1);
7882 Check_Arg_Is_Identifier (Arg1);
7885 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7888 for J in Check_Names.First .. Check_Names.Last loop
7889 if Check_Names.Table (J) = Nam then
7894 Check_Names.Append (Nam);
7901 -- pragma Check_Policy (
7902 -- [Name =>] IDENTIFIER,
7903 -- [Policy =>] POLICY_IDENTIFIER);
7905 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7907 -- Note: this is a configuration pragma, but it is allowed to appear
7910 when Pragma_Check_Policy =>
7912 Check_Arg_Count (2);
7913 Check_Optional_Identifier (Arg1, Name_Name);
7914 Check_Optional_Identifier (Arg2, Name_Policy);
7916 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7918 -- A Check_Policy pragma can appear either as a configuration
7919 -- pragma, or in a declarative part or a package spec (see RM
7920 -- 11.5(5) for rules for Suppress/Unsuppress which are also
7921 -- followed for Check_Policy).
7923 if not Is_Configuration_Pragma then
7924 Check_Is_In_Decl_Part_Or_Package_Spec;
7927 Set_Next_Pragma (N, Opt.Check_Policy_List);
7928 Opt.Check_Policy_List := N;
7930 ---------------------
7931 -- CIL_Constructor --
7932 ---------------------
7934 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7936 -- Processing for this pragma is shared with Java_Constructor
7942 -- pragma Comment (static_string_EXPRESSION)
7944 -- Processing for pragma Comment shares the circuitry for pragma
7945 -- Ident. The only differences are that Ident enforces a limit of 31
7946 -- characters on its argument, and also enforces limitations on
7947 -- placement for DEC compatibility. Pragma Comment shares neither of
7948 -- these restrictions.
7954 -- pragma Common_Object (
7955 -- [Internal =>] LOCAL_NAME
7956 -- [, [External =>] EXTERNAL_SYMBOL]
7957 -- [, [Size =>] EXTERNAL_SYMBOL]);
7959 -- Processing for this pragma is shared with Psect_Object
7961 ------------------------
7962 -- Compile_Time_Error --
7963 ------------------------
7965 -- pragma Compile_Time_Error
7966 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7968 when Pragma_Compile_Time_Error =>
7970 Process_Compile_Time_Warning_Or_Error;
7972 --------------------------
7973 -- Compile_Time_Warning --
7974 --------------------------
7976 -- pragma Compile_Time_Warning
7977 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7979 when Pragma_Compile_Time_Warning =>
7981 Process_Compile_Time_Warning_Or_Error;
7987 when Pragma_Compiler_Unit =>
7989 Check_Arg_Count (0);
7990 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7992 -----------------------------
7993 -- Complete_Representation --
7994 -----------------------------
7996 -- pragma Complete_Representation;
7998 when Pragma_Complete_Representation =>
8000 Check_Arg_Count (0);
8002 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
8004 ("pragma & must appear within record representation clause");
8007 ----------------------------
8008 -- Complex_Representation --
8009 ----------------------------
8011 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
8013 when Pragma_Complex_Representation => Complex_Representation : declare
8020 Check_Arg_Count (1);
8021 Check_Optional_Identifier (Arg1, Name_Entity);
8022 Check_Arg_Is_Local_Name (Arg1);
8023 E_Id := Get_Pragma_Arg (Arg1);
8025 if Etype (E_Id) = Any_Type then
8031 if not Is_Record_Type (E) then
8033 ("argument for pragma% must be record type", Arg1);
8036 Ent := First_Entity (E);
8039 or else No (Next_Entity (Ent))
8040 or else Present (Next_Entity (Next_Entity (Ent)))
8041 or else not Is_Floating_Point_Type (Etype (Ent))
8042 or else Etype (Ent) /= Etype (Next_Entity (Ent))
8045 ("record for pragma% must have two fields of the same "
8046 & "floating-point type", Arg1);
8049 Set_Has_Complex_Representation (Base_Type (E));
8051 -- We need to treat the type has having a non-standard
8052 -- representation, for back-end purposes, even though in
8053 -- general a complex will have the default representation
8054 -- of a record with two real components.
8056 Set_Has_Non_Standard_Rep (Base_Type (E));
8058 end Complex_Representation;
8060 -------------------------
8061 -- Component_Alignment --
8062 -------------------------
8064 -- pragma Component_Alignment (
8065 -- [Form =>] ALIGNMENT_CHOICE
8066 -- [, [Name =>] type_LOCAL_NAME]);
8068 -- ALIGNMENT_CHOICE ::=
8070 -- | Component_Size_4
8074 when Pragma_Component_Alignment => Component_AlignmentP : declare
8075 Args : Args_List (1 .. 2);
8076 Names : constant Name_List (1 .. 2) := (
8080 Form : Node_Id renames Args (1);
8081 Name : Node_Id renames Args (2);
8083 Atype : Component_Alignment_Kind;
8088 Gather_Associations (Names, Args);
8091 Error_Pragma ("missing Form argument for pragma%");
8094 Check_Arg_Is_Identifier (Form);
8096 -- Get proper alignment, note that Default = Component_Size on all
8097 -- machines we have so far, and we want to set this value rather
8098 -- than the default value to indicate that it has been explicitly
8099 -- set (and thus will not get overridden by the default component
8100 -- alignment for the current scope)
8102 if Chars (Form) = Name_Component_Size then
8103 Atype := Calign_Component_Size;
8105 elsif Chars (Form) = Name_Component_Size_4 then
8106 Atype := Calign_Component_Size_4;
8108 elsif Chars (Form) = Name_Default then
8109 Atype := Calign_Component_Size;
8111 elsif Chars (Form) = Name_Storage_Unit then
8112 Atype := Calign_Storage_Unit;
8116 ("invalid Form parameter for pragma%", Form);
8119 -- Case with no name, supplied, affects scope table entry
8123 (Scope_Stack.Last).Component_Alignment_Default := Atype;
8125 -- Case of name supplied
8128 Check_Arg_Is_Local_Name (Name);
8130 Typ := Entity (Name);
8133 or else Rep_Item_Too_Early (Typ, N)
8137 Typ := Underlying_Type (Typ);
8140 if not Is_Record_Type (Typ)
8141 and then not Is_Array_Type (Typ)
8144 ("Name parameter of pragma% must identify record or " &
8145 "array type", Name);
8148 -- An explicit Component_Alignment pragma overrides an
8149 -- implicit pragma Pack, but not an explicit one.
8151 if not Has_Pragma_Pack (Base_Type (Typ)) then
8152 Set_Is_Packed (Base_Type (Typ), False);
8153 Set_Component_Alignment (Base_Type (Typ), Atype);
8156 end Component_AlignmentP;
8162 -- pragma Contract_Case
8163 -- ([Name =>] Static_String_EXPRESSION
8164 -- ,[Mode =>] MODE_TYPE
8165 -- [, Requires => Boolean_EXPRESSION]
8166 -- [, Ensures => Boolean_EXPRESSION]);
8168 -- MODE_TYPE ::= Nominal | Robustness
8170 when Pragma_Contract_Case =>
8171 Check_Contract_Or_Test_Case;
8173 --------------------
8174 -- Contract_Cases --
8175 --------------------
8177 -- pragma Contract_Cases (CONTRACT_CASE_LIST);
8179 -- CONTRACT_CASE_LIST ::= CONTRACT_CASE {, CONTRACT_CASE}
8181 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
8183 -- CASE_GUARD ::= boolean_EXPRESSION | others
8185 -- CONSEQUENCE ::= boolean_EXPRESSION
8187 when Pragma_Contract_Cases => Contract_Cases : declare
8188 procedure Chain_Contract_Cases (Subp_Decl : Node_Id);
8189 -- Chain pragma Contract_Cases to the contract of a subprogram.
8190 -- Subp_Decl is the declaration of the subprogram.
8192 --------------------------
8193 -- Chain_Contract_Cases --
8194 --------------------------
8196 procedure Chain_Contract_Cases (Subp_Decl : Node_Id) is
8197 Subp : constant Entity_Id :=
8198 Defining_Unit_Name (Specification (Subp_Decl));
8202 Check_Duplicate_Pragma (Subp);
8203 CTC := Spec_CTC_List (Contract (Subp));
8204 while Present (CTC) loop
8205 if Chars (Pragma_Identifier (CTC)) = Pname then
8206 Error_Msg_Name_1 := Pname;
8207 Error_Msg_Sloc := Sloc (CTC);
8209 if From_Aspect_Specification (CTC) then
8211 ("aspect% for & previously given#", N, Subp);
8214 ("pragma% for & duplicates pragma#", N, Subp);
8220 CTC := Next_Pragma (CTC);
8223 -- Prepend pragma Contract_Cases to the contract
8225 Set_Next_Pragma (N, Spec_CTC_List (Contract (Subp)));
8226 Set_Spec_CTC_List (Contract (Subp), N);
8227 end Chain_Contract_Cases;
8231 Case_Guard : Node_Id;
8234 Others_Seen : Boolean := False;
8235 Contract_Case : Node_Id;
8236 Subp_Decl : Node_Id;
8238 -- Start of processing for Contract_Cases
8243 Check_Arg_Count (1);
8245 -- Completely ignore if disabled
8247 if Check_Disabled (Pname) then
8248 Rewrite (N, Make_Null_Statement (Loc));
8253 -- Check the placement of the pragma
8255 if not Is_List_Member (N) then
8259 -- Pragma Contract_Cases must be associated with a subprogram
8262 while Present (Prev (Decl)) loop
8263 Decl := Prev (Decl);
8265 if Nkind (Decl) in N_Generic_Declaration then
8268 Subp_Decl := Original_Node (Decl);
8271 -- Skip prior pragmas
8273 if Nkind (Subp_Decl) = N_Pragma then
8276 -- Skip internally generated code
8278 elsif not Comes_From_Source (Subp_Decl) then
8281 -- We have found the related subprogram
8283 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
8284 N_Subprogram_Declaration)
8293 -- All contract cases must appear as an aggregate
8295 if Nkind (Expression (Arg1)) /= N_Aggregate then
8296 Error_Pragma ("wrong syntax for pragma %");
8300 -- Verify the legality of individual contract cases
8303 First (Component_Associations (Expression (Arg1)));
8304 while Present (Contract_Case) loop
8305 if Nkind (Contract_Case) /= N_Component_Association then
8307 ("wrong syntax in contract case", Contract_Case);
8311 Case_Guard := First (Choices (Contract_Case));
8313 -- Each contract case must have exactly on case guard
8315 Extra := Next (Case_Guard);
8316 if Present (Extra) then
8318 ("contract case may have only one case guard", Extra);
8322 -- Check the placement of "others" (if available)
8324 if Nkind (Case_Guard) = N_Others_Choice then
8327 ("only one others choice allowed in pragma %",
8331 Others_Seen := True;
8334 elsif Others_Seen then
8336 ("others must be the last choice in pragma %", N);
8340 Next (Contract_Case);
8343 Chain_Contract_Cases (Subp_Decl);
8350 -- pragma Controlled (first_subtype_LOCAL_NAME);
8352 when Pragma_Controlled => Controlled : declare
8356 Check_No_Identifiers;
8357 Check_Arg_Count (1);
8358 Check_Arg_Is_Local_Name (Arg1);
8359 Arg := Get_Pragma_Arg (Arg1);
8361 if not Is_Entity_Name (Arg)
8362 or else not Is_Access_Type (Entity (Arg))
8364 Error_Pragma_Arg ("pragma% requires access type", Arg1);
8366 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
8374 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
8375 -- [Entity =>] LOCAL_NAME);
8377 when Pragma_Convention => Convention : declare
8380 pragma Warnings (Off, C);
8381 pragma Warnings (Off, E);
8383 Check_Arg_Order ((Name_Convention, Name_Entity));
8384 Check_Ada_83_Warning;
8385 Check_Arg_Count (2);
8386 Process_Convention (C, E);
8389 ---------------------------
8390 -- Convention_Identifier --
8391 ---------------------------
8393 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
8394 -- [Convention =>] convention_IDENTIFIER);
8396 when Pragma_Convention_Identifier => Convention_Identifier : declare
8402 Check_Arg_Order ((Name_Name, Name_Convention));
8403 Check_Arg_Count (2);
8404 Check_Optional_Identifier (Arg1, Name_Name);
8405 Check_Optional_Identifier (Arg2, Name_Convention);
8406 Check_Arg_Is_Identifier (Arg1);
8407 Check_Arg_Is_Identifier (Arg2);
8408 Idnam := Chars (Get_Pragma_Arg (Arg1));
8409 Cname := Chars (Get_Pragma_Arg (Arg2));
8411 if Is_Convention_Name (Cname) then
8412 Record_Convention_Identifier
8413 (Idnam, Get_Convention_Id (Cname));
8416 ("second arg for % pragma must be convention", Arg2);
8418 end Convention_Identifier;
8424 -- pragma CPP_Class ([Entity =>] local_NAME)
8426 when Pragma_CPP_Class => CPP_Class : declare
8430 if Warn_On_Obsolescent_Feature then
8431 -- Following message is obsolete ???
8433 ("'G'N'A'T pragma cpp'_class is now obsolete and has no " &
8434 "effect; replace it by pragma import?j?", N);
8437 Check_Arg_Count (1);
8441 Chars => Name_Import,
8442 Pragma_Argument_Associations => New_List (
8443 Make_Pragma_Argument_Association (Loc,
8444 Expression => Make_Identifier (Loc, Name_CPP)),
8445 New_Copy (First (Pragma_Argument_Associations (N))))));
8449 ---------------------
8450 -- CPP_Constructor --
8451 ---------------------
8453 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
8454 -- [, [External_Name =>] static_string_EXPRESSION ]
8455 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8457 when Pragma_CPP_Constructor => CPP_Constructor : declare
8461 Tag_Typ : Entity_Id;
8465 Check_At_Least_N_Arguments (1);
8466 Check_At_Most_N_Arguments (3);
8467 Check_Optional_Identifier (Arg1, Name_Entity);
8468 Check_Arg_Is_Local_Name (Arg1);
8470 Id := Get_Pragma_Arg (Arg1);
8471 Find_Program_Unit_Name (Id);
8473 -- If we did not find the name, we are done
8475 if Etype (Id) = Any_Type then
8479 Def_Id := Entity (Id);
8481 -- Check if already defined as constructor
8483 if Is_Constructor (Def_Id) then
8485 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
8489 if Ekind (Def_Id) = E_Function
8490 and then (Is_CPP_Class (Etype (Def_Id))
8491 or else (Is_Class_Wide_Type (Etype (Def_Id))
8493 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
8495 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
8497 ("'C'P'P constructor must be defined in the scope of " &
8498 "its returned type", Arg1);
8501 if Arg_Count >= 2 then
8502 Set_Imported (Def_Id);
8503 Set_Is_Public (Def_Id);
8504 Process_Interface_Name (Def_Id, Arg2, Arg3);
8507 Set_Has_Completion (Def_Id);
8508 Set_Is_Constructor (Def_Id);
8509 Set_Convention (Def_Id, Convention_CPP);
8511 -- Imported C++ constructors are not dispatching primitives
8512 -- because in C++ they don't have a dispatch table slot.
8513 -- However, in Ada the constructor has the profile of a
8514 -- function that returns a tagged type and therefore it has
8515 -- been treated as a primitive operation during semantic
8516 -- analysis. We now remove it from the list of primitive
8517 -- operations of the type.
8519 if Is_Tagged_Type (Etype (Def_Id))
8520 and then not Is_Class_Wide_Type (Etype (Def_Id))
8521 and then Is_Dispatching_Operation (Def_Id)
8523 Tag_Typ := Etype (Def_Id);
8525 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
8526 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
8530 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
8531 Set_Is_Dispatching_Operation (Def_Id, False);
8534 -- For backward compatibility, if the constructor returns a
8535 -- class wide type, and we internally change the return type to
8536 -- the corresponding root type.
8538 if Is_Class_Wide_Type (Etype (Def_Id)) then
8539 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
8543 ("pragma% requires function returning a 'C'P'P_Class type",
8546 end CPP_Constructor;
8552 when Pragma_CPP_Virtual => CPP_Virtual : declare
8556 if Warn_On_Obsolescent_Feature then
8558 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
8567 when Pragma_CPP_Vtable => CPP_Vtable : declare
8571 if Warn_On_Obsolescent_Feature then
8573 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
8582 -- pragma CPU (EXPRESSION);
8584 when Pragma_CPU => CPU : declare
8585 P : constant Node_Id := Parent (N);
8591 Check_No_Identifiers;
8592 Check_Arg_Count (1);
8596 if Nkind (P) = N_Subprogram_Body then
8597 Check_In_Main_Program;
8599 Arg := Get_Pragma_Arg (Arg1);
8600 Analyze_And_Resolve (Arg, Any_Integer);
8602 Ent := Defining_Unit_Name (Specification (P));
8604 if Nkind (Ent) = N_Defining_Program_Unit_Name then
8605 Ent := Defining_Identifier (Ent);
8610 if not Is_Static_Expression (Arg) then
8611 Flag_Non_Static_Expr
8612 ("main subprogram affinity is not static!", Arg);
8615 -- If constraint error, then we already signalled an error
8617 elsif Raises_Constraint_Error (Arg) then
8620 -- Otherwise check in range
8624 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
8625 -- This is the entity System.Multiprocessors.CPU_Range;
8627 Val : constant Uint := Expr_Value (Arg);
8630 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
8632 Val > Expr_Value (Type_High_Bound (CPU_Id))
8635 ("main subprogram CPU is out of range", Arg1);
8641 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8645 elsif Nkind (P) = N_Task_Definition then
8646 Arg := Get_Pragma_Arg (Arg1);
8647 Ent := Defining_Identifier (Parent (P));
8649 -- The expression must be analyzed in the special manner
8650 -- described in "Handling of Default and Per-Object
8651 -- Expressions" in sem.ads.
8653 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
8655 -- Anything else is incorrect
8661 -- Check duplicate pragma before we chain the pragma in the Rep
8662 -- Item chain of Ent.
8664 Check_Duplicate_Pragma (Ent);
8665 Record_Rep_Item (Ent, N);
8672 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
8674 when Pragma_Debug => Debug : declare
8681 -- Skip analysis if disabled
8683 if Debug_Pragmas_Disabled then
8684 Rewrite (N, Make_Null_Statement (Loc));
8691 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
8694 if Debug_Pragmas_Enabled then
8695 Set_SCO_Pragma_Enabled (Loc);
8698 if Arg_Count = 2 then
8701 Left_Opnd => Relocate_Node (Cond),
8702 Right_Opnd => Get_Pragma_Arg (Arg1));
8703 Call := Get_Pragma_Arg (Arg2);
8705 Call := Get_Pragma_Arg (Arg1);
8709 N_Indexed_Component,
8713 N_Selected_Component)
8715 -- If this pragma Debug comes from source, its argument was
8716 -- parsed as a name form (which is syntactically identical).
8717 -- In a generic context a parameterless call will be left as
8718 -- an expanded name (if global) or selected_component if local.
8719 -- Change it to a procedure call statement now.
8721 Change_Name_To_Procedure_Call_Statement (Call);
8723 elsif Nkind (Call) = N_Procedure_Call_Statement then
8725 -- Already in the form of a procedure call statement: nothing
8726 -- to do (could happen in case of an internally generated
8732 -- All other cases: diagnose error
8735 ("argument of pragma ""Debug"" is not procedure call",
8740 -- Rewrite into a conditional with an appropriate condition. We
8741 -- wrap the procedure call in a block so that overhead from e.g.
8742 -- use of the secondary stack does not generate execution overhead
8743 -- for suppressed conditions.
8745 -- Normally the analysis that follows will freeze the subprogram
8746 -- being called. However, if the call is to a null procedure,
8747 -- we want to freeze it before creating the block, because the
8748 -- analysis that follows may be done with expansion disabled, in
8749 -- which case the body will not be generated, leading to spurious
8752 if Nkind (Call) = N_Procedure_Call_Statement
8753 and then Is_Entity_Name (Name (Call))
8755 Analyze (Name (Call));
8756 Freeze_Before (N, Entity (Name (Call)));
8759 Rewrite (N, Make_Implicit_If_Statement (N,
8761 Then_Statements => New_List (
8762 Make_Block_Statement (Loc,
8763 Handled_Statement_Sequence =>
8764 Make_Handled_Sequence_Of_Statements (Loc,
8765 Statements => New_List (Relocate_Node (Call)))))));
8773 -- pragma Debug_Policy (Check | Ignore)
8775 when Pragma_Debug_Policy =>
8777 Check_Arg_Count (1);
8778 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
8779 Debug_Pragmas_Enabled :=
8780 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
8781 Debug_Pragmas_Disabled :=
8782 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
8784 ---------------------
8785 -- Detect_Blocking --
8786 ---------------------
8788 -- pragma Detect_Blocking;
8790 when Pragma_Detect_Blocking =>
8792 Check_Arg_Count (0);
8793 Check_Valid_Configuration_Pragma;
8794 Detect_Blocking := True;
8796 --------------------------
8797 -- Default_Storage_Pool --
8798 --------------------------
8800 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
8802 when Pragma_Default_Storage_Pool =>
8804 Check_Arg_Count (1);
8806 -- Default_Storage_Pool can appear as a configuration pragma, or
8807 -- in a declarative part or a package spec.
8809 if not Is_Configuration_Pragma then
8810 Check_Is_In_Decl_Part_Or_Package_Spec;
8813 -- Case of Default_Storage_Pool (null);
8815 if Nkind (Expression (Arg1)) = N_Null then
8816 Analyze (Expression (Arg1));
8818 -- This is an odd case, this is not really an expression, so
8819 -- we don't have a type for it. So just set the type to Empty.
8821 Set_Etype (Expression (Arg1), Empty);
8823 -- Case of Default_Storage_Pool (storage_pool_NAME);
8826 -- If it's a configuration pragma, then the only allowed
8827 -- argument is "null".
8829 if Is_Configuration_Pragma then
8830 Error_Pragma_Arg ("NULL expected", Arg1);
8833 -- The expected type for a non-"null" argument is
8834 -- Root_Storage_Pool'Class.
8837 (Get_Pragma_Arg (Arg1),
8838 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8841 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
8842 -- for an access type will use this information to set the
8843 -- appropriate attributes of the access type.
8845 Default_Pool := Expression (Arg1);
8847 ------------------------------------
8848 -- Disable_Atomic_Synchronization --
8849 ------------------------------------
8851 -- pragma Disable_Atomic_Synchronization [(Entity)];
8853 when Pragma_Disable_Atomic_Synchronization =>
8854 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8860 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
8862 when Pragma_Discard_Names => Discard_Names : declare
8867 Check_Ada_83_Warning;
8869 -- Deal with configuration pragma case
8871 if Arg_Count = 0 and then Is_Configuration_Pragma then
8872 Global_Discard_Names := True;
8875 -- Otherwise, check correct appropriate context
8878 Check_Is_In_Decl_Part_Or_Package_Spec;
8880 if Arg_Count = 0 then
8882 -- If there is no parameter, then from now on this pragma
8883 -- applies to any enumeration, exception or tagged type
8884 -- defined in the current declarative part, and recursively
8885 -- to any nested scope.
8887 Set_Discard_Names (Current_Scope);
8891 Check_Arg_Count (1);
8892 Check_Optional_Identifier (Arg1, Name_On);
8893 Check_Arg_Is_Local_Name (Arg1);
8895 E_Id := Get_Pragma_Arg (Arg1);
8897 if Etype (E_Id) = Any_Type then
8903 if (Is_First_Subtype (E)
8905 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8906 or else Ekind (E) = E_Exception
8908 Set_Discard_Names (E);
8909 Record_Rep_Item (E, N);
8913 ("inappropriate entity for pragma%", Arg1);
8920 ------------------------
8921 -- Dispatching_Domain --
8922 ------------------------
8924 -- pragma Dispatching_Domain (EXPRESSION);
8926 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8927 P : constant Node_Id := Parent (N);
8933 Check_No_Identifiers;
8934 Check_Arg_Count (1);
8936 -- This pragma is born obsolete, but not the aspect
8938 if not From_Aspect_Specification (N) then
8940 (No_Obsolescent_Features, Pragma_Identifier (N));
8943 if Nkind (P) = N_Task_Definition then
8944 Arg := Get_Pragma_Arg (Arg1);
8945 Ent := Defining_Identifier (Parent (P));
8947 -- The expression must be analyzed in the special manner
8948 -- described in "Handling of Default and Per-Object
8949 -- Expressions" in sem.ads.
8951 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8953 -- Check duplicate pragma before we chain the pragma in the Rep
8954 -- Item chain of Ent.
8956 Check_Duplicate_Pragma (Ent);
8957 Record_Rep_Item (Ent, N);
8959 -- Anything else is incorrect
8964 end Dispatching_Domain;
8970 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8972 when Pragma_Elaborate => Elaborate : declare
8977 -- Pragma must be in context items list of a compilation unit
8979 if not Is_In_Context_Clause then
8983 -- Must be at least one argument
8985 if Arg_Count = 0 then
8986 Error_Pragma ("pragma% requires at least one argument");
8989 -- In Ada 83 mode, there can be no items following it in the
8990 -- context list except other pragmas and implicit with clauses
8991 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8992 -- placement rule does not apply.
8994 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8996 while Present (Citem) loop
8997 if Nkind (Citem) = N_Pragma
8998 or else (Nkind (Citem) = N_With_Clause
8999 and then Implicit_With (Citem))
9004 ("(Ada 83) pragma% must be at end of context clause");
9011 -- Finally, the arguments must all be units mentioned in a with
9012 -- clause in the same context clause. Note we already checked (in
9013 -- Par.Prag) that the arguments are all identifiers or selected
9017 Outer : while Present (Arg) loop
9018 Citem := First (List_Containing (N));
9019 Inner : while Citem /= N loop
9020 if Nkind (Citem) = N_With_Clause
9021 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
9023 Set_Elaborate_Present (Citem, True);
9024 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
9025 Generate_Reference (Entity (Name (Citem)), Citem);
9027 -- With the pragma present, elaboration calls on
9028 -- subprograms from the named unit need no further
9029 -- checks, as long as the pragma appears in the current
9030 -- compilation unit. If the pragma appears in some unit
9031 -- in the context, there might still be a need for an
9032 -- Elaborate_All_Desirable from the current compilation
9033 -- to the named unit, so we keep the check enabled.
9035 if In_Extended_Main_Source_Unit (N) then
9036 Set_Suppress_Elaboration_Warnings
9037 (Entity (Name (Citem)));
9048 ("argument of pragma% is not withed unit", Arg);
9054 -- Give a warning if operating in static mode with -gnatwl
9055 -- (elaboration warnings enabled) switch set.
9057 if Elab_Warnings and not Dynamic_Elaboration_Checks then
9059 ("?l?use of pragma Elaborate may not be safe", N);
9061 ("?l?use pragma Elaborate_All instead if possible", N);
9069 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
9071 when Pragma_Elaborate_All => Elaborate_All : declare
9076 Check_Ada_83_Warning;
9078 -- Pragma must be in context items list of a compilation unit
9080 if not Is_In_Context_Clause then
9084 -- Must be at least one argument
9086 if Arg_Count = 0 then
9087 Error_Pragma ("pragma% requires at least one argument");
9090 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
9091 -- have to appear at the end of the context clause, but may
9092 -- appear mixed in with other items, even in Ada 83 mode.
9094 -- Final check: the arguments must all be units mentioned in
9095 -- a with clause in the same context clause. Note that we
9096 -- already checked (in Par.Prag) that all the arguments are
9097 -- either identifiers or selected components.
9100 Outr : while Present (Arg) loop
9101 Citem := First (List_Containing (N));
9102 Innr : while Citem /= N loop
9103 if Nkind (Citem) = N_With_Clause
9104 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
9106 Set_Elaborate_All_Present (Citem, True);
9107 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
9109 -- Suppress warnings and elaboration checks on the named
9110 -- unit if the pragma is in the current compilation, as
9111 -- for pragma Elaborate.
9113 if In_Extended_Main_Source_Unit (N) then
9114 Set_Suppress_Elaboration_Warnings
9115 (Entity (Name (Citem)));
9124 Set_Error_Posted (N);
9126 ("argument of pragma% is not withed unit", Arg);
9133 --------------------
9134 -- Elaborate_Body --
9135 --------------------
9137 -- pragma Elaborate_Body [( library_unit_NAME )];
9139 when Pragma_Elaborate_Body => Elaborate_Body : declare
9140 Cunit_Node : Node_Id;
9141 Cunit_Ent : Entity_Id;
9144 Check_Ada_83_Warning;
9145 Check_Valid_Library_Unit_Pragma;
9147 if Nkind (N) = N_Null_Statement then
9151 Cunit_Node := Cunit (Current_Sem_Unit);
9152 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
9154 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
9157 Error_Pragma ("pragma% must refer to a spec, not a body");
9159 Set_Body_Required (Cunit_Node, True);
9160 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
9162 -- If we are in dynamic elaboration mode, then we suppress
9163 -- elaboration warnings for the unit, since it is definitely
9164 -- fine NOT to do dynamic checks at the first level (and such
9165 -- checks will be suppressed because no elaboration boolean
9166 -- is created for Elaborate_Body packages).
9168 -- But in the static model of elaboration, Elaborate_Body is
9169 -- definitely NOT good enough to ensure elaboration safety on
9170 -- its own, since the body may WITH other units that are not
9171 -- safe from an elaboration point of view, so a client must
9172 -- still do an Elaborate_All on such units.
9174 -- Debug flag -gnatdD restores the old behavior of 3.13, where
9175 -- Elaborate_Body always suppressed elab warnings.
9177 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
9178 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
9183 ------------------------
9184 -- Elaboration_Checks --
9185 ------------------------
9187 -- pragma Elaboration_Checks (Static | Dynamic);
9189 when Pragma_Elaboration_Checks =>
9191 Check_Arg_Count (1);
9192 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
9193 Dynamic_Elaboration_Checks :=
9194 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
9200 -- pragma Eliminate (
9201 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
9202 -- [,[Entity =>] IDENTIFIER |
9203 -- SELECTED_COMPONENT |
9205 -- [, OVERLOADING_RESOLUTION]);
9207 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
9210 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
9213 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
9215 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
9216 -- Result_Type => result_SUBTYPE_NAME]
9218 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
9219 -- SUBTYPE_NAME ::= STRING_LITERAL
9221 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
9222 -- SOURCE_TRACE ::= STRING_LITERAL
9224 when Pragma_Eliminate => Eliminate : declare
9225 Args : Args_List (1 .. 5);
9226 Names : constant Name_List (1 .. 5) := (
9229 Name_Parameter_Types,
9231 Name_Source_Location);
9233 Unit_Name : Node_Id renames Args (1);
9234 Entity : Node_Id renames Args (2);
9235 Parameter_Types : Node_Id renames Args (3);
9236 Result_Type : Node_Id renames Args (4);
9237 Source_Location : Node_Id renames Args (5);
9241 Check_Valid_Configuration_Pragma;
9242 Gather_Associations (Names, Args);
9244 if No (Unit_Name) then
9245 Error_Pragma ("missing Unit_Name argument for pragma%");
9249 and then (Present (Parameter_Types)
9251 Present (Result_Type)
9253 Present (Source_Location))
9255 Error_Pragma ("missing Entity argument for pragma%");
9258 if (Present (Parameter_Types)
9260 Present (Result_Type))
9262 Present (Source_Location)
9265 ("parameter profile and source location cannot " &
9266 "be used together in pragma%");
9269 Process_Eliminate_Pragma
9278 -----------------------------------
9279 -- Enable_Atomic_Synchronization --
9280 -----------------------------------
9282 -- pragma Enable_Atomic_Synchronization [(Entity)];
9284 when Pragma_Enable_Atomic_Synchronization =>
9285 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
9292 -- [ Convention =>] convention_IDENTIFIER,
9293 -- [ Entity =>] local_NAME
9294 -- [, [External_Name =>] static_string_EXPRESSION ]
9295 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9297 when Pragma_Export => Export : declare
9301 pragma Warnings (Off, C);
9304 Check_Ada_83_Warning;
9311 Check_At_Least_N_Arguments (2);
9313 Check_At_Most_N_Arguments (4);
9314 Process_Convention (C, Def_Id);
9316 if Ekind (Def_Id) /= E_Constant then
9317 Note_Possible_Modification
9318 (Get_Pragma_Arg (Arg2), Sure => False);
9321 Process_Interface_Name (Def_Id, Arg3, Arg4);
9322 Set_Exported (Def_Id, Arg2);
9324 -- If the entity is a deferred constant, propagate the information
9325 -- to the full view, because gigi elaborates the full view only.
9327 if Ekind (Def_Id) = E_Constant
9328 and then Present (Full_View (Def_Id))
9331 Id2 : constant Entity_Id := Full_View (Def_Id);
9333 Set_Is_Exported (Id2, Is_Exported (Def_Id));
9334 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
9335 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
9340 ----------------------
9341 -- Export_Exception --
9342 ----------------------
9344 -- pragma Export_Exception (
9345 -- [Internal =>] LOCAL_NAME
9346 -- [, [External =>] EXTERNAL_SYMBOL]
9347 -- [, [Form =>] Ada | VMS]
9348 -- [, [Code =>] static_integer_EXPRESSION]);
9350 when Pragma_Export_Exception => Export_Exception : declare
9351 Args : Args_List (1 .. 4);
9352 Names : constant Name_List (1 .. 4) := (
9358 Internal : Node_Id renames Args (1);
9359 External : Node_Id renames Args (2);
9360 Form : Node_Id renames Args (3);
9361 Code : Node_Id renames Args (4);
9366 if Inside_A_Generic then
9367 Error_Pragma ("pragma% cannot be used for generic entities");
9370 Gather_Associations (Names, Args);
9371 Process_Extended_Import_Export_Exception_Pragma (
9372 Arg_Internal => Internal,
9373 Arg_External => External,
9377 if not Is_VMS_Exception (Entity (Internal)) then
9378 Set_Exported (Entity (Internal), Internal);
9380 end Export_Exception;
9382 ---------------------
9383 -- Export_Function --
9384 ---------------------
9386 -- pragma Export_Function (
9387 -- [Internal =>] LOCAL_NAME
9388 -- [, [External =>] EXTERNAL_SYMBOL]
9389 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9390 -- [, [Result_Type =>] TYPE_DESIGNATOR]
9391 -- [, [Mechanism =>] MECHANISM]
9392 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
9394 -- EXTERNAL_SYMBOL ::=
9396 -- | static_string_EXPRESSION
9398 -- PARAMETER_TYPES ::=
9400 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9402 -- TYPE_DESIGNATOR ::=
9404 -- | subtype_Name ' Access
9408 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9410 -- MECHANISM_ASSOCIATION ::=
9411 -- [formal_parameter_NAME =>] MECHANISM_NAME
9413 -- MECHANISM_NAME ::=
9416 -- | Descriptor [([Class =>] CLASS_NAME)]
9418 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9420 when Pragma_Export_Function => Export_Function : declare
9421 Args : Args_List (1 .. 6);
9422 Names : constant Name_List (1 .. 6) := (
9425 Name_Parameter_Types,
9428 Name_Result_Mechanism);
9430 Internal : Node_Id renames Args (1);
9431 External : Node_Id renames Args (2);
9432 Parameter_Types : Node_Id renames Args (3);
9433 Result_Type : Node_Id renames Args (4);
9434 Mechanism : Node_Id renames Args (5);
9435 Result_Mechanism : Node_Id renames Args (6);
9439 Gather_Associations (Names, Args);
9440 Process_Extended_Import_Export_Subprogram_Pragma (
9441 Arg_Internal => Internal,
9442 Arg_External => External,
9443 Arg_Parameter_Types => Parameter_Types,
9444 Arg_Result_Type => Result_Type,
9445 Arg_Mechanism => Mechanism,
9446 Arg_Result_Mechanism => Result_Mechanism);
9447 end Export_Function;
9453 -- pragma Export_Object (
9454 -- [Internal =>] LOCAL_NAME
9455 -- [, [External =>] EXTERNAL_SYMBOL]
9456 -- [, [Size =>] EXTERNAL_SYMBOL]);
9458 -- EXTERNAL_SYMBOL ::=
9460 -- | static_string_EXPRESSION
9462 -- PARAMETER_TYPES ::=
9464 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9466 -- TYPE_DESIGNATOR ::=
9468 -- | subtype_Name ' Access
9472 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9474 -- MECHANISM_ASSOCIATION ::=
9475 -- [formal_parameter_NAME =>] MECHANISM_NAME
9477 -- MECHANISM_NAME ::=
9480 -- | Descriptor [([Class =>] CLASS_NAME)]
9482 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9484 when Pragma_Export_Object => Export_Object : declare
9485 Args : Args_List (1 .. 3);
9486 Names : constant Name_List (1 .. 3) := (
9491 Internal : Node_Id renames Args (1);
9492 External : Node_Id renames Args (2);
9493 Size : Node_Id renames Args (3);
9497 Gather_Associations (Names, Args);
9498 Process_Extended_Import_Export_Object_Pragma (
9499 Arg_Internal => Internal,
9500 Arg_External => External,
9504 ----------------------
9505 -- Export_Procedure --
9506 ----------------------
9508 -- pragma Export_Procedure (
9509 -- [Internal =>] LOCAL_NAME
9510 -- [, [External =>] EXTERNAL_SYMBOL]
9511 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9512 -- [, [Mechanism =>] MECHANISM]);
9514 -- EXTERNAL_SYMBOL ::=
9516 -- | static_string_EXPRESSION
9518 -- PARAMETER_TYPES ::=
9520 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9522 -- TYPE_DESIGNATOR ::=
9524 -- | subtype_Name ' Access
9528 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9530 -- MECHANISM_ASSOCIATION ::=
9531 -- [formal_parameter_NAME =>] MECHANISM_NAME
9533 -- MECHANISM_NAME ::=
9536 -- | Descriptor [([Class =>] CLASS_NAME)]
9538 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9540 when Pragma_Export_Procedure => Export_Procedure : declare
9541 Args : Args_List (1 .. 4);
9542 Names : constant Name_List (1 .. 4) := (
9545 Name_Parameter_Types,
9548 Internal : Node_Id renames Args (1);
9549 External : Node_Id renames Args (2);
9550 Parameter_Types : Node_Id renames Args (3);
9551 Mechanism : Node_Id renames Args (4);
9555 Gather_Associations (Names, Args);
9556 Process_Extended_Import_Export_Subprogram_Pragma (
9557 Arg_Internal => Internal,
9558 Arg_External => External,
9559 Arg_Parameter_Types => Parameter_Types,
9560 Arg_Mechanism => Mechanism);
9561 end Export_Procedure;
9567 -- pragma Export_Value (
9568 -- [Value =>] static_integer_EXPRESSION,
9569 -- [Link_Name =>] static_string_EXPRESSION);
9571 when Pragma_Export_Value =>
9573 Check_Arg_Order ((Name_Value, Name_Link_Name));
9574 Check_Arg_Count (2);
9576 Check_Optional_Identifier (Arg1, Name_Value);
9577 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9579 Check_Optional_Identifier (Arg2, Name_Link_Name);
9580 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9582 -----------------------------
9583 -- Export_Valued_Procedure --
9584 -----------------------------
9586 -- pragma Export_Valued_Procedure (
9587 -- [Internal =>] LOCAL_NAME
9588 -- [, [External =>] EXTERNAL_SYMBOL,]
9589 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9590 -- [, [Mechanism =>] MECHANISM]);
9592 -- EXTERNAL_SYMBOL ::=
9594 -- | static_string_EXPRESSION
9596 -- PARAMETER_TYPES ::=
9598 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9600 -- TYPE_DESIGNATOR ::=
9602 -- | subtype_Name ' Access
9606 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9608 -- MECHANISM_ASSOCIATION ::=
9609 -- [formal_parameter_NAME =>] MECHANISM_NAME
9611 -- MECHANISM_NAME ::=
9614 -- | Descriptor [([Class =>] CLASS_NAME)]
9616 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9618 when Pragma_Export_Valued_Procedure =>
9619 Export_Valued_Procedure : declare
9620 Args : Args_List (1 .. 4);
9621 Names : constant Name_List (1 .. 4) := (
9624 Name_Parameter_Types,
9627 Internal : Node_Id renames Args (1);
9628 External : Node_Id renames Args (2);
9629 Parameter_Types : Node_Id renames Args (3);
9630 Mechanism : Node_Id renames Args (4);
9634 Gather_Associations (Names, Args);
9635 Process_Extended_Import_Export_Subprogram_Pragma (
9636 Arg_Internal => Internal,
9637 Arg_External => External,
9638 Arg_Parameter_Types => Parameter_Types,
9639 Arg_Mechanism => Mechanism);
9640 end Export_Valued_Procedure;
9646 -- pragma Extend_System ([Name =>] Identifier);
9648 when Pragma_Extend_System => Extend_System : declare
9651 Check_Valid_Configuration_Pragma;
9652 Check_Arg_Count (1);
9653 Check_Optional_Identifier (Arg1, Name_Name);
9654 Check_Arg_Is_Identifier (Arg1);
9656 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
9659 and then Name_Buffer (1 .. 4) = "aux_"
9661 if Present (System_Extend_Pragma_Arg) then
9662 if Chars (Get_Pragma_Arg (Arg1)) =
9663 Chars (Expression (System_Extend_Pragma_Arg))
9667 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
9668 Error_Pragma ("pragma% conflicts with that #");
9672 System_Extend_Pragma_Arg := Arg1;
9674 if not GNAT_Mode then
9675 System_Extend_Unit := Arg1;
9679 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
9683 ------------------------
9684 -- Extensions_Allowed --
9685 ------------------------
9687 -- pragma Extensions_Allowed (ON | OFF);
9689 when Pragma_Extensions_Allowed =>
9691 Check_Arg_Count (1);
9692 Check_No_Identifiers;
9693 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9695 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
9696 Extensions_Allowed := True;
9697 Ada_Version := Ada_Version_Type'Last;
9700 Extensions_Allowed := False;
9701 Ada_Version := Ada_Version_Explicit;
9708 -- pragma External (
9709 -- [ Convention =>] convention_IDENTIFIER,
9710 -- [ Entity =>] local_NAME
9711 -- [, [External_Name =>] static_string_EXPRESSION ]
9712 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9714 when Pragma_External => External : declare
9718 pragma Warnings (Off, C);
9727 Check_At_Least_N_Arguments (2);
9728 Check_At_Most_N_Arguments (4);
9729 Process_Convention (C, Def_Id);
9730 Note_Possible_Modification
9731 (Get_Pragma_Arg (Arg2), Sure => False);
9732 Process_Interface_Name (Def_Id, Arg3, Arg4);
9733 Set_Exported (Def_Id, Arg2);
9736 --------------------------
9737 -- External_Name_Casing --
9738 --------------------------
9740 -- pragma External_Name_Casing (
9741 -- UPPERCASE | LOWERCASE
9742 -- [, AS_IS | UPPERCASE | LOWERCASE]);
9744 when Pragma_External_Name_Casing => External_Name_Casing : declare
9747 Check_No_Identifiers;
9749 if Arg_Count = 2 then
9751 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
9753 case Chars (Get_Pragma_Arg (Arg2)) is
9755 Opt.External_Name_Exp_Casing := As_Is;
9757 when Name_Uppercase =>
9758 Opt.External_Name_Exp_Casing := Uppercase;
9760 when Name_Lowercase =>
9761 Opt.External_Name_Exp_Casing := Lowercase;
9768 Check_Arg_Count (1);
9771 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
9773 case Chars (Get_Pragma_Arg (Arg1)) is
9774 when Name_Uppercase =>
9775 Opt.External_Name_Imp_Casing := Uppercase;
9777 when Name_Lowercase =>
9778 Opt.External_Name_Imp_Casing := Lowercase;
9783 end External_Name_Casing;
9785 --------------------------
9786 -- Favor_Top_Level --
9787 --------------------------
9789 -- pragma Favor_Top_Level (type_NAME);
9791 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
9792 Named_Entity : Entity_Id;
9796 Check_No_Identifiers;
9797 Check_Arg_Count (1);
9798 Check_Arg_Is_Local_Name (Arg1);
9799 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
9801 -- If it's an access-to-subprogram type (in particular, not a
9802 -- subtype), set the flag on that type.
9804 if Is_Access_Subprogram_Type (Named_Entity) then
9805 Set_Can_Use_Internal_Rep (Named_Entity, False);
9807 -- Otherwise it's an error (name denotes the wrong sort of entity)
9811 ("access-to-subprogram type expected",
9812 Get_Pragma_Arg (Arg1));
9814 end Favor_Top_Level;
9820 -- pragma Fast_Math;
9822 when Pragma_Fast_Math =>
9824 Check_No_Identifiers;
9825 Check_Valid_Configuration_Pragma;
9828 ---------------------------
9829 -- Finalize_Storage_Only --
9830 ---------------------------
9832 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9834 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9835 Assoc : constant Node_Id := Arg1;
9836 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9841 Check_No_Identifiers;
9842 Check_Arg_Count (1);
9843 Check_Arg_Is_Local_Name (Arg1);
9845 Find_Type (Type_Id);
9846 Typ := Entity (Type_Id);
9849 or else Rep_Item_Too_Early (Typ, N)
9853 Typ := Underlying_Type (Typ);
9856 if not Is_Controlled (Typ) then
9857 Error_Pragma ("pragma% must specify controlled type");
9860 Check_First_Subtype (Arg1);
9862 if Finalize_Storage_Only (Typ) then
9863 Error_Pragma ("duplicate pragma%, only one allowed");
9865 elsif not Rep_Item_Too_Late (Typ, N) then
9866 Set_Finalize_Storage_Only (Base_Type (Typ), True);
9868 end Finalize_Storage;
9870 --------------------------
9871 -- Float_Representation --
9872 --------------------------
9874 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9876 -- FLOAT_REP ::= VAX_Float | IEEE_Float
9878 when Pragma_Float_Representation => Float_Representation : declare
9886 if Arg_Count = 1 then
9887 Check_Valid_Configuration_Pragma;
9889 Check_Arg_Count (2);
9890 Check_Optional_Identifier (Arg2, Name_Entity);
9891 Check_Arg_Is_Local_Name (Arg2);
9894 Check_No_Identifier (Arg1);
9895 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9897 if not OpenVMS_On_Target then
9898 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9900 ("??pragma% ignored (applies only to Open'V'M'S)");
9906 -- One argument case
9908 if Arg_Count = 1 then
9909 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9910 if Opt.Float_Format = 'I' then
9911 Error_Pragma ("'I'E'E'E format previously specified");
9914 Opt.Float_Format := 'V';
9917 if Opt.Float_Format = 'V' then
9918 Error_Pragma ("'V'A'X format previously specified");
9921 Opt.Float_Format := 'I';
9924 Set_Standard_Fpt_Formats;
9926 -- Two argument case
9929 Argx := Get_Pragma_Arg (Arg2);
9931 if not Is_Entity_Name (Argx)
9932 or else not Is_Floating_Point_Type (Entity (Argx))
9935 ("second argument of% pragma must be floating-point type",
9939 Ent := Entity (Argx);
9940 Digs := UI_To_Int (Digits_Value (Ent));
9942 -- Two arguments, VAX_Float case
9944 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9946 when 6 => Set_F_Float (Ent);
9947 when 9 => Set_D_Float (Ent);
9948 when 15 => Set_G_Float (Ent);
9952 ("wrong digits value, must be 6,9 or 15", Arg2);
9955 -- Two arguments, IEEE_Float case
9959 when 6 => Set_IEEE_Short (Ent);
9960 when 15 => Set_IEEE_Long (Ent);
9964 ("wrong digits value, must be 6 or 15", Arg2);
9968 end Float_Representation;
9974 -- pragma Global (GLOBAL_SPECIFICATION)
9976 -- GLOBAL_SPECIFICATION ::= MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
9979 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
9980 -- MODE_SELECTOR ::= Input | Output | In_Out | Contract_In
9981 -- GLOBAL_LIST ::= GLOBAL_ITEM
9982 -- | (GLOBAL_ITEM {, GLOBAL_ITEM})
9983 -- GLOBAL_ITEM ::= NAME
9985 when Pragma_Global => Global : declare
9986 Subp_Id : Entity_Id;
9988 Seen : Elist_Id := No_Elist;
9989 -- A list containing the entities of all the items processed so
9990 -- far. It plays a role in detecting distinct entities.
9992 -- Flags used to verify the consistency of modes
9994 Contract_Seen : Boolean := False;
9995 In_Out_Seen : Boolean := False;
9996 Input_Seen : Boolean := False;
9997 Output_Seen : Boolean := False;
9999 procedure Analyze_Global_List
10001 Global_Mode : Name_Id := Name_Input);
10002 -- Verify the legality of a single global list declaration.
10003 -- Global_Mode denotes the current mode in effect.
10005 -------------------------
10006 -- Analyze_Global_List --
10007 -------------------------
10009 procedure Analyze_Global_List
10011 Global_Mode : Name_Id := Name_Input)
10013 procedure Analyze_Global_Item
10015 Global_Mode : Name_Id);
10016 -- Verify the legality of a single global item declaration.
10017 -- Global_Mode denotes the current mode in effect.
10019 procedure Check_Duplicate_Mode
10021 Status : in out Boolean);
10022 -- Flag Status denotes whether a particular mode has been seen
10023 -- while processing a global list. This routine verifies that
10024 -- Mode is not a duplicate mode and sets the flag Status.
10026 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
10027 -- Mode denotes either In_Out or Output. Depending on the kind
10028 -- of the related subprogram, emit an error if those two modes
10029 -- apply to a function.
10031 -------------------------
10032 -- Analyze_Global_Item --
10033 -------------------------
10035 procedure Analyze_Global_Item
10037 Global_Mode : Name_Id)
10039 function Is_Duplicate_Item (Id : Entity_Id) return Boolean;
10040 -- Determine whether Id has already been processed
10042 -----------------------
10043 -- Is_Duplicate_Item --
10044 -----------------------
10046 function Is_Duplicate_Item (Id : Entity_Id) return Boolean is
10047 Item_Elmt : Elmt_Id;
10050 if Present (Seen) then
10051 Item_Elmt := First_Elmt (Seen);
10052 while Present (Item_Elmt) loop
10053 if Node (Item_Elmt) = Id then
10057 Next_Elmt (Item_Elmt);
10062 end Is_Duplicate_Item;
10064 -- Local declarations
10068 -- Start of processing for Analyze_Global_Item
10071 -- Detect one of the following cases
10073 -- with Global => (null, Name)
10074 -- with Global => (Name_1, null, Name_2)
10075 -- with Global => (Name, null)
10077 if Nkind (Item) = N_Null then
10079 ("cannot mix null and non-null global items", Item);
10085 if Is_Entity_Name (Item) then
10086 Id := Entity (Item);
10088 -- A global item cannot reference a formal parameter. Do
10089 -- this check first to provide a better error diagnostic.
10091 if Is_Formal (Id) then
10093 ("global item cannot reference formal parameter",
10097 -- The only legal references are those to abstract states
10100 elsif not Ekind_In (Entity (Item), E_Abstract_State,
10104 ("global item must denote variable or state", Item);
10108 -- Some form of illegal construct masquerading as a name
10112 ("global item must denote variable or state", Item);
10116 -- The same entity might be referenced through various way.
10117 -- Check the entity of the item rather than the item itself.
10119 if Is_Duplicate_Item (Id) then
10120 Error_Msg_N ("duplicate global item", Item);
10122 -- Add the entity of the current item to the list of
10123 -- processed items.
10127 Seen := New_Elmt_List;
10130 Append_Elmt (Id, Seen);
10133 if Ekind (Id) = E_Abstract_State
10134 and then Is_Volatile_State (Id)
10136 -- A global item of mode In_Out or Output cannot denote a
10137 -- volatile Input state.
10139 if Is_Input_State (Id)
10140 and then (Global_Mode = Name_In_Out
10142 Global_Mode = Name_Output)
10145 ("global item of mode In_Out or Output cannot " &
10146 "reference Volatile Input state", Item);
10148 -- A global item of mode In_Out or Input cannot reference
10149 -- a volatile Output state.
10151 elsif Is_Output_State (Id)
10152 and then (Global_Mode = Name_In_Out
10154 Global_Mode = Name_Input)
10157 ("global item of mode In_Out or Input cannot "
10158 & "reference Volatile Output state", Item);
10161 end Analyze_Global_Item;
10163 --------------------------
10164 -- Check_Duplicate_Mode --
10165 --------------------------
10167 procedure Check_Duplicate_Mode
10169 Status : in out Boolean)
10173 Error_Msg_N ("duplicate global mode", Mode);
10177 end Check_Duplicate_Mode;
10179 ----------------------------------------
10180 -- Check_Mode_Restriction_In_Function --
10181 ----------------------------------------
10183 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
10185 if Ekind (Subp_Id) = E_Function then
10186 Error_Msg_Name_1 := Chars (Mode);
10188 ("global mode % not applicable to functions", Mode);
10190 end Check_Mode_Restriction_In_Function;
10198 -- Start of processing for Analyze_Global_List
10201 -- Single global item declaration
10203 if Nkind_In (List, N_Identifier, N_Selected_Component) then
10204 Analyze_Global_Item (List, Global_Mode);
10206 -- Simple global list or moded global list declaration
10208 elsif Nkind (List) = N_Aggregate then
10210 -- The declaration of a simple global list appear as a
10211 -- collection of expressions.
10213 if Present (Expressions (List)) then
10214 if Present (Component_Associations (List)) then
10216 ("cannot mix moded and non-moded global lists",
10220 Item := First (Expressions (List));
10221 while Present (Item) loop
10222 Analyze_Global_Item (Item, Global_Mode);
10227 -- The declaration of a moded global list appears as a
10228 -- collection of component associations where individual
10229 -- choices denote modes.
10231 elsif Present (Component_Associations (List)) then
10232 if Present (Expressions (List)) then
10234 ("cannot mix moded and non-moded global lists",
10238 Assoc := First (Component_Associations (List));
10239 while Present (Assoc) loop
10240 Mode := First (Choices (Assoc));
10242 if Nkind (Mode) = N_Identifier then
10243 if Chars (Mode) = Name_Contract_In then
10244 Check_Duplicate_Mode (Mode, Contract_Seen);
10246 elsif Chars (Mode) = Name_In_Out then
10247 Check_Duplicate_Mode (Mode, In_Out_Seen);
10248 Check_Mode_Restriction_In_Function (Mode);
10250 elsif Chars (Mode) = Name_Input then
10251 Check_Duplicate_Mode (Mode, Input_Seen);
10253 elsif Chars (Mode) = Name_Output then
10254 Check_Duplicate_Mode (Mode, Output_Seen);
10255 Check_Mode_Restriction_In_Function (Mode);
10258 Error_Msg_N ("invalid mode selector", Mode);
10262 Error_Msg_N ("invalid mode selector", Mode);
10265 -- Items in a moded list appear as a collection of
10266 -- expressions. Reuse the existing machinery to
10269 Analyze_Global_List
10270 (List => Expression (Assoc),
10271 Global_Mode => Chars (Mode));
10276 -- Something went horribly wrong, we have a malformed tree
10279 raise Program_Error;
10282 -- Any other attempt to declare a global item is erroneous
10285 Error_Msg_N ("malformed global list declaration", List);
10287 end Analyze_Global_List;
10294 -- Start of processing for Global
10299 Check_Arg_Count (1);
10301 -- Ensure the proper placement of the pragma. Global must be
10302 -- associated with a subprogram declaration.
10304 Subp := Parent (Corresponding_Aspect (N));
10306 if Nkind (Subp) /= N_Subprogram_Declaration then
10311 Subp_Id := Defining_Unit_Name (Specification (Subp));
10312 List := Expression (Arg1);
10314 -- There is nothing to be done for a null global list
10316 if Nkind (List) = N_Null then
10319 -- Analyze the various forms of global lists and items. Note that
10320 -- some of these may be malformed in which case the analysis emits
10324 -- Ensure that the formal parameters are visible when
10325 -- processing an item. This falls out of the general rule of
10326 -- aspects pertaining to subprogram declarations.
10328 Push_Scope (Subp_Id);
10329 Install_Formals (Subp_Id);
10331 Analyze_Global_List (List);
10341 -- pragma Ident (static_string_EXPRESSION)
10343 -- Note: pragma Comment shares this processing. Pragma Comment is
10344 -- identical to Ident, except that the restriction of the argument to
10345 -- 31 characters and the placement restrictions are not enforced for
10348 when Pragma_Ident | Pragma_Comment => Ident : declare
10353 Check_Arg_Count (1);
10354 Check_No_Identifiers;
10355 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10358 -- For pragma Ident, preserve DEC compatibility by requiring the
10359 -- pragma to appear in a declarative part or package spec.
10361 if Prag_Id = Pragma_Ident then
10362 Check_Is_In_Decl_Part_Or_Package_Spec;
10365 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
10372 GP := Parent (Parent (N));
10374 if Nkind_In (GP, N_Package_Declaration,
10375 N_Generic_Package_Declaration)
10380 -- If we have a compilation unit, then record the ident value,
10381 -- checking for improper duplication.
10383 if Nkind (GP) = N_Compilation_Unit then
10384 CS := Ident_String (Current_Sem_Unit);
10386 if Present (CS) then
10388 -- For Ident, we do not permit multiple instances
10390 if Prag_Id = Pragma_Ident then
10391 Error_Pragma ("duplicate% pragma not permitted");
10393 -- For Comment, we concatenate the string, unless we want
10394 -- to preserve the tree structure for ASIS.
10396 elsif not ASIS_Mode then
10397 Start_String (Strval (CS));
10398 Store_String_Char (' ');
10399 Store_String_Chars (Strval (Str));
10400 Set_Strval (CS, End_String);
10404 -- In VMS, the effect of IDENT is achieved by passing
10405 -- --identification=name as a --for-linker switch.
10407 if OpenVMS_On_Target then
10410 ("--for-linker=--identification=");
10411 String_To_Name_Buffer (Strval (Str));
10412 Store_String_Chars (Name_Buffer (1 .. Name_Len));
10414 -- Only the last processed IDENT is saved. The main
10415 -- purpose is so an IDENT associated with a main
10416 -- procedure will be used in preference to an IDENT
10417 -- associated with a with'd package.
10419 Replace_Linker_Option_String
10420 (End_String, "--for-linker=--identification=");
10423 Set_Ident_String (Current_Sem_Unit, Str);
10426 -- For subunits, we just ignore the Ident, since in GNAT these
10427 -- are not separate object files, and hence not separate units
10428 -- in the unit table.
10430 elsif Nkind (GP) = N_Subunit then
10433 -- Otherwise we have a misplaced pragma Ident, but we ignore
10434 -- this if we are in an instantiation, since it comes from
10435 -- a generic, and has no relevance to the instantiation.
10437 elsif Prag_Id = Pragma_Ident then
10438 if Instantiation_Location (Loc) = No_Location then
10439 Error_Pragma ("pragma% only allowed at outer level");
10445 ----------------------------
10446 -- Implementation_Defined --
10447 ----------------------------
10449 -- pragma Implementation_Defined (local_NAME);
10451 -- Marks previously declared entity as implementation defined. For
10452 -- an overloaded entity, applies to the most recent homonym.
10454 -- pragma Implementation_Defined;
10456 -- The form with no arguments appears anywhere within a scope, most
10457 -- typically a package spec, and indicates that all entities that are
10458 -- defined within the package spec are Implementation_Defined.
10460 when Pragma_Implementation_Defined => Implementation_Defined : declare
10464 Check_No_Identifiers;
10466 -- Form with no arguments
10468 if Arg_Count = 0 then
10469 Set_Is_Implementation_Defined (Current_Scope);
10471 -- Form with one argument
10474 Check_Arg_Count (1);
10475 Check_Arg_Is_Local_Name (Arg1);
10476 Ent := Entity (Get_Pragma_Arg (Arg1));
10477 Set_Is_Implementation_Defined (Ent);
10479 end Implementation_Defined;
10485 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
10487 -- IMPLEMENTATION_KIND ::=
10488 -- By_Entry | By_Protected_Procedure | By_Any | Optional
10490 -- "By_Any" and "Optional" are treated as synonyms in order to
10491 -- support Ada 2012 aspect Synchronization.
10493 when Pragma_Implemented => Implemented : declare
10494 Proc_Id : Entity_Id;
10499 Check_Arg_Count (2);
10500 Check_No_Identifiers;
10501 Check_Arg_Is_Identifier (Arg1);
10502 Check_Arg_Is_Local_Name (Arg1);
10503 Check_Arg_Is_One_Of (Arg2,
10506 Name_By_Protected_Procedure,
10509 -- Extract the name of the local procedure
10511 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
10513 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
10514 -- primitive procedure of a synchronized tagged type.
10516 if Ekind (Proc_Id) = E_Procedure
10517 and then Is_Primitive (Proc_Id)
10518 and then Present (First_Formal (Proc_Id))
10520 Typ := Etype (First_Formal (Proc_Id));
10522 if Is_Tagged_Type (Typ)
10525 -- Check for a protected, a synchronized or a task interface
10527 ((Is_Interface (Typ)
10528 and then Is_Synchronized_Interface (Typ))
10530 -- Check for a protected type or a task type that implements
10534 (Is_Concurrent_Record_Type (Typ)
10535 and then Present (Interfaces (Typ)))
10537 -- Check for a private record extension with keyword
10541 (Ekind_In (Typ, E_Record_Type_With_Private,
10542 E_Record_Subtype_With_Private)
10543 and then Synchronized_Present (Parent (Typ))))
10548 ("controlling formal must be of synchronized " &
10549 "tagged type", Arg1);
10553 -- Procedures declared inside a protected type must be accepted
10555 elsif Ekind (Proc_Id) = E_Procedure
10556 and then Is_Protected_Type (Scope (Proc_Id))
10560 -- The first argument is not a primitive procedure
10564 ("pragma % must be applied to a primitive procedure", Arg1);
10568 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
10569 -- By_Protected_Procedure to the primitive procedure of a task
10572 if Chars (Arg2) = Name_By_Protected_Procedure
10573 and then Is_Interface (Typ)
10574 and then Is_Task_Interface (Typ)
10577 ("implementation kind By_Protected_Procedure cannot be " &
10578 "applied to a task interface primitive", Arg2);
10582 Record_Rep_Item (Proc_Id, N);
10585 ----------------------
10586 -- Implicit_Packing --
10587 ----------------------
10589 -- pragma Implicit_Packing;
10591 when Pragma_Implicit_Packing =>
10593 Check_Arg_Count (0);
10594 Implicit_Packing := True;
10601 -- [Convention =>] convention_IDENTIFIER,
10602 -- [Entity =>] local_NAME
10603 -- [, [External_Name =>] static_string_EXPRESSION ]
10604 -- [, [Link_Name =>] static_string_EXPRESSION ]);
10606 when Pragma_Import =>
10607 Check_Ada_83_Warning;
10611 Name_External_Name,
10614 Check_At_Least_N_Arguments (2);
10615 Check_At_Most_N_Arguments (4);
10616 Process_Import_Or_Interface;
10618 ----------------------
10619 -- Import_Exception --
10620 ----------------------
10622 -- pragma Import_Exception (
10623 -- [Internal =>] LOCAL_NAME
10624 -- [, [External =>] EXTERNAL_SYMBOL]
10625 -- [, [Form =>] Ada | VMS]
10626 -- [, [Code =>] static_integer_EXPRESSION]);
10628 when Pragma_Import_Exception => Import_Exception : declare
10629 Args : Args_List (1 .. 4);
10630 Names : constant Name_List (1 .. 4) := (
10636 Internal : Node_Id renames Args (1);
10637 External : Node_Id renames Args (2);
10638 Form : Node_Id renames Args (3);
10639 Code : Node_Id renames Args (4);
10643 Gather_Associations (Names, Args);
10645 if Present (External) and then Present (Code) then
10647 ("cannot give both External and Code options for pragma%");
10650 Process_Extended_Import_Export_Exception_Pragma (
10651 Arg_Internal => Internal,
10652 Arg_External => External,
10656 if not Is_VMS_Exception (Entity (Internal)) then
10657 Set_Imported (Entity (Internal));
10659 end Import_Exception;
10661 ---------------------
10662 -- Import_Function --
10663 ---------------------
10665 -- pragma Import_Function (
10666 -- [Internal =>] LOCAL_NAME,
10667 -- [, [External =>] EXTERNAL_SYMBOL]
10668 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10669 -- [, [Result_Type =>] SUBTYPE_MARK]
10670 -- [, [Mechanism =>] MECHANISM]
10671 -- [, [Result_Mechanism =>] MECHANISM_NAME]
10672 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10674 -- EXTERNAL_SYMBOL ::=
10676 -- | static_string_EXPRESSION
10678 -- PARAMETER_TYPES ::=
10680 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10682 -- TYPE_DESIGNATOR ::=
10684 -- | subtype_Name ' Access
10688 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10690 -- MECHANISM_ASSOCIATION ::=
10691 -- [formal_parameter_NAME =>] MECHANISM_NAME
10693 -- MECHANISM_NAME ::=
10696 -- | Descriptor [([Class =>] CLASS_NAME)]
10698 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10700 when Pragma_Import_Function => Import_Function : declare
10701 Args : Args_List (1 .. 7);
10702 Names : constant Name_List (1 .. 7) := (
10705 Name_Parameter_Types,
10708 Name_Result_Mechanism,
10709 Name_First_Optional_Parameter);
10711 Internal : Node_Id renames Args (1);
10712 External : Node_Id renames Args (2);
10713 Parameter_Types : Node_Id renames Args (3);
10714 Result_Type : Node_Id renames Args (4);
10715 Mechanism : Node_Id renames Args (5);
10716 Result_Mechanism : Node_Id renames Args (6);
10717 First_Optional_Parameter : Node_Id renames Args (7);
10721 Gather_Associations (Names, Args);
10722 Process_Extended_Import_Export_Subprogram_Pragma (
10723 Arg_Internal => Internal,
10724 Arg_External => External,
10725 Arg_Parameter_Types => Parameter_Types,
10726 Arg_Result_Type => Result_Type,
10727 Arg_Mechanism => Mechanism,
10728 Arg_Result_Mechanism => Result_Mechanism,
10729 Arg_First_Optional_Parameter => First_Optional_Parameter);
10730 end Import_Function;
10732 -------------------
10733 -- Import_Object --
10734 -------------------
10736 -- pragma Import_Object (
10737 -- [Internal =>] LOCAL_NAME
10738 -- [, [External =>] EXTERNAL_SYMBOL]
10739 -- [, [Size =>] EXTERNAL_SYMBOL]);
10741 -- EXTERNAL_SYMBOL ::=
10743 -- | static_string_EXPRESSION
10745 when Pragma_Import_Object => Import_Object : declare
10746 Args : Args_List (1 .. 3);
10747 Names : constant Name_List (1 .. 3) := (
10752 Internal : Node_Id renames Args (1);
10753 External : Node_Id renames Args (2);
10754 Size : Node_Id renames Args (3);
10758 Gather_Associations (Names, Args);
10759 Process_Extended_Import_Export_Object_Pragma (
10760 Arg_Internal => Internal,
10761 Arg_External => External,
10765 ----------------------
10766 -- Import_Procedure --
10767 ----------------------
10769 -- pragma Import_Procedure (
10770 -- [Internal =>] LOCAL_NAME
10771 -- [, [External =>] EXTERNAL_SYMBOL]
10772 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10773 -- [, [Mechanism =>] MECHANISM]
10774 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10776 -- EXTERNAL_SYMBOL ::=
10778 -- | static_string_EXPRESSION
10780 -- PARAMETER_TYPES ::=
10782 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10784 -- TYPE_DESIGNATOR ::=
10786 -- | subtype_Name ' Access
10790 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10792 -- MECHANISM_ASSOCIATION ::=
10793 -- [formal_parameter_NAME =>] MECHANISM_NAME
10795 -- MECHANISM_NAME ::=
10798 -- | Descriptor [([Class =>] CLASS_NAME)]
10800 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10802 when Pragma_Import_Procedure => Import_Procedure : declare
10803 Args : Args_List (1 .. 5);
10804 Names : constant Name_List (1 .. 5) := (
10807 Name_Parameter_Types,
10809 Name_First_Optional_Parameter);
10811 Internal : Node_Id renames Args (1);
10812 External : Node_Id renames Args (2);
10813 Parameter_Types : Node_Id renames Args (3);
10814 Mechanism : Node_Id renames Args (4);
10815 First_Optional_Parameter : Node_Id renames Args (5);
10819 Gather_Associations (Names, Args);
10820 Process_Extended_Import_Export_Subprogram_Pragma (
10821 Arg_Internal => Internal,
10822 Arg_External => External,
10823 Arg_Parameter_Types => Parameter_Types,
10824 Arg_Mechanism => Mechanism,
10825 Arg_First_Optional_Parameter => First_Optional_Parameter);
10826 end Import_Procedure;
10828 -----------------------------
10829 -- Import_Valued_Procedure --
10830 -----------------------------
10832 -- pragma Import_Valued_Procedure (
10833 -- [Internal =>] LOCAL_NAME
10834 -- [, [External =>] EXTERNAL_SYMBOL]
10835 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10836 -- [, [Mechanism =>] MECHANISM]
10837 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10839 -- EXTERNAL_SYMBOL ::=
10841 -- | static_string_EXPRESSION
10843 -- PARAMETER_TYPES ::=
10845 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10847 -- TYPE_DESIGNATOR ::=
10849 -- | subtype_Name ' Access
10853 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10855 -- MECHANISM_ASSOCIATION ::=
10856 -- [formal_parameter_NAME =>] MECHANISM_NAME
10858 -- MECHANISM_NAME ::=
10861 -- | Descriptor [([Class =>] CLASS_NAME)]
10863 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10865 when Pragma_Import_Valued_Procedure =>
10866 Import_Valued_Procedure : declare
10867 Args : Args_List (1 .. 5);
10868 Names : constant Name_List (1 .. 5) := (
10871 Name_Parameter_Types,
10873 Name_First_Optional_Parameter);
10875 Internal : Node_Id renames Args (1);
10876 External : Node_Id renames Args (2);
10877 Parameter_Types : Node_Id renames Args (3);
10878 Mechanism : Node_Id renames Args (4);
10879 First_Optional_Parameter : Node_Id renames Args (5);
10883 Gather_Associations (Names, Args);
10884 Process_Extended_Import_Export_Subprogram_Pragma (
10885 Arg_Internal => Internal,
10886 Arg_External => External,
10887 Arg_Parameter_Types => Parameter_Types,
10888 Arg_Mechanism => Mechanism,
10889 Arg_First_Optional_Parameter => First_Optional_Parameter);
10890 end Import_Valued_Procedure;
10896 -- pragma Independent (LOCAL_NAME);
10898 when Pragma_Independent => Independent : declare
10905 Check_Ada_83_Warning;
10907 Check_No_Identifiers;
10908 Check_Arg_Count (1);
10909 Check_Arg_Is_Local_Name (Arg1);
10910 E_Id := Get_Pragma_Arg (Arg1);
10912 if Etype (E_Id) = Any_Type then
10916 E := Entity (E_Id);
10917 D := Declaration_Node (E);
10920 -- Check duplicate before we chain ourselves!
10922 Check_Duplicate_Pragma (E);
10924 -- Check appropriate entity
10926 if Is_Type (E) then
10927 if Rep_Item_Too_Early (E, N)
10929 Rep_Item_Too_Late (E, N)
10933 Check_First_Subtype (Arg1);
10936 elsif K = N_Object_Declaration
10937 or else (K = N_Component_Declaration
10938 and then Original_Record_Component (E) = E)
10940 if Rep_Item_Too_Late (E, N) then
10946 ("inappropriate entity for pragma%", Arg1);
10949 Independence_Checks.Append ((N, E));
10952 ----------------------------
10953 -- Independent_Components --
10954 ----------------------------
10956 -- pragma Atomic_Components (array_LOCAL_NAME);
10958 -- This processing is shared by Volatile_Components
10960 when Pragma_Independent_Components => Independent_Components : declare
10967 Check_Ada_83_Warning;
10969 Check_No_Identifiers;
10970 Check_Arg_Count (1);
10971 Check_Arg_Is_Local_Name (Arg1);
10972 E_Id := Get_Pragma_Arg (Arg1);
10974 if Etype (E_Id) = Any_Type then
10978 E := Entity (E_Id);
10980 -- Check duplicate before we chain ourselves!
10982 Check_Duplicate_Pragma (E);
10984 -- Check appropriate entity
10986 if Rep_Item_Too_Early (E, N)
10988 Rep_Item_Too_Late (E, N)
10993 D := Declaration_Node (E);
10996 if K = N_Full_Type_Declaration
10997 and then (Is_Array_Type (E) or else Is_Record_Type (E))
10999 Independence_Checks.Append ((N, E));
11000 Set_Has_Independent_Components (Base_Type (E));
11002 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
11003 and then Nkind (D) = N_Object_Declaration
11004 and then Nkind (Object_Definition (D)) =
11005 N_Constrained_Array_Definition
11007 Independence_Checks.Append ((N, E));
11008 Set_Has_Independent_Components (E);
11011 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
11013 end Independent_Components;
11015 ------------------------
11016 -- Initialize_Scalars --
11017 ------------------------
11019 -- pragma Initialize_Scalars;
11021 when Pragma_Initialize_Scalars =>
11023 Check_Arg_Count (0);
11024 Check_Valid_Configuration_Pragma;
11025 Check_Restriction (No_Initialize_Scalars, N);
11027 -- Initialize_Scalars creates false positives in CodePeer, and
11028 -- incorrect negative results in Alfa mode, so ignore this pragma
11031 if not Restriction_Active (No_Initialize_Scalars)
11032 and then not (CodePeer_Mode or Alfa_Mode)
11034 Init_Or_Norm_Scalars := True;
11035 Initialize_Scalars := True;
11042 -- pragma Inline ( NAME {, NAME} );
11044 when Pragma_Inline =>
11046 -- Pragma is active if inlining option is active
11048 Process_Inline (Inline_Active);
11050 -------------------
11051 -- Inline_Always --
11052 -------------------
11054 -- pragma Inline_Always ( NAME {, NAME} );
11056 when Pragma_Inline_Always =>
11059 -- Pragma always active unless in CodePeer or Alfa mode, since
11060 -- this causes walk order issues.
11062 if not (CodePeer_Mode or Alfa_Mode) then
11063 Process_Inline (True);
11066 --------------------
11067 -- Inline_Generic --
11068 --------------------
11070 -- pragma Inline_Generic (NAME {, NAME});
11072 when Pragma_Inline_Generic =>
11074 Process_Generic_List;
11076 ----------------------
11077 -- Inspection_Point --
11078 ----------------------
11080 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
11082 when Pragma_Inspection_Point => Inspection_Point : declare
11087 if Arg_Count > 0 then
11090 Exp := Get_Pragma_Arg (Arg);
11093 if not Is_Entity_Name (Exp)
11094 or else not Is_Object (Entity (Exp))
11096 Error_Pragma_Arg ("object name required", Arg);
11100 exit when No (Arg);
11103 end Inspection_Point;
11109 -- pragma Interface (
11110 -- [ Convention =>] convention_IDENTIFIER,
11111 -- [ Entity =>] local_NAME
11112 -- [, [External_Name =>] static_string_EXPRESSION ]
11113 -- [, [Link_Name =>] static_string_EXPRESSION ]);
11115 when Pragma_Interface =>
11120 Name_External_Name,
11122 Check_At_Least_N_Arguments (2);
11123 Check_At_Most_N_Arguments (4);
11124 Process_Import_Or_Interface;
11126 -- In Ada 2005, the permission to use Interface (a reserved word)
11127 -- as a pragma name is considered an obsolescent feature, and this
11128 -- pragma was already obsolescent in Ada 95.
11130 if Ada_Version >= Ada_95 then
11132 (No_Obsolescent_Features, Pragma_Identifier (N));
11134 if Warn_On_Obsolescent_Feature then
11136 ("pragma Interface is an obsolescent feature?j?", N);
11138 ("|use pragma Import instead?j?", N);
11142 --------------------
11143 -- Interface_Name --
11144 --------------------
11146 -- pragma Interface_Name (
11147 -- [ Entity =>] local_NAME
11148 -- [,[External_Name =>] static_string_EXPRESSION ]
11149 -- [,[Link_Name =>] static_string_EXPRESSION ]);
11151 when Pragma_Interface_Name => Interface_Name : declare
11153 Def_Id : Entity_Id;
11154 Hom_Id : Entity_Id;
11160 ((Name_Entity, Name_External_Name, Name_Link_Name));
11161 Check_At_Least_N_Arguments (2);
11162 Check_At_Most_N_Arguments (3);
11163 Id := Get_Pragma_Arg (Arg1);
11166 -- This is obsolete from Ada 95 on, but it is an implementation
11167 -- defined pragma, so we do not consider that it violates the
11168 -- restriction (No_Obsolescent_Features).
11170 if Ada_Version >= Ada_95 then
11171 if Warn_On_Obsolescent_Feature then
11173 ("pragma Interface_Name is an obsolescent feature?j?", N);
11175 ("|use pragma Import instead?j?", N);
11179 if not Is_Entity_Name (Id) then
11181 ("first argument for pragma% must be entity name", Arg1);
11182 elsif Etype (Id) = Any_Type then
11185 Def_Id := Entity (Id);
11188 -- Special DEC-compatible processing for the object case, forces
11189 -- object to be imported.
11191 if Ekind (Def_Id) = E_Variable then
11192 Kill_Size_Check_Code (Def_Id);
11193 Note_Possible_Modification (Id, Sure => False);
11195 -- Initialization is not allowed for imported variable
11197 if Present (Expression (Parent (Def_Id)))
11198 and then Comes_From_Source (Expression (Parent (Def_Id)))
11200 Error_Msg_Sloc := Sloc (Def_Id);
11202 ("no initialization allowed for declaration of& #",
11206 -- For compatibility, support VADS usage of providing both
11207 -- pragmas Interface and Interface_Name to obtain the effect
11208 -- of a single Import pragma.
11210 if Is_Imported (Def_Id)
11211 and then Present (First_Rep_Item (Def_Id))
11212 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
11214 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
11218 Set_Imported (Def_Id);
11221 Set_Is_Public (Def_Id);
11222 Process_Interface_Name (Def_Id, Arg2, Arg3);
11225 -- Otherwise must be subprogram
11227 elsif not Is_Subprogram (Def_Id) then
11229 ("argument of pragma% is not subprogram", Arg1);
11232 Check_At_Most_N_Arguments (3);
11236 -- Loop through homonyms
11239 Def_Id := Get_Base_Subprogram (Hom_Id);
11241 if Is_Imported (Def_Id) then
11242 Process_Interface_Name (Def_Id, Arg2, Arg3);
11246 exit when From_Aspect_Specification (N);
11247 Hom_Id := Homonym (Hom_Id);
11249 exit when No (Hom_Id)
11250 or else Scope (Hom_Id) /= Current_Scope;
11255 ("argument of pragma% is not imported subprogram",
11259 end Interface_Name;
11261 -----------------------
11262 -- Interrupt_Handler --
11263 -----------------------
11265 -- pragma Interrupt_Handler (handler_NAME);
11267 when Pragma_Interrupt_Handler =>
11268 Check_Ada_83_Warning;
11269 Check_Arg_Count (1);
11270 Check_No_Identifiers;
11272 if No_Run_Time_Mode then
11273 Error_Msg_CRT ("Interrupt_Handler pragma", N);
11275 Check_Interrupt_Or_Attach_Handler;
11276 Process_Interrupt_Or_Attach_Handler;
11279 ------------------------
11280 -- Interrupt_Priority --
11281 ------------------------
11283 -- pragma Interrupt_Priority [(EXPRESSION)];
11285 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
11286 P : constant Node_Id := Parent (N);
11291 Check_Ada_83_Warning;
11293 if Arg_Count /= 0 then
11294 Arg := Get_Pragma_Arg (Arg1);
11295 Check_Arg_Count (1);
11296 Check_No_Identifiers;
11298 -- The expression must be analyzed in the special manner
11299 -- described in "Handling of Default and Per-Object
11300 -- Expressions" in sem.ads.
11302 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
11305 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
11310 Ent := Defining_Identifier (Parent (P));
11312 -- Check duplicate pragma before we chain the pragma in the Rep
11313 -- Item chain of Ent.
11315 Check_Duplicate_Pragma (Ent);
11316 Record_Rep_Item (Ent, N);
11318 end Interrupt_Priority;
11320 ---------------------
11321 -- Interrupt_State --
11322 ---------------------
11324 -- pragma Interrupt_State (
11325 -- [Name =>] INTERRUPT_ID,
11326 -- [State =>] INTERRUPT_STATE);
11328 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
11329 -- INTERRUPT_STATE => System | Runtime | User
11331 -- Note: if the interrupt id is given as an identifier, then it must
11332 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
11333 -- given as a static integer expression which must be in the range of
11334 -- Ada.Interrupts.Interrupt_ID.
11336 when Pragma_Interrupt_State => Interrupt_State : declare
11338 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
11339 -- This is the entity Ada.Interrupts.Interrupt_ID;
11341 State_Type : Character;
11342 -- Set to 's'/'r'/'u' for System/Runtime/User
11345 -- Index to entry in Interrupt_States table
11348 -- Value of interrupt
11350 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
11351 -- The first argument to the pragma
11353 Int_Ent : Entity_Id;
11354 -- Interrupt entity in Ada.Interrupts.Names
11358 Check_Arg_Order ((Name_Name, Name_State));
11359 Check_Arg_Count (2);
11361 Check_Optional_Identifier (Arg1, Name_Name);
11362 Check_Optional_Identifier (Arg2, Name_State);
11363 Check_Arg_Is_Identifier (Arg2);
11365 -- First argument is identifier
11367 if Nkind (Arg1X) = N_Identifier then
11369 -- Search list of names in Ada.Interrupts.Names
11371 Int_Ent := First_Entity (RTE (RE_Names));
11373 if No (Int_Ent) then
11374 Error_Pragma_Arg ("invalid interrupt name", Arg1);
11376 elsif Chars (Int_Ent) = Chars (Arg1X) then
11377 Int_Val := Expr_Value (Constant_Value (Int_Ent));
11381 Next_Entity (Int_Ent);
11384 -- First argument is not an identifier, so it must be a static
11385 -- expression of type Ada.Interrupts.Interrupt_ID.
11388 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
11389 Int_Val := Expr_Value (Arg1X);
11391 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
11393 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
11396 ("value not in range of type " &
11397 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
11403 case Chars (Get_Pragma_Arg (Arg2)) is
11404 when Name_Runtime => State_Type := 'r';
11405 when Name_System => State_Type := 's';
11406 when Name_User => State_Type := 'u';
11409 Error_Pragma_Arg ("invalid interrupt state", Arg2);
11412 -- Check if entry is already stored
11414 IST_Num := Interrupt_States.First;
11416 -- If entry not found, add it
11418 if IST_Num > Interrupt_States.Last then
11419 Interrupt_States.Append
11420 ((Interrupt_Number => UI_To_Int (Int_Val),
11421 Interrupt_State => State_Type,
11422 Pragma_Loc => Loc));
11425 -- Case of entry for the same entry
11427 elsif Int_Val = Interrupt_States.Table (IST_Num).
11430 -- If state matches, done, no need to make redundant entry
11433 State_Type = Interrupt_States.Table (IST_Num).
11436 -- Otherwise if state does not match, error
11439 Interrupt_States.Table (IST_Num).Pragma_Loc;
11441 ("state conflicts with that given #", Arg2);
11445 IST_Num := IST_Num + 1;
11447 end Interrupt_State;
11453 -- pragma Invariant
11454 -- ([Entity =>] type_LOCAL_NAME,
11455 -- [Check =>] EXPRESSION
11456 -- [,[Message =>] String_Expression]);
11458 when Pragma_Invariant => Invariant : declare
11464 pragma Unreferenced (Discard);
11468 Check_At_Least_N_Arguments (2);
11469 Check_At_Most_N_Arguments (3);
11470 Check_Optional_Identifier (Arg1, Name_Entity);
11471 Check_Optional_Identifier (Arg2, Name_Check);
11473 if Arg_Count = 3 then
11474 Check_Optional_Identifier (Arg3, Name_Message);
11475 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
11478 Check_Arg_Is_Local_Name (Arg1);
11480 Type_Id := Get_Pragma_Arg (Arg1);
11481 Find_Type (Type_Id);
11482 Typ := Entity (Type_Id);
11484 if Typ = Any_Type then
11487 -- An invariant must apply to a private type, or appear in the
11488 -- private part of a package spec and apply to a completion.
11490 elsif Ekind_In (Typ, E_Private_Type,
11491 E_Record_Type_With_Private,
11492 E_Limited_Private_Type)
11496 elsif In_Private_Part (Current_Scope)
11497 and then Has_Private_Declaration (Typ)
11501 elsif In_Private_Part (Current_Scope) then
11503 ("pragma% only allowed for private type " &
11504 "declared in visible part", Arg1);
11508 ("pragma% only allowed for private type", Arg1);
11511 -- Note that the type has at least one invariant, and also that
11512 -- it has inheritable invariants if we have Invariant'Class.
11513 -- Build the corresponding invariant procedure declaration, so
11514 -- that calls to it can be generated before the body is built
11515 -- (for example wihin an expression function).
11517 PDecl := Build_Invariant_Procedure_Declaration (Typ);
11518 Insert_After (N, PDecl);
11521 if Class_Present (N) then
11522 Set_Has_Inheritable_Invariants (Typ);
11525 -- The remaining processing is simply to link the pragma on to
11526 -- the rep item chain, for processing when the type is frozen.
11527 -- This is accomplished by a call to Rep_Item_Too_Late.
11529 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11532 ----------------------
11533 -- Java_Constructor --
11534 ----------------------
11536 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
11538 -- Also handles pragma CIL_Constructor
11540 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
11541 Java_Constructor : declare
11542 Convention : Convention_Id;
11543 Def_Id : Entity_Id;
11544 Hom_Id : Entity_Id;
11546 This_Formal : Entity_Id;
11550 Check_Arg_Count (1);
11551 Check_Optional_Identifier (Arg1, Name_Entity);
11552 Check_Arg_Is_Local_Name (Arg1);
11554 Id := Get_Pragma_Arg (Arg1);
11555 Find_Program_Unit_Name (Id);
11557 -- If we did not find the name, we are done
11559 if Etype (Id) = Any_Type then
11563 -- Check wrong use of pragma in wrong VM target
11565 if VM_Target = No_VM then
11568 elsif VM_Target = CLI_Target
11569 and then Prag_Id = Pragma_Java_Constructor
11571 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
11573 elsif VM_Target = JVM_Target
11574 and then Prag_Id = Pragma_CIL_Constructor
11576 Error_Pragma ("must use pragma 'Java_'Constructor");
11580 when Pragma_CIL_Constructor => Convention := Convention_CIL;
11581 when Pragma_Java_Constructor => Convention := Convention_Java;
11582 when others => null;
11585 Hom_Id := Entity (Id);
11587 -- Loop through homonyms
11590 Def_Id := Get_Base_Subprogram (Hom_Id);
11592 -- The constructor is required to be a function
11594 if Ekind (Def_Id) /= E_Function then
11595 if VM_Target = JVM_Target then
11597 ("pragma% requires function returning a " &
11598 "'Java access type", Def_Id);
11601 ("pragma% requires function returning a " &
11602 "'C'I'L access type", Def_Id);
11606 -- Check arguments: For tagged type the first formal must be
11607 -- named "this" and its type must be a named access type
11608 -- designating a class-wide tagged type that has convention
11609 -- CIL/Java. The first formal must also have a null default
11610 -- value. For example:
11612 -- type Typ is tagged ...
11613 -- type Ref is access all Typ;
11614 -- pragma Convention (CIL, Typ);
11616 -- function New_Typ (This : Ref) return Ref;
11617 -- function New_Typ (This : Ref; I : Integer) return Ref;
11618 -- pragma Cil_Constructor (New_Typ);
11620 -- Reason: The first formal must NOT be a primitive of the
11623 -- This rule also applies to constructors of delegates used
11624 -- to interface with standard target libraries. For example:
11626 -- type Delegate is access procedure ...
11627 -- pragma Import (CIL, Delegate, ...);
11629 -- function new_Delegate
11630 -- (This : Delegate := null; ... ) return Delegate;
11632 -- For value-types this rule does not apply.
11634 if not Is_Value_Type (Etype (Def_Id)) then
11635 if No (First_Formal (Def_Id)) then
11636 Error_Msg_Name_1 := Pname;
11637 Error_Msg_N ("% function must have parameters", Def_Id);
11641 -- In the JRE library we have several occurrences in which
11642 -- the "this" parameter is not the first formal.
11644 This_Formal := First_Formal (Def_Id);
11646 -- In the JRE library we have several occurrences in which
11647 -- the "this" parameter is not the first formal. Search for
11650 if VM_Target = JVM_Target then
11651 while Present (This_Formal)
11652 and then Get_Name_String (Chars (This_Formal)) /= "this"
11654 Next_Formal (This_Formal);
11657 if No (This_Formal) then
11658 This_Formal := First_Formal (Def_Id);
11662 -- Warning: The first parameter should be named "this".
11663 -- We temporarily allow it because we have the following
11664 -- case in the Java runtime (file s-osinte.ads) ???
11666 -- function new_Thread
11667 -- (Self_Id : System.Address) return Thread_Id;
11668 -- pragma Java_Constructor (new_Thread);
11670 if VM_Target = JVM_Target
11671 and then Get_Name_String (Chars (First_Formal (Def_Id)))
11673 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
11677 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
11678 Error_Msg_Name_1 := Pname;
11680 ("first formal of % function must be named `this`",
11681 Parent (This_Formal));
11683 elsif not Is_Access_Type (Etype (This_Formal)) then
11684 Error_Msg_Name_1 := Pname;
11686 ("first formal of % function must be an access type",
11687 Parameter_Type (Parent (This_Formal)));
11689 -- For delegates the type of the first formal must be a
11690 -- named access-to-subprogram type (see previous example)
11692 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
11693 and then Ekind (Etype (This_Formal))
11694 /= E_Access_Subprogram_Type
11696 Error_Msg_Name_1 := Pname;
11698 ("first formal of % function must be a named access" &
11699 " to subprogram type",
11700 Parameter_Type (Parent (This_Formal)));
11702 -- Warning: We should reject anonymous access types because
11703 -- the constructor must not be handled as a primitive of the
11704 -- tagged type. We temporarily allow it because this profile
11705 -- is currently generated by cil2ada???
11707 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
11708 and then not Ekind_In (Etype (This_Formal),
11710 E_General_Access_Type,
11711 E_Anonymous_Access_Type)
11713 Error_Msg_Name_1 := Pname;
11715 ("first formal of % function must be a named access" &
11717 Parameter_Type (Parent (This_Formal)));
11719 elsif Atree.Convention
11720 (Designated_Type (Etype (This_Formal))) /= Convention
11722 Error_Msg_Name_1 := Pname;
11724 if Convention = Convention_Java then
11726 ("pragma% requires convention 'Cil in designated" &
11728 Parameter_Type (Parent (This_Formal)));
11731 ("pragma% requires convention 'Java in designated" &
11733 Parameter_Type (Parent (This_Formal)));
11736 elsif No (Expression (Parent (This_Formal)))
11737 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
11739 Error_Msg_Name_1 := Pname;
11741 ("pragma% requires first formal with default `null`",
11742 Parameter_Type (Parent (This_Formal)));
11746 -- Check result type: the constructor must be a function
11748 -- * a value type (only allowed in the CIL compiler)
11749 -- * an access-to-subprogram type with convention Java/CIL
11750 -- * an access-type designating a type that has convention
11753 if Is_Value_Type (Etype (Def_Id)) then
11756 -- Access-to-subprogram type with convention Java/CIL
11758 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
11759 if Atree.Convention (Etype (Def_Id)) /= Convention then
11760 if Convention = Convention_Java then
11762 ("pragma% requires function returning a " &
11763 "'Java access type", Arg1);
11765 pragma Assert (Convention = Convention_CIL);
11767 ("pragma% requires function returning a " &
11768 "'C'I'L access type", Arg1);
11772 elsif Ekind (Etype (Def_Id)) in Access_Kind then
11773 if not Ekind_In (Etype (Def_Id), E_Access_Type,
11774 E_General_Access_Type)
11777 (Designated_Type (Etype (Def_Id))) /= Convention
11779 Error_Msg_Name_1 := Pname;
11781 if Convention = Convention_Java then
11783 ("pragma% requires function returning a named" &
11784 "'Java access type", Arg1);
11787 ("pragma% requires function returning a named" &
11788 "'C'I'L access type", Arg1);
11793 Set_Is_Constructor (Def_Id);
11794 Set_Convention (Def_Id, Convention);
11795 Set_Is_Imported (Def_Id);
11797 exit when From_Aspect_Specification (N);
11798 Hom_Id := Homonym (Hom_Id);
11800 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
11802 end Java_Constructor;
11804 ----------------------
11805 -- Java_Interface --
11806 ----------------------
11808 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
11810 when Pragma_Java_Interface => Java_Interface : declare
11816 Check_Arg_Count (1);
11817 Check_Optional_Identifier (Arg1, Name_Entity);
11818 Check_Arg_Is_Local_Name (Arg1);
11820 Arg := Get_Pragma_Arg (Arg1);
11823 if Etype (Arg) = Any_Type then
11827 if not Is_Entity_Name (Arg)
11828 or else not Is_Type (Entity (Arg))
11830 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
11833 Typ := Underlying_Type (Entity (Arg));
11835 -- For now simply check some of the semantic constraints on the
11836 -- type. This currently leaves out some restrictions on interface
11837 -- types, namely that the parent type must be java.lang.Object.Typ
11838 -- and that all primitives of the type should be declared
11841 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
11842 Error_Pragma_Arg ("pragma% requires an abstract "
11843 & "tagged type", Arg1);
11845 elsif not Has_Discriminants (Typ)
11846 or else Ekind (Etype (First_Discriminant (Typ)))
11847 /= E_Anonymous_Access_Type
11849 not Is_Class_Wide_Type
11850 (Designated_Type (Etype (First_Discriminant (Typ))))
11853 ("type must have a class-wide access discriminant", Arg1);
11855 end Java_Interface;
11861 -- pragma Keep_Names ([On => ] local_NAME);
11863 when Pragma_Keep_Names => Keep_Names : declare
11868 Check_Arg_Count (1);
11869 Check_Optional_Identifier (Arg1, Name_On);
11870 Check_Arg_Is_Local_Name (Arg1);
11872 Arg := Get_Pragma_Arg (Arg1);
11875 if Etype (Arg) = Any_Type then
11879 if not Is_Entity_Name (Arg)
11880 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
11883 ("pragma% requires a local enumeration type", Arg1);
11886 Set_Discard_Names (Entity (Arg), False);
11893 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
11895 when Pragma_License =>
11897 Check_Arg_Count (1);
11898 Check_No_Identifiers;
11899 Check_Valid_Configuration_Pragma;
11900 Check_Arg_Is_Identifier (Arg1);
11903 Sind : constant Source_File_Index :=
11904 Source_Index (Current_Sem_Unit);
11907 case Chars (Get_Pragma_Arg (Arg1)) is
11909 Set_License (Sind, GPL);
11911 when Name_Modified_GPL =>
11912 Set_License (Sind, Modified_GPL);
11914 when Name_Restricted =>
11915 Set_License (Sind, Restricted);
11917 when Name_Unrestricted =>
11918 Set_License (Sind, Unrestricted);
11921 Error_Pragma_Arg ("invalid license name", Arg1);
11929 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
11931 when Pragma_Link_With => Link_With : declare
11937 if Operating_Mode = Generate_Code
11938 and then In_Extended_Main_Source_Unit (N)
11940 Check_At_Least_N_Arguments (1);
11941 Check_No_Identifiers;
11942 Check_Is_In_Decl_Part_Or_Package_Spec;
11943 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11947 while Present (Arg) loop
11948 Check_Arg_Is_Static_Expression (Arg, Standard_String);
11950 -- Store argument, converting sequences of spaces to a
11951 -- single null character (this is one of the differences
11952 -- in processing between Link_With and Linker_Options).
11954 Arg_Store : declare
11955 C : constant Char_Code := Get_Char_Code (' ');
11956 S : constant String_Id :=
11957 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
11958 L : constant Nat := String_Length (S);
11961 procedure Skip_Spaces;
11962 -- Advance F past any spaces
11968 procedure Skip_Spaces is
11970 while F <= L and then Get_String_Char (S, F) = C loop
11975 -- Start of processing for Arg_Store
11978 Skip_Spaces; -- skip leading spaces
11980 -- Loop through characters, changing any embedded
11981 -- sequence of spaces to a single null character (this
11982 -- is how Link_With/Linker_Options differ)
11985 if Get_String_Char (S, F) = C then
11988 Store_String_Char (ASCII.NUL);
11991 Store_String_Char (Get_String_Char (S, F));
11999 if Present (Arg) then
12000 Store_String_Char (ASCII.NUL);
12004 Store_Linker_Option_String (End_String);
12012 -- pragma Linker_Alias (
12013 -- [Entity =>] LOCAL_NAME
12014 -- [Target =>] static_string_EXPRESSION);
12016 when Pragma_Linker_Alias =>
12018 Check_Arg_Order ((Name_Entity, Name_Target));
12019 Check_Arg_Count (2);
12020 Check_Optional_Identifier (Arg1, Name_Entity);
12021 Check_Optional_Identifier (Arg2, Name_Target);
12022 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12023 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
12025 -- The only processing required is to link this item on to the
12026 -- list of rep items for the given entity. This is accomplished
12027 -- by the call to Rep_Item_Too_Late (when no error is detected
12028 -- and False is returned).
12030 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
12033 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
12036 ------------------------
12037 -- Linker_Constructor --
12038 ------------------------
12040 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
12042 -- Code is shared with Linker_Destructor
12044 -----------------------
12045 -- Linker_Destructor --
12046 -----------------------
12048 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
12050 when Pragma_Linker_Constructor |
12051 Pragma_Linker_Destructor =>
12052 Linker_Constructor : declare
12058 Check_Arg_Count (1);
12059 Check_No_Identifiers;
12060 Check_Arg_Is_Local_Name (Arg1);
12061 Arg1_X := Get_Pragma_Arg (Arg1);
12063 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
12065 if not Is_Library_Level_Entity (Proc) then
12067 ("argument for pragma% must be library level entity", Arg1);
12070 -- The only processing required is to link this item on to the
12071 -- list of rep items for the given entity. This is accomplished
12072 -- by the call to Rep_Item_Too_Late (when no error is detected
12073 -- and False is returned).
12075 if Rep_Item_Too_Late (Proc, N) then
12078 Set_Has_Gigi_Rep_Item (Proc);
12080 end Linker_Constructor;
12082 --------------------
12083 -- Linker_Options --
12084 --------------------
12086 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
12088 when Pragma_Linker_Options => Linker_Options : declare
12092 Check_Ada_83_Warning;
12093 Check_No_Identifiers;
12094 Check_Arg_Count (1);
12095 Check_Is_In_Decl_Part_Or_Package_Spec;
12096 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12097 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
12100 while Present (Arg) loop
12101 Check_Arg_Is_Static_Expression (Arg, Standard_String);
12102 Store_String_Char (ASCII.NUL);
12104 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
12108 if Operating_Mode = Generate_Code
12109 and then In_Extended_Main_Source_Unit (N)
12111 Store_Linker_Option_String (End_String);
12113 end Linker_Options;
12115 --------------------
12116 -- Linker_Section --
12117 --------------------
12119 -- pragma Linker_Section (
12120 -- [Entity =>] LOCAL_NAME
12121 -- [Section =>] static_string_EXPRESSION);
12123 when Pragma_Linker_Section =>
12125 Check_Arg_Order ((Name_Entity, Name_Section));
12126 Check_Arg_Count (2);
12127 Check_Optional_Identifier (Arg1, Name_Entity);
12128 Check_Optional_Identifier (Arg2, Name_Section);
12129 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12130 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
12132 -- This pragma applies only to objects
12134 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
12135 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
12138 -- The only processing required is to link this item on to the
12139 -- list of rep items for the given entity. This is accomplished
12140 -- by the call to Rep_Item_Too_Late (when no error is detected
12141 -- and False is returned).
12143 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
12146 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
12153 -- pragma List (On | Off)
12155 -- There is nothing to do here, since we did all the processing for
12156 -- this pragma in Par.Prag (so that it works properly even in syntax
12159 when Pragma_List =>
12166 -- pragma Lock_Free [(Boolean_EXPRESSION)];
12168 when Pragma_Lock_Free => Lock_Free : declare
12169 P : constant Node_Id := Parent (N);
12175 Check_No_Identifiers;
12176 Check_At_Most_N_Arguments (1);
12178 -- Protected definition case
12180 if Nkind (P) = N_Protected_Definition then
12181 Ent := Defining_Identifier (Parent (P));
12185 if Arg_Count = 1 then
12186 Arg := Get_Pragma_Arg (Arg1);
12187 Val := Is_True (Static_Boolean (Arg));
12189 -- No arguments (expression is considered to be True)
12195 -- Check duplicate pragma before we chain the pragma in the Rep
12196 -- Item chain of Ent.
12198 Check_Duplicate_Pragma (Ent);
12199 Record_Rep_Item (Ent, N);
12200 Set_Uses_Lock_Free (Ent, Val);
12202 -- Anything else is incorrect placement
12209 --------------------
12210 -- Locking_Policy --
12211 --------------------
12213 -- pragma Locking_Policy (policy_IDENTIFIER);
12215 when Pragma_Locking_Policy => declare
12216 subtype LP_Range is Name_Id
12217 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
12222 Check_Ada_83_Warning;
12223 Check_Arg_Count (1);
12224 Check_No_Identifiers;
12225 Check_Arg_Is_Locking_Policy (Arg1);
12226 Check_Valid_Configuration_Pragma;
12227 LP_Val := Chars (Get_Pragma_Arg (Arg1));
12230 when Name_Ceiling_Locking =>
12232 when Name_Inheritance_Locking =>
12234 when Name_Concurrent_Readers_Locking =>
12238 if Locking_Policy /= ' '
12239 and then Locking_Policy /= LP
12241 Error_Msg_Sloc := Locking_Policy_Sloc;
12242 Error_Pragma ("locking policy incompatible with policy#");
12244 -- Set new policy, but always preserve System_Location since we
12245 -- like the error message with the run time name.
12248 Locking_Policy := LP;
12250 if Locking_Policy_Sloc /= System_Location then
12251 Locking_Policy_Sloc := Loc;
12260 -- pragma Long_Float (D_Float | G_Float);
12262 when Pragma_Long_Float => Long_Float : declare
12265 Check_Valid_Configuration_Pragma;
12266 Check_Arg_Count (1);
12267 Check_No_Identifier (Arg1);
12268 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
12270 if not OpenVMS_On_Target then
12271 Error_Pragma ("??pragma% ignored (applies only to Open'V'M'S)");
12276 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
12277 if Opt.Float_Format_Long = 'G' then
12279 ("G_Float previously specified", Arg1);
12281 elsif Current_Sem_Unit /= Main_Unit
12282 and then Opt.Float_Format_Long /= 'D'
12285 ("main unit not compiled with pragma Long_Float (D_Float)",
12286 "\pragma% must be used consistently for whole partition",
12290 Opt.Float_Format_Long := 'D';
12293 -- G_Float case (this is the default, does not need overriding)
12296 if Opt.Float_Format_Long = 'D' then
12297 Error_Pragma ("D_Float previously specified");
12299 elsif Current_Sem_Unit /= Main_Unit
12300 and then Opt.Float_Format_Long /= 'G'
12303 ("main unit not compiled with pragma Long_Float (G_Float)",
12304 "\pragma% must be used consistently for whole partition",
12308 Opt.Float_Format_Long := 'G';
12312 Set_Standard_Fpt_Formats;
12315 --------------------
12316 -- Loop_Invariant --
12317 --------------------
12319 -- pragma Loop_Invariant ( boolean_EXPRESSION );
12321 when Pragma_Loop_Invariant => Loop_Invariant : declare
12325 Check_Arg_Count (1);
12326 Check_Loop_Invariant_Variant_Placement;
12328 -- Completely ignore if disabled
12330 if Check_Disabled (Pname) then
12331 Rewrite (N, Make_Null_Statement (Loc));
12336 Preanalyze_And_Resolve (Expression (Arg1), Any_Boolean);
12338 -- Transform pragma Loop_Invariant into equivalent pragma Check
12340 -- pragma Check (Loop_Invaraint, Arg1);
12342 -- Seems completely wrong to hijack pragma Check this way ???
12346 Chars => Name_Check,
12347 Pragma_Argument_Associations => New_List (
12348 Make_Pragma_Argument_Association (Loc,
12349 Expression => Make_Identifier (Loc, Name_Loop_Invariant)),
12350 Relocate_Node (Arg1))));
12353 end Loop_Invariant;
12359 -- pragma Loop_Variant
12360 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
12362 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
12364 -- CHANGE_DIRECTION ::= Increases | Decreases
12366 when Pragma_Loop_Variant => Loop_Variant : declare
12372 Check_At_Least_N_Arguments (1);
12373 Check_Loop_Invariant_Variant_Placement;
12375 -- Completely ignore if disabled
12377 if Check_Disabled (Pname) then
12378 Rewrite (N, Make_Null_Statement (Loc));
12383 -- Process all increasing / decreasing expressions
12385 Variant := First (Pragma_Argument_Associations (N));
12386 while Present (Variant) loop
12387 if Chars (Variant) /= Name_Decreases
12388 and then Chars (Variant) /= Name_Increases
12390 Error_Pragma_Arg ("wrong change modifier", Variant);
12393 Preanalyze_And_Resolve (Expression (Variant), Any_Discrete);
12399 -----------------------
12400 -- Machine_Attribute --
12401 -----------------------
12403 -- pragma Machine_Attribute (
12404 -- [Entity =>] LOCAL_NAME,
12405 -- [Attribute_Name =>] static_string_EXPRESSION
12406 -- [, [Info =>] static_EXPRESSION] );
12408 when Pragma_Machine_Attribute => Machine_Attribute : declare
12409 Def_Id : Entity_Id;
12413 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
12415 if Arg_Count = 3 then
12416 Check_Optional_Identifier (Arg3, Name_Info);
12417 Check_Arg_Is_Static_Expression (Arg3);
12419 Check_Arg_Count (2);
12422 Check_Optional_Identifier (Arg1, Name_Entity);
12423 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
12424 Check_Arg_Is_Local_Name (Arg1);
12425 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
12426 Def_Id := Entity (Get_Pragma_Arg (Arg1));
12428 if Is_Access_Type (Def_Id) then
12429 Def_Id := Designated_Type (Def_Id);
12432 if Rep_Item_Too_Early (Def_Id, N) then
12436 Def_Id := Underlying_Type (Def_Id);
12438 -- The only processing required is to link this item on to the
12439 -- list of rep items for the given entity. This is accomplished
12440 -- by the call to Rep_Item_Too_Late (when no error is detected
12441 -- and False is returned).
12443 if Rep_Item_Too_Late (Def_Id, N) then
12446 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
12448 end Machine_Attribute;
12455 -- (MAIN_OPTION [, MAIN_OPTION]);
12458 -- [STACK_SIZE =>] static_integer_EXPRESSION
12459 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
12460 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
12462 when Pragma_Main => Main : declare
12463 Args : Args_List (1 .. 3);
12464 Names : constant Name_List (1 .. 3) := (
12466 Name_Task_Stack_Size_Default,
12467 Name_Time_Slicing_Enabled);
12473 Gather_Associations (Names, Args);
12475 for J in 1 .. 2 loop
12476 if Present (Args (J)) then
12477 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
12481 if Present (Args (3)) then
12482 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
12486 while Present (Nod) loop
12487 if Nkind (Nod) = N_Pragma
12488 and then Pragma_Name (Nod) = Name_Main
12490 Error_Msg_Name_1 := Pname;
12491 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12502 -- pragma Main_Storage
12503 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
12505 -- MAIN_STORAGE_OPTION ::=
12506 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
12507 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
12509 when Pragma_Main_Storage => Main_Storage : declare
12510 Args : Args_List (1 .. 2);
12511 Names : constant Name_List (1 .. 2) := (
12512 Name_Working_Storage,
12519 Gather_Associations (Names, Args);
12521 for J in 1 .. 2 loop
12522 if Present (Args (J)) then
12523 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
12527 Check_In_Main_Program;
12530 while Present (Nod) loop
12531 if Nkind (Nod) = N_Pragma
12532 and then Pragma_Name (Nod) = Name_Main_Storage
12534 Error_Msg_Name_1 := Pname;
12535 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12546 -- pragma Memory_Size (NUMERIC_LITERAL)
12548 when Pragma_Memory_Size =>
12551 -- Memory size is simply ignored
12553 Check_No_Identifiers;
12554 Check_Arg_Count (1);
12555 Check_Arg_Is_Integer_Literal (Arg1);
12563 -- The only correct use of this pragma is on its own in a file, in
12564 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
12565 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
12566 -- check for a file containing nothing but a No_Body pragma). If we
12567 -- attempt to process it during normal semantics processing, it means
12568 -- it was misplaced.
12570 when Pragma_No_Body =>
12578 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
12580 when Pragma_No_Return => No_Return : declare
12588 Check_At_Least_N_Arguments (1);
12590 -- Loop through arguments of pragma
12593 while Present (Arg) loop
12594 Check_Arg_Is_Local_Name (Arg);
12595 Id := Get_Pragma_Arg (Arg);
12598 if not Is_Entity_Name (Id) then
12599 Error_Pragma_Arg ("entity name required", Arg);
12602 if Etype (Id) = Any_Type then
12606 -- Loop to find matching procedures
12611 and then Scope (E) = Current_Scope
12613 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
12616 -- Set flag on any alias as well
12618 if Is_Overloadable (E) and then Present (Alias (E)) then
12619 Set_No_Return (Alias (E));
12625 exit when From_Aspect_Specification (N);
12630 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
12641 -- pragma No_Run_Time;
12643 -- Note: this pragma is retained for backwards compatibility. See
12644 -- body of Rtsfind for full details on its handling.
12646 when Pragma_No_Run_Time =>
12648 Check_Valid_Configuration_Pragma;
12649 Check_Arg_Count (0);
12651 No_Run_Time_Mode := True;
12652 Configurable_Run_Time_Mode := True;
12654 -- Set Duration to 32 bits if word size is 32
12656 if Ttypes.System_Word_Size = 32 then
12657 Duration_32_Bits_On_Target := True;
12660 -- Set appropriate restrictions
12662 Set_Restriction (No_Finalization, N);
12663 Set_Restriction (No_Exception_Handlers, N);
12664 Set_Restriction (Max_Tasks, N, 0);
12665 Set_Restriction (No_Tasking, N);
12667 ------------------------
12668 -- No_Strict_Aliasing --
12669 ------------------------
12671 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
12673 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
12678 Check_At_Most_N_Arguments (1);
12680 if Arg_Count = 0 then
12681 Check_Valid_Configuration_Pragma;
12682 Opt.No_Strict_Aliasing := True;
12685 Check_Optional_Identifier (Arg2, Name_Entity);
12686 Check_Arg_Is_Local_Name (Arg1);
12687 E_Id := Entity (Get_Pragma_Arg (Arg1));
12689 if E_Id = Any_Type then
12691 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
12692 Error_Pragma_Arg ("pragma% requires access type", Arg1);
12695 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
12697 end No_Strict_Aliasing;
12699 -----------------------
12700 -- Normalize_Scalars --
12701 -----------------------
12703 -- pragma Normalize_Scalars;
12705 when Pragma_Normalize_Scalars =>
12706 Check_Ada_83_Warning;
12707 Check_Arg_Count (0);
12708 Check_Valid_Configuration_Pragma;
12710 -- Normalize_Scalars creates false positives in CodePeer, and
12711 -- incorrect negative results in Alfa mode, so ignore this pragma
12714 if not (CodePeer_Mode or Alfa_Mode) then
12715 Normalize_Scalars := True;
12716 Init_Or_Norm_Scalars := True;
12723 -- pragma Obsolescent;
12725 -- pragma Obsolescent (
12726 -- [Message =>] static_string_EXPRESSION
12727 -- [,[Version =>] Ada_05]]);
12729 -- pragma Obsolescent (
12730 -- [Entity =>] NAME
12731 -- [,[Message =>] static_string_EXPRESSION
12732 -- [,[Version =>] Ada_05]] );
12734 when Pragma_Obsolescent => Obsolescent : declare
12738 procedure Set_Obsolescent (E : Entity_Id);
12739 -- Given an entity Ent, mark it as obsolescent if appropriate
12741 ---------------------
12742 -- Set_Obsolescent --
12743 ---------------------
12745 procedure Set_Obsolescent (E : Entity_Id) is
12754 -- Entity name was given
12756 if Present (Ename) then
12758 -- If entity name matches, we are fine. Save entity in
12759 -- pragma argument, for ASIS use.
12761 if Chars (Ename) = Chars (Ent) then
12762 Set_Entity (Ename, Ent);
12763 Generate_Reference (Ent, Ename);
12765 -- If entity name does not match, only possibility is an
12766 -- enumeration literal from an enumeration type declaration.
12768 elsif Ekind (Ent) /= E_Enumeration_Type then
12770 ("pragma % entity name does not match declaration");
12773 Ent := First_Literal (E);
12777 ("pragma % entity name does not match any " &
12778 "enumeration literal");
12780 elsif Chars (Ent) = Chars (Ename) then
12781 Set_Entity (Ename, Ent);
12782 Generate_Reference (Ent, Ename);
12786 Ent := Next_Literal (Ent);
12792 -- Ent points to entity to be marked
12794 if Arg_Count >= 1 then
12796 -- Deal with static string argument
12798 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12799 S := Strval (Get_Pragma_Arg (Arg1));
12801 for J in 1 .. String_Length (S) loop
12802 if not In_Character_Range (Get_String_Char (S, J)) then
12804 ("pragma% argument does not allow wide characters",
12809 Obsolescent_Warnings.Append
12810 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
12812 -- Check for Ada_05 parameter
12814 if Arg_Count /= 1 then
12815 Check_Arg_Count (2);
12818 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
12821 Check_Arg_Is_Identifier (Argx);
12823 if Chars (Argx) /= Name_Ada_05 then
12824 Error_Msg_Name_2 := Name_Ada_05;
12826 ("only allowed argument for pragma% is %", Argx);
12829 if Ada_Version_Explicit < Ada_2005
12830 or else not Warn_On_Ada_2005_Compatibility
12838 -- Set flag if pragma active
12841 Set_Is_Obsolescent (Ent);
12845 end Set_Obsolescent;
12847 -- Start of processing for pragma Obsolescent
12852 Check_At_Most_N_Arguments (3);
12854 -- See if first argument specifies an entity name
12858 (Chars (Arg1) = Name_Entity
12860 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
12862 N_Operator_Symbol))
12864 Ename := Get_Pragma_Arg (Arg1);
12866 -- Eliminate first argument, so we can share processing
12870 Arg_Count := Arg_Count - 1;
12872 -- No Entity name argument given
12878 if Arg_Count >= 1 then
12879 Check_Optional_Identifier (Arg1, Name_Message);
12881 if Arg_Count = 2 then
12882 Check_Optional_Identifier (Arg2, Name_Version);
12886 -- Get immediately preceding declaration
12889 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
12893 -- Cases where we do not follow anything other than another pragma
12897 -- First case: library level compilation unit declaration with
12898 -- the pragma immediately following the declaration.
12900 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
12902 (Defining_Entity (Unit (Parent (Parent (N)))));
12905 -- Case 2: library unit placement for package
12909 Ent : constant Entity_Id := Find_Lib_Unit_Name;
12911 if Is_Package_Or_Generic_Package (Ent) then
12912 Set_Obsolescent (Ent);
12918 -- Cases where we must follow a declaration
12921 if Nkind (Decl) not in N_Declaration
12922 and then Nkind (Decl) not in N_Later_Decl_Item
12923 and then Nkind (Decl) not in N_Generic_Declaration
12924 and then Nkind (Decl) not in N_Renaming_Declaration
12927 ("pragma% misplaced, "
12928 & "must immediately follow a declaration");
12931 Set_Obsolescent (Defining_Entity (Decl));
12941 -- pragma Optimize (Time | Space | Off);
12943 -- The actual check for optimize is done in Gigi. Note that this
12944 -- pragma does not actually change the optimization setting, it
12945 -- simply checks that it is consistent with the pragma.
12947 when Pragma_Optimize =>
12948 Check_No_Identifiers;
12949 Check_Arg_Count (1);
12950 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
12952 ------------------------
12953 -- Optimize_Alignment --
12954 ------------------------
12956 -- pragma Optimize_Alignment (Time | Space | Off);
12958 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
12960 Check_No_Identifiers;
12961 Check_Arg_Count (1);
12962 Check_Valid_Configuration_Pragma;
12965 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
12969 Opt.Optimize_Alignment := 'T';
12971 Opt.Optimize_Alignment := 'S';
12973 Opt.Optimize_Alignment := 'O';
12975 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
12979 -- Set indication that mode is set locally. If we are in fact in a
12980 -- configuration pragma file, this setting is harmless since the
12981 -- switch will get reset anyway at the start of each unit.
12983 Optimize_Alignment_Local := True;
12984 end Optimize_Alignment;
12986 -------------------
12987 -- Overflow_Mode --
12988 -------------------
12990 -- pragma Overflow_Mode
12991 -- ([General => ] MODE [, [Assertions => ] MODE]);
12993 -- MODE := STRICT | MINIMIZED | ELIMINATED
12995 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
12996 -- since System.Bignums makes this assumption. This is true of nearly
12997 -- all (all?) targets.
12999 when Pragma_Overflow_Mode => Overflow_Mode : declare
13000 function Get_Overflow_Mode
13002 Arg : Node_Id) return Overflow_Mode_Type;
13003 -- Function to process one pragma argument, Arg. If an identifier
13004 -- is present, it must be Name. Mode type is returned if a valid
13005 -- argument exists, otherwise an error is signalled.
13007 -----------------------
13008 -- Get_Overflow_Mode --
13009 -----------------------
13011 function Get_Overflow_Mode
13013 Arg : Node_Id) return Overflow_Mode_Type
13015 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
13018 Check_Optional_Identifier (Arg, Name);
13019 Check_Arg_Is_Identifier (Argx);
13021 if Chars (Argx) = Name_Strict then
13024 elsif Chars (Argx) = Name_Minimized then
13027 elsif Chars (Argx) = Name_Eliminated then
13028 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
13030 ("Eliminated not implemented on this target", Argx);
13036 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
13038 end Get_Overflow_Mode;
13040 -- Start of processing for Overflow_Mode
13044 Check_At_Least_N_Arguments (1);
13045 Check_At_Most_N_Arguments (2);
13047 -- Process first argument
13049 Scope_Suppress.Overflow_Mode_General :=
13050 Get_Overflow_Mode (Name_General, Arg1);
13052 -- Case of only one argument
13054 if Arg_Count = 1 then
13055 Scope_Suppress.Overflow_Mode_Assertions :=
13056 Scope_Suppress.Overflow_Mode_General;
13058 -- Case of two arguments present
13061 Scope_Suppress.Overflow_Mode_Assertions :=
13062 Get_Overflow_Mode (Name_Assertions, Arg2);
13070 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
13072 when Pragma_Ordered => Ordered : declare
13073 Assoc : constant Node_Id := Arg1;
13079 Check_No_Identifiers;
13080 Check_Arg_Count (1);
13081 Check_Arg_Is_Local_Name (Arg1);
13083 Type_Id := Get_Pragma_Arg (Assoc);
13084 Find_Type (Type_Id);
13085 Typ := Entity (Type_Id);
13087 if Typ = Any_Type then
13090 Typ := Underlying_Type (Typ);
13093 if not Is_Enumeration_Type (Typ) then
13094 Error_Pragma ("pragma% must specify enumeration type");
13097 Check_First_Subtype (Arg1);
13098 Set_Has_Pragma_Ordered (Base_Type (Typ));
13105 -- pragma Pack (first_subtype_LOCAL_NAME);
13107 when Pragma_Pack => Pack : declare
13108 Assoc : constant Node_Id := Arg1;
13112 Ignore : Boolean := False;
13115 Check_No_Identifiers;
13116 Check_Arg_Count (1);
13117 Check_Arg_Is_Local_Name (Arg1);
13119 Type_Id := Get_Pragma_Arg (Assoc);
13120 Find_Type (Type_Id);
13121 Typ := Entity (Type_Id);
13124 or else Rep_Item_Too_Early (Typ, N)
13128 Typ := Underlying_Type (Typ);
13131 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
13132 Error_Pragma ("pragma% must specify array or record type");
13135 Check_First_Subtype (Arg1);
13136 Check_Duplicate_Pragma (Typ);
13140 if Is_Array_Type (Typ) then
13141 Ctyp := Component_Type (Typ);
13143 -- Ignore pack that does nothing
13145 if Known_Static_Esize (Ctyp)
13146 and then Known_Static_RM_Size (Ctyp)
13147 and then Esize (Ctyp) = RM_Size (Ctyp)
13148 and then Addressable (Esize (Ctyp))
13153 -- Process OK pragma Pack. Note that if there is a separate
13154 -- component clause present, the Pack will be cancelled. This
13155 -- processing is in Freeze.
13157 if not Rep_Item_Too_Late (Typ, N) then
13159 -- In the context of static code analysis, we do not need
13160 -- complex front-end expansions related to pragma Pack,
13161 -- so disable handling of pragma Pack in these cases.
13163 if CodePeer_Mode or Alfa_Mode then
13166 -- Don't attempt any packing for VM targets. We possibly
13167 -- could deal with some cases of array bit-packing, but we
13168 -- don't bother, since this is not a typical kind of
13169 -- representation in the VM context anyway (and would not
13170 -- for example work nicely with the debugger).
13172 elsif VM_Target /= No_VM then
13173 if not GNAT_Mode then
13175 ("??pragma% ignored in this configuration");
13178 -- Normal case where we do the pack action
13182 Set_Is_Packed (Base_Type (Typ));
13183 Set_Has_Non_Standard_Rep (Base_Type (Typ));
13186 Set_Has_Pragma_Pack (Base_Type (Typ));
13190 -- For record types, the pack is always effective
13192 else pragma Assert (Is_Record_Type (Typ));
13193 if not Rep_Item_Too_Late (Typ, N) then
13195 -- Ignore pack request with warning in VM mode (skip warning
13196 -- if we are compiling GNAT run time library).
13198 if VM_Target /= No_VM then
13199 if not GNAT_Mode then
13201 ("??pragma% ignored in this configuration");
13204 -- Normal case of pack request active
13207 Set_Is_Packed (Base_Type (Typ));
13208 Set_Has_Pragma_Pack (Base_Type (Typ));
13209 Set_Has_Non_Standard_Rep (Base_Type (Typ));
13221 -- There is nothing to do here, since we did all the processing for
13222 -- this pragma in Par.Prag (so that it works properly even in syntax
13225 when Pragma_Page =>
13228 ----------------------------------
13229 -- Partition_Elaboration_Policy --
13230 ----------------------------------
13232 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
13234 when Pragma_Partition_Elaboration_Policy => declare
13235 subtype PEP_Range is Name_Id
13236 range First_Partition_Elaboration_Policy_Name
13237 .. Last_Partition_Elaboration_Policy_Name;
13238 PEP_Val : PEP_Range;
13243 Check_Arg_Count (1);
13244 Check_No_Identifiers;
13245 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
13246 Check_Valid_Configuration_Pragma;
13247 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
13250 when Name_Concurrent =>
13252 when Name_Sequential =>
13256 if Partition_Elaboration_Policy /= ' '
13257 and then Partition_Elaboration_Policy /= PEP
13259 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
13261 ("partition elaboration policy incompatible with policy#");
13263 -- Set new policy, but always preserve System_Location since we
13264 -- like the error message with the run time name.
13267 Partition_Elaboration_Policy := PEP;
13269 if Partition_Elaboration_Policy_Sloc /= System_Location then
13270 Partition_Elaboration_Policy_Sloc := Loc;
13279 -- pragma Passive [(PASSIVE_FORM)];
13281 -- PASSIVE_FORM ::= Semaphore | No
13283 when Pragma_Passive =>
13286 if Nkind (Parent (N)) /= N_Task_Definition then
13287 Error_Pragma ("pragma% must be within task definition");
13290 if Arg_Count /= 0 then
13291 Check_Arg_Count (1);
13292 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
13295 ----------------------------------
13296 -- Preelaborable_Initialization --
13297 ----------------------------------
13299 -- pragma Preelaborable_Initialization (DIRECT_NAME);
13301 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
13306 Check_Arg_Count (1);
13307 Check_No_Identifiers;
13308 Check_Arg_Is_Identifier (Arg1);
13309 Check_Arg_Is_Local_Name (Arg1);
13310 Check_First_Subtype (Arg1);
13311 Ent := Entity (Get_Pragma_Arg (Arg1));
13313 if not (Is_Private_Type (Ent)
13315 Is_Protected_Type (Ent)
13317 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
13320 ("pragma % can only be applied to private, formal derived or "
13321 & "protected type",
13325 -- Give an error if the pragma is applied to a protected type that
13326 -- does not qualify (due to having entries, or due to components
13327 -- that do not qualify).
13329 if Is_Protected_Type (Ent)
13330 and then not Has_Preelaborable_Initialization (Ent)
13333 ("protected type & does not have preelaborable " &
13334 "initialization", Ent);
13336 -- Otherwise mark the type as definitely having preelaborable
13340 Set_Known_To_Have_Preelab_Init (Ent);
13343 if Has_Pragma_Preelab_Init (Ent)
13344 and then Warn_On_Redundant_Constructs
13346 Error_Pragma ("?r?duplicate pragma%!");
13348 Set_Has_Pragma_Preelab_Init (Ent);
13352 --------------------
13353 -- Persistent_BSS --
13354 --------------------
13356 -- pragma Persistent_BSS [(object_NAME)];
13358 when Pragma_Persistent_BSS => Persistent_BSS : declare
13365 Check_At_Most_N_Arguments (1);
13367 -- Case of application to specific object (one argument)
13369 if Arg_Count = 1 then
13370 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13372 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
13374 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
13377 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
13380 Ent := Entity (Get_Pragma_Arg (Arg1));
13381 Decl := Parent (Ent);
13383 -- Check for duplication before inserting in list of
13384 -- representation items.
13386 Check_Duplicate_Pragma (Ent);
13388 if Rep_Item_Too_Late (Ent, N) then
13392 if Present (Expression (Decl)) then
13394 ("object for pragma% cannot have initialization", Arg1);
13397 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
13399 ("object type for pragma% is not potentially persistent",
13404 Make_Linker_Section_Pragma
13405 (Ent, Sloc (N), ".persistent.bss");
13406 Insert_After (N, Prag);
13409 -- Case of use as configuration pragma with no arguments
13412 Check_Valid_Configuration_Pragma;
13413 Persistent_BSS_Mode := True;
13415 end Persistent_BSS;
13421 -- pragma Polling (ON | OFF);
13423 when Pragma_Polling =>
13425 Check_Arg_Count (1);
13426 Check_No_Identifiers;
13427 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13428 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
13430 -------------------
13431 -- Postcondition --
13432 -------------------
13434 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
13435 -- [,[Message =>] String_EXPRESSION]);
13437 when Pragma_Postcondition => Postcondition : declare
13442 Check_At_Least_N_Arguments (1);
13443 Check_At_Most_N_Arguments (2);
13444 Check_Optional_Identifier (Arg1, Name_Check);
13446 -- Verify the proper placement of the pragma. The remainder of the
13447 -- processing is found in Sem_Ch6/Sem_Ch7.
13449 Check_Precondition_Postcondition (In_Body);
13451 -- When the pragma is a source contruct and appears inside a body,
13452 -- preanalyze the boolean_expression to detect illegal forward
13456 -- pragma Postcondition (X'Old ...);
13459 if Comes_From_Source (N) and then In_Body then
13460 Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
13468 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
13469 -- [,[Message =>] String_EXPRESSION]);
13471 when Pragma_Precondition => Precondition : declare
13476 Check_At_Least_N_Arguments (1);
13477 Check_At_Most_N_Arguments (2);
13478 Check_Optional_Identifier (Arg1, Name_Check);
13479 Check_Precondition_Postcondition (In_Body);
13481 -- If in spec, nothing more to do. If in body, then we convert the
13482 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
13483 -- this whether or not precondition checks are enabled. That works
13484 -- fine since pragma Check will do this check, and will also
13485 -- analyze the condition itself in the proper context.
13490 Chars => Name_Check,
13491 Pragma_Argument_Associations => New_List (
13492 Make_Pragma_Argument_Association (Loc,
13493 Expression => Make_Identifier (Loc, Name_Precondition)),
13495 Make_Pragma_Argument_Association (Sloc (Arg1),
13496 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
13498 if Arg_Count = 2 then
13499 Append_To (Pragma_Argument_Associations (N),
13500 Make_Pragma_Argument_Association (Sloc (Arg2),
13501 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
13512 -- pragma Predicate
13513 -- ([Entity =>] type_LOCAL_NAME,
13514 -- [Check =>] EXPRESSION);
13516 when Pragma_Predicate => Predicate : declare
13521 pragma Unreferenced (Discard);
13525 Check_Arg_Count (2);
13526 Check_Optional_Identifier (Arg1, Name_Entity);
13527 Check_Optional_Identifier (Arg2, Name_Check);
13529 Check_Arg_Is_Local_Name (Arg1);
13531 Type_Id := Get_Pragma_Arg (Arg1);
13532 Find_Type (Type_Id);
13533 Typ := Entity (Type_Id);
13535 if Typ = Any_Type then
13539 -- The remaining processing is simply to link the pragma on to
13540 -- the rep item chain, for processing when the type is frozen.
13541 -- This is accomplished by a call to Rep_Item_Too_Late. We also
13542 -- mark the type as having predicates.
13544 Set_Has_Predicates (Typ);
13545 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
13552 -- pragma Preelaborate [(library_unit_NAME)];
13554 -- Set the flag Is_Preelaborated of program unit name entity
13556 when Pragma_Preelaborate => Preelaborate : declare
13557 Pa : constant Node_Id := Parent (N);
13558 Pk : constant Node_Kind := Nkind (Pa);
13562 Check_Ada_83_Warning;
13563 Check_Valid_Library_Unit_Pragma;
13565 if Nkind (N) = N_Null_Statement then
13569 Ent := Find_Lib_Unit_Name;
13570 Check_Duplicate_Pragma (Ent);
13572 -- This filters out pragmas inside generic parent then
13573 -- show up inside instantiation
13576 and then not (Pk = N_Package_Specification
13577 and then Present (Generic_Parent (Pa)))
13579 if not Debug_Flag_U then
13580 Set_Is_Preelaborated (Ent);
13581 Set_Suppress_Elaboration_Warnings (Ent);
13586 ---------------------
13587 -- Preelaborate_05 --
13588 ---------------------
13590 -- pragma Preelaborate_05 [(library_unit_NAME)];
13592 -- This pragma is useable only in GNAT_Mode, where it is used like
13593 -- pragma Preelaborate but it is only effective in Ada 2005 mode
13594 -- (otherwise it is ignored). This is used to implement AI-362 which
13595 -- recategorizes some run-time packages in Ada 2005 mode.
13597 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
13602 Check_Valid_Library_Unit_Pragma;
13604 if not GNAT_Mode then
13605 Error_Pragma ("pragma% only available in GNAT mode");
13608 if Nkind (N) = N_Null_Statement then
13612 -- This is one of the few cases where we need to test the value of
13613 -- Ada_Version_Explicit rather than Ada_Version (which is always
13614 -- set to Ada_2012 in a predefined unit), we need to know the
13615 -- explicit version set to know if this pragma is active.
13617 if Ada_Version_Explicit >= Ada_2005 then
13618 Ent := Find_Lib_Unit_Name;
13619 Set_Is_Preelaborated (Ent);
13620 Set_Suppress_Elaboration_Warnings (Ent);
13622 end Preelaborate_05;
13628 -- pragma Priority (EXPRESSION);
13630 when Pragma_Priority => Priority : declare
13631 P : constant Node_Id := Parent (N);
13636 Check_No_Identifiers;
13637 Check_Arg_Count (1);
13641 if Nkind (P) = N_Subprogram_Body then
13642 Check_In_Main_Program;
13644 Ent := Defining_Unit_Name (Specification (P));
13646 if Nkind (Ent) = N_Defining_Program_Unit_Name then
13647 Ent := Defining_Identifier (Ent);
13650 Arg := Get_Pragma_Arg (Arg1);
13651 Analyze_And_Resolve (Arg, Standard_Integer);
13655 if not Is_Static_Expression (Arg) then
13656 Flag_Non_Static_Expr
13657 ("main subprogram priority is not static!", Arg);
13660 -- If constraint error, then we already signalled an error
13662 elsif Raises_Constraint_Error (Arg) then
13665 -- Otherwise check in range
13669 Val : constant Uint := Expr_Value (Arg);
13673 or else Val > Expr_Value (Expression
13674 (Parent (RTE (RE_Max_Priority))))
13677 ("main subprogram priority is out of range", Arg1);
13683 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
13685 -- Load an arbitrary entity from System.Tasking to make sure
13686 -- this package is implicitly with'ed, since we need to have
13687 -- the tasking run-time active for the pragma Priority to have
13691 Discard : Entity_Id;
13692 pragma Warnings (Off, Discard);
13694 Discard := RTE (RE_Task_List);
13697 -- Task or Protected, must be of type Integer
13699 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
13700 Arg := Get_Pragma_Arg (Arg1);
13701 Ent := Defining_Identifier (Parent (P));
13703 -- The expression must be analyzed in the special manner
13704 -- described in "Handling of Default and Per-Object
13705 -- Expressions" in sem.ads.
13707 Preanalyze_Spec_Expression (Arg, Standard_Integer);
13709 if not Is_Static_Expression (Arg) then
13710 Check_Restriction (Static_Priorities, Arg);
13713 -- Anything else is incorrect
13719 -- Check duplicate pragma before we chain the pragma in the Rep
13720 -- Item chain of Ent.
13722 Check_Duplicate_Pragma (Ent);
13723 Record_Rep_Item (Ent, N);
13726 -----------------------------------
13727 -- Priority_Specific_Dispatching --
13728 -----------------------------------
13730 -- pragma Priority_Specific_Dispatching (
13731 -- policy_IDENTIFIER,
13732 -- first_priority_EXPRESSION,
13733 -- last_priority_EXPRESSION);
13735 when Pragma_Priority_Specific_Dispatching =>
13736 Priority_Specific_Dispatching : declare
13737 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
13738 -- This is the entity System.Any_Priority;
13741 Lower_Bound : Node_Id;
13742 Upper_Bound : Node_Id;
13748 Check_Arg_Count (3);
13749 Check_No_Identifiers;
13750 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13751 Check_Valid_Configuration_Pragma;
13752 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13753 DP := Fold_Upper (Name_Buffer (1));
13755 Lower_Bound := Get_Pragma_Arg (Arg2);
13756 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
13757 Lower_Val := Expr_Value (Lower_Bound);
13759 Upper_Bound := Get_Pragma_Arg (Arg3);
13760 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
13761 Upper_Val := Expr_Value (Upper_Bound);
13763 -- It is not allowed to use Task_Dispatching_Policy and
13764 -- Priority_Specific_Dispatching in the same partition.
13766 if Task_Dispatching_Policy /= ' ' then
13767 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13769 ("pragma% incompatible with Task_Dispatching_Policy#");
13771 -- Check lower bound in range
13773 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
13775 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
13778 ("first_priority is out of range", Arg2);
13780 -- Check upper bound in range
13782 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
13784 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
13787 ("last_priority is out of range", Arg3);
13789 -- Check that the priority range is valid
13791 elsif Lower_Val > Upper_Val then
13793 ("last_priority_expression must be greater than" &
13794 " or equal to first_priority_expression");
13796 -- Store the new policy, but always preserve System_Location since
13797 -- we like the error message with the run-time name.
13800 -- Check overlapping in the priority ranges specified in other
13801 -- Priority_Specific_Dispatching pragmas within the same
13802 -- partition. We can only check those we know about!
13805 Specific_Dispatching.First .. Specific_Dispatching.Last
13807 if Specific_Dispatching.Table (J).First_Priority in
13808 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
13809 or else Specific_Dispatching.Table (J).Last_Priority in
13810 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
13813 Specific_Dispatching.Table (J).Pragma_Loc;
13815 ("priority range overlaps with "
13816 & "Priority_Specific_Dispatching#");
13820 -- The use of Priority_Specific_Dispatching is incompatible
13821 -- with Task_Dispatching_Policy.
13823 if Task_Dispatching_Policy /= ' ' then
13824 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13826 ("Priority_Specific_Dispatching incompatible "
13827 & "with Task_Dispatching_Policy#");
13830 -- The use of Priority_Specific_Dispatching forces ceiling
13833 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
13834 Error_Msg_Sloc := Locking_Policy_Sloc;
13836 ("Priority_Specific_Dispatching incompatible "
13837 & "with Locking_Policy#");
13839 -- Set the Ceiling_Locking policy, but preserve System_Location
13840 -- since we like the error message with the run time name.
13843 Locking_Policy := 'C';
13845 if Locking_Policy_Sloc /= System_Location then
13846 Locking_Policy_Sloc := Loc;
13850 -- Add entry in the table
13852 Specific_Dispatching.Append
13853 ((Dispatching_Policy => DP,
13854 First_Priority => UI_To_Int (Lower_Val),
13855 Last_Priority => UI_To_Int (Upper_Val),
13856 Pragma_Loc => Loc));
13858 end Priority_Specific_Dispatching;
13864 -- pragma Profile (profile_IDENTIFIER);
13866 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
13868 when Pragma_Profile =>
13870 Check_Arg_Count (1);
13871 Check_Valid_Configuration_Pragma;
13872 Check_No_Identifiers;
13875 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13878 if Chars (Argx) = Name_Ravenscar then
13879 Set_Ravenscar_Profile (N);
13881 elsif Chars (Argx) = Name_Restricted then
13882 Set_Profile_Restrictions
13884 N, Warn => Treat_Restrictions_As_Warnings);
13886 elsif Chars (Argx) = Name_Rational then
13887 Rational_Profile := True;
13889 elsif Chars (Argx) = Name_No_Implementation_Extensions then
13890 Set_Profile_Restrictions
13891 (No_Implementation_Extensions,
13892 N, Warn => Treat_Restrictions_As_Warnings);
13895 Error_Pragma_Arg ("& is not a valid profile", Argx);
13899 ----------------------
13900 -- Profile_Warnings --
13901 ----------------------
13903 -- pragma Profile_Warnings (profile_IDENTIFIER);
13905 -- profile_IDENTIFIER => Restricted | Ravenscar
13907 when Pragma_Profile_Warnings =>
13909 Check_Arg_Count (1);
13910 Check_Valid_Configuration_Pragma;
13911 Check_No_Identifiers;
13914 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13917 if Chars (Argx) = Name_Ravenscar then
13918 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
13920 elsif Chars (Argx) = Name_Restricted then
13921 Set_Profile_Restrictions (Restricted, N, Warn => True);
13923 elsif Chars (Argx) = Name_No_Implementation_Extensions then
13924 Set_Profile_Restrictions
13925 (No_Implementation_Extensions, N, Warn => True);
13928 Error_Pragma_Arg ("& is not a valid profile", Argx);
13932 --------------------------
13933 -- Propagate_Exceptions --
13934 --------------------------
13936 -- pragma Propagate_Exceptions;
13938 -- Note: this pragma is obsolete and has no effect
13940 when Pragma_Propagate_Exceptions =>
13942 Check_Arg_Count (0);
13944 if In_Extended_Main_Source_Unit (N) then
13945 Propagate_Exceptions := True;
13952 -- pragma Psect_Object (
13953 -- [Internal =>] LOCAL_NAME,
13954 -- [, [External =>] EXTERNAL_SYMBOL]
13955 -- [, [Size =>] EXTERNAL_SYMBOL]);
13957 when Pragma_Psect_Object | Pragma_Common_Object =>
13958 Psect_Object : declare
13959 Args : Args_List (1 .. 3);
13960 Names : constant Name_List (1 .. 3) := (
13965 Internal : Node_Id renames Args (1);
13966 External : Node_Id renames Args (2);
13967 Size : Node_Id renames Args (3);
13969 Def_Id : Entity_Id;
13971 procedure Check_Too_Long (Arg : Node_Id);
13972 -- Posts message if the argument is an identifier with more
13973 -- than 31 characters, or a string literal with more than
13974 -- 31 characters, and we are operating under VMS
13976 --------------------
13977 -- Check_Too_Long --
13978 --------------------
13980 procedure Check_Too_Long (Arg : Node_Id) is
13981 X : constant Node_Id := Original_Node (Arg);
13984 if not Nkind_In (X, N_String_Literal, N_Identifier) then
13986 ("inappropriate argument for pragma %", Arg);
13989 if OpenVMS_On_Target then
13990 if (Nkind (X) = N_String_Literal
13991 and then String_Length (Strval (X)) > 31)
13993 (Nkind (X) = N_Identifier
13994 and then Length_Of_Name (Chars (X)) > 31)
13997 ("argument for pragma % is longer than 31 characters",
14001 end Check_Too_Long;
14003 -- Start of processing for Common_Object/Psect_Object
14007 Gather_Associations (Names, Args);
14008 Process_Extended_Import_Export_Internal_Arg (Internal);
14010 Def_Id := Entity (Internal);
14012 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
14014 ("pragma% must designate an object", Internal);
14017 Check_Too_Long (Internal);
14019 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
14021 ("cannot use pragma% for imported/exported object",
14025 if Is_Concurrent_Type (Etype (Internal)) then
14027 ("cannot specify pragma % for task/protected object",
14031 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
14033 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
14035 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
14038 if Ekind (Def_Id) = E_Constant then
14040 ("cannot specify pragma % for a constant", Internal);
14043 if Is_Record_Type (Etype (Internal)) then
14049 Ent := First_Entity (Etype (Internal));
14050 while Present (Ent) loop
14051 Decl := Declaration_Node (Ent);
14053 if Ekind (Ent) = E_Component
14054 and then Nkind (Decl) = N_Component_Declaration
14055 and then Present (Expression (Decl))
14056 and then Warn_On_Export_Import
14059 ("?x?object for pragma % has defaults", Internal);
14069 if Present (Size) then
14070 Check_Too_Long (Size);
14073 if Present (External) then
14074 Check_Arg_Is_External_Name (External);
14075 Check_Too_Long (External);
14078 -- If all error tests pass, link pragma on to the rep item chain
14080 Record_Rep_Item (Def_Id, N);
14087 -- pragma Pure [(library_unit_NAME)];
14089 when Pragma_Pure => Pure : declare
14093 Check_Ada_83_Warning;
14094 Check_Valid_Library_Unit_Pragma;
14096 if Nkind (N) = N_Null_Statement then
14100 Ent := Find_Lib_Unit_Name;
14102 Set_Has_Pragma_Pure (Ent);
14103 Set_Suppress_Elaboration_Warnings (Ent);
14110 -- pragma Pure_05 [(library_unit_NAME)];
14112 -- This pragma is useable only in GNAT_Mode, where it is used like
14113 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
14114 -- it is ignored). It may be used after a pragma Preelaborate, in
14115 -- which case it overrides the effect of the pragma Preelaborate.
14116 -- This is used to implement AI-362 which recategorizes some run-time
14117 -- packages in Ada 2005 mode.
14119 when Pragma_Pure_05 => Pure_05 : declare
14124 Check_Valid_Library_Unit_Pragma;
14126 if not GNAT_Mode then
14127 Error_Pragma ("pragma% only available in GNAT mode");
14130 if Nkind (N) = N_Null_Statement then
14134 -- This is one of the few cases where we need to test the value of
14135 -- Ada_Version_Explicit rather than Ada_Version (which is always
14136 -- set to Ada_2012 in a predefined unit), we need to know the
14137 -- explicit version set to know if this pragma is active.
14139 if Ada_Version_Explicit >= Ada_2005 then
14140 Ent := Find_Lib_Unit_Name;
14141 Set_Is_Preelaborated (Ent, False);
14143 Set_Suppress_Elaboration_Warnings (Ent);
14151 -- pragma Pure_12 [(library_unit_NAME)];
14153 -- This pragma is useable only in GNAT_Mode, where it is used like
14154 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
14155 -- it is ignored). It may be used after a pragma Preelaborate, in
14156 -- which case it overrides the effect of the pragma Preelaborate.
14157 -- This is used to implement AI05-0212 which recategorizes some
14158 -- run-time packages in Ada 2012 mode.
14160 when Pragma_Pure_12 => Pure_12 : declare
14165 Check_Valid_Library_Unit_Pragma;
14167 if not GNAT_Mode then
14168 Error_Pragma ("pragma% only available in GNAT mode");
14171 if Nkind (N) = N_Null_Statement then
14175 -- This is one of the few cases where we need to test the value of
14176 -- Ada_Version_Explicit rather than Ada_Version (which is always
14177 -- set to Ada_2012 in a predefined unit), we need to know the
14178 -- explicit version set to know if this pragma is active.
14180 if Ada_Version_Explicit >= Ada_2012 then
14181 Ent := Find_Lib_Unit_Name;
14182 Set_Is_Preelaborated (Ent, False);
14184 Set_Suppress_Elaboration_Warnings (Ent);
14188 -------------------
14189 -- Pure_Function --
14190 -------------------
14192 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
14194 when Pragma_Pure_Function => Pure_Function : declare
14197 Def_Id : Entity_Id;
14198 Effective : Boolean := False;
14202 Check_Arg_Count (1);
14203 Check_Optional_Identifier (Arg1, Name_Entity);
14204 Check_Arg_Is_Local_Name (Arg1);
14205 E_Id := Get_Pragma_Arg (Arg1);
14207 if Error_Posted (E_Id) then
14211 -- Loop through homonyms (overloadings) of referenced entity
14213 E := Entity (E_Id);
14215 if Present (E) then
14217 Def_Id := Get_Base_Subprogram (E);
14219 if not Ekind_In (Def_Id, E_Function,
14220 E_Generic_Function,
14224 ("pragma% requires a function name", Arg1);
14227 Set_Is_Pure (Def_Id);
14229 if not Has_Pragma_Pure_Function (Def_Id) then
14230 Set_Has_Pragma_Pure_Function (Def_Id);
14234 exit when From_Aspect_Specification (N);
14236 exit when No (E) or else Scope (E) /= Current_Scope;
14240 and then Warn_On_Redundant_Constructs
14243 ("pragma Pure_Function on& is redundant?r?",
14249 --------------------
14250 -- Queuing_Policy --
14251 --------------------
14253 -- pragma Queuing_Policy (policy_IDENTIFIER);
14255 when Pragma_Queuing_Policy => declare
14259 Check_Ada_83_Warning;
14260 Check_Arg_Count (1);
14261 Check_No_Identifiers;
14262 Check_Arg_Is_Queuing_Policy (Arg1);
14263 Check_Valid_Configuration_Pragma;
14264 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14265 QP := Fold_Upper (Name_Buffer (1));
14267 if Queuing_Policy /= ' '
14268 and then Queuing_Policy /= QP
14270 Error_Msg_Sloc := Queuing_Policy_Sloc;
14271 Error_Pragma ("queuing policy incompatible with policy#");
14273 -- Set new policy, but always preserve System_Location since we
14274 -- like the error message with the run time name.
14277 Queuing_Policy := QP;
14279 if Queuing_Policy_Sloc /= System_Location then
14280 Queuing_Policy_Sloc := Loc;
14289 -- pragma Rational, for compatibility with foreign compiler
14291 when Pragma_Rational =>
14292 Rational_Profile := True;
14294 -----------------------
14295 -- Relative_Deadline --
14296 -----------------------
14298 -- pragma Relative_Deadline (time_span_EXPRESSION);
14300 when Pragma_Relative_Deadline => Relative_Deadline : declare
14301 P : constant Node_Id := Parent (N);
14306 Check_No_Identifiers;
14307 Check_Arg_Count (1);
14309 Arg := Get_Pragma_Arg (Arg1);
14311 -- The expression must be analyzed in the special manner described
14312 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
14314 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
14318 if Nkind (P) = N_Subprogram_Body then
14319 Check_In_Main_Program;
14321 -- Only Task and subprogram cases allowed
14323 elsif Nkind (P) /= N_Task_Definition then
14327 -- Check duplicate pragma before we set the corresponding flag
14329 if Has_Relative_Deadline_Pragma (P) then
14330 Error_Pragma ("duplicate pragma% not allowed");
14333 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
14334 -- Relative_Deadline pragma node cannot be inserted in the Rep
14335 -- Item chain of Ent since it is rewritten by the expander as a
14336 -- procedure call statement that will break the chain.
14338 Set_Has_Relative_Deadline_Pragma (P, True);
14339 end Relative_Deadline;
14341 ------------------------
14342 -- Remote_Access_Type --
14343 ------------------------
14345 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
14347 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
14352 Check_Arg_Count (1);
14353 Check_Optional_Identifier (Arg1, Name_Entity);
14354 Check_Arg_Is_Local_Name (Arg1);
14356 E := Entity (Get_Pragma_Arg (Arg1));
14358 if Nkind (Parent (E)) = N_Formal_Type_Declaration
14359 and then Ekind (E) = E_General_Access_Type
14360 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
14361 and then Scope (Root_Type (Directly_Designated_Type (E)))
14363 and then Is_Valid_Remote_Object_Type
14364 (Root_Type (Directly_Designated_Type (E)))
14366 Set_Is_Remote_Types (E);
14370 ("pragma% applies only to formal access to classwide types",
14373 end Remote_Access_Type;
14375 ---------------------------
14376 -- Remote_Call_Interface --
14377 ---------------------------
14379 -- pragma Remote_Call_Interface [(library_unit_NAME)];
14381 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
14382 Cunit_Node : Node_Id;
14383 Cunit_Ent : Entity_Id;
14387 Check_Ada_83_Warning;
14388 Check_Valid_Library_Unit_Pragma;
14390 if Nkind (N) = N_Null_Statement then
14394 Cunit_Node := Cunit (Current_Sem_Unit);
14395 K := Nkind (Unit (Cunit_Node));
14396 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14398 if K = N_Package_Declaration
14399 or else K = N_Generic_Package_Declaration
14400 or else K = N_Subprogram_Declaration
14401 or else K = N_Generic_Subprogram_Declaration
14402 or else (K = N_Subprogram_Body
14403 and then Acts_As_Spec (Unit (Cunit_Node)))
14408 "pragma% must apply to package or subprogram declaration");
14411 Set_Is_Remote_Call_Interface (Cunit_Ent);
14412 end Remote_Call_Interface;
14418 -- pragma Remote_Types [(library_unit_NAME)];
14420 when Pragma_Remote_Types => Remote_Types : declare
14421 Cunit_Node : Node_Id;
14422 Cunit_Ent : Entity_Id;
14425 Check_Ada_83_Warning;
14426 Check_Valid_Library_Unit_Pragma;
14428 if Nkind (N) = N_Null_Statement then
14432 Cunit_Node := Cunit (Current_Sem_Unit);
14433 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14435 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
14436 N_Generic_Package_Declaration)
14439 ("pragma% can only apply to a package declaration");
14442 Set_Is_Remote_Types (Cunit_Ent);
14449 -- pragma Ravenscar;
14451 when Pragma_Ravenscar =>
14453 Check_Arg_Count (0);
14454 Check_Valid_Configuration_Pragma;
14455 Set_Ravenscar_Profile (N);
14457 if Warn_On_Obsolescent_Feature then
14459 ("pragma Ravenscar is an obsolescent feature?j?", N);
14461 ("|use pragma Profile (Ravenscar) instead?j?", N);
14464 -------------------------
14465 -- Restricted_Run_Time --
14466 -------------------------
14468 -- pragma Restricted_Run_Time;
14470 when Pragma_Restricted_Run_Time =>
14472 Check_Arg_Count (0);
14473 Check_Valid_Configuration_Pragma;
14474 Set_Profile_Restrictions
14475 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
14477 if Warn_On_Obsolescent_Feature then
14479 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
14482 ("|use pragma Profile (Restricted) instead?j?", N);
14489 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
14492 -- restriction_IDENTIFIER
14493 -- | restriction_parameter_IDENTIFIER => EXPRESSION
14495 when Pragma_Restrictions =>
14496 Process_Restrictions_Or_Restriction_Warnings
14497 (Warn => Treat_Restrictions_As_Warnings);
14499 --------------------------
14500 -- Restriction_Warnings --
14501 --------------------------
14503 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
14506 -- restriction_IDENTIFIER
14507 -- | restriction_parameter_IDENTIFIER => EXPRESSION
14509 when Pragma_Restriction_Warnings =>
14511 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
14517 -- pragma Reviewable;
14519 when Pragma_Reviewable =>
14520 Check_Ada_83_Warning;
14521 Check_Arg_Count (0);
14523 -- Call dummy debugging function rv. This is done to assist front
14524 -- end debugging. By placing a Reviewable pragma in the source
14525 -- program, a breakpoint on rv catches this place in the source,
14526 -- allowing convenient stepping to the point of interest.
14530 --------------------------
14531 -- Short_Circuit_And_Or --
14532 --------------------------
14534 when Pragma_Short_Circuit_And_Or =>
14536 Check_Arg_Count (0);
14537 Check_Valid_Configuration_Pragma;
14538 Short_Circuit_And_Or := True;
14540 -------------------
14541 -- Share_Generic --
14542 -------------------
14544 -- pragma Share_Generic (NAME {, NAME});
14546 when Pragma_Share_Generic =>
14548 Process_Generic_List;
14554 -- pragma Shared (LOCAL_NAME);
14556 when Pragma_Shared =>
14558 Process_Atomic_Shared_Volatile;
14560 --------------------
14561 -- Shared_Passive --
14562 --------------------
14564 -- pragma Shared_Passive [(library_unit_NAME)];
14566 -- Set the flag Is_Shared_Passive of program unit name entity
14568 when Pragma_Shared_Passive => Shared_Passive : declare
14569 Cunit_Node : Node_Id;
14570 Cunit_Ent : Entity_Id;
14573 Check_Ada_83_Warning;
14574 Check_Valid_Library_Unit_Pragma;
14576 if Nkind (N) = N_Null_Statement then
14580 Cunit_Node := Cunit (Current_Sem_Unit);
14581 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14583 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
14584 N_Generic_Package_Declaration)
14587 ("pragma% can only apply to a package declaration");
14590 Set_Is_Shared_Passive (Cunit_Ent);
14591 end Shared_Passive;
14593 -----------------------
14594 -- Short_Descriptors --
14595 -----------------------
14597 -- pragma Short_Descriptors;
14599 when Pragma_Short_Descriptors =>
14601 Check_Arg_Count (0);
14602 Check_Valid_Configuration_Pragma;
14603 Short_Descriptors := True;
14605 ------------------------------
14606 -- Simple_Storage_Pool_Type --
14607 ------------------------------
14609 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
14611 when Pragma_Simple_Storage_Pool_Type =>
14612 Simple_Storage_Pool_Type : declare
14618 Check_Arg_Count (1);
14619 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14621 Type_Id := Get_Pragma_Arg (Arg1);
14622 Find_Type (Type_Id);
14623 Typ := Entity (Type_Id);
14625 if Typ = Any_Type then
14629 -- We require the pragma to apply to a type declared in a package
14630 -- declaration, but not (immediately) within a package body.
14632 if Ekind (Current_Scope) /= E_Package
14633 or else In_Package_Body (Current_Scope)
14636 ("pragma% can only apply to type declared immediately " &
14637 "within a package declaration");
14640 -- A simple storage pool type must be an immutably limited record
14641 -- or private type. If the pragma is given for a private type,
14642 -- the full type is similarly restricted (which is checked later
14643 -- in Freeze_Entity).
14645 if Is_Record_Type (Typ)
14646 and then not Is_Immutably_Limited_Type (Typ)
14649 ("pragma% can only apply to explicitly limited record type");
14651 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
14653 ("pragma% can only apply to a private type that is limited");
14655 elsif not Is_Record_Type (Typ)
14656 and then not Is_Private_Type (Typ)
14659 ("pragma% can only apply to limited record or private type");
14662 Record_Rep_Item (Typ, N);
14663 end Simple_Storage_Pool_Type;
14665 ----------------------
14666 -- Source_File_Name --
14667 ----------------------
14669 -- There are five forms for this pragma:
14671 -- pragma Source_File_Name (
14672 -- [UNIT_NAME =>] unit_NAME,
14673 -- BODY_FILE_NAME => STRING_LITERAL
14674 -- [, [INDEX =>] INTEGER_LITERAL]);
14676 -- pragma Source_File_Name (
14677 -- [UNIT_NAME =>] unit_NAME,
14678 -- SPEC_FILE_NAME => STRING_LITERAL
14679 -- [, [INDEX =>] INTEGER_LITERAL]);
14681 -- pragma Source_File_Name (
14682 -- BODY_FILE_NAME => STRING_LITERAL
14683 -- [, DOT_REPLACEMENT => STRING_LITERAL]
14684 -- [, CASING => CASING_SPEC]);
14686 -- pragma Source_File_Name (
14687 -- SPEC_FILE_NAME => STRING_LITERAL
14688 -- [, DOT_REPLACEMENT => STRING_LITERAL]
14689 -- [, CASING => CASING_SPEC]);
14691 -- pragma Source_File_Name (
14692 -- SUBUNIT_FILE_NAME => STRING_LITERAL
14693 -- [, DOT_REPLACEMENT => STRING_LITERAL]
14694 -- [, CASING => CASING_SPEC]);
14696 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
14698 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
14699 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
14700 -- only be used when no project file is used, while SFNP can only be
14701 -- used when a project file is used.
14703 -- No processing here. Processing was completed during parsing, since
14704 -- we need to have file names set as early as possible. Units are
14705 -- loaded well before semantic processing starts.
14707 -- The only processing we defer to this point is the check for
14708 -- correct placement.
14710 when Pragma_Source_File_Name =>
14712 Check_Valid_Configuration_Pragma;
14714 ------------------------------
14715 -- Source_File_Name_Project --
14716 ------------------------------
14718 -- See Source_File_Name for syntax
14720 -- No processing here. Processing was completed during parsing, since
14721 -- we need to have file names set as early as possible. Units are
14722 -- loaded well before semantic processing starts.
14724 -- The only processing we defer to this point is the check for
14725 -- correct placement.
14727 when Pragma_Source_File_Name_Project =>
14729 Check_Valid_Configuration_Pragma;
14731 -- Check that a pragma Source_File_Name_Project is used only in a
14732 -- configuration pragmas file.
14734 -- Pragmas Source_File_Name_Project should only be generated by
14735 -- the Project Manager in configuration pragmas files.
14737 -- This is really an ugly test. It seems to depend on some
14738 -- accidental and undocumented property. At the very least it
14739 -- needs to be documented, but it would be better to have a
14740 -- clean way of testing if we are in a configuration file???
14742 if Present (Parent (N)) then
14744 ("pragma% can only appear in a configuration pragmas file");
14747 ----------------------
14748 -- Source_Reference --
14749 ----------------------
14751 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
14753 -- Nothing to do, all processing completed in Par.Prag, since we need
14754 -- the information for possible parser messages that are output.
14756 when Pragma_Source_Reference =>
14759 --------------------------------
14760 -- Static_Elaboration_Desired --
14761 --------------------------------
14763 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
14765 when Pragma_Static_Elaboration_Desired =>
14767 Check_At_Most_N_Arguments (1);
14769 if Is_Compilation_Unit (Current_Scope)
14770 and then Ekind (Current_Scope) = E_Package
14772 Set_Static_Elaboration_Desired (Current_Scope, True);
14774 Error_Pragma ("pragma% must apply to a library-level package");
14781 -- pragma Storage_Size (EXPRESSION);
14783 when Pragma_Storage_Size => Storage_Size : declare
14784 P : constant Node_Id := Parent (N);
14788 Check_No_Identifiers;
14789 Check_Arg_Count (1);
14791 -- The expression must be analyzed in the special manner described
14792 -- in "Handling of Default Expressions" in sem.ads.
14794 Arg := Get_Pragma_Arg (Arg1);
14795 Preanalyze_Spec_Expression (Arg, Any_Integer);
14797 if not Is_Static_Expression (Arg) then
14798 Check_Restriction (Static_Storage_Size, Arg);
14801 if Nkind (P) /= N_Task_Definition then
14806 if Has_Storage_Size_Pragma (P) then
14807 Error_Pragma ("duplicate pragma% not allowed");
14809 Set_Has_Storage_Size_Pragma (P, True);
14812 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
14820 -- pragma Storage_Unit (NUMERIC_LITERAL);
14822 -- Only permitted argument is System'Storage_Unit value
14824 when Pragma_Storage_Unit =>
14825 Check_No_Identifiers;
14826 Check_Arg_Count (1);
14827 Check_Arg_Is_Integer_Literal (Arg1);
14829 if Intval (Get_Pragma_Arg (Arg1)) /=
14830 UI_From_Int (Ttypes.System_Storage_Unit)
14832 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
14834 ("the only allowed argument for pragma% is ^", Arg1);
14837 --------------------
14838 -- Stream_Convert --
14839 --------------------
14841 -- pragma Stream_Convert (
14842 -- [Entity =>] type_LOCAL_NAME,
14843 -- [Read =>] function_NAME,
14844 -- [Write =>] function NAME);
14846 when Pragma_Stream_Convert => Stream_Convert : declare
14848 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
14849 -- Check that the given argument is the name of a local function
14850 -- of one argument that is not overloaded earlier in the current
14851 -- local scope. A check is also made that the argument is a
14852 -- function with one parameter.
14854 --------------------------------------
14855 -- Check_OK_Stream_Convert_Function --
14856 --------------------------------------
14858 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
14862 Check_Arg_Is_Local_Name (Arg);
14863 Ent := Entity (Get_Pragma_Arg (Arg));
14865 if Has_Homonym (Ent) then
14867 ("argument for pragma% may not be overloaded", Arg);
14870 if Ekind (Ent) /= E_Function
14871 or else No (First_Formal (Ent))
14872 or else Present (Next_Formal (First_Formal (Ent)))
14875 ("argument for pragma% must be" &
14876 " function of one argument", Arg);
14878 end Check_OK_Stream_Convert_Function;
14880 -- Start of processing for Stream_Convert
14884 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
14885 Check_Arg_Count (3);
14886 Check_Optional_Identifier (Arg1, Name_Entity);
14887 Check_Optional_Identifier (Arg2, Name_Read);
14888 Check_Optional_Identifier (Arg3, Name_Write);
14889 Check_Arg_Is_Local_Name (Arg1);
14890 Check_OK_Stream_Convert_Function (Arg2);
14891 Check_OK_Stream_Convert_Function (Arg3);
14894 Typ : constant Entity_Id :=
14895 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
14896 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
14897 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
14900 Check_First_Subtype (Arg1);
14902 -- Check for too early or too late. Note that we don't enforce
14903 -- the rule about primitive operations in this case, since, as
14904 -- is the case for explicit stream attributes themselves, these
14905 -- restrictions are not appropriate. Note that the chaining of
14906 -- the pragma by Rep_Item_Too_Late is actually the critical
14907 -- processing done for this pragma.
14909 if Rep_Item_Too_Early (Typ, N)
14911 Rep_Item_Too_Late (Typ, N, FOnly => True)
14916 -- Return if previous error
14918 if Etype (Typ) = Any_Type
14920 Etype (Read) = Any_Type
14922 Etype (Write) = Any_Type
14929 if Underlying_Type (Etype (Read)) /= Typ then
14931 ("incorrect return type for function&", Arg2);
14934 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
14936 ("incorrect parameter type for function&", Arg3);
14939 if Underlying_Type (Etype (First_Formal (Read))) /=
14940 Underlying_Type (Etype (Write))
14943 ("result type of & does not match Read parameter type",
14947 end Stream_Convert;
14953 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14955 -- This is processed by the parser since some of the style checks
14956 -- take place during source scanning and parsing. This means that
14957 -- we don't need to issue error messages here.
14959 when Pragma_Style_Checks => Style_Checks : declare
14960 A : constant Node_Id := Get_Pragma_Arg (Arg1);
14966 Check_No_Identifiers;
14968 -- Two argument form
14970 if Arg_Count = 2 then
14971 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14978 E_Id := Get_Pragma_Arg (Arg2);
14981 if not Is_Entity_Name (E_Id) then
14983 ("second argument of pragma% must be entity name",
14987 E := Entity (E_Id);
14989 if not Ignore_Style_Checks_Pragmas then
14994 Set_Suppress_Style_Checks
14995 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
14996 exit when No (Homonym (E));
15003 -- One argument form
15006 Check_Arg_Count (1);
15008 if Nkind (A) = N_String_Literal then
15012 Slen : constant Natural := Natural (String_Length (S));
15013 Options : String (1 .. Slen);
15019 C := Get_String_Char (S, Int (J));
15020 exit when not In_Character_Range (C);
15021 Options (J) := Get_Character (C);
15023 -- If at end of string, set options. As per discussion
15024 -- above, no need to check for errors, since we issued
15025 -- them in the parser.
15028 if not Ignore_Style_Checks_Pragmas then
15029 Set_Style_Check_Options (Options);
15039 elsif Nkind (A) = N_Identifier then
15040 if Chars (A) = Name_All_Checks then
15041 if not Ignore_Style_Checks_Pragmas then
15043 Set_GNAT_Style_Check_Options;
15045 Set_Default_Style_Check_Options;
15049 elsif Chars (A) = Name_On then
15050 if not Ignore_Style_Checks_Pragmas then
15051 Style_Check := True;
15054 elsif Chars (A) = Name_Off then
15055 if not Ignore_Style_Checks_Pragmas then
15056 Style_Check := False;
15067 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
15069 when Pragma_Subtitle =>
15071 Check_Arg_Count (1);
15072 Check_Optional_Identifier (Arg1, Name_Subtitle);
15073 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
15080 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
15082 when Pragma_Suppress =>
15083 Process_Suppress_Unsuppress (True);
15089 -- pragma Suppress_All;
15091 -- The only check made here is that the pragma has no arguments.
15092 -- There are no placement rules, and the processing required (setting
15093 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
15094 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
15095 -- then creates and inserts a pragma Suppress (All_Checks).
15097 when Pragma_Suppress_All =>
15099 Check_Arg_Count (0);
15101 -------------------------
15102 -- Suppress_Debug_Info --
15103 -------------------------
15105 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
15107 when Pragma_Suppress_Debug_Info =>
15109 Check_Arg_Count (1);
15110 Check_Optional_Identifier (Arg1, Name_Entity);
15111 Check_Arg_Is_Local_Name (Arg1);
15112 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
15114 ----------------------------------
15115 -- Suppress_Exception_Locations --
15116 ----------------------------------
15118 -- pragma Suppress_Exception_Locations;
15120 when Pragma_Suppress_Exception_Locations =>
15122 Check_Arg_Count (0);
15123 Check_Valid_Configuration_Pragma;
15124 Exception_Locations_Suppressed := True;
15126 -----------------------------
15127 -- Suppress_Initialization --
15128 -----------------------------
15130 -- pragma Suppress_Initialization ([Entity =>] type_Name);
15132 when Pragma_Suppress_Initialization => Suppress_Init : declare
15138 Check_Arg_Count (1);
15139 Check_Optional_Identifier (Arg1, Name_Entity);
15140 Check_Arg_Is_Local_Name (Arg1);
15142 E_Id := Get_Pragma_Arg (Arg1);
15144 if Etype (E_Id) = Any_Type then
15148 E := Entity (E_Id);
15150 if not Is_Type (E) then
15151 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
15154 if Rep_Item_Too_Early (E, N)
15156 Rep_Item_Too_Late (E, N, FOnly => True)
15161 -- For incomplete/private type, set flag on full view
15163 if Is_Incomplete_Or_Private_Type (E) then
15164 if No (Full_View (Base_Type (E))) then
15166 ("argument of pragma% cannot be an incomplete type", Arg1);
15168 Set_Suppress_Initialization (Full_View (Base_Type (E)));
15171 -- For first subtype, set flag on base type
15173 elsif Is_First_Subtype (E) then
15174 Set_Suppress_Initialization (Base_Type (E));
15176 -- For other than first subtype, set flag on subtype itself
15179 Set_Suppress_Initialization (E);
15187 -- pragma System_Name (DIRECT_NAME);
15189 -- Syntax check: one argument, which must be the identifier GNAT or
15190 -- the identifier GCC, no other identifiers are acceptable.
15192 when Pragma_System_Name =>
15194 Check_No_Identifiers;
15195 Check_Arg_Count (1);
15196 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
15198 -----------------------------
15199 -- Task_Dispatching_Policy --
15200 -----------------------------
15202 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
15204 when Pragma_Task_Dispatching_Policy => declare
15208 Check_Ada_83_Warning;
15209 Check_Arg_Count (1);
15210 Check_No_Identifiers;
15211 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
15212 Check_Valid_Configuration_Pragma;
15213 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15214 DP := Fold_Upper (Name_Buffer (1));
15216 if Task_Dispatching_Policy /= ' '
15217 and then Task_Dispatching_Policy /= DP
15219 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
15221 ("task dispatching policy incompatible with policy#");
15223 -- Set new policy, but always preserve System_Location since we
15224 -- like the error message with the run time name.
15227 Task_Dispatching_Policy := DP;
15229 if Task_Dispatching_Policy_Sloc /= System_Location then
15230 Task_Dispatching_Policy_Sloc := Loc;
15239 -- pragma Task_Info (EXPRESSION);
15241 when Pragma_Task_Info => Task_Info : declare
15242 P : constant Node_Id := Parent (N);
15248 if Nkind (P) /= N_Task_Definition then
15249 Error_Pragma ("pragma% must appear in task definition");
15252 Check_No_Identifiers;
15253 Check_Arg_Count (1);
15255 Analyze_And_Resolve
15256 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
15258 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
15262 Ent := Defining_Identifier (Parent (P));
15264 -- Check duplicate pragma before we chain the pragma in the Rep
15265 -- Item chain of Ent.
15268 (Ent, Name_Task_Info, Check_Parents => False)
15270 Error_Pragma ("duplicate pragma% not allowed");
15273 Record_Rep_Item (Ent, N);
15280 -- pragma Task_Name (string_EXPRESSION);
15282 when Pragma_Task_Name => Task_Name : declare
15283 P : constant Node_Id := Parent (N);
15288 Check_No_Identifiers;
15289 Check_Arg_Count (1);
15291 Arg := Get_Pragma_Arg (Arg1);
15293 -- The expression is used in the call to Create_Task, and must be
15294 -- expanded there, not in the context of the current spec. It must
15295 -- however be analyzed to capture global references, in case it
15296 -- appears in a generic context.
15298 Preanalyze_And_Resolve (Arg, Standard_String);
15300 if Nkind (P) /= N_Task_Definition then
15304 Ent := Defining_Identifier (Parent (P));
15306 -- Check duplicate pragma before we chain the pragma in the Rep
15307 -- Item chain of Ent.
15310 (Ent, Name_Task_Name, Check_Parents => False)
15312 Error_Pragma ("duplicate pragma% not allowed");
15315 Record_Rep_Item (Ent, N);
15322 -- pragma Task_Storage (
15323 -- [Task_Type =>] LOCAL_NAME,
15324 -- [Top_Guard =>] static_integer_EXPRESSION);
15326 when Pragma_Task_Storage => Task_Storage : declare
15327 Args : Args_List (1 .. 2);
15328 Names : constant Name_List (1 .. 2) := (
15332 Task_Type : Node_Id renames Args (1);
15333 Top_Guard : Node_Id renames Args (2);
15339 Gather_Associations (Names, Args);
15341 if No (Task_Type) then
15343 ("missing task_type argument for pragma%");
15346 Check_Arg_Is_Local_Name (Task_Type);
15348 Ent := Entity (Task_Type);
15350 if not Is_Task_Type (Ent) then
15352 ("argument for pragma% must be task type", Task_Type);
15355 if No (Top_Guard) then
15357 ("pragma% takes two arguments", Task_Type);
15359 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
15362 Check_First_Subtype (Task_Type);
15364 if Rep_Item_Too_Late (Ent, N) then
15373 -- pragma Test_Case
15374 -- ([Name =>] Static_String_EXPRESSION
15375 -- ,[Mode =>] MODE_TYPE
15376 -- [, Requires => Boolean_EXPRESSION]
15377 -- [, Ensures => Boolean_EXPRESSION]);
15379 -- MODE_TYPE ::= Nominal | Robustness
15381 when Pragma_Test_Case =>
15382 Check_Contract_Or_Test_Case;
15384 --------------------------
15385 -- Thread_Local_Storage --
15386 --------------------------
15388 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
15390 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
15396 Check_Arg_Count (1);
15397 Check_Optional_Identifier (Arg1, Name_Entity);
15398 Check_Arg_Is_Library_Level_Local_Name (Arg1);
15400 Id := Get_Pragma_Arg (Arg1);
15403 if not Is_Entity_Name (Id)
15404 or else Ekind (Entity (Id)) /= E_Variable
15406 Error_Pragma_Arg ("local variable name required", Arg1);
15411 if Rep_Item_Too_Early (E, N)
15412 or else Rep_Item_Too_Late (E, N)
15417 Set_Has_Pragma_Thread_Local_Storage (E);
15418 Set_Has_Gigi_Rep_Item (E);
15419 end Thread_Local_Storage;
15425 -- pragma Time_Slice (static_duration_EXPRESSION);
15427 when Pragma_Time_Slice => Time_Slice : declare
15433 Check_Arg_Count (1);
15434 Check_No_Identifiers;
15435 Check_In_Main_Program;
15436 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
15438 if not Error_Posted (Arg1) then
15440 while Present (Nod) loop
15441 if Nkind (Nod) = N_Pragma
15442 and then Pragma_Name (Nod) = Name_Time_Slice
15444 Error_Msg_Name_1 := Pname;
15445 Error_Msg_N ("duplicate pragma% not permitted", Nod);
15452 -- Process only if in main unit
15454 if Get_Source_Unit (Loc) = Main_Unit then
15455 Opt.Time_Slice_Set := True;
15456 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
15458 if Val <= Ureal_0 then
15459 Opt.Time_Slice_Value := 0;
15461 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
15462 Opt.Time_Slice_Value := 1_000_000_000;
15465 Opt.Time_Slice_Value :=
15466 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
15475 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
15477 -- TITLING_OPTION ::=
15478 -- [Title =>] STRING_LITERAL
15479 -- | [Subtitle =>] STRING_LITERAL
15481 when Pragma_Title => Title : declare
15482 Args : Args_List (1 .. 2);
15483 Names : constant Name_List (1 .. 2) := (
15489 Gather_Associations (Names, Args);
15492 for J in 1 .. 2 loop
15493 if Present (Args (J)) then
15494 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
15499 ---------------------
15500 -- Unchecked_Union --
15501 ---------------------
15503 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
15505 when Pragma_Unchecked_Union => Unchecked_Union : declare
15506 Assoc : constant Node_Id := Arg1;
15507 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
15517 Check_No_Identifiers;
15518 Check_Arg_Count (1);
15519 Check_Arg_Is_Local_Name (Arg1);
15521 Find_Type (Type_Id);
15523 Typ := Entity (Type_Id);
15526 or else Rep_Item_Too_Early (Typ, N)
15530 Typ := Underlying_Type (Typ);
15533 if Rep_Item_Too_Late (Typ, N) then
15537 Check_First_Subtype (Arg1);
15539 -- Note remaining cases are references to a type in the current
15540 -- declarative part. If we find an error, we post the error on
15541 -- the relevant type declaration at an appropriate point.
15543 if not Is_Record_Type (Typ) then
15544 Error_Msg_N ("unchecked union must be record type", Typ);
15547 elsif Is_Tagged_Type (Typ) then
15548 Error_Msg_N ("unchecked union must not be tagged", Typ);
15551 elsif not Has_Discriminants (Typ) then
15553 ("unchecked union must have one discriminant", Typ);
15556 -- Note: in previous versions of GNAT we used to check for limited
15557 -- types and give an error, but in fact the standard does allow
15558 -- Unchecked_Union on limited types, so this check was removed.
15560 -- Similarly, GNAT used to require that all discriminants have
15561 -- default values, but this is not mandated by the RM.
15563 -- Proceed with basic error checks completed
15566 Tdef := Type_Definition (Declaration_Node (Typ));
15567 Clist := Component_List (Tdef);
15569 -- Check presence of component list and variant part
15571 if No (Clist) or else No (Variant_Part (Clist)) then
15573 ("unchecked union must have variant part", Tdef);
15577 -- Check components
15579 Comp := First (Component_Items (Clist));
15580 while Present (Comp) loop
15581 Check_Component (Comp, Typ);
15585 -- Check variant part
15587 Vpart := Variant_Part (Clist);
15589 Variant := First (Variants (Vpart));
15590 while Present (Variant) loop
15591 Check_Variant (Variant, Typ);
15596 Set_Is_Unchecked_Union (Typ);
15597 Set_Convention (Typ, Convention_C);
15598 Set_Has_Unchecked_Union (Base_Type (Typ));
15599 Set_Is_Unchecked_Union (Base_Type (Typ));
15600 end Unchecked_Union;
15602 ------------------------
15603 -- Unimplemented_Unit --
15604 ------------------------
15606 -- pragma Unimplemented_Unit;
15608 -- Note: this only gives an error if we are generating code, or if
15609 -- we are in a generic library unit (where the pragma appears in the
15610 -- body, not in the spec).
15612 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
15613 Cunitent : constant Entity_Id :=
15614 Cunit_Entity (Get_Source_Unit (Loc));
15615 Ent_Kind : constant Entity_Kind :=
15620 Check_Arg_Count (0);
15622 if Operating_Mode = Generate_Code
15623 or else Ent_Kind = E_Generic_Function
15624 or else Ent_Kind = E_Generic_Procedure
15625 or else Ent_Kind = E_Generic_Package
15627 Get_Name_String (Chars (Cunitent));
15628 Set_Casing (Mixed_Case);
15629 Write_Str (Name_Buffer (1 .. Name_Len));
15630 Write_Str (" is not supported in this configuration");
15632 raise Unrecoverable_Error;
15634 end Unimplemented_Unit;
15636 ------------------------
15637 -- Universal_Aliasing --
15638 ------------------------
15640 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
15642 when Pragma_Universal_Aliasing => Universal_Alias : declare
15647 Check_Arg_Count (1);
15648 Check_Optional_Identifier (Arg2, Name_Entity);
15649 Check_Arg_Is_Local_Name (Arg1);
15650 E_Id := Entity (Get_Pragma_Arg (Arg1));
15652 if E_Id = Any_Type then
15654 elsif No (E_Id) or else not Is_Type (E_Id) then
15655 Error_Pragma_Arg ("pragma% requires type", Arg1);
15658 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
15659 Record_Rep_Item (E_Id, N);
15660 end Universal_Alias;
15662 --------------------
15663 -- Universal_Data --
15664 --------------------
15666 -- pragma Universal_Data [(library_unit_NAME)];
15668 when Pragma_Universal_Data =>
15671 -- If this is a configuration pragma, then set the universal
15672 -- addressing option, otherwise confirm that the pragma satisfies
15673 -- the requirements of library unit pragma placement and leave it
15674 -- to the GNAAMP back end to detect the pragma (avoids transitive
15675 -- setting of the option due to withed units).
15677 if Is_Configuration_Pragma then
15678 Universal_Addressing_On_AAMP := True;
15680 Check_Valid_Library_Unit_Pragma;
15683 if not AAMP_On_Target then
15684 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
15691 -- pragma Unmodified (local_Name {, local_Name});
15693 when Pragma_Unmodified => Unmodified : declare
15694 Arg_Node : Node_Id;
15695 Arg_Expr : Node_Id;
15696 Arg_Ent : Entity_Id;
15700 Check_At_Least_N_Arguments (1);
15702 -- Loop through arguments
15705 while Present (Arg_Node) loop
15706 Check_No_Identifier (Arg_Node);
15708 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
15709 -- in fact generate reference, so that the entity will have a
15710 -- reference, which will inhibit any warnings about it not
15711 -- being referenced, and also properly show up in the ali file
15712 -- as a reference. But this reference is recorded before the
15713 -- Has_Pragma_Unreferenced flag is set, so that no warning is
15714 -- generated for this reference.
15716 Check_Arg_Is_Local_Name (Arg_Node);
15717 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15719 if Is_Entity_Name (Arg_Expr) then
15720 Arg_Ent := Entity (Arg_Expr);
15722 if not Is_Assignable (Arg_Ent) then
15724 ("pragma% can only be applied to a variable",
15727 Set_Has_Pragma_Unmodified (Arg_Ent);
15739 -- pragma Unreferenced (local_Name {, local_Name});
15741 -- or when used in a context clause:
15743 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
15745 when Pragma_Unreferenced => Unreferenced : declare
15746 Arg_Node : Node_Id;
15747 Arg_Expr : Node_Id;
15748 Arg_Ent : Entity_Id;
15753 Check_At_Least_N_Arguments (1);
15755 -- Check case of appearing within context clause
15757 if Is_In_Context_Clause then
15759 -- The arguments must all be units mentioned in a with clause
15760 -- in the same context clause. Note we already checked (in
15761 -- Par.Prag) that the arguments are either identifiers or
15762 -- selected components.
15765 while Present (Arg_Node) loop
15766 Citem := First (List_Containing (N));
15767 while Citem /= N loop
15768 if Nkind (Citem) = N_With_Clause
15770 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
15772 Set_Has_Pragma_Unreferenced
15775 (Library_Unit (Citem))));
15777 (Get_Pragma_Arg (Arg_Node), Name (Citem));
15786 ("argument of pragma% is not withed unit", Arg_Node);
15792 -- Case of not in list of context items
15796 while Present (Arg_Node) loop
15797 Check_No_Identifier (Arg_Node);
15799 -- Note: the analyze call done by Check_Arg_Is_Local_Name
15800 -- will in fact generate reference, so that the entity will
15801 -- have a reference, which will inhibit any warnings about
15802 -- it not being referenced, and also properly show up in the
15803 -- ali file as a reference. But this reference is recorded
15804 -- before the Has_Pragma_Unreferenced flag is set, so that
15805 -- no warning is generated for this reference.
15807 Check_Arg_Is_Local_Name (Arg_Node);
15808 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15810 if Is_Entity_Name (Arg_Expr) then
15811 Arg_Ent := Entity (Arg_Expr);
15813 -- If the entity is overloaded, the pragma applies to the
15814 -- most recent overloading, as documented. In this case,
15815 -- name resolution does not generate a reference, so it
15816 -- must be done here explicitly.
15818 if Is_Overloaded (Arg_Expr) then
15819 Generate_Reference (Arg_Ent, N);
15822 Set_Has_Pragma_Unreferenced (Arg_Ent);
15830 --------------------------
15831 -- Unreferenced_Objects --
15832 --------------------------
15834 -- pragma Unreferenced_Objects (local_Name {, local_Name});
15836 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
15837 Arg_Node : Node_Id;
15838 Arg_Expr : Node_Id;
15842 Check_At_Least_N_Arguments (1);
15845 while Present (Arg_Node) loop
15846 Check_No_Identifier (Arg_Node);
15847 Check_Arg_Is_Local_Name (Arg_Node);
15848 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15850 if not Is_Entity_Name (Arg_Expr)
15851 or else not Is_Type (Entity (Arg_Expr))
15854 ("argument for pragma% must be type or subtype", Arg_Node);
15857 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
15860 end Unreferenced_Objects;
15862 ------------------------------
15863 -- Unreserve_All_Interrupts --
15864 ------------------------------
15866 -- pragma Unreserve_All_Interrupts;
15868 when Pragma_Unreserve_All_Interrupts =>
15870 Check_Arg_Count (0);
15872 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
15873 Unreserve_All_Interrupts := True;
15880 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
15882 when Pragma_Unsuppress =>
15884 Process_Suppress_Unsuppress (False);
15886 -------------------
15887 -- Use_VADS_Size --
15888 -------------------
15890 -- pragma Use_VADS_Size;
15892 when Pragma_Use_VADS_Size =>
15894 Check_Arg_Count (0);
15895 Check_Valid_Configuration_Pragma;
15896 Use_VADS_Size := True;
15898 ---------------------
15899 -- Validity_Checks --
15900 ---------------------
15902 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
15904 when Pragma_Validity_Checks => Validity_Checks : declare
15905 A : constant Node_Id := Get_Pragma_Arg (Arg1);
15911 Check_Arg_Count (1);
15912 Check_No_Identifiers;
15914 if Nkind (A) = N_String_Literal then
15918 Slen : constant Natural := Natural (String_Length (S));
15919 Options : String (1 .. Slen);
15925 C := Get_String_Char (S, Int (J));
15926 exit when not In_Character_Range (C);
15927 Options (J) := Get_Character (C);
15930 Set_Validity_Check_Options (Options);
15938 elsif Nkind (A) = N_Identifier then
15939 if Chars (A) = Name_All_Checks then
15940 Set_Validity_Check_Options ("a");
15941 elsif Chars (A) = Name_On then
15942 Validity_Checks_On := True;
15943 elsif Chars (A) = Name_Off then
15944 Validity_Checks_On := False;
15947 end Validity_Checks;
15953 -- pragma Volatile (LOCAL_NAME);
15955 when Pragma_Volatile =>
15956 Process_Atomic_Shared_Volatile;
15958 -------------------------
15959 -- Volatile_Components --
15960 -------------------------
15962 -- pragma Volatile_Components (array_LOCAL_NAME);
15964 -- Volatile is handled by the same circuit as Atomic_Components
15970 -- pragma Warnings (On | Off);
15971 -- pragma Warnings (On | Off, LOCAL_NAME);
15972 -- pragma Warnings (static_string_EXPRESSION);
15973 -- pragma Warnings (On | Off, STRING_LITERAL);
15975 when Pragma_Warnings => Warnings : begin
15977 Check_At_Least_N_Arguments (1);
15978 Check_No_Identifiers;
15980 -- If debug flag -gnatd.i is set, pragma is ignored
15982 if Debug_Flag_Dot_I then
15986 -- Process various forms of the pragma
15989 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
15992 -- One argument case
15994 if Arg_Count = 1 then
15996 -- On/Off one argument case was processed by parser
15998 if Nkind (Argx) = N_Identifier
16000 (Chars (Argx) = Name_On
16002 Chars (Argx) = Name_Off)
16006 -- One argument case must be ON/OFF or static string expr
16008 elsif not Is_Static_String_Expression (Arg1) then
16010 ("argument of pragma% must be On/Off or " &
16011 "static string expression", Arg1);
16013 -- One argument string expression case
16017 Lit : constant Node_Id := Expr_Value_S (Argx);
16018 Str : constant String_Id := Strval (Lit);
16019 Len : constant Nat := String_Length (Str);
16027 while J <= Len loop
16028 C := Get_String_Char (Str, J);
16029 OK := In_Character_Range (C);
16032 Chr := Get_Character (C);
16034 -- Dash case: only -Wxxx is accepted
16041 C := Get_String_Char (Str, J);
16042 Chr := Get_Character (C);
16043 exit when Chr = 'W';
16048 elsif J < Len and then Chr = '.' then
16050 C := Get_String_Char (Str, J);
16051 Chr := Get_Character (C);
16053 if not Set_Dot_Warning_Switch (Chr) then
16055 ("invalid warning switch character " &
16062 OK := Set_Warning_Switch (Chr);
16068 ("invalid warning switch character " & Chr,
16077 -- Two or more arguments (must be two)
16080 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16081 Check_At_Most_N_Arguments (2);
16089 E_Id := Get_Pragma_Arg (Arg2);
16092 -- In the expansion of an inlined body, a reference to
16093 -- the formal may be wrapped in a conversion if the
16094 -- actual is a conversion. Retrieve the real entity name.
16096 if (In_Instance_Body or In_Inlined_Body)
16097 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
16099 E_Id := Expression (E_Id);
16102 -- Entity name case
16104 if Is_Entity_Name (E_Id) then
16105 E := Entity (E_Id);
16112 (E, (Chars (Get_Pragma_Arg (Arg1)) =
16115 -- For OFF case, make entry in warnings off
16116 -- pragma table for later processing. But we do
16117 -- not do that within an instance, since these
16118 -- warnings are about what is needed in the
16119 -- template, not an instance of it.
16121 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
16122 and then Warn_On_Warnings_Off
16123 and then not In_Instance
16125 Warnings_Off_Pragmas.Append ((N, E));
16128 if Is_Enumeration_Type (E) then
16132 Lit := First_Literal (E);
16133 while Present (Lit) loop
16134 Set_Warnings_Off (Lit);
16135 Next_Literal (Lit);
16140 exit when No (Homonym (E));
16145 -- Error if not entity or static string literal case
16147 elsif not Is_Static_String_Expression (Arg2) then
16149 ("second argument of pragma% must be entity " &
16150 "name or static string expression", Arg2);
16152 -- String literal case
16155 String_To_Name_Buffer
16156 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
16158 -- Note on configuration pragma case: If this is a
16159 -- configuration pragma, then for an OFF pragma, we
16160 -- just set Config True in the call, which is all
16161 -- that needs to be done. For the case of ON, this
16162 -- is normally an error, unless it is canceling the
16163 -- effect of a previous OFF pragma in the same file.
16164 -- In any other case, an error will be signalled (ON
16165 -- with no matching OFF).
16167 -- Note: We set Used if we are inside a generic to
16168 -- disable the test that the non-config case actually
16169 -- cancels a warning. That's because we can't be sure
16170 -- there isn't an instantiation in some other unit
16171 -- where a warning is suppressed.
16173 -- We could do a little better here by checking if the
16174 -- generic unit we are inside is public, but for now
16175 -- we don't bother with that refinement.
16177 if Chars (Argx) = Name_Off then
16178 Set_Specific_Warning_Off
16179 (Loc, Name_Buffer (1 .. Name_Len),
16180 Config => Is_Configuration_Pragma,
16181 Used => Inside_A_Generic or else In_Instance);
16183 elsif Chars (Argx) = Name_On then
16184 Set_Specific_Warning_On
16185 (Loc, Name_Buffer (1 .. Name_Len), Err);
16189 ("??pragma Warnings On with no " &
16190 "matching Warnings Off",
16200 -------------------
16201 -- Weak_External --
16202 -------------------
16204 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
16206 when Pragma_Weak_External => Weak_External : declare
16211 Check_Arg_Count (1);
16212 Check_Optional_Identifier (Arg1, Name_Entity);
16213 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16214 Ent := Entity (Get_Pragma_Arg (Arg1));
16216 if Rep_Item_Too_Early (Ent, N) then
16219 Ent := Underlying_Type (Ent);
16222 -- The only processing required is to link this item on to the
16223 -- list of rep items for the given entity. This is accomplished
16224 -- by the call to Rep_Item_Too_Late (when no error is detected
16225 -- and False is returned).
16227 if Rep_Item_Too_Late (Ent, N) then
16230 Set_Has_Gigi_Rep_Item (Ent);
16234 -----------------------------
16235 -- Wide_Character_Encoding --
16236 -----------------------------
16238 -- pragma Wide_Character_Encoding (IDENTIFIER);
16240 when Pragma_Wide_Character_Encoding =>
16243 -- Nothing to do, handled in parser. Note that we do not enforce
16244 -- configuration pragma placement, this pragma can appear at any
16245 -- place in the source, allowing mixed encodings within a single
16250 --------------------
16251 -- Unknown_Pragma --
16252 --------------------
16254 -- Should be impossible, since the case of an unknown pragma is
16255 -- separately processed before the case statement is entered.
16257 when Unknown_Pragma =>
16258 raise Program_Error;
16261 -- AI05-0144: detect dangerous order dependence. Disabled for now,
16262 -- until AI is formally approved.
16264 -- Check_Order_Dependence;
16267 when Pragma_Exit => null;
16268 end Analyze_Pragma;
16270 --------------------
16271 -- Check_Disabled --
16272 --------------------
16274 function Check_Disabled (Nam : Name_Id) return Boolean is
16278 -- Loop through entries in check policy list
16280 PP := Opt.Check_Policy_List;
16282 -- If there are no specific entries that matched, then nothing is
16283 -- disabled, so return False.
16288 -- Here we have an entry see if it matches
16292 PPA : constant List_Id := Pragma_Argument_Associations (PP);
16294 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
16295 return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
16297 PP := Next_Pragma (PP);
16302 end Check_Disabled;
16304 -------------------
16305 -- Check_Enabled --
16306 -------------------
16308 function Check_Enabled (Nam : Name_Id) return Boolean is
16312 -- Loop through entries in check policy list
16314 PP := Opt.Check_Policy_List;
16316 -- If there are no specific entries that matched, then we let the
16317 -- setting of assertions govern. Note that this provides the needed
16318 -- compatibility with the RM for the cases of assertion, invariant,
16319 -- precondition, predicate, and postcondition.
16322 return Assertions_Enabled;
16324 -- Here we have an entry see if it matches
16328 PPA : constant List_Id := Pragma_Argument_Associations (PP);
16331 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
16332 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
16333 when Name_On | Name_Check =>
16335 when Name_Off | Name_Ignore =>
16338 raise Program_Error;
16342 PP := Next_Pragma (PP);
16349 ---------------------------------
16350 -- Delay_Config_Pragma_Analyze --
16351 ---------------------------------
16353 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
16355 return Pragma_Name (N) = Name_Interrupt_State
16357 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
16358 end Delay_Config_Pragma_Analyze;
16360 -------------------------
16361 -- Get_Base_Subprogram --
16362 -------------------------
16364 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
16365 Result : Entity_Id;
16368 -- Follow subprogram renaming chain
16372 if Is_Subprogram (Result)
16374 Nkind (Parent (Declaration_Node (Result))) =
16375 N_Subprogram_Renaming_Declaration
16376 and then Present (Alias (Result))
16378 Result := Alias (Result);
16382 end Get_Base_Subprogram;
16388 procedure Initialize is
16393 -----------------------------
16394 -- Is_Config_Static_String --
16395 -----------------------------
16397 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
16399 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
16400 -- This is an internal recursive function that is just like the outer
16401 -- function except that it adds the string to the name buffer rather
16402 -- than placing the string in the name buffer.
16404 ------------------------------
16405 -- Add_Config_Static_String --
16406 ------------------------------
16408 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
16415 if Nkind (N) = N_Op_Concat then
16416 if Add_Config_Static_String (Left_Opnd (N)) then
16417 N := Right_Opnd (N);
16423 if Nkind (N) /= N_String_Literal then
16424 Error_Msg_N ("string literal expected for pragma argument", N);
16428 for J in 1 .. String_Length (Strval (N)) loop
16429 C := Get_String_Char (Strval (N), J);
16431 if not In_Character_Range (C) then
16433 ("string literal contains invalid wide character",
16434 Sloc (N) + 1 + Source_Ptr (J));
16438 Add_Char_To_Name_Buffer (Get_Character (C));
16443 end Add_Config_Static_String;
16445 -- Start of processing for Is_Config_Static_String
16450 return Add_Config_Static_String (Arg);
16451 end Is_Config_Static_String;
16453 -----------------------------------------
16454 -- Is_Non_Significant_Pragma_Reference --
16455 -----------------------------------------
16457 -- This function makes use of the following static table which indicates
16458 -- whether appearance of some name in a given pragma is to be considered
16459 -- as a reference for the purposes of warnings about unreferenced objects.
16461 -- -1 indicates that references in any argument position are significant
16462 -- 0 indicates that appearance in any argument is not significant
16463 -- +n indicates that appearance as argument n is significant, but all
16464 -- other arguments are not significant
16465 -- 99 special processing required (e.g. for pragma Check)
16467 Sig_Flags : constant array (Pragma_Id) of Int :=
16468 (Pragma_AST_Entry => -1,
16469 Pragma_Abort_Defer => -1,
16470 Pragma_Abstract_State => -1,
16471 Pragma_Ada_83 => -1,
16472 Pragma_Ada_95 => -1,
16473 Pragma_Ada_05 => -1,
16474 Pragma_Ada_2005 => -1,
16475 Pragma_Ada_12 => -1,
16476 Pragma_Ada_2012 => -1,
16477 Pragma_All_Calls_Remote => -1,
16478 Pragma_Annotate => -1,
16479 Pragma_Assert => -1,
16480 Pragma_Assert_And_Cut => -1,
16481 Pragma_Assertion_Policy => 0,
16482 Pragma_Assume => 0,
16483 Pragma_Assume_No_Invalid_Values => 0,
16484 Pragma_Attribute_Definition => +3,
16485 Pragma_Asynchronous => -1,
16486 Pragma_Atomic => 0,
16487 Pragma_Atomic_Components => 0,
16488 Pragma_Attach_Handler => -1,
16489 Pragma_Check => 99,
16490 Pragma_Check_Float_Overflow => 0,
16491 Pragma_Check_Name => 0,
16492 Pragma_Check_Policy => 0,
16493 Pragma_CIL_Constructor => -1,
16494 Pragma_CPP_Class => 0,
16495 Pragma_CPP_Constructor => 0,
16496 Pragma_CPP_Virtual => 0,
16497 Pragma_CPP_Vtable => 0,
16499 Pragma_C_Pass_By_Copy => 0,
16500 Pragma_Comment => 0,
16501 Pragma_Common_Object => -1,
16502 Pragma_Compile_Time_Error => -1,
16503 Pragma_Compile_Time_Warning => -1,
16504 Pragma_Compiler_Unit => 0,
16505 Pragma_Complete_Representation => 0,
16506 Pragma_Complex_Representation => 0,
16507 Pragma_Component_Alignment => -1,
16508 Pragma_Contract_Case => -1,
16509 Pragma_Contract_Cases => -1,
16510 Pragma_Controlled => 0,
16511 Pragma_Convention => 0,
16512 Pragma_Convention_Identifier => 0,
16513 Pragma_Debug => -1,
16514 Pragma_Debug_Policy => 0,
16515 Pragma_Detect_Blocking => -1,
16516 Pragma_Default_Storage_Pool => -1,
16517 Pragma_Disable_Atomic_Synchronization => -1,
16518 Pragma_Discard_Names => 0,
16519 Pragma_Dispatching_Domain => -1,
16520 Pragma_Elaborate => -1,
16521 Pragma_Elaborate_All => -1,
16522 Pragma_Elaborate_Body => -1,
16523 Pragma_Elaboration_Checks => -1,
16524 Pragma_Eliminate => -1,
16525 Pragma_Enable_Atomic_Synchronization => -1,
16526 Pragma_Export => -1,
16527 Pragma_Export_Exception => -1,
16528 Pragma_Export_Function => -1,
16529 Pragma_Export_Object => -1,
16530 Pragma_Export_Procedure => -1,
16531 Pragma_Export_Value => -1,
16532 Pragma_Export_Valued_Procedure => -1,
16533 Pragma_Extend_System => -1,
16534 Pragma_Extensions_Allowed => -1,
16535 Pragma_External => -1,
16536 Pragma_Favor_Top_Level => -1,
16537 Pragma_External_Name_Casing => -1,
16538 Pragma_Fast_Math => -1,
16539 Pragma_Finalize_Storage_Only => 0,
16540 Pragma_Float_Representation => 0,
16541 Pragma_Global => -1,
16542 Pragma_Ident => -1,
16543 Pragma_Implementation_Defined => -1,
16544 Pragma_Implemented => -1,
16545 Pragma_Implicit_Packing => 0,
16546 Pragma_Import => +2,
16547 Pragma_Import_Exception => 0,
16548 Pragma_Import_Function => 0,
16549 Pragma_Import_Object => 0,
16550 Pragma_Import_Procedure => 0,
16551 Pragma_Import_Valued_Procedure => 0,
16552 Pragma_Independent => 0,
16553 Pragma_Independent_Components => 0,
16554 Pragma_Initialize_Scalars => -1,
16555 Pragma_Inline => 0,
16556 Pragma_Inline_Always => 0,
16557 Pragma_Inline_Generic => 0,
16558 Pragma_Inspection_Point => -1,
16559 Pragma_Interface => +2,
16560 Pragma_Interface_Name => +2,
16561 Pragma_Interrupt_Handler => -1,
16562 Pragma_Interrupt_Priority => -1,
16563 Pragma_Interrupt_State => -1,
16564 Pragma_Invariant => -1,
16565 Pragma_Java_Constructor => -1,
16566 Pragma_Java_Interface => -1,
16567 Pragma_Keep_Names => 0,
16568 Pragma_License => -1,
16569 Pragma_Link_With => -1,
16570 Pragma_Linker_Alias => -1,
16571 Pragma_Linker_Constructor => -1,
16572 Pragma_Linker_Destructor => -1,
16573 Pragma_Linker_Options => -1,
16574 Pragma_Linker_Section => -1,
16576 Pragma_Lock_Free => -1,
16577 Pragma_Locking_Policy => -1,
16578 Pragma_Long_Float => -1,
16579 Pragma_Loop_Invariant => -1,
16580 Pragma_Loop_Variant => -1,
16581 Pragma_Machine_Attribute => -1,
16583 Pragma_Main_Storage => -1,
16584 Pragma_Memory_Size => -1,
16585 Pragma_No_Return => 0,
16586 Pragma_No_Body => 0,
16587 Pragma_No_Run_Time => -1,
16588 Pragma_No_Strict_Aliasing => -1,
16589 Pragma_Normalize_Scalars => -1,
16590 Pragma_Obsolescent => 0,
16591 Pragma_Optimize => -1,
16592 Pragma_Optimize_Alignment => -1,
16593 Pragma_Overflow_Mode => 0,
16594 Pragma_Ordered => 0,
16597 Pragma_Partition_Elaboration_Policy => -1,
16598 Pragma_Passive => -1,
16599 Pragma_Preelaborable_Initialization => -1,
16600 Pragma_Polling => -1,
16601 Pragma_Persistent_BSS => 0,
16602 Pragma_Postcondition => -1,
16603 Pragma_Precondition => -1,
16604 Pragma_Predicate => -1,
16605 Pragma_Preelaborate => -1,
16606 Pragma_Preelaborate_05 => -1,
16607 Pragma_Priority => -1,
16608 Pragma_Priority_Specific_Dispatching => -1,
16609 Pragma_Profile => 0,
16610 Pragma_Profile_Warnings => 0,
16611 Pragma_Propagate_Exceptions => -1,
16612 Pragma_Psect_Object => -1,
16614 Pragma_Pure_05 => -1,
16615 Pragma_Pure_12 => -1,
16616 Pragma_Pure_Function => -1,
16617 Pragma_Queuing_Policy => -1,
16618 Pragma_Rational => -1,
16619 Pragma_Ravenscar => -1,
16620 Pragma_Relative_Deadline => -1,
16621 Pragma_Remote_Access_Type => -1,
16622 Pragma_Remote_Call_Interface => -1,
16623 Pragma_Remote_Types => -1,
16624 Pragma_Restricted_Run_Time => -1,
16625 Pragma_Restriction_Warnings => -1,
16626 Pragma_Restrictions => -1,
16627 Pragma_Reviewable => -1,
16628 Pragma_Short_Circuit_And_Or => -1,
16629 Pragma_Share_Generic => -1,
16630 Pragma_Shared => -1,
16631 Pragma_Shared_Passive => -1,
16632 Pragma_Short_Descriptors => 0,
16633 Pragma_Simple_Storage_Pool_Type => 0,
16634 Pragma_Source_File_Name => -1,
16635 Pragma_Source_File_Name_Project => -1,
16636 Pragma_Source_Reference => -1,
16637 Pragma_Storage_Size => -1,
16638 Pragma_Storage_Unit => -1,
16639 Pragma_Static_Elaboration_Desired => -1,
16640 Pragma_Stream_Convert => -1,
16641 Pragma_Style_Checks => -1,
16642 Pragma_Subtitle => -1,
16643 Pragma_Suppress => 0,
16644 Pragma_Suppress_Exception_Locations => 0,
16645 Pragma_Suppress_All => -1,
16646 Pragma_Suppress_Debug_Info => 0,
16647 Pragma_Suppress_Initialization => 0,
16648 Pragma_System_Name => -1,
16649 Pragma_Task_Dispatching_Policy => -1,
16650 Pragma_Task_Info => -1,
16651 Pragma_Task_Name => -1,
16652 Pragma_Task_Storage => 0,
16653 Pragma_Test_Case => -1,
16654 Pragma_Thread_Local_Storage => 0,
16655 Pragma_Time_Slice => -1,
16656 Pragma_Title => -1,
16657 Pragma_Unchecked_Union => 0,
16658 Pragma_Unimplemented_Unit => -1,
16659 Pragma_Universal_Aliasing => -1,
16660 Pragma_Universal_Data => -1,
16661 Pragma_Unmodified => -1,
16662 Pragma_Unreferenced => -1,
16663 Pragma_Unreferenced_Objects => -1,
16664 Pragma_Unreserve_All_Interrupts => -1,
16665 Pragma_Unsuppress => 0,
16666 Pragma_Use_VADS_Size => -1,
16667 Pragma_Validity_Checks => -1,
16668 Pragma_Volatile => 0,
16669 Pragma_Volatile_Components => 0,
16670 Pragma_Warnings => -1,
16671 Pragma_Weak_External => -1,
16672 Pragma_Wide_Character_Encoding => 0,
16673 Unknown_Pragma => 0);
16675 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
16684 if Nkind (P) /= N_Pragma_Argument_Association then
16688 Id := Get_Pragma_Id (Parent (P));
16689 C := Sig_Flags (Id);
16701 -- For pragma Check, the first argument is not significant,
16702 -- the second and the third (if present) arguments are
16705 when Pragma_Check =>
16707 P = First (Pragma_Argument_Associations (Parent (P)));
16710 raise Program_Error;
16714 A := First (Pragma_Argument_Associations (Parent (P)));
16715 for J in 1 .. C - 1 loop
16723 return A = P; -- is this wrong way round ???
16726 end Is_Non_Significant_Pragma_Reference;
16728 ------------------------------
16729 -- Is_Pragma_String_Literal --
16730 ------------------------------
16732 -- This function returns true if the corresponding pragma argument is a
16733 -- static string expression. These are the only cases in which string
16734 -- literals can appear as pragma arguments. We also allow a string literal
16735 -- as the first argument to pragma Assert (although it will of course
16736 -- always generate a type error).
16738 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
16739 Pragn : constant Node_Id := Parent (Par);
16740 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
16741 Pname : constant Name_Id := Pragma_Name (Pragn);
16747 N := First (Assoc);
16754 if Pname = Name_Assert then
16757 elsif Pname = Name_Export then
16760 elsif Pname = Name_Ident then
16763 elsif Pname = Name_Import then
16766 elsif Pname = Name_Interface_Name then
16769 elsif Pname = Name_Linker_Alias then
16772 elsif Pname = Name_Linker_Section then
16775 elsif Pname = Name_Machine_Attribute then
16778 elsif Pname = Name_Source_File_Name then
16781 elsif Pname = Name_Source_Reference then
16784 elsif Pname = Name_Title then
16787 elsif Pname = Name_Subtitle then
16793 end Is_Pragma_String_Literal;
16795 -----------------------------------------
16796 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
16797 -----------------------------------------
16799 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
16800 Aspects : constant List_Id := New_List;
16801 Loc : constant Source_Ptr := Sloc (Decl);
16802 Or_Decl : constant Node_Id := Original_Node (Decl);
16804 Original_Aspects : List_Id;
16805 -- To capture global references, a copy of the created aspects must be
16806 -- inserted in the original tree.
16809 Prag_Arg_Ass : Node_Id;
16810 Prag_Id : Pragma_Id;
16813 -- Check for any PPC pragmas that appear within Decl
16815 Prag := Next (Decl);
16816 while Nkind (Prag) = N_Pragma loop
16817 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
16820 when Pragma_Postcondition | Pragma_Precondition =>
16821 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
16823 -- Make an aspect from any PPC pragma
16825 Append_To (Aspects,
16826 Make_Aspect_Specification (Loc,
16828 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
16830 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
16832 -- Generate the analysis information in the pragma expression
16833 -- and then set the pragma node analyzed to avoid any further
16836 Analyze (Expression (Prag_Arg_Ass));
16837 Set_Analyzed (Prag, True);
16839 when others => null;
16845 -- Set all new aspects into the generic declaration node
16847 if Is_Non_Empty_List (Aspects) then
16849 -- Create the list of aspects to be inserted in the original tree
16851 Original_Aspects := Copy_Separate_List (Aspects);
16853 -- Check if Decl already has aspects
16855 -- Attach the new lists of aspects to both the generic copy and the
16858 if Has_Aspects (Decl) then
16859 Append_List (Aspects, Aspect_Specifications (Decl));
16860 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
16863 Set_Parent (Aspects, Decl);
16864 Set_Aspect_Specifications (Decl, Aspects);
16865 Set_Parent (Original_Aspects, Or_Decl);
16866 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
16869 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
16871 -------------------------
16872 -- Preanalyze_CTC_Args --
16873 -------------------------
16875 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
16877 -- Preanalyze the boolean expressions, we treat these as spec
16878 -- expressions (i.e. similar to a default expression).
16880 if Present (Arg_Req) then
16881 Preanalyze_Assert_Expression
16882 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
16884 -- In ASIS mode, for a pragma generated from a source aspect, also
16885 -- analyze the original aspect expression.
16887 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
16888 Preanalyze_Assert_Expression
16889 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
16893 if Present (Arg_Ens) then
16894 Preanalyze_Assert_Expression
16895 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
16897 -- In ASIS mode, for a pragma generated from a source aspect, also
16898 -- analyze the original aspect expression.
16900 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
16901 Preanalyze_Assert_Expression
16902 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
16905 end Preanalyze_CTC_Args;
16907 --------------------------------------
16908 -- Process_Compilation_Unit_Pragmas --
16909 --------------------------------------
16911 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
16913 -- A special check for pragma Suppress_All, a very strange DEC pragma,
16914 -- strange because it comes at the end of the unit. Rational has the
16915 -- same name for a pragma, but treats it as a program unit pragma, In
16916 -- GNAT we just decide to allow it anywhere at all. If it appeared then
16917 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
16918 -- node, and we insert a pragma Suppress (All_Checks) at the start of
16919 -- the context clause to ensure the correct processing.
16921 if Has_Pragma_Suppress_All (N) then
16922 Prepend_To (Context_Items (N),
16923 Make_Pragma (Sloc (N),
16924 Chars => Name_Suppress,
16925 Pragma_Argument_Associations => New_List (
16926 Make_Pragma_Argument_Association (Sloc (N),
16927 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
16930 -- Nothing else to do at the current time!
16932 end Process_Compilation_Unit_Pragmas;
16943 --------------------------------
16944 -- Set_Encoded_Interface_Name --
16945 --------------------------------
16947 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
16948 Str : constant String_Id := Strval (S);
16949 Len : constant Int := String_Length (Str);
16954 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
16957 -- Stores encoded value of character code CC. The encoding we use an
16958 -- underscore followed by four lower case hex digits.
16964 procedure Encode is
16966 Store_String_Char (Get_Char_Code ('_'));
16968 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
16970 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
16972 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
16974 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
16977 -- Start of processing for Set_Encoded_Interface_Name
16980 -- If first character is asterisk, this is a link name, and we leave it
16981 -- completely unmodified. We also ignore null strings (the latter case
16982 -- happens only in error cases) and no encoding should occur for Java or
16983 -- AAMP interface names.
16986 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
16987 or else VM_Target /= No_VM
16988 or else AAMP_On_Target
16990 Set_Interface_Name (E, S);
16995 CC := Get_String_Char (Str, J);
16997 exit when not In_Character_Range (CC);
16999 C := Get_Character (CC);
17001 exit when C /= '_' and then C /= '$'
17002 and then C not in '0' .. '9'
17003 and then C not in 'a' .. 'z'
17004 and then C not in 'A' .. 'Z';
17007 Set_Interface_Name (E, S);
17015 -- Here we need to encode. The encoding we use as follows:
17016 -- three underscores + four hex digits (lower case)
17020 for J in 1 .. String_Length (Str) loop
17021 CC := Get_String_Char (Str, J);
17023 if not In_Character_Range (CC) then
17026 C := Get_Character (CC);
17028 if C = '_' or else C = '$'
17029 or else C in '0' .. '9'
17030 or else C in 'a' .. 'z'
17031 or else C in 'A' .. 'Z'
17033 Store_String_Char (CC);
17040 Set_Interface_Name (E,
17041 Make_String_Literal (Sloc (S),
17042 Strval => End_String));
17044 end Set_Encoded_Interface_Name;
17046 -------------------
17047 -- Set_Unit_Name --
17048 -------------------
17050 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
17055 if Nkind (N) = N_Identifier
17056 and then Nkind (With_Item) = N_Identifier
17058 Set_Entity (N, Entity (With_Item));
17060 elsif Nkind (N) = N_Selected_Component then
17061 Change_Selected_Component_To_Expanded_Name (N);
17062 Set_Entity (N, Entity (With_Item));
17063 Set_Entity (Selector_Name (N), Entity (N));
17065 Pref := Prefix (N);
17066 Scop := Scope (Entity (N));
17067 while Nkind (Pref) = N_Selected_Component loop
17068 Change_Selected_Component_To_Expanded_Name (Pref);
17069 Set_Entity (Selector_Name (Pref), Scop);
17070 Set_Entity (Pref, Scop);
17071 Pref := Prefix (Pref);
17072 Scop := Scope (Scop);
17075 Set_Entity (Pref, Scop);