1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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_Ch7; use Exp_Ch7;
41 with Exp_Dist; use Exp_Dist;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet.Sp; use Namet.Sp;
46 with Nlists; use Nlists;
47 with Nmake; use Nmake;
49 with Output; use Output;
50 with Par_SCO; use Par_SCO;
51 with Restrict; use Restrict;
52 with Rident; use Rident;
53 with Rtsfind; use Rtsfind;
55 with Sem_Aux; use Sem_Aux;
56 with Sem_Ch3; use Sem_Ch3;
57 with Sem_Ch6; use Sem_Ch6;
58 with Sem_Ch8; use Sem_Ch8;
59 with Sem_Ch12; use Sem_Ch12;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Dist; use Sem_Dist;
62 with Sem_Elim; use Sem_Elim;
63 with Sem_Eval; use Sem_Eval;
64 with Sem_Intr; use Sem_Intr;
65 with Sem_Mech; use Sem_Mech;
66 with Sem_Res; use Sem_Res;
67 with Sem_Type; use Sem_Type;
68 with Sem_Util; use Sem_Util;
69 with Sem_VFpt; use Sem_VFpt;
70 with Sem_Warn; use Sem_Warn;
71 with Stand; use Stand;
72 with Sinfo; use Sinfo;
73 with Sinfo.CN; use Sinfo.CN;
74 with Sinput; use Sinput;
75 with Snames; use Snames;
76 with Stringt; use Stringt;
77 with Stylesw; use Stylesw;
79 with Targparm; use Targparm;
80 with Tbuild; use Tbuild;
82 with Uintp; use Uintp;
83 with Uname; use Uname;
84 with Urealp; use Urealp;
85 with Validsw; use Validsw;
87 package body Sem_Prag is
89 ----------------------------------------------
90 -- Common Handling of Import-Export Pragmas --
91 ----------------------------------------------
93 -- In the following section, a number of Import_xxx and Export_xxx
94 -- pragmas are defined by GNAT. These are compatible with the DEC
95 -- pragmas of the same name, and all have the following common
96 -- form and processing:
99 -- [Internal =>] LOCAL_NAME
100 -- [, [External =>] EXTERNAL_SYMBOL]
101 -- [, other optional parameters ]);
104 -- [Internal =>] LOCAL_NAME
105 -- [, [External =>] EXTERNAL_SYMBOL]
106 -- [, other optional parameters ]);
108 -- EXTERNAL_SYMBOL ::=
110 -- | static_string_EXPRESSION
112 -- The internal LOCAL_NAME designates the entity that is imported or
113 -- exported, and must refer to an entity in the current declarative
114 -- part (as required by the rules for LOCAL_NAME).
116 -- The external linker name is designated by the External parameter if
117 -- given, or the Internal parameter if not (if there is no External
118 -- parameter, the External parameter is a copy of the Internal name).
120 -- If the External parameter is given as a string, then this string is
121 -- treated as an external name (exactly as though it had been given as an
122 -- External_Name parameter for a normal Import pragma).
124 -- If the External parameter is given as an identifier (or there is no
125 -- External parameter, so that the Internal identifier is used), then
126 -- the external name is the characters of the identifier, translated
127 -- to all upper case letters for OpenVMS versions of GNAT, and to all
128 -- lower case letters for all other versions
130 -- Note: the external name specified or implied by any of these special
131 -- Import_xxx or Export_xxx pragmas override an external or link name
132 -- specified in a previous Import or Export pragma.
134 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
135 -- named notation, following the standard rules for subprogram calls, i.e.
136 -- parameters can be given in any order if named notation is used, and
137 -- positional and named notation can be mixed, subject to the rule that all
138 -- positional parameters must appear first.
140 -- Note: All these pragmas are implemented exactly following the DEC design
141 -- and implementation and are intended to be fully compatible with the use
142 -- of these pragmas in the DEC Ada compiler.
144 --------------------------------------------
145 -- Checking for Duplicated External Names --
146 --------------------------------------------
148 -- It is suspicious if two separate Export pragmas use the same external
149 -- name. The following table is used to diagnose this situation so that
150 -- an appropriate warning can be issued.
152 -- The Node_Id stored is for the N_String_Literal node created to hold
153 -- the value of the external name. The Sloc of this node is used to
154 -- cross-reference the location of the duplication.
156 package Externals is new Table.Table (
157 Table_Component_Type => Node_Id,
158 Table_Index_Type => Int,
159 Table_Low_Bound => 0,
160 Table_Initial => 100,
161 Table_Increment => 100,
162 Table_Name => "Name_Externals");
164 -------------------------------------
165 -- Local Subprograms and Variables --
166 -------------------------------------
168 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
169 -- This routine is used for possible casing adjustment of an explicit
170 -- external name supplied as a string literal (the node N), according to
171 -- the casing requirement of Opt.External_Name_Casing. If this is set to
172 -- As_Is, then the string literal is returned unchanged, but if it is set
173 -- to Uppercase or Lowercase, then a new string literal with appropriate
174 -- casing is constructed.
176 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
177 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
178 -- original one, following the renaming chain) is returned. Otherwise the
179 -- entity is returned unchanged. Should be in Einfo???
181 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
182 -- All the routines that check pragma arguments take either a pragma
183 -- argument association (in which case the expression of the argument
184 -- association is checked), or the expression directly. The function
185 -- Get_Pragma_Arg is a utility used to deal with these two cases. If Arg
186 -- is a pragma argument association node, then its expression is returned,
187 -- otherwise Arg is returned unchanged.
190 -- This is a dummy function called by the processing for pragma Reviewable.
191 -- It is there for assisting front end debugging. By placing a Reviewable
192 -- pragma in the source program, a breakpoint on rv catches this place in
193 -- the source, allowing convenient stepping to the point of interest.
195 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
196 -- Place semantic information on the argument of an Elaborate/Elaborate_All
197 -- pragma. Entity name for unit and its parents is taken from item in
198 -- previous with_clause that mentions the unit.
200 -------------------------------
201 -- Adjust_External_Name_Case --
202 -------------------------------
204 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
208 -- Adjust case of literal if required
210 if Opt.External_Name_Exp_Casing = As_Is then
214 -- Copy existing string
220 for J in 1 .. String_Length (Strval (N)) loop
221 CC := Get_String_Char (Strval (N), J);
223 if Opt.External_Name_Exp_Casing = Uppercase
224 and then CC >= Get_Char_Code ('a')
225 and then CC <= Get_Char_Code ('z')
227 Store_String_Char (CC - 32);
229 elsif Opt.External_Name_Exp_Casing = Lowercase
230 and then CC >= Get_Char_Code ('A')
231 and then CC <= Get_Char_Code ('Z')
233 Store_String_Char (CC + 32);
236 Store_String_Char (CC);
241 Make_String_Literal (Sloc (N),
242 Strval => End_String);
244 end Adjust_External_Name_Case;
246 ------------------------------
247 -- Analyze_PPC_In_Decl_Part --
248 ------------------------------
250 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
251 Arg1 : constant Node_Id :=
252 First (Pragma_Argument_Associations (N));
253 Arg2 : constant Node_Id := Next (Arg1);
256 -- Install formals and push subprogram spec onto scope stack so that we
257 -- can see the formals from the pragma.
262 -- Preanalyze the boolean expression, we treat this as a spec expression
263 -- (i.e. similar to a default expression).
265 Preanalyze_Spec_Expression
266 (Get_Pragma_Arg (Arg1), Standard_Boolean);
268 -- If there is a message argument, analyze it the same way
270 if Present (Arg2) then
271 Preanalyze_Spec_Expression
272 (Get_Pragma_Arg (Arg2), Standard_String);
275 -- Remove the subprogram from the scope stack now that the pre-analysis
276 -- of the precondition/postcondition is done.
279 end Analyze_PPC_In_Decl_Part;
285 procedure Analyze_Pragma (N : Node_Id) is
286 Loc : constant Source_Ptr := Sloc (N);
287 Pname : constant Name_Id := Pragma_Name (N);
290 Pragma_Exit : exception;
291 -- This exception is used to exit pragma processing completely. It is
292 -- used when an error is detected, and no further processing is
293 -- required. It is also used if an earlier error has left the tree in
294 -- a state where the pragma should not be processed.
297 -- Number of pragma argument associations
303 -- First four pragma arguments (pragma argument association nodes, or
304 -- Empty if the corresponding argument does not exist).
306 type Name_List is array (Natural range <>) of Name_Id;
307 type Args_List is array (Natural range <>) of Node_Id;
308 -- Types used for arguments to Check_Arg_Order and Gather_Associations
310 procedure Ada_2005_Pragma;
311 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
312 -- Ada 95 mode, these are implementation defined pragmas, so should be
313 -- caught by the No_Implementation_Pragmas restriction.
315 procedure Ada_2012_Pragma;
316 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
317 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
318 -- should be caught by the No_Implementation_Pragmas restriction.
320 procedure Check_Ada_83_Warning;
321 -- Issues a warning message for the current pragma if operating in Ada
322 -- 83 mode (used for language pragmas that are not a standard part of
323 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
326 procedure Check_Arg_Count (Required : Nat);
327 -- Check argument count for pragma is equal to given parameter. If not,
328 -- then issue an error message and raise Pragma_Exit.
330 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
331 -- Arg which can either be a pragma argument association, in which case
332 -- the check is applied to the expression of the association or an
333 -- expression directly.
335 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
336 -- Check that an argument has the right form for an EXTERNAL_NAME
337 -- parameter of an extended import/export pragma. The rule is that the
338 -- name must be an identifier or string literal (in Ada 83 mode) or a
339 -- static string expression (in Ada 95 mode).
341 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
342 -- Check the specified argument Arg to make sure that it is an
343 -- identifier. If not give error and raise Pragma_Exit.
345 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
346 -- Check the specified argument Arg to make sure that it is an integer
347 -- literal. If not give error and raise Pragma_Exit.
349 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
350 -- Check the specified argument Arg to make sure that it has the proper
351 -- syntactic form for a local name and meets the semantic requirements
352 -- for a local name. The local name is analyzed as part of the
353 -- processing for this call. In addition, the local name is required
354 -- to represent an entity at the library level.
356 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
357 -- Check the specified argument Arg to make sure that it has the proper
358 -- syntactic form for a local name and meets the semantic requirements
359 -- for a local name. The local name is analyzed as part of the
360 -- processing for this call.
362 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
363 -- Check the specified argument Arg to make sure that it is a valid
364 -- locking policy name. If not give error and raise Pragma_Exit.
366 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
367 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
368 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
369 -- Check the specified argument Arg to make sure that it is an
370 -- identifier whose name matches either N1 or N2 (or N3 if present).
371 -- If not then give error and raise Pragma_Exit.
373 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
374 -- Check the specified argument Arg to make sure that it is a valid
375 -- queuing policy name. If not give error and raise Pragma_Exit.
377 procedure Check_Arg_Is_Static_Expression
379 Typ : Entity_Id := Empty);
380 -- Check the specified argument Arg to make sure that it is a static
381 -- expression of the given type (i.e. it will be analyzed and resolved
382 -- using this type, which can be any valid argument to Resolve, e.g.
383 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
384 -- Typ is left Empty, then any static expression is allowed.
386 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
387 -- Check the specified argument Arg to make sure that it is a valid task
388 -- dispatching policy name. If not give error and raise Pragma_Exit.
390 procedure Check_Arg_Order (Names : Name_List);
391 -- Checks for an instance of two arguments with identifiers for the
392 -- current pragma which are not in the sequence indicated by Names,
393 -- and if so, generates a fatal message about bad order of arguments.
395 procedure Check_At_Least_N_Arguments (N : Nat);
396 -- Check there are at least N arguments present
398 procedure Check_At_Most_N_Arguments (N : Nat);
399 -- Check there are no more than N arguments present
401 procedure Check_Component
404 In_Variant_Part : Boolean := False);
405 -- Examine an Unchecked_Union component for correct use of per-object
406 -- constrained subtypes, and for restrictions on finalizable components.
407 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
408 -- should be set when Comp comes from a record variant.
410 procedure Check_Duplicate_Pragma (E : Entity_Id);
411 -- Check if a pragma of the same name as the current pragma is already
412 -- chained as a rep pragma to the given entity. if so give a message
413 -- about the duplicate, using Error_Pragma so the call does not return.
415 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
416 -- Nam is an N_String_Literal node containing the external name set by
417 -- an Import or Export pragma (or extended Import or Export pragma).
418 -- This procedure checks for possible duplications if this is the export
419 -- case, and if found, issues an appropriate error message.
421 procedure Check_First_Subtype (Arg : Node_Id);
422 -- Checks that Arg, whose expression is an entity name referencing a
423 -- subtype, does not reference a type that is not a first subtype.
425 procedure Check_In_Main_Program;
426 -- Common checks for pragmas that appear within a main program
427 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline).
429 procedure Check_Interrupt_Or_Attach_Handler;
430 -- Common processing for first argument of pragma Interrupt_Handler or
431 -- pragma Attach_Handler.
433 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
434 -- Check that pragma appears in a declarative part, or in a package
435 -- specification, i.e. that it does not occur in a statement sequence
438 procedure Check_No_Identifier (Arg : Node_Id);
439 -- Checks that the given argument does not have an identifier. If
440 -- an identifier is present, then an error message is issued, and
441 -- Pragma_Exit is raised.
443 procedure Check_No_Identifiers;
444 -- Checks that none of the arguments to the pragma has an identifier.
445 -- If any argument has an identifier, then an error message is issued,
446 -- and Pragma_Exit is raised.
448 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
449 -- Checks if the given argument has an identifier, and if so, requires
450 -- it to match the given identifier name. If there is a non-matching
451 -- identifier, then an error message is given and Error_Pragmas raised.
453 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
454 -- Checks if the given argument has an identifier, and if so, requires
455 -- it to match the given identifier name. If there is a non-matching
456 -- identifier, then an error message is given and Error_Pragmas raised.
457 -- In this version of the procedure, the identifier name is given as
458 -- a string with lower case letters.
460 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
461 -- Called to process a precondition or postcondition pragma. There are
464 -- The pragma appears after a subprogram spec
466 -- If the corresponding check is not enabled, the pragma is analyzed
467 -- but otherwise ignored and control returns with In_Body set False.
469 -- If the check is enabled, then the first step is to analyze the
470 -- pragma, but this is skipped if the subprogram spec appears within
471 -- a package specification (because this is the case where we delay
472 -- analysis till the end of the spec). Then (whether or not it was
473 -- analyzed), the pragma is chained to the subprogram in question
474 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
475 -- caller with In_Body set False.
477 -- The pragma appears at the start of subprogram body declarations
479 -- In this case an immediate return to the caller is made with
480 -- In_Body set True, and the pragma is NOT analyzed.
482 -- In all other cases, an error message for bad placement is given
484 procedure Check_Static_Constraint (Constr : Node_Id);
485 -- Constr is a constraint from an N_Subtype_Indication node from a
486 -- component constraint in an Unchecked_Union type. This routine checks
487 -- that the constraint is static as required by the restrictions for
490 procedure Check_Valid_Configuration_Pragma;
491 -- Legality checks for placement of a configuration pragma
493 procedure Check_Valid_Library_Unit_Pragma;
494 -- Legality checks for library unit pragmas. A special case arises for
495 -- pragmas in generic instances that come from copies of the original
496 -- library unit pragmas in the generic templates. In the case of other
497 -- than library level instantiations these can appear in contexts which
498 -- would normally be invalid (they only apply to the original template
499 -- and to library level instantiations), and they are simply ignored,
500 -- which is implemented by rewriting them as null statements.
502 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
503 -- Check an Unchecked_Union variant for lack of nested variants and
504 -- presence of at least one component. UU_Typ is the related Unchecked_
507 procedure Error_Pragma (Msg : String);
508 pragma No_Return (Error_Pragma);
509 -- Outputs error message for current pragma. The message contains a %
510 -- that will be replaced with the pragma name, and the flag is placed
511 -- on the pragma itself. Pragma_Exit is then raised.
513 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
514 pragma No_Return (Error_Pragma_Arg);
515 -- Outputs error message for current pragma. The message may contain
516 -- a % that will be replaced with the pragma name. The parameter Arg
517 -- may either be a pragma argument association, in which case the flag
518 -- is placed on the expression of this association, or an expression,
519 -- in which case the flag is placed directly on the expression. The
520 -- message is placed using Error_Msg_N, so the message may also contain
521 -- an & insertion character which will reference the given Arg value.
522 -- After placing the message, Pragma_Exit is raised.
524 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
525 pragma No_Return (Error_Pragma_Arg);
526 -- Similar to above form of Error_Pragma_Arg except that two messages
527 -- are provided, the second is a continuation comment starting with \.
529 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
530 pragma No_Return (Error_Pragma_Arg_Ident);
531 -- Outputs error message for current pragma. The message may contain
532 -- a % that will be replaced with the pragma name. The parameter Arg
533 -- must be a pragma argument association with a non-empty identifier
534 -- (i.e. its Chars field must be set), and the error message is placed
535 -- on the identifier. The message is placed using Error_Msg_N so
536 -- the message may also contain an & insertion character which will
537 -- reference the identifier. After placing the message, Pragma_Exit
540 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
541 pragma No_Return (Error_Pragma_Ref);
542 -- Outputs error message for current pragma. The message may contain
543 -- a % that will be replaced with the pragma name. The parameter Ref
544 -- must be an entity whose name can be referenced by & and sloc by #.
545 -- After placing the message, Pragma_Exit is raised.
547 function Find_Lib_Unit_Name return Entity_Id;
548 -- Used for a library unit pragma to find the entity to which the
549 -- library unit pragma applies, returns the entity found.
551 procedure Find_Program_Unit_Name (Id : Node_Id);
552 -- If the pragma is a compilation unit pragma, the id must denote the
553 -- compilation unit in the same compilation, and the pragma must appear
554 -- in the list of preceding or trailing pragmas. If it is a program
555 -- unit pragma that is not a compilation unit pragma, then the
556 -- identifier must be visible.
558 function Find_Unique_Parameterless_Procedure
560 Arg : Node_Id) return Entity_Id;
561 -- Used for a procedure pragma to find the unique parameterless
562 -- procedure identified by Name, returns it if it exists, otherwise
563 -- errors out and uses Arg as the pragma argument for the message.
565 procedure Gather_Associations
567 Args : out Args_List);
568 -- This procedure is used to gather the arguments for a pragma that
569 -- permits arbitrary ordering of parameters using the normal rules
570 -- for named and positional parameters. The Names argument is a list
571 -- of Name_Id values that corresponds to the allowed pragma argument
572 -- association identifiers in order. The result returned in Args is
573 -- a list of corresponding expressions that are the pragma arguments.
574 -- Note that this is a list of expressions, not of pragma argument
575 -- associations (Gather_Associations has completely checked all the
576 -- optional identifiers when it returns). An entry in Args is Empty
577 -- on return if the corresponding argument is not present.
579 procedure GNAT_Pragma;
580 -- Called for all GNAT defined pragmas to check the relevant restriction
581 -- (No_Implementation_Pragmas).
583 function Is_Before_First_Decl
584 (Pragma_Node : Node_Id;
585 Decls : List_Id) return Boolean;
586 -- Return True if Pragma_Node is before the first declarative item in
587 -- Decls where Decls is the list of declarative items.
589 function Is_Configuration_Pragma return Boolean;
590 -- Determines if the placement of the current pragma is appropriate
591 -- for a configuration pragma.
593 function Is_In_Context_Clause return Boolean;
594 -- Returns True if pragma appears within the context clause of a unit,
595 -- and False for any other placement (does not generate any messages).
597 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
598 -- Analyzes the argument, and determines if it is a static string
599 -- expression, returns True if so, False if non-static or not String.
601 procedure Pragma_Misplaced;
602 pragma No_Return (Pragma_Misplaced);
603 -- Issue fatal error message for misplaced pragma
605 procedure Process_Atomic_Shared_Volatile;
606 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
607 -- Shared is an obsolete Ada 83 pragma, treated as being identical
608 -- in effect to pragma Atomic.
610 procedure Process_Compile_Time_Warning_Or_Error;
611 -- Common processing for Compile_Time_Error and Compile_Time_Warning
613 procedure Process_Convention
614 (C : out Convention_Id;
615 Ent : out Entity_Id);
616 -- Common processing for Convention, Interface, Import and Export.
617 -- Checks first two arguments of pragma, and sets the appropriate
618 -- convention value in the specified entity or entities. On return
619 -- C is the convention, Ent is the referenced entity.
621 procedure Process_Extended_Import_Export_Exception_Pragma
622 (Arg_Internal : Node_Id;
623 Arg_External : Node_Id;
626 -- Common processing for the pragmas Import/Export_Exception. The three
627 -- arguments correspond to the three named parameters of the pragma. An
628 -- argument is empty if the corresponding parameter is not present in
631 procedure Process_Extended_Import_Export_Object_Pragma
632 (Arg_Internal : Node_Id;
633 Arg_External : Node_Id;
635 -- Common processing for the pragmas Import/Export_Object. The three
636 -- arguments correspond to the three named parameters of the pragmas. An
637 -- argument is empty if the corresponding parameter is not present in
640 procedure Process_Extended_Import_Export_Internal_Arg
641 (Arg_Internal : Node_Id := Empty);
642 -- Common processing for all extended Import and Export pragmas. The
643 -- argument is the pragma parameter for the Internal argument. If
644 -- Arg_Internal is empty or inappropriate, an error message is posted.
645 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
646 -- set to identify the referenced entity.
648 procedure Process_Extended_Import_Export_Subprogram_Pragma
649 (Arg_Internal : Node_Id;
650 Arg_External : Node_Id;
651 Arg_Parameter_Types : Node_Id;
652 Arg_Result_Type : Node_Id := Empty;
653 Arg_Mechanism : Node_Id;
654 Arg_Result_Mechanism : Node_Id := Empty;
655 Arg_First_Optional_Parameter : Node_Id := Empty);
656 -- Common processing for all extended Import and Export pragmas applying
657 -- to subprograms. The caller omits any arguments that do not apply to
658 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
659 -- only in the Import_Function and Export_Function cases). The argument
660 -- names correspond to the allowed pragma association identifiers.
662 procedure Process_Generic_List;
663 -- Common processing for Share_Generic and Inline_Generic
665 procedure Process_Import_Or_Interface;
666 -- Common processing for Import of Interface
668 procedure Process_Inline (Active : Boolean);
669 -- Common processing for Inline and Inline_Always. The parameter
670 -- indicates if the inline pragma is active, i.e. if it should actually
671 -- cause inlining to occur.
673 procedure Process_Interface_Name
674 (Subprogram_Def : Entity_Id;
677 -- Given the last two arguments of pragma Import, pragma Export, or
678 -- pragma Interface_Name, performs validity checks and sets the
679 -- Interface_Name field of the given subprogram entity to the
680 -- appropriate external or link name, depending on the arguments given.
681 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
682 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
683 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
684 -- nor Link_Arg is present, the interface name is set to the default
685 -- from the subprogram name.
687 procedure Process_Interrupt_Or_Attach_Handler;
688 -- Common processing for Interrupt and Attach_Handler pragmas
690 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
691 -- Common processing for Restrictions and Restriction_Warnings pragmas.
692 -- Warn is True for Restriction_Warnings, or for Restrictions if the
693 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
694 -- is not set in the Restrictions case.
696 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
697 -- Common processing for Suppress and Unsuppress. The boolean parameter
698 -- Suppress_Case is True for the Suppress case, and False for the
701 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
702 -- This procedure sets the Is_Exported flag for the given entity,
703 -- checking that the entity was not previously imported. Arg is
704 -- the argument that specified the entity. A check is also made
705 -- for exporting inappropriate entities.
707 procedure Set_Extended_Import_Export_External_Name
708 (Internal_Ent : Entity_Id;
709 Arg_External : Node_Id);
710 -- Common processing for all extended import export pragmas. The first
711 -- argument, Internal_Ent, is the internal entity, which has already
712 -- been checked for validity by the caller. Arg_External is from the
713 -- Import or Export pragma, and may be null if no External parameter
714 -- was present. If Arg_External is present and is a non-null string
715 -- (a null string is treated as the default), then the Interface_Name
716 -- field of Internal_Ent is set appropriately.
718 procedure Set_Imported (E : Entity_Id);
719 -- This procedure sets the Is_Imported flag for the given entity,
720 -- checking that it is not previously exported or imported.
722 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
723 -- Mech is a parameter passing mechanism (see Import_Function syntax
724 -- for MECHANISM_NAME). This routine checks that the mechanism argument
725 -- has the right form, and if not issues an error message. If the
726 -- argument has the right form then the Mechanism field of Ent is
727 -- set appropriately.
729 procedure Set_Ravenscar_Profile (N : Node_Id);
730 -- Activate the set of configuration pragmas and restrictions that make
731 -- up the Ravenscar Profile. N is the corresponding pragma node, which
732 -- is used for error messages on any constructs that violate the
735 ---------------------
736 -- Ada_2005_Pragma --
737 ---------------------
739 procedure Ada_2005_Pragma is
741 if Ada_Version <= Ada_95 then
742 Check_Restriction (No_Implementation_Pragmas, N);
746 ---------------------
747 -- Ada_2012_Pragma --
748 ---------------------
750 procedure Ada_2012_Pragma is
752 if Ada_Version <= Ada_05 then
753 Check_Restriction (No_Implementation_Pragmas, N);
757 --------------------------
758 -- Check_Ada_83_Warning --
759 --------------------------
761 procedure Check_Ada_83_Warning is
763 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
764 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
766 end Check_Ada_83_Warning;
768 ---------------------
769 -- Check_Arg_Count --
770 ---------------------
772 procedure Check_Arg_Count (Required : Nat) is
774 if Arg_Count /= Required then
775 Error_Pragma ("wrong number of arguments for pragma%");
779 --------------------------------
780 -- Check_Arg_Is_External_Name --
781 --------------------------------
783 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
784 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
787 if Nkind (Argx) = N_Identifier then
791 Analyze_And_Resolve (Argx, Standard_String);
793 if Is_OK_Static_Expression (Argx) then
796 elsif Etype (Argx) = Any_Type then
799 -- An interesting special case, if we have a string literal and
800 -- we are in Ada 83 mode, then we allow it even though it will
801 -- not be flagged as static. This allows expected Ada 83 mode
802 -- use of external names which are string literals, even though
803 -- technically these are not static in Ada 83.
805 elsif Ada_Version = Ada_83
806 and then Nkind (Argx) = N_String_Literal
810 -- Static expression that raises Constraint_Error. This has
811 -- already been flagged, so just exit from pragma processing.
813 elsif Is_Static_Expression (Argx) then
816 -- Here we have a real error (non-static expression)
819 Error_Msg_Name_1 := Pname;
821 ("argument for pragma% must be a identifier or " &
822 "static string expression!", Argx);
826 end Check_Arg_Is_External_Name;
828 -----------------------------
829 -- Check_Arg_Is_Identifier --
830 -----------------------------
832 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
833 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
835 if Nkind (Argx) /= N_Identifier then
837 ("argument for pragma% must be identifier", Argx);
839 end Check_Arg_Is_Identifier;
841 ----------------------------------
842 -- Check_Arg_Is_Integer_Literal --
843 ----------------------------------
845 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
846 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
848 if Nkind (Argx) /= N_Integer_Literal then
850 ("argument for pragma% must be integer literal", Argx);
852 end Check_Arg_Is_Integer_Literal;
854 -------------------------------------------
855 -- Check_Arg_Is_Library_Level_Local_Name --
856 -------------------------------------------
860 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
861 -- | library_unit_NAME
863 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
865 Check_Arg_Is_Local_Name (Arg);
867 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
868 and then Comes_From_Source (N)
871 ("argument for pragma% must be library level entity", Arg);
873 end Check_Arg_Is_Library_Level_Local_Name;
875 -----------------------------
876 -- Check_Arg_Is_Local_Name --
877 -----------------------------
881 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
882 -- | library_unit_NAME
884 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
885 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
890 if Nkind (Argx) not in N_Direct_Name
891 and then (Nkind (Argx) /= N_Attribute_Reference
892 or else Present (Expressions (Argx))
893 or else Nkind (Prefix (Argx)) /= N_Identifier)
894 and then (not Is_Entity_Name (Argx)
895 or else not Is_Compilation_Unit (Entity (Argx)))
897 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
900 if Is_Entity_Name (Argx)
901 and then Scope (Entity (Argx)) /= Current_Scope
904 ("pragma% argument must be in same declarative part", Arg);
906 end Check_Arg_Is_Local_Name;
908 ---------------------------------
909 -- Check_Arg_Is_Locking_Policy --
910 ---------------------------------
912 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
913 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
916 Check_Arg_Is_Identifier (Argx);
918 if not Is_Locking_Policy_Name (Chars (Argx)) then
920 ("& is not a valid locking policy name", Argx);
922 end Check_Arg_Is_Locking_Policy;
924 -------------------------
925 -- Check_Arg_Is_One_Of --
926 -------------------------
928 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
929 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
932 Check_Arg_Is_Identifier (Argx);
934 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
935 Error_Msg_Name_2 := N1;
936 Error_Msg_Name_3 := N2;
937 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
939 end Check_Arg_Is_One_Of;
941 procedure Check_Arg_Is_One_Of
943 N1, N2, N3 : Name_Id)
945 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
948 Check_Arg_Is_Identifier (Argx);
950 if Chars (Argx) /= N1
951 and then Chars (Argx) /= N2
952 and then Chars (Argx) /= N3
954 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
956 end Check_Arg_Is_One_Of;
958 procedure Check_Arg_Is_One_Of
960 N1, N2, N3, N4 : Name_Id)
962 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
965 Check_Arg_Is_Identifier (Argx);
967 if Chars (Argx) /= N1
968 and then Chars (Argx) /= N2
969 and then Chars (Argx) /= N3
970 and then Chars (Argx) /= N4
972 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
974 end Check_Arg_Is_One_Of;
976 ---------------------------------
977 -- Check_Arg_Is_Queuing_Policy --
978 ---------------------------------
980 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
981 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
984 Check_Arg_Is_Identifier (Argx);
986 if not Is_Queuing_Policy_Name (Chars (Argx)) then
988 ("& is not a valid queuing policy name", Argx);
990 end Check_Arg_Is_Queuing_Policy;
992 ------------------------------------
993 -- Check_Arg_Is_Static_Expression --
994 ------------------------------------
996 procedure Check_Arg_Is_Static_Expression
998 Typ : Entity_Id := Empty)
1000 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1003 if Present (Typ) then
1004 Analyze_And_Resolve (Argx, Typ);
1006 Analyze_And_Resolve (Argx);
1009 if Is_OK_Static_Expression (Argx) then
1012 elsif Etype (Argx) = Any_Type then
1015 -- An interesting special case, if we have a string literal and we
1016 -- are in Ada 83 mode, then we allow it even though it will not be
1017 -- flagged as static. This allows the use of Ada 95 pragmas like
1018 -- Import in Ada 83 mode. They will of course be flagged with
1019 -- warnings as usual, but will not cause errors.
1021 elsif Ada_Version = Ada_83
1022 and then Nkind (Argx) = N_String_Literal
1026 -- Static expression that raises Constraint_Error. This has already
1027 -- been flagged, so just exit from pragma processing.
1029 elsif Is_Static_Expression (Argx) then
1032 -- Finally, we have a real error
1035 Error_Msg_Name_1 := Pname;
1036 Flag_Non_Static_Expr
1037 ("argument for pragma% must be a static expression!", Argx);
1040 end Check_Arg_Is_Static_Expression;
1042 ------------------------------------------
1043 -- Check_Arg_Is_Task_Dispatching_Policy --
1044 ------------------------------------------
1046 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1047 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1050 Check_Arg_Is_Identifier (Argx);
1052 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1054 ("& is not a valid task dispatching policy name", Argx);
1056 end Check_Arg_Is_Task_Dispatching_Policy;
1058 ---------------------
1059 -- Check_Arg_Order --
1060 ---------------------
1062 procedure Check_Arg_Order (Names : Name_List) is
1065 Highest_So_Far : Natural := 0;
1066 -- Highest index in Names seen do far
1070 for J in 1 .. Arg_Count loop
1071 if Chars (Arg) /= No_Name then
1072 for K in Names'Range loop
1073 if Chars (Arg) = Names (K) then
1074 if K < Highest_So_Far then
1075 Error_Msg_Name_1 := Pname;
1077 ("parameters out of order for pragma%", Arg);
1078 Error_Msg_Name_1 := Names (K);
1079 Error_Msg_Name_2 := Names (Highest_So_Far);
1080 Error_Msg_N ("\% must appear before %", Arg);
1084 Highest_So_Far := K;
1092 end Check_Arg_Order;
1094 --------------------------------
1095 -- Check_At_Least_N_Arguments --
1096 --------------------------------
1098 procedure Check_At_Least_N_Arguments (N : Nat) is
1100 if Arg_Count < N then
1101 Error_Pragma ("too few arguments for pragma%");
1103 end Check_At_Least_N_Arguments;
1105 -------------------------------
1106 -- Check_At_Most_N_Arguments --
1107 -------------------------------
1109 procedure Check_At_Most_N_Arguments (N : Nat) is
1112 if Arg_Count > N then
1114 for J in 1 .. N loop
1116 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1119 end Check_At_Most_N_Arguments;
1121 ---------------------
1122 -- Check_Component --
1123 ---------------------
1125 procedure Check_Component
1128 In_Variant_Part : Boolean := False)
1130 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1131 Sindic : constant Node_Id :=
1132 Subtype_Indication (Component_Definition (Comp));
1133 Typ : constant Entity_Id := Etype (Comp_Id);
1135 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1136 -- Determine whether entity Id appears inside a generic body
1138 -------------------------
1139 -- Inside_Generic_Body --
1140 -------------------------
1142 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1143 S : Entity_Id := Id;
1147 and then S /= Standard_Standard
1149 if Ekind (S) = E_Generic_Package
1150 and then In_Package_Body (S)
1159 end Inside_Generic_Body;
1161 -- Start of processing for Check_Component
1164 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1165 -- object constraint, then the component type shall be an Unchecked_
1168 if Nkind (Sindic) = N_Subtype_Indication
1169 and then Has_Per_Object_Constraint (Comp_Id)
1170 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1173 ("component subtype subject to per-object constraint " &
1174 "must be an Unchecked_Union", Comp);
1176 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1177 -- the body of a generic unit, or within the body of any of its
1178 -- descendant library units, no part of the type of a component
1179 -- declared in a variant_part of the unchecked union type shall be of
1180 -- a formal private type or formal private extension declared within
1181 -- the formal part of the generic unit.
1183 elsif Ada_Version >= Ada_2012
1184 and then Inside_Generic_Body (UU_Typ)
1185 and then In_Variant_Part
1186 and then Is_Private_Type (Typ)
1187 and then Is_Generic_Type (Typ)
1190 ("component of Unchecked_Union cannot be of generic type", Comp);
1192 elsif Needs_Finalization (Typ) then
1194 ("component of Unchecked_Union cannot be controlled", Comp);
1196 elsif Has_Task (Typ) then
1198 ("component of Unchecked_Union cannot have tasks", Comp);
1200 end Check_Component;
1202 ----------------------------
1203 -- Check_Duplicate_Pragma --
1204 ----------------------------
1206 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1207 P : constant Node_Id := Get_Rep_Pragma (E, Pragma_Name (N));
1213 -- Make sure pragma is for this entity, and not for some parent
1214 -- entity in the case of a derived type.
1216 Arg := Get_Pragma_Arg (First (Pragma_Argument_Associations (P)));
1218 if Nkind (Arg) = N_Identifier
1219 and then Entity (Arg) = E
1221 Error_Msg_Name_1 := Pname;
1222 Error_Msg_Sloc := Sloc (P);
1223 Error_Msg_NE ("pragma% for & duplicates one#", N, E);
1227 end Check_Duplicate_Pragma;
1229 ----------------------------------
1230 -- Check_Duplicated_Export_Name --
1231 ----------------------------------
1233 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1234 String_Val : constant String_Id := Strval (Nam);
1237 -- We are only interested in the export case, and in the case of
1238 -- generics, it is the instance, not the template, that is the
1239 -- problem (the template will generate a warning in any case).
1241 if not Inside_A_Generic
1242 and then (Prag_Id = Pragma_Export
1244 Prag_Id = Pragma_Export_Procedure
1246 Prag_Id = Pragma_Export_Valued_Procedure
1248 Prag_Id = Pragma_Export_Function)
1250 for J in Externals.First .. Externals.Last loop
1251 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1252 Error_Msg_Sloc := Sloc (Externals.Table (J));
1253 Error_Msg_N ("external name duplicates name given#", Nam);
1258 Externals.Append (Nam);
1260 end Check_Duplicated_Export_Name;
1262 -------------------------
1263 -- Check_First_Subtype --
1264 -------------------------
1266 procedure Check_First_Subtype (Arg : Node_Id) is
1267 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1269 if not Is_First_Subtype (Entity (Argx)) then
1271 ("pragma% cannot apply to subtype", Argx);
1273 end Check_First_Subtype;
1275 ---------------------------
1276 -- Check_In_Main_Program --
1277 ---------------------------
1279 procedure Check_In_Main_Program is
1280 P : constant Node_Id := Parent (N);
1283 -- Must be at in subprogram body
1285 if Nkind (P) /= N_Subprogram_Body then
1286 Error_Pragma ("% pragma allowed only in subprogram");
1288 -- Otherwise warn if obviously not main program
1290 elsif Present (Parameter_Specifications (Specification (P)))
1291 or else not Is_Compilation_Unit (Defining_Entity (P))
1293 Error_Msg_Name_1 := Pname;
1295 ("?pragma% is only effective in main program", N);
1297 end Check_In_Main_Program;
1299 ---------------------------------------
1300 -- Check_Interrupt_Or_Attach_Handler --
1301 ---------------------------------------
1303 procedure Check_Interrupt_Or_Attach_Handler is
1304 Arg1_X : constant Node_Id := Expression (Arg1);
1305 Handler_Proc, Proc_Scope : Entity_Id;
1310 if Prag_Id = Pragma_Interrupt_Handler then
1311 Check_Restriction (No_Dynamic_Attachment, N);
1314 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1315 Proc_Scope := Scope (Handler_Proc);
1317 -- On AAMP only, a pragma Interrupt_Handler is supported for
1318 -- nonprotected parameterless procedures.
1320 if not AAMP_On_Target
1321 or else Prag_Id = Pragma_Attach_Handler
1323 if Ekind (Proc_Scope) /= E_Protected_Type then
1325 ("argument of pragma% must be protected procedure", Arg1);
1328 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1329 Error_Pragma ("pragma% must be in protected definition");
1333 if not Is_Library_Level_Entity (Proc_Scope)
1334 or else (AAMP_On_Target
1335 and then not Is_Library_Level_Entity (Handler_Proc))
1338 ("argument for pragma% must be library level entity", Arg1);
1341 -- AI05-0033: A pragma cannot appear within a generic body, because
1342 -- instance can be in a nested scope. The check that protected type
1343 -- is itself a library-level declaration is done elsewhere.
1345 -- Note: we omit this check in Codepeer mode to properly handle code
1346 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1348 if Inside_A_Generic then
1349 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1350 and then In_Package_Body (Scope (Current_Scope))
1351 and then not CodePeer_Mode
1353 Error_Pragma ("pragma% cannot be used inside a generic");
1356 end Check_Interrupt_Or_Attach_Handler;
1358 -------------------------------------------
1359 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1360 -------------------------------------------
1362 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1371 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1374 elsif Nkind_In (P, N_Package_Specification,
1379 -- Note: the following tests seem a little peculiar, because
1380 -- they test for bodies, but if we were in the statement part
1381 -- of the body, we would already have hit the handled statement
1382 -- sequence, so the only way we get here is by being in the
1383 -- declarative part of the body.
1385 elsif Nkind_In (P, N_Subprogram_Body,
1396 Error_Pragma ("pragma% is not in declarative part or package spec");
1397 end Check_Is_In_Decl_Part_Or_Package_Spec;
1399 -------------------------
1400 -- Check_No_Identifier --
1401 -------------------------
1403 procedure Check_No_Identifier (Arg : Node_Id) is
1405 if Chars (Arg) /= No_Name then
1406 Error_Pragma_Arg_Ident
1407 ("pragma% does not permit identifier& here", Arg);
1409 end Check_No_Identifier;
1411 --------------------------
1412 -- Check_No_Identifiers --
1413 --------------------------
1415 procedure Check_No_Identifiers is
1418 if Arg_Count > 0 then
1420 while Present (Arg_Node) loop
1421 Check_No_Identifier (Arg_Node);
1425 end Check_No_Identifiers;
1427 -------------------------------
1428 -- Check_Optional_Identifier --
1429 -------------------------------
1431 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1433 if Present (Arg) and then Chars (Arg) /= No_Name then
1434 if Chars (Arg) /= Id then
1435 Error_Msg_Name_1 := Pname;
1436 Error_Msg_Name_2 := Id;
1437 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1441 end Check_Optional_Identifier;
1443 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1445 Name_Buffer (1 .. Id'Length) := Id;
1446 Name_Len := Id'Length;
1447 Check_Optional_Identifier (Arg, Name_Find);
1448 end Check_Optional_Identifier;
1450 --------------------------------------
1451 -- Check_Precondition_Postcondition --
1452 --------------------------------------
1454 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1458 procedure Chain_PPC (PO : Node_Id);
1459 -- If PO is a subprogram declaration node (or a generic subprogram
1460 -- declaration node), then the precondition/postcondition applies
1461 -- to this subprogram and the processing for the pragma is completed.
1462 -- Otherwise the pragma is misplaced.
1468 procedure Chain_PPC (PO : Node_Id) is
1472 if not Nkind_In (PO, N_Subprogram_Declaration,
1473 N_Generic_Subprogram_Declaration)
1478 -- Here if we have subprogram or generic subprogram declaration
1480 S := Defining_Unit_Name (Specification (PO));
1482 -- Analyze the pragma unless it appears within a package spec,
1483 -- which is the case where we delay the analysis of the PPC until
1484 -- the end of the package declarations (for details, see
1485 -- Analyze_Package_Specification.Analyze_PPCs).
1487 if not Is_Package_Or_Generic_Package (Scope (S)) then
1488 Analyze_PPC_In_Decl_Part (N, S);
1491 -- Chain spec PPC pragma to list for subprogram
1493 Set_Next_Pragma (N, Spec_PPC_List (S));
1494 Set_Spec_PPC_List (S, N);
1496 -- Return indicating spec case
1502 -- Start of processing for Check_Precondition_Postcondition
1505 if not Is_List_Member (N) then
1509 -- Record if pragma is enabled
1511 if Check_Enabled (Pname) then
1512 Set_Pragma_Enabled (N);
1513 Set_SCO_Pragma_Enabled (Loc);
1516 -- If we are within an inlined body, the legality of the pragma
1517 -- has been checked already.
1519 if In_Inlined_Body then
1524 -- Search prior declarations
1527 while Present (Prev (P)) loop
1530 -- If the previous node is a generic subprogram, do not go to to
1531 -- the original node, which is the unanalyzed tree: we need to
1532 -- attach the pre/postconditions to the analyzed version at this
1533 -- point. They get propagated to the original tree when analyzing
1534 -- the corresponding body.
1536 if Nkind (P) not in N_Generic_Declaration then
1537 PO := Original_Node (P);
1542 -- Skip past prior pragma
1544 if Nkind (PO) = N_Pragma then
1547 -- Skip stuff not coming from source
1549 elsif not Comes_From_Source (PO) then
1552 -- Only remaining possibility is subprogram declaration
1560 -- If we fall through loop, pragma is at start of list, so see if it
1561 -- is at the start of declarations of a subprogram body.
1563 if Nkind (Parent (N)) = N_Subprogram_Body
1564 and then List_Containing (N) = Declarations (Parent (N))
1566 if Operating_Mode /= Generate_Code
1567 or else Inside_A_Generic
1570 -- Analyze expression in pragma, for correctness
1571 -- and for ASIS use.
1573 Preanalyze_Spec_Expression
1574 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1580 -- See if it is in the pragmas after a library level subprogram
1582 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1583 Chain_PPC (Unit (Parent (Parent (N))));
1587 -- If we fall through, pragma was misplaced
1590 end Check_Precondition_Postcondition;
1592 -----------------------------
1593 -- Check_Static_Constraint --
1594 -----------------------------
1596 -- Note: for convenience in writing this procedure, in addition to
1597 -- the officially (i.e. by spec) allowed argument which is always a
1598 -- constraint, it also allows ranges and discriminant associations.
1599 -- Above is not clear ???
1601 procedure Check_Static_Constraint (Constr : Node_Id) is
1603 procedure Require_Static (E : Node_Id);
1604 -- Require given expression to be static expression
1606 --------------------
1607 -- Require_Static --
1608 --------------------
1610 procedure Require_Static (E : Node_Id) is
1612 if not Is_OK_Static_Expression (E) then
1613 Flag_Non_Static_Expr
1614 ("non-static constraint not allowed in Unchecked_Union!", E);
1619 -- Start of processing for Check_Static_Constraint
1622 case Nkind (Constr) is
1623 when N_Discriminant_Association =>
1624 Require_Static (Expression (Constr));
1627 Require_Static (Low_Bound (Constr));
1628 Require_Static (High_Bound (Constr));
1630 when N_Attribute_Reference =>
1631 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1632 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1634 when N_Range_Constraint =>
1635 Check_Static_Constraint (Range_Expression (Constr));
1637 when N_Index_Or_Discriminant_Constraint =>
1641 IDC := First (Constraints (Constr));
1642 while Present (IDC) loop
1643 Check_Static_Constraint (IDC);
1651 end Check_Static_Constraint;
1653 --------------------------------------
1654 -- Check_Valid_Configuration_Pragma --
1655 --------------------------------------
1657 -- A configuration pragma must appear in the context clause of a
1658 -- compilation unit, and only other pragmas may precede it. Note that
1659 -- the test also allows use in a configuration pragma file.
1661 procedure Check_Valid_Configuration_Pragma is
1663 if not Is_Configuration_Pragma then
1664 Error_Pragma ("incorrect placement for configuration pragma%");
1666 end Check_Valid_Configuration_Pragma;
1668 -------------------------------------
1669 -- Check_Valid_Library_Unit_Pragma --
1670 -------------------------------------
1672 procedure Check_Valid_Library_Unit_Pragma is
1674 Parent_Node : Node_Id;
1675 Unit_Name : Entity_Id;
1676 Unit_Kind : Node_Kind;
1677 Unit_Node : Node_Id;
1678 Sindex : Source_File_Index;
1681 if not Is_List_Member (N) then
1685 Plist := List_Containing (N);
1686 Parent_Node := Parent (Plist);
1688 if Parent_Node = Empty then
1691 -- Case of pragma appearing after a compilation unit. In this case
1692 -- it must have an argument with the corresponding name and must
1693 -- be part of the following pragmas of its parent.
1695 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1696 if Plist /= Pragmas_After (Parent_Node) then
1699 elsif Arg_Count = 0 then
1701 ("argument required if outside compilation unit");
1704 Check_No_Identifiers;
1705 Check_Arg_Count (1);
1706 Unit_Node := Unit (Parent (Parent_Node));
1707 Unit_Kind := Nkind (Unit_Node);
1709 Analyze (Expression (Arg1));
1711 if Unit_Kind = N_Generic_Subprogram_Declaration
1712 or else Unit_Kind = N_Subprogram_Declaration
1714 Unit_Name := Defining_Entity (Unit_Node);
1716 elsif Unit_Kind in N_Generic_Instantiation then
1717 Unit_Name := Defining_Entity (Unit_Node);
1720 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1723 if Chars (Unit_Name) /=
1724 Chars (Entity (Expression (Arg1)))
1727 ("pragma% argument is not current unit name", Arg1);
1730 if Ekind (Unit_Name) = E_Package
1731 and then Present (Renamed_Entity (Unit_Name))
1733 Error_Pragma ("pragma% not allowed for renamed package");
1737 -- Pragma appears other than after a compilation unit
1740 -- Here we check for the generic instantiation case and also
1741 -- for the case of processing a generic formal package. We
1742 -- detect these cases by noting that the Sloc on the node
1743 -- does not belong to the current compilation unit.
1745 Sindex := Source_Index (Current_Sem_Unit);
1747 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1748 Rewrite (N, Make_Null_Statement (Loc));
1751 -- If before first declaration, the pragma applies to the
1752 -- enclosing unit, and the name if present must be this name.
1754 elsif Is_Before_First_Decl (N, Plist) then
1755 Unit_Node := Unit_Declaration_Node (Current_Scope);
1756 Unit_Kind := Nkind (Unit_Node);
1758 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1761 elsif Unit_Kind = N_Subprogram_Body
1762 and then not Acts_As_Spec (Unit_Node)
1766 elsif Nkind (Parent_Node) = N_Package_Body then
1769 elsif Nkind (Parent_Node) = N_Package_Specification
1770 and then Plist = Private_Declarations (Parent_Node)
1774 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1775 or else Nkind (Parent_Node) =
1776 N_Generic_Subprogram_Declaration)
1777 and then Plist = Generic_Formal_Declarations (Parent_Node)
1781 elsif Arg_Count > 0 then
1782 Analyze (Expression (Arg1));
1784 if Entity (Expression (Arg1)) /= Current_Scope then
1786 ("name in pragma% must be enclosing unit", Arg1);
1789 -- It is legal to have no argument in this context
1795 -- Error if not before first declaration. This is because a
1796 -- library unit pragma argument must be the name of a library
1797 -- unit (RM 10.1.5(7)), but the only names permitted in this
1798 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1799 -- generic subprogram declarations or generic instantiations.
1803 ("pragma% misplaced, must be before first declaration");
1807 end Check_Valid_Library_Unit_Pragma;
1813 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
1814 Clist : constant Node_Id := Component_List (Variant);
1818 if not Is_Non_Empty_List (Component_Items (Clist)) then
1820 ("Unchecked_Union may not have empty component list",
1825 Comp := First (Component_Items (Clist));
1826 while Present (Comp) loop
1827 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
1836 procedure Error_Pragma (Msg : String) is
1838 Error_Msg_Name_1 := Pname;
1839 Error_Msg_N (Msg, N);
1843 ----------------------
1844 -- Error_Pragma_Arg --
1845 ----------------------
1847 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1849 Error_Msg_Name_1 := Pname;
1850 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1852 end Error_Pragma_Arg;
1854 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1856 Error_Msg_Name_1 := Pname;
1857 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1858 Error_Pragma_Arg (Msg2, Arg);
1859 end Error_Pragma_Arg;
1861 ----------------------------
1862 -- Error_Pragma_Arg_Ident --
1863 ----------------------------
1865 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1867 Error_Msg_Name_1 := Pname;
1868 Error_Msg_N (Msg, Arg);
1870 end Error_Pragma_Arg_Ident;
1872 ----------------------
1873 -- Error_Pragma_Ref --
1874 ----------------------
1876 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
1878 Error_Msg_Name_1 := Pname;
1879 Error_Msg_Sloc := Sloc (Ref);
1880 Error_Msg_NE (Msg, N, Ref);
1882 end Error_Pragma_Ref;
1884 ------------------------
1885 -- Find_Lib_Unit_Name --
1886 ------------------------
1888 function Find_Lib_Unit_Name return Entity_Id is
1890 -- Return inner compilation unit entity, for case of nested
1891 -- categorization pragmas. This happens in generic unit.
1893 if Nkind (Parent (N)) = N_Package_Specification
1894 and then Defining_Entity (Parent (N)) /= Current_Scope
1896 return Defining_Entity (Parent (N));
1898 return Current_Scope;
1900 end Find_Lib_Unit_Name;
1902 ----------------------------
1903 -- Find_Program_Unit_Name --
1904 ----------------------------
1906 procedure Find_Program_Unit_Name (Id : Node_Id) is
1907 Unit_Name : Entity_Id;
1908 Unit_Kind : Node_Kind;
1909 P : constant Node_Id := Parent (N);
1912 if Nkind (P) = N_Compilation_Unit then
1913 Unit_Kind := Nkind (Unit (P));
1915 if Unit_Kind = N_Subprogram_Declaration
1916 or else Unit_Kind = N_Package_Declaration
1917 or else Unit_Kind in N_Generic_Declaration
1919 Unit_Name := Defining_Entity (Unit (P));
1921 if Chars (Id) = Chars (Unit_Name) then
1922 Set_Entity (Id, Unit_Name);
1923 Set_Etype (Id, Etype (Unit_Name));
1925 Set_Etype (Id, Any_Type);
1927 ("cannot find program unit referenced by pragma%");
1931 Set_Etype (Id, Any_Type);
1932 Error_Pragma ("pragma% inapplicable to this unit");
1938 end Find_Program_Unit_Name;
1940 -----------------------------------------
1941 -- Find_Unique_Parameterless_Procedure --
1942 -----------------------------------------
1944 function Find_Unique_Parameterless_Procedure
1946 Arg : Node_Id) return Entity_Id
1948 Proc : Entity_Id := Empty;
1951 -- The body of this procedure needs some comments ???
1953 if not Is_Entity_Name (Name) then
1955 ("argument of pragma% must be entity name", Arg);
1957 elsif not Is_Overloaded (Name) then
1958 Proc := Entity (Name);
1960 if Ekind (Proc) /= E_Procedure
1961 or else Present (First_Formal (Proc))
1964 ("argument of pragma% must be parameterless procedure", Arg);
1969 Found : Boolean := False;
1971 Index : Interp_Index;
1974 Get_First_Interp (Name, Index, It);
1975 while Present (It.Nam) loop
1978 if Ekind (Proc) = E_Procedure
1979 and then No (First_Formal (Proc))
1983 Set_Entity (Name, Proc);
1984 Set_Is_Overloaded (Name, False);
1987 ("ambiguous handler name for pragma% ", Arg);
1991 Get_Next_Interp (Index, It);
1996 ("argument of pragma% must be parameterless procedure",
1999 Proc := Entity (Name);
2005 end Find_Unique_Parameterless_Procedure;
2007 -------------------------
2008 -- Gather_Associations --
2009 -------------------------
2011 procedure Gather_Associations
2013 Args : out Args_List)
2018 -- Initialize all parameters to Empty
2020 for J in Args'Range loop
2024 -- That's all we have to do if there are no argument associations
2026 if No (Pragma_Argument_Associations (N)) then
2030 -- Otherwise first deal with any positional parameters present
2032 Arg := First (Pragma_Argument_Associations (N));
2033 for Index in Args'Range loop
2034 exit when No (Arg) or else Chars (Arg) /= No_Name;
2035 Args (Index) := Expression (Arg);
2039 -- Positional parameters all processed, if any left, then we
2040 -- have too many positional parameters.
2042 if Present (Arg) and then Chars (Arg) = No_Name then
2044 ("too many positional associations for pragma%", Arg);
2047 -- Process named parameters if any are present
2049 while Present (Arg) loop
2050 if Chars (Arg) = No_Name then
2052 ("positional association cannot follow named association",
2056 for Index in Names'Range loop
2057 if Names (Index) = Chars (Arg) then
2058 if Present (Args (Index)) then
2060 ("duplicate argument association for pragma%", Arg);
2062 Args (Index) := Expression (Arg);
2067 if Index = Names'Last then
2068 Error_Msg_Name_1 := Pname;
2069 Error_Msg_N ("pragma% does not allow & argument", Arg);
2071 -- Check for possible misspelling
2073 for Index1 in Names'Range loop
2074 if Is_Bad_Spelling_Of
2075 (Chars (Arg), Names (Index1))
2077 Error_Msg_Name_1 := Names (Index1);
2078 Error_Msg_N -- CODEFIX
2079 ("\possible misspelling of%", Arg);
2091 end Gather_Associations;
2097 procedure GNAT_Pragma is
2099 Check_Restriction (No_Implementation_Pragmas, N);
2102 --------------------------
2103 -- Is_Before_First_Decl --
2104 --------------------------
2106 function Is_Before_First_Decl
2107 (Pragma_Node : Node_Id;
2108 Decls : List_Id) return Boolean
2110 Item : Node_Id := First (Decls);
2113 -- Only other pragmas can come before this pragma
2116 if No (Item) or else Nkind (Item) /= N_Pragma then
2119 elsif Item = Pragma_Node then
2125 end Is_Before_First_Decl;
2127 -----------------------------
2128 -- Is_Configuration_Pragma --
2129 -----------------------------
2131 -- A configuration pragma must appear in the context clause of a
2132 -- compilation unit, and only other pragmas may precede it. Note that
2133 -- the test below also permits use in a configuration pragma file.
2135 function Is_Configuration_Pragma return Boolean is
2136 Lis : constant List_Id := List_Containing (N);
2137 Par : constant Node_Id := Parent (N);
2141 -- If no parent, then we are in the configuration pragma file,
2142 -- so the placement is definitely appropriate.
2147 -- Otherwise we must be in the context clause of a compilation unit
2148 -- and the only thing allowed before us in the context list is more
2149 -- configuration pragmas.
2151 elsif Nkind (Par) = N_Compilation_Unit
2152 and then Context_Items (Par) = Lis
2159 elsif Nkind (Prg) /= N_Pragma then
2169 end Is_Configuration_Pragma;
2171 --------------------------
2172 -- Is_In_Context_Clause --
2173 --------------------------
2175 function Is_In_Context_Clause return Boolean is
2177 Parent_Node : Node_Id;
2180 if not Is_List_Member (N) then
2184 Plist := List_Containing (N);
2185 Parent_Node := Parent (Plist);
2187 if Parent_Node = Empty
2188 or else Nkind (Parent_Node) /= N_Compilation_Unit
2189 or else Context_Items (Parent_Node) /= Plist
2196 end Is_In_Context_Clause;
2198 ---------------------------------
2199 -- Is_Static_String_Expression --
2200 ---------------------------------
2202 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2203 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2206 Analyze_And_Resolve (Argx);
2207 return Is_OK_Static_Expression (Argx)
2208 and then Nkind (Argx) = N_String_Literal;
2209 end Is_Static_String_Expression;
2211 ----------------------
2212 -- Pragma_Misplaced --
2213 ----------------------
2215 procedure Pragma_Misplaced is
2217 Error_Pragma ("incorrect placement of pragma%");
2218 end Pragma_Misplaced;
2220 ------------------------------------
2221 -- Process Atomic_Shared_Volatile --
2222 ------------------------------------
2224 procedure Process_Atomic_Shared_Volatile is
2231 procedure Set_Atomic (E : Entity_Id);
2232 -- Set given type as atomic, and if no explicit alignment was given,
2233 -- set alignment to unknown, since back end knows what the alignment
2234 -- requirements are for atomic arrays. Note: this step is necessary
2235 -- for derived types.
2241 procedure Set_Atomic (E : Entity_Id) is
2245 if not Has_Alignment_Clause (E) then
2246 Set_Alignment (E, Uint_0);
2250 -- Start of processing for Process_Atomic_Shared_Volatile
2253 Check_Ada_83_Warning;
2254 Check_No_Identifiers;
2255 Check_Arg_Count (1);
2256 Check_Arg_Is_Local_Name (Arg1);
2257 E_Id := Expression (Arg1);
2259 if Etype (E_Id) = Any_Type then
2264 D := Declaration_Node (E);
2267 -- Check duplicate before we chain ourselves!
2269 Check_Duplicate_Pragma (E);
2271 -- Now check appropriateness of the entity
2274 if Rep_Item_Too_Early (E, N)
2276 Rep_Item_Too_Late (E, N)
2280 Check_First_Subtype (Arg1);
2283 if Prag_Id /= Pragma_Volatile then
2285 Set_Atomic (Underlying_Type (E));
2286 Set_Atomic (Base_Type (E));
2289 -- Attribute belongs on the base type. If the view of the type is
2290 -- currently private, it also belongs on the underlying type.
2292 Set_Is_Volatile (Base_Type (E));
2293 Set_Is_Volatile (Underlying_Type (E));
2295 Set_Treat_As_Volatile (E);
2296 Set_Treat_As_Volatile (Underlying_Type (E));
2298 elsif K = N_Object_Declaration
2299 or else (K = N_Component_Declaration
2300 and then Original_Record_Component (E) = E)
2302 if Rep_Item_Too_Late (E, N) then
2306 if Prag_Id /= Pragma_Volatile then
2309 -- If the object declaration has an explicit initialization, a
2310 -- temporary may have to be created to hold the expression, to
2311 -- ensure that access to the object remain atomic.
2313 if Nkind (Parent (E)) = N_Object_Declaration
2314 and then Present (Expression (Parent (E)))
2316 Set_Has_Delayed_Freeze (E);
2319 -- An interesting improvement here. If an object of type X is
2320 -- declared atomic, and the type X is not atomic, that's a
2321 -- pity, since it may not have appropriate alignment etc. We
2322 -- can rescue this in the special case where the object and
2323 -- type are in the same unit by just setting the type as
2324 -- atomic, so that the back end will process it as atomic.
2326 Utyp := Underlying_Type (Etype (E));
2329 and then Sloc (E) > No_Location
2330 and then Sloc (Utyp) > No_Location
2332 Get_Source_File_Index (Sloc (E)) =
2333 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2335 Set_Is_Atomic (Underlying_Type (Etype (E)));
2339 Set_Is_Volatile (E);
2340 Set_Treat_As_Volatile (E);
2344 ("inappropriate entity for pragma%", Arg1);
2346 end Process_Atomic_Shared_Volatile;
2348 -------------------------------------------
2349 -- Process_Compile_Time_Warning_Or_Error --
2350 -------------------------------------------
2352 procedure Process_Compile_Time_Warning_Or_Error is
2353 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2356 Check_Arg_Count (2);
2357 Check_No_Identifiers;
2358 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2359 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2361 if Compile_Time_Known_Value (Arg1x) then
2362 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2364 Str : constant String_Id :=
2365 Strval (Get_Pragma_Arg (Arg2));
2366 Len : constant Int := String_Length (Str);
2371 Cent : constant Entity_Id :=
2372 Cunit_Entity (Current_Sem_Unit);
2374 Force : constant Boolean :=
2375 Prag_Id = Pragma_Compile_Time_Warning
2377 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2378 and then (Ekind (Cent) /= E_Package
2379 or else not In_Private_Part (Cent));
2380 -- Set True if this is the warning case, and we are in the
2381 -- visible part of a package spec, or in a subprogram spec,
2382 -- in which case we want to force the client to see the
2383 -- warning, even though it is not in the main unit.
2386 -- Loop through segments of message separated by line feeds.
2387 -- We output these segments as separate messages with
2388 -- continuation marks for all but the first.
2393 Error_Msg_Strlen := 0;
2395 -- Loop to copy characters from argument to error message
2399 exit when Ptr > Len;
2400 CC := Get_String_Char (Str, Ptr);
2403 -- Ignore wide chars ??? else store character
2405 if In_Character_Range (CC) then
2406 C := Get_Character (CC);
2407 exit when C = ASCII.LF;
2408 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2409 Error_Msg_String (Error_Msg_Strlen) := C;
2413 -- Here with one line ready to go
2415 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2417 -- If this is a warning in a spec, then we want clients
2418 -- to see the warning, so mark the message with the
2419 -- special sequence !! to force the warning. In the case
2420 -- of a package spec, we do not force this if we are in
2421 -- the private part of the spec.
2424 if Cont = False then
2425 Error_Msg_N ("<~!!", Arg1);
2428 Error_Msg_N ("\<~!!", Arg1);
2431 -- Error, rather than warning, or in a body, so we do not
2432 -- need to force visibility for client (error will be
2433 -- output in any case, and this is the situation in which
2434 -- we do not want a client to get a warning, since the
2435 -- warning is in the body or the spec private part).
2438 if Cont = False then
2439 Error_Msg_N ("<~", Arg1);
2442 Error_Msg_N ("\<~", Arg1);
2446 exit when Ptr > Len;
2451 end Process_Compile_Time_Warning_Or_Error;
2453 ------------------------
2454 -- Process_Convention --
2455 ------------------------
2457 procedure Process_Convention
2458 (C : out Convention_Id;
2459 Ent : out Entity_Id)
2465 Comp_Unit : Unit_Number_Type;
2467 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2468 -- Called if we have more than one Export/Import/Convention pragma.
2469 -- This is generally illegal, but we have a special case of allowing
2470 -- Import and Interface to coexist if they specify the convention in
2471 -- a consistent manner. We are allowed to do this, since Interface is
2472 -- an implementation defined pragma, and we choose to do it since we
2473 -- know Rational allows this combination. S is the entity id of the
2474 -- subprogram in question. This procedure also sets the special flag
2475 -- Import_Interface_Present in both pragmas in the case where we do
2476 -- have matching Import and Interface pragmas.
2478 procedure Set_Convention_From_Pragma (E : Entity_Id);
2479 -- Set convention in entity E, and also flag that the entity has a
2480 -- convention pragma. If entity is for a private or incomplete type,
2481 -- also set convention and flag on underlying type. This procedure
2482 -- also deals with the special case of C_Pass_By_Copy convention.
2484 -------------------------------
2485 -- Diagnose_Multiple_Pragmas --
2486 -------------------------------
2488 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2489 Pdec : constant Node_Id := Declaration_Node (S);
2493 function Same_Convention (Decl : Node_Id) return Boolean;
2494 -- Decl is a pragma node. This function returns True if this
2495 -- pragma has a first argument that is an identifier with a
2496 -- Chars field corresponding to the Convention_Id C.
2498 function Same_Name (Decl : Node_Id) return Boolean;
2499 -- Decl is a pragma node. This function returns True if this
2500 -- pragma has a second argument that is an identifier with a
2501 -- Chars field that matches the Chars of the current subprogram.
2503 ---------------------
2504 -- Same_Convention --
2505 ---------------------
2507 function Same_Convention (Decl : Node_Id) return Boolean is
2508 Arg1 : constant Node_Id :=
2509 First (Pragma_Argument_Associations (Decl));
2512 if Present (Arg1) then
2514 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2516 if Nkind (Arg) = N_Identifier
2517 and then Is_Convention_Name (Chars (Arg))
2518 and then Get_Convention_Id (Chars (Arg)) = C
2526 end Same_Convention;
2532 function Same_Name (Decl : Node_Id) return Boolean is
2533 Arg1 : constant Node_Id :=
2534 First (Pragma_Argument_Associations (Decl));
2542 Arg2 := Next (Arg1);
2549 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2551 if Nkind (Arg) = N_Identifier
2552 and then Chars (Arg) = Chars (S)
2561 -- Start of processing for Diagnose_Multiple_Pragmas
2566 -- Definitely give message if we have Convention/Export here
2568 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2571 -- If we have an Import or Export, scan back from pragma to
2572 -- find any previous pragma applying to the same procedure.
2573 -- The scan will be terminated by the start of the list, or
2574 -- hitting the subprogram declaration. This won't allow one
2575 -- pragma to appear in the public part and one in the private
2576 -- part, but that seems very unlikely in practice.
2580 while Present (Decl) and then Decl /= Pdec loop
2582 -- Look for pragma with same name as us
2584 if Nkind (Decl) = N_Pragma
2585 and then Same_Name (Decl)
2587 -- Give error if same as our pragma or Export/Convention
2589 if Pragma_Name (Decl) = Name_Export
2591 Pragma_Name (Decl) = Name_Convention
2593 Pragma_Name (Decl) = Pragma_Name (N)
2597 -- Case of Import/Interface or the other way round
2599 elsif Pragma_Name (Decl) = Name_Interface
2601 Pragma_Name (Decl) = Name_Import
2603 -- Here we know that we have Import and Interface. It
2604 -- doesn't matter which way round they are. See if
2605 -- they specify the same convention. If so, all OK,
2606 -- and set special flags to stop other messages
2608 if Same_Convention (Decl) then
2609 Set_Import_Interface_Present (N);
2610 Set_Import_Interface_Present (Decl);
2613 -- If different conventions, special message
2616 Error_Msg_Sloc := Sloc (Decl);
2618 ("convention differs from that given#", Arg1);
2628 -- Give message if needed if we fall through those tests
2632 ("at most one Convention/Export/Import pragma is allowed",
2635 end Diagnose_Multiple_Pragmas;
2637 --------------------------------
2638 -- Set_Convention_From_Pragma --
2639 --------------------------------
2641 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2643 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2644 -- for an overridden dispatching operation. Technically this is
2645 -- an amendment and should only be done in Ada 2005 mode. However,
2646 -- this is clearly a mistake, since the problem that is addressed
2647 -- by this AI is that there is a clear gap in the RM!
2649 if Is_Dispatching_Operation (E)
2650 and then Present (Overridden_Operation (E))
2651 and then C /= Convention (Overridden_Operation (E))
2654 ("cannot change convention for " &
2655 "overridden dispatching operation",
2659 -- Set the convention
2661 Set_Convention (E, C);
2662 Set_Has_Convention_Pragma (E);
2664 if Is_Incomplete_Or_Private_Type (E) then
2665 Set_Convention (Underlying_Type (E), C);
2666 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2669 -- A class-wide type should inherit the convention of the specific
2670 -- root type (although this isn't specified clearly by the RM).
2672 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2673 Set_Convention (Class_Wide_Type (E), C);
2676 -- If the entity is a record type, then check for special case of
2677 -- C_Pass_By_Copy, which is treated the same as C except that the
2678 -- special record flag is set. This convention is only permitted
2679 -- on record types (see AI95-00131).
2681 if Cname = Name_C_Pass_By_Copy then
2682 if Is_Record_Type (E) then
2683 Set_C_Pass_By_Copy (Base_Type (E));
2684 elsif Is_Incomplete_Or_Private_Type (E)
2685 and then Is_Record_Type (Underlying_Type (E))
2687 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2690 ("C_Pass_By_Copy convention allowed only for record type",
2695 -- If the entity is a derived boolean type, check for the special
2696 -- case of convention C, C++, or Fortran, where we consider any
2697 -- nonzero value to represent true.
2699 if Is_Discrete_Type (E)
2700 and then Root_Type (Etype (E)) = Standard_Boolean
2706 C = Convention_Fortran)
2708 Set_Nonzero_Is_True (Base_Type (E));
2710 end Set_Convention_From_Pragma;
2712 -- Start of processing for Process_Convention
2715 Check_At_Least_N_Arguments (2);
2716 Check_Optional_Identifier (Arg1, Name_Convention);
2717 Check_Arg_Is_Identifier (Arg1);
2718 Cname := Chars (Expression (Arg1));
2720 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2721 -- tested again below to set the critical flag).
2722 if Cname = Name_C_Pass_By_Copy then
2725 -- Otherwise we must have something in the standard convention list
2727 elsif Is_Convention_Name (Cname) then
2728 C := Get_Convention_Id (Chars (Expression (Arg1)));
2730 -- In DEC VMS, it seems that there is an undocumented feature that
2731 -- any unrecognized convention is treated as the default, which for
2732 -- us is convention C. It does not seem so terrible to do this
2733 -- unconditionally, silently in the VMS case, and with a warning
2734 -- in the non-VMS case.
2737 if Warn_On_Export_Import and not OpenVMS_On_Target then
2739 ("?unrecognized convention name, C assumed",
2746 Check_Optional_Identifier (Arg2, Name_Entity);
2747 Check_Arg_Is_Local_Name (Arg2);
2749 Id := Expression (Arg2);
2752 if not Is_Entity_Name (Id) then
2753 Error_Pragma_Arg ("entity name required", Arg2);
2758 -- Set entity to return
2762 -- Go to renamed subprogram if present, since convention applies to
2763 -- the actual renamed entity, not to the renaming entity. If the
2764 -- subprogram is inherited, go to parent subprogram.
2766 if Is_Subprogram (E)
2767 and then Present (Alias (E))
2769 if Nkind (Parent (Declaration_Node (E))) =
2770 N_Subprogram_Renaming_Declaration
2772 if Scope (E) /= Scope (Alias (E)) then
2774 ("cannot apply pragma% to non-local entity&#", E);
2779 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
2780 N_Private_Extension_Declaration)
2781 and then Scope (E) = Scope (Alias (E))
2785 -- Return the parent subprogram the entity was inherited from
2791 -- Check that we are not applying this to a specless body
2793 if Is_Subprogram (E)
2794 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2797 ("pragma% requires separate spec and must come before body");
2800 -- Check that we are not applying this to a named constant
2802 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
2803 Error_Msg_Name_1 := Pname;
2805 ("cannot apply pragma% to named constant!",
2806 Get_Pragma_Arg (Arg2));
2808 ("\supply appropriate type for&!", Arg2);
2811 if Ekind (E) = E_Enumeration_Literal then
2812 Error_Pragma ("enumeration literal not allowed for pragma%");
2815 -- Check for rep item appearing too early or too late
2817 if Etype (E) = Any_Type
2818 or else Rep_Item_Too_Early (E, N)
2822 E := Underlying_Type (E);
2825 if Rep_Item_Too_Late (E, N) then
2829 if Has_Convention_Pragma (E) then
2830 Diagnose_Multiple_Pragmas (E);
2832 elsif Convention (E) = Convention_Protected
2833 or else Ekind (Scope (E)) = E_Protected_Type
2836 ("a protected operation cannot be given a different convention",
2840 -- For Intrinsic, a subprogram is required
2842 if C = Convention_Intrinsic
2843 and then not Is_Subprogram (E)
2844 and then not Is_Generic_Subprogram (E)
2847 ("second argument of pragma% must be a subprogram", Arg2);
2850 -- For Stdcall, a subprogram, variable or subprogram type is required
2852 if C = Convention_Stdcall
2853 and then not Is_Subprogram (E)
2854 and then not Is_Generic_Subprogram (E)
2855 and then Ekind (E) /= E_Variable
2858 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2861 ("second argument of pragma% must be subprogram (type)",
2865 if not Is_Subprogram (E)
2866 and then not Is_Generic_Subprogram (E)
2868 Set_Convention_From_Pragma (E);
2871 Check_First_Subtype (Arg2);
2872 Set_Convention_From_Pragma (Base_Type (E));
2874 -- For subprograms, we must set the convention on the
2875 -- internally generated directly designated type as well.
2877 if Ekind (E) = E_Access_Subprogram_Type then
2878 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2882 -- For the subprogram case, set proper convention for all homonyms
2883 -- in same scope and the same declarative part, i.e. the same
2884 -- compilation unit.
2887 Comp_Unit := Get_Source_Unit (E);
2888 Set_Convention_From_Pragma (E);
2890 -- Treat a pragma Import as an implicit body, for GPS use
2892 if Prag_Id = Pragma_Import then
2893 Generate_Reference (E, Id, 'b');
2896 -- Loop through the homonyms of the pragma argument's entity
2901 exit when No (E1) or else Scope (E1) /= Current_Scope;
2903 -- Do not set the pragma on inherited operations or on formal
2906 if Comes_From_Source (E1)
2907 and then Comp_Unit = Get_Source_Unit (E1)
2908 and then not Is_Formal_Subprogram (E1)
2909 and then Nkind (Original_Node (Parent (E1))) /=
2910 N_Full_Type_Declaration
2912 if Present (Alias (E1))
2913 and then Scope (E1) /= Scope (Alias (E1))
2916 ("cannot apply pragma% to non-local entity& declared#",
2920 Set_Convention_From_Pragma (E1);
2922 if Prag_Id = Pragma_Import then
2923 Generate_Reference (E1, Id, 'b');
2928 end Process_Convention;
2930 -----------------------------------------------------
2931 -- Process_Extended_Import_Export_Exception_Pragma --
2932 -----------------------------------------------------
2934 procedure Process_Extended_Import_Export_Exception_Pragma
2935 (Arg_Internal : Node_Id;
2936 Arg_External : Node_Id;
2944 if not OpenVMS_On_Target then
2946 ("?pragma% ignored (applies only to Open'V'M'S)");
2949 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2950 Def_Id := Entity (Arg_Internal);
2952 if Ekind (Def_Id) /= E_Exception then
2954 ("pragma% must refer to declared exception", Arg_Internal);
2957 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2959 if Present (Arg_Form) then
2960 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2963 if Present (Arg_Form)
2964 and then Chars (Arg_Form) = Name_Ada
2968 Set_Is_VMS_Exception (Def_Id);
2969 Set_Exception_Code (Def_Id, No_Uint);
2972 if Present (Arg_Code) then
2973 if not Is_VMS_Exception (Def_Id) then
2975 ("Code option for pragma% not allowed for Ada case",
2979 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2980 Code_Val := Expr_Value (Arg_Code);
2982 if not UI_Is_In_Int_Range (Code_Val) then
2984 ("Code option for pragma% must be in 32-bit range",
2988 Set_Exception_Code (Def_Id, Code_Val);
2991 end Process_Extended_Import_Export_Exception_Pragma;
2993 -------------------------------------------------
2994 -- Process_Extended_Import_Export_Internal_Arg --
2995 -------------------------------------------------
2997 procedure Process_Extended_Import_Export_Internal_Arg
2998 (Arg_Internal : Node_Id := Empty)
3001 if No (Arg_Internal) then
3002 Error_Pragma ("Internal parameter required for pragma%");
3005 if Nkind (Arg_Internal) = N_Identifier then
3008 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3009 and then (Prag_Id = Pragma_Import_Function
3011 Prag_Id = Pragma_Export_Function)
3017 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3020 Check_Arg_Is_Local_Name (Arg_Internal);
3021 end Process_Extended_Import_Export_Internal_Arg;
3023 --------------------------------------------------
3024 -- Process_Extended_Import_Export_Object_Pragma --
3025 --------------------------------------------------
3027 procedure Process_Extended_Import_Export_Object_Pragma
3028 (Arg_Internal : Node_Id;
3029 Arg_External : Node_Id;
3035 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3036 Def_Id := Entity (Arg_Internal);
3038 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3040 ("pragma% must designate an object", Arg_Internal);
3043 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3045 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3048 ("previous Common/Psect_Object applies, pragma % not permitted",
3052 if Rep_Item_Too_Late (Def_Id, N) then
3056 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3058 if Present (Arg_Size) then
3059 Check_Arg_Is_External_Name (Arg_Size);
3062 -- Export_Object case
3064 if Prag_Id = Pragma_Export_Object then
3065 if not Is_Library_Level_Entity (Def_Id) then
3067 ("argument for pragma% must be library level entity",
3071 if Ekind (Current_Scope) = E_Generic_Package then
3072 Error_Pragma ("pragma& cannot appear in a generic unit");
3075 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3077 ("exported object must have compile time known size",
3081 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3082 Error_Msg_N ("?duplicate Export_Object pragma", N);
3084 Set_Exported (Def_Id, Arg_Internal);
3087 -- Import_Object case
3090 if Is_Concurrent_Type (Etype (Def_Id)) then
3092 ("cannot use pragma% for task/protected object",
3096 if Ekind (Def_Id) = E_Constant then
3098 ("cannot import a constant", Arg_Internal);
3101 if Warn_On_Export_Import
3102 and then Has_Discriminants (Etype (Def_Id))
3105 ("imported value must be initialized?", Arg_Internal);
3108 if Warn_On_Export_Import
3109 and then Is_Access_Type (Etype (Def_Id))
3112 ("cannot import object of an access type?", Arg_Internal);
3115 if Warn_On_Export_Import
3116 and then Is_Imported (Def_Id)
3119 ("?duplicate Import_Object pragma", N);
3121 -- Check for explicit initialization present. Note that an
3122 -- initialization generated by the code generator, e.g. for an
3123 -- access type, does not count here.
3125 elsif Present (Expression (Parent (Def_Id)))
3128 (Original_Node (Expression (Parent (Def_Id))))
3130 Error_Msg_Sloc := Sloc (Def_Id);
3132 ("imported entities cannot be initialized (RM B.1(24))",
3133 "\no initialization allowed for & declared#", Arg1);
3135 Set_Imported (Def_Id);
3136 Note_Possible_Modification (Arg_Internal, Sure => False);
3139 end Process_Extended_Import_Export_Object_Pragma;
3141 ------------------------------------------------------
3142 -- Process_Extended_Import_Export_Subprogram_Pragma --
3143 ------------------------------------------------------
3145 procedure Process_Extended_Import_Export_Subprogram_Pragma
3146 (Arg_Internal : Node_Id;
3147 Arg_External : Node_Id;
3148 Arg_Parameter_Types : Node_Id;
3149 Arg_Result_Type : Node_Id := Empty;
3150 Arg_Mechanism : Node_Id;
3151 Arg_Result_Mechanism : Node_Id := Empty;
3152 Arg_First_Optional_Parameter : Node_Id := Empty)
3158 Ambiguous : Boolean;
3162 function Same_Base_Type
3164 Formal : Entity_Id) return Boolean;
3165 -- Determines if Ptype references the type of Formal. Note that only
3166 -- the base types need to match according to the spec. Ptype here is
3167 -- the argument from the pragma, which is either a type name, or an
3168 -- access attribute.
3170 --------------------
3171 -- Same_Base_Type --
3172 --------------------
3174 function Same_Base_Type
3176 Formal : Entity_Id) return Boolean
3178 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3182 -- Case where pragma argument is typ'Access
3184 if Nkind (Ptype) = N_Attribute_Reference
3185 and then Attribute_Name (Ptype) = Name_Access
3187 Pref := Prefix (Ptype);
3190 if not Is_Entity_Name (Pref)
3191 or else Entity (Pref) = Any_Type
3196 -- We have a match if the corresponding argument is of an
3197 -- anonymous access type, and its designated type matches the
3198 -- type of the prefix of the access attribute
3200 return Ekind (Ftyp) = E_Anonymous_Access_Type
3201 and then Base_Type (Entity (Pref)) =
3202 Base_Type (Etype (Designated_Type (Ftyp)));
3204 -- Case where pragma argument is a type name
3209 if not Is_Entity_Name (Ptype)
3210 or else Entity (Ptype) = Any_Type
3215 -- We have a match if the corresponding argument is of the type
3216 -- given in the pragma (comparing base types)
3218 return Base_Type (Entity (Ptype)) = Ftyp;
3222 -- Start of processing for
3223 -- Process_Extended_Import_Export_Subprogram_Pragma
3226 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3230 -- Loop through homonyms (overloadings) of the entity
3232 Hom_Id := Entity (Arg_Internal);
3233 while Present (Hom_Id) loop
3234 Def_Id := Get_Base_Subprogram (Hom_Id);
3236 -- We need a subprogram in the current scope
3238 if not Is_Subprogram (Def_Id)
3239 or else Scope (Def_Id) /= Current_Scope
3246 -- Pragma cannot apply to subprogram body
3248 if Is_Subprogram (Def_Id)
3249 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3253 ("pragma% requires separate spec"
3254 & " and must come before body");
3257 -- Test result type if given, note that the result type
3258 -- parameter can only be present for the function cases.
3260 if Present (Arg_Result_Type)
3261 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3265 elsif Etype (Def_Id) /= Standard_Void_Type
3267 (Pname = Name_Export_Procedure
3269 Pname = Name_Import_Procedure)
3273 -- Test parameter types if given. Note that this parameter
3274 -- has not been analyzed (and must not be, since it is
3275 -- semantic nonsense), so we get it as the parser left it.
3277 elsif Present (Arg_Parameter_Types) then
3278 Check_Matching_Types : declare
3283 Formal := First_Formal (Def_Id);
3285 if Nkind (Arg_Parameter_Types) = N_Null then
3286 if Present (Formal) then
3290 -- A list of one type, e.g. (List) is parsed as
3291 -- a parenthesized expression.
3293 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3294 and then Paren_Count (Arg_Parameter_Types) = 1
3297 or else Present (Next_Formal (Formal))
3302 Same_Base_Type (Arg_Parameter_Types, Formal);
3305 -- A list of more than one type is parsed as a aggregate
3307 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3308 and then Paren_Count (Arg_Parameter_Types) = 0
3310 Ptype := First (Expressions (Arg_Parameter_Types));
3311 while Present (Ptype) or else Present (Formal) loop
3314 or else not Same_Base_Type (Ptype, Formal)
3319 Next_Formal (Formal);
3324 -- Anything else is of the wrong form
3328 ("wrong form for Parameter_Types parameter",
3329 Arg_Parameter_Types);
3331 end Check_Matching_Types;
3334 -- Match is now False if the entry we found did not match
3335 -- either a supplied Parameter_Types or Result_Types argument
3341 -- Ambiguous case, the flag Ambiguous shows if we already
3342 -- detected this and output the initial messages.
3345 if not Ambiguous then
3347 Error_Msg_Name_1 := Pname;
3349 ("pragma% does not uniquely identify subprogram!",
3351 Error_Msg_Sloc := Sloc (Ent);
3352 Error_Msg_N ("matching subprogram #!", N);
3356 Error_Msg_Sloc := Sloc (Def_Id);
3357 Error_Msg_N ("matching subprogram #!", N);
3362 Hom_Id := Homonym (Hom_Id);
3365 -- See if we found an entry
3368 if not Ambiguous then
3369 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3371 ("pragma% cannot be given for generic subprogram");
3374 ("pragma% does not identify local subprogram");
3381 -- Import pragmas must be for imported entities
3383 if Prag_Id = Pragma_Import_Function
3385 Prag_Id = Pragma_Import_Procedure
3387 Prag_Id = Pragma_Import_Valued_Procedure
3389 if not Is_Imported (Ent) then
3391 ("pragma Import or Interface must precede pragma%");
3394 -- Here we have the Export case which can set the entity as exported
3396 -- But does not do so if the specified external name is null, since
3397 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3398 -- compatible) to request no external name.
3400 elsif Nkind (Arg_External) = N_String_Literal
3401 and then String_Length (Strval (Arg_External)) = 0
3405 -- In all other cases, set entity as exported
3408 Set_Exported (Ent, Arg_Internal);
3411 -- Special processing for Valued_Procedure cases
3413 if Prag_Id = Pragma_Import_Valued_Procedure
3415 Prag_Id = Pragma_Export_Valued_Procedure
3417 Formal := First_Formal (Ent);
3420 Error_Pragma ("at least one parameter required for pragma%");
3422 elsif Ekind (Formal) /= E_Out_Parameter then
3423 Error_Pragma ("first parameter must have mode out for pragma%");
3426 Set_Is_Valued_Procedure (Ent);
3430 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3432 -- Process Result_Mechanism argument if present. We have already
3433 -- checked that this is only allowed for the function case.
3435 if Present (Arg_Result_Mechanism) then
3436 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3439 -- Process Mechanism parameter if present. Note that this parameter
3440 -- is not analyzed, and must not be analyzed since it is semantic
3441 -- nonsense, so we get it in exactly as the parser left it.
3443 if Present (Arg_Mechanism) then
3451 -- A single mechanism association without a formal parameter
3452 -- name is parsed as a parenthesized expression. All other
3453 -- cases are parsed as aggregates, so we rewrite the single
3454 -- parameter case as an aggregate for consistency.
3456 if Nkind (Arg_Mechanism) /= N_Aggregate
3457 and then Paren_Count (Arg_Mechanism) = 1
3459 Rewrite (Arg_Mechanism,
3460 Make_Aggregate (Sloc (Arg_Mechanism),
3461 Expressions => New_List (
3462 Relocate_Node (Arg_Mechanism))));
3465 -- Case of only mechanism name given, applies to all formals
3467 if Nkind (Arg_Mechanism) /= N_Aggregate then
3468 Formal := First_Formal (Ent);
3469 while Present (Formal) loop
3470 Set_Mechanism_Value (Formal, Arg_Mechanism);
3471 Next_Formal (Formal);
3474 -- Case of list of mechanism associations given
3477 if Null_Record_Present (Arg_Mechanism) then
3479 ("inappropriate form for Mechanism parameter",
3483 -- Deal with positional ones first
3485 Formal := First_Formal (Ent);
3487 if Present (Expressions (Arg_Mechanism)) then
3488 Mname := First (Expressions (Arg_Mechanism));
3489 while Present (Mname) loop
3492 ("too many mechanism associations", Mname);
3495 Set_Mechanism_Value (Formal, Mname);
3496 Next_Formal (Formal);
3501 -- Deal with named entries
3503 if Present (Component_Associations (Arg_Mechanism)) then
3504 Massoc := First (Component_Associations (Arg_Mechanism));
3505 while Present (Massoc) loop
3506 Choice := First (Choices (Massoc));
3508 if Nkind (Choice) /= N_Identifier
3509 or else Present (Next (Choice))
3512 ("incorrect form for mechanism association",
3516 Formal := First_Formal (Ent);
3520 ("parameter name & not present", Choice);
3523 if Chars (Choice) = Chars (Formal) then
3525 (Formal, Expression (Massoc));
3527 -- Set entity on identifier for ASIS
3529 Set_Entity (Choice, Formal);
3534 Next_Formal (Formal);
3544 -- Process First_Optional_Parameter argument if present. We have
3545 -- already checked that this is only allowed for the Import case.
3547 if Present (Arg_First_Optional_Parameter) then
3548 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3550 ("first optional parameter must be formal parameter name",
3551 Arg_First_Optional_Parameter);
3554 Formal := First_Formal (Ent);
3558 ("specified formal parameter& not found",
3559 Arg_First_Optional_Parameter);
3562 exit when Chars (Formal) =
3563 Chars (Arg_First_Optional_Parameter);
3565 Next_Formal (Formal);
3568 Set_First_Optional_Parameter (Ent, Formal);
3570 -- Check specified and all remaining formals have right form
3572 while Present (Formal) loop
3573 if Ekind (Formal) /= E_In_Parameter then
3575 ("optional formal& is not of mode in!",
3576 Arg_First_Optional_Parameter, Formal);
3579 Dval := Default_Value (Formal);
3583 ("optional formal& does not have default value!",
3584 Arg_First_Optional_Parameter, Formal);
3586 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3591 ("default value for optional formal& is non-static!",
3592 Arg_First_Optional_Parameter, Formal);
3596 Set_Is_Optional_Parameter (Formal);
3597 Next_Formal (Formal);
3600 end Process_Extended_Import_Export_Subprogram_Pragma;
3602 --------------------------
3603 -- Process_Generic_List --
3604 --------------------------
3606 procedure Process_Generic_List is
3611 Check_No_Identifiers;
3612 Check_At_Least_N_Arguments (1);
3615 while Present (Arg) loop
3616 Exp := Expression (Arg);
3619 if not Is_Entity_Name (Exp)
3621 (not Is_Generic_Instance (Entity (Exp))
3623 not Is_Generic_Unit (Entity (Exp)))
3626 ("pragma% argument must be name of generic unit/instance",
3632 end Process_Generic_List;
3634 ---------------------------------
3635 -- Process_Import_Or_Interface --
3636 ---------------------------------
3638 procedure Process_Import_Or_Interface is
3644 Process_Convention (C, Def_Id);
3645 Kill_Size_Check_Code (Def_Id);
3646 Note_Possible_Modification (Expression (Arg2), Sure => False);
3648 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3650 -- We do not permit Import to apply to a renaming declaration
3652 if Present (Renamed_Object (Def_Id)) then
3654 ("pragma% not allowed for object renaming", Arg2);
3656 -- User initialization is not allowed for imported object, but
3657 -- the object declaration may contain a default initialization,
3658 -- that will be discarded. Note that an explicit initialization
3659 -- only counts if it comes from source, otherwise it is simply
3660 -- the code generator making an implicit initialization explicit.
3662 elsif Present (Expression (Parent (Def_Id)))
3663 and then Comes_From_Source (Expression (Parent (Def_Id)))
3665 Error_Msg_Sloc := Sloc (Def_Id);
3667 ("no initialization allowed for declaration of& #",
3668 "\imported entities cannot be initialized (RM B.1(24))",
3672 Set_Imported (Def_Id);
3673 Process_Interface_Name (Def_Id, Arg3, Arg4);
3675 -- Note that we do not set Is_Public here. That's because we
3676 -- only want to set it if there is no address clause, and we
3677 -- don't know that yet, so we delay that processing till
3680 -- pragma Import completes deferred constants
3682 if Ekind (Def_Id) = E_Constant then
3683 Set_Has_Completion (Def_Id);
3686 -- It is not possible to import a constant of an unconstrained
3687 -- array type (e.g. string) because there is no simple way to
3688 -- write a meaningful subtype for it.
3690 if Is_Array_Type (Etype (Def_Id))
3691 and then not Is_Constrained (Etype (Def_Id))
3694 ("imported constant& must have a constrained subtype",
3699 elsif Is_Subprogram (Def_Id)
3700 or else Is_Generic_Subprogram (Def_Id)
3702 -- If the name is overloaded, pragma applies to all of the
3703 -- denoted entities in the same declarative part.
3706 while Present (Hom_Id) loop
3707 Def_Id := Get_Base_Subprogram (Hom_Id);
3709 -- Ignore inherited subprograms because the pragma will
3710 -- apply to the parent operation, which is the one called.
3712 if Is_Overloadable (Def_Id)
3713 and then Present (Alias (Def_Id))
3717 -- If it is not a subprogram, it must be in an outer scope and
3718 -- pragma does not apply.
3720 elsif not Is_Subprogram (Def_Id)
3721 and then not Is_Generic_Subprogram (Def_Id)
3725 -- Verify that the homonym is in the same declarative part (not
3726 -- just the same scope).
3728 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3729 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3734 Set_Imported (Def_Id);
3736 -- Reject an Import applied to an abstract subprogram
3738 if Is_Subprogram (Def_Id)
3739 and then Is_Abstract_Subprogram (Def_Id)
3741 Error_Msg_Sloc := Sloc (Def_Id);
3743 ("cannot import abstract subprogram& declared#",
3747 -- Special processing for Convention_Intrinsic
3749 if C = Convention_Intrinsic then
3751 -- Link_Name argument not allowed for intrinsic
3754 and then Chars (Arg3) = Name_Link_Name
3759 if Present (Arg4) then
3761 ("Link_Name argument not allowed for " &
3766 Set_Is_Intrinsic_Subprogram (Def_Id);
3768 -- If no external name is present, then check that this
3769 -- is a valid intrinsic subprogram. If an external name
3770 -- is present, then this is handled by the back end.
3773 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3777 -- All interfaced procedures need an external symbol created
3778 -- for them since they are always referenced from another
3781 Set_Is_Public (Def_Id);
3783 -- Verify that the subprogram does not have a completion
3784 -- through a renaming declaration. For other completions the
3785 -- pragma appears as a too late representation.
3788 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3792 and then Nkind (Decl) = N_Subprogram_Declaration
3793 and then Present (Corresponding_Body (Decl))
3794 and then Nkind (Unit_Declaration_Node
3795 (Corresponding_Body (Decl))) =
3796 N_Subprogram_Renaming_Declaration
3798 Error_Msg_Sloc := Sloc (Def_Id);
3800 ("cannot import&, renaming already provided for " &
3801 "declaration #", N, Def_Id);
3805 Set_Has_Completion (Def_Id);
3806 Process_Interface_Name (Def_Id, Arg3, Arg4);
3809 if Is_Compilation_Unit (Hom_Id) then
3811 -- Its possible homonyms are not affected by the pragma.
3812 -- Such homonyms might be present in the context of other
3813 -- units being compiled.
3818 Hom_Id := Homonym (Hom_Id);
3822 -- When the convention is Java or CIL, we also allow Import to be
3823 -- given for packages, generic packages, exceptions, record
3824 -- components, and access to subprograms.
3826 elsif (C = Convention_Java or else C = Convention_CIL)
3828 (Is_Package_Or_Generic_Package (Def_Id)
3829 or else Ekind (Def_Id) = E_Exception
3830 or else Ekind (Def_Id) = E_Access_Subprogram_Type
3831 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3833 Set_Imported (Def_Id);
3834 Set_Is_Public (Def_Id);
3835 Process_Interface_Name (Def_Id, Arg3, Arg4);
3837 -- Import a CPP class
3839 elsif Is_Record_Type (Def_Id)
3840 and then C = Convention_CPP
3842 -- Types treated as CPP classes are treated as limited, but we
3843 -- don't require them to be declared this way. A warning is
3844 -- issued to encourage the user to declare them as limited.
3845 -- This is not an error, for compatibility reasons, because
3846 -- these types have been supported this way for some time.
3848 if not Is_Limited_Type (Def_Id) then
3850 ("imported 'C'P'P type should be " &
3851 "explicitly declared limited?",
3852 Get_Pragma_Arg (Arg2));
3854 ("\type will be considered limited",
3855 Get_Pragma_Arg (Arg2));
3858 Set_Is_CPP_Class (Def_Id);
3859 Set_Is_Limited_Record (Def_Id);
3861 -- Imported CPP types must not have discriminants (because C++
3862 -- classes do not have discriminants).
3864 if Has_Discriminants (Def_Id) then
3866 ("imported 'C'P'P type cannot have discriminants",
3867 First (Discriminant_Specifications
3868 (Declaration_Node (Def_Id))));
3871 -- Components of imported CPP types must not have default
3872 -- expressions because the constructor (if any) is on the
3876 Tdef : constant Node_Id :=
3877 Type_Definition (Declaration_Node (Def_Id));
3882 if Nkind (Tdef) = N_Record_Definition then
3883 Clist := Component_List (Tdef);
3886 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
3887 Clist := Component_List (Record_Extension_Part (Tdef));
3890 if Present (Clist) then
3891 Comp := First (Component_Items (Clist));
3892 while Present (Comp) loop
3893 if Present (Expression (Comp)) then
3895 ("component of imported 'C'P'P type cannot have" &
3896 " default expression", Expression (Comp));
3906 ("second argument of pragma% must be object or subprogram",
3910 -- If this pragma applies to a compilation unit, then the unit, which
3911 -- is a subprogram, does not require (or allow) a body. We also do
3912 -- not need to elaborate imported procedures.
3914 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3916 Cunit : constant Node_Id := Parent (Parent (N));
3918 Set_Body_Required (Cunit, False);
3921 end Process_Import_Or_Interface;
3923 --------------------
3924 -- Process_Inline --
3925 --------------------
3927 procedure Process_Inline (Active : Boolean) is
3933 Effective : Boolean := False;
3935 procedure Make_Inline (Subp : Entity_Id);
3936 -- Subp is the defining unit name of the subprogram declaration. Set
3937 -- the flag, as well as the flag in the corresponding body, if there
3940 procedure Set_Inline_Flags (Subp : Entity_Id);
3941 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
3942 -- Has_Pragma_Inline_Always for the Inline_Always case.
3944 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3945 -- Returns True if it can be determined at this stage that inlining
3946 -- is not possible, for example if the body is available and contains
3947 -- exception handlers, we prevent inlining, since otherwise we can
3948 -- get undefined symbols at link time. This function also emits a
3949 -- warning if front-end inlining is enabled and the pragma appears
3952 -- ??? is business with link symbols still valid, or does it relate
3953 -- to front end ZCX which is being phased out ???
3955 ---------------------------
3956 -- Inlining_Not_Possible --
3957 ---------------------------
3959 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3960 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3964 if Nkind (Decl) = N_Subprogram_Body then
3965 Stats := Handled_Statement_Sequence (Decl);
3966 return Present (Exception_Handlers (Stats))
3967 or else Present (At_End_Proc (Stats));
3969 elsif Nkind (Decl) = N_Subprogram_Declaration
3970 and then Present (Corresponding_Body (Decl))
3972 if Front_End_Inlining
3973 and then Analyzed (Corresponding_Body (Decl))
3975 Error_Msg_N ("pragma appears too late, ignored?", N);
3978 -- If the subprogram is a renaming as body, the body is just a
3979 -- call to the renamed subprogram, and inlining is trivially
3983 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
3984 N_Subprogram_Renaming_Declaration
3990 Handled_Statement_Sequence
3991 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3994 Present (Exception_Handlers (Stats))
3995 or else Present (At_End_Proc (Stats));
3999 -- If body is not available, assume the best, the check is
4000 -- performed again when compiling enclosing package bodies.
4004 end Inlining_Not_Possible;
4010 procedure Make_Inline (Subp : Entity_Id) is
4011 Kind : constant Entity_Kind := Ekind (Subp);
4012 Inner_Subp : Entity_Id := Subp;
4015 -- Ignore if bad type, avoid cascaded error
4017 if Etype (Subp) = Any_Type then
4021 -- Ignore if all inlining is suppressed
4023 elsif Suppress_All_Inlining then
4027 -- If inlining is not possible, for now do not treat as an error
4029 elsif Inlining_Not_Possible (Subp) then
4033 -- Here we have a candidate for inlining, but we must exclude
4034 -- derived operations. Otherwise we would end up trying to inline
4035 -- a phantom declaration, and the result would be to drag in a
4036 -- body which has no direct inlining associated with it. That
4037 -- would not only be inefficient but would also result in the
4038 -- backend doing cross-unit inlining in cases where it was
4039 -- definitely inappropriate to do so.
4041 -- However, a simple Comes_From_Source test is insufficient, since
4042 -- we do want to allow inlining of generic instances which also do
4043 -- not come from source. We also need to recognize specs generated
4044 -- by the front-end for bodies that carry the pragma. Finally,
4045 -- predefined operators do not come from source but are not
4046 -- inlineable either.
4048 elsif Is_Generic_Instance (Subp)
4049 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4053 elsif not Comes_From_Source (Subp)
4054 and then Scope (Subp) /= Standard_Standard
4060 -- The referenced entity must either be the enclosing entity, or
4061 -- an entity declared within the current open scope.
4063 if Present (Scope (Subp))
4064 and then Scope (Subp) /= Current_Scope
4065 and then Subp /= Current_Scope
4068 ("argument of% must be entity in current scope", Assoc);
4072 -- Processing for procedure, operator or function. If subprogram
4073 -- is aliased (as for an instance) indicate that the renamed
4074 -- entity (if declared in the same unit) is inlined.
4076 if Is_Subprogram (Subp) then
4077 Inner_Subp := Ultimate_Alias (Inner_Subp);
4079 if In_Same_Source_Unit (Subp, Inner_Subp) then
4080 Set_Inline_Flags (Inner_Subp);
4082 Decl := Parent (Parent (Inner_Subp));
4084 if Nkind (Decl) = N_Subprogram_Declaration
4085 and then Present (Corresponding_Body (Decl))
4087 Set_Inline_Flags (Corresponding_Body (Decl));
4089 elsif Is_Generic_Instance (Subp) then
4091 -- Indicate that the body needs to be created for
4092 -- inlining subsequent calls. The instantiation node
4093 -- follows the declaration of the wrapper package
4096 if Scope (Subp) /= Standard_Standard
4098 Need_Subprogram_Instance_Body
4099 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4109 -- For a generic subprogram set flag as well, for use at the point
4110 -- of instantiation, to determine whether the body should be
4113 elsif Is_Generic_Subprogram (Subp) then
4114 Set_Inline_Flags (Subp);
4117 -- Literals are by definition inlined
4119 elsif Kind = E_Enumeration_Literal then
4122 -- Anything else is an error
4126 ("expect subprogram name for pragma%", Assoc);
4130 ----------------------
4131 -- Set_Inline_Flags --
4132 ----------------------
4134 procedure Set_Inline_Flags (Subp : Entity_Id) is
4137 Set_Is_Inlined (Subp, True);
4140 if not Has_Pragma_Inline (Subp) then
4141 Set_Has_Pragma_Inline (Subp);
4145 if Prag_Id = Pragma_Inline_Always then
4146 Set_Has_Pragma_Inline_Always (Subp);
4148 end Set_Inline_Flags;
4150 -- Start of processing for Process_Inline
4153 Check_No_Identifiers;
4154 Check_At_Least_N_Arguments (1);
4157 Inline_Processing_Required := True;
4161 while Present (Assoc) loop
4162 Subp_Id := Expression (Assoc);
4166 if Is_Entity_Name (Subp_Id) then
4167 Subp := Entity (Subp_Id);
4169 if Subp = Any_Id then
4171 -- If previous error, avoid cascaded errors
4179 while Present (Homonym (Subp))
4180 and then Scope (Homonym (Subp)) = Current_Scope
4182 Make_Inline (Homonym (Subp));
4183 Subp := Homonym (Subp);
4190 ("inappropriate argument for pragma%", Assoc);
4193 and then Warn_On_Redundant_Constructs
4194 and then not Suppress_All_Inlining
4196 if Inlining_Not_Possible (Subp) then
4198 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4201 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4209 ----------------------------
4210 -- Process_Interface_Name --
4211 ----------------------------
4213 procedure Process_Interface_Name
4214 (Subprogram_Def : Entity_Id;
4220 String_Val : String_Id;
4222 procedure Check_Form_Of_Interface_Name
4224 Ext_Name_Case : Boolean);
4225 -- SN is a string literal node for an interface name. This routine
4226 -- performs some minimal checks that the name is reasonable. In
4227 -- particular that no spaces or other obviously incorrect characters
4228 -- appear. This is only a warning, since any characters are allowed.
4229 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4231 ----------------------------------
4232 -- Check_Form_Of_Interface_Name --
4233 ----------------------------------
4235 procedure Check_Form_Of_Interface_Name
4237 Ext_Name_Case : Boolean)
4239 S : constant String_Id := Strval (Expr_Value_S (SN));
4240 SL : constant Nat := String_Length (S);
4245 Error_Msg_N ("interface name cannot be null string", SN);
4248 for J in 1 .. SL loop
4249 C := Get_String_Char (S, J);
4251 -- Look for dubious character and issue unconditional warning.
4252 -- Definitely dubious if not in character range.
4254 if not In_Character_Range (C)
4256 -- For all cases except CLI target,
4257 -- commas, spaces and slashes are dubious (in CLI, we use
4258 -- commas and backslashes in external names to specify
4259 -- assembly version and public key, while slashes and spaces
4260 -- can be used in names to mark nested classes and
4263 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4264 and then (Get_Character (C) = ','
4266 Get_Character (C) = '\'))
4267 or else (VM_Target /= CLI_Target
4268 and then (Get_Character (C) = ' '
4270 Get_Character (C) = '/'))
4273 ("?interface name contains illegal character",
4274 Sloc (SN) + Source_Ptr (J));
4277 end Check_Form_Of_Interface_Name;
4279 -- Start of processing for Process_Interface_Name
4282 if No (Link_Arg) then
4283 if No (Ext_Arg) then
4284 if VM_Target = CLI_Target
4285 and then Ekind (Subprogram_Def) = E_Package
4286 and then Nkind (Parent (Subprogram_Def)) =
4287 N_Package_Specification
4288 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4293 (Generic_Parent (Parent (Subprogram_Def))));
4298 elsif Chars (Ext_Arg) = Name_Link_Name then
4300 Link_Nam := Expression (Ext_Arg);
4303 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4304 Ext_Nam := Expression (Ext_Arg);
4309 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4310 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4311 Ext_Nam := Expression (Ext_Arg);
4312 Link_Nam := Expression (Link_Arg);
4315 -- Check expressions for external name and link name are static
4317 if Present (Ext_Nam) then
4318 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4319 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4321 -- Verify that external name is not the name of a local entity,
4322 -- which would hide the imported one and could lead to run-time
4323 -- surprises. The problem can only arise for entities declared in
4324 -- a package body (otherwise the external name is fully qualified
4325 -- and will not conflict).
4333 if Prag_Id = Pragma_Import then
4334 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4336 E := Entity_Id (Get_Name_Table_Info (Nam));
4338 if Nam /= Chars (Subprogram_Def)
4339 and then Present (E)
4340 and then not Is_Overloadable (E)
4341 and then Is_Immediately_Visible (E)
4342 and then not Is_Imported (E)
4343 and then Ekind (Scope (E)) = E_Package
4346 while Present (Par) loop
4347 if Nkind (Par) = N_Package_Body then
4348 Error_Msg_Sloc := Sloc (E);
4350 ("imported entity is hidden by & declared#",
4355 Par := Parent (Par);
4362 if Present (Link_Nam) then
4363 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4364 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4367 -- If there is no link name, just set the external name
4369 if No (Link_Nam) then
4370 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4372 -- For the Link_Name case, the given literal is preceded by an
4373 -- asterisk, which indicates to GCC that the given name should be
4374 -- taken literally, and in particular that no prepending of
4375 -- underlines should occur, even in systems where this is the
4381 if VM_Target = No_VM then
4382 Store_String_Char (Get_Char_Code ('*'));
4385 String_Val := Strval (Expr_Value_S (Link_Nam));
4386 Store_String_Chars (String_Val);
4388 Make_String_Literal (Sloc (Link_Nam),
4389 Strval => End_String);
4392 Set_Encoded_Interface_Name
4393 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4395 -- We allow duplicated export names in CIL, as they are always
4396 -- enclosed in a namespace that differentiates them, and overloaded
4397 -- entities are supported by the VM.
4399 if Convention (Subprogram_Def) /= Convention_CIL then
4400 Check_Duplicated_Export_Name (Link_Nam);
4402 end Process_Interface_Name;
4404 -----------------------------------------
4405 -- Process_Interrupt_Or_Attach_Handler --
4406 -----------------------------------------
4408 procedure Process_Interrupt_Or_Attach_Handler is
4409 Arg1_X : constant Node_Id := Expression (Arg1);
4410 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4411 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4414 Set_Is_Interrupt_Handler (Handler_Proc);
4416 -- If the pragma is not associated with a handler procedure within a
4417 -- protected type, then it must be for a nonprotected procedure for
4418 -- the AAMP target, in which case we don't associate a representation
4419 -- item with the procedure's scope.
4421 if Ekind (Proc_Scope) = E_Protected_Type then
4422 if Prag_Id = Pragma_Interrupt_Handler
4424 Prag_Id = Pragma_Attach_Handler
4426 Record_Rep_Item (Proc_Scope, N);
4429 end Process_Interrupt_Or_Attach_Handler;
4431 --------------------------------------------------
4432 -- Process_Restrictions_Or_Restriction_Warnings --
4433 --------------------------------------------------
4435 -- Note: some of the simple identifier cases were handled in par-prag,
4436 -- but it is harmless (and more straightforward) to simply handle all
4437 -- cases here, even if it means we repeat a bit of work in some cases.
4439 procedure Process_Restrictions_Or_Restriction_Warnings
4443 R_Id : Restriction_Id;
4448 procedure Check_Unit_Name (N : Node_Id);
4449 -- Checks unit name parameter for No_Dependence. Returns if it has
4450 -- an appropriate form, otherwise raises pragma argument error.
4452 ---------------------
4453 -- Check_Unit_Name --
4454 ---------------------
4456 procedure Check_Unit_Name (N : Node_Id) is
4458 if Nkind (N) = N_Selected_Component then
4459 Check_Unit_Name (Prefix (N));
4460 Check_Unit_Name (Selector_Name (N));
4462 elsif Nkind (N) = N_Identifier then
4467 ("wrong form for unit name for No_Dependence", N);
4469 end Check_Unit_Name;
4471 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4474 Check_Ada_83_Warning;
4475 Check_At_Least_N_Arguments (1);
4476 Check_Valid_Configuration_Pragma;
4479 while Present (Arg) loop
4481 Expr := Expression (Arg);
4483 -- Case of no restriction identifier present
4485 if Id = No_Name then
4486 if Nkind (Expr) /= N_Identifier then
4488 ("invalid form for restriction", Arg);
4493 (Process_Restriction_Synonyms (Expr));
4495 if R_Id not in All_Boolean_Restrictions then
4496 Error_Msg_Name_1 := Pname;
4498 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4500 -- Check for possible misspelling
4502 for J in Restriction_Id loop
4504 Rnm : constant String := Restriction_Id'Image (J);
4507 Name_Buffer (1 .. Rnm'Length) := Rnm;
4508 Name_Len := Rnm'Length;
4509 Set_Casing (All_Lower_Case);
4511 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4513 (Identifier_Casing (Current_Source_File));
4514 Error_Msg_String (1 .. Rnm'Length) :=
4515 Name_Buffer (1 .. Name_Len);
4516 Error_Msg_Strlen := Rnm'Length;
4517 Error_Msg_N -- CODEFIX
4518 ("\possible misspelling of ""~""",
4519 Get_Pragma_Arg (Arg));
4528 if Implementation_Restriction (R_Id) then
4529 Check_Restriction (No_Implementation_Restrictions, Arg);
4532 -- If this is a warning, then set the warning unless we already
4533 -- have a real restriction active (we never want a warning to
4534 -- override a real restriction).
4537 if not Restriction_Active (R_Id) then
4538 Set_Restriction (R_Id, N);
4539 Restriction_Warnings (R_Id) := True;
4542 -- If real restriction case, then set it and make sure that the
4543 -- restriction warning flag is off, since a real restriction
4544 -- always overrides a warning.
4547 Set_Restriction (R_Id, N);
4548 Restriction_Warnings (R_Id) := False;
4551 -- Check for obsolescent restrictions in Ada 2005 mode
4554 and then Ada_Version >= Ada_2005
4555 and then (R_Id = No_Asynchronous_Control
4557 R_Id = No_Unchecked_Deallocation
4559 R_Id = No_Unchecked_Conversion)
4561 Check_Restriction (No_Obsolescent_Features, N);
4564 -- A very special case that must be processed here: pragma
4565 -- Restrictions (No_Exceptions) turns off all run-time
4566 -- checking. This is a bit dubious in terms of the formal
4567 -- language definition, but it is what is intended by RM
4568 -- H.4(12). Restriction_Warnings never affects generated code
4569 -- so this is done only in the real restriction case.
4571 if R_Id = No_Exceptions and then not Warn then
4572 Scope_Suppress := (others => True);
4575 -- Case of No_Dependence => unit-name. Note that the parser
4576 -- already made the necessary entry in the No_Dependence table.
4578 elsif Id = Name_No_Dependence then
4579 Check_Unit_Name (Expr);
4581 -- All other cases of restriction identifier present
4584 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4585 Analyze_And_Resolve (Expr, Any_Integer);
4587 if R_Id not in All_Parameter_Restrictions then
4589 ("invalid restriction parameter identifier", Arg);
4591 elsif not Is_OK_Static_Expression (Expr) then
4592 Flag_Non_Static_Expr
4593 ("value must be static expression!", Expr);
4596 elsif not Is_Integer_Type (Etype (Expr))
4597 or else Expr_Value (Expr) < 0
4600 ("value must be non-negative integer", Arg);
4603 -- Restriction pragma is active
4605 Val := Expr_Value (Expr);
4607 if not UI_Is_In_Int_Range (Val) then
4609 ("pragma ignored, value too large?", Arg);
4612 -- Warning case. If the real restriction is active, then we
4613 -- ignore the request, since warning never overrides a real
4614 -- restriction. Otherwise we set the proper warning. Note that
4615 -- this circuit sets the warning again if it is already set,
4616 -- which is what we want, since the constant may have changed.
4619 if not Restriction_Active (R_Id) then
4621 (R_Id, N, Integer (UI_To_Int (Val)));
4622 Restriction_Warnings (R_Id) := True;
4625 -- Real restriction case, set restriction and make sure warning
4626 -- flag is off since real restriction always overrides warning.
4629 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4630 Restriction_Warnings (R_Id) := False;
4636 end Process_Restrictions_Or_Restriction_Warnings;
4638 ---------------------------------
4639 -- Process_Suppress_Unsuppress --
4640 ---------------------------------
4642 -- Note: this procedure makes entries in the check suppress data
4643 -- structures managed by Sem. See spec of package Sem for full
4644 -- details on how we handle recording of check suppression.
4646 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4651 In_Package_Spec : constant Boolean :=
4652 Is_Package_Or_Generic_Package (Current_Scope)
4653 and then not In_Package_Body (Current_Scope);
4655 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4656 -- Used to suppress a single check on the given entity
4658 --------------------------------
4659 -- Suppress_Unsuppress_Echeck --
4660 --------------------------------
4662 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4664 Set_Checks_May_Be_Suppressed (E);
4666 if In_Package_Spec then
4667 Push_Global_Suppress_Stack_Entry
4670 Suppress => Suppress_Case);
4673 Push_Local_Suppress_Stack_Entry
4676 Suppress => Suppress_Case);
4679 -- If this is a first subtype, and the base type is distinct,
4680 -- then also set the suppress flags on the base type.
4682 if Is_First_Subtype (E)
4683 and then Etype (E) /= E
4685 Suppress_Unsuppress_Echeck (Etype (E), C);
4687 end Suppress_Unsuppress_Echeck;
4689 -- Start of processing for Process_Suppress_Unsuppress
4692 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4693 -- declarative part or a package spec (RM 11.5(5)).
4695 if not Is_Configuration_Pragma then
4696 Check_Is_In_Decl_Part_Or_Package_Spec;
4699 Check_At_Least_N_Arguments (1);
4700 Check_At_Most_N_Arguments (2);
4701 Check_No_Identifier (Arg1);
4702 Check_Arg_Is_Identifier (Arg1);
4704 C := Get_Check_Id (Chars (Expression (Arg1)));
4706 if C = No_Check_Id then
4708 ("argument of pragma% is not valid check name", Arg1);
4711 if not Suppress_Case
4712 and then (C = All_Checks or else C = Overflow_Check)
4714 Opt.Overflow_Checks_Unsuppressed := True;
4717 if Arg_Count = 1 then
4719 -- Make an entry in the local scope suppress table. This is the
4720 -- table that directly shows the current value of the scope
4721 -- suppress check for any check id value.
4723 if C = All_Checks then
4725 -- For All_Checks, we set all specific predefined checks with
4726 -- the exception of Elaboration_Check, which is handled
4727 -- specially because of not wanting All_Checks to have the
4728 -- effect of deactivating static elaboration order processing.
4730 for J in Scope_Suppress'Range loop
4731 if J /= Elaboration_Check then
4732 Scope_Suppress (J) := Suppress_Case;
4736 -- If not All_Checks, and predefined check, then set appropriate
4737 -- scope entry. Note that we will set Elaboration_Check if this
4738 -- is explicitly specified.
4740 elsif C in Predefined_Check_Id then
4741 Scope_Suppress (C) := Suppress_Case;
4744 -- Also make an entry in the Local_Entity_Suppress table
4746 Push_Local_Suppress_Stack_Entry
4749 Suppress => Suppress_Case);
4751 -- Case of two arguments present, where the check is suppressed for
4752 -- a specified entity (given as the second argument of the pragma)
4755 -- This is obsolescent in Ada 2005 mode
4757 if Ada_Version >= Ada_2005 then
4758 Check_Restriction (No_Obsolescent_Features, Arg2);
4761 Check_Optional_Identifier (Arg2, Name_On);
4762 E_Id := Expression (Arg2);
4765 if not Is_Entity_Name (E_Id) then
4767 ("second argument of pragma% must be entity name", Arg2);
4776 -- Enforce RM 11.5(7) which requires that for a pragma that
4777 -- appears within a package spec, the named entity must be
4778 -- within the package spec. We allow the package name itself
4779 -- to be mentioned since that makes sense, although it is not
4780 -- strictly allowed by 11.5(7).
4783 and then E /= Current_Scope
4784 and then Scope (E) /= Current_Scope
4787 ("entity in pragma% is not in package spec (RM 11.5(7))",
4791 -- Loop through homonyms. As noted below, in the case of a package
4792 -- spec, only homonyms within the package spec are considered.
4795 Suppress_Unsuppress_Echeck (E, C);
4797 if Is_Generic_Instance (E)
4798 and then Is_Subprogram (E)
4799 and then Present (Alias (E))
4801 Suppress_Unsuppress_Echeck (Alias (E), C);
4804 -- Move to next homonym
4809 -- If we are within a package specification, the pragma only
4810 -- applies to homonyms in the same scope.
4812 exit when In_Package_Spec
4813 and then Scope (E) /= Current_Scope;
4816 end Process_Suppress_Unsuppress;
4822 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4824 if Is_Imported (E) then
4826 ("cannot export entity& that was previously imported", Arg);
4828 elsif Present (Address_Clause (E)) then
4830 ("cannot export entity& that has an address clause", Arg);
4833 Set_Is_Exported (E);
4835 -- Generate a reference for entity explicitly, because the
4836 -- identifier may be overloaded and name resolution will not
4839 Generate_Reference (E, Arg);
4841 -- Deal with exporting non-library level entity
4843 if not Is_Library_Level_Entity (E) then
4845 -- Not allowed at all for subprograms
4847 if Is_Subprogram (E) then
4848 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4850 -- Otherwise set public and statically allocated
4854 Set_Is_Statically_Allocated (E);
4856 -- Warn if the corresponding W flag is set and the pragma comes
4857 -- from source. The latter may not be true e.g. on VMS where we
4858 -- expand export pragmas for exception codes associated with
4859 -- imported or exported exceptions. We do not want to generate
4860 -- a warning for something that the user did not write.
4862 if Warn_On_Export_Import
4863 and then Comes_From_Source (Arg)
4866 ("?& has been made static as a result of Export", Arg, E);
4868 ("\this usage is non-standard and non-portable", Arg);
4873 if Warn_On_Export_Import and then Is_Type (E) then
4874 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
4877 if Warn_On_Export_Import and Inside_A_Generic then
4879 ("all instances of& will have the same external name?", Arg, E);
4883 ----------------------------------------------
4884 -- Set_Extended_Import_Export_External_Name --
4885 ----------------------------------------------
4887 procedure Set_Extended_Import_Export_External_Name
4888 (Internal_Ent : Entity_Id;
4889 Arg_External : Node_Id)
4891 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4895 if No (Arg_External) then
4899 Check_Arg_Is_External_Name (Arg_External);
4901 if Nkind (Arg_External) = N_String_Literal then
4902 if String_Length (Strval (Arg_External)) = 0 then
4905 New_Name := Adjust_External_Name_Case (Arg_External);
4908 elsif Nkind (Arg_External) = N_Identifier then
4909 New_Name := Get_Default_External_Name (Arg_External);
4911 -- Check_Arg_Is_External_Name should let through only identifiers and
4912 -- string literals or static string expressions (which are folded to
4913 -- string literals).
4916 raise Program_Error;
4919 -- If we already have an external name set (by a prior normal Import
4920 -- or Export pragma), then the external names must match
4922 if Present (Interface_Name (Internal_Ent)) then
4923 Check_Matching_Internal_Names : declare
4924 S1 : constant String_Id := Strval (Old_Name);
4925 S2 : constant String_Id := Strval (New_Name);
4928 -- Called if names do not match
4934 procedure Mismatch is
4936 Error_Msg_Sloc := Sloc (Old_Name);
4938 ("external name does not match that given #",
4942 -- Start of processing for Check_Matching_Internal_Names
4945 if String_Length (S1) /= String_Length (S2) then
4949 for J in 1 .. String_Length (S1) loop
4950 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4955 end Check_Matching_Internal_Names;
4957 -- Otherwise set the given name
4960 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4961 Check_Duplicated_Export_Name (New_Name);
4963 end Set_Extended_Import_Export_External_Name;
4969 procedure Set_Imported (E : Entity_Id) is
4971 -- Error message if already imported or exported
4973 if Is_Exported (E) or else Is_Imported (E) then
4975 -- Error if being set Exported twice
4977 if Is_Exported (E) then
4978 Error_Msg_NE ("entity& was previously exported", N, E);
4980 -- OK if Import/Interface case
4982 elsif Import_Interface_Present (N) then
4985 -- Error if being set Imported twice
4988 Error_Msg_NE ("entity& was previously imported", N, E);
4991 Error_Msg_Name_1 := Pname;
4993 ("\(pragma% applies to all previous entities)", N);
4995 Error_Msg_Sloc := Sloc (E);
4996 Error_Msg_NE ("\import not allowed for& declared#", N, E);
4998 -- Here if not previously imported or exported, OK to import
5001 Set_Is_Imported (E);
5003 -- If the entity is an object that is not at the library level,
5004 -- then it is statically allocated. We do not worry about objects
5005 -- with address clauses in this context since they are not really
5006 -- imported in the linker sense.
5009 and then not Is_Library_Level_Entity (E)
5010 and then No (Address_Clause (E))
5012 Set_Is_Statically_Allocated (E);
5019 -------------------------
5020 -- Set_Mechanism_Value --
5021 -------------------------
5023 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5024 -- analyzed, since it is semantic nonsense), so we get it in the exact
5025 -- form created by the parser.
5027 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5030 Mech_Name_Id : Name_Id;
5032 procedure Bad_Class;
5033 -- Signal bad descriptor class name
5035 procedure Bad_Mechanism;
5036 -- Signal bad mechanism name
5042 procedure Bad_Class is
5044 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5047 -------------------------
5048 -- Bad_Mechanism_Value --
5049 -------------------------
5051 procedure Bad_Mechanism is
5053 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5056 -- Start of processing for Set_Mechanism_Value
5059 if Mechanism (Ent) /= Default_Mechanism then
5061 ("mechanism for & has already been set", Mech_Name, Ent);
5064 -- MECHANISM_NAME ::= value | reference | descriptor |
5067 if Nkind (Mech_Name) = N_Identifier then
5068 if Chars (Mech_Name) = Name_Value then
5069 Set_Mechanism (Ent, By_Copy);
5072 elsif Chars (Mech_Name) = Name_Reference then
5073 Set_Mechanism (Ent, By_Reference);
5076 elsif Chars (Mech_Name) = Name_Descriptor then
5077 Check_VMS (Mech_Name);
5079 -- Descriptor => Short_Descriptor if pragma was given
5081 if Short_Descriptors then
5082 Set_Mechanism (Ent, By_Short_Descriptor);
5084 Set_Mechanism (Ent, By_Descriptor);
5089 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5090 Check_VMS (Mech_Name);
5091 Set_Mechanism (Ent, By_Short_Descriptor);
5094 elsif Chars (Mech_Name) = Name_Copy then
5096 ("bad mechanism name, Value assumed", Mech_Name);
5102 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5103 -- short_descriptor (CLASS_NAME)
5104 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5106 -- Note: this form is parsed as an indexed component
5108 elsif Nkind (Mech_Name) = N_Indexed_Component then
5109 Class := First (Expressions (Mech_Name));
5111 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5112 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5113 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5114 or else Present (Next (Class))
5118 Mech_Name_Id := Chars (Prefix (Mech_Name));
5120 -- Change Descriptor => Short_Descriptor if pragma was given
5122 if Mech_Name_Id = Name_Descriptor
5123 and then Short_Descriptors
5125 Mech_Name_Id := Name_Short_Descriptor;
5129 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5130 -- short_descriptor (Class => CLASS_NAME)
5131 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5133 -- Note: this form is parsed as a function call
5135 elsif Nkind (Mech_Name) = N_Function_Call then
5136 Param := First (Parameter_Associations (Mech_Name));
5138 if Nkind (Name (Mech_Name)) /= N_Identifier
5139 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5140 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5141 or else Present (Next (Param))
5142 or else No (Selector_Name (Param))
5143 or else Chars (Selector_Name (Param)) /= Name_Class
5147 Class := Explicit_Actual_Parameter (Param);
5148 Mech_Name_Id := Chars (Name (Mech_Name));
5155 -- Fall through here with Class set to descriptor class name
5157 Check_VMS (Mech_Name);
5159 if Nkind (Class) /= N_Identifier then
5162 elsif Mech_Name_Id = Name_Descriptor
5163 and then Chars (Class) = Name_UBS
5165 Set_Mechanism (Ent, By_Descriptor_UBS);
5167 elsif Mech_Name_Id = Name_Descriptor
5168 and then Chars (Class) = Name_UBSB
5170 Set_Mechanism (Ent, By_Descriptor_UBSB);
5172 elsif Mech_Name_Id = Name_Descriptor
5173 and then Chars (Class) = Name_UBA
5175 Set_Mechanism (Ent, By_Descriptor_UBA);
5177 elsif Mech_Name_Id = Name_Descriptor
5178 and then Chars (Class) = Name_S
5180 Set_Mechanism (Ent, By_Descriptor_S);
5182 elsif Mech_Name_Id = Name_Descriptor
5183 and then Chars (Class) = Name_SB
5185 Set_Mechanism (Ent, By_Descriptor_SB);
5187 elsif Mech_Name_Id = Name_Descriptor
5188 and then Chars (Class) = Name_A
5190 Set_Mechanism (Ent, By_Descriptor_A);
5192 elsif Mech_Name_Id = Name_Descriptor
5193 and then Chars (Class) = Name_NCA
5195 Set_Mechanism (Ent, By_Descriptor_NCA);
5197 elsif Mech_Name_Id = Name_Short_Descriptor
5198 and then Chars (Class) = Name_UBS
5200 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5202 elsif Mech_Name_Id = Name_Short_Descriptor
5203 and then Chars (Class) = Name_UBSB
5205 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5207 elsif Mech_Name_Id = Name_Short_Descriptor
5208 and then Chars (Class) = Name_UBA
5210 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5212 elsif Mech_Name_Id = Name_Short_Descriptor
5213 and then Chars (Class) = Name_S
5215 Set_Mechanism (Ent, By_Short_Descriptor_S);
5217 elsif Mech_Name_Id = Name_Short_Descriptor
5218 and then Chars (Class) = Name_SB
5220 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5222 elsif Mech_Name_Id = Name_Short_Descriptor
5223 and then Chars (Class) = Name_A
5225 Set_Mechanism (Ent, By_Short_Descriptor_A);
5227 elsif Mech_Name_Id = Name_Short_Descriptor
5228 and then Chars (Class) = Name_NCA
5230 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5235 end Set_Mechanism_Value;
5237 ---------------------------
5238 -- Set_Ravenscar_Profile --
5239 ---------------------------
5241 -- The tasks to be done here are
5243 -- Set required policies
5245 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5246 -- pragma Locking_Policy (Ceiling_Locking)
5248 -- Set Detect_Blocking mode
5250 -- Set required restrictions (see System.Rident for detailed list)
5252 procedure Set_Ravenscar_Profile (N : Node_Id) is
5254 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5256 if Task_Dispatching_Policy /= ' '
5257 and then Task_Dispatching_Policy /= 'F'
5259 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5260 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5262 -- Set the FIFO_Within_Priorities policy, but always preserve
5263 -- System_Location since we like the error message with the run time
5267 Task_Dispatching_Policy := 'F';
5269 if Task_Dispatching_Policy_Sloc /= System_Location then
5270 Task_Dispatching_Policy_Sloc := Loc;
5274 -- pragma Locking_Policy (Ceiling_Locking)
5276 if Locking_Policy /= ' '
5277 and then Locking_Policy /= 'C'
5279 Error_Msg_Sloc := Locking_Policy_Sloc;
5280 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5282 -- Set the Ceiling_Locking policy, but preserve System_Location since
5283 -- we like the error message with the run time name.
5286 Locking_Policy := 'C';
5288 if Locking_Policy_Sloc /= System_Location then
5289 Locking_Policy_Sloc := Loc;
5293 -- pragma Detect_Blocking
5295 Detect_Blocking := True;
5297 -- Set the corresponding restrictions
5299 Set_Profile_Restrictions
5300 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5301 end Set_Ravenscar_Profile;
5303 -- Start of processing for Analyze_Pragma
5306 -- Deal with unrecognized pragma
5308 if not Is_Pragma_Name (Pname) then
5309 if Warn_On_Unrecognized_Pragma then
5310 Error_Msg_Name_1 := Pname;
5311 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5313 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5314 if Is_Bad_Spelling_Of (Pname, PN) then
5315 Error_Msg_Name_1 := PN;
5316 Error_Msg_N -- CODEFIX
5317 ("\?possible misspelling of %!", Pragma_Identifier (N));
5326 -- Here to start processing for recognized pragma
5328 Prag_Id := Get_Pragma_Id (Pname);
5337 if Present (Pragma_Argument_Associations (N)) then
5338 Arg1 := First (Pragma_Argument_Associations (N));
5340 if Present (Arg1) then
5341 Arg2 := Next (Arg1);
5343 if Present (Arg2) then
5344 Arg3 := Next (Arg2);
5346 if Present (Arg3) then
5347 Arg4 := Next (Arg3);
5353 -- Count number of arguments
5360 while Present (Arg_Node) loop
5361 Arg_Count := Arg_Count + 1;
5366 -- An enumeration type defines the pragmas that are supported by the
5367 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5368 -- into the corresponding enumeration value for the following case.
5376 -- pragma Abort_Defer;
5378 when Pragma_Abort_Defer =>
5380 Check_Arg_Count (0);
5382 -- The only required semantic processing is to check the
5383 -- placement. This pragma must appear at the start of the
5384 -- statement sequence of a handled sequence of statements.
5386 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5387 or else N /= First (Statements (Parent (N)))
5398 -- Note: this pragma also has some specific processing in Par.Prag
5399 -- because we want to set the Ada version mode during parsing.
5401 when Pragma_Ada_83 =>
5403 Check_Arg_Count (0);
5405 -- We really should check unconditionally for proper configuration
5406 -- pragma placement, since we really don't want mixed Ada modes
5407 -- within a single unit, and the GNAT reference manual has always
5408 -- said this was a configuration pragma, but we did not check and
5409 -- are hesitant to add the check now.
5411 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5412 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5413 -- or Ada 2012 mode.
5415 if Ada_Version >= Ada_05 then
5416 Check_Valid_Configuration_Pragma;
5419 -- Now set Ada 83 mode
5421 Ada_Version := Ada_83;
5422 Ada_Version_Explicit := Ada_Version;
5430 -- Note: this pragma also has some specific processing in Par.Prag
5431 -- because we want to set the Ada 83 version mode during parsing.
5433 when Pragma_Ada_95 =>
5435 Check_Arg_Count (0);
5437 -- We really should check unconditionally for proper configuration
5438 -- pragma placement, since we really don't want mixed Ada modes
5439 -- within a single unit, and the GNAT reference manual has always
5440 -- said this was a configuration pragma, but we did not check and
5441 -- are hesitant to add the check now.
5443 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5444 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5446 if Ada_Version >= Ada_05 then
5447 Check_Valid_Configuration_Pragma;
5450 -- Now set Ada 95 mode
5452 Ada_Version := Ada_95;
5453 Ada_Version_Explicit := Ada_Version;
5455 ---------------------
5456 -- Ada_05/Ada_2005 --
5457 ---------------------
5460 -- pragma Ada_05 (LOCAL_NAME);
5463 -- pragma Ada_2005 (LOCAL_NAME):
5465 -- Note: these pragmas also have some specific processing in Par.Prag
5466 -- because we want to set the Ada 2005 version mode during parsing.
5468 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5474 if Arg_Count = 1 then
5475 Check_Arg_Is_Local_Name (Arg1);
5476 E_Id := Expression (Arg1);
5478 if Etype (E_Id) = Any_Type then
5482 Set_Is_Ada_2005_Only (Entity (E_Id));
5485 Check_Arg_Count (0);
5487 -- For Ada_2005 we unconditionally enforce the documented
5488 -- configuration pragma placement, since we do not want to
5489 -- tolerate mixed modes in a unit involving Ada 2005. That
5490 -- would cause real difficulties for those cases where there
5491 -- are incompatibilities between Ada 95 and Ada 2005.
5493 Check_Valid_Configuration_Pragma;
5495 -- Now set Ada 2005 mode
5497 Ada_Version := Ada_05;
5498 Ada_Version_Explicit := Ada_05;
5502 ---------------------
5503 -- Ada_12/Ada_2012 --
5504 ---------------------
5507 -- pragma Ada_12 (LOCAL_NAME);
5510 -- pragma Ada_2012 (LOCAL_NAME):
5512 -- Note: these pragmas also have some specific processing in Par.Prag
5513 -- because we want to set the Ada 2012 version mode during parsing.
5515 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5521 if Arg_Count = 1 then
5522 Check_Arg_Is_Local_Name (Arg1);
5523 E_Id := Expression (Arg1);
5525 if Etype (E_Id) = Any_Type then
5529 Set_Is_Ada_2012_Only (Entity (E_Id));
5532 Check_Arg_Count (0);
5534 -- For Ada_2012 we unconditionally enforce the documented
5535 -- configuration pragma placement, since we do not want to
5536 -- tolerate mixed modes in a unit involving Ada 2012. That
5537 -- would cause real difficulties for those cases where there
5538 -- are incompatibilities between Ada 95 and Ada 2012. We could
5539 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5541 Check_Valid_Configuration_Pragma;
5543 -- Now set Ada 2012 mode
5545 Ada_Version := Ada_2012;
5546 Ada_Version_Explicit := Ada_2012;
5550 ----------------------
5551 -- All_Calls_Remote --
5552 ----------------------
5554 -- pragma All_Calls_Remote [(library_package_NAME)];
5556 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5557 Lib_Entity : Entity_Id;
5560 Check_Ada_83_Warning;
5561 Check_Valid_Library_Unit_Pragma;
5563 if Nkind (N) = N_Null_Statement then
5567 Lib_Entity := Find_Lib_Unit_Name;
5569 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5571 if Present (Lib_Entity)
5572 and then not Debug_Flag_U
5574 if not Is_Remote_Call_Interface (Lib_Entity) then
5575 Error_Pragma ("pragma% only apply to rci unit");
5577 -- Set flag for entity of the library unit
5580 Set_Has_All_Calls_Remote (Lib_Entity);
5584 end All_Calls_Remote;
5590 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
5591 -- ARG ::= NAME | EXPRESSION
5593 -- The first two arguments are by convention intended to refer to an
5594 -- external tool and a tool-specific function. These arguments are
5597 when Pragma_Annotate => Annotate : begin
5599 Check_At_Least_N_Arguments (1);
5600 Check_Arg_Is_Identifier (Arg1);
5601 Check_No_Identifiers;
5609 -- Second unanalyzed parameter is optional
5615 while Present (Arg) loop
5616 Exp := Expression (Arg);
5619 if Is_Entity_Name (Exp) then
5622 -- For string literals, we assume Standard_String as the
5623 -- type, unless the string contains wide or wide_wide
5626 elsif Nkind (Exp) = N_String_Literal then
5627 if Has_Wide_Wide_Character (Exp) then
5628 Resolve (Exp, Standard_Wide_Wide_String);
5629 elsif Has_Wide_Character (Exp) then
5630 Resolve (Exp, Standard_Wide_String);
5632 Resolve (Exp, Standard_String);
5635 elsif Is_Overloaded (Exp) then
5637 ("ambiguous argument for pragma%", Exp);
5653 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5654 -- [, [Message =>] Static_String_EXPRESSION]);
5656 when Pragma_Assert => Assert : declare
5662 Check_At_Least_N_Arguments (1);
5663 Check_At_Most_N_Arguments (2);
5664 Check_Arg_Order ((Name_Check, Name_Message));
5665 Check_Optional_Identifier (Arg1, Name_Check);
5667 -- We treat pragma Assert as equivalent to:
5669 -- pragma Check (Assertion, condition [, msg]);
5671 -- So rewrite pragma in this manner, and analyze the result
5673 Expr := Get_Pragma_Arg (Arg1);
5675 Make_Pragma_Argument_Association (Loc,
5677 Make_Identifier (Loc,
5678 Chars => Name_Assertion)),
5680 Make_Pragma_Argument_Association (Sloc (Expr),
5681 Expression => Expr));
5683 if Arg_Count > 1 then
5684 Check_Optional_Identifier (Arg2, Name_Message);
5685 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5686 Append_To (Newa, Relocate_Node (Arg2));
5691 Chars => Name_Check,
5692 Pragma_Argument_Associations => Newa));
5696 ----------------------
5697 -- Assertion_Policy --
5698 ----------------------
5700 -- pragma Assertion_Policy (Check | Ignore)
5702 when Pragma_Assertion_Policy => Assertion_Policy : declare
5707 Check_Valid_Configuration_Pragma;
5708 Check_Arg_Count (1);
5709 Check_No_Identifiers;
5710 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5712 -- We treat pragma Assertion_Policy as equivalent to:
5714 -- pragma Check_Policy (Assertion, policy)
5716 -- So rewrite the pragma in that manner and link on to the chain
5717 -- of Check_Policy pragmas, marking the pragma as analyzed.
5719 Policy := Get_Pragma_Arg (Arg1);
5723 Chars => Name_Check_Policy,
5725 Pragma_Argument_Associations => New_List (
5726 Make_Pragma_Argument_Association (Loc,
5728 Make_Identifier (Loc,
5729 Chars => Name_Assertion)),
5731 Make_Pragma_Argument_Association (Loc,
5733 Make_Identifier (Sloc (Policy),
5734 Chars => Chars (Policy))))));
5737 Set_Next_Pragma (N, Opt.Check_Policy_List);
5738 Opt.Check_Policy_List := N;
5739 end Assertion_Policy;
5741 ------------------------------
5742 -- Assume_No_Invalid_Values --
5743 ------------------------------
5745 -- pragma Assume_No_Invalid_Values (On | Off);
5747 when Pragma_Assume_No_Invalid_Values =>
5749 Check_Valid_Configuration_Pragma;
5750 Check_Arg_Count (1);
5751 Check_No_Identifiers;
5752 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5754 if Chars (Expression (Arg1)) = Name_On then
5755 Assume_No_Invalid_Values := True;
5757 Assume_No_Invalid_Values := False;
5764 -- pragma AST_Entry (entry_IDENTIFIER);
5766 when Pragma_AST_Entry => AST_Entry : declare
5772 Check_Arg_Count (1);
5773 Check_No_Identifiers;
5774 Check_Arg_Is_Local_Name (Arg1);
5775 Ent := Entity (Expression (Arg1));
5777 -- Note: the implementation of the AST_Entry pragma could handle
5778 -- the entry family case fine, but for now we are consistent with
5779 -- the DEC rules, and do not allow the pragma, which of course
5780 -- has the effect of also forbidding the attribute.
5782 if Ekind (Ent) /= E_Entry then
5784 ("pragma% argument must be simple entry name", Arg1);
5786 elsif Is_AST_Entry (Ent) then
5788 ("duplicate % pragma for entry", Arg1);
5790 elsif Has_Homonym (Ent) then
5792 ("pragma% argument cannot specify overloaded entry", Arg1);
5796 FF : constant Entity_Id := First_Formal (Ent);
5799 if Present (FF) then
5800 if Present (Next_Formal (FF)) then
5802 ("entry for pragma% can have only one argument",
5805 elsif Parameter_Mode (FF) /= E_In_Parameter then
5807 ("entry parameter for pragma% must have mode IN",
5813 Set_Is_AST_Entry (Ent);
5821 -- pragma Asynchronous (LOCAL_NAME);
5823 when Pragma_Asynchronous => Asynchronous : declare
5831 procedure Process_Async_Pragma;
5832 -- Common processing for procedure and access-to-procedure case
5834 --------------------------
5835 -- Process_Async_Pragma --
5836 --------------------------
5838 procedure Process_Async_Pragma is
5841 Set_Is_Asynchronous (Nm);
5845 -- The formals should be of mode IN (RM E.4.1(6))
5848 while Present (S) loop
5849 Formal := Defining_Identifier (S);
5851 if Nkind (Formal) = N_Defining_Identifier
5852 and then Ekind (Formal) /= E_In_Parameter
5855 ("pragma% procedure can only have IN parameter",
5862 Set_Is_Asynchronous (Nm);
5863 end Process_Async_Pragma;
5865 -- Start of processing for pragma Asynchronous
5868 Check_Ada_83_Warning;
5869 Check_No_Identifiers;
5870 Check_Arg_Count (1);
5871 Check_Arg_Is_Local_Name (Arg1);
5873 if Debug_Flag_U then
5877 C_Ent := Cunit_Entity (Current_Sem_Unit);
5878 Analyze (Expression (Arg1));
5879 Nm := Entity (Expression (Arg1));
5881 if not Is_Remote_Call_Interface (C_Ent)
5882 and then not Is_Remote_Types (C_Ent)
5884 -- This pragma should only appear in an RCI or Remote Types
5885 -- unit (RM E.4.1(4)).
5888 ("pragma% not in Remote_Call_Interface or " &
5889 "Remote_Types unit");
5892 if Ekind (Nm) = E_Procedure
5893 and then Nkind (Parent (Nm)) = N_Procedure_Specification
5895 if not Is_Remote_Call_Interface (Nm) then
5897 ("pragma% cannot be applied on non-remote procedure",
5901 L := Parameter_Specifications (Parent (Nm));
5902 Process_Async_Pragma;
5905 elsif Ekind (Nm) = E_Function then
5907 ("pragma% cannot be applied to function", Arg1);
5909 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5911 if Is_Record_Type (Nm) then
5913 -- A record type that is the Equivalent_Type for a remote
5914 -- access-to-subprogram type.
5916 N := Declaration_Node (Corresponding_Remote_Type (Nm));
5919 -- A non-expanded RAS type (distribution is not enabled)
5921 N := Declaration_Node (Nm);
5924 if Nkind (N) = N_Full_Type_Declaration
5925 and then Nkind (Type_Definition (N)) =
5926 N_Access_Procedure_Definition
5928 L := Parameter_Specifications (Type_Definition (N));
5929 Process_Async_Pragma;
5931 if Is_Asynchronous (Nm)
5932 and then Expander_Active
5933 and then Get_PCS_Name /= Name_No_DSA
5935 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5940 ("pragma% cannot reference access-to-function type",
5944 -- Only other possibility is Access-to-class-wide type
5946 elsif Is_Access_Type (Nm)
5947 and then Is_Class_Wide_Type (Designated_Type (Nm))
5949 Check_First_Subtype (Arg1);
5950 Set_Is_Asynchronous (Nm);
5951 if Expander_Active then
5952 RACW_Type_Is_Asynchronous (Nm);
5956 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5964 -- pragma Atomic (LOCAL_NAME);
5966 when Pragma_Atomic =>
5967 Process_Atomic_Shared_Volatile;
5969 -----------------------
5970 -- Atomic_Components --
5971 -----------------------
5973 -- pragma Atomic_Components (array_LOCAL_NAME);
5975 -- This processing is shared by Volatile_Components
5977 when Pragma_Atomic_Components |
5978 Pragma_Volatile_Components =>
5980 Atomic_Components : declare
5987 Check_Ada_83_Warning;
5988 Check_No_Identifiers;
5989 Check_Arg_Count (1);
5990 Check_Arg_Is_Local_Name (Arg1);
5991 E_Id := Expression (Arg1);
5993 if Etype (E_Id) = Any_Type then
5999 Check_Duplicate_Pragma (E);
6001 if Rep_Item_Too_Early (E, N)
6003 Rep_Item_Too_Late (E, N)
6008 D := Declaration_Node (E);
6011 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6013 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6014 and then Nkind (D) = N_Object_Declaration
6015 and then Nkind (Object_Definition (D)) =
6016 N_Constrained_Array_Definition)
6018 -- The flag is set on the object, or on the base type
6020 if Nkind (D) /= N_Object_Declaration then
6024 Set_Has_Volatile_Components (E);
6026 if Prag_Id = Pragma_Atomic_Components then
6027 Set_Has_Atomic_Components (E);
6031 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6033 end Atomic_Components;
6035 --------------------
6036 -- Attach_Handler --
6037 --------------------
6039 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6041 when Pragma_Attach_Handler =>
6042 Check_Ada_83_Warning;
6043 Check_No_Identifiers;
6044 Check_Arg_Count (2);
6046 if No_Run_Time_Mode then
6047 Error_Msg_CRT ("Attach_Handler pragma", N);
6049 Check_Interrupt_Or_Attach_Handler;
6051 -- The expression that designates the attribute may
6052 -- depend on a discriminant, and is therefore a per-
6053 -- object expression, to be expanded in the init proc.
6054 -- If expansion is enabled, perform semantic checks
6057 if Expander_Active then
6059 Temp : constant Node_Id :=
6060 New_Copy_Tree (Expression (Arg2));
6062 Set_Parent (Temp, N);
6063 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6067 Analyze (Expression (Arg2));
6068 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
6071 Process_Interrupt_Or_Attach_Handler;
6074 --------------------
6075 -- C_Pass_By_Copy --
6076 --------------------
6078 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6080 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6086 Check_Valid_Configuration_Pragma;
6087 Check_Arg_Count (1);
6088 Check_Optional_Identifier (Arg1, "max_size");
6090 Arg := Expression (Arg1);
6091 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6093 Val := Expr_Value (Arg);
6097 ("maximum size for pragma% must be positive", Arg1);
6099 elsif UI_Is_In_Int_Range (Val) then
6100 Default_C_Record_Mechanism := UI_To_Int (Val);
6102 -- If a giant value is given, Int'Last will do well enough.
6103 -- If sometime someone complains that a record larger than
6104 -- two gigabytes is not copied, we will worry about it then!
6107 Default_C_Record_Mechanism := Mechanism_Type'Last;
6115 -- pragma Check ([Name =>] Identifier,
6116 -- [Check =>] Boolean_Expression
6117 -- [,[Message =>] String_Expression]);
6119 when Pragma_Check => Check : declare
6124 -- Set True if category of assertions referenced by Name enabled
6128 Check_At_Least_N_Arguments (2);
6129 Check_At_Most_N_Arguments (3);
6130 Check_Optional_Identifier (Arg1, Name_Name);
6131 Check_Optional_Identifier (Arg2, Name_Check);
6133 if Arg_Count = 3 then
6134 Check_Optional_Identifier (Arg3, Name_Message);
6135 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6138 Check_Arg_Is_Identifier (Arg1);
6140 -- Indicate if pragma is enabled. The Original_Node reference here
6141 -- is to deal with pragma Assert rewritten as a Check pragma.
6143 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6146 Set_Pragma_Enabled (N);
6147 Set_Pragma_Enabled (Original_Node (N));
6148 Set_SCO_Pragma_Enabled (Loc);
6151 -- If expansion is active and the check is not enabled then we
6152 -- rewrite the Check as:
6154 -- if False and then condition then
6158 -- The reason we do this rewriting during semantic analysis rather
6159 -- than as part of normal expansion is that we cannot analyze and
6160 -- expand the code for the boolean expression directly, or it may
6161 -- cause insertion of actions that would escape the attempt to
6162 -- suppress the check code.
6164 -- Note that the Sloc for the if statement corresponds to the
6165 -- argument condition, not the pragma itself. The reason for this
6166 -- is that we may generate a warning if the condition is False at
6167 -- compile time, and we do not want to delete this warning when we
6168 -- delete the if statement.
6170 Expr := Expression (Arg2);
6172 if Expander_Active and then not Check_On then
6173 Eloc := Sloc (Expr);
6176 Make_If_Statement (Eloc,
6178 Make_And_Then (Eloc,
6179 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6180 Right_Opnd => Expr),
6181 Then_Statements => New_List (
6182 Make_Null_Statement (Eloc))));
6189 Analyze_And_Resolve (Expr, Any_Boolean);
6197 -- pragma Check_Name (check_IDENTIFIER);
6199 when Pragma_Check_Name =>
6200 Check_No_Identifiers;
6202 Check_Valid_Configuration_Pragma;
6203 Check_Arg_Count (1);
6204 Check_Arg_Is_Identifier (Arg1);
6207 Nam : constant Name_Id := Chars (Expression (Arg1));
6210 for J in Check_Names.First .. Check_Names.Last loop
6211 if Check_Names.Table (J) = Nam then
6216 Check_Names.Append (Nam);
6223 -- pragma Check_Policy (
6224 -- [Name =>] IDENTIFIER,
6225 -- [Policy =>] POLICY_IDENTIFIER);
6227 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6229 -- Note: this is a configuration pragma, but it is allowed to appear
6232 when Pragma_Check_Policy =>
6234 Check_Arg_Count (2);
6235 Check_Optional_Identifier (Arg1, Name_Name);
6236 Check_Optional_Identifier (Arg2, Name_Policy);
6238 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6240 -- A Check_Policy pragma can appear either as a configuration
6241 -- pragma, or in a declarative part or a package spec (see RM
6242 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6243 -- followed for Check_Policy).
6245 if not Is_Configuration_Pragma then
6246 Check_Is_In_Decl_Part_Or_Package_Spec;
6249 Set_Next_Pragma (N, Opt.Check_Policy_List);
6250 Opt.Check_Policy_List := N;
6252 ---------------------
6253 -- CIL_Constructor --
6254 ---------------------
6256 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6258 -- Processing for this pragma is shared with Java_Constructor
6264 -- pragma Comment (static_string_EXPRESSION)
6266 -- Processing for pragma Comment shares the circuitry for pragma
6267 -- Ident. The only differences are that Ident enforces a limit of 31
6268 -- characters on its argument, and also enforces limitations on
6269 -- placement for DEC compatibility. Pragma Comment shares neither of
6270 -- these restrictions.
6276 -- pragma Common_Object (
6277 -- [Internal =>] LOCAL_NAME
6278 -- [, [External =>] EXTERNAL_SYMBOL]
6279 -- [, [Size =>] EXTERNAL_SYMBOL]);
6281 -- Processing for this pragma is shared with Psect_Object
6283 ------------------------
6284 -- Compile_Time_Error --
6285 ------------------------
6287 -- pragma Compile_Time_Error
6288 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6290 when Pragma_Compile_Time_Error =>
6292 Process_Compile_Time_Warning_Or_Error;
6294 --------------------------
6295 -- Compile_Time_Warning --
6296 --------------------------
6298 -- pragma Compile_Time_Warning
6299 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6301 when Pragma_Compile_Time_Warning =>
6303 Process_Compile_Time_Warning_Or_Error;
6309 when Pragma_Compiler_Unit =>
6311 Check_Arg_Count (0);
6312 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6314 -----------------------------
6315 -- Complete_Representation --
6316 -----------------------------
6318 -- pragma Complete_Representation;
6320 when Pragma_Complete_Representation =>
6322 Check_Arg_Count (0);
6324 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6326 ("pragma & must appear within record representation clause");
6329 ----------------------------
6330 -- Complex_Representation --
6331 ----------------------------
6333 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6335 when Pragma_Complex_Representation => Complex_Representation : declare
6342 Check_Arg_Count (1);
6343 Check_Optional_Identifier (Arg1, Name_Entity);
6344 Check_Arg_Is_Local_Name (Arg1);
6345 E_Id := Expression (Arg1);
6347 if Etype (E_Id) = Any_Type then
6353 if not Is_Record_Type (E) then
6355 ("argument for pragma% must be record type", Arg1);
6358 Ent := First_Entity (E);
6361 or else No (Next_Entity (Ent))
6362 or else Present (Next_Entity (Next_Entity (Ent)))
6363 or else not Is_Floating_Point_Type (Etype (Ent))
6364 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6367 ("record for pragma% must have two fields of the same "
6368 & "floating-point type", Arg1);
6371 Set_Has_Complex_Representation (Base_Type (E));
6373 -- We need to treat the type has having a non-standard
6374 -- representation, for back-end purposes, even though in
6375 -- general a complex will have the default representation
6376 -- of a record with two real components.
6378 Set_Has_Non_Standard_Rep (Base_Type (E));
6380 end Complex_Representation;
6382 -------------------------
6383 -- Component_Alignment --
6384 -------------------------
6386 -- pragma Component_Alignment (
6387 -- [Form =>] ALIGNMENT_CHOICE
6388 -- [, [Name =>] type_LOCAL_NAME]);
6390 -- ALIGNMENT_CHOICE ::=
6392 -- | Component_Size_4
6396 when Pragma_Component_Alignment => Component_AlignmentP : declare
6397 Args : Args_List (1 .. 2);
6398 Names : constant Name_List (1 .. 2) := (
6402 Form : Node_Id renames Args (1);
6403 Name : Node_Id renames Args (2);
6405 Atype : Component_Alignment_Kind;
6410 Gather_Associations (Names, Args);
6413 Error_Pragma ("missing Form argument for pragma%");
6416 Check_Arg_Is_Identifier (Form);
6418 -- Get proper alignment, note that Default = Component_Size on all
6419 -- machines we have so far, and we want to set this value rather
6420 -- than the default value to indicate that it has been explicitly
6421 -- set (and thus will not get overridden by the default component
6422 -- alignment for the current scope)
6424 if Chars (Form) = Name_Component_Size then
6425 Atype := Calign_Component_Size;
6427 elsif Chars (Form) = Name_Component_Size_4 then
6428 Atype := Calign_Component_Size_4;
6430 elsif Chars (Form) = Name_Default then
6431 Atype := Calign_Component_Size;
6433 elsif Chars (Form) = Name_Storage_Unit then
6434 Atype := Calign_Storage_Unit;
6438 ("invalid Form parameter for pragma%", Form);
6441 -- Case with no name, supplied, affects scope table entry
6445 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6447 -- Case of name supplied
6450 Check_Arg_Is_Local_Name (Name);
6452 Typ := Entity (Name);
6455 or else Rep_Item_Too_Early (Typ, N)
6459 Typ := Underlying_Type (Typ);
6462 if not Is_Record_Type (Typ)
6463 and then not Is_Array_Type (Typ)
6466 ("Name parameter of pragma% must identify record or " &
6467 "array type", Name);
6470 -- An explicit Component_Alignment pragma overrides an
6471 -- implicit pragma Pack, but not an explicit one.
6473 if not Has_Pragma_Pack (Base_Type (Typ)) then
6474 Set_Is_Packed (Base_Type (Typ), False);
6475 Set_Component_Alignment (Base_Type (Typ), Atype);
6478 end Component_AlignmentP;
6484 -- pragma Controlled (first_subtype_LOCAL_NAME);
6486 when Pragma_Controlled => Controlled : declare
6490 Check_No_Identifiers;
6491 Check_Arg_Count (1);
6492 Check_Arg_Is_Local_Name (Arg1);
6493 Arg := Expression (Arg1);
6495 if not Is_Entity_Name (Arg)
6496 or else not Is_Access_Type (Entity (Arg))
6498 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6500 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6508 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6509 -- [Entity =>] LOCAL_NAME);
6511 when Pragma_Convention => Convention : declare
6514 pragma Warnings (Off, C);
6515 pragma Warnings (Off, E);
6517 Check_Arg_Order ((Name_Convention, Name_Entity));
6518 Check_Ada_83_Warning;
6519 Check_Arg_Count (2);
6520 Process_Convention (C, E);
6523 ---------------------------
6524 -- Convention_Identifier --
6525 ---------------------------
6527 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6528 -- [Convention =>] convention_IDENTIFIER);
6530 when Pragma_Convention_Identifier => Convention_Identifier : declare
6536 Check_Arg_Order ((Name_Name, Name_Convention));
6537 Check_Arg_Count (2);
6538 Check_Optional_Identifier (Arg1, Name_Name);
6539 Check_Optional_Identifier (Arg2, Name_Convention);
6540 Check_Arg_Is_Identifier (Arg1);
6541 Check_Arg_Is_Identifier (Arg2);
6542 Idnam := Chars (Expression (Arg1));
6543 Cname := Chars (Expression (Arg2));
6545 if Is_Convention_Name (Cname) then
6546 Record_Convention_Identifier
6547 (Idnam, Get_Convention_Id (Cname));
6550 ("second arg for % pragma must be convention", Arg2);
6552 end Convention_Identifier;
6558 -- pragma CPP_Class ([Entity =>] local_NAME)
6560 when Pragma_CPP_Class => CPP_Class : declare
6565 if Warn_On_Obsolescent_Feature then
6567 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6568 " by pragma import?", N);
6572 Check_Arg_Count (1);
6573 Check_Optional_Identifier (Arg1, Name_Entity);
6574 Check_Arg_Is_Local_Name (Arg1);
6576 Arg := Expression (Arg1);
6579 if Etype (Arg) = Any_Type then
6583 if not Is_Entity_Name (Arg)
6584 or else not Is_Type (Entity (Arg))
6586 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6589 Typ := Entity (Arg);
6591 if not Is_Tagged_Type (Typ) then
6592 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6595 -- Types treated as CPP classes are treated as limited, but we
6596 -- don't require them to be declared this way. A warning is issued
6597 -- to encourage the user to declare them as limited. This is not
6598 -- an error, for compatibility reasons, because these types have
6599 -- been supported this way for some time.
6601 if not Is_Limited_Type (Typ) then
6603 ("imported 'C'P'P type should be " &
6604 "explicitly declared limited?",
6605 Get_Pragma_Arg (Arg1));
6607 ("\type will be considered limited",
6608 Get_Pragma_Arg (Arg1));
6611 Set_Is_CPP_Class (Typ);
6612 Set_Is_Limited_Record (Typ);
6613 Set_Convention (Typ, Convention_CPP);
6615 -- Imported CPP types must not have discriminants (because C++
6616 -- classes do not have discriminants).
6618 if Has_Discriminants (Typ) then
6620 ("imported 'C'P'P type cannot have discriminants",
6621 First (Discriminant_Specifications
6622 (Declaration_Node (Typ))));
6625 -- Components of imported CPP types must not have default
6626 -- expressions because the constructor (if any) is in the
6629 if Is_Incomplete_Or_Private_Type (Typ)
6630 and then No (Underlying_Type (Typ))
6632 -- It should be an error to apply pragma CPP to a private
6633 -- type if the underlying type is not visible (as it is
6634 -- for any representation item). For now, for backward
6635 -- compatibility we do nothing but we cannot check components
6636 -- because they are not available at this stage. All this code
6637 -- will be removed when we cleanup this obsolete GNAT pragma???
6643 Tdef : constant Node_Id :=
6644 Type_Definition (Declaration_Node (Typ));
6649 if Nkind (Tdef) = N_Record_Definition then
6650 Clist := Component_List (Tdef);
6652 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
6653 Clist := Component_List (Record_Extension_Part (Tdef));
6656 if Present (Clist) then
6657 Comp := First (Component_Items (Clist));
6658 while Present (Comp) loop
6659 if Present (Expression (Comp)) then
6661 ("component of imported 'C'P'P type cannot have" &
6662 " default expression", Expression (Comp));
6672 ---------------------
6673 -- CPP_Constructor --
6674 ---------------------
6676 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6677 -- [, [External_Name =>] static_string_EXPRESSION ]
6678 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6680 when Pragma_CPP_Constructor => CPP_Constructor : declare
6684 Tag_Typ : Entity_Id;
6688 Check_At_Least_N_Arguments (1);
6689 Check_At_Most_N_Arguments (3);
6690 Check_Optional_Identifier (Arg1, Name_Entity);
6691 Check_Arg_Is_Local_Name (Arg1);
6693 Id := Expression (Arg1);
6694 Find_Program_Unit_Name (Id);
6696 -- If we did not find the name, we are done
6698 if Etype (Id) = Any_Type then
6702 Def_Id := Entity (Id);
6704 -- Check if already defined as constructor
6706 if Is_Constructor (Def_Id) then
6708 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
6712 if Ekind (Def_Id) = E_Function
6713 and then (Is_CPP_Class (Etype (Def_Id))
6714 or else (Is_Class_Wide_Type (Etype (Def_Id))
6716 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
6718 if Arg_Count >= 2 then
6719 Set_Imported (Def_Id);
6720 Set_Is_Public (Def_Id);
6721 Process_Interface_Name (Def_Id, Arg2, Arg3);
6724 Set_Has_Completion (Def_Id);
6725 Set_Is_Constructor (Def_Id);
6727 -- Imported C++ constructors are not dispatching primitives
6728 -- because in C++ they don't have a dispatch table slot.
6729 -- However, in Ada the constructor has the profile of a
6730 -- function that returns a tagged type and therefore it has
6731 -- been treated as a primitive operation during semantic
6732 -- analysis. We now remove it from the list of primitive
6733 -- operations of the type.
6735 if Is_Tagged_Type (Etype (Def_Id))
6736 and then not Is_Class_Wide_Type (Etype (Def_Id))
6738 pragma Assert (Is_Dispatching_Operation (Def_Id));
6739 Tag_Typ := Etype (Def_Id);
6741 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
6742 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
6746 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
6747 Set_Is_Dispatching_Operation (Def_Id, False);
6750 -- For backward compatibility, if the constructor returns a
6751 -- class wide type, and we internally change the return type to
6752 -- the corresponding root type.
6754 if Is_Class_Wide_Type (Etype (Def_Id)) then
6755 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
6759 ("pragma% requires function returning a 'C'P'P_Class type",
6762 end CPP_Constructor;
6768 when Pragma_CPP_Virtual => CPP_Virtual : declare
6772 if Warn_On_Obsolescent_Feature then
6774 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6783 when Pragma_CPP_Vtable => CPP_Vtable : declare
6787 if Warn_On_Obsolescent_Feature then
6789 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6798 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6800 when Pragma_Debug => Debug : declare
6808 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6811 if Arg_Count = 2 then
6814 Left_Opnd => Relocate_Node (Cond),
6815 Right_Opnd => Expression (Arg1));
6818 -- Rewrite into a conditional with an appropriate condition. We
6819 -- wrap the procedure call in a block so that overhead from e.g.
6820 -- use of the secondary stack does not generate execution overhead
6821 -- for suppressed conditions.
6823 Rewrite (N, Make_Implicit_If_Statement (N,
6825 Then_Statements => New_List (
6826 Make_Block_Statement (Loc,
6827 Handled_Statement_Sequence =>
6828 Make_Handled_Sequence_Of_Statements (Loc,
6829 Statements => New_List (
6830 Relocate_Node (Debug_Statement (N))))))));
6838 -- pragma Debug_Policy (Check | Ignore)
6840 when Pragma_Debug_Policy =>
6842 Check_Arg_Count (1);
6843 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6844 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
6846 ---------------------
6847 -- Detect_Blocking --
6848 ---------------------
6850 -- pragma Detect_Blocking;
6852 when Pragma_Detect_Blocking =>
6854 Check_Arg_Count (0);
6855 Check_Valid_Configuration_Pragma;
6856 Detect_Blocking := True;
6862 when Pragma_Dimension =>
6864 Check_Arg_Count (4);
6865 Check_No_Identifiers;
6866 Check_Arg_Is_Local_Name (Arg1);
6868 if not Is_Type (Arg1) then
6869 Error_Pragma ("first argument for pragma% must be subtype");
6872 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
6873 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
6874 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
6880 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
6882 when Pragma_Discard_Names => Discard_Names : declare
6887 Check_Ada_83_Warning;
6889 -- Deal with configuration pragma case
6891 if Arg_Count = 0 and then Is_Configuration_Pragma then
6892 Global_Discard_Names := True;
6895 -- Otherwise, check correct appropriate context
6898 Check_Is_In_Decl_Part_Or_Package_Spec;
6900 if Arg_Count = 0 then
6902 -- If there is no parameter, then from now on this pragma
6903 -- applies to any enumeration, exception or tagged type
6904 -- defined in the current declarative part, and recursively
6905 -- to any nested scope.
6907 Set_Discard_Names (Current_Scope);
6911 Check_Arg_Count (1);
6912 Check_Optional_Identifier (Arg1, Name_On);
6913 Check_Arg_Is_Local_Name (Arg1);
6915 E_Id := Expression (Arg1);
6917 if Etype (E_Id) = Any_Type then
6923 if (Is_First_Subtype (E)
6925 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
6926 or else Ekind (E) = E_Exception
6928 Set_Discard_Names (E);
6931 ("inappropriate entity for pragma%", Arg1);
6942 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
6944 when Pragma_Elaborate => Elaborate : declare
6949 -- Pragma must be in context items list of a compilation unit
6951 if not Is_In_Context_Clause then
6955 -- Must be at least one argument
6957 if Arg_Count = 0 then
6958 Error_Pragma ("pragma% requires at least one argument");
6961 -- In Ada 83 mode, there can be no items following it in the
6962 -- context list except other pragmas and implicit with clauses
6963 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
6964 -- placement rule does not apply.
6966 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
6968 while Present (Citem) loop
6969 if Nkind (Citem) = N_Pragma
6970 or else (Nkind (Citem) = N_With_Clause
6971 and then Implicit_With (Citem))
6976 ("(Ada 83) pragma% must be at end of context clause");
6983 -- Finally, the arguments must all be units mentioned in a with
6984 -- clause in the same context clause. Note we already checked (in
6985 -- Par.Prag) that the arguments are all identifiers or selected
6989 Outer : while Present (Arg) loop
6990 Citem := First (List_Containing (N));
6991 Inner : while Citem /= N loop
6992 if Nkind (Citem) = N_With_Clause
6993 and then Same_Name (Name (Citem), Expression (Arg))
6995 Set_Elaborate_Present (Citem, True);
6996 Set_Unit_Name (Expression (Arg), Name (Citem));
6998 -- With the pragma present, elaboration calls on
6999 -- subprograms from the named unit need no further
7000 -- checks, as long as the pragma appears in the current
7001 -- compilation unit. If the pragma appears in some unit
7002 -- in the context, there might still be a need for an
7003 -- Elaborate_All_Desirable from the current compilation
7004 -- to the named unit, so we keep the check enabled.
7006 if In_Extended_Main_Source_Unit (N) then
7007 Set_Suppress_Elaboration_Warnings
7008 (Entity (Name (Citem)));
7019 ("argument of pragma% is not with'ed unit", Arg);
7025 -- Give a warning if operating in static mode with -gnatwl
7026 -- (elaboration warnings enabled) switch set.
7028 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7030 ("?use of pragma Elaborate may not be safe", N);
7032 ("?use pragma Elaborate_All instead if possible", N);
7040 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7042 when Pragma_Elaborate_All => Elaborate_All : declare
7047 Check_Ada_83_Warning;
7049 -- Pragma must be in context items list of a compilation unit
7051 if not Is_In_Context_Clause then
7055 -- Must be at least one argument
7057 if Arg_Count = 0 then
7058 Error_Pragma ("pragma% requires at least one argument");
7061 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7062 -- have to appear at the end of the context clause, but may
7063 -- appear mixed in with other items, even in Ada 83 mode.
7065 -- Final check: the arguments must all be units mentioned in
7066 -- a with clause in the same context clause. Note that we
7067 -- already checked (in Par.Prag) that all the arguments are
7068 -- either identifiers or selected components.
7071 Outr : while Present (Arg) loop
7072 Citem := First (List_Containing (N));
7073 Innr : while Citem /= N loop
7074 if Nkind (Citem) = N_With_Clause
7075 and then Same_Name (Name (Citem), Expression (Arg))
7077 Set_Elaborate_All_Present (Citem, True);
7078 Set_Unit_Name (Expression (Arg), Name (Citem));
7080 -- Suppress warnings and elaboration checks on the named
7081 -- unit if the pragma is in the current compilation, as
7082 -- for pragma Elaborate.
7084 if In_Extended_Main_Source_Unit (N) then
7085 Set_Suppress_Elaboration_Warnings
7086 (Entity (Name (Citem)));
7095 Set_Error_Posted (N);
7097 ("argument of pragma% is not with'ed unit", Arg);
7104 --------------------
7105 -- Elaborate_Body --
7106 --------------------
7108 -- pragma Elaborate_Body [( library_unit_NAME )];
7110 when Pragma_Elaborate_Body => Elaborate_Body : declare
7111 Cunit_Node : Node_Id;
7112 Cunit_Ent : Entity_Id;
7115 Check_Ada_83_Warning;
7116 Check_Valid_Library_Unit_Pragma;
7118 if Nkind (N) = N_Null_Statement then
7122 Cunit_Node := Cunit (Current_Sem_Unit);
7123 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7125 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7128 Error_Pragma ("pragma% must refer to a spec, not a body");
7130 Set_Body_Required (Cunit_Node, True);
7131 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7133 -- If we are in dynamic elaboration mode, then we suppress
7134 -- elaboration warnings for the unit, since it is definitely
7135 -- fine NOT to do dynamic checks at the first level (and such
7136 -- checks will be suppressed because no elaboration boolean
7137 -- is created for Elaborate_Body packages).
7139 -- But in the static model of elaboration, Elaborate_Body is
7140 -- definitely NOT good enough to ensure elaboration safety on
7141 -- its own, since the body may WITH other units that are not
7142 -- safe from an elaboration point of view, so a client must
7143 -- still do an Elaborate_All on such units.
7145 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7146 -- Elaborate_Body always suppressed elab warnings.
7148 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7149 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7154 ------------------------
7155 -- Elaboration_Checks --
7156 ------------------------
7158 -- pragma Elaboration_Checks (Static | Dynamic);
7160 when Pragma_Elaboration_Checks =>
7162 Check_Arg_Count (1);
7163 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7164 Dynamic_Elaboration_Checks :=
7165 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7171 -- pragma Eliminate (
7172 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7173 -- [,[Entity =>] IDENTIFIER |
7174 -- SELECTED_COMPONENT |
7176 -- [, OVERLOADING_RESOLUTION]);
7178 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7181 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7184 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7186 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7187 -- Result_Type => result_SUBTYPE_NAME]
7189 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7190 -- SUBTYPE_NAME ::= STRING_LITERAL
7192 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7193 -- SOURCE_TRACE ::= STRING_LITERAL
7195 when Pragma_Eliminate => Eliminate : declare
7196 Args : Args_List (1 .. 5);
7197 Names : constant Name_List (1 .. 5) := (
7200 Name_Parameter_Types,
7202 Name_Source_Location);
7204 Unit_Name : Node_Id renames Args (1);
7205 Entity : Node_Id renames Args (2);
7206 Parameter_Types : Node_Id renames Args (3);
7207 Result_Type : Node_Id renames Args (4);
7208 Source_Location : Node_Id renames Args (5);
7212 Check_Valid_Configuration_Pragma;
7213 Gather_Associations (Names, Args);
7215 if No (Unit_Name) then
7216 Error_Pragma ("missing Unit_Name argument for pragma%");
7220 and then (Present (Parameter_Types)
7222 Present (Result_Type)
7224 Present (Source_Location))
7226 Error_Pragma ("missing Entity argument for pragma%");
7229 if (Present (Parameter_Types)
7231 Present (Result_Type))
7233 Present (Source_Location)
7236 ("parameter profile and source location cannot " &
7237 "be used together in pragma%");
7240 Process_Eliminate_Pragma
7254 -- [ Convention =>] convention_IDENTIFIER,
7255 -- [ Entity =>] local_NAME
7256 -- [, [External_Name =>] static_string_EXPRESSION ]
7257 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7259 when Pragma_Export => Export : declare
7263 pragma Warnings (Off, C);
7266 Check_Ada_83_Warning;
7272 Check_At_Least_N_Arguments (2);
7273 Check_At_Most_N_Arguments (4);
7274 Process_Convention (C, Def_Id);
7276 if Ekind (Def_Id) /= E_Constant then
7277 Note_Possible_Modification (Expression (Arg2), Sure => False);
7280 Process_Interface_Name (Def_Id, Arg3, Arg4);
7281 Set_Exported (Def_Id, Arg2);
7283 -- If the entity is a deferred constant, propagate the information
7284 -- to the full view, because gigi elaborates the full view only.
7286 if Ekind (Def_Id) = E_Constant
7287 and then Present (Full_View (Def_Id))
7290 Id2 : constant Entity_Id := Full_View (Def_Id);
7292 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7293 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7294 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7299 ----------------------
7300 -- Export_Exception --
7301 ----------------------
7303 -- pragma Export_Exception (
7304 -- [Internal =>] LOCAL_NAME
7305 -- [, [External =>] EXTERNAL_SYMBOL]
7306 -- [, [Form =>] Ada | VMS]
7307 -- [, [Code =>] static_integer_EXPRESSION]);
7309 when Pragma_Export_Exception => Export_Exception : declare
7310 Args : Args_List (1 .. 4);
7311 Names : constant Name_List (1 .. 4) := (
7317 Internal : Node_Id renames Args (1);
7318 External : Node_Id renames Args (2);
7319 Form : Node_Id renames Args (3);
7320 Code : Node_Id renames Args (4);
7325 if Inside_A_Generic then
7326 Error_Pragma ("pragma% cannot be used for generic entities");
7329 Gather_Associations (Names, Args);
7330 Process_Extended_Import_Export_Exception_Pragma (
7331 Arg_Internal => Internal,
7332 Arg_External => External,
7336 if not Is_VMS_Exception (Entity (Internal)) then
7337 Set_Exported (Entity (Internal), Internal);
7339 end Export_Exception;
7341 ---------------------
7342 -- Export_Function --
7343 ---------------------
7345 -- pragma Export_Function (
7346 -- [Internal =>] LOCAL_NAME
7347 -- [, [External =>] EXTERNAL_SYMBOL]
7348 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7349 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7350 -- [, [Mechanism =>] MECHANISM]
7351 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7353 -- EXTERNAL_SYMBOL ::=
7355 -- | static_string_EXPRESSION
7357 -- PARAMETER_TYPES ::=
7359 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7361 -- TYPE_DESIGNATOR ::=
7363 -- | subtype_Name ' Access
7367 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7369 -- MECHANISM_ASSOCIATION ::=
7370 -- [formal_parameter_NAME =>] MECHANISM_NAME
7372 -- MECHANISM_NAME ::=
7375 -- | Descriptor [([Class =>] CLASS_NAME)]
7377 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7379 when Pragma_Export_Function => Export_Function : declare
7380 Args : Args_List (1 .. 6);
7381 Names : constant Name_List (1 .. 6) := (
7384 Name_Parameter_Types,
7387 Name_Result_Mechanism);
7389 Internal : Node_Id renames Args (1);
7390 External : Node_Id renames Args (2);
7391 Parameter_Types : Node_Id renames Args (3);
7392 Result_Type : Node_Id renames Args (4);
7393 Mechanism : Node_Id renames Args (5);
7394 Result_Mechanism : Node_Id renames Args (6);
7398 Gather_Associations (Names, Args);
7399 Process_Extended_Import_Export_Subprogram_Pragma (
7400 Arg_Internal => Internal,
7401 Arg_External => External,
7402 Arg_Parameter_Types => Parameter_Types,
7403 Arg_Result_Type => Result_Type,
7404 Arg_Mechanism => Mechanism,
7405 Arg_Result_Mechanism => Result_Mechanism);
7406 end Export_Function;
7412 -- pragma Export_Object (
7413 -- [Internal =>] LOCAL_NAME
7414 -- [, [External =>] EXTERNAL_SYMBOL]
7415 -- [, [Size =>] EXTERNAL_SYMBOL]);
7417 -- EXTERNAL_SYMBOL ::=
7419 -- | static_string_EXPRESSION
7421 -- PARAMETER_TYPES ::=
7423 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7425 -- TYPE_DESIGNATOR ::=
7427 -- | subtype_Name ' Access
7431 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7433 -- MECHANISM_ASSOCIATION ::=
7434 -- [formal_parameter_NAME =>] MECHANISM_NAME
7436 -- MECHANISM_NAME ::=
7439 -- | Descriptor [([Class =>] CLASS_NAME)]
7441 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7443 when Pragma_Export_Object => Export_Object : declare
7444 Args : Args_List (1 .. 3);
7445 Names : constant Name_List (1 .. 3) := (
7450 Internal : Node_Id renames Args (1);
7451 External : Node_Id renames Args (2);
7452 Size : Node_Id renames Args (3);
7456 Gather_Associations (Names, Args);
7457 Process_Extended_Import_Export_Object_Pragma (
7458 Arg_Internal => Internal,
7459 Arg_External => External,
7463 ----------------------
7464 -- Export_Procedure --
7465 ----------------------
7467 -- pragma Export_Procedure (
7468 -- [Internal =>] LOCAL_NAME
7469 -- [, [External =>] EXTERNAL_SYMBOL]
7470 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7471 -- [, [Mechanism =>] MECHANISM]);
7473 -- EXTERNAL_SYMBOL ::=
7475 -- | static_string_EXPRESSION
7477 -- PARAMETER_TYPES ::=
7479 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7481 -- TYPE_DESIGNATOR ::=
7483 -- | subtype_Name ' Access
7487 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7489 -- MECHANISM_ASSOCIATION ::=
7490 -- [formal_parameter_NAME =>] MECHANISM_NAME
7492 -- MECHANISM_NAME ::=
7495 -- | Descriptor [([Class =>] CLASS_NAME)]
7497 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7499 when Pragma_Export_Procedure => Export_Procedure : declare
7500 Args : Args_List (1 .. 4);
7501 Names : constant Name_List (1 .. 4) := (
7504 Name_Parameter_Types,
7507 Internal : Node_Id renames Args (1);
7508 External : Node_Id renames Args (2);
7509 Parameter_Types : Node_Id renames Args (3);
7510 Mechanism : Node_Id renames Args (4);
7514 Gather_Associations (Names, Args);
7515 Process_Extended_Import_Export_Subprogram_Pragma (
7516 Arg_Internal => Internal,
7517 Arg_External => External,
7518 Arg_Parameter_Types => Parameter_Types,
7519 Arg_Mechanism => Mechanism);
7520 end Export_Procedure;
7526 -- pragma Export_Value (
7527 -- [Value =>] static_integer_EXPRESSION,
7528 -- [Link_Name =>] static_string_EXPRESSION);
7530 when Pragma_Export_Value =>
7532 Check_Arg_Order ((Name_Value, Name_Link_Name));
7533 Check_Arg_Count (2);
7535 Check_Optional_Identifier (Arg1, Name_Value);
7536 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7538 Check_Optional_Identifier (Arg2, Name_Link_Name);
7539 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7541 -----------------------------
7542 -- Export_Valued_Procedure --
7543 -----------------------------
7545 -- pragma Export_Valued_Procedure (
7546 -- [Internal =>] LOCAL_NAME
7547 -- [, [External =>] EXTERNAL_SYMBOL,]
7548 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7549 -- [, [Mechanism =>] MECHANISM]);
7551 -- EXTERNAL_SYMBOL ::=
7553 -- | static_string_EXPRESSION
7555 -- PARAMETER_TYPES ::=
7557 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7559 -- TYPE_DESIGNATOR ::=
7561 -- | subtype_Name ' Access
7565 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7567 -- MECHANISM_ASSOCIATION ::=
7568 -- [formal_parameter_NAME =>] MECHANISM_NAME
7570 -- MECHANISM_NAME ::=
7573 -- | Descriptor [([Class =>] CLASS_NAME)]
7575 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7577 when Pragma_Export_Valued_Procedure =>
7578 Export_Valued_Procedure : declare
7579 Args : Args_List (1 .. 4);
7580 Names : constant Name_List (1 .. 4) := (
7583 Name_Parameter_Types,
7586 Internal : Node_Id renames Args (1);
7587 External : Node_Id renames Args (2);
7588 Parameter_Types : Node_Id renames Args (3);
7589 Mechanism : Node_Id renames Args (4);
7593 Gather_Associations (Names, Args);
7594 Process_Extended_Import_Export_Subprogram_Pragma (
7595 Arg_Internal => Internal,
7596 Arg_External => External,
7597 Arg_Parameter_Types => Parameter_Types,
7598 Arg_Mechanism => Mechanism);
7599 end Export_Valued_Procedure;
7605 -- pragma Extend_System ([Name =>] Identifier);
7607 when Pragma_Extend_System => Extend_System : declare
7610 Check_Valid_Configuration_Pragma;
7611 Check_Arg_Count (1);
7612 Check_Optional_Identifier (Arg1, Name_Name);
7613 Check_Arg_Is_Identifier (Arg1);
7615 Get_Name_String (Chars (Expression (Arg1)));
7618 and then Name_Buffer (1 .. 4) = "aux_"
7620 if Present (System_Extend_Pragma_Arg) then
7621 if Chars (Expression (Arg1)) =
7622 Chars (Expression (System_Extend_Pragma_Arg))
7626 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7627 Error_Pragma ("pragma% conflicts with that #");
7631 System_Extend_Pragma_Arg := Arg1;
7633 if not GNAT_Mode then
7634 System_Extend_Unit := Arg1;
7638 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7642 ------------------------
7643 -- Extensions_Allowed --
7644 ------------------------
7646 -- pragma Extensions_Allowed (ON | OFF);
7648 when Pragma_Extensions_Allowed =>
7650 Check_Arg_Count (1);
7651 Check_No_Identifiers;
7652 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7654 if Chars (Expression (Arg1)) = Name_On then
7655 Extensions_Allowed := True;
7656 Ada_Version := Ada_Version_Type'Last;
7659 Extensions_Allowed := False;
7660 Ada_Version := Ada_Version_Explicit;
7667 -- pragma External (
7668 -- [ Convention =>] convention_IDENTIFIER,
7669 -- [ Entity =>] local_NAME
7670 -- [, [External_Name =>] static_string_EXPRESSION ]
7671 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7673 when Pragma_External => External : declare
7677 pragma Warnings (Off, C);
7686 Check_At_Least_N_Arguments (2);
7687 Check_At_Most_N_Arguments (4);
7688 Process_Convention (C, Def_Id);
7689 Note_Possible_Modification (Expression (Arg2), Sure => False);
7690 Process_Interface_Name (Def_Id, Arg3, Arg4);
7691 Set_Exported (Def_Id, Arg2);
7694 --------------------------
7695 -- External_Name_Casing --
7696 --------------------------
7698 -- pragma External_Name_Casing (
7699 -- UPPERCASE | LOWERCASE
7700 -- [, AS_IS | UPPERCASE | LOWERCASE]);
7702 when Pragma_External_Name_Casing => External_Name_Casing : declare
7705 Check_No_Identifiers;
7707 if Arg_Count = 2 then
7709 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7711 case Chars (Get_Pragma_Arg (Arg2)) is
7713 Opt.External_Name_Exp_Casing := As_Is;
7715 when Name_Uppercase =>
7716 Opt.External_Name_Exp_Casing := Uppercase;
7718 when Name_Lowercase =>
7719 Opt.External_Name_Exp_Casing := Lowercase;
7726 Check_Arg_Count (1);
7729 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7731 case Chars (Get_Pragma_Arg (Arg1)) is
7732 when Name_Uppercase =>
7733 Opt.External_Name_Imp_Casing := Uppercase;
7735 when Name_Lowercase =>
7736 Opt.External_Name_Imp_Casing := Lowercase;
7741 end External_Name_Casing;
7743 --------------------------
7744 -- Favor_Top_Level --
7745 --------------------------
7747 -- pragma Favor_Top_Level (type_NAME);
7749 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7750 Named_Entity : Entity_Id;
7754 Check_No_Identifiers;
7755 Check_Arg_Count (1);
7756 Check_Arg_Is_Local_Name (Arg1);
7757 Named_Entity := Entity (Expression (Arg1));
7759 -- If it's an access-to-subprogram type (in particular, not a
7760 -- subtype), set the flag on that type.
7762 if Is_Access_Subprogram_Type (Named_Entity) then
7763 Set_Can_Use_Internal_Rep (Named_Entity, False);
7765 -- Otherwise it's an error (name denotes the wrong sort of entity)
7769 ("access-to-subprogram type expected", Expression (Arg1));
7771 end Favor_Top_Level;
7777 -- pragma Fast_Math;
7779 when Pragma_Fast_Math =>
7781 Check_No_Identifiers;
7782 Check_Valid_Configuration_Pragma;
7785 ---------------------------
7786 -- Finalize_Storage_Only --
7787 ---------------------------
7789 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7791 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7792 Assoc : constant Node_Id := Arg1;
7793 Type_Id : constant Node_Id := Expression (Assoc);
7798 Check_No_Identifiers;
7799 Check_Arg_Count (1);
7800 Check_Arg_Is_Local_Name (Arg1);
7802 Find_Type (Type_Id);
7803 Typ := Entity (Type_Id);
7806 or else Rep_Item_Too_Early (Typ, N)
7810 Typ := Underlying_Type (Typ);
7813 if not Is_Controlled (Typ) then
7814 Error_Pragma ("pragma% must specify controlled type");
7817 Check_First_Subtype (Arg1);
7819 if Finalize_Storage_Only (Typ) then
7820 Error_Pragma ("duplicate pragma%, only one allowed");
7822 elsif not Rep_Item_Too_Late (Typ, N) then
7823 Set_Finalize_Storage_Only (Base_Type (Typ), True);
7825 end Finalize_Storage;
7827 --------------------------
7828 -- Float_Representation --
7829 --------------------------
7831 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7833 -- FLOAT_REP ::= VAX_Float | IEEE_Float
7835 when Pragma_Float_Representation => Float_Representation : declare
7843 if Arg_Count = 1 then
7844 Check_Valid_Configuration_Pragma;
7846 Check_Arg_Count (2);
7847 Check_Optional_Identifier (Arg2, Name_Entity);
7848 Check_Arg_Is_Local_Name (Arg2);
7851 Check_No_Identifier (Arg1);
7852 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
7854 if not OpenVMS_On_Target then
7855 if Chars (Expression (Arg1)) = Name_VAX_Float then
7857 ("?pragma% ignored (applies only to Open'V'M'S)");
7863 -- One argument case
7865 if Arg_Count = 1 then
7866 if Chars (Expression (Arg1)) = Name_VAX_Float then
7867 if Opt.Float_Format = 'I' then
7868 Error_Pragma ("'I'E'E'E format previously specified");
7871 Opt.Float_Format := 'V';
7874 if Opt.Float_Format = 'V' then
7875 Error_Pragma ("'V'A'X format previously specified");
7878 Opt.Float_Format := 'I';
7881 Set_Standard_Fpt_Formats;
7883 -- Two argument case
7886 Argx := Get_Pragma_Arg (Arg2);
7888 if not Is_Entity_Name (Argx)
7889 or else not Is_Floating_Point_Type (Entity (Argx))
7892 ("second argument of% pragma must be floating-point type",
7896 Ent := Entity (Argx);
7897 Digs := UI_To_Int (Digits_Value (Ent));
7899 -- Two arguments, VAX_Float case
7901 if Chars (Expression (Arg1)) = Name_VAX_Float then
7903 when 6 => Set_F_Float (Ent);
7904 when 9 => Set_D_Float (Ent);
7905 when 15 => Set_G_Float (Ent);
7909 ("wrong digits value, must be 6,9 or 15", Arg2);
7912 -- Two arguments, IEEE_Float case
7916 when 6 => Set_IEEE_Short (Ent);
7917 when 15 => Set_IEEE_Long (Ent);
7921 ("wrong digits value, must be 6 or 15", Arg2);
7925 end Float_Representation;
7931 -- pragma Ident (static_string_EXPRESSION)
7933 -- Note: pragma Comment shares this processing. Pragma Comment is
7934 -- identical to Ident, except that the restriction of the argument to
7935 -- 31 characters and the placement restrictions are not enforced for
7938 when Pragma_Ident | Pragma_Comment => Ident : declare
7943 Check_Arg_Count (1);
7944 Check_No_Identifiers;
7945 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7948 -- For pragma Ident, preserve DEC compatibility by requiring the
7949 -- pragma to appear in a declarative part or package spec.
7951 if Prag_Id = Pragma_Ident then
7952 Check_Is_In_Decl_Part_Or_Package_Spec;
7955 Str := Expr_Value_S (Expression (Arg1));
7962 GP := Parent (Parent (N));
7964 if Nkind_In (GP, N_Package_Declaration,
7965 N_Generic_Package_Declaration)
7970 -- If we have a compilation unit, then record the ident value,
7971 -- checking for improper duplication.
7973 if Nkind (GP) = N_Compilation_Unit then
7974 CS := Ident_String (Current_Sem_Unit);
7976 if Present (CS) then
7978 -- For Ident, we do not permit multiple instances
7980 if Prag_Id = Pragma_Ident then
7981 Error_Pragma ("duplicate% pragma not permitted");
7983 -- For Comment, we concatenate the string, unless we want
7984 -- to preserve the tree structure for ASIS.
7986 elsif not ASIS_Mode then
7987 Start_String (Strval (CS));
7988 Store_String_Char (' ');
7989 Store_String_Chars (Strval (Str));
7990 Set_Strval (CS, End_String);
7994 -- In VMS, the effect of IDENT is achieved by passing
7995 -- --identification=name as a --for-linker switch.
7997 if OpenVMS_On_Target then
8000 ("--for-linker=--identification=");
8001 String_To_Name_Buffer (Strval (Str));
8002 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8004 -- Only the last processed IDENT is saved. The main
8005 -- purpose is so an IDENT associated with a main
8006 -- procedure will be used in preference to an IDENT
8007 -- associated with a with'd package.
8009 Replace_Linker_Option_String
8010 (End_String, "--for-linker=--identification=");
8013 Set_Ident_String (Current_Sem_Unit, Str);
8016 -- For subunits, we just ignore the Ident, since in GNAT these
8017 -- are not separate object files, and hence not separate units
8018 -- in the unit table.
8020 elsif Nkind (GP) = N_Subunit then
8023 -- Otherwise we have a misplaced pragma Ident, but we ignore
8024 -- this if we are in an instantiation, since it comes from
8025 -- a generic, and has no relevance to the instantiation.
8027 elsif Prag_Id = Pragma_Ident then
8028 if Instantiation_Location (Loc) = No_Location then
8029 Error_Pragma ("pragma% only allowed at outer level");
8039 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8040 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8042 when Pragma_Implemented => Implemented : declare
8043 Proc_Id : Entity_Id;
8048 Check_Arg_Count (2);
8049 Check_No_Identifiers;
8050 Check_Arg_Is_Identifier (Arg1);
8051 Check_Arg_Is_Local_Name (Arg1);
8053 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8055 -- Extract the name of the local procedure
8057 Proc_Id := Entity (Expression (Arg1));
8059 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8060 -- primitive procedure of a synchronized tagged type.
8062 if Ekind (Proc_Id) = E_Procedure
8063 and then Is_Primitive (Proc_Id)
8064 and then Present (First_Formal (Proc_Id))
8066 Typ := Etype (First_Formal (Proc_Id));
8068 if Is_Tagged_Type (Typ)
8071 -- Check for a protected, a synchronized or a task interface
8073 ((Is_Interface (Typ)
8074 and then Is_Synchronized_Interface (Typ))
8076 -- Check for a protected type or a task type that implements
8080 (Is_Concurrent_Record_Type (Typ)
8081 and then Present (Interfaces (Typ)))
8083 -- Check for a private record extension with keyword
8087 (Ekind_In (Typ, E_Record_Type_With_Private,
8088 E_Record_Subtype_With_Private)
8089 and then Synchronized_Present (Parent (Typ))))
8094 ("controlling formal must be of synchronized " &
8095 "tagged type", Arg1);
8099 -- Procedures declared inside a protected type must be accepted
8101 elsif Ekind (Proc_Id) = E_Procedure
8102 and then Is_Protected_Type (Scope (Proc_Id))
8106 -- The first argument is not a primitive procedure
8110 ("pragma % must be applied to a primitive procedure", Arg1);
8114 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8115 -- By_Protected_Procedure to the primitive procedure of a task
8118 if Chars (Arg2) = Name_By_Protected_Procedure
8119 and then Is_Interface (Typ)
8120 and then Is_Task_Interface (Typ)
8123 ("implementation kind By_Protected_Procedure cannot be " &
8124 "applied to a task interface primitive", Arg2);
8128 Record_Rep_Item (Proc_Id, N);
8131 ----------------------
8132 -- Implicit_Packing --
8133 ----------------------
8135 -- pragma Implicit_Packing;
8137 when Pragma_Implicit_Packing =>
8139 Check_Arg_Count (0);
8140 Implicit_Packing := True;
8147 -- [Convention =>] convention_IDENTIFIER,
8148 -- [Entity =>] local_NAME
8149 -- [, [External_Name =>] static_string_EXPRESSION ]
8150 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8152 when Pragma_Import =>
8153 Check_Ada_83_Warning;
8159 Check_At_Least_N_Arguments (2);
8160 Check_At_Most_N_Arguments (4);
8161 Process_Import_Or_Interface;
8163 ----------------------
8164 -- Import_Exception --
8165 ----------------------
8167 -- pragma Import_Exception (
8168 -- [Internal =>] LOCAL_NAME
8169 -- [, [External =>] EXTERNAL_SYMBOL]
8170 -- [, [Form =>] Ada | VMS]
8171 -- [, [Code =>] static_integer_EXPRESSION]);
8173 when Pragma_Import_Exception => Import_Exception : declare
8174 Args : Args_List (1 .. 4);
8175 Names : constant Name_List (1 .. 4) := (
8181 Internal : Node_Id renames Args (1);
8182 External : Node_Id renames Args (2);
8183 Form : Node_Id renames Args (3);
8184 Code : Node_Id renames Args (4);
8188 Gather_Associations (Names, Args);
8190 if Present (External) and then Present (Code) then
8192 ("cannot give both External and Code options for pragma%");
8195 Process_Extended_Import_Export_Exception_Pragma (
8196 Arg_Internal => Internal,
8197 Arg_External => External,
8201 if not Is_VMS_Exception (Entity (Internal)) then
8202 Set_Imported (Entity (Internal));
8204 end Import_Exception;
8206 ---------------------
8207 -- Import_Function --
8208 ---------------------
8210 -- pragma Import_Function (
8211 -- [Internal =>] LOCAL_NAME,
8212 -- [, [External =>] EXTERNAL_SYMBOL]
8213 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8214 -- [, [Result_Type =>] SUBTYPE_MARK]
8215 -- [, [Mechanism =>] MECHANISM]
8216 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8217 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8219 -- EXTERNAL_SYMBOL ::=
8221 -- | static_string_EXPRESSION
8223 -- PARAMETER_TYPES ::=
8225 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8227 -- TYPE_DESIGNATOR ::=
8229 -- | subtype_Name ' Access
8233 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8235 -- MECHANISM_ASSOCIATION ::=
8236 -- [formal_parameter_NAME =>] MECHANISM_NAME
8238 -- MECHANISM_NAME ::=
8241 -- | Descriptor [([Class =>] CLASS_NAME)]
8243 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8245 when Pragma_Import_Function => Import_Function : declare
8246 Args : Args_List (1 .. 7);
8247 Names : constant Name_List (1 .. 7) := (
8250 Name_Parameter_Types,
8253 Name_Result_Mechanism,
8254 Name_First_Optional_Parameter);
8256 Internal : Node_Id renames Args (1);
8257 External : Node_Id renames Args (2);
8258 Parameter_Types : Node_Id renames Args (3);
8259 Result_Type : Node_Id renames Args (4);
8260 Mechanism : Node_Id renames Args (5);
8261 Result_Mechanism : Node_Id renames Args (6);
8262 First_Optional_Parameter : Node_Id renames Args (7);
8266 Gather_Associations (Names, Args);
8267 Process_Extended_Import_Export_Subprogram_Pragma (
8268 Arg_Internal => Internal,
8269 Arg_External => External,
8270 Arg_Parameter_Types => Parameter_Types,
8271 Arg_Result_Type => Result_Type,
8272 Arg_Mechanism => Mechanism,
8273 Arg_Result_Mechanism => Result_Mechanism,
8274 Arg_First_Optional_Parameter => First_Optional_Parameter);
8275 end Import_Function;
8281 -- pragma Import_Object (
8282 -- [Internal =>] LOCAL_NAME
8283 -- [, [External =>] EXTERNAL_SYMBOL]
8284 -- [, [Size =>] EXTERNAL_SYMBOL]);
8286 -- EXTERNAL_SYMBOL ::=
8288 -- | static_string_EXPRESSION
8290 when Pragma_Import_Object => Import_Object : declare
8291 Args : Args_List (1 .. 3);
8292 Names : constant Name_List (1 .. 3) := (
8297 Internal : Node_Id renames Args (1);
8298 External : Node_Id renames Args (2);
8299 Size : Node_Id renames Args (3);
8303 Gather_Associations (Names, Args);
8304 Process_Extended_Import_Export_Object_Pragma (
8305 Arg_Internal => Internal,
8306 Arg_External => External,
8310 ----------------------
8311 -- Import_Procedure --
8312 ----------------------
8314 -- pragma Import_Procedure (
8315 -- [Internal =>] LOCAL_NAME
8316 -- [, [External =>] EXTERNAL_SYMBOL]
8317 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8318 -- [, [Mechanism =>] MECHANISM]
8319 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8321 -- EXTERNAL_SYMBOL ::=
8323 -- | static_string_EXPRESSION
8325 -- PARAMETER_TYPES ::=
8327 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8329 -- TYPE_DESIGNATOR ::=
8331 -- | subtype_Name ' Access
8335 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8337 -- MECHANISM_ASSOCIATION ::=
8338 -- [formal_parameter_NAME =>] MECHANISM_NAME
8340 -- MECHANISM_NAME ::=
8343 -- | Descriptor [([Class =>] CLASS_NAME)]
8345 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8347 when Pragma_Import_Procedure => Import_Procedure : declare
8348 Args : Args_List (1 .. 5);
8349 Names : constant Name_List (1 .. 5) := (
8352 Name_Parameter_Types,
8354 Name_First_Optional_Parameter);
8356 Internal : Node_Id renames Args (1);
8357 External : Node_Id renames Args (2);
8358 Parameter_Types : Node_Id renames Args (3);
8359 Mechanism : Node_Id renames Args (4);
8360 First_Optional_Parameter : Node_Id renames Args (5);
8364 Gather_Associations (Names, Args);
8365 Process_Extended_Import_Export_Subprogram_Pragma (
8366 Arg_Internal => Internal,
8367 Arg_External => External,
8368 Arg_Parameter_Types => Parameter_Types,
8369 Arg_Mechanism => Mechanism,
8370 Arg_First_Optional_Parameter => First_Optional_Parameter);
8371 end Import_Procedure;
8373 -----------------------------
8374 -- Import_Valued_Procedure --
8375 -----------------------------
8377 -- pragma Import_Valued_Procedure (
8378 -- [Internal =>] LOCAL_NAME
8379 -- [, [External =>] EXTERNAL_SYMBOL]
8380 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8381 -- [, [Mechanism =>] MECHANISM]
8382 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8384 -- EXTERNAL_SYMBOL ::=
8386 -- | static_string_EXPRESSION
8388 -- PARAMETER_TYPES ::=
8390 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8392 -- TYPE_DESIGNATOR ::=
8394 -- | subtype_Name ' Access
8398 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8400 -- MECHANISM_ASSOCIATION ::=
8401 -- [formal_parameter_NAME =>] MECHANISM_NAME
8403 -- MECHANISM_NAME ::=
8406 -- | Descriptor [([Class =>] CLASS_NAME)]
8408 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8410 when Pragma_Import_Valued_Procedure =>
8411 Import_Valued_Procedure : declare
8412 Args : Args_List (1 .. 5);
8413 Names : constant Name_List (1 .. 5) := (
8416 Name_Parameter_Types,
8418 Name_First_Optional_Parameter);
8420 Internal : Node_Id renames Args (1);
8421 External : Node_Id renames Args (2);
8422 Parameter_Types : Node_Id renames Args (3);
8423 Mechanism : Node_Id renames Args (4);
8424 First_Optional_Parameter : Node_Id renames Args (5);
8428 Gather_Associations (Names, Args);
8429 Process_Extended_Import_Export_Subprogram_Pragma (
8430 Arg_Internal => Internal,
8431 Arg_External => External,
8432 Arg_Parameter_Types => Parameter_Types,
8433 Arg_Mechanism => Mechanism,
8434 Arg_First_Optional_Parameter => First_Optional_Parameter);
8435 end Import_Valued_Procedure;
8441 -- pragma Independent (LOCAL_NAME);
8443 when Pragma_Independent => Independent : declare
8450 Check_Ada_83_Warning;
8452 Check_No_Identifiers;
8453 Check_Arg_Count (1);
8454 Check_Arg_Is_Local_Name (Arg1);
8455 E_Id := Expression (Arg1);
8457 if Etype (E_Id) = Any_Type then
8462 D := Declaration_Node (E);
8465 -- Check duplicate before we chain ourselves!
8467 Check_Duplicate_Pragma (E);
8469 -- Check appropriate entity
8472 if Rep_Item_Too_Early (E, N)
8474 Rep_Item_Too_Late (E, N)
8478 Check_First_Subtype (Arg1);
8481 elsif K = N_Object_Declaration
8482 or else (K = N_Component_Declaration
8483 and then Original_Record_Component (E) = E)
8485 if Rep_Item_Too_Late (E, N) then
8491 ("inappropriate entity for pragma%", Arg1);
8494 Independence_Checks.Append ((N, E));
8497 ----------------------------
8498 -- Independent_Components --
8499 ----------------------------
8501 -- pragma Atomic_Components (array_LOCAL_NAME);
8503 -- This processing is shared by Volatile_Components
8505 when Pragma_Independent_Components => Independent_Components : declare
8512 Check_Ada_83_Warning;
8514 Check_No_Identifiers;
8515 Check_Arg_Count (1);
8516 Check_Arg_Is_Local_Name (Arg1);
8517 E_Id := Expression (Arg1);
8519 if Etype (E_Id) = Any_Type then
8525 -- Check duplicate before we chain ourselves!
8527 Check_Duplicate_Pragma (E);
8529 -- Check appropriate entity
8531 if Rep_Item_Too_Early (E, N)
8533 Rep_Item_Too_Late (E, N)
8538 D := Declaration_Node (E);
8541 if (K = N_Full_Type_Declaration
8542 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
8544 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
8545 and then Nkind (D) = N_Object_Declaration
8546 and then Nkind (Object_Definition (D)) =
8547 N_Constrained_Array_Definition)
8549 Independence_Checks.Append ((N, E));
8552 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
8554 end Independent_Components;
8556 ------------------------
8557 -- Initialize_Scalars --
8558 ------------------------
8560 -- pragma Initialize_Scalars;
8562 when Pragma_Initialize_Scalars =>
8564 Check_Arg_Count (0);
8565 Check_Valid_Configuration_Pragma;
8566 Check_Restriction (No_Initialize_Scalars, N);
8568 -- Initialize_Scalars creates false positives in CodePeer,
8569 -- so ignore this pragma in this mode.
8571 if not Restriction_Active (No_Initialize_Scalars)
8572 and then not CodePeer_Mode
8574 Init_Or_Norm_Scalars := True;
8575 Initialize_Scalars := True;
8582 -- pragma Inline ( NAME {, NAME} );
8584 when Pragma_Inline =>
8586 -- Pragma is active if inlining option is active
8588 Process_Inline (Inline_Active);
8594 -- pragma Inline_Always ( NAME {, NAME} );
8596 when Pragma_Inline_Always =>
8599 -- Pragma always active unless in CodePeer mode, since this causes
8600 -- walk order issues.
8602 if not CodePeer_Mode then
8603 Process_Inline (True);
8606 --------------------
8607 -- Inline_Generic --
8608 --------------------
8610 -- pragma Inline_Generic (NAME {, NAME});
8612 when Pragma_Inline_Generic =>
8614 Process_Generic_List;
8616 ----------------------
8617 -- Inspection_Point --
8618 ----------------------
8620 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
8622 when Pragma_Inspection_Point => Inspection_Point : declare
8627 if Arg_Count > 0 then
8630 Exp := Expression (Arg);
8633 if not Is_Entity_Name (Exp)
8634 or else not Is_Object (Entity (Exp))
8636 Error_Pragma_Arg ("object name required", Arg);
8643 end Inspection_Point;
8649 -- pragma Interface (
8650 -- [ Convention =>] convention_IDENTIFIER,
8651 -- [ Entity =>] local_NAME
8652 -- [, [External_Name =>] static_string_EXPRESSION ]
8653 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8655 when Pragma_Interface =>
8662 Check_At_Least_N_Arguments (2);
8663 Check_At_Most_N_Arguments (4);
8664 Process_Import_Or_Interface;
8666 -- In Ada 2005, the permission to use Interface (a reserved word)
8667 -- as a pragma name is considered an obsolescent feature.
8669 if Ada_Version >= Ada_2005 then
8671 (No_Obsolescent_Features, Pragma_Identifier (N));
8674 --------------------
8675 -- Interface_Name --
8676 --------------------
8678 -- pragma Interface_Name (
8679 -- [ Entity =>] local_NAME
8680 -- [,[External_Name =>] static_string_EXPRESSION ]
8681 -- [,[Link_Name =>] static_string_EXPRESSION ]);
8683 when Pragma_Interface_Name => Interface_Name : declare
8692 ((Name_Entity, Name_External_Name, Name_Link_Name));
8693 Check_At_Least_N_Arguments (2);
8694 Check_At_Most_N_Arguments (3);
8695 Id := Expression (Arg1);
8698 if not Is_Entity_Name (Id) then
8700 ("first argument for pragma% must be entity name", Arg1);
8701 elsif Etype (Id) = Any_Type then
8704 Def_Id := Entity (Id);
8707 -- Special DEC-compatible processing for the object case, forces
8708 -- object to be imported.
8710 if Ekind (Def_Id) = E_Variable then
8711 Kill_Size_Check_Code (Def_Id);
8712 Note_Possible_Modification (Id, Sure => False);
8714 -- Initialization is not allowed for imported variable
8716 if Present (Expression (Parent (Def_Id)))
8717 and then Comes_From_Source (Expression (Parent (Def_Id)))
8719 Error_Msg_Sloc := Sloc (Def_Id);
8721 ("no initialization allowed for declaration of& #",
8725 -- For compatibility, support VADS usage of providing both
8726 -- pragmas Interface and Interface_Name to obtain the effect
8727 -- of a single Import pragma.
8729 if Is_Imported (Def_Id)
8730 and then Present (First_Rep_Item (Def_Id))
8731 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
8733 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
8737 Set_Imported (Def_Id);
8740 Set_Is_Public (Def_Id);
8741 Process_Interface_Name (Def_Id, Arg2, Arg3);
8744 -- Otherwise must be subprogram
8746 elsif not Is_Subprogram (Def_Id) then
8748 ("argument of pragma% is not subprogram", Arg1);
8751 Check_At_Most_N_Arguments (3);
8755 -- Loop through homonyms
8758 Def_Id := Get_Base_Subprogram (Hom_Id);
8760 if Is_Imported (Def_Id) then
8761 Process_Interface_Name (Def_Id, Arg2, Arg3);
8765 Hom_Id := Homonym (Hom_Id);
8767 exit when No (Hom_Id)
8768 or else Scope (Hom_Id) /= Current_Scope;
8773 ("argument of pragma% is not imported subprogram",
8779 -----------------------
8780 -- Interrupt_Handler --
8781 -----------------------
8783 -- pragma Interrupt_Handler (handler_NAME);
8785 when Pragma_Interrupt_Handler =>
8786 Check_Ada_83_Warning;
8787 Check_Arg_Count (1);
8788 Check_No_Identifiers;
8790 if No_Run_Time_Mode then
8791 Error_Msg_CRT ("Interrupt_Handler pragma", N);
8793 Check_Interrupt_Or_Attach_Handler;
8794 Process_Interrupt_Or_Attach_Handler;
8797 ------------------------
8798 -- Interrupt_Priority --
8799 ------------------------
8801 -- pragma Interrupt_Priority [(EXPRESSION)];
8803 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
8804 P : constant Node_Id := Parent (N);
8808 Check_Ada_83_Warning;
8810 if Arg_Count /= 0 then
8811 Arg := Expression (Arg1);
8812 Check_Arg_Count (1);
8813 Check_No_Identifiers;
8815 -- The expression must be analyzed in the special manner
8816 -- described in "Handling of Default and Per-Object
8817 -- Expressions" in sem.ads.
8819 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
8822 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
8826 elsif Has_Priority_Pragma (P) then
8827 Error_Pragma ("duplicate pragma% not allowed");
8830 Set_Has_Priority_Pragma (P, True);
8831 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8833 end Interrupt_Priority;
8835 ---------------------
8836 -- Interrupt_State --
8837 ---------------------
8839 -- pragma Interrupt_State (
8840 -- [Name =>] INTERRUPT_ID,
8841 -- [State =>] INTERRUPT_STATE);
8843 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
8844 -- INTERRUPT_STATE => System | Runtime | User
8846 -- Note: if the interrupt id is given as an identifier, then it must
8847 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
8848 -- given as a static integer expression which must be in the range of
8849 -- Ada.Interrupts.Interrupt_ID.
8851 when Pragma_Interrupt_State => Interrupt_State : declare
8853 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
8854 -- This is the entity Ada.Interrupts.Interrupt_ID;
8856 State_Type : Character;
8857 -- Set to 's'/'r'/'u' for System/Runtime/User
8860 -- Index to entry in Interrupt_States table
8863 -- Value of interrupt
8865 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
8866 -- The first argument to the pragma
8868 Int_Ent : Entity_Id;
8869 -- Interrupt entity in Ada.Interrupts.Names
8873 Check_Arg_Order ((Name_Name, Name_State));
8874 Check_Arg_Count (2);
8876 Check_Optional_Identifier (Arg1, Name_Name);
8877 Check_Optional_Identifier (Arg2, Name_State);
8878 Check_Arg_Is_Identifier (Arg2);
8880 -- First argument is identifier
8882 if Nkind (Arg1X) = N_Identifier then
8884 -- Search list of names in Ada.Interrupts.Names
8886 Int_Ent := First_Entity (RTE (RE_Names));
8888 if No (Int_Ent) then
8889 Error_Pragma_Arg ("invalid interrupt name", Arg1);
8891 elsif Chars (Int_Ent) = Chars (Arg1X) then
8892 Int_Val := Expr_Value (Constant_Value (Int_Ent));
8896 Next_Entity (Int_Ent);
8899 -- First argument is not an identifier, so it must be a static
8900 -- expression of type Ada.Interrupts.Interrupt_ID.
8903 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8904 Int_Val := Expr_Value (Arg1X);
8906 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
8908 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
8911 ("value not in range of type " &
8912 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
8918 case Chars (Get_Pragma_Arg (Arg2)) is
8919 when Name_Runtime => State_Type := 'r';
8920 when Name_System => State_Type := 's';
8921 when Name_User => State_Type := 'u';
8924 Error_Pragma_Arg ("invalid interrupt state", Arg2);
8927 -- Check if entry is already stored
8929 IST_Num := Interrupt_States.First;
8931 -- If entry not found, add it
8933 if IST_Num > Interrupt_States.Last then
8934 Interrupt_States.Append
8935 ((Interrupt_Number => UI_To_Int (Int_Val),
8936 Interrupt_State => State_Type,
8937 Pragma_Loc => Loc));
8940 -- Case of entry for the same entry
8942 elsif Int_Val = Interrupt_States.Table (IST_Num).
8945 -- If state matches, done, no need to make redundant entry
8948 State_Type = Interrupt_States.Table (IST_Num).
8951 -- Otherwise if state does not match, error
8954 Interrupt_States.Table (IST_Num).Pragma_Loc;
8956 ("state conflicts with that given #", Arg2);
8960 IST_Num := IST_Num + 1;
8962 end Interrupt_State;
8964 ----------------------
8965 -- Java_Constructor --
8966 ----------------------
8968 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
8970 -- Also handles pragma CIL_Constructor
8972 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
8973 Java_Constructor : declare
8974 Convention : Convention_Id;
8978 This_Formal : Entity_Id;
8982 Check_Arg_Count (1);
8983 Check_Optional_Identifier (Arg1, Name_Entity);
8984 Check_Arg_Is_Local_Name (Arg1);
8986 Id := Expression (Arg1);
8987 Find_Program_Unit_Name (Id);
8989 -- If we did not find the name, we are done
8991 if Etype (Id) = Any_Type then
8995 -- Check wrong use of pragma in wrong VM target
8997 if VM_Target = No_VM then
9000 elsif VM_Target = CLI_Target
9001 and then Prag_Id = Pragma_Java_Constructor
9003 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9005 elsif VM_Target = JVM_Target
9006 and then Prag_Id = Pragma_CIL_Constructor
9008 Error_Pragma ("must use pragma 'Java_'Constructor");
9012 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9013 when Pragma_Java_Constructor => Convention := Convention_Java;
9014 when others => null;
9017 Hom_Id := Entity (Id);
9019 -- Loop through homonyms
9022 Def_Id := Get_Base_Subprogram (Hom_Id);
9024 -- The constructor is required to be a function
9026 if Ekind (Def_Id) /= E_Function then
9027 if VM_Target = JVM_Target then
9029 ("pragma% requires function returning a " &
9030 "'Java access type", Def_Id);
9033 ("pragma% requires function returning a " &
9034 "'C'I'L access type", Def_Id);
9038 -- Check arguments: For tagged type the first formal must be
9039 -- named "this" and its type must be a named access type
9040 -- designating a class-wide tagged type that has convention
9041 -- CIL/Java. The first formal must also have a null default
9042 -- value. For example:
9044 -- type Typ is tagged ...
9045 -- type Ref is access all Typ;
9046 -- pragma Convention (CIL, Typ);
9048 -- function New_Typ (This : Ref) return Ref;
9049 -- function New_Typ (This : Ref; I : Integer) return Ref;
9050 -- pragma Cil_Constructor (New_Typ);
9052 -- Reason: The first formal must NOT be a primitive of the
9055 -- This rule also applies to constructors of delegates used
9056 -- to interface with standard target libraries. For example:
9058 -- type Delegate is access procedure ...
9059 -- pragma Import (CIL, Delegate, ...);
9061 -- function new_Delegate
9062 -- (This : Delegate := null; ... ) return Delegate;
9064 -- For value-types this rule does not apply.
9066 if not Is_Value_Type (Etype (Def_Id)) then
9067 if No (First_Formal (Def_Id)) then
9068 Error_Msg_Name_1 := Pname;
9069 Error_Msg_N ("% function must have parameters", Def_Id);
9073 -- In the JRE library we have several occurrences in which
9074 -- the "this" parameter is not the first formal.
9076 This_Formal := First_Formal (Def_Id);
9078 -- In the JRE library we have several occurrences in which
9079 -- the "this" parameter is not the first formal. Search for
9082 if VM_Target = JVM_Target then
9083 while Present (This_Formal)
9084 and then Get_Name_String (Chars (This_Formal)) /= "this"
9086 Next_Formal (This_Formal);
9089 if No (This_Formal) then
9090 This_Formal := First_Formal (Def_Id);
9094 -- Warning: The first parameter should be named "this".
9095 -- We temporarily allow it because we have the following
9096 -- case in the Java runtime (file s-osinte.ads) ???
9098 -- function new_Thread
9099 -- (Self_Id : System.Address) return Thread_Id;
9100 -- pragma Java_Constructor (new_Thread);
9102 if VM_Target = JVM_Target
9103 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9105 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9109 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9110 Error_Msg_Name_1 := Pname;
9112 ("first formal of % function must be named `this`",
9113 Parent (This_Formal));
9115 elsif not Is_Access_Type (Etype (This_Formal)) then
9116 Error_Msg_Name_1 := Pname;
9118 ("first formal of % function must be an access type",
9119 Parameter_Type (Parent (This_Formal)));
9121 -- For delegates the type of the first formal must be a
9122 -- named access-to-subprogram type (see previous example)
9124 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9125 and then Ekind (Etype (This_Formal))
9126 /= E_Access_Subprogram_Type
9128 Error_Msg_Name_1 := Pname;
9130 ("first formal of % function must be a named access" &
9131 " to subprogram type",
9132 Parameter_Type (Parent (This_Formal)));
9134 -- Warning: We should reject anonymous access types because
9135 -- the constructor must not be handled as a primitive of the
9136 -- tagged type. We temporarily allow it because this profile
9137 -- is currently generated by cil2ada???
9139 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9140 and then not Ekind_In (Etype (This_Formal),
9142 E_General_Access_Type,
9143 E_Anonymous_Access_Type)
9145 Error_Msg_Name_1 := Pname;
9147 ("first formal of % function must be a named access" &
9149 Parameter_Type (Parent (This_Formal)));
9151 elsif Atree.Convention
9152 (Designated_Type (Etype (This_Formal))) /= Convention
9154 Error_Msg_Name_1 := Pname;
9156 if Convention = Convention_Java then
9158 ("pragma% requires convention 'Cil in designated" &
9160 Parameter_Type (Parent (This_Formal)));
9163 ("pragma% requires convention 'Java in designated" &
9165 Parameter_Type (Parent (This_Formal)));
9168 elsif No (Expression (Parent (This_Formal)))
9169 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9171 Error_Msg_Name_1 := Pname;
9173 ("pragma% requires first formal with default `null`",
9174 Parameter_Type (Parent (This_Formal)));
9178 -- Check result type: the constructor must be a function
9180 -- * a value type (only allowed in the CIL compiler)
9181 -- * an access-to-subprogram type with convention Java/CIL
9182 -- * an access-type designating a type that has convention
9185 if Is_Value_Type (Etype (Def_Id)) then
9188 -- Access-to-subprogram type with convention Java/CIL
9190 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9191 if Atree.Convention (Etype (Def_Id)) /= Convention then
9192 if Convention = Convention_Java then
9194 ("pragma% requires function returning a " &
9195 "'Java access type", Arg1);
9197 pragma Assert (Convention = Convention_CIL);
9199 ("pragma% requires function returning a " &
9200 "'C'I'L access type", Arg1);
9204 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9205 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9206 E_General_Access_Type)
9209 (Designated_Type (Etype (Def_Id))) /= Convention
9211 Error_Msg_Name_1 := Pname;
9213 if Convention = Convention_Java then
9215 ("pragma% requires function returning a named" &
9216 "'Java access type", Arg1);
9219 ("pragma% requires function returning a named" &
9220 "'C'I'L access type", Arg1);
9225 Set_Is_Constructor (Def_Id);
9226 Set_Convention (Def_Id, Convention);
9227 Set_Is_Imported (Def_Id);
9229 Hom_Id := Homonym (Hom_Id);
9231 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9233 end Java_Constructor;
9235 ----------------------
9236 -- Java_Interface --
9237 ----------------------
9239 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9241 when Pragma_Java_Interface => Java_Interface : declare
9247 Check_Arg_Count (1);
9248 Check_Optional_Identifier (Arg1, Name_Entity);
9249 Check_Arg_Is_Local_Name (Arg1);
9251 Arg := Expression (Arg1);
9254 if Etype (Arg) = Any_Type then
9258 if not Is_Entity_Name (Arg)
9259 or else not Is_Type (Entity (Arg))
9261 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9264 Typ := Underlying_Type (Entity (Arg));
9266 -- For now simply check some of the semantic constraints on the
9267 -- type. This currently leaves out some restrictions on interface
9268 -- types, namely that the parent type must be java.lang.Object.Typ
9269 -- and that all primitives of the type should be declared
9272 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9273 Error_Pragma_Arg ("pragma% requires an abstract "
9274 & "tagged type", Arg1);
9276 elsif not Has_Discriminants (Typ)
9277 or else Ekind (Etype (First_Discriminant (Typ)))
9278 /= E_Anonymous_Access_Type
9280 not Is_Class_Wide_Type
9281 (Designated_Type (Etype (First_Discriminant (Typ))))
9284 ("type must have a class-wide access discriminant", Arg1);
9292 -- pragma Keep_Names ([On => ] local_NAME);
9294 when Pragma_Keep_Names => Keep_Names : declare
9299 Check_Arg_Count (1);
9300 Check_Optional_Identifier (Arg1, Name_On);
9301 Check_Arg_Is_Local_Name (Arg1);
9303 Arg := Expression (Arg1);
9306 if Etype (Arg) = Any_Type then
9310 if not Is_Entity_Name (Arg)
9311 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
9314 ("pragma% requires a local enumeration type", Arg1);
9317 Set_Discard_Names (Entity (Arg), False);
9324 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
9326 when Pragma_License =>
9328 Check_Arg_Count (1);
9329 Check_No_Identifiers;
9330 Check_Valid_Configuration_Pragma;
9331 Check_Arg_Is_Identifier (Arg1);
9334 Sind : constant Source_File_Index :=
9335 Source_Index (Current_Sem_Unit);
9338 case Chars (Get_Pragma_Arg (Arg1)) is
9340 Set_License (Sind, GPL);
9342 when Name_Modified_GPL =>
9343 Set_License (Sind, Modified_GPL);
9345 when Name_Restricted =>
9346 Set_License (Sind, Restricted);
9348 when Name_Unrestricted =>
9349 Set_License (Sind, Unrestricted);
9352 Error_Pragma_Arg ("invalid license name", Arg1);
9360 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
9362 when Pragma_Link_With => Link_With : declare
9368 if Operating_Mode = Generate_Code
9369 and then In_Extended_Main_Source_Unit (N)
9371 Check_At_Least_N_Arguments (1);
9372 Check_No_Identifiers;
9373 Check_Is_In_Decl_Part_Or_Package_Spec;
9374 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9378 while Present (Arg) loop
9379 Check_Arg_Is_Static_Expression (Arg, Standard_String);
9381 -- Store argument, converting sequences of spaces to a
9382 -- single null character (this is one of the differences
9383 -- in processing between Link_With and Linker_Options).
9386 C : constant Char_Code := Get_Char_Code (' ');
9387 S : constant String_Id :=
9388 Strval (Expr_Value_S (Expression (Arg)));
9389 L : constant Nat := String_Length (S);
9392 procedure Skip_Spaces;
9393 -- Advance F past any spaces
9399 procedure Skip_Spaces is
9401 while F <= L and then Get_String_Char (S, F) = C loop
9406 -- Start of processing for Arg_Store
9409 Skip_Spaces; -- skip leading spaces
9411 -- Loop through characters, changing any embedded
9412 -- sequence of spaces to a single null character (this
9413 -- is how Link_With/Linker_Options differ)
9416 if Get_String_Char (S, F) = C then
9419 Store_String_Char (ASCII.NUL);
9422 Store_String_Char (Get_String_Char (S, F));
9430 if Present (Arg) then
9431 Store_String_Char (ASCII.NUL);
9435 Store_Linker_Option_String (End_String);
9443 -- pragma Linker_Alias (
9444 -- [Entity =>] LOCAL_NAME
9445 -- [Target =>] static_string_EXPRESSION);
9447 when Pragma_Linker_Alias =>
9449 Check_Arg_Order ((Name_Entity, Name_Target));
9450 Check_Arg_Count (2);
9451 Check_Optional_Identifier (Arg1, Name_Entity);
9452 Check_Optional_Identifier (Arg2, Name_Target);
9453 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9454 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9456 -- The only processing required is to link this item on to the
9457 -- list of rep items for the given entity. This is accomplished
9458 -- by the call to Rep_Item_Too_Late (when no error is detected
9459 -- and False is returned).
9461 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
9464 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9467 ------------------------
9468 -- Linker_Constructor --
9469 ------------------------
9471 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
9473 -- Code is shared with Linker_Destructor
9475 -----------------------
9476 -- Linker_Destructor --
9477 -----------------------
9479 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
9481 when Pragma_Linker_Constructor |
9482 Pragma_Linker_Destructor =>
9483 Linker_Constructor : declare
9489 Check_Arg_Count (1);
9490 Check_No_Identifiers;
9491 Check_Arg_Is_Local_Name (Arg1);
9492 Arg1_X := Expression (Arg1);
9494 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
9496 if not Is_Library_Level_Entity (Proc) then
9498 ("argument for pragma% must be library level entity", Arg1);
9501 -- The only processing required is to link this item on to the
9502 -- list of rep items for the given entity. This is accomplished
9503 -- by the call to Rep_Item_Too_Late (when no error is detected
9504 -- and False is returned).
9506 if Rep_Item_Too_Late (Proc, N) then
9509 Set_Has_Gigi_Rep_Item (Proc);
9511 end Linker_Constructor;
9513 --------------------
9514 -- Linker_Options --
9515 --------------------
9517 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
9519 when Pragma_Linker_Options => Linker_Options : declare
9523 Check_Ada_83_Warning;
9524 Check_No_Identifiers;
9525 Check_Arg_Count (1);
9526 Check_Is_In_Decl_Part_Or_Package_Spec;
9527 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9528 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
9531 while Present (Arg) loop
9532 Check_Arg_Is_Static_Expression (Arg, Standard_String);
9533 Store_String_Char (ASCII.NUL);
9534 Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
9538 if Operating_Mode = Generate_Code
9539 and then In_Extended_Main_Source_Unit (N)
9541 Store_Linker_Option_String (End_String);
9545 --------------------
9546 -- Linker_Section --
9547 --------------------
9549 -- pragma Linker_Section (
9550 -- [Entity =>] LOCAL_NAME
9551 -- [Section =>] static_string_EXPRESSION);
9553 when Pragma_Linker_Section =>
9555 Check_Arg_Order ((Name_Entity, Name_Section));
9556 Check_Arg_Count (2);
9557 Check_Optional_Identifier (Arg1, Name_Entity);
9558 Check_Optional_Identifier (Arg2, Name_Section);
9559 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9560 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9562 -- This pragma applies only to objects
9564 if not Is_Object (Entity (Expression (Arg1))) then
9565 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
9568 -- The only processing required is to link this item on to the
9569 -- list of rep items for the given entity. This is accomplished
9570 -- by the call to Rep_Item_Too_Late (when no error is detected
9571 -- and False is returned).
9573 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
9576 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9583 -- pragma List (On | Off)
9585 -- There is nothing to do here, since we did all the processing for
9586 -- this pragma in Par.Prag (so that it works properly even in syntax
9592 --------------------
9593 -- Locking_Policy --
9594 --------------------
9596 -- pragma Locking_Policy (policy_IDENTIFIER);
9598 when Pragma_Locking_Policy => declare
9602 Check_Ada_83_Warning;
9603 Check_Arg_Count (1);
9604 Check_No_Identifiers;
9605 Check_Arg_Is_Locking_Policy (Arg1);
9606 Check_Valid_Configuration_Pragma;
9607 Get_Name_String (Chars (Expression (Arg1)));
9608 LP := Fold_Upper (Name_Buffer (1));
9610 if Locking_Policy /= ' '
9611 and then Locking_Policy /= LP
9613 Error_Msg_Sloc := Locking_Policy_Sloc;
9614 Error_Pragma ("locking policy incompatible with policy#");
9616 -- Set new policy, but always preserve System_Location since we
9617 -- like the error message with the run time name.
9620 Locking_Policy := LP;
9622 if Locking_Policy_Sloc /= System_Location then
9623 Locking_Policy_Sloc := Loc;
9632 -- pragma Long_Float (D_Float | G_Float);
9634 when Pragma_Long_Float =>
9636 Check_Valid_Configuration_Pragma;
9637 Check_Arg_Count (1);
9638 Check_No_Identifier (Arg1);
9639 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
9641 if not OpenVMS_On_Target then
9642 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
9647 if Chars (Expression (Arg1)) = Name_D_Float then
9648 if Opt.Float_Format_Long = 'G' then
9649 Error_Pragma ("G_Float previously specified");
9652 Opt.Float_Format_Long := 'D';
9654 -- G_Float case (this is the default, does not need overriding)
9657 if Opt.Float_Format_Long = 'D' then
9658 Error_Pragma ("D_Float previously specified");
9661 Opt.Float_Format_Long := 'G';
9664 Set_Standard_Fpt_Formats;
9666 -----------------------
9667 -- Machine_Attribute --
9668 -----------------------
9670 -- pragma Machine_Attribute (
9671 -- [Entity =>] LOCAL_NAME,
9672 -- [Attribute_Name =>] static_string_EXPRESSION
9673 -- [, [Info =>] static_EXPRESSION] );
9675 when Pragma_Machine_Attribute => Machine_Attribute : declare
9680 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
9682 if Arg_Count = 3 then
9683 Check_Optional_Identifier (Arg3, Name_Info);
9684 Check_Arg_Is_Static_Expression (Arg3);
9686 Check_Arg_Count (2);
9689 Check_Optional_Identifier (Arg1, Name_Entity);
9690 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
9691 Check_Arg_Is_Local_Name (Arg1);
9692 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9693 Def_Id := Entity (Expression (Arg1));
9695 if Is_Access_Type (Def_Id) then
9696 Def_Id := Designated_Type (Def_Id);
9699 if Rep_Item_Too_Early (Def_Id, N) then
9703 Def_Id := Underlying_Type (Def_Id);
9705 -- The only processing required is to link this item on to the
9706 -- list of rep items for the given entity. This is accomplished
9707 -- by the call to Rep_Item_Too_Late (when no error is detected
9708 -- and False is returned).
9710 if Rep_Item_Too_Late (Def_Id, N) then
9713 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9715 end Machine_Attribute;
9722 -- (MAIN_OPTION [, MAIN_OPTION]);
9725 -- [STACK_SIZE =>] static_integer_EXPRESSION
9726 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
9727 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
9729 when Pragma_Main => Main : declare
9730 Args : Args_List (1 .. 3);
9731 Names : constant Name_List (1 .. 3) := (
9733 Name_Task_Stack_Size_Default,
9734 Name_Time_Slicing_Enabled);
9740 Gather_Associations (Names, Args);
9742 for J in 1 .. 2 loop
9743 if Present (Args (J)) then
9744 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9748 if Present (Args (3)) then
9749 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
9753 while Present (Nod) loop
9754 if Nkind (Nod) = N_Pragma
9755 and then Pragma_Name (Nod) = Name_Main
9757 Error_Msg_Name_1 := Pname;
9758 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9769 -- pragma Main_Storage
9770 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
9772 -- MAIN_STORAGE_OPTION ::=
9773 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
9774 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
9776 when Pragma_Main_Storage => Main_Storage : declare
9777 Args : Args_List (1 .. 2);
9778 Names : constant Name_List (1 .. 2) := (
9779 Name_Working_Storage,
9786 Gather_Associations (Names, Args);
9788 for J in 1 .. 2 loop
9789 if Present (Args (J)) then
9790 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9794 Check_In_Main_Program;
9797 while Present (Nod) loop
9798 if Nkind (Nod) = N_Pragma
9799 and then Pragma_Name (Nod) = Name_Main_Storage
9801 Error_Msg_Name_1 := Pname;
9802 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9813 -- pragma Memory_Size (NUMERIC_LITERAL)
9815 when Pragma_Memory_Size =>
9818 -- Memory size is simply ignored
9820 Check_No_Identifiers;
9821 Check_Arg_Count (1);
9822 Check_Arg_Is_Integer_Literal (Arg1);
9830 -- The only correct use of this pragma is on its own in a file, in
9831 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
9832 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
9833 -- check for a file containing nothing but a No_Body pragma). If we
9834 -- attempt to process it during normal semantics processing, it means
9835 -- it was misplaced.
9837 when Pragma_No_Body =>
9845 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
9847 when Pragma_No_Return => No_Return : declare
9855 Check_At_Least_N_Arguments (1);
9857 -- Loop through arguments of pragma
9860 while Present (Arg) loop
9861 Check_Arg_Is_Local_Name (Arg);
9862 Id := Expression (Arg);
9865 if not Is_Entity_Name (Id) then
9866 Error_Pragma_Arg ("entity name required", Arg);
9869 if Etype (Id) = Any_Type then
9873 -- Loop to find matching procedures
9878 and then Scope (E) = Current_Scope
9880 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
9883 -- Set flag on any alias as well
9885 if Is_Overloadable (E) and then Present (Alias (E)) then
9886 Set_No_Return (Alias (E));
9896 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
9907 -- pragma No_Run_Time;
9909 -- Note: this pragma is retained for backwards compatibility. See
9910 -- body of Rtsfind for full details on its handling.
9912 when Pragma_No_Run_Time =>
9914 Check_Valid_Configuration_Pragma;
9915 Check_Arg_Count (0);
9917 No_Run_Time_Mode := True;
9918 Configurable_Run_Time_Mode := True;
9920 -- Set Duration to 32 bits if word size is 32
9922 if Ttypes.System_Word_Size = 32 then
9923 Duration_32_Bits_On_Target := True;
9926 -- Set appropriate restrictions
9928 Set_Restriction (No_Finalization, N);
9929 Set_Restriction (No_Exception_Handlers, N);
9930 Set_Restriction (Max_Tasks, N, 0);
9931 Set_Restriction (No_Tasking, N);
9933 ------------------------
9934 -- No_Strict_Aliasing --
9935 ------------------------
9937 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
9939 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
9944 Check_At_Most_N_Arguments (1);
9946 if Arg_Count = 0 then
9947 Check_Valid_Configuration_Pragma;
9948 Opt.No_Strict_Aliasing := True;
9951 Check_Optional_Identifier (Arg2, Name_Entity);
9952 Check_Arg_Is_Local_Name (Arg1);
9953 E_Id := Entity (Expression (Arg1));
9955 if E_Id = Any_Type then
9957 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
9958 Error_Pragma_Arg ("pragma% requires access type", Arg1);
9961 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
9963 end No_Strict_Aliasing;
9965 -----------------------
9966 -- Normalize_Scalars --
9967 -----------------------
9969 -- pragma Normalize_Scalars;
9971 when Pragma_Normalize_Scalars =>
9972 Check_Ada_83_Warning;
9973 Check_Arg_Count (0);
9974 Check_Valid_Configuration_Pragma;
9976 -- Normalize_Scalars creates false positives in CodePeer, so
9977 -- ignore this pragma in this mode.
9979 if not CodePeer_Mode then
9980 Normalize_Scalars := True;
9981 Init_Or_Norm_Scalars := True;
9988 -- pragma Obsolescent;
9990 -- pragma Obsolescent (
9991 -- [Message =>] static_string_EXPRESSION
9992 -- [,[Version =>] Ada_05]]);
9994 -- pragma Obsolescent (
9996 -- [,[Message =>] static_string_EXPRESSION
9997 -- [,[Version =>] Ada_05]] );
9999 when Pragma_Obsolescent => Obsolescent : declare
10003 procedure Set_Obsolescent (E : Entity_Id);
10004 -- Given an entity Ent, mark it as obsolescent if appropriate
10006 ---------------------
10007 -- Set_Obsolescent --
10008 ---------------------
10010 procedure Set_Obsolescent (E : Entity_Id) is
10019 -- Entity name was given
10021 if Present (Ename) then
10023 -- If entity name matches, we are fine. Save entity in
10024 -- pragma argument, for ASIS use.
10026 if Chars (Ename) = Chars (Ent) then
10027 Set_Entity (Ename, Ent);
10028 Generate_Reference (Ent, Ename);
10030 -- If entity name does not match, only possibility is an
10031 -- enumeration literal from an enumeration type declaration.
10033 elsif Ekind (Ent) /= E_Enumeration_Type then
10035 ("pragma % entity name does not match declaration");
10038 Ent := First_Literal (E);
10042 ("pragma % entity name does not match any " &
10043 "enumeration literal");
10045 elsif Chars (Ent) = Chars (Ename) then
10046 Set_Entity (Ename, Ent);
10047 Generate_Reference (Ent, Ename);
10051 Ent := Next_Literal (Ent);
10057 -- Ent points to entity to be marked
10059 if Arg_Count >= 1 then
10061 -- Deal with static string argument
10063 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10064 S := Strval (Expression (Arg1));
10066 for J in 1 .. String_Length (S) loop
10067 if not In_Character_Range (Get_String_Char (S, J)) then
10069 ("pragma% argument does not allow wide characters",
10074 Obsolescent_Warnings.Append
10075 ((Ent => Ent, Msg => Strval (Expression (Arg1))));
10077 -- Check for Ada_05 parameter
10079 if Arg_Count /= 1 then
10080 Check_Arg_Count (2);
10083 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10086 Check_Arg_Is_Identifier (Argx);
10088 if Chars (Argx) /= Name_Ada_05 then
10089 Error_Msg_Name_2 := Name_Ada_05;
10091 ("only allowed argument for pragma% is %", Argx);
10094 if Ada_Version_Explicit < Ada_05
10095 or else not Warn_On_Ada_2005_Compatibility
10103 -- Set flag if pragma active
10106 Set_Is_Obsolescent (Ent);
10110 end Set_Obsolescent;
10112 -- Start of processing for pragma Obsolescent
10117 Check_At_Most_N_Arguments (3);
10119 -- See if first argument specifies an entity name
10123 (Chars (Arg1) = Name_Entity
10125 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10127 N_Operator_Symbol))
10129 Ename := Get_Pragma_Arg (Arg1);
10131 -- Eliminate first argument, so we can share processing
10135 Arg_Count := Arg_Count - 1;
10137 -- No Entity name argument given
10143 if Arg_Count >= 1 then
10144 Check_Optional_Identifier (Arg1, Name_Message);
10146 if Arg_Count = 2 then
10147 Check_Optional_Identifier (Arg2, Name_Version);
10151 -- Get immediately preceding declaration
10154 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10158 -- Cases where we do not follow anything other than another pragma
10162 -- First case: library level compilation unit declaration with
10163 -- the pragma immediately following the declaration.
10165 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10167 (Defining_Entity (Unit (Parent (Parent (N)))));
10170 -- Case 2: library unit placement for package
10174 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10176 if Is_Package_Or_Generic_Package (Ent) then
10177 Set_Obsolescent (Ent);
10183 -- Cases where we must follow a declaration
10186 if Nkind (Decl) not in N_Declaration
10187 and then Nkind (Decl) not in N_Later_Decl_Item
10188 and then Nkind (Decl) not in N_Generic_Declaration
10189 and then Nkind (Decl) not in N_Renaming_Declaration
10192 ("pragma% misplaced, "
10193 & "must immediately follow a declaration");
10196 Set_Obsolescent (Defining_Entity (Decl));
10206 -- pragma Optimize (Time | Space | Off);
10208 -- The actual check for optimize is done in Gigi. Note that this
10209 -- pragma does not actually change the optimization setting, it
10210 -- simply checks that it is consistent with the pragma.
10212 when Pragma_Optimize =>
10213 Check_No_Identifiers;
10214 Check_Arg_Count (1);
10215 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10217 ------------------------
10218 -- Optimize_Alignment --
10219 ------------------------
10221 -- pragma Optimize_Alignment (Time | Space | Off);
10223 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10225 Check_No_Identifiers;
10226 Check_Arg_Count (1);
10227 Check_Valid_Configuration_Pragma;
10230 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10234 Opt.Optimize_Alignment := 'T';
10236 Opt.Optimize_Alignment := 'S';
10238 Opt.Optimize_Alignment := 'O';
10240 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10244 -- Set indication that mode is set locally. If we are in fact in a
10245 -- configuration pragma file, this setting is harmless since the
10246 -- switch will get reset anyway at the start of each unit.
10248 Optimize_Alignment_Local := True;
10249 end Optimize_Alignment;
10255 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10257 when Pragma_Ordered => Ordered : declare
10258 Assoc : constant Node_Id := Arg1;
10264 Check_No_Identifiers;
10265 Check_Arg_Count (1);
10266 Check_Arg_Is_Local_Name (Arg1);
10268 Type_Id := Expression (Assoc);
10269 Find_Type (Type_Id);
10270 Typ := Entity (Type_Id);
10272 if Typ = Any_Type then
10275 Typ := Underlying_Type (Typ);
10278 if not Is_Enumeration_Type (Typ) then
10279 Error_Pragma ("pragma% must specify enumeration type");
10282 Check_First_Subtype (Arg1);
10283 Set_Has_Pragma_Ordered (Base_Type (Typ));
10290 -- pragma Pack (first_subtype_LOCAL_NAME);
10292 when Pragma_Pack => Pack : declare
10293 Assoc : constant Node_Id := Arg1;
10297 Ignore : Boolean := False;
10300 Check_No_Identifiers;
10301 Check_Arg_Count (1);
10302 Check_Arg_Is_Local_Name (Arg1);
10304 Type_Id := Expression (Assoc);
10305 Find_Type (Type_Id);
10306 Typ := Entity (Type_Id);
10309 or else Rep_Item_Too_Early (Typ, N)
10313 Typ := Underlying_Type (Typ);
10316 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
10317 Error_Pragma ("pragma% must specify array or record type");
10320 Check_First_Subtype (Arg1);
10322 if Has_Pragma_Pack (Typ) then
10323 Error_Pragma ("duplicate pragma%, only one allowed");
10327 elsif Is_Array_Type (Typ) then
10328 Ctyp := Component_Type (Typ);
10330 -- Ignore pack that does nothing
10332 if Known_Static_Esize (Ctyp)
10333 and then Known_Static_RM_Size (Ctyp)
10334 and then Esize (Ctyp) = RM_Size (Ctyp)
10335 and then Addressable (Esize (Ctyp))
10340 -- Process OK pragma Pack. Note that if there is a separate
10341 -- component clause present, the Pack will be cancelled. This
10342 -- processing is in Freeze.
10344 if not Rep_Item_Too_Late (Typ, N) then
10346 -- In the context of static code analysis, we do not need
10347 -- complex front-end expansions related to pragma Pack,
10348 -- so disable handling of pragma Pack in this case.
10350 if CodePeer_Mode then
10353 -- For normal non-VM target, do the packing
10355 elsif VM_Target = No_VM then
10357 Set_Is_Packed (Base_Type (Typ));
10358 Set_Has_Non_Standard_Rep (Base_Type (Typ));
10361 Set_Has_Pragma_Pack (Base_Type (Typ));
10363 -- If we ignore the pack for VM_Targets, then warn about
10364 -- this, except suppress the warning in GNAT mode.
10366 elsif not GNAT_Mode then
10368 ("?pragma% ignored in this configuration");
10372 -- For record types, the pack is always effective
10374 else pragma Assert (Is_Record_Type (Typ));
10375 if not Rep_Item_Too_Late (Typ, N) then
10376 if VM_Target = No_VM then
10377 Set_Is_Packed (Base_Type (Typ));
10378 Set_Has_Pragma_Pack (Base_Type (Typ));
10379 Set_Has_Non_Standard_Rep (Base_Type (Typ));
10381 elsif not GNAT_Mode then
10382 Error_Pragma ("?pragma% ignored in this configuration");
10394 -- There is nothing to do here, since we did all the processing for
10395 -- this pragma in Par.Prag (so that it works properly even in syntax
10398 when Pragma_Page =>
10405 -- pragma Passive [(PASSIVE_FORM)];
10407 -- PASSIVE_FORM ::= Semaphore | No
10409 when Pragma_Passive =>
10412 if Nkind (Parent (N)) /= N_Task_Definition then
10413 Error_Pragma ("pragma% must be within task definition");
10416 if Arg_Count /= 0 then
10417 Check_Arg_Count (1);
10418 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
10421 ----------------------------------
10422 -- Preelaborable_Initialization --
10423 ----------------------------------
10425 -- pragma Preelaborable_Initialization (DIRECT_NAME);
10427 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
10432 Check_Arg_Count (1);
10433 Check_No_Identifiers;
10434 Check_Arg_Is_Identifier (Arg1);
10435 Check_Arg_Is_Local_Name (Arg1);
10436 Check_First_Subtype (Arg1);
10437 Ent := Entity (Expression (Arg1));
10439 if not Is_Private_Type (Ent)
10440 and then not Is_Protected_Type (Ent)
10443 ("pragma % can only be applied to private or protected type",
10447 -- Give an error if the pragma is applied to a protected type that
10448 -- does not qualify (due to having entries, or due to components
10449 -- that do not qualify).
10451 if Is_Protected_Type (Ent)
10452 and then not Has_Preelaborable_Initialization (Ent)
10455 ("protected type & does not have preelaborable " &
10456 "initialization", Ent);
10458 -- Otherwise mark the type as definitely having preelaborable
10462 Set_Known_To_Have_Preelab_Init (Ent);
10465 if Has_Pragma_Preelab_Init (Ent)
10466 and then Warn_On_Redundant_Constructs
10468 Error_Pragma ("?duplicate pragma%!");
10470 Set_Has_Pragma_Preelab_Init (Ent);
10474 --------------------
10475 -- Persistent_BSS --
10476 --------------------
10478 -- pragma Persistent_BSS [(object_NAME)];
10480 when Pragma_Persistent_BSS => Persistent_BSS : declare
10487 Check_At_Most_N_Arguments (1);
10489 -- Case of application to specific object (one argument)
10491 if Arg_Count = 1 then
10492 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10494 if not Is_Entity_Name (Expression (Arg1))
10496 (Ekind (Entity (Expression (Arg1))) /= E_Variable
10497 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
10499 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
10502 Ent := Entity (Expression (Arg1));
10503 Decl := Parent (Ent);
10505 if Rep_Item_Too_Late (Ent, N) then
10509 if Present (Expression (Decl)) then
10511 ("object for pragma% cannot have initialization", Arg1);
10514 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
10516 ("object type for pragma% is not potentially persistent",
10521 Make_Linker_Section_Pragma
10522 (Ent, Sloc (N), ".persistent.bss");
10523 Insert_After (N, Prag);
10526 -- Case of use as configuration pragma with no arguments
10529 Check_Valid_Configuration_Pragma;
10530 Persistent_BSS_Mode := True;
10532 end Persistent_BSS;
10538 -- pragma Polling (ON | OFF);
10540 when Pragma_Polling =>
10542 Check_Arg_Count (1);
10543 Check_No_Identifiers;
10544 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10545 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
10547 -------------------
10548 -- Postcondition --
10549 -------------------
10551 -- pragma Postcondition ([Check =>] Boolean_Expression
10552 -- [,[Message =>] String_Expression]);
10554 when Pragma_Postcondition => Postcondition : declare
10556 pragma Warnings (Off, In_Body);
10560 Check_At_Least_N_Arguments (1);
10561 Check_At_Most_N_Arguments (2);
10562 Check_Optional_Identifier (Arg1, Name_Check);
10564 -- All we need to do here is call the common check procedure,
10565 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
10567 Check_Precondition_Postcondition (In_Body);
10574 -- pragma Precondition ([Check =>] Boolean_Expression
10575 -- [,[Message =>] String_Expression]);
10577 when Pragma_Precondition => Precondition : declare
10582 Check_At_Least_N_Arguments (1);
10583 Check_At_Most_N_Arguments (2);
10584 Check_Optional_Identifier (Arg1, Name_Check);
10586 Check_Precondition_Postcondition (In_Body);
10588 -- If in spec, nothing more to do. If in body, then we convert the
10589 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
10590 -- this whether or not precondition checks are enabled. That works
10591 -- fine since pragma Check will do this check, and will also
10592 -- analyze the condition itself in the proper context.
10595 if Arg_Count = 2 then
10596 Check_Optional_Identifier (Arg3, Name_Message);
10597 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
10602 Chars => Name_Check,
10603 Pragma_Argument_Associations => New_List (
10604 Make_Pragma_Argument_Association (Loc,
10606 Make_Identifier (Loc,
10607 Chars => Name_Precondition)),
10609 Make_Pragma_Argument_Association (Sloc (Arg1),
10610 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
10612 if Arg_Count = 2 then
10613 Append_To (Pragma_Argument_Associations (N),
10614 Make_Pragma_Argument_Association (Sloc (Arg2),
10615 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
10626 -- pragma Preelaborate [(library_unit_NAME)];
10628 -- Set the flag Is_Preelaborated of program unit name entity
10630 when Pragma_Preelaborate => Preelaborate : declare
10631 Pa : constant Node_Id := Parent (N);
10632 Pk : constant Node_Kind := Nkind (Pa);
10636 Check_Ada_83_Warning;
10637 Check_Valid_Library_Unit_Pragma;
10639 if Nkind (N) = N_Null_Statement then
10643 Ent := Find_Lib_Unit_Name;
10645 -- This filters out pragmas inside generic parent then
10646 -- show up inside instantiation
10649 and then not (Pk = N_Package_Specification
10650 and then Present (Generic_Parent (Pa)))
10652 if not Debug_Flag_U then
10653 Set_Is_Preelaborated (Ent);
10654 Set_Suppress_Elaboration_Warnings (Ent);
10659 ---------------------
10660 -- Preelaborate_05 --
10661 ---------------------
10663 -- pragma Preelaborate_05 [(library_unit_NAME)];
10665 -- This pragma is useable only in GNAT_Mode, where it is used like
10666 -- pragma Preelaborate but it is only effective in Ada 2005 mode
10667 -- (otherwise it is ignored). This is used to implement AI-362 which
10668 -- recategorizes some run-time packages in Ada 2005 mode.
10670 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
10675 Check_Valid_Library_Unit_Pragma;
10677 if not GNAT_Mode then
10678 Error_Pragma ("pragma% only available in GNAT mode");
10681 if Nkind (N) = N_Null_Statement then
10685 -- This is one of the few cases where we need to test the value of
10686 -- Ada_Version_Explicit rather than Ada_Version (which is always
10687 -- set to Ada_2012 in a predefined unit), we need to know the
10688 -- explicit version set to know if this pragma is active.
10690 if Ada_Version_Explicit >= Ada_05 then
10691 Ent := Find_Lib_Unit_Name;
10692 Set_Is_Preelaborated (Ent);
10693 Set_Suppress_Elaboration_Warnings (Ent);
10695 end Preelaborate_05;
10701 -- pragma Priority (EXPRESSION);
10703 when Pragma_Priority => Priority : declare
10704 P : constant Node_Id := Parent (N);
10708 Check_No_Identifiers;
10709 Check_Arg_Count (1);
10713 if Nkind (P) = N_Subprogram_Body then
10714 Check_In_Main_Program;
10716 Arg := Expression (Arg1);
10717 Analyze_And_Resolve (Arg, Standard_Integer);
10721 if not Is_Static_Expression (Arg) then
10722 Flag_Non_Static_Expr
10723 ("main subprogram priority is not static!", Arg);
10726 -- If constraint error, then we already signalled an error
10728 elsif Raises_Constraint_Error (Arg) then
10731 -- Otherwise check in range
10735 Val : constant Uint := Expr_Value (Arg);
10739 or else Val > Expr_Value (Expression
10740 (Parent (RTE (RE_Max_Priority))))
10743 ("main subprogram priority is out of range", Arg1);
10749 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
10751 -- Load an arbitrary entity from System.Tasking to make sure
10752 -- this package is implicitly with'ed, since we need to have
10753 -- the tasking run-time active for the pragma Priority to have
10757 Discard : Entity_Id;
10758 pragma Warnings (Off, Discard);
10760 Discard := RTE (RE_Task_List);
10763 -- Task or Protected, must be of type Integer
10765 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
10766 Arg := Expression (Arg1);
10768 -- The expression must be analyzed in the special manner
10769 -- described in "Handling of Default and Per-Object
10770 -- Expressions" in sem.ads.
10772 Preanalyze_Spec_Expression (Arg, Standard_Integer);
10774 if not Is_Static_Expression (Arg) then
10775 Check_Restriction (Static_Priorities, Arg);
10778 -- Anything else is incorrect
10784 if Has_Priority_Pragma (P) then
10785 Error_Pragma ("duplicate pragma% not allowed");
10787 Set_Has_Priority_Pragma (P, True);
10789 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
10790 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10791 -- exp_ch9 should use this ???
10796 -----------------------------------
10797 -- Priority_Specific_Dispatching --
10798 -----------------------------------
10800 -- pragma Priority_Specific_Dispatching (
10801 -- policy_IDENTIFIER,
10802 -- first_priority_EXPRESSION,
10803 -- last_priority_EXPRESSION);
10805 when Pragma_Priority_Specific_Dispatching =>
10806 Priority_Specific_Dispatching : declare
10807 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
10808 -- This is the entity System.Any_Priority;
10811 Lower_Bound : Node_Id;
10812 Upper_Bound : Node_Id;
10818 Check_Arg_Count (3);
10819 Check_No_Identifiers;
10820 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
10821 Check_Valid_Configuration_Pragma;
10822 Get_Name_String (Chars (Expression (Arg1)));
10823 DP := Fold_Upper (Name_Buffer (1));
10825 Lower_Bound := Expression (Arg2);
10826 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
10827 Lower_Val := Expr_Value (Lower_Bound);
10829 Upper_Bound := Expression (Arg3);
10830 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
10831 Upper_Val := Expr_Value (Upper_Bound);
10833 -- It is not allowed to use Task_Dispatching_Policy and
10834 -- Priority_Specific_Dispatching in the same partition.
10836 if Task_Dispatching_Policy /= ' ' then
10837 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10839 ("pragma% incompatible with Task_Dispatching_Policy#");
10841 -- Check lower bound in range
10843 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10845 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
10848 ("first_priority is out of range", Arg2);
10850 -- Check upper bound in range
10852 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10854 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
10857 ("last_priority is out of range", Arg3);
10859 -- Check that the priority range is valid
10861 elsif Lower_Val > Upper_Val then
10863 ("last_priority_expression must be greater than" &
10864 " or equal to first_priority_expression");
10866 -- Store the new policy, but always preserve System_Location since
10867 -- we like the error message with the run-time name.
10870 -- Check overlapping in the priority ranges specified in other
10871 -- Priority_Specific_Dispatching pragmas within the same
10872 -- partition. We can only check those we know about!
10875 Specific_Dispatching.First .. Specific_Dispatching.Last
10877 if Specific_Dispatching.Table (J).First_Priority in
10878 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10879 or else Specific_Dispatching.Table (J).Last_Priority in
10880 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10883 Specific_Dispatching.Table (J).Pragma_Loc;
10885 ("priority range overlaps with "
10886 & "Priority_Specific_Dispatching#");
10890 -- The use of Priority_Specific_Dispatching is incompatible
10891 -- with Task_Dispatching_Policy.
10893 if Task_Dispatching_Policy /= ' ' then
10894 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10896 ("Priority_Specific_Dispatching incompatible "
10897 & "with Task_Dispatching_Policy#");
10900 -- The use of Priority_Specific_Dispatching forces ceiling
10903 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
10904 Error_Msg_Sloc := Locking_Policy_Sloc;
10906 ("Priority_Specific_Dispatching incompatible "
10907 & "with Locking_Policy#");
10909 -- Set the Ceiling_Locking policy, but preserve System_Location
10910 -- since we like the error message with the run time name.
10913 Locking_Policy := 'C';
10915 if Locking_Policy_Sloc /= System_Location then
10916 Locking_Policy_Sloc := Loc;
10920 -- Add entry in the table
10922 Specific_Dispatching.Append
10923 ((Dispatching_Policy => DP,
10924 First_Priority => UI_To_Int (Lower_Val),
10925 Last_Priority => UI_To_Int (Upper_Val),
10926 Pragma_Loc => Loc));
10928 end Priority_Specific_Dispatching;
10934 -- pragma Profile (profile_IDENTIFIER);
10936 -- profile_IDENTIFIER => Restricted | Ravenscar
10938 when Pragma_Profile =>
10940 Check_Arg_Count (1);
10941 Check_Valid_Configuration_Pragma;
10942 Check_No_Identifiers;
10945 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10947 if Chars (Argx) = Name_Ravenscar then
10948 Set_Ravenscar_Profile (N);
10949 elsif Chars (Argx) = Name_Restricted then
10950 Set_Profile_Restrictions
10951 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10953 Error_Pragma_Arg ("& is not a valid profile", Argx);
10957 ----------------------
10958 -- Profile_Warnings --
10959 ----------------------
10961 -- pragma Profile_Warnings (profile_IDENTIFIER);
10963 -- profile_IDENTIFIER => Restricted | Ravenscar
10965 when Pragma_Profile_Warnings =>
10967 Check_Arg_Count (1);
10968 Check_Valid_Configuration_Pragma;
10969 Check_No_Identifiers;
10972 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10974 if Chars (Argx) = Name_Ravenscar then
10975 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
10976 elsif Chars (Argx) = Name_Restricted then
10977 Set_Profile_Restrictions (Restricted, N, Warn => True);
10979 Error_Pragma_Arg ("& is not a valid profile", Argx);
10983 --------------------------
10984 -- Propagate_Exceptions --
10985 --------------------------
10987 -- pragma Propagate_Exceptions;
10989 -- Note: this pragma is obsolete and has no effect
10991 when Pragma_Propagate_Exceptions =>
10993 Check_Arg_Count (0);
10995 if In_Extended_Main_Source_Unit (N) then
10996 Propagate_Exceptions := True;
11003 -- pragma Psect_Object (
11004 -- [Internal =>] LOCAL_NAME,
11005 -- [, [External =>] EXTERNAL_SYMBOL]
11006 -- [, [Size =>] EXTERNAL_SYMBOL]);
11008 when Pragma_Psect_Object | Pragma_Common_Object =>
11009 Psect_Object : declare
11010 Args : Args_List (1 .. 3);
11011 Names : constant Name_List (1 .. 3) := (
11016 Internal : Node_Id renames Args (1);
11017 External : Node_Id renames Args (2);
11018 Size : Node_Id renames Args (3);
11020 Def_Id : Entity_Id;
11022 procedure Check_Too_Long (Arg : Node_Id);
11023 -- Posts message if the argument is an identifier with more
11024 -- than 31 characters, or a string literal with more than
11025 -- 31 characters, and we are operating under VMS
11027 --------------------
11028 -- Check_Too_Long --
11029 --------------------
11031 procedure Check_Too_Long (Arg : Node_Id) is
11032 X : constant Node_Id := Original_Node (Arg);
11035 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11037 ("inappropriate argument for pragma %", Arg);
11040 if OpenVMS_On_Target then
11041 if (Nkind (X) = N_String_Literal
11042 and then String_Length (Strval (X)) > 31)
11044 (Nkind (X) = N_Identifier
11045 and then Length_Of_Name (Chars (X)) > 31)
11048 ("argument for pragma % is longer than 31 characters",
11052 end Check_Too_Long;
11054 -- Start of processing for Common_Object/Psect_Object
11058 Gather_Associations (Names, Args);
11059 Process_Extended_Import_Export_Internal_Arg (Internal);
11061 Def_Id := Entity (Internal);
11063 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11065 ("pragma% must designate an object", Internal);
11068 Check_Too_Long (Internal);
11070 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11072 ("cannot use pragma% for imported/exported object",
11076 if Is_Concurrent_Type (Etype (Internal)) then
11078 ("cannot specify pragma % for task/protected object",
11082 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11084 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11086 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11089 if Ekind (Def_Id) = E_Constant then
11091 ("cannot specify pragma % for a constant", Internal);
11094 if Is_Record_Type (Etype (Internal)) then
11100 Ent := First_Entity (Etype (Internal));
11101 while Present (Ent) loop
11102 Decl := Declaration_Node (Ent);
11104 if Ekind (Ent) = E_Component
11105 and then Nkind (Decl) = N_Component_Declaration
11106 and then Present (Expression (Decl))
11107 and then Warn_On_Export_Import
11110 ("?object for pragma % has defaults", Internal);
11120 if Present (Size) then
11121 Check_Too_Long (Size);
11124 if Present (External) then
11125 Check_Arg_Is_External_Name (External);
11126 Check_Too_Long (External);
11129 -- If all error tests pass, link pragma on to the rep item chain
11131 Record_Rep_Item (Def_Id, N);
11138 -- pragma Pure [(library_unit_NAME)];
11140 when Pragma_Pure => Pure : declare
11144 Check_Ada_83_Warning;
11145 Check_Valid_Library_Unit_Pragma;
11147 if Nkind (N) = N_Null_Statement then
11151 Ent := Find_Lib_Unit_Name;
11153 Set_Has_Pragma_Pure (Ent);
11154 Set_Suppress_Elaboration_Warnings (Ent);
11161 -- pragma Pure_05 [(library_unit_NAME)];
11163 -- This pragma is useable only in GNAT_Mode, where it is used like
11164 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11165 -- it is ignored). It may be used after a pragma Preelaborate, in
11166 -- which case it overrides the effect of the pragma Preelaborate.
11167 -- This is used to implement AI-362 which recategorizes some run-time
11168 -- packages in Ada 2005 mode.
11170 when Pragma_Pure_05 => Pure_05 : declare
11175 Check_Valid_Library_Unit_Pragma;
11177 if not GNAT_Mode then
11178 Error_Pragma ("pragma% only available in GNAT mode");
11181 if Nkind (N) = N_Null_Statement then
11185 -- This is one of the few cases where we need to test the value of
11186 -- Ada_Version_Explicit rather than Ada_Version (which is always
11187 -- set to Ada_2012 in a predefined unit), we need to know the
11188 -- explicit version set to know if this pragma is active.
11190 if Ada_Version_Explicit >= Ada_05 then
11191 Ent := Find_Lib_Unit_Name;
11192 Set_Is_Preelaborated (Ent, False);
11194 Set_Suppress_Elaboration_Warnings (Ent);
11198 -------------------
11199 -- Pure_Function --
11200 -------------------
11202 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11204 when Pragma_Pure_Function => Pure_Function : declare
11207 Def_Id : Entity_Id;
11208 Effective : Boolean := False;
11212 Check_Arg_Count (1);
11213 Check_Optional_Identifier (Arg1, Name_Entity);
11214 Check_Arg_Is_Local_Name (Arg1);
11215 E_Id := Expression (Arg1);
11217 if Error_Posted (E_Id) then
11221 -- Loop through homonyms (overloadings) of referenced entity
11223 E := Entity (E_Id);
11225 if Present (E) then
11227 Def_Id := Get_Base_Subprogram (E);
11229 if not Ekind_In (Def_Id, E_Function,
11230 E_Generic_Function,
11234 ("pragma% requires a function name", Arg1);
11237 Set_Is_Pure (Def_Id);
11239 if not Has_Pragma_Pure_Function (Def_Id) then
11240 Set_Has_Pragma_Pure_Function (Def_Id);
11245 exit when No (E) or else Scope (E) /= Current_Scope;
11249 and then Warn_On_Redundant_Constructs
11252 ("pragma Pure_Function on& is redundant?",
11258 --------------------
11259 -- Queuing_Policy --
11260 --------------------
11262 -- pragma Queuing_Policy (policy_IDENTIFIER);
11264 when Pragma_Queuing_Policy => declare
11268 Check_Ada_83_Warning;
11269 Check_Arg_Count (1);
11270 Check_No_Identifiers;
11271 Check_Arg_Is_Queuing_Policy (Arg1);
11272 Check_Valid_Configuration_Pragma;
11273 Get_Name_String (Chars (Expression (Arg1)));
11274 QP := Fold_Upper (Name_Buffer (1));
11276 if Queuing_Policy /= ' '
11277 and then Queuing_Policy /= QP
11279 Error_Msg_Sloc := Queuing_Policy_Sloc;
11280 Error_Pragma ("queuing policy incompatible with policy#");
11282 -- Set new policy, but always preserve System_Location since we
11283 -- like the error message with the run time name.
11286 Queuing_Policy := QP;
11288 if Queuing_Policy_Sloc /= System_Location then
11289 Queuing_Policy_Sloc := Loc;
11294 -----------------------
11295 -- Relative_Deadline --
11296 -----------------------
11298 -- pragma Relative_Deadline (time_span_EXPRESSION);
11300 when Pragma_Relative_Deadline => Relative_Deadline : declare
11301 P : constant Node_Id := Parent (N);
11306 Check_No_Identifiers;
11307 Check_Arg_Count (1);
11309 Arg := Expression (Arg1);
11311 -- The expression must be analyzed in the special manner described
11312 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
11314 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
11318 if Nkind (P) = N_Subprogram_Body then
11319 Check_In_Main_Program;
11323 elsif Nkind (P) = N_Task_Definition then
11326 -- Anything else is incorrect
11332 if Has_Relative_Deadline_Pragma (P) then
11333 Error_Pragma ("duplicate pragma% not allowed");
11335 Set_Has_Relative_Deadline_Pragma (P, True);
11337 if Nkind (P) = N_Task_Definition then
11338 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11341 end Relative_Deadline;
11343 ---------------------------
11344 -- Remote_Call_Interface --
11345 ---------------------------
11347 -- pragma Remote_Call_Interface [(library_unit_NAME)];
11349 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
11350 Cunit_Node : Node_Id;
11351 Cunit_Ent : Entity_Id;
11355 Check_Ada_83_Warning;
11356 Check_Valid_Library_Unit_Pragma;
11358 if Nkind (N) = N_Null_Statement then
11362 Cunit_Node := Cunit (Current_Sem_Unit);
11363 K := Nkind (Unit (Cunit_Node));
11364 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
11366 if K = N_Package_Declaration
11367 or else K = N_Generic_Package_Declaration
11368 or else K = N_Subprogram_Declaration
11369 or else K = N_Generic_Subprogram_Declaration
11370 or else (K = N_Subprogram_Body
11371 and then Acts_As_Spec (Unit (Cunit_Node)))
11376 "pragma% must apply to package or subprogram declaration");
11379 Set_Is_Remote_Call_Interface (Cunit_Ent);
11380 end Remote_Call_Interface;
11386 -- pragma Remote_Types [(library_unit_NAME)];
11388 when Pragma_Remote_Types => Remote_Types : declare
11389 Cunit_Node : Node_Id;
11390 Cunit_Ent : Entity_Id;
11393 Check_Ada_83_Warning;
11394 Check_Valid_Library_Unit_Pragma;
11396 if Nkind (N) = N_Null_Statement then
11400 Cunit_Node := Cunit (Current_Sem_Unit);
11401 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
11403 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
11404 N_Generic_Package_Declaration)
11407 ("pragma% can only apply to a package declaration");
11410 Set_Is_Remote_Types (Cunit_Ent);
11417 -- pragma Ravenscar;
11419 when Pragma_Ravenscar =>
11421 Check_Arg_Count (0);
11422 Check_Valid_Configuration_Pragma;
11423 Set_Ravenscar_Profile (N);
11425 if Warn_On_Obsolescent_Feature then
11426 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
11427 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
11430 -------------------------
11431 -- Restricted_Run_Time --
11432 -------------------------
11434 -- pragma Restricted_Run_Time;
11436 when Pragma_Restricted_Run_Time =>
11438 Check_Arg_Count (0);
11439 Check_Valid_Configuration_Pragma;
11440 Set_Profile_Restrictions
11441 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11443 if Warn_On_Obsolescent_Feature then
11445 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
11446 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
11453 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
11456 -- restriction_IDENTIFIER
11457 -- | restriction_parameter_IDENTIFIER => EXPRESSION
11459 when Pragma_Restrictions =>
11460 Process_Restrictions_Or_Restriction_Warnings
11461 (Warn => Treat_Restrictions_As_Warnings);
11463 --------------------------
11464 -- Restriction_Warnings --
11465 --------------------------
11467 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
11470 -- restriction_IDENTIFIER
11471 -- | restriction_parameter_IDENTIFIER => EXPRESSION
11473 when Pragma_Restriction_Warnings =>
11475 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
11481 -- pragma Reviewable;
11483 when Pragma_Reviewable =>
11484 Check_Ada_83_Warning;
11485 Check_Arg_Count (0);
11487 -- Call dummy debugging function rv. This is done to assist front
11488 -- end debugging. By placing a Reviewable pragma in the source
11489 -- program, a breakpoint on rv catches this place in the source,
11490 -- allowing convenient stepping to the point of interest.
11494 --------------------------
11495 -- Short_Circuit_And_Or --
11496 --------------------------
11498 when Pragma_Short_Circuit_And_Or =>
11500 Check_Arg_Count (0);
11501 Check_Valid_Configuration_Pragma;
11502 Short_Circuit_And_Or := True;
11504 -------------------
11505 -- Share_Generic --
11506 -------------------
11508 -- pragma Share_Generic (NAME {, NAME});
11510 when Pragma_Share_Generic =>
11512 Process_Generic_List;
11518 -- pragma Shared (LOCAL_NAME);
11520 when Pragma_Shared =>
11522 Process_Atomic_Shared_Volatile;
11524 --------------------
11525 -- Shared_Passive --
11526 --------------------
11528 -- pragma Shared_Passive [(library_unit_NAME)];
11530 -- Set the flag Is_Shared_Passive of program unit name entity
11532 when Pragma_Shared_Passive => Shared_Passive : declare
11533 Cunit_Node : Node_Id;
11534 Cunit_Ent : Entity_Id;
11537 Check_Ada_83_Warning;
11538 Check_Valid_Library_Unit_Pragma;
11540 if Nkind (N) = N_Null_Statement then
11544 Cunit_Node := Cunit (Current_Sem_Unit);
11545 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
11547 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
11548 N_Generic_Package_Declaration)
11551 ("pragma% can only apply to a package declaration");
11554 Set_Is_Shared_Passive (Cunit_Ent);
11555 end Shared_Passive;
11557 -----------------------
11558 -- Short_Descriptors --
11559 -----------------------
11561 -- pragma Short_Descriptors;
11563 when Pragma_Short_Descriptors =>
11565 Check_Arg_Count (0);
11566 Check_Valid_Configuration_Pragma;
11567 Short_Descriptors := True;
11569 ----------------------
11570 -- Source_File_Name --
11571 ----------------------
11573 -- There are five forms for this pragma:
11575 -- pragma Source_File_Name (
11576 -- [UNIT_NAME =>] unit_NAME,
11577 -- BODY_FILE_NAME => STRING_LITERAL
11578 -- [, [INDEX =>] INTEGER_LITERAL]);
11580 -- pragma Source_File_Name (
11581 -- [UNIT_NAME =>] unit_NAME,
11582 -- SPEC_FILE_NAME => STRING_LITERAL
11583 -- [, [INDEX =>] INTEGER_LITERAL]);
11585 -- pragma Source_File_Name (
11586 -- BODY_FILE_NAME => STRING_LITERAL
11587 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11588 -- [, CASING => CASING_SPEC]);
11590 -- pragma Source_File_Name (
11591 -- SPEC_FILE_NAME => STRING_LITERAL
11592 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11593 -- [, CASING => CASING_SPEC]);
11595 -- pragma Source_File_Name (
11596 -- SUBUNIT_FILE_NAME => STRING_LITERAL
11597 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11598 -- [, CASING => CASING_SPEC]);
11600 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
11602 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
11603 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
11604 -- only be used when no project file is used, while SFNP can only be
11605 -- used when a project file is used.
11607 -- No processing here. Processing was completed during parsing, since
11608 -- we need to have file names set as early as possible. Units are
11609 -- loaded well before semantic processing starts.
11611 -- The only processing we defer to this point is the check for
11612 -- correct placement.
11614 when Pragma_Source_File_Name =>
11616 Check_Valid_Configuration_Pragma;
11618 ------------------------------
11619 -- Source_File_Name_Project --
11620 ------------------------------
11622 -- See Source_File_Name for syntax
11624 -- No processing here. Processing was completed during parsing, since
11625 -- we need to have file names set as early as possible. Units are
11626 -- loaded well before semantic processing starts.
11628 -- The only processing we defer to this point is the check for
11629 -- correct placement.
11631 when Pragma_Source_File_Name_Project =>
11633 Check_Valid_Configuration_Pragma;
11635 -- Check that a pragma Source_File_Name_Project is used only in a
11636 -- configuration pragmas file.
11638 -- Pragmas Source_File_Name_Project should only be generated by
11639 -- the Project Manager in configuration pragmas files.
11641 -- This is really an ugly test. It seems to depend on some
11642 -- accidental and undocumented property. At the very least it
11643 -- needs to be documented, but it would be better to have a
11644 -- clean way of testing if we are in a configuration file???
11646 if Present (Parent (N)) then
11648 ("pragma% can only appear in a configuration pragmas file");
11651 ----------------------
11652 -- Source_Reference --
11653 ----------------------
11655 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
11657 -- Nothing to do, all processing completed in Par.Prag, since we need
11658 -- the information for possible parser messages that are output.
11660 when Pragma_Source_Reference =>
11663 --------------------------------
11664 -- Static_Elaboration_Desired --
11665 --------------------------------
11667 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
11669 when Pragma_Static_Elaboration_Desired =>
11671 Check_At_Most_N_Arguments (1);
11673 if Is_Compilation_Unit (Current_Scope)
11674 and then Ekind (Current_Scope) = E_Package
11676 Set_Static_Elaboration_Desired (Current_Scope, True);
11678 Error_Pragma ("pragma% must apply to a library-level package");
11685 -- pragma Storage_Size (EXPRESSION);
11687 when Pragma_Storage_Size => Storage_Size : declare
11688 P : constant Node_Id := Parent (N);
11692 Check_No_Identifiers;
11693 Check_Arg_Count (1);
11695 -- The expression must be analyzed in the special manner described
11696 -- in "Handling of Default Expressions" in sem.ads.
11698 Arg := Expression (Arg1);
11699 Preanalyze_Spec_Expression (Arg, Any_Integer);
11701 if not Is_Static_Expression (Arg) then
11702 Check_Restriction (Static_Storage_Size, Arg);
11705 if Nkind (P) /= N_Task_Definition then
11710 if Has_Storage_Size_Pragma (P) then
11711 Error_Pragma ("duplicate pragma% not allowed");
11713 Set_Has_Storage_Size_Pragma (P, True);
11716 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11717 -- ??? exp_ch9 should use this!
11725 -- pragma Storage_Unit (NUMERIC_LITERAL);
11727 -- Only permitted argument is System'Storage_Unit value
11729 when Pragma_Storage_Unit =>
11730 Check_No_Identifiers;
11731 Check_Arg_Count (1);
11732 Check_Arg_Is_Integer_Literal (Arg1);
11734 if Intval (Expression (Arg1)) /=
11735 UI_From_Int (Ttypes.System_Storage_Unit)
11737 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
11739 ("the only allowed argument for pragma% is ^", Arg1);
11742 --------------------
11743 -- Stream_Convert --
11744 --------------------
11746 -- pragma Stream_Convert (
11747 -- [Entity =>] type_LOCAL_NAME,
11748 -- [Read =>] function_NAME,
11749 -- [Write =>] function NAME);
11751 when Pragma_Stream_Convert => Stream_Convert : declare
11753 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
11754 -- Check that the given argument is the name of a local function
11755 -- of one argument that is not overloaded earlier in the current
11756 -- local scope. A check is also made that the argument is a
11757 -- function with one parameter.
11759 --------------------------------------
11760 -- Check_OK_Stream_Convert_Function --
11761 --------------------------------------
11763 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
11767 Check_Arg_Is_Local_Name (Arg);
11768 Ent := Entity (Expression (Arg));
11770 if Has_Homonym (Ent) then
11772 ("argument for pragma% may not be overloaded", Arg);
11775 if Ekind (Ent) /= E_Function
11776 or else No (First_Formal (Ent))
11777 or else Present (Next_Formal (First_Formal (Ent)))
11780 ("argument for pragma% must be" &
11781 " function of one argument", Arg);
11783 end Check_OK_Stream_Convert_Function;
11785 -- Start of processing for Stream_Convert
11789 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
11790 Check_Arg_Count (3);
11791 Check_Optional_Identifier (Arg1, Name_Entity);
11792 Check_Optional_Identifier (Arg2, Name_Read);
11793 Check_Optional_Identifier (Arg3, Name_Write);
11794 Check_Arg_Is_Local_Name (Arg1);
11795 Check_OK_Stream_Convert_Function (Arg2);
11796 Check_OK_Stream_Convert_Function (Arg3);
11799 Typ : constant Entity_Id :=
11800 Underlying_Type (Entity (Expression (Arg1)));
11801 Read : constant Entity_Id := Entity (Expression (Arg2));
11802 Write : constant Entity_Id := Entity (Expression (Arg3));
11805 Check_First_Subtype (Arg1);
11807 -- Check for too early or too late. Note that we don't enforce
11808 -- the rule about primitive operations in this case, since, as
11809 -- is the case for explicit stream attributes themselves, these
11810 -- restrictions are not appropriate. Note that the chaining of
11811 -- the pragma by Rep_Item_Too_Late is actually the critical
11812 -- processing done for this pragma.
11814 if Rep_Item_Too_Early (Typ, N)
11816 Rep_Item_Too_Late (Typ, N, FOnly => True)
11821 -- Return if previous error
11823 if Etype (Typ) = Any_Type
11825 Etype (Read) = Any_Type
11827 Etype (Write) = Any_Type
11834 if Underlying_Type (Etype (Read)) /= Typ then
11836 ("incorrect return type for function&", Arg2);
11839 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
11841 ("incorrect parameter type for function&", Arg3);
11844 if Underlying_Type (Etype (First_Formal (Read))) /=
11845 Underlying_Type (Etype (Write))
11848 ("result type of & does not match Read parameter type",
11852 end Stream_Convert;
11854 -------------------------
11855 -- Style_Checks (GNAT) --
11856 -------------------------
11858 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11860 -- This is processed by the parser since some of the style checks
11861 -- take place during source scanning and parsing. This means that
11862 -- we don't need to issue error messages here.
11864 when Pragma_Style_Checks => Style_Checks : declare
11865 A : constant Node_Id := Expression (Arg1);
11871 Check_No_Identifiers;
11873 -- Two argument form
11875 if Arg_Count = 2 then
11876 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11883 E_Id := Expression (Arg2);
11886 if not Is_Entity_Name (E_Id) then
11888 ("second argument of pragma% must be entity name",
11892 E := Entity (E_Id);
11898 Set_Suppress_Style_Checks (E,
11899 (Chars (Expression (Arg1)) = Name_Off));
11900 exit when No (Homonym (E));
11906 -- One argument form
11909 Check_Arg_Count (1);
11911 if Nkind (A) = N_String_Literal then
11915 Slen : constant Natural := Natural (String_Length (S));
11916 Options : String (1 .. Slen);
11922 C := Get_String_Char (S, Int (J));
11923 exit when not In_Character_Range (C);
11924 Options (J) := Get_Character (C);
11926 -- If at end of string, set options. As per discussion
11927 -- above, no need to check for errors, since we issued
11928 -- them in the parser.
11931 Set_Style_Check_Options (Options);
11939 elsif Nkind (A) = N_Identifier then
11940 if Chars (A) = Name_All_Checks then
11942 Set_GNAT_Style_Check_Options;
11944 Set_Default_Style_Check_Options;
11947 elsif Chars (A) = Name_On then
11948 Style_Check := True;
11950 elsif Chars (A) = Name_Off then
11951 Style_Check := False;
11961 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
11963 when Pragma_Subtitle =>
11965 Check_Arg_Count (1);
11966 Check_Optional_Identifier (Arg1, Name_Subtitle);
11967 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11974 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
11976 when Pragma_Suppress =>
11977 Process_Suppress_Unsuppress (True);
11983 -- pragma Suppress_All;
11985 -- The only check made here is that the pragma appears in the proper
11986 -- place, i.e. following a compilation unit. If indeed it appears in
11987 -- this context, then the parser has already inserted an equivalent
11988 -- pragma Suppress (All_Checks) to get the required effect.
11990 when Pragma_Suppress_All =>
11992 Check_Arg_Count (0);
11994 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
11995 or else not Is_List_Member (N)
11996 or else List_Containing (N) /= Pragmas_After (Parent (N))
11999 ("misplaced pragma%, must follow compilation unit");
12002 -------------------------
12003 -- Suppress_Debug_Info --
12004 -------------------------
12006 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12008 when Pragma_Suppress_Debug_Info =>
12010 Check_Arg_Count (1);
12011 Check_Optional_Identifier (Arg1, Name_Entity);
12012 Check_Arg_Is_Local_Name (Arg1);
12013 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
12015 ----------------------------------
12016 -- Suppress_Exception_Locations --
12017 ----------------------------------
12019 -- pragma Suppress_Exception_Locations;
12021 when Pragma_Suppress_Exception_Locations =>
12023 Check_Arg_Count (0);
12024 Check_Valid_Configuration_Pragma;
12025 Exception_Locations_Suppressed := True;
12027 -----------------------------
12028 -- Suppress_Initialization --
12029 -----------------------------
12031 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12033 when Pragma_Suppress_Initialization => Suppress_Init : declare
12039 Check_Arg_Count (1);
12040 Check_Optional_Identifier (Arg1, Name_Entity);
12041 Check_Arg_Is_Local_Name (Arg1);
12043 E_Id := Expression (Arg1);
12045 if Etype (E_Id) = Any_Type then
12049 E := Entity (E_Id);
12051 if Is_Type (E) then
12052 if Is_Incomplete_Or_Private_Type (E) then
12053 if No (Full_View (Base_Type (E))) then
12055 ("argument of pragma% cannot be an incomplete type",
12058 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12061 Set_Suppress_Init_Proc (Base_Type (E));
12066 ("pragma% requires argument that is a type name", Arg1);
12074 -- pragma System_Name (DIRECT_NAME);
12076 -- Syntax check: one argument, which must be the identifier GNAT or
12077 -- the identifier GCC, no other identifiers are acceptable.
12079 when Pragma_System_Name =>
12081 Check_No_Identifiers;
12082 Check_Arg_Count (1);
12083 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12085 -----------------------------
12086 -- Task_Dispatching_Policy --
12087 -----------------------------
12089 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12091 when Pragma_Task_Dispatching_Policy => declare
12095 Check_Ada_83_Warning;
12096 Check_Arg_Count (1);
12097 Check_No_Identifiers;
12098 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12099 Check_Valid_Configuration_Pragma;
12100 Get_Name_String (Chars (Expression (Arg1)));
12101 DP := Fold_Upper (Name_Buffer (1));
12103 if Task_Dispatching_Policy /= ' '
12104 and then Task_Dispatching_Policy /= DP
12106 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12108 ("task dispatching policy incompatible with policy#");
12110 -- Set new policy, but always preserve System_Location since we
12111 -- like the error message with the run time name.
12114 Task_Dispatching_Policy := DP;
12116 if Task_Dispatching_Policy_Sloc /= System_Location then
12117 Task_Dispatching_Policy_Sloc := Loc;
12126 -- pragma Task_Info (EXPRESSION);
12128 when Pragma_Task_Info => Task_Info : declare
12129 P : constant Node_Id := Parent (N);
12134 if Nkind (P) /= N_Task_Definition then
12135 Error_Pragma ("pragma% must appear in task definition");
12138 Check_No_Identifiers;
12139 Check_Arg_Count (1);
12141 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
12143 if Etype (Expression (Arg1)) = Any_Type then
12147 if Has_Task_Info_Pragma (P) then
12148 Error_Pragma ("duplicate pragma% not allowed");
12150 Set_Has_Task_Info_Pragma (P, True);
12158 -- pragma Task_Name (string_EXPRESSION);
12160 when Pragma_Task_Name => Task_Name : declare
12161 P : constant Node_Id := Parent (N);
12165 Check_No_Identifiers;
12166 Check_Arg_Count (1);
12168 Arg := Expression (Arg1);
12170 -- The expression is used in the call to Create_Task, and must be
12171 -- expanded there, not in the context of the current spec. It must
12172 -- however be analyzed to capture global references, in case it
12173 -- appears in a generic context.
12175 Preanalyze_And_Resolve (Arg, Standard_String);
12177 if Nkind (P) /= N_Task_Definition then
12181 if Has_Task_Name_Pragma (P) then
12182 Error_Pragma ("duplicate pragma% not allowed");
12184 Set_Has_Task_Name_Pragma (P, True);
12185 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12193 -- pragma Task_Storage (
12194 -- [Task_Type =>] LOCAL_NAME,
12195 -- [Top_Guard =>] static_integer_EXPRESSION);
12197 when Pragma_Task_Storage => Task_Storage : declare
12198 Args : Args_List (1 .. 2);
12199 Names : constant Name_List (1 .. 2) := (
12203 Task_Type : Node_Id renames Args (1);
12204 Top_Guard : Node_Id renames Args (2);
12210 Gather_Associations (Names, Args);
12212 if No (Task_Type) then
12214 ("missing task_type argument for pragma%");
12217 Check_Arg_Is_Local_Name (Task_Type);
12219 Ent := Entity (Task_Type);
12221 if not Is_Task_Type (Ent) then
12223 ("argument for pragma% must be task type", Task_Type);
12226 if No (Top_Guard) then
12228 ("pragma% takes two arguments", Task_Type);
12230 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12233 Check_First_Subtype (Task_Type);
12235 if Rep_Item_Too_Late (Ent, N) then
12240 --------------------------
12241 -- Thread_Local_Storage --
12242 --------------------------
12244 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12246 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
12252 Check_Arg_Count (1);
12253 Check_Optional_Identifier (Arg1, Name_Entity);
12254 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12256 Id := Expression (Arg1);
12259 if not Is_Entity_Name (Id)
12260 or else Ekind (Entity (Id)) /= E_Variable
12262 Error_Pragma_Arg ("local variable name required", Arg1);
12267 if Rep_Item_Too_Early (E, N)
12268 or else Rep_Item_Too_Late (E, N)
12273 Set_Has_Pragma_Thread_Local_Storage (E);
12274 Set_Has_Gigi_Rep_Item (E);
12275 end Thread_Local_Storage;
12281 -- pragma Time_Slice (static_duration_EXPRESSION);
12283 when Pragma_Time_Slice => Time_Slice : declare
12289 Check_Arg_Count (1);
12290 Check_No_Identifiers;
12291 Check_In_Main_Program;
12292 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
12294 if not Error_Posted (Arg1) then
12296 while Present (Nod) loop
12297 if Nkind (Nod) = N_Pragma
12298 and then Pragma_Name (Nod) = Name_Time_Slice
12300 Error_Msg_Name_1 := Pname;
12301 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12308 -- Process only if in main unit
12310 if Get_Source_Unit (Loc) = Main_Unit then
12311 Opt.Time_Slice_Set := True;
12312 Val := Expr_Value_R (Expression (Arg1));
12314 if Val <= Ureal_0 then
12315 Opt.Time_Slice_Value := 0;
12317 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
12318 Opt.Time_Slice_Value := 1_000_000_000;
12321 Opt.Time_Slice_Value :=
12322 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
12331 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
12333 -- TITLING_OPTION ::=
12334 -- [Title =>] STRING_LITERAL
12335 -- | [Subtitle =>] STRING_LITERAL
12337 when Pragma_Title => Title : declare
12338 Args : Args_List (1 .. 2);
12339 Names : constant Name_List (1 .. 2) := (
12345 Gather_Associations (Names, Args);
12348 for J in 1 .. 2 loop
12349 if Present (Args (J)) then
12350 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
12355 ---------------------
12356 -- Unchecked_Union --
12357 ---------------------
12359 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
12361 when Pragma_Unchecked_Union => Unchecked_Union : declare
12362 Assoc : constant Node_Id := Arg1;
12363 Type_Id : constant Node_Id := Expression (Assoc);
12374 Check_No_Identifiers;
12375 Check_Arg_Count (1);
12376 Check_Arg_Is_Local_Name (Arg1);
12378 Find_Type (Type_Id);
12379 Typ := Entity (Type_Id);
12382 or else Rep_Item_Too_Early (Typ, N)
12386 Typ := Underlying_Type (Typ);
12389 if Rep_Item_Too_Late (Typ, N) then
12393 Check_First_Subtype (Arg1);
12395 -- Note remaining cases are references to a type in the current
12396 -- declarative part. If we find an error, we post the error on
12397 -- the relevant type declaration at an appropriate point.
12399 if not Is_Record_Type (Typ) then
12400 Error_Msg_N ("Unchecked_Union must be record type", Typ);
12403 elsif Is_Tagged_Type (Typ) then
12404 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
12407 elsif Is_Limited_Type (Typ) then
12409 ("Unchecked_Union must not be limited record type", Typ);
12410 Explain_Limited_Type (Typ, Typ);
12414 if not Has_Discriminants (Typ) then
12416 ("Unchecked_Union must have one discriminant", Typ);
12420 Discr := First_Discriminant (Typ);
12421 while Present (Discr) loop
12422 if No (Discriminant_Default_Value (Discr)) then
12424 ("Unchecked_Union discriminant must have default value",
12427 Next_Discriminant (Discr);
12430 Tdef := Type_Definition (Declaration_Node (Typ));
12431 Clist := Component_List (Tdef);
12433 Comp := First (Component_Items (Clist));
12434 while Present (Comp) loop
12435 Check_Component (Comp, Typ);
12439 if No (Clist) or else No (Variant_Part (Clist)) then
12441 ("Unchecked_Union must have variant part",
12446 Vpart := Variant_Part (Clist);
12448 Variant := First (Variants (Vpart));
12449 while Present (Variant) loop
12450 Check_Variant (Variant, Typ);
12455 Set_Is_Unchecked_Union (Typ, True);
12456 Set_Convention (Typ, Convention_C);
12458 Set_Has_Unchecked_Union (Base_Type (Typ), True);
12459 Set_Is_Unchecked_Union (Base_Type (Typ), True);
12460 end Unchecked_Union;
12462 ------------------------
12463 -- Unimplemented_Unit --
12464 ------------------------
12466 -- pragma Unimplemented_Unit;
12468 -- Note: this only gives an error if we are generating code, or if
12469 -- we are in a generic library unit (where the pragma appears in the
12470 -- body, not in the spec).
12472 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
12473 Cunitent : constant Entity_Id :=
12474 Cunit_Entity (Get_Source_Unit (Loc));
12475 Ent_Kind : constant Entity_Kind :=
12480 Check_Arg_Count (0);
12482 if Operating_Mode = Generate_Code
12483 or else Ent_Kind = E_Generic_Function
12484 or else Ent_Kind = E_Generic_Procedure
12485 or else Ent_Kind = E_Generic_Package
12487 Get_Name_String (Chars (Cunitent));
12488 Set_Casing (Mixed_Case);
12489 Write_Str (Name_Buffer (1 .. Name_Len));
12490 Write_Str (" is not supported in this configuration");
12492 raise Unrecoverable_Error;
12494 end Unimplemented_Unit;
12496 ------------------------
12497 -- Universal_Aliasing --
12498 ------------------------
12500 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
12502 when Pragma_Universal_Aliasing => Universal_Alias : declare
12507 Check_Arg_Count (1);
12508 Check_Optional_Identifier (Arg2, Name_Entity);
12509 Check_Arg_Is_Local_Name (Arg1);
12510 E_Id := Entity (Expression (Arg1));
12512 if E_Id = Any_Type then
12514 elsif No (E_Id) or else not Is_Type (E_Id) then
12515 Error_Pragma_Arg ("pragma% requires type", Arg1);
12518 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
12519 end Universal_Alias;
12521 --------------------
12522 -- Universal_Data --
12523 --------------------
12525 -- pragma Universal_Data [(library_unit_NAME)];
12527 when Pragma_Universal_Data =>
12530 -- If this is a configuration pragma, then set the universal
12531 -- addressing option, otherwise confirm that the pragma satisfies
12532 -- the requirements of library unit pragma placement and leave it
12533 -- to the GNAAMP back end to detect the pragma (avoids transitive
12534 -- setting of the option due to withed units).
12536 if Is_Configuration_Pragma then
12537 Universal_Addressing_On_AAMP := True;
12539 Check_Valid_Library_Unit_Pragma;
12542 if not AAMP_On_Target then
12543 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
12550 -- pragma Unmodified (local_Name {, local_Name});
12552 when Pragma_Unmodified => Unmodified : declare
12553 Arg_Node : Node_Id;
12554 Arg_Expr : Node_Id;
12555 Arg_Ent : Entity_Id;
12559 Check_At_Least_N_Arguments (1);
12561 -- Loop through arguments
12564 while Present (Arg_Node) loop
12565 Check_No_Identifier (Arg_Node);
12567 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
12568 -- in fact generate reference, so that the entity will have a
12569 -- reference, which will inhibit any warnings about it not
12570 -- being referenced, and also properly show up in the ali file
12571 -- as a reference. But this reference is recorded before the
12572 -- Has_Pragma_Unreferenced flag is set, so that no warning is
12573 -- generated for this reference.
12575 Check_Arg_Is_Local_Name (Arg_Node);
12576 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12578 if Is_Entity_Name (Arg_Expr) then
12579 Arg_Ent := Entity (Arg_Expr);
12581 if not Is_Assignable (Arg_Ent) then
12583 ("pragma% can only be applied to a variable",
12586 Set_Has_Pragma_Unmodified (Arg_Ent);
12598 -- pragma Unreferenced (local_Name {, local_Name});
12600 -- or when used in a context clause:
12602 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
12604 when Pragma_Unreferenced => Unreferenced : declare
12605 Arg_Node : Node_Id;
12606 Arg_Expr : Node_Id;
12607 Arg_Ent : Entity_Id;
12612 Check_At_Least_N_Arguments (1);
12614 -- Check case of appearing within context clause
12616 if Is_In_Context_Clause then
12618 -- The arguments must all be units mentioned in a with clause
12619 -- in the same context clause. Note we already checked (in
12620 -- Par.Prag) that the arguments are either identifiers or
12621 -- selected components.
12624 while Present (Arg_Node) loop
12625 Citem := First (List_Containing (N));
12626 while Citem /= N loop
12627 if Nkind (Citem) = N_With_Clause
12628 and then Same_Name (Name (Citem), Expression (Arg_Node))
12630 Set_Has_Pragma_Unreferenced
12633 (Library_Unit (Citem))));
12634 Set_Unit_Name (Expression (Arg_Node), Name (Citem));
12643 ("argument of pragma% is not with'ed unit", Arg_Node);
12649 -- Case of not in list of context items
12653 while Present (Arg_Node) loop
12654 Check_No_Identifier (Arg_Node);
12656 -- Note: the analyze call done by Check_Arg_Is_Local_Name
12657 -- will in fact generate reference, so that the entity will
12658 -- have a reference, which will inhibit any warnings about
12659 -- it not being referenced, and also properly show up in the
12660 -- ali file as a reference. But this reference is recorded
12661 -- before the Has_Pragma_Unreferenced flag is set, so that
12662 -- no warning is generated for this reference.
12664 Check_Arg_Is_Local_Name (Arg_Node);
12665 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12667 if Is_Entity_Name (Arg_Expr) then
12668 Arg_Ent := Entity (Arg_Expr);
12670 -- If the entity is overloaded, the pragma applies to the
12671 -- most recent overloading, as documented. In this case,
12672 -- name resolution does not generate a reference, so it
12673 -- must be done here explicitly.
12675 if Is_Overloaded (Arg_Expr) then
12676 Generate_Reference (Arg_Ent, N);
12679 Set_Has_Pragma_Unreferenced (Arg_Ent);
12687 --------------------------
12688 -- Unreferenced_Objects --
12689 --------------------------
12691 -- pragma Unreferenced_Objects (local_Name {, local_Name});
12693 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
12694 Arg_Node : Node_Id;
12695 Arg_Expr : Node_Id;
12699 Check_At_Least_N_Arguments (1);
12702 while Present (Arg_Node) loop
12703 Check_No_Identifier (Arg_Node);
12704 Check_Arg_Is_Local_Name (Arg_Node);
12705 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12707 if not Is_Entity_Name (Arg_Expr)
12708 or else not Is_Type (Entity (Arg_Expr))
12711 ("argument for pragma% must be type or subtype", Arg_Node);
12714 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
12717 end Unreferenced_Objects;
12719 ------------------------------
12720 -- Unreserve_All_Interrupts --
12721 ------------------------------
12723 -- pragma Unreserve_All_Interrupts;
12725 when Pragma_Unreserve_All_Interrupts =>
12727 Check_Arg_Count (0);
12729 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
12730 Unreserve_All_Interrupts := True;
12737 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
12739 when Pragma_Unsuppress =>
12741 Process_Suppress_Unsuppress (False);
12743 -------------------
12744 -- Use_VADS_Size --
12745 -------------------
12747 -- pragma Use_VADS_Size;
12749 when Pragma_Use_VADS_Size =>
12751 Check_Arg_Count (0);
12752 Check_Valid_Configuration_Pragma;
12753 Use_VADS_Size := True;
12755 ---------------------
12756 -- Validity_Checks --
12757 ---------------------
12759 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12761 when Pragma_Validity_Checks => Validity_Checks : declare
12762 A : constant Node_Id := Expression (Arg1);
12768 Check_Arg_Count (1);
12769 Check_No_Identifiers;
12771 if Nkind (A) = N_String_Literal then
12775 Slen : constant Natural := Natural (String_Length (S));
12776 Options : String (1 .. Slen);
12782 C := Get_String_Char (S, Int (J));
12783 exit when not In_Character_Range (C);
12784 Options (J) := Get_Character (C);
12787 Set_Validity_Check_Options (Options);
12795 elsif Nkind (A) = N_Identifier then
12797 if Chars (A) = Name_All_Checks then
12798 Set_Validity_Check_Options ("a");
12800 elsif Chars (A) = Name_On then
12801 Validity_Checks_On := True;
12803 elsif Chars (A) = Name_Off then
12804 Validity_Checks_On := False;
12808 end Validity_Checks;
12814 -- pragma Volatile (LOCAL_NAME);
12816 when Pragma_Volatile =>
12817 Process_Atomic_Shared_Volatile;
12819 -------------------------
12820 -- Volatile_Components --
12821 -------------------------
12823 -- pragma Volatile_Components (array_LOCAL_NAME);
12825 -- Volatile is handled by the same circuit as Atomic_Components
12831 -- pragma Warnings (On | Off);
12832 -- pragma Warnings (On | Off, LOCAL_NAME);
12833 -- pragma Warnings (static_string_EXPRESSION);
12834 -- pragma Warnings (On | Off, STRING_LITERAL);
12836 when Pragma_Warnings => Warnings : begin
12838 Check_At_Least_N_Arguments (1);
12839 Check_No_Identifiers;
12841 -- If debug flag -gnatd.i is set, pragma is ignored
12843 if Debug_Flag_Dot_I then
12847 -- Process various forms of the pragma
12850 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12853 -- One argument case
12855 if Arg_Count = 1 then
12857 -- On/Off one argument case was processed by parser
12859 if Nkind (Argx) = N_Identifier
12861 (Chars (Argx) = Name_On
12863 Chars (Argx) = Name_Off)
12867 -- One argument case must be ON/OFF or static string expr
12869 elsif not Is_Static_String_Expression (Arg1) then
12871 ("argument of pragma% must be On/Off or " &
12872 "static string expression", Arg1);
12874 -- One argument string expression case
12878 Lit : constant Node_Id := Expr_Value_S (Argx);
12879 Str : constant String_Id := Strval (Lit);
12880 Len : constant Nat := String_Length (Str);
12888 while J <= Len loop
12889 C := Get_String_Char (Str, J);
12890 OK := In_Character_Range (C);
12893 Chr := Get_Character (C);
12897 if J < Len and then Chr = '.' then
12899 C := Get_String_Char (Str, J);
12900 Chr := Get_Character (C);
12902 if not Set_Dot_Warning_Switch (Chr) then
12904 ("invalid warning switch character " &
12911 OK := Set_Warning_Switch (Chr);
12917 ("invalid warning switch character " & Chr,
12926 -- Two or more arguments (must be two)
12929 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12930 Check_At_Most_N_Arguments (2);
12938 E_Id := Expression (Arg2);
12941 -- In the expansion of an inlined body, a reference to
12942 -- the formal may be wrapped in a conversion if the
12943 -- actual is a conversion. Retrieve the real entity name.
12945 if (In_Instance_Body
12946 or else In_Inlined_Body)
12947 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
12949 E_Id := Expression (E_Id);
12952 -- Entity name case
12954 if Is_Entity_Name (E_Id) then
12955 E := Entity (E_Id);
12962 (E, (Chars (Expression (Arg1)) = Name_Off));
12964 if Chars (Expression (Arg1)) = Name_Off
12965 and then Warn_On_Warnings_Off
12967 Warnings_Off_Pragmas.Append ((N, E));
12970 if Is_Enumeration_Type (E) then
12974 Lit := First_Literal (E);
12975 while Present (Lit) loop
12976 Set_Warnings_Off (Lit);
12977 Next_Literal (Lit);
12982 exit when No (Homonym (E));
12987 -- Error if not entity or static string literal case
12989 elsif not Is_Static_String_Expression (Arg2) then
12991 ("second argument of pragma% must be entity " &
12992 "name or static string expression", Arg2);
12994 -- String literal case
12997 String_To_Name_Buffer
12998 (Strval (Expr_Value_S (Expression (Arg2))));
13000 -- Note on configuration pragma case: If this is a
13001 -- configuration pragma, then for an OFF pragma, we
13002 -- just set Config True in the call, which is all
13003 -- that needs to be done. For the case of ON, this
13004 -- is normally an error, unless it is canceling the
13005 -- effect of a previous OFF pragma in the same file.
13006 -- In any other case, an error will be signalled (ON
13007 -- with no matching OFF).
13009 if Chars (Argx) = Name_Off then
13010 Set_Specific_Warning_Off
13011 (Loc, Name_Buffer (1 .. Name_Len),
13012 Config => Is_Configuration_Pragma);
13014 elsif Chars (Argx) = Name_On then
13015 Set_Specific_Warning_On
13016 (Loc, Name_Buffer (1 .. Name_Len), Err);
13020 ("?pragma Warnings On with no " &
13021 "matching Warnings Off",
13031 -------------------
13032 -- Weak_External --
13033 -------------------
13035 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13037 when Pragma_Weak_External => Weak_External : declare
13042 Check_Arg_Count (1);
13043 Check_Optional_Identifier (Arg1, Name_Entity);
13044 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13045 Ent := Entity (Expression (Arg1));
13047 if Rep_Item_Too_Early (Ent, N) then
13050 Ent := Underlying_Type (Ent);
13053 -- The only processing required is to link this item on to the
13054 -- list of rep items for the given entity. This is accomplished
13055 -- by the call to Rep_Item_Too_Late (when no error is detected
13056 -- and False is returned).
13058 if Rep_Item_Too_Late (Ent, N) then
13061 Set_Has_Gigi_Rep_Item (Ent);
13065 -----------------------------
13066 -- Wide_Character_Encoding --
13067 -----------------------------
13069 -- pragma Wide_Character_Encoding (IDENTIFIER);
13071 when Pragma_Wide_Character_Encoding =>
13074 -- Nothing to do, handled in parser. Note that we do not enforce
13075 -- configuration pragma placement, this pragma can appear at any
13076 -- place in the source, allowing mixed encodings within a single
13081 --------------------
13082 -- Unknown_Pragma --
13083 --------------------
13085 -- Should be impossible, since the case of an unknown pragma is
13086 -- separately processed before the case statement is entered.
13088 when Unknown_Pragma =>
13089 raise Program_Error;
13092 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13093 -- until AI is formally approved.
13095 -- Check_Order_Dependence;
13098 when Pragma_Exit => null;
13099 end Analyze_Pragma;
13101 -------------------
13102 -- Check_Enabled --
13103 -------------------
13105 function Check_Enabled (Nam : Name_Id) return Boolean is
13109 PP := Opt.Check_Policy_List;
13112 return Assertions_Enabled;
13115 Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
13118 Chars (Expression (Last (Pragma_Argument_Associations (PP))))
13120 when Name_On | Name_Check =>
13122 when Name_Off | Name_Ignore =>
13125 raise Program_Error;
13129 PP := Next_Pragma (PP);
13134 ---------------------------------
13135 -- Delay_Config_Pragma_Analyze --
13136 ---------------------------------
13138 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13140 return Pragma_Name (N) = Name_Interrupt_State
13142 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13143 end Delay_Config_Pragma_Analyze;
13145 -------------------------
13146 -- Get_Base_Subprogram --
13147 -------------------------
13149 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13150 Result : Entity_Id;
13153 -- Follow subprogram renaming chain
13156 while Is_Subprogram (Result)
13158 (Is_Generic_Instance (Result)
13159 or else Nkind (Parent (Declaration_Node (Result))) =
13160 N_Subprogram_Renaming_Declaration)
13161 and then Present (Alias (Result))
13163 Result := Alias (Result);
13167 end Get_Base_Subprogram;
13169 --------------------
13170 -- Get_Pragma_Arg --
13171 --------------------
13173 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
13175 if Nkind (Arg) = N_Pragma_Argument_Association then
13176 return Expression (Arg);
13180 end Get_Pragma_Arg;
13186 procedure Initialize is
13191 -----------------------------
13192 -- Is_Config_Static_String --
13193 -----------------------------
13195 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13197 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13198 -- This is an internal recursive function that is just like the outer
13199 -- function except that it adds the string to the name buffer rather
13200 -- than placing the string in the name buffer.
13202 ------------------------------
13203 -- Add_Config_Static_String --
13204 ------------------------------
13206 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13213 if Nkind (N) = N_Op_Concat then
13214 if Add_Config_Static_String (Left_Opnd (N)) then
13215 N := Right_Opnd (N);
13221 if Nkind (N) /= N_String_Literal then
13222 Error_Msg_N ("string literal expected for pragma argument", N);
13226 for J in 1 .. String_Length (Strval (N)) loop
13227 C := Get_String_Char (Strval (N), J);
13229 if not In_Character_Range (C) then
13231 ("string literal contains invalid wide character",
13232 Sloc (N) + 1 + Source_Ptr (J));
13236 Add_Char_To_Name_Buffer (Get_Character (C));
13241 end Add_Config_Static_String;
13243 -- Start of processing for Is_Config_Static_String
13248 return Add_Config_Static_String (Arg);
13249 end Is_Config_Static_String;
13251 -----------------------------------------
13252 -- Is_Non_Significant_Pragma_Reference --
13253 -----------------------------------------
13255 -- This function makes use of the following static table which indicates
13256 -- whether a given pragma is significant.
13258 -- -1 indicates that references in any argument position are significant
13259 -- 0 indicates that appearence in any argument is not significant
13260 -- +n indicates that appearence as argument n is significant, but all
13261 -- other arguments are not significant
13262 -- 99 special processing required (e.g. for pragma Check)
13264 Sig_Flags : constant array (Pragma_Id) of Int :=
13265 (Pragma_AST_Entry => -1,
13266 Pragma_Abort_Defer => -1,
13267 Pragma_Ada_83 => -1,
13268 Pragma_Ada_95 => -1,
13269 Pragma_Ada_05 => -1,
13270 Pragma_Ada_2005 => -1,
13271 Pragma_Ada_12 => -1,
13272 Pragma_Ada_2012 => -1,
13273 Pragma_All_Calls_Remote => -1,
13274 Pragma_Annotate => -1,
13275 Pragma_Assert => -1,
13276 Pragma_Assertion_Policy => 0,
13277 Pragma_Assume_No_Invalid_Values => 0,
13278 Pragma_Asynchronous => -1,
13279 Pragma_Atomic => 0,
13280 Pragma_Atomic_Components => 0,
13281 Pragma_Attach_Handler => -1,
13282 Pragma_Check => 99,
13283 Pragma_Check_Name => 0,
13284 Pragma_Check_Policy => 0,
13285 Pragma_CIL_Constructor => -1,
13286 Pragma_CPP_Class => 0,
13287 Pragma_CPP_Constructor => 0,
13288 Pragma_CPP_Virtual => 0,
13289 Pragma_CPP_Vtable => 0,
13290 Pragma_C_Pass_By_Copy => 0,
13291 Pragma_Comment => 0,
13292 Pragma_Common_Object => -1,
13293 Pragma_Compile_Time_Error => -1,
13294 Pragma_Compile_Time_Warning => -1,
13295 Pragma_Compiler_Unit => 0,
13296 Pragma_Complete_Representation => 0,
13297 Pragma_Complex_Representation => 0,
13298 Pragma_Component_Alignment => -1,
13299 Pragma_Controlled => 0,
13300 Pragma_Convention => 0,
13301 Pragma_Convention_Identifier => 0,
13302 Pragma_Debug => -1,
13303 Pragma_Debug_Policy => 0,
13304 Pragma_Detect_Blocking => -1,
13305 Pragma_Dimension => -1,
13306 Pragma_Discard_Names => 0,
13307 Pragma_Elaborate => -1,
13308 Pragma_Elaborate_All => -1,
13309 Pragma_Elaborate_Body => -1,
13310 Pragma_Elaboration_Checks => -1,
13311 Pragma_Eliminate => -1,
13312 Pragma_Export => -1,
13313 Pragma_Export_Exception => -1,
13314 Pragma_Export_Function => -1,
13315 Pragma_Export_Object => -1,
13316 Pragma_Export_Procedure => -1,
13317 Pragma_Export_Value => -1,
13318 Pragma_Export_Valued_Procedure => -1,
13319 Pragma_Extend_System => -1,
13320 Pragma_Extensions_Allowed => -1,
13321 Pragma_External => -1,
13322 Pragma_Favor_Top_Level => -1,
13323 Pragma_External_Name_Casing => -1,
13324 Pragma_Fast_Math => -1,
13325 Pragma_Finalize_Storage_Only => 0,
13326 Pragma_Float_Representation => 0,
13327 Pragma_Ident => -1,
13328 Pragma_Implemented => -1,
13329 Pragma_Implicit_Packing => 0,
13330 Pragma_Import => +2,
13331 Pragma_Import_Exception => 0,
13332 Pragma_Import_Function => 0,
13333 Pragma_Import_Object => 0,
13334 Pragma_Import_Procedure => 0,
13335 Pragma_Import_Valued_Procedure => 0,
13336 Pragma_Independent => 0,
13337 Pragma_Independent_Components => 0,
13338 Pragma_Initialize_Scalars => -1,
13339 Pragma_Inline => 0,
13340 Pragma_Inline_Always => 0,
13341 Pragma_Inline_Generic => 0,
13342 Pragma_Inspection_Point => -1,
13343 Pragma_Interface => +2,
13344 Pragma_Interface_Name => +2,
13345 Pragma_Interrupt_Handler => -1,
13346 Pragma_Interrupt_Priority => -1,
13347 Pragma_Interrupt_State => -1,
13348 Pragma_Java_Constructor => -1,
13349 Pragma_Java_Interface => -1,
13350 Pragma_Keep_Names => 0,
13351 Pragma_License => -1,
13352 Pragma_Link_With => -1,
13353 Pragma_Linker_Alias => -1,
13354 Pragma_Linker_Constructor => -1,
13355 Pragma_Linker_Destructor => -1,
13356 Pragma_Linker_Options => -1,
13357 Pragma_Linker_Section => -1,
13359 Pragma_Locking_Policy => -1,
13360 Pragma_Long_Float => -1,
13361 Pragma_Machine_Attribute => -1,
13363 Pragma_Main_Storage => -1,
13364 Pragma_Memory_Size => -1,
13365 Pragma_No_Return => 0,
13366 Pragma_No_Body => 0,
13367 Pragma_No_Run_Time => -1,
13368 Pragma_No_Strict_Aliasing => -1,
13369 Pragma_Normalize_Scalars => -1,
13370 Pragma_Obsolescent => 0,
13371 Pragma_Optimize => -1,
13372 Pragma_Optimize_Alignment => -1,
13373 Pragma_Ordered => 0,
13376 Pragma_Passive => -1,
13377 Pragma_Preelaborable_Initialization => -1,
13378 Pragma_Polling => -1,
13379 Pragma_Persistent_BSS => 0,
13380 Pragma_Postcondition => -1,
13381 Pragma_Precondition => -1,
13382 Pragma_Preelaborate => -1,
13383 Pragma_Preelaborate_05 => -1,
13384 Pragma_Priority => -1,
13385 Pragma_Priority_Specific_Dispatching => -1,
13386 Pragma_Profile => 0,
13387 Pragma_Profile_Warnings => 0,
13388 Pragma_Propagate_Exceptions => -1,
13389 Pragma_Psect_Object => -1,
13391 Pragma_Pure_05 => -1,
13392 Pragma_Pure_Function => -1,
13393 Pragma_Queuing_Policy => -1,
13394 Pragma_Ravenscar => -1,
13395 Pragma_Relative_Deadline => -1,
13396 Pragma_Remote_Call_Interface => -1,
13397 Pragma_Remote_Types => -1,
13398 Pragma_Restricted_Run_Time => -1,
13399 Pragma_Restriction_Warnings => -1,
13400 Pragma_Restrictions => -1,
13401 Pragma_Reviewable => -1,
13402 Pragma_Short_Circuit_And_Or => -1,
13403 Pragma_Share_Generic => -1,
13404 Pragma_Shared => -1,
13405 Pragma_Shared_Passive => -1,
13406 Pragma_Short_Descriptors => 0,
13407 Pragma_Source_File_Name => -1,
13408 Pragma_Source_File_Name_Project => -1,
13409 Pragma_Source_Reference => -1,
13410 Pragma_Storage_Size => -1,
13411 Pragma_Storage_Unit => -1,
13412 Pragma_Static_Elaboration_Desired => -1,
13413 Pragma_Stream_Convert => -1,
13414 Pragma_Style_Checks => -1,
13415 Pragma_Subtitle => -1,
13416 Pragma_Suppress => 0,
13417 Pragma_Suppress_Exception_Locations => 0,
13418 Pragma_Suppress_All => -1,
13419 Pragma_Suppress_Debug_Info => 0,
13420 Pragma_Suppress_Initialization => 0,
13421 Pragma_System_Name => -1,
13422 Pragma_Task_Dispatching_Policy => -1,
13423 Pragma_Task_Info => -1,
13424 Pragma_Task_Name => -1,
13425 Pragma_Task_Storage => 0,
13426 Pragma_Thread_Local_Storage => 0,
13427 Pragma_Time_Slice => -1,
13428 Pragma_Title => -1,
13429 Pragma_Unchecked_Union => 0,
13430 Pragma_Unimplemented_Unit => -1,
13431 Pragma_Universal_Aliasing => -1,
13432 Pragma_Universal_Data => -1,
13433 Pragma_Unmodified => -1,
13434 Pragma_Unreferenced => -1,
13435 Pragma_Unreferenced_Objects => -1,
13436 Pragma_Unreserve_All_Interrupts => -1,
13437 Pragma_Unsuppress => 0,
13438 Pragma_Use_VADS_Size => -1,
13439 Pragma_Validity_Checks => -1,
13440 Pragma_Volatile => 0,
13441 Pragma_Volatile_Components => 0,
13442 Pragma_Warnings => -1,
13443 Pragma_Weak_External => -1,
13444 Pragma_Wide_Character_Encoding => 0,
13445 Unknown_Pragma => 0);
13447 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
13456 if Nkind (P) /= N_Pragma_Argument_Association then
13460 Id := Get_Pragma_Id (Parent (P));
13461 C := Sig_Flags (Id);
13473 -- For pragma Check, the first argument is not significant,
13474 -- the second and the third (if present) arguments are
13477 when Pragma_Check =>
13479 P = First (Pragma_Argument_Associations (Parent (P)));
13482 raise Program_Error;
13486 A := First (Pragma_Argument_Associations (Parent (P)));
13487 for J in 1 .. C - 1 loop
13495 return A = P; -- is this wrong way round ???
13498 end Is_Non_Significant_Pragma_Reference;
13500 ------------------------------
13501 -- Is_Pragma_String_Literal --
13502 ------------------------------
13504 -- This function returns true if the corresponding pragma argument is a
13505 -- static string expression. These are the only cases in which string
13506 -- literals can appear as pragma arguments. We also allow a string literal
13507 -- as the first argument to pragma Assert (although it will of course
13508 -- always generate a type error).
13510 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
13511 Pragn : constant Node_Id := Parent (Par);
13512 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
13513 Pname : constant Name_Id := Pragma_Name (Pragn);
13519 N := First (Assoc);
13526 if Pname = Name_Assert then
13529 elsif Pname = Name_Export then
13532 elsif Pname = Name_Ident then
13535 elsif Pname = Name_Import then
13538 elsif Pname = Name_Interface_Name then
13541 elsif Pname = Name_Linker_Alias then
13544 elsif Pname = Name_Linker_Section then
13547 elsif Pname = Name_Machine_Attribute then
13550 elsif Pname = Name_Source_File_Name then
13553 elsif Pname = Name_Source_Reference then
13556 elsif Pname = Name_Title then
13559 elsif Pname = Name_Subtitle then
13565 end Is_Pragma_String_Literal;
13567 --------------------------------------
13568 -- Process_Compilation_Unit_Pragmas --
13569 --------------------------------------
13571 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
13573 -- A special check for pragma Suppress_All, a very strange DEC pragma,
13574 -- strange because it comes at the end of the unit. If we have a pragma
13575 -- Suppress_All in the Pragmas_After of the current unit, then we insert
13576 -- a pragma Suppress (All_Checks) at the start of the context clause to
13577 -- ensure the correct processing.
13580 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
13584 if Present (PA) then
13586 while Present (P) loop
13587 if Pragma_Name (P) = Name_Suppress_All then
13588 Prepend_To (Context_Items (N),
13589 Make_Pragma (Sloc (P),
13590 Chars => Name_Suppress,
13591 Pragma_Argument_Associations => New_List (
13592 Make_Pragma_Argument_Association (Sloc (P),
13594 Make_Identifier (Sloc (P),
13595 Chars => Name_All_Checks)))));
13603 end Process_Compilation_Unit_Pragmas;
13614 --------------------------------
13615 -- Set_Encoded_Interface_Name --
13616 --------------------------------
13618 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
13619 Str : constant String_Id := Strval (S);
13620 Len : constant Int := String_Length (Str);
13625 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
13628 -- Stores encoded value of character code CC. The encoding we use an
13629 -- underscore followed by four lower case hex digits.
13635 procedure Encode is
13637 Store_String_Char (Get_Char_Code ('_'));
13639 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
13641 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
13643 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
13645 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
13648 -- Start of processing for Set_Encoded_Interface_Name
13651 -- If first character is asterisk, this is a link name, and we leave it
13652 -- completely unmodified. We also ignore null strings (the latter case
13653 -- happens only in error cases) and no encoding should occur for Java or
13654 -- AAMP interface names.
13657 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
13658 or else VM_Target /= No_VM
13659 or else AAMP_On_Target
13661 Set_Interface_Name (E, S);
13666 CC := Get_String_Char (Str, J);
13668 exit when not In_Character_Range (CC);
13670 C := Get_Character (CC);
13672 exit when C /= '_' and then C /= '$'
13673 and then C not in '0' .. '9'
13674 and then C not in 'a' .. 'z'
13675 and then C not in 'A' .. 'Z';
13678 Set_Interface_Name (E, S);
13686 -- Here we need to encode. The encoding we use as follows:
13687 -- three underscores + four hex digits (lower case)
13691 for J in 1 .. String_Length (Str) loop
13692 CC := Get_String_Char (Str, J);
13694 if not In_Character_Range (CC) then
13697 C := Get_Character (CC);
13699 if C = '_' or else C = '$'
13700 or else C in '0' .. '9'
13701 or else C in 'a' .. 'z'
13702 or else C in 'A' .. 'Z'
13704 Store_String_Char (CC);
13711 Set_Interface_Name (E,
13712 Make_String_Literal (Sloc (S),
13713 Strval => End_String));
13715 end Set_Encoded_Interface_Name;
13717 -------------------
13718 -- Set_Unit_Name --
13719 -------------------
13721 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
13726 if Nkind (N) = N_Identifier
13727 and then Nkind (With_Item) = N_Identifier
13729 Set_Entity (N, Entity (With_Item));
13731 elsif Nkind (N) = N_Selected_Component then
13732 Change_Selected_Component_To_Expanded_Name (N);
13733 Set_Entity (N, Entity (With_Item));
13734 Set_Entity (Selector_Name (N), Entity (N));
13736 Pref := Prefix (N);
13737 Scop := Scope (Entity (N));
13738 while Nkind (Pref) = N_Selected_Component loop
13739 Change_Selected_Component_To_Expanded_Name (Pref);
13740 Set_Entity (Selector_Name (Pref), Scop);
13741 Set_Entity (Pref, Scop);
13742 Pref := Prefix (Pref);
13743 Scop := Scope (Scop);
13746 Set_Entity (Pref, Scop);