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
281 Class_Wide_Condition : declare
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);
368 -- Start of processing for Class_Wide_Condition
371 if not Present (T) then
373 Chars (Identifier (Corresponding_Aspect (N)));
375 Error_Msg_Name_2 := Name_Class;
378 ("aspect `%''%` can only be specified for a primitive " &
379 "operation of a tagged type",
380 Corresponding_Aspect (N));
383 Replace_Type (Get_Pragma_Arg (Arg1));
384 end Class_Wide_Condition;
387 -- Remove the subprogram from the scope stack now that the pre-analysis
388 -- of the precondition/postcondition is done.
391 end Analyze_PPC_In_Decl_Part;
397 procedure Analyze_Pragma (N : Node_Id) is
398 Loc : constant Source_Ptr := Sloc (N);
402 -- Name of the source pragma, or name of the corresponding aspect for
403 -- pragmas which originate in a source aspect. In the latter case, the
404 -- name may be different from the pragma name.
406 Pragma_Exit : exception;
407 -- This exception is used to exit pragma processing completely. It is
408 -- used when an error is detected, and no further processing is
409 -- required. It is also used if an earlier error has left the tree in
410 -- a state where the pragma should not be processed.
413 -- Number of pragma argument associations
419 -- First four pragma arguments (pragma argument association nodes, or
420 -- Empty if the corresponding argument does not exist).
422 type Name_List is array (Natural range <>) of Name_Id;
423 type Args_List is array (Natural range <>) of Node_Id;
424 -- Types used for arguments to Check_Arg_Order and Gather_Associations
426 procedure Ada_2005_Pragma;
427 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
428 -- Ada 95 mode, these are implementation defined pragmas, so should be
429 -- caught by the No_Implementation_Pragmas restriction.
431 procedure Ada_2012_Pragma;
432 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
433 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
434 -- should be caught by the No_Implementation_Pragmas restriction.
436 procedure Check_Ada_83_Warning;
437 -- Issues a warning message for the current pragma if operating in Ada
438 -- 83 mode (used for language pragmas that are not a standard part of
439 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
442 procedure Check_Arg_Count (Required : Nat);
443 -- Check argument count for pragma is equal to given parameter. If not,
444 -- then issue an error message and raise Pragma_Exit.
446 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
447 -- Arg which can either be a pragma argument association, in which case
448 -- the check is applied to the expression of the association or an
449 -- expression directly.
451 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
452 -- Check that an argument has the right form for an EXTERNAL_NAME
453 -- parameter of an extended import/export pragma. The rule is that the
454 -- name must be an identifier or string literal (in Ada 83 mode) or a
455 -- static string expression (in Ada 95 mode).
457 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
458 -- Check the specified argument Arg to make sure that it is an
459 -- identifier. If not give error and raise Pragma_Exit.
461 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
462 -- Check the specified argument Arg to make sure that it is an integer
463 -- literal. If not give error and raise Pragma_Exit.
465 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
466 -- Check the specified argument Arg to make sure that it has the proper
467 -- syntactic form for a local name and meets the semantic requirements
468 -- for a local name. The local name is analyzed as part of the
469 -- processing for this call. In addition, the local name is required
470 -- to represent an entity at the library level.
472 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
473 -- Check the specified argument Arg to make sure that it has the proper
474 -- syntactic form for a local name and meets the semantic requirements
475 -- for a local name. The local name is analyzed as part of the
476 -- processing for this call.
478 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
479 -- Check the specified argument Arg to make sure that it is a valid
480 -- locking policy name. If not give error and raise Pragma_Exit.
482 procedure Check_Arg_Is_One_Of
485 procedure Check_Arg_Is_One_Of
487 N1, N2, N3 : Name_Id);
488 procedure Check_Arg_Is_One_Of
490 N1, N2, N3, N4 : Name_Id);
491 procedure Check_Arg_Is_One_Of
493 N1, N2, N3, N4, N5 : Name_Id);
494 -- Check the specified argument Arg to make sure that it is an
495 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
496 -- present). If not then give error and raise Pragma_Exit.
498 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
499 -- Check the specified argument Arg to make sure that it is a valid
500 -- queuing policy name. If not give error and raise Pragma_Exit.
502 procedure Check_Arg_Is_Static_Expression
504 Typ : Entity_Id := Empty);
505 -- Check the specified argument Arg to make sure that it is a static
506 -- expression of the given type (i.e. it will be analyzed and resolved
507 -- using this type, which can be any valid argument to Resolve, e.g.
508 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
509 -- Typ is left Empty, then any static expression is allowed.
511 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
512 -- Check the specified argument Arg to make sure that it is a valid task
513 -- dispatching policy name. If not give error and raise Pragma_Exit.
515 procedure Check_Arg_Order (Names : Name_List);
516 -- Checks for an instance of two arguments with identifiers for the
517 -- current pragma which are not in the sequence indicated by Names,
518 -- and if so, generates a fatal message about bad order of arguments.
520 procedure Check_At_Least_N_Arguments (N : Nat);
521 -- Check there are at least N arguments present
523 procedure Check_At_Most_N_Arguments (N : Nat);
524 -- Check there are no more than N arguments present
526 procedure Check_Component
529 In_Variant_Part : Boolean := False);
530 -- Examine an Unchecked_Union component for correct use of per-object
531 -- constrained subtypes, and for restrictions on finalizable components.
532 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
533 -- should be set when Comp comes from a record variant.
535 procedure Check_Duplicate_Pragma (E : Entity_Id);
536 -- Check if a pragma of the same name as the current pragma is already
537 -- chained as a rep pragma to the given entity. If so give a message
538 -- about the duplicate, and then raise Pragma_Exit so does not return.
539 -- Also checks for delayed aspect specification node in the chain.
541 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
542 -- Nam is an N_String_Literal node containing the external name set by
543 -- an Import or Export pragma (or extended Import or Export pragma).
544 -- This procedure checks for possible duplications if this is the export
545 -- case, and if found, issues an appropriate error message.
547 procedure Check_Expr_Is_Static_Expression
549 Typ : Entity_Id := Empty);
550 -- Check the specified expression Expr to make sure that it is a static
551 -- expression of the given type (i.e. it will be analyzed and resolved
552 -- using this type, which can be any valid argument to Resolve, e.g.
553 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
554 -- Typ is left Empty, then any static expression is allowed.
556 procedure Check_First_Subtype (Arg : Node_Id);
557 -- Checks that Arg, whose expression is an entity name, references a
560 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
561 -- Checks that the given argument has an identifier, and if so, requires
562 -- it to match the given identifier name. If there is no identifier, or
563 -- a non-matching identifier, then an error message is given and
564 -- Pragma_Exit is raised.
566 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
567 -- Checks that the given argument has an identifier, and if so, requires
568 -- it to match one of the given identifier names. If there is no
569 -- identifier, or a non-matching identifier, then an error message is
570 -- given and Pragma_Exit is raised.
572 procedure Check_In_Main_Program;
573 -- Common checks for pragmas that appear within a main program
574 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
576 procedure Check_Interrupt_Or_Attach_Handler;
577 -- Common processing for first argument of pragma Interrupt_Handler or
578 -- pragma Attach_Handler.
580 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
581 -- Check that pragma appears in a declarative part, or in a package
582 -- specification, i.e. that it does not occur in a statement sequence
585 procedure Check_No_Identifier (Arg : Node_Id);
586 -- Checks that the given argument does not have an identifier. If
587 -- an identifier is present, then an error message is issued, and
588 -- Pragma_Exit is raised.
590 procedure Check_No_Identifiers;
591 -- Checks that none of the arguments to the pragma has an identifier.
592 -- If any argument has an identifier, then an error message is issued,
593 -- and Pragma_Exit is raised.
595 procedure Check_No_Link_Name;
596 -- Checks that no link name is specified
598 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
599 -- Checks if the given argument has an identifier, and if so, requires
600 -- it to match the given identifier name. If there is a non-matching
601 -- identifier, then an error message is given and Pragma_Exit is raised.
603 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
604 -- Checks if the given argument has an identifier, and if so, requires
605 -- it to match the given identifier name. If there is a non-matching
606 -- identifier, then an error message is given and Pragma_Exit is raised.
607 -- In this version of the procedure, the identifier name is given as
608 -- a string with lower case letters.
610 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
611 -- Called to process a precondition or postcondition pragma. There are
614 -- The pragma appears after a subprogram spec
616 -- If the corresponding check is not enabled, the pragma is analyzed
617 -- but otherwise ignored and control returns with In_Body set False.
619 -- If the check is enabled, then the first step is to analyze the
620 -- pragma, but this is skipped if the subprogram spec appears within
621 -- a package specification (because this is the case where we delay
622 -- analysis till the end of the spec). Then (whether or not it was
623 -- analyzed), the pragma is chained to the subprogram in question
624 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
625 -- caller with In_Body set False.
627 -- The pragma appears at the start of subprogram body declarations
629 -- In this case an immediate return to the caller is made with
630 -- In_Body set True, and the pragma is NOT analyzed.
632 -- In all other cases, an error message for bad placement is given
634 procedure Check_Static_Constraint (Constr : Node_Id);
635 -- Constr is a constraint from an N_Subtype_Indication node from a
636 -- component constraint in an Unchecked_Union type. This routine checks
637 -- that the constraint is static as required by the restrictions for
640 procedure Check_Test_Case;
641 -- Called to process a test-case pragma. The treatment is similar to the
642 -- one for pre- and postcondition in Check_Precondition_Postcondition,
643 -- except the placement rules for the test-case pragma are stricter.
644 -- This pragma may only occur after a subprogram spec declared directly
645 -- in a package spec unit. In this case, the pragma is chained to the
646 -- subprogram in question (using Spec_TC_List and Next_Pragma) and
647 -- analysis of the pragma is delayed till the end of the spec. In
648 -- all other cases, an error message for bad placement is given.
650 procedure Check_Valid_Configuration_Pragma;
651 -- Legality checks for placement of a configuration pragma
653 procedure Check_Valid_Library_Unit_Pragma;
654 -- Legality checks for library unit pragmas. A special case arises for
655 -- pragmas in generic instances that come from copies of the original
656 -- library unit pragmas in the generic templates. In the case of other
657 -- than library level instantiations these can appear in contexts which
658 -- would normally be invalid (they only apply to the original template
659 -- and to library level instantiations), and they are simply ignored,
660 -- which is implemented by rewriting them as null statements.
662 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
663 -- Check an Unchecked_Union variant for lack of nested variants and
664 -- presence of at least one component. UU_Typ is the related Unchecked_
667 procedure Error_Pragma (Msg : String);
668 pragma No_Return (Error_Pragma);
669 -- Outputs error message for current pragma. The message contains a %
670 -- that will be replaced with the pragma name, and the flag is placed
671 -- on the pragma itself. Pragma_Exit is then raised.
673 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
674 pragma No_Return (Error_Pragma_Arg);
675 -- Outputs error message for current pragma. The message may contain
676 -- a % that will be replaced with the pragma name. The parameter Arg
677 -- may either be a pragma argument association, in which case the flag
678 -- is placed on the expression of this association, or an expression,
679 -- in which case the flag is placed directly on the expression. The
680 -- message is placed using Error_Msg_N, so the message may also contain
681 -- an & insertion character which will reference the given Arg value.
682 -- After placing the message, Pragma_Exit is raised.
684 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
685 pragma No_Return (Error_Pragma_Arg);
686 -- Similar to above form of Error_Pragma_Arg except that two messages
687 -- are provided, the second is a continuation comment starting with \.
689 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
690 pragma No_Return (Error_Pragma_Arg_Ident);
691 -- Outputs error message for current pragma. The message may contain
692 -- a % that will be replaced with the pragma name. The parameter Arg
693 -- must be a pragma argument association with a non-empty identifier
694 -- (i.e. its Chars field must be set), and the error message is placed
695 -- on the identifier. The message is placed using Error_Msg_N so
696 -- the message may also contain an & insertion character which will
697 -- reference the identifier. After placing the message, Pragma_Exit
700 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
701 pragma No_Return (Error_Pragma_Ref);
702 -- Outputs error message for current pragma. The message may contain
703 -- a % that will be replaced with the pragma name. The parameter Ref
704 -- must be an entity whose name can be referenced by & and sloc by #.
705 -- After placing the message, Pragma_Exit is raised.
707 function Find_Lib_Unit_Name return Entity_Id;
708 -- Used for a library unit pragma to find the entity to which the
709 -- library unit pragma applies, returns the entity found.
711 procedure Find_Program_Unit_Name (Id : Node_Id);
712 -- If the pragma is a compilation unit pragma, the id must denote the
713 -- compilation unit in the same compilation, and the pragma must appear
714 -- in the list of preceding or trailing pragmas. If it is a program
715 -- unit pragma that is not a compilation unit pragma, then the
716 -- identifier must be visible.
718 function Find_Unique_Parameterless_Procedure
720 Arg : Node_Id) return Entity_Id;
721 -- Used for a procedure pragma to find the unique parameterless
722 -- procedure identified by Name, returns it if it exists, otherwise
723 -- errors out and uses Arg as the pragma argument for the message.
725 procedure Fix_Error (Msg : in out String);
726 -- This is called prior to issuing an error message. Msg is a string
727 -- that typically contains the substring "pragma". If the current pragma
728 -- comes from an aspect, each such "pragma" substring is replaced with
729 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
730 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
732 procedure Gather_Associations
734 Args : out Args_List);
735 -- This procedure is used to gather the arguments for a pragma that
736 -- permits arbitrary ordering of parameters using the normal rules
737 -- for named and positional parameters. The Names argument is a list
738 -- of Name_Id values that corresponds to the allowed pragma argument
739 -- association identifiers in order. The result returned in Args is
740 -- a list of corresponding expressions that are the pragma arguments.
741 -- Note that this is a list of expressions, not of pragma argument
742 -- associations (Gather_Associations has completely checked all the
743 -- optional identifiers when it returns). An entry in Args is Empty
744 -- on return if the corresponding argument is not present.
746 procedure GNAT_Pragma;
747 -- Called for all GNAT defined pragmas to check the relevant restriction
748 -- (No_Implementation_Pragmas).
750 function Is_Before_First_Decl
751 (Pragma_Node : Node_Id;
752 Decls : List_Id) return Boolean;
753 -- Return True if Pragma_Node is before the first declarative item in
754 -- Decls where Decls is the list of declarative items.
756 function Is_Configuration_Pragma return Boolean;
757 -- Determines if the placement of the current pragma is appropriate
758 -- for a configuration pragma.
760 function Is_In_Context_Clause return Boolean;
761 -- Returns True if pragma appears within the context clause of a unit,
762 -- and False for any other placement (does not generate any messages).
764 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
765 -- Analyzes the argument, and determines if it is a static string
766 -- expression, returns True if so, False if non-static or not String.
768 procedure Pragma_Misplaced;
769 pragma No_Return (Pragma_Misplaced);
770 -- Issue fatal error message for misplaced pragma
772 procedure Process_Atomic_Shared_Volatile;
773 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
774 -- Shared is an obsolete Ada 83 pragma, treated as being identical
775 -- in effect to pragma Atomic.
777 procedure Process_Compile_Time_Warning_Or_Error;
778 -- Common processing for Compile_Time_Error and Compile_Time_Warning
780 procedure Process_Convention
781 (C : out Convention_Id;
782 Ent : out Entity_Id);
783 -- Common processing for Convention, Interface, Import and Export.
784 -- Checks first two arguments of pragma, and sets the appropriate
785 -- convention value in the specified entity or entities. On return
786 -- C is the convention, Ent is the referenced entity.
788 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
789 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
790 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
792 procedure Process_Extended_Import_Export_Exception_Pragma
793 (Arg_Internal : Node_Id;
794 Arg_External : Node_Id;
797 -- Common processing for the pragmas Import/Export_Exception. The three
798 -- arguments correspond to the three named parameters of the pragma. An
799 -- argument is empty if the corresponding parameter is not present in
802 procedure Process_Extended_Import_Export_Object_Pragma
803 (Arg_Internal : Node_Id;
804 Arg_External : Node_Id;
806 -- Common processing for the pragmas Import/Export_Object. The three
807 -- arguments correspond to the three named parameters of the pragmas. An
808 -- argument is empty if the corresponding parameter is not present in
811 procedure Process_Extended_Import_Export_Internal_Arg
812 (Arg_Internal : Node_Id := Empty);
813 -- Common processing for all extended Import and Export pragmas. The
814 -- argument is the pragma parameter for the Internal argument. If
815 -- Arg_Internal is empty or inappropriate, an error message is posted.
816 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
817 -- set to identify the referenced entity.
819 procedure Process_Extended_Import_Export_Subprogram_Pragma
820 (Arg_Internal : Node_Id;
821 Arg_External : Node_Id;
822 Arg_Parameter_Types : Node_Id;
823 Arg_Result_Type : Node_Id := Empty;
824 Arg_Mechanism : Node_Id;
825 Arg_Result_Mechanism : Node_Id := Empty;
826 Arg_First_Optional_Parameter : Node_Id := Empty);
827 -- Common processing for all extended Import and Export pragmas applying
828 -- to subprograms. The caller omits any arguments that do not apply to
829 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
830 -- only in the Import_Function and Export_Function cases). The argument
831 -- names correspond to the allowed pragma association identifiers.
833 procedure Process_Generic_List;
834 -- Common processing for Share_Generic and Inline_Generic
836 procedure Process_Import_Or_Interface;
837 -- Common processing for Import of Interface
839 procedure Process_Import_Predefined_Type;
840 -- Processing for completing a type with pragma Import. This is used
841 -- to declare types that match predefined C types, especially for cases
842 -- without corresponding Ada predefined type.
844 procedure Process_Inline (Active : Boolean);
845 -- Common processing for Inline and Inline_Always. The parameter
846 -- indicates if the inline pragma is active, i.e. if it should actually
847 -- cause inlining to occur.
849 procedure Process_Interface_Name
850 (Subprogram_Def : Entity_Id;
853 -- Given the last two arguments of pragma Import, pragma Export, or
854 -- pragma Interface_Name, performs validity checks and sets the
855 -- Interface_Name field of the given subprogram entity to the
856 -- appropriate external or link name, depending on the arguments given.
857 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
858 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
859 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
860 -- nor Link_Arg is present, the interface name is set to the default
861 -- from the subprogram name.
863 procedure Process_Interrupt_Or_Attach_Handler;
864 -- Common processing for Interrupt and Attach_Handler pragmas
866 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
867 -- Common processing for Restrictions and Restriction_Warnings pragmas.
868 -- Warn is True for Restriction_Warnings, or for Restrictions if the
869 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
870 -- is not set in the Restrictions case.
872 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
873 -- Common processing for Suppress and Unsuppress. The boolean parameter
874 -- Suppress_Case is True for the Suppress case, and False for the
877 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
878 -- This procedure sets the Is_Exported flag for the given entity,
879 -- checking that the entity was not previously imported. Arg is
880 -- the argument that specified the entity. A check is also made
881 -- for exporting inappropriate entities.
883 procedure Set_Extended_Import_Export_External_Name
884 (Internal_Ent : Entity_Id;
885 Arg_External : Node_Id);
886 -- Common processing for all extended import export pragmas. The first
887 -- argument, Internal_Ent, is the internal entity, which has already
888 -- been checked for validity by the caller. Arg_External is from the
889 -- Import or Export pragma, and may be null if no External parameter
890 -- was present. If Arg_External is present and is a non-null string
891 -- (a null string is treated as the default), then the Interface_Name
892 -- field of Internal_Ent is set appropriately.
894 procedure Set_Imported (E : Entity_Id);
895 -- This procedure sets the Is_Imported flag for the given entity,
896 -- checking that it is not previously exported or imported.
898 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
899 -- Mech is a parameter passing mechanism (see Import_Function syntax
900 -- for MECHANISM_NAME). This routine checks that the mechanism argument
901 -- has the right form, and if not issues an error message. If the
902 -- argument has the right form then the Mechanism field of Ent is
903 -- set appropriately.
905 procedure Set_Ravenscar_Profile (N : Node_Id);
906 -- Activate the set of configuration pragmas and restrictions that make
907 -- up the Ravenscar Profile. N is the corresponding pragma node, which
908 -- is used for error messages on any constructs that violate the
911 ---------------------
912 -- Ada_2005_Pragma --
913 ---------------------
915 procedure Ada_2005_Pragma is
917 if Ada_Version <= Ada_95 then
918 Check_Restriction (No_Implementation_Pragmas, N);
922 ---------------------
923 -- Ada_2012_Pragma --
924 ---------------------
926 procedure Ada_2012_Pragma is
928 if Ada_Version <= Ada_2005 then
929 Check_Restriction (No_Implementation_Pragmas, N);
933 --------------------------
934 -- Check_Ada_83_Warning --
935 --------------------------
937 procedure Check_Ada_83_Warning is
939 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
940 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
942 end Check_Ada_83_Warning;
944 ---------------------
945 -- Check_Arg_Count --
946 ---------------------
948 procedure Check_Arg_Count (Required : Nat) is
950 if Arg_Count /= Required then
951 Error_Pragma ("wrong number of arguments for pragma%");
955 --------------------------------
956 -- Check_Arg_Is_External_Name --
957 --------------------------------
959 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
960 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
963 if Nkind (Argx) = N_Identifier then
967 Analyze_And_Resolve (Argx, Standard_String);
969 if Is_OK_Static_Expression (Argx) then
972 elsif Etype (Argx) = Any_Type then
975 -- An interesting special case, if we have a string literal and
976 -- we are in Ada 83 mode, then we allow it even though it will
977 -- not be flagged as static. This allows expected Ada 83 mode
978 -- use of external names which are string literals, even though
979 -- technically these are not static in Ada 83.
981 elsif Ada_Version = Ada_83
982 and then Nkind (Argx) = N_String_Literal
986 -- Static expression that raises Constraint_Error. This has
987 -- already been flagged, so just exit from pragma processing.
989 elsif Is_Static_Expression (Argx) then
992 -- Here we have a real error (non-static expression)
995 Error_Msg_Name_1 := Pname;
999 "argument for pragma% must be a identifier or "
1000 & "static string expression!";
1003 Flag_Non_Static_Expr (Msg, Argx);
1008 end Check_Arg_Is_External_Name;
1010 -----------------------------
1011 -- Check_Arg_Is_Identifier --
1012 -----------------------------
1014 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
1015 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1017 if Nkind (Argx) /= N_Identifier then
1019 ("argument for pragma% must be identifier", Argx);
1021 end Check_Arg_Is_Identifier;
1023 ----------------------------------
1024 -- Check_Arg_Is_Integer_Literal --
1025 ----------------------------------
1027 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1028 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1030 if Nkind (Argx) /= N_Integer_Literal then
1032 ("argument for pragma% must be integer literal", Argx);
1034 end Check_Arg_Is_Integer_Literal;
1036 -------------------------------------------
1037 -- Check_Arg_Is_Library_Level_Local_Name --
1038 -------------------------------------------
1042 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1043 -- | library_unit_NAME
1045 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1047 Check_Arg_Is_Local_Name (Arg);
1049 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1050 and then Comes_From_Source (N)
1053 ("argument for pragma% must be library level entity", Arg);
1055 end Check_Arg_Is_Library_Level_Local_Name;
1057 -----------------------------
1058 -- Check_Arg_Is_Local_Name --
1059 -----------------------------
1063 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1064 -- | library_unit_NAME
1066 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1067 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1072 if Nkind (Argx) not in N_Direct_Name
1073 and then (Nkind (Argx) /= N_Attribute_Reference
1074 or else Present (Expressions (Argx))
1075 or else Nkind (Prefix (Argx)) /= N_Identifier)
1076 and then (not Is_Entity_Name (Argx)
1077 or else not Is_Compilation_Unit (Entity (Argx)))
1079 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1082 -- No further check required if not an entity name
1084 if not Is_Entity_Name (Argx) then
1090 Ent : constant Entity_Id := Entity (Argx);
1091 Scop : constant Entity_Id := Scope (Ent);
1093 -- Case of a pragma applied to a compilation unit: pragma must
1094 -- occur immediately after the program unit in the compilation.
1096 if Is_Compilation_Unit (Ent) then
1098 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1101 -- Case of pragma placed immediately after spec
1103 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1106 -- Case of pragma placed immediately after body
1108 elsif Nkind (Decl) = N_Subprogram_Declaration
1109 and then Present (Corresponding_Body (Decl))
1113 (Parent (Unit_Declaration_Node
1114 (Corresponding_Body (Decl))));
1116 -- All other cases are illegal
1123 -- Special restricted placement rule from 10.2.1(11.8/2)
1125 elsif Is_Generic_Formal (Ent)
1126 and then Prag_Id = Pragma_Preelaborable_Initialization
1128 OK := List_Containing (N) =
1129 Generic_Formal_Declarations
1130 (Unit_Declaration_Node (Scop));
1132 -- Default case, just check that the pragma occurs in the scope
1133 -- of the entity denoted by the name.
1136 OK := Current_Scope = Scop;
1141 ("pragma% argument must be in same declarative part", Arg);
1145 end Check_Arg_Is_Local_Name;
1147 ---------------------------------
1148 -- Check_Arg_Is_Locking_Policy --
1149 ---------------------------------
1151 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1152 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1155 Check_Arg_Is_Identifier (Argx);
1157 if not Is_Locking_Policy_Name (Chars (Argx)) then
1158 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1160 end Check_Arg_Is_Locking_Policy;
1162 -------------------------
1163 -- Check_Arg_Is_One_Of --
1164 -------------------------
1166 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1167 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1170 Check_Arg_Is_Identifier (Argx);
1172 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1173 Error_Msg_Name_2 := N1;
1174 Error_Msg_Name_3 := N2;
1175 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1177 end Check_Arg_Is_One_Of;
1179 procedure Check_Arg_Is_One_Of
1181 N1, N2, N3 : Name_Id)
1183 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1186 Check_Arg_Is_Identifier (Argx);
1188 if Chars (Argx) /= N1
1189 and then Chars (Argx) /= N2
1190 and then Chars (Argx) /= N3
1192 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1194 end Check_Arg_Is_One_Of;
1196 procedure Check_Arg_Is_One_Of
1198 N1, N2, N3, N4 : Name_Id)
1200 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1203 Check_Arg_Is_Identifier (Argx);
1205 if Chars (Argx) /= N1
1206 and then Chars (Argx) /= N2
1207 and then Chars (Argx) /= N3
1208 and then Chars (Argx) /= N4
1210 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1212 end Check_Arg_Is_One_Of;
1214 procedure Check_Arg_Is_One_Of
1216 N1, N2, N3, N4, N5 : Name_Id)
1218 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1221 Check_Arg_Is_Identifier (Argx);
1223 if Chars (Argx) /= N1
1224 and then Chars (Argx) /= N2
1225 and then Chars (Argx) /= N3
1226 and then Chars (Argx) /= N4
1227 and then Chars (Argx) /= N5
1229 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1231 end Check_Arg_Is_One_Of;
1232 ---------------------------------
1233 -- Check_Arg_Is_Queuing_Policy --
1234 ---------------------------------
1236 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1237 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1240 Check_Arg_Is_Identifier (Argx);
1242 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1243 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1245 end Check_Arg_Is_Queuing_Policy;
1247 ------------------------------------
1248 -- Check_Arg_Is_Static_Expression --
1249 ------------------------------------
1251 procedure Check_Arg_Is_Static_Expression
1253 Typ : Entity_Id := Empty)
1256 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1257 end Check_Arg_Is_Static_Expression;
1259 ------------------------------------------
1260 -- Check_Arg_Is_Task_Dispatching_Policy --
1261 ------------------------------------------
1263 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1264 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1267 Check_Arg_Is_Identifier (Argx);
1269 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1271 ("& is not a valid task dispatching policy name", Argx);
1273 end Check_Arg_Is_Task_Dispatching_Policy;
1275 ---------------------
1276 -- Check_Arg_Order --
1277 ---------------------
1279 procedure Check_Arg_Order (Names : Name_List) is
1282 Highest_So_Far : Natural := 0;
1283 -- Highest index in Names seen do far
1287 for J in 1 .. Arg_Count loop
1288 if Chars (Arg) /= No_Name then
1289 for K in Names'Range loop
1290 if Chars (Arg) = Names (K) then
1291 if K < Highest_So_Far then
1292 Error_Msg_Name_1 := Pname;
1294 ("parameters out of order for pragma%", Arg);
1295 Error_Msg_Name_1 := Names (K);
1296 Error_Msg_Name_2 := Names (Highest_So_Far);
1297 Error_Msg_N ("\% must appear before %", Arg);
1301 Highest_So_Far := K;
1309 end Check_Arg_Order;
1311 --------------------------------
1312 -- Check_At_Least_N_Arguments --
1313 --------------------------------
1315 procedure Check_At_Least_N_Arguments (N : Nat) is
1317 if Arg_Count < N then
1318 Error_Pragma ("too few arguments for pragma%");
1320 end Check_At_Least_N_Arguments;
1322 -------------------------------
1323 -- Check_At_Most_N_Arguments --
1324 -------------------------------
1326 procedure Check_At_Most_N_Arguments (N : Nat) is
1329 if Arg_Count > N then
1331 for J in 1 .. N loop
1333 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1336 end Check_At_Most_N_Arguments;
1338 ---------------------
1339 -- Check_Component --
1340 ---------------------
1342 procedure Check_Component
1345 In_Variant_Part : Boolean := False)
1347 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1348 Sindic : constant Node_Id :=
1349 Subtype_Indication (Component_Definition (Comp));
1350 Typ : constant Entity_Id := Etype (Comp_Id);
1353 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1354 -- object constraint, then the component type shall be an Unchecked_
1357 if Nkind (Sindic) = N_Subtype_Indication
1358 and then Has_Per_Object_Constraint (Comp_Id)
1359 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1362 ("component subtype subject to per-object constraint " &
1363 "must be an Unchecked_Union", Comp);
1365 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1366 -- the body of a generic unit, or within the body of any of its
1367 -- descendant library units, no part of the type of a component
1368 -- declared in a variant_part of the unchecked union type shall be of
1369 -- a formal private type or formal private extension declared within
1370 -- the formal part of the generic unit.
1372 elsif Ada_Version >= Ada_2012
1373 and then In_Generic_Body (UU_Typ)
1374 and then In_Variant_Part
1375 and then Is_Private_Type (Typ)
1376 and then Is_Generic_Type (Typ)
1379 ("component of Unchecked_Union cannot be of generic type", Comp);
1381 elsif Needs_Finalization (Typ) then
1383 ("component of Unchecked_Union cannot be controlled", Comp);
1385 elsif Has_Task (Typ) then
1387 ("component of Unchecked_Union cannot have tasks", Comp);
1389 end Check_Component;
1391 ----------------------------
1392 -- Check_Duplicate_Pragma --
1393 ----------------------------
1395 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1399 -- Nothing to do if this pragma comes from an aspect specification,
1400 -- since we could not be duplicating a pragma, and we dealt with the
1401 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1403 if From_Aspect_Specification (N) then
1407 -- Otherwise current pragma may duplicate previous pragma or a
1408 -- previously given aspect specification for the same pragma.
1410 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1413 Error_Msg_Name_1 := Pragma_Name (N);
1414 Error_Msg_Sloc := Sloc (P);
1416 if Nkind (P) = N_Aspect_Specification
1417 or else From_Aspect_Specification (P)
1419 Error_Msg_NE ("aspect% for & previously given#", N, E);
1421 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1426 end Check_Duplicate_Pragma;
1428 ----------------------------------
1429 -- Check_Duplicated_Export_Name --
1430 ----------------------------------
1432 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1433 String_Val : constant String_Id := Strval (Nam);
1436 -- We are only interested in the export case, and in the case of
1437 -- generics, it is the instance, not the template, that is the
1438 -- problem (the template will generate a warning in any case).
1440 if not Inside_A_Generic
1441 and then (Prag_Id = Pragma_Export
1443 Prag_Id = Pragma_Export_Procedure
1445 Prag_Id = Pragma_Export_Valued_Procedure
1447 Prag_Id = Pragma_Export_Function)
1449 for J in Externals.First .. Externals.Last loop
1450 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1451 Error_Msg_Sloc := Sloc (Externals.Table (J));
1452 Error_Msg_N ("external name duplicates name given#", Nam);
1457 Externals.Append (Nam);
1459 end Check_Duplicated_Export_Name;
1461 -------------------------------------
1462 -- Check_Expr_Is_Static_Expression --
1463 -------------------------------------
1465 procedure Check_Expr_Is_Static_Expression
1467 Typ : Entity_Id := Empty)
1470 if Present (Typ) then
1471 Analyze_And_Resolve (Expr, Typ);
1473 Analyze_And_Resolve (Expr);
1476 if Is_OK_Static_Expression (Expr) then
1479 elsif Etype (Expr) = Any_Type then
1482 -- An interesting special case, if we have a string literal and we
1483 -- are in Ada 83 mode, then we allow it even though it will not be
1484 -- flagged as static. This allows the use of Ada 95 pragmas like
1485 -- Import in Ada 83 mode. They will of course be flagged with
1486 -- warnings as usual, but will not cause errors.
1488 elsif Ada_Version = Ada_83
1489 and then Nkind (Expr) = N_String_Literal
1493 -- Static expression that raises Constraint_Error. This has already
1494 -- been flagged, so just exit from pragma processing.
1496 elsif Is_Static_Expression (Expr) then
1499 -- Finally, we have a real error
1502 Error_Msg_Name_1 := Pname;
1506 "argument for pragma% must be a static expression!";
1509 Flag_Non_Static_Expr (Msg, Expr);
1514 end Check_Expr_Is_Static_Expression;
1516 -------------------------
1517 -- Check_First_Subtype --
1518 -------------------------
1520 procedure Check_First_Subtype (Arg : Node_Id) is
1521 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1522 Ent : constant Entity_Id := Entity (Argx);
1525 if Is_First_Subtype (Ent) then
1528 elsif Is_Type (Ent) then
1530 ("pragma% cannot apply to subtype", Argx);
1532 elsif Is_Object (Ent) then
1534 ("pragma% cannot apply to object, requires a type", Argx);
1538 ("pragma% cannot apply to&, requires a type", Argx);
1540 end Check_First_Subtype;
1542 ----------------------
1543 -- Check_Identifier --
1544 ----------------------
1546 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1549 and then Nkind (Arg) = N_Pragma_Argument_Association
1551 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1552 Error_Msg_Name_1 := Pname;
1553 Error_Msg_Name_2 := Id;
1554 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1558 end Check_Identifier;
1560 --------------------------------
1561 -- Check_Identifier_Is_One_Of --
1562 --------------------------------
1564 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1567 and then Nkind (Arg) = N_Pragma_Argument_Association
1569 if Chars (Arg) = No_Name then
1570 Error_Msg_Name_1 := Pname;
1571 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1574 elsif Chars (Arg) /= N1
1575 and then Chars (Arg) /= N2
1577 Error_Msg_Name_1 := Pname;
1578 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1582 end Check_Identifier_Is_One_Of;
1584 ---------------------------
1585 -- Check_In_Main_Program --
1586 ---------------------------
1588 procedure Check_In_Main_Program is
1589 P : constant Node_Id := Parent (N);
1592 -- Must be at in subprogram body
1594 if Nkind (P) /= N_Subprogram_Body then
1595 Error_Pragma ("% pragma allowed only in subprogram");
1597 -- Otherwise warn if obviously not main program
1599 elsif Present (Parameter_Specifications (Specification (P)))
1600 or else not Is_Compilation_Unit (Defining_Entity (P))
1602 Error_Msg_Name_1 := Pname;
1604 ("?pragma% is only effective in main program", N);
1606 end Check_In_Main_Program;
1608 ---------------------------------------
1609 -- Check_Interrupt_Or_Attach_Handler --
1610 ---------------------------------------
1612 procedure Check_Interrupt_Or_Attach_Handler is
1613 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1614 Handler_Proc, Proc_Scope : Entity_Id;
1619 if Prag_Id = Pragma_Interrupt_Handler then
1620 Check_Restriction (No_Dynamic_Attachment, N);
1623 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1624 Proc_Scope := Scope (Handler_Proc);
1626 -- On AAMP only, a pragma Interrupt_Handler is supported for
1627 -- nonprotected parameterless procedures.
1629 if not AAMP_On_Target
1630 or else Prag_Id = Pragma_Attach_Handler
1632 if Ekind (Proc_Scope) /= E_Protected_Type then
1634 ("argument of pragma% must be protected procedure", Arg1);
1637 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1638 Error_Pragma ("pragma% must be in protected definition");
1642 if not Is_Library_Level_Entity (Proc_Scope)
1643 or else (AAMP_On_Target
1644 and then not Is_Library_Level_Entity (Handler_Proc))
1647 ("argument for pragma% must be library level entity", Arg1);
1650 -- AI05-0033: A pragma cannot appear within a generic body, because
1651 -- instance can be in a nested scope. The check that protected type
1652 -- is itself a library-level declaration is done elsewhere.
1654 -- Note: we omit this check in Codepeer mode to properly handle code
1655 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1657 if Inside_A_Generic then
1658 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1659 and then In_Package_Body (Scope (Current_Scope))
1660 and then not CodePeer_Mode
1662 Error_Pragma ("pragma% cannot be used inside a generic");
1665 end Check_Interrupt_Or_Attach_Handler;
1667 -------------------------------------------
1668 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1669 -------------------------------------------
1671 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1680 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1683 elsif Nkind_In (P, N_Package_Specification,
1688 -- Note: the following tests seem a little peculiar, because
1689 -- they test for bodies, but if we were in the statement part
1690 -- of the body, we would already have hit the handled statement
1691 -- sequence, so the only way we get here is by being in the
1692 -- declarative part of the body.
1694 elsif Nkind_In (P, N_Subprogram_Body,
1705 Error_Pragma ("pragma% is not in declarative part or package spec");
1706 end Check_Is_In_Decl_Part_Or_Package_Spec;
1708 -------------------------
1709 -- Check_No_Identifier --
1710 -------------------------
1712 procedure Check_No_Identifier (Arg : Node_Id) is
1714 if Nkind (Arg) = N_Pragma_Argument_Association
1715 and then Chars (Arg) /= No_Name
1717 Error_Pragma_Arg_Ident
1718 ("pragma% does not permit identifier& here", Arg);
1720 end Check_No_Identifier;
1722 --------------------------
1723 -- Check_No_Identifiers --
1724 --------------------------
1726 procedure Check_No_Identifiers is
1729 if Arg_Count > 0 then
1731 while Present (Arg_Node) loop
1732 Check_No_Identifier (Arg_Node);
1736 end Check_No_Identifiers;
1738 ------------------------
1739 -- Check_No_Link_Name --
1740 ------------------------
1742 procedure Check_No_Link_Name is
1745 and then Chars (Arg3) = Name_Link_Name
1750 if Present (Arg4) then
1752 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1754 end Check_No_Link_Name;
1756 -------------------------------
1757 -- Check_Optional_Identifier --
1758 -------------------------------
1760 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1763 and then Nkind (Arg) = N_Pragma_Argument_Association
1764 and then Chars (Arg) /= No_Name
1766 if Chars (Arg) /= Id then
1767 Error_Msg_Name_1 := Pname;
1768 Error_Msg_Name_2 := Id;
1769 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1773 end Check_Optional_Identifier;
1775 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1777 Name_Buffer (1 .. Id'Length) := Id;
1778 Name_Len := Id'Length;
1779 Check_Optional_Identifier (Arg, Name_Find);
1780 end Check_Optional_Identifier;
1782 --------------------------------------
1783 -- Check_Precondition_Postcondition --
1784 --------------------------------------
1786 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1790 procedure Chain_PPC (PO : Node_Id);
1791 -- If PO is an entry or a [generic] subprogram declaration node, then
1792 -- the precondition/postcondition applies to this subprogram and the
1793 -- processing for the pragma is completed. Otherwise the pragma is
1800 procedure Chain_PPC (PO : Node_Id) is
1805 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1806 if not From_Aspect_Specification (N) then
1808 ("pragma% cannot be applied to abstract subprogram");
1810 elsif Class_Present (N) then
1815 ("aspect % requires ''Class for abstract subprogram");
1818 -- AI05-0230: The same restriction applies to null procedures. For
1819 -- compatibility with earlier uses of the Ada pragma, apply this
1820 -- rule only to aspect specifications.
1822 -- The above discrpency needs documentation. Robert is dubious
1823 -- about whether it is a good idea ???
1825 elsif Nkind (PO) = N_Subprogram_Declaration
1826 and then Nkind (Specification (PO)) = N_Procedure_Specification
1827 and then Null_Present (Specification (PO))
1828 and then From_Aspect_Specification (N)
1829 and then not Class_Present (N)
1832 ("aspect % requires ''Class for null procedure");
1834 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1835 N_Expression_Function,
1836 N_Generic_Subprogram_Declaration,
1837 N_Entry_Declaration)
1842 -- Here if we have [generic] subprogram or entry declaration
1844 if Nkind (PO) = N_Entry_Declaration then
1845 S := Defining_Entity (PO);
1847 S := Defining_Unit_Name (Specification (PO));
1850 -- Make sure we do not have the case of a precondition pragma when
1851 -- the Pre'Class aspect is present.
1853 -- We do this by looking at pragmas already chained to the entity
1854 -- since the aspect derived pragma will be put on this list first.
1856 if Pragma_Name (N) = Name_Precondition then
1857 if not From_Aspect_Specification (N) then
1858 P := Spec_PPC_List (Contract (S));
1859 while Present (P) loop
1860 if Pragma_Name (P) = Name_Precondition
1861 and then From_Aspect_Specification (P)
1862 and then Class_Present (P)
1864 Error_Msg_Sloc := Sloc (P);
1866 ("pragma% not allowed, `Pre''Class` aspect given#");
1869 P := Next_Pragma (P);
1874 -- Similarly check for Pre with inherited Pre'Class. Note that
1875 -- we cover the aspect case as well here.
1877 if Pragma_Name (N) = Name_Precondition
1878 and then not Class_Present (N)
1881 Inherited : constant Subprogram_List :=
1882 Inherited_Subprograms (S);
1886 for J in Inherited'Range loop
1887 P := Spec_PPC_List (Contract (Inherited (J)));
1888 while Present (P) loop
1889 if Pragma_Name (P) = Name_Precondition
1890 and then Class_Present (P)
1892 Error_Msg_Sloc := Sloc (P);
1894 ("pragma% not allowed, `Pre''Class` "
1895 & "aspect inherited from#");
1898 P := Next_Pragma (P);
1904 -- Note: we do not analyze the pragma at this point. Instead we
1905 -- delay this analysis until the end of the declarative part in
1906 -- which the pragma appears. This implements the required delay
1907 -- in this analysis, allowing forward references. The analysis
1908 -- happens at the end of Analyze_Declarations.
1910 -- Chain spec PPC pragma to list for subprogram
1912 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1913 Set_Spec_PPC_List (Contract (S), N);
1915 -- Return indicating spec case
1921 -- Start of processing for Check_Precondition_Postcondition
1924 if not Is_List_Member (N) then
1928 -- Preanalyze message argument if present. Visibility in this
1929 -- argument is established at the point of pragma occurrence.
1931 if Arg_Count = 2 then
1932 Check_Optional_Identifier (Arg2, Name_Message);
1933 Preanalyze_Spec_Expression
1934 (Get_Pragma_Arg (Arg2), Standard_String);
1937 -- Record if pragma is disabled
1939 if Check_Enabled (Pname) then
1940 Set_SCO_Pragma_Enabled (Loc);
1943 -- If we are within an inlined body, the legality of the pragma
1944 -- has been checked already.
1946 if In_Inlined_Body then
1951 -- Search prior declarations
1954 while Present (Prev (P)) loop
1957 -- If the previous node is a generic subprogram, do not go to to
1958 -- the original node, which is the unanalyzed tree: we need to
1959 -- attach the pre/postconditions to the analyzed version at this
1960 -- point. They get propagated to the original tree when analyzing
1961 -- the corresponding body.
1963 if Nkind (P) not in N_Generic_Declaration then
1964 PO := Original_Node (P);
1969 -- Skip past prior pragma
1971 if Nkind (PO) = N_Pragma then
1974 -- Skip stuff not coming from source
1976 elsif not Comes_From_Source (PO) then
1978 -- The condition may apply to a subprogram instantiation
1980 if Nkind (PO) = N_Subprogram_Declaration
1981 and then Present (Generic_Parent (Specification (PO)))
1986 elsif Nkind (PO) = N_Subprogram_Declaration
1987 and then In_Instance
1992 -- For all other cases of non source code, do nothing
1998 -- Only remaining possibility is subprogram declaration
2006 -- If we fall through loop, pragma is at start of list, so see if it
2007 -- is at the start of declarations of a subprogram body.
2009 if Nkind (Parent (N)) = N_Subprogram_Body
2010 and then List_Containing (N) = Declarations (Parent (N))
2012 if Operating_Mode /= Generate_Code
2013 or else Inside_A_Generic
2015 -- Analyze pragma expression for correctness and for ASIS use
2017 Preanalyze_Spec_Expression
2018 (Get_Pragma_Arg (Arg1), Standard_Boolean);
2020 -- In ASIS mode, for a pragma generated from a source aspect,
2021 -- also analyze the original aspect expression.
2024 and then Present (Corresponding_Aspect (N))
2026 Preanalyze_Spec_Expression
2027 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2034 -- See if it is in the pragmas after a library level subprogram
2036 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2038 -- In formal verification mode, analyze pragma expression for
2039 -- correctness, as it is not expanded later.
2042 Analyze_PPC_In_Decl_Part
2043 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2046 Chain_PPC (Unit (Parent (Parent (N))));
2050 -- If we fall through, pragma was misplaced
2053 end Check_Precondition_Postcondition;
2055 -----------------------------
2056 -- Check_Static_Constraint --
2057 -----------------------------
2059 -- Note: for convenience in writing this procedure, in addition to
2060 -- the officially (i.e. by spec) allowed argument which is always a
2061 -- constraint, it also allows ranges and discriminant associations.
2062 -- Above is not clear ???
2064 procedure Check_Static_Constraint (Constr : Node_Id) is
2066 procedure Require_Static (E : Node_Id);
2067 -- Require given expression to be static expression
2069 --------------------
2070 -- Require_Static --
2071 --------------------
2073 procedure Require_Static (E : Node_Id) is
2075 if not Is_OK_Static_Expression (E) then
2076 Flag_Non_Static_Expr
2077 ("non-static constraint not allowed in Unchecked_Union!", E);
2082 -- Start of processing for Check_Static_Constraint
2085 case Nkind (Constr) is
2086 when N_Discriminant_Association =>
2087 Require_Static (Expression (Constr));
2090 Require_Static (Low_Bound (Constr));
2091 Require_Static (High_Bound (Constr));
2093 when N_Attribute_Reference =>
2094 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2095 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2097 when N_Range_Constraint =>
2098 Check_Static_Constraint (Range_Expression (Constr));
2100 when N_Index_Or_Discriminant_Constraint =>
2104 IDC := First (Constraints (Constr));
2105 while Present (IDC) loop
2106 Check_Static_Constraint (IDC);
2114 end Check_Static_Constraint;
2116 ---------------------
2117 -- Check_Test_Case --
2118 ---------------------
2120 procedure Check_Test_Case is
2124 procedure Chain_TC (PO : Node_Id);
2125 -- If PO is a [generic] subprogram declaration node, then the
2126 -- test-case applies to this subprogram and the processing for the
2127 -- pragma is completed. Otherwise the pragma is misplaced.
2133 procedure Chain_TC (PO : Node_Id) is
2137 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2138 if From_Aspect_Specification (N) then
2140 ("aspect% cannot be applied to abstract subprogram");
2143 ("pragma% cannot be applied to abstract subprogram");
2146 elsif Nkind (PO) = N_Entry_Declaration then
2147 if From_Aspect_Specification (N) then
2148 Error_Pragma ("aspect% cannot be applied to entry");
2150 Error_Pragma ("pragma% cannot be applied to entry");
2153 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2154 N_Generic_Subprogram_Declaration)
2159 -- Here if we have [generic] subprogram declaration
2161 S := Defining_Unit_Name (Specification (PO));
2163 -- Note: we do not analyze the pragma at this point. Instead we
2164 -- delay this analysis until the end of the declarative part in
2165 -- which the pragma appears. This implements the required delay
2166 -- in this analysis, allowing forward references. The analysis
2167 -- happens at the end of Analyze_Declarations.
2169 -- There should not be another test case with the same name
2170 -- associated to this subprogram.
2173 Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2177 TC := Spec_TC_List (Contract (S));
2178 while Present (TC) loop
2181 (Name, Get_Name_From_Test_Case_Pragma (TC))
2183 Error_Msg_Sloc := Sloc (TC);
2185 if From_Aspect_Specification (N) then
2186 Error_Pragma ("name for aspect% is already used#");
2188 Error_Pragma ("name for pragma% is already used#");
2192 TC := Next_Pragma (TC);
2196 -- Chain spec TC pragma to list for subprogram
2198 Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2199 Set_Spec_TC_List (Contract (S), N);
2202 -- Start of processing for Check_Test_Case
2205 if not Is_List_Member (N) then
2209 -- Test cases should only appear in package spec unit
2211 if Get_Source_Unit (N) = No_Unit
2212 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2213 N_Package_Declaration,
2214 N_Generic_Package_Declaration)
2219 -- Search prior declarations
2222 while Present (Prev (P)) loop
2225 -- If the previous node is a generic subprogram, do not go to to
2226 -- the original node, which is the unanalyzed tree: we need to
2227 -- attach the test-case to the analyzed version at this point.
2228 -- They get propagated to the original tree when analyzing the
2229 -- corresponding body.
2231 if Nkind (P) not in N_Generic_Declaration then
2232 PO := Original_Node (P);
2237 -- Skip past prior pragma
2239 if Nkind (PO) = N_Pragma then
2242 -- Skip stuff not coming from source
2244 elsif not Comes_From_Source (PO) then
2247 -- Only remaining possibility is subprogram declaration. First
2248 -- check that it is declared directly in a package declaration.
2249 -- This may be either the package declaration for the current unit
2250 -- being defined or a local package declaration.
2252 elsif not Present (Parent (Parent (PO)))
2253 or else not Present (Parent (Parent (Parent (PO))))
2254 or else not Nkind_In (Parent (Parent (PO)),
2255 N_Package_Declaration,
2256 N_Generic_Package_Declaration)
2266 -- If we fall through, pragma was misplaced
2269 end Check_Test_Case;
2271 --------------------------------------
2272 -- Check_Valid_Configuration_Pragma --
2273 --------------------------------------
2275 -- A configuration pragma must appear in the context clause of a
2276 -- compilation unit, and only other pragmas may precede it. Note that
2277 -- the test also allows use in a configuration pragma file.
2279 procedure Check_Valid_Configuration_Pragma is
2281 if not Is_Configuration_Pragma then
2282 Error_Pragma ("incorrect placement for configuration pragma%");
2284 end Check_Valid_Configuration_Pragma;
2286 -------------------------------------
2287 -- Check_Valid_Library_Unit_Pragma --
2288 -------------------------------------
2290 procedure Check_Valid_Library_Unit_Pragma is
2292 Parent_Node : Node_Id;
2293 Unit_Name : Entity_Id;
2294 Unit_Kind : Node_Kind;
2295 Unit_Node : Node_Id;
2296 Sindex : Source_File_Index;
2299 if not Is_List_Member (N) then
2303 Plist := List_Containing (N);
2304 Parent_Node := Parent (Plist);
2306 if Parent_Node = Empty then
2309 -- Case of pragma appearing after a compilation unit. In this case
2310 -- it must have an argument with the corresponding name and must
2311 -- be part of the following pragmas of its parent.
2313 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2314 if Plist /= Pragmas_After (Parent_Node) then
2317 elsif Arg_Count = 0 then
2319 ("argument required if outside compilation unit");
2322 Check_No_Identifiers;
2323 Check_Arg_Count (1);
2324 Unit_Node := Unit (Parent (Parent_Node));
2325 Unit_Kind := Nkind (Unit_Node);
2327 Analyze (Get_Pragma_Arg (Arg1));
2329 if Unit_Kind = N_Generic_Subprogram_Declaration
2330 or else Unit_Kind = N_Subprogram_Declaration
2332 Unit_Name := Defining_Entity (Unit_Node);
2334 elsif Unit_Kind in N_Generic_Instantiation then
2335 Unit_Name := Defining_Entity (Unit_Node);
2338 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2341 if Chars (Unit_Name) /=
2342 Chars (Entity (Get_Pragma_Arg (Arg1)))
2345 ("pragma% argument is not current unit name", Arg1);
2348 if Ekind (Unit_Name) = E_Package
2349 and then Present (Renamed_Entity (Unit_Name))
2351 Error_Pragma ("pragma% not allowed for renamed package");
2355 -- Pragma appears other than after a compilation unit
2358 -- Here we check for the generic instantiation case and also
2359 -- for the case of processing a generic formal package. We
2360 -- detect these cases by noting that the Sloc on the node
2361 -- does not belong to the current compilation unit.
2363 Sindex := Source_Index (Current_Sem_Unit);
2365 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2366 Rewrite (N, Make_Null_Statement (Loc));
2369 -- If before first declaration, the pragma applies to the
2370 -- enclosing unit, and the name if present must be this name.
2372 elsif Is_Before_First_Decl (N, Plist) then
2373 Unit_Node := Unit_Declaration_Node (Current_Scope);
2374 Unit_Kind := Nkind (Unit_Node);
2376 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2379 elsif Unit_Kind = N_Subprogram_Body
2380 and then not Acts_As_Spec (Unit_Node)
2384 elsif Nkind (Parent_Node) = N_Package_Body then
2387 elsif Nkind (Parent_Node) = N_Package_Specification
2388 and then Plist = Private_Declarations (Parent_Node)
2392 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2393 or else Nkind (Parent_Node) =
2394 N_Generic_Subprogram_Declaration)
2395 and then Plist = Generic_Formal_Declarations (Parent_Node)
2399 elsif Arg_Count > 0 then
2400 Analyze (Get_Pragma_Arg (Arg1));
2402 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2404 ("name in pragma% must be enclosing unit", Arg1);
2407 -- It is legal to have no argument in this context
2413 -- Error if not before first declaration. This is because a
2414 -- library unit pragma argument must be the name of a library
2415 -- unit (RM 10.1.5(7)), but the only names permitted in this
2416 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2417 -- generic subprogram declarations or generic instantiations.
2421 ("pragma% misplaced, must be before first declaration");
2425 end Check_Valid_Library_Unit_Pragma;
2431 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2432 Clist : constant Node_Id := Component_List (Variant);
2436 if not Is_Non_Empty_List (Component_Items (Clist)) then
2438 ("Unchecked_Union may not have empty component list",
2443 Comp := First (Component_Items (Clist));
2444 while Present (Comp) loop
2445 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2454 procedure Error_Pragma (Msg : String) is
2455 MsgF : String := Msg;
2457 Error_Msg_Name_1 := Pname;
2459 Error_Msg_N (MsgF, N);
2463 ----------------------
2464 -- Error_Pragma_Arg --
2465 ----------------------
2467 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2468 MsgF : String := Msg;
2470 Error_Msg_Name_1 := Pname;
2472 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2474 end Error_Pragma_Arg;
2476 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2477 MsgF : String := Msg1;
2479 Error_Msg_Name_1 := Pname;
2481 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2482 Error_Pragma_Arg (Msg2, Arg);
2483 end Error_Pragma_Arg;
2485 ----------------------------
2486 -- Error_Pragma_Arg_Ident --
2487 ----------------------------
2489 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2490 MsgF : String := Msg;
2492 Error_Msg_Name_1 := Pname;
2494 Error_Msg_N (MsgF, Arg);
2496 end Error_Pragma_Arg_Ident;
2498 ----------------------
2499 -- Error_Pragma_Ref --
2500 ----------------------
2502 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2503 MsgF : String := Msg;
2505 Error_Msg_Name_1 := Pname;
2507 Error_Msg_Sloc := Sloc (Ref);
2508 Error_Msg_NE (MsgF, N, Ref);
2510 end Error_Pragma_Ref;
2512 ------------------------
2513 -- Find_Lib_Unit_Name --
2514 ------------------------
2516 function Find_Lib_Unit_Name return Entity_Id is
2518 -- Return inner compilation unit entity, for case of nested
2519 -- categorization pragmas. This happens in generic unit.
2521 if Nkind (Parent (N)) = N_Package_Specification
2522 and then Defining_Entity (Parent (N)) /= Current_Scope
2524 return Defining_Entity (Parent (N));
2526 return Current_Scope;
2528 end Find_Lib_Unit_Name;
2530 ----------------------------
2531 -- Find_Program_Unit_Name --
2532 ----------------------------
2534 procedure Find_Program_Unit_Name (Id : Node_Id) is
2535 Unit_Name : Entity_Id;
2536 Unit_Kind : Node_Kind;
2537 P : constant Node_Id := Parent (N);
2540 if Nkind (P) = N_Compilation_Unit then
2541 Unit_Kind := Nkind (Unit (P));
2543 if Unit_Kind = N_Subprogram_Declaration
2544 or else Unit_Kind = N_Package_Declaration
2545 or else Unit_Kind in N_Generic_Declaration
2547 Unit_Name := Defining_Entity (Unit (P));
2549 if Chars (Id) = Chars (Unit_Name) then
2550 Set_Entity (Id, Unit_Name);
2551 Set_Etype (Id, Etype (Unit_Name));
2553 Set_Etype (Id, Any_Type);
2555 ("cannot find program unit referenced by pragma%");
2559 Set_Etype (Id, Any_Type);
2560 Error_Pragma ("pragma% inapplicable to this unit");
2566 end Find_Program_Unit_Name;
2568 -----------------------------------------
2569 -- Find_Unique_Parameterless_Procedure --
2570 -----------------------------------------
2572 function Find_Unique_Parameterless_Procedure
2574 Arg : Node_Id) return Entity_Id
2576 Proc : Entity_Id := Empty;
2579 -- The body of this procedure needs some comments ???
2581 if not Is_Entity_Name (Name) then
2583 ("argument of pragma% must be entity name", Arg);
2585 elsif not Is_Overloaded (Name) then
2586 Proc := Entity (Name);
2588 if Ekind (Proc) /= E_Procedure
2589 or else Present (First_Formal (Proc))
2592 ("argument of pragma% must be parameterless procedure", Arg);
2597 Found : Boolean := False;
2599 Index : Interp_Index;
2602 Get_First_Interp (Name, Index, It);
2603 while Present (It.Nam) loop
2606 if Ekind (Proc) = E_Procedure
2607 and then No (First_Formal (Proc))
2611 Set_Entity (Name, Proc);
2612 Set_Is_Overloaded (Name, False);
2615 ("ambiguous handler name for pragma% ", Arg);
2619 Get_Next_Interp (Index, It);
2624 ("argument of pragma% must be parameterless procedure",
2627 Proc := Entity (Name);
2633 end Find_Unique_Parameterless_Procedure;
2639 procedure Fix_Error (Msg : in out String) is
2641 if From_Aspect_Specification (N) then
2642 for J in Msg'First .. Msg'Last - 5 loop
2643 if Msg (J .. J + 5) = "pragma" then
2644 Msg (J .. J + 5) := "aspect";
2648 if Error_Msg_Name_1 = Name_Precondition then
2649 Error_Msg_Name_1 := Name_Pre;
2650 elsif Error_Msg_Name_1 = Name_Postcondition then
2651 Error_Msg_Name_1 := Name_Post;
2656 -------------------------
2657 -- Gather_Associations --
2658 -------------------------
2660 procedure Gather_Associations
2662 Args : out Args_List)
2667 -- Initialize all parameters to Empty
2669 for J in Args'Range loop
2673 -- That's all we have to do if there are no argument associations
2675 if No (Pragma_Argument_Associations (N)) then
2679 -- Otherwise first deal with any positional parameters present
2681 Arg := First (Pragma_Argument_Associations (N));
2682 for Index in Args'Range loop
2683 exit when No (Arg) or else Chars (Arg) /= No_Name;
2684 Args (Index) := Get_Pragma_Arg (Arg);
2688 -- Positional parameters all processed, if any left, then we
2689 -- have too many positional parameters.
2691 if Present (Arg) and then Chars (Arg) = No_Name then
2693 ("too many positional associations for pragma%", Arg);
2696 -- Process named parameters if any are present
2698 while Present (Arg) loop
2699 if Chars (Arg) = No_Name then
2701 ("positional association cannot follow named association",
2705 for Index in Names'Range loop
2706 if Names (Index) = Chars (Arg) then
2707 if Present (Args (Index)) then
2709 ("duplicate argument association for pragma%", Arg);
2711 Args (Index) := Get_Pragma_Arg (Arg);
2716 if Index = Names'Last then
2717 Error_Msg_Name_1 := Pname;
2718 Error_Msg_N ("pragma% does not allow & argument", Arg);
2720 -- Check for possible misspelling
2722 for Index1 in Names'Range loop
2723 if Is_Bad_Spelling_Of
2724 (Chars (Arg), Names (Index1))
2726 Error_Msg_Name_1 := Names (Index1);
2727 Error_Msg_N -- CODEFIX
2728 ("\possible misspelling of%", Arg);
2740 end Gather_Associations;
2746 procedure GNAT_Pragma is
2748 -- We need to check the No_Implementation_Pragmas restriction for
2749 -- the case of a pragma from source. Note that the case of aspects
2750 -- generating corresponding pragmas marks these pragmas as not being
2751 -- from source, so this test also catches that case.
2753 if Comes_From_Source (N) then
2754 Check_Restriction (No_Implementation_Pragmas, N);
2758 --------------------------
2759 -- Is_Before_First_Decl --
2760 --------------------------
2762 function Is_Before_First_Decl
2763 (Pragma_Node : Node_Id;
2764 Decls : List_Id) return Boolean
2766 Item : Node_Id := First (Decls);
2769 -- Only other pragmas can come before this pragma
2772 if No (Item) or else Nkind (Item) /= N_Pragma then
2775 elsif Item = Pragma_Node then
2781 end Is_Before_First_Decl;
2783 -----------------------------
2784 -- Is_Configuration_Pragma --
2785 -----------------------------
2787 -- A configuration pragma must appear in the context clause of a
2788 -- compilation unit, and only other pragmas may precede it. Note that
2789 -- the test below also permits use in a configuration pragma file.
2791 function Is_Configuration_Pragma return Boolean is
2792 Lis : constant List_Id := List_Containing (N);
2793 Par : constant Node_Id := Parent (N);
2797 -- If no parent, then we are in the configuration pragma file,
2798 -- so the placement is definitely appropriate.
2803 -- Otherwise we must be in the context clause of a compilation unit
2804 -- and the only thing allowed before us in the context list is more
2805 -- configuration pragmas.
2807 elsif Nkind (Par) = N_Compilation_Unit
2808 and then Context_Items (Par) = Lis
2815 elsif Nkind (Prg) /= N_Pragma then
2825 end Is_Configuration_Pragma;
2827 --------------------------
2828 -- Is_In_Context_Clause --
2829 --------------------------
2831 function Is_In_Context_Clause return Boolean is
2833 Parent_Node : Node_Id;
2836 if not Is_List_Member (N) then
2840 Plist := List_Containing (N);
2841 Parent_Node := Parent (Plist);
2843 if Parent_Node = Empty
2844 or else Nkind (Parent_Node) /= N_Compilation_Unit
2845 or else Context_Items (Parent_Node) /= Plist
2852 end Is_In_Context_Clause;
2854 ---------------------------------
2855 -- Is_Static_String_Expression --
2856 ---------------------------------
2858 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2859 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2862 Analyze_And_Resolve (Argx);
2863 return Is_OK_Static_Expression (Argx)
2864 and then Nkind (Argx) = N_String_Literal;
2865 end Is_Static_String_Expression;
2867 ----------------------
2868 -- Pragma_Misplaced --
2869 ----------------------
2871 procedure Pragma_Misplaced is
2873 Error_Pragma ("incorrect placement of pragma%");
2874 end Pragma_Misplaced;
2876 ------------------------------------
2877 -- Process Atomic_Shared_Volatile --
2878 ------------------------------------
2880 procedure Process_Atomic_Shared_Volatile is
2887 procedure Set_Atomic (E : Entity_Id);
2888 -- Set given type as atomic, and if no explicit alignment was given,
2889 -- set alignment to unknown, since back end knows what the alignment
2890 -- requirements are for atomic arrays. Note: this step is necessary
2891 -- for derived types.
2897 procedure Set_Atomic (E : Entity_Id) is
2901 if not Has_Alignment_Clause (E) then
2902 Set_Alignment (E, Uint_0);
2906 -- Start of processing for Process_Atomic_Shared_Volatile
2909 Check_Ada_83_Warning;
2910 Check_No_Identifiers;
2911 Check_Arg_Count (1);
2912 Check_Arg_Is_Local_Name (Arg1);
2913 E_Id := Get_Pragma_Arg (Arg1);
2915 if Etype (E_Id) = Any_Type then
2920 D := Declaration_Node (E);
2923 -- Check duplicate before we chain ourselves!
2925 Check_Duplicate_Pragma (E);
2927 -- Now check appropriateness of the entity
2930 if Rep_Item_Too_Early (E, N)
2932 Rep_Item_Too_Late (E, N)
2936 Check_First_Subtype (Arg1);
2939 if Prag_Id /= Pragma_Volatile then
2941 Set_Atomic (Underlying_Type (E));
2942 Set_Atomic (Base_Type (E));
2945 -- Attribute belongs on the base type. If the view of the type is
2946 -- currently private, it also belongs on the underlying type.
2948 Set_Is_Volatile (Base_Type (E));
2949 Set_Is_Volatile (Underlying_Type (E));
2951 Set_Treat_As_Volatile (E);
2952 Set_Treat_As_Volatile (Underlying_Type (E));
2954 elsif K = N_Object_Declaration
2955 or else (K = N_Component_Declaration
2956 and then Original_Record_Component (E) = E)
2958 if Rep_Item_Too_Late (E, N) then
2962 if Prag_Id /= Pragma_Volatile then
2965 -- If the object declaration has an explicit initialization, a
2966 -- temporary may have to be created to hold the expression, to
2967 -- ensure that access to the object remain atomic.
2969 if Nkind (Parent (E)) = N_Object_Declaration
2970 and then Present (Expression (Parent (E)))
2972 Set_Has_Delayed_Freeze (E);
2975 -- An interesting improvement here. If an object of type X is
2976 -- declared atomic, and the type X is not atomic, that's a
2977 -- pity, since it may not have appropriate alignment etc. We
2978 -- can rescue this in the special case where the object and
2979 -- type are in the same unit by just setting the type as
2980 -- atomic, so that the back end will process it as atomic.
2982 Utyp := Underlying_Type (Etype (E));
2985 and then Sloc (E) > No_Location
2986 and then Sloc (Utyp) > No_Location
2988 Get_Source_File_Index (Sloc (E)) =
2989 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2991 Set_Is_Atomic (Underlying_Type (Etype (E)));
2995 Set_Is_Volatile (E);
2996 Set_Treat_As_Volatile (E);
3000 ("inappropriate entity for pragma%", Arg1);
3002 end Process_Atomic_Shared_Volatile;
3004 -------------------------------------------
3005 -- Process_Compile_Time_Warning_Or_Error --
3006 -------------------------------------------
3008 procedure Process_Compile_Time_Warning_Or_Error is
3009 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
3012 Check_Arg_Count (2);
3013 Check_No_Identifiers;
3014 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3015 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3017 if Compile_Time_Known_Value (Arg1x) then
3018 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3020 Str : constant String_Id :=
3021 Strval (Get_Pragma_Arg (Arg2));
3022 Len : constant Int := String_Length (Str);
3027 Cent : constant Entity_Id :=
3028 Cunit_Entity (Current_Sem_Unit);
3030 Force : constant Boolean :=
3031 Prag_Id = Pragma_Compile_Time_Warning
3033 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3034 and then (Ekind (Cent) /= E_Package
3035 or else not In_Private_Part (Cent));
3036 -- Set True if this is the warning case, and we are in the
3037 -- visible part of a package spec, or in a subprogram spec,
3038 -- in which case we want to force the client to see the
3039 -- warning, even though it is not in the main unit.
3042 -- Loop through segments of message separated by line feeds.
3043 -- We output these segments as separate messages with
3044 -- continuation marks for all but the first.
3049 Error_Msg_Strlen := 0;
3051 -- Loop to copy characters from argument to error message
3055 exit when Ptr > Len;
3056 CC := Get_String_Char (Str, Ptr);
3059 -- Ignore wide chars ??? else store character
3061 if In_Character_Range (CC) then
3062 C := Get_Character (CC);
3063 exit when C = ASCII.LF;
3064 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3065 Error_Msg_String (Error_Msg_Strlen) := C;
3069 -- Here with one line ready to go
3071 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3073 -- If this is a warning in a spec, then we want clients
3074 -- to see the warning, so mark the message with the
3075 -- special sequence !! to force the warning. In the case
3076 -- of a package spec, we do not force this if we are in
3077 -- the private part of the spec.
3080 if Cont = False then
3081 Error_Msg_N ("<~!!", Arg1);
3084 Error_Msg_N ("\<~!!", Arg1);
3087 -- Error, rather than warning, or in a body, so we do not
3088 -- need to force visibility for client (error will be
3089 -- output in any case, and this is the situation in which
3090 -- we do not want a client to get a warning, since the
3091 -- warning is in the body or the spec private part).
3094 if Cont = False then
3095 Error_Msg_N ("<~", Arg1);
3098 Error_Msg_N ("\<~", Arg1);
3102 exit when Ptr > Len;
3107 end Process_Compile_Time_Warning_Or_Error;
3109 ------------------------
3110 -- Process_Convention --
3111 ------------------------
3113 procedure Process_Convention
3114 (C : out Convention_Id;
3115 Ent : out Entity_Id)
3121 Comp_Unit : Unit_Number_Type;
3123 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3124 -- Called if we have more than one Export/Import/Convention pragma.
3125 -- This is generally illegal, but we have a special case of allowing
3126 -- Import and Interface to coexist if they specify the convention in
3127 -- a consistent manner. We are allowed to do this, since Interface is
3128 -- an implementation defined pragma, and we choose to do it since we
3129 -- know Rational allows this combination. S is the entity id of the
3130 -- subprogram in question. This procedure also sets the special flag
3131 -- Import_Interface_Present in both pragmas in the case where we do
3132 -- have matching Import and Interface pragmas.
3134 procedure Set_Convention_From_Pragma (E : Entity_Id);
3135 -- Set convention in entity E, and also flag that the entity has a
3136 -- convention pragma. If entity is for a private or incomplete type,
3137 -- also set convention and flag on underlying type. This procedure
3138 -- also deals with the special case of C_Pass_By_Copy convention.
3140 -------------------------------
3141 -- Diagnose_Multiple_Pragmas --
3142 -------------------------------
3144 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3145 Pdec : constant Node_Id := Declaration_Node (S);
3149 function Same_Convention (Decl : Node_Id) return Boolean;
3150 -- Decl is a pragma node. This function returns True if this
3151 -- pragma has a first argument that is an identifier with a
3152 -- Chars field corresponding to the Convention_Id C.
3154 function Same_Name (Decl : Node_Id) return Boolean;
3155 -- Decl is a pragma node. This function returns True if this
3156 -- pragma has a second argument that is an identifier with a
3157 -- Chars field that matches the Chars of the current subprogram.
3159 ---------------------
3160 -- Same_Convention --
3161 ---------------------
3163 function Same_Convention (Decl : Node_Id) return Boolean is
3164 Arg1 : constant Node_Id :=
3165 First (Pragma_Argument_Associations (Decl));
3168 if Present (Arg1) then
3170 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3172 if Nkind (Arg) = N_Identifier
3173 and then Is_Convention_Name (Chars (Arg))
3174 and then Get_Convention_Id (Chars (Arg)) = C
3182 end Same_Convention;
3188 function Same_Name (Decl : Node_Id) return Boolean is
3189 Arg1 : constant Node_Id :=
3190 First (Pragma_Argument_Associations (Decl));
3198 Arg2 := Next (Arg1);
3205 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3207 if Nkind (Arg) = N_Identifier
3208 and then Chars (Arg) = Chars (S)
3217 -- Start of processing for Diagnose_Multiple_Pragmas
3222 -- Definitely give message if we have Convention/Export here
3224 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3227 -- If we have an Import or Export, scan back from pragma to
3228 -- find any previous pragma applying to the same procedure.
3229 -- The scan will be terminated by the start of the list, or
3230 -- hitting the subprogram declaration. This won't allow one
3231 -- pragma to appear in the public part and one in the private
3232 -- part, but that seems very unlikely in practice.
3236 while Present (Decl) and then Decl /= Pdec loop
3238 -- Look for pragma with same name as us
3240 if Nkind (Decl) = N_Pragma
3241 and then Same_Name (Decl)
3243 -- Give error if same as our pragma or Export/Convention
3245 if Pragma_Name (Decl) = Name_Export
3247 Pragma_Name (Decl) = Name_Convention
3249 Pragma_Name (Decl) = Pragma_Name (N)
3253 -- Case of Import/Interface or the other way round
3255 elsif Pragma_Name (Decl) = Name_Interface
3257 Pragma_Name (Decl) = Name_Import
3259 -- Here we know that we have Import and Interface. It
3260 -- doesn't matter which way round they are. See if
3261 -- they specify the same convention. If so, all OK,
3262 -- and set special flags to stop other messages
3264 if Same_Convention (Decl) then
3265 Set_Import_Interface_Present (N);
3266 Set_Import_Interface_Present (Decl);
3269 -- If different conventions, special message
3272 Error_Msg_Sloc := Sloc (Decl);
3274 ("convention differs from that given#", Arg1);
3284 -- Give message if needed if we fall through those tests
3288 ("at most one Convention/Export/Import pragma is allowed",
3291 end Diagnose_Multiple_Pragmas;
3293 --------------------------------
3294 -- Set_Convention_From_Pragma --
3295 --------------------------------
3297 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3299 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3300 -- for an overridden dispatching operation. Technically this is
3301 -- an amendment and should only be done in Ada 2005 mode. However,
3302 -- this is clearly a mistake, since the problem that is addressed
3303 -- by this AI is that there is a clear gap in the RM!
3305 if Is_Dispatching_Operation (E)
3306 and then Present (Overridden_Operation (E))
3307 and then C /= Convention (Overridden_Operation (E))
3310 ("cannot change convention for " &
3311 "overridden dispatching operation",
3315 -- Set the convention
3317 Set_Convention (E, C);
3318 Set_Has_Convention_Pragma (E);
3320 if Is_Incomplete_Or_Private_Type (E)
3321 and then Present (Underlying_Type (E))
3323 Set_Convention (Underlying_Type (E), C);
3324 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3327 -- A class-wide type should inherit the convention of the specific
3328 -- root type (although this isn't specified clearly by the RM).
3330 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3331 Set_Convention (Class_Wide_Type (E), C);
3334 -- If the entity is a record type, then check for special case of
3335 -- C_Pass_By_Copy, which is treated the same as C except that the
3336 -- special record flag is set. This convention is only permitted
3337 -- on record types (see AI95-00131).
3339 if Cname = Name_C_Pass_By_Copy then
3340 if Is_Record_Type (E) then
3341 Set_C_Pass_By_Copy (Base_Type (E));
3342 elsif Is_Incomplete_Or_Private_Type (E)
3343 and then Is_Record_Type (Underlying_Type (E))
3345 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3348 ("C_Pass_By_Copy convention allowed only for record type",
3353 -- If the entity is a derived boolean type, check for the special
3354 -- case of convention C, C++, or Fortran, where we consider any
3355 -- nonzero value to represent true.
3357 if Is_Discrete_Type (E)
3358 and then Root_Type (Etype (E)) = Standard_Boolean
3364 C = Convention_Fortran)
3366 Set_Nonzero_Is_True (Base_Type (E));
3368 end Set_Convention_From_Pragma;
3370 -- Start of processing for Process_Convention
3373 Check_At_Least_N_Arguments (2);
3374 Check_Optional_Identifier (Arg1, Name_Convention);
3375 Check_Arg_Is_Identifier (Arg1);
3376 Cname := Chars (Get_Pragma_Arg (Arg1));
3378 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3379 -- tested again below to set the critical flag).
3381 if Cname = Name_C_Pass_By_Copy then
3384 -- Otherwise we must have something in the standard convention list
3386 elsif Is_Convention_Name (Cname) then
3387 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3389 -- In DEC VMS, it seems that there is an undocumented feature that
3390 -- any unrecognized convention is treated as the default, which for
3391 -- us is convention C. It does not seem so terrible to do this
3392 -- unconditionally, silently in the VMS case, and with a warning
3393 -- in the non-VMS case.
3396 if Warn_On_Export_Import and not OpenVMS_On_Target then
3398 ("?unrecognized convention name, C assumed",
3399 Get_Pragma_Arg (Arg1));
3405 Check_Optional_Identifier (Arg2, Name_Entity);
3406 Check_Arg_Is_Local_Name (Arg2);
3408 Id := Get_Pragma_Arg (Arg2);
3411 if not Is_Entity_Name (Id) then
3412 Error_Pragma_Arg ("entity name required", Arg2);
3417 -- Set entity to return
3421 -- Ada_Pass_By_Copy special checking
3423 if C = Convention_Ada_Pass_By_Copy then
3424 if not Is_First_Subtype (E) then
3426 ("convention `Ada_Pass_By_Copy` only "
3427 & "allowed for types", Arg2);
3430 if Is_By_Reference_Type (E) then
3432 ("convention `Ada_Pass_By_Copy` not allowed for "
3433 & "by-reference type", Arg1);
3437 -- Ada_Pass_By_Reference special checking
3439 if C = Convention_Ada_Pass_By_Reference then
3440 if not Is_First_Subtype (E) then
3442 ("convention `Ada_Pass_By_Reference` only "
3443 & "allowed for types", Arg2);
3446 if Is_By_Copy_Type (E) then
3448 ("convention `Ada_Pass_By_Reference` not allowed for "
3449 & "by-copy type", Arg1);
3453 -- Go to renamed subprogram if present, since convention applies to
3454 -- the actual renamed entity, not to the renaming entity. If the
3455 -- subprogram is inherited, go to parent subprogram.
3457 if Is_Subprogram (E)
3458 and then Present (Alias (E))
3460 if Nkind (Parent (Declaration_Node (E))) =
3461 N_Subprogram_Renaming_Declaration
3463 if Scope (E) /= Scope (Alias (E)) then
3465 ("cannot apply pragma% to non-local entity&#", E);
3470 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3471 N_Private_Extension_Declaration)
3472 and then Scope (E) = Scope (Alias (E))
3476 -- Return the parent subprogram the entity was inherited from
3482 -- Check that we are not applying this to a specless body
3484 if Is_Subprogram (E)
3485 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3488 ("pragma% requires separate spec and must come before body");
3491 -- Check that we are not applying this to a named constant
3493 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3494 Error_Msg_Name_1 := Pname;
3496 ("cannot apply pragma% to named constant!",
3497 Get_Pragma_Arg (Arg2));
3499 ("\supply appropriate type for&!", Arg2);
3502 if Ekind (E) = E_Enumeration_Literal then
3503 Error_Pragma ("enumeration literal not allowed for pragma%");
3506 -- Check for rep item appearing too early or too late
3508 if Etype (E) = Any_Type
3509 or else Rep_Item_Too_Early (E, N)
3513 elsif Present (Underlying_Type (E)) then
3514 E := Underlying_Type (E);
3517 if Rep_Item_Too_Late (E, N) then
3521 if Has_Convention_Pragma (E) then
3522 Diagnose_Multiple_Pragmas (E);
3524 elsif Convention (E) = Convention_Protected
3525 or else Ekind (Scope (E)) = E_Protected_Type
3528 ("a protected operation cannot be given a different convention",
3532 -- For Intrinsic, a subprogram is required
3534 if C = Convention_Intrinsic
3535 and then not Is_Subprogram (E)
3536 and then not Is_Generic_Subprogram (E)
3539 ("second argument of pragma% must be a subprogram", Arg2);
3544 if C = Convention_Stdcall then
3546 -- A dispatching call is not allowed. A dispatching subprogram
3547 -- cannot be used to interface to the Win32 API, so in fact this
3548 -- check does not impose any effective restriction.
3550 if Is_Dispatching_Operation (E) then
3553 ("dispatching subprograms cannot use Stdcall convention");
3555 -- Subprogram is allowed, but not a generic subprogram, and not a
3556 -- dispatching operation.
3558 elsif not Is_Subprogram (E)
3559 and then not Is_Generic_Subprogram (E)
3563 and then Ekind (E) /= E_Variable
3565 -- An access to subprogram is also allowed
3569 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3572 ("second argument of pragma% must be subprogram (type)",
3577 if not Is_Subprogram (E)
3578 and then not Is_Generic_Subprogram (E)
3580 Set_Convention_From_Pragma (E);
3583 Check_First_Subtype (Arg2);
3584 Set_Convention_From_Pragma (Base_Type (E));
3586 -- For subprograms, we must set the convention on the
3587 -- internally generated directly designated type as well.
3589 if Ekind (E) = E_Access_Subprogram_Type then
3590 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3594 -- For the subprogram case, set proper convention for all homonyms
3595 -- in same scope and the same declarative part, i.e. the same
3596 -- compilation unit.
3599 Comp_Unit := Get_Source_Unit (E);
3600 Set_Convention_From_Pragma (E);
3602 -- Treat a pragma Import as an implicit body, for GPS use
3604 if Prag_Id = Pragma_Import then
3605 Generate_Reference (E, Id, 'b');
3608 -- Loop through the homonyms of the pragma argument's entity
3613 exit when No (E1) or else Scope (E1) /= Current_Scope;
3615 -- Do not set the pragma on inherited operations or on formal
3618 if Comes_From_Source (E1)
3619 and then Comp_Unit = Get_Source_Unit (E1)
3620 and then not Is_Formal_Subprogram (E1)
3621 and then Nkind (Original_Node (Parent (E1))) /=
3622 N_Full_Type_Declaration
3624 if Present (Alias (E1))
3625 and then Scope (E1) /= Scope (Alias (E1))
3628 ("cannot apply pragma% to non-local entity& declared#",
3632 Set_Convention_From_Pragma (E1);
3634 if Prag_Id = Pragma_Import then
3635 Generate_Reference (E1, Id, 'b');
3639 -- For aspect case, do NOT apply to homonyms
3641 exit when From_Aspect_Specification (N);
3644 end Process_Convention;
3646 ----------------------------------------
3647 -- Process_Disable_Enable_Atomic_Sync --
3648 ----------------------------------------
3650 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3653 Check_No_Identifiers;
3654 Check_At_Most_N_Arguments (1);
3656 -- Modeled internally as
3657 -- pragma Unsuppress (Atomic_Synchronization [,Entity])
3661 Pragma_Identifier =>
3662 Make_Identifier (Loc, Nam),
3663 Pragma_Argument_Associations => New_List (
3664 Make_Pragma_Argument_Association (Loc,
3666 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3668 if Present (Arg1) then
3669 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3673 end Process_Disable_Enable_Atomic_Sync;
3675 -----------------------------------------------------
3676 -- Process_Extended_Import_Export_Exception_Pragma --
3677 -----------------------------------------------------
3679 procedure Process_Extended_Import_Export_Exception_Pragma
3680 (Arg_Internal : Node_Id;
3681 Arg_External : Node_Id;
3689 if not OpenVMS_On_Target then
3691 ("?pragma% ignored (applies only to Open'V'M'S)");
3694 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3695 Def_Id := Entity (Arg_Internal);
3697 if Ekind (Def_Id) /= E_Exception then
3699 ("pragma% must refer to declared exception", Arg_Internal);
3702 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3704 if Present (Arg_Form) then
3705 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3708 if Present (Arg_Form)
3709 and then Chars (Arg_Form) = Name_Ada
3713 Set_Is_VMS_Exception (Def_Id);
3714 Set_Exception_Code (Def_Id, No_Uint);
3717 if Present (Arg_Code) then
3718 if not Is_VMS_Exception (Def_Id) then
3720 ("Code option for pragma% not allowed for Ada case",
3724 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3725 Code_Val := Expr_Value (Arg_Code);
3727 if not UI_Is_In_Int_Range (Code_Val) then
3729 ("Code option for pragma% must be in 32-bit range",
3733 Set_Exception_Code (Def_Id, Code_Val);
3736 end Process_Extended_Import_Export_Exception_Pragma;
3738 -------------------------------------------------
3739 -- Process_Extended_Import_Export_Internal_Arg --
3740 -------------------------------------------------
3742 procedure Process_Extended_Import_Export_Internal_Arg
3743 (Arg_Internal : Node_Id := Empty)
3746 if No (Arg_Internal) then
3747 Error_Pragma ("Internal parameter required for pragma%");
3750 if Nkind (Arg_Internal) = N_Identifier then
3753 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3754 and then (Prag_Id = Pragma_Import_Function
3756 Prag_Id = Pragma_Export_Function)
3762 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3765 Check_Arg_Is_Local_Name (Arg_Internal);
3766 end Process_Extended_Import_Export_Internal_Arg;
3768 --------------------------------------------------
3769 -- Process_Extended_Import_Export_Object_Pragma --
3770 --------------------------------------------------
3772 procedure Process_Extended_Import_Export_Object_Pragma
3773 (Arg_Internal : Node_Id;
3774 Arg_External : Node_Id;
3780 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3781 Def_Id := Entity (Arg_Internal);
3783 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3785 ("pragma% must designate an object", Arg_Internal);
3788 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3790 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3793 ("previous Common/Psect_Object applies, pragma % not permitted",
3797 if Rep_Item_Too_Late (Def_Id, N) then
3801 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3803 if Present (Arg_Size) then
3804 Check_Arg_Is_External_Name (Arg_Size);
3807 -- Export_Object case
3809 if Prag_Id = Pragma_Export_Object then
3810 if not Is_Library_Level_Entity (Def_Id) then
3812 ("argument for pragma% must be library level entity",
3816 if Ekind (Current_Scope) = E_Generic_Package then
3817 Error_Pragma ("pragma& cannot appear in a generic unit");
3820 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3822 ("exported object must have compile time known size",
3826 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3827 Error_Msg_N ("?duplicate Export_Object pragma", N);
3829 Set_Exported (Def_Id, Arg_Internal);
3832 -- Import_Object case
3835 if Is_Concurrent_Type (Etype (Def_Id)) then
3837 ("cannot use pragma% for task/protected object",
3841 if Ekind (Def_Id) = E_Constant then
3843 ("cannot import a constant", Arg_Internal);
3846 if Warn_On_Export_Import
3847 and then Has_Discriminants (Etype (Def_Id))
3850 ("imported value must be initialized?", Arg_Internal);
3853 if Warn_On_Export_Import
3854 and then Is_Access_Type (Etype (Def_Id))
3857 ("cannot import object of an access type?", Arg_Internal);
3860 if Warn_On_Export_Import
3861 and then Is_Imported (Def_Id)
3864 ("?duplicate Import_Object pragma", N);
3866 -- Check for explicit initialization present. Note that an
3867 -- initialization generated by the code generator, e.g. for an
3868 -- access type, does not count here.
3870 elsif Present (Expression (Parent (Def_Id)))
3873 (Original_Node (Expression (Parent (Def_Id))))
3875 Error_Msg_Sloc := Sloc (Def_Id);
3877 ("imported entities cannot be initialized (RM B.1(24))",
3878 "\no initialization allowed for & declared#", Arg1);
3880 Set_Imported (Def_Id);
3881 Note_Possible_Modification (Arg_Internal, Sure => False);
3884 end Process_Extended_Import_Export_Object_Pragma;
3886 ------------------------------------------------------
3887 -- Process_Extended_Import_Export_Subprogram_Pragma --
3888 ------------------------------------------------------
3890 procedure Process_Extended_Import_Export_Subprogram_Pragma
3891 (Arg_Internal : Node_Id;
3892 Arg_External : Node_Id;
3893 Arg_Parameter_Types : Node_Id;
3894 Arg_Result_Type : Node_Id := Empty;
3895 Arg_Mechanism : Node_Id;
3896 Arg_Result_Mechanism : Node_Id := Empty;
3897 Arg_First_Optional_Parameter : Node_Id := Empty)
3903 Ambiguous : Boolean;
3907 function Same_Base_Type
3909 Formal : Entity_Id) return Boolean;
3910 -- Determines if Ptype references the type of Formal. Note that only
3911 -- the base types need to match according to the spec. Ptype here is
3912 -- the argument from the pragma, which is either a type name, or an
3913 -- access attribute.
3915 --------------------
3916 -- Same_Base_Type --
3917 --------------------
3919 function Same_Base_Type
3921 Formal : Entity_Id) return Boolean
3923 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3927 -- Case where pragma argument is typ'Access
3929 if Nkind (Ptype) = N_Attribute_Reference
3930 and then Attribute_Name (Ptype) = Name_Access
3932 Pref := Prefix (Ptype);
3935 if not Is_Entity_Name (Pref)
3936 or else Entity (Pref) = Any_Type
3941 -- We have a match if the corresponding argument is of an
3942 -- anonymous access type, and its designated type matches the
3943 -- type of the prefix of the access attribute
3945 return Ekind (Ftyp) = E_Anonymous_Access_Type
3946 and then Base_Type (Entity (Pref)) =
3947 Base_Type (Etype (Designated_Type (Ftyp)));
3949 -- Case where pragma argument is a type name
3954 if not Is_Entity_Name (Ptype)
3955 or else Entity (Ptype) = Any_Type
3960 -- We have a match if the corresponding argument is of the type
3961 -- given in the pragma (comparing base types)
3963 return Base_Type (Entity (Ptype)) = Ftyp;
3967 -- Start of processing for
3968 -- Process_Extended_Import_Export_Subprogram_Pragma
3971 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3975 -- Loop through homonyms (overloadings) of the entity
3977 Hom_Id := Entity (Arg_Internal);
3978 while Present (Hom_Id) loop
3979 Def_Id := Get_Base_Subprogram (Hom_Id);
3981 -- We need a subprogram in the current scope
3983 if not Is_Subprogram (Def_Id)
3984 or else Scope (Def_Id) /= Current_Scope
3991 -- Pragma cannot apply to subprogram body
3993 if Is_Subprogram (Def_Id)
3994 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3998 ("pragma% requires separate spec"
3999 & " and must come before body");
4002 -- Test result type if given, note that the result type
4003 -- parameter can only be present for the function cases.
4005 if Present (Arg_Result_Type)
4006 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
4010 elsif Etype (Def_Id) /= Standard_Void_Type
4012 (Pname = Name_Export_Procedure
4014 Pname = Name_Import_Procedure)
4018 -- Test parameter types if given. Note that this parameter
4019 -- has not been analyzed (and must not be, since it is
4020 -- semantic nonsense), so we get it as the parser left it.
4022 elsif Present (Arg_Parameter_Types) then
4023 Check_Matching_Types : declare
4028 Formal := First_Formal (Def_Id);
4030 if Nkind (Arg_Parameter_Types) = N_Null then
4031 if Present (Formal) then
4035 -- A list of one type, e.g. (List) is parsed as
4036 -- a parenthesized expression.
4038 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4039 and then Paren_Count (Arg_Parameter_Types) = 1
4042 or else Present (Next_Formal (Formal))
4047 Same_Base_Type (Arg_Parameter_Types, Formal);
4050 -- A list of more than one type is parsed as a aggregate
4052 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4053 and then Paren_Count (Arg_Parameter_Types) = 0
4055 Ptype := First (Expressions (Arg_Parameter_Types));
4056 while Present (Ptype) or else Present (Formal) loop
4059 or else not Same_Base_Type (Ptype, Formal)
4064 Next_Formal (Formal);
4069 -- Anything else is of the wrong form
4073 ("wrong form for Parameter_Types parameter",
4074 Arg_Parameter_Types);
4076 end Check_Matching_Types;
4079 -- Match is now False if the entry we found did not match
4080 -- either a supplied Parameter_Types or Result_Types argument
4086 -- Ambiguous case, the flag Ambiguous shows if we already
4087 -- detected this and output the initial messages.
4090 if not Ambiguous then
4092 Error_Msg_Name_1 := Pname;
4094 ("pragma% does not uniquely identify subprogram!",
4096 Error_Msg_Sloc := Sloc (Ent);
4097 Error_Msg_N ("matching subprogram #!", N);
4101 Error_Msg_Sloc := Sloc (Def_Id);
4102 Error_Msg_N ("matching subprogram #!", N);
4107 Hom_Id := Homonym (Hom_Id);
4110 -- See if we found an entry
4113 if not Ambiguous then
4114 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4116 ("pragma% cannot be given for generic subprogram");
4119 ("pragma% does not identify local subprogram");
4126 -- Import pragmas must be for imported entities
4128 if Prag_Id = Pragma_Import_Function
4130 Prag_Id = Pragma_Import_Procedure
4132 Prag_Id = Pragma_Import_Valued_Procedure
4134 if not Is_Imported (Ent) then
4136 ("pragma Import or Interface must precede pragma%");
4139 -- Here we have the Export case which can set the entity as exported
4141 -- But does not do so if the specified external name is null, since
4142 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4143 -- compatible) to request no external name.
4145 elsif Nkind (Arg_External) = N_String_Literal
4146 and then String_Length (Strval (Arg_External)) = 0
4150 -- In all other cases, set entity as exported
4153 Set_Exported (Ent, Arg_Internal);
4156 -- Special processing for Valued_Procedure cases
4158 if Prag_Id = Pragma_Import_Valued_Procedure
4160 Prag_Id = Pragma_Export_Valued_Procedure
4162 Formal := First_Formal (Ent);
4165 Error_Pragma ("at least one parameter required for pragma%");
4167 elsif Ekind (Formal) /= E_Out_Parameter then
4168 Error_Pragma ("first parameter must have mode out for pragma%");
4171 Set_Is_Valued_Procedure (Ent);
4175 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4177 -- Process Result_Mechanism argument if present. We have already
4178 -- checked that this is only allowed for the function case.
4180 if Present (Arg_Result_Mechanism) then
4181 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4184 -- Process Mechanism parameter if present. Note that this parameter
4185 -- is not analyzed, and must not be analyzed since it is semantic
4186 -- nonsense, so we get it in exactly as the parser left it.
4188 if Present (Arg_Mechanism) then
4196 -- A single mechanism association without a formal parameter
4197 -- name is parsed as a parenthesized expression. All other
4198 -- cases are parsed as aggregates, so we rewrite the single
4199 -- parameter case as an aggregate for consistency.
4201 if Nkind (Arg_Mechanism) /= N_Aggregate
4202 and then Paren_Count (Arg_Mechanism) = 1
4204 Rewrite (Arg_Mechanism,
4205 Make_Aggregate (Sloc (Arg_Mechanism),
4206 Expressions => New_List (
4207 Relocate_Node (Arg_Mechanism))));
4210 -- Case of only mechanism name given, applies to all formals
4212 if Nkind (Arg_Mechanism) /= N_Aggregate then
4213 Formal := First_Formal (Ent);
4214 while Present (Formal) loop
4215 Set_Mechanism_Value (Formal, Arg_Mechanism);
4216 Next_Formal (Formal);
4219 -- Case of list of mechanism associations given
4222 if Null_Record_Present (Arg_Mechanism) then
4224 ("inappropriate form for Mechanism parameter",
4228 -- Deal with positional ones first
4230 Formal := First_Formal (Ent);
4232 if Present (Expressions (Arg_Mechanism)) then
4233 Mname := First (Expressions (Arg_Mechanism));
4234 while Present (Mname) loop
4237 ("too many mechanism associations", Mname);
4240 Set_Mechanism_Value (Formal, Mname);
4241 Next_Formal (Formal);
4246 -- Deal with named entries
4248 if Present (Component_Associations (Arg_Mechanism)) then
4249 Massoc := First (Component_Associations (Arg_Mechanism));
4250 while Present (Massoc) loop
4251 Choice := First (Choices (Massoc));
4253 if Nkind (Choice) /= N_Identifier
4254 or else Present (Next (Choice))
4257 ("incorrect form for mechanism association",
4261 Formal := First_Formal (Ent);
4265 ("parameter name & not present", Choice);
4268 if Chars (Choice) = Chars (Formal) then
4270 (Formal, Expression (Massoc));
4272 -- Set entity on identifier (needed by ASIS)
4274 Set_Entity (Choice, Formal);
4279 Next_Formal (Formal);
4289 -- Process First_Optional_Parameter argument if present. We have
4290 -- already checked that this is only allowed for the Import case.
4292 if Present (Arg_First_Optional_Parameter) then
4293 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4295 ("first optional parameter must be formal parameter name",
4296 Arg_First_Optional_Parameter);
4299 Formal := First_Formal (Ent);
4303 ("specified formal parameter& not found",
4304 Arg_First_Optional_Parameter);
4307 exit when Chars (Formal) =
4308 Chars (Arg_First_Optional_Parameter);
4310 Next_Formal (Formal);
4313 Set_First_Optional_Parameter (Ent, Formal);
4315 -- Check specified and all remaining formals have right form
4317 while Present (Formal) loop
4318 if Ekind (Formal) /= E_In_Parameter then
4320 ("optional formal& is not of mode in!",
4321 Arg_First_Optional_Parameter, Formal);
4324 Dval := Default_Value (Formal);
4328 ("optional formal& does not have default value!",
4329 Arg_First_Optional_Parameter, Formal);
4331 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4336 ("default value for optional formal& is non-static!",
4337 Arg_First_Optional_Parameter, Formal);
4341 Set_Is_Optional_Parameter (Formal);
4342 Next_Formal (Formal);
4345 end Process_Extended_Import_Export_Subprogram_Pragma;
4347 --------------------------
4348 -- Process_Generic_List --
4349 --------------------------
4351 procedure Process_Generic_List is
4356 Check_No_Identifiers;
4357 Check_At_Least_N_Arguments (1);
4360 while Present (Arg) loop
4361 Exp := Get_Pragma_Arg (Arg);
4364 if not Is_Entity_Name (Exp)
4366 (not Is_Generic_Instance (Entity (Exp))
4368 not Is_Generic_Unit (Entity (Exp)))
4371 ("pragma% argument must be name of generic unit/instance",
4377 end Process_Generic_List;
4379 ------------------------------------
4380 -- Process_Import_Predefined_Type --
4381 ------------------------------------
4383 procedure Process_Import_Predefined_Type is
4384 Loc : constant Source_Ptr := Sloc (N);
4386 Ftyp : Node_Id := Empty;
4392 String_To_Name_Buffer (Strval (Expression (Arg3)));
4395 Elmt := First_Elmt (Predefined_Float_Types);
4396 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4400 Ftyp := Node (Elmt);
4402 if Present (Ftyp) then
4404 -- Don't build a derived type declaration, because predefined C
4405 -- types have no declaration anywhere, so cannot really be named.
4406 -- Instead build a full type declaration, starting with an
4407 -- appropriate type definition is built
4409 if Is_Floating_Point_Type (Ftyp) then
4410 Def := Make_Floating_Point_Definition (Loc,
4411 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4412 Make_Real_Range_Specification (Loc,
4413 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4414 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4416 -- Should never have a predefined type we cannot handle
4419 raise Program_Error;
4422 -- Build and insert a Full_Type_Declaration, which will be
4423 -- analyzed as soon as this list entry has been analyzed.
4425 Decl := Make_Full_Type_Declaration (Loc,
4426 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4427 Type_Definition => Def);
4429 Insert_After (N, Decl);
4430 Mark_Rewrite_Insertion (Decl);
4433 Error_Pragma_Arg ("no matching type found for pragma%",
4436 end Process_Import_Predefined_Type;
4438 ---------------------------------
4439 -- Process_Import_Or_Interface --
4440 ---------------------------------
4442 procedure Process_Import_Or_Interface is
4448 Process_Convention (C, Def_Id);
4449 Kill_Size_Check_Code (Def_Id);
4450 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4452 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4454 -- We do not permit Import to apply to a renaming declaration
4456 if Present (Renamed_Object (Def_Id)) then
4458 ("pragma% not allowed for object renaming", Arg2);
4460 -- User initialization is not allowed for imported object, but
4461 -- the object declaration may contain a default initialization,
4462 -- that will be discarded. Note that an explicit initialization
4463 -- only counts if it comes from source, otherwise it is simply
4464 -- the code generator making an implicit initialization explicit.
4466 elsif Present (Expression (Parent (Def_Id)))
4467 and then Comes_From_Source (Expression (Parent (Def_Id)))
4469 Error_Msg_Sloc := Sloc (Def_Id);
4471 ("no initialization allowed for declaration of& #",
4472 "\imported entities cannot be initialized (RM B.1(24))",
4476 Set_Imported (Def_Id);
4477 Process_Interface_Name (Def_Id, Arg3, Arg4);
4479 -- Note that we do not set Is_Public here. That's because we
4480 -- only want to set it if there is no address clause, and we
4481 -- don't know that yet, so we delay that processing till
4484 -- pragma Import completes deferred constants
4486 if Ekind (Def_Id) = E_Constant then
4487 Set_Has_Completion (Def_Id);
4490 -- It is not possible to import a constant of an unconstrained
4491 -- array type (e.g. string) because there is no simple way to
4492 -- write a meaningful subtype for it.
4494 if Is_Array_Type (Etype (Def_Id))
4495 and then not Is_Constrained (Etype (Def_Id))
4498 ("imported constant& must have a constrained subtype",
4503 elsif Is_Subprogram (Def_Id)
4504 or else Is_Generic_Subprogram (Def_Id)
4506 -- If the name is overloaded, pragma applies to all of the denoted
4507 -- entities in the same declarative part.
4510 while Present (Hom_Id) loop
4511 Def_Id := Get_Base_Subprogram (Hom_Id);
4513 -- Ignore inherited subprograms because the pragma will apply
4514 -- to the parent operation, which is the one called.
4516 if Is_Overloadable (Def_Id)
4517 and then Present (Alias (Def_Id))
4521 -- If it is not a subprogram, it must be in an outer scope and
4522 -- pragma does not apply.
4524 elsif not Is_Subprogram (Def_Id)
4525 and then not Is_Generic_Subprogram (Def_Id)
4529 -- The pragma does not apply to primitives of interfaces
4531 elsif Is_Dispatching_Operation (Def_Id)
4532 and then Present (Find_Dispatching_Type (Def_Id))
4533 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4537 -- Verify that the homonym is in the same declarative part (not
4538 -- just the same scope).
4540 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4541 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4546 Set_Imported (Def_Id);
4548 -- Reject an Import applied to an abstract subprogram
4550 if Is_Subprogram (Def_Id)
4551 and then Is_Abstract_Subprogram (Def_Id)
4553 Error_Msg_Sloc := Sloc (Def_Id);
4555 ("cannot import abstract subprogram& declared#",
4559 -- Special processing for Convention_Intrinsic
4561 if C = Convention_Intrinsic then
4563 -- Link_Name argument not allowed for intrinsic
4567 Set_Is_Intrinsic_Subprogram (Def_Id);
4569 -- If no external name is present, then check that this
4570 -- is a valid intrinsic subprogram. If an external name
4571 -- is present, then this is handled by the back end.
4574 Check_Intrinsic_Subprogram
4575 (Def_Id, Get_Pragma_Arg (Arg2));
4579 -- All interfaced procedures need an external symbol created
4580 -- for them since they are always referenced from another
4583 Set_Is_Public (Def_Id);
4585 -- Verify that the subprogram does not have a completion
4586 -- through a renaming declaration. For other completions the
4587 -- pragma appears as a too late representation.
4590 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4594 and then Nkind (Decl) = N_Subprogram_Declaration
4595 and then Present (Corresponding_Body (Decl))
4596 and then Nkind (Unit_Declaration_Node
4597 (Corresponding_Body (Decl))) =
4598 N_Subprogram_Renaming_Declaration
4600 Error_Msg_Sloc := Sloc (Def_Id);
4602 ("cannot import&, renaming already provided for " &
4603 "declaration #", N, Def_Id);
4607 Set_Has_Completion (Def_Id);
4608 Process_Interface_Name (Def_Id, Arg3, Arg4);
4611 if Is_Compilation_Unit (Hom_Id) then
4613 -- Its possible homonyms are not affected by the pragma.
4614 -- Such homonyms might be present in the context of other
4615 -- units being compiled.
4620 Hom_Id := Homonym (Hom_Id);
4624 -- When the convention is Java or CIL, we also allow Import to be
4625 -- given for packages, generic packages, exceptions, record
4626 -- components, and access to subprograms.
4628 elsif (C = Convention_Java or else C = Convention_CIL)
4630 (Is_Package_Or_Generic_Package (Def_Id)
4631 or else Ekind (Def_Id) = E_Exception
4632 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4633 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4635 Set_Imported (Def_Id);
4636 Set_Is_Public (Def_Id);
4637 Process_Interface_Name (Def_Id, Arg3, Arg4);
4639 -- Import a CPP class
4641 elsif C = Convention_CPP
4642 and then (Is_Record_Type (Def_Id)
4643 or else Ekind (Def_Id) = E_Incomplete_Type)
4645 if Ekind (Def_Id) = E_Incomplete_Type then
4646 if Present (Full_View (Def_Id)) then
4647 Def_Id := Full_View (Def_Id);
4651 ("cannot import 'C'P'P type before full declaration seen",
4652 Get_Pragma_Arg (Arg2));
4654 -- Although we have reported the error we decorate it as
4655 -- CPP_Class to avoid reporting spurious errors
4657 Set_Is_CPP_Class (Def_Id);
4662 -- Types treated as CPP classes must be declared limited (note:
4663 -- this used to be a warning but there is no real benefit to it
4664 -- since we did effectively intend to treat the type as limited
4667 if not Is_Limited_Type (Def_Id) then
4669 ("imported 'C'P'P type must be limited",
4670 Get_Pragma_Arg (Arg2));
4673 Set_Is_CPP_Class (Def_Id);
4675 -- Imported CPP types must not have discriminants (because C++
4676 -- classes do not have discriminants).
4678 if Has_Discriminants (Def_Id) then
4680 ("imported 'C'P'P type cannot have discriminants",
4681 First (Discriminant_Specifications
4682 (Declaration_Node (Def_Id))));
4685 -- Check that components of imported CPP types do not have default
4686 -- expressions. For private types this check is performed when the
4687 -- full view is analyzed (see Process_Full_View).
4689 if not Is_Private_Type (Def_Id) then
4690 Check_CPP_Type_Has_No_Defaults (Def_Id);
4693 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4695 Check_Arg_Count (3);
4696 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4698 Process_Import_Predefined_Type;
4702 ("second argument of pragma% must be object, subprogram "
4703 & "or incomplete type",
4707 -- If this pragma applies to a compilation unit, then the unit, which
4708 -- is a subprogram, does not require (or allow) a body. We also do
4709 -- not need to elaborate imported procedures.
4711 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4713 Cunit : constant Node_Id := Parent (Parent (N));
4715 Set_Body_Required (Cunit, False);
4718 end Process_Import_Or_Interface;
4720 --------------------
4721 -- Process_Inline --
4722 --------------------
4724 procedure Process_Inline (Active : Boolean) is
4731 Effective : Boolean := False;
4732 -- Set True if inline has some effect, i.e. if there is at least one
4733 -- subprogram set as inlined as a result of the use of the pragma.
4735 procedure Make_Inline (Subp : Entity_Id);
4736 -- Subp is the defining unit name of the subprogram declaration. Set
4737 -- the flag, as well as the flag in the corresponding body, if there
4740 procedure Set_Inline_Flags (Subp : Entity_Id);
4741 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4742 -- Has_Pragma_Inline_Always for the Inline_Always case.
4744 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4745 -- Returns True if it can be determined at this stage that inlining
4746 -- is not possible, for example if the body is available and contains
4747 -- exception handlers, we prevent inlining, since otherwise we can
4748 -- get undefined symbols at link time. This function also emits a
4749 -- warning if front-end inlining is enabled and the pragma appears
4752 -- ??? is business with link symbols still valid, or does it relate
4753 -- to front end ZCX which is being phased out ???
4755 ---------------------------
4756 -- Inlining_Not_Possible --
4757 ---------------------------
4759 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4760 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4764 if Nkind (Decl) = N_Subprogram_Body then
4765 Stats := Handled_Statement_Sequence (Decl);
4766 return Present (Exception_Handlers (Stats))
4767 or else Present (At_End_Proc (Stats));
4769 elsif Nkind (Decl) = N_Subprogram_Declaration
4770 and then Present (Corresponding_Body (Decl))
4772 if Front_End_Inlining
4773 and then Analyzed (Corresponding_Body (Decl))
4775 Error_Msg_N ("pragma appears too late, ignored?", N);
4778 -- If the subprogram is a renaming as body, the body is just a
4779 -- call to the renamed subprogram, and inlining is trivially
4783 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4784 N_Subprogram_Renaming_Declaration
4790 Handled_Statement_Sequence
4791 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4794 Present (Exception_Handlers (Stats))
4795 or else Present (At_End_Proc (Stats));
4799 -- If body is not available, assume the best, the check is
4800 -- performed again when compiling enclosing package bodies.
4804 end Inlining_Not_Possible;
4810 procedure Make_Inline (Subp : Entity_Id) is
4811 Kind : constant Entity_Kind := Ekind (Subp);
4812 Inner_Subp : Entity_Id := Subp;
4815 -- Ignore if bad type, avoid cascaded error
4817 if Etype (Subp) = Any_Type then
4821 -- Ignore if all inlining is suppressed
4823 elsif Suppress_All_Inlining then
4827 -- If inlining is not possible, for now do not treat as an error
4829 elsif Inlining_Not_Possible (Subp) then
4833 -- Here we have a candidate for inlining, but we must exclude
4834 -- derived operations. Otherwise we would end up trying to inline
4835 -- a phantom declaration, and the result would be to drag in a
4836 -- body which has no direct inlining associated with it. That
4837 -- would not only be inefficient but would also result in the
4838 -- backend doing cross-unit inlining in cases where it was
4839 -- definitely inappropriate to do so.
4841 -- However, a simple Comes_From_Source test is insufficient, since
4842 -- we do want to allow inlining of generic instances which also do
4843 -- not come from source. We also need to recognize specs generated
4844 -- by the front-end for bodies that carry the pragma. Finally,
4845 -- predefined operators do not come from source but are not
4846 -- inlineable either.
4848 elsif Is_Generic_Instance (Subp)
4849 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4853 elsif not Comes_From_Source (Subp)
4854 and then Scope (Subp) /= Standard_Standard
4860 -- The referenced entity must either be the enclosing entity, or
4861 -- an entity declared within the current open scope.
4863 if Present (Scope (Subp))
4864 and then Scope (Subp) /= Current_Scope
4865 and then Subp /= Current_Scope
4868 ("argument of% must be entity in current scope", Assoc);
4872 -- Processing for procedure, operator or function. If subprogram
4873 -- is aliased (as for an instance) indicate that the renamed
4874 -- entity (if declared in the same unit) is inlined.
4876 if Is_Subprogram (Subp) then
4877 Inner_Subp := Ultimate_Alias (Inner_Subp);
4879 if In_Same_Source_Unit (Subp, Inner_Subp) then
4880 Set_Inline_Flags (Inner_Subp);
4882 Decl := Parent (Parent (Inner_Subp));
4884 if Nkind (Decl) = N_Subprogram_Declaration
4885 and then Present (Corresponding_Body (Decl))
4887 Set_Inline_Flags (Corresponding_Body (Decl));
4889 elsif Is_Generic_Instance (Subp) then
4891 -- Indicate that the body needs to be created for
4892 -- inlining subsequent calls. The instantiation node
4893 -- follows the declaration of the wrapper package
4896 if Scope (Subp) /= Standard_Standard
4898 Need_Subprogram_Instance_Body
4899 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4905 -- Inline is a program unit pragma (RM 10.1.5) and cannot
4906 -- appear in a formal part to apply to a formal subprogram.
4907 -- Do not apply check within an instance or a formal package
4908 -- the test will have been applied to the original generic.
4910 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4911 and then List_Containing (Decl) = List_Containing (N)
4912 and then not In_Instance
4915 ("Inline cannot apply to a formal subprogram", N);
4921 -- For a generic subprogram set flag as well, for use at the point
4922 -- of instantiation, to determine whether the body should be
4925 elsif Is_Generic_Subprogram (Subp) then
4926 Set_Inline_Flags (Subp);
4929 -- Literals are by definition inlined
4931 elsif Kind = E_Enumeration_Literal then
4934 -- Anything else is an error
4938 ("expect subprogram name for pragma%", Assoc);
4942 ----------------------
4943 -- Set_Inline_Flags --
4944 ----------------------
4946 procedure Set_Inline_Flags (Subp : Entity_Id) is
4949 Set_Is_Inlined (Subp);
4952 if not Has_Pragma_Inline (Subp) then
4953 Set_Has_Pragma_Inline (Subp);
4957 if Prag_Id = Pragma_Inline_Always then
4958 Set_Has_Pragma_Inline_Always (Subp);
4960 end Set_Inline_Flags;
4962 -- Start of processing for Process_Inline
4965 Check_No_Identifiers;
4966 Check_At_Least_N_Arguments (1);
4969 Inline_Processing_Required := True;
4973 while Present (Assoc) loop
4974 Subp_Id := Get_Pragma_Arg (Assoc);
4978 if Is_Entity_Name (Subp_Id) then
4979 Subp := Entity (Subp_Id);
4981 if Subp = Any_Id then
4983 -- If previous error, avoid cascaded errors
4991 -- For the pragma case, climb homonym chain. This is
4992 -- what implements allowing the pragma in the renaming
4993 -- case, with the result applying to the ancestors, and
4994 -- also allows Inline to apply to all previous homonyms.
4996 if not From_Aspect_Specification (N) then
4997 while Present (Homonym (Subp))
4998 and then Scope (Homonym (Subp)) = Current_Scope
5000 Make_Inline (Homonym (Subp));
5001 Subp := Homonym (Subp);
5009 ("inappropriate argument for pragma%", Assoc);
5012 and then Warn_On_Redundant_Constructs
5013 and then not Suppress_All_Inlining
5015 if Inlining_Not_Possible (Subp) then
5017 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
5020 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
5028 ----------------------------
5029 -- Process_Interface_Name --
5030 ----------------------------
5032 procedure Process_Interface_Name
5033 (Subprogram_Def : Entity_Id;
5039 String_Val : String_Id;
5041 procedure Check_Form_Of_Interface_Name
5043 Ext_Name_Case : Boolean);
5044 -- SN is a string literal node for an interface name. This routine
5045 -- performs some minimal checks that the name is reasonable. In
5046 -- particular that no spaces or other obviously incorrect characters
5047 -- appear. This is only a warning, since any characters are allowed.
5048 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5050 ----------------------------------
5051 -- Check_Form_Of_Interface_Name --
5052 ----------------------------------
5054 procedure Check_Form_Of_Interface_Name
5056 Ext_Name_Case : Boolean)
5058 S : constant String_Id := Strval (Expr_Value_S (SN));
5059 SL : constant Nat := String_Length (S);
5064 Error_Msg_N ("interface name cannot be null string", SN);
5067 for J in 1 .. SL loop
5068 C := Get_String_Char (S, J);
5070 -- Look for dubious character and issue unconditional warning.
5071 -- Definitely dubious if not in character range.
5073 if not In_Character_Range (C)
5075 -- For all cases except CLI target,
5076 -- commas, spaces and slashes are dubious (in CLI, we use
5077 -- commas and backslashes in external names to specify
5078 -- assembly version and public key, while slashes and spaces
5079 -- can be used in names to mark nested classes and
5082 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5083 and then (Get_Character (C) = ','
5085 Get_Character (C) = '\'))
5086 or else (VM_Target /= CLI_Target
5087 and then (Get_Character (C) = ' '
5089 Get_Character (C) = '/'))
5092 ("?interface name contains illegal character",
5093 Sloc (SN) + Source_Ptr (J));
5096 end Check_Form_Of_Interface_Name;
5098 -- Start of processing for Process_Interface_Name
5101 if No (Link_Arg) then
5102 if No (Ext_Arg) then
5103 if VM_Target = CLI_Target
5104 and then Ekind (Subprogram_Def) = E_Package
5105 and then Nkind (Parent (Subprogram_Def)) =
5106 N_Package_Specification
5107 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5112 (Generic_Parent (Parent (Subprogram_Def))));
5117 elsif Chars (Ext_Arg) = Name_Link_Name then
5119 Link_Nam := Expression (Ext_Arg);
5122 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5123 Ext_Nam := Expression (Ext_Arg);
5128 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5129 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5130 Ext_Nam := Expression (Ext_Arg);
5131 Link_Nam := Expression (Link_Arg);
5134 -- Check expressions for external name and link name are static
5136 if Present (Ext_Nam) then
5137 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5138 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5140 -- Verify that external name is not the name of a local entity,
5141 -- which would hide the imported one and could lead to run-time
5142 -- surprises. The problem can only arise for entities declared in
5143 -- a package body (otherwise the external name is fully qualified
5144 -- and will not conflict).
5152 if Prag_Id = Pragma_Import then
5153 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5155 E := Entity_Id (Get_Name_Table_Info (Nam));
5157 if Nam /= Chars (Subprogram_Def)
5158 and then Present (E)
5159 and then not Is_Overloadable (E)
5160 and then Is_Immediately_Visible (E)
5161 and then not Is_Imported (E)
5162 and then Ekind (Scope (E)) = E_Package
5165 while Present (Par) loop
5166 if Nkind (Par) = N_Package_Body then
5167 Error_Msg_Sloc := Sloc (E);
5169 ("imported entity is hidden by & declared#",
5174 Par := Parent (Par);
5181 if Present (Link_Nam) then
5182 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5183 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5186 -- If there is no link name, just set the external name
5188 if No (Link_Nam) then
5189 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5191 -- For the Link_Name case, the given literal is preceded by an
5192 -- asterisk, which indicates to GCC that the given name should be
5193 -- taken literally, and in particular that no prepending of
5194 -- underlines should occur, even in systems where this is the
5200 if VM_Target = No_VM then
5201 Store_String_Char (Get_Char_Code ('*'));
5204 String_Val := Strval (Expr_Value_S (Link_Nam));
5205 Store_String_Chars (String_Val);
5207 Make_String_Literal (Sloc (Link_Nam),
5208 Strval => End_String);
5211 -- Set the interface name. If the entity is a generic instance, use
5212 -- its alias, which is the callable entity.
5214 if Is_Generic_Instance (Subprogram_Def) then
5215 Set_Encoded_Interface_Name
5216 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5218 Set_Encoded_Interface_Name
5219 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5222 -- We allow duplicated export names in CIL/Java, as they are always
5223 -- enclosed in a namespace that differentiates them, and overloaded
5224 -- entities are supported by the VM.
5226 if Convention (Subprogram_Def) /= Convention_CIL
5228 Convention (Subprogram_Def) /= Convention_Java
5230 Check_Duplicated_Export_Name (Link_Nam);
5232 end Process_Interface_Name;
5234 -----------------------------------------
5235 -- Process_Interrupt_Or_Attach_Handler --
5236 -----------------------------------------
5238 procedure Process_Interrupt_Or_Attach_Handler is
5239 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5240 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5241 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5244 Set_Is_Interrupt_Handler (Handler_Proc);
5246 -- If the pragma is not associated with a handler procedure within a
5247 -- protected type, then it must be for a nonprotected procedure for
5248 -- the AAMP target, in which case we don't associate a representation
5249 -- item with the procedure's scope.
5251 if Ekind (Proc_Scope) = E_Protected_Type then
5252 if Prag_Id = Pragma_Interrupt_Handler
5254 Prag_Id = Pragma_Attach_Handler
5256 Record_Rep_Item (Proc_Scope, N);
5259 end Process_Interrupt_Or_Attach_Handler;
5261 --------------------------------------------------
5262 -- Process_Restrictions_Or_Restriction_Warnings --
5263 --------------------------------------------------
5265 -- Note: some of the simple identifier cases were handled in par-prag,
5266 -- but it is harmless (and more straightforward) to simply handle all
5267 -- cases here, even if it means we repeat a bit of work in some cases.
5269 procedure Process_Restrictions_Or_Restriction_Warnings
5273 R_Id : Restriction_Id;
5278 procedure Check_Unit_Name (N : Node_Id);
5279 -- Checks unit name parameter for No_Dependence. Returns if it has
5280 -- an appropriate form, otherwise raises pragma argument error.
5282 ---------------------
5283 -- Check_Unit_Name --
5284 ---------------------
5286 procedure Check_Unit_Name (N : Node_Id) is
5288 if Nkind (N) = N_Selected_Component then
5289 Check_Unit_Name (Prefix (N));
5290 Check_Unit_Name (Selector_Name (N));
5292 elsif Nkind (N) = N_Identifier then
5297 ("wrong form for unit name for No_Dependence", N);
5299 end Check_Unit_Name;
5301 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5304 -- Ignore all Restrictions pragma in CodePeer mode
5306 if CodePeer_Mode then
5310 Check_Ada_83_Warning;
5311 Check_At_Least_N_Arguments (1);
5312 Check_Valid_Configuration_Pragma;
5315 while Present (Arg) loop
5317 Expr := Get_Pragma_Arg (Arg);
5319 -- Case of no restriction identifier present
5321 if Id = No_Name then
5322 if Nkind (Expr) /= N_Identifier then
5324 ("invalid form for restriction", Arg);
5329 (Process_Restriction_Synonyms (Expr));
5331 if R_Id not in All_Boolean_Restrictions then
5332 Error_Msg_Name_1 := Pname;
5334 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5336 -- Check for possible misspelling
5338 for J in Restriction_Id loop
5340 Rnm : constant String := Restriction_Id'Image (J);
5343 Name_Buffer (1 .. Rnm'Length) := Rnm;
5344 Name_Len := Rnm'Length;
5345 Set_Casing (All_Lower_Case);
5347 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5349 (Identifier_Casing (Current_Source_File));
5350 Error_Msg_String (1 .. Rnm'Length) :=
5351 Name_Buffer (1 .. Name_Len);
5352 Error_Msg_Strlen := Rnm'Length;
5353 Error_Msg_N -- CODEFIX
5354 ("\possible misspelling of ""~""",
5355 Get_Pragma_Arg (Arg));
5364 if Implementation_Restriction (R_Id) then
5365 Check_Restriction (No_Implementation_Restrictions, Arg);
5368 -- Special processing for No_Elaboration_Code restriction
5370 if R_Id = No_Elaboration_Code then
5372 -- Restriction is only recognized within a configuration
5373 -- pragma file, or within a unit of the main extended
5374 -- program. Note: the test for Main_Unit is needed to
5375 -- properly include the case of configuration pragma files.
5377 if not (Current_Sem_Unit = Main_Unit
5378 or else In_Extended_Main_Source_Unit (N))
5382 -- Don't allow in a subunit unless already specified in
5385 elsif Nkind (Parent (N)) = N_Compilation_Unit
5386 and then Nkind (Unit (Parent (N))) = N_Subunit
5387 and then not Restriction_Active (No_Elaboration_Code)
5390 ("invalid specification of ""No_Elaboration_Code""",
5393 ("\restriction cannot be specified in a subunit", N);
5395 ("\unless also specified in body or spec", N);
5398 -- If we have a No_Elaboration_Code pragma that we
5399 -- accept, then it needs to be added to the configuration
5400 -- restrcition set so that we get proper application to
5401 -- other units in the main extended source as required.
5404 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
5408 -- If this is a warning, then set the warning unless we already
5409 -- have a real restriction active (we never want a warning to
5410 -- override a real restriction).
5413 if not Restriction_Active (R_Id) then
5414 Set_Restriction (R_Id, N);
5415 Restriction_Warnings (R_Id) := True;
5418 -- If real restriction case, then set it and make sure that the
5419 -- restriction warning flag is off, since a real restriction
5420 -- always overrides a warning.
5423 Set_Restriction (R_Id, N);
5424 Restriction_Warnings (R_Id) := False;
5427 -- Check for obsolescent restrictions in Ada 2005 mode
5430 and then Ada_Version >= Ada_2005
5431 and then (R_Id = No_Asynchronous_Control
5433 R_Id = No_Unchecked_Deallocation
5435 R_Id = No_Unchecked_Conversion)
5437 Check_Restriction (No_Obsolescent_Features, N);
5440 -- A very special case that must be processed here: pragma
5441 -- Restrictions (No_Exceptions) turns off all run-time
5442 -- checking. This is a bit dubious in terms of the formal
5443 -- language definition, but it is what is intended by RM
5444 -- H.4(12). Restriction_Warnings never affects generated code
5445 -- so this is done only in the real restriction case.
5447 -- Atomic_Synchronization is not a real check, so it is not
5448 -- affected by this processing).
5450 if R_Id = No_Exceptions and then not Warn then
5451 for J in Scope_Suppress'Range loop
5452 if J /= Atomic_Synchronization then
5453 Scope_Suppress (J) := True;
5458 -- Case of No_Dependence => unit-name. Note that the parser
5459 -- already made the necessary entry in the No_Dependence table.
5461 elsif Id = Name_No_Dependence then
5462 Check_Unit_Name (Expr);
5464 -- Case of No_Specification_Of_Aspect => Identifier.
5466 elsif Id = Name_No_Specification_Of_Aspect then
5471 if Nkind (Expr) /= N_Identifier then
5474 A_Id := Get_Aspect_Id (Chars (Expr));
5477 if A_Id = No_Aspect then
5478 Error_Pragma_Arg ("invalid restriction name", Arg);
5480 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5484 -- All other cases of restriction identifier present
5487 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5488 Analyze_And_Resolve (Expr, Any_Integer);
5490 if R_Id not in All_Parameter_Restrictions then
5492 ("invalid restriction parameter identifier", Arg);
5494 elsif not Is_OK_Static_Expression (Expr) then
5495 Flag_Non_Static_Expr
5496 ("value must be static expression!", Expr);
5499 elsif not Is_Integer_Type (Etype (Expr))
5500 or else Expr_Value (Expr) < 0
5503 ("value must be non-negative integer", Arg);
5506 -- Restriction pragma is active
5508 Val := Expr_Value (Expr);
5510 if not UI_Is_In_Int_Range (Val) then
5512 ("pragma ignored, value too large?", Arg);
5515 -- Warning case. If the real restriction is active, then we
5516 -- ignore the request, since warning never overrides a real
5517 -- restriction. Otherwise we set the proper warning. Note that
5518 -- this circuit sets the warning again if it is already set,
5519 -- which is what we want, since the constant may have changed.
5522 if not Restriction_Active (R_Id) then
5524 (R_Id, N, Integer (UI_To_Int (Val)));
5525 Restriction_Warnings (R_Id) := True;
5528 -- Real restriction case, set restriction and make sure warning
5529 -- flag is off since real restriction always overrides warning.
5532 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5533 Restriction_Warnings (R_Id) := False;
5539 end Process_Restrictions_Or_Restriction_Warnings;
5541 ---------------------------------
5542 -- Process_Suppress_Unsuppress --
5543 ---------------------------------
5545 -- Note: this procedure makes entries in the check suppress data
5546 -- structures managed by Sem. See spec of package Sem for full
5547 -- details on how we handle recording of check suppression.
5549 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5554 In_Package_Spec : constant Boolean :=
5555 Is_Package_Or_Generic_Package (Current_Scope)
5556 and then not In_Package_Body (Current_Scope);
5558 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5559 -- Used to suppress a single check on the given entity
5561 --------------------------------
5562 -- Suppress_Unsuppress_Echeck --
5563 --------------------------------
5565 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5567 -- Check for error of trying to set atomic synchronization for
5568 -- a non-atomic variable.
5570 if C = Atomic_Synchronization
5571 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5574 ("pragma & requires atomic type or variable",
5575 Pragma_Identifier (Original_Node (N)));
5578 Set_Checks_May_Be_Suppressed (E);
5580 if In_Package_Spec then
5581 Push_Global_Suppress_Stack_Entry
5584 Suppress => Suppress_Case);
5586 Push_Local_Suppress_Stack_Entry
5589 Suppress => Suppress_Case);
5592 -- If this is a first subtype, and the base type is distinct,
5593 -- then also set the suppress flags on the base type.
5595 if Is_First_Subtype (E)
5596 and then Etype (E) /= E
5598 Suppress_Unsuppress_Echeck (Etype (E), C);
5600 end Suppress_Unsuppress_Echeck;
5602 -- Start of processing for Process_Suppress_Unsuppress
5605 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5606 -- user code: we want to generate checks for analysis purposes, as
5607 -- set respectively by -gnatC and -gnatd.F
5609 if (CodePeer_Mode or Alfa_Mode)
5610 and then Comes_From_Source (N)
5615 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5616 -- declarative part or a package spec (RM 11.5(5)).
5618 if not Is_Configuration_Pragma then
5619 Check_Is_In_Decl_Part_Or_Package_Spec;
5622 Check_At_Least_N_Arguments (1);
5623 Check_At_Most_N_Arguments (2);
5624 Check_No_Identifier (Arg1);
5625 Check_Arg_Is_Identifier (Arg1);
5627 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5629 if C = No_Check_Id then
5631 ("argument of pragma% is not valid check name", Arg1);
5634 if not Suppress_Case
5635 and then (C = All_Checks or else C = Overflow_Check)
5637 Opt.Overflow_Checks_Unsuppressed := True;
5640 if Arg_Count = 1 then
5642 -- Make an entry in the local scope suppress table. This is the
5643 -- table that directly shows the current value of the scope
5644 -- suppress check for any check id value.
5646 if C = All_Checks then
5648 -- For All_Checks, we set all specific predefined checks with
5649 -- the exception of Elaboration_Check, which is handled
5650 -- specially because of not wanting All_Checks to have the
5651 -- effect of deactivating static elaboration order processing.
5652 -- Atomic_Synchronization is also not affected, since this is
5653 -- not a real check.
5655 for J in Scope_Suppress'Range loop
5656 if J /= Elaboration_Check
5657 and then J /= Atomic_Synchronization
5659 Scope_Suppress (J) := Suppress_Case;
5663 -- If not All_Checks, and predefined check, then set appropriate
5664 -- scope entry. Note that we will set Elaboration_Check if this
5665 -- is explicitly specified. Atomic_Synchronization is allowed
5666 -- only if internally generated and entity is atomic.
5668 elsif C in Predefined_Check_Id
5669 and then (not Comes_From_Source (N)
5670 or else C /= Atomic_Synchronization)
5672 Scope_Suppress (C) := Suppress_Case;
5675 -- Also make an entry in the Local_Entity_Suppress table
5677 Push_Local_Suppress_Stack_Entry
5680 Suppress => Suppress_Case);
5682 -- Case of two arguments present, where the check is suppressed for
5683 -- a specified entity (given as the second argument of the pragma)
5686 -- This is obsolescent in Ada 2005 mode
5688 if Ada_Version >= Ada_2005 then
5689 Check_Restriction (No_Obsolescent_Features, Arg2);
5692 Check_Optional_Identifier (Arg2, Name_On);
5693 E_Id := Get_Pragma_Arg (Arg2);
5696 if not Is_Entity_Name (E_Id) then
5698 ("second argument of pragma% must be entity name", Arg2);
5707 -- Enforce RM 11.5(7) which requires that for a pragma that
5708 -- appears within a package spec, the named entity must be
5709 -- within the package spec. We allow the package name itself
5710 -- to be mentioned since that makes sense, although it is not
5711 -- strictly allowed by 11.5(7).
5714 and then E /= Current_Scope
5715 and then Scope (E) /= Current_Scope
5718 ("entity in pragma% is not in package spec (RM 11.5(7))",
5722 -- Loop through homonyms. As noted below, in the case of a package
5723 -- spec, only homonyms within the package spec are considered.
5726 Suppress_Unsuppress_Echeck (E, C);
5728 if Is_Generic_Instance (E)
5729 and then Is_Subprogram (E)
5730 and then Present (Alias (E))
5732 Suppress_Unsuppress_Echeck (Alias (E), C);
5735 -- Move to next homonym if not aspect spec case
5737 exit when From_Aspect_Specification (N);
5741 -- If we are within a package specification, the pragma only
5742 -- applies to homonyms in the same scope.
5744 exit when In_Package_Spec
5745 and then Scope (E) /= Current_Scope;
5748 end Process_Suppress_Unsuppress;
5754 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5756 if Is_Imported (E) then
5758 ("cannot export entity& that was previously imported", Arg);
5760 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5762 ("cannot export entity& that has an address clause", Arg);
5765 Set_Is_Exported (E);
5767 -- Generate a reference for entity explicitly, because the
5768 -- identifier may be overloaded and name resolution will not
5771 Generate_Reference (E, Arg);
5773 -- Deal with exporting non-library level entity
5775 if not Is_Library_Level_Entity (E) then
5777 -- Not allowed at all for subprograms
5779 if Is_Subprogram (E) then
5780 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5782 -- Otherwise set public and statically allocated
5786 Set_Is_Statically_Allocated (E);
5788 -- Warn if the corresponding W flag is set and the pragma comes
5789 -- from source. The latter may not be true e.g. on VMS where we
5790 -- expand export pragmas for exception codes associated with
5791 -- imported or exported exceptions. We do not want to generate
5792 -- a warning for something that the user did not write.
5794 if Warn_On_Export_Import
5795 and then Comes_From_Source (Arg)
5798 ("?& has been made static as a result of Export", Arg, E);
5800 ("\this usage is non-standard and non-portable", Arg);
5805 if Warn_On_Export_Import and then Is_Type (E) then
5806 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5809 if Warn_On_Export_Import and Inside_A_Generic then
5811 ("all instances of& will have the same external name?", Arg, E);
5815 ----------------------------------------------
5816 -- Set_Extended_Import_Export_External_Name --
5817 ----------------------------------------------
5819 procedure Set_Extended_Import_Export_External_Name
5820 (Internal_Ent : Entity_Id;
5821 Arg_External : Node_Id)
5823 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5827 if No (Arg_External) then
5831 Check_Arg_Is_External_Name (Arg_External);
5833 if Nkind (Arg_External) = N_String_Literal then
5834 if String_Length (Strval (Arg_External)) = 0 then
5837 New_Name := Adjust_External_Name_Case (Arg_External);
5840 elsif Nkind (Arg_External) = N_Identifier then
5841 New_Name := Get_Default_External_Name (Arg_External);
5843 -- Check_Arg_Is_External_Name should let through only identifiers and
5844 -- string literals or static string expressions (which are folded to
5845 -- string literals).
5848 raise Program_Error;
5851 -- If we already have an external name set (by a prior normal Import
5852 -- or Export pragma), then the external names must match
5854 if Present (Interface_Name (Internal_Ent)) then
5855 Check_Matching_Internal_Names : declare
5856 S1 : constant String_Id := Strval (Old_Name);
5857 S2 : constant String_Id := Strval (New_Name);
5860 -- Called if names do not match
5866 procedure Mismatch is
5868 Error_Msg_Sloc := Sloc (Old_Name);
5870 ("external name does not match that given #",
5874 -- Start of processing for Check_Matching_Internal_Names
5877 if String_Length (S1) /= String_Length (S2) then
5881 for J in 1 .. String_Length (S1) loop
5882 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5887 end Check_Matching_Internal_Names;
5889 -- Otherwise set the given name
5892 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5893 Check_Duplicated_Export_Name (New_Name);
5895 end Set_Extended_Import_Export_External_Name;
5901 procedure Set_Imported (E : Entity_Id) is
5903 -- Error message if already imported or exported
5905 if Is_Exported (E) or else Is_Imported (E) then
5907 -- Error if being set Exported twice
5909 if Is_Exported (E) then
5910 Error_Msg_NE ("entity& was previously exported", N, E);
5912 -- OK if Import/Interface case
5914 elsif Import_Interface_Present (N) then
5917 -- Error if being set Imported twice
5920 Error_Msg_NE ("entity& was previously imported", N, E);
5923 Error_Msg_Name_1 := Pname;
5925 ("\(pragma% applies to all previous entities)", N);
5927 Error_Msg_Sloc := Sloc (E);
5928 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5930 -- Here if not previously imported or exported, OK to import
5933 Set_Is_Imported (E);
5935 -- If the entity is an object that is not at the library level,
5936 -- then it is statically allocated. We do not worry about objects
5937 -- with address clauses in this context since they are not really
5938 -- imported in the linker sense.
5941 and then not Is_Library_Level_Entity (E)
5942 and then No (Address_Clause (E))
5944 Set_Is_Statically_Allocated (E);
5951 -------------------------
5952 -- Set_Mechanism_Value --
5953 -------------------------
5955 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5956 -- analyzed, since it is semantic nonsense), so we get it in the exact
5957 -- form created by the parser.
5959 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5962 Mech_Name_Id : Name_Id;
5964 procedure Bad_Class;
5965 -- Signal bad descriptor class name
5967 procedure Bad_Mechanism;
5968 -- Signal bad mechanism name
5974 procedure Bad_Class is
5976 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5979 -------------------------
5980 -- Bad_Mechanism_Value --
5981 -------------------------
5983 procedure Bad_Mechanism is
5985 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5988 -- Start of processing for Set_Mechanism_Value
5991 if Mechanism (Ent) /= Default_Mechanism then
5993 ("mechanism for & has already been set", Mech_Name, Ent);
5996 -- MECHANISM_NAME ::= value | reference | descriptor |
5999 if Nkind (Mech_Name) = N_Identifier then
6000 if Chars (Mech_Name) = Name_Value then
6001 Set_Mechanism (Ent, By_Copy);
6004 elsif Chars (Mech_Name) = Name_Reference then
6005 Set_Mechanism (Ent, By_Reference);
6008 elsif Chars (Mech_Name) = Name_Descriptor then
6009 Check_VMS (Mech_Name);
6011 -- Descriptor => Short_Descriptor if pragma was given
6013 if Short_Descriptors then
6014 Set_Mechanism (Ent, By_Short_Descriptor);
6016 Set_Mechanism (Ent, By_Descriptor);
6021 elsif Chars (Mech_Name) = Name_Short_Descriptor then
6022 Check_VMS (Mech_Name);
6023 Set_Mechanism (Ent, By_Short_Descriptor);
6026 elsif Chars (Mech_Name) = Name_Copy then
6028 ("bad mechanism name, Value assumed", Mech_Name);
6034 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
6035 -- short_descriptor (CLASS_NAME)
6036 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6038 -- Note: this form is parsed as an indexed component
6040 elsif Nkind (Mech_Name) = N_Indexed_Component then
6041 Class := First (Expressions (Mech_Name));
6043 if Nkind (Prefix (Mech_Name)) /= N_Identifier
6044 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
6045 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
6046 or else Present (Next (Class))
6050 Mech_Name_Id := Chars (Prefix (Mech_Name));
6052 -- Change Descriptor => Short_Descriptor if pragma was given
6054 if Mech_Name_Id = Name_Descriptor
6055 and then Short_Descriptors
6057 Mech_Name_Id := Name_Short_Descriptor;
6061 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6062 -- short_descriptor (Class => CLASS_NAME)
6063 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6065 -- Note: this form is parsed as a function call
6067 elsif Nkind (Mech_Name) = N_Function_Call then
6068 Param := First (Parameter_Associations (Mech_Name));
6070 if Nkind (Name (Mech_Name)) /= N_Identifier
6071 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6072 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6073 or else Present (Next (Param))
6074 or else No (Selector_Name (Param))
6075 or else Chars (Selector_Name (Param)) /= Name_Class
6079 Class := Explicit_Actual_Parameter (Param);
6080 Mech_Name_Id := Chars (Name (Mech_Name));
6087 -- Fall through here with Class set to descriptor class name
6089 Check_VMS (Mech_Name);
6091 if Nkind (Class) /= N_Identifier then
6094 elsif Mech_Name_Id = Name_Descriptor
6095 and then Chars (Class) = Name_UBS
6097 Set_Mechanism (Ent, By_Descriptor_UBS);
6099 elsif Mech_Name_Id = Name_Descriptor
6100 and then Chars (Class) = Name_UBSB
6102 Set_Mechanism (Ent, By_Descriptor_UBSB);
6104 elsif Mech_Name_Id = Name_Descriptor
6105 and then Chars (Class) = Name_UBA
6107 Set_Mechanism (Ent, By_Descriptor_UBA);
6109 elsif Mech_Name_Id = Name_Descriptor
6110 and then Chars (Class) = Name_S
6112 Set_Mechanism (Ent, By_Descriptor_S);
6114 elsif Mech_Name_Id = Name_Descriptor
6115 and then Chars (Class) = Name_SB
6117 Set_Mechanism (Ent, By_Descriptor_SB);
6119 elsif Mech_Name_Id = Name_Descriptor
6120 and then Chars (Class) = Name_A
6122 Set_Mechanism (Ent, By_Descriptor_A);
6124 elsif Mech_Name_Id = Name_Descriptor
6125 and then Chars (Class) = Name_NCA
6127 Set_Mechanism (Ent, By_Descriptor_NCA);
6129 elsif Mech_Name_Id = Name_Short_Descriptor
6130 and then Chars (Class) = Name_UBS
6132 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6134 elsif Mech_Name_Id = Name_Short_Descriptor
6135 and then Chars (Class) = Name_UBSB
6137 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6139 elsif Mech_Name_Id = Name_Short_Descriptor
6140 and then Chars (Class) = Name_UBA
6142 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6144 elsif Mech_Name_Id = Name_Short_Descriptor
6145 and then Chars (Class) = Name_S
6147 Set_Mechanism (Ent, By_Short_Descriptor_S);
6149 elsif Mech_Name_Id = Name_Short_Descriptor
6150 and then Chars (Class) = Name_SB
6152 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6154 elsif Mech_Name_Id = Name_Short_Descriptor
6155 and then Chars (Class) = Name_A
6157 Set_Mechanism (Ent, By_Short_Descriptor_A);
6159 elsif Mech_Name_Id = Name_Short_Descriptor
6160 and then Chars (Class) = Name_NCA
6162 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6167 end Set_Mechanism_Value;
6169 ---------------------------
6170 -- Set_Ravenscar_Profile --
6171 ---------------------------
6173 -- The tasks to be done here are
6175 -- Set required policies
6177 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6178 -- pragma Locking_Policy (Ceiling_Locking)
6180 -- Set Detect_Blocking mode
6182 -- Set required restrictions (see System.Rident for detailed list)
6184 -- Set the No_Dependence rules
6185 -- No_Dependence => Ada.Asynchronous_Task_Control
6186 -- No_Dependence => Ada.Calendar
6187 -- No_Dependence => Ada.Execution_Time.Group_Budget
6188 -- No_Dependence => Ada.Execution_Time.Timers
6189 -- No_Dependence => Ada.Task_Attributes
6190 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6192 procedure Set_Ravenscar_Profile (N : Node_Id) is
6193 Prefix_Entity : Entity_Id;
6194 Selector_Entity : Entity_Id;
6195 Prefix_Node : Node_Id;
6199 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6201 if Task_Dispatching_Policy /= ' '
6202 and then Task_Dispatching_Policy /= 'F'
6204 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6205 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6207 -- Set the FIFO_Within_Priorities policy, but always preserve
6208 -- System_Location since we like the error message with the run time
6212 Task_Dispatching_Policy := 'F';
6214 if Task_Dispatching_Policy_Sloc /= System_Location then
6215 Task_Dispatching_Policy_Sloc := Loc;
6219 -- pragma Locking_Policy (Ceiling_Locking)
6221 if Locking_Policy /= ' '
6222 and then Locking_Policy /= 'C'
6224 Error_Msg_Sloc := Locking_Policy_Sloc;
6225 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6227 -- Set the Ceiling_Locking policy, but preserve System_Location since
6228 -- we like the error message with the run time name.
6231 Locking_Policy := 'C';
6233 if Locking_Policy_Sloc /= System_Location then
6234 Locking_Policy_Sloc := Loc;
6238 -- pragma Detect_Blocking
6240 Detect_Blocking := True;
6242 -- Set the corresponding restrictions
6244 Set_Profile_Restrictions
6245 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6247 -- Set the No_Dependence restrictions
6249 -- The following No_Dependence restrictions:
6250 -- No_Dependence => Ada.Asynchronous_Task_Control
6251 -- No_Dependence => Ada.Calendar
6252 -- No_Dependence => Ada.Task_Attributes
6253 -- are already set by previous call to Set_Profile_Restrictions.
6255 -- Set the following restrictions which were added to Ada 2005:
6256 -- No_Dependence => Ada.Execution_Time.Group_Budget
6257 -- No_Dependence => Ada.Execution_Time.Timers
6259 if Ada_Version >= Ada_2005 then
6260 Name_Buffer (1 .. 3) := "ada";
6263 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6265 Name_Buffer (1 .. 14) := "execution_time";
6268 Selector_Entity := Make_Identifier (Loc, Name_Find);
6271 Make_Selected_Component
6273 Prefix => Prefix_Entity,
6274 Selector_Name => Selector_Entity);
6276 Name_Buffer (1 .. 13) := "group_budgets";
6279 Selector_Entity := Make_Identifier (Loc, Name_Find);
6282 Make_Selected_Component
6284 Prefix => Prefix_Node,
6285 Selector_Name => Selector_Entity);
6287 Set_Restriction_No_Dependence
6289 Warn => Treat_Restrictions_As_Warnings,
6290 Profile => Ravenscar);
6292 Name_Buffer (1 .. 6) := "timers";
6295 Selector_Entity := Make_Identifier (Loc, Name_Find);
6298 Make_Selected_Component
6300 Prefix => Prefix_Node,
6301 Selector_Name => Selector_Entity);
6303 Set_Restriction_No_Dependence
6305 Warn => Treat_Restrictions_As_Warnings,
6306 Profile => Ravenscar);
6309 -- Set the following restrictions which was added to Ada 2012 (see
6311 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6313 if Ada_Version >= Ada_2012 then
6314 Name_Buffer (1 .. 6) := "system";
6317 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6319 Name_Buffer (1 .. 15) := "multiprocessors";
6322 Selector_Entity := Make_Identifier (Loc, Name_Find);
6325 Make_Selected_Component
6327 Prefix => Prefix_Entity,
6328 Selector_Name => Selector_Entity);
6330 Name_Buffer (1 .. 19) := "dispatching_domains";
6333 Selector_Entity := Make_Identifier (Loc, Name_Find);
6336 Make_Selected_Component
6338 Prefix => Prefix_Node,
6339 Selector_Name => Selector_Entity);
6341 Set_Restriction_No_Dependence
6343 Warn => Treat_Restrictions_As_Warnings,
6344 Profile => Ravenscar);
6346 end Set_Ravenscar_Profile;
6348 -- Start of processing for Analyze_Pragma
6351 -- The following code is a defense against recursion. Not clear that
6352 -- this can happen legitimately, but perhaps some error situations
6353 -- can cause it, and we did see this recursion during testing.
6355 if Analyzed (N) then
6358 Set_Analyzed (N, True);
6361 -- Deal with unrecognized pragma
6363 Pname := Pragma_Name (N);
6365 if not Is_Pragma_Name (Pname) then
6366 if Warn_On_Unrecognized_Pragma then
6367 Error_Msg_Name_1 := Pname;
6368 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6370 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6371 if Is_Bad_Spelling_Of (Pname, PN) then
6372 Error_Msg_Name_1 := PN;
6373 Error_Msg_N -- CODEFIX
6374 ("\?possible misspelling of %!", Pragma_Identifier (N));
6383 -- Here to start processing for recognized pragma
6385 Prag_Id := Get_Pragma_Id (Pname);
6387 if Present (Corresponding_Aspect (N)) then
6388 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6399 if Present (Pragma_Argument_Associations (N)) then
6400 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6401 Arg1 := First (Pragma_Argument_Associations (N));
6403 if Present (Arg1) then
6404 Arg2 := Next (Arg1);
6406 if Present (Arg2) then
6407 Arg3 := Next (Arg2);
6409 if Present (Arg3) then
6410 Arg4 := Next (Arg3);
6416 -- An enumeration type defines the pragmas that are supported by the
6417 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6418 -- into the corresponding enumeration value for the following case.
6426 -- pragma Abort_Defer;
6428 when Pragma_Abort_Defer =>
6430 Check_Arg_Count (0);
6432 -- The only required semantic processing is to check the
6433 -- placement. This pragma must appear at the start of the
6434 -- statement sequence of a handled sequence of statements.
6436 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6437 or else N /= First (Statements (Parent (N)))
6448 -- Note: this pragma also has some specific processing in Par.Prag
6449 -- because we want to set the Ada version mode during parsing.
6451 when Pragma_Ada_83 =>
6453 Check_Arg_Count (0);
6455 -- We really should check unconditionally for proper configuration
6456 -- pragma placement, since we really don't want mixed Ada modes
6457 -- within a single unit, and the GNAT reference manual has always
6458 -- said this was a configuration pragma, but we did not check and
6459 -- are hesitant to add the check now.
6461 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6462 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6463 -- or Ada 2012 mode.
6465 if Ada_Version >= Ada_2005 then
6466 Check_Valid_Configuration_Pragma;
6469 -- Now set Ada 83 mode
6471 Ada_Version := Ada_83;
6472 Ada_Version_Explicit := Ada_Version;
6480 -- Note: this pragma also has some specific processing in Par.Prag
6481 -- because we want to set the Ada 83 version mode during parsing.
6483 when Pragma_Ada_95 =>
6485 Check_Arg_Count (0);
6487 -- We really should check unconditionally for proper configuration
6488 -- pragma placement, since we really don't want mixed Ada modes
6489 -- within a single unit, and the GNAT reference manual has always
6490 -- said this was a configuration pragma, but we did not check and
6491 -- are hesitant to add the check now.
6493 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6494 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6496 if Ada_Version >= Ada_2005 then
6497 Check_Valid_Configuration_Pragma;
6500 -- Now set Ada 95 mode
6502 Ada_Version := Ada_95;
6503 Ada_Version_Explicit := Ada_Version;
6505 ---------------------
6506 -- Ada_05/Ada_2005 --
6507 ---------------------
6510 -- pragma Ada_05 (LOCAL_NAME);
6513 -- pragma Ada_2005 (LOCAL_NAME):
6515 -- Note: these pragmas also have some specific processing in Par.Prag
6516 -- because we want to set the Ada 2005 version mode during parsing.
6518 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6524 if Arg_Count = 1 then
6525 Check_Arg_Is_Local_Name (Arg1);
6526 E_Id := Get_Pragma_Arg (Arg1);
6528 if Etype (E_Id) = Any_Type then
6532 Set_Is_Ada_2005_Only (Entity (E_Id));
6535 Check_Arg_Count (0);
6537 -- For Ada_2005 we unconditionally enforce the documented
6538 -- configuration pragma placement, since we do not want to
6539 -- tolerate mixed modes in a unit involving Ada 2005. That
6540 -- would cause real difficulties for those cases where there
6541 -- are incompatibilities between Ada 95 and Ada 2005.
6543 Check_Valid_Configuration_Pragma;
6545 -- Now set appropriate Ada mode
6547 Ada_Version := Ada_2005;
6548 Ada_Version_Explicit := Ada_2005;
6552 ---------------------
6553 -- Ada_12/Ada_2012 --
6554 ---------------------
6557 -- pragma Ada_12 (LOCAL_NAME);
6560 -- pragma Ada_2012 (LOCAL_NAME):
6562 -- Note: these pragmas also have some specific processing in Par.Prag
6563 -- because we want to set the Ada 2012 version mode during parsing.
6565 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6571 if Arg_Count = 1 then
6572 Check_Arg_Is_Local_Name (Arg1);
6573 E_Id := Get_Pragma_Arg (Arg1);
6575 if Etype (E_Id) = Any_Type then
6579 Set_Is_Ada_2012_Only (Entity (E_Id));
6582 Check_Arg_Count (0);
6584 -- For Ada_2012 we unconditionally enforce the documented
6585 -- configuration pragma placement, since we do not want to
6586 -- tolerate mixed modes in a unit involving Ada 2012. That
6587 -- would cause real difficulties for those cases where there
6588 -- are incompatibilities between Ada 95 and Ada 2012. We could
6589 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6591 Check_Valid_Configuration_Pragma;
6593 -- Now set appropriate Ada mode
6595 Ada_Version := Ada_2012;
6596 Ada_Version_Explicit := Ada_2012;
6600 ----------------------
6601 -- All_Calls_Remote --
6602 ----------------------
6604 -- pragma All_Calls_Remote [(library_package_NAME)];
6606 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6607 Lib_Entity : Entity_Id;
6610 Check_Ada_83_Warning;
6611 Check_Valid_Library_Unit_Pragma;
6613 if Nkind (N) = N_Null_Statement then
6617 Lib_Entity := Find_Lib_Unit_Name;
6619 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6621 if Present (Lib_Entity)
6622 and then not Debug_Flag_U
6624 if not Is_Remote_Call_Interface (Lib_Entity) then
6625 Error_Pragma ("pragma% only apply to rci unit");
6627 -- Set flag for entity of the library unit
6630 Set_Has_All_Calls_Remote (Lib_Entity);
6634 end All_Calls_Remote;
6640 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6641 -- ARG ::= NAME | EXPRESSION
6643 -- The first two arguments are by convention intended to refer to an
6644 -- external tool and a tool-specific function. These arguments are
6647 when Pragma_Annotate => Annotate : declare
6653 Check_At_Least_N_Arguments (1);
6654 Check_Arg_Is_Identifier (Arg1);
6655 Check_No_Identifiers;
6658 -- Second parameter is optional, it is never analyzed
6663 -- Here if we have a second parameter
6666 -- Second parameter must be identifier
6668 Check_Arg_Is_Identifier (Arg2);
6670 -- Process remaining parameters if any
6673 while Present (Arg) loop
6674 Exp := Get_Pragma_Arg (Arg);
6677 if Is_Entity_Name (Exp) then
6680 -- For string literals, we assume Standard_String as the
6681 -- type, unless the string contains wide or wide_wide
6684 elsif Nkind (Exp) = N_String_Literal then
6685 if Has_Wide_Wide_Character (Exp) then
6686 Resolve (Exp, Standard_Wide_Wide_String);
6687 elsif Has_Wide_Character (Exp) then
6688 Resolve (Exp, Standard_Wide_String);
6690 Resolve (Exp, Standard_String);
6693 elsif Is_Overloaded (Exp) then
6695 ("ambiguous argument for pragma%", Exp);
6710 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6711 -- [, [Message =>] Static_String_EXPRESSION]);
6713 when Pragma_Assert => Assert : declare
6719 Check_At_Least_N_Arguments (1);
6720 Check_At_Most_N_Arguments (2);
6721 Check_Arg_Order ((Name_Check, Name_Message));
6722 Check_Optional_Identifier (Arg1, Name_Check);
6724 -- We treat pragma Assert as equivalent to:
6726 -- pragma Check (Assertion, condition [, msg]);
6728 -- So rewrite pragma in this manner, and analyze the result
6730 Expr := Get_Pragma_Arg (Arg1);
6732 Make_Pragma_Argument_Association (Loc,
6733 Expression => Make_Identifier (Loc, Name_Assertion)),
6735 Make_Pragma_Argument_Association (Sloc (Expr),
6736 Expression => Expr));
6738 if Arg_Count > 1 then
6739 Check_Optional_Identifier (Arg2, Name_Message);
6740 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6741 Append_To (Newa, Relocate_Node (Arg2));
6746 Chars => Name_Check,
6747 Pragma_Argument_Associations => Newa));
6751 ----------------------
6752 -- Assertion_Policy --
6753 ----------------------
6755 -- pragma Assertion_Policy (Check | Disable |Ignore)
6757 when Pragma_Assertion_Policy => Assertion_Policy : declare
6762 Check_Valid_Configuration_Pragma;
6763 Check_Arg_Count (1);
6764 Check_No_Identifiers;
6765 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6767 -- We treat pragma Assertion_Policy as equivalent to:
6769 -- pragma Check_Policy (Assertion, policy)
6771 -- So rewrite the pragma in that manner and link on to the chain
6772 -- of Check_Policy pragmas, marking the pragma as analyzed.
6774 Policy := Get_Pragma_Arg (Arg1);
6778 Chars => Name_Check_Policy,
6780 Pragma_Argument_Associations => New_List (
6781 Make_Pragma_Argument_Association (Loc,
6782 Expression => Make_Identifier (Loc, Name_Assertion)),
6784 Make_Pragma_Argument_Association (Loc,
6786 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6789 Set_Next_Pragma (N, Opt.Check_Policy_List);
6790 Opt.Check_Policy_List := N;
6791 end Assertion_Policy;
6793 ------------------------------
6794 -- Assume_No_Invalid_Values --
6795 ------------------------------
6797 -- pragma Assume_No_Invalid_Values (On | Off);
6799 when Pragma_Assume_No_Invalid_Values =>
6801 Check_Valid_Configuration_Pragma;
6802 Check_Arg_Count (1);
6803 Check_No_Identifiers;
6804 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6806 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6807 Assume_No_Invalid_Values := True;
6809 Assume_No_Invalid_Values := False;
6816 -- pragma AST_Entry (entry_IDENTIFIER);
6818 when Pragma_AST_Entry => AST_Entry : declare
6824 Check_Arg_Count (1);
6825 Check_No_Identifiers;
6826 Check_Arg_Is_Local_Name (Arg1);
6827 Ent := Entity (Get_Pragma_Arg (Arg1));
6829 -- Note: the implementation of the AST_Entry pragma could handle
6830 -- the entry family case fine, but for now we are consistent with
6831 -- the DEC rules, and do not allow the pragma, which of course
6832 -- has the effect of also forbidding the attribute.
6834 if Ekind (Ent) /= E_Entry then
6836 ("pragma% argument must be simple entry name", Arg1);
6838 elsif Is_AST_Entry (Ent) then
6840 ("duplicate % pragma for entry", Arg1);
6842 elsif Has_Homonym (Ent) then
6844 ("pragma% argument cannot specify overloaded entry", Arg1);
6848 FF : constant Entity_Id := First_Formal (Ent);
6851 if Present (FF) then
6852 if Present (Next_Formal (FF)) then
6854 ("entry for pragma% can have only one argument",
6857 elsif Parameter_Mode (FF) /= E_In_Parameter then
6859 ("entry parameter for pragma% must have mode IN",
6865 Set_Is_AST_Entry (Ent);
6873 -- pragma Asynchronous (LOCAL_NAME);
6875 when Pragma_Asynchronous => Asynchronous : declare
6883 procedure Process_Async_Pragma;
6884 -- Common processing for procedure and access-to-procedure case
6886 --------------------------
6887 -- Process_Async_Pragma --
6888 --------------------------
6890 procedure Process_Async_Pragma is
6893 Set_Is_Asynchronous (Nm);
6897 -- The formals should be of mode IN (RM E.4.1(6))
6900 while Present (S) loop
6901 Formal := Defining_Identifier (S);
6903 if Nkind (Formal) = N_Defining_Identifier
6904 and then Ekind (Formal) /= E_In_Parameter
6907 ("pragma% procedure can only have IN parameter",
6914 Set_Is_Asynchronous (Nm);
6915 end Process_Async_Pragma;
6917 -- Start of processing for pragma Asynchronous
6920 Check_Ada_83_Warning;
6921 Check_No_Identifiers;
6922 Check_Arg_Count (1);
6923 Check_Arg_Is_Local_Name (Arg1);
6925 if Debug_Flag_U then
6929 C_Ent := Cunit_Entity (Current_Sem_Unit);
6930 Analyze (Get_Pragma_Arg (Arg1));
6931 Nm := Entity (Get_Pragma_Arg (Arg1));
6933 if not Is_Remote_Call_Interface (C_Ent)
6934 and then not Is_Remote_Types (C_Ent)
6936 -- This pragma should only appear in an RCI or Remote Types
6937 -- unit (RM E.4.1(4)).
6940 ("pragma% not in Remote_Call_Interface or " &
6941 "Remote_Types unit");
6944 if Ekind (Nm) = E_Procedure
6945 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6947 if not Is_Remote_Call_Interface (Nm) then
6949 ("pragma% cannot be applied on non-remote procedure",
6953 L := Parameter_Specifications (Parent (Nm));
6954 Process_Async_Pragma;
6957 elsif Ekind (Nm) = E_Function then
6959 ("pragma% cannot be applied to function", Arg1);
6961 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6962 if Is_Record_Type (Nm) then
6964 -- A record type that is the Equivalent_Type for a remote
6965 -- access-to-subprogram type.
6967 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6970 -- A non-expanded RAS type (distribution is not enabled)
6972 N := Declaration_Node (Nm);
6975 if Nkind (N) = N_Full_Type_Declaration
6976 and then Nkind (Type_Definition (N)) =
6977 N_Access_Procedure_Definition
6979 L := Parameter_Specifications (Type_Definition (N));
6980 Process_Async_Pragma;
6982 if Is_Asynchronous (Nm)
6983 and then Expander_Active
6984 and then Get_PCS_Name /= Name_No_DSA
6986 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6991 ("pragma% cannot reference access-to-function type",
6995 -- Only other possibility is Access-to-class-wide type
6997 elsif Is_Access_Type (Nm)
6998 and then Is_Class_Wide_Type (Designated_Type (Nm))
7000 Check_First_Subtype (Arg1);
7001 Set_Is_Asynchronous (Nm);
7002 if Expander_Active then
7003 RACW_Type_Is_Asynchronous (Nm);
7007 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
7015 -- pragma Atomic (LOCAL_NAME);
7017 when Pragma_Atomic =>
7018 Process_Atomic_Shared_Volatile;
7020 -----------------------
7021 -- Atomic_Components --
7022 -----------------------
7024 -- pragma Atomic_Components (array_LOCAL_NAME);
7026 -- This processing is shared by Volatile_Components
7028 when Pragma_Atomic_Components |
7029 Pragma_Volatile_Components =>
7031 Atomic_Components : declare
7038 Check_Ada_83_Warning;
7039 Check_No_Identifiers;
7040 Check_Arg_Count (1);
7041 Check_Arg_Is_Local_Name (Arg1);
7042 E_Id := Get_Pragma_Arg (Arg1);
7044 if Etype (E_Id) = Any_Type then
7050 Check_Duplicate_Pragma (E);
7052 if Rep_Item_Too_Early (E, N)
7054 Rep_Item_Too_Late (E, N)
7059 D := Declaration_Node (E);
7062 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7064 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7065 and then Nkind (D) = N_Object_Declaration
7066 and then Nkind (Object_Definition (D)) =
7067 N_Constrained_Array_Definition)
7069 -- The flag is set on the object, or on the base type
7071 if Nkind (D) /= N_Object_Declaration then
7075 Set_Has_Volatile_Components (E);
7077 if Prag_Id = Pragma_Atomic_Components then
7078 Set_Has_Atomic_Components (E);
7082 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7084 end Atomic_Components;
7085 --------------------
7086 -- Attach_Handler --
7087 --------------------
7089 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7091 when Pragma_Attach_Handler =>
7092 Check_Ada_83_Warning;
7093 Check_No_Identifiers;
7094 Check_Arg_Count (2);
7096 if No_Run_Time_Mode then
7097 Error_Msg_CRT ("Attach_Handler pragma", N);
7099 Check_Interrupt_Or_Attach_Handler;
7101 -- The expression that designates the attribute may depend on a
7102 -- discriminant, and is therefore a per-object expression, to
7103 -- be expanded in the init proc. If expansion is enabled, then
7104 -- perform semantic checks on a copy only.
7106 if Expander_Active then
7108 Temp : constant Node_Id :=
7109 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7111 Set_Parent (Temp, N);
7112 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7116 Analyze (Get_Pragma_Arg (Arg2));
7117 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7120 Process_Interrupt_Or_Attach_Handler;
7123 --------------------
7124 -- C_Pass_By_Copy --
7125 --------------------
7127 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7129 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7135 Check_Valid_Configuration_Pragma;
7136 Check_Arg_Count (1);
7137 Check_Optional_Identifier (Arg1, "max_size");
7139 Arg := Get_Pragma_Arg (Arg1);
7140 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7142 Val := Expr_Value (Arg);
7146 ("maximum size for pragma% must be positive", Arg1);
7148 elsif UI_Is_In_Int_Range (Val) then
7149 Default_C_Record_Mechanism := UI_To_Int (Val);
7151 -- If a giant value is given, Int'Last will do well enough.
7152 -- If sometime someone complains that a record larger than
7153 -- two gigabytes is not copied, we will worry about it then!
7156 Default_C_Record_Mechanism := Mechanism_Type'Last;
7164 -- pragma Check ([Name =>] IDENTIFIER,
7165 -- [Check =>] Boolean_EXPRESSION
7166 -- [,[Message =>] String_EXPRESSION]);
7168 when Pragma_Check => Check : declare
7173 -- Set True if category of assertions referenced by Name enabled
7177 Check_At_Least_N_Arguments (2);
7178 Check_At_Most_N_Arguments (3);
7179 Check_Optional_Identifier (Arg1, Name_Name);
7180 Check_Optional_Identifier (Arg2, Name_Check);
7182 if Arg_Count = 3 then
7183 Check_Optional_Identifier (Arg3, Name_Message);
7184 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7187 Check_Arg_Is_Identifier (Arg1);
7189 -- Completely ignore if disabled
7191 if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7192 Rewrite (N, Make_Null_Statement (Loc));
7197 -- Indicate if pragma is enabled. The Original_Node reference here
7198 -- is to deal with pragma Assert rewritten as a Check pragma.
7200 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
7203 Set_SCO_Pragma_Enabled (Loc);
7206 -- If expansion is active and the check is not enabled then we
7207 -- rewrite the Check as:
7209 -- if False and then condition then
7213 -- The reason we do this rewriting during semantic analysis rather
7214 -- than as part of normal expansion is that we cannot analyze and
7215 -- expand the code for the boolean expression directly, or it may
7216 -- cause insertion of actions that would escape the attempt to
7217 -- suppress the check code.
7219 -- Note that the Sloc for the if statement corresponds to the
7220 -- argument condition, not the pragma itself. The reason for this
7221 -- is that we may generate a warning if the condition is False at
7222 -- compile time, and we do not want to delete this warning when we
7223 -- delete the if statement.
7225 Expr := Get_Pragma_Arg (Arg2);
7227 if Expander_Active and then not Check_On then
7228 Eloc := Sloc (Expr);
7231 Make_If_Statement (Eloc,
7233 Make_And_Then (Eloc,
7234 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7235 Right_Opnd => Expr),
7236 Then_Statements => New_List (
7237 Make_Null_Statement (Eloc))));
7244 Analyze_And_Resolve (Expr, Any_Boolean);
7252 -- pragma Check_Name (check_IDENTIFIER);
7254 when Pragma_Check_Name =>
7255 Check_No_Identifiers;
7257 Check_Valid_Configuration_Pragma;
7258 Check_Arg_Count (1);
7259 Check_Arg_Is_Identifier (Arg1);
7262 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7265 for J in Check_Names.First .. Check_Names.Last loop
7266 if Check_Names.Table (J) = Nam then
7271 Check_Names.Append (Nam);
7278 -- pragma Check_Policy (
7279 -- [Name =>] IDENTIFIER,
7280 -- [Policy =>] POLICY_IDENTIFIER);
7282 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7284 -- Note: this is a configuration pragma, but it is allowed to appear
7287 when Pragma_Check_Policy =>
7289 Check_Arg_Count (2);
7290 Check_Optional_Identifier (Arg1, Name_Name);
7291 Check_Optional_Identifier (Arg2, Name_Policy);
7293 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7295 -- A Check_Policy pragma can appear either as a configuration
7296 -- pragma, or in a declarative part or a package spec (see RM
7297 -- 11.5(5) for rules for Suppress/Unsuppress which are also
7298 -- followed for Check_Policy).
7300 if not Is_Configuration_Pragma then
7301 Check_Is_In_Decl_Part_Or_Package_Spec;
7304 Set_Next_Pragma (N, Opt.Check_Policy_List);
7305 Opt.Check_Policy_List := N;
7307 ---------------------
7308 -- CIL_Constructor --
7309 ---------------------
7311 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7313 -- Processing for this pragma is shared with Java_Constructor
7319 -- pragma Comment (static_string_EXPRESSION)
7321 -- Processing for pragma Comment shares the circuitry for pragma
7322 -- Ident. The only differences are that Ident enforces a limit of 31
7323 -- characters on its argument, and also enforces limitations on
7324 -- placement for DEC compatibility. Pragma Comment shares neither of
7325 -- these restrictions.
7331 -- pragma Common_Object (
7332 -- [Internal =>] LOCAL_NAME
7333 -- [, [External =>] EXTERNAL_SYMBOL]
7334 -- [, [Size =>] EXTERNAL_SYMBOL]);
7336 -- Processing for this pragma is shared with Psect_Object
7338 ------------------------
7339 -- Compile_Time_Error --
7340 ------------------------
7342 -- pragma Compile_Time_Error
7343 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7345 when Pragma_Compile_Time_Error =>
7347 Process_Compile_Time_Warning_Or_Error;
7349 --------------------------
7350 -- Compile_Time_Warning --
7351 --------------------------
7353 -- pragma Compile_Time_Warning
7354 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7356 when Pragma_Compile_Time_Warning =>
7358 Process_Compile_Time_Warning_Or_Error;
7364 when Pragma_Compiler_Unit =>
7366 Check_Arg_Count (0);
7367 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7369 -----------------------------
7370 -- Complete_Representation --
7371 -----------------------------
7373 -- pragma Complete_Representation;
7375 when Pragma_Complete_Representation =>
7377 Check_Arg_Count (0);
7379 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7381 ("pragma & must appear within record representation clause");
7384 ----------------------------
7385 -- Complex_Representation --
7386 ----------------------------
7388 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7390 when Pragma_Complex_Representation => Complex_Representation : declare
7397 Check_Arg_Count (1);
7398 Check_Optional_Identifier (Arg1, Name_Entity);
7399 Check_Arg_Is_Local_Name (Arg1);
7400 E_Id := Get_Pragma_Arg (Arg1);
7402 if Etype (E_Id) = Any_Type then
7408 if not Is_Record_Type (E) then
7410 ("argument for pragma% must be record type", Arg1);
7413 Ent := First_Entity (E);
7416 or else No (Next_Entity (Ent))
7417 or else Present (Next_Entity (Next_Entity (Ent)))
7418 or else not Is_Floating_Point_Type (Etype (Ent))
7419 or else Etype (Ent) /= Etype (Next_Entity (Ent))
7422 ("record for pragma% must have two fields of the same "
7423 & "floating-point type", Arg1);
7426 Set_Has_Complex_Representation (Base_Type (E));
7428 -- We need to treat the type has having a non-standard
7429 -- representation, for back-end purposes, even though in
7430 -- general a complex will have the default representation
7431 -- of a record with two real components.
7433 Set_Has_Non_Standard_Rep (Base_Type (E));
7435 end Complex_Representation;
7437 -------------------------
7438 -- Component_Alignment --
7439 -------------------------
7441 -- pragma Component_Alignment (
7442 -- [Form =>] ALIGNMENT_CHOICE
7443 -- [, [Name =>] type_LOCAL_NAME]);
7445 -- ALIGNMENT_CHOICE ::=
7447 -- | Component_Size_4
7451 when Pragma_Component_Alignment => Component_AlignmentP : declare
7452 Args : Args_List (1 .. 2);
7453 Names : constant Name_List (1 .. 2) := (
7457 Form : Node_Id renames Args (1);
7458 Name : Node_Id renames Args (2);
7460 Atype : Component_Alignment_Kind;
7465 Gather_Associations (Names, Args);
7468 Error_Pragma ("missing Form argument for pragma%");
7471 Check_Arg_Is_Identifier (Form);
7473 -- Get proper alignment, note that Default = Component_Size on all
7474 -- machines we have so far, and we want to set this value rather
7475 -- than the default value to indicate that it has been explicitly
7476 -- set (and thus will not get overridden by the default component
7477 -- alignment for the current scope)
7479 if Chars (Form) = Name_Component_Size then
7480 Atype := Calign_Component_Size;
7482 elsif Chars (Form) = Name_Component_Size_4 then
7483 Atype := Calign_Component_Size_4;
7485 elsif Chars (Form) = Name_Default then
7486 Atype := Calign_Component_Size;
7488 elsif Chars (Form) = Name_Storage_Unit then
7489 Atype := Calign_Storage_Unit;
7493 ("invalid Form parameter for pragma%", Form);
7496 -- Case with no name, supplied, affects scope table entry
7500 (Scope_Stack.Last).Component_Alignment_Default := Atype;
7502 -- Case of name supplied
7505 Check_Arg_Is_Local_Name (Name);
7507 Typ := Entity (Name);
7510 or else Rep_Item_Too_Early (Typ, N)
7514 Typ := Underlying_Type (Typ);
7517 if not Is_Record_Type (Typ)
7518 and then not Is_Array_Type (Typ)
7521 ("Name parameter of pragma% must identify record or " &
7522 "array type", Name);
7525 -- An explicit Component_Alignment pragma overrides an
7526 -- implicit pragma Pack, but not an explicit one.
7528 if not Has_Pragma_Pack (Base_Type (Typ)) then
7529 Set_Is_Packed (Base_Type (Typ), False);
7530 Set_Component_Alignment (Base_Type (Typ), Atype);
7533 end Component_AlignmentP;
7539 -- pragma Controlled (first_subtype_LOCAL_NAME);
7541 when Pragma_Controlled => Controlled : declare
7545 Check_No_Identifiers;
7546 Check_Arg_Count (1);
7547 Check_Arg_Is_Local_Name (Arg1);
7548 Arg := Get_Pragma_Arg (Arg1);
7550 if not Is_Entity_Name (Arg)
7551 or else not Is_Access_Type (Entity (Arg))
7553 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7555 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7563 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
7564 -- [Entity =>] LOCAL_NAME);
7566 when Pragma_Convention => Convention : declare
7569 pragma Warnings (Off, C);
7570 pragma Warnings (Off, E);
7572 Check_Arg_Order ((Name_Convention, Name_Entity));
7573 Check_Ada_83_Warning;
7574 Check_Arg_Count (2);
7575 Process_Convention (C, E);
7578 ---------------------------
7579 -- Convention_Identifier --
7580 ---------------------------
7582 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7583 -- [Convention =>] convention_IDENTIFIER);
7585 when Pragma_Convention_Identifier => Convention_Identifier : declare
7591 Check_Arg_Order ((Name_Name, Name_Convention));
7592 Check_Arg_Count (2);
7593 Check_Optional_Identifier (Arg1, Name_Name);
7594 Check_Optional_Identifier (Arg2, Name_Convention);
7595 Check_Arg_Is_Identifier (Arg1);
7596 Check_Arg_Is_Identifier (Arg2);
7597 Idnam := Chars (Get_Pragma_Arg (Arg1));
7598 Cname := Chars (Get_Pragma_Arg (Arg2));
7600 if Is_Convention_Name (Cname) then
7601 Record_Convention_Identifier
7602 (Idnam, Get_Convention_Id (Cname));
7605 ("second arg for % pragma must be convention", Arg2);
7607 end Convention_Identifier;
7613 -- pragma CPP_Class ([Entity =>] local_NAME)
7615 when Pragma_CPP_Class => CPP_Class : declare
7620 if Warn_On_Obsolescent_Feature then
7622 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7623 " by pragma import?", N);
7627 Check_Arg_Count (1);
7628 Check_Optional_Identifier (Arg1, Name_Entity);
7629 Check_Arg_Is_Local_Name (Arg1);
7631 Arg := Get_Pragma_Arg (Arg1);
7634 if Etype (Arg) = Any_Type then
7638 if not Is_Entity_Name (Arg)
7639 or else not Is_Type (Entity (Arg))
7641 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7644 Typ := Entity (Arg);
7646 if not Is_Tagged_Type (Typ) then
7647 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7650 -- Types treated as CPP classes must be declared limited (note:
7651 -- this used to be a warning but there is no real benefit to it
7652 -- since we did effectively intend to treat the type as limited
7655 if not Is_Limited_Type (Typ) then
7657 ("imported 'C'P'P type must be limited",
7658 Get_Pragma_Arg (Arg1));
7661 Set_Is_CPP_Class (Typ);
7662 Set_Convention (Typ, Convention_CPP);
7664 -- Imported CPP types must not have discriminants (because C++
7665 -- classes do not have discriminants).
7667 if Has_Discriminants (Typ) then
7669 ("imported 'C'P'P type cannot have discriminants",
7670 First (Discriminant_Specifications
7671 (Declaration_Node (Typ))));
7674 -- Components of imported CPP types must not have default
7675 -- expressions because the constructor (if any) is in the
7678 if Is_Incomplete_Or_Private_Type (Typ)
7679 and then No (Underlying_Type (Typ))
7681 -- It should be an error to apply pragma CPP to a private
7682 -- type if the underlying type is not visible (as it is
7683 -- for any representation item). For now, for backward
7684 -- compatibility we do nothing but we cannot check components
7685 -- because they are not available at this stage. All this code
7686 -- will be removed when we cleanup this obsolete GNAT pragma???
7692 Tdef : constant Node_Id :=
7693 Type_Definition (Declaration_Node (Typ));
7698 if Nkind (Tdef) = N_Record_Definition then
7699 Clist := Component_List (Tdef);
7701 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7702 Clist := Component_List (Record_Extension_Part (Tdef));
7705 if Present (Clist) then
7706 Comp := First (Component_Items (Clist));
7707 while Present (Comp) loop
7708 if Present (Expression (Comp)) then
7710 ("component of imported 'C'P'P type cannot have" &
7711 " default expression", Expression (Comp));
7721 ---------------------
7722 -- CPP_Constructor --
7723 ---------------------
7725 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7726 -- [, [External_Name =>] static_string_EXPRESSION ]
7727 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7729 when Pragma_CPP_Constructor => CPP_Constructor : declare
7733 Tag_Typ : Entity_Id;
7737 Check_At_Least_N_Arguments (1);
7738 Check_At_Most_N_Arguments (3);
7739 Check_Optional_Identifier (Arg1, Name_Entity);
7740 Check_Arg_Is_Local_Name (Arg1);
7742 Id := Get_Pragma_Arg (Arg1);
7743 Find_Program_Unit_Name (Id);
7745 -- If we did not find the name, we are done
7747 if Etype (Id) = Any_Type then
7751 Def_Id := Entity (Id);
7753 -- Check if already defined as constructor
7755 if Is_Constructor (Def_Id) then
7757 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7761 if Ekind (Def_Id) = E_Function
7762 and then (Is_CPP_Class (Etype (Def_Id))
7763 or else (Is_Class_Wide_Type (Etype (Def_Id))
7765 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7767 if Arg_Count >= 2 then
7768 Set_Imported (Def_Id);
7769 Set_Is_Public (Def_Id);
7770 Process_Interface_Name (Def_Id, Arg2, Arg3);
7773 Set_Has_Completion (Def_Id);
7774 Set_Is_Constructor (Def_Id);
7776 -- Imported C++ constructors are not dispatching primitives
7777 -- because in C++ they don't have a dispatch table slot.
7778 -- However, in Ada the constructor has the profile of a
7779 -- function that returns a tagged type and therefore it has
7780 -- been treated as a primitive operation during semantic
7781 -- analysis. We now remove it from the list of primitive
7782 -- operations of the type.
7784 if Is_Tagged_Type (Etype (Def_Id))
7785 and then not Is_Class_Wide_Type (Etype (Def_Id))
7787 pragma Assert (Is_Dispatching_Operation (Def_Id));
7788 Tag_Typ := Etype (Def_Id);
7790 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7791 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7795 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7796 Set_Is_Dispatching_Operation (Def_Id, False);
7799 -- For backward compatibility, if the constructor returns a
7800 -- class wide type, and we internally change the return type to
7801 -- the corresponding root type.
7803 if Is_Class_Wide_Type (Etype (Def_Id)) then
7804 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7808 ("pragma% requires function returning a 'C'P'P_Class type",
7811 end CPP_Constructor;
7817 when Pragma_CPP_Virtual => CPP_Virtual : declare
7821 if Warn_On_Obsolescent_Feature then
7823 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7832 when Pragma_CPP_Vtable => CPP_Vtable : declare
7836 if Warn_On_Obsolescent_Feature then
7838 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7847 -- pragma CPU (EXPRESSION);
7849 when Pragma_CPU => CPU : declare
7850 P : constant Node_Id := Parent (N);
7855 Check_No_Identifiers;
7856 Check_Arg_Count (1);
7860 if Nkind (P) = N_Subprogram_Body then
7861 Check_In_Main_Program;
7863 Arg := Get_Pragma_Arg (Arg1);
7864 Analyze_And_Resolve (Arg, Any_Integer);
7868 if not Is_Static_Expression (Arg) then
7869 Flag_Non_Static_Expr
7870 ("main subprogram affinity is not static!", Arg);
7873 -- If constraint error, then we already signalled an error
7875 elsif Raises_Constraint_Error (Arg) then
7878 -- Otherwise check in range
7882 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7883 -- This is the entity System.Multiprocessors.CPU_Range;
7885 Val : constant Uint := Expr_Value (Arg);
7888 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7890 Val > Expr_Value (Type_High_Bound (CPU_Id))
7893 ("main subprogram CPU is out of range", Arg1);
7899 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7903 elsif Nkind (P) = N_Task_Definition then
7904 Arg := Get_Pragma_Arg (Arg1);
7906 -- The expression must be analyzed in the special manner
7907 -- described in "Handling of Default and Per-Object
7908 -- Expressions" in sem.ads.
7910 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7912 -- Anything else is incorrect
7918 if Has_Pragma_CPU (P) then
7919 Error_Pragma ("duplicate pragma% not allowed");
7921 Set_Has_Pragma_CPU (P, True);
7923 if Nkind (P) = N_Task_Definition then
7924 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7933 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7935 when Pragma_Debug => Debug : declare
7942 -- Skip analysis if disabled
7944 if Debug_Pragmas_Disabled then
7945 Rewrite (N, Make_Null_Statement (Loc));
7952 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7955 if Debug_Pragmas_Enabled then
7956 Set_SCO_Pragma_Enabled (Loc);
7959 if Arg_Count = 2 then
7962 Left_Opnd => Relocate_Node (Cond),
7963 Right_Opnd => Get_Pragma_Arg (Arg1));
7964 Call := Get_Pragma_Arg (Arg2);
7966 Call := Get_Pragma_Arg (Arg1);
7970 N_Indexed_Component,
7974 N_Selected_Component)
7976 -- If this pragma Debug comes from source, its argument was
7977 -- parsed as a name form (which is syntactically identical).
7978 -- In a generic context a parameterless call will be left as
7979 -- an expanded name (if global) or selected_component if local.
7980 -- Change it to a procedure call statement now.
7982 Change_Name_To_Procedure_Call_Statement (Call);
7984 elsif Nkind (Call) = N_Procedure_Call_Statement then
7986 -- Already in the form of a procedure call statement: nothing
7987 -- to do (could happen in case of an internally generated
7993 -- All other cases: diagnose error
7996 ("argument of pragma ""Debug"" is not procedure call",
8001 -- Rewrite into a conditional with an appropriate condition. We
8002 -- wrap the procedure call in a block so that overhead from e.g.
8003 -- use of the secondary stack does not generate execution overhead
8004 -- for suppressed conditions.
8006 -- Normally the analysis that follows will freeze the subprogram
8007 -- being called. However, if the call is to a null procedure,
8008 -- we want to freeze it before creating the block, because the
8009 -- analysis that follows may be done with expansion disabled, in
8010 -- which case the body will not be generated, leading to spurious
8013 if Nkind (Call) = N_Procedure_Call_Statement
8014 and then Is_Entity_Name (Name (Call))
8016 Analyze (Name (Call));
8017 Freeze_Before (N, Entity (Name (Call)));
8020 Rewrite (N, Make_Implicit_If_Statement (N,
8022 Then_Statements => New_List (
8023 Make_Block_Statement (Loc,
8024 Handled_Statement_Sequence =>
8025 Make_Handled_Sequence_Of_Statements (Loc,
8026 Statements => New_List (Relocate_Node (Call)))))));
8034 -- pragma Debug_Policy (Check | Ignore)
8036 when Pragma_Debug_Policy =>
8038 Check_Arg_Count (1);
8039 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
8040 Debug_Pragmas_Enabled :=
8041 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
8042 Debug_Pragmas_Disabled :=
8043 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
8045 ---------------------
8046 -- Detect_Blocking --
8047 ---------------------
8049 -- pragma Detect_Blocking;
8051 when Pragma_Detect_Blocking =>
8053 Check_Arg_Count (0);
8054 Check_Valid_Configuration_Pragma;
8055 Detect_Blocking := True;
8057 --------------------------
8058 -- Default_Storage_Pool --
8059 --------------------------
8061 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
8063 when Pragma_Default_Storage_Pool =>
8065 Check_Arg_Count (1);
8067 -- Default_Storage_Pool can appear as a configuration pragma, or
8068 -- in a declarative part or a package spec.
8070 if not Is_Configuration_Pragma then
8071 Check_Is_In_Decl_Part_Or_Package_Spec;
8074 -- Case of Default_Storage_Pool (null);
8076 if Nkind (Expression (Arg1)) = N_Null then
8077 Analyze (Expression (Arg1));
8079 -- This is an odd case, this is not really an expression, so
8080 -- we don't have a type for it. So just set the type to Empty.
8082 Set_Etype (Expression (Arg1), Empty);
8084 -- Case of Default_Storage_Pool (storage_pool_NAME);
8087 -- If it's a configuration pragma, then the only allowed
8088 -- argument is "null".
8090 if Is_Configuration_Pragma then
8091 Error_Pragma_Arg ("NULL expected", Arg1);
8094 -- The expected type for a non-"null" argument is
8095 -- Root_Storage_Pool'Class.
8098 (Get_Pragma_Arg (Arg1),
8099 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8102 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
8103 -- for an access type will use this information to set the
8104 -- appropriate attributes of the access type.
8106 Default_Pool := Expression (Arg1);
8108 ------------------------------------
8109 -- Disable_Atomic_Synchronization --
8110 ------------------------------------
8112 -- pragma Disable_Atomic_Synchronization [(Entity)];
8114 when Pragma_Disable_Atomic_Synchronization =>
8115 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8121 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
8123 when Pragma_Discard_Names => Discard_Names : declare
8128 Check_Ada_83_Warning;
8130 -- Deal with configuration pragma case
8132 if Arg_Count = 0 and then Is_Configuration_Pragma then
8133 Global_Discard_Names := True;
8136 -- Otherwise, check correct appropriate context
8139 Check_Is_In_Decl_Part_Or_Package_Spec;
8141 if Arg_Count = 0 then
8143 -- If there is no parameter, then from now on this pragma
8144 -- applies to any enumeration, exception or tagged type
8145 -- defined in the current declarative part, and recursively
8146 -- to any nested scope.
8148 Set_Discard_Names (Current_Scope);
8152 Check_Arg_Count (1);
8153 Check_Optional_Identifier (Arg1, Name_On);
8154 Check_Arg_Is_Local_Name (Arg1);
8156 E_Id := Get_Pragma_Arg (Arg1);
8158 if Etype (E_Id) = Any_Type then
8164 if (Is_First_Subtype (E)
8166 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8167 or else Ekind (E) = E_Exception
8169 Set_Discard_Names (E);
8172 ("inappropriate entity for pragma%", Arg1);
8179 ------------------------
8180 -- Dispatching_Domain --
8181 ------------------------
8183 -- pragma Dispatching_Domain (EXPRESSION);
8185 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8186 P : constant Node_Id := Parent (N);
8191 Check_No_Identifiers;
8192 Check_Arg_Count (1);
8194 -- This pragma is born obsolete, but not the aspect
8196 if not From_Aspect_Specification (N) then
8198 (No_Obsolescent_Features, Pragma_Identifier (N));
8201 if Nkind (P) = N_Task_Definition then
8202 Arg := Get_Pragma_Arg (Arg1);
8204 -- The expression must be analyzed in the special manner
8205 -- described in "Handling of Default and Per-Object
8206 -- Expressions" in sem.ads.
8208 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8210 -- Anything else is incorrect
8216 if Has_Pragma_Dispatching_Domain (P) then
8217 Error_Pragma ("duplicate pragma% not allowed");
8219 Set_Has_Pragma_Dispatching_Domain (P, True);
8221 if Nkind (P) = N_Task_Definition then
8222 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8225 end Dispatching_Domain;
8231 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8233 when Pragma_Elaborate => Elaborate : declare
8238 -- Pragma must be in context items list of a compilation unit
8240 if not Is_In_Context_Clause then
8244 -- Must be at least one argument
8246 if Arg_Count = 0 then
8247 Error_Pragma ("pragma% requires at least one argument");
8250 -- In Ada 83 mode, there can be no items following it in the
8251 -- context list except other pragmas and implicit with clauses
8252 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8253 -- placement rule does not apply.
8255 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8257 while Present (Citem) loop
8258 if Nkind (Citem) = N_Pragma
8259 or else (Nkind (Citem) = N_With_Clause
8260 and then Implicit_With (Citem))
8265 ("(Ada 83) pragma% must be at end of context clause");
8272 -- Finally, the arguments must all be units mentioned in a with
8273 -- clause in the same context clause. Note we already checked (in
8274 -- Par.Prag) that the arguments are all identifiers or selected
8278 Outer : while Present (Arg) loop
8279 Citem := First (List_Containing (N));
8280 Inner : while Citem /= N loop
8281 if Nkind (Citem) = N_With_Clause
8282 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8284 Set_Elaborate_Present (Citem, True);
8285 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8286 Generate_Reference (Entity (Name (Citem)), Citem);
8288 -- With the pragma present, elaboration calls on
8289 -- subprograms from the named unit need no further
8290 -- checks, as long as the pragma appears in the current
8291 -- compilation unit. If the pragma appears in some unit
8292 -- in the context, there might still be a need for an
8293 -- Elaborate_All_Desirable from the current compilation
8294 -- to the named unit, so we keep the check enabled.
8296 if In_Extended_Main_Source_Unit (N) then
8297 Set_Suppress_Elaboration_Warnings
8298 (Entity (Name (Citem)));
8309 ("argument of pragma% is not withed unit", Arg);
8315 -- Give a warning if operating in static mode with -gnatwl
8316 -- (elaboration warnings enabled) switch set.
8318 if Elab_Warnings and not Dynamic_Elaboration_Checks then
8320 ("?use of pragma Elaborate may not be safe", N);
8322 ("?use pragma Elaborate_All instead if possible", N);
8330 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8332 when Pragma_Elaborate_All => Elaborate_All : declare
8337 Check_Ada_83_Warning;
8339 -- Pragma must be in context items list of a compilation unit
8341 if not Is_In_Context_Clause then
8345 -- Must be at least one argument
8347 if Arg_Count = 0 then
8348 Error_Pragma ("pragma% requires at least one argument");
8351 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
8352 -- have to appear at the end of the context clause, but may
8353 -- appear mixed in with other items, even in Ada 83 mode.
8355 -- Final check: the arguments must all be units mentioned in
8356 -- a with clause in the same context clause. Note that we
8357 -- already checked (in Par.Prag) that all the arguments are
8358 -- either identifiers or selected components.
8361 Outr : while Present (Arg) loop
8362 Citem := First (List_Containing (N));
8363 Innr : while Citem /= N loop
8364 if Nkind (Citem) = N_With_Clause
8365 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8367 Set_Elaborate_All_Present (Citem, True);
8368 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8370 -- Suppress warnings and elaboration checks on the named
8371 -- unit if the pragma is in the current compilation, as
8372 -- for pragma Elaborate.
8374 if In_Extended_Main_Source_Unit (N) then
8375 Set_Suppress_Elaboration_Warnings
8376 (Entity (Name (Citem)));
8385 Set_Error_Posted (N);
8387 ("argument of pragma% is not withed unit", Arg);
8394 --------------------
8395 -- Elaborate_Body --
8396 --------------------
8398 -- pragma Elaborate_Body [( library_unit_NAME )];
8400 when Pragma_Elaborate_Body => Elaborate_Body : declare
8401 Cunit_Node : Node_Id;
8402 Cunit_Ent : Entity_Id;
8405 Check_Ada_83_Warning;
8406 Check_Valid_Library_Unit_Pragma;
8408 if Nkind (N) = N_Null_Statement then
8412 Cunit_Node := Cunit (Current_Sem_Unit);
8413 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8415 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8418 Error_Pragma ("pragma% must refer to a spec, not a body");
8420 Set_Body_Required (Cunit_Node, True);
8421 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8423 -- If we are in dynamic elaboration mode, then we suppress
8424 -- elaboration warnings for the unit, since it is definitely
8425 -- fine NOT to do dynamic checks at the first level (and such
8426 -- checks will be suppressed because no elaboration boolean
8427 -- is created for Elaborate_Body packages).
8429 -- But in the static model of elaboration, Elaborate_Body is
8430 -- definitely NOT good enough to ensure elaboration safety on
8431 -- its own, since the body may WITH other units that are not
8432 -- safe from an elaboration point of view, so a client must
8433 -- still do an Elaborate_All on such units.
8435 -- Debug flag -gnatdD restores the old behavior of 3.13, where
8436 -- Elaborate_Body always suppressed elab warnings.
8438 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8439 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8444 ------------------------
8445 -- Elaboration_Checks --
8446 ------------------------
8448 -- pragma Elaboration_Checks (Static | Dynamic);
8450 when Pragma_Elaboration_Checks =>
8452 Check_Arg_Count (1);
8453 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8454 Dynamic_Elaboration_Checks :=
8455 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8461 -- pragma Eliminate (
8462 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
8463 -- [,[Entity =>] IDENTIFIER |
8464 -- SELECTED_COMPONENT |
8466 -- [, OVERLOADING_RESOLUTION]);
8468 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8471 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8474 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8476 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8477 -- Result_Type => result_SUBTYPE_NAME]
8479 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8480 -- SUBTYPE_NAME ::= STRING_LITERAL
8482 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8483 -- SOURCE_TRACE ::= STRING_LITERAL
8485 when Pragma_Eliminate => Eliminate : declare
8486 Args : Args_List (1 .. 5);
8487 Names : constant Name_List (1 .. 5) := (
8490 Name_Parameter_Types,
8492 Name_Source_Location);
8494 Unit_Name : Node_Id renames Args (1);
8495 Entity : Node_Id renames Args (2);
8496 Parameter_Types : Node_Id renames Args (3);
8497 Result_Type : Node_Id renames Args (4);
8498 Source_Location : Node_Id renames Args (5);
8502 Check_Valid_Configuration_Pragma;
8503 Gather_Associations (Names, Args);
8505 if No (Unit_Name) then
8506 Error_Pragma ("missing Unit_Name argument for pragma%");
8510 and then (Present (Parameter_Types)
8512 Present (Result_Type)
8514 Present (Source_Location))
8516 Error_Pragma ("missing Entity argument for pragma%");
8519 if (Present (Parameter_Types)
8521 Present (Result_Type))
8523 Present (Source_Location)
8526 ("parameter profile and source location cannot " &
8527 "be used together in pragma%");
8530 Process_Eliminate_Pragma
8539 -----------------------------------
8540 -- Enable_Atomic_Synchronization --
8541 -----------------------------------
8543 -- pragma Enable_Atomic_Synchronization [(Entity)];
8545 when Pragma_Enable_Atomic_Synchronization =>
8546 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
8553 -- [ Convention =>] convention_IDENTIFIER,
8554 -- [ Entity =>] local_NAME
8555 -- [, [External_Name =>] static_string_EXPRESSION ]
8556 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8558 when Pragma_Export => Export : declare
8562 pragma Warnings (Off, C);
8565 Check_Ada_83_Warning;
8571 Check_At_Least_N_Arguments (2);
8572 Check_At_Most_N_Arguments (4);
8573 Process_Convention (C, Def_Id);
8575 if Ekind (Def_Id) /= E_Constant then
8576 Note_Possible_Modification
8577 (Get_Pragma_Arg (Arg2), Sure => False);
8580 Process_Interface_Name (Def_Id, Arg3, Arg4);
8581 Set_Exported (Def_Id, Arg2);
8583 -- If the entity is a deferred constant, propagate the information
8584 -- to the full view, because gigi elaborates the full view only.
8586 if Ekind (Def_Id) = E_Constant
8587 and then Present (Full_View (Def_Id))
8590 Id2 : constant Entity_Id := Full_View (Def_Id);
8592 Set_Is_Exported (Id2, Is_Exported (Def_Id));
8593 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
8594 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8599 ----------------------
8600 -- Export_Exception --
8601 ----------------------
8603 -- pragma Export_Exception (
8604 -- [Internal =>] LOCAL_NAME
8605 -- [, [External =>] EXTERNAL_SYMBOL]
8606 -- [, [Form =>] Ada | VMS]
8607 -- [, [Code =>] static_integer_EXPRESSION]);
8609 when Pragma_Export_Exception => Export_Exception : declare
8610 Args : Args_List (1 .. 4);
8611 Names : constant Name_List (1 .. 4) := (
8617 Internal : Node_Id renames Args (1);
8618 External : Node_Id renames Args (2);
8619 Form : Node_Id renames Args (3);
8620 Code : Node_Id renames Args (4);
8625 if Inside_A_Generic then
8626 Error_Pragma ("pragma% cannot be used for generic entities");
8629 Gather_Associations (Names, Args);
8630 Process_Extended_Import_Export_Exception_Pragma (
8631 Arg_Internal => Internal,
8632 Arg_External => External,
8636 if not Is_VMS_Exception (Entity (Internal)) then
8637 Set_Exported (Entity (Internal), Internal);
8639 end Export_Exception;
8641 ---------------------
8642 -- Export_Function --
8643 ---------------------
8645 -- pragma Export_Function (
8646 -- [Internal =>] LOCAL_NAME
8647 -- [, [External =>] EXTERNAL_SYMBOL]
8648 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8649 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8650 -- [, [Mechanism =>] MECHANISM]
8651 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8653 -- EXTERNAL_SYMBOL ::=
8655 -- | static_string_EXPRESSION
8657 -- PARAMETER_TYPES ::=
8659 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8661 -- TYPE_DESIGNATOR ::=
8663 -- | subtype_Name ' Access
8667 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8669 -- MECHANISM_ASSOCIATION ::=
8670 -- [formal_parameter_NAME =>] MECHANISM_NAME
8672 -- MECHANISM_NAME ::=
8675 -- | Descriptor [([Class =>] CLASS_NAME)]
8677 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8679 when Pragma_Export_Function => Export_Function : declare
8680 Args : Args_List (1 .. 6);
8681 Names : constant Name_List (1 .. 6) := (
8684 Name_Parameter_Types,
8687 Name_Result_Mechanism);
8689 Internal : Node_Id renames Args (1);
8690 External : Node_Id renames Args (2);
8691 Parameter_Types : Node_Id renames Args (3);
8692 Result_Type : Node_Id renames Args (4);
8693 Mechanism : Node_Id renames Args (5);
8694 Result_Mechanism : Node_Id renames Args (6);
8698 Gather_Associations (Names, Args);
8699 Process_Extended_Import_Export_Subprogram_Pragma (
8700 Arg_Internal => Internal,
8701 Arg_External => External,
8702 Arg_Parameter_Types => Parameter_Types,
8703 Arg_Result_Type => Result_Type,
8704 Arg_Mechanism => Mechanism,
8705 Arg_Result_Mechanism => Result_Mechanism);
8706 end Export_Function;
8712 -- pragma Export_Object (
8713 -- [Internal =>] LOCAL_NAME
8714 -- [, [External =>] EXTERNAL_SYMBOL]
8715 -- [, [Size =>] EXTERNAL_SYMBOL]);
8717 -- EXTERNAL_SYMBOL ::=
8719 -- | static_string_EXPRESSION
8721 -- PARAMETER_TYPES ::=
8723 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8725 -- TYPE_DESIGNATOR ::=
8727 -- | subtype_Name ' Access
8731 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8733 -- MECHANISM_ASSOCIATION ::=
8734 -- [formal_parameter_NAME =>] MECHANISM_NAME
8736 -- MECHANISM_NAME ::=
8739 -- | Descriptor [([Class =>] CLASS_NAME)]
8741 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8743 when Pragma_Export_Object => Export_Object : declare
8744 Args : Args_List (1 .. 3);
8745 Names : constant Name_List (1 .. 3) := (
8750 Internal : Node_Id renames Args (1);
8751 External : Node_Id renames Args (2);
8752 Size : Node_Id renames Args (3);
8756 Gather_Associations (Names, Args);
8757 Process_Extended_Import_Export_Object_Pragma (
8758 Arg_Internal => Internal,
8759 Arg_External => External,
8763 ----------------------
8764 -- Export_Procedure --
8765 ----------------------
8767 -- pragma Export_Procedure (
8768 -- [Internal =>] LOCAL_NAME
8769 -- [, [External =>] EXTERNAL_SYMBOL]
8770 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8771 -- [, [Mechanism =>] MECHANISM]);
8773 -- EXTERNAL_SYMBOL ::=
8775 -- | static_string_EXPRESSION
8777 -- PARAMETER_TYPES ::=
8779 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8781 -- TYPE_DESIGNATOR ::=
8783 -- | subtype_Name ' Access
8787 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8789 -- MECHANISM_ASSOCIATION ::=
8790 -- [formal_parameter_NAME =>] MECHANISM_NAME
8792 -- MECHANISM_NAME ::=
8795 -- | Descriptor [([Class =>] CLASS_NAME)]
8797 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8799 when Pragma_Export_Procedure => Export_Procedure : declare
8800 Args : Args_List (1 .. 4);
8801 Names : constant Name_List (1 .. 4) := (
8804 Name_Parameter_Types,
8807 Internal : Node_Id renames Args (1);
8808 External : Node_Id renames Args (2);
8809 Parameter_Types : Node_Id renames Args (3);
8810 Mechanism : Node_Id renames Args (4);
8814 Gather_Associations (Names, Args);
8815 Process_Extended_Import_Export_Subprogram_Pragma (
8816 Arg_Internal => Internal,
8817 Arg_External => External,
8818 Arg_Parameter_Types => Parameter_Types,
8819 Arg_Mechanism => Mechanism);
8820 end Export_Procedure;
8826 -- pragma Export_Value (
8827 -- [Value =>] static_integer_EXPRESSION,
8828 -- [Link_Name =>] static_string_EXPRESSION);
8830 when Pragma_Export_Value =>
8832 Check_Arg_Order ((Name_Value, Name_Link_Name));
8833 Check_Arg_Count (2);
8835 Check_Optional_Identifier (Arg1, Name_Value);
8836 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8838 Check_Optional_Identifier (Arg2, Name_Link_Name);
8839 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8841 -----------------------------
8842 -- Export_Valued_Procedure --
8843 -----------------------------
8845 -- pragma Export_Valued_Procedure (
8846 -- [Internal =>] LOCAL_NAME
8847 -- [, [External =>] EXTERNAL_SYMBOL,]
8848 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8849 -- [, [Mechanism =>] MECHANISM]);
8851 -- EXTERNAL_SYMBOL ::=
8853 -- | static_string_EXPRESSION
8855 -- PARAMETER_TYPES ::=
8857 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8859 -- TYPE_DESIGNATOR ::=
8861 -- | subtype_Name ' Access
8865 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8867 -- MECHANISM_ASSOCIATION ::=
8868 -- [formal_parameter_NAME =>] MECHANISM_NAME
8870 -- MECHANISM_NAME ::=
8873 -- | Descriptor [([Class =>] CLASS_NAME)]
8875 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8877 when Pragma_Export_Valued_Procedure =>
8878 Export_Valued_Procedure : declare
8879 Args : Args_List (1 .. 4);
8880 Names : constant Name_List (1 .. 4) := (
8883 Name_Parameter_Types,
8886 Internal : Node_Id renames Args (1);
8887 External : Node_Id renames Args (2);
8888 Parameter_Types : Node_Id renames Args (3);
8889 Mechanism : Node_Id renames Args (4);
8893 Gather_Associations (Names, Args);
8894 Process_Extended_Import_Export_Subprogram_Pragma (
8895 Arg_Internal => Internal,
8896 Arg_External => External,
8897 Arg_Parameter_Types => Parameter_Types,
8898 Arg_Mechanism => Mechanism);
8899 end Export_Valued_Procedure;
8905 -- pragma Extend_System ([Name =>] Identifier);
8907 when Pragma_Extend_System => Extend_System : declare
8910 Check_Valid_Configuration_Pragma;
8911 Check_Arg_Count (1);
8912 Check_Optional_Identifier (Arg1, Name_Name);
8913 Check_Arg_Is_Identifier (Arg1);
8915 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8918 and then Name_Buffer (1 .. 4) = "aux_"
8920 if Present (System_Extend_Pragma_Arg) then
8921 if Chars (Get_Pragma_Arg (Arg1)) =
8922 Chars (Expression (System_Extend_Pragma_Arg))
8926 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8927 Error_Pragma ("pragma% conflicts with that #");
8931 System_Extend_Pragma_Arg := Arg1;
8933 if not GNAT_Mode then
8934 System_Extend_Unit := Arg1;
8938 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8942 ------------------------
8943 -- Extensions_Allowed --
8944 ------------------------
8946 -- pragma Extensions_Allowed (ON | OFF);
8948 when Pragma_Extensions_Allowed =>
8950 Check_Arg_Count (1);
8951 Check_No_Identifiers;
8952 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8954 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8955 Extensions_Allowed := True;
8956 Ada_Version := Ada_Version_Type'Last;
8959 Extensions_Allowed := False;
8960 Ada_Version := Ada_Version_Explicit;
8967 -- pragma External (
8968 -- [ Convention =>] convention_IDENTIFIER,
8969 -- [ Entity =>] local_NAME
8970 -- [, [External_Name =>] static_string_EXPRESSION ]
8971 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8973 when Pragma_External => External : declare
8977 pragma Warnings (Off, C);
8986 Check_At_Least_N_Arguments (2);
8987 Check_At_Most_N_Arguments (4);
8988 Process_Convention (C, Def_Id);
8989 Note_Possible_Modification
8990 (Get_Pragma_Arg (Arg2), Sure => False);
8991 Process_Interface_Name (Def_Id, Arg3, Arg4);
8992 Set_Exported (Def_Id, Arg2);
8995 --------------------------
8996 -- External_Name_Casing --
8997 --------------------------
8999 -- pragma External_Name_Casing (
9000 -- UPPERCASE | LOWERCASE
9001 -- [, AS_IS | UPPERCASE | LOWERCASE]);
9003 when Pragma_External_Name_Casing => External_Name_Casing : declare
9006 Check_No_Identifiers;
9008 if Arg_Count = 2 then
9010 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
9012 case Chars (Get_Pragma_Arg (Arg2)) is
9014 Opt.External_Name_Exp_Casing := As_Is;
9016 when Name_Uppercase =>
9017 Opt.External_Name_Exp_Casing := Uppercase;
9019 when Name_Lowercase =>
9020 Opt.External_Name_Exp_Casing := Lowercase;
9027 Check_Arg_Count (1);
9030 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
9032 case Chars (Get_Pragma_Arg (Arg1)) is
9033 when Name_Uppercase =>
9034 Opt.External_Name_Imp_Casing := Uppercase;
9036 when Name_Lowercase =>
9037 Opt.External_Name_Imp_Casing := Lowercase;
9042 end External_Name_Casing;
9044 --------------------------
9045 -- Favor_Top_Level --
9046 --------------------------
9048 -- pragma Favor_Top_Level (type_NAME);
9050 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
9051 Named_Entity : Entity_Id;
9055 Check_No_Identifiers;
9056 Check_Arg_Count (1);
9057 Check_Arg_Is_Local_Name (Arg1);
9058 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
9060 -- If it's an access-to-subprogram type (in particular, not a
9061 -- subtype), set the flag on that type.
9063 if Is_Access_Subprogram_Type (Named_Entity) then
9064 Set_Can_Use_Internal_Rep (Named_Entity, False);
9066 -- Otherwise it's an error (name denotes the wrong sort of entity)
9070 ("access-to-subprogram type expected",
9071 Get_Pragma_Arg (Arg1));
9073 end Favor_Top_Level;
9079 -- pragma Fast_Math;
9081 when Pragma_Fast_Math =>
9083 Check_No_Identifiers;
9084 Check_Valid_Configuration_Pragma;
9087 ---------------------------
9088 -- Finalize_Storage_Only --
9089 ---------------------------
9091 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9093 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9094 Assoc : constant Node_Id := Arg1;
9095 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9100 Check_No_Identifiers;
9101 Check_Arg_Count (1);
9102 Check_Arg_Is_Local_Name (Arg1);
9104 Find_Type (Type_Id);
9105 Typ := Entity (Type_Id);
9108 or else Rep_Item_Too_Early (Typ, N)
9112 Typ := Underlying_Type (Typ);
9115 if not Is_Controlled (Typ) then
9116 Error_Pragma ("pragma% must specify controlled type");
9119 Check_First_Subtype (Arg1);
9121 if Finalize_Storage_Only (Typ) then
9122 Error_Pragma ("duplicate pragma%, only one allowed");
9124 elsif not Rep_Item_Too_Late (Typ, N) then
9125 Set_Finalize_Storage_Only (Base_Type (Typ), True);
9127 end Finalize_Storage;
9129 --------------------------
9130 -- Float_Representation --
9131 --------------------------
9133 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9135 -- FLOAT_REP ::= VAX_Float | IEEE_Float
9137 when Pragma_Float_Representation => Float_Representation : declare
9145 if Arg_Count = 1 then
9146 Check_Valid_Configuration_Pragma;
9148 Check_Arg_Count (2);
9149 Check_Optional_Identifier (Arg2, Name_Entity);
9150 Check_Arg_Is_Local_Name (Arg2);
9153 Check_No_Identifier (Arg1);
9154 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9156 if not OpenVMS_On_Target then
9157 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9159 ("?pragma% ignored (applies only to Open'V'M'S)");
9165 -- One argument case
9167 if Arg_Count = 1 then
9168 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9169 if Opt.Float_Format = 'I' then
9170 Error_Pragma ("'I'E'E'E format previously specified");
9173 Opt.Float_Format := 'V';
9176 if Opt.Float_Format = 'V' then
9177 Error_Pragma ("'V'A'X format previously specified");
9180 Opt.Float_Format := 'I';
9183 Set_Standard_Fpt_Formats;
9185 -- Two argument case
9188 Argx := Get_Pragma_Arg (Arg2);
9190 if not Is_Entity_Name (Argx)
9191 or else not Is_Floating_Point_Type (Entity (Argx))
9194 ("second argument of% pragma must be floating-point type",
9198 Ent := Entity (Argx);
9199 Digs := UI_To_Int (Digits_Value (Ent));
9201 -- Two arguments, VAX_Float case
9203 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9205 when 6 => Set_F_Float (Ent);
9206 when 9 => Set_D_Float (Ent);
9207 when 15 => Set_G_Float (Ent);
9211 ("wrong digits value, must be 6,9 or 15", Arg2);
9214 -- Two arguments, IEEE_Float case
9218 when 6 => Set_IEEE_Short (Ent);
9219 when 15 => Set_IEEE_Long (Ent);
9223 ("wrong digits value, must be 6 or 15", Arg2);
9227 end Float_Representation;
9233 -- pragma Ident (static_string_EXPRESSION)
9235 -- Note: pragma Comment shares this processing. Pragma Comment is
9236 -- identical to Ident, except that the restriction of the argument to
9237 -- 31 characters and the placement restrictions are not enforced for
9240 when Pragma_Ident | Pragma_Comment => Ident : declare
9245 Check_Arg_Count (1);
9246 Check_No_Identifiers;
9247 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9250 -- For pragma Ident, preserve DEC compatibility by requiring the
9251 -- pragma to appear in a declarative part or package spec.
9253 if Prag_Id = Pragma_Ident then
9254 Check_Is_In_Decl_Part_Or_Package_Spec;
9257 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9264 GP := Parent (Parent (N));
9266 if Nkind_In (GP, N_Package_Declaration,
9267 N_Generic_Package_Declaration)
9272 -- If we have a compilation unit, then record the ident value,
9273 -- checking for improper duplication.
9275 if Nkind (GP) = N_Compilation_Unit then
9276 CS := Ident_String (Current_Sem_Unit);
9278 if Present (CS) then
9280 -- For Ident, we do not permit multiple instances
9282 if Prag_Id = Pragma_Ident then
9283 Error_Pragma ("duplicate% pragma not permitted");
9285 -- For Comment, we concatenate the string, unless we want
9286 -- to preserve the tree structure for ASIS.
9288 elsif not ASIS_Mode then
9289 Start_String (Strval (CS));
9290 Store_String_Char (' ');
9291 Store_String_Chars (Strval (Str));
9292 Set_Strval (CS, End_String);
9296 -- In VMS, the effect of IDENT is achieved by passing
9297 -- --identification=name as a --for-linker switch.
9299 if OpenVMS_On_Target then
9302 ("--for-linker=--identification=");
9303 String_To_Name_Buffer (Strval (Str));
9304 Store_String_Chars (Name_Buffer (1 .. Name_Len));
9306 -- Only the last processed IDENT is saved. The main
9307 -- purpose is so an IDENT associated with a main
9308 -- procedure will be used in preference to an IDENT
9309 -- associated with a with'd package.
9311 Replace_Linker_Option_String
9312 (End_String, "--for-linker=--identification=");
9315 Set_Ident_String (Current_Sem_Unit, Str);
9318 -- For subunits, we just ignore the Ident, since in GNAT these
9319 -- are not separate object files, and hence not separate units
9320 -- in the unit table.
9322 elsif Nkind (GP) = N_Subunit then
9325 -- Otherwise we have a misplaced pragma Ident, but we ignore
9326 -- this if we are in an instantiation, since it comes from
9327 -- a generic, and has no relevance to the instantiation.
9329 elsif Prag_Id = Pragma_Ident then
9330 if Instantiation_Location (Loc) = No_Location then
9331 Error_Pragma ("pragma% only allowed at outer level");
9337 ----------------------------
9338 -- Implementation_Defined --
9339 ----------------------------
9341 -- pragma Implementation_Defined (local_NAME);
9343 -- Marks previously declared entity as implementation defined. For
9344 -- an overloaded entity, applies to the most recent homonym.
9346 -- pragma Implementation_Defined;
9348 -- The form with no arguments appears anywhere within a scope, most
9349 -- typically a package spec, and indicates that all entities that are
9350 -- defined within the package spec are Implementation_Defined.
9352 when Pragma_Implementation_Defined => Implementation_Defined : declare
9356 Check_No_Identifiers;
9358 -- Form with no arguments
9360 if Arg_Count = 0 then
9361 Set_Is_Implementation_Defined (Current_Scope);
9363 -- Form with one argument
9366 Check_Arg_Count (1);
9367 Check_Arg_Is_Local_Name (Arg1);
9368 Ent := Entity (Get_Pragma_Arg (Arg1));
9369 Set_Is_Implementation_Defined (Ent);
9371 end Implementation_Defined;
9377 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9378 -- implementation_kind ::=
9379 -- By_Entry | By_Protected_Procedure | By_Any | Optional
9381 -- "By_Any" and "Optional" are treated as synonyms in order to
9382 -- support Ada 2012 aspect Synchronization.
9384 when Pragma_Implemented => Implemented : declare
9385 Proc_Id : Entity_Id;
9390 Check_Arg_Count (2);
9391 Check_No_Identifiers;
9392 Check_Arg_Is_Identifier (Arg1);
9393 Check_Arg_Is_Local_Name (Arg1);
9394 Check_Arg_Is_One_Of (Arg2,
9397 Name_By_Protected_Procedure,
9400 -- Extract the name of the local procedure
9402 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9404 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9405 -- primitive procedure of a synchronized tagged type.
9407 if Ekind (Proc_Id) = E_Procedure
9408 and then Is_Primitive (Proc_Id)
9409 and then Present (First_Formal (Proc_Id))
9411 Typ := Etype (First_Formal (Proc_Id));
9413 if Is_Tagged_Type (Typ)
9416 -- Check for a protected, a synchronized or a task interface
9418 ((Is_Interface (Typ)
9419 and then Is_Synchronized_Interface (Typ))
9421 -- Check for a protected type or a task type that implements
9425 (Is_Concurrent_Record_Type (Typ)
9426 and then Present (Interfaces (Typ)))
9428 -- Check for a private record extension with keyword
9432 (Ekind_In (Typ, E_Record_Type_With_Private,
9433 E_Record_Subtype_With_Private)
9434 and then Synchronized_Present (Parent (Typ))))
9439 ("controlling formal must be of synchronized " &
9440 "tagged type", Arg1);
9444 -- Procedures declared inside a protected type must be accepted
9446 elsif Ekind (Proc_Id) = E_Procedure
9447 and then Is_Protected_Type (Scope (Proc_Id))
9451 -- The first argument is not a primitive procedure
9455 ("pragma % must be applied to a primitive procedure", Arg1);
9459 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9460 -- By_Protected_Procedure to the primitive procedure of a task
9463 if Chars (Arg2) = Name_By_Protected_Procedure
9464 and then Is_Interface (Typ)
9465 and then Is_Task_Interface (Typ)
9468 ("implementation kind By_Protected_Procedure cannot be " &
9469 "applied to a task interface primitive", Arg2);
9473 Record_Rep_Item (Proc_Id, N);
9476 ----------------------
9477 -- Implicit_Packing --
9478 ----------------------
9480 -- pragma Implicit_Packing;
9482 when Pragma_Implicit_Packing =>
9484 Check_Arg_Count (0);
9485 Implicit_Packing := True;
9492 -- [Convention =>] convention_IDENTIFIER,
9493 -- [Entity =>] local_NAME
9494 -- [, [External_Name =>] static_string_EXPRESSION ]
9495 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9497 when Pragma_Import =>
9498 Check_Ada_83_Warning;
9504 Check_At_Least_N_Arguments (2);
9505 Check_At_Most_N_Arguments (4);
9506 Process_Import_Or_Interface;
9508 ----------------------
9509 -- Import_Exception --
9510 ----------------------
9512 -- pragma Import_Exception (
9513 -- [Internal =>] LOCAL_NAME
9514 -- [, [External =>] EXTERNAL_SYMBOL]
9515 -- [, [Form =>] Ada | VMS]
9516 -- [, [Code =>] static_integer_EXPRESSION]);
9518 when Pragma_Import_Exception => Import_Exception : declare
9519 Args : Args_List (1 .. 4);
9520 Names : constant Name_List (1 .. 4) := (
9526 Internal : Node_Id renames Args (1);
9527 External : Node_Id renames Args (2);
9528 Form : Node_Id renames Args (3);
9529 Code : Node_Id renames Args (4);
9533 Gather_Associations (Names, Args);
9535 if Present (External) and then Present (Code) then
9537 ("cannot give both External and Code options for pragma%");
9540 Process_Extended_Import_Export_Exception_Pragma (
9541 Arg_Internal => Internal,
9542 Arg_External => External,
9546 if not Is_VMS_Exception (Entity (Internal)) then
9547 Set_Imported (Entity (Internal));
9549 end Import_Exception;
9551 ---------------------
9552 -- Import_Function --
9553 ---------------------
9555 -- pragma Import_Function (
9556 -- [Internal =>] LOCAL_NAME,
9557 -- [, [External =>] EXTERNAL_SYMBOL]
9558 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9559 -- [, [Result_Type =>] SUBTYPE_MARK]
9560 -- [, [Mechanism =>] MECHANISM]
9561 -- [, [Result_Mechanism =>] MECHANISM_NAME]
9562 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9564 -- EXTERNAL_SYMBOL ::=
9566 -- | static_string_EXPRESSION
9568 -- PARAMETER_TYPES ::=
9570 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9572 -- TYPE_DESIGNATOR ::=
9574 -- | subtype_Name ' Access
9578 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9580 -- MECHANISM_ASSOCIATION ::=
9581 -- [formal_parameter_NAME =>] MECHANISM_NAME
9583 -- MECHANISM_NAME ::=
9586 -- | Descriptor [([Class =>] CLASS_NAME)]
9588 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9590 when Pragma_Import_Function => Import_Function : declare
9591 Args : Args_List (1 .. 7);
9592 Names : constant Name_List (1 .. 7) := (
9595 Name_Parameter_Types,
9598 Name_Result_Mechanism,
9599 Name_First_Optional_Parameter);
9601 Internal : Node_Id renames Args (1);
9602 External : Node_Id renames Args (2);
9603 Parameter_Types : Node_Id renames Args (3);
9604 Result_Type : Node_Id renames Args (4);
9605 Mechanism : Node_Id renames Args (5);
9606 Result_Mechanism : Node_Id renames Args (6);
9607 First_Optional_Parameter : Node_Id renames Args (7);
9611 Gather_Associations (Names, Args);
9612 Process_Extended_Import_Export_Subprogram_Pragma (
9613 Arg_Internal => Internal,
9614 Arg_External => External,
9615 Arg_Parameter_Types => Parameter_Types,
9616 Arg_Result_Type => Result_Type,
9617 Arg_Mechanism => Mechanism,
9618 Arg_Result_Mechanism => Result_Mechanism,
9619 Arg_First_Optional_Parameter => First_Optional_Parameter);
9620 end Import_Function;
9626 -- pragma Import_Object (
9627 -- [Internal =>] LOCAL_NAME
9628 -- [, [External =>] EXTERNAL_SYMBOL]
9629 -- [, [Size =>] EXTERNAL_SYMBOL]);
9631 -- EXTERNAL_SYMBOL ::=
9633 -- | static_string_EXPRESSION
9635 when Pragma_Import_Object => Import_Object : declare
9636 Args : Args_List (1 .. 3);
9637 Names : constant Name_List (1 .. 3) := (
9642 Internal : Node_Id renames Args (1);
9643 External : Node_Id renames Args (2);
9644 Size : Node_Id renames Args (3);
9648 Gather_Associations (Names, Args);
9649 Process_Extended_Import_Export_Object_Pragma (
9650 Arg_Internal => Internal,
9651 Arg_External => External,
9655 ----------------------
9656 -- Import_Procedure --
9657 ----------------------
9659 -- pragma Import_Procedure (
9660 -- [Internal =>] LOCAL_NAME
9661 -- [, [External =>] EXTERNAL_SYMBOL]
9662 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9663 -- [, [Mechanism =>] MECHANISM]
9664 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9666 -- EXTERNAL_SYMBOL ::=
9668 -- | static_string_EXPRESSION
9670 -- PARAMETER_TYPES ::=
9672 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9674 -- TYPE_DESIGNATOR ::=
9676 -- | subtype_Name ' Access
9680 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9682 -- MECHANISM_ASSOCIATION ::=
9683 -- [formal_parameter_NAME =>] MECHANISM_NAME
9685 -- MECHANISM_NAME ::=
9688 -- | Descriptor [([Class =>] CLASS_NAME)]
9690 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9692 when Pragma_Import_Procedure => Import_Procedure : declare
9693 Args : Args_List (1 .. 5);
9694 Names : constant Name_List (1 .. 5) := (
9697 Name_Parameter_Types,
9699 Name_First_Optional_Parameter);
9701 Internal : Node_Id renames Args (1);
9702 External : Node_Id renames Args (2);
9703 Parameter_Types : Node_Id renames Args (3);
9704 Mechanism : Node_Id renames Args (4);
9705 First_Optional_Parameter : Node_Id renames Args (5);
9709 Gather_Associations (Names, Args);
9710 Process_Extended_Import_Export_Subprogram_Pragma (
9711 Arg_Internal => Internal,
9712 Arg_External => External,
9713 Arg_Parameter_Types => Parameter_Types,
9714 Arg_Mechanism => Mechanism,
9715 Arg_First_Optional_Parameter => First_Optional_Parameter);
9716 end Import_Procedure;
9718 -----------------------------
9719 -- Import_Valued_Procedure --
9720 -----------------------------
9722 -- pragma Import_Valued_Procedure (
9723 -- [Internal =>] LOCAL_NAME
9724 -- [, [External =>] EXTERNAL_SYMBOL]
9725 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9726 -- [, [Mechanism =>] MECHANISM]
9727 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9729 -- EXTERNAL_SYMBOL ::=
9731 -- | static_string_EXPRESSION
9733 -- PARAMETER_TYPES ::=
9735 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9737 -- TYPE_DESIGNATOR ::=
9739 -- | subtype_Name ' Access
9743 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9745 -- MECHANISM_ASSOCIATION ::=
9746 -- [formal_parameter_NAME =>] MECHANISM_NAME
9748 -- MECHANISM_NAME ::=
9751 -- | Descriptor [([Class =>] CLASS_NAME)]
9753 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9755 when Pragma_Import_Valued_Procedure =>
9756 Import_Valued_Procedure : declare
9757 Args : Args_List (1 .. 5);
9758 Names : constant Name_List (1 .. 5) := (
9761 Name_Parameter_Types,
9763 Name_First_Optional_Parameter);
9765 Internal : Node_Id renames Args (1);
9766 External : Node_Id renames Args (2);
9767 Parameter_Types : Node_Id renames Args (3);
9768 Mechanism : Node_Id renames Args (4);
9769 First_Optional_Parameter : Node_Id renames Args (5);
9773 Gather_Associations (Names, Args);
9774 Process_Extended_Import_Export_Subprogram_Pragma (
9775 Arg_Internal => Internal,
9776 Arg_External => External,
9777 Arg_Parameter_Types => Parameter_Types,
9778 Arg_Mechanism => Mechanism,
9779 Arg_First_Optional_Parameter => First_Optional_Parameter);
9780 end Import_Valued_Procedure;
9786 -- pragma Independent (LOCAL_NAME);
9788 when Pragma_Independent => Independent : declare
9795 Check_Ada_83_Warning;
9797 Check_No_Identifiers;
9798 Check_Arg_Count (1);
9799 Check_Arg_Is_Local_Name (Arg1);
9800 E_Id := Get_Pragma_Arg (Arg1);
9802 if Etype (E_Id) = Any_Type then
9807 D := Declaration_Node (E);
9810 -- Check duplicate before we chain ourselves!
9812 Check_Duplicate_Pragma (E);
9814 -- Check appropriate entity
9817 if Rep_Item_Too_Early (E, N)
9819 Rep_Item_Too_Late (E, N)
9823 Check_First_Subtype (Arg1);
9826 elsif K = N_Object_Declaration
9827 or else (K = N_Component_Declaration
9828 and then Original_Record_Component (E) = E)
9830 if Rep_Item_Too_Late (E, N) then
9836 ("inappropriate entity for pragma%", Arg1);
9839 Independence_Checks.Append ((N, E));
9842 ----------------------------
9843 -- Independent_Components --
9844 ----------------------------
9846 -- pragma Atomic_Components (array_LOCAL_NAME);
9848 -- This processing is shared by Volatile_Components
9850 when Pragma_Independent_Components => Independent_Components : declare
9857 Check_Ada_83_Warning;
9859 Check_No_Identifiers;
9860 Check_Arg_Count (1);
9861 Check_Arg_Is_Local_Name (Arg1);
9862 E_Id := Get_Pragma_Arg (Arg1);
9864 if Etype (E_Id) = Any_Type then
9870 -- Check duplicate before we chain ourselves!
9872 Check_Duplicate_Pragma (E);
9874 -- Check appropriate entity
9876 if Rep_Item_Too_Early (E, N)
9878 Rep_Item_Too_Late (E, N)
9883 D := Declaration_Node (E);
9886 if (K = N_Full_Type_Declaration
9887 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9889 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9890 and then Nkind (D) = N_Object_Declaration
9891 and then Nkind (Object_Definition (D)) =
9892 N_Constrained_Array_Definition)
9894 Independence_Checks.Append ((N, E));
9897 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9899 end Independent_Components;
9901 ------------------------
9902 -- Initialize_Scalars --
9903 ------------------------
9905 -- pragma Initialize_Scalars;
9907 when Pragma_Initialize_Scalars =>
9909 Check_Arg_Count (0);
9910 Check_Valid_Configuration_Pragma;
9911 Check_Restriction (No_Initialize_Scalars, N);
9913 -- Initialize_Scalars creates false positives in CodePeer, and
9914 -- incorrect negative results in Alfa mode, so ignore this pragma
9917 if not Restriction_Active (No_Initialize_Scalars)
9918 and then not (CodePeer_Mode or Alfa_Mode)
9920 Init_Or_Norm_Scalars := True;
9921 Initialize_Scalars := True;
9928 -- pragma Inline ( NAME {, NAME} );
9930 when Pragma_Inline =>
9932 -- Pragma is active if inlining option is active
9934 Process_Inline (Inline_Active);
9940 -- pragma Inline_Always ( NAME {, NAME} );
9942 when Pragma_Inline_Always =>
9945 -- Pragma always active unless in CodePeer or Alfa mode, since
9946 -- this causes walk order issues.
9948 if not (CodePeer_Mode or Alfa_Mode) then
9949 Process_Inline (True);
9952 --------------------
9953 -- Inline_Generic --
9954 --------------------
9956 -- pragma Inline_Generic (NAME {, NAME});
9958 when Pragma_Inline_Generic =>
9960 Process_Generic_List;
9962 ----------------------
9963 -- Inspection_Point --
9964 ----------------------
9966 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9968 when Pragma_Inspection_Point => Inspection_Point : declare
9973 if Arg_Count > 0 then
9976 Exp := Get_Pragma_Arg (Arg);
9979 if not Is_Entity_Name (Exp)
9980 or else not Is_Object (Entity (Exp))
9982 Error_Pragma_Arg ("object name required", Arg);
9989 end Inspection_Point;
9995 -- pragma Interface (
9996 -- [ Convention =>] convention_IDENTIFIER,
9997 -- [ Entity =>] local_NAME
9998 -- [, [External_Name =>] static_string_EXPRESSION ]
9999 -- [, [Link_Name =>] static_string_EXPRESSION ]);
10001 when Pragma_Interface =>
10006 Name_External_Name,
10008 Check_At_Least_N_Arguments (2);
10009 Check_At_Most_N_Arguments (4);
10010 Process_Import_Or_Interface;
10012 -- In Ada 2005, the permission to use Interface (a reserved word)
10013 -- as a pragma name is considered an obsolescent feature.
10015 if Ada_Version >= Ada_2005 then
10017 (No_Obsolescent_Features, Pragma_Identifier (N));
10020 --------------------
10021 -- Interface_Name --
10022 --------------------
10024 -- pragma Interface_Name (
10025 -- [ Entity =>] local_NAME
10026 -- [,[External_Name =>] static_string_EXPRESSION ]
10027 -- [,[Link_Name =>] static_string_EXPRESSION ]);
10029 when Pragma_Interface_Name => Interface_Name : declare
10031 Def_Id : Entity_Id;
10032 Hom_Id : Entity_Id;
10038 ((Name_Entity, Name_External_Name, Name_Link_Name));
10039 Check_At_Least_N_Arguments (2);
10040 Check_At_Most_N_Arguments (3);
10041 Id := Get_Pragma_Arg (Arg1);
10044 if not Is_Entity_Name (Id) then
10046 ("first argument for pragma% must be entity name", Arg1);
10047 elsif Etype (Id) = Any_Type then
10050 Def_Id := Entity (Id);
10053 -- Special DEC-compatible processing for the object case, forces
10054 -- object to be imported.
10056 if Ekind (Def_Id) = E_Variable then
10057 Kill_Size_Check_Code (Def_Id);
10058 Note_Possible_Modification (Id, Sure => False);
10060 -- Initialization is not allowed for imported variable
10062 if Present (Expression (Parent (Def_Id)))
10063 and then Comes_From_Source (Expression (Parent (Def_Id)))
10065 Error_Msg_Sloc := Sloc (Def_Id);
10067 ("no initialization allowed for declaration of& #",
10071 -- For compatibility, support VADS usage of providing both
10072 -- pragmas Interface and Interface_Name to obtain the effect
10073 -- of a single Import pragma.
10075 if Is_Imported (Def_Id)
10076 and then Present (First_Rep_Item (Def_Id))
10077 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
10079 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
10083 Set_Imported (Def_Id);
10086 Set_Is_Public (Def_Id);
10087 Process_Interface_Name (Def_Id, Arg2, Arg3);
10090 -- Otherwise must be subprogram
10092 elsif not Is_Subprogram (Def_Id) then
10094 ("argument of pragma% is not subprogram", Arg1);
10097 Check_At_Most_N_Arguments (3);
10101 -- Loop through homonyms
10104 Def_Id := Get_Base_Subprogram (Hom_Id);
10106 if Is_Imported (Def_Id) then
10107 Process_Interface_Name (Def_Id, Arg2, Arg3);
10111 exit when From_Aspect_Specification (N);
10112 Hom_Id := Homonym (Hom_Id);
10114 exit when No (Hom_Id)
10115 or else Scope (Hom_Id) /= Current_Scope;
10120 ("argument of pragma% is not imported subprogram",
10124 end Interface_Name;
10126 -----------------------
10127 -- Interrupt_Handler --
10128 -----------------------
10130 -- pragma Interrupt_Handler (handler_NAME);
10132 when Pragma_Interrupt_Handler =>
10133 Check_Ada_83_Warning;
10134 Check_Arg_Count (1);
10135 Check_No_Identifiers;
10137 if No_Run_Time_Mode then
10138 Error_Msg_CRT ("Interrupt_Handler pragma", N);
10140 Check_Interrupt_Or_Attach_Handler;
10141 Process_Interrupt_Or_Attach_Handler;
10144 ------------------------
10145 -- Interrupt_Priority --
10146 ------------------------
10148 -- pragma Interrupt_Priority [(EXPRESSION)];
10150 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
10151 P : constant Node_Id := Parent (N);
10155 Check_Ada_83_Warning;
10157 if Arg_Count /= 0 then
10158 Arg := Get_Pragma_Arg (Arg1);
10159 Check_Arg_Count (1);
10160 Check_No_Identifiers;
10162 -- The expression must be analyzed in the special manner
10163 -- described in "Handling of Default and Per-Object
10164 -- Expressions" in sem.ads.
10166 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
10169 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
10173 elsif Has_Pragma_Priority (P) then
10174 Error_Pragma ("duplicate pragma% not allowed");
10177 Set_Has_Pragma_Priority (P, True);
10178 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10180 end Interrupt_Priority;
10182 ---------------------
10183 -- Interrupt_State --
10184 ---------------------
10186 -- pragma Interrupt_State (
10187 -- [Name =>] INTERRUPT_ID,
10188 -- [State =>] INTERRUPT_STATE);
10190 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
10191 -- INTERRUPT_STATE => System | Runtime | User
10193 -- Note: if the interrupt id is given as an identifier, then it must
10194 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
10195 -- given as a static integer expression which must be in the range of
10196 -- Ada.Interrupts.Interrupt_ID.
10198 when Pragma_Interrupt_State => Interrupt_State : declare
10200 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
10201 -- This is the entity Ada.Interrupts.Interrupt_ID;
10203 State_Type : Character;
10204 -- Set to 's'/'r'/'u' for System/Runtime/User
10207 -- Index to entry in Interrupt_States table
10210 -- Value of interrupt
10212 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
10213 -- The first argument to the pragma
10215 Int_Ent : Entity_Id;
10216 -- Interrupt entity in Ada.Interrupts.Names
10220 Check_Arg_Order ((Name_Name, Name_State));
10221 Check_Arg_Count (2);
10223 Check_Optional_Identifier (Arg1, Name_Name);
10224 Check_Optional_Identifier (Arg2, Name_State);
10225 Check_Arg_Is_Identifier (Arg2);
10227 -- First argument is identifier
10229 if Nkind (Arg1X) = N_Identifier then
10231 -- Search list of names in Ada.Interrupts.Names
10233 Int_Ent := First_Entity (RTE (RE_Names));
10235 if No (Int_Ent) then
10236 Error_Pragma_Arg ("invalid interrupt name", Arg1);
10238 elsif Chars (Int_Ent) = Chars (Arg1X) then
10239 Int_Val := Expr_Value (Constant_Value (Int_Ent));
10243 Next_Entity (Int_Ent);
10246 -- First argument is not an identifier, so it must be a static
10247 -- expression of type Ada.Interrupts.Interrupt_ID.
10250 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10251 Int_Val := Expr_Value (Arg1X);
10253 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
10255 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10258 ("value not in range of type " &
10259 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10265 case Chars (Get_Pragma_Arg (Arg2)) is
10266 when Name_Runtime => State_Type := 'r';
10267 when Name_System => State_Type := 's';
10268 when Name_User => State_Type := 'u';
10271 Error_Pragma_Arg ("invalid interrupt state", Arg2);
10274 -- Check if entry is already stored
10276 IST_Num := Interrupt_States.First;
10278 -- If entry not found, add it
10280 if IST_Num > Interrupt_States.Last then
10281 Interrupt_States.Append
10282 ((Interrupt_Number => UI_To_Int (Int_Val),
10283 Interrupt_State => State_Type,
10284 Pragma_Loc => Loc));
10287 -- Case of entry for the same entry
10289 elsif Int_Val = Interrupt_States.Table (IST_Num).
10292 -- If state matches, done, no need to make redundant entry
10295 State_Type = Interrupt_States.Table (IST_Num).
10298 -- Otherwise if state does not match, error
10301 Interrupt_States.Table (IST_Num).Pragma_Loc;
10303 ("state conflicts with that given #", Arg2);
10307 IST_Num := IST_Num + 1;
10309 end Interrupt_State;
10315 -- pragma Invariant
10316 -- ([Entity =>] type_LOCAL_NAME,
10317 -- [Check =>] EXPRESSION
10318 -- [,[Message =>] String_Expression]);
10320 when Pragma_Invariant => Invariant : declare
10325 pragma Unreferenced (Discard);
10329 Check_At_Least_N_Arguments (2);
10330 Check_At_Most_N_Arguments (3);
10331 Check_Optional_Identifier (Arg1, Name_Entity);
10332 Check_Optional_Identifier (Arg2, Name_Check);
10334 if Arg_Count = 3 then
10335 Check_Optional_Identifier (Arg3, Name_Message);
10336 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10339 Check_Arg_Is_Local_Name (Arg1);
10341 Type_Id := Get_Pragma_Arg (Arg1);
10342 Find_Type (Type_Id);
10343 Typ := Entity (Type_Id);
10345 if Typ = Any_Type then
10348 -- An invariant must apply to a private type, or appear in the
10349 -- private part of a package spec and apply to a completion.
10351 elsif Ekind_In (Typ, E_Private_Type,
10352 E_Record_Type_With_Private,
10353 E_Limited_Private_Type)
10357 elsif In_Private_Part (Current_Scope)
10358 and then Has_Private_Declaration (Typ)
10362 elsif In_Private_Part (Current_Scope) then
10364 ("pragma% only allowed for private type " &
10365 "declared in visible part", Arg1);
10369 ("pragma% only allowed for private type", Arg1);
10372 -- Note that the type has at least one invariant, and also that
10373 -- it has inheritable invariants if we have Invariant'Class.
10375 Set_Has_Invariants (Typ);
10377 if Class_Present (N) then
10378 Set_Has_Inheritable_Invariants (Typ);
10381 -- The remaining processing is simply to link the pragma on to
10382 -- the rep item chain, for processing when the type is frozen.
10383 -- This is accomplished by a call to Rep_Item_Too_Late.
10385 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10388 ----------------------
10389 -- Java_Constructor --
10390 ----------------------
10392 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10394 -- Also handles pragma CIL_Constructor
10396 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10397 Java_Constructor : declare
10398 Convention : Convention_Id;
10399 Def_Id : Entity_Id;
10400 Hom_Id : Entity_Id;
10402 This_Formal : Entity_Id;
10406 Check_Arg_Count (1);
10407 Check_Optional_Identifier (Arg1, Name_Entity);
10408 Check_Arg_Is_Local_Name (Arg1);
10410 Id := Get_Pragma_Arg (Arg1);
10411 Find_Program_Unit_Name (Id);
10413 -- If we did not find the name, we are done
10415 if Etype (Id) = Any_Type then
10419 -- Check wrong use of pragma in wrong VM target
10421 if VM_Target = No_VM then
10424 elsif VM_Target = CLI_Target
10425 and then Prag_Id = Pragma_Java_Constructor
10427 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10429 elsif VM_Target = JVM_Target
10430 and then Prag_Id = Pragma_CIL_Constructor
10432 Error_Pragma ("must use pragma 'Java_'Constructor");
10436 when Pragma_CIL_Constructor => Convention := Convention_CIL;
10437 when Pragma_Java_Constructor => Convention := Convention_Java;
10438 when others => null;
10441 Hom_Id := Entity (Id);
10443 -- Loop through homonyms
10446 Def_Id := Get_Base_Subprogram (Hom_Id);
10448 -- The constructor is required to be a function
10450 if Ekind (Def_Id) /= E_Function then
10451 if VM_Target = JVM_Target then
10453 ("pragma% requires function returning a " &
10454 "'Java access type", Def_Id);
10457 ("pragma% requires function returning a " &
10458 "'C'I'L access type", Def_Id);
10462 -- Check arguments: For tagged type the first formal must be
10463 -- named "this" and its type must be a named access type
10464 -- designating a class-wide tagged type that has convention
10465 -- CIL/Java. The first formal must also have a null default
10466 -- value. For example:
10468 -- type Typ is tagged ...
10469 -- type Ref is access all Typ;
10470 -- pragma Convention (CIL, Typ);
10472 -- function New_Typ (This : Ref) return Ref;
10473 -- function New_Typ (This : Ref; I : Integer) return Ref;
10474 -- pragma Cil_Constructor (New_Typ);
10476 -- Reason: The first formal must NOT be a primitive of the
10479 -- This rule also applies to constructors of delegates used
10480 -- to interface with standard target libraries. For example:
10482 -- type Delegate is access procedure ...
10483 -- pragma Import (CIL, Delegate, ...);
10485 -- function new_Delegate
10486 -- (This : Delegate := null; ... ) return Delegate;
10488 -- For value-types this rule does not apply.
10490 if not Is_Value_Type (Etype (Def_Id)) then
10491 if No (First_Formal (Def_Id)) then
10492 Error_Msg_Name_1 := Pname;
10493 Error_Msg_N ("% function must have parameters", Def_Id);
10497 -- In the JRE library we have several occurrences in which
10498 -- the "this" parameter is not the first formal.
10500 This_Formal := First_Formal (Def_Id);
10502 -- In the JRE library we have several occurrences in which
10503 -- the "this" parameter is not the first formal. Search for
10506 if VM_Target = JVM_Target then
10507 while Present (This_Formal)
10508 and then Get_Name_String (Chars (This_Formal)) /= "this"
10510 Next_Formal (This_Formal);
10513 if No (This_Formal) then
10514 This_Formal := First_Formal (Def_Id);
10518 -- Warning: The first parameter should be named "this".
10519 -- We temporarily allow it because we have the following
10520 -- case in the Java runtime (file s-osinte.ads) ???
10522 -- function new_Thread
10523 -- (Self_Id : System.Address) return Thread_Id;
10524 -- pragma Java_Constructor (new_Thread);
10526 if VM_Target = JVM_Target
10527 and then Get_Name_String (Chars (First_Formal (Def_Id)))
10529 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10533 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10534 Error_Msg_Name_1 := Pname;
10536 ("first formal of % function must be named `this`",
10537 Parent (This_Formal));
10539 elsif not Is_Access_Type (Etype (This_Formal)) then
10540 Error_Msg_Name_1 := Pname;
10542 ("first formal of % function must be an access type",
10543 Parameter_Type (Parent (This_Formal)));
10545 -- For delegates the type of the first formal must be a
10546 -- named access-to-subprogram type (see previous example)
10548 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10549 and then Ekind (Etype (This_Formal))
10550 /= E_Access_Subprogram_Type
10552 Error_Msg_Name_1 := Pname;
10554 ("first formal of % function must be a named access" &
10555 " to subprogram type",
10556 Parameter_Type (Parent (This_Formal)));
10558 -- Warning: We should reject anonymous access types because
10559 -- the constructor must not be handled as a primitive of the
10560 -- tagged type. We temporarily allow it because this profile
10561 -- is currently generated by cil2ada???
10563 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10564 and then not Ekind_In (Etype (This_Formal),
10566 E_General_Access_Type,
10567 E_Anonymous_Access_Type)
10569 Error_Msg_Name_1 := Pname;
10571 ("first formal of % function must be a named access" &
10573 Parameter_Type (Parent (This_Formal)));
10575 elsif Atree.Convention
10576 (Designated_Type (Etype (This_Formal))) /= Convention
10578 Error_Msg_Name_1 := Pname;
10580 if Convention = Convention_Java then
10582 ("pragma% requires convention 'Cil in designated" &
10584 Parameter_Type (Parent (This_Formal)));
10587 ("pragma% requires convention 'Java in designated" &
10589 Parameter_Type (Parent (This_Formal)));
10592 elsif No (Expression (Parent (This_Formal)))
10593 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10595 Error_Msg_Name_1 := Pname;
10597 ("pragma% requires first formal with default `null`",
10598 Parameter_Type (Parent (This_Formal)));
10602 -- Check result type: the constructor must be a function
10604 -- * a value type (only allowed in the CIL compiler)
10605 -- * an access-to-subprogram type with convention Java/CIL
10606 -- * an access-type designating a type that has convention
10609 if Is_Value_Type (Etype (Def_Id)) then
10612 -- Access-to-subprogram type with convention Java/CIL
10614 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10615 if Atree.Convention (Etype (Def_Id)) /= Convention then
10616 if Convention = Convention_Java then
10618 ("pragma% requires function returning a " &
10619 "'Java access type", Arg1);
10621 pragma Assert (Convention = Convention_CIL);
10623 ("pragma% requires function returning a " &
10624 "'C'I'L access type", Arg1);
10628 elsif Ekind (Etype (Def_Id)) in Access_Kind then
10629 if not Ekind_In (Etype (Def_Id), E_Access_Type,
10630 E_General_Access_Type)
10633 (Designated_Type (Etype (Def_Id))) /= Convention
10635 Error_Msg_Name_1 := Pname;
10637 if Convention = Convention_Java then
10639 ("pragma% requires function returning a named" &
10640 "'Java access type", Arg1);
10643 ("pragma% requires function returning a named" &
10644 "'C'I'L access type", Arg1);
10649 Set_Is_Constructor (Def_Id);
10650 Set_Convention (Def_Id, Convention);
10651 Set_Is_Imported (Def_Id);
10653 exit when From_Aspect_Specification (N);
10654 Hom_Id := Homonym (Hom_Id);
10656 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10658 end Java_Constructor;
10660 ----------------------
10661 -- Java_Interface --
10662 ----------------------
10664 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
10666 when Pragma_Java_Interface => Java_Interface : declare
10672 Check_Arg_Count (1);
10673 Check_Optional_Identifier (Arg1, Name_Entity);
10674 Check_Arg_Is_Local_Name (Arg1);
10676 Arg := Get_Pragma_Arg (Arg1);
10679 if Etype (Arg) = Any_Type then
10683 if not Is_Entity_Name (Arg)
10684 or else not Is_Type (Entity (Arg))
10686 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10689 Typ := Underlying_Type (Entity (Arg));
10691 -- For now simply check some of the semantic constraints on the
10692 -- type. This currently leaves out some restrictions on interface
10693 -- types, namely that the parent type must be java.lang.Object.Typ
10694 -- and that all primitives of the type should be declared
10697 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10698 Error_Pragma_Arg ("pragma% requires an abstract "
10699 & "tagged type", Arg1);
10701 elsif not Has_Discriminants (Typ)
10702 or else Ekind (Etype (First_Discriminant (Typ)))
10703 /= E_Anonymous_Access_Type
10705 not Is_Class_Wide_Type
10706 (Designated_Type (Etype (First_Discriminant (Typ))))
10709 ("type must have a class-wide access discriminant", Arg1);
10711 end Java_Interface;
10717 -- pragma Keep_Names ([On => ] local_NAME);
10719 when Pragma_Keep_Names => Keep_Names : declare
10724 Check_Arg_Count (1);
10725 Check_Optional_Identifier (Arg1, Name_On);
10726 Check_Arg_Is_Local_Name (Arg1);
10728 Arg := Get_Pragma_Arg (Arg1);
10731 if Etype (Arg) = Any_Type then
10735 if not Is_Entity_Name (Arg)
10736 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10739 ("pragma% requires a local enumeration type", Arg1);
10742 Set_Discard_Names (Entity (Arg), False);
10749 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10751 when Pragma_License =>
10753 Check_Arg_Count (1);
10754 Check_No_Identifiers;
10755 Check_Valid_Configuration_Pragma;
10756 Check_Arg_Is_Identifier (Arg1);
10759 Sind : constant Source_File_Index :=
10760 Source_Index (Current_Sem_Unit);
10763 case Chars (Get_Pragma_Arg (Arg1)) is
10765 Set_License (Sind, GPL);
10767 when Name_Modified_GPL =>
10768 Set_License (Sind, Modified_GPL);
10770 when Name_Restricted =>
10771 Set_License (Sind, Restricted);
10773 when Name_Unrestricted =>
10774 Set_License (Sind, Unrestricted);
10777 Error_Pragma_Arg ("invalid license name", Arg1);
10785 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10787 when Pragma_Link_With => Link_With : declare
10793 if Operating_Mode = Generate_Code
10794 and then In_Extended_Main_Source_Unit (N)
10796 Check_At_Least_N_Arguments (1);
10797 Check_No_Identifiers;
10798 Check_Is_In_Decl_Part_Or_Package_Spec;
10799 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10803 while Present (Arg) loop
10804 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10806 -- Store argument, converting sequences of spaces to a
10807 -- single null character (this is one of the differences
10808 -- in processing between Link_With and Linker_Options).
10810 Arg_Store : declare
10811 C : constant Char_Code := Get_Char_Code (' ');
10812 S : constant String_Id :=
10813 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10814 L : constant Nat := String_Length (S);
10817 procedure Skip_Spaces;
10818 -- Advance F past any spaces
10824 procedure Skip_Spaces is
10826 while F <= L and then Get_String_Char (S, F) = C loop
10831 -- Start of processing for Arg_Store
10834 Skip_Spaces; -- skip leading spaces
10836 -- Loop through characters, changing any embedded
10837 -- sequence of spaces to a single null character (this
10838 -- is how Link_With/Linker_Options differ)
10841 if Get_String_Char (S, F) = C then
10844 Store_String_Char (ASCII.NUL);
10847 Store_String_Char (Get_String_Char (S, F));
10855 if Present (Arg) then
10856 Store_String_Char (ASCII.NUL);
10860 Store_Linker_Option_String (End_String);
10868 -- pragma Linker_Alias (
10869 -- [Entity =>] LOCAL_NAME
10870 -- [Target =>] static_string_EXPRESSION);
10872 when Pragma_Linker_Alias =>
10874 Check_Arg_Order ((Name_Entity, Name_Target));
10875 Check_Arg_Count (2);
10876 Check_Optional_Identifier (Arg1, Name_Entity);
10877 Check_Optional_Identifier (Arg2, Name_Target);
10878 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10879 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10881 -- The only processing required is to link this item on to the
10882 -- list of rep items for the given entity. This is accomplished
10883 -- by the call to Rep_Item_Too_Late (when no error is detected
10884 -- and False is returned).
10886 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10889 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10892 ------------------------
10893 -- Linker_Constructor --
10894 ------------------------
10896 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10898 -- Code is shared with Linker_Destructor
10900 -----------------------
10901 -- Linker_Destructor --
10902 -----------------------
10904 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10906 when Pragma_Linker_Constructor |
10907 Pragma_Linker_Destructor =>
10908 Linker_Constructor : declare
10914 Check_Arg_Count (1);
10915 Check_No_Identifiers;
10916 Check_Arg_Is_Local_Name (Arg1);
10917 Arg1_X := Get_Pragma_Arg (Arg1);
10919 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10921 if not Is_Library_Level_Entity (Proc) then
10923 ("argument for pragma% must be library level entity", Arg1);
10926 -- The only processing required is to link this item on to the
10927 -- list of rep items for the given entity. This is accomplished
10928 -- by the call to Rep_Item_Too_Late (when no error is detected
10929 -- and False is returned).
10931 if Rep_Item_Too_Late (Proc, N) then
10934 Set_Has_Gigi_Rep_Item (Proc);
10936 end Linker_Constructor;
10938 --------------------
10939 -- Linker_Options --
10940 --------------------
10942 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10944 when Pragma_Linker_Options => Linker_Options : declare
10948 Check_Ada_83_Warning;
10949 Check_No_Identifiers;
10950 Check_Arg_Count (1);
10951 Check_Is_In_Decl_Part_Or_Package_Spec;
10952 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10953 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10956 while Present (Arg) loop
10957 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10958 Store_String_Char (ASCII.NUL);
10960 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10964 if Operating_Mode = Generate_Code
10965 and then In_Extended_Main_Source_Unit (N)
10967 Store_Linker_Option_String (End_String);
10969 end Linker_Options;
10971 --------------------
10972 -- Linker_Section --
10973 --------------------
10975 -- pragma Linker_Section (
10976 -- [Entity =>] LOCAL_NAME
10977 -- [Section =>] static_string_EXPRESSION);
10979 when Pragma_Linker_Section =>
10981 Check_Arg_Order ((Name_Entity, Name_Section));
10982 Check_Arg_Count (2);
10983 Check_Optional_Identifier (Arg1, Name_Entity);
10984 Check_Optional_Identifier (Arg2, Name_Section);
10985 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10986 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10988 -- This pragma applies only to objects
10990 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10991 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10994 -- The only processing required is to link this item on to the
10995 -- list of rep items for the given entity. This is accomplished
10996 -- by the call to Rep_Item_Too_Late (when no error is detected
10997 -- and False is returned).
10999 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
11002 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11009 -- pragma List (On | Off)
11011 -- There is nothing to do here, since we did all the processing for
11012 -- this pragma in Par.Prag (so that it works properly even in syntax
11015 when Pragma_List =>
11018 --------------------
11019 -- Locking_Policy --
11020 --------------------
11022 -- pragma Locking_Policy (policy_IDENTIFIER);
11024 when Pragma_Locking_Policy => declare
11025 subtype LP_Range is Name_Id
11026 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
11030 Check_Ada_83_Warning;
11031 Check_Arg_Count (1);
11032 Check_No_Identifiers;
11033 Check_Arg_Is_Locking_Policy (Arg1);
11034 Check_Valid_Configuration_Pragma;
11035 LP_Val := Chars (Get_Pragma_Arg (Arg1));
11038 when Name_Ceiling_Locking => LP := 'C';
11039 when Name_Inheritance_Locking => LP := 'I';
11040 when Name_Concurrent_Readers_Locking => LP := 'R';
11043 if Locking_Policy /= ' '
11044 and then Locking_Policy /= LP
11046 Error_Msg_Sloc := Locking_Policy_Sloc;
11047 Error_Pragma ("locking policy incompatible with policy#");
11049 -- Set new policy, but always preserve System_Location since we
11050 -- like the error message with the run time name.
11053 Locking_Policy := LP;
11055 if Locking_Policy_Sloc /= System_Location then
11056 Locking_Policy_Sloc := Loc;
11065 -- pragma Long_Float (D_Float | G_Float);
11067 when Pragma_Long_Float => Long_Float : declare
11070 Check_Valid_Configuration_Pragma;
11071 Check_Arg_Count (1);
11072 Check_No_Identifier (Arg1);
11073 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
11075 if not OpenVMS_On_Target then
11076 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
11081 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
11082 if Opt.Float_Format_Long = 'G' then
11084 ("G_Float previously specified", Arg1);
11086 elsif Current_Sem_Unit /= Main_Unit
11087 and then Opt.Float_Format_Long /= 'D'
11090 ("main unit not compiled with pragma Long_Float (D_Float)",
11091 "\pragma% must be used consistently for whole partition",
11095 Opt.Float_Format_Long := 'D';
11098 -- G_Float case (this is the default, does not need overriding)
11101 if Opt.Float_Format_Long = 'D' then
11102 Error_Pragma ("D_Float previously specified");
11104 elsif Current_Sem_Unit /= Main_Unit
11105 and then Opt.Float_Format_Long /= 'G'
11108 ("main unit not compiled with pragma Long_Float (G_Float)",
11109 "\pragma% must be used consistently for whole partition",
11113 Opt.Float_Format_Long := 'G';
11117 Set_Standard_Fpt_Formats;
11120 -----------------------
11121 -- Machine_Attribute --
11122 -----------------------
11124 -- pragma Machine_Attribute (
11125 -- [Entity =>] LOCAL_NAME,
11126 -- [Attribute_Name =>] static_string_EXPRESSION
11127 -- [, [Info =>] static_EXPRESSION] );
11129 when Pragma_Machine_Attribute => Machine_Attribute : declare
11130 Def_Id : Entity_Id;
11134 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
11136 if Arg_Count = 3 then
11137 Check_Optional_Identifier (Arg3, Name_Info);
11138 Check_Arg_Is_Static_Expression (Arg3);
11140 Check_Arg_Count (2);
11143 Check_Optional_Identifier (Arg1, Name_Entity);
11144 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
11145 Check_Arg_Is_Local_Name (Arg1);
11146 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11147 Def_Id := Entity (Get_Pragma_Arg (Arg1));
11149 if Is_Access_Type (Def_Id) then
11150 Def_Id := Designated_Type (Def_Id);
11153 if Rep_Item_Too_Early (Def_Id, N) then
11157 Def_Id := Underlying_Type (Def_Id);
11159 -- The only processing required is to link this item on to the
11160 -- list of rep items for the given entity. This is accomplished
11161 -- by the call to Rep_Item_Too_Late (when no error is detected
11162 -- and False is returned).
11164 if Rep_Item_Too_Late (Def_Id, N) then
11167 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11169 end Machine_Attribute;
11176 -- (MAIN_OPTION [, MAIN_OPTION]);
11179 -- [STACK_SIZE =>] static_integer_EXPRESSION
11180 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
11181 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
11183 when Pragma_Main => Main : declare
11184 Args : Args_List (1 .. 3);
11185 Names : constant Name_List (1 .. 3) := (
11187 Name_Task_Stack_Size_Default,
11188 Name_Time_Slicing_Enabled);
11194 Gather_Associations (Names, Args);
11196 for J in 1 .. 2 loop
11197 if Present (Args (J)) then
11198 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11202 if Present (Args (3)) then
11203 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
11207 while Present (Nod) loop
11208 if Nkind (Nod) = N_Pragma
11209 and then Pragma_Name (Nod) = Name_Main
11211 Error_Msg_Name_1 := Pname;
11212 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11223 -- pragma Main_Storage
11224 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
11226 -- MAIN_STORAGE_OPTION ::=
11227 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
11228 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
11230 when Pragma_Main_Storage => Main_Storage : declare
11231 Args : Args_List (1 .. 2);
11232 Names : constant Name_List (1 .. 2) := (
11233 Name_Working_Storage,
11240 Gather_Associations (Names, Args);
11242 for J in 1 .. 2 loop
11243 if Present (Args (J)) then
11244 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11248 Check_In_Main_Program;
11251 while Present (Nod) loop
11252 if Nkind (Nod) = N_Pragma
11253 and then Pragma_Name (Nod) = Name_Main_Storage
11255 Error_Msg_Name_1 := Pname;
11256 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11267 -- pragma Memory_Size (NUMERIC_LITERAL)
11269 when Pragma_Memory_Size =>
11272 -- Memory size is simply ignored
11274 Check_No_Identifiers;
11275 Check_Arg_Count (1);
11276 Check_Arg_Is_Integer_Literal (Arg1);
11284 -- The only correct use of this pragma is on its own in a file, in
11285 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
11286 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
11287 -- check for a file containing nothing but a No_Body pragma). If we
11288 -- attempt to process it during normal semantics processing, it means
11289 -- it was misplaced.
11291 when Pragma_No_Body =>
11299 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
11301 when Pragma_No_Return => No_Return : declare
11309 Check_At_Least_N_Arguments (1);
11311 -- Loop through arguments of pragma
11314 while Present (Arg) loop
11315 Check_Arg_Is_Local_Name (Arg);
11316 Id := Get_Pragma_Arg (Arg);
11319 if not Is_Entity_Name (Id) then
11320 Error_Pragma_Arg ("entity name required", Arg);
11323 if Etype (Id) = Any_Type then
11327 -- Loop to find matching procedures
11332 and then Scope (E) = Current_Scope
11334 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11337 -- Set flag on any alias as well
11339 if Is_Overloadable (E) and then Present (Alias (E)) then
11340 Set_No_Return (Alias (E));
11346 exit when From_Aspect_Specification (N);
11351 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11362 -- pragma No_Run_Time;
11364 -- Note: this pragma is retained for backwards compatibility. See
11365 -- body of Rtsfind for full details on its handling.
11367 when Pragma_No_Run_Time =>
11369 Check_Valid_Configuration_Pragma;
11370 Check_Arg_Count (0);
11372 No_Run_Time_Mode := True;
11373 Configurable_Run_Time_Mode := True;
11375 -- Set Duration to 32 bits if word size is 32
11377 if Ttypes.System_Word_Size = 32 then
11378 Duration_32_Bits_On_Target := True;
11381 -- Set appropriate restrictions
11383 Set_Restriction (No_Finalization, N);
11384 Set_Restriction (No_Exception_Handlers, N);
11385 Set_Restriction (Max_Tasks, N, 0);
11386 Set_Restriction (No_Tasking, N);
11388 ------------------------
11389 -- No_Strict_Aliasing --
11390 ------------------------
11392 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11394 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11399 Check_At_Most_N_Arguments (1);
11401 if Arg_Count = 0 then
11402 Check_Valid_Configuration_Pragma;
11403 Opt.No_Strict_Aliasing := True;
11406 Check_Optional_Identifier (Arg2, Name_Entity);
11407 Check_Arg_Is_Local_Name (Arg1);
11408 E_Id := Entity (Get_Pragma_Arg (Arg1));
11410 if E_Id = Any_Type then
11412 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11413 Error_Pragma_Arg ("pragma% requires access type", Arg1);
11416 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11418 end No_Strict_Aliasing;
11420 -----------------------
11421 -- Normalize_Scalars --
11422 -----------------------
11424 -- pragma Normalize_Scalars;
11426 when Pragma_Normalize_Scalars =>
11427 Check_Ada_83_Warning;
11428 Check_Arg_Count (0);
11429 Check_Valid_Configuration_Pragma;
11431 -- Normalize_Scalars creates false positives in CodePeer, and
11432 -- incorrect negative results in Alfa mode, so ignore this pragma
11435 if not (CodePeer_Mode or Alfa_Mode) then
11436 Normalize_Scalars := True;
11437 Init_Or_Norm_Scalars := True;
11444 -- pragma Obsolescent;
11446 -- pragma Obsolescent (
11447 -- [Message =>] static_string_EXPRESSION
11448 -- [,[Version =>] Ada_05]]);
11450 -- pragma Obsolescent (
11451 -- [Entity =>] NAME
11452 -- [,[Message =>] static_string_EXPRESSION
11453 -- [,[Version =>] Ada_05]] );
11455 when Pragma_Obsolescent => Obsolescent : declare
11459 procedure Set_Obsolescent (E : Entity_Id);
11460 -- Given an entity Ent, mark it as obsolescent if appropriate
11462 ---------------------
11463 -- Set_Obsolescent --
11464 ---------------------
11466 procedure Set_Obsolescent (E : Entity_Id) is
11475 -- Entity name was given
11477 if Present (Ename) then
11479 -- If entity name matches, we are fine. Save entity in
11480 -- pragma argument, for ASIS use.
11482 if Chars (Ename) = Chars (Ent) then
11483 Set_Entity (Ename, Ent);
11484 Generate_Reference (Ent, Ename);
11486 -- If entity name does not match, only possibility is an
11487 -- enumeration literal from an enumeration type declaration.
11489 elsif Ekind (Ent) /= E_Enumeration_Type then
11491 ("pragma % entity name does not match declaration");
11494 Ent := First_Literal (E);
11498 ("pragma % entity name does not match any " &
11499 "enumeration literal");
11501 elsif Chars (Ent) = Chars (Ename) then
11502 Set_Entity (Ename, Ent);
11503 Generate_Reference (Ent, Ename);
11507 Ent := Next_Literal (Ent);
11513 -- Ent points to entity to be marked
11515 if Arg_Count >= 1 then
11517 -- Deal with static string argument
11519 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11520 S := Strval (Get_Pragma_Arg (Arg1));
11522 for J in 1 .. String_Length (S) loop
11523 if not In_Character_Range (Get_String_Char (S, J)) then
11525 ("pragma% argument does not allow wide characters",
11530 Obsolescent_Warnings.Append
11531 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11533 -- Check for Ada_05 parameter
11535 if Arg_Count /= 1 then
11536 Check_Arg_Count (2);
11539 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11542 Check_Arg_Is_Identifier (Argx);
11544 if Chars (Argx) /= Name_Ada_05 then
11545 Error_Msg_Name_2 := Name_Ada_05;
11547 ("only allowed argument for pragma% is %", Argx);
11550 if Ada_Version_Explicit < Ada_2005
11551 or else not Warn_On_Ada_2005_Compatibility
11559 -- Set flag if pragma active
11562 Set_Is_Obsolescent (Ent);
11566 end Set_Obsolescent;
11568 -- Start of processing for pragma Obsolescent
11573 Check_At_Most_N_Arguments (3);
11575 -- See if first argument specifies an entity name
11579 (Chars (Arg1) = Name_Entity
11581 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11583 N_Operator_Symbol))
11585 Ename := Get_Pragma_Arg (Arg1);
11587 -- Eliminate first argument, so we can share processing
11591 Arg_Count := Arg_Count - 1;
11593 -- No Entity name argument given
11599 if Arg_Count >= 1 then
11600 Check_Optional_Identifier (Arg1, Name_Message);
11602 if Arg_Count = 2 then
11603 Check_Optional_Identifier (Arg2, Name_Version);
11607 -- Get immediately preceding declaration
11610 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11614 -- Cases where we do not follow anything other than another pragma
11618 -- First case: library level compilation unit declaration with
11619 -- the pragma immediately following the declaration.
11621 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11623 (Defining_Entity (Unit (Parent (Parent (N)))));
11626 -- Case 2: library unit placement for package
11630 Ent : constant Entity_Id := Find_Lib_Unit_Name;
11632 if Is_Package_Or_Generic_Package (Ent) then
11633 Set_Obsolescent (Ent);
11639 -- Cases where we must follow a declaration
11642 if Nkind (Decl) not in N_Declaration
11643 and then Nkind (Decl) not in N_Later_Decl_Item
11644 and then Nkind (Decl) not in N_Generic_Declaration
11645 and then Nkind (Decl) not in N_Renaming_Declaration
11648 ("pragma% misplaced, "
11649 & "must immediately follow a declaration");
11652 Set_Obsolescent (Defining_Entity (Decl));
11662 -- pragma Optimize (Time | Space | Off);
11664 -- The actual check for optimize is done in Gigi. Note that this
11665 -- pragma does not actually change the optimization setting, it
11666 -- simply checks that it is consistent with the pragma.
11668 when Pragma_Optimize =>
11669 Check_No_Identifiers;
11670 Check_Arg_Count (1);
11671 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11673 ------------------------
11674 -- Optimize_Alignment --
11675 ------------------------
11677 -- pragma Optimize_Alignment (Time | Space | Off);
11679 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11681 Check_No_Identifiers;
11682 Check_Arg_Count (1);
11683 Check_Valid_Configuration_Pragma;
11686 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11690 Opt.Optimize_Alignment := 'T';
11692 Opt.Optimize_Alignment := 'S';
11694 Opt.Optimize_Alignment := 'O';
11696 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11700 -- Set indication that mode is set locally. If we are in fact in a
11701 -- configuration pragma file, this setting is harmless since the
11702 -- switch will get reset anyway at the start of each unit.
11704 Optimize_Alignment_Local := True;
11705 end Optimize_Alignment;
11711 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11713 when Pragma_Ordered => Ordered : declare
11714 Assoc : constant Node_Id := Arg1;
11720 Check_No_Identifiers;
11721 Check_Arg_Count (1);
11722 Check_Arg_Is_Local_Name (Arg1);
11724 Type_Id := Get_Pragma_Arg (Assoc);
11725 Find_Type (Type_Id);
11726 Typ := Entity (Type_Id);
11728 if Typ = Any_Type then
11731 Typ := Underlying_Type (Typ);
11734 if not Is_Enumeration_Type (Typ) then
11735 Error_Pragma ("pragma% must specify enumeration type");
11738 Check_First_Subtype (Arg1);
11739 Set_Has_Pragma_Ordered (Base_Type (Typ));
11746 -- pragma Pack (first_subtype_LOCAL_NAME);
11748 when Pragma_Pack => Pack : declare
11749 Assoc : constant Node_Id := Arg1;
11753 Ignore : Boolean := False;
11756 Check_No_Identifiers;
11757 Check_Arg_Count (1);
11758 Check_Arg_Is_Local_Name (Arg1);
11760 Type_Id := Get_Pragma_Arg (Assoc);
11761 Find_Type (Type_Id);
11762 Typ := Entity (Type_Id);
11765 or else Rep_Item_Too_Early (Typ, N)
11769 Typ := Underlying_Type (Typ);
11772 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11773 Error_Pragma ("pragma% must specify array or record type");
11776 Check_First_Subtype (Arg1);
11777 Check_Duplicate_Pragma (Typ);
11781 if Is_Array_Type (Typ) then
11782 Ctyp := Component_Type (Typ);
11784 -- Ignore pack that does nothing
11786 if Known_Static_Esize (Ctyp)
11787 and then Known_Static_RM_Size (Ctyp)
11788 and then Esize (Ctyp) = RM_Size (Ctyp)
11789 and then Addressable (Esize (Ctyp))
11794 -- Process OK pragma Pack. Note that if there is a separate
11795 -- component clause present, the Pack will be cancelled. This
11796 -- processing is in Freeze.
11798 if not Rep_Item_Too_Late (Typ, N) then
11800 -- In the context of static code analysis, we do not need
11801 -- complex front-end expansions related to pragma Pack,
11802 -- so disable handling of pragma Pack in these cases.
11804 if CodePeer_Mode or Alfa_Mode then
11807 -- Don't attempt any packing for VM targets. We possibly
11808 -- could deal with some cases of array bit-packing, but we
11809 -- don't bother, since this is not a typical kind of
11810 -- representation in the VM context anyway (and would not
11811 -- for example work nicely with the debugger).
11813 elsif VM_Target /= No_VM then
11814 if not GNAT_Mode then
11816 ("?pragma% ignored in this configuration");
11819 -- Normal case where we do the pack action
11823 Set_Is_Packed (Base_Type (Typ));
11824 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11827 Set_Has_Pragma_Pack (Base_Type (Typ));
11831 -- For record types, the pack is always effective
11833 else pragma Assert (Is_Record_Type (Typ));
11834 if not Rep_Item_Too_Late (Typ, N) then
11836 -- Ignore pack request with warning in VM mode (skip warning
11837 -- if we are compiling GNAT run time library).
11839 if VM_Target /= No_VM then
11840 if not GNAT_Mode then
11842 ("?pragma% ignored in this configuration");
11845 -- Normal case of pack request active
11848 Set_Is_Packed (Base_Type (Typ));
11849 Set_Has_Pragma_Pack (Base_Type (Typ));
11850 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11862 -- There is nothing to do here, since we did all the processing for
11863 -- this pragma in Par.Prag (so that it works properly even in syntax
11866 when Pragma_Page =>
11873 -- pragma Passive [(PASSIVE_FORM)];
11875 -- PASSIVE_FORM ::= Semaphore | No
11877 when Pragma_Passive =>
11880 if Nkind (Parent (N)) /= N_Task_Definition then
11881 Error_Pragma ("pragma% must be within task definition");
11884 if Arg_Count /= 0 then
11885 Check_Arg_Count (1);
11886 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11889 ----------------------------------
11890 -- Preelaborable_Initialization --
11891 ----------------------------------
11893 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11895 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11900 Check_Arg_Count (1);
11901 Check_No_Identifiers;
11902 Check_Arg_Is_Identifier (Arg1);
11903 Check_Arg_Is_Local_Name (Arg1);
11904 Check_First_Subtype (Arg1);
11905 Ent := Entity (Get_Pragma_Arg (Arg1));
11907 if not (Is_Private_Type (Ent)
11909 Is_Protected_Type (Ent)
11911 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11914 ("pragma % can only be applied to private, formal derived or "
11915 & "protected type",
11919 -- Give an error if the pragma is applied to a protected type that
11920 -- does not qualify (due to having entries, or due to components
11921 -- that do not qualify).
11923 if Is_Protected_Type (Ent)
11924 and then not Has_Preelaborable_Initialization (Ent)
11927 ("protected type & does not have preelaborable " &
11928 "initialization", Ent);
11930 -- Otherwise mark the type as definitely having preelaborable
11934 Set_Known_To_Have_Preelab_Init (Ent);
11937 if Has_Pragma_Preelab_Init (Ent)
11938 and then Warn_On_Redundant_Constructs
11940 Error_Pragma ("?duplicate pragma%!");
11942 Set_Has_Pragma_Preelab_Init (Ent);
11946 --------------------
11947 -- Persistent_BSS --
11948 --------------------
11950 -- pragma Persistent_BSS [(object_NAME)];
11952 when Pragma_Persistent_BSS => Persistent_BSS : declare
11959 Check_At_Most_N_Arguments (1);
11961 -- Case of application to specific object (one argument)
11963 if Arg_Count = 1 then
11964 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11966 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11968 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11971 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11974 Ent := Entity (Get_Pragma_Arg (Arg1));
11975 Decl := Parent (Ent);
11977 if Rep_Item_Too_Late (Ent, N) then
11981 if Present (Expression (Decl)) then
11983 ("object for pragma% cannot have initialization", Arg1);
11986 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11988 ("object type for pragma% is not potentially persistent",
11992 Check_Duplicate_Pragma (Ent);
11995 Make_Linker_Section_Pragma
11996 (Ent, Sloc (N), ".persistent.bss");
11997 Insert_After (N, Prag);
12000 -- Case of use as configuration pragma with no arguments
12003 Check_Valid_Configuration_Pragma;
12004 Persistent_BSS_Mode := True;
12006 end Persistent_BSS;
12012 -- pragma Polling (ON | OFF);
12014 when Pragma_Polling =>
12016 Check_Arg_Count (1);
12017 Check_No_Identifiers;
12018 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12019 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
12021 -------------------
12022 -- Postcondition --
12023 -------------------
12025 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
12026 -- [,[Message =>] String_EXPRESSION]);
12028 when Pragma_Postcondition => Postcondition : declare
12030 pragma Warnings (Off, In_Body);
12034 Check_At_Least_N_Arguments (1);
12035 Check_At_Most_N_Arguments (2);
12036 Check_Optional_Identifier (Arg1, Name_Check);
12038 -- All we need to do here is call the common check procedure,
12039 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
12041 Check_Precondition_Postcondition (In_Body);
12048 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
12049 -- [,[Message =>] String_EXPRESSION]);
12051 when Pragma_Precondition => Precondition : declare
12056 Check_At_Least_N_Arguments (1);
12057 Check_At_Most_N_Arguments (2);
12058 Check_Optional_Identifier (Arg1, Name_Check);
12059 Check_Precondition_Postcondition (In_Body);
12061 -- If in spec, nothing more to do. If in body, then we convert the
12062 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
12063 -- this whether or not precondition checks are enabled. That works
12064 -- fine since pragma Check will do this check, and will also
12065 -- analyze the condition itself in the proper context.
12070 Chars => Name_Check,
12071 Pragma_Argument_Associations => New_List (
12072 Make_Pragma_Argument_Association (Loc,
12073 Expression => Make_Identifier (Loc, Name_Precondition)),
12075 Make_Pragma_Argument_Association (Sloc (Arg1),
12076 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
12078 if Arg_Count = 2 then
12079 Append_To (Pragma_Argument_Associations (N),
12080 Make_Pragma_Argument_Association (Sloc (Arg2),
12081 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
12092 -- pragma Predicate
12093 -- ([Entity =>] type_LOCAL_NAME,
12094 -- [Check =>] EXPRESSION);
12096 when Pragma_Predicate => Predicate : declare
12101 pragma Unreferenced (Discard);
12105 Check_Arg_Count (2);
12106 Check_Optional_Identifier (Arg1, Name_Entity);
12107 Check_Optional_Identifier (Arg2, Name_Check);
12109 Check_Arg_Is_Local_Name (Arg1);
12111 Type_Id := Get_Pragma_Arg (Arg1);
12112 Find_Type (Type_Id);
12113 Typ := Entity (Type_Id);
12115 if Typ = Any_Type then
12119 -- The remaining processing is simply to link the pragma on to
12120 -- the rep item chain, for processing when the type is frozen.
12121 -- This is accomplished by a call to Rep_Item_Too_Late. We also
12122 -- mark the type as having predicates.
12124 Set_Has_Predicates (Typ);
12125 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12132 -- pragma Preelaborate [(library_unit_NAME)];
12134 -- Set the flag Is_Preelaborated of program unit name entity
12136 when Pragma_Preelaborate => Preelaborate : declare
12137 Pa : constant Node_Id := Parent (N);
12138 Pk : constant Node_Kind := Nkind (Pa);
12142 Check_Ada_83_Warning;
12143 Check_Valid_Library_Unit_Pragma;
12145 if Nkind (N) = N_Null_Statement then
12149 Ent := Find_Lib_Unit_Name;
12150 Check_Duplicate_Pragma (Ent);
12152 -- This filters out pragmas inside generic parent then
12153 -- show up inside instantiation
12156 and then not (Pk = N_Package_Specification
12157 and then Present (Generic_Parent (Pa)))
12159 if not Debug_Flag_U then
12160 Set_Is_Preelaborated (Ent);
12161 Set_Suppress_Elaboration_Warnings (Ent);
12166 ---------------------
12167 -- Preelaborate_05 --
12168 ---------------------
12170 -- pragma Preelaborate_05 [(library_unit_NAME)];
12172 -- This pragma is useable only in GNAT_Mode, where it is used like
12173 -- pragma Preelaborate but it is only effective in Ada 2005 mode
12174 -- (otherwise it is ignored). This is used to implement AI-362 which
12175 -- recategorizes some run-time packages in Ada 2005 mode.
12177 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
12182 Check_Valid_Library_Unit_Pragma;
12184 if not GNAT_Mode then
12185 Error_Pragma ("pragma% only available in GNAT mode");
12188 if Nkind (N) = N_Null_Statement then
12192 -- This is one of the few cases where we need to test the value of
12193 -- Ada_Version_Explicit rather than Ada_Version (which is always
12194 -- set to Ada_2012 in a predefined unit), we need to know the
12195 -- explicit version set to know if this pragma is active.
12197 if Ada_Version_Explicit >= Ada_2005 then
12198 Ent := Find_Lib_Unit_Name;
12199 Set_Is_Preelaborated (Ent);
12200 Set_Suppress_Elaboration_Warnings (Ent);
12202 end Preelaborate_05;
12208 -- pragma Priority (EXPRESSION);
12210 when Pragma_Priority => Priority : declare
12211 P : constant Node_Id := Parent (N);
12215 Check_No_Identifiers;
12216 Check_Arg_Count (1);
12220 if Nkind (P) = N_Subprogram_Body then
12221 Check_In_Main_Program;
12223 Arg := Get_Pragma_Arg (Arg1);
12224 Analyze_And_Resolve (Arg, Standard_Integer);
12228 if not Is_Static_Expression (Arg) then
12229 Flag_Non_Static_Expr
12230 ("main subprogram priority is not static!", Arg);
12233 -- If constraint error, then we already signalled an error
12235 elsif Raises_Constraint_Error (Arg) then
12238 -- Otherwise check in range
12242 Val : constant Uint := Expr_Value (Arg);
12246 or else Val > Expr_Value (Expression
12247 (Parent (RTE (RE_Max_Priority))))
12250 ("main subprogram priority is out of range", Arg1);
12256 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12258 -- Load an arbitrary entity from System.Tasking to make sure
12259 -- this package is implicitly with'ed, since we need to have
12260 -- the tasking run-time active for the pragma Priority to have
12264 Discard : Entity_Id;
12265 pragma Warnings (Off, Discard);
12267 Discard := RTE (RE_Task_List);
12270 -- Task or Protected, must be of type Integer
12272 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12273 Arg := Get_Pragma_Arg (Arg1);
12275 -- The expression must be analyzed in the special manner
12276 -- described in "Handling of Default and Per-Object
12277 -- Expressions" in sem.ads.
12279 Preanalyze_Spec_Expression (Arg, Standard_Integer);
12281 if not Is_Static_Expression (Arg) then
12282 Check_Restriction (Static_Priorities, Arg);
12285 -- Anything else is incorrect
12291 if Has_Pragma_Priority (P) then
12292 Error_Pragma ("duplicate pragma% not allowed");
12294 Set_Has_Pragma_Priority (P, True);
12296 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12297 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12298 -- exp_ch9 should use this ???
12303 -----------------------------------
12304 -- Priority_Specific_Dispatching --
12305 -----------------------------------
12307 -- pragma Priority_Specific_Dispatching (
12308 -- policy_IDENTIFIER,
12309 -- first_priority_EXPRESSION,
12310 -- last_priority_EXPRESSION);
12312 when Pragma_Priority_Specific_Dispatching =>
12313 Priority_Specific_Dispatching : declare
12314 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12315 -- This is the entity System.Any_Priority;
12318 Lower_Bound : Node_Id;
12319 Upper_Bound : Node_Id;
12325 Check_Arg_Count (3);
12326 Check_No_Identifiers;
12327 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12328 Check_Valid_Configuration_Pragma;
12329 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12330 DP := Fold_Upper (Name_Buffer (1));
12332 Lower_Bound := Get_Pragma_Arg (Arg2);
12333 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12334 Lower_Val := Expr_Value (Lower_Bound);
12336 Upper_Bound := Get_Pragma_Arg (Arg3);
12337 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12338 Upper_Val := Expr_Value (Upper_Bound);
12340 -- It is not allowed to use Task_Dispatching_Policy and
12341 -- Priority_Specific_Dispatching in the same partition.
12343 if Task_Dispatching_Policy /= ' ' then
12344 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12346 ("pragma% incompatible with Task_Dispatching_Policy#");
12348 -- Check lower bound in range
12350 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12352 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12355 ("first_priority is out of range", Arg2);
12357 -- Check upper bound in range
12359 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12361 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12364 ("last_priority is out of range", Arg3);
12366 -- Check that the priority range is valid
12368 elsif Lower_Val > Upper_Val then
12370 ("last_priority_expression must be greater than" &
12371 " or equal to first_priority_expression");
12373 -- Store the new policy, but always preserve System_Location since
12374 -- we like the error message with the run-time name.
12377 -- Check overlapping in the priority ranges specified in other
12378 -- Priority_Specific_Dispatching pragmas within the same
12379 -- partition. We can only check those we know about!
12382 Specific_Dispatching.First .. Specific_Dispatching.Last
12384 if Specific_Dispatching.Table (J).First_Priority in
12385 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12386 or else Specific_Dispatching.Table (J).Last_Priority in
12387 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12390 Specific_Dispatching.Table (J).Pragma_Loc;
12392 ("priority range overlaps with "
12393 & "Priority_Specific_Dispatching#");
12397 -- The use of Priority_Specific_Dispatching is incompatible
12398 -- with Task_Dispatching_Policy.
12400 if Task_Dispatching_Policy /= ' ' then
12401 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12403 ("Priority_Specific_Dispatching incompatible "
12404 & "with Task_Dispatching_Policy#");
12407 -- The use of Priority_Specific_Dispatching forces ceiling
12410 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12411 Error_Msg_Sloc := Locking_Policy_Sloc;
12413 ("Priority_Specific_Dispatching incompatible "
12414 & "with Locking_Policy#");
12416 -- Set the Ceiling_Locking policy, but preserve System_Location
12417 -- since we like the error message with the run time name.
12420 Locking_Policy := 'C';
12422 if Locking_Policy_Sloc /= System_Location then
12423 Locking_Policy_Sloc := Loc;
12427 -- Add entry in the table
12429 Specific_Dispatching.Append
12430 ((Dispatching_Policy => DP,
12431 First_Priority => UI_To_Int (Lower_Val),
12432 Last_Priority => UI_To_Int (Upper_Val),
12433 Pragma_Loc => Loc));
12435 end Priority_Specific_Dispatching;
12441 -- pragma Profile (profile_IDENTIFIER);
12443 -- profile_IDENTIFIER => Restricted | Ravenscar
12445 when Pragma_Profile =>
12447 Check_Arg_Count (1);
12448 Check_Valid_Configuration_Pragma;
12449 Check_No_Identifiers;
12452 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12455 if Chars (Argx) = Name_Ravenscar then
12456 Set_Ravenscar_Profile (N);
12458 elsif Chars (Argx) = Name_Restricted then
12459 Set_Profile_Restrictions
12461 N, Warn => Treat_Restrictions_As_Warnings);
12463 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12464 Set_Profile_Restrictions
12465 (No_Implementation_Extensions,
12466 N, Warn => Treat_Restrictions_As_Warnings);
12469 Error_Pragma_Arg ("& is not a valid profile", Argx);
12473 ----------------------
12474 -- Profile_Warnings --
12475 ----------------------
12477 -- pragma Profile_Warnings (profile_IDENTIFIER);
12479 -- profile_IDENTIFIER => Restricted | Ravenscar
12481 when Pragma_Profile_Warnings =>
12483 Check_Arg_Count (1);
12484 Check_Valid_Configuration_Pragma;
12485 Check_No_Identifiers;
12488 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12491 if Chars (Argx) = Name_Ravenscar then
12492 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12494 elsif Chars (Argx) = Name_Restricted then
12495 Set_Profile_Restrictions (Restricted, N, Warn => True);
12497 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12498 Set_Profile_Restrictions
12499 (No_Implementation_Extensions, N, Warn => True);
12502 Error_Pragma_Arg ("& is not a valid profile", Argx);
12506 --------------------------
12507 -- Propagate_Exceptions --
12508 --------------------------
12510 -- pragma Propagate_Exceptions;
12512 -- Note: this pragma is obsolete and has no effect
12514 when Pragma_Propagate_Exceptions =>
12516 Check_Arg_Count (0);
12518 if In_Extended_Main_Source_Unit (N) then
12519 Propagate_Exceptions := True;
12526 -- pragma Psect_Object (
12527 -- [Internal =>] LOCAL_NAME,
12528 -- [, [External =>] EXTERNAL_SYMBOL]
12529 -- [, [Size =>] EXTERNAL_SYMBOL]);
12531 when Pragma_Psect_Object | Pragma_Common_Object =>
12532 Psect_Object : declare
12533 Args : Args_List (1 .. 3);
12534 Names : constant Name_List (1 .. 3) := (
12539 Internal : Node_Id renames Args (1);
12540 External : Node_Id renames Args (2);
12541 Size : Node_Id renames Args (3);
12543 Def_Id : Entity_Id;
12545 procedure Check_Too_Long (Arg : Node_Id);
12546 -- Posts message if the argument is an identifier with more
12547 -- than 31 characters, or a string literal with more than
12548 -- 31 characters, and we are operating under VMS
12550 --------------------
12551 -- Check_Too_Long --
12552 --------------------
12554 procedure Check_Too_Long (Arg : Node_Id) is
12555 X : constant Node_Id := Original_Node (Arg);
12558 if not Nkind_In (X, N_String_Literal, N_Identifier) then
12560 ("inappropriate argument for pragma %", Arg);
12563 if OpenVMS_On_Target then
12564 if (Nkind (X) = N_String_Literal
12565 and then String_Length (Strval (X)) > 31)
12567 (Nkind (X) = N_Identifier
12568 and then Length_Of_Name (Chars (X)) > 31)
12571 ("argument for pragma % is longer than 31 characters",
12575 end Check_Too_Long;
12577 -- Start of processing for Common_Object/Psect_Object
12581 Gather_Associations (Names, Args);
12582 Process_Extended_Import_Export_Internal_Arg (Internal);
12584 Def_Id := Entity (Internal);
12586 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12588 ("pragma% must designate an object", Internal);
12591 Check_Too_Long (Internal);
12593 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12595 ("cannot use pragma% for imported/exported object",
12599 if Is_Concurrent_Type (Etype (Internal)) then
12601 ("cannot specify pragma % for task/protected object",
12605 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12607 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12609 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12612 if Ekind (Def_Id) = E_Constant then
12614 ("cannot specify pragma % for a constant", Internal);
12617 if Is_Record_Type (Etype (Internal)) then
12623 Ent := First_Entity (Etype (Internal));
12624 while Present (Ent) loop
12625 Decl := Declaration_Node (Ent);
12627 if Ekind (Ent) = E_Component
12628 and then Nkind (Decl) = N_Component_Declaration
12629 and then Present (Expression (Decl))
12630 and then Warn_On_Export_Import
12633 ("?object for pragma % has defaults", Internal);
12643 if Present (Size) then
12644 Check_Too_Long (Size);
12647 if Present (External) then
12648 Check_Arg_Is_External_Name (External);
12649 Check_Too_Long (External);
12652 -- If all error tests pass, link pragma on to the rep item chain
12654 Record_Rep_Item (Def_Id, N);
12661 -- pragma Pure [(library_unit_NAME)];
12663 when Pragma_Pure => Pure : declare
12667 Check_Ada_83_Warning;
12668 Check_Valid_Library_Unit_Pragma;
12670 if Nkind (N) = N_Null_Statement then
12674 Ent := Find_Lib_Unit_Name;
12676 Set_Has_Pragma_Pure (Ent);
12677 Set_Suppress_Elaboration_Warnings (Ent);
12684 -- pragma Pure_05 [(library_unit_NAME)];
12686 -- This pragma is useable only in GNAT_Mode, where it is used like
12687 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
12688 -- it is ignored). It may be used after a pragma Preelaborate, in
12689 -- which case it overrides the effect of the pragma Preelaborate.
12690 -- This is used to implement AI-362 which recategorizes some run-time
12691 -- packages in Ada 2005 mode.
12693 when Pragma_Pure_05 => Pure_05 : declare
12698 Check_Valid_Library_Unit_Pragma;
12700 if not GNAT_Mode then
12701 Error_Pragma ("pragma% only available in GNAT mode");
12704 if Nkind (N) = N_Null_Statement then
12708 -- This is one of the few cases where we need to test the value of
12709 -- Ada_Version_Explicit rather than Ada_Version (which is always
12710 -- set to Ada_2012 in a predefined unit), we need to know the
12711 -- explicit version set to know if this pragma is active.
12713 if Ada_Version_Explicit >= Ada_2005 then
12714 Ent := Find_Lib_Unit_Name;
12715 Set_Is_Preelaborated (Ent, False);
12717 Set_Suppress_Elaboration_Warnings (Ent);
12725 -- pragma Pure_12 [(library_unit_NAME)];
12727 -- This pragma is useable only in GNAT_Mode, where it is used like
12728 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
12729 -- it is ignored). It may be used after a pragma Preelaborate, in
12730 -- which case it overrides the effect of the pragma Preelaborate.
12731 -- This is used to implement AI05-0212 which recategorizes some
12732 -- run-time packages in Ada 2012 mode.
12734 when Pragma_Pure_12 => Pure_12 : declare
12739 Check_Valid_Library_Unit_Pragma;
12741 if not GNAT_Mode then
12742 Error_Pragma ("pragma% only available in GNAT mode");
12745 if Nkind (N) = N_Null_Statement then
12749 -- This is one of the few cases where we need to test the value of
12750 -- Ada_Version_Explicit rather than Ada_Version (which is always
12751 -- set to Ada_2012 in a predefined unit), we need to know the
12752 -- explicit version set to know if this pragma is active.
12754 if Ada_Version_Explicit >= Ada_2012 then
12755 Ent := Find_Lib_Unit_Name;
12756 Set_Is_Preelaborated (Ent, False);
12758 Set_Suppress_Elaboration_Warnings (Ent);
12762 -------------------
12763 -- Pure_Function --
12764 -------------------
12766 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12768 when Pragma_Pure_Function => Pure_Function : declare
12771 Def_Id : Entity_Id;
12772 Effective : Boolean := False;
12776 Check_Arg_Count (1);
12777 Check_Optional_Identifier (Arg1, Name_Entity);
12778 Check_Arg_Is_Local_Name (Arg1);
12779 E_Id := Get_Pragma_Arg (Arg1);
12781 if Error_Posted (E_Id) then
12785 -- Loop through homonyms (overloadings) of referenced entity
12787 E := Entity (E_Id);
12789 if Present (E) then
12791 Def_Id := Get_Base_Subprogram (E);
12793 if not Ekind_In (Def_Id, E_Function,
12794 E_Generic_Function,
12798 ("pragma% requires a function name", Arg1);
12801 Set_Is_Pure (Def_Id);
12803 if not Has_Pragma_Pure_Function (Def_Id) then
12804 Set_Has_Pragma_Pure_Function (Def_Id);
12808 exit when From_Aspect_Specification (N);
12810 exit when No (E) or else Scope (E) /= Current_Scope;
12814 and then Warn_On_Redundant_Constructs
12817 ("pragma Pure_Function on& is redundant?",
12823 --------------------
12824 -- Queuing_Policy --
12825 --------------------
12827 -- pragma Queuing_Policy (policy_IDENTIFIER);
12829 when Pragma_Queuing_Policy => declare
12833 Check_Ada_83_Warning;
12834 Check_Arg_Count (1);
12835 Check_No_Identifiers;
12836 Check_Arg_Is_Queuing_Policy (Arg1);
12837 Check_Valid_Configuration_Pragma;
12838 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12839 QP := Fold_Upper (Name_Buffer (1));
12841 if Queuing_Policy /= ' '
12842 and then Queuing_Policy /= QP
12844 Error_Msg_Sloc := Queuing_Policy_Sloc;
12845 Error_Pragma ("queuing policy incompatible with policy#");
12847 -- Set new policy, but always preserve System_Location since we
12848 -- like the error message with the run time name.
12851 Queuing_Policy := QP;
12853 if Queuing_Policy_Sloc /= System_Location then
12854 Queuing_Policy_Sloc := Loc;
12859 -----------------------
12860 -- Relative_Deadline --
12861 -----------------------
12863 -- pragma Relative_Deadline (time_span_EXPRESSION);
12865 when Pragma_Relative_Deadline => Relative_Deadline : declare
12866 P : constant Node_Id := Parent (N);
12871 Check_No_Identifiers;
12872 Check_Arg_Count (1);
12874 Arg := Get_Pragma_Arg (Arg1);
12876 -- The expression must be analyzed in the special manner described
12877 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12879 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12883 if Nkind (P) = N_Subprogram_Body then
12884 Check_In_Main_Program;
12888 elsif Nkind (P) = N_Task_Definition then
12891 -- Anything else is incorrect
12897 if Has_Relative_Deadline_Pragma (P) then
12898 Error_Pragma ("duplicate pragma% not allowed");
12900 Set_Has_Relative_Deadline_Pragma (P, True);
12902 if Nkind (P) = N_Task_Definition then
12903 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12906 end Relative_Deadline;
12908 ------------------------
12909 -- Remote_Access_Type --
12910 ------------------------
12912 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
12914 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
12919 Check_Arg_Count (1);
12920 Check_Optional_Identifier (Arg1, Name_Entity);
12921 Check_Arg_Is_Local_Name (Arg1);
12923 E := Entity (Get_Pragma_Arg (Arg1));
12925 if Nkind (Parent (E)) = N_Formal_Type_Declaration
12926 and then Ekind (E) = E_General_Access_Type
12927 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
12928 and then Scope (Root_Type (Directly_Designated_Type (E)))
12930 and then Is_Valid_Remote_Object_Type
12931 (Root_Type (Directly_Designated_Type (E)))
12933 Set_Is_Remote_Types (E);
12937 ("pragma% applies only to formal access to classwide types",
12940 end Remote_Access_Type;
12942 ---------------------------
12943 -- Remote_Call_Interface --
12944 ---------------------------
12946 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12948 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12949 Cunit_Node : Node_Id;
12950 Cunit_Ent : Entity_Id;
12954 Check_Ada_83_Warning;
12955 Check_Valid_Library_Unit_Pragma;
12957 if Nkind (N) = N_Null_Statement then
12961 Cunit_Node := Cunit (Current_Sem_Unit);
12962 K := Nkind (Unit (Cunit_Node));
12963 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12965 if K = N_Package_Declaration
12966 or else K = N_Generic_Package_Declaration
12967 or else K = N_Subprogram_Declaration
12968 or else K = N_Generic_Subprogram_Declaration
12969 or else (K = N_Subprogram_Body
12970 and then Acts_As_Spec (Unit (Cunit_Node)))
12975 "pragma% must apply to package or subprogram declaration");
12978 Set_Is_Remote_Call_Interface (Cunit_Ent);
12979 end Remote_Call_Interface;
12985 -- pragma Remote_Types [(library_unit_NAME)];
12987 when Pragma_Remote_Types => Remote_Types : declare
12988 Cunit_Node : Node_Id;
12989 Cunit_Ent : Entity_Id;
12992 Check_Ada_83_Warning;
12993 Check_Valid_Library_Unit_Pragma;
12995 if Nkind (N) = N_Null_Statement then
12999 Cunit_Node := Cunit (Current_Sem_Unit);
13000 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13002 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13003 N_Generic_Package_Declaration)
13006 ("pragma% can only apply to a package declaration");
13009 Set_Is_Remote_Types (Cunit_Ent);
13016 -- pragma Ravenscar;
13018 when Pragma_Ravenscar =>
13020 Check_Arg_Count (0);
13021 Check_Valid_Configuration_Pragma;
13022 Set_Ravenscar_Profile (N);
13024 if Warn_On_Obsolescent_Feature then
13025 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
13026 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
13029 -------------------------
13030 -- Restricted_Run_Time --
13031 -------------------------
13033 -- pragma Restricted_Run_Time;
13035 when Pragma_Restricted_Run_Time =>
13037 Check_Arg_Count (0);
13038 Check_Valid_Configuration_Pragma;
13039 Set_Profile_Restrictions
13040 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
13042 if Warn_On_Obsolescent_Feature then
13044 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
13045 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
13052 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
13055 -- restriction_IDENTIFIER
13056 -- | restriction_parameter_IDENTIFIER => EXPRESSION
13058 when Pragma_Restrictions =>
13059 Process_Restrictions_Or_Restriction_Warnings
13060 (Warn => Treat_Restrictions_As_Warnings);
13062 --------------------------
13063 -- Restriction_Warnings --
13064 --------------------------
13066 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
13069 -- restriction_IDENTIFIER
13070 -- | restriction_parameter_IDENTIFIER => EXPRESSION
13072 when Pragma_Restriction_Warnings =>
13074 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
13080 -- pragma Reviewable;
13082 when Pragma_Reviewable =>
13083 Check_Ada_83_Warning;
13084 Check_Arg_Count (0);
13086 -- Call dummy debugging function rv. This is done to assist front
13087 -- end debugging. By placing a Reviewable pragma in the source
13088 -- program, a breakpoint on rv catches this place in the source,
13089 -- allowing convenient stepping to the point of interest.
13093 --------------------------
13094 -- Short_Circuit_And_Or --
13095 --------------------------
13097 when Pragma_Short_Circuit_And_Or =>
13099 Check_Arg_Count (0);
13100 Check_Valid_Configuration_Pragma;
13101 Short_Circuit_And_Or := True;
13103 -------------------
13104 -- Share_Generic --
13105 -------------------
13107 -- pragma Share_Generic (NAME {, NAME});
13109 when Pragma_Share_Generic =>
13111 Process_Generic_List;
13117 -- pragma Shared (LOCAL_NAME);
13119 when Pragma_Shared =>
13121 Process_Atomic_Shared_Volatile;
13123 --------------------
13124 -- Shared_Passive --
13125 --------------------
13127 -- pragma Shared_Passive [(library_unit_NAME)];
13129 -- Set the flag Is_Shared_Passive of program unit name entity
13131 when Pragma_Shared_Passive => Shared_Passive : declare
13132 Cunit_Node : Node_Id;
13133 Cunit_Ent : Entity_Id;
13136 Check_Ada_83_Warning;
13137 Check_Valid_Library_Unit_Pragma;
13139 if Nkind (N) = N_Null_Statement then
13143 Cunit_Node := Cunit (Current_Sem_Unit);
13144 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13146 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13147 N_Generic_Package_Declaration)
13150 ("pragma% can only apply to a package declaration");
13153 Set_Is_Shared_Passive (Cunit_Ent);
13154 end Shared_Passive;
13156 -----------------------
13157 -- Short_Descriptors --
13158 -----------------------
13160 -- pragma Short_Descriptors;
13162 when Pragma_Short_Descriptors =>
13164 Check_Arg_Count (0);
13165 Check_Valid_Configuration_Pragma;
13166 Short_Descriptors := True;
13168 ------------------------------
13169 -- Simple_Storage_Pool_Type --
13170 ------------------------------
13172 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
13174 when Pragma_Simple_Storage_Pool_Type =>
13175 Simple_Storage_Pool_Type : declare
13181 Check_Arg_Count (1);
13182 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13184 Type_Id := Get_Pragma_Arg (Arg1);
13185 Find_Type (Type_Id);
13186 Typ := Entity (Type_Id);
13188 if Typ = Any_Type then
13192 -- We require the pragma to apply to a type declared in a package
13193 -- declaration, but not (immediately) within a package body.
13195 if Ekind (Current_Scope) /= E_Package
13196 or else In_Package_Body (Current_Scope)
13199 ("pragma% can only apply to type declared immediately " &
13200 "within a package declaration");
13203 -- A simple storage pool type must be an immutably limited record
13204 -- or private type. If the pragma is given for a private type,
13205 -- the full type is similarly restricted (which is checked later
13206 -- in Freeze_Entity).
13208 if Is_Record_Type (Typ)
13209 and then not Is_Immutably_Limited_Type (Typ)
13212 ("pragma% can only apply to explicitly limited record type");
13214 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
13216 ("pragma% can only apply to a private type that is limited");
13218 elsif not Is_Record_Type (Typ)
13219 and then not Is_Private_Type (Typ)
13222 ("pragma% can only apply to limited record or private type");
13225 Record_Rep_Item (Typ, N);
13226 end Simple_Storage_Pool_Type;
13228 ----------------------
13229 -- Source_File_Name --
13230 ----------------------
13232 -- There are five forms for this pragma:
13234 -- pragma Source_File_Name (
13235 -- [UNIT_NAME =>] unit_NAME,
13236 -- BODY_FILE_NAME => STRING_LITERAL
13237 -- [, [INDEX =>] INTEGER_LITERAL]);
13239 -- pragma Source_File_Name (
13240 -- [UNIT_NAME =>] unit_NAME,
13241 -- SPEC_FILE_NAME => STRING_LITERAL
13242 -- [, [INDEX =>] INTEGER_LITERAL]);
13244 -- pragma Source_File_Name (
13245 -- BODY_FILE_NAME => STRING_LITERAL
13246 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13247 -- [, CASING => CASING_SPEC]);
13249 -- pragma Source_File_Name (
13250 -- SPEC_FILE_NAME => STRING_LITERAL
13251 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13252 -- [, CASING => CASING_SPEC]);
13254 -- pragma Source_File_Name (
13255 -- SUBUNIT_FILE_NAME => STRING_LITERAL
13256 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13257 -- [, CASING => CASING_SPEC]);
13259 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
13261 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
13262 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
13263 -- only be used when no project file is used, while SFNP can only be
13264 -- used when a project file is used.
13266 -- No processing here. Processing was completed during parsing, since
13267 -- we need to have file names set as early as possible. Units are
13268 -- loaded well before semantic processing starts.
13270 -- The only processing we defer to this point is the check for
13271 -- correct placement.
13273 when Pragma_Source_File_Name =>
13275 Check_Valid_Configuration_Pragma;
13277 ------------------------------
13278 -- Source_File_Name_Project --
13279 ------------------------------
13281 -- See Source_File_Name for syntax
13283 -- No processing here. Processing was completed during parsing, since
13284 -- we need to have file names set as early as possible. Units are
13285 -- loaded well before semantic processing starts.
13287 -- The only processing we defer to this point is the check for
13288 -- correct placement.
13290 when Pragma_Source_File_Name_Project =>
13292 Check_Valid_Configuration_Pragma;
13294 -- Check that a pragma Source_File_Name_Project is used only in a
13295 -- configuration pragmas file.
13297 -- Pragmas Source_File_Name_Project should only be generated by
13298 -- the Project Manager in configuration pragmas files.
13300 -- This is really an ugly test. It seems to depend on some
13301 -- accidental and undocumented property. At the very least it
13302 -- needs to be documented, but it would be better to have a
13303 -- clean way of testing if we are in a configuration file???
13305 if Present (Parent (N)) then
13307 ("pragma% can only appear in a configuration pragmas file");
13310 ----------------------
13311 -- Source_Reference --
13312 ----------------------
13314 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
13316 -- Nothing to do, all processing completed in Par.Prag, since we need
13317 -- the information for possible parser messages that are output.
13319 when Pragma_Source_Reference =>
13322 --------------------------------
13323 -- Static_Elaboration_Desired --
13324 --------------------------------
13326 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
13328 when Pragma_Static_Elaboration_Desired =>
13330 Check_At_Most_N_Arguments (1);
13332 if Is_Compilation_Unit (Current_Scope)
13333 and then Ekind (Current_Scope) = E_Package
13335 Set_Static_Elaboration_Desired (Current_Scope, True);
13337 Error_Pragma ("pragma% must apply to a library-level package");
13344 -- pragma Storage_Size (EXPRESSION);
13346 when Pragma_Storage_Size => Storage_Size : declare
13347 P : constant Node_Id := Parent (N);
13351 Check_No_Identifiers;
13352 Check_Arg_Count (1);
13354 -- The expression must be analyzed in the special manner described
13355 -- in "Handling of Default Expressions" in sem.ads.
13357 Arg := Get_Pragma_Arg (Arg1);
13358 Preanalyze_Spec_Expression (Arg, Any_Integer);
13360 if not Is_Static_Expression (Arg) then
13361 Check_Restriction (Static_Storage_Size, Arg);
13364 if Nkind (P) /= N_Task_Definition then
13369 if Has_Storage_Size_Pragma (P) then
13370 Error_Pragma ("duplicate pragma% not allowed");
13372 Set_Has_Storage_Size_Pragma (P, True);
13375 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13376 -- ??? exp_ch9 should use this!
13384 -- pragma Storage_Unit (NUMERIC_LITERAL);
13386 -- Only permitted argument is System'Storage_Unit value
13388 when Pragma_Storage_Unit =>
13389 Check_No_Identifiers;
13390 Check_Arg_Count (1);
13391 Check_Arg_Is_Integer_Literal (Arg1);
13393 if Intval (Get_Pragma_Arg (Arg1)) /=
13394 UI_From_Int (Ttypes.System_Storage_Unit)
13396 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
13398 ("the only allowed argument for pragma% is ^", Arg1);
13401 --------------------
13402 -- Stream_Convert --
13403 --------------------
13405 -- pragma Stream_Convert (
13406 -- [Entity =>] type_LOCAL_NAME,
13407 -- [Read =>] function_NAME,
13408 -- [Write =>] function NAME);
13410 when Pragma_Stream_Convert => Stream_Convert : declare
13412 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
13413 -- Check that the given argument is the name of a local function
13414 -- of one argument that is not overloaded earlier in the current
13415 -- local scope. A check is also made that the argument is a
13416 -- function with one parameter.
13418 --------------------------------------
13419 -- Check_OK_Stream_Convert_Function --
13420 --------------------------------------
13422 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
13426 Check_Arg_Is_Local_Name (Arg);
13427 Ent := Entity (Get_Pragma_Arg (Arg));
13429 if Has_Homonym (Ent) then
13431 ("argument for pragma% may not be overloaded", Arg);
13434 if Ekind (Ent) /= E_Function
13435 or else No (First_Formal (Ent))
13436 or else Present (Next_Formal (First_Formal (Ent)))
13439 ("argument for pragma% must be" &
13440 " function of one argument", Arg);
13442 end Check_OK_Stream_Convert_Function;
13444 -- Start of processing for Stream_Convert
13448 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
13449 Check_Arg_Count (3);
13450 Check_Optional_Identifier (Arg1, Name_Entity);
13451 Check_Optional_Identifier (Arg2, Name_Read);
13452 Check_Optional_Identifier (Arg3, Name_Write);
13453 Check_Arg_Is_Local_Name (Arg1);
13454 Check_OK_Stream_Convert_Function (Arg2);
13455 Check_OK_Stream_Convert_Function (Arg3);
13458 Typ : constant Entity_Id :=
13459 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13460 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13461 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
13464 Check_First_Subtype (Arg1);
13466 -- Check for too early or too late. Note that we don't enforce
13467 -- the rule about primitive operations in this case, since, as
13468 -- is the case for explicit stream attributes themselves, these
13469 -- restrictions are not appropriate. Note that the chaining of
13470 -- the pragma by Rep_Item_Too_Late is actually the critical
13471 -- processing done for this pragma.
13473 if Rep_Item_Too_Early (Typ, N)
13475 Rep_Item_Too_Late (Typ, N, FOnly => True)
13480 -- Return if previous error
13482 if Etype (Typ) = Any_Type
13484 Etype (Read) = Any_Type
13486 Etype (Write) = Any_Type
13493 if Underlying_Type (Etype (Read)) /= Typ then
13495 ("incorrect return type for function&", Arg2);
13498 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13500 ("incorrect parameter type for function&", Arg3);
13503 if Underlying_Type (Etype (First_Formal (Read))) /=
13504 Underlying_Type (Etype (Write))
13507 ("result type of & does not match Read parameter type",
13511 end Stream_Convert;
13513 -------------------------
13514 -- Style_Checks (GNAT) --
13515 -------------------------
13517 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13519 -- This is processed by the parser since some of the style checks
13520 -- take place during source scanning and parsing. This means that
13521 -- we don't need to issue error messages here.
13523 when Pragma_Style_Checks => Style_Checks : declare
13524 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13530 Check_No_Identifiers;
13532 -- Two argument form
13534 if Arg_Count = 2 then
13535 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13542 E_Id := Get_Pragma_Arg (Arg2);
13545 if not Is_Entity_Name (E_Id) then
13547 ("second argument of pragma% must be entity name",
13551 E := Entity (E_Id);
13557 Set_Suppress_Style_Checks (E,
13558 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
13559 exit when No (Homonym (E));
13565 -- One argument form
13568 Check_Arg_Count (1);
13570 if Nkind (A) = N_String_Literal then
13574 Slen : constant Natural := Natural (String_Length (S));
13575 Options : String (1 .. Slen);
13581 C := Get_String_Char (S, Int (J));
13582 exit when not In_Character_Range (C);
13583 Options (J) := Get_Character (C);
13585 -- If at end of string, set options. As per discussion
13586 -- above, no need to check for errors, since we issued
13587 -- them in the parser.
13590 Set_Style_Check_Options (Options);
13598 elsif Nkind (A) = N_Identifier then
13599 if Chars (A) = Name_All_Checks then
13601 Set_GNAT_Style_Check_Options;
13603 Set_Default_Style_Check_Options;
13606 elsif Chars (A) = Name_On then
13607 Style_Check := True;
13609 elsif Chars (A) = Name_Off then
13610 Style_Check := False;
13620 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13622 when Pragma_Subtitle =>
13624 Check_Arg_Count (1);
13625 Check_Optional_Identifier (Arg1, Name_Subtitle);
13626 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13633 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13635 when Pragma_Suppress =>
13636 Process_Suppress_Unsuppress (True);
13642 -- pragma Suppress_All;
13644 -- The only check made here is that the pragma has no arguments.
13645 -- There are no placement rules, and the processing required (setting
13646 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
13647 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
13648 -- then creates and inserts a pragma Suppress (All_Checks).
13650 when Pragma_Suppress_All =>
13652 Check_Arg_Count (0);
13654 -------------------------
13655 -- Suppress_Debug_Info --
13656 -------------------------
13658 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13660 when Pragma_Suppress_Debug_Info =>
13662 Check_Arg_Count (1);
13663 Check_Optional_Identifier (Arg1, Name_Entity);
13664 Check_Arg_Is_Local_Name (Arg1);
13665 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13667 ----------------------------------
13668 -- Suppress_Exception_Locations --
13669 ----------------------------------
13671 -- pragma Suppress_Exception_Locations;
13673 when Pragma_Suppress_Exception_Locations =>
13675 Check_Arg_Count (0);
13676 Check_Valid_Configuration_Pragma;
13677 Exception_Locations_Suppressed := True;
13679 -----------------------------
13680 -- Suppress_Initialization --
13681 -----------------------------
13683 -- pragma Suppress_Initialization ([Entity =>] type_Name);
13685 when Pragma_Suppress_Initialization => Suppress_Init : declare
13691 Check_Arg_Count (1);
13692 Check_Optional_Identifier (Arg1, Name_Entity);
13693 Check_Arg_Is_Local_Name (Arg1);
13695 E_Id := Get_Pragma_Arg (Arg1);
13697 if Etype (E_Id) = Any_Type then
13701 E := Entity (E_Id);
13703 if not Is_Type (E) then
13704 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13707 if Rep_Item_Too_Early (E, N)
13709 Rep_Item_Too_Late (E, N, FOnly => True)
13714 -- For incomplete/private type, set flag on full view
13716 if Is_Incomplete_Or_Private_Type (E) then
13717 if No (Full_View (Base_Type (E))) then
13719 ("argument of pragma% cannot be an incomplete type", Arg1);
13721 Set_Suppress_Initialization (Full_View (Base_Type (E)));
13724 -- For first subtype, set flag on base type
13726 elsif Is_First_Subtype (E) then
13727 Set_Suppress_Initialization (Base_Type (E));
13729 -- For other than first subtype, set flag on subtype itself
13732 Set_Suppress_Initialization (E);
13740 -- pragma System_Name (DIRECT_NAME);
13742 -- Syntax check: one argument, which must be the identifier GNAT or
13743 -- the identifier GCC, no other identifiers are acceptable.
13745 when Pragma_System_Name =>
13747 Check_No_Identifiers;
13748 Check_Arg_Count (1);
13749 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13751 -----------------------------
13752 -- Task_Dispatching_Policy --
13753 -----------------------------
13755 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13757 when Pragma_Task_Dispatching_Policy => declare
13761 Check_Ada_83_Warning;
13762 Check_Arg_Count (1);
13763 Check_No_Identifiers;
13764 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13765 Check_Valid_Configuration_Pragma;
13766 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13767 DP := Fold_Upper (Name_Buffer (1));
13769 if Task_Dispatching_Policy /= ' '
13770 and then Task_Dispatching_Policy /= DP
13772 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13774 ("task dispatching policy incompatible with policy#");
13776 -- Set new policy, but always preserve System_Location since we
13777 -- like the error message with the run time name.
13780 Task_Dispatching_Policy := DP;
13782 if Task_Dispatching_Policy_Sloc /= System_Location then
13783 Task_Dispatching_Policy_Sloc := Loc;
13792 -- pragma Task_Info (EXPRESSION);
13794 when Pragma_Task_Info => Task_Info : declare
13795 P : constant Node_Id := Parent (N);
13800 if Nkind (P) /= N_Task_Definition then
13801 Error_Pragma ("pragma% must appear in task definition");
13804 Check_No_Identifiers;
13805 Check_Arg_Count (1);
13807 Analyze_And_Resolve
13808 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13810 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13814 if Has_Task_Info_Pragma (P) then
13815 Error_Pragma ("duplicate pragma% not allowed");
13817 Set_Has_Task_Info_Pragma (P, True);
13825 -- pragma Task_Name (string_EXPRESSION);
13827 when Pragma_Task_Name => Task_Name : declare
13828 P : constant Node_Id := Parent (N);
13832 Check_No_Identifiers;
13833 Check_Arg_Count (1);
13835 Arg := Get_Pragma_Arg (Arg1);
13837 -- The expression is used in the call to Create_Task, and must be
13838 -- expanded there, not in the context of the current spec. It must
13839 -- however be analyzed to capture global references, in case it
13840 -- appears in a generic context.
13842 Preanalyze_And_Resolve (Arg, Standard_String);
13844 if Nkind (P) /= N_Task_Definition then
13848 if Has_Task_Name_Pragma (P) then
13849 Error_Pragma ("duplicate pragma% not allowed");
13851 Set_Has_Task_Name_Pragma (P, True);
13852 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13860 -- pragma Task_Storage (
13861 -- [Task_Type =>] LOCAL_NAME,
13862 -- [Top_Guard =>] static_integer_EXPRESSION);
13864 when Pragma_Task_Storage => Task_Storage : declare
13865 Args : Args_List (1 .. 2);
13866 Names : constant Name_List (1 .. 2) := (
13870 Task_Type : Node_Id renames Args (1);
13871 Top_Guard : Node_Id renames Args (2);
13877 Gather_Associations (Names, Args);
13879 if No (Task_Type) then
13881 ("missing task_type argument for pragma%");
13884 Check_Arg_Is_Local_Name (Task_Type);
13886 Ent := Entity (Task_Type);
13888 if not Is_Task_Type (Ent) then
13890 ("argument for pragma% must be task type", Task_Type);
13893 if No (Top_Guard) then
13895 ("pragma% takes two arguments", Task_Type);
13897 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13900 Check_First_Subtype (Task_Type);
13902 if Rep_Item_Too_Late (Ent, N) then
13911 -- pragma Test_Case ([Name =>] Static_String_EXPRESSION
13912 -- ,[Mode =>] MODE_TYPE
13913 -- [, Requires => Boolean_EXPRESSION]
13914 -- [, Ensures => Boolean_EXPRESSION]);
13916 -- MODE_TYPE ::= Nominal | Robustness
13918 when Pragma_Test_Case => Test_Case : declare
13921 Check_At_Least_N_Arguments (2);
13922 Check_At_Most_N_Arguments (4);
13924 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13926 Check_Optional_Identifier (Arg1, Name_Name);
13927 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13929 -- In ASIS mode, for a pragma generated from a source aspect, also
13930 -- analyze the original aspect expression.
13933 and then Present (Corresponding_Aspect (N))
13935 Check_Expr_Is_Static_Expression
13936 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
13939 Check_Optional_Identifier (Arg2, Name_Mode);
13940 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13942 if Arg_Count = 4 then
13943 Check_Identifier (Arg3, Name_Requires);
13944 Check_Identifier (Arg4, Name_Ensures);
13946 elsif Arg_Count = 3 then
13947 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13953 --------------------------
13954 -- Thread_Local_Storage --
13955 --------------------------
13957 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13959 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13965 Check_Arg_Count (1);
13966 Check_Optional_Identifier (Arg1, Name_Entity);
13967 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13969 Id := Get_Pragma_Arg (Arg1);
13972 if not Is_Entity_Name (Id)
13973 or else Ekind (Entity (Id)) /= E_Variable
13975 Error_Pragma_Arg ("local variable name required", Arg1);
13980 if Rep_Item_Too_Early (E, N)
13981 or else Rep_Item_Too_Late (E, N)
13986 Set_Has_Pragma_Thread_Local_Storage (E);
13987 Set_Has_Gigi_Rep_Item (E);
13988 end Thread_Local_Storage;
13994 -- pragma Time_Slice (static_duration_EXPRESSION);
13996 when Pragma_Time_Slice => Time_Slice : declare
14002 Check_Arg_Count (1);
14003 Check_No_Identifiers;
14004 Check_In_Main_Program;
14005 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
14007 if not Error_Posted (Arg1) then
14009 while Present (Nod) loop
14010 if Nkind (Nod) = N_Pragma
14011 and then Pragma_Name (Nod) = Name_Time_Slice
14013 Error_Msg_Name_1 := Pname;
14014 Error_Msg_N ("duplicate pragma% not permitted", Nod);
14021 -- Process only if in main unit
14023 if Get_Source_Unit (Loc) = Main_Unit then
14024 Opt.Time_Slice_Set := True;
14025 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
14027 if Val <= Ureal_0 then
14028 Opt.Time_Slice_Value := 0;
14030 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
14031 Opt.Time_Slice_Value := 1_000_000_000;
14034 Opt.Time_Slice_Value :=
14035 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
14044 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
14046 -- TITLING_OPTION ::=
14047 -- [Title =>] STRING_LITERAL
14048 -- | [Subtitle =>] STRING_LITERAL
14050 when Pragma_Title => Title : declare
14051 Args : Args_List (1 .. 2);
14052 Names : constant Name_List (1 .. 2) := (
14058 Gather_Associations (Names, Args);
14061 for J in 1 .. 2 loop
14062 if Present (Args (J)) then
14063 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
14068 ---------------------
14069 -- Unchecked_Union --
14070 ---------------------
14072 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
14074 when Pragma_Unchecked_Union => Unchecked_Union : declare
14075 Assoc : constant Node_Id := Arg1;
14076 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
14087 Check_No_Identifiers;
14088 Check_Arg_Count (1);
14089 Check_Arg_Is_Local_Name (Arg1);
14091 Find_Type (Type_Id);
14092 Typ := Entity (Type_Id);
14095 or else Rep_Item_Too_Early (Typ, N)
14099 Typ := Underlying_Type (Typ);
14102 if Rep_Item_Too_Late (Typ, N) then
14106 Check_First_Subtype (Arg1);
14108 -- Note remaining cases are references to a type in the current
14109 -- declarative part. If we find an error, we post the error on
14110 -- the relevant type declaration at an appropriate point.
14112 if not Is_Record_Type (Typ) then
14113 Error_Msg_N ("Unchecked_Union must be record type", Typ);
14116 elsif Is_Tagged_Type (Typ) then
14117 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
14120 elsif not Has_Discriminants (Typ) then
14122 ("Unchecked_Union must have one discriminant", Typ);
14125 -- Note: in previous versions of GNAT we used to check for limited
14126 -- types and give an error, but in fact the standard does allow
14127 -- Unchecked_Union on limited types, so this check was removed.
14129 -- Proceed with basic error checks completed
14132 Discr := First_Discriminant (Typ);
14133 while Present (Discr) loop
14134 if No (Discriminant_Default_Value (Discr)) then
14136 ("Unchecked_Union discriminant must have default value",
14140 Next_Discriminant (Discr);
14143 Tdef := Type_Definition (Declaration_Node (Typ));
14144 Clist := Component_List (Tdef);
14146 Comp := First (Component_Items (Clist));
14147 while Present (Comp) loop
14148 Check_Component (Comp, Typ);
14152 if No (Clist) or else No (Variant_Part (Clist)) then
14154 ("Unchecked_Union must have variant part",
14159 Vpart := Variant_Part (Clist);
14161 Variant := First (Variants (Vpart));
14162 while Present (Variant) loop
14163 Check_Variant (Variant, Typ);
14168 Set_Is_Unchecked_Union (Typ);
14169 Set_Convention (Typ, Convention_C);
14170 Set_Has_Unchecked_Union (Base_Type (Typ));
14171 Set_Is_Unchecked_Union (Base_Type (Typ));
14172 end Unchecked_Union;
14174 ------------------------
14175 -- Unimplemented_Unit --
14176 ------------------------
14178 -- pragma Unimplemented_Unit;
14180 -- Note: this only gives an error if we are generating code, or if
14181 -- we are in a generic library unit (where the pragma appears in the
14182 -- body, not in the spec).
14184 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
14185 Cunitent : constant Entity_Id :=
14186 Cunit_Entity (Get_Source_Unit (Loc));
14187 Ent_Kind : constant Entity_Kind :=
14192 Check_Arg_Count (0);
14194 if Operating_Mode = Generate_Code
14195 or else Ent_Kind = E_Generic_Function
14196 or else Ent_Kind = E_Generic_Procedure
14197 or else Ent_Kind = E_Generic_Package
14199 Get_Name_String (Chars (Cunitent));
14200 Set_Casing (Mixed_Case);
14201 Write_Str (Name_Buffer (1 .. Name_Len));
14202 Write_Str (" is not supported in this configuration");
14204 raise Unrecoverable_Error;
14206 end Unimplemented_Unit;
14208 ------------------------
14209 -- Universal_Aliasing --
14210 ------------------------
14212 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
14214 when Pragma_Universal_Aliasing => Universal_Alias : declare
14219 Check_Arg_Count (1);
14220 Check_Optional_Identifier (Arg2, Name_Entity);
14221 Check_Arg_Is_Local_Name (Arg1);
14222 E_Id := Entity (Get_Pragma_Arg (Arg1));
14224 if E_Id = Any_Type then
14226 elsif No (E_Id) or else not Is_Type (E_Id) then
14227 Error_Pragma_Arg ("pragma% requires type", Arg1);
14230 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
14231 end Universal_Alias;
14233 --------------------
14234 -- Universal_Data --
14235 --------------------
14237 -- pragma Universal_Data [(library_unit_NAME)];
14239 when Pragma_Universal_Data =>
14242 -- If this is a configuration pragma, then set the universal
14243 -- addressing option, otherwise confirm that the pragma satisfies
14244 -- the requirements of library unit pragma placement and leave it
14245 -- to the GNAAMP back end to detect the pragma (avoids transitive
14246 -- setting of the option due to withed units).
14248 if Is_Configuration_Pragma then
14249 Universal_Addressing_On_AAMP := True;
14251 Check_Valid_Library_Unit_Pragma;
14254 if not AAMP_On_Target then
14255 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
14262 -- pragma Unmodified (local_Name {, local_Name});
14264 when Pragma_Unmodified => Unmodified : declare
14265 Arg_Node : Node_Id;
14266 Arg_Expr : Node_Id;
14267 Arg_Ent : Entity_Id;
14271 Check_At_Least_N_Arguments (1);
14273 -- Loop through arguments
14276 while Present (Arg_Node) loop
14277 Check_No_Identifier (Arg_Node);
14279 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
14280 -- in fact generate reference, so that the entity will have a
14281 -- reference, which will inhibit any warnings about it not
14282 -- being referenced, and also properly show up in the ali file
14283 -- as a reference. But this reference is recorded before the
14284 -- Has_Pragma_Unreferenced flag is set, so that no warning is
14285 -- generated for this reference.
14287 Check_Arg_Is_Local_Name (Arg_Node);
14288 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14290 if Is_Entity_Name (Arg_Expr) then
14291 Arg_Ent := Entity (Arg_Expr);
14293 if not Is_Assignable (Arg_Ent) then
14295 ("pragma% can only be applied to a variable",
14298 Set_Has_Pragma_Unmodified (Arg_Ent);
14310 -- pragma Unreferenced (local_Name {, local_Name});
14312 -- or when used in a context clause:
14314 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
14316 when Pragma_Unreferenced => Unreferenced : declare
14317 Arg_Node : Node_Id;
14318 Arg_Expr : Node_Id;
14319 Arg_Ent : Entity_Id;
14324 Check_At_Least_N_Arguments (1);
14326 -- Check case of appearing within context clause
14328 if Is_In_Context_Clause then
14330 -- The arguments must all be units mentioned in a with clause
14331 -- in the same context clause. Note we already checked (in
14332 -- Par.Prag) that the arguments are either identifiers or
14333 -- selected components.
14336 while Present (Arg_Node) loop
14337 Citem := First (List_Containing (N));
14338 while Citem /= N loop
14339 if Nkind (Citem) = N_With_Clause
14341 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
14343 Set_Has_Pragma_Unreferenced
14346 (Library_Unit (Citem))));
14348 (Get_Pragma_Arg (Arg_Node), Name (Citem));
14357 ("argument of pragma% is not withed unit", Arg_Node);
14363 -- Case of not in list of context items
14367 while Present (Arg_Node) loop
14368 Check_No_Identifier (Arg_Node);
14370 -- Note: the analyze call done by Check_Arg_Is_Local_Name
14371 -- will in fact generate reference, so that the entity will
14372 -- have a reference, which will inhibit any warnings about
14373 -- it not being referenced, and also properly show up in the
14374 -- ali file as a reference. But this reference is recorded
14375 -- before the Has_Pragma_Unreferenced flag is set, so that
14376 -- no warning is generated for this reference.
14378 Check_Arg_Is_Local_Name (Arg_Node);
14379 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14381 if Is_Entity_Name (Arg_Expr) then
14382 Arg_Ent := Entity (Arg_Expr);
14384 -- If the entity is overloaded, the pragma applies to the
14385 -- most recent overloading, as documented. In this case,
14386 -- name resolution does not generate a reference, so it
14387 -- must be done here explicitly.
14389 if Is_Overloaded (Arg_Expr) then
14390 Generate_Reference (Arg_Ent, N);
14393 Set_Has_Pragma_Unreferenced (Arg_Ent);
14401 --------------------------
14402 -- Unreferenced_Objects --
14403 --------------------------
14405 -- pragma Unreferenced_Objects (local_Name {, local_Name});
14407 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
14408 Arg_Node : Node_Id;
14409 Arg_Expr : Node_Id;
14413 Check_At_Least_N_Arguments (1);
14416 while Present (Arg_Node) loop
14417 Check_No_Identifier (Arg_Node);
14418 Check_Arg_Is_Local_Name (Arg_Node);
14419 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14421 if not Is_Entity_Name (Arg_Expr)
14422 or else not Is_Type (Entity (Arg_Expr))
14425 ("argument for pragma% must be type or subtype", Arg_Node);
14428 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
14431 end Unreferenced_Objects;
14433 ------------------------------
14434 -- Unreserve_All_Interrupts --
14435 ------------------------------
14437 -- pragma Unreserve_All_Interrupts;
14439 when Pragma_Unreserve_All_Interrupts =>
14441 Check_Arg_Count (0);
14443 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
14444 Unreserve_All_Interrupts := True;
14451 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
14453 when Pragma_Unsuppress =>
14455 Process_Suppress_Unsuppress (False);
14457 -------------------
14458 -- Use_VADS_Size --
14459 -------------------
14461 -- pragma Use_VADS_Size;
14463 when Pragma_Use_VADS_Size =>
14465 Check_Arg_Count (0);
14466 Check_Valid_Configuration_Pragma;
14467 Use_VADS_Size := True;
14469 ---------------------
14470 -- Validity_Checks --
14471 ---------------------
14473 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14475 when Pragma_Validity_Checks => Validity_Checks : declare
14476 A : constant Node_Id := Get_Pragma_Arg (Arg1);
14482 Check_Arg_Count (1);
14483 Check_No_Identifiers;
14485 if Nkind (A) = N_String_Literal then
14489 Slen : constant Natural := Natural (String_Length (S));
14490 Options : String (1 .. Slen);
14496 C := Get_String_Char (S, Int (J));
14497 exit when not In_Character_Range (C);
14498 Options (J) := Get_Character (C);
14501 Set_Validity_Check_Options (Options);
14509 elsif Nkind (A) = N_Identifier then
14510 if Chars (A) = Name_All_Checks then
14511 Set_Validity_Check_Options ("a");
14512 elsif Chars (A) = Name_On then
14513 Validity_Checks_On := True;
14514 elsif Chars (A) = Name_Off then
14515 Validity_Checks_On := False;
14518 end Validity_Checks;
14524 -- pragma Volatile (LOCAL_NAME);
14526 when Pragma_Volatile =>
14527 Process_Atomic_Shared_Volatile;
14529 -------------------------
14530 -- Volatile_Components --
14531 -------------------------
14533 -- pragma Volatile_Components (array_LOCAL_NAME);
14535 -- Volatile is handled by the same circuit as Atomic_Components
14541 -- pragma Warnings (On | Off);
14542 -- pragma Warnings (On | Off, LOCAL_NAME);
14543 -- pragma Warnings (static_string_EXPRESSION);
14544 -- pragma Warnings (On | Off, STRING_LITERAL);
14546 when Pragma_Warnings => Warnings : begin
14548 Check_At_Least_N_Arguments (1);
14549 Check_No_Identifiers;
14551 -- If debug flag -gnatd.i is set, pragma is ignored
14553 if Debug_Flag_Dot_I then
14557 -- Process various forms of the pragma
14560 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14563 -- One argument case
14565 if Arg_Count = 1 then
14567 -- On/Off one argument case was processed by parser
14569 if Nkind (Argx) = N_Identifier
14571 (Chars (Argx) = Name_On
14573 Chars (Argx) = Name_Off)
14577 -- One argument case must be ON/OFF or static string expr
14579 elsif not Is_Static_String_Expression (Arg1) then
14581 ("argument of pragma% must be On/Off or " &
14582 "static string expression", Arg1);
14584 -- One argument string expression case
14588 Lit : constant Node_Id := Expr_Value_S (Argx);
14589 Str : constant String_Id := Strval (Lit);
14590 Len : constant Nat := String_Length (Str);
14598 while J <= Len loop
14599 C := Get_String_Char (Str, J);
14600 OK := In_Character_Range (C);
14603 Chr := Get_Character (C);
14607 if J < Len and then Chr = '.' then
14609 C := Get_String_Char (Str, J);
14610 Chr := Get_Character (C);
14612 if not Set_Dot_Warning_Switch (Chr) then
14614 ("invalid warning switch character " &
14621 OK := Set_Warning_Switch (Chr);
14627 ("invalid warning switch character " & Chr,
14636 -- Two or more arguments (must be two)
14639 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14640 Check_At_Most_N_Arguments (2);
14648 E_Id := Get_Pragma_Arg (Arg2);
14651 -- In the expansion of an inlined body, a reference to
14652 -- the formal may be wrapped in a conversion if the
14653 -- actual is a conversion. Retrieve the real entity name.
14655 if (In_Instance_Body or In_Inlined_Body)
14656 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14658 E_Id := Expression (E_Id);
14661 -- Entity name case
14663 if Is_Entity_Name (E_Id) then
14664 E := Entity (E_Id);
14671 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14674 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14675 and then Warn_On_Warnings_Off
14677 Warnings_Off_Pragmas.Append ((N, E));
14680 if Is_Enumeration_Type (E) then
14684 Lit := First_Literal (E);
14685 while Present (Lit) loop
14686 Set_Warnings_Off (Lit);
14687 Next_Literal (Lit);
14692 exit when No (Homonym (E));
14697 -- Error if not entity or static string literal case
14699 elsif not Is_Static_String_Expression (Arg2) then
14701 ("second argument of pragma% must be entity " &
14702 "name or static string expression", Arg2);
14704 -- String literal case
14707 String_To_Name_Buffer
14708 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14710 -- Note on configuration pragma case: If this is a
14711 -- configuration pragma, then for an OFF pragma, we
14712 -- just set Config True in the call, which is all
14713 -- that needs to be done. For the case of ON, this
14714 -- is normally an error, unless it is canceling the
14715 -- effect of a previous OFF pragma in the same file.
14716 -- In any other case, an error will be signalled (ON
14717 -- with no matching OFF).
14719 -- Note: We set Used if we are inside a generic to
14720 -- disable the test that the non-config case actually
14721 -- cancels a warning. That's because we can't be sure
14722 -- there isn't an instantiation in some other unit
14723 -- where a warning is suppressed.
14725 -- We could do a little better here by checking if the
14726 -- generic unit we are inside is public, but for now
14727 -- we don't bother with that refinement.
14729 if Chars (Argx) = Name_Off then
14730 Set_Specific_Warning_Off
14731 (Loc, Name_Buffer (1 .. Name_Len),
14732 Config => Is_Configuration_Pragma,
14733 Used => Inside_A_Generic or else In_Instance);
14735 elsif Chars (Argx) = Name_On then
14736 Set_Specific_Warning_On
14737 (Loc, Name_Buffer (1 .. Name_Len), Err);
14741 ("?pragma Warnings On with no " &
14742 "matching Warnings Off",
14752 -------------------
14753 -- Weak_External --
14754 -------------------
14756 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
14758 when Pragma_Weak_External => Weak_External : declare
14763 Check_Arg_Count (1);
14764 Check_Optional_Identifier (Arg1, Name_Entity);
14765 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14766 Ent := Entity (Get_Pragma_Arg (Arg1));
14768 if Rep_Item_Too_Early (Ent, N) then
14771 Ent := Underlying_Type (Ent);
14774 -- The only processing required is to link this item on to the
14775 -- list of rep items for the given entity. This is accomplished
14776 -- by the call to Rep_Item_Too_Late (when no error is detected
14777 -- and False is returned).
14779 if Rep_Item_Too_Late (Ent, N) then
14782 Set_Has_Gigi_Rep_Item (Ent);
14786 -----------------------------
14787 -- Wide_Character_Encoding --
14788 -----------------------------
14790 -- pragma Wide_Character_Encoding (IDENTIFIER);
14792 when Pragma_Wide_Character_Encoding =>
14795 -- Nothing to do, handled in parser. Note that we do not enforce
14796 -- configuration pragma placement, this pragma can appear at any
14797 -- place in the source, allowing mixed encodings within a single
14802 --------------------
14803 -- Unknown_Pragma --
14804 --------------------
14806 -- Should be impossible, since the case of an unknown pragma is
14807 -- separately processed before the case statement is entered.
14809 when Unknown_Pragma =>
14810 raise Program_Error;
14813 -- AI05-0144: detect dangerous order dependence. Disabled for now,
14814 -- until AI is formally approved.
14816 -- Check_Order_Dependence;
14819 when Pragma_Exit => null;
14820 end Analyze_Pragma;
14822 -----------------------------
14823 -- Analyze_TC_In_Decl_Part --
14824 -----------------------------
14826 procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14828 -- Install formals and push subprogram spec onto scope stack so that we
14829 -- can see the formals from the pragma.
14831 Install_Formals (S);
14834 -- Preanalyze the boolean expressions, we treat these as spec
14835 -- expressions (i.e. similar to a default expression).
14837 Preanalyze_TC_Args (N,
14838 Get_Requires_From_Test_Case_Pragma (N),
14839 Get_Ensures_From_Test_Case_Pragma (N));
14841 -- Remove the subprogram from the scope stack now that the pre-analysis
14842 -- of the expressions in the test-case is done.
14845 end Analyze_TC_In_Decl_Part;
14847 --------------------
14848 -- Check_Disabled --
14849 --------------------
14851 function Check_Disabled (Nam : Name_Id) return Boolean is
14855 -- Loop through entries in check policy list
14857 PP := Opt.Check_Policy_List;
14859 -- If there are no specific entries that matched, then nothing is
14860 -- disabled, so return False.
14865 -- Here we have an entry see if it matches
14869 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14871 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14872 return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14874 PP := Next_Pragma (PP);
14879 end Check_Disabled;
14881 -------------------
14882 -- Check_Enabled --
14883 -------------------
14885 function Check_Enabled (Nam : Name_Id) return Boolean is
14889 -- Loop through entries in check policy list
14891 PP := Opt.Check_Policy_List;
14893 -- If there are no specific entries that matched, then we let the
14894 -- setting of assertions govern. Note that this provides the needed
14895 -- compatibility with the RM for the cases of assertion, invariant,
14896 -- precondition, predicate, and postcondition.
14899 return Assertions_Enabled;
14901 -- Here we have an entry see if it matches
14905 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14908 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14909 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14910 when Name_On | Name_Check =>
14912 when Name_Off | Name_Ignore =>
14915 raise Program_Error;
14919 PP := Next_Pragma (PP);
14926 ---------------------------------
14927 -- Delay_Config_Pragma_Analyze --
14928 ---------------------------------
14930 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14932 return Pragma_Name (N) = Name_Interrupt_State
14934 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14935 end Delay_Config_Pragma_Analyze;
14937 -------------------------
14938 -- Get_Base_Subprogram --
14939 -------------------------
14941 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14942 Result : Entity_Id;
14945 -- Follow subprogram renaming chain
14949 if Is_Subprogram (Result)
14951 Nkind (Parent (Declaration_Node (Result))) =
14952 N_Subprogram_Renaming_Declaration
14953 and then Present (Alias (Result))
14955 Result := Alias (Result);
14959 end Get_Base_Subprogram;
14965 procedure Initialize is
14970 -----------------------------
14971 -- Is_Config_Static_String --
14972 -----------------------------
14974 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14976 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14977 -- This is an internal recursive function that is just like the outer
14978 -- function except that it adds the string to the name buffer rather
14979 -- than placing the string in the name buffer.
14981 ------------------------------
14982 -- Add_Config_Static_String --
14983 ------------------------------
14985 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14992 if Nkind (N) = N_Op_Concat then
14993 if Add_Config_Static_String (Left_Opnd (N)) then
14994 N := Right_Opnd (N);
15000 if Nkind (N) /= N_String_Literal then
15001 Error_Msg_N ("string literal expected for pragma argument", N);
15005 for J in 1 .. String_Length (Strval (N)) loop
15006 C := Get_String_Char (Strval (N), J);
15008 if not In_Character_Range (C) then
15010 ("string literal contains invalid wide character",
15011 Sloc (N) + 1 + Source_Ptr (J));
15015 Add_Char_To_Name_Buffer (Get_Character (C));
15020 end Add_Config_Static_String;
15022 -- Start of processing for Is_Config_Static_String
15027 return Add_Config_Static_String (Arg);
15028 end Is_Config_Static_String;
15030 -----------------------------------------
15031 -- Is_Non_Significant_Pragma_Reference --
15032 -----------------------------------------
15034 -- This function makes use of the following static table which indicates
15035 -- whether appearance of some name in a given pragma is to be considered
15036 -- as a reference for the purposes of warnings about unreferenced objects.
15038 -- -1 indicates that references in any argument position are significant
15039 -- 0 indicates that appearance in any argument is not significant
15040 -- +n indicates that appearance as argument n is significant, but all
15041 -- other arguments are not significant
15042 -- 99 special processing required (e.g. for pragma Check)
15044 Sig_Flags : constant array (Pragma_Id) of Int :=
15045 (Pragma_AST_Entry => -1,
15046 Pragma_Abort_Defer => -1,
15047 Pragma_Ada_83 => -1,
15048 Pragma_Ada_95 => -1,
15049 Pragma_Ada_05 => -1,
15050 Pragma_Ada_2005 => -1,
15051 Pragma_Ada_12 => -1,
15052 Pragma_Ada_2012 => -1,
15053 Pragma_All_Calls_Remote => -1,
15054 Pragma_Annotate => -1,
15055 Pragma_Assert => -1,
15056 Pragma_Assertion_Policy => 0,
15057 Pragma_Assume_No_Invalid_Values => 0,
15058 Pragma_Asynchronous => -1,
15059 Pragma_Atomic => 0,
15060 Pragma_Atomic_Components => 0,
15061 Pragma_Attach_Handler => -1,
15062 Pragma_Check => 99,
15063 Pragma_Check_Name => 0,
15064 Pragma_Check_Policy => 0,
15065 Pragma_CIL_Constructor => -1,
15066 Pragma_CPP_Class => 0,
15067 Pragma_CPP_Constructor => 0,
15068 Pragma_CPP_Virtual => 0,
15069 Pragma_CPP_Vtable => 0,
15071 Pragma_C_Pass_By_Copy => 0,
15072 Pragma_Comment => 0,
15073 Pragma_Common_Object => -1,
15074 Pragma_Compile_Time_Error => -1,
15075 Pragma_Compile_Time_Warning => -1,
15076 Pragma_Compiler_Unit => 0,
15077 Pragma_Complete_Representation => 0,
15078 Pragma_Complex_Representation => 0,
15079 Pragma_Component_Alignment => -1,
15080 Pragma_Controlled => 0,
15081 Pragma_Convention => 0,
15082 Pragma_Convention_Identifier => 0,
15083 Pragma_Debug => -1,
15084 Pragma_Debug_Policy => 0,
15085 Pragma_Detect_Blocking => -1,
15086 Pragma_Default_Storage_Pool => -1,
15087 Pragma_Disable_Atomic_Synchronization => -1,
15088 Pragma_Discard_Names => 0,
15089 Pragma_Dispatching_Domain => -1,
15090 Pragma_Elaborate => -1,
15091 Pragma_Elaborate_All => -1,
15092 Pragma_Elaborate_Body => -1,
15093 Pragma_Elaboration_Checks => -1,
15094 Pragma_Eliminate => -1,
15095 Pragma_Enable_Atomic_Synchronization => -1,
15096 Pragma_Export => -1,
15097 Pragma_Export_Exception => -1,
15098 Pragma_Export_Function => -1,
15099 Pragma_Export_Object => -1,
15100 Pragma_Export_Procedure => -1,
15101 Pragma_Export_Value => -1,
15102 Pragma_Export_Valued_Procedure => -1,
15103 Pragma_Extend_System => -1,
15104 Pragma_Extensions_Allowed => -1,
15105 Pragma_External => -1,
15106 Pragma_Favor_Top_Level => -1,
15107 Pragma_External_Name_Casing => -1,
15108 Pragma_Fast_Math => -1,
15109 Pragma_Finalize_Storage_Only => 0,
15110 Pragma_Float_Representation => 0,
15111 Pragma_Ident => -1,
15112 Pragma_Implementation_Defined => -1,
15113 Pragma_Implemented => -1,
15114 Pragma_Implicit_Packing => 0,
15115 Pragma_Import => +2,
15116 Pragma_Import_Exception => 0,
15117 Pragma_Import_Function => 0,
15118 Pragma_Import_Object => 0,
15119 Pragma_Import_Procedure => 0,
15120 Pragma_Import_Valued_Procedure => 0,
15121 Pragma_Independent => 0,
15122 Pragma_Independent_Components => 0,
15123 Pragma_Initialize_Scalars => -1,
15124 Pragma_Inline => 0,
15125 Pragma_Inline_Always => 0,
15126 Pragma_Inline_Generic => 0,
15127 Pragma_Inspection_Point => -1,
15128 Pragma_Interface => +2,
15129 Pragma_Interface_Name => +2,
15130 Pragma_Interrupt_Handler => -1,
15131 Pragma_Interrupt_Priority => -1,
15132 Pragma_Interrupt_State => -1,
15133 Pragma_Invariant => -1,
15134 Pragma_Java_Constructor => -1,
15135 Pragma_Java_Interface => -1,
15136 Pragma_Keep_Names => 0,
15137 Pragma_License => -1,
15138 Pragma_Link_With => -1,
15139 Pragma_Linker_Alias => -1,
15140 Pragma_Linker_Constructor => -1,
15141 Pragma_Linker_Destructor => -1,
15142 Pragma_Linker_Options => -1,
15143 Pragma_Linker_Section => -1,
15145 Pragma_Locking_Policy => -1,
15146 Pragma_Long_Float => -1,
15147 Pragma_Machine_Attribute => -1,
15149 Pragma_Main_Storage => -1,
15150 Pragma_Memory_Size => -1,
15151 Pragma_No_Return => 0,
15152 Pragma_No_Body => 0,
15153 Pragma_No_Run_Time => -1,
15154 Pragma_No_Strict_Aliasing => -1,
15155 Pragma_Normalize_Scalars => -1,
15156 Pragma_Obsolescent => 0,
15157 Pragma_Optimize => -1,
15158 Pragma_Optimize_Alignment => -1,
15159 Pragma_Ordered => 0,
15162 Pragma_Passive => -1,
15163 Pragma_Preelaborable_Initialization => -1,
15164 Pragma_Polling => -1,
15165 Pragma_Persistent_BSS => 0,
15166 Pragma_Postcondition => -1,
15167 Pragma_Precondition => -1,
15168 Pragma_Predicate => -1,
15169 Pragma_Preelaborate => -1,
15170 Pragma_Preelaborate_05 => -1,
15171 Pragma_Priority => -1,
15172 Pragma_Priority_Specific_Dispatching => -1,
15173 Pragma_Profile => 0,
15174 Pragma_Profile_Warnings => 0,
15175 Pragma_Propagate_Exceptions => -1,
15176 Pragma_Psect_Object => -1,
15178 Pragma_Pure_05 => -1,
15179 Pragma_Pure_12 => -1,
15180 Pragma_Pure_Function => -1,
15181 Pragma_Queuing_Policy => -1,
15182 Pragma_Ravenscar => -1,
15183 Pragma_Relative_Deadline => -1,
15184 Pragma_Remote_Access_Type => -1,
15185 Pragma_Remote_Call_Interface => -1,
15186 Pragma_Remote_Types => -1,
15187 Pragma_Restricted_Run_Time => -1,
15188 Pragma_Restriction_Warnings => -1,
15189 Pragma_Restrictions => -1,
15190 Pragma_Reviewable => -1,
15191 Pragma_Short_Circuit_And_Or => -1,
15192 Pragma_Share_Generic => -1,
15193 Pragma_Shared => -1,
15194 Pragma_Shared_Passive => -1,
15195 Pragma_Short_Descriptors => 0,
15196 Pragma_Simple_Storage_Pool_Type => 0,
15197 Pragma_Source_File_Name => -1,
15198 Pragma_Source_File_Name_Project => -1,
15199 Pragma_Source_Reference => -1,
15200 Pragma_Storage_Size => -1,
15201 Pragma_Storage_Unit => -1,
15202 Pragma_Static_Elaboration_Desired => -1,
15203 Pragma_Stream_Convert => -1,
15204 Pragma_Style_Checks => -1,
15205 Pragma_Subtitle => -1,
15206 Pragma_Suppress => 0,
15207 Pragma_Suppress_Exception_Locations => 0,
15208 Pragma_Suppress_All => -1,
15209 Pragma_Suppress_Debug_Info => 0,
15210 Pragma_Suppress_Initialization => 0,
15211 Pragma_System_Name => -1,
15212 Pragma_Task_Dispatching_Policy => -1,
15213 Pragma_Task_Info => -1,
15214 Pragma_Task_Name => -1,
15215 Pragma_Task_Storage => 0,
15216 Pragma_Test_Case => -1,
15217 Pragma_Thread_Local_Storage => 0,
15218 Pragma_Time_Slice => -1,
15219 Pragma_Title => -1,
15220 Pragma_Unchecked_Union => 0,
15221 Pragma_Unimplemented_Unit => -1,
15222 Pragma_Universal_Aliasing => -1,
15223 Pragma_Universal_Data => -1,
15224 Pragma_Unmodified => -1,
15225 Pragma_Unreferenced => -1,
15226 Pragma_Unreferenced_Objects => -1,
15227 Pragma_Unreserve_All_Interrupts => -1,
15228 Pragma_Unsuppress => 0,
15229 Pragma_Use_VADS_Size => -1,
15230 Pragma_Validity_Checks => -1,
15231 Pragma_Volatile => 0,
15232 Pragma_Volatile_Components => 0,
15233 Pragma_Warnings => -1,
15234 Pragma_Weak_External => -1,
15235 Pragma_Wide_Character_Encoding => 0,
15236 Unknown_Pragma => 0);
15238 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
15247 if Nkind (P) /= N_Pragma_Argument_Association then
15251 Id := Get_Pragma_Id (Parent (P));
15252 C := Sig_Flags (Id);
15264 -- For pragma Check, the first argument is not significant,
15265 -- the second and the third (if present) arguments are
15268 when Pragma_Check =>
15270 P = First (Pragma_Argument_Associations (Parent (P)));
15273 raise Program_Error;
15277 A := First (Pragma_Argument_Associations (Parent (P)));
15278 for J in 1 .. C - 1 loop
15286 return A = P; -- is this wrong way round ???
15289 end Is_Non_Significant_Pragma_Reference;
15291 ------------------------------
15292 -- Is_Pragma_String_Literal --
15293 ------------------------------
15295 -- This function returns true if the corresponding pragma argument is a
15296 -- static string expression. These are the only cases in which string
15297 -- literals can appear as pragma arguments. We also allow a string literal
15298 -- as the first argument to pragma Assert (although it will of course
15299 -- always generate a type error).
15301 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
15302 Pragn : constant Node_Id := Parent (Par);
15303 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
15304 Pname : constant Name_Id := Pragma_Name (Pragn);
15310 N := First (Assoc);
15317 if Pname = Name_Assert then
15320 elsif Pname = Name_Export then
15323 elsif Pname = Name_Ident then
15326 elsif Pname = Name_Import then
15329 elsif Pname = Name_Interface_Name then
15332 elsif Pname = Name_Linker_Alias then
15335 elsif Pname = Name_Linker_Section then
15338 elsif Pname = Name_Machine_Attribute then
15341 elsif Pname = Name_Source_File_Name then
15344 elsif Pname = Name_Source_Reference then
15347 elsif Pname = Name_Title then
15350 elsif Pname = Name_Subtitle then
15356 end Is_Pragma_String_Literal;
15358 -----------------------------------------
15359 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
15360 -----------------------------------------
15362 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
15363 Aspects : constant List_Id := New_List;
15364 Loc : constant Source_Ptr := Sloc (Decl);
15365 Or_Decl : constant Node_Id := Original_Node (Decl);
15367 Original_Aspects : List_Id;
15368 -- To capture global references, a copy of the created aspects must be
15369 -- inserted in the original tree.
15372 Prag_Arg_Ass : Node_Id;
15373 Prag_Id : Pragma_Id;
15376 -- Check for any PPC pragmas that appear within Decl
15378 Prag := Next (Decl);
15379 while Nkind (Prag) = N_Pragma loop
15380 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
15383 when Pragma_Postcondition | Pragma_Precondition =>
15384 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
15386 -- Make an aspect from any PPC pragma
15388 Append_To (Aspects,
15389 Make_Aspect_Specification (Loc,
15391 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
15393 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
15395 -- Generate the analysis information in the pragma expression
15396 -- and then set the pragma node analyzed to avoid any further
15399 Analyze (Expression (Prag_Arg_Ass));
15400 Set_Analyzed (Prag, True);
15402 when others => null;
15408 -- Set all new aspects into the generic declaration node
15410 if Is_Non_Empty_List (Aspects) then
15412 -- Create the list of aspects to be inserted in the original tree
15414 Original_Aspects := Copy_Separate_List (Aspects);
15416 -- Check if Decl already has aspects
15418 -- Attach the new lists of aspects to both the generic copy and the
15421 if Has_Aspects (Decl) then
15422 Append_List (Aspects, Aspect_Specifications (Decl));
15423 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
15426 Set_Parent (Aspects, Decl);
15427 Set_Aspect_Specifications (Decl, Aspects);
15428 Set_Parent (Original_Aspects, Or_Decl);
15429 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
15432 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
15434 ------------------------
15435 -- Preanalyze_TC_Args --
15436 ------------------------
15438 procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
15440 -- Preanalyze the boolean expressions, we treat these as spec
15441 -- expressions (i.e. similar to a default expression).
15443 if Present (Arg_Req) then
15444 Preanalyze_Spec_Expression
15445 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
15447 -- In ASIS mode, for a pragma generated from a source aspect, also
15448 -- analyze the original aspect expression.
15450 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
15451 Preanalyze_Spec_Expression
15452 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
15456 if Present (Arg_Ens) then
15457 Preanalyze_Spec_Expression
15458 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
15460 -- In ASIS mode, for a pragma generated from a source aspect, also
15461 -- analyze the original aspect expression.
15463 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
15464 Preanalyze_Spec_Expression
15465 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
15468 end Preanalyze_TC_Args;
15470 --------------------------------------
15471 -- Process_Compilation_Unit_Pragmas --
15472 --------------------------------------
15474 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
15476 -- A special check for pragma Suppress_All, a very strange DEC pragma,
15477 -- strange because it comes at the end of the unit. Rational has the
15478 -- same name for a pragma, but treats it as a program unit pragma, In
15479 -- GNAT we just decide to allow it anywhere at all. If it appeared then
15480 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
15481 -- node, and we insert a pragma Suppress (All_Checks) at the start of
15482 -- the context clause to ensure the correct processing.
15484 if Has_Pragma_Suppress_All (N) then
15485 Prepend_To (Context_Items (N),
15486 Make_Pragma (Sloc (N),
15487 Chars => Name_Suppress,
15488 Pragma_Argument_Associations => New_List (
15489 Make_Pragma_Argument_Association (Sloc (N),
15490 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
15493 -- Nothing else to do at the current time!
15495 end Process_Compilation_Unit_Pragmas;
15506 --------------------------------
15507 -- Set_Encoded_Interface_Name --
15508 --------------------------------
15510 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
15511 Str : constant String_Id := Strval (S);
15512 Len : constant Int := String_Length (Str);
15517 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
15520 -- Stores encoded value of character code CC. The encoding we use an
15521 -- underscore followed by four lower case hex digits.
15527 procedure Encode is
15529 Store_String_Char (Get_Char_Code ('_'));
15531 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
15533 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
15535 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
15537 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
15540 -- Start of processing for Set_Encoded_Interface_Name
15543 -- If first character is asterisk, this is a link name, and we leave it
15544 -- completely unmodified. We also ignore null strings (the latter case
15545 -- happens only in error cases) and no encoding should occur for Java or
15546 -- AAMP interface names.
15549 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
15550 or else VM_Target /= No_VM
15551 or else AAMP_On_Target
15553 Set_Interface_Name (E, S);
15558 CC := Get_String_Char (Str, J);
15560 exit when not In_Character_Range (CC);
15562 C := Get_Character (CC);
15564 exit when C /= '_' and then C /= '$'
15565 and then C not in '0' .. '9'
15566 and then C not in 'a' .. 'z'
15567 and then C not in 'A' .. 'Z';
15570 Set_Interface_Name (E, S);
15578 -- Here we need to encode. The encoding we use as follows:
15579 -- three underscores + four hex digits (lower case)
15583 for J in 1 .. String_Length (Str) loop
15584 CC := Get_String_Char (Str, J);
15586 if not In_Character_Range (CC) then
15589 C := Get_Character (CC);
15591 if C = '_' or else C = '$'
15592 or else C in '0' .. '9'
15593 or else C in 'a' .. 'z'
15594 or else C in 'A' .. 'Z'
15596 Store_String_Char (CC);
15603 Set_Interface_Name (E,
15604 Make_String_Literal (Sloc (S),
15605 Strval => End_String));
15607 end Set_Encoded_Interface_Name;
15609 -------------------
15610 -- Set_Unit_Name --
15611 -------------------
15613 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15618 if Nkind (N) = N_Identifier
15619 and then Nkind (With_Item) = N_Identifier
15621 Set_Entity (N, Entity (With_Item));
15623 elsif Nkind (N) = N_Selected_Component then
15624 Change_Selected_Component_To_Expanded_Name (N);
15625 Set_Entity (N, Entity (With_Item));
15626 Set_Entity (Selector_Name (N), Entity (N));
15628 Pref := Prefix (N);
15629 Scop := Scope (Entity (N));
15630 while Nkind (Pref) = N_Selected_Component loop
15631 Change_Selected_Component_To_Expanded_Name (Pref);
15632 Set_Entity (Selector_Name (Pref), Scop);
15633 Set_Entity (Pref, Scop);
15634 Pref := Prefix (Pref);
15635 Scop := Scope (Scop);
15638 Set_Entity (Pref, Scop);