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_Disp; use Sem_Disp;
62 with Sem_Dist; use Sem_Dist;
63 with Sem_Elim; use Sem_Elim;
64 with Sem_Eval; use Sem_Eval;
65 with Sem_Intr; use Sem_Intr;
66 with Sem_Mech; use Sem_Mech;
67 with Sem_Res; use Sem_Res;
68 with Sem_Type; use Sem_Type;
69 with Sem_Util; use Sem_Util;
70 with Sem_VFpt; use Sem_VFpt;
71 with Sem_Warn; use Sem_Warn;
72 with Stand; use Stand;
73 with Sinfo; use Sinfo;
74 with Sinfo.CN; use Sinfo.CN;
75 with Sinput; use Sinput;
76 with Snames; use Snames;
77 with Stringt; use Stringt;
78 with Stylesw; use Stylesw;
80 with Targparm; use Targparm;
81 with Tbuild; use Tbuild;
83 with Uintp; use Uintp;
84 with Uname; use Uname;
85 with Urealp; use Urealp;
86 with Validsw; use Validsw;
88 package body Sem_Prag is
90 ----------------------------------------------
91 -- Common Handling of Import-Export Pragmas --
92 ----------------------------------------------
94 -- In the following section, a number of Import_xxx and Export_xxx pragmas
95 -- are defined by GNAT. These are compatible with the DEC pragmas of the
96 -- same name, and all have the following common 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???
182 -- This is a dummy function called by the processing for pragma Reviewable.
183 -- It is there for assisting front end debugging. By placing a Reviewable
184 -- pragma in the source program, a breakpoint on rv catches this place in
185 -- the source, allowing convenient stepping to the point of interest.
187 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
188 -- Place semantic information on the argument of an Elaborate/Elaborate_All
189 -- pragma. Entity name for unit and its parents is taken from item in
190 -- previous with_clause that mentions the unit.
192 -------------------------------
193 -- Adjust_External_Name_Case --
194 -------------------------------
196 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
200 -- Adjust case of literal if required
202 if Opt.External_Name_Exp_Casing = As_Is then
206 -- Copy existing string
212 for J in 1 .. String_Length (Strval (N)) loop
213 CC := Get_String_Char (Strval (N), J);
215 if Opt.External_Name_Exp_Casing = Uppercase
216 and then CC >= Get_Char_Code ('a')
217 and then CC <= Get_Char_Code ('z')
219 Store_String_Char (CC - 32);
221 elsif Opt.External_Name_Exp_Casing = Lowercase
222 and then CC >= Get_Char_Code ('A')
223 and then CC <= Get_Char_Code ('Z')
225 Store_String_Char (CC + 32);
228 Store_String_Char (CC);
233 Make_String_Literal (Sloc (N),
234 Strval => End_String);
236 end Adjust_External_Name_Case;
238 ------------------------------
239 -- Analyze_PPC_In_Decl_Part --
240 ------------------------------
242 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
243 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
246 -- Install formals and push subprogram spec onto scope stack so that we
247 -- can see the formals from the pragma.
252 -- Preanalyze the boolean expression, we treat this as a spec expression
253 -- (i.e. similar to a default expression).
255 Preanalyze_Spec_Expression
256 (Get_Pragma_Arg (Arg1), Standard_Boolean);
258 -- Remove the subprogram from the scope stack now that the pre-analysis
259 -- of the precondition/postcondition is done.
262 end Analyze_PPC_In_Decl_Part;
268 procedure Analyze_Pragma (N : Node_Id) is
269 Loc : constant Source_Ptr := Sloc (N);
270 Pname : constant Name_Id := Pragma_Name (N);
273 Sense : constant Boolean := not Aspect_Cancel (N);
274 -- Sense is True if we have the normal case of a pragma that is active
275 -- and turns the corresponding aspect on. It is false only for the case
276 -- of a pragma coming from an aspect which is explicitly turned off by
277 -- using aspect => False. If Sense is False, the effect of the pragma
278 -- is to turn the corresponding aspect off.
280 Pragma_Exit : exception;
281 -- This exception is used to exit pragma processing completely. It is
282 -- used when an error is detected, and no further processing is
283 -- required. It is also used if an earlier error has left the tree in
284 -- a state where the pragma should not be processed.
287 -- Number of pragma argument associations
293 -- First four pragma arguments (pragma argument association nodes, or
294 -- Empty if the corresponding argument does not exist).
296 type Name_List is array (Natural range <>) of Name_Id;
297 type Args_List is array (Natural range <>) of Node_Id;
298 -- Types used for arguments to Check_Arg_Order and Gather_Associations
300 procedure Ada_2005_Pragma;
301 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
302 -- Ada 95 mode, these are implementation defined pragmas, so should be
303 -- caught by the No_Implementation_Pragmas restriction.
305 procedure Ada_2012_Pragma;
306 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
307 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
308 -- should be caught by the No_Implementation_Pragmas restriction.
310 procedure Check_Ada_83_Warning;
311 -- Issues a warning message for the current pragma if operating in Ada
312 -- 83 mode (used for language pragmas that are not a standard part of
313 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
316 procedure Check_Arg_Count (Required : Nat);
317 -- Check argument count for pragma is equal to given parameter. If not,
318 -- then issue an error message and raise Pragma_Exit.
320 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
321 -- Arg which can either be a pragma argument association, in which case
322 -- the check is applied to the expression of the association or an
323 -- expression directly.
325 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
326 -- Check that an argument has the right form for an EXTERNAL_NAME
327 -- parameter of an extended import/export pragma. The rule is that the
328 -- name must be an identifier or string literal (in Ada 83 mode) or a
329 -- static string expression (in Ada 95 mode).
331 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
332 -- Check the specified argument Arg to make sure that it is an
333 -- identifier. If not give error and raise Pragma_Exit.
335 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
336 -- Check the specified argument Arg to make sure that it is an integer
337 -- literal. If not give error and raise Pragma_Exit.
339 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
340 -- Check the specified argument Arg to make sure that it has the proper
341 -- syntactic form for a local name and meets the semantic requirements
342 -- for a local name. The local name is analyzed as part of the
343 -- processing for this call. In addition, the local name is required
344 -- to represent an entity at the library level.
346 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
347 -- Check the specified argument Arg to make sure that it has the proper
348 -- syntactic form for a local name and meets the semantic requirements
349 -- for a local name. The local name is analyzed as part of the
350 -- processing for this call.
352 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
353 -- Check the specified argument Arg to make sure that it is a valid
354 -- locking policy name. If not give error and raise Pragma_Exit.
356 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
357 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
358 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
359 -- Check the specified argument Arg to make sure that it is an
360 -- identifier whose name matches either N1 or N2 (or N3 if present).
361 -- If not then give error and raise Pragma_Exit.
363 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
364 -- Check the specified argument Arg to make sure that it is a valid
365 -- queuing policy name. If not give error and raise Pragma_Exit.
367 procedure Check_Arg_Is_Static_Expression
369 Typ : Entity_Id := Empty);
370 -- Check the specified argument Arg to make sure that it is a static
371 -- expression of the given type (i.e. it will be analyzed and resolved
372 -- using this type, which can be any valid argument to Resolve, e.g.
373 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
374 -- Typ is left Empty, then any static expression is allowed.
376 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
377 -- Check the specified argument Arg to make sure that it is a valid task
378 -- dispatching policy name. If not give error and raise Pragma_Exit.
380 procedure Check_Arg_Order (Names : Name_List);
381 -- Checks for an instance of two arguments with identifiers for the
382 -- current pragma which are not in the sequence indicated by Names,
383 -- and if so, generates a fatal message about bad order of arguments.
385 procedure Check_At_Least_N_Arguments (N : Nat);
386 -- Check there are at least N arguments present
388 procedure Check_At_Most_N_Arguments (N : Nat);
389 -- Check there are no more than N arguments present
391 procedure Check_Component
394 In_Variant_Part : Boolean := False);
395 -- Examine an Unchecked_Union component for correct use of per-object
396 -- constrained subtypes, and for restrictions on finalizable components.
397 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
398 -- should be set when Comp comes from a record variant.
400 procedure Check_Duplicate_Pragma (E : Entity_Id);
401 -- Check if a pragma of the same name as the current pragma is already
402 -- chained as a rep pragma to the given entity. If so give a message
403 -- about the duplicate, and then raise Pragma_Exit so does not return.
404 -- Also checks for delayed aspect specification node in the chain.
406 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
407 -- Nam is an N_String_Literal node containing the external name set by
408 -- an Import or Export pragma (or extended Import or Export pragma).
409 -- This procedure checks for possible duplications if this is the export
410 -- case, and if found, issues an appropriate error message.
412 procedure Check_First_Subtype (Arg : Node_Id);
413 -- Checks that Arg, whose expression is an entity name, references a
416 procedure Check_In_Main_Program;
417 -- Common checks for pragmas that appear within a main program
418 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
420 procedure Check_Interrupt_Or_Attach_Handler;
421 -- Common processing for first argument of pragma Interrupt_Handler or
422 -- pragma Attach_Handler.
424 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
425 -- Check that pragma appears in a declarative part, or in a package
426 -- specification, i.e. that it does not occur in a statement sequence
429 procedure Check_No_Identifier (Arg : Node_Id);
430 -- Checks that the given argument does not have an identifier. If
431 -- an identifier is present, then an error message is issued, and
432 -- Pragma_Exit is raised.
434 procedure Check_No_Identifiers;
435 -- Checks that none of the arguments to the pragma has an identifier.
436 -- If any argument has an identifier, then an error message is issued,
437 -- and Pragma_Exit is raised.
439 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
440 -- Checks if the given argument has an identifier, and if so, requires
441 -- it to match the given identifier name. If there is a non-matching
442 -- identifier, then an error message is given and Error_Pragmas raised.
444 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
445 -- Checks if the given argument has an identifier, and if so, requires
446 -- it to match the given identifier name. If there is a non-matching
447 -- identifier, then an error message is given and Error_Pragmas raised.
448 -- In this version of the procedure, the identifier name is given as
449 -- a string with lower case letters.
451 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
452 -- Called to process a precondition or postcondition pragma. There are
455 -- The pragma appears after a subprogram spec
457 -- If the corresponding check is not enabled, the pragma is analyzed
458 -- but otherwise ignored and control returns with In_Body set False.
460 -- If the check is enabled, then the first step is to analyze the
461 -- pragma, but this is skipped if the subprogram spec appears within
462 -- a package specification (because this is the case where we delay
463 -- analysis till the end of the spec). Then (whether or not it was
464 -- analyzed), the pragma is chained to the subprogram in question
465 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
466 -- caller with In_Body set False.
468 -- The pragma appears at the start of subprogram body declarations
470 -- In this case an immediate return to the caller is made with
471 -- In_Body set True, and the pragma is NOT analyzed.
473 -- In all other cases, an error message for bad placement is given
475 procedure Check_Static_Constraint (Constr : Node_Id);
476 -- Constr is a constraint from an N_Subtype_Indication node from a
477 -- component constraint in an Unchecked_Union type. This routine checks
478 -- that the constraint is static as required by the restrictions for
481 procedure Check_Valid_Configuration_Pragma;
482 -- Legality checks for placement of a configuration pragma
484 procedure Check_Valid_Library_Unit_Pragma;
485 -- Legality checks for library unit pragmas. A special case arises for
486 -- pragmas in generic instances that come from copies of the original
487 -- library unit pragmas in the generic templates. In the case of other
488 -- than library level instantiations these can appear in contexts which
489 -- would normally be invalid (they only apply to the original template
490 -- and to library level instantiations), and they are simply ignored,
491 -- which is implemented by rewriting them as null statements.
493 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
494 -- Check an Unchecked_Union variant for lack of nested variants and
495 -- presence of at least one component. UU_Typ is the related Unchecked_
498 procedure Error_Pragma (Msg : String);
499 pragma No_Return (Error_Pragma);
500 -- Outputs error message for current pragma. The message contains a %
501 -- that will be replaced with the pragma name, and the flag is placed
502 -- on the pragma itself. Pragma_Exit is then raised.
504 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
505 pragma No_Return (Error_Pragma_Arg);
506 -- Outputs error message for current pragma. The message may contain
507 -- a % that will be replaced with the pragma name. The parameter Arg
508 -- may either be a pragma argument association, in which case the flag
509 -- is placed on the expression of this association, or an expression,
510 -- in which case the flag is placed directly on the expression. The
511 -- message is placed using Error_Msg_N, so the message may also contain
512 -- an & insertion character which will reference the given Arg value.
513 -- After placing the message, Pragma_Exit is raised.
515 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
516 pragma No_Return (Error_Pragma_Arg);
517 -- Similar to above form of Error_Pragma_Arg except that two messages
518 -- are provided, the second is a continuation comment starting with \.
520 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
521 pragma No_Return (Error_Pragma_Arg_Ident);
522 -- Outputs error message for current pragma. The message may contain
523 -- a % that will be replaced with the pragma name. The parameter Arg
524 -- must be a pragma argument association with a non-empty identifier
525 -- (i.e. its Chars field must be set), and the error message is placed
526 -- on the identifier. The message is placed using Error_Msg_N so
527 -- the message may also contain an & insertion character which will
528 -- reference the identifier. After placing the message, Pragma_Exit
531 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
532 pragma No_Return (Error_Pragma_Ref);
533 -- Outputs error message for current pragma. The message may contain
534 -- a % that will be replaced with the pragma name. The parameter Ref
535 -- must be an entity whose name can be referenced by & and sloc by #.
536 -- After placing the message, Pragma_Exit is raised.
538 function Find_Lib_Unit_Name return Entity_Id;
539 -- Used for a library unit pragma to find the entity to which the
540 -- library unit pragma applies, returns the entity found.
542 procedure Find_Program_Unit_Name (Id : Node_Id);
543 -- If the pragma is a compilation unit pragma, the id must denote the
544 -- compilation unit in the same compilation, and the pragma must appear
545 -- in the list of preceding or trailing pragmas. If it is a program
546 -- unit pragma that is not a compilation unit pragma, then the
547 -- identifier must be visible.
549 function Find_Unique_Parameterless_Procedure
551 Arg : Node_Id) return Entity_Id;
552 -- Used for a procedure pragma to find the unique parameterless
553 -- procedure identified by Name, returns it if it exists, otherwise
554 -- errors out and uses Arg as the pragma argument for the message.
556 procedure Fix_Error (Msg : in out String);
557 -- This is called prior to issuing an error message. Msg is a string
558 -- which typically contains the substring pragma. If the current pragma
559 -- comes from an aspect, each such "pragma" substring is replaced with
560 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
561 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
563 procedure Gather_Associations
565 Args : out Args_List);
566 -- This procedure is used to gather the arguments for a pragma that
567 -- permits arbitrary ordering of parameters using the normal rules
568 -- for named and positional parameters. The Names argument is a list
569 -- of Name_Id values that corresponds to the allowed pragma argument
570 -- association identifiers in order. The result returned in Args is
571 -- a list of corresponding expressions that are the pragma arguments.
572 -- Note that this is a list of expressions, not of pragma argument
573 -- associations (Gather_Associations has completely checked all the
574 -- optional identifiers when it returns). An entry in Args is Empty
575 -- on return if the corresponding argument is not present.
577 procedure GNAT_Pragma;
578 -- Called for all GNAT defined pragmas to check the relevant restriction
579 -- (No_Implementation_Pragmas).
581 function Is_Before_First_Decl
582 (Pragma_Node : Node_Id;
583 Decls : List_Id) return Boolean;
584 -- Return True if Pragma_Node is before the first declarative item in
585 -- Decls where Decls is the list of declarative items.
587 function Is_Configuration_Pragma return Boolean;
588 -- Determines if the placement of the current pragma is appropriate
589 -- for a configuration pragma.
591 function Is_In_Context_Clause return Boolean;
592 -- Returns True if pragma appears within the context clause of a unit,
593 -- and False for any other placement (does not generate any messages).
595 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
596 -- Analyzes the argument, and determines if it is a static string
597 -- expression, returns True if so, False if non-static or not String.
599 procedure Pragma_Misplaced;
600 pragma No_Return (Pragma_Misplaced);
601 -- Issue fatal error message for misplaced pragma
603 procedure Process_Atomic_Shared_Volatile;
604 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
605 -- Shared is an obsolete Ada 83 pragma, treated as being identical
606 -- in effect to pragma Atomic.
608 procedure Process_Compile_Time_Warning_Or_Error;
609 -- Common processing for Compile_Time_Error and Compile_Time_Warning
611 procedure Process_Convention
612 (C : out Convention_Id;
613 Ent : out Entity_Id);
614 -- Common processing for Convention, Interface, Import and Export.
615 -- Checks first two arguments of pragma, and sets the appropriate
616 -- convention value in the specified entity or entities. On return
617 -- C is the convention, Ent is the referenced entity.
619 procedure Process_Extended_Import_Export_Exception_Pragma
620 (Arg_Internal : Node_Id;
621 Arg_External : Node_Id;
624 -- Common processing for the pragmas Import/Export_Exception. The three
625 -- arguments correspond to the three named parameters of the pragma. An
626 -- argument is empty if the corresponding parameter is not present in
629 procedure Process_Extended_Import_Export_Object_Pragma
630 (Arg_Internal : Node_Id;
631 Arg_External : Node_Id;
633 -- Common processing for the pragmas Import/Export_Object. The three
634 -- arguments correspond to the three named parameters of the pragmas. An
635 -- argument is empty if the corresponding parameter is not present in
638 procedure Process_Extended_Import_Export_Internal_Arg
639 (Arg_Internal : Node_Id := Empty);
640 -- Common processing for all extended Import and Export pragmas. The
641 -- argument is the pragma parameter for the Internal argument. If
642 -- Arg_Internal is empty or inappropriate, an error message is posted.
643 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
644 -- set to identify the referenced entity.
646 procedure Process_Extended_Import_Export_Subprogram_Pragma
647 (Arg_Internal : Node_Id;
648 Arg_External : Node_Id;
649 Arg_Parameter_Types : Node_Id;
650 Arg_Result_Type : Node_Id := Empty;
651 Arg_Mechanism : Node_Id;
652 Arg_Result_Mechanism : Node_Id := Empty;
653 Arg_First_Optional_Parameter : Node_Id := Empty);
654 -- Common processing for all extended Import and Export pragmas applying
655 -- to subprograms. The caller omits any arguments that do not apply to
656 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
657 -- only in the Import_Function and Export_Function cases). The argument
658 -- names correspond to the allowed pragma association identifiers.
660 procedure Process_Generic_List;
661 -- Common processing for Share_Generic and Inline_Generic
663 procedure Process_Import_Or_Interface;
664 -- Common processing for Import of Interface
666 procedure Process_Inline (Active : Boolean);
667 -- Common processing for Inline and Inline_Always. The parameter
668 -- indicates if the inline pragma is active, i.e. if it should actually
669 -- cause inlining to occur.
671 procedure Process_Interface_Name
672 (Subprogram_Def : Entity_Id;
675 -- Given the last two arguments of pragma Import, pragma Export, or
676 -- pragma Interface_Name, performs validity checks and sets the
677 -- Interface_Name field of the given subprogram entity to the
678 -- appropriate external or link name, depending on the arguments given.
679 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
680 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
681 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
682 -- nor Link_Arg is present, the interface name is set to the default
683 -- from the subprogram name.
685 procedure Process_Interrupt_Or_Attach_Handler;
686 -- Common processing for Interrupt and Attach_Handler pragmas
688 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
689 -- Common processing for Restrictions and Restriction_Warnings pragmas.
690 -- Warn is True for Restriction_Warnings, or for Restrictions if the
691 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
692 -- is not set in the Restrictions case.
694 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
695 -- Common processing for Suppress and Unsuppress. The boolean parameter
696 -- Suppress_Case is True for the Suppress case, and False for the
699 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
700 -- This procedure sets the Is_Exported flag for the given entity,
701 -- checking that the entity was not previously imported. Arg is
702 -- the argument that specified the entity. A check is also made
703 -- for exporting inappropriate entities.
705 procedure Set_Extended_Import_Export_External_Name
706 (Internal_Ent : Entity_Id;
707 Arg_External : Node_Id);
708 -- Common processing for all extended import export pragmas. The first
709 -- argument, Internal_Ent, is the internal entity, which has already
710 -- been checked for validity by the caller. Arg_External is from the
711 -- Import or Export pragma, and may be null if no External parameter
712 -- was present. If Arg_External is present and is a non-null string
713 -- (a null string is treated as the default), then the Interface_Name
714 -- field of Internal_Ent is set appropriately.
716 procedure Set_Imported (E : Entity_Id);
717 -- This procedure sets the Is_Imported flag for the given entity,
718 -- checking that it is not previously exported or imported.
720 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
721 -- Mech is a parameter passing mechanism (see Import_Function syntax
722 -- for MECHANISM_NAME). This routine checks that the mechanism argument
723 -- has the right form, and if not issues an error message. If the
724 -- argument has the right form then the Mechanism field of Ent is
725 -- set appropriately.
727 procedure Set_Ravenscar_Profile (N : Node_Id);
728 -- Activate the set of configuration pragmas and restrictions that make
729 -- up the Ravenscar Profile. N is the corresponding pragma node, which
730 -- is used for error messages on any constructs that violate the
733 ---------------------
734 -- Ada_2005_Pragma --
735 ---------------------
737 procedure Ada_2005_Pragma is
739 if Ada_Version <= Ada_95 then
740 Check_Restriction (No_Implementation_Pragmas, N);
744 ---------------------
745 -- Ada_2012_Pragma --
746 ---------------------
748 procedure Ada_2012_Pragma is
750 if Ada_Version <= Ada_2005 then
751 Check_Restriction (No_Implementation_Pragmas, N);
755 --------------------------
756 -- Check_Ada_83_Warning --
757 --------------------------
759 procedure Check_Ada_83_Warning is
761 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
762 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
764 end Check_Ada_83_Warning;
766 ---------------------
767 -- Check_Arg_Count --
768 ---------------------
770 procedure Check_Arg_Count (Required : Nat) is
772 if Arg_Count /= Required then
773 Error_Pragma ("wrong number of arguments for pragma%");
777 --------------------------------
778 -- Check_Arg_Is_External_Name --
779 --------------------------------
781 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
782 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
785 if Nkind (Argx) = N_Identifier then
789 Analyze_And_Resolve (Argx, Standard_String);
791 if Is_OK_Static_Expression (Argx) then
794 elsif Etype (Argx) = Any_Type then
797 -- An interesting special case, if we have a string literal and
798 -- we are in Ada 83 mode, then we allow it even though it will
799 -- not be flagged as static. This allows expected Ada 83 mode
800 -- use of external names which are string literals, even though
801 -- technically these are not static in Ada 83.
803 elsif Ada_Version = Ada_83
804 and then Nkind (Argx) = N_String_Literal
808 -- Static expression that raises Constraint_Error. This has
809 -- already been flagged, so just exit from pragma processing.
811 elsif Is_Static_Expression (Argx) then
814 -- Here we have a real error (non-static expression)
817 Error_Msg_Name_1 := Pname;
821 "argument for pragma% must be a identifier or "
822 & "static string expression!";
825 Flag_Non_Static_Expr (Msg, Argx);
830 end Check_Arg_Is_External_Name;
832 -----------------------------
833 -- Check_Arg_Is_Identifier --
834 -----------------------------
836 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
837 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
839 if Nkind (Argx) /= N_Identifier then
841 ("argument for pragma% must be identifier", Argx);
843 end Check_Arg_Is_Identifier;
845 ----------------------------------
846 -- Check_Arg_Is_Integer_Literal --
847 ----------------------------------
849 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
850 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
852 if Nkind (Argx) /= N_Integer_Literal then
854 ("argument for pragma% must be integer literal", Argx);
856 end Check_Arg_Is_Integer_Literal;
858 -------------------------------------------
859 -- Check_Arg_Is_Library_Level_Local_Name --
860 -------------------------------------------
864 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
865 -- | library_unit_NAME
867 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
869 Check_Arg_Is_Local_Name (Arg);
871 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
872 and then Comes_From_Source (N)
875 ("argument for pragma% must be library level entity", Arg);
877 end Check_Arg_Is_Library_Level_Local_Name;
879 -----------------------------
880 -- Check_Arg_Is_Local_Name --
881 -----------------------------
885 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
886 -- | library_unit_NAME
888 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
889 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
894 if Nkind (Argx) not in N_Direct_Name
895 and then (Nkind (Argx) /= N_Attribute_Reference
896 or else Present (Expressions (Argx))
897 or else Nkind (Prefix (Argx)) /= N_Identifier)
898 and then (not Is_Entity_Name (Argx)
899 or else not Is_Compilation_Unit (Entity (Argx)))
901 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
904 -- No further check required if not an entity name
906 if not Is_Entity_Name (Argx) then
912 Ent : constant Entity_Id := Entity (Argx);
913 Scop : constant Entity_Id := Scope (Ent);
915 -- Case of a pragma applied to a compilation unit: pragma must
916 -- occur immediately after the program unit in the compilation.
918 if Is_Compilation_Unit (Ent) then
920 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
922 -- Case of pragma placed immediately after spec
924 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
927 -- Case of pragma placed immediately after body
929 elsif Nkind (Decl) = N_Subprogram_Declaration
930 and then Present (Corresponding_Body (Decl))
934 (Parent (Unit_Declaration_Node
935 (Corresponding_Body (Decl))));
937 -- All other cases are illegal
944 -- Special restricted placement rule from 10.2.1(11.8/2)
946 elsif Is_Generic_Formal (Ent)
947 and then Prag_Id = Pragma_Preelaborable_Initialization
949 OK := List_Containing (N) =
950 Generic_Formal_Declarations
951 (Unit_Declaration_Node (Scop));
953 -- Default case, just check that the pragma occurs in the scope
954 -- of the entity denoted by the name.
957 OK := Current_Scope = Scop;
962 ("pragma% argument must be in same declarative part", Arg);
966 end Check_Arg_Is_Local_Name;
968 ---------------------------------
969 -- Check_Arg_Is_Locking_Policy --
970 ---------------------------------
972 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
973 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
976 Check_Arg_Is_Identifier (Argx);
978 if not Is_Locking_Policy_Name (Chars (Argx)) then
979 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
981 end Check_Arg_Is_Locking_Policy;
983 -------------------------
984 -- Check_Arg_Is_One_Of --
985 -------------------------
987 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
988 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
991 Check_Arg_Is_Identifier (Argx);
993 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
994 Error_Msg_Name_2 := N1;
995 Error_Msg_Name_3 := N2;
996 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
998 end Check_Arg_Is_One_Of;
1000 procedure Check_Arg_Is_One_Of
1002 N1, N2, N3 : Name_Id)
1004 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1007 Check_Arg_Is_Identifier (Argx);
1009 if Chars (Argx) /= N1
1010 and then Chars (Argx) /= N2
1011 and then Chars (Argx) /= N3
1013 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1015 end Check_Arg_Is_One_Of;
1017 procedure Check_Arg_Is_One_Of
1019 N1, N2, N3, N4 : Name_Id)
1021 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1024 Check_Arg_Is_Identifier (Argx);
1026 if Chars (Argx) /= N1
1027 and then Chars (Argx) /= N2
1028 and then Chars (Argx) /= N3
1029 and then Chars (Argx) /= N4
1031 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1033 end Check_Arg_Is_One_Of;
1034 ---------------------------------
1035 -- Check_Arg_Is_Queuing_Policy --
1036 ---------------------------------
1038 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1039 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1042 Check_Arg_Is_Identifier (Argx);
1044 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1045 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1047 end Check_Arg_Is_Queuing_Policy;
1049 ------------------------------------
1050 -- Check_Arg_Is_Static_Expression --
1051 ------------------------------------
1053 procedure Check_Arg_Is_Static_Expression
1055 Typ : Entity_Id := Empty)
1057 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1060 if Present (Typ) then
1061 Analyze_And_Resolve (Argx, Typ);
1063 Analyze_And_Resolve (Argx);
1066 if Is_OK_Static_Expression (Argx) then
1069 elsif Etype (Argx) = Any_Type then
1072 -- An interesting special case, if we have a string literal and we
1073 -- are in Ada 83 mode, then we allow it even though it will not be
1074 -- flagged as static. This allows the use of Ada 95 pragmas like
1075 -- Import in Ada 83 mode. They will of course be flagged with
1076 -- warnings as usual, but will not cause errors.
1078 elsif Ada_Version = Ada_83
1079 and then Nkind (Argx) = N_String_Literal
1083 -- Static expression that raises Constraint_Error. This has already
1084 -- been flagged, so just exit from pragma processing.
1086 elsif Is_Static_Expression (Argx) then
1089 -- Finally, we have a real error
1092 Error_Msg_Name_1 := Pname;
1096 "argument for pragma% must be a static expression!";
1099 Flag_Non_Static_Expr (Msg, Argx);
1104 end Check_Arg_Is_Static_Expression;
1106 ------------------------------------------
1107 -- Check_Arg_Is_Task_Dispatching_Policy --
1108 ------------------------------------------
1110 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1111 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1114 Check_Arg_Is_Identifier (Argx);
1116 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1118 ("& is not a valid task dispatching policy name", Argx);
1120 end Check_Arg_Is_Task_Dispatching_Policy;
1122 ---------------------
1123 -- Check_Arg_Order --
1124 ---------------------
1126 procedure Check_Arg_Order (Names : Name_List) is
1129 Highest_So_Far : Natural := 0;
1130 -- Highest index in Names seen do far
1134 for J in 1 .. Arg_Count loop
1135 if Chars (Arg) /= No_Name then
1136 for K in Names'Range loop
1137 if Chars (Arg) = Names (K) then
1138 if K < Highest_So_Far then
1139 Error_Msg_Name_1 := Pname;
1141 ("parameters out of order for pragma%", Arg);
1142 Error_Msg_Name_1 := Names (K);
1143 Error_Msg_Name_2 := Names (Highest_So_Far);
1144 Error_Msg_N ("\% must appear before %", Arg);
1148 Highest_So_Far := K;
1156 end Check_Arg_Order;
1158 --------------------------------
1159 -- Check_At_Least_N_Arguments --
1160 --------------------------------
1162 procedure Check_At_Least_N_Arguments (N : Nat) is
1164 if Arg_Count < N then
1165 Error_Pragma ("too few arguments for pragma%");
1167 end Check_At_Least_N_Arguments;
1169 -------------------------------
1170 -- Check_At_Most_N_Arguments --
1171 -------------------------------
1173 procedure Check_At_Most_N_Arguments (N : Nat) is
1176 if Arg_Count > N then
1178 for J in 1 .. N loop
1180 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1183 end Check_At_Most_N_Arguments;
1185 ---------------------
1186 -- Check_Component --
1187 ---------------------
1189 procedure Check_Component
1192 In_Variant_Part : Boolean := False)
1194 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1195 Sindic : constant Node_Id :=
1196 Subtype_Indication (Component_Definition (Comp));
1197 Typ : constant Entity_Id := Etype (Comp_Id);
1199 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1200 -- Determine whether entity Id appears inside a generic body.
1201 -- Shouldn't this be in a more general place ???
1203 -------------------------
1204 -- Inside_Generic_Body --
1205 -------------------------
1207 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1212 while Present (S) and then S /= Standard_Standard loop
1213 if Ekind (S) = E_Generic_Package
1214 and then In_Package_Body (S)
1223 end Inside_Generic_Body;
1225 -- Start of processing for Check_Component
1228 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1229 -- object constraint, then the component type shall be an Unchecked_
1232 if Nkind (Sindic) = N_Subtype_Indication
1233 and then Has_Per_Object_Constraint (Comp_Id)
1234 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1237 ("component subtype subject to per-object constraint " &
1238 "must be an Unchecked_Union", Comp);
1240 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1241 -- the body of a generic unit, or within the body of any of its
1242 -- descendant library units, no part of the type of a component
1243 -- declared in a variant_part of the unchecked union type shall be of
1244 -- a formal private type or formal private extension declared within
1245 -- the formal part of the generic unit.
1247 elsif Ada_Version >= Ada_2012
1248 and then Inside_Generic_Body (UU_Typ)
1249 and then In_Variant_Part
1250 and then Is_Private_Type (Typ)
1251 and then Is_Generic_Type (Typ)
1254 ("component of Unchecked_Union cannot be of generic type", Comp);
1256 elsif Needs_Finalization (Typ) then
1258 ("component of Unchecked_Union cannot be controlled", Comp);
1260 elsif Has_Task (Typ) then
1262 ("component of Unchecked_Union cannot have tasks", Comp);
1264 end Check_Component;
1266 ----------------------------
1267 -- Check_Duplicate_Pragma --
1268 ----------------------------
1270 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1274 -- Nothing to do if this pragma comes from an aspect specification,
1275 -- since we could not be duplicating a pragma, and we dealt with the
1276 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1278 if From_Aspect_Specification (N) then
1282 -- Otherwise current pragma may duplicate previous pragma or a
1283 -- previously given aspect specification for the same pragma.
1285 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1288 Error_Msg_Name_1 := Pragma_Name (N);
1289 Error_Msg_Sloc := Sloc (P);
1291 if Nkind (P) = N_Aspect_Specification
1292 or else From_Aspect_Specification (P)
1294 Error_Msg_NE ("aspect% for & previously given#", N, E);
1296 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1301 end Check_Duplicate_Pragma;
1303 ----------------------------------
1304 -- Check_Duplicated_Export_Name --
1305 ----------------------------------
1307 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1308 String_Val : constant String_Id := Strval (Nam);
1311 -- We are only interested in the export case, and in the case of
1312 -- generics, it is the instance, not the template, that is the
1313 -- problem (the template will generate a warning in any case).
1315 if not Inside_A_Generic
1316 and then (Prag_Id = Pragma_Export
1318 Prag_Id = Pragma_Export_Procedure
1320 Prag_Id = Pragma_Export_Valued_Procedure
1322 Prag_Id = Pragma_Export_Function)
1324 for J in Externals.First .. Externals.Last loop
1325 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1326 Error_Msg_Sloc := Sloc (Externals.Table (J));
1327 Error_Msg_N ("external name duplicates name given#", Nam);
1332 Externals.Append (Nam);
1334 end Check_Duplicated_Export_Name;
1336 -------------------------
1337 -- Check_First_Subtype --
1338 -------------------------
1340 procedure Check_First_Subtype (Arg : Node_Id) is
1341 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1342 Ent : constant Entity_Id := Entity (Argx);
1345 if Is_First_Subtype (Ent) then
1348 elsif Is_Type (Ent) then
1350 ("pragma% cannot apply to subtype", Argx);
1352 elsif Is_Object (Ent) then
1354 ("pragma% cannot apply to object, requires a type", Argx);
1358 ("pragma% cannot apply to&, requires a type", Argx);
1360 end Check_First_Subtype;
1362 ---------------------------
1363 -- Check_In_Main_Program --
1364 ---------------------------
1366 procedure Check_In_Main_Program is
1367 P : constant Node_Id := Parent (N);
1370 -- Must be at in subprogram body
1372 if Nkind (P) /= N_Subprogram_Body then
1373 Error_Pragma ("% pragma allowed only in subprogram");
1375 -- Otherwise warn if obviously not main program
1377 elsif Present (Parameter_Specifications (Specification (P)))
1378 or else not Is_Compilation_Unit (Defining_Entity (P))
1380 Error_Msg_Name_1 := Pname;
1382 ("?pragma% is only effective in main program", N);
1384 end Check_In_Main_Program;
1386 ---------------------------------------
1387 -- Check_Interrupt_Or_Attach_Handler --
1388 ---------------------------------------
1390 procedure Check_Interrupt_Or_Attach_Handler is
1391 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1392 Handler_Proc, Proc_Scope : Entity_Id;
1397 if Prag_Id = Pragma_Interrupt_Handler then
1398 Check_Restriction (No_Dynamic_Attachment, N);
1401 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1402 Proc_Scope := Scope (Handler_Proc);
1404 -- On AAMP only, a pragma Interrupt_Handler is supported for
1405 -- nonprotected parameterless procedures.
1407 if not AAMP_On_Target
1408 or else Prag_Id = Pragma_Attach_Handler
1410 if Ekind (Proc_Scope) /= E_Protected_Type then
1412 ("argument of pragma% must be protected procedure", Arg1);
1415 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1416 Error_Pragma ("pragma% must be in protected definition");
1420 if not Is_Library_Level_Entity (Proc_Scope)
1421 or else (AAMP_On_Target
1422 and then not Is_Library_Level_Entity (Handler_Proc))
1425 ("argument for pragma% must be library level entity", Arg1);
1428 -- AI05-0033: A pragma cannot appear within a generic body, because
1429 -- instance can be in a nested scope. The check that protected type
1430 -- is itself a library-level declaration is done elsewhere.
1432 -- Note: we omit this check in Codepeer mode to properly handle code
1433 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1435 if Inside_A_Generic then
1436 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1437 and then In_Package_Body (Scope (Current_Scope))
1438 and then not CodePeer_Mode
1440 Error_Pragma ("pragma% cannot be used inside a generic");
1443 end Check_Interrupt_Or_Attach_Handler;
1445 -------------------------------------------
1446 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1447 -------------------------------------------
1449 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1458 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1461 elsif Nkind_In (P, N_Package_Specification,
1466 -- Note: the following tests seem a little peculiar, because
1467 -- they test for bodies, but if we were in the statement part
1468 -- of the body, we would already have hit the handled statement
1469 -- sequence, so the only way we get here is by being in the
1470 -- declarative part of the body.
1472 elsif Nkind_In (P, N_Subprogram_Body,
1483 Error_Pragma ("pragma% is not in declarative part or package spec");
1484 end Check_Is_In_Decl_Part_Or_Package_Spec;
1486 -------------------------
1487 -- Check_No_Identifier --
1488 -------------------------
1490 procedure Check_No_Identifier (Arg : Node_Id) is
1492 if Nkind (Arg) = N_Pragma_Argument_Association
1493 and then Chars (Arg) /= No_Name
1495 Error_Pragma_Arg_Ident
1496 ("pragma% does not permit identifier& here", Arg);
1498 end Check_No_Identifier;
1500 --------------------------
1501 -- Check_No_Identifiers --
1502 --------------------------
1504 procedure Check_No_Identifiers is
1507 if Arg_Count > 0 then
1509 while Present (Arg_Node) loop
1510 Check_No_Identifier (Arg_Node);
1514 end Check_No_Identifiers;
1516 -------------------------------
1517 -- Check_Optional_Identifier --
1518 -------------------------------
1520 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1523 and then Nkind (Arg) = N_Pragma_Argument_Association
1524 and then Chars (Arg) /= No_Name
1526 if Chars (Arg) /= Id then
1527 Error_Msg_Name_1 := Pname;
1528 Error_Msg_Name_2 := Id;
1529 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1533 end Check_Optional_Identifier;
1535 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1537 Name_Buffer (1 .. Id'Length) := Id;
1538 Name_Len := Id'Length;
1539 Check_Optional_Identifier (Arg, Name_Find);
1540 end Check_Optional_Identifier;
1542 --------------------------------------
1543 -- Check_Precondition_Postcondition --
1544 --------------------------------------
1546 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1550 procedure Chain_PPC (PO : Node_Id);
1551 -- If PO is a subprogram declaration node (or a generic subprogram
1552 -- declaration node), then the precondition/postcondition applies
1553 -- to this subprogram and the processing for the pragma is completed.
1554 -- Otherwise the pragma is misplaced.
1560 procedure Chain_PPC (PO : Node_Id) is
1565 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1566 if not From_Aspect_Specification (N) then
1568 ("pragma% cannot be applied to abstract subprogram");
1570 elsif Class_Present (N) then
1575 ("aspect % requires ''Class for abstract subprogram");
1578 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1579 N_Generic_Subprogram_Declaration,
1580 N_Entry_Declaration)
1585 -- Here if we have [generic] subprogram or entry declaration
1587 if Nkind (PO) = N_Entry_Declaration then
1588 S := Defining_Entity (PO);
1590 S := Defining_Unit_Name (Specification (PO));
1593 -- Make sure we do not have the case of a precondition pragma when
1594 -- the Pre'Class aspect is present.
1596 -- We do this by looking at pragmas already chained to the entity
1597 -- since the aspect derived pragma will be put on this list first.
1599 if Pragma_Name (N) = Name_Precondition then
1600 if not From_Aspect_Specification (N) then
1601 P := Spec_PPC_List (S);
1602 while Present (P) loop
1603 if Pragma_Name (P) = Name_Precondition
1604 and then From_Aspect_Specification (P)
1605 and then Class_Present (P)
1607 Error_Msg_Sloc := Sloc (P);
1609 ("pragma% not allowed, `Pre''Class` aspect given#");
1612 P := Next_Pragma (P);
1617 -- Similarly check for Pre with inherited Pre'Class. Note that
1618 -- we cover the aspect case as well here.
1620 if Pragma_Name (N) = Name_Precondition
1621 and then not Class_Present (N)
1624 Inherited : constant Subprogram_List :=
1625 Inherited_Subprograms (S);
1629 for J in Inherited'Range loop
1630 P := Spec_PPC_List (Inherited (J));
1631 while Present (P) loop
1632 if Pragma_Name (P) = Name_Precondition
1633 and then Class_Present (P)
1635 Error_Msg_Sloc := Sloc (P);
1637 ("pragma% not allowed, `Pre''Class` "
1638 & "aspect inherited from#");
1641 P := Next_Pragma (P);
1647 -- Note: we do not analye the pragma at this point. Instead we
1648 -- delay this analysis until the end of the declarative part in
1649 -- which the pragma appears. This implements the required delay
1650 -- in this analysis, allowing forward references. The analysis
1651 -- happens at the end of Analyze_Declarations.
1653 -- Chain spec PPC pragma to list for subprogram
1655 Set_Next_Pragma (N, Spec_PPC_List (S));
1656 Set_Spec_PPC_List (S, N);
1658 -- Return indicating spec case
1664 -- Start of processing for Check_Precondition_Postcondition
1667 if not Is_List_Member (N) then
1671 -- Preanalyze message argument if present. Visibility in this
1672 -- argument is established at the point of pragma occurrence.
1674 if Arg_Count = 2 then
1675 Check_Optional_Identifier (Arg2, Name_Message);
1676 Preanalyze_Spec_Expression
1677 (Get_Pragma_Arg (Arg2), Standard_String);
1680 -- Record if pragma is enabled
1682 if Check_Enabled (Pname) then
1683 Set_Pragma_Enabled (N);
1684 Set_SCO_Pragma_Enabled (Loc);
1687 -- If we are within an inlined body, the legality of the pragma
1688 -- has been checked already.
1690 if In_Inlined_Body then
1695 -- Search prior declarations
1698 while Present (Prev (P)) loop
1701 -- If the previous node is a generic subprogram, do not go to to
1702 -- the original node, which is the unanalyzed tree: we need to
1703 -- attach the pre/postconditions to the analyzed version at this
1704 -- point. They get propagated to the original tree when analyzing
1705 -- the corresponding body.
1707 if Nkind (P) not in N_Generic_Declaration then
1708 PO := Original_Node (P);
1713 -- Skip past prior pragma
1715 if Nkind (PO) = N_Pragma then
1718 -- Skip stuff not coming from source
1720 elsif not Comes_From_Source (PO) then
1723 -- Only remaining possibility is subprogram declaration
1731 -- If we fall through loop, pragma is at start of list, so see if it
1732 -- is at the start of declarations of a subprogram body.
1734 if Nkind (Parent (N)) = N_Subprogram_Body
1735 and then List_Containing (N) = Declarations (Parent (N))
1737 if Operating_Mode /= Generate_Code
1738 or else Inside_A_Generic
1740 -- Analyze pragma expression for correctness and for ASIS use
1742 Preanalyze_Spec_Expression
1743 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1749 -- See if it is in the pragmas after a library level subprogram
1751 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1752 Chain_PPC (Unit (Parent (Parent (N))));
1756 -- If we fall through, pragma was misplaced
1759 end Check_Precondition_Postcondition;
1761 -----------------------------
1762 -- Check_Static_Constraint --
1763 -----------------------------
1765 -- Note: for convenience in writing this procedure, in addition to
1766 -- the officially (i.e. by spec) allowed argument which is always a
1767 -- constraint, it also allows ranges and discriminant associations.
1768 -- Above is not clear ???
1770 procedure Check_Static_Constraint (Constr : Node_Id) is
1772 procedure Require_Static (E : Node_Id);
1773 -- Require given expression to be static expression
1775 --------------------
1776 -- Require_Static --
1777 --------------------
1779 procedure Require_Static (E : Node_Id) is
1781 if not Is_OK_Static_Expression (E) then
1782 Flag_Non_Static_Expr
1783 ("non-static constraint not allowed in Unchecked_Union!", E);
1788 -- Start of processing for Check_Static_Constraint
1791 case Nkind (Constr) is
1792 when N_Discriminant_Association =>
1793 Require_Static (Expression (Constr));
1796 Require_Static (Low_Bound (Constr));
1797 Require_Static (High_Bound (Constr));
1799 when N_Attribute_Reference =>
1800 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1801 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1803 when N_Range_Constraint =>
1804 Check_Static_Constraint (Range_Expression (Constr));
1806 when N_Index_Or_Discriminant_Constraint =>
1810 IDC := First (Constraints (Constr));
1811 while Present (IDC) loop
1812 Check_Static_Constraint (IDC);
1820 end Check_Static_Constraint;
1822 --------------------------------------
1823 -- Check_Valid_Configuration_Pragma --
1824 --------------------------------------
1826 -- A configuration pragma must appear in the context clause of a
1827 -- compilation unit, and only other pragmas may precede it. Note that
1828 -- the test also allows use in a configuration pragma file.
1830 procedure Check_Valid_Configuration_Pragma is
1832 if not Is_Configuration_Pragma then
1833 Error_Pragma ("incorrect placement for configuration pragma%");
1835 end Check_Valid_Configuration_Pragma;
1837 -------------------------------------
1838 -- Check_Valid_Library_Unit_Pragma --
1839 -------------------------------------
1841 procedure Check_Valid_Library_Unit_Pragma is
1843 Parent_Node : Node_Id;
1844 Unit_Name : Entity_Id;
1845 Unit_Kind : Node_Kind;
1846 Unit_Node : Node_Id;
1847 Sindex : Source_File_Index;
1850 if not Is_List_Member (N) then
1854 Plist := List_Containing (N);
1855 Parent_Node := Parent (Plist);
1857 if Parent_Node = Empty then
1860 -- Case of pragma appearing after a compilation unit. In this case
1861 -- it must have an argument with the corresponding name and must
1862 -- be part of the following pragmas of its parent.
1864 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1865 if Plist /= Pragmas_After (Parent_Node) then
1868 elsif Arg_Count = 0 then
1870 ("argument required if outside compilation unit");
1873 Check_No_Identifiers;
1874 Check_Arg_Count (1);
1875 Unit_Node := Unit (Parent (Parent_Node));
1876 Unit_Kind := Nkind (Unit_Node);
1878 Analyze (Get_Pragma_Arg (Arg1));
1880 if Unit_Kind = N_Generic_Subprogram_Declaration
1881 or else Unit_Kind = N_Subprogram_Declaration
1883 Unit_Name := Defining_Entity (Unit_Node);
1885 elsif Unit_Kind in N_Generic_Instantiation then
1886 Unit_Name := Defining_Entity (Unit_Node);
1889 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1892 if Chars (Unit_Name) /=
1893 Chars (Entity (Get_Pragma_Arg (Arg1)))
1896 ("pragma% argument is not current unit name", Arg1);
1899 if Ekind (Unit_Name) = E_Package
1900 and then Present (Renamed_Entity (Unit_Name))
1902 Error_Pragma ("pragma% not allowed for renamed package");
1906 -- Pragma appears other than after a compilation unit
1909 -- Here we check for the generic instantiation case and also
1910 -- for the case of processing a generic formal package. We
1911 -- detect these cases by noting that the Sloc on the node
1912 -- does not belong to the current compilation unit.
1914 Sindex := Source_Index (Current_Sem_Unit);
1916 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1917 Rewrite (N, Make_Null_Statement (Loc));
1920 -- If before first declaration, the pragma applies to the
1921 -- enclosing unit, and the name if present must be this name.
1923 elsif Is_Before_First_Decl (N, Plist) then
1924 Unit_Node := Unit_Declaration_Node (Current_Scope);
1925 Unit_Kind := Nkind (Unit_Node);
1927 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1930 elsif Unit_Kind = N_Subprogram_Body
1931 and then not Acts_As_Spec (Unit_Node)
1935 elsif Nkind (Parent_Node) = N_Package_Body then
1938 elsif Nkind (Parent_Node) = N_Package_Specification
1939 and then Plist = Private_Declarations (Parent_Node)
1943 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1944 or else Nkind (Parent_Node) =
1945 N_Generic_Subprogram_Declaration)
1946 and then Plist = Generic_Formal_Declarations (Parent_Node)
1950 elsif Arg_Count > 0 then
1951 Analyze (Get_Pragma_Arg (Arg1));
1953 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
1955 ("name in pragma% must be enclosing unit", Arg1);
1958 -- It is legal to have no argument in this context
1964 -- Error if not before first declaration. This is because a
1965 -- library unit pragma argument must be the name of a library
1966 -- unit (RM 10.1.5(7)), but the only names permitted in this
1967 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1968 -- generic subprogram declarations or generic instantiations.
1972 ("pragma% misplaced, must be before first declaration");
1976 end Check_Valid_Library_Unit_Pragma;
1982 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
1983 Clist : constant Node_Id := Component_List (Variant);
1987 if not Is_Non_Empty_List (Component_Items (Clist)) then
1989 ("Unchecked_Union may not have empty component list",
1994 Comp := First (Component_Items (Clist));
1995 while Present (Comp) loop
1996 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2005 procedure Error_Pragma (Msg : String) is
2006 MsgF : String := Msg;
2008 Error_Msg_Name_1 := Pname;
2010 Error_Msg_N (MsgF, N);
2014 ----------------------
2015 -- Error_Pragma_Arg --
2016 ----------------------
2018 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2019 MsgF : String := Msg;
2021 Error_Msg_Name_1 := Pname;
2023 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2025 end Error_Pragma_Arg;
2027 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2028 MsgF : String := Msg1;
2030 Error_Msg_Name_1 := Pname;
2032 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2033 Error_Pragma_Arg (Msg2, Arg);
2034 end Error_Pragma_Arg;
2036 ----------------------------
2037 -- Error_Pragma_Arg_Ident --
2038 ----------------------------
2040 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2041 MsgF : String := Msg;
2043 Error_Msg_Name_1 := Pname;
2045 Error_Msg_N (MsgF, Arg);
2047 end Error_Pragma_Arg_Ident;
2049 ----------------------
2050 -- Error_Pragma_Ref --
2051 ----------------------
2053 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2054 MsgF : String := Msg;
2056 Error_Msg_Name_1 := Pname;
2058 Error_Msg_Sloc := Sloc (Ref);
2059 Error_Msg_NE (MsgF, N, Ref);
2061 end Error_Pragma_Ref;
2063 ------------------------
2064 -- Find_Lib_Unit_Name --
2065 ------------------------
2067 function Find_Lib_Unit_Name return Entity_Id is
2069 -- Return inner compilation unit entity, for case of nested
2070 -- categorization pragmas. This happens in generic unit.
2072 if Nkind (Parent (N)) = N_Package_Specification
2073 and then Defining_Entity (Parent (N)) /= Current_Scope
2075 return Defining_Entity (Parent (N));
2077 return Current_Scope;
2079 end Find_Lib_Unit_Name;
2081 ----------------------------
2082 -- Find_Program_Unit_Name --
2083 ----------------------------
2085 procedure Find_Program_Unit_Name (Id : Node_Id) is
2086 Unit_Name : Entity_Id;
2087 Unit_Kind : Node_Kind;
2088 P : constant Node_Id := Parent (N);
2091 if Nkind (P) = N_Compilation_Unit then
2092 Unit_Kind := Nkind (Unit (P));
2094 if Unit_Kind = N_Subprogram_Declaration
2095 or else Unit_Kind = N_Package_Declaration
2096 or else Unit_Kind in N_Generic_Declaration
2098 Unit_Name := Defining_Entity (Unit (P));
2100 if Chars (Id) = Chars (Unit_Name) then
2101 Set_Entity (Id, Unit_Name);
2102 Set_Etype (Id, Etype (Unit_Name));
2104 Set_Etype (Id, Any_Type);
2106 ("cannot find program unit referenced by pragma%");
2110 Set_Etype (Id, Any_Type);
2111 Error_Pragma ("pragma% inapplicable to this unit");
2117 end Find_Program_Unit_Name;
2119 -----------------------------------------
2120 -- Find_Unique_Parameterless_Procedure --
2121 -----------------------------------------
2123 function Find_Unique_Parameterless_Procedure
2125 Arg : Node_Id) return Entity_Id
2127 Proc : Entity_Id := Empty;
2130 -- The body of this procedure needs some comments ???
2132 if not Is_Entity_Name (Name) then
2134 ("argument of pragma% must be entity name", Arg);
2136 elsif not Is_Overloaded (Name) then
2137 Proc := Entity (Name);
2139 if Ekind (Proc) /= E_Procedure
2140 or else Present (First_Formal (Proc))
2143 ("argument of pragma% must be parameterless procedure", Arg);
2148 Found : Boolean := False;
2150 Index : Interp_Index;
2153 Get_First_Interp (Name, Index, It);
2154 while Present (It.Nam) loop
2157 if Ekind (Proc) = E_Procedure
2158 and then No (First_Formal (Proc))
2162 Set_Entity (Name, Proc);
2163 Set_Is_Overloaded (Name, False);
2166 ("ambiguous handler name for pragma% ", Arg);
2170 Get_Next_Interp (Index, It);
2175 ("argument of pragma% must be parameterless procedure",
2178 Proc := Entity (Name);
2184 end Find_Unique_Parameterless_Procedure;
2190 procedure Fix_Error (Msg : in out String) is
2192 if From_Aspect_Specification (N) then
2193 for J in Msg'First .. Msg'Last - 5 loop
2194 if Msg (J .. J + 5) = "pragma" then
2195 Msg (J .. J + 5) := "aspect";
2199 if Error_Msg_Name_1 = Name_Precondition then
2200 Error_Msg_Name_1 := Name_Pre;
2201 elsif Error_Msg_Name_1 = Name_Postcondition then
2202 Error_Msg_Name_1 := Name_Post;
2207 -------------------------
2208 -- Gather_Associations --
2209 -------------------------
2211 procedure Gather_Associations
2213 Args : out Args_List)
2218 -- Initialize all parameters to Empty
2220 for J in Args'Range loop
2224 -- That's all we have to do if there are no argument associations
2226 if No (Pragma_Argument_Associations (N)) then
2230 -- Otherwise first deal with any positional parameters present
2232 Arg := First (Pragma_Argument_Associations (N));
2233 for Index in Args'Range loop
2234 exit when No (Arg) or else Chars (Arg) /= No_Name;
2235 Args (Index) := Get_Pragma_Arg (Arg);
2239 -- Positional parameters all processed, if any left, then we
2240 -- have too many positional parameters.
2242 if Present (Arg) and then Chars (Arg) = No_Name then
2244 ("too many positional associations for pragma%", Arg);
2247 -- Process named parameters if any are present
2249 while Present (Arg) loop
2250 if Chars (Arg) = No_Name then
2252 ("positional association cannot follow named association",
2256 for Index in Names'Range loop
2257 if Names (Index) = Chars (Arg) then
2258 if Present (Args (Index)) then
2260 ("duplicate argument association for pragma%", Arg);
2262 Args (Index) := Get_Pragma_Arg (Arg);
2267 if Index = Names'Last then
2268 Error_Msg_Name_1 := Pname;
2269 Error_Msg_N ("pragma% does not allow & argument", Arg);
2271 -- Check for possible misspelling
2273 for Index1 in Names'Range loop
2274 if Is_Bad_Spelling_Of
2275 (Chars (Arg), Names (Index1))
2277 Error_Msg_Name_1 := Names (Index1);
2278 Error_Msg_N -- CODEFIX
2279 ("\possible misspelling of%", Arg);
2291 end Gather_Associations;
2297 procedure GNAT_Pragma is
2299 Check_Restriction (No_Implementation_Pragmas, N);
2302 --------------------------
2303 -- Is_Before_First_Decl --
2304 --------------------------
2306 function Is_Before_First_Decl
2307 (Pragma_Node : Node_Id;
2308 Decls : List_Id) return Boolean
2310 Item : Node_Id := First (Decls);
2313 -- Only other pragmas can come before this pragma
2316 if No (Item) or else Nkind (Item) /= N_Pragma then
2319 elsif Item = Pragma_Node then
2325 end Is_Before_First_Decl;
2327 -----------------------------
2328 -- Is_Configuration_Pragma --
2329 -----------------------------
2331 -- A configuration pragma must appear in the context clause of a
2332 -- compilation unit, and only other pragmas may precede it. Note that
2333 -- the test below also permits use in a configuration pragma file.
2335 function Is_Configuration_Pragma return Boolean is
2336 Lis : constant List_Id := List_Containing (N);
2337 Par : constant Node_Id := Parent (N);
2341 -- If no parent, then we are in the configuration pragma file,
2342 -- so the placement is definitely appropriate.
2347 -- Otherwise we must be in the context clause of a compilation unit
2348 -- and the only thing allowed before us in the context list is more
2349 -- configuration pragmas.
2351 elsif Nkind (Par) = N_Compilation_Unit
2352 and then Context_Items (Par) = Lis
2359 elsif Nkind (Prg) /= N_Pragma then
2369 end Is_Configuration_Pragma;
2371 --------------------------
2372 -- Is_In_Context_Clause --
2373 --------------------------
2375 function Is_In_Context_Clause return Boolean is
2377 Parent_Node : Node_Id;
2380 if not Is_List_Member (N) then
2384 Plist := List_Containing (N);
2385 Parent_Node := Parent (Plist);
2387 if Parent_Node = Empty
2388 or else Nkind (Parent_Node) /= N_Compilation_Unit
2389 or else Context_Items (Parent_Node) /= Plist
2396 end Is_In_Context_Clause;
2398 ---------------------------------
2399 -- Is_Static_String_Expression --
2400 ---------------------------------
2402 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2403 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2406 Analyze_And_Resolve (Argx);
2407 return Is_OK_Static_Expression (Argx)
2408 and then Nkind (Argx) = N_String_Literal;
2409 end Is_Static_String_Expression;
2411 ----------------------
2412 -- Pragma_Misplaced --
2413 ----------------------
2415 procedure Pragma_Misplaced is
2417 Error_Pragma ("incorrect placement of pragma%");
2418 end Pragma_Misplaced;
2420 ------------------------------------
2421 -- Process Atomic_Shared_Volatile --
2422 ------------------------------------
2424 procedure Process_Atomic_Shared_Volatile is
2431 procedure Set_Atomic (E : Entity_Id);
2432 -- Set given type as atomic, and if no explicit alignment was given,
2433 -- set alignment to unknown, since back end knows what the alignment
2434 -- requirements are for atomic arrays. Note: this step is necessary
2435 -- for derived types.
2441 procedure Set_Atomic (E : Entity_Id) is
2443 Set_Is_Atomic (E, Sense);
2445 if Sense and then not Has_Alignment_Clause (E) then
2446 Set_Alignment (E, Uint_0);
2450 -- Start of processing for Process_Atomic_Shared_Volatile
2453 Check_Ada_83_Warning;
2454 Check_No_Identifiers;
2455 Check_Arg_Count (1);
2456 Check_Arg_Is_Local_Name (Arg1);
2457 E_Id := Get_Pragma_Arg (Arg1);
2459 if Etype (E_Id) = Any_Type then
2464 D := Declaration_Node (E);
2467 -- Check duplicate before we chain ourselves!
2469 Check_Duplicate_Pragma (E);
2471 -- Now check appropriateness of the entity
2474 if Rep_Item_Too_Early (E, N)
2476 Rep_Item_Too_Late (E, N)
2480 Check_First_Subtype (Arg1);
2483 if Prag_Id /= Pragma_Volatile then
2485 Set_Atomic (Underlying_Type (E));
2486 Set_Atomic (Base_Type (E));
2489 -- Attribute belongs on the base type. If the view of the type is
2490 -- currently private, it also belongs on the underlying type.
2492 Set_Is_Volatile (Base_Type (E), Sense);
2493 Set_Is_Volatile (Underlying_Type (E), Sense);
2495 Set_Treat_As_Volatile (E, Sense);
2496 Set_Treat_As_Volatile (Underlying_Type (E), Sense);
2498 elsif K = N_Object_Declaration
2499 or else (K = N_Component_Declaration
2500 and then Original_Record_Component (E) = E)
2502 if Rep_Item_Too_Late (E, N) then
2506 if Prag_Id /= Pragma_Volatile then
2507 Set_Is_Atomic (E, Sense);
2509 -- If the object declaration has an explicit initialization, a
2510 -- temporary may have to be created to hold the expression, to
2511 -- ensure that access to the object remain atomic.
2513 if Nkind (Parent (E)) = N_Object_Declaration
2514 and then Present (Expression (Parent (E)))
2517 Set_Has_Delayed_Freeze (E);
2520 -- An interesting improvement here. If an object of type X is
2521 -- declared atomic, and the type X is not atomic, that's a
2522 -- pity, since it may not have appropriate alignment etc. We
2523 -- can rescue this in the special case where the object and
2524 -- type are in the same unit by just setting the type as
2525 -- atomic, so that the back end will process it as atomic.
2527 Utyp := Underlying_Type (Etype (E));
2530 and then Sloc (E) > No_Location
2531 and then Sloc (Utyp) > No_Location
2533 Get_Source_File_Index (Sloc (E)) =
2534 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2536 Set_Is_Atomic (Underlying_Type (Etype (E)), Sense);
2540 Set_Is_Volatile (E);
2541 Set_Treat_As_Volatile (E);
2545 ("inappropriate entity for pragma%", Arg1);
2547 end Process_Atomic_Shared_Volatile;
2549 -------------------------------------------
2550 -- Process_Compile_Time_Warning_Or_Error --
2551 -------------------------------------------
2553 procedure Process_Compile_Time_Warning_Or_Error is
2554 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2557 Check_Arg_Count (2);
2558 Check_No_Identifiers;
2559 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2560 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2562 if Compile_Time_Known_Value (Arg1x) then
2563 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2565 Str : constant String_Id :=
2566 Strval (Get_Pragma_Arg (Arg2));
2567 Len : constant Int := String_Length (Str);
2572 Cent : constant Entity_Id :=
2573 Cunit_Entity (Current_Sem_Unit);
2575 Force : constant Boolean :=
2576 Prag_Id = Pragma_Compile_Time_Warning
2578 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2579 and then (Ekind (Cent) /= E_Package
2580 or else not In_Private_Part (Cent));
2581 -- Set True if this is the warning case, and we are in the
2582 -- visible part of a package spec, or in a subprogram spec,
2583 -- in which case we want to force the client to see the
2584 -- warning, even though it is not in the main unit.
2587 -- Loop through segments of message separated by line feeds.
2588 -- We output these segments as separate messages with
2589 -- continuation marks for all but the first.
2594 Error_Msg_Strlen := 0;
2596 -- Loop to copy characters from argument to error message
2600 exit when Ptr > Len;
2601 CC := Get_String_Char (Str, Ptr);
2604 -- Ignore wide chars ??? else store character
2606 if In_Character_Range (CC) then
2607 C := Get_Character (CC);
2608 exit when C = ASCII.LF;
2609 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2610 Error_Msg_String (Error_Msg_Strlen) := C;
2614 -- Here with one line ready to go
2616 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2618 -- If this is a warning in a spec, then we want clients
2619 -- to see the warning, so mark the message with the
2620 -- special sequence !! to force the warning. In the case
2621 -- of a package spec, we do not force this if we are in
2622 -- the private part of the spec.
2625 if Cont = False then
2626 Error_Msg_N ("<~!!", Arg1);
2629 Error_Msg_N ("\<~!!", Arg1);
2632 -- Error, rather than warning, or in a body, so we do not
2633 -- need to force visibility for client (error will be
2634 -- output in any case, and this is the situation in which
2635 -- we do not want a client to get a warning, since the
2636 -- warning is in the body or the spec private part).
2639 if Cont = False then
2640 Error_Msg_N ("<~", Arg1);
2643 Error_Msg_N ("\<~", Arg1);
2647 exit when Ptr > Len;
2652 end Process_Compile_Time_Warning_Or_Error;
2654 ------------------------
2655 -- Process_Convention --
2656 ------------------------
2658 procedure Process_Convention
2659 (C : out Convention_Id;
2660 Ent : out Entity_Id)
2666 Comp_Unit : Unit_Number_Type;
2668 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2669 -- Called if we have more than one Export/Import/Convention pragma.
2670 -- This is generally illegal, but we have a special case of allowing
2671 -- Import and Interface to coexist if they specify the convention in
2672 -- a consistent manner. We are allowed to do this, since Interface is
2673 -- an implementation defined pragma, and we choose to do it since we
2674 -- know Rational allows this combination. S is the entity id of the
2675 -- subprogram in question. This procedure also sets the special flag
2676 -- Import_Interface_Present in both pragmas in the case where we do
2677 -- have matching Import and Interface pragmas.
2679 procedure Set_Convention_From_Pragma (E : Entity_Id);
2680 -- Set convention in entity E, and also flag that the entity has a
2681 -- convention pragma. If entity is for a private or incomplete type,
2682 -- also set convention and flag on underlying type. This procedure
2683 -- also deals with the special case of C_Pass_By_Copy convention.
2685 -------------------------------
2686 -- Diagnose_Multiple_Pragmas --
2687 -------------------------------
2689 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2690 Pdec : constant Node_Id := Declaration_Node (S);
2694 function Same_Convention (Decl : Node_Id) return Boolean;
2695 -- Decl is a pragma node. This function returns True if this
2696 -- pragma has a first argument that is an identifier with a
2697 -- Chars field corresponding to the Convention_Id C.
2699 function Same_Name (Decl : Node_Id) return Boolean;
2700 -- Decl is a pragma node. This function returns True if this
2701 -- pragma has a second argument that is an identifier with a
2702 -- Chars field that matches the Chars of the current subprogram.
2704 ---------------------
2705 -- Same_Convention --
2706 ---------------------
2708 function Same_Convention (Decl : Node_Id) return Boolean is
2709 Arg1 : constant Node_Id :=
2710 First (Pragma_Argument_Associations (Decl));
2713 if Present (Arg1) then
2715 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2717 if Nkind (Arg) = N_Identifier
2718 and then Is_Convention_Name (Chars (Arg))
2719 and then Get_Convention_Id (Chars (Arg)) = C
2727 end Same_Convention;
2733 function Same_Name (Decl : Node_Id) return Boolean is
2734 Arg1 : constant Node_Id :=
2735 First (Pragma_Argument_Associations (Decl));
2743 Arg2 := Next (Arg1);
2750 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2752 if Nkind (Arg) = N_Identifier
2753 and then Chars (Arg) = Chars (S)
2762 -- Start of processing for Diagnose_Multiple_Pragmas
2767 -- Definitely give message if we have Convention/Export here
2769 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2772 -- If we have an Import or Export, scan back from pragma to
2773 -- find any previous pragma applying to the same procedure.
2774 -- The scan will be terminated by the start of the list, or
2775 -- hitting the subprogram declaration. This won't allow one
2776 -- pragma to appear in the public part and one in the private
2777 -- part, but that seems very unlikely in practice.
2781 while Present (Decl) and then Decl /= Pdec loop
2783 -- Look for pragma with same name as us
2785 if Nkind (Decl) = N_Pragma
2786 and then Same_Name (Decl)
2788 -- Give error if same as our pragma or Export/Convention
2790 if Pragma_Name (Decl) = Name_Export
2792 Pragma_Name (Decl) = Name_Convention
2794 Pragma_Name (Decl) = Pragma_Name (N)
2798 -- Case of Import/Interface or the other way round
2800 elsif Pragma_Name (Decl) = Name_Interface
2802 Pragma_Name (Decl) = Name_Import
2804 -- Here we know that we have Import and Interface. It
2805 -- doesn't matter which way round they are. See if
2806 -- they specify the same convention. If so, all OK,
2807 -- and set special flags to stop other messages
2809 if Same_Convention (Decl) then
2810 Set_Import_Interface_Present (N);
2811 Set_Import_Interface_Present (Decl);
2814 -- If different conventions, special message
2817 Error_Msg_Sloc := Sloc (Decl);
2819 ("convention differs from that given#", Arg1);
2829 -- Give message if needed if we fall through those tests
2833 ("at most one Convention/Export/Import pragma is allowed",
2836 end Diagnose_Multiple_Pragmas;
2838 --------------------------------
2839 -- Set_Convention_From_Pragma --
2840 --------------------------------
2842 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2844 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2845 -- for an overridden dispatching operation. Technically this is
2846 -- an amendment and should only be done in Ada 2005 mode. However,
2847 -- this is clearly a mistake, since the problem that is addressed
2848 -- by this AI is that there is a clear gap in the RM!
2850 if Is_Dispatching_Operation (E)
2851 and then Present (Overridden_Operation (E))
2852 and then C /= Convention (Overridden_Operation (E))
2855 ("cannot change convention for " &
2856 "overridden dispatching operation",
2860 -- Set the convention
2862 Set_Convention (E, C);
2863 Set_Has_Convention_Pragma (E);
2865 if Is_Incomplete_Or_Private_Type (E) then
2866 Set_Convention (Underlying_Type (E), C);
2867 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2870 -- A class-wide type should inherit the convention of the specific
2871 -- root type (although this isn't specified clearly by the RM).
2873 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2874 Set_Convention (Class_Wide_Type (E), C);
2877 -- If the entity is a record type, then check for special case of
2878 -- C_Pass_By_Copy, which is treated the same as C except that the
2879 -- special record flag is set. This convention is only permitted
2880 -- on record types (see AI95-00131).
2882 if Cname = Name_C_Pass_By_Copy then
2883 if Is_Record_Type (E) then
2884 Set_C_Pass_By_Copy (Base_Type (E));
2885 elsif Is_Incomplete_Or_Private_Type (E)
2886 and then Is_Record_Type (Underlying_Type (E))
2888 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2891 ("C_Pass_By_Copy convention allowed only for record type",
2896 -- If the entity is a derived boolean type, check for the special
2897 -- case of convention C, C++, or Fortran, where we consider any
2898 -- nonzero value to represent true.
2900 if Is_Discrete_Type (E)
2901 and then Root_Type (Etype (E)) = Standard_Boolean
2907 C = Convention_Fortran)
2909 Set_Nonzero_Is_True (Base_Type (E));
2911 end Set_Convention_From_Pragma;
2913 -- Start of processing for Process_Convention
2916 Check_At_Least_N_Arguments (2);
2917 Check_Optional_Identifier (Arg1, Name_Convention);
2918 Check_Arg_Is_Identifier (Arg1);
2919 Cname := Chars (Get_Pragma_Arg (Arg1));
2921 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2922 -- tested again below to set the critical flag).
2924 if Cname = Name_C_Pass_By_Copy then
2927 -- Otherwise we must have something in the standard convention list
2929 elsif Is_Convention_Name (Cname) then
2930 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
2932 -- In DEC VMS, it seems that there is an undocumented feature that
2933 -- any unrecognized convention is treated as the default, which for
2934 -- us is convention C. It does not seem so terrible to do this
2935 -- unconditionally, silently in the VMS case, and with a warning
2936 -- in the non-VMS case.
2939 if Warn_On_Export_Import and not OpenVMS_On_Target then
2941 ("?unrecognized convention name, C assumed",
2942 Get_Pragma_Arg (Arg1));
2948 Check_Optional_Identifier (Arg2, Name_Entity);
2949 Check_Arg_Is_Local_Name (Arg2);
2951 Id := Get_Pragma_Arg (Arg2);
2954 if not Is_Entity_Name (Id) then
2955 Error_Pragma_Arg ("entity name required", Arg2);
2960 -- Set entity to return
2964 -- Go to renamed subprogram if present, since convention applies to
2965 -- the actual renamed entity, not to the renaming entity. If the
2966 -- subprogram is inherited, go to parent subprogram.
2968 if Is_Subprogram (E)
2969 and then Present (Alias (E))
2971 if Nkind (Parent (Declaration_Node (E))) =
2972 N_Subprogram_Renaming_Declaration
2974 if Scope (E) /= Scope (Alias (E)) then
2976 ("cannot apply pragma% to non-local entity&#", E);
2981 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
2982 N_Private_Extension_Declaration)
2983 and then Scope (E) = Scope (Alias (E))
2987 -- Return the parent subprogram the entity was inherited from
2993 -- Check that we are not applying this to a specless body
2995 if Is_Subprogram (E)
2996 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2999 ("pragma% requires separate spec and must come before body");
3002 -- Check that we are not applying this to a named constant
3004 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3005 Error_Msg_Name_1 := Pname;
3007 ("cannot apply pragma% to named constant!",
3008 Get_Pragma_Arg (Arg2));
3010 ("\supply appropriate type for&!", Arg2);
3013 if Ekind (E) = E_Enumeration_Literal then
3014 Error_Pragma ("enumeration literal not allowed for pragma%");
3017 -- Check for rep item appearing too early or too late
3019 if Etype (E) = Any_Type
3020 or else Rep_Item_Too_Early (E, N)
3024 E := Underlying_Type (E);
3027 if Rep_Item_Too_Late (E, N) then
3031 if Has_Convention_Pragma (E) then
3032 Diagnose_Multiple_Pragmas (E);
3034 elsif Convention (E) = Convention_Protected
3035 or else Ekind (Scope (E)) = E_Protected_Type
3038 ("a protected operation cannot be given a different convention",
3042 -- For Intrinsic, a subprogram is required
3044 if C = Convention_Intrinsic
3045 and then not Is_Subprogram (E)
3046 and then not Is_Generic_Subprogram (E)
3049 ("second argument of pragma% must be a subprogram", Arg2);
3052 -- For Stdcall, a subprogram, variable or subprogram type is required
3054 if C = Convention_Stdcall
3055 and then not Is_Subprogram (E)
3056 and then not Is_Generic_Subprogram (E)
3057 and then Ekind (E) /= E_Variable
3060 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3063 ("second argument of pragma% must be subprogram (type)",
3067 if not Is_Subprogram (E)
3068 and then not Is_Generic_Subprogram (E)
3070 Set_Convention_From_Pragma (E);
3073 Check_First_Subtype (Arg2);
3074 Set_Convention_From_Pragma (Base_Type (E));
3076 -- For subprograms, we must set the convention on the
3077 -- internally generated directly designated type as well.
3079 if Ekind (E) = E_Access_Subprogram_Type then
3080 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3084 -- For the subprogram case, set proper convention for all homonyms
3085 -- in same scope and the same declarative part, i.e. the same
3086 -- compilation unit.
3089 Comp_Unit := Get_Source_Unit (E);
3090 Set_Convention_From_Pragma (E);
3092 -- Treat a pragma Import as an implicit body, for GPS use
3094 if Prag_Id = Pragma_Import then
3095 Generate_Reference (E, Id, 'b');
3098 -- Loop through the homonyms of the pragma argument's entity
3103 exit when No (E1) or else Scope (E1) /= Current_Scope;
3105 -- Do not set the pragma on inherited operations or on formal
3108 if Comes_From_Source (E1)
3109 and then Comp_Unit = Get_Source_Unit (E1)
3110 and then not Is_Formal_Subprogram (E1)
3111 and then Nkind (Original_Node (Parent (E1))) /=
3112 N_Full_Type_Declaration
3114 if Present (Alias (E1))
3115 and then Scope (E1) /= Scope (Alias (E1))
3118 ("cannot apply pragma% to non-local entity& declared#",
3122 Set_Convention_From_Pragma (E1);
3124 if Prag_Id = Pragma_Import then
3125 Generate_Reference (E1, Id, 'b');
3129 -- For aspect case, do NOT apply to homonyms
3131 exit when From_Aspect_Specification (N);
3134 end Process_Convention;
3136 -----------------------------------------------------
3137 -- Process_Extended_Import_Export_Exception_Pragma --
3138 -----------------------------------------------------
3140 procedure Process_Extended_Import_Export_Exception_Pragma
3141 (Arg_Internal : Node_Id;
3142 Arg_External : Node_Id;
3150 if not OpenVMS_On_Target then
3152 ("?pragma% ignored (applies only to Open'V'M'S)");
3155 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3156 Def_Id := Entity (Arg_Internal);
3158 if Ekind (Def_Id) /= E_Exception then
3160 ("pragma% must refer to declared exception", Arg_Internal);
3163 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3165 if Present (Arg_Form) then
3166 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3169 if Present (Arg_Form)
3170 and then Chars (Arg_Form) = Name_Ada
3174 Set_Is_VMS_Exception (Def_Id);
3175 Set_Exception_Code (Def_Id, No_Uint);
3178 if Present (Arg_Code) then
3179 if not Is_VMS_Exception (Def_Id) then
3181 ("Code option for pragma% not allowed for Ada case",
3185 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3186 Code_Val := Expr_Value (Arg_Code);
3188 if not UI_Is_In_Int_Range (Code_Val) then
3190 ("Code option for pragma% must be in 32-bit range",
3194 Set_Exception_Code (Def_Id, Code_Val);
3197 end Process_Extended_Import_Export_Exception_Pragma;
3199 -------------------------------------------------
3200 -- Process_Extended_Import_Export_Internal_Arg --
3201 -------------------------------------------------
3203 procedure Process_Extended_Import_Export_Internal_Arg
3204 (Arg_Internal : Node_Id := Empty)
3207 if No (Arg_Internal) then
3208 Error_Pragma ("Internal parameter required for pragma%");
3211 if Nkind (Arg_Internal) = N_Identifier then
3214 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3215 and then (Prag_Id = Pragma_Import_Function
3217 Prag_Id = Pragma_Export_Function)
3223 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3226 Check_Arg_Is_Local_Name (Arg_Internal);
3227 end Process_Extended_Import_Export_Internal_Arg;
3229 --------------------------------------------------
3230 -- Process_Extended_Import_Export_Object_Pragma --
3231 --------------------------------------------------
3233 procedure Process_Extended_Import_Export_Object_Pragma
3234 (Arg_Internal : Node_Id;
3235 Arg_External : Node_Id;
3241 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3242 Def_Id := Entity (Arg_Internal);
3244 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3246 ("pragma% must designate an object", Arg_Internal);
3249 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3251 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3254 ("previous Common/Psect_Object applies, pragma % not permitted",
3258 if Rep_Item_Too_Late (Def_Id, N) then
3262 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3264 if Present (Arg_Size) then
3265 Check_Arg_Is_External_Name (Arg_Size);
3268 -- Export_Object case
3270 if Prag_Id = Pragma_Export_Object then
3271 if not Is_Library_Level_Entity (Def_Id) then
3273 ("argument for pragma% must be library level entity",
3277 if Ekind (Current_Scope) = E_Generic_Package then
3278 Error_Pragma ("pragma& cannot appear in a generic unit");
3281 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3283 ("exported object must have compile time known size",
3287 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3288 Error_Msg_N ("?duplicate Export_Object pragma", N);
3290 Set_Exported (Def_Id, Arg_Internal);
3293 -- Import_Object case
3296 if Is_Concurrent_Type (Etype (Def_Id)) then
3298 ("cannot use pragma% for task/protected object",
3302 if Ekind (Def_Id) = E_Constant then
3304 ("cannot import a constant", Arg_Internal);
3307 if Warn_On_Export_Import
3308 and then Has_Discriminants (Etype (Def_Id))
3311 ("imported value must be initialized?", Arg_Internal);
3314 if Warn_On_Export_Import
3315 and then Is_Access_Type (Etype (Def_Id))
3318 ("cannot import object of an access type?", Arg_Internal);
3321 if Warn_On_Export_Import
3322 and then Is_Imported (Def_Id)
3325 ("?duplicate Import_Object pragma", N);
3327 -- Check for explicit initialization present. Note that an
3328 -- initialization generated by the code generator, e.g. for an
3329 -- access type, does not count here.
3331 elsif Present (Expression (Parent (Def_Id)))
3334 (Original_Node (Expression (Parent (Def_Id))))
3336 Error_Msg_Sloc := Sloc (Def_Id);
3338 ("imported entities cannot be initialized (RM B.1(24))",
3339 "\no initialization allowed for & declared#", Arg1);
3341 Set_Imported (Def_Id);
3342 Note_Possible_Modification (Arg_Internal, Sure => False);
3345 end Process_Extended_Import_Export_Object_Pragma;
3347 ------------------------------------------------------
3348 -- Process_Extended_Import_Export_Subprogram_Pragma --
3349 ------------------------------------------------------
3351 procedure Process_Extended_Import_Export_Subprogram_Pragma
3352 (Arg_Internal : Node_Id;
3353 Arg_External : Node_Id;
3354 Arg_Parameter_Types : Node_Id;
3355 Arg_Result_Type : Node_Id := Empty;
3356 Arg_Mechanism : Node_Id;
3357 Arg_Result_Mechanism : Node_Id := Empty;
3358 Arg_First_Optional_Parameter : Node_Id := Empty)
3364 Ambiguous : Boolean;
3368 function Same_Base_Type
3370 Formal : Entity_Id) return Boolean;
3371 -- Determines if Ptype references the type of Formal. Note that only
3372 -- the base types need to match according to the spec. Ptype here is
3373 -- the argument from the pragma, which is either a type name, or an
3374 -- access attribute.
3376 --------------------
3377 -- Same_Base_Type --
3378 --------------------
3380 function Same_Base_Type
3382 Formal : Entity_Id) return Boolean
3384 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3388 -- Case where pragma argument is typ'Access
3390 if Nkind (Ptype) = N_Attribute_Reference
3391 and then Attribute_Name (Ptype) = Name_Access
3393 Pref := Prefix (Ptype);
3396 if not Is_Entity_Name (Pref)
3397 or else Entity (Pref) = Any_Type
3402 -- We have a match if the corresponding argument is of an
3403 -- anonymous access type, and its designated type matches the
3404 -- type of the prefix of the access attribute
3406 return Ekind (Ftyp) = E_Anonymous_Access_Type
3407 and then Base_Type (Entity (Pref)) =
3408 Base_Type (Etype (Designated_Type (Ftyp)));
3410 -- Case where pragma argument is a type name
3415 if not Is_Entity_Name (Ptype)
3416 or else Entity (Ptype) = Any_Type
3421 -- We have a match if the corresponding argument is of the type
3422 -- given in the pragma (comparing base types)
3424 return Base_Type (Entity (Ptype)) = Ftyp;
3428 -- Start of processing for
3429 -- Process_Extended_Import_Export_Subprogram_Pragma
3432 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3436 -- Loop through homonyms (overloadings) of the entity
3438 Hom_Id := Entity (Arg_Internal);
3439 while Present (Hom_Id) loop
3440 Def_Id := Get_Base_Subprogram (Hom_Id);
3442 -- We need a subprogram in the current scope
3444 if not Is_Subprogram (Def_Id)
3445 or else Scope (Def_Id) /= Current_Scope
3452 -- Pragma cannot apply to subprogram body
3454 if Is_Subprogram (Def_Id)
3455 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3459 ("pragma% requires separate spec"
3460 & " and must come before body");
3463 -- Test result type if given, note that the result type
3464 -- parameter can only be present for the function cases.
3466 if Present (Arg_Result_Type)
3467 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3471 elsif Etype (Def_Id) /= Standard_Void_Type
3473 (Pname = Name_Export_Procedure
3475 Pname = Name_Import_Procedure)
3479 -- Test parameter types if given. Note that this parameter
3480 -- has not been analyzed (and must not be, since it is
3481 -- semantic nonsense), so we get it as the parser left it.
3483 elsif Present (Arg_Parameter_Types) then
3484 Check_Matching_Types : declare
3489 Formal := First_Formal (Def_Id);
3491 if Nkind (Arg_Parameter_Types) = N_Null then
3492 if Present (Formal) then
3496 -- A list of one type, e.g. (List) is parsed as
3497 -- a parenthesized expression.
3499 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3500 and then Paren_Count (Arg_Parameter_Types) = 1
3503 or else Present (Next_Formal (Formal))
3508 Same_Base_Type (Arg_Parameter_Types, Formal);
3511 -- A list of more than one type is parsed as a aggregate
3513 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3514 and then Paren_Count (Arg_Parameter_Types) = 0
3516 Ptype := First (Expressions (Arg_Parameter_Types));
3517 while Present (Ptype) or else Present (Formal) loop
3520 or else not Same_Base_Type (Ptype, Formal)
3525 Next_Formal (Formal);
3530 -- Anything else is of the wrong form
3534 ("wrong form for Parameter_Types parameter",
3535 Arg_Parameter_Types);
3537 end Check_Matching_Types;
3540 -- Match is now False if the entry we found did not match
3541 -- either a supplied Parameter_Types or Result_Types argument
3547 -- Ambiguous case, the flag Ambiguous shows if we already
3548 -- detected this and output the initial messages.
3551 if not Ambiguous then
3553 Error_Msg_Name_1 := Pname;
3555 ("pragma% does not uniquely identify subprogram!",
3557 Error_Msg_Sloc := Sloc (Ent);
3558 Error_Msg_N ("matching subprogram #!", N);
3562 Error_Msg_Sloc := Sloc (Def_Id);
3563 Error_Msg_N ("matching subprogram #!", N);
3568 Hom_Id := Homonym (Hom_Id);
3571 -- See if we found an entry
3574 if not Ambiguous then
3575 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3577 ("pragma% cannot be given for generic subprogram");
3580 ("pragma% does not identify local subprogram");
3587 -- Import pragmas must be for imported entities
3589 if Prag_Id = Pragma_Import_Function
3591 Prag_Id = Pragma_Import_Procedure
3593 Prag_Id = Pragma_Import_Valued_Procedure
3595 if not Is_Imported (Ent) then
3597 ("pragma Import or Interface must precede pragma%");
3600 -- Here we have the Export case which can set the entity as exported
3602 -- But does not do so if the specified external name is null, since
3603 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3604 -- compatible) to request no external name.
3606 elsif Nkind (Arg_External) = N_String_Literal
3607 and then String_Length (Strval (Arg_External)) = 0
3611 -- In all other cases, set entity as exported
3614 Set_Exported (Ent, Arg_Internal);
3617 -- Special processing for Valued_Procedure cases
3619 if Prag_Id = Pragma_Import_Valued_Procedure
3621 Prag_Id = Pragma_Export_Valued_Procedure
3623 Formal := First_Formal (Ent);
3626 Error_Pragma ("at least one parameter required for pragma%");
3628 elsif Ekind (Formal) /= E_Out_Parameter then
3629 Error_Pragma ("first parameter must have mode out for pragma%");
3632 Set_Is_Valued_Procedure (Ent);
3636 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3638 -- Process Result_Mechanism argument if present. We have already
3639 -- checked that this is only allowed for the function case.
3641 if Present (Arg_Result_Mechanism) then
3642 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3645 -- Process Mechanism parameter if present. Note that this parameter
3646 -- is not analyzed, and must not be analyzed since it is semantic
3647 -- nonsense, so we get it in exactly as the parser left it.
3649 if Present (Arg_Mechanism) then
3657 -- A single mechanism association without a formal parameter
3658 -- name is parsed as a parenthesized expression. All other
3659 -- cases are parsed as aggregates, so we rewrite the single
3660 -- parameter case as an aggregate for consistency.
3662 if Nkind (Arg_Mechanism) /= N_Aggregate
3663 and then Paren_Count (Arg_Mechanism) = 1
3665 Rewrite (Arg_Mechanism,
3666 Make_Aggregate (Sloc (Arg_Mechanism),
3667 Expressions => New_List (
3668 Relocate_Node (Arg_Mechanism))));
3671 -- Case of only mechanism name given, applies to all formals
3673 if Nkind (Arg_Mechanism) /= N_Aggregate then
3674 Formal := First_Formal (Ent);
3675 while Present (Formal) loop
3676 Set_Mechanism_Value (Formal, Arg_Mechanism);
3677 Next_Formal (Formal);
3680 -- Case of list of mechanism associations given
3683 if Null_Record_Present (Arg_Mechanism) then
3685 ("inappropriate form for Mechanism parameter",
3689 -- Deal with positional ones first
3691 Formal := First_Formal (Ent);
3693 if Present (Expressions (Arg_Mechanism)) then
3694 Mname := First (Expressions (Arg_Mechanism));
3695 while Present (Mname) loop
3698 ("too many mechanism associations", Mname);
3701 Set_Mechanism_Value (Formal, Mname);
3702 Next_Formal (Formal);
3707 -- Deal with named entries
3709 if Present (Component_Associations (Arg_Mechanism)) then
3710 Massoc := First (Component_Associations (Arg_Mechanism));
3711 while Present (Massoc) loop
3712 Choice := First (Choices (Massoc));
3714 if Nkind (Choice) /= N_Identifier
3715 or else Present (Next (Choice))
3718 ("incorrect form for mechanism association",
3722 Formal := First_Formal (Ent);
3726 ("parameter name & not present", Choice);
3729 if Chars (Choice) = Chars (Formal) then
3731 (Formal, Expression (Massoc));
3733 -- Set entity on identifier (needed by ASIS)
3735 Set_Entity (Choice, Formal);
3740 Next_Formal (Formal);
3750 -- Process First_Optional_Parameter argument if present. We have
3751 -- already checked that this is only allowed for the Import case.
3753 if Present (Arg_First_Optional_Parameter) then
3754 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3756 ("first optional parameter must be formal parameter name",
3757 Arg_First_Optional_Parameter);
3760 Formal := First_Formal (Ent);
3764 ("specified formal parameter& not found",
3765 Arg_First_Optional_Parameter);
3768 exit when Chars (Formal) =
3769 Chars (Arg_First_Optional_Parameter);
3771 Next_Formal (Formal);
3774 Set_First_Optional_Parameter (Ent, Formal);
3776 -- Check specified and all remaining formals have right form
3778 while Present (Formal) loop
3779 if Ekind (Formal) /= E_In_Parameter then
3781 ("optional formal& is not of mode in!",
3782 Arg_First_Optional_Parameter, Formal);
3785 Dval := Default_Value (Formal);
3789 ("optional formal& does not have default value!",
3790 Arg_First_Optional_Parameter, Formal);
3792 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3797 ("default value for optional formal& is non-static!",
3798 Arg_First_Optional_Parameter, Formal);
3802 Set_Is_Optional_Parameter (Formal);
3803 Next_Formal (Formal);
3806 end Process_Extended_Import_Export_Subprogram_Pragma;
3808 --------------------------
3809 -- Process_Generic_List --
3810 --------------------------
3812 procedure Process_Generic_List is
3817 Check_No_Identifiers;
3818 Check_At_Least_N_Arguments (1);
3821 while Present (Arg) loop
3822 Exp := Get_Pragma_Arg (Arg);
3825 if not Is_Entity_Name (Exp)
3827 (not Is_Generic_Instance (Entity (Exp))
3829 not Is_Generic_Unit (Entity (Exp)))
3832 ("pragma% argument must be name of generic unit/instance",
3838 end Process_Generic_List;
3840 ---------------------------------
3841 -- Process_Import_Or_Interface --
3842 ---------------------------------
3844 procedure Process_Import_Or_Interface is
3850 Process_Convention (C, Def_Id);
3851 Kill_Size_Check_Code (Def_Id);
3852 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
3854 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3856 -- We do not permit Import to apply to a renaming declaration
3858 if Present (Renamed_Object (Def_Id)) then
3860 ("pragma% not allowed for object renaming", Arg2);
3862 -- User initialization is not allowed for imported object, but
3863 -- the object declaration may contain a default initialization,
3864 -- that will be discarded. Note that an explicit initialization
3865 -- only counts if it comes from source, otherwise it is simply
3866 -- the code generator making an implicit initialization explicit.
3868 elsif Present (Expression (Parent (Def_Id)))
3869 and then Comes_From_Source (Expression (Parent (Def_Id)))
3871 Error_Msg_Sloc := Sloc (Def_Id);
3873 ("no initialization allowed for declaration of& #",
3874 "\imported entities cannot be initialized (RM B.1(24))",
3878 Set_Imported (Def_Id);
3879 Process_Interface_Name (Def_Id, Arg3, Arg4);
3881 -- Note that we do not set Is_Public here. That's because we
3882 -- only want to set it if there is no address clause, and we
3883 -- don't know that yet, so we delay that processing till
3886 -- pragma Import completes deferred constants
3888 if Ekind (Def_Id) = E_Constant then
3889 Set_Has_Completion (Def_Id);
3892 -- It is not possible to import a constant of an unconstrained
3893 -- array type (e.g. string) because there is no simple way to
3894 -- write a meaningful subtype for it.
3896 if Is_Array_Type (Etype (Def_Id))
3897 and then not Is_Constrained (Etype (Def_Id))
3900 ("imported constant& must have a constrained subtype",
3905 elsif Is_Subprogram (Def_Id)
3906 or else Is_Generic_Subprogram (Def_Id)
3908 -- If the name is overloaded, pragma applies to all of the denoted
3909 -- entities in the same declarative part.
3912 while Present (Hom_Id) loop
3913 Def_Id := Get_Base_Subprogram (Hom_Id);
3915 -- Ignore inherited subprograms because the pragma will apply
3916 -- to the parent operation, which is the one called.
3918 if Is_Overloadable (Def_Id)
3919 and then Present (Alias (Def_Id))
3923 -- If it is not a subprogram, it must be in an outer scope and
3924 -- pragma does not apply.
3926 elsif not Is_Subprogram (Def_Id)
3927 and then not Is_Generic_Subprogram (Def_Id)
3931 -- The pragma does not apply to primitives of interfaces
3933 elsif Is_Dispatching_Operation (Def_Id)
3934 and then Present (Find_Dispatching_Type (Def_Id))
3935 and then Is_Interface (Find_Dispatching_Type (Def_Id))
3939 -- Verify that the homonym is in the same declarative part (not
3940 -- just the same scope).
3942 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3943 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3948 Set_Imported (Def_Id);
3950 -- Reject an Import applied to an abstract subprogram
3952 if Is_Subprogram (Def_Id)
3953 and then Is_Abstract_Subprogram (Def_Id)
3955 Error_Msg_Sloc := Sloc (Def_Id);
3957 ("cannot import abstract subprogram& declared#",
3961 -- Special processing for Convention_Intrinsic
3963 if C = Convention_Intrinsic then
3965 -- Link_Name argument not allowed for intrinsic
3968 and then Chars (Arg3) = Name_Link_Name
3973 if Present (Arg4) then
3975 ("Link_Name argument not allowed for " &
3980 Set_Is_Intrinsic_Subprogram (Def_Id);
3982 -- If no external name is present, then check that this
3983 -- is a valid intrinsic subprogram. If an external name
3984 -- is present, then this is handled by the back end.
3987 Check_Intrinsic_Subprogram
3988 (Def_Id, Get_Pragma_Arg (Arg2));
3992 -- All interfaced procedures need an external symbol created
3993 -- for them since they are always referenced from another
3996 Set_Is_Public (Def_Id);
3998 -- Verify that the subprogram does not have a completion
3999 -- through a renaming declaration. For other completions the
4000 -- pragma appears as a too late representation.
4003 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4007 and then Nkind (Decl) = N_Subprogram_Declaration
4008 and then Present (Corresponding_Body (Decl))
4009 and then Nkind (Unit_Declaration_Node
4010 (Corresponding_Body (Decl))) =
4011 N_Subprogram_Renaming_Declaration
4013 Error_Msg_Sloc := Sloc (Def_Id);
4015 ("cannot import&, renaming already provided for " &
4016 "declaration #", N, Def_Id);
4020 Set_Has_Completion (Def_Id);
4021 Process_Interface_Name (Def_Id, Arg3, Arg4);
4024 if Is_Compilation_Unit (Hom_Id) then
4026 -- Its possible homonyms are not affected by the pragma.
4027 -- Such homonyms might be present in the context of other
4028 -- units being compiled.
4033 Hom_Id := Homonym (Hom_Id);
4037 -- When the convention is Java or CIL, we also allow Import to be
4038 -- given for packages, generic packages, exceptions, record
4039 -- components, and access to subprograms.
4041 elsif (C = Convention_Java or else C = Convention_CIL)
4043 (Is_Package_Or_Generic_Package (Def_Id)
4044 or else Ekind (Def_Id) = E_Exception
4045 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4046 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4048 Set_Imported (Def_Id);
4049 Set_Is_Public (Def_Id);
4050 Process_Interface_Name (Def_Id, Arg3, Arg4);
4052 -- Import a CPP class
4054 elsif Is_Record_Type (Def_Id)
4055 and then C = Convention_CPP
4057 -- Types treated as CPP classes are treated as limited, but we
4058 -- don't require them to be declared this way. A warning is issued
4059 -- to encourage the user to declare them as limited. This is not
4060 -- an error, for compatibility reasons, because these types have
4061 -- been supported this way for some time.
4063 if not Is_Limited_Type (Def_Id) then
4065 ("imported 'C'P'P type should be " &
4066 "explicitly declared limited?",
4067 Get_Pragma_Arg (Arg2));
4069 ("\type will be considered limited",
4070 Get_Pragma_Arg (Arg2));
4073 Set_Is_CPP_Class (Def_Id);
4074 Set_Is_Limited_Record (Def_Id);
4076 -- Imported CPP types must not have discriminants (because C++
4077 -- classes do not have discriminants).
4079 if Has_Discriminants (Def_Id) then
4081 ("imported 'C'P'P type cannot have discriminants",
4082 First (Discriminant_Specifications
4083 (Declaration_Node (Def_Id))));
4086 -- Components of imported CPP types must not have default
4087 -- expressions because the constructor (if any) is on the
4091 Tdef : constant Node_Id :=
4092 Type_Definition (Declaration_Node (Def_Id));
4097 if Nkind (Tdef) = N_Record_Definition then
4098 Clist := Component_List (Tdef);
4101 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4102 Clist := Component_List (Record_Extension_Part (Tdef));
4105 if Present (Clist) then
4106 Comp := First (Component_Items (Clist));
4107 while Present (Comp) loop
4108 if Present (Expression (Comp)) then
4110 ("component of imported 'C'P'P type cannot have" &
4111 " default expression", Expression (Comp));
4121 ("second argument of pragma% must be object or subprogram",
4125 -- If this pragma applies to a compilation unit, then the unit, which
4126 -- is a subprogram, does not require (or allow) a body. We also do
4127 -- not need to elaborate imported procedures.
4129 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4131 Cunit : constant Node_Id := Parent (Parent (N));
4133 Set_Body_Required (Cunit, False);
4136 end Process_Import_Or_Interface;
4138 --------------------
4139 -- Process_Inline --
4140 --------------------
4142 procedure Process_Inline (Active : Boolean) is
4148 Effective : Boolean := False;
4150 procedure Make_Inline (Subp : Entity_Id);
4151 -- Subp is the defining unit name of the subprogram declaration. Set
4152 -- the flag, as well as the flag in the corresponding body, if there
4155 procedure Set_Inline_Flags (Subp : Entity_Id);
4156 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4157 -- Has_Pragma_Inline_Always for the Inline_Always case.
4159 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4160 -- Returns True if it can be determined at this stage that inlining
4161 -- is not possible, for example if the body is available and contains
4162 -- exception handlers, we prevent inlining, since otherwise we can
4163 -- get undefined symbols at link time. This function also emits a
4164 -- warning if front-end inlining is enabled and the pragma appears
4167 -- ??? is business with link symbols still valid, or does it relate
4168 -- to front end ZCX which is being phased out ???
4170 ---------------------------
4171 -- Inlining_Not_Possible --
4172 ---------------------------
4174 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4175 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4179 if Nkind (Decl) = N_Subprogram_Body then
4180 Stats := Handled_Statement_Sequence (Decl);
4181 return Present (Exception_Handlers (Stats))
4182 or else Present (At_End_Proc (Stats));
4184 elsif Nkind (Decl) = N_Subprogram_Declaration
4185 and then Present (Corresponding_Body (Decl))
4187 if Front_End_Inlining
4188 and then Analyzed (Corresponding_Body (Decl))
4190 Error_Msg_N ("pragma appears too late, ignored?", N);
4193 -- If the subprogram is a renaming as body, the body is just a
4194 -- call to the renamed subprogram, and inlining is trivially
4198 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4199 N_Subprogram_Renaming_Declaration
4205 Handled_Statement_Sequence
4206 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4209 Present (Exception_Handlers (Stats))
4210 or else Present (At_End_Proc (Stats));
4214 -- If body is not available, assume the best, the check is
4215 -- performed again when compiling enclosing package bodies.
4219 end Inlining_Not_Possible;
4225 procedure Make_Inline (Subp : Entity_Id) is
4226 Kind : constant Entity_Kind := Ekind (Subp);
4227 Inner_Subp : Entity_Id := Subp;
4230 -- Ignore if bad type, avoid cascaded error
4232 if Etype (Subp) = Any_Type then
4236 -- Ignore if all inlining is suppressed
4238 elsif Suppress_All_Inlining then
4242 -- If inlining is not possible, for now do not treat as an error
4244 elsif Inlining_Not_Possible (Subp) then
4248 -- Here we have a candidate for inlining, but we must exclude
4249 -- derived operations. Otherwise we would end up trying to inline
4250 -- a phantom declaration, and the result would be to drag in a
4251 -- body which has no direct inlining associated with it. That
4252 -- would not only be inefficient but would also result in the
4253 -- backend doing cross-unit inlining in cases where it was
4254 -- definitely inappropriate to do so.
4256 -- However, a simple Comes_From_Source test is insufficient, since
4257 -- we do want to allow inlining of generic instances which also do
4258 -- not come from source. We also need to recognize specs generated
4259 -- by the front-end for bodies that carry the pragma. Finally,
4260 -- predefined operators do not come from source but are not
4261 -- inlineable either.
4263 elsif Is_Generic_Instance (Subp)
4264 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4268 elsif not Comes_From_Source (Subp)
4269 and then Scope (Subp) /= Standard_Standard
4275 -- The referenced entity must either be the enclosing entity, or
4276 -- an entity declared within the current open scope.
4278 if Present (Scope (Subp))
4279 and then Scope (Subp) /= Current_Scope
4280 and then Subp /= Current_Scope
4283 ("argument of% must be entity in current scope", Assoc);
4287 -- Processing for procedure, operator or function. If subprogram
4288 -- is aliased (as for an instance) indicate that the renamed
4289 -- entity (if declared in the same unit) is inlined.
4291 if Is_Subprogram (Subp) then
4297 Inner_Subp := Ultimate_Alias (Inner_Subp);
4299 if In_Same_Source_Unit (Subp, Inner_Subp) then
4300 Set_Inline_Flags (Inner_Subp);
4302 Decl := Parent (Parent (Inner_Subp));
4304 if Nkind (Decl) = N_Subprogram_Declaration
4305 and then Present (Corresponding_Body (Decl))
4307 Set_Inline_Flags (Corresponding_Body (Decl));
4309 elsif Is_Generic_Instance (Subp) then
4311 -- Indicate that the body needs to be created for
4312 -- inlining subsequent calls. The instantiation node
4313 -- follows the declaration of the wrapper package
4316 if Scope (Subp) /= Standard_Standard
4318 Need_Subprogram_Instance_Body
4319 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4329 -- For a generic subprogram set flag as well, for use at the point
4330 -- of instantiation, to determine whether the body should be
4333 elsif Is_Generic_Subprogram (Subp) then
4334 Set_Inline_Flags (Subp);
4337 -- Literals are by definition inlined
4339 elsif Kind = E_Enumeration_Literal then
4342 -- Anything else is an error
4346 ("expect subprogram name for pragma%", Assoc);
4350 ----------------------
4351 -- Set_Inline_Flags --
4352 ----------------------
4354 procedure Set_Inline_Flags (Subp : Entity_Id) is
4357 Set_Is_Inlined (Subp, Sense);
4360 if not Has_Pragma_Inline (Subp) then
4361 Set_Has_Pragma_Inline (Subp, Sense);
4365 if Prag_Id = Pragma_Inline_Always then
4366 Set_Has_Pragma_Inline_Always (Subp, Sense);
4368 end Set_Inline_Flags;
4370 -- Start of processing for Process_Inline
4373 Check_No_Identifiers;
4374 Check_At_Least_N_Arguments (1);
4377 Inline_Processing_Required := True;
4381 while Present (Assoc) loop
4382 Subp_Id := Get_Pragma_Arg (Assoc);
4386 if Is_Entity_Name (Subp_Id) then
4387 Subp := Entity (Subp_Id);
4389 if Subp = Any_Id then
4391 -- If previous error, avoid cascaded errors
4399 if not From_Aspect_Specification (N) then
4400 while Present (Homonym (Subp))
4401 and then Scope (Homonym (Subp)) = Current_Scope
4403 Make_Inline (Homonym (Subp));
4404 Subp := Homonym (Subp);
4412 ("inappropriate argument for pragma%", Assoc);
4415 and then Warn_On_Redundant_Constructs
4416 and then not Suppress_All_Inlining
4418 if Inlining_Not_Possible (Subp) then
4420 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4423 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4431 ----------------------------
4432 -- Process_Interface_Name --
4433 ----------------------------
4435 procedure Process_Interface_Name
4436 (Subprogram_Def : Entity_Id;
4442 String_Val : String_Id;
4444 procedure Check_Form_Of_Interface_Name
4446 Ext_Name_Case : Boolean);
4447 -- SN is a string literal node for an interface name. This routine
4448 -- performs some minimal checks that the name is reasonable. In
4449 -- particular that no spaces or other obviously incorrect characters
4450 -- appear. This is only a warning, since any characters are allowed.
4451 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4453 ----------------------------------
4454 -- Check_Form_Of_Interface_Name --
4455 ----------------------------------
4457 procedure Check_Form_Of_Interface_Name
4459 Ext_Name_Case : Boolean)
4461 S : constant String_Id := Strval (Expr_Value_S (SN));
4462 SL : constant Nat := String_Length (S);
4467 Error_Msg_N ("interface name cannot be null string", SN);
4470 for J in 1 .. SL loop
4471 C := Get_String_Char (S, J);
4473 -- Look for dubious character and issue unconditional warning.
4474 -- Definitely dubious if not in character range.
4476 if not In_Character_Range (C)
4478 -- For all cases except CLI target,
4479 -- commas, spaces and slashes are dubious (in CLI, we use
4480 -- commas and backslashes in external names to specify
4481 -- assembly version and public key, while slashes and spaces
4482 -- can be used in names to mark nested classes and
4485 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4486 and then (Get_Character (C) = ','
4488 Get_Character (C) = '\'))
4489 or else (VM_Target /= CLI_Target
4490 and then (Get_Character (C) = ' '
4492 Get_Character (C) = '/'))
4495 ("?interface name contains illegal character",
4496 Sloc (SN) + Source_Ptr (J));
4499 end Check_Form_Of_Interface_Name;
4501 -- Start of processing for Process_Interface_Name
4504 if No (Link_Arg) then
4505 if No (Ext_Arg) then
4506 if VM_Target = CLI_Target
4507 and then Ekind (Subprogram_Def) = E_Package
4508 and then Nkind (Parent (Subprogram_Def)) =
4509 N_Package_Specification
4510 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4515 (Generic_Parent (Parent (Subprogram_Def))));
4520 elsif Chars (Ext_Arg) = Name_Link_Name then
4522 Link_Nam := Expression (Ext_Arg);
4525 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4526 Ext_Nam := Expression (Ext_Arg);
4531 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4532 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4533 Ext_Nam := Expression (Ext_Arg);
4534 Link_Nam := Expression (Link_Arg);
4537 -- Check expressions for external name and link name are static
4539 if Present (Ext_Nam) then
4540 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4541 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4543 -- Verify that external name is not the name of a local entity,
4544 -- which would hide the imported one and could lead to run-time
4545 -- surprises. The problem can only arise for entities declared in
4546 -- a package body (otherwise the external name is fully qualified
4547 -- and will not conflict).
4555 if Prag_Id = Pragma_Import then
4556 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4558 E := Entity_Id (Get_Name_Table_Info (Nam));
4560 if Nam /= Chars (Subprogram_Def)
4561 and then Present (E)
4562 and then not Is_Overloadable (E)
4563 and then Is_Immediately_Visible (E)
4564 and then not Is_Imported (E)
4565 and then Ekind (Scope (E)) = E_Package
4568 while Present (Par) loop
4569 if Nkind (Par) = N_Package_Body then
4570 Error_Msg_Sloc := Sloc (E);
4572 ("imported entity is hidden by & declared#",
4577 Par := Parent (Par);
4584 if Present (Link_Nam) then
4585 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4586 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4589 -- If there is no link name, just set the external name
4591 if No (Link_Nam) then
4592 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4594 -- For the Link_Name case, the given literal is preceded by an
4595 -- asterisk, which indicates to GCC that the given name should be
4596 -- taken literally, and in particular that no prepending of
4597 -- underlines should occur, even in systems where this is the
4603 if VM_Target = No_VM then
4604 Store_String_Char (Get_Char_Code ('*'));
4607 String_Val := Strval (Expr_Value_S (Link_Nam));
4608 Store_String_Chars (String_Val);
4610 Make_String_Literal (Sloc (Link_Nam),
4611 Strval => End_String);
4614 Set_Encoded_Interface_Name
4615 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4617 -- We allow duplicated export names in CIL, as they are always
4618 -- enclosed in a namespace that differentiates them, and overloaded
4619 -- entities are supported by the VM.
4621 if Convention (Subprogram_Def) /= Convention_CIL then
4622 Check_Duplicated_Export_Name (Link_Nam);
4624 end Process_Interface_Name;
4626 -----------------------------------------
4627 -- Process_Interrupt_Or_Attach_Handler --
4628 -----------------------------------------
4630 procedure Process_Interrupt_Or_Attach_Handler is
4631 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4632 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4633 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4636 Set_Is_Interrupt_Handler (Handler_Proc);
4638 -- If the pragma is not associated with a handler procedure within a
4639 -- protected type, then it must be for a nonprotected procedure for
4640 -- the AAMP target, in which case we don't associate a representation
4641 -- item with the procedure's scope.
4643 if Ekind (Proc_Scope) = E_Protected_Type then
4644 if Prag_Id = Pragma_Interrupt_Handler
4646 Prag_Id = Pragma_Attach_Handler
4648 Record_Rep_Item (Proc_Scope, N);
4651 end Process_Interrupt_Or_Attach_Handler;
4653 --------------------------------------------------
4654 -- Process_Restrictions_Or_Restriction_Warnings --
4655 --------------------------------------------------
4657 -- Note: some of the simple identifier cases were handled in par-prag,
4658 -- but it is harmless (and more straightforward) to simply handle all
4659 -- cases here, even if it means we repeat a bit of work in some cases.
4661 procedure Process_Restrictions_Or_Restriction_Warnings
4665 R_Id : Restriction_Id;
4670 procedure Check_Unit_Name (N : Node_Id);
4671 -- Checks unit name parameter for No_Dependence. Returns if it has
4672 -- an appropriate form, otherwise raises pragma argument error.
4674 ---------------------
4675 -- Check_Unit_Name --
4676 ---------------------
4678 procedure Check_Unit_Name (N : Node_Id) is
4680 if Nkind (N) = N_Selected_Component then
4681 Check_Unit_Name (Prefix (N));
4682 Check_Unit_Name (Selector_Name (N));
4684 elsif Nkind (N) = N_Identifier then
4689 ("wrong form for unit name for No_Dependence", N);
4691 end Check_Unit_Name;
4693 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4696 -- Ignore all Restrictions pragma in CodePeer mode
4698 if CodePeer_Mode then
4702 Check_Ada_83_Warning;
4703 Check_At_Least_N_Arguments (1);
4704 Check_Valid_Configuration_Pragma;
4707 while Present (Arg) loop
4709 Expr := Get_Pragma_Arg (Arg);
4711 -- Case of no restriction identifier present
4713 if Id = No_Name then
4714 if Nkind (Expr) /= N_Identifier then
4716 ("invalid form for restriction", Arg);
4721 (Process_Restriction_Synonyms (Expr));
4723 if R_Id not in All_Boolean_Restrictions then
4724 Error_Msg_Name_1 := Pname;
4726 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4728 -- Check for possible misspelling
4730 for J in Restriction_Id loop
4732 Rnm : constant String := Restriction_Id'Image (J);
4735 Name_Buffer (1 .. Rnm'Length) := Rnm;
4736 Name_Len := Rnm'Length;
4737 Set_Casing (All_Lower_Case);
4739 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4741 (Identifier_Casing (Current_Source_File));
4742 Error_Msg_String (1 .. Rnm'Length) :=
4743 Name_Buffer (1 .. Name_Len);
4744 Error_Msg_Strlen := Rnm'Length;
4745 Error_Msg_N -- CODEFIX
4746 ("\possible misspelling of ""~""",
4747 Get_Pragma_Arg (Arg));
4756 if Implementation_Restriction (R_Id) then
4757 Check_Restriction (No_Implementation_Restrictions, Arg);
4760 -- If this is a warning, then set the warning unless we already
4761 -- have a real restriction active (we never want a warning to
4762 -- override a real restriction).
4765 if not Restriction_Active (R_Id) then
4766 Set_Restriction (R_Id, N);
4767 Restriction_Warnings (R_Id) := True;
4770 -- If real restriction case, then set it and make sure that the
4771 -- restriction warning flag is off, since a real restriction
4772 -- always overrides a warning.
4775 Set_Restriction (R_Id, N);
4776 Restriction_Warnings (R_Id) := False;
4779 -- Check for obsolescent restrictions in Ada 2005 mode
4782 and then Ada_Version >= Ada_2005
4783 and then (R_Id = No_Asynchronous_Control
4785 R_Id = No_Unchecked_Deallocation
4787 R_Id = No_Unchecked_Conversion)
4789 Check_Restriction (No_Obsolescent_Features, N);
4792 -- A very special case that must be processed here: pragma
4793 -- Restrictions (No_Exceptions) turns off all run-time
4794 -- checking. This is a bit dubious in terms of the formal
4795 -- language definition, but it is what is intended by RM
4796 -- H.4(12). Restriction_Warnings never affects generated code
4797 -- so this is done only in the real restriction case.
4799 if R_Id = No_Exceptions and then not Warn then
4800 Scope_Suppress := (others => True);
4803 -- Case of No_Dependence => unit-name. Note that the parser
4804 -- already made the necessary entry in the No_Dependence table.
4806 elsif Id = Name_No_Dependence then
4807 Check_Unit_Name (Expr);
4809 -- All other cases of restriction identifier present
4812 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4813 Analyze_And_Resolve (Expr, Any_Integer);
4815 if R_Id not in All_Parameter_Restrictions then
4817 ("invalid restriction parameter identifier", Arg);
4819 elsif not Is_OK_Static_Expression (Expr) then
4820 Flag_Non_Static_Expr
4821 ("value must be static expression!", Expr);
4824 elsif not Is_Integer_Type (Etype (Expr))
4825 or else Expr_Value (Expr) < 0
4828 ("value must be non-negative integer", Arg);
4831 -- Restriction pragma is active
4833 Val := Expr_Value (Expr);
4835 if not UI_Is_In_Int_Range (Val) then
4837 ("pragma ignored, value too large?", Arg);
4840 -- Warning case. If the real restriction is active, then we
4841 -- ignore the request, since warning never overrides a real
4842 -- restriction. Otherwise we set the proper warning. Note that
4843 -- this circuit sets the warning again if it is already set,
4844 -- which is what we want, since the constant may have changed.
4847 if not Restriction_Active (R_Id) then
4849 (R_Id, N, Integer (UI_To_Int (Val)));
4850 Restriction_Warnings (R_Id) := True;
4853 -- Real restriction case, set restriction and make sure warning
4854 -- flag is off since real restriction always overrides warning.
4857 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4858 Restriction_Warnings (R_Id) := False;
4864 end Process_Restrictions_Or_Restriction_Warnings;
4866 ---------------------------------
4867 -- Process_Suppress_Unsuppress --
4868 ---------------------------------
4870 -- Note: this procedure makes entries in the check suppress data
4871 -- structures managed by Sem. See spec of package Sem for full
4872 -- details on how we handle recording of check suppression.
4874 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4879 In_Package_Spec : constant Boolean :=
4880 Is_Package_Or_Generic_Package (Current_Scope)
4881 and then not In_Package_Body (Current_Scope);
4883 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4884 -- Used to suppress a single check on the given entity
4886 --------------------------------
4887 -- Suppress_Unsuppress_Echeck --
4888 --------------------------------
4890 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4892 Set_Checks_May_Be_Suppressed (E);
4894 if In_Package_Spec then
4895 Push_Global_Suppress_Stack_Entry
4898 Suppress => Suppress_Case);
4901 Push_Local_Suppress_Stack_Entry
4904 Suppress => Suppress_Case);
4907 -- If this is a first subtype, and the base type is distinct,
4908 -- then also set the suppress flags on the base type.
4910 if Is_First_Subtype (E)
4911 and then Etype (E) /= E
4913 Suppress_Unsuppress_Echeck (Etype (E), C);
4915 end Suppress_Unsuppress_Echeck;
4917 -- Start of processing for Process_Suppress_Unsuppress
4920 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
4921 -- we want to generate checks for analysis purposes, as set by -gnatC
4923 if CodePeer_Mode and then Comes_From_Source (N) then
4927 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4928 -- declarative part or a package spec (RM 11.5(5)).
4930 if not Is_Configuration_Pragma then
4931 Check_Is_In_Decl_Part_Or_Package_Spec;
4934 Check_At_Least_N_Arguments (1);
4935 Check_At_Most_N_Arguments (2);
4936 Check_No_Identifier (Arg1);
4937 Check_Arg_Is_Identifier (Arg1);
4939 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
4941 if C = No_Check_Id then
4943 ("argument of pragma% is not valid check name", Arg1);
4946 if not Suppress_Case
4947 and then (C = All_Checks or else C = Overflow_Check)
4949 Opt.Overflow_Checks_Unsuppressed := True;
4952 if Arg_Count = 1 then
4954 -- Make an entry in the local scope suppress table. This is the
4955 -- table that directly shows the current value of the scope
4956 -- suppress check for any check id value.
4958 if C = All_Checks then
4960 -- For All_Checks, we set all specific predefined checks with
4961 -- the exception of Elaboration_Check, which is handled
4962 -- specially because of not wanting All_Checks to have the
4963 -- effect of deactivating static elaboration order processing.
4965 for J in Scope_Suppress'Range loop
4966 if J /= Elaboration_Check then
4967 Scope_Suppress (J) := Suppress_Case;
4971 -- If not All_Checks, and predefined check, then set appropriate
4972 -- scope entry. Note that we will set Elaboration_Check if this
4973 -- is explicitly specified.
4975 elsif C in Predefined_Check_Id then
4976 Scope_Suppress (C) := Suppress_Case;
4979 -- Also make an entry in the Local_Entity_Suppress table
4981 Push_Local_Suppress_Stack_Entry
4984 Suppress => Suppress_Case);
4986 -- Case of two arguments present, where the check is suppressed for
4987 -- a specified entity (given as the second argument of the pragma)
4990 -- This is obsolescent in Ada 2005 mode
4992 if Ada_Version >= Ada_2005 then
4993 Check_Restriction (No_Obsolescent_Features, Arg2);
4996 Check_Optional_Identifier (Arg2, Name_On);
4997 E_Id := Get_Pragma_Arg (Arg2);
5000 if not Is_Entity_Name (E_Id) then
5002 ("second argument of pragma% must be entity name", Arg2);
5011 -- Enforce RM 11.5(7) which requires that for a pragma that
5012 -- appears within a package spec, the named entity must be
5013 -- within the package spec. We allow the package name itself
5014 -- to be mentioned since that makes sense, although it is not
5015 -- strictly allowed by 11.5(7).
5018 and then E /= Current_Scope
5019 and then Scope (E) /= Current_Scope
5022 ("entity in pragma% is not in package spec (RM 11.5(7))",
5026 -- Loop through homonyms. As noted below, in the case of a package
5027 -- spec, only homonyms within the package spec are considered.
5030 Suppress_Unsuppress_Echeck (E, C);
5032 if Is_Generic_Instance (E)
5033 and then Is_Subprogram (E)
5034 and then Present (Alias (E))
5036 Suppress_Unsuppress_Echeck (Alias (E), C);
5039 -- Move to next homonym if not aspect spec case
5041 exit when From_Aspect_Specification (N);
5045 -- If we are within a package specification, the pragma only
5046 -- applies to homonyms in the same scope.
5048 exit when In_Package_Spec
5049 and then Scope (E) /= Current_Scope;
5052 end Process_Suppress_Unsuppress;
5058 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5060 if Is_Imported (E) then
5062 ("cannot export entity& that was previously imported", Arg);
5064 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5066 ("cannot export entity& that has an address clause", Arg);
5069 Set_Is_Exported (E);
5071 -- Generate a reference for entity explicitly, because the
5072 -- identifier may be overloaded and name resolution will not
5075 Generate_Reference (E, Arg);
5077 -- Deal with exporting non-library level entity
5079 if not Is_Library_Level_Entity (E) then
5081 -- Not allowed at all for subprograms
5083 if Is_Subprogram (E) then
5084 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5086 -- Otherwise set public and statically allocated
5090 Set_Is_Statically_Allocated (E);
5092 -- Warn if the corresponding W flag is set and the pragma comes
5093 -- from source. The latter may not be true e.g. on VMS where we
5094 -- expand export pragmas for exception codes associated with
5095 -- imported or exported exceptions. We do not want to generate
5096 -- a warning for something that the user did not write.
5098 if Warn_On_Export_Import
5099 and then Comes_From_Source (Arg)
5102 ("?& has been made static as a result of Export", Arg, E);
5104 ("\this usage is non-standard and non-portable", Arg);
5109 if Warn_On_Export_Import and then Is_Type (E) then
5110 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5113 if Warn_On_Export_Import and Inside_A_Generic then
5115 ("all instances of& will have the same external name?", Arg, E);
5119 ----------------------------------------------
5120 -- Set_Extended_Import_Export_External_Name --
5121 ----------------------------------------------
5123 procedure Set_Extended_Import_Export_External_Name
5124 (Internal_Ent : Entity_Id;
5125 Arg_External : Node_Id)
5127 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5131 if No (Arg_External) then
5135 Check_Arg_Is_External_Name (Arg_External);
5137 if Nkind (Arg_External) = N_String_Literal then
5138 if String_Length (Strval (Arg_External)) = 0 then
5141 New_Name := Adjust_External_Name_Case (Arg_External);
5144 elsif Nkind (Arg_External) = N_Identifier then
5145 New_Name := Get_Default_External_Name (Arg_External);
5147 -- Check_Arg_Is_External_Name should let through only identifiers and
5148 -- string literals or static string expressions (which are folded to
5149 -- string literals).
5152 raise Program_Error;
5155 -- If we already have an external name set (by a prior normal Import
5156 -- or Export pragma), then the external names must match
5158 if Present (Interface_Name (Internal_Ent)) then
5159 Check_Matching_Internal_Names : declare
5160 S1 : constant String_Id := Strval (Old_Name);
5161 S2 : constant String_Id := Strval (New_Name);
5164 -- Called if names do not match
5170 procedure Mismatch is
5172 Error_Msg_Sloc := Sloc (Old_Name);
5174 ("external name does not match that given #",
5178 -- Start of processing for Check_Matching_Internal_Names
5181 if String_Length (S1) /= String_Length (S2) then
5185 for J in 1 .. String_Length (S1) loop
5186 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5191 end Check_Matching_Internal_Names;
5193 -- Otherwise set the given name
5196 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5197 Check_Duplicated_Export_Name (New_Name);
5199 end Set_Extended_Import_Export_External_Name;
5205 procedure Set_Imported (E : Entity_Id) is
5207 -- Error message if already imported or exported
5209 if Is_Exported (E) or else Is_Imported (E) then
5211 -- Error if being set Exported twice
5213 if Is_Exported (E) then
5214 Error_Msg_NE ("entity& was previously exported", N, E);
5216 -- OK if Import/Interface case
5218 elsif Import_Interface_Present (N) then
5221 -- Error if being set Imported twice
5224 Error_Msg_NE ("entity& was previously imported", N, E);
5227 Error_Msg_Name_1 := Pname;
5229 ("\(pragma% applies to all previous entities)", N);
5231 Error_Msg_Sloc := Sloc (E);
5232 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5234 -- Here if not previously imported or exported, OK to import
5237 Set_Is_Imported (E);
5239 -- If the entity is an object that is not at the library level,
5240 -- then it is statically allocated. We do not worry about objects
5241 -- with address clauses in this context since they are not really
5242 -- imported in the linker sense.
5245 and then not Is_Library_Level_Entity (E)
5246 and then No (Address_Clause (E))
5248 Set_Is_Statically_Allocated (E);
5255 -------------------------
5256 -- Set_Mechanism_Value --
5257 -------------------------
5259 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5260 -- analyzed, since it is semantic nonsense), so we get it in the exact
5261 -- form created by the parser.
5263 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5266 Mech_Name_Id : Name_Id;
5268 procedure Bad_Class;
5269 -- Signal bad descriptor class name
5271 procedure Bad_Mechanism;
5272 -- Signal bad mechanism name
5278 procedure Bad_Class is
5280 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5283 -------------------------
5284 -- Bad_Mechanism_Value --
5285 -------------------------
5287 procedure Bad_Mechanism is
5289 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5292 -- Start of processing for Set_Mechanism_Value
5295 if Mechanism (Ent) /= Default_Mechanism then
5297 ("mechanism for & has already been set", Mech_Name, Ent);
5300 -- MECHANISM_NAME ::= value | reference | descriptor |
5303 if Nkind (Mech_Name) = N_Identifier then
5304 if Chars (Mech_Name) = Name_Value then
5305 Set_Mechanism (Ent, By_Copy);
5308 elsif Chars (Mech_Name) = Name_Reference then
5309 Set_Mechanism (Ent, By_Reference);
5312 elsif Chars (Mech_Name) = Name_Descriptor then
5313 Check_VMS (Mech_Name);
5315 -- Descriptor => Short_Descriptor if pragma was given
5317 if Short_Descriptors then
5318 Set_Mechanism (Ent, By_Short_Descriptor);
5320 Set_Mechanism (Ent, By_Descriptor);
5325 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5326 Check_VMS (Mech_Name);
5327 Set_Mechanism (Ent, By_Short_Descriptor);
5330 elsif Chars (Mech_Name) = Name_Copy then
5332 ("bad mechanism name, Value assumed", Mech_Name);
5338 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5339 -- short_descriptor (CLASS_NAME)
5340 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5342 -- Note: this form is parsed as an indexed component
5344 elsif Nkind (Mech_Name) = N_Indexed_Component then
5345 Class := First (Expressions (Mech_Name));
5347 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5348 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5349 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5350 or else Present (Next (Class))
5354 Mech_Name_Id := Chars (Prefix (Mech_Name));
5356 -- Change Descriptor => Short_Descriptor if pragma was given
5358 if Mech_Name_Id = Name_Descriptor
5359 and then Short_Descriptors
5361 Mech_Name_Id := Name_Short_Descriptor;
5365 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5366 -- short_descriptor (Class => CLASS_NAME)
5367 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5369 -- Note: this form is parsed as a function call
5371 elsif Nkind (Mech_Name) = N_Function_Call then
5372 Param := First (Parameter_Associations (Mech_Name));
5374 if Nkind (Name (Mech_Name)) /= N_Identifier
5375 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5376 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5377 or else Present (Next (Param))
5378 or else No (Selector_Name (Param))
5379 or else Chars (Selector_Name (Param)) /= Name_Class
5383 Class := Explicit_Actual_Parameter (Param);
5384 Mech_Name_Id := Chars (Name (Mech_Name));
5391 -- Fall through here with Class set to descriptor class name
5393 Check_VMS (Mech_Name);
5395 if Nkind (Class) /= N_Identifier then
5398 elsif Mech_Name_Id = Name_Descriptor
5399 and then Chars (Class) = Name_UBS
5401 Set_Mechanism (Ent, By_Descriptor_UBS);
5403 elsif Mech_Name_Id = Name_Descriptor
5404 and then Chars (Class) = Name_UBSB
5406 Set_Mechanism (Ent, By_Descriptor_UBSB);
5408 elsif Mech_Name_Id = Name_Descriptor
5409 and then Chars (Class) = Name_UBA
5411 Set_Mechanism (Ent, By_Descriptor_UBA);
5413 elsif Mech_Name_Id = Name_Descriptor
5414 and then Chars (Class) = Name_S
5416 Set_Mechanism (Ent, By_Descriptor_S);
5418 elsif Mech_Name_Id = Name_Descriptor
5419 and then Chars (Class) = Name_SB
5421 Set_Mechanism (Ent, By_Descriptor_SB);
5423 elsif Mech_Name_Id = Name_Descriptor
5424 and then Chars (Class) = Name_A
5426 Set_Mechanism (Ent, By_Descriptor_A);
5428 elsif Mech_Name_Id = Name_Descriptor
5429 and then Chars (Class) = Name_NCA
5431 Set_Mechanism (Ent, By_Descriptor_NCA);
5433 elsif Mech_Name_Id = Name_Short_Descriptor
5434 and then Chars (Class) = Name_UBS
5436 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5438 elsif Mech_Name_Id = Name_Short_Descriptor
5439 and then Chars (Class) = Name_UBSB
5441 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5443 elsif Mech_Name_Id = Name_Short_Descriptor
5444 and then Chars (Class) = Name_UBA
5446 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5448 elsif Mech_Name_Id = Name_Short_Descriptor
5449 and then Chars (Class) = Name_S
5451 Set_Mechanism (Ent, By_Short_Descriptor_S);
5453 elsif Mech_Name_Id = Name_Short_Descriptor
5454 and then Chars (Class) = Name_SB
5456 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5458 elsif Mech_Name_Id = Name_Short_Descriptor
5459 and then Chars (Class) = Name_A
5461 Set_Mechanism (Ent, By_Short_Descriptor_A);
5463 elsif Mech_Name_Id = Name_Short_Descriptor
5464 and then Chars (Class) = Name_NCA
5466 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5471 end Set_Mechanism_Value;
5473 ---------------------------
5474 -- Set_Ravenscar_Profile --
5475 ---------------------------
5477 -- The tasks to be done here are
5479 -- Set required policies
5481 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5482 -- pragma Locking_Policy (Ceiling_Locking)
5484 -- Set Detect_Blocking mode
5486 -- Set required restrictions (see System.Rident for detailed list)
5488 -- Set the No_Dependence rules
5489 -- No_Dependence => Ada.Asynchronous_Task_Control
5490 -- No_Dependence => Ada.Calendar
5491 -- No_Dependence => Ada.Execution_Time.Group_Budget
5492 -- No_Dependence => Ada.Execution_Time.Timers
5493 -- No_Dependence => Ada.Task_Attributes
5494 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5496 procedure Set_Ravenscar_Profile (N : Node_Id) is
5497 Prefix_Entity : Entity_Id;
5498 Selector_Entity : Entity_Id;
5499 Prefix_Node : Node_Id;
5503 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5505 if Task_Dispatching_Policy /= ' '
5506 and then Task_Dispatching_Policy /= 'F'
5508 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5509 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5511 -- Set the FIFO_Within_Priorities policy, but always preserve
5512 -- System_Location since we like the error message with the run time
5516 Task_Dispatching_Policy := 'F';
5518 if Task_Dispatching_Policy_Sloc /= System_Location then
5519 Task_Dispatching_Policy_Sloc := Loc;
5523 -- pragma Locking_Policy (Ceiling_Locking)
5525 if Locking_Policy /= ' '
5526 and then Locking_Policy /= 'C'
5528 Error_Msg_Sloc := Locking_Policy_Sloc;
5529 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5531 -- Set the Ceiling_Locking policy, but preserve System_Location since
5532 -- we like the error message with the run time name.
5535 Locking_Policy := 'C';
5537 if Locking_Policy_Sloc /= System_Location then
5538 Locking_Policy_Sloc := Loc;
5542 -- pragma Detect_Blocking
5544 Detect_Blocking := True;
5546 -- Set the corresponding restrictions
5548 Set_Profile_Restrictions
5549 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5551 -- Set the No_Dependence restrictions
5553 -- The following No_Dependence restrictions:
5554 -- No_Dependence => Ada.Asynchronous_Task_Control
5555 -- No_Dependence => Ada.Calendar
5556 -- No_Dependence => Ada.Task_Attributes
5557 -- are already set by previous call to Set_Profile_Restrictions.
5559 -- Set the following restrictions which were added to Ada 2005:
5560 -- No_Dependence => Ada.Execution_Time.Group_Budget
5561 -- No_Dependence => Ada.Execution_Time.Timers
5563 if Ada_Version >= Ada_2005 then
5564 Name_Buffer (1 .. 3) := "ada";
5567 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5569 Name_Buffer (1 .. 14) := "execution_time";
5572 Selector_Entity := Make_Identifier (Loc, Name_Find);
5575 Make_Selected_Component
5577 Prefix => Prefix_Entity,
5578 Selector_Name => Selector_Entity);
5580 Name_Buffer (1 .. 13) := "group_budgets";
5583 Selector_Entity := Make_Identifier (Loc, Name_Find);
5586 Make_Selected_Component
5588 Prefix => Prefix_Node,
5589 Selector_Name => Selector_Entity);
5591 Set_Restriction_No_Dependence
5593 Warn => Treat_Restrictions_As_Warnings,
5594 Profile => Ravenscar);
5596 Name_Buffer (1 .. 6) := "timers";
5599 Selector_Entity := Make_Identifier (Loc, Name_Find);
5602 Make_Selected_Component
5604 Prefix => Prefix_Node,
5605 Selector_Name => Selector_Entity);
5607 Set_Restriction_No_Dependence
5609 Warn => Treat_Restrictions_As_Warnings,
5610 Profile => Ravenscar);
5613 -- Set the following restrictions which was added to Ada 2012 (see
5615 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5617 if Ada_Version >= Ada_2012 then
5618 Name_Buffer (1 .. 6) := "system";
5621 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5623 Name_Buffer (1 .. 15) := "multiprocessors";
5626 Selector_Entity := Make_Identifier (Loc, Name_Find);
5629 Make_Selected_Component
5631 Prefix => Prefix_Entity,
5632 Selector_Name => Selector_Entity);
5634 Name_Buffer (1 .. 19) := "dispatching_domains";
5637 Selector_Entity := Make_Identifier (Loc, Name_Find);
5640 Make_Selected_Component
5642 Prefix => Prefix_Node,
5643 Selector_Name => Selector_Entity);
5645 Set_Restriction_No_Dependence
5647 Warn => Treat_Restrictions_As_Warnings,
5648 Profile => Ravenscar);
5650 end Set_Ravenscar_Profile;
5652 -- Start of processing for Analyze_Pragma
5655 -- Deal with unrecognized pragma
5657 if not Is_Pragma_Name (Pname) then
5658 if Warn_On_Unrecognized_Pragma then
5659 Error_Msg_Name_1 := Pname;
5660 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5662 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5663 if Is_Bad_Spelling_Of (Pname, PN) then
5664 Error_Msg_Name_1 := PN;
5665 Error_Msg_N -- CODEFIX
5666 ("\?possible misspelling of %!", Pragma_Identifier (N));
5675 -- Here to start processing for recognized pragma
5677 Prag_Id := Get_Pragma_Id (Pname);
5686 if Present (Pragma_Argument_Associations (N)) then
5687 Arg1 := First (Pragma_Argument_Associations (N));
5689 if Present (Arg1) then
5690 Arg2 := Next (Arg1);
5692 if Present (Arg2) then
5693 Arg3 := Next (Arg2);
5695 if Present (Arg3) then
5696 Arg4 := Next (Arg3);
5702 -- Count number of arguments
5709 while Present (Arg_Node) loop
5710 Arg_Count := Arg_Count + 1;
5715 -- An enumeration type defines the pragmas that are supported by the
5716 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5717 -- into the corresponding enumeration value for the following case.
5725 -- pragma Abort_Defer;
5727 when Pragma_Abort_Defer =>
5729 Check_Arg_Count (0);
5731 -- The only required semantic processing is to check the
5732 -- placement. This pragma must appear at the start of the
5733 -- statement sequence of a handled sequence of statements.
5735 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5736 or else N /= First (Statements (Parent (N)))
5747 -- Note: this pragma also has some specific processing in Par.Prag
5748 -- because we want to set the Ada version mode during parsing.
5750 when Pragma_Ada_83 =>
5752 Check_Arg_Count (0);
5754 -- We really should check unconditionally for proper configuration
5755 -- pragma placement, since we really don't want mixed Ada modes
5756 -- within a single unit, and the GNAT reference manual has always
5757 -- said this was a configuration pragma, but we did not check and
5758 -- are hesitant to add the check now.
5760 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5761 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5762 -- or Ada 2012 mode.
5764 if Ada_Version >= Ada_2005 then
5765 Check_Valid_Configuration_Pragma;
5768 -- Now set Ada 83 mode
5770 Ada_Version := Ada_83;
5771 Ada_Version_Explicit := Ada_Version;
5779 -- Note: this pragma also has some specific processing in Par.Prag
5780 -- because we want to set the Ada 83 version mode during parsing.
5782 when Pragma_Ada_95 =>
5784 Check_Arg_Count (0);
5786 -- We really should check unconditionally for proper configuration
5787 -- pragma placement, since we really don't want mixed Ada modes
5788 -- within a single unit, and the GNAT reference manual has always
5789 -- said this was a configuration pragma, but we did not check and
5790 -- are hesitant to add the check now.
5792 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5793 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5795 if Ada_Version >= Ada_2005 then
5796 Check_Valid_Configuration_Pragma;
5799 -- Now set Ada 95 mode
5801 Ada_Version := Ada_95;
5802 Ada_Version_Explicit := Ada_Version;
5804 ---------------------
5805 -- Ada_05/Ada_2005 --
5806 ---------------------
5809 -- pragma Ada_05 (LOCAL_NAME);
5812 -- pragma Ada_2005 (LOCAL_NAME):
5814 -- Note: these pragmas also have some specific processing in Par.Prag
5815 -- because we want to set the Ada 2005 version mode during parsing.
5817 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5823 if Arg_Count = 1 then
5824 Check_Arg_Is_Local_Name (Arg1);
5825 E_Id := Get_Pragma_Arg (Arg1);
5827 if Etype (E_Id) = Any_Type then
5831 Set_Is_Ada_2005_Only (Entity (E_Id));
5834 Check_Arg_Count (0);
5836 -- For Ada_2005 we unconditionally enforce the documented
5837 -- configuration pragma placement, since we do not want to
5838 -- tolerate mixed modes in a unit involving Ada 2005. That
5839 -- would cause real difficulties for those cases where there
5840 -- are incompatibilities between Ada 95 and Ada 2005.
5842 Check_Valid_Configuration_Pragma;
5844 -- Now set appropriate Ada mode
5847 Ada_Version := Ada_2005;
5849 Ada_Version := Ada_Version_Default;
5852 Ada_Version_Explicit := Ada_2005;
5856 ---------------------
5857 -- Ada_12/Ada_2012 --
5858 ---------------------
5861 -- pragma Ada_12 (LOCAL_NAME);
5864 -- pragma Ada_2012 (LOCAL_NAME):
5866 -- Note: these pragmas also have some specific processing in Par.Prag
5867 -- because we want to set the Ada 2012 version mode during parsing.
5869 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5875 if Arg_Count = 1 then
5876 Check_Arg_Is_Local_Name (Arg1);
5877 E_Id := Get_Pragma_Arg (Arg1);
5879 if Etype (E_Id) = Any_Type then
5883 Set_Is_Ada_2012_Only (Entity (E_Id));
5886 Check_Arg_Count (0);
5888 -- For Ada_2012 we unconditionally enforce the documented
5889 -- configuration pragma placement, since we do not want to
5890 -- tolerate mixed modes in a unit involving Ada 2012. That
5891 -- would cause real difficulties for those cases where there
5892 -- are incompatibilities between Ada 95 and Ada 2012. We could
5893 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5895 Check_Valid_Configuration_Pragma;
5897 -- Now set appropriate Ada mode
5900 Ada_Version := Ada_2012;
5902 Ada_Version := Ada_Version_Default;
5905 Ada_Version_Explicit := Ada_2012;
5909 ----------------------
5910 -- All_Calls_Remote --
5911 ----------------------
5913 -- pragma All_Calls_Remote [(library_package_NAME)];
5915 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5916 Lib_Entity : Entity_Id;
5919 Check_Ada_83_Warning;
5920 Check_Valid_Library_Unit_Pragma;
5922 if Nkind (N) = N_Null_Statement then
5926 Lib_Entity := Find_Lib_Unit_Name;
5928 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5930 if Present (Lib_Entity)
5931 and then not Debug_Flag_U
5933 if not Is_Remote_Call_Interface (Lib_Entity) then
5934 Error_Pragma ("pragma% only apply to rci unit");
5936 -- Set flag for entity of the library unit
5939 Set_Has_All_Calls_Remote (Lib_Entity);
5943 end All_Calls_Remote;
5949 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
5950 -- ARG ::= NAME | EXPRESSION
5952 -- The first two arguments are by convention intended to refer to an
5953 -- external tool and a tool-specific function. These arguments are
5956 when Pragma_Annotate => Annotate : begin
5958 Check_At_Least_N_Arguments (1);
5959 Check_Arg_Is_Identifier (Arg1);
5960 Check_No_Identifiers;
5968 -- Second unanalyzed parameter is optional
5974 while Present (Arg) loop
5975 Exp := Get_Pragma_Arg (Arg);
5978 if Is_Entity_Name (Exp) then
5981 -- For string literals, we assume Standard_String as the
5982 -- type, unless the string contains wide or wide_wide
5985 elsif Nkind (Exp) = N_String_Literal then
5986 if Has_Wide_Wide_Character (Exp) then
5987 Resolve (Exp, Standard_Wide_Wide_String);
5988 elsif Has_Wide_Character (Exp) then
5989 Resolve (Exp, Standard_Wide_String);
5991 Resolve (Exp, Standard_String);
5994 elsif Is_Overloaded (Exp) then
5996 ("ambiguous argument for pragma%", Exp);
6012 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6013 -- [, [Message =>] Static_String_EXPRESSION]);
6015 when Pragma_Assert => Assert : declare
6021 Check_At_Least_N_Arguments (1);
6022 Check_At_Most_N_Arguments (2);
6023 Check_Arg_Order ((Name_Check, Name_Message));
6024 Check_Optional_Identifier (Arg1, Name_Check);
6026 -- We treat pragma Assert as equivalent to:
6028 -- pragma Check (Assertion, condition [, msg]);
6030 -- So rewrite pragma in this manner, and analyze the result
6032 Expr := Get_Pragma_Arg (Arg1);
6034 Make_Pragma_Argument_Association (Loc,
6036 Make_Identifier (Loc,
6037 Chars => Name_Assertion)),
6039 Make_Pragma_Argument_Association (Sloc (Expr),
6040 Expression => Expr));
6042 if Arg_Count > 1 then
6043 Check_Optional_Identifier (Arg2, Name_Message);
6044 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6045 Append_To (Newa, Relocate_Node (Arg2));
6050 Chars => Name_Check,
6051 Pragma_Argument_Associations => Newa));
6055 ----------------------
6056 -- Assertion_Policy --
6057 ----------------------
6059 -- pragma Assertion_Policy (Check | Ignore)
6061 when Pragma_Assertion_Policy => Assertion_Policy : declare
6066 Check_Valid_Configuration_Pragma;
6067 Check_Arg_Count (1);
6068 Check_No_Identifiers;
6069 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6071 -- We treat pragma Assertion_Policy as equivalent to:
6073 -- pragma Check_Policy (Assertion, policy)
6075 -- So rewrite the pragma in that manner and link on to the chain
6076 -- of Check_Policy pragmas, marking the pragma as analyzed.
6078 Policy := Get_Pragma_Arg (Arg1);
6082 Chars => Name_Check_Policy,
6084 Pragma_Argument_Associations => New_List (
6085 Make_Pragma_Argument_Association (Loc,
6087 Make_Identifier (Loc,
6088 Chars => Name_Assertion)),
6090 Make_Pragma_Argument_Association (Loc,
6092 Make_Identifier (Sloc (Policy),
6093 Chars => Chars (Policy))))));
6096 Set_Next_Pragma (N, Opt.Check_Policy_List);
6097 Opt.Check_Policy_List := N;
6098 end Assertion_Policy;
6100 ------------------------------
6101 -- Assume_No_Invalid_Values --
6102 ------------------------------
6104 -- pragma Assume_No_Invalid_Values (On | Off);
6106 when Pragma_Assume_No_Invalid_Values =>
6108 Check_Valid_Configuration_Pragma;
6109 Check_Arg_Count (1);
6110 Check_No_Identifiers;
6111 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6113 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6114 Assume_No_Invalid_Values := True;
6116 Assume_No_Invalid_Values := False;
6123 -- pragma AST_Entry (entry_IDENTIFIER);
6125 when Pragma_AST_Entry => AST_Entry : declare
6131 Check_Arg_Count (1);
6132 Check_No_Identifiers;
6133 Check_Arg_Is_Local_Name (Arg1);
6134 Ent := Entity (Get_Pragma_Arg (Arg1));
6136 -- Note: the implementation of the AST_Entry pragma could handle
6137 -- the entry family case fine, but for now we are consistent with
6138 -- the DEC rules, and do not allow the pragma, which of course
6139 -- has the effect of also forbidding the attribute.
6141 if Ekind (Ent) /= E_Entry then
6143 ("pragma% argument must be simple entry name", Arg1);
6145 elsif Is_AST_Entry (Ent) then
6147 ("duplicate % pragma for entry", Arg1);
6149 elsif Has_Homonym (Ent) then
6151 ("pragma% argument cannot specify overloaded entry", Arg1);
6155 FF : constant Entity_Id := First_Formal (Ent);
6158 if Present (FF) then
6159 if Present (Next_Formal (FF)) then
6161 ("entry for pragma% can have only one argument",
6164 elsif Parameter_Mode (FF) /= E_In_Parameter then
6166 ("entry parameter for pragma% must have mode IN",
6172 Set_Is_AST_Entry (Ent);
6180 -- pragma Asynchronous (LOCAL_NAME);
6182 when Pragma_Asynchronous => Asynchronous : declare
6190 procedure Process_Async_Pragma;
6191 -- Common processing for procedure and access-to-procedure case
6193 --------------------------
6194 -- Process_Async_Pragma --
6195 --------------------------
6197 procedure Process_Async_Pragma is
6200 Set_Is_Asynchronous (Nm);
6204 -- The formals should be of mode IN (RM E.4.1(6))
6207 while Present (S) loop
6208 Formal := Defining_Identifier (S);
6210 if Nkind (Formal) = N_Defining_Identifier
6211 and then Ekind (Formal) /= E_In_Parameter
6214 ("pragma% procedure can only have IN parameter",
6221 Set_Is_Asynchronous (Nm);
6222 end Process_Async_Pragma;
6224 -- Start of processing for pragma Asynchronous
6227 Check_Ada_83_Warning;
6228 Check_No_Identifiers;
6229 Check_Arg_Count (1);
6230 Check_Arg_Is_Local_Name (Arg1);
6232 if Debug_Flag_U then
6236 C_Ent := Cunit_Entity (Current_Sem_Unit);
6237 Analyze (Get_Pragma_Arg (Arg1));
6238 Nm := Entity (Get_Pragma_Arg (Arg1));
6240 if not Is_Remote_Call_Interface (C_Ent)
6241 and then not Is_Remote_Types (C_Ent)
6243 -- This pragma should only appear in an RCI or Remote Types
6244 -- unit (RM E.4.1(4)).
6247 ("pragma% not in Remote_Call_Interface or " &
6248 "Remote_Types unit");
6251 if Ekind (Nm) = E_Procedure
6252 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6254 if not Is_Remote_Call_Interface (Nm) then
6256 ("pragma% cannot be applied on non-remote procedure",
6260 L := Parameter_Specifications (Parent (Nm));
6261 Process_Async_Pragma;
6264 elsif Ekind (Nm) = E_Function then
6266 ("pragma% cannot be applied to function", Arg1);
6268 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6270 if Is_Record_Type (Nm) then
6272 -- A record type that is the Equivalent_Type for a remote
6273 -- access-to-subprogram type.
6275 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6278 -- A non-expanded RAS type (distribution is not enabled)
6280 N := Declaration_Node (Nm);
6283 if Nkind (N) = N_Full_Type_Declaration
6284 and then Nkind (Type_Definition (N)) =
6285 N_Access_Procedure_Definition
6287 L := Parameter_Specifications (Type_Definition (N));
6288 Process_Async_Pragma;
6290 if Is_Asynchronous (Nm)
6291 and then Expander_Active
6292 and then Get_PCS_Name /= Name_No_DSA
6294 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6299 ("pragma% cannot reference access-to-function type",
6303 -- Only other possibility is Access-to-class-wide type
6305 elsif Is_Access_Type (Nm)
6306 and then Is_Class_Wide_Type (Designated_Type (Nm))
6308 Check_First_Subtype (Arg1);
6309 Set_Is_Asynchronous (Nm);
6310 if Expander_Active then
6311 RACW_Type_Is_Asynchronous (Nm);
6315 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6323 -- pragma Atomic (LOCAL_NAME);
6325 when Pragma_Atomic =>
6326 Process_Atomic_Shared_Volatile;
6328 -----------------------
6329 -- Atomic_Components --
6330 -----------------------
6332 -- pragma Atomic_Components (array_LOCAL_NAME);
6334 -- This processing is shared by Volatile_Components
6336 when Pragma_Atomic_Components |
6337 Pragma_Volatile_Components =>
6339 Atomic_Components : declare
6346 Check_Ada_83_Warning;
6347 Check_No_Identifiers;
6348 Check_Arg_Count (1);
6349 Check_Arg_Is_Local_Name (Arg1);
6350 E_Id := Get_Pragma_Arg (Arg1);
6352 if Etype (E_Id) = Any_Type then
6358 Check_Duplicate_Pragma (E);
6360 if Rep_Item_Too_Early (E, N)
6362 Rep_Item_Too_Late (E, N)
6367 D := Declaration_Node (E);
6370 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6372 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6373 and then Nkind (D) = N_Object_Declaration
6374 and then Nkind (Object_Definition (D)) =
6375 N_Constrained_Array_Definition)
6377 -- The flag is set on the object, or on the base type
6379 if Nkind (D) /= N_Object_Declaration then
6383 Set_Has_Volatile_Components (E, Sense);
6385 if Prag_Id = Pragma_Atomic_Components then
6386 Set_Has_Atomic_Components (E, Sense);
6390 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6392 end Atomic_Components;
6394 --------------------
6395 -- Attach_Handler --
6396 --------------------
6398 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6400 when Pragma_Attach_Handler =>
6401 Check_Ada_83_Warning;
6402 Check_No_Identifiers;
6403 Check_Arg_Count (2);
6405 if No_Run_Time_Mode then
6406 Error_Msg_CRT ("Attach_Handler pragma", N);
6408 Check_Interrupt_Or_Attach_Handler;
6410 -- The expression that designates the attribute may depend on a
6411 -- discriminant, and is therefore a per- object expression, to
6412 -- be expanded in the init proc. If expansion is enabled, then
6413 -- perform semantic checks on a copy only.
6415 if Expander_Active then
6417 Temp : constant Node_Id :=
6418 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6420 Set_Parent (Temp, N);
6421 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6425 Analyze (Get_Pragma_Arg (Arg2));
6426 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6429 Process_Interrupt_Or_Attach_Handler;
6432 --------------------
6433 -- C_Pass_By_Copy --
6434 --------------------
6436 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6438 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6444 Check_Valid_Configuration_Pragma;
6445 Check_Arg_Count (1);
6446 Check_Optional_Identifier (Arg1, "max_size");
6448 Arg := Get_Pragma_Arg (Arg1);
6449 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6451 Val := Expr_Value (Arg);
6455 ("maximum size for pragma% must be positive", Arg1);
6457 elsif UI_Is_In_Int_Range (Val) then
6458 Default_C_Record_Mechanism := UI_To_Int (Val);
6460 -- If a giant value is given, Int'Last will do well enough.
6461 -- If sometime someone complains that a record larger than
6462 -- two gigabytes is not copied, we will worry about it then!
6465 Default_C_Record_Mechanism := Mechanism_Type'Last;
6473 -- pragma Check ([Name =>] Identifier,
6474 -- [Check =>] Boolean_Expression
6475 -- [,[Message =>] String_Expression]);
6477 when Pragma_Check => Check : declare
6482 -- Set True if category of assertions referenced by Name enabled
6486 Check_At_Least_N_Arguments (2);
6487 Check_At_Most_N_Arguments (3);
6488 Check_Optional_Identifier (Arg1, Name_Name);
6489 Check_Optional_Identifier (Arg2, Name_Check);
6491 if Arg_Count = 3 then
6492 Check_Optional_Identifier (Arg3, Name_Message);
6493 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6496 Check_Arg_Is_Identifier (Arg1);
6498 -- Indicate if pragma is enabled. The Original_Node reference here
6499 -- is to deal with pragma Assert rewritten as a Check pragma.
6501 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6504 Set_Pragma_Enabled (N);
6505 Set_Pragma_Enabled (Original_Node (N));
6506 Set_SCO_Pragma_Enabled (Loc);
6509 -- If expansion is active and the check is not enabled then we
6510 -- rewrite the Check as:
6512 -- if False and then condition then
6516 -- The reason we do this rewriting during semantic analysis rather
6517 -- than as part of normal expansion is that we cannot analyze and
6518 -- expand the code for the boolean expression directly, or it may
6519 -- cause insertion of actions that would escape the attempt to
6520 -- suppress the check code.
6522 -- Note that the Sloc for the if statement corresponds to the
6523 -- argument condition, not the pragma itself. The reason for this
6524 -- is that we may generate a warning if the condition is False at
6525 -- compile time, and we do not want to delete this warning when we
6526 -- delete the if statement.
6528 Expr := Get_Pragma_Arg (Arg2);
6530 if Expander_Active and then not Check_On then
6531 Eloc := Sloc (Expr);
6534 Make_If_Statement (Eloc,
6536 Make_And_Then (Eloc,
6537 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6538 Right_Opnd => Expr),
6539 Then_Statements => New_List (
6540 Make_Null_Statement (Eloc))));
6547 Analyze_And_Resolve (Expr, Any_Boolean);
6555 -- pragma Check_Name (check_IDENTIFIER);
6557 when Pragma_Check_Name =>
6558 Check_No_Identifiers;
6560 Check_Valid_Configuration_Pragma;
6561 Check_Arg_Count (1);
6562 Check_Arg_Is_Identifier (Arg1);
6565 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6568 for J in Check_Names.First .. Check_Names.Last loop
6569 if Check_Names.Table (J) = Nam then
6574 Check_Names.Append (Nam);
6581 -- pragma Check_Policy (
6582 -- [Name =>] IDENTIFIER,
6583 -- [Policy =>] POLICY_IDENTIFIER);
6585 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6587 -- Note: this is a configuration pragma, but it is allowed to appear
6590 when Pragma_Check_Policy =>
6592 Check_Arg_Count (2);
6593 Check_Optional_Identifier (Arg1, Name_Name);
6594 Check_Optional_Identifier (Arg2, Name_Policy);
6596 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6598 -- A Check_Policy pragma can appear either as a configuration
6599 -- pragma, or in a declarative part or a package spec (see RM
6600 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6601 -- followed for Check_Policy).
6603 if not Is_Configuration_Pragma then
6604 Check_Is_In_Decl_Part_Or_Package_Spec;
6607 Set_Next_Pragma (N, Opt.Check_Policy_List);
6608 Opt.Check_Policy_List := N;
6610 ---------------------
6611 -- CIL_Constructor --
6612 ---------------------
6614 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6616 -- Processing for this pragma is shared with Java_Constructor
6622 -- pragma Comment (static_string_EXPRESSION)
6624 -- Processing for pragma Comment shares the circuitry for pragma
6625 -- Ident. The only differences are that Ident enforces a limit of 31
6626 -- characters on its argument, and also enforces limitations on
6627 -- placement for DEC compatibility. Pragma Comment shares neither of
6628 -- these restrictions.
6634 -- pragma Common_Object (
6635 -- [Internal =>] LOCAL_NAME
6636 -- [, [External =>] EXTERNAL_SYMBOL]
6637 -- [, [Size =>] EXTERNAL_SYMBOL]);
6639 -- Processing for this pragma is shared with Psect_Object
6641 ------------------------
6642 -- Compile_Time_Error --
6643 ------------------------
6645 -- pragma Compile_Time_Error
6646 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6648 when Pragma_Compile_Time_Error =>
6650 Process_Compile_Time_Warning_Or_Error;
6652 --------------------------
6653 -- Compile_Time_Warning --
6654 --------------------------
6656 -- pragma Compile_Time_Warning
6657 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6659 when Pragma_Compile_Time_Warning =>
6661 Process_Compile_Time_Warning_Or_Error;
6667 when Pragma_Compiler_Unit =>
6669 Check_Arg_Count (0);
6670 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6672 -----------------------------
6673 -- Complete_Representation --
6674 -----------------------------
6676 -- pragma Complete_Representation;
6678 when Pragma_Complete_Representation =>
6680 Check_Arg_Count (0);
6682 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6684 ("pragma & must appear within record representation clause");
6687 ----------------------------
6688 -- Complex_Representation --
6689 ----------------------------
6691 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6693 when Pragma_Complex_Representation => Complex_Representation : declare
6700 Check_Arg_Count (1);
6701 Check_Optional_Identifier (Arg1, Name_Entity);
6702 Check_Arg_Is_Local_Name (Arg1);
6703 E_Id := Get_Pragma_Arg (Arg1);
6705 if Etype (E_Id) = Any_Type then
6711 if not Is_Record_Type (E) then
6713 ("argument for pragma% must be record type", Arg1);
6716 Ent := First_Entity (E);
6719 or else No (Next_Entity (Ent))
6720 or else Present (Next_Entity (Next_Entity (Ent)))
6721 or else not Is_Floating_Point_Type (Etype (Ent))
6722 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6725 ("record for pragma% must have two fields of the same "
6726 & "floating-point type", Arg1);
6729 Set_Has_Complex_Representation (Base_Type (E));
6731 -- We need to treat the type has having a non-standard
6732 -- representation, for back-end purposes, even though in
6733 -- general a complex will have the default representation
6734 -- of a record with two real components.
6736 Set_Has_Non_Standard_Rep (Base_Type (E));
6738 end Complex_Representation;
6740 -------------------------
6741 -- Component_Alignment --
6742 -------------------------
6744 -- pragma Component_Alignment (
6745 -- [Form =>] ALIGNMENT_CHOICE
6746 -- [, [Name =>] type_LOCAL_NAME]);
6748 -- ALIGNMENT_CHOICE ::=
6750 -- | Component_Size_4
6754 when Pragma_Component_Alignment => Component_AlignmentP : declare
6755 Args : Args_List (1 .. 2);
6756 Names : constant Name_List (1 .. 2) := (
6760 Form : Node_Id renames Args (1);
6761 Name : Node_Id renames Args (2);
6763 Atype : Component_Alignment_Kind;
6768 Gather_Associations (Names, Args);
6771 Error_Pragma ("missing Form argument for pragma%");
6774 Check_Arg_Is_Identifier (Form);
6776 -- Get proper alignment, note that Default = Component_Size on all
6777 -- machines we have so far, and we want to set this value rather
6778 -- than the default value to indicate that it has been explicitly
6779 -- set (and thus will not get overridden by the default component
6780 -- alignment for the current scope)
6782 if Chars (Form) = Name_Component_Size then
6783 Atype := Calign_Component_Size;
6785 elsif Chars (Form) = Name_Component_Size_4 then
6786 Atype := Calign_Component_Size_4;
6788 elsif Chars (Form) = Name_Default then
6789 Atype := Calign_Component_Size;
6791 elsif Chars (Form) = Name_Storage_Unit then
6792 Atype := Calign_Storage_Unit;
6796 ("invalid Form parameter for pragma%", Form);
6799 -- Case with no name, supplied, affects scope table entry
6803 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6805 -- Case of name supplied
6808 Check_Arg_Is_Local_Name (Name);
6810 Typ := Entity (Name);
6813 or else Rep_Item_Too_Early (Typ, N)
6817 Typ := Underlying_Type (Typ);
6820 if not Is_Record_Type (Typ)
6821 and then not Is_Array_Type (Typ)
6824 ("Name parameter of pragma% must identify record or " &
6825 "array type", Name);
6828 -- An explicit Component_Alignment pragma overrides an
6829 -- implicit pragma Pack, but not an explicit one.
6831 if not Has_Pragma_Pack (Base_Type (Typ)) then
6832 Set_Is_Packed (Base_Type (Typ), False);
6833 Set_Component_Alignment (Base_Type (Typ), Atype);
6836 end Component_AlignmentP;
6842 -- pragma Controlled (first_subtype_LOCAL_NAME);
6844 when Pragma_Controlled => Controlled : declare
6848 Check_No_Identifiers;
6849 Check_Arg_Count (1);
6850 Check_Arg_Is_Local_Name (Arg1);
6851 Arg := Get_Pragma_Arg (Arg1);
6853 if not Is_Entity_Name (Arg)
6854 or else not Is_Access_Type (Entity (Arg))
6856 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6858 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6866 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6867 -- [Entity =>] LOCAL_NAME);
6869 when Pragma_Convention => Convention : declare
6872 pragma Warnings (Off, C);
6873 pragma Warnings (Off, E);
6875 Check_Arg_Order ((Name_Convention, Name_Entity));
6876 Check_Ada_83_Warning;
6877 Check_Arg_Count (2);
6878 Process_Convention (C, E);
6881 ---------------------------
6882 -- Convention_Identifier --
6883 ---------------------------
6885 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6886 -- [Convention =>] convention_IDENTIFIER);
6888 when Pragma_Convention_Identifier => Convention_Identifier : declare
6894 Check_Arg_Order ((Name_Name, Name_Convention));
6895 Check_Arg_Count (2);
6896 Check_Optional_Identifier (Arg1, Name_Name);
6897 Check_Optional_Identifier (Arg2, Name_Convention);
6898 Check_Arg_Is_Identifier (Arg1);
6899 Check_Arg_Is_Identifier (Arg2);
6900 Idnam := Chars (Get_Pragma_Arg (Arg1));
6901 Cname := Chars (Get_Pragma_Arg (Arg2));
6903 if Is_Convention_Name (Cname) then
6904 Record_Convention_Identifier
6905 (Idnam, Get_Convention_Id (Cname));
6908 ("second arg for % pragma must be convention", Arg2);
6910 end Convention_Identifier;
6916 -- pragma CPP_Class ([Entity =>] local_NAME)
6918 when Pragma_CPP_Class => CPP_Class : declare
6923 if Warn_On_Obsolescent_Feature then
6925 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6926 " by pragma import?", N);
6930 Check_Arg_Count (1);
6931 Check_Optional_Identifier (Arg1, Name_Entity);
6932 Check_Arg_Is_Local_Name (Arg1);
6934 Arg := Get_Pragma_Arg (Arg1);
6937 if Etype (Arg) = Any_Type then
6941 if not Is_Entity_Name (Arg)
6942 or else not Is_Type (Entity (Arg))
6944 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6947 Typ := Entity (Arg);
6949 if not Is_Tagged_Type (Typ) then
6950 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6953 -- Types treated as CPP classes are treated as limited, but we
6954 -- don't require them to be declared this way. A warning is issued
6955 -- to encourage the user to declare them as limited. This is not
6956 -- an error, for compatibility reasons, because these types have
6957 -- been supported this way for some time.
6959 if not Is_Limited_Type (Typ) then
6961 ("imported 'C'P'P type should be " &
6962 "explicitly declared limited?",
6963 Get_Pragma_Arg (Arg1));
6965 ("\type will be considered limited",
6966 Get_Pragma_Arg (Arg1));
6969 Set_Is_CPP_Class (Typ);
6970 Set_Is_Limited_Record (Typ);
6971 Set_Convention (Typ, Convention_CPP);
6973 -- Imported CPP types must not have discriminants (because C++
6974 -- classes do not have discriminants).
6976 if Has_Discriminants (Typ) then
6978 ("imported 'C'P'P type cannot have discriminants",
6979 First (Discriminant_Specifications
6980 (Declaration_Node (Typ))));
6983 -- Components of imported CPP types must not have default
6984 -- expressions because the constructor (if any) is in the
6987 if Is_Incomplete_Or_Private_Type (Typ)
6988 and then No (Underlying_Type (Typ))
6990 -- It should be an error to apply pragma CPP to a private
6991 -- type if the underlying type is not visible (as it is
6992 -- for any representation item). For now, for backward
6993 -- compatibility we do nothing but we cannot check components
6994 -- because they are not available at this stage. All this code
6995 -- will be removed when we cleanup this obsolete GNAT pragma???
7001 Tdef : constant Node_Id :=
7002 Type_Definition (Declaration_Node (Typ));
7007 if Nkind (Tdef) = N_Record_Definition then
7008 Clist := Component_List (Tdef);
7010 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7011 Clist := Component_List (Record_Extension_Part (Tdef));
7014 if Present (Clist) then
7015 Comp := First (Component_Items (Clist));
7016 while Present (Comp) loop
7017 if Present (Expression (Comp)) then
7019 ("component of imported 'C'P'P type cannot have" &
7020 " default expression", Expression (Comp));
7030 ---------------------
7031 -- CPP_Constructor --
7032 ---------------------
7034 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7035 -- [, [External_Name =>] static_string_EXPRESSION ]
7036 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7038 when Pragma_CPP_Constructor => CPP_Constructor : declare
7042 Tag_Typ : Entity_Id;
7046 Check_At_Least_N_Arguments (1);
7047 Check_At_Most_N_Arguments (3);
7048 Check_Optional_Identifier (Arg1, Name_Entity);
7049 Check_Arg_Is_Local_Name (Arg1);
7051 Id := Get_Pragma_Arg (Arg1);
7052 Find_Program_Unit_Name (Id);
7054 -- If we did not find the name, we are done
7056 if Etype (Id) = Any_Type then
7060 Def_Id := Entity (Id);
7062 -- Check if already defined as constructor
7064 if Is_Constructor (Def_Id) then
7066 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7070 if Ekind (Def_Id) = E_Function
7071 and then (Is_CPP_Class (Etype (Def_Id))
7072 or else (Is_Class_Wide_Type (Etype (Def_Id))
7074 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7076 if Arg_Count >= 2 then
7077 Set_Imported (Def_Id);
7078 Set_Is_Public (Def_Id);
7079 Process_Interface_Name (Def_Id, Arg2, Arg3);
7082 Set_Has_Completion (Def_Id);
7083 Set_Is_Constructor (Def_Id);
7085 -- Imported C++ constructors are not dispatching primitives
7086 -- because in C++ they don't have a dispatch table slot.
7087 -- However, in Ada the constructor has the profile of a
7088 -- function that returns a tagged type and therefore it has
7089 -- been treated as a primitive operation during semantic
7090 -- analysis. We now remove it from the list of primitive
7091 -- operations of the type.
7093 if Is_Tagged_Type (Etype (Def_Id))
7094 and then not Is_Class_Wide_Type (Etype (Def_Id))
7096 pragma Assert (Is_Dispatching_Operation (Def_Id));
7097 Tag_Typ := Etype (Def_Id);
7099 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7100 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7104 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7105 Set_Is_Dispatching_Operation (Def_Id, False);
7108 -- For backward compatibility, if the constructor returns a
7109 -- class wide type, and we internally change the return type to
7110 -- the corresponding root type.
7112 if Is_Class_Wide_Type (Etype (Def_Id)) then
7113 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7117 ("pragma% requires function returning a 'C'P'P_Class type",
7120 end CPP_Constructor;
7126 when Pragma_CPP_Virtual => CPP_Virtual : declare
7130 if Warn_On_Obsolescent_Feature then
7132 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7141 when Pragma_CPP_Vtable => CPP_Vtable : declare
7145 if Warn_On_Obsolescent_Feature then
7147 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7156 -- pragma CPU (EXPRESSION);
7158 when Pragma_CPU => CPU : declare
7159 P : constant Node_Id := Parent (N);
7164 Check_No_Identifiers;
7165 Check_Arg_Count (1);
7169 if Nkind (P) = N_Subprogram_Body then
7170 Check_In_Main_Program;
7172 Arg := Get_Pragma_Arg (Arg1);
7173 Analyze_And_Resolve (Arg, Any_Integer);
7177 if not Is_Static_Expression (Arg) then
7178 Flag_Non_Static_Expr
7179 ("main subprogram affinity is not static!", Arg);
7182 -- If constraint error, then we already signalled an error
7184 elsif Raises_Constraint_Error (Arg) then
7187 -- Otherwise check in range
7191 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7192 -- This is the entity System.Multiprocessors.CPU_Range;
7194 Val : constant Uint := Expr_Value (Arg);
7197 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7199 Val > Expr_Value (Type_High_Bound (CPU_Id))
7202 ("main subprogram CPU is out of range", Arg1);
7208 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7212 elsif Nkind (P) = N_Task_Definition then
7213 Arg := Get_Pragma_Arg (Arg1);
7215 -- The expression must be analyzed in the special manner
7216 -- described in "Handling of Default and Per-Object
7217 -- Expressions" in sem.ads.
7219 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7221 -- Anything else is incorrect
7227 if Has_Pragma_CPU (P) then
7228 Error_Pragma ("duplicate pragma% not allowed");
7230 Set_Has_Pragma_CPU (P, True);
7232 if Nkind (P) = N_Task_Definition then
7233 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7242 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7244 when Pragma_Debug => Debug : declare
7252 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7255 if Arg_Count = 2 then
7258 Left_Opnd => Relocate_Node (Cond),
7259 Right_Opnd => Get_Pragma_Arg (Arg1));
7262 -- Rewrite into a conditional with an appropriate condition. We
7263 -- wrap the procedure call in a block so that overhead from e.g.
7264 -- use of the secondary stack does not generate execution overhead
7265 -- for suppressed conditions.
7267 Rewrite (N, Make_Implicit_If_Statement (N,
7269 Then_Statements => New_List (
7270 Make_Block_Statement (Loc,
7271 Handled_Statement_Sequence =>
7272 Make_Handled_Sequence_Of_Statements (Loc,
7273 Statements => New_List (
7274 Relocate_Node (Debug_Statement (N))))))));
7282 -- pragma Debug_Policy (Check | Ignore)
7284 when Pragma_Debug_Policy =>
7286 Check_Arg_Count (1);
7287 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7288 Debug_Pragmas_Enabled :=
7289 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7291 ---------------------
7292 -- Detect_Blocking --
7293 ---------------------
7295 -- pragma Detect_Blocking;
7297 when Pragma_Detect_Blocking =>
7299 Check_Arg_Count (0);
7300 Check_Valid_Configuration_Pragma;
7301 Detect_Blocking := True;
7303 --------------------------
7304 -- Default_Storage_Pool --
7305 --------------------------
7307 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7309 when Pragma_Default_Storage_Pool =>
7311 Check_Arg_Count (1);
7313 -- Default_Storage_Pool can appear as a configuration pragma, or
7314 -- in a declarative part or a package spec.
7316 if not Is_Configuration_Pragma then
7317 Check_Is_In_Decl_Part_Or_Package_Spec;
7320 -- Case of Default_Storage_Pool (null);
7322 if Nkind (Expression (Arg1)) = N_Null then
7323 Analyze (Expression (Arg1));
7325 -- This is an odd case, this is not really an expression, so
7326 -- we don't have a type for it. So just set the type to Empty.
7328 Set_Etype (Expression (Arg1), Empty);
7330 -- Case of Default_Storage_Pool (storage_pool_NAME);
7333 -- If it's a configuration pragma, then the only allowed
7334 -- argument is "null".
7336 if Is_Configuration_Pragma then
7337 Error_Pragma_Arg ("NULL expected", Arg1);
7340 -- The expected type for a non-"null" argument is
7341 -- Root_Storage_Pool'Class.
7344 (Get_Pragma_Arg (Arg1),
7345 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7348 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7349 -- for an access type will use this information to set the
7350 -- appropriate attributes of the access type.
7352 Default_Pool := Expression (Arg1);
7358 when Pragma_Dimension =>
7360 Check_Arg_Count (4);
7361 Check_No_Identifiers;
7362 Check_Arg_Is_Local_Name (Arg1);
7364 if not Is_Type (Arg1) then
7365 Error_Pragma ("first argument for pragma% must be subtype");
7368 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7369 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7370 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7376 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7378 when Pragma_Discard_Names => Discard_Names : declare
7383 Check_Ada_83_Warning;
7385 -- Deal with configuration pragma case
7387 if Arg_Count = 0 and then Is_Configuration_Pragma then
7388 Global_Discard_Names := True;
7391 -- Otherwise, check correct appropriate context
7394 Check_Is_In_Decl_Part_Or_Package_Spec;
7396 if Arg_Count = 0 then
7398 -- If there is no parameter, then from now on this pragma
7399 -- applies to any enumeration, exception or tagged type
7400 -- defined in the current declarative part, and recursively
7401 -- to any nested scope.
7403 Set_Discard_Names (Current_Scope, Sense);
7407 Check_Arg_Count (1);
7408 Check_Optional_Identifier (Arg1, Name_On);
7409 Check_Arg_Is_Local_Name (Arg1);
7411 E_Id := Get_Pragma_Arg (Arg1);
7413 if Etype (E_Id) = Any_Type then
7419 if (Is_First_Subtype (E)
7421 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7422 or else Ekind (E) = E_Exception
7424 Set_Discard_Names (E, Sense);
7427 ("inappropriate entity for pragma%", Arg1);
7438 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7440 when Pragma_Elaborate => Elaborate : declare
7445 -- Pragma must be in context items list of a compilation unit
7447 if not Is_In_Context_Clause then
7451 -- Must be at least one argument
7453 if Arg_Count = 0 then
7454 Error_Pragma ("pragma% requires at least one argument");
7457 -- In Ada 83 mode, there can be no items following it in the
7458 -- context list except other pragmas and implicit with clauses
7459 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7460 -- placement rule does not apply.
7462 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7464 while Present (Citem) loop
7465 if Nkind (Citem) = N_Pragma
7466 or else (Nkind (Citem) = N_With_Clause
7467 and then Implicit_With (Citem))
7472 ("(Ada 83) pragma% must be at end of context clause");
7479 -- Finally, the arguments must all be units mentioned in a with
7480 -- clause in the same context clause. Note we already checked (in
7481 -- Par.Prag) that the arguments are all identifiers or selected
7485 Outer : while Present (Arg) loop
7486 Citem := First (List_Containing (N));
7487 Inner : while Citem /= N loop
7488 if Nkind (Citem) = N_With_Clause
7489 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7491 Set_Elaborate_Present (Citem, True);
7492 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7494 -- With the pragma present, elaboration calls on
7495 -- subprograms from the named unit need no further
7496 -- checks, as long as the pragma appears in the current
7497 -- compilation unit. If the pragma appears in some unit
7498 -- in the context, there might still be a need for an
7499 -- Elaborate_All_Desirable from the current compilation
7500 -- to the named unit, so we keep the check enabled.
7502 if In_Extended_Main_Source_Unit (N) then
7503 Set_Suppress_Elaboration_Warnings
7504 (Entity (Name (Citem)));
7515 ("argument of pragma% is not with'ed unit", Arg);
7521 -- Give a warning if operating in static mode with -gnatwl
7522 -- (elaboration warnings enabled) switch set.
7524 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7526 ("?use of pragma Elaborate may not be safe", N);
7528 ("?use pragma Elaborate_All instead if possible", N);
7536 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7538 when Pragma_Elaborate_All => Elaborate_All : declare
7543 Check_Ada_83_Warning;
7545 -- Pragma must be in context items list of a compilation unit
7547 if not Is_In_Context_Clause then
7551 -- Must be at least one argument
7553 if Arg_Count = 0 then
7554 Error_Pragma ("pragma% requires at least one argument");
7557 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7558 -- have to appear at the end of the context clause, but may
7559 -- appear mixed in with other items, even in Ada 83 mode.
7561 -- Final check: the arguments must all be units mentioned in
7562 -- a with clause in the same context clause. Note that we
7563 -- already checked (in Par.Prag) that all the arguments are
7564 -- either identifiers or selected components.
7567 Outr : while Present (Arg) loop
7568 Citem := First (List_Containing (N));
7569 Innr : while Citem /= N loop
7570 if Nkind (Citem) = N_With_Clause
7571 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7573 Set_Elaborate_All_Present (Citem, True);
7574 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7576 -- Suppress warnings and elaboration checks on the named
7577 -- unit if the pragma is in the current compilation, as
7578 -- for pragma Elaborate.
7580 if In_Extended_Main_Source_Unit (N) then
7581 Set_Suppress_Elaboration_Warnings
7582 (Entity (Name (Citem)));
7591 Set_Error_Posted (N);
7593 ("argument of pragma% is not with'ed unit", Arg);
7600 --------------------
7601 -- Elaborate_Body --
7602 --------------------
7604 -- pragma Elaborate_Body [( library_unit_NAME )];
7606 when Pragma_Elaborate_Body => Elaborate_Body : declare
7607 Cunit_Node : Node_Id;
7608 Cunit_Ent : Entity_Id;
7611 Check_Ada_83_Warning;
7612 Check_Valid_Library_Unit_Pragma;
7614 if Nkind (N) = N_Null_Statement then
7618 Cunit_Node := Cunit (Current_Sem_Unit);
7619 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7621 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7624 Error_Pragma ("pragma% must refer to a spec, not a body");
7626 Set_Body_Required (Cunit_Node, True);
7627 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7629 -- If we are in dynamic elaboration mode, then we suppress
7630 -- elaboration warnings for the unit, since it is definitely
7631 -- fine NOT to do dynamic checks at the first level (and such
7632 -- checks will be suppressed because no elaboration boolean
7633 -- is created for Elaborate_Body packages).
7635 -- But in the static model of elaboration, Elaborate_Body is
7636 -- definitely NOT good enough to ensure elaboration safety on
7637 -- its own, since the body may WITH other units that are not
7638 -- safe from an elaboration point of view, so a client must
7639 -- still do an Elaborate_All on such units.
7641 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7642 -- Elaborate_Body always suppressed elab warnings.
7644 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7645 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7650 ------------------------
7651 -- Elaboration_Checks --
7652 ------------------------
7654 -- pragma Elaboration_Checks (Static | Dynamic);
7656 when Pragma_Elaboration_Checks =>
7658 Check_Arg_Count (1);
7659 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7660 Dynamic_Elaboration_Checks :=
7661 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7667 -- pragma Eliminate (
7668 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7669 -- [,[Entity =>] IDENTIFIER |
7670 -- SELECTED_COMPONENT |
7672 -- [, OVERLOADING_RESOLUTION]);
7674 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7677 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7680 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7682 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7683 -- Result_Type => result_SUBTYPE_NAME]
7685 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7686 -- SUBTYPE_NAME ::= STRING_LITERAL
7688 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7689 -- SOURCE_TRACE ::= STRING_LITERAL
7691 when Pragma_Eliminate => Eliminate : declare
7692 Args : Args_List (1 .. 5);
7693 Names : constant Name_List (1 .. 5) := (
7696 Name_Parameter_Types,
7698 Name_Source_Location);
7700 Unit_Name : Node_Id renames Args (1);
7701 Entity : Node_Id renames Args (2);
7702 Parameter_Types : Node_Id renames Args (3);
7703 Result_Type : Node_Id renames Args (4);
7704 Source_Location : Node_Id renames Args (5);
7708 Check_Valid_Configuration_Pragma;
7709 Gather_Associations (Names, Args);
7711 if No (Unit_Name) then
7712 Error_Pragma ("missing Unit_Name argument for pragma%");
7716 and then (Present (Parameter_Types)
7718 Present (Result_Type)
7720 Present (Source_Location))
7722 Error_Pragma ("missing Entity argument for pragma%");
7725 if (Present (Parameter_Types)
7727 Present (Result_Type))
7729 Present (Source_Location)
7732 ("parameter profile and source location cannot " &
7733 "be used together in pragma%");
7736 Process_Eliminate_Pragma
7750 -- [ Convention =>] convention_IDENTIFIER,
7751 -- [ Entity =>] local_NAME
7752 -- [, [External_Name =>] static_string_EXPRESSION ]
7753 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7755 when Pragma_Export => Export : declare
7759 pragma Warnings (Off, C);
7762 Check_Ada_83_Warning;
7768 Check_At_Least_N_Arguments (2);
7769 Check_At_Most_N_Arguments (4);
7770 Process_Convention (C, Def_Id);
7772 if Ekind (Def_Id) /= E_Constant then
7773 Note_Possible_Modification
7774 (Get_Pragma_Arg (Arg2), Sure => False);
7777 Process_Interface_Name (Def_Id, Arg3, Arg4);
7778 Set_Exported (Def_Id, Arg2);
7780 -- If the entity is a deferred constant, propagate the information
7781 -- to the full view, because gigi elaborates the full view only.
7783 if Ekind (Def_Id) = E_Constant
7784 and then Present (Full_View (Def_Id))
7787 Id2 : constant Entity_Id := Full_View (Def_Id);
7789 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7790 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7791 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7796 ----------------------
7797 -- Export_Exception --
7798 ----------------------
7800 -- pragma Export_Exception (
7801 -- [Internal =>] LOCAL_NAME
7802 -- [, [External =>] EXTERNAL_SYMBOL]
7803 -- [, [Form =>] Ada | VMS]
7804 -- [, [Code =>] static_integer_EXPRESSION]);
7806 when Pragma_Export_Exception => Export_Exception : declare
7807 Args : Args_List (1 .. 4);
7808 Names : constant Name_List (1 .. 4) := (
7814 Internal : Node_Id renames Args (1);
7815 External : Node_Id renames Args (2);
7816 Form : Node_Id renames Args (3);
7817 Code : Node_Id renames Args (4);
7822 if Inside_A_Generic then
7823 Error_Pragma ("pragma% cannot be used for generic entities");
7826 Gather_Associations (Names, Args);
7827 Process_Extended_Import_Export_Exception_Pragma (
7828 Arg_Internal => Internal,
7829 Arg_External => External,
7833 if not Is_VMS_Exception (Entity (Internal)) then
7834 Set_Exported (Entity (Internal), Internal);
7836 end Export_Exception;
7838 ---------------------
7839 -- Export_Function --
7840 ---------------------
7842 -- pragma Export_Function (
7843 -- [Internal =>] LOCAL_NAME
7844 -- [, [External =>] EXTERNAL_SYMBOL]
7845 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7846 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7847 -- [, [Mechanism =>] MECHANISM]
7848 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7850 -- EXTERNAL_SYMBOL ::=
7852 -- | static_string_EXPRESSION
7854 -- PARAMETER_TYPES ::=
7856 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7858 -- TYPE_DESIGNATOR ::=
7860 -- | subtype_Name ' Access
7864 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7866 -- MECHANISM_ASSOCIATION ::=
7867 -- [formal_parameter_NAME =>] MECHANISM_NAME
7869 -- MECHANISM_NAME ::=
7872 -- | Descriptor [([Class =>] CLASS_NAME)]
7874 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7876 when Pragma_Export_Function => Export_Function : declare
7877 Args : Args_List (1 .. 6);
7878 Names : constant Name_List (1 .. 6) := (
7881 Name_Parameter_Types,
7884 Name_Result_Mechanism);
7886 Internal : Node_Id renames Args (1);
7887 External : Node_Id renames Args (2);
7888 Parameter_Types : Node_Id renames Args (3);
7889 Result_Type : Node_Id renames Args (4);
7890 Mechanism : Node_Id renames Args (5);
7891 Result_Mechanism : Node_Id renames Args (6);
7895 Gather_Associations (Names, Args);
7896 Process_Extended_Import_Export_Subprogram_Pragma (
7897 Arg_Internal => Internal,
7898 Arg_External => External,
7899 Arg_Parameter_Types => Parameter_Types,
7900 Arg_Result_Type => Result_Type,
7901 Arg_Mechanism => Mechanism,
7902 Arg_Result_Mechanism => Result_Mechanism);
7903 end Export_Function;
7909 -- pragma Export_Object (
7910 -- [Internal =>] LOCAL_NAME
7911 -- [, [External =>] EXTERNAL_SYMBOL]
7912 -- [, [Size =>] EXTERNAL_SYMBOL]);
7914 -- EXTERNAL_SYMBOL ::=
7916 -- | static_string_EXPRESSION
7918 -- PARAMETER_TYPES ::=
7920 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7922 -- TYPE_DESIGNATOR ::=
7924 -- | subtype_Name ' Access
7928 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7930 -- MECHANISM_ASSOCIATION ::=
7931 -- [formal_parameter_NAME =>] MECHANISM_NAME
7933 -- MECHANISM_NAME ::=
7936 -- | Descriptor [([Class =>] CLASS_NAME)]
7938 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7940 when Pragma_Export_Object => Export_Object : declare
7941 Args : Args_List (1 .. 3);
7942 Names : constant Name_List (1 .. 3) := (
7947 Internal : Node_Id renames Args (1);
7948 External : Node_Id renames Args (2);
7949 Size : Node_Id renames Args (3);
7953 Gather_Associations (Names, Args);
7954 Process_Extended_Import_Export_Object_Pragma (
7955 Arg_Internal => Internal,
7956 Arg_External => External,
7960 ----------------------
7961 -- Export_Procedure --
7962 ----------------------
7964 -- pragma Export_Procedure (
7965 -- [Internal =>] LOCAL_NAME
7966 -- [, [External =>] EXTERNAL_SYMBOL]
7967 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7968 -- [, [Mechanism =>] MECHANISM]);
7970 -- EXTERNAL_SYMBOL ::=
7972 -- | static_string_EXPRESSION
7974 -- PARAMETER_TYPES ::=
7976 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7978 -- TYPE_DESIGNATOR ::=
7980 -- | subtype_Name ' Access
7984 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7986 -- MECHANISM_ASSOCIATION ::=
7987 -- [formal_parameter_NAME =>] MECHANISM_NAME
7989 -- MECHANISM_NAME ::=
7992 -- | Descriptor [([Class =>] CLASS_NAME)]
7994 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7996 when Pragma_Export_Procedure => Export_Procedure : declare
7997 Args : Args_List (1 .. 4);
7998 Names : constant Name_List (1 .. 4) := (
8001 Name_Parameter_Types,
8004 Internal : Node_Id renames Args (1);
8005 External : Node_Id renames Args (2);
8006 Parameter_Types : Node_Id renames Args (3);
8007 Mechanism : Node_Id renames Args (4);
8011 Gather_Associations (Names, Args);
8012 Process_Extended_Import_Export_Subprogram_Pragma (
8013 Arg_Internal => Internal,
8014 Arg_External => External,
8015 Arg_Parameter_Types => Parameter_Types,
8016 Arg_Mechanism => Mechanism);
8017 end Export_Procedure;
8023 -- pragma Export_Value (
8024 -- [Value =>] static_integer_EXPRESSION,
8025 -- [Link_Name =>] static_string_EXPRESSION);
8027 when Pragma_Export_Value =>
8029 Check_Arg_Order ((Name_Value, Name_Link_Name));
8030 Check_Arg_Count (2);
8032 Check_Optional_Identifier (Arg1, Name_Value);
8033 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8035 Check_Optional_Identifier (Arg2, Name_Link_Name);
8036 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8038 -----------------------------
8039 -- Export_Valued_Procedure --
8040 -----------------------------
8042 -- pragma Export_Valued_Procedure (
8043 -- [Internal =>] LOCAL_NAME
8044 -- [, [External =>] EXTERNAL_SYMBOL,]
8045 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8046 -- [, [Mechanism =>] MECHANISM]);
8048 -- EXTERNAL_SYMBOL ::=
8050 -- | static_string_EXPRESSION
8052 -- PARAMETER_TYPES ::=
8054 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8056 -- TYPE_DESIGNATOR ::=
8058 -- | subtype_Name ' Access
8062 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8064 -- MECHANISM_ASSOCIATION ::=
8065 -- [formal_parameter_NAME =>] MECHANISM_NAME
8067 -- MECHANISM_NAME ::=
8070 -- | Descriptor [([Class =>] CLASS_NAME)]
8072 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8074 when Pragma_Export_Valued_Procedure =>
8075 Export_Valued_Procedure : declare
8076 Args : Args_List (1 .. 4);
8077 Names : constant Name_List (1 .. 4) := (
8080 Name_Parameter_Types,
8083 Internal : Node_Id renames Args (1);
8084 External : Node_Id renames Args (2);
8085 Parameter_Types : Node_Id renames Args (3);
8086 Mechanism : Node_Id renames Args (4);
8090 Gather_Associations (Names, Args);
8091 Process_Extended_Import_Export_Subprogram_Pragma (
8092 Arg_Internal => Internal,
8093 Arg_External => External,
8094 Arg_Parameter_Types => Parameter_Types,
8095 Arg_Mechanism => Mechanism);
8096 end Export_Valued_Procedure;
8102 -- pragma Extend_System ([Name =>] Identifier);
8104 when Pragma_Extend_System => Extend_System : declare
8107 Check_Valid_Configuration_Pragma;
8108 Check_Arg_Count (1);
8109 Check_Optional_Identifier (Arg1, Name_Name);
8110 Check_Arg_Is_Identifier (Arg1);
8112 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8115 and then Name_Buffer (1 .. 4) = "aux_"
8117 if Present (System_Extend_Pragma_Arg) then
8118 if Chars (Get_Pragma_Arg (Arg1)) =
8119 Chars (Expression (System_Extend_Pragma_Arg))
8123 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8124 Error_Pragma ("pragma% conflicts with that #");
8128 System_Extend_Pragma_Arg := Arg1;
8130 if not GNAT_Mode then
8131 System_Extend_Unit := Arg1;
8135 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8139 ------------------------
8140 -- Extensions_Allowed --
8141 ------------------------
8143 -- pragma Extensions_Allowed (ON | OFF);
8145 when Pragma_Extensions_Allowed =>
8147 Check_Arg_Count (1);
8148 Check_No_Identifiers;
8149 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8151 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8152 Extensions_Allowed := True;
8153 Ada_Version := Ada_Version_Type'Last;
8156 Extensions_Allowed := False;
8157 Ada_Version := Ada_Version_Explicit;
8164 -- pragma External (
8165 -- [ Convention =>] convention_IDENTIFIER,
8166 -- [ Entity =>] local_NAME
8167 -- [, [External_Name =>] static_string_EXPRESSION ]
8168 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8170 when Pragma_External => External : declare
8174 pragma Warnings (Off, C);
8183 Check_At_Least_N_Arguments (2);
8184 Check_At_Most_N_Arguments (4);
8185 Process_Convention (C, Def_Id);
8186 Note_Possible_Modification
8187 (Get_Pragma_Arg (Arg2), Sure => False);
8188 Process_Interface_Name (Def_Id, Arg3, Arg4);
8189 Set_Exported (Def_Id, Arg2);
8192 --------------------------
8193 -- External_Name_Casing --
8194 --------------------------
8196 -- pragma External_Name_Casing (
8197 -- UPPERCASE | LOWERCASE
8198 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8200 when Pragma_External_Name_Casing => External_Name_Casing : declare
8203 Check_No_Identifiers;
8205 if Arg_Count = 2 then
8207 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8209 case Chars (Get_Pragma_Arg (Arg2)) is
8211 Opt.External_Name_Exp_Casing := As_Is;
8213 when Name_Uppercase =>
8214 Opt.External_Name_Exp_Casing := Uppercase;
8216 when Name_Lowercase =>
8217 Opt.External_Name_Exp_Casing := Lowercase;
8224 Check_Arg_Count (1);
8227 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8229 case Chars (Get_Pragma_Arg (Arg1)) is
8230 when Name_Uppercase =>
8231 Opt.External_Name_Imp_Casing := Uppercase;
8233 when Name_Lowercase =>
8234 Opt.External_Name_Imp_Casing := Lowercase;
8239 end External_Name_Casing;
8241 --------------------------
8242 -- Favor_Top_Level --
8243 --------------------------
8245 -- pragma Favor_Top_Level (type_NAME);
8247 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8248 Named_Entity : Entity_Id;
8252 Check_No_Identifiers;
8253 Check_Arg_Count (1);
8254 Check_Arg_Is_Local_Name (Arg1);
8255 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8257 -- If it's an access-to-subprogram type (in particular, not a
8258 -- subtype), set the flag on that type.
8260 if Is_Access_Subprogram_Type (Named_Entity) then
8262 Set_Can_Use_Internal_Rep (Named_Entity, False);
8265 -- Otherwise it's an error (name denotes the wrong sort of entity)
8269 ("access-to-subprogram type expected",
8270 Get_Pragma_Arg (Arg1));
8272 end Favor_Top_Level;
8278 -- pragma Fast_Math;
8280 when Pragma_Fast_Math =>
8282 Check_No_Identifiers;
8283 Check_Valid_Configuration_Pragma;
8286 ---------------------------
8287 -- Finalize_Storage_Only --
8288 ---------------------------
8290 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8292 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8293 Assoc : constant Node_Id := Arg1;
8294 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8299 Check_No_Identifiers;
8300 Check_Arg_Count (1);
8301 Check_Arg_Is_Local_Name (Arg1);
8303 Find_Type (Type_Id);
8304 Typ := Entity (Type_Id);
8307 or else Rep_Item_Too_Early (Typ, N)
8311 Typ := Underlying_Type (Typ);
8314 if not Is_Controlled (Typ) then
8315 Error_Pragma ("pragma% must specify controlled type");
8318 Check_First_Subtype (Arg1);
8320 if Finalize_Storage_Only (Typ) then
8321 Error_Pragma ("duplicate pragma%, only one allowed");
8323 elsif not Rep_Item_Too_Late (Typ, N) then
8324 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8326 end Finalize_Storage;
8328 --------------------------
8329 -- Float_Representation --
8330 --------------------------
8332 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8334 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8336 when Pragma_Float_Representation => Float_Representation : declare
8344 if Arg_Count = 1 then
8345 Check_Valid_Configuration_Pragma;
8347 Check_Arg_Count (2);
8348 Check_Optional_Identifier (Arg2, Name_Entity);
8349 Check_Arg_Is_Local_Name (Arg2);
8352 Check_No_Identifier (Arg1);
8353 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8355 if not OpenVMS_On_Target then
8356 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8358 ("?pragma% ignored (applies only to Open'V'M'S)");
8364 -- One argument case
8366 if Arg_Count = 1 then
8367 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8368 if Opt.Float_Format = 'I' then
8369 Error_Pragma ("'I'E'E'E format previously specified");
8372 Opt.Float_Format := 'V';
8375 if Opt.Float_Format = 'V' then
8376 Error_Pragma ("'V'A'X format previously specified");
8379 Opt.Float_Format := 'I';
8382 Set_Standard_Fpt_Formats;
8384 -- Two argument case
8387 Argx := Get_Pragma_Arg (Arg2);
8389 if not Is_Entity_Name (Argx)
8390 or else not Is_Floating_Point_Type (Entity (Argx))
8393 ("second argument of% pragma must be floating-point type",
8397 Ent := Entity (Argx);
8398 Digs := UI_To_Int (Digits_Value (Ent));
8400 -- Two arguments, VAX_Float case
8402 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8404 when 6 => Set_F_Float (Ent);
8405 when 9 => Set_D_Float (Ent);
8406 when 15 => Set_G_Float (Ent);
8410 ("wrong digits value, must be 6,9 or 15", Arg2);
8413 -- Two arguments, IEEE_Float case
8417 when 6 => Set_IEEE_Short (Ent);
8418 when 15 => Set_IEEE_Long (Ent);
8422 ("wrong digits value, must be 6 or 15", Arg2);
8426 end Float_Representation;
8432 -- pragma Ident (static_string_EXPRESSION)
8434 -- Note: pragma Comment shares this processing. Pragma Comment is
8435 -- identical to Ident, except that the restriction of the argument to
8436 -- 31 characters and the placement restrictions are not enforced for
8439 when Pragma_Ident | Pragma_Comment => Ident : declare
8444 Check_Arg_Count (1);
8445 Check_No_Identifiers;
8446 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8449 -- For pragma Ident, preserve DEC compatibility by requiring the
8450 -- pragma to appear in a declarative part or package spec.
8452 if Prag_Id = Pragma_Ident then
8453 Check_Is_In_Decl_Part_Or_Package_Spec;
8456 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8463 GP := Parent (Parent (N));
8465 if Nkind_In (GP, N_Package_Declaration,
8466 N_Generic_Package_Declaration)
8471 -- If we have a compilation unit, then record the ident value,
8472 -- checking for improper duplication.
8474 if Nkind (GP) = N_Compilation_Unit then
8475 CS := Ident_String (Current_Sem_Unit);
8477 if Present (CS) then
8479 -- For Ident, we do not permit multiple instances
8481 if Prag_Id = Pragma_Ident then
8482 Error_Pragma ("duplicate% pragma not permitted");
8484 -- For Comment, we concatenate the string, unless we want
8485 -- to preserve the tree structure for ASIS.
8487 elsif not ASIS_Mode then
8488 Start_String (Strval (CS));
8489 Store_String_Char (' ');
8490 Store_String_Chars (Strval (Str));
8491 Set_Strval (CS, End_String);
8495 -- In VMS, the effect of IDENT is achieved by passing
8496 -- --identification=name as a --for-linker switch.
8498 if OpenVMS_On_Target then
8501 ("--for-linker=--identification=");
8502 String_To_Name_Buffer (Strval (Str));
8503 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8505 -- Only the last processed IDENT is saved. The main
8506 -- purpose is so an IDENT associated with a main
8507 -- procedure will be used in preference to an IDENT
8508 -- associated with a with'd package.
8510 Replace_Linker_Option_String
8511 (End_String, "--for-linker=--identification=");
8514 Set_Ident_String (Current_Sem_Unit, Str);
8517 -- For subunits, we just ignore the Ident, since in GNAT these
8518 -- are not separate object files, and hence not separate units
8519 -- in the unit table.
8521 elsif Nkind (GP) = N_Subunit then
8524 -- Otherwise we have a misplaced pragma Ident, but we ignore
8525 -- this if we are in an instantiation, since it comes from
8526 -- a generic, and has no relevance to the instantiation.
8528 elsif Prag_Id = Pragma_Ident then
8529 if Instantiation_Location (Loc) = No_Location then
8530 Error_Pragma ("pragma% only allowed at outer level");
8540 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8541 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8543 when Pragma_Implemented => Implemented : declare
8544 Proc_Id : Entity_Id;
8549 Check_Arg_Count (2);
8550 Check_No_Identifiers;
8551 Check_Arg_Is_Identifier (Arg1);
8552 Check_Arg_Is_Local_Name (Arg1);
8554 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8556 -- Extract the name of the local procedure
8558 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8560 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8561 -- primitive procedure of a synchronized tagged type.
8563 if Ekind (Proc_Id) = E_Procedure
8564 and then Is_Primitive (Proc_Id)
8565 and then Present (First_Formal (Proc_Id))
8567 Typ := Etype (First_Formal (Proc_Id));
8569 if Is_Tagged_Type (Typ)
8572 -- Check for a protected, a synchronized or a task interface
8574 ((Is_Interface (Typ)
8575 and then Is_Synchronized_Interface (Typ))
8577 -- Check for a protected type or a task type that implements
8581 (Is_Concurrent_Record_Type (Typ)
8582 and then Present (Interfaces (Typ)))
8584 -- Check for a private record extension with keyword
8588 (Ekind_In (Typ, E_Record_Type_With_Private,
8589 E_Record_Subtype_With_Private)
8590 and then Synchronized_Present (Parent (Typ))))
8595 ("controlling formal must be of synchronized " &
8596 "tagged type", Arg1);
8600 -- Procedures declared inside a protected type must be accepted
8602 elsif Ekind (Proc_Id) = E_Procedure
8603 and then Is_Protected_Type (Scope (Proc_Id))
8607 -- The first argument is not a primitive procedure
8611 ("pragma % must be applied to a primitive procedure", Arg1);
8615 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8616 -- By_Protected_Procedure to the primitive procedure of a task
8619 if Chars (Arg2) = Name_By_Protected_Procedure
8620 and then Is_Interface (Typ)
8621 and then Is_Task_Interface (Typ)
8624 ("implementation kind By_Protected_Procedure cannot be " &
8625 "applied to a task interface primitive", Arg2);
8629 Record_Rep_Item (Proc_Id, N);
8632 ----------------------
8633 -- Implicit_Packing --
8634 ----------------------
8636 -- pragma Implicit_Packing;
8638 when Pragma_Implicit_Packing =>
8640 Check_Arg_Count (0);
8641 Implicit_Packing := True;
8648 -- [Convention =>] convention_IDENTIFIER,
8649 -- [Entity =>] local_NAME
8650 -- [, [External_Name =>] static_string_EXPRESSION ]
8651 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8653 when Pragma_Import =>
8654 Check_Ada_83_Warning;
8660 Check_At_Least_N_Arguments (2);
8661 Check_At_Most_N_Arguments (4);
8662 Process_Import_Or_Interface;
8664 ----------------------
8665 -- Import_Exception --
8666 ----------------------
8668 -- pragma Import_Exception (
8669 -- [Internal =>] LOCAL_NAME
8670 -- [, [External =>] EXTERNAL_SYMBOL]
8671 -- [, [Form =>] Ada | VMS]
8672 -- [, [Code =>] static_integer_EXPRESSION]);
8674 when Pragma_Import_Exception => Import_Exception : declare
8675 Args : Args_List (1 .. 4);
8676 Names : constant Name_List (1 .. 4) := (
8682 Internal : Node_Id renames Args (1);
8683 External : Node_Id renames Args (2);
8684 Form : Node_Id renames Args (3);
8685 Code : Node_Id renames Args (4);
8689 Gather_Associations (Names, Args);
8691 if Present (External) and then Present (Code) then
8693 ("cannot give both External and Code options for pragma%");
8696 Process_Extended_Import_Export_Exception_Pragma (
8697 Arg_Internal => Internal,
8698 Arg_External => External,
8702 if not Is_VMS_Exception (Entity (Internal)) then
8703 Set_Imported (Entity (Internal));
8705 end Import_Exception;
8707 ---------------------
8708 -- Import_Function --
8709 ---------------------
8711 -- pragma Import_Function (
8712 -- [Internal =>] LOCAL_NAME,
8713 -- [, [External =>] EXTERNAL_SYMBOL]
8714 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8715 -- [, [Result_Type =>] SUBTYPE_MARK]
8716 -- [, [Mechanism =>] MECHANISM]
8717 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8718 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8720 -- EXTERNAL_SYMBOL ::=
8722 -- | static_string_EXPRESSION
8724 -- PARAMETER_TYPES ::=
8726 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8728 -- TYPE_DESIGNATOR ::=
8730 -- | subtype_Name ' Access
8734 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8736 -- MECHANISM_ASSOCIATION ::=
8737 -- [formal_parameter_NAME =>] MECHANISM_NAME
8739 -- MECHANISM_NAME ::=
8742 -- | Descriptor [([Class =>] CLASS_NAME)]
8744 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8746 when Pragma_Import_Function => Import_Function : declare
8747 Args : Args_List (1 .. 7);
8748 Names : constant Name_List (1 .. 7) := (
8751 Name_Parameter_Types,
8754 Name_Result_Mechanism,
8755 Name_First_Optional_Parameter);
8757 Internal : Node_Id renames Args (1);
8758 External : Node_Id renames Args (2);
8759 Parameter_Types : Node_Id renames Args (3);
8760 Result_Type : Node_Id renames Args (4);
8761 Mechanism : Node_Id renames Args (5);
8762 Result_Mechanism : Node_Id renames Args (6);
8763 First_Optional_Parameter : Node_Id renames Args (7);
8767 Gather_Associations (Names, Args);
8768 Process_Extended_Import_Export_Subprogram_Pragma (
8769 Arg_Internal => Internal,
8770 Arg_External => External,
8771 Arg_Parameter_Types => Parameter_Types,
8772 Arg_Result_Type => Result_Type,
8773 Arg_Mechanism => Mechanism,
8774 Arg_Result_Mechanism => Result_Mechanism,
8775 Arg_First_Optional_Parameter => First_Optional_Parameter);
8776 end Import_Function;
8782 -- pragma Import_Object (
8783 -- [Internal =>] LOCAL_NAME
8784 -- [, [External =>] EXTERNAL_SYMBOL]
8785 -- [, [Size =>] EXTERNAL_SYMBOL]);
8787 -- EXTERNAL_SYMBOL ::=
8789 -- | static_string_EXPRESSION
8791 when Pragma_Import_Object => Import_Object : declare
8792 Args : Args_List (1 .. 3);
8793 Names : constant Name_List (1 .. 3) := (
8798 Internal : Node_Id renames Args (1);
8799 External : Node_Id renames Args (2);
8800 Size : Node_Id renames Args (3);
8804 Gather_Associations (Names, Args);
8805 Process_Extended_Import_Export_Object_Pragma (
8806 Arg_Internal => Internal,
8807 Arg_External => External,
8811 ----------------------
8812 -- Import_Procedure --
8813 ----------------------
8815 -- pragma Import_Procedure (
8816 -- [Internal =>] LOCAL_NAME
8817 -- [, [External =>] EXTERNAL_SYMBOL]
8818 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8819 -- [, [Mechanism =>] MECHANISM]
8820 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8822 -- EXTERNAL_SYMBOL ::=
8824 -- | static_string_EXPRESSION
8826 -- PARAMETER_TYPES ::=
8828 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8830 -- TYPE_DESIGNATOR ::=
8832 -- | subtype_Name ' Access
8836 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8838 -- MECHANISM_ASSOCIATION ::=
8839 -- [formal_parameter_NAME =>] MECHANISM_NAME
8841 -- MECHANISM_NAME ::=
8844 -- | Descriptor [([Class =>] CLASS_NAME)]
8846 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8848 when Pragma_Import_Procedure => Import_Procedure : declare
8849 Args : Args_List (1 .. 5);
8850 Names : constant Name_List (1 .. 5) := (
8853 Name_Parameter_Types,
8855 Name_First_Optional_Parameter);
8857 Internal : Node_Id renames Args (1);
8858 External : Node_Id renames Args (2);
8859 Parameter_Types : Node_Id renames Args (3);
8860 Mechanism : Node_Id renames Args (4);
8861 First_Optional_Parameter : Node_Id renames Args (5);
8865 Gather_Associations (Names, Args);
8866 Process_Extended_Import_Export_Subprogram_Pragma (
8867 Arg_Internal => Internal,
8868 Arg_External => External,
8869 Arg_Parameter_Types => Parameter_Types,
8870 Arg_Mechanism => Mechanism,
8871 Arg_First_Optional_Parameter => First_Optional_Parameter);
8872 end Import_Procedure;
8874 -----------------------------
8875 -- Import_Valued_Procedure --
8876 -----------------------------
8878 -- pragma Import_Valued_Procedure (
8879 -- [Internal =>] LOCAL_NAME
8880 -- [, [External =>] EXTERNAL_SYMBOL]
8881 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8882 -- [, [Mechanism =>] MECHANISM]
8883 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8885 -- EXTERNAL_SYMBOL ::=
8887 -- | static_string_EXPRESSION
8889 -- PARAMETER_TYPES ::=
8891 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8893 -- TYPE_DESIGNATOR ::=
8895 -- | subtype_Name ' Access
8899 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8901 -- MECHANISM_ASSOCIATION ::=
8902 -- [formal_parameter_NAME =>] MECHANISM_NAME
8904 -- MECHANISM_NAME ::=
8907 -- | Descriptor [([Class =>] CLASS_NAME)]
8909 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8911 when Pragma_Import_Valued_Procedure =>
8912 Import_Valued_Procedure : declare
8913 Args : Args_List (1 .. 5);
8914 Names : constant Name_List (1 .. 5) := (
8917 Name_Parameter_Types,
8919 Name_First_Optional_Parameter);
8921 Internal : Node_Id renames Args (1);
8922 External : Node_Id renames Args (2);
8923 Parameter_Types : Node_Id renames Args (3);
8924 Mechanism : Node_Id renames Args (4);
8925 First_Optional_Parameter : Node_Id renames Args (5);
8929 Gather_Associations (Names, Args);
8930 Process_Extended_Import_Export_Subprogram_Pragma (
8931 Arg_Internal => Internal,
8932 Arg_External => External,
8933 Arg_Parameter_Types => Parameter_Types,
8934 Arg_Mechanism => Mechanism,
8935 Arg_First_Optional_Parameter => First_Optional_Parameter);
8936 end Import_Valued_Procedure;
8942 -- pragma Independent (LOCAL_NAME);
8944 when Pragma_Independent => Independent : declare
8951 Check_Ada_83_Warning;
8953 Check_No_Identifiers;
8954 Check_Arg_Count (1);
8955 Check_Arg_Is_Local_Name (Arg1);
8956 E_Id := Get_Pragma_Arg (Arg1);
8958 if Etype (E_Id) = Any_Type then
8963 D := Declaration_Node (E);
8966 -- Check duplicate before we chain ourselves!
8968 Check_Duplicate_Pragma (E);
8970 -- Check appropriate entity
8973 if Rep_Item_Too_Early (E, N)
8975 Rep_Item_Too_Late (E, N)
8979 Check_First_Subtype (Arg1);
8982 elsif K = N_Object_Declaration
8983 or else (K = N_Component_Declaration
8984 and then Original_Record_Component (E) = E)
8986 if Rep_Item_Too_Late (E, N) then
8992 ("inappropriate entity for pragma%", Arg1);
8995 Independence_Checks.Append ((N, E));
8998 ----------------------------
8999 -- Independent_Components --
9000 ----------------------------
9002 -- pragma Atomic_Components (array_LOCAL_NAME);
9004 -- This processing is shared by Volatile_Components
9006 when Pragma_Independent_Components => Independent_Components : declare
9013 Check_Ada_83_Warning;
9015 Check_No_Identifiers;
9016 Check_Arg_Count (1);
9017 Check_Arg_Is_Local_Name (Arg1);
9018 E_Id := Get_Pragma_Arg (Arg1);
9020 if Etype (E_Id) = Any_Type then
9026 -- Check duplicate before we chain ourselves!
9028 Check_Duplicate_Pragma (E);
9030 -- Check appropriate entity
9032 if Rep_Item_Too_Early (E, N)
9034 Rep_Item_Too_Late (E, N)
9039 D := Declaration_Node (E);
9042 if (K = N_Full_Type_Declaration
9043 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9045 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9046 and then Nkind (D) = N_Object_Declaration
9047 and then Nkind (Object_Definition (D)) =
9048 N_Constrained_Array_Definition)
9050 Independence_Checks.Append ((N, E));
9053 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9055 end Independent_Components;
9057 ------------------------
9058 -- Initialize_Scalars --
9059 ------------------------
9061 -- pragma Initialize_Scalars;
9063 when Pragma_Initialize_Scalars =>
9065 Check_Arg_Count (0);
9066 Check_Valid_Configuration_Pragma;
9067 Check_Restriction (No_Initialize_Scalars, N);
9069 -- Initialize_Scalars creates false positives in CodePeer,
9070 -- so ignore this pragma in this mode.
9072 if not Restriction_Active (No_Initialize_Scalars)
9073 and then not CodePeer_Mode
9075 Init_Or_Norm_Scalars := True;
9076 Initialize_Scalars := True;
9083 -- pragma Inline ( NAME {, NAME} );
9085 when Pragma_Inline =>
9087 -- Pragma is active if inlining option is active
9089 Process_Inline (Inline_Active);
9095 -- pragma Inline_Always ( NAME {, NAME} );
9097 when Pragma_Inline_Always =>
9100 -- Pragma always active unless in CodePeer mode, since this causes
9101 -- walk order issues.
9103 if not CodePeer_Mode then
9104 Process_Inline (True);
9107 --------------------
9108 -- Inline_Generic --
9109 --------------------
9111 -- pragma Inline_Generic (NAME {, NAME});
9113 when Pragma_Inline_Generic =>
9115 Process_Generic_List;
9117 ----------------------
9118 -- Inspection_Point --
9119 ----------------------
9121 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9123 when Pragma_Inspection_Point => Inspection_Point : declare
9128 if Arg_Count > 0 then
9131 Exp := Get_Pragma_Arg (Arg);
9134 if not Is_Entity_Name (Exp)
9135 or else not Is_Object (Entity (Exp))
9137 Error_Pragma_Arg ("object name required", Arg);
9144 end Inspection_Point;
9150 -- pragma Interface (
9151 -- [ Convention =>] convention_IDENTIFIER,
9152 -- [ Entity =>] local_NAME
9153 -- [, [External_Name =>] static_string_EXPRESSION ]
9154 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9156 when Pragma_Interface =>
9163 Check_At_Least_N_Arguments (2);
9164 Check_At_Most_N_Arguments (4);
9165 Process_Import_Or_Interface;
9167 -- In Ada 2005, the permission to use Interface (a reserved word)
9168 -- as a pragma name is considered an obsolescent feature.
9170 if Ada_Version >= Ada_2005 then
9172 (No_Obsolescent_Features, Pragma_Identifier (N));
9175 --------------------
9176 -- Interface_Name --
9177 --------------------
9179 -- pragma Interface_Name (
9180 -- [ Entity =>] local_NAME
9181 -- [,[External_Name =>] static_string_EXPRESSION ]
9182 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9184 when Pragma_Interface_Name => Interface_Name : declare
9193 ((Name_Entity, Name_External_Name, Name_Link_Name));
9194 Check_At_Least_N_Arguments (2);
9195 Check_At_Most_N_Arguments (3);
9196 Id := Get_Pragma_Arg (Arg1);
9199 if not Is_Entity_Name (Id) then
9201 ("first argument for pragma% must be entity name", Arg1);
9202 elsif Etype (Id) = Any_Type then
9205 Def_Id := Entity (Id);
9208 -- Special DEC-compatible processing for the object case, forces
9209 -- object to be imported.
9211 if Ekind (Def_Id) = E_Variable then
9212 Kill_Size_Check_Code (Def_Id);
9213 Note_Possible_Modification (Id, Sure => False);
9215 -- Initialization is not allowed for imported variable
9217 if Present (Expression (Parent (Def_Id)))
9218 and then Comes_From_Source (Expression (Parent (Def_Id)))
9220 Error_Msg_Sloc := Sloc (Def_Id);
9222 ("no initialization allowed for declaration of& #",
9226 -- For compatibility, support VADS usage of providing both
9227 -- pragmas Interface and Interface_Name to obtain the effect
9228 -- of a single Import pragma.
9230 if Is_Imported (Def_Id)
9231 and then Present (First_Rep_Item (Def_Id))
9232 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9234 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9238 Set_Imported (Def_Id);
9241 Set_Is_Public (Def_Id);
9242 Process_Interface_Name (Def_Id, Arg2, Arg3);
9245 -- Otherwise must be subprogram
9247 elsif not Is_Subprogram (Def_Id) then
9249 ("argument of pragma% is not subprogram", Arg1);
9252 Check_At_Most_N_Arguments (3);
9256 -- Loop through homonyms
9259 Def_Id := Get_Base_Subprogram (Hom_Id);
9261 if Is_Imported (Def_Id) then
9262 Process_Interface_Name (Def_Id, Arg2, Arg3);
9266 exit when From_Aspect_Specification (N);
9267 Hom_Id := Homonym (Hom_Id);
9269 exit when No (Hom_Id)
9270 or else Scope (Hom_Id) /= Current_Scope;
9275 ("argument of pragma% is not imported subprogram",
9281 -----------------------
9282 -- Interrupt_Handler --
9283 -----------------------
9285 -- pragma Interrupt_Handler (handler_NAME);
9287 when Pragma_Interrupt_Handler =>
9288 Check_Ada_83_Warning;
9289 Check_Arg_Count (1);
9290 Check_No_Identifiers;
9292 if No_Run_Time_Mode then
9293 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9295 Check_Interrupt_Or_Attach_Handler;
9296 Process_Interrupt_Or_Attach_Handler;
9299 ------------------------
9300 -- Interrupt_Priority --
9301 ------------------------
9303 -- pragma Interrupt_Priority [(EXPRESSION)];
9305 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9306 P : constant Node_Id := Parent (N);
9310 Check_Ada_83_Warning;
9312 if Arg_Count /= 0 then
9313 Arg := Get_Pragma_Arg (Arg1);
9314 Check_Arg_Count (1);
9315 Check_No_Identifiers;
9317 -- The expression must be analyzed in the special manner
9318 -- described in "Handling of Default and Per-Object
9319 -- Expressions" in sem.ads.
9321 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9324 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9328 elsif Has_Pragma_Priority (P) then
9329 Error_Pragma ("duplicate pragma% not allowed");
9332 Set_Has_Pragma_Priority (P, True);
9333 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9335 end Interrupt_Priority;
9337 ---------------------
9338 -- Interrupt_State --
9339 ---------------------
9341 -- pragma Interrupt_State (
9342 -- [Name =>] INTERRUPT_ID,
9343 -- [State =>] INTERRUPT_STATE);
9345 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9346 -- INTERRUPT_STATE => System | Runtime | User
9348 -- Note: if the interrupt id is given as an identifier, then it must
9349 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9350 -- given as a static integer expression which must be in the range of
9351 -- Ada.Interrupts.Interrupt_ID.
9353 when Pragma_Interrupt_State => Interrupt_State : declare
9355 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9356 -- This is the entity Ada.Interrupts.Interrupt_ID;
9358 State_Type : Character;
9359 -- Set to 's'/'r'/'u' for System/Runtime/User
9362 -- Index to entry in Interrupt_States table
9365 -- Value of interrupt
9367 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9368 -- The first argument to the pragma
9370 Int_Ent : Entity_Id;
9371 -- Interrupt entity in Ada.Interrupts.Names
9375 Check_Arg_Order ((Name_Name, Name_State));
9376 Check_Arg_Count (2);
9378 Check_Optional_Identifier (Arg1, Name_Name);
9379 Check_Optional_Identifier (Arg2, Name_State);
9380 Check_Arg_Is_Identifier (Arg2);
9382 -- First argument is identifier
9384 if Nkind (Arg1X) = N_Identifier then
9386 -- Search list of names in Ada.Interrupts.Names
9388 Int_Ent := First_Entity (RTE (RE_Names));
9390 if No (Int_Ent) then
9391 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9393 elsif Chars (Int_Ent) = Chars (Arg1X) then
9394 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9398 Next_Entity (Int_Ent);
9401 -- First argument is not an identifier, so it must be a static
9402 -- expression of type Ada.Interrupts.Interrupt_ID.
9405 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9406 Int_Val := Expr_Value (Arg1X);
9408 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9410 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9413 ("value not in range of type " &
9414 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9420 case Chars (Get_Pragma_Arg (Arg2)) is
9421 when Name_Runtime => State_Type := 'r';
9422 when Name_System => State_Type := 's';
9423 when Name_User => State_Type := 'u';
9426 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9429 -- Check if entry is already stored
9431 IST_Num := Interrupt_States.First;
9433 -- If entry not found, add it
9435 if IST_Num > Interrupt_States.Last then
9436 Interrupt_States.Append
9437 ((Interrupt_Number => UI_To_Int (Int_Val),
9438 Interrupt_State => State_Type,
9439 Pragma_Loc => Loc));
9442 -- Case of entry for the same entry
9444 elsif Int_Val = Interrupt_States.Table (IST_Num).
9447 -- If state matches, done, no need to make redundant entry
9450 State_Type = Interrupt_States.Table (IST_Num).
9453 -- Otherwise if state does not match, error
9456 Interrupt_States.Table (IST_Num).Pragma_Loc;
9458 ("state conflicts with that given #", Arg2);
9462 IST_Num := IST_Num + 1;
9464 end Interrupt_State;
9471 -- ([Entity =>] type_LOCAL_NAME,
9472 -- [Check =>] EXPRESSION
9473 -- [,[Message =>] String_Expression]);
9475 when Pragma_Invariant => Invariant : declare
9480 pragma Unreferenced (Discard);
9484 Check_At_Least_N_Arguments (2);
9485 Check_At_Most_N_Arguments (3);
9486 Check_Optional_Identifier (Arg1, Name_Entity);
9487 Check_Optional_Identifier (Arg2, Name_Check);
9489 if Arg_Count = 3 then
9490 Check_Optional_Identifier (Arg3, Name_Message);
9491 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9494 Check_Arg_Is_Local_Name (Arg1);
9496 Type_Id := Get_Pragma_Arg (Arg1);
9497 Find_Type (Type_Id);
9498 Typ := Entity (Type_Id);
9500 if Typ = Any_Type then
9503 elsif not Ekind_In (Typ, E_Private_Type,
9504 E_Record_Type_With_Private,
9505 E_Limited_Private_Type)
9508 ("pragma% only allowed for private type", Arg1);
9511 -- Note that the type has at least one invariant, and also that
9512 -- it has inheritable invariants if we have Invariant'Class.
9514 Set_Has_Invariants (Typ);
9516 if Class_Present (N) then
9517 Set_Has_Inheritable_Invariants (Typ);
9520 -- The remaining processing is simply to link the pragma on to
9521 -- the rep item chain, for processing when the type is frozen.
9522 -- This is accomplished by a call to Rep_Item_Too_Late.
9524 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9527 ----------------------
9528 -- Java_Constructor --
9529 ----------------------
9531 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9533 -- Also handles pragma CIL_Constructor
9535 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9536 Java_Constructor : declare
9537 Convention : Convention_Id;
9541 This_Formal : Entity_Id;
9545 Check_Arg_Count (1);
9546 Check_Optional_Identifier (Arg1, Name_Entity);
9547 Check_Arg_Is_Local_Name (Arg1);
9549 Id := Get_Pragma_Arg (Arg1);
9550 Find_Program_Unit_Name (Id);
9552 -- If we did not find the name, we are done
9554 if Etype (Id) = Any_Type then
9558 -- Check wrong use of pragma in wrong VM target
9560 if VM_Target = No_VM then
9563 elsif VM_Target = CLI_Target
9564 and then Prag_Id = Pragma_Java_Constructor
9566 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9568 elsif VM_Target = JVM_Target
9569 and then Prag_Id = Pragma_CIL_Constructor
9571 Error_Pragma ("must use pragma 'Java_'Constructor");
9575 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9576 when Pragma_Java_Constructor => Convention := Convention_Java;
9577 when others => null;
9580 Hom_Id := Entity (Id);
9582 -- Loop through homonyms
9585 Def_Id := Get_Base_Subprogram (Hom_Id);
9587 -- The constructor is required to be a function
9589 if Ekind (Def_Id) /= E_Function then
9590 if VM_Target = JVM_Target then
9592 ("pragma% requires function returning a " &
9593 "'Java access type", Def_Id);
9596 ("pragma% requires function returning a " &
9597 "'C'I'L access type", Def_Id);
9601 -- Check arguments: For tagged type the first formal must be
9602 -- named "this" and its type must be a named access type
9603 -- designating a class-wide tagged type that has convention
9604 -- CIL/Java. The first formal must also have a null default
9605 -- value. For example:
9607 -- type Typ is tagged ...
9608 -- type Ref is access all Typ;
9609 -- pragma Convention (CIL, Typ);
9611 -- function New_Typ (This : Ref) return Ref;
9612 -- function New_Typ (This : Ref; I : Integer) return Ref;
9613 -- pragma Cil_Constructor (New_Typ);
9615 -- Reason: The first formal must NOT be a primitive of the
9618 -- This rule also applies to constructors of delegates used
9619 -- to interface with standard target libraries. For example:
9621 -- type Delegate is access procedure ...
9622 -- pragma Import (CIL, Delegate, ...);
9624 -- function new_Delegate
9625 -- (This : Delegate := null; ... ) return Delegate;
9627 -- For value-types this rule does not apply.
9629 if not Is_Value_Type (Etype (Def_Id)) then
9630 if No (First_Formal (Def_Id)) then
9631 Error_Msg_Name_1 := Pname;
9632 Error_Msg_N ("% function must have parameters", Def_Id);
9636 -- In the JRE library we have several occurrences in which
9637 -- the "this" parameter is not the first formal.
9639 This_Formal := First_Formal (Def_Id);
9641 -- In the JRE library we have several occurrences in which
9642 -- the "this" parameter is not the first formal. Search for
9645 if VM_Target = JVM_Target then
9646 while Present (This_Formal)
9647 and then Get_Name_String (Chars (This_Formal)) /= "this"
9649 Next_Formal (This_Formal);
9652 if No (This_Formal) then
9653 This_Formal := First_Formal (Def_Id);
9657 -- Warning: The first parameter should be named "this".
9658 -- We temporarily allow it because we have the following
9659 -- case in the Java runtime (file s-osinte.ads) ???
9661 -- function new_Thread
9662 -- (Self_Id : System.Address) return Thread_Id;
9663 -- pragma Java_Constructor (new_Thread);
9665 if VM_Target = JVM_Target
9666 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9668 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9672 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9673 Error_Msg_Name_1 := Pname;
9675 ("first formal of % function must be named `this`",
9676 Parent (This_Formal));
9678 elsif not Is_Access_Type (Etype (This_Formal)) then
9679 Error_Msg_Name_1 := Pname;
9681 ("first formal of % function must be an access type",
9682 Parameter_Type (Parent (This_Formal)));
9684 -- For delegates the type of the first formal must be a
9685 -- named access-to-subprogram type (see previous example)
9687 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9688 and then Ekind (Etype (This_Formal))
9689 /= E_Access_Subprogram_Type
9691 Error_Msg_Name_1 := Pname;
9693 ("first formal of % function must be a named access" &
9694 " to subprogram type",
9695 Parameter_Type (Parent (This_Formal)));
9697 -- Warning: We should reject anonymous access types because
9698 -- the constructor must not be handled as a primitive of the
9699 -- tagged type. We temporarily allow it because this profile
9700 -- is currently generated by cil2ada???
9702 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9703 and then not Ekind_In (Etype (This_Formal),
9705 E_General_Access_Type,
9706 E_Anonymous_Access_Type)
9708 Error_Msg_Name_1 := Pname;
9710 ("first formal of % function must be a named access" &
9712 Parameter_Type (Parent (This_Formal)));
9714 elsif Atree.Convention
9715 (Designated_Type (Etype (This_Formal))) /= Convention
9717 Error_Msg_Name_1 := Pname;
9719 if Convention = Convention_Java then
9721 ("pragma% requires convention 'Cil in designated" &
9723 Parameter_Type (Parent (This_Formal)));
9726 ("pragma% requires convention 'Java in designated" &
9728 Parameter_Type (Parent (This_Formal)));
9731 elsif No (Expression (Parent (This_Formal)))
9732 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9734 Error_Msg_Name_1 := Pname;
9736 ("pragma% requires first formal with default `null`",
9737 Parameter_Type (Parent (This_Formal)));
9741 -- Check result type: the constructor must be a function
9743 -- * a value type (only allowed in the CIL compiler)
9744 -- * an access-to-subprogram type with convention Java/CIL
9745 -- * an access-type designating a type that has convention
9748 if Is_Value_Type (Etype (Def_Id)) then
9751 -- Access-to-subprogram type with convention Java/CIL
9753 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9754 if Atree.Convention (Etype (Def_Id)) /= Convention then
9755 if Convention = Convention_Java then
9757 ("pragma% requires function returning a " &
9758 "'Java access type", Arg1);
9760 pragma Assert (Convention = Convention_CIL);
9762 ("pragma% requires function returning a " &
9763 "'C'I'L access type", Arg1);
9767 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9768 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9769 E_General_Access_Type)
9772 (Designated_Type (Etype (Def_Id))) /= Convention
9774 Error_Msg_Name_1 := Pname;
9776 if Convention = Convention_Java then
9778 ("pragma% requires function returning a named" &
9779 "'Java access type", Arg1);
9782 ("pragma% requires function returning a named" &
9783 "'C'I'L access type", Arg1);
9788 Set_Is_Constructor (Def_Id);
9789 Set_Convention (Def_Id, Convention);
9790 Set_Is_Imported (Def_Id);
9792 exit when From_Aspect_Specification (N);
9793 Hom_Id := Homonym (Hom_Id);
9795 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9797 end Java_Constructor;
9799 ----------------------
9800 -- Java_Interface --
9801 ----------------------
9803 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9805 when Pragma_Java_Interface => Java_Interface : declare
9811 Check_Arg_Count (1);
9812 Check_Optional_Identifier (Arg1, Name_Entity);
9813 Check_Arg_Is_Local_Name (Arg1);
9815 Arg := Get_Pragma_Arg (Arg1);
9818 if Etype (Arg) = Any_Type then
9822 if not Is_Entity_Name (Arg)
9823 or else not Is_Type (Entity (Arg))
9825 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9828 Typ := Underlying_Type (Entity (Arg));
9830 -- For now simply check some of the semantic constraints on the
9831 -- type. This currently leaves out some restrictions on interface
9832 -- types, namely that the parent type must be java.lang.Object.Typ
9833 -- and that all primitives of the type should be declared
9836 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9837 Error_Pragma_Arg ("pragma% requires an abstract "
9838 & "tagged type", Arg1);
9840 elsif not Has_Discriminants (Typ)
9841 or else Ekind (Etype (First_Discriminant (Typ)))
9842 /= E_Anonymous_Access_Type
9844 not Is_Class_Wide_Type
9845 (Designated_Type (Etype (First_Discriminant (Typ))))
9848 ("type must have a class-wide access discriminant", Arg1);
9856 -- pragma Keep_Names ([On => ] local_NAME);
9858 when Pragma_Keep_Names => Keep_Names : declare
9863 Check_Arg_Count (1);
9864 Check_Optional_Identifier (Arg1, Name_On);
9865 Check_Arg_Is_Local_Name (Arg1);
9867 Arg := Get_Pragma_Arg (Arg1);
9870 if Etype (Arg) = Any_Type then
9874 if not Is_Entity_Name (Arg)
9875 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
9878 ("pragma% requires a local enumeration type", Arg1);
9881 Set_Discard_Names (Entity (Arg), False);
9888 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
9890 when Pragma_License =>
9892 Check_Arg_Count (1);
9893 Check_No_Identifiers;
9894 Check_Valid_Configuration_Pragma;
9895 Check_Arg_Is_Identifier (Arg1);
9898 Sind : constant Source_File_Index :=
9899 Source_Index (Current_Sem_Unit);
9902 case Chars (Get_Pragma_Arg (Arg1)) is
9904 Set_License (Sind, GPL);
9906 when Name_Modified_GPL =>
9907 Set_License (Sind, Modified_GPL);
9909 when Name_Restricted =>
9910 Set_License (Sind, Restricted);
9912 when Name_Unrestricted =>
9913 Set_License (Sind, Unrestricted);
9916 Error_Pragma_Arg ("invalid license name", Arg1);
9924 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
9926 when Pragma_Link_With => Link_With : declare
9932 if Operating_Mode = Generate_Code
9933 and then In_Extended_Main_Source_Unit (N)
9935 Check_At_Least_N_Arguments (1);
9936 Check_No_Identifiers;
9937 Check_Is_In_Decl_Part_Or_Package_Spec;
9938 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9942 while Present (Arg) loop
9943 Check_Arg_Is_Static_Expression (Arg, Standard_String);
9945 -- Store argument, converting sequences of spaces to a
9946 -- single null character (this is one of the differences
9947 -- in processing between Link_With and Linker_Options).
9950 C : constant Char_Code := Get_Char_Code (' ');
9951 S : constant String_Id :=
9952 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
9953 L : constant Nat := String_Length (S);
9956 procedure Skip_Spaces;
9957 -- Advance F past any spaces
9963 procedure Skip_Spaces is
9965 while F <= L and then Get_String_Char (S, F) = C loop
9970 -- Start of processing for Arg_Store
9973 Skip_Spaces; -- skip leading spaces
9975 -- Loop through characters, changing any embedded
9976 -- sequence of spaces to a single null character (this
9977 -- is how Link_With/Linker_Options differ)
9980 if Get_String_Char (S, F) = C then
9983 Store_String_Char (ASCII.NUL);
9986 Store_String_Char (Get_String_Char (S, F));
9994 if Present (Arg) then
9995 Store_String_Char (ASCII.NUL);
9999 Store_Linker_Option_String (End_String);
10007 -- pragma Linker_Alias (
10008 -- [Entity =>] LOCAL_NAME
10009 -- [Target =>] static_string_EXPRESSION);
10011 when Pragma_Linker_Alias =>
10013 Check_Arg_Order ((Name_Entity, Name_Target));
10014 Check_Arg_Count (2);
10015 Check_Optional_Identifier (Arg1, Name_Entity);
10016 Check_Optional_Identifier (Arg2, Name_Target);
10017 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10018 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10020 -- The only processing required is to link this item on to the
10021 -- list of rep items for the given entity. This is accomplished
10022 -- by the call to Rep_Item_Too_Late (when no error is detected
10023 -- and False is returned).
10025 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10028 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10031 ------------------------
10032 -- Linker_Constructor --
10033 ------------------------
10035 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10037 -- Code is shared with Linker_Destructor
10039 -----------------------
10040 -- Linker_Destructor --
10041 -----------------------
10043 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10045 when Pragma_Linker_Constructor |
10046 Pragma_Linker_Destructor =>
10047 Linker_Constructor : declare
10053 Check_Arg_Count (1);
10054 Check_No_Identifiers;
10055 Check_Arg_Is_Local_Name (Arg1);
10056 Arg1_X := Get_Pragma_Arg (Arg1);
10058 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10060 if not Is_Library_Level_Entity (Proc) then
10062 ("argument for pragma% must be library level entity", Arg1);
10065 -- The only processing required is to link this item on to the
10066 -- list of rep items for the given entity. This is accomplished
10067 -- by the call to Rep_Item_Too_Late (when no error is detected
10068 -- and False is returned).
10070 if Rep_Item_Too_Late (Proc, N) then
10073 Set_Has_Gigi_Rep_Item (Proc);
10075 end Linker_Constructor;
10077 --------------------
10078 -- Linker_Options --
10079 --------------------
10081 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10083 when Pragma_Linker_Options => Linker_Options : declare
10087 Check_Ada_83_Warning;
10088 Check_No_Identifiers;
10089 Check_Arg_Count (1);
10090 Check_Is_In_Decl_Part_Or_Package_Spec;
10091 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10092 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10095 while Present (Arg) loop
10096 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10097 Store_String_Char (ASCII.NUL);
10099 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10103 if Operating_Mode = Generate_Code
10104 and then In_Extended_Main_Source_Unit (N)
10106 Store_Linker_Option_String (End_String);
10108 end Linker_Options;
10110 --------------------
10111 -- Linker_Section --
10112 --------------------
10114 -- pragma Linker_Section (
10115 -- [Entity =>] LOCAL_NAME
10116 -- [Section =>] static_string_EXPRESSION);
10118 when Pragma_Linker_Section =>
10120 Check_Arg_Order ((Name_Entity, Name_Section));
10121 Check_Arg_Count (2);
10122 Check_Optional_Identifier (Arg1, Name_Entity);
10123 Check_Optional_Identifier (Arg2, Name_Section);
10124 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10125 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10127 -- This pragma applies only to objects
10129 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10130 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10133 -- The only processing required is to link this item on to the
10134 -- list of rep items for the given entity. This is accomplished
10135 -- by the call to Rep_Item_Too_Late (when no error is detected
10136 -- and False is returned).
10138 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10141 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10148 -- pragma List (On | Off)
10150 -- There is nothing to do here, since we did all the processing for
10151 -- this pragma in Par.Prag (so that it works properly even in syntax
10154 when Pragma_List =>
10157 --------------------
10158 -- Locking_Policy --
10159 --------------------
10161 -- pragma Locking_Policy (policy_IDENTIFIER);
10163 when Pragma_Locking_Policy => declare
10167 Check_Ada_83_Warning;
10168 Check_Arg_Count (1);
10169 Check_No_Identifiers;
10170 Check_Arg_Is_Locking_Policy (Arg1);
10171 Check_Valid_Configuration_Pragma;
10172 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10173 LP := Fold_Upper (Name_Buffer (1));
10175 if Locking_Policy /= ' '
10176 and then Locking_Policy /= LP
10178 Error_Msg_Sloc := Locking_Policy_Sloc;
10179 Error_Pragma ("locking policy incompatible with policy#");
10181 -- Set new policy, but always preserve System_Location since we
10182 -- like the error message with the run time name.
10185 Locking_Policy := LP;
10187 if Locking_Policy_Sloc /= System_Location then
10188 Locking_Policy_Sloc := Loc;
10197 -- pragma Long_Float (D_Float | G_Float);
10199 when Pragma_Long_Float =>
10201 Check_Valid_Configuration_Pragma;
10202 Check_Arg_Count (1);
10203 Check_No_Identifier (Arg1);
10204 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10206 if not OpenVMS_On_Target then
10207 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10212 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10213 if Opt.Float_Format_Long = 'G' then
10214 Error_Pragma ("G_Float previously specified");
10217 Opt.Float_Format_Long := 'D';
10219 -- G_Float case (this is the default, does not need overriding)
10222 if Opt.Float_Format_Long = 'D' then
10223 Error_Pragma ("D_Float previously specified");
10226 Opt.Float_Format_Long := 'G';
10229 Set_Standard_Fpt_Formats;
10231 -----------------------
10232 -- Machine_Attribute --
10233 -----------------------
10235 -- pragma Machine_Attribute (
10236 -- [Entity =>] LOCAL_NAME,
10237 -- [Attribute_Name =>] static_string_EXPRESSION
10238 -- [, [Info =>] static_EXPRESSION] );
10240 when Pragma_Machine_Attribute => Machine_Attribute : declare
10241 Def_Id : Entity_Id;
10245 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10247 if Arg_Count = 3 then
10248 Check_Optional_Identifier (Arg3, Name_Info);
10249 Check_Arg_Is_Static_Expression (Arg3);
10251 Check_Arg_Count (2);
10254 Check_Optional_Identifier (Arg1, Name_Entity);
10255 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10256 Check_Arg_Is_Local_Name (Arg1);
10257 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10258 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10260 if Is_Access_Type (Def_Id) then
10261 Def_Id := Designated_Type (Def_Id);
10264 if Rep_Item_Too_Early (Def_Id, N) then
10268 Def_Id := Underlying_Type (Def_Id);
10270 -- The only processing required is to link this item on to the
10271 -- list of rep items for the given entity. This is accomplished
10272 -- by the call to Rep_Item_Too_Late (when no error is detected
10273 -- and False is returned).
10275 if Rep_Item_Too_Late (Def_Id, N) then
10278 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10280 end Machine_Attribute;
10287 -- (MAIN_OPTION [, MAIN_OPTION]);
10290 -- [STACK_SIZE =>] static_integer_EXPRESSION
10291 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10292 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10294 when Pragma_Main => Main : declare
10295 Args : Args_List (1 .. 3);
10296 Names : constant Name_List (1 .. 3) := (
10298 Name_Task_Stack_Size_Default,
10299 Name_Time_Slicing_Enabled);
10305 Gather_Associations (Names, Args);
10307 for J in 1 .. 2 loop
10308 if Present (Args (J)) then
10309 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10313 if Present (Args (3)) then
10314 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10318 while Present (Nod) loop
10319 if Nkind (Nod) = N_Pragma
10320 and then Pragma_Name (Nod) = Name_Main
10322 Error_Msg_Name_1 := Pname;
10323 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10334 -- pragma Main_Storage
10335 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10337 -- MAIN_STORAGE_OPTION ::=
10338 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10339 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10341 when Pragma_Main_Storage => Main_Storage : declare
10342 Args : Args_List (1 .. 2);
10343 Names : constant Name_List (1 .. 2) := (
10344 Name_Working_Storage,
10351 Gather_Associations (Names, Args);
10353 for J in 1 .. 2 loop
10354 if Present (Args (J)) then
10355 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10359 Check_In_Main_Program;
10362 while Present (Nod) loop
10363 if Nkind (Nod) = N_Pragma
10364 and then Pragma_Name (Nod) = Name_Main_Storage
10366 Error_Msg_Name_1 := Pname;
10367 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10378 -- pragma Memory_Size (NUMERIC_LITERAL)
10380 when Pragma_Memory_Size =>
10383 -- Memory size is simply ignored
10385 Check_No_Identifiers;
10386 Check_Arg_Count (1);
10387 Check_Arg_Is_Integer_Literal (Arg1);
10395 -- The only correct use of this pragma is on its own in a file, in
10396 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10397 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10398 -- check for a file containing nothing but a No_Body pragma). If we
10399 -- attempt to process it during normal semantics processing, it means
10400 -- it was misplaced.
10402 when Pragma_No_Body =>
10410 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10412 when Pragma_No_Return => No_Return : declare
10420 Check_At_Least_N_Arguments (1);
10422 -- Loop through arguments of pragma
10425 while Present (Arg) loop
10426 Check_Arg_Is_Local_Name (Arg);
10427 Id := Get_Pragma_Arg (Arg);
10430 if not Is_Entity_Name (Id) then
10431 Error_Pragma_Arg ("entity name required", Arg);
10434 if Etype (Id) = Any_Type then
10438 -- Loop to find matching procedures
10443 and then Scope (E) = Current_Scope
10445 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10448 -- Set flag on any alias as well
10450 if Is_Overloadable (E) and then Present (Alias (E)) then
10451 Set_No_Return (Alias (E));
10457 exit when From_Aspect_Specification (N);
10462 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10473 -- pragma No_Run_Time;
10475 -- Note: this pragma is retained for backwards compatibility. See
10476 -- body of Rtsfind for full details on its handling.
10478 when Pragma_No_Run_Time =>
10480 Check_Valid_Configuration_Pragma;
10481 Check_Arg_Count (0);
10483 No_Run_Time_Mode := True;
10484 Configurable_Run_Time_Mode := True;
10486 -- Set Duration to 32 bits if word size is 32
10488 if Ttypes.System_Word_Size = 32 then
10489 Duration_32_Bits_On_Target := True;
10492 -- Set appropriate restrictions
10494 Set_Restriction (No_Finalization, N);
10495 Set_Restriction (No_Exception_Handlers, N);
10496 Set_Restriction (Max_Tasks, N, 0);
10497 Set_Restriction (No_Tasking, N);
10499 ------------------------
10500 -- No_Strict_Aliasing --
10501 ------------------------
10503 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10505 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10510 Check_At_Most_N_Arguments (1);
10512 if Arg_Count = 0 then
10513 Check_Valid_Configuration_Pragma;
10514 Opt.No_Strict_Aliasing := True;
10517 Check_Optional_Identifier (Arg2, Name_Entity);
10518 Check_Arg_Is_Local_Name (Arg1);
10519 E_Id := Entity (Get_Pragma_Arg (Arg1));
10521 if E_Id = Any_Type then
10523 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10524 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10527 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10529 end No_Strict_Aliasing;
10531 -----------------------
10532 -- Normalize_Scalars --
10533 -----------------------
10535 -- pragma Normalize_Scalars;
10537 when Pragma_Normalize_Scalars =>
10538 Check_Ada_83_Warning;
10539 Check_Arg_Count (0);
10540 Check_Valid_Configuration_Pragma;
10542 -- Normalize_Scalars creates false positives in CodePeer, so
10543 -- ignore this pragma in this mode.
10545 if not CodePeer_Mode then
10546 Normalize_Scalars := True;
10547 Init_Or_Norm_Scalars := True;
10554 -- pragma Obsolescent;
10556 -- pragma Obsolescent (
10557 -- [Message =>] static_string_EXPRESSION
10558 -- [,[Version =>] Ada_05]]);
10560 -- pragma Obsolescent (
10561 -- [Entity =>] NAME
10562 -- [,[Message =>] static_string_EXPRESSION
10563 -- [,[Version =>] Ada_05]] );
10565 when Pragma_Obsolescent => Obsolescent : declare
10569 procedure Set_Obsolescent (E : Entity_Id);
10570 -- Given an entity Ent, mark it as obsolescent if appropriate
10572 ---------------------
10573 -- Set_Obsolescent --
10574 ---------------------
10576 procedure Set_Obsolescent (E : Entity_Id) is
10585 -- Entity name was given
10587 if Present (Ename) then
10589 -- If entity name matches, we are fine. Save entity in
10590 -- pragma argument, for ASIS use.
10592 if Chars (Ename) = Chars (Ent) then
10593 Set_Entity (Ename, Ent);
10594 Generate_Reference (Ent, Ename);
10596 -- If entity name does not match, only possibility is an
10597 -- enumeration literal from an enumeration type declaration.
10599 elsif Ekind (Ent) /= E_Enumeration_Type then
10601 ("pragma % entity name does not match declaration");
10604 Ent := First_Literal (E);
10608 ("pragma % entity name does not match any " &
10609 "enumeration literal");
10611 elsif Chars (Ent) = Chars (Ename) then
10612 Set_Entity (Ename, Ent);
10613 Generate_Reference (Ent, Ename);
10617 Ent := Next_Literal (Ent);
10623 -- Ent points to entity to be marked
10625 if Arg_Count >= 1 then
10627 -- Deal with static string argument
10629 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10630 S := Strval (Get_Pragma_Arg (Arg1));
10632 for J in 1 .. String_Length (S) loop
10633 if not In_Character_Range (Get_String_Char (S, J)) then
10635 ("pragma% argument does not allow wide characters",
10640 Obsolescent_Warnings.Append
10641 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10643 -- Check for Ada_05 parameter
10645 if Arg_Count /= 1 then
10646 Check_Arg_Count (2);
10649 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10652 Check_Arg_Is_Identifier (Argx);
10654 if Chars (Argx) /= Name_Ada_05 then
10655 Error_Msg_Name_2 := Name_Ada_05;
10657 ("only allowed argument for pragma% is %", Argx);
10660 if Ada_Version_Explicit < Ada_2005
10661 or else not Warn_On_Ada_2005_Compatibility
10669 -- Set flag if pragma active
10672 Set_Is_Obsolescent (Ent);
10676 end Set_Obsolescent;
10678 -- Start of processing for pragma Obsolescent
10683 Check_At_Most_N_Arguments (3);
10685 -- See if first argument specifies an entity name
10689 (Chars (Arg1) = Name_Entity
10691 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10693 N_Operator_Symbol))
10695 Ename := Get_Pragma_Arg (Arg1);
10697 -- Eliminate first argument, so we can share processing
10701 Arg_Count := Arg_Count - 1;
10703 -- No Entity name argument given
10709 if Arg_Count >= 1 then
10710 Check_Optional_Identifier (Arg1, Name_Message);
10712 if Arg_Count = 2 then
10713 Check_Optional_Identifier (Arg2, Name_Version);
10717 -- Get immediately preceding declaration
10720 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10724 -- Cases where we do not follow anything other than another pragma
10728 -- First case: library level compilation unit declaration with
10729 -- the pragma immediately following the declaration.
10731 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10733 (Defining_Entity (Unit (Parent (Parent (N)))));
10736 -- Case 2: library unit placement for package
10740 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10742 if Is_Package_Or_Generic_Package (Ent) then
10743 Set_Obsolescent (Ent);
10749 -- Cases where we must follow a declaration
10752 if Nkind (Decl) not in N_Declaration
10753 and then Nkind (Decl) not in N_Later_Decl_Item
10754 and then Nkind (Decl) not in N_Generic_Declaration
10755 and then Nkind (Decl) not in N_Renaming_Declaration
10758 ("pragma% misplaced, "
10759 & "must immediately follow a declaration");
10762 Set_Obsolescent (Defining_Entity (Decl));
10772 -- pragma Optimize (Time | Space | Off);
10774 -- The actual check for optimize is done in Gigi. Note that this
10775 -- pragma does not actually change the optimization setting, it
10776 -- simply checks that it is consistent with the pragma.
10778 when Pragma_Optimize =>
10779 Check_No_Identifiers;
10780 Check_Arg_Count (1);
10781 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10783 ------------------------
10784 -- Optimize_Alignment --
10785 ------------------------
10787 -- pragma Optimize_Alignment (Time | Space | Off);
10789 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10791 Check_No_Identifiers;
10792 Check_Arg_Count (1);
10793 Check_Valid_Configuration_Pragma;
10796 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10800 Opt.Optimize_Alignment := 'T';
10802 Opt.Optimize_Alignment := 'S';
10804 Opt.Optimize_Alignment := 'O';
10806 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10810 -- Set indication that mode is set locally. If we are in fact in a
10811 -- configuration pragma file, this setting is harmless since the
10812 -- switch will get reset anyway at the start of each unit.
10814 Optimize_Alignment_Local := True;
10815 end Optimize_Alignment;
10821 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10823 when Pragma_Ordered => Ordered : declare
10824 Assoc : constant Node_Id := Arg1;
10830 Check_No_Identifiers;
10831 Check_Arg_Count (1);
10832 Check_Arg_Is_Local_Name (Arg1);
10834 Type_Id := Get_Pragma_Arg (Assoc);
10835 Find_Type (Type_Id);
10836 Typ := Entity (Type_Id);
10838 if Typ = Any_Type then
10841 Typ := Underlying_Type (Typ);
10844 if not Is_Enumeration_Type (Typ) then
10845 Error_Pragma ("pragma% must specify enumeration type");
10848 Check_First_Subtype (Arg1);
10849 Set_Has_Pragma_Ordered (Base_Type (Typ));
10856 -- pragma Pack (first_subtype_LOCAL_NAME);
10858 when Pragma_Pack => Pack : declare
10859 Assoc : constant Node_Id := Arg1;
10863 Ignore : Boolean := False;
10866 Check_No_Identifiers;
10867 Check_Arg_Count (1);
10868 Check_Arg_Is_Local_Name (Arg1);
10870 Type_Id := Get_Pragma_Arg (Assoc);
10871 Find_Type (Type_Id);
10872 Typ := Entity (Type_Id);
10875 or else Rep_Item_Too_Early (Typ, N)
10879 Typ := Underlying_Type (Typ);
10882 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
10883 Error_Pragma ("pragma% must specify array or record type");
10886 Check_First_Subtype (Arg1);
10887 Check_Duplicate_Pragma (Typ);
10891 if Is_Array_Type (Typ) then
10892 Ctyp := Component_Type (Typ);
10894 -- Ignore pack that does nothing
10896 if Known_Static_Esize (Ctyp)
10897 and then Known_Static_RM_Size (Ctyp)
10898 and then Esize (Ctyp) = RM_Size (Ctyp)
10899 and then Addressable (Esize (Ctyp))
10904 -- Process OK pragma Pack. Note that if there is a separate
10905 -- component clause present, the Pack will be cancelled. This
10906 -- processing is in Freeze.
10908 if not Rep_Item_Too_Late (Typ, N) then
10910 -- In the context of static code analysis, we do not need
10911 -- complex front-end expansions related to pragma Pack,
10912 -- so disable handling of pragma Pack in this case.
10914 if CodePeer_Mode then
10917 -- Don't attempt any packing for VM targets. We possibly
10918 -- could deal with some cases of array bit-packing, but we
10919 -- don't bother, since this is not a typical kind of
10920 -- representation in the VM context anyway (and would not
10921 -- for example work nicely with the debugger).
10923 elsif VM_Target /= No_VM then
10924 if not GNAT_Mode then
10926 ("?pragma% ignored in this configuration");
10929 -- Normal case where we do the pack action
10933 Set_Is_Packed (Base_Type (Typ), Sense);
10934 Set_Has_Non_Standard_Rep (Base_Type (Typ), Sense);
10937 Set_Has_Pragma_Pack (Base_Type (Typ), Sense);
10939 -- Complete reset action for Aspect_Cancel case
10941 if Sense = False then
10943 -- Cancel size unless explicitly set
10945 if not Has_Size_Clause (Typ)
10946 and then not Has_Object_Size_Clause (Typ)
10948 Set_Esize (Typ, Uint_0);
10949 Set_RM_Size (Typ, Uint_0);
10950 Set_Alignment (Typ, Uint_0);
10951 Set_Packed_Array_Type (Typ, Empty);
10954 -- Reset component size unless explicitly set
10956 if not Has_Component_Size_Clause (Typ) then
10957 if Known_Static_Esize (Ctyp)
10958 and then Known_Static_RM_Size (Ctyp)
10959 and then Esize (Ctyp) = RM_Size (Ctyp)
10960 and then Addressable (Esize (Ctyp))
10963 (Base_Type (Typ), Esize (Ctyp));
10966 (Base_Type (Typ), Uint_0);
10973 -- For record types, the pack is always effective
10975 else pragma Assert (Is_Record_Type (Typ));
10976 if not Rep_Item_Too_Late (Typ, N) then
10978 -- Ignore pack request with warning in VM mode (skip warning
10979 -- if we are compiling GNAT run time library).
10981 if VM_Target /= No_VM then
10982 if not GNAT_Mode then
10984 ("?pragma% ignored in this configuration");
10987 -- Normal case of pack request active
10990 Set_Is_Packed (Base_Type (Typ), Sense);
10991 Set_Has_Pragma_Pack (Base_Type (Typ), Sense);
10992 Set_Has_Non_Standard_Rep (Base_Type (Typ), Sense);
10994 -- Complete reset action for Aspect_Cancel case
10996 if Sense = False then
10998 -- Cancel size if not explicitly given
11000 if not Has_Size_Clause (Typ)
11001 and then not Has_Object_Size_Clause (Typ)
11003 Set_Esize (Typ, Uint_0);
11004 Set_Alignment (Typ, Uint_0);
11018 -- There is nothing to do here, since we did all the processing for
11019 -- this pragma in Par.Prag (so that it works properly even in syntax
11022 when Pragma_Page =>
11029 -- pragma Passive [(PASSIVE_FORM)];
11031 -- PASSIVE_FORM ::= Semaphore | No
11033 when Pragma_Passive =>
11036 if Nkind (Parent (N)) /= N_Task_Definition then
11037 Error_Pragma ("pragma% must be within task definition");
11040 if Arg_Count /= 0 then
11041 Check_Arg_Count (1);
11042 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11045 ----------------------------------
11046 -- Preelaborable_Initialization --
11047 ----------------------------------
11049 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11051 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11056 Check_Arg_Count (1);
11057 Check_No_Identifiers;
11058 Check_Arg_Is_Identifier (Arg1);
11059 Check_Arg_Is_Local_Name (Arg1);
11060 Check_First_Subtype (Arg1);
11061 Ent := Entity (Get_Pragma_Arg (Arg1));
11063 if not (Is_Private_Type (Ent)
11065 Is_Protected_Type (Ent)
11067 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11070 ("pragma % can only be applied to private, formal derived or "
11071 & "protected type",
11075 -- Give an error if the pragma is applied to a protected type that
11076 -- does not qualify (due to having entries, or due to components
11077 -- that do not qualify).
11079 if Is_Protected_Type (Ent)
11080 and then not Has_Preelaborable_Initialization (Ent)
11083 ("protected type & does not have preelaborable " &
11084 "initialization", Ent);
11086 -- Otherwise mark the type as definitely having preelaborable
11090 Set_Known_To_Have_Preelab_Init (Ent);
11093 if Has_Pragma_Preelab_Init (Ent)
11094 and then Warn_On_Redundant_Constructs
11096 Error_Pragma ("?duplicate pragma%!");
11098 Set_Has_Pragma_Preelab_Init (Ent);
11102 --------------------
11103 -- Persistent_BSS --
11104 --------------------
11106 -- pragma Persistent_BSS [(object_NAME)];
11108 when Pragma_Persistent_BSS => Persistent_BSS : declare
11115 Check_At_Most_N_Arguments (1);
11117 -- Case of application to specific object (one argument)
11119 if Arg_Count = 1 then
11120 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11122 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11124 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11127 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11130 Ent := Entity (Get_Pragma_Arg (Arg1));
11131 Decl := Parent (Ent);
11133 if Rep_Item_Too_Late (Ent, N) then
11137 if Present (Expression (Decl)) then
11139 ("object for pragma% cannot have initialization", Arg1);
11142 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11144 ("object type for pragma% is not potentially persistent",
11148 Check_Duplicate_Pragma (Ent);
11152 Make_Linker_Section_Pragma
11153 (Ent, Sloc (N), ".persistent.bss");
11154 Insert_After (N, Prag);
11158 -- Case of use as configuration pragma with no arguments
11161 Check_Valid_Configuration_Pragma;
11162 Persistent_BSS_Mode := True;
11164 end Persistent_BSS;
11170 -- pragma Polling (ON | OFF);
11172 when Pragma_Polling =>
11174 Check_Arg_Count (1);
11175 Check_No_Identifiers;
11176 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11177 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11179 -------------------
11180 -- Postcondition --
11181 -------------------
11183 -- pragma Postcondition ([Check =>] Boolean_Expression
11184 -- [,[Message =>] String_Expression]);
11186 when Pragma_Postcondition => Postcondition : declare
11188 pragma Warnings (Off, In_Body);
11192 Check_At_Least_N_Arguments (1);
11193 Check_At_Most_N_Arguments (2);
11194 Check_Optional_Identifier (Arg1, Name_Check);
11196 -- All we need to do here is call the common check procedure,
11197 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11199 Check_Precondition_Postcondition (In_Body);
11206 -- pragma Precondition ([Check =>] Boolean_Expression
11207 -- [,[Message =>] String_Expression]);
11209 when Pragma_Precondition => Precondition : declare
11214 Check_At_Least_N_Arguments (1);
11215 Check_At_Most_N_Arguments (2);
11216 Check_Optional_Identifier (Arg1, Name_Check);
11217 Check_Precondition_Postcondition (In_Body);
11219 -- If in spec, nothing more to do. If in body, then we convert the
11220 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11221 -- this whether or not precondition checks are enabled. That works
11222 -- fine since pragma Check will do this check, and will also
11223 -- analyze the condition itself in the proper context.
11228 Chars => Name_Check,
11229 Pragma_Argument_Associations => New_List (
11230 Make_Pragma_Argument_Association (Loc,
11232 Make_Identifier (Loc,
11233 Chars => Name_Precondition)),
11235 Make_Pragma_Argument_Association (Sloc (Arg1),
11236 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11238 if Arg_Count = 2 then
11239 Append_To (Pragma_Argument_Associations (N),
11240 Make_Pragma_Argument_Association (Sloc (Arg2),
11241 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11252 -- pragma Predicate
11253 -- ([Entity =>] type_LOCAL_NAME,
11254 -- [Check =>] EXPRESSION);
11256 when Pragma_Predicate => Predicate : declare
11261 pragma Unreferenced (Discard);
11265 Check_Arg_Count (2);
11266 Check_Optional_Identifier (Arg1, Name_Entity);
11267 Check_Optional_Identifier (Arg2, Name_Check);
11269 Check_Arg_Is_Local_Name (Arg1);
11271 Type_Id := Get_Pragma_Arg (Arg1);
11272 Find_Type (Type_Id);
11273 Typ := Entity (Type_Id);
11275 if Typ = Any_Type then
11279 -- The remaining processing is simply to link the pragma on to
11280 -- the rep item chain, for processing when the type is frozen.
11281 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11282 -- mark the type as having predicates.
11284 Set_Has_Predicates (Typ);
11285 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11292 -- pragma Preelaborate [(library_unit_NAME)];
11294 -- Set the flag Is_Preelaborated of program unit name entity
11296 when Pragma_Preelaborate => Preelaborate : declare
11297 Pa : constant Node_Id := Parent (N);
11298 Pk : constant Node_Kind := Nkind (Pa);
11302 Check_Ada_83_Warning;
11303 Check_Valid_Library_Unit_Pragma;
11305 if Nkind (N) = N_Null_Statement then
11309 Ent := Find_Lib_Unit_Name;
11310 Check_Duplicate_Pragma (Ent);
11312 -- This filters out pragmas inside generic parent then
11313 -- show up inside instantiation
11316 and then not (Pk = N_Package_Specification
11317 and then Present (Generic_Parent (Pa)))
11319 if not Debug_Flag_U then
11320 Set_Is_Preelaborated (Ent, Sense);
11321 Set_Suppress_Elaboration_Warnings (Ent, Sense);
11326 ---------------------
11327 -- Preelaborate_05 --
11328 ---------------------
11330 -- pragma Preelaborate_05 [(library_unit_NAME)];
11332 -- This pragma is useable only in GNAT_Mode, where it is used like
11333 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11334 -- (otherwise it is ignored). This is used to implement AI-362 which
11335 -- recategorizes some run-time packages in Ada 2005 mode.
11337 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11342 Check_Valid_Library_Unit_Pragma;
11344 if not GNAT_Mode then
11345 Error_Pragma ("pragma% only available in GNAT mode");
11348 if Nkind (N) = N_Null_Statement then
11352 -- This is one of the few cases where we need to test the value of
11353 -- Ada_Version_Explicit rather than Ada_Version (which is always
11354 -- set to Ada_2012 in a predefined unit), we need to know the
11355 -- explicit version set to know if this pragma is active.
11357 if Ada_Version_Explicit >= Ada_2005 then
11358 Ent := Find_Lib_Unit_Name;
11359 Set_Is_Preelaborated (Ent);
11360 Set_Suppress_Elaboration_Warnings (Ent);
11362 end Preelaborate_05;
11368 -- pragma Priority (EXPRESSION);
11370 when Pragma_Priority => Priority : declare
11371 P : constant Node_Id := Parent (N);
11375 Check_No_Identifiers;
11376 Check_Arg_Count (1);
11380 if Nkind (P) = N_Subprogram_Body then
11381 Check_In_Main_Program;
11383 Arg := Get_Pragma_Arg (Arg1);
11384 Analyze_And_Resolve (Arg, Standard_Integer);
11388 if not Is_Static_Expression (Arg) then
11389 Flag_Non_Static_Expr
11390 ("main subprogram priority is not static!", Arg);
11393 -- If constraint error, then we already signalled an error
11395 elsif Raises_Constraint_Error (Arg) then
11398 -- Otherwise check in range
11402 Val : constant Uint := Expr_Value (Arg);
11406 or else Val > Expr_Value (Expression
11407 (Parent (RTE (RE_Max_Priority))))
11410 ("main subprogram priority is out of range", Arg1);
11416 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11418 -- Load an arbitrary entity from System.Tasking to make sure
11419 -- this package is implicitly with'ed, since we need to have
11420 -- the tasking run-time active for the pragma Priority to have
11424 Discard : Entity_Id;
11425 pragma Warnings (Off, Discard);
11427 Discard := RTE (RE_Task_List);
11430 -- Task or Protected, must be of type Integer
11432 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11433 Arg := Get_Pragma_Arg (Arg1);
11435 -- The expression must be analyzed in the special manner
11436 -- described in "Handling of Default and Per-Object
11437 -- Expressions" in sem.ads.
11439 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11441 if not Is_Static_Expression (Arg) then
11442 Check_Restriction (Static_Priorities, Arg);
11445 -- Anything else is incorrect
11451 if Has_Pragma_Priority (P) then
11452 Error_Pragma ("duplicate pragma% not allowed");
11454 Set_Has_Pragma_Priority (P, True);
11456 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11457 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11458 -- exp_ch9 should use this ???
11463 -----------------------------------
11464 -- Priority_Specific_Dispatching --
11465 -----------------------------------
11467 -- pragma Priority_Specific_Dispatching (
11468 -- policy_IDENTIFIER,
11469 -- first_priority_EXPRESSION,
11470 -- last_priority_EXPRESSION);
11472 when Pragma_Priority_Specific_Dispatching =>
11473 Priority_Specific_Dispatching : declare
11474 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11475 -- This is the entity System.Any_Priority;
11478 Lower_Bound : Node_Id;
11479 Upper_Bound : Node_Id;
11485 Check_Arg_Count (3);
11486 Check_No_Identifiers;
11487 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11488 Check_Valid_Configuration_Pragma;
11489 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11490 DP := Fold_Upper (Name_Buffer (1));
11492 Lower_Bound := Get_Pragma_Arg (Arg2);
11493 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11494 Lower_Val := Expr_Value (Lower_Bound);
11496 Upper_Bound := Get_Pragma_Arg (Arg3);
11497 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11498 Upper_Val := Expr_Value (Upper_Bound);
11500 -- It is not allowed to use Task_Dispatching_Policy and
11501 -- Priority_Specific_Dispatching in the same partition.
11503 if Task_Dispatching_Policy /= ' ' then
11504 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11506 ("pragma% incompatible with Task_Dispatching_Policy#");
11508 -- Check lower bound in range
11510 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11512 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11515 ("first_priority is out of range", Arg2);
11517 -- Check upper bound in range
11519 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11521 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11524 ("last_priority is out of range", Arg3);
11526 -- Check that the priority range is valid
11528 elsif Lower_Val > Upper_Val then
11530 ("last_priority_expression must be greater than" &
11531 " or equal to first_priority_expression");
11533 -- Store the new policy, but always preserve System_Location since
11534 -- we like the error message with the run-time name.
11537 -- Check overlapping in the priority ranges specified in other
11538 -- Priority_Specific_Dispatching pragmas within the same
11539 -- partition. We can only check those we know about!
11542 Specific_Dispatching.First .. Specific_Dispatching.Last
11544 if Specific_Dispatching.Table (J).First_Priority in
11545 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11546 or else Specific_Dispatching.Table (J).Last_Priority in
11547 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11550 Specific_Dispatching.Table (J).Pragma_Loc;
11552 ("priority range overlaps with "
11553 & "Priority_Specific_Dispatching#");
11557 -- The use of Priority_Specific_Dispatching is incompatible
11558 -- with Task_Dispatching_Policy.
11560 if Task_Dispatching_Policy /= ' ' then
11561 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11563 ("Priority_Specific_Dispatching incompatible "
11564 & "with Task_Dispatching_Policy#");
11567 -- The use of Priority_Specific_Dispatching forces ceiling
11570 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11571 Error_Msg_Sloc := Locking_Policy_Sloc;
11573 ("Priority_Specific_Dispatching incompatible "
11574 & "with Locking_Policy#");
11576 -- Set the Ceiling_Locking policy, but preserve System_Location
11577 -- since we like the error message with the run time name.
11580 Locking_Policy := 'C';
11582 if Locking_Policy_Sloc /= System_Location then
11583 Locking_Policy_Sloc := Loc;
11587 -- Add entry in the table
11589 Specific_Dispatching.Append
11590 ((Dispatching_Policy => DP,
11591 First_Priority => UI_To_Int (Lower_Val),
11592 Last_Priority => UI_To_Int (Upper_Val),
11593 Pragma_Loc => Loc));
11595 end Priority_Specific_Dispatching;
11601 -- pragma Profile (profile_IDENTIFIER);
11603 -- profile_IDENTIFIER => Restricted | Ravenscar
11605 when Pragma_Profile =>
11607 Check_Arg_Count (1);
11608 Check_Valid_Configuration_Pragma;
11609 Check_No_Identifiers;
11612 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11614 if Chars (Argx) = Name_Ravenscar then
11615 Set_Ravenscar_Profile (N);
11616 elsif Chars (Argx) = Name_Restricted then
11617 Set_Profile_Restrictions
11618 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11620 Error_Pragma_Arg ("& is not a valid profile", Argx);
11624 ----------------------
11625 -- Profile_Warnings --
11626 ----------------------
11628 -- pragma Profile_Warnings (profile_IDENTIFIER);
11630 -- profile_IDENTIFIER => Restricted | Ravenscar
11632 when Pragma_Profile_Warnings =>
11634 Check_Arg_Count (1);
11635 Check_Valid_Configuration_Pragma;
11636 Check_No_Identifiers;
11639 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11641 if Chars (Argx) = Name_Ravenscar then
11642 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11643 elsif Chars (Argx) = Name_Restricted then
11644 Set_Profile_Restrictions (Restricted, N, Warn => True);
11646 Error_Pragma_Arg ("& is not a valid profile", Argx);
11650 --------------------------
11651 -- Propagate_Exceptions --
11652 --------------------------
11654 -- pragma Propagate_Exceptions;
11656 -- Note: this pragma is obsolete and has no effect
11658 when Pragma_Propagate_Exceptions =>
11660 Check_Arg_Count (0);
11662 if In_Extended_Main_Source_Unit (N) then
11663 Propagate_Exceptions := True;
11670 -- pragma Psect_Object (
11671 -- [Internal =>] LOCAL_NAME,
11672 -- [, [External =>] EXTERNAL_SYMBOL]
11673 -- [, [Size =>] EXTERNAL_SYMBOL]);
11675 when Pragma_Psect_Object | Pragma_Common_Object =>
11676 Psect_Object : declare
11677 Args : Args_List (1 .. 3);
11678 Names : constant Name_List (1 .. 3) := (
11683 Internal : Node_Id renames Args (1);
11684 External : Node_Id renames Args (2);
11685 Size : Node_Id renames Args (3);
11687 Def_Id : Entity_Id;
11689 procedure Check_Too_Long (Arg : Node_Id);
11690 -- Posts message if the argument is an identifier with more
11691 -- than 31 characters, or a string literal with more than
11692 -- 31 characters, and we are operating under VMS
11694 --------------------
11695 -- Check_Too_Long --
11696 --------------------
11698 procedure Check_Too_Long (Arg : Node_Id) is
11699 X : constant Node_Id := Original_Node (Arg);
11702 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11704 ("inappropriate argument for pragma %", Arg);
11707 if OpenVMS_On_Target then
11708 if (Nkind (X) = N_String_Literal
11709 and then String_Length (Strval (X)) > 31)
11711 (Nkind (X) = N_Identifier
11712 and then Length_Of_Name (Chars (X)) > 31)
11715 ("argument for pragma % is longer than 31 characters",
11719 end Check_Too_Long;
11721 -- Start of processing for Common_Object/Psect_Object
11725 Gather_Associations (Names, Args);
11726 Process_Extended_Import_Export_Internal_Arg (Internal);
11728 Def_Id := Entity (Internal);
11730 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11732 ("pragma% must designate an object", Internal);
11735 Check_Too_Long (Internal);
11737 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11739 ("cannot use pragma% for imported/exported object",
11743 if Is_Concurrent_Type (Etype (Internal)) then
11745 ("cannot specify pragma % for task/protected object",
11749 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11751 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11753 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11756 if Ekind (Def_Id) = E_Constant then
11758 ("cannot specify pragma % for a constant", Internal);
11761 if Is_Record_Type (Etype (Internal)) then
11767 Ent := First_Entity (Etype (Internal));
11768 while Present (Ent) loop
11769 Decl := Declaration_Node (Ent);
11771 if Ekind (Ent) = E_Component
11772 and then Nkind (Decl) = N_Component_Declaration
11773 and then Present (Expression (Decl))
11774 and then Warn_On_Export_Import
11777 ("?object for pragma % has defaults", Internal);
11787 if Present (Size) then
11788 Check_Too_Long (Size);
11791 if Present (External) then
11792 Check_Arg_Is_External_Name (External);
11793 Check_Too_Long (External);
11796 -- If all error tests pass, link pragma on to the rep item chain
11798 Record_Rep_Item (Def_Id, N);
11805 -- pragma Pure [(library_unit_NAME)];
11807 when Pragma_Pure => Pure : declare
11811 Check_Ada_83_Warning;
11812 Check_Valid_Library_Unit_Pragma;
11814 if Nkind (N) = N_Null_Statement then
11818 Ent := Find_Lib_Unit_Name;
11820 Set_Has_Pragma_Pure (Ent);
11821 Set_Suppress_Elaboration_Warnings (Ent);
11828 -- pragma Pure_05 [(library_unit_NAME)];
11830 -- This pragma is useable only in GNAT_Mode, where it is used like
11831 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11832 -- it is ignored). It may be used after a pragma Preelaborate, in
11833 -- which case it overrides the effect of the pragma Preelaborate.
11834 -- This is used to implement AI-362 which recategorizes some run-time
11835 -- packages in Ada 2005 mode.
11837 when Pragma_Pure_05 => Pure_05 : declare
11842 Check_Valid_Library_Unit_Pragma;
11844 if not GNAT_Mode then
11845 Error_Pragma ("pragma% only available in GNAT mode");
11848 if Nkind (N) = N_Null_Statement then
11852 -- This is one of the few cases where we need to test the value of
11853 -- Ada_Version_Explicit rather than Ada_Version (which is always
11854 -- set to Ada_2012 in a predefined unit), we need to know the
11855 -- explicit version set to know if this pragma is active.
11857 if Ada_Version_Explicit >= Ada_2005 then
11858 Ent := Find_Lib_Unit_Name;
11859 Set_Is_Preelaborated (Ent, False);
11861 Set_Suppress_Elaboration_Warnings (Ent);
11865 -------------------
11866 -- Pure_Function --
11867 -------------------
11869 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11871 when Pragma_Pure_Function => Pure_Function : declare
11874 Def_Id : Entity_Id;
11875 Effective : Boolean := False;
11879 Check_Arg_Count (1);
11880 Check_Optional_Identifier (Arg1, Name_Entity);
11881 Check_Arg_Is_Local_Name (Arg1);
11882 E_Id := Get_Pragma_Arg (Arg1);
11884 if Error_Posted (E_Id) then
11888 -- Loop through homonyms (overloadings) of referenced entity
11890 E := Entity (E_Id);
11892 if Present (E) then
11894 Def_Id := Get_Base_Subprogram (E);
11896 if not Ekind_In (Def_Id, E_Function,
11897 E_Generic_Function,
11901 ("pragma% requires a function name", Arg1);
11904 Set_Is_Pure (Def_Id, Sense);
11906 if not Has_Pragma_Pure_Function (Def_Id) then
11907 Set_Has_Pragma_Pure_Function (Def_Id, Sense);
11908 Effective := Sense;
11911 exit when From_Aspect_Specification (N);
11913 exit when No (E) or else Scope (E) /= Current_Scope;
11916 if Sense and then not Effective
11917 and then Warn_On_Redundant_Constructs
11920 ("pragma Pure_Function on& is redundant?",
11926 --------------------
11927 -- Queuing_Policy --
11928 --------------------
11930 -- pragma Queuing_Policy (policy_IDENTIFIER);
11932 when Pragma_Queuing_Policy => declare
11936 Check_Ada_83_Warning;
11937 Check_Arg_Count (1);
11938 Check_No_Identifiers;
11939 Check_Arg_Is_Queuing_Policy (Arg1);
11940 Check_Valid_Configuration_Pragma;
11941 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11942 QP := Fold_Upper (Name_Buffer (1));
11944 if Queuing_Policy /= ' '
11945 and then Queuing_Policy /= QP
11947 Error_Msg_Sloc := Queuing_Policy_Sloc;
11948 Error_Pragma ("queuing policy incompatible with policy#");
11950 -- Set new policy, but always preserve System_Location since we
11951 -- like the error message with the run time name.
11954 Queuing_Policy := QP;
11956 if Queuing_Policy_Sloc /= System_Location then
11957 Queuing_Policy_Sloc := Loc;
11962 -----------------------
11963 -- Relative_Deadline --
11964 -----------------------
11966 -- pragma Relative_Deadline (time_span_EXPRESSION);
11968 when Pragma_Relative_Deadline => Relative_Deadline : declare
11969 P : constant Node_Id := Parent (N);
11974 Check_No_Identifiers;
11975 Check_Arg_Count (1);
11977 Arg := Get_Pragma_Arg (Arg1);
11979 -- The expression must be analyzed in the special manner described
11980 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
11982 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
11986 if Nkind (P) = N_Subprogram_Body then
11987 Check_In_Main_Program;
11991 elsif Nkind (P) = N_Task_Definition then
11994 -- Anything else is incorrect
12000 if Has_Relative_Deadline_Pragma (P) then
12001 Error_Pragma ("duplicate pragma% not allowed");
12003 Set_Has_Relative_Deadline_Pragma (P, True);
12005 if Nkind (P) = N_Task_Definition then
12006 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12009 end Relative_Deadline;
12011 ---------------------------
12012 -- Remote_Call_Interface --
12013 ---------------------------
12015 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12017 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12018 Cunit_Node : Node_Id;
12019 Cunit_Ent : Entity_Id;
12023 Check_Ada_83_Warning;
12024 Check_Valid_Library_Unit_Pragma;
12026 if Nkind (N) = N_Null_Statement then
12030 Cunit_Node := Cunit (Current_Sem_Unit);
12031 K := Nkind (Unit (Cunit_Node));
12032 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12034 if K = N_Package_Declaration
12035 or else K = N_Generic_Package_Declaration
12036 or else K = N_Subprogram_Declaration
12037 or else K = N_Generic_Subprogram_Declaration
12038 or else (K = N_Subprogram_Body
12039 and then Acts_As_Spec (Unit (Cunit_Node)))
12044 "pragma% must apply to package or subprogram declaration");
12047 Set_Is_Remote_Call_Interface (Cunit_Ent);
12048 end Remote_Call_Interface;
12054 -- pragma Remote_Types [(library_unit_NAME)];
12056 when Pragma_Remote_Types => Remote_Types : declare
12057 Cunit_Node : Node_Id;
12058 Cunit_Ent : Entity_Id;
12061 Check_Ada_83_Warning;
12062 Check_Valid_Library_Unit_Pragma;
12064 if Nkind (N) = N_Null_Statement then
12068 Cunit_Node := Cunit (Current_Sem_Unit);
12069 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12071 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12072 N_Generic_Package_Declaration)
12075 ("pragma% can only apply to a package declaration");
12078 Set_Is_Remote_Types (Cunit_Ent);
12085 -- pragma Ravenscar;
12087 when Pragma_Ravenscar =>
12089 Check_Arg_Count (0);
12090 Check_Valid_Configuration_Pragma;
12091 Set_Ravenscar_Profile (N);
12093 if Warn_On_Obsolescent_Feature then
12094 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12095 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12098 -------------------------
12099 -- Restricted_Run_Time --
12100 -------------------------
12102 -- pragma Restricted_Run_Time;
12104 when Pragma_Restricted_Run_Time =>
12106 Check_Arg_Count (0);
12107 Check_Valid_Configuration_Pragma;
12108 Set_Profile_Restrictions
12109 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12111 if Warn_On_Obsolescent_Feature then
12113 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12114 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12121 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12124 -- restriction_IDENTIFIER
12125 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12127 when Pragma_Restrictions =>
12128 Process_Restrictions_Or_Restriction_Warnings
12129 (Warn => Treat_Restrictions_As_Warnings);
12131 --------------------------
12132 -- Restriction_Warnings --
12133 --------------------------
12135 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12138 -- restriction_IDENTIFIER
12139 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12141 when Pragma_Restriction_Warnings =>
12143 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12149 -- pragma Reviewable;
12151 when Pragma_Reviewable =>
12152 Check_Ada_83_Warning;
12153 Check_Arg_Count (0);
12155 -- Call dummy debugging function rv. This is done to assist front
12156 -- end debugging. By placing a Reviewable pragma in the source
12157 -- program, a breakpoint on rv catches this place in the source,
12158 -- allowing convenient stepping to the point of interest.
12162 --------------------------
12163 -- Short_Circuit_And_Or --
12164 --------------------------
12166 when Pragma_Short_Circuit_And_Or =>
12168 Check_Arg_Count (0);
12169 Check_Valid_Configuration_Pragma;
12170 Short_Circuit_And_Or := True;
12172 -------------------
12173 -- Share_Generic --
12174 -------------------
12176 -- pragma Share_Generic (NAME {, NAME});
12178 when Pragma_Share_Generic =>
12180 Process_Generic_List;
12186 -- pragma Shared (LOCAL_NAME);
12188 when Pragma_Shared =>
12190 Process_Atomic_Shared_Volatile;
12192 --------------------
12193 -- Shared_Passive --
12194 --------------------
12196 -- pragma Shared_Passive [(library_unit_NAME)];
12198 -- Set the flag Is_Shared_Passive of program unit name entity
12200 when Pragma_Shared_Passive => Shared_Passive : declare
12201 Cunit_Node : Node_Id;
12202 Cunit_Ent : Entity_Id;
12205 Check_Ada_83_Warning;
12206 Check_Valid_Library_Unit_Pragma;
12208 if Nkind (N) = N_Null_Statement then
12212 Cunit_Node := Cunit (Current_Sem_Unit);
12213 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12215 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12216 N_Generic_Package_Declaration)
12219 ("pragma% can only apply to a package declaration");
12222 Set_Is_Shared_Passive (Cunit_Ent);
12223 end Shared_Passive;
12225 -----------------------
12226 -- Short_Descriptors --
12227 -----------------------
12229 -- pragma Short_Descriptors;
12231 when Pragma_Short_Descriptors =>
12233 Check_Arg_Count (0);
12234 Check_Valid_Configuration_Pragma;
12235 Short_Descriptors := True;
12237 ----------------------
12238 -- Source_File_Name --
12239 ----------------------
12241 -- There are five forms for this pragma:
12243 -- pragma Source_File_Name (
12244 -- [UNIT_NAME =>] unit_NAME,
12245 -- BODY_FILE_NAME => STRING_LITERAL
12246 -- [, [INDEX =>] INTEGER_LITERAL]);
12248 -- pragma Source_File_Name (
12249 -- [UNIT_NAME =>] unit_NAME,
12250 -- SPEC_FILE_NAME => STRING_LITERAL
12251 -- [, [INDEX =>] INTEGER_LITERAL]);
12253 -- pragma Source_File_Name (
12254 -- BODY_FILE_NAME => STRING_LITERAL
12255 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12256 -- [, CASING => CASING_SPEC]);
12258 -- pragma Source_File_Name (
12259 -- SPEC_FILE_NAME => STRING_LITERAL
12260 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12261 -- [, CASING => CASING_SPEC]);
12263 -- pragma Source_File_Name (
12264 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12265 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12266 -- [, CASING => CASING_SPEC]);
12268 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12270 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12271 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12272 -- only be used when no project file is used, while SFNP can only be
12273 -- used when a project file is used.
12275 -- No processing here. Processing was completed during parsing, since
12276 -- we need to have file names set as early as possible. Units are
12277 -- loaded well before semantic processing starts.
12279 -- The only processing we defer to this point is the check for
12280 -- correct placement.
12282 when Pragma_Source_File_Name =>
12284 Check_Valid_Configuration_Pragma;
12286 ------------------------------
12287 -- Source_File_Name_Project --
12288 ------------------------------
12290 -- See Source_File_Name for syntax
12292 -- No processing here. Processing was completed during parsing, since
12293 -- we need to have file names set as early as possible. Units are
12294 -- loaded well before semantic processing starts.
12296 -- The only processing we defer to this point is the check for
12297 -- correct placement.
12299 when Pragma_Source_File_Name_Project =>
12301 Check_Valid_Configuration_Pragma;
12303 -- Check that a pragma Source_File_Name_Project is used only in a
12304 -- configuration pragmas file.
12306 -- Pragmas Source_File_Name_Project should only be generated by
12307 -- the Project Manager in configuration pragmas files.
12309 -- This is really an ugly test. It seems to depend on some
12310 -- accidental and undocumented property. At the very least it
12311 -- needs to be documented, but it would be better to have a
12312 -- clean way of testing if we are in a configuration file???
12314 if Present (Parent (N)) then
12316 ("pragma% can only appear in a configuration pragmas file");
12319 ----------------------
12320 -- Source_Reference --
12321 ----------------------
12323 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12325 -- Nothing to do, all processing completed in Par.Prag, since we need
12326 -- the information for possible parser messages that are output.
12328 when Pragma_Source_Reference =>
12331 --------------------------------
12332 -- Static_Elaboration_Desired --
12333 --------------------------------
12335 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12337 when Pragma_Static_Elaboration_Desired =>
12339 Check_At_Most_N_Arguments (1);
12341 if Is_Compilation_Unit (Current_Scope)
12342 and then Ekind (Current_Scope) = E_Package
12344 Set_Static_Elaboration_Desired (Current_Scope, True);
12346 Error_Pragma ("pragma% must apply to a library-level package");
12353 -- pragma Storage_Size (EXPRESSION);
12355 when Pragma_Storage_Size => Storage_Size : declare
12356 P : constant Node_Id := Parent (N);
12360 Check_No_Identifiers;
12361 Check_Arg_Count (1);
12363 -- The expression must be analyzed in the special manner described
12364 -- in "Handling of Default Expressions" in sem.ads.
12366 Arg := Get_Pragma_Arg (Arg1);
12367 Preanalyze_Spec_Expression (Arg, Any_Integer);
12369 if not Is_Static_Expression (Arg) then
12370 Check_Restriction (Static_Storage_Size, Arg);
12373 if Nkind (P) /= N_Task_Definition then
12378 if Has_Storage_Size_Pragma (P) then
12379 Error_Pragma ("duplicate pragma% not allowed");
12381 Set_Has_Storage_Size_Pragma (P, True);
12384 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12385 -- ??? exp_ch9 should use this!
12393 -- pragma Storage_Unit (NUMERIC_LITERAL);
12395 -- Only permitted argument is System'Storage_Unit value
12397 when Pragma_Storage_Unit =>
12398 Check_No_Identifiers;
12399 Check_Arg_Count (1);
12400 Check_Arg_Is_Integer_Literal (Arg1);
12402 if Intval (Get_Pragma_Arg (Arg1)) /=
12403 UI_From_Int (Ttypes.System_Storage_Unit)
12405 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12407 ("the only allowed argument for pragma% is ^", Arg1);
12410 --------------------
12411 -- Stream_Convert --
12412 --------------------
12414 -- pragma Stream_Convert (
12415 -- [Entity =>] type_LOCAL_NAME,
12416 -- [Read =>] function_NAME,
12417 -- [Write =>] function NAME);
12419 when Pragma_Stream_Convert => Stream_Convert : declare
12421 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12422 -- Check that the given argument is the name of a local function
12423 -- of one argument that is not overloaded earlier in the current
12424 -- local scope. A check is also made that the argument is a
12425 -- function with one parameter.
12427 --------------------------------------
12428 -- Check_OK_Stream_Convert_Function --
12429 --------------------------------------
12431 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12435 Check_Arg_Is_Local_Name (Arg);
12436 Ent := Entity (Get_Pragma_Arg (Arg));
12438 if Has_Homonym (Ent) then
12440 ("argument for pragma% may not be overloaded", Arg);
12443 if Ekind (Ent) /= E_Function
12444 or else No (First_Formal (Ent))
12445 or else Present (Next_Formal (First_Formal (Ent)))
12448 ("argument for pragma% must be" &
12449 " function of one argument", Arg);
12451 end Check_OK_Stream_Convert_Function;
12453 -- Start of processing for Stream_Convert
12457 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12458 Check_Arg_Count (3);
12459 Check_Optional_Identifier (Arg1, Name_Entity);
12460 Check_Optional_Identifier (Arg2, Name_Read);
12461 Check_Optional_Identifier (Arg3, Name_Write);
12462 Check_Arg_Is_Local_Name (Arg1);
12463 Check_OK_Stream_Convert_Function (Arg2);
12464 Check_OK_Stream_Convert_Function (Arg3);
12467 Typ : constant Entity_Id :=
12468 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12469 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12470 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12473 Check_First_Subtype (Arg1);
12475 -- Check for too early or too late. Note that we don't enforce
12476 -- the rule about primitive operations in this case, since, as
12477 -- is the case for explicit stream attributes themselves, these
12478 -- restrictions are not appropriate. Note that the chaining of
12479 -- the pragma by Rep_Item_Too_Late is actually the critical
12480 -- processing done for this pragma.
12482 if Rep_Item_Too_Early (Typ, N)
12484 Rep_Item_Too_Late (Typ, N, FOnly => True)
12489 -- Return if previous error
12491 if Etype (Typ) = Any_Type
12493 Etype (Read) = Any_Type
12495 Etype (Write) = Any_Type
12502 if Underlying_Type (Etype (Read)) /= Typ then
12504 ("incorrect return type for function&", Arg2);
12507 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12509 ("incorrect parameter type for function&", Arg3);
12512 if Underlying_Type (Etype (First_Formal (Read))) /=
12513 Underlying_Type (Etype (Write))
12516 ("result type of & does not match Read parameter type",
12520 end Stream_Convert;
12522 -------------------------
12523 -- Style_Checks (GNAT) --
12524 -------------------------
12526 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12528 -- This is processed by the parser since some of the style checks
12529 -- take place during source scanning and parsing. This means that
12530 -- we don't need to issue error messages here.
12532 when Pragma_Style_Checks => Style_Checks : declare
12533 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12539 Check_No_Identifiers;
12541 -- Two argument form
12543 if Arg_Count = 2 then
12544 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12551 E_Id := Get_Pragma_Arg (Arg2);
12554 if not Is_Entity_Name (E_Id) then
12556 ("second argument of pragma% must be entity name",
12560 E := Entity (E_Id);
12566 Set_Suppress_Style_Checks (E,
12567 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12568 exit when No (Homonym (E));
12574 -- One argument form
12577 Check_Arg_Count (1);
12579 if Nkind (A) = N_String_Literal then
12583 Slen : constant Natural := Natural (String_Length (S));
12584 Options : String (1 .. Slen);
12590 C := Get_String_Char (S, Int (J));
12591 exit when not In_Character_Range (C);
12592 Options (J) := Get_Character (C);
12594 -- If at end of string, set options. As per discussion
12595 -- above, no need to check for errors, since we issued
12596 -- them in the parser.
12599 Set_Style_Check_Options (Options);
12607 elsif Nkind (A) = N_Identifier then
12608 if Chars (A) = Name_All_Checks then
12610 Set_GNAT_Style_Check_Options;
12612 Set_Default_Style_Check_Options;
12615 elsif Chars (A) = Name_On then
12616 Style_Check := True;
12618 elsif Chars (A) = Name_Off then
12619 Style_Check := False;
12629 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12631 when Pragma_Subtitle =>
12633 Check_Arg_Count (1);
12634 Check_Optional_Identifier (Arg1, Name_Subtitle);
12635 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12642 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12644 when Pragma_Suppress =>
12645 Process_Suppress_Unsuppress (True);
12651 -- pragma Suppress_All;
12653 -- The only check made here is that the pragma has no arguments.
12654 -- There are no placement rules, and the processing required (setting
12655 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12656 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12657 -- then creates and inserts a pragma Suppress (All_Checks).
12659 when Pragma_Suppress_All =>
12661 Check_Arg_Count (0);
12663 -------------------------
12664 -- Suppress_Debug_Info --
12665 -------------------------
12667 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12669 when Pragma_Suppress_Debug_Info =>
12671 Check_Arg_Count (1);
12672 Check_Optional_Identifier (Arg1, Name_Entity);
12673 Check_Arg_Is_Local_Name (Arg1);
12674 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)), Sense);
12676 ----------------------------------
12677 -- Suppress_Exception_Locations --
12678 ----------------------------------
12680 -- pragma Suppress_Exception_Locations;
12682 when Pragma_Suppress_Exception_Locations =>
12684 Check_Arg_Count (0);
12685 Check_Valid_Configuration_Pragma;
12686 Exception_Locations_Suppressed := True;
12688 -----------------------------
12689 -- Suppress_Initialization --
12690 -----------------------------
12692 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12694 when Pragma_Suppress_Initialization => Suppress_Init : declare
12700 Check_Arg_Count (1);
12701 Check_Optional_Identifier (Arg1, Name_Entity);
12702 Check_Arg_Is_Local_Name (Arg1);
12704 E_Id := Get_Pragma_Arg (Arg1);
12706 if Etype (E_Id) = Any_Type then
12710 E := Entity (E_Id);
12712 if Is_Type (E) then
12713 if Is_Incomplete_Or_Private_Type (E) then
12714 if No (Full_View (Base_Type (E))) then
12716 ("argument of pragma% cannot be an incomplete type",
12719 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12722 Set_Suppress_Init_Proc (Base_Type (E));
12727 ("pragma% requires argument that is a type name", Arg1);
12735 -- pragma System_Name (DIRECT_NAME);
12737 -- Syntax check: one argument, which must be the identifier GNAT or
12738 -- the identifier GCC, no other identifiers are acceptable.
12740 when Pragma_System_Name =>
12742 Check_No_Identifiers;
12743 Check_Arg_Count (1);
12744 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12746 -----------------------------
12747 -- Task_Dispatching_Policy --
12748 -----------------------------
12750 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12752 when Pragma_Task_Dispatching_Policy => declare
12756 Check_Ada_83_Warning;
12757 Check_Arg_Count (1);
12758 Check_No_Identifiers;
12759 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12760 Check_Valid_Configuration_Pragma;
12761 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12762 DP := Fold_Upper (Name_Buffer (1));
12764 if Task_Dispatching_Policy /= ' '
12765 and then Task_Dispatching_Policy /= DP
12767 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12769 ("task dispatching policy incompatible with policy#");
12771 -- Set new policy, but always preserve System_Location since we
12772 -- like the error message with the run time name.
12775 Task_Dispatching_Policy := DP;
12777 if Task_Dispatching_Policy_Sloc /= System_Location then
12778 Task_Dispatching_Policy_Sloc := Loc;
12787 -- pragma Task_Info (EXPRESSION);
12789 when Pragma_Task_Info => Task_Info : declare
12790 P : constant Node_Id := Parent (N);
12795 if Nkind (P) /= N_Task_Definition then
12796 Error_Pragma ("pragma% must appear in task definition");
12799 Check_No_Identifiers;
12800 Check_Arg_Count (1);
12802 Analyze_And_Resolve
12803 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12805 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12809 if Has_Task_Info_Pragma (P) then
12810 Error_Pragma ("duplicate pragma% not allowed");
12812 Set_Has_Task_Info_Pragma (P, True);
12820 -- pragma Task_Name (string_EXPRESSION);
12822 when Pragma_Task_Name => Task_Name : declare
12823 P : constant Node_Id := Parent (N);
12827 Check_No_Identifiers;
12828 Check_Arg_Count (1);
12830 Arg := Get_Pragma_Arg (Arg1);
12832 -- The expression is used in the call to Create_Task, and must be
12833 -- expanded there, not in the context of the current spec. It must
12834 -- however be analyzed to capture global references, in case it
12835 -- appears in a generic context.
12837 Preanalyze_And_Resolve (Arg, Standard_String);
12839 if Nkind (P) /= N_Task_Definition then
12843 if Has_Task_Name_Pragma (P) then
12844 Error_Pragma ("duplicate pragma% not allowed");
12846 Set_Has_Task_Name_Pragma (P, True);
12847 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12855 -- pragma Task_Storage (
12856 -- [Task_Type =>] LOCAL_NAME,
12857 -- [Top_Guard =>] static_integer_EXPRESSION);
12859 when Pragma_Task_Storage => Task_Storage : declare
12860 Args : Args_List (1 .. 2);
12861 Names : constant Name_List (1 .. 2) := (
12865 Task_Type : Node_Id renames Args (1);
12866 Top_Guard : Node_Id renames Args (2);
12872 Gather_Associations (Names, Args);
12874 if No (Task_Type) then
12876 ("missing task_type argument for pragma%");
12879 Check_Arg_Is_Local_Name (Task_Type);
12881 Ent := Entity (Task_Type);
12883 if not Is_Task_Type (Ent) then
12885 ("argument for pragma% must be task type", Task_Type);
12888 if No (Top_Guard) then
12890 ("pragma% takes two arguments", Task_Type);
12892 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12895 Check_First_Subtype (Task_Type);
12897 if Rep_Item_Too_Late (Ent, N) then
12902 --------------------------
12903 -- Thread_Local_Storage --
12904 --------------------------
12906 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12908 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
12914 Check_Arg_Count (1);
12915 Check_Optional_Identifier (Arg1, Name_Entity);
12916 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12918 Id := Get_Pragma_Arg (Arg1);
12921 if not Is_Entity_Name (Id)
12922 or else Ekind (Entity (Id)) /= E_Variable
12924 Error_Pragma_Arg ("local variable name required", Arg1);
12929 if Rep_Item_Too_Early (E, N)
12930 or else Rep_Item_Too_Late (E, N)
12935 Set_Has_Pragma_Thread_Local_Storage (E);
12936 Set_Has_Gigi_Rep_Item (E);
12937 end Thread_Local_Storage;
12943 -- pragma Time_Slice (static_duration_EXPRESSION);
12945 when Pragma_Time_Slice => Time_Slice : declare
12951 Check_Arg_Count (1);
12952 Check_No_Identifiers;
12953 Check_In_Main_Program;
12954 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
12956 if not Error_Posted (Arg1) then
12958 while Present (Nod) loop
12959 if Nkind (Nod) = N_Pragma
12960 and then Pragma_Name (Nod) = Name_Time_Slice
12962 Error_Msg_Name_1 := Pname;
12963 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12970 -- Process only if in main unit
12972 if Get_Source_Unit (Loc) = Main_Unit then
12973 Opt.Time_Slice_Set := True;
12974 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
12976 if Val <= Ureal_0 then
12977 Opt.Time_Slice_Value := 0;
12979 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
12980 Opt.Time_Slice_Value := 1_000_000_000;
12983 Opt.Time_Slice_Value :=
12984 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
12993 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
12995 -- TITLING_OPTION ::=
12996 -- [Title =>] STRING_LITERAL
12997 -- | [Subtitle =>] STRING_LITERAL
12999 when Pragma_Title => Title : declare
13000 Args : Args_List (1 .. 2);
13001 Names : constant Name_List (1 .. 2) := (
13007 Gather_Associations (Names, Args);
13010 for J in 1 .. 2 loop
13011 if Present (Args (J)) then
13012 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13017 ---------------------
13018 -- Unchecked_Union --
13019 ---------------------
13021 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13023 when Pragma_Unchecked_Union => Unchecked_Union : declare
13024 Assoc : constant Node_Id := Arg1;
13025 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13036 Check_No_Identifiers;
13037 Check_Arg_Count (1);
13038 Check_Arg_Is_Local_Name (Arg1);
13040 Find_Type (Type_Id);
13041 Typ := Entity (Type_Id);
13044 or else Rep_Item_Too_Early (Typ, N)
13048 Typ := Underlying_Type (Typ);
13051 if Rep_Item_Too_Late (Typ, N) then
13055 Check_First_Subtype (Arg1);
13057 -- Note remaining cases are references to a type in the current
13058 -- declarative part. If we find an error, we post the error on
13059 -- the relevant type declaration at an appropriate point.
13061 if not Is_Record_Type (Typ) then
13062 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13065 elsif Is_Tagged_Type (Typ) then
13066 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13069 elsif Is_Limited_Type (Typ) then
13071 ("Unchecked_Union must not be limited record type", Typ);
13072 Explain_Limited_Type (Typ, Typ);
13076 if not Has_Discriminants (Typ) then
13078 ("Unchecked_Union must have one discriminant", Typ);
13082 Discr := First_Discriminant (Typ);
13083 while Present (Discr) loop
13084 if No (Discriminant_Default_Value (Discr)) then
13086 ("Unchecked_Union discriminant must have default value",
13090 Next_Discriminant (Discr);
13093 Tdef := Type_Definition (Declaration_Node (Typ));
13094 Clist := Component_List (Tdef);
13096 Comp := First (Component_Items (Clist));
13097 while Present (Comp) loop
13098 Check_Component (Comp, Typ);
13102 if No (Clist) or else No (Variant_Part (Clist)) then
13104 ("Unchecked_Union must have variant part",
13109 Vpart := Variant_Part (Clist);
13111 Variant := First (Variants (Vpart));
13112 while Present (Variant) loop
13113 Check_Variant (Variant, Typ);
13118 Set_Is_Unchecked_Union (Typ, Sense);
13121 Set_Convention (Typ, Convention_C);
13124 Set_Has_Unchecked_Union (Base_Type (Typ), Sense);
13125 Set_Is_Unchecked_Union (Base_Type (Typ), Sense);
13126 end Unchecked_Union;
13128 ------------------------
13129 -- Unimplemented_Unit --
13130 ------------------------
13132 -- pragma Unimplemented_Unit;
13134 -- Note: this only gives an error if we are generating code, or if
13135 -- we are in a generic library unit (where the pragma appears in the
13136 -- body, not in the spec).
13138 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13139 Cunitent : constant Entity_Id :=
13140 Cunit_Entity (Get_Source_Unit (Loc));
13141 Ent_Kind : constant Entity_Kind :=
13146 Check_Arg_Count (0);
13148 if Operating_Mode = Generate_Code
13149 or else Ent_Kind = E_Generic_Function
13150 or else Ent_Kind = E_Generic_Procedure
13151 or else Ent_Kind = E_Generic_Package
13153 Get_Name_String (Chars (Cunitent));
13154 Set_Casing (Mixed_Case);
13155 Write_Str (Name_Buffer (1 .. Name_Len));
13156 Write_Str (" is not supported in this configuration");
13158 raise Unrecoverable_Error;
13160 end Unimplemented_Unit;
13162 ------------------------
13163 -- Universal_Aliasing --
13164 ------------------------
13166 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13168 when Pragma_Universal_Aliasing => Universal_Alias : declare
13173 Check_Arg_Count (1);
13174 Check_Optional_Identifier (Arg2, Name_Entity);
13175 Check_Arg_Is_Local_Name (Arg1);
13176 E_Id := Entity (Get_Pragma_Arg (Arg1));
13178 if E_Id = Any_Type then
13180 elsif No (E_Id) or else not Is_Type (E_Id) then
13181 Error_Pragma_Arg ("pragma% requires type", Arg1);
13184 Set_Universal_Aliasing (Implementation_Base_Type (E_Id), Sense);
13185 end Universal_Alias;
13187 --------------------
13188 -- Universal_Data --
13189 --------------------
13191 -- pragma Universal_Data [(library_unit_NAME)];
13193 when Pragma_Universal_Data =>
13196 -- If this is a configuration pragma, then set the universal
13197 -- addressing option, otherwise confirm that the pragma satisfies
13198 -- the requirements of library unit pragma placement and leave it
13199 -- to the GNAAMP back end to detect the pragma (avoids transitive
13200 -- setting of the option due to withed units).
13202 if Is_Configuration_Pragma then
13203 Universal_Addressing_On_AAMP := True;
13205 Check_Valid_Library_Unit_Pragma;
13208 if not AAMP_On_Target then
13209 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13216 -- pragma Unmodified (local_Name {, local_Name});
13218 when Pragma_Unmodified => Unmodified : declare
13219 Arg_Node : Node_Id;
13220 Arg_Expr : Node_Id;
13221 Arg_Ent : Entity_Id;
13225 Check_At_Least_N_Arguments (1);
13227 -- Loop through arguments
13230 while Present (Arg_Node) loop
13231 Check_No_Identifier (Arg_Node);
13233 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13234 -- in fact generate reference, so that the entity will have a
13235 -- reference, which will inhibit any warnings about it not
13236 -- being referenced, and also properly show up in the ali file
13237 -- as a reference. But this reference is recorded before the
13238 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13239 -- generated for this reference.
13241 Check_Arg_Is_Local_Name (Arg_Node);
13242 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13244 if Is_Entity_Name (Arg_Expr) then
13245 Arg_Ent := Entity (Arg_Expr);
13247 if not Is_Assignable (Arg_Ent) then
13249 ("pragma% can only be applied to a variable",
13252 Set_Has_Pragma_Unmodified (Arg_Ent, Sense);
13264 -- pragma Unreferenced (local_Name {, local_Name});
13266 -- or when used in a context clause:
13268 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13270 when Pragma_Unreferenced => Unreferenced : declare
13271 Arg_Node : Node_Id;
13272 Arg_Expr : Node_Id;
13273 Arg_Ent : Entity_Id;
13278 Check_At_Least_N_Arguments (1);
13280 -- Check case of appearing within context clause
13282 if Is_In_Context_Clause then
13284 -- The arguments must all be units mentioned in a with clause
13285 -- in the same context clause. Note we already checked (in
13286 -- Par.Prag) that the arguments are either identifiers or
13287 -- selected components.
13290 while Present (Arg_Node) loop
13291 Citem := First (List_Containing (N));
13292 while Citem /= N loop
13293 if Nkind (Citem) = N_With_Clause
13295 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13297 Set_Has_Pragma_Unreferenced
13300 (Library_Unit (Citem))));
13302 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13311 ("argument of pragma% is not with'ed unit", Arg_Node);
13317 -- Case of not in list of context items
13321 while Present (Arg_Node) loop
13322 Check_No_Identifier (Arg_Node);
13324 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13325 -- will in fact generate reference, so that the entity will
13326 -- have a reference, which will inhibit any warnings about
13327 -- it not being referenced, and also properly show up in the
13328 -- ali file as a reference. But this reference is recorded
13329 -- before the Has_Pragma_Unreferenced flag is set, so that
13330 -- no warning is generated for this reference.
13332 Check_Arg_Is_Local_Name (Arg_Node);
13333 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13335 if Is_Entity_Name (Arg_Expr) then
13336 Arg_Ent := Entity (Arg_Expr);
13338 -- If the entity is overloaded, the pragma applies to the
13339 -- most recent overloading, as documented. In this case,
13340 -- name resolution does not generate a reference, so it
13341 -- must be done here explicitly.
13343 if Is_Overloaded (Arg_Expr) then
13344 Generate_Reference (Arg_Ent, N);
13347 Set_Has_Pragma_Unreferenced (Arg_Ent, Sense);
13355 --------------------------
13356 -- Unreferenced_Objects --
13357 --------------------------
13359 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13361 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13362 Arg_Node : Node_Id;
13363 Arg_Expr : Node_Id;
13367 Check_At_Least_N_Arguments (1);
13370 while Present (Arg_Node) loop
13371 Check_No_Identifier (Arg_Node);
13372 Check_Arg_Is_Local_Name (Arg_Node);
13373 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13375 if not Is_Entity_Name (Arg_Expr)
13376 or else not Is_Type (Entity (Arg_Expr))
13379 ("argument for pragma% must be type or subtype", Arg_Node);
13382 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr), Sense);
13385 end Unreferenced_Objects;
13387 ------------------------------
13388 -- Unreserve_All_Interrupts --
13389 ------------------------------
13391 -- pragma Unreserve_All_Interrupts;
13393 when Pragma_Unreserve_All_Interrupts =>
13395 Check_Arg_Count (0);
13397 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13398 Unreserve_All_Interrupts := True;
13405 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13407 when Pragma_Unsuppress =>
13409 Process_Suppress_Unsuppress (False);
13411 -------------------
13412 -- Use_VADS_Size --
13413 -------------------
13415 -- pragma Use_VADS_Size;
13417 when Pragma_Use_VADS_Size =>
13419 Check_Arg_Count (0);
13420 Check_Valid_Configuration_Pragma;
13421 Use_VADS_Size := True;
13423 ---------------------
13424 -- Validity_Checks --
13425 ---------------------
13427 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13429 when Pragma_Validity_Checks => Validity_Checks : declare
13430 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13436 Check_Arg_Count (1);
13437 Check_No_Identifiers;
13439 if Nkind (A) = N_String_Literal then
13443 Slen : constant Natural := Natural (String_Length (S));
13444 Options : String (1 .. Slen);
13450 C := Get_String_Char (S, Int (J));
13451 exit when not In_Character_Range (C);
13452 Options (J) := Get_Character (C);
13455 Set_Validity_Check_Options (Options);
13463 elsif Nkind (A) = N_Identifier then
13465 if Chars (A) = Name_All_Checks then
13466 Set_Validity_Check_Options ("a");
13468 elsif Chars (A) = Name_On then
13469 Validity_Checks_On := True;
13471 elsif Chars (A) = Name_Off then
13472 Validity_Checks_On := False;
13476 end Validity_Checks;
13482 -- pragma Volatile (LOCAL_NAME);
13484 when Pragma_Volatile =>
13485 Process_Atomic_Shared_Volatile;
13487 -------------------------
13488 -- Volatile_Components --
13489 -------------------------
13491 -- pragma Volatile_Components (array_LOCAL_NAME);
13493 -- Volatile is handled by the same circuit as Atomic_Components
13499 -- pragma Warnings (On | Off);
13500 -- pragma Warnings (On | Off, LOCAL_NAME);
13501 -- pragma Warnings (static_string_EXPRESSION);
13502 -- pragma Warnings (On | Off, STRING_LITERAL);
13504 when Pragma_Warnings => Warnings : begin
13506 Check_At_Least_N_Arguments (1);
13507 Check_No_Identifiers;
13509 -- If debug flag -gnatd.i is set, pragma is ignored
13511 if Debug_Flag_Dot_I then
13515 -- Process various forms of the pragma
13518 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13521 -- One argument case
13523 if Arg_Count = 1 then
13525 -- On/Off one argument case was processed by parser
13527 if Nkind (Argx) = N_Identifier
13529 (Chars (Argx) = Name_On
13531 Chars (Argx) = Name_Off)
13535 -- One argument case must be ON/OFF or static string expr
13537 elsif not Is_Static_String_Expression (Arg1) then
13539 ("argument of pragma% must be On/Off or " &
13540 "static string expression", Arg1);
13542 -- One argument string expression case
13546 Lit : constant Node_Id := Expr_Value_S (Argx);
13547 Str : constant String_Id := Strval (Lit);
13548 Len : constant Nat := String_Length (Str);
13556 while J <= Len loop
13557 C := Get_String_Char (Str, J);
13558 OK := In_Character_Range (C);
13561 Chr := Get_Character (C);
13565 if J < Len and then Chr = '.' then
13567 C := Get_String_Char (Str, J);
13568 Chr := Get_Character (C);
13570 if not Set_Dot_Warning_Switch (Chr) then
13572 ("invalid warning switch character " &
13579 OK := Set_Warning_Switch (Chr);
13585 ("invalid warning switch character " & Chr,
13594 -- Two or more arguments (must be two)
13597 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13598 Check_At_Most_N_Arguments (2);
13606 E_Id := Get_Pragma_Arg (Arg2);
13609 -- In the expansion of an inlined body, a reference to
13610 -- the formal may be wrapped in a conversion if the
13611 -- actual is a conversion. Retrieve the real entity name.
13613 if (In_Instance_Body
13614 or else In_Inlined_Body)
13615 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13617 E_Id := Expression (E_Id);
13620 -- Entity name case
13622 if Is_Entity_Name (E_Id) then
13623 E := Entity (E_Id);
13630 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13633 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13634 and then Warn_On_Warnings_Off
13636 Warnings_Off_Pragmas.Append ((N, E));
13639 if Is_Enumeration_Type (E) then
13643 Lit := First_Literal (E);
13644 while Present (Lit) loop
13645 Set_Warnings_Off (Lit);
13646 Next_Literal (Lit);
13651 exit when No (Homonym (E));
13656 -- Error if not entity or static string literal case
13658 elsif not Is_Static_String_Expression (Arg2) then
13660 ("second argument of pragma% must be entity " &
13661 "name or static string expression", Arg2);
13663 -- String literal case
13666 String_To_Name_Buffer
13667 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13669 -- Note on configuration pragma case: If this is a
13670 -- configuration pragma, then for an OFF pragma, we
13671 -- just set Config True in the call, which is all
13672 -- that needs to be done. For the case of ON, this
13673 -- is normally an error, unless it is canceling the
13674 -- effect of a previous OFF pragma in the same file.
13675 -- In any other case, an error will be signalled (ON
13676 -- with no matching OFF).
13678 if Chars (Argx) = Name_Off then
13679 Set_Specific_Warning_Off
13680 (Loc, Name_Buffer (1 .. Name_Len),
13681 Config => Is_Configuration_Pragma);
13683 elsif Chars (Argx) = Name_On then
13684 Set_Specific_Warning_On
13685 (Loc, Name_Buffer (1 .. Name_Len), Err);
13689 ("?pragma Warnings On with no " &
13690 "matching Warnings Off",
13700 -------------------
13701 -- Weak_External --
13702 -------------------
13704 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13706 when Pragma_Weak_External => Weak_External : declare
13711 Check_Arg_Count (1);
13712 Check_Optional_Identifier (Arg1, Name_Entity);
13713 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13714 Ent := Entity (Get_Pragma_Arg (Arg1));
13716 if Rep_Item_Too_Early (Ent, N) then
13719 Ent := Underlying_Type (Ent);
13722 -- The only processing required is to link this item on to the
13723 -- list of rep items for the given entity. This is accomplished
13724 -- by the call to Rep_Item_Too_Late (when no error is detected
13725 -- and False is returned).
13727 if Rep_Item_Too_Late (Ent, N) then
13730 Set_Has_Gigi_Rep_Item (Ent);
13734 -----------------------------
13735 -- Wide_Character_Encoding --
13736 -----------------------------
13738 -- pragma Wide_Character_Encoding (IDENTIFIER);
13740 when Pragma_Wide_Character_Encoding =>
13743 -- Nothing to do, handled in parser. Note that we do not enforce
13744 -- configuration pragma placement, this pragma can appear at any
13745 -- place in the source, allowing mixed encodings within a single
13750 --------------------
13751 -- Unknown_Pragma --
13752 --------------------
13754 -- Should be impossible, since the case of an unknown pragma is
13755 -- separately processed before the case statement is entered.
13757 when Unknown_Pragma =>
13758 raise Program_Error;
13761 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13762 -- until AI is formally approved.
13764 -- Check_Order_Dependence;
13767 when Pragma_Exit => null;
13768 end Analyze_Pragma;
13770 -------------------
13771 -- Check_Enabled --
13772 -------------------
13774 function Check_Enabled (Nam : Name_Id) return Boolean is
13778 -- Loop through entries in check policy list
13780 PP := Opt.Check_Policy_List;
13782 -- If there are no specific entries that matched, then we let the
13783 -- setting of assertions govern. Note that this provides the needed
13784 -- compatibility with the RM for the cases of assertion, invariant,
13785 -- precondition, predicate, and postcondition.
13788 return Assertions_Enabled;
13790 -- Here we have an entry see if it matches
13794 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13797 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13798 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13799 when Name_On | Name_Check =>
13801 when Name_Off | Name_Ignore =>
13804 raise Program_Error;
13808 PP := Next_Pragma (PP);
13815 ---------------------------------
13816 -- Delay_Config_Pragma_Analyze --
13817 ---------------------------------
13819 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13821 return Pragma_Name (N) = Name_Interrupt_State
13823 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13824 end Delay_Config_Pragma_Analyze;
13826 -------------------------
13827 -- Get_Base_Subprogram --
13828 -------------------------
13830 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13831 Result : Entity_Id;
13834 -- Follow subprogram renaming chain
13837 while Is_Subprogram (Result)
13839 (Is_Generic_Instance (Result)
13840 or else Nkind (Parent (Declaration_Node (Result))) =
13841 N_Subprogram_Renaming_Declaration)
13842 and then Present (Alias (Result))
13844 Result := Alias (Result);
13848 end Get_Base_Subprogram;
13854 procedure Initialize is
13859 -----------------------------
13860 -- Is_Config_Static_String --
13861 -----------------------------
13863 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13865 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13866 -- This is an internal recursive function that is just like the outer
13867 -- function except that it adds the string to the name buffer rather
13868 -- than placing the string in the name buffer.
13870 ------------------------------
13871 -- Add_Config_Static_String --
13872 ------------------------------
13874 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13881 if Nkind (N) = N_Op_Concat then
13882 if Add_Config_Static_String (Left_Opnd (N)) then
13883 N := Right_Opnd (N);
13889 if Nkind (N) /= N_String_Literal then
13890 Error_Msg_N ("string literal expected for pragma argument", N);
13894 for J in 1 .. String_Length (Strval (N)) loop
13895 C := Get_String_Char (Strval (N), J);
13897 if not In_Character_Range (C) then
13899 ("string literal contains invalid wide character",
13900 Sloc (N) + 1 + Source_Ptr (J));
13904 Add_Char_To_Name_Buffer (Get_Character (C));
13909 end Add_Config_Static_String;
13911 -- Start of processing for Is_Config_Static_String
13916 return Add_Config_Static_String (Arg);
13917 end Is_Config_Static_String;
13919 -----------------------------------------
13920 -- Is_Non_Significant_Pragma_Reference --
13921 -----------------------------------------
13923 -- This function makes use of the following static table which indicates
13924 -- whether a given pragma is significant.
13926 -- -1 indicates that references in any argument position are significant
13927 -- 0 indicates that appearence in any argument is not significant
13928 -- +n indicates that appearence as argument n is significant, but all
13929 -- other arguments are not significant
13930 -- 99 special processing required (e.g. for pragma Check)
13932 Sig_Flags : constant array (Pragma_Id) of Int :=
13933 (Pragma_AST_Entry => -1,
13934 Pragma_Abort_Defer => -1,
13935 Pragma_Ada_83 => -1,
13936 Pragma_Ada_95 => -1,
13937 Pragma_Ada_05 => -1,
13938 Pragma_Ada_2005 => -1,
13939 Pragma_Ada_12 => -1,
13940 Pragma_Ada_2012 => -1,
13941 Pragma_All_Calls_Remote => -1,
13942 Pragma_Annotate => -1,
13943 Pragma_Assert => -1,
13944 Pragma_Assertion_Policy => 0,
13945 Pragma_Assume_No_Invalid_Values => 0,
13946 Pragma_Asynchronous => -1,
13947 Pragma_Atomic => 0,
13948 Pragma_Atomic_Components => 0,
13949 Pragma_Attach_Handler => -1,
13950 Pragma_Check => 99,
13951 Pragma_Check_Name => 0,
13952 Pragma_Check_Policy => 0,
13953 Pragma_CIL_Constructor => -1,
13954 Pragma_CPP_Class => 0,
13955 Pragma_CPP_Constructor => 0,
13956 Pragma_CPP_Virtual => 0,
13957 Pragma_CPP_Vtable => 0,
13959 Pragma_C_Pass_By_Copy => 0,
13960 Pragma_Comment => 0,
13961 Pragma_Common_Object => -1,
13962 Pragma_Compile_Time_Error => -1,
13963 Pragma_Compile_Time_Warning => -1,
13964 Pragma_Compiler_Unit => 0,
13965 Pragma_Complete_Representation => 0,
13966 Pragma_Complex_Representation => 0,
13967 Pragma_Component_Alignment => -1,
13968 Pragma_Controlled => 0,
13969 Pragma_Convention => 0,
13970 Pragma_Convention_Identifier => 0,
13971 Pragma_Debug => -1,
13972 Pragma_Debug_Policy => 0,
13973 Pragma_Detect_Blocking => -1,
13974 Pragma_Default_Storage_Pool => -1,
13975 Pragma_Dimension => -1,
13976 Pragma_Discard_Names => 0,
13977 Pragma_Elaborate => -1,
13978 Pragma_Elaborate_All => -1,
13979 Pragma_Elaborate_Body => -1,
13980 Pragma_Elaboration_Checks => -1,
13981 Pragma_Eliminate => -1,
13982 Pragma_Export => -1,
13983 Pragma_Export_Exception => -1,
13984 Pragma_Export_Function => -1,
13985 Pragma_Export_Object => -1,
13986 Pragma_Export_Procedure => -1,
13987 Pragma_Export_Value => -1,
13988 Pragma_Export_Valued_Procedure => -1,
13989 Pragma_Extend_System => -1,
13990 Pragma_Extensions_Allowed => -1,
13991 Pragma_External => -1,
13992 Pragma_Favor_Top_Level => -1,
13993 Pragma_External_Name_Casing => -1,
13994 Pragma_Fast_Math => -1,
13995 Pragma_Finalize_Storage_Only => 0,
13996 Pragma_Float_Representation => 0,
13997 Pragma_Ident => -1,
13998 Pragma_Implemented => -1,
13999 Pragma_Implicit_Packing => 0,
14000 Pragma_Import => +2,
14001 Pragma_Import_Exception => 0,
14002 Pragma_Import_Function => 0,
14003 Pragma_Import_Object => 0,
14004 Pragma_Import_Procedure => 0,
14005 Pragma_Import_Valued_Procedure => 0,
14006 Pragma_Independent => 0,
14007 Pragma_Independent_Components => 0,
14008 Pragma_Initialize_Scalars => -1,
14009 Pragma_Inline => 0,
14010 Pragma_Inline_Always => 0,
14011 Pragma_Inline_Generic => 0,
14012 Pragma_Inspection_Point => -1,
14013 Pragma_Interface => +2,
14014 Pragma_Interface_Name => +2,
14015 Pragma_Interrupt_Handler => -1,
14016 Pragma_Interrupt_Priority => -1,
14017 Pragma_Interrupt_State => -1,
14018 Pragma_Invariant => -1,
14019 Pragma_Java_Constructor => -1,
14020 Pragma_Java_Interface => -1,
14021 Pragma_Keep_Names => 0,
14022 Pragma_License => -1,
14023 Pragma_Link_With => -1,
14024 Pragma_Linker_Alias => -1,
14025 Pragma_Linker_Constructor => -1,
14026 Pragma_Linker_Destructor => -1,
14027 Pragma_Linker_Options => -1,
14028 Pragma_Linker_Section => -1,
14030 Pragma_Locking_Policy => -1,
14031 Pragma_Long_Float => -1,
14032 Pragma_Machine_Attribute => -1,
14034 Pragma_Main_Storage => -1,
14035 Pragma_Memory_Size => -1,
14036 Pragma_No_Return => 0,
14037 Pragma_No_Body => 0,
14038 Pragma_No_Run_Time => -1,
14039 Pragma_No_Strict_Aliasing => -1,
14040 Pragma_Normalize_Scalars => -1,
14041 Pragma_Obsolescent => 0,
14042 Pragma_Optimize => -1,
14043 Pragma_Optimize_Alignment => -1,
14044 Pragma_Ordered => 0,
14047 Pragma_Passive => -1,
14048 Pragma_Preelaborable_Initialization => -1,
14049 Pragma_Polling => -1,
14050 Pragma_Persistent_BSS => 0,
14051 Pragma_Postcondition => -1,
14052 Pragma_Precondition => -1,
14053 Pragma_Predicate => -1,
14054 Pragma_Preelaborate => -1,
14055 Pragma_Preelaborate_05 => -1,
14056 Pragma_Priority => -1,
14057 Pragma_Priority_Specific_Dispatching => -1,
14058 Pragma_Profile => 0,
14059 Pragma_Profile_Warnings => 0,
14060 Pragma_Propagate_Exceptions => -1,
14061 Pragma_Psect_Object => -1,
14063 Pragma_Pure_05 => -1,
14064 Pragma_Pure_Function => -1,
14065 Pragma_Queuing_Policy => -1,
14066 Pragma_Ravenscar => -1,
14067 Pragma_Relative_Deadline => -1,
14068 Pragma_Remote_Call_Interface => -1,
14069 Pragma_Remote_Types => -1,
14070 Pragma_Restricted_Run_Time => -1,
14071 Pragma_Restriction_Warnings => -1,
14072 Pragma_Restrictions => -1,
14073 Pragma_Reviewable => -1,
14074 Pragma_Short_Circuit_And_Or => -1,
14075 Pragma_Share_Generic => -1,
14076 Pragma_Shared => -1,
14077 Pragma_Shared_Passive => -1,
14078 Pragma_Short_Descriptors => 0,
14079 Pragma_Source_File_Name => -1,
14080 Pragma_Source_File_Name_Project => -1,
14081 Pragma_Source_Reference => -1,
14082 Pragma_Storage_Size => -1,
14083 Pragma_Storage_Unit => -1,
14084 Pragma_Static_Elaboration_Desired => -1,
14085 Pragma_Stream_Convert => -1,
14086 Pragma_Style_Checks => -1,
14087 Pragma_Subtitle => -1,
14088 Pragma_Suppress => 0,
14089 Pragma_Suppress_Exception_Locations => 0,
14090 Pragma_Suppress_All => -1,
14091 Pragma_Suppress_Debug_Info => 0,
14092 Pragma_Suppress_Initialization => 0,
14093 Pragma_System_Name => -1,
14094 Pragma_Task_Dispatching_Policy => -1,
14095 Pragma_Task_Info => -1,
14096 Pragma_Task_Name => -1,
14097 Pragma_Task_Storage => 0,
14098 Pragma_Thread_Local_Storage => 0,
14099 Pragma_Time_Slice => -1,
14100 Pragma_Title => -1,
14101 Pragma_Unchecked_Union => 0,
14102 Pragma_Unimplemented_Unit => -1,
14103 Pragma_Universal_Aliasing => -1,
14104 Pragma_Universal_Data => -1,
14105 Pragma_Unmodified => -1,
14106 Pragma_Unreferenced => -1,
14107 Pragma_Unreferenced_Objects => -1,
14108 Pragma_Unreserve_All_Interrupts => -1,
14109 Pragma_Unsuppress => 0,
14110 Pragma_Use_VADS_Size => -1,
14111 Pragma_Validity_Checks => -1,
14112 Pragma_Volatile => 0,
14113 Pragma_Volatile_Components => 0,
14114 Pragma_Warnings => -1,
14115 Pragma_Weak_External => -1,
14116 Pragma_Wide_Character_Encoding => 0,
14117 Unknown_Pragma => 0);
14119 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14128 if Nkind (P) /= N_Pragma_Argument_Association then
14132 Id := Get_Pragma_Id (Parent (P));
14133 C := Sig_Flags (Id);
14145 -- For pragma Check, the first argument is not significant,
14146 -- the second and the third (if present) arguments are
14149 when Pragma_Check =>
14151 P = First (Pragma_Argument_Associations (Parent (P)));
14154 raise Program_Error;
14158 A := First (Pragma_Argument_Associations (Parent (P)));
14159 for J in 1 .. C - 1 loop
14167 return A = P; -- is this wrong way round ???
14170 end Is_Non_Significant_Pragma_Reference;
14172 ------------------------------
14173 -- Is_Pragma_String_Literal --
14174 ------------------------------
14176 -- This function returns true if the corresponding pragma argument is a
14177 -- static string expression. These are the only cases in which string
14178 -- literals can appear as pragma arguments. We also allow a string literal
14179 -- as the first argument to pragma Assert (although it will of course
14180 -- always generate a type error).
14182 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14183 Pragn : constant Node_Id := Parent (Par);
14184 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14185 Pname : constant Name_Id := Pragma_Name (Pragn);
14191 N := First (Assoc);
14198 if Pname = Name_Assert then
14201 elsif Pname = Name_Export then
14204 elsif Pname = Name_Ident then
14207 elsif Pname = Name_Import then
14210 elsif Pname = Name_Interface_Name then
14213 elsif Pname = Name_Linker_Alias then
14216 elsif Pname = Name_Linker_Section then
14219 elsif Pname = Name_Machine_Attribute then
14222 elsif Pname = Name_Source_File_Name then
14225 elsif Pname = Name_Source_Reference then
14228 elsif Pname = Name_Title then
14231 elsif Pname = Name_Subtitle then
14237 end Is_Pragma_String_Literal;
14239 --------------------------------------
14240 -- Process_Compilation_Unit_Pragmas --
14241 --------------------------------------
14243 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14245 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14246 -- strange because it comes at the end of the unit. Rational has the
14247 -- same name for a pragma, but treats it as a program unit pragma, In
14248 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14249 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14250 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14251 -- the context clause to ensure the correct processing.
14253 if Has_Pragma_Suppress_All (N) then
14254 Prepend_To (Context_Items (N),
14255 Make_Pragma (Sloc (N),
14256 Chars => Name_Suppress,
14257 Pragma_Argument_Associations => New_List (
14258 Make_Pragma_Argument_Association (Sloc (N),
14260 Make_Identifier (Sloc (N),
14261 Chars => Name_All_Checks)))));
14264 -- Nothing else to do at the current time!
14266 end Process_Compilation_Unit_Pragmas;
14277 --------------------------------
14278 -- Set_Encoded_Interface_Name --
14279 --------------------------------
14281 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14282 Str : constant String_Id := Strval (S);
14283 Len : constant Int := String_Length (Str);
14288 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14291 -- Stores encoded value of character code CC. The encoding we use an
14292 -- underscore followed by four lower case hex digits.
14298 procedure Encode is
14300 Store_String_Char (Get_Char_Code ('_'));
14302 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14304 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14306 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14308 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14311 -- Start of processing for Set_Encoded_Interface_Name
14314 -- If first character is asterisk, this is a link name, and we leave it
14315 -- completely unmodified. We also ignore null strings (the latter case
14316 -- happens only in error cases) and no encoding should occur for Java or
14317 -- AAMP interface names.
14320 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14321 or else VM_Target /= No_VM
14322 or else AAMP_On_Target
14324 Set_Interface_Name (E, S);
14329 CC := Get_String_Char (Str, J);
14331 exit when not In_Character_Range (CC);
14333 C := Get_Character (CC);
14335 exit when C /= '_' and then C /= '$'
14336 and then C not in '0' .. '9'
14337 and then C not in 'a' .. 'z'
14338 and then C not in 'A' .. 'Z';
14341 Set_Interface_Name (E, S);
14349 -- Here we need to encode. The encoding we use as follows:
14350 -- three underscores + four hex digits (lower case)
14354 for J in 1 .. String_Length (Str) loop
14355 CC := Get_String_Char (Str, J);
14357 if not In_Character_Range (CC) then
14360 C := Get_Character (CC);
14362 if C = '_' or else C = '$'
14363 or else C in '0' .. '9'
14364 or else C in 'a' .. 'z'
14365 or else C in 'A' .. 'Z'
14367 Store_String_Char (CC);
14374 Set_Interface_Name (E,
14375 Make_String_Literal (Sloc (S),
14376 Strval => End_String));
14378 end Set_Encoded_Interface_Name;
14380 -------------------
14381 -- Set_Unit_Name --
14382 -------------------
14384 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14389 if Nkind (N) = N_Identifier
14390 and then Nkind (With_Item) = N_Identifier
14392 Set_Entity (N, Entity (With_Item));
14394 elsif Nkind (N) = N_Selected_Component then
14395 Change_Selected_Component_To_Expanded_Name (N);
14396 Set_Entity (N, Entity (With_Item));
14397 Set_Entity (Selector_Name (N), Entity (N));
14399 Pref := Prefix (N);
14400 Scop := Scope (Entity (N));
14401 while Nkind (Pref) = N_Selected_Component loop
14402 Change_Selected_Component_To_Expanded_Name (Pref);
14403 Set_Entity (Selector_Name (Pref), Scop);
14404 Set_Entity (Pref, Scop);
14405 Pref := Prefix (Pref);
14406 Scop := Scope (Scop);
14409 Set_Entity (Pref, Scop);