1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Aspects; use Aspects;
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Checks; use Checks;
36 with Csets; use Csets;
37 with Debug; use Debug;
38 with Einfo; use Einfo;
39 with Elists; use Elists;
40 with Errout; use Errout;
41 with Exp_Dist; use Exp_Dist;
42 with Exp_Util; use Exp_Util;
43 with Freeze; use Freeze;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet.Sp; use Namet.Sp;
48 with Nlists; use Nlists;
49 with Nmake; use Nmake;
51 with Output; use Output;
52 with Par_SCO; use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident; use Rident;
55 with Rtsfind; use Rtsfind;
57 with Sem_Aux; use Sem_Aux;
58 with Sem_Ch3; use Sem_Ch3;
59 with Sem_Ch6; use Sem_Ch6;
60 with Sem_Ch8; use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res; use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_VFpt; use Sem_VFpt;
73 with Sem_Warn; use Sem_Warn;
74 with Stand; use Stand;
75 with Sinfo; use Sinfo;
76 with Sinfo.CN; use Sinfo.CN;
77 with Sinput; use Sinput;
78 with Snames; use Snames;
79 with Stringt; use Stringt;
80 with Stylesw; use Stylesw;
82 with Targparm; use Targparm;
83 with Tbuild; use Tbuild;
85 with Uintp; use Uintp;
86 with Uname; use Uname;
87 with Urealp; use Urealp;
88 with Validsw; use Validsw;
89 with Warnsw; use Warnsw;
91 package body Sem_Prag is
93 ----------------------------------------------
94 -- Common Handling of Import-Export Pragmas --
95 ----------------------------------------------
97 -- In the following section, a number of Import_xxx and Export_xxx pragmas
98 -- are defined by GNAT. These are compatible with the DEC pragmas of the
99 -- same name, and all have the following common form and processing:
102 -- [Internal =>] LOCAL_NAME
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
107 -- [Internal =>] LOCAL_NAME
108 -- [, [External =>] EXTERNAL_SYMBOL]
109 -- [, other optional parameters ]);
111 -- EXTERNAL_SYMBOL ::=
113 -- | static_string_EXPRESSION
115 -- The internal LOCAL_NAME designates the entity that is imported or
116 -- exported, and must refer to an entity in the current declarative
117 -- part (as required by the rules for LOCAL_NAME).
119 -- The external linker name is designated by the External parameter if
120 -- given, or the Internal parameter if not (if there is no External
121 -- parameter, the External parameter is a copy of the Internal name).
123 -- If the External parameter is given as a string, then this string is
124 -- treated as an external name (exactly as though it had been given as an
125 -- External_Name parameter for a normal Import pragma).
127 -- If the External parameter is given as an identifier (or there is no
128 -- External parameter, so that the Internal identifier is used), then
129 -- the external name is the characters of the identifier, translated
130 -- to all upper case letters for OpenVMS versions of GNAT, and to all
131 -- lower case letters for all other versions
133 -- Note: the external name specified or implied by any of these special
134 -- Import_xxx or Export_xxx pragmas override an external or link name
135 -- specified in a previous Import or Export pragma.
137 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
138 -- named notation, following the standard rules for subprogram calls, i.e.
139 -- parameters can be given in any order if named notation is used, and
140 -- positional and named notation can be mixed, subject to the rule that all
141 -- positional parameters must appear first.
143 -- Note: All these pragmas are implemented exactly following the DEC design
144 -- and implementation and are intended to be fully compatible with the use
145 -- of these pragmas in the DEC Ada compiler.
147 --------------------------------------------
148 -- Checking for Duplicated External Names --
149 --------------------------------------------
151 -- It is suspicious if two separate Export pragmas use the same external
152 -- name. The following table is used to diagnose this situation so that
153 -- an appropriate warning can be issued.
155 -- The Node_Id stored is for the N_String_Literal node created to hold
156 -- the value of the external name. The Sloc of this node is used to
157 -- cross-reference the location of the duplication.
159 package Externals is new Table.Table (
160 Table_Component_Type => Node_Id,
161 Table_Index_Type => Int,
162 Table_Low_Bound => 0,
163 Table_Initial => 100,
164 Table_Increment => 100,
165 Table_Name => "Name_Externals");
167 -------------------------------------
168 -- Local Subprograms and Variables --
169 -------------------------------------
171 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
172 -- This routine is used for possible casing adjustment of an explicit
173 -- external name supplied as a string literal (the node N), according to
174 -- the casing requirement of Opt.External_Name_Casing. If this is set to
175 -- As_Is, then the string literal is returned unchanged, but if it is set
176 -- to Uppercase or Lowercase, then a new string literal with appropriate
177 -- casing is constructed.
179 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
180 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
181 -- original one, following the renaming chain) is returned. Otherwise the
182 -- entity is returned unchanged. Should be in Einfo???
184 procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id);
185 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
186 -- of a Test_Case pragma if present (possibly Empty). We treat these as
187 -- spec expressions (i.e. similar to a default expression).
190 -- This is a dummy function called by the processing for pragma Reviewable.
191 -- It is there for assisting front end debugging. By placing a Reviewable
192 -- pragma in the source program, a breakpoint on rv catches this place in
193 -- the source, allowing convenient stepping to the point of interest.
195 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
196 -- Place semantic information on the argument of an Elaborate/Elaborate_All
197 -- pragma. Entity name for unit and its parents is taken from item in
198 -- previous with_clause that mentions the unit.
200 -------------------------------
201 -- Adjust_External_Name_Case --
202 -------------------------------
204 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
208 -- Adjust case of literal if required
210 if Opt.External_Name_Exp_Casing = As_Is then
214 -- Copy existing string
220 for J in 1 .. String_Length (Strval (N)) loop
221 CC := Get_String_Char (Strval (N), J);
223 if Opt.External_Name_Exp_Casing = Uppercase
224 and then CC >= Get_Char_Code ('a')
225 and then CC <= Get_Char_Code ('z')
227 Store_String_Char (CC - 32);
229 elsif Opt.External_Name_Exp_Casing = Lowercase
230 and then CC >= Get_Char_Code ('A')
231 and then CC <= Get_Char_Code ('Z')
233 Store_String_Char (CC + 32);
236 Store_String_Char (CC);
241 Make_String_Literal (Sloc (N),
242 Strval => End_String);
244 end Adjust_External_Name_Case;
246 ------------------------------
247 -- Analyze_PPC_In_Decl_Part --
248 ------------------------------
250 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
251 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
254 -- Install formals and push subprogram spec onto scope stack so that we
255 -- can see the formals from the pragma.
260 -- Preanalyze the boolean expression, we treat this as a spec expression
261 -- (i.e. similar to a default expression).
263 Preanalyze_Spec_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
265 -- In ASIS mode, for a pragma generated from a source aspect, also
266 -- analyze the original aspect expression.
269 and then Present (Corresponding_Aspect (N))
271 Preanalyze_Spec_Expression
272 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
275 -- For a class-wide condition, a reference to a controlling formal must
276 -- be interpreted as having the class-wide type (or an access to such)
277 -- so that the inherited condition can be properly applied to any
278 -- overriding operation (see ARM12 6.6.1 (7)).
280 if Class_Present (N) then
282 T : constant Entity_Id := Find_Dispatching_Type (S);
284 ACW : Entity_Id := Empty;
285 -- Access to T'class, created if there is a controlling formal
286 -- that is an access parameter.
288 function Get_ACW return Entity_Id;
289 -- If the expression has a reference to an controlling access
290 -- parameter, create an access to T'class for the necessary
291 -- conversions if one does not exist.
293 function Process (N : Node_Id) return Traverse_Result;
294 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
295 -- aspect for a primitive subprogram of a tagged type T, a name
296 -- that denotes a formal parameter of type T is interpreted as
297 -- having type T'Class. Similarly, a name that denotes a formal
298 -- accessparameter of type access-to-T is interpreted as having
299 -- type access-to-T'Class. This ensures the expression is well-
300 -- defined for a primitive subprogram of a type descended from T.
306 function Get_ACW return Entity_Id is
307 Loc : constant Source_Ptr := Sloc (N);
312 Decl := Make_Full_Type_Declaration (Loc,
313 Defining_Identifier => Make_Temporary (Loc, 'T'),
315 Make_Access_To_Object_Definition (Loc,
316 Subtype_Indication =>
317 New_Occurrence_Of (Class_Wide_Type (T), Loc),
318 All_Present => True));
320 Insert_Before (Unit_Declaration_Node (S), Decl);
322 ACW := Defining_Identifier (Decl);
323 Freeze_Before (Unit_Declaration_Node (S), ACW);
333 function Process (N : Node_Id) return Traverse_Result is
334 Loc : constant Source_Ptr := Sloc (N);
338 if Is_Entity_Name (N)
339 and then Is_Formal (Entity (N))
340 and then Nkind (Parent (N)) /= N_Type_Conversion
342 if Etype (Entity (N)) = T then
343 Typ := Class_Wide_Type (T);
345 elsif Is_Access_Type (Etype (Entity (N)))
346 and then Designated_Type (Etype (Entity (N))) = T
353 if Present (Typ) then
355 Make_Type_Conversion (Loc,
357 New_Occurrence_Of (Typ, Loc),
358 Expression => New_Occurrence_Of (Entity (N), Loc)));
366 procedure Replace_Type is new Traverse_Proc (Process);
369 Replace_Type (Get_Pragma_Arg (Arg1));
373 -- Remove the subprogram from the scope stack now that the pre-analysis
374 -- of the precondition/postcondition is done.
377 end Analyze_PPC_In_Decl_Part;
383 procedure Analyze_Pragma (N : Node_Id) is
384 Loc : constant Source_Ptr := Sloc (N);
388 -- Name of the source pragma, or name of the corresponding aspect for
389 -- pragmas which originate in a source aspect. In the latter case, the
390 -- name may be different from the pragma name.
392 Pragma_Exit : exception;
393 -- This exception is used to exit pragma processing completely. It is
394 -- used when an error is detected, and no further processing is
395 -- required. It is also used if an earlier error has left the tree in
396 -- a state where the pragma should not be processed.
399 -- Number of pragma argument associations
405 -- First four pragma arguments (pragma argument association nodes, or
406 -- Empty if the corresponding argument does not exist).
408 type Name_List is array (Natural range <>) of Name_Id;
409 type Args_List is array (Natural range <>) of Node_Id;
410 -- Types used for arguments to Check_Arg_Order and Gather_Associations
412 procedure Ada_2005_Pragma;
413 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
414 -- Ada 95 mode, these are implementation defined pragmas, so should be
415 -- caught by the No_Implementation_Pragmas restriction.
417 procedure Ada_2012_Pragma;
418 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
419 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
420 -- should be caught by the No_Implementation_Pragmas restriction.
422 procedure Check_Ada_83_Warning;
423 -- Issues a warning message for the current pragma if operating in Ada
424 -- 83 mode (used for language pragmas that are not a standard part of
425 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
428 procedure Check_Arg_Count (Required : Nat);
429 -- Check argument count for pragma is equal to given parameter. If not,
430 -- then issue an error message and raise Pragma_Exit.
432 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
433 -- Arg which can either be a pragma argument association, in which case
434 -- the check is applied to the expression of the association or an
435 -- expression directly.
437 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
438 -- Check that an argument has the right form for an EXTERNAL_NAME
439 -- parameter of an extended import/export pragma. The rule is that the
440 -- name must be an identifier or string literal (in Ada 83 mode) or a
441 -- static string expression (in Ada 95 mode).
443 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
444 -- Check the specified argument Arg to make sure that it is an
445 -- identifier. If not give error and raise Pragma_Exit.
447 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
448 -- Check the specified argument Arg to make sure that it is an integer
449 -- literal. If not give error and raise Pragma_Exit.
451 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
452 -- Check the specified argument Arg to make sure that it has the proper
453 -- syntactic form for a local name and meets the semantic requirements
454 -- for a local name. The local name is analyzed as part of the
455 -- processing for this call. In addition, the local name is required
456 -- to represent an entity at the library level.
458 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
459 -- Check the specified argument Arg to make sure that it has the proper
460 -- syntactic form for a local name and meets the semantic requirements
461 -- for a local name. The local name is analyzed as part of the
462 -- processing for this call.
464 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
465 -- Check the specified argument Arg to make sure that it is a valid
466 -- locking policy name. If not give error and raise Pragma_Exit.
468 procedure Check_Arg_Is_One_Of
471 procedure Check_Arg_Is_One_Of
473 N1, N2, N3 : Name_Id);
474 procedure Check_Arg_Is_One_Of
476 N1, N2, N3, N4 : Name_Id);
477 procedure Check_Arg_Is_One_Of
479 N1, N2, N3, N4, N5 : Name_Id);
480 -- Check the specified argument Arg to make sure that it is an
481 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
482 -- present). If not then give error and raise Pragma_Exit.
484 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
485 -- Check the specified argument Arg to make sure that it is a valid
486 -- queuing policy name. If not give error and raise Pragma_Exit.
488 procedure Check_Arg_Is_Static_Expression
490 Typ : Entity_Id := Empty);
491 -- Check the specified argument Arg to make sure that it is a static
492 -- expression of the given type (i.e. it will be analyzed and resolved
493 -- using this type, which can be any valid argument to Resolve, e.g.
494 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
495 -- Typ is left Empty, then any static expression is allowed.
497 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
498 -- Check the specified argument Arg to make sure that it is a valid task
499 -- dispatching policy name. If not give error and raise Pragma_Exit.
501 procedure Check_Arg_Order (Names : Name_List);
502 -- Checks for an instance of two arguments with identifiers for the
503 -- current pragma which are not in the sequence indicated by Names,
504 -- and if so, generates a fatal message about bad order of arguments.
506 procedure Check_At_Least_N_Arguments (N : Nat);
507 -- Check there are at least N arguments present
509 procedure Check_At_Most_N_Arguments (N : Nat);
510 -- Check there are no more than N arguments present
512 procedure Check_Component
515 In_Variant_Part : Boolean := False);
516 -- Examine an Unchecked_Union component for correct use of per-object
517 -- constrained subtypes, and for restrictions on finalizable components.
518 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
519 -- should be set when Comp comes from a record variant.
521 procedure Check_Duplicate_Pragma (E : Entity_Id);
522 -- Check if a pragma of the same name as the current pragma is already
523 -- chained as a rep pragma to the given entity. If so give a message
524 -- about the duplicate, and then raise Pragma_Exit so does not return.
525 -- Also checks for delayed aspect specification node in the chain.
527 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
528 -- Nam is an N_String_Literal node containing the external name set by
529 -- an Import or Export pragma (or extended Import or Export pragma).
530 -- This procedure checks for possible duplications if this is the export
531 -- case, and if found, issues an appropriate error message.
533 procedure Check_Expr_Is_Static_Expression
535 Typ : Entity_Id := Empty);
536 -- Check the specified expression Expr to make sure that it is a static
537 -- expression of the given type (i.e. it will be analyzed and resolved
538 -- using this type, which can be any valid argument to Resolve, e.g.
539 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
540 -- Typ is left Empty, then any static expression is allowed.
542 procedure Check_First_Subtype (Arg : Node_Id);
543 -- Checks that Arg, whose expression is an entity name, references a
546 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
547 -- Checks that the given argument has an identifier, and if so, requires
548 -- it to match the given identifier name. If there is no identifier, or
549 -- a non-matching identifier, then an error message is given and
550 -- Pragma_Exit is raised.
552 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
553 -- Checks that the given argument has an identifier, and if so, requires
554 -- it to match one of the given identifier names. If there is no
555 -- identifier, or a non-matching identifier, then an error message is
556 -- given and Pragma_Exit is raised.
558 procedure Check_In_Main_Program;
559 -- Common checks for pragmas that appear within a main program
560 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
562 procedure Check_Interrupt_Or_Attach_Handler;
563 -- Common processing for first argument of pragma Interrupt_Handler or
564 -- pragma Attach_Handler.
566 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
567 -- Check that pragma appears in a declarative part, or in a package
568 -- specification, i.e. that it does not occur in a statement sequence
571 procedure Check_No_Identifier (Arg : Node_Id);
572 -- Checks that the given argument does not have an identifier. If
573 -- an identifier is present, then an error message is issued, and
574 -- Pragma_Exit is raised.
576 procedure Check_No_Identifiers;
577 -- Checks that none of the arguments to the pragma has an identifier.
578 -- If any argument has an identifier, then an error message is issued,
579 -- and Pragma_Exit is raised.
581 procedure Check_No_Link_Name;
582 -- Checks that no link name is specified
584 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
585 -- Checks if the given argument has an identifier, and if so, requires
586 -- it to match the given identifier name. If there is a non-matching
587 -- identifier, then an error message is given and Pragma_Exit is raised.
589 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
590 -- Checks if the given argument has an identifier, and if so, requires
591 -- it to match the given identifier name. If there is a non-matching
592 -- identifier, then an error message is given and Pragma_Exit is raised.
593 -- In this version of the procedure, the identifier name is given as
594 -- a string with lower case letters.
596 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
597 -- Called to process a precondition or postcondition pragma. There are
600 -- The pragma appears after a subprogram spec
602 -- If the corresponding check is not enabled, the pragma is analyzed
603 -- but otherwise ignored and control returns with In_Body set False.
605 -- If the check is enabled, then the first step is to analyze the
606 -- pragma, but this is skipped if the subprogram spec appears within
607 -- a package specification (because this is the case where we delay
608 -- analysis till the end of the spec). Then (whether or not it was
609 -- analyzed), the pragma is chained to the subprogram in question
610 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
611 -- caller with In_Body set False.
613 -- The pragma appears at the start of subprogram body declarations
615 -- In this case an immediate return to the caller is made with
616 -- In_Body set True, and the pragma is NOT analyzed.
618 -- In all other cases, an error message for bad placement is given
620 procedure Check_Static_Constraint (Constr : Node_Id);
621 -- Constr is a constraint from an N_Subtype_Indication node from a
622 -- component constraint in an Unchecked_Union type. This routine checks
623 -- that the constraint is static as required by the restrictions for
626 procedure Check_Test_Case;
627 -- Called to process a test-case pragma. The treatment is similar to the
628 -- one for pre- and postcondition in Check_Precondition_Postcondition,
629 -- except the placement rules for the test-case pragma are stricter.
630 -- This pragma may only occur after a subprogram spec declared directly
631 -- in a package spec unit. In this case, the pragma is chained to the
632 -- subprogram in question (using Spec_TC_List and Next_Pragma) and
633 -- analysis of the pragma is delayed till the end of the spec. In
634 -- all other cases, an error message for bad placement is given.
636 procedure Check_Valid_Configuration_Pragma;
637 -- Legality checks for placement of a configuration pragma
639 procedure Check_Valid_Library_Unit_Pragma;
640 -- Legality checks for library unit pragmas. A special case arises for
641 -- pragmas in generic instances that come from copies of the original
642 -- library unit pragmas in the generic templates. In the case of other
643 -- than library level instantiations these can appear in contexts which
644 -- would normally be invalid (they only apply to the original template
645 -- and to library level instantiations), and they are simply ignored,
646 -- which is implemented by rewriting them as null statements.
648 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
649 -- Check an Unchecked_Union variant for lack of nested variants and
650 -- presence of at least one component. UU_Typ is the related Unchecked_
653 procedure Error_Pragma (Msg : String);
654 pragma No_Return (Error_Pragma);
655 -- Outputs error message for current pragma. The message contains a %
656 -- that will be replaced with the pragma name, and the flag is placed
657 -- on the pragma itself. Pragma_Exit is then raised.
659 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
660 pragma No_Return (Error_Pragma_Arg);
661 -- Outputs error message for current pragma. The message may contain
662 -- a % that will be replaced with the pragma name. The parameter Arg
663 -- may either be a pragma argument association, in which case the flag
664 -- is placed on the expression of this association, or an expression,
665 -- in which case the flag is placed directly on the expression. The
666 -- message is placed using Error_Msg_N, so the message may also contain
667 -- an & insertion character which will reference the given Arg value.
668 -- After placing the message, Pragma_Exit is raised.
670 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
671 pragma No_Return (Error_Pragma_Arg);
672 -- Similar to above form of Error_Pragma_Arg except that two messages
673 -- are provided, the second is a continuation comment starting with \.
675 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
676 pragma No_Return (Error_Pragma_Arg_Ident);
677 -- Outputs error message for current pragma. The message may contain
678 -- a % that will be replaced with the pragma name. The parameter Arg
679 -- must be a pragma argument association with a non-empty identifier
680 -- (i.e. its Chars field must be set), and the error message is placed
681 -- on the identifier. The message is placed using Error_Msg_N so
682 -- the message may also contain an & insertion character which will
683 -- reference the identifier. After placing the message, Pragma_Exit
686 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
687 pragma No_Return (Error_Pragma_Ref);
688 -- Outputs error message for current pragma. The message may contain
689 -- a % that will be replaced with the pragma name. The parameter Ref
690 -- must be an entity whose name can be referenced by & and sloc by #.
691 -- After placing the message, Pragma_Exit is raised.
693 function Find_Lib_Unit_Name return Entity_Id;
694 -- Used for a library unit pragma to find the entity to which the
695 -- library unit pragma applies, returns the entity found.
697 procedure Find_Program_Unit_Name (Id : Node_Id);
698 -- If the pragma is a compilation unit pragma, the id must denote the
699 -- compilation unit in the same compilation, and the pragma must appear
700 -- in the list of preceding or trailing pragmas. If it is a program
701 -- unit pragma that is not a compilation unit pragma, then the
702 -- identifier must be visible.
704 function Find_Unique_Parameterless_Procedure
706 Arg : Node_Id) return Entity_Id;
707 -- Used for a procedure pragma to find the unique parameterless
708 -- procedure identified by Name, returns it if it exists, otherwise
709 -- errors out and uses Arg as the pragma argument for the message.
711 procedure Fix_Error (Msg : in out String);
712 -- This is called prior to issuing an error message. Msg is a string
713 -- that typically contains the substring "pragma". If the current pragma
714 -- comes from an aspect, each such "pragma" substring is replaced with
715 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
716 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
718 procedure Gather_Associations
720 Args : out Args_List);
721 -- This procedure is used to gather the arguments for a pragma that
722 -- permits arbitrary ordering of parameters using the normal rules
723 -- for named and positional parameters. The Names argument is a list
724 -- of Name_Id values that corresponds to the allowed pragma argument
725 -- association identifiers in order. The result returned in Args is
726 -- a list of corresponding expressions that are the pragma arguments.
727 -- Note that this is a list of expressions, not of pragma argument
728 -- associations (Gather_Associations has completely checked all the
729 -- optional identifiers when it returns). An entry in Args is Empty
730 -- on return if the corresponding argument is not present.
732 procedure GNAT_Pragma;
733 -- Called for all GNAT defined pragmas to check the relevant restriction
734 -- (No_Implementation_Pragmas).
736 function Is_Before_First_Decl
737 (Pragma_Node : Node_Id;
738 Decls : List_Id) return Boolean;
739 -- Return True if Pragma_Node is before the first declarative item in
740 -- Decls where Decls is the list of declarative items.
742 function Is_Configuration_Pragma return Boolean;
743 -- Determines if the placement of the current pragma is appropriate
744 -- for a configuration pragma.
746 function Is_In_Context_Clause return Boolean;
747 -- Returns True if pragma appears within the context clause of a unit,
748 -- and False for any other placement (does not generate any messages).
750 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
751 -- Analyzes the argument, and determines if it is a static string
752 -- expression, returns True if so, False if non-static or not String.
754 procedure Pragma_Misplaced;
755 pragma No_Return (Pragma_Misplaced);
756 -- Issue fatal error message for misplaced pragma
758 procedure Process_Atomic_Shared_Volatile;
759 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
760 -- Shared is an obsolete Ada 83 pragma, treated as being identical
761 -- in effect to pragma Atomic.
763 procedure Process_Compile_Time_Warning_Or_Error;
764 -- Common processing for Compile_Time_Error and Compile_Time_Warning
766 procedure Process_Convention
767 (C : out Convention_Id;
768 Ent : out Entity_Id);
769 -- Common processing for Convention, Interface, Import and Export.
770 -- Checks first two arguments of pragma, and sets the appropriate
771 -- convention value in the specified entity or entities. On return
772 -- C is the convention, Ent is the referenced entity.
774 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
775 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
776 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
778 procedure Process_Extended_Import_Export_Exception_Pragma
779 (Arg_Internal : Node_Id;
780 Arg_External : Node_Id;
783 -- Common processing for the pragmas Import/Export_Exception. The three
784 -- arguments correspond to the three named parameters of the pragma. An
785 -- argument is empty if the corresponding parameter is not present in
788 procedure Process_Extended_Import_Export_Object_Pragma
789 (Arg_Internal : Node_Id;
790 Arg_External : Node_Id;
792 -- Common processing for the pragmas Import/Export_Object. The three
793 -- arguments correspond to the three named parameters of the pragmas. An
794 -- argument is empty if the corresponding parameter is not present in
797 procedure Process_Extended_Import_Export_Internal_Arg
798 (Arg_Internal : Node_Id := Empty);
799 -- Common processing for all extended Import and Export pragmas. The
800 -- argument is the pragma parameter for the Internal argument. If
801 -- Arg_Internal is empty or inappropriate, an error message is posted.
802 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
803 -- set to identify the referenced entity.
805 procedure Process_Extended_Import_Export_Subprogram_Pragma
806 (Arg_Internal : Node_Id;
807 Arg_External : Node_Id;
808 Arg_Parameter_Types : Node_Id;
809 Arg_Result_Type : Node_Id := Empty;
810 Arg_Mechanism : Node_Id;
811 Arg_Result_Mechanism : Node_Id := Empty;
812 Arg_First_Optional_Parameter : Node_Id := Empty);
813 -- Common processing for all extended Import and Export pragmas applying
814 -- to subprograms. The caller omits any arguments that do not apply to
815 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
816 -- only in the Import_Function and Export_Function cases). The argument
817 -- names correspond to the allowed pragma association identifiers.
819 procedure Process_Generic_List;
820 -- Common processing for Share_Generic and Inline_Generic
822 procedure Process_Import_Or_Interface;
823 -- Common processing for Import of Interface
825 procedure Process_Import_Predefined_Type;
826 -- Processing for completing a type with pragma Import. This is used
827 -- to declare types that match predefined C types, especially for cases
828 -- without corresponding Ada predefined type.
830 procedure Process_Inline (Active : Boolean);
831 -- Common processing for Inline and Inline_Always. The parameter
832 -- indicates if the inline pragma is active, i.e. if it should actually
833 -- cause inlining to occur.
835 procedure Process_Interface_Name
836 (Subprogram_Def : Entity_Id;
839 -- Given the last two arguments of pragma Import, pragma Export, or
840 -- pragma Interface_Name, performs validity checks and sets the
841 -- Interface_Name field of the given subprogram entity to the
842 -- appropriate external or link name, depending on the arguments given.
843 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
844 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
845 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
846 -- nor Link_Arg is present, the interface name is set to the default
847 -- from the subprogram name.
849 procedure Process_Interrupt_Or_Attach_Handler;
850 -- Common processing for Interrupt and Attach_Handler pragmas
852 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
853 -- Common processing for Restrictions and Restriction_Warnings pragmas.
854 -- Warn is True for Restriction_Warnings, or for Restrictions if the
855 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
856 -- is not set in the Restrictions case.
858 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
859 -- Common processing for Suppress and Unsuppress. The boolean parameter
860 -- Suppress_Case is True for the Suppress case, and False for the
863 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
864 -- This procedure sets the Is_Exported flag for the given entity,
865 -- checking that the entity was not previously imported. Arg is
866 -- the argument that specified the entity. A check is also made
867 -- for exporting inappropriate entities.
869 procedure Set_Extended_Import_Export_External_Name
870 (Internal_Ent : Entity_Id;
871 Arg_External : Node_Id);
872 -- Common processing for all extended import export pragmas. The first
873 -- argument, Internal_Ent, is the internal entity, which has already
874 -- been checked for validity by the caller. Arg_External is from the
875 -- Import or Export pragma, and may be null if no External parameter
876 -- was present. If Arg_External is present and is a non-null string
877 -- (a null string is treated as the default), then the Interface_Name
878 -- field of Internal_Ent is set appropriately.
880 procedure Set_Imported (E : Entity_Id);
881 -- This procedure sets the Is_Imported flag for the given entity,
882 -- checking that it is not previously exported or imported.
884 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
885 -- Mech is a parameter passing mechanism (see Import_Function syntax
886 -- for MECHANISM_NAME). This routine checks that the mechanism argument
887 -- has the right form, and if not issues an error message. If the
888 -- argument has the right form then the Mechanism field of Ent is
889 -- set appropriately.
891 procedure Set_Ravenscar_Profile (N : Node_Id);
892 -- Activate the set of configuration pragmas and restrictions that make
893 -- up the Ravenscar Profile. N is the corresponding pragma node, which
894 -- is used for error messages on any constructs that violate the
897 ---------------------
898 -- Ada_2005_Pragma --
899 ---------------------
901 procedure Ada_2005_Pragma is
903 if Ada_Version <= Ada_95 then
904 Check_Restriction (No_Implementation_Pragmas, N);
908 ---------------------
909 -- Ada_2012_Pragma --
910 ---------------------
912 procedure Ada_2012_Pragma is
914 if Ada_Version <= Ada_2005 then
915 Check_Restriction (No_Implementation_Pragmas, N);
919 --------------------------
920 -- Check_Ada_83_Warning --
921 --------------------------
923 procedure Check_Ada_83_Warning is
925 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
926 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
928 end Check_Ada_83_Warning;
930 ---------------------
931 -- Check_Arg_Count --
932 ---------------------
934 procedure Check_Arg_Count (Required : Nat) is
936 if Arg_Count /= Required then
937 Error_Pragma ("wrong number of arguments for pragma%");
941 --------------------------------
942 -- Check_Arg_Is_External_Name --
943 --------------------------------
945 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
946 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
949 if Nkind (Argx) = N_Identifier then
953 Analyze_And_Resolve (Argx, Standard_String);
955 if Is_OK_Static_Expression (Argx) then
958 elsif Etype (Argx) = Any_Type then
961 -- An interesting special case, if we have a string literal and
962 -- we are in Ada 83 mode, then we allow it even though it will
963 -- not be flagged as static. This allows expected Ada 83 mode
964 -- use of external names which are string literals, even though
965 -- technically these are not static in Ada 83.
967 elsif Ada_Version = Ada_83
968 and then Nkind (Argx) = N_String_Literal
972 -- Static expression that raises Constraint_Error. This has
973 -- already been flagged, so just exit from pragma processing.
975 elsif Is_Static_Expression (Argx) then
978 -- Here we have a real error (non-static expression)
981 Error_Msg_Name_1 := Pname;
985 "argument for pragma% must be a identifier or "
986 & "static string expression!";
989 Flag_Non_Static_Expr (Msg, Argx);
994 end Check_Arg_Is_External_Name;
996 -----------------------------
997 -- Check_Arg_Is_Identifier --
998 -----------------------------
1000 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
1001 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1003 if Nkind (Argx) /= N_Identifier then
1005 ("argument for pragma% must be identifier", Argx);
1007 end Check_Arg_Is_Identifier;
1009 ----------------------------------
1010 -- Check_Arg_Is_Integer_Literal --
1011 ----------------------------------
1013 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1014 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1016 if Nkind (Argx) /= N_Integer_Literal then
1018 ("argument for pragma% must be integer literal", Argx);
1020 end Check_Arg_Is_Integer_Literal;
1022 -------------------------------------------
1023 -- Check_Arg_Is_Library_Level_Local_Name --
1024 -------------------------------------------
1028 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1029 -- | library_unit_NAME
1031 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1033 Check_Arg_Is_Local_Name (Arg);
1035 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1036 and then Comes_From_Source (N)
1039 ("argument for pragma% must be library level entity", Arg);
1041 end Check_Arg_Is_Library_Level_Local_Name;
1043 -----------------------------
1044 -- Check_Arg_Is_Local_Name --
1045 -----------------------------
1049 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1050 -- | library_unit_NAME
1052 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1053 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1058 if Nkind (Argx) not in N_Direct_Name
1059 and then (Nkind (Argx) /= N_Attribute_Reference
1060 or else Present (Expressions (Argx))
1061 or else Nkind (Prefix (Argx)) /= N_Identifier)
1062 and then (not Is_Entity_Name (Argx)
1063 or else not Is_Compilation_Unit (Entity (Argx)))
1065 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1068 -- No further check required if not an entity name
1070 if not Is_Entity_Name (Argx) then
1076 Ent : constant Entity_Id := Entity (Argx);
1077 Scop : constant Entity_Id := Scope (Ent);
1079 -- Case of a pragma applied to a compilation unit: pragma must
1080 -- occur immediately after the program unit in the compilation.
1082 if Is_Compilation_Unit (Ent) then
1084 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1087 -- Case of pragma placed immediately after spec
1089 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1092 -- Case of pragma placed immediately after body
1094 elsif Nkind (Decl) = N_Subprogram_Declaration
1095 and then Present (Corresponding_Body (Decl))
1099 (Parent (Unit_Declaration_Node
1100 (Corresponding_Body (Decl))));
1102 -- All other cases are illegal
1109 -- Special restricted placement rule from 10.2.1(11.8/2)
1111 elsif Is_Generic_Formal (Ent)
1112 and then Prag_Id = Pragma_Preelaborable_Initialization
1114 OK := List_Containing (N) =
1115 Generic_Formal_Declarations
1116 (Unit_Declaration_Node (Scop));
1118 -- Default case, just check that the pragma occurs in the scope
1119 -- of the entity denoted by the name.
1122 OK := Current_Scope = Scop;
1127 ("pragma% argument must be in same declarative part", Arg);
1131 end Check_Arg_Is_Local_Name;
1133 ---------------------------------
1134 -- Check_Arg_Is_Locking_Policy --
1135 ---------------------------------
1137 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1138 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1141 Check_Arg_Is_Identifier (Argx);
1143 if not Is_Locking_Policy_Name (Chars (Argx)) then
1144 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1146 end Check_Arg_Is_Locking_Policy;
1148 -------------------------
1149 -- Check_Arg_Is_One_Of --
1150 -------------------------
1152 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1153 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1156 Check_Arg_Is_Identifier (Argx);
1158 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1159 Error_Msg_Name_2 := N1;
1160 Error_Msg_Name_3 := N2;
1161 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1163 end Check_Arg_Is_One_Of;
1165 procedure Check_Arg_Is_One_Of
1167 N1, N2, N3 : Name_Id)
1169 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1172 Check_Arg_Is_Identifier (Argx);
1174 if Chars (Argx) /= N1
1175 and then Chars (Argx) /= N2
1176 and then Chars (Argx) /= N3
1178 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1180 end Check_Arg_Is_One_Of;
1182 procedure Check_Arg_Is_One_Of
1184 N1, N2, N3, N4 : Name_Id)
1186 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1189 Check_Arg_Is_Identifier (Argx);
1191 if Chars (Argx) /= N1
1192 and then Chars (Argx) /= N2
1193 and then Chars (Argx) /= N3
1194 and then Chars (Argx) /= N4
1196 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1198 end Check_Arg_Is_One_Of;
1200 procedure Check_Arg_Is_One_Of
1202 N1, N2, N3, N4, N5 : Name_Id)
1204 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1207 Check_Arg_Is_Identifier (Argx);
1209 if Chars (Argx) /= N1
1210 and then Chars (Argx) /= N2
1211 and then Chars (Argx) /= N3
1212 and then Chars (Argx) /= N4
1213 and then Chars (Argx) /= N5
1215 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1217 end Check_Arg_Is_One_Of;
1218 ---------------------------------
1219 -- Check_Arg_Is_Queuing_Policy --
1220 ---------------------------------
1222 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1223 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1226 Check_Arg_Is_Identifier (Argx);
1228 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1229 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1231 end Check_Arg_Is_Queuing_Policy;
1233 ------------------------------------
1234 -- Check_Arg_Is_Static_Expression --
1235 ------------------------------------
1237 procedure Check_Arg_Is_Static_Expression
1239 Typ : Entity_Id := Empty)
1242 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1243 end Check_Arg_Is_Static_Expression;
1245 ------------------------------------------
1246 -- Check_Arg_Is_Task_Dispatching_Policy --
1247 ------------------------------------------
1249 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1250 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1253 Check_Arg_Is_Identifier (Argx);
1255 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1257 ("& is not a valid task dispatching policy name", Argx);
1259 end Check_Arg_Is_Task_Dispatching_Policy;
1261 ---------------------
1262 -- Check_Arg_Order --
1263 ---------------------
1265 procedure Check_Arg_Order (Names : Name_List) is
1268 Highest_So_Far : Natural := 0;
1269 -- Highest index in Names seen do far
1273 for J in 1 .. Arg_Count loop
1274 if Chars (Arg) /= No_Name then
1275 for K in Names'Range loop
1276 if Chars (Arg) = Names (K) then
1277 if K < Highest_So_Far then
1278 Error_Msg_Name_1 := Pname;
1280 ("parameters out of order for pragma%", Arg);
1281 Error_Msg_Name_1 := Names (K);
1282 Error_Msg_Name_2 := Names (Highest_So_Far);
1283 Error_Msg_N ("\% must appear before %", Arg);
1287 Highest_So_Far := K;
1295 end Check_Arg_Order;
1297 --------------------------------
1298 -- Check_At_Least_N_Arguments --
1299 --------------------------------
1301 procedure Check_At_Least_N_Arguments (N : Nat) is
1303 if Arg_Count < N then
1304 Error_Pragma ("too few arguments for pragma%");
1306 end Check_At_Least_N_Arguments;
1308 -------------------------------
1309 -- Check_At_Most_N_Arguments --
1310 -------------------------------
1312 procedure Check_At_Most_N_Arguments (N : Nat) is
1315 if Arg_Count > N then
1317 for J in 1 .. N loop
1319 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1322 end Check_At_Most_N_Arguments;
1324 ---------------------
1325 -- Check_Component --
1326 ---------------------
1328 procedure Check_Component
1331 In_Variant_Part : Boolean := False)
1333 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1334 Sindic : constant Node_Id :=
1335 Subtype_Indication (Component_Definition (Comp));
1336 Typ : constant Entity_Id := Etype (Comp_Id);
1339 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1340 -- object constraint, then the component type shall be an Unchecked_
1343 if Nkind (Sindic) = N_Subtype_Indication
1344 and then Has_Per_Object_Constraint (Comp_Id)
1345 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1348 ("component subtype subject to per-object constraint " &
1349 "must be an Unchecked_Union", Comp);
1351 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1352 -- the body of a generic unit, or within the body of any of its
1353 -- descendant library units, no part of the type of a component
1354 -- declared in a variant_part of the unchecked union type shall be of
1355 -- a formal private type or formal private extension declared within
1356 -- the formal part of the generic unit.
1358 elsif Ada_Version >= Ada_2012
1359 and then In_Generic_Body (UU_Typ)
1360 and then In_Variant_Part
1361 and then Is_Private_Type (Typ)
1362 and then Is_Generic_Type (Typ)
1365 ("component of Unchecked_Union cannot be of generic type", Comp);
1367 elsif Needs_Finalization (Typ) then
1369 ("component of Unchecked_Union cannot be controlled", Comp);
1371 elsif Has_Task (Typ) then
1373 ("component of Unchecked_Union cannot have tasks", Comp);
1375 end Check_Component;
1377 ----------------------------
1378 -- Check_Duplicate_Pragma --
1379 ----------------------------
1381 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1385 -- Nothing to do if this pragma comes from an aspect specification,
1386 -- since we could not be duplicating a pragma, and we dealt with the
1387 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1389 if From_Aspect_Specification (N) then
1393 -- Otherwise current pragma may duplicate previous pragma or a
1394 -- previously given aspect specification for the same pragma.
1396 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1399 Error_Msg_Name_1 := Pragma_Name (N);
1400 Error_Msg_Sloc := Sloc (P);
1402 if Nkind (P) = N_Aspect_Specification
1403 or else From_Aspect_Specification (P)
1405 Error_Msg_NE ("aspect% for & previously given#", N, E);
1407 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1412 end Check_Duplicate_Pragma;
1414 ----------------------------------
1415 -- Check_Duplicated_Export_Name --
1416 ----------------------------------
1418 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1419 String_Val : constant String_Id := Strval (Nam);
1422 -- We are only interested in the export case, and in the case of
1423 -- generics, it is the instance, not the template, that is the
1424 -- problem (the template will generate a warning in any case).
1426 if not Inside_A_Generic
1427 and then (Prag_Id = Pragma_Export
1429 Prag_Id = Pragma_Export_Procedure
1431 Prag_Id = Pragma_Export_Valued_Procedure
1433 Prag_Id = Pragma_Export_Function)
1435 for J in Externals.First .. Externals.Last loop
1436 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1437 Error_Msg_Sloc := Sloc (Externals.Table (J));
1438 Error_Msg_N ("external name duplicates name given#", Nam);
1443 Externals.Append (Nam);
1445 end Check_Duplicated_Export_Name;
1447 -------------------------------------
1448 -- Check_Expr_Is_Static_Expression --
1449 -------------------------------------
1451 procedure Check_Expr_Is_Static_Expression
1453 Typ : Entity_Id := Empty)
1456 if Present (Typ) then
1457 Analyze_And_Resolve (Expr, Typ);
1459 Analyze_And_Resolve (Expr);
1462 if Is_OK_Static_Expression (Expr) then
1465 elsif Etype (Expr) = Any_Type then
1468 -- An interesting special case, if we have a string literal and we
1469 -- are in Ada 83 mode, then we allow it even though it will not be
1470 -- flagged as static. This allows the use of Ada 95 pragmas like
1471 -- Import in Ada 83 mode. They will of course be flagged with
1472 -- warnings as usual, but will not cause errors.
1474 elsif Ada_Version = Ada_83
1475 and then Nkind (Expr) = N_String_Literal
1479 -- Static expression that raises Constraint_Error. This has already
1480 -- been flagged, so just exit from pragma processing.
1482 elsif Is_Static_Expression (Expr) then
1485 -- Finally, we have a real error
1488 Error_Msg_Name_1 := Pname;
1492 "argument for pragma% must be a static expression!";
1495 Flag_Non_Static_Expr (Msg, Expr);
1500 end Check_Expr_Is_Static_Expression;
1502 -------------------------
1503 -- Check_First_Subtype --
1504 -------------------------
1506 procedure Check_First_Subtype (Arg : Node_Id) is
1507 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1508 Ent : constant Entity_Id := Entity (Argx);
1511 if Is_First_Subtype (Ent) then
1514 elsif Is_Type (Ent) then
1516 ("pragma% cannot apply to subtype", Argx);
1518 elsif Is_Object (Ent) then
1520 ("pragma% cannot apply to object, requires a type", Argx);
1524 ("pragma% cannot apply to&, requires a type", Argx);
1526 end Check_First_Subtype;
1528 ----------------------
1529 -- Check_Identifier --
1530 ----------------------
1532 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1535 and then Nkind (Arg) = N_Pragma_Argument_Association
1537 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1538 Error_Msg_Name_1 := Pname;
1539 Error_Msg_Name_2 := Id;
1540 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1544 end Check_Identifier;
1546 --------------------------------
1547 -- Check_Identifier_Is_One_Of --
1548 --------------------------------
1550 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1553 and then Nkind (Arg) = N_Pragma_Argument_Association
1555 if Chars (Arg) = No_Name then
1556 Error_Msg_Name_1 := Pname;
1557 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1560 elsif Chars (Arg) /= N1
1561 and then Chars (Arg) /= N2
1563 Error_Msg_Name_1 := Pname;
1564 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1568 end Check_Identifier_Is_One_Of;
1570 ---------------------------
1571 -- Check_In_Main_Program --
1572 ---------------------------
1574 procedure Check_In_Main_Program is
1575 P : constant Node_Id := Parent (N);
1578 -- Must be at in subprogram body
1580 if Nkind (P) /= N_Subprogram_Body then
1581 Error_Pragma ("% pragma allowed only in subprogram");
1583 -- Otherwise warn if obviously not main program
1585 elsif Present (Parameter_Specifications (Specification (P)))
1586 or else not Is_Compilation_Unit (Defining_Entity (P))
1588 Error_Msg_Name_1 := Pname;
1590 ("?pragma% is only effective in main program", N);
1592 end Check_In_Main_Program;
1594 ---------------------------------------
1595 -- Check_Interrupt_Or_Attach_Handler --
1596 ---------------------------------------
1598 procedure Check_Interrupt_Or_Attach_Handler is
1599 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1600 Handler_Proc, Proc_Scope : Entity_Id;
1605 if Prag_Id = Pragma_Interrupt_Handler then
1606 Check_Restriction (No_Dynamic_Attachment, N);
1609 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1610 Proc_Scope := Scope (Handler_Proc);
1612 -- On AAMP only, a pragma Interrupt_Handler is supported for
1613 -- nonprotected parameterless procedures.
1615 if not AAMP_On_Target
1616 or else Prag_Id = Pragma_Attach_Handler
1618 if Ekind (Proc_Scope) /= E_Protected_Type then
1620 ("argument of pragma% must be protected procedure", Arg1);
1623 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1624 Error_Pragma ("pragma% must be in protected definition");
1628 if not Is_Library_Level_Entity (Proc_Scope)
1629 or else (AAMP_On_Target
1630 and then not Is_Library_Level_Entity (Handler_Proc))
1633 ("argument for pragma% must be library level entity", Arg1);
1636 -- AI05-0033: A pragma cannot appear within a generic body, because
1637 -- instance can be in a nested scope. The check that protected type
1638 -- is itself a library-level declaration is done elsewhere.
1640 -- Note: we omit this check in Codepeer mode to properly handle code
1641 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1643 if Inside_A_Generic then
1644 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1645 and then In_Package_Body (Scope (Current_Scope))
1646 and then not CodePeer_Mode
1648 Error_Pragma ("pragma% cannot be used inside a generic");
1651 end Check_Interrupt_Or_Attach_Handler;
1653 -------------------------------------------
1654 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1655 -------------------------------------------
1657 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1666 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1669 elsif Nkind_In (P, N_Package_Specification,
1674 -- Note: the following tests seem a little peculiar, because
1675 -- they test for bodies, but if we were in the statement part
1676 -- of the body, we would already have hit the handled statement
1677 -- sequence, so the only way we get here is by being in the
1678 -- declarative part of the body.
1680 elsif Nkind_In (P, N_Subprogram_Body,
1691 Error_Pragma ("pragma% is not in declarative part or package spec");
1692 end Check_Is_In_Decl_Part_Or_Package_Spec;
1694 -------------------------
1695 -- Check_No_Identifier --
1696 -------------------------
1698 procedure Check_No_Identifier (Arg : Node_Id) is
1700 if Nkind (Arg) = N_Pragma_Argument_Association
1701 and then Chars (Arg) /= No_Name
1703 Error_Pragma_Arg_Ident
1704 ("pragma% does not permit identifier& here", Arg);
1706 end Check_No_Identifier;
1708 --------------------------
1709 -- Check_No_Identifiers --
1710 --------------------------
1712 procedure Check_No_Identifiers is
1715 if Arg_Count > 0 then
1717 while Present (Arg_Node) loop
1718 Check_No_Identifier (Arg_Node);
1722 end Check_No_Identifiers;
1724 ------------------------
1725 -- Check_No_Link_Name --
1726 ------------------------
1728 procedure Check_No_Link_Name is
1731 and then Chars (Arg3) = Name_Link_Name
1736 if Present (Arg4) then
1738 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1740 end Check_No_Link_Name;
1742 -------------------------------
1743 -- Check_Optional_Identifier --
1744 -------------------------------
1746 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1749 and then Nkind (Arg) = N_Pragma_Argument_Association
1750 and then Chars (Arg) /= No_Name
1752 if Chars (Arg) /= Id then
1753 Error_Msg_Name_1 := Pname;
1754 Error_Msg_Name_2 := Id;
1755 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1759 end Check_Optional_Identifier;
1761 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1763 Name_Buffer (1 .. Id'Length) := Id;
1764 Name_Len := Id'Length;
1765 Check_Optional_Identifier (Arg, Name_Find);
1766 end Check_Optional_Identifier;
1768 --------------------------------------
1769 -- Check_Precondition_Postcondition --
1770 --------------------------------------
1772 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1776 procedure Chain_PPC (PO : Node_Id);
1777 -- If PO is an entry or a [generic] subprogram declaration node, then
1778 -- the precondition/postcondition applies to this subprogram and the
1779 -- processing for the pragma is completed. Otherwise the pragma is
1786 procedure Chain_PPC (PO : Node_Id) is
1791 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1792 if not From_Aspect_Specification (N) then
1794 ("pragma% cannot be applied to abstract subprogram");
1796 elsif Class_Present (N) then
1801 ("aspect % requires ''Class for abstract subprogram");
1804 -- AI05-0230: The same restriction applies to null procedures. For
1805 -- compatibility with earlier uses of the Ada pragma, apply this
1806 -- rule only to aspect specifications.
1808 -- The above discrpency needs documentation. Robert is dubious
1809 -- about whether it is a good idea ???
1811 elsif Nkind (PO) = N_Subprogram_Declaration
1812 and then Nkind (Specification (PO)) = N_Procedure_Specification
1813 and then Null_Present (Specification (PO))
1814 and then From_Aspect_Specification (N)
1815 and then not Class_Present (N)
1818 ("aspect % requires ''Class for null procedure");
1820 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1821 N_Expression_Function,
1822 N_Generic_Subprogram_Declaration,
1823 N_Entry_Declaration)
1828 -- Here if we have [generic] subprogram or entry declaration
1830 if Nkind (PO) = N_Entry_Declaration then
1831 S := Defining_Entity (PO);
1833 S := Defining_Unit_Name (Specification (PO));
1836 -- Make sure we do not have the case of a precondition pragma when
1837 -- the Pre'Class aspect is present.
1839 -- We do this by looking at pragmas already chained to the entity
1840 -- since the aspect derived pragma will be put on this list first.
1842 if Pragma_Name (N) = Name_Precondition then
1843 if not From_Aspect_Specification (N) then
1844 P := Spec_PPC_List (Contract (S));
1845 while Present (P) loop
1846 if Pragma_Name (P) = Name_Precondition
1847 and then From_Aspect_Specification (P)
1848 and then Class_Present (P)
1850 Error_Msg_Sloc := Sloc (P);
1852 ("pragma% not allowed, `Pre''Class` aspect given#");
1855 P := Next_Pragma (P);
1860 -- Similarly check for Pre with inherited Pre'Class. Note that
1861 -- we cover the aspect case as well here.
1863 if Pragma_Name (N) = Name_Precondition
1864 and then not Class_Present (N)
1867 Inherited : constant Subprogram_List :=
1868 Inherited_Subprograms (S);
1872 for J in Inherited'Range loop
1873 P := Spec_PPC_List (Contract (Inherited (J)));
1874 while Present (P) loop
1875 if Pragma_Name (P) = Name_Precondition
1876 and then Class_Present (P)
1878 Error_Msg_Sloc := Sloc (P);
1880 ("pragma% not allowed, `Pre''Class` "
1881 & "aspect inherited from#");
1884 P := Next_Pragma (P);
1890 -- Note: we do not analyze the pragma at this point. Instead we
1891 -- delay this analysis until the end of the declarative part in
1892 -- which the pragma appears. This implements the required delay
1893 -- in this analysis, allowing forward references. The analysis
1894 -- happens at the end of Analyze_Declarations.
1896 -- Chain spec PPC pragma to list for subprogram
1898 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1899 Set_Spec_PPC_List (Contract (S), N);
1901 -- Return indicating spec case
1907 -- Start of processing for Check_Precondition_Postcondition
1910 if not Is_List_Member (N) then
1914 -- Preanalyze message argument if present. Visibility in this
1915 -- argument is established at the point of pragma occurrence.
1917 if Arg_Count = 2 then
1918 Check_Optional_Identifier (Arg2, Name_Message);
1919 Preanalyze_Spec_Expression
1920 (Get_Pragma_Arg (Arg2), Standard_String);
1923 -- Record if pragma is disabled
1925 if Check_Enabled (Pname) then
1926 Set_SCO_Pragma_Enabled (Loc);
1929 -- If we are within an inlined body, the legality of the pragma
1930 -- has been checked already.
1932 if In_Inlined_Body then
1937 -- Search prior declarations
1940 while Present (Prev (P)) loop
1943 -- If the previous node is a generic subprogram, do not go to to
1944 -- the original node, which is the unanalyzed tree: we need to
1945 -- attach the pre/postconditions to the analyzed version at this
1946 -- point. They get propagated to the original tree when analyzing
1947 -- the corresponding body.
1949 if Nkind (P) not in N_Generic_Declaration then
1950 PO := Original_Node (P);
1955 -- Skip past prior pragma
1957 if Nkind (PO) = N_Pragma then
1960 -- Skip stuff not coming from source
1962 elsif not Comes_From_Source (PO) then
1964 -- The condition may apply to a subprogram instantiation
1966 if Nkind (PO) = N_Subprogram_Declaration
1967 and then Present (Generic_Parent (Specification (PO)))
1972 elsif Nkind (PO) = N_Subprogram_Declaration
1973 and then In_Instance
1978 -- For all other cases of non source code, do nothing
1984 -- Only remaining possibility is subprogram declaration
1992 -- If we fall through loop, pragma is at start of list, so see if it
1993 -- is at the start of declarations of a subprogram body.
1995 if Nkind (Parent (N)) = N_Subprogram_Body
1996 and then List_Containing (N) = Declarations (Parent (N))
1998 if Operating_Mode /= Generate_Code
1999 or else Inside_A_Generic
2001 -- Analyze pragma expression for correctness and for ASIS use
2003 Preanalyze_Spec_Expression
2004 (Get_Pragma_Arg (Arg1), Standard_Boolean);
2006 -- In ASIS mode, for a pragma generated from a source aspect,
2007 -- also analyze the original aspect expression.
2010 and then Present (Corresponding_Aspect (N))
2012 Preanalyze_Spec_Expression
2013 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2020 -- See if it is in the pragmas after a library level subprogram
2022 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2024 -- In formal verification mode, analyze pragma expression for
2025 -- correctness, as it is not expanded later.
2028 Analyze_PPC_In_Decl_Part
2029 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2032 Chain_PPC (Unit (Parent (Parent (N))));
2036 -- If we fall through, pragma was misplaced
2039 end Check_Precondition_Postcondition;
2041 -----------------------------
2042 -- Check_Static_Constraint --
2043 -----------------------------
2045 -- Note: for convenience in writing this procedure, in addition to
2046 -- the officially (i.e. by spec) allowed argument which is always a
2047 -- constraint, it also allows ranges and discriminant associations.
2048 -- Above is not clear ???
2050 procedure Check_Static_Constraint (Constr : Node_Id) is
2052 procedure Require_Static (E : Node_Id);
2053 -- Require given expression to be static expression
2055 --------------------
2056 -- Require_Static --
2057 --------------------
2059 procedure Require_Static (E : Node_Id) is
2061 if not Is_OK_Static_Expression (E) then
2062 Flag_Non_Static_Expr
2063 ("non-static constraint not allowed in Unchecked_Union!", E);
2068 -- Start of processing for Check_Static_Constraint
2071 case Nkind (Constr) is
2072 when N_Discriminant_Association =>
2073 Require_Static (Expression (Constr));
2076 Require_Static (Low_Bound (Constr));
2077 Require_Static (High_Bound (Constr));
2079 when N_Attribute_Reference =>
2080 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2081 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2083 when N_Range_Constraint =>
2084 Check_Static_Constraint (Range_Expression (Constr));
2086 when N_Index_Or_Discriminant_Constraint =>
2090 IDC := First (Constraints (Constr));
2091 while Present (IDC) loop
2092 Check_Static_Constraint (IDC);
2100 end Check_Static_Constraint;
2102 ---------------------
2103 -- Check_Test_Case --
2104 ---------------------
2106 procedure Check_Test_Case is
2110 procedure Chain_TC (PO : Node_Id);
2111 -- If PO is a [generic] subprogram declaration node, then the
2112 -- test-case applies to this subprogram and the processing for the
2113 -- pragma is completed. Otherwise the pragma is misplaced.
2119 procedure Chain_TC (PO : Node_Id) is
2123 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2124 if From_Aspect_Specification (N) then
2126 ("aspect% cannot be applied to abstract subprogram");
2129 ("pragma% cannot be applied to abstract subprogram");
2132 elsif Nkind (PO) = N_Entry_Declaration then
2133 if From_Aspect_Specification (N) then
2134 Error_Pragma ("aspect% cannot be applied to entry");
2136 Error_Pragma ("pragma% cannot be applied to entry");
2139 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2140 N_Generic_Subprogram_Declaration)
2145 -- Here if we have [generic] subprogram declaration
2147 S := Defining_Unit_Name (Specification (PO));
2149 -- Note: we do not analyze the pragma at this point. Instead we
2150 -- delay this analysis until the end of the declarative part in
2151 -- which the pragma appears. This implements the required delay
2152 -- in this analysis, allowing forward references. The analysis
2153 -- happens at the end of Analyze_Declarations.
2155 -- There should not be another test case with the same name
2156 -- associated to this subprogram.
2159 Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2163 TC := Spec_TC_List (Contract (S));
2164 while Present (TC) loop
2167 (Name, Get_Name_From_Test_Case_Pragma (TC))
2169 Error_Msg_Sloc := Sloc (TC);
2171 if From_Aspect_Specification (N) then
2172 Error_Pragma ("name for aspect% is already used#");
2174 Error_Pragma ("name for pragma% is already used#");
2178 TC := Next_Pragma (TC);
2182 -- Chain spec TC pragma to list for subprogram
2184 Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2185 Set_Spec_TC_List (Contract (S), N);
2188 -- Start of processing for Check_Test_Case
2191 if not Is_List_Member (N) then
2195 -- Test cases should only appear in package spec unit
2197 if Get_Source_Unit (N) = No_Unit
2198 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2199 N_Package_Declaration,
2200 N_Generic_Package_Declaration)
2205 -- Search prior declarations
2208 while Present (Prev (P)) loop
2211 -- If the previous node is a generic subprogram, do not go to to
2212 -- the original node, which is the unanalyzed tree: we need to
2213 -- attach the test-case to the analyzed version at this point.
2214 -- They get propagated to the original tree when analyzing the
2215 -- corresponding body.
2217 if Nkind (P) not in N_Generic_Declaration then
2218 PO := Original_Node (P);
2223 -- Skip past prior pragma
2225 if Nkind (PO) = N_Pragma then
2228 -- Skip stuff not coming from source
2230 elsif not Comes_From_Source (PO) then
2233 -- Only remaining possibility is subprogram declaration. First
2234 -- check that it is declared directly in a package declaration.
2235 -- This may be either the package declaration for the current unit
2236 -- being defined or a local package declaration.
2238 elsif not Present (Parent (Parent (PO)))
2239 or else not Present (Parent (Parent (Parent (PO))))
2240 or else not Nkind_In (Parent (Parent (PO)),
2241 N_Package_Declaration,
2242 N_Generic_Package_Declaration)
2252 -- If we fall through, pragma was misplaced
2255 end Check_Test_Case;
2257 --------------------------------------
2258 -- Check_Valid_Configuration_Pragma --
2259 --------------------------------------
2261 -- A configuration pragma must appear in the context clause of a
2262 -- compilation unit, and only other pragmas may precede it. Note that
2263 -- the test also allows use in a configuration pragma file.
2265 procedure Check_Valid_Configuration_Pragma is
2267 if not Is_Configuration_Pragma then
2268 Error_Pragma ("incorrect placement for configuration pragma%");
2270 end Check_Valid_Configuration_Pragma;
2272 -------------------------------------
2273 -- Check_Valid_Library_Unit_Pragma --
2274 -------------------------------------
2276 procedure Check_Valid_Library_Unit_Pragma is
2278 Parent_Node : Node_Id;
2279 Unit_Name : Entity_Id;
2280 Unit_Kind : Node_Kind;
2281 Unit_Node : Node_Id;
2282 Sindex : Source_File_Index;
2285 if not Is_List_Member (N) then
2289 Plist := List_Containing (N);
2290 Parent_Node := Parent (Plist);
2292 if Parent_Node = Empty then
2295 -- Case of pragma appearing after a compilation unit. In this case
2296 -- it must have an argument with the corresponding name and must
2297 -- be part of the following pragmas of its parent.
2299 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2300 if Plist /= Pragmas_After (Parent_Node) then
2303 elsif Arg_Count = 0 then
2305 ("argument required if outside compilation unit");
2308 Check_No_Identifiers;
2309 Check_Arg_Count (1);
2310 Unit_Node := Unit (Parent (Parent_Node));
2311 Unit_Kind := Nkind (Unit_Node);
2313 Analyze (Get_Pragma_Arg (Arg1));
2315 if Unit_Kind = N_Generic_Subprogram_Declaration
2316 or else Unit_Kind = N_Subprogram_Declaration
2318 Unit_Name := Defining_Entity (Unit_Node);
2320 elsif Unit_Kind in N_Generic_Instantiation then
2321 Unit_Name := Defining_Entity (Unit_Node);
2324 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2327 if Chars (Unit_Name) /=
2328 Chars (Entity (Get_Pragma_Arg (Arg1)))
2331 ("pragma% argument is not current unit name", Arg1);
2334 if Ekind (Unit_Name) = E_Package
2335 and then Present (Renamed_Entity (Unit_Name))
2337 Error_Pragma ("pragma% not allowed for renamed package");
2341 -- Pragma appears other than after a compilation unit
2344 -- Here we check for the generic instantiation case and also
2345 -- for the case of processing a generic formal package. We
2346 -- detect these cases by noting that the Sloc on the node
2347 -- does not belong to the current compilation unit.
2349 Sindex := Source_Index (Current_Sem_Unit);
2351 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2352 Rewrite (N, Make_Null_Statement (Loc));
2355 -- If before first declaration, the pragma applies to the
2356 -- enclosing unit, and the name if present must be this name.
2358 elsif Is_Before_First_Decl (N, Plist) then
2359 Unit_Node := Unit_Declaration_Node (Current_Scope);
2360 Unit_Kind := Nkind (Unit_Node);
2362 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2365 elsif Unit_Kind = N_Subprogram_Body
2366 and then not Acts_As_Spec (Unit_Node)
2370 elsif Nkind (Parent_Node) = N_Package_Body then
2373 elsif Nkind (Parent_Node) = N_Package_Specification
2374 and then Plist = Private_Declarations (Parent_Node)
2378 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2379 or else Nkind (Parent_Node) =
2380 N_Generic_Subprogram_Declaration)
2381 and then Plist = Generic_Formal_Declarations (Parent_Node)
2385 elsif Arg_Count > 0 then
2386 Analyze (Get_Pragma_Arg (Arg1));
2388 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2390 ("name in pragma% must be enclosing unit", Arg1);
2393 -- It is legal to have no argument in this context
2399 -- Error if not before first declaration. This is because a
2400 -- library unit pragma argument must be the name of a library
2401 -- unit (RM 10.1.5(7)), but the only names permitted in this
2402 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2403 -- generic subprogram declarations or generic instantiations.
2407 ("pragma% misplaced, must be before first declaration");
2411 end Check_Valid_Library_Unit_Pragma;
2417 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2418 Clist : constant Node_Id := Component_List (Variant);
2422 if not Is_Non_Empty_List (Component_Items (Clist)) then
2424 ("Unchecked_Union may not have empty component list",
2429 Comp := First (Component_Items (Clist));
2430 while Present (Comp) loop
2431 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2440 procedure Error_Pragma (Msg : String) is
2441 MsgF : String := Msg;
2443 Error_Msg_Name_1 := Pname;
2445 Error_Msg_N (MsgF, N);
2449 ----------------------
2450 -- Error_Pragma_Arg --
2451 ----------------------
2453 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2454 MsgF : String := Msg;
2456 Error_Msg_Name_1 := Pname;
2458 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2460 end Error_Pragma_Arg;
2462 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2463 MsgF : String := Msg1;
2465 Error_Msg_Name_1 := Pname;
2467 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2468 Error_Pragma_Arg (Msg2, Arg);
2469 end Error_Pragma_Arg;
2471 ----------------------------
2472 -- Error_Pragma_Arg_Ident --
2473 ----------------------------
2475 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2476 MsgF : String := Msg;
2478 Error_Msg_Name_1 := Pname;
2480 Error_Msg_N (MsgF, Arg);
2482 end Error_Pragma_Arg_Ident;
2484 ----------------------
2485 -- Error_Pragma_Ref --
2486 ----------------------
2488 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2489 MsgF : String := Msg;
2491 Error_Msg_Name_1 := Pname;
2493 Error_Msg_Sloc := Sloc (Ref);
2494 Error_Msg_NE (MsgF, N, Ref);
2496 end Error_Pragma_Ref;
2498 ------------------------
2499 -- Find_Lib_Unit_Name --
2500 ------------------------
2502 function Find_Lib_Unit_Name return Entity_Id is
2504 -- Return inner compilation unit entity, for case of nested
2505 -- categorization pragmas. This happens in generic unit.
2507 if Nkind (Parent (N)) = N_Package_Specification
2508 and then Defining_Entity (Parent (N)) /= Current_Scope
2510 return Defining_Entity (Parent (N));
2512 return Current_Scope;
2514 end Find_Lib_Unit_Name;
2516 ----------------------------
2517 -- Find_Program_Unit_Name --
2518 ----------------------------
2520 procedure Find_Program_Unit_Name (Id : Node_Id) is
2521 Unit_Name : Entity_Id;
2522 Unit_Kind : Node_Kind;
2523 P : constant Node_Id := Parent (N);
2526 if Nkind (P) = N_Compilation_Unit then
2527 Unit_Kind := Nkind (Unit (P));
2529 if Unit_Kind = N_Subprogram_Declaration
2530 or else Unit_Kind = N_Package_Declaration
2531 or else Unit_Kind in N_Generic_Declaration
2533 Unit_Name := Defining_Entity (Unit (P));
2535 if Chars (Id) = Chars (Unit_Name) then
2536 Set_Entity (Id, Unit_Name);
2537 Set_Etype (Id, Etype (Unit_Name));
2539 Set_Etype (Id, Any_Type);
2541 ("cannot find program unit referenced by pragma%");
2545 Set_Etype (Id, Any_Type);
2546 Error_Pragma ("pragma% inapplicable to this unit");
2552 end Find_Program_Unit_Name;
2554 -----------------------------------------
2555 -- Find_Unique_Parameterless_Procedure --
2556 -----------------------------------------
2558 function Find_Unique_Parameterless_Procedure
2560 Arg : Node_Id) return Entity_Id
2562 Proc : Entity_Id := Empty;
2565 -- The body of this procedure needs some comments ???
2567 if not Is_Entity_Name (Name) then
2569 ("argument of pragma% must be entity name", Arg);
2571 elsif not Is_Overloaded (Name) then
2572 Proc := Entity (Name);
2574 if Ekind (Proc) /= E_Procedure
2575 or else Present (First_Formal (Proc))
2578 ("argument of pragma% must be parameterless procedure", Arg);
2583 Found : Boolean := False;
2585 Index : Interp_Index;
2588 Get_First_Interp (Name, Index, It);
2589 while Present (It.Nam) loop
2592 if Ekind (Proc) = E_Procedure
2593 and then No (First_Formal (Proc))
2597 Set_Entity (Name, Proc);
2598 Set_Is_Overloaded (Name, False);
2601 ("ambiguous handler name for pragma% ", Arg);
2605 Get_Next_Interp (Index, It);
2610 ("argument of pragma% must be parameterless procedure",
2613 Proc := Entity (Name);
2619 end Find_Unique_Parameterless_Procedure;
2625 procedure Fix_Error (Msg : in out String) is
2627 if From_Aspect_Specification (N) then
2628 for J in Msg'First .. Msg'Last - 5 loop
2629 if Msg (J .. J + 5) = "pragma" then
2630 Msg (J .. J + 5) := "aspect";
2634 if Error_Msg_Name_1 = Name_Precondition then
2635 Error_Msg_Name_1 := Name_Pre;
2636 elsif Error_Msg_Name_1 = Name_Postcondition then
2637 Error_Msg_Name_1 := Name_Post;
2642 -------------------------
2643 -- Gather_Associations --
2644 -------------------------
2646 procedure Gather_Associations
2648 Args : out Args_List)
2653 -- Initialize all parameters to Empty
2655 for J in Args'Range loop
2659 -- That's all we have to do if there are no argument associations
2661 if No (Pragma_Argument_Associations (N)) then
2665 -- Otherwise first deal with any positional parameters present
2667 Arg := First (Pragma_Argument_Associations (N));
2668 for Index in Args'Range loop
2669 exit when No (Arg) or else Chars (Arg) /= No_Name;
2670 Args (Index) := Get_Pragma_Arg (Arg);
2674 -- Positional parameters all processed, if any left, then we
2675 -- have too many positional parameters.
2677 if Present (Arg) and then Chars (Arg) = No_Name then
2679 ("too many positional associations for pragma%", Arg);
2682 -- Process named parameters if any are present
2684 while Present (Arg) loop
2685 if Chars (Arg) = No_Name then
2687 ("positional association cannot follow named association",
2691 for Index in Names'Range loop
2692 if Names (Index) = Chars (Arg) then
2693 if Present (Args (Index)) then
2695 ("duplicate argument association for pragma%", Arg);
2697 Args (Index) := Get_Pragma_Arg (Arg);
2702 if Index = Names'Last then
2703 Error_Msg_Name_1 := Pname;
2704 Error_Msg_N ("pragma% does not allow & argument", Arg);
2706 -- Check for possible misspelling
2708 for Index1 in Names'Range loop
2709 if Is_Bad_Spelling_Of
2710 (Chars (Arg), Names (Index1))
2712 Error_Msg_Name_1 := Names (Index1);
2713 Error_Msg_N -- CODEFIX
2714 ("\possible misspelling of%", Arg);
2726 end Gather_Associations;
2732 procedure GNAT_Pragma is
2734 -- We need to check the No_Implementation_Pragmas restriction for
2735 -- the case of a pragma from source. Note that the case of aspects
2736 -- generating corresponding pragmas marks these pragmas as not being
2737 -- from source, so this test also catches that case.
2739 if Comes_From_Source (N) then
2740 Check_Restriction (No_Implementation_Pragmas, N);
2744 --------------------------
2745 -- Is_Before_First_Decl --
2746 --------------------------
2748 function Is_Before_First_Decl
2749 (Pragma_Node : Node_Id;
2750 Decls : List_Id) return Boolean
2752 Item : Node_Id := First (Decls);
2755 -- Only other pragmas can come before this pragma
2758 if No (Item) or else Nkind (Item) /= N_Pragma then
2761 elsif Item = Pragma_Node then
2767 end Is_Before_First_Decl;
2769 -----------------------------
2770 -- Is_Configuration_Pragma --
2771 -----------------------------
2773 -- A configuration pragma must appear in the context clause of a
2774 -- compilation unit, and only other pragmas may precede it. Note that
2775 -- the test below also permits use in a configuration pragma file.
2777 function Is_Configuration_Pragma return Boolean is
2778 Lis : constant List_Id := List_Containing (N);
2779 Par : constant Node_Id := Parent (N);
2783 -- If no parent, then we are in the configuration pragma file,
2784 -- so the placement is definitely appropriate.
2789 -- Otherwise we must be in the context clause of a compilation unit
2790 -- and the only thing allowed before us in the context list is more
2791 -- configuration pragmas.
2793 elsif Nkind (Par) = N_Compilation_Unit
2794 and then Context_Items (Par) = Lis
2801 elsif Nkind (Prg) /= N_Pragma then
2811 end Is_Configuration_Pragma;
2813 --------------------------
2814 -- Is_In_Context_Clause --
2815 --------------------------
2817 function Is_In_Context_Clause return Boolean is
2819 Parent_Node : Node_Id;
2822 if not Is_List_Member (N) then
2826 Plist := List_Containing (N);
2827 Parent_Node := Parent (Plist);
2829 if Parent_Node = Empty
2830 or else Nkind (Parent_Node) /= N_Compilation_Unit
2831 or else Context_Items (Parent_Node) /= Plist
2838 end Is_In_Context_Clause;
2840 ---------------------------------
2841 -- Is_Static_String_Expression --
2842 ---------------------------------
2844 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2845 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2848 Analyze_And_Resolve (Argx);
2849 return Is_OK_Static_Expression (Argx)
2850 and then Nkind (Argx) = N_String_Literal;
2851 end Is_Static_String_Expression;
2853 ----------------------
2854 -- Pragma_Misplaced --
2855 ----------------------
2857 procedure Pragma_Misplaced is
2859 Error_Pragma ("incorrect placement of pragma%");
2860 end Pragma_Misplaced;
2862 ------------------------------------
2863 -- Process Atomic_Shared_Volatile --
2864 ------------------------------------
2866 procedure Process_Atomic_Shared_Volatile is
2873 procedure Set_Atomic (E : Entity_Id);
2874 -- Set given type as atomic, and if no explicit alignment was given,
2875 -- set alignment to unknown, since back end knows what the alignment
2876 -- requirements are for atomic arrays. Note: this step is necessary
2877 -- for derived types.
2883 procedure Set_Atomic (E : Entity_Id) is
2887 if not Has_Alignment_Clause (E) then
2888 Set_Alignment (E, Uint_0);
2892 -- Start of processing for Process_Atomic_Shared_Volatile
2895 Check_Ada_83_Warning;
2896 Check_No_Identifiers;
2897 Check_Arg_Count (1);
2898 Check_Arg_Is_Local_Name (Arg1);
2899 E_Id := Get_Pragma_Arg (Arg1);
2901 if Etype (E_Id) = Any_Type then
2906 D := Declaration_Node (E);
2909 -- Check duplicate before we chain ourselves!
2911 Check_Duplicate_Pragma (E);
2913 -- Now check appropriateness of the entity
2916 if Rep_Item_Too_Early (E, N)
2918 Rep_Item_Too_Late (E, N)
2922 Check_First_Subtype (Arg1);
2925 if Prag_Id /= Pragma_Volatile then
2927 Set_Atomic (Underlying_Type (E));
2928 Set_Atomic (Base_Type (E));
2931 -- Attribute belongs on the base type. If the view of the type is
2932 -- currently private, it also belongs on the underlying type.
2934 Set_Is_Volatile (Base_Type (E));
2935 Set_Is_Volatile (Underlying_Type (E));
2937 Set_Treat_As_Volatile (E);
2938 Set_Treat_As_Volatile (Underlying_Type (E));
2940 elsif K = N_Object_Declaration
2941 or else (K = N_Component_Declaration
2942 and then Original_Record_Component (E) = E)
2944 if Rep_Item_Too_Late (E, N) then
2948 if Prag_Id /= Pragma_Volatile then
2951 -- If the object declaration has an explicit initialization, a
2952 -- temporary may have to be created to hold the expression, to
2953 -- ensure that access to the object remain atomic.
2955 if Nkind (Parent (E)) = N_Object_Declaration
2956 and then Present (Expression (Parent (E)))
2958 Set_Has_Delayed_Freeze (E);
2961 -- An interesting improvement here. If an object of type X is
2962 -- declared atomic, and the type X is not atomic, that's a
2963 -- pity, since it may not have appropriate alignment etc. We
2964 -- can rescue this in the special case where the object and
2965 -- type are in the same unit by just setting the type as
2966 -- atomic, so that the back end will process it as atomic.
2968 Utyp := Underlying_Type (Etype (E));
2971 and then Sloc (E) > No_Location
2972 and then Sloc (Utyp) > No_Location
2974 Get_Source_File_Index (Sloc (E)) =
2975 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2977 Set_Is_Atomic (Underlying_Type (Etype (E)));
2981 Set_Is_Volatile (E);
2982 Set_Treat_As_Volatile (E);
2986 ("inappropriate entity for pragma%", Arg1);
2988 end Process_Atomic_Shared_Volatile;
2990 -------------------------------------------
2991 -- Process_Compile_Time_Warning_Or_Error --
2992 -------------------------------------------
2994 procedure Process_Compile_Time_Warning_Or_Error is
2995 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2998 Check_Arg_Count (2);
2999 Check_No_Identifiers;
3000 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3001 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3003 if Compile_Time_Known_Value (Arg1x) then
3004 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3006 Str : constant String_Id :=
3007 Strval (Get_Pragma_Arg (Arg2));
3008 Len : constant Int := String_Length (Str);
3013 Cent : constant Entity_Id :=
3014 Cunit_Entity (Current_Sem_Unit);
3016 Force : constant Boolean :=
3017 Prag_Id = Pragma_Compile_Time_Warning
3019 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3020 and then (Ekind (Cent) /= E_Package
3021 or else not In_Private_Part (Cent));
3022 -- Set True if this is the warning case, and we are in the
3023 -- visible part of a package spec, or in a subprogram spec,
3024 -- in which case we want to force the client to see the
3025 -- warning, even though it is not in the main unit.
3028 -- Loop through segments of message separated by line feeds.
3029 -- We output these segments as separate messages with
3030 -- continuation marks for all but the first.
3035 Error_Msg_Strlen := 0;
3037 -- Loop to copy characters from argument to error message
3041 exit when Ptr > Len;
3042 CC := Get_String_Char (Str, Ptr);
3045 -- Ignore wide chars ??? else store character
3047 if In_Character_Range (CC) then
3048 C := Get_Character (CC);
3049 exit when C = ASCII.LF;
3050 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3051 Error_Msg_String (Error_Msg_Strlen) := C;
3055 -- Here with one line ready to go
3057 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3059 -- If this is a warning in a spec, then we want clients
3060 -- to see the warning, so mark the message with the
3061 -- special sequence !! to force the warning. In the case
3062 -- of a package spec, we do not force this if we are in
3063 -- the private part of the spec.
3066 if Cont = False then
3067 Error_Msg_N ("<~!!", Arg1);
3070 Error_Msg_N ("\<~!!", Arg1);
3073 -- Error, rather than warning, or in a body, so we do not
3074 -- need to force visibility for client (error will be
3075 -- output in any case, and this is the situation in which
3076 -- we do not want a client to get a warning, since the
3077 -- warning is in the body or the spec private part).
3080 if Cont = False then
3081 Error_Msg_N ("<~", Arg1);
3084 Error_Msg_N ("\<~", Arg1);
3088 exit when Ptr > Len;
3093 end Process_Compile_Time_Warning_Or_Error;
3095 ------------------------
3096 -- Process_Convention --
3097 ------------------------
3099 procedure Process_Convention
3100 (C : out Convention_Id;
3101 Ent : out Entity_Id)
3107 Comp_Unit : Unit_Number_Type;
3109 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3110 -- Called if we have more than one Export/Import/Convention pragma.
3111 -- This is generally illegal, but we have a special case of allowing
3112 -- Import and Interface to coexist if they specify the convention in
3113 -- a consistent manner. We are allowed to do this, since Interface is
3114 -- an implementation defined pragma, and we choose to do it since we
3115 -- know Rational allows this combination. S is the entity id of the
3116 -- subprogram in question. This procedure also sets the special flag
3117 -- Import_Interface_Present in both pragmas in the case where we do
3118 -- have matching Import and Interface pragmas.
3120 procedure Set_Convention_From_Pragma (E : Entity_Id);
3121 -- Set convention in entity E, and also flag that the entity has a
3122 -- convention pragma. If entity is for a private or incomplete type,
3123 -- also set convention and flag on underlying type. This procedure
3124 -- also deals with the special case of C_Pass_By_Copy convention.
3126 -------------------------------
3127 -- Diagnose_Multiple_Pragmas --
3128 -------------------------------
3130 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3131 Pdec : constant Node_Id := Declaration_Node (S);
3135 function Same_Convention (Decl : Node_Id) return Boolean;
3136 -- Decl is a pragma node. This function returns True if this
3137 -- pragma has a first argument that is an identifier with a
3138 -- Chars field corresponding to the Convention_Id C.
3140 function Same_Name (Decl : Node_Id) return Boolean;
3141 -- Decl is a pragma node. This function returns True if this
3142 -- pragma has a second argument that is an identifier with a
3143 -- Chars field that matches the Chars of the current subprogram.
3145 ---------------------
3146 -- Same_Convention --
3147 ---------------------
3149 function Same_Convention (Decl : Node_Id) return Boolean is
3150 Arg1 : constant Node_Id :=
3151 First (Pragma_Argument_Associations (Decl));
3154 if Present (Arg1) then
3156 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3158 if Nkind (Arg) = N_Identifier
3159 and then Is_Convention_Name (Chars (Arg))
3160 and then Get_Convention_Id (Chars (Arg)) = C
3168 end Same_Convention;
3174 function Same_Name (Decl : Node_Id) return Boolean is
3175 Arg1 : constant Node_Id :=
3176 First (Pragma_Argument_Associations (Decl));
3184 Arg2 := Next (Arg1);
3191 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3193 if Nkind (Arg) = N_Identifier
3194 and then Chars (Arg) = Chars (S)
3203 -- Start of processing for Diagnose_Multiple_Pragmas
3208 -- Definitely give message if we have Convention/Export here
3210 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3213 -- If we have an Import or Export, scan back from pragma to
3214 -- find any previous pragma applying to the same procedure.
3215 -- The scan will be terminated by the start of the list, or
3216 -- hitting the subprogram declaration. This won't allow one
3217 -- pragma to appear in the public part and one in the private
3218 -- part, but that seems very unlikely in practice.
3222 while Present (Decl) and then Decl /= Pdec loop
3224 -- Look for pragma with same name as us
3226 if Nkind (Decl) = N_Pragma
3227 and then Same_Name (Decl)
3229 -- Give error if same as our pragma or Export/Convention
3231 if Pragma_Name (Decl) = Name_Export
3233 Pragma_Name (Decl) = Name_Convention
3235 Pragma_Name (Decl) = Pragma_Name (N)
3239 -- Case of Import/Interface or the other way round
3241 elsif Pragma_Name (Decl) = Name_Interface
3243 Pragma_Name (Decl) = Name_Import
3245 -- Here we know that we have Import and Interface. It
3246 -- doesn't matter which way round they are. See if
3247 -- they specify the same convention. If so, all OK,
3248 -- and set special flags to stop other messages
3250 if Same_Convention (Decl) then
3251 Set_Import_Interface_Present (N);
3252 Set_Import_Interface_Present (Decl);
3255 -- If different conventions, special message
3258 Error_Msg_Sloc := Sloc (Decl);
3260 ("convention differs from that given#", Arg1);
3270 -- Give message if needed if we fall through those tests
3274 ("at most one Convention/Export/Import pragma is allowed",
3277 end Diagnose_Multiple_Pragmas;
3279 --------------------------------
3280 -- Set_Convention_From_Pragma --
3281 --------------------------------
3283 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3285 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3286 -- for an overridden dispatching operation. Technically this is
3287 -- an amendment and should only be done in Ada 2005 mode. However,
3288 -- this is clearly a mistake, since the problem that is addressed
3289 -- by this AI is that there is a clear gap in the RM!
3291 if Is_Dispatching_Operation (E)
3292 and then Present (Overridden_Operation (E))
3293 and then C /= Convention (Overridden_Operation (E))
3296 ("cannot change convention for " &
3297 "overridden dispatching operation",
3301 -- Set the convention
3303 Set_Convention (E, C);
3304 Set_Has_Convention_Pragma (E);
3306 if Is_Incomplete_Or_Private_Type (E)
3307 and then Present (Underlying_Type (E))
3309 Set_Convention (Underlying_Type (E), C);
3310 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3313 -- A class-wide type should inherit the convention of the specific
3314 -- root type (although this isn't specified clearly by the RM).
3316 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3317 Set_Convention (Class_Wide_Type (E), C);
3320 -- If the entity is a record type, then check for special case of
3321 -- C_Pass_By_Copy, which is treated the same as C except that the
3322 -- special record flag is set. This convention is only permitted
3323 -- on record types (see AI95-00131).
3325 if Cname = Name_C_Pass_By_Copy then
3326 if Is_Record_Type (E) then
3327 Set_C_Pass_By_Copy (Base_Type (E));
3328 elsif Is_Incomplete_Or_Private_Type (E)
3329 and then Is_Record_Type (Underlying_Type (E))
3331 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3334 ("C_Pass_By_Copy convention allowed only for record type",
3339 -- If the entity is a derived boolean type, check for the special
3340 -- case of convention C, C++, or Fortran, where we consider any
3341 -- nonzero value to represent true.
3343 if Is_Discrete_Type (E)
3344 and then Root_Type (Etype (E)) = Standard_Boolean
3350 C = Convention_Fortran)
3352 Set_Nonzero_Is_True (Base_Type (E));
3354 end Set_Convention_From_Pragma;
3356 -- Start of processing for Process_Convention
3359 Check_At_Least_N_Arguments (2);
3360 Check_Optional_Identifier (Arg1, Name_Convention);
3361 Check_Arg_Is_Identifier (Arg1);
3362 Cname := Chars (Get_Pragma_Arg (Arg1));
3364 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3365 -- tested again below to set the critical flag).
3367 if Cname = Name_C_Pass_By_Copy then
3370 -- Otherwise we must have something in the standard convention list
3372 elsif Is_Convention_Name (Cname) then
3373 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3375 -- In DEC VMS, it seems that there is an undocumented feature that
3376 -- any unrecognized convention is treated as the default, which for
3377 -- us is convention C. It does not seem so terrible to do this
3378 -- unconditionally, silently in the VMS case, and with a warning
3379 -- in the non-VMS case.
3382 if Warn_On_Export_Import and not OpenVMS_On_Target then
3384 ("?unrecognized convention name, C assumed",
3385 Get_Pragma_Arg (Arg1));
3391 Check_Optional_Identifier (Arg2, Name_Entity);
3392 Check_Arg_Is_Local_Name (Arg2);
3394 Id := Get_Pragma_Arg (Arg2);
3397 if not Is_Entity_Name (Id) then
3398 Error_Pragma_Arg ("entity name required", Arg2);
3403 -- Set entity to return
3407 -- Ada_Pass_By_Copy special checking
3409 if C = Convention_Ada_Pass_By_Copy then
3410 if not Is_First_Subtype (E) then
3412 ("convention `Ada_Pass_By_Copy` only "
3413 & "allowed for types", Arg2);
3416 if Is_By_Reference_Type (E) then
3418 ("convention `Ada_Pass_By_Copy` not allowed for "
3419 & "by-reference type", Arg1);
3423 -- Ada_Pass_By_Reference special checking
3425 if C = Convention_Ada_Pass_By_Reference then
3426 if not Is_First_Subtype (E) then
3428 ("convention `Ada_Pass_By_Reference` only "
3429 & "allowed for types", Arg2);
3432 if Is_By_Copy_Type (E) then
3434 ("convention `Ada_Pass_By_Reference` not allowed for "
3435 & "by-copy type", Arg1);
3439 -- Go to renamed subprogram if present, since convention applies to
3440 -- the actual renamed entity, not to the renaming entity. If the
3441 -- subprogram is inherited, go to parent subprogram.
3443 if Is_Subprogram (E)
3444 and then Present (Alias (E))
3446 if Nkind (Parent (Declaration_Node (E))) =
3447 N_Subprogram_Renaming_Declaration
3449 if Scope (E) /= Scope (Alias (E)) then
3451 ("cannot apply pragma% to non-local entity&#", E);
3456 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3457 N_Private_Extension_Declaration)
3458 and then Scope (E) = Scope (Alias (E))
3462 -- Return the parent subprogram the entity was inherited from
3468 -- Check that we are not applying this to a specless body
3470 if Is_Subprogram (E)
3471 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3474 ("pragma% requires separate spec and must come before body");
3477 -- Check that we are not applying this to a named constant
3479 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3480 Error_Msg_Name_1 := Pname;
3482 ("cannot apply pragma% to named constant!",
3483 Get_Pragma_Arg (Arg2));
3485 ("\supply appropriate type for&!", Arg2);
3488 if Ekind (E) = E_Enumeration_Literal then
3489 Error_Pragma ("enumeration literal not allowed for pragma%");
3492 -- Check for rep item appearing too early or too late
3494 if Etype (E) = Any_Type
3495 or else Rep_Item_Too_Early (E, N)
3499 elsif Present (Underlying_Type (E)) then
3500 E := Underlying_Type (E);
3503 if Rep_Item_Too_Late (E, N) then
3507 if Has_Convention_Pragma (E) then
3508 Diagnose_Multiple_Pragmas (E);
3510 elsif Convention (E) = Convention_Protected
3511 or else Ekind (Scope (E)) = E_Protected_Type
3514 ("a protected operation cannot be given a different convention",
3518 -- For Intrinsic, a subprogram is required
3520 if C = Convention_Intrinsic
3521 and then not Is_Subprogram (E)
3522 and then not Is_Generic_Subprogram (E)
3525 ("second argument of pragma% must be a subprogram", Arg2);
3530 if C = Convention_Stdcall then
3532 -- A dispatching call is not allowed. A dispatching subprogram
3533 -- cannot be used to interface to the Win32 API, so in fact this
3534 -- check does not impose any effective restriction.
3536 if Is_Dispatching_Operation (E) then
3539 ("dispatching subprograms cannot use Stdcall convention");
3541 -- Subprogram is allowed, but not a generic subprogram, and not a
3542 -- dispatching operation.
3544 elsif not Is_Subprogram (E)
3545 and then not Is_Generic_Subprogram (E)
3549 and then Ekind (E) /= E_Variable
3551 -- An access to subprogram is also allowed
3555 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3558 ("second argument of pragma% must be subprogram (type)",
3563 if not Is_Subprogram (E)
3564 and then not Is_Generic_Subprogram (E)
3566 Set_Convention_From_Pragma (E);
3569 Check_First_Subtype (Arg2);
3570 Set_Convention_From_Pragma (Base_Type (E));
3572 -- For subprograms, we must set the convention on the
3573 -- internally generated directly designated type as well.
3575 if Ekind (E) = E_Access_Subprogram_Type then
3576 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3580 -- For the subprogram case, set proper convention for all homonyms
3581 -- in same scope and the same declarative part, i.e. the same
3582 -- compilation unit.
3585 Comp_Unit := Get_Source_Unit (E);
3586 Set_Convention_From_Pragma (E);
3588 -- Treat a pragma Import as an implicit body, for GPS use
3590 if Prag_Id = Pragma_Import then
3591 Generate_Reference (E, Id, 'b');
3594 -- Loop through the homonyms of the pragma argument's entity
3599 exit when No (E1) or else Scope (E1) /= Current_Scope;
3601 -- Do not set the pragma on inherited operations or on formal
3604 if Comes_From_Source (E1)
3605 and then Comp_Unit = Get_Source_Unit (E1)
3606 and then not Is_Formal_Subprogram (E1)
3607 and then Nkind (Original_Node (Parent (E1))) /=
3608 N_Full_Type_Declaration
3610 if Present (Alias (E1))
3611 and then Scope (E1) /= Scope (Alias (E1))
3614 ("cannot apply pragma% to non-local entity& declared#",
3618 Set_Convention_From_Pragma (E1);
3620 if Prag_Id = Pragma_Import then
3621 Generate_Reference (E1, Id, 'b');
3625 -- For aspect case, do NOT apply to homonyms
3627 exit when From_Aspect_Specification (N);
3630 end Process_Convention;
3632 ----------------------------------------
3633 -- Process_Disable_Enable_Atomic_Sync --
3634 ----------------------------------------
3636 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3639 Check_No_Identifiers;
3640 Check_At_Most_N_Arguments (1);
3642 -- Modeled internally as
3643 -- pragma Unsuppress (Atomic_Synchronization [,Entity])
3647 Pragma_Identifier =>
3648 Make_Identifier (Loc, Nam),
3649 Pragma_Argument_Associations => New_List (
3650 Make_Pragma_Argument_Association (Loc,
3652 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3654 if Present (Arg1) then
3655 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3659 end Process_Disable_Enable_Atomic_Sync;
3661 -----------------------------------------------------
3662 -- Process_Extended_Import_Export_Exception_Pragma --
3663 -----------------------------------------------------
3665 procedure Process_Extended_Import_Export_Exception_Pragma
3666 (Arg_Internal : Node_Id;
3667 Arg_External : Node_Id;
3675 if not OpenVMS_On_Target then
3677 ("?pragma% ignored (applies only to Open'V'M'S)");
3680 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3681 Def_Id := Entity (Arg_Internal);
3683 if Ekind (Def_Id) /= E_Exception then
3685 ("pragma% must refer to declared exception", Arg_Internal);
3688 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3690 if Present (Arg_Form) then
3691 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3694 if Present (Arg_Form)
3695 and then Chars (Arg_Form) = Name_Ada
3699 Set_Is_VMS_Exception (Def_Id);
3700 Set_Exception_Code (Def_Id, No_Uint);
3703 if Present (Arg_Code) then
3704 if not Is_VMS_Exception (Def_Id) then
3706 ("Code option for pragma% not allowed for Ada case",
3710 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3711 Code_Val := Expr_Value (Arg_Code);
3713 if not UI_Is_In_Int_Range (Code_Val) then
3715 ("Code option for pragma% must be in 32-bit range",
3719 Set_Exception_Code (Def_Id, Code_Val);
3722 end Process_Extended_Import_Export_Exception_Pragma;
3724 -------------------------------------------------
3725 -- Process_Extended_Import_Export_Internal_Arg --
3726 -------------------------------------------------
3728 procedure Process_Extended_Import_Export_Internal_Arg
3729 (Arg_Internal : Node_Id := Empty)
3732 if No (Arg_Internal) then
3733 Error_Pragma ("Internal parameter required for pragma%");
3736 if Nkind (Arg_Internal) = N_Identifier then
3739 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3740 and then (Prag_Id = Pragma_Import_Function
3742 Prag_Id = Pragma_Export_Function)
3748 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3751 Check_Arg_Is_Local_Name (Arg_Internal);
3752 end Process_Extended_Import_Export_Internal_Arg;
3754 --------------------------------------------------
3755 -- Process_Extended_Import_Export_Object_Pragma --
3756 --------------------------------------------------
3758 procedure Process_Extended_Import_Export_Object_Pragma
3759 (Arg_Internal : Node_Id;
3760 Arg_External : Node_Id;
3766 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3767 Def_Id := Entity (Arg_Internal);
3769 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3771 ("pragma% must designate an object", Arg_Internal);
3774 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3776 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3779 ("previous Common/Psect_Object applies, pragma % not permitted",
3783 if Rep_Item_Too_Late (Def_Id, N) then
3787 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3789 if Present (Arg_Size) then
3790 Check_Arg_Is_External_Name (Arg_Size);
3793 -- Export_Object case
3795 if Prag_Id = Pragma_Export_Object then
3796 if not Is_Library_Level_Entity (Def_Id) then
3798 ("argument for pragma% must be library level entity",
3802 if Ekind (Current_Scope) = E_Generic_Package then
3803 Error_Pragma ("pragma& cannot appear in a generic unit");
3806 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3808 ("exported object must have compile time known size",
3812 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3813 Error_Msg_N ("?duplicate Export_Object pragma", N);
3815 Set_Exported (Def_Id, Arg_Internal);
3818 -- Import_Object case
3821 if Is_Concurrent_Type (Etype (Def_Id)) then
3823 ("cannot use pragma% for task/protected object",
3827 if Ekind (Def_Id) = E_Constant then
3829 ("cannot import a constant", Arg_Internal);
3832 if Warn_On_Export_Import
3833 and then Has_Discriminants (Etype (Def_Id))
3836 ("imported value must be initialized?", Arg_Internal);
3839 if Warn_On_Export_Import
3840 and then Is_Access_Type (Etype (Def_Id))
3843 ("cannot import object of an access type?", Arg_Internal);
3846 if Warn_On_Export_Import
3847 and then Is_Imported (Def_Id)
3850 ("?duplicate Import_Object pragma", N);
3852 -- Check for explicit initialization present. Note that an
3853 -- initialization generated by the code generator, e.g. for an
3854 -- access type, does not count here.
3856 elsif Present (Expression (Parent (Def_Id)))
3859 (Original_Node (Expression (Parent (Def_Id))))
3861 Error_Msg_Sloc := Sloc (Def_Id);
3863 ("imported entities cannot be initialized (RM B.1(24))",
3864 "\no initialization allowed for & declared#", Arg1);
3866 Set_Imported (Def_Id);
3867 Note_Possible_Modification (Arg_Internal, Sure => False);
3870 end Process_Extended_Import_Export_Object_Pragma;
3872 ------------------------------------------------------
3873 -- Process_Extended_Import_Export_Subprogram_Pragma --
3874 ------------------------------------------------------
3876 procedure Process_Extended_Import_Export_Subprogram_Pragma
3877 (Arg_Internal : Node_Id;
3878 Arg_External : Node_Id;
3879 Arg_Parameter_Types : Node_Id;
3880 Arg_Result_Type : Node_Id := Empty;
3881 Arg_Mechanism : Node_Id;
3882 Arg_Result_Mechanism : Node_Id := Empty;
3883 Arg_First_Optional_Parameter : Node_Id := Empty)
3889 Ambiguous : Boolean;
3893 function Same_Base_Type
3895 Formal : Entity_Id) return Boolean;
3896 -- Determines if Ptype references the type of Formal. Note that only
3897 -- the base types need to match according to the spec. Ptype here is
3898 -- the argument from the pragma, which is either a type name, or an
3899 -- access attribute.
3901 --------------------
3902 -- Same_Base_Type --
3903 --------------------
3905 function Same_Base_Type
3907 Formal : Entity_Id) return Boolean
3909 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3913 -- Case where pragma argument is typ'Access
3915 if Nkind (Ptype) = N_Attribute_Reference
3916 and then Attribute_Name (Ptype) = Name_Access
3918 Pref := Prefix (Ptype);
3921 if not Is_Entity_Name (Pref)
3922 or else Entity (Pref) = Any_Type
3927 -- We have a match if the corresponding argument is of an
3928 -- anonymous access type, and its designated type matches the
3929 -- type of the prefix of the access attribute
3931 return Ekind (Ftyp) = E_Anonymous_Access_Type
3932 and then Base_Type (Entity (Pref)) =
3933 Base_Type (Etype (Designated_Type (Ftyp)));
3935 -- Case where pragma argument is a type name
3940 if not Is_Entity_Name (Ptype)
3941 or else Entity (Ptype) = Any_Type
3946 -- We have a match if the corresponding argument is of the type
3947 -- given in the pragma (comparing base types)
3949 return Base_Type (Entity (Ptype)) = Ftyp;
3953 -- Start of processing for
3954 -- Process_Extended_Import_Export_Subprogram_Pragma
3957 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3961 -- Loop through homonyms (overloadings) of the entity
3963 Hom_Id := Entity (Arg_Internal);
3964 while Present (Hom_Id) loop
3965 Def_Id := Get_Base_Subprogram (Hom_Id);
3967 -- We need a subprogram in the current scope
3969 if not Is_Subprogram (Def_Id)
3970 or else Scope (Def_Id) /= Current_Scope
3977 -- Pragma cannot apply to subprogram body
3979 if Is_Subprogram (Def_Id)
3980 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3984 ("pragma% requires separate spec"
3985 & " and must come before body");
3988 -- Test result type if given, note that the result type
3989 -- parameter can only be present for the function cases.
3991 if Present (Arg_Result_Type)
3992 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3996 elsif Etype (Def_Id) /= Standard_Void_Type
3998 (Pname = Name_Export_Procedure
4000 Pname = Name_Import_Procedure)
4004 -- Test parameter types if given. Note that this parameter
4005 -- has not been analyzed (and must not be, since it is
4006 -- semantic nonsense), so we get it as the parser left it.
4008 elsif Present (Arg_Parameter_Types) then
4009 Check_Matching_Types : declare
4014 Formal := First_Formal (Def_Id);
4016 if Nkind (Arg_Parameter_Types) = N_Null then
4017 if Present (Formal) then
4021 -- A list of one type, e.g. (List) is parsed as
4022 -- a parenthesized expression.
4024 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4025 and then Paren_Count (Arg_Parameter_Types) = 1
4028 or else Present (Next_Formal (Formal))
4033 Same_Base_Type (Arg_Parameter_Types, Formal);
4036 -- A list of more than one type is parsed as a aggregate
4038 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4039 and then Paren_Count (Arg_Parameter_Types) = 0
4041 Ptype := First (Expressions (Arg_Parameter_Types));
4042 while Present (Ptype) or else Present (Formal) loop
4045 or else not Same_Base_Type (Ptype, Formal)
4050 Next_Formal (Formal);
4055 -- Anything else is of the wrong form
4059 ("wrong form for Parameter_Types parameter",
4060 Arg_Parameter_Types);
4062 end Check_Matching_Types;
4065 -- Match is now False if the entry we found did not match
4066 -- either a supplied Parameter_Types or Result_Types argument
4072 -- Ambiguous case, the flag Ambiguous shows if we already
4073 -- detected this and output the initial messages.
4076 if not Ambiguous then
4078 Error_Msg_Name_1 := Pname;
4080 ("pragma% does not uniquely identify subprogram!",
4082 Error_Msg_Sloc := Sloc (Ent);
4083 Error_Msg_N ("matching subprogram #!", N);
4087 Error_Msg_Sloc := Sloc (Def_Id);
4088 Error_Msg_N ("matching subprogram #!", N);
4093 Hom_Id := Homonym (Hom_Id);
4096 -- See if we found an entry
4099 if not Ambiguous then
4100 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4102 ("pragma% cannot be given for generic subprogram");
4105 ("pragma% does not identify local subprogram");
4112 -- Import pragmas must be for imported entities
4114 if Prag_Id = Pragma_Import_Function
4116 Prag_Id = Pragma_Import_Procedure
4118 Prag_Id = Pragma_Import_Valued_Procedure
4120 if not Is_Imported (Ent) then
4122 ("pragma Import or Interface must precede pragma%");
4125 -- Here we have the Export case which can set the entity as exported
4127 -- But does not do so if the specified external name is null, since
4128 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4129 -- compatible) to request no external name.
4131 elsif Nkind (Arg_External) = N_String_Literal
4132 and then String_Length (Strval (Arg_External)) = 0
4136 -- In all other cases, set entity as exported
4139 Set_Exported (Ent, Arg_Internal);
4142 -- Special processing for Valued_Procedure cases
4144 if Prag_Id = Pragma_Import_Valued_Procedure
4146 Prag_Id = Pragma_Export_Valued_Procedure
4148 Formal := First_Formal (Ent);
4151 Error_Pragma ("at least one parameter required for pragma%");
4153 elsif Ekind (Formal) /= E_Out_Parameter then
4154 Error_Pragma ("first parameter must have mode out for pragma%");
4157 Set_Is_Valued_Procedure (Ent);
4161 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4163 -- Process Result_Mechanism argument if present. We have already
4164 -- checked that this is only allowed for the function case.
4166 if Present (Arg_Result_Mechanism) then
4167 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4170 -- Process Mechanism parameter if present. Note that this parameter
4171 -- is not analyzed, and must not be analyzed since it is semantic
4172 -- nonsense, so we get it in exactly as the parser left it.
4174 if Present (Arg_Mechanism) then
4182 -- A single mechanism association without a formal parameter
4183 -- name is parsed as a parenthesized expression. All other
4184 -- cases are parsed as aggregates, so we rewrite the single
4185 -- parameter case as an aggregate for consistency.
4187 if Nkind (Arg_Mechanism) /= N_Aggregate
4188 and then Paren_Count (Arg_Mechanism) = 1
4190 Rewrite (Arg_Mechanism,
4191 Make_Aggregate (Sloc (Arg_Mechanism),
4192 Expressions => New_List (
4193 Relocate_Node (Arg_Mechanism))));
4196 -- Case of only mechanism name given, applies to all formals
4198 if Nkind (Arg_Mechanism) /= N_Aggregate then
4199 Formal := First_Formal (Ent);
4200 while Present (Formal) loop
4201 Set_Mechanism_Value (Formal, Arg_Mechanism);
4202 Next_Formal (Formal);
4205 -- Case of list of mechanism associations given
4208 if Null_Record_Present (Arg_Mechanism) then
4210 ("inappropriate form for Mechanism parameter",
4214 -- Deal with positional ones first
4216 Formal := First_Formal (Ent);
4218 if Present (Expressions (Arg_Mechanism)) then
4219 Mname := First (Expressions (Arg_Mechanism));
4220 while Present (Mname) loop
4223 ("too many mechanism associations", Mname);
4226 Set_Mechanism_Value (Formal, Mname);
4227 Next_Formal (Formal);
4232 -- Deal with named entries
4234 if Present (Component_Associations (Arg_Mechanism)) then
4235 Massoc := First (Component_Associations (Arg_Mechanism));
4236 while Present (Massoc) loop
4237 Choice := First (Choices (Massoc));
4239 if Nkind (Choice) /= N_Identifier
4240 or else Present (Next (Choice))
4243 ("incorrect form for mechanism association",
4247 Formal := First_Formal (Ent);
4251 ("parameter name & not present", Choice);
4254 if Chars (Choice) = Chars (Formal) then
4256 (Formal, Expression (Massoc));
4258 -- Set entity on identifier (needed by ASIS)
4260 Set_Entity (Choice, Formal);
4265 Next_Formal (Formal);
4275 -- Process First_Optional_Parameter argument if present. We have
4276 -- already checked that this is only allowed for the Import case.
4278 if Present (Arg_First_Optional_Parameter) then
4279 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4281 ("first optional parameter must be formal parameter name",
4282 Arg_First_Optional_Parameter);
4285 Formal := First_Formal (Ent);
4289 ("specified formal parameter& not found",
4290 Arg_First_Optional_Parameter);
4293 exit when Chars (Formal) =
4294 Chars (Arg_First_Optional_Parameter);
4296 Next_Formal (Formal);
4299 Set_First_Optional_Parameter (Ent, Formal);
4301 -- Check specified and all remaining formals have right form
4303 while Present (Formal) loop
4304 if Ekind (Formal) /= E_In_Parameter then
4306 ("optional formal& is not of mode in!",
4307 Arg_First_Optional_Parameter, Formal);
4310 Dval := Default_Value (Formal);
4314 ("optional formal& does not have default value!",
4315 Arg_First_Optional_Parameter, Formal);
4317 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4322 ("default value for optional formal& is non-static!",
4323 Arg_First_Optional_Parameter, Formal);
4327 Set_Is_Optional_Parameter (Formal);
4328 Next_Formal (Formal);
4331 end Process_Extended_Import_Export_Subprogram_Pragma;
4333 --------------------------
4334 -- Process_Generic_List --
4335 --------------------------
4337 procedure Process_Generic_List is
4342 Check_No_Identifiers;
4343 Check_At_Least_N_Arguments (1);
4346 while Present (Arg) loop
4347 Exp := Get_Pragma_Arg (Arg);
4350 if not Is_Entity_Name (Exp)
4352 (not Is_Generic_Instance (Entity (Exp))
4354 not Is_Generic_Unit (Entity (Exp)))
4357 ("pragma% argument must be name of generic unit/instance",
4363 end Process_Generic_List;
4365 ------------------------------------
4366 -- Process_Import_Predefined_Type --
4367 ------------------------------------
4369 procedure Process_Import_Predefined_Type is
4370 Loc : constant Source_Ptr := Sloc (N);
4372 Ftyp : Node_Id := Empty;
4378 String_To_Name_Buffer (Strval (Expression (Arg3)));
4381 Elmt := First_Elmt (Predefined_Float_Types);
4382 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4386 Ftyp := Node (Elmt);
4388 if Present (Ftyp) then
4390 -- Don't build a derived type declaration, because predefined C
4391 -- types have no declaration anywhere, so cannot really be named.
4392 -- Instead build a full type declaration, starting with an
4393 -- appropriate type definition is built
4395 if Is_Floating_Point_Type (Ftyp) then
4396 Def := Make_Floating_Point_Definition (Loc,
4397 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4398 Make_Real_Range_Specification (Loc,
4399 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4400 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4402 -- Should never have a predefined type we cannot handle
4405 raise Program_Error;
4408 -- Build and insert a Full_Type_Declaration, which will be
4409 -- analyzed as soon as this list entry has been analyzed.
4411 Decl := Make_Full_Type_Declaration (Loc,
4412 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4413 Type_Definition => Def);
4415 Insert_After (N, Decl);
4416 Mark_Rewrite_Insertion (Decl);
4419 Error_Pragma_Arg ("no matching type found for pragma%",
4422 end Process_Import_Predefined_Type;
4424 ---------------------------------
4425 -- Process_Import_Or_Interface --
4426 ---------------------------------
4428 procedure Process_Import_Or_Interface is
4434 Process_Convention (C, Def_Id);
4435 Kill_Size_Check_Code (Def_Id);
4436 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4438 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4440 -- We do not permit Import to apply to a renaming declaration
4442 if Present (Renamed_Object (Def_Id)) then
4444 ("pragma% not allowed for object renaming", Arg2);
4446 -- User initialization is not allowed for imported object, but
4447 -- the object declaration may contain a default initialization,
4448 -- that will be discarded. Note that an explicit initialization
4449 -- only counts if it comes from source, otherwise it is simply
4450 -- the code generator making an implicit initialization explicit.
4452 elsif Present (Expression (Parent (Def_Id)))
4453 and then Comes_From_Source (Expression (Parent (Def_Id)))
4455 Error_Msg_Sloc := Sloc (Def_Id);
4457 ("no initialization allowed for declaration of& #",
4458 "\imported entities cannot be initialized (RM B.1(24))",
4462 Set_Imported (Def_Id);
4463 Process_Interface_Name (Def_Id, Arg3, Arg4);
4465 -- Note that we do not set Is_Public here. That's because we
4466 -- only want to set it if there is no address clause, and we
4467 -- don't know that yet, so we delay that processing till
4470 -- pragma Import completes deferred constants
4472 if Ekind (Def_Id) = E_Constant then
4473 Set_Has_Completion (Def_Id);
4476 -- It is not possible to import a constant of an unconstrained
4477 -- array type (e.g. string) because there is no simple way to
4478 -- write a meaningful subtype for it.
4480 if Is_Array_Type (Etype (Def_Id))
4481 and then not Is_Constrained (Etype (Def_Id))
4484 ("imported constant& must have a constrained subtype",
4489 elsif Is_Subprogram (Def_Id)
4490 or else Is_Generic_Subprogram (Def_Id)
4492 -- If the name is overloaded, pragma applies to all of the denoted
4493 -- entities in the same declarative part.
4496 while Present (Hom_Id) loop
4497 Def_Id := Get_Base_Subprogram (Hom_Id);
4499 -- Ignore inherited subprograms because the pragma will apply
4500 -- to the parent operation, which is the one called.
4502 if Is_Overloadable (Def_Id)
4503 and then Present (Alias (Def_Id))
4507 -- If it is not a subprogram, it must be in an outer scope and
4508 -- pragma does not apply.
4510 elsif not Is_Subprogram (Def_Id)
4511 and then not Is_Generic_Subprogram (Def_Id)
4515 -- The pragma does not apply to primitives of interfaces
4517 elsif Is_Dispatching_Operation (Def_Id)
4518 and then Present (Find_Dispatching_Type (Def_Id))
4519 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4523 -- Verify that the homonym is in the same declarative part (not
4524 -- just the same scope).
4526 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4527 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4532 Set_Imported (Def_Id);
4534 -- Reject an Import applied to an abstract subprogram
4536 if Is_Subprogram (Def_Id)
4537 and then Is_Abstract_Subprogram (Def_Id)
4539 Error_Msg_Sloc := Sloc (Def_Id);
4541 ("cannot import abstract subprogram& declared#",
4545 -- Special processing for Convention_Intrinsic
4547 if C = Convention_Intrinsic then
4549 -- Link_Name argument not allowed for intrinsic
4553 Set_Is_Intrinsic_Subprogram (Def_Id);
4555 -- If no external name is present, then check that this
4556 -- is a valid intrinsic subprogram. If an external name
4557 -- is present, then this is handled by the back end.
4560 Check_Intrinsic_Subprogram
4561 (Def_Id, Get_Pragma_Arg (Arg2));
4565 -- All interfaced procedures need an external symbol created
4566 -- for them since they are always referenced from another
4569 Set_Is_Public (Def_Id);
4571 -- Verify that the subprogram does not have a completion
4572 -- through a renaming declaration. For other completions the
4573 -- pragma appears as a too late representation.
4576 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4580 and then Nkind (Decl) = N_Subprogram_Declaration
4581 and then Present (Corresponding_Body (Decl))
4582 and then Nkind (Unit_Declaration_Node
4583 (Corresponding_Body (Decl))) =
4584 N_Subprogram_Renaming_Declaration
4586 Error_Msg_Sloc := Sloc (Def_Id);
4588 ("cannot import&, renaming already provided for " &
4589 "declaration #", N, Def_Id);
4593 Set_Has_Completion (Def_Id);
4594 Process_Interface_Name (Def_Id, Arg3, Arg4);
4597 if Is_Compilation_Unit (Hom_Id) then
4599 -- Its possible homonyms are not affected by the pragma.
4600 -- Such homonyms might be present in the context of other
4601 -- units being compiled.
4606 Hom_Id := Homonym (Hom_Id);
4610 -- When the convention is Java or CIL, we also allow Import to be
4611 -- given for packages, generic packages, exceptions, record
4612 -- components, and access to subprograms.
4614 elsif (C = Convention_Java or else C = Convention_CIL)
4616 (Is_Package_Or_Generic_Package (Def_Id)
4617 or else Ekind (Def_Id) = E_Exception
4618 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4619 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4621 Set_Imported (Def_Id);
4622 Set_Is_Public (Def_Id);
4623 Process_Interface_Name (Def_Id, Arg3, Arg4);
4625 -- Import a CPP class
4627 elsif C = Convention_CPP
4628 and then (Is_Record_Type (Def_Id)
4629 or else Ekind (Def_Id) = E_Incomplete_Type)
4631 if Ekind (Def_Id) = E_Incomplete_Type then
4632 if Present (Full_View (Def_Id)) then
4633 Def_Id := Full_View (Def_Id);
4637 ("cannot import 'C'P'P type before full declaration seen",
4638 Get_Pragma_Arg (Arg2));
4640 -- Although we have reported the error we decorate it as
4641 -- CPP_Class to avoid reporting spurious errors
4643 Set_Is_CPP_Class (Def_Id);
4648 -- Types treated as CPP classes must be declared limited (note:
4649 -- this used to be a warning but there is no real benefit to it
4650 -- since we did effectively intend to treat the type as limited
4653 if not Is_Limited_Type (Def_Id) then
4655 ("imported 'C'P'P type must be limited",
4656 Get_Pragma_Arg (Arg2));
4659 Set_Is_CPP_Class (Def_Id);
4661 -- Imported CPP types must not have discriminants (because C++
4662 -- classes do not have discriminants).
4664 if Has_Discriminants (Def_Id) then
4666 ("imported 'C'P'P type cannot have discriminants",
4667 First (Discriminant_Specifications
4668 (Declaration_Node (Def_Id))));
4671 -- Check that components of imported CPP types do not have default
4672 -- expressions. For private types this check is performed when the
4673 -- full view is analyzed (see Process_Full_View).
4675 if not Is_Private_Type (Def_Id) then
4676 Check_CPP_Type_Has_No_Defaults (Def_Id);
4679 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4681 Check_Arg_Count (3);
4682 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4684 Process_Import_Predefined_Type;
4688 ("second argument of pragma% must be object, subprogram "
4689 & "or incomplete type",
4693 -- If this pragma applies to a compilation unit, then the unit, which
4694 -- is a subprogram, does not require (or allow) a body. We also do
4695 -- not need to elaborate imported procedures.
4697 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4699 Cunit : constant Node_Id := Parent (Parent (N));
4701 Set_Body_Required (Cunit, False);
4704 end Process_Import_Or_Interface;
4706 --------------------
4707 -- Process_Inline --
4708 --------------------
4710 procedure Process_Inline (Active : Boolean) is
4717 Effective : Boolean := False;
4718 -- Set True if inline has some effect, i.e. if there is at least one
4719 -- subprogram set as inlined as a result of the use of the pragma.
4721 procedure Make_Inline (Subp : Entity_Id);
4722 -- Subp is the defining unit name of the subprogram declaration. Set
4723 -- the flag, as well as the flag in the corresponding body, if there
4726 procedure Set_Inline_Flags (Subp : Entity_Id);
4727 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4728 -- Has_Pragma_Inline_Always for the Inline_Always case.
4730 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4731 -- Returns True if it can be determined at this stage that inlining
4732 -- is not possible, for example if the body is available and contains
4733 -- exception handlers, we prevent inlining, since otherwise we can
4734 -- get undefined symbols at link time. This function also emits a
4735 -- warning if front-end inlining is enabled and the pragma appears
4738 -- ??? is business with link symbols still valid, or does it relate
4739 -- to front end ZCX which is being phased out ???
4741 ---------------------------
4742 -- Inlining_Not_Possible --
4743 ---------------------------
4745 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4746 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4750 if Nkind (Decl) = N_Subprogram_Body then
4751 Stats := Handled_Statement_Sequence (Decl);
4752 return Present (Exception_Handlers (Stats))
4753 or else Present (At_End_Proc (Stats));
4755 elsif Nkind (Decl) = N_Subprogram_Declaration
4756 and then Present (Corresponding_Body (Decl))
4758 if Front_End_Inlining
4759 and then Analyzed (Corresponding_Body (Decl))
4761 Error_Msg_N ("pragma appears too late, ignored?", N);
4764 -- If the subprogram is a renaming as body, the body is just a
4765 -- call to the renamed subprogram, and inlining is trivially
4769 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4770 N_Subprogram_Renaming_Declaration
4776 Handled_Statement_Sequence
4777 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4780 Present (Exception_Handlers (Stats))
4781 or else Present (At_End_Proc (Stats));
4785 -- If body is not available, assume the best, the check is
4786 -- performed again when compiling enclosing package bodies.
4790 end Inlining_Not_Possible;
4796 procedure Make_Inline (Subp : Entity_Id) is
4797 Kind : constant Entity_Kind := Ekind (Subp);
4798 Inner_Subp : Entity_Id := Subp;
4801 -- Ignore if bad type, avoid cascaded error
4803 if Etype (Subp) = Any_Type then
4807 -- Ignore if all inlining is suppressed
4809 elsif Suppress_All_Inlining then
4813 -- If inlining is not possible, for now do not treat as an error
4815 elsif Inlining_Not_Possible (Subp) then
4819 -- Here we have a candidate for inlining, but we must exclude
4820 -- derived operations. Otherwise we would end up trying to inline
4821 -- a phantom declaration, and the result would be to drag in a
4822 -- body which has no direct inlining associated with it. That
4823 -- would not only be inefficient but would also result in the
4824 -- backend doing cross-unit inlining in cases where it was
4825 -- definitely inappropriate to do so.
4827 -- However, a simple Comes_From_Source test is insufficient, since
4828 -- we do want to allow inlining of generic instances which also do
4829 -- not come from source. We also need to recognize specs generated
4830 -- by the front-end for bodies that carry the pragma. Finally,
4831 -- predefined operators do not come from source but are not
4832 -- inlineable either.
4834 elsif Is_Generic_Instance (Subp)
4835 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4839 elsif not Comes_From_Source (Subp)
4840 and then Scope (Subp) /= Standard_Standard
4846 -- The referenced entity must either be the enclosing entity, or
4847 -- an entity declared within the current open scope.
4849 if Present (Scope (Subp))
4850 and then Scope (Subp) /= Current_Scope
4851 and then Subp /= Current_Scope
4854 ("argument of% must be entity in current scope", Assoc);
4858 -- Processing for procedure, operator or function. If subprogram
4859 -- is aliased (as for an instance) indicate that the renamed
4860 -- entity (if declared in the same unit) is inlined.
4862 if Is_Subprogram (Subp) then
4863 Inner_Subp := Ultimate_Alias (Inner_Subp);
4865 if In_Same_Source_Unit (Subp, Inner_Subp) then
4866 Set_Inline_Flags (Inner_Subp);
4868 Decl := Parent (Parent (Inner_Subp));
4870 if Nkind (Decl) = N_Subprogram_Declaration
4871 and then Present (Corresponding_Body (Decl))
4873 Set_Inline_Flags (Corresponding_Body (Decl));
4875 elsif Is_Generic_Instance (Subp) then
4877 -- Indicate that the body needs to be created for
4878 -- inlining subsequent calls. The instantiation node
4879 -- follows the declaration of the wrapper package
4882 if Scope (Subp) /= Standard_Standard
4884 Need_Subprogram_Instance_Body
4885 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4891 -- Inline is a program unit pragma (RM 10.1.5) and cannot
4892 -- appear in a formal part to apply to a formal subprogram.
4893 -- Do not apply check within an instance or a formal package
4894 -- the test will have been applied to the original generic.
4896 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4897 and then List_Containing (Decl) = List_Containing (N)
4898 and then not In_Instance
4901 ("Inline cannot apply to a formal subprogram", N);
4907 -- For a generic subprogram set flag as well, for use at the point
4908 -- of instantiation, to determine whether the body should be
4911 elsif Is_Generic_Subprogram (Subp) then
4912 Set_Inline_Flags (Subp);
4915 -- Literals are by definition inlined
4917 elsif Kind = E_Enumeration_Literal then
4920 -- Anything else is an error
4924 ("expect subprogram name for pragma%", Assoc);
4928 ----------------------
4929 -- Set_Inline_Flags --
4930 ----------------------
4932 procedure Set_Inline_Flags (Subp : Entity_Id) is
4935 Set_Is_Inlined (Subp);
4938 if not Has_Pragma_Inline (Subp) then
4939 Set_Has_Pragma_Inline (Subp);
4943 if Prag_Id = Pragma_Inline_Always then
4944 Set_Has_Pragma_Inline_Always (Subp);
4946 end Set_Inline_Flags;
4948 -- Start of processing for Process_Inline
4951 Check_No_Identifiers;
4952 Check_At_Least_N_Arguments (1);
4955 Inline_Processing_Required := True;
4959 while Present (Assoc) loop
4960 Subp_Id := Get_Pragma_Arg (Assoc);
4964 if Is_Entity_Name (Subp_Id) then
4965 Subp := Entity (Subp_Id);
4967 if Subp = Any_Id then
4969 -- If previous error, avoid cascaded errors
4977 -- For the pragma case, climb homonym chain. This is
4978 -- what implements allowing the pragma in the renaming
4979 -- case, with the result applying to the ancestors, and
4980 -- also allows Inline to apply to all previous homonyms.
4982 if not From_Aspect_Specification (N) then
4983 while Present (Homonym (Subp))
4984 and then Scope (Homonym (Subp)) = Current_Scope
4986 Make_Inline (Homonym (Subp));
4987 Subp := Homonym (Subp);
4995 ("inappropriate argument for pragma%", Assoc);
4998 and then Warn_On_Redundant_Constructs
4999 and then not Suppress_All_Inlining
5001 if Inlining_Not_Possible (Subp) then
5003 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
5006 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
5014 ----------------------------
5015 -- Process_Interface_Name --
5016 ----------------------------
5018 procedure Process_Interface_Name
5019 (Subprogram_Def : Entity_Id;
5025 String_Val : String_Id;
5027 procedure Check_Form_Of_Interface_Name
5029 Ext_Name_Case : Boolean);
5030 -- SN is a string literal node for an interface name. This routine
5031 -- performs some minimal checks that the name is reasonable. In
5032 -- particular that no spaces or other obviously incorrect characters
5033 -- appear. This is only a warning, since any characters are allowed.
5034 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5036 ----------------------------------
5037 -- Check_Form_Of_Interface_Name --
5038 ----------------------------------
5040 procedure Check_Form_Of_Interface_Name
5042 Ext_Name_Case : Boolean)
5044 S : constant String_Id := Strval (Expr_Value_S (SN));
5045 SL : constant Nat := String_Length (S);
5050 Error_Msg_N ("interface name cannot be null string", SN);
5053 for J in 1 .. SL loop
5054 C := Get_String_Char (S, J);
5056 -- Look for dubious character and issue unconditional warning.
5057 -- Definitely dubious if not in character range.
5059 if not In_Character_Range (C)
5061 -- For all cases except CLI target,
5062 -- commas, spaces and slashes are dubious (in CLI, we use
5063 -- commas and backslashes in external names to specify
5064 -- assembly version and public key, while slashes and spaces
5065 -- can be used in names to mark nested classes and
5068 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5069 and then (Get_Character (C) = ','
5071 Get_Character (C) = '\'))
5072 or else (VM_Target /= CLI_Target
5073 and then (Get_Character (C) = ' '
5075 Get_Character (C) = '/'))
5078 ("?interface name contains illegal character",
5079 Sloc (SN) + Source_Ptr (J));
5082 end Check_Form_Of_Interface_Name;
5084 -- Start of processing for Process_Interface_Name
5087 if No (Link_Arg) then
5088 if No (Ext_Arg) then
5089 if VM_Target = CLI_Target
5090 and then Ekind (Subprogram_Def) = E_Package
5091 and then Nkind (Parent (Subprogram_Def)) =
5092 N_Package_Specification
5093 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5098 (Generic_Parent (Parent (Subprogram_Def))));
5103 elsif Chars (Ext_Arg) = Name_Link_Name then
5105 Link_Nam := Expression (Ext_Arg);
5108 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5109 Ext_Nam := Expression (Ext_Arg);
5114 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5115 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5116 Ext_Nam := Expression (Ext_Arg);
5117 Link_Nam := Expression (Link_Arg);
5120 -- Check expressions for external name and link name are static
5122 if Present (Ext_Nam) then
5123 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5124 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5126 -- Verify that external name is not the name of a local entity,
5127 -- which would hide the imported one and could lead to run-time
5128 -- surprises. The problem can only arise for entities declared in
5129 -- a package body (otherwise the external name is fully qualified
5130 -- and will not conflict).
5138 if Prag_Id = Pragma_Import then
5139 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5141 E := Entity_Id (Get_Name_Table_Info (Nam));
5143 if Nam /= Chars (Subprogram_Def)
5144 and then Present (E)
5145 and then not Is_Overloadable (E)
5146 and then Is_Immediately_Visible (E)
5147 and then not Is_Imported (E)
5148 and then Ekind (Scope (E)) = E_Package
5151 while Present (Par) loop
5152 if Nkind (Par) = N_Package_Body then
5153 Error_Msg_Sloc := Sloc (E);
5155 ("imported entity is hidden by & declared#",
5160 Par := Parent (Par);
5167 if Present (Link_Nam) then
5168 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5169 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5172 -- If there is no link name, just set the external name
5174 if No (Link_Nam) then
5175 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5177 -- For the Link_Name case, the given literal is preceded by an
5178 -- asterisk, which indicates to GCC that the given name should be
5179 -- taken literally, and in particular that no prepending of
5180 -- underlines should occur, even in systems where this is the
5186 if VM_Target = No_VM then
5187 Store_String_Char (Get_Char_Code ('*'));
5190 String_Val := Strval (Expr_Value_S (Link_Nam));
5191 Store_String_Chars (String_Val);
5193 Make_String_Literal (Sloc (Link_Nam),
5194 Strval => End_String);
5197 -- Set the interface name. If the entity is a generic instance, use
5198 -- its alias, which is the callable entity.
5200 if Is_Generic_Instance (Subprogram_Def) then
5201 Set_Encoded_Interface_Name
5202 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5204 Set_Encoded_Interface_Name
5205 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5208 -- We allow duplicated export names in CIL/Java, as they are always
5209 -- enclosed in a namespace that differentiates them, and overloaded
5210 -- entities are supported by the VM.
5212 if Convention (Subprogram_Def) /= Convention_CIL
5214 Convention (Subprogram_Def) /= Convention_Java
5216 Check_Duplicated_Export_Name (Link_Nam);
5218 end Process_Interface_Name;
5220 -----------------------------------------
5221 -- Process_Interrupt_Or_Attach_Handler --
5222 -----------------------------------------
5224 procedure Process_Interrupt_Or_Attach_Handler is
5225 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5226 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5227 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5230 Set_Is_Interrupt_Handler (Handler_Proc);
5232 -- If the pragma is not associated with a handler procedure within a
5233 -- protected type, then it must be for a nonprotected procedure for
5234 -- the AAMP target, in which case we don't associate a representation
5235 -- item with the procedure's scope.
5237 if Ekind (Proc_Scope) = E_Protected_Type then
5238 if Prag_Id = Pragma_Interrupt_Handler
5240 Prag_Id = Pragma_Attach_Handler
5242 Record_Rep_Item (Proc_Scope, N);
5245 end Process_Interrupt_Or_Attach_Handler;
5247 --------------------------------------------------
5248 -- Process_Restrictions_Or_Restriction_Warnings --
5249 --------------------------------------------------
5251 -- Note: some of the simple identifier cases were handled in par-prag,
5252 -- but it is harmless (and more straightforward) to simply handle all
5253 -- cases here, even if it means we repeat a bit of work in some cases.
5255 procedure Process_Restrictions_Or_Restriction_Warnings
5259 R_Id : Restriction_Id;
5264 procedure Check_Unit_Name (N : Node_Id);
5265 -- Checks unit name parameter for No_Dependence. Returns if it has
5266 -- an appropriate form, otherwise raises pragma argument error.
5268 ---------------------
5269 -- Check_Unit_Name --
5270 ---------------------
5272 procedure Check_Unit_Name (N : Node_Id) is
5274 if Nkind (N) = N_Selected_Component then
5275 Check_Unit_Name (Prefix (N));
5276 Check_Unit_Name (Selector_Name (N));
5278 elsif Nkind (N) = N_Identifier then
5283 ("wrong form for unit name for No_Dependence", N);
5285 end Check_Unit_Name;
5287 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5290 -- Ignore all Restrictions pragma in CodePeer mode
5292 if CodePeer_Mode then
5296 Check_Ada_83_Warning;
5297 Check_At_Least_N_Arguments (1);
5298 Check_Valid_Configuration_Pragma;
5301 while Present (Arg) loop
5303 Expr := Get_Pragma_Arg (Arg);
5305 -- Case of no restriction identifier present
5307 if Id = No_Name then
5308 if Nkind (Expr) /= N_Identifier then
5310 ("invalid form for restriction", Arg);
5315 (Process_Restriction_Synonyms (Expr));
5317 if R_Id not in All_Boolean_Restrictions then
5318 Error_Msg_Name_1 := Pname;
5320 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5322 -- Check for possible misspelling
5324 for J in Restriction_Id loop
5326 Rnm : constant String := Restriction_Id'Image (J);
5329 Name_Buffer (1 .. Rnm'Length) := Rnm;
5330 Name_Len := Rnm'Length;
5331 Set_Casing (All_Lower_Case);
5333 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5335 (Identifier_Casing (Current_Source_File));
5336 Error_Msg_String (1 .. Rnm'Length) :=
5337 Name_Buffer (1 .. Name_Len);
5338 Error_Msg_Strlen := Rnm'Length;
5339 Error_Msg_N -- CODEFIX
5340 ("\possible misspelling of ""~""",
5341 Get_Pragma_Arg (Arg));
5350 if Implementation_Restriction (R_Id) then
5351 Check_Restriction (No_Implementation_Restrictions, Arg);
5354 -- Special processing for No_Elaboration_Code restriction
5356 if R_Id = No_Elaboration_Code then
5358 -- Restriction is only recognized within a configuration
5359 -- pragma file, or within a unit of the main extended
5360 -- program. Note: the test for Main_Unit is needed to
5361 -- properly include the case of configuration pragma files.
5363 if not (Current_Sem_Unit = Main_Unit
5364 or else In_Extended_Main_Source_Unit (N))
5368 -- Don't allow in a subunit unless already specified in
5371 elsif Nkind (Parent (N)) = N_Compilation_Unit
5372 and then Nkind (Unit (Parent (N))) = N_Subunit
5373 and then not Restriction_Active (No_Elaboration_Code)
5376 ("invalid specification of ""No_Elaboration_Code""",
5379 ("\restriction cannot be specified in a subunit", N);
5381 ("\unless also specified in body or spec", N);
5384 -- If we have a No_Elaboration_Code pragma that we
5385 -- accept, then it needs to be added to the configuration
5386 -- restrcition set so that we get proper application to
5387 -- other units in the main extended source as required.
5390 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
5394 -- If this is a warning, then set the warning unless we already
5395 -- have a real restriction active (we never want a warning to
5396 -- override a real restriction).
5399 if not Restriction_Active (R_Id) then
5400 Set_Restriction (R_Id, N);
5401 Restriction_Warnings (R_Id) := True;
5404 -- If real restriction case, then set it and make sure that the
5405 -- restriction warning flag is off, since a real restriction
5406 -- always overrides a warning.
5409 Set_Restriction (R_Id, N);
5410 Restriction_Warnings (R_Id) := False;
5413 -- Check for obsolescent restrictions in Ada 2005 mode
5416 and then Ada_Version >= Ada_2005
5417 and then (R_Id = No_Asynchronous_Control
5419 R_Id = No_Unchecked_Deallocation
5421 R_Id = No_Unchecked_Conversion)
5423 Check_Restriction (No_Obsolescent_Features, N);
5426 -- A very special case that must be processed here: pragma
5427 -- Restrictions (No_Exceptions) turns off all run-time
5428 -- checking. This is a bit dubious in terms of the formal
5429 -- language definition, but it is what is intended by RM
5430 -- H.4(12). Restriction_Warnings never affects generated code
5431 -- so this is done only in the real restriction case.
5433 -- Atomic_Synchronization is not a real check, so it is not
5434 -- affected by this processing).
5436 if R_Id = No_Exceptions and then not Warn then
5437 for J in Scope_Suppress'Range loop
5438 if J /= Atomic_Synchronization then
5439 Scope_Suppress (J) := True;
5444 -- Case of No_Dependence => unit-name. Note that the parser
5445 -- already made the necessary entry in the No_Dependence table.
5447 elsif Id = Name_No_Dependence then
5448 Check_Unit_Name (Expr);
5450 -- Case of No_Specification_Of_Aspect => Identifier.
5452 elsif Id = Name_No_Specification_Of_Aspect then
5457 if Nkind (Expr) /= N_Identifier then
5460 A_Id := Get_Aspect_Id (Chars (Expr));
5463 if A_Id = No_Aspect then
5464 Error_Pragma_Arg ("invalid restriction name", Arg);
5466 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5470 -- All other cases of restriction identifier present
5473 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5474 Analyze_And_Resolve (Expr, Any_Integer);
5476 if R_Id not in All_Parameter_Restrictions then
5478 ("invalid restriction parameter identifier", Arg);
5480 elsif not Is_OK_Static_Expression (Expr) then
5481 Flag_Non_Static_Expr
5482 ("value must be static expression!", Expr);
5485 elsif not Is_Integer_Type (Etype (Expr))
5486 or else Expr_Value (Expr) < 0
5489 ("value must be non-negative integer", Arg);
5492 -- Restriction pragma is active
5494 Val := Expr_Value (Expr);
5496 if not UI_Is_In_Int_Range (Val) then
5498 ("pragma ignored, value too large?", Arg);
5501 -- Warning case. If the real restriction is active, then we
5502 -- ignore the request, since warning never overrides a real
5503 -- restriction. Otherwise we set the proper warning. Note that
5504 -- this circuit sets the warning again if it is already set,
5505 -- which is what we want, since the constant may have changed.
5508 if not Restriction_Active (R_Id) then
5510 (R_Id, N, Integer (UI_To_Int (Val)));
5511 Restriction_Warnings (R_Id) := True;
5514 -- Real restriction case, set restriction and make sure warning
5515 -- flag is off since real restriction always overrides warning.
5518 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5519 Restriction_Warnings (R_Id) := False;
5525 end Process_Restrictions_Or_Restriction_Warnings;
5527 ---------------------------------
5528 -- Process_Suppress_Unsuppress --
5529 ---------------------------------
5531 -- Note: this procedure makes entries in the check suppress data
5532 -- structures managed by Sem. See spec of package Sem for full
5533 -- details on how we handle recording of check suppression.
5535 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5540 In_Package_Spec : constant Boolean :=
5541 Is_Package_Or_Generic_Package (Current_Scope)
5542 and then not In_Package_Body (Current_Scope);
5544 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5545 -- Used to suppress a single check on the given entity
5547 --------------------------------
5548 -- Suppress_Unsuppress_Echeck --
5549 --------------------------------
5551 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5553 -- Check for error of trying to set atomic synchronization for
5554 -- a non-atomic variable.
5556 if C = Atomic_Synchronization
5557 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5560 ("pragma & requires atomic type or variable",
5561 Pragma_Identifier (Original_Node (N)));
5564 Set_Checks_May_Be_Suppressed (E);
5566 if In_Package_Spec then
5567 Push_Global_Suppress_Stack_Entry
5570 Suppress => Suppress_Case);
5572 Push_Local_Suppress_Stack_Entry
5575 Suppress => Suppress_Case);
5578 -- If this is a first subtype, and the base type is distinct,
5579 -- then also set the suppress flags on the base type.
5581 if Is_First_Subtype (E)
5582 and then Etype (E) /= E
5584 Suppress_Unsuppress_Echeck (Etype (E), C);
5586 end Suppress_Unsuppress_Echeck;
5588 -- Start of processing for Process_Suppress_Unsuppress
5591 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5592 -- user code: we want to generate checks for analysis purposes, as
5593 -- set respectively by -gnatC and -gnatd.F
5595 if (CodePeer_Mode or Alfa_Mode)
5596 and then Comes_From_Source (N)
5601 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5602 -- declarative part or a package spec (RM 11.5(5)).
5604 if not Is_Configuration_Pragma then
5605 Check_Is_In_Decl_Part_Or_Package_Spec;
5608 Check_At_Least_N_Arguments (1);
5609 Check_At_Most_N_Arguments (2);
5610 Check_No_Identifier (Arg1);
5611 Check_Arg_Is_Identifier (Arg1);
5613 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5615 if C = No_Check_Id then
5617 ("argument of pragma% is not valid check name", Arg1);
5620 if not Suppress_Case
5621 and then (C = All_Checks or else C = Overflow_Check)
5623 Opt.Overflow_Checks_Unsuppressed := True;
5626 if Arg_Count = 1 then
5628 -- Make an entry in the local scope suppress table. This is the
5629 -- table that directly shows the current value of the scope
5630 -- suppress check for any check id value.
5632 if C = All_Checks then
5634 -- For All_Checks, we set all specific predefined checks with
5635 -- the exception of Elaboration_Check, which is handled
5636 -- specially because of not wanting All_Checks to have the
5637 -- effect of deactivating static elaboration order processing.
5638 -- Atomic_Synchronization is also not affected, since this is
5639 -- not a real check.
5641 for J in Scope_Suppress'Range loop
5642 if J /= Elaboration_Check
5643 and then J /= Atomic_Synchronization
5645 Scope_Suppress (J) := Suppress_Case;
5649 -- If not All_Checks, and predefined check, then set appropriate
5650 -- scope entry. Note that we will set Elaboration_Check if this
5651 -- is explicitly specified. Atomic_Synchronization is allowed
5652 -- only if internally generated and entity is atomic.
5654 elsif C in Predefined_Check_Id
5655 and then (not Comes_From_Source (N)
5656 or else C /= Atomic_Synchronization)
5658 Scope_Suppress (C) := Suppress_Case;
5661 -- Also make an entry in the Local_Entity_Suppress table
5663 Push_Local_Suppress_Stack_Entry
5666 Suppress => Suppress_Case);
5668 -- Case of two arguments present, where the check is suppressed for
5669 -- a specified entity (given as the second argument of the pragma)
5672 -- This is obsolescent in Ada 2005 mode
5674 if Ada_Version >= Ada_2005 then
5675 Check_Restriction (No_Obsolescent_Features, Arg2);
5678 Check_Optional_Identifier (Arg2, Name_On);
5679 E_Id := Get_Pragma_Arg (Arg2);
5682 if not Is_Entity_Name (E_Id) then
5684 ("second argument of pragma% must be entity name", Arg2);
5693 -- Enforce RM 11.5(7) which requires that for a pragma that
5694 -- appears within a package spec, the named entity must be
5695 -- within the package spec. We allow the package name itself
5696 -- to be mentioned since that makes sense, although it is not
5697 -- strictly allowed by 11.5(7).
5700 and then E /= Current_Scope
5701 and then Scope (E) /= Current_Scope
5704 ("entity in pragma% is not in package spec (RM 11.5(7))",
5708 -- Loop through homonyms. As noted below, in the case of a package
5709 -- spec, only homonyms within the package spec are considered.
5712 Suppress_Unsuppress_Echeck (E, C);
5714 if Is_Generic_Instance (E)
5715 and then Is_Subprogram (E)
5716 and then Present (Alias (E))
5718 Suppress_Unsuppress_Echeck (Alias (E), C);
5721 -- Move to next homonym if not aspect spec case
5723 exit when From_Aspect_Specification (N);
5727 -- If we are within a package specification, the pragma only
5728 -- applies to homonyms in the same scope.
5730 exit when In_Package_Spec
5731 and then Scope (E) /= Current_Scope;
5734 end Process_Suppress_Unsuppress;
5740 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5742 if Is_Imported (E) then
5744 ("cannot export entity& that was previously imported", Arg);
5746 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5748 ("cannot export entity& that has an address clause", Arg);
5751 Set_Is_Exported (E);
5753 -- Generate a reference for entity explicitly, because the
5754 -- identifier may be overloaded and name resolution will not
5757 Generate_Reference (E, Arg);
5759 -- Deal with exporting non-library level entity
5761 if not Is_Library_Level_Entity (E) then
5763 -- Not allowed at all for subprograms
5765 if Is_Subprogram (E) then
5766 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5768 -- Otherwise set public and statically allocated
5772 Set_Is_Statically_Allocated (E);
5774 -- Warn if the corresponding W flag is set and the pragma comes
5775 -- from source. The latter may not be true e.g. on VMS where we
5776 -- expand export pragmas for exception codes associated with
5777 -- imported or exported exceptions. We do not want to generate
5778 -- a warning for something that the user did not write.
5780 if Warn_On_Export_Import
5781 and then Comes_From_Source (Arg)
5784 ("?& has been made static as a result of Export", Arg, E);
5786 ("\this usage is non-standard and non-portable", Arg);
5791 if Warn_On_Export_Import and then Is_Type (E) then
5792 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5795 if Warn_On_Export_Import and Inside_A_Generic then
5797 ("all instances of& will have the same external name?", Arg, E);
5801 ----------------------------------------------
5802 -- Set_Extended_Import_Export_External_Name --
5803 ----------------------------------------------
5805 procedure Set_Extended_Import_Export_External_Name
5806 (Internal_Ent : Entity_Id;
5807 Arg_External : Node_Id)
5809 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5813 if No (Arg_External) then
5817 Check_Arg_Is_External_Name (Arg_External);
5819 if Nkind (Arg_External) = N_String_Literal then
5820 if String_Length (Strval (Arg_External)) = 0 then
5823 New_Name := Adjust_External_Name_Case (Arg_External);
5826 elsif Nkind (Arg_External) = N_Identifier then
5827 New_Name := Get_Default_External_Name (Arg_External);
5829 -- Check_Arg_Is_External_Name should let through only identifiers and
5830 -- string literals or static string expressions (which are folded to
5831 -- string literals).
5834 raise Program_Error;
5837 -- If we already have an external name set (by a prior normal Import
5838 -- or Export pragma), then the external names must match
5840 if Present (Interface_Name (Internal_Ent)) then
5841 Check_Matching_Internal_Names : declare
5842 S1 : constant String_Id := Strval (Old_Name);
5843 S2 : constant String_Id := Strval (New_Name);
5846 -- Called if names do not match
5852 procedure Mismatch is
5854 Error_Msg_Sloc := Sloc (Old_Name);
5856 ("external name does not match that given #",
5860 -- Start of processing for Check_Matching_Internal_Names
5863 if String_Length (S1) /= String_Length (S2) then
5867 for J in 1 .. String_Length (S1) loop
5868 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5873 end Check_Matching_Internal_Names;
5875 -- Otherwise set the given name
5878 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5879 Check_Duplicated_Export_Name (New_Name);
5881 end Set_Extended_Import_Export_External_Name;
5887 procedure Set_Imported (E : Entity_Id) is
5889 -- Error message if already imported or exported
5891 if Is_Exported (E) or else Is_Imported (E) then
5893 -- Error if being set Exported twice
5895 if Is_Exported (E) then
5896 Error_Msg_NE ("entity& was previously exported", N, E);
5898 -- OK if Import/Interface case
5900 elsif Import_Interface_Present (N) then
5903 -- Error if being set Imported twice
5906 Error_Msg_NE ("entity& was previously imported", N, E);
5909 Error_Msg_Name_1 := Pname;
5911 ("\(pragma% applies to all previous entities)", N);
5913 Error_Msg_Sloc := Sloc (E);
5914 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5916 -- Here if not previously imported or exported, OK to import
5919 Set_Is_Imported (E);
5921 -- If the entity is an object that is not at the library level,
5922 -- then it is statically allocated. We do not worry about objects
5923 -- with address clauses in this context since they are not really
5924 -- imported in the linker sense.
5927 and then not Is_Library_Level_Entity (E)
5928 and then No (Address_Clause (E))
5930 Set_Is_Statically_Allocated (E);
5937 -------------------------
5938 -- Set_Mechanism_Value --
5939 -------------------------
5941 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5942 -- analyzed, since it is semantic nonsense), so we get it in the exact
5943 -- form created by the parser.
5945 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5948 Mech_Name_Id : Name_Id;
5950 procedure Bad_Class;
5951 -- Signal bad descriptor class name
5953 procedure Bad_Mechanism;
5954 -- Signal bad mechanism name
5960 procedure Bad_Class is
5962 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5965 -------------------------
5966 -- Bad_Mechanism_Value --
5967 -------------------------
5969 procedure Bad_Mechanism is
5971 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5974 -- Start of processing for Set_Mechanism_Value
5977 if Mechanism (Ent) /= Default_Mechanism then
5979 ("mechanism for & has already been set", Mech_Name, Ent);
5982 -- MECHANISM_NAME ::= value | reference | descriptor |
5985 if Nkind (Mech_Name) = N_Identifier then
5986 if Chars (Mech_Name) = Name_Value then
5987 Set_Mechanism (Ent, By_Copy);
5990 elsif Chars (Mech_Name) = Name_Reference then
5991 Set_Mechanism (Ent, By_Reference);
5994 elsif Chars (Mech_Name) = Name_Descriptor then
5995 Check_VMS (Mech_Name);
5997 -- Descriptor => Short_Descriptor if pragma was given
5999 if Short_Descriptors then
6000 Set_Mechanism (Ent, By_Short_Descriptor);
6002 Set_Mechanism (Ent, By_Descriptor);
6007 elsif Chars (Mech_Name) = Name_Short_Descriptor then
6008 Check_VMS (Mech_Name);
6009 Set_Mechanism (Ent, By_Short_Descriptor);
6012 elsif Chars (Mech_Name) = Name_Copy then
6014 ("bad mechanism name, Value assumed", Mech_Name);
6020 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
6021 -- short_descriptor (CLASS_NAME)
6022 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6024 -- Note: this form is parsed as an indexed component
6026 elsif Nkind (Mech_Name) = N_Indexed_Component then
6027 Class := First (Expressions (Mech_Name));
6029 if Nkind (Prefix (Mech_Name)) /= N_Identifier
6030 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
6031 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
6032 or else Present (Next (Class))
6036 Mech_Name_Id := Chars (Prefix (Mech_Name));
6038 -- Change Descriptor => Short_Descriptor if pragma was given
6040 if Mech_Name_Id = Name_Descriptor
6041 and then Short_Descriptors
6043 Mech_Name_Id := Name_Short_Descriptor;
6047 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6048 -- short_descriptor (Class => CLASS_NAME)
6049 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6051 -- Note: this form is parsed as a function call
6053 elsif Nkind (Mech_Name) = N_Function_Call then
6054 Param := First (Parameter_Associations (Mech_Name));
6056 if Nkind (Name (Mech_Name)) /= N_Identifier
6057 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6058 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6059 or else Present (Next (Param))
6060 or else No (Selector_Name (Param))
6061 or else Chars (Selector_Name (Param)) /= Name_Class
6065 Class := Explicit_Actual_Parameter (Param);
6066 Mech_Name_Id := Chars (Name (Mech_Name));
6073 -- Fall through here with Class set to descriptor class name
6075 Check_VMS (Mech_Name);
6077 if Nkind (Class) /= N_Identifier then
6080 elsif Mech_Name_Id = Name_Descriptor
6081 and then Chars (Class) = Name_UBS
6083 Set_Mechanism (Ent, By_Descriptor_UBS);
6085 elsif Mech_Name_Id = Name_Descriptor
6086 and then Chars (Class) = Name_UBSB
6088 Set_Mechanism (Ent, By_Descriptor_UBSB);
6090 elsif Mech_Name_Id = Name_Descriptor
6091 and then Chars (Class) = Name_UBA
6093 Set_Mechanism (Ent, By_Descriptor_UBA);
6095 elsif Mech_Name_Id = Name_Descriptor
6096 and then Chars (Class) = Name_S
6098 Set_Mechanism (Ent, By_Descriptor_S);
6100 elsif Mech_Name_Id = Name_Descriptor
6101 and then Chars (Class) = Name_SB
6103 Set_Mechanism (Ent, By_Descriptor_SB);
6105 elsif Mech_Name_Id = Name_Descriptor
6106 and then Chars (Class) = Name_A
6108 Set_Mechanism (Ent, By_Descriptor_A);
6110 elsif Mech_Name_Id = Name_Descriptor
6111 and then Chars (Class) = Name_NCA
6113 Set_Mechanism (Ent, By_Descriptor_NCA);
6115 elsif Mech_Name_Id = Name_Short_Descriptor
6116 and then Chars (Class) = Name_UBS
6118 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6120 elsif Mech_Name_Id = Name_Short_Descriptor
6121 and then Chars (Class) = Name_UBSB
6123 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6125 elsif Mech_Name_Id = Name_Short_Descriptor
6126 and then Chars (Class) = Name_UBA
6128 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6130 elsif Mech_Name_Id = Name_Short_Descriptor
6131 and then Chars (Class) = Name_S
6133 Set_Mechanism (Ent, By_Short_Descriptor_S);
6135 elsif Mech_Name_Id = Name_Short_Descriptor
6136 and then Chars (Class) = Name_SB
6138 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6140 elsif Mech_Name_Id = Name_Short_Descriptor
6141 and then Chars (Class) = Name_A
6143 Set_Mechanism (Ent, By_Short_Descriptor_A);
6145 elsif Mech_Name_Id = Name_Short_Descriptor
6146 and then Chars (Class) = Name_NCA
6148 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6153 end Set_Mechanism_Value;
6155 ---------------------------
6156 -- Set_Ravenscar_Profile --
6157 ---------------------------
6159 -- The tasks to be done here are
6161 -- Set required policies
6163 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6164 -- pragma Locking_Policy (Ceiling_Locking)
6166 -- Set Detect_Blocking mode
6168 -- Set required restrictions (see System.Rident for detailed list)
6170 -- Set the No_Dependence rules
6171 -- No_Dependence => Ada.Asynchronous_Task_Control
6172 -- No_Dependence => Ada.Calendar
6173 -- No_Dependence => Ada.Execution_Time.Group_Budget
6174 -- No_Dependence => Ada.Execution_Time.Timers
6175 -- No_Dependence => Ada.Task_Attributes
6176 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6178 procedure Set_Ravenscar_Profile (N : Node_Id) is
6179 Prefix_Entity : Entity_Id;
6180 Selector_Entity : Entity_Id;
6181 Prefix_Node : Node_Id;
6185 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6187 if Task_Dispatching_Policy /= ' '
6188 and then Task_Dispatching_Policy /= 'F'
6190 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6191 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6193 -- Set the FIFO_Within_Priorities policy, but always preserve
6194 -- System_Location since we like the error message with the run time
6198 Task_Dispatching_Policy := 'F';
6200 if Task_Dispatching_Policy_Sloc /= System_Location then
6201 Task_Dispatching_Policy_Sloc := Loc;
6205 -- pragma Locking_Policy (Ceiling_Locking)
6207 if Locking_Policy /= ' '
6208 and then Locking_Policy /= 'C'
6210 Error_Msg_Sloc := Locking_Policy_Sloc;
6211 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6213 -- Set the Ceiling_Locking policy, but preserve System_Location since
6214 -- we like the error message with the run time name.
6217 Locking_Policy := 'C';
6219 if Locking_Policy_Sloc /= System_Location then
6220 Locking_Policy_Sloc := Loc;
6224 -- pragma Detect_Blocking
6226 Detect_Blocking := True;
6228 -- Set the corresponding restrictions
6230 Set_Profile_Restrictions
6231 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6233 -- Set the No_Dependence restrictions
6235 -- The following No_Dependence restrictions:
6236 -- No_Dependence => Ada.Asynchronous_Task_Control
6237 -- No_Dependence => Ada.Calendar
6238 -- No_Dependence => Ada.Task_Attributes
6239 -- are already set by previous call to Set_Profile_Restrictions.
6241 -- Set the following restrictions which were added to Ada 2005:
6242 -- No_Dependence => Ada.Execution_Time.Group_Budget
6243 -- No_Dependence => Ada.Execution_Time.Timers
6245 if Ada_Version >= Ada_2005 then
6246 Name_Buffer (1 .. 3) := "ada";
6249 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6251 Name_Buffer (1 .. 14) := "execution_time";
6254 Selector_Entity := Make_Identifier (Loc, Name_Find);
6257 Make_Selected_Component
6259 Prefix => Prefix_Entity,
6260 Selector_Name => Selector_Entity);
6262 Name_Buffer (1 .. 13) := "group_budgets";
6265 Selector_Entity := Make_Identifier (Loc, Name_Find);
6268 Make_Selected_Component
6270 Prefix => Prefix_Node,
6271 Selector_Name => Selector_Entity);
6273 Set_Restriction_No_Dependence
6275 Warn => Treat_Restrictions_As_Warnings,
6276 Profile => Ravenscar);
6278 Name_Buffer (1 .. 6) := "timers";
6281 Selector_Entity := Make_Identifier (Loc, Name_Find);
6284 Make_Selected_Component
6286 Prefix => Prefix_Node,
6287 Selector_Name => Selector_Entity);
6289 Set_Restriction_No_Dependence
6291 Warn => Treat_Restrictions_As_Warnings,
6292 Profile => Ravenscar);
6295 -- Set the following restrictions which was added to Ada 2012 (see
6297 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6299 if Ada_Version >= Ada_2012 then
6300 Name_Buffer (1 .. 6) := "system";
6303 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6305 Name_Buffer (1 .. 15) := "multiprocessors";
6308 Selector_Entity := Make_Identifier (Loc, Name_Find);
6311 Make_Selected_Component
6313 Prefix => Prefix_Entity,
6314 Selector_Name => Selector_Entity);
6316 Name_Buffer (1 .. 19) := "dispatching_domains";
6319 Selector_Entity := Make_Identifier (Loc, Name_Find);
6322 Make_Selected_Component
6324 Prefix => Prefix_Node,
6325 Selector_Name => Selector_Entity);
6327 Set_Restriction_No_Dependence
6329 Warn => Treat_Restrictions_As_Warnings,
6330 Profile => Ravenscar);
6332 end Set_Ravenscar_Profile;
6334 -- Start of processing for Analyze_Pragma
6337 -- The following code is a defense against recursion. Not clear that
6338 -- this can happen legitimately, but perhaps some error situations
6339 -- can cause it, and we did see this recursion during testing.
6341 if Analyzed (N) then
6344 Set_Analyzed (N, True);
6347 -- Deal with unrecognized pragma
6349 Pname := Pragma_Name (N);
6351 if not Is_Pragma_Name (Pname) then
6352 if Warn_On_Unrecognized_Pragma then
6353 Error_Msg_Name_1 := Pname;
6354 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6356 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6357 if Is_Bad_Spelling_Of (Pname, PN) then
6358 Error_Msg_Name_1 := PN;
6359 Error_Msg_N -- CODEFIX
6360 ("\?possible misspelling of %!", Pragma_Identifier (N));
6369 -- Here to start processing for recognized pragma
6371 Prag_Id := Get_Pragma_Id (Pname);
6373 if Present (Corresponding_Aspect (N)) then
6374 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6385 if Present (Pragma_Argument_Associations (N)) then
6386 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6387 Arg1 := First (Pragma_Argument_Associations (N));
6389 if Present (Arg1) then
6390 Arg2 := Next (Arg1);
6392 if Present (Arg2) then
6393 Arg3 := Next (Arg2);
6395 if Present (Arg3) then
6396 Arg4 := Next (Arg3);
6402 -- An enumeration type defines the pragmas that are supported by the
6403 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6404 -- into the corresponding enumeration value for the following case.
6412 -- pragma Abort_Defer;
6414 when Pragma_Abort_Defer =>
6416 Check_Arg_Count (0);
6418 -- The only required semantic processing is to check the
6419 -- placement. This pragma must appear at the start of the
6420 -- statement sequence of a handled sequence of statements.
6422 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6423 or else N /= First (Statements (Parent (N)))
6434 -- Note: this pragma also has some specific processing in Par.Prag
6435 -- because we want to set the Ada version mode during parsing.
6437 when Pragma_Ada_83 =>
6439 Check_Arg_Count (0);
6441 -- We really should check unconditionally for proper configuration
6442 -- pragma placement, since we really don't want mixed Ada modes
6443 -- within a single unit, and the GNAT reference manual has always
6444 -- said this was a configuration pragma, but we did not check and
6445 -- are hesitant to add the check now.
6447 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6448 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6449 -- or Ada 2012 mode.
6451 if Ada_Version >= Ada_2005 then
6452 Check_Valid_Configuration_Pragma;
6455 -- Now set Ada 83 mode
6457 Ada_Version := Ada_83;
6458 Ada_Version_Explicit := Ada_Version;
6466 -- Note: this pragma also has some specific processing in Par.Prag
6467 -- because we want to set the Ada 83 version mode during parsing.
6469 when Pragma_Ada_95 =>
6471 Check_Arg_Count (0);
6473 -- We really should check unconditionally for proper configuration
6474 -- pragma placement, since we really don't want mixed Ada modes
6475 -- within a single unit, and the GNAT reference manual has always
6476 -- said this was a configuration pragma, but we did not check and
6477 -- are hesitant to add the check now.
6479 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6480 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6482 if Ada_Version >= Ada_2005 then
6483 Check_Valid_Configuration_Pragma;
6486 -- Now set Ada 95 mode
6488 Ada_Version := Ada_95;
6489 Ada_Version_Explicit := Ada_Version;
6491 ---------------------
6492 -- Ada_05/Ada_2005 --
6493 ---------------------
6496 -- pragma Ada_05 (LOCAL_NAME);
6499 -- pragma Ada_2005 (LOCAL_NAME):
6501 -- Note: these pragmas also have some specific processing in Par.Prag
6502 -- because we want to set the Ada 2005 version mode during parsing.
6504 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6510 if Arg_Count = 1 then
6511 Check_Arg_Is_Local_Name (Arg1);
6512 E_Id := Get_Pragma_Arg (Arg1);
6514 if Etype (E_Id) = Any_Type then
6518 Set_Is_Ada_2005_Only (Entity (E_Id));
6521 Check_Arg_Count (0);
6523 -- For Ada_2005 we unconditionally enforce the documented
6524 -- configuration pragma placement, since we do not want to
6525 -- tolerate mixed modes in a unit involving Ada 2005. That
6526 -- would cause real difficulties for those cases where there
6527 -- are incompatibilities between Ada 95 and Ada 2005.
6529 Check_Valid_Configuration_Pragma;
6531 -- Now set appropriate Ada mode
6533 Ada_Version := Ada_2005;
6534 Ada_Version_Explicit := Ada_2005;
6538 ---------------------
6539 -- Ada_12/Ada_2012 --
6540 ---------------------
6543 -- pragma Ada_12 (LOCAL_NAME);
6546 -- pragma Ada_2012 (LOCAL_NAME):
6548 -- Note: these pragmas also have some specific processing in Par.Prag
6549 -- because we want to set the Ada 2012 version mode during parsing.
6551 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6557 if Arg_Count = 1 then
6558 Check_Arg_Is_Local_Name (Arg1);
6559 E_Id := Get_Pragma_Arg (Arg1);
6561 if Etype (E_Id) = Any_Type then
6565 Set_Is_Ada_2012_Only (Entity (E_Id));
6568 Check_Arg_Count (0);
6570 -- For Ada_2012 we unconditionally enforce the documented
6571 -- configuration pragma placement, since we do not want to
6572 -- tolerate mixed modes in a unit involving Ada 2012. That
6573 -- would cause real difficulties for those cases where there
6574 -- are incompatibilities between Ada 95 and Ada 2012. We could
6575 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6577 Check_Valid_Configuration_Pragma;
6579 -- Now set appropriate Ada mode
6581 Ada_Version := Ada_2012;
6582 Ada_Version_Explicit := Ada_2012;
6586 ----------------------
6587 -- All_Calls_Remote --
6588 ----------------------
6590 -- pragma All_Calls_Remote [(library_package_NAME)];
6592 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6593 Lib_Entity : Entity_Id;
6596 Check_Ada_83_Warning;
6597 Check_Valid_Library_Unit_Pragma;
6599 if Nkind (N) = N_Null_Statement then
6603 Lib_Entity := Find_Lib_Unit_Name;
6605 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6607 if Present (Lib_Entity)
6608 and then not Debug_Flag_U
6610 if not Is_Remote_Call_Interface (Lib_Entity) then
6611 Error_Pragma ("pragma% only apply to rci unit");
6613 -- Set flag for entity of the library unit
6616 Set_Has_All_Calls_Remote (Lib_Entity);
6620 end All_Calls_Remote;
6626 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6627 -- ARG ::= NAME | EXPRESSION
6629 -- The first two arguments are by convention intended to refer to an
6630 -- external tool and a tool-specific function. These arguments are
6633 when Pragma_Annotate => Annotate : declare
6639 Check_At_Least_N_Arguments (1);
6640 Check_Arg_Is_Identifier (Arg1);
6641 Check_No_Identifiers;
6644 -- Second parameter is optional, it is never analyzed
6649 -- Here if we have a second parameter
6652 -- Second parameter must be identifier
6654 Check_Arg_Is_Identifier (Arg2);
6656 -- Process remaining parameters if any
6659 while Present (Arg) loop
6660 Exp := Get_Pragma_Arg (Arg);
6663 if Is_Entity_Name (Exp) then
6666 -- For string literals, we assume Standard_String as the
6667 -- type, unless the string contains wide or wide_wide
6670 elsif Nkind (Exp) = N_String_Literal then
6671 if Has_Wide_Wide_Character (Exp) then
6672 Resolve (Exp, Standard_Wide_Wide_String);
6673 elsif Has_Wide_Character (Exp) then
6674 Resolve (Exp, Standard_Wide_String);
6676 Resolve (Exp, Standard_String);
6679 elsif Is_Overloaded (Exp) then
6681 ("ambiguous argument for pragma%", Exp);
6696 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6697 -- [, [Message =>] Static_String_EXPRESSION]);
6699 when Pragma_Assert => Assert : declare
6705 Check_At_Least_N_Arguments (1);
6706 Check_At_Most_N_Arguments (2);
6707 Check_Arg_Order ((Name_Check, Name_Message));
6708 Check_Optional_Identifier (Arg1, Name_Check);
6710 -- We treat pragma Assert as equivalent to:
6712 -- pragma Check (Assertion, condition [, msg]);
6714 -- So rewrite pragma in this manner, and analyze the result
6716 Expr := Get_Pragma_Arg (Arg1);
6718 Make_Pragma_Argument_Association (Loc,
6719 Expression => Make_Identifier (Loc, Name_Assertion)),
6721 Make_Pragma_Argument_Association (Sloc (Expr),
6722 Expression => Expr));
6724 if Arg_Count > 1 then
6725 Check_Optional_Identifier (Arg2, Name_Message);
6726 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6727 Append_To (Newa, Relocate_Node (Arg2));
6732 Chars => Name_Check,
6733 Pragma_Argument_Associations => Newa));
6737 ----------------------
6738 -- Assertion_Policy --
6739 ----------------------
6741 -- pragma Assertion_Policy (Check | Disable |Ignore)
6743 when Pragma_Assertion_Policy => Assertion_Policy : declare
6748 Check_Valid_Configuration_Pragma;
6749 Check_Arg_Count (1);
6750 Check_No_Identifiers;
6751 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6753 -- We treat pragma Assertion_Policy as equivalent to:
6755 -- pragma Check_Policy (Assertion, policy)
6757 -- So rewrite the pragma in that manner and link on to the chain
6758 -- of Check_Policy pragmas, marking the pragma as analyzed.
6760 Policy := Get_Pragma_Arg (Arg1);
6764 Chars => Name_Check_Policy,
6766 Pragma_Argument_Associations => New_List (
6767 Make_Pragma_Argument_Association (Loc,
6768 Expression => Make_Identifier (Loc, Name_Assertion)),
6770 Make_Pragma_Argument_Association (Loc,
6772 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6775 Set_Next_Pragma (N, Opt.Check_Policy_List);
6776 Opt.Check_Policy_List := N;
6777 end Assertion_Policy;
6779 ------------------------------
6780 -- Assume_No_Invalid_Values --
6781 ------------------------------
6783 -- pragma Assume_No_Invalid_Values (On | Off);
6785 when Pragma_Assume_No_Invalid_Values =>
6787 Check_Valid_Configuration_Pragma;
6788 Check_Arg_Count (1);
6789 Check_No_Identifiers;
6790 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6792 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6793 Assume_No_Invalid_Values := True;
6795 Assume_No_Invalid_Values := False;
6802 -- pragma AST_Entry (entry_IDENTIFIER);
6804 when Pragma_AST_Entry => AST_Entry : declare
6810 Check_Arg_Count (1);
6811 Check_No_Identifiers;
6812 Check_Arg_Is_Local_Name (Arg1);
6813 Ent := Entity (Get_Pragma_Arg (Arg1));
6815 -- Note: the implementation of the AST_Entry pragma could handle
6816 -- the entry family case fine, but for now we are consistent with
6817 -- the DEC rules, and do not allow the pragma, which of course
6818 -- has the effect of also forbidding the attribute.
6820 if Ekind (Ent) /= E_Entry then
6822 ("pragma% argument must be simple entry name", Arg1);
6824 elsif Is_AST_Entry (Ent) then
6826 ("duplicate % pragma for entry", Arg1);
6828 elsif Has_Homonym (Ent) then
6830 ("pragma% argument cannot specify overloaded entry", Arg1);
6834 FF : constant Entity_Id := First_Formal (Ent);
6837 if Present (FF) then
6838 if Present (Next_Formal (FF)) then
6840 ("entry for pragma% can have only one argument",
6843 elsif Parameter_Mode (FF) /= E_In_Parameter then
6845 ("entry parameter for pragma% must have mode IN",
6851 Set_Is_AST_Entry (Ent);
6859 -- pragma Asynchronous (LOCAL_NAME);
6861 when Pragma_Asynchronous => Asynchronous : declare
6869 procedure Process_Async_Pragma;
6870 -- Common processing for procedure and access-to-procedure case
6872 --------------------------
6873 -- Process_Async_Pragma --
6874 --------------------------
6876 procedure Process_Async_Pragma is
6879 Set_Is_Asynchronous (Nm);
6883 -- The formals should be of mode IN (RM E.4.1(6))
6886 while Present (S) loop
6887 Formal := Defining_Identifier (S);
6889 if Nkind (Formal) = N_Defining_Identifier
6890 and then Ekind (Formal) /= E_In_Parameter
6893 ("pragma% procedure can only have IN parameter",
6900 Set_Is_Asynchronous (Nm);
6901 end Process_Async_Pragma;
6903 -- Start of processing for pragma Asynchronous
6906 Check_Ada_83_Warning;
6907 Check_No_Identifiers;
6908 Check_Arg_Count (1);
6909 Check_Arg_Is_Local_Name (Arg1);
6911 if Debug_Flag_U then
6915 C_Ent := Cunit_Entity (Current_Sem_Unit);
6916 Analyze (Get_Pragma_Arg (Arg1));
6917 Nm := Entity (Get_Pragma_Arg (Arg1));
6919 if not Is_Remote_Call_Interface (C_Ent)
6920 and then not Is_Remote_Types (C_Ent)
6922 -- This pragma should only appear in an RCI or Remote Types
6923 -- unit (RM E.4.1(4)).
6926 ("pragma% not in Remote_Call_Interface or " &
6927 "Remote_Types unit");
6930 if Ekind (Nm) = E_Procedure
6931 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6933 if not Is_Remote_Call_Interface (Nm) then
6935 ("pragma% cannot be applied on non-remote procedure",
6939 L := Parameter_Specifications (Parent (Nm));
6940 Process_Async_Pragma;
6943 elsif Ekind (Nm) = E_Function then
6945 ("pragma% cannot be applied to function", Arg1);
6947 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6948 if Is_Record_Type (Nm) then
6950 -- A record type that is the Equivalent_Type for a remote
6951 -- access-to-subprogram type.
6953 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6956 -- A non-expanded RAS type (distribution is not enabled)
6958 N := Declaration_Node (Nm);
6961 if Nkind (N) = N_Full_Type_Declaration
6962 and then Nkind (Type_Definition (N)) =
6963 N_Access_Procedure_Definition
6965 L := Parameter_Specifications (Type_Definition (N));
6966 Process_Async_Pragma;
6968 if Is_Asynchronous (Nm)
6969 and then Expander_Active
6970 and then Get_PCS_Name /= Name_No_DSA
6972 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6977 ("pragma% cannot reference access-to-function type",
6981 -- Only other possibility is Access-to-class-wide type
6983 elsif Is_Access_Type (Nm)
6984 and then Is_Class_Wide_Type (Designated_Type (Nm))
6986 Check_First_Subtype (Arg1);
6987 Set_Is_Asynchronous (Nm);
6988 if Expander_Active then
6989 RACW_Type_Is_Asynchronous (Nm);
6993 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
7001 -- pragma Atomic (LOCAL_NAME);
7003 when Pragma_Atomic =>
7004 Process_Atomic_Shared_Volatile;
7006 -----------------------
7007 -- Atomic_Components --
7008 -----------------------
7010 -- pragma Atomic_Components (array_LOCAL_NAME);
7012 -- This processing is shared by Volatile_Components
7014 when Pragma_Atomic_Components |
7015 Pragma_Volatile_Components =>
7017 Atomic_Components : declare
7024 Check_Ada_83_Warning;
7025 Check_No_Identifiers;
7026 Check_Arg_Count (1);
7027 Check_Arg_Is_Local_Name (Arg1);
7028 E_Id := Get_Pragma_Arg (Arg1);
7030 if Etype (E_Id) = Any_Type then
7036 Check_Duplicate_Pragma (E);
7038 if Rep_Item_Too_Early (E, N)
7040 Rep_Item_Too_Late (E, N)
7045 D := Declaration_Node (E);
7048 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7050 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7051 and then Nkind (D) = N_Object_Declaration
7052 and then Nkind (Object_Definition (D)) =
7053 N_Constrained_Array_Definition)
7055 -- The flag is set on the object, or on the base type
7057 if Nkind (D) /= N_Object_Declaration then
7061 Set_Has_Volatile_Components (E);
7063 if Prag_Id = Pragma_Atomic_Components then
7064 Set_Has_Atomic_Components (E);
7068 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7070 end Atomic_Components;
7071 --------------------
7072 -- Attach_Handler --
7073 --------------------
7075 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7077 when Pragma_Attach_Handler =>
7078 Check_Ada_83_Warning;
7079 Check_No_Identifiers;
7080 Check_Arg_Count (2);
7082 if No_Run_Time_Mode then
7083 Error_Msg_CRT ("Attach_Handler pragma", N);
7085 Check_Interrupt_Or_Attach_Handler;
7087 -- The expression that designates the attribute may depend on a
7088 -- discriminant, and is therefore a per-object expression, to
7089 -- be expanded in the init proc. If expansion is enabled, then
7090 -- perform semantic checks on a copy only.
7092 if Expander_Active then
7094 Temp : constant Node_Id :=
7095 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7097 Set_Parent (Temp, N);
7098 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7102 Analyze (Get_Pragma_Arg (Arg2));
7103 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7106 Process_Interrupt_Or_Attach_Handler;
7109 --------------------
7110 -- C_Pass_By_Copy --
7111 --------------------
7113 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7115 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7121 Check_Valid_Configuration_Pragma;
7122 Check_Arg_Count (1);
7123 Check_Optional_Identifier (Arg1, "max_size");
7125 Arg := Get_Pragma_Arg (Arg1);
7126 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7128 Val := Expr_Value (Arg);
7132 ("maximum size for pragma% must be positive", Arg1);
7134 elsif UI_Is_In_Int_Range (Val) then
7135 Default_C_Record_Mechanism := UI_To_Int (Val);
7137 -- If a giant value is given, Int'Last will do well enough.
7138 -- If sometime someone complains that a record larger than
7139 -- two gigabytes is not copied, we will worry about it then!
7142 Default_C_Record_Mechanism := Mechanism_Type'Last;
7150 -- pragma Check ([Name =>] IDENTIFIER,
7151 -- [Check =>] Boolean_EXPRESSION
7152 -- [,[Message =>] String_EXPRESSION]);
7154 when Pragma_Check => Check : declare
7159 -- Set True if category of assertions referenced by Name enabled
7163 Check_At_Least_N_Arguments (2);
7164 Check_At_Most_N_Arguments (3);
7165 Check_Optional_Identifier (Arg1, Name_Name);
7166 Check_Optional_Identifier (Arg2, Name_Check);
7168 if Arg_Count = 3 then
7169 Check_Optional_Identifier (Arg3, Name_Message);
7170 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7173 Check_Arg_Is_Identifier (Arg1);
7175 -- Completely ignore if disabled
7177 if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7178 Rewrite (N, Make_Null_Statement (Loc));
7183 -- Indicate if pragma is enabled. The Original_Node reference here
7184 -- is to deal with pragma Assert rewritten as a Check pragma.
7186 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
7189 Set_SCO_Pragma_Enabled (Loc);
7192 -- If expansion is active and the check is not enabled then we
7193 -- rewrite the Check as:
7195 -- if False and then condition then
7199 -- The reason we do this rewriting during semantic analysis rather
7200 -- than as part of normal expansion is that we cannot analyze and
7201 -- expand the code for the boolean expression directly, or it may
7202 -- cause insertion of actions that would escape the attempt to
7203 -- suppress the check code.
7205 -- Note that the Sloc for the if statement corresponds to the
7206 -- argument condition, not the pragma itself. The reason for this
7207 -- is that we may generate a warning if the condition is False at
7208 -- compile time, and we do not want to delete this warning when we
7209 -- delete the if statement.
7211 Expr := Get_Pragma_Arg (Arg2);
7213 if Expander_Active and then not Check_On then
7214 Eloc := Sloc (Expr);
7217 Make_If_Statement (Eloc,
7219 Make_And_Then (Eloc,
7220 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7221 Right_Opnd => Expr),
7222 Then_Statements => New_List (
7223 Make_Null_Statement (Eloc))));
7230 Analyze_And_Resolve (Expr, Any_Boolean);
7238 -- pragma Check_Name (check_IDENTIFIER);
7240 when Pragma_Check_Name =>
7241 Check_No_Identifiers;
7243 Check_Valid_Configuration_Pragma;
7244 Check_Arg_Count (1);
7245 Check_Arg_Is_Identifier (Arg1);
7248 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7251 for J in Check_Names.First .. Check_Names.Last loop
7252 if Check_Names.Table (J) = Nam then
7257 Check_Names.Append (Nam);
7264 -- pragma Check_Policy (
7265 -- [Name =>] IDENTIFIER,
7266 -- [Policy =>] POLICY_IDENTIFIER);
7268 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7270 -- Note: this is a configuration pragma, but it is allowed to appear
7273 when Pragma_Check_Policy =>
7275 Check_Arg_Count (2);
7276 Check_Optional_Identifier (Arg1, Name_Name);
7277 Check_Optional_Identifier (Arg2, Name_Policy);
7279 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7281 -- A Check_Policy pragma can appear either as a configuration
7282 -- pragma, or in a declarative part or a package spec (see RM
7283 -- 11.5(5) for rules for Suppress/Unsuppress which are also
7284 -- followed for Check_Policy).
7286 if not Is_Configuration_Pragma then
7287 Check_Is_In_Decl_Part_Or_Package_Spec;
7290 Set_Next_Pragma (N, Opt.Check_Policy_List);
7291 Opt.Check_Policy_List := N;
7293 ---------------------
7294 -- CIL_Constructor --
7295 ---------------------
7297 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7299 -- Processing for this pragma is shared with Java_Constructor
7305 -- pragma Comment (static_string_EXPRESSION)
7307 -- Processing for pragma Comment shares the circuitry for pragma
7308 -- Ident. The only differences are that Ident enforces a limit of 31
7309 -- characters on its argument, and also enforces limitations on
7310 -- placement for DEC compatibility. Pragma Comment shares neither of
7311 -- these restrictions.
7317 -- pragma Common_Object (
7318 -- [Internal =>] LOCAL_NAME
7319 -- [, [External =>] EXTERNAL_SYMBOL]
7320 -- [, [Size =>] EXTERNAL_SYMBOL]);
7322 -- Processing for this pragma is shared with Psect_Object
7324 ------------------------
7325 -- Compile_Time_Error --
7326 ------------------------
7328 -- pragma Compile_Time_Error
7329 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7331 when Pragma_Compile_Time_Error =>
7333 Process_Compile_Time_Warning_Or_Error;
7335 --------------------------
7336 -- Compile_Time_Warning --
7337 --------------------------
7339 -- pragma Compile_Time_Warning
7340 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7342 when Pragma_Compile_Time_Warning =>
7344 Process_Compile_Time_Warning_Or_Error;
7350 when Pragma_Compiler_Unit =>
7352 Check_Arg_Count (0);
7353 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7355 -----------------------------
7356 -- Complete_Representation --
7357 -----------------------------
7359 -- pragma Complete_Representation;
7361 when Pragma_Complete_Representation =>
7363 Check_Arg_Count (0);
7365 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7367 ("pragma & must appear within record representation clause");
7370 ----------------------------
7371 -- Complex_Representation --
7372 ----------------------------
7374 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7376 when Pragma_Complex_Representation => Complex_Representation : declare
7383 Check_Arg_Count (1);
7384 Check_Optional_Identifier (Arg1, Name_Entity);
7385 Check_Arg_Is_Local_Name (Arg1);
7386 E_Id := Get_Pragma_Arg (Arg1);
7388 if Etype (E_Id) = Any_Type then
7394 if not Is_Record_Type (E) then
7396 ("argument for pragma% must be record type", Arg1);
7399 Ent := First_Entity (E);
7402 or else No (Next_Entity (Ent))
7403 or else Present (Next_Entity (Next_Entity (Ent)))
7404 or else not Is_Floating_Point_Type (Etype (Ent))
7405 or else Etype (Ent) /= Etype (Next_Entity (Ent))
7408 ("record for pragma% must have two fields of the same "
7409 & "floating-point type", Arg1);
7412 Set_Has_Complex_Representation (Base_Type (E));
7414 -- We need to treat the type has having a non-standard
7415 -- representation, for back-end purposes, even though in
7416 -- general a complex will have the default representation
7417 -- of a record with two real components.
7419 Set_Has_Non_Standard_Rep (Base_Type (E));
7421 end Complex_Representation;
7423 -------------------------
7424 -- Component_Alignment --
7425 -------------------------
7427 -- pragma Component_Alignment (
7428 -- [Form =>] ALIGNMENT_CHOICE
7429 -- [, [Name =>] type_LOCAL_NAME]);
7431 -- ALIGNMENT_CHOICE ::=
7433 -- | Component_Size_4
7437 when Pragma_Component_Alignment => Component_AlignmentP : declare
7438 Args : Args_List (1 .. 2);
7439 Names : constant Name_List (1 .. 2) := (
7443 Form : Node_Id renames Args (1);
7444 Name : Node_Id renames Args (2);
7446 Atype : Component_Alignment_Kind;
7451 Gather_Associations (Names, Args);
7454 Error_Pragma ("missing Form argument for pragma%");
7457 Check_Arg_Is_Identifier (Form);
7459 -- Get proper alignment, note that Default = Component_Size on all
7460 -- machines we have so far, and we want to set this value rather
7461 -- than the default value to indicate that it has been explicitly
7462 -- set (and thus will not get overridden by the default component
7463 -- alignment for the current scope)
7465 if Chars (Form) = Name_Component_Size then
7466 Atype := Calign_Component_Size;
7468 elsif Chars (Form) = Name_Component_Size_4 then
7469 Atype := Calign_Component_Size_4;
7471 elsif Chars (Form) = Name_Default then
7472 Atype := Calign_Component_Size;
7474 elsif Chars (Form) = Name_Storage_Unit then
7475 Atype := Calign_Storage_Unit;
7479 ("invalid Form parameter for pragma%", Form);
7482 -- Case with no name, supplied, affects scope table entry
7486 (Scope_Stack.Last).Component_Alignment_Default := Atype;
7488 -- Case of name supplied
7491 Check_Arg_Is_Local_Name (Name);
7493 Typ := Entity (Name);
7496 or else Rep_Item_Too_Early (Typ, N)
7500 Typ := Underlying_Type (Typ);
7503 if not Is_Record_Type (Typ)
7504 and then not Is_Array_Type (Typ)
7507 ("Name parameter of pragma% must identify record or " &
7508 "array type", Name);
7511 -- An explicit Component_Alignment pragma overrides an
7512 -- implicit pragma Pack, but not an explicit one.
7514 if not Has_Pragma_Pack (Base_Type (Typ)) then
7515 Set_Is_Packed (Base_Type (Typ), False);
7516 Set_Component_Alignment (Base_Type (Typ), Atype);
7519 end Component_AlignmentP;
7525 -- pragma Controlled (first_subtype_LOCAL_NAME);
7527 when Pragma_Controlled => Controlled : declare
7531 Check_No_Identifiers;
7532 Check_Arg_Count (1);
7533 Check_Arg_Is_Local_Name (Arg1);
7534 Arg := Get_Pragma_Arg (Arg1);
7536 if not Is_Entity_Name (Arg)
7537 or else not Is_Access_Type (Entity (Arg))
7539 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7541 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7549 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
7550 -- [Entity =>] LOCAL_NAME);
7552 when Pragma_Convention => Convention : declare
7555 pragma Warnings (Off, C);
7556 pragma Warnings (Off, E);
7558 Check_Arg_Order ((Name_Convention, Name_Entity));
7559 Check_Ada_83_Warning;
7560 Check_Arg_Count (2);
7561 Process_Convention (C, E);
7564 ---------------------------
7565 -- Convention_Identifier --
7566 ---------------------------
7568 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7569 -- [Convention =>] convention_IDENTIFIER);
7571 when Pragma_Convention_Identifier => Convention_Identifier : declare
7577 Check_Arg_Order ((Name_Name, Name_Convention));
7578 Check_Arg_Count (2);
7579 Check_Optional_Identifier (Arg1, Name_Name);
7580 Check_Optional_Identifier (Arg2, Name_Convention);
7581 Check_Arg_Is_Identifier (Arg1);
7582 Check_Arg_Is_Identifier (Arg2);
7583 Idnam := Chars (Get_Pragma_Arg (Arg1));
7584 Cname := Chars (Get_Pragma_Arg (Arg2));
7586 if Is_Convention_Name (Cname) then
7587 Record_Convention_Identifier
7588 (Idnam, Get_Convention_Id (Cname));
7591 ("second arg for % pragma must be convention", Arg2);
7593 end Convention_Identifier;
7599 -- pragma CPP_Class ([Entity =>] local_NAME)
7601 when Pragma_CPP_Class => CPP_Class : declare
7606 if Warn_On_Obsolescent_Feature then
7608 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7609 " by pragma import?", N);
7613 Check_Arg_Count (1);
7614 Check_Optional_Identifier (Arg1, Name_Entity);
7615 Check_Arg_Is_Local_Name (Arg1);
7617 Arg := Get_Pragma_Arg (Arg1);
7620 if Etype (Arg) = Any_Type then
7624 if not Is_Entity_Name (Arg)
7625 or else not Is_Type (Entity (Arg))
7627 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7630 Typ := Entity (Arg);
7632 if not Is_Tagged_Type (Typ) then
7633 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7636 -- Types treated as CPP classes must be declared limited (note:
7637 -- this used to be a warning but there is no real benefit to it
7638 -- since we did effectively intend to treat the type as limited
7641 if not Is_Limited_Type (Typ) then
7643 ("imported 'C'P'P type must be limited",
7644 Get_Pragma_Arg (Arg1));
7647 Set_Is_CPP_Class (Typ);
7648 Set_Convention (Typ, Convention_CPP);
7650 -- Imported CPP types must not have discriminants (because C++
7651 -- classes do not have discriminants).
7653 if Has_Discriminants (Typ) then
7655 ("imported 'C'P'P type cannot have discriminants",
7656 First (Discriminant_Specifications
7657 (Declaration_Node (Typ))));
7660 -- Components of imported CPP types must not have default
7661 -- expressions because the constructor (if any) is in the
7664 if Is_Incomplete_Or_Private_Type (Typ)
7665 and then No (Underlying_Type (Typ))
7667 -- It should be an error to apply pragma CPP to a private
7668 -- type if the underlying type is not visible (as it is
7669 -- for any representation item). For now, for backward
7670 -- compatibility we do nothing but we cannot check components
7671 -- because they are not available at this stage. All this code
7672 -- will be removed when we cleanup this obsolete GNAT pragma???
7678 Tdef : constant Node_Id :=
7679 Type_Definition (Declaration_Node (Typ));
7684 if Nkind (Tdef) = N_Record_Definition then
7685 Clist := Component_List (Tdef);
7687 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7688 Clist := Component_List (Record_Extension_Part (Tdef));
7691 if Present (Clist) then
7692 Comp := First (Component_Items (Clist));
7693 while Present (Comp) loop
7694 if Present (Expression (Comp)) then
7696 ("component of imported 'C'P'P type cannot have" &
7697 " default expression", Expression (Comp));
7707 ---------------------
7708 -- CPP_Constructor --
7709 ---------------------
7711 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7712 -- [, [External_Name =>] static_string_EXPRESSION ]
7713 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7715 when Pragma_CPP_Constructor => CPP_Constructor : declare
7719 Tag_Typ : Entity_Id;
7723 Check_At_Least_N_Arguments (1);
7724 Check_At_Most_N_Arguments (3);
7725 Check_Optional_Identifier (Arg1, Name_Entity);
7726 Check_Arg_Is_Local_Name (Arg1);
7728 Id := Get_Pragma_Arg (Arg1);
7729 Find_Program_Unit_Name (Id);
7731 -- If we did not find the name, we are done
7733 if Etype (Id) = Any_Type then
7737 Def_Id := Entity (Id);
7739 -- Check if already defined as constructor
7741 if Is_Constructor (Def_Id) then
7743 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7747 if Ekind (Def_Id) = E_Function
7748 and then (Is_CPP_Class (Etype (Def_Id))
7749 or else (Is_Class_Wide_Type (Etype (Def_Id))
7751 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7753 if Arg_Count >= 2 then
7754 Set_Imported (Def_Id);
7755 Set_Is_Public (Def_Id);
7756 Process_Interface_Name (Def_Id, Arg2, Arg3);
7759 Set_Has_Completion (Def_Id);
7760 Set_Is_Constructor (Def_Id);
7762 -- Imported C++ constructors are not dispatching primitives
7763 -- because in C++ they don't have a dispatch table slot.
7764 -- However, in Ada the constructor has the profile of a
7765 -- function that returns a tagged type and therefore it has
7766 -- been treated as a primitive operation during semantic
7767 -- analysis. We now remove it from the list of primitive
7768 -- operations of the type.
7770 if Is_Tagged_Type (Etype (Def_Id))
7771 and then not Is_Class_Wide_Type (Etype (Def_Id))
7773 pragma Assert (Is_Dispatching_Operation (Def_Id));
7774 Tag_Typ := Etype (Def_Id);
7776 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7777 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7781 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7782 Set_Is_Dispatching_Operation (Def_Id, False);
7785 -- For backward compatibility, if the constructor returns a
7786 -- class wide type, and we internally change the return type to
7787 -- the corresponding root type.
7789 if Is_Class_Wide_Type (Etype (Def_Id)) then
7790 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7794 ("pragma% requires function returning a 'C'P'P_Class type",
7797 end CPP_Constructor;
7803 when Pragma_CPP_Virtual => CPP_Virtual : declare
7807 if Warn_On_Obsolescent_Feature then
7809 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7818 when Pragma_CPP_Vtable => CPP_Vtable : declare
7822 if Warn_On_Obsolescent_Feature then
7824 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7833 -- pragma CPU (EXPRESSION);
7835 when Pragma_CPU => CPU : declare
7836 P : constant Node_Id := Parent (N);
7841 Check_No_Identifiers;
7842 Check_Arg_Count (1);
7846 if Nkind (P) = N_Subprogram_Body then
7847 Check_In_Main_Program;
7849 Arg := Get_Pragma_Arg (Arg1);
7850 Analyze_And_Resolve (Arg, Any_Integer);
7854 if not Is_Static_Expression (Arg) then
7855 Flag_Non_Static_Expr
7856 ("main subprogram affinity is not static!", Arg);
7859 -- If constraint error, then we already signalled an error
7861 elsif Raises_Constraint_Error (Arg) then
7864 -- Otherwise check in range
7868 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7869 -- This is the entity System.Multiprocessors.CPU_Range;
7871 Val : constant Uint := Expr_Value (Arg);
7874 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7876 Val > Expr_Value (Type_High_Bound (CPU_Id))
7879 ("main subprogram CPU is out of range", Arg1);
7885 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7889 elsif Nkind (P) = N_Task_Definition then
7890 Arg := Get_Pragma_Arg (Arg1);
7892 -- The expression must be analyzed in the special manner
7893 -- described in "Handling of Default and Per-Object
7894 -- Expressions" in sem.ads.
7896 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7898 -- Anything else is incorrect
7904 if Has_Pragma_CPU (P) then
7905 Error_Pragma ("duplicate pragma% not allowed");
7907 Set_Has_Pragma_CPU (P, True);
7909 if Nkind (P) = N_Task_Definition then
7910 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7919 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7921 when Pragma_Debug => Debug : declare
7928 -- Skip analysis if disabled
7930 if Debug_Pragmas_Disabled then
7931 Rewrite (N, Make_Null_Statement (Loc));
7938 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7941 if Debug_Pragmas_Enabled then
7942 Set_SCO_Pragma_Enabled (Loc);
7945 if Arg_Count = 2 then
7948 Left_Opnd => Relocate_Node (Cond),
7949 Right_Opnd => Get_Pragma_Arg (Arg1));
7950 Call := Get_Pragma_Arg (Arg2);
7952 Call := Get_Pragma_Arg (Arg1);
7956 N_Indexed_Component,
7960 N_Selected_Component)
7962 -- If this pragma Debug comes from source, its argument was
7963 -- parsed as a name form (which is syntactically identical).
7964 -- In a generic context a parameterless call will be left as
7965 -- an expanded name (if global) or selected_component if local.
7966 -- Change it to a procedure call statement now.
7968 Change_Name_To_Procedure_Call_Statement (Call);
7970 elsif Nkind (Call) = N_Procedure_Call_Statement then
7972 -- Already in the form of a procedure call statement: nothing
7973 -- to do (could happen in case of an internally generated
7979 -- All other cases: diagnose error
7982 ("argument of pragma ""Debug"" is not procedure call",
7987 -- Rewrite into a conditional with an appropriate condition. We
7988 -- wrap the procedure call in a block so that overhead from e.g.
7989 -- use of the secondary stack does not generate execution overhead
7990 -- for suppressed conditions.
7992 -- Normally the analysis that follows will freeze the subprogram
7993 -- being called. However, if the call is to a null procedure,
7994 -- we want to freeze it before creating the block, because the
7995 -- analysis that follows may be done with expansion disabled, in
7996 -- which case the body will not be generated, leading to spurious
7999 if Nkind (Call) = N_Procedure_Call_Statement
8000 and then Is_Entity_Name (Name (Call))
8002 Analyze (Name (Call));
8003 Freeze_Before (N, Entity (Name (Call)));
8006 Rewrite (N, Make_Implicit_If_Statement (N,
8008 Then_Statements => New_List (
8009 Make_Block_Statement (Loc,
8010 Handled_Statement_Sequence =>
8011 Make_Handled_Sequence_Of_Statements (Loc,
8012 Statements => New_List (Relocate_Node (Call)))))));
8020 -- pragma Debug_Policy (Check | Ignore)
8022 when Pragma_Debug_Policy =>
8024 Check_Arg_Count (1);
8025 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
8026 Debug_Pragmas_Enabled :=
8027 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
8028 Debug_Pragmas_Disabled :=
8029 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
8031 ---------------------
8032 -- Detect_Blocking --
8033 ---------------------
8035 -- pragma Detect_Blocking;
8037 when Pragma_Detect_Blocking =>
8039 Check_Arg_Count (0);
8040 Check_Valid_Configuration_Pragma;
8041 Detect_Blocking := True;
8043 --------------------------
8044 -- Default_Storage_Pool --
8045 --------------------------
8047 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
8049 when Pragma_Default_Storage_Pool =>
8051 Check_Arg_Count (1);
8053 -- Default_Storage_Pool can appear as a configuration pragma, or
8054 -- in a declarative part or a package spec.
8056 if not Is_Configuration_Pragma then
8057 Check_Is_In_Decl_Part_Or_Package_Spec;
8060 -- Case of Default_Storage_Pool (null);
8062 if Nkind (Expression (Arg1)) = N_Null then
8063 Analyze (Expression (Arg1));
8065 -- This is an odd case, this is not really an expression, so
8066 -- we don't have a type for it. So just set the type to Empty.
8068 Set_Etype (Expression (Arg1), Empty);
8070 -- Case of Default_Storage_Pool (storage_pool_NAME);
8073 -- If it's a configuration pragma, then the only allowed
8074 -- argument is "null".
8076 if Is_Configuration_Pragma then
8077 Error_Pragma_Arg ("NULL expected", Arg1);
8080 -- The expected type for a non-"null" argument is
8081 -- Root_Storage_Pool'Class.
8084 (Get_Pragma_Arg (Arg1),
8085 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8088 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
8089 -- for an access type will use this information to set the
8090 -- appropriate attributes of the access type.
8092 Default_Pool := Expression (Arg1);
8094 ------------------------------------
8095 -- Disable_Atomic_Synchronization --
8096 ------------------------------------
8098 -- pragma Disable_Atomic_Synchronization [(Entity)];
8100 when Pragma_Disable_Atomic_Synchronization =>
8101 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8107 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
8109 when Pragma_Discard_Names => Discard_Names : declare
8114 Check_Ada_83_Warning;
8116 -- Deal with configuration pragma case
8118 if Arg_Count = 0 and then Is_Configuration_Pragma then
8119 Global_Discard_Names := True;
8122 -- Otherwise, check correct appropriate context
8125 Check_Is_In_Decl_Part_Or_Package_Spec;
8127 if Arg_Count = 0 then
8129 -- If there is no parameter, then from now on this pragma
8130 -- applies to any enumeration, exception or tagged type
8131 -- defined in the current declarative part, and recursively
8132 -- to any nested scope.
8134 Set_Discard_Names (Current_Scope);
8138 Check_Arg_Count (1);
8139 Check_Optional_Identifier (Arg1, Name_On);
8140 Check_Arg_Is_Local_Name (Arg1);
8142 E_Id := Get_Pragma_Arg (Arg1);
8144 if Etype (E_Id) = Any_Type then
8150 if (Is_First_Subtype (E)
8152 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8153 or else Ekind (E) = E_Exception
8155 Set_Discard_Names (E);
8158 ("inappropriate entity for pragma%", Arg1);
8165 ------------------------
8166 -- Dispatching_Domain --
8167 ------------------------
8169 -- pragma Dispatching_Domain (EXPRESSION);
8171 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8172 P : constant Node_Id := Parent (N);
8177 Check_No_Identifiers;
8178 Check_Arg_Count (1);
8180 -- This pragma is born obsolete, but not the aspect
8182 if not From_Aspect_Specification (N) then
8184 (No_Obsolescent_Features, Pragma_Identifier (N));
8187 if Nkind (P) = N_Task_Definition then
8188 Arg := Get_Pragma_Arg (Arg1);
8190 -- The expression must be analyzed in the special manner
8191 -- described in "Handling of Default and Per-Object
8192 -- Expressions" in sem.ads.
8194 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8196 -- Anything else is incorrect
8202 if Has_Pragma_Dispatching_Domain (P) then
8203 Error_Pragma ("duplicate pragma% not allowed");
8205 Set_Has_Pragma_Dispatching_Domain (P, True);
8207 if Nkind (P) = N_Task_Definition then
8208 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8211 end Dispatching_Domain;
8217 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8219 when Pragma_Elaborate => Elaborate : declare
8224 -- Pragma must be in context items list of a compilation unit
8226 if not Is_In_Context_Clause then
8230 -- Must be at least one argument
8232 if Arg_Count = 0 then
8233 Error_Pragma ("pragma% requires at least one argument");
8236 -- In Ada 83 mode, there can be no items following it in the
8237 -- context list except other pragmas and implicit with clauses
8238 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8239 -- placement rule does not apply.
8241 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8243 while Present (Citem) loop
8244 if Nkind (Citem) = N_Pragma
8245 or else (Nkind (Citem) = N_With_Clause
8246 and then Implicit_With (Citem))
8251 ("(Ada 83) pragma% must be at end of context clause");
8258 -- Finally, the arguments must all be units mentioned in a with
8259 -- clause in the same context clause. Note we already checked (in
8260 -- Par.Prag) that the arguments are all identifiers or selected
8264 Outer : while Present (Arg) loop
8265 Citem := First (List_Containing (N));
8266 Inner : while Citem /= N loop
8267 if Nkind (Citem) = N_With_Clause
8268 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8270 Set_Elaborate_Present (Citem, True);
8271 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8272 Generate_Reference (Entity (Name (Citem)), Citem);
8274 -- With the pragma present, elaboration calls on
8275 -- subprograms from the named unit need no further
8276 -- checks, as long as the pragma appears in the current
8277 -- compilation unit. If the pragma appears in some unit
8278 -- in the context, there might still be a need for an
8279 -- Elaborate_All_Desirable from the current compilation
8280 -- to the named unit, so we keep the check enabled.
8282 if In_Extended_Main_Source_Unit (N) then
8283 Set_Suppress_Elaboration_Warnings
8284 (Entity (Name (Citem)));
8295 ("argument of pragma% is not withed unit", Arg);
8301 -- Give a warning if operating in static mode with -gnatwl
8302 -- (elaboration warnings enabled) switch set.
8304 if Elab_Warnings and not Dynamic_Elaboration_Checks then
8306 ("?use of pragma Elaborate may not be safe", N);
8308 ("?use pragma Elaborate_All instead if possible", N);
8316 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8318 when Pragma_Elaborate_All => Elaborate_All : declare
8323 Check_Ada_83_Warning;
8325 -- Pragma must be in context items list of a compilation unit
8327 if not Is_In_Context_Clause then
8331 -- Must be at least one argument
8333 if Arg_Count = 0 then
8334 Error_Pragma ("pragma% requires at least one argument");
8337 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
8338 -- have to appear at the end of the context clause, but may
8339 -- appear mixed in with other items, even in Ada 83 mode.
8341 -- Final check: the arguments must all be units mentioned in
8342 -- a with clause in the same context clause. Note that we
8343 -- already checked (in Par.Prag) that all the arguments are
8344 -- either identifiers or selected components.
8347 Outr : while Present (Arg) loop
8348 Citem := First (List_Containing (N));
8349 Innr : while Citem /= N loop
8350 if Nkind (Citem) = N_With_Clause
8351 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8353 Set_Elaborate_All_Present (Citem, True);
8354 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8356 -- Suppress warnings and elaboration checks on the named
8357 -- unit if the pragma is in the current compilation, as
8358 -- for pragma Elaborate.
8360 if In_Extended_Main_Source_Unit (N) then
8361 Set_Suppress_Elaboration_Warnings
8362 (Entity (Name (Citem)));
8371 Set_Error_Posted (N);
8373 ("argument of pragma% is not withed unit", Arg);
8380 --------------------
8381 -- Elaborate_Body --
8382 --------------------
8384 -- pragma Elaborate_Body [( library_unit_NAME )];
8386 when Pragma_Elaborate_Body => Elaborate_Body : declare
8387 Cunit_Node : Node_Id;
8388 Cunit_Ent : Entity_Id;
8391 Check_Ada_83_Warning;
8392 Check_Valid_Library_Unit_Pragma;
8394 if Nkind (N) = N_Null_Statement then
8398 Cunit_Node := Cunit (Current_Sem_Unit);
8399 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8401 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8404 Error_Pragma ("pragma% must refer to a spec, not a body");
8406 Set_Body_Required (Cunit_Node, True);
8407 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8409 -- If we are in dynamic elaboration mode, then we suppress
8410 -- elaboration warnings for the unit, since it is definitely
8411 -- fine NOT to do dynamic checks at the first level (and such
8412 -- checks will be suppressed because no elaboration boolean
8413 -- is created for Elaborate_Body packages).
8415 -- But in the static model of elaboration, Elaborate_Body is
8416 -- definitely NOT good enough to ensure elaboration safety on
8417 -- its own, since the body may WITH other units that are not
8418 -- safe from an elaboration point of view, so a client must
8419 -- still do an Elaborate_All on such units.
8421 -- Debug flag -gnatdD restores the old behavior of 3.13, where
8422 -- Elaborate_Body always suppressed elab warnings.
8424 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8425 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8430 ------------------------
8431 -- Elaboration_Checks --
8432 ------------------------
8434 -- pragma Elaboration_Checks (Static | Dynamic);
8436 when Pragma_Elaboration_Checks =>
8438 Check_Arg_Count (1);
8439 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8440 Dynamic_Elaboration_Checks :=
8441 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8447 -- pragma Eliminate (
8448 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
8449 -- [,[Entity =>] IDENTIFIER |
8450 -- SELECTED_COMPONENT |
8452 -- [, OVERLOADING_RESOLUTION]);
8454 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8457 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8460 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8462 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8463 -- Result_Type => result_SUBTYPE_NAME]
8465 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8466 -- SUBTYPE_NAME ::= STRING_LITERAL
8468 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8469 -- SOURCE_TRACE ::= STRING_LITERAL
8471 when Pragma_Eliminate => Eliminate : declare
8472 Args : Args_List (1 .. 5);
8473 Names : constant Name_List (1 .. 5) := (
8476 Name_Parameter_Types,
8478 Name_Source_Location);
8480 Unit_Name : Node_Id renames Args (1);
8481 Entity : Node_Id renames Args (2);
8482 Parameter_Types : Node_Id renames Args (3);
8483 Result_Type : Node_Id renames Args (4);
8484 Source_Location : Node_Id renames Args (5);
8488 Check_Valid_Configuration_Pragma;
8489 Gather_Associations (Names, Args);
8491 if No (Unit_Name) then
8492 Error_Pragma ("missing Unit_Name argument for pragma%");
8496 and then (Present (Parameter_Types)
8498 Present (Result_Type)
8500 Present (Source_Location))
8502 Error_Pragma ("missing Entity argument for pragma%");
8505 if (Present (Parameter_Types)
8507 Present (Result_Type))
8509 Present (Source_Location)
8512 ("parameter profile and source location cannot " &
8513 "be used together in pragma%");
8516 Process_Eliminate_Pragma
8525 -----------------------------------
8526 -- Enable_Atomic_Synchronization --
8527 -----------------------------------
8529 -- pragma Enable_Atomic_Synchronization [(Entity)];
8531 when Pragma_Enable_Atomic_Synchronization =>
8532 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
8539 -- [ Convention =>] convention_IDENTIFIER,
8540 -- [ Entity =>] local_NAME
8541 -- [, [External_Name =>] static_string_EXPRESSION ]
8542 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8544 when Pragma_Export => Export : declare
8548 pragma Warnings (Off, C);
8551 Check_Ada_83_Warning;
8557 Check_At_Least_N_Arguments (2);
8558 Check_At_Most_N_Arguments (4);
8559 Process_Convention (C, Def_Id);
8561 if Ekind (Def_Id) /= E_Constant then
8562 Note_Possible_Modification
8563 (Get_Pragma_Arg (Arg2), Sure => False);
8566 Process_Interface_Name (Def_Id, Arg3, Arg4);
8567 Set_Exported (Def_Id, Arg2);
8569 -- If the entity is a deferred constant, propagate the information
8570 -- to the full view, because gigi elaborates the full view only.
8572 if Ekind (Def_Id) = E_Constant
8573 and then Present (Full_View (Def_Id))
8576 Id2 : constant Entity_Id := Full_View (Def_Id);
8578 Set_Is_Exported (Id2, Is_Exported (Def_Id));
8579 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
8580 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8585 ----------------------
8586 -- Export_Exception --
8587 ----------------------
8589 -- pragma Export_Exception (
8590 -- [Internal =>] LOCAL_NAME
8591 -- [, [External =>] EXTERNAL_SYMBOL]
8592 -- [, [Form =>] Ada | VMS]
8593 -- [, [Code =>] static_integer_EXPRESSION]);
8595 when Pragma_Export_Exception => Export_Exception : declare
8596 Args : Args_List (1 .. 4);
8597 Names : constant Name_List (1 .. 4) := (
8603 Internal : Node_Id renames Args (1);
8604 External : Node_Id renames Args (2);
8605 Form : Node_Id renames Args (3);
8606 Code : Node_Id renames Args (4);
8611 if Inside_A_Generic then
8612 Error_Pragma ("pragma% cannot be used for generic entities");
8615 Gather_Associations (Names, Args);
8616 Process_Extended_Import_Export_Exception_Pragma (
8617 Arg_Internal => Internal,
8618 Arg_External => External,
8622 if not Is_VMS_Exception (Entity (Internal)) then
8623 Set_Exported (Entity (Internal), Internal);
8625 end Export_Exception;
8627 ---------------------
8628 -- Export_Function --
8629 ---------------------
8631 -- pragma Export_Function (
8632 -- [Internal =>] LOCAL_NAME
8633 -- [, [External =>] EXTERNAL_SYMBOL]
8634 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8635 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8636 -- [, [Mechanism =>] MECHANISM]
8637 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8639 -- EXTERNAL_SYMBOL ::=
8641 -- | static_string_EXPRESSION
8643 -- PARAMETER_TYPES ::=
8645 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8647 -- TYPE_DESIGNATOR ::=
8649 -- | subtype_Name ' Access
8653 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8655 -- MECHANISM_ASSOCIATION ::=
8656 -- [formal_parameter_NAME =>] MECHANISM_NAME
8658 -- MECHANISM_NAME ::=
8661 -- | Descriptor [([Class =>] CLASS_NAME)]
8663 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8665 when Pragma_Export_Function => Export_Function : declare
8666 Args : Args_List (1 .. 6);
8667 Names : constant Name_List (1 .. 6) := (
8670 Name_Parameter_Types,
8673 Name_Result_Mechanism);
8675 Internal : Node_Id renames Args (1);
8676 External : Node_Id renames Args (2);
8677 Parameter_Types : Node_Id renames Args (3);
8678 Result_Type : Node_Id renames Args (4);
8679 Mechanism : Node_Id renames Args (5);
8680 Result_Mechanism : Node_Id renames Args (6);
8684 Gather_Associations (Names, Args);
8685 Process_Extended_Import_Export_Subprogram_Pragma (
8686 Arg_Internal => Internal,
8687 Arg_External => External,
8688 Arg_Parameter_Types => Parameter_Types,
8689 Arg_Result_Type => Result_Type,
8690 Arg_Mechanism => Mechanism,
8691 Arg_Result_Mechanism => Result_Mechanism);
8692 end Export_Function;
8698 -- pragma Export_Object (
8699 -- [Internal =>] LOCAL_NAME
8700 -- [, [External =>] EXTERNAL_SYMBOL]
8701 -- [, [Size =>] EXTERNAL_SYMBOL]);
8703 -- EXTERNAL_SYMBOL ::=
8705 -- | static_string_EXPRESSION
8707 -- PARAMETER_TYPES ::=
8709 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8711 -- TYPE_DESIGNATOR ::=
8713 -- | subtype_Name ' Access
8717 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8719 -- MECHANISM_ASSOCIATION ::=
8720 -- [formal_parameter_NAME =>] MECHANISM_NAME
8722 -- MECHANISM_NAME ::=
8725 -- | Descriptor [([Class =>] CLASS_NAME)]
8727 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8729 when Pragma_Export_Object => Export_Object : declare
8730 Args : Args_List (1 .. 3);
8731 Names : constant Name_List (1 .. 3) := (
8736 Internal : Node_Id renames Args (1);
8737 External : Node_Id renames Args (2);
8738 Size : Node_Id renames Args (3);
8742 Gather_Associations (Names, Args);
8743 Process_Extended_Import_Export_Object_Pragma (
8744 Arg_Internal => Internal,
8745 Arg_External => External,
8749 ----------------------
8750 -- Export_Procedure --
8751 ----------------------
8753 -- pragma Export_Procedure (
8754 -- [Internal =>] LOCAL_NAME
8755 -- [, [External =>] EXTERNAL_SYMBOL]
8756 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8757 -- [, [Mechanism =>] MECHANISM]);
8759 -- EXTERNAL_SYMBOL ::=
8761 -- | static_string_EXPRESSION
8763 -- PARAMETER_TYPES ::=
8765 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8767 -- TYPE_DESIGNATOR ::=
8769 -- | subtype_Name ' Access
8773 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8775 -- MECHANISM_ASSOCIATION ::=
8776 -- [formal_parameter_NAME =>] MECHANISM_NAME
8778 -- MECHANISM_NAME ::=
8781 -- | Descriptor [([Class =>] CLASS_NAME)]
8783 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8785 when Pragma_Export_Procedure => Export_Procedure : declare
8786 Args : Args_List (1 .. 4);
8787 Names : constant Name_List (1 .. 4) := (
8790 Name_Parameter_Types,
8793 Internal : Node_Id renames Args (1);
8794 External : Node_Id renames Args (2);
8795 Parameter_Types : Node_Id renames Args (3);
8796 Mechanism : Node_Id renames Args (4);
8800 Gather_Associations (Names, Args);
8801 Process_Extended_Import_Export_Subprogram_Pragma (
8802 Arg_Internal => Internal,
8803 Arg_External => External,
8804 Arg_Parameter_Types => Parameter_Types,
8805 Arg_Mechanism => Mechanism);
8806 end Export_Procedure;
8812 -- pragma Export_Value (
8813 -- [Value =>] static_integer_EXPRESSION,
8814 -- [Link_Name =>] static_string_EXPRESSION);
8816 when Pragma_Export_Value =>
8818 Check_Arg_Order ((Name_Value, Name_Link_Name));
8819 Check_Arg_Count (2);
8821 Check_Optional_Identifier (Arg1, Name_Value);
8822 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8824 Check_Optional_Identifier (Arg2, Name_Link_Name);
8825 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8827 -----------------------------
8828 -- Export_Valued_Procedure --
8829 -----------------------------
8831 -- pragma Export_Valued_Procedure (
8832 -- [Internal =>] LOCAL_NAME
8833 -- [, [External =>] EXTERNAL_SYMBOL,]
8834 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8835 -- [, [Mechanism =>] MECHANISM]);
8837 -- EXTERNAL_SYMBOL ::=
8839 -- | static_string_EXPRESSION
8841 -- PARAMETER_TYPES ::=
8843 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8845 -- TYPE_DESIGNATOR ::=
8847 -- | subtype_Name ' Access
8851 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8853 -- MECHANISM_ASSOCIATION ::=
8854 -- [formal_parameter_NAME =>] MECHANISM_NAME
8856 -- MECHANISM_NAME ::=
8859 -- | Descriptor [([Class =>] CLASS_NAME)]
8861 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8863 when Pragma_Export_Valued_Procedure =>
8864 Export_Valued_Procedure : declare
8865 Args : Args_List (1 .. 4);
8866 Names : constant Name_List (1 .. 4) := (
8869 Name_Parameter_Types,
8872 Internal : Node_Id renames Args (1);
8873 External : Node_Id renames Args (2);
8874 Parameter_Types : Node_Id renames Args (3);
8875 Mechanism : Node_Id renames Args (4);
8879 Gather_Associations (Names, Args);
8880 Process_Extended_Import_Export_Subprogram_Pragma (
8881 Arg_Internal => Internal,
8882 Arg_External => External,
8883 Arg_Parameter_Types => Parameter_Types,
8884 Arg_Mechanism => Mechanism);
8885 end Export_Valued_Procedure;
8891 -- pragma Extend_System ([Name =>] Identifier);
8893 when Pragma_Extend_System => Extend_System : declare
8896 Check_Valid_Configuration_Pragma;
8897 Check_Arg_Count (1);
8898 Check_Optional_Identifier (Arg1, Name_Name);
8899 Check_Arg_Is_Identifier (Arg1);
8901 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8904 and then Name_Buffer (1 .. 4) = "aux_"
8906 if Present (System_Extend_Pragma_Arg) then
8907 if Chars (Get_Pragma_Arg (Arg1)) =
8908 Chars (Expression (System_Extend_Pragma_Arg))
8912 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8913 Error_Pragma ("pragma% conflicts with that #");
8917 System_Extend_Pragma_Arg := Arg1;
8919 if not GNAT_Mode then
8920 System_Extend_Unit := Arg1;
8924 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8928 ------------------------
8929 -- Extensions_Allowed --
8930 ------------------------
8932 -- pragma Extensions_Allowed (ON | OFF);
8934 when Pragma_Extensions_Allowed =>
8936 Check_Arg_Count (1);
8937 Check_No_Identifiers;
8938 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8940 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8941 Extensions_Allowed := True;
8942 Ada_Version := Ada_Version_Type'Last;
8945 Extensions_Allowed := False;
8946 Ada_Version := Ada_Version_Explicit;
8953 -- pragma External (
8954 -- [ Convention =>] convention_IDENTIFIER,
8955 -- [ Entity =>] local_NAME
8956 -- [, [External_Name =>] static_string_EXPRESSION ]
8957 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8959 when Pragma_External => External : declare
8963 pragma Warnings (Off, C);
8972 Check_At_Least_N_Arguments (2);
8973 Check_At_Most_N_Arguments (4);
8974 Process_Convention (C, Def_Id);
8975 Note_Possible_Modification
8976 (Get_Pragma_Arg (Arg2), Sure => False);
8977 Process_Interface_Name (Def_Id, Arg3, Arg4);
8978 Set_Exported (Def_Id, Arg2);
8981 --------------------------
8982 -- External_Name_Casing --
8983 --------------------------
8985 -- pragma External_Name_Casing (
8986 -- UPPERCASE | LOWERCASE
8987 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8989 when Pragma_External_Name_Casing => External_Name_Casing : declare
8992 Check_No_Identifiers;
8994 if Arg_Count = 2 then
8996 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8998 case Chars (Get_Pragma_Arg (Arg2)) is
9000 Opt.External_Name_Exp_Casing := As_Is;
9002 when Name_Uppercase =>
9003 Opt.External_Name_Exp_Casing := Uppercase;
9005 when Name_Lowercase =>
9006 Opt.External_Name_Exp_Casing := Lowercase;
9013 Check_Arg_Count (1);
9016 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
9018 case Chars (Get_Pragma_Arg (Arg1)) is
9019 when Name_Uppercase =>
9020 Opt.External_Name_Imp_Casing := Uppercase;
9022 when Name_Lowercase =>
9023 Opt.External_Name_Imp_Casing := Lowercase;
9028 end External_Name_Casing;
9030 --------------------------
9031 -- Favor_Top_Level --
9032 --------------------------
9034 -- pragma Favor_Top_Level (type_NAME);
9036 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
9037 Named_Entity : Entity_Id;
9041 Check_No_Identifiers;
9042 Check_Arg_Count (1);
9043 Check_Arg_Is_Local_Name (Arg1);
9044 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
9046 -- If it's an access-to-subprogram type (in particular, not a
9047 -- subtype), set the flag on that type.
9049 if Is_Access_Subprogram_Type (Named_Entity) then
9050 Set_Can_Use_Internal_Rep (Named_Entity, False);
9052 -- Otherwise it's an error (name denotes the wrong sort of entity)
9056 ("access-to-subprogram type expected",
9057 Get_Pragma_Arg (Arg1));
9059 end Favor_Top_Level;
9065 -- pragma Fast_Math;
9067 when Pragma_Fast_Math =>
9069 Check_No_Identifiers;
9070 Check_Valid_Configuration_Pragma;
9073 ---------------------------
9074 -- Finalize_Storage_Only --
9075 ---------------------------
9077 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9079 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9080 Assoc : constant Node_Id := Arg1;
9081 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9086 Check_No_Identifiers;
9087 Check_Arg_Count (1);
9088 Check_Arg_Is_Local_Name (Arg1);
9090 Find_Type (Type_Id);
9091 Typ := Entity (Type_Id);
9094 or else Rep_Item_Too_Early (Typ, N)
9098 Typ := Underlying_Type (Typ);
9101 if not Is_Controlled (Typ) then
9102 Error_Pragma ("pragma% must specify controlled type");
9105 Check_First_Subtype (Arg1);
9107 if Finalize_Storage_Only (Typ) then
9108 Error_Pragma ("duplicate pragma%, only one allowed");
9110 elsif not Rep_Item_Too_Late (Typ, N) then
9111 Set_Finalize_Storage_Only (Base_Type (Typ), True);
9113 end Finalize_Storage;
9115 --------------------------
9116 -- Float_Representation --
9117 --------------------------
9119 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9121 -- FLOAT_REP ::= VAX_Float | IEEE_Float
9123 when Pragma_Float_Representation => Float_Representation : declare
9131 if Arg_Count = 1 then
9132 Check_Valid_Configuration_Pragma;
9134 Check_Arg_Count (2);
9135 Check_Optional_Identifier (Arg2, Name_Entity);
9136 Check_Arg_Is_Local_Name (Arg2);
9139 Check_No_Identifier (Arg1);
9140 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9142 if not OpenVMS_On_Target then
9143 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9145 ("?pragma% ignored (applies only to Open'V'M'S)");
9151 -- One argument case
9153 if Arg_Count = 1 then
9154 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9155 if Opt.Float_Format = 'I' then
9156 Error_Pragma ("'I'E'E'E format previously specified");
9159 Opt.Float_Format := 'V';
9162 if Opt.Float_Format = 'V' then
9163 Error_Pragma ("'V'A'X format previously specified");
9166 Opt.Float_Format := 'I';
9169 Set_Standard_Fpt_Formats;
9171 -- Two argument case
9174 Argx := Get_Pragma_Arg (Arg2);
9176 if not Is_Entity_Name (Argx)
9177 or else not Is_Floating_Point_Type (Entity (Argx))
9180 ("second argument of% pragma must be floating-point type",
9184 Ent := Entity (Argx);
9185 Digs := UI_To_Int (Digits_Value (Ent));
9187 -- Two arguments, VAX_Float case
9189 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9191 when 6 => Set_F_Float (Ent);
9192 when 9 => Set_D_Float (Ent);
9193 when 15 => Set_G_Float (Ent);
9197 ("wrong digits value, must be 6,9 or 15", Arg2);
9200 -- Two arguments, IEEE_Float case
9204 when 6 => Set_IEEE_Short (Ent);
9205 when 15 => Set_IEEE_Long (Ent);
9209 ("wrong digits value, must be 6 or 15", Arg2);
9213 end Float_Representation;
9219 -- pragma Ident (static_string_EXPRESSION)
9221 -- Note: pragma Comment shares this processing. Pragma Comment is
9222 -- identical to Ident, except that the restriction of the argument to
9223 -- 31 characters and the placement restrictions are not enforced for
9226 when Pragma_Ident | Pragma_Comment => Ident : declare
9231 Check_Arg_Count (1);
9232 Check_No_Identifiers;
9233 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9236 -- For pragma Ident, preserve DEC compatibility by requiring the
9237 -- pragma to appear in a declarative part or package spec.
9239 if Prag_Id = Pragma_Ident then
9240 Check_Is_In_Decl_Part_Or_Package_Spec;
9243 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9250 GP := Parent (Parent (N));
9252 if Nkind_In (GP, N_Package_Declaration,
9253 N_Generic_Package_Declaration)
9258 -- If we have a compilation unit, then record the ident value,
9259 -- checking for improper duplication.
9261 if Nkind (GP) = N_Compilation_Unit then
9262 CS := Ident_String (Current_Sem_Unit);
9264 if Present (CS) then
9266 -- For Ident, we do not permit multiple instances
9268 if Prag_Id = Pragma_Ident then
9269 Error_Pragma ("duplicate% pragma not permitted");
9271 -- For Comment, we concatenate the string, unless we want
9272 -- to preserve the tree structure for ASIS.
9274 elsif not ASIS_Mode then
9275 Start_String (Strval (CS));
9276 Store_String_Char (' ');
9277 Store_String_Chars (Strval (Str));
9278 Set_Strval (CS, End_String);
9282 -- In VMS, the effect of IDENT is achieved by passing
9283 -- --identification=name as a --for-linker switch.
9285 if OpenVMS_On_Target then
9288 ("--for-linker=--identification=");
9289 String_To_Name_Buffer (Strval (Str));
9290 Store_String_Chars (Name_Buffer (1 .. Name_Len));
9292 -- Only the last processed IDENT is saved. The main
9293 -- purpose is so an IDENT associated with a main
9294 -- procedure will be used in preference to an IDENT
9295 -- associated with a with'd package.
9297 Replace_Linker_Option_String
9298 (End_String, "--for-linker=--identification=");
9301 Set_Ident_String (Current_Sem_Unit, Str);
9304 -- For subunits, we just ignore the Ident, since in GNAT these
9305 -- are not separate object files, and hence not separate units
9306 -- in the unit table.
9308 elsif Nkind (GP) = N_Subunit then
9311 -- Otherwise we have a misplaced pragma Ident, but we ignore
9312 -- this if we are in an instantiation, since it comes from
9313 -- a generic, and has no relevance to the instantiation.
9315 elsif Prag_Id = Pragma_Ident then
9316 if Instantiation_Location (Loc) = No_Location then
9317 Error_Pragma ("pragma% only allowed at outer level");
9323 ----------------------------
9324 -- Implementation_Defined --
9325 ----------------------------
9327 -- pragma Implementation_Defined (local_NAME);
9329 -- Marks previously declared entity as implementation defined. For
9330 -- an overloaded entity, applies to the most recent homonym.
9332 -- pragma Implementation_Defined;
9334 -- The form with no arguments appears anywhere within a scope, most
9335 -- typically a package spec, and indicates that all entities that are
9336 -- defined within the package spec are Implementation_Defined.
9338 when Pragma_Implementation_Defined => Implementation_Defined : declare
9342 Check_No_Identifiers;
9344 -- Form with no arguments
9346 if Arg_Count = 0 then
9347 Set_Is_Implementation_Defined (Current_Scope);
9349 -- Form with one argument
9352 Check_Arg_Count (1);
9353 Check_Arg_Is_Local_Name (Arg1);
9354 Ent := Entity (Get_Pragma_Arg (Arg1));
9355 Set_Is_Implementation_Defined (Ent);
9357 end Implementation_Defined;
9363 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9364 -- implementation_kind ::=
9365 -- By_Entry | By_Protected_Procedure | By_Any | Optional
9367 -- "By_Any" and "Optional" are treated as synonyms in order to
9368 -- support Ada 2012 aspect Synchronization.
9370 when Pragma_Implemented => Implemented : declare
9371 Proc_Id : Entity_Id;
9376 Check_Arg_Count (2);
9377 Check_No_Identifiers;
9378 Check_Arg_Is_Identifier (Arg1);
9379 Check_Arg_Is_Local_Name (Arg1);
9380 Check_Arg_Is_One_Of (Arg2,
9383 Name_By_Protected_Procedure,
9386 -- Extract the name of the local procedure
9388 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9390 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9391 -- primitive procedure of a synchronized tagged type.
9393 if Ekind (Proc_Id) = E_Procedure
9394 and then Is_Primitive (Proc_Id)
9395 and then Present (First_Formal (Proc_Id))
9397 Typ := Etype (First_Formal (Proc_Id));
9399 if Is_Tagged_Type (Typ)
9402 -- Check for a protected, a synchronized or a task interface
9404 ((Is_Interface (Typ)
9405 and then Is_Synchronized_Interface (Typ))
9407 -- Check for a protected type or a task type that implements
9411 (Is_Concurrent_Record_Type (Typ)
9412 and then Present (Interfaces (Typ)))
9414 -- Check for a private record extension with keyword
9418 (Ekind_In (Typ, E_Record_Type_With_Private,
9419 E_Record_Subtype_With_Private)
9420 and then Synchronized_Present (Parent (Typ))))
9425 ("controlling formal must be of synchronized " &
9426 "tagged type", Arg1);
9430 -- Procedures declared inside a protected type must be accepted
9432 elsif Ekind (Proc_Id) = E_Procedure
9433 and then Is_Protected_Type (Scope (Proc_Id))
9437 -- The first argument is not a primitive procedure
9441 ("pragma % must be applied to a primitive procedure", Arg1);
9445 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9446 -- By_Protected_Procedure to the primitive procedure of a task
9449 if Chars (Arg2) = Name_By_Protected_Procedure
9450 and then Is_Interface (Typ)
9451 and then Is_Task_Interface (Typ)
9454 ("implementation kind By_Protected_Procedure cannot be " &
9455 "applied to a task interface primitive", Arg2);
9459 Record_Rep_Item (Proc_Id, N);
9462 ----------------------
9463 -- Implicit_Packing --
9464 ----------------------
9466 -- pragma Implicit_Packing;
9468 when Pragma_Implicit_Packing =>
9470 Check_Arg_Count (0);
9471 Implicit_Packing := True;
9478 -- [Convention =>] convention_IDENTIFIER,
9479 -- [Entity =>] local_NAME
9480 -- [, [External_Name =>] static_string_EXPRESSION ]
9481 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9483 when Pragma_Import =>
9484 Check_Ada_83_Warning;
9490 Check_At_Least_N_Arguments (2);
9491 Check_At_Most_N_Arguments (4);
9492 Process_Import_Or_Interface;
9494 ----------------------
9495 -- Import_Exception --
9496 ----------------------
9498 -- pragma Import_Exception (
9499 -- [Internal =>] LOCAL_NAME
9500 -- [, [External =>] EXTERNAL_SYMBOL]
9501 -- [, [Form =>] Ada | VMS]
9502 -- [, [Code =>] static_integer_EXPRESSION]);
9504 when Pragma_Import_Exception => Import_Exception : declare
9505 Args : Args_List (1 .. 4);
9506 Names : constant Name_List (1 .. 4) := (
9512 Internal : Node_Id renames Args (1);
9513 External : Node_Id renames Args (2);
9514 Form : Node_Id renames Args (3);
9515 Code : Node_Id renames Args (4);
9519 Gather_Associations (Names, Args);
9521 if Present (External) and then Present (Code) then
9523 ("cannot give both External and Code options for pragma%");
9526 Process_Extended_Import_Export_Exception_Pragma (
9527 Arg_Internal => Internal,
9528 Arg_External => External,
9532 if not Is_VMS_Exception (Entity (Internal)) then
9533 Set_Imported (Entity (Internal));
9535 end Import_Exception;
9537 ---------------------
9538 -- Import_Function --
9539 ---------------------
9541 -- pragma Import_Function (
9542 -- [Internal =>] LOCAL_NAME,
9543 -- [, [External =>] EXTERNAL_SYMBOL]
9544 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9545 -- [, [Result_Type =>] SUBTYPE_MARK]
9546 -- [, [Mechanism =>] MECHANISM]
9547 -- [, [Result_Mechanism =>] MECHANISM_NAME]
9548 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9550 -- EXTERNAL_SYMBOL ::=
9552 -- | static_string_EXPRESSION
9554 -- PARAMETER_TYPES ::=
9556 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9558 -- TYPE_DESIGNATOR ::=
9560 -- | subtype_Name ' Access
9564 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9566 -- MECHANISM_ASSOCIATION ::=
9567 -- [formal_parameter_NAME =>] MECHANISM_NAME
9569 -- MECHANISM_NAME ::=
9572 -- | Descriptor [([Class =>] CLASS_NAME)]
9574 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9576 when Pragma_Import_Function => Import_Function : declare
9577 Args : Args_List (1 .. 7);
9578 Names : constant Name_List (1 .. 7) := (
9581 Name_Parameter_Types,
9584 Name_Result_Mechanism,
9585 Name_First_Optional_Parameter);
9587 Internal : Node_Id renames Args (1);
9588 External : Node_Id renames Args (2);
9589 Parameter_Types : Node_Id renames Args (3);
9590 Result_Type : Node_Id renames Args (4);
9591 Mechanism : Node_Id renames Args (5);
9592 Result_Mechanism : Node_Id renames Args (6);
9593 First_Optional_Parameter : Node_Id renames Args (7);
9597 Gather_Associations (Names, Args);
9598 Process_Extended_Import_Export_Subprogram_Pragma (
9599 Arg_Internal => Internal,
9600 Arg_External => External,
9601 Arg_Parameter_Types => Parameter_Types,
9602 Arg_Result_Type => Result_Type,
9603 Arg_Mechanism => Mechanism,
9604 Arg_Result_Mechanism => Result_Mechanism,
9605 Arg_First_Optional_Parameter => First_Optional_Parameter);
9606 end Import_Function;
9612 -- pragma Import_Object (
9613 -- [Internal =>] LOCAL_NAME
9614 -- [, [External =>] EXTERNAL_SYMBOL]
9615 -- [, [Size =>] EXTERNAL_SYMBOL]);
9617 -- EXTERNAL_SYMBOL ::=
9619 -- | static_string_EXPRESSION
9621 when Pragma_Import_Object => Import_Object : declare
9622 Args : Args_List (1 .. 3);
9623 Names : constant Name_List (1 .. 3) := (
9628 Internal : Node_Id renames Args (1);
9629 External : Node_Id renames Args (2);
9630 Size : Node_Id renames Args (3);
9634 Gather_Associations (Names, Args);
9635 Process_Extended_Import_Export_Object_Pragma (
9636 Arg_Internal => Internal,
9637 Arg_External => External,
9641 ----------------------
9642 -- Import_Procedure --
9643 ----------------------
9645 -- pragma Import_Procedure (
9646 -- [Internal =>] LOCAL_NAME
9647 -- [, [External =>] EXTERNAL_SYMBOL]
9648 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9649 -- [, [Mechanism =>] MECHANISM]
9650 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9652 -- EXTERNAL_SYMBOL ::=
9654 -- | static_string_EXPRESSION
9656 -- PARAMETER_TYPES ::=
9658 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9660 -- TYPE_DESIGNATOR ::=
9662 -- | subtype_Name ' Access
9666 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9668 -- MECHANISM_ASSOCIATION ::=
9669 -- [formal_parameter_NAME =>] MECHANISM_NAME
9671 -- MECHANISM_NAME ::=
9674 -- | Descriptor [([Class =>] CLASS_NAME)]
9676 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9678 when Pragma_Import_Procedure => Import_Procedure : declare
9679 Args : Args_List (1 .. 5);
9680 Names : constant Name_List (1 .. 5) := (
9683 Name_Parameter_Types,
9685 Name_First_Optional_Parameter);
9687 Internal : Node_Id renames Args (1);
9688 External : Node_Id renames Args (2);
9689 Parameter_Types : Node_Id renames Args (3);
9690 Mechanism : Node_Id renames Args (4);
9691 First_Optional_Parameter : Node_Id renames Args (5);
9695 Gather_Associations (Names, Args);
9696 Process_Extended_Import_Export_Subprogram_Pragma (
9697 Arg_Internal => Internal,
9698 Arg_External => External,
9699 Arg_Parameter_Types => Parameter_Types,
9700 Arg_Mechanism => Mechanism,
9701 Arg_First_Optional_Parameter => First_Optional_Parameter);
9702 end Import_Procedure;
9704 -----------------------------
9705 -- Import_Valued_Procedure --
9706 -----------------------------
9708 -- pragma Import_Valued_Procedure (
9709 -- [Internal =>] LOCAL_NAME
9710 -- [, [External =>] EXTERNAL_SYMBOL]
9711 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9712 -- [, [Mechanism =>] MECHANISM]
9713 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9715 -- EXTERNAL_SYMBOL ::=
9717 -- | static_string_EXPRESSION
9719 -- PARAMETER_TYPES ::=
9721 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9723 -- TYPE_DESIGNATOR ::=
9725 -- | subtype_Name ' Access
9729 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9731 -- MECHANISM_ASSOCIATION ::=
9732 -- [formal_parameter_NAME =>] MECHANISM_NAME
9734 -- MECHANISM_NAME ::=
9737 -- | Descriptor [([Class =>] CLASS_NAME)]
9739 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9741 when Pragma_Import_Valued_Procedure =>
9742 Import_Valued_Procedure : declare
9743 Args : Args_List (1 .. 5);
9744 Names : constant Name_List (1 .. 5) := (
9747 Name_Parameter_Types,
9749 Name_First_Optional_Parameter);
9751 Internal : Node_Id renames Args (1);
9752 External : Node_Id renames Args (2);
9753 Parameter_Types : Node_Id renames Args (3);
9754 Mechanism : Node_Id renames Args (4);
9755 First_Optional_Parameter : Node_Id renames Args (5);
9759 Gather_Associations (Names, Args);
9760 Process_Extended_Import_Export_Subprogram_Pragma (
9761 Arg_Internal => Internal,
9762 Arg_External => External,
9763 Arg_Parameter_Types => Parameter_Types,
9764 Arg_Mechanism => Mechanism,
9765 Arg_First_Optional_Parameter => First_Optional_Parameter);
9766 end Import_Valued_Procedure;
9772 -- pragma Independent (LOCAL_NAME);
9774 when Pragma_Independent => Independent : declare
9781 Check_Ada_83_Warning;
9783 Check_No_Identifiers;
9784 Check_Arg_Count (1);
9785 Check_Arg_Is_Local_Name (Arg1);
9786 E_Id := Get_Pragma_Arg (Arg1);
9788 if Etype (E_Id) = Any_Type then
9793 D := Declaration_Node (E);
9796 -- Check duplicate before we chain ourselves!
9798 Check_Duplicate_Pragma (E);
9800 -- Check appropriate entity
9803 if Rep_Item_Too_Early (E, N)
9805 Rep_Item_Too_Late (E, N)
9809 Check_First_Subtype (Arg1);
9812 elsif K = N_Object_Declaration
9813 or else (K = N_Component_Declaration
9814 and then Original_Record_Component (E) = E)
9816 if Rep_Item_Too_Late (E, N) then
9822 ("inappropriate entity for pragma%", Arg1);
9825 Independence_Checks.Append ((N, E));
9828 ----------------------------
9829 -- Independent_Components --
9830 ----------------------------
9832 -- pragma Atomic_Components (array_LOCAL_NAME);
9834 -- This processing is shared by Volatile_Components
9836 when Pragma_Independent_Components => Independent_Components : declare
9843 Check_Ada_83_Warning;
9845 Check_No_Identifiers;
9846 Check_Arg_Count (1);
9847 Check_Arg_Is_Local_Name (Arg1);
9848 E_Id := Get_Pragma_Arg (Arg1);
9850 if Etype (E_Id) = Any_Type then
9856 -- Check duplicate before we chain ourselves!
9858 Check_Duplicate_Pragma (E);
9860 -- Check appropriate entity
9862 if Rep_Item_Too_Early (E, N)
9864 Rep_Item_Too_Late (E, N)
9869 D := Declaration_Node (E);
9872 if (K = N_Full_Type_Declaration
9873 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9875 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9876 and then Nkind (D) = N_Object_Declaration
9877 and then Nkind (Object_Definition (D)) =
9878 N_Constrained_Array_Definition)
9880 Independence_Checks.Append ((N, E));
9883 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9885 end Independent_Components;
9887 ------------------------
9888 -- Initialize_Scalars --
9889 ------------------------
9891 -- pragma Initialize_Scalars;
9893 when Pragma_Initialize_Scalars =>
9895 Check_Arg_Count (0);
9896 Check_Valid_Configuration_Pragma;
9897 Check_Restriction (No_Initialize_Scalars, N);
9899 -- Initialize_Scalars creates false positives in CodePeer, and
9900 -- incorrect negative results in Alfa mode, so ignore this pragma
9903 if not Restriction_Active (No_Initialize_Scalars)
9904 and then not (CodePeer_Mode or Alfa_Mode)
9906 Init_Or_Norm_Scalars := True;
9907 Initialize_Scalars := True;
9914 -- pragma Inline ( NAME {, NAME} );
9916 when Pragma_Inline =>
9918 -- Pragma is active if inlining option is active
9920 Process_Inline (Inline_Active);
9926 -- pragma Inline_Always ( NAME {, NAME} );
9928 when Pragma_Inline_Always =>
9931 -- Pragma always active unless in CodePeer or Alfa mode, since
9932 -- this causes walk order issues.
9934 if not (CodePeer_Mode or Alfa_Mode) then
9935 Process_Inline (True);
9938 --------------------
9939 -- Inline_Generic --
9940 --------------------
9942 -- pragma Inline_Generic (NAME {, NAME});
9944 when Pragma_Inline_Generic =>
9946 Process_Generic_List;
9948 ----------------------
9949 -- Inspection_Point --
9950 ----------------------
9952 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9954 when Pragma_Inspection_Point => Inspection_Point : declare
9959 if Arg_Count > 0 then
9962 Exp := Get_Pragma_Arg (Arg);
9965 if not Is_Entity_Name (Exp)
9966 or else not Is_Object (Entity (Exp))
9968 Error_Pragma_Arg ("object name required", Arg);
9975 end Inspection_Point;
9981 -- pragma Interface (
9982 -- [ Convention =>] convention_IDENTIFIER,
9983 -- [ Entity =>] local_NAME
9984 -- [, [External_Name =>] static_string_EXPRESSION ]
9985 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9987 when Pragma_Interface =>
9994 Check_At_Least_N_Arguments (2);
9995 Check_At_Most_N_Arguments (4);
9996 Process_Import_Or_Interface;
9998 -- In Ada 2005, the permission to use Interface (a reserved word)
9999 -- as a pragma name is considered an obsolescent feature.
10001 if Ada_Version >= Ada_2005 then
10003 (No_Obsolescent_Features, Pragma_Identifier (N));
10006 --------------------
10007 -- Interface_Name --
10008 --------------------
10010 -- pragma Interface_Name (
10011 -- [ Entity =>] local_NAME
10012 -- [,[External_Name =>] static_string_EXPRESSION ]
10013 -- [,[Link_Name =>] static_string_EXPRESSION ]);
10015 when Pragma_Interface_Name => Interface_Name : declare
10017 Def_Id : Entity_Id;
10018 Hom_Id : Entity_Id;
10024 ((Name_Entity, Name_External_Name, Name_Link_Name));
10025 Check_At_Least_N_Arguments (2);
10026 Check_At_Most_N_Arguments (3);
10027 Id := Get_Pragma_Arg (Arg1);
10030 if not Is_Entity_Name (Id) then
10032 ("first argument for pragma% must be entity name", Arg1);
10033 elsif Etype (Id) = Any_Type then
10036 Def_Id := Entity (Id);
10039 -- Special DEC-compatible processing for the object case, forces
10040 -- object to be imported.
10042 if Ekind (Def_Id) = E_Variable then
10043 Kill_Size_Check_Code (Def_Id);
10044 Note_Possible_Modification (Id, Sure => False);
10046 -- Initialization is not allowed for imported variable
10048 if Present (Expression (Parent (Def_Id)))
10049 and then Comes_From_Source (Expression (Parent (Def_Id)))
10051 Error_Msg_Sloc := Sloc (Def_Id);
10053 ("no initialization allowed for declaration of& #",
10057 -- For compatibility, support VADS usage of providing both
10058 -- pragmas Interface and Interface_Name to obtain the effect
10059 -- of a single Import pragma.
10061 if Is_Imported (Def_Id)
10062 and then Present (First_Rep_Item (Def_Id))
10063 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
10065 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
10069 Set_Imported (Def_Id);
10072 Set_Is_Public (Def_Id);
10073 Process_Interface_Name (Def_Id, Arg2, Arg3);
10076 -- Otherwise must be subprogram
10078 elsif not Is_Subprogram (Def_Id) then
10080 ("argument of pragma% is not subprogram", Arg1);
10083 Check_At_Most_N_Arguments (3);
10087 -- Loop through homonyms
10090 Def_Id := Get_Base_Subprogram (Hom_Id);
10092 if Is_Imported (Def_Id) then
10093 Process_Interface_Name (Def_Id, Arg2, Arg3);
10097 exit when From_Aspect_Specification (N);
10098 Hom_Id := Homonym (Hom_Id);
10100 exit when No (Hom_Id)
10101 or else Scope (Hom_Id) /= Current_Scope;
10106 ("argument of pragma% is not imported subprogram",
10110 end Interface_Name;
10112 -----------------------
10113 -- Interrupt_Handler --
10114 -----------------------
10116 -- pragma Interrupt_Handler (handler_NAME);
10118 when Pragma_Interrupt_Handler =>
10119 Check_Ada_83_Warning;
10120 Check_Arg_Count (1);
10121 Check_No_Identifiers;
10123 if No_Run_Time_Mode then
10124 Error_Msg_CRT ("Interrupt_Handler pragma", N);
10126 Check_Interrupt_Or_Attach_Handler;
10127 Process_Interrupt_Or_Attach_Handler;
10130 ------------------------
10131 -- Interrupt_Priority --
10132 ------------------------
10134 -- pragma Interrupt_Priority [(EXPRESSION)];
10136 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
10137 P : constant Node_Id := Parent (N);
10141 Check_Ada_83_Warning;
10143 if Arg_Count /= 0 then
10144 Arg := Get_Pragma_Arg (Arg1);
10145 Check_Arg_Count (1);
10146 Check_No_Identifiers;
10148 -- The expression must be analyzed in the special manner
10149 -- described in "Handling of Default and Per-Object
10150 -- Expressions" in sem.ads.
10152 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
10155 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
10159 elsif Has_Pragma_Priority (P) then
10160 Error_Pragma ("duplicate pragma% not allowed");
10163 Set_Has_Pragma_Priority (P, True);
10164 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10166 end Interrupt_Priority;
10168 ---------------------
10169 -- Interrupt_State --
10170 ---------------------
10172 -- pragma Interrupt_State (
10173 -- [Name =>] INTERRUPT_ID,
10174 -- [State =>] INTERRUPT_STATE);
10176 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
10177 -- INTERRUPT_STATE => System | Runtime | User
10179 -- Note: if the interrupt id is given as an identifier, then it must
10180 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
10181 -- given as a static integer expression which must be in the range of
10182 -- Ada.Interrupts.Interrupt_ID.
10184 when Pragma_Interrupt_State => Interrupt_State : declare
10186 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
10187 -- This is the entity Ada.Interrupts.Interrupt_ID;
10189 State_Type : Character;
10190 -- Set to 's'/'r'/'u' for System/Runtime/User
10193 -- Index to entry in Interrupt_States table
10196 -- Value of interrupt
10198 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
10199 -- The first argument to the pragma
10201 Int_Ent : Entity_Id;
10202 -- Interrupt entity in Ada.Interrupts.Names
10206 Check_Arg_Order ((Name_Name, Name_State));
10207 Check_Arg_Count (2);
10209 Check_Optional_Identifier (Arg1, Name_Name);
10210 Check_Optional_Identifier (Arg2, Name_State);
10211 Check_Arg_Is_Identifier (Arg2);
10213 -- First argument is identifier
10215 if Nkind (Arg1X) = N_Identifier then
10217 -- Search list of names in Ada.Interrupts.Names
10219 Int_Ent := First_Entity (RTE (RE_Names));
10221 if No (Int_Ent) then
10222 Error_Pragma_Arg ("invalid interrupt name", Arg1);
10224 elsif Chars (Int_Ent) = Chars (Arg1X) then
10225 Int_Val := Expr_Value (Constant_Value (Int_Ent));
10229 Next_Entity (Int_Ent);
10232 -- First argument is not an identifier, so it must be a static
10233 -- expression of type Ada.Interrupts.Interrupt_ID.
10236 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10237 Int_Val := Expr_Value (Arg1X);
10239 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
10241 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10244 ("value not in range of type " &
10245 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10251 case Chars (Get_Pragma_Arg (Arg2)) is
10252 when Name_Runtime => State_Type := 'r';
10253 when Name_System => State_Type := 's';
10254 when Name_User => State_Type := 'u';
10257 Error_Pragma_Arg ("invalid interrupt state", Arg2);
10260 -- Check if entry is already stored
10262 IST_Num := Interrupt_States.First;
10264 -- If entry not found, add it
10266 if IST_Num > Interrupt_States.Last then
10267 Interrupt_States.Append
10268 ((Interrupt_Number => UI_To_Int (Int_Val),
10269 Interrupt_State => State_Type,
10270 Pragma_Loc => Loc));
10273 -- Case of entry for the same entry
10275 elsif Int_Val = Interrupt_States.Table (IST_Num).
10278 -- If state matches, done, no need to make redundant entry
10281 State_Type = Interrupt_States.Table (IST_Num).
10284 -- Otherwise if state does not match, error
10287 Interrupt_States.Table (IST_Num).Pragma_Loc;
10289 ("state conflicts with that given #", Arg2);
10293 IST_Num := IST_Num + 1;
10295 end Interrupt_State;
10301 -- pragma Invariant
10302 -- ([Entity =>] type_LOCAL_NAME,
10303 -- [Check =>] EXPRESSION
10304 -- [,[Message =>] String_Expression]);
10306 when Pragma_Invariant => Invariant : declare
10311 pragma Unreferenced (Discard);
10315 Check_At_Least_N_Arguments (2);
10316 Check_At_Most_N_Arguments (3);
10317 Check_Optional_Identifier (Arg1, Name_Entity);
10318 Check_Optional_Identifier (Arg2, Name_Check);
10320 if Arg_Count = 3 then
10321 Check_Optional_Identifier (Arg3, Name_Message);
10322 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10325 Check_Arg_Is_Local_Name (Arg1);
10327 Type_Id := Get_Pragma_Arg (Arg1);
10328 Find_Type (Type_Id);
10329 Typ := Entity (Type_Id);
10331 if Typ = Any_Type then
10334 -- An invariant must apply to a private type, or appear in the
10335 -- private part of a package spec and apply to a completion.
10337 elsif Ekind_In (Typ, E_Private_Type,
10338 E_Record_Type_With_Private,
10339 E_Limited_Private_Type)
10343 elsif In_Private_Part (Current_Scope)
10344 and then Has_Private_Declaration (Typ)
10348 elsif In_Private_Part (Current_Scope) then
10350 ("pragma% only allowed for private type " &
10351 "declared in visible part", Arg1);
10355 ("pragma% only allowed for private type", Arg1);
10358 -- Note that the type has at least one invariant, and also that
10359 -- it has inheritable invariants if we have Invariant'Class.
10361 Set_Has_Invariants (Typ);
10363 if Class_Present (N) then
10364 Set_Has_Inheritable_Invariants (Typ);
10367 -- The remaining processing is simply to link the pragma on to
10368 -- the rep item chain, for processing when the type is frozen.
10369 -- This is accomplished by a call to Rep_Item_Too_Late.
10371 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10374 ----------------------
10375 -- Java_Constructor --
10376 ----------------------
10378 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10380 -- Also handles pragma CIL_Constructor
10382 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10383 Java_Constructor : declare
10384 Convention : Convention_Id;
10385 Def_Id : Entity_Id;
10386 Hom_Id : Entity_Id;
10388 This_Formal : Entity_Id;
10392 Check_Arg_Count (1);
10393 Check_Optional_Identifier (Arg1, Name_Entity);
10394 Check_Arg_Is_Local_Name (Arg1);
10396 Id := Get_Pragma_Arg (Arg1);
10397 Find_Program_Unit_Name (Id);
10399 -- If we did not find the name, we are done
10401 if Etype (Id) = Any_Type then
10405 -- Check wrong use of pragma in wrong VM target
10407 if VM_Target = No_VM then
10410 elsif VM_Target = CLI_Target
10411 and then Prag_Id = Pragma_Java_Constructor
10413 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10415 elsif VM_Target = JVM_Target
10416 and then Prag_Id = Pragma_CIL_Constructor
10418 Error_Pragma ("must use pragma 'Java_'Constructor");
10422 when Pragma_CIL_Constructor => Convention := Convention_CIL;
10423 when Pragma_Java_Constructor => Convention := Convention_Java;
10424 when others => null;
10427 Hom_Id := Entity (Id);
10429 -- Loop through homonyms
10432 Def_Id := Get_Base_Subprogram (Hom_Id);
10434 -- The constructor is required to be a function
10436 if Ekind (Def_Id) /= E_Function then
10437 if VM_Target = JVM_Target then
10439 ("pragma% requires function returning a " &
10440 "'Java access type", Def_Id);
10443 ("pragma% requires function returning a " &
10444 "'C'I'L access type", Def_Id);
10448 -- Check arguments: For tagged type the first formal must be
10449 -- named "this" and its type must be a named access type
10450 -- designating a class-wide tagged type that has convention
10451 -- CIL/Java. The first formal must also have a null default
10452 -- value. For example:
10454 -- type Typ is tagged ...
10455 -- type Ref is access all Typ;
10456 -- pragma Convention (CIL, Typ);
10458 -- function New_Typ (This : Ref) return Ref;
10459 -- function New_Typ (This : Ref; I : Integer) return Ref;
10460 -- pragma Cil_Constructor (New_Typ);
10462 -- Reason: The first formal must NOT be a primitive of the
10465 -- This rule also applies to constructors of delegates used
10466 -- to interface with standard target libraries. For example:
10468 -- type Delegate is access procedure ...
10469 -- pragma Import (CIL, Delegate, ...);
10471 -- function new_Delegate
10472 -- (This : Delegate := null; ... ) return Delegate;
10474 -- For value-types this rule does not apply.
10476 if not Is_Value_Type (Etype (Def_Id)) then
10477 if No (First_Formal (Def_Id)) then
10478 Error_Msg_Name_1 := Pname;
10479 Error_Msg_N ("% function must have parameters", Def_Id);
10483 -- In the JRE library we have several occurrences in which
10484 -- the "this" parameter is not the first formal.
10486 This_Formal := First_Formal (Def_Id);
10488 -- In the JRE library we have several occurrences in which
10489 -- the "this" parameter is not the first formal. Search for
10492 if VM_Target = JVM_Target then
10493 while Present (This_Formal)
10494 and then Get_Name_String (Chars (This_Formal)) /= "this"
10496 Next_Formal (This_Formal);
10499 if No (This_Formal) then
10500 This_Formal := First_Formal (Def_Id);
10504 -- Warning: The first parameter should be named "this".
10505 -- We temporarily allow it because we have the following
10506 -- case in the Java runtime (file s-osinte.ads) ???
10508 -- function new_Thread
10509 -- (Self_Id : System.Address) return Thread_Id;
10510 -- pragma Java_Constructor (new_Thread);
10512 if VM_Target = JVM_Target
10513 and then Get_Name_String (Chars (First_Formal (Def_Id)))
10515 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10519 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10520 Error_Msg_Name_1 := Pname;
10522 ("first formal of % function must be named `this`",
10523 Parent (This_Formal));
10525 elsif not Is_Access_Type (Etype (This_Formal)) then
10526 Error_Msg_Name_1 := Pname;
10528 ("first formal of % function must be an access type",
10529 Parameter_Type (Parent (This_Formal)));
10531 -- For delegates the type of the first formal must be a
10532 -- named access-to-subprogram type (see previous example)
10534 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10535 and then Ekind (Etype (This_Formal))
10536 /= E_Access_Subprogram_Type
10538 Error_Msg_Name_1 := Pname;
10540 ("first formal of % function must be a named access" &
10541 " to subprogram type",
10542 Parameter_Type (Parent (This_Formal)));
10544 -- Warning: We should reject anonymous access types because
10545 -- the constructor must not be handled as a primitive of the
10546 -- tagged type. We temporarily allow it because this profile
10547 -- is currently generated by cil2ada???
10549 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10550 and then not Ekind_In (Etype (This_Formal),
10552 E_General_Access_Type,
10553 E_Anonymous_Access_Type)
10555 Error_Msg_Name_1 := Pname;
10557 ("first formal of % function must be a named access" &
10559 Parameter_Type (Parent (This_Formal)));
10561 elsif Atree.Convention
10562 (Designated_Type (Etype (This_Formal))) /= Convention
10564 Error_Msg_Name_1 := Pname;
10566 if Convention = Convention_Java then
10568 ("pragma% requires convention 'Cil in designated" &
10570 Parameter_Type (Parent (This_Formal)));
10573 ("pragma% requires convention 'Java in designated" &
10575 Parameter_Type (Parent (This_Formal)));
10578 elsif No (Expression (Parent (This_Formal)))
10579 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10581 Error_Msg_Name_1 := Pname;
10583 ("pragma% requires first formal with default `null`",
10584 Parameter_Type (Parent (This_Formal)));
10588 -- Check result type: the constructor must be a function
10590 -- * a value type (only allowed in the CIL compiler)
10591 -- * an access-to-subprogram type with convention Java/CIL
10592 -- * an access-type designating a type that has convention
10595 if Is_Value_Type (Etype (Def_Id)) then
10598 -- Access-to-subprogram type with convention Java/CIL
10600 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10601 if Atree.Convention (Etype (Def_Id)) /= Convention then
10602 if Convention = Convention_Java then
10604 ("pragma% requires function returning a " &
10605 "'Java access type", Arg1);
10607 pragma Assert (Convention = Convention_CIL);
10609 ("pragma% requires function returning a " &
10610 "'C'I'L access type", Arg1);
10614 elsif Ekind (Etype (Def_Id)) in Access_Kind then
10615 if not Ekind_In (Etype (Def_Id), E_Access_Type,
10616 E_General_Access_Type)
10619 (Designated_Type (Etype (Def_Id))) /= Convention
10621 Error_Msg_Name_1 := Pname;
10623 if Convention = Convention_Java then
10625 ("pragma% requires function returning a named" &
10626 "'Java access type", Arg1);
10629 ("pragma% requires function returning a named" &
10630 "'C'I'L access type", Arg1);
10635 Set_Is_Constructor (Def_Id);
10636 Set_Convention (Def_Id, Convention);
10637 Set_Is_Imported (Def_Id);
10639 exit when From_Aspect_Specification (N);
10640 Hom_Id := Homonym (Hom_Id);
10642 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10644 end Java_Constructor;
10646 ----------------------
10647 -- Java_Interface --
10648 ----------------------
10650 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
10652 when Pragma_Java_Interface => Java_Interface : declare
10658 Check_Arg_Count (1);
10659 Check_Optional_Identifier (Arg1, Name_Entity);
10660 Check_Arg_Is_Local_Name (Arg1);
10662 Arg := Get_Pragma_Arg (Arg1);
10665 if Etype (Arg) = Any_Type then
10669 if not Is_Entity_Name (Arg)
10670 or else not Is_Type (Entity (Arg))
10672 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10675 Typ := Underlying_Type (Entity (Arg));
10677 -- For now simply check some of the semantic constraints on the
10678 -- type. This currently leaves out some restrictions on interface
10679 -- types, namely that the parent type must be java.lang.Object.Typ
10680 -- and that all primitives of the type should be declared
10683 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10684 Error_Pragma_Arg ("pragma% requires an abstract "
10685 & "tagged type", Arg1);
10687 elsif not Has_Discriminants (Typ)
10688 or else Ekind (Etype (First_Discriminant (Typ)))
10689 /= E_Anonymous_Access_Type
10691 not Is_Class_Wide_Type
10692 (Designated_Type (Etype (First_Discriminant (Typ))))
10695 ("type must have a class-wide access discriminant", Arg1);
10697 end Java_Interface;
10703 -- pragma Keep_Names ([On => ] local_NAME);
10705 when Pragma_Keep_Names => Keep_Names : declare
10710 Check_Arg_Count (1);
10711 Check_Optional_Identifier (Arg1, Name_On);
10712 Check_Arg_Is_Local_Name (Arg1);
10714 Arg := Get_Pragma_Arg (Arg1);
10717 if Etype (Arg) = Any_Type then
10721 if not Is_Entity_Name (Arg)
10722 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10725 ("pragma% requires a local enumeration type", Arg1);
10728 Set_Discard_Names (Entity (Arg), False);
10735 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10737 when Pragma_License =>
10739 Check_Arg_Count (1);
10740 Check_No_Identifiers;
10741 Check_Valid_Configuration_Pragma;
10742 Check_Arg_Is_Identifier (Arg1);
10745 Sind : constant Source_File_Index :=
10746 Source_Index (Current_Sem_Unit);
10749 case Chars (Get_Pragma_Arg (Arg1)) is
10751 Set_License (Sind, GPL);
10753 when Name_Modified_GPL =>
10754 Set_License (Sind, Modified_GPL);
10756 when Name_Restricted =>
10757 Set_License (Sind, Restricted);
10759 when Name_Unrestricted =>
10760 Set_License (Sind, Unrestricted);
10763 Error_Pragma_Arg ("invalid license name", Arg1);
10771 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10773 when Pragma_Link_With => Link_With : declare
10779 if Operating_Mode = Generate_Code
10780 and then In_Extended_Main_Source_Unit (N)
10782 Check_At_Least_N_Arguments (1);
10783 Check_No_Identifiers;
10784 Check_Is_In_Decl_Part_Or_Package_Spec;
10785 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10789 while Present (Arg) loop
10790 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10792 -- Store argument, converting sequences of spaces to a
10793 -- single null character (this is one of the differences
10794 -- in processing between Link_With and Linker_Options).
10796 Arg_Store : declare
10797 C : constant Char_Code := Get_Char_Code (' ');
10798 S : constant String_Id :=
10799 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10800 L : constant Nat := String_Length (S);
10803 procedure Skip_Spaces;
10804 -- Advance F past any spaces
10810 procedure Skip_Spaces is
10812 while F <= L and then Get_String_Char (S, F) = C loop
10817 -- Start of processing for Arg_Store
10820 Skip_Spaces; -- skip leading spaces
10822 -- Loop through characters, changing any embedded
10823 -- sequence of spaces to a single null character (this
10824 -- is how Link_With/Linker_Options differ)
10827 if Get_String_Char (S, F) = C then
10830 Store_String_Char (ASCII.NUL);
10833 Store_String_Char (Get_String_Char (S, F));
10841 if Present (Arg) then
10842 Store_String_Char (ASCII.NUL);
10846 Store_Linker_Option_String (End_String);
10854 -- pragma Linker_Alias (
10855 -- [Entity =>] LOCAL_NAME
10856 -- [Target =>] static_string_EXPRESSION);
10858 when Pragma_Linker_Alias =>
10860 Check_Arg_Order ((Name_Entity, Name_Target));
10861 Check_Arg_Count (2);
10862 Check_Optional_Identifier (Arg1, Name_Entity);
10863 Check_Optional_Identifier (Arg2, Name_Target);
10864 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10865 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10867 -- The only processing required is to link this item on to the
10868 -- list of rep items for the given entity. This is accomplished
10869 -- by the call to Rep_Item_Too_Late (when no error is detected
10870 -- and False is returned).
10872 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10875 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10878 ------------------------
10879 -- Linker_Constructor --
10880 ------------------------
10882 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10884 -- Code is shared with Linker_Destructor
10886 -----------------------
10887 -- Linker_Destructor --
10888 -----------------------
10890 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10892 when Pragma_Linker_Constructor |
10893 Pragma_Linker_Destructor =>
10894 Linker_Constructor : declare
10900 Check_Arg_Count (1);
10901 Check_No_Identifiers;
10902 Check_Arg_Is_Local_Name (Arg1);
10903 Arg1_X := Get_Pragma_Arg (Arg1);
10905 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10907 if not Is_Library_Level_Entity (Proc) then
10909 ("argument for pragma% must be library level entity", Arg1);
10912 -- The only processing required is to link this item on to the
10913 -- list of rep items for the given entity. This is accomplished
10914 -- by the call to Rep_Item_Too_Late (when no error is detected
10915 -- and False is returned).
10917 if Rep_Item_Too_Late (Proc, N) then
10920 Set_Has_Gigi_Rep_Item (Proc);
10922 end Linker_Constructor;
10924 --------------------
10925 -- Linker_Options --
10926 --------------------
10928 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10930 when Pragma_Linker_Options => Linker_Options : declare
10934 Check_Ada_83_Warning;
10935 Check_No_Identifiers;
10936 Check_Arg_Count (1);
10937 Check_Is_In_Decl_Part_Or_Package_Spec;
10938 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10939 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10942 while Present (Arg) loop
10943 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10944 Store_String_Char (ASCII.NUL);
10946 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10950 if Operating_Mode = Generate_Code
10951 and then In_Extended_Main_Source_Unit (N)
10953 Store_Linker_Option_String (End_String);
10955 end Linker_Options;
10957 --------------------
10958 -- Linker_Section --
10959 --------------------
10961 -- pragma Linker_Section (
10962 -- [Entity =>] LOCAL_NAME
10963 -- [Section =>] static_string_EXPRESSION);
10965 when Pragma_Linker_Section =>
10967 Check_Arg_Order ((Name_Entity, Name_Section));
10968 Check_Arg_Count (2);
10969 Check_Optional_Identifier (Arg1, Name_Entity);
10970 Check_Optional_Identifier (Arg2, Name_Section);
10971 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10972 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10974 -- This pragma applies only to objects
10976 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10977 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10980 -- The only processing required is to link this item on to the
10981 -- list of rep items for the given entity. This is accomplished
10982 -- by the call to Rep_Item_Too_Late (when no error is detected
10983 -- and False is returned).
10985 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10988 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10995 -- pragma List (On | Off)
10997 -- There is nothing to do here, since we did all the processing for
10998 -- this pragma in Par.Prag (so that it works properly even in syntax
11001 when Pragma_List =>
11004 --------------------
11005 -- Locking_Policy --
11006 --------------------
11008 -- pragma Locking_Policy (policy_IDENTIFIER);
11010 when Pragma_Locking_Policy => declare
11011 subtype LP_Range is Name_Id
11012 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
11016 Check_Ada_83_Warning;
11017 Check_Arg_Count (1);
11018 Check_No_Identifiers;
11019 Check_Arg_Is_Locking_Policy (Arg1);
11020 Check_Valid_Configuration_Pragma;
11021 LP_Val := Chars (Get_Pragma_Arg (Arg1));
11024 when Name_Ceiling_Locking => LP := 'C';
11025 when Name_Inheritance_Locking => LP := 'I';
11026 when Name_Concurrent_Readers_Locking => LP := 'R';
11029 if Locking_Policy /= ' '
11030 and then Locking_Policy /= LP
11032 Error_Msg_Sloc := Locking_Policy_Sloc;
11033 Error_Pragma ("locking policy incompatible with policy#");
11035 -- Set new policy, but always preserve System_Location since we
11036 -- like the error message with the run time name.
11039 Locking_Policy := LP;
11041 if Locking_Policy_Sloc /= System_Location then
11042 Locking_Policy_Sloc := Loc;
11051 -- pragma Long_Float (D_Float | G_Float);
11053 when Pragma_Long_Float => Long_Float : declare
11056 Check_Valid_Configuration_Pragma;
11057 Check_Arg_Count (1);
11058 Check_No_Identifier (Arg1);
11059 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
11061 if not OpenVMS_On_Target then
11062 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
11067 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
11068 if Opt.Float_Format_Long = 'G' then
11070 ("G_Float previously specified", Arg1);
11072 elsif Current_Sem_Unit /= Main_Unit
11073 and then Opt.Float_Format_Long /= 'D'
11076 ("main unit not compiled with pragma Long_Float (D_Float)",
11077 "\pragma% must be used consistently for whole partition",
11081 Opt.Float_Format_Long := 'D';
11084 -- G_Float case (this is the default, does not need overriding)
11087 if Opt.Float_Format_Long = 'D' then
11088 Error_Pragma ("D_Float previously specified");
11090 elsif Current_Sem_Unit /= Main_Unit
11091 and then Opt.Float_Format_Long /= 'G'
11094 ("main unit not compiled with pragma Long_Float (G_Float)",
11095 "\pragma% must be used consistently for whole partition",
11099 Opt.Float_Format_Long := 'G';
11103 Set_Standard_Fpt_Formats;
11106 -----------------------
11107 -- Machine_Attribute --
11108 -----------------------
11110 -- pragma Machine_Attribute (
11111 -- [Entity =>] LOCAL_NAME,
11112 -- [Attribute_Name =>] static_string_EXPRESSION
11113 -- [, [Info =>] static_EXPRESSION] );
11115 when Pragma_Machine_Attribute => Machine_Attribute : declare
11116 Def_Id : Entity_Id;
11120 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
11122 if Arg_Count = 3 then
11123 Check_Optional_Identifier (Arg3, Name_Info);
11124 Check_Arg_Is_Static_Expression (Arg3);
11126 Check_Arg_Count (2);
11129 Check_Optional_Identifier (Arg1, Name_Entity);
11130 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
11131 Check_Arg_Is_Local_Name (Arg1);
11132 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11133 Def_Id := Entity (Get_Pragma_Arg (Arg1));
11135 if Is_Access_Type (Def_Id) then
11136 Def_Id := Designated_Type (Def_Id);
11139 if Rep_Item_Too_Early (Def_Id, N) then
11143 Def_Id := Underlying_Type (Def_Id);
11145 -- The only processing required is to link this item on to the
11146 -- list of rep items for the given entity. This is accomplished
11147 -- by the call to Rep_Item_Too_Late (when no error is detected
11148 -- and False is returned).
11150 if Rep_Item_Too_Late (Def_Id, N) then
11153 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11155 end Machine_Attribute;
11162 -- (MAIN_OPTION [, MAIN_OPTION]);
11165 -- [STACK_SIZE =>] static_integer_EXPRESSION
11166 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
11167 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
11169 when Pragma_Main => Main : declare
11170 Args : Args_List (1 .. 3);
11171 Names : constant Name_List (1 .. 3) := (
11173 Name_Task_Stack_Size_Default,
11174 Name_Time_Slicing_Enabled);
11180 Gather_Associations (Names, Args);
11182 for J in 1 .. 2 loop
11183 if Present (Args (J)) then
11184 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11188 if Present (Args (3)) then
11189 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
11193 while Present (Nod) loop
11194 if Nkind (Nod) = N_Pragma
11195 and then Pragma_Name (Nod) = Name_Main
11197 Error_Msg_Name_1 := Pname;
11198 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11209 -- pragma Main_Storage
11210 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
11212 -- MAIN_STORAGE_OPTION ::=
11213 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
11214 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
11216 when Pragma_Main_Storage => Main_Storage : declare
11217 Args : Args_List (1 .. 2);
11218 Names : constant Name_List (1 .. 2) := (
11219 Name_Working_Storage,
11226 Gather_Associations (Names, Args);
11228 for J in 1 .. 2 loop
11229 if Present (Args (J)) then
11230 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11234 Check_In_Main_Program;
11237 while Present (Nod) loop
11238 if Nkind (Nod) = N_Pragma
11239 and then Pragma_Name (Nod) = Name_Main_Storage
11241 Error_Msg_Name_1 := Pname;
11242 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11253 -- pragma Memory_Size (NUMERIC_LITERAL)
11255 when Pragma_Memory_Size =>
11258 -- Memory size is simply ignored
11260 Check_No_Identifiers;
11261 Check_Arg_Count (1);
11262 Check_Arg_Is_Integer_Literal (Arg1);
11270 -- The only correct use of this pragma is on its own in a file, in
11271 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
11272 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
11273 -- check for a file containing nothing but a No_Body pragma). If we
11274 -- attempt to process it during normal semantics processing, it means
11275 -- it was misplaced.
11277 when Pragma_No_Body =>
11285 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
11287 when Pragma_No_Return => No_Return : declare
11295 Check_At_Least_N_Arguments (1);
11297 -- Loop through arguments of pragma
11300 while Present (Arg) loop
11301 Check_Arg_Is_Local_Name (Arg);
11302 Id := Get_Pragma_Arg (Arg);
11305 if not Is_Entity_Name (Id) then
11306 Error_Pragma_Arg ("entity name required", Arg);
11309 if Etype (Id) = Any_Type then
11313 -- Loop to find matching procedures
11318 and then Scope (E) = Current_Scope
11320 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11323 -- Set flag on any alias as well
11325 if Is_Overloadable (E) and then Present (Alias (E)) then
11326 Set_No_Return (Alias (E));
11332 exit when From_Aspect_Specification (N);
11337 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11348 -- pragma No_Run_Time;
11350 -- Note: this pragma is retained for backwards compatibility. See
11351 -- body of Rtsfind for full details on its handling.
11353 when Pragma_No_Run_Time =>
11355 Check_Valid_Configuration_Pragma;
11356 Check_Arg_Count (0);
11358 No_Run_Time_Mode := True;
11359 Configurable_Run_Time_Mode := True;
11361 -- Set Duration to 32 bits if word size is 32
11363 if Ttypes.System_Word_Size = 32 then
11364 Duration_32_Bits_On_Target := True;
11367 -- Set appropriate restrictions
11369 Set_Restriction (No_Finalization, N);
11370 Set_Restriction (No_Exception_Handlers, N);
11371 Set_Restriction (Max_Tasks, N, 0);
11372 Set_Restriction (No_Tasking, N);
11374 ------------------------
11375 -- No_Strict_Aliasing --
11376 ------------------------
11378 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11380 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11385 Check_At_Most_N_Arguments (1);
11387 if Arg_Count = 0 then
11388 Check_Valid_Configuration_Pragma;
11389 Opt.No_Strict_Aliasing := True;
11392 Check_Optional_Identifier (Arg2, Name_Entity);
11393 Check_Arg_Is_Local_Name (Arg1);
11394 E_Id := Entity (Get_Pragma_Arg (Arg1));
11396 if E_Id = Any_Type then
11398 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11399 Error_Pragma_Arg ("pragma% requires access type", Arg1);
11402 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11404 end No_Strict_Aliasing;
11406 -----------------------
11407 -- Normalize_Scalars --
11408 -----------------------
11410 -- pragma Normalize_Scalars;
11412 when Pragma_Normalize_Scalars =>
11413 Check_Ada_83_Warning;
11414 Check_Arg_Count (0);
11415 Check_Valid_Configuration_Pragma;
11417 -- Normalize_Scalars creates false positives in CodePeer, and
11418 -- incorrect negative results in Alfa mode, so ignore this pragma
11421 if not (CodePeer_Mode or Alfa_Mode) then
11422 Normalize_Scalars := True;
11423 Init_Or_Norm_Scalars := True;
11430 -- pragma Obsolescent;
11432 -- pragma Obsolescent (
11433 -- [Message =>] static_string_EXPRESSION
11434 -- [,[Version =>] Ada_05]]);
11436 -- pragma Obsolescent (
11437 -- [Entity =>] NAME
11438 -- [,[Message =>] static_string_EXPRESSION
11439 -- [,[Version =>] Ada_05]] );
11441 when Pragma_Obsolescent => Obsolescent : declare
11445 procedure Set_Obsolescent (E : Entity_Id);
11446 -- Given an entity Ent, mark it as obsolescent if appropriate
11448 ---------------------
11449 -- Set_Obsolescent --
11450 ---------------------
11452 procedure Set_Obsolescent (E : Entity_Id) is
11461 -- Entity name was given
11463 if Present (Ename) then
11465 -- If entity name matches, we are fine. Save entity in
11466 -- pragma argument, for ASIS use.
11468 if Chars (Ename) = Chars (Ent) then
11469 Set_Entity (Ename, Ent);
11470 Generate_Reference (Ent, Ename);
11472 -- If entity name does not match, only possibility is an
11473 -- enumeration literal from an enumeration type declaration.
11475 elsif Ekind (Ent) /= E_Enumeration_Type then
11477 ("pragma % entity name does not match declaration");
11480 Ent := First_Literal (E);
11484 ("pragma % entity name does not match any " &
11485 "enumeration literal");
11487 elsif Chars (Ent) = Chars (Ename) then
11488 Set_Entity (Ename, Ent);
11489 Generate_Reference (Ent, Ename);
11493 Ent := Next_Literal (Ent);
11499 -- Ent points to entity to be marked
11501 if Arg_Count >= 1 then
11503 -- Deal with static string argument
11505 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11506 S := Strval (Get_Pragma_Arg (Arg1));
11508 for J in 1 .. String_Length (S) loop
11509 if not In_Character_Range (Get_String_Char (S, J)) then
11511 ("pragma% argument does not allow wide characters",
11516 Obsolescent_Warnings.Append
11517 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11519 -- Check for Ada_05 parameter
11521 if Arg_Count /= 1 then
11522 Check_Arg_Count (2);
11525 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11528 Check_Arg_Is_Identifier (Argx);
11530 if Chars (Argx) /= Name_Ada_05 then
11531 Error_Msg_Name_2 := Name_Ada_05;
11533 ("only allowed argument for pragma% is %", Argx);
11536 if Ada_Version_Explicit < Ada_2005
11537 or else not Warn_On_Ada_2005_Compatibility
11545 -- Set flag if pragma active
11548 Set_Is_Obsolescent (Ent);
11552 end Set_Obsolescent;
11554 -- Start of processing for pragma Obsolescent
11559 Check_At_Most_N_Arguments (3);
11561 -- See if first argument specifies an entity name
11565 (Chars (Arg1) = Name_Entity
11567 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11569 N_Operator_Symbol))
11571 Ename := Get_Pragma_Arg (Arg1);
11573 -- Eliminate first argument, so we can share processing
11577 Arg_Count := Arg_Count - 1;
11579 -- No Entity name argument given
11585 if Arg_Count >= 1 then
11586 Check_Optional_Identifier (Arg1, Name_Message);
11588 if Arg_Count = 2 then
11589 Check_Optional_Identifier (Arg2, Name_Version);
11593 -- Get immediately preceding declaration
11596 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11600 -- Cases where we do not follow anything other than another pragma
11604 -- First case: library level compilation unit declaration with
11605 -- the pragma immediately following the declaration.
11607 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11609 (Defining_Entity (Unit (Parent (Parent (N)))));
11612 -- Case 2: library unit placement for package
11616 Ent : constant Entity_Id := Find_Lib_Unit_Name;
11618 if Is_Package_Or_Generic_Package (Ent) then
11619 Set_Obsolescent (Ent);
11625 -- Cases where we must follow a declaration
11628 if Nkind (Decl) not in N_Declaration
11629 and then Nkind (Decl) not in N_Later_Decl_Item
11630 and then Nkind (Decl) not in N_Generic_Declaration
11631 and then Nkind (Decl) not in N_Renaming_Declaration
11634 ("pragma% misplaced, "
11635 & "must immediately follow a declaration");
11638 Set_Obsolescent (Defining_Entity (Decl));
11648 -- pragma Optimize (Time | Space | Off);
11650 -- The actual check for optimize is done in Gigi. Note that this
11651 -- pragma does not actually change the optimization setting, it
11652 -- simply checks that it is consistent with the pragma.
11654 when Pragma_Optimize =>
11655 Check_No_Identifiers;
11656 Check_Arg_Count (1);
11657 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11659 ------------------------
11660 -- Optimize_Alignment --
11661 ------------------------
11663 -- pragma Optimize_Alignment (Time | Space | Off);
11665 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11667 Check_No_Identifiers;
11668 Check_Arg_Count (1);
11669 Check_Valid_Configuration_Pragma;
11672 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11676 Opt.Optimize_Alignment := 'T';
11678 Opt.Optimize_Alignment := 'S';
11680 Opt.Optimize_Alignment := 'O';
11682 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11686 -- Set indication that mode is set locally. If we are in fact in a
11687 -- configuration pragma file, this setting is harmless since the
11688 -- switch will get reset anyway at the start of each unit.
11690 Optimize_Alignment_Local := True;
11691 end Optimize_Alignment;
11697 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11699 when Pragma_Ordered => Ordered : declare
11700 Assoc : constant Node_Id := Arg1;
11706 Check_No_Identifiers;
11707 Check_Arg_Count (1);
11708 Check_Arg_Is_Local_Name (Arg1);
11710 Type_Id := Get_Pragma_Arg (Assoc);
11711 Find_Type (Type_Id);
11712 Typ := Entity (Type_Id);
11714 if Typ = Any_Type then
11717 Typ := Underlying_Type (Typ);
11720 if not Is_Enumeration_Type (Typ) then
11721 Error_Pragma ("pragma% must specify enumeration type");
11724 Check_First_Subtype (Arg1);
11725 Set_Has_Pragma_Ordered (Base_Type (Typ));
11732 -- pragma Pack (first_subtype_LOCAL_NAME);
11734 when Pragma_Pack => Pack : declare
11735 Assoc : constant Node_Id := Arg1;
11739 Ignore : Boolean := False;
11742 Check_No_Identifiers;
11743 Check_Arg_Count (1);
11744 Check_Arg_Is_Local_Name (Arg1);
11746 Type_Id := Get_Pragma_Arg (Assoc);
11747 Find_Type (Type_Id);
11748 Typ := Entity (Type_Id);
11751 or else Rep_Item_Too_Early (Typ, N)
11755 Typ := Underlying_Type (Typ);
11758 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11759 Error_Pragma ("pragma% must specify array or record type");
11762 Check_First_Subtype (Arg1);
11763 Check_Duplicate_Pragma (Typ);
11767 if Is_Array_Type (Typ) then
11768 Ctyp := Component_Type (Typ);
11770 -- Ignore pack that does nothing
11772 if Known_Static_Esize (Ctyp)
11773 and then Known_Static_RM_Size (Ctyp)
11774 and then Esize (Ctyp) = RM_Size (Ctyp)
11775 and then Addressable (Esize (Ctyp))
11780 -- Process OK pragma Pack. Note that if there is a separate
11781 -- component clause present, the Pack will be cancelled. This
11782 -- processing is in Freeze.
11784 if not Rep_Item_Too_Late (Typ, N) then
11786 -- In the context of static code analysis, we do not need
11787 -- complex front-end expansions related to pragma Pack,
11788 -- so disable handling of pragma Pack in these cases.
11790 if CodePeer_Mode or Alfa_Mode then
11793 -- Don't attempt any packing for VM targets. We possibly
11794 -- could deal with some cases of array bit-packing, but we
11795 -- don't bother, since this is not a typical kind of
11796 -- representation in the VM context anyway (and would not
11797 -- for example work nicely with the debugger).
11799 elsif VM_Target /= No_VM then
11800 if not GNAT_Mode then
11802 ("?pragma% ignored in this configuration");
11805 -- Normal case where we do the pack action
11809 Set_Is_Packed (Base_Type (Typ));
11810 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11813 Set_Has_Pragma_Pack (Base_Type (Typ));
11817 -- For record types, the pack is always effective
11819 else pragma Assert (Is_Record_Type (Typ));
11820 if not Rep_Item_Too_Late (Typ, N) then
11822 -- Ignore pack request with warning in VM mode (skip warning
11823 -- if we are compiling GNAT run time library).
11825 if VM_Target /= No_VM then
11826 if not GNAT_Mode then
11828 ("?pragma% ignored in this configuration");
11831 -- Normal case of pack request active
11834 Set_Is_Packed (Base_Type (Typ));
11835 Set_Has_Pragma_Pack (Base_Type (Typ));
11836 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11848 -- There is nothing to do here, since we did all the processing for
11849 -- this pragma in Par.Prag (so that it works properly even in syntax
11852 when Pragma_Page =>
11859 -- pragma Passive [(PASSIVE_FORM)];
11861 -- PASSIVE_FORM ::= Semaphore | No
11863 when Pragma_Passive =>
11866 if Nkind (Parent (N)) /= N_Task_Definition then
11867 Error_Pragma ("pragma% must be within task definition");
11870 if Arg_Count /= 0 then
11871 Check_Arg_Count (1);
11872 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11875 ----------------------------------
11876 -- Preelaborable_Initialization --
11877 ----------------------------------
11879 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11881 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11886 Check_Arg_Count (1);
11887 Check_No_Identifiers;
11888 Check_Arg_Is_Identifier (Arg1);
11889 Check_Arg_Is_Local_Name (Arg1);
11890 Check_First_Subtype (Arg1);
11891 Ent := Entity (Get_Pragma_Arg (Arg1));
11893 if not (Is_Private_Type (Ent)
11895 Is_Protected_Type (Ent)
11897 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11900 ("pragma % can only be applied to private, formal derived or "
11901 & "protected type",
11905 -- Give an error if the pragma is applied to a protected type that
11906 -- does not qualify (due to having entries, or due to components
11907 -- that do not qualify).
11909 if Is_Protected_Type (Ent)
11910 and then not Has_Preelaborable_Initialization (Ent)
11913 ("protected type & does not have preelaborable " &
11914 "initialization", Ent);
11916 -- Otherwise mark the type as definitely having preelaborable
11920 Set_Known_To_Have_Preelab_Init (Ent);
11923 if Has_Pragma_Preelab_Init (Ent)
11924 and then Warn_On_Redundant_Constructs
11926 Error_Pragma ("?duplicate pragma%!");
11928 Set_Has_Pragma_Preelab_Init (Ent);
11932 --------------------
11933 -- Persistent_BSS --
11934 --------------------
11936 -- pragma Persistent_BSS [(object_NAME)];
11938 when Pragma_Persistent_BSS => Persistent_BSS : declare
11945 Check_At_Most_N_Arguments (1);
11947 -- Case of application to specific object (one argument)
11949 if Arg_Count = 1 then
11950 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11952 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11954 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11957 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11960 Ent := Entity (Get_Pragma_Arg (Arg1));
11961 Decl := Parent (Ent);
11963 if Rep_Item_Too_Late (Ent, N) then
11967 if Present (Expression (Decl)) then
11969 ("object for pragma% cannot have initialization", Arg1);
11972 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11974 ("object type for pragma% is not potentially persistent",
11978 Check_Duplicate_Pragma (Ent);
11981 Make_Linker_Section_Pragma
11982 (Ent, Sloc (N), ".persistent.bss");
11983 Insert_After (N, Prag);
11986 -- Case of use as configuration pragma with no arguments
11989 Check_Valid_Configuration_Pragma;
11990 Persistent_BSS_Mode := True;
11992 end Persistent_BSS;
11998 -- pragma Polling (ON | OFF);
12000 when Pragma_Polling =>
12002 Check_Arg_Count (1);
12003 Check_No_Identifiers;
12004 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12005 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
12007 -------------------
12008 -- Postcondition --
12009 -------------------
12011 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
12012 -- [,[Message =>] String_EXPRESSION]);
12014 when Pragma_Postcondition => Postcondition : declare
12016 pragma Warnings (Off, In_Body);
12020 Check_At_Least_N_Arguments (1);
12021 Check_At_Most_N_Arguments (2);
12022 Check_Optional_Identifier (Arg1, Name_Check);
12024 -- All we need to do here is call the common check procedure,
12025 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
12027 Check_Precondition_Postcondition (In_Body);
12034 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
12035 -- [,[Message =>] String_EXPRESSION]);
12037 when Pragma_Precondition => Precondition : declare
12042 Check_At_Least_N_Arguments (1);
12043 Check_At_Most_N_Arguments (2);
12044 Check_Optional_Identifier (Arg1, Name_Check);
12045 Check_Precondition_Postcondition (In_Body);
12047 -- If in spec, nothing more to do. If in body, then we convert the
12048 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
12049 -- this whether or not precondition checks are enabled. That works
12050 -- fine since pragma Check will do this check, and will also
12051 -- analyze the condition itself in the proper context.
12056 Chars => Name_Check,
12057 Pragma_Argument_Associations => New_List (
12058 Make_Pragma_Argument_Association (Loc,
12059 Expression => Make_Identifier (Loc, Name_Precondition)),
12061 Make_Pragma_Argument_Association (Sloc (Arg1),
12062 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
12064 if Arg_Count = 2 then
12065 Append_To (Pragma_Argument_Associations (N),
12066 Make_Pragma_Argument_Association (Sloc (Arg2),
12067 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
12078 -- pragma Predicate
12079 -- ([Entity =>] type_LOCAL_NAME,
12080 -- [Check =>] EXPRESSION);
12082 when Pragma_Predicate => Predicate : declare
12087 pragma Unreferenced (Discard);
12091 Check_Arg_Count (2);
12092 Check_Optional_Identifier (Arg1, Name_Entity);
12093 Check_Optional_Identifier (Arg2, Name_Check);
12095 Check_Arg_Is_Local_Name (Arg1);
12097 Type_Id := Get_Pragma_Arg (Arg1);
12098 Find_Type (Type_Id);
12099 Typ := Entity (Type_Id);
12101 if Typ = Any_Type then
12105 -- The remaining processing is simply to link the pragma on to
12106 -- the rep item chain, for processing when the type is frozen.
12107 -- This is accomplished by a call to Rep_Item_Too_Late. We also
12108 -- mark the type as having predicates.
12110 Set_Has_Predicates (Typ);
12111 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12118 -- pragma Preelaborate [(library_unit_NAME)];
12120 -- Set the flag Is_Preelaborated of program unit name entity
12122 when Pragma_Preelaborate => Preelaborate : declare
12123 Pa : constant Node_Id := Parent (N);
12124 Pk : constant Node_Kind := Nkind (Pa);
12128 Check_Ada_83_Warning;
12129 Check_Valid_Library_Unit_Pragma;
12131 if Nkind (N) = N_Null_Statement then
12135 Ent := Find_Lib_Unit_Name;
12136 Check_Duplicate_Pragma (Ent);
12138 -- This filters out pragmas inside generic parent then
12139 -- show up inside instantiation
12142 and then not (Pk = N_Package_Specification
12143 and then Present (Generic_Parent (Pa)))
12145 if not Debug_Flag_U then
12146 Set_Is_Preelaborated (Ent);
12147 Set_Suppress_Elaboration_Warnings (Ent);
12152 ---------------------
12153 -- Preelaborate_05 --
12154 ---------------------
12156 -- pragma Preelaborate_05 [(library_unit_NAME)];
12158 -- This pragma is useable only in GNAT_Mode, where it is used like
12159 -- pragma Preelaborate but it is only effective in Ada 2005 mode
12160 -- (otherwise it is ignored). This is used to implement AI-362 which
12161 -- recategorizes some run-time packages in Ada 2005 mode.
12163 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
12168 Check_Valid_Library_Unit_Pragma;
12170 if not GNAT_Mode then
12171 Error_Pragma ("pragma% only available in GNAT mode");
12174 if Nkind (N) = N_Null_Statement then
12178 -- This is one of the few cases where we need to test the value of
12179 -- Ada_Version_Explicit rather than Ada_Version (which is always
12180 -- set to Ada_2012 in a predefined unit), we need to know the
12181 -- explicit version set to know if this pragma is active.
12183 if Ada_Version_Explicit >= Ada_2005 then
12184 Ent := Find_Lib_Unit_Name;
12185 Set_Is_Preelaborated (Ent);
12186 Set_Suppress_Elaboration_Warnings (Ent);
12188 end Preelaborate_05;
12194 -- pragma Priority (EXPRESSION);
12196 when Pragma_Priority => Priority : declare
12197 P : constant Node_Id := Parent (N);
12201 Check_No_Identifiers;
12202 Check_Arg_Count (1);
12206 if Nkind (P) = N_Subprogram_Body then
12207 Check_In_Main_Program;
12209 Arg := Get_Pragma_Arg (Arg1);
12210 Analyze_And_Resolve (Arg, Standard_Integer);
12214 if not Is_Static_Expression (Arg) then
12215 Flag_Non_Static_Expr
12216 ("main subprogram priority is not static!", Arg);
12219 -- If constraint error, then we already signalled an error
12221 elsif Raises_Constraint_Error (Arg) then
12224 -- Otherwise check in range
12228 Val : constant Uint := Expr_Value (Arg);
12232 or else Val > Expr_Value (Expression
12233 (Parent (RTE (RE_Max_Priority))))
12236 ("main subprogram priority is out of range", Arg1);
12242 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12244 -- Load an arbitrary entity from System.Tasking to make sure
12245 -- this package is implicitly with'ed, since we need to have
12246 -- the tasking run-time active for the pragma Priority to have
12250 Discard : Entity_Id;
12251 pragma Warnings (Off, Discard);
12253 Discard := RTE (RE_Task_List);
12256 -- Task or Protected, must be of type Integer
12258 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12259 Arg := Get_Pragma_Arg (Arg1);
12261 -- The expression must be analyzed in the special manner
12262 -- described in "Handling of Default and Per-Object
12263 -- Expressions" in sem.ads.
12265 Preanalyze_Spec_Expression (Arg, Standard_Integer);
12267 if not Is_Static_Expression (Arg) then
12268 Check_Restriction (Static_Priorities, Arg);
12271 -- Anything else is incorrect
12277 if Has_Pragma_Priority (P) then
12278 Error_Pragma ("duplicate pragma% not allowed");
12280 Set_Has_Pragma_Priority (P, True);
12282 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12283 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12284 -- exp_ch9 should use this ???
12289 -----------------------------------
12290 -- Priority_Specific_Dispatching --
12291 -----------------------------------
12293 -- pragma Priority_Specific_Dispatching (
12294 -- policy_IDENTIFIER,
12295 -- first_priority_EXPRESSION,
12296 -- last_priority_EXPRESSION);
12298 when Pragma_Priority_Specific_Dispatching =>
12299 Priority_Specific_Dispatching : declare
12300 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12301 -- This is the entity System.Any_Priority;
12304 Lower_Bound : Node_Id;
12305 Upper_Bound : Node_Id;
12311 Check_Arg_Count (3);
12312 Check_No_Identifiers;
12313 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12314 Check_Valid_Configuration_Pragma;
12315 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12316 DP := Fold_Upper (Name_Buffer (1));
12318 Lower_Bound := Get_Pragma_Arg (Arg2);
12319 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12320 Lower_Val := Expr_Value (Lower_Bound);
12322 Upper_Bound := Get_Pragma_Arg (Arg3);
12323 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12324 Upper_Val := Expr_Value (Upper_Bound);
12326 -- It is not allowed to use Task_Dispatching_Policy and
12327 -- Priority_Specific_Dispatching in the same partition.
12329 if Task_Dispatching_Policy /= ' ' then
12330 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12332 ("pragma% incompatible with Task_Dispatching_Policy#");
12334 -- Check lower bound in range
12336 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12338 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12341 ("first_priority is out of range", Arg2);
12343 -- Check upper bound in range
12345 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12347 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12350 ("last_priority is out of range", Arg3);
12352 -- Check that the priority range is valid
12354 elsif Lower_Val > Upper_Val then
12356 ("last_priority_expression must be greater than" &
12357 " or equal to first_priority_expression");
12359 -- Store the new policy, but always preserve System_Location since
12360 -- we like the error message with the run-time name.
12363 -- Check overlapping in the priority ranges specified in other
12364 -- Priority_Specific_Dispatching pragmas within the same
12365 -- partition. We can only check those we know about!
12368 Specific_Dispatching.First .. Specific_Dispatching.Last
12370 if Specific_Dispatching.Table (J).First_Priority in
12371 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12372 or else Specific_Dispatching.Table (J).Last_Priority in
12373 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12376 Specific_Dispatching.Table (J).Pragma_Loc;
12378 ("priority range overlaps with "
12379 & "Priority_Specific_Dispatching#");
12383 -- The use of Priority_Specific_Dispatching is incompatible
12384 -- with Task_Dispatching_Policy.
12386 if Task_Dispatching_Policy /= ' ' then
12387 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12389 ("Priority_Specific_Dispatching incompatible "
12390 & "with Task_Dispatching_Policy#");
12393 -- The use of Priority_Specific_Dispatching forces ceiling
12396 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12397 Error_Msg_Sloc := Locking_Policy_Sloc;
12399 ("Priority_Specific_Dispatching incompatible "
12400 & "with Locking_Policy#");
12402 -- Set the Ceiling_Locking policy, but preserve System_Location
12403 -- since we like the error message with the run time name.
12406 Locking_Policy := 'C';
12408 if Locking_Policy_Sloc /= System_Location then
12409 Locking_Policy_Sloc := Loc;
12413 -- Add entry in the table
12415 Specific_Dispatching.Append
12416 ((Dispatching_Policy => DP,
12417 First_Priority => UI_To_Int (Lower_Val),
12418 Last_Priority => UI_To_Int (Upper_Val),
12419 Pragma_Loc => Loc));
12421 end Priority_Specific_Dispatching;
12427 -- pragma Profile (profile_IDENTIFIER);
12429 -- profile_IDENTIFIER => Restricted | Ravenscar
12431 when Pragma_Profile =>
12433 Check_Arg_Count (1);
12434 Check_Valid_Configuration_Pragma;
12435 Check_No_Identifiers;
12438 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12441 if Chars (Argx) = Name_Ravenscar then
12442 Set_Ravenscar_Profile (N);
12444 elsif Chars (Argx) = Name_Restricted then
12445 Set_Profile_Restrictions
12447 N, Warn => Treat_Restrictions_As_Warnings);
12449 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12450 Set_Profile_Restrictions
12451 (No_Implementation_Extensions,
12452 N, Warn => Treat_Restrictions_As_Warnings);
12455 Error_Pragma_Arg ("& is not a valid profile", Argx);
12459 ----------------------
12460 -- Profile_Warnings --
12461 ----------------------
12463 -- pragma Profile_Warnings (profile_IDENTIFIER);
12465 -- profile_IDENTIFIER => Restricted | Ravenscar
12467 when Pragma_Profile_Warnings =>
12469 Check_Arg_Count (1);
12470 Check_Valid_Configuration_Pragma;
12471 Check_No_Identifiers;
12474 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12477 if Chars (Argx) = Name_Ravenscar then
12478 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12480 elsif Chars (Argx) = Name_Restricted then
12481 Set_Profile_Restrictions (Restricted, N, Warn => True);
12483 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12484 Set_Profile_Restrictions
12485 (No_Implementation_Extensions, N, Warn => True);
12488 Error_Pragma_Arg ("& is not a valid profile", Argx);
12492 --------------------------
12493 -- Propagate_Exceptions --
12494 --------------------------
12496 -- pragma Propagate_Exceptions;
12498 -- Note: this pragma is obsolete and has no effect
12500 when Pragma_Propagate_Exceptions =>
12502 Check_Arg_Count (0);
12504 if In_Extended_Main_Source_Unit (N) then
12505 Propagate_Exceptions := True;
12512 -- pragma Psect_Object (
12513 -- [Internal =>] LOCAL_NAME,
12514 -- [, [External =>] EXTERNAL_SYMBOL]
12515 -- [, [Size =>] EXTERNAL_SYMBOL]);
12517 when Pragma_Psect_Object | Pragma_Common_Object =>
12518 Psect_Object : declare
12519 Args : Args_List (1 .. 3);
12520 Names : constant Name_List (1 .. 3) := (
12525 Internal : Node_Id renames Args (1);
12526 External : Node_Id renames Args (2);
12527 Size : Node_Id renames Args (3);
12529 Def_Id : Entity_Id;
12531 procedure Check_Too_Long (Arg : Node_Id);
12532 -- Posts message if the argument is an identifier with more
12533 -- than 31 characters, or a string literal with more than
12534 -- 31 characters, and we are operating under VMS
12536 --------------------
12537 -- Check_Too_Long --
12538 --------------------
12540 procedure Check_Too_Long (Arg : Node_Id) is
12541 X : constant Node_Id := Original_Node (Arg);
12544 if not Nkind_In (X, N_String_Literal, N_Identifier) then
12546 ("inappropriate argument for pragma %", Arg);
12549 if OpenVMS_On_Target then
12550 if (Nkind (X) = N_String_Literal
12551 and then String_Length (Strval (X)) > 31)
12553 (Nkind (X) = N_Identifier
12554 and then Length_Of_Name (Chars (X)) > 31)
12557 ("argument for pragma % is longer than 31 characters",
12561 end Check_Too_Long;
12563 -- Start of processing for Common_Object/Psect_Object
12567 Gather_Associations (Names, Args);
12568 Process_Extended_Import_Export_Internal_Arg (Internal);
12570 Def_Id := Entity (Internal);
12572 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12574 ("pragma% must designate an object", Internal);
12577 Check_Too_Long (Internal);
12579 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12581 ("cannot use pragma% for imported/exported object",
12585 if Is_Concurrent_Type (Etype (Internal)) then
12587 ("cannot specify pragma % for task/protected object",
12591 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12593 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12595 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12598 if Ekind (Def_Id) = E_Constant then
12600 ("cannot specify pragma % for a constant", Internal);
12603 if Is_Record_Type (Etype (Internal)) then
12609 Ent := First_Entity (Etype (Internal));
12610 while Present (Ent) loop
12611 Decl := Declaration_Node (Ent);
12613 if Ekind (Ent) = E_Component
12614 and then Nkind (Decl) = N_Component_Declaration
12615 and then Present (Expression (Decl))
12616 and then Warn_On_Export_Import
12619 ("?object for pragma % has defaults", Internal);
12629 if Present (Size) then
12630 Check_Too_Long (Size);
12633 if Present (External) then
12634 Check_Arg_Is_External_Name (External);
12635 Check_Too_Long (External);
12638 -- If all error tests pass, link pragma on to the rep item chain
12640 Record_Rep_Item (Def_Id, N);
12647 -- pragma Pure [(library_unit_NAME)];
12649 when Pragma_Pure => Pure : declare
12653 Check_Ada_83_Warning;
12654 Check_Valid_Library_Unit_Pragma;
12656 if Nkind (N) = N_Null_Statement then
12660 Ent := Find_Lib_Unit_Name;
12662 Set_Has_Pragma_Pure (Ent);
12663 Set_Suppress_Elaboration_Warnings (Ent);
12670 -- pragma Pure_05 [(library_unit_NAME)];
12672 -- This pragma is useable only in GNAT_Mode, where it is used like
12673 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
12674 -- it is ignored). It may be used after a pragma Preelaborate, in
12675 -- which case it overrides the effect of the pragma Preelaborate.
12676 -- This is used to implement AI-362 which recategorizes some run-time
12677 -- packages in Ada 2005 mode.
12679 when Pragma_Pure_05 => Pure_05 : declare
12684 Check_Valid_Library_Unit_Pragma;
12686 if not GNAT_Mode then
12687 Error_Pragma ("pragma% only available in GNAT mode");
12690 if Nkind (N) = N_Null_Statement then
12694 -- This is one of the few cases where we need to test the value of
12695 -- Ada_Version_Explicit rather than Ada_Version (which is always
12696 -- set to Ada_2012 in a predefined unit), we need to know the
12697 -- explicit version set to know if this pragma is active.
12699 if Ada_Version_Explicit >= Ada_2005 then
12700 Ent := Find_Lib_Unit_Name;
12701 Set_Is_Preelaborated (Ent, False);
12703 Set_Suppress_Elaboration_Warnings (Ent);
12711 -- pragma Pure_12 [(library_unit_NAME)];
12713 -- This pragma is useable only in GNAT_Mode, where it is used like
12714 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
12715 -- it is ignored). It may be used after a pragma Preelaborate, in
12716 -- which case it overrides the effect of the pragma Preelaborate.
12717 -- This is used to implement AI05-0212 which recategorizes some
12718 -- run-time packages in Ada 2012 mode.
12720 when Pragma_Pure_12 => Pure_12 : declare
12725 Check_Valid_Library_Unit_Pragma;
12727 if not GNAT_Mode then
12728 Error_Pragma ("pragma% only available in GNAT mode");
12731 if Nkind (N) = N_Null_Statement then
12735 -- This is one of the few cases where we need to test the value of
12736 -- Ada_Version_Explicit rather than Ada_Version (which is always
12737 -- set to Ada_2012 in a predefined unit), we need to know the
12738 -- explicit version set to know if this pragma is active.
12740 if Ada_Version_Explicit >= Ada_2012 then
12741 Ent := Find_Lib_Unit_Name;
12742 Set_Is_Preelaborated (Ent, False);
12744 Set_Suppress_Elaboration_Warnings (Ent);
12748 -------------------
12749 -- Pure_Function --
12750 -------------------
12752 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12754 when Pragma_Pure_Function => Pure_Function : declare
12757 Def_Id : Entity_Id;
12758 Effective : Boolean := False;
12762 Check_Arg_Count (1);
12763 Check_Optional_Identifier (Arg1, Name_Entity);
12764 Check_Arg_Is_Local_Name (Arg1);
12765 E_Id := Get_Pragma_Arg (Arg1);
12767 if Error_Posted (E_Id) then
12771 -- Loop through homonyms (overloadings) of referenced entity
12773 E := Entity (E_Id);
12775 if Present (E) then
12777 Def_Id := Get_Base_Subprogram (E);
12779 if not Ekind_In (Def_Id, E_Function,
12780 E_Generic_Function,
12784 ("pragma% requires a function name", Arg1);
12787 Set_Is_Pure (Def_Id);
12789 if not Has_Pragma_Pure_Function (Def_Id) then
12790 Set_Has_Pragma_Pure_Function (Def_Id);
12794 exit when From_Aspect_Specification (N);
12796 exit when No (E) or else Scope (E) /= Current_Scope;
12800 and then Warn_On_Redundant_Constructs
12803 ("pragma Pure_Function on& is redundant?",
12809 --------------------
12810 -- Queuing_Policy --
12811 --------------------
12813 -- pragma Queuing_Policy (policy_IDENTIFIER);
12815 when Pragma_Queuing_Policy => declare
12819 Check_Ada_83_Warning;
12820 Check_Arg_Count (1);
12821 Check_No_Identifiers;
12822 Check_Arg_Is_Queuing_Policy (Arg1);
12823 Check_Valid_Configuration_Pragma;
12824 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12825 QP := Fold_Upper (Name_Buffer (1));
12827 if Queuing_Policy /= ' '
12828 and then Queuing_Policy /= QP
12830 Error_Msg_Sloc := Queuing_Policy_Sloc;
12831 Error_Pragma ("queuing policy incompatible with policy#");
12833 -- Set new policy, but always preserve System_Location since we
12834 -- like the error message with the run time name.
12837 Queuing_Policy := QP;
12839 if Queuing_Policy_Sloc /= System_Location then
12840 Queuing_Policy_Sloc := Loc;
12845 -----------------------
12846 -- Relative_Deadline --
12847 -----------------------
12849 -- pragma Relative_Deadline (time_span_EXPRESSION);
12851 when Pragma_Relative_Deadline => Relative_Deadline : declare
12852 P : constant Node_Id := Parent (N);
12857 Check_No_Identifiers;
12858 Check_Arg_Count (1);
12860 Arg := Get_Pragma_Arg (Arg1);
12862 -- The expression must be analyzed in the special manner described
12863 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12865 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12869 if Nkind (P) = N_Subprogram_Body then
12870 Check_In_Main_Program;
12874 elsif Nkind (P) = N_Task_Definition then
12877 -- Anything else is incorrect
12883 if Has_Relative_Deadline_Pragma (P) then
12884 Error_Pragma ("duplicate pragma% not allowed");
12886 Set_Has_Relative_Deadline_Pragma (P, True);
12888 if Nkind (P) = N_Task_Definition then
12889 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12892 end Relative_Deadline;
12894 ------------------------
12895 -- Remote_Access_Type --
12896 ------------------------
12898 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
12900 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
12905 Check_Arg_Count (1);
12906 Check_Optional_Identifier (Arg1, Name_Entity);
12907 Check_Arg_Is_Local_Name (Arg1);
12909 E := Entity (Get_Pragma_Arg (Arg1));
12911 if Nkind (Parent (E)) = N_Formal_Type_Declaration
12912 and then Ekind (E) = E_General_Access_Type
12913 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
12914 and then Scope (Root_Type (Directly_Designated_Type (E)))
12916 and then Is_Valid_Remote_Object_Type
12917 (Root_Type (Directly_Designated_Type (E)))
12919 Set_Is_Remote_Types (E);
12923 ("pragma% applies only to formal access to classwide types",
12926 end Remote_Access_Type;
12928 ---------------------------
12929 -- Remote_Call_Interface --
12930 ---------------------------
12932 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12934 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12935 Cunit_Node : Node_Id;
12936 Cunit_Ent : Entity_Id;
12940 Check_Ada_83_Warning;
12941 Check_Valid_Library_Unit_Pragma;
12943 if Nkind (N) = N_Null_Statement then
12947 Cunit_Node := Cunit (Current_Sem_Unit);
12948 K := Nkind (Unit (Cunit_Node));
12949 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12951 if K = N_Package_Declaration
12952 or else K = N_Generic_Package_Declaration
12953 or else K = N_Subprogram_Declaration
12954 or else K = N_Generic_Subprogram_Declaration
12955 or else (K = N_Subprogram_Body
12956 and then Acts_As_Spec (Unit (Cunit_Node)))
12961 "pragma% must apply to package or subprogram declaration");
12964 Set_Is_Remote_Call_Interface (Cunit_Ent);
12965 end Remote_Call_Interface;
12971 -- pragma Remote_Types [(library_unit_NAME)];
12973 when Pragma_Remote_Types => Remote_Types : declare
12974 Cunit_Node : Node_Id;
12975 Cunit_Ent : Entity_Id;
12978 Check_Ada_83_Warning;
12979 Check_Valid_Library_Unit_Pragma;
12981 if Nkind (N) = N_Null_Statement then
12985 Cunit_Node := Cunit (Current_Sem_Unit);
12986 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12988 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12989 N_Generic_Package_Declaration)
12992 ("pragma% can only apply to a package declaration");
12995 Set_Is_Remote_Types (Cunit_Ent);
13002 -- pragma Ravenscar;
13004 when Pragma_Ravenscar =>
13006 Check_Arg_Count (0);
13007 Check_Valid_Configuration_Pragma;
13008 Set_Ravenscar_Profile (N);
13010 if Warn_On_Obsolescent_Feature then
13011 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
13012 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
13015 -------------------------
13016 -- Restricted_Run_Time --
13017 -------------------------
13019 -- pragma Restricted_Run_Time;
13021 when Pragma_Restricted_Run_Time =>
13023 Check_Arg_Count (0);
13024 Check_Valid_Configuration_Pragma;
13025 Set_Profile_Restrictions
13026 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
13028 if Warn_On_Obsolescent_Feature then
13030 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
13031 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
13038 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
13041 -- restriction_IDENTIFIER
13042 -- | restriction_parameter_IDENTIFIER => EXPRESSION
13044 when Pragma_Restrictions =>
13045 Process_Restrictions_Or_Restriction_Warnings
13046 (Warn => Treat_Restrictions_As_Warnings);
13048 --------------------------
13049 -- Restriction_Warnings --
13050 --------------------------
13052 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
13055 -- restriction_IDENTIFIER
13056 -- | restriction_parameter_IDENTIFIER => EXPRESSION
13058 when Pragma_Restriction_Warnings =>
13060 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
13066 -- pragma Reviewable;
13068 when Pragma_Reviewable =>
13069 Check_Ada_83_Warning;
13070 Check_Arg_Count (0);
13072 -- Call dummy debugging function rv. This is done to assist front
13073 -- end debugging. By placing a Reviewable pragma in the source
13074 -- program, a breakpoint on rv catches this place in the source,
13075 -- allowing convenient stepping to the point of interest.
13079 --------------------------
13080 -- Short_Circuit_And_Or --
13081 --------------------------
13083 when Pragma_Short_Circuit_And_Or =>
13085 Check_Arg_Count (0);
13086 Check_Valid_Configuration_Pragma;
13087 Short_Circuit_And_Or := True;
13089 -------------------
13090 -- Share_Generic --
13091 -------------------
13093 -- pragma Share_Generic (NAME {, NAME});
13095 when Pragma_Share_Generic =>
13097 Process_Generic_List;
13103 -- pragma Shared (LOCAL_NAME);
13105 when Pragma_Shared =>
13107 Process_Atomic_Shared_Volatile;
13109 --------------------
13110 -- Shared_Passive --
13111 --------------------
13113 -- pragma Shared_Passive [(library_unit_NAME)];
13115 -- Set the flag Is_Shared_Passive of program unit name entity
13117 when Pragma_Shared_Passive => Shared_Passive : declare
13118 Cunit_Node : Node_Id;
13119 Cunit_Ent : Entity_Id;
13122 Check_Ada_83_Warning;
13123 Check_Valid_Library_Unit_Pragma;
13125 if Nkind (N) = N_Null_Statement then
13129 Cunit_Node := Cunit (Current_Sem_Unit);
13130 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13132 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13133 N_Generic_Package_Declaration)
13136 ("pragma% can only apply to a package declaration");
13139 Set_Is_Shared_Passive (Cunit_Ent);
13140 end Shared_Passive;
13142 -----------------------
13143 -- Short_Descriptors --
13144 -----------------------
13146 -- pragma Short_Descriptors;
13148 when Pragma_Short_Descriptors =>
13150 Check_Arg_Count (0);
13151 Check_Valid_Configuration_Pragma;
13152 Short_Descriptors := True;
13154 ------------------------------
13155 -- Simple_Storage_Pool_Type --
13156 ------------------------------
13158 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
13160 when Pragma_Simple_Storage_Pool_Type =>
13161 Simple_Storage_Pool_Type : declare
13167 Check_Arg_Count (1);
13168 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13170 Type_Id := Get_Pragma_Arg (Arg1);
13171 Find_Type (Type_Id);
13172 Typ := Entity (Type_Id);
13174 if Typ = Any_Type then
13178 -- We require the pragma to apply to a type declared in a package
13179 -- declaration, but not (immediately) within a package body.
13181 if Ekind (Current_Scope) /= E_Package
13182 or else In_Package_Body (Current_Scope)
13185 ("pragma% can only apply to type declared immediately " &
13186 "within a package declaration");
13189 -- A simple storage pool type must be an immutably limited record
13190 -- or private type. If the pragma is given for a private type,
13191 -- the full type is similarly restricted (which is checked later
13192 -- in Freeze_Entity).
13194 if Is_Record_Type (Typ)
13195 and then not Is_Immutably_Limited_Type (Typ)
13198 ("pragma% can only apply to explicitly limited record type");
13200 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
13202 ("pragma% can only apply to a private type that is limited");
13204 elsif not Is_Record_Type (Typ)
13205 and then not Is_Private_Type (Typ)
13208 ("pragma% can only apply to limited record or private type");
13211 Record_Rep_Item (Typ, N);
13212 end Simple_Storage_Pool_Type;
13214 ----------------------
13215 -- Source_File_Name --
13216 ----------------------
13218 -- There are five forms for this pragma:
13220 -- pragma Source_File_Name (
13221 -- [UNIT_NAME =>] unit_NAME,
13222 -- BODY_FILE_NAME => STRING_LITERAL
13223 -- [, [INDEX =>] INTEGER_LITERAL]);
13225 -- pragma Source_File_Name (
13226 -- [UNIT_NAME =>] unit_NAME,
13227 -- SPEC_FILE_NAME => STRING_LITERAL
13228 -- [, [INDEX =>] INTEGER_LITERAL]);
13230 -- pragma Source_File_Name (
13231 -- BODY_FILE_NAME => STRING_LITERAL
13232 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13233 -- [, CASING => CASING_SPEC]);
13235 -- pragma Source_File_Name (
13236 -- SPEC_FILE_NAME => STRING_LITERAL
13237 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13238 -- [, CASING => CASING_SPEC]);
13240 -- pragma Source_File_Name (
13241 -- SUBUNIT_FILE_NAME => STRING_LITERAL
13242 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13243 -- [, CASING => CASING_SPEC]);
13245 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
13247 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
13248 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
13249 -- only be used when no project file is used, while SFNP can only be
13250 -- used when a project file is used.
13252 -- No processing here. Processing was completed during parsing, since
13253 -- we need to have file names set as early as possible. Units are
13254 -- loaded well before semantic processing starts.
13256 -- The only processing we defer to this point is the check for
13257 -- correct placement.
13259 when Pragma_Source_File_Name =>
13261 Check_Valid_Configuration_Pragma;
13263 ------------------------------
13264 -- Source_File_Name_Project --
13265 ------------------------------
13267 -- See Source_File_Name for syntax
13269 -- No processing here. Processing was completed during parsing, since
13270 -- we need to have file names set as early as possible. Units are
13271 -- loaded well before semantic processing starts.
13273 -- The only processing we defer to this point is the check for
13274 -- correct placement.
13276 when Pragma_Source_File_Name_Project =>
13278 Check_Valid_Configuration_Pragma;
13280 -- Check that a pragma Source_File_Name_Project is used only in a
13281 -- configuration pragmas file.
13283 -- Pragmas Source_File_Name_Project should only be generated by
13284 -- the Project Manager in configuration pragmas files.
13286 -- This is really an ugly test. It seems to depend on some
13287 -- accidental and undocumented property. At the very least it
13288 -- needs to be documented, but it would be better to have a
13289 -- clean way of testing if we are in a configuration file???
13291 if Present (Parent (N)) then
13293 ("pragma% can only appear in a configuration pragmas file");
13296 ----------------------
13297 -- Source_Reference --
13298 ----------------------
13300 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
13302 -- Nothing to do, all processing completed in Par.Prag, since we need
13303 -- the information for possible parser messages that are output.
13305 when Pragma_Source_Reference =>
13308 --------------------------------
13309 -- Static_Elaboration_Desired --
13310 --------------------------------
13312 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
13314 when Pragma_Static_Elaboration_Desired =>
13316 Check_At_Most_N_Arguments (1);
13318 if Is_Compilation_Unit (Current_Scope)
13319 and then Ekind (Current_Scope) = E_Package
13321 Set_Static_Elaboration_Desired (Current_Scope, True);
13323 Error_Pragma ("pragma% must apply to a library-level package");
13330 -- pragma Storage_Size (EXPRESSION);
13332 when Pragma_Storage_Size => Storage_Size : declare
13333 P : constant Node_Id := Parent (N);
13337 Check_No_Identifiers;
13338 Check_Arg_Count (1);
13340 -- The expression must be analyzed in the special manner described
13341 -- in "Handling of Default Expressions" in sem.ads.
13343 Arg := Get_Pragma_Arg (Arg1);
13344 Preanalyze_Spec_Expression (Arg, Any_Integer);
13346 if not Is_Static_Expression (Arg) then
13347 Check_Restriction (Static_Storage_Size, Arg);
13350 if Nkind (P) /= N_Task_Definition then
13355 if Has_Storage_Size_Pragma (P) then
13356 Error_Pragma ("duplicate pragma% not allowed");
13358 Set_Has_Storage_Size_Pragma (P, True);
13361 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13362 -- ??? exp_ch9 should use this!
13370 -- pragma Storage_Unit (NUMERIC_LITERAL);
13372 -- Only permitted argument is System'Storage_Unit value
13374 when Pragma_Storage_Unit =>
13375 Check_No_Identifiers;
13376 Check_Arg_Count (1);
13377 Check_Arg_Is_Integer_Literal (Arg1);
13379 if Intval (Get_Pragma_Arg (Arg1)) /=
13380 UI_From_Int (Ttypes.System_Storage_Unit)
13382 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
13384 ("the only allowed argument for pragma% is ^", Arg1);
13387 --------------------
13388 -- Stream_Convert --
13389 --------------------
13391 -- pragma Stream_Convert (
13392 -- [Entity =>] type_LOCAL_NAME,
13393 -- [Read =>] function_NAME,
13394 -- [Write =>] function NAME);
13396 when Pragma_Stream_Convert => Stream_Convert : declare
13398 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
13399 -- Check that the given argument is the name of a local function
13400 -- of one argument that is not overloaded earlier in the current
13401 -- local scope. A check is also made that the argument is a
13402 -- function with one parameter.
13404 --------------------------------------
13405 -- Check_OK_Stream_Convert_Function --
13406 --------------------------------------
13408 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
13412 Check_Arg_Is_Local_Name (Arg);
13413 Ent := Entity (Get_Pragma_Arg (Arg));
13415 if Has_Homonym (Ent) then
13417 ("argument for pragma% may not be overloaded", Arg);
13420 if Ekind (Ent) /= E_Function
13421 or else No (First_Formal (Ent))
13422 or else Present (Next_Formal (First_Formal (Ent)))
13425 ("argument for pragma% must be" &
13426 " function of one argument", Arg);
13428 end Check_OK_Stream_Convert_Function;
13430 -- Start of processing for Stream_Convert
13434 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
13435 Check_Arg_Count (3);
13436 Check_Optional_Identifier (Arg1, Name_Entity);
13437 Check_Optional_Identifier (Arg2, Name_Read);
13438 Check_Optional_Identifier (Arg3, Name_Write);
13439 Check_Arg_Is_Local_Name (Arg1);
13440 Check_OK_Stream_Convert_Function (Arg2);
13441 Check_OK_Stream_Convert_Function (Arg3);
13444 Typ : constant Entity_Id :=
13445 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13446 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13447 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
13450 Check_First_Subtype (Arg1);
13452 -- Check for too early or too late. Note that we don't enforce
13453 -- the rule about primitive operations in this case, since, as
13454 -- is the case for explicit stream attributes themselves, these
13455 -- restrictions are not appropriate. Note that the chaining of
13456 -- the pragma by Rep_Item_Too_Late is actually the critical
13457 -- processing done for this pragma.
13459 if Rep_Item_Too_Early (Typ, N)
13461 Rep_Item_Too_Late (Typ, N, FOnly => True)
13466 -- Return if previous error
13468 if Etype (Typ) = Any_Type
13470 Etype (Read) = Any_Type
13472 Etype (Write) = Any_Type
13479 if Underlying_Type (Etype (Read)) /= Typ then
13481 ("incorrect return type for function&", Arg2);
13484 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13486 ("incorrect parameter type for function&", Arg3);
13489 if Underlying_Type (Etype (First_Formal (Read))) /=
13490 Underlying_Type (Etype (Write))
13493 ("result type of & does not match Read parameter type",
13497 end Stream_Convert;
13499 -------------------------
13500 -- Style_Checks (GNAT) --
13501 -------------------------
13503 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13505 -- This is processed by the parser since some of the style checks
13506 -- take place during source scanning and parsing. This means that
13507 -- we don't need to issue error messages here.
13509 when Pragma_Style_Checks => Style_Checks : declare
13510 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13516 Check_No_Identifiers;
13518 -- Two argument form
13520 if Arg_Count = 2 then
13521 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13528 E_Id := Get_Pragma_Arg (Arg2);
13531 if not Is_Entity_Name (E_Id) then
13533 ("second argument of pragma% must be entity name",
13537 E := Entity (E_Id);
13543 Set_Suppress_Style_Checks (E,
13544 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
13545 exit when No (Homonym (E));
13551 -- One argument form
13554 Check_Arg_Count (1);
13556 if Nkind (A) = N_String_Literal then
13560 Slen : constant Natural := Natural (String_Length (S));
13561 Options : String (1 .. Slen);
13567 C := Get_String_Char (S, Int (J));
13568 exit when not In_Character_Range (C);
13569 Options (J) := Get_Character (C);
13571 -- If at end of string, set options. As per discussion
13572 -- above, no need to check for errors, since we issued
13573 -- them in the parser.
13576 Set_Style_Check_Options (Options);
13584 elsif Nkind (A) = N_Identifier then
13585 if Chars (A) = Name_All_Checks then
13587 Set_GNAT_Style_Check_Options;
13589 Set_Default_Style_Check_Options;
13592 elsif Chars (A) = Name_On then
13593 Style_Check := True;
13595 elsif Chars (A) = Name_Off then
13596 Style_Check := False;
13606 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13608 when Pragma_Subtitle =>
13610 Check_Arg_Count (1);
13611 Check_Optional_Identifier (Arg1, Name_Subtitle);
13612 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13619 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13621 when Pragma_Suppress =>
13622 Process_Suppress_Unsuppress (True);
13628 -- pragma Suppress_All;
13630 -- The only check made here is that the pragma has no arguments.
13631 -- There are no placement rules, and the processing required (setting
13632 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
13633 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
13634 -- then creates and inserts a pragma Suppress (All_Checks).
13636 when Pragma_Suppress_All =>
13638 Check_Arg_Count (0);
13640 -------------------------
13641 -- Suppress_Debug_Info --
13642 -------------------------
13644 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13646 when Pragma_Suppress_Debug_Info =>
13648 Check_Arg_Count (1);
13649 Check_Optional_Identifier (Arg1, Name_Entity);
13650 Check_Arg_Is_Local_Name (Arg1);
13651 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13653 ----------------------------------
13654 -- Suppress_Exception_Locations --
13655 ----------------------------------
13657 -- pragma Suppress_Exception_Locations;
13659 when Pragma_Suppress_Exception_Locations =>
13661 Check_Arg_Count (0);
13662 Check_Valid_Configuration_Pragma;
13663 Exception_Locations_Suppressed := True;
13665 -----------------------------
13666 -- Suppress_Initialization --
13667 -----------------------------
13669 -- pragma Suppress_Initialization ([Entity =>] type_Name);
13671 when Pragma_Suppress_Initialization => Suppress_Init : declare
13677 Check_Arg_Count (1);
13678 Check_Optional_Identifier (Arg1, Name_Entity);
13679 Check_Arg_Is_Local_Name (Arg1);
13681 E_Id := Get_Pragma_Arg (Arg1);
13683 if Etype (E_Id) = Any_Type then
13687 E := Entity (E_Id);
13689 if not Is_Type (E) then
13690 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13693 if Rep_Item_Too_Early (E, N)
13695 Rep_Item_Too_Late (E, N, FOnly => True)
13700 -- For incomplete/private type, set flag on full view
13702 if Is_Incomplete_Or_Private_Type (E) then
13703 if No (Full_View (Base_Type (E))) then
13705 ("argument of pragma% cannot be an incomplete type", Arg1);
13707 Set_Suppress_Initialization (Full_View (Base_Type (E)));
13710 -- For first subtype, set flag on base type
13712 elsif Is_First_Subtype (E) then
13713 Set_Suppress_Initialization (Base_Type (E));
13715 -- For other than first subtype, set flag on subtype itself
13718 Set_Suppress_Initialization (E);
13726 -- pragma System_Name (DIRECT_NAME);
13728 -- Syntax check: one argument, which must be the identifier GNAT or
13729 -- the identifier GCC, no other identifiers are acceptable.
13731 when Pragma_System_Name =>
13733 Check_No_Identifiers;
13734 Check_Arg_Count (1);
13735 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13737 -----------------------------
13738 -- Task_Dispatching_Policy --
13739 -----------------------------
13741 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13743 when Pragma_Task_Dispatching_Policy => declare
13747 Check_Ada_83_Warning;
13748 Check_Arg_Count (1);
13749 Check_No_Identifiers;
13750 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13751 Check_Valid_Configuration_Pragma;
13752 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13753 DP := Fold_Upper (Name_Buffer (1));
13755 if Task_Dispatching_Policy /= ' '
13756 and then Task_Dispatching_Policy /= DP
13758 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13760 ("task dispatching policy incompatible with policy#");
13762 -- Set new policy, but always preserve System_Location since we
13763 -- like the error message with the run time name.
13766 Task_Dispatching_Policy := DP;
13768 if Task_Dispatching_Policy_Sloc /= System_Location then
13769 Task_Dispatching_Policy_Sloc := Loc;
13778 -- pragma Task_Info (EXPRESSION);
13780 when Pragma_Task_Info => Task_Info : declare
13781 P : constant Node_Id := Parent (N);
13786 if Nkind (P) /= N_Task_Definition then
13787 Error_Pragma ("pragma% must appear in task definition");
13790 Check_No_Identifiers;
13791 Check_Arg_Count (1);
13793 Analyze_And_Resolve
13794 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13796 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13800 if Has_Task_Info_Pragma (P) then
13801 Error_Pragma ("duplicate pragma% not allowed");
13803 Set_Has_Task_Info_Pragma (P, True);
13811 -- pragma Task_Name (string_EXPRESSION);
13813 when Pragma_Task_Name => Task_Name : declare
13814 P : constant Node_Id := Parent (N);
13818 Check_No_Identifiers;
13819 Check_Arg_Count (1);
13821 Arg := Get_Pragma_Arg (Arg1);
13823 -- The expression is used in the call to Create_Task, and must be
13824 -- expanded there, not in the context of the current spec. It must
13825 -- however be analyzed to capture global references, in case it
13826 -- appears in a generic context.
13828 Preanalyze_And_Resolve (Arg, Standard_String);
13830 if Nkind (P) /= N_Task_Definition then
13834 if Has_Task_Name_Pragma (P) then
13835 Error_Pragma ("duplicate pragma% not allowed");
13837 Set_Has_Task_Name_Pragma (P, True);
13838 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13846 -- pragma Task_Storage (
13847 -- [Task_Type =>] LOCAL_NAME,
13848 -- [Top_Guard =>] static_integer_EXPRESSION);
13850 when Pragma_Task_Storage => Task_Storage : declare
13851 Args : Args_List (1 .. 2);
13852 Names : constant Name_List (1 .. 2) := (
13856 Task_Type : Node_Id renames Args (1);
13857 Top_Guard : Node_Id renames Args (2);
13863 Gather_Associations (Names, Args);
13865 if No (Task_Type) then
13867 ("missing task_type argument for pragma%");
13870 Check_Arg_Is_Local_Name (Task_Type);
13872 Ent := Entity (Task_Type);
13874 if not Is_Task_Type (Ent) then
13876 ("argument for pragma% must be task type", Task_Type);
13879 if No (Top_Guard) then
13881 ("pragma% takes two arguments", Task_Type);
13883 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13886 Check_First_Subtype (Task_Type);
13888 if Rep_Item_Too_Late (Ent, N) then
13897 -- pragma Test_Case ([Name =>] Static_String_EXPRESSION
13898 -- ,[Mode =>] MODE_TYPE
13899 -- [, Requires => Boolean_EXPRESSION]
13900 -- [, Ensures => Boolean_EXPRESSION]);
13902 -- MODE_TYPE ::= Nominal | Robustness
13904 when Pragma_Test_Case => Test_Case : declare
13907 Check_At_Least_N_Arguments (2);
13908 Check_At_Most_N_Arguments (4);
13910 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13912 Check_Optional_Identifier (Arg1, Name_Name);
13913 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13915 -- In ASIS mode, for a pragma generated from a source aspect, also
13916 -- analyze the original aspect expression.
13919 and then Present (Corresponding_Aspect (N))
13921 Check_Expr_Is_Static_Expression
13922 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
13925 Check_Optional_Identifier (Arg2, Name_Mode);
13926 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13928 if Arg_Count = 4 then
13929 Check_Identifier (Arg3, Name_Requires);
13930 Check_Identifier (Arg4, Name_Ensures);
13932 elsif Arg_Count = 3 then
13933 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13939 --------------------------
13940 -- Thread_Local_Storage --
13941 --------------------------
13943 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13945 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13951 Check_Arg_Count (1);
13952 Check_Optional_Identifier (Arg1, Name_Entity);
13953 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13955 Id := Get_Pragma_Arg (Arg1);
13958 if not Is_Entity_Name (Id)
13959 or else Ekind (Entity (Id)) /= E_Variable
13961 Error_Pragma_Arg ("local variable name required", Arg1);
13966 if Rep_Item_Too_Early (E, N)
13967 or else Rep_Item_Too_Late (E, N)
13972 Set_Has_Pragma_Thread_Local_Storage (E);
13973 Set_Has_Gigi_Rep_Item (E);
13974 end Thread_Local_Storage;
13980 -- pragma Time_Slice (static_duration_EXPRESSION);
13982 when Pragma_Time_Slice => Time_Slice : declare
13988 Check_Arg_Count (1);
13989 Check_No_Identifiers;
13990 Check_In_Main_Program;
13991 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13993 if not Error_Posted (Arg1) then
13995 while Present (Nod) loop
13996 if Nkind (Nod) = N_Pragma
13997 and then Pragma_Name (Nod) = Name_Time_Slice
13999 Error_Msg_Name_1 := Pname;
14000 Error_Msg_N ("duplicate pragma% not permitted", Nod);
14007 -- Process only if in main unit
14009 if Get_Source_Unit (Loc) = Main_Unit then
14010 Opt.Time_Slice_Set := True;
14011 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
14013 if Val <= Ureal_0 then
14014 Opt.Time_Slice_Value := 0;
14016 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
14017 Opt.Time_Slice_Value := 1_000_000_000;
14020 Opt.Time_Slice_Value :=
14021 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
14030 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
14032 -- TITLING_OPTION ::=
14033 -- [Title =>] STRING_LITERAL
14034 -- | [Subtitle =>] STRING_LITERAL
14036 when Pragma_Title => Title : declare
14037 Args : Args_List (1 .. 2);
14038 Names : constant Name_List (1 .. 2) := (
14044 Gather_Associations (Names, Args);
14047 for J in 1 .. 2 loop
14048 if Present (Args (J)) then
14049 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
14054 ---------------------
14055 -- Unchecked_Union --
14056 ---------------------
14058 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
14060 when Pragma_Unchecked_Union => Unchecked_Union : declare
14061 Assoc : constant Node_Id := Arg1;
14062 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
14073 Check_No_Identifiers;
14074 Check_Arg_Count (1);
14075 Check_Arg_Is_Local_Name (Arg1);
14077 Find_Type (Type_Id);
14078 Typ := Entity (Type_Id);
14081 or else Rep_Item_Too_Early (Typ, N)
14085 Typ := Underlying_Type (Typ);
14088 if Rep_Item_Too_Late (Typ, N) then
14092 Check_First_Subtype (Arg1);
14094 -- Note remaining cases are references to a type in the current
14095 -- declarative part. If we find an error, we post the error on
14096 -- the relevant type declaration at an appropriate point.
14098 if not Is_Record_Type (Typ) then
14099 Error_Msg_N ("Unchecked_Union must be record type", Typ);
14102 elsif Is_Tagged_Type (Typ) then
14103 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
14106 elsif not Has_Discriminants (Typ) then
14108 ("Unchecked_Union must have one discriminant", Typ);
14111 -- Note: in previous versions of GNAT we used to check for limited
14112 -- types and give an error, but in fact the standard does allow
14113 -- Unchecked_Union on limited types, so this check was removed.
14115 -- Proceed with basic error checks completed
14118 Discr := First_Discriminant (Typ);
14119 while Present (Discr) loop
14120 if No (Discriminant_Default_Value (Discr)) then
14122 ("Unchecked_Union discriminant must have default value",
14126 Next_Discriminant (Discr);
14129 Tdef := Type_Definition (Declaration_Node (Typ));
14130 Clist := Component_List (Tdef);
14132 Comp := First (Component_Items (Clist));
14133 while Present (Comp) loop
14134 Check_Component (Comp, Typ);
14138 if No (Clist) or else No (Variant_Part (Clist)) then
14140 ("Unchecked_Union must have variant part",
14145 Vpart := Variant_Part (Clist);
14147 Variant := First (Variants (Vpart));
14148 while Present (Variant) loop
14149 Check_Variant (Variant, Typ);
14154 Set_Is_Unchecked_Union (Typ);
14155 Set_Convention (Typ, Convention_C);
14156 Set_Has_Unchecked_Union (Base_Type (Typ));
14157 Set_Is_Unchecked_Union (Base_Type (Typ));
14158 end Unchecked_Union;
14160 ------------------------
14161 -- Unimplemented_Unit --
14162 ------------------------
14164 -- pragma Unimplemented_Unit;
14166 -- Note: this only gives an error if we are generating code, or if
14167 -- we are in a generic library unit (where the pragma appears in the
14168 -- body, not in the spec).
14170 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
14171 Cunitent : constant Entity_Id :=
14172 Cunit_Entity (Get_Source_Unit (Loc));
14173 Ent_Kind : constant Entity_Kind :=
14178 Check_Arg_Count (0);
14180 if Operating_Mode = Generate_Code
14181 or else Ent_Kind = E_Generic_Function
14182 or else Ent_Kind = E_Generic_Procedure
14183 or else Ent_Kind = E_Generic_Package
14185 Get_Name_String (Chars (Cunitent));
14186 Set_Casing (Mixed_Case);
14187 Write_Str (Name_Buffer (1 .. Name_Len));
14188 Write_Str (" is not supported in this configuration");
14190 raise Unrecoverable_Error;
14192 end Unimplemented_Unit;
14194 ------------------------
14195 -- Universal_Aliasing --
14196 ------------------------
14198 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
14200 when Pragma_Universal_Aliasing => Universal_Alias : declare
14205 Check_Arg_Count (1);
14206 Check_Optional_Identifier (Arg2, Name_Entity);
14207 Check_Arg_Is_Local_Name (Arg1);
14208 E_Id := Entity (Get_Pragma_Arg (Arg1));
14210 if E_Id = Any_Type then
14212 elsif No (E_Id) or else not Is_Type (E_Id) then
14213 Error_Pragma_Arg ("pragma% requires type", Arg1);
14216 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
14217 end Universal_Alias;
14219 --------------------
14220 -- Universal_Data --
14221 --------------------
14223 -- pragma Universal_Data [(library_unit_NAME)];
14225 when Pragma_Universal_Data =>
14228 -- If this is a configuration pragma, then set the universal
14229 -- addressing option, otherwise confirm that the pragma satisfies
14230 -- the requirements of library unit pragma placement and leave it
14231 -- to the GNAAMP back end to detect the pragma (avoids transitive
14232 -- setting of the option due to withed units).
14234 if Is_Configuration_Pragma then
14235 Universal_Addressing_On_AAMP := True;
14237 Check_Valid_Library_Unit_Pragma;
14240 if not AAMP_On_Target then
14241 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
14248 -- pragma Unmodified (local_Name {, local_Name});
14250 when Pragma_Unmodified => Unmodified : declare
14251 Arg_Node : Node_Id;
14252 Arg_Expr : Node_Id;
14253 Arg_Ent : Entity_Id;
14257 Check_At_Least_N_Arguments (1);
14259 -- Loop through arguments
14262 while Present (Arg_Node) loop
14263 Check_No_Identifier (Arg_Node);
14265 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
14266 -- in fact generate reference, so that the entity will have a
14267 -- reference, which will inhibit any warnings about it not
14268 -- being referenced, and also properly show up in the ali file
14269 -- as a reference. But this reference is recorded before the
14270 -- Has_Pragma_Unreferenced flag is set, so that no warning is
14271 -- generated for this reference.
14273 Check_Arg_Is_Local_Name (Arg_Node);
14274 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14276 if Is_Entity_Name (Arg_Expr) then
14277 Arg_Ent := Entity (Arg_Expr);
14279 if not Is_Assignable (Arg_Ent) then
14281 ("pragma% can only be applied to a variable",
14284 Set_Has_Pragma_Unmodified (Arg_Ent);
14296 -- pragma Unreferenced (local_Name {, local_Name});
14298 -- or when used in a context clause:
14300 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
14302 when Pragma_Unreferenced => Unreferenced : declare
14303 Arg_Node : Node_Id;
14304 Arg_Expr : Node_Id;
14305 Arg_Ent : Entity_Id;
14310 Check_At_Least_N_Arguments (1);
14312 -- Check case of appearing within context clause
14314 if Is_In_Context_Clause then
14316 -- The arguments must all be units mentioned in a with clause
14317 -- in the same context clause. Note we already checked (in
14318 -- Par.Prag) that the arguments are either identifiers or
14319 -- selected components.
14322 while Present (Arg_Node) loop
14323 Citem := First (List_Containing (N));
14324 while Citem /= N loop
14325 if Nkind (Citem) = N_With_Clause
14327 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
14329 Set_Has_Pragma_Unreferenced
14332 (Library_Unit (Citem))));
14334 (Get_Pragma_Arg (Arg_Node), Name (Citem));
14343 ("argument of pragma% is not withed unit", Arg_Node);
14349 -- Case of not in list of context items
14353 while Present (Arg_Node) loop
14354 Check_No_Identifier (Arg_Node);
14356 -- Note: the analyze call done by Check_Arg_Is_Local_Name
14357 -- will in fact generate reference, so that the entity will
14358 -- have a reference, which will inhibit any warnings about
14359 -- it not being referenced, and also properly show up in the
14360 -- ali file as a reference. But this reference is recorded
14361 -- before the Has_Pragma_Unreferenced flag is set, so that
14362 -- no warning is generated for this reference.
14364 Check_Arg_Is_Local_Name (Arg_Node);
14365 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14367 if Is_Entity_Name (Arg_Expr) then
14368 Arg_Ent := Entity (Arg_Expr);
14370 -- If the entity is overloaded, the pragma applies to the
14371 -- most recent overloading, as documented. In this case,
14372 -- name resolution does not generate a reference, so it
14373 -- must be done here explicitly.
14375 if Is_Overloaded (Arg_Expr) then
14376 Generate_Reference (Arg_Ent, N);
14379 Set_Has_Pragma_Unreferenced (Arg_Ent);
14387 --------------------------
14388 -- Unreferenced_Objects --
14389 --------------------------
14391 -- pragma Unreferenced_Objects (local_Name {, local_Name});
14393 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
14394 Arg_Node : Node_Id;
14395 Arg_Expr : Node_Id;
14399 Check_At_Least_N_Arguments (1);
14402 while Present (Arg_Node) loop
14403 Check_No_Identifier (Arg_Node);
14404 Check_Arg_Is_Local_Name (Arg_Node);
14405 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14407 if not Is_Entity_Name (Arg_Expr)
14408 or else not Is_Type (Entity (Arg_Expr))
14411 ("argument for pragma% must be type or subtype", Arg_Node);
14414 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
14417 end Unreferenced_Objects;
14419 ------------------------------
14420 -- Unreserve_All_Interrupts --
14421 ------------------------------
14423 -- pragma Unreserve_All_Interrupts;
14425 when Pragma_Unreserve_All_Interrupts =>
14427 Check_Arg_Count (0);
14429 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
14430 Unreserve_All_Interrupts := True;
14437 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
14439 when Pragma_Unsuppress =>
14441 Process_Suppress_Unsuppress (False);
14443 -------------------
14444 -- Use_VADS_Size --
14445 -------------------
14447 -- pragma Use_VADS_Size;
14449 when Pragma_Use_VADS_Size =>
14451 Check_Arg_Count (0);
14452 Check_Valid_Configuration_Pragma;
14453 Use_VADS_Size := True;
14455 ---------------------
14456 -- Validity_Checks --
14457 ---------------------
14459 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14461 when Pragma_Validity_Checks => Validity_Checks : declare
14462 A : constant Node_Id := Get_Pragma_Arg (Arg1);
14468 Check_Arg_Count (1);
14469 Check_No_Identifiers;
14471 if Nkind (A) = N_String_Literal then
14475 Slen : constant Natural := Natural (String_Length (S));
14476 Options : String (1 .. Slen);
14482 C := Get_String_Char (S, Int (J));
14483 exit when not In_Character_Range (C);
14484 Options (J) := Get_Character (C);
14487 Set_Validity_Check_Options (Options);
14495 elsif Nkind (A) = N_Identifier then
14496 if Chars (A) = Name_All_Checks then
14497 Set_Validity_Check_Options ("a");
14498 elsif Chars (A) = Name_On then
14499 Validity_Checks_On := True;
14500 elsif Chars (A) = Name_Off then
14501 Validity_Checks_On := False;
14504 end Validity_Checks;
14510 -- pragma Volatile (LOCAL_NAME);
14512 when Pragma_Volatile =>
14513 Process_Atomic_Shared_Volatile;
14515 -------------------------
14516 -- Volatile_Components --
14517 -------------------------
14519 -- pragma Volatile_Components (array_LOCAL_NAME);
14521 -- Volatile is handled by the same circuit as Atomic_Components
14527 -- pragma Warnings (On | Off);
14528 -- pragma Warnings (On | Off, LOCAL_NAME);
14529 -- pragma Warnings (static_string_EXPRESSION);
14530 -- pragma Warnings (On | Off, STRING_LITERAL);
14532 when Pragma_Warnings => Warnings : begin
14534 Check_At_Least_N_Arguments (1);
14535 Check_No_Identifiers;
14537 -- If debug flag -gnatd.i is set, pragma is ignored
14539 if Debug_Flag_Dot_I then
14543 -- Process various forms of the pragma
14546 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14549 -- One argument case
14551 if Arg_Count = 1 then
14553 -- On/Off one argument case was processed by parser
14555 if Nkind (Argx) = N_Identifier
14557 (Chars (Argx) = Name_On
14559 Chars (Argx) = Name_Off)
14563 -- One argument case must be ON/OFF or static string expr
14565 elsif not Is_Static_String_Expression (Arg1) then
14567 ("argument of pragma% must be On/Off or " &
14568 "static string expression", Arg1);
14570 -- One argument string expression case
14574 Lit : constant Node_Id := Expr_Value_S (Argx);
14575 Str : constant String_Id := Strval (Lit);
14576 Len : constant Nat := String_Length (Str);
14584 while J <= Len loop
14585 C := Get_String_Char (Str, J);
14586 OK := In_Character_Range (C);
14589 Chr := Get_Character (C);
14593 if J < Len and then Chr = '.' then
14595 C := Get_String_Char (Str, J);
14596 Chr := Get_Character (C);
14598 if not Set_Dot_Warning_Switch (Chr) then
14600 ("invalid warning switch character " &
14607 OK := Set_Warning_Switch (Chr);
14613 ("invalid warning switch character " & Chr,
14622 -- Two or more arguments (must be two)
14625 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14626 Check_At_Most_N_Arguments (2);
14634 E_Id := Get_Pragma_Arg (Arg2);
14637 -- In the expansion of an inlined body, a reference to
14638 -- the formal may be wrapped in a conversion if the
14639 -- actual is a conversion. Retrieve the real entity name.
14641 if (In_Instance_Body or In_Inlined_Body)
14642 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14644 E_Id := Expression (E_Id);
14647 -- Entity name case
14649 if Is_Entity_Name (E_Id) then
14650 E := Entity (E_Id);
14657 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14660 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14661 and then Warn_On_Warnings_Off
14663 Warnings_Off_Pragmas.Append ((N, E));
14666 if Is_Enumeration_Type (E) then
14670 Lit := First_Literal (E);
14671 while Present (Lit) loop
14672 Set_Warnings_Off (Lit);
14673 Next_Literal (Lit);
14678 exit when No (Homonym (E));
14683 -- Error if not entity or static string literal case
14685 elsif not Is_Static_String_Expression (Arg2) then
14687 ("second argument of pragma% must be entity " &
14688 "name or static string expression", Arg2);
14690 -- String literal case
14693 String_To_Name_Buffer
14694 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14696 -- Note on configuration pragma case: If this is a
14697 -- configuration pragma, then for an OFF pragma, we
14698 -- just set Config True in the call, which is all
14699 -- that needs to be done. For the case of ON, this
14700 -- is normally an error, unless it is canceling the
14701 -- effect of a previous OFF pragma in the same file.
14702 -- In any other case, an error will be signalled (ON
14703 -- with no matching OFF).
14705 -- Note: We set Used if we are inside a generic to
14706 -- disable the test that the non-config case actually
14707 -- cancels a warning. That's because we can't be sure
14708 -- there isn't an instantiation in some other unit
14709 -- where a warning is suppressed.
14711 -- We could do a little better here by checking if the
14712 -- generic unit we are inside is public, but for now
14713 -- we don't bother with that refinement.
14715 if Chars (Argx) = Name_Off then
14716 Set_Specific_Warning_Off
14717 (Loc, Name_Buffer (1 .. Name_Len),
14718 Config => Is_Configuration_Pragma,
14719 Used => Inside_A_Generic or else In_Instance);
14721 elsif Chars (Argx) = Name_On then
14722 Set_Specific_Warning_On
14723 (Loc, Name_Buffer (1 .. Name_Len), Err);
14727 ("?pragma Warnings On with no " &
14728 "matching Warnings Off",
14738 -------------------
14739 -- Weak_External --
14740 -------------------
14742 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
14744 when Pragma_Weak_External => Weak_External : declare
14749 Check_Arg_Count (1);
14750 Check_Optional_Identifier (Arg1, Name_Entity);
14751 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14752 Ent := Entity (Get_Pragma_Arg (Arg1));
14754 if Rep_Item_Too_Early (Ent, N) then
14757 Ent := Underlying_Type (Ent);
14760 -- The only processing required is to link this item on to the
14761 -- list of rep items for the given entity. This is accomplished
14762 -- by the call to Rep_Item_Too_Late (when no error is detected
14763 -- and False is returned).
14765 if Rep_Item_Too_Late (Ent, N) then
14768 Set_Has_Gigi_Rep_Item (Ent);
14772 -----------------------------
14773 -- Wide_Character_Encoding --
14774 -----------------------------
14776 -- pragma Wide_Character_Encoding (IDENTIFIER);
14778 when Pragma_Wide_Character_Encoding =>
14781 -- Nothing to do, handled in parser. Note that we do not enforce
14782 -- configuration pragma placement, this pragma can appear at any
14783 -- place in the source, allowing mixed encodings within a single
14788 --------------------
14789 -- Unknown_Pragma --
14790 --------------------
14792 -- Should be impossible, since the case of an unknown pragma is
14793 -- separately processed before the case statement is entered.
14795 when Unknown_Pragma =>
14796 raise Program_Error;
14799 -- AI05-0144: detect dangerous order dependence. Disabled for now,
14800 -- until AI is formally approved.
14802 -- Check_Order_Dependence;
14805 when Pragma_Exit => null;
14806 end Analyze_Pragma;
14808 -----------------------------
14809 -- Analyze_TC_In_Decl_Part --
14810 -----------------------------
14812 procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14814 -- Install formals and push subprogram spec onto scope stack so that we
14815 -- can see the formals from the pragma.
14817 Install_Formals (S);
14820 -- Preanalyze the boolean expressions, we treat these as spec
14821 -- expressions (i.e. similar to a default expression).
14823 Preanalyze_TC_Args (N,
14824 Get_Requires_From_Test_Case_Pragma (N),
14825 Get_Ensures_From_Test_Case_Pragma (N));
14827 -- Remove the subprogram from the scope stack now that the pre-analysis
14828 -- of the expressions in the test-case is done.
14831 end Analyze_TC_In_Decl_Part;
14833 --------------------
14834 -- Check_Disabled --
14835 --------------------
14837 function Check_Disabled (Nam : Name_Id) return Boolean is
14841 -- Loop through entries in check policy list
14843 PP := Opt.Check_Policy_List;
14845 -- If there are no specific entries that matched, then nothing is
14846 -- disabled, so return False.
14851 -- Here we have an entry see if it matches
14855 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14857 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14858 return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14860 PP := Next_Pragma (PP);
14865 end Check_Disabled;
14867 -------------------
14868 -- Check_Enabled --
14869 -------------------
14871 function Check_Enabled (Nam : Name_Id) return Boolean is
14875 -- Loop through entries in check policy list
14877 PP := Opt.Check_Policy_List;
14879 -- If there are no specific entries that matched, then we let the
14880 -- setting of assertions govern. Note that this provides the needed
14881 -- compatibility with the RM for the cases of assertion, invariant,
14882 -- precondition, predicate, and postcondition.
14885 return Assertions_Enabled;
14887 -- Here we have an entry see if it matches
14891 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14894 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14895 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14896 when Name_On | Name_Check =>
14898 when Name_Off | Name_Ignore =>
14901 raise Program_Error;
14905 PP := Next_Pragma (PP);
14912 ---------------------------------
14913 -- Delay_Config_Pragma_Analyze --
14914 ---------------------------------
14916 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14918 return Pragma_Name (N) = Name_Interrupt_State
14920 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14921 end Delay_Config_Pragma_Analyze;
14923 -------------------------
14924 -- Get_Base_Subprogram --
14925 -------------------------
14927 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14928 Result : Entity_Id;
14931 -- Follow subprogram renaming chain
14934 while Is_Subprogram (Result)
14936 Nkind (Parent (Declaration_Node (Result))) =
14937 N_Subprogram_Renaming_Declaration
14938 and then Present (Alias (Result))
14940 Result := Alias (Result);
14944 end Get_Base_Subprogram;
14950 procedure Initialize is
14955 -----------------------------
14956 -- Is_Config_Static_String --
14957 -----------------------------
14959 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14961 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14962 -- This is an internal recursive function that is just like the outer
14963 -- function except that it adds the string to the name buffer rather
14964 -- than placing the string in the name buffer.
14966 ------------------------------
14967 -- Add_Config_Static_String --
14968 ------------------------------
14970 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14977 if Nkind (N) = N_Op_Concat then
14978 if Add_Config_Static_String (Left_Opnd (N)) then
14979 N := Right_Opnd (N);
14985 if Nkind (N) /= N_String_Literal then
14986 Error_Msg_N ("string literal expected for pragma argument", N);
14990 for J in 1 .. String_Length (Strval (N)) loop
14991 C := Get_String_Char (Strval (N), J);
14993 if not In_Character_Range (C) then
14995 ("string literal contains invalid wide character",
14996 Sloc (N) + 1 + Source_Ptr (J));
15000 Add_Char_To_Name_Buffer (Get_Character (C));
15005 end Add_Config_Static_String;
15007 -- Start of processing for Is_Config_Static_String
15012 return Add_Config_Static_String (Arg);
15013 end Is_Config_Static_String;
15015 -----------------------------------------
15016 -- Is_Non_Significant_Pragma_Reference --
15017 -----------------------------------------
15019 -- This function makes use of the following static table which indicates
15020 -- whether appearance of some name in a given pragma is to be considered
15021 -- as a reference for the purposes of warnings about unreferenced objects.
15023 -- -1 indicates that references in any argument position are significant
15024 -- 0 indicates that appearance in any argument is not significant
15025 -- +n indicates that appearance as argument n is significant, but all
15026 -- other arguments are not significant
15027 -- 99 special processing required (e.g. for pragma Check)
15029 Sig_Flags : constant array (Pragma_Id) of Int :=
15030 (Pragma_AST_Entry => -1,
15031 Pragma_Abort_Defer => -1,
15032 Pragma_Ada_83 => -1,
15033 Pragma_Ada_95 => -1,
15034 Pragma_Ada_05 => -1,
15035 Pragma_Ada_2005 => -1,
15036 Pragma_Ada_12 => -1,
15037 Pragma_Ada_2012 => -1,
15038 Pragma_All_Calls_Remote => -1,
15039 Pragma_Annotate => -1,
15040 Pragma_Assert => -1,
15041 Pragma_Assertion_Policy => 0,
15042 Pragma_Assume_No_Invalid_Values => 0,
15043 Pragma_Asynchronous => -1,
15044 Pragma_Atomic => 0,
15045 Pragma_Atomic_Components => 0,
15046 Pragma_Attach_Handler => -1,
15047 Pragma_Check => 99,
15048 Pragma_Check_Name => 0,
15049 Pragma_Check_Policy => 0,
15050 Pragma_CIL_Constructor => -1,
15051 Pragma_CPP_Class => 0,
15052 Pragma_CPP_Constructor => 0,
15053 Pragma_CPP_Virtual => 0,
15054 Pragma_CPP_Vtable => 0,
15056 Pragma_C_Pass_By_Copy => 0,
15057 Pragma_Comment => 0,
15058 Pragma_Common_Object => -1,
15059 Pragma_Compile_Time_Error => -1,
15060 Pragma_Compile_Time_Warning => -1,
15061 Pragma_Compiler_Unit => 0,
15062 Pragma_Complete_Representation => 0,
15063 Pragma_Complex_Representation => 0,
15064 Pragma_Component_Alignment => -1,
15065 Pragma_Controlled => 0,
15066 Pragma_Convention => 0,
15067 Pragma_Convention_Identifier => 0,
15068 Pragma_Debug => -1,
15069 Pragma_Debug_Policy => 0,
15070 Pragma_Detect_Blocking => -1,
15071 Pragma_Default_Storage_Pool => -1,
15072 Pragma_Disable_Atomic_Synchronization => -1,
15073 Pragma_Discard_Names => 0,
15074 Pragma_Dispatching_Domain => -1,
15075 Pragma_Elaborate => -1,
15076 Pragma_Elaborate_All => -1,
15077 Pragma_Elaborate_Body => -1,
15078 Pragma_Elaboration_Checks => -1,
15079 Pragma_Eliminate => -1,
15080 Pragma_Enable_Atomic_Synchronization => -1,
15081 Pragma_Export => -1,
15082 Pragma_Export_Exception => -1,
15083 Pragma_Export_Function => -1,
15084 Pragma_Export_Object => -1,
15085 Pragma_Export_Procedure => -1,
15086 Pragma_Export_Value => -1,
15087 Pragma_Export_Valued_Procedure => -1,
15088 Pragma_Extend_System => -1,
15089 Pragma_Extensions_Allowed => -1,
15090 Pragma_External => -1,
15091 Pragma_Favor_Top_Level => -1,
15092 Pragma_External_Name_Casing => -1,
15093 Pragma_Fast_Math => -1,
15094 Pragma_Finalize_Storage_Only => 0,
15095 Pragma_Float_Representation => 0,
15096 Pragma_Ident => -1,
15097 Pragma_Implementation_Defined => -1,
15098 Pragma_Implemented => -1,
15099 Pragma_Implicit_Packing => 0,
15100 Pragma_Import => +2,
15101 Pragma_Import_Exception => 0,
15102 Pragma_Import_Function => 0,
15103 Pragma_Import_Object => 0,
15104 Pragma_Import_Procedure => 0,
15105 Pragma_Import_Valued_Procedure => 0,
15106 Pragma_Independent => 0,
15107 Pragma_Independent_Components => 0,
15108 Pragma_Initialize_Scalars => -1,
15109 Pragma_Inline => 0,
15110 Pragma_Inline_Always => 0,
15111 Pragma_Inline_Generic => 0,
15112 Pragma_Inspection_Point => -1,
15113 Pragma_Interface => +2,
15114 Pragma_Interface_Name => +2,
15115 Pragma_Interrupt_Handler => -1,
15116 Pragma_Interrupt_Priority => -1,
15117 Pragma_Interrupt_State => -1,
15118 Pragma_Invariant => -1,
15119 Pragma_Java_Constructor => -1,
15120 Pragma_Java_Interface => -1,
15121 Pragma_Keep_Names => 0,
15122 Pragma_License => -1,
15123 Pragma_Link_With => -1,
15124 Pragma_Linker_Alias => -1,
15125 Pragma_Linker_Constructor => -1,
15126 Pragma_Linker_Destructor => -1,
15127 Pragma_Linker_Options => -1,
15128 Pragma_Linker_Section => -1,
15130 Pragma_Locking_Policy => -1,
15131 Pragma_Long_Float => -1,
15132 Pragma_Machine_Attribute => -1,
15134 Pragma_Main_Storage => -1,
15135 Pragma_Memory_Size => -1,
15136 Pragma_No_Return => 0,
15137 Pragma_No_Body => 0,
15138 Pragma_No_Run_Time => -1,
15139 Pragma_No_Strict_Aliasing => -1,
15140 Pragma_Normalize_Scalars => -1,
15141 Pragma_Obsolescent => 0,
15142 Pragma_Optimize => -1,
15143 Pragma_Optimize_Alignment => -1,
15144 Pragma_Ordered => 0,
15147 Pragma_Passive => -1,
15148 Pragma_Preelaborable_Initialization => -1,
15149 Pragma_Polling => -1,
15150 Pragma_Persistent_BSS => 0,
15151 Pragma_Postcondition => -1,
15152 Pragma_Precondition => -1,
15153 Pragma_Predicate => -1,
15154 Pragma_Preelaborate => -1,
15155 Pragma_Preelaborate_05 => -1,
15156 Pragma_Priority => -1,
15157 Pragma_Priority_Specific_Dispatching => -1,
15158 Pragma_Profile => 0,
15159 Pragma_Profile_Warnings => 0,
15160 Pragma_Propagate_Exceptions => -1,
15161 Pragma_Psect_Object => -1,
15163 Pragma_Pure_05 => -1,
15164 Pragma_Pure_12 => -1,
15165 Pragma_Pure_Function => -1,
15166 Pragma_Queuing_Policy => -1,
15167 Pragma_Ravenscar => -1,
15168 Pragma_Relative_Deadline => -1,
15169 Pragma_Remote_Access_Type => -1,
15170 Pragma_Remote_Call_Interface => -1,
15171 Pragma_Remote_Types => -1,
15172 Pragma_Restricted_Run_Time => -1,
15173 Pragma_Restriction_Warnings => -1,
15174 Pragma_Restrictions => -1,
15175 Pragma_Reviewable => -1,
15176 Pragma_Short_Circuit_And_Or => -1,
15177 Pragma_Share_Generic => -1,
15178 Pragma_Shared => -1,
15179 Pragma_Shared_Passive => -1,
15180 Pragma_Short_Descriptors => 0,
15181 Pragma_Simple_Storage_Pool_Type => 0,
15182 Pragma_Source_File_Name => -1,
15183 Pragma_Source_File_Name_Project => -1,
15184 Pragma_Source_Reference => -1,
15185 Pragma_Storage_Size => -1,
15186 Pragma_Storage_Unit => -1,
15187 Pragma_Static_Elaboration_Desired => -1,
15188 Pragma_Stream_Convert => -1,
15189 Pragma_Style_Checks => -1,
15190 Pragma_Subtitle => -1,
15191 Pragma_Suppress => 0,
15192 Pragma_Suppress_Exception_Locations => 0,
15193 Pragma_Suppress_All => -1,
15194 Pragma_Suppress_Debug_Info => 0,
15195 Pragma_Suppress_Initialization => 0,
15196 Pragma_System_Name => -1,
15197 Pragma_Task_Dispatching_Policy => -1,
15198 Pragma_Task_Info => -1,
15199 Pragma_Task_Name => -1,
15200 Pragma_Task_Storage => 0,
15201 Pragma_Test_Case => -1,
15202 Pragma_Thread_Local_Storage => 0,
15203 Pragma_Time_Slice => -1,
15204 Pragma_Title => -1,
15205 Pragma_Unchecked_Union => 0,
15206 Pragma_Unimplemented_Unit => -1,
15207 Pragma_Universal_Aliasing => -1,
15208 Pragma_Universal_Data => -1,
15209 Pragma_Unmodified => -1,
15210 Pragma_Unreferenced => -1,
15211 Pragma_Unreferenced_Objects => -1,
15212 Pragma_Unreserve_All_Interrupts => -1,
15213 Pragma_Unsuppress => 0,
15214 Pragma_Use_VADS_Size => -1,
15215 Pragma_Validity_Checks => -1,
15216 Pragma_Volatile => 0,
15217 Pragma_Volatile_Components => 0,
15218 Pragma_Warnings => -1,
15219 Pragma_Weak_External => -1,
15220 Pragma_Wide_Character_Encoding => 0,
15221 Unknown_Pragma => 0);
15223 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
15232 if Nkind (P) /= N_Pragma_Argument_Association then
15236 Id := Get_Pragma_Id (Parent (P));
15237 C := Sig_Flags (Id);
15249 -- For pragma Check, the first argument is not significant,
15250 -- the second and the third (if present) arguments are
15253 when Pragma_Check =>
15255 P = First (Pragma_Argument_Associations (Parent (P)));
15258 raise Program_Error;
15262 A := First (Pragma_Argument_Associations (Parent (P)));
15263 for J in 1 .. C - 1 loop
15271 return A = P; -- is this wrong way round ???
15274 end Is_Non_Significant_Pragma_Reference;
15276 ------------------------------
15277 -- Is_Pragma_String_Literal --
15278 ------------------------------
15280 -- This function returns true if the corresponding pragma argument is a
15281 -- static string expression. These are the only cases in which string
15282 -- literals can appear as pragma arguments. We also allow a string literal
15283 -- as the first argument to pragma Assert (although it will of course
15284 -- always generate a type error).
15286 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
15287 Pragn : constant Node_Id := Parent (Par);
15288 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
15289 Pname : constant Name_Id := Pragma_Name (Pragn);
15295 N := First (Assoc);
15302 if Pname = Name_Assert then
15305 elsif Pname = Name_Export then
15308 elsif Pname = Name_Ident then
15311 elsif Pname = Name_Import then
15314 elsif Pname = Name_Interface_Name then
15317 elsif Pname = Name_Linker_Alias then
15320 elsif Pname = Name_Linker_Section then
15323 elsif Pname = Name_Machine_Attribute then
15326 elsif Pname = Name_Source_File_Name then
15329 elsif Pname = Name_Source_Reference then
15332 elsif Pname = Name_Title then
15335 elsif Pname = Name_Subtitle then
15341 end Is_Pragma_String_Literal;
15343 -----------------------------------------
15344 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
15345 -----------------------------------------
15347 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
15348 Aspects : constant List_Id := New_List;
15349 Loc : constant Source_Ptr := Sloc (Decl);
15350 Or_Decl : constant Node_Id := Original_Node (Decl);
15352 Original_Aspects : List_Id;
15353 -- To capture global references, a copy of the created aspects must be
15354 -- inserted in the original tree.
15357 Prag_Arg_Ass : Node_Id;
15358 Prag_Id : Pragma_Id;
15361 -- Check for any PPC pragmas that appear within Decl
15363 Prag := Next (Decl);
15364 while Nkind (Prag) = N_Pragma loop
15365 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
15368 when Pragma_Postcondition | Pragma_Precondition =>
15369 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
15371 -- Make an aspect from any PPC pragma
15373 Append_To (Aspects,
15374 Make_Aspect_Specification (Loc,
15376 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
15378 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
15380 -- Generate the analysis information in the pragma expression
15381 -- and then set the pragma node analyzed to avoid any further
15384 Analyze (Expression (Prag_Arg_Ass));
15385 Set_Analyzed (Prag, True);
15387 when others => null;
15393 -- Set all new aspects into the generic declaration node
15395 if Is_Non_Empty_List (Aspects) then
15397 -- Create the list of aspects to be inserted in the original tree
15399 Original_Aspects := Copy_Separate_List (Aspects);
15401 -- Check if Decl already has aspects
15403 -- Attach the new lists of aspects to both the generic copy and the
15406 if Has_Aspects (Decl) then
15407 Append_List (Aspects, Aspect_Specifications (Decl));
15408 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
15411 Set_Parent (Aspects, Decl);
15412 Set_Aspect_Specifications (Decl, Aspects);
15413 Set_Parent (Original_Aspects, Or_Decl);
15414 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
15417 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
15419 ------------------------
15420 -- Preanalyze_TC_Args --
15421 ------------------------
15423 procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
15425 -- Preanalyze the boolean expressions, we treat these as spec
15426 -- expressions (i.e. similar to a default expression).
15428 if Present (Arg_Req) then
15429 Preanalyze_Spec_Expression
15430 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
15432 -- In ASIS mode, for a pragma generated from a source aspect, also
15433 -- analyze the original aspect expression.
15435 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
15436 Preanalyze_Spec_Expression
15437 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
15441 if Present (Arg_Ens) then
15442 Preanalyze_Spec_Expression
15443 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
15445 -- In ASIS mode, for a pragma generated from a source aspect, also
15446 -- analyze the original aspect expression.
15448 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
15449 Preanalyze_Spec_Expression
15450 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
15453 end Preanalyze_TC_Args;
15455 --------------------------------------
15456 -- Process_Compilation_Unit_Pragmas --
15457 --------------------------------------
15459 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
15461 -- A special check for pragma Suppress_All, a very strange DEC pragma,
15462 -- strange because it comes at the end of the unit. Rational has the
15463 -- same name for a pragma, but treats it as a program unit pragma, In
15464 -- GNAT we just decide to allow it anywhere at all. If it appeared then
15465 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
15466 -- node, and we insert a pragma Suppress (All_Checks) at the start of
15467 -- the context clause to ensure the correct processing.
15469 if Has_Pragma_Suppress_All (N) then
15470 Prepend_To (Context_Items (N),
15471 Make_Pragma (Sloc (N),
15472 Chars => Name_Suppress,
15473 Pragma_Argument_Associations => New_List (
15474 Make_Pragma_Argument_Association (Sloc (N),
15475 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
15478 -- Nothing else to do at the current time!
15480 end Process_Compilation_Unit_Pragmas;
15491 --------------------------------
15492 -- Set_Encoded_Interface_Name --
15493 --------------------------------
15495 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
15496 Str : constant String_Id := Strval (S);
15497 Len : constant Int := String_Length (Str);
15502 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
15505 -- Stores encoded value of character code CC. The encoding we use an
15506 -- underscore followed by four lower case hex digits.
15512 procedure Encode is
15514 Store_String_Char (Get_Char_Code ('_'));
15516 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
15518 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
15520 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
15522 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
15525 -- Start of processing for Set_Encoded_Interface_Name
15528 -- If first character is asterisk, this is a link name, and we leave it
15529 -- completely unmodified. We also ignore null strings (the latter case
15530 -- happens only in error cases) and no encoding should occur for Java or
15531 -- AAMP interface names.
15534 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
15535 or else VM_Target /= No_VM
15536 or else AAMP_On_Target
15538 Set_Interface_Name (E, S);
15543 CC := Get_String_Char (Str, J);
15545 exit when not In_Character_Range (CC);
15547 C := Get_Character (CC);
15549 exit when C /= '_' and then C /= '$'
15550 and then C not in '0' .. '9'
15551 and then C not in 'a' .. 'z'
15552 and then C not in 'A' .. 'Z';
15555 Set_Interface_Name (E, S);
15563 -- Here we need to encode. The encoding we use as follows:
15564 -- three underscores + four hex digits (lower case)
15568 for J in 1 .. String_Length (Str) loop
15569 CC := Get_String_Char (Str, J);
15571 if not In_Character_Range (CC) then
15574 C := Get_Character (CC);
15576 if C = '_' or else C = '$'
15577 or else C in '0' .. '9'
15578 or else C in 'a' .. 'z'
15579 or else C in 'A' .. 'Z'
15581 Store_String_Char (CC);
15588 Set_Interface_Name (E,
15589 Make_String_Literal (Sloc (S),
15590 Strval => End_String));
15592 end Set_Encoded_Interface_Name;
15594 -------------------
15595 -- Set_Unit_Name --
15596 -------------------
15598 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15603 if Nkind (N) = N_Identifier
15604 and then Nkind (With_Item) = N_Identifier
15606 Set_Entity (N, Entity (With_Item));
15608 elsif Nkind (N) = N_Selected_Component then
15609 Change_Selected_Component_To_Expanded_Name (N);
15610 Set_Entity (N, Entity (With_Item));
15611 Set_Entity (Selector_Name (N), Entity (N));
15613 Pref := Prefix (N);
15614 Scop := Scope (Entity (N));
15615 while Nkind (Pref) = N_Selected_Component loop
15616 Change_Selected_Component_To_Expanded_Name (Pref);
15617 Set_Entity (Selector_Name (Pref), Scop);
15618 Set_Entity (Pref, Scop);
15619 Pref := Prefix (Pref);
15620 Scop := Scope (Scop);
15623 Set_Entity (Pref, Scop);