1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Aspects; use Aspects;
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Checks; use Checks;
36 with Csets; use Csets;
37 with Debug; use Debug;
38 with Einfo; use Einfo;
39 with Elists; use Elists;
40 with Errout; use Errout;
41 with Exp_Dist; use Exp_Dist;
42 with Exp_Util; use Exp_Util;
43 with Freeze; use Freeze;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet.Sp; use Namet.Sp;
48 with Nlists; use Nlists;
49 with Nmake; use Nmake;
51 with Output; use Output;
52 with Par_SCO; use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident; use Rident;
55 with Rtsfind; use Rtsfind;
57 with Sem_Aux; use Sem_Aux;
58 with Sem_Ch3; use Sem_Ch3;
59 with Sem_Ch6; use Sem_Ch6;
60 with Sem_Ch8; use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res; use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_VFpt; use Sem_VFpt;
73 with Sem_Warn; use Sem_Warn;
74 with Stand; use Stand;
75 with Sinfo; use Sinfo;
76 with Sinfo.CN; use Sinfo.CN;
77 with Sinput; use Sinput;
78 with Snames; use Snames;
79 with Stringt; use Stringt;
80 with Stylesw; use Stylesw;
82 with Targparm; use Targparm;
83 with Tbuild; use Tbuild;
85 with Uintp; use Uintp;
86 with Uname; use Uname;
87 with Urealp; use Urealp;
88 with Validsw; use Validsw;
89 with Warnsw; use Warnsw;
91 package body Sem_Prag is
93 ----------------------------------------------
94 -- Common Handling of Import-Export Pragmas --
95 ----------------------------------------------
97 -- In the following section, a number of Import_xxx and Export_xxx pragmas
98 -- are defined by GNAT. These are compatible with the DEC pragmas of the
99 -- same name, and all have the following common form and processing:
102 -- [Internal =>] LOCAL_NAME
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
107 -- [Internal =>] LOCAL_NAME
108 -- [, [External =>] EXTERNAL_SYMBOL]
109 -- [, other optional parameters ]);
111 -- EXTERNAL_SYMBOL ::=
113 -- | static_string_EXPRESSION
115 -- The internal LOCAL_NAME designates the entity that is imported or
116 -- exported, and must refer to an entity in the current declarative
117 -- part (as required by the rules for LOCAL_NAME).
119 -- The external linker name is designated by the External parameter if
120 -- given, or the Internal parameter if not (if there is no External
121 -- parameter, the External parameter is a copy of the Internal name).
123 -- If the External parameter is given as a string, then this string is
124 -- treated as an external name (exactly as though it had been given as an
125 -- External_Name parameter for a normal Import pragma).
127 -- If the External parameter is given as an identifier (or there is no
128 -- External parameter, so that the Internal identifier is used), then
129 -- the external name is the characters of the identifier, translated
130 -- to all upper case letters for OpenVMS versions of GNAT, and to all
131 -- lower case letters for all other versions
133 -- Note: the external name specified or implied by any of these special
134 -- Import_xxx or Export_xxx pragmas override an external or link name
135 -- specified in a previous Import or Export pragma.
137 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
138 -- named notation, following the standard rules for subprogram calls, i.e.
139 -- parameters can be given in any order if named notation is used, and
140 -- positional and named notation can be mixed, subject to the rule that all
141 -- positional parameters must appear first.
143 -- Note: All these pragmas are implemented exactly following the DEC design
144 -- and implementation and are intended to be fully compatible with the use
145 -- of these pragmas in the DEC Ada compiler.
147 --------------------------------------------
148 -- Checking for Duplicated External Names --
149 --------------------------------------------
151 -- It is suspicious if two separate Export pragmas use the same external
152 -- name. The following table is used to diagnose this situation so that
153 -- an appropriate warning can be issued.
155 -- The Node_Id stored is for the N_String_Literal node created to hold
156 -- the value of the external name. The Sloc of this node is used to
157 -- cross-reference the location of the duplication.
159 package Externals is new Table.Table (
160 Table_Component_Type => Node_Id,
161 Table_Index_Type => Int,
162 Table_Low_Bound => 0,
163 Table_Initial => 100,
164 Table_Increment => 100,
165 Table_Name => "Name_Externals");
167 -------------------------------------
168 -- Local Subprograms and Variables --
169 -------------------------------------
171 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
172 -- This routine is used for possible casing adjustment of an explicit
173 -- external name supplied as a string literal (the node N), according to
174 -- the casing requirement of Opt.External_Name_Casing. If this is set to
175 -- As_Is, then the string literal is returned unchanged, but if it is set
176 -- to Uppercase or Lowercase, then a new string literal with appropriate
177 -- casing is constructed.
179 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
180 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
181 -- original one, following the renaming chain) is returned. Otherwise the
182 -- entity is returned unchanged. Should be in Einfo???
184 procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id);
185 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
186 -- of a Test_Case pragma if present (possibly Empty). We treat these as
187 -- spec expressions (i.e. similar to a default expression).
190 -- This is a dummy function called by the processing for pragma Reviewable.
191 -- It is there for assisting front end debugging. By placing a Reviewable
192 -- pragma in the source program, a breakpoint on rv catches this place in
193 -- the source, allowing convenient stepping to the point of interest.
195 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
196 -- Place semantic information on the argument of an Elaborate/Elaborate_All
197 -- pragma. Entity name for unit and its parents is taken from item in
198 -- previous with_clause that mentions the unit.
200 -------------------------------
201 -- Adjust_External_Name_Case --
202 -------------------------------
204 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
208 -- Adjust case of literal if required
210 if Opt.External_Name_Exp_Casing = As_Is then
214 -- Copy existing string
220 for J in 1 .. String_Length (Strval (N)) loop
221 CC := Get_String_Char (Strval (N), J);
223 if Opt.External_Name_Exp_Casing = Uppercase
224 and then CC >= Get_Char_Code ('a')
225 and then CC <= Get_Char_Code ('z')
227 Store_String_Char (CC - 32);
229 elsif Opt.External_Name_Exp_Casing = Lowercase
230 and then CC >= Get_Char_Code ('A')
231 and then CC <= Get_Char_Code ('Z')
233 Store_String_Char (CC + 32);
236 Store_String_Char (CC);
241 Make_String_Literal (Sloc (N),
242 Strval => End_String);
244 end Adjust_External_Name_Case;
246 ------------------------------
247 -- Analyze_PPC_In_Decl_Part --
248 ------------------------------
250 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
251 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
254 -- Install formals and push subprogram spec onto scope stack so that we
255 -- can see the formals from the pragma.
260 -- Preanalyze the boolean expression, we treat this as a spec expression
261 -- (i.e. similar to a default expression).
263 Preanalyze_Spec_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
265 -- In ASIS mode, for a pragma generated from a source aspect, also
266 -- analyze the original aspect expression.
269 and then Present (Corresponding_Aspect (N))
271 Preanalyze_Spec_Expression
272 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
275 -- For a class-wide condition, a reference to a controlling formal must
276 -- be interpreted as having the class-wide type (or an access to such)
277 -- so that the inherited condition can be properly applied to any
278 -- overriding operation (see ARM12 6.6.1 (7)).
280 if Class_Present (N) then
282 T : constant Entity_Id := Find_Dispatching_Type (S);
284 ACW : Entity_Id := Empty;
285 -- Access to T'class, created if there is a controlling formal
286 -- that is an access parameter.
288 function Get_ACW return Entity_Id;
289 -- If the expression has a reference to an controlling access
290 -- parameter, create an access to T'class for the necessary
291 -- conversions if one does not exist.
293 function Process (N : Node_Id) return Traverse_Result;
294 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
295 -- aspect for a primitive subprogram of a tagged type T, a name
296 -- that denotes a formal parameter of type T is interpreted as
297 -- having type T'Class. Similarly, a name that denotes a formal
298 -- accessparameter of type access-to-T is interpreted as having
299 -- type access-to-T'Class. This ensures the expression is well-
300 -- defined for a primitive subprogram of a type descended from T.
306 function Get_ACW return Entity_Id is
307 Loc : constant Source_Ptr := Sloc (N);
312 Decl := Make_Full_Type_Declaration (Loc,
313 Defining_Identifier => Make_Temporary (Loc, 'T'),
315 Make_Access_To_Object_Definition (Loc,
316 Subtype_Indication =>
317 New_Occurrence_Of (Class_Wide_Type (T), Loc),
318 All_Present => True));
320 Insert_Before (Unit_Declaration_Node (S), Decl);
322 ACW := Defining_Identifier (Decl);
323 Freeze_Before (Unit_Declaration_Node (S), ACW);
333 function Process (N : Node_Id) return Traverse_Result is
334 Loc : constant Source_Ptr := Sloc (N);
338 if Is_Entity_Name (N)
339 and then Is_Formal (Entity (N))
340 and then Nkind (Parent (N)) /= N_Type_Conversion
342 if Etype (Entity (N)) = T then
343 Typ := Class_Wide_Type (T);
345 elsif Is_Access_Type (Etype (Entity (N)))
346 and then Designated_Type (Etype (Entity (N))) = T
353 if Present (Typ) then
355 Make_Type_Conversion (Loc,
357 New_Occurrence_Of (Typ, Loc),
358 Expression => New_Occurrence_Of (Entity (N), Loc)));
366 procedure Replace_Type is new Traverse_Proc (Process);
369 Replace_Type (Get_Pragma_Arg (Arg1));
373 -- Remove the subprogram from the scope stack now that the pre-analysis
374 -- of the precondition/postcondition is done.
377 end Analyze_PPC_In_Decl_Part;
383 procedure Analyze_Pragma (N : Node_Id) is
384 Loc : constant Source_Ptr := Sloc (N);
388 -- Name of the source pragma, or name of the corresponding aspect for
389 -- pragmas which originate in a source aspect. In the latter case, the
390 -- name may be different from the pragma name.
392 Pragma_Exit : exception;
393 -- This exception is used to exit pragma processing completely. It is
394 -- used when an error is detected, and no further processing is
395 -- required. It is also used if an earlier error has left the tree in
396 -- a state where the pragma should not be processed.
399 -- Number of pragma argument associations
405 -- First four pragma arguments (pragma argument association nodes, or
406 -- Empty if the corresponding argument does not exist).
408 type Name_List is array (Natural range <>) of Name_Id;
409 type Args_List is array (Natural range <>) of Node_Id;
410 -- Types used for arguments to Check_Arg_Order and Gather_Associations
412 procedure Ada_2005_Pragma;
413 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
414 -- Ada 95 mode, these are implementation defined pragmas, so should be
415 -- caught by the No_Implementation_Pragmas restriction.
417 procedure Ada_2012_Pragma;
418 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
419 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
420 -- should be caught by the No_Implementation_Pragmas restriction.
422 procedure Check_Ada_83_Warning;
423 -- Issues a warning message for the current pragma if operating in Ada
424 -- 83 mode (used for language pragmas that are not a standard part of
425 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
428 procedure Check_Arg_Count (Required : Nat);
429 -- Check argument count for pragma is equal to given parameter. If not,
430 -- then issue an error message and raise Pragma_Exit.
432 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
433 -- Arg which can either be a pragma argument association, in which case
434 -- the check is applied to the expression of the association or an
435 -- expression directly.
437 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
438 -- Check that an argument has the right form for an EXTERNAL_NAME
439 -- parameter of an extended import/export pragma. The rule is that the
440 -- name must be an identifier or string literal (in Ada 83 mode) or a
441 -- static string expression (in Ada 95 mode).
443 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
444 -- Check the specified argument Arg to make sure that it is an
445 -- identifier. If not give error and raise Pragma_Exit.
447 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
448 -- Check the specified argument Arg to make sure that it is an integer
449 -- literal. If not give error and raise Pragma_Exit.
451 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
452 -- Check the specified argument Arg to make sure that it has the proper
453 -- syntactic form for a local name and meets the semantic requirements
454 -- for a local name. The local name is analyzed as part of the
455 -- processing for this call. In addition, the local name is required
456 -- to represent an entity at the library level.
458 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
459 -- Check the specified argument Arg to make sure that it has the proper
460 -- syntactic form for a local name and meets the semantic requirements
461 -- for a local name. The local name is analyzed as part of the
462 -- processing for this call.
464 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
465 -- Check the specified argument Arg to make sure that it is a valid
466 -- locking policy name. If not give error and raise Pragma_Exit.
468 procedure Check_Arg_Is_One_Of
471 procedure Check_Arg_Is_One_Of
473 N1, N2, N3 : Name_Id);
474 procedure Check_Arg_Is_One_Of
476 N1, N2, N3, N4, N5 : Name_Id);
477 -- Check the specified argument Arg to make sure that it is an
478 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
479 -- present). If not then give error and raise Pragma_Exit.
481 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
482 -- Check the specified argument Arg to make sure that it is a valid
483 -- queuing policy name. If not give error and raise Pragma_Exit.
485 procedure Check_Arg_Is_Static_Expression
487 Typ : Entity_Id := Empty);
488 -- Check the specified argument Arg to make sure that it is a static
489 -- expression of the given type (i.e. it will be analyzed and resolved
490 -- using this type, which can be any valid argument to Resolve, e.g.
491 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
492 -- Typ is left Empty, then any static expression is allowed.
494 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
495 -- Check the specified argument Arg to make sure that it is a valid task
496 -- dispatching policy name. If not give error and raise Pragma_Exit.
498 procedure Check_Arg_Order (Names : Name_List);
499 -- Checks for an instance of two arguments with identifiers for the
500 -- current pragma which are not in the sequence indicated by Names,
501 -- and if so, generates a fatal message about bad order of arguments.
503 procedure Check_At_Least_N_Arguments (N : Nat);
504 -- Check there are at least N arguments present
506 procedure Check_At_Most_N_Arguments (N : Nat);
507 -- Check there are no more than N arguments present
509 procedure Check_Component
512 In_Variant_Part : Boolean := False);
513 -- Examine an Unchecked_Union component for correct use of per-object
514 -- constrained subtypes, and for restrictions on finalizable components.
515 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
516 -- should be set when Comp comes from a record variant.
518 procedure Check_Duplicate_Pragma (E : Entity_Id);
519 -- Check if a pragma of the same name as the current pragma is already
520 -- chained as a rep pragma to the given entity. If so give a message
521 -- about the duplicate, and then raise Pragma_Exit so does not return.
522 -- Also checks for delayed aspect specification node in the chain.
524 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
525 -- Nam is an N_String_Literal node containing the external name set by
526 -- an Import or Export pragma (or extended Import or Export pragma).
527 -- This procedure checks for possible duplications if this is the export
528 -- case, and if found, issues an appropriate error message.
530 procedure Check_Expr_Is_Static_Expression
532 Typ : Entity_Id := Empty);
533 -- Check the specified expression Expr to make sure that it is a static
534 -- expression of the given type (i.e. it will be analyzed and resolved
535 -- using this type, which can be any valid argument to Resolve, e.g.
536 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
537 -- Typ is left Empty, then any static expression is allowed.
539 procedure Check_First_Subtype (Arg : Node_Id);
540 -- Checks that Arg, whose expression is an entity name, references a
543 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
544 -- Checks that the given argument has an identifier, and if so, requires
545 -- it to match the given identifier name. If there is no identifier, or
546 -- a non-matching identifier, then an error message is given and
547 -- Pragma_Exit is raised.
549 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
550 -- Checks that the given argument has an identifier, and if so, requires
551 -- it to match one of the given identifier names. If there is no
552 -- identifier, or a non-matching identifier, then an error message is
553 -- given and Pragma_Exit is raised.
555 procedure Check_In_Main_Program;
556 -- Common checks for pragmas that appear within a main program
557 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
559 procedure Check_Interrupt_Or_Attach_Handler;
560 -- Common processing for first argument of pragma Interrupt_Handler or
561 -- pragma Attach_Handler.
563 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
564 -- Check that pragma appears in a declarative part, or in a package
565 -- specification, i.e. that it does not occur in a statement sequence
568 procedure Check_No_Identifier (Arg : Node_Id);
569 -- Checks that the given argument does not have an identifier. If
570 -- an identifier is present, then an error message is issued, and
571 -- Pragma_Exit is raised.
573 procedure Check_No_Identifiers;
574 -- Checks that none of the arguments to the pragma has an identifier.
575 -- If any argument has an identifier, then an error message is issued,
576 -- and Pragma_Exit is raised.
578 procedure Check_No_Link_Name;
579 -- Checks that no link name is specified
581 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
582 -- Checks if the given argument has an identifier, and if so, requires
583 -- it to match the given identifier name. If there is a non-matching
584 -- identifier, then an error message is given and Pragma_Exit is raised.
586 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
587 -- Checks if the given argument has an identifier, and if so, requires
588 -- it to match the given identifier name. If there is a non-matching
589 -- identifier, then an error message is given and Pragma_Exit is raised.
590 -- In this version of the procedure, the identifier name is given as
591 -- a string with lower case letters.
593 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
594 -- Called to process a precondition or postcondition pragma. There are
597 -- The pragma appears after a subprogram spec
599 -- If the corresponding check is not enabled, the pragma is analyzed
600 -- but otherwise ignored and control returns with In_Body set False.
602 -- If the check is enabled, then the first step is to analyze the
603 -- pragma, but this is skipped if the subprogram spec appears within
604 -- a package specification (because this is the case where we delay
605 -- analysis till the end of the spec). Then (whether or not it was
606 -- analyzed), the pragma is chained to the subprogram in question
607 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
608 -- caller with In_Body set False.
610 -- The pragma appears at the start of subprogram body declarations
612 -- In this case an immediate return to the caller is made with
613 -- In_Body set True, and the pragma is NOT analyzed.
615 -- In all other cases, an error message for bad placement is given
617 procedure Check_Static_Constraint (Constr : Node_Id);
618 -- Constr is a constraint from an N_Subtype_Indication node from a
619 -- component constraint in an Unchecked_Union type. This routine checks
620 -- that the constraint is static as required by the restrictions for
623 procedure Check_Test_Case;
624 -- Called to process a test-case pragma. The treatment is similar to the
625 -- one for pre- and postcondition in Check_Precondition_Postcondition,
626 -- except the placement rules for the test-case pragma are stricter.
627 -- This pragma may only occur after a subprogram spec declared directly
628 -- in a package spec unit. In this case, the pragma is chained to the
629 -- subprogram in question (using Spec_TC_List and Next_Pragma) and
630 -- analysis of the pragma is delayed till the end of the spec. In
631 -- all other cases, an error message for bad placement is given.
633 procedure Check_Valid_Configuration_Pragma;
634 -- Legality checks for placement of a configuration pragma
636 procedure Check_Valid_Library_Unit_Pragma;
637 -- Legality checks for library unit pragmas. A special case arises for
638 -- pragmas in generic instances that come from copies of the original
639 -- library unit pragmas in the generic templates. In the case of other
640 -- than library level instantiations these can appear in contexts which
641 -- would normally be invalid (they only apply to the original template
642 -- and to library level instantiations), and they are simply ignored,
643 -- which is implemented by rewriting them as null statements.
645 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
646 -- Check an Unchecked_Union variant for lack of nested variants and
647 -- presence of at least one component. UU_Typ is the related Unchecked_
650 procedure Error_Pragma (Msg : String);
651 pragma No_Return (Error_Pragma);
652 -- Outputs error message for current pragma. The message contains a %
653 -- that will be replaced with the pragma name, and the flag is placed
654 -- on the pragma itself. Pragma_Exit is then raised.
656 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
657 pragma No_Return (Error_Pragma_Arg);
658 -- Outputs error message for current pragma. The message may contain
659 -- a % that will be replaced with the pragma name. The parameter Arg
660 -- may either be a pragma argument association, in which case the flag
661 -- is placed on the expression of this association, or an expression,
662 -- in which case the flag is placed directly on the expression. The
663 -- message is placed using Error_Msg_N, so the message may also contain
664 -- an & insertion character which will reference the given Arg value.
665 -- After placing the message, Pragma_Exit is raised.
667 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
668 pragma No_Return (Error_Pragma_Arg);
669 -- Similar to above form of Error_Pragma_Arg except that two messages
670 -- are provided, the second is a continuation comment starting with \.
672 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
673 pragma No_Return (Error_Pragma_Arg_Ident);
674 -- Outputs error message for current pragma. The message may contain
675 -- a % that will be replaced with the pragma name. The parameter Arg
676 -- must be a pragma argument association with a non-empty identifier
677 -- (i.e. its Chars field must be set), and the error message is placed
678 -- on the identifier. The message is placed using Error_Msg_N so
679 -- the message may also contain an & insertion character which will
680 -- reference the identifier. After placing the message, Pragma_Exit
683 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
684 pragma No_Return (Error_Pragma_Ref);
685 -- Outputs error message for current pragma. The message may contain
686 -- a % that will be replaced with the pragma name. The parameter Ref
687 -- must be an entity whose name can be referenced by & and sloc by #.
688 -- After placing the message, Pragma_Exit is raised.
690 function Find_Lib_Unit_Name return Entity_Id;
691 -- Used for a library unit pragma to find the entity to which the
692 -- library unit pragma applies, returns the entity found.
694 procedure Find_Program_Unit_Name (Id : Node_Id);
695 -- If the pragma is a compilation unit pragma, the id must denote the
696 -- compilation unit in the same compilation, and the pragma must appear
697 -- in the list of preceding or trailing pragmas. If it is a program
698 -- unit pragma that is not a compilation unit pragma, then the
699 -- identifier must be visible.
701 function Find_Unique_Parameterless_Procedure
703 Arg : Node_Id) return Entity_Id;
704 -- Used for a procedure pragma to find the unique parameterless
705 -- procedure identified by Name, returns it if it exists, otherwise
706 -- errors out and uses Arg as the pragma argument for the message.
708 procedure Fix_Error (Msg : in out String);
709 -- This is called prior to issuing an error message. Msg is a string
710 -- which typically contains the substring pragma. If the current pragma
711 -- comes from an aspect, each such "pragma" substring is replaced with
712 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
713 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
715 procedure Gather_Associations
717 Args : out Args_List);
718 -- This procedure is used to gather the arguments for a pragma that
719 -- permits arbitrary ordering of parameters using the normal rules
720 -- for named and positional parameters. The Names argument is a list
721 -- of Name_Id values that corresponds to the allowed pragma argument
722 -- association identifiers in order. The result returned in Args is
723 -- a list of corresponding expressions that are the pragma arguments.
724 -- Note that this is a list of expressions, not of pragma argument
725 -- associations (Gather_Associations has completely checked all the
726 -- optional identifiers when it returns). An entry in Args is Empty
727 -- on return if the corresponding argument is not present.
729 procedure GNAT_Pragma;
730 -- Called for all GNAT defined pragmas to check the relevant restriction
731 -- (No_Implementation_Pragmas).
733 function Is_Before_First_Decl
734 (Pragma_Node : Node_Id;
735 Decls : List_Id) return Boolean;
736 -- Return True if Pragma_Node is before the first declarative item in
737 -- Decls where Decls is the list of declarative items.
739 function Is_Configuration_Pragma return Boolean;
740 -- Determines if the placement of the current pragma is appropriate
741 -- for a configuration pragma.
743 function Is_In_Context_Clause return Boolean;
744 -- Returns True if pragma appears within the context clause of a unit,
745 -- and False for any other placement (does not generate any messages).
747 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
748 -- Analyzes the argument, and determines if it is a static string
749 -- expression, returns True if so, False if non-static or not String.
751 procedure Pragma_Misplaced;
752 pragma No_Return (Pragma_Misplaced);
753 -- Issue fatal error message for misplaced pragma
755 procedure Process_Atomic_Shared_Volatile;
756 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
757 -- Shared is an obsolete Ada 83 pragma, treated as being identical
758 -- in effect to pragma Atomic.
760 procedure Process_Compile_Time_Warning_Or_Error;
761 -- Common processing for Compile_Time_Error and Compile_Time_Warning
763 procedure Process_Convention
764 (C : out Convention_Id;
765 Ent : out Entity_Id);
766 -- Common processing for Convention, Interface, Import and Export.
767 -- Checks first two arguments of pragma, and sets the appropriate
768 -- convention value in the specified entity or entities. On return
769 -- C is the convention, Ent is the referenced entity.
771 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
772 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
773 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
775 procedure Process_Extended_Import_Export_Exception_Pragma
776 (Arg_Internal : Node_Id;
777 Arg_External : Node_Id;
780 -- Common processing for the pragmas Import/Export_Exception. The three
781 -- arguments correspond to the three named parameters of the pragma. An
782 -- argument is empty if the corresponding parameter is not present in
785 procedure Process_Extended_Import_Export_Object_Pragma
786 (Arg_Internal : Node_Id;
787 Arg_External : Node_Id;
789 -- Common processing for the pragmas Import/Export_Object. The three
790 -- arguments correspond to the three named parameters of the pragmas. An
791 -- argument is empty if the corresponding parameter is not present in
794 procedure Process_Extended_Import_Export_Internal_Arg
795 (Arg_Internal : Node_Id := Empty);
796 -- Common processing for all extended Import and Export pragmas. The
797 -- argument is the pragma parameter for the Internal argument. If
798 -- Arg_Internal is empty or inappropriate, an error message is posted.
799 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
800 -- set to identify the referenced entity.
802 procedure Process_Extended_Import_Export_Subprogram_Pragma
803 (Arg_Internal : Node_Id;
804 Arg_External : Node_Id;
805 Arg_Parameter_Types : Node_Id;
806 Arg_Result_Type : Node_Id := Empty;
807 Arg_Mechanism : Node_Id;
808 Arg_Result_Mechanism : Node_Id := Empty;
809 Arg_First_Optional_Parameter : Node_Id := Empty);
810 -- Common processing for all extended Import and Export pragmas applying
811 -- to subprograms. The caller omits any arguments that do not apply to
812 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
813 -- only in the Import_Function and Export_Function cases). The argument
814 -- names correspond to the allowed pragma association identifiers.
816 procedure Process_Generic_List;
817 -- Common processing for Share_Generic and Inline_Generic
819 procedure Process_Import_Or_Interface;
820 -- Common processing for Import of Interface
822 procedure Process_Import_Predefined_Type;
823 -- Processing for completing a type with pragma Import. This is used
824 -- to declare types that match predefined C types, especially for cases
825 -- without corresponding Ada predefined type.
827 procedure Process_Inline (Active : Boolean);
828 -- Common processing for Inline and Inline_Always. The parameter
829 -- indicates if the inline pragma is active, i.e. if it should actually
830 -- cause inlining to occur.
832 procedure Process_Interface_Name
833 (Subprogram_Def : Entity_Id;
836 -- Given the last two arguments of pragma Import, pragma Export, or
837 -- pragma Interface_Name, performs validity checks and sets the
838 -- Interface_Name field of the given subprogram entity to the
839 -- appropriate external or link name, depending on the arguments given.
840 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
841 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
842 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
843 -- nor Link_Arg is present, the interface name is set to the default
844 -- from the subprogram name.
846 procedure Process_Interrupt_Or_Attach_Handler;
847 -- Common processing for Interrupt and Attach_Handler pragmas
849 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
850 -- Common processing for Restrictions and Restriction_Warnings pragmas.
851 -- Warn is True for Restriction_Warnings, or for Restrictions if the
852 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
853 -- is not set in the Restrictions case.
855 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
856 -- Common processing for Suppress and Unsuppress. The boolean parameter
857 -- Suppress_Case is True for the Suppress case, and False for the
860 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
861 -- This procedure sets the Is_Exported flag for the given entity,
862 -- checking that the entity was not previously imported. Arg is
863 -- the argument that specified the entity. A check is also made
864 -- for exporting inappropriate entities.
866 procedure Set_Extended_Import_Export_External_Name
867 (Internal_Ent : Entity_Id;
868 Arg_External : Node_Id);
869 -- Common processing for all extended import export pragmas. The first
870 -- argument, Internal_Ent, is the internal entity, which has already
871 -- been checked for validity by the caller. Arg_External is from the
872 -- Import or Export pragma, and may be null if no External parameter
873 -- was present. If Arg_External is present and is a non-null string
874 -- (a null string is treated as the default), then the Interface_Name
875 -- field of Internal_Ent is set appropriately.
877 procedure Set_Imported (E : Entity_Id);
878 -- This procedure sets the Is_Imported flag for the given entity,
879 -- checking that it is not previously exported or imported.
881 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
882 -- Mech is a parameter passing mechanism (see Import_Function syntax
883 -- for MECHANISM_NAME). This routine checks that the mechanism argument
884 -- has the right form, and if not issues an error message. If the
885 -- argument has the right form then the Mechanism field of Ent is
886 -- set appropriately.
888 procedure Set_Ravenscar_Profile (N : Node_Id);
889 -- Activate the set of configuration pragmas and restrictions that make
890 -- up the Ravenscar Profile. N is the corresponding pragma node, which
891 -- is used for error messages on any constructs that violate the
894 ---------------------
895 -- Ada_2005_Pragma --
896 ---------------------
898 procedure Ada_2005_Pragma is
900 if Ada_Version <= Ada_95 then
901 Check_Restriction (No_Implementation_Pragmas, N);
905 ---------------------
906 -- Ada_2012_Pragma --
907 ---------------------
909 procedure Ada_2012_Pragma is
911 if Ada_Version <= Ada_2005 then
912 Check_Restriction (No_Implementation_Pragmas, N);
916 --------------------------
917 -- Check_Ada_83_Warning --
918 --------------------------
920 procedure Check_Ada_83_Warning is
922 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
923 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
925 end Check_Ada_83_Warning;
927 ---------------------
928 -- Check_Arg_Count --
929 ---------------------
931 procedure Check_Arg_Count (Required : Nat) is
933 if Arg_Count /= Required then
934 Error_Pragma ("wrong number of arguments for pragma%");
938 --------------------------------
939 -- Check_Arg_Is_External_Name --
940 --------------------------------
942 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
943 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
946 if Nkind (Argx) = N_Identifier then
950 Analyze_And_Resolve (Argx, Standard_String);
952 if Is_OK_Static_Expression (Argx) then
955 elsif Etype (Argx) = Any_Type then
958 -- An interesting special case, if we have a string literal and
959 -- we are in Ada 83 mode, then we allow it even though it will
960 -- not be flagged as static. This allows expected Ada 83 mode
961 -- use of external names which are string literals, even though
962 -- technically these are not static in Ada 83.
964 elsif Ada_Version = Ada_83
965 and then Nkind (Argx) = N_String_Literal
969 -- Static expression that raises Constraint_Error. This has
970 -- already been flagged, so just exit from pragma processing.
972 elsif Is_Static_Expression (Argx) then
975 -- Here we have a real error (non-static expression)
978 Error_Msg_Name_1 := Pname;
982 "argument for pragma% must be a identifier or "
983 & "static string expression!";
986 Flag_Non_Static_Expr (Msg, Argx);
991 end Check_Arg_Is_External_Name;
993 -----------------------------
994 -- Check_Arg_Is_Identifier --
995 -----------------------------
997 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
998 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1000 if Nkind (Argx) /= N_Identifier then
1002 ("argument for pragma% must be identifier", Argx);
1004 end Check_Arg_Is_Identifier;
1006 ----------------------------------
1007 -- Check_Arg_Is_Integer_Literal --
1008 ----------------------------------
1010 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1011 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1013 if Nkind (Argx) /= N_Integer_Literal then
1015 ("argument for pragma% must be integer literal", Argx);
1017 end Check_Arg_Is_Integer_Literal;
1019 -------------------------------------------
1020 -- Check_Arg_Is_Library_Level_Local_Name --
1021 -------------------------------------------
1025 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1026 -- | library_unit_NAME
1028 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1030 Check_Arg_Is_Local_Name (Arg);
1032 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1033 and then Comes_From_Source (N)
1036 ("argument for pragma% must be library level entity", Arg);
1038 end Check_Arg_Is_Library_Level_Local_Name;
1040 -----------------------------
1041 -- Check_Arg_Is_Local_Name --
1042 -----------------------------
1046 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1047 -- | library_unit_NAME
1049 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1050 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1055 if Nkind (Argx) not in N_Direct_Name
1056 and then (Nkind (Argx) /= N_Attribute_Reference
1057 or else Present (Expressions (Argx))
1058 or else Nkind (Prefix (Argx)) /= N_Identifier)
1059 and then (not Is_Entity_Name (Argx)
1060 or else not Is_Compilation_Unit (Entity (Argx)))
1062 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1065 -- No further check required if not an entity name
1067 if not Is_Entity_Name (Argx) then
1073 Ent : constant Entity_Id := Entity (Argx);
1074 Scop : constant Entity_Id := Scope (Ent);
1076 -- Case of a pragma applied to a compilation unit: pragma must
1077 -- occur immediately after the program unit in the compilation.
1079 if Is_Compilation_Unit (Ent) then
1081 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1084 -- Case of pragma placed immediately after spec
1086 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1089 -- Case of pragma placed immediately after body
1091 elsif Nkind (Decl) = N_Subprogram_Declaration
1092 and then Present (Corresponding_Body (Decl))
1096 (Parent (Unit_Declaration_Node
1097 (Corresponding_Body (Decl))));
1099 -- All other cases are illegal
1106 -- Special restricted placement rule from 10.2.1(11.8/2)
1108 elsif Is_Generic_Formal (Ent)
1109 and then Prag_Id = Pragma_Preelaborable_Initialization
1111 OK := List_Containing (N) =
1112 Generic_Formal_Declarations
1113 (Unit_Declaration_Node (Scop));
1115 -- Default case, just check that the pragma occurs in the scope
1116 -- of the entity denoted by the name.
1119 OK := Current_Scope = Scop;
1124 ("pragma% argument must be in same declarative part", Arg);
1128 end Check_Arg_Is_Local_Name;
1130 ---------------------------------
1131 -- Check_Arg_Is_Locking_Policy --
1132 ---------------------------------
1134 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1135 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1138 Check_Arg_Is_Identifier (Argx);
1140 if not Is_Locking_Policy_Name (Chars (Argx)) then
1141 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1143 end Check_Arg_Is_Locking_Policy;
1145 -------------------------
1146 -- Check_Arg_Is_One_Of --
1147 -------------------------
1149 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1150 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1153 Check_Arg_Is_Identifier (Argx);
1155 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1156 Error_Msg_Name_2 := N1;
1157 Error_Msg_Name_3 := N2;
1158 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1160 end Check_Arg_Is_One_Of;
1162 procedure Check_Arg_Is_One_Of
1164 N1, N2, N3 : Name_Id)
1166 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1169 Check_Arg_Is_Identifier (Argx);
1171 if Chars (Argx) /= N1
1172 and then Chars (Argx) /= N2
1173 and then Chars (Argx) /= N3
1175 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1177 end Check_Arg_Is_One_Of;
1179 procedure Check_Arg_Is_One_Of
1181 N1, N2, N3, N4, N5 : Name_Id)
1183 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1186 Check_Arg_Is_Identifier (Argx);
1188 if Chars (Argx) /= N1
1189 and then Chars (Argx) /= N2
1190 and then Chars (Argx) /= N3
1191 and then Chars (Argx) /= N4
1192 and then Chars (Argx) /= N5
1194 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1196 end Check_Arg_Is_One_Of;
1197 ---------------------------------
1198 -- Check_Arg_Is_Queuing_Policy --
1199 ---------------------------------
1201 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1202 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1205 Check_Arg_Is_Identifier (Argx);
1207 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1208 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1210 end Check_Arg_Is_Queuing_Policy;
1212 ------------------------------------
1213 -- Check_Arg_Is_Static_Expression --
1214 ------------------------------------
1216 procedure Check_Arg_Is_Static_Expression
1218 Typ : Entity_Id := Empty)
1221 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1222 end Check_Arg_Is_Static_Expression;
1224 ------------------------------------------
1225 -- Check_Arg_Is_Task_Dispatching_Policy --
1226 ------------------------------------------
1228 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1229 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1232 Check_Arg_Is_Identifier (Argx);
1234 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1236 ("& is not a valid task dispatching policy name", Argx);
1238 end Check_Arg_Is_Task_Dispatching_Policy;
1240 ---------------------
1241 -- Check_Arg_Order --
1242 ---------------------
1244 procedure Check_Arg_Order (Names : Name_List) is
1247 Highest_So_Far : Natural := 0;
1248 -- Highest index in Names seen do far
1252 for J in 1 .. Arg_Count loop
1253 if Chars (Arg) /= No_Name then
1254 for K in Names'Range loop
1255 if Chars (Arg) = Names (K) then
1256 if K < Highest_So_Far then
1257 Error_Msg_Name_1 := Pname;
1259 ("parameters out of order for pragma%", Arg);
1260 Error_Msg_Name_1 := Names (K);
1261 Error_Msg_Name_2 := Names (Highest_So_Far);
1262 Error_Msg_N ("\% must appear before %", Arg);
1266 Highest_So_Far := K;
1274 end Check_Arg_Order;
1276 --------------------------------
1277 -- Check_At_Least_N_Arguments --
1278 --------------------------------
1280 procedure Check_At_Least_N_Arguments (N : Nat) is
1282 if Arg_Count < N then
1283 Error_Pragma ("too few arguments for pragma%");
1285 end Check_At_Least_N_Arguments;
1287 -------------------------------
1288 -- Check_At_Most_N_Arguments --
1289 -------------------------------
1291 procedure Check_At_Most_N_Arguments (N : Nat) is
1294 if Arg_Count > N then
1296 for J in 1 .. N loop
1298 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1301 end Check_At_Most_N_Arguments;
1303 ---------------------
1304 -- Check_Component --
1305 ---------------------
1307 procedure Check_Component
1310 In_Variant_Part : Boolean := False)
1312 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1313 Sindic : constant Node_Id :=
1314 Subtype_Indication (Component_Definition (Comp));
1315 Typ : constant Entity_Id := Etype (Comp_Id);
1318 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1319 -- object constraint, then the component type shall be an Unchecked_
1322 if Nkind (Sindic) = N_Subtype_Indication
1323 and then Has_Per_Object_Constraint (Comp_Id)
1324 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1327 ("component subtype subject to per-object constraint " &
1328 "must be an Unchecked_Union", Comp);
1330 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1331 -- the body of a generic unit, or within the body of any of its
1332 -- descendant library units, no part of the type of a component
1333 -- declared in a variant_part of the unchecked union type shall be of
1334 -- a formal private type or formal private extension declared within
1335 -- the formal part of the generic unit.
1337 elsif Ada_Version >= Ada_2012
1338 and then In_Generic_Body (UU_Typ)
1339 and then In_Variant_Part
1340 and then Is_Private_Type (Typ)
1341 and then Is_Generic_Type (Typ)
1344 ("component of Unchecked_Union cannot be of generic type", Comp);
1346 elsif Needs_Finalization (Typ) then
1348 ("component of Unchecked_Union cannot be controlled", Comp);
1350 elsif Has_Task (Typ) then
1352 ("component of Unchecked_Union cannot have tasks", Comp);
1354 end Check_Component;
1356 ----------------------------
1357 -- Check_Duplicate_Pragma --
1358 ----------------------------
1360 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1364 -- Nothing to do if this pragma comes from an aspect specification,
1365 -- since we could not be duplicating a pragma, and we dealt with the
1366 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1368 if From_Aspect_Specification (N) then
1372 -- Otherwise current pragma may duplicate previous pragma or a
1373 -- previously given aspect specification for the same pragma.
1375 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1378 Error_Msg_Name_1 := Pragma_Name (N);
1379 Error_Msg_Sloc := Sloc (P);
1381 if Nkind (P) = N_Aspect_Specification
1382 or else From_Aspect_Specification (P)
1384 Error_Msg_NE ("aspect% for & previously given#", N, E);
1386 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1391 end Check_Duplicate_Pragma;
1393 ----------------------------------
1394 -- Check_Duplicated_Export_Name --
1395 ----------------------------------
1397 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1398 String_Val : constant String_Id := Strval (Nam);
1401 -- We are only interested in the export case, and in the case of
1402 -- generics, it is the instance, not the template, that is the
1403 -- problem (the template will generate a warning in any case).
1405 if not Inside_A_Generic
1406 and then (Prag_Id = Pragma_Export
1408 Prag_Id = Pragma_Export_Procedure
1410 Prag_Id = Pragma_Export_Valued_Procedure
1412 Prag_Id = Pragma_Export_Function)
1414 for J in Externals.First .. Externals.Last loop
1415 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1416 Error_Msg_Sloc := Sloc (Externals.Table (J));
1417 Error_Msg_N ("external name duplicates name given#", Nam);
1422 Externals.Append (Nam);
1424 end Check_Duplicated_Export_Name;
1426 -------------------------------------
1427 -- Check_Expr_Is_Static_Expression --
1428 -------------------------------------
1430 procedure Check_Expr_Is_Static_Expression
1432 Typ : Entity_Id := Empty)
1435 if Present (Typ) then
1436 Analyze_And_Resolve (Expr, Typ);
1438 Analyze_And_Resolve (Expr);
1441 if Is_OK_Static_Expression (Expr) then
1444 elsif Etype (Expr) = Any_Type then
1447 -- An interesting special case, if we have a string literal and we
1448 -- are in Ada 83 mode, then we allow it even though it will not be
1449 -- flagged as static. This allows the use of Ada 95 pragmas like
1450 -- Import in Ada 83 mode. They will of course be flagged with
1451 -- warnings as usual, but will not cause errors.
1453 elsif Ada_Version = Ada_83
1454 and then Nkind (Expr) = N_String_Literal
1458 -- Static expression that raises Constraint_Error. This has already
1459 -- been flagged, so just exit from pragma processing.
1461 elsif Is_Static_Expression (Expr) then
1464 -- Finally, we have a real error
1467 Error_Msg_Name_1 := Pname;
1471 "argument for pragma% must be a static expression!";
1474 Flag_Non_Static_Expr (Msg, Expr);
1479 end Check_Expr_Is_Static_Expression;
1481 -------------------------
1482 -- Check_First_Subtype --
1483 -------------------------
1485 procedure Check_First_Subtype (Arg : Node_Id) is
1486 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1487 Ent : constant Entity_Id := Entity (Argx);
1490 if Is_First_Subtype (Ent) then
1493 elsif Is_Type (Ent) then
1495 ("pragma% cannot apply to subtype", Argx);
1497 elsif Is_Object (Ent) then
1499 ("pragma% cannot apply to object, requires a type", Argx);
1503 ("pragma% cannot apply to&, requires a type", Argx);
1505 end Check_First_Subtype;
1507 ----------------------
1508 -- Check_Identifier --
1509 ----------------------
1511 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1514 and then Nkind (Arg) = N_Pragma_Argument_Association
1516 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1517 Error_Msg_Name_1 := Pname;
1518 Error_Msg_Name_2 := Id;
1519 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1523 end Check_Identifier;
1525 --------------------------------
1526 -- Check_Identifier_Is_One_Of --
1527 --------------------------------
1529 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1532 and then Nkind (Arg) = N_Pragma_Argument_Association
1534 if Chars (Arg) = No_Name then
1535 Error_Msg_Name_1 := Pname;
1536 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1539 elsif Chars (Arg) /= N1
1540 and then Chars (Arg) /= N2
1542 Error_Msg_Name_1 := Pname;
1543 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1547 end Check_Identifier_Is_One_Of;
1549 ---------------------------
1550 -- Check_In_Main_Program --
1551 ---------------------------
1553 procedure Check_In_Main_Program is
1554 P : constant Node_Id := Parent (N);
1557 -- Must be at in subprogram body
1559 if Nkind (P) /= N_Subprogram_Body then
1560 Error_Pragma ("% pragma allowed only in subprogram");
1562 -- Otherwise warn if obviously not main program
1564 elsif Present (Parameter_Specifications (Specification (P)))
1565 or else not Is_Compilation_Unit (Defining_Entity (P))
1567 Error_Msg_Name_1 := Pname;
1569 ("?pragma% is only effective in main program", N);
1571 end Check_In_Main_Program;
1573 ---------------------------------------
1574 -- Check_Interrupt_Or_Attach_Handler --
1575 ---------------------------------------
1577 procedure Check_Interrupt_Or_Attach_Handler is
1578 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1579 Handler_Proc, Proc_Scope : Entity_Id;
1584 if Prag_Id = Pragma_Interrupt_Handler then
1585 Check_Restriction (No_Dynamic_Attachment, N);
1588 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1589 Proc_Scope := Scope (Handler_Proc);
1591 -- On AAMP only, a pragma Interrupt_Handler is supported for
1592 -- nonprotected parameterless procedures.
1594 if not AAMP_On_Target
1595 or else Prag_Id = Pragma_Attach_Handler
1597 if Ekind (Proc_Scope) /= E_Protected_Type then
1599 ("argument of pragma% must be protected procedure", Arg1);
1602 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1603 Error_Pragma ("pragma% must be in protected definition");
1607 if not Is_Library_Level_Entity (Proc_Scope)
1608 or else (AAMP_On_Target
1609 and then not Is_Library_Level_Entity (Handler_Proc))
1612 ("argument for pragma% must be library level entity", Arg1);
1615 -- AI05-0033: A pragma cannot appear within a generic body, because
1616 -- instance can be in a nested scope. The check that protected type
1617 -- is itself a library-level declaration is done elsewhere.
1619 -- Note: we omit this check in Codepeer mode to properly handle code
1620 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1622 if Inside_A_Generic then
1623 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1624 and then In_Package_Body (Scope (Current_Scope))
1625 and then not CodePeer_Mode
1627 Error_Pragma ("pragma% cannot be used inside a generic");
1630 end Check_Interrupt_Or_Attach_Handler;
1632 -------------------------------------------
1633 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1634 -------------------------------------------
1636 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1645 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1648 elsif Nkind_In (P, N_Package_Specification,
1653 -- Note: the following tests seem a little peculiar, because
1654 -- they test for bodies, but if we were in the statement part
1655 -- of the body, we would already have hit the handled statement
1656 -- sequence, so the only way we get here is by being in the
1657 -- declarative part of the body.
1659 elsif Nkind_In (P, N_Subprogram_Body,
1670 Error_Pragma ("pragma% is not in declarative part or package spec");
1671 end Check_Is_In_Decl_Part_Or_Package_Spec;
1673 -------------------------
1674 -- Check_No_Identifier --
1675 -------------------------
1677 procedure Check_No_Identifier (Arg : Node_Id) is
1679 if Nkind (Arg) = N_Pragma_Argument_Association
1680 and then Chars (Arg) /= No_Name
1682 Error_Pragma_Arg_Ident
1683 ("pragma% does not permit identifier& here", Arg);
1685 end Check_No_Identifier;
1687 --------------------------
1688 -- Check_No_Identifiers --
1689 --------------------------
1691 procedure Check_No_Identifiers is
1694 if Arg_Count > 0 then
1696 while Present (Arg_Node) loop
1697 Check_No_Identifier (Arg_Node);
1701 end Check_No_Identifiers;
1703 ------------------------
1704 -- Check_No_Link_Name --
1705 ------------------------
1707 procedure Check_No_Link_Name is
1710 and then Chars (Arg3) = Name_Link_Name
1715 if Present (Arg4) then
1717 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1719 end Check_No_Link_Name;
1721 -------------------------------
1722 -- Check_Optional_Identifier --
1723 -------------------------------
1725 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1728 and then Nkind (Arg) = N_Pragma_Argument_Association
1729 and then Chars (Arg) /= No_Name
1731 if Chars (Arg) /= Id then
1732 Error_Msg_Name_1 := Pname;
1733 Error_Msg_Name_2 := Id;
1734 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1738 end Check_Optional_Identifier;
1740 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1742 Name_Buffer (1 .. Id'Length) := Id;
1743 Name_Len := Id'Length;
1744 Check_Optional_Identifier (Arg, Name_Find);
1745 end Check_Optional_Identifier;
1747 --------------------------------------
1748 -- Check_Precondition_Postcondition --
1749 --------------------------------------
1751 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1755 procedure Chain_PPC (PO : Node_Id);
1756 -- If PO is an entry or a [generic] subprogram declaration node, then
1757 -- the precondition/postcondition applies to this subprogram and the
1758 -- processing for the pragma is completed. Otherwise the pragma is
1765 procedure Chain_PPC (PO : Node_Id) is
1770 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1771 if not From_Aspect_Specification (N) then
1773 ("pragma% cannot be applied to abstract subprogram");
1775 elsif Class_Present (N) then
1780 ("aspect % requires ''Class for abstract subprogram");
1783 -- AI05-0230: The same restriction applies to null procedures. For
1784 -- compatibility with earlier uses of the Ada pragma, apply this
1785 -- rule only to aspect specifications.
1787 -- The above discrpency needs documentation. Robert is dubious
1788 -- about whether it is a good idea ???
1790 elsif Nkind (PO) = N_Subprogram_Declaration
1791 and then Nkind (Specification (PO)) = N_Procedure_Specification
1792 and then Null_Present (Specification (PO))
1793 and then From_Aspect_Specification (N)
1794 and then not Class_Present (N)
1797 ("aspect % requires ''Class for null procedure");
1799 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1800 N_Generic_Subprogram_Declaration,
1801 N_Entry_Declaration)
1806 -- Here if we have [generic] subprogram or entry declaration
1808 if Nkind (PO) = N_Entry_Declaration then
1809 S := Defining_Entity (PO);
1811 S := Defining_Unit_Name (Specification (PO));
1814 -- Make sure we do not have the case of a precondition pragma when
1815 -- the Pre'Class aspect is present.
1817 -- We do this by looking at pragmas already chained to the entity
1818 -- since the aspect derived pragma will be put on this list first.
1820 if Pragma_Name (N) = Name_Precondition then
1821 if not From_Aspect_Specification (N) then
1822 P := Spec_PPC_List (Contract (S));
1823 while Present (P) loop
1824 if Pragma_Name (P) = Name_Precondition
1825 and then From_Aspect_Specification (P)
1826 and then Class_Present (P)
1828 Error_Msg_Sloc := Sloc (P);
1830 ("pragma% not allowed, `Pre''Class` aspect given#");
1833 P := Next_Pragma (P);
1838 -- Similarly check for Pre with inherited Pre'Class. Note that
1839 -- we cover the aspect case as well here.
1841 if Pragma_Name (N) = Name_Precondition
1842 and then not Class_Present (N)
1845 Inherited : constant Subprogram_List :=
1846 Inherited_Subprograms (S);
1850 for J in Inherited'Range loop
1851 P := Spec_PPC_List (Contract (Inherited (J)));
1852 while Present (P) loop
1853 if Pragma_Name (P) = Name_Precondition
1854 and then Class_Present (P)
1856 Error_Msg_Sloc := Sloc (P);
1858 ("pragma% not allowed, `Pre''Class` "
1859 & "aspect inherited from#");
1862 P := Next_Pragma (P);
1868 -- Note: we do not analyze the pragma at this point. Instead we
1869 -- delay this analysis until the end of the declarative part in
1870 -- which the pragma appears. This implements the required delay
1871 -- in this analysis, allowing forward references. The analysis
1872 -- happens at the end of Analyze_Declarations.
1874 -- Chain spec PPC pragma to list for subprogram
1876 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1877 Set_Spec_PPC_List (Contract (S), N);
1879 -- Return indicating spec case
1885 -- Start of processing for Check_Precondition_Postcondition
1888 if not Is_List_Member (N) then
1892 -- Preanalyze message argument if present. Visibility in this
1893 -- argument is established at the point of pragma occurrence.
1895 if Arg_Count = 2 then
1896 Check_Optional_Identifier (Arg2, Name_Message);
1897 Preanalyze_Spec_Expression
1898 (Get_Pragma_Arg (Arg2), Standard_String);
1901 -- Record if pragma is disabled
1903 if Check_Enabled (Pname) then
1904 Set_SCO_Pragma_Enabled (Loc);
1907 -- If we are within an inlined body, the legality of the pragma
1908 -- has been checked already.
1910 if In_Inlined_Body then
1915 -- Search prior declarations
1918 while Present (Prev (P)) loop
1921 -- If the previous node is a generic subprogram, do not go to to
1922 -- the original node, which is the unanalyzed tree: we need to
1923 -- attach the pre/postconditions to the analyzed version at this
1924 -- point. They get propagated to the original tree when analyzing
1925 -- the corresponding body.
1927 if Nkind (P) not in N_Generic_Declaration then
1928 PO := Original_Node (P);
1933 -- Skip past prior pragma
1935 if Nkind (PO) = N_Pragma then
1938 -- Skip stuff not coming from source
1940 elsif not Comes_From_Source (PO) then
1942 -- The condition may apply to a subprogram instantiation
1944 if Nkind (PO) = N_Subprogram_Declaration
1945 and then Present (Generic_Parent (Specification (PO)))
1950 elsif Nkind (PO) = N_Subprogram_Declaration
1951 and then In_Instance
1956 -- For all other cases of non source code, do nothing
1962 -- Only remaining possibility is subprogram declaration
1970 -- If we fall through loop, pragma is at start of list, so see if it
1971 -- is at the start of declarations of a subprogram body.
1973 if Nkind (Parent (N)) = N_Subprogram_Body
1974 and then List_Containing (N) = Declarations (Parent (N))
1976 if Operating_Mode /= Generate_Code
1977 or else Inside_A_Generic
1979 -- Analyze pragma expression for correctness and for ASIS use
1981 Preanalyze_Spec_Expression
1982 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1984 -- In ASIS mode, for a pragma generated from a source aspect,
1985 -- also analyze the original aspect expression.
1988 and then Present (Corresponding_Aspect (N))
1990 Preanalyze_Spec_Expression
1991 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
1998 -- See if it is in the pragmas after a library level subprogram
2000 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2002 -- In formal verification mode, analyze pragma expression for
2003 -- correctness, as it is not expanded later.
2006 Analyze_PPC_In_Decl_Part
2007 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2010 Chain_PPC (Unit (Parent (Parent (N))));
2014 -- If we fall through, pragma was misplaced
2017 end Check_Precondition_Postcondition;
2019 -----------------------------
2020 -- Check_Static_Constraint --
2021 -----------------------------
2023 -- Note: for convenience in writing this procedure, in addition to
2024 -- the officially (i.e. by spec) allowed argument which is always a
2025 -- constraint, it also allows ranges and discriminant associations.
2026 -- Above is not clear ???
2028 procedure Check_Static_Constraint (Constr : Node_Id) is
2030 procedure Require_Static (E : Node_Id);
2031 -- Require given expression to be static expression
2033 --------------------
2034 -- Require_Static --
2035 --------------------
2037 procedure Require_Static (E : Node_Id) is
2039 if not Is_OK_Static_Expression (E) then
2040 Flag_Non_Static_Expr
2041 ("non-static constraint not allowed in Unchecked_Union!", E);
2046 -- Start of processing for Check_Static_Constraint
2049 case Nkind (Constr) is
2050 when N_Discriminant_Association =>
2051 Require_Static (Expression (Constr));
2054 Require_Static (Low_Bound (Constr));
2055 Require_Static (High_Bound (Constr));
2057 when N_Attribute_Reference =>
2058 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2059 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2061 when N_Range_Constraint =>
2062 Check_Static_Constraint (Range_Expression (Constr));
2064 when N_Index_Or_Discriminant_Constraint =>
2068 IDC := First (Constraints (Constr));
2069 while Present (IDC) loop
2070 Check_Static_Constraint (IDC);
2078 end Check_Static_Constraint;
2080 ---------------------
2081 -- Check_Test_Case --
2082 ---------------------
2084 procedure Check_Test_Case is
2088 procedure Chain_TC (PO : Node_Id);
2089 -- If PO is a [generic] subprogram declaration node, then the
2090 -- test-case applies to this subprogram and the processing for the
2091 -- pragma is completed. Otherwise the pragma is misplaced.
2097 procedure Chain_TC (PO : Node_Id) is
2101 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2102 if From_Aspect_Specification (N) then
2104 ("aspect% cannot be applied to abstract subprogram");
2107 ("pragma% cannot be applied to abstract subprogram");
2110 elsif Nkind (PO) = N_Entry_Declaration then
2111 if From_Aspect_Specification (N) then
2112 Error_Pragma ("aspect% cannot be applied to entry");
2114 Error_Pragma ("pragma% cannot be applied to entry");
2117 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2118 N_Generic_Subprogram_Declaration)
2123 -- Here if we have [generic] subprogram declaration
2125 S := Defining_Unit_Name (Specification (PO));
2127 -- Note: we do not analyze the pragma at this point. Instead we
2128 -- delay this analysis until the end of the declarative part in
2129 -- which the pragma appears. This implements the required delay
2130 -- in this analysis, allowing forward references. The analysis
2131 -- happens at the end of Analyze_Declarations.
2133 -- There should not be another test case with the same name
2134 -- associated to this subprogram.
2137 Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2141 TC := Spec_TC_List (Contract (S));
2142 while Present (TC) loop
2145 (Name, Get_Name_From_Test_Case_Pragma (TC))
2147 Error_Msg_Sloc := Sloc (TC);
2149 if From_Aspect_Specification (N) then
2150 Error_Pragma ("name for aspect% is already used#");
2152 Error_Pragma ("name for pragma% is already used#");
2156 TC := Next_Pragma (TC);
2160 -- Chain spec TC pragma to list for subprogram
2162 Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2163 Set_Spec_TC_List (Contract (S), N);
2166 -- Start of processing for Check_Test_Case
2169 if not Is_List_Member (N) then
2173 -- Test cases should only appear in package spec unit
2175 if Get_Source_Unit (N) = No_Unit
2176 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2177 N_Package_Declaration,
2178 N_Generic_Package_Declaration)
2183 -- Search prior declarations
2186 while Present (Prev (P)) loop
2189 -- If the previous node is a generic subprogram, do not go to to
2190 -- the original node, which is the unanalyzed tree: we need to
2191 -- attach the test-case to the analyzed version at this point.
2192 -- They get propagated to the original tree when analyzing the
2193 -- corresponding body.
2195 if Nkind (P) not in N_Generic_Declaration then
2196 PO := Original_Node (P);
2201 -- Skip past prior pragma
2203 if Nkind (PO) = N_Pragma then
2206 -- Skip stuff not coming from source
2208 elsif not Comes_From_Source (PO) then
2211 -- Only remaining possibility is subprogram declaration. First
2212 -- check that it is declared directly in a package declaration.
2213 -- This may be either the package declaration for the current unit
2214 -- being defined or a local package declaration.
2216 elsif not Present (Parent (Parent (PO)))
2217 or else not Present (Parent (Parent (Parent (PO))))
2218 or else not Nkind_In (Parent (Parent (PO)),
2219 N_Package_Declaration,
2220 N_Generic_Package_Declaration)
2230 -- If we fall through, pragma was misplaced
2233 end Check_Test_Case;
2235 --------------------------------------
2236 -- Check_Valid_Configuration_Pragma --
2237 --------------------------------------
2239 -- A configuration pragma must appear in the context clause of a
2240 -- compilation unit, and only other pragmas may precede it. Note that
2241 -- the test also allows use in a configuration pragma file.
2243 procedure Check_Valid_Configuration_Pragma is
2245 if not Is_Configuration_Pragma then
2246 Error_Pragma ("incorrect placement for configuration pragma%");
2248 end Check_Valid_Configuration_Pragma;
2250 -------------------------------------
2251 -- Check_Valid_Library_Unit_Pragma --
2252 -------------------------------------
2254 procedure Check_Valid_Library_Unit_Pragma is
2256 Parent_Node : Node_Id;
2257 Unit_Name : Entity_Id;
2258 Unit_Kind : Node_Kind;
2259 Unit_Node : Node_Id;
2260 Sindex : Source_File_Index;
2263 if not Is_List_Member (N) then
2267 Plist := List_Containing (N);
2268 Parent_Node := Parent (Plist);
2270 if Parent_Node = Empty then
2273 -- Case of pragma appearing after a compilation unit. In this case
2274 -- it must have an argument with the corresponding name and must
2275 -- be part of the following pragmas of its parent.
2277 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2278 if Plist /= Pragmas_After (Parent_Node) then
2281 elsif Arg_Count = 0 then
2283 ("argument required if outside compilation unit");
2286 Check_No_Identifiers;
2287 Check_Arg_Count (1);
2288 Unit_Node := Unit (Parent (Parent_Node));
2289 Unit_Kind := Nkind (Unit_Node);
2291 Analyze (Get_Pragma_Arg (Arg1));
2293 if Unit_Kind = N_Generic_Subprogram_Declaration
2294 or else Unit_Kind = N_Subprogram_Declaration
2296 Unit_Name := Defining_Entity (Unit_Node);
2298 elsif Unit_Kind in N_Generic_Instantiation then
2299 Unit_Name := Defining_Entity (Unit_Node);
2302 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2305 if Chars (Unit_Name) /=
2306 Chars (Entity (Get_Pragma_Arg (Arg1)))
2309 ("pragma% argument is not current unit name", Arg1);
2312 if Ekind (Unit_Name) = E_Package
2313 and then Present (Renamed_Entity (Unit_Name))
2315 Error_Pragma ("pragma% not allowed for renamed package");
2319 -- Pragma appears other than after a compilation unit
2322 -- Here we check for the generic instantiation case and also
2323 -- for the case of processing a generic formal package. We
2324 -- detect these cases by noting that the Sloc on the node
2325 -- does not belong to the current compilation unit.
2327 Sindex := Source_Index (Current_Sem_Unit);
2329 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2330 Rewrite (N, Make_Null_Statement (Loc));
2333 -- If before first declaration, the pragma applies to the
2334 -- enclosing unit, and the name if present must be this name.
2336 elsif Is_Before_First_Decl (N, Plist) then
2337 Unit_Node := Unit_Declaration_Node (Current_Scope);
2338 Unit_Kind := Nkind (Unit_Node);
2340 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2343 elsif Unit_Kind = N_Subprogram_Body
2344 and then not Acts_As_Spec (Unit_Node)
2348 elsif Nkind (Parent_Node) = N_Package_Body then
2351 elsif Nkind (Parent_Node) = N_Package_Specification
2352 and then Plist = Private_Declarations (Parent_Node)
2356 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2357 or else Nkind (Parent_Node) =
2358 N_Generic_Subprogram_Declaration)
2359 and then Plist = Generic_Formal_Declarations (Parent_Node)
2363 elsif Arg_Count > 0 then
2364 Analyze (Get_Pragma_Arg (Arg1));
2366 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2368 ("name in pragma% must be enclosing unit", Arg1);
2371 -- It is legal to have no argument in this context
2377 -- Error if not before first declaration. This is because a
2378 -- library unit pragma argument must be the name of a library
2379 -- unit (RM 10.1.5(7)), but the only names permitted in this
2380 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2381 -- generic subprogram declarations or generic instantiations.
2385 ("pragma% misplaced, must be before first declaration");
2389 end Check_Valid_Library_Unit_Pragma;
2395 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2396 Clist : constant Node_Id := Component_List (Variant);
2400 if not Is_Non_Empty_List (Component_Items (Clist)) then
2402 ("Unchecked_Union may not have empty component list",
2407 Comp := First (Component_Items (Clist));
2408 while Present (Comp) loop
2409 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2418 procedure Error_Pragma (Msg : String) is
2419 MsgF : String := Msg;
2421 Error_Msg_Name_1 := Pname;
2423 Error_Msg_N (MsgF, N);
2427 ----------------------
2428 -- Error_Pragma_Arg --
2429 ----------------------
2431 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2432 MsgF : String := Msg;
2434 Error_Msg_Name_1 := Pname;
2436 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2438 end Error_Pragma_Arg;
2440 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2441 MsgF : String := Msg1;
2443 Error_Msg_Name_1 := Pname;
2445 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2446 Error_Pragma_Arg (Msg2, Arg);
2447 end Error_Pragma_Arg;
2449 ----------------------------
2450 -- Error_Pragma_Arg_Ident --
2451 ----------------------------
2453 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2454 MsgF : String := Msg;
2456 Error_Msg_Name_1 := Pname;
2458 Error_Msg_N (MsgF, Arg);
2460 end Error_Pragma_Arg_Ident;
2462 ----------------------
2463 -- Error_Pragma_Ref --
2464 ----------------------
2466 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2467 MsgF : String := Msg;
2469 Error_Msg_Name_1 := Pname;
2471 Error_Msg_Sloc := Sloc (Ref);
2472 Error_Msg_NE (MsgF, N, Ref);
2474 end Error_Pragma_Ref;
2476 ------------------------
2477 -- Find_Lib_Unit_Name --
2478 ------------------------
2480 function Find_Lib_Unit_Name return Entity_Id is
2482 -- Return inner compilation unit entity, for case of nested
2483 -- categorization pragmas. This happens in generic unit.
2485 if Nkind (Parent (N)) = N_Package_Specification
2486 and then Defining_Entity (Parent (N)) /= Current_Scope
2488 return Defining_Entity (Parent (N));
2490 return Current_Scope;
2492 end Find_Lib_Unit_Name;
2494 ----------------------------
2495 -- Find_Program_Unit_Name --
2496 ----------------------------
2498 procedure Find_Program_Unit_Name (Id : Node_Id) is
2499 Unit_Name : Entity_Id;
2500 Unit_Kind : Node_Kind;
2501 P : constant Node_Id := Parent (N);
2504 if Nkind (P) = N_Compilation_Unit then
2505 Unit_Kind := Nkind (Unit (P));
2507 if Unit_Kind = N_Subprogram_Declaration
2508 or else Unit_Kind = N_Package_Declaration
2509 or else Unit_Kind in N_Generic_Declaration
2511 Unit_Name := Defining_Entity (Unit (P));
2513 if Chars (Id) = Chars (Unit_Name) then
2514 Set_Entity (Id, Unit_Name);
2515 Set_Etype (Id, Etype (Unit_Name));
2517 Set_Etype (Id, Any_Type);
2519 ("cannot find program unit referenced by pragma%");
2523 Set_Etype (Id, Any_Type);
2524 Error_Pragma ("pragma% inapplicable to this unit");
2530 end Find_Program_Unit_Name;
2532 -----------------------------------------
2533 -- Find_Unique_Parameterless_Procedure --
2534 -----------------------------------------
2536 function Find_Unique_Parameterless_Procedure
2538 Arg : Node_Id) return Entity_Id
2540 Proc : Entity_Id := Empty;
2543 -- The body of this procedure needs some comments ???
2545 if not Is_Entity_Name (Name) then
2547 ("argument of pragma% must be entity name", Arg);
2549 elsif not Is_Overloaded (Name) then
2550 Proc := Entity (Name);
2552 if Ekind (Proc) /= E_Procedure
2553 or else Present (First_Formal (Proc))
2556 ("argument of pragma% must be parameterless procedure", Arg);
2561 Found : Boolean := False;
2563 Index : Interp_Index;
2566 Get_First_Interp (Name, Index, It);
2567 while Present (It.Nam) loop
2570 if Ekind (Proc) = E_Procedure
2571 and then No (First_Formal (Proc))
2575 Set_Entity (Name, Proc);
2576 Set_Is_Overloaded (Name, False);
2579 ("ambiguous handler name for pragma% ", Arg);
2583 Get_Next_Interp (Index, It);
2588 ("argument of pragma% must be parameterless procedure",
2591 Proc := Entity (Name);
2597 end Find_Unique_Parameterless_Procedure;
2603 procedure Fix_Error (Msg : in out String) is
2605 if From_Aspect_Specification (N) then
2606 for J in Msg'First .. Msg'Last - 5 loop
2607 if Msg (J .. J + 5) = "pragma" then
2608 Msg (J .. J + 5) := "aspect";
2612 if Error_Msg_Name_1 = Name_Precondition then
2613 Error_Msg_Name_1 := Name_Pre;
2614 elsif Error_Msg_Name_1 = Name_Postcondition then
2615 Error_Msg_Name_1 := Name_Post;
2620 -------------------------
2621 -- Gather_Associations --
2622 -------------------------
2624 procedure Gather_Associations
2626 Args : out Args_List)
2631 -- Initialize all parameters to Empty
2633 for J in Args'Range loop
2637 -- That's all we have to do if there are no argument associations
2639 if No (Pragma_Argument_Associations (N)) then
2643 -- Otherwise first deal with any positional parameters present
2645 Arg := First (Pragma_Argument_Associations (N));
2646 for Index in Args'Range loop
2647 exit when No (Arg) or else Chars (Arg) /= No_Name;
2648 Args (Index) := Get_Pragma_Arg (Arg);
2652 -- Positional parameters all processed, if any left, then we
2653 -- have too many positional parameters.
2655 if Present (Arg) and then Chars (Arg) = No_Name then
2657 ("too many positional associations for pragma%", Arg);
2660 -- Process named parameters if any are present
2662 while Present (Arg) loop
2663 if Chars (Arg) = No_Name then
2665 ("positional association cannot follow named association",
2669 for Index in Names'Range loop
2670 if Names (Index) = Chars (Arg) then
2671 if Present (Args (Index)) then
2673 ("duplicate argument association for pragma%", Arg);
2675 Args (Index) := Get_Pragma_Arg (Arg);
2680 if Index = Names'Last then
2681 Error_Msg_Name_1 := Pname;
2682 Error_Msg_N ("pragma% does not allow & argument", Arg);
2684 -- Check for possible misspelling
2686 for Index1 in Names'Range loop
2687 if Is_Bad_Spelling_Of
2688 (Chars (Arg), Names (Index1))
2690 Error_Msg_Name_1 := Names (Index1);
2691 Error_Msg_N -- CODEFIX
2692 ("\possible misspelling of%", Arg);
2704 end Gather_Associations;
2710 procedure GNAT_Pragma is
2712 -- We need to check the No_Implementation_Pragmas restriction for
2713 -- the case of a pragma from source. Note that the case of aspects
2714 -- generating corresponding pragmas marks these pragmas as not being
2715 -- from source, so this test also catches that case.
2717 if Comes_From_Source (N) then
2718 Check_Restriction (No_Implementation_Pragmas, N);
2722 --------------------------
2723 -- Is_Before_First_Decl --
2724 --------------------------
2726 function Is_Before_First_Decl
2727 (Pragma_Node : Node_Id;
2728 Decls : List_Id) return Boolean
2730 Item : Node_Id := First (Decls);
2733 -- Only other pragmas can come before this pragma
2736 if No (Item) or else Nkind (Item) /= N_Pragma then
2739 elsif Item = Pragma_Node then
2745 end Is_Before_First_Decl;
2747 -----------------------------
2748 -- Is_Configuration_Pragma --
2749 -----------------------------
2751 -- A configuration pragma must appear in the context clause of a
2752 -- compilation unit, and only other pragmas may precede it. Note that
2753 -- the test below also permits use in a configuration pragma file.
2755 function Is_Configuration_Pragma return Boolean is
2756 Lis : constant List_Id := List_Containing (N);
2757 Par : constant Node_Id := Parent (N);
2761 -- If no parent, then we are in the configuration pragma file,
2762 -- so the placement is definitely appropriate.
2767 -- Otherwise we must be in the context clause of a compilation unit
2768 -- and the only thing allowed before us in the context list is more
2769 -- configuration pragmas.
2771 elsif Nkind (Par) = N_Compilation_Unit
2772 and then Context_Items (Par) = Lis
2779 elsif Nkind (Prg) /= N_Pragma then
2789 end Is_Configuration_Pragma;
2791 --------------------------
2792 -- Is_In_Context_Clause --
2793 --------------------------
2795 function Is_In_Context_Clause return Boolean is
2797 Parent_Node : Node_Id;
2800 if not Is_List_Member (N) then
2804 Plist := List_Containing (N);
2805 Parent_Node := Parent (Plist);
2807 if Parent_Node = Empty
2808 or else Nkind (Parent_Node) /= N_Compilation_Unit
2809 or else Context_Items (Parent_Node) /= Plist
2816 end Is_In_Context_Clause;
2818 ---------------------------------
2819 -- Is_Static_String_Expression --
2820 ---------------------------------
2822 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2823 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2826 Analyze_And_Resolve (Argx);
2827 return Is_OK_Static_Expression (Argx)
2828 and then Nkind (Argx) = N_String_Literal;
2829 end Is_Static_String_Expression;
2831 ----------------------
2832 -- Pragma_Misplaced --
2833 ----------------------
2835 procedure Pragma_Misplaced is
2837 Error_Pragma ("incorrect placement of pragma%");
2838 end Pragma_Misplaced;
2840 ------------------------------------
2841 -- Process Atomic_Shared_Volatile --
2842 ------------------------------------
2844 procedure Process_Atomic_Shared_Volatile is
2851 procedure Set_Atomic (E : Entity_Id);
2852 -- Set given type as atomic, and if no explicit alignment was given,
2853 -- set alignment to unknown, since back end knows what the alignment
2854 -- requirements are for atomic arrays. Note: this step is necessary
2855 -- for derived types.
2861 procedure Set_Atomic (E : Entity_Id) is
2865 if not Has_Alignment_Clause (E) then
2866 Set_Alignment (E, Uint_0);
2870 -- Start of processing for Process_Atomic_Shared_Volatile
2873 Check_Ada_83_Warning;
2874 Check_No_Identifiers;
2875 Check_Arg_Count (1);
2876 Check_Arg_Is_Local_Name (Arg1);
2877 E_Id := Get_Pragma_Arg (Arg1);
2879 if Etype (E_Id) = Any_Type then
2884 D := Declaration_Node (E);
2887 -- Check duplicate before we chain ourselves!
2889 Check_Duplicate_Pragma (E);
2891 -- Now check appropriateness of the entity
2894 if Rep_Item_Too_Early (E, N)
2896 Rep_Item_Too_Late (E, N)
2900 Check_First_Subtype (Arg1);
2903 if Prag_Id /= Pragma_Volatile then
2905 Set_Atomic (Underlying_Type (E));
2906 Set_Atomic (Base_Type (E));
2909 -- Attribute belongs on the base type. If the view of the type is
2910 -- currently private, it also belongs on the underlying type.
2912 Set_Is_Volatile (Base_Type (E));
2913 Set_Is_Volatile (Underlying_Type (E));
2915 Set_Treat_As_Volatile (E);
2916 Set_Treat_As_Volatile (Underlying_Type (E));
2918 elsif K = N_Object_Declaration
2919 or else (K = N_Component_Declaration
2920 and then Original_Record_Component (E) = E)
2922 if Rep_Item_Too_Late (E, N) then
2926 if Prag_Id /= Pragma_Volatile then
2929 -- If the object declaration has an explicit initialization, a
2930 -- temporary may have to be created to hold the expression, to
2931 -- ensure that access to the object remain atomic.
2933 if Nkind (Parent (E)) = N_Object_Declaration
2934 and then Present (Expression (Parent (E)))
2936 Set_Has_Delayed_Freeze (E);
2939 -- An interesting improvement here. If an object of type X is
2940 -- declared atomic, and the type X is not atomic, that's a
2941 -- pity, since it may not have appropriate alignment etc. We
2942 -- can rescue this in the special case where the object and
2943 -- type are in the same unit by just setting the type as
2944 -- atomic, so that the back end will process it as atomic.
2946 Utyp := Underlying_Type (Etype (E));
2949 and then Sloc (E) > No_Location
2950 and then Sloc (Utyp) > No_Location
2952 Get_Source_File_Index (Sloc (E)) =
2953 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2955 Set_Is_Atomic (Underlying_Type (Etype (E)));
2959 Set_Is_Volatile (E);
2960 Set_Treat_As_Volatile (E);
2964 ("inappropriate entity for pragma%", Arg1);
2966 end Process_Atomic_Shared_Volatile;
2968 -------------------------------------------
2969 -- Process_Compile_Time_Warning_Or_Error --
2970 -------------------------------------------
2972 procedure Process_Compile_Time_Warning_Or_Error is
2973 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2976 Check_Arg_Count (2);
2977 Check_No_Identifiers;
2978 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2979 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2981 if Compile_Time_Known_Value (Arg1x) then
2982 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2984 Str : constant String_Id :=
2985 Strval (Get_Pragma_Arg (Arg2));
2986 Len : constant Int := String_Length (Str);
2991 Cent : constant Entity_Id :=
2992 Cunit_Entity (Current_Sem_Unit);
2994 Force : constant Boolean :=
2995 Prag_Id = Pragma_Compile_Time_Warning
2997 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2998 and then (Ekind (Cent) /= E_Package
2999 or else not In_Private_Part (Cent));
3000 -- Set True if this is the warning case, and we are in the
3001 -- visible part of a package spec, or in a subprogram spec,
3002 -- in which case we want to force the client to see the
3003 -- warning, even though it is not in the main unit.
3006 -- Loop through segments of message separated by line feeds.
3007 -- We output these segments as separate messages with
3008 -- continuation marks for all but the first.
3013 Error_Msg_Strlen := 0;
3015 -- Loop to copy characters from argument to error message
3019 exit when Ptr > Len;
3020 CC := Get_String_Char (Str, Ptr);
3023 -- Ignore wide chars ??? else store character
3025 if In_Character_Range (CC) then
3026 C := Get_Character (CC);
3027 exit when C = ASCII.LF;
3028 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3029 Error_Msg_String (Error_Msg_Strlen) := C;
3033 -- Here with one line ready to go
3035 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3037 -- If this is a warning in a spec, then we want clients
3038 -- to see the warning, so mark the message with the
3039 -- special sequence !! to force the warning. In the case
3040 -- of a package spec, we do not force this if we are in
3041 -- the private part of the spec.
3044 if Cont = False then
3045 Error_Msg_N ("<~!!", Arg1);
3048 Error_Msg_N ("\<~!!", Arg1);
3051 -- Error, rather than warning, or in a body, so we do not
3052 -- need to force visibility for client (error will be
3053 -- output in any case, and this is the situation in which
3054 -- we do not want a client to get a warning, since the
3055 -- warning is in the body or the spec private part).
3058 if Cont = False then
3059 Error_Msg_N ("<~", Arg1);
3062 Error_Msg_N ("\<~", Arg1);
3066 exit when Ptr > Len;
3071 end Process_Compile_Time_Warning_Or_Error;
3073 ------------------------
3074 -- Process_Convention --
3075 ------------------------
3077 procedure Process_Convention
3078 (C : out Convention_Id;
3079 Ent : out Entity_Id)
3085 Comp_Unit : Unit_Number_Type;
3087 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3088 -- Called if we have more than one Export/Import/Convention pragma.
3089 -- This is generally illegal, but we have a special case of allowing
3090 -- Import and Interface to coexist if they specify the convention in
3091 -- a consistent manner. We are allowed to do this, since Interface is
3092 -- an implementation defined pragma, and we choose to do it since we
3093 -- know Rational allows this combination. S is the entity id of the
3094 -- subprogram in question. This procedure also sets the special flag
3095 -- Import_Interface_Present in both pragmas in the case where we do
3096 -- have matching Import and Interface pragmas.
3098 procedure Set_Convention_From_Pragma (E : Entity_Id);
3099 -- Set convention in entity E, and also flag that the entity has a
3100 -- convention pragma. If entity is for a private or incomplete type,
3101 -- also set convention and flag on underlying type. This procedure
3102 -- also deals with the special case of C_Pass_By_Copy convention.
3104 -------------------------------
3105 -- Diagnose_Multiple_Pragmas --
3106 -------------------------------
3108 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3109 Pdec : constant Node_Id := Declaration_Node (S);
3113 function Same_Convention (Decl : Node_Id) return Boolean;
3114 -- Decl is a pragma node. This function returns True if this
3115 -- pragma has a first argument that is an identifier with a
3116 -- Chars field corresponding to the Convention_Id C.
3118 function Same_Name (Decl : Node_Id) return Boolean;
3119 -- Decl is a pragma node. This function returns True if this
3120 -- pragma has a second argument that is an identifier with a
3121 -- Chars field that matches the Chars of the current subprogram.
3123 ---------------------
3124 -- Same_Convention --
3125 ---------------------
3127 function Same_Convention (Decl : Node_Id) return Boolean is
3128 Arg1 : constant Node_Id :=
3129 First (Pragma_Argument_Associations (Decl));
3132 if Present (Arg1) then
3134 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3136 if Nkind (Arg) = N_Identifier
3137 and then Is_Convention_Name (Chars (Arg))
3138 and then Get_Convention_Id (Chars (Arg)) = C
3146 end Same_Convention;
3152 function Same_Name (Decl : Node_Id) return Boolean is
3153 Arg1 : constant Node_Id :=
3154 First (Pragma_Argument_Associations (Decl));
3162 Arg2 := Next (Arg1);
3169 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3171 if Nkind (Arg) = N_Identifier
3172 and then Chars (Arg) = Chars (S)
3181 -- Start of processing for Diagnose_Multiple_Pragmas
3186 -- Definitely give message if we have Convention/Export here
3188 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3191 -- If we have an Import or Export, scan back from pragma to
3192 -- find any previous pragma applying to the same procedure.
3193 -- The scan will be terminated by the start of the list, or
3194 -- hitting the subprogram declaration. This won't allow one
3195 -- pragma to appear in the public part and one in the private
3196 -- part, but that seems very unlikely in practice.
3200 while Present (Decl) and then Decl /= Pdec loop
3202 -- Look for pragma with same name as us
3204 if Nkind (Decl) = N_Pragma
3205 and then Same_Name (Decl)
3207 -- Give error if same as our pragma or Export/Convention
3209 if Pragma_Name (Decl) = Name_Export
3211 Pragma_Name (Decl) = Name_Convention
3213 Pragma_Name (Decl) = Pragma_Name (N)
3217 -- Case of Import/Interface or the other way round
3219 elsif Pragma_Name (Decl) = Name_Interface
3221 Pragma_Name (Decl) = Name_Import
3223 -- Here we know that we have Import and Interface. It
3224 -- doesn't matter which way round they are. See if
3225 -- they specify the same convention. If so, all OK,
3226 -- and set special flags to stop other messages
3228 if Same_Convention (Decl) then
3229 Set_Import_Interface_Present (N);
3230 Set_Import_Interface_Present (Decl);
3233 -- If different conventions, special message
3236 Error_Msg_Sloc := Sloc (Decl);
3238 ("convention differs from that given#", Arg1);
3248 -- Give message if needed if we fall through those tests
3252 ("at most one Convention/Export/Import pragma is allowed",
3255 end Diagnose_Multiple_Pragmas;
3257 --------------------------------
3258 -- Set_Convention_From_Pragma --
3259 --------------------------------
3261 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3263 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3264 -- for an overridden dispatching operation. Technically this is
3265 -- an amendment and should only be done in Ada 2005 mode. However,
3266 -- this is clearly a mistake, since the problem that is addressed
3267 -- by this AI is that there is a clear gap in the RM!
3269 if Is_Dispatching_Operation (E)
3270 and then Present (Overridden_Operation (E))
3271 and then C /= Convention (Overridden_Operation (E))
3274 ("cannot change convention for " &
3275 "overridden dispatching operation",
3279 -- Set the convention
3281 Set_Convention (E, C);
3282 Set_Has_Convention_Pragma (E);
3284 if Is_Incomplete_Or_Private_Type (E)
3285 and then Present (Underlying_Type (E))
3287 Set_Convention (Underlying_Type (E), C);
3288 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3291 -- A class-wide type should inherit the convention of the specific
3292 -- root type (although this isn't specified clearly by the RM).
3294 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3295 Set_Convention (Class_Wide_Type (E), C);
3298 -- If the entity is a record type, then check for special case of
3299 -- C_Pass_By_Copy, which is treated the same as C except that the
3300 -- special record flag is set. This convention is only permitted
3301 -- on record types (see AI95-00131).
3303 if Cname = Name_C_Pass_By_Copy then
3304 if Is_Record_Type (E) then
3305 Set_C_Pass_By_Copy (Base_Type (E));
3306 elsif Is_Incomplete_Or_Private_Type (E)
3307 and then Is_Record_Type (Underlying_Type (E))
3309 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3312 ("C_Pass_By_Copy convention allowed only for record type",
3317 -- If the entity is a derived boolean type, check for the special
3318 -- case of convention C, C++, or Fortran, where we consider any
3319 -- nonzero value to represent true.
3321 if Is_Discrete_Type (E)
3322 and then Root_Type (Etype (E)) = Standard_Boolean
3328 C = Convention_Fortran)
3330 Set_Nonzero_Is_True (Base_Type (E));
3332 end Set_Convention_From_Pragma;
3334 -- Start of processing for Process_Convention
3337 Check_At_Least_N_Arguments (2);
3338 Check_Optional_Identifier (Arg1, Name_Convention);
3339 Check_Arg_Is_Identifier (Arg1);
3340 Cname := Chars (Get_Pragma_Arg (Arg1));
3342 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3343 -- tested again below to set the critical flag).
3345 if Cname = Name_C_Pass_By_Copy then
3348 -- Otherwise we must have something in the standard convention list
3350 elsif Is_Convention_Name (Cname) then
3351 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3353 -- In DEC VMS, it seems that there is an undocumented feature that
3354 -- any unrecognized convention is treated as the default, which for
3355 -- us is convention C. It does not seem so terrible to do this
3356 -- unconditionally, silently in the VMS case, and with a warning
3357 -- in the non-VMS case.
3360 if Warn_On_Export_Import and not OpenVMS_On_Target then
3362 ("?unrecognized convention name, C assumed",
3363 Get_Pragma_Arg (Arg1));
3369 Check_Optional_Identifier (Arg2, Name_Entity);
3370 Check_Arg_Is_Local_Name (Arg2);
3372 Id := Get_Pragma_Arg (Arg2);
3375 if not Is_Entity_Name (Id) then
3376 Error_Pragma_Arg ("entity name required", Arg2);
3381 -- Set entity to return
3385 -- Ada_Pass_By_Copy special checking
3387 if C = Convention_Ada_Pass_By_Copy then
3388 if not Is_First_Subtype (E) then
3390 ("convention `Ada_Pass_By_Copy` only "
3391 & "allowed for types", Arg2);
3394 if Is_By_Reference_Type (E) then
3396 ("convention `Ada_Pass_By_Copy` not allowed for "
3397 & "by-reference type", Arg1);
3401 -- Ada_Pass_By_Reference special checking
3403 if C = Convention_Ada_Pass_By_Reference then
3404 if not Is_First_Subtype (E) then
3406 ("convention `Ada_Pass_By_Reference` only "
3407 & "allowed for types", Arg2);
3410 if Is_By_Copy_Type (E) then
3412 ("convention `Ada_Pass_By_Reference` not allowed for "
3413 & "by-copy type", Arg1);
3417 -- Go to renamed subprogram if present, since convention applies to
3418 -- the actual renamed entity, not to the renaming entity. If the
3419 -- subprogram is inherited, go to parent subprogram.
3421 if Is_Subprogram (E)
3422 and then Present (Alias (E))
3424 if Nkind (Parent (Declaration_Node (E))) =
3425 N_Subprogram_Renaming_Declaration
3427 if Scope (E) /= Scope (Alias (E)) then
3429 ("cannot apply pragma% to non-local entity&#", E);
3434 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3435 N_Private_Extension_Declaration)
3436 and then Scope (E) = Scope (Alias (E))
3440 -- Return the parent subprogram the entity was inherited from
3446 -- Check that we are not applying this to a specless body
3448 if Is_Subprogram (E)
3449 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3452 ("pragma% requires separate spec and must come before body");
3455 -- Check that we are not applying this to a named constant
3457 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3458 Error_Msg_Name_1 := Pname;
3460 ("cannot apply pragma% to named constant!",
3461 Get_Pragma_Arg (Arg2));
3463 ("\supply appropriate type for&!", Arg2);
3466 if Ekind (E) = E_Enumeration_Literal then
3467 Error_Pragma ("enumeration literal not allowed for pragma%");
3470 -- Check for rep item appearing too early or too late
3472 if Etype (E) = Any_Type
3473 or else Rep_Item_Too_Early (E, N)
3477 elsif Present (Underlying_Type (E)) then
3478 E := Underlying_Type (E);
3481 if Rep_Item_Too_Late (E, N) then
3485 if Has_Convention_Pragma (E) then
3486 Diagnose_Multiple_Pragmas (E);
3488 elsif Convention (E) = Convention_Protected
3489 or else Ekind (Scope (E)) = E_Protected_Type
3492 ("a protected operation cannot be given a different convention",
3496 -- For Intrinsic, a subprogram is required
3498 if C = Convention_Intrinsic
3499 and then not Is_Subprogram (E)
3500 and then not Is_Generic_Subprogram (E)
3503 ("second argument of pragma% must be a subprogram", Arg2);
3508 if C = Convention_Stdcall then
3510 -- A dispatching call is not allowed. A dispatching subprogram
3511 -- cannot be used to interface to the Win32 API, so in fact this
3512 -- check does not impose any effective restriction.
3514 if Is_Dispatching_Operation (E) then
3517 ("dispatching subprograms cannot use Stdcall convention");
3519 -- Subprogram is allowed, but not a generic subprogram, and not a
3520 -- dispatching operation.
3522 elsif not Is_Subprogram (E)
3523 and then not Is_Generic_Subprogram (E)
3527 and then Ekind (E) /= E_Variable
3529 -- An access to subprogram is also allowed
3533 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3536 ("second argument of pragma% must be subprogram (type)",
3541 if not Is_Subprogram (E)
3542 and then not Is_Generic_Subprogram (E)
3544 Set_Convention_From_Pragma (E);
3547 Check_First_Subtype (Arg2);
3548 Set_Convention_From_Pragma (Base_Type (E));
3550 -- For subprograms, we must set the convention on the
3551 -- internally generated directly designated type as well.
3553 if Ekind (E) = E_Access_Subprogram_Type then
3554 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3558 -- For the subprogram case, set proper convention for all homonyms
3559 -- in same scope and the same declarative part, i.e. the same
3560 -- compilation unit.
3563 Comp_Unit := Get_Source_Unit (E);
3564 Set_Convention_From_Pragma (E);
3566 -- Treat a pragma Import as an implicit body, for GPS use
3568 if Prag_Id = Pragma_Import then
3569 Generate_Reference (E, Id, 'b');
3572 -- Loop through the homonyms of the pragma argument's entity
3577 exit when No (E1) or else Scope (E1) /= Current_Scope;
3579 -- Do not set the pragma on inherited operations or on formal
3582 if Comes_From_Source (E1)
3583 and then Comp_Unit = Get_Source_Unit (E1)
3584 and then not Is_Formal_Subprogram (E1)
3585 and then Nkind (Original_Node (Parent (E1))) /=
3586 N_Full_Type_Declaration
3588 if Present (Alias (E1))
3589 and then Scope (E1) /= Scope (Alias (E1))
3592 ("cannot apply pragma% to non-local entity& declared#",
3596 Set_Convention_From_Pragma (E1);
3598 if Prag_Id = Pragma_Import then
3599 Generate_Reference (E1, Id, 'b');
3603 -- For aspect case, do NOT apply to homonyms
3605 exit when From_Aspect_Specification (N);
3608 end Process_Convention;
3610 ----------------------------------------
3611 -- Process_Disable_Enable_Atomic_Sync --
3612 ----------------------------------------
3614 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3617 Check_No_Identifiers;
3618 Check_At_Most_N_Arguments (1);
3620 -- Modeled internally as
3621 -- pragma Unsuppress (Atomic_Synchronization [,Entity])
3625 Pragma_Identifier =>
3626 Make_Identifier (Loc, Nam),
3627 Pragma_Argument_Associations => New_List (
3628 Make_Pragma_Argument_Association (Loc,
3630 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3632 if Present (Arg1) then
3633 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3637 end Process_Disable_Enable_Atomic_Sync;
3639 -----------------------------------------------------
3640 -- Process_Extended_Import_Export_Exception_Pragma --
3641 -----------------------------------------------------
3643 procedure Process_Extended_Import_Export_Exception_Pragma
3644 (Arg_Internal : Node_Id;
3645 Arg_External : Node_Id;
3653 if not OpenVMS_On_Target then
3655 ("?pragma% ignored (applies only to Open'V'M'S)");
3658 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3659 Def_Id := Entity (Arg_Internal);
3661 if Ekind (Def_Id) /= E_Exception then
3663 ("pragma% must refer to declared exception", Arg_Internal);
3666 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3668 if Present (Arg_Form) then
3669 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3672 if Present (Arg_Form)
3673 and then Chars (Arg_Form) = Name_Ada
3677 Set_Is_VMS_Exception (Def_Id);
3678 Set_Exception_Code (Def_Id, No_Uint);
3681 if Present (Arg_Code) then
3682 if not Is_VMS_Exception (Def_Id) then
3684 ("Code option for pragma% not allowed for Ada case",
3688 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3689 Code_Val := Expr_Value (Arg_Code);
3691 if not UI_Is_In_Int_Range (Code_Val) then
3693 ("Code option for pragma% must be in 32-bit range",
3697 Set_Exception_Code (Def_Id, Code_Val);
3700 end Process_Extended_Import_Export_Exception_Pragma;
3702 -------------------------------------------------
3703 -- Process_Extended_Import_Export_Internal_Arg --
3704 -------------------------------------------------
3706 procedure Process_Extended_Import_Export_Internal_Arg
3707 (Arg_Internal : Node_Id := Empty)
3710 if No (Arg_Internal) then
3711 Error_Pragma ("Internal parameter required for pragma%");
3714 if Nkind (Arg_Internal) = N_Identifier then
3717 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3718 and then (Prag_Id = Pragma_Import_Function
3720 Prag_Id = Pragma_Export_Function)
3726 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3729 Check_Arg_Is_Local_Name (Arg_Internal);
3730 end Process_Extended_Import_Export_Internal_Arg;
3732 --------------------------------------------------
3733 -- Process_Extended_Import_Export_Object_Pragma --
3734 --------------------------------------------------
3736 procedure Process_Extended_Import_Export_Object_Pragma
3737 (Arg_Internal : Node_Id;
3738 Arg_External : Node_Id;
3744 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3745 Def_Id := Entity (Arg_Internal);
3747 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3749 ("pragma% must designate an object", Arg_Internal);
3752 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3754 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3757 ("previous Common/Psect_Object applies, pragma % not permitted",
3761 if Rep_Item_Too_Late (Def_Id, N) then
3765 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3767 if Present (Arg_Size) then
3768 Check_Arg_Is_External_Name (Arg_Size);
3771 -- Export_Object case
3773 if Prag_Id = Pragma_Export_Object then
3774 if not Is_Library_Level_Entity (Def_Id) then
3776 ("argument for pragma% must be library level entity",
3780 if Ekind (Current_Scope) = E_Generic_Package then
3781 Error_Pragma ("pragma& cannot appear in a generic unit");
3784 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3786 ("exported object must have compile time known size",
3790 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3791 Error_Msg_N ("?duplicate Export_Object pragma", N);
3793 Set_Exported (Def_Id, Arg_Internal);
3796 -- Import_Object case
3799 if Is_Concurrent_Type (Etype (Def_Id)) then
3801 ("cannot use pragma% for task/protected object",
3805 if Ekind (Def_Id) = E_Constant then
3807 ("cannot import a constant", Arg_Internal);
3810 if Warn_On_Export_Import
3811 and then Has_Discriminants (Etype (Def_Id))
3814 ("imported value must be initialized?", Arg_Internal);
3817 if Warn_On_Export_Import
3818 and then Is_Access_Type (Etype (Def_Id))
3821 ("cannot import object of an access type?", Arg_Internal);
3824 if Warn_On_Export_Import
3825 and then Is_Imported (Def_Id)
3828 ("?duplicate Import_Object pragma", N);
3830 -- Check for explicit initialization present. Note that an
3831 -- initialization generated by the code generator, e.g. for an
3832 -- access type, does not count here.
3834 elsif Present (Expression (Parent (Def_Id)))
3837 (Original_Node (Expression (Parent (Def_Id))))
3839 Error_Msg_Sloc := Sloc (Def_Id);
3841 ("imported entities cannot be initialized (RM B.1(24))",
3842 "\no initialization allowed for & declared#", Arg1);
3844 Set_Imported (Def_Id);
3845 Note_Possible_Modification (Arg_Internal, Sure => False);
3848 end Process_Extended_Import_Export_Object_Pragma;
3850 ------------------------------------------------------
3851 -- Process_Extended_Import_Export_Subprogram_Pragma --
3852 ------------------------------------------------------
3854 procedure Process_Extended_Import_Export_Subprogram_Pragma
3855 (Arg_Internal : Node_Id;
3856 Arg_External : Node_Id;
3857 Arg_Parameter_Types : Node_Id;
3858 Arg_Result_Type : Node_Id := Empty;
3859 Arg_Mechanism : Node_Id;
3860 Arg_Result_Mechanism : Node_Id := Empty;
3861 Arg_First_Optional_Parameter : Node_Id := Empty)
3867 Ambiguous : Boolean;
3871 function Same_Base_Type
3873 Formal : Entity_Id) return Boolean;
3874 -- Determines if Ptype references the type of Formal. Note that only
3875 -- the base types need to match according to the spec. Ptype here is
3876 -- the argument from the pragma, which is either a type name, or an
3877 -- access attribute.
3879 --------------------
3880 -- Same_Base_Type --
3881 --------------------
3883 function Same_Base_Type
3885 Formal : Entity_Id) return Boolean
3887 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3891 -- Case where pragma argument is typ'Access
3893 if Nkind (Ptype) = N_Attribute_Reference
3894 and then Attribute_Name (Ptype) = Name_Access
3896 Pref := Prefix (Ptype);
3899 if not Is_Entity_Name (Pref)
3900 or else Entity (Pref) = Any_Type
3905 -- We have a match if the corresponding argument is of an
3906 -- anonymous access type, and its designated type matches the
3907 -- type of the prefix of the access attribute
3909 return Ekind (Ftyp) = E_Anonymous_Access_Type
3910 and then Base_Type (Entity (Pref)) =
3911 Base_Type (Etype (Designated_Type (Ftyp)));
3913 -- Case where pragma argument is a type name
3918 if not Is_Entity_Name (Ptype)
3919 or else Entity (Ptype) = Any_Type
3924 -- We have a match if the corresponding argument is of the type
3925 -- given in the pragma (comparing base types)
3927 return Base_Type (Entity (Ptype)) = Ftyp;
3931 -- Start of processing for
3932 -- Process_Extended_Import_Export_Subprogram_Pragma
3935 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3939 -- Loop through homonyms (overloadings) of the entity
3941 Hom_Id := Entity (Arg_Internal);
3942 while Present (Hom_Id) loop
3943 Def_Id := Get_Base_Subprogram (Hom_Id);
3945 -- We need a subprogram in the current scope
3947 if not Is_Subprogram (Def_Id)
3948 or else Scope (Def_Id) /= Current_Scope
3955 -- Pragma cannot apply to subprogram body
3957 if Is_Subprogram (Def_Id)
3958 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3962 ("pragma% requires separate spec"
3963 & " and must come before body");
3966 -- Test result type if given, note that the result type
3967 -- parameter can only be present for the function cases.
3969 if Present (Arg_Result_Type)
3970 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3974 elsif Etype (Def_Id) /= Standard_Void_Type
3976 (Pname = Name_Export_Procedure
3978 Pname = Name_Import_Procedure)
3982 -- Test parameter types if given. Note that this parameter
3983 -- has not been analyzed (and must not be, since it is
3984 -- semantic nonsense), so we get it as the parser left it.
3986 elsif Present (Arg_Parameter_Types) then
3987 Check_Matching_Types : declare
3992 Formal := First_Formal (Def_Id);
3994 if Nkind (Arg_Parameter_Types) = N_Null then
3995 if Present (Formal) then
3999 -- A list of one type, e.g. (List) is parsed as
4000 -- a parenthesized expression.
4002 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4003 and then Paren_Count (Arg_Parameter_Types) = 1
4006 or else Present (Next_Formal (Formal))
4011 Same_Base_Type (Arg_Parameter_Types, Formal);
4014 -- A list of more than one type is parsed as a aggregate
4016 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4017 and then Paren_Count (Arg_Parameter_Types) = 0
4019 Ptype := First (Expressions (Arg_Parameter_Types));
4020 while Present (Ptype) or else Present (Formal) loop
4023 or else not Same_Base_Type (Ptype, Formal)
4028 Next_Formal (Formal);
4033 -- Anything else is of the wrong form
4037 ("wrong form for Parameter_Types parameter",
4038 Arg_Parameter_Types);
4040 end Check_Matching_Types;
4043 -- Match is now False if the entry we found did not match
4044 -- either a supplied Parameter_Types or Result_Types argument
4050 -- Ambiguous case, the flag Ambiguous shows if we already
4051 -- detected this and output the initial messages.
4054 if not Ambiguous then
4056 Error_Msg_Name_1 := Pname;
4058 ("pragma% does not uniquely identify subprogram!",
4060 Error_Msg_Sloc := Sloc (Ent);
4061 Error_Msg_N ("matching subprogram #!", N);
4065 Error_Msg_Sloc := Sloc (Def_Id);
4066 Error_Msg_N ("matching subprogram #!", N);
4071 Hom_Id := Homonym (Hom_Id);
4074 -- See if we found an entry
4077 if not Ambiguous then
4078 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4080 ("pragma% cannot be given for generic subprogram");
4083 ("pragma% does not identify local subprogram");
4090 -- Import pragmas must be for imported entities
4092 if Prag_Id = Pragma_Import_Function
4094 Prag_Id = Pragma_Import_Procedure
4096 Prag_Id = Pragma_Import_Valued_Procedure
4098 if not Is_Imported (Ent) then
4100 ("pragma Import or Interface must precede pragma%");
4103 -- Here we have the Export case which can set the entity as exported
4105 -- But does not do so if the specified external name is null, since
4106 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4107 -- compatible) to request no external name.
4109 elsif Nkind (Arg_External) = N_String_Literal
4110 and then String_Length (Strval (Arg_External)) = 0
4114 -- In all other cases, set entity as exported
4117 Set_Exported (Ent, Arg_Internal);
4120 -- Special processing for Valued_Procedure cases
4122 if Prag_Id = Pragma_Import_Valued_Procedure
4124 Prag_Id = Pragma_Export_Valued_Procedure
4126 Formal := First_Formal (Ent);
4129 Error_Pragma ("at least one parameter required for pragma%");
4131 elsif Ekind (Formal) /= E_Out_Parameter then
4132 Error_Pragma ("first parameter must have mode out for pragma%");
4135 Set_Is_Valued_Procedure (Ent);
4139 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4141 -- Process Result_Mechanism argument if present. We have already
4142 -- checked that this is only allowed for the function case.
4144 if Present (Arg_Result_Mechanism) then
4145 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4148 -- Process Mechanism parameter if present. Note that this parameter
4149 -- is not analyzed, and must not be analyzed since it is semantic
4150 -- nonsense, so we get it in exactly as the parser left it.
4152 if Present (Arg_Mechanism) then
4160 -- A single mechanism association without a formal parameter
4161 -- name is parsed as a parenthesized expression. All other
4162 -- cases are parsed as aggregates, so we rewrite the single
4163 -- parameter case as an aggregate for consistency.
4165 if Nkind (Arg_Mechanism) /= N_Aggregate
4166 and then Paren_Count (Arg_Mechanism) = 1
4168 Rewrite (Arg_Mechanism,
4169 Make_Aggregate (Sloc (Arg_Mechanism),
4170 Expressions => New_List (
4171 Relocate_Node (Arg_Mechanism))));
4174 -- Case of only mechanism name given, applies to all formals
4176 if Nkind (Arg_Mechanism) /= N_Aggregate then
4177 Formal := First_Formal (Ent);
4178 while Present (Formal) loop
4179 Set_Mechanism_Value (Formal, Arg_Mechanism);
4180 Next_Formal (Formal);
4183 -- Case of list of mechanism associations given
4186 if Null_Record_Present (Arg_Mechanism) then
4188 ("inappropriate form for Mechanism parameter",
4192 -- Deal with positional ones first
4194 Formal := First_Formal (Ent);
4196 if Present (Expressions (Arg_Mechanism)) then
4197 Mname := First (Expressions (Arg_Mechanism));
4198 while Present (Mname) loop
4201 ("too many mechanism associations", Mname);
4204 Set_Mechanism_Value (Formal, Mname);
4205 Next_Formal (Formal);
4210 -- Deal with named entries
4212 if Present (Component_Associations (Arg_Mechanism)) then
4213 Massoc := First (Component_Associations (Arg_Mechanism));
4214 while Present (Massoc) loop
4215 Choice := First (Choices (Massoc));
4217 if Nkind (Choice) /= N_Identifier
4218 or else Present (Next (Choice))
4221 ("incorrect form for mechanism association",
4225 Formal := First_Formal (Ent);
4229 ("parameter name & not present", Choice);
4232 if Chars (Choice) = Chars (Formal) then
4234 (Formal, Expression (Massoc));
4236 -- Set entity on identifier (needed by ASIS)
4238 Set_Entity (Choice, Formal);
4243 Next_Formal (Formal);
4253 -- Process First_Optional_Parameter argument if present. We have
4254 -- already checked that this is only allowed for the Import case.
4256 if Present (Arg_First_Optional_Parameter) then
4257 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4259 ("first optional parameter must be formal parameter name",
4260 Arg_First_Optional_Parameter);
4263 Formal := First_Formal (Ent);
4267 ("specified formal parameter& not found",
4268 Arg_First_Optional_Parameter);
4271 exit when Chars (Formal) =
4272 Chars (Arg_First_Optional_Parameter);
4274 Next_Formal (Formal);
4277 Set_First_Optional_Parameter (Ent, Formal);
4279 -- Check specified and all remaining formals have right form
4281 while Present (Formal) loop
4282 if Ekind (Formal) /= E_In_Parameter then
4284 ("optional formal& is not of mode in!",
4285 Arg_First_Optional_Parameter, Formal);
4288 Dval := Default_Value (Formal);
4292 ("optional formal& does not have default value!",
4293 Arg_First_Optional_Parameter, Formal);
4295 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4300 ("default value for optional formal& is non-static!",
4301 Arg_First_Optional_Parameter, Formal);
4305 Set_Is_Optional_Parameter (Formal);
4306 Next_Formal (Formal);
4309 end Process_Extended_Import_Export_Subprogram_Pragma;
4311 --------------------------
4312 -- Process_Generic_List --
4313 --------------------------
4315 procedure Process_Generic_List is
4320 Check_No_Identifiers;
4321 Check_At_Least_N_Arguments (1);
4324 while Present (Arg) loop
4325 Exp := Get_Pragma_Arg (Arg);
4328 if not Is_Entity_Name (Exp)
4330 (not Is_Generic_Instance (Entity (Exp))
4332 not Is_Generic_Unit (Entity (Exp)))
4335 ("pragma% argument must be name of generic unit/instance",
4341 end Process_Generic_List;
4343 ------------------------------------
4344 -- Process_Import_Predefined_Type --
4345 ------------------------------------
4347 procedure Process_Import_Predefined_Type is
4348 Loc : constant Source_Ptr := Sloc (N);
4350 Ftyp : Node_Id := Empty;
4356 String_To_Name_Buffer (Strval (Expression (Arg3)));
4359 Elmt := First_Elmt (Predefined_Float_Types);
4360 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4364 Ftyp := Node (Elmt);
4366 if Present (Ftyp) then
4368 -- Don't build a derived type declaration, because predefined C
4369 -- types have no declaration anywhere, so cannot really be named.
4370 -- Instead build a full type declaration, starting with an
4371 -- appropriate type definition is built
4373 if Is_Floating_Point_Type (Ftyp) then
4374 Def := Make_Floating_Point_Definition (Loc,
4375 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4376 Make_Real_Range_Specification (Loc,
4377 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4378 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4380 -- Should never have a predefined type we cannot handle
4383 raise Program_Error;
4386 -- Build and insert a Full_Type_Declaration, which will be
4387 -- analyzed as soon as this list entry has been analyzed.
4389 Decl := Make_Full_Type_Declaration (Loc,
4390 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4391 Type_Definition => Def);
4393 Insert_After (N, Decl);
4394 Mark_Rewrite_Insertion (Decl);
4397 Error_Pragma_Arg ("no matching type found for pragma%",
4400 end Process_Import_Predefined_Type;
4402 ---------------------------------
4403 -- Process_Import_Or_Interface --
4404 ---------------------------------
4406 procedure Process_Import_Or_Interface is
4412 Process_Convention (C, Def_Id);
4413 Kill_Size_Check_Code (Def_Id);
4414 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4416 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4418 -- We do not permit Import to apply to a renaming declaration
4420 if Present (Renamed_Object (Def_Id)) then
4422 ("pragma% not allowed for object renaming", Arg2);
4424 -- User initialization is not allowed for imported object, but
4425 -- the object declaration may contain a default initialization,
4426 -- that will be discarded. Note that an explicit initialization
4427 -- only counts if it comes from source, otherwise it is simply
4428 -- the code generator making an implicit initialization explicit.
4430 elsif Present (Expression (Parent (Def_Id)))
4431 and then Comes_From_Source (Expression (Parent (Def_Id)))
4433 Error_Msg_Sloc := Sloc (Def_Id);
4435 ("no initialization allowed for declaration of& #",
4436 "\imported entities cannot be initialized (RM B.1(24))",
4440 Set_Imported (Def_Id);
4441 Process_Interface_Name (Def_Id, Arg3, Arg4);
4443 -- Note that we do not set Is_Public here. That's because we
4444 -- only want to set it if there is no address clause, and we
4445 -- don't know that yet, so we delay that processing till
4448 -- pragma Import completes deferred constants
4450 if Ekind (Def_Id) = E_Constant then
4451 Set_Has_Completion (Def_Id);
4454 -- It is not possible to import a constant of an unconstrained
4455 -- array type (e.g. string) because there is no simple way to
4456 -- write a meaningful subtype for it.
4458 if Is_Array_Type (Etype (Def_Id))
4459 and then not Is_Constrained (Etype (Def_Id))
4462 ("imported constant& must have a constrained subtype",
4467 elsif Is_Subprogram (Def_Id)
4468 or else Is_Generic_Subprogram (Def_Id)
4470 -- If the name is overloaded, pragma applies to all of the denoted
4471 -- entities in the same declarative part.
4474 while Present (Hom_Id) loop
4475 Def_Id := Get_Base_Subprogram (Hom_Id);
4477 -- Ignore inherited subprograms because the pragma will apply
4478 -- to the parent operation, which is the one called.
4480 if Is_Overloadable (Def_Id)
4481 and then Present (Alias (Def_Id))
4485 -- If it is not a subprogram, it must be in an outer scope and
4486 -- pragma does not apply.
4488 elsif not Is_Subprogram (Def_Id)
4489 and then not Is_Generic_Subprogram (Def_Id)
4493 -- The pragma does not apply to primitives of interfaces
4495 elsif Is_Dispatching_Operation (Def_Id)
4496 and then Present (Find_Dispatching_Type (Def_Id))
4497 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4501 -- Verify that the homonym is in the same declarative part (not
4502 -- just the same scope).
4504 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4505 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4510 Set_Imported (Def_Id);
4512 -- Reject an Import applied to an abstract subprogram
4514 if Is_Subprogram (Def_Id)
4515 and then Is_Abstract_Subprogram (Def_Id)
4517 Error_Msg_Sloc := Sloc (Def_Id);
4519 ("cannot import abstract subprogram& declared#",
4523 -- Special processing for Convention_Intrinsic
4525 if C = Convention_Intrinsic then
4527 -- Link_Name argument not allowed for intrinsic
4531 Set_Is_Intrinsic_Subprogram (Def_Id);
4533 -- If no external name is present, then check that this
4534 -- is a valid intrinsic subprogram. If an external name
4535 -- is present, then this is handled by the back end.
4538 Check_Intrinsic_Subprogram
4539 (Def_Id, Get_Pragma_Arg (Arg2));
4543 -- All interfaced procedures need an external symbol created
4544 -- for them since they are always referenced from another
4547 Set_Is_Public (Def_Id);
4549 -- Verify that the subprogram does not have a completion
4550 -- through a renaming declaration. For other completions the
4551 -- pragma appears as a too late representation.
4554 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4558 and then Nkind (Decl) = N_Subprogram_Declaration
4559 and then Present (Corresponding_Body (Decl))
4560 and then Nkind (Unit_Declaration_Node
4561 (Corresponding_Body (Decl))) =
4562 N_Subprogram_Renaming_Declaration
4564 Error_Msg_Sloc := Sloc (Def_Id);
4566 ("cannot import&, renaming already provided for " &
4567 "declaration #", N, Def_Id);
4571 Set_Has_Completion (Def_Id);
4572 Process_Interface_Name (Def_Id, Arg3, Arg4);
4575 if Is_Compilation_Unit (Hom_Id) then
4577 -- Its possible homonyms are not affected by the pragma.
4578 -- Such homonyms might be present in the context of other
4579 -- units being compiled.
4584 Hom_Id := Homonym (Hom_Id);
4588 -- When the convention is Java or CIL, we also allow Import to be
4589 -- given for packages, generic packages, exceptions, record
4590 -- components, and access to subprograms.
4592 elsif (C = Convention_Java or else C = Convention_CIL)
4594 (Is_Package_Or_Generic_Package (Def_Id)
4595 or else Ekind (Def_Id) = E_Exception
4596 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4597 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4599 Set_Imported (Def_Id);
4600 Set_Is_Public (Def_Id);
4601 Process_Interface_Name (Def_Id, Arg3, Arg4);
4603 -- Import a CPP class
4605 elsif C = Convention_CPP
4606 and then (Is_Record_Type (Def_Id)
4607 or else Ekind (Def_Id) = E_Incomplete_Type)
4609 if Ekind (Def_Id) = E_Incomplete_Type then
4610 if Present (Full_View (Def_Id)) then
4611 Def_Id := Full_View (Def_Id);
4615 ("cannot import 'C'P'P type before full declaration seen",
4616 Get_Pragma_Arg (Arg2));
4618 -- Although we have reported the error we decorate it as
4619 -- CPP_Class to avoid reporting spurious errors
4621 Set_Is_CPP_Class (Def_Id);
4626 -- Types treated as CPP classes must be declared limited (note:
4627 -- this used to be a warning but there is no real benefit to it
4628 -- since we did effectively intend to treat the type as limited
4631 if not Is_Limited_Type (Def_Id) then
4633 ("imported 'C'P'P type must be limited",
4634 Get_Pragma_Arg (Arg2));
4637 Set_Is_CPP_Class (Def_Id);
4639 -- Imported CPP types must not have discriminants (because C++
4640 -- classes do not have discriminants).
4642 if Has_Discriminants (Def_Id) then
4644 ("imported 'C'P'P type cannot have discriminants",
4645 First (Discriminant_Specifications
4646 (Declaration_Node (Def_Id))));
4649 -- Check that components of imported CPP types do not have default
4650 -- expressions. For private types this check is performed when the
4651 -- full view is analyzed (see Process_Full_View).
4653 if not Is_Private_Type (Def_Id) then
4654 Check_CPP_Type_Has_No_Defaults (Def_Id);
4657 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4659 Check_Arg_Count (3);
4660 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4662 Process_Import_Predefined_Type;
4666 ("second argument of pragma% must be object, subprogram "
4667 & "or incomplete type",
4671 -- If this pragma applies to a compilation unit, then the unit, which
4672 -- is a subprogram, does not require (or allow) a body. We also do
4673 -- not need to elaborate imported procedures.
4675 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4677 Cunit : constant Node_Id := Parent (Parent (N));
4679 Set_Body_Required (Cunit, False);
4682 end Process_Import_Or_Interface;
4684 --------------------
4685 -- Process_Inline --
4686 --------------------
4688 procedure Process_Inline (Active : Boolean) is
4695 Effective : Boolean := False;
4696 -- Set True if inline has some effect, i.e. if there is at least one
4697 -- subprogram set as inlined as a result of the use of the pragma.
4699 procedure Make_Inline (Subp : Entity_Id);
4700 -- Subp is the defining unit name of the subprogram declaration. Set
4701 -- the flag, as well as the flag in the corresponding body, if there
4704 procedure Set_Inline_Flags (Subp : Entity_Id);
4705 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4706 -- Has_Pragma_Inline_Always for the Inline_Always case.
4708 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4709 -- Returns True if it can be determined at this stage that inlining
4710 -- is not possible, for example if the body is available and contains
4711 -- exception handlers, we prevent inlining, since otherwise we can
4712 -- get undefined symbols at link time. This function also emits a
4713 -- warning if front-end inlining is enabled and the pragma appears
4716 -- ??? is business with link symbols still valid, or does it relate
4717 -- to front end ZCX which is being phased out ???
4719 ---------------------------
4720 -- Inlining_Not_Possible --
4721 ---------------------------
4723 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4724 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4728 if Nkind (Decl) = N_Subprogram_Body then
4729 Stats := Handled_Statement_Sequence (Decl);
4730 return Present (Exception_Handlers (Stats))
4731 or else Present (At_End_Proc (Stats));
4733 elsif Nkind (Decl) = N_Subprogram_Declaration
4734 and then Present (Corresponding_Body (Decl))
4736 if Front_End_Inlining
4737 and then Analyzed (Corresponding_Body (Decl))
4739 Error_Msg_N ("pragma appears too late, ignored?", N);
4742 -- If the subprogram is a renaming as body, the body is just a
4743 -- call to the renamed subprogram, and inlining is trivially
4747 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4748 N_Subprogram_Renaming_Declaration
4754 Handled_Statement_Sequence
4755 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4758 Present (Exception_Handlers (Stats))
4759 or else Present (At_End_Proc (Stats));
4763 -- If body is not available, assume the best, the check is
4764 -- performed again when compiling enclosing package bodies.
4768 end Inlining_Not_Possible;
4774 procedure Make_Inline (Subp : Entity_Id) is
4775 Kind : constant Entity_Kind := Ekind (Subp);
4776 Inner_Subp : Entity_Id := Subp;
4779 -- Ignore if bad type, avoid cascaded error
4781 if Etype (Subp) = Any_Type then
4785 -- Ignore if all inlining is suppressed
4787 elsif Suppress_All_Inlining then
4791 -- If inlining is not possible, for now do not treat as an error
4793 elsif Inlining_Not_Possible (Subp) then
4797 -- Here we have a candidate for inlining, but we must exclude
4798 -- derived operations. Otherwise we would end up trying to inline
4799 -- a phantom declaration, and the result would be to drag in a
4800 -- body which has no direct inlining associated with it. That
4801 -- would not only be inefficient but would also result in the
4802 -- backend doing cross-unit inlining in cases where it was
4803 -- definitely inappropriate to do so.
4805 -- However, a simple Comes_From_Source test is insufficient, since
4806 -- we do want to allow inlining of generic instances which also do
4807 -- not come from source. We also need to recognize specs generated
4808 -- by the front-end for bodies that carry the pragma. Finally,
4809 -- predefined operators do not come from source but are not
4810 -- inlineable either.
4812 elsif Is_Generic_Instance (Subp)
4813 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4817 elsif not Comes_From_Source (Subp)
4818 and then Scope (Subp) /= Standard_Standard
4824 -- The referenced entity must either be the enclosing entity, or
4825 -- an entity declared within the current open scope.
4827 if Present (Scope (Subp))
4828 and then Scope (Subp) /= Current_Scope
4829 and then Subp /= Current_Scope
4832 ("argument of% must be entity in current scope", Assoc);
4836 -- Processing for procedure, operator or function. If subprogram
4837 -- is aliased (as for an instance) indicate that the renamed
4838 -- entity (if declared in the same unit) is inlined.
4840 if Is_Subprogram (Subp) then
4841 Inner_Subp := Ultimate_Alias (Inner_Subp);
4843 if In_Same_Source_Unit (Subp, Inner_Subp) then
4844 Set_Inline_Flags (Inner_Subp);
4846 Decl := Parent (Parent (Inner_Subp));
4848 if Nkind (Decl) = N_Subprogram_Declaration
4849 and then Present (Corresponding_Body (Decl))
4851 Set_Inline_Flags (Corresponding_Body (Decl));
4853 elsif Is_Generic_Instance (Subp) then
4855 -- Indicate that the body needs to be created for
4856 -- inlining subsequent calls. The instantiation node
4857 -- follows the declaration of the wrapper package
4860 if Scope (Subp) /= Standard_Standard
4862 Need_Subprogram_Instance_Body
4863 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4869 -- Inline is a program unit pragma (RM 10.1.5) and cannot
4870 -- appear in a formal part to apply to a formal subprogram.
4871 -- Do not apply check within an instance or a formal package
4872 -- the test will have been applied to the original generic.
4874 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4875 and then List_Containing (Decl) = List_Containing (N)
4876 and then not In_Instance
4879 ("Inline cannot apply to a formal subprogram", N);
4885 -- For a generic subprogram set flag as well, for use at the point
4886 -- of instantiation, to determine whether the body should be
4889 elsif Is_Generic_Subprogram (Subp) then
4890 Set_Inline_Flags (Subp);
4893 -- Literals are by definition inlined
4895 elsif Kind = E_Enumeration_Literal then
4898 -- Anything else is an error
4902 ("expect subprogram name for pragma%", Assoc);
4906 ----------------------
4907 -- Set_Inline_Flags --
4908 ----------------------
4910 procedure Set_Inline_Flags (Subp : Entity_Id) is
4913 Set_Is_Inlined (Subp);
4916 if not Has_Pragma_Inline (Subp) then
4917 Set_Has_Pragma_Inline (Subp);
4921 if Prag_Id = Pragma_Inline_Always then
4922 Set_Has_Pragma_Inline_Always (Subp);
4924 end Set_Inline_Flags;
4926 -- Start of processing for Process_Inline
4929 Check_No_Identifiers;
4930 Check_At_Least_N_Arguments (1);
4933 Inline_Processing_Required := True;
4937 while Present (Assoc) loop
4938 Subp_Id := Get_Pragma_Arg (Assoc);
4942 if Is_Entity_Name (Subp_Id) then
4943 Subp := Entity (Subp_Id);
4945 if Subp = Any_Id then
4947 -- If previous error, avoid cascaded errors
4955 -- For the pragma case, climb homonym chain. This is
4956 -- what implements allowing the pragma in the renaming
4957 -- case, with the result applying to the ancestors, and
4958 -- also allows Inline to apply to all previous homonyms.
4960 if not From_Aspect_Specification (N) then
4961 while Present (Homonym (Subp))
4962 and then Scope (Homonym (Subp)) = Current_Scope
4964 Make_Inline (Homonym (Subp));
4965 Subp := Homonym (Subp);
4973 ("inappropriate argument for pragma%", Assoc);
4976 and then Warn_On_Redundant_Constructs
4977 and then not Suppress_All_Inlining
4979 if Inlining_Not_Possible (Subp) then
4981 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4984 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4992 ----------------------------
4993 -- Process_Interface_Name --
4994 ----------------------------
4996 procedure Process_Interface_Name
4997 (Subprogram_Def : Entity_Id;
5003 String_Val : String_Id;
5005 procedure Check_Form_Of_Interface_Name
5007 Ext_Name_Case : Boolean);
5008 -- SN is a string literal node for an interface name. This routine
5009 -- performs some minimal checks that the name is reasonable. In
5010 -- particular that no spaces or other obviously incorrect characters
5011 -- appear. This is only a warning, since any characters are allowed.
5012 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5014 ----------------------------------
5015 -- Check_Form_Of_Interface_Name --
5016 ----------------------------------
5018 procedure Check_Form_Of_Interface_Name
5020 Ext_Name_Case : Boolean)
5022 S : constant String_Id := Strval (Expr_Value_S (SN));
5023 SL : constant Nat := String_Length (S);
5028 Error_Msg_N ("interface name cannot be null string", SN);
5031 for J in 1 .. SL loop
5032 C := Get_String_Char (S, J);
5034 -- Look for dubious character and issue unconditional warning.
5035 -- Definitely dubious if not in character range.
5037 if not In_Character_Range (C)
5039 -- For all cases except CLI target,
5040 -- commas, spaces and slashes are dubious (in CLI, we use
5041 -- commas and backslashes in external names to specify
5042 -- assembly version and public key, while slashes and spaces
5043 -- can be used in names to mark nested classes and
5046 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5047 and then (Get_Character (C) = ','
5049 Get_Character (C) = '\'))
5050 or else (VM_Target /= CLI_Target
5051 and then (Get_Character (C) = ' '
5053 Get_Character (C) = '/'))
5056 ("?interface name contains illegal character",
5057 Sloc (SN) + Source_Ptr (J));
5060 end Check_Form_Of_Interface_Name;
5062 -- Start of processing for Process_Interface_Name
5065 if No (Link_Arg) then
5066 if No (Ext_Arg) then
5067 if VM_Target = CLI_Target
5068 and then Ekind (Subprogram_Def) = E_Package
5069 and then Nkind (Parent (Subprogram_Def)) =
5070 N_Package_Specification
5071 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5076 (Generic_Parent (Parent (Subprogram_Def))));
5081 elsif Chars (Ext_Arg) = Name_Link_Name then
5083 Link_Nam := Expression (Ext_Arg);
5086 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5087 Ext_Nam := Expression (Ext_Arg);
5092 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5093 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5094 Ext_Nam := Expression (Ext_Arg);
5095 Link_Nam := Expression (Link_Arg);
5098 -- Check expressions for external name and link name are static
5100 if Present (Ext_Nam) then
5101 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5102 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5104 -- Verify that external name is not the name of a local entity,
5105 -- which would hide the imported one and could lead to run-time
5106 -- surprises. The problem can only arise for entities declared in
5107 -- a package body (otherwise the external name is fully qualified
5108 -- and will not conflict).
5116 if Prag_Id = Pragma_Import then
5117 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5119 E := Entity_Id (Get_Name_Table_Info (Nam));
5121 if Nam /= Chars (Subprogram_Def)
5122 and then Present (E)
5123 and then not Is_Overloadable (E)
5124 and then Is_Immediately_Visible (E)
5125 and then not Is_Imported (E)
5126 and then Ekind (Scope (E)) = E_Package
5129 while Present (Par) loop
5130 if Nkind (Par) = N_Package_Body then
5131 Error_Msg_Sloc := Sloc (E);
5133 ("imported entity is hidden by & declared#",
5138 Par := Parent (Par);
5145 if Present (Link_Nam) then
5146 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5147 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5150 -- If there is no link name, just set the external name
5152 if No (Link_Nam) then
5153 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5155 -- For the Link_Name case, the given literal is preceded by an
5156 -- asterisk, which indicates to GCC that the given name should be
5157 -- taken literally, and in particular that no prepending of
5158 -- underlines should occur, even in systems where this is the
5164 if VM_Target = No_VM then
5165 Store_String_Char (Get_Char_Code ('*'));
5168 String_Val := Strval (Expr_Value_S (Link_Nam));
5169 Store_String_Chars (String_Val);
5171 Make_String_Literal (Sloc (Link_Nam),
5172 Strval => End_String);
5175 -- Set the interface name. If the entity is a generic instance, use
5176 -- its alias, which is the callable entity.
5178 if Is_Generic_Instance (Subprogram_Def) then
5179 Set_Encoded_Interface_Name
5180 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5182 Set_Encoded_Interface_Name
5183 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5186 -- We allow duplicated export names in CIL/Java, as they are always
5187 -- enclosed in a namespace that differentiates them, and overloaded
5188 -- entities are supported by the VM.
5190 if Convention (Subprogram_Def) /= Convention_CIL
5192 Convention (Subprogram_Def) /= Convention_Java
5194 Check_Duplicated_Export_Name (Link_Nam);
5196 end Process_Interface_Name;
5198 -----------------------------------------
5199 -- Process_Interrupt_Or_Attach_Handler --
5200 -----------------------------------------
5202 procedure Process_Interrupt_Or_Attach_Handler is
5203 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5204 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5205 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5208 Set_Is_Interrupt_Handler (Handler_Proc);
5210 -- If the pragma is not associated with a handler procedure within a
5211 -- protected type, then it must be for a nonprotected procedure for
5212 -- the AAMP target, in which case we don't associate a representation
5213 -- item with the procedure's scope.
5215 if Ekind (Proc_Scope) = E_Protected_Type then
5216 if Prag_Id = Pragma_Interrupt_Handler
5218 Prag_Id = Pragma_Attach_Handler
5220 Record_Rep_Item (Proc_Scope, N);
5223 end Process_Interrupt_Or_Attach_Handler;
5225 --------------------------------------------------
5226 -- Process_Restrictions_Or_Restriction_Warnings --
5227 --------------------------------------------------
5229 -- Note: some of the simple identifier cases were handled in par-prag,
5230 -- but it is harmless (and more straightforward) to simply handle all
5231 -- cases here, even if it means we repeat a bit of work in some cases.
5233 procedure Process_Restrictions_Or_Restriction_Warnings
5237 R_Id : Restriction_Id;
5242 procedure Check_Unit_Name (N : Node_Id);
5243 -- Checks unit name parameter for No_Dependence. Returns if it has
5244 -- an appropriate form, otherwise raises pragma argument error.
5246 ---------------------
5247 -- Check_Unit_Name --
5248 ---------------------
5250 procedure Check_Unit_Name (N : Node_Id) is
5252 if Nkind (N) = N_Selected_Component then
5253 Check_Unit_Name (Prefix (N));
5254 Check_Unit_Name (Selector_Name (N));
5256 elsif Nkind (N) = N_Identifier then
5261 ("wrong form for unit name for No_Dependence", N);
5263 end Check_Unit_Name;
5265 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5268 -- Ignore all Restrictions pragma in CodePeer mode
5270 if CodePeer_Mode then
5274 Check_Ada_83_Warning;
5275 Check_At_Least_N_Arguments (1);
5276 Check_Valid_Configuration_Pragma;
5279 while Present (Arg) loop
5281 Expr := Get_Pragma_Arg (Arg);
5283 -- Case of no restriction identifier present
5285 if Id = No_Name then
5286 if Nkind (Expr) /= N_Identifier then
5288 ("invalid form for restriction", Arg);
5293 (Process_Restriction_Synonyms (Expr));
5295 if R_Id not in All_Boolean_Restrictions then
5296 Error_Msg_Name_1 := Pname;
5298 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5300 -- Check for possible misspelling
5302 for J in Restriction_Id loop
5304 Rnm : constant String := Restriction_Id'Image (J);
5307 Name_Buffer (1 .. Rnm'Length) := Rnm;
5308 Name_Len := Rnm'Length;
5309 Set_Casing (All_Lower_Case);
5311 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5313 (Identifier_Casing (Current_Source_File));
5314 Error_Msg_String (1 .. Rnm'Length) :=
5315 Name_Buffer (1 .. Name_Len);
5316 Error_Msg_Strlen := Rnm'Length;
5317 Error_Msg_N -- CODEFIX
5318 ("\possible misspelling of ""~""",
5319 Get_Pragma_Arg (Arg));
5328 if Implementation_Restriction (R_Id) then
5329 Check_Restriction (No_Implementation_Restrictions, Arg);
5332 -- Special processing for No_Elaboration_Code restriction
5334 if R_Id = No_Elaboration_Code then
5336 -- Restriction is only recognized within a configuration
5337 -- pragma file, or within a unit of the main extended
5338 -- program. Note: the test for Main_Unit is needed to
5339 -- properly include the case of configuration pragma files.
5341 if not (Current_Sem_Unit = Main_Unit
5342 or else In_Extended_Main_Source_Unit (N))
5346 -- Don't allow in a subunit unless already specified in
5349 elsif Nkind (Parent (N)) = N_Compilation_Unit
5350 and then Nkind (Unit (Parent (N))) = N_Subunit
5351 and then not Restriction_Active (No_Elaboration_Code)
5354 ("invalid specification of ""No_Elaboration_Code""",
5357 ("\restriction cannot be specified in a subunit", N);
5359 ("\unless also specified in body or spec", N);
5362 -- If we have a No_Elaboration_Code pragma that we
5363 -- accept, then it needs to be added to the configuration
5364 -- restrcition set so that we get proper application to
5365 -- other units in the main extended source as required.
5368 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
5372 -- If this is a warning, then set the warning unless we already
5373 -- have a real restriction active (we never want a warning to
5374 -- override a real restriction).
5377 if not Restriction_Active (R_Id) then
5378 Set_Restriction (R_Id, N);
5379 Restriction_Warnings (R_Id) := True;
5382 -- If real restriction case, then set it and make sure that the
5383 -- restriction warning flag is off, since a real restriction
5384 -- always overrides a warning.
5387 Set_Restriction (R_Id, N);
5388 Restriction_Warnings (R_Id) := False;
5391 -- Check for obsolescent restrictions in Ada 2005 mode
5394 and then Ada_Version >= Ada_2005
5395 and then (R_Id = No_Asynchronous_Control
5397 R_Id = No_Unchecked_Deallocation
5399 R_Id = No_Unchecked_Conversion)
5401 Check_Restriction (No_Obsolescent_Features, N);
5404 -- A very special case that must be processed here: pragma
5405 -- Restrictions (No_Exceptions) turns off all run-time
5406 -- checking. This is a bit dubious in terms of the formal
5407 -- language definition, but it is what is intended by RM
5408 -- H.4(12). Restriction_Warnings never affects generated code
5409 -- so this is done only in the real restriction case.
5411 -- Atomic_Synchronization is not a real check, so it is not
5412 -- affected by this processing).
5414 if R_Id = No_Exceptions and then not Warn then
5415 for J in Scope_Suppress'Range loop
5416 if J /= Atomic_Synchronization then
5417 Scope_Suppress (J) := True;
5422 -- Case of No_Dependence => unit-name. Note that the parser
5423 -- already made the necessary entry in the No_Dependence table.
5425 elsif Id = Name_No_Dependence then
5426 Check_Unit_Name (Expr);
5428 -- Case of No_Specification_Of_Aspect => Identifier.
5430 elsif Id = Name_No_Specification_Of_Aspect then
5435 if Nkind (Expr) /= N_Identifier then
5438 A_Id := Get_Aspect_Id (Chars (Expr));
5441 if A_Id = No_Aspect then
5442 Error_Pragma_Arg ("invalid restriction name", Arg);
5444 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5448 -- All other cases of restriction identifier present
5451 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5452 Analyze_And_Resolve (Expr, Any_Integer);
5454 if R_Id not in All_Parameter_Restrictions then
5456 ("invalid restriction parameter identifier", Arg);
5458 elsif not Is_OK_Static_Expression (Expr) then
5459 Flag_Non_Static_Expr
5460 ("value must be static expression!", Expr);
5463 elsif not Is_Integer_Type (Etype (Expr))
5464 or else Expr_Value (Expr) < 0
5467 ("value must be non-negative integer", Arg);
5470 -- Restriction pragma is active
5472 Val := Expr_Value (Expr);
5474 if not UI_Is_In_Int_Range (Val) then
5476 ("pragma ignored, value too large?", Arg);
5479 -- Warning case. If the real restriction is active, then we
5480 -- ignore the request, since warning never overrides a real
5481 -- restriction. Otherwise we set the proper warning. Note that
5482 -- this circuit sets the warning again if it is already set,
5483 -- which is what we want, since the constant may have changed.
5486 if not Restriction_Active (R_Id) then
5488 (R_Id, N, Integer (UI_To_Int (Val)));
5489 Restriction_Warnings (R_Id) := True;
5492 -- Real restriction case, set restriction and make sure warning
5493 -- flag is off since real restriction always overrides warning.
5496 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5497 Restriction_Warnings (R_Id) := False;
5503 end Process_Restrictions_Or_Restriction_Warnings;
5505 ---------------------------------
5506 -- Process_Suppress_Unsuppress --
5507 ---------------------------------
5509 -- Note: this procedure makes entries in the check suppress data
5510 -- structures managed by Sem. See spec of package Sem for full
5511 -- details on how we handle recording of check suppression.
5513 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5518 In_Package_Spec : constant Boolean :=
5519 Is_Package_Or_Generic_Package (Current_Scope)
5520 and then not In_Package_Body (Current_Scope);
5522 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5523 -- Used to suppress a single check on the given entity
5525 --------------------------------
5526 -- Suppress_Unsuppress_Echeck --
5527 --------------------------------
5529 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5531 -- Check for error of trying to set atomic synchronization for
5532 -- a non-atomic variable.
5534 if C = Atomic_Synchronization
5535 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5538 ("pragma & requires atomic type or variable",
5539 Pragma_Identifier (Original_Node (N)));
5542 Set_Checks_May_Be_Suppressed (E);
5544 if In_Package_Spec then
5545 Push_Global_Suppress_Stack_Entry
5548 Suppress => Suppress_Case);
5550 Push_Local_Suppress_Stack_Entry
5553 Suppress => Suppress_Case);
5556 -- If this is a first subtype, and the base type is distinct,
5557 -- then also set the suppress flags on the base type.
5559 if Is_First_Subtype (E)
5560 and then Etype (E) /= E
5562 Suppress_Unsuppress_Echeck (Etype (E), C);
5564 end Suppress_Unsuppress_Echeck;
5566 -- Start of processing for Process_Suppress_Unsuppress
5569 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5570 -- user code: we want to generate checks for analysis purposes, as
5571 -- set respectively by -gnatC and -gnatd.F
5573 if (CodePeer_Mode or Alfa_Mode)
5574 and then Comes_From_Source (N)
5579 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5580 -- declarative part or a package spec (RM 11.5(5)).
5582 if not Is_Configuration_Pragma then
5583 Check_Is_In_Decl_Part_Or_Package_Spec;
5586 Check_At_Least_N_Arguments (1);
5587 Check_At_Most_N_Arguments (2);
5588 Check_No_Identifier (Arg1);
5589 Check_Arg_Is_Identifier (Arg1);
5591 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5593 if C = No_Check_Id then
5595 ("argument of pragma% is not valid check name", Arg1);
5598 if not Suppress_Case
5599 and then (C = All_Checks or else C = Overflow_Check)
5601 Opt.Overflow_Checks_Unsuppressed := True;
5604 if Arg_Count = 1 then
5606 -- Make an entry in the local scope suppress table. This is the
5607 -- table that directly shows the current value of the scope
5608 -- suppress check for any check id value.
5610 if C = All_Checks then
5612 -- For All_Checks, we set all specific predefined checks with
5613 -- the exception of Elaboration_Check, which is handled
5614 -- specially because of not wanting All_Checks to have the
5615 -- effect of deactivating static elaboration order processing.
5616 -- Atomic_Synchronization is also not affected, since this is
5617 -- not a real check.
5619 for J in Scope_Suppress'Range loop
5620 if J /= Elaboration_Check
5621 and then J /= Atomic_Synchronization
5623 Scope_Suppress (J) := Suppress_Case;
5627 -- If not All_Checks, and predefined check, then set appropriate
5628 -- scope entry. Note that we will set Elaboration_Check if this
5629 -- is explicitly specified. Atomic_Synchronization is allowed
5630 -- only if internally generated and entity is atomic.
5632 elsif C in Predefined_Check_Id
5633 and then (not Comes_From_Source (N)
5634 or else C /= Atomic_Synchronization)
5636 Scope_Suppress (C) := Suppress_Case;
5639 -- Also make an entry in the Local_Entity_Suppress table
5641 Push_Local_Suppress_Stack_Entry
5644 Suppress => Suppress_Case);
5646 -- Case of two arguments present, where the check is suppressed for
5647 -- a specified entity (given as the second argument of the pragma)
5650 -- This is obsolescent in Ada 2005 mode
5652 if Ada_Version >= Ada_2005 then
5653 Check_Restriction (No_Obsolescent_Features, Arg2);
5656 Check_Optional_Identifier (Arg2, Name_On);
5657 E_Id := Get_Pragma_Arg (Arg2);
5660 if not Is_Entity_Name (E_Id) then
5662 ("second argument of pragma% must be entity name", Arg2);
5671 -- Enforce RM 11.5(7) which requires that for a pragma that
5672 -- appears within a package spec, the named entity must be
5673 -- within the package spec. We allow the package name itself
5674 -- to be mentioned since that makes sense, although it is not
5675 -- strictly allowed by 11.5(7).
5678 and then E /= Current_Scope
5679 and then Scope (E) /= Current_Scope
5682 ("entity in pragma% is not in package spec (RM 11.5(7))",
5686 -- Loop through homonyms. As noted below, in the case of a package
5687 -- spec, only homonyms within the package spec are considered.
5690 Suppress_Unsuppress_Echeck (E, C);
5692 if Is_Generic_Instance (E)
5693 and then Is_Subprogram (E)
5694 and then Present (Alias (E))
5696 Suppress_Unsuppress_Echeck (Alias (E), C);
5699 -- Move to next homonym if not aspect spec case
5701 exit when From_Aspect_Specification (N);
5705 -- If we are within a package specification, the pragma only
5706 -- applies to homonyms in the same scope.
5708 exit when In_Package_Spec
5709 and then Scope (E) /= Current_Scope;
5712 end Process_Suppress_Unsuppress;
5718 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5720 if Is_Imported (E) then
5722 ("cannot export entity& that was previously imported", Arg);
5724 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5726 ("cannot export entity& that has an address clause", Arg);
5729 Set_Is_Exported (E);
5731 -- Generate a reference for entity explicitly, because the
5732 -- identifier may be overloaded and name resolution will not
5735 Generate_Reference (E, Arg);
5737 -- Deal with exporting non-library level entity
5739 if not Is_Library_Level_Entity (E) then
5741 -- Not allowed at all for subprograms
5743 if Is_Subprogram (E) then
5744 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5746 -- Otherwise set public and statically allocated
5750 Set_Is_Statically_Allocated (E);
5752 -- Warn if the corresponding W flag is set and the pragma comes
5753 -- from source. The latter may not be true e.g. on VMS where we
5754 -- expand export pragmas for exception codes associated with
5755 -- imported or exported exceptions. We do not want to generate
5756 -- a warning for something that the user did not write.
5758 if Warn_On_Export_Import
5759 and then Comes_From_Source (Arg)
5762 ("?& has been made static as a result of Export", Arg, E);
5764 ("\this usage is non-standard and non-portable", Arg);
5769 if Warn_On_Export_Import and then Is_Type (E) then
5770 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5773 if Warn_On_Export_Import and Inside_A_Generic then
5775 ("all instances of& will have the same external name?", Arg, E);
5779 ----------------------------------------------
5780 -- Set_Extended_Import_Export_External_Name --
5781 ----------------------------------------------
5783 procedure Set_Extended_Import_Export_External_Name
5784 (Internal_Ent : Entity_Id;
5785 Arg_External : Node_Id)
5787 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5791 if No (Arg_External) then
5795 Check_Arg_Is_External_Name (Arg_External);
5797 if Nkind (Arg_External) = N_String_Literal then
5798 if String_Length (Strval (Arg_External)) = 0 then
5801 New_Name := Adjust_External_Name_Case (Arg_External);
5804 elsif Nkind (Arg_External) = N_Identifier then
5805 New_Name := Get_Default_External_Name (Arg_External);
5807 -- Check_Arg_Is_External_Name should let through only identifiers and
5808 -- string literals or static string expressions (which are folded to
5809 -- string literals).
5812 raise Program_Error;
5815 -- If we already have an external name set (by a prior normal Import
5816 -- or Export pragma), then the external names must match
5818 if Present (Interface_Name (Internal_Ent)) then
5819 Check_Matching_Internal_Names : declare
5820 S1 : constant String_Id := Strval (Old_Name);
5821 S2 : constant String_Id := Strval (New_Name);
5824 -- Called if names do not match
5830 procedure Mismatch is
5832 Error_Msg_Sloc := Sloc (Old_Name);
5834 ("external name does not match that given #",
5838 -- Start of processing for Check_Matching_Internal_Names
5841 if String_Length (S1) /= String_Length (S2) then
5845 for J in 1 .. String_Length (S1) loop
5846 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5851 end Check_Matching_Internal_Names;
5853 -- Otherwise set the given name
5856 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5857 Check_Duplicated_Export_Name (New_Name);
5859 end Set_Extended_Import_Export_External_Name;
5865 procedure Set_Imported (E : Entity_Id) is
5867 -- Error message if already imported or exported
5869 if Is_Exported (E) or else Is_Imported (E) then
5871 -- Error if being set Exported twice
5873 if Is_Exported (E) then
5874 Error_Msg_NE ("entity& was previously exported", N, E);
5876 -- OK if Import/Interface case
5878 elsif Import_Interface_Present (N) then
5881 -- Error if being set Imported twice
5884 Error_Msg_NE ("entity& was previously imported", N, E);
5887 Error_Msg_Name_1 := Pname;
5889 ("\(pragma% applies to all previous entities)", N);
5891 Error_Msg_Sloc := Sloc (E);
5892 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5894 -- Here if not previously imported or exported, OK to import
5897 Set_Is_Imported (E);
5899 -- If the entity is an object that is not at the library level,
5900 -- then it is statically allocated. We do not worry about objects
5901 -- with address clauses in this context since they are not really
5902 -- imported in the linker sense.
5905 and then not Is_Library_Level_Entity (E)
5906 and then No (Address_Clause (E))
5908 Set_Is_Statically_Allocated (E);
5915 -------------------------
5916 -- Set_Mechanism_Value --
5917 -------------------------
5919 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5920 -- analyzed, since it is semantic nonsense), so we get it in the exact
5921 -- form created by the parser.
5923 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5926 Mech_Name_Id : Name_Id;
5928 procedure Bad_Class;
5929 -- Signal bad descriptor class name
5931 procedure Bad_Mechanism;
5932 -- Signal bad mechanism name
5938 procedure Bad_Class is
5940 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5943 -------------------------
5944 -- Bad_Mechanism_Value --
5945 -------------------------
5947 procedure Bad_Mechanism is
5949 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5952 -- Start of processing for Set_Mechanism_Value
5955 if Mechanism (Ent) /= Default_Mechanism then
5957 ("mechanism for & has already been set", Mech_Name, Ent);
5960 -- MECHANISM_NAME ::= value | reference | descriptor |
5963 if Nkind (Mech_Name) = N_Identifier then
5964 if Chars (Mech_Name) = Name_Value then
5965 Set_Mechanism (Ent, By_Copy);
5968 elsif Chars (Mech_Name) = Name_Reference then
5969 Set_Mechanism (Ent, By_Reference);
5972 elsif Chars (Mech_Name) = Name_Descriptor then
5973 Check_VMS (Mech_Name);
5975 -- Descriptor => Short_Descriptor if pragma was given
5977 if Short_Descriptors then
5978 Set_Mechanism (Ent, By_Short_Descriptor);
5980 Set_Mechanism (Ent, By_Descriptor);
5985 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5986 Check_VMS (Mech_Name);
5987 Set_Mechanism (Ent, By_Short_Descriptor);
5990 elsif Chars (Mech_Name) = Name_Copy then
5992 ("bad mechanism name, Value assumed", Mech_Name);
5998 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5999 -- short_descriptor (CLASS_NAME)
6000 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6002 -- Note: this form is parsed as an indexed component
6004 elsif Nkind (Mech_Name) = N_Indexed_Component then
6005 Class := First (Expressions (Mech_Name));
6007 if Nkind (Prefix (Mech_Name)) /= N_Identifier
6008 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
6009 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
6010 or else Present (Next (Class))
6014 Mech_Name_Id := Chars (Prefix (Mech_Name));
6016 -- Change Descriptor => Short_Descriptor if pragma was given
6018 if Mech_Name_Id = Name_Descriptor
6019 and then Short_Descriptors
6021 Mech_Name_Id := Name_Short_Descriptor;
6025 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6026 -- short_descriptor (Class => CLASS_NAME)
6027 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6029 -- Note: this form is parsed as a function call
6031 elsif Nkind (Mech_Name) = N_Function_Call then
6032 Param := First (Parameter_Associations (Mech_Name));
6034 if Nkind (Name (Mech_Name)) /= N_Identifier
6035 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6036 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6037 or else Present (Next (Param))
6038 or else No (Selector_Name (Param))
6039 or else Chars (Selector_Name (Param)) /= Name_Class
6043 Class := Explicit_Actual_Parameter (Param);
6044 Mech_Name_Id := Chars (Name (Mech_Name));
6051 -- Fall through here with Class set to descriptor class name
6053 Check_VMS (Mech_Name);
6055 if Nkind (Class) /= N_Identifier then
6058 elsif Mech_Name_Id = Name_Descriptor
6059 and then Chars (Class) = Name_UBS
6061 Set_Mechanism (Ent, By_Descriptor_UBS);
6063 elsif Mech_Name_Id = Name_Descriptor
6064 and then Chars (Class) = Name_UBSB
6066 Set_Mechanism (Ent, By_Descriptor_UBSB);
6068 elsif Mech_Name_Id = Name_Descriptor
6069 and then Chars (Class) = Name_UBA
6071 Set_Mechanism (Ent, By_Descriptor_UBA);
6073 elsif Mech_Name_Id = Name_Descriptor
6074 and then Chars (Class) = Name_S
6076 Set_Mechanism (Ent, By_Descriptor_S);
6078 elsif Mech_Name_Id = Name_Descriptor
6079 and then Chars (Class) = Name_SB
6081 Set_Mechanism (Ent, By_Descriptor_SB);
6083 elsif Mech_Name_Id = Name_Descriptor
6084 and then Chars (Class) = Name_A
6086 Set_Mechanism (Ent, By_Descriptor_A);
6088 elsif Mech_Name_Id = Name_Descriptor
6089 and then Chars (Class) = Name_NCA
6091 Set_Mechanism (Ent, By_Descriptor_NCA);
6093 elsif Mech_Name_Id = Name_Short_Descriptor
6094 and then Chars (Class) = Name_UBS
6096 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6098 elsif Mech_Name_Id = Name_Short_Descriptor
6099 and then Chars (Class) = Name_UBSB
6101 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6103 elsif Mech_Name_Id = Name_Short_Descriptor
6104 and then Chars (Class) = Name_UBA
6106 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6108 elsif Mech_Name_Id = Name_Short_Descriptor
6109 and then Chars (Class) = Name_S
6111 Set_Mechanism (Ent, By_Short_Descriptor_S);
6113 elsif Mech_Name_Id = Name_Short_Descriptor
6114 and then Chars (Class) = Name_SB
6116 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6118 elsif Mech_Name_Id = Name_Short_Descriptor
6119 and then Chars (Class) = Name_A
6121 Set_Mechanism (Ent, By_Short_Descriptor_A);
6123 elsif Mech_Name_Id = Name_Short_Descriptor
6124 and then Chars (Class) = Name_NCA
6126 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6131 end Set_Mechanism_Value;
6133 ---------------------------
6134 -- Set_Ravenscar_Profile --
6135 ---------------------------
6137 -- The tasks to be done here are
6139 -- Set required policies
6141 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6142 -- pragma Locking_Policy (Ceiling_Locking)
6144 -- Set Detect_Blocking mode
6146 -- Set required restrictions (see System.Rident for detailed list)
6148 -- Set the No_Dependence rules
6149 -- No_Dependence => Ada.Asynchronous_Task_Control
6150 -- No_Dependence => Ada.Calendar
6151 -- No_Dependence => Ada.Execution_Time.Group_Budget
6152 -- No_Dependence => Ada.Execution_Time.Timers
6153 -- No_Dependence => Ada.Task_Attributes
6154 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6156 procedure Set_Ravenscar_Profile (N : Node_Id) is
6157 Prefix_Entity : Entity_Id;
6158 Selector_Entity : Entity_Id;
6159 Prefix_Node : Node_Id;
6163 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6165 if Task_Dispatching_Policy /= ' '
6166 and then Task_Dispatching_Policy /= 'F'
6168 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6169 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6171 -- Set the FIFO_Within_Priorities policy, but always preserve
6172 -- System_Location since we like the error message with the run time
6176 Task_Dispatching_Policy := 'F';
6178 if Task_Dispatching_Policy_Sloc /= System_Location then
6179 Task_Dispatching_Policy_Sloc := Loc;
6183 -- pragma Locking_Policy (Ceiling_Locking)
6185 if Locking_Policy /= ' '
6186 and then Locking_Policy /= 'C'
6188 Error_Msg_Sloc := Locking_Policy_Sloc;
6189 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6191 -- Set the Ceiling_Locking policy, but preserve System_Location since
6192 -- we like the error message with the run time name.
6195 Locking_Policy := 'C';
6197 if Locking_Policy_Sloc /= System_Location then
6198 Locking_Policy_Sloc := Loc;
6202 -- pragma Detect_Blocking
6204 Detect_Blocking := True;
6206 -- Set the corresponding restrictions
6208 Set_Profile_Restrictions
6209 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6211 -- Set the No_Dependence restrictions
6213 -- The following No_Dependence restrictions:
6214 -- No_Dependence => Ada.Asynchronous_Task_Control
6215 -- No_Dependence => Ada.Calendar
6216 -- No_Dependence => Ada.Task_Attributes
6217 -- are already set by previous call to Set_Profile_Restrictions.
6219 -- Set the following restrictions which were added to Ada 2005:
6220 -- No_Dependence => Ada.Execution_Time.Group_Budget
6221 -- No_Dependence => Ada.Execution_Time.Timers
6223 if Ada_Version >= Ada_2005 then
6224 Name_Buffer (1 .. 3) := "ada";
6227 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6229 Name_Buffer (1 .. 14) := "execution_time";
6232 Selector_Entity := Make_Identifier (Loc, Name_Find);
6235 Make_Selected_Component
6237 Prefix => Prefix_Entity,
6238 Selector_Name => Selector_Entity);
6240 Name_Buffer (1 .. 13) := "group_budgets";
6243 Selector_Entity := Make_Identifier (Loc, Name_Find);
6246 Make_Selected_Component
6248 Prefix => Prefix_Node,
6249 Selector_Name => Selector_Entity);
6251 Set_Restriction_No_Dependence
6253 Warn => Treat_Restrictions_As_Warnings,
6254 Profile => Ravenscar);
6256 Name_Buffer (1 .. 6) := "timers";
6259 Selector_Entity := Make_Identifier (Loc, Name_Find);
6262 Make_Selected_Component
6264 Prefix => Prefix_Node,
6265 Selector_Name => Selector_Entity);
6267 Set_Restriction_No_Dependence
6269 Warn => Treat_Restrictions_As_Warnings,
6270 Profile => Ravenscar);
6273 -- Set the following restrictions which was added to Ada 2012 (see
6275 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6277 if Ada_Version >= Ada_2012 then
6278 Name_Buffer (1 .. 6) := "system";
6281 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6283 Name_Buffer (1 .. 15) := "multiprocessors";
6286 Selector_Entity := Make_Identifier (Loc, Name_Find);
6289 Make_Selected_Component
6291 Prefix => Prefix_Entity,
6292 Selector_Name => Selector_Entity);
6294 Name_Buffer (1 .. 19) := "dispatching_domains";
6297 Selector_Entity := Make_Identifier (Loc, Name_Find);
6300 Make_Selected_Component
6302 Prefix => Prefix_Node,
6303 Selector_Name => Selector_Entity);
6305 Set_Restriction_No_Dependence
6307 Warn => Treat_Restrictions_As_Warnings,
6308 Profile => Ravenscar);
6310 end Set_Ravenscar_Profile;
6312 -- Start of processing for Analyze_Pragma
6315 -- The following code is a defense against recursion. Not clear that
6316 -- this can happen legitimately, but perhaps some error situations
6317 -- can cause it, and we did see this recursion during testing.
6319 if Analyzed (N) then
6322 Set_Analyzed (N, True);
6325 -- Deal with unrecognized pragma
6327 Pname := Pragma_Name (N);
6329 if not Is_Pragma_Name (Pname) then
6330 if Warn_On_Unrecognized_Pragma then
6331 Error_Msg_Name_1 := Pname;
6332 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6334 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6335 if Is_Bad_Spelling_Of (Pname, PN) then
6336 Error_Msg_Name_1 := PN;
6337 Error_Msg_N -- CODEFIX
6338 ("\?possible misspelling of %!", Pragma_Identifier (N));
6347 -- Here to start processing for recognized pragma
6349 Prag_Id := Get_Pragma_Id (Pname);
6351 if Present (Corresponding_Aspect (N)) then
6352 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6363 if Present (Pragma_Argument_Associations (N)) then
6364 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6365 Arg1 := First (Pragma_Argument_Associations (N));
6367 if Present (Arg1) then
6368 Arg2 := Next (Arg1);
6370 if Present (Arg2) then
6371 Arg3 := Next (Arg2);
6373 if Present (Arg3) then
6374 Arg4 := Next (Arg3);
6380 -- An enumeration type defines the pragmas that are supported by the
6381 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6382 -- into the corresponding enumeration value for the following case.
6390 -- pragma Abort_Defer;
6392 when Pragma_Abort_Defer =>
6394 Check_Arg_Count (0);
6396 -- The only required semantic processing is to check the
6397 -- placement. This pragma must appear at the start of the
6398 -- statement sequence of a handled sequence of statements.
6400 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6401 or else N /= First (Statements (Parent (N)))
6412 -- Note: this pragma also has some specific processing in Par.Prag
6413 -- because we want to set the Ada version mode during parsing.
6415 when Pragma_Ada_83 =>
6417 Check_Arg_Count (0);
6419 -- We really should check unconditionally for proper configuration
6420 -- pragma placement, since we really don't want mixed Ada modes
6421 -- within a single unit, and the GNAT reference manual has always
6422 -- said this was a configuration pragma, but we did not check and
6423 -- are hesitant to add the check now.
6425 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6426 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6427 -- or Ada 2012 mode.
6429 if Ada_Version >= Ada_2005 then
6430 Check_Valid_Configuration_Pragma;
6433 -- Now set Ada 83 mode
6435 Ada_Version := Ada_83;
6436 Ada_Version_Explicit := Ada_Version;
6444 -- Note: this pragma also has some specific processing in Par.Prag
6445 -- because we want to set the Ada 83 version mode during parsing.
6447 when Pragma_Ada_95 =>
6449 Check_Arg_Count (0);
6451 -- We really should check unconditionally for proper configuration
6452 -- pragma placement, since we really don't want mixed Ada modes
6453 -- within a single unit, and the GNAT reference manual has always
6454 -- said this was a configuration pragma, but we did not check and
6455 -- are hesitant to add the check now.
6457 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6458 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6460 if Ada_Version >= Ada_2005 then
6461 Check_Valid_Configuration_Pragma;
6464 -- Now set Ada 95 mode
6466 Ada_Version := Ada_95;
6467 Ada_Version_Explicit := Ada_Version;
6469 ---------------------
6470 -- Ada_05/Ada_2005 --
6471 ---------------------
6474 -- pragma Ada_05 (LOCAL_NAME);
6477 -- pragma Ada_2005 (LOCAL_NAME):
6479 -- Note: these pragmas also have some specific processing in Par.Prag
6480 -- because we want to set the Ada 2005 version mode during parsing.
6482 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6488 if Arg_Count = 1 then
6489 Check_Arg_Is_Local_Name (Arg1);
6490 E_Id := Get_Pragma_Arg (Arg1);
6492 if Etype (E_Id) = Any_Type then
6496 Set_Is_Ada_2005_Only (Entity (E_Id));
6499 Check_Arg_Count (0);
6501 -- For Ada_2005 we unconditionally enforce the documented
6502 -- configuration pragma placement, since we do not want to
6503 -- tolerate mixed modes in a unit involving Ada 2005. That
6504 -- would cause real difficulties for those cases where there
6505 -- are incompatibilities between Ada 95 and Ada 2005.
6507 Check_Valid_Configuration_Pragma;
6509 -- Now set appropriate Ada mode
6511 Ada_Version := Ada_2005;
6512 Ada_Version_Explicit := Ada_2005;
6516 ---------------------
6517 -- Ada_12/Ada_2012 --
6518 ---------------------
6521 -- pragma Ada_12 (LOCAL_NAME);
6524 -- pragma Ada_2012 (LOCAL_NAME):
6526 -- Note: these pragmas also have some specific processing in Par.Prag
6527 -- because we want to set the Ada 2012 version mode during parsing.
6529 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6535 if Arg_Count = 1 then
6536 Check_Arg_Is_Local_Name (Arg1);
6537 E_Id := Get_Pragma_Arg (Arg1);
6539 if Etype (E_Id) = Any_Type then
6543 Set_Is_Ada_2012_Only (Entity (E_Id));
6546 Check_Arg_Count (0);
6548 -- For Ada_2012 we unconditionally enforce the documented
6549 -- configuration pragma placement, since we do not want to
6550 -- tolerate mixed modes in a unit involving Ada 2012. That
6551 -- would cause real difficulties for those cases where there
6552 -- are incompatibilities between Ada 95 and Ada 2012. We could
6553 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6555 Check_Valid_Configuration_Pragma;
6557 -- Now set appropriate Ada mode
6559 Ada_Version := Ada_2012;
6560 Ada_Version_Explicit := Ada_2012;
6564 ----------------------
6565 -- All_Calls_Remote --
6566 ----------------------
6568 -- pragma All_Calls_Remote [(library_package_NAME)];
6570 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6571 Lib_Entity : Entity_Id;
6574 Check_Ada_83_Warning;
6575 Check_Valid_Library_Unit_Pragma;
6577 if Nkind (N) = N_Null_Statement then
6581 Lib_Entity := Find_Lib_Unit_Name;
6583 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6585 if Present (Lib_Entity)
6586 and then not Debug_Flag_U
6588 if not Is_Remote_Call_Interface (Lib_Entity) then
6589 Error_Pragma ("pragma% only apply to rci unit");
6591 -- Set flag for entity of the library unit
6594 Set_Has_All_Calls_Remote (Lib_Entity);
6598 end All_Calls_Remote;
6604 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6605 -- ARG ::= NAME | EXPRESSION
6607 -- The first two arguments are by convention intended to refer to an
6608 -- external tool and a tool-specific function. These arguments are
6611 when Pragma_Annotate => Annotate : declare
6617 Check_At_Least_N_Arguments (1);
6618 Check_Arg_Is_Identifier (Arg1);
6619 Check_No_Identifiers;
6622 -- Second parameter is optional, it is never analyzed
6627 -- Here if we have a second parameter
6630 -- Second parameter must be identifier
6632 Check_Arg_Is_Identifier (Arg2);
6634 -- Process remaining parameters if any
6637 while Present (Arg) loop
6638 Exp := Get_Pragma_Arg (Arg);
6641 if Is_Entity_Name (Exp) then
6644 -- For string literals, we assume Standard_String as the
6645 -- type, unless the string contains wide or wide_wide
6648 elsif Nkind (Exp) = N_String_Literal then
6649 if Has_Wide_Wide_Character (Exp) then
6650 Resolve (Exp, Standard_Wide_Wide_String);
6651 elsif Has_Wide_Character (Exp) then
6652 Resolve (Exp, Standard_Wide_String);
6654 Resolve (Exp, Standard_String);
6657 elsif Is_Overloaded (Exp) then
6659 ("ambiguous argument for pragma%", Exp);
6674 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6675 -- [, [Message =>] Static_String_EXPRESSION]);
6677 when Pragma_Assert => Assert : declare
6683 Check_At_Least_N_Arguments (1);
6684 Check_At_Most_N_Arguments (2);
6685 Check_Arg_Order ((Name_Check, Name_Message));
6686 Check_Optional_Identifier (Arg1, Name_Check);
6688 -- We treat pragma Assert as equivalent to:
6690 -- pragma Check (Assertion, condition [, msg]);
6692 -- So rewrite pragma in this manner, and analyze the result
6694 Expr := Get_Pragma_Arg (Arg1);
6696 Make_Pragma_Argument_Association (Loc,
6697 Expression => Make_Identifier (Loc, Name_Assertion)),
6699 Make_Pragma_Argument_Association (Sloc (Expr),
6700 Expression => Expr));
6702 if Arg_Count > 1 then
6703 Check_Optional_Identifier (Arg2, Name_Message);
6704 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6705 Append_To (Newa, Relocate_Node (Arg2));
6710 Chars => Name_Check,
6711 Pragma_Argument_Associations => Newa));
6715 ----------------------
6716 -- Assertion_Policy --
6717 ----------------------
6719 -- pragma Assertion_Policy (Check | Disable |Ignore)
6721 when Pragma_Assertion_Policy => Assertion_Policy : declare
6726 Check_Valid_Configuration_Pragma;
6727 Check_Arg_Count (1);
6728 Check_No_Identifiers;
6729 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6731 -- We treat pragma Assertion_Policy as equivalent to:
6733 -- pragma Check_Policy (Assertion, policy)
6735 -- So rewrite the pragma in that manner and link on to the chain
6736 -- of Check_Policy pragmas, marking the pragma as analyzed.
6738 Policy := Get_Pragma_Arg (Arg1);
6742 Chars => Name_Check_Policy,
6744 Pragma_Argument_Associations => New_List (
6745 Make_Pragma_Argument_Association (Loc,
6746 Expression => Make_Identifier (Loc, Name_Assertion)),
6748 Make_Pragma_Argument_Association (Loc,
6750 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6753 Set_Next_Pragma (N, Opt.Check_Policy_List);
6754 Opt.Check_Policy_List := N;
6755 end Assertion_Policy;
6757 ------------------------------
6758 -- Assume_No_Invalid_Values --
6759 ------------------------------
6761 -- pragma Assume_No_Invalid_Values (On | Off);
6763 when Pragma_Assume_No_Invalid_Values =>
6765 Check_Valid_Configuration_Pragma;
6766 Check_Arg_Count (1);
6767 Check_No_Identifiers;
6768 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6770 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6771 Assume_No_Invalid_Values := True;
6773 Assume_No_Invalid_Values := False;
6780 -- pragma AST_Entry (entry_IDENTIFIER);
6782 when Pragma_AST_Entry => AST_Entry : declare
6788 Check_Arg_Count (1);
6789 Check_No_Identifiers;
6790 Check_Arg_Is_Local_Name (Arg1);
6791 Ent := Entity (Get_Pragma_Arg (Arg1));
6793 -- Note: the implementation of the AST_Entry pragma could handle
6794 -- the entry family case fine, but for now we are consistent with
6795 -- the DEC rules, and do not allow the pragma, which of course
6796 -- has the effect of also forbidding the attribute.
6798 if Ekind (Ent) /= E_Entry then
6800 ("pragma% argument must be simple entry name", Arg1);
6802 elsif Is_AST_Entry (Ent) then
6804 ("duplicate % pragma for entry", Arg1);
6806 elsif Has_Homonym (Ent) then
6808 ("pragma% argument cannot specify overloaded entry", Arg1);
6812 FF : constant Entity_Id := First_Formal (Ent);
6815 if Present (FF) then
6816 if Present (Next_Formal (FF)) then
6818 ("entry for pragma% can have only one argument",
6821 elsif Parameter_Mode (FF) /= E_In_Parameter then
6823 ("entry parameter for pragma% must have mode IN",
6829 Set_Is_AST_Entry (Ent);
6837 -- pragma Asynchronous (LOCAL_NAME);
6839 when Pragma_Asynchronous => Asynchronous : declare
6847 procedure Process_Async_Pragma;
6848 -- Common processing for procedure and access-to-procedure case
6850 --------------------------
6851 -- Process_Async_Pragma --
6852 --------------------------
6854 procedure Process_Async_Pragma is
6857 Set_Is_Asynchronous (Nm);
6861 -- The formals should be of mode IN (RM E.4.1(6))
6864 while Present (S) loop
6865 Formal := Defining_Identifier (S);
6867 if Nkind (Formal) = N_Defining_Identifier
6868 and then Ekind (Formal) /= E_In_Parameter
6871 ("pragma% procedure can only have IN parameter",
6878 Set_Is_Asynchronous (Nm);
6879 end Process_Async_Pragma;
6881 -- Start of processing for pragma Asynchronous
6884 Check_Ada_83_Warning;
6885 Check_No_Identifiers;
6886 Check_Arg_Count (1);
6887 Check_Arg_Is_Local_Name (Arg1);
6889 if Debug_Flag_U then
6893 C_Ent := Cunit_Entity (Current_Sem_Unit);
6894 Analyze (Get_Pragma_Arg (Arg1));
6895 Nm := Entity (Get_Pragma_Arg (Arg1));
6897 if not Is_Remote_Call_Interface (C_Ent)
6898 and then not Is_Remote_Types (C_Ent)
6900 -- This pragma should only appear in an RCI or Remote Types
6901 -- unit (RM E.4.1(4)).
6904 ("pragma% not in Remote_Call_Interface or " &
6905 "Remote_Types unit");
6908 if Ekind (Nm) = E_Procedure
6909 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6911 if not Is_Remote_Call_Interface (Nm) then
6913 ("pragma% cannot be applied on non-remote procedure",
6917 L := Parameter_Specifications (Parent (Nm));
6918 Process_Async_Pragma;
6921 elsif Ekind (Nm) = E_Function then
6923 ("pragma% cannot be applied to function", Arg1);
6925 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6926 if Is_Record_Type (Nm) then
6928 -- A record type that is the Equivalent_Type for a remote
6929 -- access-to-subprogram type.
6931 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6934 -- A non-expanded RAS type (distribution is not enabled)
6936 N := Declaration_Node (Nm);
6939 if Nkind (N) = N_Full_Type_Declaration
6940 and then Nkind (Type_Definition (N)) =
6941 N_Access_Procedure_Definition
6943 L := Parameter_Specifications (Type_Definition (N));
6944 Process_Async_Pragma;
6946 if Is_Asynchronous (Nm)
6947 and then Expander_Active
6948 and then Get_PCS_Name /= Name_No_DSA
6950 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6955 ("pragma% cannot reference access-to-function type",
6959 -- Only other possibility is Access-to-class-wide type
6961 elsif Is_Access_Type (Nm)
6962 and then Is_Class_Wide_Type (Designated_Type (Nm))
6964 Check_First_Subtype (Arg1);
6965 Set_Is_Asynchronous (Nm);
6966 if Expander_Active then
6967 RACW_Type_Is_Asynchronous (Nm);
6971 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6979 -- pragma Atomic (LOCAL_NAME);
6981 when Pragma_Atomic =>
6982 Process_Atomic_Shared_Volatile;
6984 -----------------------
6985 -- Atomic_Components --
6986 -----------------------
6988 -- pragma Atomic_Components (array_LOCAL_NAME);
6990 -- This processing is shared by Volatile_Components
6992 when Pragma_Atomic_Components |
6993 Pragma_Volatile_Components =>
6995 Atomic_Components : declare
7002 Check_Ada_83_Warning;
7003 Check_No_Identifiers;
7004 Check_Arg_Count (1);
7005 Check_Arg_Is_Local_Name (Arg1);
7006 E_Id := Get_Pragma_Arg (Arg1);
7008 if Etype (E_Id) = Any_Type then
7014 Check_Duplicate_Pragma (E);
7016 if Rep_Item_Too_Early (E, N)
7018 Rep_Item_Too_Late (E, N)
7023 D := Declaration_Node (E);
7026 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7028 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7029 and then Nkind (D) = N_Object_Declaration
7030 and then Nkind (Object_Definition (D)) =
7031 N_Constrained_Array_Definition)
7033 -- The flag is set on the object, or on the base type
7035 if Nkind (D) /= N_Object_Declaration then
7039 Set_Has_Volatile_Components (E);
7041 if Prag_Id = Pragma_Atomic_Components then
7042 Set_Has_Atomic_Components (E);
7046 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7048 end Atomic_Components;
7049 --------------------
7050 -- Attach_Handler --
7051 --------------------
7053 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7055 when Pragma_Attach_Handler =>
7056 Check_Ada_83_Warning;
7057 Check_No_Identifiers;
7058 Check_Arg_Count (2);
7060 if No_Run_Time_Mode then
7061 Error_Msg_CRT ("Attach_Handler pragma", N);
7063 Check_Interrupt_Or_Attach_Handler;
7065 -- The expression that designates the attribute may depend on a
7066 -- discriminant, and is therefore a per- object expression, to
7067 -- be expanded in the init proc. If expansion is enabled, then
7068 -- perform semantic checks on a copy only.
7070 if Expander_Active then
7072 Temp : constant Node_Id :=
7073 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7075 Set_Parent (Temp, N);
7076 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7080 Analyze (Get_Pragma_Arg (Arg2));
7081 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7084 Process_Interrupt_Or_Attach_Handler;
7087 --------------------
7088 -- C_Pass_By_Copy --
7089 --------------------
7091 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7093 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7099 Check_Valid_Configuration_Pragma;
7100 Check_Arg_Count (1);
7101 Check_Optional_Identifier (Arg1, "max_size");
7103 Arg := Get_Pragma_Arg (Arg1);
7104 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7106 Val := Expr_Value (Arg);
7110 ("maximum size for pragma% must be positive", Arg1);
7112 elsif UI_Is_In_Int_Range (Val) then
7113 Default_C_Record_Mechanism := UI_To_Int (Val);
7115 -- If a giant value is given, Int'Last will do well enough.
7116 -- If sometime someone complains that a record larger than
7117 -- two gigabytes is not copied, we will worry about it then!
7120 Default_C_Record_Mechanism := Mechanism_Type'Last;
7128 -- pragma Check ([Name =>] IDENTIFIER,
7129 -- [Check =>] Boolean_EXPRESSION
7130 -- [,[Message =>] String_EXPRESSION]);
7132 when Pragma_Check => Check : declare
7137 -- Set True if category of assertions referenced by Name enabled
7141 Check_At_Least_N_Arguments (2);
7142 Check_At_Most_N_Arguments (3);
7143 Check_Optional_Identifier (Arg1, Name_Name);
7144 Check_Optional_Identifier (Arg2, Name_Check);
7146 if Arg_Count = 3 then
7147 Check_Optional_Identifier (Arg3, Name_Message);
7148 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7151 Check_Arg_Is_Identifier (Arg1);
7153 -- Completely ignore if disabled
7155 if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7156 Rewrite (N, Make_Null_Statement (Loc));
7161 -- Indicate if pragma is enabled. The Original_Node reference here
7162 -- is to deal with pragma Assert rewritten as a Check pragma.
7164 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
7167 Set_SCO_Pragma_Enabled (Loc);
7170 -- If expansion is active and the check is not enabled then we
7171 -- rewrite the Check as:
7173 -- if False and then condition then
7177 -- The reason we do this rewriting during semantic analysis rather
7178 -- than as part of normal expansion is that we cannot analyze and
7179 -- expand the code for the boolean expression directly, or it may
7180 -- cause insertion of actions that would escape the attempt to
7181 -- suppress the check code.
7183 -- Note that the Sloc for the if statement corresponds to the
7184 -- argument condition, not the pragma itself. The reason for this
7185 -- is that we may generate a warning if the condition is False at
7186 -- compile time, and we do not want to delete this warning when we
7187 -- delete the if statement.
7189 Expr := Get_Pragma_Arg (Arg2);
7191 if Expander_Active and then not Check_On then
7192 Eloc := Sloc (Expr);
7195 Make_If_Statement (Eloc,
7197 Make_And_Then (Eloc,
7198 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7199 Right_Opnd => Expr),
7200 Then_Statements => New_List (
7201 Make_Null_Statement (Eloc))));
7208 Analyze_And_Resolve (Expr, Any_Boolean);
7216 -- pragma Check_Name (check_IDENTIFIER);
7218 when Pragma_Check_Name =>
7219 Check_No_Identifiers;
7221 Check_Valid_Configuration_Pragma;
7222 Check_Arg_Count (1);
7223 Check_Arg_Is_Identifier (Arg1);
7226 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7229 for J in Check_Names.First .. Check_Names.Last loop
7230 if Check_Names.Table (J) = Nam then
7235 Check_Names.Append (Nam);
7242 -- pragma Check_Policy (
7243 -- [Name =>] IDENTIFIER,
7244 -- [Policy =>] POLICY_IDENTIFIER);
7246 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7248 -- Note: this is a configuration pragma, but it is allowed to appear
7251 when Pragma_Check_Policy =>
7253 Check_Arg_Count (2);
7254 Check_Optional_Identifier (Arg1, Name_Name);
7255 Check_Optional_Identifier (Arg2, Name_Policy);
7257 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7259 -- A Check_Policy pragma can appear either as a configuration
7260 -- pragma, or in a declarative part or a package spec (see RM
7261 -- 11.5(5) for rules for Suppress/Unsuppress which are also
7262 -- followed for Check_Policy).
7264 if not Is_Configuration_Pragma then
7265 Check_Is_In_Decl_Part_Or_Package_Spec;
7268 Set_Next_Pragma (N, Opt.Check_Policy_List);
7269 Opt.Check_Policy_List := N;
7271 ---------------------
7272 -- CIL_Constructor --
7273 ---------------------
7275 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7277 -- Processing for this pragma is shared with Java_Constructor
7283 -- pragma Comment (static_string_EXPRESSION)
7285 -- Processing for pragma Comment shares the circuitry for pragma
7286 -- Ident. The only differences are that Ident enforces a limit of 31
7287 -- characters on its argument, and also enforces limitations on
7288 -- placement for DEC compatibility. Pragma Comment shares neither of
7289 -- these restrictions.
7295 -- pragma Common_Object (
7296 -- [Internal =>] LOCAL_NAME
7297 -- [, [External =>] EXTERNAL_SYMBOL]
7298 -- [, [Size =>] EXTERNAL_SYMBOL]);
7300 -- Processing for this pragma is shared with Psect_Object
7302 ------------------------
7303 -- Compile_Time_Error --
7304 ------------------------
7306 -- pragma Compile_Time_Error
7307 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7309 when Pragma_Compile_Time_Error =>
7311 Process_Compile_Time_Warning_Or_Error;
7313 --------------------------
7314 -- Compile_Time_Warning --
7315 --------------------------
7317 -- pragma Compile_Time_Warning
7318 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7320 when Pragma_Compile_Time_Warning =>
7322 Process_Compile_Time_Warning_Or_Error;
7328 when Pragma_Compiler_Unit =>
7330 Check_Arg_Count (0);
7331 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7333 -----------------------------
7334 -- Complete_Representation --
7335 -----------------------------
7337 -- pragma Complete_Representation;
7339 when Pragma_Complete_Representation =>
7341 Check_Arg_Count (0);
7343 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7345 ("pragma & must appear within record representation clause");
7348 ----------------------------
7349 -- Complex_Representation --
7350 ----------------------------
7352 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7354 when Pragma_Complex_Representation => Complex_Representation : declare
7361 Check_Arg_Count (1);
7362 Check_Optional_Identifier (Arg1, Name_Entity);
7363 Check_Arg_Is_Local_Name (Arg1);
7364 E_Id := Get_Pragma_Arg (Arg1);
7366 if Etype (E_Id) = Any_Type then
7372 if not Is_Record_Type (E) then
7374 ("argument for pragma% must be record type", Arg1);
7377 Ent := First_Entity (E);
7380 or else No (Next_Entity (Ent))
7381 or else Present (Next_Entity (Next_Entity (Ent)))
7382 or else not Is_Floating_Point_Type (Etype (Ent))
7383 or else Etype (Ent) /= Etype (Next_Entity (Ent))
7386 ("record for pragma% must have two fields of the same "
7387 & "floating-point type", Arg1);
7390 Set_Has_Complex_Representation (Base_Type (E));
7392 -- We need to treat the type has having a non-standard
7393 -- representation, for back-end purposes, even though in
7394 -- general a complex will have the default representation
7395 -- of a record with two real components.
7397 Set_Has_Non_Standard_Rep (Base_Type (E));
7399 end Complex_Representation;
7401 -------------------------
7402 -- Component_Alignment --
7403 -------------------------
7405 -- pragma Component_Alignment (
7406 -- [Form =>] ALIGNMENT_CHOICE
7407 -- [, [Name =>] type_LOCAL_NAME]);
7409 -- ALIGNMENT_CHOICE ::=
7411 -- | Component_Size_4
7415 when Pragma_Component_Alignment => Component_AlignmentP : declare
7416 Args : Args_List (1 .. 2);
7417 Names : constant Name_List (1 .. 2) := (
7421 Form : Node_Id renames Args (1);
7422 Name : Node_Id renames Args (2);
7424 Atype : Component_Alignment_Kind;
7429 Gather_Associations (Names, Args);
7432 Error_Pragma ("missing Form argument for pragma%");
7435 Check_Arg_Is_Identifier (Form);
7437 -- Get proper alignment, note that Default = Component_Size on all
7438 -- machines we have so far, and we want to set this value rather
7439 -- than the default value to indicate that it has been explicitly
7440 -- set (and thus will not get overridden by the default component
7441 -- alignment for the current scope)
7443 if Chars (Form) = Name_Component_Size then
7444 Atype := Calign_Component_Size;
7446 elsif Chars (Form) = Name_Component_Size_4 then
7447 Atype := Calign_Component_Size_4;
7449 elsif Chars (Form) = Name_Default then
7450 Atype := Calign_Component_Size;
7452 elsif Chars (Form) = Name_Storage_Unit then
7453 Atype := Calign_Storage_Unit;
7457 ("invalid Form parameter for pragma%", Form);
7460 -- Case with no name, supplied, affects scope table entry
7464 (Scope_Stack.Last).Component_Alignment_Default := Atype;
7466 -- Case of name supplied
7469 Check_Arg_Is_Local_Name (Name);
7471 Typ := Entity (Name);
7474 or else Rep_Item_Too_Early (Typ, N)
7478 Typ := Underlying_Type (Typ);
7481 if not Is_Record_Type (Typ)
7482 and then not Is_Array_Type (Typ)
7485 ("Name parameter of pragma% must identify record or " &
7486 "array type", Name);
7489 -- An explicit Component_Alignment pragma overrides an
7490 -- implicit pragma Pack, but not an explicit one.
7492 if not Has_Pragma_Pack (Base_Type (Typ)) then
7493 Set_Is_Packed (Base_Type (Typ), False);
7494 Set_Component_Alignment (Base_Type (Typ), Atype);
7497 end Component_AlignmentP;
7503 -- pragma Controlled (first_subtype_LOCAL_NAME);
7505 when Pragma_Controlled => Controlled : declare
7509 Check_No_Identifiers;
7510 Check_Arg_Count (1);
7511 Check_Arg_Is_Local_Name (Arg1);
7512 Arg := Get_Pragma_Arg (Arg1);
7514 if not Is_Entity_Name (Arg)
7515 or else not Is_Access_Type (Entity (Arg))
7517 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7519 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7527 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
7528 -- [Entity =>] LOCAL_NAME);
7530 when Pragma_Convention => Convention : declare
7533 pragma Warnings (Off, C);
7534 pragma Warnings (Off, E);
7536 Check_Arg_Order ((Name_Convention, Name_Entity));
7537 Check_Ada_83_Warning;
7538 Check_Arg_Count (2);
7539 Process_Convention (C, E);
7542 ---------------------------
7543 -- Convention_Identifier --
7544 ---------------------------
7546 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7547 -- [Convention =>] convention_IDENTIFIER);
7549 when Pragma_Convention_Identifier => Convention_Identifier : declare
7555 Check_Arg_Order ((Name_Name, Name_Convention));
7556 Check_Arg_Count (2);
7557 Check_Optional_Identifier (Arg1, Name_Name);
7558 Check_Optional_Identifier (Arg2, Name_Convention);
7559 Check_Arg_Is_Identifier (Arg1);
7560 Check_Arg_Is_Identifier (Arg2);
7561 Idnam := Chars (Get_Pragma_Arg (Arg1));
7562 Cname := Chars (Get_Pragma_Arg (Arg2));
7564 if Is_Convention_Name (Cname) then
7565 Record_Convention_Identifier
7566 (Idnam, Get_Convention_Id (Cname));
7569 ("second arg for % pragma must be convention", Arg2);
7571 end Convention_Identifier;
7577 -- pragma CPP_Class ([Entity =>] local_NAME)
7579 when Pragma_CPP_Class => CPP_Class : declare
7584 if Warn_On_Obsolescent_Feature then
7586 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7587 " by pragma import?", N);
7591 Check_Arg_Count (1);
7592 Check_Optional_Identifier (Arg1, Name_Entity);
7593 Check_Arg_Is_Local_Name (Arg1);
7595 Arg := Get_Pragma_Arg (Arg1);
7598 if Etype (Arg) = Any_Type then
7602 if not Is_Entity_Name (Arg)
7603 or else not Is_Type (Entity (Arg))
7605 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7608 Typ := Entity (Arg);
7610 if not Is_Tagged_Type (Typ) then
7611 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7614 -- Types treated as CPP classes must be declared limited (note:
7615 -- this used to be a warning but there is no real benefit to it
7616 -- since we did effectively intend to treat the type as limited
7619 if not Is_Limited_Type (Typ) then
7621 ("imported 'C'P'P type must be limited",
7622 Get_Pragma_Arg (Arg1));
7625 Set_Is_CPP_Class (Typ);
7626 Set_Convention (Typ, Convention_CPP);
7628 -- Imported CPP types must not have discriminants (because C++
7629 -- classes do not have discriminants).
7631 if Has_Discriminants (Typ) then
7633 ("imported 'C'P'P type cannot have discriminants",
7634 First (Discriminant_Specifications
7635 (Declaration_Node (Typ))));
7638 -- Components of imported CPP types must not have default
7639 -- expressions because the constructor (if any) is in the
7642 if Is_Incomplete_Or_Private_Type (Typ)
7643 and then No (Underlying_Type (Typ))
7645 -- It should be an error to apply pragma CPP to a private
7646 -- type if the underlying type is not visible (as it is
7647 -- for any representation item). For now, for backward
7648 -- compatibility we do nothing but we cannot check components
7649 -- because they are not available at this stage. All this code
7650 -- will be removed when we cleanup this obsolete GNAT pragma???
7656 Tdef : constant Node_Id :=
7657 Type_Definition (Declaration_Node (Typ));
7662 if Nkind (Tdef) = N_Record_Definition then
7663 Clist := Component_List (Tdef);
7665 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7666 Clist := Component_List (Record_Extension_Part (Tdef));
7669 if Present (Clist) then
7670 Comp := First (Component_Items (Clist));
7671 while Present (Comp) loop
7672 if Present (Expression (Comp)) then
7674 ("component of imported 'C'P'P type cannot have" &
7675 " default expression", Expression (Comp));
7685 ---------------------
7686 -- CPP_Constructor --
7687 ---------------------
7689 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7690 -- [, [External_Name =>] static_string_EXPRESSION ]
7691 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7693 when Pragma_CPP_Constructor => CPP_Constructor : declare
7697 Tag_Typ : Entity_Id;
7701 Check_At_Least_N_Arguments (1);
7702 Check_At_Most_N_Arguments (3);
7703 Check_Optional_Identifier (Arg1, Name_Entity);
7704 Check_Arg_Is_Local_Name (Arg1);
7706 Id := Get_Pragma_Arg (Arg1);
7707 Find_Program_Unit_Name (Id);
7709 -- If we did not find the name, we are done
7711 if Etype (Id) = Any_Type then
7715 Def_Id := Entity (Id);
7717 -- Check if already defined as constructor
7719 if Is_Constructor (Def_Id) then
7721 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7725 if Ekind (Def_Id) = E_Function
7726 and then (Is_CPP_Class (Etype (Def_Id))
7727 or else (Is_Class_Wide_Type (Etype (Def_Id))
7729 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7731 if Arg_Count >= 2 then
7732 Set_Imported (Def_Id);
7733 Set_Is_Public (Def_Id);
7734 Process_Interface_Name (Def_Id, Arg2, Arg3);
7737 Set_Has_Completion (Def_Id);
7738 Set_Is_Constructor (Def_Id);
7740 -- Imported C++ constructors are not dispatching primitives
7741 -- because in C++ they don't have a dispatch table slot.
7742 -- However, in Ada the constructor has the profile of a
7743 -- function that returns a tagged type and therefore it has
7744 -- been treated as a primitive operation during semantic
7745 -- analysis. We now remove it from the list of primitive
7746 -- operations of the type.
7748 if Is_Tagged_Type (Etype (Def_Id))
7749 and then not Is_Class_Wide_Type (Etype (Def_Id))
7751 pragma Assert (Is_Dispatching_Operation (Def_Id));
7752 Tag_Typ := Etype (Def_Id);
7754 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7755 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7759 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7760 Set_Is_Dispatching_Operation (Def_Id, False);
7763 -- For backward compatibility, if the constructor returns a
7764 -- class wide type, and we internally change the return type to
7765 -- the corresponding root type.
7767 if Is_Class_Wide_Type (Etype (Def_Id)) then
7768 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7772 ("pragma% requires function returning a 'C'P'P_Class type",
7775 end CPP_Constructor;
7781 when Pragma_CPP_Virtual => CPP_Virtual : declare
7785 if Warn_On_Obsolescent_Feature then
7787 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7796 when Pragma_CPP_Vtable => CPP_Vtable : declare
7800 if Warn_On_Obsolescent_Feature then
7802 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7811 -- pragma CPU (EXPRESSION);
7813 when Pragma_CPU => CPU : declare
7814 P : constant Node_Id := Parent (N);
7819 Check_No_Identifiers;
7820 Check_Arg_Count (1);
7824 if Nkind (P) = N_Subprogram_Body then
7825 Check_In_Main_Program;
7827 Arg := Get_Pragma_Arg (Arg1);
7828 Analyze_And_Resolve (Arg, Any_Integer);
7832 if not Is_Static_Expression (Arg) then
7833 Flag_Non_Static_Expr
7834 ("main subprogram affinity is not static!", Arg);
7837 -- If constraint error, then we already signalled an error
7839 elsif Raises_Constraint_Error (Arg) then
7842 -- Otherwise check in range
7846 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7847 -- This is the entity System.Multiprocessors.CPU_Range;
7849 Val : constant Uint := Expr_Value (Arg);
7852 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7854 Val > Expr_Value (Type_High_Bound (CPU_Id))
7857 ("main subprogram CPU is out of range", Arg1);
7863 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7867 elsif Nkind (P) = N_Task_Definition then
7868 Arg := Get_Pragma_Arg (Arg1);
7870 -- The expression must be analyzed in the special manner
7871 -- described in "Handling of Default and Per-Object
7872 -- Expressions" in sem.ads.
7874 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7876 -- Anything else is incorrect
7882 if Has_Pragma_CPU (P) then
7883 Error_Pragma ("duplicate pragma% not allowed");
7885 Set_Has_Pragma_CPU (P, True);
7887 if Nkind (P) = N_Task_Definition then
7888 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7897 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7899 when Pragma_Debug => Debug : declare
7906 -- Skip analysis if disabled
7908 if Debug_Pragmas_Disabled then
7909 Rewrite (N, Make_Null_Statement (Loc));
7916 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7919 if Debug_Pragmas_Enabled then
7920 Set_SCO_Pragma_Enabled (Loc);
7923 if Arg_Count = 2 then
7926 Left_Opnd => Relocate_Node (Cond),
7927 Right_Opnd => Get_Pragma_Arg (Arg1));
7928 Call := Get_Pragma_Arg (Arg2);
7930 Call := Get_Pragma_Arg (Arg1);
7934 N_Indexed_Component,
7938 N_Selected_Component)
7940 -- If this pragma Debug comes from source, its argument was
7941 -- parsed as a name form (which is syntactically identical).
7942 -- In a generic context a parameterless call will be left as
7943 -- an expanded name (if global) or selected_component if local.
7944 -- Change it to a procedure call statement now.
7946 Change_Name_To_Procedure_Call_Statement (Call);
7948 elsif Nkind (Call) = N_Procedure_Call_Statement then
7950 -- Already in the form of a procedure call statement: nothing
7951 -- to do (could happen in case of an internally generated
7957 -- All other cases: diagnose error
7960 ("argument of pragma ""Debug"" is not procedure call",
7965 -- Rewrite into a conditional with an appropriate condition. We
7966 -- wrap the procedure call in a block so that overhead from e.g.
7967 -- use of the secondary stack does not generate execution overhead
7968 -- for suppressed conditions.
7970 Rewrite (N, Make_Implicit_If_Statement (N,
7972 Then_Statements => New_List (
7973 Make_Block_Statement (Loc,
7974 Handled_Statement_Sequence =>
7975 Make_Handled_Sequence_Of_Statements (Loc,
7976 Statements => New_List (Relocate_Node (Call)))))));
7984 -- pragma Debug_Policy (Check | Ignore)
7986 when Pragma_Debug_Policy =>
7988 Check_Arg_Count (1);
7989 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7990 Debug_Pragmas_Enabled :=
7991 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7992 Debug_Pragmas_Disabled :=
7993 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
7995 ---------------------
7996 -- Detect_Blocking --
7997 ---------------------
7999 -- pragma Detect_Blocking;
8001 when Pragma_Detect_Blocking =>
8003 Check_Arg_Count (0);
8004 Check_Valid_Configuration_Pragma;
8005 Detect_Blocking := True;
8007 --------------------------
8008 -- Default_Storage_Pool --
8009 --------------------------
8011 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
8013 when Pragma_Default_Storage_Pool =>
8015 Check_Arg_Count (1);
8017 -- Default_Storage_Pool can appear as a configuration pragma, or
8018 -- in a declarative part or a package spec.
8020 if not Is_Configuration_Pragma then
8021 Check_Is_In_Decl_Part_Or_Package_Spec;
8024 -- Case of Default_Storage_Pool (null);
8026 if Nkind (Expression (Arg1)) = N_Null then
8027 Analyze (Expression (Arg1));
8029 -- This is an odd case, this is not really an expression, so
8030 -- we don't have a type for it. So just set the type to Empty.
8032 Set_Etype (Expression (Arg1), Empty);
8034 -- Case of Default_Storage_Pool (storage_pool_NAME);
8037 -- If it's a configuration pragma, then the only allowed
8038 -- argument is "null".
8040 if Is_Configuration_Pragma then
8041 Error_Pragma_Arg ("NULL expected", Arg1);
8044 -- The expected type for a non-"null" argument is
8045 -- Root_Storage_Pool'Class.
8048 (Get_Pragma_Arg (Arg1),
8049 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8052 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
8053 -- for an access type will use this information to set the
8054 -- appropriate attributes of the access type.
8056 Default_Pool := Expression (Arg1);
8058 ------------------------------------
8059 -- Disable_Atomic_Synchronization --
8060 ------------------------------------
8062 -- pragma Disable_Atomic_Synchronization [(Entity)];
8064 when Pragma_Disable_Atomic_Synchronization =>
8065 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8071 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
8073 when Pragma_Discard_Names => Discard_Names : declare
8078 Check_Ada_83_Warning;
8080 -- Deal with configuration pragma case
8082 if Arg_Count = 0 and then Is_Configuration_Pragma then
8083 Global_Discard_Names := True;
8086 -- Otherwise, check correct appropriate context
8089 Check_Is_In_Decl_Part_Or_Package_Spec;
8091 if Arg_Count = 0 then
8093 -- If there is no parameter, then from now on this pragma
8094 -- applies to any enumeration, exception or tagged type
8095 -- defined in the current declarative part, and recursively
8096 -- to any nested scope.
8098 Set_Discard_Names (Current_Scope);
8102 Check_Arg_Count (1);
8103 Check_Optional_Identifier (Arg1, Name_On);
8104 Check_Arg_Is_Local_Name (Arg1);
8106 E_Id := Get_Pragma_Arg (Arg1);
8108 if Etype (E_Id) = Any_Type then
8114 if (Is_First_Subtype (E)
8116 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8117 or else Ekind (E) = E_Exception
8119 Set_Discard_Names (E);
8122 ("inappropriate entity for pragma%", Arg1);
8129 ------------------------
8130 -- Dispatching_Domain --
8131 ------------------------
8133 -- pragma Dispatching_Domain (EXPRESSION);
8135 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8136 P : constant Node_Id := Parent (N);
8141 Check_No_Identifiers;
8142 Check_Arg_Count (1);
8144 -- This pragma is born obsolete, but not the aspect
8146 if not From_Aspect_Specification (N) then
8148 (No_Obsolescent_Features, Pragma_Identifier (N));
8151 if Nkind (P) = N_Task_Definition then
8152 Arg := Get_Pragma_Arg (Arg1);
8154 -- The expression must be analyzed in the special manner
8155 -- described in "Handling of Default and Per-Object
8156 -- Expressions" in sem.ads.
8158 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8160 -- Anything else is incorrect
8166 if Has_Pragma_Dispatching_Domain (P) then
8167 Error_Pragma ("duplicate pragma% not allowed");
8169 Set_Has_Pragma_Dispatching_Domain (P, True);
8171 if Nkind (P) = N_Task_Definition then
8172 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8175 end Dispatching_Domain;
8181 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8183 when Pragma_Elaborate => Elaborate : declare
8188 -- Pragma must be in context items list of a compilation unit
8190 if not Is_In_Context_Clause then
8194 -- Must be at least one argument
8196 if Arg_Count = 0 then
8197 Error_Pragma ("pragma% requires at least one argument");
8200 -- In Ada 83 mode, there can be no items following it in the
8201 -- context list except other pragmas and implicit with clauses
8202 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8203 -- placement rule does not apply.
8205 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8207 while Present (Citem) loop
8208 if Nkind (Citem) = N_Pragma
8209 or else (Nkind (Citem) = N_With_Clause
8210 and then Implicit_With (Citem))
8215 ("(Ada 83) pragma% must be at end of context clause");
8222 -- Finally, the arguments must all be units mentioned in a with
8223 -- clause in the same context clause. Note we already checked (in
8224 -- Par.Prag) that the arguments are all identifiers or selected
8228 Outer : while Present (Arg) loop
8229 Citem := First (List_Containing (N));
8230 Inner : while Citem /= N loop
8231 if Nkind (Citem) = N_With_Clause
8232 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8234 Set_Elaborate_Present (Citem, True);
8235 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8236 Generate_Reference (Entity (Name (Citem)), Citem);
8238 -- With the pragma present, elaboration calls on
8239 -- subprograms from the named unit need no further
8240 -- checks, as long as the pragma appears in the current
8241 -- compilation unit. If the pragma appears in some unit
8242 -- in the context, there might still be a need for an
8243 -- Elaborate_All_Desirable from the current compilation
8244 -- to the named unit, so we keep the check enabled.
8246 if In_Extended_Main_Source_Unit (N) then
8247 Set_Suppress_Elaboration_Warnings
8248 (Entity (Name (Citem)));
8259 ("argument of pragma% is not withed unit", Arg);
8265 -- Give a warning if operating in static mode with -gnatwl
8266 -- (elaboration warnings enabled) switch set.
8268 if Elab_Warnings and not Dynamic_Elaboration_Checks then
8270 ("?use of pragma Elaborate may not be safe", N);
8272 ("?use pragma Elaborate_All instead if possible", N);
8280 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8282 when Pragma_Elaborate_All => Elaborate_All : declare
8287 Check_Ada_83_Warning;
8289 -- Pragma must be in context items list of a compilation unit
8291 if not Is_In_Context_Clause then
8295 -- Must be at least one argument
8297 if Arg_Count = 0 then
8298 Error_Pragma ("pragma% requires at least one argument");
8301 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
8302 -- have to appear at the end of the context clause, but may
8303 -- appear mixed in with other items, even in Ada 83 mode.
8305 -- Final check: the arguments must all be units mentioned in
8306 -- a with clause in the same context clause. Note that we
8307 -- already checked (in Par.Prag) that all the arguments are
8308 -- either identifiers or selected components.
8311 Outr : while Present (Arg) loop
8312 Citem := First (List_Containing (N));
8313 Innr : while Citem /= N loop
8314 if Nkind (Citem) = N_With_Clause
8315 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8317 Set_Elaborate_All_Present (Citem, True);
8318 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8320 -- Suppress warnings and elaboration checks on the named
8321 -- unit if the pragma is in the current compilation, as
8322 -- for pragma Elaborate.
8324 if In_Extended_Main_Source_Unit (N) then
8325 Set_Suppress_Elaboration_Warnings
8326 (Entity (Name (Citem)));
8335 Set_Error_Posted (N);
8337 ("argument of pragma% is not withed unit", Arg);
8344 --------------------
8345 -- Elaborate_Body --
8346 --------------------
8348 -- pragma Elaborate_Body [( library_unit_NAME )];
8350 when Pragma_Elaborate_Body => Elaborate_Body : declare
8351 Cunit_Node : Node_Id;
8352 Cunit_Ent : Entity_Id;
8355 Check_Ada_83_Warning;
8356 Check_Valid_Library_Unit_Pragma;
8358 if Nkind (N) = N_Null_Statement then
8362 Cunit_Node := Cunit (Current_Sem_Unit);
8363 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8365 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8368 Error_Pragma ("pragma% must refer to a spec, not a body");
8370 Set_Body_Required (Cunit_Node, True);
8371 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8373 -- If we are in dynamic elaboration mode, then we suppress
8374 -- elaboration warnings for the unit, since it is definitely
8375 -- fine NOT to do dynamic checks at the first level (and such
8376 -- checks will be suppressed because no elaboration boolean
8377 -- is created for Elaborate_Body packages).
8379 -- But in the static model of elaboration, Elaborate_Body is
8380 -- definitely NOT good enough to ensure elaboration safety on
8381 -- its own, since the body may WITH other units that are not
8382 -- safe from an elaboration point of view, so a client must
8383 -- still do an Elaborate_All on such units.
8385 -- Debug flag -gnatdD restores the old behavior of 3.13, where
8386 -- Elaborate_Body always suppressed elab warnings.
8388 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8389 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8394 ------------------------
8395 -- Elaboration_Checks --
8396 ------------------------
8398 -- pragma Elaboration_Checks (Static | Dynamic);
8400 when Pragma_Elaboration_Checks =>
8402 Check_Arg_Count (1);
8403 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8404 Dynamic_Elaboration_Checks :=
8405 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8411 -- pragma Eliminate (
8412 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
8413 -- [,[Entity =>] IDENTIFIER |
8414 -- SELECTED_COMPONENT |
8416 -- [, OVERLOADING_RESOLUTION]);
8418 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8421 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8424 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8426 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8427 -- Result_Type => result_SUBTYPE_NAME]
8429 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8430 -- SUBTYPE_NAME ::= STRING_LITERAL
8432 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8433 -- SOURCE_TRACE ::= STRING_LITERAL
8435 when Pragma_Eliminate => Eliminate : declare
8436 Args : Args_List (1 .. 5);
8437 Names : constant Name_List (1 .. 5) := (
8440 Name_Parameter_Types,
8442 Name_Source_Location);
8444 Unit_Name : Node_Id renames Args (1);
8445 Entity : Node_Id renames Args (2);
8446 Parameter_Types : Node_Id renames Args (3);
8447 Result_Type : Node_Id renames Args (4);
8448 Source_Location : Node_Id renames Args (5);
8452 Check_Valid_Configuration_Pragma;
8453 Gather_Associations (Names, Args);
8455 if No (Unit_Name) then
8456 Error_Pragma ("missing Unit_Name argument for pragma%");
8460 and then (Present (Parameter_Types)
8462 Present (Result_Type)
8464 Present (Source_Location))
8466 Error_Pragma ("missing Entity argument for pragma%");
8469 if (Present (Parameter_Types)
8471 Present (Result_Type))
8473 Present (Source_Location)
8476 ("parameter profile and source location cannot " &
8477 "be used together in pragma%");
8480 Process_Eliminate_Pragma
8489 -----------------------------------
8490 -- Enable_Atomic_Synchronization --
8491 -----------------------------------
8493 -- pragma Enable_Atomic_Synchronization [(Entity)];
8495 when Pragma_Enable_Atomic_Synchronization =>
8496 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
8503 -- [ Convention =>] convention_IDENTIFIER,
8504 -- [ Entity =>] local_NAME
8505 -- [, [External_Name =>] static_string_EXPRESSION ]
8506 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8508 when Pragma_Export => Export : declare
8512 pragma Warnings (Off, C);
8515 Check_Ada_83_Warning;
8521 Check_At_Least_N_Arguments (2);
8522 Check_At_Most_N_Arguments (4);
8523 Process_Convention (C, Def_Id);
8525 if Ekind (Def_Id) /= E_Constant then
8526 Note_Possible_Modification
8527 (Get_Pragma_Arg (Arg2), Sure => False);
8530 Process_Interface_Name (Def_Id, Arg3, Arg4);
8531 Set_Exported (Def_Id, Arg2);
8533 -- If the entity is a deferred constant, propagate the information
8534 -- to the full view, because gigi elaborates the full view only.
8536 if Ekind (Def_Id) = E_Constant
8537 and then Present (Full_View (Def_Id))
8540 Id2 : constant Entity_Id := Full_View (Def_Id);
8542 Set_Is_Exported (Id2, Is_Exported (Def_Id));
8543 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
8544 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8549 ----------------------
8550 -- Export_Exception --
8551 ----------------------
8553 -- pragma Export_Exception (
8554 -- [Internal =>] LOCAL_NAME
8555 -- [, [External =>] EXTERNAL_SYMBOL]
8556 -- [, [Form =>] Ada | VMS]
8557 -- [, [Code =>] static_integer_EXPRESSION]);
8559 when Pragma_Export_Exception => Export_Exception : declare
8560 Args : Args_List (1 .. 4);
8561 Names : constant Name_List (1 .. 4) := (
8567 Internal : Node_Id renames Args (1);
8568 External : Node_Id renames Args (2);
8569 Form : Node_Id renames Args (3);
8570 Code : Node_Id renames Args (4);
8575 if Inside_A_Generic then
8576 Error_Pragma ("pragma% cannot be used for generic entities");
8579 Gather_Associations (Names, Args);
8580 Process_Extended_Import_Export_Exception_Pragma (
8581 Arg_Internal => Internal,
8582 Arg_External => External,
8586 if not Is_VMS_Exception (Entity (Internal)) then
8587 Set_Exported (Entity (Internal), Internal);
8589 end Export_Exception;
8591 ---------------------
8592 -- Export_Function --
8593 ---------------------
8595 -- pragma Export_Function (
8596 -- [Internal =>] LOCAL_NAME
8597 -- [, [External =>] EXTERNAL_SYMBOL]
8598 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8599 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8600 -- [, [Mechanism =>] MECHANISM]
8601 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8603 -- EXTERNAL_SYMBOL ::=
8605 -- | static_string_EXPRESSION
8607 -- PARAMETER_TYPES ::=
8609 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8611 -- TYPE_DESIGNATOR ::=
8613 -- | subtype_Name ' Access
8617 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8619 -- MECHANISM_ASSOCIATION ::=
8620 -- [formal_parameter_NAME =>] MECHANISM_NAME
8622 -- MECHANISM_NAME ::=
8625 -- | Descriptor [([Class =>] CLASS_NAME)]
8627 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8629 when Pragma_Export_Function => Export_Function : declare
8630 Args : Args_List (1 .. 6);
8631 Names : constant Name_List (1 .. 6) := (
8634 Name_Parameter_Types,
8637 Name_Result_Mechanism);
8639 Internal : Node_Id renames Args (1);
8640 External : Node_Id renames Args (2);
8641 Parameter_Types : Node_Id renames Args (3);
8642 Result_Type : Node_Id renames Args (4);
8643 Mechanism : Node_Id renames Args (5);
8644 Result_Mechanism : Node_Id renames Args (6);
8648 Gather_Associations (Names, Args);
8649 Process_Extended_Import_Export_Subprogram_Pragma (
8650 Arg_Internal => Internal,
8651 Arg_External => External,
8652 Arg_Parameter_Types => Parameter_Types,
8653 Arg_Result_Type => Result_Type,
8654 Arg_Mechanism => Mechanism,
8655 Arg_Result_Mechanism => Result_Mechanism);
8656 end Export_Function;
8662 -- pragma Export_Object (
8663 -- [Internal =>] LOCAL_NAME
8664 -- [, [External =>] EXTERNAL_SYMBOL]
8665 -- [, [Size =>] EXTERNAL_SYMBOL]);
8667 -- EXTERNAL_SYMBOL ::=
8669 -- | static_string_EXPRESSION
8671 -- PARAMETER_TYPES ::=
8673 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8675 -- TYPE_DESIGNATOR ::=
8677 -- | subtype_Name ' Access
8681 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8683 -- MECHANISM_ASSOCIATION ::=
8684 -- [formal_parameter_NAME =>] MECHANISM_NAME
8686 -- MECHANISM_NAME ::=
8689 -- | Descriptor [([Class =>] CLASS_NAME)]
8691 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8693 when Pragma_Export_Object => Export_Object : declare
8694 Args : Args_List (1 .. 3);
8695 Names : constant Name_List (1 .. 3) := (
8700 Internal : Node_Id renames Args (1);
8701 External : Node_Id renames Args (2);
8702 Size : Node_Id renames Args (3);
8706 Gather_Associations (Names, Args);
8707 Process_Extended_Import_Export_Object_Pragma (
8708 Arg_Internal => Internal,
8709 Arg_External => External,
8713 ----------------------
8714 -- Export_Procedure --
8715 ----------------------
8717 -- pragma Export_Procedure (
8718 -- [Internal =>] LOCAL_NAME
8719 -- [, [External =>] EXTERNAL_SYMBOL]
8720 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8721 -- [, [Mechanism =>] MECHANISM]);
8723 -- EXTERNAL_SYMBOL ::=
8725 -- | static_string_EXPRESSION
8727 -- PARAMETER_TYPES ::=
8729 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8731 -- TYPE_DESIGNATOR ::=
8733 -- | subtype_Name ' Access
8737 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8739 -- MECHANISM_ASSOCIATION ::=
8740 -- [formal_parameter_NAME =>] MECHANISM_NAME
8742 -- MECHANISM_NAME ::=
8745 -- | Descriptor [([Class =>] CLASS_NAME)]
8747 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8749 when Pragma_Export_Procedure => Export_Procedure : declare
8750 Args : Args_List (1 .. 4);
8751 Names : constant Name_List (1 .. 4) := (
8754 Name_Parameter_Types,
8757 Internal : Node_Id renames Args (1);
8758 External : Node_Id renames Args (2);
8759 Parameter_Types : Node_Id renames Args (3);
8760 Mechanism : Node_Id renames Args (4);
8764 Gather_Associations (Names, Args);
8765 Process_Extended_Import_Export_Subprogram_Pragma (
8766 Arg_Internal => Internal,
8767 Arg_External => External,
8768 Arg_Parameter_Types => Parameter_Types,
8769 Arg_Mechanism => Mechanism);
8770 end Export_Procedure;
8776 -- pragma Export_Value (
8777 -- [Value =>] static_integer_EXPRESSION,
8778 -- [Link_Name =>] static_string_EXPRESSION);
8780 when Pragma_Export_Value =>
8782 Check_Arg_Order ((Name_Value, Name_Link_Name));
8783 Check_Arg_Count (2);
8785 Check_Optional_Identifier (Arg1, Name_Value);
8786 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8788 Check_Optional_Identifier (Arg2, Name_Link_Name);
8789 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8791 -----------------------------
8792 -- Export_Valued_Procedure --
8793 -----------------------------
8795 -- pragma Export_Valued_Procedure (
8796 -- [Internal =>] LOCAL_NAME
8797 -- [, [External =>] EXTERNAL_SYMBOL,]
8798 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8799 -- [, [Mechanism =>] MECHANISM]);
8801 -- EXTERNAL_SYMBOL ::=
8803 -- | static_string_EXPRESSION
8805 -- PARAMETER_TYPES ::=
8807 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8809 -- TYPE_DESIGNATOR ::=
8811 -- | subtype_Name ' Access
8815 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8817 -- MECHANISM_ASSOCIATION ::=
8818 -- [formal_parameter_NAME =>] MECHANISM_NAME
8820 -- MECHANISM_NAME ::=
8823 -- | Descriptor [([Class =>] CLASS_NAME)]
8825 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8827 when Pragma_Export_Valued_Procedure =>
8828 Export_Valued_Procedure : declare
8829 Args : Args_List (1 .. 4);
8830 Names : constant Name_List (1 .. 4) := (
8833 Name_Parameter_Types,
8836 Internal : Node_Id renames Args (1);
8837 External : Node_Id renames Args (2);
8838 Parameter_Types : Node_Id renames Args (3);
8839 Mechanism : Node_Id renames Args (4);
8843 Gather_Associations (Names, Args);
8844 Process_Extended_Import_Export_Subprogram_Pragma (
8845 Arg_Internal => Internal,
8846 Arg_External => External,
8847 Arg_Parameter_Types => Parameter_Types,
8848 Arg_Mechanism => Mechanism);
8849 end Export_Valued_Procedure;
8855 -- pragma Extend_System ([Name =>] Identifier);
8857 when Pragma_Extend_System => Extend_System : declare
8860 Check_Valid_Configuration_Pragma;
8861 Check_Arg_Count (1);
8862 Check_Optional_Identifier (Arg1, Name_Name);
8863 Check_Arg_Is_Identifier (Arg1);
8865 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8868 and then Name_Buffer (1 .. 4) = "aux_"
8870 if Present (System_Extend_Pragma_Arg) then
8871 if Chars (Get_Pragma_Arg (Arg1)) =
8872 Chars (Expression (System_Extend_Pragma_Arg))
8876 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8877 Error_Pragma ("pragma% conflicts with that #");
8881 System_Extend_Pragma_Arg := Arg1;
8883 if not GNAT_Mode then
8884 System_Extend_Unit := Arg1;
8888 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8892 ------------------------
8893 -- Extensions_Allowed --
8894 ------------------------
8896 -- pragma Extensions_Allowed (ON | OFF);
8898 when Pragma_Extensions_Allowed =>
8900 Check_Arg_Count (1);
8901 Check_No_Identifiers;
8902 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8904 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8905 Extensions_Allowed := True;
8906 Ada_Version := Ada_Version_Type'Last;
8909 Extensions_Allowed := False;
8910 Ada_Version := Ada_Version_Explicit;
8917 -- pragma External (
8918 -- [ Convention =>] convention_IDENTIFIER,
8919 -- [ Entity =>] local_NAME
8920 -- [, [External_Name =>] static_string_EXPRESSION ]
8921 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8923 when Pragma_External => External : declare
8927 pragma Warnings (Off, C);
8936 Check_At_Least_N_Arguments (2);
8937 Check_At_Most_N_Arguments (4);
8938 Process_Convention (C, Def_Id);
8939 Note_Possible_Modification
8940 (Get_Pragma_Arg (Arg2), Sure => False);
8941 Process_Interface_Name (Def_Id, Arg3, Arg4);
8942 Set_Exported (Def_Id, Arg2);
8945 --------------------------
8946 -- External_Name_Casing --
8947 --------------------------
8949 -- pragma External_Name_Casing (
8950 -- UPPERCASE | LOWERCASE
8951 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8953 when Pragma_External_Name_Casing => External_Name_Casing : declare
8956 Check_No_Identifiers;
8958 if Arg_Count = 2 then
8960 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8962 case Chars (Get_Pragma_Arg (Arg2)) is
8964 Opt.External_Name_Exp_Casing := As_Is;
8966 when Name_Uppercase =>
8967 Opt.External_Name_Exp_Casing := Uppercase;
8969 when Name_Lowercase =>
8970 Opt.External_Name_Exp_Casing := Lowercase;
8977 Check_Arg_Count (1);
8980 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8982 case Chars (Get_Pragma_Arg (Arg1)) is
8983 when Name_Uppercase =>
8984 Opt.External_Name_Imp_Casing := Uppercase;
8986 when Name_Lowercase =>
8987 Opt.External_Name_Imp_Casing := Lowercase;
8992 end External_Name_Casing;
8994 --------------------------
8995 -- Favor_Top_Level --
8996 --------------------------
8998 -- pragma Favor_Top_Level (type_NAME);
9000 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
9001 Named_Entity : Entity_Id;
9005 Check_No_Identifiers;
9006 Check_Arg_Count (1);
9007 Check_Arg_Is_Local_Name (Arg1);
9008 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
9010 -- If it's an access-to-subprogram type (in particular, not a
9011 -- subtype), set the flag on that type.
9013 if Is_Access_Subprogram_Type (Named_Entity) then
9014 Set_Can_Use_Internal_Rep (Named_Entity, False);
9016 -- Otherwise it's an error (name denotes the wrong sort of entity)
9020 ("access-to-subprogram type expected",
9021 Get_Pragma_Arg (Arg1));
9023 end Favor_Top_Level;
9029 -- pragma Fast_Math;
9031 when Pragma_Fast_Math =>
9033 Check_No_Identifiers;
9034 Check_Valid_Configuration_Pragma;
9037 ---------------------------
9038 -- Finalize_Storage_Only --
9039 ---------------------------
9041 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9043 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9044 Assoc : constant Node_Id := Arg1;
9045 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9050 Check_No_Identifiers;
9051 Check_Arg_Count (1);
9052 Check_Arg_Is_Local_Name (Arg1);
9054 Find_Type (Type_Id);
9055 Typ := Entity (Type_Id);
9058 or else Rep_Item_Too_Early (Typ, N)
9062 Typ := Underlying_Type (Typ);
9065 if not Is_Controlled (Typ) then
9066 Error_Pragma ("pragma% must specify controlled type");
9069 Check_First_Subtype (Arg1);
9071 if Finalize_Storage_Only (Typ) then
9072 Error_Pragma ("duplicate pragma%, only one allowed");
9074 elsif not Rep_Item_Too_Late (Typ, N) then
9075 Set_Finalize_Storage_Only (Base_Type (Typ), True);
9077 end Finalize_Storage;
9079 --------------------------
9080 -- Float_Representation --
9081 --------------------------
9083 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9085 -- FLOAT_REP ::= VAX_Float | IEEE_Float
9087 when Pragma_Float_Representation => Float_Representation : declare
9095 if Arg_Count = 1 then
9096 Check_Valid_Configuration_Pragma;
9098 Check_Arg_Count (2);
9099 Check_Optional_Identifier (Arg2, Name_Entity);
9100 Check_Arg_Is_Local_Name (Arg2);
9103 Check_No_Identifier (Arg1);
9104 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9106 if not OpenVMS_On_Target then
9107 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9109 ("?pragma% ignored (applies only to Open'V'M'S)");
9115 -- One argument case
9117 if Arg_Count = 1 then
9118 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9119 if Opt.Float_Format = 'I' then
9120 Error_Pragma ("'I'E'E'E format previously specified");
9123 Opt.Float_Format := 'V';
9126 if Opt.Float_Format = 'V' then
9127 Error_Pragma ("'V'A'X format previously specified");
9130 Opt.Float_Format := 'I';
9133 Set_Standard_Fpt_Formats;
9135 -- Two argument case
9138 Argx := Get_Pragma_Arg (Arg2);
9140 if not Is_Entity_Name (Argx)
9141 or else not Is_Floating_Point_Type (Entity (Argx))
9144 ("second argument of% pragma must be floating-point type",
9148 Ent := Entity (Argx);
9149 Digs := UI_To_Int (Digits_Value (Ent));
9151 -- Two arguments, VAX_Float case
9153 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9155 when 6 => Set_F_Float (Ent);
9156 when 9 => Set_D_Float (Ent);
9157 when 15 => Set_G_Float (Ent);
9161 ("wrong digits value, must be 6,9 or 15", Arg2);
9164 -- Two arguments, IEEE_Float case
9168 when 6 => Set_IEEE_Short (Ent);
9169 when 15 => Set_IEEE_Long (Ent);
9173 ("wrong digits value, must be 6 or 15", Arg2);
9177 end Float_Representation;
9183 -- pragma Ident (static_string_EXPRESSION)
9185 -- Note: pragma Comment shares this processing. Pragma Comment is
9186 -- identical to Ident, except that the restriction of the argument to
9187 -- 31 characters and the placement restrictions are not enforced for
9190 when Pragma_Ident | Pragma_Comment => Ident : declare
9195 Check_Arg_Count (1);
9196 Check_No_Identifiers;
9197 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9200 -- For pragma Ident, preserve DEC compatibility by requiring the
9201 -- pragma to appear in a declarative part or package spec.
9203 if Prag_Id = Pragma_Ident then
9204 Check_Is_In_Decl_Part_Or_Package_Spec;
9207 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9214 GP := Parent (Parent (N));
9216 if Nkind_In (GP, N_Package_Declaration,
9217 N_Generic_Package_Declaration)
9222 -- If we have a compilation unit, then record the ident value,
9223 -- checking for improper duplication.
9225 if Nkind (GP) = N_Compilation_Unit then
9226 CS := Ident_String (Current_Sem_Unit);
9228 if Present (CS) then
9230 -- For Ident, we do not permit multiple instances
9232 if Prag_Id = Pragma_Ident then
9233 Error_Pragma ("duplicate% pragma not permitted");
9235 -- For Comment, we concatenate the string, unless we want
9236 -- to preserve the tree structure for ASIS.
9238 elsif not ASIS_Mode then
9239 Start_String (Strval (CS));
9240 Store_String_Char (' ');
9241 Store_String_Chars (Strval (Str));
9242 Set_Strval (CS, End_String);
9246 -- In VMS, the effect of IDENT is achieved by passing
9247 -- --identification=name as a --for-linker switch.
9249 if OpenVMS_On_Target then
9252 ("--for-linker=--identification=");
9253 String_To_Name_Buffer (Strval (Str));
9254 Store_String_Chars (Name_Buffer (1 .. Name_Len));
9256 -- Only the last processed IDENT is saved. The main
9257 -- purpose is so an IDENT associated with a main
9258 -- procedure will be used in preference to an IDENT
9259 -- associated with a with'd package.
9261 Replace_Linker_Option_String
9262 (End_String, "--for-linker=--identification=");
9265 Set_Ident_String (Current_Sem_Unit, Str);
9268 -- For subunits, we just ignore the Ident, since in GNAT these
9269 -- are not separate object files, and hence not separate units
9270 -- in the unit table.
9272 elsif Nkind (GP) = N_Subunit then
9275 -- Otherwise we have a misplaced pragma Ident, but we ignore
9276 -- this if we are in an instantiation, since it comes from
9277 -- a generic, and has no relevance to the instantiation.
9279 elsif Prag_Id = Pragma_Ident then
9280 if Instantiation_Location (Loc) = No_Location then
9281 Error_Pragma ("pragma% only allowed at outer level");
9287 ----------------------------
9288 -- Implementation_Defined --
9289 ----------------------------
9291 -- pragma Implementation_Defined (local_NAME);
9293 -- Marks previously declared entity as implementation defined. For
9294 -- an overloaded entity, applies to the most recent homonym.
9296 -- pragma Implementation_Defined;
9298 -- The form with no arguments appears anywhere within a scope, most
9299 -- typically a package spec, and indicates that all entities that are
9300 -- defined within the package spec are Implementation_Defined.
9302 when Pragma_Implementation_Defined => Implementation_Defined : declare
9306 Check_No_Identifiers;
9308 -- Form with no arguments
9310 if Arg_Count = 0 then
9311 Set_Is_Implementation_Defined (Current_Scope);
9313 -- Form with one argument
9316 Check_Arg_Count (1);
9317 Check_Arg_Is_Local_Name (Arg1);
9318 Ent := Entity (Get_Pragma_Arg (Arg1));
9319 Set_Is_Implementation_Defined (Ent);
9321 end Implementation_Defined;
9327 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9328 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
9330 when Pragma_Implemented => Implemented : declare
9331 Proc_Id : Entity_Id;
9336 Check_Arg_Count (2);
9337 Check_No_Identifiers;
9338 Check_Arg_Is_Identifier (Arg1);
9339 Check_Arg_Is_Local_Name (Arg1);
9341 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
9343 -- Extract the name of the local procedure
9345 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9347 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9348 -- primitive procedure of a synchronized tagged type.
9350 if Ekind (Proc_Id) = E_Procedure
9351 and then Is_Primitive (Proc_Id)
9352 and then Present (First_Formal (Proc_Id))
9354 Typ := Etype (First_Formal (Proc_Id));
9356 if Is_Tagged_Type (Typ)
9359 -- Check for a protected, a synchronized or a task interface
9361 ((Is_Interface (Typ)
9362 and then Is_Synchronized_Interface (Typ))
9364 -- Check for a protected type or a task type that implements
9368 (Is_Concurrent_Record_Type (Typ)
9369 and then Present (Interfaces (Typ)))
9371 -- Check for a private record extension with keyword
9375 (Ekind_In (Typ, E_Record_Type_With_Private,
9376 E_Record_Subtype_With_Private)
9377 and then Synchronized_Present (Parent (Typ))))
9382 ("controlling formal must be of synchronized " &
9383 "tagged type", Arg1);
9387 -- Procedures declared inside a protected type must be accepted
9389 elsif Ekind (Proc_Id) = E_Procedure
9390 and then Is_Protected_Type (Scope (Proc_Id))
9394 -- The first argument is not a primitive procedure
9398 ("pragma % must be applied to a primitive procedure", Arg1);
9402 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9403 -- By_Protected_Procedure to the primitive procedure of a task
9406 if Chars (Arg2) = Name_By_Protected_Procedure
9407 and then Is_Interface (Typ)
9408 and then Is_Task_Interface (Typ)
9411 ("implementation kind By_Protected_Procedure cannot be " &
9412 "applied to a task interface primitive", Arg2);
9416 Record_Rep_Item (Proc_Id, N);
9419 ----------------------
9420 -- Implicit_Packing --
9421 ----------------------
9423 -- pragma Implicit_Packing;
9425 when Pragma_Implicit_Packing =>
9427 Check_Arg_Count (0);
9428 Implicit_Packing := True;
9435 -- [Convention =>] convention_IDENTIFIER,
9436 -- [Entity =>] local_NAME
9437 -- [, [External_Name =>] static_string_EXPRESSION ]
9438 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9440 when Pragma_Import =>
9441 Check_Ada_83_Warning;
9447 Check_At_Least_N_Arguments (2);
9448 Check_At_Most_N_Arguments (4);
9449 Process_Import_Or_Interface;
9451 ----------------------
9452 -- Import_Exception --
9453 ----------------------
9455 -- pragma Import_Exception (
9456 -- [Internal =>] LOCAL_NAME
9457 -- [, [External =>] EXTERNAL_SYMBOL]
9458 -- [, [Form =>] Ada | VMS]
9459 -- [, [Code =>] static_integer_EXPRESSION]);
9461 when Pragma_Import_Exception => Import_Exception : declare
9462 Args : Args_List (1 .. 4);
9463 Names : constant Name_List (1 .. 4) := (
9469 Internal : Node_Id renames Args (1);
9470 External : Node_Id renames Args (2);
9471 Form : Node_Id renames Args (3);
9472 Code : Node_Id renames Args (4);
9476 Gather_Associations (Names, Args);
9478 if Present (External) and then Present (Code) then
9480 ("cannot give both External and Code options for pragma%");
9483 Process_Extended_Import_Export_Exception_Pragma (
9484 Arg_Internal => Internal,
9485 Arg_External => External,
9489 if not Is_VMS_Exception (Entity (Internal)) then
9490 Set_Imported (Entity (Internal));
9492 end Import_Exception;
9494 ---------------------
9495 -- Import_Function --
9496 ---------------------
9498 -- pragma Import_Function (
9499 -- [Internal =>] LOCAL_NAME,
9500 -- [, [External =>] EXTERNAL_SYMBOL]
9501 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9502 -- [, [Result_Type =>] SUBTYPE_MARK]
9503 -- [, [Mechanism =>] MECHANISM]
9504 -- [, [Result_Mechanism =>] MECHANISM_NAME]
9505 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9507 -- EXTERNAL_SYMBOL ::=
9509 -- | static_string_EXPRESSION
9511 -- PARAMETER_TYPES ::=
9513 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9515 -- TYPE_DESIGNATOR ::=
9517 -- | subtype_Name ' Access
9521 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9523 -- MECHANISM_ASSOCIATION ::=
9524 -- [formal_parameter_NAME =>] MECHANISM_NAME
9526 -- MECHANISM_NAME ::=
9529 -- | Descriptor [([Class =>] CLASS_NAME)]
9531 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9533 when Pragma_Import_Function => Import_Function : declare
9534 Args : Args_List (1 .. 7);
9535 Names : constant Name_List (1 .. 7) := (
9538 Name_Parameter_Types,
9541 Name_Result_Mechanism,
9542 Name_First_Optional_Parameter);
9544 Internal : Node_Id renames Args (1);
9545 External : Node_Id renames Args (2);
9546 Parameter_Types : Node_Id renames Args (3);
9547 Result_Type : Node_Id renames Args (4);
9548 Mechanism : Node_Id renames Args (5);
9549 Result_Mechanism : Node_Id renames Args (6);
9550 First_Optional_Parameter : Node_Id renames Args (7);
9554 Gather_Associations (Names, Args);
9555 Process_Extended_Import_Export_Subprogram_Pragma (
9556 Arg_Internal => Internal,
9557 Arg_External => External,
9558 Arg_Parameter_Types => Parameter_Types,
9559 Arg_Result_Type => Result_Type,
9560 Arg_Mechanism => Mechanism,
9561 Arg_Result_Mechanism => Result_Mechanism,
9562 Arg_First_Optional_Parameter => First_Optional_Parameter);
9563 end Import_Function;
9569 -- pragma Import_Object (
9570 -- [Internal =>] LOCAL_NAME
9571 -- [, [External =>] EXTERNAL_SYMBOL]
9572 -- [, [Size =>] EXTERNAL_SYMBOL]);
9574 -- EXTERNAL_SYMBOL ::=
9576 -- | static_string_EXPRESSION
9578 when Pragma_Import_Object => Import_Object : declare
9579 Args : Args_List (1 .. 3);
9580 Names : constant Name_List (1 .. 3) := (
9585 Internal : Node_Id renames Args (1);
9586 External : Node_Id renames Args (2);
9587 Size : Node_Id renames Args (3);
9591 Gather_Associations (Names, Args);
9592 Process_Extended_Import_Export_Object_Pragma (
9593 Arg_Internal => Internal,
9594 Arg_External => External,
9598 ----------------------
9599 -- Import_Procedure --
9600 ----------------------
9602 -- pragma Import_Procedure (
9603 -- [Internal =>] LOCAL_NAME
9604 -- [, [External =>] EXTERNAL_SYMBOL]
9605 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9606 -- [, [Mechanism =>] MECHANISM]
9607 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9609 -- EXTERNAL_SYMBOL ::=
9611 -- | static_string_EXPRESSION
9613 -- PARAMETER_TYPES ::=
9615 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9617 -- TYPE_DESIGNATOR ::=
9619 -- | subtype_Name ' Access
9623 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9625 -- MECHANISM_ASSOCIATION ::=
9626 -- [formal_parameter_NAME =>] MECHANISM_NAME
9628 -- MECHANISM_NAME ::=
9631 -- | Descriptor [([Class =>] CLASS_NAME)]
9633 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9635 when Pragma_Import_Procedure => Import_Procedure : declare
9636 Args : Args_List (1 .. 5);
9637 Names : constant Name_List (1 .. 5) := (
9640 Name_Parameter_Types,
9642 Name_First_Optional_Parameter);
9644 Internal : Node_Id renames Args (1);
9645 External : Node_Id renames Args (2);
9646 Parameter_Types : Node_Id renames Args (3);
9647 Mechanism : Node_Id renames Args (4);
9648 First_Optional_Parameter : Node_Id renames Args (5);
9652 Gather_Associations (Names, Args);
9653 Process_Extended_Import_Export_Subprogram_Pragma (
9654 Arg_Internal => Internal,
9655 Arg_External => External,
9656 Arg_Parameter_Types => Parameter_Types,
9657 Arg_Mechanism => Mechanism,
9658 Arg_First_Optional_Parameter => First_Optional_Parameter);
9659 end Import_Procedure;
9661 -----------------------------
9662 -- Import_Valued_Procedure --
9663 -----------------------------
9665 -- pragma Import_Valued_Procedure (
9666 -- [Internal =>] LOCAL_NAME
9667 -- [, [External =>] EXTERNAL_SYMBOL]
9668 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9669 -- [, [Mechanism =>] MECHANISM]
9670 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9672 -- EXTERNAL_SYMBOL ::=
9674 -- | static_string_EXPRESSION
9676 -- PARAMETER_TYPES ::=
9678 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9680 -- TYPE_DESIGNATOR ::=
9682 -- | subtype_Name ' Access
9686 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9688 -- MECHANISM_ASSOCIATION ::=
9689 -- [formal_parameter_NAME =>] MECHANISM_NAME
9691 -- MECHANISM_NAME ::=
9694 -- | Descriptor [([Class =>] CLASS_NAME)]
9696 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9698 when Pragma_Import_Valued_Procedure =>
9699 Import_Valued_Procedure : declare
9700 Args : Args_List (1 .. 5);
9701 Names : constant Name_List (1 .. 5) := (
9704 Name_Parameter_Types,
9706 Name_First_Optional_Parameter);
9708 Internal : Node_Id renames Args (1);
9709 External : Node_Id renames Args (2);
9710 Parameter_Types : Node_Id renames Args (3);
9711 Mechanism : Node_Id renames Args (4);
9712 First_Optional_Parameter : Node_Id renames Args (5);
9716 Gather_Associations (Names, Args);
9717 Process_Extended_Import_Export_Subprogram_Pragma (
9718 Arg_Internal => Internal,
9719 Arg_External => External,
9720 Arg_Parameter_Types => Parameter_Types,
9721 Arg_Mechanism => Mechanism,
9722 Arg_First_Optional_Parameter => First_Optional_Parameter);
9723 end Import_Valued_Procedure;
9729 -- pragma Independent (LOCAL_NAME);
9731 when Pragma_Independent => Independent : declare
9738 Check_Ada_83_Warning;
9740 Check_No_Identifiers;
9741 Check_Arg_Count (1);
9742 Check_Arg_Is_Local_Name (Arg1);
9743 E_Id := Get_Pragma_Arg (Arg1);
9745 if Etype (E_Id) = Any_Type then
9750 D := Declaration_Node (E);
9753 -- Check duplicate before we chain ourselves!
9755 Check_Duplicate_Pragma (E);
9757 -- Check appropriate entity
9760 if Rep_Item_Too_Early (E, N)
9762 Rep_Item_Too_Late (E, N)
9766 Check_First_Subtype (Arg1);
9769 elsif K = N_Object_Declaration
9770 or else (K = N_Component_Declaration
9771 and then Original_Record_Component (E) = E)
9773 if Rep_Item_Too_Late (E, N) then
9779 ("inappropriate entity for pragma%", Arg1);
9782 Independence_Checks.Append ((N, E));
9785 ----------------------------
9786 -- Independent_Components --
9787 ----------------------------
9789 -- pragma Atomic_Components (array_LOCAL_NAME);
9791 -- This processing is shared by Volatile_Components
9793 when Pragma_Independent_Components => Independent_Components : declare
9800 Check_Ada_83_Warning;
9802 Check_No_Identifiers;
9803 Check_Arg_Count (1);
9804 Check_Arg_Is_Local_Name (Arg1);
9805 E_Id := Get_Pragma_Arg (Arg1);
9807 if Etype (E_Id) = Any_Type then
9813 -- Check duplicate before we chain ourselves!
9815 Check_Duplicate_Pragma (E);
9817 -- Check appropriate entity
9819 if Rep_Item_Too_Early (E, N)
9821 Rep_Item_Too_Late (E, N)
9826 D := Declaration_Node (E);
9829 if (K = N_Full_Type_Declaration
9830 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9832 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9833 and then Nkind (D) = N_Object_Declaration
9834 and then Nkind (Object_Definition (D)) =
9835 N_Constrained_Array_Definition)
9837 Independence_Checks.Append ((N, E));
9840 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9842 end Independent_Components;
9844 ------------------------
9845 -- Initialize_Scalars --
9846 ------------------------
9848 -- pragma Initialize_Scalars;
9850 when Pragma_Initialize_Scalars =>
9852 Check_Arg_Count (0);
9853 Check_Valid_Configuration_Pragma;
9854 Check_Restriction (No_Initialize_Scalars, N);
9856 -- Initialize_Scalars creates false positives in CodePeer, and
9857 -- incorrect negative results in Alfa mode, so ignore this pragma
9860 if not Restriction_Active (No_Initialize_Scalars)
9861 and then not (CodePeer_Mode or Alfa_Mode)
9863 Init_Or_Norm_Scalars := True;
9864 Initialize_Scalars := True;
9871 -- pragma Inline ( NAME {, NAME} );
9873 when Pragma_Inline =>
9875 -- Pragma is active if inlining option is active
9877 Process_Inline (Inline_Active);
9883 -- pragma Inline_Always ( NAME {, NAME} );
9885 when Pragma_Inline_Always =>
9888 -- Pragma always active unless in CodePeer or Alfa mode, since
9889 -- this causes walk order issues.
9891 if not (CodePeer_Mode or Alfa_Mode) then
9892 Process_Inline (True);
9895 --------------------
9896 -- Inline_Generic --
9897 --------------------
9899 -- pragma Inline_Generic (NAME {, NAME});
9901 when Pragma_Inline_Generic =>
9903 Process_Generic_List;
9905 ----------------------
9906 -- Inspection_Point --
9907 ----------------------
9909 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9911 when Pragma_Inspection_Point => Inspection_Point : declare
9916 if Arg_Count > 0 then
9919 Exp := Get_Pragma_Arg (Arg);
9922 if not Is_Entity_Name (Exp)
9923 or else not Is_Object (Entity (Exp))
9925 Error_Pragma_Arg ("object name required", Arg);
9932 end Inspection_Point;
9938 -- pragma Interface (
9939 -- [ Convention =>] convention_IDENTIFIER,
9940 -- [ Entity =>] local_NAME
9941 -- [, [External_Name =>] static_string_EXPRESSION ]
9942 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9944 when Pragma_Interface =>
9951 Check_At_Least_N_Arguments (2);
9952 Check_At_Most_N_Arguments (4);
9953 Process_Import_Or_Interface;
9955 -- In Ada 2005, the permission to use Interface (a reserved word)
9956 -- as a pragma name is considered an obsolescent feature.
9958 if Ada_Version >= Ada_2005 then
9960 (No_Obsolescent_Features, Pragma_Identifier (N));
9963 --------------------
9964 -- Interface_Name --
9965 --------------------
9967 -- pragma Interface_Name (
9968 -- [ Entity =>] local_NAME
9969 -- [,[External_Name =>] static_string_EXPRESSION ]
9970 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9972 when Pragma_Interface_Name => Interface_Name : declare
9981 ((Name_Entity, Name_External_Name, Name_Link_Name));
9982 Check_At_Least_N_Arguments (2);
9983 Check_At_Most_N_Arguments (3);
9984 Id := Get_Pragma_Arg (Arg1);
9987 if not Is_Entity_Name (Id) then
9989 ("first argument for pragma% must be entity name", Arg1);
9990 elsif Etype (Id) = Any_Type then
9993 Def_Id := Entity (Id);
9996 -- Special DEC-compatible processing for the object case, forces
9997 -- object to be imported.
9999 if Ekind (Def_Id) = E_Variable then
10000 Kill_Size_Check_Code (Def_Id);
10001 Note_Possible_Modification (Id, Sure => False);
10003 -- Initialization is not allowed for imported variable
10005 if Present (Expression (Parent (Def_Id)))
10006 and then Comes_From_Source (Expression (Parent (Def_Id)))
10008 Error_Msg_Sloc := Sloc (Def_Id);
10010 ("no initialization allowed for declaration of& #",
10014 -- For compatibility, support VADS usage of providing both
10015 -- pragmas Interface and Interface_Name to obtain the effect
10016 -- of a single Import pragma.
10018 if Is_Imported (Def_Id)
10019 and then Present (First_Rep_Item (Def_Id))
10020 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
10022 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
10026 Set_Imported (Def_Id);
10029 Set_Is_Public (Def_Id);
10030 Process_Interface_Name (Def_Id, Arg2, Arg3);
10033 -- Otherwise must be subprogram
10035 elsif not Is_Subprogram (Def_Id) then
10037 ("argument of pragma% is not subprogram", Arg1);
10040 Check_At_Most_N_Arguments (3);
10044 -- Loop through homonyms
10047 Def_Id := Get_Base_Subprogram (Hom_Id);
10049 if Is_Imported (Def_Id) then
10050 Process_Interface_Name (Def_Id, Arg2, Arg3);
10054 exit when From_Aspect_Specification (N);
10055 Hom_Id := Homonym (Hom_Id);
10057 exit when No (Hom_Id)
10058 or else Scope (Hom_Id) /= Current_Scope;
10063 ("argument of pragma% is not imported subprogram",
10067 end Interface_Name;
10069 -----------------------
10070 -- Interrupt_Handler --
10071 -----------------------
10073 -- pragma Interrupt_Handler (handler_NAME);
10075 when Pragma_Interrupt_Handler =>
10076 Check_Ada_83_Warning;
10077 Check_Arg_Count (1);
10078 Check_No_Identifiers;
10080 if No_Run_Time_Mode then
10081 Error_Msg_CRT ("Interrupt_Handler pragma", N);
10083 Check_Interrupt_Or_Attach_Handler;
10084 Process_Interrupt_Or_Attach_Handler;
10087 ------------------------
10088 -- Interrupt_Priority --
10089 ------------------------
10091 -- pragma Interrupt_Priority [(EXPRESSION)];
10093 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
10094 P : constant Node_Id := Parent (N);
10098 Check_Ada_83_Warning;
10100 if Arg_Count /= 0 then
10101 Arg := Get_Pragma_Arg (Arg1);
10102 Check_Arg_Count (1);
10103 Check_No_Identifiers;
10105 -- The expression must be analyzed in the special manner
10106 -- described in "Handling of Default and Per-Object
10107 -- Expressions" in sem.ads.
10109 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
10112 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
10116 elsif Has_Pragma_Priority (P) then
10117 Error_Pragma ("duplicate pragma% not allowed");
10120 Set_Has_Pragma_Priority (P, True);
10121 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10123 end Interrupt_Priority;
10125 ---------------------
10126 -- Interrupt_State --
10127 ---------------------
10129 -- pragma Interrupt_State (
10130 -- [Name =>] INTERRUPT_ID,
10131 -- [State =>] INTERRUPT_STATE);
10133 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
10134 -- INTERRUPT_STATE => System | Runtime | User
10136 -- Note: if the interrupt id is given as an identifier, then it must
10137 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
10138 -- given as a static integer expression which must be in the range of
10139 -- Ada.Interrupts.Interrupt_ID.
10141 when Pragma_Interrupt_State => Interrupt_State : declare
10143 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
10144 -- This is the entity Ada.Interrupts.Interrupt_ID;
10146 State_Type : Character;
10147 -- Set to 's'/'r'/'u' for System/Runtime/User
10150 -- Index to entry in Interrupt_States table
10153 -- Value of interrupt
10155 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
10156 -- The first argument to the pragma
10158 Int_Ent : Entity_Id;
10159 -- Interrupt entity in Ada.Interrupts.Names
10163 Check_Arg_Order ((Name_Name, Name_State));
10164 Check_Arg_Count (2);
10166 Check_Optional_Identifier (Arg1, Name_Name);
10167 Check_Optional_Identifier (Arg2, Name_State);
10168 Check_Arg_Is_Identifier (Arg2);
10170 -- First argument is identifier
10172 if Nkind (Arg1X) = N_Identifier then
10174 -- Search list of names in Ada.Interrupts.Names
10176 Int_Ent := First_Entity (RTE (RE_Names));
10178 if No (Int_Ent) then
10179 Error_Pragma_Arg ("invalid interrupt name", Arg1);
10181 elsif Chars (Int_Ent) = Chars (Arg1X) then
10182 Int_Val := Expr_Value (Constant_Value (Int_Ent));
10186 Next_Entity (Int_Ent);
10189 -- First argument is not an identifier, so it must be a static
10190 -- expression of type Ada.Interrupts.Interrupt_ID.
10193 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10194 Int_Val := Expr_Value (Arg1X);
10196 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
10198 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10201 ("value not in range of type " &
10202 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10208 case Chars (Get_Pragma_Arg (Arg2)) is
10209 when Name_Runtime => State_Type := 'r';
10210 when Name_System => State_Type := 's';
10211 when Name_User => State_Type := 'u';
10214 Error_Pragma_Arg ("invalid interrupt state", Arg2);
10217 -- Check if entry is already stored
10219 IST_Num := Interrupt_States.First;
10221 -- If entry not found, add it
10223 if IST_Num > Interrupt_States.Last then
10224 Interrupt_States.Append
10225 ((Interrupt_Number => UI_To_Int (Int_Val),
10226 Interrupt_State => State_Type,
10227 Pragma_Loc => Loc));
10230 -- Case of entry for the same entry
10232 elsif Int_Val = Interrupt_States.Table (IST_Num).
10235 -- If state matches, done, no need to make redundant entry
10238 State_Type = Interrupt_States.Table (IST_Num).
10241 -- Otherwise if state does not match, error
10244 Interrupt_States.Table (IST_Num).Pragma_Loc;
10246 ("state conflicts with that given #", Arg2);
10250 IST_Num := IST_Num + 1;
10252 end Interrupt_State;
10258 -- pragma Invariant
10259 -- ([Entity =>] type_LOCAL_NAME,
10260 -- [Check =>] EXPRESSION
10261 -- [,[Message =>] String_Expression]);
10263 when Pragma_Invariant => Invariant : declare
10268 pragma Unreferenced (Discard);
10272 Check_At_Least_N_Arguments (2);
10273 Check_At_Most_N_Arguments (3);
10274 Check_Optional_Identifier (Arg1, Name_Entity);
10275 Check_Optional_Identifier (Arg2, Name_Check);
10277 if Arg_Count = 3 then
10278 Check_Optional_Identifier (Arg3, Name_Message);
10279 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10282 Check_Arg_Is_Local_Name (Arg1);
10284 Type_Id := Get_Pragma_Arg (Arg1);
10285 Find_Type (Type_Id);
10286 Typ := Entity (Type_Id);
10288 if Typ = Any_Type then
10291 -- An invariant must apply to a private type, or appear in the
10292 -- private part of a package spec and apply to a completion.
10294 elsif Ekind_In (Typ, E_Private_Type,
10295 E_Record_Type_With_Private,
10296 E_Limited_Private_Type)
10300 elsif In_Private_Part (Current_Scope)
10301 and then Has_Private_Declaration (Typ)
10305 elsif In_Private_Part (Current_Scope) then
10307 ("pragma% only allowed for private type " &
10308 "declared in visible part", Arg1);
10312 ("pragma% only allowed for private type", Arg1);
10315 -- Note that the type has at least one invariant, and also that
10316 -- it has inheritable invariants if we have Invariant'Class.
10318 Set_Has_Invariants (Typ);
10320 if Class_Present (N) then
10321 Set_Has_Inheritable_Invariants (Typ);
10324 -- The remaining processing is simply to link the pragma on to
10325 -- the rep item chain, for processing when the type is frozen.
10326 -- This is accomplished by a call to Rep_Item_Too_Late.
10328 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10331 ----------------------
10332 -- Java_Constructor --
10333 ----------------------
10335 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10337 -- Also handles pragma CIL_Constructor
10339 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10340 Java_Constructor : declare
10341 Convention : Convention_Id;
10342 Def_Id : Entity_Id;
10343 Hom_Id : Entity_Id;
10345 This_Formal : Entity_Id;
10349 Check_Arg_Count (1);
10350 Check_Optional_Identifier (Arg1, Name_Entity);
10351 Check_Arg_Is_Local_Name (Arg1);
10353 Id := Get_Pragma_Arg (Arg1);
10354 Find_Program_Unit_Name (Id);
10356 -- If we did not find the name, we are done
10358 if Etype (Id) = Any_Type then
10362 -- Check wrong use of pragma in wrong VM target
10364 if VM_Target = No_VM then
10367 elsif VM_Target = CLI_Target
10368 and then Prag_Id = Pragma_Java_Constructor
10370 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10372 elsif VM_Target = JVM_Target
10373 and then Prag_Id = Pragma_CIL_Constructor
10375 Error_Pragma ("must use pragma 'Java_'Constructor");
10379 when Pragma_CIL_Constructor => Convention := Convention_CIL;
10380 when Pragma_Java_Constructor => Convention := Convention_Java;
10381 when others => null;
10384 Hom_Id := Entity (Id);
10386 -- Loop through homonyms
10389 Def_Id := Get_Base_Subprogram (Hom_Id);
10391 -- The constructor is required to be a function
10393 if Ekind (Def_Id) /= E_Function then
10394 if VM_Target = JVM_Target then
10396 ("pragma% requires function returning a " &
10397 "'Java access type", Def_Id);
10400 ("pragma% requires function returning a " &
10401 "'C'I'L access type", Def_Id);
10405 -- Check arguments: For tagged type the first formal must be
10406 -- named "this" and its type must be a named access type
10407 -- designating a class-wide tagged type that has convention
10408 -- CIL/Java. The first formal must also have a null default
10409 -- value. For example:
10411 -- type Typ is tagged ...
10412 -- type Ref is access all Typ;
10413 -- pragma Convention (CIL, Typ);
10415 -- function New_Typ (This : Ref) return Ref;
10416 -- function New_Typ (This : Ref; I : Integer) return Ref;
10417 -- pragma Cil_Constructor (New_Typ);
10419 -- Reason: The first formal must NOT be a primitive of the
10422 -- This rule also applies to constructors of delegates used
10423 -- to interface with standard target libraries. For example:
10425 -- type Delegate is access procedure ...
10426 -- pragma Import (CIL, Delegate, ...);
10428 -- function new_Delegate
10429 -- (This : Delegate := null; ... ) return Delegate;
10431 -- For value-types this rule does not apply.
10433 if not Is_Value_Type (Etype (Def_Id)) then
10434 if No (First_Formal (Def_Id)) then
10435 Error_Msg_Name_1 := Pname;
10436 Error_Msg_N ("% function must have parameters", Def_Id);
10440 -- In the JRE library we have several occurrences in which
10441 -- the "this" parameter is not the first formal.
10443 This_Formal := First_Formal (Def_Id);
10445 -- In the JRE library we have several occurrences in which
10446 -- the "this" parameter is not the first formal. Search for
10449 if VM_Target = JVM_Target then
10450 while Present (This_Formal)
10451 and then Get_Name_String (Chars (This_Formal)) /= "this"
10453 Next_Formal (This_Formal);
10456 if No (This_Formal) then
10457 This_Formal := First_Formal (Def_Id);
10461 -- Warning: The first parameter should be named "this".
10462 -- We temporarily allow it because we have the following
10463 -- case in the Java runtime (file s-osinte.ads) ???
10465 -- function new_Thread
10466 -- (Self_Id : System.Address) return Thread_Id;
10467 -- pragma Java_Constructor (new_Thread);
10469 if VM_Target = JVM_Target
10470 and then Get_Name_String (Chars (First_Formal (Def_Id)))
10472 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10476 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10477 Error_Msg_Name_1 := Pname;
10479 ("first formal of % function must be named `this`",
10480 Parent (This_Formal));
10482 elsif not Is_Access_Type (Etype (This_Formal)) then
10483 Error_Msg_Name_1 := Pname;
10485 ("first formal of % function must be an access type",
10486 Parameter_Type (Parent (This_Formal)));
10488 -- For delegates the type of the first formal must be a
10489 -- named access-to-subprogram type (see previous example)
10491 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10492 and then Ekind (Etype (This_Formal))
10493 /= E_Access_Subprogram_Type
10495 Error_Msg_Name_1 := Pname;
10497 ("first formal of % function must be a named access" &
10498 " to subprogram type",
10499 Parameter_Type (Parent (This_Formal)));
10501 -- Warning: We should reject anonymous access types because
10502 -- the constructor must not be handled as a primitive of the
10503 -- tagged type. We temporarily allow it because this profile
10504 -- is currently generated by cil2ada???
10506 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10507 and then not Ekind_In (Etype (This_Formal),
10509 E_General_Access_Type,
10510 E_Anonymous_Access_Type)
10512 Error_Msg_Name_1 := Pname;
10514 ("first formal of % function must be a named access" &
10516 Parameter_Type (Parent (This_Formal)));
10518 elsif Atree.Convention
10519 (Designated_Type (Etype (This_Formal))) /= Convention
10521 Error_Msg_Name_1 := Pname;
10523 if Convention = Convention_Java then
10525 ("pragma% requires convention 'Cil in designated" &
10527 Parameter_Type (Parent (This_Formal)));
10530 ("pragma% requires convention 'Java in designated" &
10532 Parameter_Type (Parent (This_Formal)));
10535 elsif No (Expression (Parent (This_Formal)))
10536 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10538 Error_Msg_Name_1 := Pname;
10540 ("pragma% requires first formal with default `null`",
10541 Parameter_Type (Parent (This_Formal)));
10545 -- Check result type: the constructor must be a function
10547 -- * a value type (only allowed in the CIL compiler)
10548 -- * an access-to-subprogram type with convention Java/CIL
10549 -- * an access-type designating a type that has convention
10552 if Is_Value_Type (Etype (Def_Id)) then
10555 -- Access-to-subprogram type with convention Java/CIL
10557 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10558 if Atree.Convention (Etype (Def_Id)) /= Convention then
10559 if Convention = Convention_Java then
10561 ("pragma% requires function returning a " &
10562 "'Java access type", Arg1);
10564 pragma Assert (Convention = Convention_CIL);
10566 ("pragma% requires function returning a " &
10567 "'C'I'L access type", Arg1);
10571 elsif Ekind (Etype (Def_Id)) in Access_Kind then
10572 if not Ekind_In (Etype (Def_Id), E_Access_Type,
10573 E_General_Access_Type)
10576 (Designated_Type (Etype (Def_Id))) /= Convention
10578 Error_Msg_Name_1 := Pname;
10580 if Convention = Convention_Java then
10582 ("pragma% requires function returning a named" &
10583 "'Java access type", Arg1);
10586 ("pragma% requires function returning a named" &
10587 "'C'I'L access type", Arg1);
10592 Set_Is_Constructor (Def_Id);
10593 Set_Convention (Def_Id, Convention);
10594 Set_Is_Imported (Def_Id);
10596 exit when From_Aspect_Specification (N);
10597 Hom_Id := Homonym (Hom_Id);
10599 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10601 end Java_Constructor;
10603 ----------------------
10604 -- Java_Interface --
10605 ----------------------
10607 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
10609 when Pragma_Java_Interface => Java_Interface : declare
10615 Check_Arg_Count (1);
10616 Check_Optional_Identifier (Arg1, Name_Entity);
10617 Check_Arg_Is_Local_Name (Arg1);
10619 Arg := Get_Pragma_Arg (Arg1);
10622 if Etype (Arg) = Any_Type then
10626 if not Is_Entity_Name (Arg)
10627 or else not Is_Type (Entity (Arg))
10629 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10632 Typ := Underlying_Type (Entity (Arg));
10634 -- For now simply check some of the semantic constraints on the
10635 -- type. This currently leaves out some restrictions on interface
10636 -- types, namely that the parent type must be java.lang.Object.Typ
10637 -- and that all primitives of the type should be declared
10640 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10641 Error_Pragma_Arg ("pragma% requires an abstract "
10642 & "tagged type", Arg1);
10644 elsif not Has_Discriminants (Typ)
10645 or else Ekind (Etype (First_Discriminant (Typ)))
10646 /= E_Anonymous_Access_Type
10648 not Is_Class_Wide_Type
10649 (Designated_Type (Etype (First_Discriminant (Typ))))
10652 ("type must have a class-wide access discriminant", Arg1);
10654 end Java_Interface;
10660 -- pragma Keep_Names ([On => ] local_NAME);
10662 when Pragma_Keep_Names => Keep_Names : declare
10667 Check_Arg_Count (1);
10668 Check_Optional_Identifier (Arg1, Name_On);
10669 Check_Arg_Is_Local_Name (Arg1);
10671 Arg := Get_Pragma_Arg (Arg1);
10674 if Etype (Arg) = Any_Type then
10678 if not Is_Entity_Name (Arg)
10679 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10682 ("pragma% requires a local enumeration type", Arg1);
10685 Set_Discard_Names (Entity (Arg), False);
10692 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10694 when Pragma_License =>
10696 Check_Arg_Count (1);
10697 Check_No_Identifiers;
10698 Check_Valid_Configuration_Pragma;
10699 Check_Arg_Is_Identifier (Arg1);
10702 Sind : constant Source_File_Index :=
10703 Source_Index (Current_Sem_Unit);
10706 case Chars (Get_Pragma_Arg (Arg1)) is
10708 Set_License (Sind, GPL);
10710 when Name_Modified_GPL =>
10711 Set_License (Sind, Modified_GPL);
10713 when Name_Restricted =>
10714 Set_License (Sind, Restricted);
10716 when Name_Unrestricted =>
10717 Set_License (Sind, Unrestricted);
10720 Error_Pragma_Arg ("invalid license name", Arg1);
10728 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10730 when Pragma_Link_With => Link_With : declare
10736 if Operating_Mode = Generate_Code
10737 and then In_Extended_Main_Source_Unit (N)
10739 Check_At_Least_N_Arguments (1);
10740 Check_No_Identifiers;
10741 Check_Is_In_Decl_Part_Or_Package_Spec;
10742 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10746 while Present (Arg) loop
10747 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10749 -- Store argument, converting sequences of spaces to a
10750 -- single null character (this is one of the differences
10751 -- in processing between Link_With and Linker_Options).
10753 Arg_Store : declare
10754 C : constant Char_Code := Get_Char_Code (' ');
10755 S : constant String_Id :=
10756 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10757 L : constant Nat := String_Length (S);
10760 procedure Skip_Spaces;
10761 -- Advance F past any spaces
10767 procedure Skip_Spaces is
10769 while F <= L and then Get_String_Char (S, F) = C loop
10774 -- Start of processing for Arg_Store
10777 Skip_Spaces; -- skip leading spaces
10779 -- Loop through characters, changing any embedded
10780 -- sequence of spaces to a single null character (this
10781 -- is how Link_With/Linker_Options differ)
10784 if Get_String_Char (S, F) = C then
10787 Store_String_Char (ASCII.NUL);
10790 Store_String_Char (Get_String_Char (S, F));
10798 if Present (Arg) then
10799 Store_String_Char (ASCII.NUL);
10803 Store_Linker_Option_String (End_String);
10811 -- pragma Linker_Alias (
10812 -- [Entity =>] LOCAL_NAME
10813 -- [Target =>] static_string_EXPRESSION);
10815 when Pragma_Linker_Alias =>
10817 Check_Arg_Order ((Name_Entity, Name_Target));
10818 Check_Arg_Count (2);
10819 Check_Optional_Identifier (Arg1, Name_Entity);
10820 Check_Optional_Identifier (Arg2, Name_Target);
10821 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10822 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10824 -- The only processing required is to link this item on to the
10825 -- list of rep items for the given entity. This is accomplished
10826 -- by the call to Rep_Item_Too_Late (when no error is detected
10827 -- and False is returned).
10829 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10832 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10835 ------------------------
10836 -- Linker_Constructor --
10837 ------------------------
10839 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10841 -- Code is shared with Linker_Destructor
10843 -----------------------
10844 -- Linker_Destructor --
10845 -----------------------
10847 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10849 when Pragma_Linker_Constructor |
10850 Pragma_Linker_Destructor =>
10851 Linker_Constructor : declare
10857 Check_Arg_Count (1);
10858 Check_No_Identifiers;
10859 Check_Arg_Is_Local_Name (Arg1);
10860 Arg1_X := Get_Pragma_Arg (Arg1);
10862 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10864 if not Is_Library_Level_Entity (Proc) then
10866 ("argument for pragma% must be library level entity", Arg1);
10869 -- The only processing required is to link this item on to the
10870 -- list of rep items for the given entity. This is accomplished
10871 -- by the call to Rep_Item_Too_Late (when no error is detected
10872 -- and False is returned).
10874 if Rep_Item_Too_Late (Proc, N) then
10877 Set_Has_Gigi_Rep_Item (Proc);
10879 end Linker_Constructor;
10881 --------------------
10882 -- Linker_Options --
10883 --------------------
10885 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10887 when Pragma_Linker_Options => Linker_Options : declare
10891 Check_Ada_83_Warning;
10892 Check_No_Identifiers;
10893 Check_Arg_Count (1);
10894 Check_Is_In_Decl_Part_Or_Package_Spec;
10895 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10896 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10899 while Present (Arg) loop
10900 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10901 Store_String_Char (ASCII.NUL);
10903 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10907 if Operating_Mode = Generate_Code
10908 and then In_Extended_Main_Source_Unit (N)
10910 Store_Linker_Option_String (End_String);
10912 end Linker_Options;
10914 --------------------
10915 -- Linker_Section --
10916 --------------------
10918 -- pragma Linker_Section (
10919 -- [Entity =>] LOCAL_NAME
10920 -- [Section =>] static_string_EXPRESSION);
10922 when Pragma_Linker_Section =>
10924 Check_Arg_Order ((Name_Entity, Name_Section));
10925 Check_Arg_Count (2);
10926 Check_Optional_Identifier (Arg1, Name_Entity);
10927 Check_Optional_Identifier (Arg2, Name_Section);
10928 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10929 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10931 -- This pragma applies only to objects
10933 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10934 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10937 -- The only processing required is to link this item on to the
10938 -- list of rep items for the given entity. This is accomplished
10939 -- by the call to Rep_Item_Too_Late (when no error is detected
10940 -- and False is returned).
10942 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10945 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10952 -- pragma List (On | Off)
10954 -- There is nothing to do here, since we did all the processing for
10955 -- this pragma in Par.Prag (so that it works properly even in syntax
10958 when Pragma_List =>
10961 --------------------
10962 -- Locking_Policy --
10963 --------------------
10965 -- pragma Locking_Policy (policy_IDENTIFIER);
10967 when Pragma_Locking_Policy => declare
10968 subtype LP_Range is Name_Id
10969 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
10973 Check_Ada_83_Warning;
10974 Check_Arg_Count (1);
10975 Check_No_Identifiers;
10976 Check_Arg_Is_Locking_Policy (Arg1);
10977 Check_Valid_Configuration_Pragma;
10978 LP_Val := Chars (Get_Pragma_Arg (Arg1));
10981 when Name_Ceiling_Locking => LP := 'C';
10982 when Name_Inheritance_Locking => LP := 'I';
10983 when Name_Concurrent_Readers_Locking => LP := 'R';
10986 if Locking_Policy /= ' '
10987 and then Locking_Policy /= LP
10989 Error_Msg_Sloc := Locking_Policy_Sloc;
10990 Error_Pragma ("locking policy incompatible with policy#");
10992 -- Set new policy, but always preserve System_Location since we
10993 -- like the error message with the run time name.
10996 Locking_Policy := LP;
10998 if Locking_Policy_Sloc /= System_Location then
10999 Locking_Policy_Sloc := Loc;
11008 -- pragma Long_Float (D_Float | G_Float);
11010 when Pragma_Long_Float => Long_Float : declare
11013 Check_Valid_Configuration_Pragma;
11014 Check_Arg_Count (1);
11015 Check_No_Identifier (Arg1);
11016 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
11018 if not OpenVMS_On_Target then
11019 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
11024 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
11025 if Opt.Float_Format_Long = 'G' then
11027 ("G_Float previously specified", Arg1);
11029 elsif Current_Sem_Unit /= Main_Unit
11030 and then Opt.Float_Format_Long /= 'D'
11033 ("main unit not compiled with pragma Long_Float (D_Float)",
11034 "\pragma% must be used consistently for whole partition",
11038 Opt.Float_Format_Long := 'D';
11041 -- G_Float case (this is the default, does not need overriding)
11044 if Opt.Float_Format_Long = 'D' then
11045 Error_Pragma ("D_Float previously specified");
11047 elsif Current_Sem_Unit /= Main_Unit
11048 and then Opt.Float_Format_Long /= 'G'
11051 ("main unit not compiled with pragma Long_Float (G_Float)",
11052 "\pragma% must be used consistently for whole partition",
11056 Opt.Float_Format_Long := 'G';
11060 Set_Standard_Fpt_Formats;
11063 -----------------------
11064 -- Machine_Attribute --
11065 -----------------------
11067 -- pragma Machine_Attribute (
11068 -- [Entity =>] LOCAL_NAME,
11069 -- [Attribute_Name =>] static_string_EXPRESSION
11070 -- [, [Info =>] static_EXPRESSION] );
11072 when Pragma_Machine_Attribute => Machine_Attribute : declare
11073 Def_Id : Entity_Id;
11077 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
11079 if Arg_Count = 3 then
11080 Check_Optional_Identifier (Arg3, Name_Info);
11081 Check_Arg_Is_Static_Expression (Arg3);
11083 Check_Arg_Count (2);
11086 Check_Optional_Identifier (Arg1, Name_Entity);
11087 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
11088 Check_Arg_Is_Local_Name (Arg1);
11089 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11090 Def_Id := Entity (Get_Pragma_Arg (Arg1));
11092 if Is_Access_Type (Def_Id) then
11093 Def_Id := Designated_Type (Def_Id);
11096 if Rep_Item_Too_Early (Def_Id, N) then
11100 Def_Id := Underlying_Type (Def_Id);
11102 -- The only processing required is to link this item on to the
11103 -- list of rep items for the given entity. This is accomplished
11104 -- by the call to Rep_Item_Too_Late (when no error is detected
11105 -- and False is returned).
11107 if Rep_Item_Too_Late (Def_Id, N) then
11110 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11112 end Machine_Attribute;
11119 -- (MAIN_OPTION [, MAIN_OPTION]);
11122 -- [STACK_SIZE =>] static_integer_EXPRESSION
11123 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
11124 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
11126 when Pragma_Main => Main : declare
11127 Args : Args_List (1 .. 3);
11128 Names : constant Name_List (1 .. 3) := (
11130 Name_Task_Stack_Size_Default,
11131 Name_Time_Slicing_Enabled);
11137 Gather_Associations (Names, Args);
11139 for J in 1 .. 2 loop
11140 if Present (Args (J)) then
11141 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11145 if Present (Args (3)) then
11146 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
11150 while Present (Nod) loop
11151 if Nkind (Nod) = N_Pragma
11152 and then Pragma_Name (Nod) = Name_Main
11154 Error_Msg_Name_1 := Pname;
11155 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11166 -- pragma Main_Storage
11167 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
11169 -- MAIN_STORAGE_OPTION ::=
11170 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
11171 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
11173 when Pragma_Main_Storage => Main_Storage : declare
11174 Args : Args_List (1 .. 2);
11175 Names : constant Name_List (1 .. 2) := (
11176 Name_Working_Storage,
11183 Gather_Associations (Names, Args);
11185 for J in 1 .. 2 loop
11186 if Present (Args (J)) then
11187 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11191 Check_In_Main_Program;
11194 while Present (Nod) loop
11195 if Nkind (Nod) = N_Pragma
11196 and then Pragma_Name (Nod) = Name_Main_Storage
11198 Error_Msg_Name_1 := Pname;
11199 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11210 -- pragma Memory_Size (NUMERIC_LITERAL)
11212 when Pragma_Memory_Size =>
11215 -- Memory size is simply ignored
11217 Check_No_Identifiers;
11218 Check_Arg_Count (1);
11219 Check_Arg_Is_Integer_Literal (Arg1);
11227 -- The only correct use of this pragma is on its own in a file, in
11228 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
11229 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
11230 -- check for a file containing nothing but a No_Body pragma). If we
11231 -- attempt to process it during normal semantics processing, it means
11232 -- it was misplaced.
11234 when Pragma_No_Body =>
11242 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
11244 when Pragma_No_Return => No_Return : declare
11252 Check_At_Least_N_Arguments (1);
11254 -- Loop through arguments of pragma
11257 while Present (Arg) loop
11258 Check_Arg_Is_Local_Name (Arg);
11259 Id := Get_Pragma_Arg (Arg);
11262 if not Is_Entity_Name (Id) then
11263 Error_Pragma_Arg ("entity name required", Arg);
11266 if Etype (Id) = Any_Type then
11270 -- Loop to find matching procedures
11275 and then Scope (E) = Current_Scope
11277 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11280 -- Set flag on any alias as well
11282 if Is_Overloadable (E) and then Present (Alias (E)) then
11283 Set_No_Return (Alias (E));
11289 exit when From_Aspect_Specification (N);
11294 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11305 -- pragma No_Run_Time;
11307 -- Note: this pragma is retained for backwards compatibility. See
11308 -- body of Rtsfind for full details on its handling.
11310 when Pragma_No_Run_Time =>
11312 Check_Valid_Configuration_Pragma;
11313 Check_Arg_Count (0);
11315 No_Run_Time_Mode := True;
11316 Configurable_Run_Time_Mode := True;
11318 -- Set Duration to 32 bits if word size is 32
11320 if Ttypes.System_Word_Size = 32 then
11321 Duration_32_Bits_On_Target := True;
11324 -- Set appropriate restrictions
11326 Set_Restriction (No_Finalization, N);
11327 Set_Restriction (No_Exception_Handlers, N);
11328 Set_Restriction (Max_Tasks, N, 0);
11329 Set_Restriction (No_Tasking, N);
11331 ------------------------
11332 -- No_Strict_Aliasing --
11333 ------------------------
11335 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11337 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11342 Check_At_Most_N_Arguments (1);
11344 if Arg_Count = 0 then
11345 Check_Valid_Configuration_Pragma;
11346 Opt.No_Strict_Aliasing := True;
11349 Check_Optional_Identifier (Arg2, Name_Entity);
11350 Check_Arg_Is_Local_Name (Arg1);
11351 E_Id := Entity (Get_Pragma_Arg (Arg1));
11353 if E_Id = Any_Type then
11355 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11356 Error_Pragma_Arg ("pragma% requires access type", Arg1);
11359 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11361 end No_Strict_Aliasing;
11363 -----------------------
11364 -- Normalize_Scalars --
11365 -----------------------
11367 -- pragma Normalize_Scalars;
11369 when Pragma_Normalize_Scalars =>
11370 Check_Ada_83_Warning;
11371 Check_Arg_Count (0);
11372 Check_Valid_Configuration_Pragma;
11374 -- Normalize_Scalars creates false positives in CodePeer, and
11375 -- incorrect negative results in Alfa mode, so ignore this pragma
11378 if not (CodePeer_Mode or Alfa_Mode) then
11379 Normalize_Scalars := True;
11380 Init_Or_Norm_Scalars := True;
11387 -- pragma Obsolescent;
11389 -- pragma Obsolescent (
11390 -- [Message =>] static_string_EXPRESSION
11391 -- [,[Version =>] Ada_05]]);
11393 -- pragma Obsolescent (
11394 -- [Entity =>] NAME
11395 -- [,[Message =>] static_string_EXPRESSION
11396 -- [,[Version =>] Ada_05]] );
11398 when Pragma_Obsolescent => Obsolescent : declare
11402 procedure Set_Obsolescent (E : Entity_Id);
11403 -- Given an entity Ent, mark it as obsolescent if appropriate
11405 ---------------------
11406 -- Set_Obsolescent --
11407 ---------------------
11409 procedure Set_Obsolescent (E : Entity_Id) is
11418 -- Entity name was given
11420 if Present (Ename) then
11422 -- If entity name matches, we are fine. Save entity in
11423 -- pragma argument, for ASIS use.
11425 if Chars (Ename) = Chars (Ent) then
11426 Set_Entity (Ename, Ent);
11427 Generate_Reference (Ent, Ename);
11429 -- If entity name does not match, only possibility is an
11430 -- enumeration literal from an enumeration type declaration.
11432 elsif Ekind (Ent) /= E_Enumeration_Type then
11434 ("pragma % entity name does not match declaration");
11437 Ent := First_Literal (E);
11441 ("pragma % entity name does not match any " &
11442 "enumeration literal");
11444 elsif Chars (Ent) = Chars (Ename) then
11445 Set_Entity (Ename, Ent);
11446 Generate_Reference (Ent, Ename);
11450 Ent := Next_Literal (Ent);
11456 -- Ent points to entity to be marked
11458 if Arg_Count >= 1 then
11460 -- Deal with static string argument
11462 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11463 S := Strval (Get_Pragma_Arg (Arg1));
11465 for J in 1 .. String_Length (S) loop
11466 if not In_Character_Range (Get_String_Char (S, J)) then
11468 ("pragma% argument does not allow wide characters",
11473 Obsolescent_Warnings.Append
11474 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11476 -- Check for Ada_05 parameter
11478 if Arg_Count /= 1 then
11479 Check_Arg_Count (2);
11482 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11485 Check_Arg_Is_Identifier (Argx);
11487 if Chars (Argx) /= Name_Ada_05 then
11488 Error_Msg_Name_2 := Name_Ada_05;
11490 ("only allowed argument for pragma% is %", Argx);
11493 if Ada_Version_Explicit < Ada_2005
11494 or else not Warn_On_Ada_2005_Compatibility
11502 -- Set flag if pragma active
11505 Set_Is_Obsolescent (Ent);
11509 end Set_Obsolescent;
11511 -- Start of processing for pragma Obsolescent
11516 Check_At_Most_N_Arguments (3);
11518 -- See if first argument specifies an entity name
11522 (Chars (Arg1) = Name_Entity
11524 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11526 N_Operator_Symbol))
11528 Ename := Get_Pragma_Arg (Arg1);
11530 -- Eliminate first argument, so we can share processing
11534 Arg_Count := Arg_Count - 1;
11536 -- No Entity name argument given
11542 if Arg_Count >= 1 then
11543 Check_Optional_Identifier (Arg1, Name_Message);
11545 if Arg_Count = 2 then
11546 Check_Optional_Identifier (Arg2, Name_Version);
11550 -- Get immediately preceding declaration
11553 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11557 -- Cases where we do not follow anything other than another pragma
11561 -- First case: library level compilation unit declaration with
11562 -- the pragma immediately following the declaration.
11564 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11566 (Defining_Entity (Unit (Parent (Parent (N)))));
11569 -- Case 2: library unit placement for package
11573 Ent : constant Entity_Id := Find_Lib_Unit_Name;
11575 if Is_Package_Or_Generic_Package (Ent) then
11576 Set_Obsolescent (Ent);
11582 -- Cases where we must follow a declaration
11585 if Nkind (Decl) not in N_Declaration
11586 and then Nkind (Decl) not in N_Later_Decl_Item
11587 and then Nkind (Decl) not in N_Generic_Declaration
11588 and then Nkind (Decl) not in N_Renaming_Declaration
11591 ("pragma% misplaced, "
11592 & "must immediately follow a declaration");
11595 Set_Obsolescent (Defining_Entity (Decl));
11605 -- pragma Optimize (Time | Space | Off);
11607 -- The actual check for optimize is done in Gigi. Note that this
11608 -- pragma does not actually change the optimization setting, it
11609 -- simply checks that it is consistent with the pragma.
11611 when Pragma_Optimize =>
11612 Check_No_Identifiers;
11613 Check_Arg_Count (1);
11614 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11616 ------------------------
11617 -- Optimize_Alignment --
11618 ------------------------
11620 -- pragma Optimize_Alignment (Time | Space | Off);
11622 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11624 Check_No_Identifiers;
11625 Check_Arg_Count (1);
11626 Check_Valid_Configuration_Pragma;
11629 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11633 Opt.Optimize_Alignment := 'T';
11635 Opt.Optimize_Alignment := 'S';
11637 Opt.Optimize_Alignment := 'O';
11639 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11643 -- Set indication that mode is set locally. If we are in fact in a
11644 -- configuration pragma file, this setting is harmless since the
11645 -- switch will get reset anyway at the start of each unit.
11647 Optimize_Alignment_Local := True;
11648 end Optimize_Alignment;
11654 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11656 when Pragma_Ordered => Ordered : declare
11657 Assoc : constant Node_Id := Arg1;
11663 Check_No_Identifiers;
11664 Check_Arg_Count (1);
11665 Check_Arg_Is_Local_Name (Arg1);
11667 Type_Id := Get_Pragma_Arg (Assoc);
11668 Find_Type (Type_Id);
11669 Typ := Entity (Type_Id);
11671 if Typ = Any_Type then
11674 Typ := Underlying_Type (Typ);
11677 if not Is_Enumeration_Type (Typ) then
11678 Error_Pragma ("pragma% must specify enumeration type");
11681 Check_First_Subtype (Arg1);
11682 Set_Has_Pragma_Ordered (Base_Type (Typ));
11689 -- pragma Pack (first_subtype_LOCAL_NAME);
11691 when Pragma_Pack => Pack : declare
11692 Assoc : constant Node_Id := Arg1;
11696 Ignore : Boolean := False;
11699 Check_No_Identifiers;
11700 Check_Arg_Count (1);
11701 Check_Arg_Is_Local_Name (Arg1);
11703 Type_Id := Get_Pragma_Arg (Assoc);
11704 Find_Type (Type_Id);
11705 Typ := Entity (Type_Id);
11708 or else Rep_Item_Too_Early (Typ, N)
11712 Typ := Underlying_Type (Typ);
11715 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11716 Error_Pragma ("pragma% must specify array or record type");
11719 Check_First_Subtype (Arg1);
11720 Check_Duplicate_Pragma (Typ);
11724 if Is_Array_Type (Typ) then
11725 Ctyp := Component_Type (Typ);
11727 -- Ignore pack that does nothing
11729 if Known_Static_Esize (Ctyp)
11730 and then Known_Static_RM_Size (Ctyp)
11731 and then Esize (Ctyp) = RM_Size (Ctyp)
11732 and then Addressable (Esize (Ctyp))
11737 -- Process OK pragma Pack. Note that if there is a separate
11738 -- component clause present, the Pack will be cancelled. This
11739 -- processing is in Freeze.
11741 if not Rep_Item_Too_Late (Typ, N) then
11743 -- In the context of static code analysis, we do not need
11744 -- complex front-end expansions related to pragma Pack,
11745 -- so disable handling of pragma Pack in these cases.
11747 if CodePeer_Mode or Alfa_Mode then
11750 -- Don't attempt any packing for VM targets. We possibly
11751 -- could deal with some cases of array bit-packing, but we
11752 -- don't bother, since this is not a typical kind of
11753 -- representation in the VM context anyway (and would not
11754 -- for example work nicely with the debugger).
11756 elsif VM_Target /= No_VM then
11757 if not GNAT_Mode then
11759 ("?pragma% ignored in this configuration");
11762 -- Normal case where we do the pack action
11766 Set_Is_Packed (Base_Type (Typ));
11767 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11770 Set_Has_Pragma_Pack (Base_Type (Typ));
11774 -- For record types, the pack is always effective
11776 else pragma Assert (Is_Record_Type (Typ));
11777 if not Rep_Item_Too_Late (Typ, N) then
11779 -- Ignore pack request with warning in VM mode (skip warning
11780 -- if we are compiling GNAT run time library).
11782 if VM_Target /= No_VM then
11783 if not GNAT_Mode then
11785 ("?pragma% ignored in this configuration");
11788 -- Normal case of pack request active
11791 Set_Is_Packed (Base_Type (Typ));
11792 Set_Has_Pragma_Pack (Base_Type (Typ));
11793 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11805 -- There is nothing to do here, since we did all the processing for
11806 -- this pragma in Par.Prag (so that it works properly even in syntax
11809 when Pragma_Page =>
11816 -- pragma Passive [(PASSIVE_FORM)];
11818 -- PASSIVE_FORM ::= Semaphore | No
11820 when Pragma_Passive =>
11823 if Nkind (Parent (N)) /= N_Task_Definition then
11824 Error_Pragma ("pragma% must be within task definition");
11827 if Arg_Count /= 0 then
11828 Check_Arg_Count (1);
11829 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11832 ----------------------------------
11833 -- Preelaborable_Initialization --
11834 ----------------------------------
11836 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11838 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11843 Check_Arg_Count (1);
11844 Check_No_Identifiers;
11845 Check_Arg_Is_Identifier (Arg1);
11846 Check_Arg_Is_Local_Name (Arg1);
11847 Check_First_Subtype (Arg1);
11848 Ent := Entity (Get_Pragma_Arg (Arg1));
11850 if not (Is_Private_Type (Ent)
11852 Is_Protected_Type (Ent)
11854 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11857 ("pragma % can only be applied to private, formal derived or "
11858 & "protected type",
11862 -- Give an error if the pragma is applied to a protected type that
11863 -- does not qualify (due to having entries, or due to components
11864 -- that do not qualify).
11866 if Is_Protected_Type (Ent)
11867 and then not Has_Preelaborable_Initialization (Ent)
11870 ("protected type & does not have preelaborable " &
11871 "initialization", Ent);
11873 -- Otherwise mark the type as definitely having preelaborable
11877 Set_Known_To_Have_Preelab_Init (Ent);
11880 if Has_Pragma_Preelab_Init (Ent)
11881 and then Warn_On_Redundant_Constructs
11883 Error_Pragma ("?duplicate pragma%!");
11885 Set_Has_Pragma_Preelab_Init (Ent);
11889 --------------------
11890 -- Persistent_BSS --
11891 --------------------
11893 -- pragma Persistent_BSS [(object_NAME)];
11895 when Pragma_Persistent_BSS => Persistent_BSS : declare
11902 Check_At_Most_N_Arguments (1);
11904 -- Case of application to specific object (one argument)
11906 if Arg_Count = 1 then
11907 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11909 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11911 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11914 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11917 Ent := Entity (Get_Pragma_Arg (Arg1));
11918 Decl := Parent (Ent);
11920 if Rep_Item_Too_Late (Ent, N) then
11924 if Present (Expression (Decl)) then
11926 ("object for pragma% cannot have initialization", Arg1);
11929 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11931 ("object type for pragma% is not potentially persistent",
11935 Check_Duplicate_Pragma (Ent);
11938 Make_Linker_Section_Pragma
11939 (Ent, Sloc (N), ".persistent.bss");
11940 Insert_After (N, Prag);
11943 -- Case of use as configuration pragma with no arguments
11946 Check_Valid_Configuration_Pragma;
11947 Persistent_BSS_Mode := True;
11949 end Persistent_BSS;
11955 -- pragma Polling (ON | OFF);
11957 when Pragma_Polling =>
11959 Check_Arg_Count (1);
11960 Check_No_Identifiers;
11961 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11962 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11964 -------------------
11965 -- Postcondition --
11966 -------------------
11968 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
11969 -- [,[Message =>] String_EXPRESSION]);
11971 when Pragma_Postcondition => Postcondition : declare
11973 pragma Warnings (Off, In_Body);
11977 Check_At_Least_N_Arguments (1);
11978 Check_At_Most_N_Arguments (2);
11979 Check_Optional_Identifier (Arg1, Name_Check);
11981 -- All we need to do here is call the common check procedure,
11982 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11984 Check_Precondition_Postcondition (In_Body);
11991 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
11992 -- [,[Message =>] String_EXPRESSION]);
11994 when Pragma_Precondition => Precondition : declare
11999 Check_At_Least_N_Arguments (1);
12000 Check_At_Most_N_Arguments (2);
12001 Check_Optional_Identifier (Arg1, Name_Check);
12002 Check_Precondition_Postcondition (In_Body);
12004 -- If in spec, nothing more to do. If in body, then we convert the
12005 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
12006 -- this whether or not precondition checks are enabled. That works
12007 -- fine since pragma Check will do this check, and will also
12008 -- analyze the condition itself in the proper context.
12013 Chars => Name_Check,
12014 Pragma_Argument_Associations => New_List (
12015 Make_Pragma_Argument_Association (Loc,
12016 Expression => Make_Identifier (Loc, Name_Precondition)),
12018 Make_Pragma_Argument_Association (Sloc (Arg1),
12019 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
12021 if Arg_Count = 2 then
12022 Append_To (Pragma_Argument_Associations (N),
12023 Make_Pragma_Argument_Association (Sloc (Arg2),
12024 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
12035 -- pragma Predicate
12036 -- ([Entity =>] type_LOCAL_NAME,
12037 -- [Check =>] EXPRESSION);
12039 when Pragma_Predicate => Predicate : declare
12044 pragma Unreferenced (Discard);
12048 Check_Arg_Count (2);
12049 Check_Optional_Identifier (Arg1, Name_Entity);
12050 Check_Optional_Identifier (Arg2, Name_Check);
12052 Check_Arg_Is_Local_Name (Arg1);
12054 Type_Id := Get_Pragma_Arg (Arg1);
12055 Find_Type (Type_Id);
12056 Typ := Entity (Type_Id);
12058 if Typ = Any_Type then
12062 -- The remaining processing is simply to link the pragma on to
12063 -- the rep item chain, for processing when the type is frozen.
12064 -- This is accomplished by a call to Rep_Item_Too_Late. We also
12065 -- mark the type as having predicates.
12067 Set_Has_Predicates (Typ);
12068 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12075 -- pragma Preelaborate [(library_unit_NAME)];
12077 -- Set the flag Is_Preelaborated of program unit name entity
12079 when Pragma_Preelaborate => Preelaborate : declare
12080 Pa : constant Node_Id := Parent (N);
12081 Pk : constant Node_Kind := Nkind (Pa);
12085 Check_Ada_83_Warning;
12086 Check_Valid_Library_Unit_Pragma;
12088 if Nkind (N) = N_Null_Statement then
12092 Ent := Find_Lib_Unit_Name;
12093 Check_Duplicate_Pragma (Ent);
12095 -- This filters out pragmas inside generic parent then
12096 -- show up inside instantiation
12099 and then not (Pk = N_Package_Specification
12100 and then Present (Generic_Parent (Pa)))
12102 if not Debug_Flag_U then
12103 Set_Is_Preelaborated (Ent);
12104 Set_Suppress_Elaboration_Warnings (Ent);
12109 ---------------------
12110 -- Preelaborate_05 --
12111 ---------------------
12113 -- pragma Preelaborate_05 [(library_unit_NAME)];
12115 -- This pragma is useable only in GNAT_Mode, where it is used like
12116 -- pragma Preelaborate but it is only effective in Ada 2005 mode
12117 -- (otherwise it is ignored). This is used to implement AI-362 which
12118 -- recategorizes some run-time packages in Ada 2005 mode.
12120 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
12125 Check_Valid_Library_Unit_Pragma;
12127 if not GNAT_Mode then
12128 Error_Pragma ("pragma% only available in GNAT mode");
12131 if Nkind (N) = N_Null_Statement then
12135 -- This is one of the few cases where we need to test the value of
12136 -- Ada_Version_Explicit rather than Ada_Version (which is always
12137 -- set to Ada_2012 in a predefined unit), we need to know the
12138 -- explicit version set to know if this pragma is active.
12140 if Ada_Version_Explicit >= Ada_2005 then
12141 Ent := Find_Lib_Unit_Name;
12142 Set_Is_Preelaborated (Ent);
12143 Set_Suppress_Elaboration_Warnings (Ent);
12145 end Preelaborate_05;
12151 -- pragma Priority (EXPRESSION);
12153 when Pragma_Priority => Priority : declare
12154 P : constant Node_Id := Parent (N);
12158 Check_No_Identifiers;
12159 Check_Arg_Count (1);
12163 if Nkind (P) = N_Subprogram_Body then
12164 Check_In_Main_Program;
12166 Arg := Get_Pragma_Arg (Arg1);
12167 Analyze_And_Resolve (Arg, Standard_Integer);
12171 if not Is_Static_Expression (Arg) then
12172 Flag_Non_Static_Expr
12173 ("main subprogram priority is not static!", Arg);
12176 -- If constraint error, then we already signalled an error
12178 elsif Raises_Constraint_Error (Arg) then
12181 -- Otherwise check in range
12185 Val : constant Uint := Expr_Value (Arg);
12189 or else Val > Expr_Value (Expression
12190 (Parent (RTE (RE_Max_Priority))))
12193 ("main subprogram priority is out of range", Arg1);
12199 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12201 -- Load an arbitrary entity from System.Tasking to make sure
12202 -- this package is implicitly with'ed, since we need to have
12203 -- the tasking run-time active for the pragma Priority to have
12207 Discard : Entity_Id;
12208 pragma Warnings (Off, Discard);
12210 Discard := RTE (RE_Task_List);
12213 -- Task or Protected, must be of type Integer
12215 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12216 Arg := Get_Pragma_Arg (Arg1);
12218 -- The expression must be analyzed in the special manner
12219 -- described in "Handling of Default and Per-Object
12220 -- Expressions" in sem.ads.
12222 Preanalyze_Spec_Expression (Arg, Standard_Integer);
12224 if not Is_Static_Expression (Arg) then
12225 Check_Restriction (Static_Priorities, Arg);
12228 -- Anything else is incorrect
12234 if Has_Pragma_Priority (P) then
12235 Error_Pragma ("duplicate pragma% not allowed");
12237 Set_Has_Pragma_Priority (P, True);
12239 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12240 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12241 -- exp_ch9 should use this ???
12246 -----------------------------------
12247 -- Priority_Specific_Dispatching --
12248 -----------------------------------
12250 -- pragma Priority_Specific_Dispatching (
12251 -- policy_IDENTIFIER,
12252 -- first_priority_EXPRESSION,
12253 -- last_priority_EXPRESSION);
12255 when Pragma_Priority_Specific_Dispatching =>
12256 Priority_Specific_Dispatching : declare
12257 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12258 -- This is the entity System.Any_Priority;
12261 Lower_Bound : Node_Id;
12262 Upper_Bound : Node_Id;
12268 Check_Arg_Count (3);
12269 Check_No_Identifiers;
12270 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12271 Check_Valid_Configuration_Pragma;
12272 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12273 DP := Fold_Upper (Name_Buffer (1));
12275 Lower_Bound := Get_Pragma_Arg (Arg2);
12276 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12277 Lower_Val := Expr_Value (Lower_Bound);
12279 Upper_Bound := Get_Pragma_Arg (Arg3);
12280 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12281 Upper_Val := Expr_Value (Upper_Bound);
12283 -- It is not allowed to use Task_Dispatching_Policy and
12284 -- Priority_Specific_Dispatching in the same partition.
12286 if Task_Dispatching_Policy /= ' ' then
12287 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12289 ("pragma% incompatible with Task_Dispatching_Policy#");
12291 -- Check lower bound in range
12293 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12295 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12298 ("first_priority is out of range", Arg2);
12300 -- Check upper bound in range
12302 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12304 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12307 ("last_priority is out of range", Arg3);
12309 -- Check that the priority range is valid
12311 elsif Lower_Val > Upper_Val then
12313 ("last_priority_expression must be greater than" &
12314 " or equal to first_priority_expression");
12316 -- Store the new policy, but always preserve System_Location since
12317 -- we like the error message with the run-time name.
12320 -- Check overlapping in the priority ranges specified in other
12321 -- Priority_Specific_Dispatching pragmas within the same
12322 -- partition. We can only check those we know about!
12325 Specific_Dispatching.First .. Specific_Dispatching.Last
12327 if Specific_Dispatching.Table (J).First_Priority in
12328 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12329 or else Specific_Dispatching.Table (J).Last_Priority in
12330 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12333 Specific_Dispatching.Table (J).Pragma_Loc;
12335 ("priority range overlaps with "
12336 & "Priority_Specific_Dispatching#");
12340 -- The use of Priority_Specific_Dispatching is incompatible
12341 -- with Task_Dispatching_Policy.
12343 if Task_Dispatching_Policy /= ' ' then
12344 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12346 ("Priority_Specific_Dispatching incompatible "
12347 & "with Task_Dispatching_Policy#");
12350 -- The use of Priority_Specific_Dispatching forces ceiling
12353 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12354 Error_Msg_Sloc := Locking_Policy_Sloc;
12356 ("Priority_Specific_Dispatching incompatible "
12357 & "with Locking_Policy#");
12359 -- Set the Ceiling_Locking policy, but preserve System_Location
12360 -- since we like the error message with the run time name.
12363 Locking_Policy := 'C';
12365 if Locking_Policy_Sloc /= System_Location then
12366 Locking_Policy_Sloc := Loc;
12370 -- Add entry in the table
12372 Specific_Dispatching.Append
12373 ((Dispatching_Policy => DP,
12374 First_Priority => UI_To_Int (Lower_Val),
12375 Last_Priority => UI_To_Int (Upper_Val),
12376 Pragma_Loc => Loc));
12378 end Priority_Specific_Dispatching;
12384 -- pragma Profile (profile_IDENTIFIER);
12386 -- profile_IDENTIFIER => Restricted | Ravenscar
12388 when Pragma_Profile =>
12390 Check_Arg_Count (1);
12391 Check_Valid_Configuration_Pragma;
12392 Check_No_Identifiers;
12395 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12398 if Chars (Argx) = Name_Ravenscar then
12399 Set_Ravenscar_Profile (N);
12401 elsif Chars (Argx) = Name_Restricted then
12402 Set_Profile_Restrictions
12404 N, Warn => Treat_Restrictions_As_Warnings);
12406 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12407 Set_Profile_Restrictions
12408 (No_Implementation_Extensions,
12409 N, Warn => Treat_Restrictions_As_Warnings);
12412 Error_Pragma_Arg ("& is not a valid profile", Argx);
12416 ----------------------
12417 -- Profile_Warnings --
12418 ----------------------
12420 -- pragma Profile_Warnings (profile_IDENTIFIER);
12422 -- profile_IDENTIFIER => Restricted | Ravenscar
12424 when Pragma_Profile_Warnings =>
12426 Check_Arg_Count (1);
12427 Check_Valid_Configuration_Pragma;
12428 Check_No_Identifiers;
12431 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12434 if Chars (Argx) = Name_Ravenscar then
12435 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12437 elsif Chars (Argx) = Name_Restricted then
12438 Set_Profile_Restrictions (Restricted, N, Warn => True);
12440 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12441 Set_Profile_Restrictions
12442 (No_Implementation_Extensions, N, Warn => True);
12445 Error_Pragma_Arg ("& is not a valid profile", Argx);
12449 --------------------------
12450 -- Propagate_Exceptions --
12451 --------------------------
12453 -- pragma Propagate_Exceptions;
12455 -- Note: this pragma is obsolete and has no effect
12457 when Pragma_Propagate_Exceptions =>
12459 Check_Arg_Count (0);
12461 if In_Extended_Main_Source_Unit (N) then
12462 Propagate_Exceptions := True;
12469 -- pragma Psect_Object (
12470 -- [Internal =>] LOCAL_NAME,
12471 -- [, [External =>] EXTERNAL_SYMBOL]
12472 -- [, [Size =>] EXTERNAL_SYMBOL]);
12474 when Pragma_Psect_Object | Pragma_Common_Object =>
12475 Psect_Object : declare
12476 Args : Args_List (1 .. 3);
12477 Names : constant Name_List (1 .. 3) := (
12482 Internal : Node_Id renames Args (1);
12483 External : Node_Id renames Args (2);
12484 Size : Node_Id renames Args (3);
12486 Def_Id : Entity_Id;
12488 procedure Check_Too_Long (Arg : Node_Id);
12489 -- Posts message if the argument is an identifier with more
12490 -- than 31 characters, or a string literal with more than
12491 -- 31 characters, and we are operating under VMS
12493 --------------------
12494 -- Check_Too_Long --
12495 --------------------
12497 procedure Check_Too_Long (Arg : Node_Id) is
12498 X : constant Node_Id := Original_Node (Arg);
12501 if not Nkind_In (X, N_String_Literal, N_Identifier) then
12503 ("inappropriate argument for pragma %", Arg);
12506 if OpenVMS_On_Target then
12507 if (Nkind (X) = N_String_Literal
12508 and then String_Length (Strval (X)) > 31)
12510 (Nkind (X) = N_Identifier
12511 and then Length_Of_Name (Chars (X)) > 31)
12514 ("argument for pragma % is longer than 31 characters",
12518 end Check_Too_Long;
12520 -- Start of processing for Common_Object/Psect_Object
12524 Gather_Associations (Names, Args);
12525 Process_Extended_Import_Export_Internal_Arg (Internal);
12527 Def_Id := Entity (Internal);
12529 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12531 ("pragma% must designate an object", Internal);
12534 Check_Too_Long (Internal);
12536 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12538 ("cannot use pragma% for imported/exported object",
12542 if Is_Concurrent_Type (Etype (Internal)) then
12544 ("cannot specify pragma % for task/protected object",
12548 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12550 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12552 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12555 if Ekind (Def_Id) = E_Constant then
12557 ("cannot specify pragma % for a constant", Internal);
12560 if Is_Record_Type (Etype (Internal)) then
12566 Ent := First_Entity (Etype (Internal));
12567 while Present (Ent) loop
12568 Decl := Declaration_Node (Ent);
12570 if Ekind (Ent) = E_Component
12571 and then Nkind (Decl) = N_Component_Declaration
12572 and then Present (Expression (Decl))
12573 and then Warn_On_Export_Import
12576 ("?object for pragma % has defaults", Internal);
12586 if Present (Size) then
12587 Check_Too_Long (Size);
12590 if Present (External) then
12591 Check_Arg_Is_External_Name (External);
12592 Check_Too_Long (External);
12595 -- If all error tests pass, link pragma on to the rep item chain
12597 Record_Rep_Item (Def_Id, N);
12604 -- pragma Pure [(library_unit_NAME)];
12606 when Pragma_Pure => Pure : declare
12610 Check_Ada_83_Warning;
12611 Check_Valid_Library_Unit_Pragma;
12613 if Nkind (N) = N_Null_Statement then
12617 Ent := Find_Lib_Unit_Name;
12619 Set_Has_Pragma_Pure (Ent);
12620 Set_Suppress_Elaboration_Warnings (Ent);
12627 -- pragma Pure_05 [(library_unit_NAME)];
12629 -- This pragma is useable only in GNAT_Mode, where it is used like
12630 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
12631 -- it is ignored). It may be used after a pragma Preelaborate, in
12632 -- which case it overrides the effect of the pragma Preelaborate.
12633 -- This is used to implement AI-362 which recategorizes some run-time
12634 -- packages in Ada 2005 mode.
12636 when Pragma_Pure_05 => Pure_05 : declare
12641 Check_Valid_Library_Unit_Pragma;
12643 if not GNAT_Mode then
12644 Error_Pragma ("pragma% only available in GNAT mode");
12647 if Nkind (N) = N_Null_Statement then
12651 -- This is one of the few cases where we need to test the value of
12652 -- Ada_Version_Explicit rather than Ada_Version (which is always
12653 -- set to Ada_2012 in a predefined unit), we need to know the
12654 -- explicit version set to know if this pragma is active.
12656 if Ada_Version_Explicit >= Ada_2005 then
12657 Ent := Find_Lib_Unit_Name;
12658 Set_Is_Preelaborated (Ent, False);
12660 Set_Suppress_Elaboration_Warnings (Ent);
12668 -- pragma Pure_12 [(library_unit_NAME)];
12670 -- This pragma is useable only in GNAT_Mode, where it is used like
12671 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
12672 -- it is ignored). It may be used after a pragma Preelaborate, in
12673 -- which case it overrides the effect of the pragma Preelaborate.
12674 -- This is used to implement AI05-0212 which recategorizes some
12675 -- run-time packages in Ada 2012 mode.
12677 when Pragma_Pure_12 => Pure_12 : declare
12682 Check_Valid_Library_Unit_Pragma;
12684 if not GNAT_Mode then
12685 Error_Pragma ("pragma% only available in GNAT mode");
12688 if Nkind (N) = N_Null_Statement then
12692 -- This is one of the few cases where we need to test the value of
12693 -- Ada_Version_Explicit rather than Ada_Version (which is always
12694 -- set to Ada_2012 in a predefined unit), we need to know the
12695 -- explicit version set to know if this pragma is active.
12697 if Ada_Version_Explicit >= Ada_2012 then
12698 Ent := Find_Lib_Unit_Name;
12699 Set_Is_Preelaborated (Ent, False);
12701 Set_Suppress_Elaboration_Warnings (Ent);
12705 -------------------
12706 -- Pure_Function --
12707 -------------------
12709 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12711 when Pragma_Pure_Function => Pure_Function : declare
12714 Def_Id : Entity_Id;
12715 Effective : Boolean := False;
12719 Check_Arg_Count (1);
12720 Check_Optional_Identifier (Arg1, Name_Entity);
12721 Check_Arg_Is_Local_Name (Arg1);
12722 E_Id := Get_Pragma_Arg (Arg1);
12724 if Error_Posted (E_Id) then
12728 -- Loop through homonyms (overloadings) of referenced entity
12730 E := Entity (E_Id);
12732 if Present (E) then
12734 Def_Id := Get_Base_Subprogram (E);
12736 if not Ekind_In (Def_Id, E_Function,
12737 E_Generic_Function,
12741 ("pragma% requires a function name", Arg1);
12744 Set_Is_Pure (Def_Id);
12746 if not Has_Pragma_Pure_Function (Def_Id) then
12747 Set_Has_Pragma_Pure_Function (Def_Id);
12751 exit when From_Aspect_Specification (N);
12753 exit when No (E) or else Scope (E) /= Current_Scope;
12757 and then Warn_On_Redundant_Constructs
12760 ("pragma Pure_Function on& is redundant?",
12766 --------------------
12767 -- Queuing_Policy --
12768 --------------------
12770 -- pragma Queuing_Policy (policy_IDENTIFIER);
12772 when Pragma_Queuing_Policy => declare
12776 Check_Ada_83_Warning;
12777 Check_Arg_Count (1);
12778 Check_No_Identifiers;
12779 Check_Arg_Is_Queuing_Policy (Arg1);
12780 Check_Valid_Configuration_Pragma;
12781 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12782 QP := Fold_Upper (Name_Buffer (1));
12784 if Queuing_Policy /= ' '
12785 and then Queuing_Policy /= QP
12787 Error_Msg_Sloc := Queuing_Policy_Sloc;
12788 Error_Pragma ("queuing policy incompatible with policy#");
12790 -- Set new policy, but always preserve System_Location since we
12791 -- like the error message with the run time name.
12794 Queuing_Policy := QP;
12796 if Queuing_Policy_Sloc /= System_Location then
12797 Queuing_Policy_Sloc := Loc;
12802 -----------------------
12803 -- Relative_Deadline --
12804 -----------------------
12806 -- pragma Relative_Deadline (time_span_EXPRESSION);
12808 when Pragma_Relative_Deadline => Relative_Deadline : declare
12809 P : constant Node_Id := Parent (N);
12814 Check_No_Identifiers;
12815 Check_Arg_Count (1);
12817 Arg := Get_Pragma_Arg (Arg1);
12819 -- The expression must be analyzed in the special manner described
12820 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12822 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12826 if Nkind (P) = N_Subprogram_Body then
12827 Check_In_Main_Program;
12831 elsif Nkind (P) = N_Task_Definition then
12834 -- Anything else is incorrect
12840 if Has_Relative_Deadline_Pragma (P) then
12841 Error_Pragma ("duplicate pragma% not allowed");
12843 Set_Has_Relative_Deadline_Pragma (P, True);
12845 if Nkind (P) = N_Task_Definition then
12846 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12849 end Relative_Deadline;
12851 ---------------------------
12852 -- Remote_Call_Interface --
12853 ---------------------------
12855 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12857 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12858 Cunit_Node : Node_Id;
12859 Cunit_Ent : Entity_Id;
12863 Check_Ada_83_Warning;
12864 Check_Valid_Library_Unit_Pragma;
12866 if Nkind (N) = N_Null_Statement then
12870 Cunit_Node := Cunit (Current_Sem_Unit);
12871 K := Nkind (Unit (Cunit_Node));
12872 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12874 if K = N_Package_Declaration
12875 or else K = N_Generic_Package_Declaration
12876 or else K = N_Subprogram_Declaration
12877 or else K = N_Generic_Subprogram_Declaration
12878 or else (K = N_Subprogram_Body
12879 and then Acts_As_Spec (Unit (Cunit_Node)))
12884 "pragma% must apply to package or subprogram declaration");
12887 Set_Is_Remote_Call_Interface (Cunit_Ent);
12888 end Remote_Call_Interface;
12894 -- pragma Remote_Types [(library_unit_NAME)];
12896 when Pragma_Remote_Types => Remote_Types : declare
12897 Cunit_Node : Node_Id;
12898 Cunit_Ent : Entity_Id;
12901 Check_Ada_83_Warning;
12902 Check_Valid_Library_Unit_Pragma;
12904 if Nkind (N) = N_Null_Statement then
12908 Cunit_Node := Cunit (Current_Sem_Unit);
12909 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12911 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12912 N_Generic_Package_Declaration)
12915 ("pragma% can only apply to a package declaration");
12918 Set_Is_Remote_Types (Cunit_Ent);
12925 -- pragma Ravenscar;
12927 when Pragma_Ravenscar =>
12929 Check_Arg_Count (0);
12930 Check_Valid_Configuration_Pragma;
12931 Set_Ravenscar_Profile (N);
12933 if Warn_On_Obsolescent_Feature then
12934 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12935 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12938 -------------------------
12939 -- Restricted_Run_Time --
12940 -------------------------
12942 -- pragma Restricted_Run_Time;
12944 when Pragma_Restricted_Run_Time =>
12946 Check_Arg_Count (0);
12947 Check_Valid_Configuration_Pragma;
12948 Set_Profile_Restrictions
12949 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12951 if Warn_On_Obsolescent_Feature then
12953 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12954 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12961 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12964 -- restriction_IDENTIFIER
12965 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12967 when Pragma_Restrictions =>
12968 Process_Restrictions_Or_Restriction_Warnings
12969 (Warn => Treat_Restrictions_As_Warnings);
12971 --------------------------
12972 -- Restriction_Warnings --
12973 --------------------------
12975 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12978 -- restriction_IDENTIFIER
12979 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12981 when Pragma_Restriction_Warnings =>
12983 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12989 -- pragma Reviewable;
12991 when Pragma_Reviewable =>
12992 Check_Ada_83_Warning;
12993 Check_Arg_Count (0);
12995 -- Call dummy debugging function rv. This is done to assist front
12996 -- end debugging. By placing a Reviewable pragma in the source
12997 -- program, a breakpoint on rv catches this place in the source,
12998 -- allowing convenient stepping to the point of interest.
13002 --------------------------
13003 -- Short_Circuit_And_Or --
13004 --------------------------
13006 when Pragma_Short_Circuit_And_Or =>
13008 Check_Arg_Count (0);
13009 Check_Valid_Configuration_Pragma;
13010 Short_Circuit_And_Or := True;
13012 -------------------
13013 -- Share_Generic --
13014 -------------------
13016 -- pragma Share_Generic (NAME {, NAME});
13018 when Pragma_Share_Generic =>
13020 Process_Generic_List;
13026 -- pragma Shared (LOCAL_NAME);
13028 when Pragma_Shared =>
13030 Process_Atomic_Shared_Volatile;
13032 --------------------
13033 -- Shared_Passive --
13034 --------------------
13036 -- pragma Shared_Passive [(library_unit_NAME)];
13038 -- Set the flag Is_Shared_Passive of program unit name entity
13040 when Pragma_Shared_Passive => Shared_Passive : declare
13041 Cunit_Node : Node_Id;
13042 Cunit_Ent : Entity_Id;
13045 Check_Ada_83_Warning;
13046 Check_Valid_Library_Unit_Pragma;
13048 if Nkind (N) = N_Null_Statement then
13052 Cunit_Node := Cunit (Current_Sem_Unit);
13053 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13055 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13056 N_Generic_Package_Declaration)
13059 ("pragma% can only apply to a package declaration");
13062 Set_Is_Shared_Passive (Cunit_Ent);
13063 end Shared_Passive;
13065 -----------------------
13066 -- Short_Descriptors --
13067 -----------------------
13069 -- pragma Short_Descriptors;
13071 when Pragma_Short_Descriptors =>
13073 Check_Arg_Count (0);
13074 Check_Valid_Configuration_Pragma;
13075 Short_Descriptors := True;
13077 ----------------------
13078 -- Source_File_Name --
13079 ----------------------
13081 -- There are five forms for this pragma:
13083 -- pragma Source_File_Name (
13084 -- [UNIT_NAME =>] unit_NAME,
13085 -- BODY_FILE_NAME => STRING_LITERAL
13086 -- [, [INDEX =>] INTEGER_LITERAL]);
13088 -- pragma Source_File_Name (
13089 -- [UNIT_NAME =>] unit_NAME,
13090 -- SPEC_FILE_NAME => STRING_LITERAL
13091 -- [, [INDEX =>] INTEGER_LITERAL]);
13093 -- pragma Source_File_Name (
13094 -- BODY_FILE_NAME => STRING_LITERAL
13095 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13096 -- [, CASING => CASING_SPEC]);
13098 -- pragma Source_File_Name (
13099 -- SPEC_FILE_NAME => STRING_LITERAL
13100 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13101 -- [, CASING => CASING_SPEC]);
13103 -- pragma Source_File_Name (
13104 -- SUBUNIT_FILE_NAME => STRING_LITERAL
13105 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13106 -- [, CASING => CASING_SPEC]);
13108 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
13110 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
13111 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
13112 -- only be used when no project file is used, while SFNP can only be
13113 -- used when a project file is used.
13115 -- No processing here. Processing was completed during parsing, since
13116 -- we need to have file names set as early as possible. Units are
13117 -- loaded well before semantic processing starts.
13119 -- The only processing we defer to this point is the check for
13120 -- correct placement.
13122 when Pragma_Source_File_Name =>
13124 Check_Valid_Configuration_Pragma;
13126 ------------------------------
13127 -- Source_File_Name_Project --
13128 ------------------------------
13130 -- See Source_File_Name for syntax
13132 -- No processing here. Processing was completed during parsing, since
13133 -- we need to have file names set as early as possible. Units are
13134 -- loaded well before semantic processing starts.
13136 -- The only processing we defer to this point is the check for
13137 -- correct placement.
13139 when Pragma_Source_File_Name_Project =>
13141 Check_Valid_Configuration_Pragma;
13143 -- Check that a pragma Source_File_Name_Project is used only in a
13144 -- configuration pragmas file.
13146 -- Pragmas Source_File_Name_Project should only be generated by
13147 -- the Project Manager in configuration pragmas files.
13149 -- This is really an ugly test. It seems to depend on some
13150 -- accidental and undocumented property. At the very least it
13151 -- needs to be documented, but it would be better to have a
13152 -- clean way of testing if we are in a configuration file???
13154 if Present (Parent (N)) then
13156 ("pragma% can only appear in a configuration pragmas file");
13159 ----------------------
13160 -- Source_Reference --
13161 ----------------------
13163 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
13165 -- Nothing to do, all processing completed in Par.Prag, since we need
13166 -- the information for possible parser messages that are output.
13168 when Pragma_Source_Reference =>
13171 --------------------------------
13172 -- Static_Elaboration_Desired --
13173 --------------------------------
13175 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
13177 when Pragma_Static_Elaboration_Desired =>
13179 Check_At_Most_N_Arguments (1);
13181 if Is_Compilation_Unit (Current_Scope)
13182 and then Ekind (Current_Scope) = E_Package
13184 Set_Static_Elaboration_Desired (Current_Scope, True);
13186 Error_Pragma ("pragma% must apply to a library-level package");
13193 -- pragma Storage_Size (EXPRESSION);
13195 when Pragma_Storage_Size => Storage_Size : declare
13196 P : constant Node_Id := Parent (N);
13200 Check_No_Identifiers;
13201 Check_Arg_Count (1);
13203 -- The expression must be analyzed in the special manner described
13204 -- in "Handling of Default Expressions" in sem.ads.
13206 Arg := Get_Pragma_Arg (Arg1);
13207 Preanalyze_Spec_Expression (Arg, Any_Integer);
13209 if not Is_Static_Expression (Arg) then
13210 Check_Restriction (Static_Storage_Size, Arg);
13213 if Nkind (P) /= N_Task_Definition then
13218 if Has_Storage_Size_Pragma (P) then
13219 Error_Pragma ("duplicate pragma% not allowed");
13221 Set_Has_Storage_Size_Pragma (P, True);
13224 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13225 -- ??? exp_ch9 should use this!
13233 -- pragma Storage_Unit (NUMERIC_LITERAL);
13235 -- Only permitted argument is System'Storage_Unit value
13237 when Pragma_Storage_Unit =>
13238 Check_No_Identifiers;
13239 Check_Arg_Count (1);
13240 Check_Arg_Is_Integer_Literal (Arg1);
13242 if Intval (Get_Pragma_Arg (Arg1)) /=
13243 UI_From_Int (Ttypes.System_Storage_Unit)
13245 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
13247 ("the only allowed argument for pragma% is ^", Arg1);
13250 --------------------
13251 -- Stream_Convert --
13252 --------------------
13254 -- pragma Stream_Convert (
13255 -- [Entity =>] type_LOCAL_NAME,
13256 -- [Read =>] function_NAME,
13257 -- [Write =>] function NAME);
13259 when Pragma_Stream_Convert => Stream_Convert : declare
13261 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
13262 -- Check that the given argument is the name of a local function
13263 -- of one argument that is not overloaded earlier in the current
13264 -- local scope. A check is also made that the argument is a
13265 -- function with one parameter.
13267 --------------------------------------
13268 -- Check_OK_Stream_Convert_Function --
13269 --------------------------------------
13271 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
13275 Check_Arg_Is_Local_Name (Arg);
13276 Ent := Entity (Get_Pragma_Arg (Arg));
13278 if Has_Homonym (Ent) then
13280 ("argument for pragma% may not be overloaded", Arg);
13283 if Ekind (Ent) /= E_Function
13284 or else No (First_Formal (Ent))
13285 or else Present (Next_Formal (First_Formal (Ent)))
13288 ("argument for pragma% must be" &
13289 " function of one argument", Arg);
13291 end Check_OK_Stream_Convert_Function;
13293 -- Start of processing for Stream_Convert
13297 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
13298 Check_Arg_Count (3);
13299 Check_Optional_Identifier (Arg1, Name_Entity);
13300 Check_Optional_Identifier (Arg2, Name_Read);
13301 Check_Optional_Identifier (Arg3, Name_Write);
13302 Check_Arg_Is_Local_Name (Arg1);
13303 Check_OK_Stream_Convert_Function (Arg2);
13304 Check_OK_Stream_Convert_Function (Arg3);
13307 Typ : constant Entity_Id :=
13308 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13309 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13310 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
13313 Check_First_Subtype (Arg1);
13315 -- Check for too early or too late. Note that we don't enforce
13316 -- the rule about primitive operations in this case, since, as
13317 -- is the case for explicit stream attributes themselves, these
13318 -- restrictions are not appropriate. Note that the chaining of
13319 -- the pragma by Rep_Item_Too_Late is actually the critical
13320 -- processing done for this pragma.
13322 if Rep_Item_Too_Early (Typ, N)
13324 Rep_Item_Too_Late (Typ, N, FOnly => True)
13329 -- Return if previous error
13331 if Etype (Typ) = Any_Type
13333 Etype (Read) = Any_Type
13335 Etype (Write) = Any_Type
13342 if Underlying_Type (Etype (Read)) /= Typ then
13344 ("incorrect return type for function&", Arg2);
13347 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13349 ("incorrect parameter type for function&", Arg3);
13352 if Underlying_Type (Etype (First_Formal (Read))) /=
13353 Underlying_Type (Etype (Write))
13356 ("result type of & does not match Read parameter type",
13360 end Stream_Convert;
13362 -------------------------
13363 -- Style_Checks (GNAT) --
13364 -------------------------
13366 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13368 -- This is processed by the parser since some of the style checks
13369 -- take place during source scanning and parsing. This means that
13370 -- we don't need to issue error messages here.
13372 when Pragma_Style_Checks => Style_Checks : declare
13373 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13379 Check_No_Identifiers;
13381 -- Two argument form
13383 if Arg_Count = 2 then
13384 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13391 E_Id := Get_Pragma_Arg (Arg2);
13394 if not Is_Entity_Name (E_Id) then
13396 ("second argument of pragma% must be entity name",
13400 E := Entity (E_Id);
13406 Set_Suppress_Style_Checks (E,
13407 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
13408 exit when No (Homonym (E));
13414 -- One argument form
13417 Check_Arg_Count (1);
13419 if Nkind (A) = N_String_Literal then
13423 Slen : constant Natural := Natural (String_Length (S));
13424 Options : String (1 .. Slen);
13430 C := Get_String_Char (S, Int (J));
13431 exit when not In_Character_Range (C);
13432 Options (J) := Get_Character (C);
13434 -- If at end of string, set options. As per discussion
13435 -- above, no need to check for errors, since we issued
13436 -- them in the parser.
13439 Set_Style_Check_Options (Options);
13447 elsif Nkind (A) = N_Identifier then
13448 if Chars (A) = Name_All_Checks then
13450 Set_GNAT_Style_Check_Options;
13452 Set_Default_Style_Check_Options;
13455 elsif Chars (A) = Name_On then
13456 Style_Check := True;
13458 elsif Chars (A) = Name_Off then
13459 Style_Check := False;
13469 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13471 when Pragma_Subtitle =>
13473 Check_Arg_Count (1);
13474 Check_Optional_Identifier (Arg1, Name_Subtitle);
13475 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13482 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13484 when Pragma_Suppress =>
13485 Process_Suppress_Unsuppress (True);
13491 -- pragma Suppress_All;
13493 -- The only check made here is that the pragma has no arguments.
13494 -- There are no placement rules, and the processing required (setting
13495 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
13496 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
13497 -- then creates and inserts a pragma Suppress (All_Checks).
13499 when Pragma_Suppress_All =>
13501 Check_Arg_Count (0);
13503 -------------------------
13504 -- Suppress_Debug_Info --
13505 -------------------------
13507 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13509 when Pragma_Suppress_Debug_Info =>
13511 Check_Arg_Count (1);
13512 Check_Optional_Identifier (Arg1, Name_Entity);
13513 Check_Arg_Is_Local_Name (Arg1);
13514 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13516 ----------------------------------
13517 -- Suppress_Exception_Locations --
13518 ----------------------------------
13520 -- pragma Suppress_Exception_Locations;
13522 when Pragma_Suppress_Exception_Locations =>
13524 Check_Arg_Count (0);
13525 Check_Valid_Configuration_Pragma;
13526 Exception_Locations_Suppressed := True;
13528 -----------------------------
13529 -- Suppress_Initialization --
13530 -----------------------------
13532 -- pragma Suppress_Initialization ([Entity =>] type_Name);
13534 when Pragma_Suppress_Initialization => Suppress_Init : declare
13540 Check_Arg_Count (1);
13541 Check_Optional_Identifier (Arg1, Name_Entity);
13542 Check_Arg_Is_Local_Name (Arg1);
13544 E_Id := Get_Pragma_Arg (Arg1);
13546 if Etype (E_Id) = Any_Type then
13550 E := Entity (E_Id);
13552 if not Is_Type (E) then
13553 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13556 if Rep_Item_Too_Early (E, N)
13558 Rep_Item_Too_Late (E, N, FOnly => True)
13563 -- For incomplete/private type, set flag on full view
13565 if Is_Incomplete_Or_Private_Type (E) then
13566 if No (Full_View (Base_Type (E))) then
13568 ("argument of pragma% cannot be an incomplete type", Arg1);
13570 Set_Suppress_Initialization (Full_View (Base_Type (E)));
13573 -- For first subtype, set flag on base type
13575 elsif Is_First_Subtype (E) then
13576 Set_Suppress_Initialization (Base_Type (E));
13578 -- For other than first subtype, set flag on subtype itself
13581 Set_Suppress_Initialization (E);
13589 -- pragma System_Name (DIRECT_NAME);
13591 -- Syntax check: one argument, which must be the identifier GNAT or
13592 -- the identifier GCC, no other identifiers are acceptable.
13594 when Pragma_System_Name =>
13596 Check_No_Identifiers;
13597 Check_Arg_Count (1);
13598 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13600 -----------------------------
13601 -- Task_Dispatching_Policy --
13602 -----------------------------
13604 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13606 when Pragma_Task_Dispatching_Policy => declare
13610 Check_Ada_83_Warning;
13611 Check_Arg_Count (1);
13612 Check_No_Identifiers;
13613 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13614 Check_Valid_Configuration_Pragma;
13615 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13616 DP := Fold_Upper (Name_Buffer (1));
13618 if Task_Dispatching_Policy /= ' '
13619 and then Task_Dispatching_Policy /= DP
13621 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13623 ("task dispatching policy incompatible with policy#");
13625 -- Set new policy, but always preserve System_Location since we
13626 -- like the error message with the run time name.
13629 Task_Dispatching_Policy := DP;
13631 if Task_Dispatching_Policy_Sloc /= System_Location then
13632 Task_Dispatching_Policy_Sloc := Loc;
13641 -- pragma Task_Info (EXPRESSION);
13643 when Pragma_Task_Info => Task_Info : declare
13644 P : constant Node_Id := Parent (N);
13649 if Nkind (P) /= N_Task_Definition then
13650 Error_Pragma ("pragma% must appear in task definition");
13653 Check_No_Identifiers;
13654 Check_Arg_Count (1);
13656 Analyze_And_Resolve
13657 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13659 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13663 if Has_Task_Info_Pragma (P) then
13664 Error_Pragma ("duplicate pragma% not allowed");
13666 Set_Has_Task_Info_Pragma (P, True);
13674 -- pragma Task_Name (string_EXPRESSION);
13676 when Pragma_Task_Name => Task_Name : declare
13677 P : constant Node_Id := Parent (N);
13681 Check_No_Identifiers;
13682 Check_Arg_Count (1);
13684 Arg := Get_Pragma_Arg (Arg1);
13686 -- The expression is used in the call to Create_Task, and must be
13687 -- expanded there, not in the context of the current spec. It must
13688 -- however be analyzed to capture global references, in case it
13689 -- appears in a generic context.
13691 Preanalyze_And_Resolve (Arg, Standard_String);
13693 if Nkind (P) /= N_Task_Definition then
13697 if Has_Task_Name_Pragma (P) then
13698 Error_Pragma ("duplicate pragma% not allowed");
13700 Set_Has_Task_Name_Pragma (P, True);
13701 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13709 -- pragma Task_Storage (
13710 -- [Task_Type =>] LOCAL_NAME,
13711 -- [Top_Guard =>] static_integer_EXPRESSION);
13713 when Pragma_Task_Storage => Task_Storage : declare
13714 Args : Args_List (1 .. 2);
13715 Names : constant Name_List (1 .. 2) := (
13719 Task_Type : Node_Id renames Args (1);
13720 Top_Guard : Node_Id renames Args (2);
13726 Gather_Associations (Names, Args);
13728 if No (Task_Type) then
13730 ("missing task_type argument for pragma%");
13733 Check_Arg_Is_Local_Name (Task_Type);
13735 Ent := Entity (Task_Type);
13737 if not Is_Task_Type (Ent) then
13739 ("argument for pragma% must be task type", Task_Type);
13742 if No (Top_Guard) then
13744 ("pragma% takes two arguments", Task_Type);
13746 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13749 Check_First_Subtype (Task_Type);
13751 if Rep_Item_Too_Late (Ent, N) then
13760 -- pragma Test_Case ([Name =>] Static_String_EXPRESSION
13761 -- ,[Mode =>] MODE_TYPE
13762 -- [, Requires => Boolean_EXPRESSION]
13763 -- [, Ensures => Boolean_EXPRESSION]);
13765 -- MODE_TYPE ::= Nominal | Robustness
13767 when Pragma_Test_Case => Test_Case : declare
13770 Check_At_Least_N_Arguments (2);
13771 Check_At_Most_N_Arguments (4);
13773 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13775 Check_Optional_Identifier (Arg1, Name_Name);
13776 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13778 -- In ASIS mode, for a pragma generated from a source aspect, also
13779 -- analyze the original aspect expression.
13782 and then Present (Corresponding_Aspect (N))
13784 Check_Expr_Is_Static_Expression
13785 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
13788 Check_Optional_Identifier (Arg2, Name_Mode);
13789 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13791 if Arg_Count = 4 then
13792 Check_Identifier (Arg3, Name_Requires);
13793 Check_Identifier (Arg4, Name_Ensures);
13795 elsif Arg_Count = 3 then
13796 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13802 --------------------------
13803 -- Thread_Local_Storage --
13804 --------------------------
13806 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13808 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13814 Check_Arg_Count (1);
13815 Check_Optional_Identifier (Arg1, Name_Entity);
13816 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13818 Id := Get_Pragma_Arg (Arg1);
13821 if not Is_Entity_Name (Id)
13822 or else Ekind (Entity (Id)) /= E_Variable
13824 Error_Pragma_Arg ("local variable name required", Arg1);
13829 if Rep_Item_Too_Early (E, N)
13830 or else Rep_Item_Too_Late (E, N)
13835 Set_Has_Pragma_Thread_Local_Storage (E);
13836 Set_Has_Gigi_Rep_Item (E);
13837 end Thread_Local_Storage;
13843 -- pragma Time_Slice (static_duration_EXPRESSION);
13845 when Pragma_Time_Slice => Time_Slice : declare
13851 Check_Arg_Count (1);
13852 Check_No_Identifiers;
13853 Check_In_Main_Program;
13854 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13856 if not Error_Posted (Arg1) then
13858 while Present (Nod) loop
13859 if Nkind (Nod) = N_Pragma
13860 and then Pragma_Name (Nod) = Name_Time_Slice
13862 Error_Msg_Name_1 := Pname;
13863 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13870 -- Process only if in main unit
13872 if Get_Source_Unit (Loc) = Main_Unit then
13873 Opt.Time_Slice_Set := True;
13874 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13876 if Val <= Ureal_0 then
13877 Opt.Time_Slice_Value := 0;
13879 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13880 Opt.Time_Slice_Value := 1_000_000_000;
13883 Opt.Time_Slice_Value :=
13884 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13893 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13895 -- TITLING_OPTION ::=
13896 -- [Title =>] STRING_LITERAL
13897 -- | [Subtitle =>] STRING_LITERAL
13899 when Pragma_Title => Title : declare
13900 Args : Args_List (1 .. 2);
13901 Names : constant Name_List (1 .. 2) := (
13907 Gather_Associations (Names, Args);
13910 for J in 1 .. 2 loop
13911 if Present (Args (J)) then
13912 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13917 ---------------------
13918 -- Unchecked_Union --
13919 ---------------------
13921 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13923 when Pragma_Unchecked_Union => Unchecked_Union : declare
13924 Assoc : constant Node_Id := Arg1;
13925 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13936 Check_No_Identifiers;
13937 Check_Arg_Count (1);
13938 Check_Arg_Is_Local_Name (Arg1);
13940 Find_Type (Type_Id);
13941 Typ := Entity (Type_Id);
13944 or else Rep_Item_Too_Early (Typ, N)
13948 Typ := Underlying_Type (Typ);
13951 if Rep_Item_Too_Late (Typ, N) then
13955 Check_First_Subtype (Arg1);
13957 -- Note remaining cases are references to a type in the current
13958 -- declarative part. If we find an error, we post the error on
13959 -- the relevant type declaration at an appropriate point.
13961 if not Is_Record_Type (Typ) then
13962 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13965 elsif Is_Tagged_Type (Typ) then
13966 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13969 elsif not Has_Discriminants (Typ) then
13971 ("Unchecked_Union must have one discriminant", Typ);
13974 -- Note: in previous versions of GNAT we used to check for limited
13975 -- types and give an error, but in fact the standard does allow
13976 -- Unchecked_Union on limited types, so this check was removed.
13978 -- Proceed with basic error checks completed
13981 Discr := First_Discriminant (Typ);
13982 while Present (Discr) loop
13983 if No (Discriminant_Default_Value (Discr)) then
13985 ("Unchecked_Union discriminant must have default value",
13989 Next_Discriminant (Discr);
13992 Tdef := Type_Definition (Declaration_Node (Typ));
13993 Clist := Component_List (Tdef);
13995 Comp := First (Component_Items (Clist));
13996 while Present (Comp) loop
13997 Check_Component (Comp, Typ);
14001 if No (Clist) or else No (Variant_Part (Clist)) then
14003 ("Unchecked_Union must have variant part",
14008 Vpart := Variant_Part (Clist);
14010 Variant := First (Variants (Vpart));
14011 while Present (Variant) loop
14012 Check_Variant (Variant, Typ);
14017 Set_Is_Unchecked_Union (Typ);
14018 Set_Convention (Typ, Convention_C);
14019 Set_Has_Unchecked_Union (Base_Type (Typ));
14020 Set_Is_Unchecked_Union (Base_Type (Typ));
14021 end Unchecked_Union;
14023 ------------------------
14024 -- Unimplemented_Unit --
14025 ------------------------
14027 -- pragma Unimplemented_Unit;
14029 -- Note: this only gives an error if we are generating code, or if
14030 -- we are in a generic library unit (where the pragma appears in the
14031 -- body, not in the spec).
14033 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
14034 Cunitent : constant Entity_Id :=
14035 Cunit_Entity (Get_Source_Unit (Loc));
14036 Ent_Kind : constant Entity_Kind :=
14041 Check_Arg_Count (0);
14043 if Operating_Mode = Generate_Code
14044 or else Ent_Kind = E_Generic_Function
14045 or else Ent_Kind = E_Generic_Procedure
14046 or else Ent_Kind = E_Generic_Package
14048 Get_Name_String (Chars (Cunitent));
14049 Set_Casing (Mixed_Case);
14050 Write_Str (Name_Buffer (1 .. Name_Len));
14051 Write_Str (" is not supported in this configuration");
14053 raise Unrecoverable_Error;
14055 end Unimplemented_Unit;
14057 ------------------------
14058 -- Universal_Aliasing --
14059 ------------------------
14061 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
14063 when Pragma_Universal_Aliasing => Universal_Alias : declare
14068 Check_Arg_Count (1);
14069 Check_Optional_Identifier (Arg2, Name_Entity);
14070 Check_Arg_Is_Local_Name (Arg1);
14071 E_Id := Entity (Get_Pragma_Arg (Arg1));
14073 if E_Id = Any_Type then
14075 elsif No (E_Id) or else not Is_Type (E_Id) then
14076 Error_Pragma_Arg ("pragma% requires type", Arg1);
14079 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
14080 end Universal_Alias;
14082 --------------------
14083 -- Universal_Data --
14084 --------------------
14086 -- pragma Universal_Data [(library_unit_NAME)];
14088 when Pragma_Universal_Data =>
14091 -- If this is a configuration pragma, then set the universal
14092 -- addressing option, otherwise confirm that the pragma satisfies
14093 -- the requirements of library unit pragma placement and leave it
14094 -- to the GNAAMP back end to detect the pragma (avoids transitive
14095 -- setting of the option due to withed units).
14097 if Is_Configuration_Pragma then
14098 Universal_Addressing_On_AAMP := True;
14100 Check_Valid_Library_Unit_Pragma;
14103 if not AAMP_On_Target then
14104 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
14111 -- pragma Unmodified (local_Name {, local_Name});
14113 when Pragma_Unmodified => Unmodified : declare
14114 Arg_Node : Node_Id;
14115 Arg_Expr : Node_Id;
14116 Arg_Ent : Entity_Id;
14120 Check_At_Least_N_Arguments (1);
14122 -- Loop through arguments
14125 while Present (Arg_Node) loop
14126 Check_No_Identifier (Arg_Node);
14128 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
14129 -- in fact generate reference, so that the entity will have a
14130 -- reference, which will inhibit any warnings about it not
14131 -- being referenced, and also properly show up in the ali file
14132 -- as a reference. But this reference is recorded before the
14133 -- Has_Pragma_Unreferenced flag is set, so that no warning is
14134 -- generated for this reference.
14136 Check_Arg_Is_Local_Name (Arg_Node);
14137 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14139 if Is_Entity_Name (Arg_Expr) then
14140 Arg_Ent := Entity (Arg_Expr);
14142 if not Is_Assignable (Arg_Ent) then
14144 ("pragma% can only be applied to a variable",
14147 Set_Has_Pragma_Unmodified (Arg_Ent);
14159 -- pragma Unreferenced (local_Name {, local_Name});
14161 -- or when used in a context clause:
14163 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
14165 when Pragma_Unreferenced => Unreferenced : declare
14166 Arg_Node : Node_Id;
14167 Arg_Expr : Node_Id;
14168 Arg_Ent : Entity_Id;
14173 Check_At_Least_N_Arguments (1);
14175 -- Check case of appearing within context clause
14177 if Is_In_Context_Clause then
14179 -- The arguments must all be units mentioned in a with clause
14180 -- in the same context clause. Note we already checked (in
14181 -- Par.Prag) that the arguments are either identifiers or
14182 -- selected components.
14185 while Present (Arg_Node) loop
14186 Citem := First (List_Containing (N));
14187 while Citem /= N loop
14188 if Nkind (Citem) = N_With_Clause
14190 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
14192 Set_Has_Pragma_Unreferenced
14195 (Library_Unit (Citem))));
14197 (Get_Pragma_Arg (Arg_Node), Name (Citem));
14206 ("argument of pragma% is not withed unit", Arg_Node);
14212 -- Case of not in list of context items
14216 while Present (Arg_Node) loop
14217 Check_No_Identifier (Arg_Node);
14219 -- Note: the analyze call done by Check_Arg_Is_Local_Name
14220 -- will in fact generate reference, so that the entity will
14221 -- have a reference, which will inhibit any warnings about
14222 -- it not being referenced, and also properly show up in the
14223 -- ali file as a reference. But this reference is recorded
14224 -- before the Has_Pragma_Unreferenced flag is set, so that
14225 -- no warning is generated for this reference.
14227 Check_Arg_Is_Local_Name (Arg_Node);
14228 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14230 if Is_Entity_Name (Arg_Expr) then
14231 Arg_Ent := Entity (Arg_Expr);
14233 -- If the entity is overloaded, the pragma applies to the
14234 -- most recent overloading, as documented. In this case,
14235 -- name resolution does not generate a reference, so it
14236 -- must be done here explicitly.
14238 if Is_Overloaded (Arg_Expr) then
14239 Generate_Reference (Arg_Ent, N);
14242 Set_Has_Pragma_Unreferenced (Arg_Ent);
14250 --------------------------
14251 -- Unreferenced_Objects --
14252 --------------------------
14254 -- pragma Unreferenced_Objects (local_Name {, local_Name});
14256 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
14257 Arg_Node : Node_Id;
14258 Arg_Expr : Node_Id;
14262 Check_At_Least_N_Arguments (1);
14265 while Present (Arg_Node) loop
14266 Check_No_Identifier (Arg_Node);
14267 Check_Arg_Is_Local_Name (Arg_Node);
14268 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14270 if not Is_Entity_Name (Arg_Expr)
14271 or else not Is_Type (Entity (Arg_Expr))
14274 ("argument for pragma% must be type or subtype", Arg_Node);
14277 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
14280 end Unreferenced_Objects;
14282 ------------------------------
14283 -- Unreserve_All_Interrupts --
14284 ------------------------------
14286 -- pragma Unreserve_All_Interrupts;
14288 when Pragma_Unreserve_All_Interrupts =>
14290 Check_Arg_Count (0);
14292 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
14293 Unreserve_All_Interrupts := True;
14300 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
14302 when Pragma_Unsuppress =>
14304 Process_Suppress_Unsuppress (False);
14306 -------------------
14307 -- Use_VADS_Size --
14308 -------------------
14310 -- pragma Use_VADS_Size;
14312 when Pragma_Use_VADS_Size =>
14314 Check_Arg_Count (0);
14315 Check_Valid_Configuration_Pragma;
14316 Use_VADS_Size := True;
14318 ---------------------
14319 -- Validity_Checks --
14320 ---------------------
14322 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14324 when Pragma_Validity_Checks => Validity_Checks : declare
14325 A : constant Node_Id := Get_Pragma_Arg (Arg1);
14331 Check_Arg_Count (1);
14332 Check_No_Identifiers;
14334 if Nkind (A) = N_String_Literal then
14338 Slen : constant Natural := Natural (String_Length (S));
14339 Options : String (1 .. Slen);
14345 C := Get_String_Char (S, Int (J));
14346 exit when not In_Character_Range (C);
14347 Options (J) := Get_Character (C);
14350 Set_Validity_Check_Options (Options);
14358 elsif Nkind (A) = N_Identifier then
14359 if Chars (A) = Name_All_Checks then
14360 Set_Validity_Check_Options ("a");
14361 elsif Chars (A) = Name_On then
14362 Validity_Checks_On := True;
14363 elsif Chars (A) = Name_Off then
14364 Validity_Checks_On := False;
14367 end Validity_Checks;
14373 -- pragma Volatile (LOCAL_NAME);
14375 when Pragma_Volatile =>
14376 Process_Atomic_Shared_Volatile;
14378 -------------------------
14379 -- Volatile_Components --
14380 -------------------------
14382 -- pragma Volatile_Components (array_LOCAL_NAME);
14384 -- Volatile is handled by the same circuit as Atomic_Components
14390 -- pragma Warnings (On | Off);
14391 -- pragma Warnings (On | Off, LOCAL_NAME);
14392 -- pragma Warnings (static_string_EXPRESSION);
14393 -- pragma Warnings (On | Off, STRING_LITERAL);
14395 when Pragma_Warnings => Warnings : begin
14397 Check_At_Least_N_Arguments (1);
14398 Check_No_Identifiers;
14400 -- If debug flag -gnatd.i is set, pragma is ignored
14402 if Debug_Flag_Dot_I then
14406 -- Process various forms of the pragma
14409 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14412 -- One argument case
14414 if Arg_Count = 1 then
14416 -- On/Off one argument case was processed by parser
14418 if Nkind (Argx) = N_Identifier
14420 (Chars (Argx) = Name_On
14422 Chars (Argx) = Name_Off)
14426 -- One argument case must be ON/OFF or static string expr
14428 elsif not Is_Static_String_Expression (Arg1) then
14430 ("argument of pragma% must be On/Off or " &
14431 "static string expression", Arg1);
14433 -- One argument string expression case
14437 Lit : constant Node_Id := Expr_Value_S (Argx);
14438 Str : constant String_Id := Strval (Lit);
14439 Len : constant Nat := String_Length (Str);
14447 while J <= Len loop
14448 C := Get_String_Char (Str, J);
14449 OK := In_Character_Range (C);
14452 Chr := Get_Character (C);
14456 if J < Len and then Chr = '.' then
14458 C := Get_String_Char (Str, J);
14459 Chr := Get_Character (C);
14461 if not Set_Dot_Warning_Switch (Chr) then
14463 ("invalid warning switch character " &
14470 OK := Set_Warning_Switch (Chr);
14476 ("invalid warning switch character " & Chr,
14485 -- Two or more arguments (must be two)
14488 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14489 Check_At_Most_N_Arguments (2);
14497 E_Id := Get_Pragma_Arg (Arg2);
14500 -- In the expansion of an inlined body, a reference to
14501 -- the formal may be wrapped in a conversion if the
14502 -- actual is a conversion. Retrieve the real entity name.
14504 if (In_Instance_Body or 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 -- Note: We set Used if we are inside a generic to
14569 -- disable the test that the non-config case actually
14570 -- cancels a warning. That's because we can't be sure
14571 -- there isn't an instantiation in some other unit
14572 -- where a warning is suppressed.
14574 -- We could do a little better here by checking if the
14575 -- generic unit we are inside is public, but for now
14576 -- we don't bother with that refinement.
14578 if Chars (Argx) = Name_Off then
14579 Set_Specific_Warning_Off
14580 (Loc, Name_Buffer (1 .. Name_Len),
14581 Config => Is_Configuration_Pragma,
14582 Used => Inside_A_Generic or else In_Instance);
14584 elsif Chars (Argx) = Name_On then
14585 Set_Specific_Warning_On
14586 (Loc, Name_Buffer (1 .. Name_Len), Err);
14590 ("?pragma Warnings On with no " &
14591 "matching Warnings Off",
14601 -------------------
14602 -- Weak_External --
14603 -------------------
14605 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
14607 when Pragma_Weak_External => Weak_External : declare
14612 Check_Arg_Count (1);
14613 Check_Optional_Identifier (Arg1, Name_Entity);
14614 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14615 Ent := Entity (Get_Pragma_Arg (Arg1));
14617 if Rep_Item_Too_Early (Ent, N) then
14620 Ent := Underlying_Type (Ent);
14623 -- The only processing required is to link this item on to the
14624 -- list of rep items for the given entity. This is accomplished
14625 -- by the call to Rep_Item_Too_Late (when no error is detected
14626 -- and False is returned).
14628 if Rep_Item_Too_Late (Ent, N) then
14631 Set_Has_Gigi_Rep_Item (Ent);
14635 -----------------------------
14636 -- Wide_Character_Encoding --
14637 -----------------------------
14639 -- pragma Wide_Character_Encoding (IDENTIFIER);
14641 when Pragma_Wide_Character_Encoding =>
14644 -- Nothing to do, handled in parser. Note that we do not enforce
14645 -- configuration pragma placement, this pragma can appear at any
14646 -- place in the source, allowing mixed encodings within a single
14651 --------------------
14652 -- Unknown_Pragma --
14653 --------------------
14655 -- Should be impossible, since the case of an unknown pragma is
14656 -- separately processed before the case statement is entered.
14658 when Unknown_Pragma =>
14659 raise Program_Error;
14662 -- AI05-0144: detect dangerous order dependence. Disabled for now,
14663 -- until AI is formally approved.
14665 -- Check_Order_Dependence;
14668 when Pragma_Exit => null;
14669 end Analyze_Pragma;
14671 -----------------------------
14672 -- Analyze_TC_In_Decl_Part --
14673 -----------------------------
14675 procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14677 -- Install formals and push subprogram spec onto scope stack so that we
14678 -- can see the formals from the pragma.
14680 Install_Formals (S);
14683 -- Preanalyze the boolean expressions, we treat these as spec
14684 -- expressions (i.e. similar to a default expression).
14686 Preanalyze_TC_Args (N,
14687 Get_Requires_From_Test_Case_Pragma (N),
14688 Get_Ensures_From_Test_Case_Pragma (N));
14690 -- Remove the subprogram from the scope stack now that the pre-analysis
14691 -- of the expressions in the test-case is done.
14694 end Analyze_TC_In_Decl_Part;
14696 --------------------
14697 -- Check_Disabled --
14698 --------------------
14700 function Check_Disabled (Nam : Name_Id) return Boolean is
14704 -- Loop through entries in check policy list
14706 PP := Opt.Check_Policy_List;
14708 -- If there are no specific entries that matched, then nothing is
14709 -- disabled, so return False.
14714 -- Here we have an entry see if it matches
14718 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14720 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14721 return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14723 PP := Next_Pragma (PP);
14728 end Check_Disabled;
14730 -------------------
14731 -- Check_Enabled --
14732 -------------------
14734 function Check_Enabled (Nam : Name_Id) return Boolean is
14738 -- Loop through entries in check policy list
14740 PP := Opt.Check_Policy_List;
14742 -- If there are no specific entries that matched, then we let the
14743 -- setting of assertions govern. Note that this provides the needed
14744 -- compatibility with the RM for the cases of assertion, invariant,
14745 -- precondition, predicate, and postcondition.
14748 return Assertions_Enabled;
14750 -- Here we have an entry see if it matches
14754 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14757 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14758 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14759 when Name_On | Name_Check =>
14761 when Name_Off | Name_Ignore =>
14764 raise Program_Error;
14768 PP := Next_Pragma (PP);
14775 ---------------------------------
14776 -- Delay_Config_Pragma_Analyze --
14777 ---------------------------------
14779 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14781 return Pragma_Name (N) = Name_Interrupt_State
14783 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14784 end Delay_Config_Pragma_Analyze;
14786 -------------------------
14787 -- Get_Base_Subprogram --
14788 -------------------------
14790 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14791 Result : Entity_Id;
14794 -- Follow subprogram renaming chain
14797 while Is_Subprogram (Result)
14799 Nkind (Parent (Declaration_Node (Result))) =
14800 N_Subprogram_Renaming_Declaration
14801 and then Present (Alias (Result))
14803 Result := Alias (Result);
14807 end Get_Base_Subprogram;
14813 procedure Initialize is
14818 -----------------------------
14819 -- Is_Config_Static_String --
14820 -----------------------------
14822 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14824 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14825 -- This is an internal recursive function that is just like the outer
14826 -- function except that it adds the string to the name buffer rather
14827 -- than placing the string in the name buffer.
14829 ------------------------------
14830 -- Add_Config_Static_String --
14831 ------------------------------
14833 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14840 if Nkind (N) = N_Op_Concat then
14841 if Add_Config_Static_String (Left_Opnd (N)) then
14842 N := Right_Opnd (N);
14848 if Nkind (N) /= N_String_Literal then
14849 Error_Msg_N ("string literal expected for pragma argument", N);
14853 for J in 1 .. String_Length (Strval (N)) loop
14854 C := Get_String_Char (Strval (N), J);
14856 if not In_Character_Range (C) then
14858 ("string literal contains invalid wide character",
14859 Sloc (N) + 1 + Source_Ptr (J));
14863 Add_Char_To_Name_Buffer (Get_Character (C));
14868 end Add_Config_Static_String;
14870 -- Start of processing for Is_Config_Static_String
14875 return Add_Config_Static_String (Arg);
14876 end Is_Config_Static_String;
14878 -----------------------------------------
14879 -- Is_Non_Significant_Pragma_Reference --
14880 -----------------------------------------
14882 -- This function makes use of the following static table which indicates
14883 -- whether appearance of some name in a given pragma is to be considered
14884 -- as a reference for the purposes of warnings about unreferenced objects.
14886 -- -1 indicates that references in any argument position are significant
14887 -- 0 indicates that appearance in any argument is not significant
14888 -- +n indicates that appearance as argument n is significant, but all
14889 -- other arguments are not significant
14890 -- 99 special processing required (e.g. for pragma Check)
14892 Sig_Flags : constant array (Pragma_Id) of Int :=
14893 (Pragma_AST_Entry => -1,
14894 Pragma_Abort_Defer => -1,
14895 Pragma_Ada_83 => -1,
14896 Pragma_Ada_95 => -1,
14897 Pragma_Ada_05 => -1,
14898 Pragma_Ada_2005 => -1,
14899 Pragma_Ada_12 => -1,
14900 Pragma_Ada_2012 => -1,
14901 Pragma_All_Calls_Remote => -1,
14902 Pragma_Annotate => -1,
14903 Pragma_Assert => -1,
14904 Pragma_Assertion_Policy => 0,
14905 Pragma_Assume_No_Invalid_Values => 0,
14906 Pragma_Asynchronous => -1,
14907 Pragma_Atomic => 0,
14908 Pragma_Atomic_Components => 0,
14909 Pragma_Attach_Handler => -1,
14910 Pragma_Check => 99,
14911 Pragma_Check_Name => 0,
14912 Pragma_Check_Policy => 0,
14913 Pragma_CIL_Constructor => -1,
14914 Pragma_CPP_Class => 0,
14915 Pragma_CPP_Constructor => 0,
14916 Pragma_CPP_Virtual => 0,
14917 Pragma_CPP_Vtable => 0,
14919 Pragma_C_Pass_By_Copy => 0,
14920 Pragma_Comment => 0,
14921 Pragma_Common_Object => -1,
14922 Pragma_Compile_Time_Error => -1,
14923 Pragma_Compile_Time_Warning => -1,
14924 Pragma_Compiler_Unit => 0,
14925 Pragma_Complete_Representation => 0,
14926 Pragma_Complex_Representation => 0,
14927 Pragma_Component_Alignment => -1,
14928 Pragma_Controlled => 0,
14929 Pragma_Convention => 0,
14930 Pragma_Convention_Identifier => 0,
14931 Pragma_Debug => -1,
14932 Pragma_Debug_Policy => 0,
14933 Pragma_Detect_Blocking => -1,
14934 Pragma_Default_Storage_Pool => -1,
14935 Pragma_Disable_Atomic_Synchronization => -1,
14936 Pragma_Discard_Names => 0,
14937 Pragma_Dispatching_Domain => -1,
14938 Pragma_Elaborate => -1,
14939 Pragma_Elaborate_All => -1,
14940 Pragma_Elaborate_Body => -1,
14941 Pragma_Elaboration_Checks => -1,
14942 Pragma_Eliminate => -1,
14943 Pragma_Enable_Atomic_Synchronization => -1,
14944 Pragma_Export => -1,
14945 Pragma_Export_Exception => -1,
14946 Pragma_Export_Function => -1,
14947 Pragma_Export_Object => -1,
14948 Pragma_Export_Procedure => -1,
14949 Pragma_Export_Value => -1,
14950 Pragma_Export_Valued_Procedure => -1,
14951 Pragma_Extend_System => -1,
14952 Pragma_Extensions_Allowed => -1,
14953 Pragma_External => -1,
14954 Pragma_Favor_Top_Level => -1,
14955 Pragma_External_Name_Casing => -1,
14956 Pragma_Fast_Math => -1,
14957 Pragma_Finalize_Storage_Only => 0,
14958 Pragma_Float_Representation => 0,
14959 Pragma_Ident => -1,
14960 Pragma_Implementation_Defined => -1,
14961 Pragma_Implemented => -1,
14962 Pragma_Implicit_Packing => 0,
14963 Pragma_Import => +2,
14964 Pragma_Import_Exception => 0,
14965 Pragma_Import_Function => 0,
14966 Pragma_Import_Object => 0,
14967 Pragma_Import_Procedure => 0,
14968 Pragma_Import_Valued_Procedure => 0,
14969 Pragma_Independent => 0,
14970 Pragma_Independent_Components => 0,
14971 Pragma_Initialize_Scalars => -1,
14972 Pragma_Inline => 0,
14973 Pragma_Inline_Always => 0,
14974 Pragma_Inline_Generic => 0,
14975 Pragma_Inspection_Point => -1,
14976 Pragma_Interface => +2,
14977 Pragma_Interface_Name => +2,
14978 Pragma_Interrupt_Handler => -1,
14979 Pragma_Interrupt_Priority => -1,
14980 Pragma_Interrupt_State => -1,
14981 Pragma_Invariant => -1,
14982 Pragma_Java_Constructor => -1,
14983 Pragma_Java_Interface => -1,
14984 Pragma_Keep_Names => 0,
14985 Pragma_License => -1,
14986 Pragma_Link_With => -1,
14987 Pragma_Linker_Alias => -1,
14988 Pragma_Linker_Constructor => -1,
14989 Pragma_Linker_Destructor => -1,
14990 Pragma_Linker_Options => -1,
14991 Pragma_Linker_Section => -1,
14993 Pragma_Locking_Policy => -1,
14994 Pragma_Long_Float => -1,
14995 Pragma_Machine_Attribute => -1,
14997 Pragma_Main_Storage => -1,
14998 Pragma_Memory_Size => -1,
14999 Pragma_No_Return => 0,
15000 Pragma_No_Body => 0,
15001 Pragma_No_Run_Time => -1,
15002 Pragma_No_Strict_Aliasing => -1,
15003 Pragma_Normalize_Scalars => -1,
15004 Pragma_Obsolescent => 0,
15005 Pragma_Optimize => -1,
15006 Pragma_Optimize_Alignment => -1,
15007 Pragma_Ordered => 0,
15010 Pragma_Passive => -1,
15011 Pragma_Preelaborable_Initialization => -1,
15012 Pragma_Polling => -1,
15013 Pragma_Persistent_BSS => 0,
15014 Pragma_Postcondition => -1,
15015 Pragma_Precondition => -1,
15016 Pragma_Predicate => -1,
15017 Pragma_Preelaborate => -1,
15018 Pragma_Preelaborate_05 => -1,
15019 Pragma_Priority => -1,
15020 Pragma_Priority_Specific_Dispatching => -1,
15021 Pragma_Profile => 0,
15022 Pragma_Profile_Warnings => 0,
15023 Pragma_Propagate_Exceptions => -1,
15024 Pragma_Psect_Object => -1,
15026 Pragma_Pure_05 => -1,
15027 Pragma_Pure_12 => -1,
15028 Pragma_Pure_Function => -1,
15029 Pragma_Queuing_Policy => -1,
15030 Pragma_Ravenscar => -1,
15031 Pragma_Relative_Deadline => -1,
15032 Pragma_Remote_Call_Interface => -1,
15033 Pragma_Remote_Types => -1,
15034 Pragma_Restricted_Run_Time => -1,
15035 Pragma_Restriction_Warnings => -1,
15036 Pragma_Restrictions => -1,
15037 Pragma_Reviewable => -1,
15038 Pragma_Short_Circuit_And_Or => -1,
15039 Pragma_Share_Generic => -1,
15040 Pragma_Shared => -1,
15041 Pragma_Shared_Passive => -1,
15042 Pragma_Short_Descriptors => 0,
15043 Pragma_Source_File_Name => -1,
15044 Pragma_Source_File_Name_Project => -1,
15045 Pragma_Source_Reference => -1,
15046 Pragma_Storage_Size => -1,
15047 Pragma_Storage_Unit => -1,
15048 Pragma_Static_Elaboration_Desired => -1,
15049 Pragma_Stream_Convert => -1,
15050 Pragma_Style_Checks => -1,
15051 Pragma_Subtitle => -1,
15052 Pragma_Suppress => 0,
15053 Pragma_Suppress_Exception_Locations => 0,
15054 Pragma_Suppress_All => -1,
15055 Pragma_Suppress_Debug_Info => 0,
15056 Pragma_Suppress_Initialization => 0,
15057 Pragma_System_Name => -1,
15058 Pragma_Task_Dispatching_Policy => -1,
15059 Pragma_Task_Info => -1,
15060 Pragma_Task_Name => -1,
15061 Pragma_Task_Storage => 0,
15062 Pragma_Test_Case => -1,
15063 Pragma_Thread_Local_Storage => 0,
15064 Pragma_Time_Slice => -1,
15065 Pragma_Title => -1,
15066 Pragma_Unchecked_Union => 0,
15067 Pragma_Unimplemented_Unit => -1,
15068 Pragma_Universal_Aliasing => -1,
15069 Pragma_Universal_Data => -1,
15070 Pragma_Unmodified => -1,
15071 Pragma_Unreferenced => -1,
15072 Pragma_Unreferenced_Objects => -1,
15073 Pragma_Unreserve_All_Interrupts => -1,
15074 Pragma_Unsuppress => 0,
15075 Pragma_Use_VADS_Size => -1,
15076 Pragma_Validity_Checks => -1,
15077 Pragma_Volatile => 0,
15078 Pragma_Volatile_Components => 0,
15079 Pragma_Warnings => -1,
15080 Pragma_Weak_External => -1,
15081 Pragma_Wide_Character_Encoding => 0,
15082 Unknown_Pragma => 0);
15084 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
15093 if Nkind (P) /= N_Pragma_Argument_Association then
15097 Id := Get_Pragma_Id (Parent (P));
15098 C := Sig_Flags (Id);
15110 -- For pragma Check, the first argument is not significant,
15111 -- the second and the third (if present) arguments are
15114 when Pragma_Check =>
15116 P = First (Pragma_Argument_Associations (Parent (P)));
15119 raise Program_Error;
15123 A := First (Pragma_Argument_Associations (Parent (P)));
15124 for J in 1 .. C - 1 loop
15132 return A = P; -- is this wrong way round ???
15135 end Is_Non_Significant_Pragma_Reference;
15137 ------------------------------
15138 -- Is_Pragma_String_Literal --
15139 ------------------------------
15141 -- This function returns true if the corresponding pragma argument is a
15142 -- static string expression. These are the only cases in which string
15143 -- literals can appear as pragma arguments. We also allow a string literal
15144 -- as the first argument to pragma Assert (although it will of course
15145 -- always generate a type error).
15147 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
15148 Pragn : constant Node_Id := Parent (Par);
15149 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
15150 Pname : constant Name_Id := Pragma_Name (Pragn);
15156 N := First (Assoc);
15163 if Pname = Name_Assert then
15166 elsif Pname = Name_Export then
15169 elsif Pname = Name_Ident then
15172 elsif Pname = Name_Import then
15175 elsif Pname = Name_Interface_Name then
15178 elsif Pname = Name_Linker_Alias then
15181 elsif Pname = Name_Linker_Section then
15184 elsif Pname = Name_Machine_Attribute then
15187 elsif Pname = Name_Source_File_Name then
15190 elsif Pname = Name_Source_Reference then
15193 elsif Pname = Name_Title then
15196 elsif Pname = Name_Subtitle then
15202 end Is_Pragma_String_Literal;
15204 ------------------------
15205 -- Preanalyze_TC_Args --
15206 ------------------------
15208 procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
15210 -- Preanalyze the boolean expressions, we treat these as spec
15211 -- expressions (i.e. similar to a default expression).
15213 if Present (Arg_Req) then
15214 Preanalyze_Spec_Expression
15215 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
15217 -- In ASIS mode, for a pragma generated from a source aspect, also
15218 -- analyze the original aspect expression.
15221 and then Present (Corresponding_Aspect (N))
15223 Preanalyze_Spec_Expression
15224 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
15228 if Present (Arg_Ens) then
15229 Preanalyze_Spec_Expression
15230 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
15232 -- In ASIS mode, for a pragma generated from a source aspect, also
15233 -- analyze the original aspect expression.
15236 and then Present (Corresponding_Aspect (N))
15238 Preanalyze_Spec_Expression
15239 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
15242 end Preanalyze_TC_Args;
15244 --------------------------------------
15245 -- Process_Compilation_Unit_Pragmas --
15246 --------------------------------------
15248 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
15250 -- A special check for pragma Suppress_All, a very strange DEC pragma,
15251 -- strange because it comes at the end of the unit. Rational has the
15252 -- same name for a pragma, but treats it as a program unit pragma, In
15253 -- GNAT we just decide to allow it anywhere at all. If it appeared then
15254 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
15255 -- node, and we insert a pragma Suppress (All_Checks) at the start of
15256 -- the context clause to ensure the correct processing.
15258 if Has_Pragma_Suppress_All (N) then
15259 Prepend_To (Context_Items (N),
15260 Make_Pragma (Sloc (N),
15261 Chars => Name_Suppress,
15262 Pragma_Argument_Associations => New_List (
15263 Make_Pragma_Argument_Association (Sloc (N),
15264 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
15267 -- Nothing else to do at the current time!
15269 end Process_Compilation_Unit_Pragmas;
15280 --------------------------------
15281 -- Set_Encoded_Interface_Name --
15282 --------------------------------
15284 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
15285 Str : constant String_Id := Strval (S);
15286 Len : constant Int := String_Length (Str);
15291 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
15294 -- Stores encoded value of character code CC. The encoding we use an
15295 -- underscore followed by four lower case hex digits.
15301 procedure Encode is
15303 Store_String_Char (Get_Char_Code ('_'));
15305 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
15307 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
15309 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
15311 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
15314 -- Start of processing for Set_Encoded_Interface_Name
15317 -- If first character is asterisk, this is a link name, and we leave it
15318 -- completely unmodified. We also ignore null strings (the latter case
15319 -- happens only in error cases) and no encoding should occur for Java or
15320 -- AAMP interface names.
15323 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
15324 or else VM_Target /= No_VM
15325 or else AAMP_On_Target
15327 Set_Interface_Name (E, S);
15332 CC := Get_String_Char (Str, J);
15334 exit when not In_Character_Range (CC);
15336 C := Get_Character (CC);
15338 exit when C /= '_' and then C /= '$'
15339 and then C not in '0' .. '9'
15340 and then C not in 'a' .. 'z'
15341 and then C not in 'A' .. 'Z';
15344 Set_Interface_Name (E, S);
15352 -- Here we need to encode. The encoding we use as follows:
15353 -- three underscores + four hex digits (lower case)
15357 for J in 1 .. String_Length (Str) loop
15358 CC := Get_String_Char (Str, J);
15360 if not In_Character_Range (CC) then
15363 C := Get_Character (CC);
15365 if C = '_' or else C = '$'
15366 or else C in '0' .. '9'
15367 or else C in 'a' .. 'z'
15368 or else C in 'A' .. 'Z'
15370 Store_String_Char (CC);
15377 Set_Interface_Name (E,
15378 Make_String_Literal (Sloc (S),
15379 Strval => End_String));
15381 end Set_Encoded_Interface_Name;
15383 -------------------
15384 -- Set_Unit_Name --
15385 -------------------
15387 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15392 if Nkind (N) = N_Identifier
15393 and then Nkind (With_Item) = N_Identifier
15395 Set_Entity (N, Entity (With_Item));
15397 elsif Nkind (N) = N_Selected_Component then
15398 Change_Selected_Component_To_Expanded_Name (N);
15399 Set_Entity (N, Entity (With_Item));
15400 Set_Entity (Selector_Name (N), Entity (N));
15402 Pref := Prefix (N);
15403 Scop := Scope (Entity (N));
15404 while Nkind (Pref) = N_Selected_Component loop
15405 Change_Selected_Component_To_Expanded_Name (Pref);
15406 Set_Entity (Selector_Name (Pref), Scop);
15407 Set_Entity (Pref, Scop);
15408 Pref := Prefix (Pref);
15409 Scop := Scope (Scop);
15412 Set_Entity (Pref, Scop);