1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Aspects; use Aspects;
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Checks; use Checks;
36 with Csets; use Csets;
37 with Debug; use Debug;
38 with Einfo; use Einfo;
39 with Elists; use Elists;
40 with Errout; use Errout;
41 with Exp_Dist; use Exp_Dist;
42 with Exp_Util; use Exp_Util;
43 with Freeze; use Freeze;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet.Sp; use Namet.Sp;
48 with Nlists; use Nlists;
49 with Nmake; use Nmake;
51 with Output; use Output;
52 with Par_SCO; use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident; use Rident;
55 with Rtsfind; use Rtsfind;
57 with Sem_Aux; use Sem_Aux;
58 with Sem_Ch3; use Sem_Ch3;
59 with Sem_Ch6; use Sem_Ch6;
60 with Sem_Ch8; use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res; use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_VFpt; use Sem_VFpt;
73 with Sem_Warn; use Sem_Warn;
74 with Stand; use Stand;
75 with Sinfo; use Sinfo;
76 with Sinfo.CN; use Sinfo.CN;
77 with Sinput; use Sinput;
78 with Snames; use Snames;
79 with Stringt; use Stringt;
80 with Stylesw; use Stylesw;
82 with Targparm; use Targparm;
83 with Tbuild; use Tbuild;
85 with Uintp; use Uintp;
86 with Uname; use Uname;
87 with Urealp; use Urealp;
88 with Validsw; use Validsw;
89 with Warnsw; use Warnsw;
91 package body Sem_Prag is
93 ----------------------------------------------
94 -- Common Handling of Import-Export Pragmas --
95 ----------------------------------------------
97 -- In the following section, a number of Import_xxx and Export_xxx pragmas
98 -- are defined by GNAT. These are compatible with the DEC pragmas of the
99 -- same name, and all have the following common form and processing:
102 -- [Internal =>] LOCAL_NAME
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
107 -- [Internal =>] LOCAL_NAME
108 -- [, [External =>] EXTERNAL_SYMBOL]
109 -- [, other optional parameters ]);
111 -- EXTERNAL_SYMBOL ::=
113 -- | static_string_EXPRESSION
115 -- The internal LOCAL_NAME designates the entity that is imported or
116 -- exported, and must refer to an entity in the current declarative
117 -- part (as required by the rules for LOCAL_NAME).
119 -- The external linker name is designated by the External parameter if
120 -- given, or the Internal parameter if not (if there is no External
121 -- parameter, the External parameter is a copy of the Internal name).
123 -- If the External parameter is given as a string, then this string is
124 -- treated as an external name (exactly as though it had been given as an
125 -- External_Name parameter for a normal Import pragma).
127 -- If the External parameter is given as an identifier (or there is no
128 -- External parameter, so that the Internal identifier is used), then
129 -- the external name is the characters of the identifier, translated
130 -- to all upper case letters for OpenVMS versions of GNAT, and to all
131 -- lower case letters for all other versions
133 -- Note: the external name specified or implied by any of these special
134 -- Import_xxx or Export_xxx pragmas override an external or link name
135 -- specified in a previous Import or Export pragma.
137 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
138 -- named notation, following the standard rules for subprogram calls, i.e.
139 -- parameters can be given in any order if named notation is used, and
140 -- positional and named notation can be mixed, subject to the rule that all
141 -- positional parameters must appear first.
143 -- Note: All these pragmas are implemented exactly following the DEC design
144 -- and implementation and are intended to be fully compatible with the use
145 -- of these pragmas in the DEC Ada compiler.
147 --------------------------------------------
148 -- Checking for Duplicated External Names --
149 --------------------------------------------
151 -- It is suspicious if two separate Export pragmas use the same external
152 -- name. The following table is used to diagnose this situation so that
153 -- an appropriate warning can be issued.
155 -- The Node_Id stored is for the N_String_Literal node created to hold
156 -- the value of the external name. The Sloc of this node is used to
157 -- cross-reference the location of the duplication.
159 package Externals is new Table.Table (
160 Table_Component_Type => Node_Id,
161 Table_Index_Type => Int,
162 Table_Low_Bound => 0,
163 Table_Initial => 100,
164 Table_Increment => 100,
165 Table_Name => "Name_Externals");
167 -------------------------------------
168 -- Local Subprograms and Variables --
169 -------------------------------------
171 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
172 -- This routine is used for possible casing adjustment of an explicit
173 -- external name supplied as a string literal (the node N), according to
174 -- the casing requirement of Opt.External_Name_Casing. If this is set to
175 -- As_Is, then the string literal is returned unchanged, but if it is set
176 -- to Uppercase or Lowercase, then a new string literal with appropriate
177 -- casing is constructed.
179 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
180 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
181 -- original one, following the renaming chain) is returned. Otherwise the
182 -- entity is returned unchanged. Should be in Einfo???
184 procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id);
185 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
186 -- of a Test_Case pragma if present (possibly Empty). We treat these as
187 -- spec expressions (i.e. similar to a default expression).
190 -- This is a dummy function called by the processing for pragma Reviewable.
191 -- It is there for assisting front end debugging. By placing a Reviewable
192 -- pragma in the source program, a breakpoint on rv catches this place in
193 -- the source, allowing convenient stepping to the point of interest.
195 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
196 -- Place semantic information on the argument of an Elaborate/Elaborate_All
197 -- pragma. Entity name for unit and its parents is taken from item in
198 -- previous with_clause that mentions the unit.
200 -------------------------------
201 -- Adjust_External_Name_Case --
202 -------------------------------
204 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
208 -- Adjust case of literal if required
210 if Opt.External_Name_Exp_Casing = As_Is then
214 -- Copy existing string
220 for J in 1 .. String_Length (Strval (N)) loop
221 CC := Get_String_Char (Strval (N), J);
223 if Opt.External_Name_Exp_Casing = Uppercase
224 and then CC >= Get_Char_Code ('a')
225 and then CC <= Get_Char_Code ('z')
227 Store_String_Char (CC - 32);
229 elsif Opt.External_Name_Exp_Casing = Lowercase
230 and then CC >= Get_Char_Code ('A')
231 and then CC <= Get_Char_Code ('Z')
233 Store_String_Char (CC + 32);
236 Store_String_Char (CC);
241 Make_String_Literal (Sloc (N),
242 Strval => End_String);
244 end Adjust_External_Name_Case;
246 ------------------------------
247 -- Analyze_PPC_In_Decl_Part --
248 ------------------------------
250 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
251 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
254 -- Install formals and push subprogram spec onto scope stack so that we
255 -- can see the formals from the pragma.
260 -- Preanalyze the boolean expression, we treat this as a spec expression
261 -- (i.e. similar to a default expression).
263 Preanalyze_Spec_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
265 -- In ASIS mode, for a pragma generated from a source aspect, also
266 -- analyze the original aspect expression.
269 and then Present (Corresponding_Aspect (N))
271 Preanalyze_Spec_Expression
272 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
275 -- For a class-wide condition, a reference to a controlling formal must
276 -- be interpreted as having the class-wide type (or an access to such)
277 -- so that the inherited condition can be properly applied to any
278 -- overriding operation (see ARM12 6.6.1 (7)).
280 if Class_Present (N) then
282 T : constant Entity_Id := Find_Dispatching_Type (S);
284 ACW : Entity_Id := Empty;
285 -- Access to T'class, created if there is a controlling formal
286 -- that is an access parameter.
288 function Get_ACW return Entity_Id;
289 -- If the expression has a reference to an controlling access
290 -- parameter, create an access to T'class for the necessary
291 -- conversions if one does not exist.
293 function Process (N : Node_Id) return Traverse_Result;
294 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
295 -- aspect for a primitive subprogram of a tagged type T, a name
296 -- that denotes a formal parameter of type T is interpreted as
297 -- having type T'Class. Similarly, a name that denotes a formal
298 -- accessparameter of type access-to-T is interpreted as having
299 -- type access-to-T'Class. This ensures the expression is well-
300 -- defined for a primitive subprogram of a type descended from T.
306 function Get_ACW return Entity_Id is
307 Loc : constant Source_Ptr := Sloc (N);
312 Decl := Make_Full_Type_Declaration (Loc,
313 Defining_Identifier => Make_Temporary (Loc, 'T'),
315 Make_Access_To_Object_Definition (Loc,
316 Subtype_Indication =>
317 New_Occurrence_Of (Class_Wide_Type (T), Loc),
318 All_Present => True));
320 Insert_Before (Unit_Declaration_Node (S), Decl);
322 ACW := Defining_Identifier (Decl);
323 Freeze_Before (Unit_Declaration_Node (S), ACW);
333 function Process (N : Node_Id) return Traverse_Result is
334 Loc : constant Source_Ptr := Sloc (N);
338 if Is_Entity_Name (N)
339 and then Is_Formal (Entity (N))
340 and then Nkind (Parent (N)) /= N_Type_Conversion
342 if Etype (Entity (N)) = T then
343 Typ := Class_Wide_Type (T);
345 elsif Is_Access_Type (Etype (Entity (N)))
346 and then Designated_Type (Etype (Entity (N))) = T
353 if Present (Typ) then
355 Make_Type_Conversion (Loc,
357 New_Occurrence_Of (Typ, Loc),
358 Expression => New_Occurrence_Of (Entity (N), Loc)));
366 procedure Replace_Type is new Traverse_Proc (Process);
369 Replace_Type (Get_Pragma_Arg (Arg1));
373 -- Remove the subprogram from the scope stack now that the pre-analysis
374 -- of the precondition/postcondition is done.
377 end Analyze_PPC_In_Decl_Part;
383 procedure Analyze_Pragma (N : Node_Id) is
384 Loc : constant Source_Ptr := Sloc (N);
388 -- Name of the source pragma, or name of the corresponding aspect for
389 -- pragmas which originate in a source aspect. In the latter case, the
390 -- name may be different from the pragma name.
392 Pragma_Exit : exception;
393 -- This exception is used to exit pragma processing completely. It is
394 -- used when an error is detected, and no further processing is
395 -- required. It is also used if an earlier error has left the tree in
396 -- a state where the pragma should not be processed.
399 -- Number of pragma argument associations
405 -- First four pragma arguments (pragma argument association nodes, or
406 -- Empty if the corresponding argument does not exist).
408 type Name_List is array (Natural range <>) of Name_Id;
409 type Args_List is array (Natural range <>) of Node_Id;
410 -- Types used for arguments to Check_Arg_Order and Gather_Associations
412 procedure Ada_2005_Pragma;
413 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
414 -- Ada 95 mode, these are implementation defined pragmas, so should be
415 -- caught by the No_Implementation_Pragmas restriction.
417 procedure Ada_2012_Pragma;
418 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
419 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
420 -- should be caught by the No_Implementation_Pragmas restriction.
422 procedure Check_Ada_83_Warning;
423 -- Issues a warning message for the current pragma if operating in Ada
424 -- 83 mode (used for language pragmas that are not a standard part of
425 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
428 procedure Check_Arg_Count (Required : Nat);
429 -- Check argument count for pragma is equal to given parameter. If not,
430 -- then issue an error message and raise Pragma_Exit.
432 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
433 -- Arg which can either be a pragma argument association, in which case
434 -- the check is applied to the expression of the association or an
435 -- expression directly.
437 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
438 -- Check that an argument has the right form for an EXTERNAL_NAME
439 -- parameter of an extended import/export pragma. The rule is that the
440 -- name must be an identifier or string literal (in Ada 83 mode) or a
441 -- static string expression (in Ada 95 mode).
443 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
444 -- Check the specified argument Arg to make sure that it is an
445 -- identifier. If not give error and raise Pragma_Exit.
447 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
448 -- Check the specified argument Arg to make sure that it is an integer
449 -- literal. If not give error and raise Pragma_Exit.
451 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
452 -- Check the specified argument Arg to make sure that it has the proper
453 -- syntactic form for a local name and meets the semantic requirements
454 -- for a local name. The local name is analyzed as part of the
455 -- processing for this call. In addition, the local name is required
456 -- to represent an entity at the library level.
458 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
459 -- Check the specified argument Arg to make sure that it has the proper
460 -- syntactic form for a local name and meets the semantic requirements
461 -- for a local name. The local name is analyzed as part of the
462 -- processing for this call.
464 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
465 -- Check the specified argument Arg to make sure that it is a valid
466 -- locking policy name. If not give error and raise Pragma_Exit.
468 procedure Check_Arg_Is_One_Of
471 procedure Check_Arg_Is_One_Of
473 N1, N2, N3 : Name_Id);
474 procedure Check_Arg_Is_One_Of
476 N1, N2, N3, N4, N5 : Name_Id);
477 -- Check the specified argument Arg to make sure that it is an
478 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
479 -- present). If not then give error and raise Pragma_Exit.
481 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
482 -- Check the specified argument Arg to make sure that it is a valid
483 -- queuing policy name. If not give error and raise Pragma_Exit.
485 procedure Check_Arg_Is_Static_Expression
487 Typ : Entity_Id := Empty);
488 -- Check the specified argument Arg to make sure that it is a static
489 -- expression of the given type (i.e. it will be analyzed and resolved
490 -- using this type, which can be any valid argument to Resolve, e.g.
491 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
492 -- Typ is left Empty, then any static expression is allowed.
494 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
495 -- Check the specified argument Arg to make sure that it is a valid task
496 -- dispatching policy name. If not give error and raise Pragma_Exit.
498 procedure Check_Arg_Order (Names : Name_List);
499 -- Checks for an instance of two arguments with identifiers for the
500 -- current pragma which are not in the sequence indicated by Names,
501 -- and if so, generates a fatal message about bad order of arguments.
503 procedure Check_At_Least_N_Arguments (N : Nat);
504 -- Check there are at least N arguments present
506 procedure Check_At_Most_N_Arguments (N : Nat);
507 -- Check there are no more than N arguments present
509 procedure Check_Component
512 In_Variant_Part : Boolean := False);
513 -- Examine an Unchecked_Union component for correct use of per-object
514 -- constrained subtypes, and for restrictions on finalizable components.
515 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
516 -- should be set when Comp comes from a record variant.
518 procedure Check_Duplicate_Pragma (E : Entity_Id);
519 -- Check if a pragma of the same name as the current pragma is already
520 -- chained as a rep pragma to the given entity. If so give a message
521 -- about the duplicate, and then raise Pragma_Exit so does not return.
522 -- Also checks for delayed aspect specification node in the chain.
524 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
525 -- Nam is an N_String_Literal node containing the external name set by
526 -- an Import or Export pragma (or extended Import or Export pragma).
527 -- This procedure checks for possible duplications if this is the export
528 -- case, and if found, issues an appropriate error message.
530 procedure Check_Expr_Is_Static_Expression
532 Typ : Entity_Id := Empty);
533 -- Check the specified expression Expr to make sure that it is a static
534 -- expression of the given type (i.e. it will be analyzed and resolved
535 -- using this type, which can be any valid argument to Resolve, e.g.
536 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
537 -- Typ is left Empty, then any static expression is allowed.
539 procedure Check_First_Subtype (Arg : Node_Id);
540 -- Checks that Arg, whose expression is an entity name, references a
543 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
544 -- Checks that the given argument has an identifier, and if so, requires
545 -- it to match the given identifier name. If there is no identifier, or
546 -- a non-matching identifier, then an error message is given and
547 -- Pragma_Exit is raised.
549 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
550 -- Checks that the given argument has an identifier, and if so, requires
551 -- it to match one of the given identifier names. If there is no
552 -- identifier, or a non-matching identifier, then an error message is
553 -- given and Pragma_Exit is raised.
555 procedure Check_In_Main_Program;
556 -- Common checks for pragmas that appear within a main program
557 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
559 procedure Check_Interrupt_Or_Attach_Handler;
560 -- Common processing for first argument of pragma Interrupt_Handler or
561 -- pragma Attach_Handler.
563 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
564 -- Check that pragma appears in a declarative part, or in a package
565 -- specification, i.e. that it does not occur in a statement sequence
568 procedure Check_No_Identifier (Arg : Node_Id);
569 -- Checks that the given argument does not have an identifier. If
570 -- an identifier is present, then an error message is issued, and
571 -- Pragma_Exit is raised.
573 procedure Check_No_Identifiers;
574 -- Checks that none of the arguments to the pragma has an identifier.
575 -- If any argument has an identifier, then an error message is issued,
576 -- and Pragma_Exit is raised.
578 procedure Check_No_Link_Name;
579 -- Checks that no link name is specified
581 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
582 -- Checks if the given argument has an identifier, and if so, requires
583 -- it to match the given identifier name. If there is a non-matching
584 -- identifier, then an error message is given and Pragma_Exit is raised.
586 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
587 -- Checks if the given argument has an identifier, and if so, requires
588 -- it to match the given identifier name. If there is a non-matching
589 -- identifier, then an error message is given and Pragma_Exit is raised.
590 -- In this version of the procedure, the identifier name is given as
591 -- a string with lower case letters.
593 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
594 -- Called to process a precondition or postcondition pragma. There are
597 -- The pragma appears after a subprogram spec
599 -- If the corresponding check is not enabled, the pragma is analyzed
600 -- but otherwise ignored and control returns with In_Body set False.
602 -- If the check is enabled, then the first step is to analyze the
603 -- pragma, but this is skipped if the subprogram spec appears within
604 -- a package specification (because this is the case where we delay
605 -- analysis till the end of the spec). Then (whether or not it was
606 -- analyzed), the pragma is chained to the subprogram in question
607 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
608 -- caller with In_Body set False.
610 -- The pragma appears at the start of subprogram body declarations
612 -- In this case an immediate return to the caller is made with
613 -- In_Body set True, and the pragma is NOT analyzed.
615 -- In all other cases, an error message for bad placement is given
617 procedure Check_Static_Constraint (Constr : Node_Id);
618 -- Constr is a constraint from an N_Subtype_Indication node from a
619 -- component constraint in an Unchecked_Union type. This routine checks
620 -- that the constraint is static as required by the restrictions for
623 procedure Check_Test_Case;
624 -- Called to process a test-case pragma. The treatment is similar to the
625 -- one for pre- and postcondition in Check_Precondition_Postcondition,
626 -- except the placement rules for the test-case pragma are stricter.
627 -- This pragma may only occur after a subprogram spec declared directly
628 -- in a package spec unit. In this case, the pragma is chained to the
629 -- subprogram in question (using Spec_TC_List and Next_Pragma) and
630 -- analysis of the pragma is delayed till the end of the spec. In
631 -- all other cases, an error message for bad placement is given.
633 procedure Check_Valid_Configuration_Pragma;
634 -- Legality checks for placement of a configuration pragma
636 procedure Check_Valid_Library_Unit_Pragma;
637 -- Legality checks for library unit pragmas. A special case arises for
638 -- pragmas in generic instances that come from copies of the original
639 -- library unit pragmas in the generic templates. In the case of other
640 -- than library level instantiations these can appear in contexts which
641 -- would normally be invalid (they only apply to the original template
642 -- and to library level instantiations), and they are simply ignored,
643 -- which is implemented by rewriting them as null statements.
645 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
646 -- Check an Unchecked_Union variant for lack of nested variants and
647 -- presence of at least one component. UU_Typ is the related Unchecked_
650 procedure Error_Pragma (Msg : String);
651 pragma No_Return (Error_Pragma);
652 -- Outputs error message for current pragma. The message contains a %
653 -- that will be replaced with the pragma name, and the flag is placed
654 -- on the pragma itself. Pragma_Exit is then raised.
656 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
657 pragma No_Return (Error_Pragma_Arg);
658 -- Outputs error message for current pragma. The message may contain
659 -- a % that will be replaced with the pragma name. The parameter Arg
660 -- may either be a pragma argument association, in which case the flag
661 -- is placed on the expression of this association, or an expression,
662 -- in which case the flag is placed directly on the expression. The
663 -- message is placed using Error_Msg_N, so the message may also contain
664 -- an & insertion character which will reference the given Arg value.
665 -- After placing the message, Pragma_Exit is raised.
667 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
668 pragma No_Return (Error_Pragma_Arg);
669 -- Similar to above form of Error_Pragma_Arg except that two messages
670 -- are provided, the second is a continuation comment starting with \.
672 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
673 pragma No_Return (Error_Pragma_Arg_Ident);
674 -- Outputs error message for current pragma. The message may contain
675 -- a % that will be replaced with the pragma name. The parameter Arg
676 -- must be a pragma argument association with a non-empty identifier
677 -- (i.e. its Chars field must be set), and the error message is placed
678 -- on the identifier. The message is placed using Error_Msg_N so
679 -- the message may also contain an & insertion character which will
680 -- reference the identifier. After placing the message, Pragma_Exit
683 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
684 pragma No_Return (Error_Pragma_Ref);
685 -- Outputs error message for current pragma. The message may contain
686 -- a % that will be replaced with the pragma name. The parameter Ref
687 -- must be an entity whose name can be referenced by & and sloc by #.
688 -- After placing the message, Pragma_Exit is raised.
690 function Find_Lib_Unit_Name return Entity_Id;
691 -- Used for a library unit pragma to find the entity to which the
692 -- library unit pragma applies, returns the entity found.
694 procedure Find_Program_Unit_Name (Id : Node_Id);
695 -- If the pragma is a compilation unit pragma, the id must denote the
696 -- compilation unit in the same compilation, and the pragma must appear
697 -- in the list of preceding or trailing pragmas. If it is a program
698 -- unit pragma that is not a compilation unit pragma, then the
699 -- identifier must be visible.
701 function Find_Unique_Parameterless_Procedure
703 Arg : Node_Id) return Entity_Id;
704 -- Used for a procedure pragma to find the unique parameterless
705 -- procedure identified by Name, returns it if it exists, otherwise
706 -- errors out and uses Arg as the pragma argument for the message.
708 procedure Fix_Error (Msg : in out String);
709 -- This is called prior to issuing an error message. Msg is a string
710 -- which typically contains the substring pragma. If the current pragma
711 -- comes from an aspect, each such "pragma" substring is replaced with
712 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
713 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
715 procedure Gather_Associations
717 Args : out Args_List);
718 -- This procedure is used to gather the arguments for a pragma that
719 -- permits arbitrary ordering of parameters using the normal rules
720 -- for named and positional parameters. The Names argument is a list
721 -- of Name_Id values that corresponds to the allowed pragma argument
722 -- association identifiers in order. The result returned in Args is
723 -- a list of corresponding expressions that are the pragma arguments.
724 -- Note that this is a list of expressions, not of pragma argument
725 -- associations (Gather_Associations has completely checked all the
726 -- optional identifiers when it returns). An entry in Args is Empty
727 -- on return if the corresponding argument is not present.
729 procedure GNAT_Pragma;
730 -- Called for all GNAT defined pragmas to check the relevant restriction
731 -- (No_Implementation_Pragmas).
733 function Is_Before_First_Decl
734 (Pragma_Node : Node_Id;
735 Decls : List_Id) return Boolean;
736 -- Return True if Pragma_Node is before the first declarative item in
737 -- Decls where Decls is the list of declarative items.
739 function Is_Configuration_Pragma return Boolean;
740 -- Determines if the placement of the current pragma is appropriate
741 -- for a configuration pragma.
743 function Is_In_Context_Clause return Boolean;
744 -- Returns True if pragma appears within the context clause of a unit,
745 -- and False for any other placement (does not generate any messages).
747 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
748 -- Analyzes the argument, and determines if it is a static string
749 -- expression, returns True if so, False if non-static or not String.
751 procedure Pragma_Misplaced;
752 pragma No_Return (Pragma_Misplaced);
753 -- Issue fatal error message for misplaced pragma
755 procedure Process_Atomic_Shared_Volatile;
756 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
757 -- Shared is an obsolete Ada 83 pragma, treated as being identical
758 -- in effect to pragma Atomic.
760 procedure Process_Compile_Time_Warning_Or_Error;
761 -- Common processing for Compile_Time_Error and Compile_Time_Warning
763 procedure Process_Convention
764 (C : out Convention_Id;
765 Ent : out Entity_Id);
766 -- Common processing for Convention, Interface, Import and Export.
767 -- Checks first two arguments of pragma, and sets the appropriate
768 -- convention value in the specified entity or entities. On return
769 -- C is the convention, Ent is the referenced entity.
771 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
772 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
773 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
775 procedure Process_Extended_Import_Export_Exception_Pragma
776 (Arg_Internal : Node_Id;
777 Arg_External : Node_Id;
780 -- Common processing for the pragmas Import/Export_Exception. The three
781 -- arguments correspond to the three named parameters of the pragma. An
782 -- argument is empty if the corresponding parameter is not present in
785 procedure Process_Extended_Import_Export_Object_Pragma
786 (Arg_Internal : Node_Id;
787 Arg_External : Node_Id;
789 -- Common processing for the pragmas Import/Export_Object. The three
790 -- arguments correspond to the three named parameters of the pragmas. An
791 -- argument is empty if the corresponding parameter is not present in
794 procedure Process_Extended_Import_Export_Internal_Arg
795 (Arg_Internal : Node_Id := Empty);
796 -- Common processing for all extended Import and Export pragmas. The
797 -- argument is the pragma parameter for the Internal argument. If
798 -- Arg_Internal is empty or inappropriate, an error message is posted.
799 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
800 -- set to identify the referenced entity.
802 procedure Process_Extended_Import_Export_Subprogram_Pragma
803 (Arg_Internal : Node_Id;
804 Arg_External : Node_Id;
805 Arg_Parameter_Types : Node_Id;
806 Arg_Result_Type : Node_Id := Empty;
807 Arg_Mechanism : Node_Id;
808 Arg_Result_Mechanism : Node_Id := Empty;
809 Arg_First_Optional_Parameter : Node_Id := Empty);
810 -- Common processing for all extended Import and Export pragmas applying
811 -- to subprograms. The caller omits any arguments that do not apply to
812 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
813 -- only in the Import_Function and Export_Function cases). The argument
814 -- names correspond to the allowed pragma association identifiers.
816 procedure Process_Generic_List;
817 -- Common processing for Share_Generic and Inline_Generic
819 procedure Process_Import_Or_Interface;
820 -- Common processing for Import of Interface
822 procedure Process_Import_Predefined_Type;
823 -- Processing for completing a type with pragma Import. This is used
824 -- to declare types that match predefined C types, especially for cases
825 -- without corresponding Ada predefined type.
827 procedure Process_Inline (Active : Boolean);
828 -- Common processing for Inline and Inline_Always. The parameter
829 -- indicates if the inline pragma is active, i.e. if it should actually
830 -- cause inlining to occur.
832 procedure Process_Interface_Name
833 (Subprogram_Def : Entity_Id;
836 -- Given the last two arguments of pragma Import, pragma Export, or
837 -- pragma Interface_Name, performs validity checks and sets the
838 -- Interface_Name field of the given subprogram entity to the
839 -- appropriate external or link name, depending on the arguments given.
840 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
841 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
842 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
843 -- nor Link_Arg is present, the interface name is set to the default
844 -- from the subprogram name.
846 procedure Process_Interrupt_Or_Attach_Handler;
847 -- Common processing for Interrupt and Attach_Handler pragmas
849 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
850 -- Common processing for Restrictions and Restriction_Warnings pragmas.
851 -- Warn is True for Restriction_Warnings, or for Restrictions if the
852 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
853 -- is not set in the Restrictions case.
855 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
856 -- Common processing for Suppress and Unsuppress. The boolean parameter
857 -- Suppress_Case is True for the Suppress case, and False for the
860 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
861 -- This procedure sets the Is_Exported flag for the given entity,
862 -- checking that the entity was not previously imported. Arg is
863 -- the argument that specified the entity. A check is also made
864 -- for exporting inappropriate entities.
866 procedure Set_Extended_Import_Export_External_Name
867 (Internal_Ent : Entity_Id;
868 Arg_External : Node_Id);
869 -- Common processing for all extended import export pragmas. The first
870 -- argument, Internal_Ent, is the internal entity, which has already
871 -- been checked for validity by the caller. Arg_External is from the
872 -- Import or Export pragma, and may be null if no External parameter
873 -- was present. If Arg_External is present and is a non-null string
874 -- (a null string is treated as the default), then the Interface_Name
875 -- field of Internal_Ent is set appropriately.
877 procedure Set_Imported (E : Entity_Id);
878 -- This procedure sets the Is_Imported flag for the given entity,
879 -- checking that it is not previously exported or imported.
881 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
882 -- Mech is a parameter passing mechanism (see Import_Function syntax
883 -- for MECHANISM_NAME). This routine checks that the mechanism argument
884 -- has the right form, and if not issues an error message. If the
885 -- argument has the right form then the Mechanism field of Ent is
886 -- set appropriately.
888 procedure Set_Ravenscar_Profile (N : Node_Id);
889 -- Activate the set of configuration pragmas and restrictions that make
890 -- up the Ravenscar Profile. N is the corresponding pragma node, which
891 -- is used for error messages on any constructs that violate the
894 ---------------------
895 -- Ada_2005_Pragma --
896 ---------------------
898 procedure Ada_2005_Pragma is
900 if Ada_Version <= Ada_95 then
901 Check_Restriction (No_Implementation_Pragmas, N);
905 ---------------------
906 -- Ada_2012_Pragma --
907 ---------------------
909 procedure Ada_2012_Pragma is
911 if Ada_Version <= Ada_2005 then
912 Check_Restriction (No_Implementation_Pragmas, N);
916 --------------------------
917 -- Check_Ada_83_Warning --
918 --------------------------
920 procedure Check_Ada_83_Warning is
922 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
923 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
925 end Check_Ada_83_Warning;
927 ---------------------
928 -- Check_Arg_Count --
929 ---------------------
931 procedure Check_Arg_Count (Required : Nat) is
933 if Arg_Count /= Required then
934 Error_Pragma ("wrong number of arguments for pragma%");
938 --------------------------------
939 -- Check_Arg_Is_External_Name --
940 --------------------------------
942 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
943 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
946 if Nkind (Argx) = N_Identifier then
950 Analyze_And_Resolve (Argx, Standard_String);
952 if Is_OK_Static_Expression (Argx) then
955 elsif Etype (Argx) = Any_Type then
958 -- An interesting special case, if we have a string literal and
959 -- we are in Ada 83 mode, then we allow it even though it will
960 -- not be flagged as static. This allows expected Ada 83 mode
961 -- use of external names which are string literals, even though
962 -- technically these are not static in Ada 83.
964 elsif Ada_Version = Ada_83
965 and then Nkind (Argx) = N_String_Literal
969 -- Static expression that raises Constraint_Error. This has
970 -- already been flagged, so just exit from pragma processing.
972 elsif Is_Static_Expression (Argx) then
975 -- Here we have a real error (non-static expression)
978 Error_Msg_Name_1 := Pname;
982 "argument for pragma% must be a identifier or "
983 & "static string expression!";
986 Flag_Non_Static_Expr (Msg, Argx);
991 end Check_Arg_Is_External_Name;
993 -----------------------------
994 -- Check_Arg_Is_Identifier --
995 -----------------------------
997 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
998 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1000 if Nkind (Argx) /= N_Identifier then
1002 ("argument for pragma% must be identifier", Argx);
1004 end Check_Arg_Is_Identifier;
1006 ----------------------------------
1007 -- Check_Arg_Is_Integer_Literal --
1008 ----------------------------------
1010 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1011 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1013 if Nkind (Argx) /= N_Integer_Literal then
1015 ("argument for pragma% must be integer literal", Argx);
1017 end Check_Arg_Is_Integer_Literal;
1019 -------------------------------------------
1020 -- Check_Arg_Is_Library_Level_Local_Name --
1021 -------------------------------------------
1025 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1026 -- | library_unit_NAME
1028 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1030 Check_Arg_Is_Local_Name (Arg);
1032 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1033 and then Comes_From_Source (N)
1036 ("argument for pragma% must be library level entity", Arg);
1038 end Check_Arg_Is_Library_Level_Local_Name;
1040 -----------------------------
1041 -- Check_Arg_Is_Local_Name --
1042 -----------------------------
1046 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1047 -- | library_unit_NAME
1049 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1050 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1055 if Nkind (Argx) not in N_Direct_Name
1056 and then (Nkind (Argx) /= N_Attribute_Reference
1057 or else Present (Expressions (Argx))
1058 or else Nkind (Prefix (Argx)) /= N_Identifier)
1059 and then (not Is_Entity_Name (Argx)
1060 or else not Is_Compilation_Unit (Entity (Argx)))
1062 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1065 -- No further check required if not an entity name
1067 if not Is_Entity_Name (Argx) then
1073 Ent : constant Entity_Id := Entity (Argx);
1074 Scop : constant Entity_Id := Scope (Ent);
1076 -- Case of a pragma applied to a compilation unit: pragma must
1077 -- occur immediately after the program unit in the compilation.
1079 if Is_Compilation_Unit (Ent) then
1081 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1084 -- Case of pragma placed immediately after spec
1086 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1089 -- Case of pragma placed immediately after body
1091 elsif Nkind (Decl) = N_Subprogram_Declaration
1092 and then Present (Corresponding_Body (Decl))
1096 (Parent (Unit_Declaration_Node
1097 (Corresponding_Body (Decl))));
1099 -- All other cases are illegal
1106 -- Special restricted placement rule from 10.2.1(11.8/2)
1108 elsif Is_Generic_Formal (Ent)
1109 and then Prag_Id = Pragma_Preelaborable_Initialization
1111 OK := List_Containing (N) =
1112 Generic_Formal_Declarations
1113 (Unit_Declaration_Node (Scop));
1115 -- Default case, just check that the pragma occurs in the scope
1116 -- of the entity denoted by the name.
1119 OK := Current_Scope = Scop;
1124 ("pragma% argument must be in same declarative part", Arg);
1128 end Check_Arg_Is_Local_Name;
1130 ---------------------------------
1131 -- Check_Arg_Is_Locking_Policy --
1132 ---------------------------------
1134 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1135 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1138 Check_Arg_Is_Identifier (Argx);
1140 if not Is_Locking_Policy_Name (Chars (Argx)) then
1141 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1143 end Check_Arg_Is_Locking_Policy;
1145 -------------------------
1146 -- Check_Arg_Is_One_Of --
1147 -------------------------
1149 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1150 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1153 Check_Arg_Is_Identifier (Argx);
1155 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1156 Error_Msg_Name_2 := N1;
1157 Error_Msg_Name_3 := N2;
1158 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1160 end Check_Arg_Is_One_Of;
1162 procedure Check_Arg_Is_One_Of
1164 N1, N2, N3 : Name_Id)
1166 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1169 Check_Arg_Is_Identifier (Argx);
1171 if Chars (Argx) /= N1
1172 and then Chars (Argx) /= N2
1173 and then Chars (Argx) /= N3
1175 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1177 end Check_Arg_Is_One_Of;
1179 procedure Check_Arg_Is_One_Of
1181 N1, N2, N3, N4, N5 : Name_Id)
1183 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1186 Check_Arg_Is_Identifier (Argx);
1188 if Chars (Argx) /= N1
1189 and then Chars (Argx) /= N2
1190 and then Chars (Argx) /= N3
1191 and then Chars (Argx) /= N4
1192 and then Chars (Argx) /= N5
1194 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1196 end Check_Arg_Is_One_Of;
1197 ---------------------------------
1198 -- Check_Arg_Is_Queuing_Policy --
1199 ---------------------------------
1201 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1202 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1205 Check_Arg_Is_Identifier (Argx);
1207 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1208 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1210 end Check_Arg_Is_Queuing_Policy;
1212 ------------------------------------
1213 -- Check_Arg_Is_Static_Expression --
1214 ------------------------------------
1216 procedure Check_Arg_Is_Static_Expression
1218 Typ : Entity_Id := Empty)
1221 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1222 end Check_Arg_Is_Static_Expression;
1224 ------------------------------------------
1225 -- Check_Arg_Is_Task_Dispatching_Policy --
1226 ------------------------------------------
1228 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1229 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1232 Check_Arg_Is_Identifier (Argx);
1234 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1236 ("& is not a valid task dispatching policy name", Argx);
1238 end Check_Arg_Is_Task_Dispatching_Policy;
1240 ---------------------
1241 -- Check_Arg_Order --
1242 ---------------------
1244 procedure Check_Arg_Order (Names : Name_List) is
1247 Highest_So_Far : Natural := 0;
1248 -- Highest index in Names seen do far
1252 for J in 1 .. Arg_Count loop
1253 if Chars (Arg) /= No_Name then
1254 for K in Names'Range loop
1255 if Chars (Arg) = Names (K) then
1256 if K < Highest_So_Far then
1257 Error_Msg_Name_1 := Pname;
1259 ("parameters out of order for pragma%", Arg);
1260 Error_Msg_Name_1 := Names (K);
1261 Error_Msg_Name_2 := Names (Highest_So_Far);
1262 Error_Msg_N ("\% must appear before %", Arg);
1266 Highest_So_Far := K;
1274 end Check_Arg_Order;
1276 --------------------------------
1277 -- Check_At_Least_N_Arguments --
1278 --------------------------------
1280 procedure Check_At_Least_N_Arguments (N : Nat) is
1282 if Arg_Count < N then
1283 Error_Pragma ("too few arguments for pragma%");
1285 end Check_At_Least_N_Arguments;
1287 -------------------------------
1288 -- Check_At_Most_N_Arguments --
1289 -------------------------------
1291 procedure Check_At_Most_N_Arguments (N : Nat) is
1294 if Arg_Count > N then
1296 for J in 1 .. N loop
1298 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1301 end Check_At_Most_N_Arguments;
1303 ---------------------
1304 -- Check_Component --
1305 ---------------------
1307 procedure Check_Component
1310 In_Variant_Part : Boolean := False)
1312 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1313 Sindic : constant Node_Id :=
1314 Subtype_Indication (Component_Definition (Comp));
1315 Typ : constant Entity_Id := Etype (Comp_Id);
1317 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1318 -- Determine whether entity Id appears inside a generic body.
1319 -- Shouldn't this be in a more general place ???
1321 -------------------------
1322 -- Inside_Generic_Body --
1323 -------------------------
1325 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1330 while Present (S) and then S /= Standard_Standard loop
1331 if Ekind (S) = E_Generic_Package
1332 and then In_Package_Body (S)
1341 end Inside_Generic_Body;
1343 -- Start of processing for Check_Component
1346 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1347 -- object constraint, then the component type shall be an Unchecked_
1350 if Nkind (Sindic) = N_Subtype_Indication
1351 and then Has_Per_Object_Constraint (Comp_Id)
1352 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1355 ("component subtype subject to per-object constraint " &
1356 "must be an Unchecked_Union", Comp);
1358 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1359 -- the body of a generic unit, or within the body of any of its
1360 -- descendant library units, no part of the type of a component
1361 -- declared in a variant_part of the unchecked union type shall be of
1362 -- a formal private type or formal private extension declared within
1363 -- the formal part of the generic unit.
1365 elsif Ada_Version >= Ada_2012
1366 and then Inside_Generic_Body (UU_Typ)
1367 and then In_Variant_Part
1368 and then Is_Private_Type (Typ)
1369 and then Is_Generic_Type (Typ)
1372 ("component of Unchecked_Union cannot be of generic type", Comp);
1374 elsif Needs_Finalization (Typ) then
1376 ("component of Unchecked_Union cannot be controlled", Comp);
1378 elsif Has_Task (Typ) then
1380 ("component of Unchecked_Union cannot have tasks", Comp);
1382 end Check_Component;
1384 ----------------------------
1385 -- Check_Duplicate_Pragma --
1386 ----------------------------
1388 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1392 -- Nothing to do if this pragma comes from an aspect specification,
1393 -- since we could not be duplicating a pragma, and we dealt with the
1394 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1396 if From_Aspect_Specification (N) then
1400 -- Otherwise current pragma may duplicate previous pragma or a
1401 -- previously given aspect specification for the same pragma.
1403 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1406 Error_Msg_Name_1 := Pragma_Name (N);
1407 Error_Msg_Sloc := Sloc (P);
1409 if Nkind (P) = N_Aspect_Specification
1410 or else From_Aspect_Specification (P)
1412 Error_Msg_NE ("aspect% for & previously given#", N, E);
1414 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1419 end Check_Duplicate_Pragma;
1421 ----------------------------------
1422 -- Check_Duplicated_Export_Name --
1423 ----------------------------------
1425 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1426 String_Val : constant String_Id := Strval (Nam);
1429 -- We are only interested in the export case, and in the case of
1430 -- generics, it is the instance, not the template, that is the
1431 -- problem (the template will generate a warning in any case).
1433 if not Inside_A_Generic
1434 and then (Prag_Id = Pragma_Export
1436 Prag_Id = Pragma_Export_Procedure
1438 Prag_Id = Pragma_Export_Valued_Procedure
1440 Prag_Id = Pragma_Export_Function)
1442 for J in Externals.First .. Externals.Last loop
1443 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1444 Error_Msg_Sloc := Sloc (Externals.Table (J));
1445 Error_Msg_N ("external name duplicates name given#", Nam);
1450 Externals.Append (Nam);
1452 end Check_Duplicated_Export_Name;
1454 -------------------------------------
1455 -- Check_Expr_Is_Static_Expression --
1456 -------------------------------------
1458 procedure Check_Expr_Is_Static_Expression
1460 Typ : Entity_Id := Empty)
1463 if Present (Typ) then
1464 Analyze_And_Resolve (Expr, Typ);
1466 Analyze_And_Resolve (Expr);
1469 if Is_OK_Static_Expression (Expr) then
1472 elsif Etype (Expr) = Any_Type then
1475 -- An interesting special case, if we have a string literal and we
1476 -- are in Ada 83 mode, then we allow it even though it will not be
1477 -- flagged as static. This allows the use of Ada 95 pragmas like
1478 -- Import in Ada 83 mode. They will of course be flagged with
1479 -- warnings as usual, but will not cause errors.
1481 elsif Ada_Version = Ada_83
1482 and then Nkind (Expr) = N_String_Literal
1486 -- Static expression that raises Constraint_Error. This has already
1487 -- been flagged, so just exit from pragma processing.
1489 elsif Is_Static_Expression (Expr) then
1492 -- Finally, we have a real error
1495 Error_Msg_Name_1 := Pname;
1499 "argument for pragma% must be a static expression!";
1502 Flag_Non_Static_Expr (Msg, Expr);
1507 end Check_Expr_Is_Static_Expression;
1509 -------------------------
1510 -- Check_First_Subtype --
1511 -------------------------
1513 procedure Check_First_Subtype (Arg : Node_Id) is
1514 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1515 Ent : constant Entity_Id := Entity (Argx);
1518 if Is_First_Subtype (Ent) then
1521 elsif Is_Type (Ent) then
1523 ("pragma% cannot apply to subtype", Argx);
1525 elsif Is_Object (Ent) then
1527 ("pragma% cannot apply to object, requires a type", Argx);
1531 ("pragma% cannot apply to&, requires a type", Argx);
1533 end Check_First_Subtype;
1535 ----------------------
1536 -- Check_Identifier --
1537 ----------------------
1539 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1542 and then Nkind (Arg) = N_Pragma_Argument_Association
1544 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1545 Error_Msg_Name_1 := Pname;
1546 Error_Msg_Name_2 := Id;
1547 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1551 end Check_Identifier;
1553 --------------------------------
1554 -- Check_Identifier_Is_One_Of --
1555 --------------------------------
1557 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1560 and then Nkind (Arg) = N_Pragma_Argument_Association
1562 if Chars (Arg) = No_Name then
1563 Error_Msg_Name_1 := Pname;
1564 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1567 elsif Chars (Arg) /= N1
1568 and then Chars (Arg) /= N2
1570 Error_Msg_Name_1 := Pname;
1571 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1575 end Check_Identifier_Is_One_Of;
1577 ---------------------------
1578 -- Check_In_Main_Program --
1579 ---------------------------
1581 procedure Check_In_Main_Program is
1582 P : constant Node_Id := Parent (N);
1585 -- Must be at in subprogram body
1587 if Nkind (P) /= N_Subprogram_Body then
1588 Error_Pragma ("% pragma allowed only in subprogram");
1590 -- Otherwise warn if obviously not main program
1592 elsif Present (Parameter_Specifications (Specification (P)))
1593 or else not Is_Compilation_Unit (Defining_Entity (P))
1595 Error_Msg_Name_1 := Pname;
1597 ("?pragma% is only effective in main program", N);
1599 end Check_In_Main_Program;
1601 ---------------------------------------
1602 -- Check_Interrupt_Or_Attach_Handler --
1603 ---------------------------------------
1605 procedure Check_Interrupt_Or_Attach_Handler is
1606 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1607 Handler_Proc, Proc_Scope : Entity_Id;
1612 if Prag_Id = Pragma_Interrupt_Handler then
1613 Check_Restriction (No_Dynamic_Attachment, N);
1616 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1617 Proc_Scope := Scope (Handler_Proc);
1619 -- On AAMP only, a pragma Interrupt_Handler is supported for
1620 -- nonprotected parameterless procedures.
1622 if not AAMP_On_Target
1623 or else Prag_Id = Pragma_Attach_Handler
1625 if Ekind (Proc_Scope) /= E_Protected_Type then
1627 ("argument of pragma% must be protected procedure", Arg1);
1630 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1631 Error_Pragma ("pragma% must be in protected definition");
1635 if not Is_Library_Level_Entity (Proc_Scope)
1636 or else (AAMP_On_Target
1637 and then not Is_Library_Level_Entity (Handler_Proc))
1640 ("argument for pragma% must be library level entity", Arg1);
1643 -- AI05-0033: A pragma cannot appear within a generic body, because
1644 -- instance can be in a nested scope. The check that protected type
1645 -- is itself a library-level declaration is done elsewhere.
1647 -- Note: we omit this check in Codepeer mode to properly handle code
1648 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1650 if Inside_A_Generic then
1651 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1652 and then In_Package_Body (Scope (Current_Scope))
1653 and then not CodePeer_Mode
1655 Error_Pragma ("pragma% cannot be used inside a generic");
1658 end Check_Interrupt_Or_Attach_Handler;
1660 -------------------------------------------
1661 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1662 -------------------------------------------
1664 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1673 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1676 elsif Nkind_In (P, N_Package_Specification,
1681 -- Note: the following tests seem a little peculiar, because
1682 -- they test for bodies, but if we were in the statement part
1683 -- of the body, we would already have hit the handled statement
1684 -- sequence, so the only way we get here is by being in the
1685 -- declarative part of the body.
1687 elsif Nkind_In (P, N_Subprogram_Body,
1698 Error_Pragma ("pragma% is not in declarative part or package spec");
1699 end Check_Is_In_Decl_Part_Or_Package_Spec;
1701 -------------------------
1702 -- Check_No_Identifier --
1703 -------------------------
1705 procedure Check_No_Identifier (Arg : Node_Id) is
1707 if Nkind (Arg) = N_Pragma_Argument_Association
1708 and then Chars (Arg) /= No_Name
1710 Error_Pragma_Arg_Ident
1711 ("pragma% does not permit identifier& here", Arg);
1713 end Check_No_Identifier;
1715 --------------------------
1716 -- Check_No_Identifiers --
1717 --------------------------
1719 procedure Check_No_Identifiers is
1722 if Arg_Count > 0 then
1724 while Present (Arg_Node) loop
1725 Check_No_Identifier (Arg_Node);
1729 end Check_No_Identifiers;
1731 ------------------------
1732 -- Check_No_Link_Name --
1733 ------------------------
1735 procedure Check_No_Link_Name is
1738 and then Chars (Arg3) = Name_Link_Name
1743 if Present (Arg4) then
1745 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1747 end Check_No_Link_Name;
1749 -------------------------------
1750 -- Check_Optional_Identifier --
1751 -------------------------------
1753 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1756 and then Nkind (Arg) = N_Pragma_Argument_Association
1757 and then Chars (Arg) /= No_Name
1759 if Chars (Arg) /= Id then
1760 Error_Msg_Name_1 := Pname;
1761 Error_Msg_Name_2 := Id;
1762 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1766 end Check_Optional_Identifier;
1768 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1770 Name_Buffer (1 .. Id'Length) := Id;
1771 Name_Len := Id'Length;
1772 Check_Optional_Identifier (Arg, Name_Find);
1773 end Check_Optional_Identifier;
1775 --------------------------------------
1776 -- Check_Precondition_Postcondition --
1777 --------------------------------------
1779 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1783 procedure Chain_PPC (PO : Node_Id);
1784 -- If PO is an entry or a [generic] subprogram declaration node, then
1785 -- the precondition/postcondition applies to this subprogram and the
1786 -- processing for the pragma is completed. Otherwise the pragma is
1793 procedure Chain_PPC (PO : Node_Id) is
1798 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1799 if not From_Aspect_Specification (N) then
1801 ("pragma% cannot be applied to abstract subprogram");
1803 elsif Class_Present (N) then
1808 ("aspect % requires ''Class for abstract subprogram");
1811 -- AI05-0230: The same restriction applies to null procedures. For
1812 -- compatibility with earlier uses of the Ada pragma, apply this
1813 -- rule only to aspect specifications.
1815 -- The above discrpency needs documentation. Robert is dubious
1816 -- about whether it is a good idea ???
1818 elsif Nkind (PO) = N_Subprogram_Declaration
1819 and then Nkind (Specification (PO)) = N_Procedure_Specification
1820 and then Null_Present (Specification (PO))
1821 and then From_Aspect_Specification (N)
1822 and then not Class_Present (N)
1825 ("aspect % requires ''Class for null procedure");
1827 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1828 N_Generic_Subprogram_Declaration,
1829 N_Entry_Declaration)
1834 -- Here if we have [generic] subprogram or entry declaration
1836 if Nkind (PO) = N_Entry_Declaration then
1837 S := Defining_Entity (PO);
1839 S := Defining_Unit_Name (Specification (PO));
1842 -- Make sure we do not have the case of a precondition pragma when
1843 -- the Pre'Class aspect is present.
1845 -- We do this by looking at pragmas already chained to the entity
1846 -- since the aspect derived pragma will be put on this list first.
1848 if Pragma_Name (N) = Name_Precondition then
1849 if not From_Aspect_Specification (N) then
1850 P := Spec_PPC_List (Contract (S));
1851 while Present (P) loop
1852 if Pragma_Name (P) = Name_Precondition
1853 and then From_Aspect_Specification (P)
1854 and then Class_Present (P)
1856 Error_Msg_Sloc := Sloc (P);
1858 ("pragma% not allowed, `Pre''Class` aspect given#");
1861 P := Next_Pragma (P);
1866 -- Similarly check for Pre with inherited Pre'Class. Note that
1867 -- we cover the aspect case as well here.
1869 if Pragma_Name (N) = Name_Precondition
1870 and then not Class_Present (N)
1873 Inherited : constant Subprogram_List :=
1874 Inherited_Subprograms (S);
1878 for J in Inherited'Range loop
1879 P := Spec_PPC_List (Contract (Inherited (J)));
1880 while Present (P) loop
1881 if Pragma_Name (P) = Name_Precondition
1882 and then Class_Present (P)
1884 Error_Msg_Sloc := Sloc (P);
1886 ("pragma% not allowed, `Pre''Class` "
1887 & "aspect inherited from#");
1890 P := Next_Pragma (P);
1896 -- Note: we do not analyze the pragma at this point. Instead we
1897 -- delay this analysis until the end of the declarative part in
1898 -- which the pragma appears. This implements the required delay
1899 -- in this analysis, allowing forward references. The analysis
1900 -- happens at the end of Analyze_Declarations.
1902 -- Chain spec PPC pragma to list for subprogram
1904 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1905 Set_Spec_PPC_List (Contract (S), N);
1907 -- Return indicating spec case
1913 -- Start of processing for Check_Precondition_Postcondition
1916 if not Is_List_Member (N) then
1920 -- Preanalyze message argument if present. Visibility in this
1921 -- argument is established at the point of pragma occurrence.
1923 if Arg_Count = 2 then
1924 Check_Optional_Identifier (Arg2, Name_Message);
1925 Preanalyze_Spec_Expression
1926 (Get_Pragma_Arg (Arg2), Standard_String);
1929 -- Record if pragma is disabled
1931 if Check_Enabled (Pname) then
1932 Set_SCO_Pragma_Enabled (Loc);
1935 -- If we are within an inlined body, the legality of the pragma
1936 -- has been checked already.
1938 if In_Inlined_Body then
1943 -- Search prior declarations
1946 while Present (Prev (P)) loop
1949 -- If the previous node is a generic subprogram, do not go to to
1950 -- the original node, which is the unanalyzed tree: we need to
1951 -- attach the pre/postconditions to the analyzed version at this
1952 -- point. They get propagated to the original tree when analyzing
1953 -- the corresponding body.
1955 if Nkind (P) not in N_Generic_Declaration then
1956 PO := Original_Node (P);
1961 -- Skip past prior pragma
1963 if Nkind (PO) = N_Pragma then
1966 -- Skip stuff not coming from source
1968 elsif not Comes_From_Source (PO) then
1970 -- The condition may apply to a subprogram instantiation
1972 if Nkind (PO) = N_Subprogram_Declaration
1973 and then Present (Generic_Parent (Specification (PO)))
1978 elsif Nkind (PO) = N_Subprogram_Declaration
1979 and then In_Instance
1984 -- For all other cases of non source code, do nothing
1990 -- Only remaining possibility is subprogram declaration
1998 -- If we fall through loop, pragma is at start of list, so see if it
1999 -- is at the start of declarations of a subprogram body.
2001 if Nkind (Parent (N)) = N_Subprogram_Body
2002 and then List_Containing (N) = Declarations (Parent (N))
2004 if Operating_Mode /= Generate_Code
2005 or else Inside_A_Generic
2007 -- Analyze pragma expression for correctness and for ASIS use
2009 Preanalyze_Spec_Expression
2010 (Get_Pragma_Arg (Arg1), Standard_Boolean);
2012 -- In ASIS mode, for a pragma generated from a source aspect,
2013 -- also analyze the original aspect expression.
2016 and then Present (Corresponding_Aspect (N))
2018 Preanalyze_Spec_Expression
2019 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2026 -- See if it is in the pragmas after a library level subprogram
2028 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2030 -- In formal verification mode, analyze pragma expression for
2031 -- correctness, as it is not expanded later.
2034 Analyze_PPC_In_Decl_Part
2035 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2038 Chain_PPC (Unit (Parent (Parent (N))));
2042 -- If we fall through, pragma was misplaced
2045 end Check_Precondition_Postcondition;
2047 -----------------------------
2048 -- Check_Static_Constraint --
2049 -----------------------------
2051 -- Note: for convenience in writing this procedure, in addition to
2052 -- the officially (i.e. by spec) allowed argument which is always a
2053 -- constraint, it also allows ranges and discriminant associations.
2054 -- Above is not clear ???
2056 procedure Check_Static_Constraint (Constr : Node_Id) is
2058 procedure Require_Static (E : Node_Id);
2059 -- Require given expression to be static expression
2061 --------------------
2062 -- Require_Static --
2063 --------------------
2065 procedure Require_Static (E : Node_Id) is
2067 if not Is_OK_Static_Expression (E) then
2068 Flag_Non_Static_Expr
2069 ("non-static constraint not allowed in Unchecked_Union!", E);
2074 -- Start of processing for Check_Static_Constraint
2077 case Nkind (Constr) is
2078 when N_Discriminant_Association =>
2079 Require_Static (Expression (Constr));
2082 Require_Static (Low_Bound (Constr));
2083 Require_Static (High_Bound (Constr));
2085 when N_Attribute_Reference =>
2086 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2087 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2089 when N_Range_Constraint =>
2090 Check_Static_Constraint (Range_Expression (Constr));
2092 when N_Index_Or_Discriminant_Constraint =>
2096 IDC := First (Constraints (Constr));
2097 while Present (IDC) loop
2098 Check_Static_Constraint (IDC);
2106 end Check_Static_Constraint;
2108 ---------------------
2109 -- Check_Test_Case --
2110 ---------------------
2112 procedure Check_Test_Case is
2116 procedure Chain_TC (PO : Node_Id);
2117 -- If PO is a [generic] subprogram declaration node, then the
2118 -- test-case applies to this subprogram and the processing for the
2119 -- pragma is completed. Otherwise the pragma is misplaced.
2125 procedure Chain_TC (PO : Node_Id) is
2129 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2130 if From_Aspect_Specification (N) then
2132 ("aspect% cannot be applied to abstract subprogram");
2135 ("pragma% cannot be applied to abstract subprogram");
2138 elsif Nkind (PO) = N_Entry_Declaration then
2139 if From_Aspect_Specification (N) then
2140 Error_Pragma ("aspect% cannot be applied to entry");
2142 Error_Pragma ("pragma% cannot be applied to entry");
2145 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2146 N_Generic_Subprogram_Declaration)
2151 -- Here if we have [generic] subprogram declaration
2153 S := Defining_Unit_Name (Specification (PO));
2155 -- Note: we do not analyze the pragma at this point. Instead we
2156 -- delay this analysis until the end of the declarative part in
2157 -- which the pragma appears. This implements the required delay
2158 -- in this analysis, allowing forward references. The analysis
2159 -- happens at the end of Analyze_Declarations.
2161 -- There should not be another test case with the same name
2162 -- associated to this subprogram.
2165 Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2169 TC := Spec_TC_List (Contract (S));
2170 while Present (TC) loop
2173 (Name, Get_Name_From_Test_Case_Pragma (TC))
2175 Error_Msg_Sloc := Sloc (TC);
2177 if From_Aspect_Specification (N) then
2178 Error_Pragma ("name for aspect% is already used#");
2180 Error_Pragma ("name for pragma% is already used#");
2184 TC := Next_Pragma (TC);
2188 -- Chain spec TC pragma to list for subprogram
2190 Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2191 Set_Spec_TC_List (Contract (S), N);
2194 -- Start of processing for Check_Test_Case
2197 if not Is_List_Member (N) then
2201 -- Test cases should only appear in package spec unit
2203 if Get_Source_Unit (N) = No_Unit
2204 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2205 N_Package_Declaration,
2206 N_Generic_Package_Declaration)
2211 -- Search prior declarations
2214 while Present (Prev (P)) loop
2217 -- If the previous node is a generic subprogram, do not go to to
2218 -- the original node, which is the unanalyzed tree: we need to
2219 -- attach the test-case to the analyzed version at this point.
2220 -- They get propagated to the original tree when analyzing the
2221 -- corresponding body.
2223 if Nkind (P) not in N_Generic_Declaration then
2224 PO := Original_Node (P);
2229 -- Skip past prior pragma
2231 if Nkind (PO) = N_Pragma then
2234 -- Skip stuff not coming from source
2236 elsif not Comes_From_Source (PO) then
2239 -- Only remaining possibility is subprogram declaration. First
2240 -- check that it is declared directly in a package declaration.
2241 -- This may be either the package declaration for the current unit
2242 -- being defined or a local package declaration.
2244 elsif not Present (Parent (Parent (PO)))
2245 or else not Present (Parent (Parent (Parent (PO))))
2246 or else not Nkind_In (Parent (Parent (PO)),
2247 N_Package_Declaration,
2248 N_Generic_Package_Declaration)
2258 -- If we fall through, pragma was misplaced
2261 end Check_Test_Case;
2263 --------------------------------------
2264 -- Check_Valid_Configuration_Pragma --
2265 --------------------------------------
2267 -- A configuration pragma must appear in the context clause of a
2268 -- compilation unit, and only other pragmas may precede it. Note that
2269 -- the test also allows use in a configuration pragma file.
2271 procedure Check_Valid_Configuration_Pragma is
2273 if not Is_Configuration_Pragma then
2274 Error_Pragma ("incorrect placement for configuration pragma%");
2276 end Check_Valid_Configuration_Pragma;
2278 -------------------------------------
2279 -- Check_Valid_Library_Unit_Pragma --
2280 -------------------------------------
2282 procedure Check_Valid_Library_Unit_Pragma is
2284 Parent_Node : Node_Id;
2285 Unit_Name : Entity_Id;
2286 Unit_Kind : Node_Kind;
2287 Unit_Node : Node_Id;
2288 Sindex : Source_File_Index;
2291 if not Is_List_Member (N) then
2295 Plist := List_Containing (N);
2296 Parent_Node := Parent (Plist);
2298 if Parent_Node = Empty then
2301 -- Case of pragma appearing after a compilation unit. In this case
2302 -- it must have an argument with the corresponding name and must
2303 -- be part of the following pragmas of its parent.
2305 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2306 if Plist /= Pragmas_After (Parent_Node) then
2309 elsif Arg_Count = 0 then
2311 ("argument required if outside compilation unit");
2314 Check_No_Identifiers;
2315 Check_Arg_Count (1);
2316 Unit_Node := Unit (Parent (Parent_Node));
2317 Unit_Kind := Nkind (Unit_Node);
2319 Analyze (Get_Pragma_Arg (Arg1));
2321 if Unit_Kind = N_Generic_Subprogram_Declaration
2322 or else Unit_Kind = N_Subprogram_Declaration
2324 Unit_Name := Defining_Entity (Unit_Node);
2326 elsif Unit_Kind in N_Generic_Instantiation then
2327 Unit_Name := Defining_Entity (Unit_Node);
2330 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2333 if Chars (Unit_Name) /=
2334 Chars (Entity (Get_Pragma_Arg (Arg1)))
2337 ("pragma% argument is not current unit name", Arg1);
2340 if Ekind (Unit_Name) = E_Package
2341 and then Present (Renamed_Entity (Unit_Name))
2343 Error_Pragma ("pragma% not allowed for renamed package");
2347 -- Pragma appears other than after a compilation unit
2350 -- Here we check for the generic instantiation case and also
2351 -- for the case of processing a generic formal package. We
2352 -- detect these cases by noting that the Sloc on the node
2353 -- does not belong to the current compilation unit.
2355 Sindex := Source_Index (Current_Sem_Unit);
2357 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2358 Rewrite (N, Make_Null_Statement (Loc));
2361 -- If before first declaration, the pragma applies to the
2362 -- enclosing unit, and the name if present must be this name.
2364 elsif Is_Before_First_Decl (N, Plist) then
2365 Unit_Node := Unit_Declaration_Node (Current_Scope);
2366 Unit_Kind := Nkind (Unit_Node);
2368 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2371 elsif Unit_Kind = N_Subprogram_Body
2372 and then not Acts_As_Spec (Unit_Node)
2376 elsif Nkind (Parent_Node) = N_Package_Body then
2379 elsif Nkind (Parent_Node) = N_Package_Specification
2380 and then Plist = Private_Declarations (Parent_Node)
2384 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2385 or else Nkind (Parent_Node) =
2386 N_Generic_Subprogram_Declaration)
2387 and then Plist = Generic_Formal_Declarations (Parent_Node)
2391 elsif Arg_Count > 0 then
2392 Analyze (Get_Pragma_Arg (Arg1));
2394 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2396 ("name in pragma% must be enclosing unit", Arg1);
2399 -- It is legal to have no argument in this context
2405 -- Error if not before first declaration. This is because a
2406 -- library unit pragma argument must be the name of a library
2407 -- unit (RM 10.1.5(7)), but the only names permitted in this
2408 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2409 -- generic subprogram declarations or generic instantiations.
2413 ("pragma% misplaced, must be before first declaration");
2417 end Check_Valid_Library_Unit_Pragma;
2423 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2424 Clist : constant Node_Id := Component_List (Variant);
2428 if not Is_Non_Empty_List (Component_Items (Clist)) then
2430 ("Unchecked_Union may not have empty component list",
2435 Comp := First (Component_Items (Clist));
2436 while Present (Comp) loop
2437 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2446 procedure Error_Pragma (Msg : String) is
2447 MsgF : String := Msg;
2449 Error_Msg_Name_1 := Pname;
2451 Error_Msg_N (MsgF, N);
2455 ----------------------
2456 -- Error_Pragma_Arg --
2457 ----------------------
2459 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2460 MsgF : String := Msg;
2462 Error_Msg_Name_1 := Pname;
2464 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2466 end Error_Pragma_Arg;
2468 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2469 MsgF : String := Msg1;
2471 Error_Msg_Name_1 := Pname;
2473 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2474 Error_Pragma_Arg (Msg2, Arg);
2475 end Error_Pragma_Arg;
2477 ----------------------------
2478 -- Error_Pragma_Arg_Ident --
2479 ----------------------------
2481 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2482 MsgF : String := Msg;
2484 Error_Msg_Name_1 := Pname;
2486 Error_Msg_N (MsgF, Arg);
2488 end Error_Pragma_Arg_Ident;
2490 ----------------------
2491 -- Error_Pragma_Ref --
2492 ----------------------
2494 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2495 MsgF : String := Msg;
2497 Error_Msg_Name_1 := Pname;
2499 Error_Msg_Sloc := Sloc (Ref);
2500 Error_Msg_NE (MsgF, N, Ref);
2502 end Error_Pragma_Ref;
2504 ------------------------
2505 -- Find_Lib_Unit_Name --
2506 ------------------------
2508 function Find_Lib_Unit_Name return Entity_Id is
2510 -- Return inner compilation unit entity, for case of nested
2511 -- categorization pragmas. This happens in generic unit.
2513 if Nkind (Parent (N)) = N_Package_Specification
2514 and then Defining_Entity (Parent (N)) /= Current_Scope
2516 return Defining_Entity (Parent (N));
2518 return Current_Scope;
2520 end Find_Lib_Unit_Name;
2522 ----------------------------
2523 -- Find_Program_Unit_Name --
2524 ----------------------------
2526 procedure Find_Program_Unit_Name (Id : Node_Id) is
2527 Unit_Name : Entity_Id;
2528 Unit_Kind : Node_Kind;
2529 P : constant Node_Id := Parent (N);
2532 if Nkind (P) = N_Compilation_Unit then
2533 Unit_Kind := Nkind (Unit (P));
2535 if Unit_Kind = N_Subprogram_Declaration
2536 or else Unit_Kind = N_Package_Declaration
2537 or else Unit_Kind in N_Generic_Declaration
2539 Unit_Name := Defining_Entity (Unit (P));
2541 if Chars (Id) = Chars (Unit_Name) then
2542 Set_Entity (Id, Unit_Name);
2543 Set_Etype (Id, Etype (Unit_Name));
2545 Set_Etype (Id, Any_Type);
2547 ("cannot find program unit referenced by pragma%");
2551 Set_Etype (Id, Any_Type);
2552 Error_Pragma ("pragma% inapplicable to this unit");
2558 end Find_Program_Unit_Name;
2560 -----------------------------------------
2561 -- Find_Unique_Parameterless_Procedure --
2562 -----------------------------------------
2564 function Find_Unique_Parameterless_Procedure
2566 Arg : Node_Id) return Entity_Id
2568 Proc : Entity_Id := Empty;
2571 -- The body of this procedure needs some comments ???
2573 if not Is_Entity_Name (Name) then
2575 ("argument of pragma% must be entity name", Arg);
2577 elsif not Is_Overloaded (Name) then
2578 Proc := Entity (Name);
2580 if Ekind (Proc) /= E_Procedure
2581 or else Present (First_Formal (Proc))
2584 ("argument of pragma% must be parameterless procedure", Arg);
2589 Found : Boolean := False;
2591 Index : Interp_Index;
2594 Get_First_Interp (Name, Index, It);
2595 while Present (It.Nam) loop
2598 if Ekind (Proc) = E_Procedure
2599 and then No (First_Formal (Proc))
2603 Set_Entity (Name, Proc);
2604 Set_Is_Overloaded (Name, False);
2607 ("ambiguous handler name for pragma% ", Arg);
2611 Get_Next_Interp (Index, It);
2616 ("argument of pragma% must be parameterless procedure",
2619 Proc := Entity (Name);
2625 end Find_Unique_Parameterless_Procedure;
2631 procedure Fix_Error (Msg : in out String) is
2633 if From_Aspect_Specification (N) then
2634 for J in Msg'First .. Msg'Last - 5 loop
2635 if Msg (J .. J + 5) = "pragma" then
2636 Msg (J .. J + 5) := "aspect";
2640 if Error_Msg_Name_1 = Name_Precondition then
2641 Error_Msg_Name_1 := Name_Pre;
2642 elsif Error_Msg_Name_1 = Name_Postcondition then
2643 Error_Msg_Name_1 := Name_Post;
2648 -------------------------
2649 -- Gather_Associations --
2650 -------------------------
2652 procedure Gather_Associations
2654 Args : out Args_List)
2659 -- Initialize all parameters to Empty
2661 for J in Args'Range loop
2665 -- That's all we have to do if there are no argument associations
2667 if No (Pragma_Argument_Associations (N)) then
2671 -- Otherwise first deal with any positional parameters present
2673 Arg := First (Pragma_Argument_Associations (N));
2674 for Index in Args'Range loop
2675 exit when No (Arg) or else Chars (Arg) /= No_Name;
2676 Args (Index) := Get_Pragma_Arg (Arg);
2680 -- Positional parameters all processed, if any left, then we
2681 -- have too many positional parameters.
2683 if Present (Arg) and then Chars (Arg) = No_Name then
2685 ("too many positional associations for pragma%", Arg);
2688 -- Process named parameters if any are present
2690 while Present (Arg) loop
2691 if Chars (Arg) = No_Name then
2693 ("positional association cannot follow named association",
2697 for Index in Names'Range loop
2698 if Names (Index) = Chars (Arg) then
2699 if Present (Args (Index)) then
2701 ("duplicate argument association for pragma%", Arg);
2703 Args (Index) := Get_Pragma_Arg (Arg);
2708 if Index = Names'Last then
2709 Error_Msg_Name_1 := Pname;
2710 Error_Msg_N ("pragma% does not allow & argument", Arg);
2712 -- Check for possible misspelling
2714 for Index1 in Names'Range loop
2715 if Is_Bad_Spelling_Of
2716 (Chars (Arg), Names (Index1))
2718 Error_Msg_Name_1 := Names (Index1);
2719 Error_Msg_N -- CODEFIX
2720 ("\possible misspelling of%", Arg);
2732 end Gather_Associations;
2738 procedure GNAT_Pragma is
2740 Check_Restriction (No_Implementation_Pragmas, N);
2743 --------------------------
2744 -- Is_Before_First_Decl --
2745 --------------------------
2747 function Is_Before_First_Decl
2748 (Pragma_Node : Node_Id;
2749 Decls : List_Id) return Boolean
2751 Item : Node_Id := First (Decls);
2754 -- Only other pragmas can come before this pragma
2757 if No (Item) or else Nkind (Item) /= N_Pragma then
2760 elsif Item = Pragma_Node then
2766 end Is_Before_First_Decl;
2768 -----------------------------
2769 -- Is_Configuration_Pragma --
2770 -----------------------------
2772 -- A configuration pragma must appear in the context clause of a
2773 -- compilation unit, and only other pragmas may precede it. Note that
2774 -- the test below also permits use in a configuration pragma file.
2776 function Is_Configuration_Pragma return Boolean is
2777 Lis : constant List_Id := List_Containing (N);
2778 Par : constant Node_Id := Parent (N);
2782 -- If no parent, then we are in the configuration pragma file,
2783 -- so the placement is definitely appropriate.
2788 -- Otherwise we must be in the context clause of a compilation unit
2789 -- and the only thing allowed before us in the context list is more
2790 -- configuration pragmas.
2792 elsif Nkind (Par) = N_Compilation_Unit
2793 and then Context_Items (Par) = Lis
2800 elsif Nkind (Prg) /= N_Pragma then
2810 end Is_Configuration_Pragma;
2812 --------------------------
2813 -- Is_In_Context_Clause --
2814 --------------------------
2816 function Is_In_Context_Clause return Boolean is
2818 Parent_Node : Node_Id;
2821 if not Is_List_Member (N) then
2825 Plist := List_Containing (N);
2826 Parent_Node := Parent (Plist);
2828 if Parent_Node = Empty
2829 or else Nkind (Parent_Node) /= N_Compilation_Unit
2830 or else Context_Items (Parent_Node) /= Plist
2837 end Is_In_Context_Clause;
2839 ---------------------------------
2840 -- Is_Static_String_Expression --
2841 ---------------------------------
2843 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2844 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2847 Analyze_And_Resolve (Argx);
2848 return Is_OK_Static_Expression (Argx)
2849 and then Nkind (Argx) = N_String_Literal;
2850 end Is_Static_String_Expression;
2852 ----------------------
2853 -- Pragma_Misplaced --
2854 ----------------------
2856 procedure Pragma_Misplaced is
2858 Error_Pragma ("incorrect placement of pragma%");
2859 end Pragma_Misplaced;
2861 ------------------------------------
2862 -- Process Atomic_Shared_Volatile --
2863 ------------------------------------
2865 procedure Process_Atomic_Shared_Volatile is
2872 procedure Set_Atomic (E : Entity_Id);
2873 -- Set given type as atomic, and if no explicit alignment was given,
2874 -- set alignment to unknown, since back end knows what the alignment
2875 -- requirements are for atomic arrays. Note: this step is necessary
2876 -- for derived types.
2882 procedure Set_Atomic (E : Entity_Id) is
2886 if not Has_Alignment_Clause (E) then
2887 Set_Alignment (E, Uint_0);
2891 -- Start of processing for Process_Atomic_Shared_Volatile
2894 Check_Ada_83_Warning;
2895 Check_No_Identifiers;
2896 Check_Arg_Count (1);
2897 Check_Arg_Is_Local_Name (Arg1);
2898 E_Id := Get_Pragma_Arg (Arg1);
2900 if Etype (E_Id) = Any_Type then
2905 D := Declaration_Node (E);
2908 -- Check duplicate before we chain ourselves!
2910 Check_Duplicate_Pragma (E);
2912 -- Now check appropriateness of the entity
2915 if Rep_Item_Too_Early (E, N)
2917 Rep_Item_Too_Late (E, N)
2921 Check_First_Subtype (Arg1);
2924 if Prag_Id /= Pragma_Volatile then
2926 Set_Atomic (Underlying_Type (E));
2927 Set_Atomic (Base_Type (E));
2930 -- Attribute belongs on the base type. If the view of the type is
2931 -- currently private, it also belongs on the underlying type.
2933 Set_Is_Volatile (Base_Type (E));
2934 Set_Is_Volatile (Underlying_Type (E));
2936 Set_Treat_As_Volatile (E);
2937 Set_Treat_As_Volatile (Underlying_Type (E));
2939 elsif K = N_Object_Declaration
2940 or else (K = N_Component_Declaration
2941 and then Original_Record_Component (E) = E)
2943 if Rep_Item_Too_Late (E, N) then
2947 if Prag_Id /= Pragma_Volatile then
2950 -- If the object declaration has an explicit initialization, a
2951 -- temporary may have to be created to hold the expression, to
2952 -- ensure that access to the object remain atomic.
2954 if Nkind (Parent (E)) = N_Object_Declaration
2955 and then Present (Expression (Parent (E)))
2957 Set_Has_Delayed_Freeze (E);
2960 -- An interesting improvement here. If an object of type X is
2961 -- declared atomic, and the type X is not atomic, that's a
2962 -- pity, since it may not have appropriate alignment etc. We
2963 -- can rescue this in the special case where the object and
2964 -- type are in the same unit by just setting the type as
2965 -- atomic, so that the back end will process it as atomic.
2967 Utyp := Underlying_Type (Etype (E));
2970 and then Sloc (E) > No_Location
2971 and then Sloc (Utyp) > No_Location
2973 Get_Source_File_Index (Sloc (E)) =
2974 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2976 Set_Is_Atomic (Underlying_Type (Etype (E)));
2980 Set_Is_Volatile (E);
2981 Set_Treat_As_Volatile (E);
2985 ("inappropriate entity for pragma%", Arg1);
2987 end Process_Atomic_Shared_Volatile;
2989 -------------------------------------------
2990 -- Process_Compile_Time_Warning_Or_Error --
2991 -------------------------------------------
2993 procedure Process_Compile_Time_Warning_Or_Error is
2994 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2997 Check_Arg_Count (2);
2998 Check_No_Identifiers;
2999 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3000 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3002 if Compile_Time_Known_Value (Arg1x) then
3003 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3005 Str : constant String_Id :=
3006 Strval (Get_Pragma_Arg (Arg2));
3007 Len : constant Int := String_Length (Str);
3012 Cent : constant Entity_Id :=
3013 Cunit_Entity (Current_Sem_Unit);
3015 Force : constant Boolean :=
3016 Prag_Id = Pragma_Compile_Time_Warning
3018 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3019 and then (Ekind (Cent) /= E_Package
3020 or else not In_Private_Part (Cent));
3021 -- Set True if this is the warning case, and we are in the
3022 -- visible part of a package spec, or in a subprogram spec,
3023 -- in which case we want to force the client to see the
3024 -- warning, even though it is not in the main unit.
3027 -- Loop through segments of message separated by line feeds.
3028 -- We output these segments as separate messages with
3029 -- continuation marks for all but the first.
3034 Error_Msg_Strlen := 0;
3036 -- Loop to copy characters from argument to error message
3040 exit when Ptr > Len;
3041 CC := Get_String_Char (Str, Ptr);
3044 -- Ignore wide chars ??? else store character
3046 if In_Character_Range (CC) then
3047 C := Get_Character (CC);
3048 exit when C = ASCII.LF;
3049 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3050 Error_Msg_String (Error_Msg_Strlen) := C;
3054 -- Here with one line ready to go
3056 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3058 -- If this is a warning in a spec, then we want clients
3059 -- to see the warning, so mark the message with the
3060 -- special sequence !! to force the warning. In the case
3061 -- of a package spec, we do not force this if we are in
3062 -- the private part of the spec.
3065 if Cont = False then
3066 Error_Msg_N ("<~!!", Arg1);
3069 Error_Msg_N ("\<~!!", Arg1);
3072 -- Error, rather than warning, or in a body, so we do not
3073 -- need to force visibility for client (error will be
3074 -- output in any case, and this is the situation in which
3075 -- we do not want a client to get a warning, since the
3076 -- warning is in the body or the spec private part).
3079 if Cont = False then
3080 Error_Msg_N ("<~", Arg1);
3083 Error_Msg_N ("\<~", Arg1);
3087 exit when Ptr > Len;
3092 end Process_Compile_Time_Warning_Or_Error;
3094 ------------------------
3095 -- Process_Convention --
3096 ------------------------
3098 procedure Process_Convention
3099 (C : out Convention_Id;
3100 Ent : out Entity_Id)
3106 Comp_Unit : Unit_Number_Type;
3108 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3109 -- Called if we have more than one Export/Import/Convention pragma.
3110 -- This is generally illegal, but we have a special case of allowing
3111 -- Import and Interface to coexist if they specify the convention in
3112 -- a consistent manner. We are allowed to do this, since Interface is
3113 -- an implementation defined pragma, and we choose to do it since we
3114 -- know Rational allows this combination. S is the entity id of the
3115 -- subprogram in question. This procedure also sets the special flag
3116 -- Import_Interface_Present in both pragmas in the case where we do
3117 -- have matching Import and Interface pragmas.
3119 procedure Set_Convention_From_Pragma (E : Entity_Id);
3120 -- Set convention in entity E, and also flag that the entity has a
3121 -- convention pragma. If entity is for a private or incomplete type,
3122 -- also set convention and flag on underlying type. This procedure
3123 -- also deals with the special case of C_Pass_By_Copy convention.
3125 -------------------------------
3126 -- Diagnose_Multiple_Pragmas --
3127 -------------------------------
3129 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3130 Pdec : constant Node_Id := Declaration_Node (S);
3134 function Same_Convention (Decl : Node_Id) return Boolean;
3135 -- Decl is a pragma node. This function returns True if this
3136 -- pragma has a first argument that is an identifier with a
3137 -- Chars field corresponding to the Convention_Id C.
3139 function Same_Name (Decl : Node_Id) return Boolean;
3140 -- Decl is a pragma node. This function returns True if this
3141 -- pragma has a second argument that is an identifier with a
3142 -- Chars field that matches the Chars of the current subprogram.
3144 ---------------------
3145 -- Same_Convention --
3146 ---------------------
3148 function Same_Convention (Decl : Node_Id) return Boolean is
3149 Arg1 : constant Node_Id :=
3150 First (Pragma_Argument_Associations (Decl));
3153 if Present (Arg1) then
3155 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3157 if Nkind (Arg) = N_Identifier
3158 and then Is_Convention_Name (Chars (Arg))
3159 and then Get_Convention_Id (Chars (Arg)) = C
3167 end Same_Convention;
3173 function Same_Name (Decl : Node_Id) return Boolean is
3174 Arg1 : constant Node_Id :=
3175 First (Pragma_Argument_Associations (Decl));
3183 Arg2 := Next (Arg1);
3190 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3192 if Nkind (Arg) = N_Identifier
3193 and then Chars (Arg) = Chars (S)
3202 -- Start of processing for Diagnose_Multiple_Pragmas
3207 -- Definitely give message if we have Convention/Export here
3209 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3212 -- If we have an Import or Export, scan back from pragma to
3213 -- find any previous pragma applying to the same procedure.
3214 -- The scan will be terminated by the start of the list, or
3215 -- hitting the subprogram declaration. This won't allow one
3216 -- pragma to appear in the public part and one in the private
3217 -- part, but that seems very unlikely in practice.
3221 while Present (Decl) and then Decl /= Pdec loop
3223 -- Look for pragma with same name as us
3225 if Nkind (Decl) = N_Pragma
3226 and then Same_Name (Decl)
3228 -- Give error if same as our pragma or Export/Convention
3230 if Pragma_Name (Decl) = Name_Export
3232 Pragma_Name (Decl) = Name_Convention
3234 Pragma_Name (Decl) = Pragma_Name (N)
3238 -- Case of Import/Interface or the other way round
3240 elsif Pragma_Name (Decl) = Name_Interface
3242 Pragma_Name (Decl) = Name_Import
3244 -- Here we know that we have Import and Interface. It
3245 -- doesn't matter which way round they are. See if
3246 -- they specify the same convention. If so, all OK,
3247 -- and set special flags to stop other messages
3249 if Same_Convention (Decl) then
3250 Set_Import_Interface_Present (N);
3251 Set_Import_Interface_Present (Decl);
3254 -- If different conventions, special message
3257 Error_Msg_Sloc := Sloc (Decl);
3259 ("convention differs from that given#", Arg1);
3269 -- Give message if needed if we fall through those tests
3273 ("at most one Convention/Export/Import pragma is allowed",
3276 end Diagnose_Multiple_Pragmas;
3278 --------------------------------
3279 -- Set_Convention_From_Pragma --
3280 --------------------------------
3282 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3284 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3285 -- for an overridden dispatching operation. Technically this is
3286 -- an amendment and should only be done in Ada 2005 mode. However,
3287 -- this is clearly a mistake, since the problem that is addressed
3288 -- by this AI is that there is a clear gap in the RM!
3290 if Is_Dispatching_Operation (E)
3291 and then Present (Overridden_Operation (E))
3292 and then C /= Convention (Overridden_Operation (E))
3295 ("cannot change convention for " &
3296 "overridden dispatching operation",
3300 -- Set the convention
3302 Set_Convention (E, C);
3303 Set_Has_Convention_Pragma (E);
3305 if Is_Incomplete_Or_Private_Type (E)
3306 and then Present (Underlying_Type (E))
3308 Set_Convention (Underlying_Type (E), C);
3309 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3312 -- A class-wide type should inherit the convention of the specific
3313 -- root type (although this isn't specified clearly by the RM).
3315 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3316 Set_Convention (Class_Wide_Type (E), C);
3319 -- If the entity is a record type, then check for special case of
3320 -- C_Pass_By_Copy, which is treated the same as C except that the
3321 -- special record flag is set. This convention is only permitted
3322 -- on record types (see AI95-00131).
3324 if Cname = Name_C_Pass_By_Copy then
3325 if Is_Record_Type (E) then
3326 Set_C_Pass_By_Copy (Base_Type (E));
3327 elsif Is_Incomplete_Or_Private_Type (E)
3328 and then Is_Record_Type (Underlying_Type (E))
3330 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3333 ("C_Pass_By_Copy convention allowed only for record type",
3338 -- If the entity is a derived boolean type, check for the special
3339 -- case of convention C, C++, or Fortran, where we consider any
3340 -- nonzero value to represent true.
3342 if Is_Discrete_Type (E)
3343 and then Root_Type (Etype (E)) = Standard_Boolean
3349 C = Convention_Fortran)
3351 Set_Nonzero_Is_True (Base_Type (E));
3353 end Set_Convention_From_Pragma;
3355 -- Start of processing for Process_Convention
3358 Check_At_Least_N_Arguments (2);
3359 Check_Optional_Identifier (Arg1, Name_Convention);
3360 Check_Arg_Is_Identifier (Arg1);
3361 Cname := Chars (Get_Pragma_Arg (Arg1));
3363 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3364 -- tested again below to set the critical flag).
3366 if Cname = Name_C_Pass_By_Copy then
3369 -- Otherwise we must have something in the standard convention list
3371 elsif Is_Convention_Name (Cname) then
3372 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3374 -- In DEC VMS, it seems that there is an undocumented feature that
3375 -- any unrecognized convention is treated as the default, which for
3376 -- us is convention C. It does not seem so terrible to do this
3377 -- unconditionally, silently in the VMS case, and with a warning
3378 -- in the non-VMS case.
3381 if Warn_On_Export_Import and not OpenVMS_On_Target then
3383 ("?unrecognized convention name, C assumed",
3384 Get_Pragma_Arg (Arg1));
3390 Check_Optional_Identifier (Arg2, Name_Entity);
3391 Check_Arg_Is_Local_Name (Arg2);
3393 Id := Get_Pragma_Arg (Arg2);
3396 if not Is_Entity_Name (Id) then
3397 Error_Pragma_Arg ("entity name required", Arg2);
3402 -- Set entity to return
3406 -- Ada_Pass_By_Copy special checking
3408 if C = Convention_Ada_Pass_By_Copy then
3409 if not Is_First_Subtype (E) then
3411 ("convention `Ada_Pass_By_Copy` only "
3412 & "allowed for types", Arg2);
3415 if Is_By_Reference_Type (E) then
3417 ("convention `Ada_Pass_By_Copy` not allowed for "
3418 & "by-reference type", Arg1);
3422 -- Ada_Pass_By_Reference special checking
3424 if C = Convention_Ada_Pass_By_Reference then
3425 if not Is_First_Subtype (E) then
3427 ("convention `Ada_Pass_By_Reference` only "
3428 & "allowed for types", Arg2);
3431 if Is_By_Copy_Type (E) then
3433 ("convention `Ada_Pass_By_Reference` not allowed for "
3434 & "by-copy type", Arg1);
3438 -- Go to renamed subprogram if present, since convention applies to
3439 -- the actual renamed entity, not to the renaming entity. If the
3440 -- subprogram is inherited, go to parent subprogram.
3442 if Is_Subprogram (E)
3443 and then Present (Alias (E))
3445 if Nkind (Parent (Declaration_Node (E))) =
3446 N_Subprogram_Renaming_Declaration
3448 if Scope (E) /= Scope (Alias (E)) then
3450 ("cannot apply pragma% to non-local entity&#", E);
3455 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3456 N_Private_Extension_Declaration)
3457 and then Scope (E) = Scope (Alias (E))
3461 -- Return the parent subprogram the entity was inherited from
3467 -- Check that we are not applying this to a specless body
3469 if Is_Subprogram (E)
3470 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3473 ("pragma% requires separate spec and must come before body");
3476 -- Check that we are not applying this to a named constant
3478 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3479 Error_Msg_Name_1 := Pname;
3481 ("cannot apply pragma% to named constant!",
3482 Get_Pragma_Arg (Arg2));
3484 ("\supply appropriate type for&!", Arg2);
3487 if Ekind (E) = E_Enumeration_Literal then
3488 Error_Pragma ("enumeration literal not allowed for pragma%");
3491 -- Check for rep item appearing too early or too late
3493 if Etype (E) = Any_Type
3494 or else Rep_Item_Too_Early (E, N)
3498 elsif Present (Underlying_Type (E)) then
3499 E := Underlying_Type (E);
3502 if Rep_Item_Too_Late (E, N) then
3506 if Has_Convention_Pragma (E) then
3507 Diagnose_Multiple_Pragmas (E);
3509 elsif Convention (E) = Convention_Protected
3510 or else Ekind (Scope (E)) = E_Protected_Type
3513 ("a protected operation cannot be given a different convention",
3517 -- For Intrinsic, a subprogram is required
3519 if C = Convention_Intrinsic
3520 and then not Is_Subprogram (E)
3521 and then not Is_Generic_Subprogram (E)
3524 ("second argument of pragma% must be a subprogram", Arg2);
3527 -- For Stdcall, a subprogram, variable or subprogram type is required
3529 if C = Convention_Stdcall
3531 ((not Is_Subprogram (E) and then not Is_Generic_Subprogram (E))
3532 or else Is_Dispatching_Operation (E))
3533 and then Ekind (E) /= E_Variable
3536 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3539 ("second argument of pragma% must be subprogram (type)",
3543 if not Is_Subprogram (E)
3544 and then not Is_Generic_Subprogram (E)
3546 Set_Convention_From_Pragma (E);
3549 Check_First_Subtype (Arg2);
3550 Set_Convention_From_Pragma (Base_Type (E));
3552 -- For subprograms, we must set the convention on the
3553 -- internally generated directly designated type as well.
3555 if Ekind (E) = E_Access_Subprogram_Type then
3556 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3560 -- For the subprogram case, set proper convention for all homonyms
3561 -- in same scope and the same declarative part, i.e. the same
3562 -- compilation unit.
3565 Comp_Unit := Get_Source_Unit (E);
3566 Set_Convention_From_Pragma (E);
3568 -- Treat a pragma Import as an implicit body, for GPS use
3570 if Prag_Id = Pragma_Import then
3571 Generate_Reference (E, Id, 'b');
3574 -- Loop through the homonyms of the pragma argument's entity
3579 exit when No (E1) or else Scope (E1) /= Current_Scope;
3581 -- Do not set the pragma on inherited operations or on formal
3584 if Comes_From_Source (E1)
3585 and then Comp_Unit = Get_Source_Unit (E1)
3586 and then not Is_Formal_Subprogram (E1)
3587 and then Nkind (Original_Node (Parent (E1))) /=
3588 N_Full_Type_Declaration
3590 if Present (Alias (E1))
3591 and then Scope (E1) /= Scope (Alias (E1))
3594 ("cannot apply pragma% to non-local entity& declared#",
3598 Set_Convention_From_Pragma (E1);
3600 if Prag_Id = Pragma_Import then
3601 Generate_Reference (E1, Id, 'b');
3605 -- For aspect case, do NOT apply to homonyms
3607 exit when From_Aspect_Specification (N);
3610 end Process_Convention;
3612 ----------------------------------------
3613 -- Process_Disable_Enable_Atomic_Sync --
3614 ----------------------------------------
3616 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3619 Check_No_Identifiers;
3620 Check_At_Most_N_Arguments (1);
3622 -- Modeled internally as
3623 -- pragma Unsuppress (Atomic_Synchronization [,Entity])
3627 Pragma_Identifier =>
3628 Make_Identifier (Loc, Nam),
3629 Pragma_Argument_Associations => New_List (
3630 Make_Pragma_Argument_Association (Loc,
3632 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3634 if Present (Arg1) then
3635 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3639 end Process_Disable_Enable_Atomic_Sync;
3641 -----------------------------------------------------
3642 -- Process_Extended_Import_Export_Exception_Pragma --
3643 -----------------------------------------------------
3645 procedure Process_Extended_Import_Export_Exception_Pragma
3646 (Arg_Internal : Node_Id;
3647 Arg_External : Node_Id;
3655 if not OpenVMS_On_Target then
3657 ("?pragma% ignored (applies only to Open'V'M'S)");
3660 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3661 Def_Id := Entity (Arg_Internal);
3663 if Ekind (Def_Id) /= E_Exception then
3665 ("pragma% must refer to declared exception", Arg_Internal);
3668 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3670 if Present (Arg_Form) then
3671 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3674 if Present (Arg_Form)
3675 and then Chars (Arg_Form) = Name_Ada
3679 Set_Is_VMS_Exception (Def_Id);
3680 Set_Exception_Code (Def_Id, No_Uint);
3683 if Present (Arg_Code) then
3684 if not Is_VMS_Exception (Def_Id) then
3686 ("Code option for pragma% not allowed for Ada case",
3690 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3691 Code_Val := Expr_Value (Arg_Code);
3693 if not UI_Is_In_Int_Range (Code_Val) then
3695 ("Code option for pragma% must be in 32-bit range",
3699 Set_Exception_Code (Def_Id, Code_Val);
3702 end Process_Extended_Import_Export_Exception_Pragma;
3704 -------------------------------------------------
3705 -- Process_Extended_Import_Export_Internal_Arg --
3706 -------------------------------------------------
3708 procedure Process_Extended_Import_Export_Internal_Arg
3709 (Arg_Internal : Node_Id := Empty)
3712 if No (Arg_Internal) then
3713 Error_Pragma ("Internal parameter required for pragma%");
3716 if Nkind (Arg_Internal) = N_Identifier then
3719 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3720 and then (Prag_Id = Pragma_Import_Function
3722 Prag_Id = Pragma_Export_Function)
3728 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3731 Check_Arg_Is_Local_Name (Arg_Internal);
3732 end Process_Extended_Import_Export_Internal_Arg;
3734 --------------------------------------------------
3735 -- Process_Extended_Import_Export_Object_Pragma --
3736 --------------------------------------------------
3738 procedure Process_Extended_Import_Export_Object_Pragma
3739 (Arg_Internal : Node_Id;
3740 Arg_External : Node_Id;
3746 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3747 Def_Id := Entity (Arg_Internal);
3749 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3751 ("pragma% must designate an object", Arg_Internal);
3754 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3756 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3759 ("previous Common/Psect_Object applies, pragma % not permitted",
3763 if Rep_Item_Too_Late (Def_Id, N) then
3767 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3769 if Present (Arg_Size) then
3770 Check_Arg_Is_External_Name (Arg_Size);
3773 -- Export_Object case
3775 if Prag_Id = Pragma_Export_Object then
3776 if not Is_Library_Level_Entity (Def_Id) then
3778 ("argument for pragma% must be library level entity",
3782 if Ekind (Current_Scope) = E_Generic_Package then
3783 Error_Pragma ("pragma& cannot appear in a generic unit");
3786 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3788 ("exported object must have compile time known size",
3792 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3793 Error_Msg_N ("?duplicate Export_Object pragma", N);
3795 Set_Exported (Def_Id, Arg_Internal);
3798 -- Import_Object case
3801 if Is_Concurrent_Type (Etype (Def_Id)) then
3803 ("cannot use pragma% for task/protected object",
3807 if Ekind (Def_Id) = E_Constant then
3809 ("cannot import a constant", Arg_Internal);
3812 if Warn_On_Export_Import
3813 and then Has_Discriminants (Etype (Def_Id))
3816 ("imported value must be initialized?", Arg_Internal);
3819 if Warn_On_Export_Import
3820 and then Is_Access_Type (Etype (Def_Id))
3823 ("cannot import object of an access type?", Arg_Internal);
3826 if Warn_On_Export_Import
3827 and then Is_Imported (Def_Id)
3830 ("?duplicate Import_Object pragma", N);
3832 -- Check for explicit initialization present. Note that an
3833 -- initialization generated by the code generator, e.g. for an
3834 -- access type, does not count here.
3836 elsif Present (Expression (Parent (Def_Id)))
3839 (Original_Node (Expression (Parent (Def_Id))))
3841 Error_Msg_Sloc := Sloc (Def_Id);
3843 ("imported entities cannot be initialized (RM B.1(24))",
3844 "\no initialization allowed for & declared#", Arg1);
3846 Set_Imported (Def_Id);
3847 Note_Possible_Modification (Arg_Internal, Sure => False);
3850 end Process_Extended_Import_Export_Object_Pragma;
3852 ------------------------------------------------------
3853 -- Process_Extended_Import_Export_Subprogram_Pragma --
3854 ------------------------------------------------------
3856 procedure Process_Extended_Import_Export_Subprogram_Pragma
3857 (Arg_Internal : Node_Id;
3858 Arg_External : Node_Id;
3859 Arg_Parameter_Types : Node_Id;
3860 Arg_Result_Type : Node_Id := Empty;
3861 Arg_Mechanism : Node_Id;
3862 Arg_Result_Mechanism : Node_Id := Empty;
3863 Arg_First_Optional_Parameter : Node_Id := Empty)
3869 Ambiguous : Boolean;
3873 function Same_Base_Type
3875 Formal : Entity_Id) return Boolean;
3876 -- Determines if Ptype references the type of Formal. Note that only
3877 -- the base types need to match according to the spec. Ptype here is
3878 -- the argument from the pragma, which is either a type name, or an
3879 -- access attribute.
3881 --------------------
3882 -- Same_Base_Type --
3883 --------------------
3885 function Same_Base_Type
3887 Formal : Entity_Id) return Boolean
3889 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3893 -- Case where pragma argument is typ'Access
3895 if Nkind (Ptype) = N_Attribute_Reference
3896 and then Attribute_Name (Ptype) = Name_Access
3898 Pref := Prefix (Ptype);
3901 if not Is_Entity_Name (Pref)
3902 or else Entity (Pref) = Any_Type
3907 -- We have a match if the corresponding argument is of an
3908 -- anonymous access type, and its designated type matches the
3909 -- type of the prefix of the access attribute
3911 return Ekind (Ftyp) = E_Anonymous_Access_Type
3912 and then Base_Type (Entity (Pref)) =
3913 Base_Type (Etype (Designated_Type (Ftyp)));
3915 -- Case where pragma argument is a type name
3920 if not Is_Entity_Name (Ptype)
3921 or else Entity (Ptype) = Any_Type
3926 -- We have a match if the corresponding argument is of the type
3927 -- given in the pragma (comparing base types)
3929 return Base_Type (Entity (Ptype)) = Ftyp;
3933 -- Start of processing for
3934 -- Process_Extended_Import_Export_Subprogram_Pragma
3937 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3941 -- Loop through homonyms (overloadings) of the entity
3943 Hom_Id := Entity (Arg_Internal);
3944 while Present (Hom_Id) loop
3945 Def_Id := Get_Base_Subprogram (Hom_Id);
3947 -- We need a subprogram in the current scope
3949 if not Is_Subprogram (Def_Id)
3950 or else Scope (Def_Id) /= Current_Scope
3957 -- Pragma cannot apply to subprogram body
3959 if Is_Subprogram (Def_Id)
3960 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3964 ("pragma% requires separate spec"
3965 & " and must come before body");
3968 -- Test result type if given, note that the result type
3969 -- parameter can only be present for the function cases.
3971 if Present (Arg_Result_Type)
3972 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3976 elsif Etype (Def_Id) /= Standard_Void_Type
3978 (Pname = Name_Export_Procedure
3980 Pname = Name_Import_Procedure)
3984 -- Test parameter types if given. Note that this parameter
3985 -- has not been analyzed (and must not be, since it is
3986 -- semantic nonsense), so we get it as the parser left it.
3988 elsif Present (Arg_Parameter_Types) then
3989 Check_Matching_Types : declare
3994 Formal := First_Formal (Def_Id);
3996 if Nkind (Arg_Parameter_Types) = N_Null then
3997 if Present (Formal) then
4001 -- A list of one type, e.g. (List) is parsed as
4002 -- a parenthesized expression.
4004 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4005 and then Paren_Count (Arg_Parameter_Types) = 1
4008 or else Present (Next_Formal (Formal))
4013 Same_Base_Type (Arg_Parameter_Types, Formal);
4016 -- A list of more than one type is parsed as a aggregate
4018 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4019 and then Paren_Count (Arg_Parameter_Types) = 0
4021 Ptype := First (Expressions (Arg_Parameter_Types));
4022 while Present (Ptype) or else Present (Formal) loop
4025 or else not Same_Base_Type (Ptype, Formal)
4030 Next_Formal (Formal);
4035 -- Anything else is of the wrong form
4039 ("wrong form for Parameter_Types parameter",
4040 Arg_Parameter_Types);
4042 end Check_Matching_Types;
4045 -- Match is now False if the entry we found did not match
4046 -- either a supplied Parameter_Types or Result_Types argument
4052 -- Ambiguous case, the flag Ambiguous shows if we already
4053 -- detected this and output the initial messages.
4056 if not Ambiguous then
4058 Error_Msg_Name_1 := Pname;
4060 ("pragma% does not uniquely identify subprogram!",
4062 Error_Msg_Sloc := Sloc (Ent);
4063 Error_Msg_N ("matching subprogram #!", N);
4067 Error_Msg_Sloc := Sloc (Def_Id);
4068 Error_Msg_N ("matching subprogram #!", N);
4073 Hom_Id := Homonym (Hom_Id);
4076 -- See if we found an entry
4079 if not Ambiguous then
4080 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4082 ("pragma% cannot be given for generic subprogram");
4085 ("pragma% does not identify local subprogram");
4092 -- Import pragmas must be for imported entities
4094 if Prag_Id = Pragma_Import_Function
4096 Prag_Id = Pragma_Import_Procedure
4098 Prag_Id = Pragma_Import_Valued_Procedure
4100 if not Is_Imported (Ent) then
4102 ("pragma Import or Interface must precede pragma%");
4105 -- Here we have the Export case which can set the entity as exported
4107 -- But does not do so if the specified external name is null, since
4108 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4109 -- compatible) to request no external name.
4111 elsif Nkind (Arg_External) = N_String_Literal
4112 and then String_Length (Strval (Arg_External)) = 0
4116 -- In all other cases, set entity as exported
4119 Set_Exported (Ent, Arg_Internal);
4122 -- Special processing for Valued_Procedure cases
4124 if Prag_Id = Pragma_Import_Valued_Procedure
4126 Prag_Id = Pragma_Export_Valued_Procedure
4128 Formal := First_Formal (Ent);
4131 Error_Pragma ("at least one parameter required for pragma%");
4133 elsif Ekind (Formal) /= E_Out_Parameter then
4134 Error_Pragma ("first parameter must have mode out for pragma%");
4137 Set_Is_Valued_Procedure (Ent);
4141 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4143 -- Process Result_Mechanism argument if present. We have already
4144 -- checked that this is only allowed for the function case.
4146 if Present (Arg_Result_Mechanism) then
4147 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4150 -- Process Mechanism parameter if present. Note that this parameter
4151 -- is not analyzed, and must not be analyzed since it is semantic
4152 -- nonsense, so we get it in exactly as the parser left it.
4154 if Present (Arg_Mechanism) then
4162 -- A single mechanism association without a formal parameter
4163 -- name is parsed as a parenthesized expression. All other
4164 -- cases are parsed as aggregates, so we rewrite the single
4165 -- parameter case as an aggregate for consistency.
4167 if Nkind (Arg_Mechanism) /= N_Aggregate
4168 and then Paren_Count (Arg_Mechanism) = 1
4170 Rewrite (Arg_Mechanism,
4171 Make_Aggregate (Sloc (Arg_Mechanism),
4172 Expressions => New_List (
4173 Relocate_Node (Arg_Mechanism))));
4176 -- Case of only mechanism name given, applies to all formals
4178 if Nkind (Arg_Mechanism) /= N_Aggregate then
4179 Formal := First_Formal (Ent);
4180 while Present (Formal) loop
4181 Set_Mechanism_Value (Formal, Arg_Mechanism);
4182 Next_Formal (Formal);
4185 -- Case of list of mechanism associations given
4188 if Null_Record_Present (Arg_Mechanism) then
4190 ("inappropriate form for Mechanism parameter",
4194 -- Deal with positional ones first
4196 Formal := First_Formal (Ent);
4198 if Present (Expressions (Arg_Mechanism)) then
4199 Mname := First (Expressions (Arg_Mechanism));
4200 while Present (Mname) loop
4203 ("too many mechanism associations", Mname);
4206 Set_Mechanism_Value (Formal, Mname);
4207 Next_Formal (Formal);
4212 -- Deal with named entries
4214 if Present (Component_Associations (Arg_Mechanism)) then
4215 Massoc := First (Component_Associations (Arg_Mechanism));
4216 while Present (Massoc) loop
4217 Choice := First (Choices (Massoc));
4219 if Nkind (Choice) /= N_Identifier
4220 or else Present (Next (Choice))
4223 ("incorrect form for mechanism association",
4227 Formal := First_Formal (Ent);
4231 ("parameter name & not present", Choice);
4234 if Chars (Choice) = Chars (Formal) then
4236 (Formal, Expression (Massoc));
4238 -- Set entity on identifier (needed by ASIS)
4240 Set_Entity (Choice, Formal);
4245 Next_Formal (Formal);
4255 -- Process First_Optional_Parameter argument if present. We have
4256 -- already checked that this is only allowed for the Import case.
4258 if Present (Arg_First_Optional_Parameter) then
4259 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4261 ("first optional parameter must be formal parameter name",
4262 Arg_First_Optional_Parameter);
4265 Formal := First_Formal (Ent);
4269 ("specified formal parameter& not found",
4270 Arg_First_Optional_Parameter);
4273 exit when Chars (Formal) =
4274 Chars (Arg_First_Optional_Parameter);
4276 Next_Formal (Formal);
4279 Set_First_Optional_Parameter (Ent, Formal);
4281 -- Check specified and all remaining formals have right form
4283 while Present (Formal) loop
4284 if Ekind (Formal) /= E_In_Parameter then
4286 ("optional formal& is not of mode in!",
4287 Arg_First_Optional_Parameter, Formal);
4290 Dval := Default_Value (Formal);
4294 ("optional formal& does not have default value!",
4295 Arg_First_Optional_Parameter, Formal);
4297 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4302 ("default value for optional formal& is non-static!",
4303 Arg_First_Optional_Parameter, Formal);
4307 Set_Is_Optional_Parameter (Formal);
4308 Next_Formal (Formal);
4311 end Process_Extended_Import_Export_Subprogram_Pragma;
4313 --------------------------
4314 -- Process_Generic_List --
4315 --------------------------
4317 procedure Process_Generic_List is
4322 Check_No_Identifiers;
4323 Check_At_Least_N_Arguments (1);
4326 while Present (Arg) loop
4327 Exp := Get_Pragma_Arg (Arg);
4330 if not Is_Entity_Name (Exp)
4332 (not Is_Generic_Instance (Entity (Exp))
4334 not Is_Generic_Unit (Entity (Exp)))
4337 ("pragma% argument must be name of generic unit/instance",
4343 end Process_Generic_List;
4345 ------------------------------------
4346 -- Process_Import_Predefined_Type --
4347 ------------------------------------
4349 procedure Process_Import_Predefined_Type is
4350 Loc : constant Source_Ptr := Sloc (N);
4352 Ftyp : Node_Id := Empty;
4358 String_To_Name_Buffer (Strval (Expression (Arg3)));
4361 Elmt := First_Elmt (Predefined_Float_Types);
4362 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4366 Ftyp := Node (Elmt);
4368 if Present (Ftyp) then
4370 -- Don't build a derived type declaration, because predefined C
4371 -- types have no declaration anywhere, so cannot really be named.
4372 -- Instead build a full type declaration, starting with an
4373 -- appropriate type definition is built
4375 if Is_Floating_Point_Type (Ftyp) then
4376 Def := Make_Floating_Point_Definition (Loc,
4377 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4378 Make_Real_Range_Specification (Loc,
4379 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4380 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4382 -- Should never have a predefined type we cannot handle
4385 raise Program_Error;
4388 -- Build and insert a Full_Type_Declaration, which will be
4389 -- analyzed as soon as this list entry has been analyzed.
4391 Decl := Make_Full_Type_Declaration (Loc,
4392 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4393 Type_Definition => Def);
4395 Insert_After (N, Decl);
4396 Mark_Rewrite_Insertion (Decl);
4399 Error_Pragma_Arg ("no matching type found for pragma%",
4402 end Process_Import_Predefined_Type;
4404 ---------------------------------
4405 -- Process_Import_Or_Interface --
4406 ---------------------------------
4408 procedure Process_Import_Or_Interface is
4414 Process_Convention (C, Def_Id);
4415 Kill_Size_Check_Code (Def_Id);
4416 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4418 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4420 -- We do not permit Import to apply to a renaming declaration
4422 if Present (Renamed_Object (Def_Id)) then
4424 ("pragma% not allowed for object renaming", Arg2);
4426 -- User initialization is not allowed for imported object, but
4427 -- the object declaration may contain a default initialization,
4428 -- that will be discarded. Note that an explicit initialization
4429 -- only counts if it comes from source, otherwise it is simply
4430 -- the code generator making an implicit initialization explicit.
4432 elsif Present (Expression (Parent (Def_Id)))
4433 and then Comes_From_Source (Expression (Parent (Def_Id)))
4435 Error_Msg_Sloc := Sloc (Def_Id);
4437 ("no initialization allowed for declaration of& #",
4438 "\imported entities cannot be initialized (RM B.1(24))",
4442 Set_Imported (Def_Id);
4443 Process_Interface_Name (Def_Id, Arg3, Arg4);
4445 -- Note that we do not set Is_Public here. That's because we
4446 -- only want to set it if there is no address clause, and we
4447 -- don't know that yet, so we delay that processing till
4450 -- pragma Import completes deferred constants
4452 if Ekind (Def_Id) = E_Constant then
4453 Set_Has_Completion (Def_Id);
4456 -- It is not possible to import a constant of an unconstrained
4457 -- array type (e.g. string) because there is no simple way to
4458 -- write a meaningful subtype for it.
4460 if Is_Array_Type (Etype (Def_Id))
4461 and then not Is_Constrained (Etype (Def_Id))
4464 ("imported constant& must have a constrained subtype",
4469 elsif Is_Subprogram (Def_Id)
4470 or else Is_Generic_Subprogram (Def_Id)
4472 -- If the name is overloaded, pragma applies to all of the denoted
4473 -- entities in the same declarative part.
4476 while Present (Hom_Id) loop
4477 Def_Id := Get_Base_Subprogram (Hom_Id);
4479 -- Ignore inherited subprograms because the pragma will apply
4480 -- to the parent operation, which is the one called.
4482 if Is_Overloadable (Def_Id)
4483 and then Present (Alias (Def_Id))
4487 -- If it is not a subprogram, it must be in an outer scope and
4488 -- pragma does not apply.
4490 elsif not Is_Subprogram (Def_Id)
4491 and then not Is_Generic_Subprogram (Def_Id)
4495 -- The pragma does not apply to primitives of interfaces
4497 elsif Is_Dispatching_Operation (Def_Id)
4498 and then Present (Find_Dispatching_Type (Def_Id))
4499 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4503 -- Verify that the homonym is in the same declarative part (not
4504 -- just the same scope).
4506 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4507 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4512 Set_Imported (Def_Id);
4514 -- Reject an Import applied to an abstract subprogram
4516 if Is_Subprogram (Def_Id)
4517 and then Is_Abstract_Subprogram (Def_Id)
4519 Error_Msg_Sloc := Sloc (Def_Id);
4521 ("cannot import abstract subprogram& declared#",
4525 -- Special processing for Convention_Intrinsic
4527 if C = Convention_Intrinsic then
4529 -- Link_Name argument not allowed for intrinsic
4533 Set_Is_Intrinsic_Subprogram (Def_Id);
4535 -- If no external name is present, then check that this
4536 -- is a valid intrinsic subprogram. If an external name
4537 -- is present, then this is handled by the back end.
4540 Check_Intrinsic_Subprogram
4541 (Def_Id, Get_Pragma_Arg (Arg2));
4545 -- All interfaced procedures need an external symbol created
4546 -- for them since they are always referenced from another
4549 Set_Is_Public (Def_Id);
4551 -- Verify that the subprogram does not have a completion
4552 -- through a renaming declaration. For other completions the
4553 -- pragma appears as a too late representation.
4556 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4560 and then Nkind (Decl) = N_Subprogram_Declaration
4561 and then Present (Corresponding_Body (Decl))
4562 and then Nkind (Unit_Declaration_Node
4563 (Corresponding_Body (Decl))) =
4564 N_Subprogram_Renaming_Declaration
4566 Error_Msg_Sloc := Sloc (Def_Id);
4568 ("cannot import&, renaming already provided for " &
4569 "declaration #", N, Def_Id);
4573 Set_Has_Completion (Def_Id);
4574 Process_Interface_Name (Def_Id, Arg3, Arg4);
4577 if Is_Compilation_Unit (Hom_Id) then
4579 -- Its possible homonyms are not affected by the pragma.
4580 -- Such homonyms might be present in the context of other
4581 -- units being compiled.
4586 Hom_Id := Homonym (Hom_Id);
4590 -- When the convention is Java or CIL, we also allow Import to be
4591 -- given for packages, generic packages, exceptions, record
4592 -- components, and access to subprograms.
4594 elsif (C = Convention_Java or else C = Convention_CIL)
4596 (Is_Package_Or_Generic_Package (Def_Id)
4597 or else Ekind (Def_Id) = E_Exception
4598 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4599 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4601 Set_Imported (Def_Id);
4602 Set_Is_Public (Def_Id);
4603 Process_Interface_Name (Def_Id, Arg3, Arg4);
4605 -- Import a CPP class
4607 elsif Is_Record_Type (Def_Id)
4608 and then C = Convention_CPP
4610 -- Types treated as CPP classes must be declared limited (note:
4611 -- this used to be a warning but there is no real benefit to it
4612 -- since we did effectively intend to treat the type as limited
4615 if not Is_Limited_Type (Def_Id) then
4617 ("imported 'C'P'P type must be limited",
4618 Get_Pragma_Arg (Arg2));
4621 Set_Is_CPP_Class (Def_Id);
4623 -- Imported CPP types must not have discriminants (because C++
4624 -- classes do not have discriminants).
4626 if Has_Discriminants (Def_Id) then
4628 ("imported 'C'P'P type cannot have discriminants",
4629 First (Discriminant_Specifications
4630 (Declaration_Node (Def_Id))));
4633 -- Components of imported CPP types must not have default
4634 -- expressions because the constructor (if any) is on the
4638 Tdef : constant Node_Id :=
4639 Type_Definition (Declaration_Node (Def_Id));
4644 if Nkind (Tdef) = N_Record_Definition then
4645 Clist := Component_List (Tdef);
4648 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4649 Clist := Component_List (Record_Extension_Part (Tdef));
4652 if Present (Clist) then
4653 Comp := First (Component_Items (Clist));
4654 while Present (Comp) loop
4655 if Present (Expression (Comp)) then
4657 ("component of imported 'C'P'P type cannot have" &
4658 " default expression", Expression (Comp));
4666 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4668 Check_Arg_Count (3);
4669 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4671 Process_Import_Predefined_Type;
4675 ("second argument of pragma% must be object, subprogram" &
4676 " or incomplete type",
4680 -- If this pragma applies to a compilation unit, then the unit, which
4681 -- is a subprogram, does not require (or allow) a body. We also do
4682 -- not need to elaborate imported procedures.
4684 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4686 Cunit : constant Node_Id := Parent (Parent (N));
4688 Set_Body_Required (Cunit, False);
4691 end Process_Import_Or_Interface;
4693 --------------------
4694 -- Process_Inline --
4695 --------------------
4697 procedure Process_Inline (Active : Boolean) is
4704 Effective : Boolean := False;
4705 -- Set True if inline has some effect, i.e. if there is at least one
4706 -- subprogram set as inlined as a result of the use of the pragma.
4708 procedure Make_Inline (Subp : Entity_Id);
4709 -- Subp is the defining unit name of the subprogram declaration. Set
4710 -- the flag, as well as the flag in the corresponding body, if there
4713 procedure Set_Inline_Flags (Subp : Entity_Id);
4714 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4715 -- Has_Pragma_Inline_Always for the Inline_Always case.
4717 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4718 -- Returns True if it can be determined at this stage that inlining
4719 -- is not possible, for example if the body is available and contains
4720 -- exception handlers, we prevent inlining, since otherwise we can
4721 -- get undefined symbols at link time. This function also emits a
4722 -- warning if front-end inlining is enabled and the pragma appears
4725 -- ??? is business with link symbols still valid, or does it relate
4726 -- to front end ZCX which is being phased out ???
4728 ---------------------------
4729 -- Inlining_Not_Possible --
4730 ---------------------------
4732 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4733 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4737 if Nkind (Decl) = N_Subprogram_Body then
4738 Stats := Handled_Statement_Sequence (Decl);
4739 return Present (Exception_Handlers (Stats))
4740 or else Present (At_End_Proc (Stats));
4742 elsif Nkind (Decl) = N_Subprogram_Declaration
4743 and then Present (Corresponding_Body (Decl))
4745 if Front_End_Inlining
4746 and then Analyzed (Corresponding_Body (Decl))
4748 Error_Msg_N ("pragma appears too late, ignored?", N);
4751 -- If the subprogram is a renaming as body, the body is just a
4752 -- call to the renamed subprogram, and inlining is trivially
4756 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4757 N_Subprogram_Renaming_Declaration
4763 Handled_Statement_Sequence
4764 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4767 Present (Exception_Handlers (Stats))
4768 or else Present (At_End_Proc (Stats));
4772 -- If body is not available, assume the best, the check is
4773 -- performed again when compiling enclosing package bodies.
4777 end Inlining_Not_Possible;
4783 procedure Make_Inline (Subp : Entity_Id) is
4784 Kind : constant Entity_Kind := Ekind (Subp);
4785 Inner_Subp : Entity_Id := Subp;
4788 -- Ignore if bad type, avoid cascaded error
4790 if Etype (Subp) = Any_Type then
4794 -- Ignore if all inlining is suppressed
4796 elsif Suppress_All_Inlining then
4800 -- If inlining is not possible, for now do not treat as an error
4802 elsif Inlining_Not_Possible (Subp) then
4806 -- Here we have a candidate for inlining, but we must exclude
4807 -- derived operations. Otherwise we would end up trying to inline
4808 -- a phantom declaration, and the result would be to drag in a
4809 -- body which has no direct inlining associated with it. That
4810 -- would not only be inefficient but would also result in the
4811 -- backend doing cross-unit inlining in cases where it was
4812 -- definitely inappropriate to do so.
4814 -- However, a simple Comes_From_Source test is insufficient, since
4815 -- we do want to allow inlining of generic instances which also do
4816 -- not come from source. We also need to recognize specs generated
4817 -- by the front-end for bodies that carry the pragma. Finally,
4818 -- predefined operators do not come from source but are not
4819 -- inlineable either.
4821 elsif Is_Generic_Instance (Subp)
4822 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4826 elsif not Comes_From_Source (Subp)
4827 and then Scope (Subp) /= Standard_Standard
4833 -- The referenced entity must either be the enclosing entity, or
4834 -- an entity declared within the current open scope.
4836 if Present (Scope (Subp))
4837 and then Scope (Subp) /= Current_Scope
4838 and then Subp /= Current_Scope
4841 ("argument of% must be entity in current scope", Assoc);
4845 -- Processing for procedure, operator or function. If subprogram
4846 -- is aliased (as for an instance) indicate that the renamed
4847 -- entity (if declared in the same unit) is inlined.
4849 if Is_Subprogram (Subp) then
4850 Inner_Subp := Ultimate_Alias (Inner_Subp);
4852 if In_Same_Source_Unit (Subp, Inner_Subp) then
4853 Set_Inline_Flags (Inner_Subp);
4855 Decl := Parent (Parent (Inner_Subp));
4857 if Nkind (Decl) = N_Subprogram_Declaration
4858 and then Present (Corresponding_Body (Decl))
4860 Set_Inline_Flags (Corresponding_Body (Decl));
4862 elsif Is_Generic_Instance (Subp) then
4864 -- Indicate that the body needs to be created for
4865 -- inlining subsequent calls. The instantiation node
4866 -- follows the declaration of the wrapper package
4869 if Scope (Subp) /= Standard_Standard
4871 Need_Subprogram_Instance_Body
4872 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4878 -- Inline is a program unit pragma (RM 10.1.5) and cannot
4879 -- appear in a formal part to apply to a formal subprogram.
4880 -- Do not apply check within an instance or a formal package
4881 -- the test will have been applied to the original generic.
4883 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4884 and then List_Containing (Decl) = List_Containing (N)
4885 and then not In_Instance
4888 ("Inline cannot apply to a formal subprogram", N);
4894 -- For a generic subprogram set flag as well, for use at the point
4895 -- of instantiation, to determine whether the body should be
4898 elsif Is_Generic_Subprogram (Subp) then
4899 Set_Inline_Flags (Subp);
4902 -- Literals are by definition inlined
4904 elsif Kind = E_Enumeration_Literal then
4907 -- Anything else is an error
4911 ("expect subprogram name for pragma%", Assoc);
4915 ----------------------
4916 -- Set_Inline_Flags --
4917 ----------------------
4919 procedure Set_Inline_Flags (Subp : Entity_Id) is
4922 Set_Is_Inlined (Subp);
4925 if not Has_Pragma_Inline (Subp) then
4926 Set_Has_Pragma_Inline (Subp);
4930 if Prag_Id = Pragma_Inline_Always then
4931 Set_Has_Pragma_Inline_Always (Subp);
4933 end Set_Inline_Flags;
4935 -- Start of processing for Process_Inline
4938 Check_No_Identifiers;
4939 Check_At_Least_N_Arguments (1);
4942 Inline_Processing_Required := True;
4946 while Present (Assoc) loop
4947 Subp_Id := Get_Pragma_Arg (Assoc);
4951 if Is_Entity_Name (Subp_Id) then
4952 Subp := Entity (Subp_Id);
4954 if Subp = Any_Id then
4956 -- If previous error, avoid cascaded errors
4964 -- For the pragma case, climb homonym chain. This is
4965 -- what implements allowing the pragma in the renaming
4966 -- case, with the result applying to the ancestors, and
4967 -- also allows Inline to apply to all previous homonyms.
4969 if not From_Aspect_Specification (N) then
4970 while Present (Homonym (Subp))
4971 and then Scope (Homonym (Subp)) = Current_Scope
4973 Make_Inline (Homonym (Subp));
4974 Subp := Homonym (Subp);
4982 ("inappropriate argument for pragma%", Assoc);
4985 and then Warn_On_Redundant_Constructs
4986 and then not Suppress_All_Inlining
4988 if Inlining_Not_Possible (Subp) then
4990 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4993 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
5001 ----------------------------
5002 -- Process_Interface_Name --
5003 ----------------------------
5005 procedure Process_Interface_Name
5006 (Subprogram_Def : Entity_Id;
5012 String_Val : String_Id;
5014 procedure Check_Form_Of_Interface_Name
5016 Ext_Name_Case : Boolean);
5017 -- SN is a string literal node for an interface name. This routine
5018 -- performs some minimal checks that the name is reasonable. In
5019 -- particular that no spaces or other obviously incorrect characters
5020 -- appear. This is only a warning, since any characters are allowed.
5021 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5023 ----------------------------------
5024 -- Check_Form_Of_Interface_Name --
5025 ----------------------------------
5027 procedure Check_Form_Of_Interface_Name
5029 Ext_Name_Case : Boolean)
5031 S : constant String_Id := Strval (Expr_Value_S (SN));
5032 SL : constant Nat := String_Length (S);
5037 Error_Msg_N ("interface name cannot be null string", SN);
5040 for J in 1 .. SL loop
5041 C := Get_String_Char (S, J);
5043 -- Look for dubious character and issue unconditional warning.
5044 -- Definitely dubious if not in character range.
5046 if not In_Character_Range (C)
5048 -- For all cases except CLI target,
5049 -- commas, spaces and slashes are dubious (in CLI, we use
5050 -- commas and backslashes in external names to specify
5051 -- assembly version and public key, while slashes and spaces
5052 -- can be used in names to mark nested classes and
5055 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5056 and then (Get_Character (C) = ','
5058 Get_Character (C) = '\'))
5059 or else (VM_Target /= CLI_Target
5060 and then (Get_Character (C) = ' '
5062 Get_Character (C) = '/'))
5065 ("?interface name contains illegal character",
5066 Sloc (SN) + Source_Ptr (J));
5069 end Check_Form_Of_Interface_Name;
5071 -- Start of processing for Process_Interface_Name
5074 if No (Link_Arg) then
5075 if No (Ext_Arg) then
5076 if VM_Target = CLI_Target
5077 and then Ekind (Subprogram_Def) = E_Package
5078 and then Nkind (Parent (Subprogram_Def)) =
5079 N_Package_Specification
5080 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5085 (Generic_Parent (Parent (Subprogram_Def))));
5090 elsif Chars (Ext_Arg) = Name_Link_Name then
5092 Link_Nam := Expression (Ext_Arg);
5095 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5096 Ext_Nam := Expression (Ext_Arg);
5101 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5102 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5103 Ext_Nam := Expression (Ext_Arg);
5104 Link_Nam := Expression (Link_Arg);
5107 -- Check expressions for external name and link name are static
5109 if Present (Ext_Nam) then
5110 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5111 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5113 -- Verify that external name is not the name of a local entity,
5114 -- which would hide the imported one and could lead to run-time
5115 -- surprises. The problem can only arise for entities declared in
5116 -- a package body (otherwise the external name is fully qualified
5117 -- and will not conflict).
5125 if Prag_Id = Pragma_Import then
5126 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5128 E := Entity_Id (Get_Name_Table_Info (Nam));
5130 if Nam /= Chars (Subprogram_Def)
5131 and then Present (E)
5132 and then not Is_Overloadable (E)
5133 and then Is_Immediately_Visible (E)
5134 and then not Is_Imported (E)
5135 and then Ekind (Scope (E)) = E_Package
5138 while Present (Par) loop
5139 if Nkind (Par) = N_Package_Body then
5140 Error_Msg_Sloc := Sloc (E);
5142 ("imported entity is hidden by & declared#",
5147 Par := Parent (Par);
5154 if Present (Link_Nam) then
5155 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5156 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5159 -- If there is no link name, just set the external name
5161 if No (Link_Nam) then
5162 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5164 -- For the Link_Name case, the given literal is preceded by an
5165 -- asterisk, which indicates to GCC that the given name should be
5166 -- taken literally, and in particular that no prepending of
5167 -- underlines should occur, even in systems where this is the
5173 if VM_Target = No_VM then
5174 Store_String_Char (Get_Char_Code ('*'));
5177 String_Val := Strval (Expr_Value_S (Link_Nam));
5178 Store_String_Chars (String_Val);
5180 Make_String_Literal (Sloc (Link_Nam),
5181 Strval => End_String);
5184 -- Set the interface name. If the entity is a generic instance, use
5185 -- its alias, which is the callable entity.
5187 if Is_Generic_Instance (Subprogram_Def) then
5188 Set_Encoded_Interface_Name
5189 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5191 Set_Encoded_Interface_Name
5192 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5195 -- We allow duplicated export names in CIL/Java, as they are always
5196 -- enclosed in a namespace that differentiates them, and overloaded
5197 -- entities are supported by the VM.
5199 if Convention (Subprogram_Def) /= Convention_CIL
5201 Convention (Subprogram_Def) /= Convention_Java
5203 Check_Duplicated_Export_Name (Link_Nam);
5205 end Process_Interface_Name;
5207 -----------------------------------------
5208 -- Process_Interrupt_Or_Attach_Handler --
5209 -----------------------------------------
5211 procedure Process_Interrupt_Or_Attach_Handler is
5212 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5213 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5214 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5217 Set_Is_Interrupt_Handler (Handler_Proc);
5219 -- If the pragma is not associated with a handler procedure within a
5220 -- protected type, then it must be for a nonprotected procedure for
5221 -- the AAMP target, in which case we don't associate a representation
5222 -- item with the procedure's scope.
5224 if Ekind (Proc_Scope) = E_Protected_Type then
5225 if Prag_Id = Pragma_Interrupt_Handler
5227 Prag_Id = Pragma_Attach_Handler
5229 Record_Rep_Item (Proc_Scope, N);
5232 end Process_Interrupt_Or_Attach_Handler;
5234 --------------------------------------------------
5235 -- Process_Restrictions_Or_Restriction_Warnings --
5236 --------------------------------------------------
5238 -- Note: some of the simple identifier cases were handled in par-prag,
5239 -- but it is harmless (and more straightforward) to simply handle all
5240 -- cases here, even if it means we repeat a bit of work in some cases.
5242 procedure Process_Restrictions_Or_Restriction_Warnings
5246 R_Id : Restriction_Id;
5251 procedure Check_Unit_Name (N : Node_Id);
5252 -- Checks unit name parameter for No_Dependence. Returns if it has
5253 -- an appropriate form, otherwise raises pragma argument error.
5255 ---------------------
5256 -- Check_Unit_Name --
5257 ---------------------
5259 procedure Check_Unit_Name (N : Node_Id) is
5261 if Nkind (N) = N_Selected_Component then
5262 Check_Unit_Name (Prefix (N));
5263 Check_Unit_Name (Selector_Name (N));
5265 elsif Nkind (N) = N_Identifier then
5270 ("wrong form for unit name for No_Dependence", N);
5272 end Check_Unit_Name;
5274 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5277 -- Ignore all Restrictions pragma in CodePeer mode
5279 if CodePeer_Mode then
5283 Check_Ada_83_Warning;
5284 Check_At_Least_N_Arguments (1);
5285 Check_Valid_Configuration_Pragma;
5288 while Present (Arg) loop
5290 Expr := Get_Pragma_Arg (Arg);
5292 -- Case of no restriction identifier present
5294 if Id = No_Name then
5295 if Nkind (Expr) /= N_Identifier then
5297 ("invalid form for restriction", Arg);
5302 (Process_Restriction_Synonyms (Expr));
5304 if R_Id not in All_Boolean_Restrictions then
5305 Error_Msg_Name_1 := Pname;
5307 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5309 -- Check for possible misspelling
5311 for J in Restriction_Id loop
5313 Rnm : constant String := Restriction_Id'Image (J);
5316 Name_Buffer (1 .. Rnm'Length) := Rnm;
5317 Name_Len := Rnm'Length;
5318 Set_Casing (All_Lower_Case);
5320 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5322 (Identifier_Casing (Current_Source_File));
5323 Error_Msg_String (1 .. Rnm'Length) :=
5324 Name_Buffer (1 .. Name_Len);
5325 Error_Msg_Strlen := Rnm'Length;
5326 Error_Msg_N -- CODEFIX
5327 ("\possible misspelling of ""~""",
5328 Get_Pragma_Arg (Arg));
5337 if Implementation_Restriction (R_Id) then
5338 Check_Restriction (No_Implementation_Restrictions, Arg);
5341 -- If this is a warning, then set the warning unless we already
5342 -- have a real restriction active (we never want a warning to
5343 -- override a real restriction).
5346 if not Restriction_Active (R_Id) then
5347 Set_Restriction (R_Id, N);
5348 Restriction_Warnings (R_Id) := True;
5351 -- If real restriction case, then set it and make sure that the
5352 -- restriction warning flag is off, since a real restriction
5353 -- always overrides a warning.
5356 Set_Restriction (R_Id, N);
5357 Restriction_Warnings (R_Id) := False;
5360 -- Check for obsolescent restrictions in Ada 2005 mode
5363 and then Ada_Version >= Ada_2005
5364 and then (R_Id = No_Asynchronous_Control
5366 R_Id = No_Unchecked_Deallocation
5368 R_Id = No_Unchecked_Conversion)
5370 Check_Restriction (No_Obsolescent_Features, N);
5373 -- A very special case that must be processed here: pragma
5374 -- Restrictions (No_Exceptions) turns off all run-time
5375 -- checking. This is a bit dubious in terms of the formal
5376 -- language definition, but it is what is intended by RM
5377 -- H.4(12). Restriction_Warnings never affects generated code
5378 -- so this is done only in the real restriction case.
5380 -- Atomic_Synchronization is not a real check, so it is not
5381 -- affected by this processing).
5383 if R_Id = No_Exceptions and then not Warn then
5384 for J in Scope_Suppress'Range loop
5385 if J /= Atomic_Synchronization then
5386 Scope_Suppress (J) := True;
5391 -- Case of No_Dependence => unit-name. Note that the parser
5392 -- already made the necessary entry in the No_Dependence table.
5394 elsif Id = Name_No_Dependence then
5395 Check_Unit_Name (Expr);
5397 -- Case of No_Specification_Of_Aspect => Identifier.
5399 elsif Id = Name_No_Specification_Of_Aspect then
5404 if Nkind (Expr) /= N_Identifier then
5407 A_Id := Get_Aspect_Id (Chars (Expr));
5410 if A_Id = No_Aspect then
5411 Error_Pragma_Arg ("invalid restriction name", Arg);
5413 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5417 -- All other cases of restriction identifier present
5420 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5421 Analyze_And_Resolve (Expr, Any_Integer);
5423 if R_Id not in All_Parameter_Restrictions then
5425 ("invalid restriction parameter identifier", Arg);
5427 elsif not Is_OK_Static_Expression (Expr) then
5428 Flag_Non_Static_Expr
5429 ("value must be static expression!", Expr);
5432 elsif not Is_Integer_Type (Etype (Expr))
5433 or else Expr_Value (Expr) < 0
5436 ("value must be non-negative integer", Arg);
5439 -- Restriction pragma is active
5441 Val := Expr_Value (Expr);
5443 if not UI_Is_In_Int_Range (Val) then
5445 ("pragma ignored, value too large?", Arg);
5448 -- Warning case. If the real restriction is active, then we
5449 -- ignore the request, since warning never overrides a real
5450 -- restriction. Otherwise we set the proper warning. Note that
5451 -- this circuit sets the warning again if it is already set,
5452 -- which is what we want, since the constant may have changed.
5455 if not Restriction_Active (R_Id) then
5457 (R_Id, N, Integer (UI_To_Int (Val)));
5458 Restriction_Warnings (R_Id) := True;
5461 -- Real restriction case, set restriction and make sure warning
5462 -- flag is off since real restriction always overrides warning.
5465 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5466 Restriction_Warnings (R_Id) := False;
5472 end Process_Restrictions_Or_Restriction_Warnings;
5474 ---------------------------------
5475 -- Process_Suppress_Unsuppress --
5476 ---------------------------------
5478 -- Note: this procedure makes entries in the check suppress data
5479 -- structures managed by Sem. See spec of package Sem for full
5480 -- details on how we handle recording of check suppression.
5482 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5487 In_Package_Spec : constant Boolean :=
5488 Is_Package_Or_Generic_Package (Current_Scope)
5489 and then not In_Package_Body (Current_Scope);
5491 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5492 -- Used to suppress a single check on the given entity
5494 --------------------------------
5495 -- Suppress_Unsuppress_Echeck --
5496 --------------------------------
5498 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5500 -- Check for error of trying to set atomic synchronization for
5501 -- a non-atomic variable.
5503 if C = Atomic_Synchronization
5504 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5507 ("pragma & requires atomic type or variable",
5508 Pragma_Identifier (Original_Node (N)));
5511 Set_Checks_May_Be_Suppressed (E);
5513 if In_Package_Spec then
5514 Push_Global_Suppress_Stack_Entry
5517 Suppress => Suppress_Case);
5519 Push_Local_Suppress_Stack_Entry
5522 Suppress => Suppress_Case);
5525 -- If this is a first subtype, and the base type is distinct,
5526 -- then also set the suppress flags on the base type.
5528 if Is_First_Subtype (E)
5529 and then Etype (E) /= E
5531 Suppress_Unsuppress_Echeck (Etype (E), C);
5533 end Suppress_Unsuppress_Echeck;
5535 -- Start of processing for Process_Suppress_Unsuppress
5538 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5539 -- user code: we want to generate checks for analysis purposes, as
5540 -- set respectively by -gnatC and -gnatd.F
5542 if (CodePeer_Mode or Alfa_Mode)
5543 and then Comes_From_Source (N)
5548 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5549 -- declarative part or a package spec (RM 11.5(5)).
5551 if not Is_Configuration_Pragma then
5552 Check_Is_In_Decl_Part_Or_Package_Spec;
5555 Check_At_Least_N_Arguments (1);
5556 Check_At_Most_N_Arguments (2);
5557 Check_No_Identifier (Arg1);
5558 Check_Arg_Is_Identifier (Arg1);
5560 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5562 if C = No_Check_Id then
5564 ("argument of pragma% is not valid check name", Arg1);
5567 if not Suppress_Case
5568 and then (C = All_Checks or else C = Overflow_Check)
5570 Opt.Overflow_Checks_Unsuppressed := True;
5573 if Arg_Count = 1 then
5575 -- Make an entry in the local scope suppress table. This is the
5576 -- table that directly shows the current value of the scope
5577 -- suppress check for any check id value.
5579 if C = All_Checks then
5581 -- For All_Checks, we set all specific predefined checks with
5582 -- the exception of Elaboration_Check, which is handled
5583 -- specially because of not wanting All_Checks to have the
5584 -- effect of deactivating static elaboration order processing.
5585 -- Atomic_Synchronization is also not affected, since this is
5586 -- not a real check.
5588 for J in Scope_Suppress'Range loop
5589 if J /= Elaboration_Check
5590 and then J /= Atomic_Synchronization
5592 Scope_Suppress (J) := Suppress_Case;
5596 -- If not All_Checks, and predefined check, then set appropriate
5597 -- scope entry. Note that we will set Elaboration_Check if this
5598 -- is explicitly specified. Atomic_Synchronization is allowed
5599 -- only if internally generated and entity is atomic.
5601 elsif C in Predefined_Check_Id
5602 and then (not Comes_From_Source (N)
5603 or else C /= Atomic_Synchronization)
5605 Scope_Suppress (C) := Suppress_Case;
5608 -- Also make an entry in the Local_Entity_Suppress table
5610 Push_Local_Suppress_Stack_Entry
5613 Suppress => Suppress_Case);
5615 -- Case of two arguments present, where the check is suppressed for
5616 -- a specified entity (given as the second argument of the pragma)
5619 -- This is obsolescent in Ada 2005 mode
5621 if Ada_Version >= Ada_2005 then
5622 Check_Restriction (No_Obsolescent_Features, Arg2);
5625 Check_Optional_Identifier (Arg2, Name_On);
5626 E_Id := Get_Pragma_Arg (Arg2);
5629 if not Is_Entity_Name (E_Id) then
5631 ("second argument of pragma% must be entity name", Arg2);
5640 -- Enforce RM 11.5(7) which requires that for a pragma that
5641 -- appears within a package spec, the named entity must be
5642 -- within the package spec. We allow the package name itself
5643 -- to be mentioned since that makes sense, although it is not
5644 -- strictly allowed by 11.5(7).
5647 and then E /= Current_Scope
5648 and then Scope (E) /= Current_Scope
5651 ("entity in pragma% is not in package spec (RM 11.5(7))",
5655 -- Loop through homonyms. As noted below, in the case of a package
5656 -- spec, only homonyms within the package spec are considered.
5659 Suppress_Unsuppress_Echeck (E, C);
5661 if Is_Generic_Instance (E)
5662 and then Is_Subprogram (E)
5663 and then Present (Alias (E))
5665 Suppress_Unsuppress_Echeck (Alias (E), C);
5668 -- Move to next homonym if not aspect spec case
5670 exit when From_Aspect_Specification (N);
5674 -- If we are within a package specification, the pragma only
5675 -- applies to homonyms in the same scope.
5677 exit when In_Package_Spec
5678 and then Scope (E) /= Current_Scope;
5681 end Process_Suppress_Unsuppress;
5687 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5689 if Is_Imported (E) then
5691 ("cannot export entity& that was previously imported", Arg);
5693 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5695 ("cannot export entity& that has an address clause", Arg);
5698 Set_Is_Exported (E);
5700 -- Generate a reference for entity explicitly, because the
5701 -- identifier may be overloaded and name resolution will not
5704 Generate_Reference (E, Arg);
5706 -- Deal with exporting non-library level entity
5708 if not Is_Library_Level_Entity (E) then
5710 -- Not allowed at all for subprograms
5712 if Is_Subprogram (E) then
5713 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5715 -- Otherwise set public and statically allocated
5719 Set_Is_Statically_Allocated (E);
5721 -- Warn if the corresponding W flag is set and the pragma comes
5722 -- from source. The latter may not be true e.g. on VMS where we
5723 -- expand export pragmas for exception codes associated with
5724 -- imported or exported exceptions. We do not want to generate
5725 -- a warning for something that the user did not write.
5727 if Warn_On_Export_Import
5728 and then Comes_From_Source (Arg)
5731 ("?& has been made static as a result of Export", Arg, E);
5733 ("\this usage is non-standard and non-portable", Arg);
5738 if Warn_On_Export_Import and then Is_Type (E) then
5739 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5742 if Warn_On_Export_Import and Inside_A_Generic then
5744 ("all instances of& will have the same external name?", Arg, E);
5748 ----------------------------------------------
5749 -- Set_Extended_Import_Export_External_Name --
5750 ----------------------------------------------
5752 procedure Set_Extended_Import_Export_External_Name
5753 (Internal_Ent : Entity_Id;
5754 Arg_External : Node_Id)
5756 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5760 if No (Arg_External) then
5764 Check_Arg_Is_External_Name (Arg_External);
5766 if Nkind (Arg_External) = N_String_Literal then
5767 if String_Length (Strval (Arg_External)) = 0 then
5770 New_Name := Adjust_External_Name_Case (Arg_External);
5773 elsif Nkind (Arg_External) = N_Identifier then
5774 New_Name := Get_Default_External_Name (Arg_External);
5776 -- Check_Arg_Is_External_Name should let through only identifiers and
5777 -- string literals or static string expressions (which are folded to
5778 -- string literals).
5781 raise Program_Error;
5784 -- If we already have an external name set (by a prior normal Import
5785 -- or Export pragma), then the external names must match
5787 if Present (Interface_Name (Internal_Ent)) then
5788 Check_Matching_Internal_Names : declare
5789 S1 : constant String_Id := Strval (Old_Name);
5790 S2 : constant String_Id := Strval (New_Name);
5793 -- Called if names do not match
5799 procedure Mismatch is
5801 Error_Msg_Sloc := Sloc (Old_Name);
5803 ("external name does not match that given #",
5807 -- Start of processing for Check_Matching_Internal_Names
5810 if String_Length (S1) /= String_Length (S2) then
5814 for J in 1 .. String_Length (S1) loop
5815 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5820 end Check_Matching_Internal_Names;
5822 -- Otherwise set the given name
5825 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5826 Check_Duplicated_Export_Name (New_Name);
5828 end Set_Extended_Import_Export_External_Name;
5834 procedure Set_Imported (E : Entity_Id) is
5836 -- Error message if already imported or exported
5838 if Is_Exported (E) or else Is_Imported (E) then
5840 -- Error if being set Exported twice
5842 if Is_Exported (E) then
5843 Error_Msg_NE ("entity& was previously exported", N, E);
5845 -- OK if Import/Interface case
5847 elsif Import_Interface_Present (N) then
5850 -- Error if being set Imported twice
5853 Error_Msg_NE ("entity& was previously imported", N, E);
5856 Error_Msg_Name_1 := Pname;
5858 ("\(pragma% applies to all previous entities)", N);
5860 Error_Msg_Sloc := Sloc (E);
5861 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5863 -- Here if not previously imported or exported, OK to import
5866 Set_Is_Imported (E);
5868 -- If the entity is an object that is not at the library level,
5869 -- then it is statically allocated. We do not worry about objects
5870 -- with address clauses in this context since they are not really
5871 -- imported in the linker sense.
5874 and then not Is_Library_Level_Entity (E)
5875 and then No (Address_Clause (E))
5877 Set_Is_Statically_Allocated (E);
5884 -------------------------
5885 -- Set_Mechanism_Value --
5886 -------------------------
5888 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5889 -- analyzed, since it is semantic nonsense), so we get it in the exact
5890 -- form created by the parser.
5892 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5895 Mech_Name_Id : Name_Id;
5897 procedure Bad_Class;
5898 -- Signal bad descriptor class name
5900 procedure Bad_Mechanism;
5901 -- Signal bad mechanism name
5907 procedure Bad_Class is
5909 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5912 -------------------------
5913 -- Bad_Mechanism_Value --
5914 -------------------------
5916 procedure Bad_Mechanism is
5918 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5921 -- Start of processing for Set_Mechanism_Value
5924 if Mechanism (Ent) /= Default_Mechanism then
5926 ("mechanism for & has already been set", Mech_Name, Ent);
5929 -- MECHANISM_NAME ::= value | reference | descriptor |
5932 if Nkind (Mech_Name) = N_Identifier then
5933 if Chars (Mech_Name) = Name_Value then
5934 Set_Mechanism (Ent, By_Copy);
5937 elsif Chars (Mech_Name) = Name_Reference then
5938 Set_Mechanism (Ent, By_Reference);
5941 elsif Chars (Mech_Name) = Name_Descriptor then
5942 Check_VMS (Mech_Name);
5944 -- Descriptor => Short_Descriptor if pragma was given
5946 if Short_Descriptors then
5947 Set_Mechanism (Ent, By_Short_Descriptor);
5949 Set_Mechanism (Ent, By_Descriptor);
5954 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5955 Check_VMS (Mech_Name);
5956 Set_Mechanism (Ent, By_Short_Descriptor);
5959 elsif Chars (Mech_Name) = Name_Copy then
5961 ("bad mechanism name, Value assumed", Mech_Name);
5967 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5968 -- short_descriptor (CLASS_NAME)
5969 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5971 -- Note: this form is parsed as an indexed component
5973 elsif Nkind (Mech_Name) = N_Indexed_Component then
5974 Class := First (Expressions (Mech_Name));
5976 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5977 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5978 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5979 or else Present (Next (Class))
5983 Mech_Name_Id := Chars (Prefix (Mech_Name));
5985 -- Change Descriptor => Short_Descriptor if pragma was given
5987 if Mech_Name_Id = Name_Descriptor
5988 and then Short_Descriptors
5990 Mech_Name_Id := Name_Short_Descriptor;
5994 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5995 -- short_descriptor (Class => CLASS_NAME)
5996 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5998 -- Note: this form is parsed as a function call
6000 elsif Nkind (Mech_Name) = N_Function_Call then
6001 Param := First (Parameter_Associations (Mech_Name));
6003 if Nkind (Name (Mech_Name)) /= N_Identifier
6004 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6005 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6006 or else Present (Next (Param))
6007 or else No (Selector_Name (Param))
6008 or else Chars (Selector_Name (Param)) /= Name_Class
6012 Class := Explicit_Actual_Parameter (Param);
6013 Mech_Name_Id := Chars (Name (Mech_Name));
6020 -- Fall through here with Class set to descriptor class name
6022 Check_VMS (Mech_Name);
6024 if Nkind (Class) /= N_Identifier then
6027 elsif Mech_Name_Id = Name_Descriptor
6028 and then Chars (Class) = Name_UBS
6030 Set_Mechanism (Ent, By_Descriptor_UBS);
6032 elsif Mech_Name_Id = Name_Descriptor
6033 and then Chars (Class) = Name_UBSB
6035 Set_Mechanism (Ent, By_Descriptor_UBSB);
6037 elsif Mech_Name_Id = Name_Descriptor
6038 and then Chars (Class) = Name_UBA
6040 Set_Mechanism (Ent, By_Descriptor_UBA);
6042 elsif Mech_Name_Id = Name_Descriptor
6043 and then Chars (Class) = Name_S
6045 Set_Mechanism (Ent, By_Descriptor_S);
6047 elsif Mech_Name_Id = Name_Descriptor
6048 and then Chars (Class) = Name_SB
6050 Set_Mechanism (Ent, By_Descriptor_SB);
6052 elsif Mech_Name_Id = Name_Descriptor
6053 and then Chars (Class) = Name_A
6055 Set_Mechanism (Ent, By_Descriptor_A);
6057 elsif Mech_Name_Id = Name_Descriptor
6058 and then Chars (Class) = Name_NCA
6060 Set_Mechanism (Ent, By_Descriptor_NCA);
6062 elsif Mech_Name_Id = Name_Short_Descriptor
6063 and then Chars (Class) = Name_UBS
6065 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6067 elsif Mech_Name_Id = Name_Short_Descriptor
6068 and then Chars (Class) = Name_UBSB
6070 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6072 elsif Mech_Name_Id = Name_Short_Descriptor
6073 and then Chars (Class) = Name_UBA
6075 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6077 elsif Mech_Name_Id = Name_Short_Descriptor
6078 and then Chars (Class) = Name_S
6080 Set_Mechanism (Ent, By_Short_Descriptor_S);
6082 elsif Mech_Name_Id = Name_Short_Descriptor
6083 and then Chars (Class) = Name_SB
6085 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6087 elsif Mech_Name_Id = Name_Short_Descriptor
6088 and then Chars (Class) = Name_A
6090 Set_Mechanism (Ent, By_Short_Descriptor_A);
6092 elsif Mech_Name_Id = Name_Short_Descriptor
6093 and then Chars (Class) = Name_NCA
6095 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6100 end Set_Mechanism_Value;
6102 ---------------------------
6103 -- Set_Ravenscar_Profile --
6104 ---------------------------
6106 -- The tasks to be done here are
6108 -- Set required policies
6110 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6111 -- pragma Locking_Policy (Ceiling_Locking)
6113 -- Set Detect_Blocking mode
6115 -- Set required restrictions (see System.Rident for detailed list)
6117 -- Set the No_Dependence rules
6118 -- No_Dependence => Ada.Asynchronous_Task_Control
6119 -- No_Dependence => Ada.Calendar
6120 -- No_Dependence => Ada.Execution_Time.Group_Budget
6121 -- No_Dependence => Ada.Execution_Time.Timers
6122 -- No_Dependence => Ada.Task_Attributes
6123 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6125 procedure Set_Ravenscar_Profile (N : Node_Id) is
6126 Prefix_Entity : Entity_Id;
6127 Selector_Entity : Entity_Id;
6128 Prefix_Node : Node_Id;
6132 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6134 if Task_Dispatching_Policy /= ' '
6135 and then Task_Dispatching_Policy /= 'F'
6137 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6138 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6140 -- Set the FIFO_Within_Priorities policy, but always preserve
6141 -- System_Location since we like the error message with the run time
6145 Task_Dispatching_Policy := 'F';
6147 if Task_Dispatching_Policy_Sloc /= System_Location then
6148 Task_Dispatching_Policy_Sloc := Loc;
6152 -- pragma Locking_Policy (Ceiling_Locking)
6154 if Locking_Policy /= ' '
6155 and then Locking_Policy /= 'C'
6157 Error_Msg_Sloc := Locking_Policy_Sloc;
6158 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6160 -- Set the Ceiling_Locking policy, but preserve System_Location since
6161 -- we like the error message with the run time name.
6164 Locking_Policy := 'C';
6166 if Locking_Policy_Sloc /= System_Location then
6167 Locking_Policy_Sloc := Loc;
6171 -- pragma Detect_Blocking
6173 Detect_Blocking := True;
6175 -- Set the corresponding restrictions
6177 Set_Profile_Restrictions
6178 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6180 -- Set the No_Dependence restrictions
6182 -- The following No_Dependence restrictions:
6183 -- No_Dependence => Ada.Asynchronous_Task_Control
6184 -- No_Dependence => Ada.Calendar
6185 -- No_Dependence => Ada.Task_Attributes
6186 -- are already set by previous call to Set_Profile_Restrictions.
6188 -- Set the following restrictions which were added to Ada 2005:
6189 -- No_Dependence => Ada.Execution_Time.Group_Budget
6190 -- No_Dependence => Ada.Execution_Time.Timers
6192 if Ada_Version >= Ada_2005 then
6193 Name_Buffer (1 .. 3) := "ada";
6196 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6198 Name_Buffer (1 .. 14) := "execution_time";
6201 Selector_Entity := Make_Identifier (Loc, Name_Find);
6204 Make_Selected_Component
6206 Prefix => Prefix_Entity,
6207 Selector_Name => Selector_Entity);
6209 Name_Buffer (1 .. 13) := "group_budgets";
6212 Selector_Entity := Make_Identifier (Loc, Name_Find);
6215 Make_Selected_Component
6217 Prefix => Prefix_Node,
6218 Selector_Name => Selector_Entity);
6220 Set_Restriction_No_Dependence
6222 Warn => Treat_Restrictions_As_Warnings,
6223 Profile => Ravenscar);
6225 Name_Buffer (1 .. 6) := "timers";
6228 Selector_Entity := Make_Identifier (Loc, Name_Find);
6231 Make_Selected_Component
6233 Prefix => Prefix_Node,
6234 Selector_Name => Selector_Entity);
6236 Set_Restriction_No_Dependence
6238 Warn => Treat_Restrictions_As_Warnings,
6239 Profile => Ravenscar);
6242 -- Set the following restrictions which was added to Ada 2012 (see
6244 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6246 if Ada_Version >= Ada_2012 then
6247 Name_Buffer (1 .. 6) := "system";
6250 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6252 Name_Buffer (1 .. 15) := "multiprocessors";
6255 Selector_Entity := Make_Identifier (Loc, Name_Find);
6258 Make_Selected_Component
6260 Prefix => Prefix_Entity,
6261 Selector_Name => Selector_Entity);
6263 Name_Buffer (1 .. 19) := "dispatching_domains";
6266 Selector_Entity := Make_Identifier (Loc, Name_Find);
6269 Make_Selected_Component
6271 Prefix => Prefix_Node,
6272 Selector_Name => Selector_Entity);
6274 Set_Restriction_No_Dependence
6276 Warn => Treat_Restrictions_As_Warnings,
6277 Profile => Ravenscar);
6279 end Set_Ravenscar_Profile;
6281 -- Start of processing for Analyze_Pragma
6284 -- The following code is a defense against recursion. Not clear that
6285 -- this can happen legitimately, but perhaps some error situations
6286 -- can cause it, and we did see this recursion during testing.
6288 if Analyzed (N) then
6291 Set_Analyzed (N, True);
6294 -- Deal with unrecognized pragma
6296 Pname := Pragma_Name (N);
6298 if not Is_Pragma_Name (Pname) then
6299 if Warn_On_Unrecognized_Pragma then
6300 Error_Msg_Name_1 := Pname;
6301 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6303 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6304 if Is_Bad_Spelling_Of (Pname, PN) then
6305 Error_Msg_Name_1 := PN;
6306 Error_Msg_N -- CODEFIX
6307 ("\?possible misspelling of %!", Pragma_Identifier (N));
6316 -- Here to start processing for recognized pragma
6318 Prag_Id := Get_Pragma_Id (Pname);
6320 if Present (Corresponding_Aspect (N)) then
6321 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6332 if Present (Pragma_Argument_Associations (N)) then
6333 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6334 Arg1 := First (Pragma_Argument_Associations (N));
6336 if Present (Arg1) then
6337 Arg2 := Next (Arg1);
6339 if Present (Arg2) then
6340 Arg3 := Next (Arg2);
6342 if Present (Arg3) then
6343 Arg4 := Next (Arg3);
6349 -- An enumeration type defines the pragmas that are supported by the
6350 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6351 -- into the corresponding enumeration value for the following case.
6359 -- pragma Abort_Defer;
6361 when Pragma_Abort_Defer =>
6363 Check_Arg_Count (0);
6365 -- The only required semantic processing is to check the
6366 -- placement. This pragma must appear at the start of the
6367 -- statement sequence of a handled sequence of statements.
6369 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6370 or else N /= First (Statements (Parent (N)))
6381 -- Note: this pragma also has some specific processing in Par.Prag
6382 -- because we want to set the Ada version mode during parsing.
6384 when Pragma_Ada_83 =>
6386 Check_Arg_Count (0);
6388 -- We really should check unconditionally for proper configuration
6389 -- pragma placement, since we really don't want mixed Ada modes
6390 -- within a single unit, and the GNAT reference manual has always
6391 -- said this was a configuration pragma, but we did not check and
6392 -- are hesitant to add the check now.
6394 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6395 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6396 -- or Ada 2012 mode.
6398 if Ada_Version >= Ada_2005 then
6399 Check_Valid_Configuration_Pragma;
6402 -- Now set Ada 83 mode
6404 Ada_Version := Ada_83;
6405 Ada_Version_Explicit := Ada_Version;
6413 -- Note: this pragma also has some specific processing in Par.Prag
6414 -- because we want to set the Ada 83 version mode during parsing.
6416 when Pragma_Ada_95 =>
6418 Check_Arg_Count (0);
6420 -- We really should check unconditionally for proper configuration
6421 -- pragma placement, since we really don't want mixed Ada modes
6422 -- within a single unit, and the GNAT reference manual has always
6423 -- said this was a configuration pragma, but we did not check and
6424 -- are hesitant to add the check now.
6426 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6427 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6429 if Ada_Version >= Ada_2005 then
6430 Check_Valid_Configuration_Pragma;
6433 -- Now set Ada 95 mode
6435 Ada_Version := Ada_95;
6436 Ada_Version_Explicit := Ada_Version;
6438 ---------------------
6439 -- Ada_05/Ada_2005 --
6440 ---------------------
6443 -- pragma Ada_05 (LOCAL_NAME);
6446 -- pragma Ada_2005 (LOCAL_NAME):
6448 -- Note: these pragmas also have some specific processing in Par.Prag
6449 -- because we want to set the Ada 2005 version mode during parsing.
6451 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6457 if Arg_Count = 1 then
6458 Check_Arg_Is_Local_Name (Arg1);
6459 E_Id := Get_Pragma_Arg (Arg1);
6461 if Etype (E_Id) = Any_Type then
6465 Set_Is_Ada_2005_Only (Entity (E_Id));
6468 Check_Arg_Count (0);
6470 -- For Ada_2005 we unconditionally enforce the documented
6471 -- configuration pragma placement, since we do not want to
6472 -- tolerate mixed modes in a unit involving Ada 2005. That
6473 -- would cause real difficulties for those cases where there
6474 -- are incompatibilities between Ada 95 and Ada 2005.
6476 Check_Valid_Configuration_Pragma;
6478 -- Now set appropriate Ada mode
6480 Ada_Version := Ada_2005;
6481 Ada_Version_Explicit := Ada_2005;
6485 ---------------------
6486 -- Ada_12/Ada_2012 --
6487 ---------------------
6490 -- pragma Ada_12 (LOCAL_NAME);
6493 -- pragma Ada_2012 (LOCAL_NAME):
6495 -- Note: these pragmas also have some specific processing in Par.Prag
6496 -- because we want to set the Ada 2012 version mode during parsing.
6498 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6504 if Arg_Count = 1 then
6505 Check_Arg_Is_Local_Name (Arg1);
6506 E_Id := Get_Pragma_Arg (Arg1);
6508 if Etype (E_Id) = Any_Type then
6512 Set_Is_Ada_2012_Only (Entity (E_Id));
6515 Check_Arg_Count (0);
6517 -- For Ada_2012 we unconditionally enforce the documented
6518 -- configuration pragma placement, since we do not want to
6519 -- tolerate mixed modes in a unit involving Ada 2012. That
6520 -- would cause real difficulties for those cases where there
6521 -- are incompatibilities between Ada 95 and Ada 2012. We could
6522 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6524 Check_Valid_Configuration_Pragma;
6526 -- Now set appropriate Ada mode
6528 Ada_Version := Ada_2012;
6529 Ada_Version_Explicit := Ada_2012;
6533 ----------------------
6534 -- All_Calls_Remote --
6535 ----------------------
6537 -- pragma All_Calls_Remote [(library_package_NAME)];
6539 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6540 Lib_Entity : Entity_Id;
6543 Check_Ada_83_Warning;
6544 Check_Valid_Library_Unit_Pragma;
6546 if Nkind (N) = N_Null_Statement then
6550 Lib_Entity := Find_Lib_Unit_Name;
6552 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6554 if Present (Lib_Entity)
6555 and then not Debug_Flag_U
6557 if not Is_Remote_Call_Interface (Lib_Entity) then
6558 Error_Pragma ("pragma% only apply to rci unit");
6560 -- Set flag for entity of the library unit
6563 Set_Has_All_Calls_Remote (Lib_Entity);
6567 end All_Calls_Remote;
6573 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6574 -- ARG ::= NAME | EXPRESSION
6576 -- The first two arguments are by convention intended to refer to an
6577 -- external tool and a tool-specific function. These arguments are
6580 when Pragma_Annotate => Annotate : declare
6586 Check_At_Least_N_Arguments (1);
6587 Check_Arg_Is_Identifier (Arg1);
6588 Check_No_Identifiers;
6591 -- Second parameter is optional, it is never analyzed
6596 -- Here if we have a second parameter
6599 -- Second parameter must be identifier
6601 Check_Arg_Is_Identifier (Arg2);
6603 -- Process remaining parameters if any
6606 while Present (Arg) loop
6607 Exp := Get_Pragma_Arg (Arg);
6610 if Is_Entity_Name (Exp) then
6613 -- For string literals, we assume Standard_String as the
6614 -- type, unless the string contains wide or wide_wide
6617 elsif Nkind (Exp) = N_String_Literal then
6618 if Has_Wide_Wide_Character (Exp) then
6619 Resolve (Exp, Standard_Wide_Wide_String);
6620 elsif Has_Wide_Character (Exp) then
6621 Resolve (Exp, Standard_Wide_String);
6623 Resolve (Exp, Standard_String);
6626 elsif Is_Overloaded (Exp) then
6628 ("ambiguous argument for pragma%", Exp);
6643 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6644 -- [, [Message =>] Static_String_EXPRESSION]);
6646 when Pragma_Assert => Assert : declare
6652 Check_At_Least_N_Arguments (1);
6653 Check_At_Most_N_Arguments (2);
6654 Check_Arg_Order ((Name_Check, Name_Message));
6655 Check_Optional_Identifier (Arg1, Name_Check);
6657 -- We treat pragma Assert as equivalent to:
6659 -- pragma Check (Assertion, condition [, msg]);
6661 -- So rewrite pragma in this manner, and analyze the result
6663 Expr := Get_Pragma_Arg (Arg1);
6665 Make_Pragma_Argument_Association (Loc,
6666 Expression => Make_Identifier (Loc, Name_Assertion)),
6668 Make_Pragma_Argument_Association (Sloc (Expr),
6669 Expression => Expr));
6671 if Arg_Count > 1 then
6672 Check_Optional_Identifier (Arg2, Name_Message);
6673 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6674 Append_To (Newa, Relocate_Node (Arg2));
6679 Chars => Name_Check,
6680 Pragma_Argument_Associations => Newa));
6684 ----------------------
6685 -- Assertion_Policy --
6686 ----------------------
6688 -- pragma Assertion_Policy (Check | Disable |Ignore)
6690 when Pragma_Assertion_Policy => Assertion_Policy : declare
6695 Check_Valid_Configuration_Pragma;
6696 Check_Arg_Count (1);
6697 Check_No_Identifiers;
6698 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6700 -- We treat pragma Assertion_Policy as equivalent to:
6702 -- pragma Check_Policy (Assertion, policy)
6704 -- So rewrite the pragma in that manner and link on to the chain
6705 -- of Check_Policy pragmas, marking the pragma as analyzed.
6707 Policy := Get_Pragma_Arg (Arg1);
6711 Chars => Name_Check_Policy,
6713 Pragma_Argument_Associations => New_List (
6714 Make_Pragma_Argument_Association (Loc,
6715 Expression => Make_Identifier (Loc, Name_Assertion)),
6717 Make_Pragma_Argument_Association (Loc,
6719 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6722 Set_Next_Pragma (N, Opt.Check_Policy_List);
6723 Opt.Check_Policy_List := N;
6724 end Assertion_Policy;
6726 ------------------------------
6727 -- Assume_No_Invalid_Values --
6728 ------------------------------
6730 -- pragma Assume_No_Invalid_Values (On | Off);
6732 when Pragma_Assume_No_Invalid_Values =>
6734 Check_Valid_Configuration_Pragma;
6735 Check_Arg_Count (1);
6736 Check_No_Identifiers;
6737 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6739 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6740 Assume_No_Invalid_Values := True;
6742 Assume_No_Invalid_Values := False;
6749 -- pragma AST_Entry (entry_IDENTIFIER);
6751 when Pragma_AST_Entry => AST_Entry : declare
6757 Check_Arg_Count (1);
6758 Check_No_Identifiers;
6759 Check_Arg_Is_Local_Name (Arg1);
6760 Ent := Entity (Get_Pragma_Arg (Arg1));
6762 -- Note: the implementation of the AST_Entry pragma could handle
6763 -- the entry family case fine, but for now we are consistent with
6764 -- the DEC rules, and do not allow the pragma, which of course
6765 -- has the effect of also forbidding the attribute.
6767 if Ekind (Ent) /= E_Entry then
6769 ("pragma% argument must be simple entry name", Arg1);
6771 elsif Is_AST_Entry (Ent) then
6773 ("duplicate % pragma for entry", Arg1);
6775 elsif Has_Homonym (Ent) then
6777 ("pragma% argument cannot specify overloaded entry", Arg1);
6781 FF : constant Entity_Id := First_Formal (Ent);
6784 if Present (FF) then
6785 if Present (Next_Formal (FF)) then
6787 ("entry for pragma% can have only one argument",
6790 elsif Parameter_Mode (FF) /= E_In_Parameter then
6792 ("entry parameter for pragma% must have mode IN",
6798 Set_Is_AST_Entry (Ent);
6806 -- pragma Asynchronous (LOCAL_NAME);
6808 when Pragma_Asynchronous => Asynchronous : declare
6816 procedure Process_Async_Pragma;
6817 -- Common processing for procedure and access-to-procedure case
6819 --------------------------
6820 -- Process_Async_Pragma --
6821 --------------------------
6823 procedure Process_Async_Pragma is
6826 Set_Is_Asynchronous (Nm);
6830 -- The formals should be of mode IN (RM E.4.1(6))
6833 while Present (S) loop
6834 Formal := Defining_Identifier (S);
6836 if Nkind (Formal) = N_Defining_Identifier
6837 and then Ekind (Formal) /= E_In_Parameter
6840 ("pragma% procedure can only have IN parameter",
6847 Set_Is_Asynchronous (Nm);
6848 end Process_Async_Pragma;
6850 -- Start of processing for pragma Asynchronous
6853 Check_Ada_83_Warning;
6854 Check_No_Identifiers;
6855 Check_Arg_Count (1);
6856 Check_Arg_Is_Local_Name (Arg1);
6858 if Debug_Flag_U then
6862 C_Ent := Cunit_Entity (Current_Sem_Unit);
6863 Analyze (Get_Pragma_Arg (Arg1));
6864 Nm := Entity (Get_Pragma_Arg (Arg1));
6866 if not Is_Remote_Call_Interface (C_Ent)
6867 and then not Is_Remote_Types (C_Ent)
6869 -- This pragma should only appear in an RCI or Remote Types
6870 -- unit (RM E.4.1(4)).
6873 ("pragma% not in Remote_Call_Interface or " &
6874 "Remote_Types unit");
6877 if Ekind (Nm) = E_Procedure
6878 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6880 if not Is_Remote_Call_Interface (Nm) then
6882 ("pragma% cannot be applied on non-remote procedure",
6886 L := Parameter_Specifications (Parent (Nm));
6887 Process_Async_Pragma;
6890 elsif Ekind (Nm) = E_Function then
6892 ("pragma% cannot be applied to function", Arg1);
6894 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6895 if Is_Record_Type (Nm) then
6897 -- A record type that is the Equivalent_Type for a remote
6898 -- access-to-subprogram type.
6900 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6903 -- A non-expanded RAS type (distribution is not enabled)
6905 N := Declaration_Node (Nm);
6908 if Nkind (N) = N_Full_Type_Declaration
6909 and then Nkind (Type_Definition (N)) =
6910 N_Access_Procedure_Definition
6912 L := Parameter_Specifications (Type_Definition (N));
6913 Process_Async_Pragma;
6915 if Is_Asynchronous (Nm)
6916 and then Expander_Active
6917 and then Get_PCS_Name /= Name_No_DSA
6919 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6924 ("pragma% cannot reference access-to-function type",
6928 -- Only other possibility is Access-to-class-wide type
6930 elsif Is_Access_Type (Nm)
6931 and then Is_Class_Wide_Type (Designated_Type (Nm))
6933 Check_First_Subtype (Arg1);
6934 Set_Is_Asynchronous (Nm);
6935 if Expander_Active then
6936 RACW_Type_Is_Asynchronous (Nm);
6940 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6948 -- pragma Atomic (LOCAL_NAME);
6950 when Pragma_Atomic =>
6951 Process_Atomic_Shared_Volatile;
6953 -----------------------
6954 -- Atomic_Components --
6955 -----------------------
6957 -- pragma Atomic_Components (array_LOCAL_NAME);
6959 -- This processing is shared by Volatile_Components
6961 when Pragma_Atomic_Components |
6962 Pragma_Volatile_Components =>
6964 Atomic_Components : declare
6971 Check_Ada_83_Warning;
6972 Check_No_Identifiers;
6973 Check_Arg_Count (1);
6974 Check_Arg_Is_Local_Name (Arg1);
6975 E_Id := Get_Pragma_Arg (Arg1);
6977 if Etype (E_Id) = Any_Type then
6983 Check_Duplicate_Pragma (E);
6985 if Rep_Item_Too_Early (E, N)
6987 Rep_Item_Too_Late (E, N)
6992 D := Declaration_Node (E);
6995 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6997 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6998 and then Nkind (D) = N_Object_Declaration
6999 and then Nkind (Object_Definition (D)) =
7000 N_Constrained_Array_Definition)
7002 -- The flag is set on the object, or on the base type
7004 if Nkind (D) /= N_Object_Declaration then
7008 Set_Has_Volatile_Components (E);
7010 if Prag_Id = Pragma_Atomic_Components then
7011 Set_Has_Atomic_Components (E);
7015 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7017 end Atomic_Components;
7018 --------------------
7019 -- Attach_Handler --
7020 --------------------
7022 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7024 when Pragma_Attach_Handler =>
7025 Check_Ada_83_Warning;
7026 Check_No_Identifiers;
7027 Check_Arg_Count (2);
7029 if No_Run_Time_Mode then
7030 Error_Msg_CRT ("Attach_Handler pragma", N);
7032 Check_Interrupt_Or_Attach_Handler;
7034 -- The expression that designates the attribute may depend on a
7035 -- discriminant, and is therefore a per- object expression, to
7036 -- be expanded in the init proc. If expansion is enabled, then
7037 -- perform semantic checks on a copy only.
7039 if Expander_Active then
7041 Temp : constant Node_Id :=
7042 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7044 Set_Parent (Temp, N);
7045 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7049 Analyze (Get_Pragma_Arg (Arg2));
7050 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7053 Process_Interrupt_Or_Attach_Handler;
7056 --------------------
7057 -- C_Pass_By_Copy --
7058 --------------------
7060 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7062 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7068 Check_Valid_Configuration_Pragma;
7069 Check_Arg_Count (1);
7070 Check_Optional_Identifier (Arg1, "max_size");
7072 Arg := Get_Pragma_Arg (Arg1);
7073 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7075 Val := Expr_Value (Arg);
7079 ("maximum size for pragma% must be positive", Arg1);
7081 elsif UI_Is_In_Int_Range (Val) then
7082 Default_C_Record_Mechanism := UI_To_Int (Val);
7084 -- If a giant value is given, Int'Last will do well enough.
7085 -- If sometime someone complains that a record larger than
7086 -- two gigabytes is not copied, we will worry about it then!
7089 Default_C_Record_Mechanism := Mechanism_Type'Last;
7097 -- pragma Check ([Name =>] IDENTIFIER,
7098 -- [Check =>] Boolean_EXPRESSION
7099 -- [,[Message =>] String_EXPRESSION]);
7101 when Pragma_Check => Check : declare
7106 -- Set True if category of assertions referenced by Name enabled
7110 Check_At_Least_N_Arguments (2);
7111 Check_At_Most_N_Arguments (3);
7112 Check_Optional_Identifier (Arg1, Name_Name);
7113 Check_Optional_Identifier (Arg2, Name_Check);
7115 if Arg_Count = 3 then
7116 Check_Optional_Identifier (Arg3, Name_Message);
7117 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7120 Check_Arg_Is_Identifier (Arg1);
7122 -- Completely ignore if disabled
7124 if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7125 Rewrite (N, Make_Null_Statement (Loc));
7130 -- Indicate if pragma is enabled. The Original_Node reference here
7131 -- is to deal with pragma Assert rewritten as a Check pragma.
7133 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
7136 Set_SCO_Pragma_Enabled (Loc);
7139 -- If expansion is active and the check is not enabled then we
7140 -- rewrite the Check as:
7142 -- if False and then condition then
7146 -- The reason we do this rewriting during semantic analysis rather
7147 -- than as part of normal expansion is that we cannot analyze and
7148 -- expand the code for the boolean expression directly, or it may
7149 -- cause insertion of actions that would escape the attempt to
7150 -- suppress the check code.
7152 -- Note that the Sloc for the if statement corresponds to the
7153 -- argument condition, not the pragma itself. The reason for this
7154 -- is that we may generate a warning if the condition is False at
7155 -- compile time, and we do not want to delete this warning when we
7156 -- delete the if statement.
7158 Expr := Get_Pragma_Arg (Arg2);
7160 if Expander_Active and then not Check_On then
7161 Eloc := Sloc (Expr);
7164 Make_If_Statement (Eloc,
7166 Make_And_Then (Eloc,
7167 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7168 Right_Opnd => Expr),
7169 Then_Statements => New_List (
7170 Make_Null_Statement (Eloc))));
7177 Analyze_And_Resolve (Expr, Any_Boolean);
7185 -- pragma Check_Name (check_IDENTIFIER);
7187 when Pragma_Check_Name =>
7188 Check_No_Identifiers;
7190 Check_Valid_Configuration_Pragma;
7191 Check_Arg_Count (1);
7192 Check_Arg_Is_Identifier (Arg1);
7195 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7198 for J in Check_Names.First .. Check_Names.Last loop
7199 if Check_Names.Table (J) = Nam then
7204 Check_Names.Append (Nam);
7211 -- pragma Check_Policy (
7212 -- [Name =>] IDENTIFIER,
7213 -- [Policy =>] POLICY_IDENTIFIER);
7215 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7217 -- Note: this is a configuration pragma, but it is allowed to appear
7220 when Pragma_Check_Policy =>
7222 Check_Arg_Count (2);
7223 Check_Optional_Identifier (Arg1, Name_Name);
7224 Check_Optional_Identifier (Arg2, Name_Policy);
7226 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7228 -- A Check_Policy pragma can appear either as a configuration
7229 -- pragma, or in a declarative part or a package spec (see RM
7230 -- 11.5(5) for rules for Suppress/Unsuppress which are also
7231 -- followed for Check_Policy).
7233 if not Is_Configuration_Pragma then
7234 Check_Is_In_Decl_Part_Or_Package_Spec;
7237 Set_Next_Pragma (N, Opt.Check_Policy_List);
7238 Opt.Check_Policy_List := N;
7240 ---------------------
7241 -- CIL_Constructor --
7242 ---------------------
7244 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7246 -- Processing for this pragma is shared with Java_Constructor
7252 -- pragma Comment (static_string_EXPRESSION)
7254 -- Processing for pragma Comment shares the circuitry for pragma
7255 -- Ident. The only differences are that Ident enforces a limit of 31
7256 -- characters on its argument, and also enforces limitations on
7257 -- placement for DEC compatibility. Pragma Comment shares neither of
7258 -- these restrictions.
7264 -- pragma Common_Object (
7265 -- [Internal =>] LOCAL_NAME
7266 -- [, [External =>] EXTERNAL_SYMBOL]
7267 -- [, [Size =>] EXTERNAL_SYMBOL]);
7269 -- Processing for this pragma is shared with Psect_Object
7271 ------------------------
7272 -- Compile_Time_Error --
7273 ------------------------
7275 -- pragma Compile_Time_Error
7276 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7278 when Pragma_Compile_Time_Error =>
7280 Process_Compile_Time_Warning_Or_Error;
7282 --------------------------
7283 -- Compile_Time_Warning --
7284 --------------------------
7286 -- pragma Compile_Time_Warning
7287 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7289 when Pragma_Compile_Time_Warning =>
7291 Process_Compile_Time_Warning_Or_Error;
7297 when Pragma_Compiler_Unit =>
7299 Check_Arg_Count (0);
7300 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7302 -----------------------------
7303 -- Complete_Representation --
7304 -----------------------------
7306 -- pragma Complete_Representation;
7308 when Pragma_Complete_Representation =>
7310 Check_Arg_Count (0);
7312 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7314 ("pragma & must appear within record representation clause");
7317 ----------------------------
7318 -- Complex_Representation --
7319 ----------------------------
7321 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7323 when Pragma_Complex_Representation => Complex_Representation : declare
7330 Check_Arg_Count (1);
7331 Check_Optional_Identifier (Arg1, Name_Entity);
7332 Check_Arg_Is_Local_Name (Arg1);
7333 E_Id := Get_Pragma_Arg (Arg1);
7335 if Etype (E_Id) = Any_Type then
7341 if not Is_Record_Type (E) then
7343 ("argument for pragma% must be record type", Arg1);
7346 Ent := First_Entity (E);
7349 or else No (Next_Entity (Ent))
7350 or else Present (Next_Entity (Next_Entity (Ent)))
7351 or else not Is_Floating_Point_Type (Etype (Ent))
7352 or else Etype (Ent) /= Etype (Next_Entity (Ent))
7355 ("record for pragma% must have two fields of the same "
7356 & "floating-point type", Arg1);
7359 Set_Has_Complex_Representation (Base_Type (E));
7361 -- We need to treat the type has having a non-standard
7362 -- representation, for back-end purposes, even though in
7363 -- general a complex will have the default representation
7364 -- of a record with two real components.
7366 Set_Has_Non_Standard_Rep (Base_Type (E));
7368 end Complex_Representation;
7370 -------------------------
7371 -- Component_Alignment --
7372 -------------------------
7374 -- pragma Component_Alignment (
7375 -- [Form =>] ALIGNMENT_CHOICE
7376 -- [, [Name =>] type_LOCAL_NAME]);
7378 -- ALIGNMENT_CHOICE ::=
7380 -- | Component_Size_4
7384 when Pragma_Component_Alignment => Component_AlignmentP : declare
7385 Args : Args_List (1 .. 2);
7386 Names : constant Name_List (1 .. 2) := (
7390 Form : Node_Id renames Args (1);
7391 Name : Node_Id renames Args (2);
7393 Atype : Component_Alignment_Kind;
7398 Gather_Associations (Names, Args);
7401 Error_Pragma ("missing Form argument for pragma%");
7404 Check_Arg_Is_Identifier (Form);
7406 -- Get proper alignment, note that Default = Component_Size on all
7407 -- machines we have so far, and we want to set this value rather
7408 -- than the default value to indicate that it has been explicitly
7409 -- set (and thus will not get overridden by the default component
7410 -- alignment for the current scope)
7412 if Chars (Form) = Name_Component_Size then
7413 Atype := Calign_Component_Size;
7415 elsif Chars (Form) = Name_Component_Size_4 then
7416 Atype := Calign_Component_Size_4;
7418 elsif Chars (Form) = Name_Default then
7419 Atype := Calign_Component_Size;
7421 elsif Chars (Form) = Name_Storage_Unit then
7422 Atype := Calign_Storage_Unit;
7426 ("invalid Form parameter for pragma%", Form);
7429 -- Case with no name, supplied, affects scope table entry
7433 (Scope_Stack.Last).Component_Alignment_Default := Atype;
7435 -- Case of name supplied
7438 Check_Arg_Is_Local_Name (Name);
7440 Typ := Entity (Name);
7443 or else Rep_Item_Too_Early (Typ, N)
7447 Typ := Underlying_Type (Typ);
7450 if not Is_Record_Type (Typ)
7451 and then not Is_Array_Type (Typ)
7454 ("Name parameter of pragma% must identify record or " &
7455 "array type", Name);
7458 -- An explicit Component_Alignment pragma overrides an
7459 -- implicit pragma Pack, but not an explicit one.
7461 if not Has_Pragma_Pack (Base_Type (Typ)) then
7462 Set_Is_Packed (Base_Type (Typ), False);
7463 Set_Component_Alignment (Base_Type (Typ), Atype);
7466 end Component_AlignmentP;
7472 -- pragma Controlled (first_subtype_LOCAL_NAME);
7474 when Pragma_Controlled => Controlled : declare
7478 Check_No_Identifiers;
7479 Check_Arg_Count (1);
7480 Check_Arg_Is_Local_Name (Arg1);
7481 Arg := Get_Pragma_Arg (Arg1);
7483 if not Is_Entity_Name (Arg)
7484 or else not Is_Access_Type (Entity (Arg))
7486 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7488 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7496 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
7497 -- [Entity =>] LOCAL_NAME);
7499 when Pragma_Convention => Convention : declare
7502 pragma Warnings (Off, C);
7503 pragma Warnings (Off, E);
7505 Check_Arg_Order ((Name_Convention, Name_Entity));
7506 Check_Ada_83_Warning;
7507 Check_Arg_Count (2);
7508 Process_Convention (C, E);
7511 ---------------------------
7512 -- Convention_Identifier --
7513 ---------------------------
7515 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7516 -- [Convention =>] convention_IDENTIFIER);
7518 when Pragma_Convention_Identifier => Convention_Identifier : declare
7524 Check_Arg_Order ((Name_Name, Name_Convention));
7525 Check_Arg_Count (2);
7526 Check_Optional_Identifier (Arg1, Name_Name);
7527 Check_Optional_Identifier (Arg2, Name_Convention);
7528 Check_Arg_Is_Identifier (Arg1);
7529 Check_Arg_Is_Identifier (Arg2);
7530 Idnam := Chars (Get_Pragma_Arg (Arg1));
7531 Cname := Chars (Get_Pragma_Arg (Arg2));
7533 if Is_Convention_Name (Cname) then
7534 Record_Convention_Identifier
7535 (Idnam, Get_Convention_Id (Cname));
7538 ("second arg for % pragma must be convention", Arg2);
7540 end Convention_Identifier;
7546 -- pragma CPP_Class ([Entity =>] local_NAME)
7548 when Pragma_CPP_Class => CPP_Class : declare
7553 if Warn_On_Obsolescent_Feature then
7555 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7556 " by pragma import?", N);
7560 Check_Arg_Count (1);
7561 Check_Optional_Identifier (Arg1, Name_Entity);
7562 Check_Arg_Is_Local_Name (Arg1);
7564 Arg := Get_Pragma_Arg (Arg1);
7567 if Etype (Arg) = Any_Type then
7571 if not Is_Entity_Name (Arg)
7572 or else not Is_Type (Entity (Arg))
7574 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7577 Typ := Entity (Arg);
7579 if not Is_Tagged_Type (Typ) then
7580 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7583 -- Types treated as CPP classes must be declared limited (note:
7584 -- this used to be a warning but there is no real benefit to it
7585 -- since we did effectively intend to treat the type as limited
7588 if not Is_Limited_Type (Typ) then
7590 ("imported 'C'P'P type must be limited",
7591 Get_Pragma_Arg (Arg1));
7594 Set_Is_CPP_Class (Typ);
7595 Set_Convention (Typ, Convention_CPP);
7597 -- Imported CPP types must not have discriminants (because C++
7598 -- classes do not have discriminants).
7600 if Has_Discriminants (Typ) then
7602 ("imported 'C'P'P type cannot have discriminants",
7603 First (Discriminant_Specifications
7604 (Declaration_Node (Typ))));
7607 -- Components of imported CPP types must not have default
7608 -- expressions because the constructor (if any) is in the
7611 if Is_Incomplete_Or_Private_Type (Typ)
7612 and then No (Underlying_Type (Typ))
7614 -- It should be an error to apply pragma CPP to a private
7615 -- type if the underlying type is not visible (as it is
7616 -- for any representation item). For now, for backward
7617 -- compatibility we do nothing but we cannot check components
7618 -- because they are not available at this stage. All this code
7619 -- will be removed when we cleanup this obsolete GNAT pragma???
7625 Tdef : constant Node_Id :=
7626 Type_Definition (Declaration_Node (Typ));
7631 if Nkind (Tdef) = N_Record_Definition then
7632 Clist := Component_List (Tdef);
7634 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7635 Clist := Component_List (Record_Extension_Part (Tdef));
7638 if Present (Clist) then
7639 Comp := First (Component_Items (Clist));
7640 while Present (Comp) loop
7641 if Present (Expression (Comp)) then
7643 ("component of imported 'C'P'P type cannot have" &
7644 " default expression", Expression (Comp));
7654 ---------------------
7655 -- CPP_Constructor --
7656 ---------------------
7658 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7659 -- [, [External_Name =>] static_string_EXPRESSION ]
7660 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7662 when Pragma_CPP_Constructor => CPP_Constructor : declare
7666 Tag_Typ : Entity_Id;
7670 Check_At_Least_N_Arguments (1);
7671 Check_At_Most_N_Arguments (3);
7672 Check_Optional_Identifier (Arg1, Name_Entity);
7673 Check_Arg_Is_Local_Name (Arg1);
7675 Id := Get_Pragma_Arg (Arg1);
7676 Find_Program_Unit_Name (Id);
7678 -- If we did not find the name, we are done
7680 if Etype (Id) = Any_Type then
7684 Def_Id := Entity (Id);
7686 -- Check if already defined as constructor
7688 if Is_Constructor (Def_Id) then
7690 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7694 if Ekind (Def_Id) = E_Function
7695 and then (Is_CPP_Class (Etype (Def_Id))
7696 or else (Is_Class_Wide_Type (Etype (Def_Id))
7698 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7700 if Arg_Count >= 2 then
7701 Set_Imported (Def_Id);
7702 Set_Is_Public (Def_Id);
7703 Process_Interface_Name (Def_Id, Arg2, Arg3);
7706 Set_Has_Completion (Def_Id);
7707 Set_Is_Constructor (Def_Id);
7709 -- Imported C++ constructors are not dispatching primitives
7710 -- because in C++ they don't have a dispatch table slot.
7711 -- However, in Ada the constructor has the profile of a
7712 -- function that returns a tagged type and therefore it has
7713 -- been treated as a primitive operation during semantic
7714 -- analysis. We now remove it from the list of primitive
7715 -- operations of the type.
7717 if Is_Tagged_Type (Etype (Def_Id))
7718 and then not Is_Class_Wide_Type (Etype (Def_Id))
7720 pragma Assert (Is_Dispatching_Operation (Def_Id));
7721 Tag_Typ := Etype (Def_Id);
7723 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7724 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7728 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7729 Set_Is_Dispatching_Operation (Def_Id, False);
7732 -- For backward compatibility, if the constructor returns a
7733 -- class wide type, and we internally change the return type to
7734 -- the corresponding root type.
7736 if Is_Class_Wide_Type (Etype (Def_Id)) then
7737 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7741 ("pragma% requires function returning a 'C'P'P_Class type",
7744 end CPP_Constructor;
7750 when Pragma_CPP_Virtual => CPP_Virtual : declare
7754 if Warn_On_Obsolescent_Feature then
7756 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7765 when Pragma_CPP_Vtable => CPP_Vtable : declare
7769 if Warn_On_Obsolescent_Feature then
7771 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7780 -- pragma CPU (EXPRESSION);
7782 when Pragma_CPU => CPU : declare
7783 P : constant Node_Id := Parent (N);
7788 Check_No_Identifiers;
7789 Check_Arg_Count (1);
7793 if Nkind (P) = N_Subprogram_Body then
7794 Check_In_Main_Program;
7796 Arg := Get_Pragma_Arg (Arg1);
7797 Analyze_And_Resolve (Arg, Any_Integer);
7801 if not Is_Static_Expression (Arg) then
7802 Flag_Non_Static_Expr
7803 ("main subprogram affinity is not static!", Arg);
7806 -- If constraint error, then we already signalled an error
7808 elsif Raises_Constraint_Error (Arg) then
7811 -- Otherwise check in range
7815 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7816 -- This is the entity System.Multiprocessors.CPU_Range;
7818 Val : constant Uint := Expr_Value (Arg);
7821 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7823 Val > Expr_Value (Type_High_Bound (CPU_Id))
7826 ("main subprogram CPU is out of range", Arg1);
7832 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7836 elsif Nkind (P) = N_Task_Definition then
7837 Arg := Get_Pragma_Arg (Arg1);
7839 -- The expression must be analyzed in the special manner
7840 -- described in "Handling of Default and Per-Object
7841 -- Expressions" in sem.ads.
7843 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7845 -- Anything else is incorrect
7851 if Has_Pragma_CPU (P) then
7852 Error_Pragma ("duplicate pragma% not allowed");
7854 Set_Has_Pragma_CPU (P, True);
7856 if Nkind (P) = N_Task_Definition then
7857 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7866 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7868 when Pragma_Debug => Debug : declare
7875 -- Skip analysis if disabled
7877 if Debug_Pragmas_Disabled then
7878 Rewrite (N, Make_Null_Statement (Loc));
7885 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7888 if Debug_Pragmas_Enabled then
7889 Set_SCO_Pragma_Enabled (Loc);
7892 if Arg_Count = 2 then
7895 Left_Opnd => Relocate_Node (Cond),
7896 Right_Opnd => Get_Pragma_Arg (Arg1));
7897 Call := Get_Pragma_Arg (Arg2);
7899 Call := Get_Pragma_Arg (Arg1);
7903 N_Indexed_Component,
7907 N_Selected_Component)
7909 -- If this pragma Debug comes from source, its argument was
7910 -- parsed as a name form (which is syntactically identical).
7911 -- In a generic context a parameterless call will be left as
7912 -- an expanded name (if global) or selected_component if local.
7913 -- Change it to a procedure call statement now.
7915 Change_Name_To_Procedure_Call_Statement (Call);
7917 elsif Nkind (Call) = N_Procedure_Call_Statement then
7919 -- Already in the form of a procedure call statement: nothing
7920 -- to do (could happen in case of an internally generated
7926 -- All other cases: diagnose error
7929 ("argument of pragma ""Debug"" is not procedure call",
7934 -- Rewrite into a conditional with an appropriate condition. We
7935 -- wrap the procedure call in a block so that overhead from e.g.
7936 -- use of the secondary stack does not generate execution overhead
7937 -- for suppressed conditions.
7939 Rewrite (N, Make_Implicit_If_Statement (N,
7941 Then_Statements => New_List (
7942 Make_Block_Statement (Loc,
7943 Handled_Statement_Sequence =>
7944 Make_Handled_Sequence_Of_Statements (Loc,
7945 Statements => New_List (Relocate_Node (Call)))))));
7953 -- pragma Debug_Policy (Check | Ignore)
7955 when Pragma_Debug_Policy =>
7957 Check_Arg_Count (1);
7958 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7959 Debug_Pragmas_Enabled :=
7960 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7961 Debug_Pragmas_Disabled :=
7962 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
7964 ---------------------
7965 -- Detect_Blocking --
7966 ---------------------
7968 -- pragma Detect_Blocking;
7970 when Pragma_Detect_Blocking =>
7972 Check_Arg_Count (0);
7973 Check_Valid_Configuration_Pragma;
7974 Detect_Blocking := True;
7976 --------------------------
7977 -- Default_Storage_Pool --
7978 --------------------------
7980 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7982 when Pragma_Default_Storage_Pool =>
7984 Check_Arg_Count (1);
7986 -- Default_Storage_Pool can appear as a configuration pragma, or
7987 -- in a declarative part or a package spec.
7989 if not Is_Configuration_Pragma then
7990 Check_Is_In_Decl_Part_Or_Package_Spec;
7993 -- Case of Default_Storage_Pool (null);
7995 if Nkind (Expression (Arg1)) = N_Null then
7996 Analyze (Expression (Arg1));
7998 -- This is an odd case, this is not really an expression, so
7999 -- we don't have a type for it. So just set the type to Empty.
8001 Set_Etype (Expression (Arg1), Empty);
8003 -- Case of Default_Storage_Pool (storage_pool_NAME);
8006 -- If it's a configuration pragma, then the only allowed
8007 -- argument is "null".
8009 if Is_Configuration_Pragma then
8010 Error_Pragma_Arg ("NULL expected", Arg1);
8013 -- The expected type for a non-"null" argument is
8014 -- Root_Storage_Pool'Class.
8017 (Get_Pragma_Arg (Arg1),
8018 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8021 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
8022 -- for an access type will use this information to set the
8023 -- appropriate attributes of the access type.
8025 Default_Pool := Expression (Arg1);
8031 when Pragma_Dimension =>
8033 Check_Arg_Count (4);
8034 Check_No_Identifiers;
8035 Check_Arg_Is_Local_Name (Arg1);
8037 if not Is_Type (Arg1) then
8038 Error_Pragma ("first argument for pragma% must be subtype");
8041 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
8042 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
8043 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
8045 ------------------------------------
8046 -- Disable_Atomic_Synchronization --
8047 ------------------------------------
8049 -- pragma Disable_Atomic_Synchronization [(Entity)];
8051 when Pragma_Disable_Atomic_Synchronization =>
8052 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8058 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
8060 when Pragma_Discard_Names => Discard_Names : declare
8065 Check_Ada_83_Warning;
8067 -- Deal with configuration pragma case
8069 if Arg_Count = 0 and then Is_Configuration_Pragma then
8070 Global_Discard_Names := True;
8073 -- Otherwise, check correct appropriate context
8076 Check_Is_In_Decl_Part_Or_Package_Spec;
8078 if Arg_Count = 0 then
8080 -- If there is no parameter, then from now on this pragma
8081 -- applies to any enumeration, exception or tagged type
8082 -- defined in the current declarative part, and recursively
8083 -- to any nested scope.
8085 Set_Discard_Names (Current_Scope);
8089 Check_Arg_Count (1);
8090 Check_Optional_Identifier (Arg1, Name_On);
8091 Check_Arg_Is_Local_Name (Arg1);
8093 E_Id := Get_Pragma_Arg (Arg1);
8095 if Etype (E_Id) = Any_Type then
8101 if (Is_First_Subtype (E)
8103 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8104 or else Ekind (E) = E_Exception
8106 Set_Discard_Names (E);
8109 ("inappropriate entity for pragma%", Arg1);
8116 ------------------------
8117 -- Dispatching_Domain --
8118 ------------------------
8120 -- pragma Dispatching_Domain (EXPRESSION);
8122 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8123 P : constant Node_Id := Parent (N);
8128 Check_No_Identifiers;
8129 Check_Arg_Count (1);
8131 -- This pragma is born obsolete, but not the aspect
8133 if not From_Aspect_Specification (N) then
8135 (No_Obsolescent_Features, Pragma_Identifier (N));
8138 if Nkind (P) = N_Task_Definition then
8139 Arg := Get_Pragma_Arg (Arg1);
8141 -- The expression must be analyzed in the special manner
8142 -- described in "Handling of Default and Per-Object
8143 -- Expressions" in sem.ads.
8145 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8147 -- Anything else is incorrect
8153 if Has_Pragma_Dispatching_Domain (P) then
8154 Error_Pragma ("duplicate pragma% not allowed");
8156 Set_Has_Pragma_Dispatching_Domain (P, True);
8158 if Nkind (P) = N_Task_Definition then
8159 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8162 end Dispatching_Domain;
8168 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8170 when Pragma_Elaborate => Elaborate : declare
8175 -- Pragma must be in context items list of a compilation unit
8177 if not Is_In_Context_Clause then
8181 -- Must be at least one argument
8183 if Arg_Count = 0 then
8184 Error_Pragma ("pragma% requires at least one argument");
8187 -- In Ada 83 mode, there can be no items following it in the
8188 -- context list except other pragmas and implicit with clauses
8189 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8190 -- placement rule does not apply.
8192 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8194 while Present (Citem) loop
8195 if Nkind (Citem) = N_Pragma
8196 or else (Nkind (Citem) = N_With_Clause
8197 and then Implicit_With (Citem))
8202 ("(Ada 83) pragma% must be at end of context clause");
8209 -- Finally, the arguments must all be units mentioned in a with
8210 -- clause in the same context clause. Note we already checked (in
8211 -- Par.Prag) that the arguments are all identifiers or selected
8215 Outer : while Present (Arg) loop
8216 Citem := First (List_Containing (N));
8217 Inner : while Citem /= N loop
8218 if Nkind (Citem) = N_With_Clause
8219 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8221 Set_Elaborate_Present (Citem, True);
8222 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8223 Generate_Reference (Entity (Name (Citem)), Citem);
8225 -- With the pragma present, elaboration calls on
8226 -- subprograms from the named unit need no further
8227 -- checks, as long as the pragma appears in the current
8228 -- compilation unit. If the pragma appears in some unit
8229 -- in the context, there might still be a need for an
8230 -- Elaborate_All_Desirable from the current compilation
8231 -- to the named unit, so we keep the check enabled.
8233 if In_Extended_Main_Source_Unit (N) then
8234 Set_Suppress_Elaboration_Warnings
8235 (Entity (Name (Citem)));
8246 ("argument of pragma% is not with'ed unit", Arg);
8252 -- Give a warning if operating in static mode with -gnatwl
8253 -- (elaboration warnings enabled) switch set.
8255 if Elab_Warnings and not Dynamic_Elaboration_Checks then
8257 ("?use of pragma Elaborate may not be safe", N);
8259 ("?use pragma Elaborate_All instead if possible", N);
8267 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8269 when Pragma_Elaborate_All => Elaborate_All : declare
8274 Check_Ada_83_Warning;
8276 -- Pragma must be in context items list of a compilation unit
8278 if not Is_In_Context_Clause then
8282 -- Must be at least one argument
8284 if Arg_Count = 0 then
8285 Error_Pragma ("pragma% requires at least one argument");
8288 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
8289 -- have to appear at the end of the context clause, but may
8290 -- appear mixed in with other items, even in Ada 83 mode.
8292 -- Final check: the arguments must all be units mentioned in
8293 -- a with clause in the same context clause. Note that we
8294 -- already checked (in Par.Prag) that all the arguments are
8295 -- either identifiers or selected components.
8298 Outr : while Present (Arg) loop
8299 Citem := First (List_Containing (N));
8300 Innr : while Citem /= N loop
8301 if Nkind (Citem) = N_With_Clause
8302 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8304 Set_Elaborate_All_Present (Citem, True);
8305 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8307 -- Suppress warnings and elaboration checks on the named
8308 -- unit if the pragma is in the current compilation, as
8309 -- for pragma Elaborate.
8311 if In_Extended_Main_Source_Unit (N) then
8312 Set_Suppress_Elaboration_Warnings
8313 (Entity (Name (Citem)));
8322 Set_Error_Posted (N);
8324 ("argument of pragma% is not with'ed unit", Arg);
8331 --------------------
8332 -- Elaborate_Body --
8333 --------------------
8335 -- pragma Elaborate_Body [( library_unit_NAME )];
8337 when Pragma_Elaborate_Body => Elaborate_Body : declare
8338 Cunit_Node : Node_Id;
8339 Cunit_Ent : Entity_Id;
8342 Check_Ada_83_Warning;
8343 Check_Valid_Library_Unit_Pragma;
8345 if Nkind (N) = N_Null_Statement then
8349 Cunit_Node := Cunit (Current_Sem_Unit);
8350 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8352 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8355 Error_Pragma ("pragma% must refer to a spec, not a body");
8357 Set_Body_Required (Cunit_Node, True);
8358 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8360 -- If we are in dynamic elaboration mode, then we suppress
8361 -- elaboration warnings for the unit, since it is definitely
8362 -- fine NOT to do dynamic checks at the first level (and such
8363 -- checks will be suppressed because no elaboration boolean
8364 -- is created for Elaborate_Body packages).
8366 -- But in the static model of elaboration, Elaborate_Body is
8367 -- definitely NOT good enough to ensure elaboration safety on
8368 -- its own, since the body may WITH other units that are not
8369 -- safe from an elaboration point of view, so a client must
8370 -- still do an Elaborate_All on such units.
8372 -- Debug flag -gnatdD restores the old behavior of 3.13, where
8373 -- Elaborate_Body always suppressed elab warnings.
8375 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8376 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8381 ------------------------
8382 -- Elaboration_Checks --
8383 ------------------------
8385 -- pragma Elaboration_Checks (Static | Dynamic);
8387 when Pragma_Elaboration_Checks =>
8389 Check_Arg_Count (1);
8390 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8391 Dynamic_Elaboration_Checks :=
8392 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8398 -- pragma Eliminate (
8399 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
8400 -- [,[Entity =>] IDENTIFIER |
8401 -- SELECTED_COMPONENT |
8403 -- [, OVERLOADING_RESOLUTION]);
8405 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8408 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8411 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8413 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8414 -- Result_Type => result_SUBTYPE_NAME]
8416 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8417 -- SUBTYPE_NAME ::= STRING_LITERAL
8419 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8420 -- SOURCE_TRACE ::= STRING_LITERAL
8422 when Pragma_Eliminate => Eliminate : declare
8423 Args : Args_List (1 .. 5);
8424 Names : constant Name_List (1 .. 5) := (
8427 Name_Parameter_Types,
8429 Name_Source_Location);
8431 Unit_Name : Node_Id renames Args (1);
8432 Entity : Node_Id renames Args (2);
8433 Parameter_Types : Node_Id renames Args (3);
8434 Result_Type : Node_Id renames Args (4);
8435 Source_Location : Node_Id renames Args (5);
8439 Check_Valid_Configuration_Pragma;
8440 Gather_Associations (Names, Args);
8442 if No (Unit_Name) then
8443 Error_Pragma ("missing Unit_Name argument for pragma%");
8447 and then (Present (Parameter_Types)
8449 Present (Result_Type)
8451 Present (Source_Location))
8453 Error_Pragma ("missing Entity argument for pragma%");
8456 if (Present (Parameter_Types)
8458 Present (Result_Type))
8460 Present (Source_Location)
8463 ("parameter profile and source location cannot " &
8464 "be used together in pragma%");
8467 Process_Eliminate_Pragma
8476 -----------------------------------
8477 -- Enable_Atomic_Synchronization --
8478 -----------------------------------
8480 -- pragma Enable_Atomic_Synchronization [(Entity)];
8482 when Pragma_Enable_Atomic_Synchronization =>
8483 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
8490 -- [ Convention =>] convention_IDENTIFIER,
8491 -- [ Entity =>] local_NAME
8492 -- [, [External_Name =>] static_string_EXPRESSION ]
8493 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8495 when Pragma_Export => Export : declare
8499 pragma Warnings (Off, C);
8502 Check_Ada_83_Warning;
8508 Check_At_Least_N_Arguments (2);
8509 Check_At_Most_N_Arguments (4);
8510 Process_Convention (C, Def_Id);
8512 if Ekind (Def_Id) /= E_Constant then
8513 Note_Possible_Modification
8514 (Get_Pragma_Arg (Arg2), Sure => False);
8517 Process_Interface_Name (Def_Id, Arg3, Arg4);
8518 Set_Exported (Def_Id, Arg2);
8520 -- If the entity is a deferred constant, propagate the information
8521 -- to the full view, because gigi elaborates the full view only.
8523 if Ekind (Def_Id) = E_Constant
8524 and then Present (Full_View (Def_Id))
8527 Id2 : constant Entity_Id := Full_View (Def_Id);
8529 Set_Is_Exported (Id2, Is_Exported (Def_Id));
8530 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
8531 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8536 ----------------------
8537 -- Export_Exception --
8538 ----------------------
8540 -- pragma Export_Exception (
8541 -- [Internal =>] LOCAL_NAME
8542 -- [, [External =>] EXTERNAL_SYMBOL]
8543 -- [, [Form =>] Ada | VMS]
8544 -- [, [Code =>] static_integer_EXPRESSION]);
8546 when Pragma_Export_Exception => Export_Exception : declare
8547 Args : Args_List (1 .. 4);
8548 Names : constant Name_List (1 .. 4) := (
8554 Internal : Node_Id renames Args (1);
8555 External : Node_Id renames Args (2);
8556 Form : Node_Id renames Args (3);
8557 Code : Node_Id renames Args (4);
8562 if Inside_A_Generic then
8563 Error_Pragma ("pragma% cannot be used for generic entities");
8566 Gather_Associations (Names, Args);
8567 Process_Extended_Import_Export_Exception_Pragma (
8568 Arg_Internal => Internal,
8569 Arg_External => External,
8573 if not Is_VMS_Exception (Entity (Internal)) then
8574 Set_Exported (Entity (Internal), Internal);
8576 end Export_Exception;
8578 ---------------------
8579 -- Export_Function --
8580 ---------------------
8582 -- pragma Export_Function (
8583 -- [Internal =>] LOCAL_NAME
8584 -- [, [External =>] EXTERNAL_SYMBOL]
8585 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8586 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8587 -- [, [Mechanism =>] MECHANISM]
8588 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8590 -- EXTERNAL_SYMBOL ::=
8592 -- | static_string_EXPRESSION
8594 -- PARAMETER_TYPES ::=
8596 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8598 -- TYPE_DESIGNATOR ::=
8600 -- | subtype_Name ' Access
8604 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8606 -- MECHANISM_ASSOCIATION ::=
8607 -- [formal_parameter_NAME =>] MECHANISM_NAME
8609 -- MECHANISM_NAME ::=
8612 -- | Descriptor [([Class =>] CLASS_NAME)]
8614 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8616 when Pragma_Export_Function => Export_Function : declare
8617 Args : Args_List (1 .. 6);
8618 Names : constant Name_List (1 .. 6) := (
8621 Name_Parameter_Types,
8624 Name_Result_Mechanism);
8626 Internal : Node_Id renames Args (1);
8627 External : Node_Id renames Args (2);
8628 Parameter_Types : Node_Id renames Args (3);
8629 Result_Type : Node_Id renames Args (4);
8630 Mechanism : Node_Id renames Args (5);
8631 Result_Mechanism : Node_Id renames Args (6);
8635 Gather_Associations (Names, Args);
8636 Process_Extended_Import_Export_Subprogram_Pragma (
8637 Arg_Internal => Internal,
8638 Arg_External => External,
8639 Arg_Parameter_Types => Parameter_Types,
8640 Arg_Result_Type => Result_Type,
8641 Arg_Mechanism => Mechanism,
8642 Arg_Result_Mechanism => Result_Mechanism);
8643 end Export_Function;
8649 -- pragma Export_Object (
8650 -- [Internal =>] LOCAL_NAME
8651 -- [, [External =>] EXTERNAL_SYMBOL]
8652 -- [, [Size =>] EXTERNAL_SYMBOL]);
8654 -- EXTERNAL_SYMBOL ::=
8656 -- | static_string_EXPRESSION
8658 -- PARAMETER_TYPES ::=
8660 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8662 -- TYPE_DESIGNATOR ::=
8664 -- | subtype_Name ' Access
8668 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8670 -- MECHANISM_ASSOCIATION ::=
8671 -- [formal_parameter_NAME =>] MECHANISM_NAME
8673 -- MECHANISM_NAME ::=
8676 -- | Descriptor [([Class =>] CLASS_NAME)]
8678 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8680 when Pragma_Export_Object => Export_Object : declare
8681 Args : Args_List (1 .. 3);
8682 Names : constant Name_List (1 .. 3) := (
8687 Internal : Node_Id renames Args (1);
8688 External : Node_Id renames Args (2);
8689 Size : Node_Id renames Args (3);
8693 Gather_Associations (Names, Args);
8694 Process_Extended_Import_Export_Object_Pragma (
8695 Arg_Internal => Internal,
8696 Arg_External => External,
8700 ----------------------
8701 -- Export_Procedure --
8702 ----------------------
8704 -- pragma Export_Procedure (
8705 -- [Internal =>] LOCAL_NAME
8706 -- [, [External =>] EXTERNAL_SYMBOL]
8707 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8708 -- [, [Mechanism =>] MECHANISM]);
8710 -- EXTERNAL_SYMBOL ::=
8712 -- | static_string_EXPRESSION
8714 -- PARAMETER_TYPES ::=
8716 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8718 -- TYPE_DESIGNATOR ::=
8720 -- | subtype_Name ' Access
8724 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8726 -- MECHANISM_ASSOCIATION ::=
8727 -- [formal_parameter_NAME =>] MECHANISM_NAME
8729 -- MECHANISM_NAME ::=
8732 -- | Descriptor [([Class =>] CLASS_NAME)]
8734 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8736 when Pragma_Export_Procedure => Export_Procedure : declare
8737 Args : Args_List (1 .. 4);
8738 Names : constant Name_List (1 .. 4) := (
8741 Name_Parameter_Types,
8744 Internal : Node_Id renames Args (1);
8745 External : Node_Id renames Args (2);
8746 Parameter_Types : Node_Id renames Args (3);
8747 Mechanism : Node_Id renames Args (4);
8751 Gather_Associations (Names, Args);
8752 Process_Extended_Import_Export_Subprogram_Pragma (
8753 Arg_Internal => Internal,
8754 Arg_External => External,
8755 Arg_Parameter_Types => Parameter_Types,
8756 Arg_Mechanism => Mechanism);
8757 end Export_Procedure;
8763 -- pragma Export_Value (
8764 -- [Value =>] static_integer_EXPRESSION,
8765 -- [Link_Name =>] static_string_EXPRESSION);
8767 when Pragma_Export_Value =>
8769 Check_Arg_Order ((Name_Value, Name_Link_Name));
8770 Check_Arg_Count (2);
8772 Check_Optional_Identifier (Arg1, Name_Value);
8773 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8775 Check_Optional_Identifier (Arg2, Name_Link_Name);
8776 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8778 -----------------------------
8779 -- Export_Valued_Procedure --
8780 -----------------------------
8782 -- pragma Export_Valued_Procedure (
8783 -- [Internal =>] LOCAL_NAME
8784 -- [, [External =>] EXTERNAL_SYMBOL,]
8785 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8786 -- [, [Mechanism =>] MECHANISM]);
8788 -- EXTERNAL_SYMBOL ::=
8790 -- | static_string_EXPRESSION
8792 -- PARAMETER_TYPES ::=
8794 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8796 -- TYPE_DESIGNATOR ::=
8798 -- | subtype_Name ' Access
8802 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8804 -- MECHANISM_ASSOCIATION ::=
8805 -- [formal_parameter_NAME =>] MECHANISM_NAME
8807 -- MECHANISM_NAME ::=
8810 -- | Descriptor [([Class =>] CLASS_NAME)]
8812 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8814 when Pragma_Export_Valued_Procedure =>
8815 Export_Valued_Procedure : declare
8816 Args : Args_List (1 .. 4);
8817 Names : constant Name_List (1 .. 4) := (
8820 Name_Parameter_Types,
8823 Internal : Node_Id renames Args (1);
8824 External : Node_Id renames Args (2);
8825 Parameter_Types : Node_Id renames Args (3);
8826 Mechanism : Node_Id renames Args (4);
8830 Gather_Associations (Names, Args);
8831 Process_Extended_Import_Export_Subprogram_Pragma (
8832 Arg_Internal => Internal,
8833 Arg_External => External,
8834 Arg_Parameter_Types => Parameter_Types,
8835 Arg_Mechanism => Mechanism);
8836 end Export_Valued_Procedure;
8842 -- pragma Extend_System ([Name =>] Identifier);
8844 when Pragma_Extend_System => Extend_System : declare
8847 Check_Valid_Configuration_Pragma;
8848 Check_Arg_Count (1);
8849 Check_Optional_Identifier (Arg1, Name_Name);
8850 Check_Arg_Is_Identifier (Arg1);
8852 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8855 and then Name_Buffer (1 .. 4) = "aux_"
8857 if Present (System_Extend_Pragma_Arg) then
8858 if Chars (Get_Pragma_Arg (Arg1)) =
8859 Chars (Expression (System_Extend_Pragma_Arg))
8863 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8864 Error_Pragma ("pragma% conflicts with that #");
8868 System_Extend_Pragma_Arg := Arg1;
8870 if not GNAT_Mode then
8871 System_Extend_Unit := Arg1;
8875 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8879 ------------------------
8880 -- Extensions_Allowed --
8881 ------------------------
8883 -- pragma Extensions_Allowed (ON | OFF);
8885 when Pragma_Extensions_Allowed =>
8887 Check_Arg_Count (1);
8888 Check_No_Identifiers;
8889 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8891 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8892 Extensions_Allowed := True;
8893 Ada_Version := Ada_Version_Type'Last;
8896 Extensions_Allowed := False;
8897 Ada_Version := Ada_Version_Explicit;
8904 -- pragma External (
8905 -- [ Convention =>] convention_IDENTIFIER,
8906 -- [ Entity =>] local_NAME
8907 -- [, [External_Name =>] static_string_EXPRESSION ]
8908 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8910 when Pragma_External => External : declare
8914 pragma Warnings (Off, C);
8923 Check_At_Least_N_Arguments (2);
8924 Check_At_Most_N_Arguments (4);
8925 Process_Convention (C, Def_Id);
8926 Note_Possible_Modification
8927 (Get_Pragma_Arg (Arg2), Sure => False);
8928 Process_Interface_Name (Def_Id, Arg3, Arg4);
8929 Set_Exported (Def_Id, Arg2);
8932 --------------------------
8933 -- External_Name_Casing --
8934 --------------------------
8936 -- pragma External_Name_Casing (
8937 -- UPPERCASE | LOWERCASE
8938 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8940 when Pragma_External_Name_Casing => External_Name_Casing : declare
8943 Check_No_Identifiers;
8945 if Arg_Count = 2 then
8947 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8949 case Chars (Get_Pragma_Arg (Arg2)) is
8951 Opt.External_Name_Exp_Casing := As_Is;
8953 when Name_Uppercase =>
8954 Opt.External_Name_Exp_Casing := Uppercase;
8956 when Name_Lowercase =>
8957 Opt.External_Name_Exp_Casing := Lowercase;
8964 Check_Arg_Count (1);
8967 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8969 case Chars (Get_Pragma_Arg (Arg1)) is
8970 when Name_Uppercase =>
8971 Opt.External_Name_Imp_Casing := Uppercase;
8973 when Name_Lowercase =>
8974 Opt.External_Name_Imp_Casing := Lowercase;
8979 end External_Name_Casing;
8981 --------------------------
8982 -- Favor_Top_Level --
8983 --------------------------
8985 -- pragma Favor_Top_Level (type_NAME);
8987 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8988 Named_Entity : Entity_Id;
8992 Check_No_Identifiers;
8993 Check_Arg_Count (1);
8994 Check_Arg_Is_Local_Name (Arg1);
8995 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8997 -- If it's an access-to-subprogram type (in particular, not a
8998 -- subtype), set the flag on that type.
9000 if Is_Access_Subprogram_Type (Named_Entity) then
9001 Set_Can_Use_Internal_Rep (Named_Entity, False);
9003 -- Otherwise it's an error (name denotes the wrong sort of entity)
9007 ("access-to-subprogram type expected",
9008 Get_Pragma_Arg (Arg1));
9010 end Favor_Top_Level;
9016 -- pragma Fast_Math;
9018 when Pragma_Fast_Math =>
9020 Check_No_Identifiers;
9021 Check_Valid_Configuration_Pragma;
9024 ---------------------------
9025 -- Finalize_Storage_Only --
9026 ---------------------------
9028 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9030 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9031 Assoc : constant Node_Id := Arg1;
9032 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9037 Check_No_Identifiers;
9038 Check_Arg_Count (1);
9039 Check_Arg_Is_Local_Name (Arg1);
9041 Find_Type (Type_Id);
9042 Typ := Entity (Type_Id);
9045 or else Rep_Item_Too_Early (Typ, N)
9049 Typ := Underlying_Type (Typ);
9052 if not Is_Controlled (Typ) then
9053 Error_Pragma ("pragma% must specify controlled type");
9056 Check_First_Subtype (Arg1);
9058 if Finalize_Storage_Only (Typ) then
9059 Error_Pragma ("duplicate pragma%, only one allowed");
9061 elsif not Rep_Item_Too_Late (Typ, N) then
9062 Set_Finalize_Storage_Only (Base_Type (Typ), True);
9064 end Finalize_Storage;
9066 --------------------------
9067 -- Float_Representation --
9068 --------------------------
9070 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9072 -- FLOAT_REP ::= VAX_Float | IEEE_Float
9074 when Pragma_Float_Representation => Float_Representation : declare
9082 if Arg_Count = 1 then
9083 Check_Valid_Configuration_Pragma;
9085 Check_Arg_Count (2);
9086 Check_Optional_Identifier (Arg2, Name_Entity);
9087 Check_Arg_Is_Local_Name (Arg2);
9090 Check_No_Identifier (Arg1);
9091 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9093 if not OpenVMS_On_Target then
9094 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9096 ("?pragma% ignored (applies only to Open'V'M'S)");
9102 -- One argument case
9104 if Arg_Count = 1 then
9105 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9106 if Opt.Float_Format = 'I' then
9107 Error_Pragma ("'I'E'E'E format previously specified");
9110 Opt.Float_Format := 'V';
9113 if Opt.Float_Format = 'V' then
9114 Error_Pragma ("'V'A'X format previously specified");
9117 Opt.Float_Format := 'I';
9120 Set_Standard_Fpt_Formats;
9122 -- Two argument case
9125 Argx := Get_Pragma_Arg (Arg2);
9127 if not Is_Entity_Name (Argx)
9128 or else not Is_Floating_Point_Type (Entity (Argx))
9131 ("second argument of% pragma must be floating-point type",
9135 Ent := Entity (Argx);
9136 Digs := UI_To_Int (Digits_Value (Ent));
9138 -- Two arguments, VAX_Float case
9140 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9142 when 6 => Set_F_Float (Ent);
9143 when 9 => Set_D_Float (Ent);
9144 when 15 => Set_G_Float (Ent);
9148 ("wrong digits value, must be 6,9 or 15", Arg2);
9151 -- Two arguments, IEEE_Float case
9155 when 6 => Set_IEEE_Short (Ent);
9156 when 15 => Set_IEEE_Long (Ent);
9160 ("wrong digits value, must be 6 or 15", Arg2);
9164 end Float_Representation;
9170 -- pragma Ident (static_string_EXPRESSION)
9172 -- Note: pragma Comment shares this processing. Pragma Comment is
9173 -- identical to Ident, except that the restriction of the argument to
9174 -- 31 characters and the placement restrictions are not enforced for
9177 when Pragma_Ident | Pragma_Comment => Ident : declare
9182 Check_Arg_Count (1);
9183 Check_No_Identifiers;
9184 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9187 -- For pragma Ident, preserve DEC compatibility by requiring the
9188 -- pragma to appear in a declarative part or package spec.
9190 if Prag_Id = Pragma_Ident then
9191 Check_Is_In_Decl_Part_Or_Package_Spec;
9194 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9201 GP := Parent (Parent (N));
9203 if Nkind_In (GP, N_Package_Declaration,
9204 N_Generic_Package_Declaration)
9209 -- If we have a compilation unit, then record the ident value,
9210 -- checking for improper duplication.
9212 if Nkind (GP) = N_Compilation_Unit then
9213 CS := Ident_String (Current_Sem_Unit);
9215 if Present (CS) then
9217 -- For Ident, we do not permit multiple instances
9219 if Prag_Id = Pragma_Ident then
9220 Error_Pragma ("duplicate% pragma not permitted");
9222 -- For Comment, we concatenate the string, unless we want
9223 -- to preserve the tree structure for ASIS.
9225 elsif not ASIS_Mode then
9226 Start_String (Strval (CS));
9227 Store_String_Char (' ');
9228 Store_String_Chars (Strval (Str));
9229 Set_Strval (CS, End_String);
9233 -- In VMS, the effect of IDENT is achieved by passing
9234 -- --identification=name as a --for-linker switch.
9236 if OpenVMS_On_Target then
9239 ("--for-linker=--identification=");
9240 String_To_Name_Buffer (Strval (Str));
9241 Store_String_Chars (Name_Buffer (1 .. Name_Len));
9243 -- Only the last processed IDENT is saved. The main
9244 -- purpose is so an IDENT associated with a main
9245 -- procedure will be used in preference to an IDENT
9246 -- associated with a with'd package.
9248 Replace_Linker_Option_String
9249 (End_String, "--for-linker=--identification=");
9252 Set_Ident_String (Current_Sem_Unit, Str);
9255 -- For subunits, we just ignore the Ident, since in GNAT these
9256 -- are not separate object files, and hence not separate units
9257 -- in the unit table.
9259 elsif Nkind (GP) = N_Subunit then
9262 -- Otherwise we have a misplaced pragma Ident, but we ignore
9263 -- this if we are in an instantiation, since it comes from
9264 -- a generic, and has no relevance to the instantiation.
9266 elsif Prag_Id = Pragma_Ident then
9267 if Instantiation_Location (Loc) = No_Location then
9268 Error_Pragma ("pragma% only allowed at outer level");
9274 ----------------------------
9275 -- Implementation_Defined --
9276 ----------------------------
9278 -- pragma Implementation_Defined (local_NAME);
9280 -- Marks previously declared entity as implementation defined. For
9281 -- an overloaded entity, applies to the most recent homonym.
9283 -- pragma Implementation_Defined;
9285 -- The form with no arguments appears anywhere within a scope, most
9286 -- typically a package spec, and indicates that all entities that are
9287 -- defined within the package spec are Implementation_Defined.
9289 when Pragma_Implementation_Defined => Implementation_Defined : declare
9293 Check_No_Identifiers;
9295 -- Form with no arguments
9297 if Arg_Count = 0 then
9298 Set_Is_Implementation_Defined (Current_Scope);
9300 -- Form with one argument
9303 Check_Arg_Count (1);
9304 Check_Arg_Is_Local_Name (Arg1);
9305 Ent := Entity (Get_Pragma_Arg (Arg1));
9306 Set_Is_Implementation_Defined (Ent);
9308 end Implementation_Defined;
9314 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9315 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
9317 when Pragma_Implemented => Implemented : declare
9318 Proc_Id : Entity_Id;
9323 Check_Arg_Count (2);
9324 Check_No_Identifiers;
9325 Check_Arg_Is_Identifier (Arg1);
9326 Check_Arg_Is_Local_Name (Arg1);
9328 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
9330 -- Extract the name of the local procedure
9332 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9334 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9335 -- primitive procedure of a synchronized tagged type.
9337 if Ekind (Proc_Id) = E_Procedure
9338 and then Is_Primitive (Proc_Id)
9339 and then Present (First_Formal (Proc_Id))
9341 Typ := Etype (First_Formal (Proc_Id));
9343 if Is_Tagged_Type (Typ)
9346 -- Check for a protected, a synchronized or a task interface
9348 ((Is_Interface (Typ)
9349 and then Is_Synchronized_Interface (Typ))
9351 -- Check for a protected type or a task type that implements
9355 (Is_Concurrent_Record_Type (Typ)
9356 and then Present (Interfaces (Typ)))
9358 -- Check for a private record extension with keyword
9362 (Ekind_In (Typ, E_Record_Type_With_Private,
9363 E_Record_Subtype_With_Private)
9364 and then Synchronized_Present (Parent (Typ))))
9369 ("controlling formal must be of synchronized " &
9370 "tagged type", Arg1);
9374 -- Procedures declared inside a protected type must be accepted
9376 elsif Ekind (Proc_Id) = E_Procedure
9377 and then Is_Protected_Type (Scope (Proc_Id))
9381 -- The first argument is not a primitive procedure
9385 ("pragma % must be applied to a primitive procedure", Arg1);
9389 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9390 -- By_Protected_Procedure to the primitive procedure of a task
9393 if Chars (Arg2) = Name_By_Protected_Procedure
9394 and then Is_Interface (Typ)
9395 and then Is_Task_Interface (Typ)
9398 ("implementation kind By_Protected_Procedure cannot be " &
9399 "applied to a task interface primitive", Arg2);
9403 Record_Rep_Item (Proc_Id, N);
9406 ----------------------
9407 -- Implicit_Packing --
9408 ----------------------
9410 -- pragma Implicit_Packing;
9412 when Pragma_Implicit_Packing =>
9414 Check_Arg_Count (0);
9415 Implicit_Packing := True;
9422 -- [Convention =>] convention_IDENTIFIER,
9423 -- [Entity =>] local_NAME
9424 -- [, [External_Name =>] static_string_EXPRESSION ]
9425 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9427 when Pragma_Import =>
9428 Check_Ada_83_Warning;
9434 Check_At_Least_N_Arguments (2);
9435 Check_At_Most_N_Arguments (4);
9436 Process_Import_Or_Interface;
9438 ----------------------
9439 -- Import_Exception --
9440 ----------------------
9442 -- pragma Import_Exception (
9443 -- [Internal =>] LOCAL_NAME
9444 -- [, [External =>] EXTERNAL_SYMBOL]
9445 -- [, [Form =>] Ada | VMS]
9446 -- [, [Code =>] static_integer_EXPRESSION]);
9448 when Pragma_Import_Exception => Import_Exception : declare
9449 Args : Args_List (1 .. 4);
9450 Names : constant Name_List (1 .. 4) := (
9456 Internal : Node_Id renames Args (1);
9457 External : Node_Id renames Args (2);
9458 Form : Node_Id renames Args (3);
9459 Code : Node_Id renames Args (4);
9463 Gather_Associations (Names, Args);
9465 if Present (External) and then Present (Code) then
9467 ("cannot give both External and Code options for pragma%");
9470 Process_Extended_Import_Export_Exception_Pragma (
9471 Arg_Internal => Internal,
9472 Arg_External => External,
9476 if not Is_VMS_Exception (Entity (Internal)) then
9477 Set_Imported (Entity (Internal));
9479 end Import_Exception;
9481 ---------------------
9482 -- Import_Function --
9483 ---------------------
9485 -- pragma Import_Function (
9486 -- [Internal =>] LOCAL_NAME,
9487 -- [, [External =>] EXTERNAL_SYMBOL]
9488 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9489 -- [, [Result_Type =>] SUBTYPE_MARK]
9490 -- [, [Mechanism =>] MECHANISM]
9491 -- [, [Result_Mechanism =>] MECHANISM_NAME]
9492 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9494 -- EXTERNAL_SYMBOL ::=
9496 -- | static_string_EXPRESSION
9498 -- PARAMETER_TYPES ::=
9500 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9502 -- TYPE_DESIGNATOR ::=
9504 -- | subtype_Name ' Access
9508 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9510 -- MECHANISM_ASSOCIATION ::=
9511 -- [formal_parameter_NAME =>] MECHANISM_NAME
9513 -- MECHANISM_NAME ::=
9516 -- | Descriptor [([Class =>] CLASS_NAME)]
9518 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9520 when Pragma_Import_Function => Import_Function : declare
9521 Args : Args_List (1 .. 7);
9522 Names : constant Name_List (1 .. 7) := (
9525 Name_Parameter_Types,
9528 Name_Result_Mechanism,
9529 Name_First_Optional_Parameter);
9531 Internal : Node_Id renames Args (1);
9532 External : Node_Id renames Args (2);
9533 Parameter_Types : Node_Id renames Args (3);
9534 Result_Type : Node_Id renames Args (4);
9535 Mechanism : Node_Id renames Args (5);
9536 Result_Mechanism : Node_Id renames Args (6);
9537 First_Optional_Parameter : Node_Id renames Args (7);
9541 Gather_Associations (Names, Args);
9542 Process_Extended_Import_Export_Subprogram_Pragma (
9543 Arg_Internal => Internal,
9544 Arg_External => External,
9545 Arg_Parameter_Types => Parameter_Types,
9546 Arg_Result_Type => Result_Type,
9547 Arg_Mechanism => Mechanism,
9548 Arg_Result_Mechanism => Result_Mechanism,
9549 Arg_First_Optional_Parameter => First_Optional_Parameter);
9550 end Import_Function;
9556 -- pragma Import_Object (
9557 -- [Internal =>] LOCAL_NAME
9558 -- [, [External =>] EXTERNAL_SYMBOL]
9559 -- [, [Size =>] EXTERNAL_SYMBOL]);
9561 -- EXTERNAL_SYMBOL ::=
9563 -- | static_string_EXPRESSION
9565 when Pragma_Import_Object => Import_Object : declare
9566 Args : Args_List (1 .. 3);
9567 Names : constant Name_List (1 .. 3) := (
9572 Internal : Node_Id renames Args (1);
9573 External : Node_Id renames Args (2);
9574 Size : Node_Id renames Args (3);
9578 Gather_Associations (Names, Args);
9579 Process_Extended_Import_Export_Object_Pragma (
9580 Arg_Internal => Internal,
9581 Arg_External => External,
9585 ----------------------
9586 -- Import_Procedure --
9587 ----------------------
9589 -- pragma Import_Procedure (
9590 -- [Internal =>] LOCAL_NAME
9591 -- [, [External =>] EXTERNAL_SYMBOL]
9592 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9593 -- [, [Mechanism =>] MECHANISM]
9594 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9596 -- EXTERNAL_SYMBOL ::=
9598 -- | static_string_EXPRESSION
9600 -- PARAMETER_TYPES ::=
9602 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9604 -- TYPE_DESIGNATOR ::=
9606 -- | subtype_Name ' Access
9610 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9612 -- MECHANISM_ASSOCIATION ::=
9613 -- [formal_parameter_NAME =>] MECHANISM_NAME
9615 -- MECHANISM_NAME ::=
9618 -- | Descriptor [([Class =>] CLASS_NAME)]
9620 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9622 when Pragma_Import_Procedure => Import_Procedure : declare
9623 Args : Args_List (1 .. 5);
9624 Names : constant Name_List (1 .. 5) := (
9627 Name_Parameter_Types,
9629 Name_First_Optional_Parameter);
9631 Internal : Node_Id renames Args (1);
9632 External : Node_Id renames Args (2);
9633 Parameter_Types : Node_Id renames Args (3);
9634 Mechanism : Node_Id renames Args (4);
9635 First_Optional_Parameter : Node_Id renames Args (5);
9639 Gather_Associations (Names, Args);
9640 Process_Extended_Import_Export_Subprogram_Pragma (
9641 Arg_Internal => Internal,
9642 Arg_External => External,
9643 Arg_Parameter_Types => Parameter_Types,
9644 Arg_Mechanism => Mechanism,
9645 Arg_First_Optional_Parameter => First_Optional_Parameter);
9646 end Import_Procedure;
9648 -----------------------------
9649 -- Import_Valued_Procedure --
9650 -----------------------------
9652 -- pragma Import_Valued_Procedure (
9653 -- [Internal =>] LOCAL_NAME
9654 -- [, [External =>] EXTERNAL_SYMBOL]
9655 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9656 -- [, [Mechanism =>] MECHANISM]
9657 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9659 -- EXTERNAL_SYMBOL ::=
9661 -- | static_string_EXPRESSION
9663 -- PARAMETER_TYPES ::=
9665 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9667 -- TYPE_DESIGNATOR ::=
9669 -- | subtype_Name ' Access
9673 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9675 -- MECHANISM_ASSOCIATION ::=
9676 -- [formal_parameter_NAME =>] MECHANISM_NAME
9678 -- MECHANISM_NAME ::=
9681 -- | Descriptor [([Class =>] CLASS_NAME)]
9683 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9685 when Pragma_Import_Valued_Procedure =>
9686 Import_Valued_Procedure : declare
9687 Args : Args_List (1 .. 5);
9688 Names : constant Name_List (1 .. 5) := (
9691 Name_Parameter_Types,
9693 Name_First_Optional_Parameter);
9695 Internal : Node_Id renames Args (1);
9696 External : Node_Id renames Args (2);
9697 Parameter_Types : Node_Id renames Args (3);
9698 Mechanism : Node_Id renames Args (4);
9699 First_Optional_Parameter : Node_Id renames Args (5);
9703 Gather_Associations (Names, Args);
9704 Process_Extended_Import_Export_Subprogram_Pragma (
9705 Arg_Internal => Internal,
9706 Arg_External => External,
9707 Arg_Parameter_Types => Parameter_Types,
9708 Arg_Mechanism => Mechanism,
9709 Arg_First_Optional_Parameter => First_Optional_Parameter);
9710 end Import_Valued_Procedure;
9716 -- pragma Independent (LOCAL_NAME);
9718 when Pragma_Independent => Independent : declare
9725 Check_Ada_83_Warning;
9727 Check_No_Identifiers;
9728 Check_Arg_Count (1);
9729 Check_Arg_Is_Local_Name (Arg1);
9730 E_Id := Get_Pragma_Arg (Arg1);
9732 if Etype (E_Id) = Any_Type then
9737 D := Declaration_Node (E);
9740 -- Check duplicate before we chain ourselves!
9742 Check_Duplicate_Pragma (E);
9744 -- Check appropriate entity
9747 if Rep_Item_Too_Early (E, N)
9749 Rep_Item_Too_Late (E, N)
9753 Check_First_Subtype (Arg1);
9756 elsif K = N_Object_Declaration
9757 or else (K = N_Component_Declaration
9758 and then Original_Record_Component (E) = E)
9760 if Rep_Item_Too_Late (E, N) then
9766 ("inappropriate entity for pragma%", Arg1);
9769 Independence_Checks.Append ((N, E));
9772 ----------------------------
9773 -- Independent_Components --
9774 ----------------------------
9776 -- pragma Atomic_Components (array_LOCAL_NAME);
9778 -- This processing is shared by Volatile_Components
9780 when Pragma_Independent_Components => Independent_Components : declare
9787 Check_Ada_83_Warning;
9789 Check_No_Identifiers;
9790 Check_Arg_Count (1);
9791 Check_Arg_Is_Local_Name (Arg1);
9792 E_Id := Get_Pragma_Arg (Arg1);
9794 if Etype (E_Id) = Any_Type then
9800 -- Check duplicate before we chain ourselves!
9802 Check_Duplicate_Pragma (E);
9804 -- Check appropriate entity
9806 if Rep_Item_Too_Early (E, N)
9808 Rep_Item_Too_Late (E, N)
9813 D := Declaration_Node (E);
9816 if (K = N_Full_Type_Declaration
9817 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9819 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9820 and then Nkind (D) = N_Object_Declaration
9821 and then Nkind (Object_Definition (D)) =
9822 N_Constrained_Array_Definition)
9824 Independence_Checks.Append ((N, E));
9827 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9829 end Independent_Components;
9831 ------------------------
9832 -- Initialize_Scalars --
9833 ------------------------
9835 -- pragma Initialize_Scalars;
9837 when Pragma_Initialize_Scalars =>
9839 Check_Arg_Count (0);
9840 Check_Valid_Configuration_Pragma;
9841 Check_Restriction (No_Initialize_Scalars, N);
9843 -- Initialize_Scalars creates false positives in CodePeer, and
9844 -- incorrect negative results in Alfa mode, so ignore this pragma
9847 if not Restriction_Active (No_Initialize_Scalars)
9848 and then not (CodePeer_Mode or Alfa_Mode)
9850 Init_Or_Norm_Scalars := True;
9851 Initialize_Scalars := True;
9858 -- pragma Inline ( NAME {, NAME} );
9860 when Pragma_Inline =>
9862 -- Pragma is active if inlining option is active
9864 Process_Inline (Inline_Active);
9870 -- pragma Inline_Always ( NAME {, NAME} );
9872 when Pragma_Inline_Always =>
9875 -- Pragma always active unless in CodePeer or Alfa mode, since
9876 -- this causes walk order issues.
9878 if not (CodePeer_Mode or Alfa_Mode) then
9879 Process_Inline (True);
9882 --------------------
9883 -- Inline_Generic --
9884 --------------------
9886 -- pragma Inline_Generic (NAME {, NAME});
9888 when Pragma_Inline_Generic =>
9890 Process_Generic_List;
9892 ----------------------
9893 -- Inspection_Point --
9894 ----------------------
9896 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9898 when Pragma_Inspection_Point => Inspection_Point : declare
9903 if Arg_Count > 0 then
9906 Exp := Get_Pragma_Arg (Arg);
9909 if not Is_Entity_Name (Exp)
9910 or else not Is_Object (Entity (Exp))
9912 Error_Pragma_Arg ("object name required", Arg);
9919 end Inspection_Point;
9925 -- pragma Interface (
9926 -- [ Convention =>] convention_IDENTIFIER,
9927 -- [ Entity =>] local_NAME
9928 -- [, [External_Name =>] static_string_EXPRESSION ]
9929 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9931 when Pragma_Interface =>
9938 Check_At_Least_N_Arguments (2);
9939 Check_At_Most_N_Arguments (4);
9940 Process_Import_Or_Interface;
9942 -- In Ada 2005, the permission to use Interface (a reserved word)
9943 -- as a pragma name is considered an obsolescent feature.
9945 if Ada_Version >= Ada_2005 then
9947 (No_Obsolescent_Features, Pragma_Identifier (N));
9950 --------------------
9951 -- Interface_Name --
9952 --------------------
9954 -- pragma Interface_Name (
9955 -- [ Entity =>] local_NAME
9956 -- [,[External_Name =>] static_string_EXPRESSION ]
9957 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9959 when Pragma_Interface_Name => Interface_Name : declare
9968 ((Name_Entity, Name_External_Name, Name_Link_Name));
9969 Check_At_Least_N_Arguments (2);
9970 Check_At_Most_N_Arguments (3);
9971 Id := Get_Pragma_Arg (Arg1);
9974 if not Is_Entity_Name (Id) then
9976 ("first argument for pragma% must be entity name", Arg1);
9977 elsif Etype (Id) = Any_Type then
9980 Def_Id := Entity (Id);
9983 -- Special DEC-compatible processing for the object case, forces
9984 -- object to be imported.
9986 if Ekind (Def_Id) = E_Variable then
9987 Kill_Size_Check_Code (Def_Id);
9988 Note_Possible_Modification (Id, Sure => False);
9990 -- Initialization is not allowed for imported variable
9992 if Present (Expression (Parent (Def_Id)))
9993 and then Comes_From_Source (Expression (Parent (Def_Id)))
9995 Error_Msg_Sloc := Sloc (Def_Id);
9997 ("no initialization allowed for declaration of& #",
10001 -- For compatibility, support VADS usage of providing both
10002 -- pragmas Interface and Interface_Name to obtain the effect
10003 -- of a single Import pragma.
10005 if Is_Imported (Def_Id)
10006 and then Present (First_Rep_Item (Def_Id))
10007 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
10009 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
10013 Set_Imported (Def_Id);
10016 Set_Is_Public (Def_Id);
10017 Process_Interface_Name (Def_Id, Arg2, Arg3);
10020 -- Otherwise must be subprogram
10022 elsif not Is_Subprogram (Def_Id) then
10024 ("argument of pragma% is not subprogram", Arg1);
10027 Check_At_Most_N_Arguments (3);
10031 -- Loop through homonyms
10034 Def_Id := Get_Base_Subprogram (Hom_Id);
10036 if Is_Imported (Def_Id) then
10037 Process_Interface_Name (Def_Id, Arg2, Arg3);
10041 exit when From_Aspect_Specification (N);
10042 Hom_Id := Homonym (Hom_Id);
10044 exit when No (Hom_Id)
10045 or else Scope (Hom_Id) /= Current_Scope;
10050 ("argument of pragma% is not imported subprogram",
10054 end Interface_Name;
10056 -----------------------
10057 -- Interrupt_Handler --
10058 -----------------------
10060 -- pragma Interrupt_Handler (handler_NAME);
10062 when Pragma_Interrupt_Handler =>
10063 Check_Ada_83_Warning;
10064 Check_Arg_Count (1);
10065 Check_No_Identifiers;
10067 if No_Run_Time_Mode then
10068 Error_Msg_CRT ("Interrupt_Handler pragma", N);
10070 Check_Interrupt_Or_Attach_Handler;
10071 Process_Interrupt_Or_Attach_Handler;
10074 ------------------------
10075 -- Interrupt_Priority --
10076 ------------------------
10078 -- pragma Interrupt_Priority [(EXPRESSION)];
10080 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
10081 P : constant Node_Id := Parent (N);
10085 Check_Ada_83_Warning;
10087 if Arg_Count /= 0 then
10088 Arg := Get_Pragma_Arg (Arg1);
10089 Check_Arg_Count (1);
10090 Check_No_Identifiers;
10092 -- The expression must be analyzed in the special manner
10093 -- described in "Handling of Default and Per-Object
10094 -- Expressions" in sem.ads.
10096 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
10099 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
10103 elsif Has_Pragma_Priority (P) then
10104 Error_Pragma ("duplicate pragma% not allowed");
10107 Set_Has_Pragma_Priority (P, True);
10108 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10110 end Interrupt_Priority;
10112 ---------------------
10113 -- Interrupt_State --
10114 ---------------------
10116 -- pragma Interrupt_State (
10117 -- [Name =>] INTERRUPT_ID,
10118 -- [State =>] INTERRUPT_STATE);
10120 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
10121 -- INTERRUPT_STATE => System | Runtime | User
10123 -- Note: if the interrupt id is given as an identifier, then it must
10124 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
10125 -- given as a static integer expression which must be in the range of
10126 -- Ada.Interrupts.Interrupt_ID.
10128 when Pragma_Interrupt_State => Interrupt_State : declare
10130 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
10131 -- This is the entity Ada.Interrupts.Interrupt_ID;
10133 State_Type : Character;
10134 -- Set to 's'/'r'/'u' for System/Runtime/User
10137 -- Index to entry in Interrupt_States table
10140 -- Value of interrupt
10142 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
10143 -- The first argument to the pragma
10145 Int_Ent : Entity_Id;
10146 -- Interrupt entity in Ada.Interrupts.Names
10150 Check_Arg_Order ((Name_Name, Name_State));
10151 Check_Arg_Count (2);
10153 Check_Optional_Identifier (Arg1, Name_Name);
10154 Check_Optional_Identifier (Arg2, Name_State);
10155 Check_Arg_Is_Identifier (Arg2);
10157 -- First argument is identifier
10159 if Nkind (Arg1X) = N_Identifier then
10161 -- Search list of names in Ada.Interrupts.Names
10163 Int_Ent := First_Entity (RTE (RE_Names));
10165 if No (Int_Ent) then
10166 Error_Pragma_Arg ("invalid interrupt name", Arg1);
10168 elsif Chars (Int_Ent) = Chars (Arg1X) then
10169 Int_Val := Expr_Value (Constant_Value (Int_Ent));
10173 Next_Entity (Int_Ent);
10176 -- First argument is not an identifier, so it must be a static
10177 -- expression of type Ada.Interrupts.Interrupt_ID.
10180 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10181 Int_Val := Expr_Value (Arg1X);
10183 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
10185 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10188 ("value not in range of type " &
10189 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10195 case Chars (Get_Pragma_Arg (Arg2)) is
10196 when Name_Runtime => State_Type := 'r';
10197 when Name_System => State_Type := 's';
10198 when Name_User => State_Type := 'u';
10201 Error_Pragma_Arg ("invalid interrupt state", Arg2);
10204 -- Check if entry is already stored
10206 IST_Num := Interrupt_States.First;
10208 -- If entry not found, add it
10210 if IST_Num > Interrupt_States.Last then
10211 Interrupt_States.Append
10212 ((Interrupt_Number => UI_To_Int (Int_Val),
10213 Interrupt_State => State_Type,
10214 Pragma_Loc => Loc));
10217 -- Case of entry for the same entry
10219 elsif Int_Val = Interrupt_States.Table (IST_Num).
10222 -- If state matches, done, no need to make redundant entry
10225 State_Type = Interrupt_States.Table (IST_Num).
10228 -- Otherwise if state does not match, error
10231 Interrupt_States.Table (IST_Num).Pragma_Loc;
10233 ("state conflicts with that given #", Arg2);
10237 IST_Num := IST_Num + 1;
10239 end Interrupt_State;
10245 -- pragma Invariant
10246 -- ([Entity =>] type_LOCAL_NAME,
10247 -- [Check =>] EXPRESSION
10248 -- [,[Message =>] String_Expression]);
10250 when Pragma_Invariant => Invariant : declare
10255 pragma Unreferenced (Discard);
10259 Check_At_Least_N_Arguments (2);
10260 Check_At_Most_N_Arguments (3);
10261 Check_Optional_Identifier (Arg1, Name_Entity);
10262 Check_Optional_Identifier (Arg2, Name_Check);
10264 if Arg_Count = 3 then
10265 Check_Optional_Identifier (Arg3, Name_Message);
10266 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10269 Check_Arg_Is_Local_Name (Arg1);
10271 Type_Id := Get_Pragma_Arg (Arg1);
10272 Find_Type (Type_Id);
10273 Typ := Entity (Type_Id);
10275 if Typ = Any_Type then
10278 -- An invariant must apply to a private type, or appear in the
10279 -- private part of a package spec and apply to a completion.
10281 elsif Ekind_In (Typ, E_Private_Type,
10282 E_Record_Type_With_Private,
10283 E_Limited_Private_Type)
10287 elsif In_Private_Part (Current_Scope)
10288 and then Has_Private_Declaration (Typ)
10292 elsif In_Private_Part (Current_Scope) then
10294 ("pragma% only allowed for private type " &
10295 "declared in visible part", Arg1);
10299 ("pragma% only allowed for private type", Arg1);
10302 -- Note that the type has at least one invariant, and also that
10303 -- it has inheritable invariants if we have Invariant'Class.
10305 Set_Has_Invariants (Typ);
10307 if Class_Present (N) then
10308 Set_Has_Inheritable_Invariants (Typ);
10311 -- The remaining processing is simply to link the pragma on to
10312 -- the rep item chain, for processing when the type is frozen.
10313 -- This is accomplished by a call to Rep_Item_Too_Late.
10315 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10318 ----------------------
10319 -- Java_Constructor --
10320 ----------------------
10322 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10324 -- Also handles pragma CIL_Constructor
10326 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10327 Java_Constructor : declare
10328 Convention : Convention_Id;
10329 Def_Id : Entity_Id;
10330 Hom_Id : Entity_Id;
10332 This_Formal : Entity_Id;
10336 Check_Arg_Count (1);
10337 Check_Optional_Identifier (Arg1, Name_Entity);
10338 Check_Arg_Is_Local_Name (Arg1);
10340 Id := Get_Pragma_Arg (Arg1);
10341 Find_Program_Unit_Name (Id);
10343 -- If we did not find the name, we are done
10345 if Etype (Id) = Any_Type then
10349 -- Check wrong use of pragma in wrong VM target
10351 if VM_Target = No_VM then
10354 elsif VM_Target = CLI_Target
10355 and then Prag_Id = Pragma_Java_Constructor
10357 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10359 elsif VM_Target = JVM_Target
10360 and then Prag_Id = Pragma_CIL_Constructor
10362 Error_Pragma ("must use pragma 'Java_'Constructor");
10366 when Pragma_CIL_Constructor => Convention := Convention_CIL;
10367 when Pragma_Java_Constructor => Convention := Convention_Java;
10368 when others => null;
10371 Hom_Id := Entity (Id);
10373 -- Loop through homonyms
10376 Def_Id := Get_Base_Subprogram (Hom_Id);
10378 -- The constructor is required to be a function
10380 if Ekind (Def_Id) /= E_Function then
10381 if VM_Target = JVM_Target then
10383 ("pragma% requires function returning a " &
10384 "'Java access type", Def_Id);
10387 ("pragma% requires function returning a " &
10388 "'C'I'L access type", Def_Id);
10392 -- Check arguments: For tagged type the first formal must be
10393 -- named "this" and its type must be a named access type
10394 -- designating a class-wide tagged type that has convention
10395 -- CIL/Java. The first formal must also have a null default
10396 -- value. For example:
10398 -- type Typ is tagged ...
10399 -- type Ref is access all Typ;
10400 -- pragma Convention (CIL, Typ);
10402 -- function New_Typ (This : Ref) return Ref;
10403 -- function New_Typ (This : Ref; I : Integer) return Ref;
10404 -- pragma Cil_Constructor (New_Typ);
10406 -- Reason: The first formal must NOT be a primitive of the
10409 -- This rule also applies to constructors of delegates used
10410 -- to interface with standard target libraries. For example:
10412 -- type Delegate is access procedure ...
10413 -- pragma Import (CIL, Delegate, ...);
10415 -- function new_Delegate
10416 -- (This : Delegate := null; ... ) return Delegate;
10418 -- For value-types this rule does not apply.
10420 if not Is_Value_Type (Etype (Def_Id)) then
10421 if No (First_Formal (Def_Id)) then
10422 Error_Msg_Name_1 := Pname;
10423 Error_Msg_N ("% function must have parameters", Def_Id);
10427 -- In the JRE library we have several occurrences in which
10428 -- the "this" parameter is not the first formal.
10430 This_Formal := First_Formal (Def_Id);
10432 -- In the JRE library we have several occurrences in which
10433 -- the "this" parameter is not the first formal. Search for
10436 if VM_Target = JVM_Target then
10437 while Present (This_Formal)
10438 and then Get_Name_String (Chars (This_Formal)) /= "this"
10440 Next_Formal (This_Formal);
10443 if No (This_Formal) then
10444 This_Formal := First_Formal (Def_Id);
10448 -- Warning: The first parameter should be named "this".
10449 -- We temporarily allow it because we have the following
10450 -- case in the Java runtime (file s-osinte.ads) ???
10452 -- function new_Thread
10453 -- (Self_Id : System.Address) return Thread_Id;
10454 -- pragma Java_Constructor (new_Thread);
10456 if VM_Target = JVM_Target
10457 and then Get_Name_String (Chars (First_Formal (Def_Id)))
10459 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10463 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10464 Error_Msg_Name_1 := Pname;
10466 ("first formal of % function must be named `this`",
10467 Parent (This_Formal));
10469 elsif not Is_Access_Type (Etype (This_Formal)) then
10470 Error_Msg_Name_1 := Pname;
10472 ("first formal of % function must be an access type",
10473 Parameter_Type (Parent (This_Formal)));
10475 -- For delegates the type of the first formal must be a
10476 -- named access-to-subprogram type (see previous example)
10478 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10479 and then Ekind (Etype (This_Formal))
10480 /= E_Access_Subprogram_Type
10482 Error_Msg_Name_1 := Pname;
10484 ("first formal of % function must be a named access" &
10485 " to subprogram type",
10486 Parameter_Type (Parent (This_Formal)));
10488 -- Warning: We should reject anonymous access types because
10489 -- the constructor must not be handled as a primitive of the
10490 -- tagged type. We temporarily allow it because this profile
10491 -- is currently generated by cil2ada???
10493 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10494 and then not Ekind_In (Etype (This_Formal),
10496 E_General_Access_Type,
10497 E_Anonymous_Access_Type)
10499 Error_Msg_Name_1 := Pname;
10501 ("first formal of % function must be a named access" &
10503 Parameter_Type (Parent (This_Formal)));
10505 elsif Atree.Convention
10506 (Designated_Type (Etype (This_Formal))) /= Convention
10508 Error_Msg_Name_1 := Pname;
10510 if Convention = Convention_Java then
10512 ("pragma% requires convention 'Cil in designated" &
10514 Parameter_Type (Parent (This_Formal)));
10517 ("pragma% requires convention 'Java in designated" &
10519 Parameter_Type (Parent (This_Formal)));
10522 elsif No (Expression (Parent (This_Formal)))
10523 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10525 Error_Msg_Name_1 := Pname;
10527 ("pragma% requires first formal with default `null`",
10528 Parameter_Type (Parent (This_Formal)));
10532 -- Check result type: the constructor must be a function
10534 -- * a value type (only allowed in the CIL compiler)
10535 -- * an access-to-subprogram type with convention Java/CIL
10536 -- * an access-type designating a type that has convention
10539 if Is_Value_Type (Etype (Def_Id)) then
10542 -- Access-to-subprogram type with convention Java/CIL
10544 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10545 if Atree.Convention (Etype (Def_Id)) /= Convention then
10546 if Convention = Convention_Java then
10548 ("pragma% requires function returning a " &
10549 "'Java access type", Arg1);
10551 pragma Assert (Convention = Convention_CIL);
10553 ("pragma% requires function returning a " &
10554 "'C'I'L access type", Arg1);
10558 elsif Ekind (Etype (Def_Id)) in Access_Kind then
10559 if not Ekind_In (Etype (Def_Id), E_Access_Type,
10560 E_General_Access_Type)
10563 (Designated_Type (Etype (Def_Id))) /= Convention
10565 Error_Msg_Name_1 := Pname;
10567 if Convention = Convention_Java then
10569 ("pragma% requires function returning a named" &
10570 "'Java access type", Arg1);
10573 ("pragma% requires function returning a named" &
10574 "'C'I'L access type", Arg1);
10579 Set_Is_Constructor (Def_Id);
10580 Set_Convention (Def_Id, Convention);
10581 Set_Is_Imported (Def_Id);
10583 exit when From_Aspect_Specification (N);
10584 Hom_Id := Homonym (Hom_Id);
10586 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10588 end Java_Constructor;
10590 ----------------------
10591 -- Java_Interface --
10592 ----------------------
10594 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
10596 when Pragma_Java_Interface => Java_Interface : declare
10602 Check_Arg_Count (1);
10603 Check_Optional_Identifier (Arg1, Name_Entity);
10604 Check_Arg_Is_Local_Name (Arg1);
10606 Arg := Get_Pragma_Arg (Arg1);
10609 if Etype (Arg) = Any_Type then
10613 if not Is_Entity_Name (Arg)
10614 or else not Is_Type (Entity (Arg))
10616 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10619 Typ := Underlying_Type (Entity (Arg));
10621 -- For now simply check some of the semantic constraints on the
10622 -- type. This currently leaves out some restrictions on interface
10623 -- types, namely that the parent type must be java.lang.Object.Typ
10624 -- and that all primitives of the type should be declared
10627 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10628 Error_Pragma_Arg ("pragma% requires an abstract "
10629 & "tagged type", Arg1);
10631 elsif not Has_Discriminants (Typ)
10632 or else Ekind (Etype (First_Discriminant (Typ)))
10633 /= E_Anonymous_Access_Type
10635 not Is_Class_Wide_Type
10636 (Designated_Type (Etype (First_Discriminant (Typ))))
10639 ("type must have a class-wide access discriminant", Arg1);
10641 end Java_Interface;
10647 -- pragma Keep_Names ([On => ] local_NAME);
10649 when Pragma_Keep_Names => Keep_Names : declare
10654 Check_Arg_Count (1);
10655 Check_Optional_Identifier (Arg1, Name_On);
10656 Check_Arg_Is_Local_Name (Arg1);
10658 Arg := Get_Pragma_Arg (Arg1);
10661 if Etype (Arg) = Any_Type then
10665 if not Is_Entity_Name (Arg)
10666 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10669 ("pragma% requires a local enumeration type", Arg1);
10672 Set_Discard_Names (Entity (Arg), False);
10679 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10681 when Pragma_License =>
10683 Check_Arg_Count (1);
10684 Check_No_Identifiers;
10685 Check_Valid_Configuration_Pragma;
10686 Check_Arg_Is_Identifier (Arg1);
10689 Sind : constant Source_File_Index :=
10690 Source_Index (Current_Sem_Unit);
10693 case Chars (Get_Pragma_Arg (Arg1)) is
10695 Set_License (Sind, GPL);
10697 when Name_Modified_GPL =>
10698 Set_License (Sind, Modified_GPL);
10700 when Name_Restricted =>
10701 Set_License (Sind, Restricted);
10703 when Name_Unrestricted =>
10704 Set_License (Sind, Unrestricted);
10707 Error_Pragma_Arg ("invalid license name", Arg1);
10715 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10717 when Pragma_Link_With => Link_With : declare
10723 if Operating_Mode = Generate_Code
10724 and then In_Extended_Main_Source_Unit (N)
10726 Check_At_Least_N_Arguments (1);
10727 Check_No_Identifiers;
10728 Check_Is_In_Decl_Part_Or_Package_Spec;
10729 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10733 while Present (Arg) loop
10734 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10736 -- Store argument, converting sequences of spaces to a
10737 -- single null character (this is one of the differences
10738 -- in processing between Link_With and Linker_Options).
10740 Arg_Store : declare
10741 C : constant Char_Code := Get_Char_Code (' ');
10742 S : constant String_Id :=
10743 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10744 L : constant Nat := String_Length (S);
10747 procedure Skip_Spaces;
10748 -- Advance F past any spaces
10754 procedure Skip_Spaces is
10756 while F <= L and then Get_String_Char (S, F) = C loop
10761 -- Start of processing for Arg_Store
10764 Skip_Spaces; -- skip leading spaces
10766 -- Loop through characters, changing any embedded
10767 -- sequence of spaces to a single null character (this
10768 -- is how Link_With/Linker_Options differ)
10771 if Get_String_Char (S, F) = C then
10774 Store_String_Char (ASCII.NUL);
10777 Store_String_Char (Get_String_Char (S, F));
10785 if Present (Arg) then
10786 Store_String_Char (ASCII.NUL);
10790 Store_Linker_Option_String (End_String);
10798 -- pragma Linker_Alias (
10799 -- [Entity =>] LOCAL_NAME
10800 -- [Target =>] static_string_EXPRESSION);
10802 when Pragma_Linker_Alias =>
10804 Check_Arg_Order ((Name_Entity, Name_Target));
10805 Check_Arg_Count (2);
10806 Check_Optional_Identifier (Arg1, Name_Entity);
10807 Check_Optional_Identifier (Arg2, Name_Target);
10808 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10809 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10811 -- The only processing required is to link this item on to the
10812 -- list of rep items for the given entity. This is accomplished
10813 -- by the call to Rep_Item_Too_Late (when no error is detected
10814 -- and False is returned).
10816 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10819 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10822 ------------------------
10823 -- Linker_Constructor --
10824 ------------------------
10826 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10828 -- Code is shared with Linker_Destructor
10830 -----------------------
10831 -- Linker_Destructor --
10832 -----------------------
10834 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10836 when Pragma_Linker_Constructor |
10837 Pragma_Linker_Destructor =>
10838 Linker_Constructor : declare
10844 Check_Arg_Count (1);
10845 Check_No_Identifiers;
10846 Check_Arg_Is_Local_Name (Arg1);
10847 Arg1_X := Get_Pragma_Arg (Arg1);
10849 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10851 if not Is_Library_Level_Entity (Proc) then
10853 ("argument for pragma% must be library level entity", Arg1);
10856 -- The only processing required is to link this item on to the
10857 -- list of rep items for the given entity. This is accomplished
10858 -- by the call to Rep_Item_Too_Late (when no error is detected
10859 -- and False is returned).
10861 if Rep_Item_Too_Late (Proc, N) then
10864 Set_Has_Gigi_Rep_Item (Proc);
10866 end Linker_Constructor;
10868 --------------------
10869 -- Linker_Options --
10870 --------------------
10872 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10874 when Pragma_Linker_Options => Linker_Options : declare
10878 Check_Ada_83_Warning;
10879 Check_No_Identifiers;
10880 Check_Arg_Count (1);
10881 Check_Is_In_Decl_Part_Or_Package_Spec;
10882 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10883 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10886 while Present (Arg) loop
10887 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10888 Store_String_Char (ASCII.NUL);
10890 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10894 if Operating_Mode = Generate_Code
10895 and then In_Extended_Main_Source_Unit (N)
10897 Store_Linker_Option_String (End_String);
10899 end Linker_Options;
10901 --------------------
10902 -- Linker_Section --
10903 --------------------
10905 -- pragma Linker_Section (
10906 -- [Entity =>] LOCAL_NAME
10907 -- [Section =>] static_string_EXPRESSION);
10909 when Pragma_Linker_Section =>
10911 Check_Arg_Order ((Name_Entity, Name_Section));
10912 Check_Arg_Count (2);
10913 Check_Optional_Identifier (Arg1, Name_Entity);
10914 Check_Optional_Identifier (Arg2, Name_Section);
10915 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10916 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10918 -- This pragma applies only to objects
10920 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10921 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10924 -- The only processing required is to link this item on to the
10925 -- list of rep items for the given entity. This is accomplished
10926 -- by the call to Rep_Item_Too_Late (when no error is detected
10927 -- and False is returned).
10929 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10932 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10939 -- pragma List (On | Off)
10941 -- There is nothing to do here, since we did all the processing for
10942 -- this pragma in Par.Prag (so that it works properly even in syntax
10945 when Pragma_List =>
10948 --------------------
10949 -- Locking_Policy --
10950 --------------------
10952 -- pragma Locking_Policy (policy_IDENTIFIER);
10954 when Pragma_Locking_Policy => declare
10955 subtype LP_Range is Name_Id
10956 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
10960 Check_Ada_83_Warning;
10961 Check_Arg_Count (1);
10962 Check_No_Identifiers;
10963 Check_Arg_Is_Locking_Policy (Arg1);
10964 Check_Valid_Configuration_Pragma;
10965 LP_Val := Chars (Get_Pragma_Arg (Arg1));
10968 when Name_Ceiling_Locking => LP := 'C';
10969 when Name_Inheritance_Locking => LP := 'I';
10970 when Name_Concurrent_Readers_Locking => LP := 'R';
10973 if Locking_Policy /= ' '
10974 and then Locking_Policy /= LP
10976 Error_Msg_Sloc := Locking_Policy_Sloc;
10977 Error_Pragma ("locking policy incompatible with policy#");
10979 -- Set new policy, but always preserve System_Location since we
10980 -- like the error message with the run time name.
10983 Locking_Policy := LP;
10985 if Locking_Policy_Sloc /= System_Location then
10986 Locking_Policy_Sloc := Loc;
10995 -- pragma Long_Float (D_Float | G_Float);
10997 when Pragma_Long_Float => Long_Float : declare
11000 Check_Valid_Configuration_Pragma;
11001 Check_Arg_Count (1);
11002 Check_No_Identifier (Arg1);
11003 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
11005 if not OpenVMS_On_Target then
11006 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
11011 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
11012 if Opt.Float_Format_Long = 'G' then
11014 ("G_Float previously specified", Arg1);
11016 elsif Current_Sem_Unit /= Main_Unit
11017 and then Opt.Float_Format_Long /= 'D'
11020 ("main unit not compiled with pragma Long_Float (D_Float)",
11021 "\pragma% must be used consistently for whole partition",
11025 Opt.Float_Format_Long := 'D';
11028 -- G_Float case (this is the default, does not need overriding)
11031 if Opt.Float_Format_Long = 'D' then
11032 Error_Pragma ("D_Float previously specified");
11034 elsif Current_Sem_Unit /= Main_Unit
11035 and then Opt.Float_Format_Long /= 'G'
11038 ("main unit not compiled with pragma Long_Float (G_Float)",
11039 "\pragma% must be used consistently for whole partition",
11043 Opt.Float_Format_Long := 'G';
11047 Set_Standard_Fpt_Formats;
11050 -----------------------
11051 -- Machine_Attribute --
11052 -----------------------
11054 -- pragma Machine_Attribute (
11055 -- [Entity =>] LOCAL_NAME,
11056 -- [Attribute_Name =>] static_string_EXPRESSION
11057 -- [, [Info =>] static_EXPRESSION] );
11059 when Pragma_Machine_Attribute => Machine_Attribute : declare
11060 Def_Id : Entity_Id;
11064 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
11066 if Arg_Count = 3 then
11067 Check_Optional_Identifier (Arg3, Name_Info);
11068 Check_Arg_Is_Static_Expression (Arg3);
11070 Check_Arg_Count (2);
11073 Check_Optional_Identifier (Arg1, Name_Entity);
11074 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
11075 Check_Arg_Is_Local_Name (Arg1);
11076 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11077 Def_Id := Entity (Get_Pragma_Arg (Arg1));
11079 if Is_Access_Type (Def_Id) then
11080 Def_Id := Designated_Type (Def_Id);
11083 if Rep_Item_Too_Early (Def_Id, N) then
11087 Def_Id := Underlying_Type (Def_Id);
11089 -- The only processing required is to link this item on to the
11090 -- list of rep items for the given entity. This is accomplished
11091 -- by the call to Rep_Item_Too_Late (when no error is detected
11092 -- and False is returned).
11094 if Rep_Item_Too_Late (Def_Id, N) then
11097 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11099 end Machine_Attribute;
11106 -- (MAIN_OPTION [, MAIN_OPTION]);
11109 -- [STACK_SIZE =>] static_integer_EXPRESSION
11110 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
11111 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
11113 when Pragma_Main => Main : declare
11114 Args : Args_List (1 .. 3);
11115 Names : constant Name_List (1 .. 3) := (
11117 Name_Task_Stack_Size_Default,
11118 Name_Time_Slicing_Enabled);
11124 Gather_Associations (Names, Args);
11126 for J in 1 .. 2 loop
11127 if Present (Args (J)) then
11128 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11132 if Present (Args (3)) then
11133 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
11137 while Present (Nod) loop
11138 if Nkind (Nod) = N_Pragma
11139 and then Pragma_Name (Nod) = Name_Main
11141 Error_Msg_Name_1 := Pname;
11142 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11153 -- pragma Main_Storage
11154 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
11156 -- MAIN_STORAGE_OPTION ::=
11157 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
11158 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
11160 when Pragma_Main_Storage => Main_Storage : declare
11161 Args : Args_List (1 .. 2);
11162 Names : constant Name_List (1 .. 2) := (
11163 Name_Working_Storage,
11170 Gather_Associations (Names, Args);
11172 for J in 1 .. 2 loop
11173 if Present (Args (J)) then
11174 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11178 Check_In_Main_Program;
11181 while Present (Nod) loop
11182 if Nkind (Nod) = N_Pragma
11183 and then Pragma_Name (Nod) = Name_Main_Storage
11185 Error_Msg_Name_1 := Pname;
11186 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11197 -- pragma Memory_Size (NUMERIC_LITERAL)
11199 when Pragma_Memory_Size =>
11202 -- Memory size is simply ignored
11204 Check_No_Identifiers;
11205 Check_Arg_Count (1);
11206 Check_Arg_Is_Integer_Literal (Arg1);
11214 -- The only correct use of this pragma is on its own in a file, in
11215 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
11216 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
11217 -- check for a file containing nothing but a No_Body pragma). If we
11218 -- attempt to process it during normal semantics processing, it means
11219 -- it was misplaced.
11221 when Pragma_No_Body =>
11229 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
11231 when Pragma_No_Return => No_Return : declare
11239 Check_At_Least_N_Arguments (1);
11241 -- Loop through arguments of pragma
11244 while Present (Arg) loop
11245 Check_Arg_Is_Local_Name (Arg);
11246 Id := Get_Pragma_Arg (Arg);
11249 if not Is_Entity_Name (Id) then
11250 Error_Pragma_Arg ("entity name required", Arg);
11253 if Etype (Id) = Any_Type then
11257 -- Loop to find matching procedures
11262 and then Scope (E) = Current_Scope
11264 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11267 -- Set flag on any alias as well
11269 if Is_Overloadable (E) and then Present (Alias (E)) then
11270 Set_No_Return (Alias (E));
11276 exit when From_Aspect_Specification (N);
11281 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11292 -- pragma No_Run_Time;
11294 -- Note: this pragma is retained for backwards compatibility. See
11295 -- body of Rtsfind for full details on its handling.
11297 when Pragma_No_Run_Time =>
11299 Check_Valid_Configuration_Pragma;
11300 Check_Arg_Count (0);
11302 No_Run_Time_Mode := True;
11303 Configurable_Run_Time_Mode := True;
11305 -- Set Duration to 32 bits if word size is 32
11307 if Ttypes.System_Word_Size = 32 then
11308 Duration_32_Bits_On_Target := True;
11311 -- Set appropriate restrictions
11313 Set_Restriction (No_Finalization, N);
11314 Set_Restriction (No_Exception_Handlers, N);
11315 Set_Restriction (Max_Tasks, N, 0);
11316 Set_Restriction (No_Tasking, N);
11318 ------------------------
11319 -- No_Strict_Aliasing --
11320 ------------------------
11322 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11324 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11329 Check_At_Most_N_Arguments (1);
11331 if Arg_Count = 0 then
11332 Check_Valid_Configuration_Pragma;
11333 Opt.No_Strict_Aliasing := True;
11336 Check_Optional_Identifier (Arg2, Name_Entity);
11337 Check_Arg_Is_Local_Name (Arg1);
11338 E_Id := Entity (Get_Pragma_Arg (Arg1));
11340 if E_Id = Any_Type then
11342 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11343 Error_Pragma_Arg ("pragma% requires access type", Arg1);
11346 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11348 end No_Strict_Aliasing;
11350 -----------------------
11351 -- Normalize_Scalars --
11352 -----------------------
11354 -- pragma Normalize_Scalars;
11356 when Pragma_Normalize_Scalars =>
11357 Check_Ada_83_Warning;
11358 Check_Arg_Count (0);
11359 Check_Valid_Configuration_Pragma;
11361 -- Normalize_Scalars creates false positives in CodePeer, and
11362 -- incorrect negative results in Alfa mode, so ignore this pragma
11365 if not (CodePeer_Mode or Alfa_Mode) then
11366 Normalize_Scalars := True;
11367 Init_Or_Norm_Scalars := True;
11374 -- pragma Obsolescent;
11376 -- pragma Obsolescent (
11377 -- [Message =>] static_string_EXPRESSION
11378 -- [,[Version =>] Ada_05]]);
11380 -- pragma Obsolescent (
11381 -- [Entity =>] NAME
11382 -- [,[Message =>] static_string_EXPRESSION
11383 -- [,[Version =>] Ada_05]] );
11385 when Pragma_Obsolescent => Obsolescent : declare
11389 procedure Set_Obsolescent (E : Entity_Id);
11390 -- Given an entity Ent, mark it as obsolescent if appropriate
11392 ---------------------
11393 -- Set_Obsolescent --
11394 ---------------------
11396 procedure Set_Obsolescent (E : Entity_Id) is
11405 -- Entity name was given
11407 if Present (Ename) then
11409 -- If entity name matches, we are fine. Save entity in
11410 -- pragma argument, for ASIS use.
11412 if Chars (Ename) = Chars (Ent) then
11413 Set_Entity (Ename, Ent);
11414 Generate_Reference (Ent, Ename);
11416 -- If entity name does not match, only possibility is an
11417 -- enumeration literal from an enumeration type declaration.
11419 elsif Ekind (Ent) /= E_Enumeration_Type then
11421 ("pragma % entity name does not match declaration");
11424 Ent := First_Literal (E);
11428 ("pragma % entity name does not match any " &
11429 "enumeration literal");
11431 elsif Chars (Ent) = Chars (Ename) then
11432 Set_Entity (Ename, Ent);
11433 Generate_Reference (Ent, Ename);
11437 Ent := Next_Literal (Ent);
11443 -- Ent points to entity to be marked
11445 if Arg_Count >= 1 then
11447 -- Deal with static string argument
11449 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11450 S := Strval (Get_Pragma_Arg (Arg1));
11452 for J in 1 .. String_Length (S) loop
11453 if not In_Character_Range (Get_String_Char (S, J)) then
11455 ("pragma% argument does not allow wide characters",
11460 Obsolescent_Warnings.Append
11461 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11463 -- Check for Ada_05 parameter
11465 if Arg_Count /= 1 then
11466 Check_Arg_Count (2);
11469 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11472 Check_Arg_Is_Identifier (Argx);
11474 if Chars (Argx) /= Name_Ada_05 then
11475 Error_Msg_Name_2 := Name_Ada_05;
11477 ("only allowed argument for pragma% is %", Argx);
11480 if Ada_Version_Explicit < Ada_2005
11481 or else not Warn_On_Ada_2005_Compatibility
11489 -- Set flag if pragma active
11492 Set_Is_Obsolescent (Ent);
11496 end Set_Obsolescent;
11498 -- Start of processing for pragma Obsolescent
11503 Check_At_Most_N_Arguments (3);
11505 -- See if first argument specifies an entity name
11509 (Chars (Arg1) = Name_Entity
11511 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11513 N_Operator_Symbol))
11515 Ename := Get_Pragma_Arg (Arg1);
11517 -- Eliminate first argument, so we can share processing
11521 Arg_Count := Arg_Count - 1;
11523 -- No Entity name argument given
11529 if Arg_Count >= 1 then
11530 Check_Optional_Identifier (Arg1, Name_Message);
11532 if Arg_Count = 2 then
11533 Check_Optional_Identifier (Arg2, Name_Version);
11537 -- Get immediately preceding declaration
11540 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11544 -- Cases where we do not follow anything other than another pragma
11548 -- First case: library level compilation unit declaration with
11549 -- the pragma immediately following the declaration.
11551 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11553 (Defining_Entity (Unit (Parent (Parent (N)))));
11556 -- Case 2: library unit placement for package
11560 Ent : constant Entity_Id := Find_Lib_Unit_Name;
11562 if Is_Package_Or_Generic_Package (Ent) then
11563 Set_Obsolescent (Ent);
11569 -- Cases where we must follow a declaration
11572 if Nkind (Decl) not in N_Declaration
11573 and then Nkind (Decl) not in N_Later_Decl_Item
11574 and then Nkind (Decl) not in N_Generic_Declaration
11575 and then Nkind (Decl) not in N_Renaming_Declaration
11578 ("pragma% misplaced, "
11579 & "must immediately follow a declaration");
11582 Set_Obsolescent (Defining_Entity (Decl));
11592 -- pragma Optimize (Time | Space | Off);
11594 -- The actual check for optimize is done in Gigi. Note that this
11595 -- pragma does not actually change the optimization setting, it
11596 -- simply checks that it is consistent with the pragma.
11598 when Pragma_Optimize =>
11599 Check_No_Identifiers;
11600 Check_Arg_Count (1);
11601 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11603 ------------------------
11604 -- Optimize_Alignment --
11605 ------------------------
11607 -- pragma Optimize_Alignment (Time | Space | Off);
11609 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11611 Check_No_Identifiers;
11612 Check_Arg_Count (1);
11613 Check_Valid_Configuration_Pragma;
11616 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11620 Opt.Optimize_Alignment := 'T';
11622 Opt.Optimize_Alignment := 'S';
11624 Opt.Optimize_Alignment := 'O';
11626 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11630 -- Set indication that mode is set locally. If we are in fact in a
11631 -- configuration pragma file, this setting is harmless since the
11632 -- switch will get reset anyway at the start of each unit.
11634 Optimize_Alignment_Local := True;
11635 end Optimize_Alignment;
11641 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11643 when Pragma_Ordered => Ordered : declare
11644 Assoc : constant Node_Id := Arg1;
11650 Check_No_Identifiers;
11651 Check_Arg_Count (1);
11652 Check_Arg_Is_Local_Name (Arg1);
11654 Type_Id := Get_Pragma_Arg (Assoc);
11655 Find_Type (Type_Id);
11656 Typ := Entity (Type_Id);
11658 if Typ = Any_Type then
11661 Typ := Underlying_Type (Typ);
11664 if not Is_Enumeration_Type (Typ) then
11665 Error_Pragma ("pragma% must specify enumeration type");
11668 Check_First_Subtype (Arg1);
11669 Set_Has_Pragma_Ordered (Base_Type (Typ));
11676 -- pragma Pack (first_subtype_LOCAL_NAME);
11678 when Pragma_Pack => Pack : declare
11679 Assoc : constant Node_Id := Arg1;
11683 Ignore : Boolean := False;
11686 Check_No_Identifiers;
11687 Check_Arg_Count (1);
11688 Check_Arg_Is_Local_Name (Arg1);
11690 Type_Id := Get_Pragma_Arg (Assoc);
11691 Find_Type (Type_Id);
11692 Typ := Entity (Type_Id);
11695 or else Rep_Item_Too_Early (Typ, N)
11699 Typ := Underlying_Type (Typ);
11702 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11703 Error_Pragma ("pragma% must specify array or record type");
11706 Check_First_Subtype (Arg1);
11707 Check_Duplicate_Pragma (Typ);
11711 if Is_Array_Type (Typ) then
11712 Ctyp := Component_Type (Typ);
11714 -- Ignore pack that does nothing
11716 if Known_Static_Esize (Ctyp)
11717 and then Known_Static_RM_Size (Ctyp)
11718 and then Esize (Ctyp) = RM_Size (Ctyp)
11719 and then Addressable (Esize (Ctyp))
11724 -- Process OK pragma Pack. Note that if there is a separate
11725 -- component clause present, the Pack will be cancelled. This
11726 -- processing is in Freeze.
11728 if not Rep_Item_Too_Late (Typ, N) then
11730 -- In the context of static code analysis, we do not need
11731 -- complex front-end expansions related to pragma Pack,
11732 -- so disable handling of pragma Pack in these cases.
11734 if CodePeer_Mode or Alfa_Mode then
11737 -- Don't attempt any packing for VM targets. We possibly
11738 -- could deal with some cases of array bit-packing, but we
11739 -- don't bother, since this is not a typical kind of
11740 -- representation in the VM context anyway (and would not
11741 -- for example work nicely with the debugger).
11743 elsif VM_Target /= No_VM then
11744 if not GNAT_Mode then
11746 ("?pragma% ignored in this configuration");
11749 -- Normal case where we do the pack action
11753 Set_Is_Packed (Base_Type (Typ));
11754 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11757 Set_Has_Pragma_Pack (Base_Type (Typ));
11761 -- For record types, the pack is always effective
11763 else pragma Assert (Is_Record_Type (Typ));
11764 if not Rep_Item_Too_Late (Typ, N) then
11766 -- Ignore pack request with warning in VM mode (skip warning
11767 -- if we are compiling GNAT run time library).
11769 if VM_Target /= No_VM then
11770 if not GNAT_Mode then
11772 ("?pragma% ignored in this configuration");
11775 -- Normal case of pack request active
11778 Set_Is_Packed (Base_Type (Typ));
11779 Set_Has_Pragma_Pack (Base_Type (Typ));
11780 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11792 -- There is nothing to do here, since we did all the processing for
11793 -- this pragma in Par.Prag (so that it works properly even in syntax
11796 when Pragma_Page =>
11803 -- pragma Passive [(PASSIVE_FORM)];
11805 -- PASSIVE_FORM ::= Semaphore | No
11807 when Pragma_Passive =>
11810 if Nkind (Parent (N)) /= N_Task_Definition then
11811 Error_Pragma ("pragma% must be within task definition");
11814 if Arg_Count /= 0 then
11815 Check_Arg_Count (1);
11816 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11819 ----------------------------------
11820 -- Preelaborable_Initialization --
11821 ----------------------------------
11823 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11825 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11830 Check_Arg_Count (1);
11831 Check_No_Identifiers;
11832 Check_Arg_Is_Identifier (Arg1);
11833 Check_Arg_Is_Local_Name (Arg1);
11834 Check_First_Subtype (Arg1);
11835 Ent := Entity (Get_Pragma_Arg (Arg1));
11837 if not (Is_Private_Type (Ent)
11839 Is_Protected_Type (Ent)
11841 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11844 ("pragma % can only be applied to private, formal derived or "
11845 & "protected type",
11849 -- Give an error if the pragma is applied to a protected type that
11850 -- does not qualify (due to having entries, or due to components
11851 -- that do not qualify).
11853 if Is_Protected_Type (Ent)
11854 and then not Has_Preelaborable_Initialization (Ent)
11857 ("protected type & does not have preelaborable " &
11858 "initialization", Ent);
11860 -- Otherwise mark the type as definitely having preelaborable
11864 Set_Known_To_Have_Preelab_Init (Ent);
11867 if Has_Pragma_Preelab_Init (Ent)
11868 and then Warn_On_Redundant_Constructs
11870 Error_Pragma ("?duplicate pragma%!");
11872 Set_Has_Pragma_Preelab_Init (Ent);
11876 --------------------
11877 -- Persistent_BSS --
11878 --------------------
11880 -- pragma Persistent_BSS [(object_NAME)];
11882 when Pragma_Persistent_BSS => Persistent_BSS : declare
11889 Check_At_Most_N_Arguments (1);
11891 -- Case of application to specific object (one argument)
11893 if Arg_Count = 1 then
11894 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11896 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11898 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11901 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11904 Ent := Entity (Get_Pragma_Arg (Arg1));
11905 Decl := Parent (Ent);
11907 if Rep_Item_Too_Late (Ent, N) then
11911 if Present (Expression (Decl)) then
11913 ("object for pragma% cannot have initialization", Arg1);
11916 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11918 ("object type for pragma% is not potentially persistent",
11922 Check_Duplicate_Pragma (Ent);
11925 Make_Linker_Section_Pragma
11926 (Ent, Sloc (N), ".persistent.bss");
11927 Insert_After (N, Prag);
11930 -- Case of use as configuration pragma with no arguments
11933 Check_Valid_Configuration_Pragma;
11934 Persistent_BSS_Mode := True;
11936 end Persistent_BSS;
11942 -- pragma Polling (ON | OFF);
11944 when Pragma_Polling =>
11946 Check_Arg_Count (1);
11947 Check_No_Identifiers;
11948 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11949 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11951 -------------------
11952 -- Postcondition --
11953 -------------------
11955 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
11956 -- [,[Message =>] String_EXPRESSION]);
11958 when Pragma_Postcondition => Postcondition : declare
11960 pragma Warnings (Off, In_Body);
11964 Check_At_Least_N_Arguments (1);
11965 Check_At_Most_N_Arguments (2);
11966 Check_Optional_Identifier (Arg1, Name_Check);
11968 -- All we need to do here is call the common check procedure,
11969 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11971 Check_Precondition_Postcondition (In_Body);
11978 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
11979 -- [,[Message =>] String_EXPRESSION]);
11981 when Pragma_Precondition => Precondition : declare
11986 Check_At_Least_N_Arguments (1);
11987 Check_At_Most_N_Arguments (2);
11988 Check_Optional_Identifier (Arg1, Name_Check);
11989 Check_Precondition_Postcondition (In_Body);
11991 -- If in spec, nothing more to do. If in body, then we convert the
11992 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11993 -- this whether or not precondition checks are enabled. That works
11994 -- fine since pragma Check will do this check, and will also
11995 -- analyze the condition itself in the proper context.
12000 Chars => Name_Check,
12001 Pragma_Argument_Associations => New_List (
12002 Make_Pragma_Argument_Association (Loc,
12003 Expression => Make_Identifier (Loc, Name_Precondition)),
12005 Make_Pragma_Argument_Association (Sloc (Arg1),
12006 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
12008 if Arg_Count = 2 then
12009 Append_To (Pragma_Argument_Associations (N),
12010 Make_Pragma_Argument_Association (Sloc (Arg2),
12011 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
12022 -- pragma Predicate
12023 -- ([Entity =>] type_LOCAL_NAME,
12024 -- [Check =>] EXPRESSION);
12026 when Pragma_Predicate => Predicate : declare
12031 pragma Unreferenced (Discard);
12035 Check_Arg_Count (2);
12036 Check_Optional_Identifier (Arg1, Name_Entity);
12037 Check_Optional_Identifier (Arg2, Name_Check);
12039 Check_Arg_Is_Local_Name (Arg1);
12041 Type_Id := Get_Pragma_Arg (Arg1);
12042 Find_Type (Type_Id);
12043 Typ := Entity (Type_Id);
12045 if Typ = Any_Type then
12049 -- The remaining processing is simply to link the pragma on to
12050 -- the rep item chain, for processing when the type is frozen.
12051 -- This is accomplished by a call to Rep_Item_Too_Late. We also
12052 -- mark the type as having predicates.
12054 Set_Has_Predicates (Typ);
12055 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12062 -- pragma Preelaborate [(library_unit_NAME)];
12064 -- Set the flag Is_Preelaborated of program unit name entity
12066 when Pragma_Preelaborate => Preelaborate : declare
12067 Pa : constant Node_Id := Parent (N);
12068 Pk : constant Node_Kind := Nkind (Pa);
12072 Check_Ada_83_Warning;
12073 Check_Valid_Library_Unit_Pragma;
12075 if Nkind (N) = N_Null_Statement then
12079 Ent := Find_Lib_Unit_Name;
12080 Check_Duplicate_Pragma (Ent);
12082 -- This filters out pragmas inside generic parent then
12083 -- show up inside instantiation
12086 and then not (Pk = N_Package_Specification
12087 and then Present (Generic_Parent (Pa)))
12089 if not Debug_Flag_U then
12090 Set_Is_Preelaborated (Ent);
12091 Set_Suppress_Elaboration_Warnings (Ent);
12096 ---------------------
12097 -- Preelaborate_05 --
12098 ---------------------
12100 -- pragma Preelaborate_05 [(library_unit_NAME)];
12102 -- This pragma is useable only in GNAT_Mode, where it is used like
12103 -- pragma Preelaborate but it is only effective in Ada 2005 mode
12104 -- (otherwise it is ignored). This is used to implement AI-362 which
12105 -- recategorizes some run-time packages in Ada 2005 mode.
12107 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
12112 Check_Valid_Library_Unit_Pragma;
12114 if not GNAT_Mode then
12115 Error_Pragma ("pragma% only available in GNAT mode");
12118 if Nkind (N) = N_Null_Statement then
12122 -- This is one of the few cases where we need to test the value of
12123 -- Ada_Version_Explicit rather than Ada_Version (which is always
12124 -- set to Ada_2012 in a predefined unit), we need to know the
12125 -- explicit version set to know if this pragma is active.
12127 if Ada_Version_Explicit >= Ada_2005 then
12128 Ent := Find_Lib_Unit_Name;
12129 Set_Is_Preelaborated (Ent);
12130 Set_Suppress_Elaboration_Warnings (Ent);
12132 end Preelaborate_05;
12138 -- pragma Priority (EXPRESSION);
12140 when Pragma_Priority => Priority : declare
12141 P : constant Node_Id := Parent (N);
12145 Check_No_Identifiers;
12146 Check_Arg_Count (1);
12150 if Nkind (P) = N_Subprogram_Body then
12151 Check_In_Main_Program;
12153 Arg := Get_Pragma_Arg (Arg1);
12154 Analyze_And_Resolve (Arg, Standard_Integer);
12158 if not Is_Static_Expression (Arg) then
12159 Flag_Non_Static_Expr
12160 ("main subprogram priority is not static!", Arg);
12163 -- If constraint error, then we already signalled an error
12165 elsif Raises_Constraint_Error (Arg) then
12168 -- Otherwise check in range
12172 Val : constant Uint := Expr_Value (Arg);
12176 or else Val > Expr_Value (Expression
12177 (Parent (RTE (RE_Max_Priority))))
12180 ("main subprogram priority is out of range", Arg1);
12186 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12188 -- Load an arbitrary entity from System.Tasking to make sure
12189 -- this package is implicitly with'ed, since we need to have
12190 -- the tasking run-time active for the pragma Priority to have
12194 Discard : Entity_Id;
12195 pragma Warnings (Off, Discard);
12197 Discard := RTE (RE_Task_List);
12200 -- Task or Protected, must be of type Integer
12202 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12203 Arg := Get_Pragma_Arg (Arg1);
12205 -- The expression must be analyzed in the special manner
12206 -- described in "Handling of Default and Per-Object
12207 -- Expressions" in sem.ads.
12209 Preanalyze_Spec_Expression (Arg, Standard_Integer);
12211 if not Is_Static_Expression (Arg) then
12212 Check_Restriction (Static_Priorities, Arg);
12215 -- Anything else is incorrect
12221 if Has_Pragma_Priority (P) then
12222 Error_Pragma ("duplicate pragma% not allowed");
12224 Set_Has_Pragma_Priority (P, True);
12226 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12227 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12228 -- exp_ch9 should use this ???
12233 -----------------------------------
12234 -- Priority_Specific_Dispatching --
12235 -----------------------------------
12237 -- pragma Priority_Specific_Dispatching (
12238 -- policy_IDENTIFIER,
12239 -- first_priority_EXPRESSION,
12240 -- last_priority_EXPRESSION);
12242 when Pragma_Priority_Specific_Dispatching =>
12243 Priority_Specific_Dispatching : declare
12244 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12245 -- This is the entity System.Any_Priority;
12248 Lower_Bound : Node_Id;
12249 Upper_Bound : Node_Id;
12255 Check_Arg_Count (3);
12256 Check_No_Identifiers;
12257 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12258 Check_Valid_Configuration_Pragma;
12259 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12260 DP := Fold_Upper (Name_Buffer (1));
12262 Lower_Bound := Get_Pragma_Arg (Arg2);
12263 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12264 Lower_Val := Expr_Value (Lower_Bound);
12266 Upper_Bound := Get_Pragma_Arg (Arg3);
12267 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12268 Upper_Val := Expr_Value (Upper_Bound);
12270 -- It is not allowed to use Task_Dispatching_Policy and
12271 -- Priority_Specific_Dispatching in the same partition.
12273 if Task_Dispatching_Policy /= ' ' then
12274 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12276 ("pragma% incompatible with Task_Dispatching_Policy#");
12278 -- Check lower bound in range
12280 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12282 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12285 ("first_priority is out of range", Arg2);
12287 -- Check upper bound in range
12289 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12291 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12294 ("last_priority is out of range", Arg3);
12296 -- Check that the priority range is valid
12298 elsif Lower_Val > Upper_Val then
12300 ("last_priority_expression must be greater than" &
12301 " or equal to first_priority_expression");
12303 -- Store the new policy, but always preserve System_Location since
12304 -- we like the error message with the run-time name.
12307 -- Check overlapping in the priority ranges specified in other
12308 -- Priority_Specific_Dispatching pragmas within the same
12309 -- partition. We can only check those we know about!
12312 Specific_Dispatching.First .. Specific_Dispatching.Last
12314 if Specific_Dispatching.Table (J).First_Priority in
12315 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12316 or else Specific_Dispatching.Table (J).Last_Priority in
12317 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12320 Specific_Dispatching.Table (J).Pragma_Loc;
12322 ("priority range overlaps with "
12323 & "Priority_Specific_Dispatching#");
12327 -- The use of Priority_Specific_Dispatching is incompatible
12328 -- with Task_Dispatching_Policy.
12330 if Task_Dispatching_Policy /= ' ' then
12331 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12333 ("Priority_Specific_Dispatching incompatible "
12334 & "with Task_Dispatching_Policy#");
12337 -- The use of Priority_Specific_Dispatching forces ceiling
12340 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12341 Error_Msg_Sloc := Locking_Policy_Sloc;
12343 ("Priority_Specific_Dispatching incompatible "
12344 & "with Locking_Policy#");
12346 -- Set the Ceiling_Locking policy, but preserve System_Location
12347 -- since we like the error message with the run time name.
12350 Locking_Policy := 'C';
12352 if Locking_Policy_Sloc /= System_Location then
12353 Locking_Policy_Sloc := Loc;
12357 -- Add entry in the table
12359 Specific_Dispatching.Append
12360 ((Dispatching_Policy => DP,
12361 First_Priority => UI_To_Int (Lower_Val),
12362 Last_Priority => UI_To_Int (Upper_Val),
12363 Pragma_Loc => Loc));
12365 end Priority_Specific_Dispatching;
12371 -- pragma Profile (profile_IDENTIFIER);
12373 -- profile_IDENTIFIER => Restricted | Ravenscar
12375 when Pragma_Profile =>
12377 Check_Arg_Count (1);
12378 Check_Valid_Configuration_Pragma;
12379 Check_No_Identifiers;
12382 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12385 if Chars (Argx) = Name_Ravenscar then
12386 Set_Ravenscar_Profile (N);
12388 elsif Chars (Argx) = Name_Restricted then
12389 Set_Profile_Restrictions
12391 N, Warn => Treat_Restrictions_As_Warnings);
12393 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12394 Set_Profile_Restrictions
12395 (No_Implementation_Extensions,
12396 N, Warn => Treat_Restrictions_As_Warnings);
12399 Error_Pragma_Arg ("& is not a valid profile", Argx);
12403 ----------------------
12404 -- Profile_Warnings --
12405 ----------------------
12407 -- pragma Profile_Warnings (profile_IDENTIFIER);
12409 -- profile_IDENTIFIER => Restricted | Ravenscar
12411 when Pragma_Profile_Warnings =>
12413 Check_Arg_Count (1);
12414 Check_Valid_Configuration_Pragma;
12415 Check_No_Identifiers;
12418 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12421 if Chars (Argx) = Name_Ravenscar then
12422 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12424 elsif Chars (Argx) = Name_Restricted then
12425 Set_Profile_Restrictions (Restricted, N, Warn => True);
12427 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12428 Set_Profile_Restrictions
12429 (No_Implementation_Extensions, N, Warn => True);
12432 Error_Pragma_Arg ("& is not a valid profile", Argx);
12436 --------------------------
12437 -- Propagate_Exceptions --
12438 --------------------------
12440 -- pragma Propagate_Exceptions;
12442 -- Note: this pragma is obsolete and has no effect
12444 when Pragma_Propagate_Exceptions =>
12446 Check_Arg_Count (0);
12448 if In_Extended_Main_Source_Unit (N) then
12449 Propagate_Exceptions := True;
12456 -- pragma Psect_Object (
12457 -- [Internal =>] LOCAL_NAME,
12458 -- [, [External =>] EXTERNAL_SYMBOL]
12459 -- [, [Size =>] EXTERNAL_SYMBOL]);
12461 when Pragma_Psect_Object | Pragma_Common_Object =>
12462 Psect_Object : declare
12463 Args : Args_List (1 .. 3);
12464 Names : constant Name_List (1 .. 3) := (
12469 Internal : Node_Id renames Args (1);
12470 External : Node_Id renames Args (2);
12471 Size : Node_Id renames Args (3);
12473 Def_Id : Entity_Id;
12475 procedure Check_Too_Long (Arg : Node_Id);
12476 -- Posts message if the argument is an identifier with more
12477 -- than 31 characters, or a string literal with more than
12478 -- 31 characters, and we are operating under VMS
12480 --------------------
12481 -- Check_Too_Long --
12482 --------------------
12484 procedure Check_Too_Long (Arg : Node_Id) is
12485 X : constant Node_Id := Original_Node (Arg);
12488 if not Nkind_In (X, N_String_Literal, N_Identifier) then
12490 ("inappropriate argument for pragma %", Arg);
12493 if OpenVMS_On_Target then
12494 if (Nkind (X) = N_String_Literal
12495 and then String_Length (Strval (X)) > 31)
12497 (Nkind (X) = N_Identifier
12498 and then Length_Of_Name (Chars (X)) > 31)
12501 ("argument for pragma % is longer than 31 characters",
12505 end Check_Too_Long;
12507 -- Start of processing for Common_Object/Psect_Object
12511 Gather_Associations (Names, Args);
12512 Process_Extended_Import_Export_Internal_Arg (Internal);
12514 Def_Id := Entity (Internal);
12516 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12518 ("pragma% must designate an object", Internal);
12521 Check_Too_Long (Internal);
12523 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12525 ("cannot use pragma% for imported/exported object",
12529 if Is_Concurrent_Type (Etype (Internal)) then
12531 ("cannot specify pragma % for task/protected object",
12535 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12537 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12539 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12542 if Ekind (Def_Id) = E_Constant then
12544 ("cannot specify pragma % for a constant", Internal);
12547 if Is_Record_Type (Etype (Internal)) then
12553 Ent := First_Entity (Etype (Internal));
12554 while Present (Ent) loop
12555 Decl := Declaration_Node (Ent);
12557 if Ekind (Ent) = E_Component
12558 and then Nkind (Decl) = N_Component_Declaration
12559 and then Present (Expression (Decl))
12560 and then Warn_On_Export_Import
12563 ("?object for pragma % has defaults", Internal);
12573 if Present (Size) then
12574 Check_Too_Long (Size);
12577 if Present (External) then
12578 Check_Arg_Is_External_Name (External);
12579 Check_Too_Long (External);
12582 -- If all error tests pass, link pragma on to the rep item chain
12584 Record_Rep_Item (Def_Id, N);
12591 -- pragma Pure [(library_unit_NAME)];
12593 when Pragma_Pure => Pure : declare
12597 Check_Ada_83_Warning;
12598 Check_Valid_Library_Unit_Pragma;
12600 if Nkind (N) = N_Null_Statement then
12604 Ent := Find_Lib_Unit_Name;
12606 Set_Has_Pragma_Pure (Ent);
12607 Set_Suppress_Elaboration_Warnings (Ent);
12614 -- pragma Pure_05 [(library_unit_NAME)];
12616 -- This pragma is useable only in GNAT_Mode, where it is used like
12617 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
12618 -- it is ignored). It may be used after a pragma Preelaborate, in
12619 -- which case it overrides the effect of the pragma Preelaborate.
12620 -- This is used to implement AI-362 which recategorizes some run-time
12621 -- packages in Ada 2005 mode.
12623 when Pragma_Pure_05 => Pure_05 : declare
12628 Check_Valid_Library_Unit_Pragma;
12630 if not GNAT_Mode then
12631 Error_Pragma ("pragma% only available in GNAT mode");
12634 if Nkind (N) = N_Null_Statement then
12638 -- This is one of the few cases where we need to test the value of
12639 -- Ada_Version_Explicit rather than Ada_Version (which is always
12640 -- set to Ada_2012 in a predefined unit), we need to know the
12641 -- explicit version set to know if this pragma is active.
12643 if Ada_Version_Explicit >= Ada_2005 then
12644 Ent := Find_Lib_Unit_Name;
12645 Set_Is_Preelaborated (Ent, False);
12647 Set_Suppress_Elaboration_Warnings (Ent);
12655 -- pragma Pure_12 [(library_unit_NAME)];
12657 -- This pragma is useable only in GNAT_Mode, where it is used like
12658 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
12659 -- it is ignored). It may be used after a pragma Preelaborate, in
12660 -- which case it overrides the effect of the pragma Preelaborate.
12661 -- This is used to implement AI05-0212 which recategorizes some
12662 -- run-time packages in Ada 2012 mode.
12664 when Pragma_Pure_12 => Pure_12 : declare
12669 Check_Valid_Library_Unit_Pragma;
12671 if not GNAT_Mode then
12672 Error_Pragma ("pragma% only available in GNAT mode");
12675 if Nkind (N) = N_Null_Statement then
12679 -- This is one of the few cases where we need to test the value of
12680 -- Ada_Version_Explicit rather than Ada_Version (which is always
12681 -- set to Ada_2012 in a predefined unit), we need to know the
12682 -- explicit version set to know if this pragma is active.
12684 if Ada_Version_Explicit >= Ada_2012 then
12685 Ent := Find_Lib_Unit_Name;
12686 Set_Is_Preelaborated (Ent, False);
12688 Set_Suppress_Elaboration_Warnings (Ent);
12692 -------------------
12693 -- Pure_Function --
12694 -------------------
12696 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12698 when Pragma_Pure_Function => Pure_Function : declare
12701 Def_Id : Entity_Id;
12702 Effective : Boolean := False;
12706 Check_Arg_Count (1);
12707 Check_Optional_Identifier (Arg1, Name_Entity);
12708 Check_Arg_Is_Local_Name (Arg1);
12709 E_Id := Get_Pragma_Arg (Arg1);
12711 if Error_Posted (E_Id) then
12715 -- Loop through homonyms (overloadings) of referenced entity
12717 E := Entity (E_Id);
12719 if Present (E) then
12721 Def_Id := Get_Base_Subprogram (E);
12723 if not Ekind_In (Def_Id, E_Function,
12724 E_Generic_Function,
12728 ("pragma% requires a function name", Arg1);
12731 Set_Is_Pure (Def_Id);
12733 if not Has_Pragma_Pure_Function (Def_Id) then
12734 Set_Has_Pragma_Pure_Function (Def_Id);
12738 exit when From_Aspect_Specification (N);
12740 exit when No (E) or else Scope (E) /= Current_Scope;
12744 and then Warn_On_Redundant_Constructs
12747 ("pragma Pure_Function on& is redundant?",
12753 --------------------
12754 -- Queuing_Policy --
12755 --------------------
12757 -- pragma Queuing_Policy (policy_IDENTIFIER);
12759 when Pragma_Queuing_Policy => declare
12763 Check_Ada_83_Warning;
12764 Check_Arg_Count (1);
12765 Check_No_Identifiers;
12766 Check_Arg_Is_Queuing_Policy (Arg1);
12767 Check_Valid_Configuration_Pragma;
12768 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12769 QP := Fold_Upper (Name_Buffer (1));
12771 if Queuing_Policy /= ' '
12772 and then Queuing_Policy /= QP
12774 Error_Msg_Sloc := Queuing_Policy_Sloc;
12775 Error_Pragma ("queuing policy incompatible with policy#");
12777 -- Set new policy, but always preserve System_Location since we
12778 -- like the error message with the run time name.
12781 Queuing_Policy := QP;
12783 if Queuing_Policy_Sloc /= System_Location then
12784 Queuing_Policy_Sloc := Loc;
12789 -----------------------
12790 -- Relative_Deadline --
12791 -----------------------
12793 -- pragma Relative_Deadline (time_span_EXPRESSION);
12795 when Pragma_Relative_Deadline => Relative_Deadline : declare
12796 P : constant Node_Id := Parent (N);
12801 Check_No_Identifiers;
12802 Check_Arg_Count (1);
12804 Arg := Get_Pragma_Arg (Arg1);
12806 -- The expression must be analyzed in the special manner described
12807 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12809 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12813 if Nkind (P) = N_Subprogram_Body then
12814 Check_In_Main_Program;
12818 elsif Nkind (P) = N_Task_Definition then
12821 -- Anything else is incorrect
12827 if Has_Relative_Deadline_Pragma (P) then
12828 Error_Pragma ("duplicate pragma% not allowed");
12830 Set_Has_Relative_Deadline_Pragma (P, True);
12832 if Nkind (P) = N_Task_Definition then
12833 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12836 end Relative_Deadline;
12838 ---------------------------
12839 -- Remote_Call_Interface --
12840 ---------------------------
12842 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12844 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12845 Cunit_Node : Node_Id;
12846 Cunit_Ent : Entity_Id;
12850 Check_Ada_83_Warning;
12851 Check_Valid_Library_Unit_Pragma;
12853 if Nkind (N) = N_Null_Statement then
12857 Cunit_Node := Cunit (Current_Sem_Unit);
12858 K := Nkind (Unit (Cunit_Node));
12859 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12861 if K = N_Package_Declaration
12862 or else K = N_Generic_Package_Declaration
12863 or else K = N_Subprogram_Declaration
12864 or else K = N_Generic_Subprogram_Declaration
12865 or else (K = N_Subprogram_Body
12866 and then Acts_As_Spec (Unit (Cunit_Node)))
12871 "pragma% must apply to package or subprogram declaration");
12874 Set_Is_Remote_Call_Interface (Cunit_Ent);
12875 end Remote_Call_Interface;
12881 -- pragma Remote_Types [(library_unit_NAME)];
12883 when Pragma_Remote_Types => Remote_Types : declare
12884 Cunit_Node : Node_Id;
12885 Cunit_Ent : Entity_Id;
12888 Check_Ada_83_Warning;
12889 Check_Valid_Library_Unit_Pragma;
12891 if Nkind (N) = N_Null_Statement then
12895 Cunit_Node := Cunit (Current_Sem_Unit);
12896 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12898 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12899 N_Generic_Package_Declaration)
12902 ("pragma% can only apply to a package declaration");
12905 Set_Is_Remote_Types (Cunit_Ent);
12912 -- pragma Ravenscar;
12914 when Pragma_Ravenscar =>
12916 Check_Arg_Count (0);
12917 Check_Valid_Configuration_Pragma;
12918 Set_Ravenscar_Profile (N);
12920 if Warn_On_Obsolescent_Feature then
12921 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12922 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12925 -------------------------
12926 -- Restricted_Run_Time --
12927 -------------------------
12929 -- pragma Restricted_Run_Time;
12931 when Pragma_Restricted_Run_Time =>
12933 Check_Arg_Count (0);
12934 Check_Valid_Configuration_Pragma;
12935 Set_Profile_Restrictions
12936 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12938 if Warn_On_Obsolescent_Feature then
12940 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12941 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12948 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12951 -- restriction_IDENTIFIER
12952 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12954 when Pragma_Restrictions =>
12955 Process_Restrictions_Or_Restriction_Warnings
12956 (Warn => Treat_Restrictions_As_Warnings);
12958 --------------------------
12959 -- Restriction_Warnings --
12960 --------------------------
12962 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12965 -- restriction_IDENTIFIER
12966 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12968 when Pragma_Restriction_Warnings =>
12970 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12976 -- pragma Reviewable;
12978 when Pragma_Reviewable =>
12979 Check_Ada_83_Warning;
12980 Check_Arg_Count (0);
12982 -- Call dummy debugging function rv. This is done to assist front
12983 -- end debugging. By placing a Reviewable pragma in the source
12984 -- program, a breakpoint on rv catches this place in the source,
12985 -- allowing convenient stepping to the point of interest.
12989 --------------------------
12990 -- Short_Circuit_And_Or --
12991 --------------------------
12993 when Pragma_Short_Circuit_And_Or =>
12995 Check_Arg_Count (0);
12996 Check_Valid_Configuration_Pragma;
12997 Short_Circuit_And_Or := True;
12999 -------------------
13000 -- Share_Generic --
13001 -------------------
13003 -- pragma Share_Generic (NAME {, NAME});
13005 when Pragma_Share_Generic =>
13007 Process_Generic_List;
13013 -- pragma Shared (LOCAL_NAME);
13015 when Pragma_Shared =>
13017 Process_Atomic_Shared_Volatile;
13019 --------------------
13020 -- Shared_Passive --
13021 --------------------
13023 -- pragma Shared_Passive [(library_unit_NAME)];
13025 -- Set the flag Is_Shared_Passive of program unit name entity
13027 when Pragma_Shared_Passive => Shared_Passive : declare
13028 Cunit_Node : Node_Id;
13029 Cunit_Ent : Entity_Id;
13032 Check_Ada_83_Warning;
13033 Check_Valid_Library_Unit_Pragma;
13035 if Nkind (N) = N_Null_Statement then
13039 Cunit_Node := Cunit (Current_Sem_Unit);
13040 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13042 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13043 N_Generic_Package_Declaration)
13046 ("pragma% can only apply to a package declaration");
13049 Set_Is_Shared_Passive (Cunit_Ent);
13050 end Shared_Passive;
13052 -----------------------
13053 -- Short_Descriptors --
13054 -----------------------
13056 -- pragma Short_Descriptors;
13058 when Pragma_Short_Descriptors =>
13060 Check_Arg_Count (0);
13061 Check_Valid_Configuration_Pragma;
13062 Short_Descriptors := True;
13064 ----------------------
13065 -- Source_File_Name --
13066 ----------------------
13068 -- There are five forms for this pragma:
13070 -- pragma Source_File_Name (
13071 -- [UNIT_NAME =>] unit_NAME,
13072 -- BODY_FILE_NAME => STRING_LITERAL
13073 -- [, [INDEX =>] INTEGER_LITERAL]);
13075 -- pragma Source_File_Name (
13076 -- [UNIT_NAME =>] unit_NAME,
13077 -- SPEC_FILE_NAME => STRING_LITERAL
13078 -- [, [INDEX =>] INTEGER_LITERAL]);
13080 -- pragma Source_File_Name (
13081 -- BODY_FILE_NAME => STRING_LITERAL
13082 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13083 -- [, CASING => CASING_SPEC]);
13085 -- pragma Source_File_Name (
13086 -- SPEC_FILE_NAME => STRING_LITERAL
13087 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13088 -- [, CASING => CASING_SPEC]);
13090 -- pragma Source_File_Name (
13091 -- SUBUNIT_FILE_NAME => STRING_LITERAL
13092 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13093 -- [, CASING => CASING_SPEC]);
13095 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
13097 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
13098 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
13099 -- only be used when no project file is used, while SFNP can only be
13100 -- used when a project file is used.
13102 -- No processing here. Processing was completed during parsing, since
13103 -- we need to have file names set as early as possible. Units are
13104 -- loaded well before semantic processing starts.
13106 -- The only processing we defer to this point is the check for
13107 -- correct placement.
13109 when Pragma_Source_File_Name =>
13111 Check_Valid_Configuration_Pragma;
13113 ------------------------------
13114 -- Source_File_Name_Project --
13115 ------------------------------
13117 -- See Source_File_Name for syntax
13119 -- No processing here. Processing was completed during parsing, since
13120 -- we need to have file names set as early as possible. Units are
13121 -- loaded well before semantic processing starts.
13123 -- The only processing we defer to this point is the check for
13124 -- correct placement.
13126 when Pragma_Source_File_Name_Project =>
13128 Check_Valid_Configuration_Pragma;
13130 -- Check that a pragma Source_File_Name_Project is used only in a
13131 -- configuration pragmas file.
13133 -- Pragmas Source_File_Name_Project should only be generated by
13134 -- the Project Manager in configuration pragmas files.
13136 -- This is really an ugly test. It seems to depend on some
13137 -- accidental and undocumented property. At the very least it
13138 -- needs to be documented, but it would be better to have a
13139 -- clean way of testing if we are in a configuration file???
13141 if Present (Parent (N)) then
13143 ("pragma% can only appear in a configuration pragmas file");
13146 ----------------------
13147 -- Source_Reference --
13148 ----------------------
13150 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
13152 -- Nothing to do, all processing completed in Par.Prag, since we need
13153 -- the information for possible parser messages that are output.
13155 when Pragma_Source_Reference =>
13158 --------------------------------
13159 -- Static_Elaboration_Desired --
13160 --------------------------------
13162 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
13164 when Pragma_Static_Elaboration_Desired =>
13166 Check_At_Most_N_Arguments (1);
13168 if Is_Compilation_Unit (Current_Scope)
13169 and then Ekind (Current_Scope) = E_Package
13171 Set_Static_Elaboration_Desired (Current_Scope, True);
13173 Error_Pragma ("pragma% must apply to a library-level package");
13180 -- pragma Storage_Size (EXPRESSION);
13182 when Pragma_Storage_Size => Storage_Size : declare
13183 P : constant Node_Id := Parent (N);
13187 Check_No_Identifiers;
13188 Check_Arg_Count (1);
13190 -- The expression must be analyzed in the special manner described
13191 -- in "Handling of Default Expressions" in sem.ads.
13193 Arg := Get_Pragma_Arg (Arg1);
13194 Preanalyze_Spec_Expression (Arg, Any_Integer);
13196 if not Is_Static_Expression (Arg) then
13197 Check_Restriction (Static_Storage_Size, Arg);
13200 if Nkind (P) /= N_Task_Definition then
13205 if Has_Storage_Size_Pragma (P) then
13206 Error_Pragma ("duplicate pragma% not allowed");
13208 Set_Has_Storage_Size_Pragma (P, True);
13211 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13212 -- ??? exp_ch9 should use this!
13220 -- pragma Storage_Unit (NUMERIC_LITERAL);
13222 -- Only permitted argument is System'Storage_Unit value
13224 when Pragma_Storage_Unit =>
13225 Check_No_Identifiers;
13226 Check_Arg_Count (1);
13227 Check_Arg_Is_Integer_Literal (Arg1);
13229 if Intval (Get_Pragma_Arg (Arg1)) /=
13230 UI_From_Int (Ttypes.System_Storage_Unit)
13232 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
13234 ("the only allowed argument for pragma% is ^", Arg1);
13237 --------------------
13238 -- Stream_Convert --
13239 --------------------
13241 -- pragma Stream_Convert (
13242 -- [Entity =>] type_LOCAL_NAME,
13243 -- [Read =>] function_NAME,
13244 -- [Write =>] function NAME);
13246 when Pragma_Stream_Convert => Stream_Convert : declare
13248 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
13249 -- Check that the given argument is the name of a local function
13250 -- of one argument that is not overloaded earlier in the current
13251 -- local scope. A check is also made that the argument is a
13252 -- function with one parameter.
13254 --------------------------------------
13255 -- Check_OK_Stream_Convert_Function --
13256 --------------------------------------
13258 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
13262 Check_Arg_Is_Local_Name (Arg);
13263 Ent := Entity (Get_Pragma_Arg (Arg));
13265 if Has_Homonym (Ent) then
13267 ("argument for pragma% may not be overloaded", Arg);
13270 if Ekind (Ent) /= E_Function
13271 or else No (First_Formal (Ent))
13272 or else Present (Next_Formal (First_Formal (Ent)))
13275 ("argument for pragma% must be" &
13276 " function of one argument", Arg);
13278 end Check_OK_Stream_Convert_Function;
13280 -- Start of processing for Stream_Convert
13284 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
13285 Check_Arg_Count (3);
13286 Check_Optional_Identifier (Arg1, Name_Entity);
13287 Check_Optional_Identifier (Arg2, Name_Read);
13288 Check_Optional_Identifier (Arg3, Name_Write);
13289 Check_Arg_Is_Local_Name (Arg1);
13290 Check_OK_Stream_Convert_Function (Arg2);
13291 Check_OK_Stream_Convert_Function (Arg3);
13294 Typ : constant Entity_Id :=
13295 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13296 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13297 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
13300 Check_First_Subtype (Arg1);
13302 -- Check for too early or too late. Note that we don't enforce
13303 -- the rule about primitive operations in this case, since, as
13304 -- is the case for explicit stream attributes themselves, these
13305 -- restrictions are not appropriate. Note that the chaining of
13306 -- the pragma by Rep_Item_Too_Late is actually the critical
13307 -- processing done for this pragma.
13309 if Rep_Item_Too_Early (Typ, N)
13311 Rep_Item_Too_Late (Typ, N, FOnly => True)
13316 -- Return if previous error
13318 if Etype (Typ) = Any_Type
13320 Etype (Read) = Any_Type
13322 Etype (Write) = Any_Type
13329 if Underlying_Type (Etype (Read)) /= Typ then
13331 ("incorrect return type for function&", Arg2);
13334 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13336 ("incorrect parameter type for function&", Arg3);
13339 if Underlying_Type (Etype (First_Formal (Read))) /=
13340 Underlying_Type (Etype (Write))
13343 ("result type of & does not match Read parameter type",
13347 end Stream_Convert;
13349 -------------------------
13350 -- Style_Checks (GNAT) --
13351 -------------------------
13353 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13355 -- This is processed by the parser since some of the style checks
13356 -- take place during source scanning and parsing. This means that
13357 -- we don't need to issue error messages here.
13359 when Pragma_Style_Checks => Style_Checks : declare
13360 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13366 Check_No_Identifiers;
13368 -- Two argument form
13370 if Arg_Count = 2 then
13371 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13378 E_Id := Get_Pragma_Arg (Arg2);
13381 if not Is_Entity_Name (E_Id) then
13383 ("second argument of pragma% must be entity name",
13387 E := Entity (E_Id);
13393 Set_Suppress_Style_Checks (E,
13394 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
13395 exit when No (Homonym (E));
13401 -- One argument form
13404 Check_Arg_Count (1);
13406 if Nkind (A) = N_String_Literal then
13410 Slen : constant Natural := Natural (String_Length (S));
13411 Options : String (1 .. Slen);
13417 C := Get_String_Char (S, Int (J));
13418 exit when not In_Character_Range (C);
13419 Options (J) := Get_Character (C);
13421 -- If at end of string, set options. As per discussion
13422 -- above, no need to check for errors, since we issued
13423 -- them in the parser.
13426 Set_Style_Check_Options (Options);
13434 elsif Nkind (A) = N_Identifier then
13435 if Chars (A) = Name_All_Checks then
13437 Set_GNAT_Style_Check_Options;
13439 Set_Default_Style_Check_Options;
13442 elsif Chars (A) = Name_On then
13443 Style_Check := True;
13445 elsif Chars (A) = Name_Off then
13446 Style_Check := False;
13456 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13458 when Pragma_Subtitle =>
13460 Check_Arg_Count (1);
13461 Check_Optional_Identifier (Arg1, Name_Subtitle);
13462 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13469 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13471 when Pragma_Suppress =>
13472 Process_Suppress_Unsuppress (True);
13478 -- pragma Suppress_All;
13480 -- The only check made here is that the pragma has no arguments.
13481 -- There are no placement rules, and the processing required (setting
13482 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
13483 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
13484 -- then creates and inserts a pragma Suppress (All_Checks).
13486 when Pragma_Suppress_All =>
13488 Check_Arg_Count (0);
13490 -------------------------
13491 -- Suppress_Debug_Info --
13492 -------------------------
13494 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13496 when Pragma_Suppress_Debug_Info =>
13498 Check_Arg_Count (1);
13499 Check_Optional_Identifier (Arg1, Name_Entity);
13500 Check_Arg_Is_Local_Name (Arg1);
13501 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13503 ----------------------------------
13504 -- Suppress_Exception_Locations --
13505 ----------------------------------
13507 -- pragma Suppress_Exception_Locations;
13509 when Pragma_Suppress_Exception_Locations =>
13511 Check_Arg_Count (0);
13512 Check_Valid_Configuration_Pragma;
13513 Exception_Locations_Suppressed := True;
13515 -----------------------------
13516 -- Suppress_Initialization --
13517 -----------------------------
13519 -- pragma Suppress_Initialization ([Entity =>] type_Name);
13521 when Pragma_Suppress_Initialization => Suppress_Init : declare
13527 Check_Arg_Count (1);
13528 Check_Optional_Identifier (Arg1, Name_Entity);
13529 Check_Arg_Is_Local_Name (Arg1);
13531 E_Id := Get_Pragma_Arg (Arg1);
13533 if Etype (E_Id) = Any_Type then
13537 E := Entity (E_Id);
13539 if not Is_Type (E) then
13540 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13543 if Rep_Item_Too_Early (E, N)
13545 Rep_Item_Too_Late (E, N, FOnly => True)
13550 -- For incomplete/private type, set flag on full view
13552 if Is_Incomplete_Or_Private_Type (E) then
13553 if No (Full_View (Base_Type (E))) then
13555 ("argument of pragma% cannot be an incomplete type", Arg1);
13557 Set_Suppress_Initialization (Full_View (Base_Type (E)));
13560 -- For first subtype, set flag on base type
13562 elsif Is_First_Subtype (E) then
13563 Set_Suppress_Initialization (Base_Type (E));
13565 -- For other than first subtype, set flag on subtype itself
13568 Set_Suppress_Initialization (E);
13576 -- pragma System_Name (DIRECT_NAME);
13578 -- Syntax check: one argument, which must be the identifier GNAT or
13579 -- the identifier GCC, no other identifiers are acceptable.
13581 when Pragma_System_Name =>
13583 Check_No_Identifiers;
13584 Check_Arg_Count (1);
13585 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13587 -----------------------------
13588 -- Task_Dispatching_Policy --
13589 -----------------------------
13591 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13593 when Pragma_Task_Dispatching_Policy => declare
13597 Check_Ada_83_Warning;
13598 Check_Arg_Count (1);
13599 Check_No_Identifiers;
13600 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13601 Check_Valid_Configuration_Pragma;
13602 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13603 DP := Fold_Upper (Name_Buffer (1));
13605 if Task_Dispatching_Policy /= ' '
13606 and then Task_Dispatching_Policy /= DP
13608 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13610 ("task dispatching policy incompatible with policy#");
13612 -- Set new policy, but always preserve System_Location since we
13613 -- like the error message with the run time name.
13616 Task_Dispatching_Policy := DP;
13618 if Task_Dispatching_Policy_Sloc /= System_Location then
13619 Task_Dispatching_Policy_Sloc := Loc;
13628 -- pragma Task_Info (EXPRESSION);
13630 when Pragma_Task_Info => Task_Info : declare
13631 P : constant Node_Id := Parent (N);
13636 if Nkind (P) /= N_Task_Definition then
13637 Error_Pragma ("pragma% must appear in task definition");
13640 Check_No_Identifiers;
13641 Check_Arg_Count (1);
13643 Analyze_And_Resolve
13644 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13646 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13650 if Has_Task_Info_Pragma (P) then
13651 Error_Pragma ("duplicate pragma% not allowed");
13653 Set_Has_Task_Info_Pragma (P, True);
13661 -- pragma Task_Name (string_EXPRESSION);
13663 when Pragma_Task_Name => Task_Name : declare
13664 P : constant Node_Id := Parent (N);
13668 Check_No_Identifiers;
13669 Check_Arg_Count (1);
13671 Arg := Get_Pragma_Arg (Arg1);
13673 -- The expression is used in the call to Create_Task, and must be
13674 -- expanded there, not in the context of the current spec. It must
13675 -- however be analyzed to capture global references, in case it
13676 -- appears in a generic context.
13678 Preanalyze_And_Resolve (Arg, Standard_String);
13680 if Nkind (P) /= N_Task_Definition then
13684 if Has_Task_Name_Pragma (P) then
13685 Error_Pragma ("duplicate pragma% not allowed");
13687 Set_Has_Task_Name_Pragma (P, True);
13688 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13696 -- pragma Task_Storage (
13697 -- [Task_Type =>] LOCAL_NAME,
13698 -- [Top_Guard =>] static_integer_EXPRESSION);
13700 when Pragma_Task_Storage => Task_Storage : declare
13701 Args : Args_List (1 .. 2);
13702 Names : constant Name_List (1 .. 2) := (
13706 Task_Type : Node_Id renames Args (1);
13707 Top_Guard : Node_Id renames Args (2);
13713 Gather_Associations (Names, Args);
13715 if No (Task_Type) then
13717 ("missing task_type argument for pragma%");
13720 Check_Arg_Is_Local_Name (Task_Type);
13722 Ent := Entity (Task_Type);
13724 if not Is_Task_Type (Ent) then
13726 ("argument for pragma% must be task type", Task_Type);
13729 if No (Top_Guard) then
13731 ("pragma% takes two arguments", Task_Type);
13733 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13736 Check_First_Subtype (Task_Type);
13738 if Rep_Item_Too_Late (Ent, N) then
13747 -- pragma Test_Case ([Name =>] Static_String_EXPRESSION
13748 -- ,[Mode =>] MODE_TYPE
13749 -- [, Requires => Boolean_EXPRESSION]
13750 -- [, Ensures => Boolean_EXPRESSION]);
13752 -- MODE_TYPE ::= Nominal | Robustness
13754 when Pragma_Test_Case => Test_Case : declare
13757 Check_At_Least_N_Arguments (2);
13758 Check_At_Most_N_Arguments (4);
13760 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13762 Check_Optional_Identifier (Arg1, Name_Name);
13763 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13765 -- In ASIS mode, for a pragma generated from a source aspect, also
13766 -- analyze the original aspect expression.
13769 and then Present (Corresponding_Aspect (N))
13771 Check_Expr_Is_Static_Expression
13772 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
13775 Check_Optional_Identifier (Arg2, Name_Mode);
13776 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13778 if Arg_Count = 4 then
13779 Check_Identifier (Arg3, Name_Requires);
13780 Check_Identifier (Arg4, Name_Ensures);
13782 elsif Arg_Count = 3 then
13783 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13789 --------------------------
13790 -- Thread_Local_Storage --
13791 --------------------------
13793 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13795 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13801 Check_Arg_Count (1);
13802 Check_Optional_Identifier (Arg1, Name_Entity);
13803 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13805 Id := Get_Pragma_Arg (Arg1);
13808 if not Is_Entity_Name (Id)
13809 or else Ekind (Entity (Id)) /= E_Variable
13811 Error_Pragma_Arg ("local variable name required", Arg1);
13816 if Rep_Item_Too_Early (E, N)
13817 or else Rep_Item_Too_Late (E, N)
13822 Set_Has_Pragma_Thread_Local_Storage (E);
13823 Set_Has_Gigi_Rep_Item (E);
13824 end Thread_Local_Storage;
13830 -- pragma Time_Slice (static_duration_EXPRESSION);
13832 when Pragma_Time_Slice => Time_Slice : declare
13838 Check_Arg_Count (1);
13839 Check_No_Identifiers;
13840 Check_In_Main_Program;
13841 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13843 if not Error_Posted (Arg1) then
13845 while Present (Nod) loop
13846 if Nkind (Nod) = N_Pragma
13847 and then Pragma_Name (Nod) = Name_Time_Slice
13849 Error_Msg_Name_1 := Pname;
13850 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13857 -- Process only if in main unit
13859 if Get_Source_Unit (Loc) = Main_Unit then
13860 Opt.Time_Slice_Set := True;
13861 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13863 if Val <= Ureal_0 then
13864 Opt.Time_Slice_Value := 0;
13866 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13867 Opt.Time_Slice_Value := 1_000_000_000;
13870 Opt.Time_Slice_Value :=
13871 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13880 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13882 -- TITLING_OPTION ::=
13883 -- [Title =>] STRING_LITERAL
13884 -- | [Subtitle =>] STRING_LITERAL
13886 when Pragma_Title => Title : declare
13887 Args : Args_List (1 .. 2);
13888 Names : constant Name_List (1 .. 2) := (
13894 Gather_Associations (Names, Args);
13897 for J in 1 .. 2 loop
13898 if Present (Args (J)) then
13899 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13904 ---------------------
13905 -- Unchecked_Union --
13906 ---------------------
13908 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13910 when Pragma_Unchecked_Union => Unchecked_Union : declare
13911 Assoc : constant Node_Id := Arg1;
13912 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13923 Check_No_Identifiers;
13924 Check_Arg_Count (1);
13925 Check_Arg_Is_Local_Name (Arg1);
13927 Find_Type (Type_Id);
13928 Typ := Entity (Type_Id);
13931 or else Rep_Item_Too_Early (Typ, N)
13935 Typ := Underlying_Type (Typ);
13938 if Rep_Item_Too_Late (Typ, N) then
13942 Check_First_Subtype (Arg1);
13944 -- Note remaining cases are references to a type in the current
13945 -- declarative part. If we find an error, we post the error on
13946 -- the relevant type declaration at an appropriate point.
13948 if not Is_Record_Type (Typ) then
13949 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13952 elsif Is_Tagged_Type (Typ) then
13953 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13956 elsif not Has_Discriminants (Typ) then
13958 ("Unchecked_Union must have one discriminant", Typ);
13961 -- Note: in previous versions of GNAT we used to check for limited
13962 -- types and give an error, but in fact the standard does allow
13963 -- Unchecked_Union on limited types, so this check was removed.
13965 -- Proceed with basic error checks completed
13968 Discr := First_Discriminant (Typ);
13969 while Present (Discr) loop
13970 if No (Discriminant_Default_Value (Discr)) then
13972 ("Unchecked_Union discriminant must have default value",
13976 Next_Discriminant (Discr);
13979 Tdef := Type_Definition (Declaration_Node (Typ));
13980 Clist := Component_List (Tdef);
13982 Comp := First (Component_Items (Clist));
13983 while Present (Comp) loop
13984 Check_Component (Comp, Typ);
13988 if No (Clist) or else No (Variant_Part (Clist)) then
13990 ("Unchecked_Union must have variant part",
13995 Vpart := Variant_Part (Clist);
13997 Variant := First (Variants (Vpart));
13998 while Present (Variant) loop
13999 Check_Variant (Variant, Typ);
14004 Set_Is_Unchecked_Union (Typ);
14005 Set_Convention (Typ, Convention_C);
14006 Set_Has_Unchecked_Union (Base_Type (Typ));
14007 Set_Is_Unchecked_Union (Base_Type (Typ));
14008 end Unchecked_Union;
14010 ------------------------
14011 -- Unimplemented_Unit --
14012 ------------------------
14014 -- pragma Unimplemented_Unit;
14016 -- Note: this only gives an error if we are generating code, or if
14017 -- we are in a generic library unit (where the pragma appears in the
14018 -- body, not in the spec).
14020 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
14021 Cunitent : constant Entity_Id :=
14022 Cunit_Entity (Get_Source_Unit (Loc));
14023 Ent_Kind : constant Entity_Kind :=
14028 Check_Arg_Count (0);
14030 if Operating_Mode = Generate_Code
14031 or else Ent_Kind = E_Generic_Function
14032 or else Ent_Kind = E_Generic_Procedure
14033 or else Ent_Kind = E_Generic_Package
14035 Get_Name_String (Chars (Cunitent));
14036 Set_Casing (Mixed_Case);
14037 Write_Str (Name_Buffer (1 .. Name_Len));
14038 Write_Str (" is not supported in this configuration");
14040 raise Unrecoverable_Error;
14042 end Unimplemented_Unit;
14044 ------------------------
14045 -- Universal_Aliasing --
14046 ------------------------
14048 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
14050 when Pragma_Universal_Aliasing => Universal_Alias : declare
14055 Check_Arg_Count (1);
14056 Check_Optional_Identifier (Arg2, Name_Entity);
14057 Check_Arg_Is_Local_Name (Arg1);
14058 E_Id := Entity (Get_Pragma_Arg (Arg1));
14060 if E_Id = Any_Type then
14062 elsif No (E_Id) or else not Is_Type (E_Id) then
14063 Error_Pragma_Arg ("pragma% requires type", Arg1);
14066 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
14067 end Universal_Alias;
14069 --------------------
14070 -- Universal_Data --
14071 --------------------
14073 -- pragma Universal_Data [(library_unit_NAME)];
14075 when Pragma_Universal_Data =>
14078 -- If this is a configuration pragma, then set the universal
14079 -- addressing option, otherwise confirm that the pragma satisfies
14080 -- the requirements of library unit pragma placement and leave it
14081 -- to the GNAAMP back end to detect the pragma (avoids transitive
14082 -- setting of the option due to withed units).
14084 if Is_Configuration_Pragma then
14085 Universal_Addressing_On_AAMP := True;
14087 Check_Valid_Library_Unit_Pragma;
14090 if not AAMP_On_Target then
14091 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
14098 -- pragma Unmodified (local_Name {, local_Name});
14100 when Pragma_Unmodified => Unmodified : declare
14101 Arg_Node : Node_Id;
14102 Arg_Expr : Node_Id;
14103 Arg_Ent : Entity_Id;
14107 Check_At_Least_N_Arguments (1);
14109 -- Loop through arguments
14112 while Present (Arg_Node) loop
14113 Check_No_Identifier (Arg_Node);
14115 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
14116 -- in fact generate reference, so that the entity will have a
14117 -- reference, which will inhibit any warnings about it not
14118 -- being referenced, and also properly show up in the ali file
14119 -- as a reference. But this reference is recorded before the
14120 -- Has_Pragma_Unreferenced flag is set, so that no warning is
14121 -- generated for this reference.
14123 Check_Arg_Is_Local_Name (Arg_Node);
14124 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14126 if Is_Entity_Name (Arg_Expr) then
14127 Arg_Ent := Entity (Arg_Expr);
14129 if not Is_Assignable (Arg_Ent) then
14131 ("pragma% can only be applied to a variable",
14134 Set_Has_Pragma_Unmodified (Arg_Ent);
14146 -- pragma Unreferenced (local_Name {, local_Name});
14148 -- or when used in a context clause:
14150 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
14152 when Pragma_Unreferenced => Unreferenced : declare
14153 Arg_Node : Node_Id;
14154 Arg_Expr : Node_Id;
14155 Arg_Ent : Entity_Id;
14160 Check_At_Least_N_Arguments (1);
14162 -- Check case of appearing within context clause
14164 if Is_In_Context_Clause then
14166 -- The arguments must all be units mentioned in a with clause
14167 -- in the same context clause. Note we already checked (in
14168 -- Par.Prag) that the arguments are either identifiers or
14169 -- selected components.
14172 while Present (Arg_Node) loop
14173 Citem := First (List_Containing (N));
14174 while Citem /= N loop
14175 if Nkind (Citem) = N_With_Clause
14177 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
14179 Set_Has_Pragma_Unreferenced
14182 (Library_Unit (Citem))));
14184 (Get_Pragma_Arg (Arg_Node), Name (Citem));
14193 ("argument of pragma% is not with'ed unit", Arg_Node);
14199 -- Case of not in list of context items
14203 while Present (Arg_Node) loop
14204 Check_No_Identifier (Arg_Node);
14206 -- Note: the analyze call done by Check_Arg_Is_Local_Name
14207 -- will in fact generate reference, so that the entity will
14208 -- have a reference, which will inhibit any warnings about
14209 -- it not being referenced, and also properly show up in the
14210 -- ali file as a reference. But this reference is recorded
14211 -- before the Has_Pragma_Unreferenced flag is set, so that
14212 -- no warning is generated for this reference.
14214 Check_Arg_Is_Local_Name (Arg_Node);
14215 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14217 if Is_Entity_Name (Arg_Expr) then
14218 Arg_Ent := Entity (Arg_Expr);
14220 -- If the entity is overloaded, the pragma applies to the
14221 -- most recent overloading, as documented. In this case,
14222 -- name resolution does not generate a reference, so it
14223 -- must be done here explicitly.
14225 if Is_Overloaded (Arg_Expr) then
14226 Generate_Reference (Arg_Ent, N);
14229 Set_Has_Pragma_Unreferenced (Arg_Ent);
14237 --------------------------
14238 -- Unreferenced_Objects --
14239 --------------------------
14241 -- pragma Unreferenced_Objects (local_Name {, local_Name});
14243 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
14244 Arg_Node : Node_Id;
14245 Arg_Expr : Node_Id;
14249 Check_At_Least_N_Arguments (1);
14252 while Present (Arg_Node) loop
14253 Check_No_Identifier (Arg_Node);
14254 Check_Arg_Is_Local_Name (Arg_Node);
14255 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14257 if not Is_Entity_Name (Arg_Expr)
14258 or else not Is_Type (Entity (Arg_Expr))
14261 ("argument for pragma% must be type or subtype", Arg_Node);
14264 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
14267 end Unreferenced_Objects;
14269 ------------------------------
14270 -- Unreserve_All_Interrupts --
14271 ------------------------------
14273 -- pragma Unreserve_All_Interrupts;
14275 when Pragma_Unreserve_All_Interrupts =>
14277 Check_Arg_Count (0);
14279 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
14280 Unreserve_All_Interrupts := True;
14287 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
14289 when Pragma_Unsuppress =>
14291 Process_Suppress_Unsuppress (False);
14293 -------------------
14294 -- Use_VADS_Size --
14295 -------------------
14297 -- pragma Use_VADS_Size;
14299 when Pragma_Use_VADS_Size =>
14301 Check_Arg_Count (0);
14302 Check_Valid_Configuration_Pragma;
14303 Use_VADS_Size := True;
14305 ---------------------
14306 -- Validity_Checks --
14307 ---------------------
14309 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14311 when Pragma_Validity_Checks => Validity_Checks : declare
14312 A : constant Node_Id := Get_Pragma_Arg (Arg1);
14318 Check_Arg_Count (1);
14319 Check_No_Identifiers;
14321 if Nkind (A) = N_String_Literal then
14325 Slen : constant Natural := Natural (String_Length (S));
14326 Options : String (1 .. Slen);
14332 C := Get_String_Char (S, Int (J));
14333 exit when not In_Character_Range (C);
14334 Options (J) := Get_Character (C);
14337 Set_Validity_Check_Options (Options);
14345 elsif Nkind (A) = N_Identifier then
14346 if Chars (A) = Name_All_Checks then
14347 Set_Validity_Check_Options ("a");
14348 elsif Chars (A) = Name_On then
14349 Validity_Checks_On := True;
14350 elsif Chars (A) = Name_Off then
14351 Validity_Checks_On := False;
14354 end Validity_Checks;
14360 -- pragma Volatile (LOCAL_NAME);
14362 when Pragma_Volatile =>
14363 Process_Atomic_Shared_Volatile;
14365 -------------------------
14366 -- Volatile_Components --
14367 -------------------------
14369 -- pragma Volatile_Components (array_LOCAL_NAME);
14371 -- Volatile is handled by the same circuit as Atomic_Components
14377 -- pragma Warnings (On | Off);
14378 -- pragma Warnings (On | Off, LOCAL_NAME);
14379 -- pragma Warnings (static_string_EXPRESSION);
14380 -- pragma Warnings (On | Off, STRING_LITERAL);
14382 when Pragma_Warnings => Warnings : begin
14384 Check_At_Least_N_Arguments (1);
14385 Check_No_Identifiers;
14387 -- If debug flag -gnatd.i is set, pragma is ignored
14389 if Debug_Flag_Dot_I then
14393 -- Process various forms of the pragma
14396 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14399 -- One argument case
14401 if Arg_Count = 1 then
14403 -- On/Off one argument case was processed by parser
14405 if Nkind (Argx) = N_Identifier
14407 (Chars (Argx) = Name_On
14409 Chars (Argx) = Name_Off)
14413 -- One argument case must be ON/OFF or static string expr
14415 elsif not Is_Static_String_Expression (Arg1) then
14417 ("argument of pragma% must be On/Off or " &
14418 "static string expression", Arg1);
14420 -- One argument string expression case
14424 Lit : constant Node_Id := Expr_Value_S (Argx);
14425 Str : constant String_Id := Strval (Lit);
14426 Len : constant Nat := String_Length (Str);
14434 while J <= Len loop
14435 C := Get_String_Char (Str, J);
14436 OK := In_Character_Range (C);
14439 Chr := Get_Character (C);
14443 if J < Len and then Chr = '.' then
14445 C := Get_String_Char (Str, J);
14446 Chr := Get_Character (C);
14448 if not Set_Dot_Warning_Switch (Chr) then
14450 ("invalid warning switch character " &
14457 OK := Set_Warning_Switch (Chr);
14463 ("invalid warning switch character " & Chr,
14472 -- Two or more arguments (must be two)
14475 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14476 Check_At_Most_N_Arguments (2);
14484 E_Id := Get_Pragma_Arg (Arg2);
14487 -- In the expansion of an inlined body, a reference to
14488 -- the formal may be wrapped in a conversion if the
14489 -- actual is a conversion. Retrieve the real entity name.
14491 if (In_Instance_Body
14492 or else In_Inlined_Body)
14493 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14495 E_Id := Expression (E_Id);
14498 -- Entity name case
14500 if Is_Entity_Name (E_Id) then
14501 E := Entity (E_Id);
14508 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14511 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14512 and then Warn_On_Warnings_Off
14514 Warnings_Off_Pragmas.Append ((N, E));
14517 if Is_Enumeration_Type (E) then
14521 Lit := First_Literal (E);
14522 while Present (Lit) loop
14523 Set_Warnings_Off (Lit);
14524 Next_Literal (Lit);
14529 exit when No (Homonym (E));
14534 -- Error if not entity or static string literal case
14536 elsif not Is_Static_String_Expression (Arg2) then
14538 ("second argument of pragma% must be entity " &
14539 "name or static string expression", Arg2);
14541 -- String literal case
14544 String_To_Name_Buffer
14545 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14547 -- Note on configuration pragma case: If this is a
14548 -- configuration pragma, then for an OFF pragma, we
14549 -- just set Config True in the call, which is all
14550 -- that needs to be done. For the case of ON, this
14551 -- is normally an error, unless it is canceling the
14552 -- effect of a previous OFF pragma in the same file.
14553 -- In any other case, an error will be signalled (ON
14554 -- with no matching OFF).
14556 if Chars (Argx) = Name_Off then
14557 Set_Specific_Warning_Off
14558 (Loc, Name_Buffer (1 .. Name_Len),
14559 Config => Is_Configuration_Pragma);
14561 elsif Chars (Argx) = Name_On then
14562 Set_Specific_Warning_On
14563 (Loc, Name_Buffer (1 .. Name_Len), Err);
14567 ("?pragma Warnings On with no " &
14568 "matching Warnings Off",
14578 -------------------
14579 -- Weak_External --
14580 -------------------
14582 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
14584 when Pragma_Weak_External => Weak_External : declare
14589 Check_Arg_Count (1);
14590 Check_Optional_Identifier (Arg1, Name_Entity);
14591 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14592 Ent := Entity (Get_Pragma_Arg (Arg1));
14594 if Rep_Item_Too_Early (Ent, N) then
14597 Ent := Underlying_Type (Ent);
14600 -- The only processing required is to link this item on to the
14601 -- list of rep items for the given entity. This is accomplished
14602 -- by the call to Rep_Item_Too_Late (when no error is detected
14603 -- and False is returned).
14605 if Rep_Item_Too_Late (Ent, N) then
14608 Set_Has_Gigi_Rep_Item (Ent);
14612 -----------------------------
14613 -- Wide_Character_Encoding --
14614 -----------------------------
14616 -- pragma Wide_Character_Encoding (IDENTIFIER);
14618 when Pragma_Wide_Character_Encoding =>
14621 -- Nothing to do, handled in parser. Note that we do not enforce
14622 -- configuration pragma placement, this pragma can appear at any
14623 -- place in the source, allowing mixed encodings within a single
14628 --------------------
14629 -- Unknown_Pragma --
14630 --------------------
14632 -- Should be impossible, since the case of an unknown pragma is
14633 -- separately processed before the case statement is entered.
14635 when Unknown_Pragma =>
14636 raise Program_Error;
14639 -- AI05-0144: detect dangerous order dependence. Disabled for now,
14640 -- until AI is formally approved.
14642 -- Check_Order_Dependence;
14645 when Pragma_Exit => null;
14646 end Analyze_Pragma;
14648 -----------------------------
14649 -- Analyze_TC_In_Decl_Part --
14650 -----------------------------
14652 procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14654 -- Install formals and push subprogram spec onto scope stack so that we
14655 -- can see the formals from the pragma.
14657 Install_Formals (S);
14660 -- Preanalyze the boolean expressions, we treat these as spec
14661 -- expressions (i.e. similar to a default expression).
14663 Preanalyze_TC_Args (N,
14664 Get_Requires_From_Test_Case_Pragma (N),
14665 Get_Ensures_From_Test_Case_Pragma (N));
14667 -- Remove the subprogram from the scope stack now that the pre-analysis
14668 -- of the expressions in the test-case is done.
14671 end Analyze_TC_In_Decl_Part;
14673 --------------------
14674 -- Check_Disabled --
14675 --------------------
14677 function Check_Disabled (Nam : Name_Id) return Boolean is
14681 -- Loop through entries in check policy list
14683 PP := Opt.Check_Policy_List;
14685 -- If there are no specific entries that matched, then nothing is
14686 -- disabled, so return False.
14691 -- Here we have an entry see if it matches
14695 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14697 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14698 return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14700 PP := Next_Pragma (PP);
14705 end Check_Disabled;
14707 -------------------
14708 -- Check_Enabled --
14709 -------------------
14711 function Check_Enabled (Nam : Name_Id) return Boolean is
14715 -- Loop through entries in check policy list
14717 PP := Opt.Check_Policy_List;
14719 -- If there are no specific entries that matched, then we let the
14720 -- setting of assertions govern. Note that this provides the needed
14721 -- compatibility with the RM for the cases of assertion, invariant,
14722 -- precondition, predicate, and postcondition.
14725 return Assertions_Enabled;
14727 -- Here we have an entry see if it matches
14731 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14734 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14735 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14736 when Name_On | Name_Check =>
14738 when Name_Off | Name_Ignore =>
14741 raise Program_Error;
14745 PP := Next_Pragma (PP);
14752 ---------------------------------
14753 -- Delay_Config_Pragma_Analyze --
14754 ---------------------------------
14756 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14758 return Pragma_Name (N) = Name_Interrupt_State
14760 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14761 end Delay_Config_Pragma_Analyze;
14763 -------------------------
14764 -- Get_Base_Subprogram --
14765 -------------------------
14767 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14768 Result : Entity_Id;
14771 -- Follow subprogram renaming chain
14774 while Is_Subprogram (Result)
14776 Nkind (Parent (Declaration_Node (Result))) =
14777 N_Subprogram_Renaming_Declaration
14778 and then Present (Alias (Result))
14780 Result := Alias (Result);
14784 end Get_Base_Subprogram;
14790 procedure Initialize is
14795 -----------------------------
14796 -- Is_Config_Static_String --
14797 -----------------------------
14799 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14801 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14802 -- This is an internal recursive function that is just like the outer
14803 -- function except that it adds the string to the name buffer rather
14804 -- than placing the string in the name buffer.
14806 ------------------------------
14807 -- Add_Config_Static_String --
14808 ------------------------------
14810 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14817 if Nkind (N) = N_Op_Concat then
14818 if Add_Config_Static_String (Left_Opnd (N)) then
14819 N := Right_Opnd (N);
14825 if Nkind (N) /= N_String_Literal then
14826 Error_Msg_N ("string literal expected for pragma argument", N);
14830 for J in 1 .. String_Length (Strval (N)) loop
14831 C := Get_String_Char (Strval (N), J);
14833 if not In_Character_Range (C) then
14835 ("string literal contains invalid wide character",
14836 Sloc (N) + 1 + Source_Ptr (J));
14840 Add_Char_To_Name_Buffer (Get_Character (C));
14845 end Add_Config_Static_String;
14847 -- Start of processing for Is_Config_Static_String
14852 return Add_Config_Static_String (Arg);
14853 end Is_Config_Static_String;
14855 -----------------------------------------
14856 -- Is_Non_Significant_Pragma_Reference --
14857 -----------------------------------------
14859 -- This function makes use of the following static table which indicates
14860 -- whether a given pragma is significant.
14862 -- -1 indicates that references in any argument position are significant
14863 -- 0 indicates that appearance in any argument is not significant
14864 -- +n indicates that appearance as argument n is significant, but all
14865 -- other arguments are not significant
14866 -- 99 special processing required (e.g. for pragma Check)
14868 Sig_Flags : constant array (Pragma_Id) of Int :=
14869 (Pragma_AST_Entry => -1,
14870 Pragma_Abort_Defer => -1,
14871 Pragma_Ada_83 => -1,
14872 Pragma_Ada_95 => -1,
14873 Pragma_Ada_05 => -1,
14874 Pragma_Ada_2005 => -1,
14875 Pragma_Ada_12 => -1,
14876 Pragma_Ada_2012 => -1,
14877 Pragma_All_Calls_Remote => -1,
14878 Pragma_Annotate => -1,
14879 Pragma_Assert => -1,
14880 Pragma_Assertion_Policy => 0,
14881 Pragma_Assume_No_Invalid_Values => 0,
14882 Pragma_Asynchronous => -1,
14883 Pragma_Atomic => 0,
14884 Pragma_Atomic_Components => 0,
14885 Pragma_Attach_Handler => -1,
14886 Pragma_Check => 99,
14887 Pragma_Check_Name => 0,
14888 Pragma_Check_Policy => 0,
14889 Pragma_CIL_Constructor => -1,
14890 Pragma_CPP_Class => 0,
14891 Pragma_CPP_Constructor => 0,
14892 Pragma_CPP_Virtual => 0,
14893 Pragma_CPP_Vtable => 0,
14895 Pragma_C_Pass_By_Copy => 0,
14896 Pragma_Comment => 0,
14897 Pragma_Common_Object => -1,
14898 Pragma_Compile_Time_Error => -1,
14899 Pragma_Compile_Time_Warning => -1,
14900 Pragma_Compiler_Unit => 0,
14901 Pragma_Complete_Representation => 0,
14902 Pragma_Complex_Representation => 0,
14903 Pragma_Component_Alignment => -1,
14904 Pragma_Controlled => 0,
14905 Pragma_Convention => 0,
14906 Pragma_Convention_Identifier => 0,
14907 Pragma_Debug => -1,
14908 Pragma_Debug_Policy => 0,
14909 Pragma_Detect_Blocking => -1,
14910 Pragma_Default_Storage_Pool => -1,
14911 Pragma_Dimension => -1,
14912 Pragma_Disable_Atomic_Synchronization => -1,
14913 Pragma_Discard_Names => 0,
14914 Pragma_Dispatching_Domain => -1,
14915 Pragma_Elaborate => -1,
14916 Pragma_Elaborate_All => -1,
14917 Pragma_Elaborate_Body => -1,
14918 Pragma_Elaboration_Checks => -1,
14919 Pragma_Eliminate => -1,
14920 Pragma_Enable_Atomic_Synchronization => -1,
14921 Pragma_Export => -1,
14922 Pragma_Export_Exception => -1,
14923 Pragma_Export_Function => -1,
14924 Pragma_Export_Object => -1,
14925 Pragma_Export_Procedure => -1,
14926 Pragma_Export_Value => -1,
14927 Pragma_Export_Valued_Procedure => -1,
14928 Pragma_Extend_System => -1,
14929 Pragma_Extensions_Allowed => -1,
14930 Pragma_External => -1,
14931 Pragma_Favor_Top_Level => -1,
14932 Pragma_External_Name_Casing => -1,
14933 Pragma_Fast_Math => -1,
14934 Pragma_Finalize_Storage_Only => 0,
14935 Pragma_Float_Representation => 0,
14936 Pragma_Ident => -1,
14937 Pragma_Implementation_Defined => -1,
14938 Pragma_Implemented => -1,
14939 Pragma_Implicit_Packing => 0,
14940 Pragma_Import => +2,
14941 Pragma_Import_Exception => 0,
14942 Pragma_Import_Function => 0,
14943 Pragma_Import_Object => 0,
14944 Pragma_Import_Procedure => 0,
14945 Pragma_Import_Valued_Procedure => 0,
14946 Pragma_Independent => 0,
14947 Pragma_Independent_Components => 0,
14948 Pragma_Initialize_Scalars => -1,
14949 Pragma_Inline => 0,
14950 Pragma_Inline_Always => 0,
14951 Pragma_Inline_Generic => 0,
14952 Pragma_Inspection_Point => -1,
14953 Pragma_Interface => +2,
14954 Pragma_Interface_Name => +2,
14955 Pragma_Interrupt_Handler => -1,
14956 Pragma_Interrupt_Priority => -1,
14957 Pragma_Interrupt_State => -1,
14958 Pragma_Invariant => -1,
14959 Pragma_Java_Constructor => -1,
14960 Pragma_Java_Interface => -1,
14961 Pragma_Keep_Names => 0,
14962 Pragma_License => -1,
14963 Pragma_Link_With => -1,
14964 Pragma_Linker_Alias => -1,
14965 Pragma_Linker_Constructor => -1,
14966 Pragma_Linker_Destructor => -1,
14967 Pragma_Linker_Options => -1,
14968 Pragma_Linker_Section => -1,
14970 Pragma_Locking_Policy => -1,
14971 Pragma_Long_Float => -1,
14972 Pragma_Machine_Attribute => -1,
14974 Pragma_Main_Storage => -1,
14975 Pragma_Memory_Size => -1,
14976 Pragma_No_Return => 0,
14977 Pragma_No_Body => 0,
14978 Pragma_No_Run_Time => -1,
14979 Pragma_No_Strict_Aliasing => -1,
14980 Pragma_Normalize_Scalars => -1,
14981 Pragma_Obsolescent => 0,
14982 Pragma_Optimize => -1,
14983 Pragma_Optimize_Alignment => -1,
14984 Pragma_Ordered => 0,
14987 Pragma_Passive => -1,
14988 Pragma_Preelaborable_Initialization => -1,
14989 Pragma_Polling => -1,
14990 Pragma_Persistent_BSS => 0,
14991 Pragma_Postcondition => -1,
14992 Pragma_Precondition => -1,
14993 Pragma_Predicate => -1,
14994 Pragma_Preelaborate => -1,
14995 Pragma_Preelaborate_05 => -1,
14996 Pragma_Priority => -1,
14997 Pragma_Priority_Specific_Dispatching => -1,
14998 Pragma_Profile => 0,
14999 Pragma_Profile_Warnings => 0,
15000 Pragma_Propagate_Exceptions => -1,
15001 Pragma_Psect_Object => -1,
15003 Pragma_Pure_05 => -1,
15004 Pragma_Pure_12 => -1,
15005 Pragma_Pure_Function => -1,
15006 Pragma_Queuing_Policy => -1,
15007 Pragma_Ravenscar => -1,
15008 Pragma_Relative_Deadline => -1,
15009 Pragma_Remote_Call_Interface => -1,
15010 Pragma_Remote_Types => -1,
15011 Pragma_Restricted_Run_Time => -1,
15012 Pragma_Restriction_Warnings => -1,
15013 Pragma_Restrictions => -1,
15014 Pragma_Reviewable => -1,
15015 Pragma_Short_Circuit_And_Or => -1,
15016 Pragma_Share_Generic => -1,
15017 Pragma_Shared => -1,
15018 Pragma_Shared_Passive => -1,
15019 Pragma_Short_Descriptors => 0,
15020 Pragma_Source_File_Name => -1,
15021 Pragma_Source_File_Name_Project => -1,
15022 Pragma_Source_Reference => -1,
15023 Pragma_Storage_Size => -1,
15024 Pragma_Storage_Unit => -1,
15025 Pragma_Static_Elaboration_Desired => -1,
15026 Pragma_Stream_Convert => -1,
15027 Pragma_Style_Checks => -1,
15028 Pragma_Subtitle => -1,
15029 Pragma_Suppress => 0,
15030 Pragma_Suppress_Exception_Locations => 0,
15031 Pragma_Suppress_All => -1,
15032 Pragma_Suppress_Debug_Info => 0,
15033 Pragma_Suppress_Initialization => 0,
15034 Pragma_System_Name => -1,
15035 Pragma_Task_Dispatching_Policy => -1,
15036 Pragma_Task_Info => -1,
15037 Pragma_Task_Name => -1,
15038 Pragma_Task_Storage => 0,
15039 Pragma_Test_Case => -1,
15040 Pragma_Thread_Local_Storage => 0,
15041 Pragma_Time_Slice => -1,
15042 Pragma_Title => -1,
15043 Pragma_Unchecked_Union => 0,
15044 Pragma_Unimplemented_Unit => -1,
15045 Pragma_Universal_Aliasing => -1,
15046 Pragma_Universal_Data => -1,
15047 Pragma_Unmodified => -1,
15048 Pragma_Unreferenced => -1,
15049 Pragma_Unreferenced_Objects => -1,
15050 Pragma_Unreserve_All_Interrupts => -1,
15051 Pragma_Unsuppress => 0,
15052 Pragma_Use_VADS_Size => -1,
15053 Pragma_Validity_Checks => -1,
15054 Pragma_Volatile => 0,
15055 Pragma_Volatile_Components => 0,
15056 Pragma_Warnings => -1,
15057 Pragma_Weak_External => -1,
15058 Pragma_Wide_Character_Encoding => 0,
15059 Unknown_Pragma => 0);
15061 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
15070 if Nkind (P) /= N_Pragma_Argument_Association then
15074 Id := Get_Pragma_Id (Parent (P));
15075 C := Sig_Flags (Id);
15087 -- For pragma Check, the first argument is not significant,
15088 -- the second and the third (if present) arguments are
15091 when Pragma_Check =>
15093 P = First (Pragma_Argument_Associations (Parent (P)));
15096 raise Program_Error;
15100 A := First (Pragma_Argument_Associations (Parent (P)));
15101 for J in 1 .. C - 1 loop
15109 return A = P; -- is this wrong way round ???
15112 end Is_Non_Significant_Pragma_Reference;
15114 ------------------------------
15115 -- Is_Pragma_String_Literal --
15116 ------------------------------
15118 -- This function returns true if the corresponding pragma argument is a
15119 -- static string expression. These are the only cases in which string
15120 -- literals can appear as pragma arguments. We also allow a string literal
15121 -- as the first argument to pragma Assert (although it will of course
15122 -- always generate a type error).
15124 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
15125 Pragn : constant Node_Id := Parent (Par);
15126 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
15127 Pname : constant Name_Id := Pragma_Name (Pragn);
15133 N := First (Assoc);
15140 if Pname = Name_Assert then
15143 elsif Pname = Name_Export then
15146 elsif Pname = Name_Ident then
15149 elsif Pname = Name_Import then
15152 elsif Pname = Name_Interface_Name then
15155 elsif Pname = Name_Linker_Alias then
15158 elsif Pname = Name_Linker_Section then
15161 elsif Pname = Name_Machine_Attribute then
15164 elsif Pname = Name_Source_File_Name then
15167 elsif Pname = Name_Source_Reference then
15170 elsif Pname = Name_Title then
15173 elsif Pname = Name_Subtitle then
15179 end Is_Pragma_String_Literal;
15181 ------------------------
15182 -- Preanalyze_TC_Args --
15183 ------------------------
15185 procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
15187 -- Preanalyze the boolean expressions, we treat these as spec
15188 -- expressions (i.e. similar to a default expression).
15190 if Present (Arg_Req) then
15191 Preanalyze_Spec_Expression
15192 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
15194 -- In ASIS mode, for a pragma generated from a source aspect, also
15195 -- analyze the original aspect expression.
15198 and then Present (Corresponding_Aspect (N))
15200 Preanalyze_Spec_Expression
15201 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
15205 if Present (Arg_Ens) then
15206 Preanalyze_Spec_Expression
15207 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
15209 -- In ASIS mode, for a pragma generated from a source aspect, also
15210 -- analyze the original aspect expression.
15213 and then Present (Corresponding_Aspect (N))
15215 Preanalyze_Spec_Expression
15216 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
15219 end Preanalyze_TC_Args;
15221 --------------------------------------
15222 -- Process_Compilation_Unit_Pragmas --
15223 --------------------------------------
15225 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
15227 -- A special check for pragma Suppress_All, a very strange DEC pragma,
15228 -- strange because it comes at the end of the unit. Rational has the
15229 -- same name for a pragma, but treats it as a program unit pragma, In
15230 -- GNAT we just decide to allow it anywhere at all. If it appeared then
15231 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
15232 -- node, and we insert a pragma Suppress (All_Checks) at the start of
15233 -- the context clause to ensure the correct processing.
15235 if Has_Pragma_Suppress_All (N) then
15236 Prepend_To (Context_Items (N),
15237 Make_Pragma (Sloc (N),
15238 Chars => Name_Suppress,
15239 Pragma_Argument_Associations => New_List (
15240 Make_Pragma_Argument_Association (Sloc (N),
15241 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
15244 -- Nothing else to do at the current time!
15246 end Process_Compilation_Unit_Pragmas;
15257 --------------------------------
15258 -- Set_Encoded_Interface_Name --
15259 --------------------------------
15261 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
15262 Str : constant String_Id := Strval (S);
15263 Len : constant Int := String_Length (Str);
15268 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
15271 -- Stores encoded value of character code CC. The encoding we use an
15272 -- underscore followed by four lower case hex digits.
15278 procedure Encode is
15280 Store_String_Char (Get_Char_Code ('_'));
15282 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
15284 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
15286 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
15288 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
15291 -- Start of processing for Set_Encoded_Interface_Name
15294 -- If first character is asterisk, this is a link name, and we leave it
15295 -- completely unmodified. We also ignore null strings (the latter case
15296 -- happens only in error cases) and no encoding should occur for Java or
15297 -- AAMP interface names.
15300 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
15301 or else VM_Target /= No_VM
15302 or else AAMP_On_Target
15304 Set_Interface_Name (E, S);
15309 CC := Get_String_Char (Str, J);
15311 exit when not In_Character_Range (CC);
15313 C := Get_Character (CC);
15315 exit when C /= '_' and then C /= '$'
15316 and then C not in '0' .. '9'
15317 and then C not in 'a' .. 'z'
15318 and then C not in 'A' .. 'Z';
15321 Set_Interface_Name (E, S);
15329 -- Here we need to encode. The encoding we use as follows:
15330 -- three underscores + four hex digits (lower case)
15334 for J in 1 .. String_Length (Str) loop
15335 CC := Get_String_Char (Str, J);
15337 if not In_Character_Range (CC) then
15340 C := Get_Character (CC);
15342 if C = '_' or else C = '$'
15343 or else C in '0' .. '9'
15344 or else C in 'a' .. 'z'
15345 or else C in 'A' .. 'Z'
15347 Store_String_Char (CC);
15354 Set_Interface_Name (E,
15355 Make_String_Literal (Sloc (S),
15356 Strval => End_String));
15358 end Set_Encoded_Interface_Name;
15360 -------------------
15361 -- Set_Unit_Name --
15362 -------------------
15364 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15369 if Nkind (N) = N_Identifier
15370 and then Nkind (With_Item) = N_Identifier
15372 Set_Entity (N, Entity (With_Item));
15374 elsif Nkind (N) = N_Selected_Component then
15375 Change_Selected_Component_To_Expanded_Name (N);
15376 Set_Entity (N, Entity (With_Item));
15377 Set_Entity (Selector_Name (N), Entity (N));
15379 Pref := Prefix (N);
15380 Scop := Scope (Entity (N));
15381 while Nkind (Pref) = N_Selected_Component loop
15382 Change_Selected_Component_To_Expanded_Name (Pref);
15383 Set_Entity (Selector_Name (Pref), Scop);
15384 Set_Entity (Pref, Scop);
15385 Pref := Prefix (Pref);
15386 Scop := Scope (Scop);
15389 Set_Entity (Pref, Scop);