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", Corresponding_Aspect (N));
408 Replace_Type (Get_Pragma_Arg (Arg1));
409 end Class_Wide_Condition;
412 -- Remove the subprogram from the scope stack now that the pre-analysis
413 -- of the precondition/postcondition is done.
416 end Analyze_PPC_In_Decl_Part;
422 procedure Analyze_Pragma (N : Node_Id) is
423 Loc : constant Source_Ptr := Sloc (N);
427 -- Name of the source pragma, or name of the corresponding aspect for
428 -- pragmas which originate in a source aspect. In the latter case, the
429 -- name may be different from the pragma name.
431 Pragma_Exit : exception;
432 -- This exception is used to exit pragma processing completely. It is
433 -- used when an error is detected, and no further processing is
434 -- required. It is also used if an earlier error has left the tree in
435 -- a state where the pragma should not be processed.
438 -- Number of pragma argument associations
444 -- First four pragma arguments (pragma argument association nodes, or
445 -- Empty if the corresponding argument does not exist).
447 type Name_List is array (Natural range <>) of Name_Id;
448 type Args_List is array (Natural range <>) of Node_Id;
449 -- Types used for arguments to Check_Arg_Order and Gather_Associations
451 procedure Ada_2005_Pragma;
452 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
453 -- Ada 95 mode, these are implementation defined pragmas, so should be
454 -- caught by the No_Implementation_Pragmas restriction.
456 procedure Ada_2012_Pragma;
457 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
458 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
459 -- should be caught by the No_Implementation_Pragmas restriction.
461 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id);
462 -- Subsidiary routine to the analysis of pragmas Depends and Global.
463 -- Append an input or output item to a list. If the list is empty, a
464 -- new one is created.
466 procedure Check_Ada_83_Warning;
467 -- Issues a warning message for the current pragma if operating in Ada
468 -- 83 mode (used for language pragmas that are not a standard part of
469 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
472 procedure Check_Arg_Count (Required : Nat);
473 -- Check argument count for pragma is equal to given parameter. If not,
474 -- then issue an error message and raise Pragma_Exit.
476 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
477 -- Arg which can either be a pragma argument association, in which case
478 -- the check is applied to the expression of the association or an
479 -- expression directly.
481 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
482 -- Check that an argument has the right form for an EXTERNAL_NAME
483 -- parameter of an extended import/export pragma. The rule is that the
484 -- name must be an identifier or string literal (in Ada 83 mode) or a
485 -- static string expression (in Ada 95 mode).
487 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
488 -- Check the specified argument Arg to make sure that it is an
489 -- identifier. If not give error and raise Pragma_Exit.
491 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
492 -- Check the specified argument Arg to make sure that it is an integer
493 -- literal. If not give error and raise Pragma_Exit.
495 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
496 -- Check the specified argument Arg to make sure that it has the proper
497 -- syntactic form for a local name and meets the semantic requirements
498 -- for a local name. The local name is analyzed as part of the
499 -- processing for this call. In addition, the local name is required
500 -- to represent an entity at the library level.
502 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
503 -- Check the specified argument Arg to make sure that it has the proper
504 -- syntactic form for a local name and meets the semantic requirements
505 -- for a local name. The local name is analyzed as part of the
506 -- processing for this call.
508 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
509 -- Check the specified argument Arg to make sure that it is a valid
510 -- locking policy name. If not give error and raise Pragma_Exit.
512 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
513 -- Check the specified argument Arg to make sure that it is a valid
514 -- elaboration policy name. If not give error and raise Pragma_Exit.
516 procedure Check_Arg_Is_One_Of
519 procedure Check_Arg_Is_One_Of
521 N1, N2, N3 : Name_Id);
522 procedure Check_Arg_Is_One_Of
524 N1, N2, N3, N4 : Name_Id);
525 procedure Check_Arg_Is_One_Of
527 N1, N2, N3, N4, N5 : Name_Id);
528 -- Check the specified argument Arg to make sure that it is an
529 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
530 -- present). If not then give error and raise Pragma_Exit.
532 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
533 -- Check the specified argument Arg to make sure that it is a valid
534 -- queuing policy name. If not give error and raise Pragma_Exit.
536 procedure Check_Arg_Is_Static_Expression
538 Typ : Entity_Id := Empty);
539 -- Check the specified argument Arg to make sure that it is a static
540 -- expression of the given type (i.e. it will be analyzed and resolved
541 -- using this type, which can be any valid argument to Resolve, e.g.
542 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
543 -- Typ is left Empty, then any static expression is allowed.
545 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
546 -- Check the specified argument Arg to make sure that it is a valid task
547 -- dispatching policy name. If not give error and raise Pragma_Exit.
549 procedure Check_Arg_Order (Names : Name_List);
550 -- Checks for an instance of two arguments with identifiers for the
551 -- current pragma which are not in the sequence indicated by Names,
552 -- and if so, generates a fatal message about bad order of arguments.
554 procedure Check_At_Least_N_Arguments (N : Nat);
555 -- Check there are at least N arguments present
557 procedure Check_At_Most_N_Arguments (N : Nat);
558 -- Check there are no more than N arguments present
560 procedure Check_Component
563 In_Variant_Part : Boolean := False);
564 -- Examine an Unchecked_Union component for correct use of per-object
565 -- constrained subtypes, and for restrictions on finalizable components.
566 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
567 -- should be set when Comp comes from a record variant.
569 procedure Check_Contract_Or_Test_Case;
570 -- Called to process a contract-case or test-case pragma. It
571 -- starts with checking pragma arguments, and the rest of the
572 -- treatment is similar to the one for pre- and postcondition in
573 -- Check_Precondition_Postcondition, except the placement rules for the
574 -- contract-case and test-case pragmas are stricter. These pragmas may
575 -- only occur after a subprogram spec declared directly in a package
576 -- spec unit. In this case, the pragma is chained to the subprogram in
577 -- question (using Spec_CTC_List and Next_Pragma) and analysis of the
578 -- pragma is delayed till the end of the spec. In all other cases, an
579 -- error message for bad placement is given.
581 procedure Check_Duplicate_Pragma (E : Entity_Id);
582 -- Check if a rep item of the same name as the current pragma is already
583 -- chained as a rep pragma to the given entity. If so give a message
584 -- about the duplicate, and then raise Pragma_Exit so does not return.
586 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
587 -- Nam is an N_String_Literal node containing the external name set by
588 -- an Import or Export pragma (or extended Import or Export pragma).
589 -- This procedure checks for possible duplications if this is the export
590 -- case, and if found, issues an appropriate error message.
592 procedure Check_Expr_Is_Static_Expression
594 Typ : Entity_Id := Empty);
595 -- Check the specified expression Expr to make sure that it is a static
596 -- expression of the given type (i.e. it will be analyzed and resolved
597 -- using this type, which can be any valid argument to Resolve, e.g.
598 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
599 -- Typ is left Empty, then any static expression is allowed.
601 procedure Check_First_Subtype (Arg : Node_Id);
602 -- Checks that Arg, whose expression is an entity name, references a
605 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
606 -- Checks that the given argument has an identifier, and if so, requires
607 -- it to match the given identifier name. If there is no identifier, or
608 -- a non-matching identifier, then an error message is given and
609 -- Pragma_Exit is raised.
611 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
612 -- Checks that the given argument has an identifier, and if so, requires
613 -- it to match one of the given identifier names. If there is no
614 -- identifier, or a non-matching identifier, then an error message is
615 -- given and Pragma_Exit is raised.
617 procedure Check_In_Main_Program;
618 -- Common checks for pragmas that appear within a main program
619 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
621 procedure Check_Interrupt_Or_Attach_Handler;
622 -- Common processing for first argument of pragma Interrupt_Handler or
623 -- pragma Attach_Handler.
625 procedure Check_Loop_Pragma_Placement;
626 -- Verify whether pragma Loop_Invariant or Loop_Optimize or Loop_Variant
627 -- appear immediately within a construct restricted to loops.
629 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
630 -- Check that pragma appears in a declarative part, or in a package
631 -- specification, i.e. that it does not occur in a statement sequence
634 procedure Check_No_Identifier (Arg : Node_Id);
635 -- Checks that the given argument does not have an identifier. If
636 -- an identifier is present, then an error message is issued, and
637 -- Pragma_Exit is raised.
639 procedure Check_No_Identifiers;
640 -- Checks that none of the arguments to the pragma has an identifier.
641 -- If any argument has an identifier, then an error message is issued,
642 -- and Pragma_Exit is raised.
644 procedure Check_No_Link_Name;
645 -- Checks that no link name is specified
647 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
648 -- Checks if the given argument has an identifier, and if so, requires
649 -- it to match the given identifier name. If there is a non-matching
650 -- identifier, then an error message is given and Pragma_Exit is raised.
652 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
653 -- Checks if the given argument has an identifier, and if so, requires
654 -- it to match the given identifier name. If there is a non-matching
655 -- identifier, then an error message is given and Pragma_Exit is raised.
656 -- In this version of the procedure, the identifier name is given as
657 -- a string with lower case letters.
659 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
660 -- Called to process a precondition or postcondition pragma. There are
663 -- The pragma appears after a subprogram spec
665 -- If the corresponding check is not enabled, the pragma is analyzed
666 -- but otherwise ignored and control returns with In_Body set False.
668 -- If the check is enabled, then the first step is to analyze the
669 -- pragma, but this is skipped if the subprogram spec appears within
670 -- a package specification (because this is the case where we delay
671 -- analysis till the end of the spec). Then (whether or not it was
672 -- analyzed), the pragma is chained to the subprogram in question
673 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
674 -- caller with In_Body set False.
676 -- The pragma appears at the start of subprogram body declarations
678 -- In this case an immediate return to the caller is made with
679 -- In_Body set True, and the pragma is NOT analyzed.
681 -- In all other cases, an error message for bad placement is given
683 procedure Check_Static_Constraint (Constr : Node_Id);
684 -- Constr is a constraint from an N_Subtype_Indication node from a
685 -- component constraint in an Unchecked_Union type. This routine checks
686 -- that the constraint is static as required by the restrictions for
689 procedure Check_Valid_Configuration_Pragma;
690 -- Legality checks for placement of a configuration pragma
692 procedure Check_Valid_Library_Unit_Pragma;
693 -- Legality checks for library unit pragmas. A special case arises for
694 -- pragmas in generic instances that come from copies of the original
695 -- library unit pragmas in the generic templates. In the case of other
696 -- than library level instantiations these can appear in contexts which
697 -- would normally be invalid (they only apply to the original template
698 -- and to library level instantiations), and they are simply ignored,
699 -- which is implemented by rewriting them as null statements.
701 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
702 -- Check an Unchecked_Union variant for lack of nested variants and
703 -- presence of at least one component. UU_Typ is the related Unchecked_
706 procedure Error_Pragma (Msg : String);
707 pragma No_Return (Error_Pragma);
708 -- Outputs error message for current pragma. The message contains a %
709 -- that will be replaced with the pragma name, and the flag is placed
710 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
711 -- calls Fix_Error (see spec of that function for details).
713 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
714 pragma No_Return (Error_Pragma_Arg);
715 -- Outputs error message for current pragma. The message may contain
716 -- a % that will be replaced with the pragma name. The parameter Arg
717 -- may either be a pragma argument association, in which case the flag
718 -- is placed on the expression of this association, or an expression,
719 -- in which case the flag is placed directly on the expression. The
720 -- message is placed using Error_Msg_N, so the message may also contain
721 -- an & insertion character which will reference the given Arg value.
722 -- After placing the message, Pragma_Exit is raised. Note: this routine
723 -- calls Fix_Error (see spec of that function for details).
725 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
726 pragma No_Return (Error_Pragma_Arg);
727 -- Similar to above form of Error_Pragma_Arg except that two messages
728 -- are provided, the second is a continuation comment starting with \.
730 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
731 pragma No_Return (Error_Pragma_Arg_Ident);
732 -- Outputs error message for current pragma. The message may contain
733 -- a % that will be replaced with the pragma name. The parameter Arg
734 -- must be a pragma argument association with a non-empty identifier
735 -- (i.e. its Chars field must be set), and the error message is placed
736 -- on the identifier. The message is placed using Error_Msg_N so
737 -- the message may also contain an & insertion character which will
738 -- reference the identifier. After placing the message, Pragma_Exit
739 -- is raised. Note: this routine calls Fix_Error (see spec of that
740 -- function for details).
742 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
743 pragma No_Return (Error_Pragma_Ref);
744 -- Outputs error message for current pragma. The message may contain
745 -- a % that will be replaced with the pragma name. The parameter Ref
746 -- must be an entity whose name can be referenced by & and sloc by #.
747 -- After placing the message, Pragma_Exit is raised. Note: this routine
748 -- calls Fix_Error (see spec of that function for details).
750 function Find_Lib_Unit_Name return Entity_Id;
751 -- Used for a library unit pragma to find the entity to which the
752 -- library unit pragma applies, returns the entity found.
754 procedure Find_Program_Unit_Name (Id : Node_Id);
755 -- If the pragma is a compilation unit pragma, the id must denote the
756 -- compilation unit in the same compilation, and the pragma must appear
757 -- in the list of preceding or trailing pragmas. If it is a program
758 -- unit pragma that is not a compilation unit pragma, then the
759 -- identifier must be visible.
761 function Find_Unique_Parameterless_Procedure
763 Arg : Node_Id) return Entity_Id;
764 -- Used for a procedure pragma to find the unique parameterless
765 -- procedure identified by Name, returns it if it exists, otherwise
766 -- errors out and uses Arg as the pragma argument for the message.
768 procedure Fix_Error (Msg : in out String);
769 -- This is called prior to issuing an error message. Msg is a string
770 -- that typically contains the substring "pragma". If the current pragma
771 -- comes from an aspect, each such "pragma" substring is replaced with
772 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
773 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
775 procedure Gather_Associations
777 Args : out Args_List);
778 -- This procedure is used to gather the arguments for a pragma that
779 -- permits arbitrary ordering of parameters using the normal rules
780 -- for named and positional parameters. The Names argument is a list
781 -- of Name_Id values that corresponds to the allowed pragma argument
782 -- association identifiers in order. The result returned in Args is
783 -- a list of corresponding expressions that are the pragma arguments.
784 -- Note that this is a list of expressions, not of pragma argument
785 -- associations (Gather_Associations has completely checked all the
786 -- optional identifiers when it returns). An entry in Args is Empty
787 -- on return if the corresponding argument is not present.
789 procedure GNAT_Pragma;
790 -- Called for all GNAT defined pragmas to check the relevant restriction
791 -- (No_Implementation_Pragmas).
793 procedure S14_Pragma;
794 -- Called for all pragmas defined for formal verification to check that
795 -- the S14_Extensions flag is set.
796 -- This name needs fixing ??? There is no such thing as an
797 -- "S14_Extensions" flag ???
799 function Is_Before_First_Decl
800 (Pragma_Node : Node_Id;
801 Decls : List_Id) return Boolean;
802 -- Return True if Pragma_Node is before the first declarative item in
803 -- Decls where Decls is the list of declarative items.
805 function Is_Configuration_Pragma return Boolean;
806 -- Determines if the placement of the current pragma is appropriate
807 -- for a configuration pragma.
809 function Is_In_Context_Clause return Boolean;
810 -- Returns True if pragma appears within the context clause of a unit,
811 -- and False for any other placement (does not generate any messages).
813 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
814 -- Analyzes the argument, and determines if it is a static string
815 -- expression, returns True if so, False if non-static or not String.
817 procedure Pragma_Misplaced;
818 pragma No_Return (Pragma_Misplaced);
819 -- Issue fatal error message for misplaced pragma
821 procedure Process_Atomic_Shared_Volatile;
822 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
823 -- Shared is an obsolete Ada 83 pragma, treated as being identical
824 -- in effect to pragma Atomic.
826 procedure Process_Compile_Time_Warning_Or_Error;
827 -- Common processing for Compile_Time_Error and Compile_Time_Warning
829 procedure Process_Convention
830 (C : out Convention_Id;
831 Ent : out Entity_Id);
832 -- Common processing for Convention, Interface, Import and Export.
833 -- Checks first two arguments of pragma, and sets the appropriate
834 -- convention value in the specified entity or entities. On return
835 -- C is the convention, Ent is the referenced entity.
837 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
838 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
839 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
841 procedure Process_Extended_Import_Export_Exception_Pragma
842 (Arg_Internal : Node_Id;
843 Arg_External : Node_Id;
846 -- Common processing for the pragmas Import/Export_Exception. The three
847 -- arguments correspond to the three named parameters of the pragma. An
848 -- argument is empty if the corresponding parameter is not present in
851 procedure Process_Extended_Import_Export_Object_Pragma
852 (Arg_Internal : Node_Id;
853 Arg_External : Node_Id;
855 -- Common processing for the pragmas Import/Export_Object. The three
856 -- arguments correspond to the three named parameters of the pragmas. An
857 -- argument is empty if the corresponding parameter is not present in
860 procedure Process_Extended_Import_Export_Internal_Arg
861 (Arg_Internal : Node_Id := Empty);
862 -- Common processing for all extended Import and Export pragmas. The
863 -- argument is the pragma parameter for the Internal argument. If
864 -- Arg_Internal is empty or inappropriate, an error message is posted.
865 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
866 -- set to identify the referenced entity.
868 procedure Process_Extended_Import_Export_Subprogram_Pragma
869 (Arg_Internal : Node_Id;
870 Arg_External : Node_Id;
871 Arg_Parameter_Types : Node_Id;
872 Arg_Result_Type : Node_Id := Empty;
873 Arg_Mechanism : Node_Id;
874 Arg_Result_Mechanism : Node_Id := Empty;
875 Arg_First_Optional_Parameter : Node_Id := Empty);
876 -- Common processing for all extended Import and Export pragmas applying
877 -- to subprograms. The caller omits any arguments that do not apply to
878 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
879 -- only in the Import_Function and Export_Function cases). The argument
880 -- names correspond to the allowed pragma association identifiers.
882 procedure Process_Generic_List;
883 -- Common processing for Share_Generic and Inline_Generic
885 procedure Process_Import_Or_Interface;
886 -- Common processing for Import of Interface
888 procedure Process_Import_Predefined_Type;
889 -- Processing for completing a type with pragma Import. This is used
890 -- to declare types that match predefined C types, especially for cases
891 -- without corresponding Ada predefined type.
893 type Inline_Status is (Suppressed, Disabled, Enabled);
894 -- Inline status of a subprogram, indicated as follows:
895 -- Suppressed: inlining is suppressed for the subprogram
896 -- Disabled: no inlining is requested for the subprogram
897 -- Enabled: inlining is requested/required for the subprogram
899 procedure Process_Inline (Status : Inline_Status);
900 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
901 -- indicates the inline status specified by the pragma.
903 procedure Process_Interface_Name
904 (Subprogram_Def : Entity_Id;
907 -- Given the last two arguments of pragma Import, pragma Export, or
908 -- pragma Interface_Name, performs validity checks and sets the
909 -- Interface_Name field of the given subprogram entity to the
910 -- appropriate external or link name, depending on the arguments given.
911 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
912 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
913 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
914 -- nor Link_Arg is present, the interface name is set to the default
915 -- from the subprogram name.
917 procedure Process_Interrupt_Or_Attach_Handler;
918 -- Common processing for Interrupt and Attach_Handler pragmas
920 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
921 -- Common processing for Restrictions and Restriction_Warnings pragmas.
922 -- Warn is True for Restriction_Warnings, or for Restrictions if the
923 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
924 -- is not set in the Restrictions case.
926 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
927 -- Common processing for Suppress and Unsuppress. The boolean parameter
928 -- Suppress_Case is True for the Suppress case, and False for the
931 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
932 -- This procedure sets the Is_Exported flag for the given entity,
933 -- checking that the entity was not previously imported. Arg is
934 -- the argument that specified the entity. A check is also made
935 -- for exporting inappropriate entities.
937 procedure Set_Extended_Import_Export_External_Name
938 (Internal_Ent : Entity_Id;
939 Arg_External : Node_Id);
940 -- Common processing for all extended import export pragmas. The first
941 -- argument, Internal_Ent, is the internal entity, which has already
942 -- been checked for validity by the caller. Arg_External is from the
943 -- Import or Export pragma, and may be null if no External parameter
944 -- was present. If Arg_External is present and is a non-null string
945 -- (a null string is treated as the default), then the Interface_Name
946 -- field of Internal_Ent is set appropriately.
948 procedure Set_Imported (E : Entity_Id);
949 -- This procedure sets the Is_Imported flag for the given entity,
950 -- checking that it is not previously exported or imported.
952 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
953 -- Mech is a parameter passing mechanism (see Import_Function syntax
954 -- for MECHANISM_NAME). This routine checks that the mechanism argument
955 -- has the right form, and if not issues an error message. If the
956 -- argument has the right form then the Mechanism field of Ent is
957 -- set appropriately.
959 procedure Set_Rational_Profile;
960 -- Activate the set of configuration pragmas and permissions that make
961 -- up the Rational profile.
963 procedure Set_Ravenscar_Profile (N : Node_Id);
964 -- Activate the set of configuration pragmas and restrictions that make
965 -- up the Ravenscar Profile. N is the corresponding pragma node, which
966 -- is used for error messages on any constructs that violate the
969 ---------------------
970 -- Ada_2005_Pragma --
971 ---------------------
973 procedure Ada_2005_Pragma is
975 if Ada_Version <= Ada_95 then
976 Check_Restriction (No_Implementation_Pragmas, N);
980 ---------------------
981 -- Ada_2012_Pragma --
982 ---------------------
984 procedure Ada_2012_Pragma is
986 if Ada_Version <= Ada_2005 then
987 Check_Restriction (No_Implementation_Pragmas, N);
995 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id) is
998 To_List := New_Elmt_List;
1001 Append_Unique_Elmt (Item, To_List);
1004 --------------------------
1005 -- Check_Ada_83_Warning --
1006 --------------------------
1008 procedure Check_Ada_83_Warning is
1010 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
1011 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
1013 end Check_Ada_83_Warning;
1015 ---------------------
1016 -- Check_Arg_Count --
1017 ---------------------
1019 procedure Check_Arg_Count (Required : Nat) is
1021 if Arg_Count /= Required then
1022 Error_Pragma ("wrong number of arguments for pragma%");
1024 end Check_Arg_Count;
1026 --------------------------------
1027 -- Check_Arg_Is_External_Name --
1028 --------------------------------
1030 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
1031 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1034 if Nkind (Argx) = N_Identifier then
1038 Analyze_And_Resolve (Argx, Standard_String);
1040 if Is_OK_Static_Expression (Argx) then
1043 elsif Etype (Argx) = Any_Type then
1046 -- An interesting special case, if we have a string literal and
1047 -- we are in Ada 83 mode, then we allow it even though it will
1048 -- not be flagged as static. This allows expected Ada 83 mode
1049 -- use of external names which are string literals, even though
1050 -- technically these are not static in Ada 83.
1052 elsif Ada_Version = Ada_83
1053 and then Nkind (Argx) = N_String_Literal
1057 -- Static expression that raises Constraint_Error. This has
1058 -- already been flagged, so just exit from pragma processing.
1060 elsif Is_Static_Expression (Argx) then
1063 -- Here we have a real error (non-static expression)
1066 Error_Msg_Name_1 := Pname;
1070 "argument for pragma% must be a identifier or "
1071 & "static string expression!";
1074 Flag_Non_Static_Expr (Msg, Argx);
1079 end Check_Arg_Is_External_Name;
1081 -----------------------------
1082 -- Check_Arg_Is_Identifier --
1083 -----------------------------
1085 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
1086 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1088 if Nkind (Argx) /= N_Identifier then
1090 ("argument for pragma% must be identifier", Argx);
1092 end Check_Arg_Is_Identifier;
1094 ----------------------------------
1095 -- Check_Arg_Is_Integer_Literal --
1096 ----------------------------------
1098 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1099 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1101 if Nkind (Argx) /= N_Integer_Literal then
1103 ("argument for pragma% must be integer literal", Argx);
1105 end Check_Arg_Is_Integer_Literal;
1107 -------------------------------------------
1108 -- Check_Arg_Is_Library_Level_Local_Name --
1109 -------------------------------------------
1113 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1114 -- | library_unit_NAME
1116 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1118 Check_Arg_Is_Local_Name (Arg);
1120 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1121 and then Comes_From_Source (N)
1124 ("argument for pragma% must be library level entity", Arg);
1126 end Check_Arg_Is_Library_Level_Local_Name;
1128 -----------------------------
1129 -- Check_Arg_Is_Local_Name --
1130 -----------------------------
1134 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1135 -- | library_unit_NAME
1137 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1138 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1143 if Nkind (Argx) not in N_Direct_Name
1144 and then (Nkind (Argx) /= N_Attribute_Reference
1145 or else Present (Expressions (Argx))
1146 or else Nkind (Prefix (Argx)) /= N_Identifier)
1147 and then (not Is_Entity_Name (Argx)
1148 or else not Is_Compilation_Unit (Entity (Argx)))
1150 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1153 -- No further check required if not an entity name
1155 if not Is_Entity_Name (Argx) then
1161 Ent : constant Entity_Id := Entity (Argx);
1162 Scop : constant Entity_Id := Scope (Ent);
1164 -- Case of a pragma applied to a compilation unit: pragma must
1165 -- occur immediately after the program unit in the compilation.
1167 if Is_Compilation_Unit (Ent) then
1169 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1172 -- Case of pragma placed immediately after spec
1174 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1177 -- Case of pragma placed immediately after body
1179 elsif Nkind (Decl) = N_Subprogram_Declaration
1180 and then Present (Corresponding_Body (Decl))
1184 (Parent (Unit_Declaration_Node
1185 (Corresponding_Body (Decl))));
1187 -- All other cases are illegal
1194 -- Special restricted placement rule from 10.2.1(11.8/2)
1196 elsif Is_Generic_Formal (Ent)
1197 and then Prag_Id = Pragma_Preelaborable_Initialization
1199 OK := List_Containing (N) =
1200 Generic_Formal_Declarations
1201 (Unit_Declaration_Node (Scop));
1203 -- Default case, just check that the pragma occurs in the scope
1204 -- of the entity denoted by the name.
1207 OK := Current_Scope = Scop;
1212 ("pragma% argument must be in same declarative part", Arg);
1216 end Check_Arg_Is_Local_Name;
1218 ---------------------------------
1219 -- Check_Arg_Is_Locking_Policy --
1220 ---------------------------------
1222 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1223 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1226 Check_Arg_Is_Identifier (Argx);
1228 if not Is_Locking_Policy_Name (Chars (Argx)) then
1229 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1231 end Check_Arg_Is_Locking_Policy;
1233 -----------------------------------------------
1234 -- Check_Arg_Is_Partition_Elaboration_Policy --
1235 -----------------------------------------------
1237 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
1238 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1241 Check_Arg_Is_Identifier (Argx);
1243 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
1245 ("& is not a valid partition elaboration policy name", Argx);
1247 end Check_Arg_Is_Partition_Elaboration_Policy;
1249 -------------------------
1250 -- Check_Arg_Is_One_Of --
1251 -------------------------
1253 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1254 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1257 Check_Arg_Is_Identifier (Argx);
1259 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1260 Error_Msg_Name_2 := N1;
1261 Error_Msg_Name_3 := N2;
1262 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1264 end Check_Arg_Is_One_Of;
1266 procedure Check_Arg_Is_One_Of
1268 N1, N2, N3 : 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
1279 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1281 end Check_Arg_Is_One_Of;
1283 procedure Check_Arg_Is_One_Of
1285 N1, N2, N3, N4 : Name_Id)
1287 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1290 Check_Arg_Is_Identifier (Argx);
1292 if Chars (Argx) /= N1
1293 and then Chars (Argx) /= N2
1294 and then Chars (Argx) /= N3
1295 and then Chars (Argx) /= N4
1297 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1299 end Check_Arg_Is_One_Of;
1301 procedure Check_Arg_Is_One_Of
1303 N1, N2, N3, N4, N5 : Name_Id)
1305 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1308 Check_Arg_Is_Identifier (Argx);
1310 if Chars (Argx) /= N1
1311 and then Chars (Argx) /= N2
1312 and then Chars (Argx) /= N3
1313 and then Chars (Argx) /= N4
1314 and then Chars (Argx) /= N5
1316 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1318 end Check_Arg_Is_One_Of;
1320 ---------------------------------
1321 -- Check_Arg_Is_Queuing_Policy --
1322 ---------------------------------
1324 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1325 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1328 Check_Arg_Is_Identifier (Argx);
1330 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1331 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1333 end Check_Arg_Is_Queuing_Policy;
1335 ------------------------------------
1336 -- Check_Arg_Is_Static_Expression --
1337 ------------------------------------
1339 procedure Check_Arg_Is_Static_Expression
1341 Typ : Entity_Id := Empty)
1344 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1345 end Check_Arg_Is_Static_Expression;
1347 ------------------------------------------
1348 -- Check_Arg_Is_Task_Dispatching_Policy --
1349 ------------------------------------------
1351 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1352 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1355 Check_Arg_Is_Identifier (Argx);
1357 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1359 ("& is not a valid task dispatching policy name", Argx);
1361 end Check_Arg_Is_Task_Dispatching_Policy;
1363 ---------------------
1364 -- Check_Arg_Order --
1365 ---------------------
1367 procedure Check_Arg_Order (Names : Name_List) is
1370 Highest_So_Far : Natural := 0;
1371 -- Highest index in Names seen do far
1375 for J in 1 .. Arg_Count loop
1376 if Chars (Arg) /= No_Name then
1377 for K in Names'Range loop
1378 if Chars (Arg) = Names (K) then
1379 if K < Highest_So_Far then
1380 Error_Msg_Name_1 := Pname;
1382 ("parameters out of order for pragma%", Arg);
1383 Error_Msg_Name_1 := Names (K);
1384 Error_Msg_Name_2 := Names (Highest_So_Far);
1385 Error_Msg_N ("\% must appear before %", Arg);
1389 Highest_So_Far := K;
1397 end Check_Arg_Order;
1399 --------------------------------
1400 -- Check_At_Least_N_Arguments --
1401 --------------------------------
1403 procedure Check_At_Least_N_Arguments (N : Nat) is
1405 if Arg_Count < N then
1406 Error_Pragma ("too few arguments for pragma%");
1408 end Check_At_Least_N_Arguments;
1410 -------------------------------
1411 -- Check_At_Most_N_Arguments --
1412 -------------------------------
1414 procedure Check_At_Most_N_Arguments (N : Nat) is
1417 if Arg_Count > N then
1419 for J in 1 .. N loop
1421 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1424 end Check_At_Most_N_Arguments;
1426 ---------------------
1427 -- Check_Component --
1428 ---------------------
1430 procedure Check_Component
1433 In_Variant_Part : Boolean := False)
1435 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1436 Sindic : constant Node_Id :=
1437 Subtype_Indication (Component_Definition (Comp));
1438 Typ : constant Entity_Id := Etype (Comp_Id);
1441 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1442 -- object constraint, then the component type shall be an Unchecked_
1445 if Nkind (Sindic) = N_Subtype_Indication
1446 and then Has_Per_Object_Constraint (Comp_Id)
1447 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1450 ("component subtype subject to per-object constraint "
1451 & "must be an Unchecked_Union", Comp);
1453 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1454 -- the body of a generic unit, or within the body of any of its
1455 -- descendant library units, no part of the type of a component
1456 -- declared in a variant_part of the unchecked union type shall be of
1457 -- a formal private type or formal private extension declared within
1458 -- the formal part of the generic unit.
1460 elsif Ada_Version >= Ada_2012
1461 and then In_Generic_Body (UU_Typ)
1462 and then In_Variant_Part
1463 and then Is_Private_Type (Typ)
1464 and then Is_Generic_Type (Typ)
1467 ("component of unchecked union cannot be of generic type", Comp);
1469 elsif Needs_Finalization (Typ) then
1471 ("component of unchecked union cannot be controlled", Comp);
1473 elsif Has_Task (Typ) then
1475 ("component of unchecked union cannot have tasks", Comp);
1477 end Check_Component;
1479 ---------------------------------
1480 -- Check_Contract_Or_Test_Case --
1481 ---------------------------------
1483 procedure Check_Contract_Or_Test_Case is
1487 procedure Chain_CTC (PO : Node_Id);
1488 -- If PO is a [generic] subprogram declaration node, then the
1489 -- contract-case or test-case applies to this subprogram and the
1490 -- processing for the pragma is completed. Otherwise the pragma
1497 procedure Chain_CTC (PO : Node_Id) is
1501 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1503 ("pragma% cannot be applied to abstract subprogram");
1505 elsif Nkind (PO) = N_Entry_Declaration then
1506 Error_Pragma ("pragma% cannot be applied to entry");
1508 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1509 N_Generic_Subprogram_Declaration)
1514 -- Here if we have [generic] subprogram declaration
1516 S := Defining_Unit_Name (Specification (PO));
1518 -- Note: we do not analyze the pragma at this point. Instead we
1519 -- delay this analysis until the end of the declarative part in
1520 -- which the pragma appears. This implements the required delay
1521 -- in this analysis, allowing forward references. The analysis
1522 -- happens at the end of Analyze_Declarations.
1524 -- There should not be another contract-case or test-case with the
1525 -- same name associated to this subprogram.
1528 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
1532 CTC := Spec_CTC_List (Contract (S));
1533 while Present (CTC) loop
1535 -- Omit pragma Contract_Cases because it does not introduce
1536 -- a unique case name and it does not follow the syntax of
1537 -- Contract_Case and Test_Case.
1539 if Pragma_Name (CTC) = Name_Contract_Cases then
1543 (Name, Get_Name_From_CTC_Pragma (CTC))
1545 Error_Msg_Sloc := Sloc (CTC);
1546 Error_Pragma ("name for pragma% is already used#");
1549 CTC := Next_Pragma (CTC);
1553 -- Chain spec CTC pragma to list for subprogram
1555 Set_Next_Pragma (N, Spec_CTC_List (Contract (S)));
1556 Set_Spec_CTC_List (Contract (S), N);
1559 -- Start of processing for Check_Contract_Or_Test_Case
1562 -- First check pragma arguments
1565 Check_At_Least_N_Arguments (2);
1566 Check_At_Most_N_Arguments (4);
1568 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
1570 Check_Optional_Identifier (Arg1, Name_Name);
1571 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
1573 -- In ASIS mode, for a pragma generated from a source aspect, also
1574 -- analyze the original aspect expression.
1577 and then Present (Corresponding_Aspect (N))
1579 Check_Expr_Is_Static_Expression
1580 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
1583 Check_Optional_Identifier (Arg2, Name_Mode);
1584 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
1586 if Arg_Count = 4 then
1587 Check_Identifier (Arg3, Name_Requires);
1588 Check_Identifier (Arg4, Name_Ensures);
1590 elsif Arg_Count = 3 then
1591 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
1594 -- Check pragma placement
1596 if not Is_List_Member (N) then
1600 -- Contract-case or test-case should only appear in package spec unit
1602 if Get_Source_Unit (N) = No_Unit
1603 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
1604 N_Package_Declaration,
1605 N_Generic_Package_Declaration)
1610 -- Search prior declarations
1613 while Present (Prev (P)) loop
1616 -- If the previous node is a generic subprogram, do not go to to
1617 -- the original node, which is the unanalyzed tree: we need to
1618 -- attach the contract-case or test-case to the analyzed version
1619 -- at this point. They get propagated to the original tree when
1620 -- analyzing the corresponding body.
1622 if Nkind (P) not in N_Generic_Declaration then
1623 PO := Original_Node (P);
1628 -- Skip past prior pragma
1630 if Nkind (PO) = N_Pragma then
1633 -- Skip stuff not coming from source
1635 elsif not Comes_From_Source (PO) then
1638 -- Only remaining possibility is subprogram declaration. First
1639 -- check that it is declared directly in a package declaration.
1640 -- This may be either the package declaration for the current unit
1641 -- being defined or a local package declaration.
1643 elsif not Present (Parent (Parent (PO)))
1644 or else not Present (Parent (Parent (Parent (PO))))
1645 or else not Nkind_In (Parent (Parent (PO)),
1646 N_Package_Declaration,
1647 N_Generic_Package_Declaration)
1657 -- If we fall through, pragma was misplaced
1660 end Check_Contract_Or_Test_Case;
1662 ----------------------------
1663 -- Check_Duplicate_Pragma --
1664 ----------------------------
1666 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1667 Id : Entity_Id := E;
1671 -- Nothing to do if this pragma comes from an aspect specification,
1672 -- since we could not be duplicating a pragma, and we dealt with the
1673 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1675 if From_Aspect_Specification (N) then
1679 -- Otherwise current pragma may duplicate previous pragma or a
1680 -- previously given aspect specification or attribute definition
1681 -- clause for the same pragma.
1683 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
1686 Error_Msg_Name_1 := Pragma_Name (N);
1687 Error_Msg_Sloc := Sloc (P);
1689 -- For a single protected or a single task object, the error is
1690 -- issued on the original entity.
1692 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
1693 Id := Defining_Identifier (Original_Node (Parent (Id)));
1696 if Nkind (P) = N_Aspect_Specification
1697 or else From_Aspect_Specification (P)
1699 Error_Msg_NE ("aspect% for & previously given#", N, Id);
1701 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
1706 end Check_Duplicate_Pragma;
1708 ----------------------------------
1709 -- Check_Duplicated_Export_Name --
1710 ----------------------------------
1712 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1713 String_Val : constant String_Id := Strval (Nam);
1716 -- We are only interested in the export case, and in the case of
1717 -- generics, it is the instance, not the template, that is the
1718 -- problem (the template will generate a warning in any case).
1720 if not Inside_A_Generic
1721 and then (Prag_Id = Pragma_Export
1723 Prag_Id = Pragma_Export_Procedure
1725 Prag_Id = Pragma_Export_Valued_Procedure
1727 Prag_Id = Pragma_Export_Function)
1729 for J in Externals.First .. Externals.Last loop
1730 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1731 Error_Msg_Sloc := Sloc (Externals.Table (J));
1732 Error_Msg_N ("external name duplicates name given#", Nam);
1737 Externals.Append (Nam);
1739 end Check_Duplicated_Export_Name;
1741 -------------------------------------
1742 -- Check_Expr_Is_Static_Expression --
1743 -------------------------------------
1745 procedure Check_Expr_Is_Static_Expression
1747 Typ : Entity_Id := Empty)
1750 if Present (Typ) then
1751 Analyze_And_Resolve (Expr, Typ);
1753 Analyze_And_Resolve (Expr);
1756 if Is_OK_Static_Expression (Expr) then
1759 elsif Etype (Expr) = Any_Type then
1762 -- An interesting special case, if we have a string literal and we
1763 -- are in Ada 83 mode, then we allow it even though it will not be
1764 -- flagged as static. This allows the use of Ada 95 pragmas like
1765 -- Import in Ada 83 mode. They will of course be flagged with
1766 -- warnings as usual, but will not cause errors.
1768 elsif Ada_Version = Ada_83
1769 and then Nkind (Expr) = N_String_Literal
1773 -- Static expression that raises Constraint_Error. This has already
1774 -- been flagged, so just exit from pragma processing.
1776 elsif Is_Static_Expression (Expr) then
1779 -- Finally, we have a real error
1782 Error_Msg_Name_1 := Pname;
1786 "argument for pragma% must be a static expression!";
1789 Flag_Non_Static_Expr (Msg, Expr);
1794 end Check_Expr_Is_Static_Expression;
1796 -------------------------
1797 -- Check_First_Subtype --
1798 -------------------------
1800 procedure Check_First_Subtype (Arg : Node_Id) is
1801 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1802 Ent : constant Entity_Id := Entity (Argx);
1805 if Is_First_Subtype (Ent) then
1808 elsif Is_Type (Ent) then
1810 ("pragma% cannot apply to subtype", Argx);
1812 elsif Is_Object (Ent) then
1814 ("pragma% cannot apply to object, requires a type", Argx);
1818 ("pragma% cannot apply to&, requires a type", Argx);
1820 end Check_First_Subtype;
1822 ----------------------
1823 -- Check_Identifier --
1824 ----------------------
1826 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1829 and then Nkind (Arg) = N_Pragma_Argument_Association
1831 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1832 Error_Msg_Name_1 := Pname;
1833 Error_Msg_Name_2 := Id;
1834 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1838 end Check_Identifier;
1840 --------------------------------
1841 -- Check_Identifier_Is_One_Of --
1842 --------------------------------
1844 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1847 and then Nkind (Arg) = N_Pragma_Argument_Association
1849 if Chars (Arg) = No_Name then
1850 Error_Msg_Name_1 := Pname;
1851 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1854 elsif Chars (Arg) /= N1
1855 and then Chars (Arg) /= N2
1857 Error_Msg_Name_1 := Pname;
1858 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1862 end Check_Identifier_Is_One_Of;
1864 ---------------------------
1865 -- Check_In_Main_Program --
1866 ---------------------------
1868 procedure Check_In_Main_Program is
1869 P : constant Node_Id := Parent (N);
1872 -- Must be at in subprogram body
1874 if Nkind (P) /= N_Subprogram_Body then
1875 Error_Pragma ("% pragma allowed only in subprogram");
1877 -- Otherwise warn if obviously not main program
1879 elsif Present (Parameter_Specifications (Specification (P)))
1880 or else not Is_Compilation_Unit (Defining_Entity (P))
1882 Error_Msg_Name_1 := Pname;
1884 ("??pragma% is only effective in main program", N);
1886 end Check_In_Main_Program;
1888 ---------------------------------------
1889 -- Check_Interrupt_Or_Attach_Handler --
1890 ---------------------------------------
1892 procedure Check_Interrupt_Or_Attach_Handler is
1893 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1894 Handler_Proc, Proc_Scope : Entity_Id;
1899 if Prag_Id = Pragma_Interrupt_Handler then
1900 Check_Restriction (No_Dynamic_Attachment, N);
1903 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1904 Proc_Scope := Scope (Handler_Proc);
1906 -- On AAMP only, a pragma Interrupt_Handler is supported for
1907 -- nonprotected parameterless procedures.
1909 if not AAMP_On_Target
1910 or else Prag_Id = Pragma_Attach_Handler
1912 if Ekind (Proc_Scope) /= E_Protected_Type then
1914 ("argument of pragma% must be protected procedure", Arg1);
1917 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1918 Error_Pragma ("pragma% must be in protected definition");
1922 if not Is_Library_Level_Entity (Proc_Scope)
1923 or else (AAMP_On_Target
1924 and then not Is_Library_Level_Entity (Handler_Proc))
1927 ("argument for pragma% must be library level entity", Arg1);
1930 -- AI05-0033: A pragma cannot appear within a generic body, because
1931 -- instance can be in a nested scope. The check that protected type
1932 -- is itself a library-level declaration is done elsewhere.
1934 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
1935 -- handle code prior to AI-0033. Analysis tools typically are not
1936 -- interested in this pragma in any case, so no need to worry too
1937 -- much about its placement.
1939 if Inside_A_Generic then
1940 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1941 and then In_Package_Body (Scope (Current_Scope))
1942 and then not Relaxed_RM_Semantics
1944 Error_Pragma ("pragma% cannot be used inside a generic");
1947 end Check_Interrupt_Or_Attach_Handler;
1949 ---------------------------------
1950 -- Check_Loop_Pragma_Placement --
1951 ---------------------------------
1953 procedure Check_Loop_Pragma_Placement is
1954 procedure Placement_Error (Constr : Node_Id);
1955 pragma No_Return (Placement_Error);
1956 -- Node Constr denotes the last loop restricted construct before we
1957 -- encountered an illegal relation between enclosing constructs. Emit
1958 -- an error depending on what Constr was.
1960 ---------------------
1961 -- Placement_Error --
1962 ---------------------
1964 procedure Placement_Error (Constr : Node_Id) is
1966 if Nkind (Constr) = N_Pragma then
1968 ("pragma % must appear immediately within the statements "
1972 ("block containing pragma % must appear immediately within "
1973 & "the statements of a loop", Constr);
1975 end Placement_Error;
1977 -- Local declarations
1982 -- Start of processing for Check_Loop_Pragma_Placement
1987 while Present (Stmt) loop
1989 -- The pragma or previous block must appear immediately within the
1990 -- current block's declarative or statement part.
1992 if Nkind (Stmt) = N_Block_Statement then
1993 if (No (Declarations (Stmt))
1994 or else List_Containing (Prev) /= Declarations (Stmt))
1996 List_Containing (Prev) /=
1997 Statements (Handled_Statement_Sequence (Stmt))
1999 Placement_Error (Prev);
2002 -- Keep inspecting the parents because we are now within a
2003 -- chain of nested blocks.
2007 Stmt := Parent (Stmt);
2010 -- The pragma or previous block must appear immediately within the
2011 -- statements of the loop.
2013 elsif Nkind (Stmt) = N_Loop_Statement then
2014 if List_Containing (Prev) /= Statements (Stmt) then
2015 Placement_Error (Prev);
2018 -- Stop the traversal because we reached the innermost loop
2019 -- regardless of whether we encountered an error or not.
2023 -- Ignore a handled statement sequence. Note that this node may
2024 -- be related to a subprogram body in which case we will emit an
2025 -- error on the next iteration of the search.
2027 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
2028 Stmt := Parent (Stmt);
2030 -- Any other statement breaks the chain from the pragma to the
2034 Placement_Error (Prev);
2038 end Check_Loop_Pragma_Placement;
2040 -------------------------------------------
2041 -- Check_Is_In_Decl_Part_Or_Package_Spec --
2042 -------------------------------------------
2044 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
2053 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
2056 elsif Nkind_In (P, N_Package_Specification,
2061 -- Note: the following tests seem a little peculiar, because
2062 -- they test for bodies, but if we were in the statement part
2063 -- of the body, we would already have hit the handled statement
2064 -- sequence, so the only way we get here is by being in the
2065 -- declarative part of the body.
2067 elsif Nkind_In (P, N_Subprogram_Body,
2078 Error_Pragma ("pragma% is not in declarative part or package spec");
2079 end Check_Is_In_Decl_Part_Or_Package_Spec;
2081 -------------------------
2082 -- Check_No_Identifier --
2083 -------------------------
2085 procedure Check_No_Identifier (Arg : Node_Id) is
2087 if Nkind (Arg) = N_Pragma_Argument_Association
2088 and then Chars (Arg) /= No_Name
2090 Error_Pragma_Arg_Ident
2091 ("pragma% does not permit identifier& here", Arg);
2093 end Check_No_Identifier;
2095 --------------------------
2096 -- Check_No_Identifiers --
2097 --------------------------
2099 procedure Check_No_Identifiers is
2102 if Arg_Count > 0 then
2104 while Present (Arg_Node) loop
2105 Check_No_Identifier (Arg_Node);
2109 end Check_No_Identifiers;
2111 ------------------------
2112 -- Check_No_Link_Name --
2113 ------------------------
2115 procedure Check_No_Link_Name is
2118 and then Chars (Arg3) = Name_Link_Name
2123 if Present (Arg4) then
2125 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
2127 end Check_No_Link_Name;
2129 -------------------------------
2130 -- Check_Optional_Identifier --
2131 -------------------------------
2133 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
2136 and then Nkind (Arg) = N_Pragma_Argument_Association
2137 and then Chars (Arg) /= No_Name
2139 if Chars (Arg) /= Id then
2140 Error_Msg_Name_1 := Pname;
2141 Error_Msg_Name_2 := Id;
2142 Error_Msg_N ("pragma% argument expects identifier%", Arg);
2146 end Check_Optional_Identifier;
2148 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
2150 Name_Buffer (1 .. Id'Length) := Id;
2151 Name_Len := Id'Length;
2152 Check_Optional_Identifier (Arg, Name_Find);
2153 end Check_Optional_Identifier;
2155 --------------------------------------
2156 -- Check_Precondition_Postcondition --
2157 --------------------------------------
2159 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
2163 procedure Chain_PPC (PO : Node_Id);
2164 -- If PO is an entry or a [generic] subprogram declaration node, then
2165 -- the precondition/postcondition applies to this subprogram and the
2166 -- processing for the pragma is completed. Otherwise the pragma is
2173 procedure Chain_PPC (PO : Node_Id) is
2177 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2178 if not From_Aspect_Specification (N) then
2180 ("pragma% cannot be applied to abstract subprogram");
2182 elsif Class_Present (N) then
2187 ("aspect % requires ''Class for abstract subprogram");
2190 -- AI05-0230: The same restriction applies to null procedures. For
2191 -- compatibility with earlier uses of the Ada pragma, apply this
2192 -- rule only to aspect specifications.
2194 -- The above discrpency needs documentation. Robert is dubious
2195 -- about whether it is a good idea ???
2197 elsif Nkind (PO) = N_Subprogram_Declaration
2198 and then Nkind (Specification (PO)) = N_Procedure_Specification
2199 and then Null_Present (Specification (PO))
2200 and then From_Aspect_Specification (N)
2201 and then not Class_Present (N)
2204 ("aspect % requires ''Class for null procedure");
2206 -- Pre/postconditions are legal on a subprogram body if it is not
2207 -- a completion of a declaration. They are also legal on a stub
2208 -- with no previous declarations (this is checked when processing
2209 -- the corresponding aspects).
2211 elsif Nkind (PO) = N_Subprogram_Body
2212 and then Acts_As_Spec (PO)
2216 elsif Nkind (PO) = N_Subprogram_Body_Stub then
2219 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2220 N_Expression_Function,
2221 N_Generic_Subprogram_Declaration,
2222 N_Entry_Declaration)
2227 -- Here if we have [generic] subprogram or entry declaration
2229 if Nkind (PO) = N_Entry_Declaration then
2230 S := Defining_Entity (PO);
2232 S := Defining_Unit_Name (Specification (PO));
2234 if Nkind (S) = N_Defining_Program_Unit_Name then
2235 S := Defining_Identifier (S);
2239 -- Note: we do not analyze the pragma at this point. Instead we
2240 -- delay this analysis until the end of the declarative part in
2241 -- which the pragma appears. This implements the required delay
2242 -- in this analysis, allowing forward references. The analysis
2243 -- happens at the end of Analyze_Declarations.
2245 -- Chain spec PPC pragma to list for subprogram
2247 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
2248 Set_Spec_PPC_List (Contract (S), N);
2250 -- Return indicating spec case
2256 -- Start of processing for Check_Precondition_Postcondition
2259 if not Is_List_Member (N) then
2263 -- Preanalyze message argument if present. Visibility in this
2264 -- argument is established at the point of pragma occurrence.
2266 if Arg_Count = 2 then
2267 Check_Optional_Identifier (Arg2, Name_Message);
2268 Preanalyze_Spec_Expression
2269 (Get_Pragma_Arg (Arg2), Standard_String);
2272 -- For a pragma PPC in the extended main source unit, record enabled
2275 -- This may seem redundant with the call to Check_Enabled occurring
2276 -- later on when the pragma is rewritten into a pragma Check but
2277 -- is actually required in the case of a postcondition within a
2280 if Check_Enabled (Pname) and then not Split_PPC (N) then
2281 Set_SCO_Pragma_Enabled (Loc);
2284 -- If we are within an inlined body, the legality of the pragma
2285 -- has been checked already.
2287 if In_Inlined_Body then
2292 -- Search prior declarations
2295 while Present (Prev (P)) loop
2298 -- If the previous node is a generic subprogram, do not go to to
2299 -- the original node, which is the unanalyzed tree: we need to
2300 -- attach the pre/postconditions to the analyzed version at this
2301 -- point. They get propagated to the original tree when analyzing
2302 -- the corresponding body.
2304 if Nkind (P) not in N_Generic_Declaration then
2305 PO := Original_Node (P);
2310 -- Skip past prior pragma
2312 if Nkind (PO) = N_Pragma then
2315 -- Skip stuff not coming from source
2317 elsif not Comes_From_Source (PO) then
2319 -- The condition may apply to a subprogram instantiation
2321 if Nkind (PO) = N_Subprogram_Declaration
2322 and then Present (Generic_Parent (Specification (PO)))
2327 elsif Nkind (PO) = N_Subprogram_Declaration
2328 and then In_Instance
2333 -- For all other cases of non source code, do nothing
2339 -- Only remaining possibility is subprogram declaration
2347 -- If we fall through loop, pragma is at start of list, so see if it
2348 -- is at the start of declarations of a subprogram body.
2350 if Nkind (Parent (N)) = N_Subprogram_Body
2351 and then List_Containing (N) = Declarations (Parent (N))
2353 if Operating_Mode /= Generate_Code
2354 or else Inside_A_Generic
2356 -- Analyze pragma expression for correctness and for ASIS use
2358 Preanalyze_Assert_Expression
2359 (Get_Pragma_Arg (Arg1), Standard_Boolean);
2361 -- In ASIS mode, for a pragma generated from a source aspect,
2362 -- also analyze the original aspect expression.
2365 and then Present (Corresponding_Aspect (N))
2367 Preanalyze_Assert_Expression
2368 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2375 -- See if it is in the pragmas after a library level subprogram
2377 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2379 -- In formal verification mode, analyze pragma expression for
2380 -- correctness, as it is not expanded later.
2383 Analyze_PPC_In_Decl_Part
2384 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2387 Chain_PPC (Unit (Parent (Parent (N))));
2391 -- If we fall through, pragma was misplaced
2394 end Check_Precondition_Postcondition;
2396 -----------------------------
2397 -- Check_Static_Constraint --
2398 -----------------------------
2400 -- Note: for convenience in writing this procedure, in addition to
2401 -- the officially (i.e. by spec) allowed argument which is always a
2402 -- constraint, it also allows ranges and discriminant associations.
2403 -- Above is not clear ???
2405 procedure Check_Static_Constraint (Constr : Node_Id) is
2407 procedure Require_Static (E : Node_Id);
2408 -- Require given expression to be static expression
2410 --------------------
2411 -- Require_Static --
2412 --------------------
2414 procedure Require_Static (E : Node_Id) is
2416 if not Is_OK_Static_Expression (E) then
2417 Flag_Non_Static_Expr
2418 ("non-static constraint not allowed in Unchecked_Union!", E);
2423 -- Start of processing for Check_Static_Constraint
2426 case Nkind (Constr) is
2427 when N_Discriminant_Association =>
2428 Require_Static (Expression (Constr));
2431 Require_Static (Low_Bound (Constr));
2432 Require_Static (High_Bound (Constr));
2434 when N_Attribute_Reference =>
2435 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2436 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2438 when N_Range_Constraint =>
2439 Check_Static_Constraint (Range_Expression (Constr));
2441 when N_Index_Or_Discriminant_Constraint =>
2445 IDC := First (Constraints (Constr));
2446 while Present (IDC) loop
2447 Check_Static_Constraint (IDC);
2455 end Check_Static_Constraint;
2457 --------------------------------------
2458 -- Check_Valid_Configuration_Pragma --
2459 --------------------------------------
2461 -- A configuration pragma must appear in the context clause of a
2462 -- compilation unit, and only other pragmas may precede it. Note that
2463 -- the test also allows use in a configuration pragma file.
2465 procedure Check_Valid_Configuration_Pragma is
2467 if not Is_Configuration_Pragma then
2468 Error_Pragma ("incorrect placement for configuration pragma%");
2470 end Check_Valid_Configuration_Pragma;
2472 -------------------------------------
2473 -- Check_Valid_Library_Unit_Pragma --
2474 -------------------------------------
2476 procedure Check_Valid_Library_Unit_Pragma is
2478 Parent_Node : Node_Id;
2479 Unit_Name : Entity_Id;
2480 Unit_Kind : Node_Kind;
2481 Unit_Node : Node_Id;
2482 Sindex : Source_File_Index;
2485 if not Is_List_Member (N) then
2489 Plist := List_Containing (N);
2490 Parent_Node := Parent (Plist);
2492 if Parent_Node = Empty then
2495 -- Case of pragma appearing after a compilation unit. In this case
2496 -- it must have an argument with the corresponding name and must
2497 -- be part of the following pragmas of its parent.
2499 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2500 if Plist /= Pragmas_After (Parent_Node) then
2503 elsif Arg_Count = 0 then
2505 ("argument required if outside compilation unit");
2508 Check_No_Identifiers;
2509 Check_Arg_Count (1);
2510 Unit_Node := Unit (Parent (Parent_Node));
2511 Unit_Kind := Nkind (Unit_Node);
2513 Analyze (Get_Pragma_Arg (Arg1));
2515 if Unit_Kind = N_Generic_Subprogram_Declaration
2516 or else Unit_Kind = N_Subprogram_Declaration
2518 Unit_Name := Defining_Entity (Unit_Node);
2520 elsif Unit_Kind in N_Generic_Instantiation then
2521 Unit_Name := Defining_Entity (Unit_Node);
2524 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2527 if Chars (Unit_Name) /=
2528 Chars (Entity (Get_Pragma_Arg (Arg1)))
2531 ("pragma% argument is not current unit name", Arg1);
2534 if Ekind (Unit_Name) = E_Package
2535 and then Present (Renamed_Entity (Unit_Name))
2537 Error_Pragma ("pragma% not allowed for renamed package");
2541 -- Pragma appears other than after a compilation unit
2544 -- Here we check for the generic instantiation case and also
2545 -- for the case of processing a generic formal package. We
2546 -- detect these cases by noting that the Sloc on the node
2547 -- does not belong to the current compilation unit.
2549 Sindex := Source_Index (Current_Sem_Unit);
2551 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2552 Rewrite (N, Make_Null_Statement (Loc));
2555 -- If before first declaration, the pragma applies to the
2556 -- enclosing unit, and the name if present must be this name.
2558 elsif Is_Before_First_Decl (N, Plist) then
2559 Unit_Node := Unit_Declaration_Node (Current_Scope);
2560 Unit_Kind := Nkind (Unit_Node);
2562 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2565 elsif Unit_Kind = N_Subprogram_Body
2566 and then not Acts_As_Spec (Unit_Node)
2570 elsif Nkind (Parent_Node) = N_Package_Body then
2573 elsif Nkind (Parent_Node) = N_Package_Specification
2574 and then Plist = Private_Declarations (Parent_Node)
2578 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2579 or else Nkind (Parent_Node) =
2580 N_Generic_Subprogram_Declaration)
2581 and then Plist = Generic_Formal_Declarations (Parent_Node)
2585 elsif Arg_Count > 0 then
2586 Analyze (Get_Pragma_Arg (Arg1));
2588 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2590 ("name in pragma% must be enclosing unit", Arg1);
2593 -- It is legal to have no argument in this context
2599 -- Error if not before first declaration. This is because a
2600 -- library unit pragma argument must be the name of a library
2601 -- unit (RM 10.1.5(7)), but the only names permitted in this
2602 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2603 -- generic subprogram declarations or generic instantiations.
2607 ("pragma% misplaced, must be before first declaration");
2611 end Check_Valid_Library_Unit_Pragma;
2617 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2618 Clist : constant Node_Id := Component_List (Variant);
2622 Comp := First (Component_Items (Clist));
2623 while Present (Comp) loop
2624 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2633 procedure Error_Pragma (Msg : String) is
2634 MsgF : String := Msg;
2636 Error_Msg_Name_1 := Pname;
2638 Error_Msg_N (MsgF, N);
2642 ----------------------
2643 -- Error_Pragma_Arg --
2644 ----------------------
2646 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2647 MsgF : String := Msg;
2649 Error_Msg_Name_1 := Pname;
2651 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2653 end Error_Pragma_Arg;
2655 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2656 MsgF : String := Msg1;
2658 Error_Msg_Name_1 := Pname;
2660 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2661 Error_Pragma_Arg (Msg2, Arg);
2662 end Error_Pragma_Arg;
2664 ----------------------------
2665 -- Error_Pragma_Arg_Ident --
2666 ----------------------------
2668 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2669 MsgF : String := Msg;
2671 Error_Msg_Name_1 := Pname;
2673 Error_Msg_N (MsgF, Arg);
2675 end Error_Pragma_Arg_Ident;
2677 ----------------------
2678 -- Error_Pragma_Ref --
2679 ----------------------
2681 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2682 MsgF : String := Msg;
2684 Error_Msg_Name_1 := Pname;
2686 Error_Msg_Sloc := Sloc (Ref);
2687 Error_Msg_NE (MsgF, N, Ref);
2689 end Error_Pragma_Ref;
2691 ------------------------
2692 -- Find_Lib_Unit_Name --
2693 ------------------------
2695 function Find_Lib_Unit_Name return Entity_Id is
2697 -- Return inner compilation unit entity, for case of nested
2698 -- categorization pragmas. This happens in generic unit.
2700 if Nkind (Parent (N)) = N_Package_Specification
2701 and then Defining_Entity (Parent (N)) /= Current_Scope
2703 return Defining_Entity (Parent (N));
2705 return Current_Scope;
2707 end Find_Lib_Unit_Name;
2709 ----------------------------
2710 -- Find_Program_Unit_Name --
2711 ----------------------------
2713 procedure Find_Program_Unit_Name (Id : Node_Id) is
2714 Unit_Name : Entity_Id;
2715 Unit_Kind : Node_Kind;
2716 P : constant Node_Id := Parent (N);
2719 if Nkind (P) = N_Compilation_Unit then
2720 Unit_Kind := Nkind (Unit (P));
2722 if Unit_Kind = N_Subprogram_Declaration
2723 or else Unit_Kind = N_Package_Declaration
2724 or else Unit_Kind in N_Generic_Declaration
2726 Unit_Name := Defining_Entity (Unit (P));
2728 if Chars (Id) = Chars (Unit_Name) then
2729 Set_Entity (Id, Unit_Name);
2730 Set_Etype (Id, Etype (Unit_Name));
2732 Set_Etype (Id, Any_Type);
2734 ("cannot find program unit referenced by pragma%");
2738 Set_Etype (Id, Any_Type);
2739 Error_Pragma ("pragma% inapplicable to this unit");
2745 end Find_Program_Unit_Name;
2747 -----------------------------------------
2748 -- Find_Unique_Parameterless_Procedure --
2749 -----------------------------------------
2751 function Find_Unique_Parameterless_Procedure
2753 Arg : Node_Id) return Entity_Id
2755 Proc : Entity_Id := Empty;
2758 -- The body of this procedure needs some comments ???
2760 if not Is_Entity_Name (Name) then
2762 ("argument of pragma% must be entity name", Arg);
2764 elsif not Is_Overloaded (Name) then
2765 Proc := Entity (Name);
2767 if Ekind (Proc) /= E_Procedure
2768 or else Present (First_Formal (Proc))
2771 ("argument of pragma% must be parameterless procedure", Arg);
2776 Found : Boolean := False;
2778 Index : Interp_Index;
2781 Get_First_Interp (Name, Index, It);
2782 while Present (It.Nam) loop
2785 if Ekind (Proc) = E_Procedure
2786 and then No (First_Formal (Proc))
2790 Set_Entity (Name, Proc);
2791 Set_Is_Overloaded (Name, False);
2794 ("ambiguous handler name for pragma% ", Arg);
2798 Get_Next_Interp (Index, It);
2803 ("argument of pragma% must be parameterless procedure",
2806 Proc := Entity (Name);
2812 end Find_Unique_Parameterless_Procedure;
2818 procedure Fix_Error (Msg : in out String) is
2820 if From_Aspect_Specification (N) then
2821 for J in Msg'First .. Msg'Last - 5 loop
2822 if Msg (J .. J + 5) = "pragma" then
2823 Msg (J .. J + 5) := "aspect";
2827 if Error_Msg_Name_1 = Name_Precondition then
2828 Error_Msg_Name_1 := Name_Pre;
2829 elsif Error_Msg_Name_1 = Name_Postcondition then
2830 Error_Msg_Name_1 := Name_Post;
2835 -------------------------
2836 -- Gather_Associations --
2837 -------------------------
2839 procedure Gather_Associations
2841 Args : out Args_List)
2846 -- Initialize all parameters to Empty
2848 for J in Args'Range loop
2852 -- That's all we have to do if there are no argument associations
2854 if No (Pragma_Argument_Associations (N)) then
2858 -- Otherwise first deal with any positional parameters present
2860 Arg := First (Pragma_Argument_Associations (N));
2861 for Index in Args'Range loop
2862 exit when No (Arg) or else Chars (Arg) /= No_Name;
2863 Args (Index) := Get_Pragma_Arg (Arg);
2867 -- Positional parameters all processed, if any left, then we
2868 -- have too many positional parameters.
2870 if Present (Arg) and then Chars (Arg) = No_Name then
2872 ("too many positional associations for pragma%", Arg);
2875 -- Process named parameters if any are present
2877 while Present (Arg) loop
2878 if Chars (Arg) = No_Name then
2880 ("positional association cannot follow named association",
2884 for Index in Names'Range loop
2885 if Names (Index) = Chars (Arg) then
2886 if Present (Args (Index)) then
2888 ("duplicate argument association for pragma%", Arg);
2890 Args (Index) := Get_Pragma_Arg (Arg);
2895 if Index = Names'Last then
2896 Error_Msg_Name_1 := Pname;
2897 Error_Msg_N ("pragma% does not allow & argument", Arg);
2899 -- Check for possible misspelling
2901 for Index1 in Names'Range loop
2902 if Is_Bad_Spelling_Of
2903 (Chars (Arg), Names (Index1))
2905 Error_Msg_Name_1 := Names (Index1);
2906 Error_Msg_N -- CODEFIX
2907 ("\possible misspelling of%", Arg);
2919 end Gather_Associations;
2925 procedure GNAT_Pragma is
2927 -- We need to check the No_Implementation_Pragmas restriction for
2928 -- the case of a pragma from source. Note that the case of aspects
2929 -- generating corresponding pragmas marks these pragmas as not being
2930 -- from source, so this test also catches that case.
2932 if Comes_From_Source (N) then
2933 Check_Restriction (No_Implementation_Pragmas, N);
2937 --------------------------
2938 -- Is_Before_First_Decl --
2939 --------------------------
2941 function Is_Before_First_Decl
2942 (Pragma_Node : Node_Id;
2943 Decls : List_Id) return Boolean
2945 Item : Node_Id := First (Decls);
2948 -- Only other pragmas can come before this pragma
2951 if No (Item) or else Nkind (Item) /= N_Pragma then
2954 elsif Item = Pragma_Node then
2960 end Is_Before_First_Decl;
2962 -----------------------------
2963 -- Is_Configuration_Pragma --
2964 -----------------------------
2966 -- A configuration pragma must appear in the context clause of a
2967 -- compilation unit, and only other pragmas may precede it. Note that
2968 -- the test below also permits use in a configuration pragma file.
2970 function Is_Configuration_Pragma return Boolean is
2971 Lis : constant List_Id := List_Containing (N);
2972 Par : constant Node_Id := Parent (N);
2976 -- If no parent, then we are in the configuration pragma file,
2977 -- so the placement is definitely appropriate.
2982 -- Otherwise we must be in the context clause of a compilation unit
2983 -- and the only thing allowed before us in the context list is more
2984 -- configuration pragmas.
2986 elsif Nkind (Par) = N_Compilation_Unit
2987 and then Context_Items (Par) = Lis
2994 elsif Nkind (Prg) /= N_Pragma then
3004 end Is_Configuration_Pragma;
3006 --------------------------
3007 -- Is_In_Context_Clause --
3008 --------------------------
3010 function Is_In_Context_Clause return Boolean is
3012 Parent_Node : Node_Id;
3015 if not Is_List_Member (N) then
3019 Plist := List_Containing (N);
3020 Parent_Node := Parent (Plist);
3022 if Parent_Node = Empty
3023 or else Nkind (Parent_Node) /= N_Compilation_Unit
3024 or else Context_Items (Parent_Node) /= Plist
3031 end Is_In_Context_Clause;
3033 ---------------------------------
3034 -- Is_Static_String_Expression --
3035 ---------------------------------
3037 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
3038 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3041 Analyze_And_Resolve (Argx);
3042 return Is_OK_Static_Expression (Argx)
3043 and then Nkind (Argx) = N_String_Literal;
3044 end Is_Static_String_Expression;
3046 ----------------------
3047 -- Pragma_Misplaced --
3048 ----------------------
3050 procedure Pragma_Misplaced is
3052 Error_Pragma ("incorrect placement of pragma%");
3053 end Pragma_Misplaced;
3055 ------------------------------------
3056 -- Process_Atomic_Shared_Volatile --
3057 ------------------------------------
3059 procedure Process_Atomic_Shared_Volatile is
3066 procedure Set_Atomic (E : Entity_Id);
3067 -- Set given type as atomic, and if no explicit alignment was given,
3068 -- set alignment to unknown, since back end knows what the alignment
3069 -- requirements are for atomic arrays. Note: this step is necessary
3070 -- for derived types.
3076 procedure Set_Atomic (E : Entity_Id) is
3080 if not Has_Alignment_Clause (E) then
3081 Set_Alignment (E, Uint_0);
3085 -- Start of processing for Process_Atomic_Shared_Volatile
3088 Check_Ada_83_Warning;
3089 Check_No_Identifiers;
3090 Check_Arg_Count (1);
3091 Check_Arg_Is_Local_Name (Arg1);
3092 E_Id := Get_Pragma_Arg (Arg1);
3094 if Etype (E_Id) = Any_Type then
3099 D := Declaration_Node (E);
3102 -- Check duplicate before we chain ourselves!
3104 Check_Duplicate_Pragma (E);
3106 -- Now check appropriateness of the entity
3109 if Rep_Item_Too_Early (E, N)
3111 Rep_Item_Too_Late (E, N)
3115 Check_First_Subtype (Arg1);
3118 if Prag_Id /= Pragma_Volatile then
3120 Set_Atomic (Underlying_Type (E));
3121 Set_Atomic (Base_Type (E));
3124 -- Attribute belongs on the base type. If the view of the type is
3125 -- currently private, it also belongs on the underlying type.
3127 Set_Is_Volatile (Base_Type (E));
3128 Set_Is_Volatile (Underlying_Type (E));
3130 Set_Treat_As_Volatile (E);
3131 Set_Treat_As_Volatile (Underlying_Type (E));
3133 elsif K = N_Object_Declaration
3134 or else (K = N_Component_Declaration
3135 and then Original_Record_Component (E) = E)
3137 if Rep_Item_Too_Late (E, N) then
3141 if Prag_Id /= Pragma_Volatile then
3144 -- If the object declaration has an explicit initialization, a
3145 -- temporary may have to be created to hold the expression, to
3146 -- ensure that access to the object remain atomic.
3148 if Nkind (Parent (E)) = N_Object_Declaration
3149 and then Present (Expression (Parent (E)))
3151 Set_Has_Delayed_Freeze (E);
3154 -- An interesting improvement here. If an object of composite
3155 -- type X is declared atomic, and the type X isn't, that's a
3156 -- pity, since it may not have appropriate alignment etc. We
3157 -- can rescue this in the special case where the object and
3158 -- type are in the same unit by just setting the type as
3159 -- atomic, so that the back end will process it as atomic.
3161 -- Note: we used to do this for elementary types as well,
3162 -- but that turns out to be a bad idea and can have unwanted
3163 -- effects, most notably if the type is elementary, the object
3164 -- a simple component within a record, and both are in a spec:
3165 -- every object of this type in the entire program will be
3166 -- treated as atomic, thus incurring a potentially costly
3167 -- synchronization operation for every access.
3169 -- Of course it would be best if the back end could just adjust
3170 -- the alignment etc for the specific object, but that's not
3171 -- something we are capable of doing at this point.
3173 Utyp := Underlying_Type (Etype (E));
3176 and then Is_Composite_Type (Utyp)
3177 and then Sloc (E) > No_Location
3178 and then Sloc (Utyp) > No_Location
3180 Get_Source_File_Index (Sloc (E)) =
3181 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
3183 Set_Is_Atomic (Underlying_Type (Etype (E)));
3187 Set_Is_Volatile (E);
3188 Set_Treat_As_Volatile (E);
3192 ("inappropriate entity for pragma%", Arg1);
3194 end Process_Atomic_Shared_Volatile;
3196 -------------------------------------------
3197 -- Process_Compile_Time_Warning_Or_Error --
3198 -------------------------------------------
3200 procedure Process_Compile_Time_Warning_Or_Error is
3201 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
3204 Check_Arg_Count (2);
3205 Check_No_Identifiers;
3206 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3207 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3209 if Compile_Time_Known_Value (Arg1x) then
3210 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3212 Str : constant String_Id :=
3213 Strval (Get_Pragma_Arg (Arg2));
3214 Len : constant Int := String_Length (Str);
3219 Cent : constant Entity_Id :=
3220 Cunit_Entity (Current_Sem_Unit);
3222 Force : constant Boolean :=
3223 Prag_Id = Pragma_Compile_Time_Warning
3225 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3226 and then (Ekind (Cent) /= E_Package
3227 or else not In_Private_Part (Cent));
3228 -- Set True if this is the warning case, and we are in the
3229 -- visible part of a package spec, or in a subprogram spec,
3230 -- in which case we want to force the client to see the
3231 -- warning, even though it is not in the main unit.
3234 -- Loop through segments of message separated by line feeds.
3235 -- We output these segments as separate messages with
3236 -- continuation marks for all but the first.
3241 Error_Msg_Strlen := 0;
3243 -- Loop to copy characters from argument to error message
3247 exit when Ptr > Len;
3248 CC := Get_String_Char (Str, Ptr);
3251 -- Ignore wide chars ??? else store character
3253 if In_Character_Range (CC) then
3254 C := Get_Character (CC);
3255 exit when C = ASCII.LF;
3256 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3257 Error_Msg_String (Error_Msg_Strlen) := C;
3261 -- Here with one line ready to go
3263 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3265 -- If this is a warning in a spec, then we want clients
3266 -- to see the warning, so mark the message with the
3267 -- special sequence !! to force the warning. In the case
3268 -- of a package spec, we do not force this if we are in
3269 -- the private part of the spec.
3272 if Cont = False then
3273 Error_Msg_N ("<~!!", Arg1);
3276 Error_Msg_N ("\<~!!", Arg1);
3279 -- Error, rather than warning, or in a body, so we do not
3280 -- need to force visibility for client (error will be
3281 -- output in any case, and this is the situation in which
3282 -- we do not want a client to get a warning, since the
3283 -- warning is in the body or the spec private part).
3286 if Cont = False then
3287 Error_Msg_N ("<~", Arg1);
3290 Error_Msg_N ("\<~", Arg1);
3294 exit when Ptr > Len;
3299 end Process_Compile_Time_Warning_Or_Error;
3301 ------------------------
3302 -- Process_Convention --
3303 ------------------------
3305 procedure Process_Convention
3306 (C : out Convention_Id;
3307 Ent : out Entity_Id)
3313 Comp_Unit : Unit_Number_Type;
3315 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3316 -- Called if we have more than one Export/Import/Convention pragma.
3317 -- This is generally illegal, but we have a special case of allowing
3318 -- Import and Interface to coexist if they specify the convention in
3319 -- a consistent manner. We are allowed to do this, since Interface is
3320 -- an implementation defined pragma, and we choose to do it since we
3321 -- know Rational allows this combination. S is the entity id of the
3322 -- subprogram in question. This procedure also sets the special flag
3323 -- Import_Interface_Present in both pragmas in the case where we do
3324 -- have matching Import and Interface pragmas.
3326 procedure Set_Convention_From_Pragma (E : Entity_Id);
3327 -- Set convention in entity E, and also flag that the entity has a
3328 -- convention pragma. If entity is for a private or incomplete type,
3329 -- also set convention and flag on underlying type. This procedure
3330 -- also deals with the special case of C_Pass_By_Copy convention.
3332 -------------------------------
3333 -- Diagnose_Multiple_Pragmas --
3334 -------------------------------
3336 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3337 Pdec : constant Node_Id := Declaration_Node (S);
3341 function Same_Convention (Decl : Node_Id) return Boolean;
3342 -- Decl is a pragma node. This function returns True if this
3343 -- pragma has a first argument that is an identifier with a
3344 -- Chars field corresponding to the Convention_Id C.
3346 function Same_Name (Decl : Node_Id) return Boolean;
3347 -- Decl is a pragma node. This function returns True if this
3348 -- pragma has a second argument that is an identifier with a
3349 -- Chars field that matches the Chars of the current subprogram.
3351 ---------------------
3352 -- Same_Convention --
3353 ---------------------
3355 function Same_Convention (Decl : Node_Id) return Boolean is
3356 Arg1 : constant Node_Id :=
3357 First (Pragma_Argument_Associations (Decl));
3360 if Present (Arg1) then
3362 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3364 if Nkind (Arg) = N_Identifier
3365 and then Is_Convention_Name (Chars (Arg))
3366 and then Get_Convention_Id (Chars (Arg)) = C
3374 end Same_Convention;
3380 function Same_Name (Decl : Node_Id) return Boolean is
3381 Arg1 : constant Node_Id :=
3382 First (Pragma_Argument_Associations (Decl));
3390 Arg2 := Next (Arg1);
3397 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3399 if Nkind (Arg) = N_Identifier
3400 and then Chars (Arg) = Chars (S)
3409 -- Start of processing for Diagnose_Multiple_Pragmas
3414 -- Definitely give message if we have Convention/Export here
3416 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3419 -- If we have an Import or Export, scan back from pragma to
3420 -- find any previous pragma applying to the same procedure.
3421 -- The scan will be terminated by the start of the list, or
3422 -- hitting the subprogram declaration. This won't allow one
3423 -- pragma to appear in the public part and one in the private
3424 -- part, but that seems very unlikely in practice.
3428 while Present (Decl) and then Decl /= Pdec loop
3430 -- Look for pragma with same name as us
3432 if Nkind (Decl) = N_Pragma
3433 and then Same_Name (Decl)
3435 -- Give error if same as our pragma or Export/Convention
3437 if Pragma_Name (Decl) = Name_Export
3439 Pragma_Name (Decl) = Name_Convention
3441 Pragma_Name (Decl) = Pragma_Name (N)
3445 -- Case of Import/Interface or the other way round
3447 elsif Pragma_Name (Decl) = Name_Interface
3449 Pragma_Name (Decl) = Name_Import
3451 -- Here we know that we have Import and Interface. It
3452 -- doesn't matter which way round they are. See if
3453 -- they specify the same convention. If so, all OK,
3454 -- and set special flags to stop other messages
3456 if Same_Convention (Decl) then
3457 Set_Import_Interface_Present (N);
3458 Set_Import_Interface_Present (Decl);
3461 -- If different conventions, special message
3464 Error_Msg_Sloc := Sloc (Decl);
3466 ("convention differs from that given#", Arg1);
3476 -- Give message if needed if we fall through those tests
3477 -- except on Relaxed_RM_Semantics where we let go: either this
3478 -- is a case accepted/ignored by other Ada compilers (e.g.
3479 -- a mix of Convention and Import), or another error will be
3480 -- generated later (e.g. using both Import and Export).
3482 if Err and not Relaxed_RM_Semantics then
3484 ("at most one Convention/Export/Import pragma is allowed",
3487 end Diagnose_Multiple_Pragmas;
3489 --------------------------------
3490 -- Set_Convention_From_Pragma --
3491 --------------------------------
3493 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3495 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3496 -- for an overridden dispatching operation. Technically this is
3497 -- an amendment and should only be done in Ada 2005 mode. However,
3498 -- this is clearly a mistake, since the problem that is addressed
3499 -- by this AI is that there is a clear gap in the RM!
3501 if Is_Dispatching_Operation (E)
3502 and then Present (Overridden_Operation (E))
3503 and then C /= Convention (Overridden_Operation (E))
3506 ("cannot change convention for overridden dispatching "
3507 & "operation", Arg1);
3510 -- Set the convention
3512 Set_Convention (E, C);
3513 Set_Has_Convention_Pragma (E);
3515 if Is_Incomplete_Or_Private_Type (E)
3516 and then Present (Underlying_Type (E))
3518 Set_Convention (Underlying_Type (E), C);
3519 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3522 -- A class-wide type should inherit the convention of the specific
3523 -- root type (although this isn't specified clearly by the RM).
3525 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3526 Set_Convention (Class_Wide_Type (E), C);
3529 -- If the entity is a record type, then check for special case of
3530 -- C_Pass_By_Copy, which is treated the same as C except that the
3531 -- special record flag is set. This convention is only permitted
3532 -- on record types (see AI95-00131).
3534 if Cname = Name_C_Pass_By_Copy then
3535 if Is_Record_Type (E) then
3536 Set_C_Pass_By_Copy (Base_Type (E));
3537 elsif Is_Incomplete_Or_Private_Type (E)
3538 and then Is_Record_Type (Underlying_Type (E))
3540 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3543 ("C_Pass_By_Copy convention allowed only for record type",
3548 -- If the entity is a derived boolean type, check for the special
3549 -- case of convention C, C++, or Fortran, where we consider any
3550 -- nonzero value to represent true.
3552 if Is_Discrete_Type (E)
3553 and then Root_Type (Etype (E)) = Standard_Boolean
3559 C = Convention_Fortran)
3561 Set_Nonzero_Is_True (Base_Type (E));
3563 end Set_Convention_From_Pragma;
3565 -- Start of processing for Process_Convention
3568 Check_At_Least_N_Arguments (2);
3569 Check_Optional_Identifier (Arg1, Name_Convention);
3570 Check_Arg_Is_Identifier (Arg1);
3571 Cname := Chars (Get_Pragma_Arg (Arg1));
3573 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3574 -- tested again below to set the critical flag).
3576 if Cname = Name_C_Pass_By_Copy then
3579 -- Otherwise we must have something in the standard convention list
3581 elsif Is_Convention_Name (Cname) then
3582 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3584 -- In DEC VMS, it seems that there is an undocumented feature that
3585 -- any unrecognized convention is treated as the default, which for
3586 -- us is convention C. It does not seem so terrible to do this
3587 -- unconditionally, silently in the VMS case, and with a warning
3588 -- in the non-VMS case.
3591 if Warn_On_Export_Import and not OpenVMS_On_Target then
3593 ("??unrecognized convention name, C assumed",
3594 Get_Pragma_Arg (Arg1));
3600 Check_Optional_Identifier (Arg2, Name_Entity);
3601 Check_Arg_Is_Local_Name (Arg2);
3603 Id := Get_Pragma_Arg (Arg2);
3606 if not Is_Entity_Name (Id) then
3607 Error_Pragma_Arg ("entity name required", Arg2);
3612 -- Set entity to return
3616 -- Ada_Pass_By_Copy special checking
3618 if C = Convention_Ada_Pass_By_Copy then
3619 if not Is_First_Subtype (E) then
3621 ("convention `Ada_Pass_By_Copy` only "
3622 & "allowed for types", Arg2);
3625 if Is_By_Reference_Type (E) then
3627 ("convention `Ada_Pass_By_Copy` not allowed for "
3628 & "by-reference type", Arg1);
3632 -- Ada_Pass_By_Reference special checking
3634 if C = Convention_Ada_Pass_By_Reference then
3635 if not Is_First_Subtype (E) then
3637 ("convention `Ada_Pass_By_Reference` only "
3638 & "allowed for types", Arg2);
3641 if Is_By_Copy_Type (E) then
3643 ("convention `Ada_Pass_By_Reference` not allowed for "
3644 & "by-copy type", Arg1);
3648 -- Go to renamed subprogram if present, since convention applies to
3649 -- the actual renamed entity, not to the renaming entity. If the
3650 -- subprogram is inherited, go to parent subprogram.
3652 if Is_Subprogram (E)
3653 and then Present (Alias (E))
3655 if Nkind (Parent (Declaration_Node (E))) =
3656 N_Subprogram_Renaming_Declaration
3658 if Scope (E) /= Scope (Alias (E)) then
3660 ("cannot apply pragma% to non-local entity&#", E);
3665 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3666 N_Private_Extension_Declaration)
3667 and then Scope (E) = Scope (Alias (E))
3671 -- Return the parent subprogram the entity was inherited from
3677 -- Check that we are not applying this to a specless body
3678 -- Relax this check if Relaxed_RM_Semantics to accomodate other Ada
3681 if Is_Subprogram (E)
3682 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3683 and then not Relaxed_RM_Semantics
3686 ("pragma% requires separate spec and must come before body");
3689 -- Check that we are not applying this to a named constant
3691 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3692 Error_Msg_Name_1 := Pname;
3694 ("cannot apply pragma% to named constant!",
3695 Get_Pragma_Arg (Arg2));
3697 ("\supply appropriate type for&!", Arg2);
3700 if Ekind (E) = E_Enumeration_Literal then
3701 Error_Pragma ("enumeration literal not allowed for pragma%");
3704 -- Check for rep item appearing too early or too late
3706 if Etype (E) = Any_Type
3707 or else Rep_Item_Too_Early (E, N)
3711 elsif Present (Underlying_Type (E)) then
3712 E := Underlying_Type (E);
3715 if Rep_Item_Too_Late (E, N) then
3719 if Has_Convention_Pragma (E) then
3720 Diagnose_Multiple_Pragmas (E);
3722 elsif Convention (E) = Convention_Protected
3723 or else Ekind (Scope (E)) = E_Protected_Type
3726 ("a protected operation cannot be given a different convention",
3730 -- For Intrinsic, a subprogram is required
3732 if C = Convention_Intrinsic
3733 and then not Is_Subprogram (E)
3734 and then not Is_Generic_Subprogram (E)
3737 ("second argument of pragma% must be a subprogram", Arg2);
3742 if C = Convention_Stdcall then
3744 -- A dispatching call is not allowed. A dispatching subprogram
3745 -- cannot be used to interface to the Win32 API, so in fact this
3746 -- check does not impose any effective restriction.
3748 if Is_Dispatching_Operation (E) then
3751 ("dispatching subprograms cannot use Stdcall convention");
3753 -- Subprogram is allowed, but not a generic subprogram, and not a
3754 -- dispatching operation.
3756 elsif not Is_Subprogram (E)
3757 and then not Is_Generic_Subprogram (E)
3761 and then Ekind (E) /= E_Variable
3763 -- An access to subprogram is also allowed
3767 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3770 ("second argument of pragma% must be subprogram (type)",
3775 if not Is_Subprogram (E)
3776 and then not Is_Generic_Subprogram (E)
3778 Set_Convention_From_Pragma (E);
3781 Check_First_Subtype (Arg2);
3782 Set_Convention_From_Pragma (Base_Type (E));
3784 -- For subprograms, we must set the convention on the
3785 -- internally generated directly designated type as well.
3787 if Ekind (E) = E_Access_Subprogram_Type then
3788 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3792 -- For the subprogram case, set proper convention for all homonyms
3793 -- in same scope and the same declarative part, i.e. the same
3794 -- compilation unit.
3797 Comp_Unit := Get_Source_Unit (E);
3798 Set_Convention_From_Pragma (E);
3800 -- Treat a pragma Import as an implicit body, and pragma import
3801 -- as implicit reference (for navigation in GPS).
3803 if Prag_Id = Pragma_Import then
3804 Generate_Reference (E, Id, 'b');
3806 -- For exported entities we restrict the generation of references
3807 -- to entities exported to foreign languages since entities
3808 -- exported to Ada do not provide further information to GPS and
3809 -- add undesired references to the output of the gnatxref tool.
3811 elsif Prag_Id = Pragma_Export
3812 and then Convention (E) /= Convention_Ada
3814 Generate_Reference (E, Id, 'i');
3817 -- If the pragma comes from from an aspect, it only applies
3818 -- to the given entity, not its homonyms.
3820 if From_Aspect_Specification (N) then
3824 -- Otherwise Loop through the homonyms of the pragma argument's
3825 -- entity, an apply convention to those in the current scope.
3831 exit when No (E1) or else Scope (E1) /= Current_Scope;
3833 -- Do not set the pragma on inherited operations or on formal
3836 if Comes_From_Source (E1)
3837 and then Comp_Unit = Get_Source_Unit (E1)
3838 and then not Is_Formal_Subprogram (E1)
3839 and then Nkind (Original_Node (Parent (E1))) /=
3840 N_Full_Type_Declaration
3842 if Present (Alias (E1))
3843 and then Scope (E1) /= Scope (Alias (E1))
3846 ("cannot apply pragma% to non-local entity& declared#",
3850 Set_Convention_From_Pragma (E1);
3852 if Prag_Id = Pragma_Import then
3853 Generate_Reference (E1, Id, 'b');
3858 end Process_Convention;
3860 ----------------------------------------
3861 -- Process_Disable_Enable_Atomic_Sync --
3862 ----------------------------------------
3864 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3867 Check_No_Identifiers;
3868 Check_At_Most_N_Arguments (1);
3870 -- Modeled internally as
3871 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
3875 Pragma_Identifier =>
3876 Make_Identifier (Loc, Nam),
3877 Pragma_Argument_Associations => New_List (
3878 Make_Pragma_Argument_Association (Loc,
3880 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3882 if Present (Arg1) then
3883 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3887 end Process_Disable_Enable_Atomic_Sync;
3889 -----------------------------------------------------
3890 -- Process_Extended_Import_Export_Exception_Pragma --
3891 -----------------------------------------------------
3893 procedure Process_Extended_Import_Export_Exception_Pragma
3894 (Arg_Internal : Node_Id;
3895 Arg_External : Node_Id;
3903 if not OpenVMS_On_Target then
3905 ("??pragma% ignored (applies only to Open'V'M'S)");
3908 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3909 Def_Id := Entity (Arg_Internal);
3911 if Ekind (Def_Id) /= E_Exception then
3913 ("pragma% must refer to declared exception", Arg_Internal);
3916 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3918 if Present (Arg_Form) then
3919 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3922 if Present (Arg_Form)
3923 and then Chars (Arg_Form) = Name_Ada
3927 Set_Is_VMS_Exception (Def_Id);
3928 Set_Exception_Code (Def_Id, No_Uint);
3931 if Present (Arg_Code) then
3932 if not Is_VMS_Exception (Def_Id) then
3934 ("Code option for pragma% not allowed for Ada case",
3938 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3939 Code_Val := Expr_Value (Arg_Code);
3941 if not UI_Is_In_Int_Range (Code_Val) then
3943 ("Code option for pragma% must be in 32-bit range",
3947 Set_Exception_Code (Def_Id, Code_Val);
3950 end Process_Extended_Import_Export_Exception_Pragma;
3952 -------------------------------------------------
3953 -- Process_Extended_Import_Export_Internal_Arg --
3954 -------------------------------------------------
3956 procedure Process_Extended_Import_Export_Internal_Arg
3957 (Arg_Internal : Node_Id := Empty)
3960 if No (Arg_Internal) then
3961 Error_Pragma ("Internal parameter required for pragma%");
3964 if Nkind (Arg_Internal) = N_Identifier then
3967 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3968 and then (Prag_Id = Pragma_Import_Function
3970 Prag_Id = Pragma_Export_Function)
3976 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3979 Check_Arg_Is_Local_Name (Arg_Internal);
3980 end Process_Extended_Import_Export_Internal_Arg;
3982 --------------------------------------------------
3983 -- Process_Extended_Import_Export_Object_Pragma --
3984 --------------------------------------------------
3986 procedure Process_Extended_Import_Export_Object_Pragma
3987 (Arg_Internal : Node_Id;
3988 Arg_External : Node_Id;
3994 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3995 Def_Id := Entity (Arg_Internal);
3997 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3999 ("pragma% must designate an object", Arg_Internal);
4002 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
4004 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
4007 ("previous Common/Psect_Object applies, pragma % not permitted",
4011 if Rep_Item_Too_Late (Def_Id, N) then
4015 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
4017 if Present (Arg_Size) then
4018 Check_Arg_Is_External_Name (Arg_Size);
4021 -- Export_Object case
4023 if Prag_Id = Pragma_Export_Object then
4024 if not Is_Library_Level_Entity (Def_Id) then
4026 ("argument for pragma% must be library level entity",
4030 if Ekind (Current_Scope) = E_Generic_Package then
4031 Error_Pragma ("pragma& cannot appear in a generic unit");
4034 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
4036 ("exported object must have compile time known size",
4040 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
4041 Error_Msg_N ("??duplicate Export_Object pragma", N);
4043 Set_Exported (Def_Id, Arg_Internal);
4046 -- Import_Object case
4049 if Is_Concurrent_Type (Etype (Def_Id)) then
4051 ("cannot use pragma% for task/protected object",
4055 if Ekind (Def_Id) = E_Constant then
4057 ("cannot import a constant", Arg_Internal);
4060 if Warn_On_Export_Import
4061 and then Has_Discriminants (Etype (Def_Id))
4064 ("imported value must be initialized??", Arg_Internal);
4067 if Warn_On_Export_Import
4068 and then Is_Access_Type (Etype (Def_Id))
4071 ("cannot import object of an access type??", Arg_Internal);
4074 if Warn_On_Export_Import
4075 and then Is_Imported (Def_Id)
4077 Error_Msg_N ("??duplicate Import_Object pragma", N);
4079 -- Check for explicit initialization present. Note that an
4080 -- initialization generated by the code generator, e.g. for an
4081 -- access type, does not count here.
4083 elsif Present (Expression (Parent (Def_Id)))
4086 (Original_Node (Expression (Parent (Def_Id))))
4088 Error_Msg_Sloc := Sloc (Def_Id);
4090 ("imported entities cannot be initialized (RM B.1(24))",
4091 "\no initialization allowed for & declared#", Arg1);
4093 Set_Imported (Def_Id);
4094 Note_Possible_Modification (Arg_Internal, Sure => False);
4097 end Process_Extended_Import_Export_Object_Pragma;
4099 ------------------------------------------------------
4100 -- Process_Extended_Import_Export_Subprogram_Pragma --
4101 ------------------------------------------------------
4103 procedure Process_Extended_Import_Export_Subprogram_Pragma
4104 (Arg_Internal : Node_Id;
4105 Arg_External : Node_Id;
4106 Arg_Parameter_Types : Node_Id;
4107 Arg_Result_Type : Node_Id := Empty;
4108 Arg_Mechanism : Node_Id;
4109 Arg_Result_Mechanism : Node_Id := Empty;
4110 Arg_First_Optional_Parameter : Node_Id := Empty)
4116 Ambiguous : Boolean;
4120 function Same_Base_Type
4122 Formal : Entity_Id) return Boolean;
4123 -- Determines if Ptype references the type of Formal. Note that only
4124 -- the base types need to match according to the spec. Ptype here is
4125 -- the argument from the pragma, which is either a type name, or an
4126 -- access attribute.
4128 --------------------
4129 -- Same_Base_Type --
4130 --------------------
4132 function Same_Base_Type
4134 Formal : Entity_Id) return Boolean
4136 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
4140 -- Case where pragma argument is typ'Access
4142 if Nkind (Ptype) = N_Attribute_Reference
4143 and then Attribute_Name (Ptype) = Name_Access
4145 Pref := Prefix (Ptype);
4148 if not Is_Entity_Name (Pref)
4149 or else Entity (Pref) = Any_Type
4154 -- We have a match if the corresponding argument is of an
4155 -- anonymous access type, and its designated type matches the
4156 -- type of the prefix of the access attribute
4158 return Ekind (Ftyp) = E_Anonymous_Access_Type
4159 and then Base_Type (Entity (Pref)) =
4160 Base_Type (Etype (Designated_Type (Ftyp)));
4162 -- Case where pragma argument is a type name
4167 if not Is_Entity_Name (Ptype)
4168 or else Entity (Ptype) = Any_Type
4173 -- We have a match if the corresponding argument is of the type
4174 -- given in the pragma (comparing base types)
4176 return Base_Type (Entity (Ptype)) = Ftyp;
4180 -- Start of processing for
4181 -- Process_Extended_Import_Export_Subprogram_Pragma
4184 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
4188 -- Loop through homonyms (overloadings) of the entity
4190 Hom_Id := Entity (Arg_Internal);
4191 while Present (Hom_Id) loop
4192 Def_Id := Get_Base_Subprogram (Hom_Id);
4194 -- We need a subprogram in the current scope
4196 if not Is_Subprogram (Def_Id)
4197 or else Scope (Def_Id) /= Current_Scope
4204 -- Pragma cannot apply to subprogram body
4206 if Is_Subprogram (Def_Id)
4207 and then Nkind (Parent (Declaration_Node (Def_Id))) =
4211 ("pragma% requires separate spec"
4212 & " and must come before body");
4215 -- Test result type if given, note that the result type
4216 -- parameter can only be present for the function cases.
4218 if Present (Arg_Result_Type)
4219 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
4223 elsif Etype (Def_Id) /= Standard_Void_Type
4225 (Pname = Name_Export_Procedure
4227 Pname = Name_Import_Procedure)
4231 -- Test parameter types if given. Note that this parameter
4232 -- has not been analyzed (and must not be, since it is
4233 -- semantic nonsense), so we get it as the parser left it.
4235 elsif Present (Arg_Parameter_Types) then
4236 Check_Matching_Types : declare
4241 Formal := First_Formal (Def_Id);
4243 if Nkind (Arg_Parameter_Types) = N_Null then
4244 if Present (Formal) then
4248 -- A list of one type, e.g. (List) is parsed as
4249 -- a parenthesized expression.
4251 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4252 and then Paren_Count (Arg_Parameter_Types) = 1
4255 or else Present (Next_Formal (Formal))
4260 Same_Base_Type (Arg_Parameter_Types, Formal);
4263 -- A list of more than one type is parsed as a aggregate
4265 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4266 and then Paren_Count (Arg_Parameter_Types) = 0
4268 Ptype := First (Expressions (Arg_Parameter_Types));
4269 while Present (Ptype) or else Present (Formal) loop
4272 or else not Same_Base_Type (Ptype, Formal)
4277 Next_Formal (Formal);
4282 -- Anything else is of the wrong form
4286 ("wrong form for Parameter_Types parameter",
4287 Arg_Parameter_Types);
4289 end Check_Matching_Types;
4292 -- Match is now False if the entry we found did not match
4293 -- either a supplied Parameter_Types or Result_Types argument
4299 -- Ambiguous case, the flag Ambiguous shows if we already
4300 -- detected this and output the initial messages.
4303 if not Ambiguous then
4305 Error_Msg_Name_1 := Pname;
4307 ("pragma% does not uniquely identify subprogram!",
4309 Error_Msg_Sloc := Sloc (Ent);
4310 Error_Msg_N ("matching subprogram #!", N);
4314 Error_Msg_Sloc := Sloc (Def_Id);
4315 Error_Msg_N ("matching subprogram #!", N);
4320 Hom_Id := Homonym (Hom_Id);
4323 -- See if we found an entry
4326 if not Ambiguous then
4327 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4329 ("pragma% cannot be given for generic subprogram");
4332 ("pragma% does not identify local subprogram");
4339 -- Import pragmas must be for imported entities
4341 if Prag_Id = Pragma_Import_Function
4343 Prag_Id = Pragma_Import_Procedure
4345 Prag_Id = Pragma_Import_Valued_Procedure
4347 if not Is_Imported (Ent) then
4349 ("pragma Import or Interface must precede pragma%");
4352 -- Here we have the Export case which can set the entity as exported
4354 -- But does not do so if the specified external name is null, since
4355 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4356 -- compatible) to request no external name.
4358 elsif Nkind (Arg_External) = N_String_Literal
4359 and then String_Length (Strval (Arg_External)) = 0
4363 -- In all other cases, set entity as exported
4366 Set_Exported (Ent, Arg_Internal);
4369 -- Special processing for Valued_Procedure cases
4371 if Prag_Id = Pragma_Import_Valued_Procedure
4373 Prag_Id = Pragma_Export_Valued_Procedure
4375 Formal := First_Formal (Ent);
4378 Error_Pragma ("at least one parameter required for pragma%");
4380 elsif Ekind (Formal) /= E_Out_Parameter then
4381 Error_Pragma ("first parameter must have mode out for pragma%");
4384 Set_Is_Valued_Procedure (Ent);
4388 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4390 -- Process Result_Mechanism argument if present. We have already
4391 -- checked that this is only allowed for the function case.
4393 if Present (Arg_Result_Mechanism) then
4394 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4397 -- Process Mechanism parameter if present. Note that this parameter
4398 -- is not analyzed, and must not be analyzed since it is semantic
4399 -- nonsense, so we get it in exactly as the parser left it.
4401 if Present (Arg_Mechanism) then
4409 -- A single mechanism association without a formal parameter
4410 -- name is parsed as a parenthesized expression. All other
4411 -- cases are parsed as aggregates, so we rewrite the single
4412 -- parameter case as an aggregate for consistency.
4414 if Nkind (Arg_Mechanism) /= N_Aggregate
4415 and then Paren_Count (Arg_Mechanism) = 1
4417 Rewrite (Arg_Mechanism,
4418 Make_Aggregate (Sloc (Arg_Mechanism),
4419 Expressions => New_List (
4420 Relocate_Node (Arg_Mechanism))));
4423 -- Case of only mechanism name given, applies to all formals
4425 if Nkind (Arg_Mechanism) /= N_Aggregate then
4426 Formal := First_Formal (Ent);
4427 while Present (Formal) loop
4428 Set_Mechanism_Value (Formal, Arg_Mechanism);
4429 Next_Formal (Formal);
4432 -- Case of list of mechanism associations given
4435 if Null_Record_Present (Arg_Mechanism) then
4437 ("inappropriate form for Mechanism parameter",
4441 -- Deal with positional ones first
4443 Formal := First_Formal (Ent);
4445 if Present (Expressions (Arg_Mechanism)) then
4446 Mname := First (Expressions (Arg_Mechanism));
4447 while Present (Mname) loop
4450 ("too many mechanism associations", Mname);
4453 Set_Mechanism_Value (Formal, Mname);
4454 Next_Formal (Formal);
4459 -- Deal with named entries
4461 if Present (Component_Associations (Arg_Mechanism)) then
4462 Massoc := First (Component_Associations (Arg_Mechanism));
4463 while Present (Massoc) loop
4464 Choice := First (Choices (Massoc));
4466 if Nkind (Choice) /= N_Identifier
4467 or else Present (Next (Choice))
4470 ("incorrect form for mechanism association",
4474 Formal := First_Formal (Ent);
4478 ("parameter name & not present", Choice);
4481 if Chars (Choice) = Chars (Formal) then
4483 (Formal, Expression (Massoc));
4485 -- Set entity on identifier (needed by ASIS)
4487 Set_Entity (Choice, Formal);
4492 Next_Formal (Formal);
4502 -- Process First_Optional_Parameter argument if present. We have
4503 -- already checked that this is only allowed for the Import case.
4505 if Present (Arg_First_Optional_Parameter) then
4506 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4508 ("first optional parameter must be formal parameter name",
4509 Arg_First_Optional_Parameter);
4512 Formal := First_Formal (Ent);
4516 ("specified formal parameter& not found",
4517 Arg_First_Optional_Parameter);
4520 exit when Chars (Formal) =
4521 Chars (Arg_First_Optional_Parameter);
4523 Next_Formal (Formal);
4526 Set_First_Optional_Parameter (Ent, Formal);
4528 -- Check specified and all remaining formals have right form
4530 while Present (Formal) loop
4531 if Ekind (Formal) /= E_In_Parameter then
4533 ("optional formal& is not of mode in!",
4534 Arg_First_Optional_Parameter, Formal);
4537 Dval := Default_Value (Formal);
4541 ("optional formal& does not have default value!",
4542 Arg_First_Optional_Parameter, Formal);
4544 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4549 ("default value for optional formal& is non-static!",
4550 Arg_First_Optional_Parameter, Formal);
4554 Set_Is_Optional_Parameter (Formal);
4555 Next_Formal (Formal);
4558 end Process_Extended_Import_Export_Subprogram_Pragma;
4560 --------------------------
4561 -- Process_Generic_List --
4562 --------------------------
4564 procedure Process_Generic_List is
4569 Check_No_Identifiers;
4570 Check_At_Least_N_Arguments (1);
4573 while Present (Arg) loop
4574 Exp := Get_Pragma_Arg (Arg);
4577 if not Is_Entity_Name (Exp)
4579 (not Is_Generic_Instance (Entity (Exp))
4581 not Is_Generic_Unit (Entity (Exp)))
4584 ("pragma% argument must be name of generic unit/instance",
4590 end Process_Generic_List;
4592 ------------------------------------
4593 -- Process_Import_Predefined_Type --
4594 ------------------------------------
4596 procedure Process_Import_Predefined_Type is
4597 Loc : constant Source_Ptr := Sloc (N);
4599 Ftyp : Node_Id := Empty;
4605 String_To_Name_Buffer (Strval (Expression (Arg3)));
4608 Elmt := First_Elmt (Predefined_Float_Types);
4609 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4613 Ftyp := Node (Elmt);
4615 if Present (Ftyp) then
4617 -- Don't build a derived type declaration, because predefined C
4618 -- types have no declaration anywhere, so cannot really be named.
4619 -- Instead build a full type declaration, starting with an
4620 -- appropriate type definition is built
4622 if Is_Floating_Point_Type (Ftyp) then
4623 Def := Make_Floating_Point_Definition (Loc,
4624 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4625 Make_Real_Range_Specification (Loc,
4626 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4627 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4629 -- Should never have a predefined type we cannot handle
4632 raise Program_Error;
4635 -- Build and insert a Full_Type_Declaration, which will be
4636 -- analyzed as soon as this list entry has been analyzed.
4638 Decl := Make_Full_Type_Declaration (Loc,
4639 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4640 Type_Definition => Def);
4642 Insert_After (N, Decl);
4643 Mark_Rewrite_Insertion (Decl);
4646 Error_Pragma_Arg ("no matching type found for pragma%",
4649 end Process_Import_Predefined_Type;
4651 ---------------------------------
4652 -- Process_Import_Or_Interface --
4653 ---------------------------------
4655 procedure Process_Import_Or_Interface is
4661 Process_Convention (C, Def_Id);
4662 Kill_Size_Check_Code (Def_Id);
4663 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4665 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4667 -- We do not permit Import to apply to a renaming declaration
4669 if Present (Renamed_Object (Def_Id)) then
4671 ("pragma% not allowed for object renaming", Arg2);
4673 -- User initialization is not allowed for imported object, but
4674 -- the object declaration may contain a default initialization,
4675 -- that will be discarded. Note that an explicit initialization
4676 -- only counts if it comes from source, otherwise it is simply
4677 -- the code generator making an implicit initialization explicit.
4679 elsif Present (Expression (Parent (Def_Id)))
4680 and then Comes_From_Source (Expression (Parent (Def_Id)))
4682 Error_Msg_Sloc := Sloc (Def_Id);
4684 ("no initialization allowed for declaration of& #",
4685 "\imported entities cannot be initialized (RM B.1(24))",
4689 Set_Imported (Def_Id);
4690 Process_Interface_Name (Def_Id, Arg3, Arg4);
4692 -- Note that we do not set Is_Public here. That's because we
4693 -- only want to set it if there is no address clause, and we
4694 -- don't know that yet, so we delay that processing till
4697 -- pragma Import completes deferred constants
4699 if Ekind (Def_Id) = E_Constant then
4700 Set_Has_Completion (Def_Id);
4703 -- It is not possible to import a constant of an unconstrained
4704 -- array type (e.g. string) because there is no simple way to
4705 -- write a meaningful subtype for it.
4707 if Is_Array_Type (Etype (Def_Id))
4708 and then not Is_Constrained (Etype (Def_Id))
4711 ("imported constant& must have a constrained subtype",
4716 elsif Is_Subprogram (Def_Id)
4717 or else Is_Generic_Subprogram (Def_Id)
4719 -- If the name is overloaded, pragma applies to all of the denoted
4720 -- entities in the same declarative part, unless the pragma comes
4721 -- from an aspect specification.
4724 while Present (Hom_Id) loop
4726 Def_Id := Get_Base_Subprogram (Hom_Id);
4728 -- Ignore inherited subprograms because the pragma will apply
4729 -- to the parent operation, which is the one called.
4731 if Is_Overloadable (Def_Id)
4732 and then Present (Alias (Def_Id))
4736 -- If it is not a subprogram, it must be in an outer scope and
4737 -- pragma does not apply.
4739 elsif not Is_Subprogram (Def_Id)
4740 and then not Is_Generic_Subprogram (Def_Id)
4744 -- The pragma does not apply to primitives of interfaces
4746 elsif Is_Dispatching_Operation (Def_Id)
4747 and then Present (Find_Dispatching_Type (Def_Id))
4748 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4752 -- Verify that the homonym is in the same declarative part (not
4753 -- just the same scope). If the pragma comes from an aspect
4754 -- specification we know that it is part of the declaration.
4756 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4757 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4758 and then not From_Aspect_Specification (N)
4763 Set_Imported (Def_Id);
4765 -- Reject an Import applied to an abstract subprogram
4767 if Is_Subprogram (Def_Id)
4768 and then Is_Abstract_Subprogram (Def_Id)
4770 Error_Msg_Sloc := Sloc (Def_Id);
4772 ("cannot import abstract subprogram& declared#",
4776 -- Special processing for Convention_Intrinsic
4778 if C = Convention_Intrinsic then
4780 -- Link_Name argument not allowed for intrinsic
4784 Set_Is_Intrinsic_Subprogram (Def_Id);
4786 -- If no external name is present, then check that this
4787 -- is a valid intrinsic subprogram. If an external name
4788 -- is present, then this is handled by the back end.
4791 Check_Intrinsic_Subprogram
4792 (Def_Id, Get_Pragma_Arg (Arg2));
4796 -- All interfaced procedures need an external symbol created
4797 -- for them since they are always referenced from another
4800 Set_Is_Public (Def_Id);
4802 -- Verify that the subprogram does not have a completion
4803 -- through a renaming declaration. For other completions the
4804 -- pragma appears as a too late representation.
4807 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4811 and then Nkind (Decl) = N_Subprogram_Declaration
4812 and then Present (Corresponding_Body (Decl))
4813 and then Nkind (Unit_Declaration_Node
4814 (Corresponding_Body (Decl))) =
4815 N_Subprogram_Renaming_Declaration
4817 Error_Msg_Sloc := Sloc (Def_Id);
4819 ("cannot import&, renaming already provided for "
4820 & "declaration #", N, Def_Id);
4824 Set_Has_Completion (Def_Id);
4825 Process_Interface_Name (Def_Id, Arg3, Arg4);
4828 if Is_Compilation_Unit (Hom_Id) then
4830 -- Its possible homonyms are not affected by the pragma.
4831 -- Such homonyms might be present in the context of other
4832 -- units being compiled.
4836 elsif From_Aspect_Specification (N) then
4840 Hom_Id := Homonym (Hom_Id);
4844 -- When the convention is Java or CIL, we also allow Import to be
4845 -- given for packages, generic packages, exceptions, record
4846 -- components, and access to subprograms.
4848 elsif (C = Convention_Java or else C = Convention_CIL)
4850 (Is_Package_Or_Generic_Package (Def_Id)
4851 or else Ekind (Def_Id) = E_Exception
4852 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4853 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4855 Set_Imported (Def_Id);
4856 Set_Is_Public (Def_Id);
4857 Process_Interface_Name (Def_Id, Arg3, Arg4);
4859 -- Import a CPP class
4861 elsif C = Convention_CPP
4862 and then (Is_Record_Type (Def_Id)
4863 or else Ekind (Def_Id) = E_Incomplete_Type)
4865 if Ekind (Def_Id) = E_Incomplete_Type then
4866 if Present (Full_View (Def_Id)) then
4867 Def_Id := Full_View (Def_Id);
4871 ("cannot import 'C'P'P type before full declaration seen",
4872 Get_Pragma_Arg (Arg2));
4874 -- Although we have reported the error we decorate it as
4875 -- CPP_Class to avoid reporting spurious errors
4877 Set_Is_CPP_Class (Def_Id);
4882 -- Types treated as CPP classes must be declared limited (note:
4883 -- this used to be a warning but there is no real benefit to it
4884 -- since we did effectively intend to treat the type as limited
4887 if not Is_Limited_Type (Def_Id) then
4889 ("imported 'C'P'P type must be limited",
4890 Get_Pragma_Arg (Arg2));
4893 if Etype (Def_Id) /= Def_Id
4894 and then not Is_CPP_Class (Root_Type (Def_Id))
4896 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
4899 Set_Is_CPP_Class (Def_Id);
4901 -- Imported CPP types must not have discriminants (because C++
4902 -- classes do not have discriminants).
4904 if Has_Discriminants (Def_Id) then
4906 ("imported 'C'P'P type cannot have discriminants",
4907 First (Discriminant_Specifications
4908 (Declaration_Node (Def_Id))));
4911 -- Check that components of imported CPP types do not have default
4912 -- expressions. For private types this check is performed when the
4913 -- full view is analyzed (see Process_Full_View).
4915 if not Is_Private_Type (Def_Id) then
4916 Check_CPP_Type_Has_No_Defaults (Def_Id);
4919 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4921 Check_Arg_Count (3);
4922 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4924 Process_Import_Predefined_Type;
4928 ("second argument of pragma% must be object, subprogram "
4929 & "or incomplete type",
4933 -- If this pragma applies to a compilation unit, then the unit, which
4934 -- is a subprogram, does not require (or allow) a body. We also do
4935 -- not need to elaborate imported procedures.
4937 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4939 Cunit : constant Node_Id := Parent (Parent (N));
4941 Set_Body_Required (Cunit, False);
4944 end Process_Import_Or_Interface;
4946 --------------------
4947 -- Process_Inline --
4948 --------------------
4950 procedure Process_Inline (Status : Inline_Status) is
4957 Effective : Boolean := False;
4958 -- Set True if inline has some effect, i.e. if there is at least one
4959 -- subprogram set as inlined as a result of the use of the pragma.
4961 procedure Make_Inline (Subp : Entity_Id);
4962 -- Subp is the defining unit name of the subprogram declaration. Set
4963 -- the flag, as well as the flag in the corresponding body, if there
4966 procedure Set_Inline_Flags (Subp : Entity_Id);
4967 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4968 -- Has_Pragma_Inline_Always for the Inline_Always case.
4970 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4971 -- Returns True if it can be determined at this stage that inlining
4972 -- is not possible, for example if the body is available and contains
4973 -- exception handlers, we prevent inlining, since otherwise we can
4974 -- get undefined symbols at link time. This function also emits a
4975 -- warning if front-end inlining is enabled and the pragma appears
4978 -- ??? is business with link symbols still valid, or does it relate
4979 -- to front end ZCX which is being phased out ???
4981 ---------------------------
4982 -- Inlining_Not_Possible --
4983 ---------------------------
4985 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4986 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4990 if Nkind (Decl) = N_Subprogram_Body then
4991 Stats := Handled_Statement_Sequence (Decl);
4992 return Present (Exception_Handlers (Stats))
4993 or else Present (At_End_Proc (Stats));
4995 elsif Nkind (Decl) = N_Subprogram_Declaration
4996 and then Present (Corresponding_Body (Decl))
4998 if Front_End_Inlining
4999 and then Analyzed (Corresponding_Body (Decl))
5001 Error_Msg_N ("pragma appears too late, ignored??", N);
5004 -- If the subprogram is a renaming as body, the body is just a
5005 -- call to the renamed subprogram, and inlining is trivially
5009 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
5010 N_Subprogram_Renaming_Declaration
5016 Handled_Statement_Sequence
5017 (Unit_Declaration_Node (Corresponding_Body (Decl)));
5020 Present (Exception_Handlers (Stats))
5021 or else Present (At_End_Proc (Stats));
5025 -- If body is not available, assume the best, the check is
5026 -- performed again when compiling enclosing package bodies.
5030 end Inlining_Not_Possible;
5036 procedure Make_Inline (Subp : Entity_Id) is
5037 Kind : constant Entity_Kind := Ekind (Subp);
5038 Inner_Subp : Entity_Id := Subp;
5041 -- Ignore if bad type, avoid cascaded error
5043 if Etype (Subp) = Any_Type then
5047 -- Ignore if all inlining is suppressed
5049 elsif Suppress_All_Inlining then
5053 -- If inlining is not possible, for now do not treat as an error
5055 elsif Status /= Suppressed
5056 and then Inlining_Not_Possible (Subp)
5061 -- Here we have a candidate for inlining, but we must exclude
5062 -- derived operations. Otherwise we would end up trying to inline
5063 -- a phantom declaration, and the result would be to drag in a
5064 -- body which has no direct inlining associated with it. That
5065 -- would not only be inefficient but would also result in the
5066 -- backend doing cross-unit inlining in cases where it was
5067 -- definitely inappropriate to do so.
5069 -- However, a simple Comes_From_Source test is insufficient, since
5070 -- we do want to allow inlining of generic instances which also do
5071 -- not come from source. We also need to recognize specs generated
5072 -- by the front-end for bodies that carry the pragma. Finally,
5073 -- predefined operators do not come from source but are not
5074 -- inlineable either.
5076 elsif Is_Generic_Instance (Subp)
5077 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
5081 elsif not Comes_From_Source (Subp)
5082 and then Scope (Subp) /= Standard_Standard
5088 -- The referenced entity must either be the enclosing entity, or
5089 -- an entity declared within the current open scope.
5091 if Present (Scope (Subp))
5092 and then Scope (Subp) /= Current_Scope
5093 and then Subp /= Current_Scope
5096 ("argument of% must be entity in current scope", Assoc);
5100 -- Processing for procedure, operator or function. If subprogram
5101 -- is aliased (as for an instance) indicate that the renamed
5102 -- entity (if declared in the same unit) is inlined.
5104 if Is_Subprogram (Subp) then
5105 Inner_Subp := Ultimate_Alias (Inner_Subp);
5107 if In_Same_Source_Unit (Subp, Inner_Subp) then
5108 Set_Inline_Flags (Inner_Subp);
5110 Decl := Parent (Parent (Inner_Subp));
5112 if Nkind (Decl) = N_Subprogram_Declaration
5113 and then Present (Corresponding_Body (Decl))
5115 Set_Inline_Flags (Corresponding_Body (Decl));
5117 elsif Is_Generic_Instance (Subp) then
5119 -- Indicate that the body needs to be created for
5120 -- inlining subsequent calls. The instantiation node
5121 -- follows the declaration of the wrapper package
5124 if Scope (Subp) /= Standard_Standard
5126 Need_Subprogram_Instance_Body
5127 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
5133 -- Inline is a program unit pragma (RM 10.1.5) and cannot
5134 -- appear in a formal part to apply to a formal subprogram.
5135 -- Do not apply check within an instance or a formal package
5136 -- the test will have been applied to the original generic.
5138 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
5139 and then List_Containing (Decl) = List_Containing (N)
5140 and then not In_Instance
5143 ("Inline cannot apply to a formal subprogram", N);
5145 -- If Subp is a renaming, it is the renamed entity that
5146 -- will appear in any call, and be inlined. However, for
5147 -- ASIS uses it is convenient to indicate that the renaming
5148 -- itself is an inlined subprogram, so that some gnatcheck
5149 -- rules can be applied in the absence of expansion.
5151 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
5152 Set_Inline_Flags (Subp);
5158 -- For a generic subprogram set flag as well, for use at the point
5159 -- of instantiation, to determine whether the body should be
5162 elsif Is_Generic_Subprogram (Subp) then
5163 Set_Inline_Flags (Subp);
5166 -- Literals are by definition inlined
5168 elsif Kind = E_Enumeration_Literal then
5171 -- Anything else is an error
5175 ("expect subprogram name for pragma%", Assoc);
5179 ----------------------
5180 -- Set_Inline_Flags --
5181 ----------------------
5183 procedure Set_Inline_Flags (Subp : Entity_Id) is
5185 -- First set the Has_Pragma_XXX flags and issue the appropriate
5186 -- errors and warnings for suspicious combinations.
5188 if Prag_Id = Pragma_No_Inline then
5189 if Has_Pragma_Inline_Always (Subp) then
5191 ("Inline_Always and No_Inline are mutually exclusive", N);
5192 elsif Has_Pragma_Inline (Subp) then
5194 ("Inline and No_Inline both specified for& ??",
5195 N, Entity (Subp_Id));
5198 Set_Has_Pragma_No_Inline (Subp);
5200 if Prag_Id = Pragma_Inline_Always then
5201 if Has_Pragma_No_Inline (Subp) then
5203 ("Inline_Always and No_Inline are mutually exclusive",
5207 Set_Has_Pragma_Inline_Always (Subp);
5209 if Has_Pragma_No_Inline (Subp) then
5211 ("Inline and No_Inline both specified for& ??",
5212 N, Entity (Subp_Id));
5216 if not Has_Pragma_Inline (Subp) then
5217 Set_Has_Pragma_Inline (Subp);
5222 -- Then adjust the Is_Inlined flag. It can never be set if the
5223 -- subprogram is subject to pragma No_Inline.
5227 Set_Is_Inlined (Subp, False);
5231 if not Has_Pragma_No_Inline (Subp) then
5232 Set_Is_Inlined (Subp, True);
5235 end Set_Inline_Flags;
5237 -- Start of processing for Process_Inline
5240 Check_No_Identifiers;
5241 Check_At_Least_N_Arguments (1);
5243 if Status = Enabled then
5244 Inline_Processing_Required := True;
5248 while Present (Assoc) loop
5249 Subp_Id := Get_Pragma_Arg (Assoc);
5253 if Is_Entity_Name (Subp_Id) then
5254 Subp := Entity (Subp_Id);
5256 if Subp = Any_Id then
5258 -- If previous error, avoid cascaded errors
5260 Check_Error_Detected;
5267 -- For the pragma case, climb homonym chain. This is
5268 -- what implements allowing the pragma in the renaming
5269 -- case, with the result applying to the ancestors, and
5270 -- also allows Inline to apply to all previous homonyms.
5272 if not From_Aspect_Specification (N) then
5273 while Present (Homonym (Subp))
5274 and then Scope (Homonym (Subp)) = Current_Scope
5276 Make_Inline (Homonym (Subp));
5277 Subp := Homonym (Subp);
5285 ("inappropriate argument for pragma%", Assoc);
5288 and then Warn_On_Redundant_Constructs
5289 and then not (Status = Suppressed or else Suppress_All_Inlining)
5291 if Inlining_Not_Possible (Subp) then
5293 ("pragma Inline for& is ignored?r?",
5294 N, Entity (Subp_Id));
5297 ("pragma Inline for& is redundant?r?",
5298 N, Entity (Subp_Id));
5306 ----------------------------
5307 -- Process_Interface_Name --
5308 ----------------------------
5310 procedure Process_Interface_Name
5311 (Subprogram_Def : Entity_Id;
5317 String_Val : String_Id;
5319 procedure Check_Form_Of_Interface_Name
5321 Ext_Name_Case : Boolean);
5322 -- SN is a string literal node for an interface name. This routine
5323 -- performs some minimal checks that the name is reasonable. In
5324 -- particular that no spaces or other obviously incorrect characters
5325 -- appear. This is only a warning, since any characters are allowed.
5326 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5328 ----------------------------------
5329 -- Check_Form_Of_Interface_Name --
5330 ----------------------------------
5332 procedure Check_Form_Of_Interface_Name
5334 Ext_Name_Case : Boolean)
5336 S : constant String_Id := Strval (Expr_Value_S (SN));
5337 SL : constant Nat := String_Length (S);
5342 Error_Msg_N ("interface name cannot be null string", SN);
5345 for J in 1 .. SL loop
5346 C := Get_String_Char (S, J);
5348 -- Look for dubious character and issue unconditional warning.
5349 -- Definitely dubious if not in character range.
5351 if not In_Character_Range (C)
5353 -- For all cases except CLI target,
5354 -- commas, spaces and slashes are dubious (in CLI, we use
5355 -- commas and backslashes in external names to specify
5356 -- assembly version and public key, while slashes and spaces
5357 -- can be used in names to mark nested classes and
5360 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5361 and then (Get_Character (C) = ','
5363 Get_Character (C) = '\'))
5364 or else (VM_Target /= CLI_Target
5365 and then (Get_Character (C) = ' '
5367 Get_Character (C) = '/'))
5370 ("??interface name contains illegal character",
5371 Sloc (SN) + Source_Ptr (J));
5374 end Check_Form_Of_Interface_Name;
5376 -- Start of processing for Process_Interface_Name
5379 if No (Link_Arg) then
5380 if No (Ext_Arg) then
5381 if VM_Target = CLI_Target
5382 and then Ekind (Subprogram_Def) = E_Package
5383 and then Nkind (Parent (Subprogram_Def)) =
5384 N_Package_Specification
5385 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5390 (Generic_Parent (Parent (Subprogram_Def))));
5395 elsif Chars (Ext_Arg) = Name_Link_Name then
5397 Link_Nam := Expression (Ext_Arg);
5400 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5401 Ext_Nam := Expression (Ext_Arg);
5406 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5407 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5408 Ext_Nam := Expression (Ext_Arg);
5409 Link_Nam := Expression (Link_Arg);
5412 -- Check expressions for external name and link name are static
5414 if Present (Ext_Nam) then
5415 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5416 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5418 -- Verify that external name is not the name of a local entity,
5419 -- which would hide the imported one and could lead to run-time
5420 -- surprises. The problem can only arise for entities declared in
5421 -- a package body (otherwise the external name is fully qualified
5422 -- and will not conflict).
5430 if Prag_Id = Pragma_Import then
5431 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5433 E := Entity_Id (Get_Name_Table_Info (Nam));
5435 if Nam /= Chars (Subprogram_Def)
5436 and then Present (E)
5437 and then not Is_Overloadable (E)
5438 and then Is_Immediately_Visible (E)
5439 and then not Is_Imported (E)
5440 and then Ekind (Scope (E)) = E_Package
5443 while Present (Par) loop
5444 if Nkind (Par) = N_Package_Body then
5445 Error_Msg_Sloc := Sloc (E);
5447 ("imported entity is hidden by & declared#",
5452 Par := Parent (Par);
5459 if Present (Link_Nam) then
5460 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5461 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5464 -- If there is no link name, just set the external name
5466 if No (Link_Nam) then
5467 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5469 -- For the Link_Name case, the given literal is preceded by an
5470 -- asterisk, which indicates to GCC that the given name should be
5471 -- taken literally, and in particular that no prepending of
5472 -- underlines should occur, even in systems where this is the
5478 if VM_Target = No_VM then
5479 Store_String_Char (Get_Char_Code ('*'));
5482 String_Val := Strval (Expr_Value_S (Link_Nam));
5483 Store_String_Chars (String_Val);
5485 Make_String_Literal (Sloc (Link_Nam),
5486 Strval => End_String);
5489 -- Set the interface name. If the entity is a generic instance, use
5490 -- its alias, which is the callable entity.
5492 if Is_Generic_Instance (Subprogram_Def) then
5493 Set_Encoded_Interface_Name
5494 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5496 Set_Encoded_Interface_Name
5497 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5500 -- We allow duplicated export names in CIL/Java, as they are always
5501 -- enclosed in a namespace that differentiates them, and overloaded
5502 -- entities are supported by the VM.
5504 if Convention (Subprogram_Def) /= Convention_CIL
5506 Convention (Subprogram_Def) /= Convention_Java
5508 Check_Duplicated_Export_Name (Link_Nam);
5510 end Process_Interface_Name;
5512 -----------------------------------------
5513 -- Process_Interrupt_Or_Attach_Handler --
5514 -----------------------------------------
5516 procedure Process_Interrupt_Or_Attach_Handler is
5517 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5518 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5519 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5522 Set_Is_Interrupt_Handler (Handler_Proc);
5524 -- If the pragma is not associated with a handler procedure within a
5525 -- protected type, then it must be for a nonprotected procedure for
5526 -- the AAMP target, in which case we don't associate a representation
5527 -- item with the procedure's scope.
5529 if Ekind (Proc_Scope) = E_Protected_Type then
5530 if Prag_Id = Pragma_Interrupt_Handler
5532 Prag_Id = Pragma_Attach_Handler
5534 Record_Rep_Item (Proc_Scope, N);
5537 end Process_Interrupt_Or_Attach_Handler;
5539 --------------------------------------------------
5540 -- Process_Restrictions_Or_Restriction_Warnings --
5541 --------------------------------------------------
5543 -- Note: some of the simple identifier cases were handled in par-prag,
5544 -- but it is harmless (and more straightforward) to simply handle all
5545 -- cases here, even if it means we repeat a bit of work in some cases.
5547 procedure Process_Restrictions_Or_Restriction_Warnings
5551 R_Id : Restriction_Id;
5556 procedure Check_Unit_Name (N : Node_Id);
5557 -- Checks unit name parameter for No_Dependence. Returns if it has
5558 -- an appropriate form, otherwise raises pragma argument error.
5560 ---------------------
5561 -- Check_Unit_Name --
5562 ---------------------
5564 procedure Check_Unit_Name (N : Node_Id) is
5566 if Nkind (N) = N_Selected_Component then
5567 Check_Unit_Name (Prefix (N));
5568 Check_Unit_Name (Selector_Name (N));
5570 elsif Nkind (N) = N_Identifier then
5575 ("wrong form for unit name for No_Dependence", N);
5577 end Check_Unit_Name;
5579 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5582 -- Ignore all Restrictions pragma in CodePeer mode
5584 if CodePeer_Mode then
5588 Check_Ada_83_Warning;
5589 Check_At_Least_N_Arguments (1);
5590 Check_Valid_Configuration_Pragma;
5593 while Present (Arg) loop
5595 Expr := Get_Pragma_Arg (Arg);
5597 -- Case of no restriction identifier present
5599 if Id = No_Name then
5600 if Nkind (Expr) /= N_Identifier then
5602 ("invalid form for restriction", Arg);
5607 (Process_Restriction_Synonyms (Expr));
5609 if R_Id not in All_Boolean_Restrictions then
5610 Error_Msg_Name_1 := Pname;
5612 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5614 -- Check for possible misspelling
5616 for J in Restriction_Id loop
5618 Rnm : constant String := Restriction_Id'Image (J);
5621 Name_Buffer (1 .. Rnm'Length) := Rnm;
5622 Name_Len := Rnm'Length;
5623 Set_Casing (All_Lower_Case);
5625 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5627 (Identifier_Casing (Current_Source_File));
5628 Error_Msg_String (1 .. Rnm'Length) :=
5629 Name_Buffer (1 .. Name_Len);
5630 Error_Msg_Strlen := Rnm'Length;
5631 Error_Msg_N -- CODEFIX
5632 ("\possible misspelling of ""~""",
5633 Get_Pragma_Arg (Arg));
5642 if Implementation_Restriction (R_Id) then
5643 Check_Restriction (No_Implementation_Restrictions, Arg);
5646 -- Special processing for No_Elaboration_Code restriction
5648 if R_Id = No_Elaboration_Code then
5650 -- Restriction is only recognized within a configuration
5651 -- pragma file, or within a unit of the main extended
5652 -- program. Note: the test for Main_Unit is needed to
5653 -- properly include the case of configuration pragma files.
5655 if not (Current_Sem_Unit = Main_Unit
5656 or else In_Extended_Main_Source_Unit (N))
5660 -- Don't allow in a subunit unless already specified in
5663 elsif Nkind (Parent (N)) = N_Compilation_Unit
5664 and then Nkind (Unit (Parent (N))) = N_Subunit
5665 and then not Restriction_Active (No_Elaboration_Code)
5668 ("invalid specification of ""No_Elaboration_Code""",
5671 ("\restriction cannot be specified in a subunit", N);
5673 ("\unless also specified in body or spec", N);
5676 -- If we have a No_Elaboration_Code pragma that we
5677 -- accept, then it needs to be added to the configuration
5678 -- restrcition set so that we get proper application to
5679 -- other units in the main extended source as required.
5682 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
5686 -- If this is a warning, then set the warning unless we already
5687 -- have a real restriction active (we never want a warning to
5688 -- override a real restriction).
5691 if not Restriction_Active (R_Id) then
5692 Set_Restriction (R_Id, N);
5693 Restriction_Warnings (R_Id) := True;
5696 -- If real restriction case, then set it and make sure that the
5697 -- restriction warning flag is off, since a real restriction
5698 -- always overrides a warning.
5701 Set_Restriction (R_Id, N);
5702 Restriction_Warnings (R_Id) := False;
5705 -- Check for obsolescent restrictions in Ada 2005 mode
5708 and then Ada_Version >= Ada_2005
5709 and then (R_Id = No_Asynchronous_Control
5711 R_Id = No_Unchecked_Deallocation
5713 R_Id = No_Unchecked_Conversion)
5715 Check_Restriction (No_Obsolescent_Features, N);
5718 -- A very special case that must be processed here: pragma
5719 -- Restrictions (No_Exceptions) turns off all run-time
5720 -- checking. This is a bit dubious in terms of the formal
5721 -- language definition, but it is what is intended by RM
5722 -- H.4(12). Restriction_Warnings never affects generated code
5723 -- so this is done only in the real restriction case.
5725 -- Atomic_Synchronization is not a real check, so it is not
5726 -- affected by this processing).
5728 if R_Id = No_Exceptions and then not Warn then
5729 for J in Scope_Suppress.Suppress'Range loop
5730 if J /= Atomic_Synchronization then
5731 Scope_Suppress.Suppress (J) := True;
5736 -- Case of No_Dependence => unit-name. Note that the parser
5737 -- already made the necessary entry in the No_Dependence table.
5739 elsif Id = Name_No_Dependence then
5740 Check_Unit_Name (Expr);
5742 -- Case of No_Specification_Of_Aspect => Identifier.
5744 elsif Id = Name_No_Specification_Of_Aspect then
5749 if Nkind (Expr) /= N_Identifier then
5752 A_Id := Get_Aspect_Id (Chars (Expr));
5755 if A_Id = No_Aspect then
5756 Error_Pragma_Arg ("invalid restriction name", Arg);
5758 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5762 -- All other cases of restriction identifier present
5765 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5766 Analyze_And_Resolve (Expr, Any_Integer);
5768 if R_Id not in All_Parameter_Restrictions then
5770 ("invalid restriction parameter identifier", Arg);
5772 elsif not Is_OK_Static_Expression (Expr) then
5773 Flag_Non_Static_Expr
5774 ("value must be static expression!", Expr);
5777 elsif not Is_Integer_Type (Etype (Expr))
5778 or else Expr_Value (Expr) < 0
5781 ("value must be non-negative integer", Arg);
5784 -- Restriction pragma is active
5786 Val := Expr_Value (Expr);
5788 if not UI_Is_In_Int_Range (Val) then
5790 ("pragma ignored, value too large??", Arg);
5793 -- Warning case. If the real restriction is active, then we
5794 -- ignore the request, since warning never overrides a real
5795 -- restriction. Otherwise we set the proper warning. Note that
5796 -- this circuit sets the warning again if it is already set,
5797 -- which is what we want, since the constant may have changed.
5800 if not Restriction_Active (R_Id) then
5802 (R_Id, N, Integer (UI_To_Int (Val)));
5803 Restriction_Warnings (R_Id) := True;
5806 -- Real restriction case, set restriction and make sure warning
5807 -- flag is off since real restriction always overrides warning.
5810 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5811 Restriction_Warnings (R_Id) := False;
5817 end Process_Restrictions_Or_Restriction_Warnings;
5819 ---------------------------------
5820 -- Process_Suppress_Unsuppress --
5821 ---------------------------------
5823 -- Note: this procedure makes entries in the check suppress data
5824 -- structures managed by Sem. See spec of package Sem for full
5825 -- details on how we handle recording of check suppression.
5827 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5832 In_Package_Spec : constant Boolean :=
5833 Is_Package_Or_Generic_Package (Current_Scope)
5834 and then not In_Package_Body (Current_Scope);
5836 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5837 -- Used to suppress a single check on the given entity
5839 --------------------------------
5840 -- Suppress_Unsuppress_Echeck --
5841 --------------------------------
5843 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5845 -- Check for error of trying to set atomic synchronization for
5846 -- a non-atomic variable.
5848 if C = Atomic_Synchronization
5849 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5852 ("pragma & requires atomic type or variable",
5853 Pragma_Identifier (Original_Node (N)));
5856 Set_Checks_May_Be_Suppressed (E);
5858 if In_Package_Spec then
5859 Push_Global_Suppress_Stack_Entry
5862 Suppress => Suppress_Case);
5864 Push_Local_Suppress_Stack_Entry
5867 Suppress => Suppress_Case);
5870 -- If this is a first subtype, and the base type is distinct,
5871 -- then also set the suppress flags on the base type.
5873 if Is_First_Subtype (E) and then Etype (E) /= E then
5874 Suppress_Unsuppress_Echeck (Etype (E), C);
5876 end Suppress_Unsuppress_Echeck;
5878 -- Start of processing for Process_Suppress_Unsuppress
5881 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5882 -- user code: we want to generate checks for analysis purposes, as
5883 -- set respectively by -gnatC and -gnatd.F
5885 if (CodePeer_Mode or Alfa_Mode) and then Comes_From_Source (N) then
5889 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5890 -- declarative part or a package spec (RM 11.5(5)).
5892 if not Is_Configuration_Pragma then
5893 Check_Is_In_Decl_Part_Or_Package_Spec;
5896 Check_At_Least_N_Arguments (1);
5897 Check_At_Most_N_Arguments (2);
5898 Check_No_Identifier (Arg1);
5899 Check_Arg_Is_Identifier (Arg1);
5901 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5903 if C = No_Check_Id then
5905 ("argument of pragma% is not valid check name", Arg1);
5908 if Arg_Count = 1 then
5910 -- Make an entry in the local scope suppress table. This is the
5911 -- table that directly shows the current value of the scope
5912 -- suppress check for any check id value.
5914 if C = All_Checks then
5916 -- For All_Checks, we set all specific predefined checks with
5917 -- the exception of Elaboration_Check, which is handled
5918 -- specially because of not wanting All_Checks to have the
5919 -- effect of deactivating static elaboration order processing.
5920 -- Atomic_Synchronization is also not affected, since this is
5921 -- not a real check.
5923 for J in Scope_Suppress.Suppress'Range loop
5924 if J /= Elaboration_Check
5926 J /= Atomic_Synchronization
5928 Scope_Suppress.Suppress (J) := Suppress_Case;
5932 -- If not All_Checks, and predefined check, then set appropriate
5933 -- scope entry. Note that we will set Elaboration_Check if this
5934 -- is explicitly specified. Atomic_Synchronization is allowed
5935 -- only if internally generated and entity is atomic.
5937 elsif C in Predefined_Check_Id
5938 and then (not Comes_From_Source (N)
5939 or else C /= Atomic_Synchronization)
5941 Scope_Suppress.Suppress (C) := Suppress_Case;
5944 -- Also make an entry in the Local_Entity_Suppress table
5946 Push_Local_Suppress_Stack_Entry
5949 Suppress => Suppress_Case);
5951 -- Case of two arguments present, where the check is suppressed for
5952 -- a specified entity (given as the second argument of the pragma)
5955 -- This is obsolescent in Ada 2005 mode
5957 if Ada_Version >= Ada_2005 then
5958 Check_Restriction (No_Obsolescent_Features, Arg2);
5961 Check_Optional_Identifier (Arg2, Name_On);
5962 E_Id := Get_Pragma_Arg (Arg2);
5965 if not Is_Entity_Name (E_Id) then
5967 ("second argument of pragma% must be entity name", Arg2);
5976 -- Enforce RM 11.5(7) which requires that for a pragma that
5977 -- appears within a package spec, the named entity must be
5978 -- within the package spec. We allow the package name itself
5979 -- to be mentioned since that makes sense, although it is not
5980 -- strictly allowed by 11.5(7).
5983 and then E /= Current_Scope
5984 and then Scope (E) /= Current_Scope
5987 ("entity in pragma% is not in package spec (RM 11.5(7))",
5991 -- Loop through homonyms. As noted below, in the case of a package
5992 -- spec, only homonyms within the package spec are considered.
5995 Suppress_Unsuppress_Echeck (E, C);
5997 if Is_Generic_Instance (E)
5998 and then Is_Subprogram (E)
5999 and then Present (Alias (E))
6001 Suppress_Unsuppress_Echeck (Alias (E), C);
6004 -- Move to next homonym if not aspect spec case
6006 exit when From_Aspect_Specification (N);
6010 -- If we are within a package specification, the pragma only
6011 -- applies to homonyms in the same scope.
6013 exit when In_Package_Spec
6014 and then Scope (E) /= Current_Scope;
6017 end Process_Suppress_Unsuppress;
6023 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
6025 if Is_Imported (E) then
6027 ("cannot export entity& that was previously imported", Arg);
6029 elsif Present (Address_Clause (E))
6030 and then not Relaxed_RM_Semantics
6033 ("cannot export entity& that has an address clause", Arg);
6036 Set_Is_Exported (E);
6038 -- Generate a reference for entity explicitly, because the
6039 -- identifier may be overloaded and name resolution will not
6042 Generate_Reference (E, Arg);
6044 -- Deal with exporting non-library level entity
6046 if not Is_Library_Level_Entity (E) then
6048 -- Not allowed at all for subprograms
6050 if Is_Subprogram (E) then
6051 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
6053 -- Otherwise set public and statically allocated
6057 Set_Is_Statically_Allocated (E);
6059 -- Warn if the corresponding W flag is set and the pragma comes
6060 -- from source. The latter may not be true e.g. on VMS where we
6061 -- expand export pragmas for exception codes associated with
6062 -- imported or exported exceptions. We do not want to generate
6063 -- a warning for something that the user did not write.
6065 if Warn_On_Export_Import
6066 and then Comes_From_Source (Arg)
6069 ("?x?& has been made static as a result of Export",
6072 ("\?x?this usage is non-standard and non-portable",
6078 if Warn_On_Export_Import and then Is_Type (E) then
6079 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
6082 if Warn_On_Export_Import and Inside_A_Generic then
6084 ("all instances of& will have the same external name?x?",
6089 ----------------------------------------------
6090 -- Set_Extended_Import_Export_External_Name --
6091 ----------------------------------------------
6093 procedure Set_Extended_Import_Export_External_Name
6094 (Internal_Ent : Entity_Id;
6095 Arg_External : Node_Id)
6097 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
6101 if No (Arg_External) then
6105 Check_Arg_Is_External_Name (Arg_External);
6107 if Nkind (Arg_External) = N_String_Literal then
6108 if String_Length (Strval (Arg_External)) = 0 then
6111 New_Name := Adjust_External_Name_Case (Arg_External);
6114 elsif Nkind (Arg_External) = N_Identifier then
6115 New_Name := Get_Default_External_Name (Arg_External);
6117 -- Check_Arg_Is_External_Name should let through only identifiers and
6118 -- string literals or static string expressions (which are folded to
6119 -- string literals).
6122 raise Program_Error;
6125 -- If we already have an external name set (by a prior normal Import
6126 -- or Export pragma), then the external names must match
6128 if Present (Interface_Name (Internal_Ent)) then
6129 Check_Matching_Internal_Names : declare
6130 S1 : constant String_Id := Strval (Old_Name);
6131 S2 : constant String_Id := Strval (New_Name);
6134 pragma No_Return (Mismatch);
6135 -- Called if names do not match
6141 procedure Mismatch is
6143 Error_Msg_Sloc := Sloc (Old_Name);
6145 ("external name does not match that given #",
6149 -- Start of processing for Check_Matching_Internal_Names
6152 if String_Length (S1) /= String_Length (S2) then
6156 for J in 1 .. String_Length (S1) loop
6157 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
6162 end Check_Matching_Internal_Names;
6164 -- Otherwise set the given name
6167 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
6168 Check_Duplicated_Export_Name (New_Name);
6170 end Set_Extended_Import_Export_External_Name;
6176 procedure Set_Imported (E : Entity_Id) is
6178 -- Error message if already imported or exported
6180 if Is_Exported (E) or else Is_Imported (E) then
6182 -- Error if being set Exported twice
6184 if Is_Exported (E) then
6185 Error_Msg_NE ("entity& was previously exported", N, E);
6187 -- OK if Import/Interface case
6189 elsif Import_Interface_Present (N) then
6192 -- Error if being set Imported twice
6195 Error_Msg_NE ("entity& was previously imported", N, E);
6198 Error_Msg_Name_1 := Pname;
6200 ("\(pragma% applies to all previous entities)", N);
6202 Error_Msg_Sloc := Sloc (E);
6203 Error_Msg_NE ("\import not allowed for& declared#", N, E);
6205 -- Here if not previously imported or exported, OK to import
6208 Set_Is_Imported (E);
6210 -- If the entity is an object that is not at the library level,
6211 -- then it is statically allocated. We do not worry about objects
6212 -- with address clauses in this context since they are not really
6213 -- imported in the linker sense.
6216 and then not Is_Library_Level_Entity (E)
6217 and then No (Address_Clause (E))
6219 Set_Is_Statically_Allocated (E);
6226 -------------------------
6227 -- Set_Mechanism_Value --
6228 -------------------------
6230 -- Note: the mechanism name has not been analyzed (and cannot indeed be
6231 -- analyzed, since it is semantic nonsense), so we get it in the exact
6232 -- form created by the parser.
6234 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
6237 Mech_Name_Id : Name_Id;
6239 procedure Bad_Class;
6240 pragma No_Return (Bad_Class);
6241 -- Signal bad descriptor class name
6243 procedure Bad_Mechanism;
6244 pragma No_Return (Bad_Mechanism);
6245 -- Signal bad mechanism name
6251 procedure Bad_Class is
6253 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
6256 -------------------------
6257 -- Bad_Mechanism_Value --
6258 -------------------------
6260 procedure Bad_Mechanism is
6262 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
6265 -- Start of processing for Set_Mechanism_Value
6268 if Mechanism (Ent) /= Default_Mechanism then
6270 ("mechanism for & has already been set", Mech_Name, Ent);
6273 -- MECHANISM_NAME ::= value | reference | descriptor |
6276 if Nkind (Mech_Name) = N_Identifier then
6277 if Chars (Mech_Name) = Name_Value then
6278 Set_Mechanism (Ent, By_Copy);
6281 elsif Chars (Mech_Name) = Name_Reference then
6282 Set_Mechanism (Ent, By_Reference);
6285 elsif Chars (Mech_Name) = Name_Descriptor then
6286 Check_VMS (Mech_Name);
6288 -- Descriptor => Short_Descriptor if pragma was given
6290 if Short_Descriptors then
6291 Set_Mechanism (Ent, By_Short_Descriptor);
6293 Set_Mechanism (Ent, By_Descriptor);
6298 elsif Chars (Mech_Name) = Name_Short_Descriptor then
6299 Check_VMS (Mech_Name);
6300 Set_Mechanism (Ent, By_Short_Descriptor);
6303 elsif Chars (Mech_Name) = Name_Copy then
6305 ("bad mechanism name, Value assumed", Mech_Name);
6311 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
6312 -- short_descriptor (CLASS_NAME)
6313 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6315 -- Note: this form is parsed as an indexed component
6317 elsif Nkind (Mech_Name) = N_Indexed_Component then
6318 Class := First (Expressions (Mech_Name));
6320 if Nkind (Prefix (Mech_Name)) /= N_Identifier
6321 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
6322 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
6323 or else Present (Next (Class))
6327 Mech_Name_Id := Chars (Prefix (Mech_Name));
6329 -- Change Descriptor => Short_Descriptor if pragma was given
6331 if Mech_Name_Id = Name_Descriptor
6332 and then Short_Descriptors
6334 Mech_Name_Id := Name_Short_Descriptor;
6338 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6339 -- short_descriptor (Class => CLASS_NAME)
6340 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6342 -- Note: this form is parsed as a function call
6344 elsif Nkind (Mech_Name) = N_Function_Call then
6345 Param := First (Parameter_Associations (Mech_Name));
6347 if Nkind (Name (Mech_Name)) /= N_Identifier
6348 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6349 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6350 or else Present (Next (Param))
6351 or else No (Selector_Name (Param))
6352 or else Chars (Selector_Name (Param)) /= Name_Class
6356 Class := Explicit_Actual_Parameter (Param);
6357 Mech_Name_Id := Chars (Name (Mech_Name));
6364 -- Fall through here with Class set to descriptor class name
6366 Check_VMS (Mech_Name);
6368 if Nkind (Class) /= N_Identifier then
6371 elsif Mech_Name_Id = Name_Descriptor
6372 and then Chars (Class) = Name_UBS
6374 Set_Mechanism (Ent, By_Descriptor_UBS);
6376 elsif Mech_Name_Id = Name_Descriptor
6377 and then Chars (Class) = Name_UBSB
6379 Set_Mechanism (Ent, By_Descriptor_UBSB);
6381 elsif Mech_Name_Id = Name_Descriptor
6382 and then Chars (Class) = Name_UBA
6384 Set_Mechanism (Ent, By_Descriptor_UBA);
6386 elsif Mech_Name_Id = Name_Descriptor
6387 and then Chars (Class) = Name_S
6389 Set_Mechanism (Ent, By_Descriptor_S);
6391 elsif Mech_Name_Id = Name_Descriptor
6392 and then Chars (Class) = Name_SB
6394 Set_Mechanism (Ent, By_Descriptor_SB);
6396 elsif Mech_Name_Id = Name_Descriptor
6397 and then Chars (Class) = Name_A
6399 Set_Mechanism (Ent, By_Descriptor_A);
6401 elsif Mech_Name_Id = Name_Descriptor
6402 and then Chars (Class) = Name_NCA
6404 Set_Mechanism (Ent, By_Descriptor_NCA);
6406 elsif Mech_Name_Id = Name_Short_Descriptor
6407 and then Chars (Class) = Name_UBS
6409 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6411 elsif Mech_Name_Id = Name_Short_Descriptor
6412 and then Chars (Class) = Name_UBSB
6414 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6416 elsif Mech_Name_Id = Name_Short_Descriptor
6417 and then Chars (Class) = Name_UBA
6419 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6421 elsif Mech_Name_Id = Name_Short_Descriptor
6422 and then Chars (Class) = Name_S
6424 Set_Mechanism (Ent, By_Short_Descriptor_S);
6426 elsif Mech_Name_Id = Name_Short_Descriptor
6427 and then Chars (Class) = Name_SB
6429 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6431 elsif Mech_Name_Id = Name_Short_Descriptor
6432 and then Chars (Class) = Name_A
6434 Set_Mechanism (Ent, By_Short_Descriptor_A);
6436 elsif Mech_Name_Id = Name_Short_Descriptor
6437 and then Chars (Class) = Name_NCA
6439 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6444 end Set_Mechanism_Value;
6446 --------------------------
6447 -- Set_Rational_Profile --
6448 --------------------------
6450 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
6451 -- and extension to the semantics of renaming declarations.
6453 procedure Set_Rational_Profile is
6455 Implicit_Packing := True;
6456 Overriding_Renamings := True;
6457 Use_VADS_Size := True;
6458 end Set_Rational_Profile;
6460 ---------------------------
6461 -- Set_Ravenscar_Profile --
6462 ---------------------------
6464 -- The tasks to be done here are
6466 -- Set required policies
6468 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6469 -- pragma Locking_Policy (Ceiling_Locking)
6471 -- Set Detect_Blocking mode
6473 -- Set required restrictions (see System.Rident for detailed list)
6475 -- Set the No_Dependence rules
6476 -- No_Dependence => Ada.Asynchronous_Task_Control
6477 -- No_Dependence => Ada.Calendar
6478 -- No_Dependence => Ada.Execution_Time.Group_Budget
6479 -- No_Dependence => Ada.Execution_Time.Timers
6480 -- No_Dependence => Ada.Task_Attributes
6481 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6483 procedure Set_Ravenscar_Profile (N : Node_Id) is
6484 Prefix_Entity : Entity_Id;
6485 Selector_Entity : Entity_Id;
6486 Prefix_Node : Node_Id;
6490 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6492 if Task_Dispatching_Policy /= ' '
6493 and then Task_Dispatching_Policy /= 'F'
6495 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6496 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6498 -- Set the FIFO_Within_Priorities policy, but always preserve
6499 -- System_Location since we like the error message with the run time
6503 Task_Dispatching_Policy := 'F';
6505 if Task_Dispatching_Policy_Sloc /= System_Location then
6506 Task_Dispatching_Policy_Sloc := Loc;
6510 -- pragma Locking_Policy (Ceiling_Locking)
6512 if Locking_Policy /= ' '
6513 and then Locking_Policy /= 'C'
6515 Error_Msg_Sloc := Locking_Policy_Sloc;
6516 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6518 -- Set the Ceiling_Locking policy, but preserve System_Location since
6519 -- we like the error message with the run time name.
6522 Locking_Policy := 'C';
6524 if Locking_Policy_Sloc /= System_Location then
6525 Locking_Policy_Sloc := Loc;
6529 -- pragma Detect_Blocking
6531 Detect_Blocking := True;
6533 -- Set the corresponding restrictions
6535 Set_Profile_Restrictions
6536 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6538 -- Set the No_Dependence restrictions
6540 -- The following No_Dependence restrictions:
6541 -- No_Dependence => Ada.Asynchronous_Task_Control
6542 -- No_Dependence => Ada.Calendar
6543 -- No_Dependence => Ada.Task_Attributes
6544 -- are already set by previous call to Set_Profile_Restrictions.
6546 -- Set the following restrictions which were added to Ada 2005:
6547 -- No_Dependence => Ada.Execution_Time.Group_Budget
6548 -- No_Dependence => Ada.Execution_Time.Timers
6550 if Ada_Version >= Ada_2005 then
6551 Name_Buffer (1 .. 3) := "ada";
6554 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6556 Name_Buffer (1 .. 14) := "execution_time";
6559 Selector_Entity := Make_Identifier (Loc, Name_Find);
6562 Make_Selected_Component
6564 Prefix => Prefix_Entity,
6565 Selector_Name => Selector_Entity);
6567 Name_Buffer (1 .. 13) := "group_budgets";
6570 Selector_Entity := Make_Identifier (Loc, Name_Find);
6573 Make_Selected_Component
6575 Prefix => Prefix_Node,
6576 Selector_Name => Selector_Entity);
6578 Set_Restriction_No_Dependence
6580 Warn => Treat_Restrictions_As_Warnings,
6581 Profile => Ravenscar);
6583 Name_Buffer (1 .. 6) := "timers";
6586 Selector_Entity := Make_Identifier (Loc, Name_Find);
6589 Make_Selected_Component
6591 Prefix => Prefix_Node,
6592 Selector_Name => Selector_Entity);
6594 Set_Restriction_No_Dependence
6596 Warn => Treat_Restrictions_As_Warnings,
6597 Profile => Ravenscar);
6600 -- Set the following restrictions which was added to Ada 2012 (see
6602 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6604 if Ada_Version >= Ada_2012 then
6605 Name_Buffer (1 .. 6) := "system";
6608 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6610 Name_Buffer (1 .. 15) := "multiprocessors";
6613 Selector_Entity := Make_Identifier (Loc, Name_Find);
6616 Make_Selected_Component
6618 Prefix => Prefix_Entity,
6619 Selector_Name => Selector_Entity);
6621 Name_Buffer (1 .. 19) := "dispatching_domains";
6624 Selector_Entity := Make_Identifier (Loc, Name_Find);
6627 Make_Selected_Component
6629 Prefix => Prefix_Node,
6630 Selector_Name => Selector_Entity);
6632 Set_Restriction_No_Dependence
6634 Warn => Treat_Restrictions_As_Warnings,
6635 Profile => Ravenscar);
6637 end Set_Ravenscar_Profile;
6643 procedure S14_Pragma is
6645 if not Formal_Extensions then
6646 Error_Pragma ("pragma% requires the use of debug switch -gnatd.V");
6650 -- Start of processing for Analyze_Pragma
6653 -- The following code is a defense against recursion. Not clear that
6654 -- this can happen legitimately, but perhaps some error situations
6655 -- can cause it, and we did see this recursion during testing.
6657 if Analyzed (N) then
6660 Set_Analyzed (N, True);
6663 -- Deal with unrecognized pragma
6665 Pname := Pragma_Name (N);
6667 if not Is_Pragma_Name (Pname) then
6668 if Warn_On_Unrecognized_Pragma then
6669 Error_Msg_Name_1 := Pname;
6670 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
6672 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6673 if Is_Bad_Spelling_Of (Pname, PN) then
6674 Error_Msg_Name_1 := PN;
6675 Error_Msg_N -- CODEFIX
6676 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
6685 -- Here to start processing for recognized pragma
6687 Prag_Id := Get_Pragma_Id (Pname);
6689 if Present (Corresponding_Aspect (N)) then
6690 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6701 if Present (Pragma_Argument_Associations (N)) then
6702 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6703 Arg1 := First (Pragma_Argument_Associations (N));
6705 if Present (Arg1) then
6706 Arg2 := Next (Arg1);
6708 if Present (Arg2) then
6709 Arg3 := Next (Arg2);
6711 if Present (Arg3) then
6712 Arg4 := Next (Arg3);
6718 -- An enumeration type defines the pragmas that are supported by the
6719 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6720 -- into the corresponding enumeration value for the following case.
6728 -- pragma Abort_Defer;
6730 when Pragma_Abort_Defer =>
6732 Check_Arg_Count (0);
6734 -- The only required semantic processing is to check the
6735 -- placement. This pragma must appear at the start of the
6736 -- statement sequence of a handled sequence of statements.
6738 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6739 or else N /= First (Statements (Parent (N)))
6744 --------------------
6745 -- Abstract_State --
6746 --------------------
6748 -- pragma Abstract_State (ABSTRACT_STATE_LIST)
6750 -- ABSTRACT_STATE_LIST ::=
6752 -- | STATE_NAME_WITH_PROPERTIES {, STATE_NAME_WITH_PROPERTIES}
6754 -- STATE_NAME_WITH_PROPERTIES ::=
6756 -- | (STATE_NAME with PROPERTY_LIST)
6758 -- PROPERTY_LIST ::= PROPERTY {, PROPERTY}
6759 -- PROPERTY ::= SIMPLE_PROPERTY | NAME_VALUE_PROPERTY
6761 -- SIMPLE_PROPERTY ::= IDENTIFIER
6762 -- NAME_VALUE_PROPERTY ::= IDENTIFIER => EXPRESSION
6764 -- STATE_NAME ::= DEFINING_IDENTIFIER
6766 when Pragma_Abstract_State => Abstract_State : declare
6767 Pack_Id : Entity_Id;
6769 -- Flags used to verify the consistency of states
6771 Non_Null_Seen : Boolean := False;
6772 Null_Seen : Boolean := False;
6774 procedure Analyze_Abstract_State (State : Node_Id);
6775 -- Verify the legality of a single state declaration. Create and
6776 -- decorate a state abstraction entity and introduce it into the
6777 -- visibility chain.
6779 ----------------------------
6780 -- Analyze_Abstract_State --
6781 ----------------------------
6783 procedure Analyze_Abstract_State (State : Node_Id) is
6784 procedure Check_Duplicate_Property
6786 Status : in out Boolean);
6787 -- Flag Status denotes whether a particular property has been
6788 -- seen while processing a state. This routine verifies that
6789 -- Prop is not a duplicate property and sets the flag Status.
6791 ------------------------------
6792 -- Check_Duplicate_Property --
6793 ------------------------------
6795 procedure Check_Duplicate_Property
6797 Status : in out Boolean)
6801 Error_Msg_N ("duplicate state property", Prop);
6805 end Check_Duplicate_Property;
6809 Errors : constant Nat := Serious_Errors_Detected;
6810 Loc : constant Source_Ptr := Sloc (State);
6813 Is_Null : Boolean := False;
6814 Level : Uint := Uint_0;
6818 -- Flags used to verify the consistency of properties
6820 Input_Seen : Boolean := False;
6821 Integrity_Seen : Boolean := False;
6822 Output_Seen : Boolean := False;
6823 Volatile_Seen : Boolean := False;
6825 -- Start of processing for Analyze_Abstract_State
6828 -- A package with a null abstract state is not allowed to
6829 -- declare additional states.
6832 Error_Msg_Name_1 := Chars (Pack_Id);
6833 Error_Msg_N ("package % has null abstract state", State);
6835 -- Null states appear as internally generated entities
6837 elsif Nkind (State) = N_Null then
6838 Name := New_Internal_Name ('S');
6842 -- Catch a case where a null state appears in a list of
6845 if Non_Null_Seen then
6846 Error_Msg_Name_1 := Chars (Pack_Id);
6848 ("package % has non-null abstract state", State);
6851 -- Simple state declaration
6853 elsif Nkind (State) = N_Identifier then
6854 Name := Chars (State);
6855 Non_Null_Seen := True;
6857 -- State declaration with various properties. This construct
6858 -- appears as an extension aggregate in the tree.
6860 elsif Nkind (State) = N_Extension_Aggregate then
6861 if Nkind (Ancestor_Part (State)) = N_Identifier then
6862 Name := Chars (Ancestor_Part (State));
6863 Non_Null_Seen := True;
6866 ("state name must be an identifier",
6867 Ancestor_Part (State));
6870 -- Process properties Input, Output and Volatile. Ensure
6871 -- that none of them appear more than once.
6873 Prop := First (Expressions (State));
6874 while Present (Prop) loop
6875 if Nkind (Prop) = N_Identifier then
6876 if Chars (Prop) = Name_Input then
6877 Check_Duplicate_Property (Prop, Input_Seen);
6878 elsif Chars (Prop) = Name_Output then
6879 Check_Duplicate_Property (Prop, Output_Seen);
6880 elsif Chars (Prop) = Name_Volatile then
6881 Check_Duplicate_Property (Prop, Volatile_Seen);
6883 Error_Msg_N ("invalid state property", Prop);
6886 Error_Msg_N ("invalid state property", Prop);
6892 -- Volatile requires exactly one Input or Output
6896 ((Input_Seen and then Output_Seen) -- both
6898 (not Input_Seen and then not Output_Seen)) -- none
6901 ("property Volatile requires exactly one Input or "
6905 -- Either Input or Output require Volatile
6907 if (Input_Seen or Output_Seen)
6908 and then not Volatile_Seen
6911 ("properties Input and Output require Volatile", State);
6914 -- State property Integrity appears as a component
6917 Assoc := First (Component_Associations (State));
6918 while Present (Assoc) loop
6919 Prop := First (Choices (Assoc));
6920 while Present (Prop) loop
6921 if Nkind (Prop) = N_Identifier
6922 and then Chars (Prop) = Name_Integrity
6924 Check_Duplicate_Property (Prop, Integrity_Seen);
6926 Error_Msg_N ("invalid state property", Prop);
6932 if Nkind (Expression (Assoc)) = N_Integer_Literal then
6933 Level := Intval (Expression (Assoc));
6936 ("integrity level must be an integer literal",
6937 Expression (Assoc));
6943 -- Any other attempt to declare a state is erroneous
6946 Error_Msg_N ("malformed abstract state declaration", State);
6949 -- Do not generate a state abstraction entity if it was not
6950 -- properly declared.
6952 if Serious_Errors_Detected > Errors then
6956 -- The generated state abstraction reuses the same characters
6957 -- from the original state declaration. Decorate the entity.
6959 Id := Make_Defining_Identifier (Loc, New_External_Name (Name));
6960 Set_Comes_From_Source (Id, not Is_Null);
6961 Set_Parent (Id, State);
6962 Set_Ekind (Id, E_Abstract_State);
6963 Set_Etype (Id, Standard_Void_Type);
6964 Set_Integrity_Level (Id, Level);
6965 Set_Refined_State (Id, Empty);
6967 -- Every non-null state must be nameable and resolvable the
6968 -- same way a constant is.
6971 Push_Scope (Pack_Id);
6976 -- Associate the state with its related package
6978 if No (Abstract_States (Pack_Id)) then
6979 Set_Abstract_States (Pack_Id, New_Elmt_List);
6982 Append_Elmt (Id, Abstract_States (Pack_Id));
6983 end Analyze_Abstract_State;
6990 -- Start of processing for Abstract_State
6995 Check_Arg_Count (1);
6997 -- Ensure the proper placement of the pragma. Abstract states must
6998 -- be associated with a package declaration.
7000 if From_Aspect_Specification (N) then
7001 Par := Parent (Corresponding_Aspect (N));
7003 Par := Parent (Parent (N));
7006 if Nkind (Par) = N_Compilation_Unit then
7010 if Nkind (Par) /= N_Package_Declaration then
7015 Pack_Id := Defining_Unit_Name (Specification (Par));
7016 State := Expression (Arg1);
7018 -- Multiple abstract states appear as an aggregate
7020 if Nkind (State) = N_Aggregate then
7021 State := First (Expressions (State));
7022 while Present (State) loop
7023 Analyze_Abstract_State (State);
7028 -- Various forms of a single abstract state. Note that these may
7029 -- include malformed state declarations.
7032 Analyze_Abstract_State (State);
7042 -- Note: this pragma also has some specific processing in Par.Prag
7043 -- because we want to set the Ada version mode during parsing.
7045 when Pragma_Ada_83 =>
7047 Check_Arg_Count (0);
7049 -- We really should check unconditionally for proper configuration
7050 -- pragma placement, since we really don't want mixed Ada modes
7051 -- within a single unit, and the GNAT reference manual has always
7052 -- said this was a configuration pragma, but we did not check and
7053 -- are hesitant to add the check now.
7055 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
7056 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
7057 -- or Ada 2012 mode.
7059 if Ada_Version >= Ada_2005 then
7060 Check_Valid_Configuration_Pragma;
7063 -- Now set Ada 83 mode
7065 Ada_Version := Ada_83;
7066 Ada_Version_Explicit := Ada_Version;
7074 -- Note: this pragma also has some specific processing in Par.Prag
7075 -- because we want to set the Ada 83 version mode during parsing.
7077 when Pragma_Ada_95 =>
7079 Check_Arg_Count (0);
7081 -- We really should check unconditionally for proper configuration
7082 -- pragma placement, since we really don't want mixed Ada modes
7083 -- within a single unit, and the GNAT reference manual has always
7084 -- said this was a configuration pragma, but we did not check and
7085 -- are hesitant to add the check now.
7087 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
7088 -- or Ada 95, so we must check if we are in Ada 2005 mode.
7090 if Ada_Version >= Ada_2005 then
7091 Check_Valid_Configuration_Pragma;
7094 -- Now set Ada 95 mode
7096 Ada_Version := Ada_95;
7097 Ada_Version_Explicit := Ada_Version;
7099 ---------------------
7100 -- Ada_05/Ada_2005 --
7101 ---------------------
7104 -- pragma Ada_05 (LOCAL_NAME);
7107 -- pragma Ada_2005 (LOCAL_NAME):
7109 -- Note: these pragmas also have some specific processing in Par.Prag
7110 -- because we want to set the Ada 2005 version mode during parsing.
7112 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
7118 if Arg_Count = 1 then
7119 Check_Arg_Is_Local_Name (Arg1);
7120 E_Id := Get_Pragma_Arg (Arg1);
7122 if Etype (E_Id) = Any_Type then
7126 Set_Is_Ada_2005_Only (Entity (E_Id));
7127 Record_Rep_Item (Entity (E_Id), N);
7130 Check_Arg_Count (0);
7132 -- For Ada_2005 we unconditionally enforce the documented
7133 -- configuration pragma placement, since we do not want to
7134 -- tolerate mixed modes in a unit involving Ada 2005. That
7135 -- would cause real difficulties for those cases where there
7136 -- are incompatibilities between Ada 95 and Ada 2005.
7138 Check_Valid_Configuration_Pragma;
7140 -- Now set appropriate Ada mode
7142 Ada_Version := Ada_2005;
7143 Ada_Version_Explicit := Ada_2005;
7147 ---------------------
7148 -- Ada_12/Ada_2012 --
7149 ---------------------
7152 -- pragma Ada_12 (LOCAL_NAME);
7155 -- pragma Ada_2012 (LOCAL_NAME):
7157 -- Note: these pragmas also have some specific processing in Par.Prag
7158 -- because we want to set the Ada 2012 version mode during parsing.
7160 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
7166 if Arg_Count = 1 then
7167 Check_Arg_Is_Local_Name (Arg1);
7168 E_Id := Get_Pragma_Arg (Arg1);
7170 if Etype (E_Id) = Any_Type then
7174 Set_Is_Ada_2012_Only (Entity (E_Id));
7175 Record_Rep_Item (Entity (E_Id), N);
7178 Check_Arg_Count (0);
7180 -- For Ada_2012 we unconditionally enforce the documented
7181 -- configuration pragma placement, since we do not want to
7182 -- tolerate mixed modes in a unit involving Ada 2012. That
7183 -- would cause real difficulties for those cases where there
7184 -- are incompatibilities between Ada 95 and Ada 2012. We could
7185 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
7187 Check_Valid_Configuration_Pragma;
7189 -- Now set appropriate Ada mode
7191 Ada_Version := Ada_2012;
7192 Ada_Version_Explicit := Ada_2012;
7196 ----------------------
7197 -- All_Calls_Remote --
7198 ----------------------
7200 -- pragma All_Calls_Remote [(library_package_NAME)];
7202 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
7203 Lib_Entity : Entity_Id;
7206 Check_Ada_83_Warning;
7207 Check_Valid_Library_Unit_Pragma;
7209 if Nkind (N) = N_Null_Statement then
7213 Lib_Entity := Find_Lib_Unit_Name;
7215 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
7217 if Present (Lib_Entity)
7218 and then not Debug_Flag_U
7220 if not Is_Remote_Call_Interface (Lib_Entity) then
7221 Error_Pragma ("pragma% only apply to rci unit");
7223 -- Set flag for entity of the library unit
7226 Set_Has_All_Calls_Remote (Lib_Entity);
7230 end All_Calls_Remote;
7236 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
7237 -- ARG ::= NAME | EXPRESSION
7239 -- The first two arguments are by convention intended to refer to an
7240 -- external tool and a tool-specific function. These arguments are
7243 when Pragma_Annotate => Annotate : declare
7249 Check_At_Least_N_Arguments (1);
7250 Check_Arg_Is_Identifier (Arg1);
7251 Check_No_Identifiers;
7254 -- Second parameter is optional, it is never analyzed
7259 -- Here if we have a second parameter
7262 -- Second parameter must be identifier
7264 Check_Arg_Is_Identifier (Arg2);
7266 -- Process remaining parameters if any
7269 while Present (Arg) loop
7270 Exp := Get_Pragma_Arg (Arg);
7273 if Is_Entity_Name (Exp) then
7276 -- For string literals, we assume Standard_String as the
7277 -- type, unless the string contains wide or wide_wide
7280 elsif Nkind (Exp) = N_String_Literal then
7281 if Has_Wide_Wide_Character (Exp) then
7282 Resolve (Exp, Standard_Wide_Wide_String);
7283 elsif Has_Wide_Character (Exp) then
7284 Resolve (Exp, Standard_Wide_String);
7286 Resolve (Exp, Standard_String);
7289 elsif Is_Overloaded (Exp) then
7291 ("ambiguous argument for pragma%", Exp);
7302 ---------------------------
7303 -- Assert/Assert_And_Cut --
7304 ---------------------------
7307 -- ( [Check => ] Boolean_EXPRESSION
7308 -- [, [Message =>] Static_String_EXPRESSION]);
7310 -- pragma Assert_And_Cut
7311 -- ( [Check => ] Boolean_EXPRESSION
7312 -- [, [Message =>] Static_String_EXPRESSION]);
7314 when Pragma_Assert | Pragma_Assert_And_Cut => Assert : declare
7319 if Prag_Id = Pragma_Assert then
7321 else -- Pragma_Assert_And_Cut
7326 Check_At_Least_N_Arguments (1);
7327 Check_At_Most_N_Arguments (2);
7328 Check_Arg_Order ((Name_Check, Name_Message));
7329 Check_Optional_Identifier (Arg1, Name_Check);
7331 -- We treat pragma Assert as equivalent to:
7333 -- pragma Check (Assertion, condition [, msg]);
7335 -- So rewrite pragma in this manner, transfer the message
7336 -- argument if present, and analyze the result
7338 -- Pragma Assert_And_Cut is treated exactly like pragma Assert by
7339 -- the frontend. Formal verification tools may use it to "cut" the
7340 -- paths through the code, to make verification tractable. When
7341 -- dealing with a semantically analyzed tree, the information that
7342 -- a Check node N corresponds to a source Assert_And_Cut pragma
7343 -- can be retrieved from the pragma kind of Original_Node(N).
7345 Expr := Get_Pragma_Arg (Arg1);
7347 Make_Pragma_Argument_Association (Loc,
7348 Expression => Make_Identifier (Loc, Name_Assertion)),
7350 Make_Pragma_Argument_Association (Sloc (Expr),
7351 Expression => Expr));
7353 if Arg_Count > 1 then
7354 Check_Optional_Identifier (Arg2, Name_Message);
7355 Append_To (Newa, New_Copy_Tree (Arg2));
7360 Chars => Name_Check,
7361 Pragma_Argument_Associations => Newa));
7365 ----------------------
7366 -- Assertion_Policy --
7367 ----------------------
7369 -- pragma Assertion_Policy (Check | Disable | Ignore)
7371 when Pragma_Assertion_Policy => Assertion_Policy : declare
7376 Check_Valid_Configuration_Pragma;
7377 Check_Arg_Count (1);
7378 Check_No_Identifiers;
7379 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7381 -- We treat pragma Assertion_Policy as equivalent to:
7383 -- pragma Check_Policy (Assertion, policy)
7385 -- So rewrite the pragma in that manner and link on to the chain
7386 -- of Check_Policy pragmas, marking the pragma as analyzed.
7388 Policy := Get_Pragma_Arg (Arg1);
7392 Chars => Name_Check_Policy,
7393 Pragma_Argument_Associations => New_List (
7394 Make_Pragma_Argument_Association (Loc,
7395 Expression => Make_Identifier (Loc, Name_Assertion)),
7397 Make_Pragma_Argument_Association (Loc,
7399 Make_Identifier (Sloc (Policy), Chars (Policy))))));
7402 Set_Next_Pragma (N, Opt.Check_Policy_List);
7403 Opt.Check_Policy_List := N;
7404 end Assertion_Policy;
7410 -- pragma Assume (boolean_EXPRESSION);
7412 when Pragma_Assume => Assume : declare
7416 Check_Arg_Count (1);
7418 -- Pragma Assume is transformed into pragma Check in the following
7421 -- pragma Check (Assume, Expr);
7425 Chars => Name_Check,
7426 Pragma_Argument_Associations => New_List (
7427 Make_Pragma_Argument_Association (Loc,
7428 Expression => Make_Identifier (Loc, Name_Assume)),
7430 Make_Pragma_Argument_Association (Loc,
7431 Expression => Relocate_Node (Expression (Arg1))))));
7435 ------------------------------
7436 -- Assume_No_Invalid_Values --
7437 ------------------------------
7439 -- pragma Assume_No_Invalid_Values (On | Off);
7441 when Pragma_Assume_No_Invalid_Values =>
7443 Check_Valid_Configuration_Pragma;
7444 Check_Arg_Count (1);
7445 Check_No_Identifiers;
7446 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7448 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
7449 Assume_No_Invalid_Values := True;
7451 Assume_No_Invalid_Values := False;
7454 --------------------------
7455 -- Attribute_Definition --
7456 --------------------------
7458 -- pragma Attribute_Definition
7459 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
7460 -- [Entity =>] LOCAL_NAME,
7461 -- [Expression =>] EXPRESSION | NAME);
7463 when Pragma_Attribute_Definition => Attribute_Definition : declare
7464 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
7469 Check_Arg_Count (3);
7470 Check_Optional_Identifier (Arg1, "attribute");
7471 Check_Optional_Identifier (Arg2, "entity");
7472 Check_Optional_Identifier (Arg3, "expression");
7474 if Nkind (Attribute_Designator) /= N_Identifier then
7475 Error_Msg_N ("attribute name expected", Attribute_Designator);
7479 Check_Arg_Is_Local_Name (Arg2);
7481 -- If the attribute is not recognized, then issue a warning (not
7482 -- an error), and ignore the pragma.
7484 Aname := Chars (Attribute_Designator);
7486 if not Is_Attribute_Name (Aname) then
7487 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
7491 -- Otherwise, rewrite the pragma as an attribute definition clause
7494 Make_Attribute_Definition_Clause (Loc,
7495 Name => Get_Pragma_Arg (Arg2),
7497 Expression => Get_Pragma_Arg (Arg3)));
7499 end Attribute_Definition;
7505 -- pragma AST_Entry (entry_IDENTIFIER);
7507 when Pragma_AST_Entry => AST_Entry : declare
7513 Check_Arg_Count (1);
7514 Check_No_Identifiers;
7515 Check_Arg_Is_Local_Name (Arg1);
7516 Ent := Entity (Get_Pragma_Arg (Arg1));
7518 -- Note: the implementation of the AST_Entry pragma could handle
7519 -- the entry family case fine, but for now we are consistent with
7520 -- the DEC rules, and do not allow the pragma, which of course
7521 -- has the effect of also forbidding the attribute.
7523 if Ekind (Ent) /= E_Entry then
7525 ("pragma% argument must be simple entry name", Arg1);
7527 elsif Is_AST_Entry (Ent) then
7529 ("duplicate % pragma for entry", Arg1);
7531 elsif Has_Homonym (Ent) then
7533 ("pragma% argument cannot specify overloaded entry", Arg1);
7537 FF : constant Entity_Id := First_Formal (Ent);
7540 if Present (FF) then
7541 if Present (Next_Formal (FF)) then
7543 ("entry for pragma% can have only one argument",
7546 elsif Parameter_Mode (FF) /= E_In_Parameter then
7548 ("entry parameter for pragma% must have mode IN",
7554 Set_Is_AST_Entry (Ent);
7562 -- pragma Asynchronous (LOCAL_NAME);
7564 when Pragma_Asynchronous => Asynchronous : declare
7572 procedure Process_Async_Pragma;
7573 -- Common processing for procedure and access-to-procedure case
7575 --------------------------
7576 -- Process_Async_Pragma --
7577 --------------------------
7579 procedure Process_Async_Pragma is
7582 Set_Is_Asynchronous (Nm);
7586 -- The formals should be of mode IN (RM E.4.1(6))
7589 while Present (S) loop
7590 Formal := Defining_Identifier (S);
7592 if Nkind (Formal) = N_Defining_Identifier
7593 and then Ekind (Formal) /= E_In_Parameter
7596 ("pragma% procedure can only have IN parameter",
7603 Set_Is_Asynchronous (Nm);
7604 end Process_Async_Pragma;
7606 -- Start of processing for pragma Asynchronous
7609 Check_Ada_83_Warning;
7610 Check_No_Identifiers;
7611 Check_Arg_Count (1);
7612 Check_Arg_Is_Local_Name (Arg1);
7614 if Debug_Flag_U then
7618 C_Ent := Cunit_Entity (Current_Sem_Unit);
7619 Analyze (Get_Pragma_Arg (Arg1));
7620 Nm := Entity (Get_Pragma_Arg (Arg1));
7622 if not Is_Remote_Call_Interface (C_Ent)
7623 and then not Is_Remote_Types (C_Ent)
7625 -- This pragma should only appear in an RCI or Remote Types
7626 -- unit (RM E.4.1(4)).
7629 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
7632 if Ekind (Nm) = E_Procedure
7633 and then Nkind (Parent (Nm)) = N_Procedure_Specification
7635 if not Is_Remote_Call_Interface (Nm) then
7637 ("pragma% cannot be applied on non-remote procedure",
7641 L := Parameter_Specifications (Parent (Nm));
7642 Process_Async_Pragma;
7645 elsif Ekind (Nm) = E_Function then
7647 ("pragma% cannot be applied to function", Arg1);
7649 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
7650 if Is_Record_Type (Nm) then
7652 -- A record type that is the Equivalent_Type for a remote
7653 -- access-to-subprogram type.
7655 N := Declaration_Node (Corresponding_Remote_Type (Nm));
7658 -- A non-expanded RAS type (distribution is not enabled)
7660 N := Declaration_Node (Nm);
7663 if Nkind (N) = N_Full_Type_Declaration
7664 and then Nkind (Type_Definition (N)) =
7665 N_Access_Procedure_Definition
7667 L := Parameter_Specifications (Type_Definition (N));
7668 Process_Async_Pragma;
7670 if Is_Asynchronous (Nm)
7671 and then Expander_Active
7672 and then Get_PCS_Name /= Name_No_DSA
7674 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
7679 ("pragma% cannot reference access-to-function type",
7683 -- Only other possibility is Access-to-class-wide type
7685 elsif Is_Access_Type (Nm)
7686 and then Is_Class_Wide_Type (Designated_Type (Nm))
7688 Check_First_Subtype (Arg1);
7689 Set_Is_Asynchronous (Nm);
7690 if Expander_Active then
7691 RACW_Type_Is_Asynchronous (Nm);
7695 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
7703 -- pragma Atomic (LOCAL_NAME);
7705 when Pragma_Atomic =>
7706 Process_Atomic_Shared_Volatile;
7708 -----------------------
7709 -- Atomic_Components --
7710 -----------------------
7712 -- pragma Atomic_Components (array_LOCAL_NAME);
7714 -- This processing is shared by Volatile_Components
7716 when Pragma_Atomic_Components |
7717 Pragma_Volatile_Components =>
7719 Atomic_Components : declare
7726 Check_Ada_83_Warning;
7727 Check_No_Identifiers;
7728 Check_Arg_Count (1);
7729 Check_Arg_Is_Local_Name (Arg1);
7730 E_Id := Get_Pragma_Arg (Arg1);
7732 if Etype (E_Id) = Any_Type then
7738 Check_Duplicate_Pragma (E);
7740 if Rep_Item_Too_Early (E, N)
7742 Rep_Item_Too_Late (E, N)
7747 D := Declaration_Node (E);
7750 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7752 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7753 and then Nkind (D) = N_Object_Declaration
7754 and then Nkind (Object_Definition (D)) =
7755 N_Constrained_Array_Definition)
7757 -- The flag is set on the object, or on the base type
7759 if Nkind (D) /= N_Object_Declaration then
7763 Set_Has_Volatile_Components (E);
7765 if Prag_Id = Pragma_Atomic_Components then
7766 Set_Has_Atomic_Components (E);
7770 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7772 end Atomic_Components;
7774 --------------------
7775 -- Attach_Handler --
7776 --------------------
7778 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7780 when Pragma_Attach_Handler =>
7781 Check_Ada_83_Warning;
7782 Check_No_Identifiers;
7783 Check_Arg_Count (2);
7785 if No_Run_Time_Mode then
7786 Error_Msg_CRT ("Attach_Handler pragma", N);
7788 Check_Interrupt_Or_Attach_Handler;
7790 -- The expression that designates the attribute may depend on a
7791 -- discriminant, and is therefore a per-object expression, to
7792 -- be expanded in the init proc. If expansion is enabled, then
7793 -- perform semantic checks on a copy only.
7795 if Expander_Active then
7797 Temp : constant Node_Id :=
7798 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7800 Set_Parent (Temp, N);
7801 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7805 Analyze (Get_Pragma_Arg (Arg2));
7806 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7809 Process_Interrupt_Or_Attach_Handler;
7812 --------------------
7813 -- C_Pass_By_Copy --
7814 --------------------
7816 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7818 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7824 Check_Valid_Configuration_Pragma;
7825 Check_Arg_Count (1);
7826 Check_Optional_Identifier (Arg1, "max_size");
7828 Arg := Get_Pragma_Arg (Arg1);
7829 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7831 Val := Expr_Value (Arg);
7835 ("maximum size for pragma% must be positive", Arg1);
7837 elsif UI_Is_In_Int_Range (Val) then
7838 Default_C_Record_Mechanism := UI_To_Int (Val);
7840 -- If a giant value is given, Int'Last will do well enough.
7841 -- If sometime someone complains that a record larger than
7842 -- two gigabytes is not copied, we will worry about it then!
7845 Default_C_Record_Mechanism := Mechanism_Type'Last;
7853 -- pragma Check ([Name =>] IDENTIFIER,
7854 -- [Check =>] Boolean_EXPRESSION
7855 -- [,[Message =>] String_EXPRESSION]);
7857 when Pragma_Check => Check : declare
7864 -- Set True if category of assertions referenced by Name enabled
7868 Check_At_Least_N_Arguments (2);
7869 Check_At_Most_N_Arguments (3);
7870 Check_Optional_Identifier (Arg1, Name_Name);
7871 Check_Optional_Identifier (Arg2, Name_Check);
7873 if Arg_Count = 3 then
7874 Check_Optional_Identifier (Arg3, Name_Message);
7875 Str := Get_Pragma_Arg (Arg3);
7878 Check_Arg_Is_Identifier (Arg1);
7879 Cname := Chars (Get_Pragma_Arg (Arg1));
7880 Check_On := Check_Enabled (Cname);
7881 Expr := Get_Pragma_Arg (Arg2);
7883 -- Deal with SCO generation
7886 when Name_Predicate |
7889 -- Nothing to do: since checks occur in client units,
7890 -- the SCO for the aspect in the declaration unit is
7891 -- conservatively always enabled.
7897 if Check_On and then not Split_PPC (N) then
7899 -- Mark pragma/aspect SCO as enabled
7901 Set_SCO_Pragma_Enabled (Loc);
7905 -- Deal with analyzing the string argument.
7907 if Arg_Count = 3 then
7909 -- If checks are not on we don't want any expansion (since
7910 -- such expansion would not get properly deleted) but
7911 -- we do want to analyze (to get proper references).
7912 -- The Preanalyze_And_Resolve routine does just what we want
7914 if not Check_On then
7915 Preanalyze_And_Resolve (Str, Standard_String);
7917 -- Otherwise we need a proper analysis and expansion
7920 Analyze_And_Resolve (Str, Standard_String);
7924 -- Now you might think we could just do the same with the Boolean
7925 -- expression if checks are off (and expansion is on) and then
7926 -- rewrite the check as a null statement. This would work but we
7927 -- would lose the useful warnings about an assertion being bound
7928 -- to fail even if assertions are turned off.
7930 -- So instead we wrap the boolean expression in an if statement
7933 -- if False and then condition then
7937 -- The reason we do this rewriting during semantic analysis
7938 -- rather than as part of normal expansion is that we cannot
7939 -- analyze and expand the code for the boolean expression
7940 -- directly, or it may cause insertion of actions that would
7941 -- escape the attempt to suppress the check code.
7943 -- Note that the Sloc for the if statement corresponds to the
7944 -- argument condition, not the pragma itself. The reason for
7945 -- this is that we may generate a warning if the condition is
7946 -- False at compile time, and we do not want to delete this
7947 -- warning when we delete the if statement.
7949 if Expander_Active and not Check_On then
7950 Eloc := Sloc (Expr);
7953 Make_If_Statement (Eloc,
7955 Make_And_Then (Eloc,
7956 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7957 Right_Opnd => Expr),
7958 Then_Statements => New_List (
7959 Make_Null_Statement (Eloc))));
7961 In_Assertion_Expr := In_Assertion_Expr + 1;
7963 In_Assertion_Expr := In_Assertion_Expr - 1;
7965 -- Check is active or expansion not active. In these cases we can
7966 -- just go ahead and analyze the boolean with no worries.
7969 In_Assertion_Expr := In_Assertion_Expr + 1;
7970 Analyze_And_Resolve (Expr, Any_Boolean);
7971 In_Assertion_Expr := In_Assertion_Expr - 1;
7975 --------------------------
7976 -- Check_Float_Overflow --
7977 --------------------------
7979 -- pragma Check_Float_Overflow;
7981 when Pragma_Check_Float_Overflow =>
7983 Check_Valid_Configuration_Pragma;
7984 Check_Arg_Count (0);
7985 Check_Float_Overflow := True;
7991 -- pragma Check_Name (check_IDENTIFIER);
7993 when Pragma_Check_Name =>
7994 Check_No_Identifiers;
7996 Check_Valid_Configuration_Pragma;
7997 Check_Arg_Count (1);
7998 Check_Arg_Is_Identifier (Arg1);
8001 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
8004 for J in Check_Names.First .. Check_Names.Last loop
8005 if Check_Names.Table (J) = Nam then
8010 Check_Names.Append (Nam);
8017 -- pragma Check_Policy (
8018 -- [Name =>] IDENTIFIER,
8019 -- [Policy =>] POLICY_IDENTIFIER);
8021 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
8023 -- Note: this is a configuration pragma, but it is allowed to appear
8026 when Pragma_Check_Policy =>
8028 Check_Arg_Count (2);
8029 Check_Optional_Identifier (Arg1, Name_Name);
8030 Check_Optional_Identifier (Arg2, Name_Policy);
8032 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
8034 -- A Check_Policy pragma can appear either as a configuration
8035 -- pragma, or in a declarative part or a package spec (see RM
8036 -- 11.5(5) for rules for Suppress/Unsuppress which are also
8037 -- followed for Check_Policy).
8039 if not Is_Configuration_Pragma then
8040 Check_Is_In_Decl_Part_Or_Package_Spec;
8043 Set_Next_Pragma (N, Opt.Check_Policy_List);
8044 Opt.Check_Policy_List := N;
8046 ---------------------
8047 -- CIL_Constructor --
8048 ---------------------
8050 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
8052 -- Processing for this pragma is shared with Java_Constructor
8058 -- pragma Comment (static_string_EXPRESSION)
8060 -- Processing for pragma Comment shares the circuitry for pragma
8061 -- Ident. The only differences are that Ident enforces a limit of 31
8062 -- characters on its argument, and also enforces limitations on
8063 -- placement for DEC compatibility. Pragma Comment shares neither of
8064 -- these restrictions.
8070 -- pragma Common_Object (
8071 -- [Internal =>] LOCAL_NAME
8072 -- [, [External =>] EXTERNAL_SYMBOL]
8073 -- [, [Size =>] EXTERNAL_SYMBOL]);
8075 -- Processing for this pragma is shared with Psect_Object
8077 ------------------------
8078 -- Compile_Time_Error --
8079 ------------------------
8081 -- pragma Compile_Time_Error
8082 -- (boolean_EXPRESSION, static_string_EXPRESSION);
8084 when Pragma_Compile_Time_Error =>
8086 Process_Compile_Time_Warning_Or_Error;
8088 --------------------------
8089 -- Compile_Time_Warning --
8090 --------------------------
8092 -- pragma Compile_Time_Warning
8093 -- (boolean_EXPRESSION, static_string_EXPRESSION);
8095 when Pragma_Compile_Time_Warning =>
8097 Process_Compile_Time_Warning_Or_Error;
8103 when Pragma_Compiler_Unit =>
8105 Check_Arg_Count (0);
8106 Set_Is_Compiler_Unit (Get_Source_Unit (N));
8108 -----------------------------
8109 -- Complete_Representation --
8110 -----------------------------
8112 -- pragma Complete_Representation;
8114 when Pragma_Complete_Representation =>
8116 Check_Arg_Count (0);
8118 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
8120 ("pragma & must appear within record representation clause");
8123 ----------------------------
8124 -- Complex_Representation --
8125 ----------------------------
8127 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
8129 when Pragma_Complex_Representation => Complex_Representation : declare
8136 Check_Arg_Count (1);
8137 Check_Optional_Identifier (Arg1, Name_Entity);
8138 Check_Arg_Is_Local_Name (Arg1);
8139 E_Id := Get_Pragma_Arg (Arg1);
8141 if Etype (E_Id) = Any_Type then
8147 if not Is_Record_Type (E) then
8149 ("argument for pragma% must be record type", Arg1);
8152 Ent := First_Entity (E);
8155 or else No (Next_Entity (Ent))
8156 or else Present (Next_Entity (Next_Entity (Ent)))
8157 or else not Is_Floating_Point_Type (Etype (Ent))
8158 or else Etype (Ent) /= Etype (Next_Entity (Ent))
8161 ("record for pragma% must have two fields of the same "
8162 & "floating-point type", Arg1);
8165 Set_Has_Complex_Representation (Base_Type (E));
8167 -- We need to treat the type has having a non-standard
8168 -- representation, for back-end purposes, even though in
8169 -- general a complex will have the default representation
8170 -- of a record with two real components.
8172 Set_Has_Non_Standard_Rep (Base_Type (E));
8174 end Complex_Representation;
8176 -------------------------
8177 -- Component_Alignment --
8178 -------------------------
8180 -- pragma Component_Alignment (
8181 -- [Form =>] ALIGNMENT_CHOICE
8182 -- [, [Name =>] type_LOCAL_NAME]);
8184 -- ALIGNMENT_CHOICE ::=
8186 -- | Component_Size_4
8190 when Pragma_Component_Alignment => Component_AlignmentP : declare
8191 Args : Args_List (1 .. 2);
8192 Names : constant Name_List (1 .. 2) := (
8196 Form : Node_Id renames Args (1);
8197 Name : Node_Id renames Args (2);
8199 Atype : Component_Alignment_Kind;
8204 Gather_Associations (Names, Args);
8207 Error_Pragma ("missing Form argument for pragma%");
8210 Check_Arg_Is_Identifier (Form);
8212 -- Get proper alignment, note that Default = Component_Size on all
8213 -- machines we have so far, and we want to set this value rather
8214 -- than the default value to indicate that it has been explicitly
8215 -- set (and thus will not get overridden by the default component
8216 -- alignment for the current scope)
8218 if Chars (Form) = Name_Component_Size then
8219 Atype := Calign_Component_Size;
8221 elsif Chars (Form) = Name_Component_Size_4 then
8222 Atype := Calign_Component_Size_4;
8224 elsif Chars (Form) = Name_Default then
8225 Atype := Calign_Component_Size;
8227 elsif Chars (Form) = Name_Storage_Unit then
8228 Atype := Calign_Storage_Unit;
8232 ("invalid Form parameter for pragma%", Form);
8235 -- Case with no name, supplied, affects scope table entry
8239 (Scope_Stack.Last).Component_Alignment_Default := Atype;
8241 -- Case of name supplied
8244 Check_Arg_Is_Local_Name (Name);
8246 Typ := Entity (Name);
8249 or else Rep_Item_Too_Early (Typ, N)
8253 Typ := Underlying_Type (Typ);
8256 if not Is_Record_Type (Typ)
8257 and then not Is_Array_Type (Typ)
8260 ("Name parameter of pragma% must identify record or "
8261 & "array type", Name);
8264 -- An explicit Component_Alignment pragma overrides an
8265 -- implicit pragma Pack, but not an explicit one.
8267 if not Has_Pragma_Pack (Base_Type (Typ)) then
8268 Set_Is_Packed (Base_Type (Typ), False);
8269 Set_Component_Alignment (Base_Type (Typ), Atype);
8272 end Component_AlignmentP;
8278 -- pragma Contract_Case
8279 -- ([Name =>] Static_String_EXPRESSION
8280 -- ,[Mode =>] MODE_TYPE
8281 -- [, Requires => Boolean_EXPRESSION]
8282 -- [, Ensures => Boolean_EXPRESSION]);
8284 -- MODE_TYPE ::= Nominal | Robustness
8286 when Pragma_Contract_Case =>
8287 Check_Contract_Or_Test_Case;
8289 --------------------
8290 -- Contract_Cases --
8291 --------------------
8293 -- pragma Contract_Cases (CONTRACT_CASE_LIST);
8295 -- CONTRACT_CASE_LIST ::= CONTRACT_CASE {, CONTRACT_CASE}
8297 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
8299 -- CASE_GUARD ::= boolean_EXPRESSION | others
8301 -- CONSEQUENCE ::= boolean_EXPRESSION
8303 when Pragma_Contract_Cases => Contract_Cases : declare
8304 procedure Chain_Contract_Cases (Subp_Decl : Node_Id);
8305 -- Chain pragma Contract_Cases to the contract of a subprogram.
8306 -- Subp_Decl is the declaration of the subprogram.
8308 --------------------------
8309 -- Chain_Contract_Cases --
8310 --------------------------
8312 procedure Chain_Contract_Cases (Subp_Decl : Node_Id) is
8313 Subp : constant Entity_Id :=
8314 Defining_Unit_Name (Specification (Subp_Decl));
8318 Check_Duplicate_Pragma (Subp);
8319 CTC := Spec_CTC_List (Contract (Subp));
8320 while Present (CTC) loop
8321 if Chars (Pragma_Identifier (CTC)) = Pname then
8322 Error_Msg_Name_1 := Pname;
8323 Error_Msg_Sloc := Sloc (CTC);
8325 if From_Aspect_Specification (CTC) then
8327 ("aspect% for & previously given#", N, Subp);
8330 ("pragma% for & duplicates pragma#", N, Subp);
8336 CTC := Next_Pragma (CTC);
8339 -- Prepend pragma Contract_Cases to the contract
8341 Set_Next_Pragma (N, Spec_CTC_List (Contract (Subp)));
8342 Set_Spec_CTC_List (Contract (Subp), N);
8343 end Chain_Contract_Cases;
8347 Case_Guard : Node_Id;
8350 Others_Seen : Boolean := False;
8351 Contract_Case : Node_Id;
8352 Subp_Decl : Node_Id;
8354 -- Start of processing for Contract_Cases
8359 Check_Arg_Count (1);
8361 -- Completely ignore if disabled
8363 if not Check_Enabled (Pname) then
8364 Rewrite (N, Make_Null_Statement (Loc));
8369 -- Check the placement of the pragma
8371 if not Is_List_Member (N) then
8375 -- Pragma Contract_Cases must be associated with a subprogram
8378 while Present (Prev (Decl)) loop
8379 Decl := Prev (Decl);
8381 if Nkind (Decl) in N_Generic_Declaration then
8384 Subp_Decl := Original_Node (Decl);
8387 -- Skip prior pragmas
8389 if Nkind (Subp_Decl) = N_Pragma then
8392 -- Skip internally generated code
8394 elsif not Comes_From_Source (Subp_Decl) then
8397 -- We have found the related subprogram
8399 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
8400 N_Subprogram_Declaration)
8409 -- All contract cases must appear as an aggregate
8411 if Nkind (Expression (Arg1)) /= N_Aggregate then
8412 Error_Pragma ("wrong syntax for pragma %");
8416 -- Verify the legality of individual contract cases
8419 First (Component_Associations (Expression (Arg1)));
8420 while Present (Contract_Case) loop
8421 if Nkind (Contract_Case) /= N_Component_Association then
8423 ("wrong syntax in contract case", Contract_Case);
8427 Case_Guard := First (Choices (Contract_Case));
8429 -- Each contract case must have exactly on case guard
8431 Extra := Next (Case_Guard);
8432 if Present (Extra) then
8434 ("contract case may have only one case guard", Extra);
8438 -- Check the placement of "others" (if available)
8440 if Nkind (Case_Guard) = N_Others_Choice then
8443 ("only one others choice allowed in pragma %",
8447 Others_Seen := True;
8450 elsif Others_Seen then
8452 ("others must be the last choice in pragma %", N);
8456 Next (Contract_Case);
8459 Chain_Contract_Cases (Subp_Decl);
8466 -- pragma Controlled (first_subtype_LOCAL_NAME);
8468 when Pragma_Controlled => Controlled : declare
8472 Check_No_Identifiers;
8473 Check_Arg_Count (1);
8474 Check_Arg_Is_Local_Name (Arg1);
8475 Arg := Get_Pragma_Arg (Arg1);
8477 if not Is_Entity_Name (Arg)
8478 or else not Is_Access_Type (Entity (Arg))
8480 Error_Pragma_Arg ("pragma% requires access type", Arg1);
8482 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
8490 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
8491 -- [Entity =>] LOCAL_NAME);
8493 when Pragma_Convention => Convention : declare
8496 pragma Warnings (Off, C);
8497 pragma Warnings (Off, E);
8499 Check_Arg_Order ((Name_Convention, Name_Entity));
8500 Check_Ada_83_Warning;
8501 Check_Arg_Count (2);
8502 Process_Convention (C, E);
8505 ---------------------------
8506 -- Convention_Identifier --
8507 ---------------------------
8509 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
8510 -- [Convention =>] convention_IDENTIFIER);
8512 when Pragma_Convention_Identifier => Convention_Identifier : declare
8518 Check_Arg_Order ((Name_Name, Name_Convention));
8519 Check_Arg_Count (2);
8520 Check_Optional_Identifier (Arg1, Name_Name);
8521 Check_Optional_Identifier (Arg2, Name_Convention);
8522 Check_Arg_Is_Identifier (Arg1);
8523 Check_Arg_Is_Identifier (Arg2);
8524 Idnam := Chars (Get_Pragma_Arg (Arg1));
8525 Cname := Chars (Get_Pragma_Arg (Arg2));
8527 if Is_Convention_Name (Cname) then
8528 Record_Convention_Identifier
8529 (Idnam, Get_Convention_Id (Cname));
8532 ("second arg for % pragma must be convention", Arg2);
8534 end Convention_Identifier;
8540 -- pragma CPP_Class ([Entity =>] local_NAME)
8542 when Pragma_CPP_Class => CPP_Class : declare
8546 if Warn_On_Obsolescent_Feature then
8548 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
8549 & "effect; replace it by pragma import?j?", N);
8552 Check_Arg_Count (1);
8556 Chars => Name_Import,
8557 Pragma_Argument_Associations => New_List (
8558 Make_Pragma_Argument_Association (Loc,
8559 Expression => Make_Identifier (Loc, Name_CPP)),
8560 New_Copy (First (Pragma_Argument_Associations (N))))));
8564 ---------------------
8565 -- CPP_Constructor --
8566 ---------------------
8568 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
8569 -- [, [External_Name =>] static_string_EXPRESSION ]
8570 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8572 when Pragma_CPP_Constructor => CPP_Constructor : declare
8576 Tag_Typ : Entity_Id;
8580 Check_At_Least_N_Arguments (1);
8581 Check_At_Most_N_Arguments (3);
8582 Check_Optional_Identifier (Arg1, Name_Entity);
8583 Check_Arg_Is_Local_Name (Arg1);
8585 Id := Get_Pragma_Arg (Arg1);
8586 Find_Program_Unit_Name (Id);
8588 -- If we did not find the name, we are done
8590 if Etype (Id) = Any_Type then
8594 Def_Id := Entity (Id);
8596 -- Check if already defined as constructor
8598 if Is_Constructor (Def_Id) then
8600 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
8604 if Ekind (Def_Id) = E_Function
8605 and then (Is_CPP_Class (Etype (Def_Id))
8606 or else (Is_Class_Wide_Type (Etype (Def_Id))
8608 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
8610 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
8612 ("'C'P'P constructor must be defined in the scope of "
8613 & "its returned type", Arg1);
8616 if Arg_Count >= 2 then
8617 Set_Imported (Def_Id);
8618 Set_Is_Public (Def_Id);
8619 Process_Interface_Name (Def_Id, Arg2, Arg3);
8622 Set_Has_Completion (Def_Id);
8623 Set_Is_Constructor (Def_Id);
8624 Set_Convention (Def_Id, Convention_CPP);
8626 -- Imported C++ constructors are not dispatching primitives
8627 -- because in C++ they don't have a dispatch table slot.
8628 -- However, in Ada the constructor has the profile of a
8629 -- function that returns a tagged type and therefore it has
8630 -- been treated as a primitive operation during semantic
8631 -- analysis. We now remove it from the list of primitive
8632 -- operations of the type.
8634 if Is_Tagged_Type (Etype (Def_Id))
8635 and then not Is_Class_Wide_Type (Etype (Def_Id))
8636 and then Is_Dispatching_Operation (Def_Id)
8638 Tag_Typ := Etype (Def_Id);
8640 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
8641 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
8645 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
8646 Set_Is_Dispatching_Operation (Def_Id, False);
8649 -- For backward compatibility, if the constructor returns a
8650 -- class wide type, and we internally change the return type to
8651 -- the corresponding root type.
8653 if Is_Class_Wide_Type (Etype (Def_Id)) then
8654 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
8658 ("pragma% requires function returning a 'C'P'P_Class type",
8661 end CPP_Constructor;
8667 when Pragma_CPP_Virtual => CPP_Virtual : declare
8671 if Warn_On_Obsolescent_Feature then
8673 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has no "
8682 when Pragma_CPP_Vtable => CPP_Vtable : declare
8686 if Warn_On_Obsolescent_Feature then
8688 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has no "
8697 -- pragma CPU (EXPRESSION);
8699 when Pragma_CPU => CPU : declare
8700 P : constant Node_Id := Parent (N);
8706 Check_No_Identifiers;
8707 Check_Arg_Count (1);
8711 if Nkind (P) = N_Subprogram_Body then
8712 Check_In_Main_Program;
8714 Arg := Get_Pragma_Arg (Arg1);
8715 Analyze_And_Resolve (Arg, Any_Integer);
8717 Ent := Defining_Unit_Name (Specification (P));
8719 if Nkind (Ent) = N_Defining_Program_Unit_Name then
8720 Ent := Defining_Identifier (Ent);
8725 if not Is_Static_Expression (Arg) then
8726 Flag_Non_Static_Expr
8727 ("main subprogram affinity is not static!", Arg);
8730 -- If constraint error, then we already signalled an error
8732 elsif Raises_Constraint_Error (Arg) then
8735 -- Otherwise check in range
8739 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
8740 -- This is the entity System.Multiprocessors.CPU_Range;
8742 Val : constant Uint := Expr_Value (Arg);
8745 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
8747 Val > Expr_Value (Type_High_Bound (CPU_Id))
8750 ("main subprogram CPU is out of range", Arg1);
8756 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8760 elsif Nkind (P) = N_Task_Definition then
8761 Arg := Get_Pragma_Arg (Arg1);
8762 Ent := Defining_Identifier (Parent (P));
8764 -- The expression must be analyzed in the special manner
8765 -- described in "Handling of Default and Per-Object
8766 -- Expressions" in sem.ads.
8768 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
8770 -- Anything else is incorrect
8776 -- Check duplicate pragma before we chain the pragma in the Rep
8777 -- Item chain of Ent.
8779 Check_Duplicate_Pragma (Ent);
8780 Record_Rep_Item (Ent, N);
8787 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
8789 when Pragma_Debug => Debug : declare
8796 -- Skip analysis if disabled
8798 if Debug_Pragmas_Disabled then
8799 Rewrite (N, Make_Null_Statement (Loc));
8806 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
8809 if Debug_Pragmas_Enabled then
8810 Set_SCO_Pragma_Enabled (Loc);
8813 if Arg_Count = 2 then
8816 Left_Opnd => Relocate_Node (Cond),
8817 Right_Opnd => Get_Pragma_Arg (Arg1));
8818 Call := Get_Pragma_Arg (Arg2);
8820 Call := Get_Pragma_Arg (Arg1);
8824 N_Indexed_Component,
8828 N_Selected_Component)
8830 -- If this pragma Debug comes from source, its argument was
8831 -- parsed as a name form (which is syntactically identical).
8832 -- In a generic context a parameterless call will be left as
8833 -- an expanded name (if global) or selected_component if local.
8834 -- Change it to a procedure call statement now.
8836 Change_Name_To_Procedure_Call_Statement (Call);
8838 elsif Nkind (Call) = N_Procedure_Call_Statement then
8840 -- Already in the form of a procedure call statement: nothing
8841 -- to do (could happen in case of an internally generated
8847 -- All other cases: diagnose error
8850 ("argument of pragma ""Debug"" is not procedure call",
8855 -- Rewrite into a conditional with an appropriate condition. We
8856 -- wrap the procedure call in a block so that overhead from e.g.
8857 -- use of the secondary stack does not generate execution overhead
8858 -- for suppressed conditions.
8860 -- Normally the analysis that follows will freeze the subprogram
8861 -- being called. However, if the call is to a null procedure,
8862 -- we want to freeze it before creating the block, because the
8863 -- analysis that follows may be done with expansion disabled, in
8864 -- which case the body will not be generated, leading to spurious
8867 if Nkind (Call) = N_Procedure_Call_Statement
8868 and then Is_Entity_Name (Name (Call))
8870 Analyze (Name (Call));
8871 Freeze_Before (N, Entity (Name (Call)));
8874 Rewrite (N, Make_Implicit_If_Statement (N,
8876 Then_Statements => New_List (
8877 Make_Block_Statement (Loc,
8878 Handled_Statement_Sequence =>
8879 Make_Handled_Sequence_Of_Statements (Loc,
8880 Statements => New_List (Relocate_Node (Call)))))));
8888 -- pragma Debug_Policy (Check | Ignore)
8890 when Pragma_Debug_Policy =>
8892 Check_Arg_Count (1);
8893 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
8894 Debug_Pragmas_Enabled :=
8895 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
8896 Debug_Pragmas_Disabled :=
8897 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
8903 -- pragma Depends (DEPENDENCY_RELATION);
8905 -- DEPENDENCY_RELATION ::=
8907 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
8909 -- DEPENDENCY_CLAUSE ::= OUTPUT_LIST =>[+] INPUT_LIST
8911 -- OUTPUT_LIST ::= null | OUTPUT | (OUTPUT {, OUTPUT})
8913 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
8915 -- OUTPUT ::= NAME | FUNCTION_RESULT
8918 -- where FUNCTION_RESULT is a function Result attribute_reference
8920 when Pragma_Depends => Depends : declare
8921 All_Inputs_Seen : Elist_Id := No_Elist;
8922 -- A list containing the entities of all the inputs processed so
8923 -- far. This Elist is populated with unique entities because the
8924 -- same input may appear in multiple input lists.
8926 Global_Seen : Boolean := False;
8927 -- A flag set when pragma Global has been processed
8929 Outputs_Seen : Elist_Id := No_Elist;
8930 -- A list containing the entities of all the outputs processed so
8931 -- far. The elements of this list may come from different output
8934 Null_Output_Seen : Boolean := False;
8935 -- A flag used to track the legality of a null output
8937 Result_Seen : Boolean := False;
8938 -- A flag set when Subp_Id'Result is processed
8940 Subp_Id : Entity_Id;
8941 -- The entity of the subprogram subject to pragma Depends
8943 Subp_Inputs : Elist_Id := No_Elist;
8944 Subp_Outputs : Elist_Id := No_Elist;
8945 -- Two lists containing the full set of inputs and output of the
8946 -- related subprograms. Note that these lists contain both nodes
8949 procedure Analyze_Dependency_Clause
8952 -- Verify the legality of a single dependency clause. Flag Is_Last
8953 -- denotes whether Clause is the last clause in the relation.
8957 Item_Id : Entity_Id) return Boolean;
8958 -- Determine whether a particular item appears in a mixed list of
8959 -- nodes and entities.
8961 procedure Check_Function_Return;
8962 -- Verify that Funtion'Result appears as one of the outputs
8964 procedure Check_Mode
8966 Item_Id : Entity_Id;
8967 Is_Input : Boolean);
8968 -- Ensure that an item has a proper "in", "in out" or "out" mode
8969 -- depending on its function. If this is not the case, emit an
8972 procedure Check_Usage
8973 (Subp_List : Elist_Id;
8974 Item_List : Elist_Id;
8975 Is_Input : Boolean);
8976 -- Verify that all items from list Subp_List appear in Item_List.
8977 -- Emit an error if this is not the case.
8979 procedure Collect_Subprogram_Inputs_Outputs;
8980 -- Gather all inputs and outputs of the subprogram. These are the
8981 -- formal parameters and entities classified in pragma Global.
8983 procedure Normalize_Clause (Clause : Node_Id);
8984 -- Remove a self-dependency "+" from the input list of a clause.
8985 -- Depending on the contents of the relation, either split the
8986 -- the clause into multiple smaller clauses or perform the
8987 -- normalization in place.
8989 -------------------------------
8990 -- Analyze_Dependency_Clause --
8991 -------------------------------
8993 procedure Analyze_Dependency_Clause
8997 procedure Analyze_Input_List (Inputs : Node_Id);
8998 -- Verify the legality of a single input list
9000 procedure Analyze_Input_Output
9003 Top_Level : Boolean;
9004 Seen : in out Elist_Id;
9005 Null_Seen : in out Boolean);
9006 -- Verify the legality of a single input or output item. Flag
9007 -- Is_Input should be set whenever Item is an input, False when
9008 -- it denotes an output. Flag Top_Level should be set whenever
9009 -- Item appears immediately within an input or output list.
9010 -- Seen is a collection of all abstract states, variables and
9011 -- formals processed so far. Flag Null_Seen denotes whether a
9012 -- null input or output has been encountered.
9014 ------------------------
9015 -- Analyze_Input_List --
9016 ------------------------
9018 procedure Analyze_Input_List (Inputs : Node_Id) is
9019 Inputs_Seen : Elist_Id := No_Elist;
9020 -- A list containing the entities of all inputs that appear
9021 -- in the current input list.
9023 Null_Input_Seen : Boolean := False;
9024 -- A flag used to track the legality of a null input
9029 -- Multiple inputs appear as an aggregate
9031 if Nkind (Inputs) = N_Aggregate then
9032 if Present (Component_Associations (Inputs)) then
9034 ("nested dependency relations not allowed", Inputs);
9036 elsif Present (Expressions (Inputs)) then
9037 Input := First (Expressions (Inputs));
9038 while Present (Input) loop
9039 Analyze_Input_Output
9043 Seen => Inputs_Seen,
9044 Null_Seen => Null_Input_Seen);
9051 ("malformed input dependency list", Inputs);
9054 -- Process a solitary input
9057 Analyze_Input_Output
9061 Seen => Inputs_Seen,
9062 Null_Seen => Null_Input_Seen);
9064 end Analyze_Input_List;
9066 --------------------------
9067 -- Analyze_Input_Output --
9068 --------------------------
9070 procedure Analyze_Input_Output
9073 Top_Level : Boolean;
9074 Seen : in out Elist_Id;
9075 Null_Seen : in out Boolean)
9077 Is_Output : constant Boolean := not Is_Input;
9079 Item_Id : Entity_Id;
9082 -- Multiple input or output items appear as an aggregate
9084 if Nkind (Item) = N_Aggregate then
9085 if not Top_Level then
9087 ("nested grouping of items not allowed", Item);
9089 elsif Present (Component_Associations (Item)) then
9091 ("nested dependency relations not allowed", Item);
9093 -- Recursively analyze the grouped items
9095 elsif Present (Expressions (Item)) then
9096 Grouped := First (Expressions (Item));
9097 while Present (Grouped) loop
9098 Analyze_Input_Output
9100 Is_Input => Is_Input,
9103 Null_Seen => Null_Seen);
9109 Error_Msg_N ("malformed dependency list", Item);
9112 -- Process Function'Result in the context of a dependency
9115 elsif Nkind (Item) = N_Attribute_Reference
9116 and then Attribute_Name (Item) = Name_Result
9118 -- It is sufficent to analyze the prefix of 'Result in
9119 -- order to establish legality of the attribute.
9121 Analyze (Prefix (Item));
9123 -- The prefix of 'Result must denote the function for
9124 -- which aspect/pragma Depends applies.
9126 if not Is_Entity_Name (Prefix (Item))
9127 or else Ekind (Subp_Id) /= E_Function
9128 or else Entity (Prefix (Item)) /= Subp_Id
9130 Error_Msg_Name_1 := Name_Result;
9132 ("prefix of attribute % must denote the enclosing "
9133 & "function", Item);
9135 -- Function'Result is allowed to appear on the output
9136 -- side of a dependency clause.
9140 ("function result cannot act as input", Item);
9143 Result_Seen := True;
9146 -- Detect multiple uses of null in a single dependency list
9147 -- or throughout the whole relation. Verify the placement of
9148 -- a null output list relative to the other clauses.
9150 elsif Nkind (Item) = N_Null then
9153 ("multiple null dependency relations not allowed",
9158 if Is_Output and then not Is_Last then
9160 ("null output list must be the last clause in "
9161 & "a dependency relation", Item);
9170 -- Find the entity of the item. If this is a renaming,
9171 -- climb the renaming chain to reach the root object.
9172 -- Renamings of non-entire objects do not yield an
9175 Item_Id := Entity_Of (Item);
9177 if Present (Item_Id) then
9178 if Ekind_In (Item_Id, E_Abstract_State,
9184 -- Ensure that the item is of the correct mode
9185 -- depending on its function.
9187 Check_Mode (Item, Item_Id, Is_Input);
9189 -- Detect multiple uses of the same state, variable
9190 -- or formal parameter. If this is not the case,
9191 -- add the item to the list of processed relations.
9193 if Contains (Seen, Item_Id) then
9194 Error_Msg_N ("duplicate use of item", Item);
9196 Add_Item (Item_Id, Seen);
9199 -- Detect an illegal use of an input related to a
9200 -- null output. Such input items cannot appear in
9201 -- other input lists.
9204 and then Contains (All_Inputs_Seen, Item_Id)
9207 ("input of a null output list appears in "
9208 & "multiple input lists", Item);
9210 Add_Item (Item_Id, All_Inputs_Seen);
9213 -- When the item renames an entire object, replace
9214 -- the item with a reference to the object.
9216 if Present (Renamed_Object (Entity (Item))) then
9218 New_Reference_To (Item_Id, Sloc (Item)));
9222 -- All other input/output items are illegal
9226 ("item must denote variable, state or formal "
9227 & "parameter", Item);
9230 -- All other input/output items are illegal
9234 ("item must denote variable, state or formal "
9235 & "parameter", Item);
9238 end Analyze_Input_Output;
9245 -- Start of processing for Analyze_Dependency_Clause
9248 -- Process the output_list of a dependency_clause
9250 Output := First (Choices (Clause));
9251 while Present (Output) loop
9252 Analyze_Input_Output
9256 Seen => Outputs_Seen,
9257 Null_Seen => Null_Output_Seen);
9262 -- Process the input_list of a dependency_clause
9264 Inputs := Expression (Clause);
9266 -- An input list with a self-dependency appears as operator "+"
9267 -- where the actuals inputs are the right operand.
9269 if Nkind (Inputs) = N_Op_Plus then
9270 Inputs := Right_Opnd (Inputs);
9273 Analyze_Input_List (Inputs);
9274 end Analyze_Dependency_Clause;
9282 Item_Id : Entity_Id) return Boolean
9288 if Present (List) then
9289 Elmt := First_Elmt (List);
9290 while Present (Elmt) loop
9291 if Nkind (Node (Elmt)) = N_Defining_Identifier then
9294 Id := Entity (Node (Elmt));
9297 if Id = Item_Id then
9308 ----------------------------
9309 -- Check_Function_Return --
9310 ----------------------------
9312 procedure Check_Function_Return is
9314 if Ekind (Subp_Id) = E_Function and then not Result_Seen then
9316 ("result of & must appear in exactly one output list",
9319 end Check_Function_Return;
9325 procedure Check_Mode
9327 Item_Id : Entity_Id;
9332 if Ekind (Item_Id) = E_Out_Parameter
9333 or else (Global_Seen
9334 and then not Appears_In (Subp_Inputs, Item_Id))
9337 ("item & must have mode in or in out", Item, Item_Id);
9343 if Ekind (Item_Id) = E_In_Parameter
9346 and then not Appears_In (Subp_Outputs, Item_Id))
9349 ("item & must have mode out or in out", Item, Item_Id);
9358 procedure Check_Usage
9359 (Subp_List : Elist_Id;
9360 Item_List : Elist_Id;
9363 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id);
9364 -- Emit an error concerning the erroneous usage of an item
9370 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id) is
9374 ("item & must appear in at least one input list of "
9375 & "aspect Depends", Item, Item_Id);
9378 ("item & must appear in exactly one output list of "
9379 & "aspect Depends", Item, Item_Id);
9387 Item_Id : Entity_Id;
9389 -- Start of processing for Check_Usage
9392 if No (Subp_List) then
9396 -- Each input or output of the subprogram must appear in a
9397 -- dependency relation.
9399 Elmt := First_Elmt (Subp_List);
9400 while Present (Elmt) loop
9401 Item := Node (Elmt);
9403 if Nkind (Item) = N_Defining_Identifier then
9406 Item_Id := Entity (Item);
9409 -- The item does not appear in a dependency
9411 if not Contains (Item_List, Item_Id) then
9412 if Is_Formal (Item_Id) then
9413 Usage_Error (Item, Item_Id);
9415 -- States and global variables are not used properly only
9416 -- when the subprogram is subject to pragma Global.
9418 elsif Global_Seen then
9419 Usage_Error (Item, Item_Id);
9427 ---------------------------------------
9428 -- Collect_Subprogram_Inputs_Outputs --
9429 ---------------------------------------
9431 procedure Collect_Subprogram_Inputs_Outputs is
9432 procedure Collect_Global_List
9434 Mode : Name_Id := Name_Input);
9435 -- Collect all relevant items from a global list
9437 -------------------------
9438 -- Collect_Global_List --
9439 -------------------------
9441 procedure Collect_Global_List
9443 Mode : Name_Id := Name_Input)
9445 procedure Collect_Global_Item
9448 -- Add an item to the proper subprogram input or output
9451 -------------------------
9452 -- Collect_Global_Item --
9453 -------------------------
9455 procedure Collect_Global_Item
9460 if Mode = Name_In_Out or else Mode = Name_Input then
9461 Add_Item (Item, Subp_Inputs);
9464 if Mode = Name_In_Out or else Mode = Name_Output then
9465 Add_Item (Item, Subp_Outputs);
9467 end Collect_Global_Item;
9474 -- Start of processing for Collect_Global_List
9477 -- Single global item declaration
9479 if Nkind_In (List, N_Identifier, N_Selected_Component) then
9480 Collect_Global_Item (List, Mode);
9482 -- Simple global list or moded global list declaration
9485 if Present (Expressions (List)) then
9486 Item := First (Expressions (List));
9487 while Present (Item) loop
9488 Collect_Global_Item (Item, Mode);
9494 Assoc := First (Component_Associations (List));
9495 while Present (Assoc) loop
9497 (List => Expression (Assoc),
9498 Mode => Chars (First (Choices (Assoc))));
9504 end Collect_Global_List;
9512 -- Start of processing for Collect_Subprogram_Inputs_Outputs
9515 -- Process all formal parameters
9517 Formal := First_Formal (Subp_Id);
9518 while Present (Formal) loop
9519 if Ekind_In (Formal, E_In_Out_Parameter,
9522 Add_Item (Formal, Subp_Inputs);
9525 if Ekind_In (Formal, E_In_Out_Parameter,
9528 Add_Item (Formal, Subp_Outputs);
9531 Next_Formal (Formal);
9534 -- If the subprogram is subject to pragma Global, traverse all
9535 -- global lists and gather the relevant items.
9537 Global := Find_Aspect (Subp_Id, Aspect_Global);
9538 if Present (Global) then
9539 Global_Seen := True;
9541 -- Retrieve the pragma as it contains the analyzed lists
9543 Global := Aspect_Rep_Item (Parent (Global));
9545 -- The pragma may not have been analyzed because of the
9546 -- arbitrary declaration order of aspects. Make sure that
9547 -- it is analyzed for the purposes of item extraction.
9549 if not Analyzed (Global) then
9554 Expression (First (Pragma_Argument_Associations (Global)));
9556 -- Nothing to be done for a null global list
9558 if Nkind (List) /= N_Null then
9559 Collect_Global_List (List);
9562 end Collect_Subprogram_Inputs_Outputs;
9564 ----------------------
9565 -- Normalize_Clause --
9566 ----------------------
9568 procedure Normalize_Clause (Clause : Node_Id) is
9569 procedure Create_Or_Modify_Clause
9575 Multiple : Boolean);
9576 -- Create a brand new clause to represent the self-reference
9577 -- or modify the input and/or output lists of an existing
9578 -- clause. Output denotes a self-referencial output. Outputs
9579 -- is the output list of a clause. Inputs is the input list
9580 -- of a clause. After denotes the clause after which the new
9581 -- clause is to be inserted. Flag In_Place should be set when
9582 -- normalizing the last output of an output list. Flag Multiple
9583 -- should be set when Output comes from a list with multiple
9586 -----------------------------
9587 -- Create_Or_Modify_Clause --
9588 -----------------------------
9590 procedure Create_Or_Modify_Clause
9598 procedure Propagate_Output
9601 -- Handle the various cases of output propagation to the
9602 -- input list. Output denotes a self-referencial output
9603 -- item. Inputs is the input list of a clause.
9605 ----------------------
9606 -- Propagate_Output --
9607 ----------------------
9609 procedure Propagate_Output
9613 function In_Input_List
9615 Inputs : List_Id) return Boolean;
9616 -- Determine whether a particulat item appears in the
9617 -- input list of a clause.
9623 function In_Input_List
9625 Inputs : List_Id) return Boolean
9630 Elmt := First (Inputs);
9631 while Present (Elmt) loop
9632 if Entity_Of (Elmt) = Item then
9644 Output_Id : constant Entity_Id := Entity_Of (Output);
9647 -- Start of processing for Propagate_Output
9650 -- The clause is of the form:
9652 -- (Output =>+ null)
9654 -- Remove the null input and replace it with a copy of
9657 -- (Output => Output)
9659 if Nkind (Inputs) = N_Null then
9660 Rewrite (Inputs, New_Copy_Tree (Output));
9662 -- The clause is of the form:
9664 -- (Output =>+ (Input1, ..., InputN))
9666 -- Determine whether the output is not already mentioned
9667 -- in the input list and if not, add it to the list of
9670 -- (Output => (Output, Input1, ..., InputN))
9672 elsif Nkind (Inputs) = N_Aggregate then
9673 Grouped := Expressions (Inputs);
9675 if not In_Input_List
9679 Prepend_To (Grouped, New_Copy_Tree (Output));
9682 -- The clause is of the form:
9684 -- (Output =>+ Input)
9686 -- If the input does not mention the output, group the
9689 -- (Output => (Output, Input))
9691 elsif Entity_Of (Inputs) /= Output_Id then
9693 Make_Aggregate (Loc,
9694 Expressions => New_List (
9695 New_Copy_Tree (Output),
9696 New_Copy_Tree (Inputs))));
9698 end Propagate_Output;
9702 Loc : constant Source_Ptr := Sloc (Output);
9705 -- Start of processing for Create_Or_Modify_Clause
9708 -- A function result cannot depend on itself because it
9709 -- cannot appear in the input list of a relation.
9711 if Nkind (Output) = N_Attribute_Reference
9712 and then Attribute_Name (Output) = Name_Result
9715 ("function result cannot depend on itself", Output);
9718 -- A null output depending on itself does not require any
9721 elsif Nkind (Output) = N_Null then
9725 -- When performing the transformation in place, simply add
9726 -- the output to the list of inputs (if not already there).
9727 -- This case arises when dealing with the last output of an
9728 -- output list - we perform the normalization in place to
9729 -- avoid generating a malformed tree.
9732 Propagate_Output (Output, Inputs);
9734 -- A list with multiple outputs is slowly trimmed until
9735 -- only one element remains. When this happens, replace
9736 -- the aggregate with the element itself.
9740 Rewrite (Outputs, Output);
9746 -- Unchain the output from its output list as it will
9747 -- appear in a new clause. Note that we cannot simply
9748 -- rewrite the output as null because this will violate
9749 -- the semantics of aspect/pragma Depends.
9753 -- Create a new clause of the form:
9755 -- (Output => Inputs)
9758 Make_Component_Association (Loc,
9759 Choices => New_List (Output),
9760 Expression => New_Copy_Tree (Inputs));
9762 -- The new clause contains replicated content that has
9763 -- already been analyzed. There is not need to reanalyze
9764 -- it or renormalize it again.
9766 Set_Analyzed (Clause);
9769 (Output => First (Choices (Clause)),
9770 Inputs => Expression (Clause));
9772 Insert_After (After, Clause);
9774 end Create_Or_Modify_Clause;
9778 Outputs : constant Node_Id := First (Choices (Clause));
9780 Last_Output : Node_Id;
9781 Next_Output : Node_Id;
9784 -- Start of processing for Normalize_Clause
9787 -- A self-dependency appears as operator "+". Remove the "+"
9788 -- from the tree by moving the real inputs to their proper
9791 if Nkind (Expression (Clause)) = N_Op_Plus then
9793 (Expression (Clause), Right_Opnd (Expression (Clause)));
9794 Inputs := Expression (Clause);
9796 -- Multiple outputs appear as an aggregate
9798 if Nkind (Outputs) = N_Aggregate then
9799 Last_Output := Last (Expressions (Outputs));
9801 Output := First (Expressions (Outputs));
9802 while Present (Output) loop
9804 -- Normalization may remove an output from its list,
9805 -- preserve the subsequent output now.
9807 Next_Output := Next (Output);
9809 Create_Or_Modify_Clause
9814 In_Place => Output = Last_Output,
9817 Output := Next_Output;
9823 Create_Or_Modify_Clause
9832 end Normalize_Clause;
9838 Last_Clause : Node_Id;
9839 Subp_Decl : Node_Id;
9841 -- Start of processing for Depends
9846 Check_Arg_Count (1);
9848 -- Ensure the proper placement of the pragma. Depends must be
9849 -- associated with a subprogram declaration.
9851 Subp_Decl := Parent (Corresponding_Aspect (N));
9853 if Nkind (Subp_Decl) /= N_Subprogram_Declaration then
9858 Subp_Id := Defining_Unit_Name (Specification (Subp_Decl));
9859 Clause := Expression (Arg1);
9861 -- Empty dependency list
9863 if Nkind (Clause) = N_Null then
9865 -- Gather all states, variables and formal parameters that the
9866 -- subprogram may depend on. These items are obtained from the
9867 -- parameter profile or pragma Global (if available).
9869 Collect_Subprogram_Inputs_Outputs;
9871 -- Verify that every input or output of the subprogram appear
9874 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
9875 Check_Usage (Subp_Outputs, Outputs_Seen, False);
9876 Check_Function_Return;
9878 -- Dependency clauses appear as component associations of an
9881 elsif Nkind (Clause) = N_Aggregate
9882 and then Present (Component_Associations (Clause))
9884 Last_Clause := Last (Component_Associations (Clause));
9886 -- Gather all states, variables and formal parameters that the
9887 -- subprogram may depend on. These items are obtained from the
9888 -- parameter profile or pragma Global (if available).
9890 Collect_Subprogram_Inputs_Outputs;
9892 -- Ensure that the formal parameters are visible when analyzing
9893 -- all clauses. This falls out of the general rule of aspects
9894 -- pertaining to subprogram declarations.
9896 Push_Scope (Subp_Id);
9897 Install_Formals (Subp_Id);
9899 Clause := First (Component_Associations (Clause));
9900 while Present (Clause) loop
9901 Errors := Serious_Errors_Detected;
9903 -- Normalization may create extra clauses that contain
9904 -- replicated input and output names. There is no need
9905 -- to reanalyze or renormalize these extra clauses.
9907 if not Analyzed (Clause) then
9908 Set_Analyzed (Clause);
9910 Analyze_Dependency_Clause
9912 Is_Last => Clause = Last_Clause);
9914 -- Do not normalize an erroneous clause because the
9915 -- inputs or outputs may denote illegal items.
9917 if Errors = Serious_Errors_Detected then
9918 Normalize_Clause (Clause);
9927 -- Verify that every input or output of the subprogram appear
9930 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
9931 Check_Usage (Subp_Outputs, Outputs_Seen, False);
9932 Check_Function_Return;
9934 -- The top level dependency relation is malformed
9937 Error_Msg_N ("malformed dependency relation", Clause);
9941 ---------------------
9942 -- Detect_Blocking --
9943 ---------------------
9945 -- pragma Detect_Blocking;
9947 when Pragma_Detect_Blocking =>
9949 Check_Arg_Count (0);
9950 Check_Valid_Configuration_Pragma;
9951 Detect_Blocking := True;
9953 --------------------------
9954 -- Default_Storage_Pool --
9955 --------------------------
9957 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
9959 when Pragma_Default_Storage_Pool =>
9961 Check_Arg_Count (1);
9963 -- Default_Storage_Pool can appear as a configuration pragma, or
9964 -- in a declarative part or a package spec.
9966 if not Is_Configuration_Pragma then
9967 Check_Is_In_Decl_Part_Or_Package_Spec;
9970 -- Case of Default_Storage_Pool (null);
9972 if Nkind (Expression (Arg1)) = N_Null then
9973 Analyze (Expression (Arg1));
9975 -- This is an odd case, this is not really an expression, so
9976 -- we don't have a type for it. So just set the type to Empty.
9978 Set_Etype (Expression (Arg1), Empty);
9980 -- Case of Default_Storage_Pool (storage_pool_NAME);
9983 -- If it's a configuration pragma, then the only allowed
9984 -- argument is "null".
9986 if Is_Configuration_Pragma then
9987 Error_Pragma_Arg ("NULL expected", Arg1);
9990 -- The expected type for a non-"null" argument is
9991 -- Root_Storage_Pool'Class.
9994 (Get_Pragma_Arg (Arg1),
9995 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
9998 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
9999 -- for an access type will use this information to set the
10000 -- appropriate attributes of the access type.
10002 Default_Pool := Expression (Arg1);
10004 ------------------------------------
10005 -- Disable_Atomic_Synchronization --
10006 ------------------------------------
10008 -- pragma Disable_Atomic_Synchronization [(Entity)];
10010 when Pragma_Disable_Atomic_Synchronization =>
10011 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
10013 -------------------
10014 -- Discard_Names --
10015 -------------------
10017 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
10019 when Pragma_Discard_Names => Discard_Names : declare
10024 Check_Ada_83_Warning;
10026 -- Deal with configuration pragma case
10028 if Arg_Count = 0 and then Is_Configuration_Pragma then
10029 Global_Discard_Names := True;
10032 -- Otherwise, check correct appropriate context
10035 Check_Is_In_Decl_Part_Or_Package_Spec;
10037 if Arg_Count = 0 then
10039 -- If there is no parameter, then from now on this pragma
10040 -- applies to any enumeration, exception or tagged type
10041 -- defined in the current declarative part, and recursively
10042 -- to any nested scope.
10044 Set_Discard_Names (Current_Scope);
10048 Check_Arg_Count (1);
10049 Check_Optional_Identifier (Arg1, Name_On);
10050 Check_Arg_Is_Local_Name (Arg1);
10052 E_Id := Get_Pragma_Arg (Arg1);
10054 if Etype (E_Id) = Any_Type then
10057 E := Entity (E_Id);
10060 if (Is_First_Subtype (E)
10062 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
10063 or else Ekind (E) = E_Exception
10065 Set_Discard_Names (E);
10066 Record_Rep_Item (E, N);
10070 ("inappropriate entity for pragma%", Arg1);
10077 ------------------------
10078 -- Dispatching_Domain --
10079 ------------------------
10081 -- pragma Dispatching_Domain (EXPRESSION);
10083 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
10084 P : constant Node_Id := Parent (N);
10090 Check_No_Identifiers;
10091 Check_Arg_Count (1);
10093 -- This pragma is born obsolete, but not the aspect
10095 if not From_Aspect_Specification (N) then
10097 (No_Obsolescent_Features, Pragma_Identifier (N));
10100 if Nkind (P) = N_Task_Definition then
10101 Arg := Get_Pragma_Arg (Arg1);
10102 Ent := Defining_Identifier (Parent (P));
10104 -- The expression must be analyzed in the special manner
10105 -- described in "Handling of Default and Per-Object
10106 -- Expressions" in sem.ads.
10108 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
10110 -- Check duplicate pragma before we chain the pragma in the Rep
10111 -- Item chain of Ent.
10113 Check_Duplicate_Pragma (Ent);
10114 Record_Rep_Item (Ent, N);
10116 -- Anything else is incorrect
10121 end Dispatching_Domain;
10127 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
10129 when Pragma_Elaborate => Elaborate : declare
10134 -- Pragma must be in context items list of a compilation unit
10136 if not Is_In_Context_Clause then
10140 -- Must be at least one argument
10142 if Arg_Count = 0 then
10143 Error_Pragma ("pragma% requires at least one argument");
10146 -- In Ada 83 mode, there can be no items following it in the
10147 -- context list except other pragmas and implicit with clauses
10148 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
10149 -- placement rule does not apply.
10151 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
10153 while Present (Citem) loop
10154 if Nkind (Citem) = N_Pragma
10155 or else (Nkind (Citem) = N_With_Clause
10156 and then Implicit_With (Citem))
10161 ("(Ada 83) pragma% must be at end of context clause");
10168 -- Finally, the arguments must all be units mentioned in a with
10169 -- clause in the same context clause. Note we already checked (in
10170 -- Par.Prag) that the arguments are all identifiers or selected
10174 Outer : while Present (Arg) loop
10175 Citem := First (List_Containing (N));
10176 Inner : while Citem /= N loop
10177 if Nkind (Citem) = N_With_Clause
10178 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
10180 Set_Elaborate_Present (Citem, True);
10181 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
10182 Generate_Reference (Entity (Name (Citem)), Citem);
10184 -- With the pragma present, elaboration calls on
10185 -- subprograms from the named unit need no further
10186 -- checks, as long as the pragma appears in the current
10187 -- compilation unit. If the pragma appears in some unit
10188 -- in the context, there might still be a need for an
10189 -- Elaborate_All_Desirable from the current compilation
10190 -- to the named unit, so we keep the check enabled.
10192 if In_Extended_Main_Source_Unit (N) then
10193 Set_Suppress_Elaboration_Warnings
10194 (Entity (Name (Citem)));
10205 ("argument of pragma% is not withed unit", Arg);
10211 -- Give a warning if operating in static mode with -gnatwl
10212 -- (elaboration warnings enabled) switch set.
10214 if Elab_Warnings and not Dynamic_Elaboration_Checks then
10216 ("?l?use of pragma Elaborate may not be safe", N);
10218 ("?l?use pragma Elaborate_All instead if possible", N);
10222 -------------------
10223 -- Elaborate_All --
10224 -------------------
10226 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
10228 when Pragma_Elaborate_All => Elaborate_All : declare
10233 Check_Ada_83_Warning;
10235 -- Pragma must be in context items list of a compilation unit
10237 if not Is_In_Context_Clause then
10241 -- Must be at least one argument
10243 if Arg_Count = 0 then
10244 Error_Pragma ("pragma% requires at least one argument");
10247 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
10248 -- have to appear at the end of the context clause, but may
10249 -- appear mixed in with other items, even in Ada 83 mode.
10251 -- Final check: the arguments must all be units mentioned in
10252 -- a with clause in the same context clause. Note that we
10253 -- already checked (in Par.Prag) that all the arguments are
10254 -- either identifiers or selected components.
10257 Outr : while Present (Arg) loop
10258 Citem := First (List_Containing (N));
10259 Innr : while Citem /= N loop
10260 if Nkind (Citem) = N_With_Clause
10261 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
10263 Set_Elaborate_All_Present (Citem, True);
10264 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
10266 -- Suppress warnings and elaboration checks on the named
10267 -- unit if the pragma is in the current compilation, as
10268 -- for pragma Elaborate.
10270 if In_Extended_Main_Source_Unit (N) then
10271 Set_Suppress_Elaboration_Warnings
10272 (Entity (Name (Citem)));
10281 Set_Error_Posted (N);
10283 ("argument of pragma% is not withed unit", Arg);
10290 --------------------
10291 -- Elaborate_Body --
10292 --------------------
10294 -- pragma Elaborate_Body [( library_unit_NAME )];
10296 when Pragma_Elaborate_Body => Elaborate_Body : declare
10297 Cunit_Node : Node_Id;
10298 Cunit_Ent : Entity_Id;
10301 Check_Ada_83_Warning;
10302 Check_Valid_Library_Unit_Pragma;
10304 if Nkind (N) = N_Null_Statement then
10308 Cunit_Node := Cunit (Current_Sem_Unit);
10309 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10311 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
10314 Error_Pragma ("pragma% must refer to a spec, not a body");
10316 Set_Body_Required (Cunit_Node, True);
10317 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
10319 -- If we are in dynamic elaboration mode, then we suppress
10320 -- elaboration warnings for the unit, since it is definitely
10321 -- fine NOT to do dynamic checks at the first level (and such
10322 -- checks will be suppressed because no elaboration boolean
10323 -- is created for Elaborate_Body packages).
10325 -- But in the static model of elaboration, Elaborate_Body is
10326 -- definitely NOT good enough to ensure elaboration safety on
10327 -- its own, since the body may WITH other units that are not
10328 -- safe from an elaboration point of view, so a client must
10329 -- still do an Elaborate_All on such units.
10331 -- Debug flag -gnatdD restores the old behavior of 3.13, where
10332 -- Elaborate_Body always suppressed elab warnings.
10334 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
10335 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
10338 end Elaborate_Body;
10340 ------------------------
10341 -- Elaboration_Checks --
10342 ------------------------
10344 -- pragma Elaboration_Checks (Static | Dynamic);
10346 when Pragma_Elaboration_Checks =>
10348 Check_Arg_Count (1);
10349 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
10350 Dynamic_Elaboration_Checks :=
10351 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
10357 -- pragma Eliminate (
10358 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
10359 -- [,[Entity =>] IDENTIFIER |
10360 -- SELECTED_COMPONENT |
10362 -- [, OVERLOADING_RESOLUTION]);
10364 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
10367 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
10368 -- FUNCTION_PROFILE
10370 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
10372 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
10373 -- Result_Type => result_SUBTYPE_NAME]
10375 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
10376 -- SUBTYPE_NAME ::= STRING_LITERAL
10378 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
10379 -- SOURCE_TRACE ::= STRING_LITERAL
10381 when Pragma_Eliminate => Eliminate : declare
10382 Args : Args_List (1 .. 5);
10383 Names : constant Name_List (1 .. 5) := (
10386 Name_Parameter_Types,
10388 Name_Source_Location);
10390 Unit_Name : Node_Id renames Args (1);
10391 Entity : Node_Id renames Args (2);
10392 Parameter_Types : Node_Id renames Args (3);
10393 Result_Type : Node_Id renames Args (4);
10394 Source_Location : Node_Id renames Args (5);
10398 Check_Valid_Configuration_Pragma;
10399 Gather_Associations (Names, Args);
10401 if No (Unit_Name) then
10402 Error_Pragma ("missing Unit_Name argument for pragma%");
10406 and then (Present (Parameter_Types)
10408 Present (Result_Type)
10410 Present (Source_Location))
10412 Error_Pragma ("missing Entity argument for pragma%");
10415 if (Present (Parameter_Types)
10417 Present (Result_Type))
10419 Present (Source_Location)
10422 ("parameter profile and source location cannot be used "
10423 & "together in pragma%");
10426 Process_Eliminate_Pragma
10435 -----------------------------------
10436 -- Enable_Atomic_Synchronization --
10437 -----------------------------------
10439 -- pragma Enable_Atomic_Synchronization [(Entity)];
10441 when Pragma_Enable_Atomic_Synchronization =>
10442 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
10449 -- [ Convention =>] convention_IDENTIFIER,
10450 -- [ Entity =>] local_NAME
10451 -- [, [External_Name =>] static_string_EXPRESSION ]
10452 -- [, [Link_Name =>] static_string_EXPRESSION ]);
10454 when Pragma_Export => Export : declare
10456 Def_Id : Entity_Id;
10458 pragma Warnings (Off, C);
10461 Check_Ada_83_Warning;
10465 Name_External_Name,
10468 Check_At_Least_N_Arguments (2);
10470 Check_At_Most_N_Arguments (4);
10471 Process_Convention (C, Def_Id);
10473 if Ekind (Def_Id) /= E_Constant then
10474 Note_Possible_Modification
10475 (Get_Pragma_Arg (Arg2), Sure => False);
10478 Process_Interface_Name (Def_Id, Arg3, Arg4);
10479 Set_Exported (Def_Id, Arg2);
10481 -- If the entity is a deferred constant, propagate the information
10482 -- to the full view, because gigi elaborates the full view only.
10484 if Ekind (Def_Id) = E_Constant
10485 and then Present (Full_View (Def_Id))
10488 Id2 : constant Entity_Id := Full_View (Def_Id);
10490 Set_Is_Exported (Id2, Is_Exported (Def_Id));
10491 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
10492 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
10497 ----------------------
10498 -- Export_Exception --
10499 ----------------------
10501 -- pragma Export_Exception (
10502 -- [Internal =>] LOCAL_NAME
10503 -- [, [External =>] EXTERNAL_SYMBOL]
10504 -- [, [Form =>] Ada | VMS]
10505 -- [, [Code =>] static_integer_EXPRESSION]);
10507 when Pragma_Export_Exception => Export_Exception : declare
10508 Args : Args_List (1 .. 4);
10509 Names : constant Name_List (1 .. 4) := (
10515 Internal : Node_Id renames Args (1);
10516 External : Node_Id renames Args (2);
10517 Form : Node_Id renames Args (3);
10518 Code : Node_Id renames Args (4);
10523 if Inside_A_Generic then
10524 Error_Pragma ("pragma% cannot be used for generic entities");
10527 Gather_Associations (Names, Args);
10528 Process_Extended_Import_Export_Exception_Pragma (
10529 Arg_Internal => Internal,
10530 Arg_External => External,
10534 if not Is_VMS_Exception (Entity (Internal)) then
10535 Set_Exported (Entity (Internal), Internal);
10537 end Export_Exception;
10539 ---------------------
10540 -- Export_Function --
10541 ---------------------
10543 -- pragma Export_Function (
10544 -- [Internal =>] LOCAL_NAME
10545 -- [, [External =>] EXTERNAL_SYMBOL]
10546 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10547 -- [, [Result_Type =>] TYPE_DESIGNATOR]
10548 -- [, [Mechanism =>] MECHANISM]
10549 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
10551 -- EXTERNAL_SYMBOL ::=
10553 -- | static_string_EXPRESSION
10555 -- PARAMETER_TYPES ::=
10557 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10559 -- TYPE_DESIGNATOR ::=
10561 -- | subtype_Name ' Access
10565 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10567 -- MECHANISM_ASSOCIATION ::=
10568 -- [formal_parameter_NAME =>] MECHANISM_NAME
10570 -- MECHANISM_NAME ::=
10573 -- | Descriptor [([Class =>] CLASS_NAME)]
10575 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10577 when Pragma_Export_Function => Export_Function : declare
10578 Args : Args_List (1 .. 6);
10579 Names : constant Name_List (1 .. 6) := (
10582 Name_Parameter_Types,
10585 Name_Result_Mechanism);
10587 Internal : Node_Id renames Args (1);
10588 External : Node_Id renames Args (2);
10589 Parameter_Types : Node_Id renames Args (3);
10590 Result_Type : Node_Id renames Args (4);
10591 Mechanism : Node_Id renames Args (5);
10592 Result_Mechanism : Node_Id renames Args (6);
10596 Gather_Associations (Names, Args);
10597 Process_Extended_Import_Export_Subprogram_Pragma (
10598 Arg_Internal => Internal,
10599 Arg_External => External,
10600 Arg_Parameter_Types => Parameter_Types,
10601 Arg_Result_Type => Result_Type,
10602 Arg_Mechanism => Mechanism,
10603 Arg_Result_Mechanism => Result_Mechanism);
10604 end Export_Function;
10606 -------------------
10607 -- Export_Object --
10608 -------------------
10610 -- pragma Export_Object (
10611 -- [Internal =>] LOCAL_NAME
10612 -- [, [External =>] EXTERNAL_SYMBOL]
10613 -- [, [Size =>] EXTERNAL_SYMBOL]);
10615 -- EXTERNAL_SYMBOL ::=
10617 -- | static_string_EXPRESSION
10619 -- PARAMETER_TYPES ::=
10621 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10623 -- TYPE_DESIGNATOR ::=
10625 -- | subtype_Name ' Access
10629 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10631 -- MECHANISM_ASSOCIATION ::=
10632 -- [formal_parameter_NAME =>] MECHANISM_NAME
10634 -- MECHANISM_NAME ::=
10637 -- | Descriptor [([Class =>] CLASS_NAME)]
10639 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10641 when Pragma_Export_Object => Export_Object : declare
10642 Args : Args_List (1 .. 3);
10643 Names : constant Name_List (1 .. 3) := (
10648 Internal : Node_Id renames Args (1);
10649 External : Node_Id renames Args (2);
10650 Size : Node_Id renames Args (3);
10654 Gather_Associations (Names, Args);
10655 Process_Extended_Import_Export_Object_Pragma (
10656 Arg_Internal => Internal,
10657 Arg_External => External,
10661 ----------------------
10662 -- Export_Procedure --
10663 ----------------------
10665 -- pragma Export_Procedure (
10666 -- [Internal =>] LOCAL_NAME
10667 -- [, [External =>] EXTERNAL_SYMBOL]
10668 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10669 -- [, [Mechanism =>] MECHANISM]);
10671 -- EXTERNAL_SYMBOL ::=
10673 -- | static_string_EXPRESSION
10675 -- PARAMETER_TYPES ::=
10677 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10679 -- TYPE_DESIGNATOR ::=
10681 -- | subtype_Name ' Access
10685 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10687 -- MECHANISM_ASSOCIATION ::=
10688 -- [formal_parameter_NAME =>] MECHANISM_NAME
10690 -- MECHANISM_NAME ::=
10693 -- | Descriptor [([Class =>] CLASS_NAME)]
10695 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10697 when Pragma_Export_Procedure => Export_Procedure : declare
10698 Args : Args_List (1 .. 4);
10699 Names : constant Name_List (1 .. 4) := (
10702 Name_Parameter_Types,
10705 Internal : Node_Id renames Args (1);
10706 External : Node_Id renames Args (2);
10707 Parameter_Types : Node_Id renames Args (3);
10708 Mechanism : Node_Id renames Args (4);
10712 Gather_Associations (Names, Args);
10713 Process_Extended_Import_Export_Subprogram_Pragma (
10714 Arg_Internal => Internal,
10715 Arg_External => External,
10716 Arg_Parameter_Types => Parameter_Types,
10717 Arg_Mechanism => Mechanism);
10718 end Export_Procedure;
10724 -- pragma Export_Value (
10725 -- [Value =>] static_integer_EXPRESSION,
10726 -- [Link_Name =>] static_string_EXPRESSION);
10728 when Pragma_Export_Value =>
10730 Check_Arg_Order ((Name_Value, Name_Link_Name));
10731 Check_Arg_Count (2);
10733 Check_Optional_Identifier (Arg1, Name_Value);
10734 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10736 Check_Optional_Identifier (Arg2, Name_Link_Name);
10737 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10739 -----------------------------
10740 -- Export_Valued_Procedure --
10741 -----------------------------
10743 -- pragma Export_Valued_Procedure (
10744 -- [Internal =>] LOCAL_NAME
10745 -- [, [External =>] EXTERNAL_SYMBOL,]
10746 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10747 -- [, [Mechanism =>] MECHANISM]);
10749 -- EXTERNAL_SYMBOL ::=
10751 -- | static_string_EXPRESSION
10753 -- PARAMETER_TYPES ::=
10755 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10757 -- TYPE_DESIGNATOR ::=
10759 -- | subtype_Name ' Access
10763 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10765 -- MECHANISM_ASSOCIATION ::=
10766 -- [formal_parameter_NAME =>] MECHANISM_NAME
10768 -- MECHANISM_NAME ::=
10771 -- | Descriptor [([Class =>] CLASS_NAME)]
10773 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10775 when Pragma_Export_Valued_Procedure =>
10776 Export_Valued_Procedure : declare
10777 Args : Args_List (1 .. 4);
10778 Names : constant Name_List (1 .. 4) := (
10781 Name_Parameter_Types,
10784 Internal : Node_Id renames Args (1);
10785 External : Node_Id renames Args (2);
10786 Parameter_Types : Node_Id renames Args (3);
10787 Mechanism : Node_Id renames Args (4);
10791 Gather_Associations (Names, Args);
10792 Process_Extended_Import_Export_Subprogram_Pragma (
10793 Arg_Internal => Internal,
10794 Arg_External => External,
10795 Arg_Parameter_Types => Parameter_Types,
10796 Arg_Mechanism => Mechanism);
10797 end Export_Valued_Procedure;
10799 -------------------
10800 -- Extend_System --
10801 -------------------
10803 -- pragma Extend_System ([Name =>] Identifier);
10805 when Pragma_Extend_System => Extend_System : declare
10808 Check_Valid_Configuration_Pragma;
10809 Check_Arg_Count (1);
10810 Check_Optional_Identifier (Arg1, Name_Name);
10811 Check_Arg_Is_Identifier (Arg1);
10813 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10816 and then Name_Buffer (1 .. 4) = "aux_"
10818 if Present (System_Extend_Pragma_Arg) then
10819 if Chars (Get_Pragma_Arg (Arg1)) =
10820 Chars (Expression (System_Extend_Pragma_Arg))
10824 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
10825 Error_Pragma ("pragma% conflicts with that #");
10829 System_Extend_Pragma_Arg := Arg1;
10831 if not GNAT_Mode then
10832 System_Extend_Unit := Arg1;
10836 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
10840 ------------------------
10841 -- Extensions_Allowed --
10842 ------------------------
10844 -- pragma Extensions_Allowed (ON | OFF);
10846 when Pragma_Extensions_Allowed =>
10848 Check_Arg_Count (1);
10849 Check_No_Identifiers;
10850 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10852 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
10853 Extensions_Allowed := True;
10854 Ada_Version := Ada_Version_Type'Last;
10857 Extensions_Allowed := False;
10858 Ada_Version := Ada_Version_Explicit;
10865 -- pragma External (
10866 -- [ Convention =>] convention_IDENTIFIER,
10867 -- [ Entity =>] local_NAME
10868 -- [, [External_Name =>] static_string_EXPRESSION ]
10869 -- [, [Link_Name =>] static_string_EXPRESSION ]);
10871 when Pragma_External => External : declare
10872 Def_Id : Entity_Id;
10875 pragma Warnings (Off, C);
10882 Name_External_Name,
10884 Check_At_Least_N_Arguments (2);
10885 Check_At_Most_N_Arguments (4);
10886 Process_Convention (C, Def_Id);
10887 Note_Possible_Modification
10888 (Get_Pragma_Arg (Arg2), Sure => False);
10889 Process_Interface_Name (Def_Id, Arg3, Arg4);
10890 Set_Exported (Def_Id, Arg2);
10893 --------------------------
10894 -- External_Name_Casing --
10895 --------------------------
10897 -- pragma External_Name_Casing (
10898 -- UPPERCASE | LOWERCASE
10899 -- [, AS_IS | UPPERCASE | LOWERCASE]);
10901 when Pragma_External_Name_Casing => External_Name_Casing : declare
10904 Check_No_Identifiers;
10906 if Arg_Count = 2 then
10907 Check_Arg_Is_One_Of
10908 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
10910 case Chars (Get_Pragma_Arg (Arg2)) is
10912 Opt.External_Name_Exp_Casing := As_Is;
10914 when Name_Uppercase =>
10915 Opt.External_Name_Exp_Casing := Uppercase;
10917 when Name_Lowercase =>
10918 Opt.External_Name_Exp_Casing := Lowercase;
10925 Check_Arg_Count (1);
10928 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
10930 case Chars (Get_Pragma_Arg (Arg1)) is
10931 when Name_Uppercase =>
10932 Opt.External_Name_Imp_Casing := Uppercase;
10934 when Name_Lowercase =>
10935 Opt.External_Name_Imp_Casing := Lowercase;
10940 end External_Name_Casing;
10942 --------------------------
10943 -- Favor_Top_Level --
10944 --------------------------
10946 -- pragma Favor_Top_Level (type_NAME);
10948 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
10949 Named_Entity : Entity_Id;
10953 Check_No_Identifiers;
10954 Check_Arg_Count (1);
10955 Check_Arg_Is_Local_Name (Arg1);
10956 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
10958 -- If it's an access-to-subprogram type (in particular, not a
10959 -- subtype), set the flag on that type.
10961 if Is_Access_Subprogram_Type (Named_Entity) then
10962 Set_Can_Use_Internal_Rep (Named_Entity, False);
10964 -- Otherwise it's an error (name denotes the wrong sort of entity)
10968 ("access-to-subprogram type expected",
10969 Get_Pragma_Arg (Arg1));
10971 end Favor_Top_Level;
10977 -- pragma Fast_Math;
10979 when Pragma_Fast_Math =>
10981 Check_No_Identifiers;
10982 Check_Valid_Configuration_Pragma;
10985 ---------------------------
10986 -- Finalize_Storage_Only --
10987 ---------------------------
10989 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
10991 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
10992 Assoc : constant Node_Id := Arg1;
10993 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
10998 Check_No_Identifiers;
10999 Check_Arg_Count (1);
11000 Check_Arg_Is_Local_Name (Arg1);
11002 Find_Type (Type_Id);
11003 Typ := Entity (Type_Id);
11006 or else Rep_Item_Too_Early (Typ, N)
11010 Typ := Underlying_Type (Typ);
11013 if not Is_Controlled (Typ) then
11014 Error_Pragma ("pragma% must specify controlled type");
11017 Check_First_Subtype (Arg1);
11019 if Finalize_Storage_Only (Typ) then
11020 Error_Pragma ("duplicate pragma%, only one allowed");
11022 elsif not Rep_Item_Too_Late (Typ, N) then
11023 Set_Finalize_Storage_Only (Base_Type (Typ), True);
11025 end Finalize_Storage;
11027 --------------------------
11028 -- Float_Representation --
11029 --------------------------
11031 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
11033 -- FLOAT_REP ::= VAX_Float | IEEE_Float
11035 when Pragma_Float_Representation => Float_Representation : declare
11043 if Arg_Count = 1 then
11044 Check_Valid_Configuration_Pragma;
11046 Check_Arg_Count (2);
11047 Check_Optional_Identifier (Arg2, Name_Entity);
11048 Check_Arg_Is_Local_Name (Arg2);
11051 Check_No_Identifier (Arg1);
11052 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
11054 if not OpenVMS_On_Target then
11055 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11057 ("??pragma% ignored (applies only to Open'V'M'S)");
11063 -- One argument case
11065 if Arg_Count = 1 then
11066 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11067 if Opt.Float_Format = 'I' then
11068 Error_Pragma ("'I'E'E'E format previously specified");
11071 Opt.Float_Format := 'V';
11074 if Opt.Float_Format = 'V' then
11075 Error_Pragma ("'V'A'X format previously specified");
11078 Opt.Float_Format := 'I';
11081 Set_Standard_Fpt_Formats;
11083 -- Two argument case
11086 Argx := Get_Pragma_Arg (Arg2);
11088 if not Is_Entity_Name (Argx)
11089 or else not Is_Floating_Point_Type (Entity (Argx))
11092 ("second argument of% pragma must be floating-point type",
11096 Ent := Entity (Argx);
11097 Digs := UI_To_Int (Digits_Value (Ent));
11099 -- Two arguments, VAX_Float case
11101 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11103 when 6 => Set_F_Float (Ent);
11104 when 9 => Set_D_Float (Ent);
11105 when 15 => Set_G_Float (Ent);
11109 ("wrong digits value, must be 6,9 or 15", Arg2);
11112 -- Two arguments, IEEE_Float case
11116 when 6 => Set_IEEE_Short (Ent);
11117 when 15 => Set_IEEE_Long (Ent);
11121 ("wrong digits value, must be 6 or 15", Arg2);
11125 end Float_Representation;
11131 -- pragma Global (GLOBAL_SPECIFICATION)
11133 -- GLOBAL_SPECIFICATION ::=
11136 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
11138 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
11140 -- MODE_SELECTOR ::= Input | Output | In_Out | Contract_In
11141 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
11142 -- GLOBAL_ITEM ::= NAME
11144 when Pragma_Global => Global : declare
11145 Subp_Id : Entity_Id;
11147 Seen : Elist_Id := No_Elist;
11148 -- A list containing the entities of all the items processed so
11149 -- far. It plays a role in detecting distinct entities.
11151 Contract_Seen : Boolean := False;
11152 In_Out_Seen : Boolean := False;
11153 Input_Seen : Boolean := False;
11154 Output_Seen : Boolean := False;
11155 -- Flags used to verify the consistency of modes
11157 procedure Analyze_Global_List
11159 Global_Mode : Name_Id := Name_Input);
11160 -- Verify the legality of a single global list declaration.
11161 -- Global_Mode denotes the current mode in effect.
11163 -------------------------
11164 -- Analyze_Global_List --
11165 -------------------------
11167 procedure Analyze_Global_List
11169 Global_Mode : Name_Id := Name_Input)
11171 procedure Analyze_Global_Item
11173 Global_Mode : Name_Id);
11174 -- Verify the legality of a single global item declaration.
11175 -- Global_Mode denotes the current mode in effect.
11177 procedure Check_Duplicate_Mode
11179 Status : in out Boolean);
11180 -- Flag Status denotes whether a particular mode has been seen
11181 -- while processing a global list. This routine verifies that
11182 -- Mode is not a duplicate mode and sets the flag Status.
11184 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
11185 -- Mode denotes either In_Out or Output. Depending on the kind
11186 -- of the related subprogram, emit an error if those two modes
11187 -- apply to a function.
11189 -------------------------
11190 -- Analyze_Global_Item --
11191 -------------------------
11193 procedure Analyze_Global_Item
11195 Global_Mode : Name_Id)
11197 Item_Id : Entity_Id;
11200 -- Detect one of the following cases
11202 -- with Global => (null, Name)
11203 -- with Global => (Name_1, null, Name_2)
11204 -- with Global => (Name, null)
11206 if Nkind (Item) = N_Null then
11208 ("cannot mix null and non-null global items", Item);
11214 -- Find the entity of the item. If this is a renaming, climb
11215 -- the renaming chain to reach the root object. Renamings of
11216 -- non-entire objects do not yield an entity (Empty).
11218 Item_Id := Entity_Of (Item);
11220 if Present (Item_Id) then
11222 -- A global item cannot reference a formal parameter. Do
11223 -- this check first to provide a better error diagnostic.
11225 if Is_Formal (Item_Id) then
11227 ("global item cannot reference formal parameter",
11231 -- The only legal references are those to abstract states
11234 elsif not Ekind_In (Item_Id, E_Abstract_State,
11238 ("global item must denote variable or state", Item);
11242 -- When the item renames an entire object, replace the
11243 -- item with a reference to the object.
11245 if Present (Renamed_Object (Entity (Item))) then
11247 New_Reference_To (Item_Id, Sloc (Item)));
11251 -- Some form of illegal construct masquerading as a name
11255 ("global item must denote variable or state", Item);
11259 -- The same entity might be referenced through various way.
11260 -- Check the entity of the item rather than the item itself.
11262 if Contains (Seen, Item_Id) then
11263 Error_Msg_N ("duplicate global item", Item);
11265 -- Add the entity of the current item to the list of
11266 -- processed items.
11269 Add_Item (Item_Id, Seen);
11272 if Ekind (Item_Id) = E_Abstract_State
11273 and then Is_Volatile_State (Item_Id)
11275 -- A global item of mode In_Out or Output cannot denote a
11276 -- volatile Input state.
11278 if Is_Input_State (Item_Id)
11279 and then (Global_Mode = Name_In_Out
11281 Global_Mode = Name_Output)
11284 ("global item of mode In_Out or Output cannot "
11285 & "reference Volatile Input state", Item);
11287 -- A global item of mode In_Out or Input cannot reference
11288 -- a volatile Output state.
11290 elsif Is_Output_State (Item_Id)
11291 and then (Global_Mode = Name_In_Out
11293 Global_Mode = Name_Input)
11296 ("global item of mode In_Out or Input cannot "
11297 & "reference Volatile Output state", Item);
11300 end Analyze_Global_Item;
11302 --------------------------
11303 -- Check_Duplicate_Mode --
11304 --------------------------
11306 procedure Check_Duplicate_Mode
11308 Status : in out Boolean)
11312 Error_Msg_N ("duplicate global mode", Mode);
11316 end Check_Duplicate_Mode;
11318 ----------------------------------------
11319 -- Check_Mode_Restriction_In_Function --
11320 ----------------------------------------
11322 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
11324 if Ekind (Subp_Id) = E_Function then
11326 ("global mode & not applicable to functions",
11329 end Check_Mode_Restriction_In_Function;
11337 -- Start of processing for Analyze_Global_List
11340 -- Single global item declaration
11342 if Nkind_In (List, N_Identifier, N_Selected_Component) then
11343 Analyze_Global_Item (List, Global_Mode);
11345 -- Simple global list or moded global list declaration
11347 elsif Nkind (List) = N_Aggregate then
11349 -- The declaration of a simple global list appear as a
11350 -- collection of expressions.
11352 if Present (Expressions (List)) then
11353 if Present (Component_Associations (List)) then
11355 ("cannot mix moded and non-moded global lists",
11359 Item := First (Expressions (List));
11360 while Present (Item) loop
11361 Analyze_Global_Item (Item, Global_Mode);
11366 -- The declaration of a moded global list appears as a
11367 -- collection of component associations where individual
11368 -- choices denote modes.
11370 elsif Present (Component_Associations (List)) then
11371 if Present (Expressions (List)) then
11373 ("cannot mix moded and non-moded global lists",
11377 Assoc := First (Component_Associations (List));
11378 while Present (Assoc) loop
11379 Mode := First (Choices (Assoc));
11381 if Nkind (Mode) = N_Identifier then
11382 if Chars (Mode) = Name_Contract_In then
11383 Check_Duplicate_Mode (Mode, Contract_Seen);
11385 elsif Chars (Mode) = Name_In_Out then
11386 Check_Duplicate_Mode (Mode, In_Out_Seen);
11387 Check_Mode_Restriction_In_Function (Mode);
11389 elsif Chars (Mode) = Name_Input then
11390 Check_Duplicate_Mode (Mode, Input_Seen);
11392 elsif Chars (Mode) = Name_Output then
11393 Check_Duplicate_Mode (Mode, Output_Seen);
11394 Check_Mode_Restriction_In_Function (Mode);
11397 Error_Msg_N ("invalid mode selector", Mode);
11401 Error_Msg_N ("invalid mode selector", Mode);
11404 -- Items in a moded list appear as a collection of
11405 -- expressions. Reuse the existing machinery to
11408 Analyze_Global_List
11409 (List => Expression (Assoc),
11410 Global_Mode => Chars (Mode));
11415 -- Something went horribly wrong, we have a malformed tree
11418 raise Program_Error;
11421 -- Any other attempt to declare a global item is erroneous
11424 Error_Msg_N ("malformed global list declaration", List);
11426 end Analyze_Global_List;
11433 -- Start of processing for Global
11438 Check_Arg_Count (1);
11440 -- Ensure the proper placement of the pragma. Global must be
11441 -- associated with a subprogram declaration.
11443 Subp := Parent (Corresponding_Aspect (N));
11445 if Nkind (Subp) /= N_Subprogram_Declaration then
11450 Subp_Id := Defining_Unit_Name (Specification (Subp));
11451 List := Expression (Arg1);
11453 -- There is nothing to be done for a null global list
11455 if Nkind (List) = N_Null then
11458 -- Analyze the various forms of global lists and items. Note that
11459 -- some of these may be malformed in which case the analysis emits
11463 -- Ensure that the formal parameters are visible when
11464 -- processing an item. This falls out of the general rule of
11465 -- aspects pertaining to subprogram declarations.
11467 Push_Scope (Subp_Id);
11468 Install_Formals (Subp_Id);
11470 Analyze_Global_List (List);
11480 -- pragma Ident (static_string_EXPRESSION)
11482 -- Note: pragma Comment shares this processing. Pragma Comment is
11483 -- identical to Ident, except that the restriction of the argument to
11484 -- 31 characters and the placement restrictions are not enforced for
11487 when Pragma_Ident | Pragma_Comment => Ident : declare
11492 Check_Arg_Count (1);
11493 Check_No_Identifiers;
11494 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11497 -- For pragma Ident, preserve DEC compatibility by requiring the
11498 -- pragma to appear in a declarative part or package spec.
11500 if Prag_Id = Pragma_Ident then
11501 Check_Is_In_Decl_Part_Or_Package_Spec;
11504 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
11511 GP := Parent (Parent (N));
11513 if Nkind_In (GP, N_Package_Declaration,
11514 N_Generic_Package_Declaration)
11519 -- If we have a compilation unit, then record the ident value,
11520 -- checking for improper duplication.
11522 if Nkind (GP) = N_Compilation_Unit then
11523 CS := Ident_String (Current_Sem_Unit);
11525 if Present (CS) then
11527 -- For Ident, we do not permit multiple instances
11529 if Prag_Id = Pragma_Ident then
11530 Error_Pragma ("duplicate% pragma not permitted");
11532 -- For Comment, we concatenate the string, unless we want
11533 -- to preserve the tree structure for ASIS.
11535 elsif not ASIS_Mode then
11536 Start_String (Strval (CS));
11537 Store_String_Char (' ');
11538 Store_String_Chars (Strval (Str));
11539 Set_Strval (CS, End_String);
11543 -- In VMS, the effect of IDENT is achieved by passing
11544 -- --identification=name as a --for-linker switch.
11546 if OpenVMS_On_Target then
11549 ("--for-linker=--identification=");
11550 String_To_Name_Buffer (Strval (Str));
11551 Store_String_Chars (Name_Buffer (1 .. Name_Len));
11553 -- Only the last processed IDENT is saved. The main
11554 -- purpose is so an IDENT associated with a main
11555 -- procedure will be used in preference to an IDENT
11556 -- associated with a with'd package.
11558 Replace_Linker_Option_String
11559 (End_String, "--for-linker=--identification=");
11562 Set_Ident_String (Current_Sem_Unit, Str);
11565 -- For subunits, we just ignore the Ident, since in GNAT these
11566 -- are not separate object files, and hence not separate units
11567 -- in the unit table.
11569 elsif Nkind (GP) = N_Subunit then
11572 -- Otherwise we have a misplaced pragma Ident, but we ignore
11573 -- this if we are in an instantiation, since it comes from
11574 -- a generic, and has no relevance to the instantiation.
11576 elsif Prag_Id = Pragma_Ident then
11577 if Instantiation_Location (Loc) = No_Location then
11578 Error_Pragma ("pragma% only allowed at outer level");
11584 ----------------------------
11585 -- Implementation_Defined --
11586 ----------------------------
11588 -- pragma Implementation_Defined (local_NAME);
11590 -- Marks previously declared entity as implementation defined. For
11591 -- an overloaded entity, applies to the most recent homonym.
11593 -- pragma Implementation_Defined;
11595 -- The form with no arguments appears anywhere within a scope, most
11596 -- typically a package spec, and indicates that all entities that are
11597 -- defined within the package spec are Implementation_Defined.
11599 when Pragma_Implementation_Defined => Implementation_Defined : declare
11603 Check_No_Identifiers;
11605 -- Form with no arguments
11607 if Arg_Count = 0 then
11608 Set_Is_Implementation_Defined (Current_Scope);
11610 -- Form with one argument
11613 Check_Arg_Count (1);
11614 Check_Arg_Is_Local_Name (Arg1);
11615 Ent := Entity (Get_Pragma_Arg (Arg1));
11616 Set_Is_Implementation_Defined (Ent);
11618 end Implementation_Defined;
11624 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
11626 -- IMPLEMENTATION_KIND ::=
11627 -- By_Entry | By_Protected_Procedure | By_Any | Optional
11629 -- "By_Any" and "Optional" are treated as synonyms in order to
11630 -- support Ada 2012 aspect Synchronization.
11632 when Pragma_Implemented => Implemented : declare
11633 Proc_Id : Entity_Id;
11638 Check_Arg_Count (2);
11639 Check_No_Identifiers;
11640 Check_Arg_Is_Identifier (Arg1);
11641 Check_Arg_Is_Local_Name (Arg1);
11642 Check_Arg_Is_One_Of (Arg2,
11645 Name_By_Protected_Procedure,
11648 -- Extract the name of the local procedure
11650 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
11652 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
11653 -- primitive procedure of a synchronized tagged type.
11655 if Ekind (Proc_Id) = E_Procedure
11656 and then Is_Primitive (Proc_Id)
11657 and then Present (First_Formal (Proc_Id))
11659 Typ := Etype (First_Formal (Proc_Id));
11661 if Is_Tagged_Type (Typ)
11664 -- Check for a protected, a synchronized or a task interface
11666 ((Is_Interface (Typ)
11667 and then Is_Synchronized_Interface (Typ))
11669 -- Check for a protected type or a task type that implements
11673 (Is_Concurrent_Record_Type (Typ)
11674 and then Present (Interfaces (Typ)))
11676 -- Check for a private record extension with keyword
11680 (Ekind_In (Typ, E_Record_Type_With_Private,
11681 E_Record_Subtype_With_Private)
11682 and then Synchronized_Present (Parent (Typ))))
11687 ("controlling formal must be of synchronized tagged type",
11692 -- Procedures declared inside a protected type must be accepted
11694 elsif Ekind (Proc_Id) = E_Procedure
11695 and then Is_Protected_Type (Scope (Proc_Id))
11699 -- The first argument is not a primitive procedure
11703 ("pragma % must be applied to a primitive procedure", Arg1);
11707 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
11708 -- By_Protected_Procedure to the primitive procedure of a task
11711 if Chars (Arg2) = Name_By_Protected_Procedure
11712 and then Is_Interface (Typ)
11713 and then Is_Task_Interface (Typ)
11716 ("implementation kind By_Protected_Procedure cannot be "
11717 & "applied to a task interface primitive", Arg2);
11721 Record_Rep_Item (Proc_Id, N);
11724 ----------------------
11725 -- Implicit_Packing --
11726 ----------------------
11728 -- pragma Implicit_Packing;
11730 when Pragma_Implicit_Packing =>
11732 Check_Arg_Count (0);
11733 Implicit_Packing := True;
11740 -- [Convention =>] convention_IDENTIFIER,
11741 -- [Entity =>] local_NAME
11742 -- [, [External_Name =>] static_string_EXPRESSION ]
11743 -- [, [Link_Name =>] static_string_EXPRESSION ]);
11745 when Pragma_Import =>
11746 Check_Ada_83_Warning;
11750 Name_External_Name,
11753 Check_At_Least_N_Arguments (2);
11754 Check_At_Most_N_Arguments (4);
11755 Process_Import_Or_Interface;
11757 ----------------------
11758 -- Import_Exception --
11759 ----------------------
11761 -- pragma Import_Exception (
11762 -- [Internal =>] LOCAL_NAME
11763 -- [, [External =>] EXTERNAL_SYMBOL]
11764 -- [, [Form =>] Ada | VMS]
11765 -- [, [Code =>] static_integer_EXPRESSION]);
11767 when Pragma_Import_Exception => Import_Exception : declare
11768 Args : Args_List (1 .. 4);
11769 Names : constant Name_List (1 .. 4) := (
11775 Internal : Node_Id renames Args (1);
11776 External : Node_Id renames Args (2);
11777 Form : Node_Id renames Args (3);
11778 Code : Node_Id renames Args (4);
11782 Gather_Associations (Names, Args);
11784 if Present (External) and then Present (Code) then
11786 ("cannot give both External and Code options for pragma%");
11789 Process_Extended_Import_Export_Exception_Pragma (
11790 Arg_Internal => Internal,
11791 Arg_External => External,
11795 if not Is_VMS_Exception (Entity (Internal)) then
11796 Set_Imported (Entity (Internal));
11798 end Import_Exception;
11800 ---------------------
11801 -- Import_Function --
11802 ---------------------
11804 -- pragma Import_Function (
11805 -- [Internal =>] LOCAL_NAME,
11806 -- [, [External =>] EXTERNAL_SYMBOL]
11807 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
11808 -- [, [Result_Type =>] SUBTYPE_MARK]
11809 -- [, [Mechanism =>] MECHANISM]
11810 -- [, [Result_Mechanism =>] MECHANISM_NAME]
11811 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
11813 -- EXTERNAL_SYMBOL ::=
11815 -- | static_string_EXPRESSION
11817 -- PARAMETER_TYPES ::=
11819 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11821 -- TYPE_DESIGNATOR ::=
11823 -- | subtype_Name ' Access
11827 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11829 -- MECHANISM_ASSOCIATION ::=
11830 -- [formal_parameter_NAME =>] MECHANISM_NAME
11832 -- MECHANISM_NAME ::=
11835 -- | Descriptor [([Class =>] CLASS_NAME)]
11837 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
11839 when Pragma_Import_Function => Import_Function : declare
11840 Args : Args_List (1 .. 7);
11841 Names : constant Name_List (1 .. 7) := (
11844 Name_Parameter_Types,
11847 Name_Result_Mechanism,
11848 Name_First_Optional_Parameter);
11850 Internal : Node_Id renames Args (1);
11851 External : Node_Id renames Args (2);
11852 Parameter_Types : Node_Id renames Args (3);
11853 Result_Type : Node_Id renames Args (4);
11854 Mechanism : Node_Id renames Args (5);
11855 Result_Mechanism : Node_Id renames Args (6);
11856 First_Optional_Parameter : Node_Id renames Args (7);
11860 Gather_Associations (Names, Args);
11861 Process_Extended_Import_Export_Subprogram_Pragma (
11862 Arg_Internal => Internal,
11863 Arg_External => External,
11864 Arg_Parameter_Types => Parameter_Types,
11865 Arg_Result_Type => Result_Type,
11866 Arg_Mechanism => Mechanism,
11867 Arg_Result_Mechanism => Result_Mechanism,
11868 Arg_First_Optional_Parameter => First_Optional_Parameter);
11869 end Import_Function;
11871 -------------------
11872 -- Import_Object --
11873 -------------------
11875 -- pragma Import_Object (
11876 -- [Internal =>] LOCAL_NAME
11877 -- [, [External =>] EXTERNAL_SYMBOL]
11878 -- [, [Size =>] EXTERNAL_SYMBOL]);
11880 -- EXTERNAL_SYMBOL ::=
11882 -- | static_string_EXPRESSION
11884 when Pragma_Import_Object => Import_Object : declare
11885 Args : Args_List (1 .. 3);
11886 Names : constant Name_List (1 .. 3) := (
11891 Internal : Node_Id renames Args (1);
11892 External : Node_Id renames Args (2);
11893 Size : Node_Id renames Args (3);
11897 Gather_Associations (Names, Args);
11898 Process_Extended_Import_Export_Object_Pragma (
11899 Arg_Internal => Internal,
11900 Arg_External => External,
11904 ----------------------
11905 -- Import_Procedure --
11906 ----------------------
11908 -- pragma Import_Procedure (
11909 -- [Internal =>] LOCAL_NAME
11910 -- [, [External =>] EXTERNAL_SYMBOL]
11911 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
11912 -- [, [Mechanism =>] MECHANISM]
11913 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
11915 -- EXTERNAL_SYMBOL ::=
11917 -- | static_string_EXPRESSION
11919 -- PARAMETER_TYPES ::=
11921 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11923 -- TYPE_DESIGNATOR ::=
11925 -- | subtype_Name ' Access
11929 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11931 -- MECHANISM_ASSOCIATION ::=
11932 -- [formal_parameter_NAME =>] MECHANISM_NAME
11934 -- MECHANISM_NAME ::=
11937 -- | Descriptor [([Class =>] CLASS_NAME)]
11939 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
11941 when Pragma_Import_Procedure => Import_Procedure : declare
11942 Args : Args_List (1 .. 5);
11943 Names : constant Name_List (1 .. 5) := (
11946 Name_Parameter_Types,
11948 Name_First_Optional_Parameter);
11950 Internal : Node_Id renames Args (1);
11951 External : Node_Id renames Args (2);
11952 Parameter_Types : Node_Id renames Args (3);
11953 Mechanism : Node_Id renames Args (4);
11954 First_Optional_Parameter : Node_Id renames Args (5);
11958 Gather_Associations (Names, Args);
11959 Process_Extended_Import_Export_Subprogram_Pragma (
11960 Arg_Internal => Internal,
11961 Arg_External => External,
11962 Arg_Parameter_Types => Parameter_Types,
11963 Arg_Mechanism => Mechanism,
11964 Arg_First_Optional_Parameter => First_Optional_Parameter);
11965 end Import_Procedure;
11967 -----------------------------
11968 -- Import_Valued_Procedure --
11969 -----------------------------
11971 -- pragma Import_Valued_Procedure (
11972 -- [Internal =>] LOCAL_NAME
11973 -- [, [External =>] EXTERNAL_SYMBOL]
11974 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
11975 -- [, [Mechanism =>] MECHANISM]
11976 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
11978 -- EXTERNAL_SYMBOL ::=
11980 -- | static_string_EXPRESSION
11982 -- PARAMETER_TYPES ::=
11984 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11986 -- TYPE_DESIGNATOR ::=
11988 -- | subtype_Name ' Access
11992 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11994 -- MECHANISM_ASSOCIATION ::=
11995 -- [formal_parameter_NAME =>] MECHANISM_NAME
11997 -- MECHANISM_NAME ::=
12000 -- | Descriptor [([Class =>] CLASS_NAME)]
12002 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12004 when Pragma_Import_Valued_Procedure =>
12005 Import_Valued_Procedure : declare
12006 Args : Args_List (1 .. 5);
12007 Names : constant Name_List (1 .. 5) := (
12010 Name_Parameter_Types,
12012 Name_First_Optional_Parameter);
12014 Internal : Node_Id renames Args (1);
12015 External : Node_Id renames Args (2);
12016 Parameter_Types : Node_Id renames Args (3);
12017 Mechanism : Node_Id renames Args (4);
12018 First_Optional_Parameter : Node_Id renames Args (5);
12022 Gather_Associations (Names, Args);
12023 Process_Extended_Import_Export_Subprogram_Pragma (
12024 Arg_Internal => Internal,
12025 Arg_External => External,
12026 Arg_Parameter_Types => Parameter_Types,
12027 Arg_Mechanism => Mechanism,
12028 Arg_First_Optional_Parameter => First_Optional_Parameter);
12029 end Import_Valued_Procedure;
12035 -- pragma Independent (LOCAL_NAME);
12037 when Pragma_Independent => Independent : declare
12044 Check_Ada_83_Warning;
12046 Check_No_Identifiers;
12047 Check_Arg_Count (1);
12048 Check_Arg_Is_Local_Name (Arg1);
12049 E_Id := Get_Pragma_Arg (Arg1);
12051 if Etype (E_Id) = Any_Type then
12055 E := Entity (E_Id);
12056 D := Declaration_Node (E);
12059 -- Check duplicate before we chain ourselves!
12061 Check_Duplicate_Pragma (E);
12063 -- Check appropriate entity
12065 if Is_Type (E) then
12066 if Rep_Item_Too_Early (E, N)
12068 Rep_Item_Too_Late (E, N)
12072 Check_First_Subtype (Arg1);
12075 elsif K = N_Object_Declaration
12076 or else (K = N_Component_Declaration
12077 and then Original_Record_Component (E) = E)
12079 if Rep_Item_Too_Late (E, N) then
12085 ("inappropriate entity for pragma%", Arg1);
12088 Independence_Checks.Append ((N, E));
12091 ----------------------------
12092 -- Independent_Components --
12093 ----------------------------
12095 -- pragma Atomic_Components (array_LOCAL_NAME);
12097 -- This processing is shared by Volatile_Components
12099 when Pragma_Independent_Components => Independent_Components : declare
12106 Check_Ada_83_Warning;
12108 Check_No_Identifiers;
12109 Check_Arg_Count (1);
12110 Check_Arg_Is_Local_Name (Arg1);
12111 E_Id := Get_Pragma_Arg (Arg1);
12113 if Etype (E_Id) = Any_Type then
12117 E := Entity (E_Id);
12119 -- Check duplicate before we chain ourselves!
12121 Check_Duplicate_Pragma (E);
12123 -- Check appropriate entity
12125 if Rep_Item_Too_Early (E, N)
12127 Rep_Item_Too_Late (E, N)
12132 D := Declaration_Node (E);
12135 if K = N_Full_Type_Declaration
12136 and then (Is_Array_Type (E) or else Is_Record_Type (E))
12138 Independence_Checks.Append ((N, E));
12139 Set_Has_Independent_Components (Base_Type (E));
12141 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
12142 and then Nkind (D) = N_Object_Declaration
12143 and then Nkind (Object_Definition (D)) =
12144 N_Constrained_Array_Definition
12146 Independence_Checks.Append ((N, E));
12147 Set_Has_Independent_Components (E);
12150 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
12152 end Independent_Components;
12154 ------------------------
12155 -- Initialize_Scalars --
12156 ------------------------
12158 -- pragma Initialize_Scalars;
12160 when Pragma_Initialize_Scalars =>
12162 Check_Arg_Count (0);
12163 Check_Valid_Configuration_Pragma;
12164 Check_Restriction (No_Initialize_Scalars, N);
12166 -- Initialize_Scalars creates false positives in CodePeer, and
12167 -- incorrect negative results in Alfa mode, so ignore this pragma
12170 if not Restriction_Active (No_Initialize_Scalars)
12171 and then not (CodePeer_Mode or Alfa_Mode)
12173 Init_Or_Norm_Scalars := True;
12174 Initialize_Scalars := True;
12181 -- pragma Inline ( NAME {, NAME} );
12183 when Pragma_Inline =>
12185 -- Inline status is Enabled if inlining option is active
12187 if Inline_Active then
12188 Process_Inline (Enabled);
12190 Process_Inline (Disabled);
12193 -------------------
12194 -- Inline_Always --
12195 -------------------
12197 -- pragma Inline_Always ( NAME {, NAME} );
12199 when Pragma_Inline_Always =>
12202 -- Pragma always active unless in CodePeer or Alfa mode, since
12203 -- this causes walk order issues.
12205 if not (CodePeer_Mode or Alfa_Mode) then
12206 Process_Inline (Enabled);
12209 --------------------
12210 -- Inline_Generic --
12211 --------------------
12213 -- pragma Inline_Generic (NAME {, NAME});
12215 when Pragma_Inline_Generic =>
12217 Process_Generic_List;
12219 ----------------------
12220 -- Inspection_Point --
12221 ----------------------
12223 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
12225 when Pragma_Inspection_Point => Inspection_Point : declare
12230 if Arg_Count > 0 then
12233 Exp := Get_Pragma_Arg (Arg);
12236 if not Is_Entity_Name (Exp)
12237 or else not Is_Object (Entity (Exp))
12239 Error_Pragma_Arg ("object name required", Arg);
12243 exit when No (Arg);
12246 end Inspection_Point;
12252 -- pragma Interface (
12253 -- [ Convention =>] convention_IDENTIFIER,
12254 -- [ Entity =>] local_NAME
12255 -- [, [External_Name =>] static_string_EXPRESSION ]
12256 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12258 when Pragma_Interface =>
12263 Name_External_Name,
12265 Check_At_Least_N_Arguments (2);
12266 Check_At_Most_N_Arguments (4);
12267 Process_Import_Or_Interface;
12269 -- In Ada 2005, the permission to use Interface (a reserved word)
12270 -- as a pragma name is considered an obsolescent feature, and this
12271 -- pragma was already obsolescent in Ada 95.
12273 if Ada_Version >= Ada_95 then
12275 (No_Obsolescent_Features, Pragma_Identifier (N));
12277 if Warn_On_Obsolescent_Feature then
12279 ("pragma Interface is an obsolescent feature?j?", N);
12281 ("|use pragma Import instead?j?", N);
12285 --------------------
12286 -- Interface_Name --
12287 --------------------
12289 -- pragma Interface_Name (
12290 -- [ Entity =>] local_NAME
12291 -- [,[External_Name =>] static_string_EXPRESSION ]
12292 -- [,[Link_Name =>] static_string_EXPRESSION ]);
12294 when Pragma_Interface_Name => Interface_Name : declare
12296 Def_Id : Entity_Id;
12297 Hom_Id : Entity_Id;
12303 ((Name_Entity, Name_External_Name, Name_Link_Name));
12304 Check_At_Least_N_Arguments (2);
12305 Check_At_Most_N_Arguments (3);
12306 Id := Get_Pragma_Arg (Arg1);
12309 -- This is obsolete from Ada 95 on, but it is an implementation
12310 -- defined pragma, so we do not consider that it violates the
12311 -- restriction (No_Obsolescent_Features).
12313 if Ada_Version >= Ada_95 then
12314 if Warn_On_Obsolescent_Feature then
12316 ("pragma Interface_Name is an obsolescent feature?j?", N);
12318 ("|use pragma Import instead?j?", N);
12322 if not Is_Entity_Name (Id) then
12324 ("first argument for pragma% must be entity name", Arg1);
12325 elsif Etype (Id) = Any_Type then
12328 Def_Id := Entity (Id);
12331 -- Special DEC-compatible processing for the object case, forces
12332 -- object to be imported.
12334 if Ekind (Def_Id) = E_Variable then
12335 Kill_Size_Check_Code (Def_Id);
12336 Note_Possible_Modification (Id, Sure => False);
12338 -- Initialization is not allowed for imported variable
12340 if Present (Expression (Parent (Def_Id)))
12341 and then Comes_From_Source (Expression (Parent (Def_Id)))
12343 Error_Msg_Sloc := Sloc (Def_Id);
12345 ("no initialization allowed for declaration of& #",
12349 -- For compatibility, support VADS usage of providing both
12350 -- pragmas Interface and Interface_Name to obtain the effect
12351 -- of a single Import pragma.
12353 if Is_Imported (Def_Id)
12354 and then Present (First_Rep_Item (Def_Id))
12355 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
12357 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
12361 Set_Imported (Def_Id);
12364 Set_Is_Public (Def_Id);
12365 Process_Interface_Name (Def_Id, Arg2, Arg3);
12368 -- Otherwise must be subprogram
12370 elsif not Is_Subprogram (Def_Id) then
12372 ("argument of pragma% is not subprogram", Arg1);
12375 Check_At_Most_N_Arguments (3);
12379 -- Loop through homonyms
12382 Def_Id := Get_Base_Subprogram (Hom_Id);
12384 if Is_Imported (Def_Id) then
12385 Process_Interface_Name (Def_Id, Arg2, Arg3);
12389 exit when From_Aspect_Specification (N);
12390 Hom_Id := Homonym (Hom_Id);
12392 exit when No (Hom_Id)
12393 or else Scope (Hom_Id) /= Current_Scope;
12398 ("argument of pragma% is not imported subprogram",
12402 end Interface_Name;
12404 -----------------------
12405 -- Interrupt_Handler --
12406 -----------------------
12408 -- pragma Interrupt_Handler (handler_NAME);
12410 when Pragma_Interrupt_Handler =>
12411 Check_Ada_83_Warning;
12412 Check_Arg_Count (1);
12413 Check_No_Identifiers;
12415 if No_Run_Time_Mode then
12416 Error_Msg_CRT ("Interrupt_Handler pragma", N);
12418 Check_Interrupt_Or_Attach_Handler;
12419 Process_Interrupt_Or_Attach_Handler;
12422 ------------------------
12423 -- Interrupt_Priority --
12424 ------------------------
12426 -- pragma Interrupt_Priority [(EXPRESSION)];
12428 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
12429 P : constant Node_Id := Parent (N);
12434 Check_Ada_83_Warning;
12436 if Arg_Count /= 0 then
12437 Arg := Get_Pragma_Arg (Arg1);
12438 Check_Arg_Count (1);
12439 Check_No_Identifiers;
12441 -- The expression must be analyzed in the special manner
12442 -- described in "Handling of Default and Per-Object
12443 -- Expressions" in sem.ads.
12445 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
12448 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
12453 Ent := Defining_Identifier (Parent (P));
12455 -- Check duplicate pragma before we chain the pragma in the Rep
12456 -- Item chain of Ent.
12458 Check_Duplicate_Pragma (Ent);
12459 Record_Rep_Item (Ent, N);
12461 end Interrupt_Priority;
12463 ---------------------
12464 -- Interrupt_State --
12465 ---------------------
12467 -- pragma Interrupt_State (
12468 -- [Name =>] INTERRUPT_ID,
12469 -- [State =>] INTERRUPT_STATE);
12471 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
12472 -- INTERRUPT_STATE => System | Runtime | User
12474 -- Note: if the interrupt id is given as an identifier, then it must
12475 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
12476 -- given as a static integer expression which must be in the range of
12477 -- Ada.Interrupts.Interrupt_ID.
12479 when Pragma_Interrupt_State => Interrupt_State : declare
12481 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
12482 -- This is the entity Ada.Interrupts.Interrupt_ID;
12484 State_Type : Character;
12485 -- Set to 's'/'r'/'u' for System/Runtime/User
12488 -- Index to entry in Interrupt_States table
12491 -- Value of interrupt
12493 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
12494 -- The first argument to the pragma
12496 Int_Ent : Entity_Id;
12497 -- Interrupt entity in Ada.Interrupts.Names
12501 Check_Arg_Order ((Name_Name, Name_State));
12502 Check_Arg_Count (2);
12504 Check_Optional_Identifier (Arg1, Name_Name);
12505 Check_Optional_Identifier (Arg2, Name_State);
12506 Check_Arg_Is_Identifier (Arg2);
12508 -- First argument is identifier
12510 if Nkind (Arg1X) = N_Identifier then
12512 -- Search list of names in Ada.Interrupts.Names
12514 Int_Ent := First_Entity (RTE (RE_Names));
12516 if No (Int_Ent) then
12517 Error_Pragma_Arg ("invalid interrupt name", Arg1);
12519 elsif Chars (Int_Ent) = Chars (Arg1X) then
12520 Int_Val := Expr_Value (Constant_Value (Int_Ent));
12524 Next_Entity (Int_Ent);
12527 -- First argument is not an identifier, so it must be a static
12528 -- expression of type Ada.Interrupts.Interrupt_ID.
12531 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
12532 Int_Val := Expr_Value (Arg1X);
12534 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
12536 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
12539 ("value not in range of type "
12540 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
12546 case Chars (Get_Pragma_Arg (Arg2)) is
12547 when Name_Runtime => State_Type := 'r';
12548 when Name_System => State_Type := 's';
12549 when Name_User => State_Type := 'u';
12552 Error_Pragma_Arg ("invalid interrupt state", Arg2);
12555 -- Check if entry is already stored
12557 IST_Num := Interrupt_States.First;
12559 -- If entry not found, add it
12561 if IST_Num > Interrupt_States.Last then
12562 Interrupt_States.Append
12563 ((Interrupt_Number => UI_To_Int (Int_Val),
12564 Interrupt_State => State_Type,
12565 Pragma_Loc => Loc));
12568 -- Case of entry for the same entry
12570 elsif Int_Val = Interrupt_States.Table (IST_Num).
12573 -- If state matches, done, no need to make redundant entry
12576 State_Type = Interrupt_States.Table (IST_Num).
12579 -- Otherwise if state does not match, error
12582 Interrupt_States.Table (IST_Num).Pragma_Loc;
12584 ("state conflicts with that given #", Arg2);
12588 IST_Num := IST_Num + 1;
12590 end Interrupt_State;
12596 -- pragma Invariant
12597 -- ([Entity =>] type_LOCAL_NAME,
12598 -- [Check =>] EXPRESSION
12599 -- [,[Message =>] String_Expression]);
12601 when Pragma_Invariant => Invariant : declare
12607 pragma Unreferenced (Discard);
12611 Check_At_Least_N_Arguments (2);
12612 Check_At_Most_N_Arguments (3);
12613 Check_Optional_Identifier (Arg1, Name_Entity);
12614 Check_Optional_Identifier (Arg2, Name_Check);
12616 if Arg_Count = 3 then
12617 Check_Optional_Identifier (Arg3, Name_Message);
12618 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
12621 Check_Arg_Is_Local_Name (Arg1);
12623 Type_Id := Get_Pragma_Arg (Arg1);
12624 Find_Type (Type_Id);
12625 Typ := Entity (Type_Id);
12627 if Typ = Any_Type then
12630 -- An invariant must apply to a private type, or appear in the
12631 -- private part of a package spec and apply to a completion.
12633 elsif Ekind_In (Typ, E_Private_Type,
12634 E_Record_Type_With_Private,
12635 E_Limited_Private_Type)
12639 elsif In_Private_Part (Current_Scope)
12640 and then Has_Private_Declaration (Typ)
12644 elsif In_Private_Part (Current_Scope) then
12646 ("pragma% only allowed for private type declared in "
12647 & "visible part", Arg1);
12651 ("pragma% only allowed for private type", Arg1);
12654 -- Note that the type has at least one invariant, and also that
12655 -- it has inheritable invariants if we have Invariant'Class.
12656 -- Build the corresponding invariant procedure declaration, so
12657 -- that calls to it can be generated before the body is built
12658 -- (for example wihin an expression function).
12660 PDecl := Build_Invariant_Procedure_Declaration (Typ);
12661 Insert_After (N, PDecl);
12664 if Class_Present (N) then
12665 Set_Has_Inheritable_Invariants (Typ);
12668 -- The remaining processing is simply to link the pragma on to
12669 -- the rep item chain, for processing when the type is frozen.
12670 -- This is accomplished by a call to Rep_Item_Too_Late.
12672 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12675 ----------------------
12676 -- Java_Constructor --
12677 ----------------------
12679 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
12681 -- Also handles pragma CIL_Constructor
12683 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
12684 Java_Constructor : declare
12685 Convention : Convention_Id;
12686 Def_Id : Entity_Id;
12687 Hom_Id : Entity_Id;
12689 This_Formal : Entity_Id;
12693 Check_Arg_Count (1);
12694 Check_Optional_Identifier (Arg1, Name_Entity);
12695 Check_Arg_Is_Local_Name (Arg1);
12697 Id := Get_Pragma_Arg (Arg1);
12698 Find_Program_Unit_Name (Id);
12700 -- If we did not find the name, we are done
12702 if Etype (Id) = Any_Type then
12706 -- Check wrong use of pragma in wrong VM target
12708 if VM_Target = No_VM then
12711 elsif VM_Target = CLI_Target
12712 and then Prag_Id = Pragma_Java_Constructor
12714 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
12716 elsif VM_Target = JVM_Target
12717 and then Prag_Id = Pragma_CIL_Constructor
12719 Error_Pragma ("must use pragma 'Java_'Constructor");
12723 when Pragma_CIL_Constructor => Convention := Convention_CIL;
12724 when Pragma_Java_Constructor => Convention := Convention_Java;
12725 when others => null;
12728 Hom_Id := Entity (Id);
12730 -- Loop through homonyms
12733 Def_Id := Get_Base_Subprogram (Hom_Id);
12735 -- The constructor is required to be a function
12737 if Ekind (Def_Id) /= E_Function then
12738 if VM_Target = JVM_Target then
12740 ("pragma% requires function returning a 'Java access "
12744 ("pragma% requires function returning a 'C'I'L access "
12749 -- Check arguments: For tagged type the first formal must be
12750 -- named "this" and its type must be a named access type
12751 -- designating a class-wide tagged type that has convention
12752 -- CIL/Java. The first formal must also have a null default
12753 -- value. For example:
12755 -- type Typ is tagged ...
12756 -- type Ref is access all Typ;
12757 -- pragma Convention (CIL, Typ);
12759 -- function New_Typ (This : Ref) return Ref;
12760 -- function New_Typ (This : Ref; I : Integer) return Ref;
12761 -- pragma Cil_Constructor (New_Typ);
12763 -- Reason: The first formal must NOT be a primitive of the
12766 -- This rule also applies to constructors of delegates used
12767 -- to interface with standard target libraries. For example:
12769 -- type Delegate is access procedure ...
12770 -- pragma Import (CIL, Delegate, ...);
12772 -- function new_Delegate
12773 -- (This : Delegate := null; ... ) return Delegate;
12775 -- For value-types this rule does not apply.
12777 if not Is_Value_Type (Etype (Def_Id)) then
12778 if No (First_Formal (Def_Id)) then
12779 Error_Msg_Name_1 := Pname;
12780 Error_Msg_N ("% function must have parameters", Def_Id);
12784 -- In the JRE library we have several occurrences in which
12785 -- the "this" parameter is not the first formal.
12787 This_Formal := First_Formal (Def_Id);
12789 -- In the JRE library we have several occurrences in which
12790 -- the "this" parameter is not the first formal. Search for
12793 if VM_Target = JVM_Target then
12794 while Present (This_Formal)
12795 and then Get_Name_String (Chars (This_Formal)) /= "this"
12797 Next_Formal (This_Formal);
12800 if No (This_Formal) then
12801 This_Formal := First_Formal (Def_Id);
12805 -- Warning: The first parameter should be named "this".
12806 -- We temporarily allow it because we have the following
12807 -- case in the Java runtime (file s-osinte.ads) ???
12809 -- function new_Thread
12810 -- (Self_Id : System.Address) return Thread_Id;
12811 -- pragma Java_Constructor (new_Thread);
12813 if VM_Target = JVM_Target
12814 and then Get_Name_String (Chars (First_Formal (Def_Id)))
12816 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
12820 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
12821 Error_Msg_Name_1 := Pname;
12823 ("first formal of % function must be named `this`",
12824 Parent (This_Formal));
12826 elsif not Is_Access_Type (Etype (This_Formal)) then
12827 Error_Msg_Name_1 := Pname;
12829 ("first formal of % function must be an access type",
12830 Parameter_Type (Parent (This_Formal)));
12832 -- For delegates the type of the first formal must be a
12833 -- named access-to-subprogram type (see previous example)
12835 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
12836 and then Ekind (Etype (This_Formal))
12837 /= E_Access_Subprogram_Type
12839 Error_Msg_Name_1 := Pname;
12841 ("first formal of % function must be a named access "
12842 & "to subprogram type",
12843 Parameter_Type (Parent (This_Formal)));
12845 -- Warning: We should reject anonymous access types because
12846 -- the constructor must not be handled as a primitive of the
12847 -- tagged type. We temporarily allow it because this profile
12848 -- is currently generated by cil2ada???
12850 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
12851 and then not Ekind_In (Etype (This_Formal),
12853 E_General_Access_Type,
12854 E_Anonymous_Access_Type)
12856 Error_Msg_Name_1 := Pname;
12858 ("first formal of % function must be a named access "
12859 & "type", Parameter_Type (Parent (This_Formal)));
12861 elsif Atree.Convention
12862 (Designated_Type (Etype (This_Formal))) /= Convention
12864 Error_Msg_Name_1 := Pname;
12866 if Convention = Convention_Java then
12868 ("pragma% requires convention 'Cil in designated "
12869 & "type", Parameter_Type (Parent (This_Formal)));
12872 ("pragma% requires convention 'Java in designated "
12873 & "type", Parameter_Type (Parent (This_Formal)));
12876 elsif No (Expression (Parent (This_Formal)))
12877 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
12879 Error_Msg_Name_1 := Pname;
12881 ("pragma% requires first formal with default `null`",
12882 Parameter_Type (Parent (This_Formal)));
12886 -- Check result type: the constructor must be a function
12888 -- * a value type (only allowed in the CIL compiler)
12889 -- * an access-to-subprogram type with convention Java/CIL
12890 -- * an access-type designating a type that has convention
12893 if Is_Value_Type (Etype (Def_Id)) then
12896 -- Access-to-subprogram type with convention Java/CIL
12898 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
12899 if Atree.Convention (Etype (Def_Id)) /= Convention then
12900 if Convention = Convention_Java then
12902 ("pragma% requires function returning a 'Java "
12903 & "access type", Arg1);
12905 pragma Assert (Convention = Convention_CIL);
12907 ("pragma% requires function returning a 'C'I'L "
12908 & "access type", Arg1);
12912 elsif Ekind (Etype (Def_Id)) in Access_Kind then
12913 if not Ekind_In (Etype (Def_Id), E_Access_Type,
12914 E_General_Access_Type)
12917 (Designated_Type (Etype (Def_Id))) /= Convention
12919 Error_Msg_Name_1 := Pname;
12921 if Convention = Convention_Java then
12923 ("pragma% requires function returning a named "
12924 & "'Java access type", Arg1);
12927 ("pragma% requires function returning a named "
12928 & "'C'I'L access type", Arg1);
12933 Set_Is_Constructor (Def_Id);
12934 Set_Convention (Def_Id, Convention);
12935 Set_Is_Imported (Def_Id);
12937 exit when From_Aspect_Specification (N);
12938 Hom_Id := Homonym (Hom_Id);
12940 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
12942 end Java_Constructor;
12944 ----------------------
12945 -- Java_Interface --
12946 ----------------------
12948 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
12950 when Pragma_Java_Interface => Java_Interface : declare
12956 Check_Arg_Count (1);
12957 Check_Optional_Identifier (Arg1, Name_Entity);
12958 Check_Arg_Is_Local_Name (Arg1);
12960 Arg := Get_Pragma_Arg (Arg1);
12963 if Etype (Arg) = Any_Type then
12967 if not Is_Entity_Name (Arg)
12968 or else not Is_Type (Entity (Arg))
12970 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
12973 Typ := Underlying_Type (Entity (Arg));
12975 -- For now simply check some of the semantic constraints on the
12976 -- type. This currently leaves out some restrictions on interface
12977 -- types, namely that the parent type must be java.lang.Object.Typ
12978 -- and that all primitives of the type should be declared
12981 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
12982 Error_Pragma_Arg ("pragma% requires an abstract "
12983 & "tagged type", Arg1);
12985 elsif not Has_Discriminants (Typ)
12986 or else Ekind (Etype (First_Discriminant (Typ)))
12987 /= E_Anonymous_Access_Type
12989 not Is_Class_Wide_Type
12990 (Designated_Type (Etype (First_Discriminant (Typ))))
12993 ("type must have a class-wide access discriminant", Arg1);
12995 end Java_Interface;
13001 -- pragma Keep_Names ([On => ] local_NAME);
13003 when Pragma_Keep_Names => Keep_Names : declare
13008 Check_Arg_Count (1);
13009 Check_Optional_Identifier (Arg1, Name_On);
13010 Check_Arg_Is_Local_Name (Arg1);
13012 Arg := Get_Pragma_Arg (Arg1);
13015 if Etype (Arg) = Any_Type then
13019 if not Is_Entity_Name (Arg)
13020 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
13023 ("pragma% requires a local enumeration type", Arg1);
13026 Set_Discard_Names (Entity (Arg), False);
13033 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
13035 when Pragma_License =>
13037 Check_Arg_Count (1);
13038 Check_No_Identifiers;
13039 Check_Valid_Configuration_Pragma;
13040 Check_Arg_Is_Identifier (Arg1);
13043 Sind : constant Source_File_Index :=
13044 Source_Index (Current_Sem_Unit);
13047 case Chars (Get_Pragma_Arg (Arg1)) is
13049 Set_License (Sind, GPL);
13051 when Name_Modified_GPL =>
13052 Set_License (Sind, Modified_GPL);
13054 when Name_Restricted =>
13055 Set_License (Sind, Restricted);
13057 when Name_Unrestricted =>
13058 Set_License (Sind, Unrestricted);
13061 Error_Pragma_Arg ("invalid license name", Arg1);
13069 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
13071 when Pragma_Link_With => Link_With : declare
13077 if Operating_Mode = Generate_Code
13078 and then In_Extended_Main_Source_Unit (N)
13080 Check_At_Least_N_Arguments (1);
13081 Check_No_Identifiers;
13082 Check_Is_In_Decl_Part_Or_Package_Spec;
13083 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13087 while Present (Arg) loop
13088 Check_Arg_Is_Static_Expression (Arg, Standard_String);
13090 -- Store argument, converting sequences of spaces to a
13091 -- single null character (this is one of the differences
13092 -- in processing between Link_With and Linker_Options).
13094 Arg_Store : declare
13095 C : constant Char_Code := Get_Char_Code (' ');
13096 S : constant String_Id :=
13097 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
13098 L : constant Nat := String_Length (S);
13101 procedure Skip_Spaces;
13102 -- Advance F past any spaces
13108 procedure Skip_Spaces is
13110 while F <= L and then Get_String_Char (S, F) = C loop
13115 -- Start of processing for Arg_Store
13118 Skip_Spaces; -- skip leading spaces
13120 -- Loop through characters, changing any embedded
13121 -- sequence of spaces to a single null character (this
13122 -- is how Link_With/Linker_Options differ)
13125 if Get_String_Char (S, F) = C then
13128 Store_String_Char (ASCII.NUL);
13131 Store_String_Char (Get_String_Char (S, F));
13139 if Present (Arg) then
13140 Store_String_Char (ASCII.NUL);
13144 Store_Linker_Option_String (End_String);
13152 -- pragma Linker_Alias (
13153 -- [Entity =>] LOCAL_NAME
13154 -- [Target =>] static_string_EXPRESSION);
13156 when Pragma_Linker_Alias =>
13158 Check_Arg_Order ((Name_Entity, Name_Target));
13159 Check_Arg_Count (2);
13160 Check_Optional_Identifier (Arg1, Name_Entity);
13161 Check_Optional_Identifier (Arg2, Name_Target);
13162 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13163 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13165 -- The only processing required is to link this item on to the
13166 -- list of rep items for the given entity. This is accomplished
13167 -- by the call to Rep_Item_Too_Late (when no error is detected
13168 -- and False is returned).
13170 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
13173 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13176 ------------------------
13177 -- Linker_Constructor --
13178 ------------------------
13180 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
13182 -- Code is shared with Linker_Destructor
13184 -----------------------
13185 -- Linker_Destructor --
13186 -----------------------
13188 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
13190 when Pragma_Linker_Constructor |
13191 Pragma_Linker_Destructor =>
13192 Linker_Constructor : declare
13198 Check_Arg_Count (1);
13199 Check_No_Identifiers;
13200 Check_Arg_Is_Local_Name (Arg1);
13201 Arg1_X := Get_Pragma_Arg (Arg1);
13203 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
13205 if not Is_Library_Level_Entity (Proc) then
13207 ("argument for pragma% must be library level entity", Arg1);
13210 -- The only processing required is to link this item on to the
13211 -- list of rep items for the given entity. This is accomplished
13212 -- by the call to Rep_Item_Too_Late (when no error is detected
13213 -- and False is returned).
13215 if Rep_Item_Too_Late (Proc, N) then
13218 Set_Has_Gigi_Rep_Item (Proc);
13220 end Linker_Constructor;
13222 --------------------
13223 -- Linker_Options --
13224 --------------------
13226 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
13228 when Pragma_Linker_Options => Linker_Options : declare
13232 Check_Ada_83_Warning;
13233 Check_No_Identifiers;
13234 Check_Arg_Count (1);
13235 Check_Is_In_Decl_Part_Or_Package_Spec;
13236 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13237 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
13240 while Present (Arg) loop
13241 Check_Arg_Is_Static_Expression (Arg, Standard_String);
13242 Store_String_Char (ASCII.NUL);
13244 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
13248 if Operating_Mode = Generate_Code
13249 and then In_Extended_Main_Source_Unit (N)
13251 Store_Linker_Option_String (End_String);
13253 end Linker_Options;
13255 --------------------
13256 -- Linker_Section --
13257 --------------------
13259 -- pragma Linker_Section (
13260 -- [Entity =>] LOCAL_NAME
13261 -- [Section =>] static_string_EXPRESSION);
13263 when Pragma_Linker_Section =>
13265 Check_Arg_Order ((Name_Entity, Name_Section));
13266 Check_Arg_Count (2);
13267 Check_Optional_Identifier (Arg1, Name_Entity);
13268 Check_Optional_Identifier (Arg2, Name_Section);
13269 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13270 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13272 -- This pragma applies only to objects
13274 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
13275 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
13278 -- The only processing required is to link this item on to the
13279 -- list of rep items for the given entity. This is accomplished
13280 -- by the call to Rep_Item_Too_Late (when no error is detected
13281 -- and False is returned).
13283 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
13286 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13293 -- pragma List (On | Off)
13295 -- There is nothing to do here, since we did all the processing for
13296 -- this pragma in Par.Prag (so that it works properly even in syntax
13299 when Pragma_List =>
13306 -- pragma Lock_Free [(Boolean_EXPRESSION)];
13308 when Pragma_Lock_Free => Lock_Free : declare
13309 P : constant Node_Id := Parent (N);
13315 Check_No_Identifiers;
13316 Check_At_Most_N_Arguments (1);
13318 -- Protected definition case
13320 if Nkind (P) = N_Protected_Definition then
13321 Ent := Defining_Identifier (Parent (P));
13325 if Arg_Count = 1 then
13326 Arg := Get_Pragma_Arg (Arg1);
13327 Val := Is_True (Static_Boolean (Arg));
13329 -- No arguments (expression is considered to be True)
13335 -- Check duplicate pragma before we chain the pragma in the Rep
13336 -- Item chain of Ent.
13338 Check_Duplicate_Pragma (Ent);
13339 Record_Rep_Item (Ent, N);
13340 Set_Uses_Lock_Free (Ent, Val);
13342 -- Anything else is incorrect placement
13349 --------------------
13350 -- Locking_Policy --
13351 --------------------
13353 -- pragma Locking_Policy (policy_IDENTIFIER);
13355 when Pragma_Locking_Policy => declare
13356 subtype LP_Range is Name_Id
13357 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
13362 Check_Ada_83_Warning;
13363 Check_Arg_Count (1);
13364 Check_No_Identifiers;
13365 Check_Arg_Is_Locking_Policy (Arg1);
13366 Check_Valid_Configuration_Pragma;
13367 LP_Val := Chars (Get_Pragma_Arg (Arg1));
13370 when Name_Ceiling_Locking =>
13372 when Name_Inheritance_Locking =>
13374 when Name_Concurrent_Readers_Locking =>
13378 if Locking_Policy /= ' '
13379 and then Locking_Policy /= LP
13381 Error_Msg_Sloc := Locking_Policy_Sloc;
13382 Error_Pragma ("locking policy incompatible with policy#");
13384 -- Set new policy, but always preserve System_Location since we
13385 -- like the error message with the run time name.
13388 Locking_Policy := LP;
13390 if Locking_Policy_Sloc /= System_Location then
13391 Locking_Policy_Sloc := Loc;
13400 -- pragma Long_Float (D_Float | G_Float);
13402 when Pragma_Long_Float => Long_Float : declare
13405 Check_Valid_Configuration_Pragma;
13406 Check_Arg_Count (1);
13407 Check_No_Identifier (Arg1);
13408 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
13410 if not OpenVMS_On_Target then
13411 Error_Pragma ("??pragma% ignored (applies only to Open'V'M'S)");
13416 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
13417 if Opt.Float_Format_Long = 'G' then
13419 ("G_Float previously specified", Arg1);
13421 elsif Current_Sem_Unit /= Main_Unit
13422 and then Opt.Float_Format_Long /= 'D'
13425 ("main unit not compiled with pragma Long_Float (D_Float)",
13426 "\pragma% must be used consistently for whole partition",
13430 Opt.Float_Format_Long := 'D';
13433 -- G_Float case (this is the default, does not need overriding)
13436 if Opt.Float_Format_Long = 'D' then
13437 Error_Pragma ("D_Float previously specified");
13439 elsif Current_Sem_Unit /= Main_Unit
13440 and then Opt.Float_Format_Long /= 'G'
13443 ("main unit not compiled with pragma Long_Float (G_Float)",
13444 "\pragma% must be used consistently for whole partition",
13448 Opt.Float_Format_Long := 'G';
13452 Set_Standard_Fpt_Formats;
13455 --------------------
13456 -- Loop_Invariant --
13457 --------------------
13459 -- pragma Loop_Invariant ( boolean_EXPRESSION );
13461 when Pragma_Loop_Invariant => Loop_Invariant : declare
13465 Check_Arg_Count (1);
13466 Check_Loop_Pragma_Placement;
13468 -- Completely ignore if disabled
13470 if not Check_Enabled (Pname) then
13471 Rewrite (N, Make_Null_Statement (Loc));
13476 Preanalyze_And_Resolve (Expression (Arg1), Any_Boolean);
13478 -- Transform pragma Loop_Invariant into equivalent pragma Check
13480 -- pragma Check (Loop_Invaraint, Arg1);
13482 -- Seems completely wrong to hijack pragma Check this way ???
13486 Chars => Name_Check,
13487 Pragma_Argument_Associations => New_List (
13488 Make_Pragma_Argument_Association (Loc,
13489 Expression => Make_Identifier (Loc, Name_Loop_Invariant)),
13490 Relocate_Node (Arg1))));
13493 end Loop_Invariant;
13495 -------------------
13496 -- Loop_Optimize --
13497 -------------------
13499 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
13501 -- OPTIMIZATION_HINT ::= No_Unroll | Unroll | No_Vector | Vector
13503 when Pragma_Loop_Optimize => Loop_Optimize : declare
13508 Check_At_Least_N_Arguments (1);
13509 Check_No_Identifiers;
13511 Hint := First (Pragma_Argument_Associations (N));
13512 while Present (Hint) loop
13513 Check_Arg_Is_One_Of (Hint,
13514 Name_No_Unroll, Name_Unroll, Name_No_Vector, Name_Vector);
13518 Check_Loop_Pragma_Placement;
13525 -- pragma Loop_Variant
13526 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
13528 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
13530 -- CHANGE_DIRECTION ::= Increases | Decreases
13532 when Pragma_Loop_Variant => Loop_Variant : declare
13538 Check_At_Least_N_Arguments (1);
13539 Check_Loop_Pragma_Placement;
13541 -- Completely ignore if disabled
13543 if not Check_Enabled (Pname) then
13544 Rewrite (N, Make_Null_Statement (Loc));
13549 -- Process all increasing / decreasing expressions
13551 Variant := First (Pragma_Argument_Associations (N));
13552 while Present (Variant) loop
13553 if Chars (Variant) /= Name_Decreases
13554 and then Chars (Variant) /= Name_Increases
13556 Error_Pragma_Arg ("wrong change modifier", Variant);
13559 Preanalyze_And_Resolve (Expression (Variant), Any_Discrete);
13565 -----------------------
13566 -- Machine_Attribute --
13567 -----------------------
13569 -- pragma Machine_Attribute (
13570 -- [Entity =>] LOCAL_NAME,
13571 -- [Attribute_Name =>] static_string_EXPRESSION
13572 -- [, [Info =>] static_EXPRESSION] );
13574 when Pragma_Machine_Attribute => Machine_Attribute : declare
13575 Def_Id : Entity_Id;
13579 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
13581 if Arg_Count = 3 then
13582 Check_Optional_Identifier (Arg3, Name_Info);
13583 Check_Arg_Is_Static_Expression (Arg3);
13585 Check_Arg_Count (2);
13588 Check_Optional_Identifier (Arg1, Name_Entity);
13589 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
13590 Check_Arg_Is_Local_Name (Arg1);
13591 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13592 Def_Id := Entity (Get_Pragma_Arg (Arg1));
13594 if Is_Access_Type (Def_Id) then
13595 Def_Id := Designated_Type (Def_Id);
13598 if Rep_Item_Too_Early (Def_Id, N) then
13602 Def_Id := Underlying_Type (Def_Id);
13604 -- The only processing required is to link this item on to the
13605 -- list of rep items for the given entity. This is accomplished
13606 -- by the call to Rep_Item_Too_Late (when no error is detected
13607 -- and False is returned).
13609 if Rep_Item_Too_Late (Def_Id, N) then
13612 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13614 end Machine_Attribute;
13621 -- (MAIN_OPTION [, MAIN_OPTION]);
13624 -- [STACK_SIZE =>] static_integer_EXPRESSION
13625 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
13626 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
13628 when Pragma_Main => Main : declare
13629 Args : Args_List (1 .. 3);
13630 Names : constant Name_List (1 .. 3) := (
13632 Name_Task_Stack_Size_Default,
13633 Name_Time_Slicing_Enabled);
13639 Gather_Associations (Names, Args);
13641 for J in 1 .. 2 loop
13642 if Present (Args (J)) then
13643 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
13647 if Present (Args (3)) then
13648 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
13652 while Present (Nod) loop
13653 if Nkind (Nod) = N_Pragma
13654 and then Pragma_Name (Nod) = Name_Main
13656 Error_Msg_Name_1 := Pname;
13657 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13668 -- pragma Main_Storage
13669 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
13671 -- MAIN_STORAGE_OPTION ::=
13672 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
13673 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
13675 when Pragma_Main_Storage => Main_Storage : declare
13676 Args : Args_List (1 .. 2);
13677 Names : constant Name_List (1 .. 2) := (
13678 Name_Working_Storage,
13685 Gather_Associations (Names, Args);
13687 for J in 1 .. 2 loop
13688 if Present (Args (J)) then
13689 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
13693 Check_In_Main_Program;
13696 while Present (Nod) loop
13697 if Nkind (Nod) = N_Pragma
13698 and then Pragma_Name (Nod) = Name_Main_Storage
13700 Error_Msg_Name_1 := Pname;
13701 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13712 -- pragma Memory_Size (NUMERIC_LITERAL)
13714 when Pragma_Memory_Size =>
13717 -- Memory size is simply ignored
13719 Check_No_Identifiers;
13720 Check_Arg_Count (1);
13721 Check_Arg_Is_Integer_Literal (Arg1);
13729 -- The only correct use of this pragma is on its own in a file, in
13730 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
13731 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
13732 -- check for a file containing nothing but a No_Body pragma). If we
13733 -- attempt to process it during normal semantics processing, it means
13734 -- it was misplaced.
13736 when Pragma_No_Body =>
13744 -- pragma No_Inline ( NAME {, NAME} );
13746 when Pragma_No_Inline =>
13748 Process_Inline (Suppressed);
13754 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
13756 when Pragma_No_Return => No_Return : declare
13764 Check_At_Least_N_Arguments (1);
13766 -- Loop through arguments of pragma
13769 while Present (Arg) loop
13770 Check_Arg_Is_Local_Name (Arg);
13771 Id := Get_Pragma_Arg (Arg);
13774 if not Is_Entity_Name (Id) then
13775 Error_Pragma_Arg ("entity name required", Arg);
13778 if Etype (Id) = Any_Type then
13782 -- Loop to find matching procedures
13787 and then Scope (E) = Current_Scope
13789 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
13792 -- Set flag on any alias as well
13794 if Is_Overloadable (E) and then Present (Alias (E)) then
13795 Set_No_Return (Alias (E));
13801 exit when From_Aspect_Specification (N);
13806 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
13817 -- pragma No_Run_Time;
13819 -- Note: this pragma is retained for backwards compatibility. See
13820 -- body of Rtsfind for full details on its handling.
13822 when Pragma_No_Run_Time =>
13824 Check_Valid_Configuration_Pragma;
13825 Check_Arg_Count (0);
13827 No_Run_Time_Mode := True;
13828 Configurable_Run_Time_Mode := True;
13830 -- Set Duration to 32 bits if word size is 32
13832 if Ttypes.System_Word_Size = 32 then
13833 Duration_32_Bits_On_Target := True;
13836 -- Set appropriate restrictions
13838 Set_Restriction (No_Finalization, N);
13839 Set_Restriction (No_Exception_Handlers, N);
13840 Set_Restriction (Max_Tasks, N, 0);
13841 Set_Restriction (No_Tasking, N);
13843 ------------------------
13844 -- No_Strict_Aliasing --
13845 ------------------------
13847 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
13849 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
13854 Check_At_Most_N_Arguments (1);
13856 if Arg_Count = 0 then
13857 Check_Valid_Configuration_Pragma;
13858 Opt.No_Strict_Aliasing := True;
13861 Check_Optional_Identifier (Arg2, Name_Entity);
13862 Check_Arg_Is_Local_Name (Arg1);
13863 E_Id := Entity (Get_Pragma_Arg (Arg1));
13865 if E_Id = Any_Type then
13867 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
13868 Error_Pragma_Arg ("pragma% requires access type", Arg1);
13871 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
13873 end No_Strict_Aliasing;
13875 -----------------------
13876 -- Normalize_Scalars --
13877 -----------------------
13879 -- pragma Normalize_Scalars;
13881 when Pragma_Normalize_Scalars =>
13882 Check_Ada_83_Warning;
13883 Check_Arg_Count (0);
13884 Check_Valid_Configuration_Pragma;
13886 -- Normalize_Scalars creates false positives in CodePeer, and
13887 -- incorrect negative results in Alfa mode, so ignore this pragma
13890 if not (CodePeer_Mode or Alfa_Mode) then
13891 Normalize_Scalars := True;
13892 Init_Or_Norm_Scalars := True;
13899 -- pragma Obsolescent;
13901 -- pragma Obsolescent (
13902 -- [Message =>] static_string_EXPRESSION
13903 -- [,[Version =>] Ada_05]]);
13905 -- pragma Obsolescent (
13906 -- [Entity =>] NAME
13907 -- [,[Message =>] static_string_EXPRESSION
13908 -- [,[Version =>] Ada_05]] );
13910 when Pragma_Obsolescent => Obsolescent : declare
13914 procedure Set_Obsolescent (E : Entity_Id);
13915 -- Given an entity Ent, mark it as obsolescent if appropriate
13917 ---------------------
13918 -- Set_Obsolescent --
13919 ---------------------
13921 procedure Set_Obsolescent (E : Entity_Id) is
13930 -- Entity name was given
13932 if Present (Ename) then
13934 -- If entity name matches, we are fine. Save entity in
13935 -- pragma argument, for ASIS use.
13937 if Chars (Ename) = Chars (Ent) then
13938 Set_Entity (Ename, Ent);
13939 Generate_Reference (Ent, Ename);
13941 -- If entity name does not match, only possibility is an
13942 -- enumeration literal from an enumeration type declaration.
13944 elsif Ekind (Ent) /= E_Enumeration_Type then
13946 ("pragma % entity name does not match declaration");
13949 Ent := First_Literal (E);
13953 ("pragma % entity name does not match any "
13954 & "enumeration literal");
13956 elsif Chars (Ent) = Chars (Ename) then
13957 Set_Entity (Ename, Ent);
13958 Generate_Reference (Ent, Ename);
13962 Ent := Next_Literal (Ent);
13968 -- Ent points to entity to be marked
13970 if Arg_Count >= 1 then
13972 -- Deal with static string argument
13974 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13975 S := Strval (Get_Pragma_Arg (Arg1));
13977 for J in 1 .. String_Length (S) loop
13978 if not In_Character_Range (Get_String_Char (S, J)) then
13980 ("pragma% argument does not allow wide characters",
13985 Obsolescent_Warnings.Append
13986 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
13988 -- Check for Ada_05 parameter
13990 if Arg_Count /= 1 then
13991 Check_Arg_Count (2);
13994 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
13997 Check_Arg_Is_Identifier (Argx);
13999 if Chars (Argx) /= Name_Ada_05 then
14000 Error_Msg_Name_2 := Name_Ada_05;
14002 ("only allowed argument for pragma% is %", Argx);
14005 if Ada_Version_Explicit < Ada_2005
14006 or else not Warn_On_Ada_2005_Compatibility
14014 -- Set flag if pragma active
14017 Set_Is_Obsolescent (Ent);
14021 end Set_Obsolescent;
14023 -- Start of processing for pragma Obsolescent
14028 Check_At_Most_N_Arguments (3);
14030 -- See if first argument specifies an entity name
14034 (Chars (Arg1) = Name_Entity
14036 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
14038 N_Operator_Symbol))
14040 Ename := Get_Pragma_Arg (Arg1);
14042 -- Eliminate first argument, so we can share processing
14046 Arg_Count := Arg_Count - 1;
14048 -- No Entity name argument given
14054 if Arg_Count >= 1 then
14055 Check_Optional_Identifier (Arg1, Name_Message);
14057 if Arg_Count = 2 then
14058 Check_Optional_Identifier (Arg2, Name_Version);
14062 -- Get immediately preceding declaration
14065 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
14069 -- Cases where we do not follow anything other than another pragma
14073 -- First case: library level compilation unit declaration with
14074 -- the pragma immediately following the declaration.
14076 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
14078 (Defining_Entity (Unit (Parent (Parent (N)))));
14081 -- Case 2: library unit placement for package
14085 Ent : constant Entity_Id := Find_Lib_Unit_Name;
14087 if Is_Package_Or_Generic_Package (Ent) then
14088 Set_Obsolescent (Ent);
14094 -- Cases where we must follow a declaration
14097 if Nkind (Decl) not in N_Declaration
14098 and then Nkind (Decl) not in N_Later_Decl_Item
14099 and then Nkind (Decl) not in N_Generic_Declaration
14100 and then Nkind (Decl) not in N_Renaming_Declaration
14103 ("pragma% misplaced, "
14104 & "must immediately follow a declaration");
14107 Set_Obsolescent (Defining_Entity (Decl));
14117 -- pragma Optimize (Time | Space | Off);
14119 -- The actual check for optimize is done in Gigi. Note that this
14120 -- pragma does not actually change the optimization setting, it
14121 -- simply checks that it is consistent with the pragma.
14123 when Pragma_Optimize =>
14124 Check_No_Identifiers;
14125 Check_Arg_Count (1);
14126 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
14128 ------------------------
14129 -- Optimize_Alignment --
14130 ------------------------
14132 -- pragma Optimize_Alignment (Time | Space | Off);
14134 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
14136 Check_No_Identifiers;
14137 Check_Arg_Count (1);
14138 Check_Valid_Configuration_Pragma;
14141 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
14145 Opt.Optimize_Alignment := 'T';
14147 Opt.Optimize_Alignment := 'S';
14149 Opt.Optimize_Alignment := 'O';
14151 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
14155 -- Set indication that mode is set locally. If we are in fact in a
14156 -- configuration pragma file, this setting is harmless since the
14157 -- switch will get reset anyway at the start of each unit.
14159 Optimize_Alignment_Local := True;
14160 end Optimize_Alignment;
14162 -------------------
14163 -- Overflow_Mode --
14164 -------------------
14166 -- pragma Overflow_Mode
14167 -- ([General => ] MODE [, [Assertions => ] MODE]);
14169 -- MODE := STRICT | MINIMIZED | ELIMINATED
14171 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
14172 -- since System.Bignums makes this assumption. This is true of nearly
14173 -- all (all?) targets.
14175 when Pragma_Overflow_Mode => Overflow_Mode : declare
14176 function Get_Overflow_Mode
14178 Arg : Node_Id) return Overflow_Mode_Type;
14179 -- Function to process one pragma argument, Arg. If an identifier
14180 -- is present, it must be Name. Mode type is returned if a valid
14181 -- argument exists, otherwise an error is signalled.
14183 -----------------------
14184 -- Get_Overflow_Mode --
14185 -----------------------
14187 function Get_Overflow_Mode
14189 Arg : Node_Id) return Overflow_Mode_Type
14191 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
14194 Check_Optional_Identifier (Arg, Name);
14195 Check_Arg_Is_Identifier (Argx);
14197 if Chars (Argx) = Name_Strict then
14200 elsif Chars (Argx) = Name_Minimized then
14203 elsif Chars (Argx) = Name_Eliminated then
14204 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
14206 ("Eliminated not implemented on this target", Argx);
14212 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
14214 end Get_Overflow_Mode;
14216 -- Start of processing for Overflow_Mode
14220 Check_At_Least_N_Arguments (1);
14221 Check_At_Most_N_Arguments (2);
14223 -- Process first argument
14225 Scope_Suppress.Overflow_Mode_General :=
14226 Get_Overflow_Mode (Name_General, Arg1);
14228 -- Case of only one argument
14230 if Arg_Count = 1 then
14231 Scope_Suppress.Overflow_Mode_Assertions :=
14232 Scope_Suppress.Overflow_Mode_General;
14234 -- Case of two arguments present
14237 Scope_Suppress.Overflow_Mode_Assertions :=
14238 Get_Overflow_Mode (Name_Assertions, Arg2);
14242 when Pragma_Overriding_Renamings =>
14243 Overriding_Renamings := True;
14249 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
14251 when Pragma_Ordered => Ordered : declare
14252 Assoc : constant Node_Id := Arg1;
14258 Check_No_Identifiers;
14259 Check_Arg_Count (1);
14260 Check_Arg_Is_Local_Name (Arg1);
14262 Type_Id := Get_Pragma_Arg (Assoc);
14263 Find_Type (Type_Id);
14264 Typ := Entity (Type_Id);
14266 if Typ = Any_Type then
14269 Typ := Underlying_Type (Typ);
14272 if not Is_Enumeration_Type (Typ) then
14273 Error_Pragma ("pragma% must specify enumeration type");
14276 Check_First_Subtype (Arg1);
14277 Set_Has_Pragma_Ordered (Base_Type (Typ));
14284 -- pragma Pack (first_subtype_LOCAL_NAME);
14286 when Pragma_Pack => Pack : declare
14287 Assoc : constant Node_Id := Arg1;
14291 Ignore : Boolean := False;
14294 Check_No_Identifiers;
14295 Check_Arg_Count (1);
14296 Check_Arg_Is_Local_Name (Arg1);
14298 Type_Id := Get_Pragma_Arg (Assoc);
14299 Find_Type (Type_Id);
14300 Typ := Entity (Type_Id);
14303 or else Rep_Item_Too_Early (Typ, N)
14307 Typ := Underlying_Type (Typ);
14310 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
14311 Error_Pragma ("pragma% must specify array or record type");
14314 Check_First_Subtype (Arg1);
14315 Check_Duplicate_Pragma (Typ);
14319 if Is_Array_Type (Typ) then
14320 Ctyp := Component_Type (Typ);
14322 -- Ignore pack that does nothing
14324 if Known_Static_Esize (Ctyp)
14325 and then Known_Static_RM_Size (Ctyp)
14326 and then Esize (Ctyp) = RM_Size (Ctyp)
14327 and then Addressable (Esize (Ctyp))
14332 -- Process OK pragma Pack. Note that if there is a separate
14333 -- component clause present, the Pack will be cancelled. This
14334 -- processing is in Freeze.
14336 if not Rep_Item_Too_Late (Typ, N) then
14338 -- In the context of static code analysis, we do not need
14339 -- complex front-end expansions related to pragma Pack,
14340 -- so disable handling of pragma Pack in these cases.
14342 if CodePeer_Mode or Alfa_Mode then
14345 -- Don't attempt any packing for VM targets. We possibly
14346 -- could deal with some cases of array bit-packing, but we
14347 -- don't bother, since this is not a typical kind of
14348 -- representation in the VM context anyway (and would not
14349 -- for example work nicely with the debugger).
14351 elsif VM_Target /= No_VM then
14352 if not GNAT_Mode then
14354 ("??pragma% ignored in this configuration");
14357 -- Normal case where we do the pack action
14361 Set_Is_Packed (Base_Type (Typ));
14362 Set_Has_Non_Standard_Rep (Base_Type (Typ));
14365 Set_Has_Pragma_Pack (Base_Type (Typ));
14369 -- For record types, the pack is always effective
14371 else pragma Assert (Is_Record_Type (Typ));
14372 if not Rep_Item_Too_Late (Typ, N) then
14374 -- Ignore pack request with warning in VM mode (skip warning
14375 -- if we are compiling GNAT run time library).
14377 if VM_Target /= No_VM then
14378 if not GNAT_Mode then
14380 ("??pragma% ignored in this configuration");
14383 -- Normal case of pack request active
14386 Set_Is_Packed (Base_Type (Typ));
14387 Set_Has_Pragma_Pack (Base_Type (Typ));
14388 Set_Has_Non_Standard_Rep (Base_Type (Typ));
14400 -- There is nothing to do here, since we did all the processing for
14401 -- this pragma in Par.Prag (so that it works properly even in syntax
14404 when Pragma_Page =>
14407 ----------------------------------
14408 -- Partition_Elaboration_Policy --
14409 ----------------------------------
14411 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
14413 when Pragma_Partition_Elaboration_Policy => declare
14414 subtype PEP_Range is Name_Id
14415 range First_Partition_Elaboration_Policy_Name
14416 .. Last_Partition_Elaboration_Policy_Name;
14417 PEP_Val : PEP_Range;
14422 Check_Arg_Count (1);
14423 Check_No_Identifiers;
14424 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
14425 Check_Valid_Configuration_Pragma;
14426 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
14429 when Name_Concurrent =>
14431 when Name_Sequential =>
14435 if Partition_Elaboration_Policy /= ' '
14436 and then Partition_Elaboration_Policy /= PEP
14438 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
14440 ("partition elaboration policy incompatible with policy#");
14442 -- Set new policy, but always preserve System_Location since we
14443 -- like the error message with the run time name.
14446 Partition_Elaboration_Policy := PEP;
14448 if Partition_Elaboration_Policy_Sloc /= System_Location then
14449 Partition_Elaboration_Policy_Sloc := Loc;
14458 -- pragma Passive [(PASSIVE_FORM)];
14460 -- PASSIVE_FORM ::= Semaphore | No
14462 when Pragma_Passive =>
14465 if Nkind (Parent (N)) /= N_Task_Definition then
14466 Error_Pragma ("pragma% must be within task definition");
14469 if Arg_Count /= 0 then
14470 Check_Arg_Count (1);
14471 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
14474 ----------------------------------
14475 -- Preelaborable_Initialization --
14476 ----------------------------------
14478 -- pragma Preelaborable_Initialization (DIRECT_NAME);
14480 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
14485 Check_Arg_Count (1);
14486 Check_No_Identifiers;
14487 Check_Arg_Is_Identifier (Arg1);
14488 Check_Arg_Is_Local_Name (Arg1);
14489 Check_First_Subtype (Arg1);
14490 Ent := Entity (Get_Pragma_Arg (Arg1));
14492 -- The pragma may come from an aspect on a private declaration,
14493 -- even if the freeze point at which this is analyzed in the
14494 -- private part after the full view.
14496 if Has_Private_Declaration (Ent)
14497 and then From_Aspect_Specification (N)
14501 elsif Is_Private_Type (Ent)
14502 or else Is_Protected_Type (Ent)
14503 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
14509 ("pragma % can only be applied to private, formal derived or "
14510 & "protected type",
14514 -- Give an error if the pragma is applied to a protected type that
14515 -- does not qualify (due to having entries, or due to components
14516 -- that do not qualify).
14518 if Is_Protected_Type (Ent)
14519 and then not Has_Preelaborable_Initialization (Ent)
14522 ("protected type & does not have preelaborable "
14523 & "initialization", Ent);
14525 -- Otherwise mark the type as definitely having preelaborable
14529 Set_Known_To_Have_Preelab_Init (Ent);
14532 if Has_Pragma_Preelab_Init (Ent)
14533 and then Warn_On_Redundant_Constructs
14535 Error_Pragma ("?r?duplicate pragma%!");
14537 Set_Has_Pragma_Preelab_Init (Ent);
14541 --------------------
14542 -- Persistent_BSS --
14543 --------------------
14545 -- pragma Persistent_BSS [(object_NAME)];
14547 when Pragma_Persistent_BSS => Persistent_BSS : declare
14554 Check_At_Most_N_Arguments (1);
14556 -- Case of application to specific object (one argument)
14558 if Arg_Count = 1 then
14559 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14561 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
14563 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
14566 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
14569 Ent := Entity (Get_Pragma_Arg (Arg1));
14570 Decl := Parent (Ent);
14572 -- Check for duplication before inserting in list of
14573 -- representation items.
14575 Check_Duplicate_Pragma (Ent);
14577 if Rep_Item_Too_Late (Ent, N) then
14581 if Present (Expression (Decl)) then
14583 ("object for pragma% cannot have initialization", Arg1);
14586 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
14588 ("object type for pragma% is not potentially persistent",
14593 Make_Linker_Section_Pragma
14594 (Ent, Sloc (N), ".persistent.bss");
14595 Insert_After (N, Prag);
14598 -- Case of use as configuration pragma with no arguments
14601 Check_Valid_Configuration_Pragma;
14602 Persistent_BSS_Mode := True;
14604 end Persistent_BSS;
14610 -- pragma Polling (ON | OFF);
14612 when Pragma_Polling =>
14614 Check_Arg_Count (1);
14615 Check_No_Identifiers;
14616 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14617 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
14619 -------------------
14620 -- Postcondition --
14621 -------------------
14623 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
14624 -- [,[Message =>] String_EXPRESSION]);
14626 when Pragma_Postcondition => Postcondition : declare
14631 Check_At_Least_N_Arguments (1);
14632 Check_At_Most_N_Arguments (2);
14633 Check_Optional_Identifier (Arg1, Name_Check);
14635 -- Verify the proper placement of the pragma. The remainder of the
14636 -- processing is found in Sem_Ch6/Sem_Ch7.
14638 Check_Precondition_Postcondition (In_Body);
14640 -- When the pragma is a source contruct and appears inside a body,
14641 -- preanalyze the boolean_expression to detect illegal forward
14645 -- pragma Postcondition (X'Old ...);
14648 if Comes_From_Source (N) and then In_Body then
14649 Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
14657 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
14658 -- [,[Message =>] String_EXPRESSION]);
14660 when Pragma_Precondition => Precondition : declare
14665 Check_At_Least_N_Arguments (1);
14666 Check_At_Most_N_Arguments (2);
14667 Check_Optional_Identifier (Arg1, Name_Check);
14668 Check_Precondition_Postcondition (In_Body);
14670 -- If in spec, nothing more to do. If in body, then we convert the
14671 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
14672 -- this whether or not precondition checks are enabled. That works
14673 -- fine since pragma Check will do this check, and will also
14674 -- analyze the condition itself in the proper context.
14679 Chars => Name_Check,
14680 Pragma_Argument_Associations => New_List (
14681 Make_Pragma_Argument_Association (Loc,
14682 Expression => Make_Identifier (Loc, Name_Precondition)),
14684 Make_Pragma_Argument_Association (Sloc (Arg1),
14685 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
14687 if Arg_Count = 2 then
14688 Append_To (Pragma_Argument_Associations (N),
14689 Make_Pragma_Argument_Association (Sloc (Arg2),
14690 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
14701 -- pragma Predicate
14702 -- ([Entity =>] type_LOCAL_NAME,
14703 -- [Check =>] EXPRESSION);
14705 when Pragma_Predicate => Predicate : declare
14710 pragma Unreferenced (Discard);
14714 Check_Arg_Count (2);
14715 Check_Optional_Identifier (Arg1, Name_Entity);
14716 Check_Optional_Identifier (Arg2, Name_Check);
14718 Check_Arg_Is_Local_Name (Arg1);
14720 Type_Id := Get_Pragma_Arg (Arg1);
14721 Find_Type (Type_Id);
14722 Typ := Entity (Type_Id);
14724 if Typ = Any_Type then
14728 -- The remaining processing is simply to link the pragma on to
14729 -- the rep item chain, for processing when the type is frozen.
14730 -- This is accomplished by a call to Rep_Item_Too_Late. We also
14731 -- mark the type as having predicates.
14733 Set_Has_Predicates (Typ);
14734 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
14741 -- pragma Preelaborate [(library_unit_NAME)];
14743 -- Set the flag Is_Preelaborated of program unit name entity
14745 when Pragma_Preelaborate => Preelaborate : declare
14746 Pa : constant Node_Id := Parent (N);
14747 Pk : constant Node_Kind := Nkind (Pa);
14751 Check_Ada_83_Warning;
14752 Check_Valid_Library_Unit_Pragma;
14754 if Nkind (N) = N_Null_Statement then
14758 Ent := Find_Lib_Unit_Name;
14759 Check_Duplicate_Pragma (Ent);
14761 -- This filters out pragmas inside generic parent then
14762 -- show up inside instantiation
14765 and then not (Pk = N_Package_Specification
14766 and then Present (Generic_Parent (Pa)))
14768 if not Debug_Flag_U then
14769 Set_Is_Preelaborated (Ent);
14770 Set_Suppress_Elaboration_Warnings (Ent);
14775 ---------------------
14776 -- Preelaborate_05 --
14777 ---------------------
14779 -- pragma Preelaborate_05 [(library_unit_NAME)];
14781 -- This pragma is useable only in GNAT_Mode, where it is used like
14782 -- pragma Preelaborate but it is only effective in Ada 2005 mode
14783 -- (otherwise it is ignored). This is used to implement AI-362 which
14784 -- recategorizes some run-time packages in Ada 2005 mode.
14786 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
14791 Check_Valid_Library_Unit_Pragma;
14793 if not GNAT_Mode then
14794 Error_Pragma ("pragma% only available in GNAT mode");
14797 if Nkind (N) = N_Null_Statement then
14801 -- This is one of the few cases where we need to test the value of
14802 -- Ada_Version_Explicit rather than Ada_Version (which is always
14803 -- set to Ada_2012 in a predefined unit), we need to know the
14804 -- explicit version set to know if this pragma is active.
14806 if Ada_Version_Explicit >= Ada_2005 then
14807 Ent := Find_Lib_Unit_Name;
14808 Set_Is_Preelaborated (Ent);
14809 Set_Suppress_Elaboration_Warnings (Ent);
14811 end Preelaborate_05;
14817 -- pragma Priority (EXPRESSION);
14819 when Pragma_Priority => Priority : declare
14820 P : constant Node_Id := Parent (N);
14825 Check_No_Identifiers;
14826 Check_Arg_Count (1);
14830 if Nkind (P) = N_Subprogram_Body then
14831 Check_In_Main_Program;
14833 Ent := Defining_Unit_Name (Specification (P));
14835 if Nkind (Ent) = N_Defining_Program_Unit_Name then
14836 Ent := Defining_Identifier (Ent);
14839 Arg := Get_Pragma_Arg (Arg1);
14840 Analyze_And_Resolve (Arg, Standard_Integer);
14844 if not Is_Static_Expression (Arg) then
14845 Flag_Non_Static_Expr
14846 ("main subprogram priority is not static!", Arg);
14849 -- If constraint error, then we already signalled an error
14851 elsif Raises_Constraint_Error (Arg) then
14854 -- Otherwise check in range
14858 Val : constant Uint := Expr_Value (Arg);
14862 or else Val > Expr_Value (Expression
14863 (Parent (RTE (RE_Max_Priority))))
14866 ("main subprogram priority is out of range", Arg1);
14872 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
14874 -- Load an arbitrary entity from System.Tasking to make sure
14875 -- this package is implicitly with'ed, since we need to have
14876 -- the tasking run-time active for the pragma Priority to have
14880 Discard : Entity_Id;
14881 pragma Warnings (Off, Discard);
14883 Discard := RTE (RE_Task_List);
14886 -- Task or Protected, must be of type Integer
14888 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
14889 Arg := Get_Pragma_Arg (Arg1);
14890 Ent := Defining_Identifier (Parent (P));
14892 -- The expression must be analyzed in the special manner
14893 -- described in "Handling of Default and Per-Object
14894 -- Expressions" in sem.ads.
14896 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
14898 if not Is_Static_Expression (Arg) then
14899 Check_Restriction (Static_Priorities, Arg);
14902 -- Anything else is incorrect
14908 -- Check duplicate pragma before we chain the pragma in the Rep
14909 -- Item chain of Ent.
14911 Check_Duplicate_Pragma (Ent);
14912 Record_Rep_Item (Ent, N);
14915 -----------------------------------
14916 -- Priority_Specific_Dispatching --
14917 -----------------------------------
14919 -- pragma Priority_Specific_Dispatching (
14920 -- policy_IDENTIFIER,
14921 -- first_priority_EXPRESSION,
14922 -- last_priority_EXPRESSION);
14924 when Pragma_Priority_Specific_Dispatching =>
14925 Priority_Specific_Dispatching : declare
14926 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
14927 -- This is the entity System.Any_Priority;
14930 Lower_Bound : Node_Id;
14931 Upper_Bound : Node_Id;
14937 Check_Arg_Count (3);
14938 Check_No_Identifiers;
14939 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
14940 Check_Valid_Configuration_Pragma;
14941 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14942 DP := Fold_Upper (Name_Buffer (1));
14944 Lower_Bound := Get_Pragma_Arg (Arg2);
14945 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
14946 Lower_Val := Expr_Value (Lower_Bound);
14948 Upper_Bound := Get_Pragma_Arg (Arg3);
14949 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
14950 Upper_Val := Expr_Value (Upper_Bound);
14952 -- It is not allowed to use Task_Dispatching_Policy and
14953 -- Priority_Specific_Dispatching in the same partition.
14955 if Task_Dispatching_Policy /= ' ' then
14956 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
14958 ("pragma% incompatible with Task_Dispatching_Policy#");
14960 -- Check lower bound in range
14962 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
14964 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
14967 ("first_priority is out of range", Arg2);
14969 -- Check upper bound in range
14971 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
14973 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
14976 ("last_priority is out of range", Arg3);
14978 -- Check that the priority range is valid
14980 elsif Lower_Val > Upper_Val then
14982 ("last_priority_expression must be greater than or equal to "
14983 & "first_priority_expression");
14985 -- Store the new policy, but always preserve System_Location since
14986 -- we like the error message with the run-time name.
14989 -- Check overlapping in the priority ranges specified in other
14990 -- Priority_Specific_Dispatching pragmas within the same
14991 -- partition. We can only check those we know about!
14994 Specific_Dispatching.First .. Specific_Dispatching.Last
14996 if Specific_Dispatching.Table (J).First_Priority in
14997 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
14998 or else Specific_Dispatching.Table (J).Last_Priority in
14999 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
15002 Specific_Dispatching.Table (J).Pragma_Loc;
15004 ("priority range overlaps with "
15005 & "Priority_Specific_Dispatching#");
15009 -- The use of Priority_Specific_Dispatching is incompatible
15010 -- with Task_Dispatching_Policy.
15012 if Task_Dispatching_Policy /= ' ' then
15013 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
15015 ("Priority_Specific_Dispatching incompatible "
15016 & "with Task_Dispatching_Policy#");
15019 -- The use of Priority_Specific_Dispatching forces ceiling
15022 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
15023 Error_Msg_Sloc := Locking_Policy_Sloc;
15025 ("Priority_Specific_Dispatching incompatible "
15026 & "with Locking_Policy#");
15028 -- Set the Ceiling_Locking policy, but preserve System_Location
15029 -- since we like the error message with the run time name.
15032 Locking_Policy := 'C';
15034 if Locking_Policy_Sloc /= System_Location then
15035 Locking_Policy_Sloc := Loc;
15039 -- Add entry in the table
15041 Specific_Dispatching.Append
15042 ((Dispatching_Policy => DP,
15043 First_Priority => UI_To_Int (Lower_Val),
15044 Last_Priority => UI_To_Int (Upper_Val),
15045 Pragma_Loc => Loc));
15047 end Priority_Specific_Dispatching;
15053 -- pragma Profile (profile_IDENTIFIER);
15055 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
15057 when Pragma_Profile =>
15059 Check_Arg_Count (1);
15060 Check_Valid_Configuration_Pragma;
15061 Check_No_Identifiers;
15064 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
15067 if Chars (Argx) = Name_Ravenscar then
15068 Set_Ravenscar_Profile (N);
15070 elsif Chars (Argx) = Name_Restricted then
15071 Set_Profile_Restrictions
15073 N, Warn => Treat_Restrictions_As_Warnings);
15075 elsif Chars (Argx) = Name_Rational then
15076 Set_Rational_Profile;
15078 elsif Chars (Argx) = Name_No_Implementation_Extensions then
15079 Set_Profile_Restrictions
15080 (No_Implementation_Extensions,
15081 N, Warn => Treat_Restrictions_As_Warnings);
15084 Error_Pragma_Arg ("& is not a valid profile", Argx);
15088 ----------------------
15089 -- Profile_Warnings --
15090 ----------------------
15092 -- pragma Profile_Warnings (profile_IDENTIFIER);
15094 -- profile_IDENTIFIER => Restricted | Ravenscar
15096 when Pragma_Profile_Warnings =>
15098 Check_Arg_Count (1);
15099 Check_Valid_Configuration_Pragma;
15100 Check_No_Identifiers;
15103 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
15106 if Chars (Argx) = Name_Ravenscar then
15107 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
15109 elsif Chars (Argx) = Name_Restricted then
15110 Set_Profile_Restrictions (Restricted, N, Warn => True);
15112 elsif Chars (Argx) = Name_No_Implementation_Extensions then
15113 Set_Profile_Restrictions
15114 (No_Implementation_Extensions, N, Warn => True);
15117 Error_Pragma_Arg ("& is not a valid profile", Argx);
15121 --------------------------
15122 -- Propagate_Exceptions --
15123 --------------------------
15125 -- pragma Propagate_Exceptions;
15127 -- Note: this pragma is obsolete and has no effect
15129 when Pragma_Propagate_Exceptions =>
15131 Check_Arg_Count (0);
15133 if In_Extended_Main_Source_Unit (N) then
15134 Propagate_Exceptions := True;
15141 -- pragma Psect_Object (
15142 -- [Internal =>] LOCAL_NAME,
15143 -- [, [External =>] EXTERNAL_SYMBOL]
15144 -- [, [Size =>] EXTERNAL_SYMBOL]);
15146 when Pragma_Psect_Object | Pragma_Common_Object =>
15147 Psect_Object : declare
15148 Args : Args_List (1 .. 3);
15149 Names : constant Name_List (1 .. 3) := (
15154 Internal : Node_Id renames Args (1);
15155 External : Node_Id renames Args (2);
15156 Size : Node_Id renames Args (3);
15158 Def_Id : Entity_Id;
15160 procedure Check_Too_Long (Arg : Node_Id);
15161 -- Posts message if the argument is an identifier with more
15162 -- than 31 characters, or a string literal with more than
15163 -- 31 characters, and we are operating under VMS
15165 --------------------
15166 -- Check_Too_Long --
15167 --------------------
15169 procedure Check_Too_Long (Arg : Node_Id) is
15170 X : constant Node_Id := Original_Node (Arg);
15173 if not Nkind_In (X, N_String_Literal, N_Identifier) then
15175 ("inappropriate argument for pragma %", Arg);
15178 if OpenVMS_On_Target then
15179 if (Nkind (X) = N_String_Literal
15180 and then String_Length (Strval (X)) > 31)
15182 (Nkind (X) = N_Identifier
15183 and then Length_Of_Name (Chars (X)) > 31)
15186 ("argument for pragma % is longer than 31 characters",
15190 end Check_Too_Long;
15192 -- Start of processing for Common_Object/Psect_Object
15196 Gather_Associations (Names, Args);
15197 Process_Extended_Import_Export_Internal_Arg (Internal);
15199 Def_Id := Entity (Internal);
15201 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
15203 ("pragma% must designate an object", Internal);
15206 Check_Too_Long (Internal);
15208 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
15210 ("cannot use pragma% for imported/exported object",
15214 if Is_Concurrent_Type (Etype (Internal)) then
15216 ("cannot specify pragma % for task/protected object",
15220 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
15222 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
15224 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
15227 if Ekind (Def_Id) = E_Constant then
15229 ("cannot specify pragma % for a constant", Internal);
15232 if Is_Record_Type (Etype (Internal)) then
15238 Ent := First_Entity (Etype (Internal));
15239 while Present (Ent) loop
15240 Decl := Declaration_Node (Ent);
15242 if Ekind (Ent) = E_Component
15243 and then Nkind (Decl) = N_Component_Declaration
15244 and then Present (Expression (Decl))
15245 and then Warn_On_Export_Import
15248 ("?x?object for pragma % has defaults", Internal);
15258 if Present (Size) then
15259 Check_Too_Long (Size);
15262 if Present (External) then
15263 Check_Arg_Is_External_Name (External);
15264 Check_Too_Long (External);
15267 -- If all error tests pass, link pragma on to the rep item chain
15269 Record_Rep_Item (Def_Id, N);
15276 -- pragma Pure [(library_unit_NAME)];
15278 when Pragma_Pure => Pure : declare
15282 Check_Ada_83_Warning;
15283 Check_Valid_Library_Unit_Pragma;
15285 if Nkind (N) = N_Null_Statement then
15289 Ent := Find_Lib_Unit_Name;
15291 Set_Has_Pragma_Pure (Ent);
15292 Set_Suppress_Elaboration_Warnings (Ent);
15299 -- pragma Pure_05 [(library_unit_NAME)];
15301 -- This pragma is useable only in GNAT_Mode, where it is used like
15302 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
15303 -- it is ignored). It may be used after a pragma Preelaborate, in
15304 -- which case it overrides the effect of the pragma Preelaborate.
15305 -- This is used to implement AI-362 which recategorizes some run-time
15306 -- packages in Ada 2005 mode.
15308 when Pragma_Pure_05 => Pure_05 : declare
15313 Check_Valid_Library_Unit_Pragma;
15315 if not GNAT_Mode then
15316 Error_Pragma ("pragma% only available in GNAT mode");
15319 if Nkind (N) = N_Null_Statement then
15323 -- This is one of the few cases where we need to test the value of
15324 -- Ada_Version_Explicit rather than Ada_Version (which is always
15325 -- set to Ada_2012 in a predefined unit), we need to know the
15326 -- explicit version set to know if this pragma is active.
15328 if Ada_Version_Explicit >= Ada_2005 then
15329 Ent := Find_Lib_Unit_Name;
15330 Set_Is_Preelaborated (Ent, False);
15332 Set_Suppress_Elaboration_Warnings (Ent);
15340 -- pragma Pure_12 [(library_unit_NAME)];
15342 -- This pragma is useable only in GNAT_Mode, where it is used like
15343 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
15344 -- it is ignored). It may be used after a pragma Preelaborate, in
15345 -- which case it overrides the effect of the pragma Preelaborate.
15346 -- This is used to implement AI05-0212 which recategorizes some
15347 -- run-time packages in Ada 2012 mode.
15349 when Pragma_Pure_12 => Pure_12 : declare
15354 Check_Valid_Library_Unit_Pragma;
15356 if not GNAT_Mode then
15357 Error_Pragma ("pragma% only available in GNAT mode");
15360 if Nkind (N) = N_Null_Statement then
15364 -- This is one of the few cases where we need to test the value of
15365 -- Ada_Version_Explicit rather than Ada_Version (which is always
15366 -- set to Ada_2012 in a predefined unit), we need to know the
15367 -- explicit version set to know if this pragma is active.
15369 if Ada_Version_Explicit >= Ada_2012 then
15370 Ent := Find_Lib_Unit_Name;
15371 Set_Is_Preelaborated (Ent, False);
15373 Set_Suppress_Elaboration_Warnings (Ent);
15377 -------------------
15378 -- Pure_Function --
15379 -------------------
15381 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
15383 when Pragma_Pure_Function => Pure_Function : declare
15386 Def_Id : Entity_Id;
15387 Effective : Boolean := False;
15391 Check_Arg_Count (1);
15392 Check_Optional_Identifier (Arg1, Name_Entity);
15393 Check_Arg_Is_Local_Name (Arg1);
15394 E_Id := Get_Pragma_Arg (Arg1);
15396 if Error_Posted (E_Id) then
15400 -- Loop through homonyms (overloadings) of referenced entity
15402 E := Entity (E_Id);
15404 if Present (E) then
15406 Def_Id := Get_Base_Subprogram (E);
15408 if not Ekind_In (Def_Id, E_Function,
15409 E_Generic_Function,
15413 ("pragma% requires a function name", Arg1);
15416 Set_Is_Pure (Def_Id);
15418 if not Has_Pragma_Pure_Function (Def_Id) then
15419 Set_Has_Pragma_Pure_Function (Def_Id);
15423 exit when From_Aspect_Specification (N);
15425 exit when No (E) or else Scope (E) /= Current_Scope;
15429 and then Warn_On_Redundant_Constructs
15432 ("pragma Pure_Function on& is redundant?r?",
15438 --------------------
15439 -- Queuing_Policy --
15440 --------------------
15442 -- pragma Queuing_Policy (policy_IDENTIFIER);
15444 when Pragma_Queuing_Policy => declare
15448 Check_Ada_83_Warning;
15449 Check_Arg_Count (1);
15450 Check_No_Identifiers;
15451 Check_Arg_Is_Queuing_Policy (Arg1);
15452 Check_Valid_Configuration_Pragma;
15453 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15454 QP := Fold_Upper (Name_Buffer (1));
15456 if Queuing_Policy /= ' '
15457 and then Queuing_Policy /= QP
15459 Error_Msg_Sloc := Queuing_Policy_Sloc;
15460 Error_Pragma ("queuing policy incompatible with policy#");
15462 -- Set new policy, but always preserve System_Location since we
15463 -- like the error message with the run time name.
15466 Queuing_Policy := QP;
15468 if Queuing_Policy_Sloc /= System_Location then
15469 Queuing_Policy_Sloc := Loc;
15478 -- pragma Rational, for compatibility with foreign compiler
15480 when Pragma_Rational =>
15481 Set_Rational_Profile;
15483 -----------------------
15484 -- Relative_Deadline --
15485 -----------------------
15487 -- pragma Relative_Deadline (time_span_EXPRESSION);
15489 when Pragma_Relative_Deadline => Relative_Deadline : declare
15490 P : constant Node_Id := Parent (N);
15495 Check_No_Identifiers;
15496 Check_Arg_Count (1);
15498 Arg := Get_Pragma_Arg (Arg1);
15500 -- The expression must be analyzed in the special manner described
15501 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
15503 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
15507 if Nkind (P) = N_Subprogram_Body then
15508 Check_In_Main_Program;
15510 -- Only Task and subprogram cases allowed
15512 elsif Nkind (P) /= N_Task_Definition then
15516 -- Check duplicate pragma before we set the corresponding flag
15518 if Has_Relative_Deadline_Pragma (P) then
15519 Error_Pragma ("duplicate pragma% not allowed");
15522 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
15523 -- Relative_Deadline pragma node cannot be inserted in the Rep
15524 -- Item chain of Ent since it is rewritten by the expander as a
15525 -- procedure call statement that will break the chain.
15527 Set_Has_Relative_Deadline_Pragma (P, True);
15528 end Relative_Deadline;
15530 ------------------------
15531 -- Remote_Access_Type --
15532 ------------------------
15534 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
15536 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
15541 Check_Arg_Count (1);
15542 Check_Optional_Identifier (Arg1, Name_Entity);
15543 Check_Arg_Is_Local_Name (Arg1);
15545 E := Entity (Get_Pragma_Arg (Arg1));
15547 if Nkind (Parent (E)) = N_Formal_Type_Declaration
15548 and then Ekind (E) = E_General_Access_Type
15549 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
15550 and then Scope (Root_Type (Directly_Designated_Type (E)))
15552 and then Is_Valid_Remote_Object_Type
15553 (Root_Type (Directly_Designated_Type (E)))
15555 Set_Is_Remote_Types (E);
15559 ("pragma% applies only to formal access to classwide types",
15562 end Remote_Access_Type;
15564 ---------------------------
15565 -- Remote_Call_Interface --
15566 ---------------------------
15568 -- pragma Remote_Call_Interface [(library_unit_NAME)];
15570 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
15571 Cunit_Node : Node_Id;
15572 Cunit_Ent : Entity_Id;
15576 Check_Ada_83_Warning;
15577 Check_Valid_Library_Unit_Pragma;
15579 if Nkind (N) = N_Null_Statement then
15583 Cunit_Node := Cunit (Current_Sem_Unit);
15584 K := Nkind (Unit (Cunit_Node));
15585 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15587 if K = N_Package_Declaration
15588 or else K = N_Generic_Package_Declaration
15589 or else K = N_Subprogram_Declaration
15590 or else K = N_Generic_Subprogram_Declaration
15591 or else (K = N_Subprogram_Body
15592 and then Acts_As_Spec (Unit (Cunit_Node)))
15597 "pragma% must apply to package or subprogram declaration");
15600 Set_Is_Remote_Call_Interface (Cunit_Ent);
15601 end Remote_Call_Interface;
15607 -- pragma Remote_Types [(library_unit_NAME)];
15609 when Pragma_Remote_Types => Remote_Types : declare
15610 Cunit_Node : Node_Id;
15611 Cunit_Ent : Entity_Id;
15614 Check_Ada_83_Warning;
15615 Check_Valid_Library_Unit_Pragma;
15617 if Nkind (N) = N_Null_Statement then
15621 Cunit_Node := Cunit (Current_Sem_Unit);
15622 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15624 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
15625 N_Generic_Package_Declaration)
15628 ("pragma% can only apply to a package declaration");
15631 Set_Is_Remote_Types (Cunit_Ent);
15638 -- pragma Ravenscar;
15640 when Pragma_Ravenscar =>
15642 Check_Arg_Count (0);
15643 Check_Valid_Configuration_Pragma;
15644 Set_Ravenscar_Profile (N);
15646 if Warn_On_Obsolescent_Feature then
15648 ("pragma Ravenscar is an obsolescent feature?j?", N);
15650 ("|use pragma Profile (Ravenscar) instead?j?", N);
15653 -------------------------
15654 -- Restricted_Run_Time --
15655 -------------------------
15657 -- pragma Restricted_Run_Time;
15659 when Pragma_Restricted_Run_Time =>
15661 Check_Arg_Count (0);
15662 Check_Valid_Configuration_Pragma;
15663 Set_Profile_Restrictions
15664 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
15666 if Warn_On_Obsolescent_Feature then
15668 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
15671 ("|use pragma Profile (Restricted) instead?j?", N);
15678 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
15681 -- restriction_IDENTIFIER
15682 -- | restriction_parameter_IDENTIFIER => EXPRESSION
15684 when Pragma_Restrictions =>
15685 Process_Restrictions_Or_Restriction_Warnings
15686 (Warn => Treat_Restrictions_As_Warnings);
15688 --------------------------
15689 -- Restriction_Warnings --
15690 --------------------------
15692 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
15695 -- restriction_IDENTIFIER
15696 -- | restriction_parameter_IDENTIFIER => EXPRESSION
15698 when Pragma_Restriction_Warnings =>
15700 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
15706 -- pragma Reviewable;
15708 when Pragma_Reviewable =>
15709 Check_Ada_83_Warning;
15710 Check_Arg_Count (0);
15712 -- Call dummy debugging function rv. This is done to assist front
15713 -- end debugging. By placing a Reviewable pragma in the source
15714 -- program, a breakpoint on rv catches this place in the source,
15715 -- allowing convenient stepping to the point of interest.
15719 --------------------------
15720 -- Short_Circuit_And_Or --
15721 --------------------------
15723 when Pragma_Short_Circuit_And_Or =>
15725 Check_Arg_Count (0);
15726 Check_Valid_Configuration_Pragma;
15727 Short_Circuit_And_Or := True;
15729 -------------------
15730 -- Share_Generic --
15731 -------------------
15733 -- pragma Share_Generic (NAME {, NAME});
15735 when Pragma_Share_Generic =>
15737 Process_Generic_List;
15743 -- pragma Shared (LOCAL_NAME);
15745 when Pragma_Shared =>
15747 Process_Atomic_Shared_Volatile;
15749 --------------------
15750 -- Shared_Passive --
15751 --------------------
15753 -- pragma Shared_Passive [(library_unit_NAME)];
15755 -- Set the flag Is_Shared_Passive of program unit name entity
15757 when Pragma_Shared_Passive => Shared_Passive : declare
15758 Cunit_Node : Node_Id;
15759 Cunit_Ent : Entity_Id;
15762 Check_Ada_83_Warning;
15763 Check_Valid_Library_Unit_Pragma;
15765 if Nkind (N) = N_Null_Statement then
15769 Cunit_Node := Cunit (Current_Sem_Unit);
15770 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15772 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
15773 N_Generic_Package_Declaration)
15776 ("pragma% can only apply to a package declaration");
15779 Set_Is_Shared_Passive (Cunit_Ent);
15780 end Shared_Passive;
15782 -----------------------
15783 -- Short_Descriptors --
15784 -----------------------
15786 -- pragma Short_Descriptors;
15788 when Pragma_Short_Descriptors =>
15790 Check_Arg_Count (0);
15791 Check_Valid_Configuration_Pragma;
15792 Short_Descriptors := True;
15794 ------------------------------
15795 -- Simple_Storage_Pool_Type --
15796 ------------------------------
15798 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
15800 when Pragma_Simple_Storage_Pool_Type =>
15801 Simple_Storage_Pool_Type : declare
15807 Check_Arg_Count (1);
15808 Check_Arg_Is_Library_Level_Local_Name (Arg1);
15810 Type_Id := Get_Pragma_Arg (Arg1);
15811 Find_Type (Type_Id);
15812 Typ := Entity (Type_Id);
15814 if Typ = Any_Type then
15818 -- We require the pragma to apply to a type declared in a package
15819 -- declaration, but not (immediately) within a package body.
15821 if Ekind (Current_Scope) /= E_Package
15822 or else In_Package_Body (Current_Scope)
15825 ("pragma% can only apply to type declared immediately "
15826 & "within a package declaration");
15829 -- A simple storage pool type must be an immutably limited record
15830 -- or private type. If the pragma is given for a private type,
15831 -- the full type is similarly restricted (which is checked later
15832 -- in Freeze_Entity).
15834 if Is_Record_Type (Typ)
15835 and then not Is_Immutably_Limited_Type (Typ)
15838 ("pragma% can only apply to explicitly limited record type");
15840 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
15842 ("pragma% can only apply to a private type that is limited");
15844 elsif not Is_Record_Type (Typ)
15845 and then not Is_Private_Type (Typ)
15848 ("pragma% can only apply to limited record or private type");
15851 Record_Rep_Item (Typ, N);
15852 end Simple_Storage_Pool_Type;
15854 ----------------------
15855 -- Source_File_Name --
15856 ----------------------
15858 -- There are five forms for this pragma:
15860 -- pragma Source_File_Name (
15861 -- [UNIT_NAME =>] unit_NAME,
15862 -- BODY_FILE_NAME => STRING_LITERAL
15863 -- [, [INDEX =>] INTEGER_LITERAL]);
15865 -- pragma Source_File_Name (
15866 -- [UNIT_NAME =>] unit_NAME,
15867 -- SPEC_FILE_NAME => STRING_LITERAL
15868 -- [, [INDEX =>] INTEGER_LITERAL]);
15870 -- pragma Source_File_Name (
15871 -- BODY_FILE_NAME => STRING_LITERAL
15872 -- [, DOT_REPLACEMENT => STRING_LITERAL]
15873 -- [, CASING => CASING_SPEC]);
15875 -- pragma Source_File_Name (
15876 -- SPEC_FILE_NAME => STRING_LITERAL
15877 -- [, DOT_REPLACEMENT => STRING_LITERAL]
15878 -- [, CASING => CASING_SPEC]);
15880 -- pragma Source_File_Name (
15881 -- SUBUNIT_FILE_NAME => STRING_LITERAL
15882 -- [, DOT_REPLACEMENT => STRING_LITERAL]
15883 -- [, CASING => CASING_SPEC]);
15885 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
15887 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
15888 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
15889 -- only be used when no project file is used, while SFNP can only be
15890 -- used when a project file is used.
15892 -- No processing here. Processing was completed during parsing, since
15893 -- we need to have file names set as early as possible. Units are
15894 -- loaded well before semantic processing starts.
15896 -- The only processing we defer to this point is the check for
15897 -- correct placement.
15899 when Pragma_Source_File_Name =>
15901 Check_Valid_Configuration_Pragma;
15903 ------------------------------
15904 -- Source_File_Name_Project --
15905 ------------------------------
15907 -- See Source_File_Name for syntax
15909 -- No processing here. Processing was completed during parsing, since
15910 -- we need to have file names set as early as possible. Units are
15911 -- loaded well before semantic processing starts.
15913 -- The only processing we defer to this point is the check for
15914 -- correct placement.
15916 when Pragma_Source_File_Name_Project =>
15918 Check_Valid_Configuration_Pragma;
15920 -- Check that a pragma Source_File_Name_Project is used only in a
15921 -- configuration pragmas file.
15923 -- Pragmas Source_File_Name_Project should only be generated by
15924 -- the Project Manager in configuration pragmas files.
15926 -- This is really an ugly test. It seems to depend on some
15927 -- accidental and undocumented property. At the very least it
15928 -- needs to be documented, but it would be better to have a
15929 -- clean way of testing if we are in a configuration file???
15931 if Present (Parent (N)) then
15933 ("pragma% can only appear in a configuration pragmas file");
15936 ----------------------
15937 -- Source_Reference --
15938 ----------------------
15940 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
15942 -- Nothing to do, all processing completed in Par.Prag, since we need
15943 -- the information for possible parser messages that are output.
15945 when Pragma_Source_Reference =>
15948 --------------------------------
15949 -- Static_Elaboration_Desired --
15950 --------------------------------
15952 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
15954 when Pragma_Static_Elaboration_Desired =>
15956 Check_At_Most_N_Arguments (1);
15958 if Is_Compilation_Unit (Current_Scope)
15959 and then Ekind (Current_Scope) = E_Package
15961 Set_Static_Elaboration_Desired (Current_Scope, True);
15963 Error_Pragma ("pragma% must apply to a library-level package");
15970 -- pragma Storage_Size (EXPRESSION);
15972 when Pragma_Storage_Size => Storage_Size : declare
15973 P : constant Node_Id := Parent (N);
15977 Check_No_Identifiers;
15978 Check_Arg_Count (1);
15980 -- The expression must be analyzed in the special manner described
15981 -- in "Handling of Default Expressions" in sem.ads.
15983 Arg := Get_Pragma_Arg (Arg1);
15984 Preanalyze_Spec_Expression (Arg, Any_Integer);
15986 if not Is_Static_Expression (Arg) then
15987 Check_Restriction (Static_Storage_Size, Arg);
15990 if Nkind (P) /= N_Task_Definition then
15995 if Has_Storage_Size_Pragma (P) then
15996 Error_Pragma ("duplicate pragma% not allowed");
15998 Set_Has_Storage_Size_Pragma (P, True);
16001 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
16009 -- pragma Storage_Unit (NUMERIC_LITERAL);
16011 -- Only permitted argument is System'Storage_Unit value
16013 when Pragma_Storage_Unit =>
16014 Check_No_Identifiers;
16015 Check_Arg_Count (1);
16016 Check_Arg_Is_Integer_Literal (Arg1);
16018 if Intval (Get_Pragma_Arg (Arg1)) /=
16019 UI_From_Int (Ttypes.System_Storage_Unit)
16021 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
16023 ("the only allowed argument for pragma% is ^", Arg1);
16026 --------------------
16027 -- Stream_Convert --
16028 --------------------
16030 -- pragma Stream_Convert (
16031 -- [Entity =>] type_LOCAL_NAME,
16032 -- [Read =>] function_NAME,
16033 -- [Write =>] function NAME);
16035 when Pragma_Stream_Convert => Stream_Convert : declare
16037 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
16038 -- Check that the given argument is the name of a local function
16039 -- of one argument that is not overloaded earlier in the current
16040 -- local scope. A check is also made that the argument is a
16041 -- function with one parameter.
16043 --------------------------------------
16044 -- Check_OK_Stream_Convert_Function --
16045 --------------------------------------
16047 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
16051 Check_Arg_Is_Local_Name (Arg);
16052 Ent := Entity (Get_Pragma_Arg (Arg));
16054 if Has_Homonym (Ent) then
16056 ("argument for pragma% may not be overloaded", Arg);
16059 if Ekind (Ent) /= E_Function
16060 or else No (First_Formal (Ent))
16061 or else Present (Next_Formal (First_Formal (Ent)))
16064 ("argument for pragma% must be function of one argument",
16067 end Check_OK_Stream_Convert_Function;
16069 -- Start of processing for Stream_Convert
16073 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
16074 Check_Arg_Count (3);
16075 Check_Optional_Identifier (Arg1, Name_Entity);
16076 Check_Optional_Identifier (Arg2, Name_Read);
16077 Check_Optional_Identifier (Arg3, Name_Write);
16078 Check_Arg_Is_Local_Name (Arg1);
16079 Check_OK_Stream_Convert_Function (Arg2);
16080 Check_OK_Stream_Convert_Function (Arg3);
16083 Typ : constant Entity_Id :=
16084 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
16085 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
16086 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
16089 Check_First_Subtype (Arg1);
16091 -- Check for too early or too late. Note that we don't enforce
16092 -- the rule about primitive operations in this case, since, as
16093 -- is the case for explicit stream attributes themselves, these
16094 -- restrictions are not appropriate. Note that the chaining of
16095 -- the pragma by Rep_Item_Too_Late is actually the critical
16096 -- processing done for this pragma.
16098 if Rep_Item_Too_Early (Typ, N)
16100 Rep_Item_Too_Late (Typ, N, FOnly => True)
16105 -- Return if previous error
16107 if Etype (Typ) = Any_Type
16109 Etype (Read) = Any_Type
16111 Etype (Write) = Any_Type
16118 if Underlying_Type (Etype (Read)) /= Typ then
16120 ("incorrect return type for function&", Arg2);
16123 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
16125 ("incorrect parameter type for function&", Arg3);
16128 if Underlying_Type (Etype (First_Formal (Read))) /=
16129 Underlying_Type (Etype (Write))
16132 ("result type of & does not match Read parameter type",
16136 end Stream_Convert;
16142 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
16144 -- This is processed by the parser since some of the style checks
16145 -- take place during source scanning and parsing. This means that
16146 -- we don't need to issue error messages here.
16148 when Pragma_Style_Checks => Style_Checks : declare
16149 A : constant Node_Id := Get_Pragma_Arg (Arg1);
16155 Check_No_Identifiers;
16157 -- Two argument form
16159 if Arg_Count = 2 then
16160 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16167 E_Id := Get_Pragma_Arg (Arg2);
16170 if not Is_Entity_Name (E_Id) then
16172 ("second argument of pragma% must be entity name",
16176 E := Entity (E_Id);
16178 if not Ignore_Style_Checks_Pragmas then
16183 Set_Suppress_Style_Checks
16184 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
16185 exit when No (Homonym (E));
16192 -- One argument form
16195 Check_Arg_Count (1);
16197 if Nkind (A) = N_String_Literal then
16201 Slen : constant Natural := Natural (String_Length (S));
16202 Options : String (1 .. Slen);
16208 C := Get_String_Char (S, Int (J));
16209 exit when not In_Character_Range (C);
16210 Options (J) := Get_Character (C);
16212 -- If at end of string, set options. As per discussion
16213 -- above, no need to check for errors, since we issued
16214 -- them in the parser.
16217 if not Ignore_Style_Checks_Pragmas then
16218 Set_Style_Check_Options (Options);
16228 elsif Nkind (A) = N_Identifier then
16229 if Chars (A) = Name_All_Checks then
16230 if not Ignore_Style_Checks_Pragmas then
16232 Set_GNAT_Style_Check_Options;
16234 Set_Default_Style_Check_Options;
16238 elsif Chars (A) = Name_On then
16239 if not Ignore_Style_Checks_Pragmas then
16240 Style_Check := True;
16243 elsif Chars (A) = Name_Off then
16244 if not Ignore_Style_Checks_Pragmas then
16245 Style_Check := False;
16256 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
16258 when Pragma_Subtitle =>
16260 Check_Arg_Count (1);
16261 Check_Optional_Identifier (Arg1, Name_Subtitle);
16262 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
16269 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
16271 when Pragma_Suppress =>
16272 Process_Suppress_Unsuppress (True);
16278 -- pragma Suppress_All;
16280 -- The only check made here is that the pragma has no arguments.
16281 -- There are no placement rules, and the processing required (setting
16282 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
16283 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
16284 -- then creates and inserts a pragma Suppress (All_Checks).
16286 when Pragma_Suppress_All =>
16288 Check_Arg_Count (0);
16290 -------------------------
16291 -- Suppress_Debug_Info --
16292 -------------------------
16294 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
16296 when Pragma_Suppress_Debug_Info =>
16298 Check_Arg_Count (1);
16299 Check_Optional_Identifier (Arg1, Name_Entity);
16300 Check_Arg_Is_Local_Name (Arg1);
16301 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
16303 ----------------------------------
16304 -- Suppress_Exception_Locations --
16305 ----------------------------------
16307 -- pragma Suppress_Exception_Locations;
16309 when Pragma_Suppress_Exception_Locations =>
16311 Check_Arg_Count (0);
16312 Check_Valid_Configuration_Pragma;
16313 Exception_Locations_Suppressed := True;
16315 -----------------------------
16316 -- Suppress_Initialization --
16317 -----------------------------
16319 -- pragma Suppress_Initialization ([Entity =>] type_Name);
16321 when Pragma_Suppress_Initialization => Suppress_Init : declare
16327 Check_Arg_Count (1);
16328 Check_Optional_Identifier (Arg1, Name_Entity);
16329 Check_Arg_Is_Local_Name (Arg1);
16331 E_Id := Get_Pragma_Arg (Arg1);
16333 if Etype (E_Id) = Any_Type then
16337 E := Entity (E_Id);
16339 if not Is_Type (E) then
16340 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
16343 if Rep_Item_Too_Early (E, N)
16345 Rep_Item_Too_Late (E, N, FOnly => True)
16350 -- For incomplete/private type, set flag on full view
16352 if Is_Incomplete_Or_Private_Type (E) then
16353 if No (Full_View (Base_Type (E))) then
16355 ("argument of pragma% cannot be an incomplete type", Arg1);
16357 Set_Suppress_Initialization (Full_View (Base_Type (E)));
16360 -- For first subtype, set flag on base type
16362 elsif Is_First_Subtype (E) then
16363 Set_Suppress_Initialization (Base_Type (E));
16365 -- For other than first subtype, set flag on subtype itself
16368 Set_Suppress_Initialization (E);
16376 -- pragma System_Name (DIRECT_NAME);
16378 -- Syntax check: one argument, which must be the identifier GNAT or
16379 -- the identifier GCC, no other identifiers are acceptable.
16381 when Pragma_System_Name =>
16383 Check_No_Identifiers;
16384 Check_Arg_Count (1);
16385 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
16387 -----------------------------
16388 -- Task_Dispatching_Policy --
16389 -----------------------------
16391 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
16393 when Pragma_Task_Dispatching_Policy => declare
16397 Check_Ada_83_Warning;
16398 Check_Arg_Count (1);
16399 Check_No_Identifiers;
16400 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
16401 Check_Valid_Configuration_Pragma;
16402 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16403 DP := Fold_Upper (Name_Buffer (1));
16405 if Task_Dispatching_Policy /= ' '
16406 and then Task_Dispatching_Policy /= DP
16408 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
16410 ("task dispatching policy incompatible with policy#");
16412 -- Set new policy, but always preserve System_Location since we
16413 -- like the error message with the run time name.
16416 Task_Dispatching_Policy := DP;
16418 if Task_Dispatching_Policy_Sloc /= System_Location then
16419 Task_Dispatching_Policy_Sloc := Loc;
16428 -- pragma Task_Info (EXPRESSION);
16430 when Pragma_Task_Info => Task_Info : declare
16431 P : constant Node_Id := Parent (N);
16437 if Nkind (P) /= N_Task_Definition then
16438 Error_Pragma ("pragma% must appear in task definition");
16441 Check_No_Identifiers;
16442 Check_Arg_Count (1);
16444 Analyze_And_Resolve
16445 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
16447 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
16451 Ent := Defining_Identifier (Parent (P));
16453 -- Check duplicate pragma before we chain the pragma in the Rep
16454 -- Item chain of Ent.
16457 (Ent, Name_Task_Info, Check_Parents => False)
16459 Error_Pragma ("duplicate pragma% not allowed");
16462 Record_Rep_Item (Ent, N);
16469 -- pragma Task_Name (string_EXPRESSION);
16471 when Pragma_Task_Name => Task_Name : declare
16472 P : constant Node_Id := Parent (N);
16477 Check_No_Identifiers;
16478 Check_Arg_Count (1);
16480 Arg := Get_Pragma_Arg (Arg1);
16482 -- The expression is used in the call to Create_Task, and must be
16483 -- expanded there, not in the context of the current spec. It must
16484 -- however be analyzed to capture global references, in case it
16485 -- appears in a generic context.
16487 Preanalyze_And_Resolve (Arg, Standard_String);
16489 if Nkind (P) /= N_Task_Definition then
16493 Ent := Defining_Identifier (Parent (P));
16495 -- Check duplicate pragma before we chain the pragma in the Rep
16496 -- Item chain of Ent.
16499 (Ent, Name_Task_Name, Check_Parents => False)
16501 Error_Pragma ("duplicate pragma% not allowed");
16504 Record_Rep_Item (Ent, N);
16511 -- pragma Task_Storage (
16512 -- [Task_Type =>] LOCAL_NAME,
16513 -- [Top_Guard =>] static_integer_EXPRESSION);
16515 when Pragma_Task_Storage => Task_Storage : declare
16516 Args : Args_List (1 .. 2);
16517 Names : constant Name_List (1 .. 2) := (
16521 Task_Type : Node_Id renames Args (1);
16522 Top_Guard : Node_Id renames Args (2);
16528 Gather_Associations (Names, Args);
16530 if No (Task_Type) then
16532 ("missing task_type argument for pragma%");
16535 Check_Arg_Is_Local_Name (Task_Type);
16537 Ent := Entity (Task_Type);
16539 if not Is_Task_Type (Ent) then
16541 ("argument for pragma% must be task type", Task_Type);
16544 if No (Top_Guard) then
16546 ("pragma% takes two arguments", Task_Type);
16548 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
16551 Check_First_Subtype (Task_Type);
16553 if Rep_Item_Too_Late (Ent, N) then
16562 -- pragma Test_Case
16563 -- ([Name =>] Static_String_EXPRESSION
16564 -- ,[Mode =>] MODE_TYPE
16565 -- [, Requires => Boolean_EXPRESSION]
16566 -- [, Ensures => Boolean_EXPRESSION]);
16568 -- MODE_TYPE ::= Nominal | Robustness
16570 when Pragma_Test_Case =>
16571 Check_Contract_Or_Test_Case;
16573 --------------------------
16574 -- Thread_Local_Storage --
16575 --------------------------
16577 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
16579 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
16585 Check_Arg_Count (1);
16586 Check_Optional_Identifier (Arg1, Name_Entity);
16587 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16589 Id := Get_Pragma_Arg (Arg1);
16592 if not Is_Entity_Name (Id)
16593 or else Ekind (Entity (Id)) /= E_Variable
16595 Error_Pragma_Arg ("local variable name required", Arg1);
16600 if Rep_Item_Too_Early (E, N)
16601 or else Rep_Item_Too_Late (E, N)
16606 Set_Has_Pragma_Thread_Local_Storage (E);
16607 Set_Has_Gigi_Rep_Item (E);
16608 end Thread_Local_Storage;
16614 -- pragma Time_Slice (static_duration_EXPRESSION);
16616 when Pragma_Time_Slice => Time_Slice : declare
16622 Check_Arg_Count (1);
16623 Check_No_Identifiers;
16624 Check_In_Main_Program;
16625 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
16627 if not Error_Posted (Arg1) then
16629 while Present (Nod) loop
16630 if Nkind (Nod) = N_Pragma
16631 and then Pragma_Name (Nod) = Name_Time_Slice
16633 Error_Msg_Name_1 := Pname;
16634 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16641 -- Process only if in main unit
16643 if Get_Source_Unit (Loc) = Main_Unit then
16644 Opt.Time_Slice_Set := True;
16645 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
16647 if Val <= Ureal_0 then
16648 Opt.Time_Slice_Value := 0;
16650 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
16651 Opt.Time_Slice_Value := 1_000_000_000;
16654 Opt.Time_Slice_Value :=
16655 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
16664 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
16666 -- TITLING_OPTION ::=
16667 -- [Title =>] STRING_LITERAL
16668 -- | [Subtitle =>] STRING_LITERAL
16670 when Pragma_Title => Title : declare
16671 Args : Args_List (1 .. 2);
16672 Names : constant Name_List (1 .. 2) := (
16678 Gather_Associations (Names, Args);
16681 for J in 1 .. 2 loop
16682 if Present (Args (J)) then
16683 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
16688 ---------------------
16689 -- Unchecked_Union --
16690 ---------------------
16692 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
16694 when Pragma_Unchecked_Union => Unchecked_Union : declare
16695 Assoc : constant Node_Id := Arg1;
16696 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
16706 Check_No_Identifiers;
16707 Check_Arg_Count (1);
16708 Check_Arg_Is_Local_Name (Arg1);
16710 Find_Type (Type_Id);
16712 Typ := Entity (Type_Id);
16715 or else Rep_Item_Too_Early (Typ, N)
16719 Typ := Underlying_Type (Typ);
16722 if Rep_Item_Too_Late (Typ, N) then
16726 Check_First_Subtype (Arg1);
16728 -- Note remaining cases are references to a type in the current
16729 -- declarative part. If we find an error, we post the error on
16730 -- the relevant type declaration at an appropriate point.
16732 if not Is_Record_Type (Typ) then
16733 Error_Msg_N ("unchecked union must be record type", Typ);
16736 elsif Is_Tagged_Type (Typ) then
16737 Error_Msg_N ("unchecked union must not be tagged", Typ);
16740 elsif not Has_Discriminants (Typ) then
16742 ("unchecked union must have one discriminant", Typ);
16745 -- Note: in previous versions of GNAT we used to check for limited
16746 -- types and give an error, but in fact the standard does allow
16747 -- Unchecked_Union on limited types, so this check was removed.
16749 -- Similarly, GNAT used to require that all discriminants have
16750 -- default values, but this is not mandated by the RM.
16752 -- Proceed with basic error checks completed
16755 Tdef := Type_Definition (Declaration_Node (Typ));
16756 Clist := Component_List (Tdef);
16758 -- Check presence of component list and variant part
16760 if No (Clist) or else No (Variant_Part (Clist)) then
16762 ("unchecked union must have variant part", Tdef);
16766 -- Check components
16768 Comp := First (Component_Items (Clist));
16769 while Present (Comp) loop
16770 Check_Component (Comp, Typ);
16774 -- Check variant part
16776 Vpart := Variant_Part (Clist);
16778 Variant := First (Variants (Vpart));
16779 while Present (Variant) loop
16780 Check_Variant (Variant, Typ);
16785 Set_Is_Unchecked_Union (Typ);
16786 Set_Convention (Typ, Convention_C);
16787 Set_Has_Unchecked_Union (Base_Type (Typ));
16788 Set_Is_Unchecked_Union (Base_Type (Typ));
16789 end Unchecked_Union;
16791 ------------------------
16792 -- Unimplemented_Unit --
16793 ------------------------
16795 -- pragma Unimplemented_Unit;
16797 -- Note: this only gives an error if we are generating code, or if
16798 -- we are in a generic library unit (where the pragma appears in the
16799 -- body, not in the spec).
16801 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
16802 Cunitent : constant Entity_Id :=
16803 Cunit_Entity (Get_Source_Unit (Loc));
16804 Ent_Kind : constant Entity_Kind :=
16809 Check_Arg_Count (0);
16811 if Operating_Mode = Generate_Code
16812 or else Ent_Kind = E_Generic_Function
16813 or else Ent_Kind = E_Generic_Procedure
16814 or else Ent_Kind = E_Generic_Package
16816 Get_Name_String (Chars (Cunitent));
16817 Set_Casing (Mixed_Case);
16818 Write_Str (Name_Buffer (1 .. Name_Len));
16819 Write_Str (" is not supported in this configuration");
16821 raise Unrecoverable_Error;
16823 end Unimplemented_Unit;
16825 ------------------------
16826 -- Universal_Aliasing --
16827 ------------------------
16829 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
16831 when Pragma_Universal_Aliasing => Universal_Alias : declare
16836 Check_Arg_Count (1);
16837 Check_Optional_Identifier (Arg2, Name_Entity);
16838 Check_Arg_Is_Local_Name (Arg1);
16839 E_Id := Entity (Get_Pragma_Arg (Arg1));
16841 if E_Id = Any_Type then
16843 elsif No (E_Id) or else not Is_Type (E_Id) then
16844 Error_Pragma_Arg ("pragma% requires type", Arg1);
16847 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
16848 Record_Rep_Item (E_Id, N);
16849 end Universal_Alias;
16851 --------------------
16852 -- Universal_Data --
16853 --------------------
16855 -- pragma Universal_Data [(library_unit_NAME)];
16857 when Pragma_Universal_Data =>
16860 -- If this is a configuration pragma, then set the universal
16861 -- addressing option, otherwise confirm that the pragma satisfies
16862 -- the requirements of library unit pragma placement and leave it
16863 -- to the GNAAMP back end to detect the pragma (avoids transitive
16864 -- setting of the option due to withed units).
16866 if Is_Configuration_Pragma then
16867 Universal_Addressing_On_AAMP := True;
16869 Check_Valid_Library_Unit_Pragma;
16872 if not AAMP_On_Target then
16873 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
16880 -- pragma Unmodified (local_Name {, local_Name});
16882 when Pragma_Unmodified => Unmodified : declare
16883 Arg_Node : Node_Id;
16884 Arg_Expr : Node_Id;
16885 Arg_Ent : Entity_Id;
16889 Check_At_Least_N_Arguments (1);
16891 -- Loop through arguments
16894 while Present (Arg_Node) loop
16895 Check_No_Identifier (Arg_Node);
16897 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
16898 -- in fact generate reference, so that the entity will have a
16899 -- reference, which will inhibit any warnings about it not
16900 -- being referenced, and also properly show up in the ali file
16901 -- as a reference. But this reference is recorded before the
16902 -- Has_Pragma_Unreferenced flag is set, so that no warning is
16903 -- generated for this reference.
16905 Check_Arg_Is_Local_Name (Arg_Node);
16906 Arg_Expr := Get_Pragma_Arg (Arg_Node);
16908 if Is_Entity_Name (Arg_Expr) then
16909 Arg_Ent := Entity (Arg_Expr);
16911 if not Is_Assignable (Arg_Ent) then
16913 ("pragma% can only be applied to a variable",
16916 Set_Has_Pragma_Unmodified (Arg_Ent);
16928 -- pragma Unreferenced (local_Name {, local_Name});
16930 -- or when used in a context clause:
16932 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
16934 when Pragma_Unreferenced => Unreferenced : declare
16935 Arg_Node : Node_Id;
16936 Arg_Expr : Node_Id;
16937 Arg_Ent : Entity_Id;
16942 Check_At_Least_N_Arguments (1);
16944 -- Check case of appearing within context clause
16946 if Is_In_Context_Clause then
16948 -- The arguments must all be units mentioned in a with clause
16949 -- in the same context clause. Note we already checked (in
16950 -- Par.Prag) that the arguments are either identifiers or
16951 -- selected components.
16954 while Present (Arg_Node) loop
16955 Citem := First (List_Containing (N));
16956 while Citem /= N loop
16957 if Nkind (Citem) = N_With_Clause
16959 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
16961 Set_Has_Pragma_Unreferenced
16964 (Library_Unit (Citem))));
16966 (Get_Pragma_Arg (Arg_Node), Name (Citem));
16975 ("argument of pragma% is not withed unit", Arg_Node);
16981 -- Case of not in list of context items
16985 while Present (Arg_Node) loop
16986 Check_No_Identifier (Arg_Node);
16988 -- Note: the analyze call done by Check_Arg_Is_Local_Name
16989 -- will in fact generate reference, so that the entity will
16990 -- have a reference, which will inhibit any warnings about
16991 -- it not being referenced, and also properly show up in the
16992 -- ali file as a reference. But this reference is recorded
16993 -- before the Has_Pragma_Unreferenced flag is set, so that
16994 -- no warning is generated for this reference.
16996 Check_Arg_Is_Local_Name (Arg_Node);
16997 Arg_Expr := Get_Pragma_Arg (Arg_Node);
16999 if Is_Entity_Name (Arg_Expr) then
17000 Arg_Ent := Entity (Arg_Expr);
17002 -- If the entity is overloaded, the pragma applies to the
17003 -- most recent overloading, as documented. In this case,
17004 -- name resolution does not generate a reference, so it
17005 -- must be done here explicitly.
17007 if Is_Overloaded (Arg_Expr) then
17008 Generate_Reference (Arg_Ent, N);
17011 Set_Has_Pragma_Unreferenced (Arg_Ent);
17019 --------------------------
17020 -- Unreferenced_Objects --
17021 --------------------------
17023 -- pragma Unreferenced_Objects (local_Name {, local_Name});
17025 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
17026 Arg_Node : Node_Id;
17027 Arg_Expr : Node_Id;
17031 Check_At_Least_N_Arguments (1);
17034 while Present (Arg_Node) loop
17035 Check_No_Identifier (Arg_Node);
17036 Check_Arg_Is_Local_Name (Arg_Node);
17037 Arg_Expr := Get_Pragma_Arg (Arg_Node);
17039 if not Is_Entity_Name (Arg_Expr)
17040 or else not Is_Type (Entity (Arg_Expr))
17043 ("argument for pragma% must be type or subtype", Arg_Node);
17046 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
17049 end Unreferenced_Objects;
17051 ------------------------------
17052 -- Unreserve_All_Interrupts --
17053 ------------------------------
17055 -- pragma Unreserve_All_Interrupts;
17057 when Pragma_Unreserve_All_Interrupts =>
17059 Check_Arg_Count (0);
17061 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
17062 Unreserve_All_Interrupts := True;
17069 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
17071 when Pragma_Unsuppress =>
17073 Process_Suppress_Unsuppress (False);
17075 -------------------
17076 -- Use_VADS_Size --
17077 -------------------
17079 -- pragma Use_VADS_Size;
17081 when Pragma_Use_VADS_Size =>
17083 Check_Arg_Count (0);
17084 Check_Valid_Configuration_Pragma;
17085 Use_VADS_Size := True;
17087 ---------------------
17088 -- Validity_Checks --
17089 ---------------------
17091 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
17093 when Pragma_Validity_Checks => Validity_Checks : declare
17094 A : constant Node_Id := Get_Pragma_Arg (Arg1);
17100 Check_Arg_Count (1);
17101 Check_No_Identifiers;
17103 if Nkind (A) = N_String_Literal then
17107 Slen : constant Natural := Natural (String_Length (S));
17108 Options : String (1 .. Slen);
17114 C := Get_String_Char (S, Int (J));
17115 exit when not In_Character_Range (C);
17116 Options (J) := Get_Character (C);
17119 Set_Validity_Check_Options (Options);
17127 elsif Nkind (A) = N_Identifier then
17128 if Chars (A) = Name_All_Checks then
17129 Set_Validity_Check_Options ("a");
17130 elsif Chars (A) = Name_On then
17131 Validity_Checks_On := True;
17132 elsif Chars (A) = Name_Off then
17133 Validity_Checks_On := False;
17136 end Validity_Checks;
17142 -- pragma Volatile (LOCAL_NAME);
17144 when Pragma_Volatile =>
17145 Process_Atomic_Shared_Volatile;
17147 -------------------------
17148 -- Volatile_Components --
17149 -------------------------
17151 -- pragma Volatile_Components (array_LOCAL_NAME);
17153 -- Volatile is handled by the same circuit as Atomic_Components
17159 -- pragma Warnings (On | Off);
17160 -- pragma Warnings (On | Off, LOCAL_NAME);
17161 -- pragma Warnings (static_string_EXPRESSION);
17162 -- pragma Warnings (On | Off, STRING_LITERAL);
17164 when Pragma_Warnings => Warnings : begin
17166 Check_At_Least_N_Arguments (1);
17167 Check_No_Identifiers;
17169 -- If debug flag -gnatd.i is set, pragma is ignored
17171 if Debug_Flag_Dot_I then
17175 -- Process various forms of the pragma
17178 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
17181 -- One argument case
17183 if Arg_Count = 1 then
17185 -- On/Off one argument case was processed by parser
17187 if Nkind (Argx) = N_Identifier
17189 (Chars (Argx) = Name_On
17191 Chars (Argx) = Name_Off)
17195 -- One argument case must be ON/OFF or static string expr
17197 elsif not Is_Static_String_Expression (Arg1) then
17199 ("argument of pragma% must be On/Off or static string "
17200 & "expression", Arg1);
17202 -- One argument string expression case
17206 Lit : constant Node_Id := Expr_Value_S (Argx);
17207 Str : constant String_Id := Strval (Lit);
17208 Len : constant Nat := String_Length (Str);
17216 while J <= Len loop
17217 C := Get_String_Char (Str, J);
17218 OK := In_Character_Range (C);
17221 Chr := Get_Character (C);
17223 -- Dash case: only -Wxxx is accepted
17230 C := Get_String_Char (Str, J);
17231 Chr := Get_Character (C);
17232 exit when Chr = 'W';
17237 elsif J < Len and then Chr = '.' then
17239 C := Get_String_Char (Str, J);
17240 Chr := Get_Character (C);
17242 if not Set_Dot_Warning_Switch (Chr) then
17244 ("invalid warning switch character "
17245 & '.' & Chr, Arg1);
17251 OK := Set_Warning_Switch (Chr);
17257 ("invalid warning switch character " & Chr,
17266 -- Two or more arguments (must be two)
17269 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
17270 Check_At_Most_N_Arguments (2);
17278 E_Id := Get_Pragma_Arg (Arg2);
17281 -- In the expansion of an inlined body, a reference to
17282 -- the formal may be wrapped in a conversion if the
17283 -- actual is a conversion. Retrieve the real entity name.
17285 if (In_Instance_Body or In_Inlined_Body)
17286 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
17288 E_Id := Expression (E_Id);
17291 -- Entity name case
17293 if Is_Entity_Name (E_Id) then
17294 E := Entity (E_Id);
17301 (E, (Chars (Get_Pragma_Arg (Arg1)) =
17304 -- For OFF case, make entry in warnings off
17305 -- pragma table for later processing. But we do
17306 -- not do that within an instance, since these
17307 -- warnings are about what is needed in the
17308 -- template, not an instance of it.
17310 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
17311 and then Warn_On_Warnings_Off
17312 and then not In_Instance
17314 Warnings_Off_Pragmas.Append ((N, E));
17317 if Is_Enumeration_Type (E) then
17321 Lit := First_Literal (E);
17322 while Present (Lit) loop
17323 Set_Warnings_Off (Lit);
17324 Next_Literal (Lit);
17329 exit when No (Homonym (E));
17334 -- Error if not entity or static string literal case
17336 elsif not Is_Static_String_Expression (Arg2) then
17338 ("second argument of pragma% must be entity name "
17339 & "or static string expression", Arg2);
17341 -- String literal case
17344 String_To_Name_Buffer
17345 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
17347 -- Note on configuration pragma case: If this is a
17348 -- configuration pragma, then for an OFF pragma, we
17349 -- just set Config True in the call, which is all
17350 -- that needs to be done. For the case of ON, this
17351 -- is normally an error, unless it is canceling the
17352 -- effect of a previous OFF pragma in the same file.
17353 -- In any other case, an error will be signalled (ON
17354 -- with no matching OFF).
17356 -- Note: We set Used if we are inside a generic to
17357 -- disable the test that the non-config case actually
17358 -- cancels a warning. That's because we can't be sure
17359 -- there isn't an instantiation in some other unit
17360 -- where a warning is suppressed.
17362 -- We could do a little better here by checking if the
17363 -- generic unit we are inside is public, but for now
17364 -- we don't bother with that refinement.
17366 if Chars (Argx) = Name_Off then
17367 Set_Specific_Warning_Off
17368 (Loc, Name_Buffer (1 .. Name_Len),
17369 Config => Is_Configuration_Pragma,
17370 Used => Inside_A_Generic or else In_Instance);
17372 elsif Chars (Argx) = Name_On then
17373 Set_Specific_Warning_On
17374 (Loc, Name_Buffer (1 .. Name_Len), Err);
17378 ("??pragma Warnings On with no matching "
17379 & "Warnings Off", Loc);
17388 -------------------
17389 -- Weak_External --
17390 -------------------
17392 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
17394 when Pragma_Weak_External => Weak_External : declare
17399 Check_Arg_Count (1);
17400 Check_Optional_Identifier (Arg1, Name_Entity);
17401 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17402 Ent := Entity (Get_Pragma_Arg (Arg1));
17404 if Rep_Item_Too_Early (Ent, N) then
17407 Ent := Underlying_Type (Ent);
17410 -- The only processing required is to link this item on to the
17411 -- list of rep items for the given entity. This is accomplished
17412 -- by the call to Rep_Item_Too_Late (when no error is detected
17413 -- and False is returned).
17415 if Rep_Item_Too_Late (Ent, N) then
17418 Set_Has_Gigi_Rep_Item (Ent);
17422 -----------------------------
17423 -- Wide_Character_Encoding --
17424 -----------------------------
17426 -- pragma Wide_Character_Encoding (IDENTIFIER);
17428 when Pragma_Wide_Character_Encoding =>
17431 -- Nothing to do, handled in parser. Note that we do not enforce
17432 -- configuration pragma placement, this pragma can appear at any
17433 -- place in the source, allowing mixed encodings within a single
17438 --------------------
17439 -- Unknown_Pragma --
17440 --------------------
17442 -- Should be impossible, since the case of an unknown pragma is
17443 -- separately processed before the case statement is entered.
17445 when Unknown_Pragma =>
17446 raise Program_Error;
17449 -- AI05-0144: detect dangerous order dependence. Disabled for now,
17450 -- until AI is formally approved.
17452 -- Check_Order_Dependence;
17455 when Pragma_Exit => null;
17456 end Analyze_Pragma;
17458 -------------------
17459 -- Check_Enabled --
17460 -------------------
17462 function Check_Enabled (Nam : Name_Id) return Boolean is
17466 -- Loop through entries in check policy list
17468 PP := Opt.Check_Policy_List;
17470 -- If there are no specific entries that matched, then we let the
17471 -- setting of assertions govern. Note that this provides the needed
17472 -- compatibility with the RM for the cases of assertion, invariant,
17473 -- precondition, predicate, and postcondition.
17476 return Assertions_Enabled;
17478 -- Here we have an entry see if it matches
17482 PPA : constant List_Id := Pragma_Argument_Associations (PP);
17485 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
17486 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
17487 when Name_On | Name_Check =>
17489 when Name_Off | Name_Disable | Name_Ignore =>
17492 raise Program_Error;
17496 PP := Next_Pragma (PP);
17503 ---------------------------------
17504 -- Delay_Config_Pragma_Analyze --
17505 ---------------------------------
17507 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
17509 return Pragma_Name (N) = Name_Interrupt_State
17511 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
17512 end Delay_Config_Pragma_Analyze;
17514 -------------------------
17515 -- Get_Base_Subprogram --
17516 -------------------------
17518 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
17519 Result : Entity_Id;
17522 -- Follow subprogram renaming chain
17526 if Is_Subprogram (Result)
17528 Nkind (Parent (Declaration_Node (Result))) =
17529 N_Subprogram_Renaming_Declaration
17530 and then Present (Alias (Result))
17532 Result := Alias (Result);
17536 end Get_Base_Subprogram;
17542 procedure Initialize is
17547 -----------------------------
17548 -- Is_Config_Static_String --
17549 -----------------------------
17551 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
17553 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
17554 -- This is an internal recursive function that is just like the outer
17555 -- function except that it adds the string to the name buffer rather
17556 -- than placing the string in the name buffer.
17558 ------------------------------
17559 -- Add_Config_Static_String --
17560 ------------------------------
17562 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
17569 if Nkind (N) = N_Op_Concat then
17570 if Add_Config_Static_String (Left_Opnd (N)) then
17571 N := Right_Opnd (N);
17577 if Nkind (N) /= N_String_Literal then
17578 Error_Msg_N ("string literal expected for pragma argument", N);
17582 for J in 1 .. String_Length (Strval (N)) loop
17583 C := Get_String_Char (Strval (N), J);
17585 if not In_Character_Range (C) then
17587 ("string literal contains invalid wide character",
17588 Sloc (N) + 1 + Source_Ptr (J));
17592 Add_Char_To_Name_Buffer (Get_Character (C));
17597 end Add_Config_Static_String;
17599 -- Start of processing for Is_Config_Static_String
17604 return Add_Config_Static_String (Arg);
17605 end Is_Config_Static_String;
17607 -----------------------------------------
17608 -- Is_Non_Significant_Pragma_Reference --
17609 -----------------------------------------
17611 -- This function makes use of the following static table which indicates
17612 -- whether appearance of some name in a given pragma is to be considered
17613 -- as a reference for the purposes of warnings about unreferenced objects.
17615 -- -1 indicates that references in any argument position are significant
17616 -- 0 indicates that appearance in any argument is not significant
17617 -- +n indicates that appearance as argument n is significant, but all
17618 -- other arguments are not significant
17619 -- 99 special processing required (e.g. for pragma Check)
17621 Sig_Flags : constant array (Pragma_Id) of Int :=
17622 (Pragma_AST_Entry => -1,
17623 Pragma_Abort_Defer => -1,
17624 Pragma_Abstract_State => -1,
17625 Pragma_Ada_83 => -1,
17626 Pragma_Ada_95 => -1,
17627 Pragma_Ada_05 => -1,
17628 Pragma_Ada_2005 => -1,
17629 Pragma_Ada_12 => -1,
17630 Pragma_Ada_2012 => -1,
17631 Pragma_All_Calls_Remote => -1,
17632 Pragma_Annotate => -1,
17633 Pragma_Assert => -1,
17634 Pragma_Assert_And_Cut => -1,
17635 Pragma_Assertion_Policy => 0,
17636 Pragma_Assume => 0,
17637 Pragma_Assume_No_Invalid_Values => 0,
17638 Pragma_Attribute_Definition => +3,
17639 Pragma_Asynchronous => -1,
17640 Pragma_Atomic => 0,
17641 Pragma_Atomic_Components => 0,
17642 Pragma_Attach_Handler => -1,
17643 Pragma_Check => 99,
17644 Pragma_Check_Float_Overflow => 0,
17645 Pragma_Check_Name => 0,
17646 Pragma_Check_Policy => 0,
17647 Pragma_CIL_Constructor => -1,
17648 Pragma_CPP_Class => 0,
17649 Pragma_CPP_Constructor => 0,
17650 Pragma_CPP_Virtual => 0,
17651 Pragma_CPP_Vtable => 0,
17653 Pragma_C_Pass_By_Copy => 0,
17654 Pragma_Comment => 0,
17655 Pragma_Common_Object => -1,
17656 Pragma_Compile_Time_Error => -1,
17657 Pragma_Compile_Time_Warning => -1,
17658 Pragma_Compiler_Unit => 0,
17659 Pragma_Complete_Representation => 0,
17660 Pragma_Complex_Representation => 0,
17661 Pragma_Component_Alignment => -1,
17662 Pragma_Contract_Case => -1,
17663 Pragma_Contract_Cases => -1,
17664 Pragma_Controlled => 0,
17665 Pragma_Convention => 0,
17666 Pragma_Convention_Identifier => 0,
17667 Pragma_Debug => -1,
17668 Pragma_Debug_Policy => 0,
17669 Pragma_Detect_Blocking => -1,
17670 Pragma_Default_Storage_Pool => -1,
17671 Pragma_Depends => -1,
17672 Pragma_Disable_Atomic_Synchronization => -1,
17673 Pragma_Discard_Names => 0,
17674 Pragma_Dispatching_Domain => -1,
17675 Pragma_Elaborate => -1,
17676 Pragma_Elaborate_All => -1,
17677 Pragma_Elaborate_Body => -1,
17678 Pragma_Elaboration_Checks => -1,
17679 Pragma_Eliminate => -1,
17680 Pragma_Enable_Atomic_Synchronization => -1,
17681 Pragma_Export => -1,
17682 Pragma_Export_Exception => -1,
17683 Pragma_Export_Function => -1,
17684 Pragma_Export_Object => -1,
17685 Pragma_Export_Procedure => -1,
17686 Pragma_Export_Value => -1,
17687 Pragma_Export_Valued_Procedure => -1,
17688 Pragma_Extend_System => -1,
17689 Pragma_Extensions_Allowed => -1,
17690 Pragma_External => -1,
17691 Pragma_Favor_Top_Level => -1,
17692 Pragma_External_Name_Casing => -1,
17693 Pragma_Fast_Math => -1,
17694 Pragma_Finalize_Storage_Only => 0,
17695 Pragma_Float_Representation => 0,
17696 Pragma_Global => -1,
17697 Pragma_Ident => -1,
17698 Pragma_Implementation_Defined => -1,
17699 Pragma_Implemented => -1,
17700 Pragma_Implicit_Packing => 0,
17701 Pragma_Import => +2,
17702 Pragma_Import_Exception => 0,
17703 Pragma_Import_Function => 0,
17704 Pragma_Import_Object => 0,
17705 Pragma_Import_Procedure => 0,
17706 Pragma_Import_Valued_Procedure => 0,
17707 Pragma_Independent => 0,
17708 Pragma_Independent_Components => 0,
17709 Pragma_Initialize_Scalars => -1,
17710 Pragma_Inline => 0,
17711 Pragma_Inline_Always => 0,
17712 Pragma_Inline_Generic => 0,
17713 Pragma_Inspection_Point => -1,
17714 Pragma_Interface => +2,
17715 Pragma_Interface_Name => +2,
17716 Pragma_Interrupt_Handler => -1,
17717 Pragma_Interrupt_Priority => -1,
17718 Pragma_Interrupt_State => -1,
17719 Pragma_Invariant => -1,
17720 Pragma_Java_Constructor => -1,
17721 Pragma_Java_Interface => -1,
17722 Pragma_Keep_Names => 0,
17723 Pragma_License => -1,
17724 Pragma_Link_With => -1,
17725 Pragma_Linker_Alias => -1,
17726 Pragma_Linker_Constructor => -1,
17727 Pragma_Linker_Destructor => -1,
17728 Pragma_Linker_Options => -1,
17729 Pragma_Linker_Section => -1,
17731 Pragma_Lock_Free => -1,
17732 Pragma_Locking_Policy => -1,
17733 Pragma_Long_Float => -1,
17734 Pragma_Loop_Invariant => -1,
17735 Pragma_Loop_Optimize => -1,
17736 Pragma_Loop_Variant => -1,
17737 Pragma_Machine_Attribute => -1,
17739 Pragma_Main_Storage => -1,
17740 Pragma_Memory_Size => -1,
17741 Pragma_No_Return => 0,
17742 Pragma_No_Body => 0,
17743 Pragma_No_Inline => 0,
17744 Pragma_No_Run_Time => -1,
17745 Pragma_No_Strict_Aliasing => -1,
17746 Pragma_Normalize_Scalars => -1,
17747 Pragma_Obsolescent => 0,
17748 Pragma_Optimize => -1,
17749 Pragma_Optimize_Alignment => -1,
17750 Pragma_Overflow_Mode => 0,
17751 Pragma_Overriding_Renamings => 0,
17752 Pragma_Ordered => 0,
17755 Pragma_Partition_Elaboration_Policy => -1,
17756 Pragma_Passive => -1,
17757 Pragma_Preelaborable_Initialization => -1,
17758 Pragma_Polling => -1,
17759 Pragma_Persistent_BSS => 0,
17760 Pragma_Postcondition => -1,
17761 Pragma_Precondition => -1,
17762 Pragma_Predicate => -1,
17763 Pragma_Preelaborate => -1,
17764 Pragma_Preelaborate_05 => -1,
17765 Pragma_Priority => -1,
17766 Pragma_Priority_Specific_Dispatching => -1,
17767 Pragma_Profile => 0,
17768 Pragma_Profile_Warnings => 0,
17769 Pragma_Propagate_Exceptions => -1,
17770 Pragma_Psect_Object => -1,
17772 Pragma_Pure_05 => -1,
17773 Pragma_Pure_12 => -1,
17774 Pragma_Pure_Function => -1,
17775 Pragma_Queuing_Policy => -1,
17776 Pragma_Rational => -1,
17777 Pragma_Ravenscar => -1,
17778 Pragma_Relative_Deadline => -1,
17779 Pragma_Remote_Access_Type => -1,
17780 Pragma_Remote_Call_Interface => -1,
17781 Pragma_Remote_Types => -1,
17782 Pragma_Restricted_Run_Time => -1,
17783 Pragma_Restriction_Warnings => -1,
17784 Pragma_Restrictions => -1,
17785 Pragma_Reviewable => -1,
17786 Pragma_Short_Circuit_And_Or => -1,
17787 Pragma_Share_Generic => -1,
17788 Pragma_Shared => -1,
17789 Pragma_Shared_Passive => -1,
17790 Pragma_Short_Descriptors => 0,
17791 Pragma_Simple_Storage_Pool_Type => 0,
17792 Pragma_Source_File_Name => -1,
17793 Pragma_Source_File_Name_Project => -1,
17794 Pragma_Source_Reference => -1,
17795 Pragma_Storage_Size => -1,
17796 Pragma_Storage_Unit => -1,
17797 Pragma_Static_Elaboration_Desired => -1,
17798 Pragma_Stream_Convert => -1,
17799 Pragma_Style_Checks => -1,
17800 Pragma_Subtitle => -1,
17801 Pragma_Suppress => 0,
17802 Pragma_Suppress_Exception_Locations => 0,
17803 Pragma_Suppress_All => -1,
17804 Pragma_Suppress_Debug_Info => 0,
17805 Pragma_Suppress_Initialization => 0,
17806 Pragma_System_Name => -1,
17807 Pragma_Task_Dispatching_Policy => -1,
17808 Pragma_Task_Info => -1,
17809 Pragma_Task_Name => -1,
17810 Pragma_Task_Storage => 0,
17811 Pragma_Test_Case => -1,
17812 Pragma_Thread_Local_Storage => 0,
17813 Pragma_Time_Slice => -1,
17814 Pragma_Title => -1,
17815 Pragma_Unchecked_Union => 0,
17816 Pragma_Unimplemented_Unit => -1,
17817 Pragma_Universal_Aliasing => -1,
17818 Pragma_Universal_Data => -1,
17819 Pragma_Unmodified => -1,
17820 Pragma_Unreferenced => -1,
17821 Pragma_Unreferenced_Objects => -1,
17822 Pragma_Unreserve_All_Interrupts => -1,
17823 Pragma_Unsuppress => 0,
17824 Pragma_Use_VADS_Size => -1,
17825 Pragma_Validity_Checks => -1,
17826 Pragma_Volatile => 0,
17827 Pragma_Volatile_Components => 0,
17828 Pragma_Warnings => -1,
17829 Pragma_Weak_External => -1,
17830 Pragma_Wide_Character_Encoding => 0,
17831 Unknown_Pragma => 0);
17833 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
17842 if Nkind (P) /= N_Pragma_Argument_Association then
17846 Id := Get_Pragma_Id (Parent (P));
17847 C := Sig_Flags (Id);
17859 -- For pragma Check, the first argument is not significant,
17860 -- the second and the third (if present) arguments are
17863 when Pragma_Check =>
17865 P = First (Pragma_Argument_Associations (Parent (P)));
17868 raise Program_Error;
17872 A := First (Pragma_Argument_Associations (Parent (P)));
17873 for J in 1 .. C - 1 loop
17881 return A = P; -- is this wrong way round ???
17884 end Is_Non_Significant_Pragma_Reference;
17886 ------------------------------
17887 -- Is_Pragma_String_Literal --
17888 ------------------------------
17890 -- This function returns true if the corresponding pragma argument is a
17891 -- static string expression. These are the only cases in which string
17892 -- literals can appear as pragma arguments. We also allow a string literal
17893 -- as the first argument to pragma Assert (although it will of course
17894 -- always generate a type error).
17896 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
17897 Pragn : constant Node_Id := Parent (Par);
17898 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
17899 Pname : constant Name_Id := Pragma_Name (Pragn);
17905 N := First (Assoc);
17912 if Pname = Name_Assert then
17915 elsif Pname = Name_Export then
17918 elsif Pname = Name_Ident then
17921 elsif Pname = Name_Import then
17924 elsif Pname = Name_Interface_Name then
17927 elsif Pname = Name_Linker_Alias then
17930 elsif Pname = Name_Linker_Section then
17933 elsif Pname = Name_Machine_Attribute then
17936 elsif Pname = Name_Source_File_Name then
17939 elsif Pname = Name_Source_Reference then
17942 elsif Pname = Name_Title then
17945 elsif Pname = Name_Subtitle then
17951 end Is_Pragma_String_Literal;
17953 -----------------------------------------
17954 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
17955 -----------------------------------------
17957 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
17958 Aspects : constant List_Id := New_List;
17959 Loc : constant Source_Ptr := Sloc (Decl);
17960 Or_Decl : constant Node_Id := Original_Node (Decl);
17962 Original_Aspects : List_Id;
17963 -- To capture global references, a copy of the created aspects must be
17964 -- inserted in the original tree.
17967 Prag_Arg_Ass : Node_Id;
17968 Prag_Id : Pragma_Id;
17971 -- Check for any PPC pragmas that appear within Decl
17973 Prag := Next (Decl);
17974 while Nkind (Prag) = N_Pragma loop
17975 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
17978 when Pragma_Postcondition | Pragma_Precondition =>
17979 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
17981 -- Make an aspect from any PPC pragma
17983 Append_To (Aspects,
17984 Make_Aspect_Specification (Loc,
17986 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
17988 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
17990 -- Generate the analysis information in the pragma expression
17991 -- and then set the pragma node analyzed to avoid any further
17994 Analyze (Expression (Prag_Arg_Ass));
17995 Set_Analyzed (Prag, True);
17997 when others => null;
18003 -- Set all new aspects into the generic declaration node
18005 if Is_Non_Empty_List (Aspects) then
18007 -- Create the list of aspects to be inserted in the original tree
18009 Original_Aspects := Copy_Separate_List (Aspects);
18011 -- Check if Decl already has aspects
18013 -- Attach the new lists of aspects to both the generic copy and the
18016 if Has_Aspects (Decl) then
18017 Append_List (Aspects, Aspect_Specifications (Decl));
18018 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
18021 Set_Parent (Aspects, Decl);
18022 Set_Aspect_Specifications (Decl, Aspects);
18023 Set_Parent (Original_Aspects, Or_Decl);
18024 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
18027 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
18029 -------------------------
18030 -- Preanalyze_CTC_Args --
18031 -------------------------
18033 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
18035 -- Preanalyze the boolean expressions, we treat these as spec
18036 -- expressions (i.e. similar to a default expression).
18038 if Present (Arg_Req) then
18039 Preanalyze_Assert_Expression
18040 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
18042 -- In ASIS mode, for a pragma generated from a source aspect, also
18043 -- analyze the original aspect expression.
18045 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
18046 Preanalyze_Assert_Expression
18047 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
18051 if Present (Arg_Ens) then
18052 Preanalyze_Assert_Expression
18053 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
18055 -- In ASIS mode, for a pragma generated from a source aspect, also
18056 -- analyze the original aspect expression.
18058 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
18059 Preanalyze_Assert_Expression
18060 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
18063 end Preanalyze_CTC_Args;
18065 --------------------------------------
18066 -- Process_Compilation_Unit_Pragmas --
18067 --------------------------------------
18069 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
18071 -- A special check for pragma Suppress_All, a very strange DEC pragma,
18072 -- strange because it comes at the end of the unit. Rational has the
18073 -- same name for a pragma, but treats it as a program unit pragma, In
18074 -- GNAT we just decide to allow it anywhere at all. If it appeared then
18075 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
18076 -- node, and we insert a pragma Suppress (All_Checks) at the start of
18077 -- the context clause to ensure the correct processing.
18079 if Has_Pragma_Suppress_All (N) then
18080 Prepend_To (Context_Items (N),
18081 Make_Pragma (Sloc (N),
18082 Chars => Name_Suppress,
18083 Pragma_Argument_Associations => New_List (
18084 Make_Pragma_Argument_Association (Sloc (N),
18085 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
18088 -- Nothing else to do at the current time!
18090 end Process_Compilation_Unit_Pragmas;
18101 --------------------------------
18102 -- Set_Encoded_Interface_Name --
18103 --------------------------------
18105 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
18106 Str : constant String_Id := Strval (S);
18107 Len : constant Int := String_Length (Str);
18112 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
18115 -- Stores encoded value of character code CC. The encoding we use an
18116 -- underscore followed by four lower case hex digits.
18122 procedure Encode is
18124 Store_String_Char (Get_Char_Code ('_'));
18126 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
18128 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
18130 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
18132 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
18135 -- Start of processing for Set_Encoded_Interface_Name
18138 -- If first character is asterisk, this is a link name, and we leave it
18139 -- completely unmodified. We also ignore null strings (the latter case
18140 -- happens only in error cases) and no encoding should occur for Java or
18141 -- AAMP interface names.
18144 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
18145 or else VM_Target /= No_VM
18146 or else AAMP_On_Target
18148 Set_Interface_Name (E, S);
18153 CC := Get_String_Char (Str, J);
18155 exit when not In_Character_Range (CC);
18157 C := Get_Character (CC);
18159 exit when C /= '_' and then C /= '$'
18160 and then C not in '0' .. '9'
18161 and then C not in 'a' .. 'z'
18162 and then C not in 'A' .. 'Z';
18165 Set_Interface_Name (E, S);
18173 -- Here we need to encode. The encoding we use as follows:
18174 -- three underscores + four hex digits (lower case)
18178 for J in 1 .. String_Length (Str) loop
18179 CC := Get_String_Char (Str, J);
18181 if not In_Character_Range (CC) then
18184 C := Get_Character (CC);
18186 if C = '_' or else C = '$'
18187 or else C in '0' .. '9'
18188 or else C in 'a' .. 'z'
18189 or else C in 'A' .. 'Z'
18191 Store_String_Char (CC);
18198 Set_Interface_Name (E,
18199 Make_String_Literal (Sloc (S),
18200 Strval => End_String));
18202 end Set_Encoded_Interface_Name;
18204 -------------------
18205 -- Set_Unit_Name --
18206 -------------------
18208 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
18213 if Nkind (N) = N_Identifier
18214 and then Nkind (With_Item) = N_Identifier
18216 Set_Entity (N, Entity (With_Item));
18218 elsif Nkind (N) = N_Selected_Component then
18219 Change_Selected_Component_To_Expanded_Name (N);
18220 Set_Entity (N, Entity (With_Item));
18221 Set_Entity (Selector_Name (N), Entity (N));
18223 Pref := Prefix (N);
18224 Scop := Scope (Entity (N));
18225 while Nkind (Pref) = N_Selected_Component loop
18226 Change_Selected_Component_To_Expanded_Name (Pref);
18227 Set_Entity (Selector_Name (Pref), Scop);
18228 Set_Entity (Pref, Scop);
18229 Pref := Prefix (Pref);
18230 Scop := Scope (Scop);
18233 Set_Entity (Pref, Scop);