1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, 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_TC_Args (N, Arg_Req, Arg_Ens : Node_Id);
185 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
186 -- of a Test_Case pragma if present (possibly Empty). We treat these as
187 -- 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_PPC_In_Decl_Part --
248 ------------------------------
250 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
251 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
254 -- Install formals and push subprogram spec onto scope stack so that we
255 -- can see the formals from the pragma.
260 -- Preanalyze the boolean expression, we treat this as a spec expression
261 -- (i.e. similar to a default expression).
263 Preanalyze_Spec_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
265 -- In ASIS mode, for a pragma generated from a source aspect, also
266 -- analyze the original aspect expression.
269 and then Present (Corresponding_Aspect (N))
271 Preanalyze_Spec_Expression
272 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
275 -- For a class-wide condition, a reference to a controlling formal must
276 -- be interpreted as having the class-wide type (or an access to such)
277 -- so that the inherited condition can be properly applied to any
278 -- overriding operation (see ARM12 6.6.1 (7)).
280 if Class_Present (N) then
282 T : constant Entity_Id := Find_Dispatching_Type (S);
284 ACW : Entity_Id := Empty;
285 -- Access to T'class, created if there is a controlling formal
286 -- that is an access parameter.
288 function Get_ACW return Entity_Id;
289 -- If the expression has a reference to an controlling access
290 -- parameter, create an access to T'class for the necessary
291 -- conversions if one does not exist.
293 function Process (N : Node_Id) return Traverse_Result;
294 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
295 -- aspect for a primitive subprogram of a tagged type T, a name
296 -- that denotes a formal parameter of type T is interpreted as
297 -- having type T'Class. Similarly, a name that denotes a formal
298 -- accessparameter of type access-to-T is interpreted as having
299 -- type access-to-T'Class. This ensures the expression is well-
300 -- defined for a primitive subprogram of a type descended from T.
306 function Get_ACW return Entity_Id is
307 Loc : constant Source_Ptr := Sloc (N);
312 Decl := Make_Full_Type_Declaration (Loc,
313 Defining_Identifier => Make_Temporary (Loc, 'T'),
315 Make_Access_To_Object_Definition (Loc,
316 Subtype_Indication =>
317 New_Occurrence_Of (Class_Wide_Type (T), Loc),
318 All_Present => True));
320 Insert_Before (Unit_Declaration_Node (S), Decl);
322 ACW := Defining_Identifier (Decl);
323 Freeze_Before (Unit_Declaration_Node (S), ACW);
333 function Process (N : Node_Id) return Traverse_Result is
334 Loc : constant Source_Ptr := Sloc (N);
338 if Is_Entity_Name (N)
339 and then Is_Formal (Entity (N))
340 and then Nkind (Parent (N)) /= N_Type_Conversion
342 if Etype (Entity (N)) = T then
343 Typ := Class_Wide_Type (T);
345 elsif Is_Access_Type (Etype (Entity (N)))
346 and then Designated_Type (Etype (Entity (N))) = T
353 if Present (Typ) then
355 Make_Type_Conversion (Loc,
357 New_Occurrence_Of (Typ, Loc),
358 Expression => New_Occurrence_Of (Entity (N), Loc)));
366 procedure Replace_Type is new Traverse_Proc (Process);
369 Replace_Type (Get_Pragma_Arg (Arg1));
373 -- Remove the subprogram from the scope stack now that the pre-analysis
374 -- of the precondition/postcondition is done.
377 end Analyze_PPC_In_Decl_Part;
383 procedure Analyze_Pragma (N : Node_Id) is
384 Loc : constant Source_Ptr := Sloc (N);
388 -- Name of the source pragma, or name of the corresponding aspect for
389 -- pragmas which originate in a source aspect. In the latter case, the
390 -- name may be different from the pragma name.
392 Pragma_Exit : exception;
393 -- This exception is used to exit pragma processing completely. It is
394 -- used when an error is detected, and no further processing is
395 -- required. It is also used if an earlier error has left the tree in
396 -- a state where the pragma should not be processed.
399 -- Number of pragma argument associations
405 -- First four pragma arguments (pragma argument association nodes, or
406 -- Empty if the corresponding argument does not exist).
408 type Name_List is array (Natural range <>) of Name_Id;
409 type Args_List is array (Natural range <>) of Node_Id;
410 -- Types used for arguments to Check_Arg_Order and Gather_Associations
412 procedure Ada_2005_Pragma;
413 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
414 -- Ada 95 mode, these are implementation defined pragmas, so should be
415 -- caught by the No_Implementation_Pragmas restriction.
417 procedure Ada_2012_Pragma;
418 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
419 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
420 -- should be caught by the No_Implementation_Pragmas restriction.
422 procedure Check_Ada_83_Warning;
423 -- Issues a warning message for the current pragma if operating in Ada
424 -- 83 mode (used for language pragmas that are not a standard part of
425 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
428 procedure Check_Arg_Count (Required : Nat);
429 -- Check argument count for pragma is equal to given parameter. If not,
430 -- then issue an error message and raise Pragma_Exit.
432 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
433 -- Arg which can either be a pragma argument association, in which case
434 -- the check is applied to the expression of the association or an
435 -- expression directly.
437 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
438 -- Check that an argument has the right form for an EXTERNAL_NAME
439 -- parameter of an extended import/export pragma. The rule is that the
440 -- name must be an identifier or string literal (in Ada 83 mode) or a
441 -- static string expression (in Ada 95 mode).
443 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
444 -- Check the specified argument Arg to make sure that it is an
445 -- identifier. If not give error and raise Pragma_Exit.
447 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
448 -- Check the specified argument Arg to make sure that it is an integer
449 -- literal. If not give error and raise Pragma_Exit.
451 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
452 -- Check the specified argument Arg to make sure that it has the proper
453 -- syntactic form for a local name and meets the semantic requirements
454 -- for a local name. The local name is analyzed as part of the
455 -- processing for this call. In addition, the local name is required
456 -- to represent an entity at the library level.
458 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
459 -- Check the specified argument Arg to make sure that it has the proper
460 -- syntactic form for a local name and meets the semantic requirements
461 -- for a local name. The local name is analyzed as part of the
462 -- processing for this call.
464 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
465 -- Check the specified argument Arg to make sure that it is a valid
466 -- locking policy name. If not give error and raise Pragma_Exit.
468 procedure Check_Arg_Is_One_Of
471 procedure Check_Arg_Is_One_Of
473 N1, N2, N3 : Name_Id);
474 procedure Check_Arg_Is_One_Of
476 N1, N2, N3, N4, N5 : Name_Id);
477 -- Check the specified argument Arg to make sure that it is an
478 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
479 -- present). If not then give error and raise Pragma_Exit.
481 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
482 -- Check the specified argument Arg to make sure that it is a valid
483 -- queuing policy name. If not give error and raise Pragma_Exit.
485 procedure Check_Arg_Is_Static_Expression
487 Typ : Entity_Id := Empty);
488 -- Check the specified argument Arg to make sure that it is a static
489 -- expression of the given type (i.e. it will be analyzed and resolved
490 -- using this type, which can be any valid argument to Resolve, e.g.
491 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
492 -- Typ is left Empty, then any static expression is allowed.
494 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
495 -- Check the specified argument Arg to make sure that it is a valid task
496 -- dispatching policy name. If not give error and raise Pragma_Exit.
498 procedure Check_Arg_Order (Names : Name_List);
499 -- Checks for an instance of two arguments with identifiers for the
500 -- current pragma which are not in the sequence indicated by Names,
501 -- and if so, generates a fatal message about bad order of arguments.
503 procedure Check_At_Least_N_Arguments (N : Nat);
504 -- Check there are at least N arguments present
506 procedure Check_At_Most_N_Arguments (N : Nat);
507 -- Check there are no more than N arguments present
509 procedure Check_Component
512 In_Variant_Part : Boolean := False);
513 -- Examine an Unchecked_Union component for correct use of per-object
514 -- constrained subtypes, and for restrictions on finalizable components.
515 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
516 -- should be set when Comp comes from a record variant.
518 procedure Check_Duplicate_Pragma (E : Entity_Id);
519 -- Check if a pragma of the same name as the current pragma is already
520 -- chained as a rep pragma to the given entity. If so give a message
521 -- about the duplicate, and then raise Pragma_Exit so does not return.
522 -- Also checks for delayed aspect specification node in the chain.
524 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
525 -- Nam is an N_String_Literal node containing the external name set by
526 -- an Import or Export pragma (or extended Import or Export pragma).
527 -- This procedure checks for possible duplications if this is the export
528 -- case, and if found, issues an appropriate error message.
530 procedure Check_Expr_Is_Static_Expression
532 Typ : Entity_Id := Empty);
533 -- Check the specified expression Expr to make sure that it is a static
534 -- expression of the given type (i.e. it will be analyzed and resolved
535 -- using this type, which can be any valid argument to Resolve, e.g.
536 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
537 -- Typ is left Empty, then any static expression is allowed.
539 procedure Check_First_Subtype (Arg : Node_Id);
540 -- Checks that Arg, whose expression is an entity name, references a
543 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
544 -- Checks that the given argument has an identifier, and if so, requires
545 -- it to match the given identifier name. If there is no identifier, or
546 -- a non-matching identifier, then an error message is given and
547 -- Pragma_Exit is raised.
549 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
550 -- Checks that the given argument has an identifier, and if so, requires
551 -- it to match one of the given identifier names. If there is no
552 -- identifier, or a non-matching identifier, then an error message is
553 -- given and Pragma_Exit is raised.
555 procedure Check_In_Main_Program;
556 -- Common checks for pragmas that appear within a main program
557 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
559 procedure Check_Interrupt_Or_Attach_Handler;
560 -- Common processing for first argument of pragma Interrupt_Handler or
561 -- pragma Attach_Handler.
563 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
564 -- Check that pragma appears in a declarative part, or in a package
565 -- specification, i.e. that it does not occur in a statement sequence
568 procedure Check_No_Identifier (Arg : Node_Id);
569 -- Checks that the given argument does not have an identifier. If
570 -- an identifier is present, then an error message is issued, and
571 -- Pragma_Exit is raised.
573 procedure Check_No_Identifiers;
574 -- Checks that none of the arguments to the pragma has an identifier.
575 -- If any argument has an identifier, then an error message is issued,
576 -- and Pragma_Exit is raised.
578 procedure Check_No_Link_Name;
579 -- Checks that no link name is specified
581 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
582 -- Checks if the given argument has an identifier, and if so, requires
583 -- it to match the given identifier name. If there is a non-matching
584 -- identifier, then an error message is given and Pragma_Exit is raised.
586 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
587 -- Checks if the given argument has an identifier, and if so, requires
588 -- it to match the given identifier name. If there is a non-matching
589 -- identifier, then an error message is given and Pragma_Exit is raised.
590 -- In this version of the procedure, the identifier name is given as
591 -- a string with lower case letters.
593 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
594 -- Called to process a precondition or postcondition pragma. There are
597 -- The pragma appears after a subprogram spec
599 -- If the corresponding check is not enabled, the pragma is analyzed
600 -- but otherwise ignored and control returns with In_Body set False.
602 -- If the check is enabled, then the first step is to analyze the
603 -- pragma, but this is skipped if the subprogram spec appears within
604 -- a package specification (because this is the case where we delay
605 -- analysis till the end of the spec). Then (whether or not it was
606 -- analyzed), the pragma is chained to the subprogram in question
607 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
608 -- caller with In_Body set False.
610 -- The pragma appears at the start of subprogram body declarations
612 -- In this case an immediate return to the caller is made with
613 -- In_Body set True, and the pragma is NOT analyzed.
615 -- In all other cases, an error message for bad placement is given
617 procedure Check_Static_Constraint (Constr : Node_Id);
618 -- Constr is a constraint from an N_Subtype_Indication node from a
619 -- component constraint in an Unchecked_Union type. This routine checks
620 -- that the constraint is static as required by the restrictions for
623 procedure Check_Test_Case;
624 -- Called to process a test-case pragma. The treatment is similar to the
625 -- one for pre- and postcondition in Check_Precondition_Postcondition,
626 -- except the placement rules for the test-case pragma are stricter.
627 -- This pragma may only occur after a subprogram spec declared directly
628 -- in a package spec unit. In this case, the pragma is chained to the
629 -- subprogram in question (using Spec_TC_List and Next_Pragma) and
630 -- analysis of the pragma is delayed till the end of the spec. In
631 -- all other cases, an error message for bad placement is given.
633 procedure Check_Valid_Configuration_Pragma;
634 -- Legality checks for placement of a configuration pragma
636 procedure Check_Valid_Library_Unit_Pragma;
637 -- Legality checks for library unit pragmas. A special case arises for
638 -- pragmas in generic instances that come from copies of the original
639 -- library unit pragmas in the generic templates. In the case of other
640 -- than library level instantiations these can appear in contexts which
641 -- would normally be invalid (they only apply to the original template
642 -- and to library level instantiations), and they are simply ignored,
643 -- which is implemented by rewriting them as null statements.
645 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
646 -- Check an Unchecked_Union variant for lack of nested variants and
647 -- presence of at least one component. UU_Typ is the related Unchecked_
650 procedure Error_Pragma (Msg : String);
651 pragma No_Return (Error_Pragma);
652 -- Outputs error message for current pragma. The message contains a %
653 -- that will be replaced with the pragma name, and the flag is placed
654 -- on the pragma itself. Pragma_Exit is then raised.
656 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
657 pragma No_Return (Error_Pragma_Arg);
658 -- Outputs error message for current pragma. The message may contain
659 -- a % that will be replaced with the pragma name. The parameter Arg
660 -- may either be a pragma argument association, in which case the flag
661 -- is placed on the expression of this association, or an expression,
662 -- in which case the flag is placed directly on the expression. The
663 -- message is placed using Error_Msg_N, so the message may also contain
664 -- an & insertion character which will reference the given Arg value.
665 -- After placing the message, Pragma_Exit is raised.
667 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
668 pragma No_Return (Error_Pragma_Arg);
669 -- Similar to above form of Error_Pragma_Arg except that two messages
670 -- are provided, the second is a continuation comment starting with \.
672 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
673 pragma No_Return (Error_Pragma_Arg_Ident);
674 -- Outputs error message for current pragma. The message may contain
675 -- a % that will be replaced with the pragma name. The parameter Arg
676 -- must be a pragma argument association with a non-empty identifier
677 -- (i.e. its Chars field must be set), and the error message is placed
678 -- on the identifier. The message is placed using Error_Msg_N so
679 -- the message may also contain an & insertion character which will
680 -- reference the identifier. After placing the message, Pragma_Exit
683 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
684 pragma No_Return (Error_Pragma_Ref);
685 -- Outputs error message for current pragma. The message may contain
686 -- a % that will be replaced with the pragma name. The parameter Ref
687 -- must be an entity whose name can be referenced by & and sloc by #.
688 -- After placing the message, Pragma_Exit is raised.
690 function Find_Lib_Unit_Name return Entity_Id;
691 -- Used for a library unit pragma to find the entity to which the
692 -- library unit pragma applies, returns the entity found.
694 procedure Find_Program_Unit_Name (Id : Node_Id);
695 -- If the pragma is a compilation unit pragma, the id must denote the
696 -- compilation unit in the same compilation, and the pragma must appear
697 -- in the list of preceding or trailing pragmas. If it is a program
698 -- unit pragma that is not a compilation unit pragma, then the
699 -- identifier must be visible.
701 function Find_Unique_Parameterless_Procedure
703 Arg : Node_Id) return Entity_Id;
704 -- Used for a procedure pragma to find the unique parameterless
705 -- procedure identified by Name, returns it if it exists, otherwise
706 -- errors out and uses Arg as the pragma argument for the message.
708 procedure Fix_Error (Msg : in out String);
709 -- This is called prior to issuing an error message. Msg is a string
710 -- which typically contains the substring pragma. If the current pragma
711 -- comes from an aspect, each such "pragma" substring is replaced with
712 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
713 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
715 procedure Gather_Associations
717 Args : out Args_List);
718 -- This procedure is used to gather the arguments for a pragma that
719 -- permits arbitrary ordering of parameters using the normal rules
720 -- for named and positional parameters. The Names argument is a list
721 -- of Name_Id values that corresponds to the allowed pragma argument
722 -- association identifiers in order. The result returned in Args is
723 -- a list of corresponding expressions that are the pragma arguments.
724 -- Note that this is a list of expressions, not of pragma argument
725 -- associations (Gather_Associations has completely checked all the
726 -- optional identifiers when it returns). An entry in Args is Empty
727 -- on return if the corresponding argument is not present.
729 procedure GNAT_Pragma;
730 -- Called for all GNAT defined pragmas to check the relevant restriction
731 -- (No_Implementation_Pragmas).
733 function Is_Before_First_Decl
734 (Pragma_Node : Node_Id;
735 Decls : List_Id) return Boolean;
736 -- Return True if Pragma_Node is before the first declarative item in
737 -- Decls where Decls is the list of declarative items.
739 function Is_Configuration_Pragma return Boolean;
740 -- Determines if the placement of the current pragma is appropriate
741 -- for a configuration pragma.
743 function Is_In_Context_Clause return Boolean;
744 -- Returns True if pragma appears within the context clause of a unit,
745 -- and False for any other placement (does not generate any messages).
747 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
748 -- Analyzes the argument, and determines if it is a static string
749 -- expression, returns True if so, False if non-static or not String.
751 procedure Pragma_Misplaced;
752 pragma No_Return (Pragma_Misplaced);
753 -- Issue fatal error message for misplaced pragma
755 procedure Process_Atomic_Shared_Volatile;
756 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
757 -- Shared is an obsolete Ada 83 pragma, treated as being identical
758 -- in effect to pragma Atomic.
760 procedure Process_Compile_Time_Warning_Or_Error;
761 -- Common processing for Compile_Time_Error and Compile_Time_Warning
763 procedure Process_Convention
764 (C : out Convention_Id;
765 Ent : out Entity_Id);
766 -- Common processing for Convention, Interface, Import and Export.
767 -- Checks first two arguments of pragma, and sets the appropriate
768 -- convention value in the specified entity or entities. On return
769 -- C is the convention, Ent is the referenced entity.
771 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
772 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
773 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
775 procedure Process_Extended_Import_Export_Exception_Pragma
776 (Arg_Internal : Node_Id;
777 Arg_External : Node_Id;
780 -- Common processing for the pragmas Import/Export_Exception. The three
781 -- arguments correspond to the three named parameters of the pragma. An
782 -- argument is empty if the corresponding parameter is not present in
785 procedure Process_Extended_Import_Export_Object_Pragma
786 (Arg_Internal : Node_Id;
787 Arg_External : Node_Id;
789 -- Common processing for the pragmas Import/Export_Object. The three
790 -- arguments correspond to the three named parameters of the pragmas. An
791 -- argument is empty if the corresponding parameter is not present in
794 procedure Process_Extended_Import_Export_Internal_Arg
795 (Arg_Internal : Node_Id := Empty);
796 -- Common processing for all extended Import and Export pragmas. The
797 -- argument is the pragma parameter for the Internal argument. If
798 -- Arg_Internal is empty or inappropriate, an error message is posted.
799 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
800 -- set to identify the referenced entity.
802 procedure Process_Extended_Import_Export_Subprogram_Pragma
803 (Arg_Internal : Node_Id;
804 Arg_External : Node_Id;
805 Arg_Parameter_Types : Node_Id;
806 Arg_Result_Type : Node_Id := Empty;
807 Arg_Mechanism : Node_Id;
808 Arg_Result_Mechanism : Node_Id := Empty;
809 Arg_First_Optional_Parameter : Node_Id := Empty);
810 -- Common processing for all extended Import and Export pragmas applying
811 -- to subprograms. The caller omits any arguments that do not apply to
812 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
813 -- only in the Import_Function and Export_Function cases). The argument
814 -- names correspond to the allowed pragma association identifiers.
816 procedure Process_Generic_List;
817 -- Common processing for Share_Generic and Inline_Generic
819 procedure Process_Import_Or_Interface;
820 -- Common processing for Import of Interface
822 procedure Process_Import_Predefined_Type;
823 -- Processing for completing a type with pragma Import. This is used
824 -- to declare types that match predefined C types, especially for cases
825 -- without corresponding Ada predefined type.
827 procedure Process_Inline (Active : Boolean);
828 -- Common processing for Inline and Inline_Always. The parameter
829 -- indicates if the inline pragma is active, i.e. if it should actually
830 -- cause inlining to occur.
832 procedure Process_Interface_Name
833 (Subprogram_Def : Entity_Id;
836 -- Given the last two arguments of pragma Import, pragma Export, or
837 -- pragma Interface_Name, performs validity checks and sets the
838 -- Interface_Name field of the given subprogram entity to the
839 -- appropriate external or link name, depending on the arguments given.
840 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
841 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
842 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
843 -- nor Link_Arg is present, the interface name is set to the default
844 -- from the subprogram name.
846 procedure Process_Interrupt_Or_Attach_Handler;
847 -- Common processing for Interrupt and Attach_Handler pragmas
849 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
850 -- Common processing for Restrictions and Restriction_Warnings pragmas.
851 -- Warn is True for Restriction_Warnings, or for Restrictions if the
852 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
853 -- is not set in the Restrictions case.
855 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
856 -- Common processing for Suppress and Unsuppress. The boolean parameter
857 -- Suppress_Case is True for the Suppress case, and False for the
860 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
861 -- This procedure sets the Is_Exported flag for the given entity,
862 -- checking that the entity was not previously imported. Arg is
863 -- the argument that specified the entity. A check is also made
864 -- for exporting inappropriate entities.
866 procedure Set_Extended_Import_Export_External_Name
867 (Internal_Ent : Entity_Id;
868 Arg_External : Node_Id);
869 -- Common processing for all extended import export pragmas. The first
870 -- argument, Internal_Ent, is the internal entity, which has already
871 -- been checked for validity by the caller. Arg_External is from the
872 -- Import or Export pragma, and may be null if no External parameter
873 -- was present. If Arg_External is present and is a non-null string
874 -- (a null string is treated as the default), then the Interface_Name
875 -- field of Internal_Ent is set appropriately.
877 procedure Set_Imported (E : Entity_Id);
878 -- This procedure sets the Is_Imported flag for the given entity,
879 -- checking that it is not previously exported or imported.
881 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
882 -- Mech is a parameter passing mechanism (see Import_Function syntax
883 -- for MECHANISM_NAME). This routine checks that the mechanism argument
884 -- has the right form, and if not issues an error message. If the
885 -- argument has the right form then the Mechanism field of Ent is
886 -- set appropriately.
888 procedure Set_Ravenscar_Profile (N : Node_Id);
889 -- Activate the set of configuration pragmas and restrictions that make
890 -- up the Ravenscar Profile. N is the corresponding pragma node, which
891 -- is used for error messages on any constructs that violate the
894 ---------------------
895 -- Ada_2005_Pragma --
896 ---------------------
898 procedure Ada_2005_Pragma is
900 if Ada_Version <= Ada_95 then
901 Check_Restriction (No_Implementation_Pragmas, N);
905 ---------------------
906 -- Ada_2012_Pragma --
907 ---------------------
909 procedure Ada_2012_Pragma is
911 if Ada_Version <= Ada_2005 then
912 Check_Restriction (No_Implementation_Pragmas, N);
916 --------------------------
917 -- Check_Ada_83_Warning --
918 --------------------------
920 procedure Check_Ada_83_Warning is
922 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
923 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
925 end Check_Ada_83_Warning;
927 ---------------------
928 -- Check_Arg_Count --
929 ---------------------
931 procedure Check_Arg_Count (Required : Nat) is
933 if Arg_Count /= Required then
934 Error_Pragma ("wrong number of arguments for pragma%");
938 --------------------------------
939 -- Check_Arg_Is_External_Name --
940 --------------------------------
942 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
943 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
946 if Nkind (Argx) = N_Identifier then
950 Analyze_And_Resolve (Argx, Standard_String);
952 if Is_OK_Static_Expression (Argx) then
955 elsif Etype (Argx) = Any_Type then
958 -- An interesting special case, if we have a string literal and
959 -- we are in Ada 83 mode, then we allow it even though it will
960 -- not be flagged as static. This allows expected Ada 83 mode
961 -- use of external names which are string literals, even though
962 -- technically these are not static in Ada 83.
964 elsif Ada_Version = Ada_83
965 and then Nkind (Argx) = N_String_Literal
969 -- Static expression that raises Constraint_Error. This has
970 -- already been flagged, so just exit from pragma processing.
972 elsif Is_Static_Expression (Argx) then
975 -- Here we have a real error (non-static expression)
978 Error_Msg_Name_1 := Pname;
982 "argument for pragma% must be a identifier or "
983 & "static string expression!";
986 Flag_Non_Static_Expr (Msg, Argx);
991 end Check_Arg_Is_External_Name;
993 -----------------------------
994 -- Check_Arg_Is_Identifier --
995 -----------------------------
997 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
998 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1000 if Nkind (Argx) /= N_Identifier then
1002 ("argument for pragma% must be identifier", Argx);
1004 end Check_Arg_Is_Identifier;
1006 ----------------------------------
1007 -- Check_Arg_Is_Integer_Literal --
1008 ----------------------------------
1010 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1011 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1013 if Nkind (Argx) /= N_Integer_Literal then
1015 ("argument for pragma% must be integer literal", Argx);
1017 end Check_Arg_Is_Integer_Literal;
1019 -------------------------------------------
1020 -- Check_Arg_Is_Library_Level_Local_Name --
1021 -------------------------------------------
1025 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1026 -- | library_unit_NAME
1028 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1030 Check_Arg_Is_Local_Name (Arg);
1032 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1033 and then Comes_From_Source (N)
1036 ("argument for pragma% must be library level entity", Arg);
1038 end Check_Arg_Is_Library_Level_Local_Name;
1040 -----------------------------
1041 -- Check_Arg_Is_Local_Name --
1042 -----------------------------
1046 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1047 -- | library_unit_NAME
1049 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1050 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1055 if Nkind (Argx) not in N_Direct_Name
1056 and then (Nkind (Argx) /= N_Attribute_Reference
1057 or else Present (Expressions (Argx))
1058 or else Nkind (Prefix (Argx)) /= N_Identifier)
1059 and then (not Is_Entity_Name (Argx)
1060 or else not Is_Compilation_Unit (Entity (Argx)))
1062 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1065 -- No further check required if not an entity name
1067 if not Is_Entity_Name (Argx) then
1073 Ent : constant Entity_Id := Entity (Argx);
1074 Scop : constant Entity_Id := Scope (Ent);
1076 -- Case of a pragma applied to a compilation unit: pragma must
1077 -- occur immediately after the program unit in the compilation.
1079 if Is_Compilation_Unit (Ent) then
1081 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1084 -- Case of pragma placed immediately after spec
1086 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1089 -- Case of pragma placed immediately after body
1091 elsif Nkind (Decl) = N_Subprogram_Declaration
1092 and then Present (Corresponding_Body (Decl))
1096 (Parent (Unit_Declaration_Node
1097 (Corresponding_Body (Decl))));
1099 -- All other cases are illegal
1106 -- Special restricted placement rule from 10.2.1(11.8/2)
1108 elsif Is_Generic_Formal (Ent)
1109 and then Prag_Id = Pragma_Preelaborable_Initialization
1111 OK := List_Containing (N) =
1112 Generic_Formal_Declarations
1113 (Unit_Declaration_Node (Scop));
1115 -- Default case, just check that the pragma occurs in the scope
1116 -- of the entity denoted by the name.
1119 OK := Current_Scope = Scop;
1124 ("pragma% argument must be in same declarative part", Arg);
1128 end Check_Arg_Is_Local_Name;
1130 ---------------------------------
1131 -- Check_Arg_Is_Locking_Policy --
1132 ---------------------------------
1134 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1135 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1138 Check_Arg_Is_Identifier (Argx);
1140 if not Is_Locking_Policy_Name (Chars (Argx)) then
1141 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1143 end Check_Arg_Is_Locking_Policy;
1145 -------------------------
1146 -- Check_Arg_Is_One_Of --
1147 -------------------------
1149 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1150 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1153 Check_Arg_Is_Identifier (Argx);
1155 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1156 Error_Msg_Name_2 := N1;
1157 Error_Msg_Name_3 := N2;
1158 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1160 end Check_Arg_Is_One_Of;
1162 procedure Check_Arg_Is_One_Of
1164 N1, N2, N3 : Name_Id)
1166 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1169 Check_Arg_Is_Identifier (Argx);
1171 if Chars (Argx) /= N1
1172 and then Chars (Argx) /= N2
1173 and then Chars (Argx) /= N3
1175 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1177 end Check_Arg_Is_One_Of;
1179 procedure Check_Arg_Is_One_Of
1181 N1, N2, N3, N4, N5 : Name_Id)
1183 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1186 Check_Arg_Is_Identifier (Argx);
1188 if Chars (Argx) /= N1
1189 and then Chars (Argx) /= N2
1190 and then Chars (Argx) /= N3
1191 and then Chars (Argx) /= N4
1192 and then Chars (Argx) /= N5
1194 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1196 end Check_Arg_Is_One_Of;
1197 ---------------------------------
1198 -- Check_Arg_Is_Queuing_Policy --
1199 ---------------------------------
1201 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1202 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1205 Check_Arg_Is_Identifier (Argx);
1207 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1208 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1210 end Check_Arg_Is_Queuing_Policy;
1212 ------------------------------------
1213 -- Check_Arg_Is_Static_Expression --
1214 ------------------------------------
1216 procedure Check_Arg_Is_Static_Expression
1218 Typ : Entity_Id := Empty)
1221 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1222 end Check_Arg_Is_Static_Expression;
1224 ------------------------------------------
1225 -- Check_Arg_Is_Task_Dispatching_Policy --
1226 ------------------------------------------
1228 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1229 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1232 Check_Arg_Is_Identifier (Argx);
1234 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1236 ("& is not a valid task dispatching policy name", Argx);
1238 end Check_Arg_Is_Task_Dispatching_Policy;
1240 ---------------------
1241 -- Check_Arg_Order --
1242 ---------------------
1244 procedure Check_Arg_Order (Names : Name_List) is
1247 Highest_So_Far : Natural := 0;
1248 -- Highest index in Names seen do far
1252 for J in 1 .. Arg_Count loop
1253 if Chars (Arg) /= No_Name then
1254 for K in Names'Range loop
1255 if Chars (Arg) = Names (K) then
1256 if K < Highest_So_Far then
1257 Error_Msg_Name_1 := Pname;
1259 ("parameters out of order for pragma%", Arg);
1260 Error_Msg_Name_1 := Names (K);
1261 Error_Msg_Name_2 := Names (Highest_So_Far);
1262 Error_Msg_N ("\% must appear before %", Arg);
1266 Highest_So_Far := K;
1274 end Check_Arg_Order;
1276 --------------------------------
1277 -- Check_At_Least_N_Arguments --
1278 --------------------------------
1280 procedure Check_At_Least_N_Arguments (N : Nat) is
1282 if Arg_Count < N then
1283 Error_Pragma ("too few arguments for pragma%");
1285 end Check_At_Least_N_Arguments;
1287 -------------------------------
1288 -- Check_At_Most_N_Arguments --
1289 -------------------------------
1291 procedure Check_At_Most_N_Arguments (N : Nat) is
1294 if Arg_Count > N then
1296 for J in 1 .. N loop
1298 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1301 end Check_At_Most_N_Arguments;
1303 ---------------------
1304 -- Check_Component --
1305 ---------------------
1307 procedure Check_Component
1310 In_Variant_Part : Boolean := False)
1312 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1313 Sindic : constant Node_Id :=
1314 Subtype_Indication (Component_Definition (Comp));
1315 Typ : constant Entity_Id := Etype (Comp_Id);
1318 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1319 -- object constraint, then the component type shall be an Unchecked_
1322 if Nkind (Sindic) = N_Subtype_Indication
1323 and then Has_Per_Object_Constraint (Comp_Id)
1324 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1327 ("component subtype subject to per-object constraint " &
1328 "must be an Unchecked_Union", Comp);
1330 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1331 -- the body of a generic unit, or within the body of any of its
1332 -- descendant library units, no part of the type of a component
1333 -- declared in a variant_part of the unchecked union type shall be of
1334 -- a formal private type or formal private extension declared within
1335 -- the formal part of the generic unit.
1337 elsif Ada_Version >= Ada_2012
1338 and then In_Generic_Body (UU_Typ)
1339 and then In_Variant_Part
1340 and then Is_Private_Type (Typ)
1341 and then Is_Generic_Type (Typ)
1344 ("component of Unchecked_Union cannot be of generic type", Comp);
1346 elsif Needs_Finalization (Typ) then
1348 ("component of Unchecked_Union cannot be controlled", Comp);
1350 elsif Has_Task (Typ) then
1352 ("component of Unchecked_Union cannot have tasks", Comp);
1354 end Check_Component;
1356 ----------------------------
1357 -- Check_Duplicate_Pragma --
1358 ----------------------------
1360 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1364 -- Nothing to do if this pragma comes from an aspect specification,
1365 -- since we could not be duplicating a pragma, and we dealt with the
1366 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1368 if From_Aspect_Specification (N) then
1372 -- Otherwise current pragma may duplicate previous pragma or a
1373 -- previously given aspect specification for the same pragma.
1375 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1378 Error_Msg_Name_1 := Pragma_Name (N);
1379 Error_Msg_Sloc := Sloc (P);
1381 if Nkind (P) = N_Aspect_Specification
1382 or else From_Aspect_Specification (P)
1384 Error_Msg_NE ("aspect% for & previously given#", N, E);
1386 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1391 end Check_Duplicate_Pragma;
1393 ----------------------------------
1394 -- Check_Duplicated_Export_Name --
1395 ----------------------------------
1397 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1398 String_Val : constant String_Id := Strval (Nam);
1401 -- We are only interested in the export case, and in the case of
1402 -- generics, it is the instance, not the template, that is the
1403 -- problem (the template will generate a warning in any case).
1405 if not Inside_A_Generic
1406 and then (Prag_Id = Pragma_Export
1408 Prag_Id = Pragma_Export_Procedure
1410 Prag_Id = Pragma_Export_Valued_Procedure
1412 Prag_Id = Pragma_Export_Function)
1414 for J in Externals.First .. Externals.Last loop
1415 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1416 Error_Msg_Sloc := Sloc (Externals.Table (J));
1417 Error_Msg_N ("external name duplicates name given#", Nam);
1422 Externals.Append (Nam);
1424 end Check_Duplicated_Export_Name;
1426 -------------------------------------
1427 -- Check_Expr_Is_Static_Expression --
1428 -------------------------------------
1430 procedure Check_Expr_Is_Static_Expression
1432 Typ : Entity_Id := Empty)
1435 if Present (Typ) then
1436 Analyze_And_Resolve (Expr, Typ);
1438 Analyze_And_Resolve (Expr);
1441 if Is_OK_Static_Expression (Expr) then
1444 elsif Etype (Expr) = Any_Type then
1447 -- An interesting special case, if we have a string literal and we
1448 -- are in Ada 83 mode, then we allow it even though it will not be
1449 -- flagged as static. This allows the use of Ada 95 pragmas like
1450 -- Import in Ada 83 mode. They will of course be flagged with
1451 -- warnings as usual, but will not cause errors.
1453 elsif Ada_Version = Ada_83
1454 and then Nkind (Expr) = N_String_Literal
1458 -- Static expression that raises Constraint_Error. This has already
1459 -- been flagged, so just exit from pragma processing.
1461 elsif Is_Static_Expression (Expr) then
1464 -- Finally, we have a real error
1467 Error_Msg_Name_1 := Pname;
1471 "argument for pragma% must be a static expression!";
1474 Flag_Non_Static_Expr (Msg, Expr);
1479 end Check_Expr_Is_Static_Expression;
1481 -------------------------
1482 -- Check_First_Subtype --
1483 -------------------------
1485 procedure Check_First_Subtype (Arg : Node_Id) is
1486 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1487 Ent : constant Entity_Id := Entity (Argx);
1490 if Is_First_Subtype (Ent) then
1493 elsif Is_Type (Ent) then
1495 ("pragma% cannot apply to subtype", Argx);
1497 elsif Is_Object (Ent) then
1499 ("pragma% cannot apply to object, requires a type", Argx);
1503 ("pragma% cannot apply to&, requires a type", Argx);
1505 end Check_First_Subtype;
1507 ----------------------
1508 -- Check_Identifier --
1509 ----------------------
1511 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1514 and then Nkind (Arg) = N_Pragma_Argument_Association
1516 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1517 Error_Msg_Name_1 := Pname;
1518 Error_Msg_Name_2 := Id;
1519 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1523 end Check_Identifier;
1525 --------------------------------
1526 -- Check_Identifier_Is_One_Of --
1527 --------------------------------
1529 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1532 and then Nkind (Arg) = N_Pragma_Argument_Association
1534 if Chars (Arg) = No_Name then
1535 Error_Msg_Name_1 := Pname;
1536 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1539 elsif Chars (Arg) /= N1
1540 and then Chars (Arg) /= N2
1542 Error_Msg_Name_1 := Pname;
1543 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1547 end Check_Identifier_Is_One_Of;
1549 ---------------------------
1550 -- Check_In_Main_Program --
1551 ---------------------------
1553 procedure Check_In_Main_Program is
1554 P : constant Node_Id := Parent (N);
1557 -- Must be at in subprogram body
1559 if Nkind (P) /= N_Subprogram_Body then
1560 Error_Pragma ("% pragma allowed only in subprogram");
1562 -- Otherwise warn if obviously not main program
1564 elsif Present (Parameter_Specifications (Specification (P)))
1565 or else not Is_Compilation_Unit (Defining_Entity (P))
1567 Error_Msg_Name_1 := Pname;
1569 ("?pragma% is only effective in main program", N);
1571 end Check_In_Main_Program;
1573 ---------------------------------------
1574 -- Check_Interrupt_Or_Attach_Handler --
1575 ---------------------------------------
1577 procedure Check_Interrupt_Or_Attach_Handler is
1578 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1579 Handler_Proc, Proc_Scope : Entity_Id;
1584 if Prag_Id = Pragma_Interrupt_Handler then
1585 Check_Restriction (No_Dynamic_Attachment, N);
1588 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1589 Proc_Scope := Scope (Handler_Proc);
1591 -- On AAMP only, a pragma Interrupt_Handler is supported for
1592 -- nonprotected parameterless procedures.
1594 if not AAMP_On_Target
1595 or else Prag_Id = Pragma_Attach_Handler
1597 if Ekind (Proc_Scope) /= E_Protected_Type then
1599 ("argument of pragma% must be protected procedure", Arg1);
1602 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1603 Error_Pragma ("pragma% must be in protected definition");
1607 if not Is_Library_Level_Entity (Proc_Scope)
1608 or else (AAMP_On_Target
1609 and then not Is_Library_Level_Entity (Handler_Proc))
1612 ("argument for pragma% must be library level entity", Arg1);
1615 -- AI05-0033: A pragma cannot appear within a generic body, because
1616 -- instance can be in a nested scope. The check that protected type
1617 -- is itself a library-level declaration is done elsewhere.
1619 -- Note: we omit this check in Codepeer mode to properly handle code
1620 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1622 if Inside_A_Generic then
1623 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1624 and then In_Package_Body (Scope (Current_Scope))
1625 and then not CodePeer_Mode
1627 Error_Pragma ("pragma% cannot be used inside a generic");
1630 end Check_Interrupt_Or_Attach_Handler;
1632 -------------------------------------------
1633 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1634 -------------------------------------------
1636 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1645 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1648 elsif Nkind_In (P, N_Package_Specification,
1653 -- Note: the following tests seem a little peculiar, because
1654 -- they test for bodies, but if we were in the statement part
1655 -- of the body, we would already have hit the handled statement
1656 -- sequence, so the only way we get here is by being in the
1657 -- declarative part of the body.
1659 elsif Nkind_In (P, N_Subprogram_Body,
1670 Error_Pragma ("pragma% is not in declarative part or package spec");
1671 end Check_Is_In_Decl_Part_Or_Package_Spec;
1673 -------------------------
1674 -- Check_No_Identifier --
1675 -------------------------
1677 procedure Check_No_Identifier (Arg : Node_Id) is
1679 if Nkind (Arg) = N_Pragma_Argument_Association
1680 and then Chars (Arg) /= No_Name
1682 Error_Pragma_Arg_Ident
1683 ("pragma% does not permit identifier& here", Arg);
1685 end Check_No_Identifier;
1687 --------------------------
1688 -- Check_No_Identifiers --
1689 --------------------------
1691 procedure Check_No_Identifiers is
1694 if Arg_Count > 0 then
1696 while Present (Arg_Node) loop
1697 Check_No_Identifier (Arg_Node);
1701 end Check_No_Identifiers;
1703 ------------------------
1704 -- Check_No_Link_Name --
1705 ------------------------
1707 procedure Check_No_Link_Name is
1710 and then Chars (Arg3) = Name_Link_Name
1715 if Present (Arg4) then
1717 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1719 end Check_No_Link_Name;
1721 -------------------------------
1722 -- Check_Optional_Identifier --
1723 -------------------------------
1725 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1728 and then Nkind (Arg) = N_Pragma_Argument_Association
1729 and then Chars (Arg) /= No_Name
1731 if Chars (Arg) /= Id then
1732 Error_Msg_Name_1 := Pname;
1733 Error_Msg_Name_2 := Id;
1734 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1738 end Check_Optional_Identifier;
1740 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1742 Name_Buffer (1 .. Id'Length) := Id;
1743 Name_Len := Id'Length;
1744 Check_Optional_Identifier (Arg, Name_Find);
1745 end Check_Optional_Identifier;
1747 --------------------------------------
1748 -- Check_Precondition_Postcondition --
1749 --------------------------------------
1751 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1755 procedure Chain_PPC (PO : Node_Id);
1756 -- If PO is an entry or a [generic] subprogram declaration node, then
1757 -- the precondition/postcondition applies to this subprogram and the
1758 -- processing for the pragma is completed. Otherwise the pragma is
1765 procedure Chain_PPC (PO : Node_Id) is
1770 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1771 if not From_Aspect_Specification (N) then
1773 ("pragma% cannot be applied to abstract subprogram");
1775 elsif Class_Present (N) then
1780 ("aspect % requires ''Class for abstract subprogram");
1783 -- AI05-0230: The same restriction applies to null procedures. For
1784 -- compatibility with earlier uses of the Ada pragma, apply this
1785 -- rule only to aspect specifications.
1787 -- The above discrpency needs documentation. Robert is dubious
1788 -- about whether it is a good idea ???
1790 elsif Nkind (PO) = N_Subprogram_Declaration
1791 and then Nkind (Specification (PO)) = N_Procedure_Specification
1792 and then Null_Present (Specification (PO))
1793 and then From_Aspect_Specification (N)
1794 and then not Class_Present (N)
1797 ("aspect % requires ''Class for null procedure");
1799 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1800 N_Generic_Subprogram_Declaration,
1801 N_Entry_Declaration)
1806 -- Here if we have [generic] subprogram or entry declaration
1808 if Nkind (PO) = N_Entry_Declaration then
1809 S := Defining_Entity (PO);
1811 S := Defining_Unit_Name (Specification (PO));
1814 -- Make sure we do not have the case of a precondition pragma when
1815 -- the Pre'Class aspect is present.
1817 -- We do this by looking at pragmas already chained to the entity
1818 -- since the aspect derived pragma will be put on this list first.
1820 if Pragma_Name (N) = Name_Precondition then
1821 if not From_Aspect_Specification (N) then
1822 P := Spec_PPC_List (Contract (S));
1823 while Present (P) loop
1824 if Pragma_Name (P) = Name_Precondition
1825 and then From_Aspect_Specification (P)
1826 and then Class_Present (P)
1828 Error_Msg_Sloc := Sloc (P);
1830 ("pragma% not allowed, `Pre''Class` aspect given#");
1833 P := Next_Pragma (P);
1838 -- Similarly check for Pre with inherited Pre'Class. Note that
1839 -- we cover the aspect case as well here.
1841 if Pragma_Name (N) = Name_Precondition
1842 and then not Class_Present (N)
1845 Inherited : constant Subprogram_List :=
1846 Inherited_Subprograms (S);
1850 for J in Inherited'Range loop
1851 P := Spec_PPC_List (Contract (Inherited (J)));
1852 while Present (P) loop
1853 if Pragma_Name (P) = Name_Precondition
1854 and then Class_Present (P)
1856 Error_Msg_Sloc := Sloc (P);
1858 ("pragma% not allowed, `Pre''Class` "
1859 & "aspect inherited from#");
1862 P := Next_Pragma (P);
1868 -- Note: we do not analyze the pragma at this point. Instead we
1869 -- delay this analysis until the end of the declarative part in
1870 -- which the pragma appears. This implements the required delay
1871 -- in this analysis, allowing forward references. The analysis
1872 -- happens at the end of Analyze_Declarations.
1874 -- Chain spec PPC pragma to list for subprogram
1876 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1877 Set_Spec_PPC_List (Contract (S), N);
1879 -- Return indicating spec case
1885 -- Start of processing for Check_Precondition_Postcondition
1888 if not Is_List_Member (N) then
1892 -- Preanalyze message argument if present. Visibility in this
1893 -- argument is established at the point of pragma occurrence.
1895 if Arg_Count = 2 then
1896 Check_Optional_Identifier (Arg2, Name_Message);
1897 Preanalyze_Spec_Expression
1898 (Get_Pragma_Arg (Arg2), Standard_String);
1901 -- Record if pragma is disabled
1903 if Check_Enabled (Pname) then
1904 Set_SCO_Pragma_Enabled (Loc);
1907 -- If we are within an inlined body, the legality of the pragma
1908 -- has been checked already.
1910 if In_Inlined_Body then
1915 -- Search prior declarations
1918 while Present (Prev (P)) loop
1921 -- If the previous node is a generic subprogram, do not go to to
1922 -- the original node, which is the unanalyzed tree: we need to
1923 -- attach the pre/postconditions to the analyzed version at this
1924 -- point. They get propagated to the original tree when analyzing
1925 -- the corresponding body.
1927 if Nkind (P) not in N_Generic_Declaration then
1928 PO := Original_Node (P);
1933 -- Skip past prior pragma
1935 if Nkind (PO) = N_Pragma then
1938 -- Skip stuff not coming from source
1940 elsif not Comes_From_Source (PO) then
1942 -- The condition may apply to a subprogram instantiation
1944 if Nkind (PO) = N_Subprogram_Declaration
1945 and then Present (Generic_Parent (Specification (PO)))
1950 elsif Nkind (PO) = N_Subprogram_Declaration
1951 and then In_Instance
1956 -- For all other cases of non source code, do nothing
1962 -- Only remaining possibility is subprogram declaration
1970 -- If we fall through loop, pragma is at start of list, so see if it
1971 -- is at the start of declarations of a subprogram body.
1973 if Nkind (Parent (N)) = N_Subprogram_Body
1974 and then List_Containing (N) = Declarations (Parent (N))
1976 if Operating_Mode /= Generate_Code
1977 or else Inside_A_Generic
1979 -- Analyze pragma expression for correctness and for ASIS use
1981 Preanalyze_Spec_Expression
1982 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1984 -- In ASIS mode, for a pragma generated from a source aspect,
1985 -- also analyze the original aspect expression.
1988 and then Present (Corresponding_Aspect (N))
1990 Preanalyze_Spec_Expression
1991 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
1998 -- See if it is in the pragmas after a library level subprogram
2000 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2002 -- In formal verification mode, analyze pragma expression for
2003 -- correctness, as it is not expanded later.
2006 Analyze_PPC_In_Decl_Part
2007 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2010 Chain_PPC (Unit (Parent (Parent (N))));
2014 -- If we fall through, pragma was misplaced
2017 end Check_Precondition_Postcondition;
2019 -----------------------------
2020 -- Check_Static_Constraint --
2021 -----------------------------
2023 -- Note: for convenience in writing this procedure, in addition to
2024 -- the officially (i.e. by spec) allowed argument which is always a
2025 -- constraint, it also allows ranges and discriminant associations.
2026 -- Above is not clear ???
2028 procedure Check_Static_Constraint (Constr : Node_Id) is
2030 procedure Require_Static (E : Node_Id);
2031 -- Require given expression to be static expression
2033 --------------------
2034 -- Require_Static --
2035 --------------------
2037 procedure Require_Static (E : Node_Id) is
2039 if not Is_OK_Static_Expression (E) then
2040 Flag_Non_Static_Expr
2041 ("non-static constraint not allowed in Unchecked_Union!", E);
2046 -- Start of processing for Check_Static_Constraint
2049 case Nkind (Constr) is
2050 when N_Discriminant_Association =>
2051 Require_Static (Expression (Constr));
2054 Require_Static (Low_Bound (Constr));
2055 Require_Static (High_Bound (Constr));
2057 when N_Attribute_Reference =>
2058 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2059 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2061 when N_Range_Constraint =>
2062 Check_Static_Constraint (Range_Expression (Constr));
2064 when N_Index_Or_Discriminant_Constraint =>
2068 IDC := First (Constraints (Constr));
2069 while Present (IDC) loop
2070 Check_Static_Constraint (IDC);
2078 end Check_Static_Constraint;
2080 ---------------------
2081 -- Check_Test_Case --
2082 ---------------------
2084 procedure Check_Test_Case is
2088 procedure Chain_TC (PO : Node_Id);
2089 -- If PO is a [generic] subprogram declaration node, then the
2090 -- test-case applies to this subprogram and the processing for the
2091 -- pragma is completed. Otherwise the pragma is misplaced.
2097 procedure Chain_TC (PO : Node_Id) is
2101 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2102 if From_Aspect_Specification (N) then
2104 ("aspect% cannot be applied to abstract subprogram");
2107 ("pragma% cannot be applied to abstract subprogram");
2110 elsif Nkind (PO) = N_Entry_Declaration then
2111 if From_Aspect_Specification (N) then
2112 Error_Pragma ("aspect% cannot be applied to entry");
2114 Error_Pragma ("pragma% cannot be applied to entry");
2117 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2118 N_Generic_Subprogram_Declaration)
2123 -- Here if we have [generic] subprogram declaration
2125 S := Defining_Unit_Name (Specification (PO));
2127 -- Note: we do not analyze the pragma at this point. Instead we
2128 -- delay this analysis until the end of the declarative part in
2129 -- which the pragma appears. This implements the required delay
2130 -- in this analysis, allowing forward references. The analysis
2131 -- happens at the end of Analyze_Declarations.
2133 -- There should not be another test case with the same name
2134 -- associated to this subprogram.
2137 Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2141 TC := Spec_TC_List (Contract (S));
2142 while Present (TC) loop
2145 (Name, Get_Name_From_Test_Case_Pragma (TC))
2147 Error_Msg_Sloc := Sloc (TC);
2149 if From_Aspect_Specification (N) then
2150 Error_Pragma ("name for aspect% is already used#");
2152 Error_Pragma ("name for pragma% is already used#");
2156 TC := Next_Pragma (TC);
2160 -- Chain spec TC pragma to list for subprogram
2162 Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2163 Set_Spec_TC_List (Contract (S), N);
2166 -- Start of processing for Check_Test_Case
2169 if not Is_List_Member (N) then
2173 -- Test cases should only appear in package spec unit
2175 if Get_Source_Unit (N) = No_Unit
2176 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2177 N_Package_Declaration,
2178 N_Generic_Package_Declaration)
2183 -- Search prior declarations
2186 while Present (Prev (P)) loop
2189 -- If the previous node is a generic subprogram, do not go to to
2190 -- the original node, which is the unanalyzed tree: we need to
2191 -- attach the test-case to the analyzed version at this point.
2192 -- They get propagated to the original tree when analyzing the
2193 -- corresponding body.
2195 if Nkind (P) not in N_Generic_Declaration then
2196 PO := Original_Node (P);
2201 -- Skip past prior pragma
2203 if Nkind (PO) = N_Pragma then
2206 -- Skip stuff not coming from source
2208 elsif not Comes_From_Source (PO) then
2211 -- Only remaining possibility is subprogram declaration. First
2212 -- check that it is declared directly in a package declaration.
2213 -- This may be either the package declaration for the current unit
2214 -- being defined or a local package declaration.
2216 elsif not Present (Parent (Parent (PO)))
2217 or else not Present (Parent (Parent (Parent (PO))))
2218 or else not Nkind_In (Parent (Parent (PO)),
2219 N_Package_Declaration,
2220 N_Generic_Package_Declaration)
2230 -- If we fall through, pragma was misplaced
2233 end Check_Test_Case;
2235 --------------------------------------
2236 -- Check_Valid_Configuration_Pragma --
2237 --------------------------------------
2239 -- A configuration pragma must appear in the context clause of a
2240 -- compilation unit, and only other pragmas may precede it. Note that
2241 -- the test also allows use in a configuration pragma file.
2243 procedure Check_Valid_Configuration_Pragma is
2245 if not Is_Configuration_Pragma then
2246 Error_Pragma ("incorrect placement for configuration pragma%");
2248 end Check_Valid_Configuration_Pragma;
2250 -------------------------------------
2251 -- Check_Valid_Library_Unit_Pragma --
2252 -------------------------------------
2254 procedure Check_Valid_Library_Unit_Pragma is
2256 Parent_Node : Node_Id;
2257 Unit_Name : Entity_Id;
2258 Unit_Kind : Node_Kind;
2259 Unit_Node : Node_Id;
2260 Sindex : Source_File_Index;
2263 if not Is_List_Member (N) then
2267 Plist := List_Containing (N);
2268 Parent_Node := Parent (Plist);
2270 if Parent_Node = Empty then
2273 -- Case of pragma appearing after a compilation unit. In this case
2274 -- it must have an argument with the corresponding name and must
2275 -- be part of the following pragmas of its parent.
2277 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2278 if Plist /= Pragmas_After (Parent_Node) then
2281 elsif Arg_Count = 0 then
2283 ("argument required if outside compilation unit");
2286 Check_No_Identifiers;
2287 Check_Arg_Count (1);
2288 Unit_Node := Unit (Parent (Parent_Node));
2289 Unit_Kind := Nkind (Unit_Node);
2291 Analyze (Get_Pragma_Arg (Arg1));
2293 if Unit_Kind = N_Generic_Subprogram_Declaration
2294 or else Unit_Kind = N_Subprogram_Declaration
2296 Unit_Name := Defining_Entity (Unit_Node);
2298 elsif Unit_Kind in N_Generic_Instantiation then
2299 Unit_Name := Defining_Entity (Unit_Node);
2302 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2305 if Chars (Unit_Name) /=
2306 Chars (Entity (Get_Pragma_Arg (Arg1)))
2309 ("pragma% argument is not current unit name", Arg1);
2312 if Ekind (Unit_Name) = E_Package
2313 and then Present (Renamed_Entity (Unit_Name))
2315 Error_Pragma ("pragma% not allowed for renamed package");
2319 -- Pragma appears other than after a compilation unit
2322 -- Here we check for the generic instantiation case and also
2323 -- for the case of processing a generic formal package. We
2324 -- detect these cases by noting that the Sloc on the node
2325 -- does not belong to the current compilation unit.
2327 Sindex := Source_Index (Current_Sem_Unit);
2329 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2330 Rewrite (N, Make_Null_Statement (Loc));
2333 -- If before first declaration, the pragma applies to the
2334 -- enclosing unit, and the name if present must be this name.
2336 elsif Is_Before_First_Decl (N, Plist) then
2337 Unit_Node := Unit_Declaration_Node (Current_Scope);
2338 Unit_Kind := Nkind (Unit_Node);
2340 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2343 elsif Unit_Kind = N_Subprogram_Body
2344 and then not Acts_As_Spec (Unit_Node)
2348 elsif Nkind (Parent_Node) = N_Package_Body then
2351 elsif Nkind (Parent_Node) = N_Package_Specification
2352 and then Plist = Private_Declarations (Parent_Node)
2356 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2357 or else Nkind (Parent_Node) =
2358 N_Generic_Subprogram_Declaration)
2359 and then Plist = Generic_Formal_Declarations (Parent_Node)
2363 elsif Arg_Count > 0 then
2364 Analyze (Get_Pragma_Arg (Arg1));
2366 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2368 ("name in pragma% must be enclosing unit", Arg1);
2371 -- It is legal to have no argument in this context
2377 -- Error if not before first declaration. This is because a
2378 -- library unit pragma argument must be the name of a library
2379 -- unit (RM 10.1.5(7)), but the only names permitted in this
2380 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2381 -- generic subprogram declarations or generic instantiations.
2385 ("pragma% misplaced, must be before first declaration");
2389 end Check_Valid_Library_Unit_Pragma;
2395 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2396 Clist : constant Node_Id := Component_List (Variant);
2400 if not Is_Non_Empty_List (Component_Items (Clist)) then
2402 ("Unchecked_Union may not have empty component list",
2407 Comp := First (Component_Items (Clist));
2408 while Present (Comp) loop
2409 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2418 procedure Error_Pragma (Msg : String) is
2419 MsgF : String := Msg;
2421 Error_Msg_Name_1 := Pname;
2423 Error_Msg_N (MsgF, N);
2427 ----------------------
2428 -- Error_Pragma_Arg --
2429 ----------------------
2431 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2432 MsgF : String := Msg;
2434 Error_Msg_Name_1 := Pname;
2436 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2438 end Error_Pragma_Arg;
2440 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2441 MsgF : String := Msg1;
2443 Error_Msg_Name_1 := Pname;
2445 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2446 Error_Pragma_Arg (Msg2, Arg);
2447 end Error_Pragma_Arg;
2449 ----------------------------
2450 -- Error_Pragma_Arg_Ident --
2451 ----------------------------
2453 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2454 MsgF : String := Msg;
2456 Error_Msg_Name_1 := Pname;
2458 Error_Msg_N (MsgF, Arg);
2460 end Error_Pragma_Arg_Ident;
2462 ----------------------
2463 -- Error_Pragma_Ref --
2464 ----------------------
2466 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2467 MsgF : String := Msg;
2469 Error_Msg_Name_1 := Pname;
2471 Error_Msg_Sloc := Sloc (Ref);
2472 Error_Msg_NE (MsgF, N, Ref);
2474 end Error_Pragma_Ref;
2476 ------------------------
2477 -- Find_Lib_Unit_Name --
2478 ------------------------
2480 function Find_Lib_Unit_Name return Entity_Id is
2482 -- Return inner compilation unit entity, for case of nested
2483 -- categorization pragmas. This happens in generic unit.
2485 if Nkind (Parent (N)) = N_Package_Specification
2486 and then Defining_Entity (Parent (N)) /= Current_Scope
2488 return Defining_Entity (Parent (N));
2490 return Current_Scope;
2492 end Find_Lib_Unit_Name;
2494 ----------------------------
2495 -- Find_Program_Unit_Name --
2496 ----------------------------
2498 procedure Find_Program_Unit_Name (Id : Node_Id) is
2499 Unit_Name : Entity_Id;
2500 Unit_Kind : Node_Kind;
2501 P : constant Node_Id := Parent (N);
2504 if Nkind (P) = N_Compilation_Unit then
2505 Unit_Kind := Nkind (Unit (P));
2507 if Unit_Kind = N_Subprogram_Declaration
2508 or else Unit_Kind = N_Package_Declaration
2509 or else Unit_Kind in N_Generic_Declaration
2511 Unit_Name := Defining_Entity (Unit (P));
2513 if Chars (Id) = Chars (Unit_Name) then
2514 Set_Entity (Id, Unit_Name);
2515 Set_Etype (Id, Etype (Unit_Name));
2517 Set_Etype (Id, Any_Type);
2519 ("cannot find program unit referenced by pragma%");
2523 Set_Etype (Id, Any_Type);
2524 Error_Pragma ("pragma% inapplicable to this unit");
2530 end Find_Program_Unit_Name;
2532 -----------------------------------------
2533 -- Find_Unique_Parameterless_Procedure --
2534 -----------------------------------------
2536 function Find_Unique_Parameterless_Procedure
2538 Arg : Node_Id) return Entity_Id
2540 Proc : Entity_Id := Empty;
2543 -- The body of this procedure needs some comments ???
2545 if not Is_Entity_Name (Name) then
2547 ("argument of pragma% must be entity name", Arg);
2549 elsif not Is_Overloaded (Name) then
2550 Proc := Entity (Name);
2552 if Ekind (Proc) /= E_Procedure
2553 or else Present (First_Formal (Proc))
2556 ("argument of pragma% must be parameterless procedure", Arg);
2561 Found : Boolean := False;
2563 Index : Interp_Index;
2566 Get_First_Interp (Name, Index, It);
2567 while Present (It.Nam) loop
2570 if Ekind (Proc) = E_Procedure
2571 and then No (First_Formal (Proc))
2575 Set_Entity (Name, Proc);
2576 Set_Is_Overloaded (Name, False);
2579 ("ambiguous handler name for pragma% ", Arg);
2583 Get_Next_Interp (Index, It);
2588 ("argument of pragma% must be parameterless procedure",
2591 Proc := Entity (Name);
2597 end Find_Unique_Parameterless_Procedure;
2603 procedure Fix_Error (Msg : in out String) is
2605 if From_Aspect_Specification (N) then
2606 for J in Msg'First .. Msg'Last - 5 loop
2607 if Msg (J .. J + 5) = "pragma" then
2608 Msg (J .. J + 5) := "aspect";
2612 if Error_Msg_Name_1 = Name_Precondition then
2613 Error_Msg_Name_1 := Name_Pre;
2614 elsif Error_Msg_Name_1 = Name_Postcondition then
2615 Error_Msg_Name_1 := Name_Post;
2620 -------------------------
2621 -- Gather_Associations --
2622 -------------------------
2624 procedure Gather_Associations
2626 Args : out Args_List)
2631 -- Initialize all parameters to Empty
2633 for J in Args'Range loop
2637 -- That's all we have to do if there are no argument associations
2639 if No (Pragma_Argument_Associations (N)) then
2643 -- Otherwise first deal with any positional parameters present
2645 Arg := First (Pragma_Argument_Associations (N));
2646 for Index in Args'Range loop
2647 exit when No (Arg) or else Chars (Arg) /= No_Name;
2648 Args (Index) := Get_Pragma_Arg (Arg);
2652 -- Positional parameters all processed, if any left, then we
2653 -- have too many positional parameters.
2655 if Present (Arg) and then Chars (Arg) = No_Name then
2657 ("too many positional associations for pragma%", Arg);
2660 -- Process named parameters if any are present
2662 while Present (Arg) loop
2663 if Chars (Arg) = No_Name then
2665 ("positional association cannot follow named association",
2669 for Index in Names'Range loop
2670 if Names (Index) = Chars (Arg) then
2671 if Present (Args (Index)) then
2673 ("duplicate argument association for pragma%", Arg);
2675 Args (Index) := Get_Pragma_Arg (Arg);
2680 if Index = Names'Last then
2681 Error_Msg_Name_1 := Pname;
2682 Error_Msg_N ("pragma% does not allow & argument", Arg);
2684 -- Check for possible misspelling
2686 for Index1 in Names'Range loop
2687 if Is_Bad_Spelling_Of
2688 (Chars (Arg), Names (Index1))
2690 Error_Msg_Name_1 := Names (Index1);
2691 Error_Msg_N -- CODEFIX
2692 ("\possible misspelling of%", Arg);
2704 end Gather_Associations;
2710 procedure GNAT_Pragma is
2712 -- We need to check the No_Implementation_Pragmas restriction for
2713 -- the case of a pragma from source. Note that the case of aspects
2714 -- generating corresponding pragmas marks these pragmas as not being
2715 -- from source, so this test also catches that case.
2717 if Comes_From_Source (N) then
2718 Check_Restriction (No_Implementation_Pragmas, N);
2722 --------------------------
2723 -- Is_Before_First_Decl --
2724 --------------------------
2726 function Is_Before_First_Decl
2727 (Pragma_Node : Node_Id;
2728 Decls : List_Id) return Boolean
2730 Item : Node_Id := First (Decls);
2733 -- Only other pragmas can come before this pragma
2736 if No (Item) or else Nkind (Item) /= N_Pragma then
2739 elsif Item = Pragma_Node then
2745 end Is_Before_First_Decl;
2747 -----------------------------
2748 -- Is_Configuration_Pragma --
2749 -----------------------------
2751 -- A configuration pragma must appear in the context clause of a
2752 -- compilation unit, and only other pragmas may precede it. Note that
2753 -- the test below also permits use in a configuration pragma file.
2755 function Is_Configuration_Pragma return Boolean is
2756 Lis : constant List_Id := List_Containing (N);
2757 Par : constant Node_Id := Parent (N);
2761 -- If no parent, then we are in the configuration pragma file,
2762 -- so the placement is definitely appropriate.
2767 -- Otherwise we must be in the context clause of a compilation unit
2768 -- and the only thing allowed before us in the context list is more
2769 -- configuration pragmas.
2771 elsif Nkind (Par) = N_Compilation_Unit
2772 and then Context_Items (Par) = Lis
2779 elsif Nkind (Prg) /= N_Pragma then
2789 end Is_Configuration_Pragma;
2791 --------------------------
2792 -- Is_In_Context_Clause --
2793 --------------------------
2795 function Is_In_Context_Clause return Boolean is
2797 Parent_Node : Node_Id;
2800 if not Is_List_Member (N) then
2804 Plist := List_Containing (N);
2805 Parent_Node := Parent (Plist);
2807 if Parent_Node = Empty
2808 or else Nkind (Parent_Node) /= N_Compilation_Unit
2809 or else Context_Items (Parent_Node) /= Plist
2816 end Is_In_Context_Clause;
2818 ---------------------------------
2819 -- Is_Static_String_Expression --
2820 ---------------------------------
2822 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2823 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2826 Analyze_And_Resolve (Argx);
2827 return Is_OK_Static_Expression (Argx)
2828 and then Nkind (Argx) = N_String_Literal;
2829 end Is_Static_String_Expression;
2831 ----------------------
2832 -- Pragma_Misplaced --
2833 ----------------------
2835 procedure Pragma_Misplaced is
2837 Error_Pragma ("incorrect placement of pragma%");
2838 end Pragma_Misplaced;
2840 ------------------------------------
2841 -- Process Atomic_Shared_Volatile --
2842 ------------------------------------
2844 procedure Process_Atomic_Shared_Volatile is
2851 procedure Set_Atomic (E : Entity_Id);
2852 -- Set given type as atomic, and if no explicit alignment was given,
2853 -- set alignment to unknown, since back end knows what the alignment
2854 -- requirements are for atomic arrays. Note: this step is necessary
2855 -- for derived types.
2861 procedure Set_Atomic (E : Entity_Id) is
2865 if not Has_Alignment_Clause (E) then
2866 Set_Alignment (E, Uint_0);
2870 -- Start of processing for Process_Atomic_Shared_Volatile
2873 Check_Ada_83_Warning;
2874 Check_No_Identifiers;
2875 Check_Arg_Count (1);
2876 Check_Arg_Is_Local_Name (Arg1);
2877 E_Id := Get_Pragma_Arg (Arg1);
2879 if Etype (E_Id) = Any_Type then
2884 D := Declaration_Node (E);
2887 -- Check duplicate before we chain ourselves!
2889 Check_Duplicate_Pragma (E);
2891 -- Now check appropriateness of the entity
2894 if Rep_Item_Too_Early (E, N)
2896 Rep_Item_Too_Late (E, N)
2900 Check_First_Subtype (Arg1);
2903 if Prag_Id /= Pragma_Volatile then
2905 Set_Atomic (Underlying_Type (E));
2906 Set_Atomic (Base_Type (E));
2909 -- Attribute belongs on the base type. If the view of the type is
2910 -- currently private, it also belongs on the underlying type.
2912 Set_Is_Volatile (Base_Type (E));
2913 Set_Is_Volatile (Underlying_Type (E));
2915 Set_Treat_As_Volatile (E);
2916 Set_Treat_As_Volatile (Underlying_Type (E));
2918 elsif K = N_Object_Declaration
2919 or else (K = N_Component_Declaration
2920 and then Original_Record_Component (E) = E)
2922 if Rep_Item_Too_Late (E, N) then
2926 if Prag_Id /= Pragma_Volatile then
2929 -- If the object declaration has an explicit initialization, a
2930 -- temporary may have to be created to hold the expression, to
2931 -- ensure that access to the object remain atomic.
2933 if Nkind (Parent (E)) = N_Object_Declaration
2934 and then Present (Expression (Parent (E)))
2936 Set_Has_Delayed_Freeze (E);
2939 -- An interesting improvement here. If an object of type X is
2940 -- declared atomic, and the type X is not atomic, that's a
2941 -- pity, since it may not have appropriate alignment etc. We
2942 -- can rescue this in the special case where the object and
2943 -- type are in the same unit by just setting the type as
2944 -- atomic, so that the back end will process it as atomic.
2946 Utyp := Underlying_Type (Etype (E));
2949 and then Sloc (E) > No_Location
2950 and then Sloc (Utyp) > No_Location
2952 Get_Source_File_Index (Sloc (E)) =
2953 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2955 Set_Is_Atomic (Underlying_Type (Etype (E)));
2959 Set_Is_Volatile (E);
2960 Set_Treat_As_Volatile (E);
2964 ("inappropriate entity for pragma%", Arg1);
2966 end Process_Atomic_Shared_Volatile;
2968 -------------------------------------------
2969 -- Process_Compile_Time_Warning_Or_Error --
2970 -------------------------------------------
2972 procedure Process_Compile_Time_Warning_Or_Error is
2973 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2976 Check_Arg_Count (2);
2977 Check_No_Identifiers;
2978 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2979 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2981 if Compile_Time_Known_Value (Arg1x) then
2982 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2984 Str : constant String_Id :=
2985 Strval (Get_Pragma_Arg (Arg2));
2986 Len : constant Int := String_Length (Str);
2991 Cent : constant Entity_Id :=
2992 Cunit_Entity (Current_Sem_Unit);
2994 Force : constant Boolean :=
2995 Prag_Id = Pragma_Compile_Time_Warning
2997 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2998 and then (Ekind (Cent) /= E_Package
2999 or else not In_Private_Part (Cent));
3000 -- Set True if this is the warning case, and we are in the
3001 -- visible part of a package spec, or in a subprogram spec,
3002 -- in which case we want to force the client to see the
3003 -- warning, even though it is not in the main unit.
3006 -- Loop through segments of message separated by line feeds.
3007 -- We output these segments as separate messages with
3008 -- continuation marks for all but the first.
3013 Error_Msg_Strlen := 0;
3015 -- Loop to copy characters from argument to error message
3019 exit when Ptr > Len;
3020 CC := Get_String_Char (Str, Ptr);
3023 -- Ignore wide chars ??? else store character
3025 if In_Character_Range (CC) then
3026 C := Get_Character (CC);
3027 exit when C = ASCII.LF;
3028 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3029 Error_Msg_String (Error_Msg_Strlen) := C;
3033 -- Here with one line ready to go
3035 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3037 -- If this is a warning in a spec, then we want clients
3038 -- to see the warning, so mark the message with the
3039 -- special sequence !! to force the warning. In the case
3040 -- of a package spec, we do not force this if we are in
3041 -- the private part of the spec.
3044 if Cont = False then
3045 Error_Msg_N ("<~!!", Arg1);
3048 Error_Msg_N ("\<~!!", Arg1);
3051 -- Error, rather than warning, or in a body, so we do not
3052 -- need to force visibility for client (error will be
3053 -- output in any case, and this is the situation in which
3054 -- we do not want a client to get a warning, since the
3055 -- warning is in the body or the spec private part).
3058 if Cont = False then
3059 Error_Msg_N ("<~", Arg1);
3062 Error_Msg_N ("\<~", Arg1);
3066 exit when Ptr > Len;
3071 end Process_Compile_Time_Warning_Or_Error;
3073 ------------------------
3074 -- Process_Convention --
3075 ------------------------
3077 procedure Process_Convention
3078 (C : out Convention_Id;
3079 Ent : out Entity_Id)
3085 Comp_Unit : Unit_Number_Type;
3087 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3088 -- Called if we have more than one Export/Import/Convention pragma.
3089 -- This is generally illegal, but we have a special case of allowing
3090 -- Import and Interface to coexist if they specify the convention in
3091 -- a consistent manner. We are allowed to do this, since Interface is
3092 -- an implementation defined pragma, and we choose to do it since we
3093 -- know Rational allows this combination. S is the entity id of the
3094 -- subprogram in question. This procedure also sets the special flag
3095 -- Import_Interface_Present in both pragmas in the case where we do
3096 -- have matching Import and Interface pragmas.
3098 procedure Set_Convention_From_Pragma (E : Entity_Id);
3099 -- Set convention in entity E, and also flag that the entity has a
3100 -- convention pragma. If entity is for a private or incomplete type,
3101 -- also set convention and flag on underlying type. This procedure
3102 -- also deals with the special case of C_Pass_By_Copy convention.
3104 -------------------------------
3105 -- Diagnose_Multiple_Pragmas --
3106 -------------------------------
3108 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3109 Pdec : constant Node_Id := Declaration_Node (S);
3113 function Same_Convention (Decl : Node_Id) return Boolean;
3114 -- Decl is a pragma node. This function returns True if this
3115 -- pragma has a first argument that is an identifier with a
3116 -- Chars field corresponding to the Convention_Id C.
3118 function Same_Name (Decl : Node_Id) return Boolean;
3119 -- Decl is a pragma node. This function returns True if this
3120 -- pragma has a second argument that is an identifier with a
3121 -- Chars field that matches the Chars of the current subprogram.
3123 ---------------------
3124 -- Same_Convention --
3125 ---------------------
3127 function Same_Convention (Decl : Node_Id) return Boolean is
3128 Arg1 : constant Node_Id :=
3129 First (Pragma_Argument_Associations (Decl));
3132 if Present (Arg1) then
3134 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3136 if Nkind (Arg) = N_Identifier
3137 and then Is_Convention_Name (Chars (Arg))
3138 and then Get_Convention_Id (Chars (Arg)) = C
3146 end Same_Convention;
3152 function Same_Name (Decl : Node_Id) return Boolean is
3153 Arg1 : constant Node_Id :=
3154 First (Pragma_Argument_Associations (Decl));
3162 Arg2 := Next (Arg1);
3169 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3171 if Nkind (Arg) = N_Identifier
3172 and then Chars (Arg) = Chars (S)
3181 -- Start of processing for Diagnose_Multiple_Pragmas
3186 -- Definitely give message if we have Convention/Export here
3188 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3191 -- If we have an Import or Export, scan back from pragma to
3192 -- find any previous pragma applying to the same procedure.
3193 -- The scan will be terminated by the start of the list, or
3194 -- hitting the subprogram declaration. This won't allow one
3195 -- pragma to appear in the public part and one in the private
3196 -- part, but that seems very unlikely in practice.
3200 while Present (Decl) and then Decl /= Pdec loop
3202 -- Look for pragma with same name as us
3204 if Nkind (Decl) = N_Pragma
3205 and then Same_Name (Decl)
3207 -- Give error if same as our pragma or Export/Convention
3209 if Pragma_Name (Decl) = Name_Export
3211 Pragma_Name (Decl) = Name_Convention
3213 Pragma_Name (Decl) = Pragma_Name (N)
3217 -- Case of Import/Interface or the other way round
3219 elsif Pragma_Name (Decl) = Name_Interface
3221 Pragma_Name (Decl) = Name_Import
3223 -- Here we know that we have Import and Interface. It
3224 -- doesn't matter which way round they are. See if
3225 -- they specify the same convention. If so, all OK,
3226 -- and set special flags to stop other messages
3228 if Same_Convention (Decl) then
3229 Set_Import_Interface_Present (N);
3230 Set_Import_Interface_Present (Decl);
3233 -- If different conventions, special message
3236 Error_Msg_Sloc := Sloc (Decl);
3238 ("convention differs from that given#", Arg1);
3248 -- Give message if needed if we fall through those tests
3252 ("at most one Convention/Export/Import pragma is allowed",
3255 end Diagnose_Multiple_Pragmas;
3257 --------------------------------
3258 -- Set_Convention_From_Pragma --
3259 --------------------------------
3261 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3263 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3264 -- for an overridden dispatching operation. Technically this is
3265 -- an amendment and should only be done in Ada 2005 mode. However,
3266 -- this is clearly a mistake, since the problem that is addressed
3267 -- by this AI is that there is a clear gap in the RM!
3269 if Is_Dispatching_Operation (E)
3270 and then Present (Overridden_Operation (E))
3271 and then C /= Convention (Overridden_Operation (E))
3274 ("cannot change convention for " &
3275 "overridden dispatching operation",
3279 -- Set the convention
3281 Set_Convention (E, C);
3282 Set_Has_Convention_Pragma (E);
3284 if Is_Incomplete_Or_Private_Type (E)
3285 and then Present (Underlying_Type (E))
3287 Set_Convention (Underlying_Type (E), C);
3288 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3291 -- A class-wide type should inherit the convention of the specific
3292 -- root type (although this isn't specified clearly by the RM).
3294 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3295 Set_Convention (Class_Wide_Type (E), C);
3298 -- If the entity is a record type, then check for special case of
3299 -- C_Pass_By_Copy, which is treated the same as C except that the
3300 -- special record flag is set. This convention is only permitted
3301 -- on record types (see AI95-00131).
3303 if Cname = Name_C_Pass_By_Copy then
3304 if Is_Record_Type (E) then
3305 Set_C_Pass_By_Copy (Base_Type (E));
3306 elsif Is_Incomplete_Or_Private_Type (E)
3307 and then Is_Record_Type (Underlying_Type (E))
3309 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3312 ("C_Pass_By_Copy convention allowed only for record type",
3317 -- If the entity is a derived boolean type, check for the special
3318 -- case of convention C, C++, or Fortran, where we consider any
3319 -- nonzero value to represent true.
3321 if Is_Discrete_Type (E)
3322 and then Root_Type (Etype (E)) = Standard_Boolean
3328 C = Convention_Fortran)
3330 Set_Nonzero_Is_True (Base_Type (E));
3332 end Set_Convention_From_Pragma;
3334 -- Start of processing for Process_Convention
3337 Check_At_Least_N_Arguments (2);
3338 Check_Optional_Identifier (Arg1, Name_Convention);
3339 Check_Arg_Is_Identifier (Arg1);
3340 Cname := Chars (Get_Pragma_Arg (Arg1));
3342 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3343 -- tested again below to set the critical flag).
3345 if Cname = Name_C_Pass_By_Copy then
3348 -- Otherwise we must have something in the standard convention list
3350 elsif Is_Convention_Name (Cname) then
3351 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3353 -- In DEC VMS, it seems that there is an undocumented feature that
3354 -- any unrecognized convention is treated as the default, which for
3355 -- us is convention C. It does not seem so terrible to do this
3356 -- unconditionally, silently in the VMS case, and with a warning
3357 -- in the non-VMS case.
3360 if Warn_On_Export_Import and not OpenVMS_On_Target then
3362 ("?unrecognized convention name, C assumed",
3363 Get_Pragma_Arg (Arg1));
3369 Check_Optional_Identifier (Arg2, Name_Entity);
3370 Check_Arg_Is_Local_Name (Arg2);
3372 Id := Get_Pragma_Arg (Arg2);
3375 if not Is_Entity_Name (Id) then
3376 Error_Pragma_Arg ("entity name required", Arg2);
3381 -- Set entity to return
3385 -- Ada_Pass_By_Copy special checking
3387 if C = Convention_Ada_Pass_By_Copy then
3388 if not Is_First_Subtype (E) then
3390 ("convention `Ada_Pass_By_Copy` only "
3391 & "allowed for types", Arg2);
3394 if Is_By_Reference_Type (E) then
3396 ("convention `Ada_Pass_By_Copy` not allowed for "
3397 & "by-reference type", Arg1);
3401 -- Ada_Pass_By_Reference special checking
3403 if C = Convention_Ada_Pass_By_Reference then
3404 if not Is_First_Subtype (E) then
3406 ("convention `Ada_Pass_By_Reference` only "
3407 & "allowed for types", Arg2);
3410 if Is_By_Copy_Type (E) then
3412 ("convention `Ada_Pass_By_Reference` not allowed for "
3413 & "by-copy type", Arg1);
3417 -- Go to renamed subprogram if present, since convention applies to
3418 -- the actual renamed entity, not to the renaming entity. If the
3419 -- subprogram is inherited, go to parent subprogram.
3421 if Is_Subprogram (E)
3422 and then Present (Alias (E))
3424 if Nkind (Parent (Declaration_Node (E))) =
3425 N_Subprogram_Renaming_Declaration
3427 if Scope (E) /= Scope (Alias (E)) then
3429 ("cannot apply pragma% to non-local entity&#", E);
3434 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3435 N_Private_Extension_Declaration)
3436 and then Scope (E) = Scope (Alias (E))
3440 -- Return the parent subprogram the entity was inherited from
3446 -- Check that we are not applying this to a specless body
3448 if Is_Subprogram (E)
3449 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3452 ("pragma% requires separate spec and must come before body");
3455 -- Check that we are not applying this to a named constant
3457 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3458 Error_Msg_Name_1 := Pname;
3460 ("cannot apply pragma% to named constant!",
3461 Get_Pragma_Arg (Arg2));
3463 ("\supply appropriate type for&!", Arg2);
3466 if Ekind (E) = E_Enumeration_Literal then
3467 Error_Pragma ("enumeration literal not allowed for pragma%");
3470 -- Check for rep item appearing too early or too late
3472 if Etype (E) = Any_Type
3473 or else Rep_Item_Too_Early (E, N)
3477 elsif Present (Underlying_Type (E)) then
3478 E := Underlying_Type (E);
3481 if Rep_Item_Too_Late (E, N) then
3485 if Has_Convention_Pragma (E) then
3486 Diagnose_Multiple_Pragmas (E);
3488 elsif Convention (E) = Convention_Protected
3489 or else Ekind (Scope (E)) = E_Protected_Type
3492 ("a protected operation cannot be given a different convention",
3496 -- For Intrinsic, a subprogram is required
3498 if C = Convention_Intrinsic
3499 and then not Is_Subprogram (E)
3500 and then not Is_Generic_Subprogram (E)
3503 ("second argument of pragma% must be a subprogram", Arg2);
3508 if C = Convention_Stdcall then
3510 -- A dispatching call is not allowed. A dispatching subprogram
3511 -- cannot be used to interface to the Win32 API, so in fact this
3512 -- check does not impose any effective restriction.
3514 if Is_Dispatching_Operation (E) then
3517 ("dispatching subprograms cannot use Stdcall convention");
3519 -- Subprogram is allowed, but not a generic subprogram, and not a
3520 -- dispatching operation.
3522 elsif not Is_Subprogram (E)
3523 and then not Is_Generic_Subprogram (E)
3527 and then Ekind (E) /= E_Variable
3529 -- An access to subprogram is also allowed
3533 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3536 ("second argument of pragma% must be subprogram (type)",
3541 if not Is_Subprogram (E)
3542 and then not Is_Generic_Subprogram (E)
3544 Set_Convention_From_Pragma (E);
3547 Check_First_Subtype (Arg2);
3548 Set_Convention_From_Pragma (Base_Type (E));
3550 -- For subprograms, we must set the convention on the
3551 -- internally generated directly designated type as well.
3553 if Ekind (E) = E_Access_Subprogram_Type then
3554 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3558 -- For the subprogram case, set proper convention for all homonyms
3559 -- in same scope and the same declarative part, i.e. the same
3560 -- compilation unit.
3563 Comp_Unit := Get_Source_Unit (E);
3564 Set_Convention_From_Pragma (E);
3566 -- Treat a pragma Import as an implicit body, for GPS use
3568 if Prag_Id = Pragma_Import then
3569 Generate_Reference (E, Id, 'b');
3572 -- Loop through the homonyms of the pragma argument's entity
3577 exit when No (E1) or else Scope (E1) /= Current_Scope;
3579 -- Do not set the pragma on inherited operations or on formal
3582 if Comes_From_Source (E1)
3583 and then Comp_Unit = Get_Source_Unit (E1)
3584 and then not Is_Formal_Subprogram (E1)
3585 and then Nkind (Original_Node (Parent (E1))) /=
3586 N_Full_Type_Declaration
3588 if Present (Alias (E1))
3589 and then Scope (E1) /= Scope (Alias (E1))
3592 ("cannot apply pragma% to non-local entity& declared#",
3596 Set_Convention_From_Pragma (E1);
3598 if Prag_Id = Pragma_Import then
3599 Generate_Reference (E1, Id, 'b');
3603 -- For aspect case, do NOT apply to homonyms
3605 exit when From_Aspect_Specification (N);
3608 end Process_Convention;
3610 ----------------------------------------
3611 -- Process_Disable_Enable_Atomic_Sync --
3612 ----------------------------------------
3614 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3617 Check_No_Identifiers;
3618 Check_At_Most_N_Arguments (1);
3620 -- Modeled internally as
3621 -- pragma Unsuppress (Atomic_Synchronization [,Entity])
3625 Pragma_Identifier =>
3626 Make_Identifier (Loc, Nam),
3627 Pragma_Argument_Associations => New_List (
3628 Make_Pragma_Argument_Association (Loc,
3630 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3632 if Present (Arg1) then
3633 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3637 end Process_Disable_Enable_Atomic_Sync;
3639 -----------------------------------------------------
3640 -- Process_Extended_Import_Export_Exception_Pragma --
3641 -----------------------------------------------------
3643 procedure Process_Extended_Import_Export_Exception_Pragma
3644 (Arg_Internal : Node_Id;
3645 Arg_External : Node_Id;
3653 if not OpenVMS_On_Target then
3655 ("?pragma% ignored (applies only to Open'V'M'S)");
3658 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3659 Def_Id := Entity (Arg_Internal);
3661 if Ekind (Def_Id) /= E_Exception then
3663 ("pragma% must refer to declared exception", Arg_Internal);
3666 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3668 if Present (Arg_Form) then
3669 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3672 if Present (Arg_Form)
3673 and then Chars (Arg_Form) = Name_Ada
3677 Set_Is_VMS_Exception (Def_Id);
3678 Set_Exception_Code (Def_Id, No_Uint);
3681 if Present (Arg_Code) then
3682 if not Is_VMS_Exception (Def_Id) then
3684 ("Code option for pragma% not allowed for Ada case",
3688 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3689 Code_Val := Expr_Value (Arg_Code);
3691 if not UI_Is_In_Int_Range (Code_Val) then
3693 ("Code option for pragma% must be in 32-bit range",
3697 Set_Exception_Code (Def_Id, Code_Val);
3700 end Process_Extended_Import_Export_Exception_Pragma;
3702 -------------------------------------------------
3703 -- Process_Extended_Import_Export_Internal_Arg --
3704 -------------------------------------------------
3706 procedure Process_Extended_Import_Export_Internal_Arg
3707 (Arg_Internal : Node_Id := Empty)
3710 if No (Arg_Internal) then
3711 Error_Pragma ("Internal parameter required for pragma%");
3714 if Nkind (Arg_Internal) = N_Identifier then
3717 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3718 and then (Prag_Id = Pragma_Import_Function
3720 Prag_Id = Pragma_Export_Function)
3726 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3729 Check_Arg_Is_Local_Name (Arg_Internal);
3730 end Process_Extended_Import_Export_Internal_Arg;
3732 --------------------------------------------------
3733 -- Process_Extended_Import_Export_Object_Pragma --
3734 --------------------------------------------------
3736 procedure Process_Extended_Import_Export_Object_Pragma
3737 (Arg_Internal : Node_Id;
3738 Arg_External : Node_Id;
3744 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3745 Def_Id := Entity (Arg_Internal);
3747 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3749 ("pragma% must designate an object", Arg_Internal);
3752 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3754 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3757 ("previous Common/Psect_Object applies, pragma % not permitted",
3761 if Rep_Item_Too_Late (Def_Id, N) then
3765 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3767 if Present (Arg_Size) then
3768 Check_Arg_Is_External_Name (Arg_Size);
3771 -- Export_Object case
3773 if Prag_Id = Pragma_Export_Object then
3774 if not Is_Library_Level_Entity (Def_Id) then
3776 ("argument for pragma% must be library level entity",
3780 if Ekind (Current_Scope) = E_Generic_Package then
3781 Error_Pragma ("pragma& cannot appear in a generic unit");
3784 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3786 ("exported object must have compile time known size",
3790 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3791 Error_Msg_N ("?duplicate Export_Object pragma", N);
3793 Set_Exported (Def_Id, Arg_Internal);
3796 -- Import_Object case
3799 if Is_Concurrent_Type (Etype (Def_Id)) then
3801 ("cannot use pragma% for task/protected object",
3805 if Ekind (Def_Id) = E_Constant then
3807 ("cannot import a constant", Arg_Internal);
3810 if Warn_On_Export_Import
3811 and then Has_Discriminants (Etype (Def_Id))
3814 ("imported value must be initialized?", Arg_Internal);
3817 if Warn_On_Export_Import
3818 and then Is_Access_Type (Etype (Def_Id))
3821 ("cannot import object of an access type?", Arg_Internal);
3824 if Warn_On_Export_Import
3825 and then Is_Imported (Def_Id)
3828 ("?duplicate Import_Object pragma", N);
3830 -- Check for explicit initialization present. Note that an
3831 -- initialization generated by the code generator, e.g. for an
3832 -- access type, does not count here.
3834 elsif Present (Expression (Parent (Def_Id)))
3837 (Original_Node (Expression (Parent (Def_Id))))
3839 Error_Msg_Sloc := Sloc (Def_Id);
3841 ("imported entities cannot be initialized (RM B.1(24))",
3842 "\no initialization allowed for & declared#", Arg1);
3844 Set_Imported (Def_Id);
3845 Note_Possible_Modification (Arg_Internal, Sure => False);
3848 end Process_Extended_Import_Export_Object_Pragma;
3850 ------------------------------------------------------
3851 -- Process_Extended_Import_Export_Subprogram_Pragma --
3852 ------------------------------------------------------
3854 procedure Process_Extended_Import_Export_Subprogram_Pragma
3855 (Arg_Internal : Node_Id;
3856 Arg_External : Node_Id;
3857 Arg_Parameter_Types : Node_Id;
3858 Arg_Result_Type : Node_Id := Empty;
3859 Arg_Mechanism : Node_Id;
3860 Arg_Result_Mechanism : Node_Id := Empty;
3861 Arg_First_Optional_Parameter : Node_Id := Empty)
3867 Ambiguous : Boolean;
3871 function Same_Base_Type
3873 Formal : Entity_Id) return Boolean;
3874 -- Determines if Ptype references the type of Formal. Note that only
3875 -- the base types need to match according to the spec. Ptype here is
3876 -- the argument from the pragma, which is either a type name, or an
3877 -- access attribute.
3879 --------------------
3880 -- Same_Base_Type --
3881 --------------------
3883 function Same_Base_Type
3885 Formal : Entity_Id) return Boolean
3887 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3891 -- Case where pragma argument is typ'Access
3893 if Nkind (Ptype) = N_Attribute_Reference
3894 and then Attribute_Name (Ptype) = Name_Access
3896 Pref := Prefix (Ptype);
3899 if not Is_Entity_Name (Pref)
3900 or else Entity (Pref) = Any_Type
3905 -- We have a match if the corresponding argument is of an
3906 -- anonymous access type, and its designated type matches the
3907 -- type of the prefix of the access attribute
3909 return Ekind (Ftyp) = E_Anonymous_Access_Type
3910 and then Base_Type (Entity (Pref)) =
3911 Base_Type (Etype (Designated_Type (Ftyp)));
3913 -- Case where pragma argument is a type name
3918 if not Is_Entity_Name (Ptype)
3919 or else Entity (Ptype) = Any_Type
3924 -- We have a match if the corresponding argument is of the type
3925 -- given in the pragma (comparing base types)
3927 return Base_Type (Entity (Ptype)) = Ftyp;
3931 -- Start of processing for
3932 -- Process_Extended_Import_Export_Subprogram_Pragma
3935 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3939 -- Loop through homonyms (overloadings) of the entity
3941 Hom_Id := Entity (Arg_Internal);
3942 while Present (Hom_Id) loop
3943 Def_Id := Get_Base_Subprogram (Hom_Id);
3945 -- We need a subprogram in the current scope
3947 if not Is_Subprogram (Def_Id)
3948 or else Scope (Def_Id) /= Current_Scope
3955 -- Pragma cannot apply to subprogram body
3957 if Is_Subprogram (Def_Id)
3958 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3962 ("pragma% requires separate spec"
3963 & " and must come before body");
3966 -- Test result type if given, note that the result type
3967 -- parameter can only be present for the function cases.
3969 if Present (Arg_Result_Type)
3970 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3974 elsif Etype (Def_Id) /= Standard_Void_Type
3976 (Pname = Name_Export_Procedure
3978 Pname = Name_Import_Procedure)
3982 -- Test parameter types if given. Note that this parameter
3983 -- has not been analyzed (and must not be, since it is
3984 -- semantic nonsense), so we get it as the parser left it.
3986 elsif Present (Arg_Parameter_Types) then
3987 Check_Matching_Types : declare
3992 Formal := First_Formal (Def_Id);
3994 if Nkind (Arg_Parameter_Types) = N_Null then
3995 if Present (Formal) then
3999 -- A list of one type, e.g. (List) is parsed as
4000 -- a parenthesized expression.
4002 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4003 and then Paren_Count (Arg_Parameter_Types) = 1
4006 or else Present (Next_Formal (Formal))
4011 Same_Base_Type (Arg_Parameter_Types, Formal);
4014 -- A list of more than one type is parsed as a aggregate
4016 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4017 and then Paren_Count (Arg_Parameter_Types) = 0
4019 Ptype := First (Expressions (Arg_Parameter_Types));
4020 while Present (Ptype) or else Present (Formal) loop
4023 or else not Same_Base_Type (Ptype, Formal)
4028 Next_Formal (Formal);
4033 -- Anything else is of the wrong form
4037 ("wrong form for Parameter_Types parameter",
4038 Arg_Parameter_Types);
4040 end Check_Matching_Types;
4043 -- Match is now False if the entry we found did not match
4044 -- either a supplied Parameter_Types or Result_Types argument
4050 -- Ambiguous case, the flag Ambiguous shows if we already
4051 -- detected this and output the initial messages.
4054 if not Ambiguous then
4056 Error_Msg_Name_1 := Pname;
4058 ("pragma% does not uniquely identify subprogram!",
4060 Error_Msg_Sloc := Sloc (Ent);
4061 Error_Msg_N ("matching subprogram #!", N);
4065 Error_Msg_Sloc := Sloc (Def_Id);
4066 Error_Msg_N ("matching subprogram #!", N);
4071 Hom_Id := Homonym (Hom_Id);
4074 -- See if we found an entry
4077 if not Ambiguous then
4078 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4080 ("pragma% cannot be given for generic subprogram");
4083 ("pragma% does not identify local subprogram");
4090 -- Import pragmas must be for imported entities
4092 if Prag_Id = Pragma_Import_Function
4094 Prag_Id = Pragma_Import_Procedure
4096 Prag_Id = Pragma_Import_Valued_Procedure
4098 if not Is_Imported (Ent) then
4100 ("pragma Import or Interface must precede pragma%");
4103 -- Here we have the Export case which can set the entity as exported
4105 -- But does not do so if the specified external name is null, since
4106 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4107 -- compatible) to request no external name.
4109 elsif Nkind (Arg_External) = N_String_Literal
4110 and then String_Length (Strval (Arg_External)) = 0
4114 -- In all other cases, set entity as exported
4117 Set_Exported (Ent, Arg_Internal);
4120 -- Special processing for Valued_Procedure cases
4122 if Prag_Id = Pragma_Import_Valued_Procedure
4124 Prag_Id = Pragma_Export_Valued_Procedure
4126 Formal := First_Formal (Ent);
4129 Error_Pragma ("at least one parameter required for pragma%");
4131 elsif Ekind (Formal) /= E_Out_Parameter then
4132 Error_Pragma ("first parameter must have mode out for pragma%");
4135 Set_Is_Valued_Procedure (Ent);
4139 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4141 -- Process Result_Mechanism argument if present. We have already
4142 -- checked that this is only allowed for the function case.
4144 if Present (Arg_Result_Mechanism) then
4145 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4148 -- Process Mechanism parameter if present. Note that this parameter
4149 -- is not analyzed, and must not be analyzed since it is semantic
4150 -- nonsense, so we get it in exactly as the parser left it.
4152 if Present (Arg_Mechanism) then
4160 -- A single mechanism association without a formal parameter
4161 -- name is parsed as a parenthesized expression. All other
4162 -- cases are parsed as aggregates, so we rewrite the single
4163 -- parameter case as an aggregate for consistency.
4165 if Nkind (Arg_Mechanism) /= N_Aggregate
4166 and then Paren_Count (Arg_Mechanism) = 1
4168 Rewrite (Arg_Mechanism,
4169 Make_Aggregate (Sloc (Arg_Mechanism),
4170 Expressions => New_List (
4171 Relocate_Node (Arg_Mechanism))));
4174 -- Case of only mechanism name given, applies to all formals
4176 if Nkind (Arg_Mechanism) /= N_Aggregate then
4177 Formal := First_Formal (Ent);
4178 while Present (Formal) loop
4179 Set_Mechanism_Value (Formal, Arg_Mechanism);
4180 Next_Formal (Formal);
4183 -- Case of list of mechanism associations given
4186 if Null_Record_Present (Arg_Mechanism) then
4188 ("inappropriate form for Mechanism parameter",
4192 -- Deal with positional ones first
4194 Formal := First_Formal (Ent);
4196 if Present (Expressions (Arg_Mechanism)) then
4197 Mname := First (Expressions (Arg_Mechanism));
4198 while Present (Mname) loop
4201 ("too many mechanism associations", Mname);
4204 Set_Mechanism_Value (Formal, Mname);
4205 Next_Formal (Formal);
4210 -- Deal with named entries
4212 if Present (Component_Associations (Arg_Mechanism)) then
4213 Massoc := First (Component_Associations (Arg_Mechanism));
4214 while Present (Massoc) loop
4215 Choice := First (Choices (Massoc));
4217 if Nkind (Choice) /= N_Identifier
4218 or else Present (Next (Choice))
4221 ("incorrect form for mechanism association",
4225 Formal := First_Formal (Ent);
4229 ("parameter name & not present", Choice);
4232 if Chars (Choice) = Chars (Formal) then
4234 (Formal, Expression (Massoc));
4236 -- Set entity on identifier (needed by ASIS)
4238 Set_Entity (Choice, Formal);
4243 Next_Formal (Formal);
4253 -- Process First_Optional_Parameter argument if present. We have
4254 -- already checked that this is only allowed for the Import case.
4256 if Present (Arg_First_Optional_Parameter) then
4257 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4259 ("first optional parameter must be formal parameter name",
4260 Arg_First_Optional_Parameter);
4263 Formal := First_Formal (Ent);
4267 ("specified formal parameter& not found",
4268 Arg_First_Optional_Parameter);
4271 exit when Chars (Formal) =
4272 Chars (Arg_First_Optional_Parameter);
4274 Next_Formal (Formal);
4277 Set_First_Optional_Parameter (Ent, Formal);
4279 -- Check specified and all remaining formals have right form
4281 while Present (Formal) loop
4282 if Ekind (Formal) /= E_In_Parameter then
4284 ("optional formal& is not of mode in!",
4285 Arg_First_Optional_Parameter, Formal);
4288 Dval := Default_Value (Formal);
4292 ("optional formal& does not have default value!",
4293 Arg_First_Optional_Parameter, Formal);
4295 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4300 ("default value for optional formal& is non-static!",
4301 Arg_First_Optional_Parameter, Formal);
4305 Set_Is_Optional_Parameter (Formal);
4306 Next_Formal (Formal);
4309 end Process_Extended_Import_Export_Subprogram_Pragma;
4311 --------------------------
4312 -- Process_Generic_List --
4313 --------------------------
4315 procedure Process_Generic_List is
4320 Check_No_Identifiers;
4321 Check_At_Least_N_Arguments (1);
4324 while Present (Arg) loop
4325 Exp := Get_Pragma_Arg (Arg);
4328 if not Is_Entity_Name (Exp)
4330 (not Is_Generic_Instance (Entity (Exp))
4332 not Is_Generic_Unit (Entity (Exp)))
4335 ("pragma% argument must be name of generic unit/instance",
4341 end Process_Generic_List;
4343 ------------------------------------
4344 -- Process_Import_Predefined_Type --
4345 ------------------------------------
4347 procedure Process_Import_Predefined_Type is
4348 Loc : constant Source_Ptr := Sloc (N);
4350 Ftyp : Node_Id := Empty;
4356 String_To_Name_Buffer (Strval (Expression (Arg3)));
4359 Elmt := First_Elmt (Predefined_Float_Types);
4360 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4364 Ftyp := Node (Elmt);
4366 if Present (Ftyp) then
4368 -- Don't build a derived type declaration, because predefined C
4369 -- types have no declaration anywhere, so cannot really be named.
4370 -- Instead build a full type declaration, starting with an
4371 -- appropriate type definition is built
4373 if Is_Floating_Point_Type (Ftyp) then
4374 Def := Make_Floating_Point_Definition (Loc,
4375 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4376 Make_Real_Range_Specification (Loc,
4377 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4378 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4380 -- Should never have a predefined type we cannot handle
4383 raise Program_Error;
4386 -- Build and insert a Full_Type_Declaration, which will be
4387 -- analyzed as soon as this list entry has been analyzed.
4389 Decl := Make_Full_Type_Declaration (Loc,
4390 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4391 Type_Definition => Def);
4393 Insert_After (N, Decl);
4394 Mark_Rewrite_Insertion (Decl);
4397 Error_Pragma_Arg ("no matching type found for pragma%",
4400 end Process_Import_Predefined_Type;
4402 ---------------------------------
4403 -- Process_Import_Or_Interface --
4404 ---------------------------------
4406 procedure Process_Import_Or_Interface is
4412 Process_Convention (C, Def_Id);
4413 Kill_Size_Check_Code (Def_Id);
4414 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4416 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4418 -- We do not permit Import to apply to a renaming declaration
4420 if Present (Renamed_Object (Def_Id)) then
4422 ("pragma% not allowed for object renaming", Arg2);
4424 -- User initialization is not allowed for imported object, but
4425 -- the object declaration may contain a default initialization,
4426 -- that will be discarded. Note that an explicit initialization
4427 -- only counts if it comes from source, otherwise it is simply
4428 -- the code generator making an implicit initialization explicit.
4430 elsif Present (Expression (Parent (Def_Id)))
4431 and then Comes_From_Source (Expression (Parent (Def_Id)))
4433 Error_Msg_Sloc := Sloc (Def_Id);
4435 ("no initialization allowed for declaration of& #",
4436 "\imported entities cannot be initialized (RM B.1(24))",
4440 Set_Imported (Def_Id);
4441 Process_Interface_Name (Def_Id, Arg3, Arg4);
4443 -- Note that we do not set Is_Public here. That's because we
4444 -- only want to set it if there is no address clause, and we
4445 -- don't know that yet, so we delay that processing till
4448 -- pragma Import completes deferred constants
4450 if Ekind (Def_Id) = E_Constant then
4451 Set_Has_Completion (Def_Id);
4454 -- It is not possible to import a constant of an unconstrained
4455 -- array type (e.g. string) because there is no simple way to
4456 -- write a meaningful subtype for it.
4458 if Is_Array_Type (Etype (Def_Id))
4459 and then not Is_Constrained (Etype (Def_Id))
4462 ("imported constant& must have a constrained subtype",
4467 elsif Is_Subprogram (Def_Id)
4468 or else Is_Generic_Subprogram (Def_Id)
4470 -- If the name is overloaded, pragma applies to all of the denoted
4471 -- entities in the same declarative part.
4474 while Present (Hom_Id) loop
4475 Def_Id := Get_Base_Subprogram (Hom_Id);
4477 -- Ignore inherited subprograms because the pragma will apply
4478 -- to the parent operation, which is the one called.
4480 if Is_Overloadable (Def_Id)
4481 and then Present (Alias (Def_Id))
4485 -- If it is not a subprogram, it must be in an outer scope and
4486 -- pragma does not apply.
4488 elsif not Is_Subprogram (Def_Id)
4489 and then not Is_Generic_Subprogram (Def_Id)
4493 -- The pragma does not apply to primitives of interfaces
4495 elsif Is_Dispatching_Operation (Def_Id)
4496 and then Present (Find_Dispatching_Type (Def_Id))
4497 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4501 -- Verify that the homonym is in the same declarative part (not
4502 -- just the same scope).
4504 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4505 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4510 Set_Imported (Def_Id);
4512 -- Reject an Import applied to an abstract subprogram
4514 if Is_Subprogram (Def_Id)
4515 and then Is_Abstract_Subprogram (Def_Id)
4517 Error_Msg_Sloc := Sloc (Def_Id);
4519 ("cannot import abstract subprogram& declared#",
4523 -- Special processing for Convention_Intrinsic
4525 if C = Convention_Intrinsic then
4527 -- Link_Name argument not allowed for intrinsic
4531 Set_Is_Intrinsic_Subprogram (Def_Id);
4533 -- If no external name is present, then check that this
4534 -- is a valid intrinsic subprogram. If an external name
4535 -- is present, then this is handled by the back end.
4538 Check_Intrinsic_Subprogram
4539 (Def_Id, Get_Pragma_Arg (Arg2));
4543 -- All interfaced procedures need an external symbol created
4544 -- for them since they are always referenced from another
4547 Set_Is_Public (Def_Id);
4549 -- Verify that the subprogram does not have a completion
4550 -- through a renaming declaration. For other completions the
4551 -- pragma appears as a too late representation.
4554 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4558 and then Nkind (Decl) = N_Subprogram_Declaration
4559 and then Present (Corresponding_Body (Decl))
4560 and then Nkind (Unit_Declaration_Node
4561 (Corresponding_Body (Decl))) =
4562 N_Subprogram_Renaming_Declaration
4564 Error_Msg_Sloc := Sloc (Def_Id);
4566 ("cannot import&, renaming already provided for " &
4567 "declaration #", N, Def_Id);
4571 Set_Has_Completion (Def_Id);
4572 Process_Interface_Name (Def_Id, Arg3, Arg4);
4575 if Is_Compilation_Unit (Hom_Id) then
4577 -- Its possible homonyms are not affected by the pragma.
4578 -- Such homonyms might be present in the context of other
4579 -- units being compiled.
4584 Hom_Id := Homonym (Hom_Id);
4588 -- When the convention is Java or CIL, we also allow Import to be
4589 -- given for packages, generic packages, exceptions, record
4590 -- components, and access to subprograms.
4592 elsif (C = Convention_Java or else C = Convention_CIL)
4594 (Is_Package_Or_Generic_Package (Def_Id)
4595 or else Ekind (Def_Id) = E_Exception
4596 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4597 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4599 Set_Imported (Def_Id);
4600 Set_Is_Public (Def_Id);
4601 Process_Interface_Name (Def_Id, Arg3, Arg4);
4603 -- Import a CPP class
4605 elsif Is_Record_Type (Def_Id)
4606 and then C = Convention_CPP
4608 -- Types treated as CPP classes must be declared limited (note:
4609 -- this used to be a warning but there is no real benefit to it
4610 -- since we did effectively intend to treat the type as limited
4613 if not Is_Limited_Type (Def_Id) then
4615 ("imported 'C'P'P type must be limited",
4616 Get_Pragma_Arg (Arg2));
4619 Set_Is_CPP_Class (Def_Id);
4621 -- Imported CPP types must not have discriminants (because C++
4622 -- classes do not have discriminants).
4624 if Has_Discriminants (Def_Id) then
4626 ("imported 'C'P'P type cannot have discriminants",
4627 First (Discriminant_Specifications
4628 (Declaration_Node (Def_Id))));
4631 -- Components of imported CPP types must not have default
4632 -- expressions because the constructor (if any) is on the
4636 Tdef : constant Node_Id :=
4637 Type_Definition (Declaration_Node (Def_Id));
4642 if Nkind (Tdef) = N_Record_Definition then
4643 Clist := Component_List (Tdef);
4646 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4647 Clist := Component_List (Record_Extension_Part (Tdef));
4650 if Present (Clist) then
4651 Comp := First (Component_Items (Clist));
4652 while Present (Comp) loop
4653 if Present (Expression (Comp)) then
4655 ("component of imported 'C'P'P type cannot have" &
4656 " default expression", Expression (Comp));
4664 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4666 Check_Arg_Count (3);
4667 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4669 Process_Import_Predefined_Type;
4673 ("second argument of pragma% must be object, subprogram" &
4674 " or incomplete type",
4678 -- If this pragma applies to a compilation unit, then the unit, which
4679 -- is a subprogram, does not require (or allow) a body. We also do
4680 -- not need to elaborate imported procedures.
4682 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4684 Cunit : constant Node_Id := Parent (Parent (N));
4686 Set_Body_Required (Cunit, False);
4689 end Process_Import_Or_Interface;
4691 --------------------
4692 -- Process_Inline --
4693 --------------------
4695 procedure Process_Inline (Active : Boolean) is
4702 Effective : Boolean := False;
4703 -- Set True if inline has some effect, i.e. if there is at least one
4704 -- subprogram set as inlined as a result of the use of the pragma.
4706 procedure Make_Inline (Subp : Entity_Id);
4707 -- Subp is the defining unit name of the subprogram declaration. Set
4708 -- the flag, as well as the flag in the corresponding body, if there
4711 procedure Set_Inline_Flags (Subp : Entity_Id);
4712 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4713 -- Has_Pragma_Inline_Always for the Inline_Always case.
4715 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4716 -- Returns True if it can be determined at this stage that inlining
4717 -- is not possible, for example if the body is available and contains
4718 -- exception handlers, we prevent inlining, since otherwise we can
4719 -- get undefined symbols at link time. This function also emits a
4720 -- warning if front-end inlining is enabled and the pragma appears
4723 -- ??? is business with link symbols still valid, or does it relate
4724 -- to front end ZCX which is being phased out ???
4726 ---------------------------
4727 -- Inlining_Not_Possible --
4728 ---------------------------
4730 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4731 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4735 if Nkind (Decl) = N_Subprogram_Body then
4736 Stats := Handled_Statement_Sequence (Decl);
4737 return Present (Exception_Handlers (Stats))
4738 or else Present (At_End_Proc (Stats));
4740 elsif Nkind (Decl) = N_Subprogram_Declaration
4741 and then Present (Corresponding_Body (Decl))
4743 if Front_End_Inlining
4744 and then Analyzed (Corresponding_Body (Decl))
4746 Error_Msg_N ("pragma appears too late, ignored?", N);
4749 -- If the subprogram is a renaming as body, the body is just a
4750 -- call to the renamed subprogram, and inlining is trivially
4754 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4755 N_Subprogram_Renaming_Declaration
4761 Handled_Statement_Sequence
4762 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4765 Present (Exception_Handlers (Stats))
4766 or else Present (At_End_Proc (Stats));
4770 -- If body is not available, assume the best, the check is
4771 -- performed again when compiling enclosing package bodies.
4775 end Inlining_Not_Possible;
4781 procedure Make_Inline (Subp : Entity_Id) is
4782 Kind : constant Entity_Kind := Ekind (Subp);
4783 Inner_Subp : Entity_Id := Subp;
4786 -- Ignore if bad type, avoid cascaded error
4788 if Etype (Subp) = Any_Type then
4792 -- Ignore if all inlining is suppressed
4794 elsif Suppress_All_Inlining then
4798 -- If inlining is not possible, for now do not treat as an error
4800 elsif Inlining_Not_Possible (Subp) then
4804 -- Here we have a candidate for inlining, but we must exclude
4805 -- derived operations. Otherwise we would end up trying to inline
4806 -- a phantom declaration, and the result would be to drag in a
4807 -- body which has no direct inlining associated with it. That
4808 -- would not only be inefficient but would also result in the
4809 -- backend doing cross-unit inlining in cases where it was
4810 -- definitely inappropriate to do so.
4812 -- However, a simple Comes_From_Source test is insufficient, since
4813 -- we do want to allow inlining of generic instances which also do
4814 -- not come from source. We also need to recognize specs generated
4815 -- by the front-end for bodies that carry the pragma. Finally,
4816 -- predefined operators do not come from source but are not
4817 -- inlineable either.
4819 elsif Is_Generic_Instance (Subp)
4820 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4824 elsif not Comes_From_Source (Subp)
4825 and then Scope (Subp) /= Standard_Standard
4831 -- The referenced entity must either be the enclosing entity, or
4832 -- an entity declared within the current open scope.
4834 if Present (Scope (Subp))
4835 and then Scope (Subp) /= Current_Scope
4836 and then Subp /= Current_Scope
4839 ("argument of% must be entity in current scope", Assoc);
4843 -- Processing for procedure, operator or function. If subprogram
4844 -- is aliased (as for an instance) indicate that the renamed
4845 -- entity (if declared in the same unit) is inlined.
4847 if Is_Subprogram (Subp) then
4848 Inner_Subp := Ultimate_Alias (Inner_Subp);
4850 if In_Same_Source_Unit (Subp, Inner_Subp) then
4851 Set_Inline_Flags (Inner_Subp);
4853 Decl := Parent (Parent (Inner_Subp));
4855 if Nkind (Decl) = N_Subprogram_Declaration
4856 and then Present (Corresponding_Body (Decl))
4858 Set_Inline_Flags (Corresponding_Body (Decl));
4860 elsif Is_Generic_Instance (Subp) then
4862 -- Indicate that the body needs to be created for
4863 -- inlining subsequent calls. The instantiation node
4864 -- follows the declaration of the wrapper package
4867 if Scope (Subp) /= Standard_Standard
4869 Need_Subprogram_Instance_Body
4870 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4876 -- Inline is a program unit pragma (RM 10.1.5) and cannot
4877 -- appear in a formal part to apply to a formal subprogram.
4878 -- Do not apply check within an instance or a formal package
4879 -- the test will have been applied to the original generic.
4881 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4882 and then List_Containing (Decl) = List_Containing (N)
4883 and then not In_Instance
4886 ("Inline cannot apply to a formal subprogram", N);
4892 -- For a generic subprogram set flag as well, for use at the point
4893 -- of instantiation, to determine whether the body should be
4896 elsif Is_Generic_Subprogram (Subp) then
4897 Set_Inline_Flags (Subp);
4900 -- Literals are by definition inlined
4902 elsif Kind = E_Enumeration_Literal then
4905 -- Anything else is an error
4909 ("expect subprogram name for pragma%", Assoc);
4913 ----------------------
4914 -- Set_Inline_Flags --
4915 ----------------------
4917 procedure Set_Inline_Flags (Subp : Entity_Id) is
4920 Set_Is_Inlined (Subp);
4923 if not Has_Pragma_Inline (Subp) then
4924 Set_Has_Pragma_Inline (Subp);
4928 if Prag_Id = Pragma_Inline_Always then
4929 Set_Has_Pragma_Inline_Always (Subp);
4931 end Set_Inline_Flags;
4933 -- Start of processing for Process_Inline
4936 Check_No_Identifiers;
4937 Check_At_Least_N_Arguments (1);
4940 Inline_Processing_Required := True;
4944 while Present (Assoc) loop
4945 Subp_Id := Get_Pragma_Arg (Assoc);
4949 if Is_Entity_Name (Subp_Id) then
4950 Subp := Entity (Subp_Id);
4952 if Subp = Any_Id then
4954 -- If previous error, avoid cascaded errors
4962 -- For the pragma case, climb homonym chain. This is
4963 -- what implements allowing the pragma in the renaming
4964 -- case, with the result applying to the ancestors, and
4965 -- also allows Inline to apply to all previous homonyms.
4967 if not From_Aspect_Specification (N) then
4968 while Present (Homonym (Subp))
4969 and then Scope (Homonym (Subp)) = Current_Scope
4971 Make_Inline (Homonym (Subp));
4972 Subp := Homonym (Subp);
4980 ("inappropriate argument for pragma%", Assoc);
4983 and then Warn_On_Redundant_Constructs
4984 and then not Suppress_All_Inlining
4986 if Inlining_Not_Possible (Subp) then
4988 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4991 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4999 ----------------------------
5000 -- Process_Interface_Name --
5001 ----------------------------
5003 procedure Process_Interface_Name
5004 (Subprogram_Def : Entity_Id;
5010 String_Val : String_Id;
5012 procedure Check_Form_Of_Interface_Name
5014 Ext_Name_Case : Boolean);
5015 -- SN is a string literal node for an interface name. This routine
5016 -- performs some minimal checks that the name is reasonable. In
5017 -- particular that no spaces or other obviously incorrect characters
5018 -- appear. This is only a warning, since any characters are allowed.
5019 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5021 ----------------------------------
5022 -- Check_Form_Of_Interface_Name --
5023 ----------------------------------
5025 procedure Check_Form_Of_Interface_Name
5027 Ext_Name_Case : Boolean)
5029 S : constant String_Id := Strval (Expr_Value_S (SN));
5030 SL : constant Nat := String_Length (S);
5035 Error_Msg_N ("interface name cannot be null string", SN);
5038 for J in 1 .. SL loop
5039 C := Get_String_Char (S, J);
5041 -- Look for dubious character and issue unconditional warning.
5042 -- Definitely dubious if not in character range.
5044 if not In_Character_Range (C)
5046 -- For all cases except CLI target,
5047 -- commas, spaces and slashes are dubious (in CLI, we use
5048 -- commas and backslashes in external names to specify
5049 -- assembly version and public key, while slashes and spaces
5050 -- can be used in names to mark nested classes and
5053 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5054 and then (Get_Character (C) = ','
5056 Get_Character (C) = '\'))
5057 or else (VM_Target /= CLI_Target
5058 and then (Get_Character (C) = ' '
5060 Get_Character (C) = '/'))
5063 ("?interface name contains illegal character",
5064 Sloc (SN) + Source_Ptr (J));
5067 end Check_Form_Of_Interface_Name;
5069 -- Start of processing for Process_Interface_Name
5072 if No (Link_Arg) then
5073 if No (Ext_Arg) then
5074 if VM_Target = CLI_Target
5075 and then Ekind (Subprogram_Def) = E_Package
5076 and then Nkind (Parent (Subprogram_Def)) =
5077 N_Package_Specification
5078 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5083 (Generic_Parent (Parent (Subprogram_Def))));
5088 elsif Chars (Ext_Arg) = Name_Link_Name then
5090 Link_Nam := Expression (Ext_Arg);
5093 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5094 Ext_Nam := Expression (Ext_Arg);
5099 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5100 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5101 Ext_Nam := Expression (Ext_Arg);
5102 Link_Nam := Expression (Link_Arg);
5105 -- Check expressions for external name and link name are static
5107 if Present (Ext_Nam) then
5108 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5109 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5111 -- Verify that external name is not the name of a local entity,
5112 -- which would hide the imported one and could lead to run-time
5113 -- surprises. The problem can only arise for entities declared in
5114 -- a package body (otherwise the external name is fully qualified
5115 -- and will not conflict).
5123 if Prag_Id = Pragma_Import then
5124 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5126 E := Entity_Id (Get_Name_Table_Info (Nam));
5128 if Nam /= Chars (Subprogram_Def)
5129 and then Present (E)
5130 and then not Is_Overloadable (E)
5131 and then Is_Immediately_Visible (E)
5132 and then not Is_Imported (E)
5133 and then Ekind (Scope (E)) = E_Package
5136 while Present (Par) loop
5137 if Nkind (Par) = N_Package_Body then
5138 Error_Msg_Sloc := Sloc (E);
5140 ("imported entity is hidden by & declared#",
5145 Par := Parent (Par);
5152 if Present (Link_Nam) then
5153 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5154 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5157 -- If there is no link name, just set the external name
5159 if No (Link_Nam) then
5160 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5162 -- For the Link_Name case, the given literal is preceded by an
5163 -- asterisk, which indicates to GCC that the given name should be
5164 -- taken literally, and in particular that no prepending of
5165 -- underlines should occur, even in systems where this is the
5171 if VM_Target = No_VM then
5172 Store_String_Char (Get_Char_Code ('*'));
5175 String_Val := Strval (Expr_Value_S (Link_Nam));
5176 Store_String_Chars (String_Val);
5178 Make_String_Literal (Sloc (Link_Nam),
5179 Strval => End_String);
5182 -- Set the interface name. If the entity is a generic instance, use
5183 -- its alias, which is the callable entity.
5185 if Is_Generic_Instance (Subprogram_Def) then
5186 Set_Encoded_Interface_Name
5187 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5189 Set_Encoded_Interface_Name
5190 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5193 -- We allow duplicated export names in CIL/Java, as they are always
5194 -- enclosed in a namespace that differentiates them, and overloaded
5195 -- entities are supported by the VM.
5197 if Convention (Subprogram_Def) /= Convention_CIL
5199 Convention (Subprogram_Def) /= Convention_Java
5201 Check_Duplicated_Export_Name (Link_Nam);
5203 end Process_Interface_Name;
5205 -----------------------------------------
5206 -- Process_Interrupt_Or_Attach_Handler --
5207 -----------------------------------------
5209 procedure Process_Interrupt_Or_Attach_Handler is
5210 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5211 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5212 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5215 Set_Is_Interrupt_Handler (Handler_Proc);
5217 -- If the pragma is not associated with a handler procedure within a
5218 -- protected type, then it must be for a nonprotected procedure for
5219 -- the AAMP target, in which case we don't associate a representation
5220 -- item with the procedure's scope.
5222 if Ekind (Proc_Scope) = E_Protected_Type then
5223 if Prag_Id = Pragma_Interrupt_Handler
5225 Prag_Id = Pragma_Attach_Handler
5227 Record_Rep_Item (Proc_Scope, N);
5230 end Process_Interrupt_Or_Attach_Handler;
5232 --------------------------------------------------
5233 -- Process_Restrictions_Or_Restriction_Warnings --
5234 --------------------------------------------------
5236 -- Note: some of the simple identifier cases were handled in par-prag,
5237 -- but it is harmless (and more straightforward) to simply handle all
5238 -- cases here, even if it means we repeat a bit of work in some cases.
5240 procedure Process_Restrictions_Or_Restriction_Warnings
5244 R_Id : Restriction_Id;
5249 procedure Check_Unit_Name (N : Node_Id);
5250 -- Checks unit name parameter for No_Dependence. Returns if it has
5251 -- an appropriate form, otherwise raises pragma argument error.
5253 ---------------------
5254 -- Check_Unit_Name --
5255 ---------------------
5257 procedure Check_Unit_Name (N : Node_Id) is
5259 if Nkind (N) = N_Selected_Component then
5260 Check_Unit_Name (Prefix (N));
5261 Check_Unit_Name (Selector_Name (N));
5263 elsif Nkind (N) = N_Identifier then
5268 ("wrong form for unit name for No_Dependence", N);
5270 end Check_Unit_Name;
5272 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5275 -- Ignore all Restrictions pragma in CodePeer mode
5277 if CodePeer_Mode then
5281 Check_Ada_83_Warning;
5282 Check_At_Least_N_Arguments (1);
5283 Check_Valid_Configuration_Pragma;
5286 while Present (Arg) loop
5288 Expr := Get_Pragma_Arg (Arg);
5290 -- Case of no restriction identifier present
5292 if Id = No_Name then
5293 if Nkind (Expr) /= N_Identifier then
5295 ("invalid form for restriction", Arg);
5300 (Process_Restriction_Synonyms (Expr));
5302 if R_Id not in All_Boolean_Restrictions then
5303 Error_Msg_Name_1 := Pname;
5305 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5307 -- Check for possible misspelling
5309 for J in Restriction_Id loop
5311 Rnm : constant String := Restriction_Id'Image (J);
5314 Name_Buffer (1 .. Rnm'Length) := Rnm;
5315 Name_Len := Rnm'Length;
5316 Set_Casing (All_Lower_Case);
5318 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5320 (Identifier_Casing (Current_Source_File));
5321 Error_Msg_String (1 .. Rnm'Length) :=
5322 Name_Buffer (1 .. Name_Len);
5323 Error_Msg_Strlen := Rnm'Length;
5324 Error_Msg_N -- CODEFIX
5325 ("\possible misspelling of ""~""",
5326 Get_Pragma_Arg (Arg));
5335 if Implementation_Restriction (R_Id) then
5336 Check_Restriction (No_Implementation_Restrictions, Arg);
5339 -- Special processing for No_Elaboration_Code restriction
5341 if R_Id = No_Elaboration_Code then
5343 -- Restriction is only recognized within a configuration
5344 -- pragma file, or within a unit of the main extended
5345 -- program. Note: the test for Main_Unit is needed to
5346 -- properly include the case of configuration pragma files.
5348 if not (Current_Sem_Unit = Main_Unit
5349 or else In_Extended_Main_Source_Unit (N))
5353 -- Don't allow in a subunit unless already specified in
5356 elsif Nkind (Parent (N)) = N_Compilation_Unit
5357 and then Nkind (Unit (Parent (N))) = N_Subunit
5358 and then not Restriction_Active (No_Elaboration_Code)
5361 ("invalid specification of ""No_Elaboration_Code""",
5364 ("\restriction cannot be specified in a subunit", N);
5366 ("\unless also specified in body or spec", N);
5369 -- If we have a No_Elaboration_Code pragma that we
5370 -- accept, then it needs to be added to the configuration
5371 -- restrcition set so that we get proper application to
5372 -- other units in the main extended source as required.
5375 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
5379 -- If this is a warning, then set the warning unless we already
5380 -- have a real restriction active (we never want a warning to
5381 -- override a real restriction).
5384 if not Restriction_Active (R_Id) then
5385 Set_Restriction (R_Id, N);
5386 Restriction_Warnings (R_Id) := True;
5389 -- If real restriction case, then set it and make sure that the
5390 -- restriction warning flag is off, since a real restriction
5391 -- always overrides a warning.
5394 Set_Restriction (R_Id, N);
5395 Restriction_Warnings (R_Id) := False;
5398 -- Check for obsolescent restrictions in Ada 2005 mode
5401 and then Ada_Version >= Ada_2005
5402 and then (R_Id = No_Asynchronous_Control
5404 R_Id = No_Unchecked_Deallocation
5406 R_Id = No_Unchecked_Conversion)
5408 Check_Restriction (No_Obsolescent_Features, N);
5411 -- A very special case that must be processed here: pragma
5412 -- Restrictions (No_Exceptions) turns off all run-time
5413 -- checking. This is a bit dubious in terms of the formal
5414 -- language definition, but it is what is intended by RM
5415 -- H.4(12). Restriction_Warnings never affects generated code
5416 -- so this is done only in the real restriction case.
5418 -- Atomic_Synchronization is not a real check, so it is not
5419 -- affected by this processing).
5421 if R_Id = No_Exceptions and then not Warn then
5422 for J in Scope_Suppress'Range loop
5423 if J /= Atomic_Synchronization then
5424 Scope_Suppress (J) := True;
5429 -- Case of No_Dependence => unit-name. Note that the parser
5430 -- already made the necessary entry in the No_Dependence table.
5432 elsif Id = Name_No_Dependence then
5433 Check_Unit_Name (Expr);
5435 -- Case of No_Specification_Of_Aspect => Identifier.
5437 elsif Id = Name_No_Specification_Of_Aspect then
5442 if Nkind (Expr) /= N_Identifier then
5445 A_Id := Get_Aspect_Id (Chars (Expr));
5448 if A_Id = No_Aspect then
5449 Error_Pragma_Arg ("invalid restriction name", Arg);
5451 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5455 -- All other cases of restriction identifier present
5458 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5459 Analyze_And_Resolve (Expr, Any_Integer);
5461 if R_Id not in All_Parameter_Restrictions then
5463 ("invalid restriction parameter identifier", Arg);
5465 elsif not Is_OK_Static_Expression (Expr) then
5466 Flag_Non_Static_Expr
5467 ("value must be static expression!", Expr);
5470 elsif not Is_Integer_Type (Etype (Expr))
5471 or else Expr_Value (Expr) < 0
5474 ("value must be non-negative integer", Arg);
5477 -- Restriction pragma is active
5479 Val := Expr_Value (Expr);
5481 if not UI_Is_In_Int_Range (Val) then
5483 ("pragma ignored, value too large?", Arg);
5486 -- Warning case. If the real restriction is active, then we
5487 -- ignore the request, since warning never overrides a real
5488 -- restriction. Otherwise we set the proper warning. Note that
5489 -- this circuit sets the warning again if it is already set,
5490 -- which is what we want, since the constant may have changed.
5493 if not Restriction_Active (R_Id) then
5495 (R_Id, N, Integer (UI_To_Int (Val)));
5496 Restriction_Warnings (R_Id) := True;
5499 -- Real restriction case, set restriction and make sure warning
5500 -- flag is off since real restriction always overrides warning.
5503 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5504 Restriction_Warnings (R_Id) := False;
5510 end Process_Restrictions_Or_Restriction_Warnings;
5512 ---------------------------------
5513 -- Process_Suppress_Unsuppress --
5514 ---------------------------------
5516 -- Note: this procedure makes entries in the check suppress data
5517 -- structures managed by Sem. See spec of package Sem for full
5518 -- details on how we handle recording of check suppression.
5520 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5525 In_Package_Spec : constant Boolean :=
5526 Is_Package_Or_Generic_Package (Current_Scope)
5527 and then not In_Package_Body (Current_Scope);
5529 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5530 -- Used to suppress a single check on the given entity
5532 --------------------------------
5533 -- Suppress_Unsuppress_Echeck --
5534 --------------------------------
5536 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5538 -- Check for error of trying to set atomic synchronization for
5539 -- a non-atomic variable.
5541 if C = Atomic_Synchronization
5542 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5545 ("pragma & requires atomic type or variable",
5546 Pragma_Identifier (Original_Node (N)));
5549 Set_Checks_May_Be_Suppressed (E);
5551 if In_Package_Spec then
5552 Push_Global_Suppress_Stack_Entry
5555 Suppress => Suppress_Case);
5557 Push_Local_Suppress_Stack_Entry
5560 Suppress => Suppress_Case);
5563 -- If this is a first subtype, and the base type is distinct,
5564 -- then also set the suppress flags on the base type.
5566 if Is_First_Subtype (E)
5567 and then Etype (E) /= E
5569 Suppress_Unsuppress_Echeck (Etype (E), C);
5571 end Suppress_Unsuppress_Echeck;
5573 -- Start of processing for Process_Suppress_Unsuppress
5576 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5577 -- user code: we want to generate checks for analysis purposes, as
5578 -- set respectively by -gnatC and -gnatd.F
5580 if (CodePeer_Mode or Alfa_Mode)
5581 and then Comes_From_Source (N)
5586 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5587 -- declarative part or a package spec (RM 11.5(5)).
5589 if not Is_Configuration_Pragma then
5590 Check_Is_In_Decl_Part_Or_Package_Spec;
5593 Check_At_Least_N_Arguments (1);
5594 Check_At_Most_N_Arguments (2);
5595 Check_No_Identifier (Arg1);
5596 Check_Arg_Is_Identifier (Arg1);
5598 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5600 if C = No_Check_Id then
5602 ("argument of pragma% is not valid check name", Arg1);
5605 if not Suppress_Case
5606 and then (C = All_Checks or else C = Overflow_Check)
5608 Opt.Overflow_Checks_Unsuppressed := True;
5611 if Arg_Count = 1 then
5613 -- Make an entry in the local scope suppress table. This is the
5614 -- table that directly shows the current value of the scope
5615 -- suppress check for any check id value.
5617 if C = All_Checks then
5619 -- For All_Checks, we set all specific predefined checks with
5620 -- the exception of Elaboration_Check, which is handled
5621 -- specially because of not wanting All_Checks to have the
5622 -- effect of deactivating static elaboration order processing.
5623 -- Atomic_Synchronization is also not affected, since this is
5624 -- not a real check.
5626 for J in Scope_Suppress'Range loop
5627 if J /= Elaboration_Check
5628 and then J /= Atomic_Synchronization
5630 Scope_Suppress (J) := Suppress_Case;
5634 -- If not All_Checks, and predefined check, then set appropriate
5635 -- scope entry. Note that we will set Elaboration_Check if this
5636 -- is explicitly specified. Atomic_Synchronization is allowed
5637 -- only if internally generated and entity is atomic.
5639 elsif C in Predefined_Check_Id
5640 and then (not Comes_From_Source (N)
5641 or else C /= Atomic_Synchronization)
5643 Scope_Suppress (C) := Suppress_Case;
5646 -- Also make an entry in the Local_Entity_Suppress table
5648 Push_Local_Suppress_Stack_Entry
5651 Suppress => Suppress_Case);
5653 -- Case of two arguments present, where the check is suppressed for
5654 -- a specified entity (given as the second argument of the pragma)
5657 -- This is obsolescent in Ada 2005 mode
5659 if Ada_Version >= Ada_2005 then
5660 Check_Restriction (No_Obsolescent_Features, Arg2);
5663 Check_Optional_Identifier (Arg2, Name_On);
5664 E_Id := Get_Pragma_Arg (Arg2);
5667 if not Is_Entity_Name (E_Id) then
5669 ("second argument of pragma% must be entity name", Arg2);
5678 -- Enforce RM 11.5(7) which requires that for a pragma that
5679 -- appears within a package spec, the named entity must be
5680 -- within the package spec. We allow the package name itself
5681 -- to be mentioned since that makes sense, although it is not
5682 -- strictly allowed by 11.5(7).
5685 and then E /= Current_Scope
5686 and then Scope (E) /= Current_Scope
5689 ("entity in pragma% is not in package spec (RM 11.5(7))",
5693 -- Loop through homonyms. As noted below, in the case of a package
5694 -- spec, only homonyms within the package spec are considered.
5697 Suppress_Unsuppress_Echeck (E, C);
5699 if Is_Generic_Instance (E)
5700 and then Is_Subprogram (E)
5701 and then Present (Alias (E))
5703 Suppress_Unsuppress_Echeck (Alias (E), C);
5706 -- Move to next homonym if not aspect spec case
5708 exit when From_Aspect_Specification (N);
5712 -- If we are within a package specification, the pragma only
5713 -- applies to homonyms in the same scope.
5715 exit when In_Package_Spec
5716 and then Scope (E) /= Current_Scope;
5719 end Process_Suppress_Unsuppress;
5725 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5727 if Is_Imported (E) then
5729 ("cannot export entity& that was previously imported", Arg);
5731 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5733 ("cannot export entity& that has an address clause", Arg);
5736 Set_Is_Exported (E);
5738 -- Generate a reference for entity explicitly, because the
5739 -- identifier may be overloaded and name resolution will not
5742 Generate_Reference (E, Arg);
5744 -- Deal with exporting non-library level entity
5746 if not Is_Library_Level_Entity (E) then
5748 -- Not allowed at all for subprograms
5750 if Is_Subprogram (E) then
5751 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5753 -- Otherwise set public and statically allocated
5757 Set_Is_Statically_Allocated (E);
5759 -- Warn if the corresponding W flag is set and the pragma comes
5760 -- from source. The latter may not be true e.g. on VMS where we
5761 -- expand export pragmas for exception codes associated with
5762 -- imported or exported exceptions. We do not want to generate
5763 -- a warning for something that the user did not write.
5765 if Warn_On_Export_Import
5766 and then Comes_From_Source (Arg)
5769 ("?& has been made static as a result of Export", Arg, E);
5771 ("\this usage is non-standard and non-portable", Arg);
5776 if Warn_On_Export_Import and then Is_Type (E) then
5777 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5780 if Warn_On_Export_Import and Inside_A_Generic then
5782 ("all instances of& will have the same external name?", Arg, E);
5786 ----------------------------------------------
5787 -- Set_Extended_Import_Export_External_Name --
5788 ----------------------------------------------
5790 procedure Set_Extended_Import_Export_External_Name
5791 (Internal_Ent : Entity_Id;
5792 Arg_External : Node_Id)
5794 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5798 if No (Arg_External) then
5802 Check_Arg_Is_External_Name (Arg_External);
5804 if Nkind (Arg_External) = N_String_Literal then
5805 if String_Length (Strval (Arg_External)) = 0 then
5808 New_Name := Adjust_External_Name_Case (Arg_External);
5811 elsif Nkind (Arg_External) = N_Identifier then
5812 New_Name := Get_Default_External_Name (Arg_External);
5814 -- Check_Arg_Is_External_Name should let through only identifiers and
5815 -- string literals or static string expressions (which are folded to
5816 -- string literals).
5819 raise Program_Error;
5822 -- If we already have an external name set (by a prior normal Import
5823 -- or Export pragma), then the external names must match
5825 if Present (Interface_Name (Internal_Ent)) then
5826 Check_Matching_Internal_Names : declare
5827 S1 : constant String_Id := Strval (Old_Name);
5828 S2 : constant String_Id := Strval (New_Name);
5831 -- Called if names do not match
5837 procedure Mismatch is
5839 Error_Msg_Sloc := Sloc (Old_Name);
5841 ("external name does not match that given #",
5845 -- Start of processing for Check_Matching_Internal_Names
5848 if String_Length (S1) /= String_Length (S2) then
5852 for J in 1 .. String_Length (S1) loop
5853 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5858 end Check_Matching_Internal_Names;
5860 -- Otherwise set the given name
5863 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5864 Check_Duplicated_Export_Name (New_Name);
5866 end Set_Extended_Import_Export_External_Name;
5872 procedure Set_Imported (E : Entity_Id) is
5874 -- Error message if already imported or exported
5876 if Is_Exported (E) or else Is_Imported (E) then
5878 -- Error if being set Exported twice
5880 if Is_Exported (E) then
5881 Error_Msg_NE ("entity& was previously exported", N, E);
5883 -- OK if Import/Interface case
5885 elsif Import_Interface_Present (N) then
5888 -- Error if being set Imported twice
5891 Error_Msg_NE ("entity& was previously imported", N, E);
5894 Error_Msg_Name_1 := Pname;
5896 ("\(pragma% applies to all previous entities)", N);
5898 Error_Msg_Sloc := Sloc (E);
5899 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5901 -- Here if not previously imported or exported, OK to import
5904 Set_Is_Imported (E);
5906 -- If the entity is an object that is not at the library level,
5907 -- then it is statically allocated. We do not worry about objects
5908 -- with address clauses in this context since they are not really
5909 -- imported in the linker sense.
5912 and then not Is_Library_Level_Entity (E)
5913 and then No (Address_Clause (E))
5915 Set_Is_Statically_Allocated (E);
5922 -------------------------
5923 -- Set_Mechanism_Value --
5924 -------------------------
5926 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5927 -- analyzed, since it is semantic nonsense), so we get it in the exact
5928 -- form created by the parser.
5930 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5933 Mech_Name_Id : Name_Id;
5935 procedure Bad_Class;
5936 -- Signal bad descriptor class name
5938 procedure Bad_Mechanism;
5939 -- Signal bad mechanism name
5945 procedure Bad_Class is
5947 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5950 -------------------------
5951 -- Bad_Mechanism_Value --
5952 -------------------------
5954 procedure Bad_Mechanism is
5956 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5959 -- Start of processing for Set_Mechanism_Value
5962 if Mechanism (Ent) /= Default_Mechanism then
5964 ("mechanism for & has already been set", Mech_Name, Ent);
5967 -- MECHANISM_NAME ::= value | reference | descriptor |
5970 if Nkind (Mech_Name) = N_Identifier then
5971 if Chars (Mech_Name) = Name_Value then
5972 Set_Mechanism (Ent, By_Copy);
5975 elsif Chars (Mech_Name) = Name_Reference then
5976 Set_Mechanism (Ent, By_Reference);
5979 elsif Chars (Mech_Name) = Name_Descriptor then
5980 Check_VMS (Mech_Name);
5982 -- Descriptor => Short_Descriptor if pragma was given
5984 if Short_Descriptors then
5985 Set_Mechanism (Ent, By_Short_Descriptor);
5987 Set_Mechanism (Ent, By_Descriptor);
5992 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5993 Check_VMS (Mech_Name);
5994 Set_Mechanism (Ent, By_Short_Descriptor);
5997 elsif Chars (Mech_Name) = Name_Copy then
5999 ("bad mechanism name, Value assumed", Mech_Name);
6005 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
6006 -- short_descriptor (CLASS_NAME)
6007 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6009 -- Note: this form is parsed as an indexed component
6011 elsif Nkind (Mech_Name) = N_Indexed_Component then
6012 Class := First (Expressions (Mech_Name));
6014 if Nkind (Prefix (Mech_Name)) /= N_Identifier
6015 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
6016 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
6017 or else Present (Next (Class))
6021 Mech_Name_Id := Chars (Prefix (Mech_Name));
6023 -- Change Descriptor => Short_Descriptor if pragma was given
6025 if Mech_Name_Id = Name_Descriptor
6026 and then Short_Descriptors
6028 Mech_Name_Id := Name_Short_Descriptor;
6032 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6033 -- short_descriptor (Class => CLASS_NAME)
6034 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6036 -- Note: this form is parsed as a function call
6038 elsif Nkind (Mech_Name) = N_Function_Call then
6039 Param := First (Parameter_Associations (Mech_Name));
6041 if Nkind (Name (Mech_Name)) /= N_Identifier
6042 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6043 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6044 or else Present (Next (Param))
6045 or else No (Selector_Name (Param))
6046 or else Chars (Selector_Name (Param)) /= Name_Class
6050 Class := Explicit_Actual_Parameter (Param);
6051 Mech_Name_Id := Chars (Name (Mech_Name));
6058 -- Fall through here with Class set to descriptor class name
6060 Check_VMS (Mech_Name);
6062 if Nkind (Class) /= N_Identifier then
6065 elsif Mech_Name_Id = Name_Descriptor
6066 and then Chars (Class) = Name_UBS
6068 Set_Mechanism (Ent, By_Descriptor_UBS);
6070 elsif Mech_Name_Id = Name_Descriptor
6071 and then Chars (Class) = Name_UBSB
6073 Set_Mechanism (Ent, By_Descriptor_UBSB);
6075 elsif Mech_Name_Id = Name_Descriptor
6076 and then Chars (Class) = Name_UBA
6078 Set_Mechanism (Ent, By_Descriptor_UBA);
6080 elsif Mech_Name_Id = Name_Descriptor
6081 and then Chars (Class) = Name_S
6083 Set_Mechanism (Ent, By_Descriptor_S);
6085 elsif Mech_Name_Id = Name_Descriptor
6086 and then Chars (Class) = Name_SB
6088 Set_Mechanism (Ent, By_Descriptor_SB);
6090 elsif Mech_Name_Id = Name_Descriptor
6091 and then Chars (Class) = Name_A
6093 Set_Mechanism (Ent, By_Descriptor_A);
6095 elsif Mech_Name_Id = Name_Descriptor
6096 and then Chars (Class) = Name_NCA
6098 Set_Mechanism (Ent, By_Descriptor_NCA);
6100 elsif Mech_Name_Id = Name_Short_Descriptor
6101 and then Chars (Class) = Name_UBS
6103 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6105 elsif Mech_Name_Id = Name_Short_Descriptor
6106 and then Chars (Class) = Name_UBSB
6108 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6110 elsif Mech_Name_Id = Name_Short_Descriptor
6111 and then Chars (Class) = Name_UBA
6113 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6115 elsif Mech_Name_Id = Name_Short_Descriptor
6116 and then Chars (Class) = Name_S
6118 Set_Mechanism (Ent, By_Short_Descriptor_S);
6120 elsif Mech_Name_Id = Name_Short_Descriptor
6121 and then Chars (Class) = Name_SB
6123 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6125 elsif Mech_Name_Id = Name_Short_Descriptor
6126 and then Chars (Class) = Name_A
6128 Set_Mechanism (Ent, By_Short_Descriptor_A);
6130 elsif Mech_Name_Id = Name_Short_Descriptor
6131 and then Chars (Class) = Name_NCA
6133 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6138 end Set_Mechanism_Value;
6140 ---------------------------
6141 -- Set_Ravenscar_Profile --
6142 ---------------------------
6144 -- The tasks to be done here are
6146 -- Set required policies
6148 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6149 -- pragma Locking_Policy (Ceiling_Locking)
6151 -- Set Detect_Blocking mode
6153 -- Set required restrictions (see System.Rident for detailed list)
6155 -- Set the No_Dependence rules
6156 -- No_Dependence => Ada.Asynchronous_Task_Control
6157 -- No_Dependence => Ada.Calendar
6158 -- No_Dependence => Ada.Execution_Time.Group_Budget
6159 -- No_Dependence => Ada.Execution_Time.Timers
6160 -- No_Dependence => Ada.Task_Attributes
6161 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6163 procedure Set_Ravenscar_Profile (N : Node_Id) is
6164 Prefix_Entity : Entity_Id;
6165 Selector_Entity : Entity_Id;
6166 Prefix_Node : Node_Id;
6170 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6172 if Task_Dispatching_Policy /= ' '
6173 and then Task_Dispatching_Policy /= 'F'
6175 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6176 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6178 -- Set the FIFO_Within_Priorities policy, but always preserve
6179 -- System_Location since we like the error message with the run time
6183 Task_Dispatching_Policy := 'F';
6185 if Task_Dispatching_Policy_Sloc /= System_Location then
6186 Task_Dispatching_Policy_Sloc := Loc;
6190 -- pragma Locking_Policy (Ceiling_Locking)
6192 if Locking_Policy /= ' '
6193 and then Locking_Policy /= 'C'
6195 Error_Msg_Sloc := Locking_Policy_Sloc;
6196 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6198 -- Set the Ceiling_Locking policy, but preserve System_Location since
6199 -- we like the error message with the run time name.
6202 Locking_Policy := 'C';
6204 if Locking_Policy_Sloc /= System_Location then
6205 Locking_Policy_Sloc := Loc;
6209 -- pragma Detect_Blocking
6211 Detect_Blocking := True;
6213 -- Set the corresponding restrictions
6215 Set_Profile_Restrictions
6216 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6218 -- Set the No_Dependence restrictions
6220 -- The following No_Dependence restrictions:
6221 -- No_Dependence => Ada.Asynchronous_Task_Control
6222 -- No_Dependence => Ada.Calendar
6223 -- No_Dependence => Ada.Task_Attributes
6224 -- are already set by previous call to Set_Profile_Restrictions.
6226 -- Set the following restrictions which were added to Ada 2005:
6227 -- No_Dependence => Ada.Execution_Time.Group_Budget
6228 -- No_Dependence => Ada.Execution_Time.Timers
6230 if Ada_Version >= Ada_2005 then
6231 Name_Buffer (1 .. 3) := "ada";
6234 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6236 Name_Buffer (1 .. 14) := "execution_time";
6239 Selector_Entity := Make_Identifier (Loc, Name_Find);
6242 Make_Selected_Component
6244 Prefix => Prefix_Entity,
6245 Selector_Name => Selector_Entity);
6247 Name_Buffer (1 .. 13) := "group_budgets";
6250 Selector_Entity := Make_Identifier (Loc, Name_Find);
6253 Make_Selected_Component
6255 Prefix => Prefix_Node,
6256 Selector_Name => Selector_Entity);
6258 Set_Restriction_No_Dependence
6260 Warn => Treat_Restrictions_As_Warnings,
6261 Profile => Ravenscar);
6263 Name_Buffer (1 .. 6) := "timers";
6266 Selector_Entity := Make_Identifier (Loc, Name_Find);
6269 Make_Selected_Component
6271 Prefix => Prefix_Node,
6272 Selector_Name => Selector_Entity);
6274 Set_Restriction_No_Dependence
6276 Warn => Treat_Restrictions_As_Warnings,
6277 Profile => Ravenscar);
6280 -- Set the following restrictions which was added to Ada 2012 (see
6282 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6284 if Ada_Version >= Ada_2012 then
6285 Name_Buffer (1 .. 6) := "system";
6288 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6290 Name_Buffer (1 .. 15) := "multiprocessors";
6293 Selector_Entity := Make_Identifier (Loc, Name_Find);
6296 Make_Selected_Component
6298 Prefix => Prefix_Entity,
6299 Selector_Name => Selector_Entity);
6301 Name_Buffer (1 .. 19) := "dispatching_domains";
6304 Selector_Entity := Make_Identifier (Loc, Name_Find);
6307 Make_Selected_Component
6309 Prefix => Prefix_Node,
6310 Selector_Name => Selector_Entity);
6312 Set_Restriction_No_Dependence
6314 Warn => Treat_Restrictions_As_Warnings,
6315 Profile => Ravenscar);
6317 end Set_Ravenscar_Profile;
6319 -- Start of processing for Analyze_Pragma
6322 -- The following code is a defense against recursion. Not clear that
6323 -- this can happen legitimately, but perhaps some error situations
6324 -- can cause it, and we did see this recursion during testing.
6326 if Analyzed (N) then
6329 Set_Analyzed (N, True);
6332 -- Deal with unrecognized pragma
6334 Pname := Pragma_Name (N);
6336 if not Is_Pragma_Name (Pname) then
6337 if Warn_On_Unrecognized_Pragma then
6338 Error_Msg_Name_1 := Pname;
6339 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6341 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6342 if Is_Bad_Spelling_Of (Pname, PN) then
6343 Error_Msg_Name_1 := PN;
6344 Error_Msg_N -- CODEFIX
6345 ("\?possible misspelling of %!", Pragma_Identifier (N));
6354 -- Here to start processing for recognized pragma
6356 Prag_Id := Get_Pragma_Id (Pname);
6358 if Present (Corresponding_Aspect (N)) then
6359 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6370 if Present (Pragma_Argument_Associations (N)) then
6371 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6372 Arg1 := First (Pragma_Argument_Associations (N));
6374 if Present (Arg1) then
6375 Arg2 := Next (Arg1);
6377 if Present (Arg2) then
6378 Arg3 := Next (Arg2);
6380 if Present (Arg3) then
6381 Arg4 := Next (Arg3);
6387 -- An enumeration type defines the pragmas that are supported by the
6388 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6389 -- into the corresponding enumeration value for the following case.
6397 -- pragma Abort_Defer;
6399 when Pragma_Abort_Defer =>
6401 Check_Arg_Count (0);
6403 -- The only required semantic processing is to check the
6404 -- placement. This pragma must appear at the start of the
6405 -- statement sequence of a handled sequence of statements.
6407 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6408 or else N /= First (Statements (Parent (N)))
6419 -- Note: this pragma also has some specific processing in Par.Prag
6420 -- because we want to set the Ada version mode during parsing.
6422 when Pragma_Ada_83 =>
6424 Check_Arg_Count (0);
6426 -- We really should check unconditionally for proper configuration
6427 -- pragma placement, since we really don't want mixed Ada modes
6428 -- within a single unit, and the GNAT reference manual has always
6429 -- said this was a configuration pragma, but we did not check and
6430 -- are hesitant to add the check now.
6432 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6433 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6434 -- or Ada 2012 mode.
6436 if Ada_Version >= Ada_2005 then
6437 Check_Valid_Configuration_Pragma;
6440 -- Now set Ada 83 mode
6442 Ada_Version := Ada_83;
6443 Ada_Version_Explicit := Ada_Version;
6451 -- Note: this pragma also has some specific processing in Par.Prag
6452 -- because we want to set the Ada 83 version mode during parsing.
6454 when Pragma_Ada_95 =>
6456 Check_Arg_Count (0);
6458 -- We really should check unconditionally for proper configuration
6459 -- pragma placement, since we really don't want mixed Ada modes
6460 -- within a single unit, and the GNAT reference manual has always
6461 -- said this was a configuration pragma, but we did not check and
6462 -- are hesitant to add the check now.
6464 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6465 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6467 if Ada_Version >= Ada_2005 then
6468 Check_Valid_Configuration_Pragma;
6471 -- Now set Ada 95 mode
6473 Ada_Version := Ada_95;
6474 Ada_Version_Explicit := Ada_Version;
6476 ---------------------
6477 -- Ada_05/Ada_2005 --
6478 ---------------------
6481 -- pragma Ada_05 (LOCAL_NAME);
6484 -- pragma Ada_2005 (LOCAL_NAME):
6486 -- Note: these pragmas also have some specific processing in Par.Prag
6487 -- because we want to set the Ada 2005 version mode during parsing.
6489 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6495 if Arg_Count = 1 then
6496 Check_Arg_Is_Local_Name (Arg1);
6497 E_Id := Get_Pragma_Arg (Arg1);
6499 if Etype (E_Id) = Any_Type then
6503 Set_Is_Ada_2005_Only (Entity (E_Id));
6506 Check_Arg_Count (0);
6508 -- For Ada_2005 we unconditionally enforce the documented
6509 -- configuration pragma placement, since we do not want to
6510 -- tolerate mixed modes in a unit involving Ada 2005. That
6511 -- would cause real difficulties for those cases where there
6512 -- are incompatibilities between Ada 95 and Ada 2005.
6514 Check_Valid_Configuration_Pragma;
6516 -- Now set appropriate Ada mode
6518 Ada_Version := Ada_2005;
6519 Ada_Version_Explicit := Ada_2005;
6523 ---------------------
6524 -- Ada_12/Ada_2012 --
6525 ---------------------
6528 -- pragma Ada_12 (LOCAL_NAME);
6531 -- pragma Ada_2012 (LOCAL_NAME):
6533 -- Note: these pragmas also have some specific processing in Par.Prag
6534 -- because we want to set the Ada 2012 version mode during parsing.
6536 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6542 if Arg_Count = 1 then
6543 Check_Arg_Is_Local_Name (Arg1);
6544 E_Id := Get_Pragma_Arg (Arg1);
6546 if Etype (E_Id) = Any_Type then
6550 Set_Is_Ada_2012_Only (Entity (E_Id));
6553 Check_Arg_Count (0);
6555 -- For Ada_2012 we unconditionally enforce the documented
6556 -- configuration pragma placement, since we do not want to
6557 -- tolerate mixed modes in a unit involving Ada 2012. That
6558 -- would cause real difficulties for those cases where there
6559 -- are incompatibilities between Ada 95 and Ada 2012. We could
6560 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6562 Check_Valid_Configuration_Pragma;
6564 -- Now set appropriate Ada mode
6566 Ada_Version := Ada_2012;
6567 Ada_Version_Explicit := Ada_2012;
6571 ----------------------
6572 -- All_Calls_Remote --
6573 ----------------------
6575 -- pragma All_Calls_Remote [(library_package_NAME)];
6577 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6578 Lib_Entity : Entity_Id;
6581 Check_Ada_83_Warning;
6582 Check_Valid_Library_Unit_Pragma;
6584 if Nkind (N) = N_Null_Statement then
6588 Lib_Entity := Find_Lib_Unit_Name;
6590 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6592 if Present (Lib_Entity)
6593 and then not Debug_Flag_U
6595 if not Is_Remote_Call_Interface (Lib_Entity) then
6596 Error_Pragma ("pragma% only apply to rci unit");
6598 -- Set flag for entity of the library unit
6601 Set_Has_All_Calls_Remote (Lib_Entity);
6605 end All_Calls_Remote;
6611 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6612 -- ARG ::= NAME | EXPRESSION
6614 -- The first two arguments are by convention intended to refer to an
6615 -- external tool and a tool-specific function. These arguments are
6618 when Pragma_Annotate => Annotate : declare
6624 Check_At_Least_N_Arguments (1);
6625 Check_Arg_Is_Identifier (Arg1);
6626 Check_No_Identifiers;
6629 -- Second parameter is optional, it is never analyzed
6634 -- Here if we have a second parameter
6637 -- Second parameter must be identifier
6639 Check_Arg_Is_Identifier (Arg2);
6641 -- Process remaining parameters if any
6644 while Present (Arg) loop
6645 Exp := Get_Pragma_Arg (Arg);
6648 if Is_Entity_Name (Exp) then
6651 -- For string literals, we assume Standard_String as the
6652 -- type, unless the string contains wide or wide_wide
6655 elsif Nkind (Exp) = N_String_Literal then
6656 if Has_Wide_Wide_Character (Exp) then
6657 Resolve (Exp, Standard_Wide_Wide_String);
6658 elsif Has_Wide_Character (Exp) then
6659 Resolve (Exp, Standard_Wide_String);
6661 Resolve (Exp, Standard_String);
6664 elsif Is_Overloaded (Exp) then
6666 ("ambiguous argument for pragma%", Exp);
6681 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6682 -- [, [Message =>] Static_String_EXPRESSION]);
6684 when Pragma_Assert => Assert : declare
6690 Check_At_Least_N_Arguments (1);
6691 Check_At_Most_N_Arguments (2);
6692 Check_Arg_Order ((Name_Check, Name_Message));
6693 Check_Optional_Identifier (Arg1, Name_Check);
6695 -- We treat pragma Assert as equivalent to:
6697 -- pragma Check (Assertion, condition [, msg]);
6699 -- So rewrite pragma in this manner, and analyze the result
6701 Expr := Get_Pragma_Arg (Arg1);
6703 Make_Pragma_Argument_Association (Loc,
6704 Expression => Make_Identifier (Loc, Name_Assertion)),
6706 Make_Pragma_Argument_Association (Sloc (Expr),
6707 Expression => Expr));
6709 if Arg_Count > 1 then
6710 Check_Optional_Identifier (Arg2, Name_Message);
6711 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6712 Append_To (Newa, Relocate_Node (Arg2));
6717 Chars => Name_Check,
6718 Pragma_Argument_Associations => Newa));
6722 ----------------------
6723 -- Assertion_Policy --
6724 ----------------------
6726 -- pragma Assertion_Policy (Check | Disable |Ignore)
6728 when Pragma_Assertion_Policy => Assertion_Policy : declare
6733 Check_Valid_Configuration_Pragma;
6734 Check_Arg_Count (1);
6735 Check_No_Identifiers;
6736 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6738 -- We treat pragma Assertion_Policy as equivalent to:
6740 -- pragma Check_Policy (Assertion, policy)
6742 -- So rewrite the pragma in that manner and link on to the chain
6743 -- of Check_Policy pragmas, marking the pragma as analyzed.
6745 Policy := Get_Pragma_Arg (Arg1);
6749 Chars => Name_Check_Policy,
6751 Pragma_Argument_Associations => New_List (
6752 Make_Pragma_Argument_Association (Loc,
6753 Expression => Make_Identifier (Loc, Name_Assertion)),
6755 Make_Pragma_Argument_Association (Loc,
6757 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6760 Set_Next_Pragma (N, Opt.Check_Policy_List);
6761 Opt.Check_Policy_List := N;
6762 end Assertion_Policy;
6764 ------------------------------
6765 -- Assume_No_Invalid_Values --
6766 ------------------------------
6768 -- pragma Assume_No_Invalid_Values (On | Off);
6770 when Pragma_Assume_No_Invalid_Values =>
6772 Check_Valid_Configuration_Pragma;
6773 Check_Arg_Count (1);
6774 Check_No_Identifiers;
6775 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6777 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6778 Assume_No_Invalid_Values := True;
6780 Assume_No_Invalid_Values := False;
6787 -- pragma AST_Entry (entry_IDENTIFIER);
6789 when Pragma_AST_Entry => AST_Entry : declare
6795 Check_Arg_Count (1);
6796 Check_No_Identifiers;
6797 Check_Arg_Is_Local_Name (Arg1);
6798 Ent := Entity (Get_Pragma_Arg (Arg1));
6800 -- Note: the implementation of the AST_Entry pragma could handle
6801 -- the entry family case fine, but for now we are consistent with
6802 -- the DEC rules, and do not allow the pragma, which of course
6803 -- has the effect of also forbidding the attribute.
6805 if Ekind (Ent) /= E_Entry then
6807 ("pragma% argument must be simple entry name", Arg1);
6809 elsif Is_AST_Entry (Ent) then
6811 ("duplicate % pragma for entry", Arg1);
6813 elsif Has_Homonym (Ent) then
6815 ("pragma% argument cannot specify overloaded entry", Arg1);
6819 FF : constant Entity_Id := First_Formal (Ent);
6822 if Present (FF) then
6823 if Present (Next_Formal (FF)) then
6825 ("entry for pragma% can have only one argument",
6828 elsif Parameter_Mode (FF) /= E_In_Parameter then
6830 ("entry parameter for pragma% must have mode IN",
6836 Set_Is_AST_Entry (Ent);
6844 -- pragma Asynchronous (LOCAL_NAME);
6846 when Pragma_Asynchronous => Asynchronous : declare
6854 procedure Process_Async_Pragma;
6855 -- Common processing for procedure and access-to-procedure case
6857 --------------------------
6858 -- Process_Async_Pragma --
6859 --------------------------
6861 procedure Process_Async_Pragma is
6864 Set_Is_Asynchronous (Nm);
6868 -- The formals should be of mode IN (RM E.4.1(6))
6871 while Present (S) loop
6872 Formal := Defining_Identifier (S);
6874 if Nkind (Formal) = N_Defining_Identifier
6875 and then Ekind (Formal) /= E_In_Parameter
6878 ("pragma% procedure can only have IN parameter",
6885 Set_Is_Asynchronous (Nm);
6886 end Process_Async_Pragma;
6888 -- Start of processing for pragma Asynchronous
6891 Check_Ada_83_Warning;
6892 Check_No_Identifiers;
6893 Check_Arg_Count (1);
6894 Check_Arg_Is_Local_Name (Arg1);
6896 if Debug_Flag_U then
6900 C_Ent := Cunit_Entity (Current_Sem_Unit);
6901 Analyze (Get_Pragma_Arg (Arg1));
6902 Nm := Entity (Get_Pragma_Arg (Arg1));
6904 if not Is_Remote_Call_Interface (C_Ent)
6905 and then not Is_Remote_Types (C_Ent)
6907 -- This pragma should only appear in an RCI or Remote Types
6908 -- unit (RM E.4.1(4)).
6911 ("pragma% not in Remote_Call_Interface or " &
6912 "Remote_Types unit");
6915 if Ekind (Nm) = E_Procedure
6916 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6918 if not Is_Remote_Call_Interface (Nm) then
6920 ("pragma% cannot be applied on non-remote procedure",
6924 L := Parameter_Specifications (Parent (Nm));
6925 Process_Async_Pragma;
6928 elsif Ekind (Nm) = E_Function then
6930 ("pragma% cannot be applied to function", Arg1);
6932 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6933 if Is_Record_Type (Nm) then
6935 -- A record type that is the Equivalent_Type for a remote
6936 -- access-to-subprogram type.
6938 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6941 -- A non-expanded RAS type (distribution is not enabled)
6943 N := Declaration_Node (Nm);
6946 if Nkind (N) = N_Full_Type_Declaration
6947 and then Nkind (Type_Definition (N)) =
6948 N_Access_Procedure_Definition
6950 L := Parameter_Specifications (Type_Definition (N));
6951 Process_Async_Pragma;
6953 if Is_Asynchronous (Nm)
6954 and then Expander_Active
6955 and then Get_PCS_Name /= Name_No_DSA
6957 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6962 ("pragma% cannot reference access-to-function type",
6966 -- Only other possibility is Access-to-class-wide type
6968 elsif Is_Access_Type (Nm)
6969 and then Is_Class_Wide_Type (Designated_Type (Nm))
6971 Check_First_Subtype (Arg1);
6972 Set_Is_Asynchronous (Nm);
6973 if Expander_Active then
6974 RACW_Type_Is_Asynchronous (Nm);
6978 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6986 -- pragma Atomic (LOCAL_NAME);
6988 when Pragma_Atomic =>
6989 Process_Atomic_Shared_Volatile;
6991 -----------------------
6992 -- Atomic_Components --
6993 -----------------------
6995 -- pragma Atomic_Components (array_LOCAL_NAME);
6997 -- This processing is shared by Volatile_Components
6999 when Pragma_Atomic_Components |
7000 Pragma_Volatile_Components =>
7002 Atomic_Components : declare
7009 Check_Ada_83_Warning;
7010 Check_No_Identifiers;
7011 Check_Arg_Count (1);
7012 Check_Arg_Is_Local_Name (Arg1);
7013 E_Id := Get_Pragma_Arg (Arg1);
7015 if Etype (E_Id) = Any_Type then
7021 Check_Duplicate_Pragma (E);
7023 if Rep_Item_Too_Early (E, N)
7025 Rep_Item_Too_Late (E, N)
7030 D := Declaration_Node (E);
7033 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7035 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7036 and then Nkind (D) = N_Object_Declaration
7037 and then Nkind (Object_Definition (D)) =
7038 N_Constrained_Array_Definition)
7040 -- The flag is set on the object, or on the base type
7042 if Nkind (D) /= N_Object_Declaration then
7046 Set_Has_Volatile_Components (E);
7048 if Prag_Id = Pragma_Atomic_Components then
7049 Set_Has_Atomic_Components (E);
7053 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7055 end Atomic_Components;
7056 --------------------
7057 -- Attach_Handler --
7058 --------------------
7060 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7062 when Pragma_Attach_Handler =>
7063 Check_Ada_83_Warning;
7064 Check_No_Identifiers;
7065 Check_Arg_Count (2);
7067 if No_Run_Time_Mode then
7068 Error_Msg_CRT ("Attach_Handler pragma", N);
7070 Check_Interrupt_Or_Attach_Handler;
7072 -- The expression that designates the attribute may depend on a
7073 -- discriminant, and is therefore a per- object expression, to
7074 -- be expanded in the init proc. If expansion is enabled, then
7075 -- perform semantic checks on a copy only.
7077 if Expander_Active then
7079 Temp : constant Node_Id :=
7080 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7082 Set_Parent (Temp, N);
7083 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7087 Analyze (Get_Pragma_Arg (Arg2));
7088 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7091 Process_Interrupt_Or_Attach_Handler;
7094 --------------------
7095 -- C_Pass_By_Copy --
7096 --------------------
7098 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7100 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7106 Check_Valid_Configuration_Pragma;
7107 Check_Arg_Count (1);
7108 Check_Optional_Identifier (Arg1, "max_size");
7110 Arg := Get_Pragma_Arg (Arg1);
7111 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7113 Val := Expr_Value (Arg);
7117 ("maximum size for pragma% must be positive", Arg1);
7119 elsif UI_Is_In_Int_Range (Val) then
7120 Default_C_Record_Mechanism := UI_To_Int (Val);
7122 -- If a giant value is given, Int'Last will do well enough.
7123 -- If sometime someone complains that a record larger than
7124 -- two gigabytes is not copied, we will worry about it then!
7127 Default_C_Record_Mechanism := Mechanism_Type'Last;
7135 -- pragma Check ([Name =>] IDENTIFIER,
7136 -- [Check =>] Boolean_EXPRESSION
7137 -- [,[Message =>] String_EXPRESSION]);
7139 when Pragma_Check => Check : declare
7144 -- Set True if category of assertions referenced by Name enabled
7148 Check_At_Least_N_Arguments (2);
7149 Check_At_Most_N_Arguments (3);
7150 Check_Optional_Identifier (Arg1, Name_Name);
7151 Check_Optional_Identifier (Arg2, Name_Check);
7153 if Arg_Count = 3 then
7154 Check_Optional_Identifier (Arg3, Name_Message);
7155 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7158 Check_Arg_Is_Identifier (Arg1);
7160 -- Completely ignore if disabled
7162 if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7163 Rewrite (N, Make_Null_Statement (Loc));
7168 -- Indicate if pragma is enabled. The Original_Node reference here
7169 -- is to deal with pragma Assert rewritten as a Check pragma.
7171 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
7174 Set_SCO_Pragma_Enabled (Loc);
7177 -- If expansion is active and the check is not enabled then we
7178 -- rewrite the Check as:
7180 -- if False and then condition then
7184 -- The reason we do this rewriting during semantic analysis rather
7185 -- than as part of normal expansion is that we cannot analyze and
7186 -- expand the code for the boolean expression directly, or it may
7187 -- cause insertion of actions that would escape the attempt to
7188 -- suppress the check code.
7190 -- Note that the Sloc for the if statement corresponds to the
7191 -- argument condition, not the pragma itself. The reason for this
7192 -- is that we may generate a warning if the condition is False at
7193 -- compile time, and we do not want to delete this warning when we
7194 -- delete the if statement.
7196 Expr := Get_Pragma_Arg (Arg2);
7198 if Expander_Active and then not Check_On then
7199 Eloc := Sloc (Expr);
7202 Make_If_Statement (Eloc,
7204 Make_And_Then (Eloc,
7205 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7206 Right_Opnd => Expr),
7207 Then_Statements => New_List (
7208 Make_Null_Statement (Eloc))));
7215 Analyze_And_Resolve (Expr, Any_Boolean);
7223 -- pragma Check_Name (check_IDENTIFIER);
7225 when Pragma_Check_Name =>
7226 Check_No_Identifiers;
7228 Check_Valid_Configuration_Pragma;
7229 Check_Arg_Count (1);
7230 Check_Arg_Is_Identifier (Arg1);
7233 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7236 for J in Check_Names.First .. Check_Names.Last loop
7237 if Check_Names.Table (J) = Nam then
7242 Check_Names.Append (Nam);
7249 -- pragma Check_Policy (
7250 -- [Name =>] IDENTIFIER,
7251 -- [Policy =>] POLICY_IDENTIFIER);
7253 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7255 -- Note: this is a configuration pragma, but it is allowed to appear
7258 when Pragma_Check_Policy =>
7260 Check_Arg_Count (2);
7261 Check_Optional_Identifier (Arg1, Name_Name);
7262 Check_Optional_Identifier (Arg2, Name_Policy);
7264 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7266 -- A Check_Policy pragma can appear either as a configuration
7267 -- pragma, or in a declarative part or a package spec (see RM
7268 -- 11.5(5) for rules for Suppress/Unsuppress which are also
7269 -- followed for Check_Policy).
7271 if not Is_Configuration_Pragma then
7272 Check_Is_In_Decl_Part_Or_Package_Spec;
7275 Set_Next_Pragma (N, Opt.Check_Policy_List);
7276 Opt.Check_Policy_List := N;
7278 ---------------------
7279 -- CIL_Constructor --
7280 ---------------------
7282 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7284 -- Processing for this pragma is shared with Java_Constructor
7290 -- pragma Comment (static_string_EXPRESSION)
7292 -- Processing for pragma Comment shares the circuitry for pragma
7293 -- Ident. The only differences are that Ident enforces a limit of 31
7294 -- characters on its argument, and also enforces limitations on
7295 -- placement for DEC compatibility. Pragma Comment shares neither of
7296 -- these restrictions.
7302 -- pragma Common_Object (
7303 -- [Internal =>] LOCAL_NAME
7304 -- [, [External =>] EXTERNAL_SYMBOL]
7305 -- [, [Size =>] EXTERNAL_SYMBOL]);
7307 -- Processing for this pragma is shared with Psect_Object
7309 ------------------------
7310 -- Compile_Time_Error --
7311 ------------------------
7313 -- pragma Compile_Time_Error
7314 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7316 when Pragma_Compile_Time_Error =>
7318 Process_Compile_Time_Warning_Or_Error;
7320 --------------------------
7321 -- Compile_Time_Warning --
7322 --------------------------
7324 -- pragma Compile_Time_Warning
7325 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7327 when Pragma_Compile_Time_Warning =>
7329 Process_Compile_Time_Warning_Or_Error;
7335 when Pragma_Compiler_Unit =>
7337 Check_Arg_Count (0);
7338 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7340 -----------------------------
7341 -- Complete_Representation --
7342 -----------------------------
7344 -- pragma Complete_Representation;
7346 when Pragma_Complete_Representation =>
7348 Check_Arg_Count (0);
7350 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7352 ("pragma & must appear within record representation clause");
7355 ----------------------------
7356 -- Complex_Representation --
7357 ----------------------------
7359 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7361 when Pragma_Complex_Representation => Complex_Representation : declare
7368 Check_Arg_Count (1);
7369 Check_Optional_Identifier (Arg1, Name_Entity);
7370 Check_Arg_Is_Local_Name (Arg1);
7371 E_Id := Get_Pragma_Arg (Arg1);
7373 if Etype (E_Id) = Any_Type then
7379 if not Is_Record_Type (E) then
7381 ("argument for pragma% must be record type", Arg1);
7384 Ent := First_Entity (E);
7387 or else No (Next_Entity (Ent))
7388 or else Present (Next_Entity (Next_Entity (Ent)))
7389 or else not Is_Floating_Point_Type (Etype (Ent))
7390 or else Etype (Ent) /= Etype (Next_Entity (Ent))
7393 ("record for pragma% must have two fields of the same "
7394 & "floating-point type", Arg1);
7397 Set_Has_Complex_Representation (Base_Type (E));
7399 -- We need to treat the type has having a non-standard
7400 -- representation, for back-end purposes, even though in
7401 -- general a complex will have the default representation
7402 -- of a record with two real components.
7404 Set_Has_Non_Standard_Rep (Base_Type (E));
7406 end Complex_Representation;
7408 -------------------------
7409 -- Component_Alignment --
7410 -------------------------
7412 -- pragma Component_Alignment (
7413 -- [Form =>] ALIGNMENT_CHOICE
7414 -- [, [Name =>] type_LOCAL_NAME]);
7416 -- ALIGNMENT_CHOICE ::=
7418 -- | Component_Size_4
7422 when Pragma_Component_Alignment => Component_AlignmentP : declare
7423 Args : Args_List (1 .. 2);
7424 Names : constant Name_List (1 .. 2) := (
7428 Form : Node_Id renames Args (1);
7429 Name : Node_Id renames Args (2);
7431 Atype : Component_Alignment_Kind;
7436 Gather_Associations (Names, Args);
7439 Error_Pragma ("missing Form argument for pragma%");
7442 Check_Arg_Is_Identifier (Form);
7444 -- Get proper alignment, note that Default = Component_Size on all
7445 -- machines we have so far, and we want to set this value rather
7446 -- than the default value to indicate that it has been explicitly
7447 -- set (and thus will not get overridden by the default component
7448 -- alignment for the current scope)
7450 if Chars (Form) = Name_Component_Size then
7451 Atype := Calign_Component_Size;
7453 elsif Chars (Form) = Name_Component_Size_4 then
7454 Atype := Calign_Component_Size_4;
7456 elsif Chars (Form) = Name_Default then
7457 Atype := Calign_Component_Size;
7459 elsif Chars (Form) = Name_Storage_Unit then
7460 Atype := Calign_Storage_Unit;
7464 ("invalid Form parameter for pragma%", Form);
7467 -- Case with no name, supplied, affects scope table entry
7471 (Scope_Stack.Last).Component_Alignment_Default := Atype;
7473 -- Case of name supplied
7476 Check_Arg_Is_Local_Name (Name);
7478 Typ := Entity (Name);
7481 or else Rep_Item_Too_Early (Typ, N)
7485 Typ := Underlying_Type (Typ);
7488 if not Is_Record_Type (Typ)
7489 and then not Is_Array_Type (Typ)
7492 ("Name parameter of pragma% must identify record or " &
7493 "array type", Name);
7496 -- An explicit Component_Alignment pragma overrides an
7497 -- implicit pragma Pack, but not an explicit one.
7499 if not Has_Pragma_Pack (Base_Type (Typ)) then
7500 Set_Is_Packed (Base_Type (Typ), False);
7501 Set_Component_Alignment (Base_Type (Typ), Atype);
7504 end Component_AlignmentP;
7510 -- pragma Controlled (first_subtype_LOCAL_NAME);
7512 when Pragma_Controlled => Controlled : declare
7516 Check_No_Identifiers;
7517 Check_Arg_Count (1);
7518 Check_Arg_Is_Local_Name (Arg1);
7519 Arg := Get_Pragma_Arg (Arg1);
7521 if not Is_Entity_Name (Arg)
7522 or else not Is_Access_Type (Entity (Arg))
7524 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7526 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7534 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
7535 -- [Entity =>] LOCAL_NAME);
7537 when Pragma_Convention => Convention : declare
7540 pragma Warnings (Off, C);
7541 pragma Warnings (Off, E);
7543 Check_Arg_Order ((Name_Convention, Name_Entity));
7544 Check_Ada_83_Warning;
7545 Check_Arg_Count (2);
7546 Process_Convention (C, E);
7549 ---------------------------
7550 -- Convention_Identifier --
7551 ---------------------------
7553 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7554 -- [Convention =>] convention_IDENTIFIER);
7556 when Pragma_Convention_Identifier => Convention_Identifier : declare
7562 Check_Arg_Order ((Name_Name, Name_Convention));
7563 Check_Arg_Count (2);
7564 Check_Optional_Identifier (Arg1, Name_Name);
7565 Check_Optional_Identifier (Arg2, Name_Convention);
7566 Check_Arg_Is_Identifier (Arg1);
7567 Check_Arg_Is_Identifier (Arg2);
7568 Idnam := Chars (Get_Pragma_Arg (Arg1));
7569 Cname := Chars (Get_Pragma_Arg (Arg2));
7571 if Is_Convention_Name (Cname) then
7572 Record_Convention_Identifier
7573 (Idnam, Get_Convention_Id (Cname));
7576 ("second arg for % pragma must be convention", Arg2);
7578 end Convention_Identifier;
7584 -- pragma CPP_Class ([Entity =>] local_NAME)
7586 when Pragma_CPP_Class => CPP_Class : declare
7591 if Warn_On_Obsolescent_Feature then
7593 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7594 " by pragma import?", N);
7598 Check_Arg_Count (1);
7599 Check_Optional_Identifier (Arg1, Name_Entity);
7600 Check_Arg_Is_Local_Name (Arg1);
7602 Arg := Get_Pragma_Arg (Arg1);
7605 if Etype (Arg) = Any_Type then
7609 if not Is_Entity_Name (Arg)
7610 or else not Is_Type (Entity (Arg))
7612 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7615 Typ := Entity (Arg);
7617 if not Is_Tagged_Type (Typ) then
7618 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7621 -- Types treated as CPP classes must be declared limited (note:
7622 -- this used to be a warning but there is no real benefit to it
7623 -- since we did effectively intend to treat the type as limited
7626 if not Is_Limited_Type (Typ) then
7628 ("imported 'C'P'P type must be limited",
7629 Get_Pragma_Arg (Arg1));
7632 Set_Is_CPP_Class (Typ);
7633 Set_Convention (Typ, Convention_CPP);
7635 -- Imported CPP types must not have discriminants (because C++
7636 -- classes do not have discriminants).
7638 if Has_Discriminants (Typ) then
7640 ("imported 'C'P'P type cannot have discriminants",
7641 First (Discriminant_Specifications
7642 (Declaration_Node (Typ))));
7645 -- Components of imported CPP types must not have default
7646 -- expressions because the constructor (if any) is in the
7649 if Is_Incomplete_Or_Private_Type (Typ)
7650 and then No (Underlying_Type (Typ))
7652 -- It should be an error to apply pragma CPP to a private
7653 -- type if the underlying type is not visible (as it is
7654 -- for any representation item). For now, for backward
7655 -- compatibility we do nothing but we cannot check components
7656 -- because they are not available at this stage. All this code
7657 -- will be removed when we cleanup this obsolete GNAT pragma???
7663 Tdef : constant Node_Id :=
7664 Type_Definition (Declaration_Node (Typ));
7669 if Nkind (Tdef) = N_Record_Definition then
7670 Clist := Component_List (Tdef);
7672 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7673 Clist := Component_List (Record_Extension_Part (Tdef));
7676 if Present (Clist) then
7677 Comp := First (Component_Items (Clist));
7678 while Present (Comp) loop
7679 if Present (Expression (Comp)) then
7681 ("component of imported 'C'P'P type cannot have" &
7682 " default expression", Expression (Comp));
7692 ---------------------
7693 -- CPP_Constructor --
7694 ---------------------
7696 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7697 -- [, [External_Name =>] static_string_EXPRESSION ]
7698 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7700 when Pragma_CPP_Constructor => CPP_Constructor : declare
7704 Tag_Typ : Entity_Id;
7708 Check_At_Least_N_Arguments (1);
7709 Check_At_Most_N_Arguments (3);
7710 Check_Optional_Identifier (Arg1, Name_Entity);
7711 Check_Arg_Is_Local_Name (Arg1);
7713 Id := Get_Pragma_Arg (Arg1);
7714 Find_Program_Unit_Name (Id);
7716 -- If we did not find the name, we are done
7718 if Etype (Id) = Any_Type then
7722 Def_Id := Entity (Id);
7724 -- Check if already defined as constructor
7726 if Is_Constructor (Def_Id) then
7728 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7732 if Ekind (Def_Id) = E_Function
7733 and then (Is_CPP_Class (Etype (Def_Id))
7734 or else (Is_Class_Wide_Type (Etype (Def_Id))
7736 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7738 if Arg_Count >= 2 then
7739 Set_Imported (Def_Id);
7740 Set_Is_Public (Def_Id);
7741 Process_Interface_Name (Def_Id, Arg2, Arg3);
7744 Set_Has_Completion (Def_Id);
7745 Set_Is_Constructor (Def_Id);
7747 -- Imported C++ constructors are not dispatching primitives
7748 -- because in C++ they don't have a dispatch table slot.
7749 -- However, in Ada the constructor has the profile of a
7750 -- function that returns a tagged type and therefore it has
7751 -- been treated as a primitive operation during semantic
7752 -- analysis. We now remove it from the list of primitive
7753 -- operations of the type.
7755 if Is_Tagged_Type (Etype (Def_Id))
7756 and then not Is_Class_Wide_Type (Etype (Def_Id))
7758 pragma Assert (Is_Dispatching_Operation (Def_Id));
7759 Tag_Typ := Etype (Def_Id);
7761 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7762 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7766 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7767 Set_Is_Dispatching_Operation (Def_Id, False);
7770 -- For backward compatibility, if the constructor returns a
7771 -- class wide type, and we internally change the return type to
7772 -- the corresponding root type.
7774 if Is_Class_Wide_Type (Etype (Def_Id)) then
7775 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7779 ("pragma% requires function returning a 'C'P'P_Class type",
7782 end CPP_Constructor;
7788 when Pragma_CPP_Virtual => CPP_Virtual : declare
7792 if Warn_On_Obsolescent_Feature then
7794 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7803 when Pragma_CPP_Vtable => CPP_Vtable : declare
7807 if Warn_On_Obsolescent_Feature then
7809 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7818 -- pragma CPU (EXPRESSION);
7820 when Pragma_CPU => CPU : declare
7821 P : constant Node_Id := Parent (N);
7826 Check_No_Identifiers;
7827 Check_Arg_Count (1);
7831 if Nkind (P) = N_Subprogram_Body then
7832 Check_In_Main_Program;
7834 Arg := Get_Pragma_Arg (Arg1);
7835 Analyze_And_Resolve (Arg, Any_Integer);
7839 if not Is_Static_Expression (Arg) then
7840 Flag_Non_Static_Expr
7841 ("main subprogram affinity is not static!", Arg);
7844 -- If constraint error, then we already signalled an error
7846 elsif Raises_Constraint_Error (Arg) then
7849 -- Otherwise check in range
7853 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7854 -- This is the entity System.Multiprocessors.CPU_Range;
7856 Val : constant Uint := Expr_Value (Arg);
7859 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7861 Val > Expr_Value (Type_High_Bound (CPU_Id))
7864 ("main subprogram CPU is out of range", Arg1);
7870 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7874 elsif Nkind (P) = N_Task_Definition then
7875 Arg := Get_Pragma_Arg (Arg1);
7877 -- The expression must be analyzed in the special manner
7878 -- described in "Handling of Default and Per-Object
7879 -- Expressions" in sem.ads.
7881 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7883 -- Anything else is incorrect
7889 if Has_Pragma_CPU (P) then
7890 Error_Pragma ("duplicate pragma% not allowed");
7892 Set_Has_Pragma_CPU (P, True);
7894 if Nkind (P) = N_Task_Definition then
7895 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7904 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7906 when Pragma_Debug => Debug : declare
7913 -- Skip analysis if disabled
7915 if Debug_Pragmas_Disabled then
7916 Rewrite (N, Make_Null_Statement (Loc));
7923 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7926 if Debug_Pragmas_Enabled then
7927 Set_SCO_Pragma_Enabled (Loc);
7930 if Arg_Count = 2 then
7933 Left_Opnd => Relocate_Node (Cond),
7934 Right_Opnd => Get_Pragma_Arg (Arg1));
7935 Call := Get_Pragma_Arg (Arg2);
7937 Call := Get_Pragma_Arg (Arg1);
7941 N_Indexed_Component,
7945 N_Selected_Component)
7947 -- If this pragma Debug comes from source, its argument was
7948 -- parsed as a name form (which is syntactically identical).
7949 -- In a generic context a parameterless call will be left as
7950 -- an expanded name (if global) or selected_component if local.
7951 -- Change it to a procedure call statement now.
7953 Change_Name_To_Procedure_Call_Statement (Call);
7955 elsif Nkind (Call) = N_Procedure_Call_Statement then
7957 -- Already in the form of a procedure call statement: nothing
7958 -- to do (could happen in case of an internally generated
7964 -- All other cases: diagnose error
7967 ("argument of pragma ""Debug"" is not procedure call",
7972 -- Rewrite into a conditional with an appropriate condition. We
7973 -- wrap the procedure call in a block so that overhead from e.g.
7974 -- use of the secondary stack does not generate execution overhead
7975 -- for suppressed conditions.
7977 Rewrite (N, Make_Implicit_If_Statement (N,
7979 Then_Statements => New_List (
7980 Make_Block_Statement (Loc,
7981 Handled_Statement_Sequence =>
7982 Make_Handled_Sequence_Of_Statements (Loc,
7983 Statements => New_List (Relocate_Node (Call)))))));
7991 -- pragma Debug_Policy (Check | Ignore)
7993 when Pragma_Debug_Policy =>
7995 Check_Arg_Count (1);
7996 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7997 Debug_Pragmas_Enabled :=
7998 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7999 Debug_Pragmas_Disabled :=
8000 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
8002 ---------------------
8003 -- Detect_Blocking --
8004 ---------------------
8006 -- pragma Detect_Blocking;
8008 when Pragma_Detect_Blocking =>
8010 Check_Arg_Count (0);
8011 Check_Valid_Configuration_Pragma;
8012 Detect_Blocking := True;
8014 --------------------------
8015 -- Default_Storage_Pool --
8016 --------------------------
8018 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
8020 when Pragma_Default_Storage_Pool =>
8022 Check_Arg_Count (1);
8024 -- Default_Storage_Pool can appear as a configuration pragma, or
8025 -- in a declarative part or a package spec.
8027 if not Is_Configuration_Pragma then
8028 Check_Is_In_Decl_Part_Or_Package_Spec;
8031 -- Case of Default_Storage_Pool (null);
8033 if Nkind (Expression (Arg1)) = N_Null then
8034 Analyze (Expression (Arg1));
8036 -- This is an odd case, this is not really an expression, so
8037 -- we don't have a type for it. So just set the type to Empty.
8039 Set_Etype (Expression (Arg1), Empty);
8041 -- Case of Default_Storage_Pool (storage_pool_NAME);
8044 -- If it's a configuration pragma, then the only allowed
8045 -- argument is "null".
8047 if Is_Configuration_Pragma then
8048 Error_Pragma_Arg ("NULL expected", Arg1);
8051 -- The expected type for a non-"null" argument is
8052 -- Root_Storage_Pool'Class.
8055 (Get_Pragma_Arg (Arg1),
8056 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8059 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
8060 -- for an access type will use this information to set the
8061 -- appropriate attributes of the access type.
8063 Default_Pool := Expression (Arg1);
8069 when Pragma_Dimension =>
8071 Check_Arg_Count (4);
8072 Check_No_Identifiers;
8073 Check_Arg_Is_Local_Name (Arg1);
8075 if not Is_Type (Arg1) then
8076 Error_Pragma ("first argument for pragma% must be subtype");
8079 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
8080 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
8081 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
8083 ------------------------------------
8084 -- Disable_Atomic_Synchronization --
8085 ------------------------------------
8087 -- pragma Disable_Atomic_Synchronization [(Entity)];
8089 when Pragma_Disable_Atomic_Synchronization =>
8090 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8096 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
8098 when Pragma_Discard_Names => Discard_Names : declare
8103 Check_Ada_83_Warning;
8105 -- Deal with configuration pragma case
8107 if Arg_Count = 0 and then Is_Configuration_Pragma then
8108 Global_Discard_Names := True;
8111 -- Otherwise, check correct appropriate context
8114 Check_Is_In_Decl_Part_Or_Package_Spec;
8116 if Arg_Count = 0 then
8118 -- If there is no parameter, then from now on this pragma
8119 -- applies to any enumeration, exception or tagged type
8120 -- defined in the current declarative part, and recursively
8121 -- to any nested scope.
8123 Set_Discard_Names (Current_Scope);
8127 Check_Arg_Count (1);
8128 Check_Optional_Identifier (Arg1, Name_On);
8129 Check_Arg_Is_Local_Name (Arg1);
8131 E_Id := Get_Pragma_Arg (Arg1);
8133 if Etype (E_Id) = Any_Type then
8139 if (Is_First_Subtype (E)
8141 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8142 or else Ekind (E) = E_Exception
8144 Set_Discard_Names (E);
8147 ("inappropriate entity for pragma%", Arg1);
8154 ------------------------
8155 -- Dispatching_Domain --
8156 ------------------------
8158 -- pragma Dispatching_Domain (EXPRESSION);
8160 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8161 P : constant Node_Id := Parent (N);
8166 Check_No_Identifiers;
8167 Check_Arg_Count (1);
8169 -- This pragma is born obsolete, but not the aspect
8171 if not From_Aspect_Specification (N) then
8173 (No_Obsolescent_Features, Pragma_Identifier (N));
8176 if Nkind (P) = N_Task_Definition then
8177 Arg := Get_Pragma_Arg (Arg1);
8179 -- The expression must be analyzed in the special manner
8180 -- described in "Handling of Default and Per-Object
8181 -- Expressions" in sem.ads.
8183 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8185 -- Anything else is incorrect
8191 if Has_Pragma_Dispatching_Domain (P) then
8192 Error_Pragma ("duplicate pragma% not allowed");
8194 Set_Has_Pragma_Dispatching_Domain (P, True);
8196 if Nkind (P) = N_Task_Definition then
8197 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8200 end Dispatching_Domain;
8206 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8208 when Pragma_Elaborate => Elaborate : declare
8213 -- Pragma must be in context items list of a compilation unit
8215 if not Is_In_Context_Clause then
8219 -- Must be at least one argument
8221 if Arg_Count = 0 then
8222 Error_Pragma ("pragma% requires at least one argument");
8225 -- In Ada 83 mode, there can be no items following it in the
8226 -- context list except other pragmas and implicit with clauses
8227 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8228 -- placement rule does not apply.
8230 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8232 while Present (Citem) loop
8233 if Nkind (Citem) = N_Pragma
8234 or else (Nkind (Citem) = N_With_Clause
8235 and then Implicit_With (Citem))
8240 ("(Ada 83) pragma% must be at end of context clause");
8247 -- Finally, the arguments must all be units mentioned in a with
8248 -- clause in the same context clause. Note we already checked (in
8249 -- Par.Prag) that the arguments are all identifiers or selected
8253 Outer : while Present (Arg) loop
8254 Citem := First (List_Containing (N));
8255 Inner : while Citem /= N loop
8256 if Nkind (Citem) = N_With_Clause
8257 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8259 Set_Elaborate_Present (Citem, True);
8260 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8261 Generate_Reference (Entity (Name (Citem)), Citem);
8263 -- With the pragma present, elaboration calls on
8264 -- subprograms from the named unit need no further
8265 -- checks, as long as the pragma appears in the current
8266 -- compilation unit. If the pragma appears in some unit
8267 -- in the context, there might still be a need for an
8268 -- Elaborate_All_Desirable from the current compilation
8269 -- to the named unit, so we keep the check enabled.
8271 if In_Extended_Main_Source_Unit (N) then
8272 Set_Suppress_Elaboration_Warnings
8273 (Entity (Name (Citem)));
8284 ("argument of pragma% is not with'ed unit", Arg);
8290 -- Give a warning if operating in static mode with -gnatwl
8291 -- (elaboration warnings enabled) switch set.
8293 if Elab_Warnings and not Dynamic_Elaboration_Checks then
8295 ("?use of pragma Elaborate may not be safe", N);
8297 ("?use pragma Elaborate_All instead if possible", N);
8305 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8307 when Pragma_Elaborate_All => Elaborate_All : declare
8312 Check_Ada_83_Warning;
8314 -- Pragma must be in context items list of a compilation unit
8316 if not Is_In_Context_Clause then
8320 -- Must be at least one argument
8322 if Arg_Count = 0 then
8323 Error_Pragma ("pragma% requires at least one argument");
8326 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
8327 -- have to appear at the end of the context clause, but may
8328 -- appear mixed in with other items, even in Ada 83 mode.
8330 -- Final check: the arguments must all be units mentioned in
8331 -- a with clause in the same context clause. Note that we
8332 -- already checked (in Par.Prag) that all the arguments are
8333 -- either identifiers or selected components.
8336 Outr : while Present (Arg) loop
8337 Citem := First (List_Containing (N));
8338 Innr : while Citem /= N loop
8339 if Nkind (Citem) = N_With_Clause
8340 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8342 Set_Elaborate_All_Present (Citem, True);
8343 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8345 -- Suppress warnings and elaboration checks on the named
8346 -- unit if the pragma is in the current compilation, as
8347 -- for pragma Elaborate.
8349 if In_Extended_Main_Source_Unit (N) then
8350 Set_Suppress_Elaboration_Warnings
8351 (Entity (Name (Citem)));
8360 Set_Error_Posted (N);
8362 ("argument of pragma% is not with'ed unit", Arg);
8369 --------------------
8370 -- Elaborate_Body --
8371 --------------------
8373 -- pragma Elaborate_Body [( library_unit_NAME )];
8375 when Pragma_Elaborate_Body => Elaborate_Body : declare
8376 Cunit_Node : Node_Id;
8377 Cunit_Ent : Entity_Id;
8380 Check_Ada_83_Warning;
8381 Check_Valid_Library_Unit_Pragma;
8383 if Nkind (N) = N_Null_Statement then
8387 Cunit_Node := Cunit (Current_Sem_Unit);
8388 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8390 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8393 Error_Pragma ("pragma% must refer to a spec, not a body");
8395 Set_Body_Required (Cunit_Node, True);
8396 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8398 -- If we are in dynamic elaboration mode, then we suppress
8399 -- elaboration warnings for the unit, since it is definitely
8400 -- fine NOT to do dynamic checks at the first level (and such
8401 -- checks will be suppressed because no elaboration boolean
8402 -- is created for Elaborate_Body packages).
8404 -- But in the static model of elaboration, Elaborate_Body is
8405 -- definitely NOT good enough to ensure elaboration safety on
8406 -- its own, since the body may WITH other units that are not
8407 -- safe from an elaboration point of view, so a client must
8408 -- still do an Elaborate_All on such units.
8410 -- Debug flag -gnatdD restores the old behavior of 3.13, where
8411 -- Elaborate_Body always suppressed elab warnings.
8413 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8414 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8419 ------------------------
8420 -- Elaboration_Checks --
8421 ------------------------
8423 -- pragma Elaboration_Checks (Static | Dynamic);
8425 when Pragma_Elaboration_Checks =>
8427 Check_Arg_Count (1);
8428 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8429 Dynamic_Elaboration_Checks :=
8430 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8436 -- pragma Eliminate (
8437 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
8438 -- [,[Entity =>] IDENTIFIER |
8439 -- SELECTED_COMPONENT |
8441 -- [, OVERLOADING_RESOLUTION]);
8443 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8446 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8449 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8451 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8452 -- Result_Type => result_SUBTYPE_NAME]
8454 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8455 -- SUBTYPE_NAME ::= STRING_LITERAL
8457 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8458 -- SOURCE_TRACE ::= STRING_LITERAL
8460 when Pragma_Eliminate => Eliminate : declare
8461 Args : Args_List (1 .. 5);
8462 Names : constant Name_List (1 .. 5) := (
8465 Name_Parameter_Types,
8467 Name_Source_Location);
8469 Unit_Name : Node_Id renames Args (1);
8470 Entity : Node_Id renames Args (2);
8471 Parameter_Types : Node_Id renames Args (3);
8472 Result_Type : Node_Id renames Args (4);
8473 Source_Location : Node_Id renames Args (5);
8477 Check_Valid_Configuration_Pragma;
8478 Gather_Associations (Names, Args);
8480 if No (Unit_Name) then
8481 Error_Pragma ("missing Unit_Name argument for pragma%");
8485 and then (Present (Parameter_Types)
8487 Present (Result_Type)
8489 Present (Source_Location))
8491 Error_Pragma ("missing Entity argument for pragma%");
8494 if (Present (Parameter_Types)
8496 Present (Result_Type))
8498 Present (Source_Location)
8501 ("parameter profile and source location cannot " &
8502 "be used together in pragma%");
8505 Process_Eliminate_Pragma
8514 -----------------------------------
8515 -- Enable_Atomic_Synchronization --
8516 -----------------------------------
8518 -- pragma Enable_Atomic_Synchronization [(Entity)];
8520 when Pragma_Enable_Atomic_Synchronization =>
8521 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
8528 -- [ Convention =>] convention_IDENTIFIER,
8529 -- [ Entity =>] local_NAME
8530 -- [, [External_Name =>] static_string_EXPRESSION ]
8531 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8533 when Pragma_Export => Export : declare
8537 pragma Warnings (Off, C);
8540 Check_Ada_83_Warning;
8546 Check_At_Least_N_Arguments (2);
8547 Check_At_Most_N_Arguments (4);
8548 Process_Convention (C, Def_Id);
8550 if Ekind (Def_Id) /= E_Constant then
8551 Note_Possible_Modification
8552 (Get_Pragma_Arg (Arg2), Sure => False);
8555 Process_Interface_Name (Def_Id, Arg3, Arg4);
8556 Set_Exported (Def_Id, Arg2);
8558 -- If the entity is a deferred constant, propagate the information
8559 -- to the full view, because gigi elaborates the full view only.
8561 if Ekind (Def_Id) = E_Constant
8562 and then Present (Full_View (Def_Id))
8565 Id2 : constant Entity_Id := Full_View (Def_Id);
8567 Set_Is_Exported (Id2, Is_Exported (Def_Id));
8568 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
8569 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8574 ----------------------
8575 -- Export_Exception --
8576 ----------------------
8578 -- pragma Export_Exception (
8579 -- [Internal =>] LOCAL_NAME
8580 -- [, [External =>] EXTERNAL_SYMBOL]
8581 -- [, [Form =>] Ada | VMS]
8582 -- [, [Code =>] static_integer_EXPRESSION]);
8584 when Pragma_Export_Exception => Export_Exception : declare
8585 Args : Args_List (1 .. 4);
8586 Names : constant Name_List (1 .. 4) := (
8592 Internal : Node_Id renames Args (1);
8593 External : Node_Id renames Args (2);
8594 Form : Node_Id renames Args (3);
8595 Code : Node_Id renames Args (4);
8600 if Inside_A_Generic then
8601 Error_Pragma ("pragma% cannot be used for generic entities");
8604 Gather_Associations (Names, Args);
8605 Process_Extended_Import_Export_Exception_Pragma (
8606 Arg_Internal => Internal,
8607 Arg_External => External,
8611 if not Is_VMS_Exception (Entity (Internal)) then
8612 Set_Exported (Entity (Internal), Internal);
8614 end Export_Exception;
8616 ---------------------
8617 -- Export_Function --
8618 ---------------------
8620 -- pragma Export_Function (
8621 -- [Internal =>] LOCAL_NAME
8622 -- [, [External =>] EXTERNAL_SYMBOL]
8623 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8624 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8625 -- [, [Mechanism =>] MECHANISM]
8626 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8628 -- EXTERNAL_SYMBOL ::=
8630 -- | static_string_EXPRESSION
8632 -- PARAMETER_TYPES ::=
8634 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8636 -- TYPE_DESIGNATOR ::=
8638 -- | subtype_Name ' Access
8642 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8644 -- MECHANISM_ASSOCIATION ::=
8645 -- [formal_parameter_NAME =>] MECHANISM_NAME
8647 -- MECHANISM_NAME ::=
8650 -- | Descriptor [([Class =>] CLASS_NAME)]
8652 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8654 when Pragma_Export_Function => Export_Function : declare
8655 Args : Args_List (1 .. 6);
8656 Names : constant Name_List (1 .. 6) := (
8659 Name_Parameter_Types,
8662 Name_Result_Mechanism);
8664 Internal : Node_Id renames Args (1);
8665 External : Node_Id renames Args (2);
8666 Parameter_Types : Node_Id renames Args (3);
8667 Result_Type : Node_Id renames Args (4);
8668 Mechanism : Node_Id renames Args (5);
8669 Result_Mechanism : Node_Id renames Args (6);
8673 Gather_Associations (Names, Args);
8674 Process_Extended_Import_Export_Subprogram_Pragma (
8675 Arg_Internal => Internal,
8676 Arg_External => External,
8677 Arg_Parameter_Types => Parameter_Types,
8678 Arg_Result_Type => Result_Type,
8679 Arg_Mechanism => Mechanism,
8680 Arg_Result_Mechanism => Result_Mechanism);
8681 end Export_Function;
8687 -- pragma Export_Object (
8688 -- [Internal =>] LOCAL_NAME
8689 -- [, [External =>] EXTERNAL_SYMBOL]
8690 -- [, [Size =>] EXTERNAL_SYMBOL]);
8692 -- EXTERNAL_SYMBOL ::=
8694 -- | static_string_EXPRESSION
8696 -- PARAMETER_TYPES ::=
8698 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8700 -- TYPE_DESIGNATOR ::=
8702 -- | subtype_Name ' Access
8706 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8708 -- MECHANISM_ASSOCIATION ::=
8709 -- [formal_parameter_NAME =>] MECHANISM_NAME
8711 -- MECHANISM_NAME ::=
8714 -- | Descriptor [([Class =>] CLASS_NAME)]
8716 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8718 when Pragma_Export_Object => Export_Object : declare
8719 Args : Args_List (1 .. 3);
8720 Names : constant Name_List (1 .. 3) := (
8725 Internal : Node_Id renames Args (1);
8726 External : Node_Id renames Args (2);
8727 Size : Node_Id renames Args (3);
8731 Gather_Associations (Names, Args);
8732 Process_Extended_Import_Export_Object_Pragma (
8733 Arg_Internal => Internal,
8734 Arg_External => External,
8738 ----------------------
8739 -- Export_Procedure --
8740 ----------------------
8742 -- pragma Export_Procedure (
8743 -- [Internal =>] LOCAL_NAME
8744 -- [, [External =>] EXTERNAL_SYMBOL]
8745 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8746 -- [, [Mechanism =>] MECHANISM]);
8748 -- EXTERNAL_SYMBOL ::=
8750 -- | static_string_EXPRESSION
8752 -- PARAMETER_TYPES ::=
8754 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8756 -- TYPE_DESIGNATOR ::=
8758 -- | subtype_Name ' Access
8762 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8764 -- MECHANISM_ASSOCIATION ::=
8765 -- [formal_parameter_NAME =>] MECHANISM_NAME
8767 -- MECHANISM_NAME ::=
8770 -- | Descriptor [([Class =>] CLASS_NAME)]
8772 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8774 when Pragma_Export_Procedure => Export_Procedure : declare
8775 Args : Args_List (1 .. 4);
8776 Names : constant Name_List (1 .. 4) := (
8779 Name_Parameter_Types,
8782 Internal : Node_Id renames Args (1);
8783 External : Node_Id renames Args (2);
8784 Parameter_Types : Node_Id renames Args (3);
8785 Mechanism : Node_Id renames Args (4);
8789 Gather_Associations (Names, Args);
8790 Process_Extended_Import_Export_Subprogram_Pragma (
8791 Arg_Internal => Internal,
8792 Arg_External => External,
8793 Arg_Parameter_Types => Parameter_Types,
8794 Arg_Mechanism => Mechanism);
8795 end Export_Procedure;
8801 -- pragma Export_Value (
8802 -- [Value =>] static_integer_EXPRESSION,
8803 -- [Link_Name =>] static_string_EXPRESSION);
8805 when Pragma_Export_Value =>
8807 Check_Arg_Order ((Name_Value, Name_Link_Name));
8808 Check_Arg_Count (2);
8810 Check_Optional_Identifier (Arg1, Name_Value);
8811 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8813 Check_Optional_Identifier (Arg2, Name_Link_Name);
8814 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8816 -----------------------------
8817 -- Export_Valued_Procedure --
8818 -----------------------------
8820 -- pragma Export_Valued_Procedure (
8821 -- [Internal =>] LOCAL_NAME
8822 -- [, [External =>] EXTERNAL_SYMBOL,]
8823 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8824 -- [, [Mechanism =>] MECHANISM]);
8826 -- EXTERNAL_SYMBOL ::=
8828 -- | static_string_EXPRESSION
8830 -- PARAMETER_TYPES ::=
8832 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8834 -- TYPE_DESIGNATOR ::=
8836 -- | subtype_Name ' Access
8840 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8842 -- MECHANISM_ASSOCIATION ::=
8843 -- [formal_parameter_NAME =>] MECHANISM_NAME
8845 -- MECHANISM_NAME ::=
8848 -- | Descriptor [([Class =>] CLASS_NAME)]
8850 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8852 when Pragma_Export_Valued_Procedure =>
8853 Export_Valued_Procedure : declare
8854 Args : Args_List (1 .. 4);
8855 Names : constant Name_List (1 .. 4) := (
8858 Name_Parameter_Types,
8861 Internal : Node_Id renames Args (1);
8862 External : Node_Id renames Args (2);
8863 Parameter_Types : Node_Id renames Args (3);
8864 Mechanism : Node_Id renames Args (4);
8868 Gather_Associations (Names, Args);
8869 Process_Extended_Import_Export_Subprogram_Pragma (
8870 Arg_Internal => Internal,
8871 Arg_External => External,
8872 Arg_Parameter_Types => Parameter_Types,
8873 Arg_Mechanism => Mechanism);
8874 end Export_Valued_Procedure;
8880 -- pragma Extend_System ([Name =>] Identifier);
8882 when Pragma_Extend_System => Extend_System : declare
8885 Check_Valid_Configuration_Pragma;
8886 Check_Arg_Count (1);
8887 Check_Optional_Identifier (Arg1, Name_Name);
8888 Check_Arg_Is_Identifier (Arg1);
8890 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8893 and then Name_Buffer (1 .. 4) = "aux_"
8895 if Present (System_Extend_Pragma_Arg) then
8896 if Chars (Get_Pragma_Arg (Arg1)) =
8897 Chars (Expression (System_Extend_Pragma_Arg))
8901 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8902 Error_Pragma ("pragma% conflicts with that #");
8906 System_Extend_Pragma_Arg := Arg1;
8908 if not GNAT_Mode then
8909 System_Extend_Unit := Arg1;
8913 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8917 ------------------------
8918 -- Extensions_Allowed --
8919 ------------------------
8921 -- pragma Extensions_Allowed (ON | OFF);
8923 when Pragma_Extensions_Allowed =>
8925 Check_Arg_Count (1);
8926 Check_No_Identifiers;
8927 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8929 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8930 Extensions_Allowed := True;
8931 Ada_Version := Ada_Version_Type'Last;
8934 Extensions_Allowed := False;
8935 Ada_Version := Ada_Version_Explicit;
8942 -- pragma External (
8943 -- [ Convention =>] convention_IDENTIFIER,
8944 -- [ Entity =>] local_NAME
8945 -- [, [External_Name =>] static_string_EXPRESSION ]
8946 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8948 when Pragma_External => External : declare
8952 pragma Warnings (Off, C);
8961 Check_At_Least_N_Arguments (2);
8962 Check_At_Most_N_Arguments (4);
8963 Process_Convention (C, Def_Id);
8964 Note_Possible_Modification
8965 (Get_Pragma_Arg (Arg2), Sure => False);
8966 Process_Interface_Name (Def_Id, Arg3, Arg4);
8967 Set_Exported (Def_Id, Arg2);
8970 --------------------------
8971 -- External_Name_Casing --
8972 --------------------------
8974 -- pragma External_Name_Casing (
8975 -- UPPERCASE | LOWERCASE
8976 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8978 when Pragma_External_Name_Casing => External_Name_Casing : declare
8981 Check_No_Identifiers;
8983 if Arg_Count = 2 then
8985 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8987 case Chars (Get_Pragma_Arg (Arg2)) is
8989 Opt.External_Name_Exp_Casing := As_Is;
8991 when Name_Uppercase =>
8992 Opt.External_Name_Exp_Casing := Uppercase;
8994 when Name_Lowercase =>
8995 Opt.External_Name_Exp_Casing := Lowercase;
9002 Check_Arg_Count (1);
9005 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
9007 case Chars (Get_Pragma_Arg (Arg1)) is
9008 when Name_Uppercase =>
9009 Opt.External_Name_Imp_Casing := Uppercase;
9011 when Name_Lowercase =>
9012 Opt.External_Name_Imp_Casing := Lowercase;
9017 end External_Name_Casing;
9019 --------------------------
9020 -- Favor_Top_Level --
9021 --------------------------
9023 -- pragma Favor_Top_Level (type_NAME);
9025 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
9026 Named_Entity : Entity_Id;
9030 Check_No_Identifiers;
9031 Check_Arg_Count (1);
9032 Check_Arg_Is_Local_Name (Arg1);
9033 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
9035 -- If it's an access-to-subprogram type (in particular, not a
9036 -- subtype), set the flag on that type.
9038 if Is_Access_Subprogram_Type (Named_Entity) then
9039 Set_Can_Use_Internal_Rep (Named_Entity, False);
9041 -- Otherwise it's an error (name denotes the wrong sort of entity)
9045 ("access-to-subprogram type expected",
9046 Get_Pragma_Arg (Arg1));
9048 end Favor_Top_Level;
9054 -- pragma Fast_Math;
9056 when Pragma_Fast_Math =>
9058 Check_No_Identifiers;
9059 Check_Valid_Configuration_Pragma;
9062 ---------------------------
9063 -- Finalize_Storage_Only --
9064 ---------------------------
9066 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9068 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9069 Assoc : constant Node_Id := Arg1;
9070 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9075 Check_No_Identifiers;
9076 Check_Arg_Count (1);
9077 Check_Arg_Is_Local_Name (Arg1);
9079 Find_Type (Type_Id);
9080 Typ := Entity (Type_Id);
9083 or else Rep_Item_Too_Early (Typ, N)
9087 Typ := Underlying_Type (Typ);
9090 if not Is_Controlled (Typ) then
9091 Error_Pragma ("pragma% must specify controlled type");
9094 Check_First_Subtype (Arg1);
9096 if Finalize_Storage_Only (Typ) then
9097 Error_Pragma ("duplicate pragma%, only one allowed");
9099 elsif not Rep_Item_Too_Late (Typ, N) then
9100 Set_Finalize_Storage_Only (Base_Type (Typ), True);
9102 end Finalize_Storage;
9104 --------------------------
9105 -- Float_Representation --
9106 --------------------------
9108 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9110 -- FLOAT_REP ::= VAX_Float | IEEE_Float
9112 when Pragma_Float_Representation => Float_Representation : declare
9120 if Arg_Count = 1 then
9121 Check_Valid_Configuration_Pragma;
9123 Check_Arg_Count (2);
9124 Check_Optional_Identifier (Arg2, Name_Entity);
9125 Check_Arg_Is_Local_Name (Arg2);
9128 Check_No_Identifier (Arg1);
9129 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9131 if not OpenVMS_On_Target then
9132 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9134 ("?pragma% ignored (applies only to Open'V'M'S)");
9140 -- One argument case
9142 if Arg_Count = 1 then
9143 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9144 if Opt.Float_Format = 'I' then
9145 Error_Pragma ("'I'E'E'E format previously specified");
9148 Opt.Float_Format := 'V';
9151 if Opt.Float_Format = 'V' then
9152 Error_Pragma ("'V'A'X format previously specified");
9155 Opt.Float_Format := 'I';
9158 Set_Standard_Fpt_Formats;
9160 -- Two argument case
9163 Argx := Get_Pragma_Arg (Arg2);
9165 if not Is_Entity_Name (Argx)
9166 or else not Is_Floating_Point_Type (Entity (Argx))
9169 ("second argument of% pragma must be floating-point type",
9173 Ent := Entity (Argx);
9174 Digs := UI_To_Int (Digits_Value (Ent));
9176 -- Two arguments, VAX_Float case
9178 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9180 when 6 => Set_F_Float (Ent);
9181 when 9 => Set_D_Float (Ent);
9182 when 15 => Set_G_Float (Ent);
9186 ("wrong digits value, must be 6,9 or 15", Arg2);
9189 -- Two arguments, IEEE_Float case
9193 when 6 => Set_IEEE_Short (Ent);
9194 when 15 => Set_IEEE_Long (Ent);
9198 ("wrong digits value, must be 6 or 15", Arg2);
9202 end Float_Representation;
9208 -- pragma Ident (static_string_EXPRESSION)
9210 -- Note: pragma Comment shares this processing. Pragma Comment is
9211 -- identical to Ident, except that the restriction of the argument to
9212 -- 31 characters and the placement restrictions are not enforced for
9215 when Pragma_Ident | Pragma_Comment => Ident : declare
9220 Check_Arg_Count (1);
9221 Check_No_Identifiers;
9222 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9225 -- For pragma Ident, preserve DEC compatibility by requiring the
9226 -- pragma to appear in a declarative part or package spec.
9228 if Prag_Id = Pragma_Ident then
9229 Check_Is_In_Decl_Part_Or_Package_Spec;
9232 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9239 GP := Parent (Parent (N));
9241 if Nkind_In (GP, N_Package_Declaration,
9242 N_Generic_Package_Declaration)
9247 -- If we have a compilation unit, then record the ident value,
9248 -- checking for improper duplication.
9250 if Nkind (GP) = N_Compilation_Unit then
9251 CS := Ident_String (Current_Sem_Unit);
9253 if Present (CS) then
9255 -- For Ident, we do not permit multiple instances
9257 if Prag_Id = Pragma_Ident then
9258 Error_Pragma ("duplicate% pragma not permitted");
9260 -- For Comment, we concatenate the string, unless we want
9261 -- to preserve the tree structure for ASIS.
9263 elsif not ASIS_Mode then
9264 Start_String (Strval (CS));
9265 Store_String_Char (' ');
9266 Store_String_Chars (Strval (Str));
9267 Set_Strval (CS, End_String);
9271 -- In VMS, the effect of IDENT is achieved by passing
9272 -- --identification=name as a --for-linker switch.
9274 if OpenVMS_On_Target then
9277 ("--for-linker=--identification=");
9278 String_To_Name_Buffer (Strval (Str));
9279 Store_String_Chars (Name_Buffer (1 .. Name_Len));
9281 -- Only the last processed IDENT is saved. The main
9282 -- purpose is so an IDENT associated with a main
9283 -- procedure will be used in preference to an IDENT
9284 -- associated with a with'd package.
9286 Replace_Linker_Option_String
9287 (End_String, "--for-linker=--identification=");
9290 Set_Ident_String (Current_Sem_Unit, Str);
9293 -- For subunits, we just ignore the Ident, since in GNAT these
9294 -- are not separate object files, and hence not separate units
9295 -- in the unit table.
9297 elsif Nkind (GP) = N_Subunit then
9300 -- Otherwise we have a misplaced pragma Ident, but we ignore
9301 -- this if we are in an instantiation, since it comes from
9302 -- a generic, and has no relevance to the instantiation.
9304 elsif Prag_Id = Pragma_Ident then
9305 if Instantiation_Location (Loc) = No_Location then
9306 Error_Pragma ("pragma% only allowed at outer level");
9312 ----------------------------
9313 -- Implementation_Defined --
9314 ----------------------------
9316 -- pragma Implementation_Defined (local_NAME);
9318 -- Marks previously declared entity as implementation defined. For
9319 -- an overloaded entity, applies to the most recent homonym.
9321 -- pragma Implementation_Defined;
9323 -- The form with no arguments appears anywhere within a scope, most
9324 -- typically a package spec, and indicates that all entities that are
9325 -- defined within the package spec are Implementation_Defined.
9327 when Pragma_Implementation_Defined => Implementation_Defined : declare
9331 Check_No_Identifiers;
9333 -- Form with no arguments
9335 if Arg_Count = 0 then
9336 Set_Is_Implementation_Defined (Current_Scope);
9338 -- Form with one argument
9341 Check_Arg_Count (1);
9342 Check_Arg_Is_Local_Name (Arg1);
9343 Ent := Entity (Get_Pragma_Arg (Arg1));
9344 Set_Is_Implementation_Defined (Ent);
9346 end Implementation_Defined;
9352 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9353 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
9355 when Pragma_Implemented => Implemented : declare
9356 Proc_Id : Entity_Id;
9361 Check_Arg_Count (2);
9362 Check_No_Identifiers;
9363 Check_Arg_Is_Identifier (Arg1);
9364 Check_Arg_Is_Local_Name (Arg1);
9366 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
9368 -- Extract the name of the local procedure
9370 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9372 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9373 -- primitive procedure of a synchronized tagged type.
9375 if Ekind (Proc_Id) = E_Procedure
9376 and then Is_Primitive (Proc_Id)
9377 and then Present (First_Formal (Proc_Id))
9379 Typ := Etype (First_Formal (Proc_Id));
9381 if Is_Tagged_Type (Typ)
9384 -- Check for a protected, a synchronized or a task interface
9386 ((Is_Interface (Typ)
9387 and then Is_Synchronized_Interface (Typ))
9389 -- Check for a protected type or a task type that implements
9393 (Is_Concurrent_Record_Type (Typ)
9394 and then Present (Interfaces (Typ)))
9396 -- Check for a private record extension with keyword
9400 (Ekind_In (Typ, E_Record_Type_With_Private,
9401 E_Record_Subtype_With_Private)
9402 and then Synchronized_Present (Parent (Typ))))
9407 ("controlling formal must be of synchronized " &
9408 "tagged type", Arg1);
9412 -- Procedures declared inside a protected type must be accepted
9414 elsif Ekind (Proc_Id) = E_Procedure
9415 and then Is_Protected_Type (Scope (Proc_Id))
9419 -- The first argument is not a primitive procedure
9423 ("pragma % must be applied to a primitive procedure", Arg1);
9427 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9428 -- By_Protected_Procedure to the primitive procedure of a task
9431 if Chars (Arg2) = Name_By_Protected_Procedure
9432 and then Is_Interface (Typ)
9433 and then Is_Task_Interface (Typ)
9436 ("implementation kind By_Protected_Procedure cannot be " &
9437 "applied to a task interface primitive", Arg2);
9441 Record_Rep_Item (Proc_Id, N);
9444 ----------------------
9445 -- Implicit_Packing --
9446 ----------------------
9448 -- pragma Implicit_Packing;
9450 when Pragma_Implicit_Packing =>
9452 Check_Arg_Count (0);
9453 Implicit_Packing := True;
9460 -- [Convention =>] convention_IDENTIFIER,
9461 -- [Entity =>] local_NAME
9462 -- [, [External_Name =>] static_string_EXPRESSION ]
9463 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9465 when Pragma_Import =>
9466 Check_Ada_83_Warning;
9472 Check_At_Least_N_Arguments (2);
9473 Check_At_Most_N_Arguments (4);
9474 Process_Import_Or_Interface;
9476 ----------------------
9477 -- Import_Exception --
9478 ----------------------
9480 -- pragma Import_Exception (
9481 -- [Internal =>] LOCAL_NAME
9482 -- [, [External =>] EXTERNAL_SYMBOL]
9483 -- [, [Form =>] Ada | VMS]
9484 -- [, [Code =>] static_integer_EXPRESSION]);
9486 when Pragma_Import_Exception => Import_Exception : declare
9487 Args : Args_List (1 .. 4);
9488 Names : constant Name_List (1 .. 4) := (
9494 Internal : Node_Id renames Args (1);
9495 External : Node_Id renames Args (2);
9496 Form : Node_Id renames Args (3);
9497 Code : Node_Id renames Args (4);
9501 Gather_Associations (Names, Args);
9503 if Present (External) and then Present (Code) then
9505 ("cannot give both External and Code options for pragma%");
9508 Process_Extended_Import_Export_Exception_Pragma (
9509 Arg_Internal => Internal,
9510 Arg_External => External,
9514 if not Is_VMS_Exception (Entity (Internal)) then
9515 Set_Imported (Entity (Internal));
9517 end Import_Exception;
9519 ---------------------
9520 -- Import_Function --
9521 ---------------------
9523 -- pragma Import_Function (
9524 -- [Internal =>] LOCAL_NAME,
9525 -- [, [External =>] EXTERNAL_SYMBOL]
9526 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9527 -- [, [Result_Type =>] SUBTYPE_MARK]
9528 -- [, [Mechanism =>] MECHANISM]
9529 -- [, [Result_Mechanism =>] MECHANISM_NAME]
9530 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9532 -- EXTERNAL_SYMBOL ::=
9534 -- | static_string_EXPRESSION
9536 -- PARAMETER_TYPES ::=
9538 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9540 -- TYPE_DESIGNATOR ::=
9542 -- | subtype_Name ' Access
9546 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9548 -- MECHANISM_ASSOCIATION ::=
9549 -- [formal_parameter_NAME =>] MECHANISM_NAME
9551 -- MECHANISM_NAME ::=
9554 -- | Descriptor [([Class =>] CLASS_NAME)]
9556 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9558 when Pragma_Import_Function => Import_Function : declare
9559 Args : Args_List (1 .. 7);
9560 Names : constant Name_List (1 .. 7) := (
9563 Name_Parameter_Types,
9566 Name_Result_Mechanism,
9567 Name_First_Optional_Parameter);
9569 Internal : Node_Id renames Args (1);
9570 External : Node_Id renames Args (2);
9571 Parameter_Types : Node_Id renames Args (3);
9572 Result_Type : Node_Id renames Args (4);
9573 Mechanism : Node_Id renames Args (5);
9574 Result_Mechanism : Node_Id renames Args (6);
9575 First_Optional_Parameter : Node_Id renames Args (7);
9579 Gather_Associations (Names, Args);
9580 Process_Extended_Import_Export_Subprogram_Pragma (
9581 Arg_Internal => Internal,
9582 Arg_External => External,
9583 Arg_Parameter_Types => Parameter_Types,
9584 Arg_Result_Type => Result_Type,
9585 Arg_Mechanism => Mechanism,
9586 Arg_Result_Mechanism => Result_Mechanism,
9587 Arg_First_Optional_Parameter => First_Optional_Parameter);
9588 end Import_Function;
9594 -- pragma Import_Object (
9595 -- [Internal =>] LOCAL_NAME
9596 -- [, [External =>] EXTERNAL_SYMBOL]
9597 -- [, [Size =>] EXTERNAL_SYMBOL]);
9599 -- EXTERNAL_SYMBOL ::=
9601 -- | static_string_EXPRESSION
9603 when Pragma_Import_Object => Import_Object : declare
9604 Args : Args_List (1 .. 3);
9605 Names : constant Name_List (1 .. 3) := (
9610 Internal : Node_Id renames Args (1);
9611 External : Node_Id renames Args (2);
9612 Size : Node_Id renames Args (3);
9616 Gather_Associations (Names, Args);
9617 Process_Extended_Import_Export_Object_Pragma (
9618 Arg_Internal => Internal,
9619 Arg_External => External,
9623 ----------------------
9624 -- Import_Procedure --
9625 ----------------------
9627 -- pragma Import_Procedure (
9628 -- [Internal =>] LOCAL_NAME
9629 -- [, [External =>] EXTERNAL_SYMBOL]
9630 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9631 -- [, [Mechanism =>] MECHANISM]
9632 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9634 -- EXTERNAL_SYMBOL ::=
9636 -- | static_string_EXPRESSION
9638 -- PARAMETER_TYPES ::=
9640 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9642 -- TYPE_DESIGNATOR ::=
9644 -- | subtype_Name ' Access
9648 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9650 -- MECHANISM_ASSOCIATION ::=
9651 -- [formal_parameter_NAME =>] MECHANISM_NAME
9653 -- MECHANISM_NAME ::=
9656 -- | Descriptor [([Class =>] CLASS_NAME)]
9658 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9660 when Pragma_Import_Procedure => Import_Procedure : declare
9661 Args : Args_List (1 .. 5);
9662 Names : constant Name_List (1 .. 5) := (
9665 Name_Parameter_Types,
9667 Name_First_Optional_Parameter);
9669 Internal : Node_Id renames Args (1);
9670 External : Node_Id renames Args (2);
9671 Parameter_Types : Node_Id renames Args (3);
9672 Mechanism : Node_Id renames Args (4);
9673 First_Optional_Parameter : Node_Id renames Args (5);
9677 Gather_Associations (Names, Args);
9678 Process_Extended_Import_Export_Subprogram_Pragma (
9679 Arg_Internal => Internal,
9680 Arg_External => External,
9681 Arg_Parameter_Types => Parameter_Types,
9682 Arg_Mechanism => Mechanism,
9683 Arg_First_Optional_Parameter => First_Optional_Parameter);
9684 end Import_Procedure;
9686 -----------------------------
9687 -- Import_Valued_Procedure --
9688 -----------------------------
9690 -- pragma Import_Valued_Procedure (
9691 -- [Internal =>] LOCAL_NAME
9692 -- [, [External =>] EXTERNAL_SYMBOL]
9693 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9694 -- [, [Mechanism =>] MECHANISM]
9695 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9697 -- EXTERNAL_SYMBOL ::=
9699 -- | static_string_EXPRESSION
9701 -- PARAMETER_TYPES ::=
9703 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9705 -- TYPE_DESIGNATOR ::=
9707 -- | subtype_Name ' Access
9711 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9713 -- MECHANISM_ASSOCIATION ::=
9714 -- [formal_parameter_NAME =>] MECHANISM_NAME
9716 -- MECHANISM_NAME ::=
9719 -- | Descriptor [([Class =>] CLASS_NAME)]
9721 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9723 when Pragma_Import_Valued_Procedure =>
9724 Import_Valued_Procedure : declare
9725 Args : Args_List (1 .. 5);
9726 Names : constant Name_List (1 .. 5) := (
9729 Name_Parameter_Types,
9731 Name_First_Optional_Parameter);
9733 Internal : Node_Id renames Args (1);
9734 External : Node_Id renames Args (2);
9735 Parameter_Types : Node_Id renames Args (3);
9736 Mechanism : Node_Id renames Args (4);
9737 First_Optional_Parameter : Node_Id renames Args (5);
9741 Gather_Associations (Names, Args);
9742 Process_Extended_Import_Export_Subprogram_Pragma (
9743 Arg_Internal => Internal,
9744 Arg_External => External,
9745 Arg_Parameter_Types => Parameter_Types,
9746 Arg_Mechanism => Mechanism,
9747 Arg_First_Optional_Parameter => First_Optional_Parameter);
9748 end Import_Valued_Procedure;
9754 -- pragma Independent (LOCAL_NAME);
9756 when Pragma_Independent => Independent : declare
9763 Check_Ada_83_Warning;
9765 Check_No_Identifiers;
9766 Check_Arg_Count (1);
9767 Check_Arg_Is_Local_Name (Arg1);
9768 E_Id := Get_Pragma_Arg (Arg1);
9770 if Etype (E_Id) = Any_Type then
9775 D := Declaration_Node (E);
9778 -- Check duplicate before we chain ourselves!
9780 Check_Duplicate_Pragma (E);
9782 -- Check appropriate entity
9785 if Rep_Item_Too_Early (E, N)
9787 Rep_Item_Too_Late (E, N)
9791 Check_First_Subtype (Arg1);
9794 elsif K = N_Object_Declaration
9795 or else (K = N_Component_Declaration
9796 and then Original_Record_Component (E) = E)
9798 if Rep_Item_Too_Late (E, N) then
9804 ("inappropriate entity for pragma%", Arg1);
9807 Independence_Checks.Append ((N, E));
9810 ----------------------------
9811 -- Independent_Components --
9812 ----------------------------
9814 -- pragma Atomic_Components (array_LOCAL_NAME);
9816 -- This processing is shared by Volatile_Components
9818 when Pragma_Independent_Components => Independent_Components : declare
9825 Check_Ada_83_Warning;
9827 Check_No_Identifiers;
9828 Check_Arg_Count (1);
9829 Check_Arg_Is_Local_Name (Arg1);
9830 E_Id := Get_Pragma_Arg (Arg1);
9832 if Etype (E_Id) = Any_Type then
9838 -- Check duplicate before we chain ourselves!
9840 Check_Duplicate_Pragma (E);
9842 -- Check appropriate entity
9844 if Rep_Item_Too_Early (E, N)
9846 Rep_Item_Too_Late (E, N)
9851 D := Declaration_Node (E);
9854 if (K = N_Full_Type_Declaration
9855 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9857 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9858 and then Nkind (D) = N_Object_Declaration
9859 and then Nkind (Object_Definition (D)) =
9860 N_Constrained_Array_Definition)
9862 Independence_Checks.Append ((N, E));
9865 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9867 end Independent_Components;
9869 ------------------------
9870 -- Initialize_Scalars --
9871 ------------------------
9873 -- pragma Initialize_Scalars;
9875 when Pragma_Initialize_Scalars =>
9877 Check_Arg_Count (0);
9878 Check_Valid_Configuration_Pragma;
9879 Check_Restriction (No_Initialize_Scalars, N);
9881 -- Initialize_Scalars creates false positives in CodePeer, and
9882 -- incorrect negative results in Alfa mode, so ignore this pragma
9885 if not Restriction_Active (No_Initialize_Scalars)
9886 and then not (CodePeer_Mode or Alfa_Mode)
9888 Init_Or_Norm_Scalars := True;
9889 Initialize_Scalars := True;
9896 -- pragma Inline ( NAME {, NAME} );
9898 when Pragma_Inline =>
9900 -- Pragma is active if inlining option is active
9902 Process_Inline (Inline_Active);
9908 -- pragma Inline_Always ( NAME {, NAME} );
9910 when Pragma_Inline_Always =>
9913 -- Pragma always active unless in CodePeer or Alfa mode, since
9914 -- this causes walk order issues.
9916 if not (CodePeer_Mode or Alfa_Mode) then
9917 Process_Inline (True);
9920 --------------------
9921 -- Inline_Generic --
9922 --------------------
9924 -- pragma Inline_Generic (NAME {, NAME});
9926 when Pragma_Inline_Generic =>
9928 Process_Generic_List;
9930 ----------------------
9931 -- Inspection_Point --
9932 ----------------------
9934 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9936 when Pragma_Inspection_Point => Inspection_Point : declare
9941 if Arg_Count > 0 then
9944 Exp := Get_Pragma_Arg (Arg);
9947 if not Is_Entity_Name (Exp)
9948 or else not Is_Object (Entity (Exp))
9950 Error_Pragma_Arg ("object name required", Arg);
9957 end Inspection_Point;
9963 -- pragma Interface (
9964 -- [ Convention =>] convention_IDENTIFIER,
9965 -- [ Entity =>] local_NAME
9966 -- [, [External_Name =>] static_string_EXPRESSION ]
9967 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9969 when Pragma_Interface =>
9976 Check_At_Least_N_Arguments (2);
9977 Check_At_Most_N_Arguments (4);
9978 Process_Import_Or_Interface;
9980 -- In Ada 2005, the permission to use Interface (a reserved word)
9981 -- as a pragma name is considered an obsolescent feature.
9983 if Ada_Version >= Ada_2005 then
9985 (No_Obsolescent_Features, Pragma_Identifier (N));
9988 --------------------
9989 -- Interface_Name --
9990 --------------------
9992 -- pragma Interface_Name (
9993 -- [ Entity =>] local_NAME
9994 -- [,[External_Name =>] static_string_EXPRESSION ]
9995 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9997 when Pragma_Interface_Name => Interface_Name : declare
10000 Hom_Id : Entity_Id;
10006 ((Name_Entity, Name_External_Name, Name_Link_Name));
10007 Check_At_Least_N_Arguments (2);
10008 Check_At_Most_N_Arguments (3);
10009 Id := Get_Pragma_Arg (Arg1);
10012 if not Is_Entity_Name (Id) then
10014 ("first argument for pragma% must be entity name", Arg1);
10015 elsif Etype (Id) = Any_Type then
10018 Def_Id := Entity (Id);
10021 -- Special DEC-compatible processing for the object case, forces
10022 -- object to be imported.
10024 if Ekind (Def_Id) = E_Variable then
10025 Kill_Size_Check_Code (Def_Id);
10026 Note_Possible_Modification (Id, Sure => False);
10028 -- Initialization is not allowed for imported variable
10030 if Present (Expression (Parent (Def_Id)))
10031 and then Comes_From_Source (Expression (Parent (Def_Id)))
10033 Error_Msg_Sloc := Sloc (Def_Id);
10035 ("no initialization allowed for declaration of& #",
10039 -- For compatibility, support VADS usage of providing both
10040 -- pragmas Interface and Interface_Name to obtain the effect
10041 -- of a single Import pragma.
10043 if Is_Imported (Def_Id)
10044 and then Present (First_Rep_Item (Def_Id))
10045 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
10047 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
10051 Set_Imported (Def_Id);
10054 Set_Is_Public (Def_Id);
10055 Process_Interface_Name (Def_Id, Arg2, Arg3);
10058 -- Otherwise must be subprogram
10060 elsif not Is_Subprogram (Def_Id) then
10062 ("argument of pragma% is not subprogram", Arg1);
10065 Check_At_Most_N_Arguments (3);
10069 -- Loop through homonyms
10072 Def_Id := Get_Base_Subprogram (Hom_Id);
10074 if Is_Imported (Def_Id) then
10075 Process_Interface_Name (Def_Id, Arg2, Arg3);
10079 exit when From_Aspect_Specification (N);
10080 Hom_Id := Homonym (Hom_Id);
10082 exit when No (Hom_Id)
10083 or else Scope (Hom_Id) /= Current_Scope;
10088 ("argument of pragma% is not imported subprogram",
10092 end Interface_Name;
10094 -----------------------
10095 -- Interrupt_Handler --
10096 -----------------------
10098 -- pragma Interrupt_Handler (handler_NAME);
10100 when Pragma_Interrupt_Handler =>
10101 Check_Ada_83_Warning;
10102 Check_Arg_Count (1);
10103 Check_No_Identifiers;
10105 if No_Run_Time_Mode then
10106 Error_Msg_CRT ("Interrupt_Handler pragma", N);
10108 Check_Interrupt_Or_Attach_Handler;
10109 Process_Interrupt_Or_Attach_Handler;
10112 ------------------------
10113 -- Interrupt_Priority --
10114 ------------------------
10116 -- pragma Interrupt_Priority [(EXPRESSION)];
10118 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
10119 P : constant Node_Id := Parent (N);
10123 Check_Ada_83_Warning;
10125 if Arg_Count /= 0 then
10126 Arg := Get_Pragma_Arg (Arg1);
10127 Check_Arg_Count (1);
10128 Check_No_Identifiers;
10130 -- The expression must be analyzed in the special manner
10131 -- described in "Handling of Default and Per-Object
10132 -- Expressions" in sem.ads.
10134 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
10137 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
10141 elsif Has_Pragma_Priority (P) then
10142 Error_Pragma ("duplicate pragma% not allowed");
10145 Set_Has_Pragma_Priority (P, True);
10146 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10148 end Interrupt_Priority;
10150 ---------------------
10151 -- Interrupt_State --
10152 ---------------------
10154 -- pragma Interrupt_State (
10155 -- [Name =>] INTERRUPT_ID,
10156 -- [State =>] INTERRUPT_STATE);
10158 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
10159 -- INTERRUPT_STATE => System | Runtime | User
10161 -- Note: if the interrupt id is given as an identifier, then it must
10162 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
10163 -- given as a static integer expression which must be in the range of
10164 -- Ada.Interrupts.Interrupt_ID.
10166 when Pragma_Interrupt_State => Interrupt_State : declare
10168 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
10169 -- This is the entity Ada.Interrupts.Interrupt_ID;
10171 State_Type : Character;
10172 -- Set to 's'/'r'/'u' for System/Runtime/User
10175 -- Index to entry in Interrupt_States table
10178 -- Value of interrupt
10180 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
10181 -- The first argument to the pragma
10183 Int_Ent : Entity_Id;
10184 -- Interrupt entity in Ada.Interrupts.Names
10188 Check_Arg_Order ((Name_Name, Name_State));
10189 Check_Arg_Count (2);
10191 Check_Optional_Identifier (Arg1, Name_Name);
10192 Check_Optional_Identifier (Arg2, Name_State);
10193 Check_Arg_Is_Identifier (Arg2);
10195 -- First argument is identifier
10197 if Nkind (Arg1X) = N_Identifier then
10199 -- Search list of names in Ada.Interrupts.Names
10201 Int_Ent := First_Entity (RTE (RE_Names));
10203 if No (Int_Ent) then
10204 Error_Pragma_Arg ("invalid interrupt name", Arg1);
10206 elsif Chars (Int_Ent) = Chars (Arg1X) then
10207 Int_Val := Expr_Value (Constant_Value (Int_Ent));
10211 Next_Entity (Int_Ent);
10214 -- First argument is not an identifier, so it must be a static
10215 -- expression of type Ada.Interrupts.Interrupt_ID.
10218 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10219 Int_Val := Expr_Value (Arg1X);
10221 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
10223 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10226 ("value not in range of type " &
10227 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10233 case Chars (Get_Pragma_Arg (Arg2)) is
10234 when Name_Runtime => State_Type := 'r';
10235 when Name_System => State_Type := 's';
10236 when Name_User => State_Type := 'u';
10239 Error_Pragma_Arg ("invalid interrupt state", Arg2);
10242 -- Check if entry is already stored
10244 IST_Num := Interrupt_States.First;
10246 -- If entry not found, add it
10248 if IST_Num > Interrupt_States.Last then
10249 Interrupt_States.Append
10250 ((Interrupt_Number => UI_To_Int (Int_Val),
10251 Interrupt_State => State_Type,
10252 Pragma_Loc => Loc));
10255 -- Case of entry for the same entry
10257 elsif Int_Val = Interrupt_States.Table (IST_Num).
10260 -- If state matches, done, no need to make redundant entry
10263 State_Type = Interrupt_States.Table (IST_Num).
10266 -- Otherwise if state does not match, error
10269 Interrupt_States.Table (IST_Num).Pragma_Loc;
10271 ("state conflicts with that given #", Arg2);
10275 IST_Num := IST_Num + 1;
10277 end Interrupt_State;
10283 -- pragma Invariant
10284 -- ([Entity =>] type_LOCAL_NAME,
10285 -- [Check =>] EXPRESSION
10286 -- [,[Message =>] String_Expression]);
10288 when Pragma_Invariant => Invariant : declare
10293 pragma Unreferenced (Discard);
10297 Check_At_Least_N_Arguments (2);
10298 Check_At_Most_N_Arguments (3);
10299 Check_Optional_Identifier (Arg1, Name_Entity);
10300 Check_Optional_Identifier (Arg2, Name_Check);
10302 if Arg_Count = 3 then
10303 Check_Optional_Identifier (Arg3, Name_Message);
10304 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10307 Check_Arg_Is_Local_Name (Arg1);
10309 Type_Id := Get_Pragma_Arg (Arg1);
10310 Find_Type (Type_Id);
10311 Typ := Entity (Type_Id);
10313 if Typ = Any_Type then
10316 -- An invariant must apply to a private type, or appear in the
10317 -- private part of a package spec and apply to a completion.
10319 elsif Ekind_In (Typ, E_Private_Type,
10320 E_Record_Type_With_Private,
10321 E_Limited_Private_Type)
10325 elsif In_Private_Part (Current_Scope)
10326 and then Has_Private_Declaration (Typ)
10330 elsif In_Private_Part (Current_Scope) then
10332 ("pragma% only allowed for private type " &
10333 "declared in visible part", Arg1);
10337 ("pragma% only allowed for private type", Arg1);
10340 -- Note that the type has at least one invariant, and also that
10341 -- it has inheritable invariants if we have Invariant'Class.
10343 Set_Has_Invariants (Typ);
10345 if Class_Present (N) then
10346 Set_Has_Inheritable_Invariants (Typ);
10349 -- The remaining processing is simply to link the pragma on to
10350 -- the rep item chain, for processing when the type is frozen.
10351 -- This is accomplished by a call to Rep_Item_Too_Late.
10353 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10356 ----------------------
10357 -- Java_Constructor --
10358 ----------------------
10360 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10362 -- Also handles pragma CIL_Constructor
10364 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10365 Java_Constructor : declare
10366 Convention : Convention_Id;
10367 Def_Id : Entity_Id;
10368 Hom_Id : Entity_Id;
10370 This_Formal : Entity_Id;
10374 Check_Arg_Count (1);
10375 Check_Optional_Identifier (Arg1, Name_Entity);
10376 Check_Arg_Is_Local_Name (Arg1);
10378 Id := Get_Pragma_Arg (Arg1);
10379 Find_Program_Unit_Name (Id);
10381 -- If we did not find the name, we are done
10383 if Etype (Id) = Any_Type then
10387 -- Check wrong use of pragma in wrong VM target
10389 if VM_Target = No_VM then
10392 elsif VM_Target = CLI_Target
10393 and then Prag_Id = Pragma_Java_Constructor
10395 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10397 elsif VM_Target = JVM_Target
10398 and then Prag_Id = Pragma_CIL_Constructor
10400 Error_Pragma ("must use pragma 'Java_'Constructor");
10404 when Pragma_CIL_Constructor => Convention := Convention_CIL;
10405 when Pragma_Java_Constructor => Convention := Convention_Java;
10406 when others => null;
10409 Hom_Id := Entity (Id);
10411 -- Loop through homonyms
10414 Def_Id := Get_Base_Subprogram (Hom_Id);
10416 -- The constructor is required to be a function
10418 if Ekind (Def_Id) /= E_Function then
10419 if VM_Target = JVM_Target then
10421 ("pragma% requires function returning a " &
10422 "'Java access type", Def_Id);
10425 ("pragma% requires function returning a " &
10426 "'C'I'L access type", Def_Id);
10430 -- Check arguments: For tagged type the first formal must be
10431 -- named "this" and its type must be a named access type
10432 -- designating a class-wide tagged type that has convention
10433 -- CIL/Java. The first formal must also have a null default
10434 -- value. For example:
10436 -- type Typ is tagged ...
10437 -- type Ref is access all Typ;
10438 -- pragma Convention (CIL, Typ);
10440 -- function New_Typ (This : Ref) return Ref;
10441 -- function New_Typ (This : Ref; I : Integer) return Ref;
10442 -- pragma Cil_Constructor (New_Typ);
10444 -- Reason: The first formal must NOT be a primitive of the
10447 -- This rule also applies to constructors of delegates used
10448 -- to interface with standard target libraries. For example:
10450 -- type Delegate is access procedure ...
10451 -- pragma Import (CIL, Delegate, ...);
10453 -- function new_Delegate
10454 -- (This : Delegate := null; ... ) return Delegate;
10456 -- For value-types this rule does not apply.
10458 if not Is_Value_Type (Etype (Def_Id)) then
10459 if No (First_Formal (Def_Id)) then
10460 Error_Msg_Name_1 := Pname;
10461 Error_Msg_N ("% function must have parameters", Def_Id);
10465 -- In the JRE library we have several occurrences in which
10466 -- the "this" parameter is not the first formal.
10468 This_Formal := First_Formal (Def_Id);
10470 -- In the JRE library we have several occurrences in which
10471 -- the "this" parameter is not the first formal. Search for
10474 if VM_Target = JVM_Target then
10475 while Present (This_Formal)
10476 and then Get_Name_String (Chars (This_Formal)) /= "this"
10478 Next_Formal (This_Formal);
10481 if No (This_Formal) then
10482 This_Formal := First_Formal (Def_Id);
10486 -- Warning: The first parameter should be named "this".
10487 -- We temporarily allow it because we have the following
10488 -- case in the Java runtime (file s-osinte.ads) ???
10490 -- function new_Thread
10491 -- (Self_Id : System.Address) return Thread_Id;
10492 -- pragma Java_Constructor (new_Thread);
10494 if VM_Target = JVM_Target
10495 and then Get_Name_String (Chars (First_Formal (Def_Id)))
10497 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10501 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10502 Error_Msg_Name_1 := Pname;
10504 ("first formal of % function must be named `this`",
10505 Parent (This_Formal));
10507 elsif not Is_Access_Type (Etype (This_Formal)) then
10508 Error_Msg_Name_1 := Pname;
10510 ("first formal of % function must be an access type",
10511 Parameter_Type (Parent (This_Formal)));
10513 -- For delegates the type of the first formal must be a
10514 -- named access-to-subprogram type (see previous example)
10516 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10517 and then Ekind (Etype (This_Formal))
10518 /= E_Access_Subprogram_Type
10520 Error_Msg_Name_1 := Pname;
10522 ("first formal of % function must be a named access" &
10523 " to subprogram type",
10524 Parameter_Type (Parent (This_Formal)));
10526 -- Warning: We should reject anonymous access types because
10527 -- the constructor must not be handled as a primitive of the
10528 -- tagged type. We temporarily allow it because this profile
10529 -- is currently generated by cil2ada???
10531 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10532 and then not Ekind_In (Etype (This_Formal),
10534 E_General_Access_Type,
10535 E_Anonymous_Access_Type)
10537 Error_Msg_Name_1 := Pname;
10539 ("first formal of % function must be a named access" &
10541 Parameter_Type (Parent (This_Formal)));
10543 elsif Atree.Convention
10544 (Designated_Type (Etype (This_Formal))) /= Convention
10546 Error_Msg_Name_1 := Pname;
10548 if Convention = Convention_Java then
10550 ("pragma% requires convention 'Cil in designated" &
10552 Parameter_Type (Parent (This_Formal)));
10555 ("pragma% requires convention 'Java in designated" &
10557 Parameter_Type (Parent (This_Formal)));
10560 elsif No (Expression (Parent (This_Formal)))
10561 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10563 Error_Msg_Name_1 := Pname;
10565 ("pragma% requires first formal with default `null`",
10566 Parameter_Type (Parent (This_Formal)));
10570 -- Check result type: the constructor must be a function
10572 -- * a value type (only allowed in the CIL compiler)
10573 -- * an access-to-subprogram type with convention Java/CIL
10574 -- * an access-type designating a type that has convention
10577 if Is_Value_Type (Etype (Def_Id)) then
10580 -- Access-to-subprogram type with convention Java/CIL
10582 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10583 if Atree.Convention (Etype (Def_Id)) /= Convention then
10584 if Convention = Convention_Java then
10586 ("pragma% requires function returning a " &
10587 "'Java access type", Arg1);
10589 pragma Assert (Convention = Convention_CIL);
10591 ("pragma% requires function returning a " &
10592 "'C'I'L access type", Arg1);
10596 elsif Ekind (Etype (Def_Id)) in Access_Kind then
10597 if not Ekind_In (Etype (Def_Id), E_Access_Type,
10598 E_General_Access_Type)
10601 (Designated_Type (Etype (Def_Id))) /= Convention
10603 Error_Msg_Name_1 := Pname;
10605 if Convention = Convention_Java then
10607 ("pragma% requires function returning a named" &
10608 "'Java access type", Arg1);
10611 ("pragma% requires function returning a named" &
10612 "'C'I'L access type", Arg1);
10617 Set_Is_Constructor (Def_Id);
10618 Set_Convention (Def_Id, Convention);
10619 Set_Is_Imported (Def_Id);
10621 exit when From_Aspect_Specification (N);
10622 Hom_Id := Homonym (Hom_Id);
10624 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10626 end Java_Constructor;
10628 ----------------------
10629 -- Java_Interface --
10630 ----------------------
10632 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
10634 when Pragma_Java_Interface => Java_Interface : declare
10640 Check_Arg_Count (1);
10641 Check_Optional_Identifier (Arg1, Name_Entity);
10642 Check_Arg_Is_Local_Name (Arg1);
10644 Arg := Get_Pragma_Arg (Arg1);
10647 if Etype (Arg) = Any_Type then
10651 if not Is_Entity_Name (Arg)
10652 or else not Is_Type (Entity (Arg))
10654 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10657 Typ := Underlying_Type (Entity (Arg));
10659 -- For now simply check some of the semantic constraints on the
10660 -- type. This currently leaves out some restrictions on interface
10661 -- types, namely that the parent type must be java.lang.Object.Typ
10662 -- and that all primitives of the type should be declared
10665 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10666 Error_Pragma_Arg ("pragma% requires an abstract "
10667 & "tagged type", Arg1);
10669 elsif not Has_Discriminants (Typ)
10670 or else Ekind (Etype (First_Discriminant (Typ)))
10671 /= E_Anonymous_Access_Type
10673 not Is_Class_Wide_Type
10674 (Designated_Type (Etype (First_Discriminant (Typ))))
10677 ("type must have a class-wide access discriminant", Arg1);
10679 end Java_Interface;
10685 -- pragma Keep_Names ([On => ] local_NAME);
10687 when Pragma_Keep_Names => Keep_Names : declare
10692 Check_Arg_Count (1);
10693 Check_Optional_Identifier (Arg1, Name_On);
10694 Check_Arg_Is_Local_Name (Arg1);
10696 Arg := Get_Pragma_Arg (Arg1);
10699 if Etype (Arg) = Any_Type then
10703 if not Is_Entity_Name (Arg)
10704 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10707 ("pragma% requires a local enumeration type", Arg1);
10710 Set_Discard_Names (Entity (Arg), False);
10717 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10719 when Pragma_License =>
10721 Check_Arg_Count (1);
10722 Check_No_Identifiers;
10723 Check_Valid_Configuration_Pragma;
10724 Check_Arg_Is_Identifier (Arg1);
10727 Sind : constant Source_File_Index :=
10728 Source_Index (Current_Sem_Unit);
10731 case Chars (Get_Pragma_Arg (Arg1)) is
10733 Set_License (Sind, GPL);
10735 when Name_Modified_GPL =>
10736 Set_License (Sind, Modified_GPL);
10738 when Name_Restricted =>
10739 Set_License (Sind, Restricted);
10741 when Name_Unrestricted =>
10742 Set_License (Sind, Unrestricted);
10745 Error_Pragma_Arg ("invalid license name", Arg1);
10753 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10755 when Pragma_Link_With => Link_With : declare
10761 if Operating_Mode = Generate_Code
10762 and then In_Extended_Main_Source_Unit (N)
10764 Check_At_Least_N_Arguments (1);
10765 Check_No_Identifiers;
10766 Check_Is_In_Decl_Part_Or_Package_Spec;
10767 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10771 while Present (Arg) loop
10772 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10774 -- Store argument, converting sequences of spaces to a
10775 -- single null character (this is one of the differences
10776 -- in processing between Link_With and Linker_Options).
10778 Arg_Store : declare
10779 C : constant Char_Code := Get_Char_Code (' ');
10780 S : constant String_Id :=
10781 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10782 L : constant Nat := String_Length (S);
10785 procedure Skip_Spaces;
10786 -- Advance F past any spaces
10792 procedure Skip_Spaces is
10794 while F <= L and then Get_String_Char (S, F) = C loop
10799 -- Start of processing for Arg_Store
10802 Skip_Spaces; -- skip leading spaces
10804 -- Loop through characters, changing any embedded
10805 -- sequence of spaces to a single null character (this
10806 -- is how Link_With/Linker_Options differ)
10809 if Get_String_Char (S, F) = C then
10812 Store_String_Char (ASCII.NUL);
10815 Store_String_Char (Get_String_Char (S, F));
10823 if Present (Arg) then
10824 Store_String_Char (ASCII.NUL);
10828 Store_Linker_Option_String (End_String);
10836 -- pragma Linker_Alias (
10837 -- [Entity =>] LOCAL_NAME
10838 -- [Target =>] static_string_EXPRESSION);
10840 when Pragma_Linker_Alias =>
10842 Check_Arg_Order ((Name_Entity, Name_Target));
10843 Check_Arg_Count (2);
10844 Check_Optional_Identifier (Arg1, Name_Entity);
10845 Check_Optional_Identifier (Arg2, Name_Target);
10846 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10847 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10849 -- The only processing required is to link this item on to the
10850 -- list of rep items for the given entity. This is accomplished
10851 -- by the call to Rep_Item_Too_Late (when no error is detected
10852 -- and False is returned).
10854 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10857 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10860 ------------------------
10861 -- Linker_Constructor --
10862 ------------------------
10864 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10866 -- Code is shared with Linker_Destructor
10868 -----------------------
10869 -- Linker_Destructor --
10870 -----------------------
10872 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10874 when Pragma_Linker_Constructor |
10875 Pragma_Linker_Destructor =>
10876 Linker_Constructor : declare
10882 Check_Arg_Count (1);
10883 Check_No_Identifiers;
10884 Check_Arg_Is_Local_Name (Arg1);
10885 Arg1_X := Get_Pragma_Arg (Arg1);
10887 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10889 if not Is_Library_Level_Entity (Proc) then
10891 ("argument for pragma% must be library level entity", Arg1);
10894 -- The only processing required is to link this item on to the
10895 -- list of rep items for the given entity. This is accomplished
10896 -- by the call to Rep_Item_Too_Late (when no error is detected
10897 -- and False is returned).
10899 if Rep_Item_Too_Late (Proc, N) then
10902 Set_Has_Gigi_Rep_Item (Proc);
10904 end Linker_Constructor;
10906 --------------------
10907 -- Linker_Options --
10908 --------------------
10910 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10912 when Pragma_Linker_Options => Linker_Options : declare
10916 Check_Ada_83_Warning;
10917 Check_No_Identifiers;
10918 Check_Arg_Count (1);
10919 Check_Is_In_Decl_Part_Or_Package_Spec;
10920 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10921 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10924 while Present (Arg) loop
10925 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10926 Store_String_Char (ASCII.NUL);
10928 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10932 if Operating_Mode = Generate_Code
10933 and then In_Extended_Main_Source_Unit (N)
10935 Store_Linker_Option_String (End_String);
10937 end Linker_Options;
10939 --------------------
10940 -- Linker_Section --
10941 --------------------
10943 -- pragma Linker_Section (
10944 -- [Entity =>] LOCAL_NAME
10945 -- [Section =>] static_string_EXPRESSION);
10947 when Pragma_Linker_Section =>
10949 Check_Arg_Order ((Name_Entity, Name_Section));
10950 Check_Arg_Count (2);
10951 Check_Optional_Identifier (Arg1, Name_Entity);
10952 Check_Optional_Identifier (Arg2, Name_Section);
10953 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10954 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10956 -- This pragma applies only to objects
10958 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10959 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10962 -- The only processing required is to link this item on to the
10963 -- list of rep items for the given entity. This is accomplished
10964 -- by the call to Rep_Item_Too_Late (when no error is detected
10965 -- and False is returned).
10967 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10970 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10977 -- pragma List (On | Off)
10979 -- There is nothing to do here, since we did all the processing for
10980 -- this pragma in Par.Prag (so that it works properly even in syntax
10983 when Pragma_List =>
10986 --------------------
10987 -- Locking_Policy --
10988 --------------------
10990 -- pragma Locking_Policy (policy_IDENTIFIER);
10992 when Pragma_Locking_Policy => declare
10993 subtype LP_Range is Name_Id
10994 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
10998 Check_Ada_83_Warning;
10999 Check_Arg_Count (1);
11000 Check_No_Identifiers;
11001 Check_Arg_Is_Locking_Policy (Arg1);
11002 Check_Valid_Configuration_Pragma;
11003 LP_Val := Chars (Get_Pragma_Arg (Arg1));
11006 when Name_Ceiling_Locking => LP := 'C';
11007 when Name_Inheritance_Locking => LP := 'I';
11008 when Name_Concurrent_Readers_Locking => LP := 'R';
11011 if Locking_Policy /= ' '
11012 and then Locking_Policy /= LP
11014 Error_Msg_Sloc := Locking_Policy_Sloc;
11015 Error_Pragma ("locking policy incompatible with policy#");
11017 -- Set new policy, but always preserve System_Location since we
11018 -- like the error message with the run time name.
11021 Locking_Policy := LP;
11023 if Locking_Policy_Sloc /= System_Location then
11024 Locking_Policy_Sloc := Loc;
11033 -- pragma Long_Float (D_Float | G_Float);
11035 when Pragma_Long_Float => Long_Float : declare
11038 Check_Valid_Configuration_Pragma;
11039 Check_Arg_Count (1);
11040 Check_No_Identifier (Arg1);
11041 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
11043 if not OpenVMS_On_Target then
11044 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
11049 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
11050 if Opt.Float_Format_Long = 'G' then
11052 ("G_Float previously specified", Arg1);
11054 elsif Current_Sem_Unit /= Main_Unit
11055 and then Opt.Float_Format_Long /= 'D'
11058 ("main unit not compiled with pragma Long_Float (D_Float)",
11059 "\pragma% must be used consistently for whole partition",
11063 Opt.Float_Format_Long := 'D';
11066 -- G_Float case (this is the default, does not need overriding)
11069 if Opt.Float_Format_Long = 'D' then
11070 Error_Pragma ("D_Float previously specified");
11072 elsif Current_Sem_Unit /= Main_Unit
11073 and then Opt.Float_Format_Long /= 'G'
11076 ("main unit not compiled with pragma Long_Float (G_Float)",
11077 "\pragma% must be used consistently for whole partition",
11081 Opt.Float_Format_Long := 'G';
11085 Set_Standard_Fpt_Formats;
11088 -----------------------
11089 -- Machine_Attribute --
11090 -----------------------
11092 -- pragma Machine_Attribute (
11093 -- [Entity =>] LOCAL_NAME,
11094 -- [Attribute_Name =>] static_string_EXPRESSION
11095 -- [, [Info =>] static_EXPRESSION] );
11097 when Pragma_Machine_Attribute => Machine_Attribute : declare
11098 Def_Id : Entity_Id;
11102 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
11104 if Arg_Count = 3 then
11105 Check_Optional_Identifier (Arg3, Name_Info);
11106 Check_Arg_Is_Static_Expression (Arg3);
11108 Check_Arg_Count (2);
11111 Check_Optional_Identifier (Arg1, Name_Entity);
11112 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
11113 Check_Arg_Is_Local_Name (Arg1);
11114 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11115 Def_Id := Entity (Get_Pragma_Arg (Arg1));
11117 if Is_Access_Type (Def_Id) then
11118 Def_Id := Designated_Type (Def_Id);
11121 if Rep_Item_Too_Early (Def_Id, N) then
11125 Def_Id := Underlying_Type (Def_Id);
11127 -- The only processing required is to link this item on to the
11128 -- list of rep items for the given entity. This is accomplished
11129 -- by the call to Rep_Item_Too_Late (when no error is detected
11130 -- and False is returned).
11132 if Rep_Item_Too_Late (Def_Id, N) then
11135 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11137 end Machine_Attribute;
11144 -- (MAIN_OPTION [, MAIN_OPTION]);
11147 -- [STACK_SIZE =>] static_integer_EXPRESSION
11148 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
11149 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
11151 when Pragma_Main => Main : declare
11152 Args : Args_List (1 .. 3);
11153 Names : constant Name_List (1 .. 3) := (
11155 Name_Task_Stack_Size_Default,
11156 Name_Time_Slicing_Enabled);
11162 Gather_Associations (Names, Args);
11164 for J in 1 .. 2 loop
11165 if Present (Args (J)) then
11166 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11170 if Present (Args (3)) then
11171 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
11175 while Present (Nod) loop
11176 if Nkind (Nod) = N_Pragma
11177 and then Pragma_Name (Nod) = Name_Main
11179 Error_Msg_Name_1 := Pname;
11180 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11191 -- pragma Main_Storage
11192 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
11194 -- MAIN_STORAGE_OPTION ::=
11195 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
11196 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
11198 when Pragma_Main_Storage => Main_Storage : declare
11199 Args : Args_List (1 .. 2);
11200 Names : constant Name_List (1 .. 2) := (
11201 Name_Working_Storage,
11208 Gather_Associations (Names, Args);
11210 for J in 1 .. 2 loop
11211 if Present (Args (J)) then
11212 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11216 Check_In_Main_Program;
11219 while Present (Nod) loop
11220 if Nkind (Nod) = N_Pragma
11221 and then Pragma_Name (Nod) = Name_Main_Storage
11223 Error_Msg_Name_1 := Pname;
11224 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11235 -- pragma Memory_Size (NUMERIC_LITERAL)
11237 when Pragma_Memory_Size =>
11240 -- Memory size is simply ignored
11242 Check_No_Identifiers;
11243 Check_Arg_Count (1);
11244 Check_Arg_Is_Integer_Literal (Arg1);
11252 -- The only correct use of this pragma is on its own in a file, in
11253 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
11254 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
11255 -- check for a file containing nothing but a No_Body pragma). If we
11256 -- attempt to process it during normal semantics processing, it means
11257 -- it was misplaced.
11259 when Pragma_No_Body =>
11267 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
11269 when Pragma_No_Return => No_Return : declare
11277 Check_At_Least_N_Arguments (1);
11279 -- Loop through arguments of pragma
11282 while Present (Arg) loop
11283 Check_Arg_Is_Local_Name (Arg);
11284 Id := Get_Pragma_Arg (Arg);
11287 if not Is_Entity_Name (Id) then
11288 Error_Pragma_Arg ("entity name required", Arg);
11291 if Etype (Id) = Any_Type then
11295 -- Loop to find matching procedures
11300 and then Scope (E) = Current_Scope
11302 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11305 -- Set flag on any alias as well
11307 if Is_Overloadable (E) and then Present (Alias (E)) then
11308 Set_No_Return (Alias (E));
11314 exit when From_Aspect_Specification (N);
11319 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11330 -- pragma No_Run_Time;
11332 -- Note: this pragma is retained for backwards compatibility. See
11333 -- body of Rtsfind for full details on its handling.
11335 when Pragma_No_Run_Time =>
11337 Check_Valid_Configuration_Pragma;
11338 Check_Arg_Count (0);
11340 No_Run_Time_Mode := True;
11341 Configurable_Run_Time_Mode := True;
11343 -- Set Duration to 32 bits if word size is 32
11345 if Ttypes.System_Word_Size = 32 then
11346 Duration_32_Bits_On_Target := True;
11349 -- Set appropriate restrictions
11351 Set_Restriction (No_Finalization, N);
11352 Set_Restriction (No_Exception_Handlers, N);
11353 Set_Restriction (Max_Tasks, N, 0);
11354 Set_Restriction (No_Tasking, N);
11356 ------------------------
11357 -- No_Strict_Aliasing --
11358 ------------------------
11360 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11362 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11367 Check_At_Most_N_Arguments (1);
11369 if Arg_Count = 0 then
11370 Check_Valid_Configuration_Pragma;
11371 Opt.No_Strict_Aliasing := True;
11374 Check_Optional_Identifier (Arg2, Name_Entity);
11375 Check_Arg_Is_Local_Name (Arg1);
11376 E_Id := Entity (Get_Pragma_Arg (Arg1));
11378 if E_Id = Any_Type then
11380 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11381 Error_Pragma_Arg ("pragma% requires access type", Arg1);
11384 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11386 end No_Strict_Aliasing;
11388 -----------------------
11389 -- Normalize_Scalars --
11390 -----------------------
11392 -- pragma Normalize_Scalars;
11394 when Pragma_Normalize_Scalars =>
11395 Check_Ada_83_Warning;
11396 Check_Arg_Count (0);
11397 Check_Valid_Configuration_Pragma;
11399 -- Normalize_Scalars creates false positives in CodePeer, and
11400 -- incorrect negative results in Alfa mode, so ignore this pragma
11403 if not (CodePeer_Mode or Alfa_Mode) then
11404 Normalize_Scalars := True;
11405 Init_Or_Norm_Scalars := True;
11412 -- pragma Obsolescent;
11414 -- pragma Obsolescent (
11415 -- [Message =>] static_string_EXPRESSION
11416 -- [,[Version =>] Ada_05]]);
11418 -- pragma Obsolescent (
11419 -- [Entity =>] NAME
11420 -- [,[Message =>] static_string_EXPRESSION
11421 -- [,[Version =>] Ada_05]] );
11423 when Pragma_Obsolescent => Obsolescent : declare
11427 procedure Set_Obsolescent (E : Entity_Id);
11428 -- Given an entity Ent, mark it as obsolescent if appropriate
11430 ---------------------
11431 -- Set_Obsolescent --
11432 ---------------------
11434 procedure Set_Obsolescent (E : Entity_Id) is
11443 -- Entity name was given
11445 if Present (Ename) then
11447 -- If entity name matches, we are fine. Save entity in
11448 -- pragma argument, for ASIS use.
11450 if Chars (Ename) = Chars (Ent) then
11451 Set_Entity (Ename, Ent);
11452 Generate_Reference (Ent, Ename);
11454 -- If entity name does not match, only possibility is an
11455 -- enumeration literal from an enumeration type declaration.
11457 elsif Ekind (Ent) /= E_Enumeration_Type then
11459 ("pragma % entity name does not match declaration");
11462 Ent := First_Literal (E);
11466 ("pragma % entity name does not match any " &
11467 "enumeration literal");
11469 elsif Chars (Ent) = Chars (Ename) then
11470 Set_Entity (Ename, Ent);
11471 Generate_Reference (Ent, Ename);
11475 Ent := Next_Literal (Ent);
11481 -- Ent points to entity to be marked
11483 if Arg_Count >= 1 then
11485 -- Deal with static string argument
11487 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11488 S := Strval (Get_Pragma_Arg (Arg1));
11490 for J in 1 .. String_Length (S) loop
11491 if not In_Character_Range (Get_String_Char (S, J)) then
11493 ("pragma% argument does not allow wide characters",
11498 Obsolescent_Warnings.Append
11499 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11501 -- Check for Ada_05 parameter
11503 if Arg_Count /= 1 then
11504 Check_Arg_Count (2);
11507 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11510 Check_Arg_Is_Identifier (Argx);
11512 if Chars (Argx) /= Name_Ada_05 then
11513 Error_Msg_Name_2 := Name_Ada_05;
11515 ("only allowed argument for pragma% is %", Argx);
11518 if Ada_Version_Explicit < Ada_2005
11519 or else not Warn_On_Ada_2005_Compatibility
11527 -- Set flag if pragma active
11530 Set_Is_Obsolescent (Ent);
11534 end Set_Obsolescent;
11536 -- Start of processing for pragma Obsolescent
11541 Check_At_Most_N_Arguments (3);
11543 -- See if first argument specifies an entity name
11547 (Chars (Arg1) = Name_Entity
11549 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11551 N_Operator_Symbol))
11553 Ename := Get_Pragma_Arg (Arg1);
11555 -- Eliminate first argument, so we can share processing
11559 Arg_Count := Arg_Count - 1;
11561 -- No Entity name argument given
11567 if Arg_Count >= 1 then
11568 Check_Optional_Identifier (Arg1, Name_Message);
11570 if Arg_Count = 2 then
11571 Check_Optional_Identifier (Arg2, Name_Version);
11575 -- Get immediately preceding declaration
11578 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11582 -- Cases where we do not follow anything other than another pragma
11586 -- First case: library level compilation unit declaration with
11587 -- the pragma immediately following the declaration.
11589 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11591 (Defining_Entity (Unit (Parent (Parent (N)))));
11594 -- Case 2: library unit placement for package
11598 Ent : constant Entity_Id := Find_Lib_Unit_Name;
11600 if Is_Package_Or_Generic_Package (Ent) then
11601 Set_Obsolescent (Ent);
11607 -- Cases where we must follow a declaration
11610 if Nkind (Decl) not in N_Declaration
11611 and then Nkind (Decl) not in N_Later_Decl_Item
11612 and then Nkind (Decl) not in N_Generic_Declaration
11613 and then Nkind (Decl) not in N_Renaming_Declaration
11616 ("pragma% misplaced, "
11617 & "must immediately follow a declaration");
11620 Set_Obsolescent (Defining_Entity (Decl));
11630 -- pragma Optimize (Time | Space | Off);
11632 -- The actual check for optimize is done in Gigi. Note that this
11633 -- pragma does not actually change the optimization setting, it
11634 -- simply checks that it is consistent with the pragma.
11636 when Pragma_Optimize =>
11637 Check_No_Identifiers;
11638 Check_Arg_Count (1);
11639 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11641 ------------------------
11642 -- Optimize_Alignment --
11643 ------------------------
11645 -- pragma Optimize_Alignment (Time | Space | Off);
11647 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11649 Check_No_Identifiers;
11650 Check_Arg_Count (1);
11651 Check_Valid_Configuration_Pragma;
11654 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11658 Opt.Optimize_Alignment := 'T';
11660 Opt.Optimize_Alignment := 'S';
11662 Opt.Optimize_Alignment := 'O';
11664 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11668 -- Set indication that mode is set locally. If we are in fact in a
11669 -- configuration pragma file, this setting is harmless since the
11670 -- switch will get reset anyway at the start of each unit.
11672 Optimize_Alignment_Local := True;
11673 end Optimize_Alignment;
11679 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11681 when Pragma_Ordered => Ordered : declare
11682 Assoc : constant Node_Id := Arg1;
11688 Check_No_Identifiers;
11689 Check_Arg_Count (1);
11690 Check_Arg_Is_Local_Name (Arg1);
11692 Type_Id := Get_Pragma_Arg (Assoc);
11693 Find_Type (Type_Id);
11694 Typ := Entity (Type_Id);
11696 if Typ = Any_Type then
11699 Typ := Underlying_Type (Typ);
11702 if not Is_Enumeration_Type (Typ) then
11703 Error_Pragma ("pragma% must specify enumeration type");
11706 Check_First_Subtype (Arg1);
11707 Set_Has_Pragma_Ordered (Base_Type (Typ));
11714 -- pragma Pack (first_subtype_LOCAL_NAME);
11716 when Pragma_Pack => Pack : declare
11717 Assoc : constant Node_Id := Arg1;
11721 Ignore : Boolean := False;
11724 Check_No_Identifiers;
11725 Check_Arg_Count (1);
11726 Check_Arg_Is_Local_Name (Arg1);
11728 Type_Id := Get_Pragma_Arg (Assoc);
11729 Find_Type (Type_Id);
11730 Typ := Entity (Type_Id);
11733 or else Rep_Item_Too_Early (Typ, N)
11737 Typ := Underlying_Type (Typ);
11740 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11741 Error_Pragma ("pragma% must specify array or record type");
11744 Check_First_Subtype (Arg1);
11745 Check_Duplicate_Pragma (Typ);
11749 if Is_Array_Type (Typ) then
11750 Ctyp := Component_Type (Typ);
11752 -- Ignore pack that does nothing
11754 if Known_Static_Esize (Ctyp)
11755 and then Known_Static_RM_Size (Ctyp)
11756 and then Esize (Ctyp) = RM_Size (Ctyp)
11757 and then Addressable (Esize (Ctyp))
11762 -- Process OK pragma Pack. Note that if there is a separate
11763 -- component clause present, the Pack will be cancelled. This
11764 -- processing is in Freeze.
11766 if not Rep_Item_Too_Late (Typ, N) then
11768 -- In the context of static code analysis, we do not need
11769 -- complex front-end expansions related to pragma Pack,
11770 -- so disable handling of pragma Pack in these cases.
11772 if CodePeer_Mode or Alfa_Mode then
11775 -- Don't attempt any packing for VM targets. We possibly
11776 -- could deal with some cases of array bit-packing, but we
11777 -- don't bother, since this is not a typical kind of
11778 -- representation in the VM context anyway (and would not
11779 -- for example work nicely with the debugger).
11781 elsif VM_Target /= No_VM then
11782 if not GNAT_Mode then
11784 ("?pragma% ignored in this configuration");
11787 -- Normal case where we do the pack action
11791 Set_Is_Packed (Base_Type (Typ));
11792 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11795 Set_Has_Pragma_Pack (Base_Type (Typ));
11799 -- For record types, the pack is always effective
11801 else pragma Assert (Is_Record_Type (Typ));
11802 if not Rep_Item_Too_Late (Typ, N) then
11804 -- Ignore pack request with warning in VM mode (skip warning
11805 -- if we are compiling GNAT run time library).
11807 if VM_Target /= No_VM then
11808 if not GNAT_Mode then
11810 ("?pragma% ignored in this configuration");
11813 -- Normal case of pack request active
11816 Set_Is_Packed (Base_Type (Typ));
11817 Set_Has_Pragma_Pack (Base_Type (Typ));
11818 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11830 -- There is nothing to do here, since we did all the processing for
11831 -- this pragma in Par.Prag (so that it works properly even in syntax
11834 when Pragma_Page =>
11841 -- pragma Passive [(PASSIVE_FORM)];
11843 -- PASSIVE_FORM ::= Semaphore | No
11845 when Pragma_Passive =>
11848 if Nkind (Parent (N)) /= N_Task_Definition then
11849 Error_Pragma ("pragma% must be within task definition");
11852 if Arg_Count /= 0 then
11853 Check_Arg_Count (1);
11854 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11857 ----------------------------------
11858 -- Preelaborable_Initialization --
11859 ----------------------------------
11861 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11863 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11868 Check_Arg_Count (1);
11869 Check_No_Identifiers;
11870 Check_Arg_Is_Identifier (Arg1);
11871 Check_Arg_Is_Local_Name (Arg1);
11872 Check_First_Subtype (Arg1);
11873 Ent := Entity (Get_Pragma_Arg (Arg1));
11875 if not (Is_Private_Type (Ent)
11877 Is_Protected_Type (Ent)
11879 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11882 ("pragma % can only be applied to private, formal derived or "
11883 & "protected type",
11887 -- Give an error if the pragma is applied to a protected type that
11888 -- does not qualify (due to having entries, or due to components
11889 -- that do not qualify).
11891 if Is_Protected_Type (Ent)
11892 and then not Has_Preelaborable_Initialization (Ent)
11895 ("protected type & does not have preelaborable " &
11896 "initialization", Ent);
11898 -- Otherwise mark the type as definitely having preelaborable
11902 Set_Known_To_Have_Preelab_Init (Ent);
11905 if Has_Pragma_Preelab_Init (Ent)
11906 and then Warn_On_Redundant_Constructs
11908 Error_Pragma ("?duplicate pragma%!");
11910 Set_Has_Pragma_Preelab_Init (Ent);
11914 --------------------
11915 -- Persistent_BSS --
11916 --------------------
11918 -- pragma Persistent_BSS [(object_NAME)];
11920 when Pragma_Persistent_BSS => Persistent_BSS : declare
11927 Check_At_Most_N_Arguments (1);
11929 -- Case of application to specific object (one argument)
11931 if Arg_Count = 1 then
11932 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11934 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11936 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11939 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11942 Ent := Entity (Get_Pragma_Arg (Arg1));
11943 Decl := Parent (Ent);
11945 if Rep_Item_Too_Late (Ent, N) then
11949 if Present (Expression (Decl)) then
11951 ("object for pragma% cannot have initialization", Arg1);
11954 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11956 ("object type for pragma% is not potentially persistent",
11960 Check_Duplicate_Pragma (Ent);
11963 Make_Linker_Section_Pragma
11964 (Ent, Sloc (N), ".persistent.bss");
11965 Insert_After (N, Prag);
11968 -- Case of use as configuration pragma with no arguments
11971 Check_Valid_Configuration_Pragma;
11972 Persistent_BSS_Mode := True;
11974 end Persistent_BSS;
11980 -- pragma Polling (ON | OFF);
11982 when Pragma_Polling =>
11984 Check_Arg_Count (1);
11985 Check_No_Identifiers;
11986 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11987 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11989 -------------------
11990 -- Postcondition --
11991 -------------------
11993 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
11994 -- [,[Message =>] String_EXPRESSION]);
11996 when Pragma_Postcondition => Postcondition : declare
11998 pragma Warnings (Off, In_Body);
12002 Check_At_Least_N_Arguments (1);
12003 Check_At_Most_N_Arguments (2);
12004 Check_Optional_Identifier (Arg1, Name_Check);
12006 -- All we need to do here is call the common check procedure,
12007 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
12009 Check_Precondition_Postcondition (In_Body);
12016 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
12017 -- [,[Message =>] String_EXPRESSION]);
12019 when Pragma_Precondition => Precondition : declare
12024 Check_At_Least_N_Arguments (1);
12025 Check_At_Most_N_Arguments (2);
12026 Check_Optional_Identifier (Arg1, Name_Check);
12027 Check_Precondition_Postcondition (In_Body);
12029 -- If in spec, nothing more to do. If in body, then we convert the
12030 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
12031 -- this whether or not precondition checks are enabled. That works
12032 -- fine since pragma Check will do this check, and will also
12033 -- analyze the condition itself in the proper context.
12038 Chars => Name_Check,
12039 Pragma_Argument_Associations => New_List (
12040 Make_Pragma_Argument_Association (Loc,
12041 Expression => Make_Identifier (Loc, Name_Precondition)),
12043 Make_Pragma_Argument_Association (Sloc (Arg1),
12044 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
12046 if Arg_Count = 2 then
12047 Append_To (Pragma_Argument_Associations (N),
12048 Make_Pragma_Argument_Association (Sloc (Arg2),
12049 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
12060 -- pragma Predicate
12061 -- ([Entity =>] type_LOCAL_NAME,
12062 -- [Check =>] EXPRESSION);
12064 when Pragma_Predicate => Predicate : declare
12069 pragma Unreferenced (Discard);
12073 Check_Arg_Count (2);
12074 Check_Optional_Identifier (Arg1, Name_Entity);
12075 Check_Optional_Identifier (Arg2, Name_Check);
12077 Check_Arg_Is_Local_Name (Arg1);
12079 Type_Id := Get_Pragma_Arg (Arg1);
12080 Find_Type (Type_Id);
12081 Typ := Entity (Type_Id);
12083 if Typ = Any_Type then
12087 -- The remaining processing is simply to link the pragma on to
12088 -- the rep item chain, for processing when the type is frozen.
12089 -- This is accomplished by a call to Rep_Item_Too_Late. We also
12090 -- mark the type as having predicates.
12092 Set_Has_Predicates (Typ);
12093 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12100 -- pragma Preelaborate [(library_unit_NAME)];
12102 -- Set the flag Is_Preelaborated of program unit name entity
12104 when Pragma_Preelaborate => Preelaborate : declare
12105 Pa : constant Node_Id := Parent (N);
12106 Pk : constant Node_Kind := Nkind (Pa);
12110 Check_Ada_83_Warning;
12111 Check_Valid_Library_Unit_Pragma;
12113 if Nkind (N) = N_Null_Statement then
12117 Ent := Find_Lib_Unit_Name;
12118 Check_Duplicate_Pragma (Ent);
12120 -- This filters out pragmas inside generic parent then
12121 -- show up inside instantiation
12124 and then not (Pk = N_Package_Specification
12125 and then Present (Generic_Parent (Pa)))
12127 if not Debug_Flag_U then
12128 Set_Is_Preelaborated (Ent);
12129 Set_Suppress_Elaboration_Warnings (Ent);
12134 ---------------------
12135 -- Preelaborate_05 --
12136 ---------------------
12138 -- pragma Preelaborate_05 [(library_unit_NAME)];
12140 -- This pragma is useable only in GNAT_Mode, where it is used like
12141 -- pragma Preelaborate but it is only effective in Ada 2005 mode
12142 -- (otherwise it is ignored). This is used to implement AI-362 which
12143 -- recategorizes some run-time packages in Ada 2005 mode.
12145 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
12150 Check_Valid_Library_Unit_Pragma;
12152 if not GNAT_Mode then
12153 Error_Pragma ("pragma% only available in GNAT mode");
12156 if Nkind (N) = N_Null_Statement then
12160 -- This is one of the few cases where we need to test the value of
12161 -- Ada_Version_Explicit rather than Ada_Version (which is always
12162 -- set to Ada_2012 in a predefined unit), we need to know the
12163 -- explicit version set to know if this pragma is active.
12165 if Ada_Version_Explicit >= Ada_2005 then
12166 Ent := Find_Lib_Unit_Name;
12167 Set_Is_Preelaborated (Ent);
12168 Set_Suppress_Elaboration_Warnings (Ent);
12170 end Preelaborate_05;
12176 -- pragma Priority (EXPRESSION);
12178 when Pragma_Priority => Priority : declare
12179 P : constant Node_Id := Parent (N);
12183 Check_No_Identifiers;
12184 Check_Arg_Count (1);
12188 if Nkind (P) = N_Subprogram_Body then
12189 Check_In_Main_Program;
12191 Arg := Get_Pragma_Arg (Arg1);
12192 Analyze_And_Resolve (Arg, Standard_Integer);
12196 if not Is_Static_Expression (Arg) then
12197 Flag_Non_Static_Expr
12198 ("main subprogram priority is not static!", Arg);
12201 -- If constraint error, then we already signalled an error
12203 elsif Raises_Constraint_Error (Arg) then
12206 -- Otherwise check in range
12210 Val : constant Uint := Expr_Value (Arg);
12214 or else Val > Expr_Value (Expression
12215 (Parent (RTE (RE_Max_Priority))))
12218 ("main subprogram priority is out of range", Arg1);
12224 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12226 -- Load an arbitrary entity from System.Tasking to make sure
12227 -- this package is implicitly with'ed, since we need to have
12228 -- the tasking run-time active for the pragma Priority to have
12232 Discard : Entity_Id;
12233 pragma Warnings (Off, Discard);
12235 Discard := RTE (RE_Task_List);
12238 -- Task or Protected, must be of type Integer
12240 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12241 Arg := Get_Pragma_Arg (Arg1);
12243 -- The expression must be analyzed in the special manner
12244 -- described in "Handling of Default and Per-Object
12245 -- Expressions" in sem.ads.
12247 Preanalyze_Spec_Expression (Arg, Standard_Integer);
12249 if not Is_Static_Expression (Arg) then
12250 Check_Restriction (Static_Priorities, Arg);
12253 -- Anything else is incorrect
12259 if Has_Pragma_Priority (P) then
12260 Error_Pragma ("duplicate pragma% not allowed");
12262 Set_Has_Pragma_Priority (P, True);
12264 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12265 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12266 -- exp_ch9 should use this ???
12271 -----------------------------------
12272 -- Priority_Specific_Dispatching --
12273 -----------------------------------
12275 -- pragma Priority_Specific_Dispatching (
12276 -- policy_IDENTIFIER,
12277 -- first_priority_EXPRESSION,
12278 -- last_priority_EXPRESSION);
12280 when Pragma_Priority_Specific_Dispatching =>
12281 Priority_Specific_Dispatching : declare
12282 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12283 -- This is the entity System.Any_Priority;
12286 Lower_Bound : Node_Id;
12287 Upper_Bound : Node_Id;
12293 Check_Arg_Count (3);
12294 Check_No_Identifiers;
12295 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12296 Check_Valid_Configuration_Pragma;
12297 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12298 DP := Fold_Upper (Name_Buffer (1));
12300 Lower_Bound := Get_Pragma_Arg (Arg2);
12301 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12302 Lower_Val := Expr_Value (Lower_Bound);
12304 Upper_Bound := Get_Pragma_Arg (Arg3);
12305 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12306 Upper_Val := Expr_Value (Upper_Bound);
12308 -- It is not allowed to use Task_Dispatching_Policy and
12309 -- Priority_Specific_Dispatching in the same partition.
12311 if Task_Dispatching_Policy /= ' ' then
12312 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12314 ("pragma% incompatible with Task_Dispatching_Policy#");
12316 -- Check lower bound in range
12318 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12320 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12323 ("first_priority is out of range", Arg2);
12325 -- Check upper bound in range
12327 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12329 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12332 ("last_priority is out of range", Arg3);
12334 -- Check that the priority range is valid
12336 elsif Lower_Val > Upper_Val then
12338 ("last_priority_expression must be greater than" &
12339 " or equal to first_priority_expression");
12341 -- Store the new policy, but always preserve System_Location since
12342 -- we like the error message with the run-time name.
12345 -- Check overlapping in the priority ranges specified in other
12346 -- Priority_Specific_Dispatching pragmas within the same
12347 -- partition. We can only check those we know about!
12350 Specific_Dispatching.First .. Specific_Dispatching.Last
12352 if Specific_Dispatching.Table (J).First_Priority in
12353 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12354 or else Specific_Dispatching.Table (J).Last_Priority in
12355 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12358 Specific_Dispatching.Table (J).Pragma_Loc;
12360 ("priority range overlaps with "
12361 & "Priority_Specific_Dispatching#");
12365 -- The use of Priority_Specific_Dispatching is incompatible
12366 -- with Task_Dispatching_Policy.
12368 if Task_Dispatching_Policy /= ' ' then
12369 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12371 ("Priority_Specific_Dispatching incompatible "
12372 & "with Task_Dispatching_Policy#");
12375 -- The use of Priority_Specific_Dispatching forces ceiling
12378 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12379 Error_Msg_Sloc := Locking_Policy_Sloc;
12381 ("Priority_Specific_Dispatching incompatible "
12382 & "with Locking_Policy#");
12384 -- Set the Ceiling_Locking policy, but preserve System_Location
12385 -- since we like the error message with the run time name.
12388 Locking_Policy := 'C';
12390 if Locking_Policy_Sloc /= System_Location then
12391 Locking_Policy_Sloc := Loc;
12395 -- Add entry in the table
12397 Specific_Dispatching.Append
12398 ((Dispatching_Policy => DP,
12399 First_Priority => UI_To_Int (Lower_Val),
12400 Last_Priority => UI_To_Int (Upper_Val),
12401 Pragma_Loc => Loc));
12403 end Priority_Specific_Dispatching;
12409 -- pragma Profile (profile_IDENTIFIER);
12411 -- profile_IDENTIFIER => Restricted | Ravenscar
12413 when Pragma_Profile =>
12415 Check_Arg_Count (1);
12416 Check_Valid_Configuration_Pragma;
12417 Check_No_Identifiers;
12420 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12423 if Chars (Argx) = Name_Ravenscar then
12424 Set_Ravenscar_Profile (N);
12426 elsif Chars (Argx) = Name_Restricted then
12427 Set_Profile_Restrictions
12429 N, Warn => Treat_Restrictions_As_Warnings);
12431 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12432 Set_Profile_Restrictions
12433 (No_Implementation_Extensions,
12434 N, Warn => Treat_Restrictions_As_Warnings);
12437 Error_Pragma_Arg ("& is not a valid profile", Argx);
12441 ----------------------
12442 -- Profile_Warnings --
12443 ----------------------
12445 -- pragma Profile_Warnings (profile_IDENTIFIER);
12447 -- profile_IDENTIFIER => Restricted | Ravenscar
12449 when Pragma_Profile_Warnings =>
12451 Check_Arg_Count (1);
12452 Check_Valid_Configuration_Pragma;
12453 Check_No_Identifiers;
12456 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12459 if Chars (Argx) = Name_Ravenscar then
12460 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12462 elsif Chars (Argx) = Name_Restricted then
12463 Set_Profile_Restrictions (Restricted, N, Warn => True);
12465 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12466 Set_Profile_Restrictions
12467 (No_Implementation_Extensions, N, Warn => True);
12470 Error_Pragma_Arg ("& is not a valid profile", Argx);
12474 --------------------------
12475 -- Propagate_Exceptions --
12476 --------------------------
12478 -- pragma Propagate_Exceptions;
12480 -- Note: this pragma is obsolete and has no effect
12482 when Pragma_Propagate_Exceptions =>
12484 Check_Arg_Count (0);
12486 if In_Extended_Main_Source_Unit (N) then
12487 Propagate_Exceptions := True;
12494 -- pragma Psect_Object (
12495 -- [Internal =>] LOCAL_NAME,
12496 -- [, [External =>] EXTERNAL_SYMBOL]
12497 -- [, [Size =>] EXTERNAL_SYMBOL]);
12499 when Pragma_Psect_Object | Pragma_Common_Object =>
12500 Psect_Object : declare
12501 Args : Args_List (1 .. 3);
12502 Names : constant Name_List (1 .. 3) := (
12507 Internal : Node_Id renames Args (1);
12508 External : Node_Id renames Args (2);
12509 Size : Node_Id renames Args (3);
12511 Def_Id : Entity_Id;
12513 procedure Check_Too_Long (Arg : Node_Id);
12514 -- Posts message if the argument is an identifier with more
12515 -- than 31 characters, or a string literal with more than
12516 -- 31 characters, and we are operating under VMS
12518 --------------------
12519 -- Check_Too_Long --
12520 --------------------
12522 procedure Check_Too_Long (Arg : Node_Id) is
12523 X : constant Node_Id := Original_Node (Arg);
12526 if not Nkind_In (X, N_String_Literal, N_Identifier) then
12528 ("inappropriate argument for pragma %", Arg);
12531 if OpenVMS_On_Target then
12532 if (Nkind (X) = N_String_Literal
12533 and then String_Length (Strval (X)) > 31)
12535 (Nkind (X) = N_Identifier
12536 and then Length_Of_Name (Chars (X)) > 31)
12539 ("argument for pragma % is longer than 31 characters",
12543 end Check_Too_Long;
12545 -- Start of processing for Common_Object/Psect_Object
12549 Gather_Associations (Names, Args);
12550 Process_Extended_Import_Export_Internal_Arg (Internal);
12552 Def_Id := Entity (Internal);
12554 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12556 ("pragma% must designate an object", Internal);
12559 Check_Too_Long (Internal);
12561 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12563 ("cannot use pragma% for imported/exported object",
12567 if Is_Concurrent_Type (Etype (Internal)) then
12569 ("cannot specify pragma % for task/protected object",
12573 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12575 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12577 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12580 if Ekind (Def_Id) = E_Constant then
12582 ("cannot specify pragma % for a constant", Internal);
12585 if Is_Record_Type (Etype (Internal)) then
12591 Ent := First_Entity (Etype (Internal));
12592 while Present (Ent) loop
12593 Decl := Declaration_Node (Ent);
12595 if Ekind (Ent) = E_Component
12596 and then Nkind (Decl) = N_Component_Declaration
12597 and then Present (Expression (Decl))
12598 and then Warn_On_Export_Import
12601 ("?object for pragma % has defaults", Internal);
12611 if Present (Size) then
12612 Check_Too_Long (Size);
12615 if Present (External) then
12616 Check_Arg_Is_External_Name (External);
12617 Check_Too_Long (External);
12620 -- If all error tests pass, link pragma on to the rep item chain
12622 Record_Rep_Item (Def_Id, N);
12629 -- pragma Pure [(library_unit_NAME)];
12631 when Pragma_Pure => Pure : declare
12635 Check_Ada_83_Warning;
12636 Check_Valid_Library_Unit_Pragma;
12638 if Nkind (N) = N_Null_Statement then
12642 Ent := Find_Lib_Unit_Name;
12644 Set_Has_Pragma_Pure (Ent);
12645 Set_Suppress_Elaboration_Warnings (Ent);
12652 -- pragma Pure_05 [(library_unit_NAME)];
12654 -- This pragma is useable only in GNAT_Mode, where it is used like
12655 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
12656 -- it is ignored). It may be used after a pragma Preelaborate, in
12657 -- which case it overrides the effect of the pragma Preelaborate.
12658 -- This is used to implement AI-362 which recategorizes some run-time
12659 -- packages in Ada 2005 mode.
12661 when Pragma_Pure_05 => Pure_05 : declare
12666 Check_Valid_Library_Unit_Pragma;
12668 if not GNAT_Mode then
12669 Error_Pragma ("pragma% only available in GNAT mode");
12672 if Nkind (N) = N_Null_Statement then
12676 -- This is one of the few cases where we need to test the value of
12677 -- Ada_Version_Explicit rather than Ada_Version (which is always
12678 -- set to Ada_2012 in a predefined unit), we need to know the
12679 -- explicit version set to know if this pragma is active.
12681 if Ada_Version_Explicit >= Ada_2005 then
12682 Ent := Find_Lib_Unit_Name;
12683 Set_Is_Preelaborated (Ent, False);
12685 Set_Suppress_Elaboration_Warnings (Ent);
12693 -- pragma Pure_12 [(library_unit_NAME)];
12695 -- This pragma is useable only in GNAT_Mode, where it is used like
12696 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
12697 -- it is ignored). It may be used after a pragma Preelaborate, in
12698 -- which case it overrides the effect of the pragma Preelaborate.
12699 -- This is used to implement AI05-0212 which recategorizes some
12700 -- run-time packages in Ada 2012 mode.
12702 when Pragma_Pure_12 => Pure_12 : declare
12707 Check_Valid_Library_Unit_Pragma;
12709 if not GNAT_Mode then
12710 Error_Pragma ("pragma% only available in GNAT mode");
12713 if Nkind (N) = N_Null_Statement then
12717 -- This is one of the few cases where we need to test the value of
12718 -- Ada_Version_Explicit rather than Ada_Version (which is always
12719 -- set to Ada_2012 in a predefined unit), we need to know the
12720 -- explicit version set to know if this pragma is active.
12722 if Ada_Version_Explicit >= Ada_2012 then
12723 Ent := Find_Lib_Unit_Name;
12724 Set_Is_Preelaborated (Ent, False);
12726 Set_Suppress_Elaboration_Warnings (Ent);
12730 -------------------
12731 -- Pure_Function --
12732 -------------------
12734 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12736 when Pragma_Pure_Function => Pure_Function : declare
12739 Def_Id : Entity_Id;
12740 Effective : Boolean := False;
12744 Check_Arg_Count (1);
12745 Check_Optional_Identifier (Arg1, Name_Entity);
12746 Check_Arg_Is_Local_Name (Arg1);
12747 E_Id := Get_Pragma_Arg (Arg1);
12749 if Error_Posted (E_Id) then
12753 -- Loop through homonyms (overloadings) of referenced entity
12755 E := Entity (E_Id);
12757 if Present (E) then
12759 Def_Id := Get_Base_Subprogram (E);
12761 if not Ekind_In (Def_Id, E_Function,
12762 E_Generic_Function,
12766 ("pragma% requires a function name", Arg1);
12769 Set_Is_Pure (Def_Id);
12771 if not Has_Pragma_Pure_Function (Def_Id) then
12772 Set_Has_Pragma_Pure_Function (Def_Id);
12776 exit when From_Aspect_Specification (N);
12778 exit when No (E) or else Scope (E) /= Current_Scope;
12782 and then Warn_On_Redundant_Constructs
12785 ("pragma Pure_Function on& is redundant?",
12791 --------------------
12792 -- Queuing_Policy --
12793 --------------------
12795 -- pragma Queuing_Policy (policy_IDENTIFIER);
12797 when Pragma_Queuing_Policy => declare
12801 Check_Ada_83_Warning;
12802 Check_Arg_Count (1);
12803 Check_No_Identifiers;
12804 Check_Arg_Is_Queuing_Policy (Arg1);
12805 Check_Valid_Configuration_Pragma;
12806 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12807 QP := Fold_Upper (Name_Buffer (1));
12809 if Queuing_Policy /= ' '
12810 and then Queuing_Policy /= QP
12812 Error_Msg_Sloc := Queuing_Policy_Sloc;
12813 Error_Pragma ("queuing policy incompatible with policy#");
12815 -- Set new policy, but always preserve System_Location since we
12816 -- like the error message with the run time name.
12819 Queuing_Policy := QP;
12821 if Queuing_Policy_Sloc /= System_Location then
12822 Queuing_Policy_Sloc := Loc;
12827 -----------------------
12828 -- Relative_Deadline --
12829 -----------------------
12831 -- pragma Relative_Deadline (time_span_EXPRESSION);
12833 when Pragma_Relative_Deadline => Relative_Deadline : declare
12834 P : constant Node_Id := Parent (N);
12839 Check_No_Identifiers;
12840 Check_Arg_Count (1);
12842 Arg := Get_Pragma_Arg (Arg1);
12844 -- The expression must be analyzed in the special manner described
12845 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12847 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12851 if Nkind (P) = N_Subprogram_Body then
12852 Check_In_Main_Program;
12856 elsif Nkind (P) = N_Task_Definition then
12859 -- Anything else is incorrect
12865 if Has_Relative_Deadline_Pragma (P) then
12866 Error_Pragma ("duplicate pragma% not allowed");
12868 Set_Has_Relative_Deadline_Pragma (P, True);
12870 if Nkind (P) = N_Task_Definition then
12871 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12874 end Relative_Deadline;
12876 ---------------------------
12877 -- Remote_Call_Interface --
12878 ---------------------------
12880 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12882 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12883 Cunit_Node : Node_Id;
12884 Cunit_Ent : Entity_Id;
12888 Check_Ada_83_Warning;
12889 Check_Valid_Library_Unit_Pragma;
12891 if Nkind (N) = N_Null_Statement then
12895 Cunit_Node := Cunit (Current_Sem_Unit);
12896 K := Nkind (Unit (Cunit_Node));
12897 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12899 if K = N_Package_Declaration
12900 or else K = N_Generic_Package_Declaration
12901 or else K = N_Subprogram_Declaration
12902 or else K = N_Generic_Subprogram_Declaration
12903 or else (K = N_Subprogram_Body
12904 and then Acts_As_Spec (Unit (Cunit_Node)))
12909 "pragma% must apply to package or subprogram declaration");
12912 Set_Is_Remote_Call_Interface (Cunit_Ent);
12913 end Remote_Call_Interface;
12919 -- pragma Remote_Types [(library_unit_NAME)];
12921 when Pragma_Remote_Types => Remote_Types : declare
12922 Cunit_Node : Node_Id;
12923 Cunit_Ent : Entity_Id;
12926 Check_Ada_83_Warning;
12927 Check_Valid_Library_Unit_Pragma;
12929 if Nkind (N) = N_Null_Statement then
12933 Cunit_Node := Cunit (Current_Sem_Unit);
12934 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12936 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12937 N_Generic_Package_Declaration)
12940 ("pragma% can only apply to a package declaration");
12943 Set_Is_Remote_Types (Cunit_Ent);
12950 -- pragma Ravenscar;
12952 when Pragma_Ravenscar =>
12954 Check_Arg_Count (0);
12955 Check_Valid_Configuration_Pragma;
12956 Set_Ravenscar_Profile (N);
12958 if Warn_On_Obsolescent_Feature then
12959 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12960 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12963 -------------------------
12964 -- Restricted_Run_Time --
12965 -------------------------
12967 -- pragma Restricted_Run_Time;
12969 when Pragma_Restricted_Run_Time =>
12971 Check_Arg_Count (0);
12972 Check_Valid_Configuration_Pragma;
12973 Set_Profile_Restrictions
12974 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12976 if Warn_On_Obsolescent_Feature then
12978 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12979 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12986 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12989 -- restriction_IDENTIFIER
12990 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12992 when Pragma_Restrictions =>
12993 Process_Restrictions_Or_Restriction_Warnings
12994 (Warn => Treat_Restrictions_As_Warnings);
12996 --------------------------
12997 -- Restriction_Warnings --
12998 --------------------------
13000 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
13003 -- restriction_IDENTIFIER
13004 -- | restriction_parameter_IDENTIFIER => EXPRESSION
13006 when Pragma_Restriction_Warnings =>
13008 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
13014 -- pragma Reviewable;
13016 when Pragma_Reviewable =>
13017 Check_Ada_83_Warning;
13018 Check_Arg_Count (0);
13020 -- Call dummy debugging function rv. This is done to assist front
13021 -- end debugging. By placing a Reviewable pragma in the source
13022 -- program, a breakpoint on rv catches this place in the source,
13023 -- allowing convenient stepping to the point of interest.
13027 --------------------------
13028 -- Short_Circuit_And_Or --
13029 --------------------------
13031 when Pragma_Short_Circuit_And_Or =>
13033 Check_Arg_Count (0);
13034 Check_Valid_Configuration_Pragma;
13035 Short_Circuit_And_Or := True;
13037 -------------------
13038 -- Share_Generic --
13039 -------------------
13041 -- pragma Share_Generic (NAME {, NAME});
13043 when Pragma_Share_Generic =>
13045 Process_Generic_List;
13051 -- pragma Shared (LOCAL_NAME);
13053 when Pragma_Shared =>
13055 Process_Atomic_Shared_Volatile;
13057 --------------------
13058 -- Shared_Passive --
13059 --------------------
13061 -- pragma Shared_Passive [(library_unit_NAME)];
13063 -- Set the flag Is_Shared_Passive of program unit name entity
13065 when Pragma_Shared_Passive => Shared_Passive : declare
13066 Cunit_Node : Node_Id;
13067 Cunit_Ent : Entity_Id;
13070 Check_Ada_83_Warning;
13071 Check_Valid_Library_Unit_Pragma;
13073 if Nkind (N) = N_Null_Statement then
13077 Cunit_Node := Cunit (Current_Sem_Unit);
13078 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13080 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13081 N_Generic_Package_Declaration)
13084 ("pragma% can only apply to a package declaration");
13087 Set_Is_Shared_Passive (Cunit_Ent);
13088 end Shared_Passive;
13090 -----------------------
13091 -- Short_Descriptors --
13092 -----------------------
13094 -- pragma Short_Descriptors;
13096 when Pragma_Short_Descriptors =>
13098 Check_Arg_Count (0);
13099 Check_Valid_Configuration_Pragma;
13100 Short_Descriptors := True;
13102 ----------------------
13103 -- Source_File_Name --
13104 ----------------------
13106 -- There are five forms for this pragma:
13108 -- pragma Source_File_Name (
13109 -- [UNIT_NAME =>] unit_NAME,
13110 -- BODY_FILE_NAME => STRING_LITERAL
13111 -- [, [INDEX =>] INTEGER_LITERAL]);
13113 -- pragma Source_File_Name (
13114 -- [UNIT_NAME =>] unit_NAME,
13115 -- SPEC_FILE_NAME => STRING_LITERAL
13116 -- [, [INDEX =>] INTEGER_LITERAL]);
13118 -- pragma Source_File_Name (
13119 -- BODY_FILE_NAME => STRING_LITERAL
13120 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13121 -- [, CASING => CASING_SPEC]);
13123 -- pragma Source_File_Name (
13124 -- SPEC_FILE_NAME => STRING_LITERAL
13125 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13126 -- [, CASING => CASING_SPEC]);
13128 -- pragma Source_File_Name (
13129 -- SUBUNIT_FILE_NAME => STRING_LITERAL
13130 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13131 -- [, CASING => CASING_SPEC]);
13133 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
13135 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
13136 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
13137 -- only be used when no project file is used, while SFNP can only be
13138 -- used when a project file is used.
13140 -- No processing here. Processing was completed during parsing, since
13141 -- we need to have file names set as early as possible. Units are
13142 -- loaded well before semantic processing starts.
13144 -- The only processing we defer to this point is the check for
13145 -- correct placement.
13147 when Pragma_Source_File_Name =>
13149 Check_Valid_Configuration_Pragma;
13151 ------------------------------
13152 -- Source_File_Name_Project --
13153 ------------------------------
13155 -- See Source_File_Name for syntax
13157 -- No processing here. Processing was completed during parsing, since
13158 -- we need to have file names set as early as possible. Units are
13159 -- loaded well before semantic processing starts.
13161 -- The only processing we defer to this point is the check for
13162 -- correct placement.
13164 when Pragma_Source_File_Name_Project =>
13166 Check_Valid_Configuration_Pragma;
13168 -- Check that a pragma Source_File_Name_Project is used only in a
13169 -- configuration pragmas file.
13171 -- Pragmas Source_File_Name_Project should only be generated by
13172 -- the Project Manager in configuration pragmas files.
13174 -- This is really an ugly test. It seems to depend on some
13175 -- accidental and undocumented property. At the very least it
13176 -- needs to be documented, but it would be better to have a
13177 -- clean way of testing if we are in a configuration file???
13179 if Present (Parent (N)) then
13181 ("pragma% can only appear in a configuration pragmas file");
13184 ----------------------
13185 -- Source_Reference --
13186 ----------------------
13188 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
13190 -- Nothing to do, all processing completed in Par.Prag, since we need
13191 -- the information for possible parser messages that are output.
13193 when Pragma_Source_Reference =>
13196 --------------------------------
13197 -- Static_Elaboration_Desired --
13198 --------------------------------
13200 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
13202 when Pragma_Static_Elaboration_Desired =>
13204 Check_At_Most_N_Arguments (1);
13206 if Is_Compilation_Unit (Current_Scope)
13207 and then Ekind (Current_Scope) = E_Package
13209 Set_Static_Elaboration_Desired (Current_Scope, True);
13211 Error_Pragma ("pragma% must apply to a library-level package");
13218 -- pragma Storage_Size (EXPRESSION);
13220 when Pragma_Storage_Size => Storage_Size : declare
13221 P : constant Node_Id := Parent (N);
13225 Check_No_Identifiers;
13226 Check_Arg_Count (1);
13228 -- The expression must be analyzed in the special manner described
13229 -- in "Handling of Default Expressions" in sem.ads.
13231 Arg := Get_Pragma_Arg (Arg1);
13232 Preanalyze_Spec_Expression (Arg, Any_Integer);
13234 if not Is_Static_Expression (Arg) then
13235 Check_Restriction (Static_Storage_Size, Arg);
13238 if Nkind (P) /= N_Task_Definition then
13243 if Has_Storage_Size_Pragma (P) then
13244 Error_Pragma ("duplicate pragma% not allowed");
13246 Set_Has_Storage_Size_Pragma (P, True);
13249 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13250 -- ??? exp_ch9 should use this!
13258 -- pragma Storage_Unit (NUMERIC_LITERAL);
13260 -- Only permitted argument is System'Storage_Unit value
13262 when Pragma_Storage_Unit =>
13263 Check_No_Identifiers;
13264 Check_Arg_Count (1);
13265 Check_Arg_Is_Integer_Literal (Arg1);
13267 if Intval (Get_Pragma_Arg (Arg1)) /=
13268 UI_From_Int (Ttypes.System_Storage_Unit)
13270 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
13272 ("the only allowed argument for pragma% is ^", Arg1);
13275 --------------------
13276 -- Stream_Convert --
13277 --------------------
13279 -- pragma Stream_Convert (
13280 -- [Entity =>] type_LOCAL_NAME,
13281 -- [Read =>] function_NAME,
13282 -- [Write =>] function NAME);
13284 when Pragma_Stream_Convert => Stream_Convert : declare
13286 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
13287 -- Check that the given argument is the name of a local function
13288 -- of one argument that is not overloaded earlier in the current
13289 -- local scope. A check is also made that the argument is a
13290 -- function with one parameter.
13292 --------------------------------------
13293 -- Check_OK_Stream_Convert_Function --
13294 --------------------------------------
13296 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
13300 Check_Arg_Is_Local_Name (Arg);
13301 Ent := Entity (Get_Pragma_Arg (Arg));
13303 if Has_Homonym (Ent) then
13305 ("argument for pragma% may not be overloaded", Arg);
13308 if Ekind (Ent) /= E_Function
13309 or else No (First_Formal (Ent))
13310 or else Present (Next_Formal (First_Formal (Ent)))
13313 ("argument for pragma% must be" &
13314 " function of one argument", Arg);
13316 end Check_OK_Stream_Convert_Function;
13318 -- Start of processing for Stream_Convert
13322 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
13323 Check_Arg_Count (3);
13324 Check_Optional_Identifier (Arg1, Name_Entity);
13325 Check_Optional_Identifier (Arg2, Name_Read);
13326 Check_Optional_Identifier (Arg3, Name_Write);
13327 Check_Arg_Is_Local_Name (Arg1);
13328 Check_OK_Stream_Convert_Function (Arg2);
13329 Check_OK_Stream_Convert_Function (Arg3);
13332 Typ : constant Entity_Id :=
13333 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13334 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13335 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
13338 Check_First_Subtype (Arg1);
13340 -- Check for too early or too late. Note that we don't enforce
13341 -- the rule about primitive operations in this case, since, as
13342 -- is the case for explicit stream attributes themselves, these
13343 -- restrictions are not appropriate. Note that the chaining of
13344 -- the pragma by Rep_Item_Too_Late is actually the critical
13345 -- processing done for this pragma.
13347 if Rep_Item_Too_Early (Typ, N)
13349 Rep_Item_Too_Late (Typ, N, FOnly => True)
13354 -- Return if previous error
13356 if Etype (Typ) = Any_Type
13358 Etype (Read) = Any_Type
13360 Etype (Write) = Any_Type
13367 if Underlying_Type (Etype (Read)) /= Typ then
13369 ("incorrect return type for function&", Arg2);
13372 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13374 ("incorrect parameter type for function&", Arg3);
13377 if Underlying_Type (Etype (First_Formal (Read))) /=
13378 Underlying_Type (Etype (Write))
13381 ("result type of & does not match Read parameter type",
13385 end Stream_Convert;
13387 -------------------------
13388 -- Style_Checks (GNAT) --
13389 -------------------------
13391 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13393 -- This is processed by the parser since some of the style checks
13394 -- take place during source scanning and parsing. This means that
13395 -- we don't need to issue error messages here.
13397 when Pragma_Style_Checks => Style_Checks : declare
13398 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13404 Check_No_Identifiers;
13406 -- Two argument form
13408 if Arg_Count = 2 then
13409 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13416 E_Id := Get_Pragma_Arg (Arg2);
13419 if not Is_Entity_Name (E_Id) then
13421 ("second argument of pragma% must be entity name",
13425 E := Entity (E_Id);
13431 Set_Suppress_Style_Checks (E,
13432 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
13433 exit when No (Homonym (E));
13439 -- One argument form
13442 Check_Arg_Count (1);
13444 if Nkind (A) = N_String_Literal then
13448 Slen : constant Natural := Natural (String_Length (S));
13449 Options : String (1 .. Slen);
13455 C := Get_String_Char (S, Int (J));
13456 exit when not In_Character_Range (C);
13457 Options (J) := Get_Character (C);
13459 -- If at end of string, set options. As per discussion
13460 -- above, no need to check for errors, since we issued
13461 -- them in the parser.
13464 Set_Style_Check_Options (Options);
13472 elsif Nkind (A) = N_Identifier then
13473 if Chars (A) = Name_All_Checks then
13475 Set_GNAT_Style_Check_Options;
13477 Set_Default_Style_Check_Options;
13480 elsif Chars (A) = Name_On then
13481 Style_Check := True;
13483 elsif Chars (A) = Name_Off then
13484 Style_Check := False;
13494 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13496 when Pragma_Subtitle =>
13498 Check_Arg_Count (1);
13499 Check_Optional_Identifier (Arg1, Name_Subtitle);
13500 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13507 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13509 when Pragma_Suppress =>
13510 Process_Suppress_Unsuppress (True);
13516 -- pragma Suppress_All;
13518 -- The only check made here is that the pragma has no arguments.
13519 -- There are no placement rules, and the processing required (setting
13520 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
13521 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
13522 -- then creates and inserts a pragma Suppress (All_Checks).
13524 when Pragma_Suppress_All =>
13526 Check_Arg_Count (0);
13528 -------------------------
13529 -- Suppress_Debug_Info --
13530 -------------------------
13532 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13534 when Pragma_Suppress_Debug_Info =>
13536 Check_Arg_Count (1);
13537 Check_Optional_Identifier (Arg1, Name_Entity);
13538 Check_Arg_Is_Local_Name (Arg1);
13539 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13541 ----------------------------------
13542 -- Suppress_Exception_Locations --
13543 ----------------------------------
13545 -- pragma Suppress_Exception_Locations;
13547 when Pragma_Suppress_Exception_Locations =>
13549 Check_Arg_Count (0);
13550 Check_Valid_Configuration_Pragma;
13551 Exception_Locations_Suppressed := True;
13553 -----------------------------
13554 -- Suppress_Initialization --
13555 -----------------------------
13557 -- pragma Suppress_Initialization ([Entity =>] type_Name);
13559 when Pragma_Suppress_Initialization => Suppress_Init : declare
13565 Check_Arg_Count (1);
13566 Check_Optional_Identifier (Arg1, Name_Entity);
13567 Check_Arg_Is_Local_Name (Arg1);
13569 E_Id := Get_Pragma_Arg (Arg1);
13571 if Etype (E_Id) = Any_Type then
13575 E := Entity (E_Id);
13577 if not Is_Type (E) then
13578 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13581 if Rep_Item_Too_Early (E, N)
13583 Rep_Item_Too_Late (E, N, FOnly => True)
13588 -- For incomplete/private type, set flag on full view
13590 if Is_Incomplete_Or_Private_Type (E) then
13591 if No (Full_View (Base_Type (E))) then
13593 ("argument of pragma% cannot be an incomplete type", Arg1);
13595 Set_Suppress_Initialization (Full_View (Base_Type (E)));
13598 -- For first subtype, set flag on base type
13600 elsif Is_First_Subtype (E) then
13601 Set_Suppress_Initialization (Base_Type (E));
13603 -- For other than first subtype, set flag on subtype itself
13606 Set_Suppress_Initialization (E);
13614 -- pragma System_Name (DIRECT_NAME);
13616 -- Syntax check: one argument, which must be the identifier GNAT or
13617 -- the identifier GCC, no other identifiers are acceptable.
13619 when Pragma_System_Name =>
13621 Check_No_Identifiers;
13622 Check_Arg_Count (1);
13623 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13625 -----------------------------
13626 -- Task_Dispatching_Policy --
13627 -----------------------------
13629 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13631 when Pragma_Task_Dispatching_Policy => declare
13635 Check_Ada_83_Warning;
13636 Check_Arg_Count (1);
13637 Check_No_Identifiers;
13638 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13639 Check_Valid_Configuration_Pragma;
13640 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13641 DP := Fold_Upper (Name_Buffer (1));
13643 if Task_Dispatching_Policy /= ' '
13644 and then Task_Dispatching_Policy /= DP
13646 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13648 ("task dispatching policy incompatible with policy#");
13650 -- Set new policy, but always preserve System_Location since we
13651 -- like the error message with the run time name.
13654 Task_Dispatching_Policy := DP;
13656 if Task_Dispatching_Policy_Sloc /= System_Location then
13657 Task_Dispatching_Policy_Sloc := Loc;
13666 -- pragma Task_Info (EXPRESSION);
13668 when Pragma_Task_Info => Task_Info : declare
13669 P : constant Node_Id := Parent (N);
13674 if Nkind (P) /= N_Task_Definition then
13675 Error_Pragma ("pragma% must appear in task definition");
13678 Check_No_Identifiers;
13679 Check_Arg_Count (1);
13681 Analyze_And_Resolve
13682 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13684 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13688 if Has_Task_Info_Pragma (P) then
13689 Error_Pragma ("duplicate pragma% not allowed");
13691 Set_Has_Task_Info_Pragma (P, True);
13699 -- pragma Task_Name (string_EXPRESSION);
13701 when Pragma_Task_Name => Task_Name : declare
13702 P : constant Node_Id := Parent (N);
13706 Check_No_Identifiers;
13707 Check_Arg_Count (1);
13709 Arg := Get_Pragma_Arg (Arg1);
13711 -- The expression is used in the call to Create_Task, and must be
13712 -- expanded there, not in the context of the current spec. It must
13713 -- however be analyzed to capture global references, in case it
13714 -- appears in a generic context.
13716 Preanalyze_And_Resolve (Arg, Standard_String);
13718 if Nkind (P) /= N_Task_Definition then
13722 if Has_Task_Name_Pragma (P) then
13723 Error_Pragma ("duplicate pragma% not allowed");
13725 Set_Has_Task_Name_Pragma (P, True);
13726 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13734 -- pragma Task_Storage (
13735 -- [Task_Type =>] LOCAL_NAME,
13736 -- [Top_Guard =>] static_integer_EXPRESSION);
13738 when Pragma_Task_Storage => Task_Storage : declare
13739 Args : Args_List (1 .. 2);
13740 Names : constant Name_List (1 .. 2) := (
13744 Task_Type : Node_Id renames Args (1);
13745 Top_Guard : Node_Id renames Args (2);
13751 Gather_Associations (Names, Args);
13753 if No (Task_Type) then
13755 ("missing task_type argument for pragma%");
13758 Check_Arg_Is_Local_Name (Task_Type);
13760 Ent := Entity (Task_Type);
13762 if not Is_Task_Type (Ent) then
13764 ("argument for pragma% must be task type", Task_Type);
13767 if No (Top_Guard) then
13769 ("pragma% takes two arguments", Task_Type);
13771 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13774 Check_First_Subtype (Task_Type);
13776 if Rep_Item_Too_Late (Ent, N) then
13785 -- pragma Test_Case ([Name =>] Static_String_EXPRESSION
13786 -- ,[Mode =>] MODE_TYPE
13787 -- [, Requires => Boolean_EXPRESSION]
13788 -- [, Ensures => Boolean_EXPRESSION]);
13790 -- MODE_TYPE ::= Nominal | Robustness
13792 when Pragma_Test_Case => Test_Case : declare
13795 Check_At_Least_N_Arguments (2);
13796 Check_At_Most_N_Arguments (4);
13798 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13800 Check_Optional_Identifier (Arg1, Name_Name);
13801 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13803 -- In ASIS mode, for a pragma generated from a source aspect, also
13804 -- analyze the original aspect expression.
13807 and then Present (Corresponding_Aspect (N))
13809 Check_Expr_Is_Static_Expression
13810 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
13813 Check_Optional_Identifier (Arg2, Name_Mode);
13814 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13816 if Arg_Count = 4 then
13817 Check_Identifier (Arg3, Name_Requires);
13818 Check_Identifier (Arg4, Name_Ensures);
13820 elsif Arg_Count = 3 then
13821 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13827 --------------------------
13828 -- Thread_Local_Storage --
13829 --------------------------
13831 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13833 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13839 Check_Arg_Count (1);
13840 Check_Optional_Identifier (Arg1, Name_Entity);
13841 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13843 Id := Get_Pragma_Arg (Arg1);
13846 if not Is_Entity_Name (Id)
13847 or else Ekind (Entity (Id)) /= E_Variable
13849 Error_Pragma_Arg ("local variable name required", Arg1);
13854 if Rep_Item_Too_Early (E, N)
13855 or else Rep_Item_Too_Late (E, N)
13860 Set_Has_Pragma_Thread_Local_Storage (E);
13861 Set_Has_Gigi_Rep_Item (E);
13862 end Thread_Local_Storage;
13868 -- pragma Time_Slice (static_duration_EXPRESSION);
13870 when Pragma_Time_Slice => Time_Slice : declare
13876 Check_Arg_Count (1);
13877 Check_No_Identifiers;
13878 Check_In_Main_Program;
13879 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13881 if not Error_Posted (Arg1) then
13883 while Present (Nod) loop
13884 if Nkind (Nod) = N_Pragma
13885 and then Pragma_Name (Nod) = Name_Time_Slice
13887 Error_Msg_Name_1 := Pname;
13888 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13895 -- Process only if in main unit
13897 if Get_Source_Unit (Loc) = Main_Unit then
13898 Opt.Time_Slice_Set := True;
13899 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13901 if Val <= Ureal_0 then
13902 Opt.Time_Slice_Value := 0;
13904 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13905 Opt.Time_Slice_Value := 1_000_000_000;
13908 Opt.Time_Slice_Value :=
13909 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13918 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13920 -- TITLING_OPTION ::=
13921 -- [Title =>] STRING_LITERAL
13922 -- | [Subtitle =>] STRING_LITERAL
13924 when Pragma_Title => Title : declare
13925 Args : Args_List (1 .. 2);
13926 Names : constant Name_List (1 .. 2) := (
13932 Gather_Associations (Names, Args);
13935 for J in 1 .. 2 loop
13936 if Present (Args (J)) then
13937 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13942 ---------------------
13943 -- Unchecked_Union --
13944 ---------------------
13946 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13948 when Pragma_Unchecked_Union => Unchecked_Union : declare
13949 Assoc : constant Node_Id := Arg1;
13950 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13961 Check_No_Identifiers;
13962 Check_Arg_Count (1);
13963 Check_Arg_Is_Local_Name (Arg1);
13965 Find_Type (Type_Id);
13966 Typ := Entity (Type_Id);
13969 or else Rep_Item_Too_Early (Typ, N)
13973 Typ := Underlying_Type (Typ);
13976 if Rep_Item_Too_Late (Typ, N) then
13980 Check_First_Subtype (Arg1);
13982 -- Note remaining cases are references to a type in the current
13983 -- declarative part. If we find an error, we post the error on
13984 -- the relevant type declaration at an appropriate point.
13986 if not Is_Record_Type (Typ) then
13987 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13990 elsif Is_Tagged_Type (Typ) then
13991 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13994 elsif not Has_Discriminants (Typ) then
13996 ("Unchecked_Union must have one discriminant", Typ);
13999 -- Note: in previous versions of GNAT we used to check for limited
14000 -- types and give an error, but in fact the standard does allow
14001 -- Unchecked_Union on limited types, so this check was removed.
14003 -- Proceed with basic error checks completed
14006 Discr := First_Discriminant (Typ);
14007 while Present (Discr) loop
14008 if No (Discriminant_Default_Value (Discr)) then
14010 ("Unchecked_Union discriminant must have default value",
14014 Next_Discriminant (Discr);
14017 Tdef := Type_Definition (Declaration_Node (Typ));
14018 Clist := Component_List (Tdef);
14020 Comp := First (Component_Items (Clist));
14021 while Present (Comp) loop
14022 Check_Component (Comp, Typ);
14026 if No (Clist) or else No (Variant_Part (Clist)) then
14028 ("Unchecked_Union must have variant part",
14033 Vpart := Variant_Part (Clist);
14035 Variant := First (Variants (Vpart));
14036 while Present (Variant) loop
14037 Check_Variant (Variant, Typ);
14042 Set_Is_Unchecked_Union (Typ);
14043 Set_Convention (Typ, Convention_C);
14044 Set_Has_Unchecked_Union (Base_Type (Typ));
14045 Set_Is_Unchecked_Union (Base_Type (Typ));
14046 end Unchecked_Union;
14048 ------------------------
14049 -- Unimplemented_Unit --
14050 ------------------------
14052 -- pragma Unimplemented_Unit;
14054 -- Note: this only gives an error if we are generating code, or if
14055 -- we are in a generic library unit (where the pragma appears in the
14056 -- body, not in the spec).
14058 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
14059 Cunitent : constant Entity_Id :=
14060 Cunit_Entity (Get_Source_Unit (Loc));
14061 Ent_Kind : constant Entity_Kind :=
14066 Check_Arg_Count (0);
14068 if Operating_Mode = Generate_Code
14069 or else Ent_Kind = E_Generic_Function
14070 or else Ent_Kind = E_Generic_Procedure
14071 or else Ent_Kind = E_Generic_Package
14073 Get_Name_String (Chars (Cunitent));
14074 Set_Casing (Mixed_Case);
14075 Write_Str (Name_Buffer (1 .. Name_Len));
14076 Write_Str (" is not supported in this configuration");
14078 raise Unrecoverable_Error;
14080 end Unimplemented_Unit;
14082 ------------------------
14083 -- Universal_Aliasing --
14084 ------------------------
14086 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
14088 when Pragma_Universal_Aliasing => Universal_Alias : declare
14093 Check_Arg_Count (1);
14094 Check_Optional_Identifier (Arg2, Name_Entity);
14095 Check_Arg_Is_Local_Name (Arg1);
14096 E_Id := Entity (Get_Pragma_Arg (Arg1));
14098 if E_Id = Any_Type then
14100 elsif No (E_Id) or else not Is_Type (E_Id) then
14101 Error_Pragma_Arg ("pragma% requires type", Arg1);
14104 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
14105 end Universal_Alias;
14107 --------------------
14108 -- Universal_Data --
14109 --------------------
14111 -- pragma Universal_Data [(library_unit_NAME)];
14113 when Pragma_Universal_Data =>
14116 -- If this is a configuration pragma, then set the universal
14117 -- addressing option, otherwise confirm that the pragma satisfies
14118 -- the requirements of library unit pragma placement and leave it
14119 -- to the GNAAMP back end to detect the pragma (avoids transitive
14120 -- setting of the option due to withed units).
14122 if Is_Configuration_Pragma then
14123 Universal_Addressing_On_AAMP := True;
14125 Check_Valid_Library_Unit_Pragma;
14128 if not AAMP_On_Target then
14129 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
14136 -- pragma Unmodified (local_Name {, local_Name});
14138 when Pragma_Unmodified => Unmodified : declare
14139 Arg_Node : Node_Id;
14140 Arg_Expr : Node_Id;
14141 Arg_Ent : Entity_Id;
14145 Check_At_Least_N_Arguments (1);
14147 -- Loop through arguments
14150 while Present (Arg_Node) loop
14151 Check_No_Identifier (Arg_Node);
14153 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
14154 -- in fact generate reference, so that the entity will have a
14155 -- reference, which will inhibit any warnings about it not
14156 -- being referenced, and also properly show up in the ali file
14157 -- as a reference. But this reference is recorded before the
14158 -- Has_Pragma_Unreferenced flag is set, so that no warning is
14159 -- generated for this reference.
14161 Check_Arg_Is_Local_Name (Arg_Node);
14162 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14164 if Is_Entity_Name (Arg_Expr) then
14165 Arg_Ent := Entity (Arg_Expr);
14167 if not Is_Assignable (Arg_Ent) then
14169 ("pragma% can only be applied to a variable",
14172 Set_Has_Pragma_Unmodified (Arg_Ent);
14184 -- pragma Unreferenced (local_Name {, local_Name});
14186 -- or when used in a context clause:
14188 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
14190 when Pragma_Unreferenced => Unreferenced : declare
14191 Arg_Node : Node_Id;
14192 Arg_Expr : Node_Id;
14193 Arg_Ent : Entity_Id;
14198 Check_At_Least_N_Arguments (1);
14200 -- Check case of appearing within context clause
14202 if Is_In_Context_Clause then
14204 -- The arguments must all be units mentioned in a with clause
14205 -- in the same context clause. Note we already checked (in
14206 -- Par.Prag) that the arguments are either identifiers or
14207 -- selected components.
14210 while Present (Arg_Node) loop
14211 Citem := First (List_Containing (N));
14212 while Citem /= N loop
14213 if Nkind (Citem) = N_With_Clause
14215 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
14217 Set_Has_Pragma_Unreferenced
14220 (Library_Unit (Citem))));
14222 (Get_Pragma_Arg (Arg_Node), Name (Citem));
14231 ("argument of pragma% is not with'ed unit", Arg_Node);
14237 -- Case of not in list of context items
14241 while Present (Arg_Node) loop
14242 Check_No_Identifier (Arg_Node);
14244 -- Note: the analyze call done by Check_Arg_Is_Local_Name
14245 -- will in fact generate reference, so that the entity will
14246 -- have a reference, which will inhibit any warnings about
14247 -- it not being referenced, and also properly show up in the
14248 -- ali file as a reference. But this reference is recorded
14249 -- before the Has_Pragma_Unreferenced flag is set, so that
14250 -- no warning is generated for this reference.
14252 Check_Arg_Is_Local_Name (Arg_Node);
14253 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14255 if Is_Entity_Name (Arg_Expr) then
14256 Arg_Ent := Entity (Arg_Expr);
14258 -- If the entity is overloaded, the pragma applies to the
14259 -- most recent overloading, as documented. In this case,
14260 -- name resolution does not generate a reference, so it
14261 -- must be done here explicitly.
14263 if Is_Overloaded (Arg_Expr) then
14264 Generate_Reference (Arg_Ent, N);
14267 Set_Has_Pragma_Unreferenced (Arg_Ent);
14275 --------------------------
14276 -- Unreferenced_Objects --
14277 --------------------------
14279 -- pragma Unreferenced_Objects (local_Name {, local_Name});
14281 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
14282 Arg_Node : Node_Id;
14283 Arg_Expr : Node_Id;
14287 Check_At_Least_N_Arguments (1);
14290 while Present (Arg_Node) loop
14291 Check_No_Identifier (Arg_Node);
14292 Check_Arg_Is_Local_Name (Arg_Node);
14293 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14295 if not Is_Entity_Name (Arg_Expr)
14296 or else not Is_Type (Entity (Arg_Expr))
14299 ("argument for pragma% must be type or subtype", Arg_Node);
14302 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
14305 end Unreferenced_Objects;
14307 ------------------------------
14308 -- Unreserve_All_Interrupts --
14309 ------------------------------
14311 -- pragma Unreserve_All_Interrupts;
14313 when Pragma_Unreserve_All_Interrupts =>
14315 Check_Arg_Count (0);
14317 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
14318 Unreserve_All_Interrupts := True;
14325 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
14327 when Pragma_Unsuppress =>
14329 Process_Suppress_Unsuppress (False);
14331 -------------------
14332 -- Use_VADS_Size --
14333 -------------------
14335 -- pragma Use_VADS_Size;
14337 when Pragma_Use_VADS_Size =>
14339 Check_Arg_Count (0);
14340 Check_Valid_Configuration_Pragma;
14341 Use_VADS_Size := True;
14343 ---------------------
14344 -- Validity_Checks --
14345 ---------------------
14347 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14349 when Pragma_Validity_Checks => Validity_Checks : declare
14350 A : constant Node_Id := Get_Pragma_Arg (Arg1);
14356 Check_Arg_Count (1);
14357 Check_No_Identifiers;
14359 if Nkind (A) = N_String_Literal then
14363 Slen : constant Natural := Natural (String_Length (S));
14364 Options : String (1 .. Slen);
14370 C := Get_String_Char (S, Int (J));
14371 exit when not In_Character_Range (C);
14372 Options (J) := Get_Character (C);
14375 Set_Validity_Check_Options (Options);
14383 elsif Nkind (A) = N_Identifier then
14384 if Chars (A) = Name_All_Checks then
14385 Set_Validity_Check_Options ("a");
14386 elsif Chars (A) = Name_On then
14387 Validity_Checks_On := True;
14388 elsif Chars (A) = Name_Off then
14389 Validity_Checks_On := False;
14392 end Validity_Checks;
14398 -- pragma Volatile (LOCAL_NAME);
14400 when Pragma_Volatile =>
14401 Process_Atomic_Shared_Volatile;
14403 -------------------------
14404 -- Volatile_Components --
14405 -------------------------
14407 -- pragma Volatile_Components (array_LOCAL_NAME);
14409 -- Volatile is handled by the same circuit as Atomic_Components
14415 -- pragma Warnings (On | Off);
14416 -- pragma Warnings (On | Off, LOCAL_NAME);
14417 -- pragma Warnings (static_string_EXPRESSION);
14418 -- pragma Warnings (On | Off, STRING_LITERAL);
14420 when Pragma_Warnings => Warnings : begin
14422 Check_At_Least_N_Arguments (1);
14423 Check_No_Identifiers;
14425 -- If debug flag -gnatd.i is set, pragma is ignored
14427 if Debug_Flag_Dot_I then
14431 -- Process various forms of the pragma
14434 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14437 -- One argument case
14439 if Arg_Count = 1 then
14441 -- On/Off one argument case was processed by parser
14443 if Nkind (Argx) = N_Identifier
14445 (Chars (Argx) = Name_On
14447 Chars (Argx) = Name_Off)
14451 -- One argument case must be ON/OFF or static string expr
14453 elsif not Is_Static_String_Expression (Arg1) then
14455 ("argument of pragma% must be On/Off or " &
14456 "static string expression", Arg1);
14458 -- One argument string expression case
14462 Lit : constant Node_Id := Expr_Value_S (Argx);
14463 Str : constant String_Id := Strval (Lit);
14464 Len : constant Nat := String_Length (Str);
14472 while J <= Len loop
14473 C := Get_String_Char (Str, J);
14474 OK := In_Character_Range (C);
14477 Chr := Get_Character (C);
14481 if J < Len and then Chr = '.' then
14483 C := Get_String_Char (Str, J);
14484 Chr := Get_Character (C);
14486 if not Set_Dot_Warning_Switch (Chr) then
14488 ("invalid warning switch character " &
14495 OK := Set_Warning_Switch (Chr);
14501 ("invalid warning switch character " & Chr,
14510 -- Two or more arguments (must be two)
14513 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14514 Check_At_Most_N_Arguments (2);
14522 E_Id := Get_Pragma_Arg (Arg2);
14525 -- In the expansion of an inlined body, a reference to
14526 -- the formal may be wrapped in a conversion if the
14527 -- actual is a conversion. Retrieve the real entity name.
14529 if (In_Instance_Body or else In_Inlined_Body)
14530 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14532 E_Id := Expression (E_Id);
14535 -- Entity name case
14537 if Is_Entity_Name (E_Id) then
14538 E := Entity (E_Id);
14545 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14548 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14549 and then Warn_On_Warnings_Off
14551 Warnings_Off_Pragmas.Append ((N, E));
14554 if Is_Enumeration_Type (E) then
14558 Lit := First_Literal (E);
14559 while Present (Lit) loop
14560 Set_Warnings_Off (Lit);
14561 Next_Literal (Lit);
14566 exit when No (Homonym (E));
14571 -- Error if not entity or static string literal case
14573 elsif not Is_Static_String_Expression (Arg2) then
14575 ("second argument of pragma% must be entity " &
14576 "name or static string expression", Arg2);
14578 -- String literal case
14581 String_To_Name_Buffer
14582 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14584 -- Note on configuration pragma case: If this is a
14585 -- configuration pragma, then for an OFF pragma, we
14586 -- just set Config True in the call, which is all
14587 -- that needs to be done. For the case of ON, this
14588 -- is normally an error, unless it is canceling the
14589 -- effect of a previous OFF pragma in the same file.
14590 -- In any other case, an error will be signalled (ON
14591 -- with no matching OFF).
14593 -- Note: We set Used if we are inside a generic to
14594 -- disable the test that the non-config case actually
14595 -- cancels a warning. That's because we can't be sure
14596 -- there isn't an instantiation in some other unit
14597 -- where a warning is suppressed.
14599 -- We could do a little better here by checking if the
14600 -- generic unit we are inside is public, but for now
14601 -- we don't bother with that refinement.
14603 if Chars (Argx) = Name_Off then
14604 Set_Specific_Warning_Off
14605 (Loc, Name_Buffer (1 .. Name_Len),
14606 Config => Is_Configuration_Pragma,
14607 Used => Inside_A_Generic or else In_Instance);
14609 elsif Chars (Argx) = Name_On then
14610 Set_Specific_Warning_On
14611 (Loc, Name_Buffer (1 .. Name_Len), Err);
14615 ("?pragma Warnings On with no " &
14616 "matching Warnings Off",
14626 -------------------
14627 -- Weak_External --
14628 -------------------
14630 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
14632 when Pragma_Weak_External => Weak_External : declare
14637 Check_Arg_Count (1);
14638 Check_Optional_Identifier (Arg1, Name_Entity);
14639 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14640 Ent := Entity (Get_Pragma_Arg (Arg1));
14642 if Rep_Item_Too_Early (Ent, N) then
14645 Ent := Underlying_Type (Ent);
14648 -- The only processing required is to link this item on to the
14649 -- list of rep items for the given entity. This is accomplished
14650 -- by the call to Rep_Item_Too_Late (when no error is detected
14651 -- and False is returned).
14653 if Rep_Item_Too_Late (Ent, N) then
14656 Set_Has_Gigi_Rep_Item (Ent);
14660 -----------------------------
14661 -- Wide_Character_Encoding --
14662 -----------------------------
14664 -- pragma Wide_Character_Encoding (IDENTIFIER);
14666 when Pragma_Wide_Character_Encoding =>
14669 -- Nothing to do, handled in parser. Note that we do not enforce
14670 -- configuration pragma placement, this pragma can appear at any
14671 -- place in the source, allowing mixed encodings within a single
14676 --------------------
14677 -- Unknown_Pragma --
14678 --------------------
14680 -- Should be impossible, since the case of an unknown pragma is
14681 -- separately processed before the case statement is entered.
14683 when Unknown_Pragma =>
14684 raise Program_Error;
14687 -- AI05-0144: detect dangerous order dependence. Disabled for now,
14688 -- until AI is formally approved.
14690 -- Check_Order_Dependence;
14693 when Pragma_Exit => null;
14694 end Analyze_Pragma;
14696 -----------------------------
14697 -- Analyze_TC_In_Decl_Part --
14698 -----------------------------
14700 procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14702 -- Install formals and push subprogram spec onto scope stack so that we
14703 -- can see the formals from the pragma.
14705 Install_Formals (S);
14708 -- Preanalyze the boolean expressions, we treat these as spec
14709 -- expressions (i.e. similar to a default expression).
14711 Preanalyze_TC_Args (N,
14712 Get_Requires_From_Test_Case_Pragma (N),
14713 Get_Ensures_From_Test_Case_Pragma (N));
14715 -- Remove the subprogram from the scope stack now that the pre-analysis
14716 -- of the expressions in the test-case is done.
14719 end Analyze_TC_In_Decl_Part;
14721 --------------------
14722 -- Check_Disabled --
14723 --------------------
14725 function Check_Disabled (Nam : Name_Id) return Boolean is
14729 -- Loop through entries in check policy list
14731 PP := Opt.Check_Policy_List;
14733 -- If there are no specific entries that matched, then nothing is
14734 -- disabled, so return False.
14739 -- Here we have an entry see if it matches
14743 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14745 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14746 return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14748 PP := Next_Pragma (PP);
14753 end Check_Disabled;
14755 -------------------
14756 -- Check_Enabled --
14757 -------------------
14759 function Check_Enabled (Nam : Name_Id) return Boolean is
14763 -- Loop through entries in check policy list
14765 PP := Opt.Check_Policy_List;
14767 -- If there are no specific entries that matched, then we let the
14768 -- setting of assertions govern. Note that this provides the needed
14769 -- compatibility with the RM for the cases of assertion, invariant,
14770 -- precondition, predicate, and postcondition.
14773 return Assertions_Enabled;
14775 -- Here we have an entry see if it matches
14779 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14782 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14783 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14784 when Name_On | Name_Check =>
14786 when Name_Off | Name_Ignore =>
14789 raise Program_Error;
14793 PP := Next_Pragma (PP);
14800 ---------------------------------
14801 -- Delay_Config_Pragma_Analyze --
14802 ---------------------------------
14804 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14806 return Pragma_Name (N) = Name_Interrupt_State
14808 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14809 end Delay_Config_Pragma_Analyze;
14811 -------------------------
14812 -- Get_Base_Subprogram --
14813 -------------------------
14815 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14816 Result : Entity_Id;
14819 -- Follow subprogram renaming chain
14822 while Is_Subprogram (Result)
14824 Nkind (Parent (Declaration_Node (Result))) =
14825 N_Subprogram_Renaming_Declaration
14826 and then Present (Alias (Result))
14828 Result := Alias (Result);
14832 end Get_Base_Subprogram;
14838 procedure Initialize is
14843 -----------------------------
14844 -- Is_Config_Static_String --
14845 -----------------------------
14847 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14849 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14850 -- This is an internal recursive function that is just like the outer
14851 -- function except that it adds the string to the name buffer rather
14852 -- than placing the string in the name buffer.
14854 ------------------------------
14855 -- Add_Config_Static_String --
14856 ------------------------------
14858 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14865 if Nkind (N) = N_Op_Concat then
14866 if Add_Config_Static_String (Left_Opnd (N)) then
14867 N := Right_Opnd (N);
14873 if Nkind (N) /= N_String_Literal then
14874 Error_Msg_N ("string literal expected for pragma argument", N);
14878 for J in 1 .. String_Length (Strval (N)) loop
14879 C := Get_String_Char (Strval (N), J);
14881 if not In_Character_Range (C) then
14883 ("string literal contains invalid wide character",
14884 Sloc (N) + 1 + Source_Ptr (J));
14888 Add_Char_To_Name_Buffer (Get_Character (C));
14893 end Add_Config_Static_String;
14895 -- Start of processing for Is_Config_Static_String
14900 return Add_Config_Static_String (Arg);
14901 end Is_Config_Static_String;
14903 -----------------------------------------
14904 -- Is_Non_Significant_Pragma_Reference --
14905 -----------------------------------------
14907 -- This function makes use of the following static table which indicates
14908 -- whether a given pragma is significant.
14910 -- -1 indicates that references in any argument position are significant
14911 -- 0 indicates that appearance in any argument is not significant
14912 -- +n indicates that appearance as argument n is significant, but all
14913 -- other arguments are not significant
14914 -- 99 special processing required (e.g. for pragma Check)
14916 Sig_Flags : constant array (Pragma_Id) of Int :=
14917 (Pragma_AST_Entry => -1,
14918 Pragma_Abort_Defer => -1,
14919 Pragma_Ada_83 => -1,
14920 Pragma_Ada_95 => -1,
14921 Pragma_Ada_05 => -1,
14922 Pragma_Ada_2005 => -1,
14923 Pragma_Ada_12 => -1,
14924 Pragma_Ada_2012 => -1,
14925 Pragma_All_Calls_Remote => -1,
14926 Pragma_Annotate => -1,
14927 Pragma_Assert => -1,
14928 Pragma_Assertion_Policy => 0,
14929 Pragma_Assume_No_Invalid_Values => 0,
14930 Pragma_Asynchronous => -1,
14931 Pragma_Atomic => 0,
14932 Pragma_Atomic_Components => 0,
14933 Pragma_Attach_Handler => -1,
14934 Pragma_Check => 99,
14935 Pragma_Check_Name => 0,
14936 Pragma_Check_Policy => 0,
14937 Pragma_CIL_Constructor => -1,
14938 Pragma_CPP_Class => 0,
14939 Pragma_CPP_Constructor => 0,
14940 Pragma_CPP_Virtual => 0,
14941 Pragma_CPP_Vtable => 0,
14943 Pragma_C_Pass_By_Copy => 0,
14944 Pragma_Comment => 0,
14945 Pragma_Common_Object => -1,
14946 Pragma_Compile_Time_Error => -1,
14947 Pragma_Compile_Time_Warning => -1,
14948 Pragma_Compiler_Unit => 0,
14949 Pragma_Complete_Representation => 0,
14950 Pragma_Complex_Representation => 0,
14951 Pragma_Component_Alignment => -1,
14952 Pragma_Controlled => 0,
14953 Pragma_Convention => 0,
14954 Pragma_Convention_Identifier => 0,
14955 Pragma_Debug => -1,
14956 Pragma_Debug_Policy => 0,
14957 Pragma_Detect_Blocking => -1,
14958 Pragma_Default_Storage_Pool => -1,
14959 Pragma_Dimension => -1,
14960 Pragma_Disable_Atomic_Synchronization => -1,
14961 Pragma_Discard_Names => 0,
14962 Pragma_Dispatching_Domain => -1,
14963 Pragma_Elaborate => -1,
14964 Pragma_Elaborate_All => -1,
14965 Pragma_Elaborate_Body => -1,
14966 Pragma_Elaboration_Checks => -1,
14967 Pragma_Eliminate => -1,
14968 Pragma_Enable_Atomic_Synchronization => -1,
14969 Pragma_Export => -1,
14970 Pragma_Export_Exception => -1,
14971 Pragma_Export_Function => -1,
14972 Pragma_Export_Object => -1,
14973 Pragma_Export_Procedure => -1,
14974 Pragma_Export_Value => -1,
14975 Pragma_Export_Valued_Procedure => -1,
14976 Pragma_Extend_System => -1,
14977 Pragma_Extensions_Allowed => -1,
14978 Pragma_External => -1,
14979 Pragma_Favor_Top_Level => -1,
14980 Pragma_External_Name_Casing => -1,
14981 Pragma_Fast_Math => -1,
14982 Pragma_Finalize_Storage_Only => 0,
14983 Pragma_Float_Representation => 0,
14984 Pragma_Ident => -1,
14985 Pragma_Implementation_Defined => -1,
14986 Pragma_Implemented => -1,
14987 Pragma_Implicit_Packing => 0,
14988 Pragma_Import => +2,
14989 Pragma_Import_Exception => 0,
14990 Pragma_Import_Function => 0,
14991 Pragma_Import_Object => 0,
14992 Pragma_Import_Procedure => 0,
14993 Pragma_Import_Valued_Procedure => 0,
14994 Pragma_Independent => 0,
14995 Pragma_Independent_Components => 0,
14996 Pragma_Initialize_Scalars => -1,
14997 Pragma_Inline => 0,
14998 Pragma_Inline_Always => 0,
14999 Pragma_Inline_Generic => 0,
15000 Pragma_Inspection_Point => -1,
15001 Pragma_Interface => +2,
15002 Pragma_Interface_Name => +2,
15003 Pragma_Interrupt_Handler => -1,
15004 Pragma_Interrupt_Priority => -1,
15005 Pragma_Interrupt_State => -1,
15006 Pragma_Invariant => -1,
15007 Pragma_Java_Constructor => -1,
15008 Pragma_Java_Interface => -1,
15009 Pragma_Keep_Names => 0,
15010 Pragma_License => -1,
15011 Pragma_Link_With => -1,
15012 Pragma_Linker_Alias => -1,
15013 Pragma_Linker_Constructor => -1,
15014 Pragma_Linker_Destructor => -1,
15015 Pragma_Linker_Options => -1,
15016 Pragma_Linker_Section => -1,
15018 Pragma_Locking_Policy => -1,
15019 Pragma_Long_Float => -1,
15020 Pragma_Machine_Attribute => -1,
15022 Pragma_Main_Storage => -1,
15023 Pragma_Memory_Size => -1,
15024 Pragma_No_Return => 0,
15025 Pragma_No_Body => 0,
15026 Pragma_No_Run_Time => -1,
15027 Pragma_No_Strict_Aliasing => -1,
15028 Pragma_Normalize_Scalars => -1,
15029 Pragma_Obsolescent => 0,
15030 Pragma_Optimize => -1,
15031 Pragma_Optimize_Alignment => -1,
15032 Pragma_Ordered => 0,
15035 Pragma_Passive => -1,
15036 Pragma_Preelaborable_Initialization => -1,
15037 Pragma_Polling => -1,
15038 Pragma_Persistent_BSS => 0,
15039 Pragma_Postcondition => -1,
15040 Pragma_Precondition => -1,
15041 Pragma_Predicate => -1,
15042 Pragma_Preelaborate => -1,
15043 Pragma_Preelaborate_05 => -1,
15044 Pragma_Priority => -1,
15045 Pragma_Priority_Specific_Dispatching => -1,
15046 Pragma_Profile => 0,
15047 Pragma_Profile_Warnings => 0,
15048 Pragma_Propagate_Exceptions => -1,
15049 Pragma_Psect_Object => -1,
15051 Pragma_Pure_05 => -1,
15052 Pragma_Pure_12 => -1,
15053 Pragma_Pure_Function => -1,
15054 Pragma_Queuing_Policy => -1,
15055 Pragma_Ravenscar => -1,
15056 Pragma_Relative_Deadline => -1,
15057 Pragma_Remote_Call_Interface => -1,
15058 Pragma_Remote_Types => -1,
15059 Pragma_Restricted_Run_Time => -1,
15060 Pragma_Restriction_Warnings => -1,
15061 Pragma_Restrictions => -1,
15062 Pragma_Reviewable => -1,
15063 Pragma_Short_Circuit_And_Or => -1,
15064 Pragma_Share_Generic => -1,
15065 Pragma_Shared => -1,
15066 Pragma_Shared_Passive => -1,
15067 Pragma_Short_Descriptors => 0,
15068 Pragma_Source_File_Name => -1,
15069 Pragma_Source_File_Name_Project => -1,
15070 Pragma_Source_Reference => -1,
15071 Pragma_Storage_Size => -1,
15072 Pragma_Storage_Unit => -1,
15073 Pragma_Static_Elaboration_Desired => -1,
15074 Pragma_Stream_Convert => -1,
15075 Pragma_Style_Checks => -1,
15076 Pragma_Subtitle => -1,
15077 Pragma_Suppress => 0,
15078 Pragma_Suppress_Exception_Locations => 0,
15079 Pragma_Suppress_All => -1,
15080 Pragma_Suppress_Debug_Info => 0,
15081 Pragma_Suppress_Initialization => 0,
15082 Pragma_System_Name => -1,
15083 Pragma_Task_Dispatching_Policy => -1,
15084 Pragma_Task_Info => -1,
15085 Pragma_Task_Name => -1,
15086 Pragma_Task_Storage => 0,
15087 Pragma_Test_Case => -1,
15088 Pragma_Thread_Local_Storage => 0,
15089 Pragma_Time_Slice => -1,
15090 Pragma_Title => -1,
15091 Pragma_Unchecked_Union => 0,
15092 Pragma_Unimplemented_Unit => -1,
15093 Pragma_Universal_Aliasing => -1,
15094 Pragma_Universal_Data => -1,
15095 Pragma_Unmodified => -1,
15096 Pragma_Unreferenced => -1,
15097 Pragma_Unreferenced_Objects => -1,
15098 Pragma_Unreserve_All_Interrupts => -1,
15099 Pragma_Unsuppress => 0,
15100 Pragma_Use_VADS_Size => -1,
15101 Pragma_Validity_Checks => -1,
15102 Pragma_Volatile => 0,
15103 Pragma_Volatile_Components => 0,
15104 Pragma_Warnings => -1,
15105 Pragma_Weak_External => -1,
15106 Pragma_Wide_Character_Encoding => 0,
15107 Unknown_Pragma => 0);
15109 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
15118 if Nkind (P) /= N_Pragma_Argument_Association then
15122 Id := Get_Pragma_Id (Parent (P));
15123 C := Sig_Flags (Id);
15135 -- For pragma Check, the first argument is not significant,
15136 -- the second and the third (if present) arguments are
15139 when Pragma_Check =>
15141 P = First (Pragma_Argument_Associations (Parent (P)));
15144 raise Program_Error;
15148 A := First (Pragma_Argument_Associations (Parent (P)));
15149 for J in 1 .. C - 1 loop
15157 return A = P; -- is this wrong way round ???
15160 end Is_Non_Significant_Pragma_Reference;
15162 ------------------------------
15163 -- Is_Pragma_String_Literal --
15164 ------------------------------
15166 -- This function returns true if the corresponding pragma argument is a
15167 -- static string expression. These are the only cases in which string
15168 -- literals can appear as pragma arguments. We also allow a string literal
15169 -- as the first argument to pragma Assert (although it will of course
15170 -- always generate a type error).
15172 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
15173 Pragn : constant Node_Id := Parent (Par);
15174 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
15175 Pname : constant Name_Id := Pragma_Name (Pragn);
15181 N := First (Assoc);
15188 if Pname = Name_Assert then
15191 elsif Pname = Name_Export then
15194 elsif Pname = Name_Ident then
15197 elsif Pname = Name_Import then
15200 elsif Pname = Name_Interface_Name then
15203 elsif Pname = Name_Linker_Alias then
15206 elsif Pname = Name_Linker_Section then
15209 elsif Pname = Name_Machine_Attribute then
15212 elsif Pname = Name_Source_File_Name then
15215 elsif Pname = Name_Source_Reference then
15218 elsif Pname = Name_Title then
15221 elsif Pname = Name_Subtitle then
15227 end Is_Pragma_String_Literal;
15229 ------------------------
15230 -- Preanalyze_TC_Args --
15231 ------------------------
15233 procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
15235 -- Preanalyze the boolean expressions, we treat these as spec
15236 -- expressions (i.e. similar to a default expression).
15238 if Present (Arg_Req) then
15239 Preanalyze_Spec_Expression
15240 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
15242 -- In ASIS mode, for a pragma generated from a source aspect, also
15243 -- analyze the original aspect expression.
15246 and then Present (Corresponding_Aspect (N))
15248 Preanalyze_Spec_Expression
15249 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
15253 if Present (Arg_Ens) then
15254 Preanalyze_Spec_Expression
15255 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
15257 -- In ASIS mode, for a pragma generated from a source aspect, also
15258 -- analyze the original aspect expression.
15261 and then Present (Corresponding_Aspect (N))
15263 Preanalyze_Spec_Expression
15264 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
15267 end Preanalyze_TC_Args;
15269 --------------------------------------
15270 -- Process_Compilation_Unit_Pragmas --
15271 --------------------------------------
15273 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
15275 -- A special check for pragma Suppress_All, a very strange DEC pragma,
15276 -- strange because it comes at the end of the unit. Rational has the
15277 -- same name for a pragma, but treats it as a program unit pragma, In
15278 -- GNAT we just decide to allow it anywhere at all. If it appeared then
15279 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
15280 -- node, and we insert a pragma Suppress (All_Checks) at the start of
15281 -- the context clause to ensure the correct processing.
15283 if Has_Pragma_Suppress_All (N) then
15284 Prepend_To (Context_Items (N),
15285 Make_Pragma (Sloc (N),
15286 Chars => Name_Suppress,
15287 Pragma_Argument_Associations => New_List (
15288 Make_Pragma_Argument_Association (Sloc (N),
15289 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
15292 -- Nothing else to do at the current time!
15294 end Process_Compilation_Unit_Pragmas;
15305 --------------------------------
15306 -- Set_Encoded_Interface_Name --
15307 --------------------------------
15309 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
15310 Str : constant String_Id := Strval (S);
15311 Len : constant Int := String_Length (Str);
15316 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
15319 -- Stores encoded value of character code CC. The encoding we use an
15320 -- underscore followed by four lower case hex digits.
15326 procedure Encode is
15328 Store_String_Char (Get_Char_Code ('_'));
15330 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
15332 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
15334 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
15336 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
15339 -- Start of processing for Set_Encoded_Interface_Name
15342 -- If first character is asterisk, this is a link name, and we leave it
15343 -- completely unmodified. We also ignore null strings (the latter case
15344 -- happens only in error cases) and no encoding should occur for Java or
15345 -- AAMP interface names.
15348 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
15349 or else VM_Target /= No_VM
15350 or else AAMP_On_Target
15352 Set_Interface_Name (E, S);
15357 CC := Get_String_Char (Str, J);
15359 exit when not In_Character_Range (CC);
15361 C := Get_Character (CC);
15363 exit when C /= '_' and then C /= '$'
15364 and then C not in '0' .. '9'
15365 and then C not in 'a' .. 'z'
15366 and then C not in 'A' .. 'Z';
15369 Set_Interface_Name (E, S);
15377 -- Here we need to encode. The encoding we use as follows:
15378 -- three underscores + four hex digits (lower case)
15382 for J in 1 .. String_Length (Str) loop
15383 CC := Get_String_Char (Str, J);
15385 if not In_Character_Range (CC) then
15388 C := Get_Character (CC);
15390 if C = '_' or else C = '$'
15391 or else C in '0' .. '9'
15392 or else C in 'a' .. 'z'
15393 or else C in 'A' .. 'Z'
15395 Store_String_Char (CC);
15402 Set_Interface_Name (E,
15403 Make_String_Literal (Sloc (S),
15404 Strval => End_String));
15406 end Set_Encoded_Interface_Name;
15408 -------------------
15409 -- Set_Unit_Name --
15410 -------------------
15412 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15417 if Nkind (N) = N_Identifier
15418 and then Nkind (With_Item) = N_Identifier
15420 Set_Entity (N, Entity (With_Item));
15422 elsif Nkind (N) = N_Selected_Component then
15423 Change_Selected_Component_To_Expanded_Name (N);
15424 Set_Entity (N, Entity (With_Item));
15425 Set_Entity (Selector_Name (N), Entity (N));
15427 Pref := Prefix (N);
15428 Scop := Scope (Entity (N));
15429 while Nkind (Pref) = N_Selected_Component loop
15430 Change_Selected_Component_To_Expanded_Name (Pref);
15431 Set_Entity (Selector_Name (Pref), Scop);
15432 Set_Entity (Pref, Scop);
15433 Pref := Prefix (Pref);
15434 Scop := Scope (Scop);
15437 Set_Entity (Pref, Scop);