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);
1317 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1318 -- Determine whether entity Id appears inside a generic body.
1319 -- Shouldn't this be in a more general place ???
1321 -------------------------
1322 -- Inside_Generic_Body --
1323 -------------------------
1325 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1330 while Present (S) and then S /= Standard_Standard loop
1331 if Ekind (S) = E_Generic_Package
1332 and then In_Package_Body (S)
1341 end Inside_Generic_Body;
1343 -- Start of processing for Check_Component
1346 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1347 -- object constraint, then the component type shall be an Unchecked_
1350 if Nkind (Sindic) = N_Subtype_Indication
1351 and then Has_Per_Object_Constraint (Comp_Id)
1352 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1355 ("component subtype subject to per-object constraint " &
1356 "must be an Unchecked_Union", Comp);
1358 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1359 -- the body of a generic unit, or within the body of any of its
1360 -- descendant library units, no part of the type of a component
1361 -- declared in a variant_part of the unchecked union type shall be of
1362 -- a formal private type or formal private extension declared within
1363 -- the formal part of the generic unit.
1365 elsif Ada_Version >= Ada_2012
1366 and then Inside_Generic_Body (UU_Typ)
1367 and then In_Variant_Part
1368 and then Is_Private_Type (Typ)
1369 and then Is_Generic_Type (Typ)
1372 ("component of Unchecked_Union cannot be of generic type", Comp);
1374 elsif Needs_Finalization (Typ) then
1376 ("component of Unchecked_Union cannot be controlled", Comp);
1378 elsif Has_Task (Typ) then
1380 ("component of Unchecked_Union cannot have tasks", Comp);
1382 end Check_Component;
1384 ----------------------------
1385 -- Check_Duplicate_Pragma --
1386 ----------------------------
1388 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1392 -- Nothing to do if this pragma comes from an aspect specification,
1393 -- since we could not be duplicating a pragma, and we dealt with the
1394 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1396 if From_Aspect_Specification (N) then
1400 -- Otherwise current pragma may duplicate previous pragma or a
1401 -- previously given aspect specification for the same pragma.
1403 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1406 Error_Msg_Name_1 := Pragma_Name (N);
1407 Error_Msg_Sloc := Sloc (P);
1409 if Nkind (P) = N_Aspect_Specification
1410 or else From_Aspect_Specification (P)
1412 Error_Msg_NE ("aspect% for & previously given#", N, E);
1414 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1419 end Check_Duplicate_Pragma;
1421 ----------------------------------
1422 -- Check_Duplicated_Export_Name --
1423 ----------------------------------
1425 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1426 String_Val : constant String_Id := Strval (Nam);
1429 -- We are only interested in the export case, and in the case of
1430 -- generics, it is the instance, not the template, that is the
1431 -- problem (the template will generate a warning in any case).
1433 if not Inside_A_Generic
1434 and then (Prag_Id = Pragma_Export
1436 Prag_Id = Pragma_Export_Procedure
1438 Prag_Id = Pragma_Export_Valued_Procedure
1440 Prag_Id = Pragma_Export_Function)
1442 for J in Externals.First .. Externals.Last loop
1443 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1444 Error_Msg_Sloc := Sloc (Externals.Table (J));
1445 Error_Msg_N ("external name duplicates name given#", Nam);
1450 Externals.Append (Nam);
1452 end Check_Duplicated_Export_Name;
1454 -------------------------------------
1455 -- Check_Expr_Is_Static_Expression --
1456 -------------------------------------
1458 procedure Check_Expr_Is_Static_Expression
1460 Typ : Entity_Id := Empty)
1463 if Present (Typ) then
1464 Analyze_And_Resolve (Expr, Typ);
1466 Analyze_And_Resolve (Expr);
1469 if Is_OK_Static_Expression (Expr) then
1472 elsif Etype (Expr) = Any_Type then
1475 -- An interesting special case, if we have a string literal and we
1476 -- are in Ada 83 mode, then we allow it even though it will not be
1477 -- flagged as static. This allows the use of Ada 95 pragmas like
1478 -- Import in Ada 83 mode. They will of course be flagged with
1479 -- warnings as usual, but will not cause errors.
1481 elsif Ada_Version = Ada_83
1482 and then Nkind (Expr) = N_String_Literal
1486 -- Static expression that raises Constraint_Error. This has already
1487 -- been flagged, so just exit from pragma processing.
1489 elsif Is_Static_Expression (Expr) then
1492 -- Finally, we have a real error
1495 Error_Msg_Name_1 := Pname;
1499 "argument for pragma% must be a static expression!";
1502 Flag_Non_Static_Expr (Msg, Expr);
1507 end Check_Expr_Is_Static_Expression;
1509 -------------------------
1510 -- Check_First_Subtype --
1511 -------------------------
1513 procedure Check_First_Subtype (Arg : Node_Id) is
1514 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1515 Ent : constant Entity_Id := Entity (Argx);
1518 if Is_First_Subtype (Ent) then
1521 elsif Is_Type (Ent) then
1523 ("pragma% cannot apply to subtype", Argx);
1525 elsif Is_Object (Ent) then
1527 ("pragma% cannot apply to object, requires a type", Argx);
1531 ("pragma% cannot apply to&, requires a type", Argx);
1533 end Check_First_Subtype;
1535 ----------------------
1536 -- Check_Identifier --
1537 ----------------------
1539 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1542 and then Nkind (Arg) = N_Pragma_Argument_Association
1544 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1545 Error_Msg_Name_1 := Pname;
1546 Error_Msg_Name_2 := Id;
1547 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1551 end Check_Identifier;
1553 --------------------------------
1554 -- Check_Identifier_Is_One_Of --
1555 --------------------------------
1557 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1560 and then Nkind (Arg) = N_Pragma_Argument_Association
1562 if Chars (Arg) = No_Name then
1563 Error_Msg_Name_1 := Pname;
1564 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1567 elsif Chars (Arg) /= N1
1568 and then Chars (Arg) /= N2
1570 Error_Msg_Name_1 := Pname;
1571 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1575 end Check_Identifier_Is_One_Of;
1577 ---------------------------
1578 -- Check_In_Main_Program --
1579 ---------------------------
1581 procedure Check_In_Main_Program is
1582 P : constant Node_Id := Parent (N);
1585 -- Must be at in subprogram body
1587 if Nkind (P) /= N_Subprogram_Body then
1588 Error_Pragma ("% pragma allowed only in subprogram");
1590 -- Otherwise warn if obviously not main program
1592 elsif Present (Parameter_Specifications (Specification (P)))
1593 or else not Is_Compilation_Unit (Defining_Entity (P))
1595 Error_Msg_Name_1 := Pname;
1597 ("?pragma% is only effective in main program", N);
1599 end Check_In_Main_Program;
1601 ---------------------------------------
1602 -- Check_Interrupt_Or_Attach_Handler --
1603 ---------------------------------------
1605 procedure Check_Interrupt_Or_Attach_Handler is
1606 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1607 Handler_Proc, Proc_Scope : Entity_Id;
1612 if Prag_Id = Pragma_Interrupt_Handler then
1613 Check_Restriction (No_Dynamic_Attachment, N);
1616 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1617 Proc_Scope := Scope (Handler_Proc);
1619 -- On AAMP only, a pragma Interrupt_Handler is supported for
1620 -- nonprotected parameterless procedures.
1622 if not AAMP_On_Target
1623 or else Prag_Id = Pragma_Attach_Handler
1625 if Ekind (Proc_Scope) /= E_Protected_Type then
1627 ("argument of pragma% must be protected procedure", Arg1);
1630 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1631 Error_Pragma ("pragma% must be in protected definition");
1635 if not Is_Library_Level_Entity (Proc_Scope)
1636 or else (AAMP_On_Target
1637 and then not Is_Library_Level_Entity (Handler_Proc))
1640 ("argument for pragma% must be library level entity", Arg1);
1643 -- AI05-0033: A pragma cannot appear within a generic body, because
1644 -- instance can be in a nested scope. The check that protected type
1645 -- is itself a library-level declaration is done elsewhere.
1647 -- Note: we omit this check in Codepeer mode to properly handle code
1648 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1650 if Inside_A_Generic then
1651 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1652 and then In_Package_Body (Scope (Current_Scope))
1653 and then not CodePeer_Mode
1655 Error_Pragma ("pragma% cannot be used inside a generic");
1658 end Check_Interrupt_Or_Attach_Handler;
1660 -------------------------------------------
1661 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1662 -------------------------------------------
1664 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1673 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1676 elsif Nkind_In (P, N_Package_Specification,
1681 -- Note: the following tests seem a little peculiar, because
1682 -- they test for bodies, but if we were in the statement part
1683 -- of the body, we would already have hit the handled statement
1684 -- sequence, so the only way we get here is by being in the
1685 -- declarative part of the body.
1687 elsif Nkind_In (P, N_Subprogram_Body,
1698 Error_Pragma ("pragma% is not in declarative part or package spec");
1699 end Check_Is_In_Decl_Part_Or_Package_Spec;
1701 -------------------------
1702 -- Check_No_Identifier --
1703 -------------------------
1705 procedure Check_No_Identifier (Arg : Node_Id) is
1707 if Nkind (Arg) = N_Pragma_Argument_Association
1708 and then Chars (Arg) /= No_Name
1710 Error_Pragma_Arg_Ident
1711 ("pragma% does not permit identifier& here", Arg);
1713 end Check_No_Identifier;
1715 --------------------------
1716 -- Check_No_Identifiers --
1717 --------------------------
1719 procedure Check_No_Identifiers is
1722 if Arg_Count > 0 then
1724 while Present (Arg_Node) loop
1725 Check_No_Identifier (Arg_Node);
1729 end Check_No_Identifiers;
1731 ------------------------
1732 -- Check_No_Link_Name --
1733 ------------------------
1735 procedure Check_No_Link_Name is
1738 and then Chars (Arg3) = Name_Link_Name
1743 if Present (Arg4) then
1745 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1747 end Check_No_Link_Name;
1749 -------------------------------
1750 -- Check_Optional_Identifier --
1751 -------------------------------
1753 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1756 and then Nkind (Arg) = N_Pragma_Argument_Association
1757 and then Chars (Arg) /= No_Name
1759 if Chars (Arg) /= Id then
1760 Error_Msg_Name_1 := Pname;
1761 Error_Msg_Name_2 := Id;
1762 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1766 end Check_Optional_Identifier;
1768 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1770 Name_Buffer (1 .. Id'Length) := Id;
1771 Name_Len := Id'Length;
1772 Check_Optional_Identifier (Arg, Name_Find);
1773 end Check_Optional_Identifier;
1775 --------------------------------------
1776 -- Check_Precondition_Postcondition --
1777 --------------------------------------
1779 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1783 procedure Chain_PPC (PO : Node_Id);
1784 -- If PO is an entry or a [generic] subprogram declaration node, then
1785 -- the precondition/postcondition applies to this subprogram and the
1786 -- processing for the pragma is completed. Otherwise the pragma is
1793 procedure Chain_PPC (PO : Node_Id) is
1798 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1799 if not From_Aspect_Specification (N) then
1801 ("pragma% cannot be applied to abstract subprogram");
1803 elsif Class_Present (N) then
1808 ("aspect % requires ''Class for abstract subprogram");
1811 -- AI05-0230: The same restriction applies to null procedures. For
1812 -- compatibility with earlier uses of the Ada pragma, apply this
1813 -- rule only to aspect specifications.
1815 -- The above discrpency needs documentation. Robert is dubious
1816 -- about whether it is a good idea ???
1818 elsif Nkind (PO) = N_Subprogram_Declaration
1819 and then Nkind (Specification (PO)) = N_Procedure_Specification
1820 and then Null_Present (Specification (PO))
1821 and then From_Aspect_Specification (N)
1822 and then not Class_Present (N)
1825 ("aspect % requires ''Class for null procedure");
1827 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1828 N_Generic_Subprogram_Declaration,
1829 N_Entry_Declaration)
1834 -- Here if we have [generic] subprogram or entry declaration
1836 if Nkind (PO) = N_Entry_Declaration then
1837 S := Defining_Entity (PO);
1839 S := Defining_Unit_Name (Specification (PO));
1842 -- Make sure we do not have the case of a precondition pragma when
1843 -- the Pre'Class aspect is present.
1845 -- We do this by looking at pragmas already chained to the entity
1846 -- since the aspect derived pragma will be put on this list first.
1848 if Pragma_Name (N) = Name_Precondition then
1849 if not From_Aspect_Specification (N) then
1850 P := Spec_PPC_List (Contract (S));
1851 while Present (P) loop
1852 if Pragma_Name (P) = Name_Precondition
1853 and then From_Aspect_Specification (P)
1854 and then Class_Present (P)
1856 Error_Msg_Sloc := Sloc (P);
1858 ("pragma% not allowed, `Pre''Class` aspect given#");
1861 P := Next_Pragma (P);
1866 -- Similarly check for Pre with inherited Pre'Class. Note that
1867 -- we cover the aspect case as well here.
1869 if Pragma_Name (N) = Name_Precondition
1870 and then not Class_Present (N)
1873 Inherited : constant Subprogram_List :=
1874 Inherited_Subprograms (S);
1878 for J in Inherited'Range loop
1879 P := Spec_PPC_List (Contract (Inherited (J)));
1880 while Present (P) loop
1881 if Pragma_Name (P) = Name_Precondition
1882 and then Class_Present (P)
1884 Error_Msg_Sloc := Sloc (P);
1886 ("pragma% not allowed, `Pre''Class` "
1887 & "aspect inherited from#");
1890 P := Next_Pragma (P);
1896 -- Note: we do not analyze the pragma at this point. Instead we
1897 -- delay this analysis until the end of the declarative part in
1898 -- which the pragma appears. This implements the required delay
1899 -- in this analysis, allowing forward references. The analysis
1900 -- happens at the end of Analyze_Declarations.
1902 -- Chain spec PPC pragma to list for subprogram
1904 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1905 Set_Spec_PPC_List (Contract (S), N);
1907 -- Return indicating spec case
1913 -- Start of processing for Check_Precondition_Postcondition
1916 if not Is_List_Member (N) then
1920 -- Preanalyze message argument if present. Visibility in this
1921 -- argument is established at the point of pragma occurrence.
1923 if Arg_Count = 2 then
1924 Check_Optional_Identifier (Arg2, Name_Message);
1925 Preanalyze_Spec_Expression
1926 (Get_Pragma_Arg (Arg2), Standard_String);
1929 -- Record if pragma is disabled
1931 if Check_Enabled (Pname) then
1932 Set_SCO_Pragma_Enabled (Loc);
1935 -- If we are within an inlined body, the legality of the pragma
1936 -- has been checked already.
1938 if In_Inlined_Body then
1943 -- Search prior declarations
1946 while Present (Prev (P)) loop
1949 -- If the previous node is a generic subprogram, do not go to to
1950 -- the original node, which is the unanalyzed tree: we need to
1951 -- attach the pre/postconditions to the analyzed version at this
1952 -- point. They get propagated to the original tree when analyzing
1953 -- the corresponding body.
1955 if Nkind (P) not in N_Generic_Declaration then
1956 PO := Original_Node (P);
1961 -- Skip past prior pragma
1963 if Nkind (PO) = N_Pragma then
1966 -- Skip stuff not coming from source
1968 elsif not Comes_From_Source (PO) then
1970 -- The condition may apply to a subprogram instantiation
1972 if Nkind (PO) = N_Subprogram_Declaration
1973 and then Present (Generic_Parent (Specification (PO)))
1978 elsif Nkind (PO) = N_Subprogram_Declaration
1979 and then In_Instance
1984 -- For all other cases of non source code, do nothing
1990 -- Only remaining possibility is subprogram declaration
1998 -- If we fall through loop, pragma is at start of list, so see if it
1999 -- is at the start of declarations of a subprogram body.
2001 if Nkind (Parent (N)) = N_Subprogram_Body
2002 and then List_Containing (N) = Declarations (Parent (N))
2004 if Operating_Mode /= Generate_Code
2005 or else Inside_A_Generic
2007 -- Analyze pragma expression for correctness and for ASIS use
2009 Preanalyze_Spec_Expression
2010 (Get_Pragma_Arg (Arg1), Standard_Boolean);
2012 -- In ASIS mode, for a pragma generated from a source aspect,
2013 -- also analyze the original aspect expression.
2016 and then Present (Corresponding_Aspect (N))
2018 Preanalyze_Spec_Expression
2019 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2026 -- See if it is in the pragmas after a library level subprogram
2028 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2030 -- In formal verification mode, analyze pragma expression for
2031 -- correctness, as it is not expanded later.
2034 Analyze_PPC_In_Decl_Part
2035 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2038 Chain_PPC (Unit (Parent (Parent (N))));
2042 -- If we fall through, pragma was misplaced
2045 end Check_Precondition_Postcondition;
2047 -----------------------------
2048 -- Check_Static_Constraint --
2049 -----------------------------
2051 -- Note: for convenience in writing this procedure, in addition to
2052 -- the officially (i.e. by spec) allowed argument which is always a
2053 -- constraint, it also allows ranges and discriminant associations.
2054 -- Above is not clear ???
2056 procedure Check_Static_Constraint (Constr : Node_Id) is
2058 procedure Require_Static (E : Node_Id);
2059 -- Require given expression to be static expression
2061 --------------------
2062 -- Require_Static --
2063 --------------------
2065 procedure Require_Static (E : Node_Id) is
2067 if not Is_OK_Static_Expression (E) then
2068 Flag_Non_Static_Expr
2069 ("non-static constraint not allowed in Unchecked_Union!", E);
2074 -- Start of processing for Check_Static_Constraint
2077 case Nkind (Constr) is
2078 when N_Discriminant_Association =>
2079 Require_Static (Expression (Constr));
2082 Require_Static (Low_Bound (Constr));
2083 Require_Static (High_Bound (Constr));
2085 when N_Attribute_Reference =>
2086 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2087 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2089 when N_Range_Constraint =>
2090 Check_Static_Constraint (Range_Expression (Constr));
2092 when N_Index_Or_Discriminant_Constraint =>
2096 IDC := First (Constraints (Constr));
2097 while Present (IDC) loop
2098 Check_Static_Constraint (IDC);
2106 end Check_Static_Constraint;
2108 ---------------------
2109 -- Check_Test_Case --
2110 ---------------------
2112 procedure Check_Test_Case is
2116 procedure Chain_TC (PO : Node_Id);
2117 -- If PO is a [generic] subprogram declaration node, then the
2118 -- test-case applies to this subprogram and the processing for the
2119 -- pragma is completed. Otherwise the pragma is misplaced.
2125 procedure Chain_TC (PO : Node_Id) is
2129 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2130 if From_Aspect_Specification (N) then
2132 ("aspect% cannot be applied to abstract subprogram");
2135 ("pragma% cannot be applied to abstract subprogram");
2138 elsif Nkind (PO) = N_Entry_Declaration then
2139 if From_Aspect_Specification (N) then
2140 Error_Pragma ("aspect% cannot be applied to entry");
2142 Error_Pragma ("pragma% cannot be applied to entry");
2145 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2146 N_Generic_Subprogram_Declaration)
2151 -- Here if we have [generic] subprogram declaration
2153 S := Defining_Unit_Name (Specification (PO));
2155 -- Note: we do not analyze the pragma at this point. Instead we
2156 -- delay this analysis until the end of the declarative part in
2157 -- which the pragma appears. This implements the required delay
2158 -- in this analysis, allowing forward references. The analysis
2159 -- happens at the end of Analyze_Declarations.
2161 -- There should not be another test case with the same name
2162 -- associated to this subprogram.
2165 Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2169 TC := Spec_TC_List (Contract (S));
2170 while Present (TC) loop
2173 (Name, Get_Name_From_Test_Case_Pragma (TC))
2175 Error_Msg_Sloc := Sloc (TC);
2177 if From_Aspect_Specification (N) then
2178 Error_Pragma ("name for aspect% is already used#");
2180 Error_Pragma ("name for pragma% is already used#");
2184 TC := Next_Pragma (TC);
2188 -- Chain spec TC pragma to list for subprogram
2190 Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2191 Set_Spec_TC_List (Contract (S), N);
2194 -- Start of processing for Check_Test_Case
2197 if not Is_List_Member (N) then
2201 -- Test cases should only appear in package spec unit
2203 if Get_Source_Unit (N) = No_Unit
2204 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2205 N_Package_Declaration,
2206 N_Generic_Package_Declaration)
2211 -- Search prior declarations
2214 while Present (Prev (P)) loop
2217 -- If the previous node is a generic subprogram, do not go to to
2218 -- the original node, which is the unanalyzed tree: we need to
2219 -- attach the test-case to the analyzed version at this point.
2220 -- They get propagated to the original tree when analyzing the
2221 -- corresponding body.
2223 if Nkind (P) not in N_Generic_Declaration then
2224 PO := Original_Node (P);
2229 -- Skip past prior pragma
2231 if Nkind (PO) = N_Pragma then
2234 -- Skip stuff not coming from source
2236 elsif not Comes_From_Source (PO) then
2239 -- Only remaining possibility is subprogram declaration. First
2240 -- check that it is declared directly in a package declaration.
2241 -- This may be either the package declaration for the current unit
2242 -- being defined or a local package declaration.
2244 elsif not Present (Parent (Parent (PO)))
2245 or else not Present (Parent (Parent (Parent (PO))))
2246 or else not Nkind_In (Parent (Parent (PO)),
2247 N_Package_Declaration,
2248 N_Generic_Package_Declaration)
2258 -- If we fall through, pragma was misplaced
2261 end Check_Test_Case;
2263 --------------------------------------
2264 -- Check_Valid_Configuration_Pragma --
2265 --------------------------------------
2267 -- A configuration pragma must appear in the context clause of a
2268 -- compilation unit, and only other pragmas may precede it. Note that
2269 -- the test also allows use in a configuration pragma file.
2271 procedure Check_Valid_Configuration_Pragma is
2273 if not Is_Configuration_Pragma then
2274 Error_Pragma ("incorrect placement for configuration pragma%");
2276 end Check_Valid_Configuration_Pragma;
2278 -------------------------------------
2279 -- Check_Valid_Library_Unit_Pragma --
2280 -------------------------------------
2282 procedure Check_Valid_Library_Unit_Pragma is
2284 Parent_Node : Node_Id;
2285 Unit_Name : Entity_Id;
2286 Unit_Kind : Node_Kind;
2287 Unit_Node : Node_Id;
2288 Sindex : Source_File_Index;
2291 if not Is_List_Member (N) then
2295 Plist := List_Containing (N);
2296 Parent_Node := Parent (Plist);
2298 if Parent_Node = Empty then
2301 -- Case of pragma appearing after a compilation unit. In this case
2302 -- it must have an argument with the corresponding name and must
2303 -- be part of the following pragmas of its parent.
2305 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2306 if Plist /= Pragmas_After (Parent_Node) then
2309 elsif Arg_Count = 0 then
2311 ("argument required if outside compilation unit");
2314 Check_No_Identifiers;
2315 Check_Arg_Count (1);
2316 Unit_Node := Unit (Parent (Parent_Node));
2317 Unit_Kind := Nkind (Unit_Node);
2319 Analyze (Get_Pragma_Arg (Arg1));
2321 if Unit_Kind = N_Generic_Subprogram_Declaration
2322 or else Unit_Kind = N_Subprogram_Declaration
2324 Unit_Name := Defining_Entity (Unit_Node);
2326 elsif Unit_Kind in N_Generic_Instantiation then
2327 Unit_Name := Defining_Entity (Unit_Node);
2330 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2333 if Chars (Unit_Name) /=
2334 Chars (Entity (Get_Pragma_Arg (Arg1)))
2337 ("pragma% argument is not current unit name", Arg1);
2340 if Ekind (Unit_Name) = E_Package
2341 and then Present (Renamed_Entity (Unit_Name))
2343 Error_Pragma ("pragma% not allowed for renamed package");
2347 -- Pragma appears other than after a compilation unit
2350 -- Here we check for the generic instantiation case and also
2351 -- for the case of processing a generic formal package. We
2352 -- detect these cases by noting that the Sloc on the node
2353 -- does not belong to the current compilation unit.
2355 Sindex := Source_Index (Current_Sem_Unit);
2357 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2358 Rewrite (N, Make_Null_Statement (Loc));
2361 -- If before first declaration, the pragma applies to the
2362 -- enclosing unit, and the name if present must be this name.
2364 elsif Is_Before_First_Decl (N, Plist) then
2365 Unit_Node := Unit_Declaration_Node (Current_Scope);
2366 Unit_Kind := Nkind (Unit_Node);
2368 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2371 elsif Unit_Kind = N_Subprogram_Body
2372 and then not Acts_As_Spec (Unit_Node)
2376 elsif Nkind (Parent_Node) = N_Package_Body then
2379 elsif Nkind (Parent_Node) = N_Package_Specification
2380 and then Plist = Private_Declarations (Parent_Node)
2384 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2385 or else Nkind (Parent_Node) =
2386 N_Generic_Subprogram_Declaration)
2387 and then Plist = Generic_Formal_Declarations (Parent_Node)
2391 elsif Arg_Count > 0 then
2392 Analyze (Get_Pragma_Arg (Arg1));
2394 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2396 ("name in pragma% must be enclosing unit", Arg1);
2399 -- It is legal to have no argument in this context
2405 -- Error if not before first declaration. This is because a
2406 -- library unit pragma argument must be the name of a library
2407 -- unit (RM 10.1.5(7)), but the only names permitted in this
2408 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2409 -- generic subprogram declarations or generic instantiations.
2413 ("pragma% misplaced, must be before first declaration");
2417 end Check_Valid_Library_Unit_Pragma;
2423 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2424 Clist : constant Node_Id := Component_List (Variant);
2428 if not Is_Non_Empty_List (Component_Items (Clist)) then
2430 ("Unchecked_Union may not have empty component list",
2435 Comp := First (Component_Items (Clist));
2436 while Present (Comp) loop
2437 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2446 procedure Error_Pragma (Msg : String) is
2447 MsgF : String := Msg;
2449 Error_Msg_Name_1 := Pname;
2451 Error_Msg_N (MsgF, N);
2455 ----------------------
2456 -- Error_Pragma_Arg --
2457 ----------------------
2459 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2460 MsgF : String := Msg;
2462 Error_Msg_Name_1 := Pname;
2464 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2466 end Error_Pragma_Arg;
2468 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2469 MsgF : String := Msg1;
2471 Error_Msg_Name_1 := Pname;
2473 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2474 Error_Pragma_Arg (Msg2, Arg);
2475 end Error_Pragma_Arg;
2477 ----------------------------
2478 -- Error_Pragma_Arg_Ident --
2479 ----------------------------
2481 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2482 MsgF : String := Msg;
2484 Error_Msg_Name_1 := Pname;
2486 Error_Msg_N (MsgF, Arg);
2488 end Error_Pragma_Arg_Ident;
2490 ----------------------
2491 -- Error_Pragma_Ref --
2492 ----------------------
2494 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2495 MsgF : String := Msg;
2497 Error_Msg_Name_1 := Pname;
2499 Error_Msg_Sloc := Sloc (Ref);
2500 Error_Msg_NE (MsgF, N, Ref);
2502 end Error_Pragma_Ref;
2504 ------------------------
2505 -- Find_Lib_Unit_Name --
2506 ------------------------
2508 function Find_Lib_Unit_Name return Entity_Id is
2510 -- Return inner compilation unit entity, for case of nested
2511 -- categorization pragmas. This happens in generic unit.
2513 if Nkind (Parent (N)) = N_Package_Specification
2514 and then Defining_Entity (Parent (N)) /= Current_Scope
2516 return Defining_Entity (Parent (N));
2518 return Current_Scope;
2520 end Find_Lib_Unit_Name;
2522 ----------------------------
2523 -- Find_Program_Unit_Name --
2524 ----------------------------
2526 procedure Find_Program_Unit_Name (Id : Node_Id) is
2527 Unit_Name : Entity_Id;
2528 Unit_Kind : Node_Kind;
2529 P : constant Node_Id := Parent (N);
2532 if Nkind (P) = N_Compilation_Unit then
2533 Unit_Kind := Nkind (Unit (P));
2535 if Unit_Kind = N_Subprogram_Declaration
2536 or else Unit_Kind = N_Package_Declaration
2537 or else Unit_Kind in N_Generic_Declaration
2539 Unit_Name := Defining_Entity (Unit (P));
2541 if Chars (Id) = Chars (Unit_Name) then
2542 Set_Entity (Id, Unit_Name);
2543 Set_Etype (Id, Etype (Unit_Name));
2545 Set_Etype (Id, Any_Type);
2547 ("cannot find program unit referenced by pragma%");
2551 Set_Etype (Id, Any_Type);
2552 Error_Pragma ("pragma% inapplicable to this unit");
2558 end Find_Program_Unit_Name;
2560 -----------------------------------------
2561 -- Find_Unique_Parameterless_Procedure --
2562 -----------------------------------------
2564 function Find_Unique_Parameterless_Procedure
2566 Arg : Node_Id) return Entity_Id
2568 Proc : Entity_Id := Empty;
2571 -- The body of this procedure needs some comments ???
2573 if not Is_Entity_Name (Name) then
2575 ("argument of pragma% must be entity name", Arg);
2577 elsif not Is_Overloaded (Name) then
2578 Proc := Entity (Name);
2580 if Ekind (Proc) /= E_Procedure
2581 or else Present (First_Formal (Proc))
2584 ("argument of pragma% must be parameterless procedure", Arg);
2589 Found : Boolean := False;
2591 Index : Interp_Index;
2594 Get_First_Interp (Name, Index, It);
2595 while Present (It.Nam) loop
2598 if Ekind (Proc) = E_Procedure
2599 and then No (First_Formal (Proc))
2603 Set_Entity (Name, Proc);
2604 Set_Is_Overloaded (Name, False);
2607 ("ambiguous handler name for pragma% ", Arg);
2611 Get_Next_Interp (Index, It);
2616 ("argument of pragma% must be parameterless procedure",
2619 Proc := Entity (Name);
2625 end Find_Unique_Parameterless_Procedure;
2631 procedure Fix_Error (Msg : in out String) is
2633 if From_Aspect_Specification (N) then
2634 for J in Msg'First .. Msg'Last - 5 loop
2635 if Msg (J .. J + 5) = "pragma" then
2636 Msg (J .. J + 5) := "aspect";
2640 if Error_Msg_Name_1 = Name_Precondition then
2641 Error_Msg_Name_1 := Name_Pre;
2642 elsif Error_Msg_Name_1 = Name_Postcondition then
2643 Error_Msg_Name_1 := Name_Post;
2648 -------------------------
2649 -- Gather_Associations --
2650 -------------------------
2652 procedure Gather_Associations
2654 Args : out Args_List)
2659 -- Initialize all parameters to Empty
2661 for J in Args'Range loop
2665 -- That's all we have to do if there are no argument associations
2667 if No (Pragma_Argument_Associations (N)) then
2671 -- Otherwise first deal with any positional parameters present
2673 Arg := First (Pragma_Argument_Associations (N));
2674 for Index in Args'Range loop
2675 exit when No (Arg) or else Chars (Arg) /= No_Name;
2676 Args (Index) := Get_Pragma_Arg (Arg);
2680 -- Positional parameters all processed, if any left, then we
2681 -- have too many positional parameters.
2683 if Present (Arg) and then Chars (Arg) = No_Name then
2685 ("too many positional associations for pragma%", Arg);
2688 -- Process named parameters if any are present
2690 while Present (Arg) loop
2691 if Chars (Arg) = No_Name then
2693 ("positional association cannot follow named association",
2697 for Index in Names'Range loop
2698 if Names (Index) = Chars (Arg) then
2699 if Present (Args (Index)) then
2701 ("duplicate argument association for pragma%", Arg);
2703 Args (Index) := Get_Pragma_Arg (Arg);
2708 if Index = Names'Last then
2709 Error_Msg_Name_1 := Pname;
2710 Error_Msg_N ("pragma% does not allow & argument", Arg);
2712 -- Check for possible misspelling
2714 for Index1 in Names'Range loop
2715 if Is_Bad_Spelling_Of
2716 (Chars (Arg), Names (Index1))
2718 Error_Msg_Name_1 := Names (Index1);
2719 Error_Msg_N -- CODEFIX
2720 ("\possible misspelling of%", Arg);
2732 end Gather_Associations;
2738 procedure GNAT_Pragma is
2740 Check_Restriction (No_Implementation_Pragmas, N);
2743 --------------------------
2744 -- Is_Before_First_Decl --
2745 --------------------------
2747 function Is_Before_First_Decl
2748 (Pragma_Node : Node_Id;
2749 Decls : List_Id) return Boolean
2751 Item : Node_Id := First (Decls);
2754 -- Only other pragmas can come before this pragma
2757 if No (Item) or else Nkind (Item) /= N_Pragma then
2760 elsif Item = Pragma_Node then
2766 end Is_Before_First_Decl;
2768 -----------------------------
2769 -- Is_Configuration_Pragma --
2770 -----------------------------
2772 -- A configuration pragma must appear in the context clause of a
2773 -- compilation unit, and only other pragmas may precede it. Note that
2774 -- the test below also permits use in a configuration pragma file.
2776 function Is_Configuration_Pragma return Boolean is
2777 Lis : constant List_Id := List_Containing (N);
2778 Par : constant Node_Id := Parent (N);
2782 -- If no parent, then we are in the configuration pragma file,
2783 -- so the placement is definitely appropriate.
2788 -- Otherwise we must be in the context clause of a compilation unit
2789 -- and the only thing allowed before us in the context list is more
2790 -- configuration pragmas.
2792 elsif Nkind (Par) = N_Compilation_Unit
2793 and then Context_Items (Par) = Lis
2800 elsif Nkind (Prg) /= N_Pragma then
2810 end Is_Configuration_Pragma;
2812 --------------------------
2813 -- Is_In_Context_Clause --
2814 --------------------------
2816 function Is_In_Context_Clause return Boolean is
2818 Parent_Node : Node_Id;
2821 if not Is_List_Member (N) then
2825 Plist := List_Containing (N);
2826 Parent_Node := Parent (Plist);
2828 if Parent_Node = Empty
2829 or else Nkind (Parent_Node) /= N_Compilation_Unit
2830 or else Context_Items (Parent_Node) /= Plist
2837 end Is_In_Context_Clause;
2839 ---------------------------------
2840 -- Is_Static_String_Expression --
2841 ---------------------------------
2843 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2844 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2847 Analyze_And_Resolve (Argx);
2848 return Is_OK_Static_Expression (Argx)
2849 and then Nkind (Argx) = N_String_Literal;
2850 end Is_Static_String_Expression;
2852 ----------------------
2853 -- Pragma_Misplaced --
2854 ----------------------
2856 procedure Pragma_Misplaced is
2858 Error_Pragma ("incorrect placement of pragma%");
2859 end Pragma_Misplaced;
2861 ------------------------------------
2862 -- Process Atomic_Shared_Volatile --
2863 ------------------------------------
2865 procedure Process_Atomic_Shared_Volatile is
2872 procedure Set_Atomic (E : Entity_Id);
2873 -- Set given type as atomic, and if no explicit alignment was given,
2874 -- set alignment to unknown, since back end knows what the alignment
2875 -- requirements are for atomic arrays. Note: this step is necessary
2876 -- for derived types.
2882 procedure Set_Atomic (E : Entity_Id) is
2886 if not Has_Alignment_Clause (E) then
2887 Set_Alignment (E, Uint_0);
2891 -- Start of processing for Process_Atomic_Shared_Volatile
2894 Check_Ada_83_Warning;
2895 Check_No_Identifiers;
2896 Check_Arg_Count (1);
2897 Check_Arg_Is_Local_Name (Arg1);
2898 E_Id := Get_Pragma_Arg (Arg1);
2900 if Etype (E_Id) = Any_Type then
2905 D := Declaration_Node (E);
2908 -- Check duplicate before we chain ourselves!
2910 Check_Duplicate_Pragma (E);
2912 -- Now check appropriateness of the entity
2915 if Rep_Item_Too_Early (E, N)
2917 Rep_Item_Too_Late (E, N)
2921 Check_First_Subtype (Arg1);
2924 if Prag_Id /= Pragma_Volatile then
2926 Set_Atomic (Underlying_Type (E));
2927 Set_Atomic (Base_Type (E));
2930 -- Attribute belongs on the base type. If the view of the type is
2931 -- currently private, it also belongs on the underlying type.
2933 Set_Is_Volatile (Base_Type (E));
2934 Set_Is_Volatile (Underlying_Type (E));
2936 Set_Treat_As_Volatile (E);
2937 Set_Treat_As_Volatile (Underlying_Type (E));
2939 elsif K = N_Object_Declaration
2940 or else (K = N_Component_Declaration
2941 and then Original_Record_Component (E) = E)
2943 if Rep_Item_Too_Late (E, N) then
2947 if Prag_Id /= Pragma_Volatile then
2950 -- If the object declaration has an explicit initialization, a
2951 -- temporary may have to be created to hold the expression, to
2952 -- ensure that access to the object remain atomic.
2954 if Nkind (Parent (E)) = N_Object_Declaration
2955 and then Present (Expression (Parent (E)))
2957 Set_Has_Delayed_Freeze (E);
2960 -- An interesting improvement here. If an object of type X is
2961 -- declared atomic, and the type X is not atomic, that's a
2962 -- pity, since it may not have appropriate alignment etc. We
2963 -- can rescue this in the special case where the object and
2964 -- type are in the same unit by just setting the type as
2965 -- atomic, so that the back end will process it as atomic.
2967 Utyp := Underlying_Type (Etype (E));
2970 and then Sloc (E) > No_Location
2971 and then Sloc (Utyp) > No_Location
2973 Get_Source_File_Index (Sloc (E)) =
2974 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2976 Set_Is_Atomic (Underlying_Type (Etype (E)));
2980 Set_Is_Volatile (E);
2981 Set_Treat_As_Volatile (E);
2985 ("inappropriate entity for pragma%", Arg1);
2987 end Process_Atomic_Shared_Volatile;
2989 -------------------------------------------
2990 -- Process_Compile_Time_Warning_Or_Error --
2991 -------------------------------------------
2993 procedure Process_Compile_Time_Warning_Or_Error is
2994 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2997 Check_Arg_Count (2);
2998 Check_No_Identifiers;
2999 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3000 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3002 if Compile_Time_Known_Value (Arg1x) then
3003 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3005 Str : constant String_Id :=
3006 Strval (Get_Pragma_Arg (Arg2));
3007 Len : constant Int := String_Length (Str);
3012 Cent : constant Entity_Id :=
3013 Cunit_Entity (Current_Sem_Unit);
3015 Force : constant Boolean :=
3016 Prag_Id = Pragma_Compile_Time_Warning
3018 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3019 and then (Ekind (Cent) /= E_Package
3020 or else not In_Private_Part (Cent));
3021 -- Set True if this is the warning case, and we are in the
3022 -- visible part of a package spec, or in a subprogram spec,
3023 -- in which case we want to force the client to see the
3024 -- warning, even though it is not in the main unit.
3027 -- Loop through segments of message separated by line feeds.
3028 -- We output these segments as separate messages with
3029 -- continuation marks for all but the first.
3034 Error_Msg_Strlen := 0;
3036 -- Loop to copy characters from argument to error message
3040 exit when Ptr > Len;
3041 CC := Get_String_Char (Str, Ptr);
3044 -- Ignore wide chars ??? else store character
3046 if In_Character_Range (CC) then
3047 C := Get_Character (CC);
3048 exit when C = ASCII.LF;
3049 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3050 Error_Msg_String (Error_Msg_Strlen) := C;
3054 -- Here with one line ready to go
3056 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3058 -- If this is a warning in a spec, then we want clients
3059 -- to see the warning, so mark the message with the
3060 -- special sequence !! to force the warning. In the case
3061 -- of a package spec, we do not force this if we are in
3062 -- the private part of the spec.
3065 if Cont = False then
3066 Error_Msg_N ("<~!!", Arg1);
3069 Error_Msg_N ("\<~!!", Arg1);
3072 -- Error, rather than warning, or in a body, so we do not
3073 -- need to force visibility for client (error will be
3074 -- output in any case, and this is the situation in which
3075 -- we do not want a client to get a warning, since the
3076 -- warning is in the body or the spec private part).
3079 if Cont = False then
3080 Error_Msg_N ("<~", Arg1);
3083 Error_Msg_N ("\<~", Arg1);
3087 exit when Ptr > Len;
3092 end Process_Compile_Time_Warning_Or_Error;
3094 ------------------------
3095 -- Process_Convention --
3096 ------------------------
3098 procedure Process_Convention
3099 (C : out Convention_Id;
3100 Ent : out Entity_Id)
3106 Comp_Unit : Unit_Number_Type;
3108 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3109 -- Called if we have more than one Export/Import/Convention pragma.
3110 -- This is generally illegal, but we have a special case of allowing
3111 -- Import and Interface to coexist if they specify the convention in
3112 -- a consistent manner. We are allowed to do this, since Interface is
3113 -- an implementation defined pragma, and we choose to do it since we
3114 -- know Rational allows this combination. S is the entity id of the
3115 -- subprogram in question. This procedure also sets the special flag
3116 -- Import_Interface_Present in both pragmas in the case where we do
3117 -- have matching Import and Interface pragmas.
3119 procedure Set_Convention_From_Pragma (E : Entity_Id);
3120 -- Set convention in entity E, and also flag that the entity has a
3121 -- convention pragma. If entity is for a private or incomplete type,
3122 -- also set convention and flag on underlying type. This procedure
3123 -- also deals with the special case of C_Pass_By_Copy convention.
3125 -------------------------------
3126 -- Diagnose_Multiple_Pragmas --
3127 -------------------------------
3129 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3130 Pdec : constant Node_Id := Declaration_Node (S);
3134 function Same_Convention (Decl : Node_Id) return Boolean;
3135 -- Decl is a pragma node. This function returns True if this
3136 -- pragma has a first argument that is an identifier with a
3137 -- Chars field corresponding to the Convention_Id C.
3139 function Same_Name (Decl : Node_Id) return Boolean;
3140 -- Decl is a pragma node. This function returns True if this
3141 -- pragma has a second argument that is an identifier with a
3142 -- Chars field that matches the Chars of the current subprogram.
3144 ---------------------
3145 -- Same_Convention --
3146 ---------------------
3148 function Same_Convention (Decl : Node_Id) return Boolean is
3149 Arg1 : constant Node_Id :=
3150 First (Pragma_Argument_Associations (Decl));
3153 if Present (Arg1) then
3155 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3157 if Nkind (Arg) = N_Identifier
3158 and then Is_Convention_Name (Chars (Arg))
3159 and then Get_Convention_Id (Chars (Arg)) = C
3167 end Same_Convention;
3173 function Same_Name (Decl : Node_Id) return Boolean is
3174 Arg1 : constant Node_Id :=
3175 First (Pragma_Argument_Associations (Decl));
3183 Arg2 := Next (Arg1);
3190 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3192 if Nkind (Arg) = N_Identifier
3193 and then Chars (Arg) = Chars (S)
3202 -- Start of processing for Diagnose_Multiple_Pragmas
3207 -- Definitely give message if we have Convention/Export here
3209 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3212 -- If we have an Import or Export, scan back from pragma to
3213 -- find any previous pragma applying to the same procedure.
3214 -- The scan will be terminated by the start of the list, or
3215 -- hitting the subprogram declaration. This won't allow one
3216 -- pragma to appear in the public part and one in the private
3217 -- part, but that seems very unlikely in practice.
3221 while Present (Decl) and then Decl /= Pdec loop
3223 -- Look for pragma with same name as us
3225 if Nkind (Decl) = N_Pragma
3226 and then Same_Name (Decl)
3228 -- Give error if same as our pragma or Export/Convention
3230 if Pragma_Name (Decl) = Name_Export
3232 Pragma_Name (Decl) = Name_Convention
3234 Pragma_Name (Decl) = Pragma_Name (N)
3238 -- Case of Import/Interface or the other way round
3240 elsif Pragma_Name (Decl) = Name_Interface
3242 Pragma_Name (Decl) = Name_Import
3244 -- Here we know that we have Import and Interface. It
3245 -- doesn't matter which way round they are. See if
3246 -- they specify the same convention. If so, all OK,
3247 -- and set special flags to stop other messages
3249 if Same_Convention (Decl) then
3250 Set_Import_Interface_Present (N);
3251 Set_Import_Interface_Present (Decl);
3254 -- If different conventions, special message
3257 Error_Msg_Sloc := Sloc (Decl);
3259 ("convention differs from that given#", Arg1);
3269 -- Give message if needed if we fall through those tests
3273 ("at most one Convention/Export/Import pragma is allowed",
3276 end Diagnose_Multiple_Pragmas;
3278 --------------------------------
3279 -- Set_Convention_From_Pragma --
3280 --------------------------------
3282 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3284 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3285 -- for an overridden dispatching operation. Technically this is
3286 -- an amendment and should only be done in Ada 2005 mode. However,
3287 -- this is clearly a mistake, since the problem that is addressed
3288 -- by this AI is that there is a clear gap in the RM!
3290 if Is_Dispatching_Operation (E)
3291 and then Present (Overridden_Operation (E))
3292 and then C /= Convention (Overridden_Operation (E))
3295 ("cannot change convention for " &
3296 "overridden dispatching operation",
3300 -- Set the convention
3302 Set_Convention (E, C);
3303 Set_Has_Convention_Pragma (E);
3305 if Is_Incomplete_Or_Private_Type (E)
3306 and then Present (Underlying_Type (E))
3308 Set_Convention (Underlying_Type (E), C);
3309 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3312 -- A class-wide type should inherit the convention of the specific
3313 -- root type (although this isn't specified clearly by the RM).
3315 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3316 Set_Convention (Class_Wide_Type (E), C);
3319 -- If the entity is a record type, then check for special case of
3320 -- C_Pass_By_Copy, which is treated the same as C except that the
3321 -- special record flag is set. This convention is only permitted
3322 -- on record types (see AI95-00131).
3324 if Cname = Name_C_Pass_By_Copy then
3325 if Is_Record_Type (E) then
3326 Set_C_Pass_By_Copy (Base_Type (E));
3327 elsif Is_Incomplete_Or_Private_Type (E)
3328 and then Is_Record_Type (Underlying_Type (E))
3330 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3333 ("C_Pass_By_Copy convention allowed only for record type",
3338 -- If the entity is a derived boolean type, check for the special
3339 -- case of convention C, C++, or Fortran, where we consider any
3340 -- nonzero value to represent true.
3342 if Is_Discrete_Type (E)
3343 and then Root_Type (Etype (E)) = Standard_Boolean
3349 C = Convention_Fortran)
3351 Set_Nonzero_Is_True (Base_Type (E));
3353 end Set_Convention_From_Pragma;
3355 -- Start of processing for Process_Convention
3358 Check_At_Least_N_Arguments (2);
3359 Check_Optional_Identifier (Arg1, Name_Convention);
3360 Check_Arg_Is_Identifier (Arg1);
3361 Cname := Chars (Get_Pragma_Arg (Arg1));
3363 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3364 -- tested again below to set the critical flag).
3366 if Cname = Name_C_Pass_By_Copy then
3369 -- Otherwise we must have something in the standard convention list
3371 elsif Is_Convention_Name (Cname) then
3372 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3374 -- In DEC VMS, it seems that there is an undocumented feature that
3375 -- any unrecognized convention is treated as the default, which for
3376 -- us is convention C. It does not seem so terrible to do this
3377 -- unconditionally, silently in the VMS case, and with a warning
3378 -- in the non-VMS case.
3381 if Warn_On_Export_Import and not OpenVMS_On_Target then
3383 ("?unrecognized convention name, C assumed",
3384 Get_Pragma_Arg (Arg1));
3390 Check_Optional_Identifier (Arg2, Name_Entity);
3391 Check_Arg_Is_Local_Name (Arg2);
3393 Id := Get_Pragma_Arg (Arg2);
3396 if not Is_Entity_Name (Id) then
3397 Error_Pragma_Arg ("entity name required", Arg2);
3402 -- Set entity to return
3406 -- Ada_Pass_By_Copy special checking
3408 if C = Convention_Ada_Pass_By_Copy then
3409 if not Is_First_Subtype (E) then
3411 ("convention `Ada_Pass_By_Copy` only "
3412 & "allowed for types", Arg2);
3415 if Is_By_Reference_Type (E) then
3417 ("convention `Ada_Pass_By_Copy` not allowed for "
3418 & "by-reference type", Arg1);
3422 -- Ada_Pass_By_Reference special checking
3424 if C = Convention_Ada_Pass_By_Reference then
3425 if not Is_First_Subtype (E) then
3427 ("convention `Ada_Pass_By_Reference` only "
3428 & "allowed for types", Arg2);
3431 if Is_By_Copy_Type (E) then
3433 ("convention `Ada_Pass_By_Reference` not allowed for "
3434 & "by-copy type", Arg1);
3438 -- Go to renamed subprogram if present, since convention applies to
3439 -- the actual renamed entity, not to the renaming entity. If the
3440 -- subprogram is inherited, go to parent subprogram.
3442 if Is_Subprogram (E)
3443 and then Present (Alias (E))
3445 if Nkind (Parent (Declaration_Node (E))) =
3446 N_Subprogram_Renaming_Declaration
3448 if Scope (E) /= Scope (Alias (E)) then
3450 ("cannot apply pragma% to non-local entity&#", E);
3455 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3456 N_Private_Extension_Declaration)
3457 and then Scope (E) = Scope (Alias (E))
3461 -- Return the parent subprogram the entity was inherited from
3467 -- Check that we are not applying this to a specless body
3469 if Is_Subprogram (E)
3470 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3473 ("pragma% requires separate spec and must come before body");
3476 -- Check that we are not applying this to a named constant
3478 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3479 Error_Msg_Name_1 := Pname;
3481 ("cannot apply pragma% to named constant!",
3482 Get_Pragma_Arg (Arg2));
3484 ("\supply appropriate type for&!", Arg2);
3487 if Ekind (E) = E_Enumeration_Literal then
3488 Error_Pragma ("enumeration literal not allowed for pragma%");
3491 -- Check for rep item appearing too early or too late
3493 if Etype (E) = Any_Type
3494 or else Rep_Item_Too_Early (E, N)
3498 elsif Present (Underlying_Type (E)) then
3499 E := Underlying_Type (E);
3502 if Rep_Item_Too_Late (E, N) then
3506 if Has_Convention_Pragma (E) then
3507 Diagnose_Multiple_Pragmas (E);
3509 elsif Convention (E) = Convention_Protected
3510 or else Ekind (Scope (E)) = E_Protected_Type
3513 ("a protected operation cannot be given a different convention",
3517 -- For Intrinsic, a subprogram is required
3519 if C = Convention_Intrinsic
3520 and then not Is_Subprogram (E)
3521 and then not Is_Generic_Subprogram (E)
3524 ("second argument of pragma% must be a subprogram", Arg2);
3529 if C = Convention_Stdcall
3531 -- Subprogram is allowed, but not a generic subprogram, and not a
3532 -- dispatching operation. A dispatching subprogram cannot be used
3533 -- to interface to the Win32 API, so in fact this check does not
3534 -- impose any effective restriction.
3537 ((not Is_Subprogram (E) and then not Is_Generic_Subprogram (E))
3538 or else Is_Dispatching_Operation (E))
3542 and then Ekind (E) /= E_Variable
3544 -- An access to subprogram is also allowed
3548 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3551 ("second argument of pragma% must be subprogram (type)",
3555 if not Is_Subprogram (E)
3556 and then not Is_Generic_Subprogram (E)
3558 Set_Convention_From_Pragma (E);
3561 Check_First_Subtype (Arg2);
3562 Set_Convention_From_Pragma (Base_Type (E));
3564 -- For subprograms, we must set the convention on the
3565 -- internally generated directly designated type as well.
3567 if Ekind (E) = E_Access_Subprogram_Type then
3568 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3572 -- For the subprogram case, set proper convention for all homonyms
3573 -- in same scope and the same declarative part, i.e. the same
3574 -- compilation unit.
3577 Comp_Unit := Get_Source_Unit (E);
3578 Set_Convention_From_Pragma (E);
3580 -- Treat a pragma Import as an implicit body, for GPS use
3582 if Prag_Id = Pragma_Import then
3583 Generate_Reference (E, Id, 'b');
3586 -- Loop through the homonyms of the pragma argument's entity
3591 exit when No (E1) or else Scope (E1) /= Current_Scope;
3593 -- Do not set the pragma on inherited operations or on formal
3596 if Comes_From_Source (E1)
3597 and then Comp_Unit = Get_Source_Unit (E1)
3598 and then not Is_Formal_Subprogram (E1)
3599 and then Nkind (Original_Node (Parent (E1))) /=
3600 N_Full_Type_Declaration
3602 if Present (Alias (E1))
3603 and then Scope (E1) /= Scope (Alias (E1))
3606 ("cannot apply pragma% to non-local entity& declared#",
3610 Set_Convention_From_Pragma (E1);
3612 if Prag_Id = Pragma_Import then
3613 Generate_Reference (E1, Id, 'b');
3617 -- For aspect case, do NOT apply to homonyms
3619 exit when From_Aspect_Specification (N);
3622 end Process_Convention;
3624 ----------------------------------------
3625 -- Process_Disable_Enable_Atomic_Sync --
3626 ----------------------------------------
3628 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3631 Check_No_Identifiers;
3632 Check_At_Most_N_Arguments (1);
3634 -- Modeled internally as
3635 -- pragma Unsuppress (Atomic_Synchronization [,Entity])
3639 Pragma_Identifier =>
3640 Make_Identifier (Loc, Nam),
3641 Pragma_Argument_Associations => New_List (
3642 Make_Pragma_Argument_Association (Loc,
3644 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3646 if Present (Arg1) then
3647 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3651 end Process_Disable_Enable_Atomic_Sync;
3653 -----------------------------------------------------
3654 -- Process_Extended_Import_Export_Exception_Pragma --
3655 -----------------------------------------------------
3657 procedure Process_Extended_Import_Export_Exception_Pragma
3658 (Arg_Internal : Node_Id;
3659 Arg_External : Node_Id;
3667 if not OpenVMS_On_Target then
3669 ("?pragma% ignored (applies only to Open'V'M'S)");
3672 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3673 Def_Id := Entity (Arg_Internal);
3675 if Ekind (Def_Id) /= E_Exception then
3677 ("pragma% must refer to declared exception", Arg_Internal);
3680 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3682 if Present (Arg_Form) then
3683 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3686 if Present (Arg_Form)
3687 and then Chars (Arg_Form) = Name_Ada
3691 Set_Is_VMS_Exception (Def_Id);
3692 Set_Exception_Code (Def_Id, No_Uint);
3695 if Present (Arg_Code) then
3696 if not Is_VMS_Exception (Def_Id) then
3698 ("Code option for pragma% not allowed for Ada case",
3702 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3703 Code_Val := Expr_Value (Arg_Code);
3705 if not UI_Is_In_Int_Range (Code_Val) then
3707 ("Code option for pragma% must be in 32-bit range",
3711 Set_Exception_Code (Def_Id, Code_Val);
3714 end Process_Extended_Import_Export_Exception_Pragma;
3716 -------------------------------------------------
3717 -- Process_Extended_Import_Export_Internal_Arg --
3718 -------------------------------------------------
3720 procedure Process_Extended_Import_Export_Internal_Arg
3721 (Arg_Internal : Node_Id := Empty)
3724 if No (Arg_Internal) then
3725 Error_Pragma ("Internal parameter required for pragma%");
3728 if Nkind (Arg_Internal) = N_Identifier then
3731 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3732 and then (Prag_Id = Pragma_Import_Function
3734 Prag_Id = Pragma_Export_Function)
3740 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3743 Check_Arg_Is_Local_Name (Arg_Internal);
3744 end Process_Extended_Import_Export_Internal_Arg;
3746 --------------------------------------------------
3747 -- Process_Extended_Import_Export_Object_Pragma --
3748 --------------------------------------------------
3750 procedure Process_Extended_Import_Export_Object_Pragma
3751 (Arg_Internal : Node_Id;
3752 Arg_External : Node_Id;
3758 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3759 Def_Id := Entity (Arg_Internal);
3761 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3763 ("pragma% must designate an object", Arg_Internal);
3766 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3768 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3771 ("previous Common/Psect_Object applies, pragma % not permitted",
3775 if Rep_Item_Too_Late (Def_Id, N) then
3779 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3781 if Present (Arg_Size) then
3782 Check_Arg_Is_External_Name (Arg_Size);
3785 -- Export_Object case
3787 if Prag_Id = Pragma_Export_Object then
3788 if not Is_Library_Level_Entity (Def_Id) then
3790 ("argument for pragma% must be library level entity",
3794 if Ekind (Current_Scope) = E_Generic_Package then
3795 Error_Pragma ("pragma& cannot appear in a generic unit");
3798 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3800 ("exported object must have compile time known size",
3804 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3805 Error_Msg_N ("?duplicate Export_Object pragma", N);
3807 Set_Exported (Def_Id, Arg_Internal);
3810 -- Import_Object case
3813 if Is_Concurrent_Type (Etype (Def_Id)) then
3815 ("cannot use pragma% for task/protected object",
3819 if Ekind (Def_Id) = E_Constant then
3821 ("cannot import a constant", Arg_Internal);
3824 if Warn_On_Export_Import
3825 and then Has_Discriminants (Etype (Def_Id))
3828 ("imported value must be initialized?", Arg_Internal);
3831 if Warn_On_Export_Import
3832 and then Is_Access_Type (Etype (Def_Id))
3835 ("cannot import object of an access type?", Arg_Internal);
3838 if Warn_On_Export_Import
3839 and then Is_Imported (Def_Id)
3842 ("?duplicate Import_Object pragma", N);
3844 -- Check for explicit initialization present. Note that an
3845 -- initialization generated by the code generator, e.g. for an
3846 -- access type, does not count here.
3848 elsif Present (Expression (Parent (Def_Id)))
3851 (Original_Node (Expression (Parent (Def_Id))))
3853 Error_Msg_Sloc := Sloc (Def_Id);
3855 ("imported entities cannot be initialized (RM B.1(24))",
3856 "\no initialization allowed for & declared#", Arg1);
3858 Set_Imported (Def_Id);
3859 Note_Possible_Modification (Arg_Internal, Sure => False);
3862 end Process_Extended_Import_Export_Object_Pragma;
3864 ------------------------------------------------------
3865 -- Process_Extended_Import_Export_Subprogram_Pragma --
3866 ------------------------------------------------------
3868 procedure Process_Extended_Import_Export_Subprogram_Pragma
3869 (Arg_Internal : Node_Id;
3870 Arg_External : Node_Id;
3871 Arg_Parameter_Types : Node_Id;
3872 Arg_Result_Type : Node_Id := Empty;
3873 Arg_Mechanism : Node_Id;
3874 Arg_Result_Mechanism : Node_Id := Empty;
3875 Arg_First_Optional_Parameter : Node_Id := Empty)
3881 Ambiguous : Boolean;
3885 function Same_Base_Type
3887 Formal : Entity_Id) return Boolean;
3888 -- Determines if Ptype references the type of Formal. Note that only
3889 -- the base types need to match according to the spec. Ptype here is
3890 -- the argument from the pragma, which is either a type name, or an
3891 -- access attribute.
3893 --------------------
3894 -- Same_Base_Type --
3895 --------------------
3897 function Same_Base_Type
3899 Formal : Entity_Id) return Boolean
3901 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3905 -- Case where pragma argument is typ'Access
3907 if Nkind (Ptype) = N_Attribute_Reference
3908 and then Attribute_Name (Ptype) = Name_Access
3910 Pref := Prefix (Ptype);
3913 if not Is_Entity_Name (Pref)
3914 or else Entity (Pref) = Any_Type
3919 -- We have a match if the corresponding argument is of an
3920 -- anonymous access type, and its designated type matches the
3921 -- type of the prefix of the access attribute
3923 return Ekind (Ftyp) = E_Anonymous_Access_Type
3924 and then Base_Type (Entity (Pref)) =
3925 Base_Type (Etype (Designated_Type (Ftyp)));
3927 -- Case where pragma argument is a type name
3932 if not Is_Entity_Name (Ptype)
3933 or else Entity (Ptype) = Any_Type
3938 -- We have a match if the corresponding argument is of the type
3939 -- given in the pragma (comparing base types)
3941 return Base_Type (Entity (Ptype)) = Ftyp;
3945 -- Start of processing for
3946 -- Process_Extended_Import_Export_Subprogram_Pragma
3949 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3953 -- Loop through homonyms (overloadings) of the entity
3955 Hom_Id := Entity (Arg_Internal);
3956 while Present (Hom_Id) loop
3957 Def_Id := Get_Base_Subprogram (Hom_Id);
3959 -- We need a subprogram in the current scope
3961 if not Is_Subprogram (Def_Id)
3962 or else Scope (Def_Id) /= Current_Scope
3969 -- Pragma cannot apply to subprogram body
3971 if Is_Subprogram (Def_Id)
3972 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3976 ("pragma% requires separate spec"
3977 & " and must come before body");
3980 -- Test result type if given, note that the result type
3981 -- parameter can only be present for the function cases.
3983 if Present (Arg_Result_Type)
3984 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3988 elsif Etype (Def_Id) /= Standard_Void_Type
3990 (Pname = Name_Export_Procedure
3992 Pname = Name_Import_Procedure)
3996 -- Test parameter types if given. Note that this parameter
3997 -- has not been analyzed (and must not be, since it is
3998 -- semantic nonsense), so we get it as the parser left it.
4000 elsif Present (Arg_Parameter_Types) then
4001 Check_Matching_Types : declare
4006 Formal := First_Formal (Def_Id);
4008 if Nkind (Arg_Parameter_Types) = N_Null then
4009 if Present (Formal) then
4013 -- A list of one type, e.g. (List) is parsed as
4014 -- a parenthesized expression.
4016 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4017 and then Paren_Count (Arg_Parameter_Types) = 1
4020 or else Present (Next_Formal (Formal))
4025 Same_Base_Type (Arg_Parameter_Types, Formal);
4028 -- A list of more than one type is parsed as a aggregate
4030 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4031 and then Paren_Count (Arg_Parameter_Types) = 0
4033 Ptype := First (Expressions (Arg_Parameter_Types));
4034 while Present (Ptype) or else Present (Formal) loop
4037 or else not Same_Base_Type (Ptype, Formal)
4042 Next_Formal (Formal);
4047 -- Anything else is of the wrong form
4051 ("wrong form for Parameter_Types parameter",
4052 Arg_Parameter_Types);
4054 end Check_Matching_Types;
4057 -- Match is now False if the entry we found did not match
4058 -- either a supplied Parameter_Types or Result_Types argument
4064 -- Ambiguous case, the flag Ambiguous shows if we already
4065 -- detected this and output the initial messages.
4068 if not Ambiguous then
4070 Error_Msg_Name_1 := Pname;
4072 ("pragma% does not uniquely identify subprogram!",
4074 Error_Msg_Sloc := Sloc (Ent);
4075 Error_Msg_N ("matching subprogram #!", N);
4079 Error_Msg_Sloc := Sloc (Def_Id);
4080 Error_Msg_N ("matching subprogram #!", N);
4085 Hom_Id := Homonym (Hom_Id);
4088 -- See if we found an entry
4091 if not Ambiguous then
4092 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4094 ("pragma% cannot be given for generic subprogram");
4097 ("pragma% does not identify local subprogram");
4104 -- Import pragmas must be for imported entities
4106 if Prag_Id = Pragma_Import_Function
4108 Prag_Id = Pragma_Import_Procedure
4110 Prag_Id = Pragma_Import_Valued_Procedure
4112 if not Is_Imported (Ent) then
4114 ("pragma Import or Interface must precede pragma%");
4117 -- Here we have the Export case which can set the entity as exported
4119 -- But does not do so if the specified external name is null, since
4120 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4121 -- compatible) to request no external name.
4123 elsif Nkind (Arg_External) = N_String_Literal
4124 and then String_Length (Strval (Arg_External)) = 0
4128 -- In all other cases, set entity as exported
4131 Set_Exported (Ent, Arg_Internal);
4134 -- Special processing for Valued_Procedure cases
4136 if Prag_Id = Pragma_Import_Valued_Procedure
4138 Prag_Id = Pragma_Export_Valued_Procedure
4140 Formal := First_Formal (Ent);
4143 Error_Pragma ("at least one parameter required for pragma%");
4145 elsif Ekind (Formal) /= E_Out_Parameter then
4146 Error_Pragma ("first parameter must have mode out for pragma%");
4149 Set_Is_Valued_Procedure (Ent);
4153 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4155 -- Process Result_Mechanism argument if present. We have already
4156 -- checked that this is only allowed for the function case.
4158 if Present (Arg_Result_Mechanism) then
4159 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4162 -- Process Mechanism parameter if present. Note that this parameter
4163 -- is not analyzed, and must not be analyzed since it is semantic
4164 -- nonsense, so we get it in exactly as the parser left it.
4166 if Present (Arg_Mechanism) then
4174 -- A single mechanism association without a formal parameter
4175 -- name is parsed as a parenthesized expression. All other
4176 -- cases are parsed as aggregates, so we rewrite the single
4177 -- parameter case as an aggregate for consistency.
4179 if Nkind (Arg_Mechanism) /= N_Aggregate
4180 and then Paren_Count (Arg_Mechanism) = 1
4182 Rewrite (Arg_Mechanism,
4183 Make_Aggregate (Sloc (Arg_Mechanism),
4184 Expressions => New_List (
4185 Relocate_Node (Arg_Mechanism))));
4188 -- Case of only mechanism name given, applies to all formals
4190 if Nkind (Arg_Mechanism) /= N_Aggregate then
4191 Formal := First_Formal (Ent);
4192 while Present (Formal) loop
4193 Set_Mechanism_Value (Formal, Arg_Mechanism);
4194 Next_Formal (Formal);
4197 -- Case of list of mechanism associations given
4200 if Null_Record_Present (Arg_Mechanism) then
4202 ("inappropriate form for Mechanism parameter",
4206 -- Deal with positional ones first
4208 Formal := First_Formal (Ent);
4210 if Present (Expressions (Arg_Mechanism)) then
4211 Mname := First (Expressions (Arg_Mechanism));
4212 while Present (Mname) loop
4215 ("too many mechanism associations", Mname);
4218 Set_Mechanism_Value (Formal, Mname);
4219 Next_Formal (Formal);
4224 -- Deal with named entries
4226 if Present (Component_Associations (Arg_Mechanism)) then
4227 Massoc := First (Component_Associations (Arg_Mechanism));
4228 while Present (Massoc) loop
4229 Choice := First (Choices (Massoc));
4231 if Nkind (Choice) /= N_Identifier
4232 or else Present (Next (Choice))
4235 ("incorrect form for mechanism association",
4239 Formal := First_Formal (Ent);
4243 ("parameter name & not present", Choice);
4246 if Chars (Choice) = Chars (Formal) then
4248 (Formal, Expression (Massoc));
4250 -- Set entity on identifier (needed by ASIS)
4252 Set_Entity (Choice, Formal);
4257 Next_Formal (Formal);
4267 -- Process First_Optional_Parameter argument if present. We have
4268 -- already checked that this is only allowed for the Import case.
4270 if Present (Arg_First_Optional_Parameter) then
4271 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4273 ("first optional parameter must be formal parameter name",
4274 Arg_First_Optional_Parameter);
4277 Formal := First_Formal (Ent);
4281 ("specified formal parameter& not found",
4282 Arg_First_Optional_Parameter);
4285 exit when Chars (Formal) =
4286 Chars (Arg_First_Optional_Parameter);
4288 Next_Formal (Formal);
4291 Set_First_Optional_Parameter (Ent, Formal);
4293 -- Check specified and all remaining formals have right form
4295 while Present (Formal) loop
4296 if Ekind (Formal) /= E_In_Parameter then
4298 ("optional formal& is not of mode in!",
4299 Arg_First_Optional_Parameter, Formal);
4302 Dval := Default_Value (Formal);
4306 ("optional formal& does not have default value!",
4307 Arg_First_Optional_Parameter, Formal);
4309 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4314 ("default value for optional formal& is non-static!",
4315 Arg_First_Optional_Parameter, Formal);
4319 Set_Is_Optional_Parameter (Formal);
4320 Next_Formal (Formal);
4323 end Process_Extended_Import_Export_Subprogram_Pragma;
4325 --------------------------
4326 -- Process_Generic_List --
4327 --------------------------
4329 procedure Process_Generic_List is
4334 Check_No_Identifiers;
4335 Check_At_Least_N_Arguments (1);
4338 while Present (Arg) loop
4339 Exp := Get_Pragma_Arg (Arg);
4342 if not Is_Entity_Name (Exp)
4344 (not Is_Generic_Instance (Entity (Exp))
4346 not Is_Generic_Unit (Entity (Exp)))
4349 ("pragma% argument must be name of generic unit/instance",
4355 end Process_Generic_List;
4357 ------------------------------------
4358 -- Process_Import_Predefined_Type --
4359 ------------------------------------
4361 procedure Process_Import_Predefined_Type is
4362 Loc : constant Source_Ptr := Sloc (N);
4364 Ftyp : Node_Id := Empty;
4370 String_To_Name_Buffer (Strval (Expression (Arg3)));
4373 Elmt := First_Elmt (Predefined_Float_Types);
4374 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4378 Ftyp := Node (Elmt);
4380 if Present (Ftyp) then
4382 -- Don't build a derived type declaration, because predefined C
4383 -- types have no declaration anywhere, so cannot really be named.
4384 -- Instead build a full type declaration, starting with an
4385 -- appropriate type definition is built
4387 if Is_Floating_Point_Type (Ftyp) then
4388 Def := Make_Floating_Point_Definition (Loc,
4389 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4390 Make_Real_Range_Specification (Loc,
4391 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4392 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4394 -- Should never have a predefined type we cannot handle
4397 raise Program_Error;
4400 -- Build and insert a Full_Type_Declaration, which will be
4401 -- analyzed as soon as this list entry has been analyzed.
4403 Decl := Make_Full_Type_Declaration (Loc,
4404 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4405 Type_Definition => Def);
4407 Insert_After (N, Decl);
4408 Mark_Rewrite_Insertion (Decl);
4411 Error_Pragma_Arg ("no matching type found for pragma%",
4414 end Process_Import_Predefined_Type;
4416 ---------------------------------
4417 -- Process_Import_Or_Interface --
4418 ---------------------------------
4420 procedure Process_Import_Or_Interface is
4426 Process_Convention (C, Def_Id);
4427 Kill_Size_Check_Code (Def_Id);
4428 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4430 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4432 -- We do not permit Import to apply to a renaming declaration
4434 if Present (Renamed_Object (Def_Id)) then
4436 ("pragma% not allowed for object renaming", Arg2);
4438 -- User initialization is not allowed for imported object, but
4439 -- the object declaration may contain a default initialization,
4440 -- that will be discarded. Note that an explicit initialization
4441 -- only counts if it comes from source, otherwise it is simply
4442 -- the code generator making an implicit initialization explicit.
4444 elsif Present (Expression (Parent (Def_Id)))
4445 and then Comes_From_Source (Expression (Parent (Def_Id)))
4447 Error_Msg_Sloc := Sloc (Def_Id);
4449 ("no initialization allowed for declaration of& #",
4450 "\imported entities cannot be initialized (RM B.1(24))",
4454 Set_Imported (Def_Id);
4455 Process_Interface_Name (Def_Id, Arg3, Arg4);
4457 -- Note that we do not set Is_Public here. That's because we
4458 -- only want to set it if there is no address clause, and we
4459 -- don't know that yet, so we delay that processing till
4462 -- pragma Import completes deferred constants
4464 if Ekind (Def_Id) = E_Constant then
4465 Set_Has_Completion (Def_Id);
4468 -- It is not possible to import a constant of an unconstrained
4469 -- array type (e.g. string) because there is no simple way to
4470 -- write a meaningful subtype for it.
4472 if Is_Array_Type (Etype (Def_Id))
4473 and then not Is_Constrained (Etype (Def_Id))
4476 ("imported constant& must have a constrained subtype",
4481 elsif Is_Subprogram (Def_Id)
4482 or else Is_Generic_Subprogram (Def_Id)
4484 -- If the name is overloaded, pragma applies to all of the denoted
4485 -- entities in the same declarative part.
4488 while Present (Hom_Id) loop
4489 Def_Id := Get_Base_Subprogram (Hom_Id);
4491 -- Ignore inherited subprograms because the pragma will apply
4492 -- to the parent operation, which is the one called.
4494 if Is_Overloadable (Def_Id)
4495 and then Present (Alias (Def_Id))
4499 -- If it is not a subprogram, it must be in an outer scope and
4500 -- pragma does not apply.
4502 elsif not Is_Subprogram (Def_Id)
4503 and then not Is_Generic_Subprogram (Def_Id)
4507 -- The pragma does not apply to primitives of interfaces
4509 elsif Is_Dispatching_Operation (Def_Id)
4510 and then Present (Find_Dispatching_Type (Def_Id))
4511 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4515 -- Verify that the homonym is in the same declarative part (not
4516 -- just the same scope).
4518 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4519 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4524 Set_Imported (Def_Id);
4526 -- Reject an Import applied to an abstract subprogram
4528 if Is_Subprogram (Def_Id)
4529 and then Is_Abstract_Subprogram (Def_Id)
4531 Error_Msg_Sloc := Sloc (Def_Id);
4533 ("cannot import abstract subprogram& declared#",
4537 -- Special processing for Convention_Intrinsic
4539 if C = Convention_Intrinsic then
4541 -- Link_Name argument not allowed for intrinsic
4545 Set_Is_Intrinsic_Subprogram (Def_Id);
4547 -- If no external name is present, then check that this
4548 -- is a valid intrinsic subprogram. If an external name
4549 -- is present, then this is handled by the back end.
4552 Check_Intrinsic_Subprogram
4553 (Def_Id, Get_Pragma_Arg (Arg2));
4557 -- All interfaced procedures need an external symbol created
4558 -- for them since they are always referenced from another
4561 Set_Is_Public (Def_Id);
4563 -- Verify that the subprogram does not have a completion
4564 -- through a renaming declaration. For other completions the
4565 -- pragma appears as a too late representation.
4568 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4572 and then Nkind (Decl) = N_Subprogram_Declaration
4573 and then Present (Corresponding_Body (Decl))
4574 and then Nkind (Unit_Declaration_Node
4575 (Corresponding_Body (Decl))) =
4576 N_Subprogram_Renaming_Declaration
4578 Error_Msg_Sloc := Sloc (Def_Id);
4580 ("cannot import&, renaming already provided for " &
4581 "declaration #", N, Def_Id);
4585 Set_Has_Completion (Def_Id);
4586 Process_Interface_Name (Def_Id, Arg3, Arg4);
4589 if Is_Compilation_Unit (Hom_Id) then
4591 -- Its possible homonyms are not affected by the pragma.
4592 -- Such homonyms might be present in the context of other
4593 -- units being compiled.
4598 Hom_Id := Homonym (Hom_Id);
4602 -- When the convention is Java or CIL, we also allow Import to be
4603 -- given for packages, generic packages, exceptions, record
4604 -- components, and access to subprograms.
4606 elsif (C = Convention_Java or else C = Convention_CIL)
4608 (Is_Package_Or_Generic_Package (Def_Id)
4609 or else Ekind (Def_Id) = E_Exception
4610 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4611 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4613 Set_Imported (Def_Id);
4614 Set_Is_Public (Def_Id);
4615 Process_Interface_Name (Def_Id, Arg3, Arg4);
4617 -- Import a CPP class
4619 elsif Is_Record_Type (Def_Id)
4620 and then C = Convention_CPP
4622 -- Types treated as CPP classes must be declared limited (note:
4623 -- this used to be a warning but there is no real benefit to it
4624 -- since we did effectively intend to treat the type as limited
4627 if not Is_Limited_Type (Def_Id) then
4629 ("imported 'C'P'P type must be limited",
4630 Get_Pragma_Arg (Arg2));
4633 Set_Is_CPP_Class (Def_Id);
4635 -- Imported CPP types must not have discriminants (because C++
4636 -- classes do not have discriminants).
4638 if Has_Discriminants (Def_Id) then
4640 ("imported 'C'P'P type cannot have discriminants",
4641 First (Discriminant_Specifications
4642 (Declaration_Node (Def_Id))));
4645 -- Components of imported CPP types must not have default
4646 -- expressions because the constructor (if any) is on the
4650 Tdef : constant Node_Id :=
4651 Type_Definition (Declaration_Node (Def_Id));
4656 if Nkind (Tdef) = N_Record_Definition then
4657 Clist := Component_List (Tdef);
4660 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4661 Clist := Component_List (Record_Extension_Part (Tdef));
4664 if Present (Clist) then
4665 Comp := First (Component_Items (Clist));
4666 while Present (Comp) loop
4667 if Present (Expression (Comp)) then
4669 ("component of imported 'C'P'P type cannot have" &
4670 " default expression", Expression (Comp));
4678 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4680 Check_Arg_Count (3);
4681 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4683 Process_Import_Predefined_Type;
4687 ("second argument of pragma% must be object, subprogram" &
4688 " or incomplete type",
4692 -- If this pragma applies to a compilation unit, then the unit, which
4693 -- is a subprogram, does not require (or allow) a body. We also do
4694 -- not need to elaborate imported procedures.
4696 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4698 Cunit : constant Node_Id := Parent (Parent (N));
4700 Set_Body_Required (Cunit, False);
4703 end Process_Import_Or_Interface;
4705 --------------------
4706 -- Process_Inline --
4707 --------------------
4709 procedure Process_Inline (Active : Boolean) is
4716 Effective : Boolean := False;
4717 -- Set True if inline has some effect, i.e. if there is at least one
4718 -- subprogram set as inlined as a result of the use of the pragma.
4720 procedure Make_Inline (Subp : Entity_Id);
4721 -- Subp is the defining unit name of the subprogram declaration. Set
4722 -- the flag, as well as the flag in the corresponding body, if there
4725 procedure Set_Inline_Flags (Subp : Entity_Id);
4726 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4727 -- Has_Pragma_Inline_Always for the Inline_Always case.
4729 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4730 -- Returns True if it can be determined at this stage that inlining
4731 -- is not possible, for example if the body is available and contains
4732 -- exception handlers, we prevent inlining, since otherwise we can
4733 -- get undefined symbols at link time. This function also emits a
4734 -- warning if front-end inlining is enabled and the pragma appears
4737 -- ??? is business with link symbols still valid, or does it relate
4738 -- to front end ZCX which is being phased out ???
4740 ---------------------------
4741 -- Inlining_Not_Possible --
4742 ---------------------------
4744 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4745 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4749 if Nkind (Decl) = N_Subprogram_Body then
4750 Stats := Handled_Statement_Sequence (Decl);
4751 return Present (Exception_Handlers (Stats))
4752 or else Present (At_End_Proc (Stats));
4754 elsif Nkind (Decl) = N_Subprogram_Declaration
4755 and then Present (Corresponding_Body (Decl))
4757 if Front_End_Inlining
4758 and then Analyzed (Corresponding_Body (Decl))
4760 Error_Msg_N ("pragma appears too late, ignored?", N);
4763 -- If the subprogram is a renaming as body, the body is just a
4764 -- call to the renamed subprogram, and inlining is trivially
4768 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4769 N_Subprogram_Renaming_Declaration
4775 Handled_Statement_Sequence
4776 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4779 Present (Exception_Handlers (Stats))
4780 or else Present (At_End_Proc (Stats));
4784 -- If body is not available, assume the best, the check is
4785 -- performed again when compiling enclosing package bodies.
4789 end Inlining_Not_Possible;
4795 procedure Make_Inline (Subp : Entity_Id) is
4796 Kind : constant Entity_Kind := Ekind (Subp);
4797 Inner_Subp : Entity_Id := Subp;
4800 -- Ignore if bad type, avoid cascaded error
4802 if Etype (Subp) = Any_Type then
4806 -- Ignore if all inlining is suppressed
4808 elsif Suppress_All_Inlining then
4812 -- If inlining is not possible, for now do not treat as an error
4814 elsif Inlining_Not_Possible (Subp) then
4818 -- Here we have a candidate for inlining, but we must exclude
4819 -- derived operations. Otherwise we would end up trying to inline
4820 -- a phantom declaration, and the result would be to drag in a
4821 -- body which has no direct inlining associated with it. That
4822 -- would not only be inefficient but would also result in the
4823 -- backend doing cross-unit inlining in cases where it was
4824 -- definitely inappropriate to do so.
4826 -- However, a simple Comes_From_Source test is insufficient, since
4827 -- we do want to allow inlining of generic instances which also do
4828 -- not come from source. We also need to recognize specs generated
4829 -- by the front-end for bodies that carry the pragma. Finally,
4830 -- predefined operators do not come from source but are not
4831 -- inlineable either.
4833 elsif Is_Generic_Instance (Subp)
4834 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4838 elsif not Comes_From_Source (Subp)
4839 and then Scope (Subp) /= Standard_Standard
4845 -- The referenced entity must either be the enclosing entity, or
4846 -- an entity declared within the current open scope.
4848 if Present (Scope (Subp))
4849 and then Scope (Subp) /= Current_Scope
4850 and then Subp /= Current_Scope
4853 ("argument of% must be entity in current scope", Assoc);
4857 -- Processing for procedure, operator or function. If subprogram
4858 -- is aliased (as for an instance) indicate that the renamed
4859 -- entity (if declared in the same unit) is inlined.
4861 if Is_Subprogram (Subp) then
4862 Inner_Subp := Ultimate_Alias (Inner_Subp);
4864 if In_Same_Source_Unit (Subp, Inner_Subp) then
4865 Set_Inline_Flags (Inner_Subp);
4867 Decl := Parent (Parent (Inner_Subp));
4869 if Nkind (Decl) = N_Subprogram_Declaration
4870 and then Present (Corresponding_Body (Decl))
4872 Set_Inline_Flags (Corresponding_Body (Decl));
4874 elsif Is_Generic_Instance (Subp) then
4876 -- Indicate that the body needs to be created for
4877 -- inlining subsequent calls. The instantiation node
4878 -- follows the declaration of the wrapper package
4881 if Scope (Subp) /= Standard_Standard
4883 Need_Subprogram_Instance_Body
4884 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4890 -- Inline is a program unit pragma (RM 10.1.5) and cannot
4891 -- appear in a formal part to apply to a formal subprogram.
4892 -- Do not apply check within an instance or a formal package
4893 -- the test will have been applied to the original generic.
4895 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4896 and then List_Containing (Decl) = List_Containing (N)
4897 and then not In_Instance
4900 ("Inline cannot apply to a formal subprogram", N);
4906 -- For a generic subprogram set flag as well, for use at the point
4907 -- of instantiation, to determine whether the body should be
4910 elsif Is_Generic_Subprogram (Subp) then
4911 Set_Inline_Flags (Subp);
4914 -- Literals are by definition inlined
4916 elsif Kind = E_Enumeration_Literal then
4919 -- Anything else is an error
4923 ("expect subprogram name for pragma%", Assoc);
4927 ----------------------
4928 -- Set_Inline_Flags --
4929 ----------------------
4931 procedure Set_Inline_Flags (Subp : Entity_Id) is
4934 Set_Is_Inlined (Subp);
4937 if not Has_Pragma_Inline (Subp) then
4938 Set_Has_Pragma_Inline (Subp);
4942 if Prag_Id = Pragma_Inline_Always then
4943 Set_Has_Pragma_Inline_Always (Subp);
4945 end Set_Inline_Flags;
4947 -- Start of processing for Process_Inline
4950 Check_No_Identifiers;
4951 Check_At_Least_N_Arguments (1);
4954 Inline_Processing_Required := True;
4958 while Present (Assoc) loop
4959 Subp_Id := Get_Pragma_Arg (Assoc);
4963 if Is_Entity_Name (Subp_Id) then
4964 Subp := Entity (Subp_Id);
4966 if Subp = Any_Id then
4968 -- If previous error, avoid cascaded errors
4976 -- For the pragma case, climb homonym chain. This is
4977 -- what implements allowing the pragma in the renaming
4978 -- case, with the result applying to the ancestors, and
4979 -- also allows Inline to apply to all previous homonyms.
4981 if not From_Aspect_Specification (N) then
4982 while Present (Homonym (Subp))
4983 and then Scope (Homonym (Subp)) = Current_Scope
4985 Make_Inline (Homonym (Subp));
4986 Subp := Homonym (Subp);
4994 ("inappropriate argument for pragma%", Assoc);
4997 and then Warn_On_Redundant_Constructs
4998 and then not Suppress_All_Inlining
5000 if Inlining_Not_Possible (Subp) then
5002 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
5005 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
5013 ----------------------------
5014 -- Process_Interface_Name --
5015 ----------------------------
5017 procedure Process_Interface_Name
5018 (Subprogram_Def : Entity_Id;
5024 String_Val : String_Id;
5026 procedure Check_Form_Of_Interface_Name
5028 Ext_Name_Case : Boolean);
5029 -- SN is a string literal node for an interface name. This routine
5030 -- performs some minimal checks that the name is reasonable. In
5031 -- particular that no spaces or other obviously incorrect characters
5032 -- appear. This is only a warning, since any characters are allowed.
5033 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5035 ----------------------------------
5036 -- Check_Form_Of_Interface_Name --
5037 ----------------------------------
5039 procedure Check_Form_Of_Interface_Name
5041 Ext_Name_Case : Boolean)
5043 S : constant String_Id := Strval (Expr_Value_S (SN));
5044 SL : constant Nat := String_Length (S);
5049 Error_Msg_N ("interface name cannot be null string", SN);
5052 for J in 1 .. SL loop
5053 C := Get_String_Char (S, J);
5055 -- Look for dubious character and issue unconditional warning.
5056 -- Definitely dubious if not in character range.
5058 if not In_Character_Range (C)
5060 -- For all cases except CLI target,
5061 -- commas, spaces and slashes are dubious (in CLI, we use
5062 -- commas and backslashes in external names to specify
5063 -- assembly version and public key, while slashes and spaces
5064 -- can be used in names to mark nested classes and
5067 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5068 and then (Get_Character (C) = ','
5070 Get_Character (C) = '\'))
5071 or else (VM_Target /= CLI_Target
5072 and then (Get_Character (C) = ' '
5074 Get_Character (C) = '/'))
5077 ("?interface name contains illegal character",
5078 Sloc (SN) + Source_Ptr (J));
5081 end Check_Form_Of_Interface_Name;
5083 -- Start of processing for Process_Interface_Name
5086 if No (Link_Arg) then
5087 if No (Ext_Arg) then
5088 if VM_Target = CLI_Target
5089 and then Ekind (Subprogram_Def) = E_Package
5090 and then Nkind (Parent (Subprogram_Def)) =
5091 N_Package_Specification
5092 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5097 (Generic_Parent (Parent (Subprogram_Def))));
5102 elsif Chars (Ext_Arg) = Name_Link_Name then
5104 Link_Nam := Expression (Ext_Arg);
5107 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5108 Ext_Nam := Expression (Ext_Arg);
5113 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5114 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5115 Ext_Nam := Expression (Ext_Arg);
5116 Link_Nam := Expression (Link_Arg);
5119 -- Check expressions for external name and link name are static
5121 if Present (Ext_Nam) then
5122 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5123 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5125 -- Verify that external name is not the name of a local entity,
5126 -- which would hide the imported one and could lead to run-time
5127 -- surprises. The problem can only arise for entities declared in
5128 -- a package body (otherwise the external name is fully qualified
5129 -- and will not conflict).
5137 if Prag_Id = Pragma_Import then
5138 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5140 E := Entity_Id (Get_Name_Table_Info (Nam));
5142 if Nam /= Chars (Subprogram_Def)
5143 and then Present (E)
5144 and then not Is_Overloadable (E)
5145 and then Is_Immediately_Visible (E)
5146 and then not Is_Imported (E)
5147 and then Ekind (Scope (E)) = E_Package
5150 while Present (Par) loop
5151 if Nkind (Par) = N_Package_Body then
5152 Error_Msg_Sloc := Sloc (E);
5154 ("imported entity is hidden by & declared#",
5159 Par := Parent (Par);
5166 if Present (Link_Nam) then
5167 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5168 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5171 -- If there is no link name, just set the external name
5173 if No (Link_Nam) then
5174 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5176 -- For the Link_Name case, the given literal is preceded by an
5177 -- asterisk, which indicates to GCC that the given name should be
5178 -- taken literally, and in particular that no prepending of
5179 -- underlines should occur, even in systems where this is the
5185 if VM_Target = No_VM then
5186 Store_String_Char (Get_Char_Code ('*'));
5189 String_Val := Strval (Expr_Value_S (Link_Nam));
5190 Store_String_Chars (String_Val);
5192 Make_String_Literal (Sloc (Link_Nam),
5193 Strval => End_String);
5196 -- Set the interface name. If the entity is a generic instance, use
5197 -- its alias, which is the callable entity.
5199 if Is_Generic_Instance (Subprogram_Def) then
5200 Set_Encoded_Interface_Name
5201 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5203 Set_Encoded_Interface_Name
5204 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5207 -- We allow duplicated export names in CIL/Java, as they are always
5208 -- enclosed in a namespace that differentiates them, and overloaded
5209 -- entities are supported by the VM.
5211 if Convention (Subprogram_Def) /= Convention_CIL
5213 Convention (Subprogram_Def) /= Convention_Java
5215 Check_Duplicated_Export_Name (Link_Nam);
5217 end Process_Interface_Name;
5219 -----------------------------------------
5220 -- Process_Interrupt_Or_Attach_Handler --
5221 -----------------------------------------
5223 procedure Process_Interrupt_Or_Attach_Handler is
5224 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5225 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5226 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5229 Set_Is_Interrupt_Handler (Handler_Proc);
5231 -- If the pragma is not associated with a handler procedure within a
5232 -- protected type, then it must be for a nonprotected procedure for
5233 -- the AAMP target, in which case we don't associate a representation
5234 -- item with the procedure's scope.
5236 if Ekind (Proc_Scope) = E_Protected_Type then
5237 if Prag_Id = Pragma_Interrupt_Handler
5239 Prag_Id = Pragma_Attach_Handler
5241 Record_Rep_Item (Proc_Scope, N);
5244 end Process_Interrupt_Or_Attach_Handler;
5246 --------------------------------------------------
5247 -- Process_Restrictions_Or_Restriction_Warnings --
5248 --------------------------------------------------
5250 -- Note: some of the simple identifier cases were handled in par-prag,
5251 -- but it is harmless (and more straightforward) to simply handle all
5252 -- cases here, even if it means we repeat a bit of work in some cases.
5254 procedure Process_Restrictions_Or_Restriction_Warnings
5258 R_Id : Restriction_Id;
5263 procedure Check_Unit_Name (N : Node_Id);
5264 -- Checks unit name parameter for No_Dependence. Returns if it has
5265 -- an appropriate form, otherwise raises pragma argument error.
5267 ---------------------
5268 -- Check_Unit_Name --
5269 ---------------------
5271 procedure Check_Unit_Name (N : Node_Id) is
5273 if Nkind (N) = N_Selected_Component then
5274 Check_Unit_Name (Prefix (N));
5275 Check_Unit_Name (Selector_Name (N));
5277 elsif Nkind (N) = N_Identifier then
5282 ("wrong form for unit name for No_Dependence", N);
5284 end Check_Unit_Name;
5286 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5289 -- Ignore all Restrictions pragma in CodePeer mode
5291 if CodePeer_Mode then
5295 Check_Ada_83_Warning;
5296 Check_At_Least_N_Arguments (1);
5297 Check_Valid_Configuration_Pragma;
5300 while Present (Arg) loop
5302 Expr := Get_Pragma_Arg (Arg);
5304 -- Case of no restriction identifier present
5306 if Id = No_Name then
5307 if Nkind (Expr) /= N_Identifier then
5309 ("invalid form for restriction", Arg);
5314 (Process_Restriction_Synonyms (Expr));
5316 if R_Id not in All_Boolean_Restrictions then
5317 Error_Msg_Name_1 := Pname;
5319 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5321 -- Check for possible misspelling
5323 for J in Restriction_Id loop
5325 Rnm : constant String := Restriction_Id'Image (J);
5328 Name_Buffer (1 .. Rnm'Length) := Rnm;
5329 Name_Len := Rnm'Length;
5330 Set_Casing (All_Lower_Case);
5332 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5334 (Identifier_Casing (Current_Source_File));
5335 Error_Msg_String (1 .. Rnm'Length) :=
5336 Name_Buffer (1 .. Name_Len);
5337 Error_Msg_Strlen := Rnm'Length;
5338 Error_Msg_N -- CODEFIX
5339 ("\possible misspelling of ""~""",
5340 Get_Pragma_Arg (Arg));
5349 if Implementation_Restriction (R_Id) then
5350 Check_Restriction (No_Implementation_Restrictions, Arg);
5353 -- If this is a warning, then set the warning unless we already
5354 -- have a real restriction active (we never want a warning to
5355 -- override a real restriction).
5358 if not Restriction_Active (R_Id) then
5359 Set_Restriction (R_Id, N);
5360 Restriction_Warnings (R_Id) := True;
5363 -- If real restriction case, then set it and make sure that the
5364 -- restriction warning flag is off, since a real restriction
5365 -- always overrides a warning.
5368 Set_Restriction (R_Id, N);
5369 Restriction_Warnings (R_Id) := False;
5372 -- Check for obsolescent restrictions in Ada 2005 mode
5375 and then Ada_Version >= Ada_2005
5376 and then (R_Id = No_Asynchronous_Control
5378 R_Id = No_Unchecked_Deallocation
5380 R_Id = No_Unchecked_Conversion)
5382 Check_Restriction (No_Obsolescent_Features, N);
5385 -- A very special case that must be processed here: pragma
5386 -- Restrictions (No_Exceptions) turns off all run-time
5387 -- checking. This is a bit dubious in terms of the formal
5388 -- language definition, but it is what is intended by RM
5389 -- H.4(12). Restriction_Warnings never affects generated code
5390 -- so this is done only in the real restriction case.
5392 -- Atomic_Synchronization is not a real check, so it is not
5393 -- affected by this processing).
5395 if R_Id = No_Exceptions and then not Warn then
5396 for J in Scope_Suppress'Range loop
5397 if J /= Atomic_Synchronization then
5398 Scope_Suppress (J) := True;
5403 -- Case of No_Dependence => unit-name. Note that the parser
5404 -- already made the necessary entry in the No_Dependence table.
5406 elsif Id = Name_No_Dependence then
5407 Check_Unit_Name (Expr);
5409 -- Case of No_Specification_Of_Aspect => Identifier.
5411 elsif Id = Name_No_Specification_Of_Aspect then
5416 if Nkind (Expr) /= N_Identifier then
5419 A_Id := Get_Aspect_Id (Chars (Expr));
5422 if A_Id = No_Aspect then
5423 Error_Pragma_Arg ("invalid restriction name", Arg);
5425 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5429 -- All other cases of restriction identifier present
5432 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5433 Analyze_And_Resolve (Expr, Any_Integer);
5435 if R_Id not in All_Parameter_Restrictions then
5437 ("invalid restriction parameter identifier", Arg);
5439 elsif not Is_OK_Static_Expression (Expr) then
5440 Flag_Non_Static_Expr
5441 ("value must be static expression!", Expr);
5444 elsif not Is_Integer_Type (Etype (Expr))
5445 or else Expr_Value (Expr) < 0
5448 ("value must be non-negative integer", Arg);
5451 -- Restriction pragma is active
5453 Val := Expr_Value (Expr);
5455 if not UI_Is_In_Int_Range (Val) then
5457 ("pragma ignored, value too large?", Arg);
5460 -- Warning case. If the real restriction is active, then we
5461 -- ignore the request, since warning never overrides a real
5462 -- restriction. Otherwise we set the proper warning. Note that
5463 -- this circuit sets the warning again if it is already set,
5464 -- which is what we want, since the constant may have changed.
5467 if not Restriction_Active (R_Id) then
5469 (R_Id, N, Integer (UI_To_Int (Val)));
5470 Restriction_Warnings (R_Id) := True;
5473 -- Real restriction case, set restriction and make sure warning
5474 -- flag is off since real restriction always overrides warning.
5477 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5478 Restriction_Warnings (R_Id) := False;
5484 end Process_Restrictions_Or_Restriction_Warnings;
5486 ---------------------------------
5487 -- Process_Suppress_Unsuppress --
5488 ---------------------------------
5490 -- Note: this procedure makes entries in the check suppress data
5491 -- structures managed by Sem. See spec of package Sem for full
5492 -- details on how we handle recording of check suppression.
5494 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5499 In_Package_Spec : constant Boolean :=
5500 Is_Package_Or_Generic_Package (Current_Scope)
5501 and then not In_Package_Body (Current_Scope);
5503 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5504 -- Used to suppress a single check on the given entity
5506 --------------------------------
5507 -- Suppress_Unsuppress_Echeck --
5508 --------------------------------
5510 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5512 -- Check for error of trying to set atomic synchronization for
5513 -- a non-atomic variable.
5515 if C = Atomic_Synchronization
5516 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5519 ("pragma & requires atomic type or variable",
5520 Pragma_Identifier (Original_Node (N)));
5523 Set_Checks_May_Be_Suppressed (E);
5525 if In_Package_Spec then
5526 Push_Global_Suppress_Stack_Entry
5529 Suppress => Suppress_Case);
5531 Push_Local_Suppress_Stack_Entry
5534 Suppress => Suppress_Case);
5537 -- If this is a first subtype, and the base type is distinct,
5538 -- then also set the suppress flags on the base type.
5540 if Is_First_Subtype (E)
5541 and then Etype (E) /= E
5543 Suppress_Unsuppress_Echeck (Etype (E), C);
5545 end Suppress_Unsuppress_Echeck;
5547 -- Start of processing for Process_Suppress_Unsuppress
5550 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5551 -- user code: we want to generate checks for analysis purposes, as
5552 -- set respectively by -gnatC and -gnatd.F
5554 if (CodePeer_Mode or Alfa_Mode)
5555 and then Comes_From_Source (N)
5560 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5561 -- declarative part or a package spec (RM 11.5(5)).
5563 if not Is_Configuration_Pragma then
5564 Check_Is_In_Decl_Part_Or_Package_Spec;
5567 Check_At_Least_N_Arguments (1);
5568 Check_At_Most_N_Arguments (2);
5569 Check_No_Identifier (Arg1);
5570 Check_Arg_Is_Identifier (Arg1);
5572 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5574 if C = No_Check_Id then
5576 ("argument of pragma% is not valid check name", Arg1);
5579 if not Suppress_Case
5580 and then (C = All_Checks or else C = Overflow_Check)
5582 Opt.Overflow_Checks_Unsuppressed := True;
5585 if Arg_Count = 1 then
5587 -- Make an entry in the local scope suppress table. This is the
5588 -- table that directly shows the current value of the scope
5589 -- suppress check for any check id value.
5591 if C = All_Checks then
5593 -- For All_Checks, we set all specific predefined checks with
5594 -- the exception of Elaboration_Check, which is handled
5595 -- specially because of not wanting All_Checks to have the
5596 -- effect of deactivating static elaboration order processing.
5597 -- Atomic_Synchronization is also not affected, since this is
5598 -- not a real check.
5600 for J in Scope_Suppress'Range loop
5601 if J /= Elaboration_Check
5602 and then J /= Atomic_Synchronization
5604 Scope_Suppress (J) := Suppress_Case;
5608 -- If not All_Checks, and predefined check, then set appropriate
5609 -- scope entry. Note that we will set Elaboration_Check if this
5610 -- is explicitly specified. Atomic_Synchronization is allowed
5611 -- only if internally generated and entity is atomic.
5613 elsif C in Predefined_Check_Id
5614 and then (not Comes_From_Source (N)
5615 or else C /= Atomic_Synchronization)
5617 Scope_Suppress (C) := Suppress_Case;
5620 -- Also make an entry in the Local_Entity_Suppress table
5622 Push_Local_Suppress_Stack_Entry
5625 Suppress => Suppress_Case);
5627 -- Case of two arguments present, where the check is suppressed for
5628 -- a specified entity (given as the second argument of the pragma)
5631 -- This is obsolescent in Ada 2005 mode
5633 if Ada_Version >= Ada_2005 then
5634 Check_Restriction (No_Obsolescent_Features, Arg2);
5637 Check_Optional_Identifier (Arg2, Name_On);
5638 E_Id := Get_Pragma_Arg (Arg2);
5641 if not Is_Entity_Name (E_Id) then
5643 ("second argument of pragma% must be entity name", Arg2);
5652 -- Enforce RM 11.5(7) which requires that for a pragma that
5653 -- appears within a package spec, the named entity must be
5654 -- within the package spec. We allow the package name itself
5655 -- to be mentioned since that makes sense, although it is not
5656 -- strictly allowed by 11.5(7).
5659 and then E /= Current_Scope
5660 and then Scope (E) /= Current_Scope
5663 ("entity in pragma% is not in package spec (RM 11.5(7))",
5667 -- Loop through homonyms. As noted below, in the case of a package
5668 -- spec, only homonyms within the package spec are considered.
5671 Suppress_Unsuppress_Echeck (E, C);
5673 if Is_Generic_Instance (E)
5674 and then Is_Subprogram (E)
5675 and then Present (Alias (E))
5677 Suppress_Unsuppress_Echeck (Alias (E), C);
5680 -- Move to next homonym if not aspect spec case
5682 exit when From_Aspect_Specification (N);
5686 -- If we are within a package specification, the pragma only
5687 -- applies to homonyms in the same scope.
5689 exit when In_Package_Spec
5690 and then Scope (E) /= Current_Scope;
5693 end Process_Suppress_Unsuppress;
5699 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5701 if Is_Imported (E) then
5703 ("cannot export entity& that was previously imported", Arg);
5705 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5707 ("cannot export entity& that has an address clause", Arg);
5710 Set_Is_Exported (E);
5712 -- Generate a reference for entity explicitly, because the
5713 -- identifier may be overloaded and name resolution will not
5716 Generate_Reference (E, Arg);
5718 -- Deal with exporting non-library level entity
5720 if not Is_Library_Level_Entity (E) then
5722 -- Not allowed at all for subprograms
5724 if Is_Subprogram (E) then
5725 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5727 -- Otherwise set public and statically allocated
5731 Set_Is_Statically_Allocated (E);
5733 -- Warn if the corresponding W flag is set and the pragma comes
5734 -- from source. The latter may not be true e.g. on VMS where we
5735 -- expand export pragmas for exception codes associated with
5736 -- imported or exported exceptions. We do not want to generate
5737 -- a warning for something that the user did not write.
5739 if Warn_On_Export_Import
5740 and then Comes_From_Source (Arg)
5743 ("?& has been made static as a result of Export", Arg, E);
5745 ("\this usage is non-standard and non-portable", Arg);
5750 if Warn_On_Export_Import and then Is_Type (E) then
5751 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5754 if Warn_On_Export_Import and Inside_A_Generic then
5756 ("all instances of& will have the same external name?", Arg, E);
5760 ----------------------------------------------
5761 -- Set_Extended_Import_Export_External_Name --
5762 ----------------------------------------------
5764 procedure Set_Extended_Import_Export_External_Name
5765 (Internal_Ent : Entity_Id;
5766 Arg_External : Node_Id)
5768 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5772 if No (Arg_External) then
5776 Check_Arg_Is_External_Name (Arg_External);
5778 if Nkind (Arg_External) = N_String_Literal then
5779 if String_Length (Strval (Arg_External)) = 0 then
5782 New_Name := Adjust_External_Name_Case (Arg_External);
5785 elsif Nkind (Arg_External) = N_Identifier then
5786 New_Name := Get_Default_External_Name (Arg_External);
5788 -- Check_Arg_Is_External_Name should let through only identifiers and
5789 -- string literals or static string expressions (which are folded to
5790 -- string literals).
5793 raise Program_Error;
5796 -- If we already have an external name set (by a prior normal Import
5797 -- or Export pragma), then the external names must match
5799 if Present (Interface_Name (Internal_Ent)) then
5800 Check_Matching_Internal_Names : declare
5801 S1 : constant String_Id := Strval (Old_Name);
5802 S2 : constant String_Id := Strval (New_Name);
5805 -- Called if names do not match
5811 procedure Mismatch is
5813 Error_Msg_Sloc := Sloc (Old_Name);
5815 ("external name does not match that given #",
5819 -- Start of processing for Check_Matching_Internal_Names
5822 if String_Length (S1) /= String_Length (S2) then
5826 for J in 1 .. String_Length (S1) loop
5827 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5832 end Check_Matching_Internal_Names;
5834 -- Otherwise set the given name
5837 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5838 Check_Duplicated_Export_Name (New_Name);
5840 end Set_Extended_Import_Export_External_Name;
5846 procedure Set_Imported (E : Entity_Id) is
5848 -- Error message if already imported or exported
5850 if Is_Exported (E) or else Is_Imported (E) then
5852 -- Error if being set Exported twice
5854 if Is_Exported (E) then
5855 Error_Msg_NE ("entity& was previously exported", N, E);
5857 -- OK if Import/Interface case
5859 elsif Import_Interface_Present (N) then
5862 -- Error if being set Imported twice
5865 Error_Msg_NE ("entity& was previously imported", N, E);
5868 Error_Msg_Name_1 := Pname;
5870 ("\(pragma% applies to all previous entities)", N);
5872 Error_Msg_Sloc := Sloc (E);
5873 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5875 -- Here if not previously imported or exported, OK to import
5878 Set_Is_Imported (E);
5880 -- If the entity is an object that is not at the library level,
5881 -- then it is statically allocated. We do not worry about objects
5882 -- with address clauses in this context since they are not really
5883 -- imported in the linker sense.
5886 and then not Is_Library_Level_Entity (E)
5887 and then No (Address_Clause (E))
5889 Set_Is_Statically_Allocated (E);
5896 -------------------------
5897 -- Set_Mechanism_Value --
5898 -------------------------
5900 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5901 -- analyzed, since it is semantic nonsense), so we get it in the exact
5902 -- form created by the parser.
5904 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5907 Mech_Name_Id : Name_Id;
5909 procedure Bad_Class;
5910 -- Signal bad descriptor class name
5912 procedure Bad_Mechanism;
5913 -- Signal bad mechanism name
5919 procedure Bad_Class is
5921 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5924 -------------------------
5925 -- Bad_Mechanism_Value --
5926 -------------------------
5928 procedure Bad_Mechanism is
5930 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5933 -- Start of processing for Set_Mechanism_Value
5936 if Mechanism (Ent) /= Default_Mechanism then
5938 ("mechanism for & has already been set", Mech_Name, Ent);
5941 -- MECHANISM_NAME ::= value | reference | descriptor |
5944 if Nkind (Mech_Name) = N_Identifier then
5945 if Chars (Mech_Name) = Name_Value then
5946 Set_Mechanism (Ent, By_Copy);
5949 elsif Chars (Mech_Name) = Name_Reference then
5950 Set_Mechanism (Ent, By_Reference);
5953 elsif Chars (Mech_Name) = Name_Descriptor then
5954 Check_VMS (Mech_Name);
5956 -- Descriptor => Short_Descriptor if pragma was given
5958 if Short_Descriptors then
5959 Set_Mechanism (Ent, By_Short_Descriptor);
5961 Set_Mechanism (Ent, By_Descriptor);
5966 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5967 Check_VMS (Mech_Name);
5968 Set_Mechanism (Ent, By_Short_Descriptor);
5971 elsif Chars (Mech_Name) = Name_Copy then
5973 ("bad mechanism name, Value assumed", Mech_Name);
5979 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5980 -- short_descriptor (CLASS_NAME)
5981 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5983 -- Note: this form is parsed as an indexed component
5985 elsif Nkind (Mech_Name) = N_Indexed_Component then
5986 Class := First (Expressions (Mech_Name));
5988 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5989 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5990 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5991 or else Present (Next (Class))
5995 Mech_Name_Id := Chars (Prefix (Mech_Name));
5997 -- Change Descriptor => Short_Descriptor if pragma was given
5999 if Mech_Name_Id = Name_Descriptor
6000 and then Short_Descriptors
6002 Mech_Name_Id := Name_Short_Descriptor;
6006 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6007 -- short_descriptor (Class => CLASS_NAME)
6008 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6010 -- Note: this form is parsed as a function call
6012 elsif Nkind (Mech_Name) = N_Function_Call then
6013 Param := First (Parameter_Associations (Mech_Name));
6015 if Nkind (Name (Mech_Name)) /= N_Identifier
6016 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6017 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6018 or else Present (Next (Param))
6019 or else No (Selector_Name (Param))
6020 or else Chars (Selector_Name (Param)) /= Name_Class
6024 Class := Explicit_Actual_Parameter (Param);
6025 Mech_Name_Id := Chars (Name (Mech_Name));
6032 -- Fall through here with Class set to descriptor class name
6034 Check_VMS (Mech_Name);
6036 if Nkind (Class) /= N_Identifier then
6039 elsif Mech_Name_Id = Name_Descriptor
6040 and then Chars (Class) = Name_UBS
6042 Set_Mechanism (Ent, By_Descriptor_UBS);
6044 elsif Mech_Name_Id = Name_Descriptor
6045 and then Chars (Class) = Name_UBSB
6047 Set_Mechanism (Ent, By_Descriptor_UBSB);
6049 elsif Mech_Name_Id = Name_Descriptor
6050 and then Chars (Class) = Name_UBA
6052 Set_Mechanism (Ent, By_Descriptor_UBA);
6054 elsif Mech_Name_Id = Name_Descriptor
6055 and then Chars (Class) = Name_S
6057 Set_Mechanism (Ent, By_Descriptor_S);
6059 elsif Mech_Name_Id = Name_Descriptor
6060 and then Chars (Class) = Name_SB
6062 Set_Mechanism (Ent, By_Descriptor_SB);
6064 elsif Mech_Name_Id = Name_Descriptor
6065 and then Chars (Class) = Name_A
6067 Set_Mechanism (Ent, By_Descriptor_A);
6069 elsif Mech_Name_Id = Name_Descriptor
6070 and then Chars (Class) = Name_NCA
6072 Set_Mechanism (Ent, By_Descriptor_NCA);
6074 elsif Mech_Name_Id = Name_Short_Descriptor
6075 and then Chars (Class) = Name_UBS
6077 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6079 elsif Mech_Name_Id = Name_Short_Descriptor
6080 and then Chars (Class) = Name_UBSB
6082 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6084 elsif Mech_Name_Id = Name_Short_Descriptor
6085 and then Chars (Class) = Name_UBA
6087 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6089 elsif Mech_Name_Id = Name_Short_Descriptor
6090 and then Chars (Class) = Name_S
6092 Set_Mechanism (Ent, By_Short_Descriptor_S);
6094 elsif Mech_Name_Id = Name_Short_Descriptor
6095 and then Chars (Class) = Name_SB
6097 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6099 elsif Mech_Name_Id = Name_Short_Descriptor
6100 and then Chars (Class) = Name_A
6102 Set_Mechanism (Ent, By_Short_Descriptor_A);
6104 elsif Mech_Name_Id = Name_Short_Descriptor
6105 and then Chars (Class) = Name_NCA
6107 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6112 end Set_Mechanism_Value;
6114 ---------------------------
6115 -- Set_Ravenscar_Profile --
6116 ---------------------------
6118 -- The tasks to be done here are
6120 -- Set required policies
6122 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6123 -- pragma Locking_Policy (Ceiling_Locking)
6125 -- Set Detect_Blocking mode
6127 -- Set required restrictions (see System.Rident for detailed list)
6129 -- Set the No_Dependence rules
6130 -- No_Dependence => Ada.Asynchronous_Task_Control
6131 -- No_Dependence => Ada.Calendar
6132 -- No_Dependence => Ada.Execution_Time.Group_Budget
6133 -- No_Dependence => Ada.Execution_Time.Timers
6134 -- No_Dependence => Ada.Task_Attributes
6135 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6137 procedure Set_Ravenscar_Profile (N : Node_Id) is
6138 Prefix_Entity : Entity_Id;
6139 Selector_Entity : Entity_Id;
6140 Prefix_Node : Node_Id;
6144 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6146 if Task_Dispatching_Policy /= ' '
6147 and then Task_Dispatching_Policy /= 'F'
6149 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6150 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6152 -- Set the FIFO_Within_Priorities policy, but always preserve
6153 -- System_Location since we like the error message with the run time
6157 Task_Dispatching_Policy := 'F';
6159 if Task_Dispatching_Policy_Sloc /= System_Location then
6160 Task_Dispatching_Policy_Sloc := Loc;
6164 -- pragma Locking_Policy (Ceiling_Locking)
6166 if Locking_Policy /= ' '
6167 and then Locking_Policy /= 'C'
6169 Error_Msg_Sloc := Locking_Policy_Sloc;
6170 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6172 -- Set the Ceiling_Locking policy, but preserve System_Location since
6173 -- we like the error message with the run time name.
6176 Locking_Policy := 'C';
6178 if Locking_Policy_Sloc /= System_Location then
6179 Locking_Policy_Sloc := Loc;
6183 -- pragma Detect_Blocking
6185 Detect_Blocking := True;
6187 -- Set the corresponding restrictions
6189 Set_Profile_Restrictions
6190 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6192 -- Set the No_Dependence restrictions
6194 -- The following No_Dependence restrictions:
6195 -- No_Dependence => Ada.Asynchronous_Task_Control
6196 -- No_Dependence => Ada.Calendar
6197 -- No_Dependence => Ada.Task_Attributes
6198 -- are already set by previous call to Set_Profile_Restrictions.
6200 -- Set the following restrictions which were added to Ada 2005:
6201 -- No_Dependence => Ada.Execution_Time.Group_Budget
6202 -- No_Dependence => Ada.Execution_Time.Timers
6204 if Ada_Version >= Ada_2005 then
6205 Name_Buffer (1 .. 3) := "ada";
6208 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6210 Name_Buffer (1 .. 14) := "execution_time";
6213 Selector_Entity := Make_Identifier (Loc, Name_Find);
6216 Make_Selected_Component
6218 Prefix => Prefix_Entity,
6219 Selector_Name => Selector_Entity);
6221 Name_Buffer (1 .. 13) := "group_budgets";
6224 Selector_Entity := Make_Identifier (Loc, Name_Find);
6227 Make_Selected_Component
6229 Prefix => Prefix_Node,
6230 Selector_Name => Selector_Entity);
6232 Set_Restriction_No_Dependence
6234 Warn => Treat_Restrictions_As_Warnings,
6235 Profile => Ravenscar);
6237 Name_Buffer (1 .. 6) := "timers";
6240 Selector_Entity := Make_Identifier (Loc, Name_Find);
6243 Make_Selected_Component
6245 Prefix => Prefix_Node,
6246 Selector_Name => Selector_Entity);
6248 Set_Restriction_No_Dependence
6250 Warn => Treat_Restrictions_As_Warnings,
6251 Profile => Ravenscar);
6254 -- Set the following restrictions which was added to Ada 2012 (see
6256 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6258 if Ada_Version >= Ada_2012 then
6259 Name_Buffer (1 .. 6) := "system";
6262 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6264 Name_Buffer (1 .. 15) := "multiprocessors";
6267 Selector_Entity := Make_Identifier (Loc, Name_Find);
6270 Make_Selected_Component
6272 Prefix => Prefix_Entity,
6273 Selector_Name => Selector_Entity);
6275 Name_Buffer (1 .. 19) := "dispatching_domains";
6278 Selector_Entity := Make_Identifier (Loc, Name_Find);
6281 Make_Selected_Component
6283 Prefix => Prefix_Node,
6284 Selector_Name => Selector_Entity);
6286 Set_Restriction_No_Dependence
6288 Warn => Treat_Restrictions_As_Warnings,
6289 Profile => Ravenscar);
6291 end Set_Ravenscar_Profile;
6293 -- Start of processing for Analyze_Pragma
6296 -- The following code is a defense against recursion. Not clear that
6297 -- this can happen legitimately, but perhaps some error situations
6298 -- can cause it, and we did see this recursion during testing.
6300 if Analyzed (N) then
6303 Set_Analyzed (N, True);
6306 -- Deal with unrecognized pragma
6308 Pname := Pragma_Name (N);
6310 if not Is_Pragma_Name (Pname) then
6311 if Warn_On_Unrecognized_Pragma then
6312 Error_Msg_Name_1 := Pname;
6313 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6315 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6316 if Is_Bad_Spelling_Of (Pname, PN) then
6317 Error_Msg_Name_1 := PN;
6318 Error_Msg_N -- CODEFIX
6319 ("\?possible misspelling of %!", Pragma_Identifier (N));
6328 -- Here to start processing for recognized pragma
6330 Prag_Id := Get_Pragma_Id (Pname);
6332 if Present (Corresponding_Aspect (N)) then
6333 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6344 if Present (Pragma_Argument_Associations (N)) then
6345 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6346 Arg1 := First (Pragma_Argument_Associations (N));
6348 if Present (Arg1) then
6349 Arg2 := Next (Arg1);
6351 if Present (Arg2) then
6352 Arg3 := Next (Arg2);
6354 if Present (Arg3) then
6355 Arg4 := Next (Arg3);
6361 -- An enumeration type defines the pragmas that are supported by the
6362 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6363 -- into the corresponding enumeration value for the following case.
6371 -- pragma Abort_Defer;
6373 when Pragma_Abort_Defer =>
6375 Check_Arg_Count (0);
6377 -- The only required semantic processing is to check the
6378 -- placement. This pragma must appear at the start of the
6379 -- statement sequence of a handled sequence of statements.
6381 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6382 or else N /= First (Statements (Parent (N)))
6393 -- Note: this pragma also has some specific processing in Par.Prag
6394 -- because we want to set the Ada version mode during parsing.
6396 when Pragma_Ada_83 =>
6398 Check_Arg_Count (0);
6400 -- We really should check unconditionally for proper configuration
6401 -- pragma placement, since we really don't want mixed Ada modes
6402 -- within a single unit, and the GNAT reference manual has always
6403 -- said this was a configuration pragma, but we did not check and
6404 -- are hesitant to add the check now.
6406 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6407 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6408 -- or Ada 2012 mode.
6410 if Ada_Version >= Ada_2005 then
6411 Check_Valid_Configuration_Pragma;
6414 -- Now set Ada 83 mode
6416 Ada_Version := Ada_83;
6417 Ada_Version_Explicit := Ada_Version;
6425 -- Note: this pragma also has some specific processing in Par.Prag
6426 -- because we want to set the Ada 83 version mode during parsing.
6428 when Pragma_Ada_95 =>
6430 Check_Arg_Count (0);
6432 -- We really should check unconditionally for proper configuration
6433 -- pragma placement, since we really don't want mixed Ada modes
6434 -- within a single unit, and the GNAT reference manual has always
6435 -- said this was a configuration pragma, but we did not check and
6436 -- are hesitant to add the check now.
6438 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6439 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6441 if Ada_Version >= Ada_2005 then
6442 Check_Valid_Configuration_Pragma;
6445 -- Now set Ada 95 mode
6447 Ada_Version := Ada_95;
6448 Ada_Version_Explicit := Ada_Version;
6450 ---------------------
6451 -- Ada_05/Ada_2005 --
6452 ---------------------
6455 -- pragma Ada_05 (LOCAL_NAME);
6458 -- pragma Ada_2005 (LOCAL_NAME):
6460 -- Note: these pragmas also have some specific processing in Par.Prag
6461 -- because we want to set the Ada 2005 version mode during parsing.
6463 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6469 if Arg_Count = 1 then
6470 Check_Arg_Is_Local_Name (Arg1);
6471 E_Id := Get_Pragma_Arg (Arg1);
6473 if Etype (E_Id) = Any_Type then
6477 Set_Is_Ada_2005_Only (Entity (E_Id));
6480 Check_Arg_Count (0);
6482 -- For Ada_2005 we unconditionally enforce the documented
6483 -- configuration pragma placement, since we do not want to
6484 -- tolerate mixed modes in a unit involving Ada 2005. That
6485 -- would cause real difficulties for those cases where there
6486 -- are incompatibilities between Ada 95 and Ada 2005.
6488 Check_Valid_Configuration_Pragma;
6490 -- Now set appropriate Ada mode
6492 Ada_Version := Ada_2005;
6493 Ada_Version_Explicit := Ada_2005;
6497 ---------------------
6498 -- Ada_12/Ada_2012 --
6499 ---------------------
6502 -- pragma Ada_12 (LOCAL_NAME);
6505 -- pragma Ada_2012 (LOCAL_NAME):
6507 -- Note: these pragmas also have some specific processing in Par.Prag
6508 -- because we want to set the Ada 2012 version mode during parsing.
6510 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6516 if Arg_Count = 1 then
6517 Check_Arg_Is_Local_Name (Arg1);
6518 E_Id := Get_Pragma_Arg (Arg1);
6520 if Etype (E_Id) = Any_Type then
6524 Set_Is_Ada_2012_Only (Entity (E_Id));
6527 Check_Arg_Count (0);
6529 -- For Ada_2012 we unconditionally enforce the documented
6530 -- configuration pragma placement, since we do not want to
6531 -- tolerate mixed modes in a unit involving Ada 2012. That
6532 -- would cause real difficulties for those cases where there
6533 -- are incompatibilities between Ada 95 and Ada 2012. We could
6534 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6536 Check_Valid_Configuration_Pragma;
6538 -- Now set appropriate Ada mode
6540 Ada_Version := Ada_2012;
6541 Ada_Version_Explicit := Ada_2012;
6545 ----------------------
6546 -- All_Calls_Remote --
6547 ----------------------
6549 -- pragma All_Calls_Remote [(library_package_NAME)];
6551 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6552 Lib_Entity : Entity_Id;
6555 Check_Ada_83_Warning;
6556 Check_Valid_Library_Unit_Pragma;
6558 if Nkind (N) = N_Null_Statement then
6562 Lib_Entity := Find_Lib_Unit_Name;
6564 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6566 if Present (Lib_Entity)
6567 and then not Debug_Flag_U
6569 if not Is_Remote_Call_Interface (Lib_Entity) then
6570 Error_Pragma ("pragma% only apply to rci unit");
6572 -- Set flag for entity of the library unit
6575 Set_Has_All_Calls_Remote (Lib_Entity);
6579 end All_Calls_Remote;
6585 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6586 -- ARG ::= NAME | EXPRESSION
6588 -- The first two arguments are by convention intended to refer to an
6589 -- external tool and a tool-specific function. These arguments are
6592 when Pragma_Annotate => Annotate : declare
6598 Check_At_Least_N_Arguments (1);
6599 Check_Arg_Is_Identifier (Arg1);
6600 Check_No_Identifiers;
6603 -- Second parameter is optional, it is never analyzed
6608 -- Here if we have a second parameter
6611 -- Second parameter must be identifier
6613 Check_Arg_Is_Identifier (Arg2);
6615 -- Process remaining parameters if any
6618 while Present (Arg) loop
6619 Exp := Get_Pragma_Arg (Arg);
6622 if Is_Entity_Name (Exp) then
6625 -- For string literals, we assume Standard_String as the
6626 -- type, unless the string contains wide or wide_wide
6629 elsif Nkind (Exp) = N_String_Literal then
6630 if Has_Wide_Wide_Character (Exp) then
6631 Resolve (Exp, Standard_Wide_Wide_String);
6632 elsif Has_Wide_Character (Exp) then
6633 Resolve (Exp, Standard_Wide_String);
6635 Resolve (Exp, Standard_String);
6638 elsif Is_Overloaded (Exp) then
6640 ("ambiguous argument for pragma%", Exp);
6655 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6656 -- [, [Message =>] Static_String_EXPRESSION]);
6658 when Pragma_Assert => Assert : declare
6664 Check_At_Least_N_Arguments (1);
6665 Check_At_Most_N_Arguments (2);
6666 Check_Arg_Order ((Name_Check, Name_Message));
6667 Check_Optional_Identifier (Arg1, Name_Check);
6669 -- We treat pragma Assert as equivalent to:
6671 -- pragma Check (Assertion, condition [, msg]);
6673 -- So rewrite pragma in this manner, and analyze the result
6675 Expr := Get_Pragma_Arg (Arg1);
6677 Make_Pragma_Argument_Association (Loc,
6678 Expression => Make_Identifier (Loc, Name_Assertion)),
6680 Make_Pragma_Argument_Association (Sloc (Expr),
6681 Expression => Expr));
6683 if Arg_Count > 1 then
6684 Check_Optional_Identifier (Arg2, Name_Message);
6685 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6686 Append_To (Newa, Relocate_Node (Arg2));
6691 Chars => Name_Check,
6692 Pragma_Argument_Associations => Newa));
6696 ----------------------
6697 -- Assertion_Policy --
6698 ----------------------
6700 -- pragma Assertion_Policy (Check | Disable |Ignore)
6702 when Pragma_Assertion_Policy => Assertion_Policy : declare
6707 Check_Valid_Configuration_Pragma;
6708 Check_Arg_Count (1);
6709 Check_No_Identifiers;
6710 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6712 -- We treat pragma Assertion_Policy as equivalent to:
6714 -- pragma Check_Policy (Assertion, policy)
6716 -- So rewrite the pragma in that manner and link on to the chain
6717 -- of Check_Policy pragmas, marking the pragma as analyzed.
6719 Policy := Get_Pragma_Arg (Arg1);
6723 Chars => Name_Check_Policy,
6725 Pragma_Argument_Associations => New_List (
6726 Make_Pragma_Argument_Association (Loc,
6727 Expression => Make_Identifier (Loc, Name_Assertion)),
6729 Make_Pragma_Argument_Association (Loc,
6731 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6734 Set_Next_Pragma (N, Opt.Check_Policy_List);
6735 Opt.Check_Policy_List := N;
6736 end Assertion_Policy;
6738 ------------------------------
6739 -- Assume_No_Invalid_Values --
6740 ------------------------------
6742 -- pragma Assume_No_Invalid_Values (On | Off);
6744 when Pragma_Assume_No_Invalid_Values =>
6746 Check_Valid_Configuration_Pragma;
6747 Check_Arg_Count (1);
6748 Check_No_Identifiers;
6749 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6751 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6752 Assume_No_Invalid_Values := True;
6754 Assume_No_Invalid_Values := False;
6761 -- pragma AST_Entry (entry_IDENTIFIER);
6763 when Pragma_AST_Entry => AST_Entry : declare
6769 Check_Arg_Count (1);
6770 Check_No_Identifiers;
6771 Check_Arg_Is_Local_Name (Arg1);
6772 Ent := Entity (Get_Pragma_Arg (Arg1));
6774 -- Note: the implementation of the AST_Entry pragma could handle
6775 -- the entry family case fine, but for now we are consistent with
6776 -- the DEC rules, and do not allow the pragma, which of course
6777 -- has the effect of also forbidding the attribute.
6779 if Ekind (Ent) /= E_Entry then
6781 ("pragma% argument must be simple entry name", Arg1);
6783 elsif Is_AST_Entry (Ent) then
6785 ("duplicate % pragma for entry", Arg1);
6787 elsif Has_Homonym (Ent) then
6789 ("pragma% argument cannot specify overloaded entry", Arg1);
6793 FF : constant Entity_Id := First_Formal (Ent);
6796 if Present (FF) then
6797 if Present (Next_Formal (FF)) then
6799 ("entry for pragma% can have only one argument",
6802 elsif Parameter_Mode (FF) /= E_In_Parameter then
6804 ("entry parameter for pragma% must have mode IN",
6810 Set_Is_AST_Entry (Ent);
6818 -- pragma Asynchronous (LOCAL_NAME);
6820 when Pragma_Asynchronous => Asynchronous : declare
6828 procedure Process_Async_Pragma;
6829 -- Common processing for procedure and access-to-procedure case
6831 --------------------------
6832 -- Process_Async_Pragma --
6833 --------------------------
6835 procedure Process_Async_Pragma is
6838 Set_Is_Asynchronous (Nm);
6842 -- The formals should be of mode IN (RM E.4.1(6))
6845 while Present (S) loop
6846 Formal := Defining_Identifier (S);
6848 if Nkind (Formal) = N_Defining_Identifier
6849 and then Ekind (Formal) /= E_In_Parameter
6852 ("pragma% procedure can only have IN parameter",
6859 Set_Is_Asynchronous (Nm);
6860 end Process_Async_Pragma;
6862 -- Start of processing for pragma Asynchronous
6865 Check_Ada_83_Warning;
6866 Check_No_Identifiers;
6867 Check_Arg_Count (1);
6868 Check_Arg_Is_Local_Name (Arg1);
6870 if Debug_Flag_U then
6874 C_Ent := Cunit_Entity (Current_Sem_Unit);
6875 Analyze (Get_Pragma_Arg (Arg1));
6876 Nm := Entity (Get_Pragma_Arg (Arg1));
6878 if not Is_Remote_Call_Interface (C_Ent)
6879 and then not Is_Remote_Types (C_Ent)
6881 -- This pragma should only appear in an RCI or Remote Types
6882 -- unit (RM E.4.1(4)).
6885 ("pragma% not in Remote_Call_Interface or " &
6886 "Remote_Types unit");
6889 if Ekind (Nm) = E_Procedure
6890 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6892 if not Is_Remote_Call_Interface (Nm) then
6894 ("pragma% cannot be applied on non-remote procedure",
6898 L := Parameter_Specifications (Parent (Nm));
6899 Process_Async_Pragma;
6902 elsif Ekind (Nm) = E_Function then
6904 ("pragma% cannot be applied to function", Arg1);
6906 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6907 if Is_Record_Type (Nm) then
6909 -- A record type that is the Equivalent_Type for a remote
6910 -- access-to-subprogram type.
6912 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6915 -- A non-expanded RAS type (distribution is not enabled)
6917 N := Declaration_Node (Nm);
6920 if Nkind (N) = N_Full_Type_Declaration
6921 and then Nkind (Type_Definition (N)) =
6922 N_Access_Procedure_Definition
6924 L := Parameter_Specifications (Type_Definition (N));
6925 Process_Async_Pragma;
6927 if Is_Asynchronous (Nm)
6928 and then Expander_Active
6929 and then Get_PCS_Name /= Name_No_DSA
6931 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6936 ("pragma% cannot reference access-to-function type",
6940 -- Only other possibility is Access-to-class-wide type
6942 elsif Is_Access_Type (Nm)
6943 and then Is_Class_Wide_Type (Designated_Type (Nm))
6945 Check_First_Subtype (Arg1);
6946 Set_Is_Asynchronous (Nm);
6947 if Expander_Active then
6948 RACW_Type_Is_Asynchronous (Nm);
6952 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6960 -- pragma Atomic (LOCAL_NAME);
6962 when Pragma_Atomic =>
6963 Process_Atomic_Shared_Volatile;
6965 -----------------------
6966 -- Atomic_Components --
6967 -----------------------
6969 -- pragma Atomic_Components (array_LOCAL_NAME);
6971 -- This processing is shared by Volatile_Components
6973 when Pragma_Atomic_Components |
6974 Pragma_Volatile_Components =>
6976 Atomic_Components : declare
6983 Check_Ada_83_Warning;
6984 Check_No_Identifiers;
6985 Check_Arg_Count (1);
6986 Check_Arg_Is_Local_Name (Arg1);
6987 E_Id := Get_Pragma_Arg (Arg1);
6989 if Etype (E_Id) = Any_Type then
6995 Check_Duplicate_Pragma (E);
6997 if Rep_Item_Too_Early (E, N)
6999 Rep_Item_Too_Late (E, N)
7004 D := Declaration_Node (E);
7007 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7009 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7010 and then Nkind (D) = N_Object_Declaration
7011 and then Nkind (Object_Definition (D)) =
7012 N_Constrained_Array_Definition)
7014 -- The flag is set on the object, or on the base type
7016 if Nkind (D) /= N_Object_Declaration then
7020 Set_Has_Volatile_Components (E);
7022 if Prag_Id = Pragma_Atomic_Components then
7023 Set_Has_Atomic_Components (E);
7027 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7029 end Atomic_Components;
7030 --------------------
7031 -- Attach_Handler --
7032 --------------------
7034 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7036 when Pragma_Attach_Handler =>
7037 Check_Ada_83_Warning;
7038 Check_No_Identifiers;
7039 Check_Arg_Count (2);
7041 if No_Run_Time_Mode then
7042 Error_Msg_CRT ("Attach_Handler pragma", N);
7044 Check_Interrupt_Or_Attach_Handler;
7046 -- The expression that designates the attribute may depend on a
7047 -- discriminant, and is therefore a per- object expression, to
7048 -- be expanded in the init proc. If expansion is enabled, then
7049 -- perform semantic checks on a copy only.
7051 if Expander_Active then
7053 Temp : constant Node_Id :=
7054 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7056 Set_Parent (Temp, N);
7057 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7061 Analyze (Get_Pragma_Arg (Arg2));
7062 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7065 Process_Interrupt_Or_Attach_Handler;
7068 --------------------
7069 -- C_Pass_By_Copy --
7070 --------------------
7072 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7074 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7080 Check_Valid_Configuration_Pragma;
7081 Check_Arg_Count (1);
7082 Check_Optional_Identifier (Arg1, "max_size");
7084 Arg := Get_Pragma_Arg (Arg1);
7085 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7087 Val := Expr_Value (Arg);
7091 ("maximum size for pragma% must be positive", Arg1);
7093 elsif UI_Is_In_Int_Range (Val) then
7094 Default_C_Record_Mechanism := UI_To_Int (Val);
7096 -- If a giant value is given, Int'Last will do well enough.
7097 -- If sometime someone complains that a record larger than
7098 -- two gigabytes is not copied, we will worry about it then!
7101 Default_C_Record_Mechanism := Mechanism_Type'Last;
7109 -- pragma Check ([Name =>] IDENTIFIER,
7110 -- [Check =>] Boolean_EXPRESSION
7111 -- [,[Message =>] String_EXPRESSION]);
7113 when Pragma_Check => Check : declare
7118 -- Set True if category of assertions referenced by Name enabled
7122 Check_At_Least_N_Arguments (2);
7123 Check_At_Most_N_Arguments (3);
7124 Check_Optional_Identifier (Arg1, Name_Name);
7125 Check_Optional_Identifier (Arg2, Name_Check);
7127 if Arg_Count = 3 then
7128 Check_Optional_Identifier (Arg3, Name_Message);
7129 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7132 Check_Arg_Is_Identifier (Arg1);
7134 -- Completely ignore if disabled
7136 if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7137 Rewrite (N, Make_Null_Statement (Loc));
7142 -- Indicate if pragma is enabled. The Original_Node reference here
7143 -- is to deal with pragma Assert rewritten as a Check pragma.
7145 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
7148 Set_SCO_Pragma_Enabled (Loc);
7151 -- If expansion is active and the check is not enabled then we
7152 -- rewrite the Check as:
7154 -- if False and then condition then
7158 -- The reason we do this rewriting during semantic analysis rather
7159 -- than as part of normal expansion is that we cannot analyze and
7160 -- expand the code for the boolean expression directly, or it may
7161 -- cause insertion of actions that would escape the attempt to
7162 -- suppress the check code.
7164 -- Note that the Sloc for the if statement corresponds to the
7165 -- argument condition, not the pragma itself. The reason for this
7166 -- is that we may generate a warning if the condition is False at
7167 -- compile time, and we do not want to delete this warning when we
7168 -- delete the if statement.
7170 Expr := Get_Pragma_Arg (Arg2);
7172 if Expander_Active and then not Check_On then
7173 Eloc := Sloc (Expr);
7176 Make_If_Statement (Eloc,
7178 Make_And_Then (Eloc,
7179 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7180 Right_Opnd => Expr),
7181 Then_Statements => New_List (
7182 Make_Null_Statement (Eloc))));
7189 Analyze_And_Resolve (Expr, Any_Boolean);
7197 -- pragma Check_Name (check_IDENTIFIER);
7199 when Pragma_Check_Name =>
7200 Check_No_Identifiers;
7202 Check_Valid_Configuration_Pragma;
7203 Check_Arg_Count (1);
7204 Check_Arg_Is_Identifier (Arg1);
7207 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7210 for J in Check_Names.First .. Check_Names.Last loop
7211 if Check_Names.Table (J) = Nam then
7216 Check_Names.Append (Nam);
7223 -- pragma Check_Policy (
7224 -- [Name =>] IDENTIFIER,
7225 -- [Policy =>] POLICY_IDENTIFIER);
7227 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7229 -- Note: this is a configuration pragma, but it is allowed to appear
7232 when Pragma_Check_Policy =>
7234 Check_Arg_Count (2);
7235 Check_Optional_Identifier (Arg1, Name_Name);
7236 Check_Optional_Identifier (Arg2, Name_Policy);
7238 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7240 -- A Check_Policy pragma can appear either as a configuration
7241 -- pragma, or in a declarative part or a package spec (see RM
7242 -- 11.5(5) for rules for Suppress/Unsuppress which are also
7243 -- followed for Check_Policy).
7245 if not Is_Configuration_Pragma then
7246 Check_Is_In_Decl_Part_Or_Package_Spec;
7249 Set_Next_Pragma (N, Opt.Check_Policy_List);
7250 Opt.Check_Policy_List := N;
7252 ---------------------
7253 -- CIL_Constructor --
7254 ---------------------
7256 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7258 -- Processing for this pragma is shared with Java_Constructor
7264 -- pragma Comment (static_string_EXPRESSION)
7266 -- Processing for pragma Comment shares the circuitry for pragma
7267 -- Ident. The only differences are that Ident enforces a limit of 31
7268 -- characters on its argument, and also enforces limitations on
7269 -- placement for DEC compatibility. Pragma Comment shares neither of
7270 -- these restrictions.
7276 -- pragma Common_Object (
7277 -- [Internal =>] LOCAL_NAME
7278 -- [, [External =>] EXTERNAL_SYMBOL]
7279 -- [, [Size =>] EXTERNAL_SYMBOL]);
7281 -- Processing for this pragma is shared with Psect_Object
7283 ------------------------
7284 -- Compile_Time_Error --
7285 ------------------------
7287 -- pragma Compile_Time_Error
7288 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7290 when Pragma_Compile_Time_Error =>
7292 Process_Compile_Time_Warning_Or_Error;
7294 --------------------------
7295 -- Compile_Time_Warning --
7296 --------------------------
7298 -- pragma Compile_Time_Warning
7299 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7301 when Pragma_Compile_Time_Warning =>
7303 Process_Compile_Time_Warning_Or_Error;
7309 when Pragma_Compiler_Unit =>
7311 Check_Arg_Count (0);
7312 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7314 -----------------------------
7315 -- Complete_Representation --
7316 -----------------------------
7318 -- pragma Complete_Representation;
7320 when Pragma_Complete_Representation =>
7322 Check_Arg_Count (0);
7324 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7326 ("pragma & must appear within record representation clause");
7329 ----------------------------
7330 -- Complex_Representation --
7331 ----------------------------
7333 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7335 when Pragma_Complex_Representation => Complex_Representation : declare
7342 Check_Arg_Count (1);
7343 Check_Optional_Identifier (Arg1, Name_Entity);
7344 Check_Arg_Is_Local_Name (Arg1);
7345 E_Id := Get_Pragma_Arg (Arg1);
7347 if Etype (E_Id) = Any_Type then
7353 if not Is_Record_Type (E) then
7355 ("argument for pragma% must be record type", Arg1);
7358 Ent := First_Entity (E);
7361 or else No (Next_Entity (Ent))
7362 or else Present (Next_Entity (Next_Entity (Ent)))
7363 or else not Is_Floating_Point_Type (Etype (Ent))
7364 or else Etype (Ent) /= Etype (Next_Entity (Ent))
7367 ("record for pragma% must have two fields of the same "
7368 & "floating-point type", Arg1);
7371 Set_Has_Complex_Representation (Base_Type (E));
7373 -- We need to treat the type has having a non-standard
7374 -- representation, for back-end purposes, even though in
7375 -- general a complex will have the default representation
7376 -- of a record with two real components.
7378 Set_Has_Non_Standard_Rep (Base_Type (E));
7380 end Complex_Representation;
7382 -------------------------
7383 -- Component_Alignment --
7384 -------------------------
7386 -- pragma Component_Alignment (
7387 -- [Form =>] ALIGNMENT_CHOICE
7388 -- [, [Name =>] type_LOCAL_NAME]);
7390 -- ALIGNMENT_CHOICE ::=
7392 -- | Component_Size_4
7396 when Pragma_Component_Alignment => Component_AlignmentP : declare
7397 Args : Args_List (1 .. 2);
7398 Names : constant Name_List (1 .. 2) := (
7402 Form : Node_Id renames Args (1);
7403 Name : Node_Id renames Args (2);
7405 Atype : Component_Alignment_Kind;
7410 Gather_Associations (Names, Args);
7413 Error_Pragma ("missing Form argument for pragma%");
7416 Check_Arg_Is_Identifier (Form);
7418 -- Get proper alignment, note that Default = Component_Size on all
7419 -- machines we have so far, and we want to set this value rather
7420 -- than the default value to indicate that it has been explicitly
7421 -- set (and thus will not get overridden by the default component
7422 -- alignment for the current scope)
7424 if Chars (Form) = Name_Component_Size then
7425 Atype := Calign_Component_Size;
7427 elsif Chars (Form) = Name_Component_Size_4 then
7428 Atype := Calign_Component_Size_4;
7430 elsif Chars (Form) = Name_Default then
7431 Atype := Calign_Component_Size;
7433 elsif Chars (Form) = Name_Storage_Unit then
7434 Atype := Calign_Storage_Unit;
7438 ("invalid Form parameter for pragma%", Form);
7441 -- Case with no name, supplied, affects scope table entry
7445 (Scope_Stack.Last).Component_Alignment_Default := Atype;
7447 -- Case of name supplied
7450 Check_Arg_Is_Local_Name (Name);
7452 Typ := Entity (Name);
7455 or else Rep_Item_Too_Early (Typ, N)
7459 Typ := Underlying_Type (Typ);
7462 if not Is_Record_Type (Typ)
7463 and then not Is_Array_Type (Typ)
7466 ("Name parameter of pragma% must identify record or " &
7467 "array type", Name);
7470 -- An explicit Component_Alignment pragma overrides an
7471 -- implicit pragma Pack, but not an explicit one.
7473 if not Has_Pragma_Pack (Base_Type (Typ)) then
7474 Set_Is_Packed (Base_Type (Typ), False);
7475 Set_Component_Alignment (Base_Type (Typ), Atype);
7478 end Component_AlignmentP;
7484 -- pragma Controlled (first_subtype_LOCAL_NAME);
7486 when Pragma_Controlled => Controlled : declare
7490 Check_No_Identifiers;
7491 Check_Arg_Count (1);
7492 Check_Arg_Is_Local_Name (Arg1);
7493 Arg := Get_Pragma_Arg (Arg1);
7495 if not Is_Entity_Name (Arg)
7496 or else not Is_Access_Type (Entity (Arg))
7498 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7500 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7508 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
7509 -- [Entity =>] LOCAL_NAME);
7511 when Pragma_Convention => Convention : declare
7514 pragma Warnings (Off, C);
7515 pragma Warnings (Off, E);
7517 Check_Arg_Order ((Name_Convention, Name_Entity));
7518 Check_Ada_83_Warning;
7519 Check_Arg_Count (2);
7520 Process_Convention (C, E);
7523 ---------------------------
7524 -- Convention_Identifier --
7525 ---------------------------
7527 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7528 -- [Convention =>] convention_IDENTIFIER);
7530 when Pragma_Convention_Identifier => Convention_Identifier : declare
7536 Check_Arg_Order ((Name_Name, Name_Convention));
7537 Check_Arg_Count (2);
7538 Check_Optional_Identifier (Arg1, Name_Name);
7539 Check_Optional_Identifier (Arg2, Name_Convention);
7540 Check_Arg_Is_Identifier (Arg1);
7541 Check_Arg_Is_Identifier (Arg2);
7542 Idnam := Chars (Get_Pragma_Arg (Arg1));
7543 Cname := Chars (Get_Pragma_Arg (Arg2));
7545 if Is_Convention_Name (Cname) then
7546 Record_Convention_Identifier
7547 (Idnam, Get_Convention_Id (Cname));
7550 ("second arg for % pragma must be convention", Arg2);
7552 end Convention_Identifier;
7558 -- pragma CPP_Class ([Entity =>] local_NAME)
7560 when Pragma_CPP_Class => CPP_Class : declare
7565 if Warn_On_Obsolescent_Feature then
7567 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7568 " by pragma import?", N);
7572 Check_Arg_Count (1);
7573 Check_Optional_Identifier (Arg1, Name_Entity);
7574 Check_Arg_Is_Local_Name (Arg1);
7576 Arg := Get_Pragma_Arg (Arg1);
7579 if Etype (Arg) = Any_Type then
7583 if not Is_Entity_Name (Arg)
7584 or else not Is_Type (Entity (Arg))
7586 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7589 Typ := Entity (Arg);
7591 if not Is_Tagged_Type (Typ) then
7592 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7595 -- Types treated as CPP classes must be declared limited (note:
7596 -- this used to be a warning but there is no real benefit to it
7597 -- since we did effectively intend to treat the type as limited
7600 if not Is_Limited_Type (Typ) then
7602 ("imported 'C'P'P type must be limited",
7603 Get_Pragma_Arg (Arg1));
7606 Set_Is_CPP_Class (Typ);
7607 Set_Convention (Typ, Convention_CPP);
7609 -- Imported CPP types must not have discriminants (because C++
7610 -- classes do not have discriminants).
7612 if Has_Discriminants (Typ) then
7614 ("imported 'C'P'P type cannot have discriminants",
7615 First (Discriminant_Specifications
7616 (Declaration_Node (Typ))));
7619 -- Components of imported CPP types must not have default
7620 -- expressions because the constructor (if any) is in the
7623 if Is_Incomplete_Or_Private_Type (Typ)
7624 and then No (Underlying_Type (Typ))
7626 -- It should be an error to apply pragma CPP to a private
7627 -- type if the underlying type is not visible (as it is
7628 -- for any representation item). For now, for backward
7629 -- compatibility we do nothing but we cannot check components
7630 -- because they are not available at this stage. All this code
7631 -- will be removed when we cleanup this obsolete GNAT pragma???
7637 Tdef : constant Node_Id :=
7638 Type_Definition (Declaration_Node (Typ));
7643 if Nkind (Tdef) = N_Record_Definition then
7644 Clist := Component_List (Tdef);
7646 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7647 Clist := Component_List (Record_Extension_Part (Tdef));
7650 if Present (Clist) then
7651 Comp := First (Component_Items (Clist));
7652 while Present (Comp) loop
7653 if Present (Expression (Comp)) then
7655 ("component of imported 'C'P'P type cannot have" &
7656 " default expression", Expression (Comp));
7666 ---------------------
7667 -- CPP_Constructor --
7668 ---------------------
7670 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7671 -- [, [External_Name =>] static_string_EXPRESSION ]
7672 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7674 when Pragma_CPP_Constructor => CPP_Constructor : declare
7678 Tag_Typ : Entity_Id;
7682 Check_At_Least_N_Arguments (1);
7683 Check_At_Most_N_Arguments (3);
7684 Check_Optional_Identifier (Arg1, Name_Entity);
7685 Check_Arg_Is_Local_Name (Arg1);
7687 Id := Get_Pragma_Arg (Arg1);
7688 Find_Program_Unit_Name (Id);
7690 -- If we did not find the name, we are done
7692 if Etype (Id) = Any_Type then
7696 Def_Id := Entity (Id);
7698 -- Check if already defined as constructor
7700 if Is_Constructor (Def_Id) then
7702 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7706 if Ekind (Def_Id) = E_Function
7707 and then (Is_CPP_Class (Etype (Def_Id))
7708 or else (Is_Class_Wide_Type (Etype (Def_Id))
7710 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7712 if Arg_Count >= 2 then
7713 Set_Imported (Def_Id);
7714 Set_Is_Public (Def_Id);
7715 Process_Interface_Name (Def_Id, Arg2, Arg3);
7718 Set_Has_Completion (Def_Id);
7719 Set_Is_Constructor (Def_Id);
7721 -- Imported C++ constructors are not dispatching primitives
7722 -- because in C++ they don't have a dispatch table slot.
7723 -- However, in Ada the constructor has the profile of a
7724 -- function that returns a tagged type and therefore it has
7725 -- been treated as a primitive operation during semantic
7726 -- analysis. We now remove it from the list of primitive
7727 -- operations of the type.
7729 if Is_Tagged_Type (Etype (Def_Id))
7730 and then not Is_Class_Wide_Type (Etype (Def_Id))
7732 pragma Assert (Is_Dispatching_Operation (Def_Id));
7733 Tag_Typ := Etype (Def_Id);
7735 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7736 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7740 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7741 Set_Is_Dispatching_Operation (Def_Id, False);
7744 -- For backward compatibility, if the constructor returns a
7745 -- class wide type, and we internally change the return type to
7746 -- the corresponding root type.
7748 if Is_Class_Wide_Type (Etype (Def_Id)) then
7749 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7753 ("pragma% requires function returning a 'C'P'P_Class type",
7756 end CPP_Constructor;
7762 when Pragma_CPP_Virtual => CPP_Virtual : declare
7766 if Warn_On_Obsolescent_Feature then
7768 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7777 when Pragma_CPP_Vtable => CPP_Vtable : declare
7781 if Warn_On_Obsolescent_Feature then
7783 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7792 -- pragma CPU (EXPRESSION);
7794 when Pragma_CPU => CPU : declare
7795 P : constant Node_Id := Parent (N);
7800 Check_No_Identifiers;
7801 Check_Arg_Count (1);
7805 if Nkind (P) = N_Subprogram_Body then
7806 Check_In_Main_Program;
7808 Arg := Get_Pragma_Arg (Arg1);
7809 Analyze_And_Resolve (Arg, Any_Integer);
7813 if not Is_Static_Expression (Arg) then
7814 Flag_Non_Static_Expr
7815 ("main subprogram affinity is not static!", Arg);
7818 -- If constraint error, then we already signalled an error
7820 elsif Raises_Constraint_Error (Arg) then
7823 -- Otherwise check in range
7827 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7828 -- This is the entity System.Multiprocessors.CPU_Range;
7830 Val : constant Uint := Expr_Value (Arg);
7833 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7835 Val > Expr_Value (Type_High_Bound (CPU_Id))
7838 ("main subprogram CPU is out of range", Arg1);
7844 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7848 elsif Nkind (P) = N_Task_Definition then
7849 Arg := Get_Pragma_Arg (Arg1);
7851 -- The expression must be analyzed in the special manner
7852 -- described in "Handling of Default and Per-Object
7853 -- Expressions" in sem.ads.
7855 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7857 -- Anything else is incorrect
7863 if Has_Pragma_CPU (P) then
7864 Error_Pragma ("duplicate pragma% not allowed");
7866 Set_Has_Pragma_CPU (P, True);
7868 if Nkind (P) = N_Task_Definition then
7869 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7878 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7880 when Pragma_Debug => Debug : declare
7887 -- Skip analysis if disabled
7889 if Debug_Pragmas_Disabled then
7890 Rewrite (N, Make_Null_Statement (Loc));
7897 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7900 if Debug_Pragmas_Enabled then
7901 Set_SCO_Pragma_Enabled (Loc);
7904 if Arg_Count = 2 then
7907 Left_Opnd => Relocate_Node (Cond),
7908 Right_Opnd => Get_Pragma_Arg (Arg1));
7909 Call := Get_Pragma_Arg (Arg2);
7911 Call := Get_Pragma_Arg (Arg1);
7915 N_Indexed_Component,
7919 N_Selected_Component)
7921 -- If this pragma Debug comes from source, its argument was
7922 -- parsed as a name form (which is syntactically identical).
7923 -- In a generic context a parameterless call will be left as
7924 -- an expanded name (if global) or selected_component if local.
7925 -- Change it to a procedure call statement now.
7927 Change_Name_To_Procedure_Call_Statement (Call);
7929 elsif Nkind (Call) = N_Procedure_Call_Statement then
7931 -- Already in the form of a procedure call statement: nothing
7932 -- to do (could happen in case of an internally generated
7938 -- All other cases: diagnose error
7941 ("argument of pragma ""Debug"" is not procedure call",
7946 -- Rewrite into a conditional with an appropriate condition. We
7947 -- wrap the procedure call in a block so that overhead from e.g.
7948 -- use of the secondary stack does not generate execution overhead
7949 -- for suppressed conditions.
7951 Rewrite (N, Make_Implicit_If_Statement (N,
7953 Then_Statements => New_List (
7954 Make_Block_Statement (Loc,
7955 Handled_Statement_Sequence =>
7956 Make_Handled_Sequence_Of_Statements (Loc,
7957 Statements => New_List (Relocate_Node (Call)))))));
7965 -- pragma Debug_Policy (Check | Ignore)
7967 when Pragma_Debug_Policy =>
7969 Check_Arg_Count (1);
7970 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7971 Debug_Pragmas_Enabled :=
7972 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7973 Debug_Pragmas_Disabled :=
7974 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
7976 ---------------------
7977 -- Detect_Blocking --
7978 ---------------------
7980 -- pragma Detect_Blocking;
7982 when Pragma_Detect_Blocking =>
7984 Check_Arg_Count (0);
7985 Check_Valid_Configuration_Pragma;
7986 Detect_Blocking := True;
7988 --------------------------
7989 -- Default_Storage_Pool --
7990 --------------------------
7992 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7994 when Pragma_Default_Storage_Pool =>
7996 Check_Arg_Count (1);
7998 -- Default_Storage_Pool can appear as a configuration pragma, or
7999 -- in a declarative part or a package spec.
8001 if not Is_Configuration_Pragma then
8002 Check_Is_In_Decl_Part_Or_Package_Spec;
8005 -- Case of Default_Storage_Pool (null);
8007 if Nkind (Expression (Arg1)) = N_Null then
8008 Analyze (Expression (Arg1));
8010 -- This is an odd case, this is not really an expression, so
8011 -- we don't have a type for it. So just set the type to Empty.
8013 Set_Etype (Expression (Arg1), Empty);
8015 -- Case of Default_Storage_Pool (storage_pool_NAME);
8018 -- If it's a configuration pragma, then the only allowed
8019 -- argument is "null".
8021 if Is_Configuration_Pragma then
8022 Error_Pragma_Arg ("NULL expected", Arg1);
8025 -- The expected type for a non-"null" argument is
8026 -- Root_Storage_Pool'Class.
8029 (Get_Pragma_Arg (Arg1),
8030 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8033 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
8034 -- for an access type will use this information to set the
8035 -- appropriate attributes of the access type.
8037 Default_Pool := Expression (Arg1);
8043 when Pragma_Dimension =>
8045 Check_Arg_Count (4);
8046 Check_No_Identifiers;
8047 Check_Arg_Is_Local_Name (Arg1);
8049 if not Is_Type (Arg1) then
8050 Error_Pragma ("first argument for pragma% must be subtype");
8053 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
8054 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
8055 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
8057 ------------------------------------
8058 -- Disable_Atomic_Synchronization --
8059 ------------------------------------
8061 -- pragma Disable_Atomic_Synchronization [(Entity)];
8063 when Pragma_Disable_Atomic_Synchronization =>
8064 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8070 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
8072 when Pragma_Discard_Names => Discard_Names : declare
8077 Check_Ada_83_Warning;
8079 -- Deal with configuration pragma case
8081 if Arg_Count = 0 and then Is_Configuration_Pragma then
8082 Global_Discard_Names := True;
8085 -- Otherwise, check correct appropriate context
8088 Check_Is_In_Decl_Part_Or_Package_Spec;
8090 if Arg_Count = 0 then
8092 -- If there is no parameter, then from now on this pragma
8093 -- applies to any enumeration, exception or tagged type
8094 -- defined in the current declarative part, and recursively
8095 -- to any nested scope.
8097 Set_Discard_Names (Current_Scope);
8101 Check_Arg_Count (1);
8102 Check_Optional_Identifier (Arg1, Name_On);
8103 Check_Arg_Is_Local_Name (Arg1);
8105 E_Id := Get_Pragma_Arg (Arg1);
8107 if Etype (E_Id) = Any_Type then
8113 if (Is_First_Subtype (E)
8115 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8116 or else Ekind (E) = E_Exception
8118 Set_Discard_Names (E);
8121 ("inappropriate entity for pragma%", Arg1);
8128 ------------------------
8129 -- Dispatching_Domain --
8130 ------------------------
8132 -- pragma Dispatching_Domain (EXPRESSION);
8134 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8135 P : constant Node_Id := Parent (N);
8140 Check_No_Identifiers;
8141 Check_Arg_Count (1);
8143 -- This pragma is born obsolete, but not the aspect
8145 if not From_Aspect_Specification (N) then
8147 (No_Obsolescent_Features, Pragma_Identifier (N));
8150 if Nkind (P) = N_Task_Definition then
8151 Arg := Get_Pragma_Arg (Arg1);
8153 -- The expression must be analyzed in the special manner
8154 -- described in "Handling of Default and Per-Object
8155 -- Expressions" in sem.ads.
8157 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8159 -- Anything else is incorrect
8165 if Has_Pragma_Dispatching_Domain (P) then
8166 Error_Pragma ("duplicate pragma% not allowed");
8168 Set_Has_Pragma_Dispatching_Domain (P, True);
8170 if Nkind (P) = N_Task_Definition then
8171 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8174 end Dispatching_Domain;
8180 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8182 when Pragma_Elaborate => Elaborate : declare
8187 -- Pragma must be in context items list of a compilation unit
8189 if not Is_In_Context_Clause then
8193 -- Must be at least one argument
8195 if Arg_Count = 0 then
8196 Error_Pragma ("pragma% requires at least one argument");
8199 -- In Ada 83 mode, there can be no items following it in the
8200 -- context list except other pragmas and implicit with clauses
8201 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8202 -- placement rule does not apply.
8204 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8206 while Present (Citem) loop
8207 if Nkind (Citem) = N_Pragma
8208 or else (Nkind (Citem) = N_With_Clause
8209 and then Implicit_With (Citem))
8214 ("(Ada 83) pragma% must be at end of context clause");
8221 -- Finally, the arguments must all be units mentioned in a with
8222 -- clause in the same context clause. Note we already checked (in
8223 -- Par.Prag) that the arguments are all identifiers or selected
8227 Outer : while Present (Arg) loop
8228 Citem := First (List_Containing (N));
8229 Inner : while Citem /= N loop
8230 if Nkind (Citem) = N_With_Clause
8231 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8233 Set_Elaborate_Present (Citem, True);
8234 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8235 Generate_Reference (Entity (Name (Citem)), Citem);
8237 -- With the pragma present, elaboration calls on
8238 -- subprograms from the named unit need no further
8239 -- checks, as long as the pragma appears in the current
8240 -- compilation unit. If the pragma appears in some unit
8241 -- in the context, there might still be a need for an
8242 -- Elaborate_All_Desirable from the current compilation
8243 -- to the named unit, so we keep the check enabled.
8245 if In_Extended_Main_Source_Unit (N) then
8246 Set_Suppress_Elaboration_Warnings
8247 (Entity (Name (Citem)));
8258 ("argument of pragma% is not with'ed unit", Arg);
8264 -- Give a warning if operating in static mode with -gnatwl
8265 -- (elaboration warnings enabled) switch set.
8267 if Elab_Warnings and not Dynamic_Elaboration_Checks then
8269 ("?use of pragma Elaborate may not be safe", N);
8271 ("?use pragma Elaborate_All instead if possible", N);
8279 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8281 when Pragma_Elaborate_All => Elaborate_All : declare
8286 Check_Ada_83_Warning;
8288 -- Pragma must be in context items list of a compilation unit
8290 if not Is_In_Context_Clause then
8294 -- Must be at least one argument
8296 if Arg_Count = 0 then
8297 Error_Pragma ("pragma% requires at least one argument");
8300 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
8301 -- have to appear at the end of the context clause, but may
8302 -- appear mixed in with other items, even in Ada 83 mode.
8304 -- Final check: the arguments must all be units mentioned in
8305 -- a with clause in the same context clause. Note that we
8306 -- already checked (in Par.Prag) that all the arguments are
8307 -- either identifiers or selected components.
8310 Outr : while Present (Arg) loop
8311 Citem := First (List_Containing (N));
8312 Innr : while Citem /= N loop
8313 if Nkind (Citem) = N_With_Clause
8314 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8316 Set_Elaborate_All_Present (Citem, True);
8317 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8319 -- Suppress warnings and elaboration checks on the named
8320 -- unit if the pragma is in the current compilation, as
8321 -- for pragma Elaborate.
8323 if In_Extended_Main_Source_Unit (N) then
8324 Set_Suppress_Elaboration_Warnings
8325 (Entity (Name (Citem)));
8334 Set_Error_Posted (N);
8336 ("argument of pragma% is not with'ed unit", Arg);
8343 --------------------
8344 -- Elaborate_Body --
8345 --------------------
8347 -- pragma Elaborate_Body [( library_unit_NAME )];
8349 when Pragma_Elaborate_Body => Elaborate_Body : declare
8350 Cunit_Node : Node_Id;
8351 Cunit_Ent : Entity_Id;
8354 Check_Ada_83_Warning;
8355 Check_Valid_Library_Unit_Pragma;
8357 if Nkind (N) = N_Null_Statement then
8361 Cunit_Node := Cunit (Current_Sem_Unit);
8362 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8364 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8367 Error_Pragma ("pragma% must refer to a spec, not a body");
8369 Set_Body_Required (Cunit_Node, True);
8370 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8372 -- If we are in dynamic elaboration mode, then we suppress
8373 -- elaboration warnings for the unit, since it is definitely
8374 -- fine NOT to do dynamic checks at the first level (and such
8375 -- checks will be suppressed because no elaboration boolean
8376 -- is created for Elaborate_Body packages).
8378 -- But in the static model of elaboration, Elaborate_Body is
8379 -- definitely NOT good enough to ensure elaboration safety on
8380 -- its own, since the body may WITH other units that are not
8381 -- safe from an elaboration point of view, so a client must
8382 -- still do an Elaborate_All on such units.
8384 -- Debug flag -gnatdD restores the old behavior of 3.13, where
8385 -- Elaborate_Body always suppressed elab warnings.
8387 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8388 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8393 ------------------------
8394 -- Elaboration_Checks --
8395 ------------------------
8397 -- pragma Elaboration_Checks (Static | Dynamic);
8399 when Pragma_Elaboration_Checks =>
8401 Check_Arg_Count (1);
8402 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8403 Dynamic_Elaboration_Checks :=
8404 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8410 -- pragma Eliminate (
8411 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
8412 -- [,[Entity =>] IDENTIFIER |
8413 -- SELECTED_COMPONENT |
8415 -- [, OVERLOADING_RESOLUTION]);
8417 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8420 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8423 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8425 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8426 -- Result_Type => result_SUBTYPE_NAME]
8428 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8429 -- SUBTYPE_NAME ::= STRING_LITERAL
8431 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8432 -- SOURCE_TRACE ::= STRING_LITERAL
8434 when Pragma_Eliminate => Eliminate : declare
8435 Args : Args_List (1 .. 5);
8436 Names : constant Name_List (1 .. 5) := (
8439 Name_Parameter_Types,
8441 Name_Source_Location);
8443 Unit_Name : Node_Id renames Args (1);
8444 Entity : Node_Id renames Args (2);
8445 Parameter_Types : Node_Id renames Args (3);
8446 Result_Type : Node_Id renames Args (4);
8447 Source_Location : Node_Id renames Args (5);
8451 Check_Valid_Configuration_Pragma;
8452 Gather_Associations (Names, Args);
8454 if No (Unit_Name) then
8455 Error_Pragma ("missing Unit_Name argument for pragma%");
8459 and then (Present (Parameter_Types)
8461 Present (Result_Type)
8463 Present (Source_Location))
8465 Error_Pragma ("missing Entity argument for pragma%");
8468 if (Present (Parameter_Types)
8470 Present (Result_Type))
8472 Present (Source_Location)
8475 ("parameter profile and source location cannot " &
8476 "be used together in pragma%");
8479 Process_Eliminate_Pragma
8488 -----------------------------------
8489 -- Enable_Atomic_Synchronization --
8490 -----------------------------------
8492 -- pragma Enable_Atomic_Synchronization [(Entity)];
8494 when Pragma_Enable_Atomic_Synchronization =>
8495 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
8502 -- [ Convention =>] convention_IDENTIFIER,
8503 -- [ Entity =>] local_NAME
8504 -- [, [External_Name =>] static_string_EXPRESSION ]
8505 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8507 when Pragma_Export => Export : declare
8511 pragma Warnings (Off, C);
8514 Check_Ada_83_Warning;
8520 Check_At_Least_N_Arguments (2);
8521 Check_At_Most_N_Arguments (4);
8522 Process_Convention (C, Def_Id);
8524 if Ekind (Def_Id) /= E_Constant then
8525 Note_Possible_Modification
8526 (Get_Pragma_Arg (Arg2), Sure => False);
8529 Process_Interface_Name (Def_Id, Arg3, Arg4);
8530 Set_Exported (Def_Id, Arg2);
8532 -- If the entity is a deferred constant, propagate the information
8533 -- to the full view, because gigi elaborates the full view only.
8535 if Ekind (Def_Id) = E_Constant
8536 and then Present (Full_View (Def_Id))
8539 Id2 : constant Entity_Id := Full_View (Def_Id);
8541 Set_Is_Exported (Id2, Is_Exported (Def_Id));
8542 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
8543 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8548 ----------------------
8549 -- Export_Exception --
8550 ----------------------
8552 -- pragma Export_Exception (
8553 -- [Internal =>] LOCAL_NAME
8554 -- [, [External =>] EXTERNAL_SYMBOL]
8555 -- [, [Form =>] Ada | VMS]
8556 -- [, [Code =>] static_integer_EXPRESSION]);
8558 when Pragma_Export_Exception => Export_Exception : declare
8559 Args : Args_List (1 .. 4);
8560 Names : constant Name_List (1 .. 4) := (
8566 Internal : Node_Id renames Args (1);
8567 External : Node_Id renames Args (2);
8568 Form : Node_Id renames Args (3);
8569 Code : Node_Id renames Args (4);
8574 if Inside_A_Generic then
8575 Error_Pragma ("pragma% cannot be used for generic entities");
8578 Gather_Associations (Names, Args);
8579 Process_Extended_Import_Export_Exception_Pragma (
8580 Arg_Internal => Internal,
8581 Arg_External => External,
8585 if not Is_VMS_Exception (Entity (Internal)) then
8586 Set_Exported (Entity (Internal), Internal);
8588 end Export_Exception;
8590 ---------------------
8591 -- Export_Function --
8592 ---------------------
8594 -- pragma Export_Function (
8595 -- [Internal =>] LOCAL_NAME
8596 -- [, [External =>] EXTERNAL_SYMBOL]
8597 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8598 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8599 -- [, [Mechanism =>] MECHANISM]
8600 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8602 -- EXTERNAL_SYMBOL ::=
8604 -- | static_string_EXPRESSION
8606 -- PARAMETER_TYPES ::=
8608 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8610 -- TYPE_DESIGNATOR ::=
8612 -- | subtype_Name ' Access
8616 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8618 -- MECHANISM_ASSOCIATION ::=
8619 -- [formal_parameter_NAME =>] MECHANISM_NAME
8621 -- MECHANISM_NAME ::=
8624 -- | Descriptor [([Class =>] CLASS_NAME)]
8626 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8628 when Pragma_Export_Function => Export_Function : declare
8629 Args : Args_List (1 .. 6);
8630 Names : constant Name_List (1 .. 6) := (
8633 Name_Parameter_Types,
8636 Name_Result_Mechanism);
8638 Internal : Node_Id renames Args (1);
8639 External : Node_Id renames Args (2);
8640 Parameter_Types : Node_Id renames Args (3);
8641 Result_Type : Node_Id renames Args (4);
8642 Mechanism : Node_Id renames Args (5);
8643 Result_Mechanism : Node_Id renames Args (6);
8647 Gather_Associations (Names, Args);
8648 Process_Extended_Import_Export_Subprogram_Pragma (
8649 Arg_Internal => Internal,
8650 Arg_External => External,
8651 Arg_Parameter_Types => Parameter_Types,
8652 Arg_Result_Type => Result_Type,
8653 Arg_Mechanism => Mechanism,
8654 Arg_Result_Mechanism => Result_Mechanism);
8655 end Export_Function;
8661 -- pragma Export_Object (
8662 -- [Internal =>] LOCAL_NAME
8663 -- [, [External =>] EXTERNAL_SYMBOL]
8664 -- [, [Size =>] EXTERNAL_SYMBOL]);
8666 -- EXTERNAL_SYMBOL ::=
8668 -- | static_string_EXPRESSION
8670 -- PARAMETER_TYPES ::=
8672 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8674 -- TYPE_DESIGNATOR ::=
8676 -- | subtype_Name ' Access
8680 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8682 -- MECHANISM_ASSOCIATION ::=
8683 -- [formal_parameter_NAME =>] MECHANISM_NAME
8685 -- MECHANISM_NAME ::=
8688 -- | Descriptor [([Class =>] CLASS_NAME)]
8690 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8692 when Pragma_Export_Object => Export_Object : declare
8693 Args : Args_List (1 .. 3);
8694 Names : constant Name_List (1 .. 3) := (
8699 Internal : Node_Id renames Args (1);
8700 External : Node_Id renames Args (2);
8701 Size : Node_Id renames Args (3);
8705 Gather_Associations (Names, Args);
8706 Process_Extended_Import_Export_Object_Pragma (
8707 Arg_Internal => Internal,
8708 Arg_External => External,
8712 ----------------------
8713 -- Export_Procedure --
8714 ----------------------
8716 -- pragma Export_Procedure (
8717 -- [Internal =>] LOCAL_NAME
8718 -- [, [External =>] EXTERNAL_SYMBOL]
8719 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8720 -- [, [Mechanism =>] MECHANISM]);
8722 -- EXTERNAL_SYMBOL ::=
8724 -- | static_string_EXPRESSION
8726 -- PARAMETER_TYPES ::=
8728 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8730 -- TYPE_DESIGNATOR ::=
8732 -- | subtype_Name ' Access
8736 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8738 -- MECHANISM_ASSOCIATION ::=
8739 -- [formal_parameter_NAME =>] MECHANISM_NAME
8741 -- MECHANISM_NAME ::=
8744 -- | Descriptor [([Class =>] CLASS_NAME)]
8746 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8748 when Pragma_Export_Procedure => Export_Procedure : declare
8749 Args : Args_List (1 .. 4);
8750 Names : constant Name_List (1 .. 4) := (
8753 Name_Parameter_Types,
8756 Internal : Node_Id renames Args (1);
8757 External : Node_Id renames Args (2);
8758 Parameter_Types : Node_Id renames Args (3);
8759 Mechanism : Node_Id renames Args (4);
8763 Gather_Associations (Names, Args);
8764 Process_Extended_Import_Export_Subprogram_Pragma (
8765 Arg_Internal => Internal,
8766 Arg_External => External,
8767 Arg_Parameter_Types => Parameter_Types,
8768 Arg_Mechanism => Mechanism);
8769 end Export_Procedure;
8775 -- pragma Export_Value (
8776 -- [Value =>] static_integer_EXPRESSION,
8777 -- [Link_Name =>] static_string_EXPRESSION);
8779 when Pragma_Export_Value =>
8781 Check_Arg_Order ((Name_Value, Name_Link_Name));
8782 Check_Arg_Count (2);
8784 Check_Optional_Identifier (Arg1, Name_Value);
8785 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8787 Check_Optional_Identifier (Arg2, Name_Link_Name);
8788 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8790 -----------------------------
8791 -- Export_Valued_Procedure --
8792 -----------------------------
8794 -- pragma Export_Valued_Procedure (
8795 -- [Internal =>] LOCAL_NAME
8796 -- [, [External =>] EXTERNAL_SYMBOL,]
8797 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8798 -- [, [Mechanism =>] MECHANISM]);
8800 -- EXTERNAL_SYMBOL ::=
8802 -- | static_string_EXPRESSION
8804 -- PARAMETER_TYPES ::=
8806 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8808 -- TYPE_DESIGNATOR ::=
8810 -- | subtype_Name ' Access
8814 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8816 -- MECHANISM_ASSOCIATION ::=
8817 -- [formal_parameter_NAME =>] MECHANISM_NAME
8819 -- MECHANISM_NAME ::=
8822 -- | Descriptor [([Class =>] CLASS_NAME)]
8824 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8826 when Pragma_Export_Valued_Procedure =>
8827 Export_Valued_Procedure : declare
8828 Args : Args_List (1 .. 4);
8829 Names : constant Name_List (1 .. 4) := (
8832 Name_Parameter_Types,
8835 Internal : Node_Id renames Args (1);
8836 External : Node_Id renames Args (2);
8837 Parameter_Types : Node_Id renames Args (3);
8838 Mechanism : Node_Id renames Args (4);
8842 Gather_Associations (Names, Args);
8843 Process_Extended_Import_Export_Subprogram_Pragma (
8844 Arg_Internal => Internal,
8845 Arg_External => External,
8846 Arg_Parameter_Types => Parameter_Types,
8847 Arg_Mechanism => Mechanism);
8848 end Export_Valued_Procedure;
8854 -- pragma Extend_System ([Name =>] Identifier);
8856 when Pragma_Extend_System => Extend_System : declare
8859 Check_Valid_Configuration_Pragma;
8860 Check_Arg_Count (1);
8861 Check_Optional_Identifier (Arg1, Name_Name);
8862 Check_Arg_Is_Identifier (Arg1);
8864 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8867 and then Name_Buffer (1 .. 4) = "aux_"
8869 if Present (System_Extend_Pragma_Arg) then
8870 if Chars (Get_Pragma_Arg (Arg1)) =
8871 Chars (Expression (System_Extend_Pragma_Arg))
8875 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8876 Error_Pragma ("pragma% conflicts with that #");
8880 System_Extend_Pragma_Arg := Arg1;
8882 if not GNAT_Mode then
8883 System_Extend_Unit := Arg1;
8887 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8891 ------------------------
8892 -- Extensions_Allowed --
8893 ------------------------
8895 -- pragma Extensions_Allowed (ON | OFF);
8897 when Pragma_Extensions_Allowed =>
8899 Check_Arg_Count (1);
8900 Check_No_Identifiers;
8901 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8903 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8904 Extensions_Allowed := True;
8905 Ada_Version := Ada_Version_Type'Last;
8908 Extensions_Allowed := False;
8909 Ada_Version := Ada_Version_Explicit;
8916 -- pragma External (
8917 -- [ Convention =>] convention_IDENTIFIER,
8918 -- [ Entity =>] local_NAME
8919 -- [, [External_Name =>] static_string_EXPRESSION ]
8920 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8922 when Pragma_External => External : declare
8926 pragma Warnings (Off, C);
8935 Check_At_Least_N_Arguments (2);
8936 Check_At_Most_N_Arguments (4);
8937 Process_Convention (C, Def_Id);
8938 Note_Possible_Modification
8939 (Get_Pragma_Arg (Arg2), Sure => False);
8940 Process_Interface_Name (Def_Id, Arg3, Arg4);
8941 Set_Exported (Def_Id, Arg2);
8944 --------------------------
8945 -- External_Name_Casing --
8946 --------------------------
8948 -- pragma External_Name_Casing (
8949 -- UPPERCASE | LOWERCASE
8950 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8952 when Pragma_External_Name_Casing => External_Name_Casing : declare
8955 Check_No_Identifiers;
8957 if Arg_Count = 2 then
8959 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8961 case Chars (Get_Pragma_Arg (Arg2)) is
8963 Opt.External_Name_Exp_Casing := As_Is;
8965 when Name_Uppercase =>
8966 Opt.External_Name_Exp_Casing := Uppercase;
8968 when Name_Lowercase =>
8969 Opt.External_Name_Exp_Casing := Lowercase;
8976 Check_Arg_Count (1);
8979 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8981 case Chars (Get_Pragma_Arg (Arg1)) is
8982 when Name_Uppercase =>
8983 Opt.External_Name_Imp_Casing := Uppercase;
8985 when Name_Lowercase =>
8986 Opt.External_Name_Imp_Casing := Lowercase;
8991 end External_Name_Casing;
8993 --------------------------
8994 -- Favor_Top_Level --
8995 --------------------------
8997 -- pragma Favor_Top_Level (type_NAME);
8999 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
9000 Named_Entity : Entity_Id;
9004 Check_No_Identifiers;
9005 Check_Arg_Count (1);
9006 Check_Arg_Is_Local_Name (Arg1);
9007 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
9009 -- If it's an access-to-subprogram type (in particular, not a
9010 -- subtype), set the flag on that type.
9012 if Is_Access_Subprogram_Type (Named_Entity) then
9013 Set_Can_Use_Internal_Rep (Named_Entity, False);
9015 -- Otherwise it's an error (name denotes the wrong sort of entity)
9019 ("access-to-subprogram type expected",
9020 Get_Pragma_Arg (Arg1));
9022 end Favor_Top_Level;
9028 -- pragma Fast_Math;
9030 when Pragma_Fast_Math =>
9032 Check_No_Identifiers;
9033 Check_Valid_Configuration_Pragma;
9036 ---------------------------
9037 -- Finalize_Storage_Only --
9038 ---------------------------
9040 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9042 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9043 Assoc : constant Node_Id := Arg1;
9044 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9049 Check_No_Identifiers;
9050 Check_Arg_Count (1);
9051 Check_Arg_Is_Local_Name (Arg1);
9053 Find_Type (Type_Id);
9054 Typ := Entity (Type_Id);
9057 or else Rep_Item_Too_Early (Typ, N)
9061 Typ := Underlying_Type (Typ);
9064 if not Is_Controlled (Typ) then
9065 Error_Pragma ("pragma% must specify controlled type");
9068 Check_First_Subtype (Arg1);
9070 if Finalize_Storage_Only (Typ) then
9071 Error_Pragma ("duplicate pragma%, only one allowed");
9073 elsif not Rep_Item_Too_Late (Typ, N) then
9074 Set_Finalize_Storage_Only (Base_Type (Typ), True);
9076 end Finalize_Storage;
9078 --------------------------
9079 -- Float_Representation --
9080 --------------------------
9082 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9084 -- FLOAT_REP ::= VAX_Float | IEEE_Float
9086 when Pragma_Float_Representation => Float_Representation : declare
9094 if Arg_Count = 1 then
9095 Check_Valid_Configuration_Pragma;
9097 Check_Arg_Count (2);
9098 Check_Optional_Identifier (Arg2, Name_Entity);
9099 Check_Arg_Is_Local_Name (Arg2);
9102 Check_No_Identifier (Arg1);
9103 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9105 if not OpenVMS_On_Target then
9106 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9108 ("?pragma% ignored (applies only to Open'V'M'S)");
9114 -- One argument case
9116 if Arg_Count = 1 then
9117 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9118 if Opt.Float_Format = 'I' then
9119 Error_Pragma ("'I'E'E'E format previously specified");
9122 Opt.Float_Format := 'V';
9125 if Opt.Float_Format = 'V' then
9126 Error_Pragma ("'V'A'X format previously specified");
9129 Opt.Float_Format := 'I';
9132 Set_Standard_Fpt_Formats;
9134 -- Two argument case
9137 Argx := Get_Pragma_Arg (Arg2);
9139 if not Is_Entity_Name (Argx)
9140 or else not Is_Floating_Point_Type (Entity (Argx))
9143 ("second argument of% pragma must be floating-point type",
9147 Ent := Entity (Argx);
9148 Digs := UI_To_Int (Digits_Value (Ent));
9150 -- Two arguments, VAX_Float case
9152 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9154 when 6 => Set_F_Float (Ent);
9155 when 9 => Set_D_Float (Ent);
9156 when 15 => Set_G_Float (Ent);
9160 ("wrong digits value, must be 6,9 or 15", Arg2);
9163 -- Two arguments, IEEE_Float case
9167 when 6 => Set_IEEE_Short (Ent);
9168 when 15 => Set_IEEE_Long (Ent);
9172 ("wrong digits value, must be 6 or 15", Arg2);
9176 end Float_Representation;
9182 -- pragma Ident (static_string_EXPRESSION)
9184 -- Note: pragma Comment shares this processing. Pragma Comment is
9185 -- identical to Ident, except that the restriction of the argument to
9186 -- 31 characters and the placement restrictions are not enforced for
9189 when Pragma_Ident | Pragma_Comment => Ident : declare
9194 Check_Arg_Count (1);
9195 Check_No_Identifiers;
9196 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9199 -- For pragma Ident, preserve DEC compatibility by requiring the
9200 -- pragma to appear in a declarative part or package spec.
9202 if Prag_Id = Pragma_Ident then
9203 Check_Is_In_Decl_Part_Or_Package_Spec;
9206 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9213 GP := Parent (Parent (N));
9215 if Nkind_In (GP, N_Package_Declaration,
9216 N_Generic_Package_Declaration)
9221 -- If we have a compilation unit, then record the ident value,
9222 -- checking for improper duplication.
9224 if Nkind (GP) = N_Compilation_Unit then
9225 CS := Ident_String (Current_Sem_Unit);
9227 if Present (CS) then
9229 -- For Ident, we do not permit multiple instances
9231 if Prag_Id = Pragma_Ident then
9232 Error_Pragma ("duplicate% pragma not permitted");
9234 -- For Comment, we concatenate the string, unless we want
9235 -- to preserve the tree structure for ASIS.
9237 elsif not ASIS_Mode then
9238 Start_String (Strval (CS));
9239 Store_String_Char (' ');
9240 Store_String_Chars (Strval (Str));
9241 Set_Strval (CS, End_String);
9245 -- In VMS, the effect of IDENT is achieved by passing
9246 -- --identification=name as a --for-linker switch.
9248 if OpenVMS_On_Target then
9251 ("--for-linker=--identification=");
9252 String_To_Name_Buffer (Strval (Str));
9253 Store_String_Chars (Name_Buffer (1 .. Name_Len));
9255 -- Only the last processed IDENT is saved. The main
9256 -- purpose is so an IDENT associated with a main
9257 -- procedure will be used in preference to an IDENT
9258 -- associated with a with'd package.
9260 Replace_Linker_Option_String
9261 (End_String, "--for-linker=--identification=");
9264 Set_Ident_String (Current_Sem_Unit, Str);
9267 -- For subunits, we just ignore the Ident, since in GNAT these
9268 -- are not separate object files, and hence not separate units
9269 -- in the unit table.
9271 elsif Nkind (GP) = N_Subunit then
9274 -- Otherwise we have a misplaced pragma Ident, but we ignore
9275 -- this if we are in an instantiation, since it comes from
9276 -- a generic, and has no relevance to the instantiation.
9278 elsif Prag_Id = Pragma_Ident then
9279 if Instantiation_Location (Loc) = No_Location then
9280 Error_Pragma ("pragma% only allowed at outer level");
9286 ----------------------------
9287 -- Implementation_Defined --
9288 ----------------------------
9290 -- pragma Implementation_Defined (local_NAME);
9292 -- Marks previously declared entity as implementation defined. For
9293 -- an overloaded entity, applies to the most recent homonym.
9295 -- pragma Implementation_Defined;
9297 -- The form with no arguments appears anywhere within a scope, most
9298 -- typically a package spec, and indicates that all entities that are
9299 -- defined within the package spec are Implementation_Defined.
9301 when Pragma_Implementation_Defined => Implementation_Defined : declare
9305 Check_No_Identifiers;
9307 -- Form with no arguments
9309 if Arg_Count = 0 then
9310 Set_Is_Implementation_Defined (Current_Scope);
9312 -- Form with one argument
9315 Check_Arg_Count (1);
9316 Check_Arg_Is_Local_Name (Arg1);
9317 Ent := Entity (Get_Pragma_Arg (Arg1));
9318 Set_Is_Implementation_Defined (Ent);
9320 end Implementation_Defined;
9326 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9327 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
9329 when Pragma_Implemented => Implemented : declare
9330 Proc_Id : Entity_Id;
9335 Check_Arg_Count (2);
9336 Check_No_Identifiers;
9337 Check_Arg_Is_Identifier (Arg1);
9338 Check_Arg_Is_Local_Name (Arg1);
9340 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
9342 -- Extract the name of the local procedure
9344 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9346 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9347 -- primitive procedure of a synchronized tagged type.
9349 if Ekind (Proc_Id) = E_Procedure
9350 and then Is_Primitive (Proc_Id)
9351 and then Present (First_Formal (Proc_Id))
9353 Typ := Etype (First_Formal (Proc_Id));
9355 if Is_Tagged_Type (Typ)
9358 -- Check for a protected, a synchronized or a task interface
9360 ((Is_Interface (Typ)
9361 and then Is_Synchronized_Interface (Typ))
9363 -- Check for a protected type or a task type that implements
9367 (Is_Concurrent_Record_Type (Typ)
9368 and then Present (Interfaces (Typ)))
9370 -- Check for a private record extension with keyword
9374 (Ekind_In (Typ, E_Record_Type_With_Private,
9375 E_Record_Subtype_With_Private)
9376 and then Synchronized_Present (Parent (Typ))))
9381 ("controlling formal must be of synchronized " &
9382 "tagged type", Arg1);
9386 -- Procedures declared inside a protected type must be accepted
9388 elsif Ekind (Proc_Id) = E_Procedure
9389 and then Is_Protected_Type (Scope (Proc_Id))
9393 -- The first argument is not a primitive procedure
9397 ("pragma % must be applied to a primitive procedure", Arg1);
9401 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9402 -- By_Protected_Procedure to the primitive procedure of a task
9405 if Chars (Arg2) = Name_By_Protected_Procedure
9406 and then Is_Interface (Typ)
9407 and then Is_Task_Interface (Typ)
9410 ("implementation kind By_Protected_Procedure cannot be " &
9411 "applied to a task interface primitive", Arg2);
9415 Record_Rep_Item (Proc_Id, N);
9418 ----------------------
9419 -- Implicit_Packing --
9420 ----------------------
9422 -- pragma Implicit_Packing;
9424 when Pragma_Implicit_Packing =>
9426 Check_Arg_Count (0);
9427 Implicit_Packing := True;
9434 -- [Convention =>] convention_IDENTIFIER,
9435 -- [Entity =>] local_NAME
9436 -- [, [External_Name =>] static_string_EXPRESSION ]
9437 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9439 when Pragma_Import =>
9440 Check_Ada_83_Warning;
9446 Check_At_Least_N_Arguments (2);
9447 Check_At_Most_N_Arguments (4);
9448 Process_Import_Or_Interface;
9450 ----------------------
9451 -- Import_Exception --
9452 ----------------------
9454 -- pragma Import_Exception (
9455 -- [Internal =>] LOCAL_NAME
9456 -- [, [External =>] EXTERNAL_SYMBOL]
9457 -- [, [Form =>] Ada | VMS]
9458 -- [, [Code =>] static_integer_EXPRESSION]);
9460 when Pragma_Import_Exception => Import_Exception : declare
9461 Args : Args_List (1 .. 4);
9462 Names : constant Name_List (1 .. 4) := (
9468 Internal : Node_Id renames Args (1);
9469 External : Node_Id renames Args (2);
9470 Form : Node_Id renames Args (3);
9471 Code : Node_Id renames Args (4);
9475 Gather_Associations (Names, Args);
9477 if Present (External) and then Present (Code) then
9479 ("cannot give both External and Code options for pragma%");
9482 Process_Extended_Import_Export_Exception_Pragma (
9483 Arg_Internal => Internal,
9484 Arg_External => External,
9488 if not Is_VMS_Exception (Entity (Internal)) then
9489 Set_Imported (Entity (Internal));
9491 end Import_Exception;
9493 ---------------------
9494 -- Import_Function --
9495 ---------------------
9497 -- pragma Import_Function (
9498 -- [Internal =>] LOCAL_NAME,
9499 -- [, [External =>] EXTERNAL_SYMBOL]
9500 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9501 -- [, [Result_Type =>] SUBTYPE_MARK]
9502 -- [, [Mechanism =>] MECHANISM]
9503 -- [, [Result_Mechanism =>] MECHANISM_NAME]
9504 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9506 -- EXTERNAL_SYMBOL ::=
9508 -- | static_string_EXPRESSION
9510 -- PARAMETER_TYPES ::=
9512 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9514 -- TYPE_DESIGNATOR ::=
9516 -- | subtype_Name ' Access
9520 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9522 -- MECHANISM_ASSOCIATION ::=
9523 -- [formal_parameter_NAME =>] MECHANISM_NAME
9525 -- MECHANISM_NAME ::=
9528 -- | Descriptor [([Class =>] CLASS_NAME)]
9530 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9532 when Pragma_Import_Function => Import_Function : declare
9533 Args : Args_List (1 .. 7);
9534 Names : constant Name_List (1 .. 7) := (
9537 Name_Parameter_Types,
9540 Name_Result_Mechanism,
9541 Name_First_Optional_Parameter);
9543 Internal : Node_Id renames Args (1);
9544 External : Node_Id renames Args (2);
9545 Parameter_Types : Node_Id renames Args (3);
9546 Result_Type : Node_Id renames Args (4);
9547 Mechanism : Node_Id renames Args (5);
9548 Result_Mechanism : Node_Id renames Args (6);
9549 First_Optional_Parameter : Node_Id renames Args (7);
9553 Gather_Associations (Names, Args);
9554 Process_Extended_Import_Export_Subprogram_Pragma (
9555 Arg_Internal => Internal,
9556 Arg_External => External,
9557 Arg_Parameter_Types => Parameter_Types,
9558 Arg_Result_Type => Result_Type,
9559 Arg_Mechanism => Mechanism,
9560 Arg_Result_Mechanism => Result_Mechanism,
9561 Arg_First_Optional_Parameter => First_Optional_Parameter);
9562 end Import_Function;
9568 -- pragma Import_Object (
9569 -- [Internal =>] LOCAL_NAME
9570 -- [, [External =>] EXTERNAL_SYMBOL]
9571 -- [, [Size =>] EXTERNAL_SYMBOL]);
9573 -- EXTERNAL_SYMBOL ::=
9575 -- | static_string_EXPRESSION
9577 when Pragma_Import_Object => Import_Object : declare
9578 Args : Args_List (1 .. 3);
9579 Names : constant Name_List (1 .. 3) := (
9584 Internal : Node_Id renames Args (1);
9585 External : Node_Id renames Args (2);
9586 Size : Node_Id renames Args (3);
9590 Gather_Associations (Names, Args);
9591 Process_Extended_Import_Export_Object_Pragma (
9592 Arg_Internal => Internal,
9593 Arg_External => External,
9597 ----------------------
9598 -- Import_Procedure --
9599 ----------------------
9601 -- pragma Import_Procedure (
9602 -- [Internal =>] LOCAL_NAME
9603 -- [, [External =>] EXTERNAL_SYMBOL]
9604 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9605 -- [, [Mechanism =>] MECHANISM]
9606 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9608 -- EXTERNAL_SYMBOL ::=
9610 -- | static_string_EXPRESSION
9612 -- PARAMETER_TYPES ::=
9614 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9616 -- TYPE_DESIGNATOR ::=
9618 -- | subtype_Name ' Access
9622 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9624 -- MECHANISM_ASSOCIATION ::=
9625 -- [formal_parameter_NAME =>] MECHANISM_NAME
9627 -- MECHANISM_NAME ::=
9630 -- | Descriptor [([Class =>] CLASS_NAME)]
9632 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9634 when Pragma_Import_Procedure => Import_Procedure : declare
9635 Args : Args_List (1 .. 5);
9636 Names : constant Name_List (1 .. 5) := (
9639 Name_Parameter_Types,
9641 Name_First_Optional_Parameter);
9643 Internal : Node_Id renames Args (1);
9644 External : Node_Id renames Args (2);
9645 Parameter_Types : Node_Id renames Args (3);
9646 Mechanism : Node_Id renames Args (4);
9647 First_Optional_Parameter : Node_Id renames Args (5);
9651 Gather_Associations (Names, Args);
9652 Process_Extended_Import_Export_Subprogram_Pragma (
9653 Arg_Internal => Internal,
9654 Arg_External => External,
9655 Arg_Parameter_Types => Parameter_Types,
9656 Arg_Mechanism => Mechanism,
9657 Arg_First_Optional_Parameter => First_Optional_Parameter);
9658 end Import_Procedure;
9660 -----------------------------
9661 -- Import_Valued_Procedure --
9662 -----------------------------
9664 -- pragma Import_Valued_Procedure (
9665 -- [Internal =>] LOCAL_NAME
9666 -- [, [External =>] EXTERNAL_SYMBOL]
9667 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9668 -- [, [Mechanism =>] MECHANISM]
9669 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9671 -- EXTERNAL_SYMBOL ::=
9673 -- | static_string_EXPRESSION
9675 -- PARAMETER_TYPES ::=
9677 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9679 -- TYPE_DESIGNATOR ::=
9681 -- | subtype_Name ' Access
9685 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9687 -- MECHANISM_ASSOCIATION ::=
9688 -- [formal_parameter_NAME =>] MECHANISM_NAME
9690 -- MECHANISM_NAME ::=
9693 -- | Descriptor [([Class =>] CLASS_NAME)]
9695 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9697 when Pragma_Import_Valued_Procedure =>
9698 Import_Valued_Procedure : declare
9699 Args : Args_List (1 .. 5);
9700 Names : constant Name_List (1 .. 5) := (
9703 Name_Parameter_Types,
9705 Name_First_Optional_Parameter);
9707 Internal : Node_Id renames Args (1);
9708 External : Node_Id renames Args (2);
9709 Parameter_Types : Node_Id renames Args (3);
9710 Mechanism : Node_Id renames Args (4);
9711 First_Optional_Parameter : Node_Id renames Args (5);
9715 Gather_Associations (Names, Args);
9716 Process_Extended_Import_Export_Subprogram_Pragma (
9717 Arg_Internal => Internal,
9718 Arg_External => External,
9719 Arg_Parameter_Types => Parameter_Types,
9720 Arg_Mechanism => Mechanism,
9721 Arg_First_Optional_Parameter => First_Optional_Parameter);
9722 end Import_Valued_Procedure;
9728 -- pragma Independent (LOCAL_NAME);
9730 when Pragma_Independent => Independent : declare
9737 Check_Ada_83_Warning;
9739 Check_No_Identifiers;
9740 Check_Arg_Count (1);
9741 Check_Arg_Is_Local_Name (Arg1);
9742 E_Id := Get_Pragma_Arg (Arg1);
9744 if Etype (E_Id) = Any_Type then
9749 D := Declaration_Node (E);
9752 -- Check duplicate before we chain ourselves!
9754 Check_Duplicate_Pragma (E);
9756 -- Check appropriate entity
9759 if Rep_Item_Too_Early (E, N)
9761 Rep_Item_Too_Late (E, N)
9765 Check_First_Subtype (Arg1);
9768 elsif K = N_Object_Declaration
9769 or else (K = N_Component_Declaration
9770 and then Original_Record_Component (E) = E)
9772 if Rep_Item_Too_Late (E, N) then
9778 ("inappropriate entity for pragma%", Arg1);
9781 Independence_Checks.Append ((N, E));
9784 ----------------------------
9785 -- Independent_Components --
9786 ----------------------------
9788 -- pragma Atomic_Components (array_LOCAL_NAME);
9790 -- This processing is shared by Volatile_Components
9792 when Pragma_Independent_Components => Independent_Components : declare
9799 Check_Ada_83_Warning;
9801 Check_No_Identifiers;
9802 Check_Arg_Count (1);
9803 Check_Arg_Is_Local_Name (Arg1);
9804 E_Id := Get_Pragma_Arg (Arg1);
9806 if Etype (E_Id) = Any_Type then
9812 -- Check duplicate before we chain ourselves!
9814 Check_Duplicate_Pragma (E);
9816 -- Check appropriate entity
9818 if Rep_Item_Too_Early (E, N)
9820 Rep_Item_Too_Late (E, N)
9825 D := Declaration_Node (E);
9828 if (K = N_Full_Type_Declaration
9829 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9831 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9832 and then Nkind (D) = N_Object_Declaration
9833 and then Nkind (Object_Definition (D)) =
9834 N_Constrained_Array_Definition)
9836 Independence_Checks.Append ((N, E));
9839 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9841 end Independent_Components;
9843 ------------------------
9844 -- Initialize_Scalars --
9845 ------------------------
9847 -- pragma Initialize_Scalars;
9849 when Pragma_Initialize_Scalars =>
9851 Check_Arg_Count (0);
9852 Check_Valid_Configuration_Pragma;
9853 Check_Restriction (No_Initialize_Scalars, N);
9855 -- Initialize_Scalars creates false positives in CodePeer, and
9856 -- incorrect negative results in Alfa mode, so ignore this pragma
9859 if not Restriction_Active (No_Initialize_Scalars)
9860 and then not (CodePeer_Mode or Alfa_Mode)
9862 Init_Or_Norm_Scalars := True;
9863 Initialize_Scalars := True;
9870 -- pragma Inline ( NAME {, NAME} );
9872 when Pragma_Inline =>
9874 -- Pragma is active if inlining option is active
9876 Process_Inline (Inline_Active);
9882 -- pragma Inline_Always ( NAME {, NAME} );
9884 when Pragma_Inline_Always =>
9887 -- Pragma always active unless in CodePeer or Alfa mode, since
9888 -- this causes walk order issues.
9890 if not (CodePeer_Mode or Alfa_Mode) then
9891 Process_Inline (True);
9894 --------------------
9895 -- Inline_Generic --
9896 --------------------
9898 -- pragma Inline_Generic (NAME {, NAME});
9900 when Pragma_Inline_Generic =>
9902 Process_Generic_List;
9904 ----------------------
9905 -- Inspection_Point --
9906 ----------------------
9908 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9910 when Pragma_Inspection_Point => Inspection_Point : declare
9915 if Arg_Count > 0 then
9918 Exp := Get_Pragma_Arg (Arg);
9921 if not Is_Entity_Name (Exp)
9922 or else not Is_Object (Entity (Exp))
9924 Error_Pragma_Arg ("object name required", Arg);
9931 end Inspection_Point;
9937 -- pragma Interface (
9938 -- [ Convention =>] convention_IDENTIFIER,
9939 -- [ Entity =>] local_NAME
9940 -- [, [External_Name =>] static_string_EXPRESSION ]
9941 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9943 when Pragma_Interface =>
9950 Check_At_Least_N_Arguments (2);
9951 Check_At_Most_N_Arguments (4);
9952 Process_Import_Or_Interface;
9954 -- In Ada 2005, the permission to use Interface (a reserved word)
9955 -- as a pragma name is considered an obsolescent feature.
9957 if Ada_Version >= Ada_2005 then
9959 (No_Obsolescent_Features, Pragma_Identifier (N));
9962 --------------------
9963 -- Interface_Name --
9964 --------------------
9966 -- pragma Interface_Name (
9967 -- [ Entity =>] local_NAME
9968 -- [,[External_Name =>] static_string_EXPRESSION ]
9969 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9971 when Pragma_Interface_Name => Interface_Name : declare
9980 ((Name_Entity, Name_External_Name, Name_Link_Name));
9981 Check_At_Least_N_Arguments (2);
9982 Check_At_Most_N_Arguments (3);
9983 Id := Get_Pragma_Arg (Arg1);
9986 if not Is_Entity_Name (Id) then
9988 ("first argument for pragma% must be entity name", Arg1);
9989 elsif Etype (Id) = Any_Type then
9992 Def_Id := Entity (Id);
9995 -- Special DEC-compatible processing for the object case, forces
9996 -- object to be imported.
9998 if Ekind (Def_Id) = E_Variable then
9999 Kill_Size_Check_Code (Def_Id);
10000 Note_Possible_Modification (Id, Sure => False);
10002 -- Initialization is not allowed for imported variable
10004 if Present (Expression (Parent (Def_Id)))
10005 and then Comes_From_Source (Expression (Parent (Def_Id)))
10007 Error_Msg_Sloc := Sloc (Def_Id);
10009 ("no initialization allowed for declaration of& #",
10013 -- For compatibility, support VADS usage of providing both
10014 -- pragmas Interface and Interface_Name to obtain the effect
10015 -- of a single Import pragma.
10017 if Is_Imported (Def_Id)
10018 and then Present (First_Rep_Item (Def_Id))
10019 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
10021 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
10025 Set_Imported (Def_Id);
10028 Set_Is_Public (Def_Id);
10029 Process_Interface_Name (Def_Id, Arg2, Arg3);
10032 -- Otherwise must be subprogram
10034 elsif not Is_Subprogram (Def_Id) then
10036 ("argument of pragma% is not subprogram", Arg1);
10039 Check_At_Most_N_Arguments (3);
10043 -- Loop through homonyms
10046 Def_Id := Get_Base_Subprogram (Hom_Id);
10048 if Is_Imported (Def_Id) then
10049 Process_Interface_Name (Def_Id, Arg2, Arg3);
10053 exit when From_Aspect_Specification (N);
10054 Hom_Id := Homonym (Hom_Id);
10056 exit when No (Hom_Id)
10057 or else Scope (Hom_Id) /= Current_Scope;
10062 ("argument of pragma% is not imported subprogram",
10066 end Interface_Name;
10068 -----------------------
10069 -- Interrupt_Handler --
10070 -----------------------
10072 -- pragma Interrupt_Handler (handler_NAME);
10074 when Pragma_Interrupt_Handler =>
10075 Check_Ada_83_Warning;
10076 Check_Arg_Count (1);
10077 Check_No_Identifiers;
10079 if No_Run_Time_Mode then
10080 Error_Msg_CRT ("Interrupt_Handler pragma", N);
10082 Check_Interrupt_Or_Attach_Handler;
10083 Process_Interrupt_Or_Attach_Handler;
10086 ------------------------
10087 -- Interrupt_Priority --
10088 ------------------------
10090 -- pragma Interrupt_Priority [(EXPRESSION)];
10092 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
10093 P : constant Node_Id := Parent (N);
10097 Check_Ada_83_Warning;
10099 if Arg_Count /= 0 then
10100 Arg := Get_Pragma_Arg (Arg1);
10101 Check_Arg_Count (1);
10102 Check_No_Identifiers;
10104 -- The expression must be analyzed in the special manner
10105 -- described in "Handling of Default and Per-Object
10106 -- Expressions" in sem.ads.
10108 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
10111 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
10115 elsif Has_Pragma_Priority (P) then
10116 Error_Pragma ("duplicate pragma% not allowed");
10119 Set_Has_Pragma_Priority (P, True);
10120 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10122 end Interrupt_Priority;
10124 ---------------------
10125 -- Interrupt_State --
10126 ---------------------
10128 -- pragma Interrupt_State (
10129 -- [Name =>] INTERRUPT_ID,
10130 -- [State =>] INTERRUPT_STATE);
10132 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
10133 -- INTERRUPT_STATE => System | Runtime | User
10135 -- Note: if the interrupt id is given as an identifier, then it must
10136 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
10137 -- given as a static integer expression which must be in the range of
10138 -- Ada.Interrupts.Interrupt_ID.
10140 when Pragma_Interrupt_State => Interrupt_State : declare
10142 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
10143 -- This is the entity Ada.Interrupts.Interrupt_ID;
10145 State_Type : Character;
10146 -- Set to 's'/'r'/'u' for System/Runtime/User
10149 -- Index to entry in Interrupt_States table
10152 -- Value of interrupt
10154 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
10155 -- The first argument to the pragma
10157 Int_Ent : Entity_Id;
10158 -- Interrupt entity in Ada.Interrupts.Names
10162 Check_Arg_Order ((Name_Name, Name_State));
10163 Check_Arg_Count (2);
10165 Check_Optional_Identifier (Arg1, Name_Name);
10166 Check_Optional_Identifier (Arg2, Name_State);
10167 Check_Arg_Is_Identifier (Arg2);
10169 -- First argument is identifier
10171 if Nkind (Arg1X) = N_Identifier then
10173 -- Search list of names in Ada.Interrupts.Names
10175 Int_Ent := First_Entity (RTE (RE_Names));
10177 if No (Int_Ent) then
10178 Error_Pragma_Arg ("invalid interrupt name", Arg1);
10180 elsif Chars (Int_Ent) = Chars (Arg1X) then
10181 Int_Val := Expr_Value (Constant_Value (Int_Ent));
10185 Next_Entity (Int_Ent);
10188 -- First argument is not an identifier, so it must be a static
10189 -- expression of type Ada.Interrupts.Interrupt_ID.
10192 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10193 Int_Val := Expr_Value (Arg1X);
10195 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
10197 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10200 ("value not in range of type " &
10201 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10207 case Chars (Get_Pragma_Arg (Arg2)) is
10208 when Name_Runtime => State_Type := 'r';
10209 when Name_System => State_Type := 's';
10210 when Name_User => State_Type := 'u';
10213 Error_Pragma_Arg ("invalid interrupt state", Arg2);
10216 -- Check if entry is already stored
10218 IST_Num := Interrupt_States.First;
10220 -- If entry not found, add it
10222 if IST_Num > Interrupt_States.Last then
10223 Interrupt_States.Append
10224 ((Interrupt_Number => UI_To_Int (Int_Val),
10225 Interrupt_State => State_Type,
10226 Pragma_Loc => Loc));
10229 -- Case of entry for the same entry
10231 elsif Int_Val = Interrupt_States.Table (IST_Num).
10234 -- If state matches, done, no need to make redundant entry
10237 State_Type = Interrupt_States.Table (IST_Num).
10240 -- Otherwise if state does not match, error
10243 Interrupt_States.Table (IST_Num).Pragma_Loc;
10245 ("state conflicts with that given #", Arg2);
10249 IST_Num := IST_Num + 1;
10251 end Interrupt_State;
10257 -- pragma Invariant
10258 -- ([Entity =>] type_LOCAL_NAME,
10259 -- [Check =>] EXPRESSION
10260 -- [,[Message =>] String_Expression]);
10262 when Pragma_Invariant => Invariant : declare
10267 pragma Unreferenced (Discard);
10271 Check_At_Least_N_Arguments (2);
10272 Check_At_Most_N_Arguments (3);
10273 Check_Optional_Identifier (Arg1, Name_Entity);
10274 Check_Optional_Identifier (Arg2, Name_Check);
10276 if Arg_Count = 3 then
10277 Check_Optional_Identifier (Arg3, Name_Message);
10278 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10281 Check_Arg_Is_Local_Name (Arg1);
10283 Type_Id := Get_Pragma_Arg (Arg1);
10284 Find_Type (Type_Id);
10285 Typ := Entity (Type_Id);
10287 if Typ = Any_Type then
10290 -- An invariant must apply to a private type, or appear in the
10291 -- private part of a package spec and apply to a completion.
10293 elsif Ekind_In (Typ, E_Private_Type,
10294 E_Record_Type_With_Private,
10295 E_Limited_Private_Type)
10299 elsif In_Private_Part (Current_Scope)
10300 and then Has_Private_Declaration (Typ)
10304 elsif In_Private_Part (Current_Scope) then
10306 ("pragma% only allowed for private type " &
10307 "declared in visible part", Arg1);
10311 ("pragma% only allowed for private type", Arg1);
10314 -- Note that the type has at least one invariant, and also that
10315 -- it has inheritable invariants if we have Invariant'Class.
10317 Set_Has_Invariants (Typ);
10319 if Class_Present (N) then
10320 Set_Has_Inheritable_Invariants (Typ);
10323 -- The remaining processing is simply to link the pragma on to
10324 -- the rep item chain, for processing when the type is frozen.
10325 -- This is accomplished by a call to Rep_Item_Too_Late.
10327 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10330 ----------------------
10331 -- Java_Constructor --
10332 ----------------------
10334 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10336 -- Also handles pragma CIL_Constructor
10338 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10339 Java_Constructor : declare
10340 Convention : Convention_Id;
10341 Def_Id : Entity_Id;
10342 Hom_Id : Entity_Id;
10344 This_Formal : Entity_Id;
10348 Check_Arg_Count (1);
10349 Check_Optional_Identifier (Arg1, Name_Entity);
10350 Check_Arg_Is_Local_Name (Arg1);
10352 Id := Get_Pragma_Arg (Arg1);
10353 Find_Program_Unit_Name (Id);
10355 -- If we did not find the name, we are done
10357 if Etype (Id) = Any_Type then
10361 -- Check wrong use of pragma in wrong VM target
10363 if VM_Target = No_VM then
10366 elsif VM_Target = CLI_Target
10367 and then Prag_Id = Pragma_Java_Constructor
10369 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10371 elsif VM_Target = JVM_Target
10372 and then Prag_Id = Pragma_CIL_Constructor
10374 Error_Pragma ("must use pragma 'Java_'Constructor");
10378 when Pragma_CIL_Constructor => Convention := Convention_CIL;
10379 when Pragma_Java_Constructor => Convention := Convention_Java;
10380 when others => null;
10383 Hom_Id := Entity (Id);
10385 -- Loop through homonyms
10388 Def_Id := Get_Base_Subprogram (Hom_Id);
10390 -- The constructor is required to be a function
10392 if Ekind (Def_Id) /= E_Function then
10393 if VM_Target = JVM_Target then
10395 ("pragma% requires function returning a " &
10396 "'Java access type", Def_Id);
10399 ("pragma% requires function returning a " &
10400 "'C'I'L access type", Def_Id);
10404 -- Check arguments: For tagged type the first formal must be
10405 -- named "this" and its type must be a named access type
10406 -- designating a class-wide tagged type that has convention
10407 -- CIL/Java. The first formal must also have a null default
10408 -- value. For example:
10410 -- type Typ is tagged ...
10411 -- type Ref is access all Typ;
10412 -- pragma Convention (CIL, Typ);
10414 -- function New_Typ (This : Ref) return Ref;
10415 -- function New_Typ (This : Ref; I : Integer) return Ref;
10416 -- pragma Cil_Constructor (New_Typ);
10418 -- Reason: The first formal must NOT be a primitive of the
10421 -- This rule also applies to constructors of delegates used
10422 -- to interface with standard target libraries. For example:
10424 -- type Delegate is access procedure ...
10425 -- pragma Import (CIL, Delegate, ...);
10427 -- function new_Delegate
10428 -- (This : Delegate := null; ... ) return Delegate;
10430 -- For value-types this rule does not apply.
10432 if not Is_Value_Type (Etype (Def_Id)) then
10433 if No (First_Formal (Def_Id)) then
10434 Error_Msg_Name_1 := Pname;
10435 Error_Msg_N ("% function must have parameters", Def_Id);
10439 -- In the JRE library we have several occurrences in which
10440 -- the "this" parameter is not the first formal.
10442 This_Formal := First_Formal (Def_Id);
10444 -- In the JRE library we have several occurrences in which
10445 -- the "this" parameter is not the first formal. Search for
10448 if VM_Target = JVM_Target then
10449 while Present (This_Formal)
10450 and then Get_Name_String (Chars (This_Formal)) /= "this"
10452 Next_Formal (This_Formal);
10455 if No (This_Formal) then
10456 This_Formal := First_Formal (Def_Id);
10460 -- Warning: The first parameter should be named "this".
10461 -- We temporarily allow it because we have the following
10462 -- case in the Java runtime (file s-osinte.ads) ???
10464 -- function new_Thread
10465 -- (Self_Id : System.Address) return Thread_Id;
10466 -- pragma Java_Constructor (new_Thread);
10468 if VM_Target = JVM_Target
10469 and then Get_Name_String (Chars (First_Formal (Def_Id)))
10471 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10475 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10476 Error_Msg_Name_1 := Pname;
10478 ("first formal of % function must be named `this`",
10479 Parent (This_Formal));
10481 elsif not Is_Access_Type (Etype (This_Formal)) then
10482 Error_Msg_Name_1 := Pname;
10484 ("first formal of % function must be an access type",
10485 Parameter_Type (Parent (This_Formal)));
10487 -- For delegates the type of the first formal must be a
10488 -- named access-to-subprogram type (see previous example)
10490 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10491 and then Ekind (Etype (This_Formal))
10492 /= E_Access_Subprogram_Type
10494 Error_Msg_Name_1 := Pname;
10496 ("first formal of % function must be a named access" &
10497 " to subprogram type",
10498 Parameter_Type (Parent (This_Formal)));
10500 -- Warning: We should reject anonymous access types because
10501 -- the constructor must not be handled as a primitive of the
10502 -- tagged type. We temporarily allow it because this profile
10503 -- is currently generated by cil2ada???
10505 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10506 and then not Ekind_In (Etype (This_Formal),
10508 E_General_Access_Type,
10509 E_Anonymous_Access_Type)
10511 Error_Msg_Name_1 := Pname;
10513 ("first formal of % function must be a named access" &
10515 Parameter_Type (Parent (This_Formal)));
10517 elsif Atree.Convention
10518 (Designated_Type (Etype (This_Formal))) /= Convention
10520 Error_Msg_Name_1 := Pname;
10522 if Convention = Convention_Java then
10524 ("pragma% requires convention 'Cil in designated" &
10526 Parameter_Type (Parent (This_Formal)));
10529 ("pragma% requires convention 'Java in designated" &
10531 Parameter_Type (Parent (This_Formal)));
10534 elsif No (Expression (Parent (This_Formal)))
10535 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10537 Error_Msg_Name_1 := Pname;
10539 ("pragma% requires first formal with default `null`",
10540 Parameter_Type (Parent (This_Formal)));
10544 -- Check result type: the constructor must be a function
10546 -- * a value type (only allowed in the CIL compiler)
10547 -- * an access-to-subprogram type with convention Java/CIL
10548 -- * an access-type designating a type that has convention
10551 if Is_Value_Type (Etype (Def_Id)) then
10554 -- Access-to-subprogram type with convention Java/CIL
10556 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10557 if Atree.Convention (Etype (Def_Id)) /= Convention then
10558 if Convention = Convention_Java then
10560 ("pragma% requires function returning a " &
10561 "'Java access type", Arg1);
10563 pragma Assert (Convention = Convention_CIL);
10565 ("pragma% requires function returning a " &
10566 "'C'I'L access type", Arg1);
10570 elsif Ekind (Etype (Def_Id)) in Access_Kind then
10571 if not Ekind_In (Etype (Def_Id), E_Access_Type,
10572 E_General_Access_Type)
10575 (Designated_Type (Etype (Def_Id))) /= Convention
10577 Error_Msg_Name_1 := Pname;
10579 if Convention = Convention_Java then
10581 ("pragma% requires function returning a named" &
10582 "'Java access type", Arg1);
10585 ("pragma% requires function returning a named" &
10586 "'C'I'L access type", Arg1);
10591 Set_Is_Constructor (Def_Id);
10592 Set_Convention (Def_Id, Convention);
10593 Set_Is_Imported (Def_Id);
10595 exit when From_Aspect_Specification (N);
10596 Hom_Id := Homonym (Hom_Id);
10598 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10600 end Java_Constructor;
10602 ----------------------
10603 -- Java_Interface --
10604 ----------------------
10606 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
10608 when Pragma_Java_Interface => Java_Interface : declare
10614 Check_Arg_Count (1);
10615 Check_Optional_Identifier (Arg1, Name_Entity);
10616 Check_Arg_Is_Local_Name (Arg1);
10618 Arg := Get_Pragma_Arg (Arg1);
10621 if Etype (Arg) = Any_Type then
10625 if not Is_Entity_Name (Arg)
10626 or else not Is_Type (Entity (Arg))
10628 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10631 Typ := Underlying_Type (Entity (Arg));
10633 -- For now simply check some of the semantic constraints on the
10634 -- type. This currently leaves out some restrictions on interface
10635 -- types, namely that the parent type must be java.lang.Object.Typ
10636 -- and that all primitives of the type should be declared
10639 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10640 Error_Pragma_Arg ("pragma% requires an abstract "
10641 & "tagged type", Arg1);
10643 elsif not Has_Discriminants (Typ)
10644 or else Ekind (Etype (First_Discriminant (Typ)))
10645 /= E_Anonymous_Access_Type
10647 not Is_Class_Wide_Type
10648 (Designated_Type (Etype (First_Discriminant (Typ))))
10651 ("type must have a class-wide access discriminant", Arg1);
10653 end Java_Interface;
10659 -- pragma Keep_Names ([On => ] local_NAME);
10661 when Pragma_Keep_Names => Keep_Names : declare
10666 Check_Arg_Count (1);
10667 Check_Optional_Identifier (Arg1, Name_On);
10668 Check_Arg_Is_Local_Name (Arg1);
10670 Arg := Get_Pragma_Arg (Arg1);
10673 if Etype (Arg) = Any_Type then
10677 if not Is_Entity_Name (Arg)
10678 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10681 ("pragma% requires a local enumeration type", Arg1);
10684 Set_Discard_Names (Entity (Arg), False);
10691 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10693 when Pragma_License =>
10695 Check_Arg_Count (1);
10696 Check_No_Identifiers;
10697 Check_Valid_Configuration_Pragma;
10698 Check_Arg_Is_Identifier (Arg1);
10701 Sind : constant Source_File_Index :=
10702 Source_Index (Current_Sem_Unit);
10705 case Chars (Get_Pragma_Arg (Arg1)) is
10707 Set_License (Sind, GPL);
10709 when Name_Modified_GPL =>
10710 Set_License (Sind, Modified_GPL);
10712 when Name_Restricted =>
10713 Set_License (Sind, Restricted);
10715 when Name_Unrestricted =>
10716 Set_License (Sind, Unrestricted);
10719 Error_Pragma_Arg ("invalid license name", Arg1);
10727 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10729 when Pragma_Link_With => Link_With : declare
10735 if Operating_Mode = Generate_Code
10736 and then In_Extended_Main_Source_Unit (N)
10738 Check_At_Least_N_Arguments (1);
10739 Check_No_Identifiers;
10740 Check_Is_In_Decl_Part_Or_Package_Spec;
10741 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10745 while Present (Arg) loop
10746 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10748 -- Store argument, converting sequences of spaces to a
10749 -- single null character (this is one of the differences
10750 -- in processing between Link_With and Linker_Options).
10752 Arg_Store : declare
10753 C : constant Char_Code := Get_Char_Code (' ');
10754 S : constant String_Id :=
10755 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10756 L : constant Nat := String_Length (S);
10759 procedure Skip_Spaces;
10760 -- Advance F past any spaces
10766 procedure Skip_Spaces is
10768 while F <= L and then Get_String_Char (S, F) = C loop
10773 -- Start of processing for Arg_Store
10776 Skip_Spaces; -- skip leading spaces
10778 -- Loop through characters, changing any embedded
10779 -- sequence of spaces to a single null character (this
10780 -- is how Link_With/Linker_Options differ)
10783 if Get_String_Char (S, F) = C then
10786 Store_String_Char (ASCII.NUL);
10789 Store_String_Char (Get_String_Char (S, F));
10797 if Present (Arg) then
10798 Store_String_Char (ASCII.NUL);
10802 Store_Linker_Option_String (End_String);
10810 -- pragma Linker_Alias (
10811 -- [Entity =>] LOCAL_NAME
10812 -- [Target =>] static_string_EXPRESSION);
10814 when Pragma_Linker_Alias =>
10816 Check_Arg_Order ((Name_Entity, Name_Target));
10817 Check_Arg_Count (2);
10818 Check_Optional_Identifier (Arg1, Name_Entity);
10819 Check_Optional_Identifier (Arg2, Name_Target);
10820 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10821 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10823 -- The only processing required is to link this item on to the
10824 -- list of rep items for the given entity. This is accomplished
10825 -- by the call to Rep_Item_Too_Late (when no error is detected
10826 -- and False is returned).
10828 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10831 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10834 ------------------------
10835 -- Linker_Constructor --
10836 ------------------------
10838 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10840 -- Code is shared with Linker_Destructor
10842 -----------------------
10843 -- Linker_Destructor --
10844 -----------------------
10846 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10848 when Pragma_Linker_Constructor |
10849 Pragma_Linker_Destructor =>
10850 Linker_Constructor : declare
10856 Check_Arg_Count (1);
10857 Check_No_Identifiers;
10858 Check_Arg_Is_Local_Name (Arg1);
10859 Arg1_X := Get_Pragma_Arg (Arg1);
10861 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10863 if not Is_Library_Level_Entity (Proc) then
10865 ("argument for pragma% must be library level entity", Arg1);
10868 -- The only processing required is to link this item on to the
10869 -- list of rep items for the given entity. This is accomplished
10870 -- by the call to Rep_Item_Too_Late (when no error is detected
10871 -- and False is returned).
10873 if Rep_Item_Too_Late (Proc, N) then
10876 Set_Has_Gigi_Rep_Item (Proc);
10878 end Linker_Constructor;
10880 --------------------
10881 -- Linker_Options --
10882 --------------------
10884 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10886 when Pragma_Linker_Options => Linker_Options : declare
10890 Check_Ada_83_Warning;
10891 Check_No_Identifiers;
10892 Check_Arg_Count (1);
10893 Check_Is_In_Decl_Part_Or_Package_Spec;
10894 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10895 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10898 while Present (Arg) loop
10899 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10900 Store_String_Char (ASCII.NUL);
10902 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10906 if Operating_Mode = Generate_Code
10907 and then In_Extended_Main_Source_Unit (N)
10909 Store_Linker_Option_String (End_String);
10911 end Linker_Options;
10913 --------------------
10914 -- Linker_Section --
10915 --------------------
10917 -- pragma Linker_Section (
10918 -- [Entity =>] LOCAL_NAME
10919 -- [Section =>] static_string_EXPRESSION);
10921 when Pragma_Linker_Section =>
10923 Check_Arg_Order ((Name_Entity, Name_Section));
10924 Check_Arg_Count (2);
10925 Check_Optional_Identifier (Arg1, Name_Entity);
10926 Check_Optional_Identifier (Arg2, Name_Section);
10927 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10928 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10930 -- This pragma applies only to objects
10932 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10933 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10936 -- The only processing required is to link this item on to the
10937 -- list of rep items for the given entity. This is accomplished
10938 -- by the call to Rep_Item_Too_Late (when no error is detected
10939 -- and False is returned).
10941 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10944 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10951 -- pragma List (On | Off)
10953 -- There is nothing to do here, since we did all the processing for
10954 -- this pragma in Par.Prag (so that it works properly even in syntax
10957 when Pragma_List =>
10960 --------------------
10961 -- Locking_Policy --
10962 --------------------
10964 -- pragma Locking_Policy (policy_IDENTIFIER);
10966 when Pragma_Locking_Policy => declare
10967 subtype LP_Range is Name_Id
10968 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
10972 Check_Ada_83_Warning;
10973 Check_Arg_Count (1);
10974 Check_No_Identifiers;
10975 Check_Arg_Is_Locking_Policy (Arg1);
10976 Check_Valid_Configuration_Pragma;
10977 LP_Val := Chars (Get_Pragma_Arg (Arg1));
10980 when Name_Ceiling_Locking => LP := 'C';
10981 when Name_Inheritance_Locking => LP := 'I';
10982 when Name_Concurrent_Readers_Locking => LP := 'R';
10985 if Locking_Policy /= ' '
10986 and then Locking_Policy /= LP
10988 Error_Msg_Sloc := Locking_Policy_Sloc;
10989 Error_Pragma ("locking policy incompatible with policy#");
10991 -- Set new policy, but always preserve System_Location since we
10992 -- like the error message with the run time name.
10995 Locking_Policy := LP;
10997 if Locking_Policy_Sloc /= System_Location then
10998 Locking_Policy_Sloc := Loc;
11007 -- pragma Long_Float (D_Float | G_Float);
11009 when Pragma_Long_Float => Long_Float : declare
11012 Check_Valid_Configuration_Pragma;
11013 Check_Arg_Count (1);
11014 Check_No_Identifier (Arg1);
11015 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
11017 if not OpenVMS_On_Target then
11018 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
11023 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
11024 if Opt.Float_Format_Long = 'G' then
11026 ("G_Float previously specified", Arg1);
11028 elsif Current_Sem_Unit /= Main_Unit
11029 and then Opt.Float_Format_Long /= 'D'
11032 ("main unit not compiled with pragma Long_Float (D_Float)",
11033 "\pragma% must be used consistently for whole partition",
11037 Opt.Float_Format_Long := 'D';
11040 -- G_Float case (this is the default, does not need overriding)
11043 if Opt.Float_Format_Long = 'D' then
11044 Error_Pragma ("D_Float previously specified");
11046 elsif Current_Sem_Unit /= Main_Unit
11047 and then Opt.Float_Format_Long /= 'G'
11050 ("main unit not compiled with pragma Long_Float (G_Float)",
11051 "\pragma% must be used consistently for whole partition",
11055 Opt.Float_Format_Long := 'G';
11059 Set_Standard_Fpt_Formats;
11062 -----------------------
11063 -- Machine_Attribute --
11064 -----------------------
11066 -- pragma Machine_Attribute (
11067 -- [Entity =>] LOCAL_NAME,
11068 -- [Attribute_Name =>] static_string_EXPRESSION
11069 -- [, [Info =>] static_EXPRESSION] );
11071 when Pragma_Machine_Attribute => Machine_Attribute : declare
11072 Def_Id : Entity_Id;
11076 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
11078 if Arg_Count = 3 then
11079 Check_Optional_Identifier (Arg3, Name_Info);
11080 Check_Arg_Is_Static_Expression (Arg3);
11082 Check_Arg_Count (2);
11085 Check_Optional_Identifier (Arg1, Name_Entity);
11086 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
11087 Check_Arg_Is_Local_Name (Arg1);
11088 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11089 Def_Id := Entity (Get_Pragma_Arg (Arg1));
11091 if Is_Access_Type (Def_Id) then
11092 Def_Id := Designated_Type (Def_Id);
11095 if Rep_Item_Too_Early (Def_Id, N) then
11099 Def_Id := Underlying_Type (Def_Id);
11101 -- The only processing required is to link this item on to the
11102 -- list of rep items for the given entity. This is accomplished
11103 -- by the call to Rep_Item_Too_Late (when no error is detected
11104 -- and False is returned).
11106 if Rep_Item_Too_Late (Def_Id, N) then
11109 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11111 end Machine_Attribute;
11118 -- (MAIN_OPTION [, MAIN_OPTION]);
11121 -- [STACK_SIZE =>] static_integer_EXPRESSION
11122 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
11123 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
11125 when Pragma_Main => Main : declare
11126 Args : Args_List (1 .. 3);
11127 Names : constant Name_List (1 .. 3) := (
11129 Name_Task_Stack_Size_Default,
11130 Name_Time_Slicing_Enabled);
11136 Gather_Associations (Names, Args);
11138 for J in 1 .. 2 loop
11139 if Present (Args (J)) then
11140 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11144 if Present (Args (3)) then
11145 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
11149 while Present (Nod) loop
11150 if Nkind (Nod) = N_Pragma
11151 and then Pragma_Name (Nod) = Name_Main
11153 Error_Msg_Name_1 := Pname;
11154 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11165 -- pragma Main_Storage
11166 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
11168 -- MAIN_STORAGE_OPTION ::=
11169 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
11170 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
11172 when Pragma_Main_Storage => Main_Storage : declare
11173 Args : Args_List (1 .. 2);
11174 Names : constant Name_List (1 .. 2) := (
11175 Name_Working_Storage,
11182 Gather_Associations (Names, Args);
11184 for J in 1 .. 2 loop
11185 if Present (Args (J)) then
11186 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11190 Check_In_Main_Program;
11193 while Present (Nod) loop
11194 if Nkind (Nod) = N_Pragma
11195 and then Pragma_Name (Nod) = Name_Main_Storage
11197 Error_Msg_Name_1 := Pname;
11198 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11209 -- pragma Memory_Size (NUMERIC_LITERAL)
11211 when Pragma_Memory_Size =>
11214 -- Memory size is simply ignored
11216 Check_No_Identifiers;
11217 Check_Arg_Count (1);
11218 Check_Arg_Is_Integer_Literal (Arg1);
11226 -- The only correct use of this pragma is on its own in a file, in
11227 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
11228 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
11229 -- check for a file containing nothing but a No_Body pragma). If we
11230 -- attempt to process it during normal semantics processing, it means
11231 -- it was misplaced.
11233 when Pragma_No_Body =>
11241 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
11243 when Pragma_No_Return => No_Return : declare
11251 Check_At_Least_N_Arguments (1);
11253 -- Loop through arguments of pragma
11256 while Present (Arg) loop
11257 Check_Arg_Is_Local_Name (Arg);
11258 Id := Get_Pragma_Arg (Arg);
11261 if not Is_Entity_Name (Id) then
11262 Error_Pragma_Arg ("entity name required", Arg);
11265 if Etype (Id) = Any_Type then
11269 -- Loop to find matching procedures
11274 and then Scope (E) = Current_Scope
11276 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11279 -- Set flag on any alias as well
11281 if Is_Overloadable (E) and then Present (Alias (E)) then
11282 Set_No_Return (Alias (E));
11288 exit when From_Aspect_Specification (N);
11293 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11304 -- pragma No_Run_Time;
11306 -- Note: this pragma is retained for backwards compatibility. See
11307 -- body of Rtsfind for full details on its handling.
11309 when Pragma_No_Run_Time =>
11311 Check_Valid_Configuration_Pragma;
11312 Check_Arg_Count (0);
11314 No_Run_Time_Mode := True;
11315 Configurable_Run_Time_Mode := True;
11317 -- Set Duration to 32 bits if word size is 32
11319 if Ttypes.System_Word_Size = 32 then
11320 Duration_32_Bits_On_Target := True;
11323 -- Set appropriate restrictions
11325 Set_Restriction (No_Finalization, N);
11326 Set_Restriction (No_Exception_Handlers, N);
11327 Set_Restriction (Max_Tasks, N, 0);
11328 Set_Restriction (No_Tasking, N);
11330 ------------------------
11331 -- No_Strict_Aliasing --
11332 ------------------------
11334 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11336 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11341 Check_At_Most_N_Arguments (1);
11343 if Arg_Count = 0 then
11344 Check_Valid_Configuration_Pragma;
11345 Opt.No_Strict_Aliasing := True;
11348 Check_Optional_Identifier (Arg2, Name_Entity);
11349 Check_Arg_Is_Local_Name (Arg1);
11350 E_Id := Entity (Get_Pragma_Arg (Arg1));
11352 if E_Id = Any_Type then
11354 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11355 Error_Pragma_Arg ("pragma% requires access type", Arg1);
11358 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11360 end No_Strict_Aliasing;
11362 -----------------------
11363 -- Normalize_Scalars --
11364 -----------------------
11366 -- pragma Normalize_Scalars;
11368 when Pragma_Normalize_Scalars =>
11369 Check_Ada_83_Warning;
11370 Check_Arg_Count (0);
11371 Check_Valid_Configuration_Pragma;
11373 -- Normalize_Scalars creates false positives in CodePeer, and
11374 -- incorrect negative results in Alfa mode, so ignore this pragma
11377 if not (CodePeer_Mode or Alfa_Mode) then
11378 Normalize_Scalars := True;
11379 Init_Or_Norm_Scalars := True;
11386 -- pragma Obsolescent;
11388 -- pragma Obsolescent (
11389 -- [Message =>] static_string_EXPRESSION
11390 -- [,[Version =>] Ada_05]]);
11392 -- pragma Obsolescent (
11393 -- [Entity =>] NAME
11394 -- [,[Message =>] static_string_EXPRESSION
11395 -- [,[Version =>] Ada_05]] );
11397 when Pragma_Obsolescent => Obsolescent : declare
11401 procedure Set_Obsolescent (E : Entity_Id);
11402 -- Given an entity Ent, mark it as obsolescent if appropriate
11404 ---------------------
11405 -- Set_Obsolescent --
11406 ---------------------
11408 procedure Set_Obsolescent (E : Entity_Id) is
11417 -- Entity name was given
11419 if Present (Ename) then
11421 -- If entity name matches, we are fine. Save entity in
11422 -- pragma argument, for ASIS use.
11424 if Chars (Ename) = Chars (Ent) then
11425 Set_Entity (Ename, Ent);
11426 Generate_Reference (Ent, Ename);
11428 -- If entity name does not match, only possibility is an
11429 -- enumeration literal from an enumeration type declaration.
11431 elsif Ekind (Ent) /= E_Enumeration_Type then
11433 ("pragma % entity name does not match declaration");
11436 Ent := First_Literal (E);
11440 ("pragma % entity name does not match any " &
11441 "enumeration literal");
11443 elsif Chars (Ent) = Chars (Ename) then
11444 Set_Entity (Ename, Ent);
11445 Generate_Reference (Ent, Ename);
11449 Ent := Next_Literal (Ent);
11455 -- Ent points to entity to be marked
11457 if Arg_Count >= 1 then
11459 -- Deal with static string argument
11461 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11462 S := Strval (Get_Pragma_Arg (Arg1));
11464 for J in 1 .. String_Length (S) loop
11465 if not In_Character_Range (Get_String_Char (S, J)) then
11467 ("pragma% argument does not allow wide characters",
11472 Obsolescent_Warnings.Append
11473 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11475 -- Check for Ada_05 parameter
11477 if Arg_Count /= 1 then
11478 Check_Arg_Count (2);
11481 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11484 Check_Arg_Is_Identifier (Argx);
11486 if Chars (Argx) /= Name_Ada_05 then
11487 Error_Msg_Name_2 := Name_Ada_05;
11489 ("only allowed argument for pragma% is %", Argx);
11492 if Ada_Version_Explicit < Ada_2005
11493 or else not Warn_On_Ada_2005_Compatibility
11501 -- Set flag if pragma active
11504 Set_Is_Obsolescent (Ent);
11508 end Set_Obsolescent;
11510 -- Start of processing for pragma Obsolescent
11515 Check_At_Most_N_Arguments (3);
11517 -- See if first argument specifies an entity name
11521 (Chars (Arg1) = Name_Entity
11523 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11525 N_Operator_Symbol))
11527 Ename := Get_Pragma_Arg (Arg1);
11529 -- Eliminate first argument, so we can share processing
11533 Arg_Count := Arg_Count - 1;
11535 -- No Entity name argument given
11541 if Arg_Count >= 1 then
11542 Check_Optional_Identifier (Arg1, Name_Message);
11544 if Arg_Count = 2 then
11545 Check_Optional_Identifier (Arg2, Name_Version);
11549 -- Get immediately preceding declaration
11552 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11556 -- Cases where we do not follow anything other than another pragma
11560 -- First case: library level compilation unit declaration with
11561 -- the pragma immediately following the declaration.
11563 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11565 (Defining_Entity (Unit (Parent (Parent (N)))));
11568 -- Case 2: library unit placement for package
11572 Ent : constant Entity_Id := Find_Lib_Unit_Name;
11574 if Is_Package_Or_Generic_Package (Ent) then
11575 Set_Obsolescent (Ent);
11581 -- Cases where we must follow a declaration
11584 if Nkind (Decl) not in N_Declaration
11585 and then Nkind (Decl) not in N_Later_Decl_Item
11586 and then Nkind (Decl) not in N_Generic_Declaration
11587 and then Nkind (Decl) not in N_Renaming_Declaration
11590 ("pragma% misplaced, "
11591 & "must immediately follow a declaration");
11594 Set_Obsolescent (Defining_Entity (Decl));
11604 -- pragma Optimize (Time | Space | Off);
11606 -- The actual check for optimize is done in Gigi. Note that this
11607 -- pragma does not actually change the optimization setting, it
11608 -- simply checks that it is consistent with the pragma.
11610 when Pragma_Optimize =>
11611 Check_No_Identifiers;
11612 Check_Arg_Count (1);
11613 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11615 ------------------------
11616 -- Optimize_Alignment --
11617 ------------------------
11619 -- pragma Optimize_Alignment (Time | Space | Off);
11621 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11623 Check_No_Identifiers;
11624 Check_Arg_Count (1);
11625 Check_Valid_Configuration_Pragma;
11628 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11632 Opt.Optimize_Alignment := 'T';
11634 Opt.Optimize_Alignment := 'S';
11636 Opt.Optimize_Alignment := 'O';
11638 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11642 -- Set indication that mode is set locally. If we are in fact in a
11643 -- configuration pragma file, this setting is harmless since the
11644 -- switch will get reset anyway at the start of each unit.
11646 Optimize_Alignment_Local := True;
11647 end Optimize_Alignment;
11653 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11655 when Pragma_Ordered => Ordered : declare
11656 Assoc : constant Node_Id := Arg1;
11662 Check_No_Identifiers;
11663 Check_Arg_Count (1);
11664 Check_Arg_Is_Local_Name (Arg1);
11666 Type_Id := Get_Pragma_Arg (Assoc);
11667 Find_Type (Type_Id);
11668 Typ := Entity (Type_Id);
11670 if Typ = Any_Type then
11673 Typ := Underlying_Type (Typ);
11676 if not Is_Enumeration_Type (Typ) then
11677 Error_Pragma ("pragma% must specify enumeration type");
11680 Check_First_Subtype (Arg1);
11681 Set_Has_Pragma_Ordered (Base_Type (Typ));
11688 -- pragma Pack (first_subtype_LOCAL_NAME);
11690 when Pragma_Pack => Pack : declare
11691 Assoc : constant Node_Id := Arg1;
11695 Ignore : Boolean := False;
11698 Check_No_Identifiers;
11699 Check_Arg_Count (1);
11700 Check_Arg_Is_Local_Name (Arg1);
11702 Type_Id := Get_Pragma_Arg (Assoc);
11703 Find_Type (Type_Id);
11704 Typ := Entity (Type_Id);
11707 or else Rep_Item_Too_Early (Typ, N)
11711 Typ := Underlying_Type (Typ);
11714 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11715 Error_Pragma ("pragma% must specify array or record type");
11718 Check_First_Subtype (Arg1);
11719 Check_Duplicate_Pragma (Typ);
11723 if Is_Array_Type (Typ) then
11724 Ctyp := Component_Type (Typ);
11726 -- Ignore pack that does nothing
11728 if Known_Static_Esize (Ctyp)
11729 and then Known_Static_RM_Size (Ctyp)
11730 and then Esize (Ctyp) = RM_Size (Ctyp)
11731 and then Addressable (Esize (Ctyp))
11736 -- Process OK pragma Pack. Note that if there is a separate
11737 -- component clause present, the Pack will be cancelled. This
11738 -- processing is in Freeze.
11740 if not Rep_Item_Too_Late (Typ, N) then
11742 -- In the context of static code analysis, we do not need
11743 -- complex front-end expansions related to pragma Pack,
11744 -- so disable handling of pragma Pack in these cases.
11746 if CodePeer_Mode or Alfa_Mode then
11749 -- Don't attempt any packing for VM targets. We possibly
11750 -- could deal with some cases of array bit-packing, but we
11751 -- don't bother, since this is not a typical kind of
11752 -- representation in the VM context anyway (and would not
11753 -- for example work nicely with the debugger).
11755 elsif VM_Target /= No_VM then
11756 if not GNAT_Mode then
11758 ("?pragma% ignored in this configuration");
11761 -- Normal case where we do the pack action
11765 Set_Is_Packed (Base_Type (Typ));
11766 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11769 Set_Has_Pragma_Pack (Base_Type (Typ));
11773 -- For record types, the pack is always effective
11775 else pragma Assert (Is_Record_Type (Typ));
11776 if not Rep_Item_Too_Late (Typ, N) then
11778 -- Ignore pack request with warning in VM mode (skip warning
11779 -- if we are compiling GNAT run time library).
11781 if VM_Target /= No_VM then
11782 if not GNAT_Mode then
11784 ("?pragma% ignored in this configuration");
11787 -- Normal case of pack request active
11790 Set_Is_Packed (Base_Type (Typ));
11791 Set_Has_Pragma_Pack (Base_Type (Typ));
11792 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11804 -- There is nothing to do here, since we did all the processing for
11805 -- this pragma in Par.Prag (so that it works properly even in syntax
11808 when Pragma_Page =>
11815 -- pragma Passive [(PASSIVE_FORM)];
11817 -- PASSIVE_FORM ::= Semaphore | No
11819 when Pragma_Passive =>
11822 if Nkind (Parent (N)) /= N_Task_Definition then
11823 Error_Pragma ("pragma% must be within task definition");
11826 if Arg_Count /= 0 then
11827 Check_Arg_Count (1);
11828 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11831 ----------------------------------
11832 -- Preelaborable_Initialization --
11833 ----------------------------------
11835 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11837 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11842 Check_Arg_Count (1);
11843 Check_No_Identifiers;
11844 Check_Arg_Is_Identifier (Arg1);
11845 Check_Arg_Is_Local_Name (Arg1);
11846 Check_First_Subtype (Arg1);
11847 Ent := Entity (Get_Pragma_Arg (Arg1));
11849 if not (Is_Private_Type (Ent)
11851 Is_Protected_Type (Ent)
11853 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11856 ("pragma % can only be applied to private, formal derived or "
11857 & "protected type",
11861 -- Give an error if the pragma is applied to a protected type that
11862 -- does not qualify (due to having entries, or due to components
11863 -- that do not qualify).
11865 if Is_Protected_Type (Ent)
11866 and then not Has_Preelaborable_Initialization (Ent)
11869 ("protected type & does not have preelaborable " &
11870 "initialization", Ent);
11872 -- Otherwise mark the type as definitely having preelaborable
11876 Set_Known_To_Have_Preelab_Init (Ent);
11879 if Has_Pragma_Preelab_Init (Ent)
11880 and then Warn_On_Redundant_Constructs
11882 Error_Pragma ("?duplicate pragma%!");
11884 Set_Has_Pragma_Preelab_Init (Ent);
11888 --------------------
11889 -- Persistent_BSS --
11890 --------------------
11892 -- pragma Persistent_BSS [(object_NAME)];
11894 when Pragma_Persistent_BSS => Persistent_BSS : declare
11901 Check_At_Most_N_Arguments (1);
11903 -- Case of application to specific object (one argument)
11905 if Arg_Count = 1 then
11906 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11908 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11910 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11913 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11916 Ent := Entity (Get_Pragma_Arg (Arg1));
11917 Decl := Parent (Ent);
11919 if Rep_Item_Too_Late (Ent, N) then
11923 if Present (Expression (Decl)) then
11925 ("object for pragma% cannot have initialization", Arg1);
11928 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11930 ("object type for pragma% is not potentially persistent",
11934 Check_Duplicate_Pragma (Ent);
11937 Make_Linker_Section_Pragma
11938 (Ent, Sloc (N), ".persistent.bss");
11939 Insert_After (N, Prag);
11942 -- Case of use as configuration pragma with no arguments
11945 Check_Valid_Configuration_Pragma;
11946 Persistent_BSS_Mode := True;
11948 end Persistent_BSS;
11954 -- pragma Polling (ON | OFF);
11956 when Pragma_Polling =>
11958 Check_Arg_Count (1);
11959 Check_No_Identifiers;
11960 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11961 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11963 -------------------
11964 -- Postcondition --
11965 -------------------
11967 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
11968 -- [,[Message =>] String_EXPRESSION]);
11970 when Pragma_Postcondition => Postcondition : declare
11972 pragma Warnings (Off, In_Body);
11976 Check_At_Least_N_Arguments (1);
11977 Check_At_Most_N_Arguments (2);
11978 Check_Optional_Identifier (Arg1, Name_Check);
11980 -- All we need to do here is call the common check procedure,
11981 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11983 Check_Precondition_Postcondition (In_Body);
11990 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
11991 -- [,[Message =>] String_EXPRESSION]);
11993 when Pragma_Precondition => Precondition : declare
11998 Check_At_Least_N_Arguments (1);
11999 Check_At_Most_N_Arguments (2);
12000 Check_Optional_Identifier (Arg1, Name_Check);
12001 Check_Precondition_Postcondition (In_Body);
12003 -- If in spec, nothing more to do. If in body, then we convert the
12004 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
12005 -- this whether or not precondition checks are enabled. That works
12006 -- fine since pragma Check will do this check, and will also
12007 -- analyze the condition itself in the proper context.
12012 Chars => Name_Check,
12013 Pragma_Argument_Associations => New_List (
12014 Make_Pragma_Argument_Association (Loc,
12015 Expression => Make_Identifier (Loc, Name_Precondition)),
12017 Make_Pragma_Argument_Association (Sloc (Arg1),
12018 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
12020 if Arg_Count = 2 then
12021 Append_To (Pragma_Argument_Associations (N),
12022 Make_Pragma_Argument_Association (Sloc (Arg2),
12023 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
12034 -- pragma Predicate
12035 -- ([Entity =>] type_LOCAL_NAME,
12036 -- [Check =>] EXPRESSION);
12038 when Pragma_Predicate => Predicate : declare
12043 pragma Unreferenced (Discard);
12047 Check_Arg_Count (2);
12048 Check_Optional_Identifier (Arg1, Name_Entity);
12049 Check_Optional_Identifier (Arg2, Name_Check);
12051 Check_Arg_Is_Local_Name (Arg1);
12053 Type_Id := Get_Pragma_Arg (Arg1);
12054 Find_Type (Type_Id);
12055 Typ := Entity (Type_Id);
12057 if Typ = Any_Type then
12061 -- The remaining processing is simply to link the pragma on to
12062 -- the rep item chain, for processing when the type is frozen.
12063 -- This is accomplished by a call to Rep_Item_Too_Late. We also
12064 -- mark the type as having predicates.
12066 Set_Has_Predicates (Typ);
12067 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12074 -- pragma Preelaborate [(library_unit_NAME)];
12076 -- Set the flag Is_Preelaborated of program unit name entity
12078 when Pragma_Preelaborate => Preelaborate : declare
12079 Pa : constant Node_Id := Parent (N);
12080 Pk : constant Node_Kind := Nkind (Pa);
12084 Check_Ada_83_Warning;
12085 Check_Valid_Library_Unit_Pragma;
12087 if Nkind (N) = N_Null_Statement then
12091 Ent := Find_Lib_Unit_Name;
12092 Check_Duplicate_Pragma (Ent);
12094 -- This filters out pragmas inside generic parent then
12095 -- show up inside instantiation
12098 and then not (Pk = N_Package_Specification
12099 and then Present (Generic_Parent (Pa)))
12101 if not Debug_Flag_U then
12102 Set_Is_Preelaborated (Ent);
12103 Set_Suppress_Elaboration_Warnings (Ent);
12108 ---------------------
12109 -- Preelaborate_05 --
12110 ---------------------
12112 -- pragma Preelaborate_05 [(library_unit_NAME)];
12114 -- This pragma is useable only in GNAT_Mode, where it is used like
12115 -- pragma Preelaborate but it is only effective in Ada 2005 mode
12116 -- (otherwise it is ignored). This is used to implement AI-362 which
12117 -- recategorizes some run-time packages in Ada 2005 mode.
12119 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
12124 Check_Valid_Library_Unit_Pragma;
12126 if not GNAT_Mode then
12127 Error_Pragma ("pragma% only available in GNAT mode");
12130 if Nkind (N) = N_Null_Statement then
12134 -- This is one of the few cases where we need to test the value of
12135 -- Ada_Version_Explicit rather than Ada_Version (which is always
12136 -- set to Ada_2012 in a predefined unit), we need to know the
12137 -- explicit version set to know if this pragma is active.
12139 if Ada_Version_Explicit >= Ada_2005 then
12140 Ent := Find_Lib_Unit_Name;
12141 Set_Is_Preelaborated (Ent);
12142 Set_Suppress_Elaboration_Warnings (Ent);
12144 end Preelaborate_05;
12150 -- pragma Priority (EXPRESSION);
12152 when Pragma_Priority => Priority : declare
12153 P : constant Node_Id := Parent (N);
12157 Check_No_Identifiers;
12158 Check_Arg_Count (1);
12162 if Nkind (P) = N_Subprogram_Body then
12163 Check_In_Main_Program;
12165 Arg := Get_Pragma_Arg (Arg1);
12166 Analyze_And_Resolve (Arg, Standard_Integer);
12170 if not Is_Static_Expression (Arg) then
12171 Flag_Non_Static_Expr
12172 ("main subprogram priority is not static!", Arg);
12175 -- If constraint error, then we already signalled an error
12177 elsif Raises_Constraint_Error (Arg) then
12180 -- Otherwise check in range
12184 Val : constant Uint := Expr_Value (Arg);
12188 or else Val > Expr_Value (Expression
12189 (Parent (RTE (RE_Max_Priority))))
12192 ("main subprogram priority is out of range", Arg1);
12198 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12200 -- Load an arbitrary entity from System.Tasking to make sure
12201 -- this package is implicitly with'ed, since we need to have
12202 -- the tasking run-time active for the pragma Priority to have
12206 Discard : Entity_Id;
12207 pragma Warnings (Off, Discard);
12209 Discard := RTE (RE_Task_List);
12212 -- Task or Protected, must be of type Integer
12214 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12215 Arg := Get_Pragma_Arg (Arg1);
12217 -- The expression must be analyzed in the special manner
12218 -- described in "Handling of Default and Per-Object
12219 -- Expressions" in sem.ads.
12221 Preanalyze_Spec_Expression (Arg, Standard_Integer);
12223 if not Is_Static_Expression (Arg) then
12224 Check_Restriction (Static_Priorities, Arg);
12227 -- Anything else is incorrect
12233 if Has_Pragma_Priority (P) then
12234 Error_Pragma ("duplicate pragma% not allowed");
12236 Set_Has_Pragma_Priority (P, True);
12238 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12239 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12240 -- exp_ch9 should use this ???
12245 -----------------------------------
12246 -- Priority_Specific_Dispatching --
12247 -----------------------------------
12249 -- pragma Priority_Specific_Dispatching (
12250 -- policy_IDENTIFIER,
12251 -- first_priority_EXPRESSION,
12252 -- last_priority_EXPRESSION);
12254 when Pragma_Priority_Specific_Dispatching =>
12255 Priority_Specific_Dispatching : declare
12256 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12257 -- This is the entity System.Any_Priority;
12260 Lower_Bound : Node_Id;
12261 Upper_Bound : Node_Id;
12267 Check_Arg_Count (3);
12268 Check_No_Identifiers;
12269 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12270 Check_Valid_Configuration_Pragma;
12271 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12272 DP := Fold_Upper (Name_Buffer (1));
12274 Lower_Bound := Get_Pragma_Arg (Arg2);
12275 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12276 Lower_Val := Expr_Value (Lower_Bound);
12278 Upper_Bound := Get_Pragma_Arg (Arg3);
12279 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12280 Upper_Val := Expr_Value (Upper_Bound);
12282 -- It is not allowed to use Task_Dispatching_Policy and
12283 -- Priority_Specific_Dispatching in the same partition.
12285 if Task_Dispatching_Policy /= ' ' then
12286 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12288 ("pragma% incompatible with Task_Dispatching_Policy#");
12290 -- Check lower bound in range
12292 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12294 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12297 ("first_priority is out of range", Arg2);
12299 -- Check upper bound in range
12301 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12303 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12306 ("last_priority is out of range", Arg3);
12308 -- Check that the priority range is valid
12310 elsif Lower_Val > Upper_Val then
12312 ("last_priority_expression must be greater than" &
12313 " or equal to first_priority_expression");
12315 -- Store the new policy, but always preserve System_Location since
12316 -- we like the error message with the run-time name.
12319 -- Check overlapping in the priority ranges specified in other
12320 -- Priority_Specific_Dispatching pragmas within the same
12321 -- partition. We can only check those we know about!
12324 Specific_Dispatching.First .. Specific_Dispatching.Last
12326 if Specific_Dispatching.Table (J).First_Priority in
12327 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12328 or else Specific_Dispatching.Table (J).Last_Priority in
12329 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12332 Specific_Dispatching.Table (J).Pragma_Loc;
12334 ("priority range overlaps with "
12335 & "Priority_Specific_Dispatching#");
12339 -- The use of Priority_Specific_Dispatching is incompatible
12340 -- with Task_Dispatching_Policy.
12342 if Task_Dispatching_Policy /= ' ' then
12343 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12345 ("Priority_Specific_Dispatching incompatible "
12346 & "with Task_Dispatching_Policy#");
12349 -- The use of Priority_Specific_Dispatching forces ceiling
12352 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12353 Error_Msg_Sloc := Locking_Policy_Sloc;
12355 ("Priority_Specific_Dispatching incompatible "
12356 & "with Locking_Policy#");
12358 -- Set the Ceiling_Locking policy, but preserve System_Location
12359 -- since we like the error message with the run time name.
12362 Locking_Policy := 'C';
12364 if Locking_Policy_Sloc /= System_Location then
12365 Locking_Policy_Sloc := Loc;
12369 -- Add entry in the table
12371 Specific_Dispatching.Append
12372 ((Dispatching_Policy => DP,
12373 First_Priority => UI_To_Int (Lower_Val),
12374 Last_Priority => UI_To_Int (Upper_Val),
12375 Pragma_Loc => Loc));
12377 end Priority_Specific_Dispatching;
12383 -- pragma Profile (profile_IDENTIFIER);
12385 -- profile_IDENTIFIER => Restricted | Ravenscar
12387 when Pragma_Profile =>
12389 Check_Arg_Count (1);
12390 Check_Valid_Configuration_Pragma;
12391 Check_No_Identifiers;
12394 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12397 if Chars (Argx) = Name_Ravenscar then
12398 Set_Ravenscar_Profile (N);
12400 elsif Chars (Argx) = Name_Restricted then
12401 Set_Profile_Restrictions
12403 N, Warn => Treat_Restrictions_As_Warnings);
12405 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12406 Set_Profile_Restrictions
12407 (No_Implementation_Extensions,
12408 N, Warn => Treat_Restrictions_As_Warnings);
12411 Error_Pragma_Arg ("& is not a valid profile", Argx);
12415 ----------------------
12416 -- Profile_Warnings --
12417 ----------------------
12419 -- pragma Profile_Warnings (profile_IDENTIFIER);
12421 -- profile_IDENTIFIER => Restricted | Ravenscar
12423 when Pragma_Profile_Warnings =>
12425 Check_Arg_Count (1);
12426 Check_Valid_Configuration_Pragma;
12427 Check_No_Identifiers;
12430 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12433 if Chars (Argx) = Name_Ravenscar then
12434 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12436 elsif Chars (Argx) = Name_Restricted then
12437 Set_Profile_Restrictions (Restricted, N, Warn => True);
12439 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12440 Set_Profile_Restrictions
12441 (No_Implementation_Extensions, N, Warn => True);
12444 Error_Pragma_Arg ("& is not a valid profile", Argx);
12448 --------------------------
12449 -- Propagate_Exceptions --
12450 --------------------------
12452 -- pragma Propagate_Exceptions;
12454 -- Note: this pragma is obsolete and has no effect
12456 when Pragma_Propagate_Exceptions =>
12458 Check_Arg_Count (0);
12460 if In_Extended_Main_Source_Unit (N) then
12461 Propagate_Exceptions := True;
12468 -- pragma Psect_Object (
12469 -- [Internal =>] LOCAL_NAME,
12470 -- [, [External =>] EXTERNAL_SYMBOL]
12471 -- [, [Size =>] EXTERNAL_SYMBOL]);
12473 when Pragma_Psect_Object | Pragma_Common_Object =>
12474 Psect_Object : declare
12475 Args : Args_List (1 .. 3);
12476 Names : constant Name_List (1 .. 3) := (
12481 Internal : Node_Id renames Args (1);
12482 External : Node_Id renames Args (2);
12483 Size : Node_Id renames Args (3);
12485 Def_Id : Entity_Id;
12487 procedure Check_Too_Long (Arg : Node_Id);
12488 -- Posts message if the argument is an identifier with more
12489 -- than 31 characters, or a string literal with more than
12490 -- 31 characters, and we are operating under VMS
12492 --------------------
12493 -- Check_Too_Long --
12494 --------------------
12496 procedure Check_Too_Long (Arg : Node_Id) is
12497 X : constant Node_Id := Original_Node (Arg);
12500 if not Nkind_In (X, N_String_Literal, N_Identifier) then
12502 ("inappropriate argument for pragma %", Arg);
12505 if OpenVMS_On_Target then
12506 if (Nkind (X) = N_String_Literal
12507 and then String_Length (Strval (X)) > 31)
12509 (Nkind (X) = N_Identifier
12510 and then Length_Of_Name (Chars (X)) > 31)
12513 ("argument for pragma % is longer than 31 characters",
12517 end Check_Too_Long;
12519 -- Start of processing for Common_Object/Psect_Object
12523 Gather_Associations (Names, Args);
12524 Process_Extended_Import_Export_Internal_Arg (Internal);
12526 Def_Id := Entity (Internal);
12528 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12530 ("pragma% must designate an object", Internal);
12533 Check_Too_Long (Internal);
12535 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12537 ("cannot use pragma% for imported/exported object",
12541 if Is_Concurrent_Type (Etype (Internal)) then
12543 ("cannot specify pragma % for task/protected object",
12547 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12549 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12551 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12554 if Ekind (Def_Id) = E_Constant then
12556 ("cannot specify pragma % for a constant", Internal);
12559 if Is_Record_Type (Etype (Internal)) then
12565 Ent := First_Entity (Etype (Internal));
12566 while Present (Ent) loop
12567 Decl := Declaration_Node (Ent);
12569 if Ekind (Ent) = E_Component
12570 and then Nkind (Decl) = N_Component_Declaration
12571 and then Present (Expression (Decl))
12572 and then Warn_On_Export_Import
12575 ("?object for pragma % has defaults", Internal);
12585 if Present (Size) then
12586 Check_Too_Long (Size);
12589 if Present (External) then
12590 Check_Arg_Is_External_Name (External);
12591 Check_Too_Long (External);
12594 -- If all error tests pass, link pragma on to the rep item chain
12596 Record_Rep_Item (Def_Id, N);
12603 -- pragma Pure [(library_unit_NAME)];
12605 when Pragma_Pure => Pure : declare
12609 Check_Ada_83_Warning;
12610 Check_Valid_Library_Unit_Pragma;
12612 if Nkind (N) = N_Null_Statement then
12616 Ent := Find_Lib_Unit_Name;
12618 Set_Has_Pragma_Pure (Ent);
12619 Set_Suppress_Elaboration_Warnings (Ent);
12626 -- pragma Pure_05 [(library_unit_NAME)];
12628 -- This pragma is useable only in GNAT_Mode, where it is used like
12629 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
12630 -- it is ignored). It may be used after a pragma Preelaborate, in
12631 -- which case it overrides the effect of the pragma Preelaborate.
12632 -- This is used to implement AI-362 which recategorizes some run-time
12633 -- packages in Ada 2005 mode.
12635 when Pragma_Pure_05 => Pure_05 : declare
12640 Check_Valid_Library_Unit_Pragma;
12642 if not GNAT_Mode then
12643 Error_Pragma ("pragma% only available in GNAT mode");
12646 if Nkind (N) = N_Null_Statement then
12650 -- This is one of the few cases where we need to test the value of
12651 -- Ada_Version_Explicit rather than Ada_Version (which is always
12652 -- set to Ada_2012 in a predefined unit), we need to know the
12653 -- explicit version set to know if this pragma is active.
12655 if Ada_Version_Explicit >= Ada_2005 then
12656 Ent := Find_Lib_Unit_Name;
12657 Set_Is_Preelaborated (Ent, False);
12659 Set_Suppress_Elaboration_Warnings (Ent);
12667 -- pragma Pure_12 [(library_unit_NAME)];
12669 -- This pragma is useable only in GNAT_Mode, where it is used like
12670 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
12671 -- it is ignored). It may be used after a pragma Preelaborate, in
12672 -- which case it overrides the effect of the pragma Preelaborate.
12673 -- This is used to implement AI05-0212 which recategorizes some
12674 -- run-time packages in Ada 2012 mode.
12676 when Pragma_Pure_12 => Pure_12 : declare
12681 Check_Valid_Library_Unit_Pragma;
12683 if not GNAT_Mode then
12684 Error_Pragma ("pragma% only available in GNAT mode");
12687 if Nkind (N) = N_Null_Statement then
12691 -- This is one of the few cases where we need to test the value of
12692 -- Ada_Version_Explicit rather than Ada_Version (which is always
12693 -- set to Ada_2012 in a predefined unit), we need to know the
12694 -- explicit version set to know if this pragma is active.
12696 if Ada_Version_Explicit >= Ada_2012 then
12697 Ent := Find_Lib_Unit_Name;
12698 Set_Is_Preelaborated (Ent, False);
12700 Set_Suppress_Elaboration_Warnings (Ent);
12704 -------------------
12705 -- Pure_Function --
12706 -------------------
12708 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12710 when Pragma_Pure_Function => Pure_Function : declare
12713 Def_Id : Entity_Id;
12714 Effective : Boolean := False;
12718 Check_Arg_Count (1);
12719 Check_Optional_Identifier (Arg1, Name_Entity);
12720 Check_Arg_Is_Local_Name (Arg1);
12721 E_Id := Get_Pragma_Arg (Arg1);
12723 if Error_Posted (E_Id) then
12727 -- Loop through homonyms (overloadings) of referenced entity
12729 E := Entity (E_Id);
12731 if Present (E) then
12733 Def_Id := Get_Base_Subprogram (E);
12735 if not Ekind_In (Def_Id, E_Function,
12736 E_Generic_Function,
12740 ("pragma% requires a function name", Arg1);
12743 Set_Is_Pure (Def_Id);
12745 if not Has_Pragma_Pure_Function (Def_Id) then
12746 Set_Has_Pragma_Pure_Function (Def_Id);
12750 exit when From_Aspect_Specification (N);
12752 exit when No (E) or else Scope (E) /= Current_Scope;
12756 and then Warn_On_Redundant_Constructs
12759 ("pragma Pure_Function on& is redundant?",
12765 --------------------
12766 -- Queuing_Policy --
12767 --------------------
12769 -- pragma Queuing_Policy (policy_IDENTIFIER);
12771 when Pragma_Queuing_Policy => declare
12775 Check_Ada_83_Warning;
12776 Check_Arg_Count (1);
12777 Check_No_Identifiers;
12778 Check_Arg_Is_Queuing_Policy (Arg1);
12779 Check_Valid_Configuration_Pragma;
12780 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12781 QP := Fold_Upper (Name_Buffer (1));
12783 if Queuing_Policy /= ' '
12784 and then Queuing_Policy /= QP
12786 Error_Msg_Sloc := Queuing_Policy_Sloc;
12787 Error_Pragma ("queuing policy incompatible with policy#");
12789 -- Set new policy, but always preserve System_Location since we
12790 -- like the error message with the run time name.
12793 Queuing_Policy := QP;
12795 if Queuing_Policy_Sloc /= System_Location then
12796 Queuing_Policy_Sloc := Loc;
12801 -----------------------
12802 -- Relative_Deadline --
12803 -----------------------
12805 -- pragma Relative_Deadline (time_span_EXPRESSION);
12807 when Pragma_Relative_Deadline => Relative_Deadline : declare
12808 P : constant Node_Id := Parent (N);
12813 Check_No_Identifiers;
12814 Check_Arg_Count (1);
12816 Arg := Get_Pragma_Arg (Arg1);
12818 -- The expression must be analyzed in the special manner described
12819 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12821 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12825 if Nkind (P) = N_Subprogram_Body then
12826 Check_In_Main_Program;
12830 elsif Nkind (P) = N_Task_Definition then
12833 -- Anything else is incorrect
12839 if Has_Relative_Deadline_Pragma (P) then
12840 Error_Pragma ("duplicate pragma% not allowed");
12842 Set_Has_Relative_Deadline_Pragma (P, True);
12844 if Nkind (P) = N_Task_Definition then
12845 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12848 end Relative_Deadline;
12850 ---------------------------
12851 -- Remote_Call_Interface --
12852 ---------------------------
12854 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12856 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12857 Cunit_Node : Node_Id;
12858 Cunit_Ent : Entity_Id;
12862 Check_Ada_83_Warning;
12863 Check_Valid_Library_Unit_Pragma;
12865 if Nkind (N) = N_Null_Statement then
12869 Cunit_Node := Cunit (Current_Sem_Unit);
12870 K := Nkind (Unit (Cunit_Node));
12871 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12873 if K = N_Package_Declaration
12874 or else K = N_Generic_Package_Declaration
12875 or else K = N_Subprogram_Declaration
12876 or else K = N_Generic_Subprogram_Declaration
12877 or else (K = N_Subprogram_Body
12878 and then Acts_As_Spec (Unit (Cunit_Node)))
12883 "pragma% must apply to package or subprogram declaration");
12886 Set_Is_Remote_Call_Interface (Cunit_Ent);
12887 end Remote_Call_Interface;
12893 -- pragma Remote_Types [(library_unit_NAME)];
12895 when Pragma_Remote_Types => Remote_Types : declare
12896 Cunit_Node : Node_Id;
12897 Cunit_Ent : Entity_Id;
12900 Check_Ada_83_Warning;
12901 Check_Valid_Library_Unit_Pragma;
12903 if Nkind (N) = N_Null_Statement then
12907 Cunit_Node := Cunit (Current_Sem_Unit);
12908 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12910 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12911 N_Generic_Package_Declaration)
12914 ("pragma% can only apply to a package declaration");
12917 Set_Is_Remote_Types (Cunit_Ent);
12924 -- pragma Ravenscar;
12926 when Pragma_Ravenscar =>
12928 Check_Arg_Count (0);
12929 Check_Valid_Configuration_Pragma;
12930 Set_Ravenscar_Profile (N);
12932 if Warn_On_Obsolescent_Feature then
12933 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12934 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12937 -------------------------
12938 -- Restricted_Run_Time --
12939 -------------------------
12941 -- pragma Restricted_Run_Time;
12943 when Pragma_Restricted_Run_Time =>
12945 Check_Arg_Count (0);
12946 Check_Valid_Configuration_Pragma;
12947 Set_Profile_Restrictions
12948 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12950 if Warn_On_Obsolescent_Feature then
12952 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12953 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12960 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12963 -- restriction_IDENTIFIER
12964 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12966 when Pragma_Restrictions =>
12967 Process_Restrictions_Or_Restriction_Warnings
12968 (Warn => Treat_Restrictions_As_Warnings);
12970 --------------------------
12971 -- Restriction_Warnings --
12972 --------------------------
12974 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12977 -- restriction_IDENTIFIER
12978 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12980 when Pragma_Restriction_Warnings =>
12982 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12988 -- pragma Reviewable;
12990 when Pragma_Reviewable =>
12991 Check_Ada_83_Warning;
12992 Check_Arg_Count (0);
12994 -- Call dummy debugging function rv. This is done to assist front
12995 -- end debugging. By placing a Reviewable pragma in the source
12996 -- program, a breakpoint on rv catches this place in the source,
12997 -- allowing convenient stepping to the point of interest.
13001 --------------------------
13002 -- Short_Circuit_And_Or --
13003 --------------------------
13005 when Pragma_Short_Circuit_And_Or =>
13007 Check_Arg_Count (0);
13008 Check_Valid_Configuration_Pragma;
13009 Short_Circuit_And_Or := True;
13011 -------------------
13012 -- Share_Generic --
13013 -------------------
13015 -- pragma Share_Generic (NAME {, NAME});
13017 when Pragma_Share_Generic =>
13019 Process_Generic_List;
13025 -- pragma Shared (LOCAL_NAME);
13027 when Pragma_Shared =>
13029 Process_Atomic_Shared_Volatile;
13031 --------------------
13032 -- Shared_Passive --
13033 --------------------
13035 -- pragma Shared_Passive [(library_unit_NAME)];
13037 -- Set the flag Is_Shared_Passive of program unit name entity
13039 when Pragma_Shared_Passive => Shared_Passive : declare
13040 Cunit_Node : Node_Id;
13041 Cunit_Ent : Entity_Id;
13044 Check_Ada_83_Warning;
13045 Check_Valid_Library_Unit_Pragma;
13047 if Nkind (N) = N_Null_Statement then
13051 Cunit_Node := Cunit (Current_Sem_Unit);
13052 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13054 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13055 N_Generic_Package_Declaration)
13058 ("pragma% can only apply to a package declaration");
13061 Set_Is_Shared_Passive (Cunit_Ent);
13062 end Shared_Passive;
13064 -----------------------
13065 -- Short_Descriptors --
13066 -----------------------
13068 -- pragma Short_Descriptors;
13070 when Pragma_Short_Descriptors =>
13072 Check_Arg_Count (0);
13073 Check_Valid_Configuration_Pragma;
13074 Short_Descriptors := True;
13076 ----------------------
13077 -- Source_File_Name --
13078 ----------------------
13080 -- There are five forms for this pragma:
13082 -- pragma Source_File_Name (
13083 -- [UNIT_NAME =>] unit_NAME,
13084 -- BODY_FILE_NAME => STRING_LITERAL
13085 -- [, [INDEX =>] INTEGER_LITERAL]);
13087 -- pragma Source_File_Name (
13088 -- [UNIT_NAME =>] unit_NAME,
13089 -- SPEC_FILE_NAME => STRING_LITERAL
13090 -- [, [INDEX =>] INTEGER_LITERAL]);
13092 -- pragma Source_File_Name (
13093 -- BODY_FILE_NAME => STRING_LITERAL
13094 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13095 -- [, CASING => CASING_SPEC]);
13097 -- pragma Source_File_Name (
13098 -- SPEC_FILE_NAME => STRING_LITERAL
13099 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13100 -- [, CASING => CASING_SPEC]);
13102 -- pragma Source_File_Name (
13103 -- SUBUNIT_FILE_NAME => STRING_LITERAL
13104 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13105 -- [, CASING => CASING_SPEC]);
13107 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
13109 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
13110 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
13111 -- only be used when no project file is used, while SFNP can only be
13112 -- used when a project file is used.
13114 -- No processing here. Processing was completed during parsing, since
13115 -- we need to have file names set as early as possible. Units are
13116 -- loaded well before semantic processing starts.
13118 -- The only processing we defer to this point is the check for
13119 -- correct placement.
13121 when Pragma_Source_File_Name =>
13123 Check_Valid_Configuration_Pragma;
13125 ------------------------------
13126 -- Source_File_Name_Project --
13127 ------------------------------
13129 -- See Source_File_Name for syntax
13131 -- No processing here. Processing was completed during parsing, since
13132 -- we need to have file names set as early as possible. Units are
13133 -- loaded well before semantic processing starts.
13135 -- The only processing we defer to this point is the check for
13136 -- correct placement.
13138 when Pragma_Source_File_Name_Project =>
13140 Check_Valid_Configuration_Pragma;
13142 -- Check that a pragma Source_File_Name_Project is used only in a
13143 -- configuration pragmas file.
13145 -- Pragmas Source_File_Name_Project should only be generated by
13146 -- the Project Manager in configuration pragmas files.
13148 -- This is really an ugly test. It seems to depend on some
13149 -- accidental and undocumented property. At the very least it
13150 -- needs to be documented, but it would be better to have a
13151 -- clean way of testing if we are in a configuration file???
13153 if Present (Parent (N)) then
13155 ("pragma% can only appear in a configuration pragmas file");
13158 ----------------------
13159 -- Source_Reference --
13160 ----------------------
13162 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
13164 -- Nothing to do, all processing completed in Par.Prag, since we need
13165 -- the information for possible parser messages that are output.
13167 when Pragma_Source_Reference =>
13170 --------------------------------
13171 -- Static_Elaboration_Desired --
13172 --------------------------------
13174 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
13176 when Pragma_Static_Elaboration_Desired =>
13178 Check_At_Most_N_Arguments (1);
13180 if Is_Compilation_Unit (Current_Scope)
13181 and then Ekind (Current_Scope) = E_Package
13183 Set_Static_Elaboration_Desired (Current_Scope, True);
13185 Error_Pragma ("pragma% must apply to a library-level package");
13192 -- pragma Storage_Size (EXPRESSION);
13194 when Pragma_Storage_Size => Storage_Size : declare
13195 P : constant Node_Id := Parent (N);
13199 Check_No_Identifiers;
13200 Check_Arg_Count (1);
13202 -- The expression must be analyzed in the special manner described
13203 -- in "Handling of Default Expressions" in sem.ads.
13205 Arg := Get_Pragma_Arg (Arg1);
13206 Preanalyze_Spec_Expression (Arg, Any_Integer);
13208 if not Is_Static_Expression (Arg) then
13209 Check_Restriction (Static_Storage_Size, Arg);
13212 if Nkind (P) /= N_Task_Definition then
13217 if Has_Storage_Size_Pragma (P) then
13218 Error_Pragma ("duplicate pragma% not allowed");
13220 Set_Has_Storage_Size_Pragma (P, True);
13223 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13224 -- ??? exp_ch9 should use this!
13232 -- pragma Storage_Unit (NUMERIC_LITERAL);
13234 -- Only permitted argument is System'Storage_Unit value
13236 when Pragma_Storage_Unit =>
13237 Check_No_Identifiers;
13238 Check_Arg_Count (1);
13239 Check_Arg_Is_Integer_Literal (Arg1);
13241 if Intval (Get_Pragma_Arg (Arg1)) /=
13242 UI_From_Int (Ttypes.System_Storage_Unit)
13244 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
13246 ("the only allowed argument for pragma% is ^", Arg1);
13249 --------------------
13250 -- Stream_Convert --
13251 --------------------
13253 -- pragma Stream_Convert (
13254 -- [Entity =>] type_LOCAL_NAME,
13255 -- [Read =>] function_NAME,
13256 -- [Write =>] function NAME);
13258 when Pragma_Stream_Convert => Stream_Convert : declare
13260 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
13261 -- Check that the given argument is the name of a local function
13262 -- of one argument that is not overloaded earlier in the current
13263 -- local scope. A check is also made that the argument is a
13264 -- function with one parameter.
13266 --------------------------------------
13267 -- Check_OK_Stream_Convert_Function --
13268 --------------------------------------
13270 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
13274 Check_Arg_Is_Local_Name (Arg);
13275 Ent := Entity (Get_Pragma_Arg (Arg));
13277 if Has_Homonym (Ent) then
13279 ("argument for pragma% may not be overloaded", Arg);
13282 if Ekind (Ent) /= E_Function
13283 or else No (First_Formal (Ent))
13284 or else Present (Next_Formal (First_Formal (Ent)))
13287 ("argument for pragma% must be" &
13288 " function of one argument", Arg);
13290 end Check_OK_Stream_Convert_Function;
13292 -- Start of processing for Stream_Convert
13296 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
13297 Check_Arg_Count (3);
13298 Check_Optional_Identifier (Arg1, Name_Entity);
13299 Check_Optional_Identifier (Arg2, Name_Read);
13300 Check_Optional_Identifier (Arg3, Name_Write);
13301 Check_Arg_Is_Local_Name (Arg1);
13302 Check_OK_Stream_Convert_Function (Arg2);
13303 Check_OK_Stream_Convert_Function (Arg3);
13306 Typ : constant Entity_Id :=
13307 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13308 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13309 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
13312 Check_First_Subtype (Arg1);
13314 -- Check for too early or too late. Note that we don't enforce
13315 -- the rule about primitive operations in this case, since, as
13316 -- is the case for explicit stream attributes themselves, these
13317 -- restrictions are not appropriate. Note that the chaining of
13318 -- the pragma by Rep_Item_Too_Late is actually the critical
13319 -- processing done for this pragma.
13321 if Rep_Item_Too_Early (Typ, N)
13323 Rep_Item_Too_Late (Typ, N, FOnly => True)
13328 -- Return if previous error
13330 if Etype (Typ) = Any_Type
13332 Etype (Read) = Any_Type
13334 Etype (Write) = Any_Type
13341 if Underlying_Type (Etype (Read)) /= Typ then
13343 ("incorrect return type for function&", Arg2);
13346 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13348 ("incorrect parameter type for function&", Arg3);
13351 if Underlying_Type (Etype (First_Formal (Read))) /=
13352 Underlying_Type (Etype (Write))
13355 ("result type of & does not match Read parameter type",
13359 end Stream_Convert;
13361 -------------------------
13362 -- Style_Checks (GNAT) --
13363 -------------------------
13365 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13367 -- This is processed by the parser since some of the style checks
13368 -- take place during source scanning and parsing. This means that
13369 -- we don't need to issue error messages here.
13371 when Pragma_Style_Checks => Style_Checks : declare
13372 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13378 Check_No_Identifiers;
13380 -- Two argument form
13382 if Arg_Count = 2 then
13383 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13390 E_Id := Get_Pragma_Arg (Arg2);
13393 if not Is_Entity_Name (E_Id) then
13395 ("second argument of pragma% must be entity name",
13399 E := Entity (E_Id);
13405 Set_Suppress_Style_Checks (E,
13406 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
13407 exit when No (Homonym (E));
13413 -- One argument form
13416 Check_Arg_Count (1);
13418 if Nkind (A) = N_String_Literal then
13422 Slen : constant Natural := Natural (String_Length (S));
13423 Options : String (1 .. Slen);
13429 C := Get_String_Char (S, Int (J));
13430 exit when not In_Character_Range (C);
13431 Options (J) := Get_Character (C);
13433 -- If at end of string, set options. As per discussion
13434 -- above, no need to check for errors, since we issued
13435 -- them in the parser.
13438 Set_Style_Check_Options (Options);
13446 elsif Nkind (A) = N_Identifier then
13447 if Chars (A) = Name_All_Checks then
13449 Set_GNAT_Style_Check_Options;
13451 Set_Default_Style_Check_Options;
13454 elsif Chars (A) = Name_On then
13455 Style_Check := True;
13457 elsif Chars (A) = Name_Off then
13458 Style_Check := False;
13468 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13470 when Pragma_Subtitle =>
13472 Check_Arg_Count (1);
13473 Check_Optional_Identifier (Arg1, Name_Subtitle);
13474 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13481 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13483 when Pragma_Suppress =>
13484 Process_Suppress_Unsuppress (True);
13490 -- pragma Suppress_All;
13492 -- The only check made here is that the pragma has no arguments.
13493 -- There are no placement rules, and the processing required (setting
13494 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
13495 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
13496 -- then creates and inserts a pragma Suppress (All_Checks).
13498 when Pragma_Suppress_All =>
13500 Check_Arg_Count (0);
13502 -------------------------
13503 -- Suppress_Debug_Info --
13504 -------------------------
13506 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13508 when Pragma_Suppress_Debug_Info =>
13510 Check_Arg_Count (1);
13511 Check_Optional_Identifier (Arg1, Name_Entity);
13512 Check_Arg_Is_Local_Name (Arg1);
13513 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13515 ----------------------------------
13516 -- Suppress_Exception_Locations --
13517 ----------------------------------
13519 -- pragma Suppress_Exception_Locations;
13521 when Pragma_Suppress_Exception_Locations =>
13523 Check_Arg_Count (0);
13524 Check_Valid_Configuration_Pragma;
13525 Exception_Locations_Suppressed := True;
13527 -----------------------------
13528 -- Suppress_Initialization --
13529 -----------------------------
13531 -- pragma Suppress_Initialization ([Entity =>] type_Name);
13533 when Pragma_Suppress_Initialization => Suppress_Init : declare
13539 Check_Arg_Count (1);
13540 Check_Optional_Identifier (Arg1, Name_Entity);
13541 Check_Arg_Is_Local_Name (Arg1);
13543 E_Id := Get_Pragma_Arg (Arg1);
13545 if Etype (E_Id) = Any_Type then
13549 E := Entity (E_Id);
13551 if not Is_Type (E) then
13552 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13555 if Rep_Item_Too_Early (E, N)
13557 Rep_Item_Too_Late (E, N, FOnly => True)
13562 -- For incomplete/private type, set flag on full view
13564 if Is_Incomplete_Or_Private_Type (E) then
13565 if No (Full_View (Base_Type (E))) then
13567 ("argument of pragma% cannot be an incomplete type", Arg1);
13569 Set_Suppress_Initialization (Full_View (Base_Type (E)));
13572 -- For first subtype, set flag on base type
13574 elsif Is_First_Subtype (E) then
13575 Set_Suppress_Initialization (Base_Type (E));
13577 -- For other than first subtype, set flag on subtype itself
13580 Set_Suppress_Initialization (E);
13588 -- pragma System_Name (DIRECT_NAME);
13590 -- Syntax check: one argument, which must be the identifier GNAT or
13591 -- the identifier GCC, no other identifiers are acceptable.
13593 when Pragma_System_Name =>
13595 Check_No_Identifiers;
13596 Check_Arg_Count (1);
13597 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13599 -----------------------------
13600 -- Task_Dispatching_Policy --
13601 -----------------------------
13603 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13605 when Pragma_Task_Dispatching_Policy => declare
13609 Check_Ada_83_Warning;
13610 Check_Arg_Count (1);
13611 Check_No_Identifiers;
13612 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13613 Check_Valid_Configuration_Pragma;
13614 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13615 DP := Fold_Upper (Name_Buffer (1));
13617 if Task_Dispatching_Policy /= ' '
13618 and then Task_Dispatching_Policy /= DP
13620 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13622 ("task dispatching policy incompatible with policy#");
13624 -- Set new policy, but always preserve System_Location since we
13625 -- like the error message with the run time name.
13628 Task_Dispatching_Policy := DP;
13630 if Task_Dispatching_Policy_Sloc /= System_Location then
13631 Task_Dispatching_Policy_Sloc := Loc;
13640 -- pragma Task_Info (EXPRESSION);
13642 when Pragma_Task_Info => Task_Info : declare
13643 P : constant Node_Id := Parent (N);
13648 if Nkind (P) /= N_Task_Definition then
13649 Error_Pragma ("pragma% must appear in task definition");
13652 Check_No_Identifiers;
13653 Check_Arg_Count (1);
13655 Analyze_And_Resolve
13656 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13658 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13662 if Has_Task_Info_Pragma (P) then
13663 Error_Pragma ("duplicate pragma% not allowed");
13665 Set_Has_Task_Info_Pragma (P, True);
13673 -- pragma Task_Name (string_EXPRESSION);
13675 when Pragma_Task_Name => Task_Name : declare
13676 P : constant Node_Id := Parent (N);
13680 Check_No_Identifiers;
13681 Check_Arg_Count (1);
13683 Arg := Get_Pragma_Arg (Arg1);
13685 -- The expression is used in the call to Create_Task, and must be
13686 -- expanded there, not in the context of the current spec. It must
13687 -- however be analyzed to capture global references, in case it
13688 -- appears in a generic context.
13690 Preanalyze_And_Resolve (Arg, Standard_String);
13692 if Nkind (P) /= N_Task_Definition then
13696 if Has_Task_Name_Pragma (P) then
13697 Error_Pragma ("duplicate pragma% not allowed");
13699 Set_Has_Task_Name_Pragma (P, True);
13700 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13708 -- pragma Task_Storage (
13709 -- [Task_Type =>] LOCAL_NAME,
13710 -- [Top_Guard =>] static_integer_EXPRESSION);
13712 when Pragma_Task_Storage => Task_Storage : declare
13713 Args : Args_List (1 .. 2);
13714 Names : constant Name_List (1 .. 2) := (
13718 Task_Type : Node_Id renames Args (1);
13719 Top_Guard : Node_Id renames Args (2);
13725 Gather_Associations (Names, Args);
13727 if No (Task_Type) then
13729 ("missing task_type argument for pragma%");
13732 Check_Arg_Is_Local_Name (Task_Type);
13734 Ent := Entity (Task_Type);
13736 if not Is_Task_Type (Ent) then
13738 ("argument for pragma% must be task type", Task_Type);
13741 if No (Top_Guard) then
13743 ("pragma% takes two arguments", Task_Type);
13745 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13748 Check_First_Subtype (Task_Type);
13750 if Rep_Item_Too_Late (Ent, N) then
13759 -- pragma Test_Case ([Name =>] Static_String_EXPRESSION
13760 -- ,[Mode =>] MODE_TYPE
13761 -- [, Requires => Boolean_EXPRESSION]
13762 -- [, Ensures => Boolean_EXPRESSION]);
13764 -- MODE_TYPE ::= Nominal | Robustness
13766 when Pragma_Test_Case => Test_Case : declare
13769 Check_At_Least_N_Arguments (2);
13770 Check_At_Most_N_Arguments (4);
13772 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13774 Check_Optional_Identifier (Arg1, Name_Name);
13775 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13777 -- In ASIS mode, for a pragma generated from a source aspect, also
13778 -- analyze the original aspect expression.
13781 and then Present (Corresponding_Aspect (N))
13783 Check_Expr_Is_Static_Expression
13784 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
13787 Check_Optional_Identifier (Arg2, Name_Mode);
13788 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13790 if Arg_Count = 4 then
13791 Check_Identifier (Arg3, Name_Requires);
13792 Check_Identifier (Arg4, Name_Ensures);
13794 elsif Arg_Count = 3 then
13795 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13801 --------------------------
13802 -- Thread_Local_Storage --
13803 --------------------------
13805 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13807 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13813 Check_Arg_Count (1);
13814 Check_Optional_Identifier (Arg1, Name_Entity);
13815 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13817 Id := Get_Pragma_Arg (Arg1);
13820 if not Is_Entity_Name (Id)
13821 or else Ekind (Entity (Id)) /= E_Variable
13823 Error_Pragma_Arg ("local variable name required", Arg1);
13828 if Rep_Item_Too_Early (E, N)
13829 or else Rep_Item_Too_Late (E, N)
13834 Set_Has_Pragma_Thread_Local_Storage (E);
13835 Set_Has_Gigi_Rep_Item (E);
13836 end Thread_Local_Storage;
13842 -- pragma Time_Slice (static_duration_EXPRESSION);
13844 when Pragma_Time_Slice => Time_Slice : declare
13850 Check_Arg_Count (1);
13851 Check_No_Identifiers;
13852 Check_In_Main_Program;
13853 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13855 if not Error_Posted (Arg1) then
13857 while Present (Nod) loop
13858 if Nkind (Nod) = N_Pragma
13859 and then Pragma_Name (Nod) = Name_Time_Slice
13861 Error_Msg_Name_1 := Pname;
13862 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13869 -- Process only if in main unit
13871 if Get_Source_Unit (Loc) = Main_Unit then
13872 Opt.Time_Slice_Set := True;
13873 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13875 if Val <= Ureal_0 then
13876 Opt.Time_Slice_Value := 0;
13878 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13879 Opt.Time_Slice_Value := 1_000_000_000;
13882 Opt.Time_Slice_Value :=
13883 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13892 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13894 -- TITLING_OPTION ::=
13895 -- [Title =>] STRING_LITERAL
13896 -- | [Subtitle =>] STRING_LITERAL
13898 when Pragma_Title => Title : declare
13899 Args : Args_List (1 .. 2);
13900 Names : constant Name_List (1 .. 2) := (
13906 Gather_Associations (Names, Args);
13909 for J in 1 .. 2 loop
13910 if Present (Args (J)) then
13911 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13916 ---------------------
13917 -- Unchecked_Union --
13918 ---------------------
13920 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13922 when Pragma_Unchecked_Union => Unchecked_Union : declare
13923 Assoc : constant Node_Id := Arg1;
13924 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13935 Check_No_Identifiers;
13936 Check_Arg_Count (1);
13937 Check_Arg_Is_Local_Name (Arg1);
13939 Find_Type (Type_Id);
13940 Typ := Entity (Type_Id);
13943 or else Rep_Item_Too_Early (Typ, N)
13947 Typ := Underlying_Type (Typ);
13950 if Rep_Item_Too_Late (Typ, N) then
13954 Check_First_Subtype (Arg1);
13956 -- Note remaining cases are references to a type in the current
13957 -- declarative part. If we find an error, we post the error on
13958 -- the relevant type declaration at an appropriate point.
13960 if not Is_Record_Type (Typ) then
13961 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13964 elsif Is_Tagged_Type (Typ) then
13965 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13968 elsif not Has_Discriminants (Typ) then
13970 ("Unchecked_Union must have one discriminant", Typ);
13973 -- Note: in previous versions of GNAT we used to check for limited
13974 -- types and give an error, but in fact the standard does allow
13975 -- Unchecked_Union on limited types, so this check was removed.
13977 -- Proceed with basic error checks completed
13980 Discr := First_Discriminant (Typ);
13981 while Present (Discr) loop
13982 if No (Discriminant_Default_Value (Discr)) then
13984 ("Unchecked_Union discriminant must have default value",
13988 Next_Discriminant (Discr);
13991 Tdef := Type_Definition (Declaration_Node (Typ));
13992 Clist := Component_List (Tdef);
13994 Comp := First (Component_Items (Clist));
13995 while Present (Comp) loop
13996 Check_Component (Comp, Typ);
14000 if No (Clist) or else No (Variant_Part (Clist)) then
14002 ("Unchecked_Union must have variant part",
14007 Vpart := Variant_Part (Clist);
14009 Variant := First (Variants (Vpart));
14010 while Present (Variant) loop
14011 Check_Variant (Variant, Typ);
14016 Set_Is_Unchecked_Union (Typ);
14017 Set_Convention (Typ, Convention_C);
14018 Set_Has_Unchecked_Union (Base_Type (Typ));
14019 Set_Is_Unchecked_Union (Base_Type (Typ));
14020 end Unchecked_Union;
14022 ------------------------
14023 -- Unimplemented_Unit --
14024 ------------------------
14026 -- pragma Unimplemented_Unit;
14028 -- Note: this only gives an error if we are generating code, or if
14029 -- we are in a generic library unit (where the pragma appears in the
14030 -- body, not in the spec).
14032 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
14033 Cunitent : constant Entity_Id :=
14034 Cunit_Entity (Get_Source_Unit (Loc));
14035 Ent_Kind : constant Entity_Kind :=
14040 Check_Arg_Count (0);
14042 if Operating_Mode = Generate_Code
14043 or else Ent_Kind = E_Generic_Function
14044 or else Ent_Kind = E_Generic_Procedure
14045 or else Ent_Kind = E_Generic_Package
14047 Get_Name_String (Chars (Cunitent));
14048 Set_Casing (Mixed_Case);
14049 Write_Str (Name_Buffer (1 .. Name_Len));
14050 Write_Str (" is not supported in this configuration");
14052 raise Unrecoverable_Error;
14054 end Unimplemented_Unit;
14056 ------------------------
14057 -- Universal_Aliasing --
14058 ------------------------
14060 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
14062 when Pragma_Universal_Aliasing => Universal_Alias : declare
14067 Check_Arg_Count (1);
14068 Check_Optional_Identifier (Arg2, Name_Entity);
14069 Check_Arg_Is_Local_Name (Arg1);
14070 E_Id := Entity (Get_Pragma_Arg (Arg1));
14072 if E_Id = Any_Type then
14074 elsif No (E_Id) or else not Is_Type (E_Id) then
14075 Error_Pragma_Arg ("pragma% requires type", Arg1);
14078 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
14079 end Universal_Alias;
14081 --------------------
14082 -- Universal_Data --
14083 --------------------
14085 -- pragma Universal_Data [(library_unit_NAME)];
14087 when Pragma_Universal_Data =>
14090 -- If this is a configuration pragma, then set the universal
14091 -- addressing option, otherwise confirm that the pragma satisfies
14092 -- the requirements of library unit pragma placement and leave it
14093 -- to the GNAAMP back end to detect the pragma (avoids transitive
14094 -- setting of the option due to withed units).
14096 if Is_Configuration_Pragma then
14097 Universal_Addressing_On_AAMP := True;
14099 Check_Valid_Library_Unit_Pragma;
14102 if not AAMP_On_Target then
14103 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
14110 -- pragma Unmodified (local_Name {, local_Name});
14112 when Pragma_Unmodified => Unmodified : declare
14113 Arg_Node : Node_Id;
14114 Arg_Expr : Node_Id;
14115 Arg_Ent : Entity_Id;
14119 Check_At_Least_N_Arguments (1);
14121 -- Loop through arguments
14124 while Present (Arg_Node) loop
14125 Check_No_Identifier (Arg_Node);
14127 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
14128 -- in fact generate reference, so that the entity will have a
14129 -- reference, which will inhibit any warnings about it not
14130 -- being referenced, and also properly show up in the ali file
14131 -- as a reference. But this reference is recorded before the
14132 -- Has_Pragma_Unreferenced flag is set, so that no warning is
14133 -- generated for this reference.
14135 Check_Arg_Is_Local_Name (Arg_Node);
14136 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14138 if Is_Entity_Name (Arg_Expr) then
14139 Arg_Ent := Entity (Arg_Expr);
14141 if not Is_Assignable (Arg_Ent) then
14143 ("pragma% can only be applied to a variable",
14146 Set_Has_Pragma_Unmodified (Arg_Ent);
14158 -- pragma Unreferenced (local_Name {, local_Name});
14160 -- or when used in a context clause:
14162 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
14164 when Pragma_Unreferenced => Unreferenced : declare
14165 Arg_Node : Node_Id;
14166 Arg_Expr : Node_Id;
14167 Arg_Ent : Entity_Id;
14172 Check_At_Least_N_Arguments (1);
14174 -- Check case of appearing within context clause
14176 if Is_In_Context_Clause then
14178 -- The arguments must all be units mentioned in a with clause
14179 -- in the same context clause. Note we already checked (in
14180 -- Par.Prag) that the arguments are either identifiers or
14181 -- selected components.
14184 while Present (Arg_Node) loop
14185 Citem := First (List_Containing (N));
14186 while Citem /= N loop
14187 if Nkind (Citem) = N_With_Clause
14189 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
14191 Set_Has_Pragma_Unreferenced
14194 (Library_Unit (Citem))));
14196 (Get_Pragma_Arg (Arg_Node), Name (Citem));
14205 ("argument of pragma% is not with'ed unit", Arg_Node);
14211 -- Case of not in list of context items
14215 while Present (Arg_Node) loop
14216 Check_No_Identifier (Arg_Node);
14218 -- Note: the analyze call done by Check_Arg_Is_Local_Name
14219 -- will in fact generate reference, so that the entity will
14220 -- have a reference, which will inhibit any warnings about
14221 -- it not being referenced, and also properly show up in the
14222 -- ali file as a reference. But this reference is recorded
14223 -- before the Has_Pragma_Unreferenced flag is set, so that
14224 -- no warning is generated for this reference.
14226 Check_Arg_Is_Local_Name (Arg_Node);
14227 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14229 if Is_Entity_Name (Arg_Expr) then
14230 Arg_Ent := Entity (Arg_Expr);
14232 -- If the entity is overloaded, the pragma applies to the
14233 -- most recent overloading, as documented. In this case,
14234 -- name resolution does not generate a reference, so it
14235 -- must be done here explicitly.
14237 if Is_Overloaded (Arg_Expr) then
14238 Generate_Reference (Arg_Ent, N);
14241 Set_Has_Pragma_Unreferenced (Arg_Ent);
14249 --------------------------
14250 -- Unreferenced_Objects --
14251 --------------------------
14253 -- pragma Unreferenced_Objects (local_Name {, local_Name});
14255 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
14256 Arg_Node : Node_Id;
14257 Arg_Expr : Node_Id;
14261 Check_At_Least_N_Arguments (1);
14264 while Present (Arg_Node) loop
14265 Check_No_Identifier (Arg_Node);
14266 Check_Arg_Is_Local_Name (Arg_Node);
14267 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14269 if not Is_Entity_Name (Arg_Expr)
14270 or else not Is_Type (Entity (Arg_Expr))
14273 ("argument for pragma% must be type or subtype", Arg_Node);
14276 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
14279 end Unreferenced_Objects;
14281 ------------------------------
14282 -- Unreserve_All_Interrupts --
14283 ------------------------------
14285 -- pragma Unreserve_All_Interrupts;
14287 when Pragma_Unreserve_All_Interrupts =>
14289 Check_Arg_Count (0);
14291 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
14292 Unreserve_All_Interrupts := True;
14299 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
14301 when Pragma_Unsuppress =>
14303 Process_Suppress_Unsuppress (False);
14305 -------------------
14306 -- Use_VADS_Size --
14307 -------------------
14309 -- pragma Use_VADS_Size;
14311 when Pragma_Use_VADS_Size =>
14313 Check_Arg_Count (0);
14314 Check_Valid_Configuration_Pragma;
14315 Use_VADS_Size := True;
14317 ---------------------
14318 -- Validity_Checks --
14319 ---------------------
14321 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14323 when Pragma_Validity_Checks => Validity_Checks : declare
14324 A : constant Node_Id := Get_Pragma_Arg (Arg1);
14330 Check_Arg_Count (1);
14331 Check_No_Identifiers;
14333 if Nkind (A) = N_String_Literal then
14337 Slen : constant Natural := Natural (String_Length (S));
14338 Options : String (1 .. Slen);
14344 C := Get_String_Char (S, Int (J));
14345 exit when not In_Character_Range (C);
14346 Options (J) := Get_Character (C);
14349 Set_Validity_Check_Options (Options);
14357 elsif Nkind (A) = N_Identifier then
14358 if Chars (A) = Name_All_Checks then
14359 Set_Validity_Check_Options ("a");
14360 elsif Chars (A) = Name_On then
14361 Validity_Checks_On := True;
14362 elsif Chars (A) = Name_Off then
14363 Validity_Checks_On := False;
14366 end Validity_Checks;
14372 -- pragma Volatile (LOCAL_NAME);
14374 when Pragma_Volatile =>
14375 Process_Atomic_Shared_Volatile;
14377 -------------------------
14378 -- Volatile_Components --
14379 -------------------------
14381 -- pragma Volatile_Components (array_LOCAL_NAME);
14383 -- Volatile is handled by the same circuit as Atomic_Components
14389 -- pragma Warnings (On | Off);
14390 -- pragma Warnings (On | Off, LOCAL_NAME);
14391 -- pragma Warnings (static_string_EXPRESSION);
14392 -- pragma Warnings (On | Off, STRING_LITERAL);
14394 when Pragma_Warnings => Warnings : begin
14396 Check_At_Least_N_Arguments (1);
14397 Check_No_Identifiers;
14399 -- If debug flag -gnatd.i is set, pragma is ignored
14401 if Debug_Flag_Dot_I then
14405 -- Process various forms of the pragma
14408 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14411 -- One argument case
14413 if Arg_Count = 1 then
14415 -- On/Off one argument case was processed by parser
14417 if Nkind (Argx) = N_Identifier
14419 (Chars (Argx) = Name_On
14421 Chars (Argx) = Name_Off)
14425 -- One argument case must be ON/OFF or static string expr
14427 elsif not Is_Static_String_Expression (Arg1) then
14429 ("argument of pragma% must be On/Off or " &
14430 "static string expression", Arg1);
14432 -- One argument string expression case
14436 Lit : constant Node_Id := Expr_Value_S (Argx);
14437 Str : constant String_Id := Strval (Lit);
14438 Len : constant Nat := String_Length (Str);
14446 while J <= Len loop
14447 C := Get_String_Char (Str, J);
14448 OK := In_Character_Range (C);
14451 Chr := Get_Character (C);
14455 if J < Len and then Chr = '.' then
14457 C := Get_String_Char (Str, J);
14458 Chr := Get_Character (C);
14460 if not Set_Dot_Warning_Switch (Chr) then
14462 ("invalid warning switch character " &
14469 OK := Set_Warning_Switch (Chr);
14475 ("invalid warning switch character " & Chr,
14484 -- Two or more arguments (must be two)
14487 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14488 Check_At_Most_N_Arguments (2);
14496 E_Id := Get_Pragma_Arg (Arg2);
14499 -- In the expansion of an inlined body, a reference to
14500 -- the formal may be wrapped in a conversion if the
14501 -- actual is a conversion. Retrieve the real entity name.
14503 if (In_Instance_Body
14504 or else In_Inlined_Body)
14505 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14507 E_Id := Expression (E_Id);
14510 -- Entity name case
14512 if Is_Entity_Name (E_Id) then
14513 E := Entity (E_Id);
14520 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14523 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14524 and then Warn_On_Warnings_Off
14526 Warnings_Off_Pragmas.Append ((N, E));
14529 if Is_Enumeration_Type (E) then
14533 Lit := First_Literal (E);
14534 while Present (Lit) loop
14535 Set_Warnings_Off (Lit);
14536 Next_Literal (Lit);
14541 exit when No (Homonym (E));
14546 -- Error if not entity or static string literal case
14548 elsif not Is_Static_String_Expression (Arg2) then
14550 ("second argument of pragma% must be entity " &
14551 "name or static string expression", Arg2);
14553 -- String literal case
14556 String_To_Name_Buffer
14557 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14559 -- Note on configuration pragma case: If this is a
14560 -- configuration pragma, then for an OFF pragma, we
14561 -- just set Config True in the call, which is all
14562 -- that needs to be done. For the case of ON, this
14563 -- is normally an error, unless it is canceling the
14564 -- effect of a previous OFF pragma in the same file.
14565 -- In any other case, an error will be signalled (ON
14566 -- with no matching OFF).
14568 if Chars (Argx) = Name_Off then
14569 Set_Specific_Warning_Off
14570 (Loc, Name_Buffer (1 .. Name_Len),
14571 Config => Is_Configuration_Pragma);
14573 elsif Chars (Argx) = Name_On then
14574 Set_Specific_Warning_On
14575 (Loc, Name_Buffer (1 .. Name_Len), Err);
14579 ("?pragma Warnings On with no " &
14580 "matching Warnings Off",
14590 -------------------
14591 -- Weak_External --
14592 -------------------
14594 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
14596 when Pragma_Weak_External => Weak_External : declare
14601 Check_Arg_Count (1);
14602 Check_Optional_Identifier (Arg1, Name_Entity);
14603 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14604 Ent := Entity (Get_Pragma_Arg (Arg1));
14606 if Rep_Item_Too_Early (Ent, N) then
14609 Ent := Underlying_Type (Ent);
14612 -- The only processing required is to link this item on to the
14613 -- list of rep items for the given entity. This is accomplished
14614 -- by the call to Rep_Item_Too_Late (when no error is detected
14615 -- and False is returned).
14617 if Rep_Item_Too_Late (Ent, N) then
14620 Set_Has_Gigi_Rep_Item (Ent);
14624 -----------------------------
14625 -- Wide_Character_Encoding --
14626 -----------------------------
14628 -- pragma Wide_Character_Encoding (IDENTIFIER);
14630 when Pragma_Wide_Character_Encoding =>
14633 -- Nothing to do, handled in parser. Note that we do not enforce
14634 -- configuration pragma placement, this pragma can appear at any
14635 -- place in the source, allowing mixed encodings within a single
14640 --------------------
14641 -- Unknown_Pragma --
14642 --------------------
14644 -- Should be impossible, since the case of an unknown pragma is
14645 -- separately processed before the case statement is entered.
14647 when Unknown_Pragma =>
14648 raise Program_Error;
14651 -- AI05-0144: detect dangerous order dependence. Disabled for now,
14652 -- until AI is formally approved.
14654 -- Check_Order_Dependence;
14657 when Pragma_Exit => null;
14658 end Analyze_Pragma;
14660 -----------------------------
14661 -- Analyze_TC_In_Decl_Part --
14662 -----------------------------
14664 procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14666 -- Install formals and push subprogram spec onto scope stack so that we
14667 -- can see the formals from the pragma.
14669 Install_Formals (S);
14672 -- Preanalyze the boolean expressions, we treat these as spec
14673 -- expressions (i.e. similar to a default expression).
14675 Preanalyze_TC_Args (N,
14676 Get_Requires_From_Test_Case_Pragma (N),
14677 Get_Ensures_From_Test_Case_Pragma (N));
14679 -- Remove the subprogram from the scope stack now that the pre-analysis
14680 -- of the expressions in the test-case is done.
14683 end Analyze_TC_In_Decl_Part;
14685 --------------------
14686 -- Check_Disabled --
14687 --------------------
14689 function Check_Disabled (Nam : Name_Id) return Boolean is
14693 -- Loop through entries in check policy list
14695 PP := Opt.Check_Policy_List;
14697 -- If there are no specific entries that matched, then nothing is
14698 -- disabled, so return False.
14703 -- Here we have an entry see if it matches
14707 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14709 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14710 return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14712 PP := Next_Pragma (PP);
14717 end Check_Disabled;
14719 -------------------
14720 -- Check_Enabled --
14721 -------------------
14723 function Check_Enabled (Nam : Name_Id) return Boolean is
14727 -- Loop through entries in check policy list
14729 PP := Opt.Check_Policy_List;
14731 -- If there are no specific entries that matched, then we let the
14732 -- setting of assertions govern. Note that this provides the needed
14733 -- compatibility with the RM for the cases of assertion, invariant,
14734 -- precondition, predicate, and postcondition.
14737 return Assertions_Enabled;
14739 -- Here we have an entry see if it matches
14743 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14746 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14747 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14748 when Name_On | Name_Check =>
14750 when Name_Off | Name_Ignore =>
14753 raise Program_Error;
14757 PP := Next_Pragma (PP);
14764 ---------------------------------
14765 -- Delay_Config_Pragma_Analyze --
14766 ---------------------------------
14768 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14770 return Pragma_Name (N) = Name_Interrupt_State
14772 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14773 end Delay_Config_Pragma_Analyze;
14775 -------------------------
14776 -- Get_Base_Subprogram --
14777 -------------------------
14779 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14780 Result : Entity_Id;
14783 -- Follow subprogram renaming chain
14786 while Is_Subprogram (Result)
14788 Nkind (Parent (Declaration_Node (Result))) =
14789 N_Subprogram_Renaming_Declaration
14790 and then Present (Alias (Result))
14792 Result := Alias (Result);
14796 end Get_Base_Subprogram;
14802 procedure Initialize is
14807 -----------------------------
14808 -- Is_Config_Static_String --
14809 -----------------------------
14811 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14813 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14814 -- This is an internal recursive function that is just like the outer
14815 -- function except that it adds the string to the name buffer rather
14816 -- than placing the string in the name buffer.
14818 ------------------------------
14819 -- Add_Config_Static_String --
14820 ------------------------------
14822 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14829 if Nkind (N) = N_Op_Concat then
14830 if Add_Config_Static_String (Left_Opnd (N)) then
14831 N := Right_Opnd (N);
14837 if Nkind (N) /= N_String_Literal then
14838 Error_Msg_N ("string literal expected for pragma argument", N);
14842 for J in 1 .. String_Length (Strval (N)) loop
14843 C := Get_String_Char (Strval (N), J);
14845 if not In_Character_Range (C) then
14847 ("string literal contains invalid wide character",
14848 Sloc (N) + 1 + Source_Ptr (J));
14852 Add_Char_To_Name_Buffer (Get_Character (C));
14857 end Add_Config_Static_String;
14859 -- Start of processing for Is_Config_Static_String
14864 return Add_Config_Static_String (Arg);
14865 end Is_Config_Static_String;
14867 -----------------------------------------
14868 -- Is_Non_Significant_Pragma_Reference --
14869 -----------------------------------------
14871 -- This function makes use of the following static table which indicates
14872 -- whether a given pragma is significant.
14874 -- -1 indicates that references in any argument position are significant
14875 -- 0 indicates that appearance in any argument is not significant
14876 -- +n indicates that appearance as argument n is significant, but all
14877 -- other arguments are not significant
14878 -- 99 special processing required (e.g. for pragma Check)
14880 Sig_Flags : constant array (Pragma_Id) of Int :=
14881 (Pragma_AST_Entry => -1,
14882 Pragma_Abort_Defer => -1,
14883 Pragma_Ada_83 => -1,
14884 Pragma_Ada_95 => -1,
14885 Pragma_Ada_05 => -1,
14886 Pragma_Ada_2005 => -1,
14887 Pragma_Ada_12 => -1,
14888 Pragma_Ada_2012 => -1,
14889 Pragma_All_Calls_Remote => -1,
14890 Pragma_Annotate => -1,
14891 Pragma_Assert => -1,
14892 Pragma_Assertion_Policy => 0,
14893 Pragma_Assume_No_Invalid_Values => 0,
14894 Pragma_Asynchronous => -1,
14895 Pragma_Atomic => 0,
14896 Pragma_Atomic_Components => 0,
14897 Pragma_Attach_Handler => -1,
14898 Pragma_Check => 99,
14899 Pragma_Check_Name => 0,
14900 Pragma_Check_Policy => 0,
14901 Pragma_CIL_Constructor => -1,
14902 Pragma_CPP_Class => 0,
14903 Pragma_CPP_Constructor => 0,
14904 Pragma_CPP_Virtual => 0,
14905 Pragma_CPP_Vtable => 0,
14907 Pragma_C_Pass_By_Copy => 0,
14908 Pragma_Comment => 0,
14909 Pragma_Common_Object => -1,
14910 Pragma_Compile_Time_Error => -1,
14911 Pragma_Compile_Time_Warning => -1,
14912 Pragma_Compiler_Unit => 0,
14913 Pragma_Complete_Representation => 0,
14914 Pragma_Complex_Representation => 0,
14915 Pragma_Component_Alignment => -1,
14916 Pragma_Controlled => 0,
14917 Pragma_Convention => 0,
14918 Pragma_Convention_Identifier => 0,
14919 Pragma_Debug => -1,
14920 Pragma_Debug_Policy => 0,
14921 Pragma_Detect_Blocking => -1,
14922 Pragma_Default_Storage_Pool => -1,
14923 Pragma_Dimension => -1,
14924 Pragma_Disable_Atomic_Synchronization => -1,
14925 Pragma_Discard_Names => 0,
14926 Pragma_Dispatching_Domain => -1,
14927 Pragma_Elaborate => -1,
14928 Pragma_Elaborate_All => -1,
14929 Pragma_Elaborate_Body => -1,
14930 Pragma_Elaboration_Checks => -1,
14931 Pragma_Eliminate => -1,
14932 Pragma_Enable_Atomic_Synchronization => -1,
14933 Pragma_Export => -1,
14934 Pragma_Export_Exception => -1,
14935 Pragma_Export_Function => -1,
14936 Pragma_Export_Object => -1,
14937 Pragma_Export_Procedure => -1,
14938 Pragma_Export_Value => -1,
14939 Pragma_Export_Valued_Procedure => -1,
14940 Pragma_Extend_System => -1,
14941 Pragma_Extensions_Allowed => -1,
14942 Pragma_External => -1,
14943 Pragma_Favor_Top_Level => -1,
14944 Pragma_External_Name_Casing => -1,
14945 Pragma_Fast_Math => -1,
14946 Pragma_Finalize_Storage_Only => 0,
14947 Pragma_Float_Representation => 0,
14948 Pragma_Ident => -1,
14949 Pragma_Implementation_Defined => -1,
14950 Pragma_Implemented => -1,
14951 Pragma_Implicit_Packing => 0,
14952 Pragma_Import => +2,
14953 Pragma_Import_Exception => 0,
14954 Pragma_Import_Function => 0,
14955 Pragma_Import_Object => 0,
14956 Pragma_Import_Procedure => 0,
14957 Pragma_Import_Valued_Procedure => 0,
14958 Pragma_Independent => 0,
14959 Pragma_Independent_Components => 0,
14960 Pragma_Initialize_Scalars => -1,
14961 Pragma_Inline => 0,
14962 Pragma_Inline_Always => 0,
14963 Pragma_Inline_Generic => 0,
14964 Pragma_Inspection_Point => -1,
14965 Pragma_Interface => +2,
14966 Pragma_Interface_Name => +2,
14967 Pragma_Interrupt_Handler => -1,
14968 Pragma_Interrupt_Priority => -1,
14969 Pragma_Interrupt_State => -1,
14970 Pragma_Invariant => -1,
14971 Pragma_Java_Constructor => -1,
14972 Pragma_Java_Interface => -1,
14973 Pragma_Keep_Names => 0,
14974 Pragma_License => -1,
14975 Pragma_Link_With => -1,
14976 Pragma_Linker_Alias => -1,
14977 Pragma_Linker_Constructor => -1,
14978 Pragma_Linker_Destructor => -1,
14979 Pragma_Linker_Options => -1,
14980 Pragma_Linker_Section => -1,
14982 Pragma_Locking_Policy => -1,
14983 Pragma_Long_Float => -1,
14984 Pragma_Machine_Attribute => -1,
14986 Pragma_Main_Storage => -1,
14987 Pragma_Memory_Size => -1,
14988 Pragma_No_Return => 0,
14989 Pragma_No_Body => 0,
14990 Pragma_No_Run_Time => -1,
14991 Pragma_No_Strict_Aliasing => -1,
14992 Pragma_Normalize_Scalars => -1,
14993 Pragma_Obsolescent => 0,
14994 Pragma_Optimize => -1,
14995 Pragma_Optimize_Alignment => -1,
14996 Pragma_Ordered => 0,
14999 Pragma_Passive => -1,
15000 Pragma_Preelaborable_Initialization => -1,
15001 Pragma_Polling => -1,
15002 Pragma_Persistent_BSS => 0,
15003 Pragma_Postcondition => -1,
15004 Pragma_Precondition => -1,
15005 Pragma_Predicate => -1,
15006 Pragma_Preelaborate => -1,
15007 Pragma_Preelaborate_05 => -1,
15008 Pragma_Priority => -1,
15009 Pragma_Priority_Specific_Dispatching => -1,
15010 Pragma_Profile => 0,
15011 Pragma_Profile_Warnings => 0,
15012 Pragma_Propagate_Exceptions => -1,
15013 Pragma_Psect_Object => -1,
15015 Pragma_Pure_05 => -1,
15016 Pragma_Pure_12 => -1,
15017 Pragma_Pure_Function => -1,
15018 Pragma_Queuing_Policy => -1,
15019 Pragma_Ravenscar => -1,
15020 Pragma_Relative_Deadline => -1,
15021 Pragma_Remote_Call_Interface => -1,
15022 Pragma_Remote_Types => -1,
15023 Pragma_Restricted_Run_Time => -1,
15024 Pragma_Restriction_Warnings => -1,
15025 Pragma_Restrictions => -1,
15026 Pragma_Reviewable => -1,
15027 Pragma_Short_Circuit_And_Or => -1,
15028 Pragma_Share_Generic => -1,
15029 Pragma_Shared => -1,
15030 Pragma_Shared_Passive => -1,
15031 Pragma_Short_Descriptors => 0,
15032 Pragma_Source_File_Name => -1,
15033 Pragma_Source_File_Name_Project => -1,
15034 Pragma_Source_Reference => -1,
15035 Pragma_Storage_Size => -1,
15036 Pragma_Storage_Unit => -1,
15037 Pragma_Static_Elaboration_Desired => -1,
15038 Pragma_Stream_Convert => -1,
15039 Pragma_Style_Checks => -1,
15040 Pragma_Subtitle => -1,
15041 Pragma_Suppress => 0,
15042 Pragma_Suppress_Exception_Locations => 0,
15043 Pragma_Suppress_All => -1,
15044 Pragma_Suppress_Debug_Info => 0,
15045 Pragma_Suppress_Initialization => 0,
15046 Pragma_System_Name => -1,
15047 Pragma_Task_Dispatching_Policy => -1,
15048 Pragma_Task_Info => -1,
15049 Pragma_Task_Name => -1,
15050 Pragma_Task_Storage => 0,
15051 Pragma_Test_Case => -1,
15052 Pragma_Thread_Local_Storage => 0,
15053 Pragma_Time_Slice => -1,
15054 Pragma_Title => -1,
15055 Pragma_Unchecked_Union => 0,
15056 Pragma_Unimplemented_Unit => -1,
15057 Pragma_Universal_Aliasing => -1,
15058 Pragma_Universal_Data => -1,
15059 Pragma_Unmodified => -1,
15060 Pragma_Unreferenced => -1,
15061 Pragma_Unreferenced_Objects => -1,
15062 Pragma_Unreserve_All_Interrupts => -1,
15063 Pragma_Unsuppress => 0,
15064 Pragma_Use_VADS_Size => -1,
15065 Pragma_Validity_Checks => -1,
15066 Pragma_Volatile => 0,
15067 Pragma_Volatile_Components => 0,
15068 Pragma_Warnings => -1,
15069 Pragma_Weak_External => -1,
15070 Pragma_Wide_Character_Encoding => 0,
15071 Unknown_Pragma => 0);
15073 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
15082 if Nkind (P) /= N_Pragma_Argument_Association then
15086 Id := Get_Pragma_Id (Parent (P));
15087 C := Sig_Flags (Id);
15099 -- For pragma Check, the first argument is not significant,
15100 -- the second and the third (if present) arguments are
15103 when Pragma_Check =>
15105 P = First (Pragma_Argument_Associations (Parent (P)));
15108 raise Program_Error;
15112 A := First (Pragma_Argument_Associations (Parent (P)));
15113 for J in 1 .. C - 1 loop
15121 return A = P; -- is this wrong way round ???
15124 end Is_Non_Significant_Pragma_Reference;
15126 ------------------------------
15127 -- Is_Pragma_String_Literal --
15128 ------------------------------
15130 -- This function returns true if the corresponding pragma argument is a
15131 -- static string expression. These are the only cases in which string
15132 -- literals can appear as pragma arguments. We also allow a string literal
15133 -- as the first argument to pragma Assert (although it will of course
15134 -- always generate a type error).
15136 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
15137 Pragn : constant Node_Id := Parent (Par);
15138 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
15139 Pname : constant Name_Id := Pragma_Name (Pragn);
15145 N := First (Assoc);
15152 if Pname = Name_Assert then
15155 elsif Pname = Name_Export then
15158 elsif Pname = Name_Ident then
15161 elsif Pname = Name_Import then
15164 elsif Pname = Name_Interface_Name then
15167 elsif Pname = Name_Linker_Alias then
15170 elsif Pname = Name_Linker_Section then
15173 elsif Pname = Name_Machine_Attribute then
15176 elsif Pname = Name_Source_File_Name then
15179 elsif Pname = Name_Source_Reference then
15182 elsif Pname = Name_Title then
15185 elsif Pname = Name_Subtitle then
15191 end Is_Pragma_String_Literal;
15193 ------------------------
15194 -- Preanalyze_TC_Args --
15195 ------------------------
15197 procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
15199 -- Preanalyze the boolean expressions, we treat these as spec
15200 -- expressions (i.e. similar to a default expression).
15202 if Present (Arg_Req) then
15203 Preanalyze_Spec_Expression
15204 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
15206 -- In ASIS mode, for a pragma generated from a source aspect, also
15207 -- analyze the original aspect expression.
15210 and then Present (Corresponding_Aspect (N))
15212 Preanalyze_Spec_Expression
15213 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
15217 if Present (Arg_Ens) then
15218 Preanalyze_Spec_Expression
15219 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
15221 -- In ASIS mode, for a pragma generated from a source aspect, also
15222 -- analyze the original aspect expression.
15225 and then Present (Corresponding_Aspect (N))
15227 Preanalyze_Spec_Expression
15228 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
15231 end Preanalyze_TC_Args;
15233 --------------------------------------
15234 -- Process_Compilation_Unit_Pragmas --
15235 --------------------------------------
15237 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
15239 -- A special check for pragma Suppress_All, a very strange DEC pragma,
15240 -- strange because it comes at the end of the unit. Rational has the
15241 -- same name for a pragma, but treats it as a program unit pragma, In
15242 -- GNAT we just decide to allow it anywhere at all. If it appeared then
15243 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
15244 -- node, and we insert a pragma Suppress (All_Checks) at the start of
15245 -- the context clause to ensure the correct processing.
15247 if Has_Pragma_Suppress_All (N) then
15248 Prepend_To (Context_Items (N),
15249 Make_Pragma (Sloc (N),
15250 Chars => Name_Suppress,
15251 Pragma_Argument_Associations => New_List (
15252 Make_Pragma_Argument_Association (Sloc (N),
15253 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
15256 -- Nothing else to do at the current time!
15258 end Process_Compilation_Unit_Pragmas;
15269 --------------------------------
15270 -- Set_Encoded_Interface_Name --
15271 --------------------------------
15273 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
15274 Str : constant String_Id := Strval (S);
15275 Len : constant Int := String_Length (Str);
15280 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
15283 -- Stores encoded value of character code CC. The encoding we use an
15284 -- underscore followed by four lower case hex digits.
15290 procedure Encode is
15292 Store_String_Char (Get_Char_Code ('_'));
15294 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
15296 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
15298 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
15300 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
15303 -- Start of processing for Set_Encoded_Interface_Name
15306 -- If first character is asterisk, this is a link name, and we leave it
15307 -- completely unmodified. We also ignore null strings (the latter case
15308 -- happens only in error cases) and no encoding should occur for Java or
15309 -- AAMP interface names.
15312 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
15313 or else VM_Target /= No_VM
15314 or else AAMP_On_Target
15316 Set_Interface_Name (E, S);
15321 CC := Get_String_Char (Str, J);
15323 exit when not In_Character_Range (CC);
15325 C := Get_Character (CC);
15327 exit when C /= '_' and then C /= '$'
15328 and then C not in '0' .. '9'
15329 and then C not in 'a' .. 'z'
15330 and then C not in 'A' .. 'Z';
15333 Set_Interface_Name (E, S);
15341 -- Here we need to encode. The encoding we use as follows:
15342 -- three underscores + four hex digits (lower case)
15346 for J in 1 .. String_Length (Str) loop
15347 CC := Get_String_Char (Str, J);
15349 if not In_Character_Range (CC) then
15352 C := Get_Character (CC);
15354 if C = '_' or else C = '$'
15355 or else C in '0' .. '9'
15356 or else C in 'a' .. 'z'
15357 or else C in 'A' .. 'Z'
15359 Store_String_Char (CC);
15366 Set_Interface_Name (E,
15367 Make_String_Literal (Sloc (S),
15368 Strval => End_String));
15370 end Set_Encoded_Interface_Name;
15372 -------------------
15373 -- Set_Unit_Name --
15374 -------------------
15376 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15381 if Nkind (N) = N_Identifier
15382 and then Nkind (With_Item) = N_Identifier
15384 Set_Entity (N, Entity (With_Item));
15386 elsif Nkind (N) = N_Selected_Component then
15387 Change_Selected_Component_To_Expanded_Name (N);
15388 Set_Entity (N, Entity (With_Item));
15389 Set_Entity (Selector_Name (N), Entity (N));
15391 Pref := Prefix (N);
15392 Scop := Scope (Entity (N));
15393 while Nkind (Pref) = N_Selected_Component loop
15394 Change_Selected_Component_To_Expanded_Name (Pref);
15395 Set_Entity (Selector_Name (Pref), Scop);
15396 Set_Entity (Pref, Scop);
15397 Pref := Prefix (Pref);
15398 Scop := Scope (Scop);
15401 Set_Entity (Pref, Scop);