1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Aspects; use Aspects;
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Checks; use Checks;
36 with Csets; use Csets;
37 with Debug; use Debug;
38 with Einfo; use Einfo;
39 with Elists; use Elists;
40 with Errout; use Errout;
41 with Exp_Dist; use Exp_Dist;
42 with Exp_Util; use Exp_Util;
43 with Freeze; use Freeze;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet.Sp; use Namet.Sp;
48 with Nlists; use Nlists;
49 with Nmake; use Nmake;
51 with Output; use Output;
52 with Par_SCO; use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident; use Rident;
55 with Rtsfind; use Rtsfind;
57 with Sem_Aux; use Sem_Aux;
58 with Sem_Ch3; use Sem_Ch3;
59 with Sem_Ch6; use Sem_Ch6;
60 with Sem_Ch8; use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res; use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_VFpt; use Sem_VFpt;
73 with Sem_Warn; use Sem_Warn;
74 with Stand; use Stand;
75 with Sinfo; use Sinfo;
76 with Sinfo.CN; use Sinfo.CN;
77 with Sinput; use Sinput;
78 with Snames; use Snames;
79 with Stringt; use Stringt;
80 with Stylesw; use Stylesw;
82 with Targparm; use Targparm;
83 with Tbuild; use Tbuild;
85 with Uintp; use Uintp;
86 with Uname; use Uname;
87 with Urealp; use Urealp;
88 with Validsw; use Validsw;
89 with Warnsw; use Warnsw;
91 package body Sem_Prag is
93 ----------------------------------------------
94 -- Common Handling of Import-Export Pragmas --
95 ----------------------------------------------
97 -- In the following section, a number of Import_xxx and Export_xxx pragmas
98 -- are defined by GNAT. These are compatible with the DEC pragmas of the
99 -- same name, and all have the following common form and processing:
102 -- [Internal =>] LOCAL_NAME
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
107 -- [Internal =>] LOCAL_NAME
108 -- [, [External =>] EXTERNAL_SYMBOL]
109 -- [, other optional parameters ]);
111 -- EXTERNAL_SYMBOL ::=
113 -- | static_string_EXPRESSION
115 -- The internal LOCAL_NAME designates the entity that is imported or
116 -- exported, and must refer to an entity in the current declarative
117 -- part (as required by the rules for LOCAL_NAME).
119 -- The external linker name is designated by the External parameter if
120 -- given, or the Internal parameter if not (if there is no External
121 -- parameter, the External parameter is a copy of the Internal name).
123 -- If the External parameter is given as a string, then this string is
124 -- treated as an external name (exactly as though it had been given as an
125 -- External_Name parameter for a normal Import pragma).
127 -- If the External parameter is given as an identifier (or there is no
128 -- External parameter, so that the Internal identifier is used), then
129 -- the external name is the characters of the identifier, translated
130 -- to all upper case letters for OpenVMS versions of GNAT, and to all
131 -- lower case letters for all other versions
133 -- Note: the external name specified or implied by any of these special
134 -- Import_xxx or Export_xxx pragmas override an external or link name
135 -- specified in a previous Import or Export pragma.
137 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
138 -- named notation, following the standard rules for subprogram calls, i.e.
139 -- parameters can be given in any order if named notation is used, and
140 -- positional and named notation can be mixed, subject to the rule that all
141 -- positional parameters must appear first.
143 -- Note: All these pragmas are implemented exactly following the DEC design
144 -- and implementation and are intended to be fully compatible with the use
145 -- of these pragmas in the DEC Ada compiler.
147 --------------------------------------------
148 -- Checking for Duplicated External Names --
149 --------------------------------------------
151 -- It is suspicious if two separate Export pragmas use the same external
152 -- name. The following table is used to diagnose this situation so that
153 -- an appropriate warning can be issued.
155 -- The Node_Id stored is for the N_String_Literal node created to hold
156 -- the value of the external name. The Sloc of this node is used to
157 -- cross-reference the location of the duplication.
159 package Externals is new Table.Table (
160 Table_Component_Type => Node_Id,
161 Table_Index_Type => Int,
162 Table_Low_Bound => 0,
163 Table_Initial => 100,
164 Table_Increment => 100,
165 Table_Name => "Name_Externals");
167 -------------------------------------
168 -- Local Subprograms and Variables --
169 -------------------------------------
171 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
172 -- This routine is used for possible casing adjustment of an explicit
173 -- external name supplied as a string literal (the node N), according to
174 -- the casing requirement of Opt.External_Name_Casing. If this is set to
175 -- As_Is, then the string literal is returned unchanged, but if it is set
176 -- to Uppercase or Lowercase, then a new string literal with appropriate
177 -- casing is constructed.
179 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
180 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
181 -- original one, following the renaming chain) is returned. Otherwise the
182 -- entity is returned unchanged. Should be in Einfo???
184 procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id);
185 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
186 -- of a Test_Case pragma if present (possibly Empty). We treat these as
187 -- spec expressions (i.e. similar to a default expression).
190 -- This is a dummy function called by the processing for pragma Reviewable.
191 -- It is there for assisting front end debugging. By placing a Reviewable
192 -- pragma in the source program, a breakpoint on rv catches this place in
193 -- the source, allowing convenient stepping to the point of interest.
195 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
196 -- Place semantic information on the argument of an Elaborate/Elaborate_All
197 -- pragma. Entity name for unit and its parents is taken from item in
198 -- previous with_clause that mentions the unit.
200 -------------------------------
201 -- Adjust_External_Name_Case --
202 -------------------------------
204 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
208 -- Adjust case of literal if required
210 if Opt.External_Name_Exp_Casing = As_Is then
214 -- Copy existing string
220 for J in 1 .. String_Length (Strval (N)) loop
221 CC := Get_String_Char (Strval (N), J);
223 if Opt.External_Name_Exp_Casing = Uppercase
224 and then CC >= Get_Char_Code ('a')
225 and then CC <= Get_Char_Code ('z')
227 Store_String_Char (CC - 32);
229 elsif Opt.External_Name_Exp_Casing = Lowercase
230 and then CC >= Get_Char_Code ('A')
231 and then CC <= Get_Char_Code ('Z')
233 Store_String_Char (CC + 32);
236 Store_String_Char (CC);
241 Make_String_Literal (Sloc (N),
242 Strval => End_String);
244 end Adjust_External_Name_Case;
246 ------------------------------
247 -- Analyze_PPC_In_Decl_Part --
248 ------------------------------
250 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
251 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
254 -- Install formals and push subprogram spec onto scope stack so that we
255 -- can see the formals from the pragma.
260 -- Preanalyze the boolean expression, we treat this as a spec expression
261 -- (i.e. similar to a default expression).
263 Preanalyze_Spec_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
265 -- In ASIS mode, for a pragma generated from a source aspect, also
266 -- analyze the original aspect expression.
269 and then Present (Corresponding_Aspect (N))
271 Preanalyze_Spec_Expression
272 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
275 -- For a class-wide condition, a reference to a controlling formal must
276 -- be interpreted as having the class-wide type (or an access to such)
277 -- so that the inherited condition can be properly applied to any
278 -- overriding operation (see ARM12 6.6.1 (7)).
280 if Class_Present (N) then
282 T : constant Entity_Id := Find_Dispatching_Type (S);
284 ACW : Entity_Id := Empty;
285 -- Access to T'class, created if there is a controlling formal
286 -- that is an access parameter.
288 function Get_ACW return Entity_Id;
289 -- If the expression has a reference to an controlling access
290 -- parameter, create an access to T'class for the necessary
291 -- conversions if one does not exist.
293 function Process (N : Node_Id) return Traverse_Result;
294 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
295 -- aspect for a primitive subprogram of a tagged type T, a name
296 -- that denotes a formal parameter of type T is interpreted as
297 -- having type T'Class. Similarly, a name that denotes a formal
298 -- accessparameter of type access-to-T is interpreted as having
299 -- type access-to-T'Class. This ensures the expression is well-
300 -- defined for a primitive subprogram of a type descended from T.
306 function Get_ACW return Entity_Id is
307 Loc : constant Source_Ptr := Sloc (N);
312 Decl := Make_Full_Type_Declaration (Loc,
313 Defining_Identifier => Make_Temporary (Loc, 'T'),
315 Make_Access_To_Object_Definition (Loc,
316 Subtype_Indication =>
317 New_Occurrence_Of (Class_Wide_Type (T), Loc),
318 All_Present => True));
320 Insert_Before (Unit_Declaration_Node (S), Decl);
322 ACW := Defining_Identifier (Decl);
323 Freeze_Before (Unit_Declaration_Node (S), ACW);
333 function Process (N : Node_Id) return Traverse_Result is
334 Loc : constant Source_Ptr := Sloc (N);
338 if Is_Entity_Name (N)
339 and then Is_Formal (Entity (N))
340 and then Nkind (Parent (N)) /= N_Type_Conversion
342 if Etype (Entity (N)) = T then
343 Typ := Class_Wide_Type (T);
345 elsif Is_Access_Type (Etype (Entity (N)))
346 and then Designated_Type (Etype (Entity (N))) = T
353 if Present (Typ) then
355 Make_Type_Conversion (Loc,
357 New_Occurrence_Of (Typ, Loc),
358 Expression => New_Occurrence_Of (Entity (N), Loc)));
366 procedure Replace_Type is new Traverse_Proc (Process);
369 Replace_Type (Get_Pragma_Arg (Arg1));
373 -- Remove the subprogram from the scope stack now that the pre-analysis
374 -- of the precondition/postcondition is done.
377 end Analyze_PPC_In_Decl_Part;
383 procedure Analyze_Pragma (N : Node_Id) is
384 Loc : constant Source_Ptr := Sloc (N);
388 -- Name of the source pragma, or name of the corresponding aspect for
389 -- pragmas which originate in a source aspect. In the latter case, the
390 -- name may be different from the pragma name.
392 Pragma_Exit : exception;
393 -- This exception is used to exit pragma processing completely. It is
394 -- used when an error is detected, and no further processing is
395 -- required. It is also used if an earlier error has left the tree in
396 -- a state where the pragma should not be processed.
399 -- Number of pragma argument associations
405 -- First four pragma arguments (pragma argument association nodes, or
406 -- Empty if the corresponding argument does not exist).
408 type Name_List is array (Natural range <>) of Name_Id;
409 type Args_List is array (Natural range <>) of Node_Id;
410 -- Types used for arguments to Check_Arg_Order and Gather_Associations
412 procedure Ada_2005_Pragma;
413 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
414 -- Ada 95 mode, these are implementation defined pragmas, so should be
415 -- caught by the No_Implementation_Pragmas restriction.
417 procedure Ada_2012_Pragma;
418 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
419 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
420 -- should be caught by the No_Implementation_Pragmas restriction.
422 procedure Check_Ada_83_Warning;
423 -- Issues a warning message for the current pragma if operating in Ada
424 -- 83 mode (used for language pragmas that are not a standard part of
425 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
428 procedure Check_Arg_Count (Required : Nat);
429 -- Check argument count for pragma is equal to given parameter. If not,
430 -- then issue an error message and raise Pragma_Exit.
432 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
433 -- Arg which can either be a pragma argument association, in which case
434 -- the check is applied to the expression of the association or an
435 -- expression directly.
437 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
438 -- Check that an argument has the right form for an EXTERNAL_NAME
439 -- parameter of an extended import/export pragma. The rule is that the
440 -- name must be an identifier or string literal (in Ada 83 mode) or a
441 -- static string expression (in Ada 95 mode).
443 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
444 -- Check the specified argument Arg to make sure that it is an
445 -- identifier. If not give error and raise Pragma_Exit.
447 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
448 -- Check the specified argument Arg to make sure that it is an integer
449 -- literal. If not give error and raise Pragma_Exit.
451 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
452 -- Check the specified argument Arg to make sure that it has the proper
453 -- syntactic form for a local name and meets the semantic requirements
454 -- for a local name. The local name is analyzed as part of the
455 -- processing for this call. In addition, the local name is required
456 -- to represent an entity at the library level.
458 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
459 -- Check the specified argument Arg to make sure that it has the proper
460 -- syntactic form for a local name and meets the semantic requirements
461 -- for a local name. The local name is analyzed as part of the
462 -- processing for this call.
464 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
465 -- Check the specified argument Arg to make sure that it is a valid
466 -- locking policy name. If not give error and raise Pragma_Exit.
468 procedure Check_Arg_Is_One_Of
471 procedure Check_Arg_Is_One_Of
473 N1, N2, N3 : Name_Id);
474 procedure Check_Arg_Is_One_Of
476 N1, N2, N3, N4 : Name_Id);
477 procedure Check_Arg_Is_One_Of
479 N1, N2, N3, N4, N5 : Name_Id);
480 -- Check the specified argument Arg to make sure that it is an
481 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
482 -- present). If not then give error and raise Pragma_Exit.
484 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
485 -- Check the specified argument Arg to make sure that it is a valid
486 -- queuing policy name. If not give error and raise Pragma_Exit.
488 procedure Check_Arg_Is_Static_Expression
490 Typ : Entity_Id := Empty);
491 -- Check the specified argument Arg to make sure that it is a static
492 -- expression of the given type (i.e. it will be analyzed and resolved
493 -- using this type, which can be any valid argument to Resolve, e.g.
494 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
495 -- Typ is left Empty, then any static expression is allowed.
497 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
498 -- Check the specified argument Arg to make sure that it is a valid task
499 -- dispatching policy name. If not give error and raise Pragma_Exit.
501 procedure Check_Arg_Order (Names : Name_List);
502 -- Checks for an instance of two arguments with identifiers for the
503 -- current pragma which are not in the sequence indicated by Names,
504 -- and if so, generates a fatal message about bad order of arguments.
506 procedure Check_At_Least_N_Arguments (N : Nat);
507 -- Check there are at least N arguments present
509 procedure Check_At_Most_N_Arguments (N : Nat);
510 -- Check there are no more than N arguments present
512 procedure Check_Component
515 In_Variant_Part : Boolean := False);
516 -- Examine an Unchecked_Union component for correct use of per-object
517 -- constrained subtypes, and for restrictions on finalizable components.
518 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
519 -- should be set when Comp comes from a record variant.
521 procedure Check_Duplicate_Pragma (E : Entity_Id);
522 -- Check if a pragma of the same name as the current pragma is already
523 -- chained as a rep pragma to the given entity. If so give a message
524 -- about the duplicate, and then raise Pragma_Exit so does not return.
525 -- Also checks for delayed aspect specification node in the chain.
527 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
528 -- Nam is an N_String_Literal node containing the external name set by
529 -- an Import or Export pragma (or extended Import or Export pragma).
530 -- This procedure checks for possible duplications if this is the export
531 -- case, and if found, issues an appropriate error message.
533 procedure Check_Expr_Is_Static_Expression
535 Typ : Entity_Id := Empty);
536 -- Check the specified expression Expr to make sure that it is a static
537 -- expression of the given type (i.e. it will be analyzed and resolved
538 -- using this type, which can be any valid argument to Resolve, e.g.
539 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
540 -- Typ is left Empty, then any static expression is allowed.
542 procedure Check_First_Subtype (Arg : Node_Id);
543 -- Checks that Arg, whose expression is an entity name, references a
546 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
547 -- Checks that the given argument has an identifier, and if so, requires
548 -- it to match the given identifier name. If there is no identifier, or
549 -- a non-matching identifier, then an error message is given and
550 -- Pragma_Exit is raised.
552 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
553 -- Checks that the given argument has an identifier, and if so, requires
554 -- it to match one of the given identifier names. If there is no
555 -- identifier, or a non-matching identifier, then an error message is
556 -- given and Pragma_Exit is raised.
558 procedure Check_In_Main_Program;
559 -- Common checks for pragmas that appear within a main program
560 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
562 procedure Check_Interrupt_Or_Attach_Handler;
563 -- Common processing for first argument of pragma Interrupt_Handler or
564 -- pragma Attach_Handler.
566 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
567 -- Check that pragma appears in a declarative part, or in a package
568 -- specification, i.e. that it does not occur in a statement sequence
571 procedure Check_No_Identifier (Arg : Node_Id);
572 -- Checks that the given argument does not have an identifier. If
573 -- an identifier is present, then an error message is issued, and
574 -- Pragma_Exit is raised.
576 procedure Check_No_Identifiers;
577 -- Checks that none of the arguments to the pragma has an identifier.
578 -- If any argument has an identifier, then an error message is issued,
579 -- and Pragma_Exit is raised.
581 procedure Check_No_Link_Name;
582 -- Checks that no link name is specified
584 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
585 -- Checks if the given argument has an identifier, and if so, requires
586 -- it to match the given identifier name. If there is a non-matching
587 -- identifier, then an error message is given and Pragma_Exit is raised.
589 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
590 -- Checks if the given argument has an identifier, and if so, requires
591 -- it to match the given identifier name. If there is a non-matching
592 -- identifier, then an error message is given and Pragma_Exit is raised.
593 -- In this version of the procedure, the identifier name is given as
594 -- a string with lower case letters.
596 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
597 -- Called to process a precondition or postcondition pragma. There are
600 -- The pragma appears after a subprogram spec
602 -- If the corresponding check is not enabled, the pragma is analyzed
603 -- but otherwise ignored and control returns with In_Body set False.
605 -- If the check is enabled, then the first step is to analyze the
606 -- pragma, but this is skipped if the subprogram spec appears within
607 -- a package specification (because this is the case where we delay
608 -- analysis till the end of the spec). Then (whether or not it was
609 -- analyzed), the pragma is chained to the subprogram in question
610 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
611 -- caller with In_Body set False.
613 -- The pragma appears at the start of subprogram body declarations
615 -- In this case an immediate return to the caller is made with
616 -- In_Body set True, and the pragma is NOT analyzed.
618 -- In all other cases, an error message for bad placement is given
620 procedure Check_Static_Constraint (Constr : Node_Id);
621 -- Constr is a constraint from an N_Subtype_Indication node from a
622 -- component constraint in an Unchecked_Union type. This routine checks
623 -- that the constraint is static as required by the restrictions for
626 procedure Check_Test_Case;
627 -- Called to process a test-case pragma. The treatment is similar to the
628 -- one for pre- and postcondition in Check_Precondition_Postcondition,
629 -- except the placement rules for the test-case pragma are stricter.
630 -- This pragma may only occur after a subprogram spec declared directly
631 -- in a package spec unit. In this case, the pragma is chained to the
632 -- subprogram in question (using Spec_TC_List and Next_Pragma) and
633 -- analysis of the pragma is delayed till the end of the spec. In
634 -- all other cases, an error message for bad placement is given.
636 procedure Check_Valid_Configuration_Pragma;
637 -- Legality checks for placement of a configuration pragma
639 procedure Check_Valid_Library_Unit_Pragma;
640 -- Legality checks for library unit pragmas. A special case arises for
641 -- pragmas in generic instances that come from copies of the original
642 -- library unit pragmas in the generic templates. In the case of other
643 -- than library level instantiations these can appear in contexts which
644 -- would normally be invalid (they only apply to the original template
645 -- and to library level instantiations), and they are simply ignored,
646 -- which is implemented by rewriting them as null statements.
648 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
649 -- Check an Unchecked_Union variant for lack of nested variants and
650 -- presence of at least one component. UU_Typ is the related Unchecked_
653 procedure Error_Pragma (Msg : String);
654 pragma No_Return (Error_Pragma);
655 -- Outputs error message for current pragma. The message contains a %
656 -- that will be replaced with the pragma name, and the flag is placed
657 -- on the pragma itself. Pragma_Exit is then raised.
659 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
660 pragma No_Return (Error_Pragma_Arg);
661 -- Outputs error message for current pragma. The message may contain
662 -- a % that will be replaced with the pragma name. The parameter Arg
663 -- may either be a pragma argument association, in which case the flag
664 -- is placed on the expression of this association, or an expression,
665 -- in which case the flag is placed directly on the expression. The
666 -- message is placed using Error_Msg_N, so the message may also contain
667 -- an & insertion character which will reference the given Arg value.
668 -- After placing the message, Pragma_Exit is raised.
670 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
671 pragma No_Return (Error_Pragma_Arg);
672 -- Similar to above form of Error_Pragma_Arg except that two messages
673 -- are provided, the second is a continuation comment starting with \.
675 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
676 pragma No_Return (Error_Pragma_Arg_Ident);
677 -- Outputs error message for current pragma. The message may contain
678 -- a % that will be replaced with the pragma name. The parameter Arg
679 -- must be a pragma argument association with a non-empty identifier
680 -- (i.e. its Chars field must be set), and the error message is placed
681 -- on the identifier. The message is placed using Error_Msg_N so
682 -- the message may also contain an & insertion character which will
683 -- reference the identifier. After placing the message, Pragma_Exit
686 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
687 pragma No_Return (Error_Pragma_Ref);
688 -- Outputs error message for current pragma. The message may contain
689 -- a % that will be replaced with the pragma name. The parameter Ref
690 -- must be an entity whose name can be referenced by & and sloc by #.
691 -- After placing the message, Pragma_Exit is raised.
693 function Find_Lib_Unit_Name return Entity_Id;
694 -- Used for a library unit pragma to find the entity to which the
695 -- library unit pragma applies, returns the entity found.
697 procedure Find_Program_Unit_Name (Id : Node_Id);
698 -- If the pragma is a compilation unit pragma, the id must denote the
699 -- compilation unit in the same compilation, and the pragma must appear
700 -- in the list of preceding or trailing pragmas. If it is a program
701 -- unit pragma that is not a compilation unit pragma, then the
702 -- identifier must be visible.
704 function Find_Unique_Parameterless_Procedure
706 Arg : Node_Id) return Entity_Id;
707 -- Used for a procedure pragma to find the unique parameterless
708 -- procedure identified by Name, returns it if it exists, otherwise
709 -- errors out and uses Arg as the pragma argument for the message.
711 procedure Fix_Error (Msg : in out String);
712 -- This is called prior to issuing an error message. Msg is a string
713 -- that typically contains the substring "pragma". If the current pragma
714 -- comes from an aspect, each such "pragma" substring is replaced with
715 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
716 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
718 procedure Gather_Associations
720 Args : out Args_List);
721 -- This procedure is used to gather the arguments for a pragma that
722 -- permits arbitrary ordering of parameters using the normal rules
723 -- for named and positional parameters. The Names argument is a list
724 -- of Name_Id values that corresponds to the allowed pragma argument
725 -- association identifiers in order. The result returned in Args is
726 -- a list of corresponding expressions that are the pragma arguments.
727 -- Note that this is a list of expressions, not of pragma argument
728 -- associations (Gather_Associations has completely checked all the
729 -- optional identifiers when it returns). An entry in Args is Empty
730 -- on return if the corresponding argument is not present.
732 procedure GNAT_Pragma;
733 -- Called for all GNAT defined pragmas to check the relevant restriction
734 -- (No_Implementation_Pragmas).
736 function Is_Before_First_Decl
737 (Pragma_Node : Node_Id;
738 Decls : List_Id) return Boolean;
739 -- Return True if Pragma_Node is before the first declarative item in
740 -- Decls where Decls is the list of declarative items.
742 function Is_Configuration_Pragma return Boolean;
743 -- Determines if the placement of the current pragma is appropriate
744 -- for a configuration pragma.
746 function Is_In_Context_Clause return Boolean;
747 -- Returns True if pragma appears within the context clause of a unit,
748 -- and False for any other placement (does not generate any messages).
750 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
751 -- Analyzes the argument, and determines if it is a static string
752 -- expression, returns True if so, False if non-static or not String.
754 procedure Pragma_Misplaced;
755 pragma No_Return (Pragma_Misplaced);
756 -- Issue fatal error message for misplaced pragma
758 procedure Process_Atomic_Shared_Volatile;
759 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
760 -- Shared is an obsolete Ada 83 pragma, treated as being identical
761 -- in effect to pragma Atomic.
763 procedure Process_Compile_Time_Warning_Or_Error;
764 -- Common processing for Compile_Time_Error and Compile_Time_Warning
766 procedure Process_Convention
767 (C : out Convention_Id;
768 Ent : out Entity_Id);
769 -- Common processing for Convention, Interface, Import and Export.
770 -- Checks first two arguments of pragma, and sets the appropriate
771 -- convention value in the specified entity or entities. On return
772 -- C is the convention, Ent is the referenced entity.
774 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
775 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
776 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
778 procedure Process_Extended_Import_Export_Exception_Pragma
779 (Arg_Internal : Node_Id;
780 Arg_External : Node_Id;
783 -- Common processing for the pragmas Import/Export_Exception. The three
784 -- arguments correspond to the three named parameters of the pragma. An
785 -- argument is empty if the corresponding parameter is not present in
788 procedure Process_Extended_Import_Export_Object_Pragma
789 (Arg_Internal : Node_Id;
790 Arg_External : Node_Id;
792 -- Common processing for the pragmas Import/Export_Object. The three
793 -- arguments correspond to the three named parameters of the pragmas. An
794 -- argument is empty if the corresponding parameter is not present in
797 procedure Process_Extended_Import_Export_Internal_Arg
798 (Arg_Internal : Node_Id := Empty);
799 -- Common processing for all extended Import and Export pragmas. The
800 -- argument is the pragma parameter for the Internal argument. If
801 -- Arg_Internal is empty or inappropriate, an error message is posted.
802 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
803 -- set to identify the referenced entity.
805 procedure Process_Extended_Import_Export_Subprogram_Pragma
806 (Arg_Internal : Node_Id;
807 Arg_External : Node_Id;
808 Arg_Parameter_Types : Node_Id;
809 Arg_Result_Type : Node_Id := Empty;
810 Arg_Mechanism : Node_Id;
811 Arg_Result_Mechanism : Node_Id := Empty;
812 Arg_First_Optional_Parameter : Node_Id := Empty);
813 -- Common processing for all extended Import and Export pragmas applying
814 -- to subprograms. The caller omits any arguments that do not apply to
815 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
816 -- only in the Import_Function and Export_Function cases). The argument
817 -- names correspond to the allowed pragma association identifiers.
819 procedure Process_Generic_List;
820 -- Common processing for Share_Generic and Inline_Generic
822 procedure Process_Import_Or_Interface;
823 -- Common processing for Import of Interface
825 procedure Process_Import_Predefined_Type;
826 -- Processing for completing a type with pragma Import. This is used
827 -- to declare types that match predefined C types, especially for cases
828 -- without corresponding Ada predefined type.
830 procedure Process_Inline (Active : Boolean);
831 -- Common processing for Inline and Inline_Always. The parameter
832 -- indicates if the inline pragma is active, i.e. if it should actually
833 -- cause inlining to occur.
835 procedure Process_Interface_Name
836 (Subprogram_Def : Entity_Id;
839 -- Given the last two arguments of pragma Import, pragma Export, or
840 -- pragma Interface_Name, performs validity checks and sets the
841 -- Interface_Name field of the given subprogram entity to the
842 -- appropriate external or link name, depending on the arguments given.
843 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
844 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
845 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
846 -- nor Link_Arg is present, the interface name is set to the default
847 -- from the subprogram name.
849 procedure Process_Interrupt_Or_Attach_Handler;
850 -- Common processing for Interrupt and Attach_Handler pragmas
852 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
853 -- Common processing for Restrictions and Restriction_Warnings pragmas.
854 -- Warn is True for Restriction_Warnings, or for Restrictions if the
855 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
856 -- is not set in the Restrictions case.
858 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
859 -- Common processing for Suppress and Unsuppress. The boolean parameter
860 -- Suppress_Case is True for the Suppress case, and False for the
863 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
864 -- This procedure sets the Is_Exported flag for the given entity,
865 -- checking that the entity was not previously imported. Arg is
866 -- the argument that specified the entity. A check is also made
867 -- for exporting inappropriate entities.
869 procedure Set_Extended_Import_Export_External_Name
870 (Internal_Ent : Entity_Id;
871 Arg_External : Node_Id);
872 -- Common processing for all extended import export pragmas. The first
873 -- argument, Internal_Ent, is the internal entity, which has already
874 -- been checked for validity by the caller. Arg_External is from the
875 -- Import or Export pragma, and may be null if no External parameter
876 -- was present. If Arg_External is present and is a non-null string
877 -- (a null string is treated as the default), then the Interface_Name
878 -- field of Internal_Ent is set appropriately.
880 procedure Set_Imported (E : Entity_Id);
881 -- This procedure sets the Is_Imported flag for the given entity,
882 -- checking that it is not previously exported or imported.
884 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
885 -- Mech is a parameter passing mechanism (see Import_Function syntax
886 -- for MECHANISM_NAME). This routine checks that the mechanism argument
887 -- has the right form, and if not issues an error message. If the
888 -- argument has the right form then the Mechanism field of Ent is
889 -- set appropriately.
891 procedure Set_Ravenscar_Profile (N : Node_Id);
892 -- Activate the set of configuration pragmas and restrictions that make
893 -- up the Ravenscar Profile. N is the corresponding pragma node, which
894 -- is used for error messages on any constructs that violate the
897 ---------------------
898 -- Ada_2005_Pragma --
899 ---------------------
901 procedure Ada_2005_Pragma is
903 if Ada_Version <= Ada_95 then
904 Check_Restriction (No_Implementation_Pragmas, N);
908 ---------------------
909 -- Ada_2012_Pragma --
910 ---------------------
912 procedure Ada_2012_Pragma is
914 if Ada_Version <= Ada_2005 then
915 Check_Restriction (No_Implementation_Pragmas, N);
919 --------------------------
920 -- Check_Ada_83_Warning --
921 --------------------------
923 procedure Check_Ada_83_Warning is
925 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
926 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
928 end Check_Ada_83_Warning;
930 ---------------------
931 -- Check_Arg_Count --
932 ---------------------
934 procedure Check_Arg_Count (Required : Nat) is
936 if Arg_Count /= Required then
937 Error_Pragma ("wrong number of arguments for pragma%");
941 --------------------------------
942 -- Check_Arg_Is_External_Name --
943 --------------------------------
945 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
946 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
949 if Nkind (Argx) = N_Identifier then
953 Analyze_And_Resolve (Argx, Standard_String);
955 if Is_OK_Static_Expression (Argx) then
958 elsif Etype (Argx) = Any_Type then
961 -- An interesting special case, if we have a string literal and
962 -- we are in Ada 83 mode, then we allow it even though it will
963 -- not be flagged as static. This allows expected Ada 83 mode
964 -- use of external names which are string literals, even though
965 -- technically these are not static in Ada 83.
967 elsif Ada_Version = Ada_83
968 and then Nkind (Argx) = N_String_Literal
972 -- Static expression that raises Constraint_Error. This has
973 -- already been flagged, so just exit from pragma processing.
975 elsif Is_Static_Expression (Argx) then
978 -- Here we have a real error (non-static expression)
981 Error_Msg_Name_1 := Pname;
985 "argument for pragma% must be a identifier or "
986 & "static string expression!";
989 Flag_Non_Static_Expr (Msg, Argx);
994 end Check_Arg_Is_External_Name;
996 -----------------------------
997 -- Check_Arg_Is_Identifier --
998 -----------------------------
1000 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
1001 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1003 if Nkind (Argx) /= N_Identifier then
1005 ("argument for pragma% must be identifier", Argx);
1007 end Check_Arg_Is_Identifier;
1009 ----------------------------------
1010 -- Check_Arg_Is_Integer_Literal --
1011 ----------------------------------
1013 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1014 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1016 if Nkind (Argx) /= N_Integer_Literal then
1018 ("argument for pragma% must be integer literal", Argx);
1020 end Check_Arg_Is_Integer_Literal;
1022 -------------------------------------------
1023 -- Check_Arg_Is_Library_Level_Local_Name --
1024 -------------------------------------------
1028 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1029 -- | library_unit_NAME
1031 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1033 Check_Arg_Is_Local_Name (Arg);
1035 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1036 and then Comes_From_Source (N)
1039 ("argument for pragma% must be library level entity", Arg);
1041 end Check_Arg_Is_Library_Level_Local_Name;
1043 -----------------------------
1044 -- Check_Arg_Is_Local_Name --
1045 -----------------------------
1049 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1050 -- | library_unit_NAME
1052 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1053 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1058 if Nkind (Argx) not in N_Direct_Name
1059 and then (Nkind (Argx) /= N_Attribute_Reference
1060 or else Present (Expressions (Argx))
1061 or else Nkind (Prefix (Argx)) /= N_Identifier)
1062 and then (not Is_Entity_Name (Argx)
1063 or else not Is_Compilation_Unit (Entity (Argx)))
1065 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1068 -- No further check required if not an entity name
1070 if not Is_Entity_Name (Argx) then
1076 Ent : constant Entity_Id := Entity (Argx);
1077 Scop : constant Entity_Id := Scope (Ent);
1079 -- Case of a pragma applied to a compilation unit: pragma must
1080 -- occur immediately after the program unit in the compilation.
1082 if Is_Compilation_Unit (Ent) then
1084 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1087 -- Case of pragma placed immediately after spec
1089 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1092 -- Case of pragma placed immediately after body
1094 elsif Nkind (Decl) = N_Subprogram_Declaration
1095 and then Present (Corresponding_Body (Decl))
1099 (Parent (Unit_Declaration_Node
1100 (Corresponding_Body (Decl))));
1102 -- All other cases are illegal
1109 -- Special restricted placement rule from 10.2.1(11.8/2)
1111 elsif Is_Generic_Formal (Ent)
1112 and then Prag_Id = Pragma_Preelaborable_Initialization
1114 OK := List_Containing (N) =
1115 Generic_Formal_Declarations
1116 (Unit_Declaration_Node (Scop));
1118 -- Default case, just check that the pragma occurs in the scope
1119 -- of the entity denoted by the name.
1122 OK := Current_Scope = Scop;
1127 ("pragma% argument must be in same declarative part", Arg);
1131 end Check_Arg_Is_Local_Name;
1133 ---------------------------------
1134 -- Check_Arg_Is_Locking_Policy --
1135 ---------------------------------
1137 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1138 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1141 Check_Arg_Is_Identifier (Argx);
1143 if not Is_Locking_Policy_Name (Chars (Argx)) then
1144 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1146 end Check_Arg_Is_Locking_Policy;
1148 -------------------------
1149 -- Check_Arg_Is_One_Of --
1150 -------------------------
1152 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1153 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1156 Check_Arg_Is_Identifier (Argx);
1158 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1159 Error_Msg_Name_2 := N1;
1160 Error_Msg_Name_3 := N2;
1161 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1163 end Check_Arg_Is_One_Of;
1165 procedure Check_Arg_Is_One_Of
1167 N1, N2, N3 : Name_Id)
1169 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1172 Check_Arg_Is_Identifier (Argx);
1174 if Chars (Argx) /= N1
1175 and then Chars (Argx) /= N2
1176 and then Chars (Argx) /= N3
1178 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1180 end Check_Arg_Is_One_Of;
1182 procedure Check_Arg_Is_One_Of
1184 N1, N2, N3, N4 : Name_Id)
1186 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1189 Check_Arg_Is_Identifier (Argx);
1191 if Chars (Argx) /= N1
1192 and then Chars (Argx) /= N2
1193 and then Chars (Argx) /= N3
1194 and then Chars (Argx) /= N4
1196 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1198 end Check_Arg_Is_One_Of;
1200 procedure Check_Arg_Is_One_Of
1202 N1, N2, N3, N4, N5 : Name_Id)
1204 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1207 Check_Arg_Is_Identifier (Argx);
1209 if Chars (Argx) /= N1
1210 and then Chars (Argx) /= N2
1211 and then Chars (Argx) /= N3
1212 and then Chars (Argx) /= N4
1213 and then Chars (Argx) /= N5
1215 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1217 end Check_Arg_Is_One_Of;
1218 ---------------------------------
1219 -- Check_Arg_Is_Queuing_Policy --
1220 ---------------------------------
1222 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1223 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1226 Check_Arg_Is_Identifier (Argx);
1228 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1229 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1231 end Check_Arg_Is_Queuing_Policy;
1233 ------------------------------------
1234 -- Check_Arg_Is_Static_Expression --
1235 ------------------------------------
1237 procedure Check_Arg_Is_Static_Expression
1239 Typ : Entity_Id := Empty)
1242 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1243 end Check_Arg_Is_Static_Expression;
1245 ------------------------------------------
1246 -- Check_Arg_Is_Task_Dispatching_Policy --
1247 ------------------------------------------
1249 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1250 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1253 Check_Arg_Is_Identifier (Argx);
1255 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1257 ("& is not a valid task dispatching policy name", Argx);
1259 end Check_Arg_Is_Task_Dispatching_Policy;
1261 ---------------------
1262 -- Check_Arg_Order --
1263 ---------------------
1265 procedure Check_Arg_Order (Names : Name_List) is
1268 Highest_So_Far : Natural := 0;
1269 -- Highest index in Names seen do far
1273 for J in 1 .. Arg_Count loop
1274 if Chars (Arg) /= No_Name then
1275 for K in Names'Range loop
1276 if Chars (Arg) = Names (K) then
1277 if K < Highest_So_Far then
1278 Error_Msg_Name_1 := Pname;
1280 ("parameters out of order for pragma%", Arg);
1281 Error_Msg_Name_1 := Names (K);
1282 Error_Msg_Name_2 := Names (Highest_So_Far);
1283 Error_Msg_N ("\% must appear before %", Arg);
1287 Highest_So_Far := K;
1295 end Check_Arg_Order;
1297 --------------------------------
1298 -- Check_At_Least_N_Arguments --
1299 --------------------------------
1301 procedure Check_At_Least_N_Arguments (N : Nat) is
1303 if Arg_Count < N then
1304 Error_Pragma ("too few arguments for pragma%");
1306 end Check_At_Least_N_Arguments;
1308 -------------------------------
1309 -- Check_At_Most_N_Arguments --
1310 -------------------------------
1312 procedure Check_At_Most_N_Arguments (N : Nat) is
1315 if Arg_Count > N then
1317 for J in 1 .. N loop
1319 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1322 end Check_At_Most_N_Arguments;
1324 ---------------------
1325 -- Check_Component --
1326 ---------------------
1328 procedure Check_Component
1331 In_Variant_Part : Boolean := False)
1333 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1334 Sindic : constant Node_Id :=
1335 Subtype_Indication (Component_Definition (Comp));
1336 Typ : constant Entity_Id := Etype (Comp_Id);
1339 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1340 -- object constraint, then the component type shall be an Unchecked_
1343 if Nkind (Sindic) = N_Subtype_Indication
1344 and then Has_Per_Object_Constraint (Comp_Id)
1345 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1348 ("component subtype subject to per-object constraint " &
1349 "must be an Unchecked_Union", Comp);
1351 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1352 -- the body of a generic unit, or within the body of any of its
1353 -- descendant library units, no part of the type of a component
1354 -- declared in a variant_part of the unchecked union type shall be of
1355 -- a formal private type or formal private extension declared within
1356 -- the formal part of the generic unit.
1358 elsif Ada_Version >= Ada_2012
1359 and then In_Generic_Body (UU_Typ)
1360 and then In_Variant_Part
1361 and then Is_Private_Type (Typ)
1362 and then Is_Generic_Type (Typ)
1365 ("component of Unchecked_Union cannot be of generic type", Comp);
1367 elsif Needs_Finalization (Typ) then
1369 ("component of Unchecked_Union cannot be controlled", Comp);
1371 elsif Has_Task (Typ) then
1373 ("component of Unchecked_Union cannot have tasks", Comp);
1375 end Check_Component;
1377 ----------------------------
1378 -- Check_Duplicate_Pragma --
1379 ----------------------------
1381 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1385 -- Nothing to do if this pragma comes from an aspect specification,
1386 -- since we could not be duplicating a pragma, and we dealt with the
1387 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1389 if From_Aspect_Specification (N) then
1393 -- Otherwise current pragma may duplicate previous pragma or a
1394 -- previously given aspect specification for the same pragma.
1396 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1399 Error_Msg_Name_1 := Pragma_Name (N);
1400 Error_Msg_Sloc := Sloc (P);
1402 if Nkind (P) = N_Aspect_Specification
1403 or else From_Aspect_Specification (P)
1405 Error_Msg_NE ("aspect% for & previously given#", N, E);
1407 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1412 end Check_Duplicate_Pragma;
1414 ----------------------------------
1415 -- Check_Duplicated_Export_Name --
1416 ----------------------------------
1418 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1419 String_Val : constant String_Id := Strval (Nam);
1422 -- We are only interested in the export case, and in the case of
1423 -- generics, it is the instance, not the template, that is the
1424 -- problem (the template will generate a warning in any case).
1426 if not Inside_A_Generic
1427 and then (Prag_Id = Pragma_Export
1429 Prag_Id = Pragma_Export_Procedure
1431 Prag_Id = Pragma_Export_Valued_Procedure
1433 Prag_Id = Pragma_Export_Function)
1435 for J in Externals.First .. Externals.Last loop
1436 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1437 Error_Msg_Sloc := Sloc (Externals.Table (J));
1438 Error_Msg_N ("external name duplicates name given#", Nam);
1443 Externals.Append (Nam);
1445 end Check_Duplicated_Export_Name;
1447 -------------------------------------
1448 -- Check_Expr_Is_Static_Expression --
1449 -------------------------------------
1451 procedure Check_Expr_Is_Static_Expression
1453 Typ : Entity_Id := Empty)
1456 if Present (Typ) then
1457 Analyze_And_Resolve (Expr, Typ);
1459 Analyze_And_Resolve (Expr);
1462 if Is_OK_Static_Expression (Expr) then
1465 elsif Etype (Expr) = Any_Type then
1468 -- An interesting special case, if we have a string literal and we
1469 -- are in Ada 83 mode, then we allow it even though it will not be
1470 -- flagged as static. This allows the use of Ada 95 pragmas like
1471 -- Import in Ada 83 mode. They will of course be flagged with
1472 -- warnings as usual, but will not cause errors.
1474 elsif Ada_Version = Ada_83
1475 and then Nkind (Expr) = N_String_Literal
1479 -- Static expression that raises Constraint_Error. This has already
1480 -- been flagged, so just exit from pragma processing.
1482 elsif Is_Static_Expression (Expr) then
1485 -- Finally, we have a real error
1488 Error_Msg_Name_1 := Pname;
1492 "argument for pragma% must be a static expression!";
1495 Flag_Non_Static_Expr (Msg, Expr);
1500 end Check_Expr_Is_Static_Expression;
1502 -------------------------
1503 -- Check_First_Subtype --
1504 -------------------------
1506 procedure Check_First_Subtype (Arg : Node_Id) is
1507 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1508 Ent : constant Entity_Id := Entity (Argx);
1511 if Is_First_Subtype (Ent) then
1514 elsif Is_Type (Ent) then
1516 ("pragma% cannot apply to subtype", Argx);
1518 elsif Is_Object (Ent) then
1520 ("pragma% cannot apply to object, requires a type", Argx);
1524 ("pragma% cannot apply to&, requires a type", Argx);
1526 end Check_First_Subtype;
1528 ----------------------
1529 -- Check_Identifier --
1530 ----------------------
1532 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1535 and then Nkind (Arg) = N_Pragma_Argument_Association
1537 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1538 Error_Msg_Name_1 := Pname;
1539 Error_Msg_Name_2 := Id;
1540 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1544 end Check_Identifier;
1546 --------------------------------
1547 -- Check_Identifier_Is_One_Of --
1548 --------------------------------
1550 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1553 and then Nkind (Arg) = N_Pragma_Argument_Association
1555 if Chars (Arg) = No_Name then
1556 Error_Msg_Name_1 := Pname;
1557 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1560 elsif Chars (Arg) /= N1
1561 and then Chars (Arg) /= N2
1563 Error_Msg_Name_1 := Pname;
1564 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1568 end Check_Identifier_Is_One_Of;
1570 ---------------------------
1571 -- Check_In_Main_Program --
1572 ---------------------------
1574 procedure Check_In_Main_Program is
1575 P : constant Node_Id := Parent (N);
1578 -- Must be at in subprogram body
1580 if Nkind (P) /= N_Subprogram_Body then
1581 Error_Pragma ("% pragma allowed only in subprogram");
1583 -- Otherwise warn if obviously not main program
1585 elsif Present (Parameter_Specifications (Specification (P)))
1586 or else not Is_Compilation_Unit (Defining_Entity (P))
1588 Error_Msg_Name_1 := Pname;
1590 ("?pragma% is only effective in main program", N);
1592 end Check_In_Main_Program;
1594 ---------------------------------------
1595 -- Check_Interrupt_Or_Attach_Handler --
1596 ---------------------------------------
1598 procedure Check_Interrupt_Or_Attach_Handler is
1599 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1600 Handler_Proc, Proc_Scope : Entity_Id;
1605 if Prag_Id = Pragma_Interrupt_Handler then
1606 Check_Restriction (No_Dynamic_Attachment, N);
1609 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1610 Proc_Scope := Scope (Handler_Proc);
1612 -- On AAMP only, a pragma Interrupt_Handler is supported for
1613 -- nonprotected parameterless procedures.
1615 if not AAMP_On_Target
1616 or else Prag_Id = Pragma_Attach_Handler
1618 if Ekind (Proc_Scope) /= E_Protected_Type then
1620 ("argument of pragma% must be protected procedure", Arg1);
1623 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1624 Error_Pragma ("pragma% must be in protected definition");
1628 if not Is_Library_Level_Entity (Proc_Scope)
1629 or else (AAMP_On_Target
1630 and then not Is_Library_Level_Entity (Handler_Proc))
1633 ("argument for pragma% must be library level entity", Arg1);
1636 -- AI05-0033: A pragma cannot appear within a generic body, because
1637 -- instance can be in a nested scope. The check that protected type
1638 -- is itself a library-level declaration is done elsewhere.
1640 -- Note: we omit this check in Codepeer mode to properly handle code
1641 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1643 if Inside_A_Generic then
1644 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1645 and then In_Package_Body (Scope (Current_Scope))
1646 and then not CodePeer_Mode
1648 Error_Pragma ("pragma% cannot be used inside a generic");
1651 end Check_Interrupt_Or_Attach_Handler;
1653 -------------------------------------------
1654 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1655 -------------------------------------------
1657 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1666 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1669 elsif Nkind_In (P, N_Package_Specification,
1674 -- Note: the following tests seem a little peculiar, because
1675 -- they test for bodies, but if we were in the statement part
1676 -- of the body, we would already have hit the handled statement
1677 -- sequence, so the only way we get here is by being in the
1678 -- declarative part of the body.
1680 elsif Nkind_In (P, N_Subprogram_Body,
1691 Error_Pragma ("pragma% is not in declarative part or package spec");
1692 end Check_Is_In_Decl_Part_Or_Package_Spec;
1694 -------------------------
1695 -- Check_No_Identifier --
1696 -------------------------
1698 procedure Check_No_Identifier (Arg : Node_Id) is
1700 if Nkind (Arg) = N_Pragma_Argument_Association
1701 and then Chars (Arg) /= No_Name
1703 Error_Pragma_Arg_Ident
1704 ("pragma% does not permit identifier& here", Arg);
1706 end Check_No_Identifier;
1708 --------------------------
1709 -- Check_No_Identifiers --
1710 --------------------------
1712 procedure Check_No_Identifiers is
1715 if Arg_Count > 0 then
1717 while Present (Arg_Node) loop
1718 Check_No_Identifier (Arg_Node);
1722 end Check_No_Identifiers;
1724 ------------------------
1725 -- Check_No_Link_Name --
1726 ------------------------
1728 procedure Check_No_Link_Name is
1731 and then Chars (Arg3) = Name_Link_Name
1736 if Present (Arg4) then
1738 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1740 end Check_No_Link_Name;
1742 -------------------------------
1743 -- Check_Optional_Identifier --
1744 -------------------------------
1746 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1749 and then Nkind (Arg) = N_Pragma_Argument_Association
1750 and then Chars (Arg) /= No_Name
1752 if Chars (Arg) /= Id then
1753 Error_Msg_Name_1 := Pname;
1754 Error_Msg_Name_2 := Id;
1755 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1759 end Check_Optional_Identifier;
1761 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1763 Name_Buffer (1 .. Id'Length) := Id;
1764 Name_Len := Id'Length;
1765 Check_Optional_Identifier (Arg, Name_Find);
1766 end Check_Optional_Identifier;
1768 --------------------------------------
1769 -- Check_Precondition_Postcondition --
1770 --------------------------------------
1772 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1776 procedure Chain_PPC (PO : Node_Id);
1777 -- If PO is an entry or a [generic] subprogram declaration node, then
1778 -- the precondition/postcondition applies to this subprogram and the
1779 -- processing for the pragma is completed. Otherwise the pragma is
1786 procedure Chain_PPC (PO : Node_Id) is
1791 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1792 if not From_Aspect_Specification (N) then
1794 ("pragma% cannot be applied to abstract subprogram");
1796 elsif Class_Present (N) then
1801 ("aspect % requires ''Class for abstract subprogram");
1804 -- AI05-0230: The same restriction applies to null procedures. For
1805 -- compatibility with earlier uses of the Ada pragma, apply this
1806 -- rule only to aspect specifications.
1808 -- The above discrpency needs documentation. Robert is dubious
1809 -- about whether it is a good idea ???
1811 elsif Nkind (PO) = N_Subprogram_Declaration
1812 and then Nkind (Specification (PO)) = N_Procedure_Specification
1813 and then Null_Present (Specification (PO))
1814 and then From_Aspect_Specification (N)
1815 and then not Class_Present (N)
1818 ("aspect % requires ''Class for null procedure");
1820 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1821 N_Generic_Subprogram_Declaration,
1822 N_Entry_Declaration)
1827 -- Here if we have [generic] subprogram or entry declaration
1829 if Nkind (PO) = N_Entry_Declaration then
1830 S := Defining_Entity (PO);
1832 S := Defining_Unit_Name (Specification (PO));
1835 -- Make sure we do not have the case of a precondition pragma when
1836 -- the Pre'Class aspect is present.
1838 -- We do this by looking at pragmas already chained to the entity
1839 -- since the aspect derived pragma will be put on this list first.
1841 if Pragma_Name (N) = Name_Precondition then
1842 if not From_Aspect_Specification (N) then
1843 P := Spec_PPC_List (Contract (S));
1844 while Present (P) loop
1845 if Pragma_Name (P) = Name_Precondition
1846 and then From_Aspect_Specification (P)
1847 and then Class_Present (P)
1849 Error_Msg_Sloc := Sloc (P);
1851 ("pragma% not allowed, `Pre''Class` aspect given#");
1854 P := Next_Pragma (P);
1859 -- Similarly check for Pre with inherited Pre'Class. Note that
1860 -- we cover the aspect case as well here.
1862 if Pragma_Name (N) = Name_Precondition
1863 and then not Class_Present (N)
1866 Inherited : constant Subprogram_List :=
1867 Inherited_Subprograms (S);
1871 for J in Inherited'Range loop
1872 P := Spec_PPC_List (Contract (Inherited (J)));
1873 while Present (P) loop
1874 if Pragma_Name (P) = Name_Precondition
1875 and then Class_Present (P)
1877 Error_Msg_Sloc := Sloc (P);
1879 ("pragma% not allowed, `Pre''Class` "
1880 & "aspect inherited from#");
1883 P := Next_Pragma (P);
1889 -- Note: we do not analyze the pragma at this point. Instead we
1890 -- delay this analysis until the end of the declarative part in
1891 -- which the pragma appears. This implements the required delay
1892 -- in this analysis, allowing forward references. The analysis
1893 -- happens at the end of Analyze_Declarations.
1895 -- Chain spec PPC pragma to list for subprogram
1897 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1898 Set_Spec_PPC_List (Contract (S), N);
1900 -- Return indicating spec case
1906 -- Start of processing for Check_Precondition_Postcondition
1909 if not Is_List_Member (N) then
1913 -- Preanalyze message argument if present. Visibility in this
1914 -- argument is established at the point of pragma occurrence.
1916 if Arg_Count = 2 then
1917 Check_Optional_Identifier (Arg2, Name_Message);
1918 Preanalyze_Spec_Expression
1919 (Get_Pragma_Arg (Arg2), Standard_String);
1922 -- Record if pragma is disabled
1924 if Check_Enabled (Pname) then
1925 Set_SCO_Pragma_Enabled (Loc);
1928 -- If we are within an inlined body, the legality of the pragma
1929 -- has been checked already.
1931 if In_Inlined_Body then
1936 -- Search prior declarations
1939 while Present (Prev (P)) loop
1942 -- If the previous node is a generic subprogram, do not go to to
1943 -- the original node, which is the unanalyzed tree: we need to
1944 -- attach the pre/postconditions to the analyzed version at this
1945 -- point. They get propagated to the original tree when analyzing
1946 -- the corresponding body.
1948 if Nkind (P) not in N_Generic_Declaration then
1949 PO := Original_Node (P);
1954 -- Skip past prior pragma
1956 if Nkind (PO) = N_Pragma then
1959 -- Skip stuff not coming from source
1961 elsif not Comes_From_Source (PO) then
1963 -- The condition may apply to a subprogram instantiation
1965 if Nkind (PO) = N_Subprogram_Declaration
1966 and then Present (Generic_Parent (Specification (PO)))
1971 elsif Nkind (PO) = N_Subprogram_Declaration
1972 and then In_Instance
1977 -- For all other cases of non source code, do nothing
1983 -- Only remaining possibility is subprogram declaration
1991 -- If we fall through loop, pragma is at start of list, so see if it
1992 -- is at the start of declarations of a subprogram body.
1994 if Nkind (Parent (N)) = N_Subprogram_Body
1995 and then List_Containing (N) = Declarations (Parent (N))
1997 if Operating_Mode /= Generate_Code
1998 or else Inside_A_Generic
2000 -- Analyze pragma expression for correctness and for ASIS use
2002 Preanalyze_Spec_Expression
2003 (Get_Pragma_Arg (Arg1), Standard_Boolean);
2005 -- In ASIS mode, for a pragma generated from a source aspect,
2006 -- also analyze the original aspect expression.
2009 and then Present (Corresponding_Aspect (N))
2011 Preanalyze_Spec_Expression
2012 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2019 -- See if it is in the pragmas after a library level subprogram
2021 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2023 -- In formal verification mode, analyze pragma expression for
2024 -- correctness, as it is not expanded later.
2027 Analyze_PPC_In_Decl_Part
2028 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2031 Chain_PPC (Unit (Parent (Parent (N))));
2035 -- If we fall through, pragma was misplaced
2038 end Check_Precondition_Postcondition;
2040 -----------------------------
2041 -- Check_Static_Constraint --
2042 -----------------------------
2044 -- Note: for convenience in writing this procedure, in addition to
2045 -- the officially (i.e. by spec) allowed argument which is always a
2046 -- constraint, it also allows ranges and discriminant associations.
2047 -- Above is not clear ???
2049 procedure Check_Static_Constraint (Constr : Node_Id) is
2051 procedure Require_Static (E : Node_Id);
2052 -- Require given expression to be static expression
2054 --------------------
2055 -- Require_Static --
2056 --------------------
2058 procedure Require_Static (E : Node_Id) is
2060 if not Is_OK_Static_Expression (E) then
2061 Flag_Non_Static_Expr
2062 ("non-static constraint not allowed in Unchecked_Union!", E);
2067 -- Start of processing for Check_Static_Constraint
2070 case Nkind (Constr) is
2071 when N_Discriminant_Association =>
2072 Require_Static (Expression (Constr));
2075 Require_Static (Low_Bound (Constr));
2076 Require_Static (High_Bound (Constr));
2078 when N_Attribute_Reference =>
2079 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2080 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2082 when N_Range_Constraint =>
2083 Check_Static_Constraint (Range_Expression (Constr));
2085 when N_Index_Or_Discriminant_Constraint =>
2089 IDC := First (Constraints (Constr));
2090 while Present (IDC) loop
2091 Check_Static_Constraint (IDC);
2099 end Check_Static_Constraint;
2101 ---------------------
2102 -- Check_Test_Case --
2103 ---------------------
2105 procedure Check_Test_Case is
2109 procedure Chain_TC (PO : Node_Id);
2110 -- If PO is a [generic] subprogram declaration node, then the
2111 -- test-case applies to this subprogram and the processing for the
2112 -- pragma is completed. Otherwise the pragma is misplaced.
2118 procedure Chain_TC (PO : Node_Id) is
2122 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2123 if From_Aspect_Specification (N) then
2125 ("aspect% cannot be applied to abstract subprogram");
2128 ("pragma% cannot be applied to abstract subprogram");
2131 elsif Nkind (PO) = N_Entry_Declaration then
2132 if From_Aspect_Specification (N) then
2133 Error_Pragma ("aspect% cannot be applied to entry");
2135 Error_Pragma ("pragma% cannot be applied to entry");
2138 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2139 N_Generic_Subprogram_Declaration)
2144 -- Here if we have [generic] subprogram declaration
2146 S := Defining_Unit_Name (Specification (PO));
2148 -- Note: we do not analyze the pragma at this point. Instead we
2149 -- delay this analysis until the end of the declarative part in
2150 -- which the pragma appears. This implements the required delay
2151 -- in this analysis, allowing forward references. The analysis
2152 -- happens at the end of Analyze_Declarations.
2154 -- There should not be another test case with the same name
2155 -- associated to this subprogram.
2158 Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2162 TC := Spec_TC_List (Contract (S));
2163 while Present (TC) loop
2166 (Name, Get_Name_From_Test_Case_Pragma (TC))
2168 Error_Msg_Sloc := Sloc (TC);
2170 if From_Aspect_Specification (N) then
2171 Error_Pragma ("name for aspect% is already used#");
2173 Error_Pragma ("name for pragma% is already used#");
2177 TC := Next_Pragma (TC);
2181 -- Chain spec TC pragma to list for subprogram
2183 Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2184 Set_Spec_TC_List (Contract (S), N);
2187 -- Start of processing for Check_Test_Case
2190 if not Is_List_Member (N) then
2194 -- Test cases should only appear in package spec unit
2196 if Get_Source_Unit (N) = No_Unit
2197 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2198 N_Package_Declaration,
2199 N_Generic_Package_Declaration)
2204 -- Search prior declarations
2207 while Present (Prev (P)) loop
2210 -- If the previous node is a generic subprogram, do not go to to
2211 -- the original node, which is the unanalyzed tree: we need to
2212 -- attach the test-case to the analyzed version at this point.
2213 -- They get propagated to the original tree when analyzing the
2214 -- corresponding body.
2216 if Nkind (P) not in N_Generic_Declaration then
2217 PO := Original_Node (P);
2222 -- Skip past prior pragma
2224 if Nkind (PO) = N_Pragma then
2227 -- Skip stuff not coming from source
2229 elsif not Comes_From_Source (PO) then
2232 -- Only remaining possibility is subprogram declaration. First
2233 -- check that it is declared directly in a package declaration.
2234 -- This may be either the package declaration for the current unit
2235 -- being defined or a local package declaration.
2237 elsif not Present (Parent (Parent (PO)))
2238 or else not Present (Parent (Parent (Parent (PO))))
2239 or else not Nkind_In (Parent (Parent (PO)),
2240 N_Package_Declaration,
2241 N_Generic_Package_Declaration)
2251 -- If we fall through, pragma was misplaced
2254 end Check_Test_Case;
2256 --------------------------------------
2257 -- Check_Valid_Configuration_Pragma --
2258 --------------------------------------
2260 -- A configuration pragma must appear in the context clause of a
2261 -- compilation unit, and only other pragmas may precede it. Note that
2262 -- the test also allows use in a configuration pragma file.
2264 procedure Check_Valid_Configuration_Pragma is
2266 if not Is_Configuration_Pragma then
2267 Error_Pragma ("incorrect placement for configuration pragma%");
2269 end Check_Valid_Configuration_Pragma;
2271 -------------------------------------
2272 -- Check_Valid_Library_Unit_Pragma --
2273 -------------------------------------
2275 procedure Check_Valid_Library_Unit_Pragma is
2277 Parent_Node : Node_Id;
2278 Unit_Name : Entity_Id;
2279 Unit_Kind : Node_Kind;
2280 Unit_Node : Node_Id;
2281 Sindex : Source_File_Index;
2284 if not Is_List_Member (N) then
2288 Plist := List_Containing (N);
2289 Parent_Node := Parent (Plist);
2291 if Parent_Node = Empty then
2294 -- Case of pragma appearing after a compilation unit. In this case
2295 -- it must have an argument with the corresponding name and must
2296 -- be part of the following pragmas of its parent.
2298 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2299 if Plist /= Pragmas_After (Parent_Node) then
2302 elsif Arg_Count = 0 then
2304 ("argument required if outside compilation unit");
2307 Check_No_Identifiers;
2308 Check_Arg_Count (1);
2309 Unit_Node := Unit (Parent (Parent_Node));
2310 Unit_Kind := Nkind (Unit_Node);
2312 Analyze (Get_Pragma_Arg (Arg1));
2314 if Unit_Kind = N_Generic_Subprogram_Declaration
2315 or else Unit_Kind = N_Subprogram_Declaration
2317 Unit_Name := Defining_Entity (Unit_Node);
2319 elsif Unit_Kind in N_Generic_Instantiation then
2320 Unit_Name := Defining_Entity (Unit_Node);
2323 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2326 if Chars (Unit_Name) /=
2327 Chars (Entity (Get_Pragma_Arg (Arg1)))
2330 ("pragma% argument is not current unit name", Arg1);
2333 if Ekind (Unit_Name) = E_Package
2334 and then Present (Renamed_Entity (Unit_Name))
2336 Error_Pragma ("pragma% not allowed for renamed package");
2340 -- Pragma appears other than after a compilation unit
2343 -- Here we check for the generic instantiation case and also
2344 -- for the case of processing a generic formal package. We
2345 -- detect these cases by noting that the Sloc on the node
2346 -- does not belong to the current compilation unit.
2348 Sindex := Source_Index (Current_Sem_Unit);
2350 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2351 Rewrite (N, Make_Null_Statement (Loc));
2354 -- If before first declaration, the pragma applies to the
2355 -- enclosing unit, and the name if present must be this name.
2357 elsif Is_Before_First_Decl (N, Plist) then
2358 Unit_Node := Unit_Declaration_Node (Current_Scope);
2359 Unit_Kind := Nkind (Unit_Node);
2361 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2364 elsif Unit_Kind = N_Subprogram_Body
2365 and then not Acts_As_Spec (Unit_Node)
2369 elsif Nkind (Parent_Node) = N_Package_Body then
2372 elsif Nkind (Parent_Node) = N_Package_Specification
2373 and then Plist = Private_Declarations (Parent_Node)
2377 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2378 or else Nkind (Parent_Node) =
2379 N_Generic_Subprogram_Declaration)
2380 and then Plist = Generic_Formal_Declarations (Parent_Node)
2384 elsif Arg_Count > 0 then
2385 Analyze (Get_Pragma_Arg (Arg1));
2387 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2389 ("name in pragma% must be enclosing unit", Arg1);
2392 -- It is legal to have no argument in this context
2398 -- Error if not before first declaration. This is because a
2399 -- library unit pragma argument must be the name of a library
2400 -- unit (RM 10.1.5(7)), but the only names permitted in this
2401 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2402 -- generic subprogram declarations or generic instantiations.
2406 ("pragma% misplaced, must be before first declaration");
2410 end Check_Valid_Library_Unit_Pragma;
2416 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2417 Clist : constant Node_Id := Component_List (Variant);
2421 if not Is_Non_Empty_List (Component_Items (Clist)) then
2423 ("Unchecked_Union may not have empty component list",
2428 Comp := First (Component_Items (Clist));
2429 while Present (Comp) loop
2430 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2439 procedure Error_Pragma (Msg : String) is
2440 MsgF : String := Msg;
2442 Error_Msg_Name_1 := Pname;
2444 Error_Msg_N (MsgF, N);
2448 ----------------------
2449 -- Error_Pragma_Arg --
2450 ----------------------
2452 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2453 MsgF : String := Msg;
2455 Error_Msg_Name_1 := Pname;
2457 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2459 end Error_Pragma_Arg;
2461 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2462 MsgF : String := Msg1;
2464 Error_Msg_Name_1 := Pname;
2466 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2467 Error_Pragma_Arg (Msg2, Arg);
2468 end Error_Pragma_Arg;
2470 ----------------------------
2471 -- Error_Pragma_Arg_Ident --
2472 ----------------------------
2474 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2475 MsgF : String := Msg;
2477 Error_Msg_Name_1 := Pname;
2479 Error_Msg_N (MsgF, Arg);
2481 end Error_Pragma_Arg_Ident;
2483 ----------------------
2484 -- Error_Pragma_Ref --
2485 ----------------------
2487 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2488 MsgF : String := Msg;
2490 Error_Msg_Name_1 := Pname;
2492 Error_Msg_Sloc := Sloc (Ref);
2493 Error_Msg_NE (MsgF, N, Ref);
2495 end Error_Pragma_Ref;
2497 ------------------------
2498 -- Find_Lib_Unit_Name --
2499 ------------------------
2501 function Find_Lib_Unit_Name return Entity_Id is
2503 -- Return inner compilation unit entity, for case of nested
2504 -- categorization pragmas. This happens in generic unit.
2506 if Nkind (Parent (N)) = N_Package_Specification
2507 and then Defining_Entity (Parent (N)) /= Current_Scope
2509 return Defining_Entity (Parent (N));
2511 return Current_Scope;
2513 end Find_Lib_Unit_Name;
2515 ----------------------------
2516 -- Find_Program_Unit_Name --
2517 ----------------------------
2519 procedure Find_Program_Unit_Name (Id : Node_Id) is
2520 Unit_Name : Entity_Id;
2521 Unit_Kind : Node_Kind;
2522 P : constant Node_Id := Parent (N);
2525 if Nkind (P) = N_Compilation_Unit then
2526 Unit_Kind := Nkind (Unit (P));
2528 if Unit_Kind = N_Subprogram_Declaration
2529 or else Unit_Kind = N_Package_Declaration
2530 or else Unit_Kind in N_Generic_Declaration
2532 Unit_Name := Defining_Entity (Unit (P));
2534 if Chars (Id) = Chars (Unit_Name) then
2535 Set_Entity (Id, Unit_Name);
2536 Set_Etype (Id, Etype (Unit_Name));
2538 Set_Etype (Id, Any_Type);
2540 ("cannot find program unit referenced by pragma%");
2544 Set_Etype (Id, Any_Type);
2545 Error_Pragma ("pragma% inapplicable to this unit");
2551 end Find_Program_Unit_Name;
2553 -----------------------------------------
2554 -- Find_Unique_Parameterless_Procedure --
2555 -----------------------------------------
2557 function Find_Unique_Parameterless_Procedure
2559 Arg : Node_Id) return Entity_Id
2561 Proc : Entity_Id := Empty;
2564 -- The body of this procedure needs some comments ???
2566 if not Is_Entity_Name (Name) then
2568 ("argument of pragma% must be entity name", Arg);
2570 elsif not Is_Overloaded (Name) then
2571 Proc := Entity (Name);
2573 if Ekind (Proc) /= E_Procedure
2574 or else Present (First_Formal (Proc))
2577 ("argument of pragma% must be parameterless procedure", Arg);
2582 Found : Boolean := False;
2584 Index : Interp_Index;
2587 Get_First_Interp (Name, Index, It);
2588 while Present (It.Nam) loop
2591 if Ekind (Proc) = E_Procedure
2592 and then No (First_Formal (Proc))
2596 Set_Entity (Name, Proc);
2597 Set_Is_Overloaded (Name, False);
2600 ("ambiguous handler name for pragma% ", Arg);
2604 Get_Next_Interp (Index, It);
2609 ("argument of pragma% must be parameterless procedure",
2612 Proc := Entity (Name);
2618 end Find_Unique_Parameterless_Procedure;
2624 procedure Fix_Error (Msg : in out String) is
2626 if From_Aspect_Specification (N) then
2627 for J in Msg'First .. Msg'Last - 5 loop
2628 if Msg (J .. J + 5) = "pragma" then
2629 Msg (J .. J + 5) := "aspect";
2633 if Error_Msg_Name_1 = Name_Precondition then
2634 Error_Msg_Name_1 := Name_Pre;
2635 elsif Error_Msg_Name_1 = Name_Postcondition then
2636 Error_Msg_Name_1 := Name_Post;
2641 -------------------------
2642 -- Gather_Associations --
2643 -------------------------
2645 procedure Gather_Associations
2647 Args : out Args_List)
2652 -- Initialize all parameters to Empty
2654 for J in Args'Range loop
2658 -- That's all we have to do if there are no argument associations
2660 if No (Pragma_Argument_Associations (N)) then
2664 -- Otherwise first deal with any positional parameters present
2666 Arg := First (Pragma_Argument_Associations (N));
2667 for Index in Args'Range loop
2668 exit when No (Arg) or else Chars (Arg) /= No_Name;
2669 Args (Index) := Get_Pragma_Arg (Arg);
2673 -- Positional parameters all processed, if any left, then we
2674 -- have too many positional parameters.
2676 if Present (Arg) and then Chars (Arg) = No_Name then
2678 ("too many positional associations for pragma%", Arg);
2681 -- Process named parameters if any are present
2683 while Present (Arg) loop
2684 if Chars (Arg) = No_Name then
2686 ("positional association cannot follow named association",
2690 for Index in Names'Range loop
2691 if Names (Index) = Chars (Arg) then
2692 if Present (Args (Index)) then
2694 ("duplicate argument association for pragma%", Arg);
2696 Args (Index) := Get_Pragma_Arg (Arg);
2701 if Index = Names'Last then
2702 Error_Msg_Name_1 := Pname;
2703 Error_Msg_N ("pragma% does not allow & argument", Arg);
2705 -- Check for possible misspelling
2707 for Index1 in Names'Range loop
2708 if Is_Bad_Spelling_Of
2709 (Chars (Arg), Names (Index1))
2711 Error_Msg_Name_1 := Names (Index1);
2712 Error_Msg_N -- CODEFIX
2713 ("\possible misspelling of%", Arg);
2725 end Gather_Associations;
2731 procedure GNAT_Pragma is
2733 -- We need to check the No_Implementation_Pragmas restriction for
2734 -- the case of a pragma from source. Note that the case of aspects
2735 -- generating corresponding pragmas marks these pragmas as not being
2736 -- from source, so this test also catches that case.
2738 if Comes_From_Source (N) then
2739 Check_Restriction (No_Implementation_Pragmas, N);
2743 --------------------------
2744 -- Is_Before_First_Decl --
2745 --------------------------
2747 function Is_Before_First_Decl
2748 (Pragma_Node : Node_Id;
2749 Decls : List_Id) return Boolean
2751 Item : Node_Id := First (Decls);
2754 -- Only other pragmas can come before this pragma
2757 if No (Item) or else Nkind (Item) /= N_Pragma then
2760 elsif Item = Pragma_Node then
2766 end Is_Before_First_Decl;
2768 -----------------------------
2769 -- Is_Configuration_Pragma --
2770 -----------------------------
2772 -- A configuration pragma must appear in the context clause of a
2773 -- compilation unit, and only other pragmas may precede it. Note that
2774 -- the test below also permits use in a configuration pragma file.
2776 function Is_Configuration_Pragma return Boolean is
2777 Lis : constant List_Id := List_Containing (N);
2778 Par : constant Node_Id := Parent (N);
2782 -- If no parent, then we are in the configuration pragma file,
2783 -- so the placement is definitely appropriate.
2788 -- Otherwise we must be in the context clause of a compilation unit
2789 -- and the only thing allowed before us in the context list is more
2790 -- configuration pragmas.
2792 elsif Nkind (Par) = N_Compilation_Unit
2793 and then Context_Items (Par) = Lis
2800 elsif Nkind (Prg) /= N_Pragma then
2810 end Is_Configuration_Pragma;
2812 --------------------------
2813 -- Is_In_Context_Clause --
2814 --------------------------
2816 function Is_In_Context_Clause return Boolean is
2818 Parent_Node : Node_Id;
2821 if not Is_List_Member (N) then
2825 Plist := List_Containing (N);
2826 Parent_Node := Parent (Plist);
2828 if Parent_Node = Empty
2829 or else Nkind (Parent_Node) /= N_Compilation_Unit
2830 or else Context_Items (Parent_Node) /= Plist
2837 end Is_In_Context_Clause;
2839 ---------------------------------
2840 -- Is_Static_String_Expression --
2841 ---------------------------------
2843 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2844 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2847 Analyze_And_Resolve (Argx);
2848 return Is_OK_Static_Expression (Argx)
2849 and then Nkind (Argx) = N_String_Literal;
2850 end Is_Static_String_Expression;
2852 ----------------------
2853 -- Pragma_Misplaced --
2854 ----------------------
2856 procedure Pragma_Misplaced is
2858 Error_Pragma ("incorrect placement of pragma%");
2859 end Pragma_Misplaced;
2861 ------------------------------------
2862 -- Process Atomic_Shared_Volatile --
2863 ------------------------------------
2865 procedure Process_Atomic_Shared_Volatile is
2872 procedure Set_Atomic (E : Entity_Id);
2873 -- Set given type as atomic, and if no explicit alignment was given,
2874 -- set alignment to unknown, since back end knows what the alignment
2875 -- requirements are for atomic arrays. Note: this step is necessary
2876 -- for derived types.
2882 procedure Set_Atomic (E : Entity_Id) is
2886 if not Has_Alignment_Clause (E) then
2887 Set_Alignment (E, Uint_0);
2891 -- Start of processing for Process_Atomic_Shared_Volatile
2894 Check_Ada_83_Warning;
2895 Check_No_Identifiers;
2896 Check_Arg_Count (1);
2897 Check_Arg_Is_Local_Name (Arg1);
2898 E_Id := Get_Pragma_Arg (Arg1);
2900 if Etype (E_Id) = Any_Type then
2905 D := Declaration_Node (E);
2908 -- Check duplicate before we chain ourselves!
2910 Check_Duplicate_Pragma (E);
2912 -- Now check appropriateness of the entity
2915 if Rep_Item_Too_Early (E, N)
2917 Rep_Item_Too_Late (E, N)
2921 Check_First_Subtype (Arg1);
2924 if Prag_Id /= Pragma_Volatile then
2926 Set_Atomic (Underlying_Type (E));
2927 Set_Atomic (Base_Type (E));
2930 -- Attribute belongs on the base type. If the view of the type is
2931 -- currently private, it also belongs on the underlying type.
2933 Set_Is_Volatile (Base_Type (E));
2934 Set_Is_Volatile (Underlying_Type (E));
2936 Set_Treat_As_Volatile (E);
2937 Set_Treat_As_Volatile (Underlying_Type (E));
2939 elsif K = N_Object_Declaration
2940 or else (K = N_Component_Declaration
2941 and then Original_Record_Component (E) = E)
2943 if Rep_Item_Too_Late (E, N) then
2947 if Prag_Id /= Pragma_Volatile then
2950 -- If the object declaration has an explicit initialization, a
2951 -- temporary may have to be created to hold the expression, to
2952 -- ensure that access to the object remain atomic.
2954 if Nkind (Parent (E)) = N_Object_Declaration
2955 and then Present (Expression (Parent (E)))
2957 Set_Has_Delayed_Freeze (E);
2960 -- An interesting improvement here. If an object of type X is
2961 -- declared atomic, and the type X is not atomic, that's a
2962 -- pity, since it may not have appropriate alignment etc. We
2963 -- can rescue this in the special case where the object and
2964 -- type are in the same unit by just setting the type as
2965 -- atomic, so that the back end will process it as atomic.
2967 Utyp := Underlying_Type (Etype (E));
2970 and then Sloc (E) > No_Location
2971 and then Sloc (Utyp) > No_Location
2973 Get_Source_File_Index (Sloc (E)) =
2974 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2976 Set_Is_Atomic (Underlying_Type (Etype (E)));
2980 Set_Is_Volatile (E);
2981 Set_Treat_As_Volatile (E);
2985 ("inappropriate entity for pragma%", Arg1);
2987 end Process_Atomic_Shared_Volatile;
2989 -------------------------------------------
2990 -- Process_Compile_Time_Warning_Or_Error --
2991 -------------------------------------------
2993 procedure Process_Compile_Time_Warning_Or_Error is
2994 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2997 Check_Arg_Count (2);
2998 Check_No_Identifiers;
2999 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3000 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3002 if Compile_Time_Known_Value (Arg1x) then
3003 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3005 Str : constant String_Id :=
3006 Strval (Get_Pragma_Arg (Arg2));
3007 Len : constant Int := String_Length (Str);
3012 Cent : constant Entity_Id :=
3013 Cunit_Entity (Current_Sem_Unit);
3015 Force : constant Boolean :=
3016 Prag_Id = Pragma_Compile_Time_Warning
3018 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3019 and then (Ekind (Cent) /= E_Package
3020 or else not In_Private_Part (Cent));
3021 -- Set True if this is the warning case, and we are in the
3022 -- visible part of a package spec, or in a subprogram spec,
3023 -- in which case we want to force the client to see the
3024 -- warning, even though it is not in the main unit.
3027 -- Loop through segments of message separated by line feeds.
3028 -- We output these segments as separate messages with
3029 -- continuation marks for all but the first.
3034 Error_Msg_Strlen := 0;
3036 -- Loop to copy characters from argument to error message
3040 exit when Ptr > Len;
3041 CC := Get_String_Char (Str, Ptr);
3044 -- Ignore wide chars ??? else store character
3046 if In_Character_Range (CC) then
3047 C := Get_Character (CC);
3048 exit when C = ASCII.LF;
3049 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3050 Error_Msg_String (Error_Msg_Strlen) := C;
3054 -- Here with one line ready to go
3056 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3058 -- If this is a warning in a spec, then we want clients
3059 -- to see the warning, so mark the message with the
3060 -- special sequence !! to force the warning. In the case
3061 -- of a package spec, we do not force this if we are in
3062 -- the private part of the spec.
3065 if Cont = False then
3066 Error_Msg_N ("<~!!", Arg1);
3069 Error_Msg_N ("\<~!!", Arg1);
3072 -- Error, rather than warning, or in a body, so we do not
3073 -- need to force visibility for client (error will be
3074 -- output in any case, and this is the situation in which
3075 -- we do not want a client to get a warning, since the
3076 -- warning is in the body or the spec private part).
3079 if Cont = False then
3080 Error_Msg_N ("<~", Arg1);
3083 Error_Msg_N ("\<~", Arg1);
3087 exit when Ptr > Len;
3092 end Process_Compile_Time_Warning_Or_Error;
3094 ------------------------
3095 -- Process_Convention --
3096 ------------------------
3098 procedure Process_Convention
3099 (C : out Convention_Id;
3100 Ent : out Entity_Id)
3106 Comp_Unit : Unit_Number_Type;
3108 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3109 -- Called if we have more than one Export/Import/Convention pragma.
3110 -- This is generally illegal, but we have a special case of allowing
3111 -- Import and Interface to coexist if they specify the convention in
3112 -- a consistent manner. We are allowed to do this, since Interface is
3113 -- an implementation defined pragma, and we choose to do it since we
3114 -- know Rational allows this combination. S is the entity id of the
3115 -- subprogram in question. This procedure also sets the special flag
3116 -- Import_Interface_Present in both pragmas in the case where we do
3117 -- have matching Import and Interface pragmas.
3119 procedure Set_Convention_From_Pragma (E : Entity_Id);
3120 -- Set convention in entity E, and also flag that the entity has a
3121 -- convention pragma. If entity is for a private or incomplete type,
3122 -- also set convention and flag on underlying type. This procedure
3123 -- also deals with the special case of C_Pass_By_Copy convention.
3125 -------------------------------
3126 -- Diagnose_Multiple_Pragmas --
3127 -------------------------------
3129 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3130 Pdec : constant Node_Id := Declaration_Node (S);
3134 function Same_Convention (Decl : Node_Id) return Boolean;
3135 -- Decl is a pragma node. This function returns True if this
3136 -- pragma has a first argument that is an identifier with a
3137 -- Chars field corresponding to the Convention_Id C.
3139 function Same_Name (Decl : Node_Id) return Boolean;
3140 -- Decl is a pragma node. This function returns True if this
3141 -- pragma has a second argument that is an identifier with a
3142 -- Chars field that matches the Chars of the current subprogram.
3144 ---------------------
3145 -- Same_Convention --
3146 ---------------------
3148 function Same_Convention (Decl : Node_Id) return Boolean is
3149 Arg1 : constant Node_Id :=
3150 First (Pragma_Argument_Associations (Decl));
3153 if Present (Arg1) then
3155 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3157 if Nkind (Arg) = N_Identifier
3158 and then Is_Convention_Name (Chars (Arg))
3159 and then Get_Convention_Id (Chars (Arg)) = C
3167 end Same_Convention;
3173 function Same_Name (Decl : Node_Id) return Boolean is
3174 Arg1 : constant Node_Id :=
3175 First (Pragma_Argument_Associations (Decl));
3183 Arg2 := Next (Arg1);
3190 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3192 if Nkind (Arg) = N_Identifier
3193 and then Chars (Arg) = Chars (S)
3202 -- Start of processing for Diagnose_Multiple_Pragmas
3207 -- Definitely give message if we have Convention/Export here
3209 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3212 -- If we have an Import or Export, scan back from pragma to
3213 -- find any previous pragma applying to the same procedure.
3214 -- The scan will be terminated by the start of the list, or
3215 -- hitting the subprogram declaration. This won't allow one
3216 -- pragma to appear in the public part and one in the private
3217 -- part, but that seems very unlikely in practice.
3221 while Present (Decl) and then Decl /= Pdec loop
3223 -- Look for pragma with same name as us
3225 if Nkind (Decl) = N_Pragma
3226 and then Same_Name (Decl)
3228 -- Give error if same as our pragma or Export/Convention
3230 if Pragma_Name (Decl) = Name_Export
3232 Pragma_Name (Decl) = Name_Convention
3234 Pragma_Name (Decl) = Pragma_Name (N)
3238 -- Case of Import/Interface or the other way round
3240 elsif Pragma_Name (Decl) = Name_Interface
3242 Pragma_Name (Decl) = Name_Import
3244 -- Here we know that we have Import and Interface. It
3245 -- doesn't matter which way round they are. See if
3246 -- they specify the same convention. If so, all OK,
3247 -- and set special flags to stop other messages
3249 if Same_Convention (Decl) then
3250 Set_Import_Interface_Present (N);
3251 Set_Import_Interface_Present (Decl);
3254 -- If different conventions, special message
3257 Error_Msg_Sloc := Sloc (Decl);
3259 ("convention differs from that given#", Arg1);
3269 -- Give message if needed if we fall through those tests
3273 ("at most one Convention/Export/Import pragma is allowed",
3276 end Diagnose_Multiple_Pragmas;
3278 --------------------------------
3279 -- Set_Convention_From_Pragma --
3280 --------------------------------
3282 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3284 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3285 -- for an overridden dispatching operation. Technically this is
3286 -- an amendment and should only be done in Ada 2005 mode. However,
3287 -- this is clearly a mistake, since the problem that is addressed
3288 -- by this AI is that there is a clear gap in the RM!
3290 if Is_Dispatching_Operation (E)
3291 and then Present (Overridden_Operation (E))
3292 and then C /= Convention (Overridden_Operation (E))
3295 ("cannot change convention for " &
3296 "overridden dispatching operation",
3300 -- Set the convention
3302 Set_Convention (E, C);
3303 Set_Has_Convention_Pragma (E);
3305 if Is_Incomplete_Or_Private_Type (E)
3306 and then Present (Underlying_Type (E))
3308 Set_Convention (Underlying_Type (E), C);
3309 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3312 -- A class-wide type should inherit the convention of the specific
3313 -- root type (although this isn't specified clearly by the RM).
3315 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3316 Set_Convention (Class_Wide_Type (E), C);
3319 -- If the entity is a record type, then check for special case of
3320 -- C_Pass_By_Copy, which is treated the same as C except that the
3321 -- special record flag is set. This convention is only permitted
3322 -- on record types (see AI95-00131).
3324 if Cname = Name_C_Pass_By_Copy then
3325 if Is_Record_Type (E) then
3326 Set_C_Pass_By_Copy (Base_Type (E));
3327 elsif Is_Incomplete_Or_Private_Type (E)
3328 and then Is_Record_Type (Underlying_Type (E))
3330 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3333 ("C_Pass_By_Copy convention allowed only for record type",
3338 -- If the entity is a derived boolean type, check for the special
3339 -- case of convention C, C++, or Fortran, where we consider any
3340 -- nonzero value to represent true.
3342 if Is_Discrete_Type (E)
3343 and then Root_Type (Etype (E)) = Standard_Boolean
3349 C = Convention_Fortran)
3351 Set_Nonzero_Is_True (Base_Type (E));
3353 end Set_Convention_From_Pragma;
3355 -- Start of processing for Process_Convention
3358 Check_At_Least_N_Arguments (2);
3359 Check_Optional_Identifier (Arg1, Name_Convention);
3360 Check_Arg_Is_Identifier (Arg1);
3361 Cname := Chars (Get_Pragma_Arg (Arg1));
3363 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3364 -- tested again below to set the critical flag).
3366 if Cname = Name_C_Pass_By_Copy then
3369 -- Otherwise we must have something in the standard convention list
3371 elsif Is_Convention_Name (Cname) then
3372 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3374 -- In DEC VMS, it seems that there is an undocumented feature that
3375 -- any unrecognized convention is treated as the default, which for
3376 -- us is convention C. It does not seem so terrible to do this
3377 -- unconditionally, silently in the VMS case, and with a warning
3378 -- in the non-VMS case.
3381 if Warn_On_Export_Import and not OpenVMS_On_Target then
3383 ("?unrecognized convention name, C assumed",
3384 Get_Pragma_Arg (Arg1));
3390 Check_Optional_Identifier (Arg2, Name_Entity);
3391 Check_Arg_Is_Local_Name (Arg2);
3393 Id := Get_Pragma_Arg (Arg2);
3396 if not Is_Entity_Name (Id) then
3397 Error_Pragma_Arg ("entity name required", Arg2);
3402 -- Set entity to return
3406 -- Ada_Pass_By_Copy special checking
3408 if C = Convention_Ada_Pass_By_Copy then
3409 if not Is_First_Subtype (E) then
3411 ("convention `Ada_Pass_By_Copy` only "
3412 & "allowed for types", Arg2);
3415 if Is_By_Reference_Type (E) then
3417 ("convention `Ada_Pass_By_Copy` not allowed for "
3418 & "by-reference type", Arg1);
3422 -- Ada_Pass_By_Reference special checking
3424 if C = Convention_Ada_Pass_By_Reference then
3425 if not Is_First_Subtype (E) then
3427 ("convention `Ada_Pass_By_Reference` only "
3428 & "allowed for types", Arg2);
3431 if Is_By_Copy_Type (E) then
3433 ("convention `Ada_Pass_By_Reference` not allowed for "
3434 & "by-copy type", Arg1);
3438 -- Go to renamed subprogram if present, since convention applies to
3439 -- the actual renamed entity, not to the renaming entity. If the
3440 -- subprogram is inherited, go to parent subprogram.
3442 if Is_Subprogram (E)
3443 and then Present (Alias (E))
3445 if Nkind (Parent (Declaration_Node (E))) =
3446 N_Subprogram_Renaming_Declaration
3448 if Scope (E) /= Scope (Alias (E)) then
3450 ("cannot apply pragma% to non-local entity&#", E);
3455 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3456 N_Private_Extension_Declaration)
3457 and then Scope (E) = Scope (Alias (E))
3461 -- Return the parent subprogram the entity was inherited from
3467 -- Check that we are not applying this to a specless body
3469 if Is_Subprogram (E)
3470 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3473 ("pragma% requires separate spec and must come before body");
3476 -- Check that we are not applying this to a named constant
3478 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3479 Error_Msg_Name_1 := Pname;
3481 ("cannot apply pragma% to named constant!",
3482 Get_Pragma_Arg (Arg2));
3484 ("\supply appropriate type for&!", Arg2);
3487 if Ekind (E) = E_Enumeration_Literal then
3488 Error_Pragma ("enumeration literal not allowed for pragma%");
3491 -- Check for rep item appearing too early or too late
3493 if Etype (E) = Any_Type
3494 or else Rep_Item_Too_Early (E, N)
3498 elsif Present (Underlying_Type (E)) then
3499 E := Underlying_Type (E);
3502 if Rep_Item_Too_Late (E, N) then
3506 if Has_Convention_Pragma (E) then
3507 Diagnose_Multiple_Pragmas (E);
3509 elsif Convention (E) = Convention_Protected
3510 or else Ekind (Scope (E)) = E_Protected_Type
3513 ("a protected operation cannot be given a different convention",
3517 -- For Intrinsic, a subprogram is required
3519 if C = Convention_Intrinsic
3520 and then not Is_Subprogram (E)
3521 and then not Is_Generic_Subprogram (E)
3524 ("second argument of pragma% must be a subprogram", Arg2);
3529 if C = Convention_Stdcall then
3531 -- A dispatching call is not allowed. A dispatching subprogram
3532 -- cannot be used to interface to the Win32 API, so in fact this
3533 -- check does not impose any effective restriction.
3535 if Is_Dispatching_Operation (E) then
3538 ("dispatching subprograms cannot use Stdcall convention");
3540 -- Subprogram is allowed, but not a generic subprogram, and not a
3541 -- dispatching operation.
3543 elsif not Is_Subprogram (E)
3544 and then not Is_Generic_Subprogram (E)
3548 and then Ekind (E) /= E_Variable
3550 -- An access to subprogram is also allowed
3554 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3557 ("second argument of pragma% must be subprogram (type)",
3562 if not Is_Subprogram (E)
3563 and then not Is_Generic_Subprogram (E)
3565 Set_Convention_From_Pragma (E);
3568 Check_First_Subtype (Arg2);
3569 Set_Convention_From_Pragma (Base_Type (E));
3571 -- For subprograms, we must set the convention on the
3572 -- internally generated directly designated type as well.
3574 if Ekind (E) = E_Access_Subprogram_Type then
3575 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3579 -- For the subprogram case, set proper convention for all homonyms
3580 -- in same scope and the same declarative part, i.e. the same
3581 -- compilation unit.
3584 Comp_Unit := Get_Source_Unit (E);
3585 Set_Convention_From_Pragma (E);
3587 -- Treat a pragma Import as an implicit body, for GPS use
3589 if Prag_Id = Pragma_Import then
3590 Generate_Reference (E, Id, 'b');
3593 -- Loop through the homonyms of the pragma argument's entity
3598 exit when No (E1) or else Scope (E1) /= Current_Scope;
3600 -- Do not set the pragma on inherited operations or on formal
3603 if Comes_From_Source (E1)
3604 and then Comp_Unit = Get_Source_Unit (E1)
3605 and then not Is_Formal_Subprogram (E1)
3606 and then Nkind (Original_Node (Parent (E1))) /=
3607 N_Full_Type_Declaration
3609 if Present (Alias (E1))
3610 and then Scope (E1) /= Scope (Alias (E1))
3613 ("cannot apply pragma% to non-local entity& declared#",
3617 Set_Convention_From_Pragma (E1);
3619 if Prag_Id = Pragma_Import then
3620 Generate_Reference (E1, Id, 'b');
3624 -- For aspect case, do NOT apply to homonyms
3626 exit when From_Aspect_Specification (N);
3629 end Process_Convention;
3631 ----------------------------------------
3632 -- Process_Disable_Enable_Atomic_Sync --
3633 ----------------------------------------
3635 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3638 Check_No_Identifiers;
3639 Check_At_Most_N_Arguments (1);
3641 -- Modeled internally as
3642 -- pragma Unsuppress (Atomic_Synchronization [,Entity])
3646 Pragma_Identifier =>
3647 Make_Identifier (Loc, Nam),
3648 Pragma_Argument_Associations => New_List (
3649 Make_Pragma_Argument_Association (Loc,
3651 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3653 if Present (Arg1) then
3654 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3658 end Process_Disable_Enable_Atomic_Sync;
3660 -----------------------------------------------------
3661 -- Process_Extended_Import_Export_Exception_Pragma --
3662 -----------------------------------------------------
3664 procedure Process_Extended_Import_Export_Exception_Pragma
3665 (Arg_Internal : Node_Id;
3666 Arg_External : Node_Id;
3674 if not OpenVMS_On_Target then
3676 ("?pragma% ignored (applies only to Open'V'M'S)");
3679 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3680 Def_Id := Entity (Arg_Internal);
3682 if Ekind (Def_Id) /= E_Exception then
3684 ("pragma% must refer to declared exception", Arg_Internal);
3687 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3689 if Present (Arg_Form) then
3690 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3693 if Present (Arg_Form)
3694 and then Chars (Arg_Form) = Name_Ada
3698 Set_Is_VMS_Exception (Def_Id);
3699 Set_Exception_Code (Def_Id, No_Uint);
3702 if Present (Arg_Code) then
3703 if not Is_VMS_Exception (Def_Id) then
3705 ("Code option for pragma% not allowed for Ada case",
3709 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3710 Code_Val := Expr_Value (Arg_Code);
3712 if not UI_Is_In_Int_Range (Code_Val) then
3714 ("Code option for pragma% must be in 32-bit range",
3718 Set_Exception_Code (Def_Id, Code_Val);
3721 end Process_Extended_Import_Export_Exception_Pragma;
3723 -------------------------------------------------
3724 -- Process_Extended_Import_Export_Internal_Arg --
3725 -------------------------------------------------
3727 procedure Process_Extended_Import_Export_Internal_Arg
3728 (Arg_Internal : Node_Id := Empty)
3731 if No (Arg_Internal) then
3732 Error_Pragma ("Internal parameter required for pragma%");
3735 if Nkind (Arg_Internal) = N_Identifier then
3738 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3739 and then (Prag_Id = Pragma_Import_Function
3741 Prag_Id = Pragma_Export_Function)
3747 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3750 Check_Arg_Is_Local_Name (Arg_Internal);
3751 end Process_Extended_Import_Export_Internal_Arg;
3753 --------------------------------------------------
3754 -- Process_Extended_Import_Export_Object_Pragma --
3755 --------------------------------------------------
3757 procedure Process_Extended_Import_Export_Object_Pragma
3758 (Arg_Internal : Node_Id;
3759 Arg_External : Node_Id;
3765 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3766 Def_Id := Entity (Arg_Internal);
3768 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3770 ("pragma% must designate an object", Arg_Internal);
3773 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3775 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3778 ("previous Common/Psect_Object applies, pragma % not permitted",
3782 if Rep_Item_Too_Late (Def_Id, N) then
3786 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3788 if Present (Arg_Size) then
3789 Check_Arg_Is_External_Name (Arg_Size);
3792 -- Export_Object case
3794 if Prag_Id = Pragma_Export_Object then
3795 if not Is_Library_Level_Entity (Def_Id) then
3797 ("argument for pragma% must be library level entity",
3801 if Ekind (Current_Scope) = E_Generic_Package then
3802 Error_Pragma ("pragma& cannot appear in a generic unit");
3805 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3807 ("exported object must have compile time known size",
3811 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3812 Error_Msg_N ("?duplicate Export_Object pragma", N);
3814 Set_Exported (Def_Id, Arg_Internal);
3817 -- Import_Object case
3820 if Is_Concurrent_Type (Etype (Def_Id)) then
3822 ("cannot use pragma% for task/protected object",
3826 if Ekind (Def_Id) = E_Constant then
3828 ("cannot import a constant", Arg_Internal);
3831 if Warn_On_Export_Import
3832 and then Has_Discriminants (Etype (Def_Id))
3835 ("imported value must be initialized?", Arg_Internal);
3838 if Warn_On_Export_Import
3839 and then Is_Access_Type (Etype (Def_Id))
3842 ("cannot import object of an access type?", Arg_Internal);
3845 if Warn_On_Export_Import
3846 and then Is_Imported (Def_Id)
3849 ("?duplicate Import_Object pragma", N);
3851 -- Check for explicit initialization present. Note that an
3852 -- initialization generated by the code generator, e.g. for an
3853 -- access type, does not count here.
3855 elsif Present (Expression (Parent (Def_Id)))
3858 (Original_Node (Expression (Parent (Def_Id))))
3860 Error_Msg_Sloc := Sloc (Def_Id);
3862 ("imported entities cannot be initialized (RM B.1(24))",
3863 "\no initialization allowed for & declared#", Arg1);
3865 Set_Imported (Def_Id);
3866 Note_Possible_Modification (Arg_Internal, Sure => False);
3869 end Process_Extended_Import_Export_Object_Pragma;
3871 ------------------------------------------------------
3872 -- Process_Extended_Import_Export_Subprogram_Pragma --
3873 ------------------------------------------------------
3875 procedure Process_Extended_Import_Export_Subprogram_Pragma
3876 (Arg_Internal : Node_Id;
3877 Arg_External : Node_Id;
3878 Arg_Parameter_Types : Node_Id;
3879 Arg_Result_Type : Node_Id := Empty;
3880 Arg_Mechanism : Node_Id;
3881 Arg_Result_Mechanism : Node_Id := Empty;
3882 Arg_First_Optional_Parameter : Node_Id := Empty)
3888 Ambiguous : Boolean;
3892 function Same_Base_Type
3894 Formal : Entity_Id) return Boolean;
3895 -- Determines if Ptype references the type of Formal. Note that only
3896 -- the base types need to match according to the spec. Ptype here is
3897 -- the argument from the pragma, which is either a type name, or an
3898 -- access attribute.
3900 --------------------
3901 -- Same_Base_Type --
3902 --------------------
3904 function Same_Base_Type
3906 Formal : Entity_Id) return Boolean
3908 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3912 -- Case where pragma argument is typ'Access
3914 if Nkind (Ptype) = N_Attribute_Reference
3915 and then Attribute_Name (Ptype) = Name_Access
3917 Pref := Prefix (Ptype);
3920 if not Is_Entity_Name (Pref)
3921 or else Entity (Pref) = Any_Type
3926 -- We have a match if the corresponding argument is of an
3927 -- anonymous access type, and its designated type matches the
3928 -- type of the prefix of the access attribute
3930 return Ekind (Ftyp) = E_Anonymous_Access_Type
3931 and then Base_Type (Entity (Pref)) =
3932 Base_Type (Etype (Designated_Type (Ftyp)));
3934 -- Case where pragma argument is a type name
3939 if not Is_Entity_Name (Ptype)
3940 or else Entity (Ptype) = Any_Type
3945 -- We have a match if the corresponding argument is of the type
3946 -- given in the pragma (comparing base types)
3948 return Base_Type (Entity (Ptype)) = Ftyp;
3952 -- Start of processing for
3953 -- Process_Extended_Import_Export_Subprogram_Pragma
3956 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3960 -- Loop through homonyms (overloadings) of the entity
3962 Hom_Id := Entity (Arg_Internal);
3963 while Present (Hom_Id) loop
3964 Def_Id := Get_Base_Subprogram (Hom_Id);
3966 -- We need a subprogram in the current scope
3968 if not Is_Subprogram (Def_Id)
3969 or else Scope (Def_Id) /= Current_Scope
3976 -- Pragma cannot apply to subprogram body
3978 if Is_Subprogram (Def_Id)
3979 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3983 ("pragma% requires separate spec"
3984 & " and must come before body");
3987 -- Test result type if given, note that the result type
3988 -- parameter can only be present for the function cases.
3990 if Present (Arg_Result_Type)
3991 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3995 elsif Etype (Def_Id) /= Standard_Void_Type
3997 (Pname = Name_Export_Procedure
3999 Pname = Name_Import_Procedure)
4003 -- Test parameter types if given. Note that this parameter
4004 -- has not been analyzed (and must not be, since it is
4005 -- semantic nonsense), so we get it as the parser left it.
4007 elsif Present (Arg_Parameter_Types) then
4008 Check_Matching_Types : declare
4013 Formal := First_Formal (Def_Id);
4015 if Nkind (Arg_Parameter_Types) = N_Null then
4016 if Present (Formal) then
4020 -- A list of one type, e.g. (List) is parsed as
4021 -- a parenthesized expression.
4023 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4024 and then Paren_Count (Arg_Parameter_Types) = 1
4027 or else Present (Next_Formal (Formal))
4032 Same_Base_Type (Arg_Parameter_Types, Formal);
4035 -- A list of more than one type is parsed as a aggregate
4037 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4038 and then Paren_Count (Arg_Parameter_Types) = 0
4040 Ptype := First (Expressions (Arg_Parameter_Types));
4041 while Present (Ptype) or else Present (Formal) loop
4044 or else not Same_Base_Type (Ptype, Formal)
4049 Next_Formal (Formal);
4054 -- Anything else is of the wrong form
4058 ("wrong form for Parameter_Types parameter",
4059 Arg_Parameter_Types);
4061 end Check_Matching_Types;
4064 -- Match is now False if the entry we found did not match
4065 -- either a supplied Parameter_Types or Result_Types argument
4071 -- Ambiguous case, the flag Ambiguous shows if we already
4072 -- detected this and output the initial messages.
4075 if not Ambiguous then
4077 Error_Msg_Name_1 := Pname;
4079 ("pragma% does not uniquely identify subprogram!",
4081 Error_Msg_Sloc := Sloc (Ent);
4082 Error_Msg_N ("matching subprogram #!", N);
4086 Error_Msg_Sloc := Sloc (Def_Id);
4087 Error_Msg_N ("matching subprogram #!", N);
4092 Hom_Id := Homonym (Hom_Id);
4095 -- See if we found an entry
4098 if not Ambiguous then
4099 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4101 ("pragma% cannot be given for generic subprogram");
4104 ("pragma% does not identify local subprogram");
4111 -- Import pragmas must be for imported entities
4113 if Prag_Id = Pragma_Import_Function
4115 Prag_Id = Pragma_Import_Procedure
4117 Prag_Id = Pragma_Import_Valued_Procedure
4119 if not Is_Imported (Ent) then
4121 ("pragma Import or Interface must precede pragma%");
4124 -- Here we have the Export case which can set the entity as exported
4126 -- But does not do so if the specified external name is null, since
4127 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4128 -- compatible) to request no external name.
4130 elsif Nkind (Arg_External) = N_String_Literal
4131 and then String_Length (Strval (Arg_External)) = 0
4135 -- In all other cases, set entity as exported
4138 Set_Exported (Ent, Arg_Internal);
4141 -- Special processing for Valued_Procedure cases
4143 if Prag_Id = Pragma_Import_Valued_Procedure
4145 Prag_Id = Pragma_Export_Valued_Procedure
4147 Formal := First_Formal (Ent);
4150 Error_Pragma ("at least one parameter required for pragma%");
4152 elsif Ekind (Formal) /= E_Out_Parameter then
4153 Error_Pragma ("first parameter must have mode out for pragma%");
4156 Set_Is_Valued_Procedure (Ent);
4160 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4162 -- Process Result_Mechanism argument if present. We have already
4163 -- checked that this is only allowed for the function case.
4165 if Present (Arg_Result_Mechanism) then
4166 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4169 -- Process Mechanism parameter if present. Note that this parameter
4170 -- is not analyzed, and must not be analyzed since it is semantic
4171 -- nonsense, so we get it in exactly as the parser left it.
4173 if Present (Arg_Mechanism) then
4181 -- A single mechanism association without a formal parameter
4182 -- name is parsed as a parenthesized expression. All other
4183 -- cases are parsed as aggregates, so we rewrite the single
4184 -- parameter case as an aggregate for consistency.
4186 if Nkind (Arg_Mechanism) /= N_Aggregate
4187 and then Paren_Count (Arg_Mechanism) = 1
4189 Rewrite (Arg_Mechanism,
4190 Make_Aggregate (Sloc (Arg_Mechanism),
4191 Expressions => New_List (
4192 Relocate_Node (Arg_Mechanism))));
4195 -- Case of only mechanism name given, applies to all formals
4197 if Nkind (Arg_Mechanism) /= N_Aggregate then
4198 Formal := First_Formal (Ent);
4199 while Present (Formal) loop
4200 Set_Mechanism_Value (Formal, Arg_Mechanism);
4201 Next_Formal (Formal);
4204 -- Case of list of mechanism associations given
4207 if Null_Record_Present (Arg_Mechanism) then
4209 ("inappropriate form for Mechanism parameter",
4213 -- Deal with positional ones first
4215 Formal := First_Formal (Ent);
4217 if Present (Expressions (Arg_Mechanism)) then
4218 Mname := First (Expressions (Arg_Mechanism));
4219 while Present (Mname) loop
4222 ("too many mechanism associations", Mname);
4225 Set_Mechanism_Value (Formal, Mname);
4226 Next_Formal (Formal);
4231 -- Deal with named entries
4233 if Present (Component_Associations (Arg_Mechanism)) then
4234 Massoc := First (Component_Associations (Arg_Mechanism));
4235 while Present (Massoc) loop
4236 Choice := First (Choices (Massoc));
4238 if Nkind (Choice) /= N_Identifier
4239 or else Present (Next (Choice))
4242 ("incorrect form for mechanism association",
4246 Formal := First_Formal (Ent);
4250 ("parameter name & not present", Choice);
4253 if Chars (Choice) = Chars (Formal) then
4255 (Formal, Expression (Massoc));
4257 -- Set entity on identifier (needed by ASIS)
4259 Set_Entity (Choice, Formal);
4264 Next_Formal (Formal);
4274 -- Process First_Optional_Parameter argument if present. We have
4275 -- already checked that this is only allowed for the Import case.
4277 if Present (Arg_First_Optional_Parameter) then
4278 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4280 ("first optional parameter must be formal parameter name",
4281 Arg_First_Optional_Parameter);
4284 Formal := First_Formal (Ent);
4288 ("specified formal parameter& not found",
4289 Arg_First_Optional_Parameter);
4292 exit when Chars (Formal) =
4293 Chars (Arg_First_Optional_Parameter);
4295 Next_Formal (Formal);
4298 Set_First_Optional_Parameter (Ent, Formal);
4300 -- Check specified and all remaining formals have right form
4302 while Present (Formal) loop
4303 if Ekind (Formal) /= E_In_Parameter then
4305 ("optional formal& is not of mode in!",
4306 Arg_First_Optional_Parameter, Formal);
4309 Dval := Default_Value (Formal);
4313 ("optional formal& does not have default value!",
4314 Arg_First_Optional_Parameter, Formal);
4316 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4321 ("default value for optional formal& is non-static!",
4322 Arg_First_Optional_Parameter, Formal);
4326 Set_Is_Optional_Parameter (Formal);
4327 Next_Formal (Formal);
4330 end Process_Extended_Import_Export_Subprogram_Pragma;
4332 --------------------------
4333 -- Process_Generic_List --
4334 --------------------------
4336 procedure Process_Generic_List is
4341 Check_No_Identifiers;
4342 Check_At_Least_N_Arguments (1);
4345 while Present (Arg) loop
4346 Exp := Get_Pragma_Arg (Arg);
4349 if not Is_Entity_Name (Exp)
4351 (not Is_Generic_Instance (Entity (Exp))
4353 not Is_Generic_Unit (Entity (Exp)))
4356 ("pragma% argument must be name of generic unit/instance",
4362 end Process_Generic_List;
4364 ------------------------------------
4365 -- Process_Import_Predefined_Type --
4366 ------------------------------------
4368 procedure Process_Import_Predefined_Type is
4369 Loc : constant Source_Ptr := Sloc (N);
4371 Ftyp : Node_Id := Empty;
4377 String_To_Name_Buffer (Strval (Expression (Arg3)));
4380 Elmt := First_Elmt (Predefined_Float_Types);
4381 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4385 Ftyp := Node (Elmt);
4387 if Present (Ftyp) then
4389 -- Don't build a derived type declaration, because predefined C
4390 -- types have no declaration anywhere, so cannot really be named.
4391 -- Instead build a full type declaration, starting with an
4392 -- appropriate type definition is built
4394 if Is_Floating_Point_Type (Ftyp) then
4395 Def := Make_Floating_Point_Definition (Loc,
4396 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4397 Make_Real_Range_Specification (Loc,
4398 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4399 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4401 -- Should never have a predefined type we cannot handle
4404 raise Program_Error;
4407 -- Build and insert a Full_Type_Declaration, which will be
4408 -- analyzed as soon as this list entry has been analyzed.
4410 Decl := Make_Full_Type_Declaration (Loc,
4411 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4412 Type_Definition => Def);
4414 Insert_After (N, Decl);
4415 Mark_Rewrite_Insertion (Decl);
4418 Error_Pragma_Arg ("no matching type found for pragma%",
4421 end Process_Import_Predefined_Type;
4423 ---------------------------------
4424 -- Process_Import_Or_Interface --
4425 ---------------------------------
4427 procedure Process_Import_Or_Interface is
4433 Process_Convention (C, Def_Id);
4434 Kill_Size_Check_Code (Def_Id);
4435 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4437 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4439 -- We do not permit Import to apply to a renaming declaration
4441 if Present (Renamed_Object (Def_Id)) then
4443 ("pragma% not allowed for object renaming", Arg2);
4445 -- User initialization is not allowed for imported object, but
4446 -- the object declaration may contain a default initialization,
4447 -- that will be discarded. Note that an explicit initialization
4448 -- only counts if it comes from source, otherwise it is simply
4449 -- the code generator making an implicit initialization explicit.
4451 elsif Present (Expression (Parent (Def_Id)))
4452 and then Comes_From_Source (Expression (Parent (Def_Id)))
4454 Error_Msg_Sloc := Sloc (Def_Id);
4456 ("no initialization allowed for declaration of& #",
4457 "\imported entities cannot be initialized (RM B.1(24))",
4461 Set_Imported (Def_Id);
4462 Process_Interface_Name (Def_Id, Arg3, Arg4);
4464 -- Note that we do not set Is_Public here. That's because we
4465 -- only want to set it if there is no address clause, and we
4466 -- don't know that yet, so we delay that processing till
4469 -- pragma Import completes deferred constants
4471 if Ekind (Def_Id) = E_Constant then
4472 Set_Has_Completion (Def_Id);
4475 -- It is not possible to import a constant of an unconstrained
4476 -- array type (e.g. string) because there is no simple way to
4477 -- write a meaningful subtype for it.
4479 if Is_Array_Type (Etype (Def_Id))
4480 and then not Is_Constrained (Etype (Def_Id))
4483 ("imported constant& must have a constrained subtype",
4488 elsif Is_Subprogram (Def_Id)
4489 or else Is_Generic_Subprogram (Def_Id)
4491 -- If the name is overloaded, pragma applies to all of the denoted
4492 -- entities in the same declarative part.
4495 while Present (Hom_Id) loop
4496 Def_Id := Get_Base_Subprogram (Hom_Id);
4498 -- Ignore inherited subprograms because the pragma will apply
4499 -- to the parent operation, which is the one called.
4501 if Is_Overloadable (Def_Id)
4502 and then Present (Alias (Def_Id))
4506 -- If it is not a subprogram, it must be in an outer scope and
4507 -- pragma does not apply.
4509 elsif not Is_Subprogram (Def_Id)
4510 and then not Is_Generic_Subprogram (Def_Id)
4514 -- The pragma does not apply to primitives of interfaces
4516 elsif Is_Dispatching_Operation (Def_Id)
4517 and then Present (Find_Dispatching_Type (Def_Id))
4518 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4522 -- Verify that the homonym is in the same declarative part (not
4523 -- just the same scope).
4525 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4526 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4531 Set_Imported (Def_Id);
4533 -- Reject an Import applied to an abstract subprogram
4535 if Is_Subprogram (Def_Id)
4536 and then Is_Abstract_Subprogram (Def_Id)
4538 Error_Msg_Sloc := Sloc (Def_Id);
4540 ("cannot import abstract subprogram& declared#",
4544 -- Special processing for Convention_Intrinsic
4546 if C = Convention_Intrinsic then
4548 -- Link_Name argument not allowed for intrinsic
4552 Set_Is_Intrinsic_Subprogram (Def_Id);
4554 -- If no external name is present, then check that this
4555 -- is a valid intrinsic subprogram. If an external name
4556 -- is present, then this is handled by the back end.
4559 Check_Intrinsic_Subprogram
4560 (Def_Id, Get_Pragma_Arg (Arg2));
4564 -- All interfaced procedures need an external symbol created
4565 -- for them since they are always referenced from another
4568 Set_Is_Public (Def_Id);
4570 -- Verify that the subprogram does not have a completion
4571 -- through a renaming declaration. For other completions the
4572 -- pragma appears as a too late representation.
4575 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4579 and then Nkind (Decl) = N_Subprogram_Declaration
4580 and then Present (Corresponding_Body (Decl))
4581 and then Nkind (Unit_Declaration_Node
4582 (Corresponding_Body (Decl))) =
4583 N_Subprogram_Renaming_Declaration
4585 Error_Msg_Sloc := Sloc (Def_Id);
4587 ("cannot import&, renaming already provided for " &
4588 "declaration #", N, Def_Id);
4592 Set_Has_Completion (Def_Id);
4593 Process_Interface_Name (Def_Id, Arg3, Arg4);
4596 if Is_Compilation_Unit (Hom_Id) then
4598 -- Its possible homonyms are not affected by the pragma.
4599 -- Such homonyms might be present in the context of other
4600 -- units being compiled.
4605 Hom_Id := Homonym (Hom_Id);
4609 -- When the convention is Java or CIL, we also allow Import to be
4610 -- given for packages, generic packages, exceptions, record
4611 -- components, and access to subprograms.
4613 elsif (C = Convention_Java or else C = Convention_CIL)
4615 (Is_Package_Or_Generic_Package (Def_Id)
4616 or else Ekind (Def_Id) = E_Exception
4617 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4618 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4620 Set_Imported (Def_Id);
4621 Set_Is_Public (Def_Id);
4622 Process_Interface_Name (Def_Id, Arg3, Arg4);
4624 -- Import a CPP class
4626 elsif C = Convention_CPP
4627 and then (Is_Record_Type (Def_Id)
4628 or else Ekind (Def_Id) = E_Incomplete_Type)
4630 if Ekind (Def_Id) = E_Incomplete_Type then
4631 if Present (Full_View (Def_Id)) then
4632 Def_Id := Full_View (Def_Id);
4636 ("cannot import 'C'P'P type before full declaration seen",
4637 Get_Pragma_Arg (Arg2));
4639 -- Although we have reported the error we decorate it as
4640 -- CPP_Class to avoid reporting spurious errors
4642 Set_Is_CPP_Class (Def_Id);
4647 -- Types treated as CPP classes must be declared limited (note:
4648 -- this used to be a warning but there is no real benefit to it
4649 -- since we did effectively intend to treat the type as limited
4652 if not Is_Limited_Type (Def_Id) then
4654 ("imported 'C'P'P type must be limited",
4655 Get_Pragma_Arg (Arg2));
4658 Set_Is_CPP_Class (Def_Id);
4660 -- Imported CPP types must not have discriminants (because C++
4661 -- classes do not have discriminants).
4663 if Has_Discriminants (Def_Id) then
4665 ("imported 'C'P'P type cannot have discriminants",
4666 First (Discriminant_Specifications
4667 (Declaration_Node (Def_Id))));
4670 -- Check that components of imported CPP types do not have default
4671 -- expressions. For private types this check is performed when the
4672 -- full view is analyzed (see Process_Full_View).
4674 if not Is_Private_Type (Def_Id) then
4675 Check_CPP_Type_Has_No_Defaults (Def_Id);
4678 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4680 Check_Arg_Count (3);
4681 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4683 Process_Import_Predefined_Type;
4687 ("second argument of pragma% must be object, subprogram "
4688 & "or incomplete type",
4692 -- If this pragma applies to a compilation unit, then the unit, which
4693 -- is a subprogram, does not require (or allow) a body. We also do
4694 -- not need to elaborate imported procedures.
4696 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4698 Cunit : constant Node_Id := Parent (Parent (N));
4700 Set_Body_Required (Cunit, False);
4703 end Process_Import_Or_Interface;
4705 --------------------
4706 -- Process_Inline --
4707 --------------------
4709 procedure Process_Inline (Active : Boolean) is
4716 Effective : Boolean := False;
4717 -- Set True if inline has some effect, i.e. if there is at least one
4718 -- subprogram set as inlined as a result of the use of the pragma.
4720 procedure Make_Inline (Subp : Entity_Id);
4721 -- Subp is the defining unit name of the subprogram declaration. Set
4722 -- the flag, as well as the flag in the corresponding body, if there
4725 procedure Set_Inline_Flags (Subp : Entity_Id);
4726 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4727 -- Has_Pragma_Inline_Always for the Inline_Always case.
4729 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4730 -- Returns True if it can be determined at this stage that inlining
4731 -- is not possible, for example if the body is available and contains
4732 -- exception handlers, we prevent inlining, since otherwise we can
4733 -- get undefined symbols at link time. This function also emits a
4734 -- warning if front-end inlining is enabled and the pragma appears
4737 -- ??? is business with link symbols still valid, or does it relate
4738 -- to front end ZCX which is being phased out ???
4740 ---------------------------
4741 -- Inlining_Not_Possible --
4742 ---------------------------
4744 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4745 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4749 if Nkind (Decl) = N_Subprogram_Body then
4750 Stats := Handled_Statement_Sequence (Decl);
4751 return Present (Exception_Handlers (Stats))
4752 or else Present (At_End_Proc (Stats));
4754 elsif Nkind (Decl) = N_Subprogram_Declaration
4755 and then Present (Corresponding_Body (Decl))
4757 if Front_End_Inlining
4758 and then Analyzed (Corresponding_Body (Decl))
4760 Error_Msg_N ("pragma appears too late, ignored?", N);
4763 -- If the subprogram is a renaming as body, the body is just a
4764 -- call to the renamed subprogram, and inlining is trivially
4768 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4769 N_Subprogram_Renaming_Declaration
4775 Handled_Statement_Sequence
4776 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4779 Present (Exception_Handlers (Stats))
4780 or else Present (At_End_Proc (Stats));
4784 -- If body is not available, assume the best, the check is
4785 -- performed again when compiling enclosing package bodies.
4789 end Inlining_Not_Possible;
4795 procedure Make_Inline (Subp : Entity_Id) is
4796 Kind : constant Entity_Kind := Ekind (Subp);
4797 Inner_Subp : Entity_Id := Subp;
4800 -- Ignore if bad type, avoid cascaded error
4802 if Etype (Subp) = Any_Type then
4806 -- Ignore if all inlining is suppressed
4808 elsif Suppress_All_Inlining then
4812 -- If inlining is not possible, for now do not treat as an error
4814 elsif Inlining_Not_Possible (Subp) then
4818 -- Here we have a candidate for inlining, but we must exclude
4819 -- derived operations. Otherwise we would end up trying to inline
4820 -- a phantom declaration, and the result would be to drag in a
4821 -- body which has no direct inlining associated with it. That
4822 -- would not only be inefficient but would also result in the
4823 -- backend doing cross-unit inlining in cases where it was
4824 -- definitely inappropriate to do so.
4826 -- However, a simple Comes_From_Source test is insufficient, since
4827 -- we do want to allow inlining of generic instances which also do
4828 -- not come from source. We also need to recognize specs generated
4829 -- by the front-end for bodies that carry the pragma. Finally,
4830 -- predefined operators do not come from source but are not
4831 -- inlineable either.
4833 elsif Is_Generic_Instance (Subp)
4834 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4838 elsif not Comes_From_Source (Subp)
4839 and then Scope (Subp) /= Standard_Standard
4845 -- The referenced entity must either be the enclosing entity, or
4846 -- an entity declared within the current open scope.
4848 if Present (Scope (Subp))
4849 and then Scope (Subp) /= Current_Scope
4850 and then Subp /= Current_Scope
4853 ("argument of% must be entity in current scope", Assoc);
4857 -- Processing for procedure, operator or function. If subprogram
4858 -- is aliased (as for an instance) indicate that the renamed
4859 -- entity (if declared in the same unit) is inlined.
4861 if Is_Subprogram (Subp) then
4862 Inner_Subp := Ultimate_Alias (Inner_Subp);
4864 if In_Same_Source_Unit (Subp, Inner_Subp) then
4865 Set_Inline_Flags (Inner_Subp);
4867 Decl := Parent (Parent (Inner_Subp));
4869 if Nkind (Decl) = N_Subprogram_Declaration
4870 and then Present (Corresponding_Body (Decl))
4872 Set_Inline_Flags (Corresponding_Body (Decl));
4874 elsif Is_Generic_Instance (Subp) then
4876 -- Indicate that the body needs to be created for
4877 -- inlining subsequent calls. The instantiation node
4878 -- follows the declaration of the wrapper package
4881 if Scope (Subp) /= Standard_Standard
4883 Need_Subprogram_Instance_Body
4884 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4890 -- Inline is a program unit pragma (RM 10.1.5) and cannot
4891 -- appear in a formal part to apply to a formal subprogram.
4892 -- Do not apply check within an instance or a formal package
4893 -- the test will have been applied to the original generic.
4895 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4896 and then List_Containing (Decl) = List_Containing (N)
4897 and then not In_Instance
4900 ("Inline cannot apply to a formal subprogram", N);
4906 -- For a generic subprogram set flag as well, for use at the point
4907 -- of instantiation, to determine whether the body should be
4910 elsif Is_Generic_Subprogram (Subp) then
4911 Set_Inline_Flags (Subp);
4914 -- Literals are by definition inlined
4916 elsif Kind = E_Enumeration_Literal then
4919 -- Anything else is an error
4923 ("expect subprogram name for pragma%", Assoc);
4927 ----------------------
4928 -- Set_Inline_Flags --
4929 ----------------------
4931 procedure Set_Inline_Flags (Subp : Entity_Id) is
4934 Set_Is_Inlined (Subp);
4937 if not Has_Pragma_Inline (Subp) then
4938 Set_Has_Pragma_Inline (Subp);
4942 if Prag_Id = Pragma_Inline_Always then
4943 Set_Has_Pragma_Inline_Always (Subp);
4945 end Set_Inline_Flags;
4947 -- Start of processing for Process_Inline
4950 Check_No_Identifiers;
4951 Check_At_Least_N_Arguments (1);
4954 Inline_Processing_Required := True;
4958 while Present (Assoc) loop
4959 Subp_Id := Get_Pragma_Arg (Assoc);
4963 if Is_Entity_Name (Subp_Id) then
4964 Subp := Entity (Subp_Id);
4966 if Subp = Any_Id then
4968 -- If previous error, avoid cascaded errors
4976 -- For the pragma case, climb homonym chain. This is
4977 -- what implements allowing the pragma in the renaming
4978 -- case, with the result applying to the ancestors, and
4979 -- also allows Inline to apply to all previous homonyms.
4981 if not From_Aspect_Specification (N) then
4982 while Present (Homonym (Subp))
4983 and then Scope (Homonym (Subp)) = Current_Scope
4985 Make_Inline (Homonym (Subp));
4986 Subp := Homonym (Subp);
4994 ("inappropriate argument for pragma%", Assoc);
4997 and then Warn_On_Redundant_Constructs
4998 and then not Suppress_All_Inlining
5000 if Inlining_Not_Possible (Subp) then
5002 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
5005 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
5013 ----------------------------
5014 -- Process_Interface_Name --
5015 ----------------------------
5017 procedure Process_Interface_Name
5018 (Subprogram_Def : Entity_Id;
5024 String_Val : String_Id;
5026 procedure Check_Form_Of_Interface_Name
5028 Ext_Name_Case : Boolean);
5029 -- SN is a string literal node for an interface name. This routine
5030 -- performs some minimal checks that the name is reasonable. In
5031 -- particular that no spaces or other obviously incorrect characters
5032 -- appear. This is only a warning, since any characters are allowed.
5033 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5035 ----------------------------------
5036 -- Check_Form_Of_Interface_Name --
5037 ----------------------------------
5039 procedure Check_Form_Of_Interface_Name
5041 Ext_Name_Case : Boolean)
5043 S : constant String_Id := Strval (Expr_Value_S (SN));
5044 SL : constant Nat := String_Length (S);
5049 Error_Msg_N ("interface name cannot be null string", SN);
5052 for J in 1 .. SL loop
5053 C := Get_String_Char (S, J);
5055 -- Look for dubious character and issue unconditional warning.
5056 -- Definitely dubious if not in character range.
5058 if not In_Character_Range (C)
5060 -- For all cases except CLI target,
5061 -- commas, spaces and slashes are dubious (in CLI, we use
5062 -- commas and backslashes in external names to specify
5063 -- assembly version and public key, while slashes and spaces
5064 -- can be used in names to mark nested classes and
5067 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5068 and then (Get_Character (C) = ','
5070 Get_Character (C) = '\'))
5071 or else (VM_Target /= CLI_Target
5072 and then (Get_Character (C) = ' '
5074 Get_Character (C) = '/'))
5077 ("?interface name contains illegal character",
5078 Sloc (SN) + Source_Ptr (J));
5081 end Check_Form_Of_Interface_Name;
5083 -- Start of processing for Process_Interface_Name
5086 if No (Link_Arg) then
5087 if No (Ext_Arg) then
5088 if VM_Target = CLI_Target
5089 and then Ekind (Subprogram_Def) = E_Package
5090 and then Nkind (Parent (Subprogram_Def)) =
5091 N_Package_Specification
5092 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5097 (Generic_Parent (Parent (Subprogram_Def))));
5102 elsif Chars (Ext_Arg) = Name_Link_Name then
5104 Link_Nam := Expression (Ext_Arg);
5107 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5108 Ext_Nam := Expression (Ext_Arg);
5113 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5114 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5115 Ext_Nam := Expression (Ext_Arg);
5116 Link_Nam := Expression (Link_Arg);
5119 -- Check expressions for external name and link name are static
5121 if Present (Ext_Nam) then
5122 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5123 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5125 -- Verify that external name is not the name of a local entity,
5126 -- which would hide the imported one and could lead to run-time
5127 -- surprises. The problem can only arise for entities declared in
5128 -- a package body (otherwise the external name is fully qualified
5129 -- and will not conflict).
5137 if Prag_Id = Pragma_Import then
5138 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5140 E := Entity_Id (Get_Name_Table_Info (Nam));
5142 if Nam /= Chars (Subprogram_Def)
5143 and then Present (E)
5144 and then not Is_Overloadable (E)
5145 and then Is_Immediately_Visible (E)
5146 and then not Is_Imported (E)
5147 and then Ekind (Scope (E)) = E_Package
5150 while Present (Par) loop
5151 if Nkind (Par) = N_Package_Body then
5152 Error_Msg_Sloc := Sloc (E);
5154 ("imported entity is hidden by & declared#",
5159 Par := Parent (Par);
5166 if Present (Link_Nam) then
5167 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5168 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5171 -- If there is no link name, just set the external name
5173 if No (Link_Nam) then
5174 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5176 -- For the Link_Name case, the given literal is preceded by an
5177 -- asterisk, which indicates to GCC that the given name should be
5178 -- taken literally, and in particular that no prepending of
5179 -- underlines should occur, even in systems where this is the
5185 if VM_Target = No_VM then
5186 Store_String_Char (Get_Char_Code ('*'));
5189 String_Val := Strval (Expr_Value_S (Link_Nam));
5190 Store_String_Chars (String_Val);
5192 Make_String_Literal (Sloc (Link_Nam),
5193 Strval => End_String);
5196 -- Set the interface name. If the entity is a generic instance, use
5197 -- its alias, which is the callable entity.
5199 if Is_Generic_Instance (Subprogram_Def) then
5200 Set_Encoded_Interface_Name
5201 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5203 Set_Encoded_Interface_Name
5204 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5207 -- We allow duplicated export names in CIL/Java, as they are always
5208 -- enclosed in a namespace that differentiates them, and overloaded
5209 -- entities are supported by the VM.
5211 if Convention (Subprogram_Def) /= Convention_CIL
5213 Convention (Subprogram_Def) /= Convention_Java
5215 Check_Duplicated_Export_Name (Link_Nam);
5217 end Process_Interface_Name;
5219 -----------------------------------------
5220 -- Process_Interrupt_Or_Attach_Handler --
5221 -----------------------------------------
5223 procedure Process_Interrupt_Or_Attach_Handler is
5224 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5225 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5226 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5229 Set_Is_Interrupt_Handler (Handler_Proc);
5231 -- If the pragma is not associated with a handler procedure within a
5232 -- protected type, then it must be for a nonprotected procedure for
5233 -- the AAMP target, in which case we don't associate a representation
5234 -- item with the procedure's scope.
5236 if Ekind (Proc_Scope) = E_Protected_Type then
5237 if Prag_Id = Pragma_Interrupt_Handler
5239 Prag_Id = Pragma_Attach_Handler
5241 Record_Rep_Item (Proc_Scope, N);
5244 end Process_Interrupt_Or_Attach_Handler;
5246 --------------------------------------------------
5247 -- Process_Restrictions_Or_Restriction_Warnings --
5248 --------------------------------------------------
5250 -- Note: some of the simple identifier cases were handled in par-prag,
5251 -- but it is harmless (and more straightforward) to simply handle all
5252 -- cases here, even if it means we repeat a bit of work in some cases.
5254 procedure Process_Restrictions_Or_Restriction_Warnings
5258 R_Id : Restriction_Id;
5263 procedure Check_Unit_Name (N : Node_Id);
5264 -- Checks unit name parameter for No_Dependence. Returns if it has
5265 -- an appropriate form, otherwise raises pragma argument error.
5267 ---------------------
5268 -- Check_Unit_Name --
5269 ---------------------
5271 procedure Check_Unit_Name (N : Node_Id) is
5273 if Nkind (N) = N_Selected_Component then
5274 Check_Unit_Name (Prefix (N));
5275 Check_Unit_Name (Selector_Name (N));
5277 elsif Nkind (N) = N_Identifier then
5282 ("wrong form for unit name for No_Dependence", N);
5284 end Check_Unit_Name;
5286 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5289 -- Ignore all Restrictions pragma in CodePeer mode
5291 if CodePeer_Mode then
5295 Check_Ada_83_Warning;
5296 Check_At_Least_N_Arguments (1);
5297 Check_Valid_Configuration_Pragma;
5300 while Present (Arg) loop
5302 Expr := Get_Pragma_Arg (Arg);
5304 -- Case of no restriction identifier present
5306 if Id = No_Name then
5307 if Nkind (Expr) /= N_Identifier then
5309 ("invalid form for restriction", Arg);
5314 (Process_Restriction_Synonyms (Expr));
5316 if R_Id not in All_Boolean_Restrictions then
5317 Error_Msg_Name_1 := Pname;
5319 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5321 -- Check for possible misspelling
5323 for J in Restriction_Id loop
5325 Rnm : constant String := Restriction_Id'Image (J);
5328 Name_Buffer (1 .. Rnm'Length) := Rnm;
5329 Name_Len := Rnm'Length;
5330 Set_Casing (All_Lower_Case);
5332 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5334 (Identifier_Casing (Current_Source_File));
5335 Error_Msg_String (1 .. Rnm'Length) :=
5336 Name_Buffer (1 .. Name_Len);
5337 Error_Msg_Strlen := Rnm'Length;
5338 Error_Msg_N -- CODEFIX
5339 ("\possible misspelling of ""~""",
5340 Get_Pragma_Arg (Arg));
5349 if Implementation_Restriction (R_Id) then
5350 Check_Restriction (No_Implementation_Restrictions, Arg);
5353 -- Special processing for No_Elaboration_Code restriction
5355 if R_Id = No_Elaboration_Code then
5357 -- Restriction is only recognized within a configuration
5358 -- pragma file, or within a unit of the main extended
5359 -- program. Note: the test for Main_Unit is needed to
5360 -- properly include the case of configuration pragma files.
5362 if not (Current_Sem_Unit = Main_Unit
5363 or else In_Extended_Main_Source_Unit (N))
5367 -- Don't allow in a subunit unless already specified in
5370 elsif Nkind (Parent (N)) = N_Compilation_Unit
5371 and then Nkind (Unit (Parent (N))) = N_Subunit
5372 and then not Restriction_Active (No_Elaboration_Code)
5375 ("invalid specification of ""No_Elaboration_Code""",
5378 ("\restriction cannot be specified in a subunit", N);
5380 ("\unless also specified in body or spec", N);
5383 -- If we have a No_Elaboration_Code pragma that we
5384 -- accept, then it needs to be added to the configuration
5385 -- restrcition set so that we get proper application to
5386 -- other units in the main extended source as required.
5389 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
5393 -- If this is a warning, then set the warning unless we already
5394 -- have a real restriction active (we never want a warning to
5395 -- override a real restriction).
5398 if not Restriction_Active (R_Id) then
5399 Set_Restriction (R_Id, N);
5400 Restriction_Warnings (R_Id) := True;
5403 -- If real restriction case, then set it and make sure that the
5404 -- restriction warning flag is off, since a real restriction
5405 -- always overrides a warning.
5408 Set_Restriction (R_Id, N);
5409 Restriction_Warnings (R_Id) := False;
5412 -- Check for obsolescent restrictions in Ada 2005 mode
5415 and then Ada_Version >= Ada_2005
5416 and then (R_Id = No_Asynchronous_Control
5418 R_Id = No_Unchecked_Deallocation
5420 R_Id = No_Unchecked_Conversion)
5422 Check_Restriction (No_Obsolescent_Features, N);
5425 -- A very special case that must be processed here: pragma
5426 -- Restrictions (No_Exceptions) turns off all run-time
5427 -- checking. This is a bit dubious in terms of the formal
5428 -- language definition, but it is what is intended by RM
5429 -- H.4(12). Restriction_Warnings never affects generated code
5430 -- so this is done only in the real restriction case.
5432 -- Atomic_Synchronization is not a real check, so it is not
5433 -- affected by this processing).
5435 if R_Id = No_Exceptions and then not Warn then
5436 for J in Scope_Suppress'Range loop
5437 if J /= Atomic_Synchronization then
5438 Scope_Suppress (J) := True;
5443 -- Case of No_Dependence => unit-name. Note that the parser
5444 -- already made the necessary entry in the No_Dependence table.
5446 elsif Id = Name_No_Dependence then
5447 Check_Unit_Name (Expr);
5449 -- Case of No_Specification_Of_Aspect => Identifier.
5451 elsif Id = Name_No_Specification_Of_Aspect then
5456 if Nkind (Expr) /= N_Identifier then
5459 A_Id := Get_Aspect_Id (Chars (Expr));
5462 if A_Id = No_Aspect then
5463 Error_Pragma_Arg ("invalid restriction name", Arg);
5465 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5469 -- All other cases of restriction identifier present
5472 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5473 Analyze_And_Resolve (Expr, Any_Integer);
5475 if R_Id not in All_Parameter_Restrictions then
5477 ("invalid restriction parameter identifier", Arg);
5479 elsif not Is_OK_Static_Expression (Expr) then
5480 Flag_Non_Static_Expr
5481 ("value must be static expression!", Expr);
5484 elsif not Is_Integer_Type (Etype (Expr))
5485 or else Expr_Value (Expr) < 0
5488 ("value must be non-negative integer", Arg);
5491 -- Restriction pragma is active
5493 Val := Expr_Value (Expr);
5495 if not UI_Is_In_Int_Range (Val) then
5497 ("pragma ignored, value too large?", Arg);
5500 -- Warning case. If the real restriction is active, then we
5501 -- ignore the request, since warning never overrides a real
5502 -- restriction. Otherwise we set the proper warning. Note that
5503 -- this circuit sets the warning again if it is already set,
5504 -- which is what we want, since the constant may have changed.
5507 if not Restriction_Active (R_Id) then
5509 (R_Id, N, Integer (UI_To_Int (Val)));
5510 Restriction_Warnings (R_Id) := True;
5513 -- Real restriction case, set restriction and make sure warning
5514 -- flag is off since real restriction always overrides warning.
5517 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5518 Restriction_Warnings (R_Id) := False;
5524 end Process_Restrictions_Or_Restriction_Warnings;
5526 ---------------------------------
5527 -- Process_Suppress_Unsuppress --
5528 ---------------------------------
5530 -- Note: this procedure makes entries in the check suppress data
5531 -- structures managed by Sem. See spec of package Sem for full
5532 -- details on how we handle recording of check suppression.
5534 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5539 In_Package_Spec : constant Boolean :=
5540 Is_Package_Or_Generic_Package (Current_Scope)
5541 and then not In_Package_Body (Current_Scope);
5543 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5544 -- Used to suppress a single check on the given entity
5546 --------------------------------
5547 -- Suppress_Unsuppress_Echeck --
5548 --------------------------------
5550 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5552 -- Check for error of trying to set atomic synchronization for
5553 -- a non-atomic variable.
5555 if C = Atomic_Synchronization
5556 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5559 ("pragma & requires atomic type or variable",
5560 Pragma_Identifier (Original_Node (N)));
5563 Set_Checks_May_Be_Suppressed (E);
5565 if In_Package_Spec then
5566 Push_Global_Suppress_Stack_Entry
5569 Suppress => Suppress_Case);
5571 Push_Local_Suppress_Stack_Entry
5574 Suppress => Suppress_Case);
5577 -- If this is a first subtype, and the base type is distinct,
5578 -- then also set the suppress flags on the base type.
5580 if Is_First_Subtype (E)
5581 and then Etype (E) /= E
5583 Suppress_Unsuppress_Echeck (Etype (E), C);
5585 end Suppress_Unsuppress_Echeck;
5587 -- Start of processing for Process_Suppress_Unsuppress
5590 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5591 -- user code: we want to generate checks for analysis purposes, as
5592 -- set respectively by -gnatC and -gnatd.F
5594 if (CodePeer_Mode or Alfa_Mode)
5595 and then Comes_From_Source (N)
5600 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5601 -- declarative part or a package spec (RM 11.5(5)).
5603 if not Is_Configuration_Pragma then
5604 Check_Is_In_Decl_Part_Or_Package_Spec;
5607 Check_At_Least_N_Arguments (1);
5608 Check_At_Most_N_Arguments (2);
5609 Check_No_Identifier (Arg1);
5610 Check_Arg_Is_Identifier (Arg1);
5612 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5614 if C = No_Check_Id then
5616 ("argument of pragma% is not valid check name", Arg1);
5619 if not Suppress_Case
5620 and then (C = All_Checks or else C = Overflow_Check)
5622 Opt.Overflow_Checks_Unsuppressed := True;
5625 if Arg_Count = 1 then
5627 -- Make an entry in the local scope suppress table. This is the
5628 -- table that directly shows the current value of the scope
5629 -- suppress check for any check id value.
5631 if C = All_Checks then
5633 -- For All_Checks, we set all specific predefined checks with
5634 -- the exception of Elaboration_Check, which is handled
5635 -- specially because of not wanting All_Checks to have the
5636 -- effect of deactivating static elaboration order processing.
5637 -- Atomic_Synchronization is also not affected, since this is
5638 -- not a real check.
5640 for J in Scope_Suppress'Range loop
5641 if J /= Elaboration_Check
5642 and then J /= Atomic_Synchronization
5644 Scope_Suppress (J) := Suppress_Case;
5648 -- If not All_Checks, and predefined check, then set appropriate
5649 -- scope entry. Note that we will set Elaboration_Check if this
5650 -- is explicitly specified. Atomic_Synchronization is allowed
5651 -- only if internally generated and entity is atomic.
5653 elsif C in Predefined_Check_Id
5654 and then (not Comes_From_Source (N)
5655 or else C /= Atomic_Synchronization)
5657 Scope_Suppress (C) := Suppress_Case;
5660 -- Also make an entry in the Local_Entity_Suppress table
5662 Push_Local_Suppress_Stack_Entry
5665 Suppress => Suppress_Case);
5667 -- Case of two arguments present, where the check is suppressed for
5668 -- a specified entity (given as the second argument of the pragma)
5671 -- This is obsolescent in Ada 2005 mode
5673 if Ada_Version >= Ada_2005 then
5674 Check_Restriction (No_Obsolescent_Features, Arg2);
5677 Check_Optional_Identifier (Arg2, Name_On);
5678 E_Id := Get_Pragma_Arg (Arg2);
5681 if not Is_Entity_Name (E_Id) then
5683 ("second argument of pragma% must be entity name", Arg2);
5692 -- Enforce RM 11.5(7) which requires that for a pragma that
5693 -- appears within a package spec, the named entity must be
5694 -- within the package spec. We allow the package name itself
5695 -- to be mentioned since that makes sense, although it is not
5696 -- strictly allowed by 11.5(7).
5699 and then E /= Current_Scope
5700 and then Scope (E) /= Current_Scope
5703 ("entity in pragma% is not in package spec (RM 11.5(7))",
5707 -- Loop through homonyms. As noted below, in the case of a package
5708 -- spec, only homonyms within the package spec are considered.
5711 Suppress_Unsuppress_Echeck (E, C);
5713 if Is_Generic_Instance (E)
5714 and then Is_Subprogram (E)
5715 and then Present (Alias (E))
5717 Suppress_Unsuppress_Echeck (Alias (E), C);
5720 -- Move to next homonym if not aspect spec case
5722 exit when From_Aspect_Specification (N);
5726 -- If we are within a package specification, the pragma only
5727 -- applies to homonyms in the same scope.
5729 exit when In_Package_Spec
5730 and then Scope (E) /= Current_Scope;
5733 end Process_Suppress_Unsuppress;
5739 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5741 if Is_Imported (E) then
5743 ("cannot export entity& that was previously imported", Arg);
5745 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5747 ("cannot export entity& that has an address clause", Arg);
5750 Set_Is_Exported (E);
5752 -- Generate a reference for entity explicitly, because the
5753 -- identifier may be overloaded and name resolution will not
5756 Generate_Reference (E, Arg);
5758 -- Deal with exporting non-library level entity
5760 if not Is_Library_Level_Entity (E) then
5762 -- Not allowed at all for subprograms
5764 if Is_Subprogram (E) then
5765 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5767 -- Otherwise set public and statically allocated
5771 Set_Is_Statically_Allocated (E);
5773 -- Warn if the corresponding W flag is set and the pragma comes
5774 -- from source. The latter may not be true e.g. on VMS where we
5775 -- expand export pragmas for exception codes associated with
5776 -- imported or exported exceptions. We do not want to generate
5777 -- a warning for something that the user did not write.
5779 if Warn_On_Export_Import
5780 and then Comes_From_Source (Arg)
5783 ("?& has been made static as a result of Export", Arg, E);
5785 ("\this usage is non-standard and non-portable", Arg);
5790 if Warn_On_Export_Import and then Is_Type (E) then
5791 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5794 if Warn_On_Export_Import and Inside_A_Generic then
5796 ("all instances of& will have the same external name?", Arg, E);
5800 ----------------------------------------------
5801 -- Set_Extended_Import_Export_External_Name --
5802 ----------------------------------------------
5804 procedure Set_Extended_Import_Export_External_Name
5805 (Internal_Ent : Entity_Id;
5806 Arg_External : Node_Id)
5808 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5812 if No (Arg_External) then
5816 Check_Arg_Is_External_Name (Arg_External);
5818 if Nkind (Arg_External) = N_String_Literal then
5819 if String_Length (Strval (Arg_External)) = 0 then
5822 New_Name := Adjust_External_Name_Case (Arg_External);
5825 elsif Nkind (Arg_External) = N_Identifier then
5826 New_Name := Get_Default_External_Name (Arg_External);
5828 -- Check_Arg_Is_External_Name should let through only identifiers and
5829 -- string literals or static string expressions (which are folded to
5830 -- string literals).
5833 raise Program_Error;
5836 -- If we already have an external name set (by a prior normal Import
5837 -- or Export pragma), then the external names must match
5839 if Present (Interface_Name (Internal_Ent)) then
5840 Check_Matching_Internal_Names : declare
5841 S1 : constant String_Id := Strval (Old_Name);
5842 S2 : constant String_Id := Strval (New_Name);
5845 -- Called if names do not match
5851 procedure Mismatch is
5853 Error_Msg_Sloc := Sloc (Old_Name);
5855 ("external name does not match that given #",
5859 -- Start of processing for Check_Matching_Internal_Names
5862 if String_Length (S1) /= String_Length (S2) then
5866 for J in 1 .. String_Length (S1) loop
5867 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5872 end Check_Matching_Internal_Names;
5874 -- Otherwise set the given name
5877 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5878 Check_Duplicated_Export_Name (New_Name);
5880 end Set_Extended_Import_Export_External_Name;
5886 procedure Set_Imported (E : Entity_Id) is
5888 -- Error message if already imported or exported
5890 if Is_Exported (E) or else Is_Imported (E) then
5892 -- Error if being set Exported twice
5894 if Is_Exported (E) then
5895 Error_Msg_NE ("entity& was previously exported", N, E);
5897 -- OK if Import/Interface case
5899 elsif Import_Interface_Present (N) then
5902 -- Error if being set Imported twice
5905 Error_Msg_NE ("entity& was previously imported", N, E);
5908 Error_Msg_Name_1 := Pname;
5910 ("\(pragma% applies to all previous entities)", N);
5912 Error_Msg_Sloc := Sloc (E);
5913 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5915 -- Here if not previously imported or exported, OK to import
5918 Set_Is_Imported (E);
5920 -- If the entity is an object that is not at the library level,
5921 -- then it is statically allocated. We do not worry about objects
5922 -- with address clauses in this context since they are not really
5923 -- imported in the linker sense.
5926 and then not Is_Library_Level_Entity (E)
5927 and then No (Address_Clause (E))
5929 Set_Is_Statically_Allocated (E);
5936 -------------------------
5937 -- Set_Mechanism_Value --
5938 -------------------------
5940 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5941 -- analyzed, since it is semantic nonsense), so we get it in the exact
5942 -- form created by the parser.
5944 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5947 Mech_Name_Id : Name_Id;
5949 procedure Bad_Class;
5950 -- Signal bad descriptor class name
5952 procedure Bad_Mechanism;
5953 -- Signal bad mechanism name
5959 procedure Bad_Class is
5961 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5964 -------------------------
5965 -- Bad_Mechanism_Value --
5966 -------------------------
5968 procedure Bad_Mechanism is
5970 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5973 -- Start of processing for Set_Mechanism_Value
5976 if Mechanism (Ent) /= Default_Mechanism then
5978 ("mechanism for & has already been set", Mech_Name, Ent);
5981 -- MECHANISM_NAME ::= value | reference | descriptor |
5984 if Nkind (Mech_Name) = N_Identifier then
5985 if Chars (Mech_Name) = Name_Value then
5986 Set_Mechanism (Ent, By_Copy);
5989 elsif Chars (Mech_Name) = Name_Reference then
5990 Set_Mechanism (Ent, By_Reference);
5993 elsif Chars (Mech_Name) = Name_Descriptor then
5994 Check_VMS (Mech_Name);
5996 -- Descriptor => Short_Descriptor if pragma was given
5998 if Short_Descriptors then
5999 Set_Mechanism (Ent, By_Short_Descriptor);
6001 Set_Mechanism (Ent, By_Descriptor);
6006 elsif Chars (Mech_Name) = Name_Short_Descriptor then
6007 Check_VMS (Mech_Name);
6008 Set_Mechanism (Ent, By_Short_Descriptor);
6011 elsif Chars (Mech_Name) = Name_Copy then
6013 ("bad mechanism name, Value assumed", Mech_Name);
6019 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
6020 -- short_descriptor (CLASS_NAME)
6021 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6023 -- Note: this form is parsed as an indexed component
6025 elsif Nkind (Mech_Name) = N_Indexed_Component then
6026 Class := First (Expressions (Mech_Name));
6028 if Nkind (Prefix (Mech_Name)) /= N_Identifier
6029 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
6030 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
6031 or else Present (Next (Class))
6035 Mech_Name_Id := Chars (Prefix (Mech_Name));
6037 -- Change Descriptor => Short_Descriptor if pragma was given
6039 if Mech_Name_Id = Name_Descriptor
6040 and then Short_Descriptors
6042 Mech_Name_Id := Name_Short_Descriptor;
6046 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6047 -- short_descriptor (Class => CLASS_NAME)
6048 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6050 -- Note: this form is parsed as a function call
6052 elsif Nkind (Mech_Name) = N_Function_Call then
6053 Param := First (Parameter_Associations (Mech_Name));
6055 if Nkind (Name (Mech_Name)) /= N_Identifier
6056 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6057 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6058 or else Present (Next (Param))
6059 or else No (Selector_Name (Param))
6060 or else Chars (Selector_Name (Param)) /= Name_Class
6064 Class := Explicit_Actual_Parameter (Param);
6065 Mech_Name_Id := Chars (Name (Mech_Name));
6072 -- Fall through here with Class set to descriptor class name
6074 Check_VMS (Mech_Name);
6076 if Nkind (Class) /= N_Identifier then
6079 elsif Mech_Name_Id = Name_Descriptor
6080 and then Chars (Class) = Name_UBS
6082 Set_Mechanism (Ent, By_Descriptor_UBS);
6084 elsif Mech_Name_Id = Name_Descriptor
6085 and then Chars (Class) = Name_UBSB
6087 Set_Mechanism (Ent, By_Descriptor_UBSB);
6089 elsif Mech_Name_Id = Name_Descriptor
6090 and then Chars (Class) = Name_UBA
6092 Set_Mechanism (Ent, By_Descriptor_UBA);
6094 elsif Mech_Name_Id = Name_Descriptor
6095 and then Chars (Class) = Name_S
6097 Set_Mechanism (Ent, By_Descriptor_S);
6099 elsif Mech_Name_Id = Name_Descriptor
6100 and then Chars (Class) = Name_SB
6102 Set_Mechanism (Ent, By_Descriptor_SB);
6104 elsif Mech_Name_Id = Name_Descriptor
6105 and then Chars (Class) = Name_A
6107 Set_Mechanism (Ent, By_Descriptor_A);
6109 elsif Mech_Name_Id = Name_Descriptor
6110 and then Chars (Class) = Name_NCA
6112 Set_Mechanism (Ent, By_Descriptor_NCA);
6114 elsif Mech_Name_Id = Name_Short_Descriptor
6115 and then Chars (Class) = Name_UBS
6117 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6119 elsif Mech_Name_Id = Name_Short_Descriptor
6120 and then Chars (Class) = Name_UBSB
6122 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6124 elsif Mech_Name_Id = Name_Short_Descriptor
6125 and then Chars (Class) = Name_UBA
6127 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6129 elsif Mech_Name_Id = Name_Short_Descriptor
6130 and then Chars (Class) = Name_S
6132 Set_Mechanism (Ent, By_Short_Descriptor_S);
6134 elsif Mech_Name_Id = Name_Short_Descriptor
6135 and then Chars (Class) = Name_SB
6137 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6139 elsif Mech_Name_Id = Name_Short_Descriptor
6140 and then Chars (Class) = Name_A
6142 Set_Mechanism (Ent, By_Short_Descriptor_A);
6144 elsif Mech_Name_Id = Name_Short_Descriptor
6145 and then Chars (Class) = Name_NCA
6147 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6152 end Set_Mechanism_Value;
6154 ---------------------------
6155 -- Set_Ravenscar_Profile --
6156 ---------------------------
6158 -- The tasks to be done here are
6160 -- Set required policies
6162 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6163 -- pragma Locking_Policy (Ceiling_Locking)
6165 -- Set Detect_Blocking mode
6167 -- Set required restrictions (see System.Rident for detailed list)
6169 -- Set the No_Dependence rules
6170 -- No_Dependence => Ada.Asynchronous_Task_Control
6171 -- No_Dependence => Ada.Calendar
6172 -- No_Dependence => Ada.Execution_Time.Group_Budget
6173 -- No_Dependence => Ada.Execution_Time.Timers
6174 -- No_Dependence => Ada.Task_Attributes
6175 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6177 procedure Set_Ravenscar_Profile (N : Node_Id) is
6178 Prefix_Entity : Entity_Id;
6179 Selector_Entity : Entity_Id;
6180 Prefix_Node : Node_Id;
6184 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6186 if Task_Dispatching_Policy /= ' '
6187 and then Task_Dispatching_Policy /= 'F'
6189 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6190 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6192 -- Set the FIFO_Within_Priorities policy, but always preserve
6193 -- System_Location since we like the error message with the run time
6197 Task_Dispatching_Policy := 'F';
6199 if Task_Dispatching_Policy_Sloc /= System_Location then
6200 Task_Dispatching_Policy_Sloc := Loc;
6204 -- pragma Locking_Policy (Ceiling_Locking)
6206 if Locking_Policy /= ' '
6207 and then Locking_Policy /= 'C'
6209 Error_Msg_Sloc := Locking_Policy_Sloc;
6210 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6212 -- Set the Ceiling_Locking policy, but preserve System_Location since
6213 -- we like the error message with the run time name.
6216 Locking_Policy := 'C';
6218 if Locking_Policy_Sloc /= System_Location then
6219 Locking_Policy_Sloc := Loc;
6223 -- pragma Detect_Blocking
6225 Detect_Blocking := True;
6227 -- Set the corresponding restrictions
6229 Set_Profile_Restrictions
6230 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6232 -- Set the No_Dependence restrictions
6234 -- The following No_Dependence restrictions:
6235 -- No_Dependence => Ada.Asynchronous_Task_Control
6236 -- No_Dependence => Ada.Calendar
6237 -- No_Dependence => Ada.Task_Attributes
6238 -- are already set by previous call to Set_Profile_Restrictions.
6240 -- Set the following restrictions which were added to Ada 2005:
6241 -- No_Dependence => Ada.Execution_Time.Group_Budget
6242 -- No_Dependence => Ada.Execution_Time.Timers
6244 if Ada_Version >= Ada_2005 then
6245 Name_Buffer (1 .. 3) := "ada";
6248 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6250 Name_Buffer (1 .. 14) := "execution_time";
6253 Selector_Entity := Make_Identifier (Loc, Name_Find);
6256 Make_Selected_Component
6258 Prefix => Prefix_Entity,
6259 Selector_Name => Selector_Entity);
6261 Name_Buffer (1 .. 13) := "group_budgets";
6264 Selector_Entity := Make_Identifier (Loc, Name_Find);
6267 Make_Selected_Component
6269 Prefix => Prefix_Node,
6270 Selector_Name => Selector_Entity);
6272 Set_Restriction_No_Dependence
6274 Warn => Treat_Restrictions_As_Warnings,
6275 Profile => Ravenscar);
6277 Name_Buffer (1 .. 6) := "timers";
6280 Selector_Entity := Make_Identifier (Loc, Name_Find);
6283 Make_Selected_Component
6285 Prefix => Prefix_Node,
6286 Selector_Name => Selector_Entity);
6288 Set_Restriction_No_Dependence
6290 Warn => Treat_Restrictions_As_Warnings,
6291 Profile => Ravenscar);
6294 -- Set the following restrictions which was added to Ada 2012 (see
6296 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6298 if Ada_Version >= Ada_2012 then
6299 Name_Buffer (1 .. 6) := "system";
6302 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6304 Name_Buffer (1 .. 15) := "multiprocessors";
6307 Selector_Entity := Make_Identifier (Loc, Name_Find);
6310 Make_Selected_Component
6312 Prefix => Prefix_Entity,
6313 Selector_Name => Selector_Entity);
6315 Name_Buffer (1 .. 19) := "dispatching_domains";
6318 Selector_Entity := Make_Identifier (Loc, Name_Find);
6321 Make_Selected_Component
6323 Prefix => Prefix_Node,
6324 Selector_Name => Selector_Entity);
6326 Set_Restriction_No_Dependence
6328 Warn => Treat_Restrictions_As_Warnings,
6329 Profile => Ravenscar);
6331 end Set_Ravenscar_Profile;
6333 -- Start of processing for Analyze_Pragma
6336 -- The following code is a defense against recursion. Not clear that
6337 -- this can happen legitimately, but perhaps some error situations
6338 -- can cause it, and we did see this recursion during testing.
6340 if Analyzed (N) then
6343 Set_Analyzed (N, True);
6346 -- Deal with unrecognized pragma
6348 Pname := Pragma_Name (N);
6350 if not Is_Pragma_Name (Pname) then
6351 if Warn_On_Unrecognized_Pragma then
6352 Error_Msg_Name_1 := Pname;
6353 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6355 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6356 if Is_Bad_Spelling_Of (Pname, PN) then
6357 Error_Msg_Name_1 := PN;
6358 Error_Msg_N -- CODEFIX
6359 ("\?possible misspelling of %!", Pragma_Identifier (N));
6368 -- Here to start processing for recognized pragma
6370 Prag_Id := Get_Pragma_Id (Pname);
6372 if Present (Corresponding_Aspect (N)) then
6373 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6384 if Present (Pragma_Argument_Associations (N)) then
6385 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6386 Arg1 := First (Pragma_Argument_Associations (N));
6388 if Present (Arg1) then
6389 Arg2 := Next (Arg1);
6391 if Present (Arg2) then
6392 Arg3 := Next (Arg2);
6394 if Present (Arg3) then
6395 Arg4 := Next (Arg3);
6401 -- An enumeration type defines the pragmas that are supported by the
6402 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6403 -- into the corresponding enumeration value for the following case.
6411 -- pragma Abort_Defer;
6413 when Pragma_Abort_Defer =>
6415 Check_Arg_Count (0);
6417 -- The only required semantic processing is to check the
6418 -- placement. This pragma must appear at the start of the
6419 -- statement sequence of a handled sequence of statements.
6421 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6422 or else N /= First (Statements (Parent (N)))
6433 -- Note: this pragma also has some specific processing in Par.Prag
6434 -- because we want to set the Ada version mode during parsing.
6436 when Pragma_Ada_83 =>
6438 Check_Arg_Count (0);
6440 -- We really should check unconditionally for proper configuration
6441 -- pragma placement, since we really don't want mixed Ada modes
6442 -- within a single unit, and the GNAT reference manual has always
6443 -- said this was a configuration pragma, but we did not check and
6444 -- are hesitant to add the check now.
6446 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6447 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6448 -- or Ada 2012 mode.
6450 if Ada_Version >= Ada_2005 then
6451 Check_Valid_Configuration_Pragma;
6454 -- Now set Ada 83 mode
6456 Ada_Version := Ada_83;
6457 Ada_Version_Explicit := Ada_Version;
6465 -- Note: this pragma also has some specific processing in Par.Prag
6466 -- because we want to set the Ada 83 version mode during parsing.
6468 when Pragma_Ada_95 =>
6470 Check_Arg_Count (0);
6472 -- We really should check unconditionally for proper configuration
6473 -- pragma placement, since we really don't want mixed Ada modes
6474 -- within a single unit, and the GNAT reference manual has always
6475 -- said this was a configuration pragma, but we did not check and
6476 -- are hesitant to add the check now.
6478 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6479 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6481 if Ada_Version >= Ada_2005 then
6482 Check_Valid_Configuration_Pragma;
6485 -- Now set Ada 95 mode
6487 Ada_Version := Ada_95;
6488 Ada_Version_Explicit := Ada_Version;
6490 ---------------------
6491 -- Ada_05/Ada_2005 --
6492 ---------------------
6495 -- pragma Ada_05 (LOCAL_NAME);
6498 -- pragma Ada_2005 (LOCAL_NAME):
6500 -- Note: these pragmas also have some specific processing in Par.Prag
6501 -- because we want to set the Ada 2005 version mode during parsing.
6503 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6509 if Arg_Count = 1 then
6510 Check_Arg_Is_Local_Name (Arg1);
6511 E_Id := Get_Pragma_Arg (Arg1);
6513 if Etype (E_Id) = Any_Type then
6517 Set_Is_Ada_2005_Only (Entity (E_Id));
6520 Check_Arg_Count (0);
6522 -- For Ada_2005 we unconditionally enforce the documented
6523 -- configuration pragma placement, since we do not want to
6524 -- tolerate mixed modes in a unit involving Ada 2005. That
6525 -- would cause real difficulties for those cases where there
6526 -- are incompatibilities between Ada 95 and Ada 2005.
6528 Check_Valid_Configuration_Pragma;
6530 -- Now set appropriate Ada mode
6532 Ada_Version := Ada_2005;
6533 Ada_Version_Explicit := Ada_2005;
6537 ---------------------
6538 -- Ada_12/Ada_2012 --
6539 ---------------------
6542 -- pragma Ada_12 (LOCAL_NAME);
6545 -- pragma Ada_2012 (LOCAL_NAME):
6547 -- Note: these pragmas also have some specific processing in Par.Prag
6548 -- because we want to set the Ada 2012 version mode during parsing.
6550 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6556 if Arg_Count = 1 then
6557 Check_Arg_Is_Local_Name (Arg1);
6558 E_Id := Get_Pragma_Arg (Arg1);
6560 if Etype (E_Id) = Any_Type then
6564 Set_Is_Ada_2012_Only (Entity (E_Id));
6567 Check_Arg_Count (0);
6569 -- For Ada_2012 we unconditionally enforce the documented
6570 -- configuration pragma placement, since we do not want to
6571 -- tolerate mixed modes in a unit involving Ada 2012. That
6572 -- would cause real difficulties for those cases where there
6573 -- are incompatibilities between Ada 95 and Ada 2012. We could
6574 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6576 Check_Valid_Configuration_Pragma;
6578 -- Now set appropriate Ada mode
6580 Ada_Version := Ada_2012;
6581 Ada_Version_Explicit := Ada_2012;
6585 ----------------------
6586 -- All_Calls_Remote --
6587 ----------------------
6589 -- pragma All_Calls_Remote [(library_package_NAME)];
6591 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6592 Lib_Entity : Entity_Id;
6595 Check_Ada_83_Warning;
6596 Check_Valid_Library_Unit_Pragma;
6598 if Nkind (N) = N_Null_Statement then
6602 Lib_Entity := Find_Lib_Unit_Name;
6604 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6606 if Present (Lib_Entity)
6607 and then not Debug_Flag_U
6609 if not Is_Remote_Call_Interface (Lib_Entity) then
6610 Error_Pragma ("pragma% only apply to rci unit");
6612 -- Set flag for entity of the library unit
6615 Set_Has_All_Calls_Remote (Lib_Entity);
6619 end All_Calls_Remote;
6625 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6626 -- ARG ::= NAME | EXPRESSION
6628 -- The first two arguments are by convention intended to refer to an
6629 -- external tool and a tool-specific function. These arguments are
6632 when Pragma_Annotate => Annotate : declare
6638 Check_At_Least_N_Arguments (1);
6639 Check_Arg_Is_Identifier (Arg1);
6640 Check_No_Identifiers;
6643 -- Second parameter is optional, it is never analyzed
6648 -- Here if we have a second parameter
6651 -- Second parameter must be identifier
6653 Check_Arg_Is_Identifier (Arg2);
6655 -- Process remaining parameters if any
6658 while Present (Arg) loop
6659 Exp := Get_Pragma_Arg (Arg);
6662 if Is_Entity_Name (Exp) then
6665 -- For string literals, we assume Standard_String as the
6666 -- type, unless the string contains wide or wide_wide
6669 elsif Nkind (Exp) = N_String_Literal then
6670 if Has_Wide_Wide_Character (Exp) then
6671 Resolve (Exp, Standard_Wide_Wide_String);
6672 elsif Has_Wide_Character (Exp) then
6673 Resolve (Exp, Standard_Wide_String);
6675 Resolve (Exp, Standard_String);
6678 elsif Is_Overloaded (Exp) then
6680 ("ambiguous argument for pragma%", Exp);
6695 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6696 -- [, [Message =>] Static_String_EXPRESSION]);
6698 when Pragma_Assert => Assert : declare
6704 Check_At_Least_N_Arguments (1);
6705 Check_At_Most_N_Arguments (2);
6706 Check_Arg_Order ((Name_Check, Name_Message));
6707 Check_Optional_Identifier (Arg1, Name_Check);
6709 -- We treat pragma Assert as equivalent to:
6711 -- pragma Check (Assertion, condition [, msg]);
6713 -- So rewrite pragma in this manner, and analyze the result
6715 Expr := Get_Pragma_Arg (Arg1);
6717 Make_Pragma_Argument_Association (Loc,
6718 Expression => Make_Identifier (Loc, Name_Assertion)),
6720 Make_Pragma_Argument_Association (Sloc (Expr),
6721 Expression => Expr));
6723 if Arg_Count > 1 then
6724 Check_Optional_Identifier (Arg2, Name_Message);
6725 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6726 Append_To (Newa, Relocate_Node (Arg2));
6731 Chars => Name_Check,
6732 Pragma_Argument_Associations => Newa));
6736 ----------------------
6737 -- Assertion_Policy --
6738 ----------------------
6740 -- pragma Assertion_Policy (Check | Disable |Ignore)
6742 when Pragma_Assertion_Policy => Assertion_Policy : declare
6747 Check_Valid_Configuration_Pragma;
6748 Check_Arg_Count (1);
6749 Check_No_Identifiers;
6750 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6752 -- We treat pragma Assertion_Policy as equivalent to:
6754 -- pragma Check_Policy (Assertion, policy)
6756 -- So rewrite the pragma in that manner and link on to the chain
6757 -- of Check_Policy pragmas, marking the pragma as analyzed.
6759 Policy := Get_Pragma_Arg (Arg1);
6763 Chars => Name_Check_Policy,
6765 Pragma_Argument_Associations => New_List (
6766 Make_Pragma_Argument_Association (Loc,
6767 Expression => Make_Identifier (Loc, Name_Assertion)),
6769 Make_Pragma_Argument_Association (Loc,
6771 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6774 Set_Next_Pragma (N, Opt.Check_Policy_List);
6775 Opt.Check_Policy_List := N;
6776 end Assertion_Policy;
6778 ------------------------------
6779 -- Assume_No_Invalid_Values --
6780 ------------------------------
6782 -- pragma Assume_No_Invalid_Values (On | Off);
6784 when Pragma_Assume_No_Invalid_Values =>
6786 Check_Valid_Configuration_Pragma;
6787 Check_Arg_Count (1);
6788 Check_No_Identifiers;
6789 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6791 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6792 Assume_No_Invalid_Values := True;
6794 Assume_No_Invalid_Values := False;
6801 -- pragma AST_Entry (entry_IDENTIFIER);
6803 when Pragma_AST_Entry => AST_Entry : declare
6809 Check_Arg_Count (1);
6810 Check_No_Identifiers;
6811 Check_Arg_Is_Local_Name (Arg1);
6812 Ent := Entity (Get_Pragma_Arg (Arg1));
6814 -- Note: the implementation of the AST_Entry pragma could handle
6815 -- the entry family case fine, but for now we are consistent with
6816 -- the DEC rules, and do not allow the pragma, which of course
6817 -- has the effect of also forbidding the attribute.
6819 if Ekind (Ent) /= E_Entry then
6821 ("pragma% argument must be simple entry name", Arg1);
6823 elsif Is_AST_Entry (Ent) then
6825 ("duplicate % pragma for entry", Arg1);
6827 elsif Has_Homonym (Ent) then
6829 ("pragma% argument cannot specify overloaded entry", Arg1);
6833 FF : constant Entity_Id := First_Formal (Ent);
6836 if Present (FF) then
6837 if Present (Next_Formal (FF)) then
6839 ("entry for pragma% can have only one argument",
6842 elsif Parameter_Mode (FF) /= E_In_Parameter then
6844 ("entry parameter for pragma% must have mode IN",
6850 Set_Is_AST_Entry (Ent);
6858 -- pragma Asynchronous (LOCAL_NAME);
6860 when Pragma_Asynchronous => Asynchronous : declare
6868 procedure Process_Async_Pragma;
6869 -- Common processing for procedure and access-to-procedure case
6871 --------------------------
6872 -- Process_Async_Pragma --
6873 --------------------------
6875 procedure Process_Async_Pragma is
6878 Set_Is_Asynchronous (Nm);
6882 -- The formals should be of mode IN (RM E.4.1(6))
6885 while Present (S) loop
6886 Formal := Defining_Identifier (S);
6888 if Nkind (Formal) = N_Defining_Identifier
6889 and then Ekind (Formal) /= E_In_Parameter
6892 ("pragma% procedure can only have IN parameter",
6899 Set_Is_Asynchronous (Nm);
6900 end Process_Async_Pragma;
6902 -- Start of processing for pragma Asynchronous
6905 Check_Ada_83_Warning;
6906 Check_No_Identifiers;
6907 Check_Arg_Count (1);
6908 Check_Arg_Is_Local_Name (Arg1);
6910 if Debug_Flag_U then
6914 C_Ent := Cunit_Entity (Current_Sem_Unit);
6915 Analyze (Get_Pragma_Arg (Arg1));
6916 Nm := Entity (Get_Pragma_Arg (Arg1));
6918 if not Is_Remote_Call_Interface (C_Ent)
6919 and then not Is_Remote_Types (C_Ent)
6921 -- This pragma should only appear in an RCI or Remote Types
6922 -- unit (RM E.4.1(4)).
6925 ("pragma% not in Remote_Call_Interface or " &
6926 "Remote_Types unit");
6929 if Ekind (Nm) = E_Procedure
6930 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6932 if not Is_Remote_Call_Interface (Nm) then
6934 ("pragma% cannot be applied on non-remote procedure",
6938 L := Parameter_Specifications (Parent (Nm));
6939 Process_Async_Pragma;
6942 elsif Ekind (Nm) = E_Function then
6944 ("pragma% cannot be applied to function", Arg1);
6946 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6947 if Is_Record_Type (Nm) then
6949 -- A record type that is the Equivalent_Type for a remote
6950 -- access-to-subprogram type.
6952 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6955 -- A non-expanded RAS type (distribution is not enabled)
6957 N := Declaration_Node (Nm);
6960 if Nkind (N) = N_Full_Type_Declaration
6961 and then Nkind (Type_Definition (N)) =
6962 N_Access_Procedure_Definition
6964 L := Parameter_Specifications (Type_Definition (N));
6965 Process_Async_Pragma;
6967 if Is_Asynchronous (Nm)
6968 and then Expander_Active
6969 and then Get_PCS_Name /= Name_No_DSA
6971 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6976 ("pragma% cannot reference access-to-function type",
6980 -- Only other possibility is Access-to-class-wide type
6982 elsif Is_Access_Type (Nm)
6983 and then Is_Class_Wide_Type (Designated_Type (Nm))
6985 Check_First_Subtype (Arg1);
6986 Set_Is_Asynchronous (Nm);
6987 if Expander_Active then
6988 RACW_Type_Is_Asynchronous (Nm);
6992 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
7000 -- pragma Atomic (LOCAL_NAME);
7002 when Pragma_Atomic =>
7003 Process_Atomic_Shared_Volatile;
7005 -----------------------
7006 -- Atomic_Components --
7007 -----------------------
7009 -- pragma Atomic_Components (array_LOCAL_NAME);
7011 -- This processing is shared by Volatile_Components
7013 when Pragma_Atomic_Components |
7014 Pragma_Volatile_Components =>
7016 Atomic_Components : declare
7023 Check_Ada_83_Warning;
7024 Check_No_Identifiers;
7025 Check_Arg_Count (1);
7026 Check_Arg_Is_Local_Name (Arg1);
7027 E_Id := Get_Pragma_Arg (Arg1);
7029 if Etype (E_Id) = Any_Type then
7035 Check_Duplicate_Pragma (E);
7037 if Rep_Item_Too_Early (E, N)
7039 Rep_Item_Too_Late (E, N)
7044 D := Declaration_Node (E);
7047 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7049 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7050 and then Nkind (D) = N_Object_Declaration
7051 and then Nkind (Object_Definition (D)) =
7052 N_Constrained_Array_Definition)
7054 -- The flag is set on the object, or on the base type
7056 if Nkind (D) /= N_Object_Declaration then
7060 Set_Has_Volatile_Components (E);
7062 if Prag_Id = Pragma_Atomic_Components then
7063 Set_Has_Atomic_Components (E);
7067 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7069 end Atomic_Components;
7070 --------------------
7071 -- Attach_Handler --
7072 --------------------
7074 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7076 when Pragma_Attach_Handler =>
7077 Check_Ada_83_Warning;
7078 Check_No_Identifiers;
7079 Check_Arg_Count (2);
7081 if No_Run_Time_Mode then
7082 Error_Msg_CRT ("Attach_Handler pragma", N);
7084 Check_Interrupt_Or_Attach_Handler;
7086 -- The expression that designates the attribute may depend on a
7087 -- discriminant, and is therefore a per-object expression, to
7088 -- be expanded in the init proc. If expansion is enabled, then
7089 -- perform semantic checks on a copy only.
7091 if Expander_Active then
7093 Temp : constant Node_Id :=
7094 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7096 Set_Parent (Temp, N);
7097 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7101 Analyze (Get_Pragma_Arg (Arg2));
7102 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7105 Process_Interrupt_Or_Attach_Handler;
7108 --------------------
7109 -- C_Pass_By_Copy --
7110 --------------------
7112 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7114 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7120 Check_Valid_Configuration_Pragma;
7121 Check_Arg_Count (1);
7122 Check_Optional_Identifier (Arg1, "max_size");
7124 Arg := Get_Pragma_Arg (Arg1);
7125 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7127 Val := Expr_Value (Arg);
7131 ("maximum size for pragma% must be positive", Arg1);
7133 elsif UI_Is_In_Int_Range (Val) then
7134 Default_C_Record_Mechanism := UI_To_Int (Val);
7136 -- If a giant value is given, Int'Last will do well enough.
7137 -- If sometime someone complains that a record larger than
7138 -- two gigabytes is not copied, we will worry about it then!
7141 Default_C_Record_Mechanism := Mechanism_Type'Last;
7149 -- pragma Check ([Name =>] IDENTIFIER,
7150 -- [Check =>] Boolean_EXPRESSION
7151 -- [,[Message =>] String_EXPRESSION]);
7153 when Pragma_Check => Check : declare
7158 -- Set True if category of assertions referenced by Name enabled
7162 Check_At_Least_N_Arguments (2);
7163 Check_At_Most_N_Arguments (3);
7164 Check_Optional_Identifier (Arg1, Name_Name);
7165 Check_Optional_Identifier (Arg2, Name_Check);
7167 if Arg_Count = 3 then
7168 Check_Optional_Identifier (Arg3, Name_Message);
7169 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7172 Check_Arg_Is_Identifier (Arg1);
7174 -- Completely ignore if disabled
7176 if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7177 Rewrite (N, Make_Null_Statement (Loc));
7182 -- Indicate if pragma is enabled. The Original_Node reference here
7183 -- is to deal with pragma Assert rewritten as a Check pragma.
7185 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
7188 Set_SCO_Pragma_Enabled (Loc);
7191 -- If expansion is active and the check is not enabled then we
7192 -- rewrite the Check as:
7194 -- if False and then condition then
7198 -- The reason we do this rewriting during semantic analysis rather
7199 -- than as part of normal expansion is that we cannot analyze and
7200 -- expand the code for the boolean expression directly, or it may
7201 -- cause insertion of actions that would escape the attempt to
7202 -- suppress the check code.
7204 -- Note that the Sloc for the if statement corresponds to the
7205 -- argument condition, not the pragma itself. The reason for this
7206 -- is that we may generate a warning if the condition is False at
7207 -- compile time, and we do not want to delete this warning when we
7208 -- delete the if statement.
7210 Expr := Get_Pragma_Arg (Arg2);
7212 if Expander_Active and then not Check_On then
7213 Eloc := Sloc (Expr);
7216 Make_If_Statement (Eloc,
7218 Make_And_Then (Eloc,
7219 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7220 Right_Opnd => Expr),
7221 Then_Statements => New_List (
7222 Make_Null_Statement (Eloc))));
7229 Analyze_And_Resolve (Expr, Any_Boolean);
7237 -- pragma Check_Name (check_IDENTIFIER);
7239 when Pragma_Check_Name =>
7240 Check_No_Identifiers;
7242 Check_Valid_Configuration_Pragma;
7243 Check_Arg_Count (1);
7244 Check_Arg_Is_Identifier (Arg1);
7247 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7250 for J in Check_Names.First .. Check_Names.Last loop
7251 if Check_Names.Table (J) = Nam then
7256 Check_Names.Append (Nam);
7263 -- pragma Check_Policy (
7264 -- [Name =>] IDENTIFIER,
7265 -- [Policy =>] POLICY_IDENTIFIER);
7267 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7269 -- Note: this is a configuration pragma, but it is allowed to appear
7272 when Pragma_Check_Policy =>
7274 Check_Arg_Count (2);
7275 Check_Optional_Identifier (Arg1, Name_Name);
7276 Check_Optional_Identifier (Arg2, Name_Policy);
7278 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7280 -- A Check_Policy pragma can appear either as a configuration
7281 -- pragma, or in a declarative part or a package spec (see RM
7282 -- 11.5(5) for rules for Suppress/Unsuppress which are also
7283 -- followed for Check_Policy).
7285 if not Is_Configuration_Pragma then
7286 Check_Is_In_Decl_Part_Or_Package_Spec;
7289 Set_Next_Pragma (N, Opt.Check_Policy_List);
7290 Opt.Check_Policy_List := N;
7292 ---------------------
7293 -- CIL_Constructor --
7294 ---------------------
7296 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7298 -- Processing for this pragma is shared with Java_Constructor
7304 -- pragma Comment (static_string_EXPRESSION)
7306 -- Processing for pragma Comment shares the circuitry for pragma
7307 -- Ident. The only differences are that Ident enforces a limit of 31
7308 -- characters on its argument, and also enforces limitations on
7309 -- placement for DEC compatibility. Pragma Comment shares neither of
7310 -- these restrictions.
7316 -- pragma Common_Object (
7317 -- [Internal =>] LOCAL_NAME
7318 -- [, [External =>] EXTERNAL_SYMBOL]
7319 -- [, [Size =>] EXTERNAL_SYMBOL]);
7321 -- Processing for this pragma is shared with Psect_Object
7323 ------------------------
7324 -- Compile_Time_Error --
7325 ------------------------
7327 -- pragma Compile_Time_Error
7328 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7330 when Pragma_Compile_Time_Error =>
7332 Process_Compile_Time_Warning_Or_Error;
7334 --------------------------
7335 -- Compile_Time_Warning --
7336 --------------------------
7338 -- pragma Compile_Time_Warning
7339 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7341 when Pragma_Compile_Time_Warning =>
7343 Process_Compile_Time_Warning_Or_Error;
7349 when Pragma_Compiler_Unit =>
7351 Check_Arg_Count (0);
7352 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7354 -----------------------------
7355 -- Complete_Representation --
7356 -----------------------------
7358 -- pragma Complete_Representation;
7360 when Pragma_Complete_Representation =>
7362 Check_Arg_Count (0);
7364 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7366 ("pragma & must appear within record representation clause");
7369 ----------------------------
7370 -- Complex_Representation --
7371 ----------------------------
7373 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7375 when Pragma_Complex_Representation => Complex_Representation : declare
7382 Check_Arg_Count (1);
7383 Check_Optional_Identifier (Arg1, Name_Entity);
7384 Check_Arg_Is_Local_Name (Arg1);
7385 E_Id := Get_Pragma_Arg (Arg1);
7387 if Etype (E_Id) = Any_Type then
7393 if not Is_Record_Type (E) then
7395 ("argument for pragma% must be record type", Arg1);
7398 Ent := First_Entity (E);
7401 or else No (Next_Entity (Ent))
7402 or else Present (Next_Entity (Next_Entity (Ent)))
7403 or else not Is_Floating_Point_Type (Etype (Ent))
7404 or else Etype (Ent) /= Etype (Next_Entity (Ent))
7407 ("record for pragma% must have two fields of the same "
7408 & "floating-point type", Arg1);
7411 Set_Has_Complex_Representation (Base_Type (E));
7413 -- We need to treat the type has having a non-standard
7414 -- representation, for back-end purposes, even though in
7415 -- general a complex will have the default representation
7416 -- of a record with two real components.
7418 Set_Has_Non_Standard_Rep (Base_Type (E));
7420 end Complex_Representation;
7422 -------------------------
7423 -- Component_Alignment --
7424 -------------------------
7426 -- pragma Component_Alignment (
7427 -- [Form =>] ALIGNMENT_CHOICE
7428 -- [, [Name =>] type_LOCAL_NAME]);
7430 -- ALIGNMENT_CHOICE ::=
7432 -- | Component_Size_4
7436 when Pragma_Component_Alignment => Component_AlignmentP : declare
7437 Args : Args_List (1 .. 2);
7438 Names : constant Name_List (1 .. 2) := (
7442 Form : Node_Id renames Args (1);
7443 Name : Node_Id renames Args (2);
7445 Atype : Component_Alignment_Kind;
7450 Gather_Associations (Names, Args);
7453 Error_Pragma ("missing Form argument for pragma%");
7456 Check_Arg_Is_Identifier (Form);
7458 -- Get proper alignment, note that Default = Component_Size on all
7459 -- machines we have so far, and we want to set this value rather
7460 -- than the default value to indicate that it has been explicitly
7461 -- set (and thus will not get overridden by the default component
7462 -- alignment for the current scope)
7464 if Chars (Form) = Name_Component_Size then
7465 Atype := Calign_Component_Size;
7467 elsif Chars (Form) = Name_Component_Size_4 then
7468 Atype := Calign_Component_Size_4;
7470 elsif Chars (Form) = Name_Default then
7471 Atype := Calign_Component_Size;
7473 elsif Chars (Form) = Name_Storage_Unit then
7474 Atype := Calign_Storage_Unit;
7478 ("invalid Form parameter for pragma%", Form);
7481 -- Case with no name, supplied, affects scope table entry
7485 (Scope_Stack.Last).Component_Alignment_Default := Atype;
7487 -- Case of name supplied
7490 Check_Arg_Is_Local_Name (Name);
7492 Typ := Entity (Name);
7495 or else Rep_Item_Too_Early (Typ, N)
7499 Typ := Underlying_Type (Typ);
7502 if not Is_Record_Type (Typ)
7503 and then not Is_Array_Type (Typ)
7506 ("Name parameter of pragma% must identify record or " &
7507 "array type", Name);
7510 -- An explicit Component_Alignment pragma overrides an
7511 -- implicit pragma Pack, but not an explicit one.
7513 if not Has_Pragma_Pack (Base_Type (Typ)) then
7514 Set_Is_Packed (Base_Type (Typ), False);
7515 Set_Component_Alignment (Base_Type (Typ), Atype);
7518 end Component_AlignmentP;
7524 -- pragma Controlled (first_subtype_LOCAL_NAME);
7526 when Pragma_Controlled => Controlled : declare
7530 Check_No_Identifiers;
7531 Check_Arg_Count (1);
7532 Check_Arg_Is_Local_Name (Arg1);
7533 Arg := Get_Pragma_Arg (Arg1);
7535 if not Is_Entity_Name (Arg)
7536 or else not Is_Access_Type (Entity (Arg))
7538 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7540 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7548 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
7549 -- [Entity =>] LOCAL_NAME);
7551 when Pragma_Convention => Convention : declare
7554 pragma Warnings (Off, C);
7555 pragma Warnings (Off, E);
7557 Check_Arg_Order ((Name_Convention, Name_Entity));
7558 Check_Ada_83_Warning;
7559 Check_Arg_Count (2);
7560 Process_Convention (C, E);
7563 ---------------------------
7564 -- Convention_Identifier --
7565 ---------------------------
7567 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7568 -- [Convention =>] convention_IDENTIFIER);
7570 when Pragma_Convention_Identifier => Convention_Identifier : declare
7576 Check_Arg_Order ((Name_Name, Name_Convention));
7577 Check_Arg_Count (2);
7578 Check_Optional_Identifier (Arg1, Name_Name);
7579 Check_Optional_Identifier (Arg2, Name_Convention);
7580 Check_Arg_Is_Identifier (Arg1);
7581 Check_Arg_Is_Identifier (Arg2);
7582 Idnam := Chars (Get_Pragma_Arg (Arg1));
7583 Cname := Chars (Get_Pragma_Arg (Arg2));
7585 if Is_Convention_Name (Cname) then
7586 Record_Convention_Identifier
7587 (Idnam, Get_Convention_Id (Cname));
7590 ("second arg for % pragma must be convention", Arg2);
7592 end Convention_Identifier;
7598 -- pragma CPP_Class ([Entity =>] local_NAME)
7600 when Pragma_CPP_Class => CPP_Class : declare
7605 if Warn_On_Obsolescent_Feature then
7607 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7608 " by pragma import?", N);
7612 Check_Arg_Count (1);
7613 Check_Optional_Identifier (Arg1, Name_Entity);
7614 Check_Arg_Is_Local_Name (Arg1);
7616 Arg := Get_Pragma_Arg (Arg1);
7619 if Etype (Arg) = Any_Type then
7623 if not Is_Entity_Name (Arg)
7624 or else not Is_Type (Entity (Arg))
7626 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7629 Typ := Entity (Arg);
7631 if not Is_Tagged_Type (Typ) then
7632 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7635 -- Types treated as CPP classes must be declared limited (note:
7636 -- this used to be a warning but there is no real benefit to it
7637 -- since we did effectively intend to treat the type as limited
7640 if not Is_Limited_Type (Typ) then
7642 ("imported 'C'P'P type must be limited",
7643 Get_Pragma_Arg (Arg1));
7646 Set_Is_CPP_Class (Typ);
7647 Set_Convention (Typ, Convention_CPP);
7649 -- Imported CPP types must not have discriminants (because C++
7650 -- classes do not have discriminants).
7652 if Has_Discriminants (Typ) then
7654 ("imported 'C'P'P type cannot have discriminants",
7655 First (Discriminant_Specifications
7656 (Declaration_Node (Typ))));
7659 -- Components of imported CPP types must not have default
7660 -- expressions because the constructor (if any) is in the
7663 if Is_Incomplete_Or_Private_Type (Typ)
7664 and then No (Underlying_Type (Typ))
7666 -- It should be an error to apply pragma CPP to a private
7667 -- type if the underlying type is not visible (as it is
7668 -- for any representation item). For now, for backward
7669 -- compatibility we do nothing but we cannot check components
7670 -- because they are not available at this stage. All this code
7671 -- will be removed when we cleanup this obsolete GNAT pragma???
7677 Tdef : constant Node_Id :=
7678 Type_Definition (Declaration_Node (Typ));
7683 if Nkind (Tdef) = N_Record_Definition then
7684 Clist := Component_List (Tdef);
7686 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7687 Clist := Component_List (Record_Extension_Part (Tdef));
7690 if Present (Clist) then
7691 Comp := First (Component_Items (Clist));
7692 while Present (Comp) loop
7693 if Present (Expression (Comp)) then
7695 ("component of imported 'C'P'P type cannot have" &
7696 " default expression", Expression (Comp));
7706 ---------------------
7707 -- CPP_Constructor --
7708 ---------------------
7710 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7711 -- [, [External_Name =>] static_string_EXPRESSION ]
7712 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7714 when Pragma_CPP_Constructor => CPP_Constructor : declare
7718 Tag_Typ : Entity_Id;
7722 Check_At_Least_N_Arguments (1);
7723 Check_At_Most_N_Arguments (3);
7724 Check_Optional_Identifier (Arg1, Name_Entity);
7725 Check_Arg_Is_Local_Name (Arg1);
7727 Id := Get_Pragma_Arg (Arg1);
7728 Find_Program_Unit_Name (Id);
7730 -- If we did not find the name, we are done
7732 if Etype (Id) = Any_Type then
7736 Def_Id := Entity (Id);
7738 -- Check if already defined as constructor
7740 if Is_Constructor (Def_Id) then
7742 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7746 if Ekind (Def_Id) = E_Function
7747 and then (Is_CPP_Class (Etype (Def_Id))
7748 or else (Is_Class_Wide_Type (Etype (Def_Id))
7750 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7752 if Arg_Count >= 2 then
7753 Set_Imported (Def_Id);
7754 Set_Is_Public (Def_Id);
7755 Process_Interface_Name (Def_Id, Arg2, Arg3);
7758 Set_Has_Completion (Def_Id);
7759 Set_Is_Constructor (Def_Id);
7761 -- Imported C++ constructors are not dispatching primitives
7762 -- because in C++ they don't have a dispatch table slot.
7763 -- However, in Ada the constructor has the profile of a
7764 -- function that returns a tagged type and therefore it has
7765 -- been treated as a primitive operation during semantic
7766 -- analysis. We now remove it from the list of primitive
7767 -- operations of the type.
7769 if Is_Tagged_Type (Etype (Def_Id))
7770 and then not Is_Class_Wide_Type (Etype (Def_Id))
7772 pragma Assert (Is_Dispatching_Operation (Def_Id));
7773 Tag_Typ := Etype (Def_Id);
7775 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7776 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7780 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7781 Set_Is_Dispatching_Operation (Def_Id, False);
7784 -- For backward compatibility, if the constructor returns a
7785 -- class wide type, and we internally change the return type to
7786 -- the corresponding root type.
7788 if Is_Class_Wide_Type (Etype (Def_Id)) then
7789 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7793 ("pragma% requires function returning a 'C'P'P_Class type",
7796 end CPP_Constructor;
7802 when Pragma_CPP_Virtual => CPP_Virtual : declare
7806 if Warn_On_Obsolescent_Feature then
7808 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7817 when Pragma_CPP_Vtable => CPP_Vtable : declare
7821 if Warn_On_Obsolescent_Feature then
7823 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7832 -- pragma CPU (EXPRESSION);
7834 when Pragma_CPU => CPU : declare
7835 P : constant Node_Id := Parent (N);
7840 Check_No_Identifiers;
7841 Check_Arg_Count (1);
7845 if Nkind (P) = N_Subprogram_Body then
7846 Check_In_Main_Program;
7848 Arg := Get_Pragma_Arg (Arg1);
7849 Analyze_And_Resolve (Arg, Any_Integer);
7853 if not Is_Static_Expression (Arg) then
7854 Flag_Non_Static_Expr
7855 ("main subprogram affinity is not static!", Arg);
7858 -- If constraint error, then we already signalled an error
7860 elsif Raises_Constraint_Error (Arg) then
7863 -- Otherwise check in range
7867 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7868 -- This is the entity System.Multiprocessors.CPU_Range;
7870 Val : constant Uint := Expr_Value (Arg);
7873 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7875 Val > Expr_Value (Type_High_Bound (CPU_Id))
7878 ("main subprogram CPU is out of range", Arg1);
7884 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7888 elsif Nkind (P) = N_Task_Definition then
7889 Arg := Get_Pragma_Arg (Arg1);
7891 -- The expression must be analyzed in the special manner
7892 -- described in "Handling of Default and Per-Object
7893 -- Expressions" in sem.ads.
7895 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7897 -- Anything else is incorrect
7903 if Has_Pragma_CPU (P) then
7904 Error_Pragma ("duplicate pragma% not allowed");
7906 Set_Has_Pragma_CPU (P, True);
7908 if Nkind (P) = N_Task_Definition then
7909 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7918 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7920 when Pragma_Debug => Debug : declare
7927 -- Skip analysis if disabled
7929 if Debug_Pragmas_Disabled then
7930 Rewrite (N, Make_Null_Statement (Loc));
7937 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7940 if Debug_Pragmas_Enabled then
7941 Set_SCO_Pragma_Enabled (Loc);
7944 if Arg_Count = 2 then
7947 Left_Opnd => Relocate_Node (Cond),
7948 Right_Opnd => Get_Pragma_Arg (Arg1));
7949 Call := Get_Pragma_Arg (Arg2);
7951 Call := Get_Pragma_Arg (Arg1);
7955 N_Indexed_Component,
7959 N_Selected_Component)
7961 -- If this pragma Debug comes from source, its argument was
7962 -- parsed as a name form (which is syntactically identical).
7963 -- In a generic context a parameterless call will be left as
7964 -- an expanded name (if global) or selected_component if local.
7965 -- Change it to a procedure call statement now.
7967 Change_Name_To_Procedure_Call_Statement (Call);
7969 elsif Nkind (Call) = N_Procedure_Call_Statement then
7971 -- Already in the form of a procedure call statement: nothing
7972 -- to do (could happen in case of an internally generated
7978 -- All other cases: diagnose error
7981 ("argument of pragma ""Debug"" is not procedure call",
7986 -- Rewrite into a conditional with an appropriate condition. We
7987 -- wrap the procedure call in a block so that overhead from e.g.
7988 -- use of the secondary stack does not generate execution overhead
7989 -- for suppressed conditions.
7991 -- Normally the analysis that follows will freeze the subprogram
7992 -- being called. However, if the call is to a null procedure,
7993 -- we want to freeze it before creating the block, because the
7994 -- analysis that follows may be done with expansion disabled, in
7995 -- which case the body will not be generated, leading to spurious
7998 if Nkind (Call) = N_Procedure_Call_Statement
7999 and then Is_Entity_Name (Name (Call))
8001 Analyze (Name (Call));
8002 Freeze_Before (N, Entity (Name (Call)));
8005 Rewrite (N, Make_Implicit_If_Statement (N,
8007 Then_Statements => New_List (
8008 Make_Block_Statement (Loc,
8009 Handled_Statement_Sequence =>
8010 Make_Handled_Sequence_Of_Statements (Loc,
8011 Statements => New_List (Relocate_Node (Call)))))));
8019 -- pragma Debug_Policy (Check | Ignore)
8021 when Pragma_Debug_Policy =>
8023 Check_Arg_Count (1);
8024 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
8025 Debug_Pragmas_Enabled :=
8026 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
8027 Debug_Pragmas_Disabled :=
8028 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
8030 ---------------------
8031 -- Detect_Blocking --
8032 ---------------------
8034 -- pragma Detect_Blocking;
8036 when Pragma_Detect_Blocking =>
8038 Check_Arg_Count (0);
8039 Check_Valid_Configuration_Pragma;
8040 Detect_Blocking := True;
8042 --------------------------
8043 -- Default_Storage_Pool --
8044 --------------------------
8046 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
8048 when Pragma_Default_Storage_Pool =>
8050 Check_Arg_Count (1);
8052 -- Default_Storage_Pool can appear as a configuration pragma, or
8053 -- in a declarative part or a package spec.
8055 if not Is_Configuration_Pragma then
8056 Check_Is_In_Decl_Part_Or_Package_Spec;
8059 -- Case of Default_Storage_Pool (null);
8061 if Nkind (Expression (Arg1)) = N_Null then
8062 Analyze (Expression (Arg1));
8064 -- This is an odd case, this is not really an expression, so
8065 -- we don't have a type for it. So just set the type to Empty.
8067 Set_Etype (Expression (Arg1), Empty);
8069 -- Case of Default_Storage_Pool (storage_pool_NAME);
8072 -- If it's a configuration pragma, then the only allowed
8073 -- argument is "null".
8075 if Is_Configuration_Pragma then
8076 Error_Pragma_Arg ("NULL expected", Arg1);
8079 -- The expected type for a non-"null" argument is
8080 -- Root_Storage_Pool'Class.
8083 (Get_Pragma_Arg (Arg1),
8084 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8087 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
8088 -- for an access type will use this information to set the
8089 -- appropriate attributes of the access type.
8091 Default_Pool := Expression (Arg1);
8093 ------------------------------------
8094 -- Disable_Atomic_Synchronization --
8095 ------------------------------------
8097 -- pragma Disable_Atomic_Synchronization [(Entity)];
8099 when Pragma_Disable_Atomic_Synchronization =>
8100 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8106 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
8108 when Pragma_Discard_Names => Discard_Names : declare
8113 Check_Ada_83_Warning;
8115 -- Deal with configuration pragma case
8117 if Arg_Count = 0 and then Is_Configuration_Pragma then
8118 Global_Discard_Names := True;
8121 -- Otherwise, check correct appropriate context
8124 Check_Is_In_Decl_Part_Or_Package_Spec;
8126 if Arg_Count = 0 then
8128 -- If there is no parameter, then from now on this pragma
8129 -- applies to any enumeration, exception or tagged type
8130 -- defined in the current declarative part, and recursively
8131 -- to any nested scope.
8133 Set_Discard_Names (Current_Scope);
8137 Check_Arg_Count (1);
8138 Check_Optional_Identifier (Arg1, Name_On);
8139 Check_Arg_Is_Local_Name (Arg1);
8141 E_Id := Get_Pragma_Arg (Arg1);
8143 if Etype (E_Id) = Any_Type then
8149 if (Is_First_Subtype (E)
8151 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8152 or else Ekind (E) = E_Exception
8154 Set_Discard_Names (E);
8157 ("inappropriate entity for pragma%", Arg1);
8164 ------------------------
8165 -- Dispatching_Domain --
8166 ------------------------
8168 -- pragma Dispatching_Domain (EXPRESSION);
8170 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8171 P : constant Node_Id := Parent (N);
8176 Check_No_Identifiers;
8177 Check_Arg_Count (1);
8179 -- This pragma is born obsolete, but not the aspect
8181 if not From_Aspect_Specification (N) then
8183 (No_Obsolescent_Features, Pragma_Identifier (N));
8186 if Nkind (P) = N_Task_Definition then
8187 Arg := Get_Pragma_Arg (Arg1);
8189 -- The expression must be analyzed in the special manner
8190 -- described in "Handling of Default and Per-Object
8191 -- Expressions" in sem.ads.
8193 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8195 -- Anything else is incorrect
8201 if Has_Pragma_Dispatching_Domain (P) then
8202 Error_Pragma ("duplicate pragma% not allowed");
8204 Set_Has_Pragma_Dispatching_Domain (P, True);
8206 if Nkind (P) = N_Task_Definition then
8207 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8210 end Dispatching_Domain;
8216 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8218 when Pragma_Elaborate => Elaborate : declare
8223 -- Pragma must be in context items list of a compilation unit
8225 if not Is_In_Context_Clause then
8229 -- Must be at least one argument
8231 if Arg_Count = 0 then
8232 Error_Pragma ("pragma% requires at least one argument");
8235 -- In Ada 83 mode, there can be no items following it in the
8236 -- context list except other pragmas and implicit with clauses
8237 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8238 -- placement rule does not apply.
8240 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8242 while Present (Citem) loop
8243 if Nkind (Citem) = N_Pragma
8244 or else (Nkind (Citem) = N_With_Clause
8245 and then Implicit_With (Citem))
8250 ("(Ada 83) pragma% must be at end of context clause");
8257 -- Finally, the arguments must all be units mentioned in a with
8258 -- clause in the same context clause. Note we already checked (in
8259 -- Par.Prag) that the arguments are all identifiers or selected
8263 Outer : while Present (Arg) loop
8264 Citem := First (List_Containing (N));
8265 Inner : while Citem /= N loop
8266 if Nkind (Citem) = N_With_Clause
8267 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8269 Set_Elaborate_Present (Citem, True);
8270 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8271 Generate_Reference (Entity (Name (Citem)), Citem);
8273 -- With the pragma present, elaboration calls on
8274 -- subprograms from the named unit need no further
8275 -- checks, as long as the pragma appears in the current
8276 -- compilation unit. If the pragma appears in some unit
8277 -- in the context, there might still be a need for an
8278 -- Elaborate_All_Desirable from the current compilation
8279 -- to the named unit, so we keep the check enabled.
8281 if In_Extended_Main_Source_Unit (N) then
8282 Set_Suppress_Elaboration_Warnings
8283 (Entity (Name (Citem)));
8294 ("argument of pragma% is not withed unit", Arg);
8300 -- Give a warning if operating in static mode with -gnatwl
8301 -- (elaboration warnings enabled) switch set.
8303 if Elab_Warnings and not Dynamic_Elaboration_Checks then
8305 ("?use of pragma Elaborate may not be safe", N);
8307 ("?use pragma Elaborate_All instead if possible", N);
8315 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8317 when Pragma_Elaborate_All => Elaborate_All : declare
8322 Check_Ada_83_Warning;
8324 -- Pragma must be in context items list of a compilation unit
8326 if not Is_In_Context_Clause then
8330 -- Must be at least one argument
8332 if Arg_Count = 0 then
8333 Error_Pragma ("pragma% requires at least one argument");
8336 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
8337 -- have to appear at the end of the context clause, but may
8338 -- appear mixed in with other items, even in Ada 83 mode.
8340 -- Final check: the arguments must all be units mentioned in
8341 -- a with clause in the same context clause. Note that we
8342 -- already checked (in Par.Prag) that all the arguments are
8343 -- either identifiers or selected components.
8346 Outr : while Present (Arg) loop
8347 Citem := First (List_Containing (N));
8348 Innr : while Citem /= N loop
8349 if Nkind (Citem) = N_With_Clause
8350 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8352 Set_Elaborate_All_Present (Citem, True);
8353 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8355 -- Suppress warnings and elaboration checks on the named
8356 -- unit if the pragma is in the current compilation, as
8357 -- for pragma Elaborate.
8359 if In_Extended_Main_Source_Unit (N) then
8360 Set_Suppress_Elaboration_Warnings
8361 (Entity (Name (Citem)));
8370 Set_Error_Posted (N);
8372 ("argument of pragma% is not withed unit", Arg);
8379 --------------------
8380 -- Elaborate_Body --
8381 --------------------
8383 -- pragma Elaborate_Body [( library_unit_NAME )];
8385 when Pragma_Elaborate_Body => Elaborate_Body : declare
8386 Cunit_Node : Node_Id;
8387 Cunit_Ent : Entity_Id;
8390 Check_Ada_83_Warning;
8391 Check_Valid_Library_Unit_Pragma;
8393 if Nkind (N) = N_Null_Statement then
8397 Cunit_Node := Cunit (Current_Sem_Unit);
8398 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8400 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8403 Error_Pragma ("pragma% must refer to a spec, not a body");
8405 Set_Body_Required (Cunit_Node, True);
8406 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8408 -- If we are in dynamic elaboration mode, then we suppress
8409 -- elaboration warnings for the unit, since it is definitely
8410 -- fine NOT to do dynamic checks at the first level (and such
8411 -- checks will be suppressed because no elaboration boolean
8412 -- is created for Elaborate_Body packages).
8414 -- But in the static model of elaboration, Elaborate_Body is
8415 -- definitely NOT good enough to ensure elaboration safety on
8416 -- its own, since the body may WITH other units that are not
8417 -- safe from an elaboration point of view, so a client must
8418 -- still do an Elaborate_All on such units.
8420 -- Debug flag -gnatdD restores the old behavior of 3.13, where
8421 -- Elaborate_Body always suppressed elab warnings.
8423 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8424 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8429 ------------------------
8430 -- Elaboration_Checks --
8431 ------------------------
8433 -- pragma Elaboration_Checks (Static | Dynamic);
8435 when Pragma_Elaboration_Checks =>
8437 Check_Arg_Count (1);
8438 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8439 Dynamic_Elaboration_Checks :=
8440 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8446 -- pragma Eliminate (
8447 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
8448 -- [,[Entity =>] IDENTIFIER |
8449 -- SELECTED_COMPONENT |
8451 -- [, OVERLOADING_RESOLUTION]);
8453 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8456 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8459 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8461 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8462 -- Result_Type => result_SUBTYPE_NAME]
8464 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8465 -- SUBTYPE_NAME ::= STRING_LITERAL
8467 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8468 -- SOURCE_TRACE ::= STRING_LITERAL
8470 when Pragma_Eliminate => Eliminate : declare
8471 Args : Args_List (1 .. 5);
8472 Names : constant Name_List (1 .. 5) := (
8475 Name_Parameter_Types,
8477 Name_Source_Location);
8479 Unit_Name : Node_Id renames Args (1);
8480 Entity : Node_Id renames Args (2);
8481 Parameter_Types : Node_Id renames Args (3);
8482 Result_Type : Node_Id renames Args (4);
8483 Source_Location : Node_Id renames Args (5);
8487 Check_Valid_Configuration_Pragma;
8488 Gather_Associations (Names, Args);
8490 if No (Unit_Name) then
8491 Error_Pragma ("missing Unit_Name argument for pragma%");
8495 and then (Present (Parameter_Types)
8497 Present (Result_Type)
8499 Present (Source_Location))
8501 Error_Pragma ("missing Entity argument for pragma%");
8504 if (Present (Parameter_Types)
8506 Present (Result_Type))
8508 Present (Source_Location)
8511 ("parameter profile and source location cannot " &
8512 "be used together in pragma%");
8515 Process_Eliminate_Pragma
8524 -----------------------------------
8525 -- Enable_Atomic_Synchronization --
8526 -----------------------------------
8528 -- pragma Enable_Atomic_Synchronization [(Entity)];
8530 when Pragma_Enable_Atomic_Synchronization =>
8531 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
8538 -- [ Convention =>] convention_IDENTIFIER,
8539 -- [ Entity =>] local_NAME
8540 -- [, [External_Name =>] static_string_EXPRESSION ]
8541 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8543 when Pragma_Export => Export : declare
8547 pragma Warnings (Off, C);
8550 Check_Ada_83_Warning;
8556 Check_At_Least_N_Arguments (2);
8557 Check_At_Most_N_Arguments (4);
8558 Process_Convention (C, Def_Id);
8560 if Ekind (Def_Id) /= E_Constant then
8561 Note_Possible_Modification
8562 (Get_Pragma_Arg (Arg2), Sure => False);
8565 Process_Interface_Name (Def_Id, Arg3, Arg4);
8566 Set_Exported (Def_Id, Arg2);
8568 -- If the entity is a deferred constant, propagate the information
8569 -- to the full view, because gigi elaborates the full view only.
8571 if Ekind (Def_Id) = E_Constant
8572 and then Present (Full_View (Def_Id))
8575 Id2 : constant Entity_Id := Full_View (Def_Id);
8577 Set_Is_Exported (Id2, Is_Exported (Def_Id));
8578 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
8579 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8584 ----------------------
8585 -- Export_Exception --
8586 ----------------------
8588 -- pragma Export_Exception (
8589 -- [Internal =>] LOCAL_NAME
8590 -- [, [External =>] EXTERNAL_SYMBOL]
8591 -- [, [Form =>] Ada | VMS]
8592 -- [, [Code =>] static_integer_EXPRESSION]);
8594 when Pragma_Export_Exception => Export_Exception : declare
8595 Args : Args_List (1 .. 4);
8596 Names : constant Name_List (1 .. 4) := (
8602 Internal : Node_Id renames Args (1);
8603 External : Node_Id renames Args (2);
8604 Form : Node_Id renames Args (3);
8605 Code : Node_Id renames Args (4);
8610 if Inside_A_Generic then
8611 Error_Pragma ("pragma% cannot be used for generic entities");
8614 Gather_Associations (Names, Args);
8615 Process_Extended_Import_Export_Exception_Pragma (
8616 Arg_Internal => Internal,
8617 Arg_External => External,
8621 if not Is_VMS_Exception (Entity (Internal)) then
8622 Set_Exported (Entity (Internal), Internal);
8624 end Export_Exception;
8626 ---------------------
8627 -- Export_Function --
8628 ---------------------
8630 -- pragma Export_Function (
8631 -- [Internal =>] LOCAL_NAME
8632 -- [, [External =>] EXTERNAL_SYMBOL]
8633 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8634 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8635 -- [, [Mechanism =>] MECHANISM]
8636 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8638 -- EXTERNAL_SYMBOL ::=
8640 -- | static_string_EXPRESSION
8642 -- PARAMETER_TYPES ::=
8644 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8646 -- TYPE_DESIGNATOR ::=
8648 -- | subtype_Name ' Access
8652 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8654 -- MECHANISM_ASSOCIATION ::=
8655 -- [formal_parameter_NAME =>] MECHANISM_NAME
8657 -- MECHANISM_NAME ::=
8660 -- | Descriptor [([Class =>] CLASS_NAME)]
8662 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8664 when Pragma_Export_Function => Export_Function : declare
8665 Args : Args_List (1 .. 6);
8666 Names : constant Name_List (1 .. 6) := (
8669 Name_Parameter_Types,
8672 Name_Result_Mechanism);
8674 Internal : Node_Id renames Args (1);
8675 External : Node_Id renames Args (2);
8676 Parameter_Types : Node_Id renames Args (3);
8677 Result_Type : Node_Id renames Args (4);
8678 Mechanism : Node_Id renames Args (5);
8679 Result_Mechanism : Node_Id renames Args (6);
8683 Gather_Associations (Names, Args);
8684 Process_Extended_Import_Export_Subprogram_Pragma (
8685 Arg_Internal => Internal,
8686 Arg_External => External,
8687 Arg_Parameter_Types => Parameter_Types,
8688 Arg_Result_Type => Result_Type,
8689 Arg_Mechanism => Mechanism,
8690 Arg_Result_Mechanism => Result_Mechanism);
8691 end Export_Function;
8697 -- pragma Export_Object (
8698 -- [Internal =>] LOCAL_NAME
8699 -- [, [External =>] EXTERNAL_SYMBOL]
8700 -- [, [Size =>] EXTERNAL_SYMBOL]);
8702 -- EXTERNAL_SYMBOL ::=
8704 -- | static_string_EXPRESSION
8706 -- PARAMETER_TYPES ::=
8708 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8710 -- TYPE_DESIGNATOR ::=
8712 -- | subtype_Name ' Access
8716 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8718 -- MECHANISM_ASSOCIATION ::=
8719 -- [formal_parameter_NAME =>] MECHANISM_NAME
8721 -- MECHANISM_NAME ::=
8724 -- | Descriptor [([Class =>] CLASS_NAME)]
8726 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8728 when Pragma_Export_Object => Export_Object : declare
8729 Args : Args_List (1 .. 3);
8730 Names : constant Name_List (1 .. 3) := (
8735 Internal : Node_Id renames Args (1);
8736 External : Node_Id renames Args (2);
8737 Size : Node_Id renames Args (3);
8741 Gather_Associations (Names, Args);
8742 Process_Extended_Import_Export_Object_Pragma (
8743 Arg_Internal => Internal,
8744 Arg_External => External,
8748 ----------------------
8749 -- Export_Procedure --
8750 ----------------------
8752 -- pragma Export_Procedure (
8753 -- [Internal =>] LOCAL_NAME
8754 -- [, [External =>] EXTERNAL_SYMBOL]
8755 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8756 -- [, [Mechanism =>] MECHANISM]);
8758 -- EXTERNAL_SYMBOL ::=
8760 -- | static_string_EXPRESSION
8762 -- PARAMETER_TYPES ::=
8764 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8766 -- TYPE_DESIGNATOR ::=
8768 -- | subtype_Name ' Access
8772 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8774 -- MECHANISM_ASSOCIATION ::=
8775 -- [formal_parameter_NAME =>] MECHANISM_NAME
8777 -- MECHANISM_NAME ::=
8780 -- | Descriptor [([Class =>] CLASS_NAME)]
8782 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8784 when Pragma_Export_Procedure => Export_Procedure : declare
8785 Args : Args_List (1 .. 4);
8786 Names : constant Name_List (1 .. 4) := (
8789 Name_Parameter_Types,
8792 Internal : Node_Id renames Args (1);
8793 External : Node_Id renames Args (2);
8794 Parameter_Types : Node_Id renames Args (3);
8795 Mechanism : Node_Id renames Args (4);
8799 Gather_Associations (Names, Args);
8800 Process_Extended_Import_Export_Subprogram_Pragma (
8801 Arg_Internal => Internal,
8802 Arg_External => External,
8803 Arg_Parameter_Types => Parameter_Types,
8804 Arg_Mechanism => Mechanism);
8805 end Export_Procedure;
8811 -- pragma Export_Value (
8812 -- [Value =>] static_integer_EXPRESSION,
8813 -- [Link_Name =>] static_string_EXPRESSION);
8815 when Pragma_Export_Value =>
8817 Check_Arg_Order ((Name_Value, Name_Link_Name));
8818 Check_Arg_Count (2);
8820 Check_Optional_Identifier (Arg1, Name_Value);
8821 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8823 Check_Optional_Identifier (Arg2, Name_Link_Name);
8824 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8826 -----------------------------
8827 -- Export_Valued_Procedure --
8828 -----------------------------
8830 -- pragma Export_Valued_Procedure (
8831 -- [Internal =>] LOCAL_NAME
8832 -- [, [External =>] EXTERNAL_SYMBOL,]
8833 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8834 -- [, [Mechanism =>] MECHANISM]);
8836 -- EXTERNAL_SYMBOL ::=
8838 -- | static_string_EXPRESSION
8840 -- PARAMETER_TYPES ::=
8842 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8844 -- TYPE_DESIGNATOR ::=
8846 -- | subtype_Name ' Access
8850 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8852 -- MECHANISM_ASSOCIATION ::=
8853 -- [formal_parameter_NAME =>] MECHANISM_NAME
8855 -- MECHANISM_NAME ::=
8858 -- | Descriptor [([Class =>] CLASS_NAME)]
8860 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8862 when Pragma_Export_Valued_Procedure =>
8863 Export_Valued_Procedure : declare
8864 Args : Args_List (1 .. 4);
8865 Names : constant Name_List (1 .. 4) := (
8868 Name_Parameter_Types,
8871 Internal : Node_Id renames Args (1);
8872 External : Node_Id renames Args (2);
8873 Parameter_Types : Node_Id renames Args (3);
8874 Mechanism : Node_Id renames Args (4);
8878 Gather_Associations (Names, Args);
8879 Process_Extended_Import_Export_Subprogram_Pragma (
8880 Arg_Internal => Internal,
8881 Arg_External => External,
8882 Arg_Parameter_Types => Parameter_Types,
8883 Arg_Mechanism => Mechanism);
8884 end Export_Valued_Procedure;
8890 -- pragma Extend_System ([Name =>] Identifier);
8892 when Pragma_Extend_System => Extend_System : declare
8895 Check_Valid_Configuration_Pragma;
8896 Check_Arg_Count (1);
8897 Check_Optional_Identifier (Arg1, Name_Name);
8898 Check_Arg_Is_Identifier (Arg1);
8900 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8903 and then Name_Buffer (1 .. 4) = "aux_"
8905 if Present (System_Extend_Pragma_Arg) then
8906 if Chars (Get_Pragma_Arg (Arg1)) =
8907 Chars (Expression (System_Extend_Pragma_Arg))
8911 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8912 Error_Pragma ("pragma% conflicts with that #");
8916 System_Extend_Pragma_Arg := Arg1;
8918 if not GNAT_Mode then
8919 System_Extend_Unit := Arg1;
8923 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8927 ------------------------
8928 -- Extensions_Allowed --
8929 ------------------------
8931 -- pragma Extensions_Allowed (ON | OFF);
8933 when Pragma_Extensions_Allowed =>
8935 Check_Arg_Count (1);
8936 Check_No_Identifiers;
8937 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8939 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8940 Extensions_Allowed := True;
8941 Ada_Version := Ada_Version_Type'Last;
8944 Extensions_Allowed := False;
8945 Ada_Version := Ada_Version_Explicit;
8952 -- pragma External (
8953 -- [ Convention =>] convention_IDENTIFIER,
8954 -- [ Entity =>] local_NAME
8955 -- [, [External_Name =>] static_string_EXPRESSION ]
8956 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8958 when Pragma_External => External : declare
8962 pragma Warnings (Off, C);
8971 Check_At_Least_N_Arguments (2);
8972 Check_At_Most_N_Arguments (4);
8973 Process_Convention (C, Def_Id);
8974 Note_Possible_Modification
8975 (Get_Pragma_Arg (Arg2), Sure => False);
8976 Process_Interface_Name (Def_Id, Arg3, Arg4);
8977 Set_Exported (Def_Id, Arg2);
8980 --------------------------
8981 -- External_Name_Casing --
8982 --------------------------
8984 -- pragma External_Name_Casing (
8985 -- UPPERCASE | LOWERCASE
8986 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8988 when Pragma_External_Name_Casing => External_Name_Casing : declare
8991 Check_No_Identifiers;
8993 if Arg_Count = 2 then
8995 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8997 case Chars (Get_Pragma_Arg (Arg2)) is
8999 Opt.External_Name_Exp_Casing := As_Is;
9001 when Name_Uppercase =>
9002 Opt.External_Name_Exp_Casing := Uppercase;
9004 when Name_Lowercase =>
9005 Opt.External_Name_Exp_Casing := Lowercase;
9012 Check_Arg_Count (1);
9015 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
9017 case Chars (Get_Pragma_Arg (Arg1)) is
9018 when Name_Uppercase =>
9019 Opt.External_Name_Imp_Casing := Uppercase;
9021 when Name_Lowercase =>
9022 Opt.External_Name_Imp_Casing := Lowercase;
9027 end External_Name_Casing;
9029 --------------------------
9030 -- Favor_Top_Level --
9031 --------------------------
9033 -- pragma Favor_Top_Level (type_NAME);
9035 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
9036 Named_Entity : Entity_Id;
9040 Check_No_Identifiers;
9041 Check_Arg_Count (1);
9042 Check_Arg_Is_Local_Name (Arg1);
9043 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
9045 -- If it's an access-to-subprogram type (in particular, not a
9046 -- subtype), set the flag on that type.
9048 if Is_Access_Subprogram_Type (Named_Entity) then
9049 Set_Can_Use_Internal_Rep (Named_Entity, False);
9051 -- Otherwise it's an error (name denotes the wrong sort of entity)
9055 ("access-to-subprogram type expected",
9056 Get_Pragma_Arg (Arg1));
9058 end Favor_Top_Level;
9064 -- pragma Fast_Math;
9066 when Pragma_Fast_Math =>
9068 Check_No_Identifiers;
9069 Check_Valid_Configuration_Pragma;
9072 ---------------------------
9073 -- Finalize_Storage_Only --
9074 ---------------------------
9076 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9078 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9079 Assoc : constant Node_Id := Arg1;
9080 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9085 Check_No_Identifiers;
9086 Check_Arg_Count (1);
9087 Check_Arg_Is_Local_Name (Arg1);
9089 Find_Type (Type_Id);
9090 Typ := Entity (Type_Id);
9093 or else Rep_Item_Too_Early (Typ, N)
9097 Typ := Underlying_Type (Typ);
9100 if not Is_Controlled (Typ) then
9101 Error_Pragma ("pragma% must specify controlled type");
9104 Check_First_Subtype (Arg1);
9106 if Finalize_Storage_Only (Typ) then
9107 Error_Pragma ("duplicate pragma%, only one allowed");
9109 elsif not Rep_Item_Too_Late (Typ, N) then
9110 Set_Finalize_Storage_Only (Base_Type (Typ), True);
9112 end Finalize_Storage;
9114 --------------------------
9115 -- Float_Representation --
9116 --------------------------
9118 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9120 -- FLOAT_REP ::= VAX_Float | IEEE_Float
9122 when Pragma_Float_Representation => Float_Representation : declare
9130 if Arg_Count = 1 then
9131 Check_Valid_Configuration_Pragma;
9133 Check_Arg_Count (2);
9134 Check_Optional_Identifier (Arg2, Name_Entity);
9135 Check_Arg_Is_Local_Name (Arg2);
9138 Check_No_Identifier (Arg1);
9139 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9141 if not OpenVMS_On_Target then
9142 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9144 ("?pragma% ignored (applies only to Open'V'M'S)");
9150 -- One argument case
9152 if Arg_Count = 1 then
9153 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9154 if Opt.Float_Format = 'I' then
9155 Error_Pragma ("'I'E'E'E format previously specified");
9158 Opt.Float_Format := 'V';
9161 if Opt.Float_Format = 'V' then
9162 Error_Pragma ("'V'A'X format previously specified");
9165 Opt.Float_Format := 'I';
9168 Set_Standard_Fpt_Formats;
9170 -- Two argument case
9173 Argx := Get_Pragma_Arg (Arg2);
9175 if not Is_Entity_Name (Argx)
9176 or else not Is_Floating_Point_Type (Entity (Argx))
9179 ("second argument of% pragma must be floating-point type",
9183 Ent := Entity (Argx);
9184 Digs := UI_To_Int (Digits_Value (Ent));
9186 -- Two arguments, VAX_Float case
9188 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9190 when 6 => Set_F_Float (Ent);
9191 when 9 => Set_D_Float (Ent);
9192 when 15 => Set_G_Float (Ent);
9196 ("wrong digits value, must be 6,9 or 15", Arg2);
9199 -- Two arguments, IEEE_Float case
9203 when 6 => Set_IEEE_Short (Ent);
9204 when 15 => Set_IEEE_Long (Ent);
9208 ("wrong digits value, must be 6 or 15", Arg2);
9212 end Float_Representation;
9218 -- pragma Ident (static_string_EXPRESSION)
9220 -- Note: pragma Comment shares this processing. Pragma Comment is
9221 -- identical to Ident, except that the restriction of the argument to
9222 -- 31 characters and the placement restrictions are not enforced for
9225 when Pragma_Ident | Pragma_Comment => Ident : declare
9230 Check_Arg_Count (1);
9231 Check_No_Identifiers;
9232 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9235 -- For pragma Ident, preserve DEC compatibility by requiring the
9236 -- pragma to appear in a declarative part or package spec.
9238 if Prag_Id = Pragma_Ident then
9239 Check_Is_In_Decl_Part_Or_Package_Spec;
9242 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9249 GP := Parent (Parent (N));
9251 if Nkind_In (GP, N_Package_Declaration,
9252 N_Generic_Package_Declaration)
9257 -- If we have a compilation unit, then record the ident value,
9258 -- checking for improper duplication.
9260 if Nkind (GP) = N_Compilation_Unit then
9261 CS := Ident_String (Current_Sem_Unit);
9263 if Present (CS) then
9265 -- For Ident, we do not permit multiple instances
9267 if Prag_Id = Pragma_Ident then
9268 Error_Pragma ("duplicate% pragma not permitted");
9270 -- For Comment, we concatenate the string, unless we want
9271 -- to preserve the tree structure for ASIS.
9273 elsif not ASIS_Mode then
9274 Start_String (Strval (CS));
9275 Store_String_Char (' ');
9276 Store_String_Chars (Strval (Str));
9277 Set_Strval (CS, End_String);
9281 -- In VMS, the effect of IDENT is achieved by passing
9282 -- --identification=name as a --for-linker switch.
9284 if OpenVMS_On_Target then
9287 ("--for-linker=--identification=");
9288 String_To_Name_Buffer (Strval (Str));
9289 Store_String_Chars (Name_Buffer (1 .. Name_Len));
9291 -- Only the last processed IDENT is saved. The main
9292 -- purpose is so an IDENT associated with a main
9293 -- procedure will be used in preference to an IDENT
9294 -- associated with a with'd package.
9296 Replace_Linker_Option_String
9297 (End_String, "--for-linker=--identification=");
9300 Set_Ident_String (Current_Sem_Unit, Str);
9303 -- For subunits, we just ignore the Ident, since in GNAT these
9304 -- are not separate object files, and hence not separate units
9305 -- in the unit table.
9307 elsif Nkind (GP) = N_Subunit then
9310 -- Otherwise we have a misplaced pragma Ident, but we ignore
9311 -- this if we are in an instantiation, since it comes from
9312 -- a generic, and has no relevance to the instantiation.
9314 elsif Prag_Id = Pragma_Ident then
9315 if Instantiation_Location (Loc) = No_Location then
9316 Error_Pragma ("pragma% only allowed at outer level");
9322 ----------------------------
9323 -- Implementation_Defined --
9324 ----------------------------
9326 -- pragma Implementation_Defined (local_NAME);
9328 -- Marks previously declared entity as implementation defined. For
9329 -- an overloaded entity, applies to the most recent homonym.
9331 -- pragma Implementation_Defined;
9333 -- The form with no arguments appears anywhere within a scope, most
9334 -- typically a package spec, and indicates that all entities that are
9335 -- defined within the package spec are Implementation_Defined.
9337 when Pragma_Implementation_Defined => Implementation_Defined : declare
9341 Check_No_Identifiers;
9343 -- Form with no arguments
9345 if Arg_Count = 0 then
9346 Set_Is_Implementation_Defined (Current_Scope);
9348 -- Form with one argument
9351 Check_Arg_Count (1);
9352 Check_Arg_Is_Local_Name (Arg1);
9353 Ent := Entity (Get_Pragma_Arg (Arg1));
9354 Set_Is_Implementation_Defined (Ent);
9356 end Implementation_Defined;
9362 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9363 -- implementation_kind ::=
9364 -- By_Entry | By_Protected_Procedure | By_Any | Optional
9366 -- "By_Any" and "Optional" are treated as synonyms in order to
9367 -- support Ada 2012 aspect Synchronization.
9369 when Pragma_Implemented => Implemented : declare
9370 Proc_Id : Entity_Id;
9375 Check_Arg_Count (2);
9376 Check_No_Identifiers;
9377 Check_Arg_Is_Identifier (Arg1);
9378 Check_Arg_Is_Local_Name (Arg1);
9379 Check_Arg_Is_One_Of (Arg2,
9382 Name_By_Protected_Procedure,
9385 -- Extract the name of the local procedure
9387 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9389 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9390 -- primitive procedure of a synchronized tagged type.
9392 if Ekind (Proc_Id) = E_Procedure
9393 and then Is_Primitive (Proc_Id)
9394 and then Present (First_Formal (Proc_Id))
9396 Typ := Etype (First_Formal (Proc_Id));
9398 if Is_Tagged_Type (Typ)
9401 -- Check for a protected, a synchronized or a task interface
9403 ((Is_Interface (Typ)
9404 and then Is_Synchronized_Interface (Typ))
9406 -- Check for a protected type or a task type that implements
9410 (Is_Concurrent_Record_Type (Typ)
9411 and then Present (Interfaces (Typ)))
9413 -- Check for a private record extension with keyword
9417 (Ekind_In (Typ, E_Record_Type_With_Private,
9418 E_Record_Subtype_With_Private)
9419 and then Synchronized_Present (Parent (Typ))))
9424 ("controlling formal must be of synchronized " &
9425 "tagged type", Arg1);
9429 -- Procedures declared inside a protected type must be accepted
9431 elsif Ekind (Proc_Id) = E_Procedure
9432 and then Is_Protected_Type (Scope (Proc_Id))
9436 -- The first argument is not a primitive procedure
9440 ("pragma % must be applied to a primitive procedure", Arg1);
9444 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9445 -- By_Protected_Procedure to the primitive procedure of a task
9448 if Chars (Arg2) = Name_By_Protected_Procedure
9449 and then Is_Interface (Typ)
9450 and then Is_Task_Interface (Typ)
9453 ("implementation kind By_Protected_Procedure cannot be " &
9454 "applied to a task interface primitive", Arg2);
9458 Record_Rep_Item (Proc_Id, N);
9461 ----------------------
9462 -- Implicit_Packing --
9463 ----------------------
9465 -- pragma Implicit_Packing;
9467 when Pragma_Implicit_Packing =>
9469 Check_Arg_Count (0);
9470 Implicit_Packing := True;
9477 -- [Convention =>] convention_IDENTIFIER,
9478 -- [Entity =>] local_NAME
9479 -- [, [External_Name =>] static_string_EXPRESSION ]
9480 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9482 when Pragma_Import =>
9483 Check_Ada_83_Warning;
9489 Check_At_Least_N_Arguments (2);
9490 Check_At_Most_N_Arguments (4);
9491 Process_Import_Or_Interface;
9493 ----------------------
9494 -- Import_Exception --
9495 ----------------------
9497 -- pragma Import_Exception (
9498 -- [Internal =>] LOCAL_NAME
9499 -- [, [External =>] EXTERNAL_SYMBOL]
9500 -- [, [Form =>] Ada | VMS]
9501 -- [, [Code =>] static_integer_EXPRESSION]);
9503 when Pragma_Import_Exception => Import_Exception : declare
9504 Args : Args_List (1 .. 4);
9505 Names : constant Name_List (1 .. 4) := (
9511 Internal : Node_Id renames Args (1);
9512 External : Node_Id renames Args (2);
9513 Form : Node_Id renames Args (3);
9514 Code : Node_Id renames Args (4);
9518 Gather_Associations (Names, Args);
9520 if Present (External) and then Present (Code) then
9522 ("cannot give both External and Code options for pragma%");
9525 Process_Extended_Import_Export_Exception_Pragma (
9526 Arg_Internal => Internal,
9527 Arg_External => External,
9531 if not Is_VMS_Exception (Entity (Internal)) then
9532 Set_Imported (Entity (Internal));
9534 end Import_Exception;
9536 ---------------------
9537 -- Import_Function --
9538 ---------------------
9540 -- pragma Import_Function (
9541 -- [Internal =>] LOCAL_NAME,
9542 -- [, [External =>] EXTERNAL_SYMBOL]
9543 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9544 -- [, [Result_Type =>] SUBTYPE_MARK]
9545 -- [, [Mechanism =>] MECHANISM]
9546 -- [, [Result_Mechanism =>] MECHANISM_NAME]
9547 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9549 -- EXTERNAL_SYMBOL ::=
9551 -- | static_string_EXPRESSION
9553 -- PARAMETER_TYPES ::=
9555 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9557 -- TYPE_DESIGNATOR ::=
9559 -- | subtype_Name ' Access
9563 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9565 -- MECHANISM_ASSOCIATION ::=
9566 -- [formal_parameter_NAME =>] MECHANISM_NAME
9568 -- MECHANISM_NAME ::=
9571 -- | Descriptor [([Class =>] CLASS_NAME)]
9573 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9575 when Pragma_Import_Function => Import_Function : declare
9576 Args : Args_List (1 .. 7);
9577 Names : constant Name_List (1 .. 7) := (
9580 Name_Parameter_Types,
9583 Name_Result_Mechanism,
9584 Name_First_Optional_Parameter);
9586 Internal : Node_Id renames Args (1);
9587 External : Node_Id renames Args (2);
9588 Parameter_Types : Node_Id renames Args (3);
9589 Result_Type : Node_Id renames Args (4);
9590 Mechanism : Node_Id renames Args (5);
9591 Result_Mechanism : Node_Id renames Args (6);
9592 First_Optional_Parameter : Node_Id renames Args (7);
9596 Gather_Associations (Names, Args);
9597 Process_Extended_Import_Export_Subprogram_Pragma (
9598 Arg_Internal => Internal,
9599 Arg_External => External,
9600 Arg_Parameter_Types => Parameter_Types,
9601 Arg_Result_Type => Result_Type,
9602 Arg_Mechanism => Mechanism,
9603 Arg_Result_Mechanism => Result_Mechanism,
9604 Arg_First_Optional_Parameter => First_Optional_Parameter);
9605 end Import_Function;
9611 -- pragma Import_Object (
9612 -- [Internal =>] LOCAL_NAME
9613 -- [, [External =>] EXTERNAL_SYMBOL]
9614 -- [, [Size =>] EXTERNAL_SYMBOL]);
9616 -- EXTERNAL_SYMBOL ::=
9618 -- | static_string_EXPRESSION
9620 when Pragma_Import_Object => Import_Object : declare
9621 Args : Args_List (1 .. 3);
9622 Names : constant Name_List (1 .. 3) := (
9627 Internal : Node_Id renames Args (1);
9628 External : Node_Id renames Args (2);
9629 Size : Node_Id renames Args (3);
9633 Gather_Associations (Names, Args);
9634 Process_Extended_Import_Export_Object_Pragma (
9635 Arg_Internal => Internal,
9636 Arg_External => External,
9640 ----------------------
9641 -- Import_Procedure --
9642 ----------------------
9644 -- pragma Import_Procedure (
9645 -- [Internal =>] LOCAL_NAME
9646 -- [, [External =>] EXTERNAL_SYMBOL]
9647 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9648 -- [, [Mechanism =>] MECHANISM]
9649 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9651 -- EXTERNAL_SYMBOL ::=
9653 -- | static_string_EXPRESSION
9655 -- PARAMETER_TYPES ::=
9657 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9659 -- TYPE_DESIGNATOR ::=
9661 -- | subtype_Name ' Access
9665 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9667 -- MECHANISM_ASSOCIATION ::=
9668 -- [formal_parameter_NAME =>] MECHANISM_NAME
9670 -- MECHANISM_NAME ::=
9673 -- | Descriptor [([Class =>] CLASS_NAME)]
9675 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9677 when Pragma_Import_Procedure => Import_Procedure : declare
9678 Args : Args_List (1 .. 5);
9679 Names : constant Name_List (1 .. 5) := (
9682 Name_Parameter_Types,
9684 Name_First_Optional_Parameter);
9686 Internal : Node_Id renames Args (1);
9687 External : Node_Id renames Args (2);
9688 Parameter_Types : Node_Id renames Args (3);
9689 Mechanism : Node_Id renames Args (4);
9690 First_Optional_Parameter : Node_Id renames Args (5);
9694 Gather_Associations (Names, Args);
9695 Process_Extended_Import_Export_Subprogram_Pragma (
9696 Arg_Internal => Internal,
9697 Arg_External => External,
9698 Arg_Parameter_Types => Parameter_Types,
9699 Arg_Mechanism => Mechanism,
9700 Arg_First_Optional_Parameter => First_Optional_Parameter);
9701 end Import_Procedure;
9703 -----------------------------
9704 -- Import_Valued_Procedure --
9705 -----------------------------
9707 -- pragma Import_Valued_Procedure (
9708 -- [Internal =>] LOCAL_NAME
9709 -- [, [External =>] EXTERNAL_SYMBOL]
9710 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9711 -- [, [Mechanism =>] MECHANISM]
9712 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9714 -- EXTERNAL_SYMBOL ::=
9716 -- | static_string_EXPRESSION
9718 -- PARAMETER_TYPES ::=
9720 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9722 -- TYPE_DESIGNATOR ::=
9724 -- | subtype_Name ' Access
9728 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9730 -- MECHANISM_ASSOCIATION ::=
9731 -- [formal_parameter_NAME =>] MECHANISM_NAME
9733 -- MECHANISM_NAME ::=
9736 -- | Descriptor [([Class =>] CLASS_NAME)]
9738 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9740 when Pragma_Import_Valued_Procedure =>
9741 Import_Valued_Procedure : declare
9742 Args : Args_List (1 .. 5);
9743 Names : constant Name_List (1 .. 5) := (
9746 Name_Parameter_Types,
9748 Name_First_Optional_Parameter);
9750 Internal : Node_Id renames Args (1);
9751 External : Node_Id renames Args (2);
9752 Parameter_Types : Node_Id renames Args (3);
9753 Mechanism : Node_Id renames Args (4);
9754 First_Optional_Parameter : Node_Id renames Args (5);
9758 Gather_Associations (Names, Args);
9759 Process_Extended_Import_Export_Subprogram_Pragma (
9760 Arg_Internal => Internal,
9761 Arg_External => External,
9762 Arg_Parameter_Types => Parameter_Types,
9763 Arg_Mechanism => Mechanism,
9764 Arg_First_Optional_Parameter => First_Optional_Parameter);
9765 end Import_Valued_Procedure;
9771 -- pragma Independent (LOCAL_NAME);
9773 when Pragma_Independent => Independent : declare
9780 Check_Ada_83_Warning;
9782 Check_No_Identifiers;
9783 Check_Arg_Count (1);
9784 Check_Arg_Is_Local_Name (Arg1);
9785 E_Id := Get_Pragma_Arg (Arg1);
9787 if Etype (E_Id) = Any_Type then
9792 D := Declaration_Node (E);
9795 -- Check duplicate before we chain ourselves!
9797 Check_Duplicate_Pragma (E);
9799 -- Check appropriate entity
9802 if Rep_Item_Too_Early (E, N)
9804 Rep_Item_Too_Late (E, N)
9808 Check_First_Subtype (Arg1);
9811 elsif K = N_Object_Declaration
9812 or else (K = N_Component_Declaration
9813 and then Original_Record_Component (E) = E)
9815 if Rep_Item_Too_Late (E, N) then
9821 ("inappropriate entity for pragma%", Arg1);
9824 Independence_Checks.Append ((N, E));
9827 ----------------------------
9828 -- Independent_Components --
9829 ----------------------------
9831 -- pragma Atomic_Components (array_LOCAL_NAME);
9833 -- This processing is shared by Volatile_Components
9835 when Pragma_Independent_Components => Independent_Components : declare
9842 Check_Ada_83_Warning;
9844 Check_No_Identifiers;
9845 Check_Arg_Count (1);
9846 Check_Arg_Is_Local_Name (Arg1);
9847 E_Id := Get_Pragma_Arg (Arg1);
9849 if Etype (E_Id) = Any_Type then
9855 -- Check duplicate before we chain ourselves!
9857 Check_Duplicate_Pragma (E);
9859 -- Check appropriate entity
9861 if Rep_Item_Too_Early (E, N)
9863 Rep_Item_Too_Late (E, N)
9868 D := Declaration_Node (E);
9871 if (K = N_Full_Type_Declaration
9872 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9874 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9875 and then Nkind (D) = N_Object_Declaration
9876 and then Nkind (Object_Definition (D)) =
9877 N_Constrained_Array_Definition)
9879 Independence_Checks.Append ((N, E));
9882 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9884 end Independent_Components;
9886 ------------------------
9887 -- Initialize_Scalars --
9888 ------------------------
9890 -- pragma Initialize_Scalars;
9892 when Pragma_Initialize_Scalars =>
9894 Check_Arg_Count (0);
9895 Check_Valid_Configuration_Pragma;
9896 Check_Restriction (No_Initialize_Scalars, N);
9898 -- Initialize_Scalars creates false positives in CodePeer, and
9899 -- incorrect negative results in Alfa mode, so ignore this pragma
9902 if not Restriction_Active (No_Initialize_Scalars)
9903 and then not (CodePeer_Mode or Alfa_Mode)
9905 Init_Or_Norm_Scalars := True;
9906 Initialize_Scalars := True;
9913 -- pragma Inline ( NAME {, NAME} );
9915 when Pragma_Inline =>
9917 -- Pragma is active if inlining option is active
9919 Process_Inline (Inline_Active);
9925 -- pragma Inline_Always ( NAME {, NAME} );
9927 when Pragma_Inline_Always =>
9930 -- Pragma always active unless in CodePeer or Alfa mode, since
9931 -- this causes walk order issues.
9933 if not (CodePeer_Mode or Alfa_Mode) then
9934 Process_Inline (True);
9937 --------------------
9938 -- Inline_Generic --
9939 --------------------
9941 -- pragma Inline_Generic (NAME {, NAME});
9943 when Pragma_Inline_Generic =>
9945 Process_Generic_List;
9947 ----------------------
9948 -- Inspection_Point --
9949 ----------------------
9951 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9953 when Pragma_Inspection_Point => Inspection_Point : declare
9958 if Arg_Count > 0 then
9961 Exp := Get_Pragma_Arg (Arg);
9964 if not Is_Entity_Name (Exp)
9965 or else not Is_Object (Entity (Exp))
9967 Error_Pragma_Arg ("object name required", Arg);
9974 end Inspection_Point;
9980 -- pragma Interface (
9981 -- [ Convention =>] convention_IDENTIFIER,
9982 -- [ Entity =>] local_NAME
9983 -- [, [External_Name =>] static_string_EXPRESSION ]
9984 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9986 when Pragma_Interface =>
9993 Check_At_Least_N_Arguments (2);
9994 Check_At_Most_N_Arguments (4);
9995 Process_Import_Or_Interface;
9997 -- In Ada 2005, the permission to use Interface (a reserved word)
9998 -- as a pragma name is considered an obsolescent feature.
10000 if Ada_Version >= Ada_2005 then
10002 (No_Obsolescent_Features, Pragma_Identifier (N));
10005 --------------------
10006 -- Interface_Name --
10007 --------------------
10009 -- pragma Interface_Name (
10010 -- [ Entity =>] local_NAME
10011 -- [,[External_Name =>] static_string_EXPRESSION ]
10012 -- [,[Link_Name =>] static_string_EXPRESSION ]);
10014 when Pragma_Interface_Name => Interface_Name : declare
10016 Def_Id : Entity_Id;
10017 Hom_Id : Entity_Id;
10023 ((Name_Entity, Name_External_Name, Name_Link_Name));
10024 Check_At_Least_N_Arguments (2);
10025 Check_At_Most_N_Arguments (3);
10026 Id := Get_Pragma_Arg (Arg1);
10029 if not Is_Entity_Name (Id) then
10031 ("first argument for pragma% must be entity name", Arg1);
10032 elsif Etype (Id) = Any_Type then
10035 Def_Id := Entity (Id);
10038 -- Special DEC-compatible processing for the object case, forces
10039 -- object to be imported.
10041 if Ekind (Def_Id) = E_Variable then
10042 Kill_Size_Check_Code (Def_Id);
10043 Note_Possible_Modification (Id, Sure => False);
10045 -- Initialization is not allowed for imported variable
10047 if Present (Expression (Parent (Def_Id)))
10048 and then Comes_From_Source (Expression (Parent (Def_Id)))
10050 Error_Msg_Sloc := Sloc (Def_Id);
10052 ("no initialization allowed for declaration of& #",
10056 -- For compatibility, support VADS usage of providing both
10057 -- pragmas Interface and Interface_Name to obtain the effect
10058 -- of a single Import pragma.
10060 if Is_Imported (Def_Id)
10061 and then Present (First_Rep_Item (Def_Id))
10062 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
10064 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
10068 Set_Imported (Def_Id);
10071 Set_Is_Public (Def_Id);
10072 Process_Interface_Name (Def_Id, Arg2, Arg3);
10075 -- Otherwise must be subprogram
10077 elsif not Is_Subprogram (Def_Id) then
10079 ("argument of pragma% is not subprogram", Arg1);
10082 Check_At_Most_N_Arguments (3);
10086 -- Loop through homonyms
10089 Def_Id := Get_Base_Subprogram (Hom_Id);
10091 if Is_Imported (Def_Id) then
10092 Process_Interface_Name (Def_Id, Arg2, Arg3);
10096 exit when From_Aspect_Specification (N);
10097 Hom_Id := Homonym (Hom_Id);
10099 exit when No (Hom_Id)
10100 or else Scope (Hom_Id) /= Current_Scope;
10105 ("argument of pragma% is not imported subprogram",
10109 end Interface_Name;
10111 -----------------------
10112 -- Interrupt_Handler --
10113 -----------------------
10115 -- pragma Interrupt_Handler (handler_NAME);
10117 when Pragma_Interrupt_Handler =>
10118 Check_Ada_83_Warning;
10119 Check_Arg_Count (1);
10120 Check_No_Identifiers;
10122 if No_Run_Time_Mode then
10123 Error_Msg_CRT ("Interrupt_Handler pragma", N);
10125 Check_Interrupt_Or_Attach_Handler;
10126 Process_Interrupt_Or_Attach_Handler;
10129 ------------------------
10130 -- Interrupt_Priority --
10131 ------------------------
10133 -- pragma Interrupt_Priority [(EXPRESSION)];
10135 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
10136 P : constant Node_Id := Parent (N);
10140 Check_Ada_83_Warning;
10142 if Arg_Count /= 0 then
10143 Arg := Get_Pragma_Arg (Arg1);
10144 Check_Arg_Count (1);
10145 Check_No_Identifiers;
10147 -- The expression must be analyzed in the special manner
10148 -- described in "Handling of Default and Per-Object
10149 -- Expressions" in sem.ads.
10151 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
10154 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
10158 elsif Has_Pragma_Priority (P) then
10159 Error_Pragma ("duplicate pragma% not allowed");
10162 Set_Has_Pragma_Priority (P, True);
10163 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10165 end Interrupt_Priority;
10167 ---------------------
10168 -- Interrupt_State --
10169 ---------------------
10171 -- pragma Interrupt_State (
10172 -- [Name =>] INTERRUPT_ID,
10173 -- [State =>] INTERRUPT_STATE);
10175 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
10176 -- INTERRUPT_STATE => System | Runtime | User
10178 -- Note: if the interrupt id is given as an identifier, then it must
10179 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
10180 -- given as a static integer expression which must be in the range of
10181 -- Ada.Interrupts.Interrupt_ID.
10183 when Pragma_Interrupt_State => Interrupt_State : declare
10185 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
10186 -- This is the entity Ada.Interrupts.Interrupt_ID;
10188 State_Type : Character;
10189 -- Set to 's'/'r'/'u' for System/Runtime/User
10192 -- Index to entry in Interrupt_States table
10195 -- Value of interrupt
10197 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
10198 -- The first argument to the pragma
10200 Int_Ent : Entity_Id;
10201 -- Interrupt entity in Ada.Interrupts.Names
10205 Check_Arg_Order ((Name_Name, Name_State));
10206 Check_Arg_Count (2);
10208 Check_Optional_Identifier (Arg1, Name_Name);
10209 Check_Optional_Identifier (Arg2, Name_State);
10210 Check_Arg_Is_Identifier (Arg2);
10212 -- First argument is identifier
10214 if Nkind (Arg1X) = N_Identifier then
10216 -- Search list of names in Ada.Interrupts.Names
10218 Int_Ent := First_Entity (RTE (RE_Names));
10220 if No (Int_Ent) then
10221 Error_Pragma_Arg ("invalid interrupt name", Arg1);
10223 elsif Chars (Int_Ent) = Chars (Arg1X) then
10224 Int_Val := Expr_Value (Constant_Value (Int_Ent));
10228 Next_Entity (Int_Ent);
10231 -- First argument is not an identifier, so it must be a static
10232 -- expression of type Ada.Interrupts.Interrupt_ID.
10235 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10236 Int_Val := Expr_Value (Arg1X);
10238 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
10240 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10243 ("value not in range of type " &
10244 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10250 case Chars (Get_Pragma_Arg (Arg2)) is
10251 when Name_Runtime => State_Type := 'r';
10252 when Name_System => State_Type := 's';
10253 when Name_User => State_Type := 'u';
10256 Error_Pragma_Arg ("invalid interrupt state", Arg2);
10259 -- Check if entry is already stored
10261 IST_Num := Interrupt_States.First;
10263 -- If entry not found, add it
10265 if IST_Num > Interrupt_States.Last then
10266 Interrupt_States.Append
10267 ((Interrupt_Number => UI_To_Int (Int_Val),
10268 Interrupt_State => State_Type,
10269 Pragma_Loc => Loc));
10272 -- Case of entry for the same entry
10274 elsif Int_Val = Interrupt_States.Table (IST_Num).
10277 -- If state matches, done, no need to make redundant entry
10280 State_Type = Interrupt_States.Table (IST_Num).
10283 -- Otherwise if state does not match, error
10286 Interrupt_States.Table (IST_Num).Pragma_Loc;
10288 ("state conflicts with that given #", Arg2);
10292 IST_Num := IST_Num + 1;
10294 end Interrupt_State;
10300 -- pragma Invariant
10301 -- ([Entity =>] type_LOCAL_NAME,
10302 -- [Check =>] EXPRESSION
10303 -- [,[Message =>] String_Expression]);
10305 when Pragma_Invariant => Invariant : declare
10310 pragma Unreferenced (Discard);
10314 Check_At_Least_N_Arguments (2);
10315 Check_At_Most_N_Arguments (3);
10316 Check_Optional_Identifier (Arg1, Name_Entity);
10317 Check_Optional_Identifier (Arg2, Name_Check);
10319 if Arg_Count = 3 then
10320 Check_Optional_Identifier (Arg3, Name_Message);
10321 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10324 Check_Arg_Is_Local_Name (Arg1);
10326 Type_Id := Get_Pragma_Arg (Arg1);
10327 Find_Type (Type_Id);
10328 Typ := Entity (Type_Id);
10330 if Typ = Any_Type then
10333 -- An invariant must apply to a private type, or appear in the
10334 -- private part of a package spec and apply to a completion.
10336 elsif Ekind_In (Typ, E_Private_Type,
10337 E_Record_Type_With_Private,
10338 E_Limited_Private_Type)
10342 elsif In_Private_Part (Current_Scope)
10343 and then Has_Private_Declaration (Typ)
10347 elsif In_Private_Part (Current_Scope) then
10349 ("pragma% only allowed for private type " &
10350 "declared in visible part", Arg1);
10354 ("pragma% only allowed for private type", Arg1);
10357 -- Note that the type has at least one invariant, and also that
10358 -- it has inheritable invariants if we have Invariant'Class.
10360 Set_Has_Invariants (Typ);
10362 if Class_Present (N) then
10363 Set_Has_Inheritable_Invariants (Typ);
10366 -- The remaining processing is simply to link the pragma on to
10367 -- the rep item chain, for processing when the type is frozen.
10368 -- This is accomplished by a call to Rep_Item_Too_Late.
10370 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10373 ----------------------
10374 -- Java_Constructor --
10375 ----------------------
10377 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10379 -- Also handles pragma CIL_Constructor
10381 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10382 Java_Constructor : declare
10383 Convention : Convention_Id;
10384 Def_Id : Entity_Id;
10385 Hom_Id : Entity_Id;
10387 This_Formal : Entity_Id;
10391 Check_Arg_Count (1);
10392 Check_Optional_Identifier (Arg1, Name_Entity);
10393 Check_Arg_Is_Local_Name (Arg1);
10395 Id := Get_Pragma_Arg (Arg1);
10396 Find_Program_Unit_Name (Id);
10398 -- If we did not find the name, we are done
10400 if Etype (Id) = Any_Type then
10404 -- Check wrong use of pragma in wrong VM target
10406 if VM_Target = No_VM then
10409 elsif VM_Target = CLI_Target
10410 and then Prag_Id = Pragma_Java_Constructor
10412 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10414 elsif VM_Target = JVM_Target
10415 and then Prag_Id = Pragma_CIL_Constructor
10417 Error_Pragma ("must use pragma 'Java_'Constructor");
10421 when Pragma_CIL_Constructor => Convention := Convention_CIL;
10422 when Pragma_Java_Constructor => Convention := Convention_Java;
10423 when others => null;
10426 Hom_Id := Entity (Id);
10428 -- Loop through homonyms
10431 Def_Id := Get_Base_Subprogram (Hom_Id);
10433 -- The constructor is required to be a function
10435 if Ekind (Def_Id) /= E_Function then
10436 if VM_Target = JVM_Target then
10438 ("pragma% requires function returning a " &
10439 "'Java access type", Def_Id);
10442 ("pragma% requires function returning a " &
10443 "'C'I'L access type", Def_Id);
10447 -- Check arguments: For tagged type the first formal must be
10448 -- named "this" and its type must be a named access type
10449 -- designating a class-wide tagged type that has convention
10450 -- CIL/Java. The first formal must also have a null default
10451 -- value. For example:
10453 -- type Typ is tagged ...
10454 -- type Ref is access all Typ;
10455 -- pragma Convention (CIL, Typ);
10457 -- function New_Typ (This : Ref) return Ref;
10458 -- function New_Typ (This : Ref; I : Integer) return Ref;
10459 -- pragma Cil_Constructor (New_Typ);
10461 -- Reason: The first formal must NOT be a primitive of the
10464 -- This rule also applies to constructors of delegates used
10465 -- to interface with standard target libraries. For example:
10467 -- type Delegate is access procedure ...
10468 -- pragma Import (CIL, Delegate, ...);
10470 -- function new_Delegate
10471 -- (This : Delegate := null; ... ) return Delegate;
10473 -- For value-types this rule does not apply.
10475 if not Is_Value_Type (Etype (Def_Id)) then
10476 if No (First_Formal (Def_Id)) then
10477 Error_Msg_Name_1 := Pname;
10478 Error_Msg_N ("% function must have parameters", Def_Id);
10482 -- In the JRE library we have several occurrences in which
10483 -- the "this" parameter is not the first formal.
10485 This_Formal := First_Formal (Def_Id);
10487 -- In the JRE library we have several occurrences in which
10488 -- the "this" parameter is not the first formal. Search for
10491 if VM_Target = JVM_Target then
10492 while Present (This_Formal)
10493 and then Get_Name_String (Chars (This_Formal)) /= "this"
10495 Next_Formal (This_Formal);
10498 if No (This_Formal) then
10499 This_Formal := First_Formal (Def_Id);
10503 -- Warning: The first parameter should be named "this".
10504 -- We temporarily allow it because we have the following
10505 -- case in the Java runtime (file s-osinte.ads) ???
10507 -- function new_Thread
10508 -- (Self_Id : System.Address) return Thread_Id;
10509 -- pragma Java_Constructor (new_Thread);
10511 if VM_Target = JVM_Target
10512 and then Get_Name_String (Chars (First_Formal (Def_Id)))
10514 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10518 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10519 Error_Msg_Name_1 := Pname;
10521 ("first formal of % function must be named `this`",
10522 Parent (This_Formal));
10524 elsif not Is_Access_Type (Etype (This_Formal)) then
10525 Error_Msg_Name_1 := Pname;
10527 ("first formal of % function must be an access type",
10528 Parameter_Type (Parent (This_Formal)));
10530 -- For delegates the type of the first formal must be a
10531 -- named access-to-subprogram type (see previous example)
10533 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10534 and then Ekind (Etype (This_Formal))
10535 /= E_Access_Subprogram_Type
10537 Error_Msg_Name_1 := Pname;
10539 ("first formal of % function must be a named access" &
10540 " to subprogram type",
10541 Parameter_Type (Parent (This_Formal)));
10543 -- Warning: We should reject anonymous access types because
10544 -- the constructor must not be handled as a primitive of the
10545 -- tagged type. We temporarily allow it because this profile
10546 -- is currently generated by cil2ada???
10548 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10549 and then not Ekind_In (Etype (This_Formal),
10551 E_General_Access_Type,
10552 E_Anonymous_Access_Type)
10554 Error_Msg_Name_1 := Pname;
10556 ("first formal of % function must be a named access" &
10558 Parameter_Type (Parent (This_Formal)));
10560 elsif Atree.Convention
10561 (Designated_Type (Etype (This_Formal))) /= Convention
10563 Error_Msg_Name_1 := Pname;
10565 if Convention = Convention_Java then
10567 ("pragma% requires convention 'Cil in designated" &
10569 Parameter_Type (Parent (This_Formal)));
10572 ("pragma% requires convention 'Java in designated" &
10574 Parameter_Type (Parent (This_Formal)));
10577 elsif No (Expression (Parent (This_Formal)))
10578 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10580 Error_Msg_Name_1 := Pname;
10582 ("pragma% requires first formal with default `null`",
10583 Parameter_Type (Parent (This_Formal)));
10587 -- Check result type: the constructor must be a function
10589 -- * a value type (only allowed in the CIL compiler)
10590 -- * an access-to-subprogram type with convention Java/CIL
10591 -- * an access-type designating a type that has convention
10594 if Is_Value_Type (Etype (Def_Id)) then
10597 -- Access-to-subprogram type with convention Java/CIL
10599 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10600 if Atree.Convention (Etype (Def_Id)) /= Convention then
10601 if Convention = Convention_Java then
10603 ("pragma% requires function returning a " &
10604 "'Java access type", Arg1);
10606 pragma Assert (Convention = Convention_CIL);
10608 ("pragma% requires function returning a " &
10609 "'C'I'L access type", Arg1);
10613 elsif Ekind (Etype (Def_Id)) in Access_Kind then
10614 if not Ekind_In (Etype (Def_Id), E_Access_Type,
10615 E_General_Access_Type)
10618 (Designated_Type (Etype (Def_Id))) /= Convention
10620 Error_Msg_Name_1 := Pname;
10622 if Convention = Convention_Java then
10624 ("pragma% requires function returning a named" &
10625 "'Java access type", Arg1);
10628 ("pragma% requires function returning a named" &
10629 "'C'I'L access type", Arg1);
10634 Set_Is_Constructor (Def_Id);
10635 Set_Convention (Def_Id, Convention);
10636 Set_Is_Imported (Def_Id);
10638 exit when From_Aspect_Specification (N);
10639 Hom_Id := Homonym (Hom_Id);
10641 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10643 end Java_Constructor;
10645 ----------------------
10646 -- Java_Interface --
10647 ----------------------
10649 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
10651 when Pragma_Java_Interface => Java_Interface : declare
10657 Check_Arg_Count (1);
10658 Check_Optional_Identifier (Arg1, Name_Entity);
10659 Check_Arg_Is_Local_Name (Arg1);
10661 Arg := Get_Pragma_Arg (Arg1);
10664 if Etype (Arg) = Any_Type then
10668 if not Is_Entity_Name (Arg)
10669 or else not Is_Type (Entity (Arg))
10671 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10674 Typ := Underlying_Type (Entity (Arg));
10676 -- For now simply check some of the semantic constraints on the
10677 -- type. This currently leaves out some restrictions on interface
10678 -- types, namely that the parent type must be java.lang.Object.Typ
10679 -- and that all primitives of the type should be declared
10682 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10683 Error_Pragma_Arg ("pragma% requires an abstract "
10684 & "tagged type", Arg1);
10686 elsif not Has_Discriminants (Typ)
10687 or else Ekind (Etype (First_Discriminant (Typ)))
10688 /= E_Anonymous_Access_Type
10690 not Is_Class_Wide_Type
10691 (Designated_Type (Etype (First_Discriminant (Typ))))
10694 ("type must have a class-wide access discriminant", Arg1);
10696 end Java_Interface;
10702 -- pragma Keep_Names ([On => ] local_NAME);
10704 when Pragma_Keep_Names => Keep_Names : declare
10709 Check_Arg_Count (1);
10710 Check_Optional_Identifier (Arg1, Name_On);
10711 Check_Arg_Is_Local_Name (Arg1);
10713 Arg := Get_Pragma_Arg (Arg1);
10716 if Etype (Arg) = Any_Type then
10720 if not Is_Entity_Name (Arg)
10721 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10724 ("pragma% requires a local enumeration type", Arg1);
10727 Set_Discard_Names (Entity (Arg), False);
10734 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10736 when Pragma_License =>
10738 Check_Arg_Count (1);
10739 Check_No_Identifiers;
10740 Check_Valid_Configuration_Pragma;
10741 Check_Arg_Is_Identifier (Arg1);
10744 Sind : constant Source_File_Index :=
10745 Source_Index (Current_Sem_Unit);
10748 case Chars (Get_Pragma_Arg (Arg1)) is
10750 Set_License (Sind, GPL);
10752 when Name_Modified_GPL =>
10753 Set_License (Sind, Modified_GPL);
10755 when Name_Restricted =>
10756 Set_License (Sind, Restricted);
10758 when Name_Unrestricted =>
10759 Set_License (Sind, Unrestricted);
10762 Error_Pragma_Arg ("invalid license name", Arg1);
10770 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10772 when Pragma_Link_With => Link_With : declare
10778 if Operating_Mode = Generate_Code
10779 and then In_Extended_Main_Source_Unit (N)
10781 Check_At_Least_N_Arguments (1);
10782 Check_No_Identifiers;
10783 Check_Is_In_Decl_Part_Or_Package_Spec;
10784 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10788 while Present (Arg) loop
10789 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10791 -- Store argument, converting sequences of spaces to a
10792 -- single null character (this is one of the differences
10793 -- in processing between Link_With and Linker_Options).
10795 Arg_Store : declare
10796 C : constant Char_Code := Get_Char_Code (' ');
10797 S : constant String_Id :=
10798 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10799 L : constant Nat := String_Length (S);
10802 procedure Skip_Spaces;
10803 -- Advance F past any spaces
10809 procedure Skip_Spaces is
10811 while F <= L and then Get_String_Char (S, F) = C loop
10816 -- Start of processing for Arg_Store
10819 Skip_Spaces; -- skip leading spaces
10821 -- Loop through characters, changing any embedded
10822 -- sequence of spaces to a single null character (this
10823 -- is how Link_With/Linker_Options differ)
10826 if Get_String_Char (S, F) = C then
10829 Store_String_Char (ASCII.NUL);
10832 Store_String_Char (Get_String_Char (S, F));
10840 if Present (Arg) then
10841 Store_String_Char (ASCII.NUL);
10845 Store_Linker_Option_String (End_String);
10853 -- pragma Linker_Alias (
10854 -- [Entity =>] LOCAL_NAME
10855 -- [Target =>] static_string_EXPRESSION);
10857 when Pragma_Linker_Alias =>
10859 Check_Arg_Order ((Name_Entity, Name_Target));
10860 Check_Arg_Count (2);
10861 Check_Optional_Identifier (Arg1, Name_Entity);
10862 Check_Optional_Identifier (Arg2, Name_Target);
10863 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10864 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10866 -- The only processing required is to link this item on to the
10867 -- list of rep items for the given entity. This is accomplished
10868 -- by the call to Rep_Item_Too_Late (when no error is detected
10869 -- and False is returned).
10871 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10874 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10877 ------------------------
10878 -- Linker_Constructor --
10879 ------------------------
10881 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10883 -- Code is shared with Linker_Destructor
10885 -----------------------
10886 -- Linker_Destructor --
10887 -----------------------
10889 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10891 when Pragma_Linker_Constructor |
10892 Pragma_Linker_Destructor =>
10893 Linker_Constructor : declare
10899 Check_Arg_Count (1);
10900 Check_No_Identifiers;
10901 Check_Arg_Is_Local_Name (Arg1);
10902 Arg1_X := Get_Pragma_Arg (Arg1);
10904 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10906 if not Is_Library_Level_Entity (Proc) then
10908 ("argument for pragma% must be library level entity", Arg1);
10911 -- The only processing required is to link this item on to the
10912 -- list of rep items for the given entity. This is accomplished
10913 -- by the call to Rep_Item_Too_Late (when no error is detected
10914 -- and False is returned).
10916 if Rep_Item_Too_Late (Proc, N) then
10919 Set_Has_Gigi_Rep_Item (Proc);
10921 end Linker_Constructor;
10923 --------------------
10924 -- Linker_Options --
10925 --------------------
10927 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10929 when Pragma_Linker_Options => Linker_Options : declare
10933 Check_Ada_83_Warning;
10934 Check_No_Identifiers;
10935 Check_Arg_Count (1);
10936 Check_Is_In_Decl_Part_Or_Package_Spec;
10937 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10938 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10941 while Present (Arg) loop
10942 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10943 Store_String_Char (ASCII.NUL);
10945 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10949 if Operating_Mode = Generate_Code
10950 and then In_Extended_Main_Source_Unit (N)
10952 Store_Linker_Option_String (End_String);
10954 end Linker_Options;
10956 --------------------
10957 -- Linker_Section --
10958 --------------------
10960 -- pragma Linker_Section (
10961 -- [Entity =>] LOCAL_NAME
10962 -- [Section =>] static_string_EXPRESSION);
10964 when Pragma_Linker_Section =>
10966 Check_Arg_Order ((Name_Entity, Name_Section));
10967 Check_Arg_Count (2);
10968 Check_Optional_Identifier (Arg1, Name_Entity);
10969 Check_Optional_Identifier (Arg2, Name_Section);
10970 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10971 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10973 -- This pragma applies only to objects
10975 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10976 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10979 -- The only processing required is to link this item on to the
10980 -- list of rep items for the given entity. This is accomplished
10981 -- by the call to Rep_Item_Too_Late (when no error is detected
10982 -- and False is returned).
10984 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10987 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10994 -- pragma List (On | Off)
10996 -- There is nothing to do here, since we did all the processing for
10997 -- this pragma in Par.Prag (so that it works properly even in syntax
11000 when Pragma_List =>
11003 --------------------
11004 -- Locking_Policy --
11005 --------------------
11007 -- pragma Locking_Policy (policy_IDENTIFIER);
11009 when Pragma_Locking_Policy => declare
11010 subtype LP_Range is Name_Id
11011 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
11015 Check_Ada_83_Warning;
11016 Check_Arg_Count (1);
11017 Check_No_Identifiers;
11018 Check_Arg_Is_Locking_Policy (Arg1);
11019 Check_Valid_Configuration_Pragma;
11020 LP_Val := Chars (Get_Pragma_Arg (Arg1));
11023 when Name_Ceiling_Locking => LP := 'C';
11024 when Name_Inheritance_Locking => LP := 'I';
11025 when Name_Concurrent_Readers_Locking => LP := 'R';
11028 if Locking_Policy /= ' '
11029 and then Locking_Policy /= LP
11031 Error_Msg_Sloc := Locking_Policy_Sloc;
11032 Error_Pragma ("locking policy incompatible with policy#");
11034 -- Set new policy, but always preserve System_Location since we
11035 -- like the error message with the run time name.
11038 Locking_Policy := LP;
11040 if Locking_Policy_Sloc /= System_Location then
11041 Locking_Policy_Sloc := Loc;
11050 -- pragma Long_Float (D_Float | G_Float);
11052 when Pragma_Long_Float => Long_Float : declare
11055 Check_Valid_Configuration_Pragma;
11056 Check_Arg_Count (1);
11057 Check_No_Identifier (Arg1);
11058 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
11060 if not OpenVMS_On_Target then
11061 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
11066 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
11067 if Opt.Float_Format_Long = 'G' then
11069 ("G_Float previously specified", Arg1);
11071 elsif Current_Sem_Unit /= Main_Unit
11072 and then Opt.Float_Format_Long /= 'D'
11075 ("main unit not compiled with pragma Long_Float (D_Float)",
11076 "\pragma% must be used consistently for whole partition",
11080 Opt.Float_Format_Long := 'D';
11083 -- G_Float case (this is the default, does not need overriding)
11086 if Opt.Float_Format_Long = 'D' then
11087 Error_Pragma ("D_Float previously specified");
11089 elsif Current_Sem_Unit /= Main_Unit
11090 and then Opt.Float_Format_Long /= 'G'
11093 ("main unit not compiled with pragma Long_Float (G_Float)",
11094 "\pragma% must be used consistently for whole partition",
11098 Opt.Float_Format_Long := 'G';
11102 Set_Standard_Fpt_Formats;
11105 -----------------------
11106 -- Machine_Attribute --
11107 -----------------------
11109 -- pragma Machine_Attribute (
11110 -- [Entity =>] LOCAL_NAME,
11111 -- [Attribute_Name =>] static_string_EXPRESSION
11112 -- [, [Info =>] static_EXPRESSION] );
11114 when Pragma_Machine_Attribute => Machine_Attribute : declare
11115 Def_Id : Entity_Id;
11119 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
11121 if Arg_Count = 3 then
11122 Check_Optional_Identifier (Arg3, Name_Info);
11123 Check_Arg_Is_Static_Expression (Arg3);
11125 Check_Arg_Count (2);
11128 Check_Optional_Identifier (Arg1, Name_Entity);
11129 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
11130 Check_Arg_Is_Local_Name (Arg1);
11131 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11132 Def_Id := Entity (Get_Pragma_Arg (Arg1));
11134 if Is_Access_Type (Def_Id) then
11135 Def_Id := Designated_Type (Def_Id);
11138 if Rep_Item_Too_Early (Def_Id, N) then
11142 Def_Id := Underlying_Type (Def_Id);
11144 -- The only processing required is to link this item on to the
11145 -- list of rep items for the given entity. This is accomplished
11146 -- by the call to Rep_Item_Too_Late (when no error is detected
11147 -- and False is returned).
11149 if Rep_Item_Too_Late (Def_Id, N) then
11152 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11154 end Machine_Attribute;
11161 -- (MAIN_OPTION [, MAIN_OPTION]);
11164 -- [STACK_SIZE =>] static_integer_EXPRESSION
11165 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
11166 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
11168 when Pragma_Main => Main : declare
11169 Args : Args_List (1 .. 3);
11170 Names : constant Name_List (1 .. 3) := (
11172 Name_Task_Stack_Size_Default,
11173 Name_Time_Slicing_Enabled);
11179 Gather_Associations (Names, Args);
11181 for J in 1 .. 2 loop
11182 if Present (Args (J)) then
11183 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11187 if Present (Args (3)) then
11188 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
11192 while Present (Nod) loop
11193 if Nkind (Nod) = N_Pragma
11194 and then Pragma_Name (Nod) = Name_Main
11196 Error_Msg_Name_1 := Pname;
11197 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11208 -- pragma Main_Storage
11209 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
11211 -- MAIN_STORAGE_OPTION ::=
11212 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
11213 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
11215 when Pragma_Main_Storage => Main_Storage : declare
11216 Args : Args_List (1 .. 2);
11217 Names : constant Name_List (1 .. 2) := (
11218 Name_Working_Storage,
11225 Gather_Associations (Names, Args);
11227 for J in 1 .. 2 loop
11228 if Present (Args (J)) then
11229 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11233 Check_In_Main_Program;
11236 while Present (Nod) loop
11237 if Nkind (Nod) = N_Pragma
11238 and then Pragma_Name (Nod) = Name_Main_Storage
11240 Error_Msg_Name_1 := Pname;
11241 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11252 -- pragma Memory_Size (NUMERIC_LITERAL)
11254 when Pragma_Memory_Size =>
11257 -- Memory size is simply ignored
11259 Check_No_Identifiers;
11260 Check_Arg_Count (1);
11261 Check_Arg_Is_Integer_Literal (Arg1);
11269 -- The only correct use of this pragma is on its own in a file, in
11270 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
11271 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
11272 -- check for a file containing nothing but a No_Body pragma). If we
11273 -- attempt to process it during normal semantics processing, it means
11274 -- it was misplaced.
11276 when Pragma_No_Body =>
11284 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
11286 when Pragma_No_Return => No_Return : declare
11294 Check_At_Least_N_Arguments (1);
11296 -- Loop through arguments of pragma
11299 while Present (Arg) loop
11300 Check_Arg_Is_Local_Name (Arg);
11301 Id := Get_Pragma_Arg (Arg);
11304 if not Is_Entity_Name (Id) then
11305 Error_Pragma_Arg ("entity name required", Arg);
11308 if Etype (Id) = Any_Type then
11312 -- Loop to find matching procedures
11317 and then Scope (E) = Current_Scope
11319 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11322 -- Set flag on any alias as well
11324 if Is_Overloadable (E) and then Present (Alias (E)) then
11325 Set_No_Return (Alias (E));
11331 exit when From_Aspect_Specification (N);
11336 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11347 -- pragma No_Run_Time;
11349 -- Note: this pragma is retained for backwards compatibility. See
11350 -- body of Rtsfind for full details on its handling.
11352 when Pragma_No_Run_Time =>
11354 Check_Valid_Configuration_Pragma;
11355 Check_Arg_Count (0);
11357 No_Run_Time_Mode := True;
11358 Configurable_Run_Time_Mode := True;
11360 -- Set Duration to 32 bits if word size is 32
11362 if Ttypes.System_Word_Size = 32 then
11363 Duration_32_Bits_On_Target := True;
11366 -- Set appropriate restrictions
11368 Set_Restriction (No_Finalization, N);
11369 Set_Restriction (No_Exception_Handlers, N);
11370 Set_Restriction (Max_Tasks, N, 0);
11371 Set_Restriction (No_Tasking, N);
11373 ------------------------
11374 -- No_Strict_Aliasing --
11375 ------------------------
11377 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11379 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11384 Check_At_Most_N_Arguments (1);
11386 if Arg_Count = 0 then
11387 Check_Valid_Configuration_Pragma;
11388 Opt.No_Strict_Aliasing := True;
11391 Check_Optional_Identifier (Arg2, Name_Entity);
11392 Check_Arg_Is_Local_Name (Arg1);
11393 E_Id := Entity (Get_Pragma_Arg (Arg1));
11395 if E_Id = Any_Type then
11397 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11398 Error_Pragma_Arg ("pragma% requires access type", Arg1);
11401 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11403 end No_Strict_Aliasing;
11405 -----------------------
11406 -- Normalize_Scalars --
11407 -----------------------
11409 -- pragma Normalize_Scalars;
11411 when Pragma_Normalize_Scalars =>
11412 Check_Ada_83_Warning;
11413 Check_Arg_Count (0);
11414 Check_Valid_Configuration_Pragma;
11416 -- Normalize_Scalars creates false positives in CodePeer, and
11417 -- incorrect negative results in Alfa mode, so ignore this pragma
11420 if not (CodePeer_Mode or Alfa_Mode) then
11421 Normalize_Scalars := True;
11422 Init_Or_Norm_Scalars := True;
11429 -- pragma Obsolescent;
11431 -- pragma Obsolescent (
11432 -- [Message =>] static_string_EXPRESSION
11433 -- [,[Version =>] Ada_05]]);
11435 -- pragma Obsolescent (
11436 -- [Entity =>] NAME
11437 -- [,[Message =>] static_string_EXPRESSION
11438 -- [,[Version =>] Ada_05]] );
11440 when Pragma_Obsolescent => Obsolescent : declare
11444 procedure Set_Obsolescent (E : Entity_Id);
11445 -- Given an entity Ent, mark it as obsolescent if appropriate
11447 ---------------------
11448 -- Set_Obsolescent --
11449 ---------------------
11451 procedure Set_Obsolescent (E : Entity_Id) is
11460 -- Entity name was given
11462 if Present (Ename) then
11464 -- If entity name matches, we are fine. Save entity in
11465 -- pragma argument, for ASIS use.
11467 if Chars (Ename) = Chars (Ent) then
11468 Set_Entity (Ename, Ent);
11469 Generate_Reference (Ent, Ename);
11471 -- If entity name does not match, only possibility is an
11472 -- enumeration literal from an enumeration type declaration.
11474 elsif Ekind (Ent) /= E_Enumeration_Type then
11476 ("pragma % entity name does not match declaration");
11479 Ent := First_Literal (E);
11483 ("pragma % entity name does not match any " &
11484 "enumeration literal");
11486 elsif Chars (Ent) = Chars (Ename) then
11487 Set_Entity (Ename, Ent);
11488 Generate_Reference (Ent, Ename);
11492 Ent := Next_Literal (Ent);
11498 -- Ent points to entity to be marked
11500 if Arg_Count >= 1 then
11502 -- Deal with static string argument
11504 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11505 S := Strval (Get_Pragma_Arg (Arg1));
11507 for J in 1 .. String_Length (S) loop
11508 if not In_Character_Range (Get_String_Char (S, J)) then
11510 ("pragma% argument does not allow wide characters",
11515 Obsolescent_Warnings.Append
11516 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11518 -- Check for Ada_05 parameter
11520 if Arg_Count /= 1 then
11521 Check_Arg_Count (2);
11524 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11527 Check_Arg_Is_Identifier (Argx);
11529 if Chars (Argx) /= Name_Ada_05 then
11530 Error_Msg_Name_2 := Name_Ada_05;
11532 ("only allowed argument for pragma% is %", Argx);
11535 if Ada_Version_Explicit < Ada_2005
11536 or else not Warn_On_Ada_2005_Compatibility
11544 -- Set flag if pragma active
11547 Set_Is_Obsolescent (Ent);
11551 end Set_Obsolescent;
11553 -- Start of processing for pragma Obsolescent
11558 Check_At_Most_N_Arguments (3);
11560 -- See if first argument specifies an entity name
11564 (Chars (Arg1) = Name_Entity
11566 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11568 N_Operator_Symbol))
11570 Ename := Get_Pragma_Arg (Arg1);
11572 -- Eliminate first argument, so we can share processing
11576 Arg_Count := Arg_Count - 1;
11578 -- No Entity name argument given
11584 if Arg_Count >= 1 then
11585 Check_Optional_Identifier (Arg1, Name_Message);
11587 if Arg_Count = 2 then
11588 Check_Optional_Identifier (Arg2, Name_Version);
11592 -- Get immediately preceding declaration
11595 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11599 -- Cases where we do not follow anything other than another pragma
11603 -- First case: library level compilation unit declaration with
11604 -- the pragma immediately following the declaration.
11606 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11608 (Defining_Entity (Unit (Parent (Parent (N)))));
11611 -- Case 2: library unit placement for package
11615 Ent : constant Entity_Id := Find_Lib_Unit_Name;
11617 if Is_Package_Or_Generic_Package (Ent) then
11618 Set_Obsolescent (Ent);
11624 -- Cases where we must follow a declaration
11627 if Nkind (Decl) not in N_Declaration
11628 and then Nkind (Decl) not in N_Later_Decl_Item
11629 and then Nkind (Decl) not in N_Generic_Declaration
11630 and then Nkind (Decl) not in N_Renaming_Declaration
11633 ("pragma% misplaced, "
11634 & "must immediately follow a declaration");
11637 Set_Obsolescent (Defining_Entity (Decl));
11647 -- pragma Optimize (Time | Space | Off);
11649 -- The actual check for optimize is done in Gigi. Note that this
11650 -- pragma does not actually change the optimization setting, it
11651 -- simply checks that it is consistent with the pragma.
11653 when Pragma_Optimize =>
11654 Check_No_Identifiers;
11655 Check_Arg_Count (1);
11656 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11658 ------------------------
11659 -- Optimize_Alignment --
11660 ------------------------
11662 -- pragma Optimize_Alignment (Time | Space | Off);
11664 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11666 Check_No_Identifiers;
11667 Check_Arg_Count (1);
11668 Check_Valid_Configuration_Pragma;
11671 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11675 Opt.Optimize_Alignment := 'T';
11677 Opt.Optimize_Alignment := 'S';
11679 Opt.Optimize_Alignment := 'O';
11681 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11685 -- Set indication that mode is set locally. If we are in fact in a
11686 -- configuration pragma file, this setting is harmless since the
11687 -- switch will get reset anyway at the start of each unit.
11689 Optimize_Alignment_Local := True;
11690 end Optimize_Alignment;
11696 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11698 when Pragma_Ordered => Ordered : declare
11699 Assoc : constant Node_Id := Arg1;
11705 Check_No_Identifiers;
11706 Check_Arg_Count (1);
11707 Check_Arg_Is_Local_Name (Arg1);
11709 Type_Id := Get_Pragma_Arg (Assoc);
11710 Find_Type (Type_Id);
11711 Typ := Entity (Type_Id);
11713 if Typ = Any_Type then
11716 Typ := Underlying_Type (Typ);
11719 if not Is_Enumeration_Type (Typ) then
11720 Error_Pragma ("pragma% must specify enumeration type");
11723 Check_First_Subtype (Arg1);
11724 Set_Has_Pragma_Ordered (Base_Type (Typ));
11731 -- pragma Pack (first_subtype_LOCAL_NAME);
11733 when Pragma_Pack => Pack : declare
11734 Assoc : constant Node_Id := Arg1;
11738 Ignore : Boolean := False;
11741 Check_No_Identifiers;
11742 Check_Arg_Count (1);
11743 Check_Arg_Is_Local_Name (Arg1);
11745 Type_Id := Get_Pragma_Arg (Assoc);
11746 Find_Type (Type_Id);
11747 Typ := Entity (Type_Id);
11750 or else Rep_Item_Too_Early (Typ, N)
11754 Typ := Underlying_Type (Typ);
11757 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11758 Error_Pragma ("pragma% must specify array or record type");
11761 Check_First_Subtype (Arg1);
11762 Check_Duplicate_Pragma (Typ);
11766 if Is_Array_Type (Typ) then
11767 Ctyp := Component_Type (Typ);
11769 -- Ignore pack that does nothing
11771 if Known_Static_Esize (Ctyp)
11772 and then Known_Static_RM_Size (Ctyp)
11773 and then Esize (Ctyp) = RM_Size (Ctyp)
11774 and then Addressable (Esize (Ctyp))
11779 -- Process OK pragma Pack. Note that if there is a separate
11780 -- component clause present, the Pack will be cancelled. This
11781 -- processing is in Freeze.
11783 if not Rep_Item_Too_Late (Typ, N) then
11785 -- In the context of static code analysis, we do not need
11786 -- complex front-end expansions related to pragma Pack,
11787 -- so disable handling of pragma Pack in these cases.
11789 if CodePeer_Mode or Alfa_Mode then
11792 -- Don't attempt any packing for VM targets. We possibly
11793 -- could deal with some cases of array bit-packing, but we
11794 -- don't bother, since this is not a typical kind of
11795 -- representation in the VM context anyway (and would not
11796 -- for example work nicely with the debugger).
11798 elsif VM_Target /= No_VM then
11799 if not GNAT_Mode then
11801 ("?pragma% ignored in this configuration");
11804 -- Normal case where we do the pack action
11808 Set_Is_Packed (Base_Type (Typ));
11809 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11812 Set_Has_Pragma_Pack (Base_Type (Typ));
11816 -- For record types, the pack is always effective
11818 else pragma Assert (Is_Record_Type (Typ));
11819 if not Rep_Item_Too_Late (Typ, N) then
11821 -- Ignore pack request with warning in VM mode (skip warning
11822 -- if we are compiling GNAT run time library).
11824 if VM_Target /= No_VM then
11825 if not GNAT_Mode then
11827 ("?pragma% ignored in this configuration");
11830 -- Normal case of pack request active
11833 Set_Is_Packed (Base_Type (Typ));
11834 Set_Has_Pragma_Pack (Base_Type (Typ));
11835 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11847 -- There is nothing to do here, since we did all the processing for
11848 -- this pragma in Par.Prag (so that it works properly even in syntax
11851 when Pragma_Page =>
11858 -- pragma Passive [(PASSIVE_FORM)];
11860 -- PASSIVE_FORM ::= Semaphore | No
11862 when Pragma_Passive =>
11865 if Nkind (Parent (N)) /= N_Task_Definition then
11866 Error_Pragma ("pragma% must be within task definition");
11869 if Arg_Count /= 0 then
11870 Check_Arg_Count (1);
11871 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11874 ----------------------------------
11875 -- Preelaborable_Initialization --
11876 ----------------------------------
11878 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11880 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11885 Check_Arg_Count (1);
11886 Check_No_Identifiers;
11887 Check_Arg_Is_Identifier (Arg1);
11888 Check_Arg_Is_Local_Name (Arg1);
11889 Check_First_Subtype (Arg1);
11890 Ent := Entity (Get_Pragma_Arg (Arg1));
11892 if not (Is_Private_Type (Ent)
11894 Is_Protected_Type (Ent)
11896 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11899 ("pragma % can only be applied to private, formal derived or "
11900 & "protected type",
11904 -- Give an error if the pragma is applied to a protected type that
11905 -- does not qualify (due to having entries, or due to components
11906 -- that do not qualify).
11908 if Is_Protected_Type (Ent)
11909 and then not Has_Preelaborable_Initialization (Ent)
11912 ("protected type & does not have preelaborable " &
11913 "initialization", Ent);
11915 -- Otherwise mark the type as definitely having preelaborable
11919 Set_Known_To_Have_Preelab_Init (Ent);
11922 if Has_Pragma_Preelab_Init (Ent)
11923 and then Warn_On_Redundant_Constructs
11925 Error_Pragma ("?duplicate pragma%!");
11927 Set_Has_Pragma_Preelab_Init (Ent);
11931 --------------------
11932 -- Persistent_BSS --
11933 --------------------
11935 -- pragma Persistent_BSS [(object_NAME)];
11937 when Pragma_Persistent_BSS => Persistent_BSS : declare
11944 Check_At_Most_N_Arguments (1);
11946 -- Case of application to specific object (one argument)
11948 if Arg_Count = 1 then
11949 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11951 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11953 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11956 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11959 Ent := Entity (Get_Pragma_Arg (Arg1));
11960 Decl := Parent (Ent);
11962 if Rep_Item_Too_Late (Ent, N) then
11966 if Present (Expression (Decl)) then
11968 ("object for pragma% cannot have initialization", Arg1);
11971 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11973 ("object type for pragma% is not potentially persistent",
11977 Check_Duplicate_Pragma (Ent);
11980 Make_Linker_Section_Pragma
11981 (Ent, Sloc (N), ".persistent.bss");
11982 Insert_After (N, Prag);
11985 -- Case of use as configuration pragma with no arguments
11988 Check_Valid_Configuration_Pragma;
11989 Persistent_BSS_Mode := True;
11991 end Persistent_BSS;
11997 -- pragma Polling (ON | OFF);
11999 when Pragma_Polling =>
12001 Check_Arg_Count (1);
12002 Check_No_Identifiers;
12003 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12004 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
12006 -------------------
12007 -- Postcondition --
12008 -------------------
12010 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
12011 -- [,[Message =>] String_EXPRESSION]);
12013 when Pragma_Postcondition => Postcondition : declare
12015 pragma Warnings (Off, In_Body);
12019 Check_At_Least_N_Arguments (1);
12020 Check_At_Most_N_Arguments (2);
12021 Check_Optional_Identifier (Arg1, Name_Check);
12023 -- All we need to do here is call the common check procedure,
12024 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
12026 Check_Precondition_Postcondition (In_Body);
12033 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
12034 -- [,[Message =>] String_EXPRESSION]);
12036 when Pragma_Precondition => Precondition : declare
12041 Check_At_Least_N_Arguments (1);
12042 Check_At_Most_N_Arguments (2);
12043 Check_Optional_Identifier (Arg1, Name_Check);
12044 Check_Precondition_Postcondition (In_Body);
12046 -- If in spec, nothing more to do. If in body, then we convert the
12047 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
12048 -- this whether or not precondition checks are enabled. That works
12049 -- fine since pragma Check will do this check, and will also
12050 -- analyze the condition itself in the proper context.
12055 Chars => Name_Check,
12056 Pragma_Argument_Associations => New_List (
12057 Make_Pragma_Argument_Association (Loc,
12058 Expression => Make_Identifier (Loc, Name_Precondition)),
12060 Make_Pragma_Argument_Association (Sloc (Arg1),
12061 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
12063 if Arg_Count = 2 then
12064 Append_To (Pragma_Argument_Associations (N),
12065 Make_Pragma_Argument_Association (Sloc (Arg2),
12066 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
12077 -- pragma Predicate
12078 -- ([Entity =>] type_LOCAL_NAME,
12079 -- [Check =>] EXPRESSION);
12081 when Pragma_Predicate => Predicate : declare
12086 pragma Unreferenced (Discard);
12090 Check_Arg_Count (2);
12091 Check_Optional_Identifier (Arg1, Name_Entity);
12092 Check_Optional_Identifier (Arg2, Name_Check);
12094 Check_Arg_Is_Local_Name (Arg1);
12096 Type_Id := Get_Pragma_Arg (Arg1);
12097 Find_Type (Type_Id);
12098 Typ := Entity (Type_Id);
12100 if Typ = Any_Type then
12104 -- The remaining processing is simply to link the pragma on to
12105 -- the rep item chain, for processing when the type is frozen.
12106 -- This is accomplished by a call to Rep_Item_Too_Late. We also
12107 -- mark the type as having predicates.
12109 Set_Has_Predicates (Typ);
12110 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12117 -- pragma Preelaborate [(library_unit_NAME)];
12119 -- Set the flag Is_Preelaborated of program unit name entity
12121 when Pragma_Preelaborate => Preelaborate : declare
12122 Pa : constant Node_Id := Parent (N);
12123 Pk : constant Node_Kind := Nkind (Pa);
12127 Check_Ada_83_Warning;
12128 Check_Valid_Library_Unit_Pragma;
12130 if Nkind (N) = N_Null_Statement then
12134 Ent := Find_Lib_Unit_Name;
12135 Check_Duplicate_Pragma (Ent);
12137 -- This filters out pragmas inside generic parent then
12138 -- show up inside instantiation
12141 and then not (Pk = N_Package_Specification
12142 and then Present (Generic_Parent (Pa)))
12144 if not Debug_Flag_U then
12145 Set_Is_Preelaborated (Ent);
12146 Set_Suppress_Elaboration_Warnings (Ent);
12151 ---------------------
12152 -- Preelaborate_05 --
12153 ---------------------
12155 -- pragma Preelaborate_05 [(library_unit_NAME)];
12157 -- This pragma is useable only in GNAT_Mode, where it is used like
12158 -- pragma Preelaborate but it is only effective in Ada 2005 mode
12159 -- (otherwise it is ignored). This is used to implement AI-362 which
12160 -- recategorizes some run-time packages in Ada 2005 mode.
12162 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
12167 Check_Valid_Library_Unit_Pragma;
12169 if not GNAT_Mode then
12170 Error_Pragma ("pragma% only available in GNAT mode");
12173 if Nkind (N) = N_Null_Statement then
12177 -- This is one of the few cases where we need to test the value of
12178 -- Ada_Version_Explicit rather than Ada_Version (which is always
12179 -- set to Ada_2012 in a predefined unit), we need to know the
12180 -- explicit version set to know if this pragma is active.
12182 if Ada_Version_Explicit >= Ada_2005 then
12183 Ent := Find_Lib_Unit_Name;
12184 Set_Is_Preelaborated (Ent);
12185 Set_Suppress_Elaboration_Warnings (Ent);
12187 end Preelaborate_05;
12193 -- pragma Priority (EXPRESSION);
12195 when Pragma_Priority => Priority : declare
12196 P : constant Node_Id := Parent (N);
12200 Check_No_Identifiers;
12201 Check_Arg_Count (1);
12205 if Nkind (P) = N_Subprogram_Body then
12206 Check_In_Main_Program;
12208 Arg := Get_Pragma_Arg (Arg1);
12209 Analyze_And_Resolve (Arg, Standard_Integer);
12213 if not Is_Static_Expression (Arg) then
12214 Flag_Non_Static_Expr
12215 ("main subprogram priority is not static!", Arg);
12218 -- If constraint error, then we already signalled an error
12220 elsif Raises_Constraint_Error (Arg) then
12223 -- Otherwise check in range
12227 Val : constant Uint := Expr_Value (Arg);
12231 or else Val > Expr_Value (Expression
12232 (Parent (RTE (RE_Max_Priority))))
12235 ("main subprogram priority is out of range", Arg1);
12241 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12243 -- Load an arbitrary entity from System.Tasking to make sure
12244 -- this package is implicitly with'ed, since we need to have
12245 -- the tasking run-time active for the pragma Priority to have
12249 Discard : Entity_Id;
12250 pragma Warnings (Off, Discard);
12252 Discard := RTE (RE_Task_List);
12255 -- Task or Protected, must be of type Integer
12257 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12258 Arg := Get_Pragma_Arg (Arg1);
12260 -- The expression must be analyzed in the special manner
12261 -- described in "Handling of Default and Per-Object
12262 -- Expressions" in sem.ads.
12264 Preanalyze_Spec_Expression (Arg, Standard_Integer);
12266 if not Is_Static_Expression (Arg) then
12267 Check_Restriction (Static_Priorities, Arg);
12270 -- Anything else is incorrect
12276 if Has_Pragma_Priority (P) then
12277 Error_Pragma ("duplicate pragma% not allowed");
12279 Set_Has_Pragma_Priority (P, True);
12281 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12282 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12283 -- exp_ch9 should use this ???
12288 -----------------------------------
12289 -- Priority_Specific_Dispatching --
12290 -----------------------------------
12292 -- pragma Priority_Specific_Dispatching (
12293 -- policy_IDENTIFIER,
12294 -- first_priority_EXPRESSION,
12295 -- last_priority_EXPRESSION);
12297 when Pragma_Priority_Specific_Dispatching =>
12298 Priority_Specific_Dispatching : declare
12299 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12300 -- This is the entity System.Any_Priority;
12303 Lower_Bound : Node_Id;
12304 Upper_Bound : Node_Id;
12310 Check_Arg_Count (3);
12311 Check_No_Identifiers;
12312 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12313 Check_Valid_Configuration_Pragma;
12314 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12315 DP := Fold_Upper (Name_Buffer (1));
12317 Lower_Bound := Get_Pragma_Arg (Arg2);
12318 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12319 Lower_Val := Expr_Value (Lower_Bound);
12321 Upper_Bound := Get_Pragma_Arg (Arg3);
12322 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12323 Upper_Val := Expr_Value (Upper_Bound);
12325 -- It is not allowed to use Task_Dispatching_Policy and
12326 -- Priority_Specific_Dispatching in the same partition.
12328 if Task_Dispatching_Policy /= ' ' then
12329 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12331 ("pragma% incompatible with Task_Dispatching_Policy#");
12333 -- Check lower bound in range
12335 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12337 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12340 ("first_priority is out of range", Arg2);
12342 -- Check upper bound in range
12344 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12346 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12349 ("last_priority is out of range", Arg3);
12351 -- Check that the priority range is valid
12353 elsif Lower_Val > Upper_Val then
12355 ("last_priority_expression must be greater than" &
12356 " or equal to first_priority_expression");
12358 -- Store the new policy, but always preserve System_Location since
12359 -- we like the error message with the run-time name.
12362 -- Check overlapping in the priority ranges specified in other
12363 -- Priority_Specific_Dispatching pragmas within the same
12364 -- partition. We can only check those we know about!
12367 Specific_Dispatching.First .. Specific_Dispatching.Last
12369 if Specific_Dispatching.Table (J).First_Priority in
12370 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12371 or else Specific_Dispatching.Table (J).Last_Priority in
12372 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12375 Specific_Dispatching.Table (J).Pragma_Loc;
12377 ("priority range overlaps with "
12378 & "Priority_Specific_Dispatching#");
12382 -- The use of Priority_Specific_Dispatching is incompatible
12383 -- with Task_Dispatching_Policy.
12385 if Task_Dispatching_Policy /= ' ' then
12386 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12388 ("Priority_Specific_Dispatching incompatible "
12389 & "with Task_Dispatching_Policy#");
12392 -- The use of Priority_Specific_Dispatching forces ceiling
12395 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12396 Error_Msg_Sloc := Locking_Policy_Sloc;
12398 ("Priority_Specific_Dispatching incompatible "
12399 & "with Locking_Policy#");
12401 -- Set the Ceiling_Locking policy, but preserve System_Location
12402 -- since we like the error message with the run time name.
12405 Locking_Policy := 'C';
12407 if Locking_Policy_Sloc /= System_Location then
12408 Locking_Policy_Sloc := Loc;
12412 -- Add entry in the table
12414 Specific_Dispatching.Append
12415 ((Dispatching_Policy => DP,
12416 First_Priority => UI_To_Int (Lower_Val),
12417 Last_Priority => UI_To_Int (Upper_Val),
12418 Pragma_Loc => Loc));
12420 end Priority_Specific_Dispatching;
12426 -- pragma Profile (profile_IDENTIFIER);
12428 -- profile_IDENTIFIER => Restricted | Ravenscar
12430 when Pragma_Profile =>
12432 Check_Arg_Count (1);
12433 Check_Valid_Configuration_Pragma;
12434 Check_No_Identifiers;
12437 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12440 if Chars (Argx) = Name_Ravenscar then
12441 Set_Ravenscar_Profile (N);
12443 elsif Chars (Argx) = Name_Restricted then
12444 Set_Profile_Restrictions
12446 N, Warn => Treat_Restrictions_As_Warnings);
12448 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12449 Set_Profile_Restrictions
12450 (No_Implementation_Extensions,
12451 N, Warn => Treat_Restrictions_As_Warnings);
12454 Error_Pragma_Arg ("& is not a valid profile", Argx);
12458 ----------------------
12459 -- Profile_Warnings --
12460 ----------------------
12462 -- pragma Profile_Warnings (profile_IDENTIFIER);
12464 -- profile_IDENTIFIER => Restricted | Ravenscar
12466 when Pragma_Profile_Warnings =>
12468 Check_Arg_Count (1);
12469 Check_Valid_Configuration_Pragma;
12470 Check_No_Identifiers;
12473 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12476 if Chars (Argx) = Name_Ravenscar then
12477 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12479 elsif Chars (Argx) = Name_Restricted then
12480 Set_Profile_Restrictions (Restricted, N, Warn => True);
12482 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12483 Set_Profile_Restrictions
12484 (No_Implementation_Extensions, N, Warn => True);
12487 Error_Pragma_Arg ("& is not a valid profile", Argx);
12491 --------------------------
12492 -- Propagate_Exceptions --
12493 --------------------------
12495 -- pragma Propagate_Exceptions;
12497 -- Note: this pragma is obsolete and has no effect
12499 when Pragma_Propagate_Exceptions =>
12501 Check_Arg_Count (0);
12503 if In_Extended_Main_Source_Unit (N) then
12504 Propagate_Exceptions := True;
12511 -- pragma Psect_Object (
12512 -- [Internal =>] LOCAL_NAME,
12513 -- [, [External =>] EXTERNAL_SYMBOL]
12514 -- [, [Size =>] EXTERNAL_SYMBOL]);
12516 when Pragma_Psect_Object | Pragma_Common_Object =>
12517 Psect_Object : declare
12518 Args : Args_List (1 .. 3);
12519 Names : constant Name_List (1 .. 3) := (
12524 Internal : Node_Id renames Args (1);
12525 External : Node_Id renames Args (2);
12526 Size : Node_Id renames Args (3);
12528 Def_Id : Entity_Id;
12530 procedure Check_Too_Long (Arg : Node_Id);
12531 -- Posts message if the argument is an identifier with more
12532 -- than 31 characters, or a string literal with more than
12533 -- 31 characters, and we are operating under VMS
12535 --------------------
12536 -- Check_Too_Long --
12537 --------------------
12539 procedure Check_Too_Long (Arg : Node_Id) is
12540 X : constant Node_Id := Original_Node (Arg);
12543 if not Nkind_In (X, N_String_Literal, N_Identifier) then
12545 ("inappropriate argument for pragma %", Arg);
12548 if OpenVMS_On_Target then
12549 if (Nkind (X) = N_String_Literal
12550 and then String_Length (Strval (X)) > 31)
12552 (Nkind (X) = N_Identifier
12553 and then Length_Of_Name (Chars (X)) > 31)
12556 ("argument for pragma % is longer than 31 characters",
12560 end Check_Too_Long;
12562 -- Start of processing for Common_Object/Psect_Object
12566 Gather_Associations (Names, Args);
12567 Process_Extended_Import_Export_Internal_Arg (Internal);
12569 Def_Id := Entity (Internal);
12571 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12573 ("pragma% must designate an object", Internal);
12576 Check_Too_Long (Internal);
12578 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12580 ("cannot use pragma% for imported/exported object",
12584 if Is_Concurrent_Type (Etype (Internal)) then
12586 ("cannot specify pragma % for task/protected object",
12590 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12592 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12594 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12597 if Ekind (Def_Id) = E_Constant then
12599 ("cannot specify pragma % for a constant", Internal);
12602 if Is_Record_Type (Etype (Internal)) then
12608 Ent := First_Entity (Etype (Internal));
12609 while Present (Ent) loop
12610 Decl := Declaration_Node (Ent);
12612 if Ekind (Ent) = E_Component
12613 and then Nkind (Decl) = N_Component_Declaration
12614 and then Present (Expression (Decl))
12615 and then Warn_On_Export_Import
12618 ("?object for pragma % has defaults", Internal);
12628 if Present (Size) then
12629 Check_Too_Long (Size);
12632 if Present (External) then
12633 Check_Arg_Is_External_Name (External);
12634 Check_Too_Long (External);
12637 -- If all error tests pass, link pragma on to the rep item chain
12639 Record_Rep_Item (Def_Id, N);
12646 -- pragma Pure [(library_unit_NAME)];
12648 when Pragma_Pure => Pure : declare
12652 Check_Ada_83_Warning;
12653 Check_Valid_Library_Unit_Pragma;
12655 if Nkind (N) = N_Null_Statement then
12659 Ent := Find_Lib_Unit_Name;
12661 Set_Has_Pragma_Pure (Ent);
12662 Set_Suppress_Elaboration_Warnings (Ent);
12669 -- pragma Pure_05 [(library_unit_NAME)];
12671 -- This pragma is useable only in GNAT_Mode, where it is used like
12672 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
12673 -- it is ignored). It may be used after a pragma Preelaborate, in
12674 -- which case it overrides the effect of the pragma Preelaborate.
12675 -- This is used to implement AI-362 which recategorizes some run-time
12676 -- packages in Ada 2005 mode.
12678 when Pragma_Pure_05 => Pure_05 : declare
12683 Check_Valid_Library_Unit_Pragma;
12685 if not GNAT_Mode then
12686 Error_Pragma ("pragma% only available in GNAT mode");
12689 if Nkind (N) = N_Null_Statement then
12693 -- This is one of the few cases where we need to test the value of
12694 -- Ada_Version_Explicit rather than Ada_Version (which is always
12695 -- set to Ada_2012 in a predefined unit), we need to know the
12696 -- explicit version set to know if this pragma is active.
12698 if Ada_Version_Explicit >= Ada_2005 then
12699 Ent := Find_Lib_Unit_Name;
12700 Set_Is_Preelaborated (Ent, False);
12702 Set_Suppress_Elaboration_Warnings (Ent);
12710 -- pragma Pure_12 [(library_unit_NAME)];
12712 -- This pragma is useable only in GNAT_Mode, where it is used like
12713 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
12714 -- it is ignored). It may be used after a pragma Preelaborate, in
12715 -- which case it overrides the effect of the pragma Preelaborate.
12716 -- This is used to implement AI05-0212 which recategorizes some
12717 -- run-time packages in Ada 2012 mode.
12719 when Pragma_Pure_12 => Pure_12 : declare
12724 Check_Valid_Library_Unit_Pragma;
12726 if not GNAT_Mode then
12727 Error_Pragma ("pragma% only available in GNAT mode");
12730 if Nkind (N) = N_Null_Statement then
12734 -- This is one of the few cases where we need to test the value of
12735 -- Ada_Version_Explicit rather than Ada_Version (which is always
12736 -- set to Ada_2012 in a predefined unit), we need to know the
12737 -- explicit version set to know if this pragma is active.
12739 if Ada_Version_Explicit >= Ada_2012 then
12740 Ent := Find_Lib_Unit_Name;
12741 Set_Is_Preelaborated (Ent, False);
12743 Set_Suppress_Elaboration_Warnings (Ent);
12747 -------------------
12748 -- Pure_Function --
12749 -------------------
12751 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12753 when Pragma_Pure_Function => Pure_Function : declare
12756 Def_Id : Entity_Id;
12757 Effective : Boolean := False;
12761 Check_Arg_Count (1);
12762 Check_Optional_Identifier (Arg1, Name_Entity);
12763 Check_Arg_Is_Local_Name (Arg1);
12764 E_Id := Get_Pragma_Arg (Arg1);
12766 if Error_Posted (E_Id) then
12770 -- Loop through homonyms (overloadings) of referenced entity
12772 E := Entity (E_Id);
12774 if Present (E) then
12776 Def_Id := Get_Base_Subprogram (E);
12778 if not Ekind_In (Def_Id, E_Function,
12779 E_Generic_Function,
12783 ("pragma% requires a function name", Arg1);
12786 Set_Is_Pure (Def_Id);
12788 if not Has_Pragma_Pure_Function (Def_Id) then
12789 Set_Has_Pragma_Pure_Function (Def_Id);
12793 exit when From_Aspect_Specification (N);
12795 exit when No (E) or else Scope (E) /= Current_Scope;
12799 and then Warn_On_Redundant_Constructs
12802 ("pragma Pure_Function on& is redundant?",
12808 --------------------
12809 -- Queuing_Policy --
12810 --------------------
12812 -- pragma Queuing_Policy (policy_IDENTIFIER);
12814 when Pragma_Queuing_Policy => declare
12818 Check_Ada_83_Warning;
12819 Check_Arg_Count (1);
12820 Check_No_Identifiers;
12821 Check_Arg_Is_Queuing_Policy (Arg1);
12822 Check_Valid_Configuration_Pragma;
12823 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12824 QP := Fold_Upper (Name_Buffer (1));
12826 if Queuing_Policy /= ' '
12827 and then Queuing_Policy /= QP
12829 Error_Msg_Sloc := Queuing_Policy_Sloc;
12830 Error_Pragma ("queuing policy incompatible with policy#");
12832 -- Set new policy, but always preserve System_Location since we
12833 -- like the error message with the run time name.
12836 Queuing_Policy := QP;
12838 if Queuing_Policy_Sloc /= System_Location then
12839 Queuing_Policy_Sloc := Loc;
12844 -----------------------
12845 -- Relative_Deadline --
12846 -----------------------
12848 -- pragma Relative_Deadline (time_span_EXPRESSION);
12850 when Pragma_Relative_Deadline => Relative_Deadline : declare
12851 P : constant Node_Id := Parent (N);
12856 Check_No_Identifiers;
12857 Check_Arg_Count (1);
12859 Arg := Get_Pragma_Arg (Arg1);
12861 -- The expression must be analyzed in the special manner described
12862 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12864 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12868 if Nkind (P) = N_Subprogram_Body then
12869 Check_In_Main_Program;
12873 elsif Nkind (P) = N_Task_Definition then
12876 -- Anything else is incorrect
12882 if Has_Relative_Deadline_Pragma (P) then
12883 Error_Pragma ("duplicate pragma% not allowed");
12885 Set_Has_Relative_Deadline_Pragma (P, True);
12887 if Nkind (P) = N_Task_Definition then
12888 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12891 end Relative_Deadline;
12893 ------------------------
12894 -- Remote_Access_Type --
12895 ------------------------
12897 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
12899 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
12904 Check_Arg_Count (1);
12905 Check_Optional_Identifier (Arg1, Name_Entity);
12906 Check_Arg_Is_Local_Name (Arg1);
12908 E := Entity (Get_Pragma_Arg (Arg1));
12910 if Nkind (Parent (E)) = N_Formal_Type_Declaration
12911 and then Ekind (E) = E_General_Access_Type
12912 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
12913 and then Scope (Root_Type (Directly_Designated_Type (E)))
12915 and then Is_Valid_Remote_Object_Type
12916 (Root_Type (Directly_Designated_Type (E)))
12918 Set_Is_Remote_Types (E);
12922 ("pragma% applies only to formal access to classwide types",
12925 end Remote_Access_Type;
12927 ---------------------------
12928 -- Remote_Call_Interface --
12929 ---------------------------
12931 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12933 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12934 Cunit_Node : Node_Id;
12935 Cunit_Ent : Entity_Id;
12939 Check_Ada_83_Warning;
12940 Check_Valid_Library_Unit_Pragma;
12942 if Nkind (N) = N_Null_Statement then
12946 Cunit_Node := Cunit (Current_Sem_Unit);
12947 K := Nkind (Unit (Cunit_Node));
12948 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12950 if K = N_Package_Declaration
12951 or else K = N_Generic_Package_Declaration
12952 or else K = N_Subprogram_Declaration
12953 or else K = N_Generic_Subprogram_Declaration
12954 or else (K = N_Subprogram_Body
12955 and then Acts_As_Spec (Unit (Cunit_Node)))
12960 "pragma% must apply to package or subprogram declaration");
12963 Set_Is_Remote_Call_Interface (Cunit_Ent);
12964 end Remote_Call_Interface;
12970 -- pragma Remote_Types [(library_unit_NAME)];
12972 when Pragma_Remote_Types => Remote_Types : declare
12973 Cunit_Node : Node_Id;
12974 Cunit_Ent : Entity_Id;
12977 Check_Ada_83_Warning;
12978 Check_Valid_Library_Unit_Pragma;
12980 if Nkind (N) = N_Null_Statement then
12984 Cunit_Node := Cunit (Current_Sem_Unit);
12985 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12987 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12988 N_Generic_Package_Declaration)
12991 ("pragma% can only apply to a package declaration");
12994 Set_Is_Remote_Types (Cunit_Ent);
13001 -- pragma Ravenscar;
13003 when Pragma_Ravenscar =>
13005 Check_Arg_Count (0);
13006 Check_Valid_Configuration_Pragma;
13007 Set_Ravenscar_Profile (N);
13009 if Warn_On_Obsolescent_Feature then
13010 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
13011 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
13014 -------------------------
13015 -- Restricted_Run_Time --
13016 -------------------------
13018 -- pragma Restricted_Run_Time;
13020 when Pragma_Restricted_Run_Time =>
13022 Check_Arg_Count (0);
13023 Check_Valid_Configuration_Pragma;
13024 Set_Profile_Restrictions
13025 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
13027 if Warn_On_Obsolescent_Feature then
13029 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
13030 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
13037 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
13040 -- restriction_IDENTIFIER
13041 -- | restriction_parameter_IDENTIFIER => EXPRESSION
13043 when Pragma_Restrictions =>
13044 Process_Restrictions_Or_Restriction_Warnings
13045 (Warn => Treat_Restrictions_As_Warnings);
13047 --------------------------
13048 -- Restriction_Warnings --
13049 --------------------------
13051 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
13054 -- restriction_IDENTIFIER
13055 -- | restriction_parameter_IDENTIFIER => EXPRESSION
13057 when Pragma_Restriction_Warnings =>
13059 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
13065 -- pragma Reviewable;
13067 when Pragma_Reviewable =>
13068 Check_Ada_83_Warning;
13069 Check_Arg_Count (0);
13071 -- Call dummy debugging function rv. This is done to assist front
13072 -- end debugging. By placing a Reviewable pragma in the source
13073 -- program, a breakpoint on rv catches this place in the source,
13074 -- allowing convenient stepping to the point of interest.
13078 --------------------------
13079 -- Short_Circuit_And_Or --
13080 --------------------------
13082 when Pragma_Short_Circuit_And_Or =>
13084 Check_Arg_Count (0);
13085 Check_Valid_Configuration_Pragma;
13086 Short_Circuit_And_Or := True;
13088 -------------------
13089 -- Share_Generic --
13090 -------------------
13092 -- pragma Share_Generic (NAME {, NAME});
13094 when Pragma_Share_Generic =>
13096 Process_Generic_List;
13102 -- pragma Shared (LOCAL_NAME);
13104 when Pragma_Shared =>
13106 Process_Atomic_Shared_Volatile;
13108 --------------------
13109 -- Shared_Passive --
13110 --------------------
13112 -- pragma Shared_Passive [(library_unit_NAME)];
13114 -- Set the flag Is_Shared_Passive of program unit name entity
13116 when Pragma_Shared_Passive => Shared_Passive : declare
13117 Cunit_Node : Node_Id;
13118 Cunit_Ent : Entity_Id;
13121 Check_Ada_83_Warning;
13122 Check_Valid_Library_Unit_Pragma;
13124 if Nkind (N) = N_Null_Statement then
13128 Cunit_Node := Cunit (Current_Sem_Unit);
13129 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13131 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13132 N_Generic_Package_Declaration)
13135 ("pragma% can only apply to a package declaration");
13138 Set_Is_Shared_Passive (Cunit_Ent);
13139 end Shared_Passive;
13141 -----------------------
13142 -- Short_Descriptors --
13143 -----------------------
13145 -- pragma Short_Descriptors;
13147 when Pragma_Short_Descriptors =>
13149 Check_Arg_Count (0);
13150 Check_Valid_Configuration_Pragma;
13151 Short_Descriptors := True;
13153 ----------------------
13154 -- Source_File_Name --
13155 ----------------------
13157 -- There are five forms for this pragma:
13159 -- pragma Source_File_Name (
13160 -- [UNIT_NAME =>] unit_NAME,
13161 -- BODY_FILE_NAME => STRING_LITERAL
13162 -- [, [INDEX =>] INTEGER_LITERAL]);
13164 -- pragma Source_File_Name (
13165 -- [UNIT_NAME =>] unit_NAME,
13166 -- SPEC_FILE_NAME => STRING_LITERAL
13167 -- [, [INDEX =>] INTEGER_LITERAL]);
13169 -- pragma Source_File_Name (
13170 -- BODY_FILE_NAME => STRING_LITERAL
13171 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13172 -- [, CASING => CASING_SPEC]);
13174 -- pragma Source_File_Name (
13175 -- SPEC_FILE_NAME => STRING_LITERAL
13176 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13177 -- [, CASING => CASING_SPEC]);
13179 -- pragma Source_File_Name (
13180 -- SUBUNIT_FILE_NAME => STRING_LITERAL
13181 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13182 -- [, CASING => CASING_SPEC]);
13184 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
13186 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
13187 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
13188 -- only be used when no project file is used, while SFNP can only be
13189 -- used when a project file is used.
13191 -- No processing here. Processing was completed during parsing, since
13192 -- we need to have file names set as early as possible. Units are
13193 -- loaded well before semantic processing starts.
13195 -- The only processing we defer to this point is the check for
13196 -- correct placement.
13198 when Pragma_Source_File_Name =>
13200 Check_Valid_Configuration_Pragma;
13202 ------------------------------
13203 -- Source_File_Name_Project --
13204 ------------------------------
13206 -- See Source_File_Name for syntax
13208 -- No processing here. Processing was completed during parsing, since
13209 -- we need to have file names set as early as possible. Units are
13210 -- loaded well before semantic processing starts.
13212 -- The only processing we defer to this point is the check for
13213 -- correct placement.
13215 when Pragma_Source_File_Name_Project =>
13217 Check_Valid_Configuration_Pragma;
13219 -- Check that a pragma Source_File_Name_Project is used only in a
13220 -- configuration pragmas file.
13222 -- Pragmas Source_File_Name_Project should only be generated by
13223 -- the Project Manager in configuration pragmas files.
13225 -- This is really an ugly test. It seems to depend on some
13226 -- accidental and undocumented property. At the very least it
13227 -- needs to be documented, but it would be better to have a
13228 -- clean way of testing if we are in a configuration file???
13230 if Present (Parent (N)) then
13232 ("pragma% can only appear in a configuration pragmas file");
13235 ----------------------
13236 -- Source_Reference --
13237 ----------------------
13239 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
13241 -- Nothing to do, all processing completed in Par.Prag, since we need
13242 -- the information for possible parser messages that are output.
13244 when Pragma_Source_Reference =>
13247 --------------------------------
13248 -- Static_Elaboration_Desired --
13249 --------------------------------
13251 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
13253 when Pragma_Static_Elaboration_Desired =>
13255 Check_At_Most_N_Arguments (1);
13257 if Is_Compilation_Unit (Current_Scope)
13258 and then Ekind (Current_Scope) = E_Package
13260 Set_Static_Elaboration_Desired (Current_Scope, True);
13262 Error_Pragma ("pragma% must apply to a library-level package");
13269 -- pragma Storage_Size (EXPRESSION);
13271 when Pragma_Storage_Size => Storage_Size : declare
13272 P : constant Node_Id := Parent (N);
13276 Check_No_Identifiers;
13277 Check_Arg_Count (1);
13279 -- The expression must be analyzed in the special manner described
13280 -- in "Handling of Default Expressions" in sem.ads.
13282 Arg := Get_Pragma_Arg (Arg1);
13283 Preanalyze_Spec_Expression (Arg, Any_Integer);
13285 if not Is_Static_Expression (Arg) then
13286 Check_Restriction (Static_Storage_Size, Arg);
13289 if Nkind (P) /= N_Task_Definition then
13294 if Has_Storage_Size_Pragma (P) then
13295 Error_Pragma ("duplicate pragma% not allowed");
13297 Set_Has_Storage_Size_Pragma (P, True);
13300 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13301 -- ??? exp_ch9 should use this!
13309 -- pragma Storage_Unit (NUMERIC_LITERAL);
13311 -- Only permitted argument is System'Storage_Unit value
13313 when Pragma_Storage_Unit =>
13314 Check_No_Identifiers;
13315 Check_Arg_Count (1);
13316 Check_Arg_Is_Integer_Literal (Arg1);
13318 if Intval (Get_Pragma_Arg (Arg1)) /=
13319 UI_From_Int (Ttypes.System_Storage_Unit)
13321 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
13323 ("the only allowed argument for pragma% is ^", Arg1);
13326 --------------------
13327 -- Stream_Convert --
13328 --------------------
13330 -- pragma Stream_Convert (
13331 -- [Entity =>] type_LOCAL_NAME,
13332 -- [Read =>] function_NAME,
13333 -- [Write =>] function NAME);
13335 when Pragma_Stream_Convert => Stream_Convert : declare
13337 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
13338 -- Check that the given argument is the name of a local function
13339 -- of one argument that is not overloaded earlier in the current
13340 -- local scope. A check is also made that the argument is a
13341 -- function with one parameter.
13343 --------------------------------------
13344 -- Check_OK_Stream_Convert_Function --
13345 --------------------------------------
13347 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
13351 Check_Arg_Is_Local_Name (Arg);
13352 Ent := Entity (Get_Pragma_Arg (Arg));
13354 if Has_Homonym (Ent) then
13356 ("argument for pragma% may not be overloaded", Arg);
13359 if Ekind (Ent) /= E_Function
13360 or else No (First_Formal (Ent))
13361 or else Present (Next_Formal (First_Formal (Ent)))
13364 ("argument for pragma% must be" &
13365 " function of one argument", Arg);
13367 end Check_OK_Stream_Convert_Function;
13369 -- Start of processing for Stream_Convert
13373 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
13374 Check_Arg_Count (3);
13375 Check_Optional_Identifier (Arg1, Name_Entity);
13376 Check_Optional_Identifier (Arg2, Name_Read);
13377 Check_Optional_Identifier (Arg3, Name_Write);
13378 Check_Arg_Is_Local_Name (Arg1);
13379 Check_OK_Stream_Convert_Function (Arg2);
13380 Check_OK_Stream_Convert_Function (Arg3);
13383 Typ : constant Entity_Id :=
13384 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13385 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13386 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
13389 Check_First_Subtype (Arg1);
13391 -- Check for too early or too late. Note that we don't enforce
13392 -- the rule about primitive operations in this case, since, as
13393 -- is the case for explicit stream attributes themselves, these
13394 -- restrictions are not appropriate. Note that the chaining of
13395 -- the pragma by Rep_Item_Too_Late is actually the critical
13396 -- processing done for this pragma.
13398 if Rep_Item_Too_Early (Typ, N)
13400 Rep_Item_Too_Late (Typ, N, FOnly => True)
13405 -- Return if previous error
13407 if Etype (Typ) = Any_Type
13409 Etype (Read) = Any_Type
13411 Etype (Write) = Any_Type
13418 if Underlying_Type (Etype (Read)) /= Typ then
13420 ("incorrect return type for function&", Arg2);
13423 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13425 ("incorrect parameter type for function&", Arg3);
13428 if Underlying_Type (Etype (First_Formal (Read))) /=
13429 Underlying_Type (Etype (Write))
13432 ("result type of & does not match Read parameter type",
13436 end Stream_Convert;
13438 -------------------------
13439 -- Style_Checks (GNAT) --
13440 -------------------------
13442 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13444 -- This is processed by the parser since some of the style checks
13445 -- take place during source scanning and parsing. This means that
13446 -- we don't need to issue error messages here.
13448 when Pragma_Style_Checks => Style_Checks : declare
13449 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13455 Check_No_Identifiers;
13457 -- Two argument form
13459 if Arg_Count = 2 then
13460 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13467 E_Id := Get_Pragma_Arg (Arg2);
13470 if not Is_Entity_Name (E_Id) then
13472 ("second argument of pragma% must be entity name",
13476 E := Entity (E_Id);
13482 Set_Suppress_Style_Checks (E,
13483 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
13484 exit when No (Homonym (E));
13490 -- One argument form
13493 Check_Arg_Count (1);
13495 if Nkind (A) = N_String_Literal then
13499 Slen : constant Natural := Natural (String_Length (S));
13500 Options : String (1 .. Slen);
13506 C := Get_String_Char (S, Int (J));
13507 exit when not In_Character_Range (C);
13508 Options (J) := Get_Character (C);
13510 -- If at end of string, set options. As per discussion
13511 -- above, no need to check for errors, since we issued
13512 -- them in the parser.
13515 Set_Style_Check_Options (Options);
13523 elsif Nkind (A) = N_Identifier then
13524 if Chars (A) = Name_All_Checks then
13526 Set_GNAT_Style_Check_Options;
13528 Set_Default_Style_Check_Options;
13531 elsif Chars (A) = Name_On then
13532 Style_Check := True;
13534 elsif Chars (A) = Name_Off then
13535 Style_Check := False;
13545 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13547 when Pragma_Subtitle =>
13549 Check_Arg_Count (1);
13550 Check_Optional_Identifier (Arg1, Name_Subtitle);
13551 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13558 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13560 when Pragma_Suppress =>
13561 Process_Suppress_Unsuppress (True);
13567 -- pragma Suppress_All;
13569 -- The only check made here is that the pragma has no arguments.
13570 -- There are no placement rules, and the processing required (setting
13571 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
13572 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
13573 -- then creates and inserts a pragma Suppress (All_Checks).
13575 when Pragma_Suppress_All =>
13577 Check_Arg_Count (0);
13579 -------------------------
13580 -- Suppress_Debug_Info --
13581 -------------------------
13583 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13585 when Pragma_Suppress_Debug_Info =>
13587 Check_Arg_Count (1);
13588 Check_Optional_Identifier (Arg1, Name_Entity);
13589 Check_Arg_Is_Local_Name (Arg1);
13590 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13592 ----------------------------------
13593 -- Suppress_Exception_Locations --
13594 ----------------------------------
13596 -- pragma Suppress_Exception_Locations;
13598 when Pragma_Suppress_Exception_Locations =>
13600 Check_Arg_Count (0);
13601 Check_Valid_Configuration_Pragma;
13602 Exception_Locations_Suppressed := True;
13604 -----------------------------
13605 -- Suppress_Initialization --
13606 -----------------------------
13608 -- pragma Suppress_Initialization ([Entity =>] type_Name);
13610 when Pragma_Suppress_Initialization => Suppress_Init : declare
13616 Check_Arg_Count (1);
13617 Check_Optional_Identifier (Arg1, Name_Entity);
13618 Check_Arg_Is_Local_Name (Arg1);
13620 E_Id := Get_Pragma_Arg (Arg1);
13622 if Etype (E_Id) = Any_Type then
13626 E := Entity (E_Id);
13628 if not Is_Type (E) then
13629 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13632 if Rep_Item_Too_Early (E, N)
13634 Rep_Item_Too_Late (E, N, FOnly => True)
13639 -- For incomplete/private type, set flag on full view
13641 if Is_Incomplete_Or_Private_Type (E) then
13642 if No (Full_View (Base_Type (E))) then
13644 ("argument of pragma% cannot be an incomplete type", Arg1);
13646 Set_Suppress_Initialization (Full_View (Base_Type (E)));
13649 -- For first subtype, set flag on base type
13651 elsif Is_First_Subtype (E) then
13652 Set_Suppress_Initialization (Base_Type (E));
13654 -- For other than first subtype, set flag on subtype itself
13657 Set_Suppress_Initialization (E);
13665 -- pragma System_Name (DIRECT_NAME);
13667 -- Syntax check: one argument, which must be the identifier GNAT or
13668 -- the identifier GCC, no other identifiers are acceptable.
13670 when Pragma_System_Name =>
13672 Check_No_Identifiers;
13673 Check_Arg_Count (1);
13674 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13676 -----------------------------
13677 -- Task_Dispatching_Policy --
13678 -----------------------------
13680 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13682 when Pragma_Task_Dispatching_Policy => declare
13686 Check_Ada_83_Warning;
13687 Check_Arg_Count (1);
13688 Check_No_Identifiers;
13689 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13690 Check_Valid_Configuration_Pragma;
13691 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13692 DP := Fold_Upper (Name_Buffer (1));
13694 if Task_Dispatching_Policy /= ' '
13695 and then Task_Dispatching_Policy /= DP
13697 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13699 ("task dispatching policy incompatible with policy#");
13701 -- Set new policy, but always preserve System_Location since we
13702 -- like the error message with the run time name.
13705 Task_Dispatching_Policy := DP;
13707 if Task_Dispatching_Policy_Sloc /= System_Location then
13708 Task_Dispatching_Policy_Sloc := Loc;
13717 -- pragma Task_Info (EXPRESSION);
13719 when Pragma_Task_Info => Task_Info : declare
13720 P : constant Node_Id := Parent (N);
13725 if Nkind (P) /= N_Task_Definition then
13726 Error_Pragma ("pragma% must appear in task definition");
13729 Check_No_Identifiers;
13730 Check_Arg_Count (1);
13732 Analyze_And_Resolve
13733 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13735 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13739 if Has_Task_Info_Pragma (P) then
13740 Error_Pragma ("duplicate pragma% not allowed");
13742 Set_Has_Task_Info_Pragma (P, True);
13750 -- pragma Task_Name (string_EXPRESSION);
13752 when Pragma_Task_Name => Task_Name : declare
13753 P : constant Node_Id := Parent (N);
13757 Check_No_Identifiers;
13758 Check_Arg_Count (1);
13760 Arg := Get_Pragma_Arg (Arg1);
13762 -- The expression is used in the call to Create_Task, and must be
13763 -- expanded there, not in the context of the current spec. It must
13764 -- however be analyzed to capture global references, in case it
13765 -- appears in a generic context.
13767 Preanalyze_And_Resolve (Arg, Standard_String);
13769 if Nkind (P) /= N_Task_Definition then
13773 if Has_Task_Name_Pragma (P) then
13774 Error_Pragma ("duplicate pragma% not allowed");
13776 Set_Has_Task_Name_Pragma (P, True);
13777 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13785 -- pragma Task_Storage (
13786 -- [Task_Type =>] LOCAL_NAME,
13787 -- [Top_Guard =>] static_integer_EXPRESSION);
13789 when Pragma_Task_Storage => Task_Storage : declare
13790 Args : Args_List (1 .. 2);
13791 Names : constant Name_List (1 .. 2) := (
13795 Task_Type : Node_Id renames Args (1);
13796 Top_Guard : Node_Id renames Args (2);
13802 Gather_Associations (Names, Args);
13804 if No (Task_Type) then
13806 ("missing task_type argument for pragma%");
13809 Check_Arg_Is_Local_Name (Task_Type);
13811 Ent := Entity (Task_Type);
13813 if not Is_Task_Type (Ent) then
13815 ("argument for pragma% must be task type", Task_Type);
13818 if No (Top_Guard) then
13820 ("pragma% takes two arguments", Task_Type);
13822 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13825 Check_First_Subtype (Task_Type);
13827 if Rep_Item_Too_Late (Ent, N) then
13836 -- pragma Test_Case ([Name =>] Static_String_EXPRESSION
13837 -- ,[Mode =>] MODE_TYPE
13838 -- [, Requires => Boolean_EXPRESSION]
13839 -- [, Ensures => Boolean_EXPRESSION]);
13841 -- MODE_TYPE ::= Nominal | Robustness
13843 when Pragma_Test_Case => Test_Case : declare
13846 Check_At_Least_N_Arguments (2);
13847 Check_At_Most_N_Arguments (4);
13849 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13851 Check_Optional_Identifier (Arg1, Name_Name);
13852 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13854 -- In ASIS mode, for a pragma generated from a source aspect, also
13855 -- analyze the original aspect expression.
13858 and then Present (Corresponding_Aspect (N))
13860 Check_Expr_Is_Static_Expression
13861 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
13864 Check_Optional_Identifier (Arg2, Name_Mode);
13865 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13867 if Arg_Count = 4 then
13868 Check_Identifier (Arg3, Name_Requires);
13869 Check_Identifier (Arg4, Name_Ensures);
13871 elsif Arg_Count = 3 then
13872 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13878 --------------------------
13879 -- Thread_Local_Storage --
13880 --------------------------
13882 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13884 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13890 Check_Arg_Count (1);
13891 Check_Optional_Identifier (Arg1, Name_Entity);
13892 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13894 Id := Get_Pragma_Arg (Arg1);
13897 if not Is_Entity_Name (Id)
13898 or else Ekind (Entity (Id)) /= E_Variable
13900 Error_Pragma_Arg ("local variable name required", Arg1);
13905 if Rep_Item_Too_Early (E, N)
13906 or else Rep_Item_Too_Late (E, N)
13911 Set_Has_Pragma_Thread_Local_Storage (E);
13912 Set_Has_Gigi_Rep_Item (E);
13913 end Thread_Local_Storage;
13919 -- pragma Time_Slice (static_duration_EXPRESSION);
13921 when Pragma_Time_Slice => Time_Slice : declare
13927 Check_Arg_Count (1);
13928 Check_No_Identifiers;
13929 Check_In_Main_Program;
13930 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13932 if not Error_Posted (Arg1) then
13934 while Present (Nod) loop
13935 if Nkind (Nod) = N_Pragma
13936 and then Pragma_Name (Nod) = Name_Time_Slice
13938 Error_Msg_Name_1 := Pname;
13939 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13946 -- Process only if in main unit
13948 if Get_Source_Unit (Loc) = Main_Unit then
13949 Opt.Time_Slice_Set := True;
13950 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13952 if Val <= Ureal_0 then
13953 Opt.Time_Slice_Value := 0;
13955 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13956 Opt.Time_Slice_Value := 1_000_000_000;
13959 Opt.Time_Slice_Value :=
13960 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13969 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13971 -- TITLING_OPTION ::=
13972 -- [Title =>] STRING_LITERAL
13973 -- | [Subtitle =>] STRING_LITERAL
13975 when Pragma_Title => Title : declare
13976 Args : Args_List (1 .. 2);
13977 Names : constant Name_List (1 .. 2) := (
13983 Gather_Associations (Names, Args);
13986 for J in 1 .. 2 loop
13987 if Present (Args (J)) then
13988 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13993 ---------------------
13994 -- Unchecked_Union --
13995 ---------------------
13997 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13999 when Pragma_Unchecked_Union => Unchecked_Union : declare
14000 Assoc : constant Node_Id := Arg1;
14001 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
14012 Check_No_Identifiers;
14013 Check_Arg_Count (1);
14014 Check_Arg_Is_Local_Name (Arg1);
14016 Find_Type (Type_Id);
14017 Typ := Entity (Type_Id);
14020 or else Rep_Item_Too_Early (Typ, N)
14024 Typ := Underlying_Type (Typ);
14027 if Rep_Item_Too_Late (Typ, N) then
14031 Check_First_Subtype (Arg1);
14033 -- Note remaining cases are references to a type in the current
14034 -- declarative part. If we find an error, we post the error on
14035 -- the relevant type declaration at an appropriate point.
14037 if not Is_Record_Type (Typ) then
14038 Error_Msg_N ("Unchecked_Union must be record type", Typ);
14041 elsif Is_Tagged_Type (Typ) then
14042 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
14045 elsif not Has_Discriminants (Typ) then
14047 ("Unchecked_Union must have one discriminant", Typ);
14050 -- Note: in previous versions of GNAT we used to check for limited
14051 -- types and give an error, but in fact the standard does allow
14052 -- Unchecked_Union on limited types, so this check was removed.
14054 -- Proceed with basic error checks completed
14057 Discr := First_Discriminant (Typ);
14058 while Present (Discr) loop
14059 if No (Discriminant_Default_Value (Discr)) then
14061 ("Unchecked_Union discriminant must have default value",
14065 Next_Discriminant (Discr);
14068 Tdef := Type_Definition (Declaration_Node (Typ));
14069 Clist := Component_List (Tdef);
14071 Comp := First (Component_Items (Clist));
14072 while Present (Comp) loop
14073 Check_Component (Comp, Typ);
14077 if No (Clist) or else No (Variant_Part (Clist)) then
14079 ("Unchecked_Union must have variant part",
14084 Vpart := Variant_Part (Clist);
14086 Variant := First (Variants (Vpart));
14087 while Present (Variant) loop
14088 Check_Variant (Variant, Typ);
14093 Set_Is_Unchecked_Union (Typ);
14094 Set_Convention (Typ, Convention_C);
14095 Set_Has_Unchecked_Union (Base_Type (Typ));
14096 Set_Is_Unchecked_Union (Base_Type (Typ));
14097 end Unchecked_Union;
14099 ------------------------
14100 -- Unimplemented_Unit --
14101 ------------------------
14103 -- pragma Unimplemented_Unit;
14105 -- Note: this only gives an error if we are generating code, or if
14106 -- we are in a generic library unit (where the pragma appears in the
14107 -- body, not in the spec).
14109 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
14110 Cunitent : constant Entity_Id :=
14111 Cunit_Entity (Get_Source_Unit (Loc));
14112 Ent_Kind : constant Entity_Kind :=
14117 Check_Arg_Count (0);
14119 if Operating_Mode = Generate_Code
14120 or else Ent_Kind = E_Generic_Function
14121 or else Ent_Kind = E_Generic_Procedure
14122 or else Ent_Kind = E_Generic_Package
14124 Get_Name_String (Chars (Cunitent));
14125 Set_Casing (Mixed_Case);
14126 Write_Str (Name_Buffer (1 .. Name_Len));
14127 Write_Str (" is not supported in this configuration");
14129 raise Unrecoverable_Error;
14131 end Unimplemented_Unit;
14133 ------------------------
14134 -- Universal_Aliasing --
14135 ------------------------
14137 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
14139 when Pragma_Universal_Aliasing => Universal_Alias : declare
14144 Check_Arg_Count (1);
14145 Check_Optional_Identifier (Arg2, Name_Entity);
14146 Check_Arg_Is_Local_Name (Arg1);
14147 E_Id := Entity (Get_Pragma_Arg (Arg1));
14149 if E_Id = Any_Type then
14151 elsif No (E_Id) or else not Is_Type (E_Id) then
14152 Error_Pragma_Arg ("pragma% requires type", Arg1);
14155 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
14156 end Universal_Alias;
14158 --------------------
14159 -- Universal_Data --
14160 --------------------
14162 -- pragma Universal_Data [(library_unit_NAME)];
14164 when Pragma_Universal_Data =>
14167 -- If this is a configuration pragma, then set the universal
14168 -- addressing option, otherwise confirm that the pragma satisfies
14169 -- the requirements of library unit pragma placement and leave it
14170 -- to the GNAAMP back end to detect the pragma (avoids transitive
14171 -- setting of the option due to withed units).
14173 if Is_Configuration_Pragma then
14174 Universal_Addressing_On_AAMP := True;
14176 Check_Valid_Library_Unit_Pragma;
14179 if not AAMP_On_Target then
14180 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
14187 -- pragma Unmodified (local_Name {, local_Name});
14189 when Pragma_Unmodified => Unmodified : declare
14190 Arg_Node : Node_Id;
14191 Arg_Expr : Node_Id;
14192 Arg_Ent : Entity_Id;
14196 Check_At_Least_N_Arguments (1);
14198 -- Loop through arguments
14201 while Present (Arg_Node) loop
14202 Check_No_Identifier (Arg_Node);
14204 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
14205 -- in fact generate reference, so that the entity will have a
14206 -- reference, which will inhibit any warnings about it not
14207 -- being referenced, and also properly show up in the ali file
14208 -- as a reference. But this reference is recorded before the
14209 -- Has_Pragma_Unreferenced flag is set, so that no warning is
14210 -- generated for this reference.
14212 Check_Arg_Is_Local_Name (Arg_Node);
14213 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14215 if Is_Entity_Name (Arg_Expr) then
14216 Arg_Ent := Entity (Arg_Expr);
14218 if not Is_Assignable (Arg_Ent) then
14220 ("pragma% can only be applied to a variable",
14223 Set_Has_Pragma_Unmodified (Arg_Ent);
14235 -- pragma Unreferenced (local_Name {, local_Name});
14237 -- or when used in a context clause:
14239 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
14241 when Pragma_Unreferenced => Unreferenced : declare
14242 Arg_Node : Node_Id;
14243 Arg_Expr : Node_Id;
14244 Arg_Ent : Entity_Id;
14249 Check_At_Least_N_Arguments (1);
14251 -- Check case of appearing within context clause
14253 if Is_In_Context_Clause then
14255 -- The arguments must all be units mentioned in a with clause
14256 -- in the same context clause. Note we already checked (in
14257 -- Par.Prag) that the arguments are either identifiers or
14258 -- selected components.
14261 while Present (Arg_Node) loop
14262 Citem := First (List_Containing (N));
14263 while Citem /= N loop
14264 if Nkind (Citem) = N_With_Clause
14266 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
14268 Set_Has_Pragma_Unreferenced
14271 (Library_Unit (Citem))));
14273 (Get_Pragma_Arg (Arg_Node), Name (Citem));
14282 ("argument of pragma% is not withed unit", Arg_Node);
14288 -- Case of not in list of context items
14292 while Present (Arg_Node) loop
14293 Check_No_Identifier (Arg_Node);
14295 -- Note: the analyze call done by Check_Arg_Is_Local_Name
14296 -- will in fact generate reference, so that the entity will
14297 -- have a reference, which will inhibit any warnings about
14298 -- it not being referenced, and also properly show up in the
14299 -- ali file as a reference. But this reference is recorded
14300 -- before the Has_Pragma_Unreferenced flag is set, so that
14301 -- no warning is generated for this reference.
14303 Check_Arg_Is_Local_Name (Arg_Node);
14304 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14306 if Is_Entity_Name (Arg_Expr) then
14307 Arg_Ent := Entity (Arg_Expr);
14309 -- If the entity is overloaded, the pragma applies to the
14310 -- most recent overloading, as documented. In this case,
14311 -- name resolution does not generate a reference, so it
14312 -- must be done here explicitly.
14314 if Is_Overloaded (Arg_Expr) then
14315 Generate_Reference (Arg_Ent, N);
14318 Set_Has_Pragma_Unreferenced (Arg_Ent);
14326 --------------------------
14327 -- Unreferenced_Objects --
14328 --------------------------
14330 -- pragma Unreferenced_Objects (local_Name {, local_Name});
14332 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
14333 Arg_Node : Node_Id;
14334 Arg_Expr : Node_Id;
14338 Check_At_Least_N_Arguments (1);
14341 while Present (Arg_Node) loop
14342 Check_No_Identifier (Arg_Node);
14343 Check_Arg_Is_Local_Name (Arg_Node);
14344 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14346 if not Is_Entity_Name (Arg_Expr)
14347 or else not Is_Type (Entity (Arg_Expr))
14350 ("argument for pragma% must be type or subtype", Arg_Node);
14353 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
14356 end Unreferenced_Objects;
14358 ------------------------------
14359 -- Unreserve_All_Interrupts --
14360 ------------------------------
14362 -- pragma Unreserve_All_Interrupts;
14364 when Pragma_Unreserve_All_Interrupts =>
14366 Check_Arg_Count (0);
14368 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
14369 Unreserve_All_Interrupts := True;
14376 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
14378 when Pragma_Unsuppress =>
14380 Process_Suppress_Unsuppress (False);
14382 -------------------
14383 -- Use_VADS_Size --
14384 -------------------
14386 -- pragma Use_VADS_Size;
14388 when Pragma_Use_VADS_Size =>
14390 Check_Arg_Count (0);
14391 Check_Valid_Configuration_Pragma;
14392 Use_VADS_Size := True;
14394 ---------------------
14395 -- Validity_Checks --
14396 ---------------------
14398 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14400 when Pragma_Validity_Checks => Validity_Checks : declare
14401 A : constant Node_Id := Get_Pragma_Arg (Arg1);
14407 Check_Arg_Count (1);
14408 Check_No_Identifiers;
14410 if Nkind (A) = N_String_Literal then
14414 Slen : constant Natural := Natural (String_Length (S));
14415 Options : String (1 .. Slen);
14421 C := Get_String_Char (S, Int (J));
14422 exit when not In_Character_Range (C);
14423 Options (J) := Get_Character (C);
14426 Set_Validity_Check_Options (Options);
14434 elsif Nkind (A) = N_Identifier then
14435 if Chars (A) = Name_All_Checks then
14436 Set_Validity_Check_Options ("a");
14437 elsif Chars (A) = Name_On then
14438 Validity_Checks_On := True;
14439 elsif Chars (A) = Name_Off then
14440 Validity_Checks_On := False;
14443 end Validity_Checks;
14449 -- pragma Volatile (LOCAL_NAME);
14451 when Pragma_Volatile =>
14452 Process_Atomic_Shared_Volatile;
14454 -------------------------
14455 -- Volatile_Components --
14456 -------------------------
14458 -- pragma Volatile_Components (array_LOCAL_NAME);
14460 -- Volatile is handled by the same circuit as Atomic_Components
14466 -- pragma Warnings (On | Off);
14467 -- pragma Warnings (On | Off, LOCAL_NAME);
14468 -- pragma Warnings (static_string_EXPRESSION);
14469 -- pragma Warnings (On | Off, STRING_LITERAL);
14471 when Pragma_Warnings => Warnings : begin
14473 Check_At_Least_N_Arguments (1);
14474 Check_No_Identifiers;
14476 -- If debug flag -gnatd.i is set, pragma is ignored
14478 if Debug_Flag_Dot_I then
14482 -- Process various forms of the pragma
14485 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14488 -- One argument case
14490 if Arg_Count = 1 then
14492 -- On/Off one argument case was processed by parser
14494 if Nkind (Argx) = N_Identifier
14496 (Chars (Argx) = Name_On
14498 Chars (Argx) = Name_Off)
14502 -- One argument case must be ON/OFF or static string expr
14504 elsif not Is_Static_String_Expression (Arg1) then
14506 ("argument of pragma% must be On/Off or " &
14507 "static string expression", Arg1);
14509 -- One argument string expression case
14513 Lit : constant Node_Id := Expr_Value_S (Argx);
14514 Str : constant String_Id := Strval (Lit);
14515 Len : constant Nat := String_Length (Str);
14523 while J <= Len loop
14524 C := Get_String_Char (Str, J);
14525 OK := In_Character_Range (C);
14528 Chr := Get_Character (C);
14532 if J < Len and then Chr = '.' then
14534 C := Get_String_Char (Str, J);
14535 Chr := Get_Character (C);
14537 if not Set_Dot_Warning_Switch (Chr) then
14539 ("invalid warning switch character " &
14546 OK := Set_Warning_Switch (Chr);
14552 ("invalid warning switch character " & Chr,
14561 -- Two or more arguments (must be two)
14564 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14565 Check_At_Most_N_Arguments (2);
14573 E_Id := Get_Pragma_Arg (Arg2);
14576 -- In the expansion of an inlined body, a reference to
14577 -- the formal may be wrapped in a conversion if the
14578 -- actual is a conversion. Retrieve the real entity name.
14580 if (In_Instance_Body or In_Inlined_Body)
14581 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14583 E_Id := Expression (E_Id);
14586 -- Entity name case
14588 if Is_Entity_Name (E_Id) then
14589 E := Entity (E_Id);
14596 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14599 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14600 and then Warn_On_Warnings_Off
14602 Warnings_Off_Pragmas.Append ((N, E));
14605 if Is_Enumeration_Type (E) then
14609 Lit := First_Literal (E);
14610 while Present (Lit) loop
14611 Set_Warnings_Off (Lit);
14612 Next_Literal (Lit);
14617 exit when No (Homonym (E));
14622 -- Error if not entity or static string literal case
14624 elsif not Is_Static_String_Expression (Arg2) then
14626 ("second argument of pragma% must be entity " &
14627 "name or static string expression", Arg2);
14629 -- String literal case
14632 String_To_Name_Buffer
14633 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14635 -- Note on configuration pragma case: If this is a
14636 -- configuration pragma, then for an OFF pragma, we
14637 -- just set Config True in the call, which is all
14638 -- that needs to be done. For the case of ON, this
14639 -- is normally an error, unless it is canceling the
14640 -- effect of a previous OFF pragma in the same file.
14641 -- In any other case, an error will be signalled (ON
14642 -- with no matching OFF).
14644 -- Note: We set Used if we are inside a generic to
14645 -- disable the test that the non-config case actually
14646 -- cancels a warning. That's because we can't be sure
14647 -- there isn't an instantiation in some other unit
14648 -- where a warning is suppressed.
14650 -- We could do a little better here by checking if the
14651 -- generic unit we are inside is public, but for now
14652 -- we don't bother with that refinement.
14654 if Chars (Argx) = Name_Off then
14655 Set_Specific_Warning_Off
14656 (Loc, Name_Buffer (1 .. Name_Len),
14657 Config => Is_Configuration_Pragma,
14658 Used => Inside_A_Generic or else In_Instance);
14660 elsif Chars (Argx) = Name_On then
14661 Set_Specific_Warning_On
14662 (Loc, Name_Buffer (1 .. Name_Len), Err);
14666 ("?pragma Warnings On with no " &
14667 "matching Warnings Off",
14677 -------------------
14678 -- Weak_External --
14679 -------------------
14681 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
14683 when Pragma_Weak_External => Weak_External : declare
14688 Check_Arg_Count (1);
14689 Check_Optional_Identifier (Arg1, Name_Entity);
14690 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14691 Ent := Entity (Get_Pragma_Arg (Arg1));
14693 if Rep_Item_Too_Early (Ent, N) then
14696 Ent := Underlying_Type (Ent);
14699 -- The only processing required is to link this item on to the
14700 -- list of rep items for the given entity. This is accomplished
14701 -- by the call to Rep_Item_Too_Late (when no error is detected
14702 -- and False is returned).
14704 if Rep_Item_Too_Late (Ent, N) then
14707 Set_Has_Gigi_Rep_Item (Ent);
14711 -----------------------------
14712 -- Wide_Character_Encoding --
14713 -----------------------------
14715 -- pragma Wide_Character_Encoding (IDENTIFIER);
14717 when Pragma_Wide_Character_Encoding =>
14720 -- Nothing to do, handled in parser. Note that we do not enforce
14721 -- configuration pragma placement, this pragma can appear at any
14722 -- place in the source, allowing mixed encodings within a single
14727 --------------------
14728 -- Unknown_Pragma --
14729 --------------------
14731 -- Should be impossible, since the case of an unknown pragma is
14732 -- separately processed before the case statement is entered.
14734 when Unknown_Pragma =>
14735 raise Program_Error;
14738 -- AI05-0144: detect dangerous order dependence. Disabled for now,
14739 -- until AI is formally approved.
14741 -- Check_Order_Dependence;
14744 when Pragma_Exit => null;
14745 end Analyze_Pragma;
14747 -----------------------------
14748 -- Analyze_TC_In_Decl_Part --
14749 -----------------------------
14751 procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14753 -- Install formals and push subprogram spec onto scope stack so that we
14754 -- can see the formals from the pragma.
14756 Install_Formals (S);
14759 -- Preanalyze the boolean expressions, we treat these as spec
14760 -- expressions (i.e. similar to a default expression).
14762 Preanalyze_TC_Args (N,
14763 Get_Requires_From_Test_Case_Pragma (N),
14764 Get_Ensures_From_Test_Case_Pragma (N));
14766 -- Remove the subprogram from the scope stack now that the pre-analysis
14767 -- of the expressions in the test-case is done.
14770 end Analyze_TC_In_Decl_Part;
14772 --------------------
14773 -- Check_Disabled --
14774 --------------------
14776 function Check_Disabled (Nam : Name_Id) return Boolean is
14780 -- Loop through entries in check policy list
14782 PP := Opt.Check_Policy_List;
14784 -- If there are no specific entries that matched, then nothing is
14785 -- disabled, so return False.
14790 -- Here we have an entry see if it matches
14794 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14796 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14797 return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14799 PP := Next_Pragma (PP);
14804 end Check_Disabled;
14806 -------------------
14807 -- Check_Enabled --
14808 -------------------
14810 function Check_Enabled (Nam : Name_Id) return Boolean is
14814 -- Loop through entries in check policy list
14816 PP := Opt.Check_Policy_List;
14818 -- If there are no specific entries that matched, then we let the
14819 -- setting of assertions govern. Note that this provides the needed
14820 -- compatibility with the RM for the cases of assertion, invariant,
14821 -- precondition, predicate, and postcondition.
14824 return Assertions_Enabled;
14826 -- Here we have an entry see if it matches
14830 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14833 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14834 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14835 when Name_On | Name_Check =>
14837 when Name_Off | Name_Ignore =>
14840 raise Program_Error;
14844 PP := Next_Pragma (PP);
14851 ---------------------------------
14852 -- Delay_Config_Pragma_Analyze --
14853 ---------------------------------
14855 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14857 return Pragma_Name (N) = Name_Interrupt_State
14859 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14860 end Delay_Config_Pragma_Analyze;
14862 -------------------------
14863 -- Get_Base_Subprogram --
14864 -------------------------
14866 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14867 Result : Entity_Id;
14870 -- Follow subprogram renaming chain
14873 while Is_Subprogram (Result)
14875 Nkind (Parent (Declaration_Node (Result))) =
14876 N_Subprogram_Renaming_Declaration
14877 and then Present (Alias (Result))
14879 Result := Alias (Result);
14883 end Get_Base_Subprogram;
14889 procedure Initialize is
14894 -----------------------------
14895 -- Is_Config_Static_String --
14896 -----------------------------
14898 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14900 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14901 -- This is an internal recursive function that is just like the outer
14902 -- function except that it adds the string to the name buffer rather
14903 -- than placing the string in the name buffer.
14905 ------------------------------
14906 -- Add_Config_Static_String --
14907 ------------------------------
14909 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14916 if Nkind (N) = N_Op_Concat then
14917 if Add_Config_Static_String (Left_Opnd (N)) then
14918 N := Right_Opnd (N);
14924 if Nkind (N) /= N_String_Literal then
14925 Error_Msg_N ("string literal expected for pragma argument", N);
14929 for J in 1 .. String_Length (Strval (N)) loop
14930 C := Get_String_Char (Strval (N), J);
14932 if not In_Character_Range (C) then
14934 ("string literal contains invalid wide character",
14935 Sloc (N) + 1 + Source_Ptr (J));
14939 Add_Char_To_Name_Buffer (Get_Character (C));
14944 end Add_Config_Static_String;
14946 -- Start of processing for Is_Config_Static_String
14951 return Add_Config_Static_String (Arg);
14952 end Is_Config_Static_String;
14954 -----------------------------------------
14955 -- Is_Non_Significant_Pragma_Reference --
14956 -----------------------------------------
14958 -- This function makes use of the following static table which indicates
14959 -- whether appearance of some name in a given pragma is to be considered
14960 -- as a reference for the purposes of warnings about unreferenced objects.
14962 -- -1 indicates that references in any argument position are significant
14963 -- 0 indicates that appearance in any argument is not significant
14964 -- +n indicates that appearance as argument n is significant, but all
14965 -- other arguments are not significant
14966 -- 99 special processing required (e.g. for pragma Check)
14968 Sig_Flags : constant array (Pragma_Id) of Int :=
14969 (Pragma_AST_Entry => -1,
14970 Pragma_Abort_Defer => -1,
14971 Pragma_Ada_83 => -1,
14972 Pragma_Ada_95 => -1,
14973 Pragma_Ada_05 => -1,
14974 Pragma_Ada_2005 => -1,
14975 Pragma_Ada_12 => -1,
14976 Pragma_Ada_2012 => -1,
14977 Pragma_All_Calls_Remote => -1,
14978 Pragma_Annotate => -1,
14979 Pragma_Assert => -1,
14980 Pragma_Assertion_Policy => 0,
14981 Pragma_Assume_No_Invalid_Values => 0,
14982 Pragma_Asynchronous => -1,
14983 Pragma_Atomic => 0,
14984 Pragma_Atomic_Components => 0,
14985 Pragma_Attach_Handler => -1,
14986 Pragma_Check => 99,
14987 Pragma_Check_Name => 0,
14988 Pragma_Check_Policy => 0,
14989 Pragma_CIL_Constructor => -1,
14990 Pragma_CPP_Class => 0,
14991 Pragma_CPP_Constructor => 0,
14992 Pragma_CPP_Virtual => 0,
14993 Pragma_CPP_Vtable => 0,
14995 Pragma_C_Pass_By_Copy => 0,
14996 Pragma_Comment => 0,
14997 Pragma_Common_Object => -1,
14998 Pragma_Compile_Time_Error => -1,
14999 Pragma_Compile_Time_Warning => -1,
15000 Pragma_Compiler_Unit => 0,
15001 Pragma_Complete_Representation => 0,
15002 Pragma_Complex_Representation => 0,
15003 Pragma_Component_Alignment => -1,
15004 Pragma_Controlled => 0,
15005 Pragma_Convention => 0,
15006 Pragma_Convention_Identifier => 0,
15007 Pragma_Debug => -1,
15008 Pragma_Debug_Policy => 0,
15009 Pragma_Detect_Blocking => -1,
15010 Pragma_Default_Storage_Pool => -1,
15011 Pragma_Disable_Atomic_Synchronization => -1,
15012 Pragma_Discard_Names => 0,
15013 Pragma_Dispatching_Domain => -1,
15014 Pragma_Elaborate => -1,
15015 Pragma_Elaborate_All => -1,
15016 Pragma_Elaborate_Body => -1,
15017 Pragma_Elaboration_Checks => -1,
15018 Pragma_Eliminate => -1,
15019 Pragma_Enable_Atomic_Synchronization => -1,
15020 Pragma_Export => -1,
15021 Pragma_Export_Exception => -1,
15022 Pragma_Export_Function => -1,
15023 Pragma_Export_Object => -1,
15024 Pragma_Export_Procedure => -1,
15025 Pragma_Export_Value => -1,
15026 Pragma_Export_Valued_Procedure => -1,
15027 Pragma_Extend_System => -1,
15028 Pragma_Extensions_Allowed => -1,
15029 Pragma_External => -1,
15030 Pragma_Favor_Top_Level => -1,
15031 Pragma_External_Name_Casing => -1,
15032 Pragma_Fast_Math => -1,
15033 Pragma_Finalize_Storage_Only => 0,
15034 Pragma_Float_Representation => 0,
15035 Pragma_Ident => -1,
15036 Pragma_Implementation_Defined => -1,
15037 Pragma_Implemented => -1,
15038 Pragma_Implicit_Packing => 0,
15039 Pragma_Import => +2,
15040 Pragma_Import_Exception => 0,
15041 Pragma_Import_Function => 0,
15042 Pragma_Import_Object => 0,
15043 Pragma_Import_Procedure => 0,
15044 Pragma_Import_Valued_Procedure => 0,
15045 Pragma_Independent => 0,
15046 Pragma_Independent_Components => 0,
15047 Pragma_Initialize_Scalars => -1,
15048 Pragma_Inline => 0,
15049 Pragma_Inline_Always => 0,
15050 Pragma_Inline_Generic => 0,
15051 Pragma_Inspection_Point => -1,
15052 Pragma_Interface => +2,
15053 Pragma_Interface_Name => +2,
15054 Pragma_Interrupt_Handler => -1,
15055 Pragma_Interrupt_Priority => -1,
15056 Pragma_Interrupt_State => -1,
15057 Pragma_Invariant => -1,
15058 Pragma_Java_Constructor => -1,
15059 Pragma_Java_Interface => -1,
15060 Pragma_Keep_Names => 0,
15061 Pragma_License => -1,
15062 Pragma_Link_With => -1,
15063 Pragma_Linker_Alias => -1,
15064 Pragma_Linker_Constructor => -1,
15065 Pragma_Linker_Destructor => -1,
15066 Pragma_Linker_Options => -1,
15067 Pragma_Linker_Section => -1,
15069 Pragma_Locking_Policy => -1,
15070 Pragma_Long_Float => -1,
15071 Pragma_Machine_Attribute => -1,
15073 Pragma_Main_Storage => -1,
15074 Pragma_Memory_Size => -1,
15075 Pragma_No_Return => 0,
15076 Pragma_No_Body => 0,
15077 Pragma_No_Run_Time => -1,
15078 Pragma_No_Strict_Aliasing => -1,
15079 Pragma_Normalize_Scalars => -1,
15080 Pragma_Obsolescent => 0,
15081 Pragma_Optimize => -1,
15082 Pragma_Optimize_Alignment => -1,
15083 Pragma_Ordered => 0,
15086 Pragma_Passive => -1,
15087 Pragma_Preelaborable_Initialization => -1,
15088 Pragma_Polling => -1,
15089 Pragma_Persistent_BSS => 0,
15090 Pragma_Postcondition => -1,
15091 Pragma_Precondition => -1,
15092 Pragma_Predicate => -1,
15093 Pragma_Preelaborate => -1,
15094 Pragma_Preelaborate_05 => -1,
15095 Pragma_Priority => -1,
15096 Pragma_Priority_Specific_Dispatching => -1,
15097 Pragma_Profile => 0,
15098 Pragma_Profile_Warnings => 0,
15099 Pragma_Propagate_Exceptions => -1,
15100 Pragma_Psect_Object => -1,
15102 Pragma_Pure_05 => -1,
15103 Pragma_Pure_12 => -1,
15104 Pragma_Pure_Function => -1,
15105 Pragma_Queuing_Policy => -1,
15106 Pragma_Ravenscar => -1,
15107 Pragma_Relative_Deadline => -1,
15108 Pragma_Remote_Access_Type => -1,
15109 Pragma_Remote_Call_Interface => -1,
15110 Pragma_Remote_Types => -1,
15111 Pragma_Restricted_Run_Time => -1,
15112 Pragma_Restriction_Warnings => -1,
15113 Pragma_Restrictions => -1,
15114 Pragma_Reviewable => -1,
15115 Pragma_Short_Circuit_And_Or => -1,
15116 Pragma_Share_Generic => -1,
15117 Pragma_Shared => -1,
15118 Pragma_Shared_Passive => -1,
15119 Pragma_Short_Descriptors => 0,
15120 Pragma_Source_File_Name => -1,
15121 Pragma_Source_File_Name_Project => -1,
15122 Pragma_Source_Reference => -1,
15123 Pragma_Storage_Size => -1,
15124 Pragma_Storage_Unit => -1,
15125 Pragma_Static_Elaboration_Desired => -1,
15126 Pragma_Stream_Convert => -1,
15127 Pragma_Style_Checks => -1,
15128 Pragma_Subtitle => -1,
15129 Pragma_Suppress => 0,
15130 Pragma_Suppress_Exception_Locations => 0,
15131 Pragma_Suppress_All => -1,
15132 Pragma_Suppress_Debug_Info => 0,
15133 Pragma_Suppress_Initialization => 0,
15134 Pragma_System_Name => -1,
15135 Pragma_Task_Dispatching_Policy => -1,
15136 Pragma_Task_Info => -1,
15137 Pragma_Task_Name => -1,
15138 Pragma_Task_Storage => 0,
15139 Pragma_Test_Case => -1,
15140 Pragma_Thread_Local_Storage => 0,
15141 Pragma_Time_Slice => -1,
15142 Pragma_Title => -1,
15143 Pragma_Unchecked_Union => 0,
15144 Pragma_Unimplemented_Unit => -1,
15145 Pragma_Universal_Aliasing => -1,
15146 Pragma_Universal_Data => -1,
15147 Pragma_Unmodified => -1,
15148 Pragma_Unreferenced => -1,
15149 Pragma_Unreferenced_Objects => -1,
15150 Pragma_Unreserve_All_Interrupts => -1,
15151 Pragma_Unsuppress => 0,
15152 Pragma_Use_VADS_Size => -1,
15153 Pragma_Validity_Checks => -1,
15154 Pragma_Volatile => 0,
15155 Pragma_Volatile_Components => 0,
15156 Pragma_Warnings => -1,
15157 Pragma_Weak_External => -1,
15158 Pragma_Wide_Character_Encoding => 0,
15159 Unknown_Pragma => 0);
15161 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
15170 if Nkind (P) /= N_Pragma_Argument_Association then
15174 Id := Get_Pragma_Id (Parent (P));
15175 C := Sig_Flags (Id);
15187 -- For pragma Check, the first argument is not significant,
15188 -- the second and the third (if present) arguments are
15191 when Pragma_Check =>
15193 P = First (Pragma_Argument_Associations (Parent (P)));
15196 raise Program_Error;
15200 A := First (Pragma_Argument_Associations (Parent (P)));
15201 for J in 1 .. C - 1 loop
15209 return A = P; -- is this wrong way round ???
15212 end Is_Non_Significant_Pragma_Reference;
15214 ------------------------------
15215 -- Is_Pragma_String_Literal --
15216 ------------------------------
15218 -- This function returns true if the corresponding pragma argument is a
15219 -- static string expression. These are the only cases in which string
15220 -- literals can appear as pragma arguments. We also allow a string literal
15221 -- as the first argument to pragma Assert (although it will of course
15222 -- always generate a type error).
15224 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
15225 Pragn : constant Node_Id := Parent (Par);
15226 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
15227 Pname : constant Name_Id := Pragma_Name (Pragn);
15233 N := First (Assoc);
15240 if Pname = Name_Assert then
15243 elsif Pname = Name_Export then
15246 elsif Pname = Name_Ident then
15249 elsif Pname = Name_Import then
15252 elsif Pname = Name_Interface_Name then
15255 elsif Pname = Name_Linker_Alias then
15258 elsif Pname = Name_Linker_Section then
15261 elsif Pname = Name_Machine_Attribute then
15264 elsif Pname = Name_Source_File_Name then
15267 elsif Pname = Name_Source_Reference then
15270 elsif Pname = Name_Title then
15273 elsif Pname = Name_Subtitle then
15279 end Is_Pragma_String_Literal;
15281 -----------------------------------------
15282 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
15283 -----------------------------------------
15285 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
15286 Aspects : constant List_Id := New_List;
15287 Loc : constant Source_Ptr := Sloc (Decl);
15288 Or_Decl : constant Node_Id := Original_Node (Decl);
15290 Original_Aspects : List_Id;
15291 -- To capture global references, a copy of the created aspects must be
15292 -- inserted in the original tree.
15295 Prag_Arg_Ass : Node_Id;
15296 Prag_Id : Pragma_Id;
15299 -- Check for any PPC pragmas that appear within Decl
15301 Prag := Next (Decl);
15302 while Nkind (Prag) = N_Pragma loop
15303 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
15306 when Pragma_Postcondition | Pragma_Precondition =>
15307 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
15309 -- Make an aspect from any PPC pragma
15311 Append_To (Aspects,
15312 Make_Aspect_Specification (Loc,
15314 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
15316 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
15318 -- Generate the analysis information in the pragma expression
15319 -- and then set the pragma node analyzed to avoid any further
15322 Analyze (Expression (Prag_Arg_Ass));
15323 Set_Analyzed (Prag, True);
15325 when others => null;
15331 -- Set all new aspects into the generic declaration node
15333 if Is_Non_Empty_List (Aspects) then
15335 -- Create the list of aspects to be inserted in the original tree
15337 Original_Aspects := Copy_Separate_List (Aspects);
15339 -- Check if Decl already has aspects
15341 -- Attach the new lists of aspects to both the generic copy and the
15344 if Has_Aspects (Decl) then
15345 Append_List (Aspects, Aspect_Specifications (Decl));
15346 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
15349 Set_Parent (Aspects, Decl);
15350 Set_Aspect_Specifications (Decl, Aspects);
15351 Set_Parent (Original_Aspects, Or_Decl);
15352 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
15355 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
15357 ------------------------
15358 -- Preanalyze_TC_Args --
15359 ------------------------
15361 procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
15363 -- Preanalyze the boolean expressions, we treat these as spec
15364 -- expressions (i.e. similar to a default expression).
15366 if Present (Arg_Req) then
15367 Preanalyze_Spec_Expression
15368 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
15370 -- In ASIS mode, for a pragma generated from a source aspect, also
15371 -- analyze the original aspect expression.
15373 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
15374 Preanalyze_Spec_Expression
15375 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
15379 if Present (Arg_Ens) then
15380 Preanalyze_Spec_Expression
15381 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
15383 -- In ASIS mode, for a pragma generated from a source aspect, also
15384 -- analyze the original aspect expression.
15386 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
15387 Preanalyze_Spec_Expression
15388 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
15391 end Preanalyze_TC_Args;
15393 --------------------------------------
15394 -- Process_Compilation_Unit_Pragmas --
15395 --------------------------------------
15397 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
15399 -- A special check for pragma Suppress_All, a very strange DEC pragma,
15400 -- strange because it comes at the end of the unit. Rational has the
15401 -- same name for a pragma, but treats it as a program unit pragma, In
15402 -- GNAT we just decide to allow it anywhere at all. If it appeared then
15403 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
15404 -- node, and we insert a pragma Suppress (All_Checks) at the start of
15405 -- the context clause to ensure the correct processing.
15407 if Has_Pragma_Suppress_All (N) then
15408 Prepend_To (Context_Items (N),
15409 Make_Pragma (Sloc (N),
15410 Chars => Name_Suppress,
15411 Pragma_Argument_Associations => New_List (
15412 Make_Pragma_Argument_Association (Sloc (N),
15413 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
15416 -- Nothing else to do at the current time!
15418 end Process_Compilation_Unit_Pragmas;
15429 --------------------------------
15430 -- Set_Encoded_Interface_Name --
15431 --------------------------------
15433 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
15434 Str : constant String_Id := Strval (S);
15435 Len : constant Int := String_Length (Str);
15440 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
15443 -- Stores encoded value of character code CC. The encoding we use an
15444 -- underscore followed by four lower case hex digits.
15450 procedure Encode is
15452 Store_String_Char (Get_Char_Code ('_'));
15454 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
15456 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
15458 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
15460 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
15463 -- Start of processing for Set_Encoded_Interface_Name
15466 -- If first character is asterisk, this is a link name, and we leave it
15467 -- completely unmodified. We also ignore null strings (the latter case
15468 -- happens only in error cases) and no encoding should occur for Java or
15469 -- AAMP interface names.
15472 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
15473 or else VM_Target /= No_VM
15474 or else AAMP_On_Target
15476 Set_Interface_Name (E, S);
15481 CC := Get_String_Char (Str, J);
15483 exit when not In_Character_Range (CC);
15485 C := Get_Character (CC);
15487 exit when C /= '_' and then C /= '$'
15488 and then C not in '0' .. '9'
15489 and then C not in 'a' .. 'z'
15490 and then C not in 'A' .. 'Z';
15493 Set_Interface_Name (E, S);
15501 -- Here we need to encode. The encoding we use as follows:
15502 -- three underscores + four hex digits (lower case)
15506 for J in 1 .. String_Length (Str) loop
15507 CC := Get_String_Char (Str, J);
15509 if not In_Character_Range (CC) then
15512 C := Get_Character (CC);
15514 if C = '_' or else C = '$'
15515 or else C in '0' .. '9'
15516 or else C in 'a' .. 'z'
15517 or else C in 'A' .. 'Z'
15519 Store_String_Char (CC);
15526 Set_Interface_Name (E,
15527 Make_String_Literal (Sloc (S),
15528 Strval => End_String));
15530 end Set_Encoded_Interface_Name;
15532 -------------------
15533 -- Set_Unit_Name --
15534 -------------------
15536 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15541 if Nkind (N) = N_Identifier
15542 and then Nkind (With_Item) = N_Identifier
15544 Set_Entity (N, Entity (With_Item));
15546 elsif Nkind (N) = N_Selected_Component then
15547 Change_Selected_Component_To_Expanded_Name (N);
15548 Set_Entity (N, Entity (With_Item));
15549 Set_Entity (Selector_Name (N), Entity (N));
15551 Pref := Prefix (N);
15552 Scop := Scope (Entity (N));
15553 while Nkind (Pref) = N_Selected_Component loop
15554 Change_Selected_Component_To_Expanded_Name (Pref);
15555 Set_Entity (Selector_Name (Pref), Scop);
15556 Set_Entity (Pref, Scop);
15557 Pref := Prefix (Pref);
15558 Scop := Scope (Scop);
15561 Set_Entity (Pref, Scop);