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_Pragma_Placement;
622 -- Verify whether pragma Loop_Invariant or Loop_Optimize or Loop_Variant
623 -- appear 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 type Inline_Status is (Suppressed, Disabled, Enabled);
890 -- Inline status of a subprogram, indicated as follows:
891 -- Suppressed: inlining is suppressed for the subprogram
892 -- Disabled: no inlining is requested for the subprogram
893 -- Enabled: inlining is requested/required for the subprogram
895 procedure Process_Inline (Status : Inline_Status);
896 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
897 -- indicates the inline status specified by the pragma.
899 procedure Process_Interface_Name
900 (Subprogram_Def : Entity_Id;
903 -- Given the last two arguments of pragma Import, pragma Export, or
904 -- pragma Interface_Name, performs validity checks and sets the
905 -- Interface_Name field of the given subprogram entity to the
906 -- appropriate external or link name, depending on the arguments given.
907 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
908 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
909 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
910 -- nor Link_Arg is present, the interface name is set to the default
911 -- from the subprogram name.
913 procedure Process_Interrupt_Or_Attach_Handler;
914 -- Common processing for Interrupt and Attach_Handler pragmas
916 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
917 -- Common processing for Restrictions and Restriction_Warnings pragmas.
918 -- Warn is True for Restriction_Warnings, or for Restrictions if the
919 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
920 -- is not set in the Restrictions case.
922 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
923 -- Common processing for Suppress and Unsuppress. The boolean parameter
924 -- Suppress_Case is True for the Suppress case, and False for the
927 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
928 -- This procedure sets the Is_Exported flag for the given entity,
929 -- checking that the entity was not previously imported. Arg is
930 -- the argument that specified the entity. A check is also made
931 -- for exporting inappropriate entities.
933 procedure Set_Extended_Import_Export_External_Name
934 (Internal_Ent : Entity_Id;
935 Arg_External : Node_Id);
936 -- Common processing for all extended import export pragmas. The first
937 -- argument, Internal_Ent, is the internal entity, which has already
938 -- been checked for validity by the caller. Arg_External is from the
939 -- Import or Export pragma, and may be null if no External parameter
940 -- was present. If Arg_External is present and is a non-null string
941 -- (a null string is treated as the default), then the Interface_Name
942 -- field of Internal_Ent is set appropriately.
944 procedure Set_Imported (E : Entity_Id);
945 -- This procedure sets the Is_Imported flag for the given entity,
946 -- checking that it is not previously exported or imported.
948 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
949 -- Mech is a parameter passing mechanism (see Import_Function syntax
950 -- for MECHANISM_NAME). This routine checks that the mechanism argument
951 -- has the right form, and if not issues an error message. If the
952 -- argument has the right form then the Mechanism field of Ent is
953 -- set appropriately.
955 procedure Set_Rational_Profile;
956 -- Activate the set of configuration pragmas and permissions that make
957 -- up the Rational profile.
959 procedure Set_Ravenscar_Profile (N : Node_Id);
960 -- Activate the set of configuration pragmas and restrictions that make
961 -- up the Ravenscar Profile. N is the corresponding pragma node, which
962 -- is used for error messages on any constructs that violate the
965 ---------------------
966 -- Ada_2005_Pragma --
967 ---------------------
969 procedure Ada_2005_Pragma is
971 if Ada_Version <= Ada_95 then
972 Check_Restriction (No_Implementation_Pragmas, N);
976 ---------------------
977 -- Ada_2012_Pragma --
978 ---------------------
980 procedure Ada_2012_Pragma is
982 if Ada_Version <= Ada_2005 then
983 Check_Restriction (No_Implementation_Pragmas, N);
987 --------------------------
988 -- Check_Ada_83_Warning --
989 --------------------------
991 procedure Check_Ada_83_Warning is
993 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
994 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
996 end Check_Ada_83_Warning;
998 ---------------------
999 -- Check_Arg_Count --
1000 ---------------------
1002 procedure Check_Arg_Count (Required : Nat) is
1004 if Arg_Count /= Required then
1005 Error_Pragma ("wrong number of arguments for pragma%");
1007 end Check_Arg_Count;
1009 --------------------------------
1010 -- Check_Arg_Is_External_Name --
1011 --------------------------------
1013 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
1014 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1017 if Nkind (Argx) = N_Identifier then
1021 Analyze_And_Resolve (Argx, Standard_String);
1023 if Is_OK_Static_Expression (Argx) then
1026 elsif Etype (Argx) = Any_Type then
1029 -- An interesting special case, if we have a string literal and
1030 -- we are in Ada 83 mode, then we allow it even though it will
1031 -- not be flagged as static. This allows expected Ada 83 mode
1032 -- use of external names which are string literals, even though
1033 -- technically these are not static in Ada 83.
1035 elsif Ada_Version = Ada_83
1036 and then Nkind (Argx) = N_String_Literal
1040 -- Static expression that raises Constraint_Error. This has
1041 -- already been flagged, so just exit from pragma processing.
1043 elsif Is_Static_Expression (Argx) then
1046 -- Here we have a real error (non-static expression)
1049 Error_Msg_Name_1 := Pname;
1053 "argument for pragma% must be a identifier or "
1054 & "static string expression!";
1057 Flag_Non_Static_Expr (Msg, Argx);
1062 end Check_Arg_Is_External_Name;
1064 -----------------------------
1065 -- Check_Arg_Is_Identifier --
1066 -----------------------------
1068 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
1069 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1071 if Nkind (Argx) /= N_Identifier then
1073 ("argument for pragma% must be identifier", Argx);
1075 end Check_Arg_Is_Identifier;
1077 ----------------------------------
1078 -- Check_Arg_Is_Integer_Literal --
1079 ----------------------------------
1081 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1082 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1084 if Nkind (Argx) /= N_Integer_Literal then
1086 ("argument for pragma% must be integer literal", Argx);
1088 end Check_Arg_Is_Integer_Literal;
1090 -------------------------------------------
1091 -- Check_Arg_Is_Library_Level_Local_Name --
1092 -------------------------------------------
1096 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1097 -- | library_unit_NAME
1099 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1101 Check_Arg_Is_Local_Name (Arg);
1103 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1104 and then Comes_From_Source (N)
1107 ("argument for pragma% must be library level entity", Arg);
1109 end Check_Arg_Is_Library_Level_Local_Name;
1111 -----------------------------
1112 -- Check_Arg_Is_Local_Name --
1113 -----------------------------
1117 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1118 -- | library_unit_NAME
1120 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1121 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1126 if Nkind (Argx) not in N_Direct_Name
1127 and then (Nkind (Argx) /= N_Attribute_Reference
1128 or else Present (Expressions (Argx))
1129 or else Nkind (Prefix (Argx)) /= N_Identifier)
1130 and then (not Is_Entity_Name (Argx)
1131 or else not Is_Compilation_Unit (Entity (Argx)))
1133 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1136 -- No further check required if not an entity name
1138 if not Is_Entity_Name (Argx) then
1144 Ent : constant Entity_Id := Entity (Argx);
1145 Scop : constant Entity_Id := Scope (Ent);
1147 -- Case of a pragma applied to a compilation unit: pragma must
1148 -- occur immediately after the program unit in the compilation.
1150 if Is_Compilation_Unit (Ent) then
1152 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1155 -- Case of pragma placed immediately after spec
1157 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1160 -- Case of pragma placed immediately after body
1162 elsif Nkind (Decl) = N_Subprogram_Declaration
1163 and then Present (Corresponding_Body (Decl))
1167 (Parent (Unit_Declaration_Node
1168 (Corresponding_Body (Decl))));
1170 -- All other cases are illegal
1177 -- Special restricted placement rule from 10.2.1(11.8/2)
1179 elsif Is_Generic_Formal (Ent)
1180 and then Prag_Id = Pragma_Preelaborable_Initialization
1182 OK := List_Containing (N) =
1183 Generic_Formal_Declarations
1184 (Unit_Declaration_Node (Scop));
1186 -- Default case, just check that the pragma occurs in the scope
1187 -- of the entity denoted by the name.
1190 OK := Current_Scope = Scop;
1195 ("pragma% argument must be in same declarative part", Arg);
1199 end Check_Arg_Is_Local_Name;
1201 ---------------------------------
1202 -- Check_Arg_Is_Locking_Policy --
1203 ---------------------------------
1205 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1206 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1209 Check_Arg_Is_Identifier (Argx);
1211 if not Is_Locking_Policy_Name (Chars (Argx)) then
1212 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1214 end Check_Arg_Is_Locking_Policy;
1216 -----------------------------------------------
1217 -- Check_Arg_Is_Partition_Elaboration_Policy --
1218 -----------------------------------------------
1220 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
1221 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1224 Check_Arg_Is_Identifier (Argx);
1226 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
1228 ("& is not a valid partition elaboration policy name", Argx);
1230 end Check_Arg_Is_Partition_Elaboration_Policy;
1232 -------------------------
1233 -- Check_Arg_Is_One_Of --
1234 -------------------------
1236 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1237 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1240 Check_Arg_Is_Identifier (Argx);
1242 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1243 Error_Msg_Name_2 := N1;
1244 Error_Msg_Name_3 := N2;
1245 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1247 end Check_Arg_Is_One_Of;
1249 procedure Check_Arg_Is_One_Of
1251 N1, N2, N3 : Name_Id)
1253 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1256 Check_Arg_Is_Identifier (Argx);
1258 if Chars (Argx) /= N1
1259 and then Chars (Argx) /= N2
1260 and then Chars (Argx) /= N3
1262 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1264 end Check_Arg_Is_One_Of;
1266 procedure Check_Arg_Is_One_Of
1268 N1, N2, N3, N4 : Name_Id)
1270 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1273 Check_Arg_Is_Identifier (Argx);
1275 if Chars (Argx) /= N1
1276 and then Chars (Argx) /= N2
1277 and then Chars (Argx) /= N3
1278 and then Chars (Argx) /= N4
1280 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1282 end Check_Arg_Is_One_Of;
1284 procedure Check_Arg_Is_One_Of
1286 N1, N2, N3, N4, N5 : Name_Id)
1288 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1291 Check_Arg_Is_Identifier (Argx);
1293 if Chars (Argx) /= N1
1294 and then Chars (Argx) /= N2
1295 and then Chars (Argx) /= N3
1296 and then Chars (Argx) /= N4
1297 and then Chars (Argx) /= N5
1299 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1301 end Check_Arg_Is_One_Of;
1303 ---------------------------------
1304 -- Check_Arg_Is_Queuing_Policy --
1305 ---------------------------------
1307 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1308 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1311 Check_Arg_Is_Identifier (Argx);
1313 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1314 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1316 end Check_Arg_Is_Queuing_Policy;
1318 ------------------------------------
1319 -- Check_Arg_Is_Static_Expression --
1320 ------------------------------------
1322 procedure Check_Arg_Is_Static_Expression
1324 Typ : Entity_Id := Empty)
1327 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1328 end Check_Arg_Is_Static_Expression;
1330 ------------------------------------------
1331 -- Check_Arg_Is_Task_Dispatching_Policy --
1332 ------------------------------------------
1334 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1335 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1338 Check_Arg_Is_Identifier (Argx);
1340 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1342 ("& is not a valid task dispatching policy name", Argx);
1344 end Check_Arg_Is_Task_Dispatching_Policy;
1346 ---------------------
1347 -- Check_Arg_Order --
1348 ---------------------
1350 procedure Check_Arg_Order (Names : Name_List) is
1353 Highest_So_Far : Natural := 0;
1354 -- Highest index in Names seen do far
1358 for J in 1 .. Arg_Count loop
1359 if Chars (Arg) /= No_Name then
1360 for K in Names'Range loop
1361 if Chars (Arg) = Names (K) then
1362 if K < Highest_So_Far then
1363 Error_Msg_Name_1 := Pname;
1365 ("parameters out of order for pragma%", Arg);
1366 Error_Msg_Name_1 := Names (K);
1367 Error_Msg_Name_2 := Names (Highest_So_Far);
1368 Error_Msg_N ("\% must appear before %", Arg);
1372 Highest_So_Far := K;
1380 end Check_Arg_Order;
1382 --------------------------------
1383 -- Check_At_Least_N_Arguments --
1384 --------------------------------
1386 procedure Check_At_Least_N_Arguments (N : Nat) is
1388 if Arg_Count < N then
1389 Error_Pragma ("too few arguments for pragma%");
1391 end Check_At_Least_N_Arguments;
1393 -------------------------------
1394 -- Check_At_Most_N_Arguments --
1395 -------------------------------
1397 procedure Check_At_Most_N_Arguments (N : Nat) is
1400 if Arg_Count > N then
1402 for J in 1 .. N loop
1404 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1407 end Check_At_Most_N_Arguments;
1409 ---------------------
1410 -- Check_Component --
1411 ---------------------
1413 procedure Check_Component
1416 In_Variant_Part : Boolean := False)
1418 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1419 Sindic : constant Node_Id :=
1420 Subtype_Indication (Component_Definition (Comp));
1421 Typ : constant Entity_Id := Etype (Comp_Id);
1424 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1425 -- object constraint, then the component type shall be an Unchecked_
1428 if Nkind (Sindic) = N_Subtype_Indication
1429 and then Has_Per_Object_Constraint (Comp_Id)
1430 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1433 ("component subtype subject to per-object constraint " &
1434 "must be an Unchecked_Union", Comp);
1436 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1437 -- the body of a generic unit, or within the body of any of its
1438 -- descendant library units, no part of the type of a component
1439 -- declared in a variant_part of the unchecked union type shall be of
1440 -- a formal private type or formal private extension declared within
1441 -- the formal part of the generic unit.
1443 elsif Ada_Version >= Ada_2012
1444 and then In_Generic_Body (UU_Typ)
1445 and then In_Variant_Part
1446 and then Is_Private_Type (Typ)
1447 and then Is_Generic_Type (Typ)
1450 ("component of unchecked union cannot be of generic type", Comp);
1452 elsif Needs_Finalization (Typ) then
1454 ("component of unchecked union cannot be controlled", Comp);
1456 elsif Has_Task (Typ) then
1458 ("component of unchecked union cannot have tasks", Comp);
1460 end Check_Component;
1462 ---------------------------------
1463 -- Check_Contract_Or_Test_Case --
1464 ---------------------------------
1466 procedure Check_Contract_Or_Test_Case is
1470 procedure Chain_CTC (PO : Node_Id);
1471 -- If PO is a [generic] subprogram declaration node, then the
1472 -- contract-case or test-case applies to this subprogram and the
1473 -- processing for the pragma is completed. Otherwise the pragma
1480 procedure Chain_CTC (PO : Node_Id) is
1484 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1486 ("pragma% cannot be applied to abstract subprogram");
1488 elsif Nkind (PO) = N_Entry_Declaration then
1489 Error_Pragma ("pragma% cannot be applied to entry");
1491 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1492 N_Generic_Subprogram_Declaration)
1497 -- Here if we have [generic] subprogram declaration
1499 S := Defining_Unit_Name (Specification (PO));
1501 -- Note: we do not analyze the pragma at this point. Instead we
1502 -- delay this analysis until the end of the declarative part in
1503 -- which the pragma appears. This implements the required delay
1504 -- in this analysis, allowing forward references. The analysis
1505 -- happens at the end of Analyze_Declarations.
1507 -- There should not be another contract-case or test-case with the
1508 -- same name associated to this subprogram.
1511 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
1515 CTC := Spec_CTC_List (Contract (S));
1516 while Present (CTC) loop
1518 -- Omit pragma Contract_Cases because it does not introduce
1519 -- a unique case name and it does not follow the syntax of
1520 -- Contract_Case and Test_Case.
1522 if Pragma_Name (CTC) = Name_Contract_Cases then
1526 (Name, Get_Name_From_CTC_Pragma (CTC))
1528 Error_Msg_Sloc := Sloc (CTC);
1529 Error_Pragma ("name for pragma% is already used#");
1532 CTC := Next_Pragma (CTC);
1536 -- Chain spec CTC pragma to list for subprogram
1538 Set_Next_Pragma (N, Spec_CTC_List (Contract (S)));
1539 Set_Spec_CTC_List (Contract (S), N);
1542 -- Start of processing for Check_Contract_Or_Test_Case
1545 -- First check pragma arguments
1548 Check_At_Least_N_Arguments (2);
1549 Check_At_Most_N_Arguments (4);
1551 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
1553 Check_Optional_Identifier (Arg1, Name_Name);
1554 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
1556 -- In ASIS mode, for a pragma generated from a source aspect, also
1557 -- analyze the original aspect expression.
1560 and then Present (Corresponding_Aspect (N))
1562 Check_Expr_Is_Static_Expression
1563 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
1566 Check_Optional_Identifier (Arg2, Name_Mode);
1567 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
1569 if Arg_Count = 4 then
1570 Check_Identifier (Arg3, Name_Requires);
1571 Check_Identifier (Arg4, Name_Ensures);
1573 elsif Arg_Count = 3 then
1574 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
1577 -- Check pragma placement
1579 if not Is_List_Member (N) then
1583 -- Contract-case or test-case should only appear in package spec unit
1585 if Get_Source_Unit (N) = No_Unit
1586 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
1587 N_Package_Declaration,
1588 N_Generic_Package_Declaration)
1593 -- Search prior declarations
1596 while Present (Prev (P)) loop
1599 -- If the previous node is a generic subprogram, do not go to to
1600 -- the original node, which is the unanalyzed tree: we need to
1601 -- attach the contract-case or test-case to the analyzed version
1602 -- at this point. They get propagated to the original tree when
1603 -- analyzing the corresponding body.
1605 if Nkind (P) not in N_Generic_Declaration then
1606 PO := Original_Node (P);
1611 -- Skip past prior pragma
1613 if Nkind (PO) = N_Pragma then
1616 -- Skip stuff not coming from source
1618 elsif not Comes_From_Source (PO) then
1621 -- Only remaining possibility is subprogram declaration. First
1622 -- check that it is declared directly in a package declaration.
1623 -- This may be either the package declaration for the current unit
1624 -- being defined or a local package declaration.
1626 elsif not Present (Parent (Parent (PO)))
1627 or else not Present (Parent (Parent (Parent (PO))))
1628 or else not Nkind_In (Parent (Parent (PO)),
1629 N_Package_Declaration,
1630 N_Generic_Package_Declaration)
1640 -- If we fall through, pragma was misplaced
1643 end Check_Contract_Or_Test_Case;
1645 ----------------------------
1646 -- Check_Duplicate_Pragma --
1647 ----------------------------
1649 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1650 Id : Entity_Id := E;
1654 -- Nothing to do if this pragma comes from an aspect specification,
1655 -- since we could not be duplicating a pragma, and we dealt with the
1656 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1658 if From_Aspect_Specification (N) then
1662 -- Otherwise current pragma may duplicate previous pragma or a
1663 -- previously given aspect specification or attribute definition
1664 -- clause for the same pragma.
1666 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
1669 Error_Msg_Name_1 := Pragma_Name (N);
1670 Error_Msg_Sloc := Sloc (P);
1672 -- For a single protected or a single task object, the error is
1673 -- issued on the original entity.
1675 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
1676 Id := Defining_Identifier (Original_Node (Parent (Id)));
1679 if Nkind (P) = N_Aspect_Specification
1680 or else From_Aspect_Specification (P)
1682 Error_Msg_NE ("aspect% for & previously given#", N, Id);
1684 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
1689 end Check_Duplicate_Pragma;
1691 ----------------------------------
1692 -- Check_Duplicated_Export_Name --
1693 ----------------------------------
1695 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1696 String_Val : constant String_Id := Strval (Nam);
1699 -- We are only interested in the export case, and in the case of
1700 -- generics, it is the instance, not the template, that is the
1701 -- problem (the template will generate a warning in any case).
1703 if not Inside_A_Generic
1704 and then (Prag_Id = Pragma_Export
1706 Prag_Id = Pragma_Export_Procedure
1708 Prag_Id = Pragma_Export_Valued_Procedure
1710 Prag_Id = Pragma_Export_Function)
1712 for J in Externals.First .. Externals.Last loop
1713 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1714 Error_Msg_Sloc := Sloc (Externals.Table (J));
1715 Error_Msg_N ("external name duplicates name given#", Nam);
1720 Externals.Append (Nam);
1722 end Check_Duplicated_Export_Name;
1724 -------------------------------------
1725 -- Check_Expr_Is_Static_Expression --
1726 -------------------------------------
1728 procedure Check_Expr_Is_Static_Expression
1730 Typ : Entity_Id := Empty)
1733 if Present (Typ) then
1734 Analyze_And_Resolve (Expr, Typ);
1736 Analyze_And_Resolve (Expr);
1739 if Is_OK_Static_Expression (Expr) then
1742 elsif Etype (Expr) = Any_Type then
1745 -- An interesting special case, if we have a string literal and we
1746 -- are in Ada 83 mode, then we allow it even though it will not be
1747 -- flagged as static. This allows the use of Ada 95 pragmas like
1748 -- Import in Ada 83 mode. They will of course be flagged with
1749 -- warnings as usual, but will not cause errors.
1751 elsif Ada_Version = Ada_83
1752 and then Nkind (Expr) = N_String_Literal
1756 -- Static expression that raises Constraint_Error. This has already
1757 -- been flagged, so just exit from pragma processing.
1759 elsif Is_Static_Expression (Expr) then
1762 -- Finally, we have a real error
1765 Error_Msg_Name_1 := Pname;
1769 "argument for pragma% must be a static expression!";
1772 Flag_Non_Static_Expr (Msg, Expr);
1777 end Check_Expr_Is_Static_Expression;
1779 -------------------------
1780 -- Check_First_Subtype --
1781 -------------------------
1783 procedure Check_First_Subtype (Arg : Node_Id) is
1784 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1785 Ent : constant Entity_Id := Entity (Argx);
1788 if Is_First_Subtype (Ent) then
1791 elsif Is_Type (Ent) then
1793 ("pragma% cannot apply to subtype", Argx);
1795 elsif Is_Object (Ent) then
1797 ("pragma% cannot apply to object, requires a type", Argx);
1801 ("pragma% cannot apply to&, requires a type", Argx);
1803 end Check_First_Subtype;
1805 ----------------------
1806 -- Check_Identifier --
1807 ----------------------
1809 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1812 and then Nkind (Arg) = N_Pragma_Argument_Association
1814 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1815 Error_Msg_Name_1 := Pname;
1816 Error_Msg_Name_2 := Id;
1817 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1821 end Check_Identifier;
1823 --------------------------------
1824 -- Check_Identifier_Is_One_Of --
1825 --------------------------------
1827 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1830 and then Nkind (Arg) = N_Pragma_Argument_Association
1832 if Chars (Arg) = No_Name then
1833 Error_Msg_Name_1 := Pname;
1834 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1837 elsif Chars (Arg) /= N1
1838 and then Chars (Arg) /= N2
1840 Error_Msg_Name_1 := Pname;
1841 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1845 end Check_Identifier_Is_One_Of;
1847 ---------------------------
1848 -- Check_In_Main_Program --
1849 ---------------------------
1851 procedure Check_In_Main_Program is
1852 P : constant Node_Id := Parent (N);
1855 -- Must be at in subprogram body
1857 if Nkind (P) /= N_Subprogram_Body then
1858 Error_Pragma ("% pragma allowed only in subprogram");
1860 -- Otherwise warn if obviously not main program
1862 elsif Present (Parameter_Specifications (Specification (P)))
1863 or else not Is_Compilation_Unit (Defining_Entity (P))
1865 Error_Msg_Name_1 := Pname;
1867 ("??pragma% is only effective in main program", N);
1869 end Check_In_Main_Program;
1871 ---------------------------------------
1872 -- Check_Interrupt_Or_Attach_Handler --
1873 ---------------------------------------
1875 procedure Check_Interrupt_Or_Attach_Handler is
1876 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1877 Handler_Proc, Proc_Scope : Entity_Id;
1882 if Prag_Id = Pragma_Interrupt_Handler then
1883 Check_Restriction (No_Dynamic_Attachment, N);
1886 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1887 Proc_Scope := Scope (Handler_Proc);
1889 -- On AAMP only, a pragma Interrupt_Handler is supported for
1890 -- nonprotected parameterless procedures.
1892 if not AAMP_On_Target
1893 or else Prag_Id = Pragma_Attach_Handler
1895 if Ekind (Proc_Scope) /= E_Protected_Type then
1897 ("argument of pragma% must be protected procedure", Arg1);
1900 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1901 Error_Pragma ("pragma% must be in protected definition");
1905 if not Is_Library_Level_Entity (Proc_Scope)
1906 or else (AAMP_On_Target
1907 and then not Is_Library_Level_Entity (Handler_Proc))
1910 ("argument for pragma% must be library level entity", Arg1);
1913 -- AI05-0033: A pragma cannot appear within a generic body, because
1914 -- instance can be in a nested scope. The check that protected type
1915 -- is itself a library-level declaration is done elsewhere.
1917 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
1918 -- handle code prior to AI-0033. Analysis tools typically are not
1919 -- interested in this pragma in any case, so no need to worry too
1920 -- much about its placement.
1922 if Inside_A_Generic then
1923 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1924 and then In_Package_Body (Scope (Current_Scope))
1925 and then not Relaxed_RM_Semantics
1927 Error_Pragma ("pragma% cannot be used inside a generic");
1930 end Check_Interrupt_Or_Attach_Handler;
1932 ---------------------------------
1933 -- Check_Loop_Pragma_Placement --
1934 ---------------------------------
1936 procedure Check_Loop_Pragma_Placement is
1937 procedure Placement_Error (Constr : Node_Id);
1938 pragma No_Return (Placement_Error);
1939 -- Node Constr denotes the last loop restricted construct before we
1940 -- encountered an illegal relation between enclosing constructs. Emit
1941 -- an error depending on what Constr was.
1943 ---------------------
1944 -- Placement_Error --
1945 ---------------------
1947 procedure Placement_Error (Constr : Node_Id) is
1949 if Nkind (Constr) = N_Pragma then
1951 ("pragma % must appear immediately within the statements " &
1955 ("block containing pragma % must appear immediately within " &
1956 "the statements of a loop", Constr);
1958 end Placement_Error;
1960 -- Local declarations
1965 -- Start of processing for Check_Loop_Pragma_Placement
1970 while Present (Stmt) loop
1972 -- The pragma or previous block must appear immediately within the
1973 -- current block's declarative or statement part.
1975 if Nkind (Stmt) = N_Block_Statement then
1976 if (No (Declarations (Stmt))
1977 or else List_Containing (Prev) /= Declarations (Stmt))
1979 List_Containing (Prev) /=
1980 Statements (Handled_Statement_Sequence (Stmt))
1982 Placement_Error (Prev);
1985 -- Keep inspecting the parents because we are now within a
1986 -- chain of nested blocks.
1990 Stmt := Parent (Stmt);
1993 -- The pragma or previous block must appear immediately within the
1994 -- statements of the loop.
1996 elsif Nkind (Stmt) = N_Loop_Statement then
1997 if List_Containing (Prev) /= Statements (Stmt) then
1998 Placement_Error (Prev);
2001 -- Stop the traversal because we reached the innermost loop
2002 -- regardless of whether we encountered an error or not.
2006 -- Ignore a handled statement sequence. Note that this node may
2007 -- be related to a subprogram body in which case we will emit an
2008 -- error on the next iteration of the search.
2010 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
2011 Stmt := Parent (Stmt);
2013 -- Any other statement breaks the chain from the pragma to the
2017 Placement_Error (Prev);
2021 end Check_Loop_Pragma_Placement;
2023 -------------------------------------------
2024 -- Check_Is_In_Decl_Part_Or_Package_Spec --
2025 -------------------------------------------
2027 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
2036 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
2039 elsif Nkind_In (P, N_Package_Specification,
2044 -- Note: the following tests seem a little peculiar, because
2045 -- they test for bodies, but if we were in the statement part
2046 -- of the body, we would already have hit the handled statement
2047 -- sequence, so the only way we get here is by being in the
2048 -- declarative part of the body.
2050 elsif Nkind_In (P, N_Subprogram_Body,
2061 Error_Pragma ("pragma% is not in declarative part or package spec");
2062 end Check_Is_In_Decl_Part_Or_Package_Spec;
2064 -------------------------
2065 -- Check_No_Identifier --
2066 -------------------------
2068 procedure Check_No_Identifier (Arg : Node_Id) is
2070 if Nkind (Arg) = N_Pragma_Argument_Association
2071 and then Chars (Arg) /= No_Name
2073 Error_Pragma_Arg_Ident
2074 ("pragma% does not permit identifier& here", Arg);
2076 end Check_No_Identifier;
2078 --------------------------
2079 -- Check_No_Identifiers --
2080 --------------------------
2082 procedure Check_No_Identifiers is
2085 if Arg_Count > 0 then
2087 while Present (Arg_Node) loop
2088 Check_No_Identifier (Arg_Node);
2092 end Check_No_Identifiers;
2094 ------------------------
2095 -- Check_No_Link_Name --
2096 ------------------------
2098 procedure Check_No_Link_Name is
2101 and then Chars (Arg3) = Name_Link_Name
2106 if Present (Arg4) then
2108 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
2110 end Check_No_Link_Name;
2112 -------------------------------
2113 -- Check_Optional_Identifier --
2114 -------------------------------
2116 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
2119 and then Nkind (Arg) = N_Pragma_Argument_Association
2120 and then Chars (Arg) /= No_Name
2122 if Chars (Arg) /= Id then
2123 Error_Msg_Name_1 := Pname;
2124 Error_Msg_Name_2 := Id;
2125 Error_Msg_N ("pragma% argument expects identifier%", Arg);
2129 end Check_Optional_Identifier;
2131 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
2133 Name_Buffer (1 .. Id'Length) := Id;
2134 Name_Len := Id'Length;
2135 Check_Optional_Identifier (Arg, Name_Find);
2136 end Check_Optional_Identifier;
2138 --------------------------------------
2139 -- Check_Precondition_Postcondition --
2140 --------------------------------------
2142 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
2146 procedure Chain_PPC (PO : Node_Id);
2147 -- If PO is an entry or a [generic] subprogram declaration node, then
2148 -- the precondition/postcondition applies to this subprogram and the
2149 -- processing for the pragma is completed. Otherwise the pragma is
2156 procedure Chain_PPC (PO : Node_Id) is
2160 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2161 if not From_Aspect_Specification (N) then
2163 ("pragma% cannot be applied to abstract subprogram");
2165 elsif Class_Present (N) then
2170 ("aspect % requires ''Class for abstract subprogram");
2173 -- AI05-0230: The same restriction applies to null procedures. For
2174 -- compatibility with earlier uses of the Ada pragma, apply this
2175 -- rule only to aspect specifications.
2177 -- The above discrpency needs documentation. Robert is dubious
2178 -- about whether it is a good idea ???
2180 elsif Nkind (PO) = N_Subprogram_Declaration
2181 and then Nkind (Specification (PO)) = N_Procedure_Specification
2182 and then Null_Present (Specification (PO))
2183 and then From_Aspect_Specification (N)
2184 and then not Class_Present (N)
2187 ("aspect % requires ''Class for null procedure");
2189 -- Pre/postconditions are legal on a subprogram body if it is not
2190 -- a completion of a declaration.
2192 elsif Nkind (PO) = N_Subprogram_Body
2193 and then Acts_As_Spec (PO)
2197 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2198 N_Expression_Function,
2199 N_Generic_Subprogram_Declaration,
2200 N_Entry_Declaration)
2205 -- Here if we have [generic] subprogram or entry declaration
2207 if Nkind (PO) = N_Entry_Declaration then
2208 S := Defining_Entity (PO);
2210 S := Defining_Unit_Name (Specification (PO));
2212 if Nkind (S) = N_Defining_Program_Unit_Name then
2213 S := Defining_Identifier (S);
2217 -- Note: we do not analyze the pragma at this point. Instead we
2218 -- delay this analysis until the end of the declarative part in
2219 -- which the pragma appears. This implements the required delay
2220 -- in this analysis, allowing forward references. The analysis
2221 -- happens at the end of Analyze_Declarations.
2223 -- Chain spec PPC pragma to list for subprogram
2225 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
2226 Set_Spec_PPC_List (Contract (S), N);
2228 -- Return indicating spec case
2234 -- Start of processing for Check_Precondition_Postcondition
2237 if not Is_List_Member (N) then
2241 -- Preanalyze message argument if present. Visibility in this
2242 -- argument is established at the point of pragma occurrence.
2244 if Arg_Count = 2 then
2245 Check_Optional_Identifier (Arg2, Name_Message);
2246 Preanalyze_Spec_Expression
2247 (Get_Pragma_Arg (Arg2), Standard_String);
2250 -- For a pragma PPC in the extended main source unit, record enabled
2253 -- This may seem redundant with the call to Check_Enabled occurring
2254 -- later on when the pragma is rewritten into a pragma Check but
2255 -- is actually required in the case of a postcondition within a
2258 if Check_Enabled (Pname) and then not Split_PPC (N) then
2259 Set_SCO_Pragma_Enabled (Loc);
2262 -- If we are within an inlined body, the legality of the pragma
2263 -- has been checked already.
2265 if In_Inlined_Body then
2270 -- Search prior declarations
2273 while Present (Prev (P)) loop
2276 -- If the previous node is a generic subprogram, do not go to to
2277 -- the original node, which is the unanalyzed tree: we need to
2278 -- attach the pre/postconditions to the analyzed version at this
2279 -- point. They get propagated to the original tree when analyzing
2280 -- the corresponding body.
2282 if Nkind (P) not in N_Generic_Declaration then
2283 PO := Original_Node (P);
2288 -- Skip past prior pragma
2290 if Nkind (PO) = N_Pragma then
2293 -- Skip stuff not coming from source
2295 elsif not Comes_From_Source (PO) then
2297 -- The condition may apply to a subprogram instantiation
2299 if Nkind (PO) = N_Subprogram_Declaration
2300 and then Present (Generic_Parent (Specification (PO)))
2305 elsif Nkind (PO) = N_Subprogram_Declaration
2306 and then In_Instance
2311 -- For all other cases of non source code, do nothing
2317 -- Only remaining possibility is subprogram declaration
2325 -- If we fall through loop, pragma is at start of list, so see if it
2326 -- is at the start of declarations of a subprogram body.
2328 if Nkind (Parent (N)) = N_Subprogram_Body
2329 and then List_Containing (N) = Declarations (Parent (N))
2331 if Operating_Mode /= Generate_Code
2332 or else Inside_A_Generic
2334 -- Analyze pragma expression for correctness and for ASIS use
2336 Preanalyze_Assert_Expression
2337 (Get_Pragma_Arg (Arg1), Standard_Boolean);
2339 -- In ASIS mode, for a pragma generated from a source aspect,
2340 -- also analyze the original aspect expression.
2343 and then Present (Corresponding_Aspect (N))
2345 Preanalyze_Assert_Expression
2346 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2353 -- See if it is in the pragmas after a library level subprogram
2355 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2357 -- In formal verification mode, analyze pragma expression for
2358 -- correctness, as it is not expanded later.
2361 Analyze_PPC_In_Decl_Part
2362 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2365 Chain_PPC (Unit (Parent (Parent (N))));
2369 -- If we fall through, pragma was misplaced
2372 end Check_Precondition_Postcondition;
2374 -----------------------------
2375 -- Check_Static_Constraint --
2376 -----------------------------
2378 -- Note: for convenience in writing this procedure, in addition to
2379 -- the officially (i.e. by spec) allowed argument which is always a
2380 -- constraint, it also allows ranges and discriminant associations.
2381 -- Above is not clear ???
2383 procedure Check_Static_Constraint (Constr : Node_Id) is
2385 procedure Require_Static (E : Node_Id);
2386 -- Require given expression to be static expression
2388 --------------------
2389 -- Require_Static --
2390 --------------------
2392 procedure Require_Static (E : Node_Id) is
2394 if not Is_OK_Static_Expression (E) then
2395 Flag_Non_Static_Expr
2396 ("non-static constraint not allowed in Unchecked_Union!", E);
2401 -- Start of processing for Check_Static_Constraint
2404 case Nkind (Constr) is
2405 when N_Discriminant_Association =>
2406 Require_Static (Expression (Constr));
2409 Require_Static (Low_Bound (Constr));
2410 Require_Static (High_Bound (Constr));
2412 when N_Attribute_Reference =>
2413 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2414 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2416 when N_Range_Constraint =>
2417 Check_Static_Constraint (Range_Expression (Constr));
2419 when N_Index_Or_Discriminant_Constraint =>
2423 IDC := First (Constraints (Constr));
2424 while Present (IDC) loop
2425 Check_Static_Constraint (IDC);
2433 end Check_Static_Constraint;
2435 --------------------------------------
2436 -- Check_Valid_Configuration_Pragma --
2437 --------------------------------------
2439 -- A configuration pragma must appear in the context clause of a
2440 -- compilation unit, and only other pragmas may precede it. Note that
2441 -- the test also allows use in a configuration pragma file.
2443 procedure Check_Valid_Configuration_Pragma is
2445 if not Is_Configuration_Pragma then
2446 Error_Pragma ("incorrect placement for configuration pragma%");
2448 end Check_Valid_Configuration_Pragma;
2450 -------------------------------------
2451 -- Check_Valid_Library_Unit_Pragma --
2452 -------------------------------------
2454 procedure Check_Valid_Library_Unit_Pragma is
2456 Parent_Node : Node_Id;
2457 Unit_Name : Entity_Id;
2458 Unit_Kind : Node_Kind;
2459 Unit_Node : Node_Id;
2460 Sindex : Source_File_Index;
2463 if not Is_List_Member (N) then
2467 Plist := List_Containing (N);
2468 Parent_Node := Parent (Plist);
2470 if Parent_Node = Empty then
2473 -- Case of pragma appearing after a compilation unit. In this case
2474 -- it must have an argument with the corresponding name and must
2475 -- be part of the following pragmas of its parent.
2477 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2478 if Plist /= Pragmas_After (Parent_Node) then
2481 elsif Arg_Count = 0 then
2483 ("argument required if outside compilation unit");
2486 Check_No_Identifiers;
2487 Check_Arg_Count (1);
2488 Unit_Node := Unit (Parent (Parent_Node));
2489 Unit_Kind := Nkind (Unit_Node);
2491 Analyze (Get_Pragma_Arg (Arg1));
2493 if Unit_Kind = N_Generic_Subprogram_Declaration
2494 or else Unit_Kind = N_Subprogram_Declaration
2496 Unit_Name := Defining_Entity (Unit_Node);
2498 elsif Unit_Kind in N_Generic_Instantiation then
2499 Unit_Name := Defining_Entity (Unit_Node);
2502 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2505 if Chars (Unit_Name) /=
2506 Chars (Entity (Get_Pragma_Arg (Arg1)))
2509 ("pragma% argument is not current unit name", Arg1);
2512 if Ekind (Unit_Name) = E_Package
2513 and then Present (Renamed_Entity (Unit_Name))
2515 Error_Pragma ("pragma% not allowed for renamed package");
2519 -- Pragma appears other than after a compilation unit
2522 -- Here we check for the generic instantiation case and also
2523 -- for the case of processing a generic formal package. We
2524 -- detect these cases by noting that the Sloc on the node
2525 -- does not belong to the current compilation unit.
2527 Sindex := Source_Index (Current_Sem_Unit);
2529 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2530 Rewrite (N, Make_Null_Statement (Loc));
2533 -- If before first declaration, the pragma applies to the
2534 -- enclosing unit, and the name if present must be this name.
2536 elsif Is_Before_First_Decl (N, Plist) then
2537 Unit_Node := Unit_Declaration_Node (Current_Scope);
2538 Unit_Kind := Nkind (Unit_Node);
2540 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2543 elsif Unit_Kind = N_Subprogram_Body
2544 and then not Acts_As_Spec (Unit_Node)
2548 elsif Nkind (Parent_Node) = N_Package_Body then
2551 elsif Nkind (Parent_Node) = N_Package_Specification
2552 and then Plist = Private_Declarations (Parent_Node)
2556 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2557 or else Nkind (Parent_Node) =
2558 N_Generic_Subprogram_Declaration)
2559 and then Plist = Generic_Formal_Declarations (Parent_Node)
2563 elsif Arg_Count > 0 then
2564 Analyze (Get_Pragma_Arg (Arg1));
2566 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2568 ("name in pragma% must be enclosing unit", Arg1);
2571 -- It is legal to have no argument in this context
2577 -- Error if not before first declaration. This is because a
2578 -- library unit pragma argument must be the name of a library
2579 -- unit (RM 10.1.5(7)), but the only names permitted in this
2580 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2581 -- generic subprogram declarations or generic instantiations.
2585 ("pragma% misplaced, must be before first declaration");
2589 end Check_Valid_Library_Unit_Pragma;
2595 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2596 Clist : constant Node_Id := Component_List (Variant);
2600 Comp := First (Component_Items (Clist));
2601 while Present (Comp) loop
2602 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2611 procedure Error_Pragma (Msg : String) is
2612 MsgF : String := Msg;
2614 Error_Msg_Name_1 := Pname;
2616 Error_Msg_N (MsgF, N);
2620 ----------------------
2621 -- Error_Pragma_Arg --
2622 ----------------------
2624 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2625 MsgF : String := Msg;
2627 Error_Msg_Name_1 := Pname;
2629 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2631 end Error_Pragma_Arg;
2633 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2634 MsgF : String := Msg1;
2636 Error_Msg_Name_1 := Pname;
2638 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2639 Error_Pragma_Arg (Msg2, Arg);
2640 end Error_Pragma_Arg;
2642 ----------------------------
2643 -- Error_Pragma_Arg_Ident --
2644 ----------------------------
2646 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2647 MsgF : String := Msg;
2649 Error_Msg_Name_1 := Pname;
2651 Error_Msg_N (MsgF, Arg);
2653 end Error_Pragma_Arg_Ident;
2655 ----------------------
2656 -- Error_Pragma_Ref --
2657 ----------------------
2659 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2660 MsgF : String := Msg;
2662 Error_Msg_Name_1 := Pname;
2664 Error_Msg_Sloc := Sloc (Ref);
2665 Error_Msg_NE (MsgF, N, Ref);
2667 end Error_Pragma_Ref;
2669 ------------------------
2670 -- Find_Lib_Unit_Name --
2671 ------------------------
2673 function Find_Lib_Unit_Name return Entity_Id is
2675 -- Return inner compilation unit entity, for case of nested
2676 -- categorization pragmas. This happens in generic unit.
2678 if Nkind (Parent (N)) = N_Package_Specification
2679 and then Defining_Entity (Parent (N)) /= Current_Scope
2681 return Defining_Entity (Parent (N));
2683 return Current_Scope;
2685 end Find_Lib_Unit_Name;
2687 ----------------------------
2688 -- Find_Program_Unit_Name --
2689 ----------------------------
2691 procedure Find_Program_Unit_Name (Id : Node_Id) is
2692 Unit_Name : Entity_Id;
2693 Unit_Kind : Node_Kind;
2694 P : constant Node_Id := Parent (N);
2697 if Nkind (P) = N_Compilation_Unit then
2698 Unit_Kind := Nkind (Unit (P));
2700 if Unit_Kind = N_Subprogram_Declaration
2701 or else Unit_Kind = N_Package_Declaration
2702 or else Unit_Kind in N_Generic_Declaration
2704 Unit_Name := Defining_Entity (Unit (P));
2706 if Chars (Id) = Chars (Unit_Name) then
2707 Set_Entity (Id, Unit_Name);
2708 Set_Etype (Id, Etype (Unit_Name));
2710 Set_Etype (Id, Any_Type);
2712 ("cannot find program unit referenced by pragma%");
2716 Set_Etype (Id, Any_Type);
2717 Error_Pragma ("pragma% inapplicable to this unit");
2723 end Find_Program_Unit_Name;
2725 -----------------------------------------
2726 -- Find_Unique_Parameterless_Procedure --
2727 -----------------------------------------
2729 function Find_Unique_Parameterless_Procedure
2731 Arg : Node_Id) return Entity_Id
2733 Proc : Entity_Id := Empty;
2736 -- The body of this procedure needs some comments ???
2738 if not Is_Entity_Name (Name) then
2740 ("argument of pragma% must be entity name", Arg);
2742 elsif not Is_Overloaded (Name) then
2743 Proc := Entity (Name);
2745 if Ekind (Proc) /= E_Procedure
2746 or else Present (First_Formal (Proc))
2749 ("argument of pragma% must be parameterless procedure", Arg);
2754 Found : Boolean := False;
2756 Index : Interp_Index;
2759 Get_First_Interp (Name, Index, It);
2760 while Present (It.Nam) loop
2763 if Ekind (Proc) = E_Procedure
2764 and then No (First_Formal (Proc))
2768 Set_Entity (Name, Proc);
2769 Set_Is_Overloaded (Name, False);
2772 ("ambiguous handler name for pragma% ", Arg);
2776 Get_Next_Interp (Index, It);
2781 ("argument of pragma% must be parameterless procedure",
2784 Proc := Entity (Name);
2790 end Find_Unique_Parameterless_Procedure;
2796 procedure Fix_Error (Msg : in out String) is
2798 if From_Aspect_Specification (N) then
2799 for J in Msg'First .. Msg'Last - 5 loop
2800 if Msg (J .. J + 5) = "pragma" then
2801 Msg (J .. J + 5) := "aspect";
2805 if Error_Msg_Name_1 = Name_Precondition then
2806 Error_Msg_Name_1 := Name_Pre;
2807 elsif Error_Msg_Name_1 = Name_Postcondition then
2808 Error_Msg_Name_1 := Name_Post;
2813 -------------------------
2814 -- Gather_Associations --
2815 -------------------------
2817 procedure Gather_Associations
2819 Args : out Args_List)
2824 -- Initialize all parameters to Empty
2826 for J in Args'Range loop
2830 -- That's all we have to do if there are no argument associations
2832 if No (Pragma_Argument_Associations (N)) then
2836 -- Otherwise first deal with any positional parameters present
2838 Arg := First (Pragma_Argument_Associations (N));
2839 for Index in Args'Range loop
2840 exit when No (Arg) or else Chars (Arg) /= No_Name;
2841 Args (Index) := Get_Pragma_Arg (Arg);
2845 -- Positional parameters all processed, if any left, then we
2846 -- have too many positional parameters.
2848 if Present (Arg) and then Chars (Arg) = No_Name then
2850 ("too many positional associations for pragma%", Arg);
2853 -- Process named parameters if any are present
2855 while Present (Arg) loop
2856 if Chars (Arg) = No_Name then
2858 ("positional association cannot follow named association",
2862 for Index in Names'Range loop
2863 if Names (Index) = Chars (Arg) then
2864 if Present (Args (Index)) then
2866 ("duplicate argument association for pragma%", Arg);
2868 Args (Index) := Get_Pragma_Arg (Arg);
2873 if Index = Names'Last then
2874 Error_Msg_Name_1 := Pname;
2875 Error_Msg_N ("pragma% does not allow & argument", Arg);
2877 -- Check for possible misspelling
2879 for Index1 in Names'Range loop
2880 if Is_Bad_Spelling_Of
2881 (Chars (Arg), Names (Index1))
2883 Error_Msg_Name_1 := Names (Index1);
2884 Error_Msg_N -- CODEFIX
2885 ("\possible misspelling of%", Arg);
2897 end Gather_Associations;
2903 procedure GNAT_Pragma is
2905 -- We need to check the No_Implementation_Pragmas restriction for
2906 -- the case of a pragma from source. Note that the case of aspects
2907 -- generating corresponding pragmas marks these pragmas as not being
2908 -- from source, so this test also catches that case.
2910 if Comes_From_Source (N) then
2911 Check_Restriction (No_Implementation_Pragmas, N);
2915 --------------------------
2916 -- Is_Before_First_Decl --
2917 --------------------------
2919 function Is_Before_First_Decl
2920 (Pragma_Node : Node_Id;
2921 Decls : List_Id) return Boolean
2923 Item : Node_Id := First (Decls);
2926 -- Only other pragmas can come before this pragma
2929 if No (Item) or else Nkind (Item) /= N_Pragma then
2932 elsif Item = Pragma_Node then
2938 end Is_Before_First_Decl;
2940 -----------------------------
2941 -- Is_Configuration_Pragma --
2942 -----------------------------
2944 -- A configuration pragma must appear in the context clause of a
2945 -- compilation unit, and only other pragmas may precede it. Note that
2946 -- the test below also permits use in a configuration pragma file.
2948 function Is_Configuration_Pragma return Boolean is
2949 Lis : constant List_Id := List_Containing (N);
2950 Par : constant Node_Id := Parent (N);
2954 -- If no parent, then we are in the configuration pragma file,
2955 -- so the placement is definitely appropriate.
2960 -- Otherwise we must be in the context clause of a compilation unit
2961 -- and the only thing allowed before us in the context list is more
2962 -- configuration pragmas.
2964 elsif Nkind (Par) = N_Compilation_Unit
2965 and then Context_Items (Par) = Lis
2972 elsif Nkind (Prg) /= N_Pragma then
2982 end Is_Configuration_Pragma;
2984 --------------------------
2985 -- Is_In_Context_Clause --
2986 --------------------------
2988 function Is_In_Context_Clause return Boolean is
2990 Parent_Node : Node_Id;
2993 if not Is_List_Member (N) then
2997 Plist := List_Containing (N);
2998 Parent_Node := Parent (Plist);
3000 if Parent_Node = Empty
3001 or else Nkind (Parent_Node) /= N_Compilation_Unit
3002 or else Context_Items (Parent_Node) /= Plist
3009 end Is_In_Context_Clause;
3011 ---------------------------------
3012 -- Is_Static_String_Expression --
3013 ---------------------------------
3015 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
3016 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3019 Analyze_And_Resolve (Argx);
3020 return Is_OK_Static_Expression (Argx)
3021 and then Nkind (Argx) = N_String_Literal;
3022 end Is_Static_String_Expression;
3024 ----------------------
3025 -- Pragma_Misplaced --
3026 ----------------------
3028 procedure Pragma_Misplaced is
3030 Error_Pragma ("incorrect placement of pragma%");
3031 end Pragma_Misplaced;
3033 ------------------------------------
3034 -- Process_Atomic_Shared_Volatile --
3035 ------------------------------------
3037 procedure Process_Atomic_Shared_Volatile is
3044 procedure Set_Atomic (E : Entity_Id);
3045 -- Set given type as atomic, and if no explicit alignment was given,
3046 -- set alignment to unknown, since back end knows what the alignment
3047 -- requirements are for atomic arrays. Note: this step is necessary
3048 -- for derived types.
3054 procedure Set_Atomic (E : Entity_Id) is
3058 if not Has_Alignment_Clause (E) then
3059 Set_Alignment (E, Uint_0);
3063 -- Start of processing for Process_Atomic_Shared_Volatile
3066 Check_Ada_83_Warning;
3067 Check_No_Identifiers;
3068 Check_Arg_Count (1);
3069 Check_Arg_Is_Local_Name (Arg1);
3070 E_Id := Get_Pragma_Arg (Arg1);
3072 if Etype (E_Id) = Any_Type then
3077 D := Declaration_Node (E);
3080 -- Check duplicate before we chain ourselves!
3082 Check_Duplicate_Pragma (E);
3084 -- Now check appropriateness of the entity
3087 if Rep_Item_Too_Early (E, N)
3089 Rep_Item_Too_Late (E, N)
3093 Check_First_Subtype (Arg1);
3096 if Prag_Id /= Pragma_Volatile then
3098 Set_Atomic (Underlying_Type (E));
3099 Set_Atomic (Base_Type (E));
3102 -- Attribute belongs on the base type. If the view of the type is
3103 -- currently private, it also belongs on the underlying type.
3105 Set_Is_Volatile (Base_Type (E));
3106 Set_Is_Volatile (Underlying_Type (E));
3108 Set_Treat_As_Volatile (E);
3109 Set_Treat_As_Volatile (Underlying_Type (E));
3111 elsif K = N_Object_Declaration
3112 or else (K = N_Component_Declaration
3113 and then Original_Record_Component (E) = E)
3115 if Rep_Item_Too_Late (E, N) then
3119 if Prag_Id /= Pragma_Volatile then
3122 -- If the object declaration has an explicit initialization, a
3123 -- temporary may have to be created to hold the expression, to
3124 -- ensure that access to the object remain atomic.
3126 if Nkind (Parent (E)) = N_Object_Declaration
3127 and then Present (Expression (Parent (E)))
3129 Set_Has_Delayed_Freeze (E);
3132 -- An interesting improvement here. If an object of composite
3133 -- type X is declared atomic, and the type X isn't, that's a
3134 -- pity, since it may not have appropriate alignment etc. We
3135 -- can rescue this in the special case where the object and
3136 -- type are in the same unit by just setting the type as
3137 -- atomic, so that the back end will process it as atomic.
3139 -- Note: we used to do this for elementary types as well,
3140 -- but that turns out to be a bad idea and can have unwanted
3141 -- effects, most notably if the type is elementary, the object
3142 -- a simple component within a record, and both are in a spec:
3143 -- every object of this type in the entire program will be
3144 -- treated as atomic, thus incurring a potentially costly
3145 -- synchronization operation for every access.
3147 -- Of course it would be best if the back end could just adjust
3148 -- the alignment etc for the specific object, but that's not
3149 -- something we are capable of doing at this point.
3151 Utyp := Underlying_Type (Etype (E));
3154 and then Is_Composite_Type (Utyp)
3155 and then Sloc (E) > No_Location
3156 and then Sloc (Utyp) > No_Location
3158 Get_Source_File_Index (Sloc (E)) =
3159 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
3161 Set_Is_Atomic (Underlying_Type (Etype (E)));
3165 Set_Is_Volatile (E);
3166 Set_Treat_As_Volatile (E);
3170 ("inappropriate entity for pragma%", Arg1);
3172 end Process_Atomic_Shared_Volatile;
3174 -------------------------------------------
3175 -- Process_Compile_Time_Warning_Or_Error --
3176 -------------------------------------------
3178 procedure Process_Compile_Time_Warning_Or_Error is
3179 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
3182 Check_Arg_Count (2);
3183 Check_No_Identifiers;
3184 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3185 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3187 if Compile_Time_Known_Value (Arg1x) then
3188 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3190 Str : constant String_Id :=
3191 Strval (Get_Pragma_Arg (Arg2));
3192 Len : constant Int := String_Length (Str);
3197 Cent : constant Entity_Id :=
3198 Cunit_Entity (Current_Sem_Unit);
3200 Force : constant Boolean :=
3201 Prag_Id = Pragma_Compile_Time_Warning
3203 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3204 and then (Ekind (Cent) /= E_Package
3205 or else not In_Private_Part (Cent));
3206 -- Set True if this is the warning case, and we are in the
3207 -- visible part of a package spec, or in a subprogram spec,
3208 -- in which case we want to force the client to see the
3209 -- warning, even though it is not in the main unit.
3212 -- Loop through segments of message separated by line feeds.
3213 -- We output these segments as separate messages with
3214 -- continuation marks for all but the first.
3219 Error_Msg_Strlen := 0;
3221 -- Loop to copy characters from argument to error message
3225 exit when Ptr > Len;
3226 CC := Get_String_Char (Str, Ptr);
3229 -- Ignore wide chars ??? else store character
3231 if In_Character_Range (CC) then
3232 C := Get_Character (CC);
3233 exit when C = ASCII.LF;
3234 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3235 Error_Msg_String (Error_Msg_Strlen) := C;
3239 -- Here with one line ready to go
3241 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3243 -- If this is a warning in a spec, then we want clients
3244 -- to see the warning, so mark the message with the
3245 -- special sequence !! to force the warning. In the case
3246 -- of a package spec, we do not force this if we are in
3247 -- the private part of the spec.
3250 if Cont = False then
3251 Error_Msg_N ("<~!!", Arg1);
3254 Error_Msg_N ("\<~!!", Arg1);
3257 -- Error, rather than warning, or in a body, so we do not
3258 -- need to force visibility for client (error will be
3259 -- output in any case, and this is the situation in which
3260 -- we do not want a client to get a warning, since the
3261 -- warning is in the body or the spec private part).
3264 if Cont = False then
3265 Error_Msg_N ("<~", Arg1);
3268 Error_Msg_N ("\<~", Arg1);
3272 exit when Ptr > Len;
3277 end Process_Compile_Time_Warning_Or_Error;
3279 ------------------------
3280 -- Process_Convention --
3281 ------------------------
3283 procedure Process_Convention
3284 (C : out Convention_Id;
3285 Ent : out Entity_Id)
3291 Comp_Unit : Unit_Number_Type;
3293 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3294 -- Called if we have more than one Export/Import/Convention pragma.
3295 -- This is generally illegal, but we have a special case of allowing
3296 -- Import and Interface to coexist if they specify the convention in
3297 -- a consistent manner. We are allowed to do this, since Interface is
3298 -- an implementation defined pragma, and we choose to do it since we
3299 -- know Rational allows this combination. S is the entity id of the
3300 -- subprogram in question. This procedure also sets the special flag
3301 -- Import_Interface_Present in both pragmas in the case where we do
3302 -- have matching Import and Interface pragmas.
3304 procedure Set_Convention_From_Pragma (E : Entity_Id);
3305 -- Set convention in entity E, and also flag that the entity has a
3306 -- convention pragma. If entity is for a private or incomplete type,
3307 -- also set convention and flag on underlying type. This procedure
3308 -- also deals with the special case of C_Pass_By_Copy convention.
3310 -------------------------------
3311 -- Diagnose_Multiple_Pragmas --
3312 -------------------------------
3314 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3315 Pdec : constant Node_Id := Declaration_Node (S);
3319 function Same_Convention (Decl : Node_Id) return Boolean;
3320 -- Decl is a pragma node. This function returns True if this
3321 -- pragma has a first argument that is an identifier with a
3322 -- Chars field corresponding to the Convention_Id C.
3324 function Same_Name (Decl : Node_Id) return Boolean;
3325 -- Decl is a pragma node. This function returns True if this
3326 -- pragma has a second argument that is an identifier with a
3327 -- Chars field that matches the Chars of the current subprogram.
3329 ---------------------
3330 -- Same_Convention --
3331 ---------------------
3333 function Same_Convention (Decl : Node_Id) return Boolean is
3334 Arg1 : constant Node_Id :=
3335 First (Pragma_Argument_Associations (Decl));
3338 if Present (Arg1) then
3340 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3342 if Nkind (Arg) = N_Identifier
3343 and then Is_Convention_Name (Chars (Arg))
3344 and then Get_Convention_Id (Chars (Arg)) = C
3352 end Same_Convention;
3358 function Same_Name (Decl : Node_Id) return Boolean is
3359 Arg1 : constant Node_Id :=
3360 First (Pragma_Argument_Associations (Decl));
3368 Arg2 := Next (Arg1);
3375 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3377 if Nkind (Arg) = N_Identifier
3378 and then Chars (Arg) = Chars (S)
3387 -- Start of processing for Diagnose_Multiple_Pragmas
3392 -- Definitely give message if we have Convention/Export here
3394 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3397 -- If we have an Import or Export, scan back from pragma to
3398 -- find any previous pragma applying to the same procedure.
3399 -- The scan will be terminated by the start of the list, or
3400 -- hitting the subprogram declaration. This won't allow one
3401 -- pragma to appear in the public part and one in the private
3402 -- part, but that seems very unlikely in practice.
3406 while Present (Decl) and then Decl /= Pdec loop
3408 -- Look for pragma with same name as us
3410 if Nkind (Decl) = N_Pragma
3411 and then Same_Name (Decl)
3413 -- Give error if same as our pragma or Export/Convention
3415 if Pragma_Name (Decl) = Name_Export
3417 Pragma_Name (Decl) = Name_Convention
3419 Pragma_Name (Decl) = Pragma_Name (N)
3423 -- Case of Import/Interface or the other way round
3425 elsif Pragma_Name (Decl) = Name_Interface
3427 Pragma_Name (Decl) = Name_Import
3429 -- Here we know that we have Import and Interface. It
3430 -- doesn't matter which way round they are. See if
3431 -- they specify the same convention. If so, all OK,
3432 -- and set special flags to stop other messages
3434 if Same_Convention (Decl) then
3435 Set_Import_Interface_Present (N);
3436 Set_Import_Interface_Present (Decl);
3439 -- If different conventions, special message
3442 Error_Msg_Sloc := Sloc (Decl);
3444 ("convention differs from that given#", Arg1);
3454 -- Give message if needed if we fall through those tests
3458 ("at most one Convention/Export/Import pragma is allowed",
3461 end Diagnose_Multiple_Pragmas;
3463 --------------------------------
3464 -- Set_Convention_From_Pragma --
3465 --------------------------------
3467 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3469 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3470 -- for an overridden dispatching operation. Technically this is
3471 -- an amendment and should only be done in Ada 2005 mode. However,
3472 -- this is clearly a mistake, since the problem that is addressed
3473 -- by this AI is that there is a clear gap in the RM!
3475 if Is_Dispatching_Operation (E)
3476 and then Present (Overridden_Operation (E))
3477 and then C /= Convention (Overridden_Operation (E))
3480 ("cannot change convention for " &
3481 "overridden dispatching operation",
3485 -- Set the convention
3487 Set_Convention (E, C);
3488 Set_Has_Convention_Pragma (E);
3490 if Is_Incomplete_Or_Private_Type (E)
3491 and then Present (Underlying_Type (E))
3493 Set_Convention (Underlying_Type (E), C);
3494 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3497 -- A class-wide type should inherit the convention of the specific
3498 -- root type (although this isn't specified clearly by the RM).
3500 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3501 Set_Convention (Class_Wide_Type (E), C);
3504 -- If the entity is a record type, then check for special case of
3505 -- C_Pass_By_Copy, which is treated the same as C except that the
3506 -- special record flag is set. This convention is only permitted
3507 -- on record types (see AI95-00131).
3509 if Cname = Name_C_Pass_By_Copy then
3510 if Is_Record_Type (E) then
3511 Set_C_Pass_By_Copy (Base_Type (E));
3512 elsif Is_Incomplete_Or_Private_Type (E)
3513 and then Is_Record_Type (Underlying_Type (E))
3515 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3518 ("C_Pass_By_Copy convention allowed only for record type",
3523 -- If the entity is a derived boolean type, check for the special
3524 -- case of convention C, C++, or Fortran, where we consider any
3525 -- nonzero value to represent true.
3527 if Is_Discrete_Type (E)
3528 and then Root_Type (Etype (E)) = Standard_Boolean
3534 C = Convention_Fortran)
3536 Set_Nonzero_Is_True (Base_Type (E));
3538 end Set_Convention_From_Pragma;
3540 -- Start of processing for Process_Convention
3543 Check_At_Least_N_Arguments (2);
3544 Check_Optional_Identifier (Arg1, Name_Convention);
3545 Check_Arg_Is_Identifier (Arg1);
3546 Cname := Chars (Get_Pragma_Arg (Arg1));
3548 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3549 -- tested again below to set the critical flag).
3551 if Cname = Name_C_Pass_By_Copy then
3554 -- Otherwise we must have something in the standard convention list
3556 elsif Is_Convention_Name (Cname) then
3557 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3559 -- In DEC VMS, it seems that there is an undocumented feature that
3560 -- any unrecognized convention is treated as the default, which for
3561 -- us is convention C. It does not seem so terrible to do this
3562 -- unconditionally, silently in the VMS case, and with a warning
3563 -- in the non-VMS case.
3566 if Warn_On_Export_Import and not OpenVMS_On_Target then
3568 ("??unrecognized convention name, C assumed",
3569 Get_Pragma_Arg (Arg1));
3575 Check_Optional_Identifier (Arg2, Name_Entity);
3576 Check_Arg_Is_Local_Name (Arg2);
3578 Id := Get_Pragma_Arg (Arg2);
3581 if not Is_Entity_Name (Id) then
3582 Error_Pragma_Arg ("entity name required", Arg2);
3587 -- Set entity to return
3591 -- Ada_Pass_By_Copy special checking
3593 if C = Convention_Ada_Pass_By_Copy then
3594 if not Is_First_Subtype (E) then
3596 ("convention `Ada_Pass_By_Copy` only "
3597 & "allowed for types", Arg2);
3600 if Is_By_Reference_Type (E) then
3602 ("convention `Ada_Pass_By_Copy` not allowed for "
3603 & "by-reference type", Arg1);
3607 -- Ada_Pass_By_Reference special checking
3609 if C = Convention_Ada_Pass_By_Reference then
3610 if not Is_First_Subtype (E) then
3612 ("convention `Ada_Pass_By_Reference` only "
3613 & "allowed for types", Arg2);
3616 if Is_By_Copy_Type (E) then
3618 ("convention `Ada_Pass_By_Reference` not allowed for "
3619 & "by-copy type", Arg1);
3623 -- Go to renamed subprogram if present, since convention applies to
3624 -- the actual renamed entity, not to the renaming entity. If the
3625 -- subprogram is inherited, go to parent subprogram.
3627 if Is_Subprogram (E)
3628 and then Present (Alias (E))
3630 if Nkind (Parent (Declaration_Node (E))) =
3631 N_Subprogram_Renaming_Declaration
3633 if Scope (E) /= Scope (Alias (E)) then
3635 ("cannot apply pragma% to non-local entity&#", E);
3640 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3641 N_Private_Extension_Declaration)
3642 and then Scope (E) = Scope (Alias (E))
3646 -- Return the parent subprogram the entity was inherited from
3652 -- Check that we are not applying this to a specless body
3653 -- Relax this check if Relaxed_RM_Semantics to accomodate other Ada
3656 if Is_Subprogram (E)
3657 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3658 and then not Relaxed_RM_Semantics
3661 ("pragma% requires separate spec and must come before body");
3664 -- Check that we are not applying this to a named constant
3666 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3667 Error_Msg_Name_1 := Pname;
3669 ("cannot apply pragma% to named constant!",
3670 Get_Pragma_Arg (Arg2));
3672 ("\supply appropriate type for&!", Arg2);
3675 if Ekind (E) = E_Enumeration_Literal then
3676 Error_Pragma ("enumeration literal not allowed for pragma%");
3679 -- Check for rep item appearing too early or too late
3681 if Etype (E) = Any_Type
3682 or else Rep_Item_Too_Early (E, N)
3686 elsif Present (Underlying_Type (E)) then
3687 E := Underlying_Type (E);
3690 if Rep_Item_Too_Late (E, N) then
3694 if Has_Convention_Pragma (E) then
3695 Diagnose_Multiple_Pragmas (E);
3697 elsif Convention (E) = Convention_Protected
3698 or else Ekind (Scope (E)) = E_Protected_Type
3701 ("a protected operation cannot be given a different convention",
3705 -- For Intrinsic, a subprogram is required
3707 if C = Convention_Intrinsic
3708 and then not Is_Subprogram (E)
3709 and then not Is_Generic_Subprogram (E)
3712 ("second argument of pragma% must be a subprogram", Arg2);
3717 if C = Convention_Stdcall then
3719 -- A dispatching call is not allowed. A dispatching subprogram
3720 -- cannot be used to interface to the Win32 API, so in fact this
3721 -- check does not impose any effective restriction.
3723 if Is_Dispatching_Operation (E) then
3726 ("dispatching subprograms cannot use Stdcall convention");
3728 -- Subprogram is allowed, but not a generic subprogram, and not a
3729 -- dispatching operation.
3731 elsif not Is_Subprogram (E)
3732 and then not Is_Generic_Subprogram (E)
3736 and then Ekind (E) /= E_Variable
3738 -- An access to subprogram is also allowed
3742 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3745 ("second argument of pragma% must be subprogram (type)",
3750 if not Is_Subprogram (E)
3751 and then not Is_Generic_Subprogram (E)
3753 Set_Convention_From_Pragma (E);
3756 Check_First_Subtype (Arg2);
3757 Set_Convention_From_Pragma (Base_Type (E));
3759 -- For subprograms, we must set the convention on the
3760 -- internally generated directly designated type as well.
3762 if Ekind (E) = E_Access_Subprogram_Type then
3763 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3767 -- For the subprogram case, set proper convention for all homonyms
3768 -- in same scope and the same declarative part, i.e. the same
3769 -- compilation unit.
3772 Comp_Unit := Get_Source_Unit (E);
3773 Set_Convention_From_Pragma (E);
3775 -- Treat a pragma Import as an implicit body, and pragma import
3776 -- as implicit reference (for navigation in GPS).
3778 if Prag_Id = Pragma_Import then
3779 Generate_Reference (E, Id, 'b');
3781 -- For exported entities we restrict the generation of references
3782 -- to entities exported to foreign languages since entities
3783 -- exported to Ada do not provide further information to GPS and
3784 -- add undesired references to the output of the gnatxref tool.
3786 elsif Prag_Id = Pragma_Export
3787 and then Convention (E) /= Convention_Ada
3789 Generate_Reference (E, Id, 'i');
3792 -- If the pragma comes from from an aspect, it only applies
3793 -- to the given entity, not its homonyms.
3795 if From_Aspect_Specification (N) then
3799 -- Otherwise Loop through the homonyms of the pragma argument's
3800 -- entity, an apply convention to those in the current scope.
3806 exit when No (E1) or else Scope (E1) /= Current_Scope;
3808 -- Do not set the pragma on inherited operations or on formal
3811 if Comes_From_Source (E1)
3812 and then Comp_Unit = Get_Source_Unit (E1)
3813 and then not Is_Formal_Subprogram (E1)
3814 and then Nkind (Original_Node (Parent (E1))) /=
3815 N_Full_Type_Declaration
3817 if Present (Alias (E1))
3818 and then Scope (E1) /= Scope (Alias (E1))
3821 ("cannot apply pragma% to non-local entity& declared#",
3825 Set_Convention_From_Pragma (E1);
3827 if Prag_Id = Pragma_Import then
3828 Generate_Reference (E1, Id, 'b');
3833 end Process_Convention;
3835 ----------------------------------------
3836 -- Process_Disable_Enable_Atomic_Sync --
3837 ----------------------------------------
3839 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3842 Check_No_Identifiers;
3843 Check_At_Most_N_Arguments (1);
3845 -- Modeled internally as
3846 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
3850 Pragma_Identifier =>
3851 Make_Identifier (Loc, Nam),
3852 Pragma_Argument_Associations => New_List (
3853 Make_Pragma_Argument_Association (Loc,
3855 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3857 if Present (Arg1) then
3858 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3862 end Process_Disable_Enable_Atomic_Sync;
3864 -----------------------------------------------------
3865 -- Process_Extended_Import_Export_Exception_Pragma --
3866 -----------------------------------------------------
3868 procedure Process_Extended_Import_Export_Exception_Pragma
3869 (Arg_Internal : Node_Id;
3870 Arg_External : Node_Id;
3878 if not OpenVMS_On_Target then
3880 ("??pragma% ignored (applies only to Open'V'M'S)");
3883 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3884 Def_Id := Entity (Arg_Internal);
3886 if Ekind (Def_Id) /= E_Exception then
3888 ("pragma% must refer to declared exception", Arg_Internal);
3891 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3893 if Present (Arg_Form) then
3894 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3897 if Present (Arg_Form)
3898 and then Chars (Arg_Form) = Name_Ada
3902 Set_Is_VMS_Exception (Def_Id);
3903 Set_Exception_Code (Def_Id, No_Uint);
3906 if Present (Arg_Code) then
3907 if not Is_VMS_Exception (Def_Id) then
3909 ("Code option for pragma% not allowed for Ada case",
3913 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3914 Code_Val := Expr_Value (Arg_Code);
3916 if not UI_Is_In_Int_Range (Code_Val) then
3918 ("Code option for pragma% must be in 32-bit range",
3922 Set_Exception_Code (Def_Id, Code_Val);
3925 end Process_Extended_Import_Export_Exception_Pragma;
3927 -------------------------------------------------
3928 -- Process_Extended_Import_Export_Internal_Arg --
3929 -------------------------------------------------
3931 procedure Process_Extended_Import_Export_Internal_Arg
3932 (Arg_Internal : Node_Id := Empty)
3935 if No (Arg_Internal) then
3936 Error_Pragma ("Internal parameter required for pragma%");
3939 if Nkind (Arg_Internal) = N_Identifier then
3942 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3943 and then (Prag_Id = Pragma_Import_Function
3945 Prag_Id = Pragma_Export_Function)
3951 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3954 Check_Arg_Is_Local_Name (Arg_Internal);
3955 end Process_Extended_Import_Export_Internal_Arg;
3957 --------------------------------------------------
3958 -- Process_Extended_Import_Export_Object_Pragma --
3959 --------------------------------------------------
3961 procedure Process_Extended_Import_Export_Object_Pragma
3962 (Arg_Internal : Node_Id;
3963 Arg_External : Node_Id;
3969 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3970 Def_Id := Entity (Arg_Internal);
3972 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3974 ("pragma% must designate an object", Arg_Internal);
3977 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3979 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3982 ("previous Common/Psect_Object applies, pragma % not permitted",
3986 if Rep_Item_Too_Late (Def_Id, N) then
3990 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3992 if Present (Arg_Size) then
3993 Check_Arg_Is_External_Name (Arg_Size);
3996 -- Export_Object case
3998 if Prag_Id = Pragma_Export_Object then
3999 if not Is_Library_Level_Entity (Def_Id) then
4001 ("argument for pragma% must be library level entity",
4005 if Ekind (Current_Scope) = E_Generic_Package then
4006 Error_Pragma ("pragma& cannot appear in a generic unit");
4009 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
4011 ("exported object must have compile time known size",
4015 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
4016 Error_Msg_N ("??duplicate Export_Object pragma", N);
4018 Set_Exported (Def_Id, Arg_Internal);
4021 -- Import_Object case
4024 if Is_Concurrent_Type (Etype (Def_Id)) then
4026 ("cannot use pragma% for task/protected object",
4030 if Ekind (Def_Id) = E_Constant then
4032 ("cannot import a constant", Arg_Internal);
4035 if Warn_On_Export_Import
4036 and then Has_Discriminants (Etype (Def_Id))
4039 ("imported value must be initialized??", Arg_Internal);
4042 if Warn_On_Export_Import
4043 and then Is_Access_Type (Etype (Def_Id))
4046 ("cannot import object of an access type??", Arg_Internal);
4049 if Warn_On_Export_Import
4050 and then Is_Imported (Def_Id)
4052 Error_Msg_N ("??duplicate Import_Object pragma", N);
4054 -- Check for explicit initialization present. Note that an
4055 -- initialization generated by the code generator, e.g. for an
4056 -- access type, does not count here.
4058 elsif Present (Expression (Parent (Def_Id)))
4061 (Original_Node (Expression (Parent (Def_Id))))
4063 Error_Msg_Sloc := Sloc (Def_Id);
4065 ("imported entities cannot be initialized (RM B.1(24))",
4066 "\no initialization allowed for & declared#", Arg1);
4068 Set_Imported (Def_Id);
4069 Note_Possible_Modification (Arg_Internal, Sure => False);
4072 end Process_Extended_Import_Export_Object_Pragma;
4074 ------------------------------------------------------
4075 -- Process_Extended_Import_Export_Subprogram_Pragma --
4076 ------------------------------------------------------
4078 procedure Process_Extended_Import_Export_Subprogram_Pragma
4079 (Arg_Internal : Node_Id;
4080 Arg_External : Node_Id;
4081 Arg_Parameter_Types : Node_Id;
4082 Arg_Result_Type : Node_Id := Empty;
4083 Arg_Mechanism : Node_Id;
4084 Arg_Result_Mechanism : Node_Id := Empty;
4085 Arg_First_Optional_Parameter : Node_Id := Empty)
4091 Ambiguous : Boolean;
4095 function Same_Base_Type
4097 Formal : Entity_Id) return Boolean;
4098 -- Determines if Ptype references the type of Formal. Note that only
4099 -- the base types need to match according to the spec. Ptype here is
4100 -- the argument from the pragma, which is either a type name, or an
4101 -- access attribute.
4103 --------------------
4104 -- Same_Base_Type --
4105 --------------------
4107 function Same_Base_Type
4109 Formal : Entity_Id) return Boolean
4111 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
4115 -- Case where pragma argument is typ'Access
4117 if Nkind (Ptype) = N_Attribute_Reference
4118 and then Attribute_Name (Ptype) = Name_Access
4120 Pref := Prefix (Ptype);
4123 if not Is_Entity_Name (Pref)
4124 or else Entity (Pref) = Any_Type
4129 -- We have a match if the corresponding argument is of an
4130 -- anonymous access type, and its designated type matches the
4131 -- type of the prefix of the access attribute
4133 return Ekind (Ftyp) = E_Anonymous_Access_Type
4134 and then Base_Type (Entity (Pref)) =
4135 Base_Type (Etype (Designated_Type (Ftyp)));
4137 -- Case where pragma argument is a type name
4142 if not Is_Entity_Name (Ptype)
4143 or else Entity (Ptype) = Any_Type
4148 -- We have a match if the corresponding argument is of the type
4149 -- given in the pragma (comparing base types)
4151 return Base_Type (Entity (Ptype)) = Ftyp;
4155 -- Start of processing for
4156 -- Process_Extended_Import_Export_Subprogram_Pragma
4159 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
4163 -- Loop through homonyms (overloadings) of the entity
4165 Hom_Id := Entity (Arg_Internal);
4166 while Present (Hom_Id) loop
4167 Def_Id := Get_Base_Subprogram (Hom_Id);
4169 -- We need a subprogram in the current scope
4171 if not Is_Subprogram (Def_Id)
4172 or else Scope (Def_Id) /= Current_Scope
4179 -- Pragma cannot apply to subprogram body
4181 if Is_Subprogram (Def_Id)
4182 and then Nkind (Parent (Declaration_Node (Def_Id))) =
4186 ("pragma% requires separate spec"
4187 & " and must come before body");
4190 -- Test result type if given, note that the result type
4191 -- parameter can only be present for the function cases.
4193 if Present (Arg_Result_Type)
4194 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
4198 elsif Etype (Def_Id) /= Standard_Void_Type
4200 (Pname = Name_Export_Procedure
4202 Pname = Name_Import_Procedure)
4206 -- Test parameter types if given. Note that this parameter
4207 -- has not been analyzed (and must not be, since it is
4208 -- semantic nonsense), so we get it as the parser left it.
4210 elsif Present (Arg_Parameter_Types) then
4211 Check_Matching_Types : declare
4216 Formal := First_Formal (Def_Id);
4218 if Nkind (Arg_Parameter_Types) = N_Null then
4219 if Present (Formal) then
4223 -- A list of one type, e.g. (List) is parsed as
4224 -- a parenthesized expression.
4226 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4227 and then Paren_Count (Arg_Parameter_Types) = 1
4230 or else Present (Next_Formal (Formal))
4235 Same_Base_Type (Arg_Parameter_Types, Formal);
4238 -- A list of more than one type is parsed as a aggregate
4240 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4241 and then Paren_Count (Arg_Parameter_Types) = 0
4243 Ptype := First (Expressions (Arg_Parameter_Types));
4244 while Present (Ptype) or else Present (Formal) loop
4247 or else not Same_Base_Type (Ptype, Formal)
4252 Next_Formal (Formal);
4257 -- Anything else is of the wrong form
4261 ("wrong form for Parameter_Types parameter",
4262 Arg_Parameter_Types);
4264 end Check_Matching_Types;
4267 -- Match is now False if the entry we found did not match
4268 -- either a supplied Parameter_Types or Result_Types argument
4274 -- Ambiguous case, the flag Ambiguous shows if we already
4275 -- detected this and output the initial messages.
4278 if not Ambiguous then
4280 Error_Msg_Name_1 := Pname;
4282 ("pragma% does not uniquely identify subprogram!",
4284 Error_Msg_Sloc := Sloc (Ent);
4285 Error_Msg_N ("matching subprogram #!", N);
4289 Error_Msg_Sloc := Sloc (Def_Id);
4290 Error_Msg_N ("matching subprogram #!", N);
4295 Hom_Id := Homonym (Hom_Id);
4298 -- See if we found an entry
4301 if not Ambiguous then
4302 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4304 ("pragma% cannot be given for generic subprogram");
4307 ("pragma% does not identify local subprogram");
4314 -- Import pragmas must be for imported entities
4316 if Prag_Id = Pragma_Import_Function
4318 Prag_Id = Pragma_Import_Procedure
4320 Prag_Id = Pragma_Import_Valued_Procedure
4322 if not Is_Imported (Ent) then
4324 ("pragma Import or Interface must precede pragma%");
4327 -- Here we have the Export case which can set the entity as exported
4329 -- But does not do so if the specified external name is null, since
4330 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4331 -- compatible) to request no external name.
4333 elsif Nkind (Arg_External) = N_String_Literal
4334 and then String_Length (Strval (Arg_External)) = 0
4338 -- In all other cases, set entity as exported
4341 Set_Exported (Ent, Arg_Internal);
4344 -- Special processing for Valued_Procedure cases
4346 if Prag_Id = Pragma_Import_Valued_Procedure
4348 Prag_Id = Pragma_Export_Valued_Procedure
4350 Formal := First_Formal (Ent);
4353 Error_Pragma ("at least one parameter required for pragma%");
4355 elsif Ekind (Formal) /= E_Out_Parameter then
4356 Error_Pragma ("first parameter must have mode out for pragma%");
4359 Set_Is_Valued_Procedure (Ent);
4363 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4365 -- Process Result_Mechanism argument if present. We have already
4366 -- checked that this is only allowed for the function case.
4368 if Present (Arg_Result_Mechanism) then
4369 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4372 -- Process Mechanism parameter if present. Note that this parameter
4373 -- is not analyzed, and must not be analyzed since it is semantic
4374 -- nonsense, so we get it in exactly as the parser left it.
4376 if Present (Arg_Mechanism) then
4384 -- A single mechanism association without a formal parameter
4385 -- name is parsed as a parenthesized expression. All other
4386 -- cases are parsed as aggregates, so we rewrite the single
4387 -- parameter case as an aggregate for consistency.
4389 if Nkind (Arg_Mechanism) /= N_Aggregate
4390 and then Paren_Count (Arg_Mechanism) = 1
4392 Rewrite (Arg_Mechanism,
4393 Make_Aggregate (Sloc (Arg_Mechanism),
4394 Expressions => New_List (
4395 Relocate_Node (Arg_Mechanism))));
4398 -- Case of only mechanism name given, applies to all formals
4400 if Nkind (Arg_Mechanism) /= N_Aggregate then
4401 Formal := First_Formal (Ent);
4402 while Present (Formal) loop
4403 Set_Mechanism_Value (Formal, Arg_Mechanism);
4404 Next_Formal (Formal);
4407 -- Case of list of mechanism associations given
4410 if Null_Record_Present (Arg_Mechanism) then
4412 ("inappropriate form for Mechanism parameter",
4416 -- Deal with positional ones first
4418 Formal := First_Formal (Ent);
4420 if Present (Expressions (Arg_Mechanism)) then
4421 Mname := First (Expressions (Arg_Mechanism));
4422 while Present (Mname) loop
4425 ("too many mechanism associations", Mname);
4428 Set_Mechanism_Value (Formal, Mname);
4429 Next_Formal (Formal);
4434 -- Deal with named entries
4436 if Present (Component_Associations (Arg_Mechanism)) then
4437 Massoc := First (Component_Associations (Arg_Mechanism));
4438 while Present (Massoc) loop
4439 Choice := First (Choices (Massoc));
4441 if Nkind (Choice) /= N_Identifier
4442 or else Present (Next (Choice))
4445 ("incorrect form for mechanism association",
4449 Formal := First_Formal (Ent);
4453 ("parameter name & not present", Choice);
4456 if Chars (Choice) = Chars (Formal) then
4458 (Formal, Expression (Massoc));
4460 -- Set entity on identifier (needed by ASIS)
4462 Set_Entity (Choice, Formal);
4467 Next_Formal (Formal);
4477 -- Process First_Optional_Parameter argument if present. We have
4478 -- already checked that this is only allowed for the Import case.
4480 if Present (Arg_First_Optional_Parameter) then
4481 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4483 ("first optional parameter must be formal parameter name",
4484 Arg_First_Optional_Parameter);
4487 Formal := First_Formal (Ent);
4491 ("specified formal parameter& not found",
4492 Arg_First_Optional_Parameter);
4495 exit when Chars (Formal) =
4496 Chars (Arg_First_Optional_Parameter);
4498 Next_Formal (Formal);
4501 Set_First_Optional_Parameter (Ent, Formal);
4503 -- Check specified and all remaining formals have right form
4505 while Present (Formal) loop
4506 if Ekind (Formal) /= E_In_Parameter then
4508 ("optional formal& is not of mode in!",
4509 Arg_First_Optional_Parameter, Formal);
4512 Dval := Default_Value (Formal);
4516 ("optional formal& does not have default value!",
4517 Arg_First_Optional_Parameter, Formal);
4519 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4524 ("default value for optional formal& is non-static!",
4525 Arg_First_Optional_Parameter, Formal);
4529 Set_Is_Optional_Parameter (Formal);
4530 Next_Formal (Formal);
4533 end Process_Extended_Import_Export_Subprogram_Pragma;
4535 --------------------------
4536 -- Process_Generic_List --
4537 --------------------------
4539 procedure Process_Generic_List is
4544 Check_No_Identifiers;
4545 Check_At_Least_N_Arguments (1);
4548 while Present (Arg) loop
4549 Exp := Get_Pragma_Arg (Arg);
4552 if not Is_Entity_Name (Exp)
4554 (not Is_Generic_Instance (Entity (Exp))
4556 not Is_Generic_Unit (Entity (Exp)))
4559 ("pragma% argument must be name of generic unit/instance",
4565 end Process_Generic_List;
4567 ------------------------------------
4568 -- Process_Import_Predefined_Type --
4569 ------------------------------------
4571 procedure Process_Import_Predefined_Type is
4572 Loc : constant Source_Ptr := Sloc (N);
4574 Ftyp : Node_Id := Empty;
4580 String_To_Name_Buffer (Strval (Expression (Arg3)));
4583 Elmt := First_Elmt (Predefined_Float_Types);
4584 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4588 Ftyp := Node (Elmt);
4590 if Present (Ftyp) then
4592 -- Don't build a derived type declaration, because predefined C
4593 -- types have no declaration anywhere, so cannot really be named.
4594 -- Instead build a full type declaration, starting with an
4595 -- appropriate type definition is built
4597 if Is_Floating_Point_Type (Ftyp) then
4598 Def := Make_Floating_Point_Definition (Loc,
4599 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4600 Make_Real_Range_Specification (Loc,
4601 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4602 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4604 -- Should never have a predefined type we cannot handle
4607 raise Program_Error;
4610 -- Build and insert a Full_Type_Declaration, which will be
4611 -- analyzed as soon as this list entry has been analyzed.
4613 Decl := Make_Full_Type_Declaration (Loc,
4614 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4615 Type_Definition => Def);
4617 Insert_After (N, Decl);
4618 Mark_Rewrite_Insertion (Decl);
4621 Error_Pragma_Arg ("no matching type found for pragma%",
4624 end Process_Import_Predefined_Type;
4626 ---------------------------------
4627 -- Process_Import_Or_Interface --
4628 ---------------------------------
4630 procedure Process_Import_Or_Interface is
4636 Process_Convention (C, Def_Id);
4637 Kill_Size_Check_Code (Def_Id);
4638 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4640 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4642 -- We do not permit Import to apply to a renaming declaration
4644 if Present (Renamed_Object (Def_Id)) then
4646 ("pragma% not allowed for object renaming", Arg2);
4648 -- User initialization is not allowed for imported object, but
4649 -- the object declaration may contain a default initialization,
4650 -- that will be discarded. Note that an explicit initialization
4651 -- only counts if it comes from source, otherwise it is simply
4652 -- the code generator making an implicit initialization explicit.
4654 elsif Present (Expression (Parent (Def_Id)))
4655 and then Comes_From_Source (Expression (Parent (Def_Id)))
4657 Error_Msg_Sloc := Sloc (Def_Id);
4659 ("no initialization allowed for declaration of& #",
4660 "\imported entities cannot be initialized (RM B.1(24))",
4664 Set_Imported (Def_Id);
4665 Process_Interface_Name (Def_Id, Arg3, Arg4);
4667 -- Note that we do not set Is_Public here. That's because we
4668 -- only want to set it if there is no address clause, and we
4669 -- don't know that yet, so we delay that processing till
4672 -- pragma Import completes deferred constants
4674 if Ekind (Def_Id) = E_Constant then
4675 Set_Has_Completion (Def_Id);
4678 -- It is not possible to import a constant of an unconstrained
4679 -- array type (e.g. string) because there is no simple way to
4680 -- write a meaningful subtype for it.
4682 if Is_Array_Type (Etype (Def_Id))
4683 and then not Is_Constrained (Etype (Def_Id))
4686 ("imported constant& must have a constrained subtype",
4691 elsif Is_Subprogram (Def_Id)
4692 or else Is_Generic_Subprogram (Def_Id)
4694 -- If the name is overloaded, pragma applies to all of the denoted
4695 -- entities in the same declarative part, unless the pragma comes
4696 -- from an aspect specification.
4699 while Present (Hom_Id) loop
4701 Def_Id := Get_Base_Subprogram (Hom_Id);
4703 -- Ignore inherited subprograms because the pragma will apply
4704 -- to the parent operation, which is the one called.
4706 if Is_Overloadable (Def_Id)
4707 and then Present (Alias (Def_Id))
4711 -- If it is not a subprogram, it must be in an outer scope and
4712 -- pragma does not apply.
4714 elsif not Is_Subprogram (Def_Id)
4715 and then not Is_Generic_Subprogram (Def_Id)
4719 -- The pragma does not apply to primitives of interfaces
4721 elsif Is_Dispatching_Operation (Def_Id)
4722 and then Present (Find_Dispatching_Type (Def_Id))
4723 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4727 -- Verify that the homonym is in the same declarative part (not
4728 -- just the same scope). If the pragma comes from an aspect
4729 -- specification we know that it is part of the declaration.
4731 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4732 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4733 and then not From_Aspect_Specification (N)
4738 Set_Imported (Def_Id);
4740 -- Reject an Import applied to an abstract subprogram
4742 if Is_Subprogram (Def_Id)
4743 and then Is_Abstract_Subprogram (Def_Id)
4745 Error_Msg_Sloc := Sloc (Def_Id);
4747 ("cannot import abstract subprogram& declared#",
4751 -- Special processing for Convention_Intrinsic
4753 if C = Convention_Intrinsic then
4755 -- Link_Name argument not allowed for intrinsic
4759 Set_Is_Intrinsic_Subprogram (Def_Id);
4761 -- If no external name is present, then check that this
4762 -- is a valid intrinsic subprogram. If an external name
4763 -- is present, then this is handled by the back end.
4766 Check_Intrinsic_Subprogram
4767 (Def_Id, Get_Pragma_Arg (Arg2));
4771 -- All interfaced procedures need an external symbol created
4772 -- for them since they are always referenced from another
4775 Set_Is_Public (Def_Id);
4777 -- Verify that the subprogram does not have a completion
4778 -- through a renaming declaration. For other completions the
4779 -- pragma appears as a too late representation.
4782 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4786 and then Nkind (Decl) = N_Subprogram_Declaration
4787 and then Present (Corresponding_Body (Decl))
4788 and then Nkind (Unit_Declaration_Node
4789 (Corresponding_Body (Decl))) =
4790 N_Subprogram_Renaming_Declaration
4792 Error_Msg_Sloc := Sloc (Def_Id);
4794 ("cannot import&, renaming already provided for " &
4795 "declaration #", N, Def_Id);
4799 Set_Has_Completion (Def_Id);
4800 Process_Interface_Name (Def_Id, Arg3, Arg4);
4803 if Is_Compilation_Unit (Hom_Id) then
4805 -- Its possible homonyms are not affected by the pragma.
4806 -- Such homonyms might be present in the context of other
4807 -- units being compiled.
4811 elsif From_Aspect_Specification (N) then
4815 Hom_Id := Homonym (Hom_Id);
4819 -- When the convention is Java or CIL, we also allow Import to be
4820 -- given for packages, generic packages, exceptions, record
4821 -- components, and access to subprograms.
4823 elsif (C = Convention_Java or else C = Convention_CIL)
4825 (Is_Package_Or_Generic_Package (Def_Id)
4826 or else Ekind (Def_Id) = E_Exception
4827 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4828 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4830 Set_Imported (Def_Id);
4831 Set_Is_Public (Def_Id);
4832 Process_Interface_Name (Def_Id, Arg3, Arg4);
4834 -- Import a CPP class
4836 elsif C = Convention_CPP
4837 and then (Is_Record_Type (Def_Id)
4838 or else Ekind (Def_Id) = E_Incomplete_Type)
4840 if Ekind (Def_Id) = E_Incomplete_Type then
4841 if Present (Full_View (Def_Id)) then
4842 Def_Id := Full_View (Def_Id);
4846 ("cannot import 'C'P'P type before full declaration seen",
4847 Get_Pragma_Arg (Arg2));
4849 -- Although we have reported the error we decorate it as
4850 -- CPP_Class to avoid reporting spurious errors
4852 Set_Is_CPP_Class (Def_Id);
4857 -- Types treated as CPP classes must be declared limited (note:
4858 -- this used to be a warning but there is no real benefit to it
4859 -- since we did effectively intend to treat the type as limited
4862 if not Is_Limited_Type (Def_Id) then
4864 ("imported 'C'P'P type must be limited",
4865 Get_Pragma_Arg (Arg2));
4868 if Etype (Def_Id) /= Def_Id
4869 and then not Is_CPP_Class (Root_Type (Def_Id))
4871 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
4874 Set_Is_CPP_Class (Def_Id);
4876 -- Imported CPP types must not have discriminants (because C++
4877 -- classes do not have discriminants).
4879 if Has_Discriminants (Def_Id) then
4881 ("imported 'C'P'P type cannot have discriminants",
4882 First (Discriminant_Specifications
4883 (Declaration_Node (Def_Id))));
4886 -- Check that components of imported CPP types do not have default
4887 -- expressions. For private types this check is performed when the
4888 -- full view is analyzed (see Process_Full_View).
4890 if not Is_Private_Type (Def_Id) then
4891 Check_CPP_Type_Has_No_Defaults (Def_Id);
4894 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4896 Check_Arg_Count (3);
4897 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4899 Process_Import_Predefined_Type;
4903 ("second argument of pragma% must be object, subprogram "
4904 & "or incomplete type",
4908 -- If this pragma applies to a compilation unit, then the unit, which
4909 -- is a subprogram, does not require (or allow) a body. We also do
4910 -- not need to elaborate imported procedures.
4912 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4914 Cunit : constant Node_Id := Parent (Parent (N));
4916 Set_Body_Required (Cunit, False);
4919 end Process_Import_Or_Interface;
4921 --------------------
4922 -- Process_Inline --
4923 --------------------
4925 procedure Process_Inline (Status : Inline_Status) is
4932 Effective : Boolean := False;
4933 -- Set True if inline has some effect, i.e. if there is at least one
4934 -- subprogram set as inlined as a result of the use of the pragma.
4936 procedure Make_Inline (Subp : Entity_Id);
4937 -- Subp is the defining unit name of the subprogram declaration. Set
4938 -- the flag, as well as the flag in the corresponding body, if there
4941 procedure Set_Inline_Flags (Subp : Entity_Id);
4942 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4943 -- Has_Pragma_Inline_Always for the Inline_Always case.
4945 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4946 -- Returns True if it can be determined at this stage that inlining
4947 -- is not possible, for example if the body is available and contains
4948 -- exception handlers, we prevent inlining, since otherwise we can
4949 -- get undefined symbols at link time. This function also emits a
4950 -- warning if front-end inlining is enabled and the pragma appears
4953 -- ??? is business with link symbols still valid, or does it relate
4954 -- to front end ZCX which is being phased out ???
4956 ---------------------------
4957 -- Inlining_Not_Possible --
4958 ---------------------------
4960 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4961 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4965 if Nkind (Decl) = N_Subprogram_Body then
4966 Stats := Handled_Statement_Sequence (Decl);
4967 return Present (Exception_Handlers (Stats))
4968 or else Present (At_End_Proc (Stats));
4970 elsif Nkind (Decl) = N_Subprogram_Declaration
4971 and then Present (Corresponding_Body (Decl))
4973 if Front_End_Inlining
4974 and then Analyzed (Corresponding_Body (Decl))
4976 Error_Msg_N ("pragma appears too late, ignored??", N);
4979 -- If the subprogram is a renaming as body, the body is just a
4980 -- call to the renamed subprogram, and inlining is trivially
4984 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4985 N_Subprogram_Renaming_Declaration
4991 Handled_Statement_Sequence
4992 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4995 Present (Exception_Handlers (Stats))
4996 or else Present (At_End_Proc (Stats));
5000 -- If body is not available, assume the best, the check is
5001 -- performed again when compiling enclosing package bodies.
5005 end Inlining_Not_Possible;
5011 procedure Make_Inline (Subp : Entity_Id) is
5012 Kind : constant Entity_Kind := Ekind (Subp);
5013 Inner_Subp : Entity_Id := Subp;
5016 -- Ignore if bad type, avoid cascaded error
5018 if Etype (Subp) = Any_Type then
5022 -- Ignore if all inlining is suppressed
5024 elsif Suppress_All_Inlining then
5028 -- If inlining is not possible, for now do not treat as an error
5030 elsif Status /= Suppressed
5031 and then Inlining_Not_Possible (Subp)
5036 -- Here we have a candidate for inlining, but we must exclude
5037 -- derived operations. Otherwise we would end up trying to inline
5038 -- a phantom declaration, and the result would be to drag in a
5039 -- body which has no direct inlining associated with it. That
5040 -- would not only be inefficient but would also result in the
5041 -- backend doing cross-unit inlining in cases where it was
5042 -- definitely inappropriate to do so.
5044 -- However, a simple Comes_From_Source test is insufficient, since
5045 -- we do want to allow inlining of generic instances which also do
5046 -- not come from source. We also need to recognize specs generated
5047 -- by the front-end for bodies that carry the pragma. Finally,
5048 -- predefined operators do not come from source but are not
5049 -- inlineable either.
5051 elsif Is_Generic_Instance (Subp)
5052 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
5056 elsif not Comes_From_Source (Subp)
5057 and then Scope (Subp) /= Standard_Standard
5063 -- The referenced entity must either be the enclosing entity, or
5064 -- an entity declared within the current open scope.
5066 if Present (Scope (Subp))
5067 and then Scope (Subp) /= Current_Scope
5068 and then Subp /= Current_Scope
5071 ("argument of% must be entity in current scope", Assoc);
5075 -- Processing for procedure, operator or function. If subprogram
5076 -- is aliased (as for an instance) indicate that the renamed
5077 -- entity (if declared in the same unit) is inlined.
5079 if Is_Subprogram (Subp) then
5080 Inner_Subp := Ultimate_Alias (Inner_Subp);
5082 if In_Same_Source_Unit (Subp, Inner_Subp) then
5083 Set_Inline_Flags (Inner_Subp);
5085 Decl := Parent (Parent (Inner_Subp));
5087 if Nkind (Decl) = N_Subprogram_Declaration
5088 and then Present (Corresponding_Body (Decl))
5090 Set_Inline_Flags (Corresponding_Body (Decl));
5092 elsif Is_Generic_Instance (Subp) then
5094 -- Indicate that the body needs to be created for
5095 -- inlining subsequent calls. The instantiation node
5096 -- follows the declaration of the wrapper package
5099 if Scope (Subp) /= Standard_Standard
5101 Need_Subprogram_Instance_Body
5102 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
5108 -- Inline is a program unit pragma (RM 10.1.5) and cannot
5109 -- appear in a formal part to apply to a formal subprogram.
5110 -- Do not apply check within an instance or a formal package
5111 -- the test will have been applied to the original generic.
5113 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
5114 and then List_Containing (Decl) = List_Containing (N)
5115 and then not In_Instance
5118 ("Inline cannot apply to a formal subprogram", N);
5120 -- If Subp is a renaming, it is the renamed entity that
5121 -- will appear in any call, and be inlined. However, for
5122 -- ASIS uses it is convenient to indicate that the renaming
5123 -- itself is an inlined subprogram, so that some gnatcheck
5124 -- rules can be applied in the absence of expansion.
5126 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
5127 Set_Inline_Flags (Subp);
5133 -- For a generic subprogram set flag as well, for use at the point
5134 -- of instantiation, to determine whether the body should be
5137 elsif Is_Generic_Subprogram (Subp) then
5138 Set_Inline_Flags (Subp);
5141 -- Literals are by definition inlined
5143 elsif Kind = E_Enumeration_Literal then
5146 -- Anything else is an error
5150 ("expect subprogram name for pragma%", Assoc);
5154 ----------------------
5155 -- Set_Inline_Flags --
5156 ----------------------
5158 procedure Set_Inline_Flags (Subp : Entity_Id) is
5160 -- First set the Has_Pragma_XXX flags and issue the appropriate
5161 -- errors and warnings for suspicious combinations.
5163 if Prag_Id = Pragma_No_Inline then
5164 if Has_Pragma_Inline_Always (Subp) then
5166 ("Inline_Always and No_Inline are mutually exclusive", N);
5167 elsif Has_Pragma_Inline (Subp) then
5169 ("Inline and No_Inline both specified for& ??",
5170 N, Entity (Subp_Id));
5173 Set_Has_Pragma_No_Inline (Subp);
5175 if Prag_Id = Pragma_Inline_Always then
5176 if Has_Pragma_No_Inline (Subp) then
5178 ("Inline_Always and No_Inline are mutually exclusive",
5182 Set_Has_Pragma_Inline_Always (Subp);
5184 if Has_Pragma_No_Inline (Subp) then
5186 ("Inline and No_Inline both specified for& ??",
5187 N, Entity (Subp_Id));
5191 if not Has_Pragma_Inline (Subp) then
5192 Set_Has_Pragma_Inline (Subp);
5197 -- Then adjust the Is_Inlined flag. It can never be set if the
5198 -- subprogram is subject to pragma No_Inline.
5202 Set_Is_Inlined (Subp, False);
5206 if not Has_Pragma_No_Inline (Subp) then
5207 Set_Is_Inlined (Subp, True);
5210 end Set_Inline_Flags;
5212 -- Start of processing for Process_Inline
5215 Check_No_Identifiers;
5216 Check_At_Least_N_Arguments (1);
5218 if Status = Enabled then
5219 Inline_Processing_Required := True;
5223 while Present (Assoc) loop
5224 Subp_Id := Get_Pragma_Arg (Assoc);
5228 if Is_Entity_Name (Subp_Id) then
5229 Subp := Entity (Subp_Id);
5231 if Subp = Any_Id then
5233 -- If previous error, avoid cascaded errors
5235 Check_Error_Detected;
5242 -- For the pragma case, climb homonym chain. This is
5243 -- what implements allowing the pragma in the renaming
5244 -- case, with the result applying to the ancestors, and
5245 -- also allows Inline to apply to all previous homonyms.
5247 if not From_Aspect_Specification (N) then
5248 while Present (Homonym (Subp))
5249 and then Scope (Homonym (Subp)) = Current_Scope
5251 Make_Inline (Homonym (Subp));
5252 Subp := Homonym (Subp);
5260 ("inappropriate argument for pragma%", Assoc);
5263 and then Warn_On_Redundant_Constructs
5264 and then not (Status = Suppressed or else Suppress_All_Inlining)
5266 if Inlining_Not_Possible (Subp) then
5268 ("pragma Inline for& is ignored?r?",
5269 N, Entity (Subp_Id));
5272 ("pragma Inline for& is redundant?r?",
5273 N, Entity (Subp_Id));
5281 ----------------------------
5282 -- Process_Interface_Name --
5283 ----------------------------
5285 procedure Process_Interface_Name
5286 (Subprogram_Def : Entity_Id;
5292 String_Val : String_Id;
5294 procedure Check_Form_Of_Interface_Name
5296 Ext_Name_Case : Boolean);
5297 -- SN is a string literal node for an interface name. This routine
5298 -- performs some minimal checks that the name is reasonable. In
5299 -- particular that no spaces or other obviously incorrect characters
5300 -- appear. This is only a warning, since any characters are allowed.
5301 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5303 ----------------------------------
5304 -- Check_Form_Of_Interface_Name --
5305 ----------------------------------
5307 procedure Check_Form_Of_Interface_Name
5309 Ext_Name_Case : Boolean)
5311 S : constant String_Id := Strval (Expr_Value_S (SN));
5312 SL : constant Nat := String_Length (S);
5317 Error_Msg_N ("interface name cannot be null string", SN);
5320 for J in 1 .. SL loop
5321 C := Get_String_Char (S, J);
5323 -- Look for dubious character and issue unconditional warning.
5324 -- Definitely dubious if not in character range.
5326 if not In_Character_Range (C)
5328 -- For all cases except CLI target,
5329 -- commas, spaces and slashes are dubious (in CLI, we use
5330 -- commas and backslashes in external names to specify
5331 -- assembly version and public key, while slashes and spaces
5332 -- can be used in names to mark nested classes and
5335 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5336 and then (Get_Character (C) = ','
5338 Get_Character (C) = '\'))
5339 or else (VM_Target /= CLI_Target
5340 and then (Get_Character (C) = ' '
5342 Get_Character (C) = '/'))
5345 ("??interface name contains illegal character",
5346 Sloc (SN) + Source_Ptr (J));
5349 end Check_Form_Of_Interface_Name;
5351 -- Start of processing for Process_Interface_Name
5354 if No (Link_Arg) then
5355 if No (Ext_Arg) then
5356 if VM_Target = CLI_Target
5357 and then Ekind (Subprogram_Def) = E_Package
5358 and then Nkind (Parent (Subprogram_Def)) =
5359 N_Package_Specification
5360 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5365 (Generic_Parent (Parent (Subprogram_Def))));
5370 elsif Chars (Ext_Arg) = Name_Link_Name then
5372 Link_Nam := Expression (Ext_Arg);
5375 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5376 Ext_Nam := Expression (Ext_Arg);
5381 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5382 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5383 Ext_Nam := Expression (Ext_Arg);
5384 Link_Nam := Expression (Link_Arg);
5387 -- Check expressions for external name and link name are static
5389 if Present (Ext_Nam) then
5390 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5391 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5393 -- Verify that external name is not the name of a local entity,
5394 -- which would hide the imported one and could lead to run-time
5395 -- surprises. The problem can only arise for entities declared in
5396 -- a package body (otherwise the external name is fully qualified
5397 -- and will not conflict).
5405 if Prag_Id = Pragma_Import then
5406 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5408 E := Entity_Id (Get_Name_Table_Info (Nam));
5410 if Nam /= Chars (Subprogram_Def)
5411 and then Present (E)
5412 and then not Is_Overloadable (E)
5413 and then Is_Immediately_Visible (E)
5414 and then not Is_Imported (E)
5415 and then Ekind (Scope (E)) = E_Package
5418 while Present (Par) loop
5419 if Nkind (Par) = N_Package_Body then
5420 Error_Msg_Sloc := Sloc (E);
5422 ("imported entity is hidden by & declared#",
5427 Par := Parent (Par);
5434 if Present (Link_Nam) then
5435 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5436 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5439 -- If there is no link name, just set the external name
5441 if No (Link_Nam) then
5442 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5444 -- For the Link_Name case, the given literal is preceded by an
5445 -- asterisk, which indicates to GCC that the given name should be
5446 -- taken literally, and in particular that no prepending of
5447 -- underlines should occur, even in systems where this is the
5453 if VM_Target = No_VM then
5454 Store_String_Char (Get_Char_Code ('*'));
5457 String_Val := Strval (Expr_Value_S (Link_Nam));
5458 Store_String_Chars (String_Val);
5460 Make_String_Literal (Sloc (Link_Nam),
5461 Strval => End_String);
5464 -- Set the interface name. If the entity is a generic instance, use
5465 -- its alias, which is the callable entity.
5467 if Is_Generic_Instance (Subprogram_Def) then
5468 Set_Encoded_Interface_Name
5469 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5471 Set_Encoded_Interface_Name
5472 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5475 -- We allow duplicated export names in CIL/Java, as they are always
5476 -- enclosed in a namespace that differentiates them, and overloaded
5477 -- entities are supported by the VM.
5479 if Convention (Subprogram_Def) /= Convention_CIL
5481 Convention (Subprogram_Def) /= Convention_Java
5483 Check_Duplicated_Export_Name (Link_Nam);
5485 end Process_Interface_Name;
5487 -----------------------------------------
5488 -- Process_Interrupt_Or_Attach_Handler --
5489 -----------------------------------------
5491 procedure Process_Interrupt_Or_Attach_Handler is
5492 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5493 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5494 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5497 Set_Is_Interrupt_Handler (Handler_Proc);
5499 -- If the pragma is not associated with a handler procedure within a
5500 -- protected type, then it must be for a nonprotected procedure for
5501 -- the AAMP target, in which case we don't associate a representation
5502 -- item with the procedure's scope.
5504 if Ekind (Proc_Scope) = E_Protected_Type then
5505 if Prag_Id = Pragma_Interrupt_Handler
5507 Prag_Id = Pragma_Attach_Handler
5509 Record_Rep_Item (Proc_Scope, N);
5512 end Process_Interrupt_Or_Attach_Handler;
5514 --------------------------------------------------
5515 -- Process_Restrictions_Or_Restriction_Warnings --
5516 --------------------------------------------------
5518 -- Note: some of the simple identifier cases were handled in par-prag,
5519 -- but it is harmless (and more straightforward) to simply handle all
5520 -- cases here, even if it means we repeat a bit of work in some cases.
5522 procedure Process_Restrictions_Or_Restriction_Warnings
5526 R_Id : Restriction_Id;
5531 procedure Check_Unit_Name (N : Node_Id);
5532 -- Checks unit name parameter for No_Dependence. Returns if it has
5533 -- an appropriate form, otherwise raises pragma argument error.
5535 ---------------------
5536 -- Check_Unit_Name --
5537 ---------------------
5539 procedure Check_Unit_Name (N : Node_Id) is
5541 if Nkind (N) = N_Selected_Component then
5542 Check_Unit_Name (Prefix (N));
5543 Check_Unit_Name (Selector_Name (N));
5545 elsif Nkind (N) = N_Identifier then
5550 ("wrong form for unit name for No_Dependence", N);
5552 end Check_Unit_Name;
5554 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5557 -- Ignore all Restrictions pragma in CodePeer mode
5559 if CodePeer_Mode then
5563 Check_Ada_83_Warning;
5564 Check_At_Least_N_Arguments (1);
5565 Check_Valid_Configuration_Pragma;
5568 while Present (Arg) loop
5570 Expr := Get_Pragma_Arg (Arg);
5572 -- Case of no restriction identifier present
5574 if Id = No_Name then
5575 if Nkind (Expr) /= N_Identifier then
5577 ("invalid form for restriction", Arg);
5582 (Process_Restriction_Synonyms (Expr));
5584 if R_Id not in All_Boolean_Restrictions then
5585 Error_Msg_Name_1 := Pname;
5587 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5589 -- Check for possible misspelling
5591 for J in Restriction_Id loop
5593 Rnm : constant String := Restriction_Id'Image (J);
5596 Name_Buffer (1 .. Rnm'Length) := Rnm;
5597 Name_Len := Rnm'Length;
5598 Set_Casing (All_Lower_Case);
5600 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5602 (Identifier_Casing (Current_Source_File));
5603 Error_Msg_String (1 .. Rnm'Length) :=
5604 Name_Buffer (1 .. Name_Len);
5605 Error_Msg_Strlen := Rnm'Length;
5606 Error_Msg_N -- CODEFIX
5607 ("\possible misspelling of ""~""",
5608 Get_Pragma_Arg (Arg));
5617 if Implementation_Restriction (R_Id) then
5618 Check_Restriction (No_Implementation_Restrictions, Arg);
5621 -- Special processing for No_Elaboration_Code restriction
5623 if R_Id = No_Elaboration_Code then
5625 -- Restriction is only recognized within a configuration
5626 -- pragma file, or within a unit of the main extended
5627 -- program. Note: the test for Main_Unit is needed to
5628 -- properly include the case of configuration pragma files.
5630 if not (Current_Sem_Unit = Main_Unit
5631 or else In_Extended_Main_Source_Unit (N))
5635 -- Don't allow in a subunit unless already specified in
5638 elsif Nkind (Parent (N)) = N_Compilation_Unit
5639 and then Nkind (Unit (Parent (N))) = N_Subunit
5640 and then not Restriction_Active (No_Elaboration_Code)
5643 ("invalid specification of ""No_Elaboration_Code""",
5646 ("\restriction cannot be specified in a subunit", N);
5648 ("\unless also specified in body or spec", N);
5651 -- If we have a No_Elaboration_Code pragma that we
5652 -- accept, then it needs to be added to the configuration
5653 -- restrcition set so that we get proper application to
5654 -- other units in the main extended source as required.
5657 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
5661 -- If this is a warning, then set the warning unless we already
5662 -- have a real restriction active (we never want a warning to
5663 -- override a real restriction).
5666 if not Restriction_Active (R_Id) then
5667 Set_Restriction (R_Id, N);
5668 Restriction_Warnings (R_Id) := True;
5671 -- If real restriction case, then set it and make sure that the
5672 -- restriction warning flag is off, since a real restriction
5673 -- always overrides a warning.
5676 Set_Restriction (R_Id, N);
5677 Restriction_Warnings (R_Id) := False;
5680 -- Check for obsolescent restrictions in Ada 2005 mode
5683 and then Ada_Version >= Ada_2005
5684 and then (R_Id = No_Asynchronous_Control
5686 R_Id = No_Unchecked_Deallocation
5688 R_Id = No_Unchecked_Conversion)
5690 Check_Restriction (No_Obsolescent_Features, N);
5693 -- A very special case that must be processed here: pragma
5694 -- Restrictions (No_Exceptions) turns off all run-time
5695 -- checking. This is a bit dubious in terms of the formal
5696 -- language definition, but it is what is intended by RM
5697 -- H.4(12). Restriction_Warnings never affects generated code
5698 -- so this is done only in the real restriction case.
5700 -- Atomic_Synchronization is not a real check, so it is not
5701 -- affected by this processing).
5703 if R_Id = No_Exceptions and then not Warn then
5704 for J in Scope_Suppress.Suppress'Range loop
5705 if J /= Atomic_Synchronization then
5706 Scope_Suppress.Suppress (J) := True;
5711 -- Case of No_Dependence => unit-name. Note that the parser
5712 -- already made the necessary entry in the No_Dependence table.
5714 elsif Id = Name_No_Dependence then
5715 Check_Unit_Name (Expr);
5717 -- Case of No_Specification_Of_Aspect => Identifier.
5719 elsif Id = Name_No_Specification_Of_Aspect then
5724 if Nkind (Expr) /= N_Identifier then
5727 A_Id := Get_Aspect_Id (Chars (Expr));
5730 if A_Id = No_Aspect then
5731 Error_Pragma_Arg ("invalid restriction name", Arg);
5733 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5737 -- All other cases of restriction identifier present
5740 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5741 Analyze_And_Resolve (Expr, Any_Integer);
5743 if R_Id not in All_Parameter_Restrictions then
5745 ("invalid restriction parameter identifier", Arg);
5747 elsif not Is_OK_Static_Expression (Expr) then
5748 Flag_Non_Static_Expr
5749 ("value must be static expression!", Expr);
5752 elsif not Is_Integer_Type (Etype (Expr))
5753 or else Expr_Value (Expr) < 0
5756 ("value must be non-negative integer", Arg);
5759 -- Restriction pragma is active
5761 Val := Expr_Value (Expr);
5763 if not UI_Is_In_Int_Range (Val) then
5765 ("pragma ignored, value too large??", Arg);
5768 -- Warning case. If the real restriction is active, then we
5769 -- ignore the request, since warning never overrides a real
5770 -- restriction. Otherwise we set the proper warning. Note that
5771 -- this circuit sets the warning again if it is already set,
5772 -- which is what we want, since the constant may have changed.
5775 if not Restriction_Active (R_Id) then
5777 (R_Id, N, Integer (UI_To_Int (Val)));
5778 Restriction_Warnings (R_Id) := True;
5781 -- Real restriction case, set restriction and make sure warning
5782 -- flag is off since real restriction always overrides warning.
5785 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5786 Restriction_Warnings (R_Id) := False;
5792 end Process_Restrictions_Or_Restriction_Warnings;
5794 ---------------------------------
5795 -- Process_Suppress_Unsuppress --
5796 ---------------------------------
5798 -- Note: this procedure makes entries in the check suppress data
5799 -- structures managed by Sem. See spec of package Sem for full
5800 -- details on how we handle recording of check suppression.
5802 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5807 In_Package_Spec : constant Boolean :=
5808 Is_Package_Or_Generic_Package (Current_Scope)
5809 and then not In_Package_Body (Current_Scope);
5811 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5812 -- Used to suppress a single check on the given entity
5814 --------------------------------
5815 -- Suppress_Unsuppress_Echeck --
5816 --------------------------------
5818 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5820 -- Check for error of trying to set atomic synchronization for
5821 -- a non-atomic variable.
5823 if C = Atomic_Synchronization
5824 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5827 ("pragma & requires atomic type or variable",
5828 Pragma_Identifier (Original_Node (N)));
5831 Set_Checks_May_Be_Suppressed (E);
5833 if In_Package_Spec then
5834 Push_Global_Suppress_Stack_Entry
5837 Suppress => Suppress_Case);
5839 Push_Local_Suppress_Stack_Entry
5842 Suppress => Suppress_Case);
5845 -- If this is a first subtype, and the base type is distinct,
5846 -- then also set the suppress flags on the base type.
5848 if Is_First_Subtype (E) and then Etype (E) /= E then
5849 Suppress_Unsuppress_Echeck (Etype (E), C);
5851 end Suppress_Unsuppress_Echeck;
5853 -- Start of processing for Process_Suppress_Unsuppress
5856 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5857 -- user code: we want to generate checks for analysis purposes, as
5858 -- set respectively by -gnatC and -gnatd.F
5860 if (CodePeer_Mode or Alfa_Mode) and then Comes_From_Source (N) then
5864 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5865 -- declarative part or a package spec (RM 11.5(5)).
5867 if not Is_Configuration_Pragma then
5868 Check_Is_In_Decl_Part_Or_Package_Spec;
5871 Check_At_Least_N_Arguments (1);
5872 Check_At_Most_N_Arguments (2);
5873 Check_No_Identifier (Arg1);
5874 Check_Arg_Is_Identifier (Arg1);
5876 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5878 if C = No_Check_Id then
5880 ("argument of pragma% is not valid check name", Arg1);
5883 if Arg_Count = 1 then
5885 -- Make an entry in the local scope suppress table. This is the
5886 -- table that directly shows the current value of the scope
5887 -- suppress check for any check id value.
5889 if C = All_Checks then
5891 -- For All_Checks, we set all specific predefined checks with
5892 -- the exception of Elaboration_Check, which is handled
5893 -- specially because of not wanting All_Checks to have the
5894 -- effect of deactivating static elaboration order processing.
5895 -- Atomic_Synchronization is also not affected, since this is
5896 -- not a real check.
5898 for J in Scope_Suppress.Suppress'Range loop
5899 if J /= Elaboration_Check
5901 J /= Atomic_Synchronization
5903 Scope_Suppress.Suppress (J) := Suppress_Case;
5907 -- If not All_Checks, and predefined check, then set appropriate
5908 -- scope entry. Note that we will set Elaboration_Check if this
5909 -- is explicitly specified. Atomic_Synchronization is allowed
5910 -- only if internally generated and entity is atomic.
5912 elsif C in Predefined_Check_Id
5913 and then (not Comes_From_Source (N)
5914 or else C /= Atomic_Synchronization)
5916 Scope_Suppress.Suppress (C) := Suppress_Case;
5919 -- Also make an entry in the Local_Entity_Suppress table
5921 Push_Local_Suppress_Stack_Entry
5924 Suppress => Suppress_Case);
5926 -- Case of two arguments present, where the check is suppressed for
5927 -- a specified entity (given as the second argument of the pragma)
5930 -- This is obsolescent in Ada 2005 mode
5932 if Ada_Version >= Ada_2005 then
5933 Check_Restriction (No_Obsolescent_Features, Arg2);
5936 Check_Optional_Identifier (Arg2, Name_On);
5937 E_Id := Get_Pragma_Arg (Arg2);
5940 if not Is_Entity_Name (E_Id) then
5942 ("second argument of pragma% must be entity name", Arg2);
5951 -- Enforce RM 11.5(7) which requires that for a pragma that
5952 -- appears within a package spec, the named entity must be
5953 -- within the package spec. We allow the package name itself
5954 -- to be mentioned since that makes sense, although it is not
5955 -- strictly allowed by 11.5(7).
5958 and then E /= Current_Scope
5959 and then Scope (E) /= Current_Scope
5962 ("entity in pragma% is not in package spec (RM 11.5(7))",
5966 -- Loop through homonyms. As noted below, in the case of a package
5967 -- spec, only homonyms within the package spec are considered.
5970 Suppress_Unsuppress_Echeck (E, C);
5972 if Is_Generic_Instance (E)
5973 and then Is_Subprogram (E)
5974 and then Present (Alias (E))
5976 Suppress_Unsuppress_Echeck (Alias (E), C);
5979 -- Move to next homonym if not aspect spec case
5981 exit when From_Aspect_Specification (N);
5985 -- If we are within a package specification, the pragma only
5986 -- applies to homonyms in the same scope.
5988 exit when In_Package_Spec
5989 and then Scope (E) /= Current_Scope;
5992 end Process_Suppress_Unsuppress;
5998 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
6000 if Is_Imported (E) then
6002 ("cannot export entity& that was previously imported", Arg);
6004 elsif Present (Address_Clause (E))
6005 and then not Relaxed_RM_Semantics
6008 ("cannot export entity& that has an address clause", Arg);
6011 Set_Is_Exported (E);
6013 -- Generate a reference for entity explicitly, because the
6014 -- identifier may be overloaded and name resolution will not
6017 Generate_Reference (E, Arg);
6019 -- Deal with exporting non-library level entity
6021 if not Is_Library_Level_Entity (E) then
6023 -- Not allowed at all for subprograms
6025 if Is_Subprogram (E) then
6026 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
6028 -- Otherwise set public and statically allocated
6032 Set_Is_Statically_Allocated (E);
6034 -- Warn if the corresponding W flag is set and the pragma comes
6035 -- from source. The latter may not be true e.g. on VMS where we
6036 -- expand export pragmas for exception codes associated with
6037 -- imported or exported exceptions. We do not want to generate
6038 -- a warning for something that the user did not write.
6040 if Warn_On_Export_Import
6041 and then Comes_From_Source (Arg)
6044 ("?x?& has been made static as a result of Export",
6047 ("\?x?this usage is non-standard and non-portable",
6053 if Warn_On_Export_Import and then Is_Type (E) then
6054 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
6057 if Warn_On_Export_Import and Inside_A_Generic then
6059 ("all instances of& will have the same external name?x?",
6064 ----------------------------------------------
6065 -- Set_Extended_Import_Export_External_Name --
6066 ----------------------------------------------
6068 procedure Set_Extended_Import_Export_External_Name
6069 (Internal_Ent : Entity_Id;
6070 Arg_External : Node_Id)
6072 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
6076 if No (Arg_External) then
6080 Check_Arg_Is_External_Name (Arg_External);
6082 if Nkind (Arg_External) = N_String_Literal then
6083 if String_Length (Strval (Arg_External)) = 0 then
6086 New_Name := Adjust_External_Name_Case (Arg_External);
6089 elsif Nkind (Arg_External) = N_Identifier then
6090 New_Name := Get_Default_External_Name (Arg_External);
6092 -- Check_Arg_Is_External_Name should let through only identifiers and
6093 -- string literals or static string expressions (which are folded to
6094 -- string literals).
6097 raise Program_Error;
6100 -- If we already have an external name set (by a prior normal Import
6101 -- or Export pragma), then the external names must match
6103 if Present (Interface_Name (Internal_Ent)) then
6104 Check_Matching_Internal_Names : declare
6105 S1 : constant String_Id := Strval (Old_Name);
6106 S2 : constant String_Id := Strval (New_Name);
6109 pragma No_Return (Mismatch);
6110 -- Called if names do not match
6116 procedure Mismatch is
6118 Error_Msg_Sloc := Sloc (Old_Name);
6120 ("external name does not match that given #",
6124 -- Start of processing for Check_Matching_Internal_Names
6127 if String_Length (S1) /= String_Length (S2) then
6131 for J in 1 .. String_Length (S1) loop
6132 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
6137 end Check_Matching_Internal_Names;
6139 -- Otherwise set the given name
6142 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
6143 Check_Duplicated_Export_Name (New_Name);
6145 end Set_Extended_Import_Export_External_Name;
6151 procedure Set_Imported (E : Entity_Id) is
6153 -- Error message if already imported or exported
6155 if Is_Exported (E) or else Is_Imported (E) then
6157 -- Error if being set Exported twice
6159 if Is_Exported (E) then
6160 Error_Msg_NE ("entity& was previously exported", N, E);
6162 -- OK if Import/Interface case
6164 elsif Import_Interface_Present (N) then
6167 -- Error if being set Imported twice
6170 Error_Msg_NE ("entity& was previously imported", N, E);
6173 Error_Msg_Name_1 := Pname;
6175 ("\(pragma% applies to all previous entities)", N);
6177 Error_Msg_Sloc := Sloc (E);
6178 Error_Msg_NE ("\import not allowed for& declared#", N, E);
6180 -- Here if not previously imported or exported, OK to import
6183 Set_Is_Imported (E);
6185 -- If the entity is an object that is not at the library level,
6186 -- then it is statically allocated. We do not worry about objects
6187 -- with address clauses in this context since they are not really
6188 -- imported in the linker sense.
6191 and then not Is_Library_Level_Entity (E)
6192 and then No (Address_Clause (E))
6194 Set_Is_Statically_Allocated (E);
6201 -------------------------
6202 -- Set_Mechanism_Value --
6203 -------------------------
6205 -- Note: the mechanism name has not been analyzed (and cannot indeed be
6206 -- analyzed, since it is semantic nonsense), so we get it in the exact
6207 -- form created by the parser.
6209 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
6212 Mech_Name_Id : Name_Id;
6214 procedure Bad_Class;
6215 pragma No_Return (Bad_Class);
6216 -- Signal bad descriptor class name
6218 procedure Bad_Mechanism;
6219 pragma No_Return (Bad_Mechanism);
6220 -- Signal bad mechanism name
6226 procedure Bad_Class is
6228 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
6231 -------------------------
6232 -- Bad_Mechanism_Value --
6233 -------------------------
6235 procedure Bad_Mechanism is
6237 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
6240 -- Start of processing for Set_Mechanism_Value
6243 if Mechanism (Ent) /= Default_Mechanism then
6245 ("mechanism for & has already been set", Mech_Name, Ent);
6248 -- MECHANISM_NAME ::= value | reference | descriptor |
6251 if Nkind (Mech_Name) = N_Identifier then
6252 if Chars (Mech_Name) = Name_Value then
6253 Set_Mechanism (Ent, By_Copy);
6256 elsif Chars (Mech_Name) = Name_Reference then
6257 Set_Mechanism (Ent, By_Reference);
6260 elsif Chars (Mech_Name) = Name_Descriptor then
6261 Check_VMS (Mech_Name);
6263 -- Descriptor => Short_Descriptor if pragma was given
6265 if Short_Descriptors then
6266 Set_Mechanism (Ent, By_Short_Descriptor);
6268 Set_Mechanism (Ent, By_Descriptor);
6273 elsif Chars (Mech_Name) = Name_Short_Descriptor then
6274 Check_VMS (Mech_Name);
6275 Set_Mechanism (Ent, By_Short_Descriptor);
6278 elsif Chars (Mech_Name) = Name_Copy then
6280 ("bad mechanism name, Value assumed", Mech_Name);
6286 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
6287 -- short_descriptor (CLASS_NAME)
6288 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6290 -- Note: this form is parsed as an indexed component
6292 elsif Nkind (Mech_Name) = N_Indexed_Component then
6293 Class := First (Expressions (Mech_Name));
6295 if Nkind (Prefix (Mech_Name)) /= N_Identifier
6296 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
6297 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
6298 or else Present (Next (Class))
6302 Mech_Name_Id := Chars (Prefix (Mech_Name));
6304 -- Change Descriptor => Short_Descriptor if pragma was given
6306 if Mech_Name_Id = Name_Descriptor
6307 and then Short_Descriptors
6309 Mech_Name_Id := Name_Short_Descriptor;
6313 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6314 -- short_descriptor (Class => CLASS_NAME)
6315 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6317 -- Note: this form is parsed as a function call
6319 elsif Nkind (Mech_Name) = N_Function_Call then
6320 Param := First (Parameter_Associations (Mech_Name));
6322 if Nkind (Name (Mech_Name)) /= N_Identifier
6323 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6324 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6325 or else Present (Next (Param))
6326 or else No (Selector_Name (Param))
6327 or else Chars (Selector_Name (Param)) /= Name_Class
6331 Class := Explicit_Actual_Parameter (Param);
6332 Mech_Name_Id := Chars (Name (Mech_Name));
6339 -- Fall through here with Class set to descriptor class name
6341 Check_VMS (Mech_Name);
6343 if Nkind (Class) /= N_Identifier then
6346 elsif Mech_Name_Id = Name_Descriptor
6347 and then Chars (Class) = Name_UBS
6349 Set_Mechanism (Ent, By_Descriptor_UBS);
6351 elsif Mech_Name_Id = Name_Descriptor
6352 and then Chars (Class) = Name_UBSB
6354 Set_Mechanism (Ent, By_Descriptor_UBSB);
6356 elsif Mech_Name_Id = Name_Descriptor
6357 and then Chars (Class) = Name_UBA
6359 Set_Mechanism (Ent, By_Descriptor_UBA);
6361 elsif Mech_Name_Id = Name_Descriptor
6362 and then Chars (Class) = Name_S
6364 Set_Mechanism (Ent, By_Descriptor_S);
6366 elsif Mech_Name_Id = Name_Descriptor
6367 and then Chars (Class) = Name_SB
6369 Set_Mechanism (Ent, By_Descriptor_SB);
6371 elsif Mech_Name_Id = Name_Descriptor
6372 and then Chars (Class) = Name_A
6374 Set_Mechanism (Ent, By_Descriptor_A);
6376 elsif Mech_Name_Id = Name_Descriptor
6377 and then Chars (Class) = Name_NCA
6379 Set_Mechanism (Ent, By_Descriptor_NCA);
6381 elsif Mech_Name_Id = Name_Short_Descriptor
6382 and then Chars (Class) = Name_UBS
6384 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6386 elsif Mech_Name_Id = Name_Short_Descriptor
6387 and then Chars (Class) = Name_UBSB
6389 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6391 elsif Mech_Name_Id = Name_Short_Descriptor
6392 and then Chars (Class) = Name_UBA
6394 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6396 elsif Mech_Name_Id = Name_Short_Descriptor
6397 and then Chars (Class) = Name_S
6399 Set_Mechanism (Ent, By_Short_Descriptor_S);
6401 elsif Mech_Name_Id = Name_Short_Descriptor
6402 and then Chars (Class) = Name_SB
6404 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6406 elsif Mech_Name_Id = Name_Short_Descriptor
6407 and then Chars (Class) = Name_A
6409 Set_Mechanism (Ent, By_Short_Descriptor_A);
6411 elsif Mech_Name_Id = Name_Short_Descriptor
6412 and then Chars (Class) = Name_NCA
6414 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6419 end Set_Mechanism_Value;
6421 --------------------------
6422 -- Set_Rational_Profile --
6423 --------------------------
6425 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
6426 -- and extension to the semantics of renaming declarations.
6428 procedure Set_Rational_Profile is
6430 Implicit_Packing := True;
6431 Overriding_Renamings := True;
6432 Use_VADS_Size := True;
6433 end Set_Rational_Profile;
6435 ---------------------------
6436 -- Set_Ravenscar_Profile --
6437 ---------------------------
6439 -- The tasks to be done here are
6441 -- Set required policies
6443 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6444 -- pragma Locking_Policy (Ceiling_Locking)
6446 -- Set Detect_Blocking mode
6448 -- Set required restrictions (see System.Rident for detailed list)
6450 -- Set the No_Dependence rules
6451 -- No_Dependence => Ada.Asynchronous_Task_Control
6452 -- No_Dependence => Ada.Calendar
6453 -- No_Dependence => Ada.Execution_Time.Group_Budget
6454 -- No_Dependence => Ada.Execution_Time.Timers
6455 -- No_Dependence => Ada.Task_Attributes
6456 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6458 procedure Set_Ravenscar_Profile (N : Node_Id) is
6459 Prefix_Entity : Entity_Id;
6460 Selector_Entity : Entity_Id;
6461 Prefix_Node : Node_Id;
6465 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6467 if Task_Dispatching_Policy /= ' '
6468 and then Task_Dispatching_Policy /= 'F'
6470 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6471 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6473 -- Set the FIFO_Within_Priorities policy, but always preserve
6474 -- System_Location since we like the error message with the run time
6478 Task_Dispatching_Policy := 'F';
6480 if Task_Dispatching_Policy_Sloc /= System_Location then
6481 Task_Dispatching_Policy_Sloc := Loc;
6485 -- pragma Locking_Policy (Ceiling_Locking)
6487 if Locking_Policy /= ' '
6488 and then Locking_Policy /= 'C'
6490 Error_Msg_Sloc := Locking_Policy_Sloc;
6491 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6493 -- Set the Ceiling_Locking policy, but preserve System_Location since
6494 -- we like the error message with the run time name.
6497 Locking_Policy := 'C';
6499 if Locking_Policy_Sloc /= System_Location then
6500 Locking_Policy_Sloc := Loc;
6504 -- pragma Detect_Blocking
6506 Detect_Blocking := True;
6508 -- Set the corresponding restrictions
6510 Set_Profile_Restrictions
6511 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6513 -- Set the No_Dependence restrictions
6515 -- The following No_Dependence restrictions:
6516 -- No_Dependence => Ada.Asynchronous_Task_Control
6517 -- No_Dependence => Ada.Calendar
6518 -- No_Dependence => Ada.Task_Attributes
6519 -- are already set by previous call to Set_Profile_Restrictions.
6521 -- Set the following restrictions which were added to Ada 2005:
6522 -- No_Dependence => Ada.Execution_Time.Group_Budget
6523 -- No_Dependence => Ada.Execution_Time.Timers
6525 if Ada_Version >= Ada_2005 then
6526 Name_Buffer (1 .. 3) := "ada";
6529 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6531 Name_Buffer (1 .. 14) := "execution_time";
6534 Selector_Entity := Make_Identifier (Loc, Name_Find);
6537 Make_Selected_Component
6539 Prefix => Prefix_Entity,
6540 Selector_Name => Selector_Entity);
6542 Name_Buffer (1 .. 13) := "group_budgets";
6545 Selector_Entity := Make_Identifier (Loc, Name_Find);
6548 Make_Selected_Component
6550 Prefix => Prefix_Node,
6551 Selector_Name => Selector_Entity);
6553 Set_Restriction_No_Dependence
6555 Warn => Treat_Restrictions_As_Warnings,
6556 Profile => Ravenscar);
6558 Name_Buffer (1 .. 6) := "timers";
6561 Selector_Entity := Make_Identifier (Loc, Name_Find);
6564 Make_Selected_Component
6566 Prefix => Prefix_Node,
6567 Selector_Name => Selector_Entity);
6569 Set_Restriction_No_Dependence
6571 Warn => Treat_Restrictions_As_Warnings,
6572 Profile => Ravenscar);
6575 -- Set the following restrictions which was added to Ada 2012 (see
6577 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6579 if Ada_Version >= Ada_2012 then
6580 Name_Buffer (1 .. 6) := "system";
6583 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6585 Name_Buffer (1 .. 15) := "multiprocessors";
6588 Selector_Entity := Make_Identifier (Loc, Name_Find);
6591 Make_Selected_Component
6593 Prefix => Prefix_Entity,
6594 Selector_Name => Selector_Entity);
6596 Name_Buffer (1 .. 19) := "dispatching_domains";
6599 Selector_Entity := Make_Identifier (Loc, Name_Find);
6602 Make_Selected_Component
6604 Prefix => Prefix_Node,
6605 Selector_Name => Selector_Entity);
6607 Set_Restriction_No_Dependence
6609 Warn => Treat_Restrictions_As_Warnings,
6610 Profile => Ravenscar);
6612 end Set_Ravenscar_Profile;
6618 procedure S14_Pragma is
6620 if not Formal_Extensions then
6621 Error_Pragma ("pragma% requires the use of debug switch -gnatd.V");
6625 -- Start of processing for Analyze_Pragma
6628 -- The following code is a defense against recursion. Not clear that
6629 -- this can happen legitimately, but perhaps some error situations
6630 -- can cause it, and we did see this recursion during testing.
6632 if Analyzed (N) then
6635 Set_Analyzed (N, True);
6638 -- Deal with unrecognized pragma
6640 Pname := Pragma_Name (N);
6642 if not Is_Pragma_Name (Pname) then
6643 if Warn_On_Unrecognized_Pragma then
6644 Error_Msg_Name_1 := Pname;
6645 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
6647 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6648 if Is_Bad_Spelling_Of (Pname, PN) then
6649 Error_Msg_Name_1 := PN;
6650 Error_Msg_N -- CODEFIX
6651 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
6660 -- Here to start processing for recognized pragma
6662 Prag_Id := Get_Pragma_Id (Pname);
6664 if Present (Corresponding_Aspect (N)) then
6665 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6676 if Present (Pragma_Argument_Associations (N)) then
6677 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6678 Arg1 := First (Pragma_Argument_Associations (N));
6680 if Present (Arg1) then
6681 Arg2 := Next (Arg1);
6683 if Present (Arg2) then
6684 Arg3 := Next (Arg2);
6686 if Present (Arg3) then
6687 Arg4 := Next (Arg3);
6693 -- An enumeration type defines the pragmas that are supported by the
6694 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6695 -- into the corresponding enumeration value for the following case.
6703 -- pragma Abort_Defer;
6705 when Pragma_Abort_Defer =>
6707 Check_Arg_Count (0);
6709 -- The only required semantic processing is to check the
6710 -- placement. This pragma must appear at the start of the
6711 -- statement sequence of a handled sequence of statements.
6713 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6714 or else N /= First (Statements (Parent (N)))
6719 --------------------
6720 -- Abstract_State --
6721 --------------------
6723 -- pragma Abstract_State (ABSTRACT_STATE_LIST)
6725 -- ABSTRACT_STATE_LIST ::=
6727 -- | STATE_NAME_WITH_PROPERTIES {, STATE_NAME_WITH_PROPERTIES}
6729 -- STATE_NAME_WITH_PROPERTIES ::=
6731 -- | (STATE_NAME with PROPERTY_LIST)
6733 -- PROPERTY_LIST ::= PROPERTY {, PROPERTY}
6734 -- PROPERTY ::= SIMPLE_PROPERTY
6735 -- | NAME_VALUE_PROPERTY
6736 -- SIMPLE_PROPERTY ::= IDENTIFIER
6737 -- NAME_VALUE_PROPERTY ::= IDENTIFIER => EXPRESSION
6738 -- STATE_NAME ::= DEFINING_IDENTIFIER
6740 when Pragma_Abstract_State => Abstract_State : declare
6741 Pack_Id : Entity_Id;
6743 -- Flags used to verify the consistency of states
6745 Non_Null_Seen : Boolean := False;
6746 Null_Seen : Boolean := False;
6748 procedure Analyze_Abstract_State (State : Node_Id);
6749 -- Verify the legality of a single state declaration. Create and
6750 -- decorate a state abstraction entity and introduce it into the
6751 -- visibility chain.
6753 ----------------------------
6754 -- Analyze_Abstract_State --
6755 ----------------------------
6757 procedure Analyze_Abstract_State (State : Node_Id) is
6758 procedure Check_Duplicate_Property
6760 Status : in out Boolean);
6761 -- Flag Status denotes whether a particular property has been
6762 -- seen while processing a state. This routine verifies that
6763 -- Prop is not a duplicate property and sets the flag Status.
6765 ------------------------------
6766 -- Check_Duplicate_Property --
6767 ------------------------------
6769 procedure Check_Duplicate_Property
6771 Status : in out Boolean)
6775 Error_Msg_N ("duplicate state property", Prop);
6779 end Check_Duplicate_Property;
6783 Errors : constant Nat := Serious_Errors_Detected;
6784 Loc : constant Source_Ptr := Sloc (State);
6787 Is_Null : Boolean := False;
6788 Level : Uint := Uint_0;
6792 -- Flags used to verify the consistency of properties
6794 Input_Seen : Boolean := False;
6795 Integrity_Seen : Boolean := False;
6796 Output_Seen : Boolean := False;
6797 Volatile_Seen : Boolean := False;
6799 -- Start of processing for Analyze_Abstract_State
6802 -- A package with a null abstract state is not allowed to
6803 -- declare additional states.
6806 Error_Msg_Name_1 := Chars (Pack_Id);
6807 Error_Msg_N ("package % has null abstract state", State);
6809 -- Null states appear as internally generated entities
6811 elsif Nkind (State) = N_Null then
6812 Name := New_Internal_Name ('S');
6816 -- Catch a case where a null state appears in a list of
6819 if Non_Null_Seen then
6820 Error_Msg_Name_1 := Chars (Pack_Id);
6822 ("package % has non-null abstract state", State);
6825 -- Simple state declaration
6827 elsif Nkind (State) = N_Identifier then
6828 Name := Chars (State);
6829 Non_Null_Seen := True;
6831 -- State declaration with various properties. This construct
6832 -- appears as an extension aggregate in the tree.
6834 elsif Nkind (State) = N_Extension_Aggregate then
6835 if Nkind (Ancestor_Part (State)) = N_Identifier then
6836 Name := Chars (Ancestor_Part (State));
6837 Non_Null_Seen := True;
6840 ("state name must be an identifier",
6841 Ancestor_Part (State));
6844 -- Process properties Input, Output and Volatile. Ensure
6845 -- that none of them appear more than once.
6847 Prop := First (Expressions (State));
6848 while Present (Prop) loop
6849 if Nkind (Prop) = N_Identifier then
6850 if Chars (Prop) = Name_Input then
6851 Check_Duplicate_Property (Prop, Input_Seen);
6852 elsif Chars (Prop) = Name_Output then
6853 Check_Duplicate_Property (Prop, Output_Seen);
6854 elsif Chars (Prop) = Name_Volatile then
6855 Check_Duplicate_Property (Prop, Volatile_Seen);
6857 Error_Msg_N ("invalid state property", Prop);
6860 Error_Msg_N ("invalid state property", Prop);
6866 -- Volatile requires exactly one Input or Output
6870 ((Input_Seen and then Output_Seen) -- both
6872 (not Input_Seen and then not Output_Seen)) -- none
6875 ("property Volatile requires exactly one Input or " &
6879 -- Either Input or Output require Volatile
6881 if (Input_Seen or Output_Seen)
6882 and then not Volatile_Seen
6885 ("properties Input and Output require Volatile", State);
6888 -- State property Integrity appears as a component
6891 Assoc := First (Component_Associations (State));
6892 while Present (Assoc) loop
6893 Prop := First (Choices (Assoc));
6894 while Present (Prop) loop
6895 if Nkind (Prop) = N_Identifier
6896 and then Chars (Prop) = Name_Integrity
6898 Check_Duplicate_Property (Prop, Integrity_Seen);
6900 Error_Msg_N ("invalid state property", Prop);
6906 if Nkind (Expression (Assoc)) = N_Integer_Literal then
6907 Level := Intval (Expression (Assoc));
6910 ("integrity level must be an integer literal",
6911 Expression (Assoc));
6917 -- Any other attempt to declare a state is erroneous
6920 Error_Msg_N ("malformed abstract state declaration", State);
6923 -- Do not generate a state abstraction entity if it was not
6924 -- properly declared.
6926 if Serious_Errors_Detected > Errors then
6930 -- The generated state abstraction reuses the same characters
6931 -- from the original state declaration. Decorate the entity.
6933 Id := Make_Defining_Identifier (Loc, New_External_Name (Name));
6934 Set_Comes_From_Source (Id, not Is_Null);
6935 Set_Parent (Id, State);
6936 Set_Ekind (Id, E_Abstract_State);
6937 Set_Etype (Id, Standard_Void_Type);
6938 Set_Integrity_Level (Id, Level);
6939 Set_Refined_State (Id, Empty);
6941 -- Every non-null state must be nameable and resolvable the
6942 -- same way a constant is.
6945 Push_Scope (Pack_Id);
6950 -- Associate the state with its related package
6952 if No (Abstract_States (Pack_Id)) then
6953 Set_Abstract_States (Pack_Id, New_Elmt_List);
6956 Append_Elmt (Id, Abstract_States (Pack_Id));
6957 end Analyze_Abstract_State;
6964 -- Start of processing for Abstract_State
6969 Check_Arg_Count (1);
6971 -- Ensure the proper placement of the pragma. Abstract states must
6972 -- be associated with a package declaration.
6974 if From_Aspect_Specification (N) then
6975 Par := Parent (Corresponding_Aspect (N));
6977 Par := Parent (Parent (N));
6980 if Nkind (Par) = N_Compilation_Unit then
6984 if Nkind (Par) /= N_Package_Declaration then
6989 Pack_Id := Defining_Unit_Name (Specification (Par));
6990 State := Expression (Arg1);
6992 -- Multiple abstract states appear as an aggregate
6994 if Nkind (State) = N_Aggregate then
6995 State := First (Expressions (State));
6996 while Present (State) loop
6997 Analyze_Abstract_State (State);
7002 -- Various forms of a single abstract state. Note that these may
7003 -- include malformed state declarations.
7006 Analyze_Abstract_State (State);
7016 -- Note: this pragma also has some specific processing in Par.Prag
7017 -- because we want to set the Ada version mode during parsing.
7019 when Pragma_Ada_83 =>
7021 Check_Arg_Count (0);
7023 -- We really should check unconditionally for proper configuration
7024 -- pragma placement, since we really don't want mixed Ada modes
7025 -- within a single unit, and the GNAT reference manual has always
7026 -- said this was a configuration pragma, but we did not check and
7027 -- are hesitant to add the check now.
7029 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
7030 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
7031 -- or Ada 2012 mode.
7033 if Ada_Version >= Ada_2005 then
7034 Check_Valid_Configuration_Pragma;
7037 -- Now set Ada 83 mode
7039 Ada_Version := Ada_83;
7040 Ada_Version_Explicit := Ada_Version;
7048 -- Note: this pragma also has some specific processing in Par.Prag
7049 -- because we want to set the Ada 83 version mode during parsing.
7051 when Pragma_Ada_95 =>
7053 Check_Arg_Count (0);
7055 -- We really should check unconditionally for proper configuration
7056 -- pragma placement, since we really don't want mixed Ada modes
7057 -- within a single unit, and the GNAT reference manual has always
7058 -- said this was a configuration pragma, but we did not check and
7059 -- are hesitant to add the check now.
7061 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
7062 -- or Ada 95, so we must check if we are in Ada 2005 mode.
7064 if Ada_Version >= Ada_2005 then
7065 Check_Valid_Configuration_Pragma;
7068 -- Now set Ada 95 mode
7070 Ada_Version := Ada_95;
7071 Ada_Version_Explicit := Ada_Version;
7073 ---------------------
7074 -- Ada_05/Ada_2005 --
7075 ---------------------
7078 -- pragma Ada_05 (LOCAL_NAME);
7081 -- pragma Ada_2005 (LOCAL_NAME):
7083 -- Note: these pragmas also have some specific processing in Par.Prag
7084 -- because we want to set the Ada 2005 version mode during parsing.
7086 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
7092 if Arg_Count = 1 then
7093 Check_Arg_Is_Local_Name (Arg1);
7094 E_Id := Get_Pragma_Arg (Arg1);
7096 if Etype (E_Id) = Any_Type then
7100 Set_Is_Ada_2005_Only (Entity (E_Id));
7101 Record_Rep_Item (Entity (E_Id), N);
7104 Check_Arg_Count (0);
7106 -- For Ada_2005 we unconditionally enforce the documented
7107 -- configuration pragma placement, since we do not want to
7108 -- tolerate mixed modes in a unit involving Ada 2005. That
7109 -- would cause real difficulties for those cases where there
7110 -- are incompatibilities between Ada 95 and Ada 2005.
7112 Check_Valid_Configuration_Pragma;
7114 -- Now set appropriate Ada mode
7116 Ada_Version := Ada_2005;
7117 Ada_Version_Explicit := Ada_2005;
7121 ---------------------
7122 -- Ada_12/Ada_2012 --
7123 ---------------------
7126 -- pragma Ada_12 (LOCAL_NAME);
7129 -- pragma Ada_2012 (LOCAL_NAME):
7131 -- Note: these pragmas also have some specific processing in Par.Prag
7132 -- because we want to set the Ada 2012 version mode during parsing.
7134 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
7140 if Arg_Count = 1 then
7141 Check_Arg_Is_Local_Name (Arg1);
7142 E_Id := Get_Pragma_Arg (Arg1);
7144 if Etype (E_Id) = Any_Type then
7148 Set_Is_Ada_2012_Only (Entity (E_Id));
7149 Record_Rep_Item (Entity (E_Id), N);
7152 Check_Arg_Count (0);
7154 -- For Ada_2012 we unconditionally enforce the documented
7155 -- configuration pragma placement, since we do not want to
7156 -- tolerate mixed modes in a unit involving Ada 2012. That
7157 -- would cause real difficulties for those cases where there
7158 -- are incompatibilities between Ada 95 and Ada 2012. We could
7159 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
7161 Check_Valid_Configuration_Pragma;
7163 -- Now set appropriate Ada mode
7165 Ada_Version := Ada_2012;
7166 Ada_Version_Explicit := Ada_2012;
7170 ----------------------
7171 -- All_Calls_Remote --
7172 ----------------------
7174 -- pragma All_Calls_Remote [(library_package_NAME)];
7176 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
7177 Lib_Entity : Entity_Id;
7180 Check_Ada_83_Warning;
7181 Check_Valid_Library_Unit_Pragma;
7183 if Nkind (N) = N_Null_Statement then
7187 Lib_Entity := Find_Lib_Unit_Name;
7189 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
7191 if Present (Lib_Entity)
7192 and then not Debug_Flag_U
7194 if not Is_Remote_Call_Interface (Lib_Entity) then
7195 Error_Pragma ("pragma% only apply to rci unit");
7197 -- Set flag for entity of the library unit
7200 Set_Has_All_Calls_Remote (Lib_Entity);
7204 end All_Calls_Remote;
7210 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
7211 -- ARG ::= NAME | EXPRESSION
7213 -- The first two arguments are by convention intended to refer to an
7214 -- external tool and a tool-specific function. These arguments are
7217 when Pragma_Annotate => Annotate : declare
7223 Check_At_Least_N_Arguments (1);
7224 Check_Arg_Is_Identifier (Arg1);
7225 Check_No_Identifiers;
7228 -- Second parameter is optional, it is never analyzed
7233 -- Here if we have a second parameter
7236 -- Second parameter must be identifier
7238 Check_Arg_Is_Identifier (Arg2);
7240 -- Process remaining parameters if any
7243 while Present (Arg) loop
7244 Exp := Get_Pragma_Arg (Arg);
7247 if Is_Entity_Name (Exp) then
7250 -- For string literals, we assume Standard_String as the
7251 -- type, unless the string contains wide or wide_wide
7254 elsif Nkind (Exp) = N_String_Literal then
7255 if Has_Wide_Wide_Character (Exp) then
7256 Resolve (Exp, Standard_Wide_Wide_String);
7257 elsif Has_Wide_Character (Exp) then
7258 Resolve (Exp, Standard_Wide_String);
7260 Resolve (Exp, Standard_String);
7263 elsif Is_Overloaded (Exp) then
7265 ("ambiguous argument for pragma%", Exp);
7276 ---------------------------
7277 -- Assert/Assert_And_Cut --
7278 ---------------------------
7281 -- ( [Check => ] Boolean_EXPRESSION
7282 -- [, [Message =>] Static_String_EXPRESSION]);
7284 -- pragma Assert_And_Cut
7285 -- ( [Check => ] Boolean_EXPRESSION
7286 -- [, [Message =>] Static_String_EXPRESSION]);
7288 when Pragma_Assert | Pragma_Assert_And_Cut => Assert : declare
7293 if Prag_Id = Pragma_Assert then
7295 else -- Pragma_Assert_And_Cut
7300 Check_At_Least_N_Arguments (1);
7301 Check_At_Most_N_Arguments (2);
7302 Check_Arg_Order ((Name_Check, Name_Message));
7303 Check_Optional_Identifier (Arg1, Name_Check);
7305 -- We treat pragma Assert as equivalent to:
7307 -- pragma Check (Assertion, condition [, msg]);
7309 -- So rewrite pragma in this manner, transfer the message
7310 -- argument if present, and analyze the result
7312 -- Pragma Assert_And_Cut is treated exactly like pragma Assert by
7313 -- the frontend. Formal verification tools may use it to "cut" the
7314 -- paths through the code, to make verification tractable. When
7315 -- dealing with a semantically analyzed tree, the information that
7316 -- a Check node N corresponds to a source Assert_And_Cut pragma
7317 -- can be retrieved from the pragma kind of Original_Node(N).
7319 Expr := Get_Pragma_Arg (Arg1);
7321 Make_Pragma_Argument_Association (Loc,
7322 Expression => Make_Identifier (Loc, Name_Assertion)),
7324 Make_Pragma_Argument_Association (Sloc (Expr),
7325 Expression => Expr));
7327 if Arg_Count > 1 then
7328 Check_Optional_Identifier (Arg2, Name_Message);
7329 Append_To (Newa, New_Copy_Tree (Arg2));
7334 Chars => Name_Check,
7335 Pragma_Argument_Associations => Newa));
7339 ----------------------
7340 -- Assertion_Policy --
7341 ----------------------
7343 -- pragma Assertion_Policy (Check | Disable | Ignore)
7345 when Pragma_Assertion_Policy => Assertion_Policy : declare
7350 Check_Valid_Configuration_Pragma;
7351 Check_Arg_Count (1);
7352 Check_No_Identifiers;
7353 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7355 -- We treat pragma Assertion_Policy as equivalent to:
7357 -- pragma Check_Policy (Assertion, policy)
7359 -- So rewrite the pragma in that manner and link on to the chain
7360 -- of Check_Policy pragmas, marking the pragma as analyzed.
7362 Policy := Get_Pragma_Arg (Arg1);
7366 Chars => Name_Check_Policy,
7367 Pragma_Argument_Associations => New_List (
7368 Make_Pragma_Argument_Association (Loc,
7369 Expression => Make_Identifier (Loc, Name_Assertion)),
7371 Make_Pragma_Argument_Association (Loc,
7373 Make_Identifier (Sloc (Policy), Chars (Policy))))));
7376 Set_Next_Pragma (N, Opt.Check_Policy_List);
7377 Opt.Check_Policy_List := N;
7378 end Assertion_Policy;
7384 -- pragma Assume (boolean_EXPRESSION);
7386 when Pragma_Assume => Assume : declare
7390 Check_Arg_Count (1);
7392 -- Pragma Assume is transformed into pragma Check in the following
7395 -- pragma Check (Assume, Expr);
7399 Chars => Name_Check,
7400 Pragma_Argument_Associations => New_List (
7401 Make_Pragma_Argument_Association (Loc,
7402 Expression => Make_Identifier (Loc, Name_Assume)),
7404 Make_Pragma_Argument_Association (Loc,
7405 Expression => Relocate_Node (Expression (Arg1))))));
7409 ------------------------------
7410 -- Assume_No_Invalid_Values --
7411 ------------------------------
7413 -- pragma Assume_No_Invalid_Values (On | Off);
7415 when Pragma_Assume_No_Invalid_Values =>
7417 Check_Valid_Configuration_Pragma;
7418 Check_Arg_Count (1);
7419 Check_No_Identifiers;
7420 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7422 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
7423 Assume_No_Invalid_Values := True;
7425 Assume_No_Invalid_Values := False;
7428 --------------------------
7429 -- Attribute_Definition --
7430 --------------------------
7432 -- pragma Attribute_Definition
7433 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
7434 -- [Entity =>] LOCAL_NAME,
7435 -- [Expression =>] EXPRESSION | NAME);
7437 when Pragma_Attribute_Definition => Attribute_Definition : declare
7438 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
7443 Check_Arg_Count (3);
7444 Check_Optional_Identifier (Arg1, "attribute");
7445 Check_Optional_Identifier (Arg2, "entity");
7446 Check_Optional_Identifier (Arg3, "expression");
7448 if Nkind (Attribute_Designator) /= N_Identifier then
7449 Error_Msg_N ("attribute name expected", Attribute_Designator);
7453 Check_Arg_Is_Local_Name (Arg2);
7455 -- If the attribute is not recognized, then issue a warning (not
7456 -- an error), and ignore the pragma.
7458 Aname := Chars (Attribute_Designator);
7460 if not Is_Attribute_Name (Aname) then
7461 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
7465 -- Otherwise, rewrite the pragma as an attribute definition clause
7468 Make_Attribute_Definition_Clause (Loc,
7469 Name => Get_Pragma_Arg (Arg2),
7471 Expression => Get_Pragma_Arg (Arg3)));
7473 end Attribute_Definition;
7479 -- pragma AST_Entry (entry_IDENTIFIER);
7481 when Pragma_AST_Entry => AST_Entry : declare
7487 Check_Arg_Count (1);
7488 Check_No_Identifiers;
7489 Check_Arg_Is_Local_Name (Arg1);
7490 Ent := Entity (Get_Pragma_Arg (Arg1));
7492 -- Note: the implementation of the AST_Entry pragma could handle
7493 -- the entry family case fine, but for now we are consistent with
7494 -- the DEC rules, and do not allow the pragma, which of course
7495 -- has the effect of also forbidding the attribute.
7497 if Ekind (Ent) /= E_Entry then
7499 ("pragma% argument must be simple entry name", Arg1);
7501 elsif Is_AST_Entry (Ent) then
7503 ("duplicate % pragma for entry", Arg1);
7505 elsif Has_Homonym (Ent) then
7507 ("pragma% argument cannot specify overloaded entry", Arg1);
7511 FF : constant Entity_Id := First_Formal (Ent);
7514 if Present (FF) then
7515 if Present (Next_Formal (FF)) then
7517 ("entry for pragma% can have only one argument",
7520 elsif Parameter_Mode (FF) /= E_In_Parameter then
7522 ("entry parameter for pragma% must have mode IN",
7528 Set_Is_AST_Entry (Ent);
7536 -- pragma Asynchronous (LOCAL_NAME);
7538 when Pragma_Asynchronous => Asynchronous : declare
7546 procedure Process_Async_Pragma;
7547 -- Common processing for procedure and access-to-procedure case
7549 --------------------------
7550 -- Process_Async_Pragma --
7551 --------------------------
7553 procedure Process_Async_Pragma is
7556 Set_Is_Asynchronous (Nm);
7560 -- The formals should be of mode IN (RM E.4.1(6))
7563 while Present (S) loop
7564 Formal := Defining_Identifier (S);
7566 if Nkind (Formal) = N_Defining_Identifier
7567 and then Ekind (Formal) /= E_In_Parameter
7570 ("pragma% procedure can only have IN parameter",
7577 Set_Is_Asynchronous (Nm);
7578 end Process_Async_Pragma;
7580 -- Start of processing for pragma Asynchronous
7583 Check_Ada_83_Warning;
7584 Check_No_Identifiers;
7585 Check_Arg_Count (1);
7586 Check_Arg_Is_Local_Name (Arg1);
7588 if Debug_Flag_U then
7592 C_Ent := Cunit_Entity (Current_Sem_Unit);
7593 Analyze (Get_Pragma_Arg (Arg1));
7594 Nm := Entity (Get_Pragma_Arg (Arg1));
7596 if not Is_Remote_Call_Interface (C_Ent)
7597 and then not Is_Remote_Types (C_Ent)
7599 -- This pragma should only appear in an RCI or Remote Types
7600 -- unit (RM E.4.1(4)).
7603 ("pragma% not in Remote_Call_Interface or " &
7604 "Remote_Types unit");
7607 if Ekind (Nm) = E_Procedure
7608 and then Nkind (Parent (Nm)) = N_Procedure_Specification
7610 if not Is_Remote_Call_Interface (Nm) then
7612 ("pragma% cannot be applied on non-remote procedure",
7616 L := Parameter_Specifications (Parent (Nm));
7617 Process_Async_Pragma;
7620 elsif Ekind (Nm) = E_Function then
7622 ("pragma% cannot be applied to function", Arg1);
7624 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
7625 if Is_Record_Type (Nm) then
7627 -- A record type that is the Equivalent_Type for a remote
7628 -- access-to-subprogram type.
7630 N := Declaration_Node (Corresponding_Remote_Type (Nm));
7633 -- A non-expanded RAS type (distribution is not enabled)
7635 N := Declaration_Node (Nm);
7638 if Nkind (N) = N_Full_Type_Declaration
7639 and then Nkind (Type_Definition (N)) =
7640 N_Access_Procedure_Definition
7642 L := Parameter_Specifications (Type_Definition (N));
7643 Process_Async_Pragma;
7645 if Is_Asynchronous (Nm)
7646 and then Expander_Active
7647 and then Get_PCS_Name /= Name_No_DSA
7649 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
7654 ("pragma% cannot reference access-to-function type",
7658 -- Only other possibility is Access-to-class-wide type
7660 elsif Is_Access_Type (Nm)
7661 and then Is_Class_Wide_Type (Designated_Type (Nm))
7663 Check_First_Subtype (Arg1);
7664 Set_Is_Asynchronous (Nm);
7665 if Expander_Active then
7666 RACW_Type_Is_Asynchronous (Nm);
7670 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
7678 -- pragma Atomic (LOCAL_NAME);
7680 when Pragma_Atomic =>
7681 Process_Atomic_Shared_Volatile;
7683 -----------------------
7684 -- Atomic_Components --
7685 -----------------------
7687 -- pragma Atomic_Components (array_LOCAL_NAME);
7689 -- This processing is shared by Volatile_Components
7691 when Pragma_Atomic_Components |
7692 Pragma_Volatile_Components =>
7694 Atomic_Components : declare
7701 Check_Ada_83_Warning;
7702 Check_No_Identifiers;
7703 Check_Arg_Count (1);
7704 Check_Arg_Is_Local_Name (Arg1);
7705 E_Id := Get_Pragma_Arg (Arg1);
7707 if Etype (E_Id) = Any_Type then
7713 Check_Duplicate_Pragma (E);
7715 if Rep_Item_Too_Early (E, N)
7717 Rep_Item_Too_Late (E, N)
7722 D := Declaration_Node (E);
7725 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7727 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7728 and then Nkind (D) = N_Object_Declaration
7729 and then Nkind (Object_Definition (D)) =
7730 N_Constrained_Array_Definition)
7732 -- The flag is set on the object, or on the base type
7734 if Nkind (D) /= N_Object_Declaration then
7738 Set_Has_Volatile_Components (E);
7740 if Prag_Id = Pragma_Atomic_Components then
7741 Set_Has_Atomic_Components (E);
7745 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7747 end Atomic_Components;
7749 --------------------
7750 -- Attach_Handler --
7751 --------------------
7753 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7755 when Pragma_Attach_Handler =>
7756 Check_Ada_83_Warning;
7757 Check_No_Identifiers;
7758 Check_Arg_Count (2);
7760 if No_Run_Time_Mode then
7761 Error_Msg_CRT ("Attach_Handler pragma", N);
7763 Check_Interrupt_Or_Attach_Handler;
7765 -- The expression that designates the attribute may depend on a
7766 -- discriminant, and is therefore a per-object expression, to
7767 -- be expanded in the init proc. If expansion is enabled, then
7768 -- perform semantic checks on a copy only.
7770 if Expander_Active then
7772 Temp : constant Node_Id :=
7773 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7775 Set_Parent (Temp, N);
7776 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7780 Analyze (Get_Pragma_Arg (Arg2));
7781 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7784 Process_Interrupt_Or_Attach_Handler;
7787 --------------------
7788 -- C_Pass_By_Copy --
7789 --------------------
7791 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7793 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7799 Check_Valid_Configuration_Pragma;
7800 Check_Arg_Count (1);
7801 Check_Optional_Identifier (Arg1, "max_size");
7803 Arg := Get_Pragma_Arg (Arg1);
7804 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7806 Val := Expr_Value (Arg);
7810 ("maximum size for pragma% must be positive", Arg1);
7812 elsif UI_Is_In_Int_Range (Val) then
7813 Default_C_Record_Mechanism := UI_To_Int (Val);
7815 -- If a giant value is given, Int'Last will do well enough.
7816 -- If sometime someone complains that a record larger than
7817 -- two gigabytes is not copied, we will worry about it then!
7820 Default_C_Record_Mechanism := Mechanism_Type'Last;
7828 -- pragma Check ([Name =>] IDENTIFIER,
7829 -- [Check =>] Boolean_EXPRESSION
7830 -- [,[Message =>] String_EXPRESSION]);
7832 when Pragma_Check => Check : declare
7839 -- Set True if category of assertions referenced by Name enabled
7843 Check_At_Least_N_Arguments (2);
7844 Check_At_Most_N_Arguments (3);
7845 Check_Optional_Identifier (Arg1, Name_Name);
7846 Check_Optional_Identifier (Arg2, Name_Check);
7848 if Arg_Count = 3 then
7849 Check_Optional_Identifier (Arg3, Name_Message);
7850 Str := Get_Pragma_Arg (Arg3);
7853 Check_Arg_Is_Identifier (Arg1);
7854 Cname := Chars (Get_Pragma_Arg (Arg1));
7855 Check_On := Check_Enabled (Cname);
7856 Expr := Get_Pragma_Arg (Arg2);
7858 -- Deal with SCO generation
7861 when Name_Predicate |
7864 -- Nothing to do: since checks occur in client units,
7865 -- the SCO for the aspect in the declaration unit is
7866 -- conservatively always enabled.
7872 if Check_On and then not Split_PPC (N) then
7874 -- Mark pragma/aspect SCO as enabled
7876 Set_SCO_Pragma_Enabled (Loc);
7880 -- Deal with analyzing the string argument.
7882 if Arg_Count = 3 then
7884 -- If checks are not on we don't want any expansion (since
7885 -- such expansion would not get properly deleted) but
7886 -- we do want to analyze (to get proper references).
7887 -- The Preanalyze_And_Resolve routine does just what we want
7889 if not Check_On then
7890 Preanalyze_And_Resolve (Str, Standard_String);
7892 -- Otherwise we need a proper analysis and expansion
7895 Analyze_And_Resolve (Str, Standard_String);
7899 -- Now you might think we could just do the same with the
7900 -- Boolean expression if checks are off (and expansion is on)
7901 -- and then rewrite the check as a null
7902 -- statement. This would work but we would lose the useful
7903 -- warnings about an assertion being bound to fail even if
7904 -- assertions are turned off.
7906 -- So instead we wrap the boolean expression in an if statement
7909 -- if False and then condition then
7913 -- The reason we do this rewriting during semantic analysis
7914 -- rather than as part of normal expansion is that we cannot
7915 -- analyze and expand the code for the boolean expression
7916 -- directly, or it may cause insertion of actions that would
7917 -- escape the attempt to suppress the check code.
7919 -- Note that the Sloc for the if statement corresponds to the
7920 -- argument condition, not the pragma itself. The reason for
7921 -- this is that we may generate a warning if the condition is
7922 -- False at compile time, and we do not want to delete this
7923 -- warning when we delete the if statement.
7925 if Expander_Active and not Check_On then
7926 Eloc := Sloc (Expr);
7929 Make_If_Statement (Eloc,
7931 Make_And_Then (Eloc,
7932 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7933 Right_Opnd => Expr),
7934 Then_Statements => New_List (
7935 Make_Null_Statement (Eloc))));
7937 In_Assertion_Expr := In_Assertion_Expr + 1;
7939 In_Assertion_Expr := In_Assertion_Expr - 1;
7941 -- Check is active or expansion not active. In these cases we can
7942 -- just go ahead and analyze the boolean with no worries.
7945 In_Assertion_Expr := In_Assertion_Expr + 1;
7946 Analyze_And_Resolve (Expr, Any_Boolean);
7947 In_Assertion_Expr := In_Assertion_Expr - 1;
7951 --------------------------
7952 -- Check_Float_Overflow --
7953 --------------------------
7955 -- pragma Check_Float_Overflow;
7957 when Pragma_Check_Float_Overflow =>
7959 Check_Valid_Configuration_Pragma;
7960 Check_Arg_Count (0);
7961 Check_Float_Overflow := True;
7967 -- pragma Check_Name (check_IDENTIFIER);
7969 when Pragma_Check_Name =>
7970 Check_No_Identifiers;
7972 Check_Valid_Configuration_Pragma;
7973 Check_Arg_Count (1);
7974 Check_Arg_Is_Identifier (Arg1);
7977 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7980 for J in Check_Names.First .. Check_Names.Last loop
7981 if Check_Names.Table (J) = Nam then
7986 Check_Names.Append (Nam);
7993 -- pragma Check_Policy (
7994 -- [Name =>] IDENTIFIER,
7995 -- [Policy =>] POLICY_IDENTIFIER);
7997 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7999 -- Note: this is a configuration pragma, but it is allowed to appear
8002 when Pragma_Check_Policy =>
8004 Check_Arg_Count (2);
8005 Check_Optional_Identifier (Arg1, Name_Name);
8006 Check_Optional_Identifier (Arg2, Name_Policy);
8008 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
8010 -- A Check_Policy pragma can appear either as a configuration
8011 -- pragma, or in a declarative part or a package spec (see RM
8012 -- 11.5(5) for rules for Suppress/Unsuppress which are also
8013 -- followed for Check_Policy).
8015 if not Is_Configuration_Pragma then
8016 Check_Is_In_Decl_Part_Or_Package_Spec;
8019 Set_Next_Pragma (N, Opt.Check_Policy_List);
8020 Opt.Check_Policy_List := N;
8022 ---------------------
8023 -- CIL_Constructor --
8024 ---------------------
8026 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
8028 -- Processing for this pragma is shared with Java_Constructor
8034 -- pragma Comment (static_string_EXPRESSION)
8036 -- Processing for pragma Comment shares the circuitry for pragma
8037 -- Ident. The only differences are that Ident enforces a limit of 31
8038 -- characters on its argument, and also enforces limitations on
8039 -- placement for DEC compatibility. Pragma Comment shares neither of
8040 -- these restrictions.
8046 -- pragma Common_Object (
8047 -- [Internal =>] LOCAL_NAME
8048 -- [, [External =>] EXTERNAL_SYMBOL]
8049 -- [, [Size =>] EXTERNAL_SYMBOL]);
8051 -- Processing for this pragma is shared with Psect_Object
8053 ------------------------
8054 -- Compile_Time_Error --
8055 ------------------------
8057 -- pragma Compile_Time_Error
8058 -- (boolean_EXPRESSION, static_string_EXPRESSION);
8060 when Pragma_Compile_Time_Error =>
8062 Process_Compile_Time_Warning_Or_Error;
8064 --------------------------
8065 -- Compile_Time_Warning --
8066 --------------------------
8068 -- pragma Compile_Time_Warning
8069 -- (boolean_EXPRESSION, static_string_EXPRESSION);
8071 when Pragma_Compile_Time_Warning =>
8073 Process_Compile_Time_Warning_Or_Error;
8079 when Pragma_Compiler_Unit =>
8081 Check_Arg_Count (0);
8082 Set_Is_Compiler_Unit (Get_Source_Unit (N));
8084 -----------------------------
8085 -- Complete_Representation --
8086 -----------------------------
8088 -- pragma Complete_Representation;
8090 when Pragma_Complete_Representation =>
8092 Check_Arg_Count (0);
8094 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
8096 ("pragma & must appear within record representation clause");
8099 ----------------------------
8100 -- Complex_Representation --
8101 ----------------------------
8103 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
8105 when Pragma_Complex_Representation => Complex_Representation : declare
8112 Check_Arg_Count (1);
8113 Check_Optional_Identifier (Arg1, Name_Entity);
8114 Check_Arg_Is_Local_Name (Arg1);
8115 E_Id := Get_Pragma_Arg (Arg1);
8117 if Etype (E_Id) = Any_Type then
8123 if not Is_Record_Type (E) then
8125 ("argument for pragma% must be record type", Arg1);
8128 Ent := First_Entity (E);
8131 or else No (Next_Entity (Ent))
8132 or else Present (Next_Entity (Next_Entity (Ent)))
8133 or else not Is_Floating_Point_Type (Etype (Ent))
8134 or else Etype (Ent) /= Etype (Next_Entity (Ent))
8137 ("record for pragma% must have two fields of the same "
8138 & "floating-point type", Arg1);
8141 Set_Has_Complex_Representation (Base_Type (E));
8143 -- We need to treat the type has having a non-standard
8144 -- representation, for back-end purposes, even though in
8145 -- general a complex will have the default representation
8146 -- of a record with two real components.
8148 Set_Has_Non_Standard_Rep (Base_Type (E));
8150 end Complex_Representation;
8152 -------------------------
8153 -- Component_Alignment --
8154 -------------------------
8156 -- pragma Component_Alignment (
8157 -- [Form =>] ALIGNMENT_CHOICE
8158 -- [, [Name =>] type_LOCAL_NAME]);
8160 -- ALIGNMENT_CHOICE ::=
8162 -- | Component_Size_4
8166 when Pragma_Component_Alignment => Component_AlignmentP : declare
8167 Args : Args_List (1 .. 2);
8168 Names : constant Name_List (1 .. 2) := (
8172 Form : Node_Id renames Args (1);
8173 Name : Node_Id renames Args (2);
8175 Atype : Component_Alignment_Kind;
8180 Gather_Associations (Names, Args);
8183 Error_Pragma ("missing Form argument for pragma%");
8186 Check_Arg_Is_Identifier (Form);
8188 -- Get proper alignment, note that Default = Component_Size on all
8189 -- machines we have so far, and we want to set this value rather
8190 -- than the default value to indicate that it has been explicitly
8191 -- set (and thus will not get overridden by the default component
8192 -- alignment for the current scope)
8194 if Chars (Form) = Name_Component_Size then
8195 Atype := Calign_Component_Size;
8197 elsif Chars (Form) = Name_Component_Size_4 then
8198 Atype := Calign_Component_Size_4;
8200 elsif Chars (Form) = Name_Default then
8201 Atype := Calign_Component_Size;
8203 elsif Chars (Form) = Name_Storage_Unit then
8204 Atype := Calign_Storage_Unit;
8208 ("invalid Form parameter for pragma%", Form);
8211 -- Case with no name, supplied, affects scope table entry
8215 (Scope_Stack.Last).Component_Alignment_Default := Atype;
8217 -- Case of name supplied
8220 Check_Arg_Is_Local_Name (Name);
8222 Typ := Entity (Name);
8225 or else Rep_Item_Too_Early (Typ, N)
8229 Typ := Underlying_Type (Typ);
8232 if not Is_Record_Type (Typ)
8233 and then not Is_Array_Type (Typ)
8236 ("Name parameter of pragma% must identify record or " &
8237 "array type", Name);
8240 -- An explicit Component_Alignment pragma overrides an
8241 -- implicit pragma Pack, but not an explicit one.
8243 if not Has_Pragma_Pack (Base_Type (Typ)) then
8244 Set_Is_Packed (Base_Type (Typ), False);
8245 Set_Component_Alignment (Base_Type (Typ), Atype);
8248 end Component_AlignmentP;
8254 -- pragma Contract_Case
8255 -- ([Name =>] Static_String_EXPRESSION
8256 -- ,[Mode =>] MODE_TYPE
8257 -- [, Requires => Boolean_EXPRESSION]
8258 -- [, Ensures => Boolean_EXPRESSION]);
8260 -- MODE_TYPE ::= Nominal | Robustness
8262 when Pragma_Contract_Case =>
8263 Check_Contract_Or_Test_Case;
8265 --------------------
8266 -- Contract_Cases --
8267 --------------------
8269 -- pragma Contract_Cases (CONTRACT_CASE_LIST);
8271 -- CONTRACT_CASE_LIST ::= CONTRACT_CASE {, CONTRACT_CASE}
8273 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
8275 -- CASE_GUARD ::= boolean_EXPRESSION | others
8277 -- CONSEQUENCE ::= boolean_EXPRESSION
8279 when Pragma_Contract_Cases => Contract_Cases : declare
8280 procedure Chain_Contract_Cases (Subp_Decl : Node_Id);
8281 -- Chain pragma Contract_Cases to the contract of a subprogram.
8282 -- Subp_Decl is the declaration of the subprogram.
8284 --------------------------
8285 -- Chain_Contract_Cases --
8286 --------------------------
8288 procedure Chain_Contract_Cases (Subp_Decl : Node_Id) is
8289 Subp : constant Entity_Id :=
8290 Defining_Unit_Name (Specification (Subp_Decl));
8294 Check_Duplicate_Pragma (Subp);
8295 CTC := Spec_CTC_List (Contract (Subp));
8296 while Present (CTC) loop
8297 if Chars (Pragma_Identifier (CTC)) = Pname then
8298 Error_Msg_Name_1 := Pname;
8299 Error_Msg_Sloc := Sloc (CTC);
8301 if From_Aspect_Specification (CTC) then
8303 ("aspect% for & previously given#", N, Subp);
8306 ("pragma% for & duplicates pragma#", N, Subp);
8312 CTC := Next_Pragma (CTC);
8315 -- Prepend pragma Contract_Cases to the contract
8317 Set_Next_Pragma (N, Spec_CTC_List (Contract (Subp)));
8318 Set_Spec_CTC_List (Contract (Subp), N);
8319 end Chain_Contract_Cases;
8323 Case_Guard : Node_Id;
8326 Others_Seen : Boolean := False;
8327 Contract_Case : Node_Id;
8328 Subp_Decl : Node_Id;
8330 -- Start of processing for Contract_Cases
8335 Check_Arg_Count (1);
8337 -- Completely ignore if disabled
8339 if not Check_Enabled (Pname) then
8340 Rewrite (N, Make_Null_Statement (Loc));
8345 -- Check the placement of the pragma
8347 if not Is_List_Member (N) then
8351 -- Pragma Contract_Cases must be associated with a subprogram
8354 while Present (Prev (Decl)) loop
8355 Decl := Prev (Decl);
8357 if Nkind (Decl) in N_Generic_Declaration then
8360 Subp_Decl := Original_Node (Decl);
8363 -- Skip prior pragmas
8365 if Nkind (Subp_Decl) = N_Pragma then
8368 -- Skip internally generated code
8370 elsif not Comes_From_Source (Subp_Decl) then
8373 -- We have found the related subprogram
8375 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
8376 N_Subprogram_Declaration)
8385 -- All contract cases must appear as an aggregate
8387 if Nkind (Expression (Arg1)) /= N_Aggregate then
8388 Error_Pragma ("wrong syntax for pragma %");
8392 -- Verify the legality of individual contract cases
8395 First (Component_Associations (Expression (Arg1)));
8396 while Present (Contract_Case) loop
8397 if Nkind (Contract_Case) /= N_Component_Association then
8399 ("wrong syntax in contract case", Contract_Case);
8403 Case_Guard := First (Choices (Contract_Case));
8405 -- Each contract case must have exactly on case guard
8407 Extra := Next (Case_Guard);
8408 if Present (Extra) then
8410 ("contract case may have only one case guard", Extra);
8414 -- Check the placement of "others" (if available)
8416 if Nkind (Case_Guard) = N_Others_Choice then
8419 ("only one others choice allowed in pragma %",
8423 Others_Seen := True;
8426 elsif Others_Seen then
8428 ("others must be the last choice in pragma %", N);
8432 Next (Contract_Case);
8435 Chain_Contract_Cases (Subp_Decl);
8442 -- pragma Controlled (first_subtype_LOCAL_NAME);
8444 when Pragma_Controlled => Controlled : declare
8448 Check_No_Identifiers;
8449 Check_Arg_Count (1);
8450 Check_Arg_Is_Local_Name (Arg1);
8451 Arg := Get_Pragma_Arg (Arg1);
8453 if not Is_Entity_Name (Arg)
8454 or else not Is_Access_Type (Entity (Arg))
8456 Error_Pragma_Arg ("pragma% requires access type", Arg1);
8458 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
8466 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
8467 -- [Entity =>] LOCAL_NAME);
8469 when Pragma_Convention => Convention : declare
8472 pragma Warnings (Off, C);
8473 pragma Warnings (Off, E);
8475 Check_Arg_Order ((Name_Convention, Name_Entity));
8476 Check_Ada_83_Warning;
8477 Check_Arg_Count (2);
8478 Process_Convention (C, E);
8481 ---------------------------
8482 -- Convention_Identifier --
8483 ---------------------------
8485 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
8486 -- [Convention =>] convention_IDENTIFIER);
8488 when Pragma_Convention_Identifier => Convention_Identifier : declare
8494 Check_Arg_Order ((Name_Name, Name_Convention));
8495 Check_Arg_Count (2);
8496 Check_Optional_Identifier (Arg1, Name_Name);
8497 Check_Optional_Identifier (Arg2, Name_Convention);
8498 Check_Arg_Is_Identifier (Arg1);
8499 Check_Arg_Is_Identifier (Arg2);
8500 Idnam := Chars (Get_Pragma_Arg (Arg1));
8501 Cname := Chars (Get_Pragma_Arg (Arg2));
8503 if Is_Convention_Name (Cname) then
8504 Record_Convention_Identifier
8505 (Idnam, Get_Convention_Id (Cname));
8508 ("second arg for % pragma must be convention", Arg2);
8510 end Convention_Identifier;
8516 -- pragma CPP_Class ([Entity =>] local_NAME)
8518 when Pragma_CPP_Class => CPP_Class : declare
8522 if Warn_On_Obsolescent_Feature then
8523 -- Following message is obsolete ???
8525 ("'G'N'A'T pragma cpp'_class is now obsolete and has no " &
8526 "effect; replace it by pragma import?j?", N);
8529 Check_Arg_Count (1);
8533 Chars => Name_Import,
8534 Pragma_Argument_Associations => New_List (
8535 Make_Pragma_Argument_Association (Loc,
8536 Expression => Make_Identifier (Loc, Name_CPP)),
8537 New_Copy (First (Pragma_Argument_Associations (N))))));
8541 ---------------------
8542 -- CPP_Constructor --
8543 ---------------------
8545 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
8546 -- [, [External_Name =>] static_string_EXPRESSION ]
8547 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8549 when Pragma_CPP_Constructor => CPP_Constructor : declare
8553 Tag_Typ : Entity_Id;
8557 Check_At_Least_N_Arguments (1);
8558 Check_At_Most_N_Arguments (3);
8559 Check_Optional_Identifier (Arg1, Name_Entity);
8560 Check_Arg_Is_Local_Name (Arg1);
8562 Id := Get_Pragma_Arg (Arg1);
8563 Find_Program_Unit_Name (Id);
8565 -- If we did not find the name, we are done
8567 if Etype (Id) = Any_Type then
8571 Def_Id := Entity (Id);
8573 -- Check if already defined as constructor
8575 if Is_Constructor (Def_Id) then
8577 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
8581 if Ekind (Def_Id) = E_Function
8582 and then (Is_CPP_Class (Etype (Def_Id))
8583 or else (Is_Class_Wide_Type (Etype (Def_Id))
8585 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
8587 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
8589 ("'C'P'P constructor must be defined in the scope of " &
8590 "its returned type", Arg1);
8593 if Arg_Count >= 2 then
8594 Set_Imported (Def_Id);
8595 Set_Is_Public (Def_Id);
8596 Process_Interface_Name (Def_Id, Arg2, Arg3);
8599 Set_Has_Completion (Def_Id);
8600 Set_Is_Constructor (Def_Id);
8601 Set_Convention (Def_Id, Convention_CPP);
8603 -- Imported C++ constructors are not dispatching primitives
8604 -- because in C++ they don't have a dispatch table slot.
8605 -- However, in Ada the constructor has the profile of a
8606 -- function that returns a tagged type and therefore it has
8607 -- been treated as a primitive operation during semantic
8608 -- analysis. We now remove it from the list of primitive
8609 -- operations of the type.
8611 if Is_Tagged_Type (Etype (Def_Id))
8612 and then not Is_Class_Wide_Type (Etype (Def_Id))
8613 and then Is_Dispatching_Operation (Def_Id)
8615 Tag_Typ := Etype (Def_Id);
8617 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
8618 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
8622 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
8623 Set_Is_Dispatching_Operation (Def_Id, False);
8626 -- For backward compatibility, if the constructor returns a
8627 -- class wide type, and we internally change the return type to
8628 -- the corresponding root type.
8630 if Is_Class_Wide_Type (Etype (Def_Id)) then
8631 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
8635 ("pragma% requires function returning a 'C'P'P_Class type",
8638 end CPP_Constructor;
8644 when Pragma_CPP_Virtual => CPP_Virtual : declare
8648 if Warn_On_Obsolescent_Feature then
8650 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
8659 when Pragma_CPP_Vtable => CPP_Vtable : declare
8663 if Warn_On_Obsolescent_Feature then
8665 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
8674 -- pragma CPU (EXPRESSION);
8676 when Pragma_CPU => CPU : declare
8677 P : constant Node_Id := Parent (N);
8683 Check_No_Identifiers;
8684 Check_Arg_Count (1);
8688 if Nkind (P) = N_Subprogram_Body then
8689 Check_In_Main_Program;
8691 Arg := Get_Pragma_Arg (Arg1);
8692 Analyze_And_Resolve (Arg, Any_Integer);
8694 Ent := Defining_Unit_Name (Specification (P));
8696 if Nkind (Ent) = N_Defining_Program_Unit_Name then
8697 Ent := Defining_Identifier (Ent);
8702 if not Is_Static_Expression (Arg) then
8703 Flag_Non_Static_Expr
8704 ("main subprogram affinity is not static!", Arg);
8707 -- If constraint error, then we already signalled an error
8709 elsif Raises_Constraint_Error (Arg) then
8712 -- Otherwise check in range
8716 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
8717 -- This is the entity System.Multiprocessors.CPU_Range;
8719 Val : constant Uint := Expr_Value (Arg);
8722 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
8724 Val > Expr_Value (Type_High_Bound (CPU_Id))
8727 ("main subprogram CPU is out of range", Arg1);
8733 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8737 elsif Nkind (P) = N_Task_Definition then
8738 Arg := Get_Pragma_Arg (Arg1);
8739 Ent := Defining_Identifier (Parent (P));
8741 -- The expression must be analyzed in the special manner
8742 -- described in "Handling of Default and Per-Object
8743 -- Expressions" in sem.ads.
8745 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
8747 -- Anything else is incorrect
8753 -- Check duplicate pragma before we chain the pragma in the Rep
8754 -- Item chain of Ent.
8756 Check_Duplicate_Pragma (Ent);
8757 Record_Rep_Item (Ent, N);
8764 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
8766 when Pragma_Debug => Debug : declare
8773 -- Skip analysis if disabled
8775 if Debug_Pragmas_Disabled then
8776 Rewrite (N, Make_Null_Statement (Loc));
8783 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
8786 if Debug_Pragmas_Enabled then
8787 Set_SCO_Pragma_Enabled (Loc);
8790 if Arg_Count = 2 then
8793 Left_Opnd => Relocate_Node (Cond),
8794 Right_Opnd => Get_Pragma_Arg (Arg1));
8795 Call := Get_Pragma_Arg (Arg2);
8797 Call := Get_Pragma_Arg (Arg1);
8801 N_Indexed_Component,
8805 N_Selected_Component)
8807 -- If this pragma Debug comes from source, its argument was
8808 -- parsed as a name form (which is syntactically identical).
8809 -- In a generic context a parameterless call will be left as
8810 -- an expanded name (if global) or selected_component if local.
8811 -- Change it to a procedure call statement now.
8813 Change_Name_To_Procedure_Call_Statement (Call);
8815 elsif Nkind (Call) = N_Procedure_Call_Statement then
8817 -- Already in the form of a procedure call statement: nothing
8818 -- to do (could happen in case of an internally generated
8824 -- All other cases: diagnose error
8827 ("argument of pragma ""Debug"" is not procedure call",
8832 -- Rewrite into a conditional with an appropriate condition. We
8833 -- wrap the procedure call in a block so that overhead from e.g.
8834 -- use of the secondary stack does not generate execution overhead
8835 -- for suppressed conditions.
8837 -- Normally the analysis that follows will freeze the subprogram
8838 -- being called. However, if the call is to a null procedure,
8839 -- we want to freeze it before creating the block, because the
8840 -- analysis that follows may be done with expansion disabled, in
8841 -- which case the body will not be generated, leading to spurious
8844 if Nkind (Call) = N_Procedure_Call_Statement
8845 and then Is_Entity_Name (Name (Call))
8847 Analyze (Name (Call));
8848 Freeze_Before (N, Entity (Name (Call)));
8851 Rewrite (N, Make_Implicit_If_Statement (N,
8853 Then_Statements => New_List (
8854 Make_Block_Statement (Loc,
8855 Handled_Statement_Sequence =>
8856 Make_Handled_Sequence_Of_Statements (Loc,
8857 Statements => New_List (Relocate_Node (Call)))))));
8865 -- pragma Debug_Policy (Check | Ignore)
8867 when Pragma_Debug_Policy =>
8869 Check_Arg_Count (1);
8870 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
8871 Debug_Pragmas_Enabled :=
8872 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
8873 Debug_Pragmas_Disabled :=
8874 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
8876 ---------------------
8877 -- Detect_Blocking --
8878 ---------------------
8880 -- pragma Detect_Blocking;
8882 when Pragma_Detect_Blocking =>
8884 Check_Arg_Count (0);
8885 Check_Valid_Configuration_Pragma;
8886 Detect_Blocking := True;
8888 --------------------------
8889 -- Default_Storage_Pool --
8890 --------------------------
8892 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
8894 when Pragma_Default_Storage_Pool =>
8896 Check_Arg_Count (1);
8898 -- Default_Storage_Pool can appear as a configuration pragma, or
8899 -- in a declarative part or a package spec.
8901 if not Is_Configuration_Pragma then
8902 Check_Is_In_Decl_Part_Or_Package_Spec;
8905 -- Case of Default_Storage_Pool (null);
8907 if Nkind (Expression (Arg1)) = N_Null then
8908 Analyze (Expression (Arg1));
8910 -- This is an odd case, this is not really an expression, so
8911 -- we don't have a type for it. So just set the type to Empty.
8913 Set_Etype (Expression (Arg1), Empty);
8915 -- Case of Default_Storage_Pool (storage_pool_NAME);
8918 -- If it's a configuration pragma, then the only allowed
8919 -- argument is "null".
8921 if Is_Configuration_Pragma then
8922 Error_Pragma_Arg ("NULL expected", Arg1);
8925 -- The expected type for a non-"null" argument is
8926 -- Root_Storage_Pool'Class.
8929 (Get_Pragma_Arg (Arg1),
8930 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8933 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
8934 -- for an access type will use this information to set the
8935 -- appropriate attributes of the access type.
8937 Default_Pool := Expression (Arg1);
8939 ------------------------------------
8940 -- Disable_Atomic_Synchronization --
8941 ------------------------------------
8943 -- pragma Disable_Atomic_Synchronization [(Entity)];
8945 when Pragma_Disable_Atomic_Synchronization =>
8946 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8952 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
8954 when Pragma_Discard_Names => Discard_Names : declare
8959 Check_Ada_83_Warning;
8961 -- Deal with configuration pragma case
8963 if Arg_Count = 0 and then Is_Configuration_Pragma then
8964 Global_Discard_Names := True;
8967 -- Otherwise, check correct appropriate context
8970 Check_Is_In_Decl_Part_Or_Package_Spec;
8972 if Arg_Count = 0 then
8974 -- If there is no parameter, then from now on this pragma
8975 -- applies to any enumeration, exception or tagged type
8976 -- defined in the current declarative part, and recursively
8977 -- to any nested scope.
8979 Set_Discard_Names (Current_Scope);
8983 Check_Arg_Count (1);
8984 Check_Optional_Identifier (Arg1, Name_On);
8985 Check_Arg_Is_Local_Name (Arg1);
8987 E_Id := Get_Pragma_Arg (Arg1);
8989 if Etype (E_Id) = Any_Type then
8995 if (Is_First_Subtype (E)
8997 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8998 or else Ekind (E) = E_Exception
9000 Set_Discard_Names (E);
9001 Record_Rep_Item (E, N);
9005 ("inappropriate entity for pragma%", Arg1);
9012 ------------------------
9013 -- Dispatching_Domain --
9014 ------------------------
9016 -- pragma Dispatching_Domain (EXPRESSION);
9018 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
9019 P : constant Node_Id := Parent (N);
9025 Check_No_Identifiers;
9026 Check_Arg_Count (1);
9028 -- This pragma is born obsolete, but not the aspect
9030 if not From_Aspect_Specification (N) then
9032 (No_Obsolescent_Features, Pragma_Identifier (N));
9035 if Nkind (P) = N_Task_Definition then
9036 Arg := Get_Pragma_Arg (Arg1);
9037 Ent := Defining_Identifier (Parent (P));
9039 -- The expression must be analyzed in the special manner
9040 -- described in "Handling of Default and Per-Object
9041 -- Expressions" in sem.ads.
9043 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
9045 -- Check duplicate pragma before we chain the pragma in the Rep
9046 -- Item chain of Ent.
9048 Check_Duplicate_Pragma (Ent);
9049 Record_Rep_Item (Ent, N);
9051 -- Anything else is incorrect
9056 end Dispatching_Domain;
9062 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
9064 when Pragma_Elaborate => Elaborate : declare
9069 -- Pragma must be in context items list of a compilation unit
9071 if not Is_In_Context_Clause then
9075 -- Must be at least one argument
9077 if Arg_Count = 0 then
9078 Error_Pragma ("pragma% requires at least one argument");
9081 -- In Ada 83 mode, there can be no items following it in the
9082 -- context list except other pragmas and implicit with clauses
9083 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
9084 -- placement rule does not apply.
9086 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
9088 while Present (Citem) loop
9089 if Nkind (Citem) = N_Pragma
9090 or else (Nkind (Citem) = N_With_Clause
9091 and then Implicit_With (Citem))
9096 ("(Ada 83) pragma% must be at end of context clause");
9103 -- Finally, the arguments must all be units mentioned in a with
9104 -- clause in the same context clause. Note we already checked (in
9105 -- Par.Prag) that the arguments are all identifiers or selected
9109 Outer : while Present (Arg) loop
9110 Citem := First (List_Containing (N));
9111 Inner : while Citem /= N loop
9112 if Nkind (Citem) = N_With_Clause
9113 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
9115 Set_Elaborate_Present (Citem, True);
9116 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
9117 Generate_Reference (Entity (Name (Citem)), Citem);
9119 -- With the pragma present, elaboration calls on
9120 -- subprograms from the named unit need no further
9121 -- checks, as long as the pragma appears in the current
9122 -- compilation unit. If the pragma appears in some unit
9123 -- in the context, there might still be a need for an
9124 -- Elaborate_All_Desirable from the current compilation
9125 -- to the named unit, so we keep the check enabled.
9127 if In_Extended_Main_Source_Unit (N) then
9128 Set_Suppress_Elaboration_Warnings
9129 (Entity (Name (Citem)));
9140 ("argument of pragma% is not withed unit", Arg);
9146 -- Give a warning if operating in static mode with -gnatwl
9147 -- (elaboration warnings enabled) switch set.
9149 if Elab_Warnings and not Dynamic_Elaboration_Checks then
9151 ("?l?use of pragma Elaborate may not be safe", N);
9153 ("?l?use pragma Elaborate_All instead if possible", N);
9161 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
9163 when Pragma_Elaborate_All => Elaborate_All : declare
9168 Check_Ada_83_Warning;
9170 -- Pragma must be in context items list of a compilation unit
9172 if not Is_In_Context_Clause then
9176 -- Must be at least one argument
9178 if Arg_Count = 0 then
9179 Error_Pragma ("pragma% requires at least one argument");
9182 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
9183 -- have to appear at the end of the context clause, but may
9184 -- appear mixed in with other items, even in Ada 83 mode.
9186 -- Final check: the arguments must all be units mentioned in
9187 -- a with clause in the same context clause. Note that we
9188 -- already checked (in Par.Prag) that all the arguments are
9189 -- either identifiers or selected components.
9192 Outr : while Present (Arg) loop
9193 Citem := First (List_Containing (N));
9194 Innr : while Citem /= N loop
9195 if Nkind (Citem) = N_With_Clause
9196 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
9198 Set_Elaborate_All_Present (Citem, True);
9199 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
9201 -- Suppress warnings and elaboration checks on the named
9202 -- unit if the pragma is in the current compilation, as
9203 -- for pragma Elaborate.
9205 if In_Extended_Main_Source_Unit (N) then
9206 Set_Suppress_Elaboration_Warnings
9207 (Entity (Name (Citem)));
9216 Set_Error_Posted (N);
9218 ("argument of pragma% is not withed unit", Arg);
9225 --------------------
9226 -- Elaborate_Body --
9227 --------------------
9229 -- pragma Elaborate_Body [( library_unit_NAME )];
9231 when Pragma_Elaborate_Body => Elaborate_Body : declare
9232 Cunit_Node : Node_Id;
9233 Cunit_Ent : Entity_Id;
9236 Check_Ada_83_Warning;
9237 Check_Valid_Library_Unit_Pragma;
9239 if Nkind (N) = N_Null_Statement then
9243 Cunit_Node := Cunit (Current_Sem_Unit);
9244 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
9246 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
9249 Error_Pragma ("pragma% must refer to a spec, not a body");
9251 Set_Body_Required (Cunit_Node, True);
9252 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
9254 -- If we are in dynamic elaboration mode, then we suppress
9255 -- elaboration warnings for the unit, since it is definitely
9256 -- fine NOT to do dynamic checks at the first level (and such
9257 -- checks will be suppressed because no elaboration boolean
9258 -- is created for Elaborate_Body packages).
9260 -- But in the static model of elaboration, Elaborate_Body is
9261 -- definitely NOT good enough to ensure elaboration safety on
9262 -- its own, since the body may WITH other units that are not
9263 -- safe from an elaboration point of view, so a client must
9264 -- still do an Elaborate_All on such units.
9266 -- Debug flag -gnatdD restores the old behavior of 3.13, where
9267 -- Elaborate_Body always suppressed elab warnings.
9269 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
9270 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
9275 ------------------------
9276 -- Elaboration_Checks --
9277 ------------------------
9279 -- pragma Elaboration_Checks (Static | Dynamic);
9281 when Pragma_Elaboration_Checks =>
9283 Check_Arg_Count (1);
9284 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
9285 Dynamic_Elaboration_Checks :=
9286 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
9292 -- pragma Eliminate (
9293 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
9294 -- [,[Entity =>] IDENTIFIER |
9295 -- SELECTED_COMPONENT |
9297 -- [, OVERLOADING_RESOLUTION]);
9299 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
9302 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
9305 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
9307 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
9308 -- Result_Type => result_SUBTYPE_NAME]
9310 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
9311 -- SUBTYPE_NAME ::= STRING_LITERAL
9313 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
9314 -- SOURCE_TRACE ::= STRING_LITERAL
9316 when Pragma_Eliminate => Eliminate : declare
9317 Args : Args_List (1 .. 5);
9318 Names : constant Name_List (1 .. 5) := (
9321 Name_Parameter_Types,
9323 Name_Source_Location);
9325 Unit_Name : Node_Id renames Args (1);
9326 Entity : Node_Id renames Args (2);
9327 Parameter_Types : Node_Id renames Args (3);
9328 Result_Type : Node_Id renames Args (4);
9329 Source_Location : Node_Id renames Args (5);
9333 Check_Valid_Configuration_Pragma;
9334 Gather_Associations (Names, Args);
9336 if No (Unit_Name) then
9337 Error_Pragma ("missing Unit_Name argument for pragma%");
9341 and then (Present (Parameter_Types)
9343 Present (Result_Type)
9345 Present (Source_Location))
9347 Error_Pragma ("missing Entity argument for pragma%");
9350 if (Present (Parameter_Types)
9352 Present (Result_Type))
9354 Present (Source_Location)
9357 ("parameter profile and source location cannot " &
9358 "be used together in pragma%");
9361 Process_Eliminate_Pragma
9370 -----------------------------------
9371 -- Enable_Atomic_Synchronization --
9372 -----------------------------------
9374 -- pragma Enable_Atomic_Synchronization [(Entity)];
9376 when Pragma_Enable_Atomic_Synchronization =>
9377 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
9384 -- [ Convention =>] convention_IDENTIFIER,
9385 -- [ Entity =>] local_NAME
9386 -- [, [External_Name =>] static_string_EXPRESSION ]
9387 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9389 when Pragma_Export => Export : declare
9393 pragma Warnings (Off, C);
9396 Check_Ada_83_Warning;
9403 Check_At_Least_N_Arguments (2);
9405 Check_At_Most_N_Arguments (4);
9406 Process_Convention (C, Def_Id);
9408 if Ekind (Def_Id) /= E_Constant then
9409 Note_Possible_Modification
9410 (Get_Pragma_Arg (Arg2), Sure => False);
9413 Process_Interface_Name (Def_Id, Arg3, Arg4);
9414 Set_Exported (Def_Id, Arg2);
9416 -- If the entity is a deferred constant, propagate the information
9417 -- to the full view, because gigi elaborates the full view only.
9419 if Ekind (Def_Id) = E_Constant
9420 and then Present (Full_View (Def_Id))
9423 Id2 : constant Entity_Id := Full_View (Def_Id);
9425 Set_Is_Exported (Id2, Is_Exported (Def_Id));
9426 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
9427 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
9432 ----------------------
9433 -- Export_Exception --
9434 ----------------------
9436 -- pragma Export_Exception (
9437 -- [Internal =>] LOCAL_NAME
9438 -- [, [External =>] EXTERNAL_SYMBOL]
9439 -- [, [Form =>] Ada | VMS]
9440 -- [, [Code =>] static_integer_EXPRESSION]);
9442 when Pragma_Export_Exception => Export_Exception : declare
9443 Args : Args_List (1 .. 4);
9444 Names : constant Name_List (1 .. 4) := (
9450 Internal : Node_Id renames Args (1);
9451 External : Node_Id renames Args (2);
9452 Form : Node_Id renames Args (3);
9453 Code : Node_Id renames Args (4);
9458 if Inside_A_Generic then
9459 Error_Pragma ("pragma% cannot be used for generic entities");
9462 Gather_Associations (Names, Args);
9463 Process_Extended_Import_Export_Exception_Pragma (
9464 Arg_Internal => Internal,
9465 Arg_External => External,
9469 if not Is_VMS_Exception (Entity (Internal)) then
9470 Set_Exported (Entity (Internal), Internal);
9472 end Export_Exception;
9474 ---------------------
9475 -- Export_Function --
9476 ---------------------
9478 -- pragma Export_Function (
9479 -- [Internal =>] LOCAL_NAME
9480 -- [, [External =>] EXTERNAL_SYMBOL]
9481 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9482 -- [, [Result_Type =>] TYPE_DESIGNATOR]
9483 -- [, [Mechanism =>] MECHANISM]
9484 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
9486 -- EXTERNAL_SYMBOL ::=
9488 -- | static_string_EXPRESSION
9490 -- PARAMETER_TYPES ::=
9492 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9494 -- TYPE_DESIGNATOR ::=
9496 -- | subtype_Name ' Access
9500 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9502 -- MECHANISM_ASSOCIATION ::=
9503 -- [formal_parameter_NAME =>] MECHANISM_NAME
9505 -- MECHANISM_NAME ::=
9508 -- | Descriptor [([Class =>] CLASS_NAME)]
9510 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9512 when Pragma_Export_Function => Export_Function : declare
9513 Args : Args_List (1 .. 6);
9514 Names : constant Name_List (1 .. 6) := (
9517 Name_Parameter_Types,
9520 Name_Result_Mechanism);
9522 Internal : Node_Id renames Args (1);
9523 External : Node_Id renames Args (2);
9524 Parameter_Types : Node_Id renames Args (3);
9525 Result_Type : Node_Id renames Args (4);
9526 Mechanism : Node_Id renames Args (5);
9527 Result_Mechanism : Node_Id renames Args (6);
9531 Gather_Associations (Names, Args);
9532 Process_Extended_Import_Export_Subprogram_Pragma (
9533 Arg_Internal => Internal,
9534 Arg_External => External,
9535 Arg_Parameter_Types => Parameter_Types,
9536 Arg_Result_Type => Result_Type,
9537 Arg_Mechanism => Mechanism,
9538 Arg_Result_Mechanism => Result_Mechanism);
9539 end Export_Function;
9545 -- pragma Export_Object (
9546 -- [Internal =>] LOCAL_NAME
9547 -- [, [External =>] EXTERNAL_SYMBOL]
9548 -- [, [Size =>] EXTERNAL_SYMBOL]);
9550 -- EXTERNAL_SYMBOL ::=
9552 -- | static_string_EXPRESSION
9554 -- PARAMETER_TYPES ::=
9556 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9558 -- TYPE_DESIGNATOR ::=
9560 -- | subtype_Name ' Access
9564 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9566 -- MECHANISM_ASSOCIATION ::=
9567 -- [formal_parameter_NAME =>] MECHANISM_NAME
9569 -- MECHANISM_NAME ::=
9572 -- | Descriptor [([Class =>] CLASS_NAME)]
9574 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9576 when Pragma_Export_Object => Export_Object : declare
9577 Args : Args_List (1 .. 3);
9578 Names : constant Name_List (1 .. 3) := (
9583 Internal : Node_Id renames Args (1);
9584 External : Node_Id renames Args (2);
9585 Size : Node_Id renames Args (3);
9589 Gather_Associations (Names, Args);
9590 Process_Extended_Import_Export_Object_Pragma (
9591 Arg_Internal => Internal,
9592 Arg_External => External,
9596 ----------------------
9597 -- Export_Procedure --
9598 ----------------------
9600 -- pragma Export_Procedure (
9601 -- [Internal =>] LOCAL_NAME
9602 -- [, [External =>] EXTERNAL_SYMBOL]
9603 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9604 -- [, [Mechanism =>] MECHANISM]);
9606 -- EXTERNAL_SYMBOL ::=
9608 -- | static_string_EXPRESSION
9610 -- PARAMETER_TYPES ::=
9612 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9614 -- TYPE_DESIGNATOR ::=
9616 -- | subtype_Name ' Access
9620 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9622 -- MECHANISM_ASSOCIATION ::=
9623 -- [formal_parameter_NAME =>] MECHANISM_NAME
9625 -- MECHANISM_NAME ::=
9628 -- | Descriptor [([Class =>] CLASS_NAME)]
9630 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9632 when Pragma_Export_Procedure => Export_Procedure : declare
9633 Args : Args_List (1 .. 4);
9634 Names : constant Name_List (1 .. 4) := (
9637 Name_Parameter_Types,
9640 Internal : Node_Id renames Args (1);
9641 External : Node_Id renames Args (2);
9642 Parameter_Types : Node_Id renames Args (3);
9643 Mechanism : Node_Id renames Args (4);
9647 Gather_Associations (Names, Args);
9648 Process_Extended_Import_Export_Subprogram_Pragma (
9649 Arg_Internal => Internal,
9650 Arg_External => External,
9651 Arg_Parameter_Types => Parameter_Types,
9652 Arg_Mechanism => Mechanism);
9653 end Export_Procedure;
9659 -- pragma Export_Value (
9660 -- [Value =>] static_integer_EXPRESSION,
9661 -- [Link_Name =>] static_string_EXPRESSION);
9663 when Pragma_Export_Value =>
9665 Check_Arg_Order ((Name_Value, Name_Link_Name));
9666 Check_Arg_Count (2);
9668 Check_Optional_Identifier (Arg1, Name_Value);
9669 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9671 Check_Optional_Identifier (Arg2, Name_Link_Name);
9672 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9674 -----------------------------
9675 -- Export_Valued_Procedure --
9676 -----------------------------
9678 -- pragma Export_Valued_Procedure (
9679 -- [Internal =>] LOCAL_NAME
9680 -- [, [External =>] EXTERNAL_SYMBOL,]
9681 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9682 -- [, [Mechanism =>] MECHANISM]);
9684 -- EXTERNAL_SYMBOL ::=
9686 -- | static_string_EXPRESSION
9688 -- PARAMETER_TYPES ::=
9690 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9692 -- TYPE_DESIGNATOR ::=
9694 -- | subtype_Name ' Access
9698 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9700 -- MECHANISM_ASSOCIATION ::=
9701 -- [formal_parameter_NAME =>] MECHANISM_NAME
9703 -- MECHANISM_NAME ::=
9706 -- | Descriptor [([Class =>] CLASS_NAME)]
9708 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9710 when Pragma_Export_Valued_Procedure =>
9711 Export_Valued_Procedure : declare
9712 Args : Args_List (1 .. 4);
9713 Names : constant Name_List (1 .. 4) := (
9716 Name_Parameter_Types,
9719 Internal : Node_Id renames Args (1);
9720 External : Node_Id renames Args (2);
9721 Parameter_Types : Node_Id renames Args (3);
9722 Mechanism : Node_Id renames Args (4);
9726 Gather_Associations (Names, Args);
9727 Process_Extended_Import_Export_Subprogram_Pragma (
9728 Arg_Internal => Internal,
9729 Arg_External => External,
9730 Arg_Parameter_Types => Parameter_Types,
9731 Arg_Mechanism => Mechanism);
9732 end Export_Valued_Procedure;
9738 -- pragma Extend_System ([Name =>] Identifier);
9740 when Pragma_Extend_System => Extend_System : declare
9743 Check_Valid_Configuration_Pragma;
9744 Check_Arg_Count (1);
9745 Check_Optional_Identifier (Arg1, Name_Name);
9746 Check_Arg_Is_Identifier (Arg1);
9748 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
9751 and then Name_Buffer (1 .. 4) = "aux_"
9753 if Present (System_Extend_Pragma_Arg) then
9754 if Chars (Get_Pragma_Arg (Arg1)) =
9755 Chars (Expression (System_Extend_Pragma_Arg))
9759 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
9760 Error_Pragma ("pragma% conflicts with that #");
9764 System_Extend_Pragma_Arg := Arg1;
9766 if not GNAT_Mode then
9767 System_Extend_Unit := Arg1;
9771 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
9775 ------------------------
9776 -- Extensions_Allowed --
9777 ------------------------
9779 -- pragma Extensions_Allowed (ON | OFF);
9781 when Pragma_Extensions_Allowed =>
9783 Check_Arg_Count (1);
9784 Check_No_Identifiers;
9785 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9787 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
9788 Extensions_Allowed := True;
9789 Ada_Version := Ada_Version_Type'Last;
9792 Extensions_Allowed := False;
9793 Ada_Version := Ada_Version_Explicit;
9800 -- pragma External (
9801 -- [ Convention =>] convention_IDENTIFIER,
9802 -- [ Entity =>] local_NAME
9803 -- [, [External_Name =>] static_string_EXPRESSION ]
9804 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9806 when Pragma_External => External : declare
9810 pragma Warnings (Off, C);
9819 Check_At_Least_N_Arguments (2);
9820 Check_At_Most_N_Arguments (4);
9821 Process_Convention (C, Def_Id);
9822 Note_Possible_Modification
9823 (Get_Pragma_Arg (Arg2), Sure => False);
9824 Process_Interface_Name (Def_Id, Arg3, Arg4);
9825 Set_Exported (Def_Id, Arg2);
9828 --------------------------
9829 -- External_Name_Casing --
9830 --------------------------
9832 -- pragma External_Name_Casing (
9833 -- UPPERCASE | LOWERCASE
9834 -- [, AS_IS | UPPERCASE | LOWERCASE]);
9836 when Pragma_External_Name_Casing => External_Name_Casing : declare
9839 Check_No_Identifiers;
9841 if Arg_Count = 2 then
9843 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
9845 case Chars (Get_Pragma_Arg (Arg2)) is
9847 Opt.External_Name_Exp_Casing := As_Is;
9849 when Name_Uppercase =>
9850 Opt.External_Name_Exp_Casing := Uppercase;
9852 when Name_Lowercase =>
9853 Opt.External_Name_Exp_Casing := Lowercase;
9860 Check_Arg_Count (1);
9863 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
9865 case Chars (Get_Pragma_Arg (Arg1)) is
9866 when Name_Uppercase =>
9867 Opt.External_Name_Imp_Casing := Uppercase;
9869 when Name_Lowercase =>
9870 Opt.External_Name_Imp_Casing := Lowercase;
9875 end External_Name_Casing;
9877 --------------------------
9878 -- Favor_Top_Level --
9879 --------------------------
9881 -- pragma Favor_Top_Level (type_NAME);
9883 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
9884 Named_Entity : Entity_Id;
9888 Check_No_Identifiers;
9889 Check_Arg_Count (1);
9890 Check_Arg_Is_Local_Name (Arg1);
9891 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
9893 -- If it's an access-to-subprogram type (in particular, not a
9894 -- subtype), set the flag on that type.
9896 if Is_Access_Subprogram_Type (Named_Entity) then
9897 Set_Can_Use_Internal_Rep (Named_Entity, False);
9899 -- Otherwise it's an error (name denotes the wrong sort of entity)
9903 ("access-to-subprogram type expected",
9904 Get_Pragma_Arg (Arg1));
9906 end Favor_Top_Level;
9912 -- pragma Fast_Math;
9914 when Pragma_Fast_Math =>
9916 Check_No_Identifiers;
9917 Check_Valid_Configuration_Pragma;
9920 ---------------------------
9921 -- Finalize_Storage_Only --
9922 ---------------------------
9924 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9926 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9927 Assoc : constant Node_Id := Arg1;
9928 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9933 Check_No_Identifiers;
9934 Check_Arg_Count (1);
9935 Check_Arg_Is_Local_Name (Arg1);
9937 Find_Type (Type_Id);
9938 Typ := Entity (Type_Id);
9941 or else Rep_Item_Too_Early (Typ, N)
9945 Typ := Underlying_Type (Typ);
9948 if not Is_Controlled (Typ) then
9949 Error_Pragma ("pragma% must specify controlled type");
9952 Check_First_Subtype (Arg1);
9954 if Finalize_Storage_Only (Typ) then
9955 Error_Pragma ("duplicate pragma%, only one allowed");
9957 elsif not Rep_Item_Too_Late (Typ, N) then
9958 Set_Finalize_Storage_Only (Base_Type (Typ), True);
9960 end Finalize_Storage;
9962 --------------------------
9963 -- Float_Representation --
9964 --------------------------
9966 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9968 -- FLOAT_REP ::= VAX_Float | IEEE_Float
9970 when Pragma_Float_Representation => Float_Representation : declare
9978 if Arg_Count = 1 then
9979 Check_Valid_Configuration_Pragma;
9981 Check_Arg_Count (2);
9982 Check_Optional_Identifier (Arg2, Name_Entity);
9983 Check_Arg_Is_Local_Name (Arg2);
9986 Check_No_Identifier (Arg1);
9987 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9989 if not OpenVMS_On_Target then
9990 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9992 ("??pragma% ignored (applies only to Open'V'M'S)");
9998 -- One argument case
10000 if Arg_Count = 1 then
10001 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
10002 if Opt.Float_Format = 'I' then
10003 Error_Pragma ("'I'E'E'E format previously specified");
10006 Opt.Float_Format := 'V';
10009 if Opt.Float_Format = 'V' then
10010 Error_Pragma ("'V'A'X format previously specified");
10013 Opt.Float_Format := 'I';
10016 Set_Standard_Fpt_Formats;
10018 -- Two argument case
10021 Argx := Get_Pragma_Arg (Arg2);
10023 if not Is_Entity_Name (Argx)
10024 or else not Is_Floating_Point_Type (Entity (Argx))
10027 ("second argument of% pragma must be floating-point type",
10031 Ent := Entity (Argx);
10032 Digs := UI_To_Int (Digits_Value (Ent));
10034 -- Two arguments, VAX_Float case
10036 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
10038 when 6 => Set_F_Float (Ent);
10039 when 9 => Set_D_Float (Ent);
10040 when 15 => Set_G_Float (Ent);
10044 ("wrong digits value, must be 6,9 or 15", Arg2);
10047 -- Two arguments, IEEE_Float case
10051 when 6 => Set_IEEE_Short (Ent);
10052 when 15 => Set_IEEE_Long (Ent);
10056 ("wrong digits value, must be 6 or 15", Arg2);
10060 end Float_Representation;
10066 -- pragma Global (GLOBAL_SPECIFICATION)
10068 -- GLOBAL_SPECIFICATION ::= MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
10071 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
10072 -- MODE_SELECTOR ::= Input | Output | In_Out | Contract_In
10073 -- GLOBAL_LIST ::= GLOBAL_ITEM
10074 -- | (GLOBAL_ITEM {, GLOBAL_ITEM})
10075 -- GLOBAL_ITEM ::= NAME
10077 when Pragma_Global => Global : declare
10078 Subp_Id : Entity_Id;
10080 Seen : Elist_Id := No_Elist;
10081 -- A list containing the entities of all the items processed so
10082 -- far. It plays a role in detecting distinct entities.
10084 -- Flags used to verify the consistency of modes
10086 Contract_Seen : Boolean := False;
10087 In_Out_Seen : Boolean := False;
10088 Input_Seen : Boolean := False;
10089 Output_Seen : Boolean := False;
10091 procedure Analyze_Global_List
10093 Global_Mode : Name_Id := Name_Input);
10094 -- Verify the legality of a single global list declaration.
10095 -- Global_Mode denotes the current mode in effect.
10097 -------------------------
10098 -- Analyze_Global_List --
10099 -------------------------
10101 procedure Analyze_Global_List
10103 Global_Mode : Name_Id := Name_Input)
10105 procedure Analyze_Global_Item
10107 Global_Mode : Name_Id);
10108 -- Verify the legality of a single global item declaration.
10109 -- Global_Mode denotes the current mode in effect.
10111 procedure Check_Duplicate_Mode
10113 Status : in out Boolean);
10114 -- Flag Status denotes whether a particular mode has been seen
10115 -- while processing a global list. This routine verifies that
10116 -- Mode is not a duplicate mode and sets the flag Status.
10118 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
10119 -- Mode denotes either In_Out or Output. Depending on the kind
10120 -- of the related subprogram, emit an error if those two modes
10121 -- apply to a function.
10123 -------------------------
10124 -- Analyze_Global_Item --
10125 -------------------------
10127 procedure Analyze_Global_Item
10129 Global_Mode : Name_Id)
10131 function Is_Duplicate_Item (Id : Entity_Id) return Boolean;
10132 -- Determine whether Id has already been processed
10134 -----------------------
10135 -- Is_Duplicate_Item --
10136 -----------------------
10138 function Is_Duplicate_Item (Id : Entity_Id) return Boolean is
10139 Item_Elmt : Elmt_Id;
10142 if Present (Seen) then
10143 Item_Elmt := First_Elmt (Seen);
10144 while Present (Item_Elmt) loop
10145 if Node (Item_Elmt) = Id then
10149 Next_Elmt (Item_Elmt);
10154 end Is_Duplicate_Item;
10156 -- Local declarations
10160 -- Start of processing for Analyze_Global_Item
10163 -- Detect one of the following cases
10165 -- with Global => (null, Name)
10166 -- with Global => (Name_1, null, Name_2)
10167 -- with Global => (Name, null)
10169 if Nkind (Item) = N_Null then
10171 ("cannot mix null and non-null global items", Item);
10177 if Is_Entity_Name (Item) then
10178 Id := Entity (Item);
10180 -- A global item cannot reference a formal parameter. Do
10181 -- this check first to provide a better error diagnostic.
10183 if Is_Formal (Id) then
10185 ("global item cannot reference formal parameter",
10189 -- The only legal references are those to abstract states
10192 elsif not Ekind_In (Entity (Item), E_Abstract_State,
10196 ("global item must denote variable or state", Item);
10200 -- Some form of illegal construct masquerading as a name
10204 ("global item must denote variable or state", Item);
10208 -- The same entity might be referenced through various way.
10209 -- Check the entity of the item rather than the item itself.
10211 if Is_Duplicate_Item (Id) then
10212 Error_Msg_N ("duplicate global item", Item);
10214 -- Add the entity of the current item to the list of
10215 -- processed items.
10219 Seen := New_Elmt_List;
10222 Append_Elmt (Id, Seen);
10225 if Ekind (Id) = E_Abstract_State
10226 and then Is_Volatile_State (Id)
10228 -- A global item of mode In_Out or Output cannot denote a
10229 -- volatile Input state.
10231 if Is_Input_State (Id)
10232 and then (Global_Mode = Name_In_Out
10234 Global_Mode = Name_Output)
10237 ("global item of mode In_Out or Output cannot " &
10238 "reference Volatile Input state", Item);
10240 -- A global item of mode In_Out or Input cannot reference
10241 -- a volatile Output state.
10243 elsif Is_Output_State (Id)
10244 and then (Global_Mode = Name_In_Out
10246 Global_Mode = Name_Input)
10249 ("global item of mode In_Out or Input cannot "
10250 & "reference Volatile Output state", Item);
10253 end Analyze_Global_Item;
10255 --------------------------
10256 -- Check_Duplicate_Mode --
10257 --------------------------
10259 procedure Check_Duplicate_Mode
10261 Status : in out Boolean)
10265 Error_Msg_N ("duplicate global mode", Mode);
10269 end Check_Duplicate_Mode;
10271 ----------------------------------------
10272 -- Check_Mode_Restriction_In_Function --
10273 ----------------------------------------
10275 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
10277 if Ekind (Subp_Id) = E_Function then
10278 Error_Msg_Name_1 := Chars (Mode);
10280 ("global mode % not applicable to functions", Mode);
10282 end Check_Mode_Restriction_In_Function;
10290 -- Start of processing for Analyze_Global_List
10293 -- Single global item declaration
10295 if Nkind_In (List, N_Identifier, N_Selected_Component) then
10296 Analyze_Global_Item (List, Global_Mode);
10298 -- Simple global list or moded global list declaration
10300 elsif Nkind (List) = N_Aggregate then
10302 -- The declaration of a simple global list appear as a
10303 -- collection of expressions.
10305 if Present (Expressions (List)) then
10306 if Present (Component_Associations (List)) then
10308 ("cannot mix moded and non-moded global lists",
10312 Item := First (Expressions (List));
10313 while Present (Item) loop
10314 Analyze_Global_Item (Item, Global_Mode);
10319 -- The declaration of a moded global list appears as a
10320 -- collection of component associations where individual
10321 -- choices denote modes.
10323 elsif Present (Component_Associations (List)) then
10324 if Present (Expressions (List)) then
10326 ("cannot mix moded and non-moded global lists",
10330 Assoc := First (Component_Associations (List));
10331 while Present (Assoc) loop
10332 Mode := First (Choices (Assoc));
10334 if Nkind (Mode) = N_Identifier then
10335 if Chars (Mode) = Name_Contract_In then
10336 Check_Duplicate_Mode (Mode, Contract_Seen);
10338 elsif Chars (Mode) = Name_In_Out then
10339 Check_Duplicate_Mode (Mode, In_Out_Seen);
10340 Check_Mode_Restriction_In_Function (Mode);
10342 elsif Chars (Mode) = Name_Input then
10343 Check_Duplicate_Mode (Mode, Input_Seen);
10345 elsif Chars (Mode) = Name_Output then
10346 Check_Duplicate_Mode (Mode, Output_Seen);
10347 Check_Mode_Restriction_In_Function (Mode);
10350 Error_Msg_N ("invalid mode selector", Mode);
10354 Error_Msg_N ("invalid mode selector", Mode);
10357 -- Items in a moded list appear as a collection of
10358 -- expressions. Reuse the existing machinery to
10361 Analyze_Global_List
10362 (List => Expression (Assoc),
10363 Global_Mode => Chars (Mode));
10368 -- Something went horribly wrong, we have a malformed tree
10371 raise Program_Error;
10374 -- Any other attempt to declare a global item is erroneous
10377 Error_Msg_N ("malformed global list declaration", List);
10379 end Analyze_Global_List;
10386 -- Start of processing for Global
10391 Check_Arg_Count (1);
10393 -- Ensure the proper placement of the pragma. Global must be
10394 -- associated with a subprogram declaration.
10396 Subp := Parent (Corresponding_Aspect (N));
10398 if Nkind (Subp) /= N_Subprogram_Declaration then
10403 Subp_Id := Defining_Unit_Name (Specification (Subp));
10404 List := Expression (Arg1);
10406 -- There is nothing to be done for a null global list
10408 if Nkind (List) = N_Null then
10411 -- Analyze the various forms of global lists and items. Note that
10412 -- some of these may be malformed in which case the analysis emits
10416 -- Ensure that the formal parameters are visible when
10417 -- processing an item. This falls out of the general rule of
10418 -- aspects pertaining to subprogram declarations.
10420 Push_Scope (Subp_Id);
10421 Install_Formals (Subp_Id);
10423 Analyze_Global_List (List);
10433 -- pragma Ident (static_string_EXPRESSION)
10435 -- Note: pragma Comment shares this processing. Pragma Comment is
10436 -- identical to Ident, except that the restriction of the argument to
10437 -- 31 characters and the placement restrictions are not enforced for
10440 when Pragma_Ident | Pragma_Comment => Ident : declare
10445 Check_Arg_Count (1);
10446 Check_No_Identifiers;
10447 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10450 -- For pragma Ident, preserve DEC compatibility by requiring the
10451 -- pragma to appear in a declarative part or package spec.
10453 if Prag_Id = Pragma_Ident then
10454 Check_Is_In_Decl_Part_Or_Package_Spec;
10457 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
10464 GP := Parent (Parent (N));
10466 if Nkind_In (GP, N_Package_Declaration,
10467 N_Generic_Package_Declaration)
10472 -- If we have a compilation unit, then record the ident value,
10473 -- checking for improper duplication.
10475 if Nkind (GP) = N_Compilation_Unit then
10476 CS := Ident_String (Current_Sem_Unit);
10478 if Present (CS) then
10480 -- For Ident, we do not permit multiple instances
10482 if Prag_Id = Pragma_Ident then
10483 Error_Pragma ("duplicate% pragma not permitted");
10485 -- For Comment, we concatenate the string, unless we want
10486 -- to preserve the tree structure for ASIS.
10488 elsif not ASIS_Mode then
10489 Start_String (Strval (CS));
10490 Store_String_Char (' ');
10491 Store_String_Chars (Strval (Str));
10492 Set_Strval (CS, End_String);
10496 -- In VMS, the effect of IDENT is achieved by passing
10497 -- --identification=name as a --for-linker switch.
10499 if OpenVMS_On_Target then
10502 ("--for-linker=--identification=");
10503 String_To_Name_Buffer (Strval (Str));
10504 Store_String_Chars (Name_Buffer (1 .. Name_Len));
10506 -- Only the last processed IDENT is saved. The main
10507 -- purpose is so an IDENT associated with a main
10508 -- procedure will be used in preference to an IDENT
10509 -- associated with a with'd package.
10511 Replace_Linker_Option_String
10512 (End_String, "--for-linker=--identification=");
10515 Set_Ident_String (Current_Sem_Unit, Str);
10518 -- For subunits, we just ignore the Ident, since in GNAT these
10519 -- are not separate object files, and hence not separate units
10520 -- in the unit table.
10522 elsif Nkind (GP) = N_Subunit then
10525 -- Otherwise we have a misplaced pragma Ident, but we ignore
10526 -- this if we are in an instantiation, since it comes from
10527 -- a generic, and has no relevance to the instantiation.
10529 elsif Prag_Id = Pragma_Ident then
10530 if Instantiation_Location (Loc) = No_Location then
10531 Error_Pragma ("pragma% only allowed at outer level");
10537 ----------------------------
10538 -- Implementation_Defined --
10539 ----------------------------
10541 -- pragma Implementation_Defined (local_NAME);
10543 -- Marks previously declared entity as implementation defined. For
10544 -- an overloaded entity, applies to the most recent homonym.
10546 -- pragma Implementation_Defined;
10548 -- The form with no arguments appears anywhere within a scope, most
10549 -- typically a package spec, and indicates that all entities that are
10550 -- defined within the package spec are Implementation_Defined.
10552 when Pragma_Implementation_Defined => Implementation_Defined : declare
10556 Check_No_Identifiers;
10558 -- Form with no arguments
10560 if Arg_Count = 0 then
10561 Set_Is_Implementation_Defined (Current_Scope);
10563 -- Form with one argument
10566 Check_Arg_Count (1);
10567 Check_Arg_Is_Local_Name (Arg1);
10568 Ent := Entity (Get_Pragma_Arg (Arg1));
10569 Set_Is_Implementation_Defined (Ent);
10571 end Implementation_Defined;
10577 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
10579 -- IMPLEMENTATION_KIND ::=
10580 -- By_Entry | By_Protected_Procedure | By_Any | Optional
10582 -- "By_Any" and "Optional" are treated as synonyms in order to
10583 -- support Ada 2012 aspect Synchronization.
10585 when Pragma_Implemented => Implemented : declare
10586 Proc_Id : Entity_Id;
10591 Check_Arg_Count (2);
10592 Check_No_Identifiers;
10593 Check_Arg_Is_Identifier (Arg1);
10594 Check_Arg_Is_Local_Name (Arg1);
10595 Check_Arg_Is_One_Of (Arg2,
10598 Name_By_Protected_Procedure,
10601 -- Extract the name of the local procedure
10603 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
10605 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
10606 -- primitive procedure of a synchronized tagged type.
10608 if Ekind (Proc_Id) = E_Procedure
10609 and then Is_Primitive (Proc_Id)
10610 and then Present (First_Formal (Proc_Id))
10612 Typ := Etype (First_Formal (Proc_Id));
10614 if Is_Tagged_Type (Typ)
10617 -- Check for a protected, a synchronized or a task interface
10619 ((Is_Interface (Typ)
10620 and then Is_Synchronized_Interface (Typ))
10622 -- Check for a protected type or a task type that implements
10626 (Is_Concurrent_Record_Type (Typ)
10627 and then Present (Interfaces (Typ)))
10629 -- Check for a private record extension with keyword
10633 (Ekind_In (Typ, E_Record_Type_With_Private,
10634 E_Record_Subtype_With_Private)
10635 and then Synchronized_Present (Parent (Typ))))
10640 ("controlling formal must be of synchronized " &
10641 "tagged type", Arg1);
10645 -- Procedures declared inside a protected type must be accepted
10647 elsif Ekind (Proc_Id) = E_Procedure
10648 and then Is_Protected_Type (Scope (Proc_Id))
10652 -- The first argument is not a primitive procedure
10656 ("pragma % must be applied to a primitive procedure", Arg1);
10660 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
10661 -- By_Protected_Procedure to the primitive procedure of a task
10664 if Chars (Arg2) = Name_By_Protected_Procedure
10665 and then Is_Interface (Typ)
10666 and then Is_Task_Interface (Typ)
10669 ("implementation kind By_Protected_Procedure cannot be " &
10670 "applied to a task interface primitive", Arg2);
10674 Record_Rep_Item (Proc_Id, N);
10677 ----------------------
10678 -- Implicit_Packing --
10679 ----------------------
10681 -- pragma Implicit_Packing;
10683 when Pragma_Implicit_Packing =>
10685 Check_Arg_Count (0);
10686 Implicit_Packing := True;
10693 -- [Convention =>] convention_IDENTIFIER,
10694 -- [Entity =>] local_NAME
10695 -- [, [External_Name =>] static_string_EXPRESSION ]
10696 -- [, [Link_Name =>] static_string_EXPRESSION ]);
10698 when Pragma_Import =>
10699 Check_Ada_83_Warning;
10703 Name_External_Name,
10706 Check_At_Least_N_Arguments (2);
10707 Check_At_Most_N_Arguments (4);
10708 Process_Import_Or_Interface;
10710 ----------------------
10711 -- Import_Exception --
10712 ----------------------
10714 -- pragma Import_Exception (
10715 -- [Internal =>] LOCAL_NAME
10716 -- [, [External =>] EXTERNAL_SYMBOL]
10717 -- [, [Form =>] Ada | VMS]
10718 -- [, [Code =>] static_integer_EXPRESSION]);
10720 when Pragma_Import_Exception => Import_Exception : declare
10721 Args : Args_List (1 .. 4);
10722 Names : constant Name_List (1 .. 4) := (
10728 Internal : Node_Id renames Args (1);
10729 External : Node_Id renames Args (2);
10730 Form : Node_Id renames Args (3);
10731 Code : Node_Id renames Args (4);
10735 Gather_Associations (Names, Args);
10737 if Present (External) and then Present (Code) then
10739 ("cannot give both External and Code options for pragma%");
10742 Process_Extended_Import_Export_Exception_Pragma (
10743 Arg_Internal => Internal,
10744 Arg_External => External,
10748 if not Is_VMS_Exception (Entity (Internal)) then
10749 Set_Imported (Entity (Internal));
10751 end Import_Exception;
10753 ---------------------
10754 -- Import_Function --
10755 ---------------------
10757 -- pragma Import_Function (
10758 -- [Internal =>] LOCAL_NAME,
10759 -- [, [External =>] EXTERNAL_SYMBOL]
10760 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10761 -- [, [Result_Type =>] SUBTYPE_MARK]
10762 -- [, [Mechanism =>] MECHANISM]
10763 -- [, [Result_Mechanism =>] MECHANISM_NAME]
10764 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10766 -- EXTERNAL_SYMBOL ::=
10768 -- | static_string_EXPRESSION
10770 -- PARAMETER_TYPES ::=
10772 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10774 -- TYPE_DESIGNATOR ::=
10776 -- | subtype_Name ' Access
10780 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10782 -- MECHANISM_ASSOCIATION ::=
10783 -- [formal_parameter_NAME =>] MECHANISM_NAME
10785 -- MECHANISM_NAME ::=
10788 -- | Descriptor [([Class =>] CLASS_NAME)]
10790 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10792 when Pragma_Import_Function => Import_Function : declare
10793 Args : Args_List (1 .. 7);
10794 Names : constant Name_List (1 .. 7) := (
10797 Name_Parameter_Types,
10800 Name_Result_Mechanism,
10801 Name_First_Optional_Parameter);
10803 Internal : Node_Id renames Args (1);
10804 External : Node_Id renames Args (2);
10805 Parameter_Types : Node_Id renames Args (3);
10806 Result_Type : Node_Id renames Args (4);
10807 Mechanism : Node_Id renames Args (5);
10808 Result_Mechanism : Node_Id renames Args (6);
10809 First_Optional_Parameter : Node_Id renames Args (7);
10813 Gather_Associations (Names, Args);
10814 Process_Extended_Import_Export_Subprogram_Pragma (
10815 Arg_Internal => Internal,
10816 Arg_External => External,
10817 Arg_Parameter_Types => Parameter_Types,
10818 Arg_Result_Type => Result_Type,
10819 Arg_Mechanism => Mechanism,
10820 Arg_Result_Mechanism => Result_Mechanism,
10821 Arg_First_Optional_Parameter => First_Optional_Parameter);
10822 end Import_Function;
10824 -------------------
10825 -- Import_Object --
10826 -------------------
10828 -- pragma Import_Object (
10829 -- [Internal =>] LOCAL_NAME
10830 -- [, [External =>] EXTERNAL_SYMBOL]
10831 -- [, [Size =>] EXTERNAL_SYMBOL]);
10833 -- EXTERNAL_SYMBOL ::=
10835 -- | static_string_EXPRESSION
10837 when Pragma_Import_Object => Import_Object : declare
10838 Args : Args_List (1 .. 3);
10839 Names : constant Name_List (1 .. 3) := (
10844 Internal : Node_Id renames Args (1);
10845 External : Node_Id renames Args (2);
10846 Size : Node_Id renames Args (3);
10850 Gather_Associations (Names, Args);
10851 Process_Extended_Import_Export_Object_Pragma (
10852 Arg_Internal => Internal,
10853 Arg_External => External,
10857 ----------------------
10858 -- Import_Procedure --
10859 ----------------------
10861 -- pragma Import_Procedure (
10862 -- [Internal =>] LOCAL_NAME
10863 -- [, [External =>] EXTERNAL_SYMBOL]
10864 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10865 -- [, [Mechanism =>] MECHANISM]
10866 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10868 -- EXTERNAL_SYMBOL ::=
10870 -- | static_string_EXPRESSION
10872 -- PARAMETER_TYPES ::=
10874 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10876 -- TYPE_DESIGNATOR ::=
10878 -- | subtype_Name ' Access
10882 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10884 -- MECHANISM_ASSOCIATION ::=
10885 -- [formal_parameter_NAME =>] MECHANISM_NAME
10887 -- MECHANISM_NAME ::=
10890 -- | Descriptor [([Class =>] CLASS_NAME)]
10892 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10894 when Pragma_Import_Procedure => Import_Procedure : declare
10895 Args : Args_List (1 .. 5);
10896 Names : constant Name_List (1 .. 5) := (
10899 Name_Parameter_Types,
10901 Name_First_Optional_Parameter);
10903 Internal : Node_Id renames Args (1);
10904 External : Node_Id renames Args (2);
10905 Parameter_Types : Node_Id renames Args (3);
10906 Mechanism : Node_Id renames Args (4);
10907 First_Optional_Parameter : Node_Id renames Args (5);
10911 Gather_Associations (Names, Args);
10912 Process_Extended_Import_Export_Subprogram_Pragma (
10913 Arg_Internal => Internal,
10914 Arg_External => External,
10915 Arg_Parameter_Types => Parameter_Types,
10916 Arg_Mechanism => Mechanism,
10917 Arg_First_Optional_Parameter => First_Optional_Parameter);
10918 end Import_Procedure;
10920 -----------------------------
10921 -- Import_Valued_Procedure --
10922 -----------------------------
10924 -- pragma Import_Valued_Procedure (
10925 -- [Internal =>] LOCAL_NAME
10926 -- [, [External =>] EXTERNAL_SYMBOL]
10927 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10928 -- [, [Mechanism =>] MECHANISM]
10929 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10931 -- EXTERNAL_SYMBOL ::=
10933 -- | static_string_EXPRESSION
10935 -- PARAMETER_TYPES ::=
10937 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10939 -- TYPE_DESIGNATOR ::=
10941 -- | subtype_Name ' Access
10945 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10947 -- MECHANISM_ASSOCIATION ::=
10948 -- [formal_parameter_NAME =>] MECHANISM_NAME
10950 -- MECHANISM_NAME ::=
10953 -- | Descriptor [([Class =>] CLASS_NAME)]
10955 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10957 when Pragma_Import_Valued_Procedure =>
10958 Import_Valued_Procedure : declare
10959 Args : Args_List (1 .. 5);
10960 Names : constant Name_List (1 .. 5) := (
10963 Name_Parameter_Types,
10965 Name_First_Optional_Parameter);
10967 Internal : Node_Id renames Args (1);
10968 External : Node_Id renames Args (2);
10969 Parameter_Types : Node_Id renames Args (3);
10970 Mechanism : Node_Id renames Args (4);
10971 First_Optional_Parameter : Node_Id renames Args (5);
10975 Gather_Associations (Names, Args);
10976 Process_Extended_Import_Export_Subprogram_Pragma (
10977 Arg_Internal => Internal,
10978 Arg_External => External,
10979 Arg_Parameter_Types => Parameter_Types,
10980 Arg_Mechanism => Mechanism,
10981 Arg_First_Optional_Parameter => First_Optional_Parameter);
10982 end Import_Valued_Procedure;
10988 -- pragma Independent (LOCAL_NAME);
10990 when Pragma_Independent => Independent : declare
10997 Check_Ada_83_Warning;
10999 Check_No_Identifiers;
11000 Check_Arg_Count (1);
11001 Check_Arg_Is_Local_Name (Arg1);
11002 E_Id := Get_Pragma_Arg (Arg1);
11004 if Etype (E_Id) = Any_Type then
11008 E := Entity (E_Id);
11009 D := Declaration_Node (E);
11012 -- Check duplicate before we chain ourselves!
11014 Check_Duplicate_Pragma (E);
11016 -- Check appropriate entity
11018 if Is_Type (E) then
11019 if Rep_Item_Too_Early (E, N)
11021 Rep_Item_Too_Late (E, N)
11025 Check_First_Subtype (Arg1);
11028 elsif K = N_Object_Declaration
11029 or else (K = N_Component_Declaration
11030 and then Original_Record_Component (E) = E)
11032 if Rep_Item_Too_Late (E, N) then
11038 ("inappropriate entity for pragma%", Arg1);
11041 Independence_Checks.Append ((N, E));
11044 ----------------------------
11045 -- Independent_Components --
11046 ----------------------------
11048 -- pragma Atomic_Components (array_LOCAL_NAME);
11050 -- This processing is shared by Volatile_Components
11052 when Pragma_Independent_Components => Independent_Components : declare
11059 Check_Ada_83_Warning;
11061 Check_No_Identifiers;
11062 Check_Arg_Count (1);
11063 Check_Arg_Is_Local_Name (Arg1);
11064 E_Id := Get_Pragma_Arg (Arg1);
11066 if Etype (E_Id) = Any_Type then
11070 E := Entity (E_Id);
11072 -- Check duplicate before we chain ourselves!
11074 Check_Duplicate_Pragma (E);
11076 -- Check appropriate entity
11078 if Rep_Item_Too_Early (E, N)
11080 Rep_Item_Too_Late (E, N)
11085 D := Declaration_Node (E);
11088 if K = N_Full_Type_Declaration
11089 and then (Is_Array_Type (E) or else Is_Record_Type (E))
11091 Independence_Checks.Append ((N, E));
11092 Set_Has_Independent_Components (Base_Type (E));
11094 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
11095 and then Nkind (D) = N_Object_Declaration
11096 and then Nkind (Object_Definition (D)) =
11097 N_Constrained_Array_Definition
11099 Independence_Checks.Append ((N, E));
11100 Set_Has_Independent_Components (E);
11103 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
11105 end Independent_Components;
11107 ------------------------
11108 -- Initialize_Scalars --
11109 ------------------------
11111 -- pragma Initialize_Scalars;
11113 when Pragma_Initialize_Scalars =>
11115 Check_Arg_Count (0);
11116 Check_Valid_Configuration_Pragma;
11117 Check_Restriction (No_Initialize_Scalars, N);
11119 -- Initialize_Scalars creates false positives in CodePeer, and
11120 -- incorrect negative results in Alfa mode, so ignore this pragma
11123 if not Restriction_Active (No_Initialize_Scalars)
11124 and then not (CodePeer_Mode or Alfa_Mode)
11126 Init_Or_Norm_Scalars := True;
11127 Initialize_Scalars := True;
11134 -- pragma Inline ( NAME {, NAME} );
11136 when Pragma_Inline =>
11138 -- Inline status is Enabled if inlining option is active
11140 if Inline_Active then
11141 Process_Inline (Enabled);
11143 Process_Inline (Disabled);
11146 -------------------
11147 -- Inline_Always --
11148 -------------------
11150 -- pragma Inline_Always ( NAME {, NAME} );
11152 when Pragma_Inline_Always =>
11155 -- Pragma always active unless in CodePeer or Alfa mode, since
11156 -- this causes walk order issues.
11158 if not (CodePeer_Mode or Alfa_Mode) then
11159 Process_Inline (Enabled);
11162 --------------------
11163 -- Inline_Generic --
11164 --------------------
11166 -- pragma Inline_Generic (NAME {, NAME});
11168 when Pragma_Inline_Generic =>
11170 Process_Generic_List;
11172 ----------------------
11173 -- Inspection_Point --
11174 ----------------------
11176 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
11178 when Pragma_Inspection_Point => Inspection_Point : declare
11183 if Arg_Count > 0 then
11186 Exp := Get_Pragma_Arg (Arg);
11189 if not Is_Entity_Name (Exp)
11190 or else not Is_Object (Entity (Exp))
11192 Error_Pragma_Arg ("object name required", Arg);
11196 exit when No (Arg);
11199 end Inspection_Point;
11205 -- pragma Interface (
11206 -- [ Convention =>] convention_IDENTIFIER,
11207 -- [ Entity =>] local_NAME
11208 -- [, [External_Name =>] static_string_EXPRESSION ]
11209 -- [, [Link_Name =>] static_string_EXPRESSION ]);
11211 when Pragma_Interface =>
11216 Name_External_Name,
11218 Check_At_Least_N_Arguments (2);
11219 Check_At_Most_N_Arguments (4);
11220 Process_Import_Or_Interface;
11222 -- In Ada 2005, the permission to use Interface (a reserved word)
11223 -- as a pragma name is considered an obsolescent feature, and this
11224 -- pragma was already obsolescent in Ada 95.
11226 if Ada_Version >= Ada_95 then
11228 (No_Obsolescent_Features, Pragma_Identifier (N));
11230 if Warn_On_Obsolescent_Feature then
11232 ("pragma Interface is an obsolescent feature?j?", N);
11234 ("|use pragma Import instead?j?", N);
11238 --------------------
11239 -- Interface_Name --
11240 --------------------
11242 -- pragma Interface_Name (
11243 -- [ Entity =>] local_NAME
11244 -- [,[External_Name =>] static_string_EXPRESSION ]
11245 -- [,[Link_Name =>] static_string_EXPRESSION ]);
11247 when Pragma_Interface_Name => Interface_Name : declare
11249 Def_Id : Entity_Id;
11250 Hom_Id : Entity_Id;
11256 ((Name_Entity, Name_External_Name, Name_Link_Name));
11257 Check_At_Least_N_Arguments (2);
11258 Check_At_Most_N_Arguments (3);
11259 Id := Get_Pragma_Arg (Arg1);
11262 -- This is obsolete from Ada 95 on, but it is an implementation
11263 -- defined pragma, so we do not consider that it violates the
11264 -- restriction (No_Obsolescent_Features).
11266 if Ada_Version >= Ada_95 then
11267 if Warn_On_Obsolescent_Feature then
11269 ("pragma Interface_Name is an obsolescent feature?j?", N);
11271 ("|use pragma Import instead?j?", N);
11275 if not Is_Entity_Name (Id) then
11277 ("first argument for pragma% must be entity name", Arg1);
11278 elsif Etype (Id) = Any_Type then
11281 Def_Id := Entity (Id);
11284 -- Special DEC-compatible processing for the object case, forces
11285 -- object to be imported.
11287 if Ekind (Def_Id) = E_Variable then
11288 Kill_Size_Check_Code (Def_Id);
11289 Note_Possible_Modification (Id, Sure => False);
11291 -- Initialization is not allowed for imported variable
11293 if Present (Expression (Parent (Def_Id)))
11294 and then Comes_From_Source (Expression (Parent (Def_Id)))
11296 Error_Msg_Sloc := Sloc (Def_Id);
11298 ("no initialization allowed for declaration of& #",
11302 -- For compatibility, support VADS usage of providing both
11303 -- pragmas Interface and Interface_Name to obtain the effect
11304 -- of a single Import pragma.
11306 if Is_Imported (Def_Id)
11307 and then Present (First_Rep_Item (Def_Id))
11308 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
11310 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
11314 Set_Imported (Def_Id);
11317 Set_Is_Public (Def_Id);
11318 Process_Interface_Name (Def_Id, Arg2, Arg3);
11321 -- Otherwise must be subprogram
11323 elsif not Is_Subprogram (Def_Id) then
11325 ("argument of pragma% is not subprogram", Arg1);
11328 Check_At_Most_N_Arguments (3);
11332 -- Loop through homonyms
11335 Def_Id := Get_Base_Subprogram (Hom_Id);
11337 if Is_Imported (Def_Id) then
11338 Process_Interface_Name (Def_Id, Arg2, Arg3);
11342 exit when From_Aspect_Specification (N);
11343 Hom_Id := Homonym (Hom_Id);
11345 exit when No (Hom_Id)
11346 or else Scope (Hom_Id) /= Current_Scope;
11351 ("argument of pragma% is not imported subprogram",
11355 end Interface_Name;
11357 -----------------------
11358 -- Interrupt_Handler --
11359 -----------------------
11361 -- pragma Interrupt_Handler (handler_NAME);
11363 when Pragma_Interrupt_Handler =>
11364 Check_Ada_83_Warning;
11365 Check_Arg_Count (1);
11366 Check_No_Identifiers;
11368 if No_Run_Time_Mode then
11369 Error_Msg_CRT ("Interrupt_Handler pragma", N);
11371 Check_Interrupt_Or_Attach_Handler;
11372 Process_Interrupt_Or_Attach_Handler;
11375 ------------------------
11376 -- Interrupt_Priority --
11377 ------------------------
11379 -- pragma Interrupt_Priority [(EXPRESSION)];
11381 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
11382 P : constant Node_Id := Parent (N);
11387 Check_Ada_83_Warning;
11389 if Arg_Count /= 0 then
11390 Arg := Get_Pragma_Arg (Arg1);
11391 Check_Arg_Count (1);
11392 Check_No_Identifiers;
11394 -- The expression must be analyzed in the special manner
11395 -- described in "Handling of Default and Per-Object
11396 -- Expressions" in sem.ads.
11398 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
11401 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
11406 Ent := Defining_Identifier (Parent (P));
11408 -- Check duplicate pragma before we chain the pragma in the Rep
11409 -- Item chain of Ent.
11411 Check_Duplicate_Pragma (Ent);
11412 Record_Rep_Item (Ent, N);
11414 end Interrupt_Priority;
11416 ---------------------
11417 -- Interrupt_State --
11418 ---------------------
11420 -- pragma Interrupt_State (
11421 -- [Name =>] INTERRUPT_ID,
11422 -- [State =>] INTERRUPT_STATE);
11424 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
11425 -- INTERRUPT_STATE => System | Runtime | User
11427 -- Note: if the interrupt id is given as an identifier, then it must
11428 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
11429 -- given as a static integer expression which must be in the range of
11430 -- Ada.Interrupts.Interrupt_ID.
11432 when Pragma_Interrupt_State => Interrupt_State : declare
11434 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
11435 -- This is the entity Ada.Interrupts.Interrupt_ID;
11437 State_Type : Character;
11438 -- Set to 's'/'r'/'u' for System/Runtime/User
11441 -- Index to entry in Interrupt_States table
11444 -- Value of interrupt
11446 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
11447 -- The first argument to the pragma
11449 Int_Ent : Entity_Id;
11450 -- Interrupt entity in Ada.Interrupts.Names
11454 Check_Arg_Order ((Name_Name, Name_State));
11455 Check_Arg_Count (2);
11457 Check_Optional_Identifier (Arg1, Name_Name);
11458 Check_Optional_Identifier (Arg2, Name_State);
11459 Check_Arg_Is_Identifier (Arg2);
11461 -- First argument is identifier
11463 if Nkind (Arg1X) = N_Identifier then
11465 -- Search list of names in Ada.Interrupts.Names
11467 Int_Ent := First_Entity (RTE (RE_Names));
11469 if No (Int_Ent) then
11470 Error_Pragma_Arg ("invalid interrupt name", Arg1);
11472 elsif Chars (Int_Ent) = Chars (Arg1X) then
11473 Int_Val := Expr_Value (Constant_Value (Int_Ent));
11477 Next_Entity (Int_Ent);
11480 -- First argument is not an identifier, so it must be a static
11481 -- expression of type Ada.Interrupts.Interrupt_ID.
11484 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
11485 Int_Val := Expr_Value (Arg1X);
11487 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
11489 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
11492 ("value not in range of type " &
11493 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
11499 case Chars (Get_Pragma_Arg (Arg2)) is
11500 when Name_Runtime => State_Type := 'r';
11501 when Name_System => State_Type := 's';
11502 when Name_User => State_Type := 'u';
11505 Error_Pragma_Arg ("invalid interrupt state", Arg2);
11508 -- Check if entry is already stored
11510 IST_Num := Interrupt_States.First;
11512 -- If entry not found, add it
11514 if IST_Num > Interrupt_States.Last then
11515 Interrupt_States.Append
11516 ((Interrupt_Number => UI_To_Int (Int_Val),
11517 Interrupt_State => State_Type,
11518 Pragma_Loc => Loc));
11521 -- Case of entry for the same entry
11523 elsif Int_Val = Interrupt_States.Table (IST_Num).
11526 -- If state matches, done, no need to make redundant entry
11529 State_Type = Interrupt_States.Table (IST_Num).
11532 -- Otherwise if state does not match, error
11535 Interrupt_States.Table (IST_Num).Pragma_Loc;
11537 ("state conflicts with that given #", Arg2);
11541 IST_Num := IST_Num + 1;
11543 end Interrupt_State;
11549 -- pragma Invariant
11550 -- ([Entity =>] type_LOCAL_NAME,
11551 -- [Check =>] EXPRESSION
11552 -- [,[Message =>] String_Expression]);
11554 when Pragma_Invariant => Invariant : declare
11560 pragma Unreferenced (Discard);
11564 Check_At_Least_N_Arguments (2);
11565 Check_At_Most_N_Arguments (3);
11566 Check_Optional_Identifier (Arg1, Name_Entity);
11567 Check_Optional_Identifier (Arg2, Name_Check);
11569 if Arg_Count = 3 then
11570 Check_Optional_Identifier (Arg3, Name_Message);
11571 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
11574 Check_Arg_Is_Local_Name (Arg1);
11576 Type_Id := Get_Pragma_Arg (Arg1);
11577 Find_Type (Type_Id);
11578 Typ := Entity (Type_Id);
11580 if Typ = Any_Type then
11583 -- An invariant must apply to a private type, or appear in the
11584 -- private part of a package spec and apply to a completion.
11586 elsif Ekind_In (Typ, E_Private_Type,
11587 E_Record_Type_With_Private,
11588 E_Limited_Private_Type)
11592 elsif In_Private_Part (Current_Scope)
11593 and then Has_Private_Declaration (Typ)
11597 elsif In_Private_Part (Current_Scope) then
11599 ("pragma% only allowed for private type " &
11600 "declared in visible part", Arg1);
11604 ("pragma% only allowed for private type", Arg1);
11607 -- Note that the type has at least one invariant, and also that
11608 -- it has inheritable invariants if we have Invariant'Class.
11609 -- Build the corresponding invariant procedure declaration, so
11610 -- that calls to it can be generated before the body is built
11611 -- (for example wihin an expression function).
11613 PDecl := Build_Invariant_Procedure_Declaration (Typ);
11614 Insert_After (N, PDecl);
11617 if Class_Present (N) then
11618 Set_Has_Inheritable_Invariants (Typ);
11621 -- The remaining processing is simply to link the pragma on to
11622 -- the rep item chain, for processing when the type is frozen.
11623 -- This is accomplished by a call to Rep_Item_Too_Late.
11625 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11628 ----------------------
11629 -- Java_Constructor --
11630 ----------------------
11632 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
11634 -- Also handles pragma CIL_Constructor
11636 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
11637 Java_Constructor : declare
11638 Convention : Convention_Id;
11639 Def_Id : Entity_Id;
11640 Hom_Id : Entity_Id;
11642 This_Formal : Entity_Id;
11646 Check_Arg_Count (1);
11647 Check_Optional_Identifier (Arg1, Name_Entity);
11648 Check_Arg_Is_Local_Name (Arg1);
11650 Id := Get_Pragma_Arg (Arg1);
11651 Find_Program_Unit_Name (Id);
11653 -- If we did not find the name, we are done
11655 if Etype (Id) = Any_Type then
11659 -- Check wrong use of pragma in wrong VM target
11661 if VM_Target = No_VM then
11664 elsif VM_Target = CLI_Target
11665 and then Prag_Id = Pragma_Java_Constructor
11667 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
11669 elsif VM_Target = JVM_Target
11670 and then Prag_Id = Pragma_CIL_Constructor
11672 Error_Pragma ("must use pragma 'Java_'Constructor");
11676 when Pragma_CIL_Constructor => Convention := Convention_CIL;
11677 when Pragma_Java_Constructor => Convention := Convention_Java;
11678 when others => null;
11681 Hom_Id := Entity (Id);
11683 -- Loop through homonyms
11686 Def_Id := Get_Base_Subprogram (Hom_Id);
11688 -- The constructor is required to be a function
11690 if Ekind (Def_Id) /= E_Function then
11691 if VM_Target = JVM_Target then
11693 ("pragma% requires function returning a " &
11694 "'Java access type", Def_Id);
11697 ("pragma% requires function returning a " &
11698 "'C'I'L access type", Def_Id);
11702 -- Check arguments: For tagged type the first formal must be
11703 -- named "this" and its type must be a named access type
11704 -- designating a class-wide tagged type that has convention
11705 -- CIL/Java. The first formal must also have a null default
11706 -- value. For example:
11708 -- type Typ is tagged ...
11709 -- type Ref is access all Typ;
11710 -- pragma Convention (CIL, Typ);
11712 -- function New_Typ (This : Ref) return Ref;
11713 -- function New_Typ (This : Ref; I : Integer) return Ref;
11714 -- pragma Cil_Constructor (New_Typ);
11716 -- Reason: The first formal must NOT be a primitive of the
11719 -- This rule also applies to constructors of delegates used
11720 -- to interface with standard target libraries. For example:
11722 -- type Delegate is access procedure ...
11723 -- pragma Import (CIL, Delegate, ...);
11725 -- function new_Delegate
11726 -- (This : Delegate := null; ... ) return Delegate;
11728 -- For value-types this rule does not apply.
11730 if not Is_Value_Type (Etype (Def_Id)) then
11731 if No (First_Formal (Def_Id)) then
11732 Error_Msg_Name_1 := Pname;
11733 Error_Msg_N ("% function must have parameters", Def_Id);
11737 -- In the JRE library we have several occurrences in which
11738 -- the "this" parameter is not the first formal.
11740 This_Formal := First_Formal (Def_Id);
11742 -- In the JRE library we have several occurrences in which
11743 -- the "this" parameter is not the first formal. Search for
11746 if VM_Target = JVM_Target then
11747 while Present (This_Formal)
11748 and then Get_Name_String (Chars (This_Formal)) /= "this"
11750 Next_Formal (This_Formal);
11753 if No (This_Formal) then
11754 This_Formal := First_Formal (Def_Id);
11758 -- Warning: The first parameter should be named "this".
11759 -- We temporarily allow it because we have the following
11760 -- case in the Java runtime (file s-osinte.ads) ???
11762 -- function new_Thread
11763 -- (Self_Id : System.Address) return Thread_Id;
11764 -- pragma Java_Constructor (new_Thread);
11766 if VM_Target = JVM_Target
11767 and then Get_Name_String (Chars (First_Formal (Def_Id)))
11769 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
11773 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
11774 Error_Msg_Name_1 := Pname;
11776 ("first formal of % function must be named `this`",
11777 Parent (This_Formal));
11779 elsif not Is_Access_Type (Etype (This_Formal)) then
11780 Error_Msg_Name_1 := Pname;
11782 ("first formal of % function must be an access type",
11783 Parameter_Type (Parent (This_Formal)));
11785 -- For delegates the type of the first formal must be a
11786 -- named access-to-subprogram type (see previous example)
11788 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
11789 and then Ekind (Etype (This_Formal))
11790 /= E_Access_Subprogram_Type
11792 Error_Msg_Name_1 := Pname;
11794 ("first formal of % function must be a named access" &
11795 " to subprogram type",
11796 Parameter_Type (Parent (This_Formal)));
11798 -- Warning: We should reject anonymous access types because
11799 -- the constructor must not be handled as a primitive of the
11800 -- tagged type. We temporarily allow it because this profile
11801 -- is currently generated by cil2ada???
11803 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
11804 and then not Ekind_In (Etype (This_Formal),
11806 E_General_Access_Type,
11807 E_Anonymous_Access_Type)
11809 Error_Msg_Name_1 := Pname;
11811 ("first formal of % function must be a named access" &
11813 Parameter_Type (Parent (This_Formal)));
11815 elsif Atree.Convention
11816 (Designated_Type (Etype (This_Formal))) /= Convention
11818 Error_Msg_Name_1 := Pname;
11820 if Convention = Convention_Java then
11822 ("pragma% requires convention 'Cil in designated" &
11824 Parameter_Type (Parent (This_Formal)));
11827 ("pragma% requires convention 'Java in designated" &
11829 Parameter_Type (Parent (This_Formal)));
11832 elsif No (Expression (Parent (This_Formal)))
11833 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
11835 Error_Msg_Name_1 := Pname;
11837 ("pragma% requires first formal with default `null`",
11838 Parameter_Type (Parent (This_Formal)));
11842 -- Check result type: the constructor must be a function
11844 -- * a value type (only allowed in the CIL compiler)
11845 -- * an access-to-subprogram type with convention Java/CIL
11846 -- * an access-type designating a type that has convention
11849 if Is_Value_Type (Etype (Def_Id)) then
11852 -- Access-to-subprogram type with convention Java/CIL
11854 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
11855 if Atree.Convention (Etype (Def_Id)) /= Convention then
11856 if Convention = Convention_Java then
11858 ("pragma% requires function returning a " &
11859 "'Java access type", Arg1);
11861 pragma Assert (Convention = Convention_CIL);
11863 ("pragma% requires function returning a " &
11864 "'C'I'L access type", Arg1);
11868 elsif Ekind (Etype (Def_Id)) in Access_Kind then
11869 if not Ekind_In (Etype (Def_Id), E_Access_Type,
11870 E_General_Access_Type)
11873 (Designated_Type (Etype (Def_Id))) /= Convention
11875 Error_Msg_Name_1 := Pname;
11877 if Convention = Convention_Java then
11879 ("pragma% requires function returning a named" &
11880 "'Java access type", Arg1);
11883 ("pragma% requires function returning a named" &
11884 "'C'I'L access type", Arg1);
11889 Set_Is_Constructor (Def_Id);
11890 Set_Convention (Def_Id, Convention);
11891 Set_Is_Imported (Def_Id);
11893 exit when From_Aspect_Specification (N);
11894 Hom_Id := Homonym (Hom_Id);
11896 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
11898 end Java_Constructor;
11900 ----------------------
11901 -- Java_Interface --
11902 ----------------------
11904 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
11906 when Pragma_Java_Interface => Java_Interface : declare
11912 Check_Arg_Count (1);
11913 Check_Optional_Identifier (Arg1, Name_Entity);
11914 Check_Arg_Is_Local_Name (Arg1);
11916 Arg := Get_Pragma_Arg (Arg1);
11919 if Etype (Arg) = Any_Type then
11923 if not Is_Entity_Name (Arg)
11924 or else not Is_Type (Entity (Arg))
11926 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
11929 Typ := Underlying_Type (Entity (Arg));
11931 -- For now simply check some of the semantic constraints on the
11932 -- type. This currently leaves out some restrictions on interface
11933 -- types, namely that the parent type must be java.lang.Object.Typ
11934 -- and that all primitives of the type should be declared
11937 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
11938 Error_Pragma_Arg ("pragma% requires an abstract "
11939 & "tagged type", Arg1);
11941 elsif not Has_Discriminants (Typ)
11942 or else Ekind (Etype (First_Discriminant (Typ)))
11943 /= E_Anonymous_Access_Type
11945 not Is_Class_Wide_Type
11946 (Designated_Type (Etype (First_Discriminant (Typ))))
11949 ("type must have a class-wide access discriminant", Arg1);
11951 end Java_Interface;
11957 -- pragma Keep_Names ([On => ] local_NAME);
11959 when Pragma_Keep_Names => Keep_Names : declare
11964 Check_Arg_Count (1);
11965 Check_Optional_Identifier (Arg1, Name_On);
11966 Check_Arg_Is_Local_Name (Arg1);
11968 Arg := Get_Pragma_Arg (Arg1);
11971 if Etype (Arg) = Any_Type then
11975 if not Is_Entity_Name (Arg)
11976 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
11979 ("pragma% requires a local enumeration type", Arg1);
11982 Set_Discard_Names (Entity (Arg), False);
11989 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
11991 when Pragma_License =>
11993 Check_Arg_Count (1);
11994 Check_No_Identifiers;
11995 Check_Valid_Configuration_Pragma;
11996 Check_Arg_Is_Identifier (Arg1);
11999 Sind : constant Source_File_Index :=
12000 Source_Index (Current_Sem_Unit);
12003 case Chars (Get_Pragma_Arg (Arg1)) is
12005 Set_License (Sind, GPL);
12007 when Name_Modified_GPL =>
12008 Set_License (Sind, Modified_GPL);
12010 when Name_Restricted =>
12011 Set_License (Sind, Restricted);
12013 when Name_Unrestricted =>
12014 Set_License (Sind, Unrestricted);
12017 Error_Pragma_Arg ("invalid license name", Arg1);
12025 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
12027 when Pragma_Link_With => Link_With : declare
12033 if Operating_Mode = Generate_Code
12034 and then In_Extended_Main_Source_Unit (N)
12036 Check_At_Least_N_Arguments (1);
12037 Check_No_Identifiers;
12038 Check_Is_In_Decl_Part_Or_Package_Spec;
12039 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12043 while Present (Arg) loop
12044 Check_Arg_Is_Static_Expression (Arg, Standard_String);
12046 -- Store argument, converting sequences of spaces to a
12047 -- single null character (this is one of the differences
12048 -- in processing between Link_With and Linker_Options).
12050 Arg_Store : declare
12051 C : constant Char_Code := Get_Char_Code (' ');
12052 S : constant String_Id :=
12053 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
12054 L : constant Nat := String_Length (S);
12057 procedure Skip_Spaces;
12058 -- Advance F past any spaces
12064 procedure Skip_Spaces is
12066 while F <= L and then Get_String_Char (S, F) = C loop
12071 -- Start of processing for Arg_Store
12074 Skip_Spaces; -- skip leading spaces
12076 -- Loop through characters, changing any embedded
12077 -- sequence of spaces to a single null character (this
12078 -- is how Link_With/Linker_Options differ)
12081 if Get_String_Char (S, F) = C then
12084 Store_String_Char (ASCII.NUL);
12087 Store_String_Char (Get_String_Char (S, F));
12095 if Present (Arg) then
12096 Store_String_Char (ASCII.NUL);
12100 Store_Linker_Option_String (End_String);
12108 -- pragma Linker_Alias (
12109 -- [Entity =>] LOCAL_NAME
12110 -- [Target =>] static_string_EXPRESSION);
12112 when Pragma_Linker_Alias =>
12114 Check_Arg_Order ((Name_Entity, Name_Target));
12115 Check_Arg_Count (2);
12116 Check_Optional_Identifier (Arg1, Name_Entity);
12117 Check_Optional_Identifier (Arg2, Name_Target);
12118 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12119 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
12121 -- The only processing required is to link this item on to the
12122 -- list of rep items for the given entity. This is accomplished
12123 -- by the call to Rep_Item_Too_Late (when no error is detected
12124 -- and False is returned).
12126 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
12129 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
12132 ------------------------
12133 -- Linker_Constructor --
12134 ------------------------
12136 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
12138 -- Code is shared with Linker_Destructor
12140 -----------------------
12141 -- Linker_Destructor --
12142 -----------------------
12144 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
12146 when Pragma_Linker_Constructor |
12147 Pragma_Linker_Destructor =>
12148 Linker_Constructor : declare
12154 Check_Arg_Count (1);
12155 Check_No_Identifiers;
12156 Check_Arg_Is_Local_Name (Arg1);
12157 Arg1_X := Get_Pragma_Arg (Arg1);
12159 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
12161 if not Is_Library_Level_Entity (Proc) then
12163 ("argument for pragma% must be library level entity", Arg1);
12166 -- The only processing required is to link this item on to the
12167 -- list of rep items for the given entity. This is accomplished
12168 -- by the call to Rep_Item_Too_Late (when no error is detected
12169 -- and False is returned).
12171 if Rep_Item_Too_Late (Proc, N) then
12174 Set_Has_Gigi_Rep_Item (Proc);
12176 end Linker_Constructor;
12178 --------------------
12179 -- Linker_Options --
12180 --------------------
12182 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
12184 when Pragma_Linker_Options => Linker_Options : declare
12188 Check_Ada_83_Warning;
12189 Check_No_Identifiers;
12190 Check_Arg_Count (1);
12191 Check_Is_In_Decl_Part_Or_Package_Spec;
12192 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12193 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
12196 while Present (Arg) loop
12197 Check_Arg_Is_Static_Expression (Arg, Standard_String);
12198 Store_String_Char (ASCII.NUL);
12200 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
12204 if Operating_Mode = Generate_Code
12205 and then In_Extended_Main_Source_Unit (N)
12207 Store_Linker_Option_String (End_String);
12209 end Linker_Options;
12211 --------------------
12212 -- Linker_Section --
12213 --------------------
12215 -- pragma Linker_Section (
12216 -- [Entity =>] LOCAL_NAME
12217 -- [Section =>] static_string_EXPRESSION);
12219 when Pragma_Linker_Section =>
12221 Check_Arg_Order ((Name_Entity, Name_Section));
12222 Check_Arg_Count (2);
12223 Check_Optional_Identifier (Arg1, Name_Entity);
12224 Check_Optional_Identifier (Arg2, Name_Section);
12225 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12226 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
12228 -- This pragma applies only to objects
12230 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
12231 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
12234 -- The only processing required is to link this item on to the
12235 -- list of rep items for the given entity. This is accomplished
12236 -- by the call to Rep_Item_Too_Late (when no error is detected
12237 -- and False is returned).
12239 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
12242 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
12249 -- pragma List (On | Off)
12251 -- There is nothing to do here, since we did all the processing for
12252 -- this pragma in Par.Prag (so that it works properly even in syntax
12255 when Pragma_List =>
12262 -- pragma Lock_Free [(Boolean_EXPRESSION)];
12264 when Pragma_Lock_Free => Lock_Free : declare
12265 P : constant Node_Id := Parent (N);
12271 Check_No_Identifiers;
12272 Check_At_Most_N_Arguments (1);
12274 -- Protected definition case
12276 if Nkind (P) = N_Protected_Definition then
12277 Ent := Defining_Identifier (Parent (P));
12281 if Arg_Count = 1 then
12282 Arg := Get_Pragma_Arg (Arg1);
12283 Val := Is_True (Static_Boolean (Arg));
12285 -- No arguments (expression is considered to be True)
12291 -- Check duplicate pragma before we chain the pragma in the Rep
12292 -- Item chain of Ent.
12294 Check_Duplicate_Pragma (Ent);
12295 Record_Rep_Item (Ent, N);
12296 Set_Uses_Lock_Free (Ent, Val);
12298 -- Anything else is incorrect placement
12305 --------------------
12306 -- Locking_Policy --
12307 --------------------
12309 -- pragma Locking_Policy (policy_IDENTIFIER);
12311 when Pragma_Locking_Policy => declare
12312 subtype LP_Range is Name_Id
12313 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
12318 Check_Ada_83_Warning;
12319 Check_Arg_Count (1);
12320 Check_No_Identifiers;
12321 Check_Arg_Is_Locking_Policy (Arg1);
12322 Check_Valid_Configuration_Pragma;
12323 LP_Val := Chars (Get_Pragma_Arg (Arg1));
12326 when Name_Ceiling_Locking =>
12328 when Name_Inheritance_Locking =>
12330 when Name_Concurrent_Readers_Locking =>
12334 if Locking_Policy /= ' '
12335 and then Locking_Policy /= LP
12337 Error_Msg_Sloc := Locking_Policy_Sloc;
12338 Error_Pragma ("locking policy incompatible with policy#");
12340 -- Set new policy, but always preserve System_Location since we
12341 -- like the error message with the run time name.
12344 Locking_Policy := LP;
12346 if Locking_Policy_Sloc /= System_Location then
12347 Locking_Policy_Sloc := Loc;
12356 -- pragma Long_Float (D_Float | G_Float);
12358 when Pragma_Long_Float => Long_Float : declare
12361 Check_Valid_Configuration_Pragma;
12362 Check_Arg_Count (1);
12363 Check_No_Identifier (Arg1);
12364 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
12366 if not OpenVMS_On_Target then
12367 Error_Pragma ("??pragma% ignored (applies only to Open'V'M'S)");
12372 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
12373 if Opt.Float_Format_Long = 'G' then
12375 ("G_Float previously specified", Arg1);
12377 elsif Current_Sem_Unit /= Main_Unit
12378 and then Opt.Float_Format_Long /= 'D'
12381 ("main unit not compiled with pragma Long_Float (D_Float)",
12382 "\pragma% must be used consistently for whole partition",
12386 Opt.Float_Format_Long := 'D';
12389 -- G_Float case (this is the default, does not need overriding)
12392 if Opt.Float_Format_Long = 'D' then
12393 Error_Pragma ("D_Float previously specified");
12395 elsif Current_Sem_Unit /= Main_Unit
12396 and then Opt.Float_Format_Long /= 'G'
12399 ("main unit not compiled with pragma Long_Float (G_Float)",
12400 "\pragma% must be used consistently for whole partition",
12404 Opt.Float_Format_Long := 'G';
12408 Set_Standard_Fpt_Formats;
12411 --------------------
12412 -- Loop_Invariant --
12413 --------------------
12415 -- pragma Loop_Invariant ( boolean_EXPRESSION );
12417 when Pragma_Loop_Invariant => Loop_Invariant : declare
12421 Check_Arg_Count (1);
12422 Check_Loop_Pragma_Placement;
12424 -- Completely ignore if disabled
12426 if not Check_Enabled (Pname) then
12427 Rewrite (N, Make_Null_Statement (Loc));
12432 Preanalyze_And_Resolve (Expression (Arg1), Any_Boolean);
12434 -- Transform pragma Loop_Invariant into equivalent pragma Check
12436 -- pragma Check (Loop_Invaraint, Arg1);
12438 -- Seems completely wrong to hijack pragma Check this way ???
12442 Chars => Name_Check,
12443 Pragma_Argument_Associations => New_List (
12444 Make_Pragma_Argument_Association (Loc,
12445 Expression => Make_Identifier (Loc, Name_Loop_Invariant)),
12446 Relocate_Node (Arg1))));
12449 end Loop_Invariant;
12451 -------------------
12452 -- Loop_Optimize --
12453 -------------------
12455 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
12457 -- OPTIMIZATION_HINT ::= No_Unroll | Unroll | No_Vector | Vector
12459 when Pragma_Loop_Optimize => Loop_Optimize : declare
12464 Check_At_Least_N_Arguments (1);
12465 Check_No_Identifiers;
12467 Hint := First (Pragma_Argument_Associations (N));
12468 while Present (Hint) loop
12469 Check_Arg_Is_One_Of (Hint,
12470 Name_No_Unroll, Name_Unroll, Name_No_Vector, Name_Vector);
12474 Check_Loop_Pragma_Placement;
12481 -- pragma Loop_Variant
12482 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
12484 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
12486 -- CHANGE_DIRECTION ::= Increases | Decreases
12488 when Pragma_Loop_Variant => Loop_Variant : declare
12494 Check_At_Least_N_Arguments (1);
12495 Check_Loop_Pragma_Placement;
12497 -- Completely ignore if disabled
12499 if not Check_Enabled (Pname) then
12500 Rewrite (N, Make_Null_Statement (Loc));
12505 -- Process all increasing / decreasing expressions
12507 Variant := First (Pragma_Argument_Associations (N));
12508 while Present (Variant) loop
12509 if Chars (Variant) /= Name_Decreases
12510 and then Chars (Variant) /= Name_Increases
12512 Error_Pragma_Arg ("wrong change modifier", Variant);
12515 Preanalyze_And_Resolve (Expression (Variant), Any_Discrete);
12521 -----------------------
12522 -- Machine_Attribute --
12523 -----------------------
12525 -- pragma Machine_Attribute (
12526 -- [Entity =>] LOCAL_NAME,
12527 -- [Attribute_Name =>] static_string_EXPRESSION
12528 -- [, [Info =>] static_EXPRESSION] );
12530 when Pragma_Machine_Attribute => Machine_Attribute : declare
12531 Def_Id : Entity_Id;
12535 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
12537 if Arg_Count = 3 then
12538 Check_Optional_Identifier (Arg3, Name_Info);
12539 Check_Arg_Is_Static_Expression (Arg3);
12541 Check_Arg_Count (2);
12544 Check_Optional_Identifier (Arg1, Name_Entity);
12545 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
12546 Check_Arg_Is_Local_Name (Arg1);
12547 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
12548 Def_Id := Entity (Get_Pragma_Arg (Arg1));
12550 if Is_Access_Type (Def_Id) then
12551 Def_Id := Designated_Type (Def_Id);
12554 if Rep_Item_Too_Early (Def_Id, N) then
12558 Def_Id := Underlying_Type (Def_Id);
12560 -- The only processing required is to link this item on to the
12561 -- list of rep items for the given entity. This is accomplished
12562 -- by the call to Rep_Item_Too_Late (when no error is detected
12563 -- and False is returned).
12565 if Rep_Item_Too_Late (Def_Id, N) then
12568 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
12570 end Machine_Attribute;
12577 -- (MAIN_OPTION [, MAIN_OPTION]);
12580 -- [STACK_SIZE =>] static_integer_EXPRESSION
12581 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
12582 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
12584 when Pragma_Main => Main : declare
12585 Args : Args_List (1 .. 3);
12586 Names : constant Name_List (1 .. 3) := (
12588 Name_Task_Stack_Size_Default,
12589 Name_Time_Slicing_Enabled);
12595 Gather_Associations (Names, Args);
12597 for J in 1 .. 2 loop
12598 if Present (Args (J)) then
12599 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
12603 if Present (Args (3)) then
12604 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
12608 while Present (Nod) loop
12609 if Nkind (Nod) = N_Pragma
12610 and then Pragma_Name (Nod) = Name_Main
12612 Error_Msg_Name_1 := Pname;
12613 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12624 -- pragma Main_Storage
12625 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
12627 -- MAIN_STORAGE_OPTION ::=
12628 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
12629 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
12631 when Pragma_Main_Storage => Main_Storage : declare
12632 Args : Args_List (1 .. 2);
12633 Names : constant Name_List (1 .. 2) := (
12634 Name_Working_Storage,
12641 Gather_Associations (Names, Args);
12643 for J in 1 .. 2 loop
12644 if Present (Args (J)) then
12645 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
12649 Check_In_Main_Program;
12652 while Present (Nod) loop
12653 if Nkind (Nod) = N_Pragma
12654 and then Pragma_Name (Nod) = Name_Main_Storage
12656 Error_Msg_Name_1 := Pname;
12657 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12668 -- pragma Memory_Size (NUMERIC_LITERAL)
12670 when Pragma_Memory_Size =>
12673 -- Memory size is simply ignored
12675 Check_No_Identifiers;
12676 Check_Arg_Count (1);
12677 Check_Arg_Is_Integer_Literal (Arg1);
12685 -- The only correct use of this pragma is on its own in a file, in
12686 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
12687 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
12688 -- check for a file containing nothing but a No_Body pragma). If we
12689 -- attempt to process it during normal semantics processing, it means
12690 -- it was misplaced.
12692 when Pragma_No_Body =>
12700 -- pragma No_Inline ( NAME {, NAME} );
12702 when Pragma_No_Inline =>
12704 Process_Inline (Suppressed);
12710 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
12712 when Pragma_No_Return => No_Return : declare
12720 Check_At_Least_N_Arguments (1);
12722 -- Loop through arguments of pragma
12725 while Present (Arg) loop
12726 Check_Arg_Is_Local_Name (Arg);
12727 Id := Get_Pragma_Arg (Arg);
12730 if not Is_Entity_Name (Id) then
12731 Error_Pragma_Arg ("entity name required", Arg);
12734 if Etype (Id) = Any_Type then
12738 -- Loop to find matching procedures
12743 and then Scope (E) = Current_Scope
12745 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
12748 -- Set flag on any alias as well
12750 if Is_Overloadable (E) and then Present (Alias (E)) then
12751 Set_No_Return (Alias (E));
12757 exit when From_Aspect_Specification (N);
12762 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
12773 -- pragma No_Run_Time;
12775 -- Note: this pragma is retained for backwards compatibility. See
12776 -- body of Rtsfind for full details on its handling.
12778 when Pragma_No_Run_Time =>
12780 Check_Valid_Configuration_Pragma;
12781 Check_Arg_Count (0);
12783 No_Run_Time_Mode := True;
12784 Configurable_Run_Time_Mode := True;
12786 -- Set Duration to 32 bits if word size is 32
12788 if Ttypes.System_Word_Size = 32 then
12789 Duration_32_Bits_On_Target := True;
12792 -- Set appropriate restrictions
12794 Set_Restriction (No_Finalization, N);
12795 Set_Restriction (No_Exception_Handlers, N);
12796 Set_Restriction (Max_Tasks, N, 0);
12797 Set_Restriction (No_Tasking, N);
12799 ------------------------
12800 -- No_Strict_Aliasing --
12801 ------------------------
12803 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
12805 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
12810 Check_At_Most_N_Arguments (1);
12812 if Arg_Count = 0 then
12813 Check_Valid_Configuration_Pragma;
12814 Opt.No_Strict_Aliasing := True;
12817 Check_Optional_Identifier (Arg2, Name_Entity);
12818 Check_Arg_Is_Local_Name (Arg1);
12819 E_Id := Entity (Get_Pragma_Arg (Arg1));
12821 if E_Id = Any_Type then
12823 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
12824 Error_Pragma_Arg ("pragma% requires access type", Arg1);
12827 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
12829 end No_Strict_Aliasing;
12831 -----------------------
12832 -- Normalize_Scalars --
12833 -----------------------
12835 -- pragma Normalize_Scalars;
12837 when Pragma_Normalize_Scalars =>
12838 Check_Ada_83_Warning;
12839 Check_Arg_Count (0);
12840 Check_Valid_Configuration_Pragma;
12842 -- Normalize_Scalars creates false positives in CodePeer, and
12843 -- incorrect negative results in Alfa mode, so ignore this pragma
12846 if not (CodePeer_Mode or Alfa_Mode) then
12847 Normalize_Scalars := True;
12848 Init_Or_Norm_Scalars := True;
12855 -- pragma Obsolescent;
12857 -- pragma Obsolescent (
12858 -- [Message =>] static_string_EXPRESSION
12859 -- [,[Version =>] Ada_05]]);
12861 -- pragma Obsolescent (
12862 -- [Entity =>] NAME
12863 -- [,[Message =>] static_string_EXPRESSION
12864 -- [,[Version =>] Ada_05]] );
12866 when Pragma_Obsolescent => Obsolescent : declare
12870 procedure Set_Obsolescent (E : Entity_Id);
12871 -- Given an entity Ent, mark it as obsolescent if appropriate
12873 ---------------------
12874 -- Set_Obsolescent --
12875 ---------------------
12877 procedure Set_Obsolescent (E : Entity_Id) is
12886 -- Entity name was given
12888 if Present (Ename) then
12890 -- If entity name matches, we are fine. Save entity in
12891 -- pragma argument, for ASIS use.
12893 if Chars (Ename) = Chars (Ent) then
12894 Set_Entity (Ename, Ent);
12895 Generate_Reference (Ent, Ename);
12897 -- If entity name does not match, only possibility is an
12898 -- enumeration literal from an enumeration type declaration.
12900 elsif Ekind (Ent) /= E_Enumeration_Type then
12902 ("pragma % entity name does not match declaration");
12905 Ent := First_Literal (E);
12909 ("pragma % entity name does not match any " &
12910 "enumeration literal");
12912 elsif Chars (Ent) = Chars (Ename) then
12913 Set_Entity (Ename, Ent);
12914 Generate_Reference (Ent, Ename);
12918 Ent := Next_Literal (Ent);
12924 -- Ent points to entity to be marked
12926 if Arg_Count >= 1 then
12928 -- Deal with static string argument
12930 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12931 S := Strval (Get_Pragma_Arg (Arg1));
12933 for J in 1 .. String_Length (S) loop
12934 if not In_Character_Range (Get_String_Char (S, J)) then
12936 ("pragma% argument does not allow wide characters",
12941 Obsolescent_Warnings.Append
12942 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
12944 -- Check for Ada_05 parameter
12946 if Arg_Count /= 1 then
12947 Check_Arg_Count (2);
12950 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
12953 Check_Arg_Is_Identifier (Argx);
12955 if Chars (Argx) /= Name_Ada_05 then
12956 Error_Msg_Name_2 := Name_Ada_05;
12958 ("only allowed argument for pragma% is %", Argx);
12961 if Ada_Version_Explicit < Ada_2005
12962 or else not Warn_On_Ada_2005_Compatibility
12970 -- Set flag if pragma active
12973 Set_Is_Obsolescent (Ent);
12977 end Set_Obsolescent;
12979 -- Start of processing for pragma Obsolescent
12984 Check_At_Most_N_Arguments (3);
12986 -- See if first argument specifies an entity name
12990 (Chars (Arg1) = Name_Entity
12992 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
12994 N_Operator_Symbol))
12996 Ename := Get_Pragma_Arg (Arg1);
12998 -- Eliminate first argument, so we can share processing
13002 Arg_Count := Arg_Count - 1;
13004 -- No Entity name argument given
13010 if Arg_Count >= 1 then
13011 Check_Optional_Identifier (Arg1, Name_Message);
13013 if Arg_Count = 2 then
13014 Check_Optional_Identifier (Arg2, Name_Version);
13018 -- Get immediately preceding declaration
13021 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
13025 -- Cases where we do not follow anything other than another pragma
13029 -- First case: library level compilation unit declaration with
13030 -- the pragma immediately following the declaration.
13032 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
13034 (Defining_Entity (Unit (Parent (Parent (N)))));
13037 -- Case 2: library unit placement for package
13041 Ent : constant Entity_Id := Find_Lib_Unit_Name;
13043 if Is_Package_Or_Generic_Package (Ent) then
13044 Set_Obsolescent (Ent);
13050 -- Cases where we must follow a declaration
13053 if Nkind (Decl) not in N_Declaration
13054 and then Nkind (Decl) not in N_Later_Decl_Item
13055 and then Nkind (Decl) not in N_Generic_Declaration
13056 and then Nkind (Decl) not in N_Renaming_Declaration
13059 ("pragma% misplaced, "
13060 & "must immediately follow a declaration");
13063 Set_Obsolescent (Defining_Entity (Decl));
13073 -- pragma Optimize (Time | Space | Off);
13075 -- The actual check for optimize is done in Gigi. Note that this
13076 -- pragma does not actually change the optimization setting, it
13077 -- simply checks that it is consistent with the pragma.
13079 when Pragma_Optimize =>
13080 Check_No_Identifiers;
13081 Check_Arg_Count (1);
13082 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
13084 ------------------------
13085 -- Optimize_Alignment --
13086 ------------------------
13088 -- pragma Optimize_Alignment (Time | Space | Off);
13090 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
13092 Check_No_Identifiers;
13093 Check_Arg_Count (1);
13094 Check_Valid_Configuration_Pragma;
13097 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
13101 Opt.Optimize_Alignment := 'T';
13103 Opt.Optimize_Alignment := 'S';
13105 Opt.Optimize_Alignment := 'O';
13107 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
13111 -- Set indication that mode is set locally. If we are in fact in a
13112 -- configuration pragma file, this setting is harmless since the
13113 -- switch will get reset anyway at the start of each unit.
13115 Optimize_Alignment_Local := True;
13116 end Optimize_Alignment;
13118 -------------------
13119 -- Overflow_Mode --
13120 -------------------
13122 -- pragma Overflow_Mode
13123 -- ([General => ] MODE [, [Assertions => ] MODE]);
13125 -- MODE := STRICT | MINIMIZED | ELIMINATED
13127 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
13128 -- since System.Bignums makes this assumption. This is true of nearly
13129 -- all (all?) targets.
13131 when Pragma_Overflow_Mode => Overflow_Mode : declare
13132 function Get_Overflow_Mode
13134 Arg : Node_Id) return Overflow_Mode_Type;
13135 -- Function to process one pragma argument, Arg. If an identifier
13136 -- is present, it must be Name. Mode type is returned if a valid
13137 -- argument exists, otherwise an error is signalled.
13139 -----------------------
13140 -- Get_Overflow_Mode --
13141 -----------------------
13143 function Get_Overflow_Mode
13145 Arg : Node_Id) return Overflow_Mode_Type
13147 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
13150 Check_Optional_Identifier (Arg, Name);
13151 Check_Arg_Is_Identifier (Argx);
13153 if Chars (Argx) = Name_Strict then
13156 elsif Chars (Argx) = Name_Minimized then
13159 elsif Chars (Argx) = Name_Eliminated then
13160 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
13162 ("Eliminated not implemented on this target", Argx);
13168 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
13170 end Get_Overflow_Mode;
13172 -- Start of processing for Overflow_Mode
13176 Check_At_Least_N_Arguments (1);
13177 Check_At_Most_N_Arguments (2);
13179 -- Process first argument
13181 Scope_Suppress.Overflow_Mode_General :=
13182 Get_Overflow_Mode (Name_General, Arg1);
13184 -- Case of only one argument
13186 if Arg_Count = 1 then
13187 Scope_Suppress.Overflow_Mode_Assertions :=
13188 Scope_Suppress.Overflow_Mode_General;
13190 -- Case of two arguments present
13193 Scope_Suppress.Overflow_Mode_Assertions :=
13194 Get_Overflow_Mode (Name_Assertions, Arg2);
13198 when Pragma_Overriding_Renamings =>
13199 Overriding_Renamings := True;
13205 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
13207 when Pragma_Ordered => Ordered : declare
13208 Assoc : constant Node_Id := Arg1;
13214 Check_No_Identifiers;
13215 Check_Arg_Count (1);
13216 Check_Arg_Is_Local_Name (Arg1);
13218 Type_Id := Get_Pragma_Arg (Assoc);
13219 Find_Type (Type_Id);
13220 Typ := Entity (Type_Id);
13222 if Typ = Any_Type then
13225 Typ := Underlying_Type (Typ);
13228 if not Is_Enumeration_Type (Typ) then
13229 Error_Pragma ("pragma% must specify enumeration type");
13232 Check_First_Subtype (Arg1);
13233 Set_Has_Pragma_Ordered (Base_Type (Typ));
13240 -- pragma Pack (first_subtype_LOCAL_NAME);
13242 when Pragma_Pack => Pack : declare
13243 Assoc : constant Node_Id := Arg1;
13247 Ignore : Boolean := False;
13250 Check_No_Identifiers;
13251 Check_Arg_Count (1);
13252 Check_Arg_Is_Local_Name (Arg1);
13254 Type_Id := Get_Pragma_Arg (Assoc);
13255 Find_Type (Type_Id);
13256 Typ := Entity (Type_Id);
13259 or else Rep_Item_Too_Early (Typ, N)
13263 Typ := Underlying_Type (Typ);
13266 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
13267 Error_Pragma ("pragma% must specify array or record type");
13270 Check_First_Subtype (Arg1);
13271 Check_Duplicate_Pragma (Typ);
13275 if Is_Array_Type (Typ) then
13276 Ctyp := Component_Type (Typ);
13278 -- Ignore pack that does nothing
13280 if Known_Static_Esize (Ctyp)
13281 and then Known_Static_RM_Size (Ctyp)
13282 and then Esize (Ctyp) = RM_Size (Ctyp)
13283 and then Addressable (Esize (Ctyp))
13288 -- Process OK pragma Pack. Note that if there is a separate
13289 -- component clause present, the Pack will be cancelled. This
13290 -- processing is in Freeze.
13292 if not Rep_Item_Too_Late (Typ, N) then
13294 -- In the context of static code analysis, we do not need
13295 -- complex front-end expansions related to pragma Pack,
13296 -- so disable handling of pragma Pack in these cases.
13298 if CodePeer_Mode or Alfa_Mode then
13301 -- Don't attempt any packing for VM targets. We possibly
13302 -- could deal with some cases of array bit-packing, but we
13303 -- don't bother, since this is not a typical kind of
13304 -- representation in the VM context anyway (and would not
13305 -- for example work nicely with the debugger).
13307 elsif VM_Target /= No_VM then
13308 if not GNAT_Mode then
13310 ("??pragma% ignored in this configuration");
13313 -- Normal case where we do the pack action
13317 Set_Is_Packed (Base_Type (Typ));
13318 Set_Has_Non_Standard_Rep (Base_Type (Typ));
13321 Set_Has_Pragma_Pack (Base_Type (Typ));
13325 -- For record types, the pack is always effective
13327 else pragma Assert (Is_Record_Type (Typ));
13328 if not Rep_Item_Too_Late (Typ, N) then
13330 -- Ignore pack request with warning in VM mode (skip warning
13331 -- if we are compiling GNAT run time library).
13333 if VM_Target /= No_VM then
13334 if not GNAT_Mode then
13336 ("??pragma% ignored in this configuration");
13339 -- Normal case of pack request active
13342 Set_Is_Packed (Base_Type (Typ));
13343 Set_Has_Pragma_Pack (Base_Type (Typ));
13344 Set_Has_Non_Standard_Rep (Base_Type (Typ));
13356 -- There is nothing to do here, since we did all the processing for
13357 -- this pragma in Par.Prag (so that it works properly even in syntax
13360 when Pragma_Page =>
13363 ----------------------------------
13364 -- Partition_Elaboration_Policy --
13365 ----------------------------------
13367 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
13369 when Pragma_Partition_Elaboration_Policy => declare
13370 subtype PEP_Range is Name_Id
13371 range First_Partition_Elaboration_Policy_Name
13372 .. Last_Partition_Elaboration_Policy_Name;
13373 PEP_Val : PEP_Range;
13378 Check_Arg_Count (1);
13379 Check_No_Identifiers;
13380 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
13381 Check_Valid_Configuration_Pragma;
13382 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
13385 when Name_Concurrent =>
13387 when Name_Sequential =>
13391 if Partition_Elaboration_Policy /= ' '
13392 and then Partition_Elaboration_Policy /= PEP
13394 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
13396 ("partition elaboration policy incompatible with policy#");
13398 -- Set new policy, but always preserve System_Location since we
13399 -- like the error message with the run time name.
13402 Partition_Elaboration_Policy := PEP;
13404 if Partition_Elaboration_Policy_Sloc /= System_Location then
13405 Partition_Elaboration_Policy_Sloc := Loc;
13414 -- pragma Passive [(PASSIVE_FORM)];
13416 -- PASSIVE_FORM ::= Semaphore | No
13418 when Pragma_Passive =>
13421 if Nkind (Parent (N)) /= N_Task_Definition then
13422 Error_Pragma ("pragma% must be within task definition");
13425 if Arg_Count /= 0 then
13426 Check_Arg_Count (1);
13427 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
13430 ----------------------------------
13431 -- Preelaborable_Initialization --
13432 ----------------------------------
13434 -- pragma Preelaborable_Initialization (DIRECT_NAME);
13436 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
13441 Check_Arg_Count (1);
13442 Check_No_Identifiers;
13443 Check_Arg_Is_Identifier (Arg1);
13444 Check_Arg_Is_Local_Name (Arg1);
13445 Check_First_Subtype (Arg1);
13446 Ent := Entity (Get_Pragma_Arg (Arg1));
13448 -- The pragma may come from an aspect on a private declaration,
13449 -- even if the freeze point at which this is analyzed in the
13450 -- private part after the full view.
13452 if Has_Private_Declaration (Ent)
13453 and then From_Aspect_Specification (N)
13457 elsif Is_Private_Type (Ent)
13458 or else Is_Protected_Type (Ent)
13459 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
13465 ("pragma % can only be applied to private, formal derived or "
13466 & "protected type",
13470 -- Give an error if the pragma is applied to a protected type that
13471 -- does not qualify (due to having entries, or due to components
13472 -- that do not qualify).
13474 if Is_Protected_Type (Ent)
13475 and then not Has_Preelaborable_Initialization (Ent)
13478 ("protected type & does not have preelaborable " &
13479 "initialization", Ent);
13481 -- Otherwise mark the type as definitely having preelaborable
13485 Set_Known_To_Have_Preelab_Init (Ent);
13488 if Has_Pragma_Preelab_Init (Ent)
13489 and then Warn_On_Redundant_Constructs
13491 Error_Pragma ("?r?duplicate pragma%!");
13493 Set_Has_Pragma_Preelab_Init (Ent);
13497 --------------------
13498 -- Persistent_BSS --
13499 --------------------
13501 -- pragma Persistent_BSS [(object_NAME)];
13503 when Pragma_Persistent_BSS => Persistent_BSS : declare
13510 Check_At_Most_N_Arguments (1);
13512 -- Case of application to specific object (one argument)
13514 if Arg_Count = 1 then
13515 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13517 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
13519 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
13522 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
13525 Ent := Entity (Get_Pragma_Arg (Arg1));
13526 Decl := Parent (Ent);
13528 -- Check for duplication before inserting in list of
13529 -- representation items.
13531 Check_Duplicate_Pragma (Ent);
13533 if Rep_Item_Too_Late (Ent, N) then
13537 if Present (Expression (Decl)) then
13539 ("object for pragma% cannot have initialization", Arg1);
13542 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
13544 ("object type for pragma% is not potentially persistent",
13549 Make_Linker_Section_Pragma
13550 (Ent, Sloc (N), ".persistent.bss");
13551 Insert_After (N, Prag);
13554 -- Case of use as configuration pragma with no arguments
13557 Check_Valid_Configuration_Pragma;
13558 Persistent_BSS_Mode := True;
13560 end Persistent_BSS;
13566 -- pragma Polling (ON | OFF);
13568 when Pragma_Polling =>
13570 Check_Arg_Count (1);
13571 Check_No_Identifiers;
13572 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13573 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
13575 -------------------
13576 -- Postcondition --
13577 -------------------
13579 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
13580 -- [,[Message =>] String_EXPRESSION]);
13582 when Pragma_Postcondition => Postcondition : declare
13587 Check_At_Least_N_Arguments (1);
13588 Check_At_Most_N_Arguments (2);
13589 Check_Optional_Identifier (Arg1, Name_Check);
13591 -- Verify the proper placement of the pragma. The remainder of the
13592 -- processing is found in Sem_Ch6/Sem_Ch7.
13594 Check_Precondition_Postcondition (In_Body);
13596 -- When the pragma is a source contruct and appears inside a body,
13597 -- preanalyze the boolean_expression to detect illegal forward
13601 -- pragma Postcondition (X'Old ...);
13604 if Comes_From_Source (N) and then In_Body then
13605 Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
13613 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
13614 -- [,[Message =>] String_EXPRESSION]);
13616 when Pragma_Precondition => Precondition : declare
13621 Check_At_Least_N_Arguments (1);
13622 Check_At_Most_N_Arguments (2);
13623 Check_Optional_Identifier (Arg1, Name_Check);
13624 Check_Precondition_Postcondition (In_Body);
13626 -- If in spec, nothing more to do. If in body, then we convert the
13627 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
13628 -- this whether or not precondition checks are enabled. That works
13629 -- fine since pragma Check will do this check, and will also
13630 -- analyze the condition itself in the proper context.
13635 Chars => Name_Check,
13636 Pragma_Argument_Associations => New_List (
13637 Make_Pragma_Argument_Association (Loc,
13638 Expression => Make_Identifier (Loc, Name_Precondition)),
13640 Make_Pragma_Argument_Association (Sloc (Arg1),
13641 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
13643 if Arg_Count = 2 then
13644 Append_To (Pragma_Argument_Associations (N),
13645 Make_Pragma_Argument_Association (Sloc (Arg2),
13646 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
13657 -- pragma Predicate
13658 -- ([Entity =>] type_LOCAL_NAME,
13659 -- [Check =>] EXPRESSION);
13661 when Pragma_Predicate => Predicate : declare
13666 pragma Unreferenced (Discard);
13670 Check_Arg_Count (2);
13671 Check_Optional_Identifier (Arg1, Name_Entity);
13672 Check_Optional_Identifier (Arg2, Name_Check);
13674 Check_Arg_Is_Local_Name (Arg1);
13676 Type_Id := Get_Pragma_Arg (Arg1);
13677 Find_Type (Type_Id);
13678 Typ := Entity (Type_Id);
13680 if Typ = Any_Type then
13684 -- The remaining processing is simply to link the pragma on to
13685 -- the rep item chain, for processing when the type is frozen.
13686 -- This is accomplished by a call to Rep_Item_Too_Late. We also
13687 -- mark the type as having predicates.
13689 Set_Has_Predicates (Typ);
13690 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
13697 -- pragma Preelaborate [(library_unit_NAME)];
13699 -- Set the flag Is_Preelaborated of program unit name entity
13701 when Pragma_Preelaborate => Preelaborate : declare
13702 Pa : constant Node_Id := Parent (N);
13703 Pk : constant Node_Kind := Nkind (Pa);
13707 Check_Ada_83_Warning;
13708 Check_Valid_Library_Unit_Pragma;
13710 if Nkind (N) = N_Null_Statement then
13714 Ent := Find_Lib_Unit_Name;
13715 Check_Duplicate_Pragma (Ent);
13717 -- This filters out pragmas inside generic parent then
13718 -- show up inside instantiation
13721 and then not (Pk = N_Package_Specification
13722 and then Present (Generic_Parent (Pa)))
13724 if not Debug_Flag_U then
13725 Set_Is_Preelaborated (Ent);
13726 Set_Suppress_Elaboration_Warnings (Ent);
13731 ---------------------
13732 -- Preelaborate_05 --
13733 ---------------------
13735 -- pragma Preelaborate_05 [(library_unit_NAME)];
13737 -- This pragma is useable only in GNAT_Mode, where it is used like
13738 -- pragma Preelaborate but it is only effective in Ada 2005 mode
13739 -- (otherwise it is ignored). This is used to implement AI-362 which
13740 -- recategorizes some run-time packages in Ada 2005 mode.
13742 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
13747 Check_Valid_Library_Unit_Pragma;
13749 if not GNAT_Mode then
13750 Error_Pragma ("pragma% only available in GNAT mode");
13753 if Nkind (N) = N_Null_Statement then
13757 -- This is one of the few cases where we need to test the value of
13758 -- Ada_Version_Explicit rather than Ada_Version (which is always
13759 -- set to Ada_2012 in a predefined unit), we need to know the
13760 -- explicit version set to know if this pragma is active.
13762 if Ada_Version_Explicit >= Ada_2005 then
13763 Ent := Find_Lib_Unit_Name;
13764 Set_Is_Preelaborated (Ent);
13765 Set_Suppress_Elaboration_Warnings (Ent);
13767 end Preelaborate_05;
13773 -- pragma Priority (EXPRESSION);
13775 when Pragma_Priority => Priority : declare
13776 P : constant Node_Id := Parent (N);
13781 Check_No_Identifiers;
13782 Check_Arg_Count (1);
13786 if Nkind (P) = N_Subprogram_Body then
13787 Check_In_Main_Program;
13789 Ent := Defining_Unit_Name (Specification (P));
13791 if Nkind (Ent) = N_Defining_Program_Unit_Name then
13792 Ent := Defining_Identifier (Ent);
13795 Arg := Get_Pragma_Arg (Arg1);
13796 Analyze_And_Resolve (Arg, Standard_Integer);
13800 if not Is_Static_Expression (Arg) then
13801 Flag_Non_Static_Expr
13802 ("main subprogram priority is not static!", Arg);
13805 -- If constraint error, then we already signalled an error
13807 elsif Raises_Constraint_Error (Arg) then
13810 -- Otherwise check in range
13814 Val : constant Uint := Expr_Value (Arg);
13818 or else Val > Expr_Value (Expression
13819 (Parent (RTE (RE_Max_Priority))))
13822 ("main subprogram priority is out of range", Arg1);
13828 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
13830 -- Load an arbitrary entity from System.Tasking to make sure
13831 -- this package is implicitly with'ed, since we need to have
13832 -- the tasking run-time active for the pragma Priority to have
13836 Discard : Entity_Id;
13837 pragma Warnings (Off, Discard);
13839 Discard := RTE (RE_Task_List);
13842 -- Task or Protected, must be of type Integer
13844 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
13845 Arg := Get_Pragma_Arg (Arg1);
13846 Ent := Defining_Identifier (Parent (P));
13848 -- The expression must be analyzed in the special manner
13849 -- described in "Handling of Default and Per-Object
13850 -- Expressions" in sem.ads.
13852 Preanalyze_Spec_Expression (Arg, Standard_Integer);
13854 if not Is_Static_Expression (Arg) then
13855 Check_Restriction (Static_Priorities, Arg);
13858 -- Anything else is incorrect
13864 -- Check duplicate pragma before we chain the pragma in the Rep
13865 -- Item chain of Ent.
13867 Check_Duplicate_Pragma (Ent);
13868 Record_Rep_Item (Ent, N);
13871 -----------------------------------
13872 -- Priority_Specific_Dispatching --
13873 -----------------------------------
13875 -- pragma Priority_Specific_Dispatching (
13876 -- policy_IDENTIFIER,
13877 -- first_priority_EXPRESSION,
13878 -- last_priority_EXPRESSION);
13880 when Pragma_Priority_Specific_Dispatching =>
13881 Priority_Specific_Dispatching : declare
13882 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
13883 -- This is the entity System.Any_Priority;
13886 Lower_Bound : Node_Id;
13887 Upper_Bound : Node_Id;
13893 Check_Arg_Count (3);
13894 Check_No_Identifiers;
13895 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13896 Check_Valid_Configuration_Pragma;
13897 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13898 DP := Fold_Upper (Name_Buffer (1));
13900 Lower_Bound := Get_Pragma_Arg (Arg2);
13901 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
13902 Lower_Val := Expr_Value (Lower_Bound);
13904 Upper_Bound := Get_Pragma_Arg (Arg3);
13905 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
13906 Upper_Val := Expr_Value (Upper_Bound);
13908 -- It is not allowed to use Task_Dispatching_Policy and
13909 -- Priority_Specific_Dispatching in the same partition.
13911 if Task_Dispatching_Policy /= ' ' then
13912 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13914 ("pragma% incompatible with Task_Dispatching_Policy#");
13916 -- Check lower bound in range
13918 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
13920 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
13923 ("first_priority is out of range", Arg2);
13925 -- Check upper bound in range
13927 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
13929 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
13932 ("last_priority is out of range", Arg3);
13934 -- Check that the priority range is valid
13936 elsif Lower_Val > Upper_Val then
13938 ("last_priority_expression must be greater than" &
13939 " or equal to first_priority_expression");
13941 -- Store the new policy, but always preserve System_Location since
13942 -- we like the error message with the run-time name.
13945 -- Check overlapping in the priority ranges specified in other
13946 -- Priority_Specific_Dispatching pragmas within the same
13947 -- partition. We can only check those we know about!
13950 Specific_Dispatching.First .. Specific_Dispatching.Last
13952 if Specific_Dispatching.Table (J).First_Priority in
13953 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
13954 or else Specific_Dispatching.Table (J).Last_Priority in
13955 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
13958 Specific_Dispatching.Table (J).Pragma_Loc;
13960 ("priority range overlaps with "
13961 & "Priority_Specific_Dispatching#");
13965 -- The use of Priority_Specific_Dispatching is incompatible
13966 -- with Task_Dispatching_Policy.
13968 if Task_Dispatching_Policy /= ' ' then
13969 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13971 ("Priority_Specific_Dispatching incompatible "
13972 & "with Task_Dispatching_Policy#");
13975 -- The use of Priority_Specific_Dispatching forces ceiling
13978 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
13979 Error_Msg_Sloc := Locking_Policy_Sloc;
13981 ("Priority_Specific_Dispatching incompatible "
13982 & "with Locking_Policy#");
13984 -- Set the Ceiling_Locking policy, but preserve System_Location
13985 -- since we like the error message with the run time name.
13988 Locking_Policy := 'C';
13990 if Locking_Policy_Sloc /= System_Location then
13991 Locking_Policy_Sloc := Loc;
13995 -- Add entry in the table
13997 Specific_Dispatching.Append
13998 ((Dispatching_Policy => DP,
13999 First_Priority => UI_To_Int (Lower_Val),
14000 Last_Priority => UI_To_Int (Upper_Val),
14001 Pragma_Loc => Loc));
14003 end Priority_Specific_Dispatching;
14009 -- pragma Profile (profile_IDENTIFIER);
14011 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
14013 when Pragma_Profile =>
14015 Check_Arg_Count (1);
14016 Check_Valid_Configuration_Pragma;
14017 Check_No_Identifiers;
14020 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14023 if Chars (Argx) = Name_Ravenscar then
14024 Set_Ravenscar_Profile (N);
14026 elsif Chars (Argx) = Name_Restricted then
14027 Set_Profile_Restrictions
14029 N, Warn => Treat_Restrictions_As_Warnings);
14031 elsif Chars (Argx) = Name_Rational then
14032 Set_Rational_Profile;
14034 elsif Chars (Argx) = Name_No_Implementation_Extensions then
14035 Set_Profile_Restrictions
14036 (No_Implementation_Extensions,
14037 N, Warn => Treat_Restrictions_As_Warnings);
14040 Error_Pragma_Arg ("& is not a valid profile", Argx);
14044 ----------------------
14045 -- Profile_Warnings --
14046 ----------------------
14048 -- pragma Profile_Warnings (profile_IDENTIFIER);
14050 -- profile_IDENTIFIER => Restricted | Ravenscar
14052 when Pragma_Profile_Warnings =>
14054 Check_Arg_Count (1);
14055 Check_Valid_Configuration_Pragma;
14056 Check_No_Identifiers;
14059 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14062 if Chars (Argx) = Name_Ravenscar then
14063 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
14065 elsif Chars (Argx) = Name_Restricted then
14066 Set_Profile_Restrictions (Restricted, N, Warn => True);
14068 elsif Chars (Argx) = Name_No_Implementation_Extensions then
14069 Set_Profile_Restrictions
14070 (No_Implementation_Extensions, N, Warn => True);
14073 Error_Pragma_Arg ("& is not a valid profile", Argx);
14077 --------------------------
14078 -- Propagate_Exceptions --
14079 --------------------------
14081 -- pragma Propagate_Exceptions;
14083 -- Note: this pragma is obsolete and has no effect
14085 when Pragma_Propagate_Exceptions =>
14087 Check_Arg_Count (0);
14089 if In_Extended_Main_Source_Unit (N) then
14090 Propagate_Exceptions := True;
14097 -- pragma Psect_Object (
14098 -- [Internal =>] LOCAL_NAME,
14099 -- [, [External =>] EXTERNAL_SYMBOL]
14100 -- [, [Size =>] EXTERNAL_SYMBOL]);
14102 when Pragma_Psect_Object | Pragma_Common_Object =>
14103 Psect_Object : declare
14104 Args : Args_List (1 .. 3);
14105 Names : constant Name_List (1 .. 3) := (
14110 Internal : Node_Id renames Args (1);
14111 External : Node_Id renames Args (2);
14112 Size : Node_Id renames Args (3);
14114 Def_Id : Entity_Id;
14116 procedure Check_Too_Long (Arg : Node_Id);
14117 -- Posts message if the argument is an identifier with more
14118 -- than 31 characters, or a string literal with more than
14119 -- 31 characters, and we are operating under VMS
14121 --------------------
14122 -- Check_Too_Long --
14123 --------------------
14125 procedure Check_Too_Long (Arg : Node_Id) is
14126 X : constant Node_Id := Original_Node (Arg);
14129 if not Nkind_In (X, N_String_Literal, N_Identifier) then
14131 ("inappropriate argument for pragma %", Arg);
14134 if OpenVMS_On_Target then
14135 if (Nkind (X) = N_String_Literal
14136 and then String_Length (Strval (X)) > 31)
14138 (Nkind (X) = N_Identifier
14139 and then Length_Of_Name (Chars (X)) > 31)
14142 ("argument for pragma % is longer than 31 characters",
14146 end Check_Too_Long;
14148 -- Start of processing for Common_Object/Psect_Object
14152 Gather_Associations (Names, Args);
14153 Process_Extended_Import_Export_Internal_Arg (Internal);
14155 Def_Id := Entity (Internal);
14157 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
14159 ("pragma% must designate an object", Internal);
14162 Check_Too_Long (Internal);
14164 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
14166 ("cannot use pragma% for imported/exported object",
14170 if Is_Concurrent_Type (Etype (Internal)) then
14172 ("cannot specify pragma % for task/protected object",
14176 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
14178 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
14180 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
14183 if Ekind (Def_Id) = E_Constant then
14185 ("cannot specify pragma % for a constant", Internal);
14188 if Is_Record_Type (Etype (Internal)) then
14194 Ent := First_Entity (Etype (Internal));
14195 while Present (Ent) loop
14196 Decl := Declaration_Node (Ent);
14198 if Ekind (Ent) = E_Component
14199 and then Nkind (Decl) = N_Component_Declaration
14200 and then Present (Expression (Decl))
14201 and then Warn_On_Export_Import
14204 ("?x?object for pragma % has defaults", Internal);
14214 if Present (Size) then
14215 Check_Too_Long (Size);
14218 if Present (External) then
14219 Check_Arg_Is_External_Name (External);
14220 Check_Too_Long (External);
14223 -- If all error tests pass, link pragma on to the rep item chain
14225 Record_Rep_Item (Def_Id, N);
14232 -- pragma Pure [(library_unit_NAME)];
14234 when Pragma_Pure => Pure : declare
14238 Check_Ada_83_Warning;
14239 Check_Valid_Library_Unit_Pragma;
14241 if Nkind (N) = N_Null_Statement then
14245 Ent := Find_Lib_Unit_Name;
14247 Set_Has_Pragma_Pure (Ent);
14248 Set_Suppress_Elaboration_Warnings (Ent);
14255 -- pragma Pure_05 [(library_unit_NAME)];
14257 -- This pragma is useable only in GNAT_Mode, where it is used like
14258 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
14259 -- it is ignored). It may be used after a pragma Preelaborate, in
14260 -- which case it overrides the effect of the pragma Preelaborate.
14261 -- This is used to implement AI-362 which recategorizes some run-time
14262 -- packages in Ada 2005 mode.
14264 when Pragma_Pure_05 => Pure_05 : declare
14269 Check_Valid_Library_Unit_Pragma;
14271 if not GNAT_Mode then
14272 Error_Pragma ("pragma% only available in GNAT mode");
14275 if Nkind (N) = N_Null_Statement then
14279 -- This is one of the few cases where we need to test the value of
14280 -- Ada_Version_Explicit rather than Ada_Version (which is always
14281 -- set to Ada_2012 in a predefined unit), we need to know the
14282 -- explicit version set to know if this pragma is active.
14284 if Ada_Version_Explicit >= Ada_2005 then
14285 Ent := Find_Lib_Unit_Name;
14286 Set_Is_Preelaborated (Ent, False);
14288 Set_Suppress_Elaboration_Warnings (Ent);
14296 -- pragma Pure_12 [(library_unit_NAME)];
14298 -- This pragma is useable only in GNAT_Mode, where it is used like
14299 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
14300 -- it is ignored). It may be used after a pragma Preelaborate, in
14301 -- which case it overrides the effect of the pragma Preelaborate.
14302 -- This is used to implement AI05-0212 which recategorizes some
14303 -- run-time packages in Ada 2012 mode.
14305 when Pragma_Pure_12 => Pure_12 : declare
14310 Check_Valid_Library_Unit_Pragma;
14312 if not GNAT_Mode then
14313 Error_Pragma ("pragma% only available in GNAT mode");
14316 if Nkind (N) = N_Null_Statement then
14320 -- This is one of the few cases where we need to test the value of
14321 -- Ada_Version_Explicit rather than Ada_Version (which is always
14322 -- set to Ada_2012 in a predefined unit), we need to know the
14323 -- explicit version set to know if this pragma is active.
14325 if Ada_Version_Explicit >= Ada_2012 then
14326 Ent := Find_Lib_Unit_Name;
14327 Set_Is_Preelaborated (Ent, False);
14329 Set_Suppress_Elaboration_Warnings (Ent);
14333 -------------------
14334 -- Pure_Function --
14335 -------------------
14337 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
14339 when Pragma_Pure_Function => Pure_Function : declare
14342 Def_Id : Entity_Id;
14343 Effective : Boolean := False;
14347 Check_Arg_Count (1);
14348 Check_Optional_Identifier (Arg1, Name_Entity);
14349 Check_Arg_Is_Local_Name (Arg1);
14350 E_Id := Get_Pragma_Arg (Arg1);
14352 if Error_Posted (E_Id) then
14356 -- Loop through homonyms (overloadings) of referenced entity
14358 E := Entity (E_Id);
14360 if Present (E) then
14362 Def_Id := Get_Base_Subprogram (E);
14364 if not Ekind_In (Def_Id, E_Function,
14365 E_Generic_Function,
14369 ("pragma% requires a function name", Arg1);
14372 Set_Is_Pure (Def_Id);
14374 if not Has_Pragma_Pure_Function (Def_Id) then
14375 Set_Has_Pragma_Pure_Function (Def_Id);
14379 exit when From_Aspect_Specification (N);
14381 exit when No (E) or else Scope (E) /= Current_Scope;
14385 and then Warn_On_Redundant_Constructs
14388 ("pragma Pure_Function on& is redundant?r?",
14394 --------------------
14395 -- Queuing_Policy --
14396 --------------------
14398 -- pragma Queuing_Policy (policy_IDENTIFIER);
14400 when Pragma_Queuing_Policy => declare
14404 Check_Ada_83_Warning;
14405 Check_Arg_Count (1);
14406 Check_No_Identifiers;
14407 Check_Arg_Is_Queuing_Policy (Arg1);
14408 Check_Valid_Configuration_Pragma;
14409 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14410 QP := Fold_Upper (Name_Buffer (1));
14412 if Queuing_Policy /= ' '
14413 and then Queuing_Policy /= QP
14415 Error_Msg_Sloc := Queuing_Policy_Sloc;
14416 Error_Pragma ("queuing policy incompatible with policy#");
14418 -- Set new policy, but always preserve System_Location since we
14419 -- like the error message with the run time name.
14422 Queuing_Policy := QP;
14424 if Queuing_Policy_Sloc /= System_Location then
14425 Queuing_Policy_Sloc := Loc;
14434 -- pragma Rational, for compatibility with foreign compiler
14436 when Pragma_Rational =>
14437 Set_Rational_Profile;
14439 -----------------------
14440 -- Relative_Deadline --
14441 -----------------------
14443 -- pragma Relative_Deadline (time_span_EXPRESSION);
14445 when Pragma_Relative_Deadline => Relative_Deadline : declare
14446 P : constant Node_Id := Parent (N);
14451 Check_No_Identifiers;
14452 Check_Arg_Count (1);
14454 Arg := Get_Pragma_Arg (Arg1);
14456 -- The expression must be analyzed in the special manner described
14457 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
14459 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
14463 if Nkind (P) = N_Subprogram_Body then
14464 Check_In_Main_Program;
14466 -- Only Task and subprogram cases allowed
14468 elsif Nkind (P) /= N_Task_Definition then
14472 -- Check duplicate pragma before we set the corresponding flag
14474 if Has_Relative_Deadline_Pragma (P) then
14475 Error_Pragma ("duplicate pragma% not allowed");
14478 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
14479 -- Relative_Deadline pragma node cannot be inserted in the Rep
14480 -- Item chain of Ent since it is rewritten by the expander as a
14481 -- procedure call statement that will break the chain.
14483 Set_Has_Relative_Deadline_Pragma (P, True);
14484 end Relative_Deadline;
14486 ------------------------
14487 -- Remote_Access_Type --
14488 ------------------------
14490 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
14492 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
14497 Check_Arg_Count (1);
14498 Check_Optional_Identifier (Arg1, Name_Entity);
14499 Check_Arg_Is_Local_Name (Arg1);
14501 E := Entity (Get_Pragma_Arg (Arg1));
14503 if Nkind (Parent (E)) = N_Formal_Type_Declaration
14504 and then Ekind (E) = E_General_Access_Type
14505 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
14506 and then Scope (Root_Type (Directly_Designated_Type (E)))
14508 and then Is_Valid_Remote_Object_Type
14509 (Root_Type (Directly_Designated_Type (E)))
14511 Set_Is_Remote_Types (E);
14515 ("pragma% applies only to formal access to classwide types",
14518 end Remote_Access_Type;
14520 ---------------------------
14521 -- Remote_Call_Interface --
14522 ---------------------------
14524 -- pragma Remote_Call_Interface [(library_unit_NAME)];
14526 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
14527 Cunit_Node : Node_Id;
14528 Cunit_Ent : Entity_Id;
14532 Check_Ada_83_Warning;
14533 Check_Valid_Library_Unit_Pragma;
14535 if Nkind (N) = N_Null_Statement then
14539 Cunit_Node := Cunit (Current_Sem_Unit);
14540 K := Nkind (Unit (Cunit_Node));
14541 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14543 if K = N_Package_Declaration
14544 or else K = N_Generic_Package_Declaration
14545 or else K = N_Subprogram_Declaration
14546 or else K = N_Generic_Subprogram_Declaration
14547 or else (K = N_Subprogram_Body
14548 and then Acts_As_Spec (Unit (Cunit_Node)))
14553 "pragma% must apply to package or subprogram declaration");
14556 Set_Is_Remote_Call_Interface (Cunit_Ent);
14557 end Remote_Call_Interface;
14563 -- pragma Remote_Types [(library_unit_NAME)];
14565 when Pragma_Remote_Types => Remote_Types : declare
14566 Cunit_Node : Node_Id;
14567 Cunit_Ent : Entity_Id;
14570 Check_Ada_83_Warning;
14571 Check_Valid_Library_Unit_Pragma;
14573 if Nkind (N) = N_Null_Statement then
14577 Cunit_Node := Cunit (Current_Sem_Unit);
14578 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14580 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
14581 N_Generic_Package_Declaration)
14584 ("pragma% can only apply to a package declaration");
14587 Set_Is_Remote_Types (Cunit_Ent);
14594 -- pragma Ravenscar;
14596 when Pragma_Ravenscar =>
14598 Check_Arg_Count (0);
14599 Check_Valid_Configuration_Pragma;
14600 Set_Ravenscar_Profile (N);
14602 if Warn_On_Obsolescent_Feature then
14604 ("pragma Ravenscar is an obsolescent feature?j?", N);
14606 ("|use pragma Profile (Ravenscar) instead?j?", N);
14609 -------------------------
14610 -- Restricted_Run_Time --
14611 -------------------------
14613 -- pragma Restricted_Run_Time;
14615 when Pragma_Restricted_Run_Time =>
14617 Check_Arg_Count (0);
14618 Check_Valid_Configuration_Pragma;
14619 Set_Profile_Restrictions
14620 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
14622 if Warn_On_Obsolescent_Feature then
14624 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
14627 ("|use pragma Profile (Restricted) instead?j?", N);
14634 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
14637 -- restriction_IDENTIFIER
14638 -- | restriction_parameter_IDENTIFIER => EXPRESSION
14640 when Pragma_Restrictions =>
14641 Process_Restrictions_Or_Restriction_Warnings
14642 (Warn => Treat_Restrictions_As_Warnings);
14644 --------------------------
14645 -- Restriction_Warnings --
14646 --------------------------
14648 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
14651 -- restriction_IDENTIFIER
14652 -- | restriction_parameter_IDENTIFIER => EXPRESSION
14654 when Pragma_Restriction_Warnings =>
14656 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
14662 -- pragma Reviewable;
14664 when Pragma_Reviewable =>
14665 Check_Ada_83_Warning;
14666 Check_Arg_Count (0);
14668 -- Call dummy debugging function rv. This is done to assist front
14669 -- end debugging. By placing a Reviewable pragma in the source
14670 -- program, a breakpoint on rv catches this place in the source,
14671 -- allowing convenient stepping to the point of interest.
14675 --------------------------
14676 -- Short_Circuit_And_Or --
14677 --------------------------
14679 when Pragma_Short_Circuit_And_Or =>
14681 Check_Arg_Count (0);
14682 Check_Valid_Configuration_Pragma;
14683 Short_Circuit_And_Or := True;
14685 -------------------
14686 -- Share_Generic --
14687 -------------------
14689 -- pragma Share_Generic (NAME {, NAME});
14691 when Pragma_Share_Generic =>
14693 Process_Generic_List;
14699 -- pragma Shared (LOCAL_NAME);
14701 when Pragma_Shared =>
14703 Process_Atomic_Shared_Volatile;
14705 --------------------
14706 -- Shared_Passive --
14707 --------------------
14709 -- pragma Shared_Passive [(library_unit_NAME)];
14711 -- Set the flag Is_Shared_Passive of program unit name entity
14713 when Pragma_Shared_Passive => Shared_Passive : declare
14714 Cunit_Node : Node_Id;
14715 Cunit_Ent : Entity_Id;
14718 Check_Ada_83_Warning;
14719 Check_Valid_Library_Unit_Pragma;
14721 if Nkind (N) = N_Null_Statement then
14725 Cunit_Node := Cunit (Current_Sem_Unit);
14726 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14728 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
14729 N_Generic_Package_Declaration)
14732 ("pragma% can only apply to a package declaration");
14735 Set_Is_Shared_Passive (Cunit_Ent);
14736 end Shared_Passive;
14738 -----------------------
14739 -- Short_Descriptors --
14740 -----------------------
14742 -- pragma Short_Descriptors;
14744 when Pragma_Short_Descriptors =>
14746 Check_Arg_Count (0);
14747 Check_Valid_Configuration_Pragma;
14748 Short_Descriptors := True;
14750 ------------------------------
14751 -- Simple_Storage_Pool_Type --
14752 ------------------------------
14754 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
14756 when Pragma_Simple_Storage_Pool_Type =>
14757 Simple_Storage_Pool_Type : declare
14763 Check_Arg_Count (1);
14764 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14766 Type_Id := Get_Pragma_Arg (Arg1);
14767 Find_Type (Type_Id);
14768 Typ := Entity (Type_Id);
14770 if Typ = Any_Type then
14774 -- We require the pragma to apply to a type declared in a package
14775 -- declaration, but not (immediately) within a package body.
14777 if Ekind (Current_Scope) /= E_Package
14778 or else In_Package_Body (Current_Scope)
14781 ("pragma% can only apply to type declared immediately " &
14782 "within a package declaration");
14785 -- A simple storage pool type must be an immutably limited record
14786 -- or private type. If the pragma is given for a private type,
14787 -- the full type is similarly restricted (which is checked later
14788 -- in Freeze_Entity).
14790 if Is_Record_Type (Typ)
14791 and then not Is_Immutably_Limited_Type (Typ)
14794 ("pragma% can only apply to explicitly limited record type");
14796 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
14798 ("pragma% can only apply to a private type that is limited");
14800 elsif not Is_Record_Type (Typ)
14801 and then not Is_Private_Type (Typ)
14804 ("pragma% can only apply to limited record or private type");
14807 Record_Rep_Item (Typ, N);
14808 end Simple_Storage_Pool_Type;
14810 ----------------------
14811 -- Source_File_Name --
14812 ----------------------
14814 -- There are five forms for this pragma:
14816 -- pragma Source_File_Name (
14817 -- [UNIT_NAME =>] unit_NAME,
14818 -- BODY_FILE_NAME => STRING_LITERAL
14819 -- [, [INDEX =>] INTEGER_LITERAL]);
14821 -- pragma Source_File_Name (
14822 -- [UNIT_NAME =>] unit_NAME,
14823 -- SPEC_FILE_NAME => STRING_LITERAL
14824 -- [, [INDEX =>] INTEGER_LITERAL]);
14826 -- pragma Source_File_Name (
14827 -- BODY_FILE_NAME => STRING_LITERAL
14828 -- [, DOT_REPLACEMENT => STRING_LITERAL]
14829 -- [, CASING => CASING_SPEC]);
14831 -- pragma Source_File_Name (
14832 -- SPEC_FILE_NAME => STRING_LITERAL
14833 -- [, DOT_REPLACEMENT => STRING_LITERAL]
14834 -- [, CASING => CASING_SPEC]);
14836 -- pragma Source_File_Name (
14837 -- SUBUNIT_FILE_NAME => STRING_LITERAL
14838 -- [, DOT_REPLACEMENT => STRING_LITERAL]
14839 -- [, CASING => CASING_SPEC]);
14841 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
14843 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
14844 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
14845 -- only be used when no project file is used, while SFNP can only be
14846 -- used when a project file is used.
14848 -- No processing here. Processing was completed during parsing, since
14849 -- we need to have file names set as early as possible. Units are
14850 -- loaded well before semantic processing starts.
14852 -- The only processing we defer to this point is the check for
14853 -- correct placement.
14855 when Pragma_Source_File_Name =>
14857 Check_Valid_Configuration_Pragma;
14859 ------------------------------
14860 -- Source_File_Name_Project --
14861 ------------------------------
14863 -- See Source_File_Name for syntax
14865 -- No processing here. Processing was completed during parsing, since
14866 -- we need to have file names set as early as possible. Units are
14867 -- loaded well before semantic processing starts.
14869 -- The only processing we defer to this point is the check for
14870 -- correct placement.
14872 when Pragma_Source_File_Name_Project =>
14874 Check_Valid_Configuration_Pragma;
14876 -- Check that a pragma Source_File_Name_Project is used only in a
14877 -- configuration pragmas file.
14879 -- Pragmas Source_File_Name_Project should only be generated by
14880 -- the Project Manager in configuration pragmas files.
14882 -- This is really an ugly test. It seems to depend on some
14883 -- accidental and undocumented property. At the very least it
14884 -- needs to be documented, but it would be better to have a
14885 -- clean way of testing if we are in a configuration file???
14887 if Present (Parent (N)) then
14889 ("pragma% can only appear in a configuration pragmas file");
14892 ----------------------
14893 -- Source_Reference --
14894 ----------------------
14896 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
14898 -- Nothing to do, all processing completed in Par.Prag, since we need
14899 -- the information for possible parser messages that are output.
14901 when Pragma_Source_Reference =>
14904 --------------------------------
14905 -- Static_Elaboration_Desired --
14906 --------------------------------
14908 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
14910 when Pragma_Static_Elaboration_Desired =>
14912 Check_At_Most_N_Arguments (1);
14914 if Is_Compilation_Unit (Current_Scope)
14915 and then Ekind (Current_Scope) = E_Package
14917 Set_Static_Elaboration_Desired (Current_Scope, True);
14919 Error_Pragma ("pragma% must apply to a library-level package");
14926 -- pragma Storage_Size (EXPRESSION);
14928 when Pragma_Storage_Size => Storage_Size : declare
14929 P : constant Node_Id := Parent (N);
14933 Check_No_Identifiers;
14934 Check_Arg_Count (1);
14936 -- The expression must be analyzed in the special manner described
14937 -- in "Handling of Default Expressions" in sem.ads.
14939 Arg := Get_Pragma_Arg (Arg1);
14940 Preanalyze_Spec_Expression (Arg, Any_Integer);
14942 if not Is_Static_Expression (Arg) then
14943 Check_Restriction (Static_Storage_Size, Arg);
14946 if Nkind (P) /= N_Task_Definition then
14951 if Has_Storage_Size_Pragma (P) then
14952 Error_Pragma ("duplicate pragma% not allowed");
14954 Set_Has_Storage_Size_Pragma (P, True);
14957 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
14965 -- pragma Storage_Unit (NUMERIC_LITERAL);
14967 -- Only permitted argument is System'Storage_Unit value
14969 when Pragma_Storage_Unit =>
14970 Check_No_Identifiers;
14971 Check_Arg_Count (1);
14972 Check_Arg_Is_Integer_Literal (Arg1);
14974 if Intval (Get_Pragma_Arg (Arg1)) /=
14975 UI_From_Int (Ttypes.System_Storage_Unit)
14977 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
14979 ("the only allowed argument for pragma% is ^", Arg1);
14982 --------------------
14983 -- Stream_Convert --
14984 --------------------
14986 -- pragma Stream_Convert (
14987 -- [Entity =>] type_LOCAL_NAME,
14988 -- [Read =>] function_NAME,
14989 -- [Write =>] function NAME);
14991 when Pragma_Stream_Convert => Stream_Convert : declare
14993 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
14994 -- Check that the given argument is the name of a local function
14995 -- of one argument that is not overloaded earlier in the current
14996 -- local scope. A check is also made that the argument is a
14997 -- function with one parameter.
14999 --------------------------------------
15000 -- Check_OK_Stream_Convert_Function --
15001 --------------------------------------
15003 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
15007 Check_Arg_Is_Local_Name (Arg);
15008 Ent := Entity (Get_Pragma_Arg (Arg));
15010 if Has_Homonym (Ent) then
15012 ("argument for pragma% may not be overloaded", Arg);
15015 if Ekind (Ent) /= E_Function
15016 or else No (First_Formal (Ent))
15017 or else Present (Next_Formal (First_Formal (Ent)))
15020 ("argument for pragma% must be" &
15021 " function of one argument", Arg);
15023 end Check_OK_Stream_Convert_Function;
15025 -- Start of processing for Stream_Convert
15029 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
15030 Check_Arg_Count (3);
15031 Check_Optional_Identifier (Arg1, Name_Entity);
15032 Check_Optional_Identifier (Arg2, Name_Read);
15033 Check_Optional_Identifier (Arg3, Name_Write);
15034 Check_Arg_Is_Local_Name (Arg1);
15035 Check_OK_Stream_Convert_Function (Arg2);
15036 Check_OK_Stream_Convert_Function (Arg3);
15039 Typ : constant Entity_Id :=
15040 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
15041 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
15042 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
15045 Check_First_Subtype (Arg1);
15047 -- Check for too early or too late. Note that we don't enforce
15048 -- the rule about primitive operations in this case, since, as
15049 -- is the case for explicit stream attributes themselves, these
15050 -- restrictions are not appropriate. Note that the chaining of
15051 -- the pragma by Rep_Item_Too_Late is actually the critical
15052 -- processing done for this pragma.
15054 if Rep_Item_Too_Early (Typ, N)
15056 Rep_Item_Too_Late (Typ, N, FOnly => True)
15061 -- Return if previous error
15063 if Etype (Typ) = Any_Type
15065 Etype (Read) = Any_Type
15067 Etype (Write) = Any_Type
15074 if Underlying_Type (Etype (Read)) /= Typ then
15076 ("incorrect return type for function&", Arg2);
15079 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
15081 ("incorrect parameter type for function&", Arg3);
15084 if Underlying_Type (Etype (First_Formal (Read))) /=
15085 Underlying_Type (Etype (Write))
15088 ("result type of & does not match Read parameter type",
15092 end Stream_Convert;
15098 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
15100 -- This is processed by the parser since some of the style checks
15101 -- take place during source scanning and parsing. This means that
15102 -- we don't need to issue error messages here.
15104 when Pragma_Style_Checks => Style_Checks : declare
15105 A : constant Node_Id := Get_Pragma_Arg (Arg1);
15111 Check_No_Identifiers;
15113 -- Two argument form
15115 if Arg_Count = 2 then
15116 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
15123 E_Id := Get_Pragma_Arg (Arg2);
15126 if not Is_Entity_Name (E_Id) then
15128 ("second argument of pragma% must be entity name",
15132 E := Entity (E_Id);
15134 if not Ignore_Style_Checks_Pragmas then
15139 Set_Suppress_Style_Checks
15140 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
15141 exit when No (Homonym (E));
15148 -- One argument form
15151 Check_Arg_Count (1);
15153 if Nkind (A) = N_String_Literal then
15157 Slen : constant Natural := Natural (String_Length (S));
15158 Options : String (1 .. Slen);
15164 C := Get_String_Char (S, Int (J));
15165 exit when not In_Character_Range (C);
15166 Options (J) := Get_Character (C);
15168 -- If at end of string, set options. As per discussion
15169 -- above, no need to check for errors, since we issued
15170 -- them in the parser.
15173 if not Ignore_Style_Checks_Pragmas then
15174 Set_Style_Check_Options (Options);
15184 elsif Nkind (A) = N_Identifier then
15185 if Chars (A) = Name_All_Checks then
15186 if not Ignore_Style_Checks_Pragmas then
15188 Set_GNAT_Style_Check_Options;
15190 Set_Default_Style_Check_Options;
15194 elsif Chars (A) = Name_On then
15195 if not Ignore_Style_Checks_Pragmas then
15196 Style_Check := True;
15199 elsif Chars (A) = Name_Off then
15200 if not Ignore_Style_Checks_Pragmas then
15201 Style_Check := False;
15212 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
15214 when Pragma_Subtitle =>
15216 Check_Arg_Count (1);
15217 Check_Optional_Identifier (Arg1, Name_Subtitle);
15218 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
15225 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
15227 when Pragma_Suppress =>
15228 Process_Suppress_Unsuppress (True);
15234 -- pragma Suppress_All;
15236 -- The only check made here is that the pragma has no arguments.
15237 -- There are no placement rules, and the processing required (setting
15238 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
15239 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
15240 -- then creates and inserts a pragma Suppress (All_Checks).
15242 when Pragma_Suppress_All =>
15244 Check_Arg_Count (0);
15246 -------------------------
15247 -- Suppress_Debug_Info --
15248 -------------------------
15250 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
15252 when Pragma_Suppress_Debug_Info =>
15254 Check_Arg_Count (1);
15255 Check_Optional_Identifier (Arg1, Name_Entity);
15256 Check_Arg_Is_Local_Name (Arg1);
15257 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
15259 ----------------------------------
15260 -- Suppress_Exception_Locations --
15261 ----------------------------------
15263 -- pragma Suppress_Exception_Locations;
15265 when Pragma_Suppress_Exception_Locations =>
15267 Check_Arg_Count (0);
15268 Check_Valid_Configuration_Pragma;
15269 Exception_Locations_Suppressed := True;
15271 -----------------------------
15272 -- Suppress_Initialization --
15273 -----------------------------
15275 -- pragma Suppress_Initialization ([Entity =>] type_Name);
15277 when Pragma_Suppress_Initialization => Suppress_Init : declare
15283 Check_Arg_Count (1);
15284 Check_Optional_Identifier (Arg1, Name_Entity);
15285 Check_Arg_Is_Local_Name (Arg1);
15287 E_Id := Get_Pragma_Arg (Arg1);
15289 if Etype (E_Id) = Any_Type then
15293 E := Entity (E_Id);
15295 if not Is_Type (E) then
15296 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
15299 if Rep_Item_Too_Early (E, N)
15301 Rep_Item_Too_Late (E, N, FOnly => True)
15306 -- For incomplete/private type, set flag on full view
15308 if Is_Incomplete_Or_Private_Type (E) then
15309 if No (Full_View (Base_Type (E))) then
15311 ("argument of pragma% cannot be an incomplete type", Arg1);
15313 Set_Suppress_Initialization (Full_View (Base_Type (E)));
15316 -- For first subtype, set flag on base type
15318 elsif Is_First_Subtype (E) then
15319 Set_Suppress_Initialization (Base_Type (E));
15321 -- For other than first subtype, set flag on subtype itself
15324 Set_Suppress_Initialization (E);
15332 -- pragma System_Name (DIRECT_NAME);
15334 -- Syntax check: one argument, which must be the identifier GNAT or
15335 -- the identifier GCC, no other identifiers are acceptable.
15337 when Pragma_System_Name =>
15339 Check_No_Identifiers;
15340 Check_Arg_Count (1);
15341 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
15343 -----------------------------
15344 -- Task_Dispatching_Policy --
15345 -----------------------------
15347 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
15349 when Pragma_Task_Dispatching_Policy => declare
15353 Check_Ada_83_Warning;
15354 Check_Arg_Count (1);
15355 Check_No_Identifiers;
15356 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
15357 Check_Valid_Configuration_Pragma;
15358 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15359 DP := Fold_Upper (Name_Buffer (1));
15361 if Task_Dispatching_Policy /= ' '
15362 and then Task_Dispatching_Policy /= DP
15364 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
15366 ("task dispatching policy incompatible with policy#");
15368 -- Set new policy, but always preserve System_Location since we
15369 -- like the error message with the run time name.
15372 Task_Dispatching_Policy := DP;
15374 if Task_Dispatching_Policy_Sloc /= System_Location then
15375 Task_Dispatching_Policy_Sloc := Loc;
15384 -- pragma Task_Info (EXPRESSION);
15386 when Pragma_Task_Info => Task_Info : declare
15387 P : constant Node_Id := Parent (N);
15393 if Nkind (P) /= N_Task_Definition then
15394 Error_Pragma ("pragma% must appear in task definition");
15397 Check_No_Identifiers;
15398 Check_Arg_Count (1);
15400 Analyze_And_Resolve
15401 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
15403 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
15407 Ent := Defining_Identifier (Parent (P));
15409 -- Check duplicate pragma before we chain the pragma in the Rep
15410 -- Item chain of Ent.
15413 (Ent, Name_Task_Info, Check_Parents => False)
15415 Error_Pragma ("duplicate pragma% not allowed");
15418 Record_Rep_Item (Ent, N);
15425 -- pragma Task_Name (string_EXPRESSION);
15427 when Pragma_Task_Name => Task_Name : declare
15428 P : constant Node_Id := Parent (N);
15433 Check_No_Identifiers;
15434 Check_Arg_Count (1);
15436 Arg := Get_Pragma_Arg (Arg1);
15438 -- The expression is used in the call to Create_Task, and must be
15439 -- expanded there, not in the context of the current spec. It must
15440 -- however be analyzed to capture global references, in case it
15441 -- appears in a generic context.
15443 Preanalyze_And_Resolve (Arg, Standard_String);
15445 if Nkind (P) /= N_Task_Definition then
15449 Ent := Defining_Identifier (Parent (P));
15451 -- Check duplicate pragma before we chain the pragma in the Rep
15452 -- Item chain of Ent.
15455 (Ent, Name_Task_Name, Check_Parents => False)
15457 Error_Pragma ("duplicate pragma% not allowed");
15460 Record_Rep_Item (Ent, N);
15467 -- pragma Task_Storage (
15468 -- [Task_Type =>] LOCAL_NAME,
15469 -- [Top_Guard =>] static_integer_EXPRESSION);
15471 when Pragma_Task_Storage => Task_Storage : declare
15472 Args : Args_List (1 .. 2);
15473 Names : constant Name_List (1 .. 2) := (
15477 Task_Type : Node_Id renames Args (1);
15478 Top_Guard : Node_Id renames Args (2);
15484 Gather_Associations (Names, Args);
15486 if No (Task_Type) then
15488 ("missing task_type argument for pragma%");
15491 Check_Arg_Is_Local_Name (Task_Type);
15493 Ent := Entity (Task_Type);
15495 if not Is_Task_Type (Ent) then
15497 ("argument for pragma% must be task type", Task_Type);
15500 if No (Top_Guard) then
15502 ("pragma% takes two arguments", Task_Type);
15504 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
15507 Check_First_Subtype (Task_Type);
15509 if Rep_Item_Too_Late (Ent, N) then
15518 -- pragma Test_Case
15519 -- ([Name =>] Static_String_EXPRESSION
15520 -- ,[Mode =>] MODE_TYPE
15521 -- [, Requires => Boolean_EXPRESSION]
15522 -- [, Ensures => Boolean_EXPRESSION]);
15524 -- MODE_TYPE ::= Nominal | Robustness
15526 when Pragma_Test_Case =>
15527 Check_Contract_Or_Test_Case;
15529 --------------------------
15530 -- Thread_Local_Storage --
15531 --------------------------
15533 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
15535 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
15541 Check_Arg_Count (1);
15542 Check_Optional_Identifier (Arg1, Name_Entity);
15543 Check_Arg_Is_Library_Level_Local_Name (Arg1);
15545 Id := Get_Pragma_Arg (Arg1);
15548 if not Is_Entity_Name (Id)
15549 or else Ekind (Entity (Id)) /= E_Variable
15551 Error_Pragma_Arg ("local variable name required", Arg1);
15556 if Rep_Item_Too_Early (E, N)
15557 or else Rep_Item_Too_Late (E, N)
15562 Set_Has_Pragma_Thread_Local_Storage (E);
15563 Set_Has_Gigi_Rep_Item (E);
15564 end Thread_Local_Storage;
15570 -- pragma Time_Slice (static_duration_EXPRESSION);
15572 when Pragma_Time_Slice => Time_Slice : declare
15578 Check_Arg_Count (1);
15579 Check_No_Identifiers;
15580 Check_In_Main_Program;
15581 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
15583 if not Error_Posted (Arg1) then
15585 while Present (Nod) loop
15586 if Nkind (Nod) = N_Pragma
15587 and then Pragma_Name (Nod) = Name_Time_Slice
15589 Error_Msg_Name_1 := Pname;
15590 Error_Msg_N ("duplicate pragma% not permitted", Nod);
15597 -- Process only if in main unit
15599 if Get_Source_Unit (Loc) = Main_Unit then
15600 Opt.Time_Slice_Set := True;
15601 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
15603 if Val <= Ureal_0 then
15604 Opt.Time_Slice_Value := 0;
15606 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
15607 Opt.Time_Slice_Value := 1_000_000_000;
15610 Opt.Time_Slice_Value :=
15611 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
15620 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
15622 -- TITLING_OPTION ::=
15623 -- [Title =>] STRING_LITERAL
15624 -- | [Subtitle =>] STRING_LITERAL
15626 when Pragma_Title => Title : declare
15627 Args : Args_List (1 .. 2);
15628 Names : constant Name_List (1 .. 2) := (
15634 Gather_Associations (Names, Args);
15637 for J in 1 .. 2 loop
15638 if Present (Args (J)) then
15639 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
15644 ---------------------
15645 -- Unchecked_Union --
15646 ---------------------
15648 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
15650 when Pragma_Unchecked_Union => Unchecked_Union : declare
15651 Assoc : constant Node_Id := Arg1;
15652 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
15662 Check_No_Identifiers;
15663 Check_Arg_Count (1);
15664 Check_Arg_Is_Local_Name (Arg1);
15666 Find_Type (Type_Id);
15668 Typ := Entity (Type_Id);
15671 or else Rep_Item_Too_Early (Typ, N)
15675 Typ := Underlying_Type (Typ);
15678 if Rep_Item_Too_Late (Typ, N) then
15682 Check_First_Subtype (Arg1);
15684 -- Note remaining cases are references to a type in the current
15685 -- declarative part. If we find an error, we post the error on
15686 -- the relevant type declaration at an appropriate point.
15688 if not Is_Record_Type (Typ) then
15689 Error_Msg_N ("unchecked union must be record type", Typ);
15692 elsif Is_Tagged_Type (Typ) then
15693 Error_Msg_N ("unchecked union must not be tagged", Typ);
15696 elsif not Has_Discriminants (Typ) then
15698 ("unchecked union must have one discriminant", Typ);
15701 -- Note: in previous versions of GNAT we used to check for limited
15702 -- types and give an error, but in fact the standard does allow
15703 -- Unchecked_Union on limited types, so this check was removed.
15705 -- Similarly, GNAT used to require that all discriminants have
15706 -- default values, but this is not mandated by the RM.
15708 -- Proceed with basic error checks completed
15711 Tdef := Type_Definition (Declaration_Node (Typ));
15712 Clist := Component_List (Tdef);
15714 -- Check presence of component list and variant part
15716 if No (Clist) or else No (Variant_Part (Clist)) then
15718 ("unchecked union must have variant part", Tdef);
15722 -- Check components
15724 Comp := First (Component_Items (Clist));
15725 while Present (Comp) loop
15726 Check_Component (Comp, Typ);
15730 -- Check variant part
15732 Vpart := Variant_Part (Clist);
15734 Variant := First (Variants (Vpart));
15735 while Present (Variant) loop
15736 Check_Variant (Variant, Typ);
15741 Set_Is_Unchecked_Union (Typ);
15742 Set_Convention (Typ, Convention_C);
15743 Set_Has_Unchecked_Union (Base_Type (Typ));
15744 Set_Is_Unchecked_Union (Base_Type (Typ));
15745 end Unchecked_Union;
15747 ------------------------
15748 -- Unimplemented_Unit --
15749 ------------------------
15751 -- pragma Unimplemented_Unit;
15753 -- Note: this only gives an error if we are generating code, or if
15754 -- we are in a generic library unit (where the pragma appears in the
15755 -- body, not in the spec).
15757 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
15758 Cunitent : constant Entity_Id :=
15759 Cunit_Entity (Get_Source_Unit (Loc));
15760 Ent_Kind : constant Entity_Kind :=
15765 Check_Arg_Count (0);
15767 if Operating_Mode = Generate_Code
15768 or else Ent_Kind = E_Generic_Function
15769 or else Ent_Kind = E_Generic_Procedure
15770 or else Ent_Kind = E_Generic_Package
15772 Get_Name_String (Chars (Cunitent));
15773 Set_Casing (Mixed_Case);
15774 Write_Str (Name_Buffer (1 .. Name_Len));
15775 Write_Str (" is not supported in this configuration");
15777 raise Unrecoverable_Error;
15779 end Unimplemented_Unit;
15781 ------------------------
15782 -- Universal_Aliasing --
15783 ------------------------
15785 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
15787 when Pragma_Universal_Aliasing => Universal_Alias : declare
15792 Check_Arg_Count (1);
15793 Check_Optional_Identifier (Arg2, Name_Entity);
15794 Check_Arg_Is_Local_Name (Arg1);
15795 E_Id := Entity (Get_Pragma_Arg (Arg1));
15797 if E_Id = Any_Type then
15799 elsif No (E_Id) or else not Is_Type (E_Id) then
15800 Error_Pragma_Arg ("pragma% requires type", Arg1);
15803 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
15804 Record_Rep_Item (E_Id, N);
15805 end Universal_Alias;
15807 --------------------
15808 -- Universal_Data --
15809 --------------------
15811 -- pragma Universal_Data [(library_unit_NAME)];
15813 when Pragma_Universal_Data =>
15816 -- If this is a configuration pragma, then set the universal
15817 -- addressing option, otherwise confirm that the pragma satisfies
15818 -- the requirements of library unit pragma placement and leave it
15819 -- to the GNAAMP back end to detect the pragma (avoids transitive
15820 -- setting of the option due to withed units).
15822 if Is_Configuration_Pragma then
15823 Universal_Addressing_On_AAMP := True;
15825 Check_Valid_Library_Unit_Pragma;
15828 if not AAMP_On_Target then
15829 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
15836 -- pragma Unmodified (local_Name {, local_Name});
15838 when Pragma_Unmodified => Unmodified : declare
15839 Arg_Node : Node_Id;
15840 Arg_Expr : Node_Id;
15841 Arg_Ent : Entity_Id;
15845 Check_At_Least_N_Arguments (1);
15847 -- Loop through arguments
15850 while Present (Arg_Node) loop
15851 Check_No_Identifier (Arg_Node);
15853 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
15854 -- in fact generate reference, so that the entity will have a
15855 -- reference, which will inhibit any warnings about it not
15856 -- being referenced, and also properly show up in the ali file
15857 -- as a reference. But this reference is recorded before the
15858 -- Has_Pragma_Unreferenced flag is set, so that no warning is
15859 -- generated for this reference.
15861 Check_Arg_Is_Local_Name (Arg_Node);
15862 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15864 if Is_Entity_Name (Arg_Expr) then
15865 Arg_Ent := Entity (Arg_Expr);
15867 if not Is_Assignable (Arg_Ent) then
15869 ("pragma% can only be applied to a variable",
15872 Set_Has_Pragma_Unmodified (Arg_Ent);
15884 -- pragma Unreferenced (local_Name {, local_Name});
15886 -- or when used in a context clause:
15888 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
15890 when Pragma_Unreferenced => Unreferenced : declare
15891 Arg_Node : Node_Id;
15892 Arg_Expr : Node_Id;
15893 Arg_Ent : Entity_Id;
15898 Check_At_Least_N_Arguments (1);
15900 -- Check case of appearing within context clause
15902 if Is_In_Context_Clause then
15904 -- The arguments must all be units mentioned in a with clause
15905 -- in the same context clause. Note we already checked (in
15906 -- Par.Prag) that the arguments are either identifiers or
15907 -- selected components.
15910 while Present (Arg_Node) loop
15911 Citem := First (List_Containing (N));
15912 while Citem /= N loop
15913 if Nkind (Citem) = N_With_Clause
15915 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
15917 Set_Has_Pragma_Unreferenced
15920 (Library_Unit (Citem))));
15922 (Get_Pragma_Arg (Arg_Node), Name (Citem));
15931 ("argument of pragma% is not withed unit", Arg_Node);
15937 -- Case of not in list of context items
15941 while Present (Arg_Node) loop
15942 Check_No_Identifier (Arg_Node);
15944 -- Note: the analyze call done by Check_Arg_Is_Local_Name
15945 -- will in fact generate reference, so that the entity will
15946 -- have a reference, which will inhibit any warnings about
15947 -- it not being referenced, and also properly show up in the
15948 -- ali file as a reference. But this reference is recorded
15949 -- before the Has_Pragma_Unreferenced flag is set, so that
15950 -- no warning is generated for this reference.
15952 Check_Arg_Is_Local_Name (Arg_Node);
15953 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15955 if Is_Entity_Name (Arg_Expr) then
15956 Arg_Ent := Entity (Arg_Expr);
15958 -- If the entity is overloaded, the pragma applies to the
15959 -- most recent overloading, as documented. In this case,
15960 -- name resolution does not generate a reference, so it
15961 -- must be done here explicitly.
15963 if Is_Overloaded (Arg_Expr) then
15964 Generate_Reference (Arg_Ent, N);
15967 Set_Has_Pragma_Unreferenced (Arg_Ent);
15975 --------------------------
15976 -- Unreferenced_Objects --
15977 --------------------------
15979 -- pragma Unreferenced_Objects (local_Name {, local_Name});
15981 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
15982 Arg_Node : Node_Id;
15983 Arg_Expr : Node_Id;
15987 Check_At_Least_N_Arguments (1);
15990 while Present (Arg_Node) loop
15991 Check_No_Identifier (Arg_Node);
15992 Check_Arg_Is_Local_Name (Arg_Node);
15993 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15995 if not Is_Entity_Name (Arg_Expr)
15996 or else not Is_Type (Entity (Arg_Expr))
15999 ("argument for pragma% must be type or subtype", Arg_Node);
16002 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
16005 end Unreferenced_Objects;
16007 ------------------------------
16008 -- Unreserve_All_Interrupts --
16009 ------------------------------
16011 -- pragma Unreserve_All_Interrupts;
16013 when Pragma_Unreserve_All_Interrupts =>
16015 Check_Arg_Count (0);
16017 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
16018 Unreserve_All_Interrupts := True;
16025 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
16027 when Pragma_Unsuppress =>
16029 Process_Suppress_Unsuppress (False);
16031 -------------------
16032 -- Use_VADS_Size --
16033 -------------------
16035 -- pragma Use_VADS_Size;
16037 when Pragma_Use_VADS_Size =>
16039 Check_Arg_Count (0);
16040 Check_Valid_Configuration_Pragma;
16041 Use_VADS_Size := True;
16043 ---------------------
16044 -- Validity_Checks --
16045 ---------------------
16047 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
16049 when Pragma_Validity_Checks => Validity_Checks : declare
16050 A : constant Node_Id := Get_Pragma_Arg (Arg1);
16056 Check_Arg_Count (1);
16057 Check_No_Identifiers;
16059 if Nkind (A) = N_String_Literal then
16063 Slen : constant Natural := Natural (String_Length (S));
16064 Options : String (1 .. Slen);
16070 C := Get_String_Char (S, Int (J));
16071 exit when not In_Character_Range (C);
16072 Options (J) := Get_Character (C);
16075 Set_Validity_Check_Options (Options);
16083 elsif Nkind (A) = N_Identifier then
16084 if Chars (A) = Name_All_Checks then
16085 Set_Validity_Check_Options ("a");
16086 elsif Chars (A) = Name_On then
16087 Validity_Checks_On := True;
16088 elsif Chars (A) = Name_Off then
16089 Validity_Checks_On := False;
16092 end Validity_Checks;
16098 -- pragma Volatile (LOCAL_NAME);
16100 when Pragma_Volatile =>
16101 Process_Atomic_Shared_Volatile;
16103 -------------------------
16104 -- Volatile_Components --
16105 -------------------------
16107 -- pragma Volatile_Components (array_LOCAL_NAME);
16109 -- Volatile is handled by the same circuit as Atomic_Components
16115 -- pragma Warnings (On | Off);
16116 -- pragma Warnings (On | Off, LOCAL_NAME);
16117 -- pragma Warnings (static_string_EXPRESSION);
16118 -- pragma Warnings (On | Off, STRING_LITERAL);
16120 when Pragma_Warnings => Warnings : begin
16122 Check_At_Least_N_Arguments (1);
16123 Check_No_Identifiers;
16125 -- If debug flag -gnatd.i is set, pragma is ignored
16127 if Debug_Flag_Dot_I then
16131 -- Process various forms of the pragma
16134 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
16137 -- One argument case
16139 if Arg_Count = 1 then
16141 -- On/Off one argument case was processed by parser
16143 if Nkind (Argx) = N_Identifier
16145 (Chars (Argx) = Name_On
16147 Chars (Argx) = Name_Off)
16151 -- One argument case must be ON/OFF or static string expr
16153 elsif not Is_Static_String_Expression (Arg1) then
16155 ("argument of pragma% must be On/Off or " &
16156 "static string expression", Arg1);
16158 -- One argument string expression case
16162 Lit : constant Node_Id := Expr_Value_S (Argx);
16163 Str : constant String_Id := Strval (Lit);
16164 Len : constant Nat := String_Length (Str);
16172 while J <= Len loop
16173 C := Get_String_Char (Str, J);
16174 OK := In_Character_Range (C);
16177 Chr := Get_Character (C);
16179 -- Dash case: only -Wxxx is accepted
16186 C := Get_String_Char (Str, J);
16187 Chr := Get_Character (C);
16188 exit when Chr = 'W';
16193 elsif J < Len and then Chr = '.' then
16195 C := Get_String_Char (Str, J);
16196 Chr := Get_Character (C);
16198 if not Set_Dot_Warning_Switch (Chr) then
16200 ("invalid warning switch character " &
16207 OK := Set_Warning_Switch (Chr);
16213 ("invalid warning switch character " & Chr,
16222 -- Two or more arguments (must be two)
16225 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16226 Check_At_Most_N_Arguments (2);
16234 E_Id := Get_Pragma_Arg (Arg2);
16237 -- In the expansion of an inlined body, a reference to
16238 -- the formal may be wrapped in a conversion if the
16239 -- actual is a conversion. Retrieve the real entity name.
16241 if (In_Instance_Body or In_Inlined_Body)
16242 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
16244 E_Id := Expression (E_Id);
16247 -- Entity name case
16249 if Is_Entity_Name (E_Id) then
16250 E := Entity (E_Id);
16257 (E, (Chars (Get_Pragma_Arg (Arg1)) =
16260 -- For OFF case, make entry in warnings off
16261 -- pragma table for later processing. But we do
16262 -- not do that within an instance, since these
16263 -- warnings are about what is needed in the
16264 -- template, not an instance of it.
16266 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
16267 and then Warn_On_Warnings_Off
16268 and then not In_Instance
16270 Warnings_Off_Pragmas.Append ((N, E));
16273 if Is_Enumeration_Type (E) then
16277 Lit := First_Literal (E);
16278 while Present (Lit) loop
16279 Set_Warnings_Off (Lit);
16280 Next_Literal (Lit);
16285 exit when No (Homonym (E));
16290 -- Error if not entity or static string literal case
16292 elsif not Is_Static_String_Expression (Arg2) then
16294 ("second argument of pragma% must be entity " &
16295 "name or static string expression", Arg2);
16297 -- String literal case
16300 String_To_Name_Buffer
16301 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
16303 -- Note on configuration pragma case: If this is a
16304 -- configuration pragma, then for an OFF pragma, we
16305 -- just set Config True in the call, which is all
16306 -- that needs to be done. For the case of ON, this
16307 -- is normally an error, unless it is canceling the
16308 -- effect of a previous OFF pragma in the same file.
16309 -- In any other case, an error will be signalled (ON
16310 -- with no matching OFF).
16312 -- Note: We set Used if we are inside a generic to
16313 -- disable the test that the non-config case actually
16314 -- cancels a warning. That's because we can't be sure
16315 -- there isn't an instantiation in some other unit
16316 -- where a warning is suppressed.
16318 -- We could do a little better here by checking if the
16319 -- generic unit we are inside is public, but for now
16320 -- we don't bother with that refinement.
16322 if Chars (Argx) = Name_Off then
16323 Set_Specific_Warning_Off
16324 (Loc, Name_Buffer (1 .. Name_Len),
16325 Config => Is_Configuration_Pragma,
16326 Used => Inside_A_Generic or else In_Instance);
16328 elsif Chars (Argx) = Name_On then
16329 Set_Specific_Warning_On
16330 (Loc, Name_Buffer (1 .. Name_Len), Err);
16334 ("??pragma Warnings On with no " &
16335 "matching Warnings Off",
16345 -------------------
16346 -- Weak_External --
16347 -------------------
16349 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
16351 when Pragma_Weak_External => Weak_External : declare
16356 Check_Arg_Count (1);
16357 Check_Optional_Identifier (Arg1, Name_Entity);
16358 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16359 Ent := Entity (Get_Pragma_Arg (Arg1));
16361 if Rep_Item_Too_Early (Ent, N) then
16364 Ent := Underlying_Type (Ent);
16367 -- The only processing required is to link this item on to the
16368 -- list of rep items for the given entity. This is accomplished
16369 -- by the call to Rep_Item_Too_Late (when no error is detected
16370 -- and False is returned).
16372 if Rep_Item_Too_Late (Ent, N) then
16375 Set_Has_Gigi_Rep_Item (Ent);
16379 -----------------------------
16380 -- Wide_Character_Encoding --
16381 -----------------------------
16383 -- pragma Wide_Character_Encoding (IDENTIFIER);
16385 when Pragma_Wide_Character_Encoding =>
16388 -- Nothing to do, handled in parser. Note that we do not enforce
16389 -- configuration pragma placement, this pragma can appear at any
16390 -- place in the source, allowing mixed encodings within a single
16395 --------------------
16396 -- Unknown_Pragma --
16397 --------------------
16399 -- Should be impossible, since the case of an unknown pragma is
16400 -- separately processed before the case statement is entered.
16402 when Unknown_Pragma =>
16403 raise Program_Error;
16406 -- AI05-0144: detect dangerous order dependence. Disabled for now,
16407 -- until AI is formally approved.
16409 -- Check_Order_Dependence;
16412 when Pragma_Exit => null;
16413 end Analyze_Pragma;
16415 -------------------
16416 -- Check_Enabled --
16417 -------------------
16419 function Check_Enabled (Nam : Name_Id) return Boolean is
16423 -- Loop through entries in check policy list
16425 PP := Opt.Check_Policy_List;
16427 -- If there are no specific entries that matched, then we let the
16428 -- setting of assertions govern. Note that this provides the needed
16429 -- compatibility with the RM for the cases of assertion, invariant,
16430 -- precondition, predicate, and postcondition.
16433 return Assertions_Enabled;
16435 -- Here we have an entry see if it matches
16439 PPA : constant List_Id := Pragma_Argument_Associations (PP);
16442 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
16443 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
16444 when Name_On | Name_Check =>
16446 when Name_Off | Name_Disable | Name_Ignore =>
16449 raise Program_Error;
16453 PP := Next_Pragma (PP);
16460 ---------------------------------
16461 -- Delay_Config_Pragma_Analyze --
16462 ---------------------------------
16464 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
16466 return Pragma_Name (N) = Name_Interrupt_State
16468 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
16469 end Delay_Config_Pragma_Analyze;
16471 -------------------------
16472 -- Get_Base_Subprogram --
16473 -------------------------
16475 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
16476 Result : Entity_Id;
16479 -- Follow subprogram renaming chain
16483 if Is_Subprogram (Result)
16485 Nkind (Parent (Declaration_Node (Result))) =
16486 N_Subprogram_Renaming_Declaration
16487 and then Present (Alias (Result))
16489 Result := Alias (Result);
16493 end Get_Base_Subprogram;
16499 procedure Initialize is
16504 -----------------------------
16505 -- Is_Config_Static_String --
16506 -----------------------------
16508 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
16510 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
16511 -- This is an internal recursive function that is just like the outer
16512 -- function except that it adds the string to the name buffer rather
16513 -- than placing the string in the name buffer.
16515 ------------------------------
16516 -- Add_Config_Static_String --
16517 ------------------------------
16519 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
16526 if Nkind (N) = N_Op_Concat then
16527 if Add_Config_Static_String (Left_Opnd (N)) then
16528 N := Right_Opnd (N);
16534 if Nkind (N) /= N_String_Literal then
16535 Error_Msg_N ("string literal expected for pragma argument", N);
16539 for J in 1 .. String_Length (Strval (N)) loop
16540 C := Get_String_Char (Strval (N), J);
16542 if not In_Character_Range (C) then
16544 ("string literal contains invalid wide character",
16545 Sloc (N) + 1 + Source_Ptr (J));
16549 Add_Char_To_Name_Buffer (Get_Character (C));
16554 end Add_Config_Static_String;
16556 -- Start of processing for Is_Config_Static_String
16561 return Add_Config_Static_String (Arg);
16562 end Is_Config_Static_String;
16564 -----------------------------------------
16565 -- Is_Non_Significant_Pragma_Reference --
16566 -----------------------------------------
16568 -- This function makes use of the following static table which indicates
16569 -- whether appearance of some name in a given pragma is to be considered
16570 -- as a reference for the purposes of warnings about unreferenced objects.
16572 -- -1 indicates that references in any argument position are significant
16573 -- 0 indicates that appearance in any argument is not significant
16574 -- +n indicates that appearance as argument n is significant, but all
16575 -- other arguments are not significant
16576 -- 99 special processing required (e.g. for pragma Check)
16578 Sig_Flags : constant array (Pragma_Id) of Int :=
16579 (Pragma_AST_Entry => -1,
16580 Pragma_Abort_Defer => -1,
16581 Pragma_Abstract_State => -1,
16582 Pragma_Ada_83 => -1,
16583 Pragma_Ada_95 => -1,
16584 Pragma_Ada_05 => -1,
16585 Pragma_Ada_2005 => -1,
16586 Pragma_Ada_12 => -1,
16587 Pragma_Ada_2012 => -1,
16588 Pragma_All_Calls_Remote => -1,
16589 Pragma_Annotate => -1,
16590 Pragma_Assert => -1,
16591 Pragma_Assert_And_Cut => -1,
16592 Pragma_Assertion_Policy => 0,
16593 Pragma_Assume => 0,
16594 Pragma_Assume_No_Invalid_Values => 0,
16595 Pragma_Attribute_Definition => +3,
16596 Pragma_Asynchronous => -1,
16597 Pragma_Atomic => 0,
16598 Pragma_Atomic_Components => 0,
16599 Pragma_Attach_Handler => -1,
16600 Pragma_Check => 99,
16601 Pragma_Check_Float_Overflow => 0,
16602 Pragma_Check_Name => 0,
16603 Pragma_Check_Policy => 0,
16604 Pragma_CIL_Constructor => -1,
16605 Pragma_CPP_Class => 0,
16606 Pragma_CPP_Constructor => 0,
16607 Pragma_CPP_Virtual => 0,
16608 Pragma_CPP_Vtable => 0,
16610 Pragma_C_Pass_By_Copy => 0,
16611 Pragma_Comment => 0,
16612 Pragma_Common_Object => -1,
16613 Pragma_Compile_Time_Error => -1,
16614 Pragma_Compile_Time_Warning => -1,
16615 Pragma_Compiler_Unit => 0,
16616 Pragma_Complete_Representation => 0,
16617 Pragma_Complex_Representation => 0,
16618 Pragma_Component_Alignment => -1,
16619 Pragma_Contract_Case => -1,
16620 Pragma_Contract_Cases => -1,
16621 Pragma_Controlled => 0,
16622 Pragma_Convention => 0,
16623 Pragma_Convention_Identifier => 0,
16624 Pragma_Debug => -1,
16625 Pragma_Debug_Policy => 0,
16626 Pragma_Detect_Blocking => -1,
16627 Pragma_Default_Storage_Pool => -1,
16628 Pragma_Disable_Atomic_Synchronization => -1,
16629 Pragma_Discard_Names => 0,
16630 Pragma_Dispatching_Domain => -1,
16631 Pragma_Elaborate => -1,
16632 Pragma_Elaborate_All => -1,
16633 Pragma_Elaborate_Body => -1,
16634 Pragma_Elaboration_Checks => -1,
16635 Pragma_Eliminate => -1,
16636 Pragma_Enable_Atomic_Synchronization => -1,
16637 Pragma_Export => -1,
16638 Pragma_Export_Exception => -1,
16639 Pragma_Export_Function => -1,
16640 Pragma_Export_Object => -1,
16641 Pragma_Export_Procedure => -1,
16642 Pragma_Export_Value => -1,
16643 Pragma_Export_Valued_Procedure => -1,
16644 Pragma_Extend_System => -1,
16645 Pragma_Extensions_Allowed => -1,
16646 Pragma_External => -1,
16647 Pragma_Favor_Top_Level => -1,
16648 Pragma_External_Name_Casing => -1,
16649 Pragma_Fast_Math => -1,
16650 Pragma_Finalize_Storage_Only => 0,
16651 Pragma_Float_Representation => 0,
16652 Pragma_Global => -1,
16653 Pragma_Ident => -1,
16654 Pragma_Implementation_Defined => -1,
16655 Pragma_Implemented => -1,
16656 Pragma_Implicit_Packing => 0,
16657 Pragma_Import => +2,
16658 Pragma_Import_Exception => 0,
16659 Pragma_Import_Function => 0,
16660 Pragma_Import_Object => 0,
16661 Pragma_Import_Procedure => 0,
16662 Pragma_Import_Valued_Procedure => 0,
16663 Pragma_Independent => 0,
16664 Pragma_Independent_Components => 0,
16665 Pragma_Initialize_Scalars => -1,
16666 Pragma_Inline => 0,
16667 Pragma_Inline_Always => 0,
16668 Pragma_Inline_Generic => 0,
16669 Pragma_Inspection_Point => -1,
16670 Pragma_Interface => +2,
16671 Pragma_Interface_Name => +2,
16672 Pragma_Interrupt_Handler => -1,
16673 Pragma_Interrupt_Priority => -1,
16674 Pragma_Interrupt_State => -1,
16675 Pragma_Invariant => -1,
16676 Pragma_Java_Constructor => -1,
16677 Pragma_Java_Interface => -1,
16678 Pragma_Keep_Names => 0,
16679 Pragma_License => -1,
16680 Pragma_Link_With => -1,
16681 Pragma_Linker_Alias => -1,
16682 Pragma_Linker_Constructor => -1,
16683 Pragma_Linker_Destructor => -1,
16684 Pragma_Linker_Options => -1,
16685 Pragma_Linker_Section => -1,
16687 Pragma_Lock_Free => -1,
16688 Pragma_Locking_Policy => -1,
16689 Pragma_Long_Float => -1,
16690 Pragma_Loop_Invariant => -1,
16691 Pragma_Loop_Optimize => -1,
16692 Pragma_Loop_Variant => -1,
16693 Pragma_Machine_Attribute => -1,
16695 Pragma_Main_Storage => -1,
16696 Pragma_Memory_Size => -1,
16697 Pragma_No_Return => 0,
16698 Pragma_No_Body => 0,
16699 Pragma_No_Inline => 0,
16700 Pragma_No_Run_Time => -1,
16701 Pragma_No_Strict_Aliasing => -1,
16702 Pragma_Normalize_Scalars => -1,
16703 Pragma_Obsolescent => 0,
16704 Pragma_Optimize => -1,
16705 Pragma_Optimize_Alignment => -1,
16706 Pragma_Overflow_Mode => 0,
16707 Pragma_Overriding_Renamings => 0,
16708 Pragma_Ordered => 0,
16711 Pragma_Partition_Elaboration_Policy => -1,
16712 Pragma_Passive => -1,
16713 Pragma_Preelaborable_Initialization => -1,
16714 Pragma_Polling => -1,
16715 Pragma_Persistent_BSS => 0,
16716 Pragma_Postcondition => -1,
16717 Pragma_Precondition => -1,
16718 Pragma_Predicate => -1,
16719 Pragma_Preelaborate => -1,
16720 Pragma_Preelaborate_05 => -1,
16721 Pragma_Priority => -1,
16722 Pragma_Priority_Specific_Dispatching => -1,
16723 Pragma_Profile => 0,
16724 Pragma_Profile_Warnings => 0,
16725 Pragma_Propagate_Exceptions => -1,
16726 Pragma_Psect_Object => -1,
16728 Pragma_Pure_05 => -1,
16729 Pragma_Pure_12 => -1,
16730 Pragma_Pure_Function => -1,
16731 Pragma_Queuing_Policy => -1,
16732 Pragma_Rational => -1,
16733 Pragma_Ravenscar => -1,
16734 Pragma_Relative_Deadline => -1,
16735 Pragma_Remote_Access_Type => -1,
16736 Pragma_Remote_Call_Interface => -1,
16737 Pragma_Remote_Types => -1,
16738 Pragma_Restricted_Run_Time => -1,
16739 Pragma_Restriction_Warnings => -1,
16740 Pragma_Restrictions => -1,
16741 Pragma_Reviewable => -1,
16742 Pragma_Short_Circuit_And_Or => -1,
16743 Pragma_Share_Generic => -1,
16744 Pragma_Shared => -1,
16745 Pragma_Shared_Passive => -1,
16746 Pragma_Short_Descriptors => 0,
16747 Pragma_Simple_Storage_Pool_Type => 0,
16748 Pragma_Source_File_Name => -1,
16749 Pragma_Source_File_Name_Project => -1,
16750 Pragma_Source_Reference => -1,
16751 Pragma_Storage_Size => -1,
16752 Pragma_Storage_Unit => -1,
16753 Pragma_Static_Elaboration_Desired => -1,
16754 Pragma_Stream_Convert => -1,
16755 Pragma_Style_Checks => -1,
16756 Pragma_Subtitle => -1,
16757 Pragma_Suppress => 0,
16758 Pragma_Suppress_Exception_Locations => 0,
16759 Pragma_Suppress_All => -1,
16760 Pragma_Suppress_Debug_Info => 0,
16761 Pragma_Suppress_Initialization => 0,
16762 Pragma_System_Name => -1,
16763 Pragma_Task_Dispatching_Policy => -1,
16764 Pragma_Task_Info => -1,
16765 Pragma_Task_Name => -1,
16766 Pragma_Task_Storage => 0,
16767 Pragma_Test_Case => -1,
16768 Pragma_Thread_Local_Storage => 0,
16769 Pragma_Time_Slice => -1,
16770 Pragma_Title => -1,
16771 Pragma_Unchecked_Union => 0,
16772 Pragma_Unimplemented_Unit => -1,
16773 Pragma_Universal_Aliasing => -1,
16774 Pragma_Universal_Data => -1,
16775 Pragma_Unmodified => -1,
16776 Pragma_Unreferenced => -1,
16777 Pragma_Unreferenced_Objects => -1,
16778 Pragma_Unreserve_All_Interrupts => -1,
16779 Pragma_Unsuppress => 0,
16780 Pragma_Use_VADS_Size => -1,
16781 Pragma_Validity_Checks => -1,
16782 Pragma_Volatile => 0,
16783 Pragma_Volatile_Components => 0,
16784 Pragma_Warnings => -1,
16785 Pragma_Weak_External => -1,
16786 Pragma_Wide_Character_Encoding => 0,
16787 Unknown_Pragma => 0);
16789 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
16798 if Nkind (P) /= N_Pragma_Argument_Association then
16802 Id := Get_Pragma_Id (Parent (P));
16803 C := Sig_Flags (Id);
16815 -- For pragma Check, the first argument is not significant,
16816 -- the second and the third (if present) arguments are
16819 when Pragma_Check =>
16821 P = First (Pragma_Argument_Associations (Parent (P)));
16824 raise Program_Error;
16828 A := First (Pragma_Argument_Associations (Parent (P)));
16829 for J in 1 .. C - 1 loop
16837 return A = P; -- is this wrong way round ???
16840 end Is_Non_Significant_Pragma_Reference;
16842 ------------------------------
16843 -- Is_Pragma_String_Literal --
16844 ------------------------------
16846 -- This function returns true if the corresponding pragma argument is a
16847 -- static string expression. These are the only cases in which string
16848 -- literals can appear as pragma arguments. We also allow a string literal
16849 -- as the first argument to pragma Assert (although it will of course
16850 -- always generate a type error).
16852 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
16853 Pragn : constant Node_Id := Parent (Par);
16854 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
16855 Pname : constant Name_Id := Pragma_Name (Pragn);
16861 N := First (Assoc);
16868 if Pname = Name_Assert then
16871 elsif Pname = Name_Export then
16874 elsif Pname = Name_Ident then
16877 elsif Pname = Name_Import then
16880 elsif Pname = Name_Interface_Name then
16883 elsif Pname = Name_Linker_Alias then
16886 elsif Pname = Name_Linker_Section then
16889 elsif Pname = Name_Machine_Attribute then
16892 elsif Pname = Name_Source_File_Name then
16895 elsif Pname = Name_Source_Reference then
16898 elsif Pname = Name_Title then
16901 elsif Pname = Name_Subtitle then
16907 end Is_Pragma_String_Literal;
16909 -----------------------------------------
16910 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
16911 -----------------------------------------
16913 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
16914 Aspects : constant List_Id := New_List;
16915 Loc : constant Source_Ptr := Sloc (Decl);
16916 Or_Decl : constant Node_Id := Original_Node (Decl);
16918 Original_Aspects : List_Id;
16919 -- To capture global references, a copy of the created aspects must be
16920 -- inserted in the original tree.
16923 Prag_Arg_Ass : Node_Id;
16924 Prag_Id : Pragma_Id;
16927 -- Check for any PPC pragmas that appear within Decl
16929 Prag := Next (Decl);
16930 while Nkind (Prag) = N_Pragma loop
16931 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
16934 when Pragma_Postcondition | Pragma_Precondition =>
16935 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
16937 -- Make an aspect from any PPC pragma
16939 Append_To (Aspects,
16940 Make_Aspect_Specification (Loc,
16942 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
16944 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
16946 -- Generate the analysis information in the pragma expression
16947 -- and then set the pragma node analyzed to avoid any further
16950 Analyze (Expression (Prag_Arg_Ass));
16951 Set_Analyzed (Prag, True);
16953 when others => null;
16959 -- Set all new aspects into the generic declaration node
16961 if Is_Non_Empty_List (Aspects) then
16963 -- Create the list of aspects to be inserted in the original tree
16965 Original_Aspects := Copy_Separate_List (Aspects);
16967 -- Check if Decl already has aspects
16969 -- Attach the new lists of aspects to both the generic copy and the
16972 if Has_Aspects (Decl) then
16973 Append_List (Aspects, Aspect_Specifications (Decl));
16974 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
16977 Set_Parent (Aspects, Decl);
16978 Set_Aspect_Specifications (Decl, Aspects);
16979 Set_Parent (Original_Aspects, Or_Decl);
16980 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
16983 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
16985 -------------------------
16986 -- Preanalyze_CTC_Args --
16987 -------------------------
16989 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
16991 -- Preanalyze the boolean expressions, we treat these as spec
16992 -- expressions (i.e. similar to a default expression).
16994 if Present (Arg_Req) then
16995 Preanalyze_Assert_Expression
16996 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
16998 -- In ASIS mode, for a pragma generated from a source aspect, also
16999 -- analyze the original aspect expression.
17001 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
17002 Preanalyze_Assert_Expression
17003 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
17007 if Present (Arg_Ens) then
17008 Preanalyze_Assert_Expression
17009 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
17011 -- In ASIS mode, for a pragma generated from a source aspect, also
17012 -- analyze the original aspect expression.
17014 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
17015 Preanalyze_Assert_Expression
17016 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
17019 end Preanalyze_CTC_Args;
17021 --------------------------------------
17022 -- Process_Compilation_Unit_Pragmas --
17023 --------------------------------------
17025 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
17027 -- A special check for pragma Suppress_All, a very strange DEC pragma,
17028 -- strange because it comes at the end of the unit. Rational has the
17029 -- same name for a pragma, but treats it as a program unit pragma, In
17030 -- GNAT we just decide to allow it anywhere at all. If it appeared then
17031 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
17032 -- node, and we insert a pragma Suppress (All_Checks) at the start of
17033 -- the context clause to ensure the correct processing.
17035 if Has_Pragma_Suppress_All (N) then
17036 Prepend_To (Context_Items (N),
17037 Make_Pragma (Sloc (N),
17038 Chars => Name_Suppress,
17039 Pragma_Argument_Associations => New_List (
17040 Make_Pragma_Argument_Association (Sloc (N),
17041 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
17044 -- Nothing else to do at the current time!
17046 end Process_Compilation_Unit_Pragmas;
17057 --------------------------------
17058 -- Set_Encoded_Interface_Name --
17059 --------------------------------
17061 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
17062 Str : constant String_Id := Strval (S);
17063 Len : constant Int := String_Length (Str);
17068 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
17071 -- Stores encoded value of character code CC. The encoding we use an
17072 -- underscore followed by four lower case hex digits.
17078 procedure Encode is
17080 Store_String_Char (Get_Char_Code ('_'));
17082 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
17084 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
17086 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
17088 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
17091 -- Start of processing for Set_Encoded_Interface_Name
17094 -- If first character is asterisk, this is a link name, and we leave it
17095 -- completely unmodified. We also ignore null strings (the latter case
17096 -- happens only in error cases) and no encoding should occur for Java or
17097 -- AAMP interface names.
17100 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
17101 or else VM_Target /= No_VM
17102 or else AAMP_On_Target
17104 Set_Interface_Name (E, S);
17109 CC := Get_String_Char (Str, J);
17111 exit when not In_Character_Range (CC);
17113 C := Get_Character (CC);
17115 exit when C /= '_' and then C /= '$'
17116 and then C not in '0' .. '9'
17117 and then C not in 'a' .. 'z'
17118 and then C not in 'A' .. 'Z';
17121 Set_Interface_Name (E, S);
17129 -- Here we need to encode. The encoding we use as follows:
17130 -- three underscores + four hex digits (lower case)
17134 for J in 1 .. String_Length (Str) loop
17135 CC := Get_String_Char (Str, J);
17137 if not In_Character_Range (CC) then
17140 C := Get_Character (CC);
17142 if C = '_' or else C = '$'
17143 or else C in '0' .. '9'
17144 or else C in 'a' .. 'z'
17145 or else C in 'A' .. 'Z'
17147 Store_String_Char (CC);
17154 Set_Interface_Name (E,
17155 Make_String_Literal (Sloc (S),
17156 Strval => End_String));
17158 end Set_Encoded_Interface_Name;
17160 -------------------
17161 -- Set_Unit_Name --
17162 -------------------
17164 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
17169 if Nkind (N) = N_Identifier
17170 and then Nkind (With_Item) = N_Identifier
17172 Set_Entity (N, Entity (With_Item));
17174 elsif Nkind (N) = N_Selected_Component then
17175 Change_Selected_Component_To_Expanded_Name (N);
17176 Set_Entity (N, Entity (With_Item));
17177 Set_Entity (Selector_Name (N), Entity (N));
17179 Pref := Prefix (N);
17180 Scop := Scope (Entity (N));
17181 while Nkind (Pref) = N_Selected_Component loop
17182 Change_Selected_Component_To_Expanded_Name (Pref);
17183 Set_Entity (Selector_Name (Pref), Scop);
17184 Set_Entity (Pref, Scop);
17185 Pref := Prefix (Pref);
17186 Scop := Scope (Scop);
17189 Set_Entity (Pref, Scop);