1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Atree; use Atree;
33 with Casing; use Casing;
34 with Checks; use Checks;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Elists; use Elists;
39 with Errout; use Errout;
40 with Exp_Dist; use Exp_Dist;
41 with Exp_Util; use Exp_Util;
42 with Freeze; use Freeze;
44 with Lib.Writ; use Lib.Writ;
45 with Lib.Xref; use Lib.Xref;
46 with Namet.Sp; use Namet.Sp;
47 with Nlists; use Nlists;
48 with Nmake; use Nmake;
50 with Output; use Output;
51 with Par_SCO; use Par_SCO;
52 with Restrict; use Restrict;
53 with Rident; use Rident;
54 with Rtsfind; use Rtsfind;
56 with Sem_Aux; use Sem_Aux;
57 with Sem_Ch3; use Sem_Ch3;
58 with Sem_Ch6; use Sem_Ch6;
59 with Sem_Ch8; use Sem_Ch8;
60 with Sem_Ch12; use Sem_Ch12;
61 with Sem_Ch13; use Sem_Ch13;
62 with Sem_Disp; use Sem_Disp;
63 with Sem_Dist; use Sem_Dist;
64 with Sem_Elim; use Sem_Elim;
65 with Sem_Eval; use Sem_Eval;
66 with Sem_Intr; use Sem_Intr;
67 with Sem_Mech; use Sem_Mech;
68 with Sem_Res; use Sem_Res;
69 with Sem_Type; use Sem_Type;
70 with Sem_Util; use Sem_Util;
71 with Sem_VFpt; use Sem_VFpt;
72 with Sem_Warn; use Sem_Warn;
73 with Stand; use Stand;
74 with Sinfo; use Sinfo;
75 with Sinfo.CN; use Sinfo.CN;
76 with Sinput; use Sinput;
77 with Snames; use Snames;
78 with Stringt; use Stringt;
79 with Stylesw; use Stylesw;
81 with Targparm; use Targparm;
82 with Tbuild; use Tbuild;
84 with Uintp; use Uintp;
85 with Uname; use Uname;
86 with Urealp; use Urealp;
87 with Validsw; use Validsw;
88 with Warnsw; use Warnsw;
90 package body Sem_Prag is
92 ----------------------------------------------
93 -- Common Handling of Import-Export Pragmas --
94 ----------------------------------------------
96 -- In the following section, a number of Import_xxx and Export_xxx pragmas
97 -- are defined by GNAT. These are compatible with the DEC pragmas of the
98 -- same name, and all have the following common form and processing:
101 -- [Internal =>] LOCAL_NAME
102 -- [, [External =>] EXTERNAL_SYMBOL]
103 -- [, other optional parameters ]);
106 -- [Internal =>] LOCAL_NAME
107 -- [, [External =>] EXTERNAL_SYMBOL]
108 -- [, other optional parameters ]);
110 -- EXTERNAL_SYMBOL ::=
112 -- | static_string_EXPRESSION
114 -- The internal LOCAL_NAME designates the entity that is imported or
115 -- exported, and must refer to an entity in the current declarative
116 -- part (as required by the rules for LOCAL_NAME).
118 -- The external linker name is designated by the External parameter if
119 -- given, or the Internal parameter if not (if there is no External
120 -- parameter, the External parameter is a copy of the Internal name).
122 -- If the External parameter is given as a string, then this string is
123 -- treated as an external name (exactly as though it had been given as an
124 -- External_Name parameter for a normal Import pragma).
126 -- If the External parameter is given as an identifier (or there is no
127 -- External parameter, so that the Internal identifier is used), then
128 -- the external name is the characters of the identifier, translated
129 -- to all upper case letters for OpenVMS versions of GNAT, and to all
130 -- lower case letters for all other versions
132 -- Note: the external name specified or implied by any of these special
133 -- Import_xxx or Export_xxx pragmas override an external or link name
134 -- specified in a previous Import or Export pragma.
136 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
137 -- named notation, following the standard rules for subprogram calls, i.e.
138 -- parameters can be given in any order if named notation is used, and
139 -- positional and named notation can be mixed, subject to the rule that all
140 -- positional parameters must appear first.
142 -- Note: All these pragmas are implemented exactly following the DEC design
143 -- and implementation and are intended to be fully compatible with the use
144 -- of these pragmas in the DEC Ada compiler.
146 --------------------------------------------
147 -- Checking for Duplicated External Names --
148 --------------------------------------------
150 -- It is suspicious if two separate Export pragmas use the same external
151 -- name. The following table is used to diagnose this situation so that
152 -- an appropriate warning can be issued.
154 -- The Node_Id stored is for the N_String_Literal node created to hold
155 -- the value of the external name. The Sloc of this node is used to
156 -- cross-reference the location of the duplication.
158 package Externals is new Table.Table (
159 Table_Component_Type => Node_Id,
160 Table_Index_Type => Int,
161 Table_Low_Bound => 0,
162 Table_Initial => 100,
163 Table_Increment => 100,
164 Table_Name => "Name_Externals");
166 -------------------------------------
167 -- Local Subprograms and Variables --
168 -------------------------------------
170 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
171 -- This routine is used for possible casing adjustment of an explicit
172 -- external name supplied as a string literal (the node N), according to
173 -- the casing requirement of Opt.External_Name_Casing. If this is set to
174 -- As_Is, then the string literal is returned unchanged, but if it is set
175 -- to Uppercase or Lowercase, then a new string literal with appropriate
176 -- casing is constructed.
178 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
179 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
180 -- original one, following the renaming chain) is returned. Otherwise the
181 -- entity is returned unchanged. Should be in Einfo???
183 procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id);
184 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
185 -- of a Test_Case pragma if present (possibly Empty). We treat these as
186 -- spec expressions (i.e. similar to a default expression).
189 -- This is a dummy function called by the processing for pragma Reviewable.
190 -- It is there for assisting front end debugging. By placing a Reviewable
191 -- pragma in the source program, a breakpoint on rv catches this place in
192 -- the source, allowing convenient stepping to the point of interest.
194 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
195 -- Place semantic information on the argument of an Elaborate/Elaborate_All
196 -- pragma. Entity name for unit and its parents is taken from item in
197 -- previous with_clause that mentions the unit.
199 -------------------------------
200 -- Adjust_External_Name_Case --
201 -------------------------------
203 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
207 -- Adjust case of literal if required
209 if Opt.External_Name_Exp_Casing = As_Is then
213 -- Copy existing string
219 for J in 1 .. String_Length (Strval (N)) loop
220 CC := Get_String_Char (Strval (N), J);
222 if Opt.External_Name_Exp_Casing = Uppercase
223 and then CC >= Get_Char_Code ('a')
224 and then CC <= Get_Char_Code ('z')
226 Store_String_Char (CC - 32);
228 elsif Opt.External_Name_Exp_Casing = Lowercase
229 and then CC >= Get_Char_Code ('A')
230 and then CC <= Get_Char_Code ('Z')
232 Store_String_Char (CC + 32);
235 Store_String_Char (CC);
240 Make_String_Literal (Sloc (N),
241 Strval => End_String);
243 end Adjust_External_Name_Case;
245 ------------------------------
246 -- Analyze_PPC_In_Decl_Part --
247 ------------------------------
249 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
250 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
253 -- Install formals and push subprogram spec onto scope stack so that we
254 -- can see the formals from the pragma.
259 -- Preanalyze the boolean expression, we treat this as a spec expression
260 -- (i.e. similar to a default expression).
262 Preanalyze_Spec_Expression
263 (Get_Pragma_Arg (Arg1), Standard_Boolean);
265 -- For a class-wide condition, a reference to a controlling formal must
266 -- be interpreted as having the class-wide type (or an access to such)
267 -- so that the inherited condition can be properly applied to any
268 -- overriding operation (see ARM12 6.6.1 (7)).
270 if Class_Present (N) then
272 T : constant Entity_Id := Find_Dispatching_Type (S);
274 ACW : Entity_Id := Empty;
275 -- Access to T'class, created if there is a controlling formal
276 -- that is an access parameter.
278 function Get_ACW return Entity_Id;
279 -- If the expression has a reference to an controlling access
280 -- parameter, create an access to T'class for the necessary
281 -- conversions if one does not exist.
283 function Process (N : Node_Id) return Traverse_Result;
284 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
285 -- aspect for a primitive subprogram of a tagged type T, a name
286 -- that denotes a formal parameter of type T is interpreted as
287 -- having type T'Class. Similarly, a name that denotes a formal
288 -- accessparameter of type access-to-T is interpreted as having
289 -- type access-to-T'Class. This ensures the expression is well-
290 -- defined for a primitive subprogram of a type descended from T.
296 function Get_ACW return Entity_Id is
297 Loc : constant Source_Ptr := Sloc (N);
302 Decl := Make_Full_Type_Declaration (Loc,
303 Defining_Identifier => Make_Temporary (Loc, 'T'),
305 Make_Access_To_Object_Definition (Loc,
306 Subtype_Indication =>
307 New_Occurrence_Of (Class_Wide_Type (T), Loc),
308 All_Present => True));
310 Insert_Before (Unit_Declaration_Node (S), Decl);
312 ACW := Defining_Identifier (Decl);
313 Freeze_Before (Unit_Declaration_Node (S), ACW);
323 function Process (N : Node_Id) return Traverse_Result is
324 Loc : constant Source_Ptr := Sloc (N);
328 if Is_Entity_Name (N)
329 and then Is_Formal (Entity (N))
330 and then Nkind (Parent (N)) /= N_Type_Conversion
332 if Etype (Entity (N)) = T then
333 Typ := Class_Wide_Type (T);
335 elsif Is_Access_Type (Etype (Entity (N)))
336 and then Designated_Type (Etype (Entity (N))) = T
343 if Present (Typ) then
345 Make_Type_Conversion (Loc,
347 New_Occurrence_Of (Typ, Loc),
348 Expression => New_Occurrence_Of (Entity (N), Loc)));
356 procedure Replace_Type is new Traverse_Proc (Process);
359 Replace_Type (Get_Pragma_Arg (Arg1));
363 -- Remove the subprogram from the scope stack now that the pre-analysis
364 -- of the precondition/postcondition is done.
367 end Analyze_PPC_In_Decl_Part;
373 procedure Analyze_Pragma (N : Node_Id) is
374 Loc : constant Source_Ptr := Sloc (N);
375 Pname : constant Name_Id := Pragma_Name (N);
378 Pragma_Exit : exception;
379 -- This exception is used to exit pragma processing completely. It is
380 -- used when an error is detected, and no further processing is
381 -- required. It is also used if an earlier error has left the tree in
382 -- a state where the pragma should not be processed.
385 -- Number of pragma argument associations
391 -- First four pragma arguments (pragma argument association nodes, or
392 -- Empty if the corresponding argument does not exist).
394 type Name_List is array (Natural range <>) of Name_Id;
395 type Args_List is array (Natural range <>) of Node_Id;
396 -- Types used for arguments to Check_Arg_Order and Gather_Associations
398 procedure Ada_2005_Pragma;
399 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
400 -- Ada 95 mode, these are implementation defined pragmas, so should be
401 -- caught by the No_Implementation_Pragmas restriction.
403 procedure Ada_2012_Pragma;
404 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
405 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
406 -- should be caught by the No_Implementation_Pragmas restriction.
408 procedure Check_Ada_83_Warning;
409 -- Issues a warning message for the current pragma if operating in Ada
410 -- 83 mode (used for language pragmas that are not a standard part of
411 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
414 procedure Check_Arg_Count (Required : Nat);
415 -- Check argument count for pragma is equal to given parameter. If not,
416 -- then issue an error message and raise Pragma_Exit.
418 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
419 -- Arg which can either be a pragma argument association, in which case
420 -- the check is applied to the expression of the association or an
421 -- expression directly.
423 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
424 -- Check that an argument has the right form for an EXTERNAL_NAME
425 -- parameter of an extended import/export pragma. The rule is that the
426 -- name must be an identifier or string literal (in Ada 83 mode) or a
427 -- static string expression (in Ada 95 mode).
429 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
430 -- Check the specified argument Arg to make sure that it is an
431 -- identifier. If not give error and raise Pragma_Exit.
433 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
434 -- Check the specified argument Arg to make sure that it is an integer
435 -- literal. If not give error and raise Pragma_Exit.
437 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
438 -- Check the specified argument Arg to make sure that it has the proper
439 -- syntactic form for a local name and meets the semantic requirements
440 -- for a local name. The local name is analyzed as part of the
441 -- processing for this call. In addition, the local name is required
442 -- to represent an entity at the library level.
444 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
445 -- Check the specified argument Arg to make sure that it has the proper
446 -- syntactic form for a local name and meets the semantic requirements
447 -- for a local name. The local name is analyzed as part of the
448 -- processing for this call.
450 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
451 -- Check the specified argument Arg to make sure that it is a valid
452 -- locking policy name. If not give error and raise Pragma_Exit.
454 procedure Check_Arg_Is_One_Of
457 procedure Check_Arg_Is_One_Of
459 N1, N2, N3 : Name_Id);
460 procedure Check_Arg_Is_One_Of
462 N1, N2, N3, N4, N5 : Name_Id);
463 -- Check the specified argument Arg to make sure that it is an
464 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
465 -- present). If not then give error and raise Pragma_Exit.
467 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
468 -- Check the specified argument Arg to make sure that it is a valid
469 -- queuing policy name. If not give error and raise Pragma_Exit.
471 procedure Check_Arg_Is_Static_Expression
473 Typ : Entity_Id := Empty);
474 -- Check the specified argument Arg to make sure that it is a static
475 -- expression of the given type (i.e. it will be analyzed and resolved
476 -- using this type, which can be any valid argument to Resolve, e.g.
477 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
478 -- Typ is left Empty, then any static expression is allowed.
480 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
481 -- Check the specified argument Arg to make sure that it is a valid task
482 -- dispatching policy name. If not give error and raise Pragma_Exit.
484 procedure Check_Arg_Order (Names : Name_List);
485 -- Checks for an instance of two arguments with identifiers for the
486 -- current pragma which are not in the sequence indicated by Names,
487 -- and if so, generates a fatal message about bad order of arguments.
489 procedure Check_At_Least_N_Arguments (N : Nat);
490 -- Check there are at least N arguments present
492 procedure Check_At_Most_N_Arguments (N : Nat);
493 -- Check there are no more than N arguments present
495 procedure Check_Component
498 In_Variant_Part : Boolean := False);
499 -- Examine an Unchecked_Union component for correct use of per-object
500 -- constrained subtypes, and for restrictions on finalizable components.
501 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
502 -- should be set when Comp comes from a record variant.
504 procedure Check_Duplicate_Pragma (E : Entity_Id);
505 -- Check if a pragma of the same name as the current pragma is already
506 -- chained as a rep pragma to the given entity. If so give a message
507 -- about the duplicate, and then raise Pragma_Exit so does not return.
508 -- Also checks for delayed aspect specification node in the chain.
510 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
511 -- Nam is an N_String_Literal node containing the external name set by
512 -- an Import or Export pragma (or extended Import or Export pragma).
513 -- This procedure checks for possible duplications if this is the export
514 -- case, and if found, issues an appropriate error message.
516 procedure Check_First_Subtype (Arg : Node_Id);
517 -- Checks that Arg, whose expression is an entity name, references a
520 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
521 -- Checks that the given argument has an identifier, and if so, requires
522 -- it to match the given identifier name. If there is no identifier, or
523 -- a non-matching identifier, then an error message is given and
524 -- Pragma_Exit is raised.
526 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
527 -- Checks that the given argument has an identifier, and if so, requires
528 -- it to match one of the given identifier names. If there is no
529 -- identifier, or a non-matching identifier, then an error message is
530 -- given and Pragma_Exit is raised.
532 procedure Check_In_Main_Program;
533 -- Common checks for pragmas that appear within a main program
534 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
536 procedure Check_Interrupt_Or_Attach_Handler;
537 -- Common processing for first argument of pragma Interrupt_Handler or
538 -- pragma Attach_Handler.
540 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
541 -- Check that pragma appears in a declarative part, or in a package
542 -- specification, i.e. that it does not occur in a statement sequence
545 procedure Check_No_Identifier (Arg : Node_Id);
546 -- Checks that the given argument does not have an identifier. If
547 -- an identifier is present, then an error message is issued, and
548 -- Pragma_Exit is raised.
550 procedure Check_No_Identifiers;
551 -- Checks that none of the arguments to the pragma has an identifier.
552 -- If any argument has an identifier, then an error message is issued,
553 -- and Pragma_Exit is raised.
555 procedure Check_No_Link_Name;
556 -- Checks that no link name is specified
558 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
559 -- Checks if the given argument has an identifier, and if so, requires
560 -- it to match the given identifier name. If there is a non-matching
561 -- identifier, then an error message is given and Pragma_Exit is raised.
563 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
564 -- Checks if the given argument has an identifier, and if so, requires
565 -- it to match the given identifier name. If there is a non-matching
566 -- identifier, then an error message is given and Pragma_Exit is raised.
567 -- In this version of the procedure, the identifier name is given as
568 -- a string with lower case letters.
570 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
571 -- Called to process a precondition or postcondition pragma. There are
574 -- The pragma appears after a subprogram spec
576 -- If the corresponding check is not enabled, the pragma is analyzed
577 -- but otherwise ignored and control returns with In_Body set False.
579 -- If the check is enabled, then the first step is to analyze the
580 -- pragma, but this is skipped if the subprogram spec appears within
581 -- a package specification (because this is the case where we delay
582 -- analysis till the end of the spec). Then (whether or not it was
583 -- analyzed), the pragma is chained to the subprogram in question
584 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
585 -- caller with In_Body set False.
587 -- The pragma appears at the start of subprogram body declarations
589 -- In this case an immediate return to the caller is made with
590 -- In_Body set True, and the pragma is NOT analyzed.
592 -- In all other cases, an error message for bad placement is given
594 procedure Check_Static_Constraint (Constr : Node_Id);
595 -- Constr is a constraint from an N_Subtype_Indication node from a
596 -- component constraint in an Unchecked_Union type. This routine checks
597 -- that the constraint is static as required by the restrictions for
600 procedure Check_Test_Case;
601 -- Called to process a test-case pragma. The treatment is similar to the
602 -- one for pre- and postcondition in Check_Precondition_Postcondition,
603 -- except the placement rules for the test-case pragma are stricter.
604 -- This pragma may only occur after a subprogram spec declared directly
605 -- in a package spec unit. In this case, the pragma is chained to the
606 -- subprogram in question (using Spec_TC_List and Next_Pragma) and
607 -- analysis of the pragma is delayed till the end of the spec. In
608 -- all other cases, an error message for bad placement is given.
610 procedure Check_Valid_Configuration_Pragma;
611 -- Legality checks for placement of a configuration pragma
613 procedure Check_Valid_Library_Unit_Pragma;
614 -- Legality checks for library unit pragmas. A special case arises for
615 -- pragmas in generic instances that come from copies of the original
616 -- library unit pragmas in the generic templates. In the case of other
617 -- than library level instantiations these can appear in contexts which
618 -- would normally be invalid (they only apply to the original template
619 -- and to library level instantiations), and they are simply ignored,
620 -- which is implemented by rewriting them as null statements.
622 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
623 -- Check an Unchecked_Union variant for lack of nested variants and
624 -- presence of at least one component. UU_Typ is the related Unchecked_
627 procedure Error_Pragma (Msg : String);
628 pragma No_Return (Error_Pragma);
629 -- Outputs error message for current pragma. The message contains a %
630 -- that will be replaced with the pragma name, and the flag is placed
631 -- on the pragma itself. Pragma_Exit is then raised.
633 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
634 pragma No_Return (Error_Pragma_Arg);
635 -- Outputs error message for current pragma. The message may contain
636 -- a % that will be replaced with the pragma name. The parameter Arg
637 -- may either be a pragma argument association, in which case the flag
638 -- is placed on the expression of this association, or an expression,
639 -- in which case the flag is placed directly on the expression. The
640 -- message is placed using Error_Msg_N, so the message may also contain
641 -- an & insertion character which will reference the given Arg value.
642 -- After placing the message, Pragma_Exit is raised.
644 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
645 pragma No_Return (Error_Pragma_Arg);
646 -- Similar to above form of Error_Pragma_Arg except that two messages
647 -- are provided, the second is a continuation comment starting with \.
649 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
650 pragma No_Return (Error_Pragma_Arg_Ident);
651 -- Outputs error message for current pragma. The message may contain
652 -- a % that will be replaced with the pragma name. The parameter Arg
653 -- must be a pragma argument association with a non-empty identifier
654 -- (i.e. its Chars field must be set), and the error message is placed
655 -- on the identifier. The message is placed using Error_Msg_N so
656 -- the message may also contain an & insertion character which will
657 -- reference the identifier. After placing the message, Pragma_Exit
660 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
661 pragma No_Return (Error_Pragma_Ref);
662 -- Outputs error message for current pragma. The message may contain
663 -- a % that will be replaced with the pragma name. The parameter Ref
664 -- must be an entity whose name can be referenced by & and sloc by #.
665 -- After placing the message, Pragma_Exit is raised.
667 function Find_Lib_Unit_Name return Entity_Id;
668 -- Used for a library unit pragma to find the entity to which the
669 -- library unit pragma applies, returns the entity found.
671 procedure Find_Program_Unit_Name (Id : Node_Id);
672 -- If the pragma is a compilation unit pragma, the id must denote the
673 -- compilation unit in the same compilation, and the pragma must appear
674 -- in the list of preceding or trailing pragmas. If it is a program
675 -- unit pragma that is not a compilation unit pragma, then the
676 -- identifier must be visible.
678 function Find_Unique_Parameterless_Procedure
680 Arg : Node_Id) return Entity_Id;
681 -- Used for a procedure pragma to find the unique parameterless
682 -- procedure identified by Name, returns it if it exists, otherwise
683 -- errors out and uses Arg as the pragma argument for the message.
685 procedure Fix_Error (Msg : in out String);
686 -- This is called prior to issuing an error message. Msg is a string
687 -- which typically contains the substring pragma. If the current pragma
688 -- comes from an aspect, each such "pragma" substring is replaced with
689 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
690 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
692 procedure Gather_Associations
694 Args : out Args_List);
695 -- This procedure is used to gather the arguments for a pragma that
696 -- permits arbitrary ordering of parameters using the normal rules
697 -- for named and positional parameters. The Names argument is a list
698 -- of Name_Id values that corresponds to the allowed pragma argument
699 -- association identifiers in order. The result returned in Args is
700 -- a list of corresponding expressions that are the pragma arguments.
701 -- Note that this is a list of expressions, not of pragma argument
702 -- associations (Gather_Associations has completely checked all the
703 -- optional identifiers when it returns). An entry in Args is Empty
704 -- on return if the corresponding argument is not present.
706 procedure GNAT_Pragma;
707 -- Called for all GNAT defined pragmas to check the relevant restriction
708 -- (No_Implementation_Pragmas).
710 function Is_Before_First_Decl
711 (Pragma_Node : Node_Id;
712 Decls : List_Id) return Boolean;
713 -- Return True if Pragma_Node is before the first declarative item in
714 -- Decls where Decls is the list of declarative items.
716 function Is_Configuration_Pragma return Boolean;
717 -- Determines if the placement of the current pragma is appropriate
718 -- for a configuration pragma.
720 function Is_In_Context_Clause return Boolean;
721 -- Returns True if pragma appears within the context clause of a unit,
722 -- and False for any other placement (does not generate any messages).
724 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
725 -- Analyzes the argument, and determines if it is a static string
726 -- expression, returns True if so, False if non-static or not String.
728 procedure Pragma_Misplaced;
729 pragma No_Return (Pragma_Misplaced);
730 -- Issue fatal error message for misplaced pragma
732 procedure Process_Atomic_Shared_Volatile;
733 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
734 -- Shared is an obsolete Ada 83 pragma, treated as being identical
735 -- in effect to pragma Atomic.
737 procedure Process_Compile_Time_Warning_Or_Error;
738 -- Common processing for Compile_Time_Error and Compile_Time_Warning
740 procedure Process_Convention
741 (C : out Convention_Id;
742 Ent : out Entity_Id);
743 -- Common processing for Convention, Interface, Import and Export.
744 -- Checks first two arguments of pragma, and sets the appropriate
745 -- convention value in the specified entity or entities. On return
746 -- C is the convention, Ent is the referenced entity.
748 procedure Process_Extended_Import_Export_Exception_Pragma
749 (Arg_Internal : Node_Id;
750 Arg_External : Node_Id;
753 -- Common processing for the pragmas Import/Export_Exception. The three
754 -- arguments correspond to the three named parameters of the pragma. An
755 -- argument is empty if the corresponding parameter is not present in
758 procedure Process_Extended_Import_Export_Object_Pragma
759 (Arg_Internal : Node_Id;
760 Arg_External : Node_Id;
762 -- Common processing for the pragmas Import/Export_Object. The three
763 -- arguments correspond to the three named parameters of the pragmas. An
764 -- argument is empty if the corresponding parameter is not present in
767 procedure Process_Extended_Import_Export_Internal_Arg
768 (Arg_Internal : Node_Id := Empty);
769 -- Common processing for all extended Import and Export pragmas. The
770 -- argument is the pragma parameter for the Internal argument. If
771 -- Arg_Internal is empty or inappropriate, an error message is posted.
772 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
773 -- set to identify the referenced entity.
775 procedure Process_Extended_Import_Export_Subprogram_Pragma
776 (Arg_Internal : Node_Id;
777 Arg_External : Node_Id;
778 Arg_Parameter_Types : Node_Id;
779 Arg_Result_Type : Node_Id := Empty;
780 Arg_Mechanism : Node_Id;
781 Arg_Result_Mechanism : Node_Id := Empty;
782 Arg_First_Optional_Parameter : Node_Id := Empty);
783 -- Common processing for all extended Import and Export pragmas applying
784 -- to subprograms. The caller omits any arguments that do not apply to
785 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
786 -- only in the Import_Function and Export_Function cases). The argument
787 -- names correspond to the allowed pragma association identifiers.
789 procedure Process_Generic_List;
790 -- Common processing for Share_Generic and Inline_Generic
792 procedure Process_Import_Or_Interface;
793 -- Common processing for Import of Interface
795 procedure Process_Import_Predefined_Type;
796 -- Processing for completing a type with pragma Import. This is used
797 -- to declare types that match predefined C types, especially for cases
798 -- without corresponding Ada predefined type.
800 procedure Process_Inline (Active : Boolean);
801 -- Common processing for Inline and Inline_Always. The parameter
802 -- indicates if the inline pragma is active, i.e. if it should actually
803 -- cause inlining to occur.
805 procedure Process_Interface_Name
806 (Subprogram_Def : Entity_Id;
809 -- Given the last two arguments of pragma Import, pragma Export, or
810 -- pragma Interface_Name, performs validity checks and sets the
811 -- Interface_Name field of the given subprogram entity to the
812 -- appropriate external or link name, depending on the arguments given.
813 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
814 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
815 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
816 -- nor Link_Arg is present, the interface name is set to the default
817 -- from the subprogram name.
819 procedure Process_Interrupt_Or_Attach_Handler;
820 -- Common processing for Interrupt and Attach_Handler pragmas
822 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
823 -- Common processing for Restrictions and Restriction_Warnings pragmas.
824 -- Warn is True for Restriction_Warnings, or for Restrictions if the
825 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
826 -- is not set in the Restrictions case.
828 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
829 -- Common processing for Suppress and Unsuppress. The boolean parameter
830 -- Suppress_Case is True for the Suppress case, and False for the
833 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
834 -- This procedure sets the Is_Exported flag for the given entity,
835 -- checking that the entity was not previously imported. Arg is
836 -- the argument that specified the entity. A check is also made
837 -- for exporting inappropriate entities.
839 procedure Set_Extended_Import_Export_External_Name
840 (Internal_Ent : Entity_Id;
841 Arg_External : Node_Id);
842 -- Common processing for all extended import export pragmas. The first
843 -- argument, Internal_Ent, is the internal entity, which has already
844 -- been checked for validity by the caller. Arg_External is from the
845 -- Import or Export pragma, and may be null if no External parameter
846 -- was present. If Arg_External is present and is a non-null string
847 -- (a null string is treated as the default), then the Interface_Name
848 -- field of Internal_Ent is set appropriately.
850 procedure Set_Imported (E : Entity_Id);
851 -- This procedure sets the Is_Imported flag for the given entity,
852 -- checking that it is not previously exported or imported.
854 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
855 -- Mech is a parameter passing mechanism (see Import_Function syntax
856 -- for MECHANISM_NAME). This routine checks that the mechanism argument
857 -- has the right form, and if not issues an error message. If the
858 -- argument has the right form then the Mechanism field of Ent is
859 -- set appropriately.
861 procedure Set_Ravenscar_Profile (N : Node_Id);
862 -- Activate the set of configuration pragmas and restrictions that make
863 -- up the Ravenscar Profile. N is the corresponding pragma node, which
864 -- is used for error messages on any constructs that violate the
867 ---------------------
868 -- Ada_2005_Pragma --
869 ---------------------
871 procedure Ada_2005_Pragma is
873 if Ada_Version <= Ada_95 then
874 Check_Restriction (No_Implementation_Pragmas, N);
878 ---------------------
879 -- Ada_2012_Pragma --
880 ---------------------
882 procedure Ada_2012_Pragma is
884 if Ada_Version <= Ada_2005 then
885 Check_Restriction (No_Implementation_Pragmas, N);
889 --------------------------
890 -- Check_Ada_83_Warning --
891 --------------------------
893 procedure Check_Ada_83_Warning is
895 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
896 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
898 end Check_Ada_83_Warning;
900 ---------------------
901 -- Check_Arg_Count --
902 ---------------------
904 procedure Check_Arg_Count (Required : Nat) is
906 if Arg_Count /= Required then
907 Error_Pragma ("wrong number of arguments for pragma%");
911 --------------------------------
912 -- Check_Arg_Is_External_Name --
913 --------------------------------
915 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
916 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
919 if Nkind (Argx) = N_Identifier then
923 Analyze_And_Resolve (Argx, Standard_String);
925 if Is_OK_Static_Expression (Argx) then
928 elsif Etype (Argx) = Any_Type then
931 -- An interesting special case, if we have a string literal and
932 -- we are in Ada 83 mode, then we allow it even though it will
933 -- not be flagged as static. This allows expected Ada 83 mode
934 -- use of external names which are string literals, even though
935 -- technically these are not static in Ada 83.
937 elsif Ada_Version = Ada_83
938 and then Nkind (Argx) = N_String_Literal
942 -- Static expression that raises Constraint_Error. This has
943 -- already been flagged, so just exit from pragma processing.
945 elsif Is_Static_Expression (Argx) then
948 -- Here we have a real error (non-static expression)
951 Error_Msg_Name_1 := Pname;
955 "argument for pragma% must be a identifier or "
956 & "static string expression!";
959 Flag_Non_Static_Expr (Msg, Argx);
964 end Check_Arg_Is_External_Name;
966 -----------------------------
967 -- Check_Arg_Is_Identifier --
968 -----------------------------
970 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
971 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
973 if Nkind (Argx) /= N_Identifier then
975 ("argument for pragma% must be identifier", Argx);
977 end Check_Arg_Is_Identifier;
979 ----------------------------------
980 -- Check_Arg_Is_Integer_Literal --
981 ----------------------------------
983 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
984 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
986 if Nkind (Argx) /= N_Integer_Literal then
988 ("argument for pragma% must be integer literal", Argx);
990 end Check_Arg_Is_Integer_Literal;
992 -------------------------------------------
993 -- Check_Arg_Is_Library_Level_Local_Name --
994 -------------------------------------------
998 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
999 -- | library_unit_NAME
1001 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1003 Check_Arg_Is_Local_Name (Arg);
1005 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1006 and then Comes_From_Source (N)
1009 ("argument for pragma% must be library level entity", Arg);
1011 end Check_Arg_Is_Library_Level_Local_Name;
1013 -----------------------------
1014 -- Check_Arg_Is_Local_Name --
1015 -----------------------------
1019 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1020 -- | library_unit_NAME
1022 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1023 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1028 if Nkind (Argx) not in N_Direct_Name
1029 and then (Nkind (Argx) /= N_Attribute_Reference
1030 or else Present (Expressions (Argx))
1031 or else Nkind (Prefix (Argx)) /= N_Identifier)
1032 and then (not Is_Entity_Name (Argx)
1033 or else not Is_Compilation_Unit (Entity (Argx)))
1035 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1038 -- No further check required if not an entity name
1040 if not Is_Entity_Name (Argx) then
1046 Ent : constant Entity_Id := Entity (Argx);
1047 Scop : constant Entity_Id := Scope (Ent);
1049 -- Case of a pragma applied to a compilation unit: pragma must
1050 -- occur immediately after the program unit in the compilation.
1052 if Is_Compilation_Unit (Ent) then
1054 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1056 -- Case of pragma placed immediately after spec
1058 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1061 -- Case of pragma placed immediately after body
1063 elsif Nkind (Decl) = N_Subprogram_Declaration
1064 and then Present (Corresponding_Body (Decl))
1068 (Parent (Unit_Declaration_Node
1069 (Corresponding_Body (Decl))));
1071 -- All other cases are illegal
1078 -- Special restricted placement rule from 10.2.1(11.8/2)
1080 elsif Is_Generic_Formal (Ent)
1081 and then Prag_Id = Pragma_Preelaborable_Initialization
1083 OK := List_Containing (N) =
1084 Generic_Formal_Declarations
1085 (Unit_Declaration_Node (Scop));
1087 -- Default case, just check that the pragma occurs in the scope
1088 -- of the entity denoted by the name.
1091 OK := Current_Scope = Scop;
1096 ("pragma% argument must be in same declarative part", Arg);
1100 end Check_Arg_Is_Local_Name;
1102 ---------------------------------
1103 -- Check_Arg_Is_Locking_Policy --
1104 ---------------------------------
1106 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1107 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1110 Check_Arg_Is_Identifier (Argx);
1112 if not Is_Locking_Policy_Name (Chars (Argx)) then
1113 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1115 end Check_Arg_Is_Locking_Policy;
1117 -------------------------
1118 -- Check_Arg_Is_One_Of --
1119 -------------------------
1121 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1122 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1125 Check_Arg_Is_Identifier (Argx);
1127 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1128 Error_Msg_Name_2 := N1;
1129 Error_Msg_Name_3 := N2;
1130 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1132 end Check_Arg_Is_One_Of;
1134 procedure Check_Arg_Is_One_Of
1136 N1, N2, N3 : Name_Id)
1138 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1141 Check_Arg_Is_Identifier (Argx);
1143 if Chars (Argx) /= N1
1144 and then Chars (Argx) /= N2
1145 and then Chars (Argx) /= N3
1147 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1149 end Check_Arg_Is_One_Of;
1151 procedure Check_Arg_Is_One_Of
1153 N1, N2, N3, N4, N5 : Name_Id)
1155 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1158 Check_Arg_Is_Identifier (Argx);
1160 if Chars (Argx) /= N1
1161 and then Chars (Argx) /= N2
1162 and then Chars (Argx) /= N3
1163 and then Chars (Argx) /= N4
1164 and then Chars (Argx) /= N5
1166 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1168 end Check_Arg_Is_One_Of;
1169 ---------------------------------
1170 -- Check_Arg_Is_Queuing_Policy --
1171 ---------------------------------
1173 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1174 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1177 Check_Arg_Is_Identifier (Argx);
1179 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1180 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1182 end Check_Arg_Is_Queuing_Policy;
1184 ------------------------------------
1185 -- Check_Arg_Is_Static_Expression --
1186 ------------------------------------
1188 procedure Check_Arg_Is_Static_Expression
1190 Typ : Entity_Id := Empty)
1192 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1195 if Present (Typ) then
1196 Analyze_And_Resolve (Argx, Typ);
1198 Analyze_And_Resolve (Argx);
1201 if Is_OK_Static_Expression (Argx) then
1204 elsif Etype (Argx) = Any_Type then
1207 -- An interesting special case, if we have a string literal and we
1208 -- are in Ada 83 mode, then we allow it even though it will not be
1209 -- flagged as static. This allows the use of Ada 95 pragmas like
1210 -- Import in Ada 83 mode. They will of course be flagged with
1211 -- warnings as usual, but will not cause errors.
1213 elsif Ada_Version = Ada_83
1214 and then Nkind (Argx) = N_String_Literal
1218 -- Static expression that raises Constraint_Error. This has already
1219 -- been flagged, so just exit from pragma processing.
1221 elsif Is_Static_Expression (Argx) then
1224 -- Finally, we have a real error
1227 Error_Msg_Name_1 := Pname;
1231 "argument for pragma% must be a static expression!";
1234 Flag_Non_Static_Expr (Msg, Argx);
1239 end Check_Arg_Is_Static_Expression;
1241 ------------------------------------------
1242 -- Check_Arg_Is_Task_Dispatching_Policy --
1243 ------------------------------------------
1245 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1246 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1249 Check_Arg_Is_Identifier (Argx);
1251 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1253 ("& is not a valid task dispatching policy name", Argx);
1255 end Check_Arg_Is_Task_Dispatching_Policy;
1257 ---------------------
1258 -- Check_Arg_Order --
1259 ---------------------
1261 procedure Check_Arg_Order (Names : Name_List) is
1264 Highest_So_Far : Natural := 0;
1265 -- Highest index in Names seen do far
1269 for J in 1 .. Arg_Count loop
1270 if Chars (Arg) /= No_Name then
1271 for K in Names'Range loop
1272 if Chars (Arg) = Names (K) then
1273 if K < Highest_So_Far then
1274 Error_Msg_Name_1 := Pname;
1276 ("parameters out of order for pragma%", Arg);
1277 Error_Msg_Name_1 := Names (K);
1278 Error_Msg_Name_2 := Names (Highest_So_Far);
1279 Error_Msg_N ("\% must appear before %", Arg);
1283 Highest_So_Far := K;
1291 end Check_Arg_Order;
1293 --------------------------------
1294 -- Check_At_Least_N_Arguments --
1295 --------------------------------
1297 procedure Check_At_Least_N_Arguments (N : Nat) is
1299 if Arg_Count < N then
1300 Error_Pragma ("too few arguments for pragma%");
1302 end Check_At_Least_N_Arguments;
1304 -------------------------------
1305 -- Check_At_Most_N_Arguments --
1306 -------------------------------
1308 procedure Check_At_Most_N_Arguments (N : Nat) is
1311 if Arg_Count > N then
1313 for J in 1 .. N loop
1315 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1318 end Check_At_Most_N_Arguments;
1320 ---------------------
1321 -- Check_Component --
1322 ---------------------
1324 procedure Check_Component
1327 In_Variant_Part : Boolean := False)
1329 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1330 Sindic : constant Node_Id :=
1331 Subtype_Indication (Component_Definition (Comp));
1332 Typ : constant Entity_Id := Etype (Comp_Id);
1334 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1335 -- Determine whether entity Id appears inside a generic body.
1336 -- Shouldn't this be in a more general place ???
1338 -------------------------
1339 -- Inside_Generic_Body --
1340 -------------------------
1342 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1347 while Present (S) and then S /= Standard_Standard loop
1348 if Ekind (S) = E_Generic_Package
1349 and then In_Package_Body (S)
1358 end Inside_Generic_Body;
1360 -- Start of processing for Check_Component
1363 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1364 -- object constraint, then the component type shall be an Unchecked_
1367 if Nkind (Sindic) = N_Subtype_Indication
1368 and then Has_Per_Object_Constraint (Comp_Id)
1369 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1372 ("component subtype subject to per-object constraint " &
1373 "must be an Unchecked_Union", Comp);
1375 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1376 -- the body of a generic unit, or within the body of any of its
1377 -- descendant library units, no part of the type of a component
1378 -- declared in a variant_part of the unchecked union type shall be of
1379 -- a formal private type or formal private extension declared within
1380 -- the formal part of the generic unit.
1382 elsif Ada_Version >= Ada_2012
1383 and then Inside_Generic_Body (UU_Typ)
1384 and then In_Variant_Part
1385 and then Is_Private_Type (Typ)
1386 and then Is_Generic_Type (Typ)
1389 ("component of Unchecked_Union cannot be of generic type", Comp);
1391 elsif Needs_Finalization (Typ) then
1393 ("component of Unchecked_Union cannot be controlled", Comp);
1395 elsif Has_Task (Typ) then
1397 ("component of Unchecked_Union cannot have tasks", Comp);
1399 end Check_Component;
1401 ----------------------------
1402 -- Check_Duplicate_Pragma --
1403 ----------------------------
1405 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1409 -- Nothing to do if this pragma comes from an aspect specification,
1410 -- since we could not be duplicating a pragma, and we dealt with the
1411 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1413 if From_Aspect_Specification (N) then
1417 -- Otherwise current pragma may duplicate previous pragma or a
1418 -- previously given aspect specification for the same pragma.
1420 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1423 Error_Msg_Name_1 := Pragma_Name (N);
1424 Error_Msg_Sloc := Sloc (P);
1426 if Nkind (P) = N_Aspect_Specification
1427 or else From_Aspect_Specification (P)
1429 Error_Msg_NE ("aspect% for & previously given#", N, E);
1431 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1436 end Check_Duplicate_Pragma;
1438 ----------------------------------
1439 -- Check_Duplicated_Export_Name --
1440 ----------------------------------
1442 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1443 String_Val : constant String_Id := Strval (Nam);
1446 -- We are only interested in the export case, and in the case of
1447 -- generics, it is the instance, not the template, that is the
1448 -- problem (the template will generate a warning in any case).
1450 if not Inside_A_Generic
1451 and then (Prag_Id = Pragma_Export
1453 Prag_Id = Pragma_Export_Procedure
1455 Prag_Id = Pragma_Export_Valued_Procedure
1457 Prag_Id = Pragma_Export_Function)
1459 for J in Externals.First .. Externals.Last loop
1460 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1461 Error_Msg_Sloc := Sloc (Externals.Table (J));
1462 Error_Msg_N ("external name duplicates name given#", Nam);
1467 Externals.Append (Nam);
1469 end Check_Duplicated_Export_Name;
1471 -------------------------
1472 -- Check_First_Subtype --
1473 -------------------------
1475 procedure Check_First_Subtype (Arg : Node_Id) is
1476 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1477 Ent : constant Entity_Id := Entity (Argx);
1480 if Is_First_Subtype (Ent) then
1483 elsif Is_Type (Ent) then
1485 ("pragma% cannot apply to subtype", Argx);
1487 elsif Is_Object (Ent) then
1489 ("pragma% cannot apply to object, requires a type", Argx);
1493 ("pragma% cannot apply to&, requires a type", Argx);
1495 end Check_First_Subtype;
1497 ----------------------
1498 -- Check_Identifier --
1499 ----------------------
1501 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1504 and then Nkind (Arg) = N_Pragma_Argument_Association
1506 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1507 Error_Msg_Name_1 := Pname;
1508 Error_Msg_Name_2 := Id;
1509 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1513 end Check_Identifier;
1515 --------------------------------
1516 -- Check_Identifier_Is_One_Of --
1517 --------------------------------
1519 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1522 and then Nkind (Arg) = N_Pragma_Argument_Association
1524 if Chars (Arg) = No_Name then
1525 Error_Msg_Name_1 := Pname;
1526 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1529 elsif Chars (Arg) /= N1
1530 and then Chars (Arg) /= N2
1532 Error_Msg_Name_1 := Pname;
1533 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1537 end Check_Identifier_Is_One_Of;
1539 ---------------------------
1540 -- Check_In_Main_Program --
1541 ---------------------------
1543 procedure Check_In_Main_Program is
1544 P : constant Node_Id := Parent (N);
1547 -- Must be at in subprogram body
1549 if Nkind (P) /= N_Subprogram_Body then
1550 Error_Pragma ("% pragma allowed only in subprogram");
1552 -- Otherwise warn if obviously not main program
1554 elsif Present (Parameter_Specifications (Specification (P)))
1555 or else not Is_Compilation_Unit (Defining_Entity (P))
1557 Error_Msg_Name_1 := Pname;
1559 ("?pragma% is only effective in main program", N);
1561 end Check_In_Main_Program;
1563 ---------------------------------------
1564 -- Check_Interrupt_Or_Attach_Handler --
1565 ---------------------------------------
1567 procedure Check_Interrupt_Or_Attach_Handler is
1568 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1569 Handler_Proc, Proc_Scope : Entity_Id;
1574 if Prag_Id = Pragma_Interrupt_Handler then
1575 Check_Restriction (No_Dynamic_Attachment, N);
1578 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1579 Proc_Scope := Scope (Handler_Proc);
1581 -- On AAMP only, a pragma Interrupt_Handler is supported for
1582 -- nonprotected parameterless procedures.
1584 if not AAMP_On_Target
1585 or else Prag_Id = Pragma_Attach_Handler
1587 if Ekind (Proc_Scope) /= E_Protected_Type then
1589 ("argument of pragma% must be protected procedure", Arg1);
1592 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1593 Error_Pragma ("pragma% must be in protected definition");
1597 if not Is_Library_Level_Entity (Proc_Scope)
1598 or else (AAMP_On_Target
1599 and then not Is_Library_Level_Entity (Handler_Proc))
1602 ("argument for pragma% must be library level entity", Arg1);
1605 -- AI05-0033: A pragma cannot appear within a generic body, because
1606 -- instance can be in a nested scope. The check that protected type
1607 -- is itself a library-level declaration is done elsewhere.
1609 -- Note: we omit this check in Codepeer mode to properly handle code
1610 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1612 if Inside_A_Generic then
1613 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1614 and then In_Package_Body (Scope (Current_Scope))
1615 and then not CodePeer_Mode
1617 Error_Pragma ("pragma% cannot be used inside a generic");
1620 end Check_Interrupt_Or_Attach_Handler;
1622 -------------------------------------------
1623 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1624 -------------------------------------------
1626 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1635 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1638 elsif Nkind_In (P, N_Package_Specification,
1643 -- Note: the following tests seem a little peculiar, because
1644 -- they test for bodies, but if we were in the statement part
1645 -- of the body, we would already have hit the handled statement
1646 -- sequence, so the only way we get here is by being in the
1647 -- declarative part of the body.
1649 elsif Nkind_In (P, N_Subprogram_Body,
1660 Error_Pragma ("pragma% is not in declarative part or package spec");
1661 end Check_Is_In_Decl_Part_Or_Package_Spec;
1663 -------------------------
1664 -- Check_No_Identifier --
1665 -------------------------
1667 procedure Check_No_Identifier (Arg : Node_Id) is
1669 if Nkind (Arg) = N_Pragma_Argument_Association
1670 and then Chars (Arg) /= No_Name
1672 Error_Pragma_Arg_Ident
1673 ("pragma% does not permit identifier& here", Arg);
1675 end Check_No_Identifier;
1677 --------------------------
1678 -- Check_No_Identifiers --
1679 --------------------------
1681 procedure Check_No_Identifiers is
1684 if Arg_Count > 0 then
1686 while Present (Arg_Node) loop
1687 Check_No_Identifier (Arg_Node);
1691 end Check_No_Identifiers;
1693 ------------------------
1694 -- Check_No_Link_Name --
1695 ------------------------
1697 procedure Check_No_Link_Name is
1700 and then Chars (Arg3) = Name_Link_Name
1705 if Present (Arg4) then
1707 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1709 end Check_No_Link_Name;
1711 -------------------------------
1712 -- Check_Optional_Identifier --
1713 -------------------------------
1715 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1718 and then Nkind (Arg) = N_Pragma_Argument_Association
1719 and then Chars (Arg) /= No_Name
1721 if Chars (Arg) /= Id then
1722 Error_Msg_Name_1 := Pname;
1723 Error_Msg_Name_2 := Id;
1724 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1728 end Check_Optional_Identifier;
1730 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1732 Name_Buffer (1 .. Id'Length) := Id;
1733 Name_Len := Id'Length;
1734 Check_Optional_Identifier (Arg, Name_Find);
1735 end Check_Optional_Identifier;
1737 --------------------------------------
1738 -- Check_Precondition_Postcondition --
1739 --------------------------------------
1741 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1745 procedure Chain_PPC (PO : Node_Id);
1746 -- If PO is an entry or a [generic] subprogram declaration node, then
1747 -- the precondition/postcondition applies to this subprogram and the
1748 -- processing for the pragma is completed. Otherwise the pragma is
1755 procedure Chain_PPC (PO : Node_Id) is
1760 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1761 if not From_Aspect_Specification (N) then
1763 ("pragma% cannot be applied to abstract subprogram");
1765 elsif Class_Present (N) then
1770 ("aspect % requires ''Class for abstract subprogram");
1773 -- AI05-0230: The same restriction applies to null procedures. For
1774 -- compatibility with earlier uses of the Ada pragma, apply this
1775 -- rule only to aspect specifications.
1777 -- The above discrpency needs documentation. Robert is dubious
1778 -- about whether it is a good idea ???
1780 elsif Nkind (PO) = N_Subprogram_Declaration
1781 and then Nkind (Specification (PO)) = N_Procedure_Specification
1782 and then Null_Present (Specification (PO))
1783 and then From_Aspect_Specification (N)
1784 and then not Class_Present (N)
1787 ("aspect % requires ''Class for null procedure");
1789 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1790 N_Generic_Subprogram_Declaration,
1791 N_Entry_Declaration)
1796 -- Here if we have [generic] subprogram or entry declaration
1798 if Nkind (PO) = N_Entry_Declaration then
1799 S := Defining_Entity (PO);
1801 S := Defining_Unit_Name (Specification (PO));
1804 -- Make sure we do not have the case of a precondition pragma when
1805 -- the Pre'Class aspect is present.
1807 -- We do this by looking at pragmas already chained to the entity
1808 -- since the aspect derived pragma will be put on this list first.
1810 if Pragma_Name (N) = Name_Precondition then
1811 if not From_Aspect_Specification (N) then
1812 P := Spec_PPC_List (Contract (S));
1813 while Present (P) loop
1814 if Pragma_Name (P) = Name_Precondition
1815 and then From_Aspect_Specification (P)
1816 and then Class_Present (P)
1818 Error_Msg_Sloc := Sloc (P);
1820 ("pragma% not allowed, `Pre''Class` aspect given#");
1823 P := Next_Pragma (P);
1828 -- Similarly check for Pre with inherited Pre'Class. Note that
1829 -- we cover the aspect case as well here.
1831 if Pragma_Name (N) = Name_Precondition
1832 and then not Class_Present (N)
1835 Inherited : constant Subprogram_List :=
1836 Inherited_Subprograms (S);
1840 for J in Inherited'Range loop
1841 P := Spec_PPC_List (Contract (Inherited (J)));
1842 while Present (P) loop
1843 if Pragma_Name (P) = Name_Precondition
1844 and then Class_Present (P)
1846 Error_Msg_Sloc := Sloc (P);
1848 ("pragma% not allowed, `Pre''Class` "
1849 & "aspect inherited from#");
1852 P := Next_Pragma (P);
1858 -- Note: we do not analyze the pragma at this point. Instead we
1859 -- delay this analysis until the end of the declarative part in
1860 -- which the pragma appears. This implements the required delay
1861 -- in this analysis, allowing forward references. The analysis
1862 -- happens at the end of Analyze_Declarations.
1864 -- Chain spec PPC pragma to list for subprogram
1866 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1867 Set_Spec_PPC_List (Contract (S), N);
1869 -- Return indicating spec case
1875 -- Start of processing for Check_Precondition_Postcondition
1878 if not Is_List_Member (N) then
1882 -- Preanalyze message argument if present. Visibility in this
1883 -- argument is established at the point of pragma occurrence.
1885 if Arg_Count = 2 then
1886 Check_Optional_Identifier (Arg2, Name_Message);
1887 Preanalyze_Spec_Expression
1888 (Get_Pragma_Arg (Arg2), Standard_String);
1891 -- Record if pragma is disabled
1893 if Check_Enabled (Pname) then
1894 Set_SCO_Pragma_Enabled (Loc);
1897 -- If we are within an inlined body, the legality of the pragma
1898 -- has been checked already.
1900 if In_Inlined_Body then
1905 -- Search prior declarations
1908 while Present (Prev (P)) loop
1911 -- If the previous node is a generic subprogram, do not go to to
1912 -- the original node, which is the unanalyzed tree: we need to
1913 -- attach the pre/postconditions to the analyzed version at this
1914 -- point. They get propagated to the original tree when analyzing
1915 -- the corresponding body.
1917 if Nkind (P) not in N_Generic_Declaration then
1918 PO := Original_Node (P);
1923 -- Skip past prior pragma
1925 if Nkind (PO) = N_Pragma then
1928 -- Skip stuff not coming from source
1930 elsif not Comes_From_Source (PO) then
1932 -- The condition may apply to a subprogram instantiation
1934 if Nkind (PO) = N_Subprogram_Declaration
1935 and then Present (Generic_Parent (Specification (PO)))
1940 elsif Nkind (PO) = N_Subprogram_Declaration
1941 and then In_Instance
1946 -- For all other cases of non source code, do nothing
1952 -- Only remaining possibility is subprogram declaration
1960 -- If we fall through loop, pragma is at start of list, so see if it
1961 -- is at the start of declarations of a subprogram body.
1963 if Nkind (Parent (N)) = N_Subprogram_Body
1964 and then List_Containing (N) = Declarations (Parent (N))
1966 if Operating_Mode /= Generate_Code
1967 or else Inside_A_Generic
1969 -- Analyze pragma expression for correctness and for ASIS use
1971 Preanalyze_Spec_Expression
1972 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1978 -- See if it is in the pragmas after a library level subprogram
1980 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1982 -- In formal verification mode, analyze pragma expression for
1983 -- correctness, as it is not expanded later.
1986 Analyze_PPC_In_Decl_Part
1987 (N, Defining_Entity (Unit (Parent (Parent (N)))));
1990 Chain_PPC (Unit (Parent (Parent (N))));
1994 -- If we fall through, pragma was misplaced
1997 end Check_Precondition_Postcondition;
1999 -----------------------------
2000 -- Check_Static_Constraint --
2001 -----------------------------
2003 -- Note: for convenience in writing this procedure, in addition to
2004 -- the officially (i.e. by spec) allowed argument which is always a
2005 -- constraint, it also allows ranges and discriminant associations.
2006 -- Above is not clear ???
2008 procedure Check_Static_Constraint (Constr : Node_Id) is
2010 procedure Require_Static (E : Node_Id);
2011 -- Require given expression to be static expression
2013 --------------------
2014 -- Require_Static --
2015 --------------------
2017 procedure Require_Static (E : Node_Id) is
2019 if not Is_OK_Static_Expression (E) then
2020 Flag_Non_Static_Expr
2021 ("non-static constraint not allowed in Unchecked_Union!", E);
2026 -- Start of processing for Check_Static_Constraint
2029 case Nkind (Constr) is
2030 when N_Discriminant_Association =>
2031 Require_Static (Expression (Constr));
2034 Require_Static (Low_Bound (Constr));
2035 Require_Static (High_Bound (Constr));
2037 when N_Attribute_Reference =>
2038 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2039 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2041 when N_Range_Constraint =>
2042 Check_Static_Constraint (Range_Expression (Constr));
2044 when N_Index_Or_Discriminant_Constraint =>
2048 IDC := First (Constraints (Constr));
2049 while Present (IDC) loop
2050 Check_Static_Constraint (IDC);
2058 end Check_Static_Constraint;
2060 ---------------------
2061 -- Check_Test_Case --
2062 ---------------------
2064 procedure Check_Test_Case is
2068 procedure Chain_TC (PO : Node_Id);
2069 -- If PO is a [generic] subprogram declaration node, then the
2070 -- test-case applies to this subprogram and the processing for the
2071 -- pragma is completed. Otherwise the pragma is misplaced.
2077 procedure Chain_TC (PO : Node_Id) is
2081 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2082 if From_Aspect_Specification (N) then
2084 ("aspect% cannot be applied to abstract subprogram");
2087 ("pragma% cannot be applied to abstract subprogram");
2090 elsif Nkind (PO) = N_Entry_Declaration then
2091 if From_Aspect_Specification (N) then
2092 Error_Pragma ("aspect% cannot be applied to entry");
2094 Error_Pragma ("pragma% cannot be applied to entry");
2097 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2098 N_Generic_Subprogram_Declaration)
2103 -- Here if we have [generic] subprogram declaration
2105 S := Defining_Unit_Name (Specification (PO));
2107 -- Note: we do not analyze the pragma at this point. Instead we
2108 -- delay this analysis until the end of the declarative part in
2109 -- which the pragma appears. This implements the required delay
2110 -- in this analysis, allowing forward references. The analysis
2111 -- happens at the end of Analyze_Declarations.
2113 -- There should not be another test case with the same name
2114 -- associated to this subprogram.
2117 Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2121 TC := Spec_TC_List (Contract (S));
2122 while Present (TC) loop
2125 (Name, Get_Name_From_Test_Case_Pragma (TC))
2127 Error_Msg_Sloc := Sloc (TC);
2129 if From_Aspect_Specification (N) then
2130 Error_Pragma ("name for aspect% is already used#");
2132 Error_Pragma ("name for pragma% is already used#");
2136 TC := Next_Pragma (TC);
2140 -- Chain spec TC pragma to list for subprogram
2142 Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2143 Set_Spec_TC_List (Contract (S), N);
2146 -- Start of processing for Check_Test_Case
2149 if not Is_List_Member (N) then
2153 -- Test cases should only appear in package spec unit
2155 if Get_Source_Unit (N) = No_Unit
2156 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2157 N_Package_Declaration,
2158 N_Generic_Package_Declaration)
2163 -- Search prior declarations
2166 while Present (Prev (P)) loop
2169 -- If the previous node is a generic subprogram, do not go to to
2170 -- the original node, which is the unanalyzed tree: we need to
2171 -- attach the test-case to the analyzed version at this point.
2172 -- They get propagated to the original tree when analyzing the
2173 -- corresponding body.
2175 if Nkind (P) not in N_Generic_Declaration then
2176 PO := Original_Node (P);
2181 -- Skip past prior pragma
2183 if Nkind (PO) = N_Pragma then
2186 -- Skip stuff not coming from source
2188 elsif not Comes_From_Source (PO) then
2191 -- Only remaining possibility is subprogram declaration. First
2192 -- check that it is declared directly in a package declaration.
2193 -- This may be either the package declaration for the current unit
2194 -- being defined or a local package declaration.
2196 elsif not Present (Parent (Parent (PO)))
2197 or else not Present (Parent (Parent (Parent (PO))))
2198 or else not Nkind_In (Parent (Parent (PO)),
2199 N_Package_Declaration,
2200 N_Generic_Package_Declaration)
2210 -- If we fall through, pragma was misplaced
2213 end Check_Test_Case;
2215 --------------------------------------
2216 -- Check_Valid_Configuration_Pragma --
2217 --------------------------------------
2219 -- A configuration pragma must appear in the context clause of a
2220 -- compilation unit, and only other pragmas may precede it. Note that
2221 -- the test also allows use in a configuration pragma file.
2223 procedure Check_Valid_Configuration_Pragma is
2225 if not Is_Configuration_Pragma then
2226 Error_Pragma ("incorrect placement for configuration pragma%");
2228 end Check_Valid_Configuration_Pragma;
2230 -------------------------------------
2231 -- Check_Valid_Library_Unit_Pragma --
2232 -------------------------------------
2234 procedure Check_Valid_Library_Unit_Pragma is
2236 Parent_Node : Node_Id;
2237 Unit_Name : Entity_Id;
2238 Unit_Kind : Node_Kind;
2239 Unit_Node : Node_Id;
2240 Sindex : Source_File_Index;
2243 if not Is_List_Member (N) then
2247 Plist := List_Containing (N);
2248 Parent_Node := Parent (Plist);
2250 if Parent_Node = Empty then
2253 -- Case of pragma appearing after a compilation unit. In this case
2254 -- it must have an argument with the corresponding name and must
2255 -- be part of the following pragmas of its parent.
2257 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2258 if Plist /= Pragmas_After (Parent_Node) then
2261 elsif Arg_Count = 0 then
2263 ("argument required if outside compilation unit");
2266 Check_No_Identifiers;
2267 Check_Arg_Count (1);
2268 Unit_Node := Unit (Parent (Parent_Node));
2269 Unit_Kind := Nkind (Unit_Node);
2271 Analyze (Get_Pragma_Arg (Arg1));
2273 if Unit_Kind = N_Generic_Subprogram_Declaration
2274 or else Unit_Kind = N_Subprogram_Declaration
2276 Unit_Name := Defining_Entity (Unit_Node);
2278 elsif Unit_Kind in N_Generic_Instantiation then
2279 Unit_Name := Defining_Entity (Unit_Node);
2282 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2285 if Chars (Unit_Name) /=
2286 Chars (Entity (Get_Pragma_Arg (Arg1)))
2289 ("pragma% argument is not current unit name", Arg1);
2292 if Ekind (Unit_Name) = E_Package
2293 and then Present (Renamed_Entity (Unit_Name))
2295 Error_Pragma ("pragma% not allowed for renamed package");
2299 -- Pragma appears other than after a compilation unit
2302 -- Here we check for the generic instantiation case and also
2303 -- for the case of processing a generic formal package. We
2304 -- detect these cases by noting that the Sloc on the node
2305 -- does not belong to the current compilation unit.
2307 Sindex := Source_Index (Current_Sem_Unit);
2309 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2310 Rewrite (N, Make_Null_Statement (Loc));
2313 -- If before first declaration, the pragma applies to the
2314 -- enclosing unit, and the name if present must be this name.
2316 elsif Is_Before_First_Decl (N, Plist) then
2317 Unit_Node := Unit_Declaration_Node (Current_Scope);
2318 Unit_Kind := Nkind (Unit_Node);
2320 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2323 elsif Unit_Kind = N_Subprogram_Body
2324 and then not Acts_As_Spec (Unit_Node)
2328 elsif Nkind (Parent_Node) = N_Package_Body then
2331 elsif Nkind (Parent_Node) = N_Package_Specification
2332 and then Plist = Private_Declarations (Parent_Node)
2336 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2337 or else Nkind (Parent_Node) =
2338 N_Generic_Subprogram_Declaration)
2339 and then Plist = Generic_Formal_Declarations (Parent_Node)
2343 elsif Arg_Count > 0 then
2344 Analyze (Get_Pragma_Arg (Arg1));
2346 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2348 ("name in pragma% must be enclosing unit", Arg1);
2351 -- It is legal to have no argument in this context
2357 -- Error if not before first declaration. This is because a
2358 -- library unit pragma argument must be the name of a library
2359 -- unit (RM 10.1.5(7)), but the only names permitted in this
2360 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2361 -- generic subprogram declarations or generic instantiations.
2365 ("pragma% misplaced, must be before first declaration");
2369 end Check_Valid_Library_Unit_Pragma;
2375 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2376 Clist : constant Node_Id := Component_List (Variant);
2380 if not Is_Non_Empty_List (Component_Items (Clist)) then
2382 ("Unchecked_Union may not have empty component list",
2387 Comp := First (Component_Items (Clist));
2388 while Present (Comp) loop
2389 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2398 procedure Error_Pragma (Msg : String) is
2399 MsgF : String := Msg;
2401 Error_Msg_Name_1 := Pname;
2403 Error_Msg_N (MsgF, N);
2407 ----------------------
2408 -- Error_Pragma_Arg --
2409 ----------------------
2411 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2412 MsgF : String := Msg;
2414 Error_Msg_Name_1 := Pname;
2416 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2418 end Error_Pragma_Arg;
2420 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2421 MsgF : String := Msg1;
2423 Error_Msg_Name_1 := Pname;
2425 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2426 Error_Pragma_Arg (Msg2, Arg);
2427 end Error_Pragma_Arg;
2429 ----------------------------
2430 -- Error_Pragma_Arg_Ident --
2431 ----------------------------
2433 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2434 MsgF : String := Msg;
2436 Error_Msg_Name_1 := Pname;
2438 Error_Msg_N (MsgF, Arg);
2440 end Error_Pragma_Arg_Ident;
2442 ----------------------
2443 -- Error_Pragma_Ref --
2444 ----------------------
2446 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2447 MsgF : String := Msg;
2449 Error_Msg_Name_1 := Pname;
2451 Error_Msg_Sloc := Sloc (Ref);
2452 Error_Msg_NE (MsgF, N, Ref);
2454 end Error_Pragma_Ref;
2456 ------------------------
2457 -- Find_Lib_Unit_Name --
2458 ------------------------
2460 function Find_Lib_Unit_Name return Entity_Id is
2462 -- Return inner compilation unit entity, for case of nested
2463 -- categorization pragmas. This happens in generic unit.
2465 if Nkind (Parent (N)) = N_Package_Specification
2466 and then Defining_Entity (Parent (N)) /= Current_Scope
2468 return Defining_Entity (Parent (N));
2470 return Current_Scope;
2472 end Find_Lib_Unit_Name;
2474 ----------------------------
2475 -- Find_Program_Unit_Name --
2476 ----------------------------
2478 procedure Find_Program_Unit_Name (Id : Node_Id) is
2479 Unit_Name : Entity_Id;
2480 Unit_Kind : Node_Kind;
2481 P : constant Node_Id := Parent (N);
2484 if Nkind (P) = N_Compilation_Unit then
2485 Unit_Kind := Nkind (Unit (P));
2487 if Unit_Kind = N_Subprogram_Declaration
2488 or else Unit_Kind = N_Package_Declaration
2489 or else Unit_Kind in N_Generic_Declaration
2491 Unit_Name := Defining_Entity (Unit (P));
2493 if Chars (Id) = Chars (Unit_Name) then
2494 Set_Entity (Id, Unit_Name);
2495 Set_Etype (Id, Etype (Unit_Name));
2497 Set_Etype (Id, Any_Type);
2499 ("cannot find program unit referenced by pragma%");
2503 Set_Etype (Id, Any_Type);
2504 Error_Pragma ("pragma% inapplicable to this unit");
2510 end Find_Program_Unit_Name;
2512 -----------------------------------------
2513 -- Find_Unique_Parameterless_Procedure --
2514 -----------------------------------------
2516 function Find_Unique_Parameterless_Procedure
2518 Arg : Node_Id) return Entity_Id
2520 Proc : Entity_Id := Empty;
2523 -- The body of this procedure needs some comments ???
2525 if not Is_Entity_Name (Name) then
2527 ("argument of pragma% must be entity name", Arg);
2529 elsif not Is_Overloaded (Name) then
2530 Proc := Entity (Name);
2532 if Ekind (Proc) /= E_Procedure
2533 or else Present (First_Formal (Proc))
2536 ("argument of pragma% must be parameterless procedure", Arg);
2541 Found : Boolean := False;
2543 Index : Interp_Index;
2546 Get_First_Interp (Name, Index, It);
2547 while Present (It.Nam) loop
2550 if Ekind (Proc) = E_Procedure
2551 and then No (First_Formal (Proc))
2555 Set_Entity (Name, Proc);
2556 Set_Is_Overloaded (Name, False);
2559 ("ambiguous handler name for pragma% ", Arg);
2563 Get_Next_Interp (Index, It);
2568 ("argument of pragma% must be parameterless procedure",
2571 Proc := Entity (Name);
2577 end Find_Unique_Parameterless_Procedure;
2583 procedure Fix_Error (Msg : in out String) is
2585 if From_Aspect_Specification (N) then
2586 for J in Msg'First .. Msg'Last - 5 loop
2587 if Msg (J .. J + 5) = "pragma" then
2588 Msg (J .. J + 5) := "aspect";
2592 if Error_Msg_Name_1 = Name_Precondition then
2593 Error_Msg_Name_1 := Name_Pre;
2594 elsif Error_Msg_Name_1 = Name_Postcondition then
2595 Error_Msg_Name_1 := Name_Post;
2600 -------------------------
2601 -- Gather_Associations --
2602 -------------------------
2604 procedure Gather_Associations
2606 Args : out Args_List)
2611 -- Initialize all parameters to Empty
2613 for J in Args'Range loop
2617 -- That's all we have to do if there are no argument associations
2619 if No (Pragma_Argument_Associations (N)) then
2623 -- Otherwise first deal with any positional parameters present
2625 Arg := First (Pragma_Argument_Associations (N));
2626 for Index in Args'Range loop
2627 exit when No (Arg) or else Chars (Arg) /= No_Name;
2628 Args (Index) := Get_Pragma_Arg (Arg);
2632 -- Positional parameters all processed, if any left, then we
2633 -- have too many positional parameters.
2635 if Present (Arg) and then Chars (Arg) = No_Name then
2637 ("too many positional associations for pragma%", Arg);
2640 -- Process named parameters if any are present
2642 while Present (Arg) loop
2643 if Chars (Arg) = No_Name then
2645 ("positional association cannot follow named association",
2649 for Index in Names'Range loop
2650 if Names (Index) = Chars (Arg) then
2651 if Present (Args (Index)) then
2653 ("duplicate argument association for pragma%", Arg);
2655 Args (Index) := Get_Pragma_Arg (Arg);
2660 if Index = Names'Last then
2661 Error_Msg_Name_1 := Pname;
2662 Error_Msg_N ("pragma% does not allow & argument", Arg);
2664 -- Check for possible misspelling
2666 for Index1 in Names'Range loop
2667 if Is_Bad_Spelling_Of
2668 (Chars (Arg), Names (Index1))
2670 Error_Msg_Name_1 := Names (Index1);
2671 Error_Msg_N -- CODEFIX
2672 ("\possible misspelling of%", Arg);
2684 end Gather_Associations;
2690 procedure GNAT_Pragma is
2692 Check_Restriction (No_Implementation_Pragmas, N);
2695 --------------------------
2696 -- Is_Before_First_Decl --
2697 --------------------------
2699 function Is_Before_First_Decl
2700 (Pragma_Node : Node_Id;
2701 Decls : List_Id) return Boolean
2703 Item : Node_Id := First (Decls);
2706 -- Only other pragmas can come before this pragma
2709 if No (Item) or else Nkind (Item) /= N_Pragma then
2712 elsif Item = Pragma_Node then
2718 end Is_Before_First_Decl;
2720 -----------------------------
2721 -- Is_Configuration_Pragma --
2722 -----------------------------
2724 -- A configuration pragma must appear in the context clause of a
2725 -- compilation unit, and only other pragmas may precede it. Note that
2726 -- the test below also permits use in a configuration pragma file.
2728 function Is_Configuration_Pragma return Boolean is
2729 Lis : constant List_Id := List_Containing (N);
2730 Par : constant Node_Id := Parent (N);
2734 -- If no parent, then we are in the configuration pragma file,
2735 -- so the placement is definitely appropriate.
2740 -- Otherwise we must be in the context clause of a compilation unit
2741 -- and the only thing allowed before us in the context list is more
2742 -- configuration pragmas.
2744 elsif Nkind (Par) = N_Compilation_Unit
2745 and then Context_Items (Par) = Lis
2752 elsif Nkind (Prg) /= N_Pragma then
2762 end Is_Configuration_Pragma;
2764 --------------------------
2765 -- Is_In_Context_Clause --
2766 --------------------------
2768 function Is_In_Context_Clause return Boolean is
2770 Parent_Node : Node_Id;
2773 if not Is_List_Member (N) then
2777 Plist := List_Containing (N);
2778 Parent_Node := Parent (Plist);
2780 if Parent_Node = Empty
2781 or else Nkind (Parent_Node) /= N_Compilation_Unit
2782 or else Context_Items (Parent_Node) /= Plist
2789 end Is_In_Context_Clause;
2791 ---------------------------------
2792 -- Is_Static_String_Expression --
2793 ---------------------------------
2795 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2796 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2799 Analyze_And_Resolve (Argx);
2800 return Is_OK_Static_Expression (Argx)
2801 and then Nkind (Argx) = N_String_Literal;
2802 end Is_Static_String_Expression;
2804 ----------------------
2805 -- Pragma_Misplaced --
2806 ----------------------
2808 procedure Pragma_Misplaced is
2810 Error_Pragma ("incorrect placement of pragma%");
2811 end Pragma_Misplaced;
2813 ------------------------------------
2814 -- Process Atomic_Shared_Volatile --
2815 ------------------------------------
2817 procedure Process_Atomic_Shared_Volatile is
2824 procedure Set_Atomic (E : Entity_Id);
2825 -- Set given type as atomic, and if no explicit alignment was given,
2826 -- set alignment to unknown, since back end knows what the alignment
2827 -- requirements are for atomic arrays. Note: this step is necessary
2828 -- for derived types.
2834 procedure Set_Atomic (E : Entity_Id) is
2838 if not Has_Alignment_Clause (E) then
2839 Set_Alignment (E, Uint_0);
2843 -- Start of processing for Process_Atomic_Shared_Volatile
2846 Check_Ada_83_Warning;
2847 Check_No_Identifiers;
2848 Check_Arg_Count (1);
2849 Check_Arg_Is_Local_Name (Arg1);
2850 E_Id := Get_Pragma_Arg (Arg1);
2852 if Etype (E_Id) = Any_Type then
2857 D := Declaration_Node (E);
2860 -- Check duplicate before we chain ourselves!
2862 Check_Duplicate_Pragma (E);
2864 -- Now check appropriateness of the entity
2867 if Rep_Item_Too_Early (E, N)
2869 Rep_Item_Too_Late (E, N)
2873 Check_First_Subtype (Arg1);
2876 if Prag_Id /= Pragma_Volatile then
2878 Set_Atomic (Underlying_Type (E));
2879 Set_Atomic (Base_Type (E));
2882 -- Attribute belongs on the base type. If the view of the type is
2883 -- currently private, it also belongs on the underlying type.
2885 Set_Is_Volatile (Base_Type (E));
2886 Set_Is_Volatile (Underlying_Type (E));
2888 Set_Treat_As_Volatile (E);
2889 Set_Treat_As_Volatile (Underlying_Type (E));
2891 elsif K = N_Object_Declaration
2892 or else (K = N_Component_Declaration
2893 and then Original_Record_Component (E) = E)
2895 if Rep_Item_Too_Late (E, N) then
2899 if Prag_Id /= Pragma_Volatile then
2902 -- If the object declaration has an explicit initialization, a
2903 -- temporary may have to be created to hold the expression, to
2904 -- ensure that access to the object remain atomic.
2906 if Nkind (Parent (E)) = N_Object_Declaration
2907 and then Present (Expression (Parent (E)))
2909 Set_Has_Delayed_Freeze (E);
2912 -- An interesting improvement here. If an object of type X is
2913 -- declared atomic, and the type X is not atomic, that's a
2914 -- pity, since it may not have appropriate alignment etc. We
2915 -- can rescue this in the special case where the object and
2916 -- type are in the same unit by just setting the type as
2917 -- atomic, so that the back end will process it as atomic.
2919 Utyp := Underlying_Type (Etype (E));
2922 and then Sloc (E) > No_Location
2923 and then Sloc (Utyp) > No_Location
2925 Get_Source_File_Index (Sloc (E)) =
2926 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2928 Set_Is_Atomic (Underlying_Type (Etype (E)));
2932 Set_Is_Volatile (E);
2933 Set_Treat_As_Volatile (E);
2937 ("inappropriate entity for pragma%", Arg1);
2939 end Process_Atomic_Shared_Volatile;
2941 -------------------------------------------
2942 -- Process_Compile_Time_Warning_Or_Error --
2943 -------------------------------------------
2945 procedure Process_Compile_Time_Warning_Or_Error is
2946 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2949 Check_Arg_Count (2);
2950 Check_No_Identifiers;
2951 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2952 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2954 if Compile_Time_Known_Value (Arg1x) then
2955 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2957 Str : constant String_Id :=
2958 Strval (Get_Pragma_Arg (Arg2));
2959 Len : constant Int := String_Length (Str);
2964 Cent : constant Entity_Id :=
2965 Cunit_Entity (Current_Sem_Unit);
2967 Force : constant Boolean :=
2968 Prag_Id = Pragma_Compile_Time_Warning
2970 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2971 and then (Ekind (Cent) /= E_Package
2972 or else not In_Private_Part (Cent));
2973 -- Set True if this is the warning case, and we are in the
2974 -- visible part of a package spec, or in a subprogram spec,
2975 -- in which case we want to force the client to see the
2976 -- warning, even though it is not in the main unit.
2979 -- Loop through segments of message separated by line feeds.
2980 -- We output these segments as separate messages with
2981 -- continuation marks for all but the first.
2986 Error_Msg_Strlen := 0;
2988 -- Loop to copy characters from argument to error message
2992 exit when Ptr > Len;
2993 CC := Get_String_Char (Str, Ptr);
2996 -- Ignore wide chars ??? else store character
2998 if In_Character_Range (CC) then
2999 C := Get_Character (CC);
3000 exit when C = ASCII.LF;
3001 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3002 Error_Msg_String (Error_Msg_Strlen) := C;
3006 -- Here with one line ready to go
3008 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3010 -- If this is a warning in a spec, then we want clients
3011 -- to see the warning, so mark the message with the
3012 -- special sequence !! to force the warning. In the case
3013 -- of a package spec, we do not force this if we are in
3014 -- the private part of the spec.
3017 if Cont = False then
3018 Error_Msg_N ("<~!!", Arg1);
3021 Error_Msg_N ("\<~!!", Arg1);
3024 -- Error, rather than warning, or in a body, so we do not
3025 -- need to force visibility for client (error will be
3026 -- output in any case, and this is the situation in which
3027 -- we do not want a client to get a warning, since the
3028 -- warning is in the body or the spec private part).
3031 if Cont = False then
3032 Error_Msg_N ("<~", Arg1);
3035 Error_Msg_N ("\<~", Arg1);
3039 exit when Ptr > Len;
3044 end Process_Compile_Time_Warning_Or_Error;
3046 ------------------------
3047 -- Process_Convention --
3048 ------------------------
3050 procedure Process_Convention
3051 (C : out Convention_Id;
3052 Ent : out Entity_Id)
3058 Comp_Unit : Unit_Number_Type;
3060 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3061 -- Called if we have more than one Export/Import/Convention pragma.
3062 -- This is generally illegal, but we have a special case of allowing
3063 -- Import and Interface to coexist if they specify the convention in
3064 -- a consistent manner. We are allowed to do this, since Interface is
3065 -- an implementation defined pragma, and we choose to do it since we
3066 -- know Rational allows this combination. S is the entity id of the
3067 -- subprogram in question. This procedure also sets the special flag
3068 -- Import_Interface_Present in both pragmas in the case where we do
3069 -- have matching Import and Interface pragmas.
3071 procedure Set_Convention_From_Pragma (E : Entity_Id);
3072 -- Set convention in entity E, and also flag that the entity has a
3073 -- convention pragma. If entity is for a private or incomplete type,
3074 -- also set convention and flag on underlying type. This procedure
3075 -- also deals with the special case of C_Pass_By_Copy convention.
3077 -------------------------------
3078 -- Diagnose_Multiple_Pragmas --
3079 -------------------------------
3081 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3082 Pdec : constant Node_Id := Declaration_Node (S);
3086 function Same_Convention (Decl : Node_Id) return Boolean;
3087 -- Decl is a pragma node. This function returns True if this
3088 -- pragma has a first argument that is an identifier with a
3089 -- Chars field corresponding to the Convention_Id C.
3091 function Same_Name (Decl : Node_Id) return Boolean;
3092 -- Decl is a pragma node. This function returns True if this
3093 -- pragma has a second argument that is an identifier with a
3094 -- Chars field that matches the Chars of the current subprogram.
3096 ---------------------
3097 -- Same_Convention --
3098 ---------------------
3100 function Same_Convention (Decl : Node_Id) return Boolean is
3101 Arg1 : constant Node_Id :=
3102 First (Pragma_Argument_Associations (Decl));
3105 if Present (Arg1) then
3107 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3109 if Nkind (Arg) = N_Identifier
3110 and then Is_Convention_Name (Chars (Arg))
3111 and then Get_Convention_Id (Chars (Arg)) = C
3119 end Same_Convention;
3125 function Same_Name (Decl : Node_Id) return Boolean is
3126 Arg1 : constant Node_Id :=
3127 First (Pragma_Argument_Associations (Decl));
3135 Arg2 := Next (Arg1);
3142 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3144 if Nkind (Arg) = N_Identifier
3145 and then Chars (Arg) = Chars (S)
3154 -- Start of processing for Diagnose_Multiple_Pragmas
3159 -- Definitely give message if we have Convention/Export here
3161 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3164 -- If we have an Import or Export, scan back from pragma to
3165 -- find any previous pragma applying to the same procedure.
3166 -- The scan will be terminated by the start of the list, or
3167 -- hitting the subprogram declaration. This won't allow one
3168 -- pragma to appear in the public part and one in the private
3169 -- part, but that seems very unlikely in practice.
3173 while Present (Decl) and then Decl /= Pdec loop
3175 -- Look for pragma with same name as us
3177 if Nkind (Decl) = N_Pragma
3178 and then Same_Name (Decl)
3180 -- Give error if same as our pragma or Export/Convention
3182 if Pragma_Name (Decl) = Name_Export
3184 Pragma_Name (Decl) = Name_Convention
3186 Pragma_Name (Decl) = Pragma_Name (N)
3190 -- Case of Import/Interface or the other way round
3192 elsif Pragma_Name (Decl) = Name_Interface
3194 Pragma_Name (Decl) = Name_Import
3196 -- Here we know that we have Import and Interface. It
3197 -- doesn't matter which way round they are. See if
3198 -- they specify the same convention. If so, all OK,
3199 -- and set special flags to stop other messages
3201 if Same_Convention (Decl) then
3202 Set_Import_Interface_Present (N);
3203 Set_Import_Interface_Present (Decl);
3206 -- If different conventions, special message
3209 Error_Msg_Sloc := Sloc (Decl);
3211 ("convention differs from that given#", Arg1);
3221 -- Give message if needed if we fall through those tests
3225 ("at most one Convention/Export/Import pragma is allowed",
3228 end Diagnose_Multiple_Pragmas;
3230 --------------------------------
3231 -- Set_Convention_From_Pragma --
3232 --------------------------------
3234 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3236 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3237 -- for an overridden dispatching operation. Technically this is
3238 -- an amendment and should only be done in Ada 2005 mode. However,
3239 -- this is clearly a mistake, since the problem that is addressed
3240 -- by this AI is that there is a clear gap in the RM!
3242 if Is_Dispatching_Operation (E)
3243 and then Present (Overridden_Operation (E))
3244 and then C /= Convention (Overridden_Operation (E))
3247 ("cannot change convention for " &
3248 "overridden dispatching operation",
3252 -- Set the convention
3254 Set_Convention (E, C);
3255 Set_Has_Convention_Pragma (E);
3257 if Is_Incomplete_Or_Private_Type (E)
3258 and then Present (Underlying_Type (E))
3260 Set_Convention (Underlying_Type (E), C);
3261 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3264 -- A class-wide type should inherit the convention of the specific
3265 -- root type (although this isn't specified clearly by the RM).
3267 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3268 Set_Convention (Class_Wide_Type (E), C);
3271 -- If the entity is a record type, then check for special case of
3272 -- C_Pass_By_Copy, which is treated the same as C except that the
3273 -- special record flag is set. This convention is only permitted
3274 -- on record types (see AI95-00131).
3276 if Cname = Name_C_Pass_By_Copy then
3277 if Is_Record_Type (E) then
3278 Set_C_Pass_By_Copy (Base_Type (E));
3279 elsif Is_Incomplete_Or_Private_Type (E)
3280 and then Is_Record_Type (Underlying_Type (E))
3282 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3285 ("C_Pass_By_Copy convention allowed only for record type",
3290 -- If the entity is a derived boolean type, check for the special
3291 -- case of convention C, C++, or Fortran, where we consider any
3292 -- nonzero value to represent true.
3294 if Is_Discrete_Type (E)
3295 and then Root_Type (Etype (E)) = Standard_Boolean
3301 C = Convention_Fortran)
3303 Set_Nonzero_Is_True (Base_Type (E));
3305 end Set_Convention_From_Pragma;
3307 -- Start of processing for Process_Convention
3310 Check_At_Least_N_Arguments (2);
3311 Check_Optional_Identifier (Arg1, Name_Convention);
3312 Check_Arg_Is_Identifier (Arg1);
3313 Cname := Chars (Get_Pragma_Arg (Arg1));
3315 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3316 -- tested again below to set the critical flag).
3318 if Cname = Name_C_Pass_By_Copy then
3321 -- Otherwise we must have something in the standard convention list
3323 elsif Is_Convention_Name (Cname) then
3324 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3326 -- In DEC VMS, it seems that there is an undocumented feature that
3327 -- any unrecognized convention is treated as the default, which for
3328 -- us is convention C. It does not seem so terrible to do this
3329 -- unconditionally, silently in the VMS case, and with a warning
3330 -- in the non-VMS case.
3333 if Warn_On_Export_Import and not OpenVMS_On_Target then
3335 ("?unrecognized convention name, C assumed",
3336 Get_Pragma_Arg (Arg1));
3342 Check_Optional_Identifier (Arg2, Name_Entity);
3343 Check_Arg_Is_Local_Name (Arg2);
3345 Id := Get_Pragma_Arg (Arg2);
3348 if not Is_Entity_Name (Id) then
3349 Error_Pragma_Arg ("entity name required", Arg2);
3354 -- Set entity to return
3358 -- Ada_Pass_By_Copy special checking
3360 if C = Convention_Ada_Pass_By_Copy then
3361 if not Is_First_Subtype (E) then
3363 ("convention `Ada_Pass_By_Copy` only "
3364 & "allowed for types", Arg2);
3367 if Is_By_Reference_Type (E) then
3369 ("convention `Ada_Pass_By_Copy` not allowed for "
3370 & "by-reference type", Arg1);
3374 -- Ada_Pass_By_Reference special checking
3376 if C = Convention_Ada_Pass_By_Reference then
3377 if not Is_First_Subtype (E) then
3379 ("convention `Ada_Pass_By_Reference` only "
3380 & "allowed for types", Arg2);
3383 if Is_By_Copy_Type (E) then
3385 ("convention `Ada_Pass_By_Reference` not allowed for "
3386 & "by-copy type", Arg1);
3390 -- Go to renamed subprogram if present, since convention applies to
3391 -- the actual renamed entity, not to the renaming entity. If the
3392 -- subprogram is inherited, go to parent subprogram.
3394 if Is_Subprogram (E)
3395 and then Present (Alias (E))
3397 if Nkind (Parent (Declaration_Node (E))) =
3398 N_Subprogram_Renaming_Declaration
3400 if Scope (E) /= Scope (Alias (E)) then
3402 ("cannot apply pragma% to non-local entity&#", E);
3407 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3408 N_Private_Extension_Declaration)
3409 and then Scope (E) = Scope (Alias (E))
3413 -- Return the parent subprogram the entity was inherited from
3419 -- Check that we are not applying this to a specless body
3421 if Is_Subprogram (E)
3422 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3425 ("pragma% requires separate spec and must come before body");
3428 -- Check that we are not applying this to a named constant
3430 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3431 Error_Msg_Name_1 := Pname;
3433 ("cannot apply pragma% to named constant!",
3434 Get_Pragma_Arg (Arg2));
3436 ("\supply appropriate type for&!", Arg2);
3439 if Ekind (E) = E_Enumeration_Literal then
3440 Error_Pragma ("enumeration literal not allowed for pragma%");
3443 -- Check for rep item appearing too early or too late
3445 if Etype (E) = Any_Type
3446 or else Rep_Item_Too_Early (E, N)
3450 elsif Present (Underlying_Type (E)) then
3451 E := Underlying_Type (E);
3454 if Rep_Item_Too_Late (E, N) then
3458 if Has_Convention_Pragma (E) then
3459 Diagnose_Multiple_Pragmas (E);
3461 elsif Convention (E) = Convention_Protected
3462 or else Ekind (Scope (E)) = E_Protected_Type
3465 ("a protected operation cannot be given a different convention",
3469 -- For Intrinsic, a subprogram is required
3471 if C = Convention_Intrinsic
3472 and then not Is_Subprogram (E)
3473 and then not Is_Generic_Subprogram (E)
3476 ("second argument of pragma% must be a subprogram", Arg2);
3479 -- For Stdcall, a subprogram, variable or subprogram type is required
3481 if C = Convention_Stdcall
3482 and then not Is_Subprogram (E)
3483 and then not Is_Generic_Subprogram (E)
3484 and then Ekind (E) /= E_Variable
3487 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3490 ("second argument of pragma% must be subprogram (type)",
3494 if not Is_Subprogram (E)
3495 and then not Is_Generic_Subprogram (E)
3497 Set_Convention_From_Pragma (E);
3500 Check_First_Subtype (Arg2);
3501 Set_Convention_From_Pragma (Base_Type (E));
3503 -- For subprograms, we must set the convention on the
3504 -- internally generated directly designated type as well.
3506 if Ekind (E) = E_Access_Subprogram_Type then
3507 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3511 -- For the subprogram case, set proper convention for all homonyms
3512 -- in same scope and the same declarative part, i.e. the same
3513 -- compilation unit.
3516 Comp_Unit := Get_Source_Unit (E);
3517 Set_Convention_From_Pragma (E);
3519 -- Treat a pragma Import as an implicit body, for GPS use
3521 if Prag_Id = Pragma_Import then
3522 Generate_Reference (E, Id, 'b');
3525 -- Loop through the homonyms of the pragma argument's entity
3530 exit when No (E1) or else Scope (E1) /= Current_Scope;
3532 -- Do not set the pragma on inherited operations or on formal
3535 if Comes_From_Source (E1)
3536 and then Comp_Unit = Get_Source_Unit (E1)
3537 and then not Is_Formal_Subprogram (E1)
3538 and then Nkind (Original_Node (Parent (E1))) /=
3539 N_Full_Type_Declaration
3541 if Present (Alias (E1))
3542 and then Scope (E1) /= Scope (Alias (E1))
3545 ("cannot apply pragma% to non-local entity& declared#",
3549 Set_Convention_From_Pragma (E1);
3551 if Prag_Id = Pragma_Import then
3552 Generate_Reference (E1, Id, 'b');
3556 -- For aspect case, do NOT apply to homonyms
3558 exit when From_Aspect_Specification (N);
3561 end Process_Convention;
3563 -----------------------------------------------------
3564 -- Process_Extended_Import_Export_Exception_Pragma --
3565 -----------------------------------------------------
3567 procedure Process_Extended_Import_Export_Exception_Pragma
3568 (Arg_Internal : Node_Id;
3569 Arg_External : Node_Id;
3577 if not OpenVMS_On_Target then
3579 ("?pragma% ignored (applies only to Open'V'M'S)");
3582 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3583 Def_Id := Entity (Arg_Internal);
3585 if Ekind (Def_Id) /= E_Exception then
3587 ("pragma% must refer to declared exception", Arg_Internal);
3590 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3592 if Present (Arg_Form) then
3593 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3596 if Present (Arg_Form)
3597 and then Chars (Arg_Form) = Name_Ada
3601 Set_Is_VMS_Exception (Def_Id);
3602 Set_Exception_Code (Def_Id, No_Uint);
3605 if Present (Arg_Code) then
3606 if not Is_VMS_Exception (Def_Id) then
3608 ("Code option for pragma% not allowed for Ada case",
3612 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3613 Code_Val := Expr_Value (Arg_Code);
3615 if not UI_Is_In_Int_Range (Code_Val) then
3617 ("Code option for pragma% must be in 32-bit range",
3621 Set_Exception_Code (Def_Id, Code_Val);
3624 end Process_Extended_Import_Export_Exception_Pragma;
3626 -------------------------------------------------
3627 -- Process_Extended_Import_Export_Internal_Arg --
3628 -------------------------------------------------
3630 procedure Process_Extended_Import_Export_Internal_Arg
3631 (Arg_Internal : Node_Id := Empty)
3634 if No (Arg_Internal) then
3635 Error_Pragma ("Internal parameter required for pragma%");
3638 if Nkind (Arg_Internal) = N_Identifier then
3641 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3642 and then (Prag_Id = Pragma_Import_Function
3644 Prag_Id = Pragma_Export_Function)
3650 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3653 Check_Arg_Is_Local_Name (Arg_Internal);
3654 end Process_Extended_Import_Export_Internal_Arg;
3656 --------------------------------------------------
3657 -- Process_Extended_Import_Export_Object_Pragma --
3658 --------------------------------------------------
3660 procedure Process_Extended_Import_Export_Object_Pragma
3661 (Arg_Internal : Node_Id;
3662 Arg_External : Node_Id;
3668 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3669 Def_Id := Entity (Arg_Internal);
3671 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3673 ("pragma% must designate an object", Arg_Internal);
3676 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3678 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3681 ("previous Common/Psect_Object applies, pragma % not permitted",
3685 if Rep_Item_Too_Late (Def_Id, N) then
3689 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3691 if Present (Arg_Size) then
3692 Check_Arg_Is_External_Name (Arg_Size);
3695 -- Export_Object case
3697 if Prag_Id = Pragma_Export_Object then
3698 if not Is_Library_Level_Entity (Def_Id) then
3700 ("argument for pragma% must be library level entity",
3704 if Ekind (Current_Scope) = E_Generic_Package then
3705 Error_Pragma ("pragma& cannot appear in a generic unit");
3708 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3710 ("exported object must have compile time known size",
3714 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3715 Error_Msg_N ("?duplicate Export_Object pragma", N);
3717 Set_Exported (Def_Id, Arg_Internal);
3720 -- Import_Object case
3723 if Is_Concurrent_Type (Etype (Def_Id)) then
3725 ("cannot use pragma% for task/protected object",
3729 if Ekind (Def_Id) = E_Constant then
3731 ("cannot import a constant", Arg_Internal);
3734 if Warn_On_Export_Import
3735 and then Has_Discriminants (Etype (Def_Id))
3738 ("imported value must be initialized?", Arg_Internal);
3741 if Warn_On_Export_Import
3742 and then Is_Access_Type (Etype (Def_Id))
3745 ("cannot import object of an access type?", Arg_Internal);
3748 if Warn_On_Export_Import
3749 and then Is_Imported (Def_Id)
3752 ("?duplicate Import_Object pragma", N);
3754 -- Check for explicit initialization present. Note that an
3755 -- initialization generated by the code generator, e.g. for an
3756 -- access type, does not count here.
3758 elsif Present (Expression (Parent (Def_Id)))
3761 (Original_Node (Expression (Parent (Def_Id))))
3763 Error_Msg_Sloc := Sloc (Def_Id);
3765 ("imported entities cannot be initialized (RM B.1(24))",
3766 "\no initialization allowed for & declared#", Arg1);
3768 Set_Imported (Def_Id);
3769 Note_Possible_Modification (Arg_Internal, Sure => False);
3772 end Process_Extended_Import_Export_Object_Pragma;
3774 ------------------------------------------------------
3775 -- Process_Extended_Import_Export_Subprogram_Pragma --
3776 ------------------------------------------------------
3778 procedure Process_Extended_Import_Export_Subprogram_Pragma
3779 (Arg_Internal : Node_Id;
3780 Arg_External : Node_Id;
3781 Arg_Parameter_Types : Node_Id;
3782 Arg_Result_Type : Node_Id := Empty;
3783 Arg_Mechanism : Node_Id;
3784 Arg_Result_Mechanism : Node_Id := Empty;
3785 Arg_First_Optional_Parameter : Node_Id := Empty)
3791 Ambiguous : Boolean;
3795 function Same_Base_Type
3797 Formal : Entity_Id) return Boolean;
3798 -- Determines if Ptype references the type of Formal. Note that only
3799 -- the base types need to match according to the spec. Ptype here is
3800 -- the argument from the pragma, which is either a type name, or an
3801 -- access attribute.
3803 --------------------
3804 -- Same_Base_Type --
3805 --------------------
3807 function Same_Base_Type
3809 Formal : Entity_Id) return Boolean
3811 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3815 -- Case where pragma argument is typ'Access
3817 if Nkind (Ptype) = N_Attribute_Reference
3818 and then Attribute_Name (Ptype) = Name_Access
3820 Pref := Prefix (Ptype);
3823 if not Is_Entity_Name (Pref)
3824 or else Entity (Pref) = Any_Type
3829 -- We have a match if the corresponding argument is of an
3830 -- anonymous access type, and its designated type matches the
3831 -- type of the prefix of the access attribute
3833 return Ekind (Ftyp) = E_Anonymous_Access_Type
3834 and then Base_Type (Entity (Pref)) =
3835 Base_Type (Etype (Designated_Type (Ftyp)));
3837 -- Case where pragma argument is a type name
3842 if not Is_Entity_Name (Ptype)
3843 or else Entity (Ptype) = Any_Type
3848 -- We have a match if the corresponding argument is of the type
3849 -- given in the pragma (comparing base types)
3851 return Base_Type (Entity (Ptype)) = Ftyp;
3855 -- Start of processing for
3856 -- Process_Extended_Import_Export_Subprogram_Pragma
3859 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3863 -- Loop through homonyms (overloadings) of the entity
3865 Hom_Id := Entity (Arg_Internal);
3866 while Present (Hom_Id) loop
3867 Def_Id := Get_Base_Subprogram (Hom_Id);
3869 -- We need a subprogram in the current scope
3871 if not Is_Subprogram (Def_Id)
3872 or else Scope (Def_Id) /= Current_Scope
3879 -- Pragma cannot apply to subprogram body
3881 if Is_Subprogram (Def_Id)
3882 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3886 ("pragma% requires separate spec"
3887 & " and must come before body");
3890 -- Test result type if given, note that the result type
3891 -- parameter can only be present for the function cases.
3893 if Present (Arg_Result_Type)
3894 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3898 elsif Etype (Def_Id) /= Standard_Void_Type
3900 (Pname = Name_Export_Procedure
3902 Pname = Name_Import_Procedure)
3906 -- Test parameter types if given. Note that this parameter
3907 -- has not been analyzed (and must not be, since it is
3908 -- semantic nonsense), so we get it as the parser left it.
3910 elsif Present (Arg_Parameter_Types) then
3911 Check_Matching_Types : declare
3916 Formal := First_Formal (Def_Id);
3918 if Nkind (Arg_Parameter_Types) = N_Null then
3919 if Present (Formal) then
3923 -- A list of one type, e.g. (List) is parsed as
3924 -- a parenthesized expression.
3926 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3927 and then Paren_Count (Arg_Parameter_Types) = 1
3930 or else Present (Next_Formal (Formal))
3935 Same_Base_Type (Arg_Parameter_Types, Formal);
3938 -- A list of more than one type is parsed as a aggregate
3940 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3941 and then Paren_Count (Arg_Parameter_Types) = 0
3943 Ptype := First (Expressions (Arg_Parameter_Types));
3944 while Present (Ptype) or else Present (Formal) loop
3947 or else not Same_Base_Type (Ptype, Formal)
3952 Next_Formal (Formal);
3957 -- Anything else is of the wrong form
3961 ("wrong form for Parameter_Types parameter",
3962 Arg_Parameter_Types);
3964 end Check_Matching_Types;
3967 -- Match is now False if the entry we found did not match
3968 -- either a supplied Parameter_Types or Result_Types argument
3974 -- Ambiguous case, the flag Ambiguous shows if we already
3975 -- detected this and output the initial messages.
3978 if not Ambiguous then
3980 Error_Msg_Name_1 := Pname;
3982 ("pragma% does not uniquely identify subprogram!",
3984 Error_Msg_Sloc := Sloc (Ent);
3985 Error_Msg_N ("matching subprogram #!", N);
3989 Error_Msg_Sloc := Sloc (Def_Id);
3990 Error_Msg_N ("matching subprogram #!", N);
3995 Hom_Id := Homonym (Hom_Id);
3998 -- See if we found an entry
4001 if not Ambiguous then
4002 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4004 ("pragma% cannot be given for generic subprogram");
4007 ("pragma% does not identify local subprogram");
4014 -- Import pragmas must be for imported entities
4016 if Prag_Id = Pragma_Import_Function
4018 Prag_Id = Pragma_Import_Procedure
4020 Prag_Id = Pragma_Import_Valued_Procedure
4022 if not Is_Imported (Ent) then
4024 ("pragma Import or Interface must precede pragma%");
4027 -- Here we have the Export case which can set the entity as exported
4029 -- But does not do so if the specified external name is null, since
4030 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4031 -- compatible) to request no external name.
4033 elsif Nkind (Arg_External) = N_String_Literal
4034 and then String_Length (Strval (Arg_External)) = 0
4038 -- In all other cases, set entity as exported
4041 Set_Exported (Ent, Arg_Internal);
4044 -- Special processing for Valued_Procedure cases
4046 if Prag_Id = Pragma_Import_Valued_Procedure
4048 Prag_Id = Pragma_Export_Valued_Procedure
4050 Formal := First_Formal (Ent);
4053 Error_Pragma ("at least one parameter required for pragma%");
4055 elsif Ekind (Formal) /= E_Out_Parameter then
4056 Error_Pragma ("first parameter must have mode out for pragma%");
4059 Set_Is_Valued_Procedure (Ent);
4063 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4065 -- Process Result_Mechanism argument if present. We have already
4066 -- checked that this is only allowed for the function case.
4068 if Present (Arg_Result_Mechanism) then
4069 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4072 -- Process Mechanism parameter if present. Note that this parameter
4073 -- is not analyzed, and must not be analyzed since it is semantic
4074 -- nonsense, so we get it in exactly as the parser left it.
4076 if Present (Arg_Mechanism) then
4084 -- A single mechanism association without a formal parameter
4085 -- name is parsed as a parenthesized expression. All other
4086 -- cases are parsed as aggregates, so we rewrite the single
4087 -- parameter case as an aggregate for consistency.
4089 if Nkind (Arg_Mechanism) /= N_Aggregate
4090 and then Paren_Count (Arg_Mechanism) = 1
4092 Rewrite (Arg_Mechanism,
4093 Make_Aggregate (Sloc (Arg_Mechanism),
4094 Expressions => New_List (
4095 Relocate_Node (Arg_Mechanism))));
4098 -- Case of only mechanism name given, applies to all formals
4100 if Nkind (Arg_Mechanism) /= N_Aggregate then
4101 Formal := First_Formal (Ent);
4102 while Present (Formal) loop
4103 Set_Mechanism_Value (Formal, Arg_Mechanism);
4104 Next_Formal (Formal);
4107 -- Case of list of mechanism associations given
4110 if Null_Record_Present (Arg_Mechanism) then
4112 ("inappropriate form for Mechanism parameter",
4116 -- Deal with positional ones first
4118 Formal := First_Formal (Ent);
4120 if Present (Expressions (Arg_Mechanism)) then
4121 Mname := First (Expressions (Arg_Mechanism));
4122 while Present (Mname) loop
4125 ("too many mechanism associations", Mname);
4128 Set_Mechanism_Value (Formal, Mname);
4129 Next_Formal (Formal);
4134 -- Deal with named entries
4136 if Present (Component_Associations (Arg_Mechanism)) then
4137 Massoc := First (Component_Associations (Arg_Mechanism));
4138 while Present (Massoc) loop
4139 Choice := First (Choices (Massoc));
4141 if Nkind (Choice) /= N_Identifier
4142 or else Present (Next (Choice))
4145 ("incorrect form for mechanism association",
4149 Formal := First_Formal (Ent);
4153 ("parameter name & not present", Choice);
4156 if Chars (Choice) = Chars (Formal) then
4158 (Formal, Expression (Massoc));
4160 -- Set entity on identifier (needed by ASIS)
4162 Set_Entity (Choice, Formal);
4167 Next_Formal (Formal);
4177 -- Process First_Optional_Parameter argument if present. We have
4178 -- already checked that this is only allowed for the Import case.
4180 if Present (Arg_First_Optional_Parameter) then
4181 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4183 ("first optional parameter must be formal parameter name",
4184 Arg_First_Optional_Parameter);
4187 Formal := First_Formal (Ent);
4191 ("specified formal parameter& not found",
4192 Arg_First_Optional_Parameter);
4195 exit when Chars (Formal) =
4196 Chars (Arg_First_Optional_Parameter);
4198 Next_Formal (Formal);
4201 Set_First_Optional_Parameter (Ent, Formal);
4203 -- Check specified and all remaining formals have right form
4205 while Present (Formal) loop
4206 if Ekind (Formal) /= E_In_Parameter then
4208 ("optional formal& is not of mode in!",
4209 Arg_First_Optional_Parameter, Formal);
4212 Dval := Default_Value (Formal);
4216 ("optional formal& does not have default value!",
4217 Arg_First_Optional_Parameter, Formal);
4219 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4224 ("default value for optional formal& is non-static!",
4225 Arg_First_Optional_Parameter, Formal);
4229 Set_Is_Optional_Parameter (Formal);
4230 Next_Formal (Formal);
4233 end Process_Extended_Import_Export_Subprogram_Pragma;
4235 --------------------------
4236 -- Process_Generic_List --
4237 --------------------------
4239 procedure Process_Generic_List is
4244 Check_No_Identifiers;
4245 Check_At_Least_N_Arguments (1);
4248 while Present (Arg) loop
4249 Exp := Get_Pragma_Arg (Arg);
4252 if not Is_Entity_Name (Exp)
4254 (not Is_Generic_Instance (Entity (Exp))
4256 not Is_Generic_Unit (Entity (Exp)))
4259 ("pragma% argument must be name of generic unit/instance",
4265 end Process_Generic_List;
4267 ------------------------------------
4268 -- Process_Import_Predefined_Type --
4269 ------------------------------------
4271 procedure Process_Import_Predefined_Type is
4272 Loc : constant Source_Ptr := Sloc (N);
4274 Ftyp : Node_Id := Empty;
4280 String_To_Name_Buffer (Strval (Expression (Arg3)));
4283 Elmt := First_Elmt (Predefined_Float_Types);
4284 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4288 Ftyp := Node (Elmt);
4290 if Present (Ftyp) then
4292 -- Don't build a derived type declaration, because predefined C
4293 -- types have no declaration anywhere, so cannot really be named.
4294 -- Instead build a full type declaration, starting with an
4295 -- appropriate type definition is built
4297 if Is_Floating_Point_Type (Ftyp) then
4298 Def := Make_Floating_Point_Definition (Loc,
4299 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4300 Make_Real_Range_Specification (Loc,
4301 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4302 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4304 -- Should never have a predefined type we cannot handle
4307 raise Program_Error;
4310 -- Build and insert a Full_Type_Declaration, which will be
4311 -- analyzed as soon as this list entry has been analyzed.
4313 Decl := Make_Full_Type_Declaration (Loc,
4314 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4315 Type_Definition => Def);
4317 Insert_After (N, Decl);
4318 Mark_Rewrite_Insertion (Decl);
4321 Error_Pragma_Arg ("no matching type found for pragma%",
4324 end Process_Import_Predefined_Type;
4326 ---------------------------------
4327 -- Process_Import_Or_Interface --
4328 ---------------------------------
4330 procedure Process_Import_Or_Interface is
4336 Process_Convention (C, Def_Id);
4337 Kill_Size_Check_Code (Def_Id);
4338 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4340 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4342 -- We do not permit Import to apply to a renaming declaration
4344 if Present (Renamed_Object (Def_Id)) then
4346 ("pragma% not allowed for object renaming", Arg2);
4348 -- User initialization is not allowed for imported object, but
4349 -- the object declaration may contain a default initialization,
4350 -- that will be discarded. Note that an explicit initialization
4351 -- only counts if it comes from source, otherwise it is simply
4352 -- the code generator making an implicit initialization explicit.
4354 elsif Present (Expression (Parent (Def_Id)))
4355 and then Comes_From_Source (Expression (Parent (Def_Id)))
4357 Error_Msg_Sloc := Sloc (Def_Id);
4359 ("no initialization allowed for declaration of& #",
4360 "\imported entities cannot be initialized (RM B.1(24))",
4364 Set_Imported (Def_Id);
4365 Process_Interface_Name (Def_Id, Arg3, Arg4);
4367 -- Note that we do not set Is_Public here. That's because we
4368 -- only want to set it if there is no address clause, and we
4369 -- don't know that yet, so we delay that processing till
4372 -- pragma Import completes deferred constants
4374 if Ekind (Def_Id) = E_Constant then
4375 Set_Has_Completion (Def_Id);
4378 -- It is not possible to import a constant of an unconstrained
4379 -- array type (e.g. string) because there is no simple way to
4380 -- write a meaningful subtype for it.
4382 if Is_Array_Type (Etype (Def_Id))
4383 and then not Is_Constrained (Etype (Def_Id))
4386 ("imported constant& must have a constrained subtype",
4391 elsif Is_Subprogram (Def_Id)
4392 or else Is_Generic_Subprogram (Def_Id)
4394 -- If the name is overloaded, pragma applies to all of the denoted
4395 -- entities in the same declarative part.
4398 while Present (Hom_Id) loop
4399 Def_Id := Get_Base_Subprogram (Hom_Id);
4401 -- Ignore inherited subprograms because the pragma will apply
4402 -- to the parent operation, which is the one called.
4404 if Is_Overloadable (Def_Id)
4405 and then Present (Alias (Def_Id))
4409 -- If it is not a subprogram, it must be in an outer scope and
4410 -- pragma does not apply.
4412 elsif not Is_Subprogram (Def_Id)
4413 and then not Is_Generic_Subprogram (Def_Id)
4417 -- The pragma does not apply to primitives of interfaces
4419 elsif Is_Dispatching_Operation (Def_Id)
4420 and then Present (Find_Dispatching_Type (Def_Id))
4421 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4425 -- Verify that the homonym is in the same declarative part (not
4426 -- just the same scope).
4428 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4429 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4434 Set_Imported (Def_Id);
4436 -- Reject an Import applied to an abstract subprogram
4438 if Is_Subprogram (Def_Id)
4439 and then Is_Abstract_Subprogram (Def_Id)
4441 Error_Msg_Sloc := Sloc (Def_Id);
4443 ("cannot import abstract subprogram& declared#",
4447 -- Special processing for Convention_Intrinsic
4449 if C = Convention_Intrinsic then
4451 -- Link_Name argument not allowed for intrinsic
4455 Set_Is_Intrinsic_Subprogram (Def_Id);
4457 -- If no external name is present, then check that this
4458 -- is a valid intrinsic subprogram. If an external name
4459 -- is present, then this is handled by the back end.
4462 Check_Intrinsic_Subprogram
4463 (Def_Id, Get_Pragma_Arg (Arg2));
4467 -- All interfaced procedures need an external symbol created
4468 -- for them since they are always referenced from another
4471 Set_Is_Public (Def_Id);
4473 -- Verify that the subprogram does not have a completion
4474 -- through a renaming declaration. For other completions the
4475 -- pragma appears as a too late representation.
4478 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4482 and then Nkind (Decl) = N_Subprogram_Declaration
4483 and then Present (Corresponding_Body (Decl))
4484 and then Nkind (Unit_Declaration_Node
4485 (Corresponding_Body (Decl))) =
4486 N_Subprogram_Renaming_Declaration
4488 Error_Msg_Sloc := Sloc (Def_Id);
4490 ("cannot import&, renaming already provided for " &
4491 "declaration #", N, Def_Id);
4495 Set_Has_Completion (Def_Id);
4496 Process_Interface_Name (Def_Id, Arg3, Arg4);
4499 if Is_Compilation_Unit (Hom_Id) then
4501 -- Its possible homonyms are not affected by the pragma.
4502 -- Such homonyms might be present in the context of other
4503 -- units being compiled.
4508 Hom_Id := Homonym (Hom_Id);
4512 -- When the convention is Java or CIL, we also allow Import to be
4513 -- given for packages, generic packages, exceptions, record
4514 -- components, and access to subprograms.
4516 elsif (C = Convention_Java or else C = Convention_CIL)
4518 (Is_Package_Or_Generic_Package (Def_Id)
4519 or else Ekind (Def_Id) = E_Exception
4520 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4521 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4523 Set_Imported (Def_Id);
4524 Set_Is_Public (Def_Id);
4525 Process_Interface_Name (Def_Id, Arg3, Arg4);
4527 -- Import a CPP class
4529 elsif Is_Record_Type (Def_Id)
4530 and then C = Convention_CPP
4532 -- Types treated as CPP classes must be declared limited (note:
4533 -- this used to be a warning but there is no real benefit to it
4534 -- since we did effectively intend to treat the type as limited
4537 if not Is_Limited_Type (Def_Id) then
4539 ("imported 'C'P'P type must be limited",
4540 Get_Pragma_Arg (Arg2));
4543 Set_Is_CPP_Class (Def_Id);
4545 -- Imported CPP types must not have discriminants (because C++
4546 -- classes do not have discriminants).
4548 if Has_Discriminants (Def_Id) then
4550 ("imported 'C'P'P type cannot have discriminants",
4551 First (Discriminant_Specifications
4552 (Declaration_Node (Def_Id))));
4555 -- Components of imported CPP types must not have default
4556 -- expressions because the constructor (if any) is on the
4560 Tdef : constant Node_Id :=
4561 Type_Definition (Declaration_Node (Def_Id));
4566 if Nkind (Tdef) = N_Record_Definition then
4567 Clist := Component_List (Tdef);
4570 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4571 Clist := Component_List (Record_Extension_Part (Tdef));
4574 if Present (Clist) then
4575 Comp := First (Component_Items (Clist));
4576 while Present (Comp) loop
4577 if Present (Expression (Comp)) then
4579 ("component of imported 'C'P'P type cannot have" &
4580 " default expression", Expression (Comp));
4588 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4590 Check_Arg_Count (3);
4591 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4593 Process_Import_Predefined_Type;
4597 ("second argument of pragma% must be object, subprogram" &
4598 " or incomplete type",
4602 -- If this pragma applies to a compilation unit, then the unit, which
4603 -- is a subprogram, does not require (or allow) a body. We also do
4604 -- not need to elaborate imported procedures.
4606 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4608 Cunit : constant Node_Id := Parent (Parent (N));
4610 Set_Body_Required (Cunit, False);
4613 end Process_Import_Or_Interface;
4615 --------------------
4616 -- Process_Inline --
4617 --------------------
4619 procedure Process_Inline (Active : Boolean) is
4626 Effective : Boolean := False;
4627 -- Set True if inline has some effect, i.e. if there is at least one
4628 -- subprogram set as inlined as a result of the use of the pragma.
4630 procedure Make_Inline (Subp : Entity_Id);
4631 -- Subp is the defining unit name of the subprogram declaration. Set
4632 -- the flag, as well as the flag in the corresponding body, if there
4635 procedure Set_Inline_Flags (Subp : Entity_Id);
4636 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4637 -- Has_Pragma_Inline_Always for the Inline_Always case.
4639 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4640 -- Returns True if it can be determined at this stage that inlining
4641 -- is not possible, for example if the body is available and contains
4642 -- exception handlers, we prevent inlining, since otherwise we can
4643 -- get undefined symbols at link time. This function also emits a
4644 -- warning if front-end inlining is enabled and the pragma appears
4647 -- ??? is business with link symbols still valid, or does it relate
4648 -- to front end ZCX which is being phased out ???
4650 ---------------------------
4651 -- Inlining_Not_Possible --
4652 ---------------------------
4654 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4655 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4659 if Nkind (Decl) = N_Subprogram_Body then
4660 Stats := Handled_Statement_Sequence (Decl);
4661 return Present (Exception_Handlers (Stats))
4662 or else Present (At_End_Proc (Stats));
4664 elsif Nkind (Decl) = N_Subprogram_Declaration
4665 and then Present (Corresponding_Body (Decl))
4667 if Front_End_Inlining
4668 and then Analyzed (Corresponding_Body (Decl))
4670 Error_Msg_N ("pragma appears too late, ignored?", N);
4673 -- If the subprogram is a renaming as body, the body is just a
4674 -- call to the renamed subprogram, and inlining is trivially
4678 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4679 N_Subprogram_Renaming_Declaration
4685 Handled_Statement_Sequence
4686 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4689 Present (Exception_Handlers (Stats))
4690 or else Present (At_End_Proc (Stats));
4694 -- If body is not available, assume the best, the check is
4695 -- performed again when compiling enclosing package bodies.
4699 end Inlining_Not_Possible;
4705 procedure Make_Inline (Subp : Entity_Id) is
4706 Kind : constant Entity_Kind := Ekind (Subp);
4707 Inner_Subp : Entity_Id := Subp;
4710 -- Ignore if bad type, avoid cascaded error
4712 if Etype (Subp) = Any_Type then
4716 -- Ignore if all inlining is suppressed
4718 elsif Suppress_All_Inlining then
4722 -- If inlining is not possible, for now do not treat as an error
4724 elsif Inlining_Not_Possible (Subp) then
4728 -- Here we have a candidate for inlining, but we must exclude
4729 -- derived operations. Otherwise we would end up trying to inline
4730 -- a phantom declaration, and the result would be to drag in a
4731 -- body which has no direct inlining associated with it. That
4732 -- would not only be inefficient but would also result in the
4733 -- backend doing cross-unit inlining in cases where it was
4734 -- definitely inappropriate to do so.
4736 -- However, a simple Comes_From_Source test is insufficient, since
4737 -- we do want to allow inlining of generic instances which also do
4738 -- not come from source. We also need to recognize specs generated
4739 -- by the front-end for bodies that carry the pragma. Finally,
4740 -- predefined operators do not come from source but are not
4741 -- inlineable either.
4743 elsif Is_Generic_Instance (Subp)
4744 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4748 elsif not Comes_From_Source (Subp)
4749 and then Scope (Subp) /= Standard_Standard
4755 -- The referenced entity must either be the enclosing entity, or
4756 -- an entity declared within the current open scope.
4758 if Present (Scope (Subp))
4759 and then Scope (Subp) /= Current_Scope
4760 and then Subp /= Current_Scope
4763 ("argument of% must be entity in current scope", Assoc);
4767 -- Processing for procedure, operator or function. If subprogram
4768 -- is aliased (as for an instance) indicate that the renamed
4769 -- entity (if declared in the same unit) is inlined.
4771 if Is_Subprogram (Subp) then
4772 Inner_Subp := Ultimate_Alias (Inner_Subp);
4774 if In_Same_Source_Unit (Subp, Inner_Subp) then
4775 Set_Inline_Flags (Inner_Subp);
4777 Decl := Parent (Parent (Inner_Subp));
4779 if Nkind (Decl) = N_Subprogram_Declaration
4780 and then Present (Corresponding_Body (Decl))
4782 Set_Inline_Flags (Corresponding_Body (Decl));
4784 elsif Is_Generic_Instance (Subp) then
4786 -- Indicate that the body needs to be created for
4787 -- inlining subsequent calls. The instantiation node
4788 -- follows the declaration of the wrapper package
4791 if Scope (Subp) /= Standard_Standard
4793 Need_Subprogram_Instance_Body
4794 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4800 -- Inline is a program unit pragma (RM 10.1.5) and cannot
4801 -- appear in a formal part to apply to a formal subprogram.
4802 -- Do not apply check within an instance or a formal package
4803 -- the test will have been applied to the original generic.
4805 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4806 and then List_Containing (Decl) = List_Containing (N)
4807 and then not In_Instance
4810 ("Inline cannot apply to a formal subprogram", N);
4816 -- For a generic subprogram set flag as well, for use at the point
4817 -- of instantiation, to determine whether the body should be
4820 elsif Is_Generic_Subprogram (Subp) then
4821 Set_Inline_Flags (Subp);
4824 -- Literals are by definition inlined
4826 elsif Kind = E_Enumeration_Literal then
4829 -- Anything else is an error
4833 ("expect subprogram name for pragma%", Assoc);
4837 ----------------------
4838 -- Set_Inline_Flags --
4839 ----------------------
4841 procedure Set_Inline_Flags (Subp : Entity_Id) is
4844 Set_Is_Inlined (Subp);
4847 if not Has_Pragma_Inline (Subp) then
4848 Set_Has_Pragma_Inline (Subp);
4852 if Prag_Id = Pragma_Inline_Always then
4853 Set_Has_Pragma_Inline_Always (Subp);
4855 end Set_Inline_Flags;
4857 -- Start of processing for Process_Inline
4860 Check_No_Identifiers;
4861 Check_At_Least_N_Arguments (1);
4864 Inline_Processing_Required := True;
4868 while Present (Assoc) loop
4869 Subp_Id := Get_Pragma_Arg (Assoc);
4873 if Is_Entity_Name (Subp_Id) then
4874 Subp := Entity (Subp_Id);
4876 if Subp = Any_Id then
4878 -- If previous error, avoid cascaded errors
4886 -- For the pragma case, climb homonym chain. This is
4887 -- what implements allowing the pragma in the renaming
4888 -- case, with the result applying to the ancestors.
4890 if not From_Aspect_Specification (N) then
4891 while Present (Homonym (Subp))
4892 and then Scope (Homonym (Subp)) = Current_Scope
4894 Make_Inline (Homonym (Subp));
4895 Subp := Homonym (Subp);
4903 ("inappropriate argument for pragma%", Assoc);
4906 and then Warn_On_Redundant_Constructs
4907 and then not Suppress_All_Inlining
4909 if Inlining_Not_Possible (Subp) then
4911 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4914 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4922 ----------------------------
4923 -- Process_Interface_Name --
4924 ----------------------------
4926 procedure Process_Interface_Name
4927 (Subprogram_Def : Entity_Id;
4933 String_Val : String_Id;
4935 procedure Check_Form_Of_Interface_Name
4937 Ext_Name_Case : Boolean);
4938 -- SN is a string literal node for an interface name. This routine
4939 -- performs some minimal checks that the name is reasonable. In
4940 -- particular that no spaces or other obviously incorrect characters
4941 -- appear. This is only a warning, since any characters are allowed.
4942 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4944 ----------------------------------
4945 -- Check_Form_Of_Interface_Name --
4946 ----------------------------------
4948 procedure Check_Form_Of_Interface_Name
4950 Ext_Name_Case : Boolean)
4952 S : constant String_Id := Strval (Expr_Value_S (SN));
4953 SL : constant Nat := String_Length (S);
4958 Error_Msg_N ("interface name cannot be null string", SN);
4961 for J in 1 .. SL loop
4962 C := Get_String_Char (S, J);
4964 -- Look for dubious character and issue unconditional warning.
4965 -- Definitely dubious if not in character range.
4967 if not In_Character_Range (C)
4969 -- For all cases except CLI target,
4970 -- commas, spaces and slashes are dubious (in CLI, we use
4971 -- commas and backslashes in external names to specify
4972 -- assembly version and public key, while slashes and spaces
4973 -- can be used in names to mark nested classes and
4976 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4977 and then (Get_Character (C) = ','
4979 Get_Character (C) = '\'))
4980 or else (VM_Target /= CLI_Target
4981 and then (Get_Character (C) = ' '
4983 Get_Character (C) = '/'))
4986 ("?interface name contains illegal character",
4987 Sloc (SN) + Source_Ptr (J));
4990 end Check_Form_Of_Interface_Name;
4992 -- Start of processing for Process_Interface_Name
4995 if No (Link_Arg) then
4996 if No (Ext_Arg) then
4997 if VM_Target = CLI_Target
4998 and then Ekind (Subprogram_Def) = E_Package
4999 and then Nkind (Parent (Subprogram_Def)) =
5000 N_Package_Specification
5001 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5006 (Generic_Parent (Parent (Subprogram_Def))));
5011 elsif Chars (Ext_Arg) = Name_Link_Name then
5013 Link_Nam := Expression (Ext_Arg);
5016 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5017 Ext_Nam := Expression (Ext_Arg);
5022 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5023 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5024 Ext_Nam := Expression (Ext_Arg);
5025 Link_Nam := Expression (Link_Arg);
5028 -- Check expressions for external name and link name are static
5030 if Present (Ext_Nam) then
5031 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5032 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5034 -- Verify that external name is not the name of a local entity,
5035 -- which would hide the imported one and could lead to run-time
5036 -- surprises. The problem can only arise for entities declared in
5037 -- a package body (otherwise the external name is fully qualified
5038 -- and will not conflict).
5046 if Prag_Id = Pragma_Import then
5047 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5049 E := Entity_Id (Get_Name_Table_Info (Nam));
5051 if Nam /= Chars (Subprogram_Def)
5052 and then Present (E)
5053 and then not Is_Overloadable (E)
5054 and then Is_Immediately_Visible (E)
5055 and then not Is_Imported (E)
5056 and then Ekind (Scope (E)) = E_Package
5059 while Present (Par) loop
5060 if Nkind (Par) = N_Package_Body then
5061 Error_Msg_Sloc := Sloc (E);
5063 ("imported entity is hidden by & declared#",
5068 Par := Parent (Par);
5075 if Present (Link_Nam) then
5076 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5077 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5080 -- If there is no link name, just set the external name
5082 if No (Link_Nam) then
5083 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5085 -- For the Link_Name case, the given literal is preceded by an
5086 -- asterisk, which indicates to GCC that the given name should be
5087 -- taken literally, and in particular that no prepending of
5088 -- underlines should occur, even in systems where this is the
5094 if VM_Target = No_VM then
5095 Store_String_Char (Get_Char_Code ('*'));
5098 String_Val := Strval (Expr_Value_S (Link_Nam));
5099 Store_String_Chars (String_Val);
5101 Make_String_Literal (Sloc (Link_Nam),
5102 Strval => End_String);
5105 -- Set the interface name. If the entity is a generic instance, use
5106 -- its alias, which is the callable entity.
5108 if Is_Generic_Instance (Subprogram_Def) then
5109 Set_Encoded_Interface_Name
5110 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5112 Set_Encoded_Interface_Name
5113 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5116 -- We allow duplicated export names in CIL/Java, as they are always
5117 -- enclosed in a namespace that differentiates them, and overloaded
5118 -- entities are supported by the VM.
5120 if Convention (Subprogram_Def) /= Convention_CIL
5122 Convention (Subprogram_Def) /= Convention_Java
5124 Check_Duplicated_Export_Name (Link_Nam);
5126 end Process_Interface_Name;
5128 -----------------------------------------
5129 -- Process_Interrupt_Or_Attach_Handler --
5130 -----------------------------------------
5132 procedure Process_Interrupt_Or_Attach_Handler is
5133 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5134 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5135 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5138 Set_Is_Interrupt_Handler (Handler_Proc);
5140 -- If the pragma is not associated with a handler procedure within a
5141 -- protected type, then it must be for a nonprotected procedure for
5142 -- the AAMP target, in which case we don't associate a representation
5143 -- item with the procedure's scope.
5145 if Ekind (Proc_Scope) = E_Protected_Type then
5146 if Prag_Id = Pragma_Interrupt_Handler
5148 Prag_Id = Pragma_Attach_Handler
5150 Record_Rep_Item (Proc_Scope, N);
5153 end Process_Interrupt_Or_Attach_Handler;
5155 --------------------------------------------------
5156 -- Process_Restrictions_Or_Restriction_Warnings --
5157 --------------------------------------------------
5159 -- Note: some of the simple identifier cases were handled in par-prag,
5160 -- but it is harmless (and more straightforward) to simply handle all
5161 -- cases here, even if it means we repeat a bit of work in some cases.
5163 procedure Process_Restrictions_Or_Restriction_Warnings
5167 R_Id : Restriction_Id;
5172 procedure Check_Unit_Name (N : Node_Id);
5173 -- Checks unit name parameter for No_Dependence. Returns if it has
5174 -- an appropriate form, otherwise raises pragma argument error.
5176 ---------------------
5177 -- Check_Unit_Name --
5178 ---------------------
5180 procedure Check_Unit_Name (N : Node_Id) is
5182 if Nkind (N) = N_Selected_Component then
5183 Check_Unit_Name (Prefix (N));
5184 Check_Unit_Name (Selector_Name (N));
5186 elsif Nkind (N) = N_Identifier then
5191 ("wrong form for unit name for No_Dependence", N);
5193 end Check_Unit_Name;
5195 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5198 -- Ignore all Restrictions pragma in CodePeer mode
5200 if CodePeer_Mode then
5204 Check_Ada_83_Warning;
5205 Check_At_Least_N_Arguments (1);
5206 Check_Valid_Configuration_Pragma;
5209 while Present (Arg) loop
5211 Expr := Get_Pragma_Arg (Arg);
5213 -- Case of no restriction identifier present
5215 if Id = No_Name then
5216 if Nkind (Expr) /= N_Identifier then
5218 ("invalid form for restriction", Arg);
5223 (Process_Restriction_Synonyms (Expr));
5225 if R_Id not in All_Boolean_Restrictions then
5226 Error_Msg_Name_1 := Pname;
5228 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5230 -- Check for possible misspelling
5232 for J in Restriction_Id loop
5234 Rnm : constant String := Restriction_Id'Image (J);
5237 Name_Buffer (1 .. Rnm'Length) := Rnm;
5238 Name_Len := Rnm'Length;
5239 Set_Casing (All_Lower_Case);
5241 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5243 (Identifier_Casing (Current_Source_File));
5244 Error_Msg_String (1 .. Rnm'Length) :=
5245 Name_Buffer (1 .. Name_Len);
5246 Error_Msg_Strlen := Rnm'Length;
5247 Error_Msg_N -- CODEFIX
5248 ("\possible misspelling of ""~""",
5249 Get_Pragma_Arg (Arg));
5258 if Implementation_Restriction (R_Id) then
5259 Check_Restriction (No_Implementation_Restrictions, Arg);
5262 -- If this is a warning, then set the warning unless we already
5263 -- have a real restriction active (we never want a warning to
5264 -- override a real restriction).
5267 if not Restriction_Active (R_Id) then
5268 Set_Restriction (R_Id, N);
5269 Restriction_Warnings (R_Id) := True;
5272 -- If real restriction case, then set it and make sure that the
5273 -- restriction warning flag is off, since a real restriction
5274 -- always overrides a warning.
5277 Set_Restriction (R_Id, N);
5278 Restriction_Warnings (R_Id) := False;
5281 -- Check for obsolescent restrictions in Ada 2005 mode
5284 and then Ada_Version >= Ada_2005
5285 and then (R_Id = No_Asynchronous_Control
5287 R_Id = No_Unchecked_Deallocation
5289 R_Id = No_Unchecked_Conversion)
5291 Check_Restriction (No_Obsolescent_Features, N);
5294 -- A very special case that must be processed here: pragma
5295 -- Restrictions (No_Exceptions) turns off all run-time
5296 -- checking. This is a bit dubious in terms of the formal
5297 -- language definition, but it is what is intended by RM
5298 -- H.4(12). Restriction_Warnings never affects generated code
5299 -- so this is done only in the real restriction case.
5301 if R_Id = No_Exceptions and then not Warn then
5302 Scope_Suppress := (others => True);
5305 -- Case of No_Dependence => unit-name. Note that the parser
5306 -- already made the necessary entry in the No_Dependence table.
5308 elsif Id = Name_No_Dependence then
5309 Check_Unit_Name (Expr);
5311 -- All other cases of restriction identifier present
5314 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5315 Analyze_And_Resolve (Expr, Any_Integer);
5317 if R_Id not in All_Parameter_Restrictions then
5319 ("invalid restriction parameter identifier", Arg);
5321 elsif not Is_OK_Static_Expression (Expr) then
5322 Flag_Non_Static_Expr
5323 ("value must be static expression!", Expr);
5326 elsif not Is_Integer_Type (Etype (Expr))
5327 or else Expr_Value (Expr) < 0
5330 ("value must be non-negative integer", Arg);
5333 -- Restriction pragma is active
5335 Val := Expr_Value (Expr);
5337 if not UI_Is_In_Int_Range (Val) then
5339 ("pragma ignored, value too large?", Arg);
5342 -- Warning case. If the real restriction is active, then we
5343 -- ignore the request, since warning never overrides a real
5344 -- restriction. Otherwise we set the proper warning. Note that
5345 -- this circuit sets the warning again if it is already set,
5346 -- which is what we want, since the constant may have changed.
5349 if not Restriction_Active (R_Id) then
5351 (R_Id, N, Integer (UI_To_Int (Val)));
5352 Restriction_Warnings (R_Id) := True;
5355 -- Real restriction case, set restriction and make sure warning
5356 -- flag is off since real restriction always overrides warning.
5359 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5360 Restriction_Warnings (R_Id) := False;
5366 end Process_Restrictions_Or_Restriction_Warnings;
5368 ---------------------------------
5369 -- Process_Suppress_Unsuppress --
5370 ---------------------------------
5372 -- Note: this procedure makes entries in the check suppress data
5373 -- structures managed by Sem. See spec of package Sem for full
5374 -- details on how we handle recording of check suppression.
5376 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5381 In_Package_Spec : constant Boolean :=
5382 Is_Package_Or_Generic_Package (Current_Scope)
5383 and then not In_Package_Body (Current_Scope);
5385 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5386 -- Used to suppress a single check on the given entity
5388 --------------------------------
5389 -- Suppress_Unsuppress_Echeck --
5390 --------------------------------
5392 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5394 Set_Checks_May_Be_Suppressed (E);
5396 if In_Package_Spec then
5397 Push_Global_Suppress_Stack_Entry
5400 Suppress => Suppress_Case);
5403 Push_Local_Suppress_Stack_Entry
5406 Suppress => Suppress_Case);
5409 -- If this is a first subtype, and the base type is distinct,
5410 -- then also set the suppress flags on the base type.
5412 if Is_First_Subtype (E)
5413 and then Etype (E) /= E
5415 Suppress_Unsuppress_Echeck (Etype (E), C);
5417 end Suppress_Unsuppress_Echeck;
5419 -- Start of processing for Process_Suppress_Unsuppress
5422 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5423 -- user code: we want to generate checks for analysis purposes, as
5424 -- set respectively by -gnatC and -gnatd.F
5426 if (CodePeer_Mode or Alfa_Mode)
5427 and then Comes_From_Source (N)
5432 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5433 -- declarative part or a package spec (RM 11.5(5)).
5435 if not Is_Configuration_Pragma then
5436 Check_Is_In_Decl_Part_Or_Package_Spec;
5439 Check_At_Least_N_Arguments (1);
5440 Check_At_Most_N_Arguments (2);
5441 Check_No_Identifier (Arg1);
5442 Check_Arg_Is_Identifier (Arg1);
5444 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5446 if C = No_Check_Id then
5448 ("argument of pragma% is not valid check name", Arg1);
5451 if not Suppress_Case
5452 and then (C = All_Checks or else C = Overflow_Check)
5454 Opt.Overflow_Checks_Unsuppressed := True;
5457 if Arg_Count = 1 then
5459 -- Make an entry in the local scope suppress table. This is the
5460 -- table that directly shows the current value of the scope
5461 -- suppress check for any check id value.
5463 if C = All_Checks then
5465 -- For All_Checks, we set all specific predefined checks with
5466 -- the exception of Elaboration_Check, which is handled
5467 -- specially because of not wanting All_Checks to have the
5468 -- effect of deactivating static elaboration order processing.
5470 for J in Scope_Suppress'Range loop
5471 if J /= Elaboration_Check then
5472 Scope_Suppress (J) := Suppress_Case;
5476 -- If not All_Checks, and predefined check, then set appropriate
5477 -- scope entry. Note that we will set Elaboration_Check if this
5478 -- is explicitly specified.
5480 elsif C in Predefined_Check_Id then
5481 Scope_Suppress (C) := Suppress_Case;
5484 -- Also make an entry in the Local_Entity_Suppress table
5486 Push_Local_Suppress_Stack_Entry
5489 Suppress => Suppress_Case);
5491 -- Case of two arguments present, where the check is suppressed for
5492 -- a specified entity (given as the second argument of the pragma)
5495 -- This is obsolescent in Ada 2005 mode
5497 if Ada_Version >= Ada_2005 then
5498 Check_Restriction (No_Obsolescent_Features, Arg2);
5501 Check_Optional_Identifier (Arg2, Name_On);
5502 E_Id := Get_Pragma_Arg (Arg2);
5505 if not Is_Entity_Name (E_Id) then
5507 ("second argument of pragma% must be entity name", Arg2);
5516 -- Enforce RM 11.5(7) which requires that for a pragma that
5517 -- appears within a package spec, the named entity must be
5518 -- within the package spec. We allow the package name itself
5519 -- to be mentioned since that makes sense, although it is not
5520 -- strictly allowed by 11.5(7).
5523 and then E /= Current_Scope
5524 and then Scope (E) /= Current_Scope
5527 ("entity in pragma% is not in package spec (RM 11.5(7))",
5531 -- Loop through homonyms. As noted below, in the case of a package
5532 -- spec, only homonyms within the package spec are considered.
5535 Suppress_Unsuppress_Echeck (E, C);
5537 if Is_Generic_Instance (E)
5538 and then Is_Subprogram (E)
5539 and then Present (Alias (E))
5541 Suppress_Unsuppress_Echeck (Alias (E), C);
5544 -- Move to next homonym if not aspect spec case
5546 exit when From_Aspect_Specification (N);
5550 -- If we are within a package specification, the pragma only
5551 -- applies to homonyms in the same scope.
5553 exit when In_Package_Spec
5554 and then Scope (E) /= Current_Scope;
5557 end Process_Suppress_Unsuppress;
5563 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5565 if Is_Imported (E) then
5567 ("cannot export entity& that was previously imported", Arg);
5569 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5571 ("cannot export entity& that has an address clause", Arg);
5574 Set_Is_Exported (E);
5576 -- Generate a reference for entity explicitly, because the
5577 -- identifier may be overloaded and name resolution will not
5580 Generate_Reference (E, Arg);
5582 -- Deal with exporting non-library level entity
5584 if not Is_Library_Level_Entity (E) then
5586 -- Not allowed at all for subprograms
5588 if Is_Subprogram (E) then
5589 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5591 -- Otherwise set public and statically allocated
5595 Set_Is_Statically_Allocated (E);
5597 -- Warn if the corresponding W flag is set and the pragma comes
5598 -- from source. The latter may not be true e.g. on VMS where we
5599 -- expand export pragmas for exception codes associated with
5600 -- imported or exported exceptions. We do not want to generate
5601 -- a warning for something that the user did not write.
5603 if Warn_On_Export_Import
5604 and then Comes_From_Source (Arg)
5607 ("?& has been made static as a result of Export", Arg, E);
5609 ("\this usage is non-standard and non-portable", Arg);
5614 if Warn_On_Export_Import and then Is_Type (E) then
5615 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5618 if Warn_On_Export_Import and Inside_A_Generic then
5620 ("all instances of& will have the same external name?", Arg, E);
5624 ----------------------------------------------
5625 -- Set_Extended_Import_Export_External_Name --
5626 ----------------------------------------------
5628 procedure Set_Extended_Import_Export_External_Name
5629 (Internal_Ent : Entity_Id;
5630 Arg_External : Node_Id)
5632 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5636 if No (Arg_External) then
5640 Check_Arg_Is_External_Name (Arg_External);
5642 if Nkind (Arg_External) = N_String_Literal then
5643 if String_Length (Strval (Arg_External)) = 0 then
5646 New_Name := Adjust_External_Name_Case (Arg_External);
5649 elsif Nkind (Arg_External) = N_Identifier then
5650 New_Name := Get_Default_External_Name (Arg_External);
5652 -- Check_Arg_Is_External_Name should let through only identifiers and
5653 -- string literals or static string expressions (which are folded to
5654 -- string literals).
5657 raise Program_Error;
5660 -- If we already have an external name set (by a prior normal Import
5661 -- or Export pragma), then the external names must match
5663 if Present (Interface_Name (Internal_Ent)) then
5664 Check_Matching_Internal_Names : declare
5665 S1 : constant String_Id := Strval (Old_Name);
5666 S2 : constant String_Id := Strval (New_Name);
5669 -- Called if names do not match
5675 procedure Mismatch is
5677 Error_Msg_Sloc := Sloc (Old_Name);
5679 ("external name does not match that given #",
5683 -- Start of processing for Check_Matching_Internal_Names
5686 if String_Length (S1) /= String_Length (S2) then
5690 for J in 1 .. String_Length (S1) loop
5691 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5696 end Check_Matching_Internal_Names;
5698 -- Otherwise set the given name
5701 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5702 Check_Duplicated_Export_Name (New_Name);
5704 end Set_Extended_Import_Export_External_Name;
5710 procedure Set_Imported (E : Entity_Id) is
5712 -- Error message if already imported or exported
5714 if Is_Exported (E) or else Is_Imported (E) then
5716 -- Error if being set Exported twice
5718 if Is_Exported (E) then
5719 Error_Msg_NE ("entity& was previously exported", N, E);
5721 -- OK if Import/Interface case
5723 elsif Import_Interface_Present (N) then
5726 -- Error if being set Imported twice
5729 Error_Msg_NE ("entity& was previously imported", N, E);
5732 Error_Msg_Name_1 := Pname;
5734 ("\(pragma% applies to all previous entities)", N);
5736 Error_Msg_Sloc := Sloc (E);
5737 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5739 -- Here if not previously imported or exported, OK to import
5742 Set_Is_Imported (E);
5744 -- If the entity is an object that is not at the library level,
5745 -- then it is statically allocated. We do not worry about objects
5746 -- with address clauses in this context since they are not really
5747 -- imported in the linker sense.
5750 and then not Is_Library_Level_Entity (E)
5751 and then No (Address_Clause (E))
5753 Set_Is_Statically_Allocated (E);
5760 -------------------------
5761 -- Set_Mechanism_Value --
5762 -------------------------
5764 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5765 -- analyzed, since it is semantic nonsense), so we get it in the exact
5766 -- form created by the parser.
5768 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5771 Mech_Name_Id : Name_Id;
5773 procedure Bad_Class;
5774 -- Signal bad descriptor class name
5776 procedure Bad_Mechanism;
5777 -- Signal bad mechanism name
5783 procedure Bad_Class is
5785 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5788 -------------------------
5789 -- Bad_Mechanism_Value --
5790 -------------------------
5792 procedure Bad_Mechanism is
5794 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5797 -- Start of processing for Set_Mechanism_Value
5800 if Mechanism (Ent) /= Default_Mechanism then
5802 ("mechanism for & has already been set", Mech_Name, Ent);
5805 -- MECHANISM_NAME ::= value | reference | descriptor |
5808 if Nkind (Mech_Name) = N_Identifier then
5809 if Chars (Mech_Name) = Name_Value then
5810 Set_Mechanism (Ent, By_Copy);
5813 elsif Chars (Mech_Name) = Name_Reference then
5814 Set_Mechanism (Ent, By_Reference);
5817 elsif Chars (Mech_Name) = Name_Descriptor then
5818 Check_VMS (Mech_Name);
5820 -- Descriptor => Short_Descriptor if pragma was given
5822 if Short_Descriptors then
5823 Set_Mechanism (Ent, By_Short_Descriptor);
5825 Set_Mechanism (Ent, By_Descriptor);
5830 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5831 Check_VMS (Mech_Name);
5832 Set_Mechanism (Ent, By_Short_Descriptor);
5835 elsif Chars (Mech_Name) = Name_Copy then
5837 ("bad mechanism name, Value assumed", Mech_Name);
5843 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5844 -- short_descriptor (CLASS_NAME)
5845 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5847 -- Note: this form is parsed as an indexed component
5849 elsif Nkind (Mech_Name) = N_Indexed_Component then
5850 Class := First (Expressions (Mech_Name));
5852 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5853 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5854 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5855 or else Present (Next (Class))
5859 Mech_Name_Id := Chars (Prefix (Mech_Name));
5861 -- Change Descriptor => Short_Descriptor if pragma was given
5863 if Mech_Name_Id = Name_Descriptor
5864 and then Short_Descriptors
5866 Mech_Name_Id := Name_Short_Descriptor;
5870 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5871 -- short_descriptor (Class => CLASS_NAME)
5872 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5874 -- Note: this form is parsed as a function call
5876 elsif Nkind (Mech_Name) = N_Function_Call then
5877 Param := First (Parameter_Associations (Mech_Name));
5879 if Nkind (Name (Mech_Name)) /= N_Identifier
5880 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5881 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5882 or else Present (Next (Param))
5883 or else No (Selector_Name (Param))
5884 or else Chars (Selector_Name (Param)) /= Name_Class
5888 Class := Explicit_Actual_Parameter (Param);
5889 Mech_Name_Id := Chars (Name (Mech_Name));
5896 -- Fall through here with Class set to descriptor class name
5898 Check_VMS (Mech_Name);
5900 if Nkind (Class) /= N_Identifier then
5903 elsif Mech_Name_Id = Name_Descriptor
5904 and then Chars (Class) = Name_UBS
5906 Set_Mechanism (Ent, By_Descriptor_UBS);
5908 elsif Mech_Name_Id = Name_Descriptor
5909 and then Chars (Class) = Name_UBSB
5911 Set_Mechanism (Ent, By_Descriptor_UBSB);
5913 elsif Mech_Name_Id = Name_Descriptor
5914 and then Chars (Class) = Name_UBA
5916 Set_Mechanism (Ent, By_Descriptor_UBA);
5918 elsif Mech_Name_Id = Name_Descriptor
5919 and then Chars (Class) = Name_S
5921 Set_Mechanism (Ent, By_Descriptor_S);
5923 elsif Mech_Name_Id = Name_Descriptor
5924 and then Chars (Class) = Name_SB
5926 Set_Mechanism (Ent, By_Descriptor_SB);
5928 elsif Mech_Name_Id = Name_Descriptor
5929 and then Chars (Class) = Name_A
5931 Set_Mechanism (Ent, By_Descriptor_A);
5933 elsif Mech_Name_Id = Name_Descriptor
5934 and then Chars (Class) = Name_NCA
5936 Set_Mechanism (Ent, By_Descriptor_NCA);
5938 elsif Mech_Name_Id = Name_Short_Descriptor
5939 and then Chars (Class) = Name_UBS
5941 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5943 elsif Mech_Name_Id = Name_Short_Descriptor
5944 and then Chars (Class) = Name_UBSB
5946 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5948 elsif Mech_Name_Id = Name_Short_Descriptor
5949 and then Chars (Class) = Name_UBA
5951 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5953 elsif Mech_Name_Id = Name_Short_Descriptor
5954 and then Chars (Class) = Name_S
5956 Set_Mechanism (Ent, By_Short_Descriptor_S);
5958 elsif Mech_Name_Id = Name_Short_Descriptor
5959 and then Chars (Class) = Name_SB
5961 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5963 elsif Mech_Name_Id = Name_Short_Descriptor
5964 and then Chars (Class) = Name_A
5966 Set_Mechanism (Ent, By_Short_Descriptor_A);
5968 elsif Mech_Name_Id = Name_Short_Descriptor
5969 and then Chars (Class) = Name_NCA
5971 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5976 end Set_Mechanism_Value;
5978 ---------------------------
5979 -- Set_Ravenscar_Profile --
5980 ---------------------------
5982 -- The tasks to be done here are
5984 -- Set required policies
5986 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5987 -- pragma Locking_Policy (Ceiling_Locking)
5989 -- Set Detect_Blocking mode
5991 -- Set required restrictions (see System.Rident for detailed list)
5993 -- Set the No_Dependence rules
5994 -- No_Dependence => Ada.Asynchronous_Task_Control
5995 -- No_Dependence => Ada.Calendar
5996 -- No_Dependence => Ada.Execution_Time.Group_Budget
5997 -- No_Dependence => Ada.Execution_Time.Timers
5998 -- No_Dependence => Ada.Task_Attributes
5999 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6001 procedure Set_Ravenscar_Profile (N : Node_Id) is
6002 Prefix_Entity : Entity_Id;
6003 Selector_Entity : Entity_Id;
6004 Prefix_Node : Node_Id;
6008 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6010 if Task_Dispatching_Policy /= ' '
6011 and then Task_Dispatching_Policy /= 'F'
6013 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6014 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6016 -- Set the FIFO_Within_Priorities policy, but always preserve
6017 -- System_Location since we like the error message with the run time
6021 Task_Dispatching_Policy := 'F';
6023 if Task_Dispatching_Policy_Sloc /= System_Location then
6024 Task_Dispatching_Policy_Sloc := Loc;
6028 -- pragma Locking_Policy (Ceiling_Locking)
6030 if Locking_Policy /= ' '
6031 and then Locking_Policy /= 'C'
6033 Error_Msg_Sloc := Locking_Policy_Sloc;
6034 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6036 -- Set the Ceiling_Locking policy, but preserve System_Location since
6037 -- we like the error message with the run time name.
6040 Locking_Policy := 'C';
6042 if Locking_Policy_Sloc /= System_Location then
6043 Locking_Policy_Sloc := Loc;
6047 -- pragma Detect_Blocking
6049 Detect_Blocking := True;
6051 -- Set the corresponding restrictions
6053 Set_Profile_Restrictions
6054 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6056 -- Set the No_Dependence restrictions
6058 -- The following No_Dependence restrictions:
6059 -- No_Dependence => Ada.Asynchronous_Task_Control
6060 -- No_Dependence => Ada.Calendar
6061 -- No_Dependence => Ada.Task_Attributes
6062 -- are already set by previous call to Set_Profile_Restrictions.
6064 -- Set the following restrictions which were added to Ada 2005:
6065 -- No_Dependence => Ada.Execution_Time.Group_Budget
6066 -- No_Dependence => Ada.Execution_Time.Timers
6068 if Ada_Version >= Ada_2005 then
6069 Name_Buffer (1 .. 3) := "ada";
6072 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6074 Name_Buffer (1 .. 14) := "execution_time";
6077 Selector_Entity := Make_Identifier (Loc, Name_Find);
6080 Make_Selected_Component
6082 Prefix => Prefix_Entity,
6083 Selector_Name => Selector_Entity);
6085 Name_Buffer (1 .. 13) := "group_budgets";
6088 Selector_Entity := Make_Identifier (Loc, Name_Find);
6091 Make_Selected_Component
6093 Prefix => Prefix_Node,
6094 Selector_Name => Selector_Entity);
6096 Set_Restriction_No_Dependence
6098 Warn => Treat_Restrictions_As_Warnings,
6099 Profile => Ravenscar);
6101 Name_Buffer (1 .. 6) := "timers";
6104 Selector_Entity := Make_Identifier (Loc, Name_Find);
6107 Make_Selected_Component
6109 Prefix => Prefix_Node,
6110 Selector_Name => Selector_Entity);
6112 Set_Restriction_No_Dependence
6114 Warn => Treat_Restrictions_As_Warnings,
6115 Profile => Ravenscar);
6118 -- Set the following restrictions which was added to Ada 2012 (see
6120 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6122 if Ada_Version >= Ada_2012 then
6123 Name_Buffer (1 .. 6) := "system";
6126 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6128 Name_Buffer (1 .. 15) := "multiprocessors";
6131 Selector_Entity := Make_Identifier (Loc, Name_Find);
6134 Make_Selected_Component
6136 Prefix => Prefix_Entity,
6137 Selector_Name => Selector_Entity);
6139 Name_Buffer (1 .. 19) := "dispatching_domains";
6142 Selector_Entity := Make_Identifier (Loc, Name_Find);
6145 Make_Selected_Component
6147 Prefix => Prefix_Node,
6148 Selector_Name => Selector_Entity);
6150 Set_Restriction_No_Dependence
6152 Warn => Treat_Restrictions_As_Warnings,
6153 Profile => Ravenscar);
6155 end Set_Ravenscar_Profile;
6157 -- Start of processing for Analyze_Pragma
6160 -- The following code is a defense against recursion. Not clear that
6161 -- this can happen legitimately, but perhaps some error situations
6162 -- can cause it, and we did see this recursion during testing.
6164 if Analyzed (N) then
6167 Set_Analyzed (N, True);
6170 -- Deal with unrecognized pragma
6172 if not Is_Pragma_Name (Pname) then
6173 if Warn_On_Unrecognized_Pragma then
6174 Error_Msg_Name_1 := Pname;
6175 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6177 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6178 if Is_Bad_Spelling_Of (Pname, PN) then
6179 Error_Msg_Name_1 := PN;
6180 Error_Msg_N -- CODEFIX
6181 ("\?possible misspelling of %!", Pragma_Identifier (N));
6190 -- Here to start processing for recognized pragma
6192 Prag_Id := Get_Pragma_Id (Pname);
6202 if Present (Pragma_Argument_Associations (N)) then
6203 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6204 Arg1 := First (Pragma_Argument_Associations (N));
6206 if Present (Arg1) then
6207 Arg2 := Next (Arg1);
6209 if Present (Arg2) then
6210 Arg3 := Next (Arg2);
6212 if Present (Arg3) then
6213 Arg4 := Next (Arg3);
6219 -- An enumeration type defines the pragmas that are supported by the
6220 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6221 -- into the corresponding enumeration value for the following case.
6229 -- pragma Abort_Defer;
6231 when Pragma_Abort_Defer =>
6233 Check_Arg_Count (0);
6235 -- The only required semantic processing is to check the
6236 -- placement. This pragma must appear at the start of the
6237 -- statement sequence of a handled sequence of statements.
6239 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6240 or else N /= First (Statements (Parent (N)))
6251 -- Note: this pragma also has some specific processing in Par.Prag
6252 -- because we want to set the Ada version mode during parsing.
6254 when Pragma_Ada_83 =>
6256 Check_Arg_Count (0);
6258 -- We really should check unconditionally for proper configuration
6259 -- pragma placement, since we really don't want mixed Ada modes
6260 -- within a single unit, and the GNAT reference manual has always
6261 -- said this was a configuration pragma, but we did not check and
6262 -- are hesitant to add the check now.
6264 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6265 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6266 -- or Ada 2012 mode.
6268 if Ada_Version >= Ada_2005 then
6269 Check_Valid_Configuration_Pragma;
6272 -- Now set Ada 83 mode
6274 Ada_Version := Ada_83;
6275 Ada_Version_Explicit := Ada_Version;
6283 -- Note: this pragma also has some specific processing in Par.Prag
6284 -- because we want to set the Ada 83 version mode during parsing.
6286 when Pragma_Ada_95 =>
6288 Check_Arg_Count (0);
6290 -- We really should check unconditionally for proper configuration
6291 -- pragma placement, since we really don't want mixed Ada modes
6292 -- within a single unit, and the GNAT reference manual has always
6293 -- said this was a configuration pragma, but we did not check and
6294 -- are hesitant to add the check now.
6296 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6297 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6299 if Ada_Version >= Ada_2005 then
6300 Check_Valid_Configuration_Pragma;
6303 -- Now set Ada 95 mode
6305 Ada_Version := Ada_95;
6306 Ada_Version_Explicit := Ada_Version;
6308 ---------------------
6309 -- Ada_05/Ada_2005 --
6310 ---------------------
6313 -- pragma Ada_05 (LOCAL_NAME);
6316 -- pragma Ada_2005 (LOCAL_NAME):
6318 -- Note: these pragmas also have some specific processing in Par.Prag
6319 -- because we want to set the Ada 2005 version mode during parsing.
6321 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6327 if Arg_Count = 1 then
6328 Check_Arg_Is_Local_Name (Arg1);
6329 E_Id := Get_Pragma_Arg (Arg1);
6331 if Etype (E_Id) = Any_Type then
6335 Set_Is_Ada_2005_Only (Entity (E_Id));
6338 Check_Arg_Count (0);
6340 -- For Ada_2005 we unconditionally enforce the documented
6341 -- configuration pragma placement, since we do not want to
6342 -- tolerate mixed modes in a unit involving Ada 2005. That
6343 -- would cause real difficulties for those cases where there
6344 -- are incompatibilities between Ada 95 and Ada 2005.
6346 Check_Valid_Configuration_Pragma;
6348 -- Now set appropriate Ada mode
6350 Ada_Version := Ada_2005;
6351 Ada_Version_Explicit := Ada_2005;
6355 ---------------------
6356 -- Ada_12/Ada_2012 --
6357 ---------------------
6360 -- pragma Ada_12 (LOCAL_NAME);
6363 -- pragma Ada_2012 (LOCAL_NAME):
6365 -- Note: these pragmas also have some specific processing in Par.Prag
6366 -- because we want to set the Ada 2012 version mode during parsing.
6368 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6374 if Arg_Count = 1 then
6375 Check_Arg_Is_Local_Name (Arg1);
6376 E_Id := Get_Pragma_Arg (Arg1);
6378 if Etype (E_Id) = Any_Type then
6382 Set_Is_Ada_2012_Only (Entity (E_Id));
6385 Check_Arg_Count (0);
6387 -- For Ada_2012 we unconditionally enforce the documented
6388 -- configuration pragma placement, since we do not want to
6389 -- tolerate mixed modes in a unit involving Ada 2012. That
6390 -- would cause real difficulties for those cases where there
6391 -- are incompatibilities between Ada 95 and Ada 2012. We could
6392 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6394 Check_Valid_Configuration_Pragma;
6396 -- Now set appropriate Ada mode
6398 Ada_Version := Ada_2012;
6399 Ada_Version_Explicit := Ada_2012;
6403 ----------------------
6404 -- All_Calls_Remote --
6405 ----------------------
6407 -- pragma All_Calls_Remote [(library_package_NAME)];
6409 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6410 Lib_Entity : Entity_Id;
6413 Check_Ada_83_Warning;
6414 Check_Valid_Library_Unit_Pragma;
6416 if Nkind (N) = N_Null_Statement then
6420 Lib_Entity := Find_Lib_Unit_Name;
6422 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6424 if Present (Lib_Entity)
6425 and then not Debug_Flag_U
6427 if not Is_Remote_Call_Interface (Lib_Entity) then
6428 Error_Pragma ("pragma% only apply to rci unit");
6430 -- Set flag for entity of the library unit
6433 Set_Has_All_Calls_Remote (Lib_Entity);
6437 end All_Calls_Remote;
6443 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6444 -- ARG ::= NAME | EXPRESSION
6446 -- The first two arguments are by convention intended to refer to an
6447 -- external tool and a tool-specific function. These arguments are
6450 when Pragma_Annotate => Annotate : declare
6456 Check_At_Least_N_Arguments (1);
6457 Check_Arg_Is_Identifier (Arg1);
6458 Check_No_Identifiers;
6461 -- Second parameter is optional, it is never analyzed
6466 -- Here if we have a second parameter
6469 -- Second parameter must be identifier
6471 Check_Arg_Is_Identifier (Arg2);
6473 -- Process remaining parameters if any
6476 while Present (Arg) loop
6477 Exp := Get_Pragma_Arg (Arg);
6480 if Is_Entity_Name (Exp) then
6483 -- For string literals, we assume Standard_String as the
6484 -- type, unless the string contains wide or wide_wide
6487 elsif Nkind (Exp) = N_String_Literal then
6488 if Has_Wide_Wide_Character (Exp) then
6489 Resolve (Exp, Standard_Wide_Wide_String);
6490 elsif Has_Wide_Character (Exp) then
6491 Resolve (Exp, Standard_Wide_String);
6493 Resolve (Exp, Standard_String);
6496 elsif Is_Overloaded (Exp) then
6498 ("ambiguous argument for pragma%", Exp);
6513 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6514 -- [, [Message =>] Static_String_EXPRESSION]);
6516 when Pragma_Assert => Assert : declare
6522 Check_At_Least_N_Arguments (1);
6523 Check_At_Most_N_Arguments (2);
6524 Check_Arg_Order ((Name_Check, Name_Message));
6525 Check_Optional_Identifier (Arg1, Name_Check);
6527 -- We treat pragma Assert as equivalent to:
6529 -- pragma Check (Assertion, condition [, msg]);
6531 -- So rewrite pragma in this manner, and analyze the result
6533 Expr := Get_Pragma_Arg (Arg1);
6535 Make_Pragma_Argument_Association (Loc,
6536 Expression => Make_Identifier (Loc, Name_Assertion)),
6538 Make_Pragma_Argument_Association (Sloc (Expr),
6539 Expression => Expr));
6541 if Arg_Count > 1 then
6542 Check_Optional_Identifier (Arg2, Name_Message);
6543 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6544 Append_To (Newa, Relocate_Node (Arg2));
6549 Chars => Name_Check,
6550 Pragma_Argument_Associations => Newa));
6554 ----------------------
6555 -- Assertion_Policy --
6556 ----------------------
6558 -- pragma Assertion_Policy (Check | Disable |Ignore)
6560 when Pragma_Assertion_Policy => Assertion_Policy : declare
6565 Check_Valid_Configuration_Pragma;
6566 Check_Arg_Count (1);
6567 Check_No_Identifiers;
6568 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6570 -- We treat pragma Assertion_Policy as equivalent to:
6572 -- pragma Check_Policy (Assertion, policy)
6574 -- So rewrite the pragma in that manner and link on to the chain
6575 -- of Check_Policy pragmas, marking the pragma as analyzed.
6577 Policy := Get_Pragma_Arg (Arg1);
6581 Chars => Name_Check_Policy,
6583 Pragma_Argument_Associations => New_List (
6584 Make_Pragma_Argument_Association (Loc,
6585 Expression => Make_Identifier (Loc, Name_Assertion)),
6587 Make_Pragma_Argument_Association (Loc,
6589 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6592 Set_Next_Pragma (N, Opt.Check_Policy_List);
6593 Opt.Check_Policy_List := N;
6594 end Assertion_Policy;
6596 ------------------------------
6597 -- Assume_No_Invalid_Values --
6598 ------------------------------
6600 -- pragma Assume_No_Invalid_Values (On | Off);
6602 when Pragma_Assume_No_Invalid_Values =>
6604 Check_Valid_Configuration_Pragma;
6605 Check_Arg_Count (1);
6606 Check_No_Identifiers;
6607 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6609 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6610 Assume_No_Invalid_Values := True;
6612 Assume_No_Invalid_Values := False;
6619 -- pragma AST_Entry (entry_IDENTIFIER);
6621 when Pragma_AST_Entry => AST_Entry : declare
6627 Check_Arg_Count (1);
6628 Check_No_Identifiers;
6629 Check_Arg_Is_Local_Name (Arg1);
6630 Ent := Entity (Get_Pragma_Arg (Arg1));
6632 -- Note: the implementation of the AST_Entry pragma could handle
6633 -- the entry family case fine, but for now we are consistent with
6634 -- the DEC rules, and do not allow the pragma, which of course
6635 -- has the effect of also forbidding the attribute.
6637 if Ekind (Ent) /= E_Entry then
6639 ("pragma% argument must be simple entry name", Arg1);
6641 elsif Is_AST_Entry (Ent) then
6643 ("duplicate % pragma for entry", Arg1);
6645 elsif Has_Homonym (Ent) then
6647 ("pragma% argument cannot specify overloaded entry", Arg1);
6651 FF : constant Entity_Id := First_Formal (Ent);
6654 if Present (FF) then
6655 if Present (Next_Formal (FF)) then
6657 ("entry for pragma% can have only one argument",
6660 elsif Parameter_Mode (FF) /= E_In_Parameter then
6662 ("entry parameter for pragma% must have mode IN",
6668 Set_Is_AST_Entry (Ent);
6676 -- pragma Asynchronous (LOCAL_NAME);
6678 when Pragma_Asynchronous => Asynchronous : declare
6686 procedure Process_Async_Pragma;
6687 -- Common processing for procedure and access-to-procedure case
6689 --------------------------
6690 -- Process_Async_Pragma --
6691 --------------------------
6693 procedure Process_Async_Pragma is
6696 Set_Is_Asynchronous (Nm);
6700 -- The formals should be of mode IN (RM E.4.1(6))
6703 while Present (S) loop
6704 Formal := Defining_Identifier (S);
6706 if Nkind (Formal) = N_Defining_Identifier
6707 and then Ekind (Formal) /= E_In_Parameter
6710 ("pragma% procedure can only have IN parameter",
6717 Set_Is_Asynchronous (Nm);
6718 end Process_Async_Pragma;
6720 -- Start of processing for pragma Asynchronous
6723 Check_Ada_83_Warning;
6724 Check_No_Identifiers;
6725 Check_Arg_Count (1);
6726 Check_Arg_Is_Local_Name (Arg1);
6728 if Debug_Flag_U then
6732 C_Ent := Cunit_Entity (Current_Sem_Unit);
6733 Analyze (Get_Pragma_Arg (Arg1));
6734 Nm := Entity (Get_Pragma_Arg (Arg1));
6736 if not Is_Remote_Call_Interface (C_Ent)
6737 and then not Is_Remote_Types (C_Ent)
6739 -- This pragma should only appear in an RCI or Remote Types
6740 -- unit (RM E.4.1(4)).
6743 ("pragma% not in Remote_Call_Interface or " &
6744 "Remote_Types unit");
6747 if Ekind (Nm) = E_Procedure
6748 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6750 if not Is_Remote_Call_Interface (Nm) then
6752 ("pragma% cannot be applied on non-remote procedure",
6756 L := Parameter_Specifications (Parent (Nm));
6757 Process_Async_Pragma;
6760 elsif Ekind (Nm) = E_Function then
6762 ("pragma% cannot be applied to function", Arg1);
6764 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6765 if Is_Record_Type (Nm) then
6767 -- A record type that is the Equivalent_Type for a remote
6768 -- access-to-subprogram type.
6770 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6773 -- A non-expanded RAS type (distribution is not enabled)
6775 N := Declaration_Node (Nm);
6778 if Nkind (N) = N_Full_Type_Declaration
6779 and then Nkind (Type_Definition (N)) =
6780 N_Access_Procedure_Definition
6782 L := Parameter_Specifications (Type_Definition (N));
6783 Process_Async_Pragma;
6785 if Is_Asynchronous (Nm)
6786 and then Expander_Active
6787 and then Get_PCS_Name /= Name_No_DSA
6789 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6794 ("pragma% cannot reference access-to-function type",
6798 -- Only other possibility is Access-to-class-wide type
6800 elsif Is_Access_Type (Nm)
6801 and then Is_Class_Wide_Type (Designated_Type (Nm))
6803 Check_First_Subtype (Arg1);
6804 Set_Is_Asynchronous (Nm);
6805 if Expander_Active then
6806 RACW_Type_Is_Asynchronous (Nm);
6810 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6818 -- pragma Atomic (LOCAL_NAME);
6820 when Pragma_Atomic =>
6821 Process_Atomic_Shared_Volatile;
6823 -----------------------
6824 -- Atomic_Components --
6825 -----------------------
6827 -- pragma Atomic_Components (array_LOCAL_NAME);
6829 -- This processing is shared by Volatile_Components
6831 when Pragma_Atomic_Components |
6832 Pragma_Volatile_Components =>
6834 Atomic_Components : declare
6841 Check_Ada_83_Warning;
6842 Check_No_Identifiers;
6843 Check_Arg_Count (1);
6844 Check_Arg_Is_Local_Name (Arg1);
6845 E_Id := Get_Pragma_Arg (Arg1);
6847 if Etype (E_Id) = Any_Type then
6853 Check_Duplicate_Pragma (E);
6855 if Rep_Item_Too_Early (E, N)
6857 Rep_Item_Too_Late (E, N)
6862 D := Declaration_Node (E);
6865 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6867 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6868 and then Nkind (D) = N_Object_Declaration
6869 and then Nkind (Object_Definition (D)) =
6870 N_Constrained_Array_Definition)
6872 -- The flag is set on the object, or on the base type
6874 if Nkind (D) /= N_Object_Declaration then
6878 Set_Has_Volatile_Components (E);
6880 if Prag_Id = Pragma_Atomic_Components then
6881 Set_Has_Atomic_Components (E);
6885 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6887 end Atomic_Components;
6889 --------------------
6890 -- Attach_Handler --
6891 --------------------
6893 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6895 when Pragma_Attach_Handler =>
6896 Check_Ada_83_Warning;
6897 Check_No_Identifiers;
6898 Check_Arg_Count (2);
6900 if No_Run_Time_Mode then
6901 Error_Msg_CRT ("Attach_Handler pragma", N);
6903 Check_Interrupt_Or_Attach_Handler;
6905 -- The expression that designates the attribute may depend on a
6906 -- discriminant, and is therefore a per- object expression, to
6907 -- be expanded in the init proc. If expansion is enabled, then
6908 -- perform semantic checks on a copy only.
6910 if Expander_Active then
6912 Temp : constant Node_Id :=
6913 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6915 Set_Parent (Temp, N);
6916 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6920 Analyze (Get_Pragma_Arg (Arg2));
6921 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6924 Process_Interrupt_Or_Attach_Handler;
6927 --------------------
6928 -- C_Pass_By_Copy --
6929 --------------------
6931 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6933 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6939 Check_Valid_Configuration_Pragma;
6940 Check_Arg_Count (1);
6941 Check_Optional_Identifier (Arg1, "max_size");
6943 Arg := Get_Pragma_Arg (Arg1);
6944 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6946 Val := Expr_Value (Arg);
6950 ("maximum size for pragma% must be positive", Arg1);
6952 elsif UI_Is_In_Int_Range (Val) then
6953 Default_C_Record_Mechanism := UI_To_Int (Val);
6955 -- If a giant value is given, Int'Last will do well enough.
6956 -- If sometime someone complains that a record larger than
6957 -- two gigabytes is not copied, we will worry about it then!
6960 Default_C_Record_Mechanism := Mechanism_Type'Last;
6968 -- pragma Check ([Name =>] IDENTIFIER,
6969 -- [Check =>] Boolean_EXPRESSION
6970 -- [,[Message =>] String_EXPRESSION]);
6972 when Pragma_Check => Check : declare
6977 -- Set True if category of assertions referenced by Name enabled
6981 Check_At_Least_N_Arguments (2);
6982 Check_At_Most_N_Arguments (3);
6983 Check_Optional_Identifier (Arg1, Name_Name);
6984 Check_Optional_Identifier (Arg2, Name_Check);
6986 if Arg_Count = 3 then
6987 Check_Optional_Identifier (Arg3, Name_Message);
6988 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6991 Check_Arg_Is_Identifier (Arg1);
6993 -- Completely ignore if disabled
6995 if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
6996 Rewrite (N, Make_Null_Statement (Loc));
7001 -- Indicate if pragma is enabled. The Original_Node reference here
7002 -- is to deal with pragma Assert rewritten as a Check pragma.
7004 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
7007 Set_SCO_Pragma_Enabled (Loc);
7010 -- If expansion is active and the check is not enabled then we
7011 -- rewrite the Check as:
7013 -- if False and then condition then
7017 -- The reason we do this rewriting during semantic analysis rather
7018 -- than as part of normal expansion is that we cannot analyze and
7019 -- expand the code for the boolean expression directly, or it may
7020 -- cause insertion of actions that would escape the attempt to
7021 -- suppress the check code.
7023 -- Note that the Sloc for the if statement corresponds to the
7024 -- argument condition, not the pragma itself. The reason for this
7025 -- is that we may generate a warning if the condition is False at
7026 -- compile time, and we do not want to delete this warning when we
7027 -- delete the if statement.
7029 Expr := Get_Pragma_Arg (Arg2);
7031 if Expander_Active and then not Check_On then
7032 Eloc := Sloc (Expr);
7035 Make_If_Statement (Eloc,
7037 Make_And_Then (Eloc,
7038 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7039 Right_Opnd => Expr),
7040 Then_Statements => New_List (
7041 Make_Null_Statement (Eloc))));
7048 Analyze_And_Resolve (Expr, Any_Boolean);
7056 -- pragma Check_Name (check_IDENTIFIER);
7058 when Pragma_Check_Name =>
7059 Check_No_Identifiers;
7061 Check_Valid_Configuration_Pragma;
7062 Check_Arg_Count (1);
7063 Check_Arg_Is_Identifier (Arg1);
7066 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7069 for J in Check_Names.First .. Check_Names.Last loop
7070 if Check_Names.Table (J) = Nam then
7075 Check_Names.Append (Nam);
7082 -- pragma Check_Policy (
7083 -- [Name =>] IDENTIFIER,
7084 -- [Policy =>] POLICY_IDENTIFIER);
7086 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7088 -- Note: this is a configuration pragma, but it is allowed to appear
7091 when Pragma_Check_Policy =>
7093 Check_Arg_Count (2);
7094 Check_Optional_Identifier (Arg1, Name_Name);
7095 Check_Optional_Identifier (Arg2, Name_Policy);
7097 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7099 -- A Check_Policy pragma can appear either as a configuration
7100 -- pragma, or in a declarative part or a package spec (see RM
7101 -- 11.5(5) for rules for Suppress/Unsuppress which are also
7102 -- followed for Check_Policy).
7104 if not Is_Configuration_Pragma then
7105 Check_Is_In_Decl_Part_Or_Package_Spec;
7108 Set_Next_Pragma (N, Opt.Check_Policy_List);
7109 Opt.Check_Policy_List := N;
7111 ---------------------
7112 -- CIL_Constructor --
7113 ---------------------
7115 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7117 -- Processing for this pragma is shared with Java_Constructor
7123 -- pragma Comment (static_string_EXPRESSION)
7125 -- Processing for pragma Comment shares the circuitry for pragma
7126 -- Ident. The only differences are that Ident enforces a limit of 31
7127 -- characters on its argument, and also enforces limitations on
7128 -- placement for DEC compatibility. Pragma Comment shares neither of
7129 -- these restrictions.
7135 -- pragma Common_Object (
7136 -- [Internal =>] LOCAL_NAME
7137 -- [, [External =>] EXTERNAL_SYMBOL]
7138 -- [, [Size =>] EXTERNAL_SYMBOL]);
7140 -- Processing for this pragma is shared with Psect_Object
7142 ------------------------
7143 -- Compile_Time_Error --
7144 ------------------------
7146 -- pragma Compile_Time_Error
7147 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7149 when Pragma_Compile_Time_Error =>
7151 Process_Compile_Time_Warning_Or_Error;
7153 --------------------------
7154 -- Compile_Time_Warning --
7155 --------------------------
7157 -- pragma Compile_Time_Warning
7158 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7160 when Pragma_Compile_Time_Warning =>
7162 Process_Compile_Time_Warning_Or_Error;
7168 when Pragma_Compiler_Unit =>
7170 Check_Arg_Count (0);
7171 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7173 -----------------------------
7174 -- Complete_Representation --
7175 -----------------------------
7177 -- pragma Complete_Representation;
7179 when Pragma_Complete_Representation =>
7181 Check_Arg_Count (0);
7183 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7185 ("pragma & must appear within record representation clause");
7188 ----------------------------
7189 -- Complex_Representation --
7190 ----------------------------
7192 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7194 when Pragma_Complex_Representation => Complex_Representation : declare
7201 Check_Arg_Count (1);
7202 Check_Optional_Identifier (Arg1, Name_Entity);
7203 Check_Arg_Is_Local_Name (Arg1);
7204 E_Id := Get_Pragma_Arg (Arg1);
7206 if Etype (E_Id) = Any_Type then
7212 if not Is_Record_Type (E) then
7214 ("argument for pragma% must be record type", Arg1);
7217 Ent := First_Entity (E);
7220 or else No (Next_Entity (Ent))
7221 or else Present (Next_Entity (Next_Entity (Ent)))
7222 or else not Is_Floating_Point_Type (Etype (Ent))
7223 or else Etype (Ent) /= Etype (Next_Entity (Ent))
7226 ("record for pragma% must have two fields of the same "
7227 & "floating-point type", Arg1);
7230 Set_Has_Complex_Representation (Base_Type (E));
7232 -- We need to treat the type has having a non-standard
7233 -- representation, for back-end purposes, even though in
7234 -- general a complex will have the default representation
7235 -- of a record with two real components.
7237 Set_Has_Non_Standard_Rep (Base_Type (E));
7239 end Complex_Representation;
7241 -------------------------
7242 -- Component_Alignment --
7243 -------------------------
7245 -- pragma Component_Alignment (
7246 -- [Form =>] ALIGNMENT_CHOICE
7247 -- [, [Name =>] type_LOCAL_NAME]);
7249 -- ALIGNMENT_CHOICE ::=
7251 -- | Component_Size_4
7255 when Pragma_Component_Alignment => Component_AlignmentP : declare
7256 Args : Args_List (1 .. 2);
7257 Names : constant Name_List (1 .. 2) := (
7261 Form : Node_Id renames Args (1);
7262 Name : Node_Id renames Args (2);
7264 Atype : Component_Alignment_Kind;
7269 Gather_Associations (Names, Args);
7272 Error_Pragma ("missing Form argument for pragma%");
7275 Check_Arg_Is_Identifier (Form);
7277 -- Get proper alignment, note that Default = Component_Size on all
7278 -- machines we have so far, and we want to set this value rather
7279 -- than the default value to indicate that it has been explicitly
7280 -- set (and thus will not get overridden by the default component
7281 -- alignment for the current scope)
7283 if Chars (Form) = Name_Component_Size then
7284 Atype := Calign_Component_Size;
7286 elsif Chars (Form) = Name_Component_Size_4 then
7287 Atype := Calign_Component_Size_4;
7289 elsif Chars (Form) = Name_Default then
7290 Atype := Calign_Component_Size;
7292 elsif Chars (Form) = Name_Storage_Unit then
7293 Atype := Calign_Storage_Unit;
7297 ("invalid Form parameter for pragma%", Form);
7300 -- Case with no name, supplied, affects scope table entry
7304 (Scope_Stack.Last).Component_Alignment_Default := Atype;
7306 -- Case of name supplied
7309 Check_Arg_Is_Local_Name (Name);
7311 Typ := Entity (Name);
7314 or else Rep_Item_Too_Early (Typ, N)
7318 Typ := Underlying_Type (Typ);
7321 if not Is_Record_Type (Typ)
7322 and then not Is_Array_Type (Typ)
7325 ("Name parameter of pragma% must identify record or " &
7326 "array type", Name);
7329 -- An explicit Component_Alignment pragma overrides an
7330 -- implicit pragma Pack, but not an explicit one.
7332 if not Has_Pragma_Pack (Base_Type (Typ)) then
7333 Set_Is_Packed (Base_Type (Typ), False);
7334 Set_Component_Alignment (Base_Type (Typ), Atype);
7337 end Component_AlignmentP;
7343 -- pragma Controlled (first_subtype_LOCAL_NAME);
7345 when Pragma_Controlled => Controlled : declare
7349 Check_No_Identifiers;
7350 Check_Arg_Count (1);
7351 Check_Arg_Is_Local_Name (Arg1);
7352 Arg := Get_Pragma_Arg (Arg1);
7354 if not Is_Entity_Name (Arg)
7355 or else not Is_Access_Type (Entity (Arg))
7357 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7359 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7367 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
7368 -- [Entity =>] LOCAL_NAME);
7370 when Pragma_Convention => Convention : declare
7373 pragma Warnings (Off, C);
7374 pragma Warnings (Off, E);
7376 Check_Arg_Order ((Name_Convention, Name_Entity));
7377 Check_Ada_83_Warning;
7378 Check_Arg_Count (2);
7379 Process_Convention (C, E);
7382 ---------------------------
7383 -- Convention_Identifier --
7384 ---------------------------
7386 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7387 -- [Convention =>] convention_IDENTIFIER);
7389 when Pragma_Convention_Identifier => Convention_Identifier : declare
7395 Check_Arg_Order ((Name_Name, Name_Convention));
7396 Check_Arg_Count (2);
7397 Check_Optional_Identifier (Arg1, Name_Name);
7398 Check_Optional_Identifier (Arg2, Name_Convention);
7399 Check_Arg_Is_Identifier (Arg1);
7400 Check_Arg_Is_Identifier (Arg2);
7401 Idnam := Chars (Get_Pragma_Arg (Arg1));
7402 Cname := Chars (Get_Pragma_Arg (Arg2));
7404 if Is_Convention_Name (Cname) then
7405 Record_Convention_Identifier
7406 (Idnam, Get_Convention_Id (Cname));
7409 ("second arg for % pragma must be convention", Arg2);
7411 end Convention_Identifier;
7417 -- pragma CPP_Class ([Entity =>] local_NAME)
7419 when Pragma_CPP_Class => CPP_Class : declare
7424 if Warn_On_Obsolescent_Feature then
7426 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7427 " by pragma import?", N);
7431 Check_Arg_Count (1);
7432 Check_Optional_Identifier (Arg1, Name_Entity);
7433 Check_Arg_Is_Local_Name (Arg1);
7435 Arg := Get_Pragma_Arg (Arg1);
7438 if Etype (Arg) = Any_Type then
7442 if not Is_Entity_Name (Arg)
7443 or else not Is_Type (Entity (Arg))
7445 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7448 Typ := Entity (Arg);
7450 if not Is_Tagged_Type (Typ) then
7451 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7454 -- Types treated as CPP classes must be declared limited (note:
7455 -- this used to be a warning but there is no real benefit to it
7456 -- since we did effectively intend to treat the type as limited
7459 if not Is_Limited_Type (Typ) then
7461 ("imported 'C'P'P type must be limited",
7462 Get_Pragma_Arg (Arg1));
7465 Set_Is_CPP_Class (Typ);
7466 Set_Convention (Typ, Convention_CPP);
7468 -- Imported CPP types must not have discriminants (because C++
7469 -- classes do not have discriminants).
7471 if Has_Discriminants (Typ) then
7473 ("imported 'C'P'P type cannot have discriminants",
7474 First (Discriminant_Specifications
7475 (Declaration_Node (Typ))));
7478 -- Components of imported CPP types must not have default
7479 -- expressions because the constructor (if any) is in the
7482 if Is_Incomplete_Or_Private_Type (Typ)
7483 and then No (Underlying_Type (Typ))
7485 -- It should be an error to apply pragma CPP to a private
7486 -- type if the underlying type is not visible (as it is
7487 -- for any representation item). For now, for backward
7488 -- compatibility we do nothing but we cannot check components
7489 -- because they are not available at this stage. All this code
7490 -- will be removed when we cleanup this obsolete GNAT pragma???
7496 Tdef : constant Node_Id :=
7497 Type_Definition (Declaration_Node (Typ));
7502 if Nkind (Tdef) = N_Record_Definition then
7503 Clist := Component_List (Tdef);
7505 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7506 Clist := Component_List (Record_Extension_Part (Tdef));
7509 if Present (Clist) then
7510 Comp := First (Component_Items (Clist));
7511 while Present (Comp) loop
7512 if Present (Expression (Comp)) then
7514 ("component of imported 'C'P'P type cannot have" &
7515 " default expression", Expression (Comp));
7525 ---------------------
7526 -- CPP_Constructor --
7527 ---------------------
7529 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7530 -- [, [External_Name =>] static_string_EXPRESSION ]
7531 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7533 when Pragma_CPP_Constructor => CPP_Constructor : declare
7537 Tag_Typ : Entity_Id;
7541 Check_At_Least_N_Arguments (1);
7542 Check_At_Most_N_Arguments (3);
7543 Check_Optional_Identifier (Arg1, Name_Entity);
7544 Check_Arg_Is_Local_Name (Arg1);
7546 Id := Get_Pragma_Arg (Arg1);
7547 Find_Program_Unit_Name (Id);
7549 -- If we did not find the name, we are done
7551 if Etype (Id) = Any_Type then
7555 Def_Id := Entity (Id);
7557 -- Check if already defined as constructor
7559 if Is_Constructor (Def_Id) then
7561 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7565 if Ekind (Def_Id) = E_Function
7566 and then (Is_CPP_Class (Etype (Def_Id))
7567 or else (Is_Class_Wide_Type (Etype (Def_Id))
7569 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7571 if Arg_Count >= 2 then
7572 Set_Imported (Def_Id);
7573 Set_Is_Public (Def_Id);
7574 Process_Interface_Name (Def_Id, Arg2, Arg3);
7577 Set_Has_Completion (Def_Id);
7578 Set_Is_Constructor (Def_Id);
7580 -- Imported C++ constructors are not dispatching primitives
7581 -- because in C++ they don't have a dispatch table slot.
7582 -- However, in Ada the constructor has the profile of a
7583 -- function that returns a tagged type and therefore it has
7584 -- been treated as a primitive operation during semantic
7585 -- analysis. We now remove it from the list of primitive
7586 -- operations of the type.
7588 if Is_Tagged_Type (Etype (Def_Id))
7589 and then not Is_Class_Wide_Type (Etype (Def_Id))
7591 pragma Assert (Is_Dispatching_Operation (Def_Id));
7592 Tag_Typ := Etype (Def_Id);
7594 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7595 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7599 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7600 Set_Is_Dispatching_Operation (Def_Id, False);
7603 -- For backward compatibility, if the constructor returns a
7604 -- class wide type, and we internally change the return type to
7605 -- the corresponding root type.
7607 if Is_Class_Wide_Type (Etype (Def_Id)) then
7608 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7612 ("pragma% requires function returning a 'C'P'P_Class type",
7615 end CPP_Constructor;
7621 when Pragma_CPP_Virtual => CPP_Virtual : declare
7625 if Warn_On_Obsolescent_Feature then
7627 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7636 when Pragma_CPP_Vtable => CPP_Vtable : declare
7640 if Warn_On_Obsolescent_Feature then
7642 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7651 -- pragma CPU (EXPRESSION);
7653 when Pragma_CPU => CPU : declare
7654 P : constant Node_Id := Parent (N);
7659 Check_No_Identifiers;
7660 Check_Arg_Count (1);
7664 if Nkind (P) = N_Subprogram_Body then
7665 Check_In_Main_Program;
7667 Arg := Get_Pragma_Arg (Arg1);
7668 Analyze_And_Resolve (Arg, Any_Integer);
7672 if not Is_Static_Expression (Arg) then
7673 Flag_Non_Static_Expr
7674 ("main subprogram affinity is not static!", Arg);
7677 -- If constraint error, then we already signalled an error
7679 elsif Raises_Constraint_Error (Arg) then
7682 -- Otherwise check in range
7686 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7687 -- This is the entity System.Multiprocessors.CPU_Range;
7689 Val : constant Uint := Expr_Value (Arg);
7692 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7694 Val > Expr_Value (Type_High_Bound (CPU_Id))
7697 ("main subprogram CPU is out of range", Arg1);
7703 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7707 elsif Nkind (P) = N_Task_Definition then
7708 Arg := Get_Pragma_Arg (Arg1);
7710 -- The expression must be analyzed in the special manner
7711 -- described in "Handling of Default and Per-Object
7712 -- Expressions" in sem.ads.
7714 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7716 -- Anything else is incorrect
7722 if Has_Pragma_CPU (P) then
7723 Error_Pragma ("duplicate pragma% not allowed");
7725 Set_Has_Pragma_CPU (P, True);
7727 if Nkind (P) = N_Task_Definition then
7728 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7737 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7739 when Pragma_Debug => Debug : declare
7746 -- Skip analysis if disabled
7748 if Debug_Pragmas_Disabled then
7749 Rewrite (N, Make_Null_Statement (Loc));
7756 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7759 if Debug_Pragmas_Enabled then
7760 Set_SCO_Pragma_Enabled (Loc);
7763 if Arg_Count = 2 then
7766 Left_Opnd => Relocate_Node (Cond),
7767 Right_Opnd => Get_Pragma_Arg (Arg1));
7768 Call := Get_Pragma_Arg (Arg2);
7770 Call := Get_Pragma_Arg (Arg1);
7774 N_Indexed_Component,
7777 N_Selected_Component)
7779 -- If this pragma Debug comes from source, its argument was
7780 -- parsed as a name form (which is syntactically identical).
7781 -- Change it to a procedure call statement now.
7783 Change_Name_To_Procedure_Call_Statement (Call);
7785 elsif Nkind (Call) = N_Procedure_Call_Statement then
7787 -- Already in the form of a procedure call statement: nothing
7788 -- to do (could happen in case of an internally generated
7794 -- All other cases: diagnose error
7797 ("argument of pragma% is not procedure call", Sloc (Call));
7801 -- Rewrite into a conditional with an appropriate condition. We
7802 -- wrap the procedure call in a block so that overhead from e.g.
7803 -- use of the secondary stack does not generate execution overhead
7804 -- for suppressed conditions.
7806 Rewrite (N, Make_Implicit_If_Statement (N,
7808 Then_Statements => New_List (
7809 Make_Block_Statement (Loc,
7810 Handled_Statement_Sequence =>
7811 Make_Handled_Sequence_Of_Statements (Loc,
7812 Statements => New_List (Relocate_Node (Call)))))));
7820 -- pragma Debug_Policy (Check | Ignore)
7822 when Pragma_Debug_Policy =>
7824 Check_Arg_Count (1);
7825 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7826 Debug_Pragmas_Enabled :=
7827 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7828 Debug_Pragmas_Disabled :=
7829 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
7831 ---------------------
7832 -- Detect_Blocking --
7833 ---------------------
7835 -- pragma Detect_Blocking;
7837 when Pragma_Detect_Blocking =>
7839 Check_Arg_Count (0);
7840 Check_Valid_Configuration_Pragma;
7841 Detect_Blocking := True;
7843 --------------------------
7844 -- Default_Storage_Pool --
7845 --------------------------
7847 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7849 when Pragma_Default_Storage_Pool =>
7851 Check_Arg_Count (1);
7853 -- Default_Storage_Pool can appear as a configuration pragma, or
7854 -- in a declarative part or a package spec.
7856 if not Is_Configuration_Pragma then
7857 Check_Is_In_Decl_Part_Or_Package_Spec;
7860 -- Case of Default_Storage_Pool (null);
7862 if Nkind (Expression (Arg1)) = N_Null then
7863 Analyze (Expression (Arg1));
7865 -- This is an odd case, this is not really an expression, so
7866 -- we don't have a type for it. So just set the type to Empty.
7868 Set_Etype (Expression (Arg1), Empty);
7870 -- Case of Default_Storage_Pool (storage_pool_NAME);
7873 -- If it's a configuration pragma, then the only allowed
7874 -- argument is "null".
7876 if Is_Configuration_Pragma then
7877 Error_Pragma_Arg ("NULL expected", Arg1);
7880 -- The expected type for a non-"null" argument is
7881 -- Root_Storage_Pool'Class.
7884 (Get_Pragma_Arg (Arg1),
7885 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7888 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7889 -- for an access type will use this information to set the
7890 -- appropriate attributes of the access type.
7892 Default_Pool := Expression (Arg1);
7898 when Pragma_Dimension =>
7900 Check_Arg_Count (4);
7901 Check_No_Identifiers;
7902 Check_Arg_Is_Local_Name (Arg1);
7904 if not Is_Type (Arg1) then
7905 Error_Pragma ("first argument for pragma% must be subtype");
7908 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7909 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7910 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7916 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7918 when Pragma_Discard_Names => Discard_Names : declare
7923 Check_Ada_83_Warning;
7925 -- Deal with configuration pragma case
7927 if Arg_Count = 0 and then Is_Configuration_Pragma then
7928 Global_Discard_Names := True;
7931 -- Otherwise, check correct appropriate context
7934 Check_Is_In_Decl_Part_Or_Package_Spec;
7936 if Arg_Count = 0 then
7938 -- If there is no parameter, then from now on this pragma
7939 -- applies to any enumeration, exception or tagged type
7940 -- defined in the current declarative part, and recursively
7941 -- to any nested scope.
7943 Set_Discard_Names (Current_Scope);
7947 Check_Arg_Count (1);
7948 Check_Optional_Identifier (Arg1, Name_On);
7949 Check_Arg_Is_Local_Name (Arg1);
7951 E_Id := Get_Pragma_Arg (Arg1);
7953 if Etype (E_Id) = Any_Type then
7959 if (Is_First_Subtype (E)
7961 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7962 or else Ekind (E) = E_Exception
7964 Set_Discard_Names (E);
7967 ("inappropriate entity for pragma%", Arg1);
7974 ------------------------
7975 -- Dispatching_Domain --
7976 ------------------------
7978 -- pragma Dispatching_Domain (EXPRESSION);
7980 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
7981 P : constant Node_Id := Parent (N);
7986 Check_No_Identifiers;
7987 Check_Arg_Count (1);
7989 -- This pragma is born obsolete, but not the aspect
7991 if not From_Aspect_Specification (N) then
7993 (No_Obsolescent_Features, Pragma_Identifier (N));
7996 if Nkind (P) = N_Task_Definition then
7997 Arg := Get_Pragma_Arg (Arg1);
7999 -- The expression must be analyzed in the special manner
8000 -- described in "Handling of Default and Per-Object
8001 -- Expressions" in sem.ads.
8003 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8005 -- Anything else is incorrect
8011 if Has_Pragma_Dispatching_Domain (P) then
8012 Error_Pragma ("duplicate pragma% not allowed");
8014 Set_Has_Pragma_Dispatching_Domain (P, True);
8016 if Nkind (P) = N_Task_Definition then
8017 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8020 end Dispatching_Domain;
8026 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8028 when Pragma_Elaborate => Elaborate : declare
8033 -- Pragma must be in context items list of a compilation unit
8035 if not Is_In_Context_Clause then
8039 -- Must be at least one argument
8041 if Arg_Count = 0 then
8042 Error_Pragma ("pragma% requires at least one argument");
8045 -- In Ada 83 mode, there can be no items following it in the
8046 -- context list except other pragmas and implicit with clauses
8047 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8048 -- placement rule does not apply.
8050 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8052 while Present (Citem) loop
8053 if Nkind (Citem) = N_Pragma
8054 or else (Nkind (Citem) = N_With_Clause
8055 and then Implicit_With (Citem))
8060 ("(Ada 83) pragma% must be at end of context clause");
8067 -- Finally, the arguments must all be units mentioned in a with
8068 -- clause in the same context clause. Note we already checked (in
8069 -- Par.Prag) that the arguments are all identifiers or selected
8073 Outer : while Present (Arg) loop
8074 Citem := First (List_Containing (N));
8075 Inner : while Citem /= N loop
8076 if Nkind (Citem) = N_With_Clause
8077 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8079 Set_Elaborate_Present (Citem, True);
8080 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8081 Generate_Reference (Entity (Name (Citem)), Citem);
8083 -- With the pragma present, elaboration calls on
8084 -- subprograms from the named unit need no further
8085 -- checks, as long as the pragma appears in the current
8086 -- compilation unit. If the pragma appears in some unit
8087 -- in the context, there might still be a need for an
8088 -- Elaborate_All_Desirable from the current compilation
8089 -- to the named unit, so we keep the check enabled.
8091 if In_Extended_Main_Source_Unit (N) then
8092 Set_Suppress_Elaboration_Warnings
8093 (Entity (Name (Citem)));
8104 ("argument of pragma% is not with'ed unit", Arg);
8110 -- Give a warning if operating in static mode with -gnatwl
8111 -- (elaboration warnings enabled) switch set.
8113 if Elab_Warnings and not Dynamic_Elaboration_Checks then
8115 ("?use of pragma Elaborate may not be safe", N);
8117 ("?use pragma Elaborate_All instead if possible", N);
8125 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8127 when Pragma_Elaborate_All => Elaborate_All : declare
8132 Check_Ada_83_Warning;
8134 -- Pragma must be in context items list of a compilation unit
8136 if not Is_In_Context_Clause then
8140 -- Must be at least one argument
8142 if Arg_Count = 0 then
8143 Error_Pragma ("pragma% requires at least one argument");
8146 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
8147 -- have to appear at the end of the context clause, but may
8148 -- appear mixed in with other items, even in Ada 83 mode.
8150 -- Final check: the arguments must all be units mentioned in
8151 -- a with clause in the same context clause. Note that we
8152 -- already checked (in Par.Prag) that all the arguments are
8153 -- either identifiers or selected components.
8156 Outr : while Present (Arg) loop
8157 Citem := First (List_Containing (N));
8158 Innr : while Citem /= N loop
8159 if Nkind (Citem) = N_With_Clause
8160 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8162 Set_Elaborate_All_Present (Citem, True);
8163 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8165 -- Suppress warnings and elaboration checks on the named
8166 -- unit if the pragma is in the current compilation, as
8167 -- for pragma Elaborate.
8169 if In_Extended_Main_Source_Unit (N) then
8170 Set_Suppress_Elaboration_Warnings
8171 (Entity (Name (Citem)));
8180 Set_Error_Posted (N);
8182 ("argument of pragma% is not with'ed unit", Arg);
8189 --------------------
8190 -- Elaborate_Body --
8191 --------------------
8193 -- pragma Elaborate_Body [( library_unit_NAME )];
8195 when Pragma_Elaborate_Body => Elaborate_Body : declare
8196 Cunit_Node : Node_Id;
8197 Cunit_Ent : Entity_Id;
8200 Check_Ada_83_Warning;
8201 Check_Valid_Library_Unit_Pragma;
8203 if Nkind (N) = N_Null_Statement then
8207 Cunit_Node := Cunit (Current_Sem_Unit);
8208 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8210 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8213 Error_Pragma ("pragma% must refer to a spec, not a body");
8215 Set_Body_Required (Cunit_Node, True);
8216 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8218 -- If we are in dynamic elaboration mode, then we suppress
8219 -- elaboration warnings for the unit, since it is definitely
8220 -- fine NOT to do dynamic checks at the first level (and such
8221 -- checks will be suppressed because no elaboration boolean
8222 -- is created for Elaborate_Body packages).
8224 -- But in the static model of elaboration, Elaborate_Body is
8225 -- definitely NOT good enough to ensure elaboration safety on
8226 -- its own, since the body may WITH other units that are not
8227 -- safe from an elaboration point of view, so a client must
8228 -- still do an Elaborate_All on such units.
8230 -- Debug flag -gnatdD restores the old behavior of 3.13, where
8231 -- Elaborate_Body always suppressed elab warnings.
8233 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8234 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8239 ------------------------
8240 -- Elaboration_Checks --
8241 ------------------------
8243 -- pragma Elaboration_Checks (Static | Dynamic);
8245 when Pragma_Elaboration_Checks =>
8247 Check_Arg_Count (1);
8248 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8249 Dynamic_Elaboration_Checks :=
8250 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8256 -- pragma Eliminate (
8257 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
8258 -- [,[Entity =>] IDENTIFIER |
8259 -- SELECTED_COMPONENT |
8261 -- [, OVERLOADING_RESOLUTION]);
8263 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8266 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8269 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8271 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8272 -- Result_Type => result_SUBTYPE_NAME]
8274 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8275 -- SUBTYPE_NAME ::= STRING_LITERAL
8277 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8278 -- SOURCE_TRACE ::= STRING_LITERAL
8280 when Pragma_Eliminate => Eliminate : declare
8281 Args : Args_List (1 .. 5);
8282 Names : constant Name_List (1 .. 5) := (
8285 Name_Parameter_Types,
8287 Name_Source_Location);
8289 Unit_Name : Node_Id renames Args (1);
8290 Entity : Node_Id renames Args (2);
8291 Parameter_Types : Node_Id renames Args (3);
8292 Result_Type : Node_Id renames Args (4);
8293 Source_Location : Node_Id renames Args (5);
8297 Check_Valid_Configuration_Pragma;
8298 Gather_Associations (Names, Args);
8300 if No (Unit_Name) then
8301 Error_Pragma ("missing Unit_Name argument for pragma%");
8305 and then (Present (Parameter_Types)
8307 Present (Result_Type)
8309 Present (Source_Location))
8311 Error_Pragma ("missing Entity argument for pragma%");
8314 if (Present (Parameter_Types)
8316 Present (Result_Type))
8318 Present (Source_Location)
8321 ("parameter profile and source location cannot " &
8322 "be used together in pragma%");
8325 Process_Eliminate_Pragma
8339 -- [ Convention =>] convention_IDENTIFIER,
8340 -- [ Entity =>] local_NAME
8341 -- [, [External_Name =>] static_string_EXPRESSION ]
8342 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8344 when Pragma_Export => Export : declare
8348 pragma Warnings (Off, C);
8351 Check_Ada_83_Warning;
8357 Check_At_Least_N_Arguments (2);
8358 Check_At_Most_N_Arguments (4);
8359 Process_Convention (C, Def_Id);
8361 if Ekind (Def_Id) /= E_Constant then
8362 Note_Possible_Modification
8363 (Get_Pragma_Arg (Arg2), Sure => False);
8366 Process_Interface_Name (Def_Id, Arg3, Arg4);
8367 Set_Exported (Def_Id, Arg2);
8369 -- If the entity is a deferred constant, propagate the information
8370 -- to the full view, because gigi elaborates the full view only.
8372 if Ekind (Def_Id) = E_Constant
8373 and then Present (Full_View (Def_Id))
8376 Id2 : constant Entity_Id := Full_View (Def_Id);
8378 Set_Is_Exported (Id2, Is_Exported (Def_Id));
8379 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
8380 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8385 ----------------------
8386 -- Export_Exception --
8387 ----------------------
8389 -- pragma Export_Exception (
8390 -- [Internal =>] LOCAL_NAME
8391 -- [, [External =>] EXTERNAL_SYMBOL]
8392 -- [, [Form =>] Ada | VMS]
8393 -- [, [Code =>] static_integer_EXPRESSION]);
8395 when Pragma_Export_Exception => Export_Exception : declare
8396 Args : Args_List (1 .. 4);
8397 Names : constant Name_List (1 .. 4) := (
8403 Internal : Node_Id renames Args (1);
8404 External : Node_Id renames Args (2);
8405 Form : Node_Id renames Args (3);
8406 Code : Node_Id renames Args (4);
8411 if Inside_A_Generic then
8412 Error_Pragma ("pragma% cannot be used for generic entities");
8415 Gather_Associations (Names, Args);
8416 Process_Extended_Import_Export_Exception_Pragma (
8417 Arg_Internal => Internal,
8418 Arg_External => External,
8422 if not Is_VMS_Exception (Entity (Internal)) then
8423 Set_Exported (Entity (Internal), Internal);
8425 end Export_Exception;
8427 ---------------------
8428 -- Export_Function --
8429 ---------------------
8431 -- pragma Export_Function (
8432 -- [Internal =>] LOCAL_NAME
8433 -- [, [External =>] EXTERNAL_SYMBOL]
8434 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8435 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8436 -- [, [Mechanism =>] MECHANISM]
8437 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8439 -- EXTERNAL_SYMBOL ::=
8441 -- | static_string_EXPRESSION
8443 -- PARAMETER_TYPES ::=
8445 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8447 -- TYPE_DESIGNATOR ::=
8449 -- | subtype_Name ' Access
8453 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8455 -- MECHANISM_ASSOCIATION ::=
8456 -- [formal_parameter_NAME =>] MECHANISM_NAME
8458 -- MECHANISM_NAME ::=
8461 -- | Descriptor [([Class =>] CLASS_NAME)]
8463 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8465 when Pragma_Export_Function => Export_Function : declare
8466 Args : Args_List (1 .. 6);
8467 Names : constant Name_List (1 .. 6) := (
8470 Name_Parameter_Types,
8473 Name_Result_Mechanism);
8475 Internal : Node_Id renames Args (1);
8476 External : Node_Id renames Args (2);
8477 Parameter_Types : Node_Id renames Args (3);
8478 Result_Type : Node_Id renames Args (4);
8479 Mechanism : Node_Id renames Args (5);
8480 Result_Mechanism : Node_Id renames Args (6);
8484 Gather_Associations (Names, Args);
8485 Process_Extended_Import_Export_Subprogram_Pragma (
8486 Arg_Internal => Internal,
8487 Arg_External => External,
8488 Arg_Parameter_Types => Parameter_Types,
8489 Arg_Result_Type => Result_Type,
8490 Arg_Mechanism => Mechanism,
8491 Arg_Result_Mechanism => Result_Mechanism);
8492 end Export_Function;
8498 -- pragma Export_Object (
8499 -- [Internal =>] LOCAL_NAME
8500 -- [, [External =>] EXTERNAL_SYMBOL]
8501 -- [, [Size =>] EXTERNAL_SYMBOL]);
8503 -- EXTERNAL_SYMBOL ::=
8505 -- | static_string_EXPRESSION
8507 -- PARAMETER_TYPES ::=
8509 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8511 -- TYPE_DESIGNATOR ::=
8513 -- | subtype_Name ' Access
8517 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8519 -- MECHANISM_ASSOCIATION ::=
8520 -- [formal_parameter_NAME =>] MECHANISM_NAME
8522 -- MECHANISM_NAME ::=
8525 -- | Descriptor [([Class =>] CLASS_NAME)]
8527 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8529 when Pragma_Export_Object => Export_Object : declare
8530 Args : Args_List (1 .. 3);
8531 Names : constant Name_List (1 .. 3) := (
8536 Internal : Node_Id renames Args (1);
8537 External : Node_Id renames Args (2);
8538 Size : Node_Id renames Args (3);
8542 Gather_Associations (Names, Args);
8543 Process_Extended_Import_Export_Object_Pragma (
8544 Arg_Internal => Internal,
8545 Arg_External => External,
8549 ----------------------
8550 -- Export_Procedure --
8551 ----------------------
8553 -- pragma Export_Procedure (
8554 -- [Internal =>] LOCAL_NAME
8555 -- [, [External =>] EXTERNAL_SYMBOL]
8556 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8557 -- [, [Mechanism =>] MECHANISM]);
8559 -- EXTERNAL_SYMBOL ::=
8561 -- | static_string_EXPRESSION
8563 -- PARAMETER_TYPES ::=
8565 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8567 -- TYPE_DESIGNATOR ::=
8569 -- | subtype_Name ' Access
8573 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8575 -- MECHANISM_ASSOCIATION ::=
8576 -- [formal_parameter_NAME =>] MECHANISM_NAME
8578 -- MECHANISM_NAME ::=
8581 -- | Descriptor [([Class =>] CLASS_NAME)]
8583 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8585 when Pragma_Export_Procedure => Export_Procedure : declare
8586 Args : Args_List (1 .. 4);
8587 Names : constant Name_List (1 .. 4) := (
8590 Name_Parameter_Types,
8593 Internal : Node_Id renames Args (1);
8594 External : Node_Id renames Args (2);
8595 Parameter_Types : Node_Id renames Args (3);
8596 Mechanism : Node_Id renames Args (4);
8600 Gather_Associations (Names, Args);
8601 Process_Extended_Import_Export_Subprogram_Pragma (
8602 Arg_Internal => Internal,
8603 Arg_External => External,
8604 Arg_Parameter_Types => Parameter_Types,
8605 Arg_Mechanism => Mechanism);
8606 end Export_Procedure;
8612 -- pragma Export_Value (
8613 -- [Value =>] static_integer_EXPRESSION,
8614 -- [Link_Name =>] static_string_EXPRESSION);
8616 when Pragma_Export_Value =>
8618 Check_Arg_Order ((Name_Value, Name_Link_Name));
8619 Check_Arg_Count (2);
8621 Check_Optional_Identifier (Arg1, Name_Value);
8622 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8624 Check_Optional_Identifier (Arg2, Name_Link_Name);
8625 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8627 -----------------------------
8628 -- Export_Valued_Procedure --
8629 -----------------------------
8631 -- pragma Export_Valued_Procedure (
8632 -- [Internal =>] LOCAL_NAME
8633 -- [, [External =>] EXTERNAL_SYMBOL,]
8634 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8635 -- [, [Mechanism =>] MECHANISM]);
8637 -- EXTERNAL_SYMBOL ::=
8639 -- | static_string_EXPRESSION
8641 -- PARAMETER_TYPES ::=
8643 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8645 -- TYPE_DESIGNATOR ::=
8647 -- | subtype_Name ' Access
8651 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8653 -- MECHANISM_ASSOCIATION ::=
8654 -- [formal_parameter_NAME =>] MECHANISM_NAME
8656 -- MECHANISM_NAME ::=
8659 -- | Descriptor [([Class =>] CLASS_NAME)]
8661 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8663 when Pragma_Export_Valued_Procedure =>
8664 Export_Valued_Procedure : declare
8665 Args : Args_List (1 .. 4);
8666 Names : constant Name_List (1 .. 4) := (
8669 Name_Parameter_Types,
8672 Internal : Node_Id renames Args (1);
8673 External : Node_Id renames Args (2);
8674 Parameter_Types : Node_Id renames Args (3);
8675 Mechanism : Node_Id renames Args (4);
8679 Gather_Associations (Names, Args);
8680 Process_Extended_Import_Export_Subprogram_Pragma (
8681 Arg_Internal => Internal,
8682 Arg_External => External,
8683 Arg_Parameter_Types => Parameter_Types,
8684 Arg_Mechanism => Mechanism);
8685 end Export_Valued_Procedure;
8691 -- pragma Extend_System ([Name =>] Identifier);
8693 when Pragma_Extend_System => Extend_System : declare
8696 Check_Valid_Configuration_Pragma;
8697 Check_Arg_Count (1);
8698 Check_Optional_Identifier (Arg1, Name_Name);
8699 Check_Arg_Is_Identifier (Arg1);
8701 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8704 and then Name_Buffer (1 .. 4) = "aux_"
8706 if Present (System_Extend_Pragma_Arg) then
8707 if Chars (Get_Pragma_Arg (Arg1)) =
8708 Chars (Expression (System_Extend_Pragma_Arg))
8712 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8713 Error_Pragma ("pragma% conflicts with that #");
8717 System_Extend_Pragma_Arg := Arg1;
8719 if not GNAT_Mode then
8720 System_Extend_Unit := Arg1;
8724 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8728 ------------------------
8729 -- Extensions_Allowed --
8730 ------------------------
8732 -- pragma Extensions_Allowed (ON | OFF);
8734 when Pragma_Extensions_Allowed =>
8736 Check_Arg_Count (1);
8737 Check_No_Identifiers;
8738 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8740 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8741 Extensions_Allowed := True;
8742 Ada_Version := Ada_Version_Type'Last;
8745 Extensions_Allowed := False;
8746 Ada_Version := Ada_Version_Explicit;
8753 -- pragma External (
8754 -- [ Convention =>] convention_IDENTIFIER,
8755 -- [ Entity =>] local_NAME
8756 -- [, [External_Name =>] static_string_EXPRESSION ]
8757 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8759 when Pragma_External => External : declare
8763 pragma Warnings (Off, C);
8772 Check_At_Least_N_Arguments (2);
8773 Check_At_Most_N_Arguments (4);
8774 Process_Convention (C, Def_Id);
8775 Note_Possible_Modification
8776 (Get_Pragma_Arg (Arg2), Sure => False);
8777 Process_Interface_Name (Def_Id, Arg3, Arg4);
8778 Set_Exported (Def_Id, Arg2);
8781 --------------------------
8782 -- External_Name_Casing --
8783 --------------------------
8785 -- pragma External_Name_Casing (
8786 -- UPPERCASE | LOWERCASE
8787 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8789 when Pragma_External_Name_Casing => External_Name_Casing : declare
8792 Check_No_Identifiers;
8794 if Arg_Count = 2 then
8796 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8798 case Chars (Get_Pragma_Arg (Arg2)) is
8800 Opt.External_Name_Exp_Casing := As_Is;
8802 when Name_Uppercase =>
8803 Opt.External_Name_Exp_Casing := Uppercase;
8805 when Name_Lowercase =>
8806 Opt.External_Name_Exp_Casing := Lowercase;
8813 Check_Arg_Count (1);
8816 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8818 case Chars (Get_Pragma_Arg (Arg1)) is
8819 when Name_Uppercase =>
8820 Opt.External_Name_Imp_Casing := Uppercase;
8822 when Name_Lowercase =>
8823 Opt.External_Name_Imp_Casing := Lowercase;
8828 end External_Name_Casing;
8830 --------------------------
8831 -- Favor_Top_Level --
8832 --------------------------
8834 -- pragma Favor_Top_Level (type_NAME);
8836 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8837 Named_Entity : Entity_Id;
8841 Check_No_Identifiers;
8842 Check_Arg_Count (1);
8843 Check_Arg_Is_Local_Name (Arg1);
8844 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8846 -- If it's an access-to-subprogram type (in particular, not a
8847 -- subtype), set the flag on that type.
8849 if Is_Access_Subprogram_Type (Named_Entity) then
8850 Set_Can_Use_Internal_Rep (Named_Entity, False);
8852 -- Otherwise it's an error (name denotes the wrong sort of entity)
8856 ("access-to-subprogram type expected",
8857 Get_Pragma_Arg (Arg1));
8859 end Favor_Top_Level;
8865 -- pragma Fast_Math;
8867 when Pragma_Fast_Math =>
8869 Check_No_Identifiers;
8870 Check_Valid_Configuration_Pragma;
8873 ---------------------------
8874 -- Finalize_Storage_Only --
8875 ---------------------------
8877 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8879 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8880 Assoc : constant Node_Id := Arg1;
8881 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8886 Check_No_Identifiers;
8887 Check_Arg_Count (1);
8888 Check_Arg_Is_Local_Name (Arg1);
8890 Find_Type (Type_Id);
8891 Typ := Entity (Type_Id);
8894 or else Rep_Item_Too_Early (Typ, N)
8898 Typ := Underlying_Type (Typ);
8901 if not Is_Controlled (Typ) then
8902 Error_Pragma ("pragma% must specify controlled type");
8905 Check_First_Subtype (Arg1);
8907 if Finalize_Storage_Only (Typ) then
8908 Error_Pragma ("duplicate pragma%, only one allowed");
8910 elsif not Rep_Item_Too_Late (Typ, N) then
8911 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8913 end Finalize_Storage;
8915 --------------------------
8916 -- Float_Representation --
8917 --------------------------
8919 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8921 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8923 when Pragma_Float_Representation => Float_Representation : declare
8931 if Arg_Count = 1 then
8932 Check_Valid_Configuration_Pragma;
8934 Check_Arg_Count (2);
8935 Check_Optional_Identifier (Arg2, Name_Entity);
8936 Check_Arg_Is_Local_Name (Arg2);
8939 Check_No_Identifier (Arg1);
8940 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8942 if not OpenVMS_On_Target then
8943 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8945 ("?pragma% ignored (applies only to Open'V'M'S)");
8951 -- One argument case
8953 if Arg_Count = 1 then
8954 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8955 if Opt.Float_Format = 'I' then
8956 Error_Pragma ("'I'E'E'E format previously specified");
8959 Opt.Float_Format := 'V';
8962 if Opt.Float_Format = 'V' then
8963 Error_Pragma ("'V'A'X format previously specified");
8966 Opt.Float_Format := 'I';
8969 Set_Standard_Fpt_Formats;
8971 -- Two argument case
8974 Argx := Get_Pragma_Arg (Arg2);
8976 if not Is_Entity_Name (Argx)
8977 or else not Is_Floating_Point_Type (Entity (Argx))
8980 ("second argument of% pragma must be floating-point type",
8984 Ent := Entity (Argx);
8985 Digs := UI_To_Int (Digits_Value (Ent));
8987 -- Two arguments, VAX_Float case
8989 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8991 when 6 => Set_F_Float (Ent);
8992 when 9 => Set_D_Float (Ent);
8993 when 15 => Set_G_Float (Ent);
8997 ("wrong digits value, must be 6,9 or 15", Arg2);
9000 -- Two arguments, IEEE_Float case
9004 when 6 => Set_IEEE_Short (Ent);
9005 when 15 => Set_IEEE_Long (Ent);
9009 ("wrong digits value, must be 6 or 15", Arg2);
9013 end Float_Representation;
9019 -- pragma Ident (static_string_EXPRESSION)
9021 -- Note: pragma Comment shares this processing. Pragma Comment is
9022 -- identical to Ident, except that the restriction of the argument to
9023 -- 31 characters and the placement restrictions are not enforced for
9026 when Pragma_Ident | Pragma_Comment => Ident : declare
9031 Check_Arg_Count (1);
9032 Check_No_Identifiers;
9033 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9036 -- For pragma Ident, preserve DEC compatibility by requiring the
9037 -- pragma to appear in a declarative part or package spec.
9039 if Prag_Id = Pragma_Ident then
9040 Check_Is_In_Decl_Part_Or_Package_Spec;
9043 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9050 GP := Parent (Parent (N));
9052 if Nkind_In (GP, N_Package_Declaration,
9053 N_Generic_Package_Declaration)
9058 -- If we have a compilation unit, then record the ident value,
9059 -- checking for improper duplication.
9061 if Nkind (GP) = N_Compilation_Unit then
9062 CS := Ident_String (Current_Sem_Unit);
9064 if Present (CS) then
9066 -- For Ident, we do not permit multiple instances
9068 if Prag_Id = Pragma_Ident then
9069 Error_Pragma ("duplicate% pragma not permitted");
9071 -- For Comment, we concatenate the string, unless we want
9072 -- to preserve the tree structure for ASIS.
9074 elsif not ASIS_Mode then
9075 Start_String (Strval (CS));
9076 Store_String_Char (' ');
9077 Store_String_Chars (Strval (Str));
9078 Set_Strval (CS, End_String);
9082 -- In VMS, the effect of IDENT is achieved by passing
9083 -- --identification=name as a --for-linker switch.
9085 if OpenVMS_On_Target then
9088 ("--for-linker=--identification=");
9089 String_To_Name_Buffer (Strval (Str));
9090 Store_String_Chars (Name_Buffer (1 .. Name_Len));
9092 -- Only the last processed IDENT is saved. The main
9093 -- purpose is so an IDENT associated with a main
9094 -- procedure will be used in preference to an IDENT
9095 -- associated with a with'd package.
9097 Replace_Linker_Option_String
9098 (End_String, "--for-linker=--identification=");
9101 Set_Ident_String (Current_Sem_Unit, Str);
9104 -- For subunits, we just ignore the Ident, since in GNAT these
9105 -- are not separate object files, and hence not separate units
9106 -- in the unit table.
9108 elsif Nkind (GP) = N_Subunit then
9111 -- Otherwise we have a misplaced pragma Ident, but we ignore
9112 -- this if we are in an instantiation, since it comes from
9113 -- a generic, and has no relevance to the instantiation.
9115 elsif Prag_Id = Pragma_Ident then
9116 if Instantiation_Location (Loc) = No_Location then
9117 Error_Pragma ("pragma% only allowed at outer level");
9127 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9128 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
9130 when Pragma_Implemented => Implemented : declare
9131 Proc_Id : Entity_Id;
9136 Check_Arg_Count (2);
9137 Check_No_Identifiers;
9138 Check_Arg_Is_Identifier (Arg1);
9139 Check_Arg_Is_Local_Name (Arg1);
9141 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
9143 -- Extract the name of the local procedure
9145 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9147 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9148 -- primitive procedure of a synchronized tagged type.
9150 if Ekind (Proc_Id) = E_Procedure
9151 and then Is_Primitive (Proc_Id)
9152 and then Present (First_Formal (Proc_Id))
9154 Typ := Etype (First_Formal (Proc_Id));
9156 if Is_Tagged_Type (Typ)
9159 -- Check for a protected, a synchronized or a task interface
9161 ((Is_Interface (Typ)
9162 and then Is_Synchronized_Interface (Typ))
9164 -- Check for a protected type or a task type that implements
9168 (Is_Concurrent_Record_Type (Typ)
9169 and then Present (Interfaces (Typ)))
9171 -- Check for a private record extension with keyword
9175 (Ekind_In (Typ, E_Record_Type_With_Private,
9176 E_Record_Subtype_With_Private)
9177 and then Synchronized_Present (Parent (Typ))))
9182 ("controlling formal must be of synchronized " &
9183 "tagged type", Arg1);
9187 -- Procedures declared inside a protected type must be accepted
9189 elsif Ekind (Proc_Id) = E_Procedure
9190 and then Is_Protected_Type (Scope (Proc_Id))
9194 -- The first argument is not a primitive procedure
9198 ("pragma % must be applied to a primitive procedure", Arg1);
9202 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9203 -- By_Protected_Procedure to the primitive procedure of a task
9206 if Chars (Arg2) = Name_By_Protected_Procedure
9207 and then Is_Interface (Typ)
9208 and then Is_Task_Interface (Typ)
9211 ("implementation kind By_Protected_Procedure cannot be " &
9212 "applied to a task interface primitive", Arg2);
9216 Record_Rep_Item (Proc_Id, N);
9219 ----------------------
9220 -- Implicit_Packing --
9221 ----------------------
9223 -- pragma Implicit_Packing;
9225 when Pragma_Implicit_Packing =>
9227 Check_Arg_Count (0);
9228 Implicit_Packing := True;
9235 -- [Convention =>] convention_IDENTIFIER,
9236 -- [Entity =>] local_NAME
9237 -- [, [External_Name =>] static_string_EXPRESSION ]
9238 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9240 when Pragma_Import =>
9241 Check_Ada_83_Warning;
9247 Check_At_Least_N_Arguments (2);
9248 Check_At_Most_N_Arguments (4);
9249 Process_Import_Or_Interface;
9251 ----------------------
9252 -- Import_Exception --
9253 ----------------------
9255 -- pragma Import_Exception (
9256 -- [Internal =>] LOCAL_NAME
9257 -- [, [External =>] EXTERNAL_SYMBOL]
9258 -- [, [Form =>] Ada | VMS]
9259 -- [, [Code =>] static_integer_EXPRESSION]);
9261 when Pragma_Import_Exception => Import_Exception : declare
9262 Args : Args_List (1 .. 4);
9263 Names : constant Name_List (1 .. 4) := (
9269 Internal : Node_Id renames Args (1);
9270 External : Node_Id renames Args (2);
9271 Form : Node_Id renames Args (3);
9272 Code : Node_Id renames Args (4);
9276 Gather_Associations (Names, Args);
9278 if Present (External) and then Present (Code) then
9280 ("cannot give both External and Code options for pragma%");
9283 Process_Extended_Import_Export_Exception_Pragma (
9284 Arg_Internal => Internal,
9285 Arg_External => External,
9289 if not Is_VMS_Exception (Entity (Internal)) then
9290 Set_Imported (Entity (Internal));
9292 end Import_Exception;
9294 ---------------------
9295 -- Import_Function --
9296 ---------------------
9298 -- pragma Import_Function (
9299 -- [Internal =>] LOCAL_NAME,
9300 -- [, [External =>] EXTERNAL_SYMBOL]
9301 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9302 -- [, [Result_Type =>] SUBTYPE_MARK]
9303 -- [, [Mechanism =>] MECHANISM]
9304 -- [, [Result_Mechanism =>] MECHANISM_NAME]
9305 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9307 -- EXTERNAL_SYMBOL ::=
9309 -- | static_string_EXPRESSION
9311 -- PARAMETER_TYPES ::=
9313 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9315 -- TYPE_DESIGNATOR ::=
9317 -- | subtype_Name ' Access
9321 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9323 -- MECHANISM_ASSOCIATION ::=
9324 -- [formal_parameter_NAME =>] MECHANISM_NAME
9326 -- MECHANISM_NAME ::=
9329 -- | Descriptor [([Class =>] CLASS_NAME)]
9331 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9333 when Pragma_Import_Function => Import_Function : declare
9334 Args : Args_List (1 .. 7);
9335 Names : constant Name_List (1 .. 7) := (
9338 Name_Parameter_Types,
9341 Name_Result_Mechanism,
9342 Name_First_Optional_Parameter);
9344 Internal : Node_Id renames Args (1);
9345 External : Node_Id renames Args (2);
9346 Parameter_Types : Node_Id renames Args (3);
9347 Result_Type : Node_Id renames Args (4);
9348 Mechanism : Node_Id renames Args (5);
9349 Result_Mechanism : Node_Id renames Args (6);
9350 First_Optional_Parameter : Node_Id renames Args (7);
9354 Gather_Associations (Names, Args);
9355 Process_Extended_Import_Export_Subprogram_Pragma (
9356 Arg_Internal => Internal,
9357 Arg_External => External,
9358 Arg_Parameter_Types => Parameter_Types,
9359 Arg_Result_Type => Result_Type,
9360 Arg_Mechanism => Mechanism,
9361 Arg_Result_Mechanism => Result_Mechanism,
9362 Arg_First_Optional_Parameter => First_Optional_Parameter);
9363 end Import_Function;
9369 -- pragma Import_Object (
9370 -- [Internal =>] LOCAL_NAME
9371 -- [, [External =>] EXTERNAL_SYMBOL]
9372 -- [, [Size =>] EXTERNAL_SYMBOL]);
9374 -- EXTERNAL_SYMBOL ::=
9376 -- | static_string_EXPRESSION
9378 when Pragma_Import_Object => Import_Object : declare
9379 Args : Args_List (1 .. 3);
9380 Names : constant Name_List (1 .. 3) := (
9385 Internal : Node_Id renames Args (1);
9386 External : Node_Id renames Args (2);
9387 Size : Node_Id renames Args (3);
9391 Gather_Associations (Names, Args);
9392 Process_Extended_Import_Export_Object_Pragma (
9393 Arg_Internal => Internal,
9394 Arg_External => External,
9398 ----------------------
9399 -- Import_Procedure --
9400 ----------------------
9402 -- pragma Import_Procedure (
9403 -- [Internal =>] LOCAL_NAME
9404 -- [, [External =>] EXTERNAL_SYMBOL]
9405 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9406 -- [, [Mechanism =>] MECHANISM]
9407 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9409 -- EXTERNAL_SYMBOL ::=
9411 -- | static_string_EXPRESSION
9413 -- PARAMETER_TYPES ::=
9415 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9417 -- TYPE_DESIGNATOR ::=
9419 -- | subtype_Name ' Access
9423 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9425 -- MECHANISM_ASSOCIATION ::=
9426 -- [formal_parameter_NAME =>] MECHANISM_NAME
9428 -- MECHANISM_NAME ::=
9431 -- | Descriptor [([Class =>] CLASS_NAME)]
9433 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9435 when Pragma_Import_Procedure => Import_Procedure : declare
9436 Args : Args_List (1 .. 5);
9437 Names : constant Name_List (1 .. 5) := (
9440 Name_Parameter_Types,
9442 Name_First_Optional_Parameter);
9444 Internal : Node_Id renames Args (1);
9445 External : Node_Id renames Args (2);
9446 Parameter_Types : Node_Id renames Args (3);
9447 Mechanism : Node_Id renames Args (4);
9448 First_Optional_Parameter : Node_Id renames Args (5);
9452 Gather_Associations (Names, Args);
9453 Process_Extended_Import_Export_Subprogram_Pragma (
9454 Arg_Internal => Internal,
9455 Arg_External => External,
9456 Arg_Parameter_Types => Parameter_Types,
9457 Arg_Mechanism => Mechanism,
9458 Arg_First_Optional_Parameter => First_Optional_Parameter);
9459 end Import_Procedure;
9461 -----------------------------
9462 -- Import_Valued_Procedure --
9463 -----------------------------
9465 -- pragma Import_Valued_Procedure (
9466 -- [Internal =>] LOCAL_NAME
9467 -- [, [External =>] EXTERNAL_SYMBOL]
9468 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9469 -- [, [Mechanism =>] MECHANISM]
9470 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9472 -- EXTERNAL_SYMBOL ::=
9474 -- | static_string_EXPRESSION
9476 -- PARAMETER_TYPES ::=
9478 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9480 -- TYPE_DESIGNATOR ::=
9482 -- | subtype_Name ' Access
9486 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9488 -- MECHANISM_ASSOCIATION ::=
9489 -- [formal_parameter_NAME =>] MECHANISM_NAME
9491 -- MECHANISM_NAME ::=
9494 -- | Descriptor [([Class =>] CLASS_NAME)]
9496 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9498 when Pragma_Import_Valued_Procedure =>
9499 Import_Valued_Procedure : declare
9500 Args : Args_List (1 .. 5);
9501 Names : constant Name_List (1 .. 5) := (
9504 Name_Parameter_Types,
9506 Name_First_Optional_Parameter);
9508 Internal : Node_Id renames Args (1);
9509 External : Node_Id renames Args (2);
9510 Parameter_Types : Node_Id renames Args (3);
9511 Mechanism : Node_Id renames Args (4);
9512 First_Optional_Parameter : Node_Id renames Args (5);
9516 Gather_Associations (Names, Args);
9517 Process_Extended_Import_Export_Subprogram_Pragma (
9518 Arg_Internal => Internal,
9519 Arg_External => External,
9520 Arg_Parameter_Types => Parameter_Types,
9521 Arg_Mechanism => Mechanism,
9522 Arg_First_Optional_Parameter => First_Optional_Parameter);
9523 end Import_Valued_Procedure;
9529 -- pragma Independent (LOCAL_NAME);
9531 when Pragma_Independent => Independent : declare
9538 Check_Ada_83_Warning;
9540 Check_No_Identifiers;
9541 Check_Arg_Count (1);
9542 Check_Arg_Is_Local_Name (Arg1);
9543 E_Id := Get_Pragma_Arg (Arg1);
9545 if Etype (E_Id) = Any_Type then
9550 D := Declaration_Node (E);
9553 -- Check duplicate before we chain ourselves!
9555 Check_Duplicate_Pragma (E);
9557 -- Check appropriate entity
9560 if Rep_Item_Too_Early (E, N)
9562 Rep_Item_Too_Late (E, N)
9566 Check_First_Subtype (Arg1);
9569 elsif K = N_Object_Declaration
9570 or else (K = N_Component_Declaration
9571 and then Original_Record_Component (E) = E)
9573 if Rep_Item_Too_Late (E, N) then
9579 ("inappropriate entity for pragma%", Arg1);
9582 Independence_Checks.Append ((N, E));
9585 ----------------------------
9586 -- Independent_Components --
9587 ----------------------------
9589 -- pragma Atomic_Components (array_LOCAL_NAME);
9591 -- This processing is shared by Volatile_Components
9593 when Pragma_Independent_Components => Independent_Components : declare
9600 Check_Ada_83_Warning;
9602 Check_No_Identifiers;
9603 Check_Arg_Count (1);
9604 Check_Arg_Is_Local_Name (Arg1);
9605 E_Id := Get_Pragma_Arg (Arg1);
9607 if Etype (E_Id) = Any_Type then
9613 -- Check duplicate before we chain ourselves!
9615 Check_Duplicate_Pragma (E);
9617 -- Check appropriate entity
9619 if Rep_Item_Too_Early (E, N)
9621 Rep_Item_Too_Late (E, N)
9626 D := Declaration_Node (E);
9629 if (K = N_Full_Type_Declaration
9630 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9632 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9633 and then Nkind (D) = N_Object_Declaration
9634 and then Nkind (Object_Definition (D)) =
9635 N_Constrained_Array_Definition)
9637 Independence_Checks.Append ((N, E));
9640 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9642 end Independent_Components;
9644 ------------------------
9645 -- Initialize_Scalars --
9646 ------------------------
9648 -- pragma Initialize_Scalars;
9650 when Pragma_Initialize_Scalars =>
9652 Check_Arg_Count (0);
9653 Check_Valid_Configuration_Pragma;
9654 Check_Restriction (No_Initialize_Scalars, N);
9656 -- Initialize_Scalars creates false positives in CodePeer, and
9657 -- incorrect negative results in Alfa mode, so ignore this pragma
9660 if not Restriction_Active (No_Initialize_Scalars)
9661 and then not (CodePeer_Mode or Alfa_Mode)
9663 Init_Or_Norm_Scalars := True;
9664 Initialize_Scalars := True;
9671 -- pragma Inline ( NAME {, NAME} );
9673 when Pragma_Inline =>
9675 -- Pragma is active if inlining option is active
9677 Process_Inline (Inline_Active);
9683 -- pragma Inline_Always ( NAME {, NAME} );
9685 when Pragma_Inline_Always =>
9688 -- Pragma always active unless in CodePeer or Alfa mode, since
9689 -- this causes walk order issues.
9691 if not (CodePeer_Mode or Alfa_Mode) then
9692 Process_Inline (True);
9695 --------------------
9696 -- Inline_Generic --
9697 --------------------
9699 -- pragma Inline_Generic (NAME {, NAME});
9701 when Pragma_Inline_Generic =>
9703 Process_Generic_List;
9705 ----------------------
9706 -- Inspection_Point --
9707 ----------------------
9709 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9711 when Pragma_Inspection_Point => Inspection_Point : declare
9716 if Arg_Count > 0 then
9719 Exp := Get_Pragma_Arg (Arg);
9722 if not Is_Entity_Name (Exp)
9723 or else not Is_Object (Entity (Exp))
9725 Error_Pragma_Arg ("object name required", Arg);
9732 end Inspection_Point;
9738 -- pragma Interface (
9739 -- [ Convention =>] convention_IDENTIFIER,
9740 -- [ Entity =>] local_NAME
9741 -- [, [External_Name =>] static_string_EXPRESSION ]
9742 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9744 when Pragma_Interface =>
9751 Check_At_Least_N_Arguments (2);
9752 Check_At_Most_N_Arguments (4);
9753 Process_Import_Or_Interface;
9755 -- In Ada 2005, the permission to use Interface (a reserved word)
9756 -- as a pragma name is considered an obsolescent feature.
9758 if Ada_Version >= Ada_2005 then
9760 (No_Obsolescent_Features, Pragma_Identifier (N));
9763 --------------------
9764 -- Interface_Name --
9765 --------------------
9767 -- pragma Interface_Name (
9768 -- [ Entity =>] local_NAME
9769 -- [,[External_Name =>] static_string_EXPRESSION ]
9770 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9772 when Pragma_Interface_Name => Interface_Name : declare
9781 ((Name_Entity, Name_External_Name, Name_Link_Name));
9782 Check_At_Least_N_Arguments (2);
9783 Check_At_Most_N_Arguments (3);
9784 Id := Get_Pragma_Arg (Arg1);
9787 if not Is_Entity_Name (Id) then
9789 ("first argument for pragma% must be entity name", Arg1);
9790 elsif Etype (Id) = Any_Type then
9793 Def_Id := Entity (Id);
9796 -- Special DEC-compatible processing for the object case, forces
9797 -- object to be imported.
9799 if Ekind (Def_Id) = E_Variable then
9800 Kill_Size_Check_Code (Def_Id);
9801 Note_Possible_Modification (Id, Sure => False);
9803 -- Initialization is not allowed for imported variable
9805 if Present (Expression (Parent (Def_Id)))
9806 and then Comes_From_Source (Expression (Parent (Def_Id)))
9808 Error_Msg_Sloc := Sloc (Def_Id);
9810 ("no initialization allowed for declaration of& #",
9814 -- For compatibility, support VADS usage of providing both
9815 -- pragmas Interface and Interface_Name to obtain the effect
9816 -- of a single Import pragma.
9818 if Is_Imported (Def_Id)
9819 and then Present (First_Rep_Item (Def_Id))
9820 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9822 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9826 Set_Imported (Def_Id);
9829 Set_Is_Public (Def_Id);
9830 Process_Interface_Name (Def_Id, Arg2, Arg3);
9833 -- Otherwise must be subprogram
9835 elsif not Is_Subprogram (Def_Id) then
9837 ("argument of pragma% is not subprogram", Arg1);
9840 Check_At_Most_N_Arguments (3);
9844 -- Loop through homonyms
9847 Def_Id := Get_Base_Subprogram (Hom_Id);
9849 if Is_Imported (Def_Id) then
9850 Process_Interface_Name (Def_Id, Arg2, Arg3);
9854 exit when From_Aspect_Specification (N);
9855 Hom_Id := Homonym (Hom_Id);
9857 exit when No (Hom_Id)
9858 or else Scope (Hom_Id) /= Current_Scope;
9863 ("argument of pragma% is not imported subprogram",
9869 -----------------------
9870 -- Interrupt_Handler --
9871 -----------------------
9873 -- pragma Interrupt_Handler (handler_NAME);
9875 when Pragma_Interrupt_Handler =>
9876 Check_Ada_83_Warning;
9877 Check_Arg_Count (1);
9878 Check_No_Identifiers;
9880 if No_Run_Time_Mode then
9881 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9883 Check_Interrupt_Or_Attach_Handler;
9884 Process_Interrupt_Or_Attach_Handler;
9887 ------------------------
9888 -- Interrupt_Priority --
9889 ------------------------
9891 -- pragma Interrupt_Priority [(EXPRESSION)];
9893 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9894 P : constant Node_Id := Parent (N);
9898 Check_Ada_83_Warning;
9900 if Arg_Count /= 0 then
9901 Arg := Get_Pragma_Arg (Arg1);
9902 Check_Arg_Count (1);
9903 Check_No_Identifiers;
9905 -- The expression must be analyzed in the special manner
9906 -- described in "Handling of Default and Per-Object
9907 -- Expressions" in sem.ads.
9909 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9912 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9916 elsif Has_Pragma_Priority (P) then
9917 Error_Pragma ("duplicate pragma% not allowed");
9920 Set_Has_Pragma_Priority (P, True);
9921 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9923 end Interrupt_Priority;
9925 ---------------------
9926 -- Interrupt_State --
9927 ---------------------
9929 -- pragma Interrupt_State (
9930 -- [Name =>] INTERRUPT_ID,
9931 -- [State =>] INTERRUPT_STATE);
9933 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9934 -- INTERRUPT_STATE => System | Runtime | User
9936 -- Note: if the interrupt id is given as an identifier, then it must
9937 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9938 -- given as a static integer expression which must be in the range of
9939 -- Ada.Interrupts.Interrupt_ID.
9941 when Pragma_Interrupt_State => Interrupt_State : declare
9943 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9944 -- This is the entity Ada.Interrupts.Interrupt_ID;
9946 State_Type : Character;
9947 -- Set to 's'/'r'/'u' for System/Runtime/User
9950 -- Index to entry in Interrupt_States table
9953 -- Value of interrupt
9955 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9956 -- The first argument to the pragma
9958 Int_Ent : Entity_Id;
9959 -- Interrupt entity in Ada.Interrupts.Names
9963 Check_Arg_Order ((Name_Name, Name_State));
9964 Check_Arg_Count (2);
9966 Check_Optional_Identifier (Arg1, Name_Name);
9967 Check_Optional_Identifier (Arg2, Name_State);
9968 Check_Arg_Is_Identifier (Arg2);
9970 -- First argument is identifier
9972 if Nkind (Arg1X) = N_Identifier then
9974 -- Search list of names in Ada.Interrupts.Names
9976 Int_Ent := First_Entity (RTE (RE_Names));
9978 if No (Int_Ent) then
9979 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9981 elsif Chars (Int_Ent) = Chars (Arg1X) then
9982 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9986 Next_Entity (Int_Ent);
9989 -- First argument is not an identifier, so it must be a static
9990 -- expression of type Ada.Interrupts.Interrupt_ID.
9993 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9994 Int_Val := Expr_Value (Arg1X);
9996 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9998 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10001 ("value not in range of type " &
10002 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10008 case Chars (Get_Pragma_Arg (Arg2)) is
10009 when Name_Runtime => State_Type := 'r';
10010 when Name_System => State_Type := 's';
10011 when Name_User => State_Type := 'u';
10014 Error_Pragma_Arg ("invalid interrupt state", Arg2);
10017 -- Check if entry is already stored
10019 IST_Num := Interrupt_States.First;
10021 -- If entry not found, add it
10023 if IST_Num > Interrupt_States.Last then
10024 Interrupt_States.Append
10025 ((Interrupt_Number => UI_To_Int (Int_Val),
10026 Interrupt_State => State_Type,
10027 Pragma_Loc => Loc));
10030 -- Case of entry for the same entry
10032 elsif Int_Val = Interrupt_States.Table (IST_Num).
10035 -- If state matches, done, no need to make redundant entry
10038 State_Type = Interrupt_States.Table (IST_Num).
10041 -- Otherwise if state does not match, error
10044 Interrupt_States.Table (IST_Num).Pragma_Loc;
10046 ("state conflicts with that given #", Arg2);
10050 IST_Num := IST_Num + 1;
10052 end Interrupt_State;
10058 -- pragma Invariant
10059 -- ([Entity =>] type_LOCAL_NAME,
10060 -- [Check =>] EXPRESSION
10061 -- [,[Message =>] String_Expression]);
10063 when Pragma_Invariant => Invariant : declare
10068 pragma Unreferenced (Discard);
10072 Check_At_Least_N_Arguments (2);
10073 Check_At_Most_N_Arguments (3);
10074 Check_Optional_Identifier (Arg1, Name_Entity);
10075 Check_Optional_Identifier (Arg2, Name_Check);
10077 if Arg_Count = 3 then
10078 Check_Optional_Identifier (Arg3, Name_Message);
10079 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10082 Check_Arg_Is_Local_Name (Arg1);
10084 Type_Id := Get_Pragma_Arg (Arg1);
10085 Find_Type (Type_Id);
10086 Typ := Entity (Type_Id);
10088 if Typ = Any_Type then
10091 elsif not Ekind_In (Typ, E_Private_Type,
10092 E_Record_Type_With_Private,
10093 E_Limited_Private_Type)
10096 ("pragma% only allowed for private type", Arg1);
10099 -- Note that the type has at least one invariant, and also that
10100 -- it has inheritable invariants if we have Invariant'Class.
10102 Set_Has_Invariants (Typ);
10104 if Class_Present (N) then
10105 Set_Has_Inheritable_Invariants (Typ);
10108 -- The remaining processing is simply to link the pragma on to
10109 -- the rep item chain, for processing when the type is frozen.
10110 -- This is accomplished by a call to Rep_Item_Too_Late.
10112 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10115 ----------------------
10116 -- Java_Constructor --
10117 ----------------------
10119 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10121 -- Also handles pragma CIL_Constructor
10123 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10124 Java_Constructor : declare
10125 Convention : Convention_Id;
10126 Def_Id : Entity_Id;
10127 Hom_Id : Entity_Id;
10129 This_Formal : Entity_Id;
10133 Check_Arg_Count (1);
10134 Check_Optional_Identifier (Arg1, Name_Entity);
10135 Check_Arg_Is_Local_Name (Arg1);
10137 Id := Get_Pragma_Arg (Arg1);
10138 Find_Program_Unit_Name (Id);
10140 -- If we did not find the name, we are done
10142 if Etype (Id) = Any_Type then
10146 -- Check wrong use of pragma in wrong VM target
10148 if VM_Target = No_VM then
10151 elsif VM_Target = CLI_Target
10152 and then Prag_Id = Pragma_Java_Constructor
10154 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10156 elsif VM_Target = JVM_Target
10157 and then Prag_Id = Pragma_CIL_Constructor
10159 Error_Pragma ("must use pragma 'Java_'Constructor");
10163 when Pragma_CIL_Constructor => Convention := Convention_CIL;
10164 when Pragma_Java_Constructor => Convention := Convention_Java;
10165 when others => null;
10168 Hom_Id := Entity (Id);
10170 -- Loop through homonyms
10173 Def_Id := Get_Base_Subprogram (Hom_Id);
10175 -- The constructor is required to be a function
10177 if Ekind (Def_Id) /= E_Function then
10178 if VM_Target = JVM_Target then
10180 ("pragma% requires function returning a " &
10181 "'Java access type", Def_Id);
10184 ("pragma% requires function returning a " &
10185 "'C'I'L access type", Def_Id);
10189 -- Check arguments: For tagged type the first formal must be
10190 -- named "this" and its type must be a named access type
10191 -- designating a class-wide tagged type that has convention
10192 -- CIL/Java. The first formal must also have a null default
10193 -- value. For example:
10195 -- type Typ is tagged ...
10196 -- type Ref is access all Typ;
10197 -- pragma Convention (CIL, Typ);
10199 -- function New_Typ (This : Ref) return Ref;
10200 -- function New_Typ (This : Ref; I : Integer) return Ref;
10201 -- pragma Cil_Constructor (New_Typ);
10203 -- Reason: The first formal must NOT be a primitive of the
10206 -- This rule also applies to constructors of delegates used
10207 -- to interface with standard target libraries. For example:
10209 -- type Delegate is access procedure ...
10210 -- pragma Import (CIL, Delegate, ...);
10212 -- function new_Delegate
10213 -- (This : Delegate := null; ... ) return Delegate;
10215 -- For value-types this rule does not apply.
10217 if not Is_Value_Type (Etype (Def_Id)) then
10218 if No (First_Formal (Def_Id)) then
10219 Error_Msg_Name_1 := Pname;
10220 Error_Msg_N ("% function must have parameters", Def_Id);
10224 -- In the JRE library we have several occurrences in which
10225 -- the "this" parameter is not the first formal.
10227 This_Formal := First_Formal (Def_Id);
10229 -- In the JRE library we have several occurrences in which
10230 -- the "this" parameter is not the first formal. Search for
10233 if VM_Target = JVM_Target then
10234 while Present (This_Formal)
10235 and then Get_Name_String (Chars (This_Formal)) /= "this"
10237 Next_Formal (This_Formal);
10240 if No (This_Formal) then
10241 This_Formal := First_Formal (Def_Id);
10245 -- Warning: The first parameter should be named "this".
10246 -- We temporarily allow it because we have the following
10247 -- case in the Java runtime (file s-osinte.ads) ???
10249 -- function new_Thread
10250 -- (Self_Id : System.Address) return Thread_Id;
10251 -- pragma Java_Constructor (new_Thread);
10253 if VM_Target = JVM_Target
10254 and then Get_Name_String (Chars (First_Formal (Def_Id)))
10256 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10260 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10261 Error_Msg_Name_1 := Pname;
10263 ("first formal of % function must be named `this`",
10264 Parent (This_Formal));
10266 elsif not Is_Access_Type (Etype (This_Formal)) then
10267 Error_Msg_Name_1 := Pname;
10269 ("first formal of % function must be an access type",
10270 Parameter_Type (Parent (This_Formal)));
10272 -- For delegates the type of the first formal must be a
10273 -- named access-to-subprogram type (see previous example)
10275 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10276 and then Ekind (Etype (This_Formal))
10277 /= E_Access_Subprogram_Type
10279 Error_Msg_Name_1 := Pname;
10281 ("first formal of % function must be a named access" &
10282 " to subprogram type",
10283 Parameter_Type (Parent (This_Formal)));
10285 -- Warning: We should reject anonymous access types because
10286 -- the constructor must not be handled as a primitive of the
10287 -- tagged type. We temporarily allow it because this profile
10288 -- is currently generated by cil2ada???
10290 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10291 and then not Ekind_In (Etype (This_Formal),
10293 E_General_Access_Type,
10294 E_Anonymous_Access_Type)
10296 Error_Msg_Name_1 := Pname;
10298 ("first formal of % function must be a named access" &
10300 Parameter_Type (Parent (This_Formal)));
10302 elsif Atree.Convention
10303 (Designated_Type (Etype (This_Formal))) /= Convention
10305 Error_Msg_Name_1 := Pname;
10307 if Convention = Convention_Java then
10309 ("pragma% requires convention 'Cil in designated" &
10311 Parameter_Type (Parent (This_Formal)));
10314 ("pragma% requires convention 'Java in designated" &
10316 Parameter_Type (Parent (This_Formal)));
10319 elsif No (Expression (Parent (This_Formal)))
10320 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10322 Error_Msg_Name_1 := Pname;
10324 ("pragma% requires first formal with default `null`",
10325 Parameter_Type (Parent (This_Formal)));
10329 -- Check result type: the constructor must be a function
10331 -- * a value type (only allowed in the CIL compiler)
10332 -- * an access-to-subprogram type with convention Java/CIL
10333 -- * an access-type designating a type that has convention
10336 if Is_Value_Type (Etype (Def_Id)) then
10339 -- Access-to-subprogram type with convention Java/CIL
10341 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10342 if Atree.Convention (Etype (Def_Id)) /= Convention then
10343 if Convention = Convention_Java then
10345 ("pragma% requires function returning a " &
10346 "'Java access type", Arg1);
10348 pragma Assert (Convention = Convention_CIL);
10350 ("pragma% requires function returning a " &
10351 "'C'I'L access type", Arg1);
10355 elsif Ekind (Etype (Def_Id)) in Access_Kind then
10356 if not Ekind_In (Etype (Def_Id), E_Access_Type,
10357 E_General_Access_Type)
10360 (Designated_Type (Etype (Def_Id))) /= Convention
10362 Error_Msg_Name_1 := Pname;
10364 if Convention = Convention_Java then
10366 ("pragma% requires function returning a named" &
10367 "'Java access type", Arg1);
10370 ("pragma% requires function returning a named" &
10371 "'C'I'L access type", Arg1);
10376 Set_Is_Constructor (Def_Id);
10377 Set_Convention (Def_Id, Convention);
10378 Set_Is_Imported (Def_Id);
10380 exit when From_Aspect_Specification (N);
10381 Hom_Id := Homonym (Hom_Id);
10383 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10385 end Java_Constructor;
10387 ----------------------
10388 -- Java_Interface --
10389 ----------------------
10391 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
10393 when Pragma_Java_Interface => Java_Interface : declare
10399 Check_Arg_Count (1);
10400 Check_Optional_Identifier (Arg1, Name_Entity);
10401 Check_Arg_Is_Local_Name (Arg1);
10403 Arg := Get_Pragma_Arg (Arg1);
10406 if Etype (Arg) = Any_Type then
10410 if not Is_Entity_Name (Arg)
10411 or else not Is_Type (Entity (Arg))
10413 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10416 Typ := Underlying_Type (Entity (Arg));
10418 -- For now simply check some of the semantic constraints on the
10419 -- type. This currently leaves out some restrictions on interface
10420 -- types, namely that the parent type must be java.lang.Object.Typ
10421 -- and that all primitives of the type should be declared
10424 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10425 Error_Pragma_Arg ("pragma% requires an abstract "
10426 & "tagged type", Arg1);
10428 elsif not Has_Discriminants (Typ)
10429 or else Ekind (Etype (First_Discriminant (Typ)))
10430 /= E_Anonymous_Access_Type
10432 not Is_Class_Wide_Type
10433 (Designated_Type (Etype (First_Discriminant (Typ))))
10436 ("type must have a class-wide access discriminant", Arg1);
10438 end Java_Interface;
10444 -- pragma Keep_Names ([On => ] local_NAME);
10446 when Pragma_Keep_Names => Keep_Names : declare
10451 Check_Arg_Count (1);
10452 Check_Optional_Identifier (Arg1, Name_On);
10453 Check_Arg_Is_Local_Name (Arg1);
10455 Arg := Get_Pragma_Arg (Arg1);
10458 if Etype (Arg) = Any_Type then
10462 if not Is_Entity_Name (Arg)
10463 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10466 ("pragma% requires a local enumeration type", Arg1);
10469 Set_Discard_Names (Entity (Arg), False);
10476 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10478 when Pragma_License =>
10480 Check_Arg_Count (1);
10481 Check_No_Identifiers;
10482 Check_Valid_Configuration_Pragma;
10483 Check_Arg_Is_Identifier (Arg1);
10486 Sind : constant Source_File_Index :=
10487 Source_Index (Current_Sem_Unit);
10490 case Chars (Get_Pragma_Arg (Arg1)) is
10492 Set_License (Sind, GPL);
10494 when Name_Modified_GPL =>
10495 Set_License (Sind, Modified_GPL);
10497 when Name_Restricted =>
10498 Set_License (Sind, Restricted);
10500 when Name_Unrestricted =>
10501 Set_License (Sind, Unrestricted);
10504 Error_Pragma_Arg ("invalid license name", Arg1);
10512 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10514 when Pragma_Link_With => Link_With : declare
10520 if Operating_Mode = Generate_Code
10521 and then In_Extended_Main_Source_Unit (N)
10523 Check_At_Least_N_Arguments (1);
10524 Check_No_Identifiers;
10525 Check_Is_In_Decl_Part_Or_Package_Spec;
10526 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10530 while Present (Arg) loop
10531 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10533 -- Store argument, converting sequences of spaces to a
10534 -- single null character (this is one of the differences
10535 -- in processing between Link_With and Linker_Options).
10537 Arg_Store : declare
10538 C : constant Char_Code := Get_Char_Code (' ');
10539 S : constant String_Id :=
10540 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10541 L : constant Nat := String_Length (S);
10544 procedure Skip_Spaces;
10545 -- Advance F past any spaces
10551 procedure Skip_Spaces is
10553 while F <= L and then Get_String_Char (S, F) = C loop
10558 -- Start of processing for Arg_Store
10561 Skip_Spaces; -- skip leading spaces
10563 -- Loop through characters, changing any embedded
10564 -- sequence of spaces to a single null character (this
10565 -- is how Link_With/Linker_Options differ)
10568 if Get_String_Char (S, F) = C then
10571 Store_String_Char (ASCII.NUL);
10574 Store_String_Char (Get_String_Char (S, F));
10582 if Present (Arg) then
10583 Store_String_Char (ASCII.NUL);
10587 Store_Linker_Option_String (End_String);
10595 -- pragma Linker_Alias (
10596 -- [Entity =>] LOCAL_NAME
10597 -- [Target =>] static_string_EXPRESSION);
10599 when Pragma_Linker_Alias =>
10601 Check_Arg_Order ((Name_Entity, Name_Target));
10602 Check_Arg_Count (2);
10603 Check_Optional_Identifier (Arg1, Name_Entity);
10604 Check_Optional_Identifier (Arg2, Name_Target);
10605 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10606 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10608 -- The only processing required is to link this item on to the
10609 -- list of rep items for the given entity. This is accomplished
10610 -- by the call to Rep_Item_Too_Late (when no error is detected
10611 -- and False is returned).
10613 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10616 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10619 ------------------------
10620 -- Linker_Constructor --
10621 ------------------------
10623 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10625 -- Code is shared with Linker_Destructor
10627 -----------------------
10628 -- Linker_Destructor --
10629 -----------------------
10631 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10633 when Pragma_Linker_Constructor |
10634 Pragma_Linker_Destructor =>
10635 Linker_Constructor : declare
10641 Check_Arg_Count (1);
10642 Check_No_Identifiers;
10643 Check_Arg_Is_Local_Name (Arg1);
10644 Arg1_X := Get_Pragma_Arg (Arg1);
10646 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10648 if not Is_Library_Level_Entity (Proc) then
10650 ("argument for pragma% must be library level entity", Arg1);
10653 -- The only processing required is to link this item on to the
10654 -- list of rep items for the given entity. This is accomplished
10655 -- by the call to Rep_Item_Too_Late (when no error is detected
10656 -- and False is returned).
10658 if Rep_Item_Too_Late (Proc, N) then
10661 Set_Has_Gigi_Rep_Item (Proc);
10663 end Linker_Constructor;
10665 --------------------
10666 -- Linker_Options --
10667 --------------------
10669 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10671 when Pragma_Linker_Options => Linker_Options : declare
10675 Check_Ada_83_Warning;
10676 Check_No_Identifiers;
10677 Check_Arg_Count (1);
10678 Check_Is_In_Decl_Part_Or_Package_Spec;
10679 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10680 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10683 while Present (Arg) loop
10684 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10685 Store_String_Char (ASCII.NUL);
10687 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10691 if Operating_Mode = Generate_Code
10692 and then In_Extended_Main_Source_Unit (N)
10694 Store_Linker_Option_String (End_String);
10696 end Linker_Options;
10698 --------------------
10699 -- Linker_Section --
10700 --------------------
10702 -- pragma Linker_Section (
10703 -- [Entity =>] LOCAL_NAME
10704 -- [Section =>] static_string_EXPRESSION);
10706 when Pragma_Linker_Section =>
10708 Check_Arg_Order ((Name_Entity, Name_Section));
10709 Check_Arg_Count (2);
10710 Check_Optional_Identifier (Arg1, Name_Entity);
10711 Check_Optional_Identifier (Arg2, Name_Section);
10712 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10713 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10715 -- This pragma applies only to objects
10717 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10718 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10721 -- The only processing required is to link this item on to the
10722 -- list of rep items for the given entity. This is accomplished
10723 -- by the call to Rep_Item_Too_Late (when no error is detected
10724 -- and False is returned).
10726 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10729 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10736 -- pragma List (On | Off)
10738 -- There is nothing to do here, since we did all the processing for
10739 -- this pragma in Par.Prag (so that it works properly even in syntax
10742 when Pragma_List =>
10745 --------------------
10746 -- Locking_Policy --
10747 --------------------
10749 -- pragma Locking_Policy (policy_IDENTIFIER);
10751 when Pragma_Locking_Policy => declare
10755 Check_Ada_83_Warning;
10756 Check_Arg_Count (1);
10757 Check_No_Identifiers;
10758 Check_Arg_Is_Locking_Policy (Arg1);
10759 Check_Valid_Configuration_Pragma;
10760 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10761 LP := Fold_Upper (Name_Buffer (1));
10763 if Locking_Policy /= ' '
10764 and then Locking_Policy /= LP
10766 Error_Msg_Sloc := Locking_Policy_Sloc;
10767 Error_Pragma ("locking policy incompatible with policy#");
10769 -- Set new policy, but always preserve System_Location since we
10770 -- like the error message with the run time name.
10773 Locking_Policy := LP;
10775 if Locking_Policy_Sloc /= System_Location then
10776 Locking_Policy_Sloc := Loc;
10785 -- pragma Long_Float (D_Float | G_Float);
10787 when Pragma_Long_Float =>
10789 Check_Valid_Configuration_Pragma;
10790 Check_Arg_Count (1);
10791 Check_No_Identifier (Arg1);
10792 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10794 if not OpenVMS_On_Target then
10795 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10800 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10801 if Opt.Float_Format_Long = 'G' then
10802 Error_Pragma ("G_Float previously specified");
10805 Opt.Float_Format_Long := 'D';
10807 -- G_Float case (this is the default, does not need overriding)
10810 if Opt.Float_Format_Long = 'D' then
10811 Error_Pragma ("D_Float previously specified");
10814 Opt.Float_Format_Long := 'G';
10817 Set_Standard_Fpt_Formats;
10819 -----------------------
10820 -- Machine_Attribute --
10821 -----------------------
10823 -- pragma Machine_Attribute (
10824 -- [Entity =>] LOCAL_NAME,
10825 -- [Attribute_Name =>] static_string_EXPRESSION
10826 -- [, [Info =>] static_EXPRESSION] );
10828 when Pragma_Machine_Attribute => Machine_Attribute : declare
10829 Def_Id : Entity_Id;
10833 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10835 if Arg_Count = 3 then
10836 Check_Optional_Identifier (Arg3, Name_Info);
10837 Check_Arg_Is_Static_Expression (Arg3);
10839 Check_Arg_Count (2);
10842 Check_Optional_Identifier (Arg1, Name_Entity);
10843 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10844 Check_Arg_Is_Local_Name (Arg1);
10845 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10846 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10848 if Is_Access_Type (Def_Id) then
10849 Def_Id := Designated_Type (Def_Id);
10852 if Rep_Item_Too_Early (Def_Id, N) then
10856 Def_Id := Underlying_Type (Def_Id);
10858 -- The only processing required is to link this item on to the
10859 -- list of rep items for the given entity. This is accomplished
10860 -- by the call to Rep_Item_Too_Late (when no error is detected
10861 -- and False is returned).
10863 if Rep_Item_Too_Late (Def_Id, N) then
10866 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10868 end Machine_Attribute;
10875 -- (MAIN_OPTION [, MAIN_OPTION]);
10878 -- [STACK_SIZE =>] static_integer_EXPRESSION
10879 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10880 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10882 when Pragma_Main => Main : declare
10883 Args : Args_List (1 .. 3);
10884 Names : constant Name_List (1 .. 3) := (
10886 Name_Task_Stack_Size_Default,
10887 Name_Time_Slicing_Enabled);
10893 Gather_Associations (Names, Args);
10895 for J in 1 .. 2 loop
10896 if Present (Args (J)) then
10897 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10901 if Present (Args (3)) then
10902 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10906 while Present (Nod) loop
10907 if Nkind (Nod) = N_Pragma
10908 and then Pragma_Name (Nod) = Name_Main
10910 Error_Msg_Name_1 := Pname;
10911 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10922 -- pragma Main_Storage
10923 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10925 -- MAIN_STORAGE_OPTION ::=
10926 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10927 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10929 when Pragma_Main_Storage => Main_Storage : declare
10930 Args : Args_List (1 .. 2);
10931 Names : constant Name_List (1 .. 2) := (
10932 Name_Working_Storage,
10939 Gather_Associations (Names, Args);
10941 for J in 1 .. 2 loop
10942 if Present (Args (J)) then
10943 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10947 Check_In_Main_Program;
10950 while Present (Nod) loop
10951 if Nkind (Nod) = N_Pragma
10952 and then Pragma_Name (Nod) = Name_Main_Storage
10954 Error_Msg_Name_1 := Pname;
10955 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10966 -- pragma Memory_Size (NUMERIC_LITERAL)
10968 when Pragma_Memory_Size =>
10971 -- Memory size is simply ignored
10973 Check_No_Identifiers;
10974 Check_Arg_Count (1);
10975 Check_Arg_Is_Integer_Literal (Arg1);
10983 -- The only correct use of this pragma is on its own in a file, in
10984 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10985 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10986 -- check for a file containing nothing but a No_Body pragma). If we
10987 -- attempt to process it during normal semantics processing, it means
10988 -- it was misplaced.
10990 when Pragma_No_Body =>
10998 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
11000 when Pragma_No_Return => No_Return : declare
11008 Check_At_Least_N_Arguments (1);
11010 -- Loop through arguments of pragma
11013 while Present (Arg) loop
11014 Check_Arg_Is_Local_Name (Arg);
11015 Id := Get_Pragma_Arg (Arg);
11018 if not Is_Entity_Name (Id) then
11019 Error_Pragma_Arg ("entity name required", Arg);
11022 if Etype (Id) = Any_Type then
11026 -- Loop to find matching procedures
11031 and then Scope (E) = Current_Scope
11033 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11036 -- Set flag on any alias as well
11038 if Is_Overloadable (E) and then Present (Alias (E)) then
11039 Set_No_Return (Alias (E));
11045 exit when From_Aspect_Specification (N);
11050 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11061 -- pragma No_Run_Time;
11063 -- Note: this pragma is retained for backwards compatibility. See
11064 -- body of Rtsfind for full details on its handling.
11066 when Pragma_No_Run_Time =>
11068 Check_Valid_Configuration_Pragma;
11069 Check_Arg_Count (0);
11071 No_Run_Time_Mode := True;
11072 Configurable_Run_Time_Mode := True;
11074 -- Set Duration to 32 bits if word size is 32
11076 if Ttypes.System_Word_Size = 32 then
11077 Duration_32_Bits_On_Target := True;
11080 -- Set appropriate restrictions
11082 Set_Restriction (No_Finalization, N);
11083 Set_Restriction (No_Exception_Handlers, N);
11084 Set_Restriction (Max_Tasks, N, 0);
11085 Set_Restriction (No_Tasking, N);
11087 ------------------------
11088 -- No_Strict_Aliasing --
11089 ------------------------
11091 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11093 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11098 Check_At_Most_N_Arguments (1);
11100 if Arg_Count = 0 then
11101 Check_Valid_Configuration_Pragma;
11102 Opt.No_Strict_Aliasing := True;
11105 Check_Optional_Identifier (Arg2, Name_Entity);
11106 Check_Arg_Is_Local_Name (Arg1);
11107 E_Id := Entity (Get_Pragma_Arg (Arg1));
11109 if E_Id = Any_Type then
11111 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11112 Error_Pragma_Arg ("pragma% requires access type", Arg1);
11115 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11117 end No_Strict_Aliasing;
11119 -----------------------
11120 -- Normalize_Scalars --
11121 -----------------------
11123 -- pragma Normalize_Scalars;
11125 when Pragma_Normalize_Scalars =>
11126 Check_Ada_83_Warning;
11127 Check_Arg_Count (0);
11128 Check_Valid_Configuration_Pragma;
11130 -- Normalize_Scalars creates false positives in CodePeer, and
11131 -- incorrect negative results in Alfa mode, so ignore this pragma
11134 if not (CodePeer_Mode or Alfa_Mode) then
11135 Normalize_Scalars := True;
11136 Init_Or_Norm_Scalars := True;
11143 -- pragma Obsolescent;
11145 -- pragma Obsolescent (
11146 -- [Message =>] static_string_EXPRESSION
11147 -- [,[Version =>] Ada_05]]);
11149 -- pragma Obsolescent (
11150 -- [Entity =>] NAME
11151 -- [,[Message =>] static_string_EXPRESSION
11152 -- [,[Version =>] Ada_05]] );
11154 when Pragma_Obsolescent => Obsolescent : declare
11158 procedure Set_Obsolescent (E : Entity_Id);
11159 -- Given an entity Ent, mark it as obsolescent if appropriate
11161 ---------------------
11162 -- Set_Obsolescent --
11163 ---------------------
11165 procedure Set_Obsolescent (E : Entity_Id) is
11174 -- Entity name was given
11176 if Present (Ename) then
11178 -- If entity name matches, we are fine. Save entity in
11179 -- pragma argument, for ASIS use.
11181 if Chars (Ename) = Chars (Ent) then
11182 Set_Entity (Ename, Ent);
11183 Generate_Reference (Ent, Ename);
11185 -- If entity name does not match, only possibility is an
11186 -- enumeration literal from an enumeration type declaration.
11188 elsif Ekind (Ent) /= E_Enumeration_Type then
11190 ("pragma % entity name does not match declaration");
11193 Ent := First_Literal (E);
11197 ("pragma % entity name does not match any " &
11198 "enumeration literal");
11200 elsif Chars (Ent) = Chars (Ename) then
11201 Set_Entity (Ename, Ent);
11202 Generate_Reference (Ent, Ename);
11206 Ent := Next_Literal (Ent);
11212 -- Ent points to entity to be marked
11214 if Arg_Count >= 1 then
11216 -- Deal with static string argument
11218 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11219 S := Strval (Get_Pragma_Arg (Arg1));
11221 for J in 1 .. String_Length (S) loop
11222 if not In_Character_Range (Get_String_Char (S, J)) then
11224 ("pragma% argument does not allow wide characters",
11229 Obsolescent_Warnings.Append
11230 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11232 -- Check for Ada_05 parameter
11234 if Arg_Count /= 1 then
11235 Check_Arg_Count (2);
11238 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11241 Check_Arg_Is_Identifier (Argx);
11243 if Chars (Argx) /= Name_Ada_05 then
11244 Error_Msg_Name_2 := Name_Ada_05;
11246 ("only allowed argument for pragma% is %", Argx);
11249 if Ada_Version_Explicit < Ada_2005
11250 or else not Warn_On_Ada_2005_Compatibility
11258 -- Set flag if pragma active
11261 Set_Is_Obsolescent (Ent);
11265 end Set_Obsolescent;
11267 -- Start of processing for pragma Obsolescent
11272 Check_At_Most_N_Arguments (3);
11274 -- See if first argument specifies an entity name
11278 (Chars (Arg1) = Name_Entity
11280 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11282 N_Operator_Symbol))
11284 Ename := Get_Pragma_Arg (Arg1);
11286 -- Eliminate first argument, so we can share processing
11290 Arg_Count := Arg_Count - 1;
11292 -- No Entity name argument given
11298 if Arg_Count >= 1 then
11299 Check_Optional_Identifier (Arg1, Name_Message);
11301 if Arg_Count = 2 then
11302 Check_Optional_Identifier (Arg2, Name_Version);
11306 -- Get immediately preceding declaration
11309 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11313 -- Cases where we do not follow anything other than another pragma
11317 -- First case: library level compilation unit declaration with
11318 -- the pragma immediately following the declaration.
11320 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11322 (Defining_Entity (Unit (Parent (Parent (N)))));
11325 -- Case 2: library unit placement for package
11329 Ent : constant Entity_Id := Find_Lib_Unit_Name;
11331 if Is_Package_Or_Generic_Package (Ent) then
11332 Set_Obsolescent (Ent);
11338 -- Cases where we must follow a declaration
11341 if Nkind (Decl) not in N_Declaration
11342 and then Nkind (Decl) not in N_Later_Decl_Item
11343 and then Nkind (Decl) not in N_Generic_Declaration
11344 and then Nkind (Decl) not in N_Renaming_Declaration
11347 ("pragma% misplaced, "
11348 & "must immediately follow a declaration");
11351 Set_Obsolescent (Defining_Entity (Decl));
11361 -- pragma Optimize (Time | Space | Off);
11363 -- The actual check for optimize is done in Gigi. Note that this
11364 -- pragma does not actually change the optimization setting, it
11365 -- simply checks that it is consistent with the pragma.
11367 when Pragma_Optimize =>
11368 Check_No_Identifiers;
11369 Check_Arg_Count (1);
11370 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11372 ------------------------
11373 -- Optimize_Alignment --
11374 ------------------------
11376 -- pragma Optimize_Alignment (Time | Space | Off);
11378 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11380 Check_No_Identifiers;
11381 Check_Arg_Count (1);
11382 Check_Valid_Configuration_Pragma;
11385 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11389 Opt.Optimize_Alignment := 'T';
11391 Opt.Optimize_Alignment := 'S';
11393 Opt.Optimize_Alignment := 'O';
11395 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11399 -- Set indication that mode is set locally. If we are in fact in a
11400 -- configuration pragma file, this setting is harmless since the
11401 -- switch will get reset anyway at the start of each unit.
11403 Optimize_Alignment_Local := True;
11404 end Optimize_Alignment;
11410 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11412 when Pragma_Ordered => Ordered : declare
11413 Assoc : constant Node_Id := Arg1;
11419 Check_No_Identifiers;
11420 Check_Arg_Count (1);
11421 Check_Arg_Is_Local_Name (Arg1);
11423 Type_Id := Get_Pragma_Arg (Assoc);
11424 Find_Type (Type_Id);
11425 Typ := Entity (Type_Id);
11427 if Typ = Any_Type then
11430 Typ := Underlying_Type (Typ);
11433 if not Is_Enumeration_Type (Typ) then
11434 Error_Pragma ("pragma% must specify enumeration type");
11437 Check_First_Subtype (Arg1);
11438 Set_Has_Pragma_Ordered (Base_Type (Typ));
11445 -- pragma Pack (first_subtype_LOCAL_NAME);
11447 when Pragma_Pack => Pack : declare
11448 Assoc : constant Node_Id := Arg1;
11452 Ignore : Boolean := False;
11455 Check_No_Identifiers;
11456 Check_Arg_Count (1);
11457 Check_Arg_Is_Local_Name (Arg1);
11459 Type_Id := Get_Pragma_Arg (Assoc);
11460 Find_Type (Type_Id);
11461 Typ := Entity (Type_Id);
11464 or else Rep_Item_Too_Early (Typ, N)
11468 Typ := Underlying_Type (Typ);
11471 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11472 Error_Pragma ("pragma% must specify array or record type");
11475 Check_First_Subtype (Arg1);
11476 Check_Duplicate_Pragma (Typ);
11480 if Is_Array_Type (Typ) then
11481 Ctyp := Component_Type (Typ);
11483 -- Ignore pack that does nothing
11485 if Known_Static_Esize (Ctyp)
11486 and then Known_Static_RM_Size (Ctyp)
11487 and then Esize (Ctyp) = RM_Size (Ctyp)
11488 and then Addressable (Esize (Ctyp))
11493 -- Process OK pragma Pack. Note that if there is a separate
11494 -- component clause present, the Pack will be cancelled. This
11495 -- processing is in Freeze.
11497 if not Rep_Item_Too_Late (Typ, N) then
11499 -- In the context of static code analysis, we do not need
11500 -- complex front-end expansions related to pragma Pack,
11501 -- so disable handling of pragma Pack in these cases.
11503 if CodePeer_Mode or Alfa_Mode then
11506 -- Don't attempt any packing for VM targets. We possibly
11507 -- could deal with some cases of array bit-packing, but we
11508 -- don't bother, since this is not a typical kind of
11509 -- representation in the VM context anyway (and would not
11510 -- for example work nicely with the debugger).
11512 elsif VM_Target /= No_VM then
11513 if not GNAT_Mode then
11515 ("?pragma% ignored in this configuration");
11518 -- Normal case where we do the pack action
11522 Set_Is_Packed (Base_Type (Typ));
11523 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11526 Set_Has_Pragma_Pack (Base_Type (Typ));
11530 -- For record types, the pack is always effective
11532 else pragma Assert (Is_Record_Type (Typ));
11533 if not Rep_Item_Too_Late (Typ, N) then
11535 -- Ignore pack request with warning in VM mode (skip warning
11536 -- if we are compiling GNAT run time library).
11538 if VM_Target /= No_VM then
11539 if not GNAT_Mode then
11541 ("?pragma% ignored in this configuration");
11544 -- Normal case of pack request active
11547 Set_Is_Packed (Base_Type (Typ));
11548 Set_Has_Pragma_Pack (Base_Type (Typ));
11549 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11561 -- There is nothing to do here, since we did all the processing for
11562 -- this pragma in Par.Prag (so that it works properly even in syntax
11565 when Pragma_Page =>
11572 -- pragma Passive [(PASSIVE_FORM)];
11574 -- PASSIVE_FORM ::= Semaphore | No
11576 when Pragma_Passive =>
11579 if Nkind (Parent (N)) /= N_Task_Definition then
11580 Error_Pragma ("pragma% must be within task definition");
11583 if Arg_Count /= 0 then
11584 Check_Arg_Count (1);
11585 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11588 ----------------------------------
11589 -- Preelaborable_Initialization --
11590 ----------------------------------
11592 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11594 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11599 Check_Arg_Count (1);
11600 Check_No_Identifiers;
11601 Check_Arg_Is_Identifier (Arg1);
11602 Check_Arg_Is_Local_Name (Arg1);
11603 Check_First_Subtype (Arg1);
11604 Ent := Entity (Get_Pragma_Arg (Arg1));
11606 if not (Is_Private_Type (Ent)
11608 Is_Protected_Type (Ent)
11610 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11613 ("pragma % can only be applied to private, formal derived or "
11614 & "protected type",
11618 -- Give an error if the pragma is applied to a protected type that
11619 -- does not qualify (due to having entries, or due to components
11620 -- that do not qualify).
11622 if Is_Protected_Type (Ent)
11623 and then not Has_Preelaborable_Initialization (Ent)
11626 ("protected type & does not have preelaborable " &
11627 "initialization", Ent);
11629 -- Otherwise mark the type as definitely having preelaborable
11633 Set_Known_To_Have_Preelab_Init (Ent);
11636 if Has_Pragma_Preelab_Init (Ent)
11637 and then Warn_On_Redundant_Constructs
11639 Error_Pragma ("?duplicate pragma%!");
11641 Set_Has_Pragma_Preelab_Init (Ent);
11645 --------------------
11646 -- Persistent_BSS --
11647 --------------------
11649 -- pragma Persistent_BSS [(object_NAME)];
11651 when Pragma_Persistent_BSS => Persistent_BSS : declare
11658 Check_At_Most_N_Arguments (1);
11660 -- Case of application to specific object (one argument)
11662 if Arg_Count = 1 then
11663 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11665 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11667 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11670 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11673 Ent := Entity (Get_Pragma_Arg (Arg1));
11674 Decl := Parent (Ent);
11676 if Rep_Item_Too_Late (Ent, N) then
11680 if Present (Expression (Decl)) then
11682 ("object for pragma% cannot have initialization", Arg1);
11685 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11687 ("object type for pragma% is not potentially persistent",
11691 Check_Duplicate_Pragma (Ent);
11694 Make_Linker_Section_Pragma
11695 (Ent, Sloc (N), ".persistent.bss");
11696 Insert_After (N, Prag);
11699 -- Case of use as configuration pragma with no arguments
11702 Check_Valid_Configuration_Pragma;
11703 Persistent_BSS_Mode := True;
11705 end Persistent_BSS;
11711 -- pragma Polling (ON | OFF);
11713 when Pragma_Polling =>
11715 Check_Arg_Count (1);
11716 Check_No_Identifiers;
11717 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11718 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11720 -------------------
11721 -- Postcondition --
11722 -------------------
11724 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
11725 -- [,[Message =>] String_EXPRESSION]);
11727 when Pragma_Postcondition => Postcondition : declare
11729 pragma Warnings (Off, In_Body);
11733 Check_At_Least_N_Arguments (1);
11734 Check_At_Most_N_Arguments (2);
11735 Check_Optional_Identifier (Arg1, Name_Check);
11737 -- All we need to do here is call the common check procedure,
11738 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11740 Check_Precondition_Postcondition (In_Body);
11747 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
11748 -- [,[Message =>] String_EXPRESSION]);
11750 when Pragma_Precondition => Precondition : declare
11755 Check_At_Least_N_Arguments (1);
11756 Check_At_Most_N_Arguments (2);
11757 Check_Optional_Identifier (Arg1, Name_Check);
11758 Check_Precondition_Postcondition (In_Body);
11760 -- If in spec, nothing more to do. If in body, then we convert the
11761 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11762 -- this whether or not precondition checks are enabled. That works
11763 -- fine since pragma Check will do this check, and will also
11764 -- analyze the condition itself in the proper context.
11769 Chars => Name_Check,
11770 Pragma_Argument_Associations => New_List (
11771 Make_Pragma_Argument_Association (Loc,
11772 Expression => Make_Identifier (Loc, Name_Precondition)),
11774 Make_Pragma_Argument_Association (Sloc (Arg1),
11775 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11777 if Arg_Count = 2 then
11778 Append_To (Pragma_Argument_Associations (N),
11779 Make_Pragma_Argument_Association (Sloc (Arg2),
11780 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11791 -- pragma Predicate
11792 -- ([Entity =>] type_LOCAL_NAME,
11793 -- [Check =>] EXPRESSION);
11795 when Pragma_Predicate => Predicate : declare
11800 pragma Unreferenced (Discard);
11804 Check_Arg_Count (2);
11805 Check_Optional_Identifier (Arg1, Name_Entity);
11806 Check_Optional_Identifier (Arg2, Name_Check);
11808 Check_Arg_Is_Local_Name (Arg1);
11810 Type_Id := Get_Pragma_Arg (Arg1);
11811 Find_Type (Type_Id);
11812 Typ := Entity (Type_Id);
11814 if Typ = Any_Type then
11818 -- The remaining processing is simply to link the pragma on to
11819 -- the rep item chain, for processing when the type is frozen.
11820 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11821 -- mark the type as having predicates.
11823 Set_Has_Predicates (Typ);
11824 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11831 -- pragma Preelaborate [(library_unit_NAME)];
11833 -- Set the flag Is_Preelaborated of program unit name entity
11835 when Pragma_Preelaborate => Preelaborate : declare
11836 Pa : constant Node_Id := Parent (N);
11837 Pk : constant Node_Kind := Nkind (Pa);
11841 Check_Ada_83_Warning;
11842 Check_Valid_Library_Unit_Pragma;
11844 if Nkind (N) = N_Null_Statement then
11848 Ent := Find_Lib_Unit_Name;
11849 Check_Duplicate_Pragma (Ent);
11851 -- This filters out pragmas inside generic parent then
11852 -- show up inside instantiation
11855 and then not (Pk = N_Package_Specification
11856 and then Present (Generic_Parent (Pa)))
11858 if not Debug_Flag_U then
11859 Set_Is_Preelaborated (Ent);
11860 Set_Suppress_Elaboration_Warnings (Ent);
11865 ---------------------
11866 -- Preelaborate_05 --
11867 ---------------------
11869 -- pragma Preelaborate_05 [(library_unit_NAME)];
11871 -- This pragma is useable only in GNAT_Mode, where it is used like
11872 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11873 -- (otherwise it is ignored). This is used to implement AI-362 which
11874 -- recategorizes some run-time packages in Ada 2005 mode.
11876 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11881 Check_Valid_Library_Unit_Pragma;
11883 if not GNAT_Mode then
11884 Error_Pragma ("pragma% only available in GNAT mode");
11887 if Nkind (N) = N_Null_Statement then
11891 -- This is one of the few cases where we need to test the value of
11892 -- Ada_Version_Explicit rather than Ada_Version (which is always
11893 -- set to Ada_2012 in a predefined unit), we need to know the
11894 -- explicit version set to know if this pragma is active.
11896 if Ada_Version_Explicit >= Ada_2005 then
11897 Ent := Find_Lib_Unit_Name;
11898 Set_Is_Preelaborated (Ent);
11899 Set_Suppress_Elaboration_Warnings (Ent);
11901 end Preelaborate_05;
11907 -- pragma Priority (EXPRESSION);
11909 when Pragma_Priority => Priority : declare
11910 P : constant Node_Id := Parent (N);
11914 Check_No_Identifiers;
11915 Check_Arg_Count (1);
11919 if Nkind (P) = N_Subprogram_Body then
11920 Check_In_Main_Program;
11922 Arg := Get_Pragma_Arg (Arg1);
11923 Analyze_And_Resolve (Arg, Standard_Integer);
11927 if not Is_Static_Expression (Arg) then
11928 Flag_Non_Static_Expr
11929 ("main subprogram priority is not static!", Arg);
11932 -- If constraint error, then we already signalled an error
11934 elsif Raises_Constraint_Error (Arg) then
11937 -- Otherwise check in range
11941 Val : constant Uint := Expr_Value (Arg);
11945 or else Val > Expr_Value (Expression
11946 (Parent (RTE (RE_Max_Priority))))
11949 ("main subprogram priority is out of range", Arg1);
11955 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11957 -- Load an arbitrary entity from System.Tasking to make sure
11958 -- this package is implicitly with'ed, since we need to have
11959 -- the tasking run-time active for the pragma Priority to have
11963 Discard : Entity_Id;
11964 pragma Warnings (Off, Discard);
11966 Discard := RTE (RE_Task_List);
11969 -- Task or Protected, must be of type Integer
11971 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11972 Arg := Get_Pragma_Arg (Arg1);
11974 -- The expression must be analyzed in the special manner
11975 -- described in "Handling of Default and Per-Object
11976 -- Expressions" in sem.ads.
11978 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11980 if not Is_Static_Expression (Arg) then
11981 Check_Restriction (Static_Priorities, Arg);
11984 -- Anything else is incorrect
11990 if Has_Pragma_Priority (P) then
11991 Error_Pragma ("duplicate pragma% not allowed");
11993 Set_Has_Pragma_Priority (P, True);
11995 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11996 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11997 -- exp_ch9 should use this ???
12002 -----------------------------------
12003 -- Priority_Specific_Dispatching --
12004 -----------------------------------
12006 -- pragma Priority_Specific_Dispatching (
12007 -- policy_IDENTIFIER,
12008 -- first_priority_EXPRESSION,
12009 -- last_priority_EXPRESSION);
12011 when Pragma_Priority_Specific_Dispatching =>
12012 Priority_Specific_Dispatching : declare
12013 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12014 -- This is the entity System.Any_Priority;
12017 Lower_Bound : Node_Id;
12018 Upper_Bound : Node_Id;
12024 Check_Arg_Count (3);
12025 Check_No_Identifiers;
12026 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12027 Check_Valid_Configuration_Pragma;
12028 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12029 DP := Fold_Upper (Name_Buffer (1));
12031 Lower_Bound := Get_Pragma_Arg (Arg2);
12032 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12033 Lower_Val := Expr_Value (Lower_Bound);
12035 Upper_Bound := Get_Pragma_Arg (Arg3);
12036 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12037 Upper_Val := Expr_Value (Upper_Bound);
12039 -- It is not allowed to use Task_Dispatching_Policy and
12040 -- Priority_Specific_Dispatching in the same partition.
12042 if Task_Dispatching_Policy /= ' ' then
12043 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12045 ("pragma% incompatible with Task_Dispatching_Policy#");
12047 -- Check lower bound in range
12049 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12051 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12054 ("first_priority is out of range", Arg2);
12056 -- Check upper bound in range
12058 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12060 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12063 ("last_priority is out of range", Arg3);
12065 -- Check that the priority range is valid
12067 elsif Lower_Val > Upper_Val then
12069 ("last_priority_expression must be greater than" &
12070 " or equal to first_priority_expression");
12072 -- Store the new policy, but always preserve System_Location since
12073 -- we like the error message with the run-time name.
12076 -- Check overlapping in the priority ranges specified in other
12077 -- Priority_Specific_Dispatching pragmas within the same
12078 -- partition. We can only check those we know about!
12081 Specific_Dispatching.First .. Specific_Dispatching.Last
12083 if Specific_Dispatching.Table (J).First_Priority in
12084 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12085 or else Specific_Dispatching.Table (J).Last_Priority in
12086 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12089 Specific_Dispatching.Table (J).Pragma_Loc;
12091 ("priority range overlaps with "
12092 & "Priority_Specific_Dispatching#");
12096 -- The use of Priority_Specific_Dispatching is incompatible
12097 -- with Task_Dispatching_Policy.
12099 if Task_Dispatching_Policy /= ' ' then
12100 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12102 ("Priority_Specific_Dispatching incompatible "
12103 & "with Task_Dispatching_Policy#");
12106 -- The use of Priority_Specific_Dispatching forces ceiling
12109 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12110 Error_Msg_Sloc := Locking_Policy_Sloc;
12112 ("Priority_Specific_Dispatching incompatible "
12113 & "with Locking_Policy#");
12115 -- Set the Ceiling_Locking policy, but preserve System_Location
12116 -- since we like the error message with the run time name.
12119 Locking_Policy := 'C';
12121 if Locking_Policy_Sloc /= System_Location then
12122 Locking_Policy_Sloc := Loc;
12126 -- Add entry in the table
12128 Specific_Dispatching.Append
12129 ((Dispatching_Policy => DP,
12130 First_Priority => UI_To_Int (Lower_Val),
12131 Last_Priority => UI_To_Int (Upper_Val),
12132 Pragma_Loc => Loc));
12134 end Priority_Specific_Dispatching;
12140 -- pragma Profile (profile_IDENTIFIER);
12142 -- profile_IDENTIFIER => Restricted | Ravenscar
12144 when Pragma_Profile =>
12146 Check_Arg_Count (1);
12147 Check_Valid_Configuration_Pragma;
12148 Check_No_Identifiers;
12151 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12153 if Chars (Argx) = Name_Ravenscar then
12154 Set_Ravenscar_Profile (N);
12155 elsif Chars (Argx) = Name_Restricted then
12156 Set_Profile_Restrictions
12157 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12159 Error_Pragma_Arg ("& is not a valid profile", Argx);
12163 ----------------------
12164 -- Profile_Warnings --
12165 ----------------------
12167 -- pragma Profile_Warnings (profile_IDENTIFIER);
12169 -- profile_IDENTIFIER => Restricted | Ravenscar
12171 when Pragma_Profile_Warnings =>
12173 Check_Arg_Count (1);
12174 Check_Valid_Configuration_Pragma;
12175 Check_No_Identifiers;
12178 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12180 if Chars (Argx) = Name_Ravenscar then
12181 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12182 elsif Chars (Argx) = Name_Restricted then
12183 Set_Profile_Restrictions (Restricted, N, Warn => True);
12185 Error_Pragma_Arg ("& is not a valid profile", Argx);
12189 --------------------------
12190 -- Propagate_Exceptions --
12191 --------------------------
12193 -- pragma Propagate_Exceptions;
12195 -- Note: this pragma is obsolete and has no effect
12197 when Pragma_Propagate_Exceptions =>
12199 Check_Arg_Count (0);
12201 if In_Extended_Main_Source_Unit (N) then
12202 Propagate_Exceptions := True;
12209 -- pragma Psect_Object (
12210 -- [Internal =>] LOCAL_NAME,
12211 -- [, [External =>] EXTERNAL_SYMBOL]
12212 -- [, [Size =>] EXTERNAL_SYMBOL]);
12214 when Pragma_Psect_Object | Pragma_Common_Object =>
12215 Psect_Object : declare
12216 Args : Args_List (1 .. 3);
12217 Names : constant Name_List (1 .. 3) := (
12222 Internal : Node_Id renames Args (1);
12223 External : Node_Id renames Args (2);
12224 Size : Node_Id renames Args (3);
12226 Def_Id : Entity_Id;
12228 procedure Check_Too_Long (Arg : Node_Id);
12229 -- Posts message if the argument is an identifier with more
12230 -- than 31 characters, or a string literal with more than
12231 -- 31 characters, and we are operating under VMS
12233 --------------------
12234 -- Check_Too_Long --
12235 --------------------
12237 procedure Check_Too_Long (Arg : Node_Id) is
12238 X : constant Node_Id := Original_Node (Arg);
12241 if not Nkind_In (X, N_String_Literal, N_Identifier) then
12243 ("inappropriate argument for pragma %", Arg);
12246 if OpenVMS_On_Target then
12247 if (Nkind (X) = N_String_Literal
12248 and then String_Length (Strval (X)) > 31)
12250 (Nkind (X) = N_Identifier
12251 and then Length_Of_Name (Chars (X)) > 31)
12254 ("argument for pragma % is longer than 31 characters",
12258 end Check_Too_Long;
12260 -- Start of processing for Common_Object/Psect_Object
12264 Gather_Associations (Names, Args);
12265 Process_Extended_Import_Export_Internal_Arg (Internal);
12267 Def_Id := Entity (Internal);
12269 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12271 ("pragma% must designate an object", Internal);
12274 Check_Too_Long (Internal);
12276 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12278 ("cannot use pragma% for imported/exported object",
12282 if Is_Concurrent_Type (Etype (Internal)) then
12284 ("cannot specify pragma % for task/protected object",
12288 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12290 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12292 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12295 if Ekind (Def_Id) = E_Constant then
12297 ("cannot specify pragma % for a constant", Internal);
12300 if Is_Record_Type (Etype (Internal)) then
12306 Ent := First_Entity (Etype (Internal));
12307 while Present (Ent) loop
12308 Decl := Declaration_Node (Ent);
12310 if Ekind (Ent) = E_Component
12311 and then Nkind (Decl) = N_Component_Declaration
12312 and then Present (Expression (Decl))
12313 and then Warn_On_Export_Import
12316 ("?object for pragma % has defaults", Internal);
12326 if Present (Size) then
12327 Check_Too_Long (Size);
12330 if Present (External) then
12331 Check_Arg_Is_External_Name (External);
12332 Check_Too_Long (External);
12335 -- If all error tests pass, link pragma on to the rep item chain
12337 Record_Rep_Item (Def_Id, N);
12344 -- pragma Pure [(library_unit_NAME)];
12346 when Pragma_Pure => Pure : declare
12350 Check_Ada_83_Warning;
12351 Check_Valid_Library_Unit_Pragma;
12353 if Nkind (N) = N_Null_Statement then
12357 Ent := Find_Lib_Unit_Name;
12359 Set_Has_Pragma_Pure (Ent);
12360 Set_Suppress_Elaboration_Warnings (Ent);
12367 -- pragma Pure_05 [(library_unit_NAME)];
12369 -- This pragma is useable only in GNAT_Mode, where it is used like
12370 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
12371 -- it is ignored). It may be used after a pragma Preelaborate, in
12372 -- which case it overrides the effect of the pragma Preelaborate.
12373 -- This is used to implement AI-362 which recategorizes some run-time
12374 -- packages in Ada 2005 mode.
12376 when Pragma_Pure_05 => Pure_05 : declare
12381 Check_Valid_Library_Unit_Pragma;
12383 if not GNAT_Mode then
12384 Error_Pragma ("pragma% only available in GNAT mode");
12387 if Nkind (N) = N_Null_Statement then
12391 -- This is one of the few cases where we need to test the value of
12392 -- Ada_Version_Explicit rather than Ada_Version (which is always
12393 -- set to Ada_2012 in a predefined unit), we need to know the
12394 -- explicit version set to know if this pragma is active.
12396 if Ada_Version_Explicit >= Ada_2005 then
12397 Ent := Find_Lib_Unit_Name;
12398 Set_Is_Preelaborated (Ent, False);
12400 Set_Suppress_Elaboration_Warnings (Ent);
12404 -------------------
12405 -- Pure_Function --
12406 -------------------
12408 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12410 when Pragma_Pure_Function => Pure_Function : declare
12413 Def_Id : Entity_Id;
12414 Effective : Boolean := False;
12418 Check_Arg_Count (1);
12419 Check_Optional_Identifier (Arg1, Name_Entity);
12420 Check_Arg_Is_Local_Name (Arg1);
12421 E_Id := Get_Pragma_Arg (Arg1);
12423 if Error_Posted (E_Id) then
12427 -- Loop through homonyms (overloadings) of referenced entity
12429 E := Entity (E_Id);
12431 if Present (E) then
12433 Def_Id := Get_Base_Subprogram (E);
12435 if not Ekind_In (Def_Id, E_Function,
12436 E_Generic_Function,
12440 ("pragma% requires a function name", Arg1);
12443 Set_Is_Pure (Def_Id);
12445 if not Has_Pragma_Pure_Function (Def_Id) then
12446 Set_Has_Pragma_Pure_Function (Def_Id);
12450 exit when From_Aspect_Specification (N);
12452 exit when No (E) or else Scope (E) /= Current_Scope;
12456 and then Warn_On_Redundant_Constructs
12459 ("pragma Pure_Function on& is redundant?",
12465 --------------------
12466 -- Queuing_Policy --
12467 --------------------
12469 -- pragma Queuing_Policy (policy_IDENTIFIER);
12471 when Pragma_Queuing_Policy => declare
12475 Check_Ada_83_Warning;
12476 Check_Arg_Count (1);
12477 Check_No_Identifiers;
12478 Check_Arg_Is_Queuing_Policy (Arg1);
12479 Check_Valid_Configuration_Pragma;
12480 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12481 QP := Fold_Upper (Name_Buffer (1));
12483 if Queuing_Policy /= ' '
12484 and then Queuing_Policy /= QP
12486 Error_Msg_Sloc := Queuing_Policy_Sloc;
12487 Error_Pragma ("queuing policy incompatible with policy#");
12489 -- Set new policy, but always preserve System_Location since we
12490 -- like the error message with the run time name.
12493 Queuing_Policy := QP;
12495 if Queuing_Policy_Sloc /= System_Location then
12496 Queuing_Policy_Sloc := Loc;
12501 -----------------------
12502 -- Relative_Deadline --
12503 -----------------------
12505 -- pragma Relative_Deadline (time_span_EXPRESSION);
12507 when Pragma_Relative_Deadline => Relative_Deadline : declare
12508 P : constant Node_Id := Parent (N);
12513 Check_No_Identifiers;
12514 Check_Arg_Count (1);
12516 Arg := Get_Pragma_Arg (Arg1);
12518 -- The expression must be analyzed in the special manner described
12519 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12521 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12525 if Nkind (P) = N_Subprogram_Body then
12526 Check_In_Main_Program;
12530 elsif Nkind (P) = N_Task_Definition then
12533 -- Anything else is incorrect
12539 if Has_Relative_Deadline_Pragma (P) then
12540 Error_Pragma ("duplicate pragma% not allowed");
12542 Set_Has_Relative_Deadline_Pragma (P, True);
12544 if Nkind (P) = N_Task_Definition then
12545 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12548 end Relative_Deadline;
12550 ---------------------------
12551 -- Remote_Call_Interface --
12552 ---------------------------
12554 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12556 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12557 Cunit_Node : Node_Id;
12558 Cunit_Ent : Entity_Id;
12562 Check_Ada_83_Warning;
12563 Check_Valid_Library_Unit_Pragma;
12565 if Nkind (N) = N_Null_Statement then
12569 Cunit_Node := Cunit (Current_Sem_Unit);
12570 K := Nkind (Unit (Cunit_Node));
12571 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12573 if K = N_Package_Declaration
12574 or else K = N_Generic_Package_Declaration
12575 or else K = N_Subprogram_Declaration
12576 or else K = N_Generic_Subprogram_Declaration
12577 or else (K = N_Subprogram_Body
12578 and then Acts_As_Spec (Unit (Cunit_Node)))
12583 "pragma% must apply to package or subprogram declaration");
12586 Set_Is_Remote_Call_Interface (Cunit_Ent);
12587 end Remote_Call_Interface;
12593 -- pragma Remote_Types [(library_unit_NAME)];
12595 when Pragma_Remote_Types => Remote_Types : declare
12596 Cunit_Node : Node_Id;
12597 Cunit_Ent : Entity_Id;
12600 Check_Ada_83_Warning;
12601 Check_Valid_Library_Unit_Pragma;
12603 if Nkind (N) = N_Null_Statement then
12607 Cunit_Node := Cunit (Current_Sem_Unit);
12608 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12610 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12611 N_Generic_Package_Declaration)
12614 ("pragma% can only apply to a package declaration");
12617 Set_Is_Remote_Types (Cunit_Ent);
12624 -- pragma Ravenscar;
12626 when Pragma_Ravenscar =>
12628 Check_Arg_Count (0);
12629 Check_Valid_Configuration_Pragma;
12630 Set_Ravenscar_Profile (N);
12632 if Warn_On_Obsolescent_Feature then
12633 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12634 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12637 -------------------------
12638 -- Restricted_Run_Time --
12639 -------------------------
12641 -- pragma Restricted_Run_Time;
12643 when Pragma_Restricted_Run_Time =>
12645 Check_Arg_Count (0);
12646 Check_Valid_Configuration_Pragma;
12647 Set_Profile_Restrictions
12648 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12650 if Warn_On_Obsolescent_Feature then
12652 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12653 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12660 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12663 -- restriction_IDENTIFIER
12664 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12666 when Pragma_Restrictions =>
12667 Process_Restrictions_Or_Restriction_Warnings
12668 (Warn => Treat_Restrictions_As_Warnings);
12670 --------------------------
12671 -- Restriction_Warnings --
12672 --------------------------
12674 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12677 -- restriction_IDENTIFIER
12678 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12680 when Pragma_Restriction_Warnings =>
12682 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12688 -- pragma Reviewable;
12690 when Pragma_Reviewable =>
12691 Check_Ada_83_Warning;
12692 Check_Arg_Count (0);
12694 -- Call dummy debugging function rv. This is done to assist front
12695 -- end debugging. By placing a Reviewable pragma in the source
12696 -- program, a breakpoint on rv catches this place in the source,
12697 -- allowing convenient stepping to the point of interest.
12701 --------------------------
12702 -- Short_Circuit_And_Or --
12703 --------------------------
12705 when Pragma_Short_Circuit_And_Or =>
12707 Check_Arg_Count (0);
12708 Check_Valid_Configuration_Pragma;
12709 Short_Circuit_And_Or := True;
12711 -------------------
12712 -- Share_Generic --
12713 -------------------
12715 -- pragma Share_Generic (NAME {, NAME});
12717 when Pragma_Share_Generic =>
12719 Process_Generic_List;
12725 -- pragma Shared (LOCAL_NAME);
12727 when Pragma_Shared =>
12729 Process_Atomic_Shared_Volatile;
12731 --------------------
12732 -- Shared_Passive --
12733 --------------------
12735 -- pragma Shared_Passive [(library_unit_NAME)];
12737 -- Set the flag Is_Shared_Passive of program unit name entity
12739 when Pragma_Shared_Passive => Shared_Passive : declare
12740 Cunit_Node : Node_Id;
12741 Cunit_Ent : Entity_Id;
12744 Check_Ada_83_Warning;
12745 Check_Valid_Library_Unit_Pragma;
12747 if Nkind (N) = N_Null_Statement then
12751 Cunit_Node := Cunit (Current_Sem_Unit);
12752 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12754 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12755 N_Generic_Package_Declaration)
12758 ("pragma% can only apply to a package declaration");
12761 Set_Is_Shared_Passive (Cunit_Ent);
12762 end Shared_Passive;
12764 -----------------------
12765 -- Short_Descriptors --
12766 -----------------------
12768 -- pragma Short_Descriptors;
12770 when Pragma_Short_Descriptors =>
12772 Check_Arg_Count (0);
12773 Check_Valid_Configuration_Pragma;
12774 Short_Descriptors := True;
12776 ----------------------
12777 -- Source_File_Name --
12778 ----------------------
12780 -- There are five forms for this pragma:
12782 -- pragma Source_File_Name (
12783 -- [UNIT_NAME =>] unit_NAME,
12784 -- BODY_FILE_NAME => STRING_LITERAL
12785 -- [, [INDEX =>] INTEGER_LITERAL]);
12787 -- pragma Source_File_Name (
12788 -- [UNIT_NAME =>] unit_NAME,
12789 -- SPEC_FILE_NAME => STRING_LITERAL
12790 -- [, [INDEX =>] INTEGER_LITERAL]);
12792 -- pragma Source_File_Name (
12793 -- BODY_FILE_NAME => STRING_LITERAL
12794 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12795 -- [, CASING => CASING_SPEC]);
12797 -- pragma Source_File_Name (
12798 -- SPEC_FILE_NAME => STRING_LITERAL
12799 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12800 -- [, CASING => CASING_SPEC]);
12802 -- pragma Source_File_Name (
12803 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12804 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12805 -- [, CASING => CASING_SPEC]);
12807 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12809 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12810 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12811 -- only be used when no project file is used, while SFNP can only be
12812 -- used when a project file is used.
12814 -- No processing here. Processing was completed during parsing, since
12815 -- we need to have file names set as early as possible. Units are
12816 -- loaded well before semantic processing starts.
12818 -- The only processing we defer to this point is the check for
12819 -- correct placement.
12821 when Pragma_Source_File_Name =>
12823 Check_Valid_Configuration_Pragma;
12825 ------------------------------
12826 -- Source_File_Name_Project --
12827 ------------------------------
12829 -- See Source_File_Name for syntax
12831 -- No processing here. Processing was completed during parsing, since
12832 -- we need to have file names set as early as possible. Units are
12833 -- loaded well before semantic processing starts.
12835 -- The only processing we defer to this point is the check for
12836 -- correct placement.
12838 when Pragma_Source_File_Name_Project =>
12840 Check_Valid_Configuration_Pragma;
12842 -- Check that a pragma Source_File_Name_Project is used only in a
12843 -- configuration pragmas file.
12845 -- Pragmas Source_File_Name_Project should only be generated by
12846 -- the Project Manager in configuration pragmas files.
12848 -- This is really an ugly test. It seems to depend on some
12849 -- accidental and undocumented property. At the very least it
12850 -- needs to be documented, but it would be better to have a
12851 -- clean way of testing if we are in a configuration file???
12853 if Present (Parent (N)) then
12855 ("pragma% can only appear in a configuration pragmas file");
12858 ----------------------
12859 -- Source_Reference --
12860 ----------------------
12862 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12864 -- Nothing to do, all processing completed in Par.Prag, since we need
12865 -- the information for possible parser messages that are output.
12867 when Pragma_Source_Reference =>
12870 --------------------------------
12871 -- Static_Elaboration_Desired --
12872 --------------------------------
12874 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12876 when Pragma_Static_Elaboration_Desired =>
12878 Check_At_Most_N_Arguments (1);
12880 if Is_Compilation_Unit (Current_Scope)
12881 and then Ekind (Current_Scope) = E_Package
12883 Set_Static_Elaboration_Desired (Current_Scope, True);
12885 Error_Pragma ("pragma% must apply to a library-level package");
12892 -- pragma Storage_Size (EXPRESSION);
12894 when Pragma_Storage_Size => Storage_Size : declare
12895 P : constant Node_Id := Parent (N);
12899 Check_No_Identifiers;
12900 Check_Arg_Count (1);
12902 -- The expression must be analyzed in the special manner described
12903 -- in "Handling of Default Expressions" in sem.ads.
12905 Arg := Get_Pragma_Arg (Arg1);
12906 Preanalyze_Spec_Expression (Arg, Any_Integer);
12908 if not Is_Static_Expression (Arg) then
12909 Check_Restriction (Static_Storage_Size, Arg);
12912 if Nkind (P) /= N_Task_Definition then
12917 if Has_Storage_Size_Pragma (P) then
12918 Error_Pragma ("duplicate pragma% not allowed");
12920 Set_Has_Storage_Size_Pragma (P, True);
12923 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12924 -- ??? exp_ch9 should use this!
12932 -- pragma Storage_Unit (NUMERIC_LITERAL);
12934 -- Only permitted argument is System'Storage_Unit value
12936 when Pragma_Storage_Unit =>
12937 Check_No_Identifiers;
12938 Check_Arg_Count (1);
12939 Check_Arg_Is_Integer_Literal (Arg1);
12941 if Intval (Get_Pragma_Arg (Arg1)) /=
12942 UI_From_Int (Ttypes.System_Storage_Unit)
12944 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12946 ("the only allowed argument for pragma% is ^", Arg1);
12949 --------------------
12950 -- Stream_Convert --
12951 --------------------
12953 -- pragma Stream_Convert (
12954 -- [Entity =>] type_LOCAL_NAME,
12955 -- [Read =>] function_NAME,
12956 -- [Write =>] function NAME);
12958 when Pragma_Stream_Convert => Stream_Convert : declare
12960 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12961 -- Check that the given argument is the name of a local function
12962 -- of one argument that is not overloaded earlier in the current
12963 -- local scope. A check is also made that the argument is a
12964 -- function with one parameter.
12966 --------------------------------------
12967 -- Check_OK_Stream_Convert_Function --
12968 --------------------------------------
12970 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12974 Check_Arg_Is_Local_Name (Arg);
12975 Ent := Entity (Get_Pragma_Arg (Arg));
12977 if Has_Homonym (Ent) then
12979 ("argument for pragma% may not be overloaded", Arg);
12982 if Ekind (Ent) /= E_Function
12983 or else No (First_Formal (Ent))
12984 or else Present (Next_Formal (First_Formal (Ent)))
12987 ("argument for pragma% must be" &
12988 " function of one argument", Arg);
12990 end Check_OK_Stream_Convert_Function;
12992 -- Start of processing for Stream_Convert
12996 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12997 Check_Arg_Count (3);
12998 Check_Optional_Identifier (Arg1, Name_Entity);
12999 Check_Optional_Identifier (Arg2, Name_Read);
13000 Check_Optional_Identifier (Arg3, Name_Write);
13001 Check_Arg_Is_Local_Name (Arg1);
13002 Check_OK_Stream_Convert_Function (Arg2);
13003 Check_OK_Stream_Convert_Function (Arg3);
13006 Typ : constant Entity_Id :=
13007 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13008 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13009 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
13012 Check_First_Subtype (Arg1);
13014 -- Check for too early or too late. Note that we don't enforce
13015 -- the rule about primitive operations in this case, since, as
13016 -- is the case for explicit stream attributes themselves, these
13017 -- restrictions are not appropriate. Note that the chaining of
13018 -- the pragma by Rep_Item_Too_Late is actually the critical
13019 -- processing done for this pragma.
13021 if Rep_Item_Too_Early (Typ, N)
13023 Rep_Item_Too_Late (Typ, N, FOnly => True)
13028 -- Return if previous error
13030 if Etype (Typ) = Any_Type
13032 Etype (Read) = Any_Type
13034 Etype (Write) = Any_Type
13041 if Underlying_Type (Etype (Read)) /= Typ then
13043 ("incorrect return type for function&", Arg2);
13046 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13048 ("incorrect parameter type for function&", Arg3);
13051 if Underlying_Type (Etype (First_Formal (Read))) /=
13052 Underlying_Type (Etype (Write))
13055 ("result type of & does not match Read parameter type",
13059 end Stream_Convert;
13061 -------------------------
13062 -- Style_Checks (GNAT) --
13063 -------------------------
13065 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13067 -- This is processed by the parser since some of the style checks
13068 -- take place during source scanning and parsing. This means that
13069 -- we don't need to issue error messages here.
13071 when Pragma_Style_Checks => Style_Checks : declare
13072 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13078 Check_No_Identifiers;
13080 -- Two argument form
13082 if Arg_Count = 2 then
13083 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13090 E_Id := Get_Pragma_Arg (Arg2);
13093 if not Is_Entity_Name (E_Id) then
13095 ("second argument of pragma% must be entity name",
13099 E := Entity (E_Id);
13105 Set_Suppress_Style_Checks (E,
13106 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
13107 exit when No (Homonym (E));
13113 -- One argument form
13116 Check_Arg_Count (1);
13118 if Nkind (A) = N_String_Literal then
13122 Slen : constant Natural := Natural (String_Length (S));
13123 Options : String (1 .. Slen);
13129 C := Get_String_Char (S, Int (J));
13130 exit when not In_Character_Range (C);
13131 Options (J) := Get_Character (C);
13133 -- If at end of string, set options. As per discussion
13134 -- above, no need to check for errors, since we issued
13135 -- them in the parser.
13138 Set_Style_Check_Options (Options);
13146 elsif Nkind (A) = N_Identifier then
13147 if Chars (A) = Name_All_Checks then
13149 Set_GNAT_Style_Check_Options;
13151 Set_Default_Style_Check_Options;
13154 elsif Chars (A) = Name_On then
13155 Style_Check := True;
13157 elsif Chars (A) = Name_Off then
13158 Style_Check := False;
13168 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13170 when Pragma_Subtitle =>
13172 Check_Arg_Count (1);
13173 Check_Optional_Identifier (Arg1, Name_Subtitle);
13174 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13181 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13183 when Pragma_Suppress =>
13184 Process_Suppress_Unsuppress (True);
13190 -- pragma Suppress_All;
13192 -- The only check made here is that the pragma has no arguments.
13193 -- There are no placement rules, and the processing required (setting
13194 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
13195 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
13196 -- then creates and inserts a pragma Suppress (All_Checks).
13198 when Pragma_Suppress_All =>
13200 Check_Arg_Count (0);
13202 -------------------------
13203 -- Suppress_Debug_Info --
13204 -------------------------
13206 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13208 when Pragma_Suppress_Debug_Info =>
13210 Check_Arg_Count (1);
13211 Check_Optional_Identifier (Arg1, Name_Entity);
13212 Check_Arg_Is_Local_Name (Arg1);
13213 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13215 ----------------------------------
13216 -- Suppress_Exception_Locations --
13217 ----------------------------------
13219 -- pragma Suppress_Exception_Locations;
13221 when Pragma_Suppress_Exception_Locations =>
13223 Check_Arg_Count (0);
13224 Check_Valid_Configuration_Pragma;
13225 Exception_Locations_Suppressed := True;
13227 -----------------------------
13228 -- Suppress_Initialization --
13229 -----------------------------
13231 -- pragma Suppress_Initialization ([Entity =>] type_Name);
13233 when Pragma_Suppress_Initialization => Suppress_Init : declare
13239 Check_Arg_Count (1);
13240 Check_Optional_Identifier (Arg1, Name_Entity);
13241 Check_Arg_Is_Local_Name (Arg1);
13243 E_Id := Get_Pragma_Arg (Arg1);
13245 if Etype (E_Id) = Any_Type then
13249 E := Entity (E_Id);
13251 if not Is_Type (E) then
13252 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13255 if Rep_Item_Too_Early (E, N)
13257 Rep_Item_Too_Late (E, N, FOnly => True)
13262 -- For incomplete/private type, set flag on full view
13264 if Is_Incomplete_Or_Private_Type (E) then
13265 if No (Full_View (Base_Type (E))) then
13267 ("argument of pragma% cannot be an incomplete type", Arg1);
13269 Set_Suppress_Initialization (Full_View (Base_Type (E)));
13272 -- For first subtype, set flag on base type
13274 elsif Is_First_Subtype (E) then
13275 Set_Suppress_Initialization (Base_Type (E));
13277 -- For other than first subtype, set flag on subtype itself
13280 Set_Suppress_Initialization (E);
13288 -- pragma System_Name (DIRECT_NAME);
13290 -- Syntax check: one argument, which must be the identifier GNAT or
13291 -- the identifier GCC, no other identifiers are acceptable.
13293 when Pragma_System_Name =>
13295 Check_No_Identifiers;
13296 Check_Arg_Count (1);
13297 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13299 -----------------------------
13300 -- Task_Dispatching_Policy --
13301 -----------------------------
13303 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13305 when Pragma_Task_Dispatching_Policy => declare
13309 Check_Ada_83_Warning;
13310 Check_Arg_Count (1);
13311 Check_No_Identifiers;
13312 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13313 Check_Valid_Configuration_Pragma;
13314 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13315 DP := Fold_Upper (Name_Buffer (1));
13317 if Task_Dispatching_Policy /= ' '
13318 and then Task_Dispatching_Policy /= DP
13320 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13322 ("task dispatching policy incompatible with policy#");
13324 -- Set new policy, but always preserve System_Location since we
13325 -- like the error message with the run time name.
13328 Task_Dispatching_Policy := DP;
13330 if Task_Dispatching_Policy_Sloc /= System_Location then
13331 Task_Dispatching_Policy_Sloc := Loc;
13340 -- pragma Task_Info (EXPRESSION);
13342 when Pragma_Task_Info => Task_Info : declare
13343 P : constant Node_Id := Parent (N);
13348 if Nkind (P) /= N_Task_Definition then
13349 Error_Pragma ("pragma% must appear in task definition");
13352 Check_No_Identifiers;
13353 Check_Arg_Count (1);
13355 Analyze_And_Resolve
13356 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13358 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13362 if Has_Task_Info_Pragma (P) then
13363 Error_Pragma ("duplicate pragma% not allowed");
13365 Set_Has_Task_Info_Pragma (P, True);
13373 -- pragma Task_Name (string_EXPRESSION);
13375 when Pragma_Task_Name => Task_Name : declare
13376 P : constant Node_Id := Parent (N);
13380 Check_No_Identifiers;
13381 Check_Arg_Count (1);
13383 Arg := Get_Pragma_Arg (Arg1);
13385 -- The expression is used in the call to Create_Task, and must be
13386 -- expanded there, not in the context of the current spec. It must
13387 -- however be analyzed to capture global references, in case it
13388 -- appears in a generic context.
13390 Preanalyze_And_Resolve (Arg, Standard_String);
13392 if Nkind (P) /= N_Task_Definition then
13396 if Has_Task_Name_Pragma (P) then
13397 Error_Pragma ("duplicate pragma% not allowed");
13399 Set_Has_Task_Name_Pragma (P, True);
13400 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13408 -- pragma Task_Storage (
13409 -- [Task_Type =>] LOCAL_NAME,
13410 -- [Top_Guard =>] static_integer_EXPRESSION);
13412 when Pragma_Task_Storage => Task_Storage : declare
13413 Args : Args_List (1 .. 2);
13414 Names : constant Name_List (1 .. 2) := (
13418 Task_Type : Node_Id renames Args (1);
13419 Top_Guard : Node_Id renames Args (2);
13425 Gather_Associations (Names, Args);
13427 if No (Task_Type) then
13429 ("missing task_type argument for pragma%");
13432 Check_Arg_Is_Local_Name (Task_Type);
13434 Ent := Entity (Task_Type);
13436 if not Is_Task_Type (Ent) then
13438 ("argument for pragma% must be task type", Task_Type);
13441 if No (Top_Guard) then
13443 ("pragma% takes two arguments", Task_Type);
13445 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13448 Check_First_Subtype (Task_Type);
13450 if Rep_Item_Too_Late (Ent, N) then
13459 -- pragma Test_Case ([Name =>] Static_String_EXPRESSION
13460 -- ,[Mode =>] MODE_TYPE
13461 -- [, Requires => Boolean_EXPRESSION]
13462 -- [, Ensures => Boolean_EXPRESSION]);
13464 -- MODE_TYPE ::= Nominal | Robustness
13466 when Pragma_Test_Case => Test_Case : declare
13469 Check_At_Least_N_Arguments (2);
13470 Check_At_Most_N_Arguments (4);
13472 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13474 Check_Optional_Identifier (Arg1, Name_Name);
13475 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13476 Check_Optional_Identifier (Arg2, Name_Mode);
13477 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13479 if Arg_Count = 4 then
13480 Check_Identifier (Arg3, Name_Requires);
13481 Check_Identifier (Arg4, Name_Ensures);
13483 elsif Arg_Count = 3 then
13484 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13490 --------------------------
13491 -- Thread_Local_Storage --
13492 --------------------------
13494 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13496 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13502 Check_Arg_Count (1);
13503 Check_Optional_Identifier (Arg1, Name_Entity);
13504 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13506 Id := Get_Pragma_Arg (Arg1);
13509 if not Is_Entity_Name (Id)
13510 or else Ekind (Entity (Id)) /= E_Variable
13512 Error_Pragma_Arg ("local variable name required", Arg1);
13517 if Rep_Item_Too_Early (E, N)
13518 or else Rep_Item_Too_Late (E, N)
13523 Set_Has_Pragma_Thread_Local_Storage (E);
13524 Set_Has_Gigi_Rep_Item (E);
13525 end Thread_Local_Storage;
13531 -- pragma Time_Slice (static_duration_EXPRESSION);
13533 when Pragma_Time_Slice => Time_Slice : declare
13539 Check_Arg_Count (1);
13540 Check_No_Identifiers;
13541 Check_In_Main_Program;
13542 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13544 if not Error_Posted (Arg1) then
13546 while Present (Nod) loop
13547 if Nkind (Nod) = N_Pragma
13548 and then Pragma_Name (Nod) = Name_Time_Slice
13550 Error_Msg_Name_1 := Pname;
13551 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13558 -- Process only if in main unit
13560 if Get_Source_Unit (Loc) = Main_Unit then
13561 Opt.Time_Slice_Set := True;
13562 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13564 if Val <= Ureal_0 then
13565 Opt.Time_Slice_Value := 0;
13567 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13568 Opt.Time_Slice_Value := 1_000_000_000;
13571 Opt.Time_Slice_Value :=
13572 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13581 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13583 -- TITLING_OPTION ::=
13584 -- [Title =>] STRING_LITERAL
13585 -- | [Subtitle =>] STRING_LITERAL
13587 when Pragma_Title => Title : declare
13588 Args : Args_List (1 .. 2);
13589 Names : constant Name_List (1 .. 2) := (
13595 Gather_Associations (Names, Args);
13598 for J in 1 .. 2 loop
13599 if Present (Args (J)) then
13600 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13605 ---------------------
13606 -- Unchecked_Union --
13607 ---------------------
13609 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13611 when Pragma_Unchecked_Union => Unchecked_Union : declare
13612 Assoc : constant Node_Id := Arg1;
13613 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13624 Check_No_Identifiers;
13625 Check_Arg_Count (1);
13626 Check_Arg_Is_Local_Name (Arg1);
13628 Find_Type (Type_Id);
13629 Typ := Entity (Type_Id);
13632 or else Rep_Item_Too_Early (Typ, N)
13636 Typ := Underlying_Type (Typ);
13639 if Rep_Item_Too_Late (Typ, N) then
13643 Check_First_Subtype (Arg1);
13645 -- Note remaining cases are references to a type in the current
13646 -- declarative part. If we find an error, we post the error on
13647 -- the relevant type declaration at an appropriate point.
13649 if not Is_Record_Type (Typ) then
13650 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13653 elsif Is_Tagged_Type (Typ) then
13654 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13657 elsif Is_Limited_Type (Typ) then
13659 ("Unchecked_Union must not be limited record type", Typ);
13660 Explain_Limited_Type (Typ, Typ);
13664 if not Has_Discriminants (Typ) then
13666 ("Unchecked_Union must have one discriminant", Typ);
13670 Discr := First_Discriminant (Typ);
13671 while Present (Discr) loop
13672 if No (Discriminant_Default_Value (Discr)) then
13674 ("Unchecked_Union discriminant must have default value",
13678 Next_Discriminant (Discr);
13681 Tdef := Type_Definition (Declaration_Node (Typ));
13682 Clist := Component_List (Tdef);
13684 Comp := First (Component_Items (Clist));
13685 while Present (Comp) loop
13686 Check_Component (Comp, Typ);
13690 if No (Clist) or else No (Variant_Part (Clist)) then
13692 ("Unchecked_Union must have variant part",
13697 Vpart := Variant_Part (Clist);
13699 Variant := First (Variants (Vpart));
13700 while Present (Variant) loop
13701 Check_Variant (Variant, Typ);
13706 Set_Is_Unchecked_Union (Typ);
13707 Set_Convention (Typ, Convention_C);
13708 Set_Has_Unchecked_Union (Base_Type (Typ));
13709 Set_Is_Unchecked_Union (Base_Type (Typ));
13710 end Unchecked_Union;
13712 ------------------------
13713 -- Unimplemented_Unit --
13714 ------------------------
13716 -- pragma Unimplemented_Unit;
13718 -- Note: this only gives an error if we are generating code, or if
13719 -- we are in a generic library unit (where the pragma appears in the
13720 -- body, not in the spec).
13722 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13723 Cunitent : constant Entity_Id :=
13724 Cunit_Entity (Get_Source_Unit (Loc));
13725 Ent_Kind : constant Entity_Kind :=
13730 Check_Arg_Count (0);
13732 if Operating_Mode = Generate_Code
13733 or else Ent_Kind = E_Generic_Function
13734 or else Ent_Kind = E_Generic_Procedure
13735 or else Ent_Kind = E_Generic_Package
13737 Get_Name_String (Chars (Cunitent));
13738 Set_Casing (Mixed_Case);
13739 Write_Str (Name_Buffer (1 .. Name_Len));
13740 Write_Str (" is not supported in this configuration");
13742 raise Unrecoverable_Error;
13744 end Unimplemented_Unit;
13746 ------------------------
13747 -- Universal_Aliasing --
13748 ------------------------
13750 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13752 when Pragma_Universal_Aliasing => Universal_Alias : declare
13757 Check_Arg_Count (1);
13758 Check_Optional_Identifier (Arg2, Name_Entity);
13759 Check_Arg_Is_Local_Name (Arg1);
13760 E_Id := Entity (Get_Pragma_Arg (Arg1));
13762 if E_Id = Any_Type then
13764 elsif No (E_Id) or else not Is_Type (E_Id) then
13765 Error_Pragma_Arg ("pragma% requires type", Arg1);
13768 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13769 end Universal_Alias;
13771 --------------------
13772 -- Universal_Data --
13773 --------------------
13775 -- pragma Universal_Data [(library_unit_NAME)];
13777 when Pragma_Universal_Data =>
13780 -- If this is a configuration pragma, then set the universal
13781 -- addressing option, otherwise confirm that the pragma satisfies
13782 -- the requirements of library unit pragma placement and leave it
13783 -- to the GNAAMP back end to detect the pragma (avoids transitive
13784 -- setting of the option due to withed units).
13786 if Is_Configuration_Pragma then
13787 Universal_Addressing_On_AAMP := True;
13789 Check_Valid_Library_Unit_Pragma;
13792 if not AAMP_On_Target then
13793 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13800 -- pragma Unmodified (local_Name {, local_Name});
13802 when Pragma_Unmodified => Unmodified : declare
13803 Arg_Node : Node_Id;
13804 Arg_Expr : Node_Id;
13805 Arg_Ent : Entity_Id;
13809 Check_At_Least_N_Arguments (1);
13811 -- Loop through arguments
13814 while Present (Arg_Node) loop
13815 Check_No_Identifier (Arg_Node);
13817 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13818 -- in fact generate reference, so that the entity will have a
13819 -- reference, which will inhibit any warnings about it not
13820 -- being referenced, and also properly show up in the ali file
13821 -- as a reference. But this reference is recorded before the
13822 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13823 -- generated for this reference.
13825 Check_Arg_Is_Local_Name (Arg_Node);
13826 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13828 if Is_Entity_Name (Arg_Expr) then
13829 Arg_Ent := Entity (Arg_Expr);
13831 if not Is_Assignable (Arg_Ent) then
13833 ("pragma% can only be applied to a variable",
13836 Set_Has_Pragma_Unmodified (Arg_Ent);
13848 -- pragma Unreferenced (local_Name {, local_Name});
13850 -- or when used in a context clause:
13852 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13854 when Pragma_Unreferenced => Unreferenced : declare
13855 Arg_Node : Node_Id;
13856 Arg_Expr : Node_Id;
13857 Arg_Ent : Entity_Id;
13862 Check_At_Least_N_Arguments (1);
13864 -- Check case of appearing within context clause
13866 if Is_In_Context_Clause then
13868 -- The arguments must all be units mentioned in a with clause
13869 -- in the same context clause. Note we already checked (in
13870 -- Par.Prag) that the arguments are either identifiers or
13871 -- selected components.
13874 while Present (Arg_Node) loop
13875 Citem := First (List_Containing (N));
13876 while Citem /= N loop
13877 if Nkind (Citem) = N_With_Clause
13879 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13881 Set_Has_Pragma_Unreferenced
13884 (Library_Unit (Citem))));
13886 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13895 ("argument of pragma% is not with'ed unit", Arg_Node);
13901 -- Case of not in list of context items
13905 while Present (Arg_Node) loop
13906 Check_No_Identifier (Arg_Node);
13908 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13909 -- will in fact generate reference, so that the entity will
13910 -- have a reference, which will inhibit any warnings about
13911 -- it not being referenced, and also properly show up in the
13912 -- ali file as a reference. But this reference is recorded
13913 -- before the Has_Pragma_Unreferenced flag is set, so that
13914 -- no warning is generated for this reference.
13916 Check_Arg_Is_Local_Name (Arg_Node);
13917 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13919 if Is_Entity_Name (Arg_Expr) then
13920 Arg_Ent := Entity (Arg_Expr);
13922 -- If the entity is overloaded, the pragma applies to the
13923 -- most recent overloading, as documented. In this case,
13924 -- name resolution does not generate a reference, so it
13925 -- must be done here explicitly.
13927 if Is_Overloaded (Arg_Expr) then
13928 Generate_Reference (Arg_Ent, N);
13931 Set_Has_Pragma_Unreferenced (Arg_Ent);
13939 --------------------------
13940 -- Unreferenced_Objects --
13941 --------------------------
13943 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13945 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13946 Arg_Node : Node_Id;
13947 Arg_Expr : Node_Id;
13951 Check_At_Least_N_Arguments (1);
13954 while Present (Arg_Node) loop
13955 Check_No_Identifier (Arg_Node);
13956 Check_Arg_Is_Local_Name (Arg_Node);
13957 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13959 if not Is_Entity_Name (Arg_Expr)
13960 or else not Is_Type (Entity (Arg_Expr))
13963 ("argument for pragma% must be type or subtype", Arg_Node);
13966 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13969 end Unreferenced_Objects;
13971 ------------------------------
13972 -- Unreserve_All_Interrupts --
13973 ------------------------------
13975 -- pragma Unreserve_All_Interrupts;
13977 when Pragma_Unreserve_All_Interrupts =>
13979 Check_Arg_Count (0);
13981 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13982 Unreserve_All_Interrupts := True;
13989 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13991 when Pragma_Unsuppress =>
13993 Process_Suppress_Unsuppress (False);
13995 -------------------
13996 -- Use_VADS_Size --
13997 -------------------
13999 -- pragma Use_VADS_Size;
14001 when Pragma_Use_VADS_Size =>
14003 Check_Arg_Count (0);
14004 Check_Valid_Configuration_Pragma;
14005 Use_VADS_Size := True;
14007 ---------------------
14008 -- Validity_Checks --
14009 ---------------------
14011 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14013 when Pragma_Validity_Checks => Validity_Checks : declare
14014 A : constant Node_Id := Get_Pragma_Arg (Arg1);
14020 Check_Arg_Count (1);
14021 Check_No_Identifiers;
14023 if Nkind (A) = N_String_Literal then
14027 Slen : constant Natural := Natural (String_Length (S));
14028 Options : String (1 .. Slen);
14034 C := Get_String_Char (S, Int (J));
14035 exit when not In_Character_Range (C);
14036 Options (J) := Get_Character (C);
14039 Set_Validity_Check_Options (Options);
14047 elsif Nkind (A) = N_Identifier then
14049 if Chars (A) = Name_All_Checks then
14050 Set_Validity_Check_Options ("a");
14052 elsif Chars (A) = Name_On then
14053 Validity_Checks_On := True;
14055 elsif Chars (A) = Name_Off then
14056 Validity_Checks_On := False;
14060 end Validity_Checks;
14066 -- pragma Volatile (LOCAL_NAME);
14068 when Pragma_Volatile =>
14069 Process_Atomic_Shared_Volatile;
14071 -------------------------
14072 -- Volatile_Components --
14073 -------------------------
14075 -- pragma Volatile_Components (array_LOCAL_NAME);
14077 -- Volatile is handled by the same circuit as Atomic_Components
14083 -- pragma Warnings (On | Off);
14084 -- pragma Warnings (On | Off, LOCAL_NAME);
14085 -- pragma Warnings (static_string_EXPRESSION);
14086 -- pragma Warnings (On | Off, STRING_LITERAL);
14088 when Pragma_Warnings => Warnings : begin
14090 Check_At_Least_N_Arguments (1);
14091 Check_No_Identifiers;
14093 -- If debug flag -gnatd.i is set, pragma is ignored
14095 if Debug_Flag_Dot_I then
14099 -- Process various forms of the pragma
14102 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14105 -- One argument case
14107 if Arg_Count = 1 then
14109 -- On/Off one argument case was processed by parser
14111 if Nkind (Argx) = N_Identifier
14113 (Chars (Argx) = Name_On
14115 Chars (Argx) = Name_Off)
14119 -- One argument case must be ON/OFF or static string expr
14121 elsif not Is_Static_String_Expression (Arg1) then
14123 ("argument of pragma% must be On/Off or " &
14124 "static string expression", Arg1);
14126 -- One argument string expression case
14130 Lit : constant Node_Id := Expr_Value_S (Argx);
14131 Str : constant String_Id := Strval (Lit);
14132 Len : constant Nat := String_Length (Str);
14140 while J <= Len loop
14141 C := Get_String_Char (Str, J);
14142 OK := In_Character_Range (C);
14145 Chr := Get_Character (C);
14149 if J < Len and then Chr = '.' then
14151 C := Get_String_Char (Str, J);
14152 Chr := Get_Character (C);
14154 if not Set_Dot_Warning_Switch (Chr) then
14156 ("invalid warning switch character " &
14163 OK := Set_Warning_Switch (Chr);
14169 ("invalid warning switch character " & Chr,
14178 -- Two or more arguments (must be two)
14181 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14182 Check_At_Most_N_Arguments (2);
14190 E_Id := Get_Pragma_Arg (Arg2);
14193 -- In the expansion of an inlined body, a reference to
14194 -- the formal may be wrapped in a conversion if the
14195 -- actual is a conversion. Retrieve the real entity name.
14197 if (In_Instance_Body
14198 or else In_Inlined_Body)
14199 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14201 E_Id := Expression (E_Id);
14204 -- Entity name case
14206 if Is_Entity_Name (E_Id) then
14207 E := Entity (E_Id);
14214 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14217 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14218 and then Warn_On_Warnings_Off
14220 Warnings_Off_Pragmas.Append ((N, E));
14223 if Is_Enumeration_Type (E) then
14227 Lit := First_Literal (E);
14228 while Present (Lit) loop
14229 Set_Warnings_Off (Lit);
14230 Next_Literal (Lit);
14235 exit when No (Homonym (E));
14240 -- Error if not entity or static string literal case
14242 elsif not Is_Static_String_Expression (Arg2) then
14244 ("second argument of pragma% must be entity " &
14245 "name or static string expression", Arg2);
14247 -- String literal case
14250 String_To_Name_Buffer
14251 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14253 -- Note on configuration pragma case: If this is a
14254 -- configuration pragma, then for an OFF pragma, we
14255 -- just set Config True in the call, which is all
14256 -- that needs to be done. For the case of ON, this
14257 -- is normally an error, unless it is canceling the
14258 -- effect of a previous OFF pragma in the same file.
14259 -- In any other case, an error will be signalled (ON
14260 -- with no matching OFF).
14262 if Chars (Argx) = Name_Off then
14263 Set_Specific_Warning_Off
14264 (Loc, Name_Buffer (1 .. Name_Len),
14265 Config => Is_Configuration_Pragma);
14267 elsif Chars (Argx) = Name_On then
14268 Set_Specific_Warning_On
14269 (Loc, Name_Buffer (1 .. Name_Len), Err);
14273 ("?pragma Warnings On with no " &
14274 "matching Warnings Off",
14284 -------------------
14285 -- Weak_External --
14286 -------------------
14288 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
14290 when Pragma_Weak_External => Weak_External : declare
14295 Check_Arg_Count (1);
14296 Check_Optional_Identifier (Arg1, Name_Entity);
14297 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14298 Ent := Entity (Get_Pragma_Arg (Arg1));
14300 if Rep_Item_Too_Early (Ent, N) then
14303 Ent := Underlying_Type (Ent);
14306 -- The only processing required is to link this item on to the
14307 -- list of rep items for the given entity. This is accomplished
14308 -- by the call to Rep_Item_Too_Late (when no error is detected
14309 -- and False is returned).
14311 if Rep_Item_Too_Late (Ent, N) then
14314 Set_Has_Gigi_Rep_Item (Ent);
14318 -----------------------------
14319 -- Wide_Character_Encoding --
14320 -----------------------------
14322 -- pragma Wide_Character_Encoding (IDENTIFIER);
14324 when Pragma_Wide_Character_Encoding =>
14327 -- Nothing to do, handled in parser. Note that we do not enforce
14328 -- configuration pragma placement, this pragma can appear at any
14329 -- place in the source, allowing mixed encodings within a single
14334 --------------------
14335 -- Unknown_Pragma --
14336 --------------------
14338 -- Should be impossible, since the case of an unknown pragma is
14339 -- separately processed before the case statement is entered.
14341 when Unknown_Pragma =>
14342 raise Program_Error;
14345 -- AI05-0144: detect dangerous order dependence. Disabled for now,
14346 -- until AI is formally approved.
14348 -- Check_Order_Dependence;
14351 when Pragma_Exit => null;
14352 end Analyze_Pragma;
14354 -----------------------------
14355 -- Analyze_TC_In_Decl_Part --
14356 -----------------------------
14358 procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14360 -- Install formals and push subprogram spec onto scope stack so that we
14361 -- can see the formals from the pragma.
14363 Install_Formals (S);
14366 -- Preanalyze the boolean expressions, we treat these as spec
14367 -- expressions (i.e. similar to a default expression).
14369 Preanalyze_TC_Args (Get_Requires_From_Test_Case_Pragma (N),
14370 Get_Ensures_From_Test_Case_Pragma (N));
14372 -- Remove the subprogram from the scope stack now that the pre-analysis
14373 -- of the expressions in the test-case is done.
14376 end Analyze_TC_In_Decl_Part;
14378 --------------------
14379 -- Check_Disabled --
14380 --------------------
14382 function Check_Disabled (Nam : Name_Id) return Boolean is
14386 -- Loop through entries in check policy list
14388 PP := Opt.Check_Policy_List;
14390 -- If there are no specific entries that matched, then nothing is
14391 -- disabled, so return False.
14396 -- Here we have an entry see if it matches
14400 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14402 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14403 return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14405 PP := Next_Pragma (PP);
14410 end Check_Disabled;
14412 -------------------
14413 -- Check_Enabled --
14414 -------------------
14416 function Check_Enabled (Nam : Name_Id) return Boolean is
14420 -- Loop through entries in check policy list
14422 PP := Opt.Check_Policy_List;
14424 -- If there are no specific entries that matched, then we let the
14425 -- setting of assertions govern. Note that this provides the needed
14426 -- compatibility with the RM for the cases of assertion, invariant,
14427 -- precondition, predicate, and postcondition.
14430 return Assertions_Enabled;
14432 -- Here we have an entry see if it matches
14436 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14439 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14440 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14441 when Name_On | Name_Check =>
14443 when Name_Off | Name_Ignore =>
14446 raise Program_Error;
14450 PP := Next_Pragma (PP);
14457 ---------------------------------
14458 -- Delay_Config_Pragma_Analyze --
14459 ---------------------------------
14461 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14463 return Pragma_Name (N) = Name_Interrupt_State
14465 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14466 end Delay_Config_Pragma_Analyze;
14468 -------------------------
14469 -- Get_Base_Subprogram --
14470 -------------------------
14472 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14473 Result : Entity_Id;
14476 -- Follow subprogram renaming chain
14479 while Is_Subprogram (Result)
14481 Nkind (Parent (Declaration_Node (Result))) =
14482 N_Subprogram_Renaming_Declaration
14483 and then Present (Alias (Result))
14485 Result := Alias (Result);
14489 end Get_Base_Subprogram;
14495 procedure Initialize is
14500 -----------------------------
14501 -- Is_Config_Static_String --
14502 -----------------------------
14504 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14506 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14507 -- This is an internal recursive function that is just like the outer
14508 -- function except that it adds the string to the name buffer rather
14509 -- than placing the string in the name buffer.
14511 ------------------------------
14512 -- Add_Config_Static_String --
14513 ------------------------------
14515 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14522 if Nkind (N) = N_Op_Concat then
14523 if Add_Config_Static_String (Left_Opnd (N)) then
14524 N := Right_Opnd (N);
14530 if Nkind (N) /= N_String_Literal then
14531 Error_Msg_N ("string literal expected for pragma argument", N);
14535 for J in 1 .. String_Length (Strval (N)) loop
14536 C := Get_String_Char (Strval (N), J);
14538 if not In_Character_Range (C) then
14540 ("string literal contains invalid wide character",
14541 Sloc (N) + 1 + Source_Ptr (J));
14545 Add_Char_To_Name_Buffer (Get_Character (C));
14550 end Add_Config_Static_String;
14552 -- Start of processing for Is_Config_Static_String
14557 return Add_Config_Static_String (Arg);
14558 end Is_Config_Static_String;
14560 -----------------------------------------
14561 -- Is_Non_Significant_Pragma_Reference --
14562 -----------------------------------------
14564 -- This function makes use of the following static table which indicates
14565 -- whether a given pragma is significant.
14567 -- -1 indicates that references in any argument position are significant
14568 -- 0 indicates that appearance in any argument is not significant
14569 -- +n indicates that appearance as argument n is significant, but all
14570 -- other arguments are not significant
14571 -- 99 special processing required (e.g. for pragma Check)
14573 Sig_Flags : constant array (Pragma_Id) of Int :=
14574 (Pragma_AST_Entry => -1,
14575 Pragma_Abort_Defer => -1,
14576 Pragma_Ada_83 => -1,
14577 Pragma_Ada_95 => -1,
14578 Pragma_Ada_05 => -1,
14579 Pragma_Ada_2005 => -1,
14580 Pragma_Ada_12 => -1,
14581 Pragma_Ada_2012 => -1,
14582 Pragma_All_Calls_Remote => -1,
14583 Pragma_Annotate => -1,
14584 Pragma_Assert => -1,
14585 Pragma_Assertion_Policy => 0,
14586 Pragma_Assume_No_Invalid_Values => 0,
14587 Pragma_Asynchronous => -1,
14588 Pragma_Atomic => 0,
14589 Pragma_Atomic_Components => 0,
14590 Pragma_Attach_Handler => -1,
14591 Pragma_Check => 99,
14592 Pragma_Check_Name => 0,
14593 Pragma_Check_Policy => 0,
14594 Pragma_CIL_Constructor => -1,
14595 Pragma_CPP_Class => 0,
14596 Pragma_CPP_Constructor => 0,
14597 Pragma_CPP_Virtual => 0,
14598 Pragma_CPP_Vtable => 0,
14600 Pragma_C_Pass_By_Copy => 0,
14601 Pragma_Comment => 0,
14602 Pragma_Common_Object => -1,
14603 Pragma_Compile_Time_Error => -1,
14604 Pragma_Compile_Time_Warning => -1,
14605 Pragma_Compiler_Unit => 0,
14606 Pragma_Complete_Representation => 0,
14607 Pragma_Complex_Representation => 0,
14608 Pragma_Component_Alignment => -1,
14609 Pragma_Controlled => 0,
14610 Pragma_Convention => 0,
14611 Pragma_Convention_Identifier => 0,
14612 Pragma_Debug => -1,
14613 Pragma_Debug_Policy => 0,
14614 Pragma_Detect_Blocking => -1,
14615 Pragma_Default_Storage_Pool => -1,
14616 Pragma_Dimension => -1,
14617 Pragma_Discard_Names => 0,
14618 Pragma_Dispatching_Domain => -1,
14619 Pragma_Elaborate => -1,
14620 Pragma_Elaborate_All => -1,
14621 Pragma_Elaborate_Body => -1,
14622 Pragma_Elaboration_Checks => -1,
14623 Pragma_Eliminate => -1,
14624 Pragma_Export => -1,
14625 Pragma_Export_Exception => -1,
14626 Pragma_Export_Function => -1,
14627 Pragma_Export_Object => -1,
14628 Pragma_Export_Procedure => -1,
14629 Pragma_Export_Value => -1,
14630 Pragma_Export_Valued_Procedure => -1,
14631 Pragma_Extend_System => -1,
14632 Pragma_Extensions_Allowed => -1,
14633 Pragma_External => -1,
14634 Pragma_Favor_Top_Level => -1,
14635 Pragma_External_Name_Casing => -1,
14636 Pragma_Fast_Math => -1,
14637 Pragma_Finalize_Storage_Only => 0,
14638 Pragma_Float_Representation => 0,
14639 Pragma_Ident => -1,
14640 Pragma_Implemented => -1,
14641 Pragma_Implicit_Packing => 0,
14642 Pragma_Import => +2,
14643 Pragma_Import_Exception => 0,
14644 Pragma_Import_Function => 0,
14645 Pragma_Import_Object => 0,
14646 Pragma_Import_Procedure => 0,
14647 Pragma_Import_Valued_Procedure => 0,
14648 Pragma_Independent => 0,
14649 Pragma_Independent_Components => 0,
14650 Pragma_Initialize_Scalars => -1,
14651 Pragma_Inline => 0,
14652 Pragma_Inline_Always => 0,
14653 Pragma_Inline_Generic => 0,
14654 Pragma_Inspection_Point => -1,
14655 Pragma_Interface => +2,
14656 Pragma_Interface_Name => +2,
14657 Pragma_Interrupt_Handler => -1,
14658 Pragma_Interrupt_Priority => -1,
14659 Pragma_Interrupt_State => -1,
14660 Pragma_Invariant => -1,
14661 Pragma_Java_Constructor => -1,
14662 Pragma_Java_Interface => -1,
14663 Pragma_Keep_Names => 0,
14664 Pragma_License => -1,
14665 Pragma_Link_With => -1,
14666 Pragma_Linker_Alias => -1,
14667 Pragma_Linker_Constructor => -1,
14668 Pragma_Linker_Destructor => -1,
14669 Pragma_Linker_Options => -1,
14670 Pragma_Linker_Section => -1,
14672 Pragma_Locking_Policy => -1,
14673 Pragma_Long_Float => -1,
14674 Pragma_Machine_Attribute => -1,
14676 Pragma_Main_Storage => -1,
14677 Pragma_Memory_Size => -1,
14678 Pragma_No_Return => 0,
14679 Pragma_No_Body => 0,
14680 Pragma_No_Run_Time => -1,
14681 Pragma_No_Strict_Aliasing => -1,
14682 Pragma_Normalize_Scalars => -1,
14683 Pragma_Obsolescent => 0,
14684 Pragma_Optimize => -1,
14685 Pragma_Optimize_Alignment => -1,
14686 Pragma_Ordered => 0,
14689 Pragma_Passive => -1,
14690 Pragma_Preelaborable_Initialization => -1,
14691 Pragma_Polling => -1,
14692 Pragma_Persistent_BSS => 0,
14693 Pragma_Postcondition => -1,
14694 Pragma_Precondition => -1,
14695 Pragma_Predicate => -1,
14696 Pragma_Preelaborate => -1,
14697 Pragma_Preelaborate_05 => -1,
14698 Pragma_Priority => -1,
14699 Pragma_Priority_Specific_Dispatching => -1,
14700 Pragma_Profile => 0,
14701 Pragma_Profile_Warnings => 0,
14702 Pragma_Propagate_Exceptions => -1,
14703 Pragma_Psect_Object => -1,
14705 Pragma_Pure_05 => -1,
14706 Pragma_Pure_Function => -1,
14707 Pragma_Queuing_Policy => -1,
14708 Pragma_Ravenscar => -1,
14709 Pragma_Relative_Deadline => -1,
14710 Pragma_Remote_Call_Interface => -1,
14711 Pragma_Remote_Types => -1,
14712 Pragma_Restricted_Run_Time => -1,
14713 Pragma_Restriction_Warnings => -1,
14714 Pragma_Restrictions => -1,
14715 Pragma_Reviewable => -1,
14716 Pragma_Short_Circuit_And_Or => -1,
14717 Pragma_Share_Generic => -1,
14718 Pragma_Shared => -1,
14719 Pragma_Shared_Passive => -1,
14720 Pragma_Short_Descriptors => 0,
14721 Pragma_Source_File_Name => -1,
14722 Pragma_Source_File_Name_Project => -1,
14723 Pragma_Source_Reference => -1,
14724 Pragma_Storage_Size => -1,
14725 Pragma_Storage_Unit => -1,
14726 Pragma_Static_Elaboration_Desired => -1,
14727 Pragma_Stream_Convert => -1,
14728 Pragma_Style_Checks => -1,
14729 Pragma_Subtitle => -1,
14730 Pragma_Suppress => 0,
14731 Pragma_Suppress_Exception_Locations => 0,
14732 Pragma_Suppress_All => -1,
14733 Pragma_Suppress_Debug_Info => 0,
14734 Pragma_Suppress_Initialization => 0,
14735 Pragma_System_Name => -1,
14736 Pragma_Task_Dispatching_Policy => -1,
14737 Pragma_Task_Info => -1,
14738 Pragma_Task_Name => -1,
14739 Pragma_Task_Storage => 0,
14740 Pragma_Test_Case => -1,
14741 Pragma_Thread_Local_Storage => 0,
14742 Pragma_Time_Slice => -1,
14743 Pragma_Title => -1,
14744 Pragma_Unchecked_Union => 0,
14745 Pragma_Unimplemented_Unit => -1,
14746 Pragma_Universal_Aliasing => -1,
14747 Pragma_Universal_Data => -1,
14748 Pragma_Unmodified => -1,
14749 Pragma_Unreferenced => -1,
14750 Pragma_Unreferenced_Objects => -1,
14751 Pragma_Unreserve_All_Interrupts => -1,
14752 Pragma_Unsuppress => 0,
14753 Pragma_Use_VADS_Size => -1,
14754 Pragma_Validity_Checks => -1,
14755 Pragma_Volatile => 0,
14756 Pragma_Volatile_Components => 0,
14757 Pragma_Warnings => -1,
14758 Pragma_Weak_External => -1,
14759 Pragma_Wide_Character_Encoding => 0,
14760 Unknown_Pragma => 0);
14762 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14771 if Nkind (P) /= N_Pragma_Argument_Association then
14775 Id := Get_Pragma_Id (Parent (P));
14776 C := Sig_Flags (Id);
14788 -- For pragma Check, the first argument is not significant,
14789 -- the second and the third (if present) arguments are
14792 when Pragma_Check =>
14794 P = First (Pragma_Argument_Associations (Parent (P)));
14797 raise Program_Error;
14801 A := First (Pragma_Argument_Associations (Parent (P)));
14802 for J in 1 .. C - 1 loop
14810 return A = P; -- is this wrong way round ???
14813 end Is_Non_Significant_Pragma_Reference;
14815 ------------------------------
14816 -- Is_Pragma_String_Literal --
14817 ------------------------------
14819 -- This function returns true if the corresponding pragma argument is a
14820 -- static string expression. These are the only cases in which string
14821 -- literals can appear as pragma arguments. We also allow a string literal
14822 -- as the first argument to pragma Assert (although it will of course
14823 -- always generate a type error).
14825 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14826 Pragn : constant Node_Id := Parent (Par);
14827 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14828 Pname : constant Name_Id := Pragma_Name (Pragn);
14834 N := First (Assoc);
14841 if Pname = Name_Assert then
14844 elsif Pname = Name_Export then
14847 elsif Pname = Name_Ident then
14850 elsif Pname = Name_Import then
14853 elsif Pname = Name_Interface_Name then
14856 elsif Pname = Name_Linker_Alias then
14859 elsif Pname = Name_Linker_Section then
14862 elsif Pname = Name_Machine_Attribute then
14865 elsif Pname = Name_Source_File_Name then
14868 elsif Pname = Name_Source_Reference then
14871 elsif Pname = Name_Title then
14874 elsif Pname = Name_Subtitle then
14880 end Is_Pragma_String_Literal;
14882 ------------------------
14883 -- Preanalyze_TC_Args --
14884 ------------------------
14886 procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id) is
14888 -- Preanalyze the boolean expressions, we treat these as spec
14889 -- expressions (i.e. similar to a default expression).
14891 if Present (Arg_Req) then
14892 Preanalyze_Spec_Expression
14893 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
14896 if Present (Arg_Ens) then
14897 Preanalyze_Spec_Expression
14898 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
14900 end Preanalyze_TC_Args;
14902 --------------------------------------
14903 -- Process_Compilation_Unit_Pragmas --
14904 --------------------------------------
14906 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14908 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14909 -- strange because it comes at the end of the unit. Rational has the
14910 -- same name for a pragma, but treats it as a program unit pragma, In
14911 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14912 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14913 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14914 -- the context clause to ensure the correct processing.
14916 if Has_Pragma_Suppress_All (N) then
14917 Prepend_To (Context_Items (N),
14918 Make_Pragma (Sloc (N),
14919 Chars => Name_Suppress,
14920 Pragma_Argument_Associations => New_List (
14921 Make_Pragma_Argument_Association (Sloc (N),
14922 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14925 -- Nothing else to do at the current time!
14927 end Process_Compilation_Unit_Pragmas;
14938 --------------------------------
14939 -- Set_Encoded_Interface_Name --
14940 --------------------------------
14942 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14943 Str : constant String_Id := Strval (S);
14944 Len : constant Int := String_Length (Str);
14949 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14952 -- Stores encoded value of character code CC. The encoding we use an
14953 -- underscore followed by four lower case hex digits.
14959 procedure Encode is
14961 Store_String_Char (Get_Char_Code ('_'));
14963 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14965 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14967 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14969 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14972 -- Start of processing for Set_Encoded_Interface_Name
14975 -- If first character is asterisk, this is a link name, and we leave it
14976 -- completely unmodified. We also ignore null strings (the latter case
14977 -- happens only in error cases) and no encoding should occur for Java or
14978 -- AAMP interface names.
14981 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14982 or else VM_Target /= No_VM
14983 or else AAMP_On_Target
14985 Set_Interface_Name (E, S);
14990 CC := Get_String_Char (Str, J);
14992 exit when not In_Character_Range (CC);
14994 C := Get_Character (CC);
14996 exit when C /= '_' and then C /= '$'
14997 and then C not in '0' .. '9'
14998 and then C not in 'a' .. 'z'
14999 and then C not in 'A' .. 'Z';
15002 Set_Interface_Name (E, S);
15010 -- Here we need to encode. The encoding we use as follows:
15011 -- three underscores + four hex digits (lower case)
15015 for J in 1 .. String_Length (Str) loop
15016 CC := Get_String_Char (Str, J);
15018 if not In_Character_Range (CC) then
15021 C := Get_Character (CC);
15023 if C = '_' or else C = '$'
15024 or else C in '0' .. '9'
15025 or else C in 'a' .. 'z'
15026 or else C in 'A' .. 'Z'
15028 Store_String_Char (CC);
15035 Set_Interface_Name (E,
15036 Make_String_Literal (Sloc (S),
15037 Strval => End_String));
15039 end Set_Encoded_Interface_Name;
15041 -------------------
15042 -- Set_Unit_Name --
15043 -------------------
15045 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15050 if Nkind (N) = N_Identifier
15051 and then Nkind (With_Item) = N_Identifier
15053 Set_Entity (N, Entity (With_Item));
15055 elsif Nkind (N) = N_Selected_Component then
15056 Change_Selected_Component_To_Expanded_Name (N);
15057 Set_Entity (N, Entity (With_Item));
15058 Set_Entity (Selector_Name (N), Entity (N));
15060 Pref := Prefix (N);
15061 Scop := Scope (Entity (N));
15062 while Nkind (Pref) = N_Selected_Component loop
15063 Change_Selected_Component_To_Expanded_Name (Pref);
15064 Set_Entity (Selector_Name (Pref), Scop);
15065 Set_Entity (Pref, Scop);
15066 Pref := Prefix (Pref);
15067 Scop := Scope (Scop);
15070 Set_Entity (Pref, Scop);