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_No_Link_Name;
440 -- Checks that no link name is specified
442 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
443 -- Checks if the given argument has an identifier, and if so, requires
444 -- it to match the given identifier name. If there is a non-matching
445 -- identifier, then an error message is given and Error_Pragmas raised.
447 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
448 -- Checks if the given argument has an identifier, and if so, requires
449 -- it to match the given identifier name. If there is a non-matching
450 -- identifier, then an error message is given and Error_Pragmas raised.
451 -- In this version of the procedure, the identifier name is given as
452 -- a string with lower case letters.
454 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
455 -- Called to process a precondition or postcondition pragma. There are
458 -- The pragma appears after a subprogram spec
460 -- If the corresponding check is not enabled, the pragma is analyzed
461 -- but otherwise ignored and control returns with In_Body set False.
463 -- If the check is enabled, then the first step is to analyze the
464 -- pragma, but this is skipped if the subprogram spec appears within
465 -- a package specification (because this is the case where we delay
466 -- analysis till the end of the spec). Then (whether or not it was
467 -- analyzed), the pragma is chained to the subprogram in question
468 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
469 -- caller with In_Body set False.
471 -- The pragma appears at the start of subprogram body declarations
473 -- In this case an immediate return to the caller is made with
474 -- In_Body set True, and the pragma is NOT analyzed.
476 -- In all other cases, an error message for bad placement is given
478 procedure Check_Static_Constraint (Constr : Node_Id);
479 -- Constr is a constraint from an N_Subtype_Indication node from a
480 -- component constraint in an Unchecked_Union type. This routine checks
481 -- that the constraint is static as required by the restrictions for
484 procedure Check_Valid_Configuration_Pragma;
485 -- Legality checks for placement of a configuration pragma
487 procedure Check_Valid_Library_Unit_Pragma;
488 -- Legality checks for library unit pragmas. A special case arises for
489 -- pragmas in generic instances that come from copies of the original
490 -- library unit pragmas in the generic templates. In the case of other
491 -- than library level instantiations these can appear in contexts which
492 -- would normally be invalid (they only apply to the original template
493 -- and to library level instantiations), and they are simply ignored,
494 -- which is implemented by rewriting them as null statements.
496 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
497 -- Check an Unchecked_Union variant for lack of nested variants and
498 -- presence of at least one component. UU_Typ is the related Unchecked_
501 procedure Error_Pragma (Msg : String);
502 pragma No_Return (Error_Pragma);
503 -- Outputs error message for current pragma. The message contains a %
504 -- that will be replaced with the pragma name, and the flag is placed
505 -- on the pragma itself. Pragma_Exit is then raised.
507 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
508 pragma No_Return (Error_Pragma_Arg);
509 -- Outputs error message for current pragma. The message may contain
510 -- a % that will be replaced with the pragma name. The parameter Arg
511 -- may either be a pragma argument association, in which case the flag
512 -- is placed on the expression of this association, or an expression,
513 -- in which case the flag is placed directly on the expression. The
514 -- message is placed using Error_Msg_N, so the message may also contain
515 -- an & insertion character which will reference the given Arg value.
516 -- After placing the message, Pragma_Exit is raised.
518 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
519 pragma No_Return (Error_Pragma_Arg);
520 -- Similar to above form of Error_Pragma_Arg except that two messages
521 -- are provided, the second is a continuation comment starting with \.
523 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
524 pragma No_Return (Error_Pragma_Arg_Ident);
525 -- Outputs error message for current pragma. The message may contain
526 -- a % that will be replaced with the pragma name. The parameter Arg
527 -- must be a pragma argument association with a non-empty identifier
528 -- (i.e. its Chars field must be set), and the error message is placed
529 -- on the identifier. The message is placed using Error_Msg_N so
530 -- the message may also contain an & insertion character which will
531 -- reference the identifier. After placing the message, Pragma_Exit
534 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
535 pragma No_Return (Error_Pragma_Ref);
536 -- Outputs error message for current pragma. The message may contain
537 -- a % that will be replaced with the pragma name. The parameter Ref
538 -- must be an entity whose name can be referenced by & and sloc by #.
539 -- After placing the message, Pragma_Exit is raised.
541 function Find_Lib_Unit_Name return Entity_Id;
542 -- Used for a library unit pragma to find the entity to which the
543 -- library unit pragma applies, returns the entity found.
545 procedure Find_Program_Unit_Name (Id : Node_Id);
546 -- If the pragma is a compilation unit pragma, the id must denote the
547 -- compilation unit in the same compilation, and the pragma must appear
548 -- in the list of preceding or trailing pragmas. If it is a program
549 -- unit pragma that is not a compilation unit pragma, then the
550 -- identifier must be visible.
552 function Find_Unique_Parameterless_Procedure
554 Arg : Node_Id) return Entity_Id;
555 -- Used for a procedure pragma to find the unique parameterless
556 -- procedure identified by Name, returns it if it exists, otherwise
557 -- errors out and uses Arg as the pragma argument for the message.
559 procedure Fix_Error (Msg : in out String);
560 -- This is called prior to issuing an error message. Msg is a string
561 -- which typically contains the substring pragma. If the current pragma
562 -- comes from an aspect, each such "pragma" substring is replaced with
563 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
564 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
566 procedure Gather_Associations
568 Args : out Args_List);
569 -- This procedure is used to gather the arguments for a pragma that
570 -- permits arbitrary ordering of parameters using the normal rules
571 -- for named and positional parameters. The Names argument is a list
572 -- of Name_Id values that corresponds to the allowed pragma argument
573 -- association identifiers in order. The result returned in Args is
574 -- a list of corresponding expressions that are the pragma arguments.
575 -- Note that this is a list of expressions, not of pragma argument
576 -- associations (Gather_Associations has completely checked all the
577 -- optional identifiers when it returns). An entry in Args is Empty
578 -- on return if the corresponding argument is not present.
580 procedure GNAT_Pragma;
581 -- Called for all GNAT defined pragmas to check the relevant restriction
582 -- (No_Implementation_Pragmas).
584 function Is_Before_First_Decl
585 (Pragma_Node : Node_Id;
586 Decls : List_Id) return Boolean;
587 -- Return True if Pragma_Node is before the first declarative item in
588 -- Decls where Decls is the list of declarative items.
590 function Is_Configuration_Pragma return Boolean;
591 -- Determines if the placement of the current pragma is appropriate
592 -- for a configuration pragma.
594 function Is_In_Context_Clause return Boolean;
595 -- Returns True if pragma appears within the context clause of a unit,
596 -- and False for any other placement (does not generate any messages).
598 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
599 -- Analyzes the argument, and determines if it is a static string
600 -- expression, returns True if so, False if non-static or not String.
602 procedure Pragma_Misplaced;
603 pragma No_Return (Pragma_Misplaced);
604 -- Issue fatal error message for misplaced pragma
606 procedure Process_Atomic_Shared_Volatile;
607 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
608 -- Shared is an obsolete Ada 83 pragma, treated as being identical
609 -- in effect to pragma Atomic.
611 procedure Process_Compile_Time_Warning_Or_Error;
612 -- Common processing for Compile_Time_Error and Compile_Time_Warning
614 procedure Process_Convention
615 (C : out Convention_Id;
616 Ent : out Entity_Id);
617 -- Common processing for Convention, Interface, Import and Export.
618 -- Checks first two arguments of pragma, and sets the appropriate
619 -- convention value in the specified entity or entities. On return
620 -- C is the convention, Ent is the referenced entity.
622 procedure Process_Extended_Import_Export_Exception_Pragma
623 (Arg_Internal : Node_Id;
624 Arg_External : Node_Id;
627 -- Common processing for the pragmas Import/Export_Exception. The three
628 -- arguments correspond to the three named parameters of the pragma. An
629 -- argument is empty if the corresponding parameter is not present in
632 procedure Process_Extended_Import_Export_Object_Pragma
633 (Arg_Internal : Node_Id;
634 Arg_External : Node_Id;
636 -- Common processing for the pragmas Import/Export_Object. The three
637 -- arguments correspond to the three named parameters of the pragmas. An
638 -- argument is empty if the corresponding parameter is not present in
641 procedure Process_Extended_Import_Export_Internal_Arg
642 (Arg_Internal : Node_Id := Empty);
643 -- Common processing for all extended Import and Export pragmas. The
644 -- argument is the pragma parameter for the Internal argument. If
645 -- Arg_Internal is empty or inappropriate, an error message is posted.
646 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
647 -- set to identify the referenced entity.
649 procedure Process_Extended_Import_Export_Subprogram_Pragma
650 (Arg_Internal : Node_Id;
651 Arg_External : Node_Id;
652 Arg_Parameter_Types : Node_Id;
653 Arg_Result_Type : Node_Id := Empty;
654 Arg_Mechanism : Node_Id;
655 Arg_Result_Mechanism : Node_Id := Empty;
656 Arg_First_Optional_Parameter : Node_Id := Empty);
657 -- Common processing for all extended Import and Export pragmas applying
658 -- to subprograms. The caller omits any arguments that do not apply to
659 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
660 -- only in the Import_Function and Export_Function cases). The argument
661 -- names correspond to the allowed pragma association identifiers.
663 procedure Process_Generic_List;
664 -- Common processing for Share_Generic and Inline_Generic
666 procedure Process_Import_Or_Interface;
667 -- Common processing for Import of Interface
669 procedure Process_Inline (Active : Boolean);
670 -- Common processing for Inline and Inline_Always. The parameter
671 -- indicates if the inline pragma is active, i.e. if it should actually
672 -- cause inlining to occur.
674 procedure Process_Interface_Name
675 (Subprogram_Def : Entity_Id;
678 -- Given the last two arguments of pragma Import, pragma Export, or
679 -- pragma Interface_Name, performs validity checks and sets the
680 -- Interface_Name field of the given subprogram entity to the
681 -- appropriate external or link name, depending on the arguments given.
682 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
683 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
684 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
685 -- nor Link_Arg is present, the interface name is set to the default
686 -- from the subprogram name.
688 procedure Process_Interrupt_Or_Attach_Handler;
689 -- Common processing for Interrupt and Attach_Handler pragmas
691 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
692 -- Common processing for Restrictions and Restriction_Warnings pragmas.
693 -- Warn is True for Restriction_Warnings, or for Restrictions if the
694 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
695 -- is not set in the Restrictions case.
697 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
698 -- Common processing for Suppress and Unsuppress. The boolean parameter
699 -- Suppress_Case is True for the Suppress case, and False for the
702 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
703 -- This procedure sets the Is_Exported flag for the given entity,
704 -- checking that the entity was not previously imported. Arg is
705 -- the argument that specified the entity. A check is also made
706 -- for exporting inappropriate entities.
708 procedure Set_Extended_Import_Export_External_Name
709 (Internal_Ent : Entity_Id;
710 Arg_External : Node_Id);
711 -- Common processing for all extended import export pragmas. The first
712 -- argument, Internal_Ent, is the internal entity, which has already
713 -- been checked for validity by the caller. Arg_External is from the
714 -- Import or Export pragma, and may be null if no External parameter
715 -- was present. If Arg_External is present and is a non-null string
716 -- (a null string is treated as the default), then the Interface_Name
717 -- field of Internal_Ent is set appropriately.
719 procedure Set_Imported (E : Entity_Id);
720 -- This procedure sets the Is_Imported flag for the given entity,
721 -- checking that it is not previously exported or imported.
723 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
724 -- Mech is a parameter passing mechanism (see Import_Function syntax
725 -- for MECHANISM_NAME). This routine checks that the mechanism argument
726 -- has the right form, and if not issues an error message. If the
727 -- argument has the right form then the Mechanism field of Ent is
728 -- set appropriately.
730 procedure Set_Ravenscar_Profile (N : Node_Id);
731 -- Activate the set of configuration pragmas and restrictions that make
732 -- up the Ravenscar Profile. N is the corresponding pragma node, which
733 -- is used for error messages on any constructs that violate the
736 ---------------------
737 -- Ada_2005_Pragma --
738 ---------------------
740 procedure Ada_2005_Pragma is
742 if Ada_Version <= Ada_95 then
743 Check_Restriction (No_Implementation_Pragmas, N);
747 ---------------------
748 -- Ada_2012_Pragma --
749 ---------------------
751 procedure Ada_2012_Pragma is
753 if Ada_Version <= Ada_2005 then
754 Check_Restriction (No_Implementation_Pragmas, N);
758 --------------------------
759 -- Check_Ada_83_Warning --
760 --------------------------
762 procedure Check_Ada_83_Warning is
764 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
765 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
767 end Check_Ada_83_Warning;
769 ---------------------
770 -- Check_Arg_Count --
771 ---------------------
773 procedure Check_Arg_Count (Required : Nat) is
775 if Arg_Count /= Required then
776 Error_Pragma ("wrong number of arguments for pragma%");
780 --------------------------------
781 -- Check_Arg_Is_External_Name --
782 --------------------------------
784 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
785 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
788 if Nkind (Argx) = N_Identifier then
792 Analyze_And_Resolve (Argx, Standard_String);
794 if Is_OK_Static_Expression (Argx) then
797 elsif Etype (Argx) = Any_Type then
800 -- An interesting special case, if we have a string literal and
801 -- we are in Ada 83 mode, then we allow it even though it will
802 -- not be flagged as static. This allows expected Ada 83 mode
803 -- use of external names which are string literals, even though
804 -- technically these are not static in Ada 83.
806 elsif Ada_Version = Ada_83
807 and then Nkind (Argx) = N_String_Literal
811 -- Static expression that raises Constraint_Error. This has
812 -- already been flagged, so just exit from pragma processing.
814 elsif Is_Static_Expression (Argx) then
817 -- Here we have a real error (non-static expression)
820 Error_Msg_Name_1 := Pname;
824 "argument for pragma% must be a identifier or "
825 & "static string expression!";
828 Flag_Non_Static_Expr (Msg, Argx);
833 end Check_Arg_Is_External_Name;
835 -----------------------------
836 -- Check_Arg_Is_Identifier --
837 -----------------------------
839 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
840 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
842 if Nkind (Argx) /= N_Identifier then
844 ("argument for pragma% must be identifier", Argx);
846 end Check_Arg_Is_Identifier;
848 ----------------------------------
849 -- Check_Arg_Is_Integer_Literal --
850 ----------------------------------
852 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
853 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
855 if Nkind (Argx) /= N_Integer_Literal then
857 ("argument for pragma% must be integer literal", Argx);
859 end Check_Arg_Is_Integer_Literal;
861 -------------------------------------------
862 -- Check_Arg_Is_Library_Level_Local_Name --
863 -------------------------------------------
867 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
868 -- | library_unit_NAME
870 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
872 Check_Arg_Is_Local_Name (Arg);
874 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
875 and then Comes_From_Source (N)
878 ("argument for pragma% must be library level entity", Arg);
880 end Check_Arg_Is_Library_Level_Local_Name;
882 -----------------------------
883 -- Check_Arg_Is_Local_Name --
884 -----------------------------
888 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
889 -- | library_unit_NAME
891 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
892 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
897 if Nkind (Argx) not in N_Direct_Name
898 and then (Nkind (Argx) /= N_Attribute_Reference
899 or else Present (Expressions (Argx))
900 or else Nkind (Prefix (Argx)) /= N_Identifier)
901 and then (not Is_Entity_Name (Argx)
902 or else not Is_Compilation_Unit (Entity (Argx)))
904 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
907 -- No further check required if not an entity name
909 if not Is_Entity_Name (Argx) then
915 Ent : constant Entity_Id := Entity (Argx);
916 Scop : constant Entity_Id := Scope (Ent);
918 -- Case of a pragma applied to a compilation unit: pragma must
919 -- occur immediately after the program unit in the compilation.
921 if Is_Compilation_Unit (Ent) then
923 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
925 -- Case of pragma placed immediately after spec
927 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
930 -- Case of pragma placed immediately after body
932 elsif Nkind (Decl) = N_Subprogram_Declaration
933 and then Present (Corresponding_Body (Decl))
937 (Parent (Unit_Declaration_Node
938 (Corresponding_Body (Decl))));
940 -- All other cases are illegal
947 -- Special restricted placement rule from 10.2.1(11.8/2)
949 elsif Is_Generic_Formal (Ent)
950 and then Prag_Id = Pragma_Preelaborable_Initialization
952 OK := List_Containing (N) =
953 Generic_Formal_Declarations
954 (Unit_Declaration_Node (Scop));
956 -- Default case, just check that the pragma occurs in the scope
957 -- of the entity denoted by the name.
960 OK := Current_Scope = Scop;
965 ("pragma% argument must be in same declarative part", Arg);
969 end Check_Arg_Is_Local_Name;
971 ---------------------------------
972 -- Check_Arg_Is_Locking_Policy --
973 ---------------------------------
975 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
976 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
979 Check_Arg_Is_Identifier (Argx);
981 if not Is_Locking_Policy_Name (Chars (Argx)) then
982 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
984 end Check_Arg_Is_Locking_Policy;
986 -------------------------
987 -- Check_Arg_Is_One_Of --
988 -------------------------
990 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
991 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
994 Check_Arg_Is_Identifier (Argx);
996 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
997 Error_Msg_Name_2 := N1;
998 Error_Msg_Name_3 := N2;
999 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1001 end Check_Arg_Is_One_Of;
1003 procedure Check_Arg_Is_One_Of
1005 N1, N2, N3 : Name_Id)
1007 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1010 Check_Arg_Is_Identifier (Argx);
1012 if Chars (Argx) /= N1
1013 and then Chars (Argx) /= N2
1014 and then Chars (Argx) /= N3
1016 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1018 end Check_Arg_Is_One_Of;
1020 procedure Check_Arg_Is_One_Of
1022 N1, N2, N3, N4 : Name_Id)
1024 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1027 Check_Arg_Is_Identifier (Argx);
1029 if Chars (Argx) /= N1
1030 and then Chars (Argx) /= N2
1031 and then Chars (Argx) /= N3
1032 and then Chars (Argx) /= N4
1034 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1036 end Check_Arg_Is_One_Of;
1037 ---------------------------------
1038 -- Check_Arg_Is_Queuing_Policy --
1039 ---------------------------------
1041 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1042 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1045 Check_Arg_Is_Identifier (Argx);
1047 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1048 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1050 end Check_Arg_Is_Queuing_Policy;
1052 ------------------------------------
1053 -- Check_Arg_Is_Static_Expression --
1054 ------------------------------------
1056 procedure Check_Arg_Is_Static_Expression
1058 Typ : Entity_Id := Empty)
1060 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1063 if Present (Typ) then
1064 Analyze_And_Resolve (Argx, Typ);
1066 Analyze_And_Resolve (Argx);
1069 if Is_OK_Static_Expression (Argx) then
1072 elsif Etype (Argx) = Any_Type then
1075 -- An interesting special case, if we have a string literal and we
1076 -- are in Ada 83 mode, then we allow it even though it will not be
1077 -- flagged as static. This allows the use of Ada 95 pragmas like
1078 -- Import in Ada 83 mode. They will of course be flagged with
1079 -- warnings as usual, but will not cause errors.
1081 elsif Ada_Version = Ada_83
1082 and then Nkind (Argx) = N_String_Literal
1086 -- Static expression that raises Constraint_Error. This has already
1087 -- been flagged, so just exit from pragma processing.
1089 elsif Is_Static_Expression (Argx) then
1092 -- Finally, we have a real error
1095 Error_Msg_Name_1 := Pname;
1099 "argument for pragma% must be a static expression!";
1102 Flag_Non_Static_Expr (Msg, Argx);
1107 end Check_Arg_Is_Static_Expression;
1109 ------------------------------------------
1110 -- Check_Arg_Is_Task_Dispatching_Policy --
1111 ------------------------------------------
1113 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1114 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1117 Check_Arg_Is_Identifier (Argx);
1119 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1121 ("& is not a valid task dispatching policy name", Argx);
1123 end Check_Arg_Is_Task_Dispatching_Policy;
1125 ---------------------
1126 -- Check_Arg_Order --
1127 ---------------------
1129 procedure Check_Arg_Order (Names : Name_List) is
1132 Highest_So_Far : Natural := 0;
1133 -- Highest index in Names seen do far
1137 for J in 1 .. Arg_Count loop
1138 if Chars (Arg) /= No_Name then
1139 for K in Names'Range loop
1140 if Chars (Arg) = Names (K) then
1141 if K < Highest_So_Far then
1142 Error_Msg_Name_1 := Pname;
1144 ("parameters out of order for pragma%", Arg);
1145 Error_Msg_Name_1 := Names (K);
1146 Error_Msg_Name_2 := Names (Highest_So_Far);
1147 Error_Msg_N ("\% must appear before %", Arg);
1151 Highest_So_Far := K;
1159 end Check_Arg_Order;
1161 --------------------------------
1162 -- Check_At_Least_N_Arguments --
1163 --------------------------------
1165 procedure Check_At_Least_N_Arguments (N : Nat) is
1167 if Arg_Count < N then
1168 Error_Pragma ("too few arguments for pragma%");
1170 end Check_At_Least_N_Arguments;
1172 -------------------------------
1173 -- Check_At_Most_N_Arguments --
1174 -------------------------------
1176 procedure Check_At_Most_N_Arguments (N : Nat) is
1179 if Arg_Count > N then
1181 for J in 1 .. N loop
1183 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1186 end Check_At_Most_N_Arguments;
1188 ---------------------
1189 -- Check_Component --
1190 ---------------------
1192 procedure Check_Component
1195 In_Variant_Part : Boolean := False)
1197 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1198 Sindic : constant Node_Id :=
1199 Subtype_Indication (Component_Definition (Comp));
1200 Typ : constant Entity_Id := Etype (Comp_Id);
1202 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1203 -- Determine whether entity Id appears inside a generic body.
1204 -- Shouldn't this be in a more general place ???
1206 -------------------------
1207 -- Inside_Generic_Body --
1208 -------------------------
1210 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1215 while Present (S) and then S /= Standard_Standard loop
1216 if Ekind (S) = E_Generic_Package
1217 and then In_Package_Body (S)
1226 end Inside_Generic_Body;
1228 -- Start of processing for Check_Component
1231 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1232 -- object constraint, then the component type shall be an Unchecked_
1235 if Nkind (Sindic) = N_Subtype_Indication
1236 and then Has_Per_Object_Constraint (Comp_Id)
1237 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1240 ("component subtype subject to per-object constraint " &
1241 "must be an Unchecked_Union", Comp);
1243 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1244 -- the body of a generic unit, or within the body of any of its
1245 -- descendant library units, no part of the type of a component
1246 -- declared in a variant_part of the unchecked union type shall be of
1247 -- a formal private type or formal private extension declared within
1248 -- the formal part of the generic unit.
1250 elsif Ada_Version >= Ada_2012
1251 and then Inside_Generic_Body (UU_Typ)
1252 and then In_Variant_Part
1253 and then Is_Private_Type (Typ)
1254 and then Is_Generic_Type (Typ)
1257 ("component of Unchecked_Union cannot be of generic type", Comp);
1259 elsif Needs_Finalization (Typ) then
1261 ("component of Unchecked_Union cannot be controlled", Comp);
1263 elsif Has_Task (Typ) then
1265 ("component of Unchecked_Union cannot have tasks", Comp);
1267 end Check_Component;
1269 ----------------------------
1270 -- Check_Duplicate_Pragma --
1271 ----------------------------
1273 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1277 -- Nothing to do if this pragma comes from an aspect specification,
1278 -- since we could not be duplicating a pragma, and we dealt with the
1279 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1281 if From_Aspect_Specification (N) then
1285 -- Otherwise current pragma may duplicate previous pragma or a
1286 -- previously given aspect specification for the same pragma.
1288 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1291 Error_Msg_Name_1 := Pragma_Name (N);
1292 Error_Msg_Sloc := Sloc (P);
1294 if Nkind (P) = N_Aspect_Specification
1295 or else From_Aspect_Specification (P)
1297 Error_Msg_NE ("aspect% for & previously given#", N, E);
1299 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1304 end Check_Duplicate_Pragma;
1306 ----------------------------------
1307 -- Check_Duplicated_Export_Name --
1308 ----------------------------------
1310 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1311 String_Val : constant String_Id := Strval (Nam);
1314 -- We are only interested in the export case, and in the case of
1315 -- generics, it is the instance, not the template, that is the
1316 -- problem (the template will generate a warning in any case).
1318 if not Inside_A_Generic
1319 and then (Prag_Id = Pragma_Export
1321 Prag_Id = Pragma_Export_Procedure
1323 Prag_Id = Pragma_Export_Valued_Procedure
1325 Prag_Id = Pragma_Export_Function)
1327 for J in Externals.First .. Externals.Last loop
1328 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1329 Error_Msg_Sloc := Sloc (Externals.Table (J));
1330 Error_Msg_N ("external name duplicates name given#", Nam);
1335 Externals.Append (Nam);
1337 end Check_Duplicated_Export_Name;
1339 -------------------------
1340 -- Check_First_Subtype --
1341 -------------------------
1343 procedure Check_First_Subtype (Arg : Node_Id) is
1344 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1345 Ent : constant Entity_Id := Entity (Argx);
1348 if Is_First_Subtype (Ent) then
1351 elsif Is_Type (Ent) then
1353 ("pragma% cannot apply to subtype", Argx);
1355 elsif Is_Object (Ent) then
1357 ("pragma% cannot apply to object, requires a type", Argx);
1361 ("pragma% cannot apply to&, requires a type", Argx);
1363 end Check_First_Subtype;
1365 ---------------------------
1366 -- Check_In_Main_Program --
1367 ---------------------------
1369 procedure Check_In_Main_Program is
1370 P : constant Node_Id := Parent (N);
1373 -- Must be at in subprogram body
1375 if Nkind (P) /= N_Subprogram_Body then
1376 Error_Pragma ("% pragma allowed only in subprogram");
1378 -- Otherwise warn if obviously not main program
1380 elsif Present (Parameter_Specifications (Specification (P)))
1381 or else not Is_Compilation_Unit (Defining_Entity (P))
1383 Error_Msg_Name_1 := Pname;
1385 ("?pragma% is only effective in main program", N);
1387 end Check_In_Main_Program;
1389 ---------------------------------------
1390 -- Check_Interrupt_Or_Attach_Handler --
1391 ---------------------------------------
1393 procedure Check_Interrupt_Or_Attach_Handler is
1394 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1395 Handler_Proc, Proc_Scope : Entity_Id;
1400 if Prag_Id = Pragma_Interrupt_Handler then
1401 Check_Restriction (No_Dynamic_Attachment, N);
1404 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1405 Proc_Scope := Scope (Handler_Proc);
1407 -- On AAMP only, a pragma Interrupt_Handler is supported for
1408 -- nonprotected parameterless procedures.
1410 if not AAMP_On_Target
1411 or else Prag_Id = Pragma_Attach_Handler
1413 if Ekind (Proc_Scope) /= E_Protected_Type then
1415 ("argument of pragma% must be protected procedure", Arg1);
1418 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1419 Error_Pragma ("pragma% must be in protected definition");
1423 if not Is_Library_Level_Entity (Proc_Scope)
1424 or else (AAMP_On_Target
1425 and then not Is_Library_Level_Entity (Handler_Proc))
1428 ("argument for pragma% must be library level entity", Arg1);
1431 -- AI05-0033: A pragma cannot appear within a generic body, because
1432 -- instance can be in a nested scope. The check that protected type
1433 -- is itself a library-level declaration is done elsewhere.
1435 -- Note: we omit this check in Codepeer mode to properly handle code
1436 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1438 if Inside_A_Generic then
1439 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1440 and then In_Package_Body (Scope (Current_Scope))
1441 and then not CodePeer_Mode
1443 Error_Pragma ("pragma% cannot be used inside a generic");
1446 end Check_Interrupt_Or_Attach_Handler;
1448 -------------------------------------------
1449 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1450 -------------------------------------------
1452 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1461 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1464 elsif Nkind_In (P, N_Package_Specification,
1469 -- Note: the following tests seem a little peculiar, because
1470 -- they test for bodies, but if we were in the statement part
1471 -- of the body, we would already have hit the handled statement
1472 -- sequence, so the only way we get here is by being in the
1473 -- declarative part of the body.
1475 elsif Nkind_In (P, N_Subprogram_Body,
1486 Error_Pragma ("pragma% is not in declarative part or package spec");
1487 end Check_Is_In_Decl_Part_Or_Package_Spec;
1489 -------------------------
1490 -- Check_No_Identifier --
1491 -------------------------
1493 procedure Check_No_Identifier (Arg : Node_Id) is
1495 if Nkind (Arg) = N_Pragma_Argument_Association
1496 and then Chars (Arg) /= No_Name
1498 Error_Pragma_Arg_Ident
1499 ("pragma% does not permit identifier& here", Arg);
1501 end Check_No_Identifier;
1503 --------------------------
1504 -- Check_No_Identifiers --
1505 --------------------------
1507 procedure Check_No_Identifiers is
1510 if Arg_Count > 0 then
1512 while Present (Arg_Node) loop
1513 Check_No_Identifier (Arg_Node);
1517 end Check_No_Identifiers;
1519 ------------------------
1520 -- Check_No_Link_Name --
1521 ------------------------
1523 procedure Check_No_Link_Name is
1526 and then Chars (Arg3) = Name_Link_Name
1531 if Present (Arg4) then
1533 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1535 end Check_No_Link_Name;
1537 -------------------------------
1538 -- Check_Optional_Identifier --
1539 -------------------------------
1541 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1544 and then Nkind (Arg) = N_Pragma_Argument_Association
1545 and then Chars (Arg) /= No_Name
1547 if Chars (Arg) /= Id then
1548 Error_Msg_Name_1 := Pname;
1549 Error_Msg_Name_2 := Id;
1550 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1554 end Check_Optional_Identifier;
1556 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1558 Name_Buffer (1 .. Id'Length) := Id;
1559 Name_Len := Id'Length;
1560 Check_Optional_Identifier (Arg, Name_Find);
1561 end Check_Optional_Identifier;
1563 --------------------------------------
1564 -- Check_Precondition_Postcondition --
1565 --------------------------------------
1567 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1571 procedure Chain_PPC (PO : Node_Id);
1572 -- If PO is a subprogram declaration node (or a generic subprogram
1573 -- declaration node), then the precondition/postcondition applies
1574 -- to this subprogram and the processing for the pragma is completed.
1575 -- Otherwise the pragma is misplaced.
1581 procedure Chain_PPC (PO : Node_Id) is
1586 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1587 if not From_Aspect_Specification (N) then
1589 ("pragma% cannot be applied to abstract subprogram");
1591 elsif Class_Present (N) then
1596 ("aspect % requires ''Class for abstract subprogram");
1599 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1600 N_Generic_Subprogram_Declaration,
1601 N_Entry_Declaration)
1606 -- Here if we have [generic] subprogram or entry declaration
1608 if Nkind (PO) = N_Entry_Declaration then
1609 S := Defining_Entity (PO);
1611 S := Defining_Unit_Name (Specification (PO));
1614 -- Make sure we do not have the case of a precondition pragma when
1615 -- the Pre'Class aspect is present.
1617 -- We do this by looking at pragmas already chained to the entity
1618 -- since the aspect derived pragma will be put on this list first.
1620 if Pragma_Name (N) = Name_Precondition then
1621 if not From_Aspect_Specification (N) then
1622 P := Spec_PPC_List (S);
1623 while Present (P) loop
1624 if Pragma_Name (P) = Name_Precondition
1625 and then From_Aspect_Specification (P)
1626 and then Class_Present (P)
1628 Error_Msg_Sloc := Sloc (P);
1630 ("pragma% not allowed, `Pre''Class` aspect given#");
1633 P := Next_Pragma (P);
1638 -- Similarly check for Pre with inherited Pre'Class. Note that
1639 -- we cover the aspect case as well here.
1641 if Pragma_Name (N) = Name_Precondition
1642 and then not Class_Present (N)
1645 Inherited : constant Subprogram_List :=
1646 Inherited_Subprograms (S);
1650 for J in Inherited'Range loop
1651 P := Spec_PPC_List (Inherited (J));
1652 while Present (P) loop
1653 if Pragma_Name (P) = Name_Precondition
1654 and then Class_Present (P)
1656 Error_Msg_Sloc := Sloc (P);
1658 ("pragma% not allowed, `Pre''Class` "
1659 & "aspect inherited from#");
1662 P := Next_Pragma (P);
1668 -- Note: we do not analyze the pragma at this point. Instead we
1669 -- delay this analysis until the end of the declarative part in
1670 -- which the pragma appears. This implements the required delay
1671 -- in this analysis, allowing forward references. The analysis
1672 -- happens at the end of Analyze_Declarations.
1674 -- Chain spec PPC pragma to list for subprogram
1676 Set_Next_Pragma (N, Spec_PPC_List (S));
1677 Set_Spec_PPC_List (S, N);
1679 -- Return indicating spec case
1685 -- Start of processing for Check_Precondition_Postcondition
1688 if not Is_List_Member (N) then
1692 -- Preanalyze message argument if present. Visibility in this
1693 -- argument is established at the point of pragma occurrence.
1695 if Arg_Count = 2 then
1696 Check_Optional_Identifier (Arg2, Name_Message);
1697 Preanalyze_Spec_Expression
1698 (Get_Pragma_Arg (Arg2), Standard_String);
1701 -- Record if pragma is enabled
1703 if Check_Enabled (Pname) then
1704 Set_Pragma_Enabled (N);
1705 Set_SCO_Pragma_Enabled (Loc);
1708 -- If we are within an inlined body, the legality of the pragma
1709 -- has been checked already.
1711 if In_Inlined_Body then
1716 -- Search prior declarations
1719 while Present (Prev (P)) loop
1722 -- If the previous node is a generic subprogram, do not go to to
1723 -- the original node, which is the unanalyzed tree: we need to
1724 -- attach the pre/postconditions to the analyzed version at this
1725 -- point. They get propagated to the original tree when analyzing
1726 -- the corresponding body.
1728 if Nkind (P) not in N_Generic_Declaration then
1729 PO := Original_Node (P);
1734 -- Skip past prior pragma
1736 if Nkind (PO) = N_Pragma then
1739 -- Skip stuff not coming from source
1741 elsif not Comes_From_Source (PO) then
1744 -- Only remaining possibility is subprogram declaration
1752 -- If we fall through loop, pragma is at start of list, so see if it
1753 -- is at the start of declarations of a subprogram body.
1755 if Nkind (Parent (N)) = N_Subprogram_Body
1756 and then List_Containing (N) = Declarations (Parent (N))
1758 if Operating_Mode /= Generate_Code
1759 or else Inside_A_Generic
1761 -- Analyze pragma expression for correctness and for ASIS use
1763 Preanalyze_Spec_Expression
1764 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1770 -- See if it is in the pragmas after a library level subprogram
1772 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1773 Chain_PPC (Unit (Parent (Parent (N))));
1777 -- If we fall through, pragma was misplaced
1780 end Check_Precondition_Postcondition;
1782 -----------------------------
1783 -- Check_Static_Constraint --
1784 -----------------------------
1786 -- Note: for convenience in writing this procedure, in addition to
1787 -- the officially (i.e. by spec) allowed argument which is always a
1788 -- constraint, it also allows ranges and discriminant associations.
1789 -- Above is not clear ???
1791 procedure Check_Static_Constraint (Constr : Node_Id) is
1793 procedure Require_Static (E : Node_Id);
1794 -- Require given expression to be static expression
1796 --------------------
1797 -- Require_Static --
1798 --------------------
1800 procedure Require_Static (E : Node_Id) is
1802 if not Is_OK_Static_Expression (E) then
1803 Flag_Non_Static_Expr
1804 ("non-static constraint not allowed in Unchecked_Union!", E);
1809 -- Start of processing for Check_Static_Constraint
1812 case Nkind (Constr) is
1813 when N_Discriminant_Association =>
1814 Require_Static (Expression (Constr));
1817 Require_Static (Low_Bound (Constr));
1818 Require_Static (High_Bound (Constr));
1820 when N_Attribute_Reference =>
1821 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1822 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1824 when N_Range_Constraint =>
1825 Check_Static_Constraint (Range_Expression (Constr));
1827 when N_Index_Or_Discriminant_Constraint =>
1831 IDC := First (Constraints (Constr));
1832 while Present (IDC) loop
1833 Check_Static_Constraint (IDC);
1841 end Check_Static_Constraint;
1843 --------------------------------------
1844 -- Check_Valid_Configuration_Pragma --
1845 --------------------------------------
1847 -- A configuration pragma must appear in the context clause of a
1848 -- compilation unit, and only other pragmas may precede it. Note that
1849 -- the test also allows use in a configuration pragma file.
1851 procedure Check_Valid_Configuration_Pragma is
1853 if not Is_Configuration_Pragma then
1854 Error_Pragma ("incorrect placement for configuration pragma%");
1856 end Check_Valid_Configuration_Pragma;
1858 -------------------------------------
1859 -- Check_Valid_Library_Unit_Pragma --
1860 -------------------------------------
1862 procedure Check_Valid_Library_Unit_Pragma is
1864 Parent_Node : Node_Id;
1865 Unit_Name : Entity_Id;
1866 Unit_Kind : Node_Kind;
1867 Unit_Node : Node_Id;
1868 Sindex : Source_File_Index;
1871 if not Is_List_Member (N) then
1875 Plist := List_Containing (N);
1876 Parent_Node := Parent (Plist);
1878 if Parent_Node = Empty then
1881 -- Case of pragma appearing after a compilation unit. In this case
1882 -- it must have an argument with the corresponding name and must
1883 -- be part of the following pragmas of its parent.
1885 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1886 if Plist /= Pragmas_After (Parent_Node) then
1889 elsif Arg_Count = 0 then
1891 ("argument required if outside compilation unit");
1894 Check_No_Identifiers;
1895 Check_Arg_Count (1);
1896 Unit_Node := Unit (Parent (Parent_Node));
1897 Unit_Kind := Nkind (Unit_Node);
1899 Analyze (Get_Pragma_Arg (Arg1));
1901 if Unit_Kind = N_Generic_Subprogram_Declaration
1902 or else Unit_Kind = N_Subprogram_Declaration
1904 Unit_Name := Defining_Entity (Unit_Node);
1906 elsif Unit_Kind in N_Generic_Instantiation then
1907 Unit_Name := Defining_Entity (Unit_Node);
1910 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1913 if Chars (Unit_Name) /=
1914 Chars (Entity (Get_Pragma_Arg (Arg1)))
1917 ("pragma% argument is not current unit name", Arg1);
1920 if Ekind (Unit_Name) = E_Package
1921 and then Present (Renamed_Entity (Unit_Name))
1923 Error_Pragma ("pragma% not allowed for renamed package");
1927 -- Pragma appears other than after a compilation unit
1930 -- Here we check for the generic instantiation case and also
1931 -- for the case of processing a generic formal package. We
1932 -- detect these cases by noting that the Sloc on the node
1933 -- does not belong to the current compilation unit.
1935 Sindex := Source_Index (Current_Sem_Unit);
1937 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1938 Rewrite (N, Make_Null_Statement (Loc));
1941 -- If before first declaration, the pragma applies to the
1942 -- enclosing unit, and the name if present must be this name.
1944 elsif Is_Before_First_Decl (N, Plist) then
1945 Unit_Node := Unit_Declaration_Node (Current_Scope);
1946 Unit_Kind := Nkind (Unit_Node);
1948 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1951 elsif Unit_Kind = N_Subprogram_Body
1952 and then not Acts_As_Spec (Unit_Node)
1956 elsif Nkind (Parent_Node) = N_Package_Body then
1959 elsif Nkind (Parent_Node) = N_Package_Specification
1960 and then Plist = Private_Declarations (Parent_Node)
1964 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1965 or else Nkind (Parent_Node) =
1966 N_Generic_Subprogram_Declaration)
1967 and then Plist = Generic_Formal_Declarations (Parent_Node)
1971 elsif Arg_Count > 0 then
1972 Analyze (Get_Pragma_Arg (Arg1));
1974 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
1976 ("name in pragma% must be enclosing unit", Arg1);
1979 -- It is legal to have no argument in this context
1985 -- Error if not before first declaration. This is because a
1986 -- library unit pragma argument must be the name of a library
1987 -- unit (RM 10.1.5(7)), but the only names permitted in this
1988 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1989 -- generic subprogram declarations or generic instantiations.
1993 ("pragma% misplaced, must be before first declaration");
1997 end Check_Valid_Library_Unit_Pragma;
2003 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2004 Clist : constant Node_Id := Component_List (Variant);
2008 if not Is_Non_Empty_List (Component_Items (Clist)) then
2010 ("Unchecked_Union may not have empty component list",
2015 Comp := First (Component_Items (Clist));
2016 while Present (Comp) loop
2017 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2026 procedure Error_Pragma (Msg : String) is
2027 MsgF : String := Msg;
2029 Error_Msg_Name_1 := Pname;
2031 Error_Msg_N (MsgF, N);
2035 ----------------------
2036 -- Error_Pragma_Arg --
2037 ----------------------
2039 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2040 MsgF : String := Msg;
2042 Error_Msg_Name_1 := Pname;
2044 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2046 end Error_Pragma_Arg;
2048 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2049 MsgF : String := Msg1;
2051 Error_Msg_Name_1 := Pname;
2053 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2054 Error_Pragma_Arg (Msg2, Arg);
2055 end Error_Pragma_Arg;
2057 ----------------------------
2058 -- Error_Pragma_Arg_Ident --
2059 ----------------------------
2061 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2062 MsgF : String := Msg;
2064 Error_Msg_Name_1 := Pname;
2066 Error_Msg_N (MsgF, Arg);
2068 end Error_Pragma_Arg_Ident;
2070 ----------------------
2071 -- Error_Pragma_Ref --
2072 ----------------------
2074 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2075 MsgF : String := Msg;
2077 Error_Msg_Name_1 := Pname;
2079 Error_Msg_Sloc := Sloc (Ref);
2080 Error_Msg_NE (MsgF, N, Ref);
2082 end Error_Pragma_Ref;
2084 ------------------------
2085 -- Find_Lib_Unit_Name --
2086 ------------------------
2088 function Find_Lib_Unit_Name return Entity_Id is
2090 -- Return inner compilation unit entity, for case of nested
2091 -- categorization pragmas. This happens in generic unit.
2093 if Nkind (Parent (N)) = N_Package_Specification
2094 and then Defining_Entity (Parent (N)) /= Current_Scope
2096 return Defining_Entity (Parent (N));
2098 return Current_Scope;
2100 end Find_Lib_Unit_Name;
2102 ----------------------------
2103 -- Find_Program_Unit_Name --
2104 ----------------------------
2106 procedure Find_Program_Unit_Name (Id : Node_Id) is
2107 Unit_Name : Entity_Id;
2108 Unit_Kind : Node_Kind;
2109 P : constant Node_Id := Parent (N);
2112 if Nkind (P) = N_Compilation_Unit then
2113 Unit_Kind := Nkind (Unit (P));
2115 if Unit_Kind = N_Subprogram_Declaration
2116 or else Unit_Kind = N_Package_Declaration
2117 or else Unit_Kind in N_Generic_Declaration
2119 Unit_Name := Defining_Entity (Unit (P));
2121 if Chars (Id) = Chars (Unit_Name) then
2122 Set_Entity (Id, Unit_Name);
2123 Set_Etype (Id, Etype (Unit_Name));
2125 Set_Etype (Id, Any_Type);
2127 ("cannot find program unit referenced by pragma%");
2131 Set_Etype (Id, Any_Type);
2132 Error_Pragma ("pragma% inapplicable to this unit");
2138 end Find_Program_Unit_Name;
2140 -----------------------------------------
2141 -- Find_Unique_Parameterless_Procedure --
2142 -----------------------------------------
2144 function Find_Unique_Parameterless_Procedure
2146 Arg : Node_Id) return Entity_Id
2148 Proc : Entity_Id := Empty;
2151 -- The body of this procedure needs some comments ???
2153 if not Is_Entity_Name (Name) then
2155 ("argument of pragma% must be entity name", Arg);
2157 elsif not Is_Overloaded (Name) then
2158 Proc := Entity (Name);
2160 if Ekind (Proc) /= E_Procedure
2161 or else Present (First_Formal (Proc))
2164 ("argument of pragma% must be parameterless procedure", Arg);
2169 Found : Boolean := False;
2171 Index : Interp_Index;
2174 Get_First_Interp (Name, Index, It);
2175 while Present (It.Nam) loop
2178 if Ekind (Proc) = E_Procedure
2179 and then No (First_Formal (Proc))
2183 Set_Entity (Name, Proc);
2184 Set_Is_Overloaded (Name, False);
2187 ("ambiguous handler name for pragma% ", Arg);
2191 Get_Next_Interp (Index, It);
2196 ("argument of pragma% must be parameterless procedure",
2199 Proc := Entity (Name);
2205 end Find_Unique_Parameterless_Procedure;
2211 procedure Fix_Error (Msg : in out String) is
2213 if From_Aspect_Specification (N) then
2214 for J in Msg'First .. Msg'Last - 5 loop
2215 if Msg (J .. J + 5) = "pragma" then
2216 Msg (J .. J + 5) := "aspect";
2220 if Error_Msg_Name_1 = Name_Precondition then
2221 Error_Msg_Name_1 := Name_Pre;
2222 elsif Error_Msg_Name_1 = Name_Postcondition then
2223 Error_Msg_Name_1 := Name_Post;
2228 -------------------------
2229 -- Gather_Associations --
2230 -------------------------
2232 procedure Gather_Associations
2234 Args : out Args_List)
2239 -- Initialize all parameters to Empty
2241 for J in Args'Range loop
2245 -- That's all we have to do if there are no argument associations
2247 if No (Pragma_Argument_Associations (N)) then
2251 -- Otherwise first deal with any positional parameters present
2253 Arg := First (Pragma_Argument_Associations (N));
2254 for Index in Args'Range loop
2255 exit when No (Arg) or else Chars (Arg) /= No_Name;
2256 Args (Index) := Get_Pragma_Arg (Arg);
2260 -- Positional parameters all processed, if any left, then we
2261 -- have too many positional parameters.
2263 if Present (Arg) and then Chars (Arg) = No_Name then
2265 ("too many positional associations for pragma%", Arg);
2268 -- Process named parameters if any are present
2270 while Present (Arg) loop
2271 if Chars (Arg) = No_Name then
2273 ("positional association cannot follow named association",
2277 for Index in Names'Range loop
2278 if Names (Index) = Chars (Arg) then
2279 if Present (Args (Index)) then
2281 ("duplicate argument association for pragma%", Arg);
2283 Args (Index) := Get_Pragma_Arg (Arg);
2288 if Index = Names'Last then
2289 Error_Msg_Name_1 := Pname;
2290 Error_Msg_N ("pragma% does not allow & argument", Arg);
2292 -- Check for possible misspelling
2294 for Index1 in Names'Range loop
2295 if Is_Bad_Spelling_Of
2296 (Chars (Arg), Names (Index1))
2298 Error_Msg_Name_1 := Names (Index1);
2299 Error_Msg_N -- CODEFIX
2300 ("\possible misspelling of%", Arg);
2312 end Gather_Associations;
2318 procedure GNAT_Pragma is
2320 Check_Restriction (No_Implementation_Pragmas, N);
2323 --------------------------
2324 -- Is_Before_First_Decl --
2325 --------------------------
2327 function Is_Before_First_Decl
2328 (Pragma_Node : Node_Id;
2329 Decls : List_Id) return Boolean
2331 Item : Node_Id := First (Decls);
2334 -- Only other pragmas can come before this pragma
2337 if No (Item) or else Nkind (Item) /= N_Pragma then
2340 elsif Item = Pragma_Node then
2346 end Is_Before_First_Decl;
2348 -----------------------------
2349 -- Is_Configuration_Pragma --
2350 -----------------------------
2352 -- A configuration pragma must appear in the context clause of a
2353 -- compilation unit, and only other pragmas may precede it. Note that
2354 -- the test below also permits use in a configuration pragma file.
2356 function Is_Configuration_Pragma return Boolean is
2357 Lis : constant List_Id := List_Containing (N);
2358 Par : constant Node_Id := Parent (N);
2362 -- If no parent, then we are in the configuration pragma file,
2363 -- so the placement is definitely appropriate.
2368 -- Otherwise we must be in the context clause of a compilation unit
2369 -- and the only thing allowed before us in the context list is more
2370 -- configuration pragmas.
2372 elsif Nkind (Par) = N_Compilation_Unit
2373 and then Context_Items (Par) = Lis
2380 elsif Nkind (Prg) /= N_Pragma then
2390 end Is_Configuration_Pragma;
2392 --------------------------
2393 -- Is_In_Context_Clause --
2394 --------------------------
2396 function Is_In_Context_Clause return Boolean is
2398 Parent_Node : Node_Id;
2401 if not Is_List_Member (N) then
2405 Plist := List_Containing (N);
2406 Parent_Node := Parent (Plist);
2408 if Parent_Node = Empty
2409 or else Nkind (Parent_Node) /= N_Compilation_Unit
2410 or else Context_Items (Parent_Node) /= Plist
2417 end Is_In_Context_Clause;
2419 ---------------------------------
2420 -- Is_Static_String_Expression --
2421 ---------------------------------
2423 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2424 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2427 Analyze_And_Resolve (Argx);
2428 return Is_OK_Static_Expression (Argx)
2429 and then Nkind (Argx) = N_String_Literal;
2430 end Is_Static_String_Expression;
2432 ----------------------
2433 -- Pragma_Misplaced --
2434 ----------------------
2436 procedure Pragma_Misplaced is
2438 Error_Pragma ("incorrect placement of pragma%");
2439 end Pragma_Misplaced;
2441 ------------------------------------
2442 -- Process Atomic_Shared_Volatile --
2443 ------------------------------------
2445 procedure Process_Atomic_Shared_Volatile is
2452 procedure Set_Atomic (E : Entity_Id);
2453 -- Set given type as atomic, and if no explicit alignment was given,
2454 -- set alignment to unknown, since back end knows what the alignment
2455 -- requirements are for atomic arrays. Note: this step is necessary
2456 -- for derived types.
2462 procedure Set_Atomic (E : Entity_Id) is
2464 Set_Is_Atomic (E, Sense);
2466 if Sense and then not Has_Alignment_Clause (E) then
2467 Set_Alignment (E, Uint_0);
2471 -- Start of processing for Process_Atomic_Shared_Volatile
2474 Check_Ada_83_Warning;
2475 Check_No_Identifiers;
2476 Check_Arg_Count (1);
2477 Check_Arg_Is_Local_Name (Arg1);
2478 E_Id := Get_Pragma_Arg (Arg1);
2480 if Etype (E_Id) = Any_Type then
2485 D := Declaration_Node (E);
2488 -- Check duplicate before we chain ourselves!
2490 Check_Duplicate_Pragma (E);
2492 -- Now check appropriateness of the entity
2495 if Rep_Item_Too_Early (E, N)
2497 Rep_Item_Too_Late (E, N)
2501 Check_First_Subtype (Arg1);
2504 if Prag_Id /= Pragma_Volatile then
2506 Set_Atomic (Underlying_Type (E));
2507 Set_Atomic (Base_Type (E));
2510 -- Attribute belongs on the base type. If the view of the type is
2511 -- currently private, it also belongs on the underlying type.
2513 Set_Is_Volatile (Base_Type (E), Sense);
2514 Set_Is_Volatile (Underlying_Type (E), Sense);
2516 Set_Treat_As_Volatile (E, Sense);
2517 Set_Treat_As_Volatile (Underlying_Type (E), Sense);
2519 elsif K = N_Object_Declaration
2520 or else (K = N_Component_Declaration
2521 and then Original_Record_Component (E) = E)
2523 if Rep_Item_Too_Late (E, N) then
2527 if Prag_Id /= Pragma_Volatile then
2528 Set_Is_Atomic (E, Sense);
2530 -- If the object declaration has an explicit initialization, a
2531 -- temporary may have to be created to hold the expression, to
2532 -- ensure that access to the object remain atomic.
2534 if Nkind (Parent (E)) = N_Object_Declaration
2535 and then Present (Expression (Parent (E)))
2538 Set_Has_Delayed_Freeze (E);
2541 -- An interesting improvement here. If an object of type X is
2542 -- declared atomic, and the type X is not atomic, that's a
2543 -- pity, since it may not have appropriate alignment etc. We
2544 -- can rescue this in the special case where the object and
2545 -- type are in the same unit by just setting the type as
2546 -- atomic, so that the back end will process it as atomic.
2548 Utyp := Underlying_Type (Etype (E));
2551 and then Sloc (E) > No_Location
2552 and then Sloc (Utyp) > No_Location
2554 Get_Source_File_Index (Sloc (E)) =
2555 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2557 Set_Is_Atomic (Underlying_Type (Etype (E)), Sense);
2561 Set_Is_Volatile (E);
2562 Set_Treat_As_Volatile (E);
2566 ("inappropriate entity for pragma%", Arg1);
2568 end Process_Atomic_Shared_Volatile;
2570 -------------------------------------------
2571 -- Process_Compile_Time_Warning_Or_Error --
2572 -------------------------------------------
2574 procedure Process_Compile_Time_Warning_Or_Error is
2575 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2578 Check_Arg_Count (2);
2579 Check_No_Identifiers;
2580 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2581 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2583 if Compile_Time_Known_Value (Arg1x) then
2584 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2586 Str : constant String_Id :=
2587 Strval (Get_Pragma_Arg (Arg2));
2588 Len : constant Int := String_Length (Str);
2593 Cent : constant Entity_Id :=
2594 Cunit_Entity (Current_Sem_Unit);
2596 Force : constant Boolean :=
2597 Prag_Id = Pragma_Compile_Time_Warning
2599 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2600 and then (Ekind (Cent) /= E_Package
2601 or else not In_Private_Part (Cent));
2602 -- Set True if this is the warning case, and we are in the
2603 -- visible part of a package spec, or in a subprogram spec,
2604 -- in which case we want to force the client to see the
2605 -- warning, even though it is not in the main unit.
2608 -- Loop through segments of message separated by line feeds.
2609 -- We output these segments as separate messages with
2610 -- continuation marks for all but the first.
2615 Error_Msg_Strlen := 0;
2617 -- Loop to copy characters from argument to error message
2621 exit when Ptr > Len;
2622 CC := Get_String_Char (Str, Ptr);
2625 -- Ignore wide chars ??? else store character
2627 if In_Character_Range (CC) then
2628 C := Get_Character (CC);
2629 exit when C = ASCII.LF;
2630 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2631 Error_Msg_String (Error_Msg_Strlen) := C;
2635 -- Here with one line ready to go
2637 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2639 -- If this is a warning in a spec, then we want clients
2640 -- to see the warning, so mark the message with the
2641 -- special sequence !! to force the warning. In the case
2642 -- of a package spec, we do not force this if we are in
2643 -- the private part of the spec.
2646 if Cont = False then
2647 Error_Msg_N ("<~!!", Arg1);
2650 Error_Msg_N ("\<~!!", Arg1);
2653 -- Error, rather than warning, or in a body, so we do not
2654 -- need to force visibility for client (error will be
2655 -- output in any case, and this is the situation in which
2656 -- we do not want a client to get a warning, since the
2657 -- warning is in the body or the spec private part).
2660 if Cont = False then
2661 Error_Msg_N ("<~", Arg1);
2664 Error_Msg_N ("\<~", Arg1);
2668 exit when Ptr > Len;
2673 end Process_Compile_Time_Warning_Or_Error;
2675 ------------------------
2676 -- Process_Convention --
2677 ------------------------
2679 procedure Process_Convention
2680 (C : out Convention_Id;
2681 Ent : out Entity_Id)
2687 Comp_Unit : Unit_Number_Type;
2689 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2690 -- Called if we have more than one Export/Import/Convention pragma.
2691 -- This is generally illegal, but we have a special case of allowing
2692 -- Import and Interface to coexist if they specify the convention in
2693 -- a consistent manner. We are allowed to do this, since Interface is
2694 -- an implementation defined pragma, and we choose to do it since we
2695 -- know Rational allows this combination. S is the entity id of the
2696 -- subprogram in question. This procedure also sets the special flag
2697 -- Import_Interface_Present in both pragmas in the case where we do
2698 -- have matching Import and Interface pragmas.
2700 procedure Set_Convention_From_Pragma (E : Entity_Id);
2701 -- Set convention in entity E, and also flag that the entity has a
2702 -- convention pragma. If entity is for a private or incomplete type,
2703 -- also set convention and flag on underlying type. This procedure
2704 -- also deals with the special case of C_Pass_By_Copy convention.
2706 -------------------------------
2707 -- Diagnose_Multiple_Pragmas --
2708 -------------------------------
2710 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2711 Pdec : constant Node_Id := Declaration_Node (S);
2715 function Same_Convention (Decl : Node_Id) return Boolean;
2716 -- Decl is a pragma node. This function returns True if this
2717 -- pragma has a first argument that is an identifier with a
2718 -- Chars field corresponding to the Convention_Id C.
2720 function Same_Name (Decl : Node_Id) return Boolean;
2721 -- Decl is a pragma node. This function returns True if this
2722 -- pragma has a second argument that is an identifier with a
2723 -- Chars field that matches the Chars of the current subprogram.
2725 ---------------------
2726 -- Same_Convention --
2727 ---------------------
2729 function Same_Convention (Decl : Node_Id) return Boolean is
2730 Arg1 : constant Node_Id :=
2731 First (Pragma_Argument_Associations (Decl));
2734 if Present (Arg1) then
2736 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2738 if Nkind (Arg) = N_Identifier
2739 and then Is_Convention_Name (Chars (Arg))
2740 and then Get_Convention_Id (Chars (Arg)) = C
2748 end Same_Convention;
2754 function Same_Name (Decl : Node_Id) return Boolean is
2755 Arg1 : constant Node_Id :=
2756 First (Pragma_Argument_Associations (Decl));
2764 Arg2 := Next (Arg1);
2771 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2773 if Nkind (Arg) = N_Identifier
2774 and then Chars (Arg) = Chars (S)
2783 -- Start of processing for Diagnose_Multiple_Pragmas
2788 -- Definitely give message if we have Convention/Export here
2790 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2793 -- If we have an Import or Export, scan back from pragma to
2794 -- find any previous pragma applying to the same procedure.
2795 -- The scan will be terminated by the start of the list, or
2796 -- hitting the subprogram declaration. This won't allow one
2797 -- pragma to appear in the public part and one in the private
2798 -- part, but that seems very unlikely in practice.
2802 while Present (Decl) and then Decl /= Pdec loop
2804 -- Look for pragma with same name as us
2806 if Nkind (Decl) = N_Pragma
2807 and then Same_Name (Decl)
2809 -- Give error if same as our pragma or Export/Convention
2811 if Pragma_Name (Decl) = Name_Export
2813 Pragma_Name (Decl) = Name_Convention
2815 Pragma_Name (Decl) = Pragma_Name (N)
2819 -- Case of Import/Interface or the other way round
2821 elsif Pragma_Name (Decl) = Name_Interface
2823 Pragma_Name (Decl) = Name_Import
2825 -- Here we know that we have Import and Interface. It
2826 -- doesn't matter which way round they are. See if
2827 -- they specify the same convention. If so, all OK,
2828 -- and set special flags to stop other messages
2830 if Same_Convention (Decl) then
2831 Set_Import_Interface_Present (N);
2832 Set_Import_Interface_Present (Decl);
2835 -- If different conventions, special message
2838 Error_Msg_Sloc := Sloc (Decl);
2840 ("convention differs from that given#", Arg1);
2850 -- Give message if needed if we fall through those tests
2854 ("at most one Convention/Export/Import pragma is allowed",
2857 end Diagnose_Multiple_Pragmas;
2859 --------------------------------
2860 -- Set_Convention_From_Pragma --
2861 --------------------------------
2863 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2865 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2866 -- for an overridden dispatching operation. Technically this is
2867 -- an amendment and should only be done in Ada 2005 mode. However,
2868 -- this is clearly a mistake, since the problem that is addressed
2869 -- by this AI is that there is a clear gap in the RM!
2871 if Is_Dispatching_Operation (E)
2872 and then Present (Overridden_Operation (E))
2873 and then C /= Convention (Overridden_Operation (E))
2876 ("cannot change convention for " &
2877 "overridden dispatching operation",
2881 -- Set the convention
2883 Set_Convention (E, C);
2884 Set_Has_Convention_Pragma (E);
2886 if Is_Incomplete_Or_Private_Type (E) then
2887 Set_Convention (Underlying_Type (E), C);
2888 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2891 -- A class-wide type should inherit the convention of the specific
2892 -- root type (although this isn't specified clearly by the RM).
2894 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2895 Set_Convention (Class_Wide_Type (E), C);
2898 -- If the entity is a record type, then check for special case of
2899 -- C_Pass_By_Copy, which is treated the same as C except that the
2900 -- special record flag is set. This convention is only permitted
2901 -- on record types (see AI95-00131).
2903 if Cname = Name_C_Pass_By_Copy then
2904 if Is_Record_Type (E) then
2905 Set_C_Pass_By_Copy (Base_Type (E));
2906 elsif Is_Incomplete_Or_Private_Type (E)
2907 and then Is_Record_Type (Underlying_Type (E))
2909 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2912 ("C_Pass_By_Copy convention allowed only for record type",
2917 -- If the entity is a derived boolean type, check for the special
2918 -- case of convention C, C++, or Fortran, where we consider any
2919 -- nonzero value to represent true.
2921 if Is_Discrete_Type (E)
2922 and then Root_Type (Etype (E)) = Standard_Boolean
2928 C = Convention_Fortran)
2930 Set_Nonzero_Is_True (Base_Type (E));
2932 end Set_Convention_From_Pragma;
2934 -- Start of processing for Process_Convention
2937 Check_At_Least_N_Arguments (2);
2938 Check_Optional_Identifier (Arg1, Name_Convention);
2939 Check_Arg_Is_Identifier (Arg1);
2940 Cname := Chars (Get_Pragma_Arg (Arg1));
2942 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2943 -- tested again below to set the critical flag).
2945 if Cname = Name_C_Pass_By_Copy then
2948 -- Otherwise we must have something in the standard convention list
2950 elsif Is_Convention_Name (Cname) then
2951 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
2953 -- In DEC VMS, it seems that there is an undocumented feature that
2954 -- any unrecognized convention is treated as the default, which for
2955 -- us is convention C. It does not seem so terrible to do this
2956 -- unconditionally, silently in the VMS case, and with a warning
2957 -- in the non-VMS case.
2960 if Warn_On_Export_Import and not OpenVMS_On_Target then
2962 ("?unrecognized convention name, C assumed",
2963 Get_Pragma_Arg (Arg1));
2969 Check_Optional_Identifier (Arg2, Name_Entity);
2970 Check_Arg_Is_Local_Name (Arg2);
2972 Id := Get_Pragma_Arg (Arg2);
2975 if not Is_Entity_Name (Id) then
2976 Error_Pragma_Arg ("entity name required", Arg2);
2981 -- Set entity to return
2985 -- Go to renamed subprogram if present, since convention applies to
2986 -- the actual renamed entity, not to the renaming entity. If the
2987 -- subprogram is inherited, go to parent subprogram.
2989 if Is_Subprogram (E)
2990 and then Present (Alias (E))
2992 if Nkind (Parent (Declaration_Node (E))) =
2993 N_Subprogram_Renaming_Declaration
2995 if Scope (E) /= Scope (Alias (E)) then
2997 ("cannot apply pragma% to non-local entity&#", E);
3002 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3003 N_Private_Extension_Declaration)
3004 and then Scope (E) = Scope (Alias (E))
3008 -- Return the parent subprogram the entity was inherited from
3014 -- Check that we are not applying this to a specless body
3016 if Is_Subprogram (E)
3017 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3020 ("pragma% requires separate spec and must come before body");
3023 -- Check that we are not applying this to a named constant
3025 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3026 Error_Msg_Name_1 := Pname;
3028 ("cannot apply pragma% to named constant!",
3029 Get_Pragma_Arg (Arg2));
3031 ("\supply appropriate type for&!", Arg2);
3034 if Ekind (E) = E_Enumeration_Literal then
3035 Error_Pragma ("enumeration literal not allowed for pragma%");
3038 -- Check for rep item appearing too early or too late
3040 if Etype (E) = Any_Type
3041 or else Rep_Item_Too_Early (E, N)
3045 E := Underlying_Type (E);
3048 if Rep_Item_Too_Late (E, N) then
3052 if Has_Convention_Pragma (E) then
3053 Diagnose_Multiple_Pragmas (E);
3055 elsif Convention (E) = Convention_Protected
3056 or else Ekind (Scope (E)) = E_Protected_Type
3059 ("a protected operation cannot be given a different convention",
3063 -- For Intrinsic, a subprogram is required
3065 if C = Convention_Intrinsic
3066 and then not Is_Subprogram (E)
3067 and then not Is_Generic_Subprogram (E)
3070 ("second argument of pragma% must be a subprogram", Arg2);
3073 -- For Stdcall, a subprogram, variable or subprogram type is required
3075 if C = Convention_Stdcall
3076 and then not Is_Subprogram (E)
3077 and then not Is_Generic_Subprogram (E)
3078 and then Ekind (E) /= E_Variable
3081 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3084 ("second argument of pragma% must be subprogram (type)",
3088 if not Is_Subprogram (E)
3089 and then not Is_Generic_Subprogram (E)
3091 Set_Convention_From_Pragma (E);
3094 Check_First_Subtype (Arg2);
3095 Set_Convention_From_Pragma (Base_Type (E));
3097 -- For subprograms, we must set the convention on the
3098 -- internally generated directly designated type as well.
3100 if Ekind (E) = E_Access_Subprogram_Type then
3101 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3105 -- For the subprogram case, set proper convention for all homonyms
3106 -- in same scope and the same declarative part, i.e. the same
3107 -- compilation unit.
3110 Comp_Unit := Get_Source_Unit (E);
3111 Set_Convention_From_Pragma (E);
3113 -- Treat a pragma Import as an implicit body, for GPS use
3115 if Prag_Id = Pragma_Import then
3116 Generate_Reference (E, Id, 'b');
3119 -- Loop through the homonyms of the pragma argument's entity
3124 exit when No (E1) or else Scope (E1) /= Current_Scope;
3126 -- Do not set the pragma on inherited operations or on formal
3129 if Comes_From_Source (E1)
3130 and then Comp_Unit = Get_Source_Unit (E1)
3131 and then not Is_Formal_Subprogram (E1)
3132 and then Nkind (Original_Node (Parent (E1))) /=
3133 N_Full_Type_Declaration
3135 if Present (Alias (E1))
3136 and then Scope (E1) /= Scope (Alias (E1))
3139 ("cannot apply pragma% to non-local entity& declared#",
3143 Set_Convention_From_Pragma (E1);
3145 if Prag_Id = Pragma_Import then
3146 Generate_Reference (E1, Id, 'b');
3150 -- For aspect case, do NOT apply to homonyms
3152 exit when From_Aspect_Specification (N);
3155 end Process_Convention;
3157 -----------------------------------------------------
3158 -- Process_Extended_Import_Export_Exception_Pragma --
3159 -----------------------------------------------------
3161 procedure Process_Extended_Import_Export_Exception_Pragma
3162 (Arg_Internal : Node_Id;
3163 Arg_External : Node_Id;
3171 if not OpenVMS_On_Target then
3173 ("?pragma% ignored (applies only to Open'V'M'S)");
3176 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3177 Def_Id := Entity (Arg_Internal);
3179 if Ekind (Def_Id) /= E_Exception then
3181 ("pragma% must refer to declared exception", Arg_Internal);
3184 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3186 if Present (Arg_Form) then
3187 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3190 if Present (Arg_Form)
3191 and then Chars (Arg_Form) = Name_Ada
3195 Set_Is_VMS_Exception (Def_Id);
3196 Set_Exception_Code (Def_Id, No_Uint);
3199 if Present (Arg_Code) then
3200 if not Is_VMS_Exception (Def_Id) then
3202 ("Code option for pragma% not allowed for Ada case",
3206 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3207 Code_Val := Expr_Value (Arg_Code);
3209 if not UI_Is_In_Int_Range (Code_Val) then
3211 ("Code option for pragma% must be in 32-bit range",
3215 Set_Exception_Code (Def_Id, Code_Val);
3218 end Process_Extended_Import_Export_Exception_Pragma;
3220 -------------------------------------------------
3221 -- Process_Extended_Import_Export_Internal_Arg --
3222 -------------------------------------------------
3224 procedure Process_Extended_Import_Export_Internal_Arg
3225 (Arg_Internal : Node_Id := Empty)
3228 if No (Arg_Internal) then
3229 Error_Pragma ("Internal parameter required for pragma%");
3232 if Nkind (Arg_Internal) = N_Identifier then
3235 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3236 and then (Prag_Id = Pragma_Import_Function
3238 Prag_Id = Pragma_Export_Function)
3244 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3247 Check_Arg_Is_Local_Name (Arg_Internal);
3248 end Process_Extended_Import_Export_Internal_Arg;
3250 --------------------------------------------------
3251 -- Process_Extended_Import_Export_Object_Pragma --
3252 --------------------------------------------------
3254 procedure Process_Extended_Import_Export_Object_Pragma
3255 (Arg_Internal : Node_Id;
3256 Arg_External : Node_Id;
3262 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3263 Def_Id := Entity (Arg_Internal);
3265 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3267 ("pragma% must designate an object", Arg_Internal);
3270 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3272 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3275 ("previous Common/Psect_Object applies, pragma % not permitted",
3279 if Rep_Item_Too_Late (Def_Id, N) then
3283 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3285 if Present (Arg_Size) then
3286 Check_Arg_Is_External_Name (Arg_Size);
3289 -- Export_Object case
3291 if Prag_Id = Pragma_Export_Object then
3292 if not Is_Library_Level_Entity (Def_Id) then
3294 ("argument for pragma% must be library level entity",
3298 if Ekind (Current_Scope) = E_Generic_Package then
3299 Error_Pragma ("pragma& cannot appear in a generic unit");
3302 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3304 ("exported object must have compile time known size",
3308 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3309 Error_Msg_N ("?duplicate Export_Object pragma", N);
3311 Set_Exported (Def_Id, Arg_Internal);
3314 -- Import_Object case
3317 if Is_Concurrent_Type (Etype (Def_Id)) then
3319 ("cannot use pragma% for task/protected object",
3323 if Ekind (Def_Id) = E_Constant then
3325 ("cannot import a constant", Arg_Internal);
3328 if Warn_On_Export_Import
3329 and then Has_Discriminants (Etype (Def_Id))
3332 ("imported value must be initialized?", Arg_Internal);
3335 if Warn_On_Export_Import
3336 and then Is_Access_Type (Etype (Def_Id))
3339 ("cannot import object of an access type?", Arg_Internal);
3342 if Warn_On_Export_Import
3343 and then Is_Imported (Def_Id)
3346 ("?duplicate Import_Object pragma", N);
3348 -- Check for explicit initialization present. Note that an
3349 -- initialization generated by the code generator, e.g. for an
3350 -- access type, does not count here.
3352 elsif Present (Expression (Parent (Def_Id)))
3355 (Original_Node (Expression (Parent (Def_Id))))
3357 Error_Msg_Sloc := Sloc (Def_Id);
3359 ("imported entities cannot be initialized (RM B.1(24))",
3360 "\no initialization allowed for & declared#", Arg1);
3362 Set_Imported (Def_Id);
3363 Note_Possible_Modification (Arg_Internal, Sure => False);
3366 end Process_Extended_Import_Export_Object_Pragma;
3368 ------------------------------------------------------
3369 -- Process_Extended_Import_Export_Subprogram_Pragma --
3370 ------------------------------------------------------
3372 procedure Process_Extended_Import_Export_Subprogram_Pragma
3373 (Arg_Internal : Node_Id;
3374 Arg_External : Node_Id;
3375 Arg_Parameter_Types : Node_Id;
3376 Arg_Result_Type : Node_Id := Empty;
3377 Arg_Mechanism : Node_Id;
3378 Arg_Result_Mechanism : Node_Id := Empty;
3379 Arg_First_Optional_Parameter : Node_Id := Empty)
3385 Ambiguous : Boolean;
3389 function Same_Base_Type
3391 Formal : Entity_Id) return Boolean;
3392 -- Determines if Ptype references the type of Formal. Note that only
3393 -- the base types need to match according to the spec. Ptype here is
3394 -- the argument from the pragma, which is either a type name, or an
3395 -- access attribute.
3397 --------------------
3398 -- Same_Base_Type --
3399 --------------------
3401 function Same_Base_Type
3403 Formal : Entity_Id) return Boolean
3405 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3409 -- Case where pragma argument is typ'Access
3411 if Nkind (Ptype) = N_Attribute_Reference
3412 and then Attribute_Name (Ptype) = Name_Access
3414 Pref := Prefix (Ptype);
3417 if not Is_Entity_Name (Pref)
3418 or else Entity (Pref) = Any_Type
3423 -- We have a match if the corresponding argument is of an
3424 -- anonymous access type, and its designated type matches the
3425 -- type of the prefix of the access attribute
3427 return Ekind (Ftyp) = E_Anonymous_Access_Type
3428 and then Base_Type (Entity (Pref)) =
3429 Base_Type (Etype (Designated_Type (Ftyp)));
3431 -- Case where pragma argument is a type name
3436 if not Is_Entity_Name (Ptype)
3437 or else Entity (Ptype) = Any_Type
3442 -- We have a match if the corresponding argument is of the type
3443 -- given in the pragma (comparing base types)
3445 return Base_Type (Entity (Ptype)) = Ftyp;
3449 -- Start of processing for
3450 -- Process_Extended_Import_Export_Subprogram_Pragma
3453 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3457 -- Loop through homonyms (overloadings) of the entity
3459 Hom_Id := Entity (Arg_Internal);
3460 while Present (Hom_Id) loop
3461 Def_Id := Get_Base_Subprogram (Hom_Id);
3463 -- We need a subprogram in the current scope
3465 if not Is_Subprogram (Def_Id)
3466 or else Scope (Def_Id) /= Current_Scope
3473 -- Pragma cannot apply to subprogram body
3475 if Is_Subprogram (Def_Id)
3476 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3480 ("pragma% requires separate spec"
3481 & " and must come before body");
3484 -- Test result type if given, note that the result type
3485 -- parameter can only be present for the function cases.
3487 if Present (Arg_Result_Type)
3488 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3492 elsif Etype (Def_Id) /= Standard_Void_Type
3494 (Pname = Name_Export_Procedure
3496 Pname = Name_Import_Procedure)
3500 -- Test parameter types if given. Note that this parameter
3501 -- has not been analyzed (and must not be, since it is
3502 -- semantic nonsense), so we get it as the parser left it.
3504 elsif Present (Arg_Parameter_Types) then
3505 Check_Matching_Types : declare
3510 Formal := First_Formal (Def_Id);
3512 if Nkind (Arg_Parameter_Types) = N_Null then
3513 if Present (Formal) then
3517 -- A list of one type, e.g. (List) is parsed as
3518 -- a parenthesized expression.
3520 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3521 and then Paren_Count (Arg_Parameter_Types) = 1
3524 or else Present (Next_Formal (Formal))
3529 Same_Base_Type (Arg_Parameter_Types, Formal);
3532 -- A list of more than one type is parsed as a aggregate
3534 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3535 and then Paren_Count (Arg_Parameter_Types) = 0
3537 Ptype := First (Expressions (Arg_Parameter_Types));
3538 while Present (Ptype) or else Present (Formal) loop
3541 or else not Same_Base_Type (Ptype, Formal)
3546 Next_Formal (Formal);
3551 -- Anything else is of the wrong form
3555 ("wrong form for Parameter_Types parameter",
3556 Arg_Parameter_Types);
3558 end Check_Matching_Types;
3561 -- Match is now False if the entry we found did not match
3562 -- either a supplied Parameter_Types or Result_Types argument
3568 -- Ambiguous case, the flag Ambiguous shows if we already
3569 -- detected this and output the initial messages.
3572 if not Ambiguous then
3574 Error_Msg_Name_1 := Pname;
3576 ("pragma% does not uniquely identify subprogram!",
3578 Error_Msg_Sloc := Sloc (Ent);
3579 Error_Msg_N ("matching subprogram #!", N);
3583 Error_Msg_Sloc := Sloc (Def_Id);
3584 Error_Msg_N ("matching subprogram #!", N);
3589 Hom_Id := Homonym (Hom_Id);
3592 -- See if we found an entry
3595 if not Ambiguous then
3596 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3598 ("pragma% cannot be given for generic subprogram");
3601 ("pragma% does not identify local subprogram");
3608 -- Import pragmas must be for imported entities
3610 if Prag_Id = Pragma_Import_Function
3612 Prag_Id = Pragma_Import_Procedure
3614 Prag_Id = Pragma_Import_Valued_Procedure
3616 if not Is_Imported (Ent) then
3618 ("pragma Import or Interface must precede pragma%");
3621 -- Here we have the Export case which can set the entity as exported
3623 -- But does not do so if the specified external name is null, since
3624 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3625 -- compatible) to request no external name.
3627 elsif Nkind (Arg_External) = N_String_Literal
3628 and then String_Length (Strval (Arg_External)) = 0
3632 -- In all other cases, set entity as exported
3635 Set_Exported (Ent, Arg_Internal);
3638 -- Special processing for Valued_Procedure cases
3640 if Prag_Id = Pragma_Import_Valued_Procedure
3642 Prag_Id = Pragma_Export_Valued_Procedure
3644 Formal := First_Formal (Ent);
3647 Error_Pragma ("at least one parameter required for pragma%");
3649 elsif Ekind (Formal) /= E_Out_Parameter then
3650 Error_Pragma ("first parameter must have mode out for pragma%");
3653 Set_Is_Valued_Procedure (Ent);
3657 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3659 -- Process Result_Mechanism argument if present. We have already
3660 -- checked that this is only allowed for the function case.
3662 if Present (Arg_Result_Mechanism) then
3663 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3666 -- Process Mechanism parameter if present. Note that this parameter
3667 -- is not analyzed, and must not be analyzed since it is semantic
3668 -- nonsense, so we get it in exactly as the parser left it.
3670 if Present (Arg_Mechanism) then
3678 -- A single mechanism association without a formal parameter
3679 -- name is parsed as a parenthesized expression. All other
3680 -- cases are parsed as aggregates, so we rewrite the single
3681 -- parameter case as an aggregate for consistency.
3683 if Nkind (Arg_Mechanism) /= N_Aggregate
3684 and then Paren_Count (Arg_Mechanism) = 1
3686 Rewrite (Arg_Mechanism,
3687 Make_Aggregate (Sloc (Arg_Mechanism),
3688 Expressions => New_List (
3689 Relocate_Node (Arg_Mechanism))));
3692 -- Case of only mechanism name given, applies to all formals
3694 if Nkind (Arg_Mechanism) /= N_Aggregate then
3695 Formal := First_Formal (Ent);
3696 while Present (Formal) loop
3697 Set_Mechanism_Value (Formal, Arg_Mechanism);
3698 Next_Formal (Formal);
3701 -- Case of list of mechanism associations given
3704 if Null_Record_Present (Arg_Mechanism) then
3706 ("inappropriate form for Mechanism parameter",
3710 -- Deal with positional ones first
3712 Formal := First_Formal (Ent);
3714 if Present (Expressions (Arg_Mechanism)) then
3715 Mname := First (Expressions (Arg_Mechanism));
3716 while Present (Mname) loop
3719 ("too many mechanism associations", Mname);
3722 Set_Mechanism_Value (Formal, Mname);
3723 Next_Formal (Formal);
3728 -- Deal with named entries
3730 if Present (Component_Associations (Arg_Mechanism)) then
3731 Massoc := First (Component_Associations (Arg_Mechanism));
3732 while Present (Massoc) loop
3733 Choice := First (Choices (Massoc));
3735 if Nkind (Choice) /= N_Identifier
3736 or else Present (Next (Choice))
3739 ("incorrect form for mechanism association",
3743 Formal := First_Formal (Ent);
3747 ("parameter name & not present", Choice);
3750 if Chars (Choice) = Chars (Formal) then
3752 (Formal, Expression (Massoc));
3754 -- Set entity on identifier (needed by ASIS)
3756 Set_Entity (Choice, Formal);
3761 Next_Formal (Formal);
3771 -- Process First_Optional_Parameter argument if present. We have
3772 -- already checked that this is only allowed for the Import case.
3774 if Present (Arg_First_Optional_Parameter) then
3775 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3777 ("first optional parameter must be formal parameter name",
3778 Arg_First_Optional_Parameter);
3781 Formal := First_Formal (Ent);
3785 ("specified formal parameter& not found",
3786 Arg_First_Optional_Parameter);
3789 exit when Chars (Formal) =
3790 Chars (Arg_First_Optional_Parameter);
3792 Next_Formal (Formal);
3795 Set_First_Optional_Parameter (Ent, Formal);
3797 -- Check specified and all remaining formals have right form
3799 while Present (Formal) loop
3800 if Ekind (Formal) /= E_In_Parameter then
3802 ("optional formal& is not of mode in!",
3803 Arg_First_Optional_Parameter, Formal);
3806 Dval := Default_Value (Formal);
3810 ("optional formal& does not have default value!",
3811 Arg_First_Optional_Parameter, Formal);
3813 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3818 ("default value for optional formal& is non-static!",
3819 Arg_First_Optional_Parameter, Formal);
3823 Set_Is_Optional_Parameter (Formal);
3824 Next_Formal (Formal);
3827 end Process_Extended_Import_Export_Subprogram_Pragma;
3829 --------------------------
3830 -- Process_Generic_List --
3831 --------------------------
3833 procedure Process_Generic_List is
3838 Check_No_Identifiers;
3839 Check_At_Least_N_Arguments (1);
3842 while Present (Arg) loop
3843 Exp := Get_Pragma_Arg (Arg);
3846 if not Is_Entity_Name (Exp)
3848 (not Is_Generic_Instance (Entity (Exp))
3850 not Is_Generic_Unit (Entity (Exp)))
3853 ("pragma% argument must be name of generic unit/instance",
3859 end Process_Generic_List;
3861 ---------------------------------
3862 -- Process_Import_Or_Interface --
3863 ---------------------------------
3865 procedure Process_Import_Or_Interface is
3871 Process_Convention (C, Def_Id);
3872 Kill_Size_Check_Code (Def_Id);
3873 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
3875 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3877 -- We do not permit Import to apply to a renaming declaration
3879 if Present (Renamed_Object (Def_Id)) then
3881 ("pragma% not allowed for object renaming", Arg2);
3883 -- User initialization is not allowed for imported object, but
3884 -- the object declaration may contain a default initialization,
3885 -- that will be discarded. Note that an explicit initialization
3886 -- only counts if it comes from source, otherwise it is simply
3887 -- the code generator making an implicit initialization explicit.
3889 elsif Present (Expression (Parent (Def_Id)))
3890 and then Comes_From_Source (Expression (Parent (Def_Id)))
3892 Error_Msg_Sloc := Sloc (Def_Id);
3894 ("no initialization allowed for declaration of& #",
3895 "\imported entities cannot be initialized (RM B.1(24))",
3899 Set_Imported (Def_Id);
3900 Process_Interface_Name (Def_Id, Arg3, Arg4);
3902 -- Note that we do not set Is_Public here. That's because we
3903 -- only want to set it if there is no address clause, and we
3904 -- don't know that yet, so we delay that processing till
3907 -- pragma Import completes deferred constants
3909 if Ekind (Def_Id) = E_Constant then
3910 Set_Has_Completion (Def_Id);
3913 -- It is not possible to import a constant of an unconstrained
3914 -- array type (e.g. string) because there is no simple way to
3915 -- write a meaningful subtype for it.
3917 if Is_Array_Type (Etype (Def_Id))
3918 and then not Is_Constrained (Etype (Def_Id))
3921 ("imported constant& must have a constrained subtype",
3926 elsif Is_Subprogram (Def_Id)
3927 or else Is_Generic_Subprogram (Def_Id)
3929 -- If the name is overloaded, pragma applies to all of the denoted
3930 -- entities in the same declarative part.
3933 while Present (Hom_Id) loop
3934 Def_Id := Get_Base_Subprogram (Hom_Id);
3936 -- Ignore inherited subprograms because the pragma will apply
3937 -- to the parent operation, which is the one called.
3939 if Is_Overloadable (Def_Id)
3940 and then Present (Alias (Def_Id))
3944 -- If it is not a subprogram, it must be in an outer scope and
3945 -- pragma does not apply.
3947 elsif not Is_Subprogram (Def_Id)
3948 and then not Is_Generic_Subprogram (Def_Id)
3952 -- The pragma does not apply to primitives of interfaces
3954 elsif Is_Dispatching_Operation (Def_Id)
3955 and then Present (Find_Dispatching_Type (Def_Id))
3956 and then Is_Interface (Find_Dispatching_Type (Def_Id))
3960 -- Verify that the homonym is in the same declarative part (not
3961 -- just the same scope).
3963 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3964 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3969 Set_Imported (Def_Id);
3971 -- Reject an Import applied to an abstract subprogram
3973 if Is_Subprogram (Def_Id)
3974 and then Is_Abstract_Subprogram (Def_Id)
3976 Error_Msg_Sloc := Sloc (Def_Id);
3978 ("cannot import abstract subprogram& declared#",
3982 -- Special processing for Convention_Intrinsic
3984 if C = Convention_Intrinsic then
3986 -- Link_Name argument not allowed for intrinsic
3990 Set_Is_Intrinsic_Subprogram (Def_Id);
3992 -- If no external name is present, then check that this
3993 -- is a valid intrinsic subprogram. If an external name
3994 -- is present, then this is handled by the back end.
3997 Check_Intrinsic_Subprogram
3998 (Def_Id, Get_Pragma_Arg (Arg2));
4002 -- All interfaced procedures need an external symbol created
4003 -- for them since they are always referenced from another
4006 Set_Is_Public (Def_Id);
4008 -- Verify that the subprogram does not have a completion
4009 -- through a renaming declaration. For other completions the
4010 -- pragma appears as a too late representation.
4013 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4017 and then Nkind (Decl) = N_Subprogram_Declaration
4018 and then Present (Corresponding_Body (Decl))
4019 and then Nkind (Unit_Declaration_Node
4020 (Corresponding_Body (Decl))) =
4021 N_Subprogram_Renaming_Declaration
4023 Error_Msg_Sloc := Sloc (Def_Id);
4025 ("cannot import&, renaming already provided for " &
4026 "declaration #", N, Def_Id);
4030 Set_Has_Completion (Def_Id);
4031 Process_Interface_Name (Def_Id, Arg3, Arg4);
4034 if Is_Compilation_Unit (Hom_Id) then
4036 -- Its possible homonyms are not affected by the pragma.
4037 -- Such homonyms might be present in the context of other
4038 -- units being compiled.
4043 Hom_Id := Homonym (Hom_Id);
4047 -- When the convention is Java or CIL, we also allow Import to be
4048 -- given for packages, generic packages, exceptions, record
4049 -- components, and access to subprograms.
4051 elsif (C = Convention_Java or else C = Convention_CIL)
4053 (Is_Package_Or_Generic_Package (Def_Id)
4054 or else Ekind (Def_Id) = E_Exception
4055 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4056 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4058 Set_Imported (Def_Id);
4059 Set_Is_Public (Def_Id);
4060 Process_Interface_Name (Def_Id, Arg3, Arg4);
4062 -- Import a CPP class
4064 elsif Is_Record_Type (Def_Id)
4065 and then C = Convention_CPP
4067 -- Types treated as CPP classes are treated as limited, but we
4068 -- don't require them to be declared this way. A warning is issued
4069 -- to encourage the user to declare them as limited. This is not
4070 -- an error, for compatibility reasons, because these types have
4071 -- been supported this way for some time.
4073 if not Is_Limited_Type (Def_Id) then
4075 ("imported 'C'P'P type should be " &
4076 "explicitly declared limited?",
4077 Get_Pragma_Arg (Arg2));
4079 ("\type will be considered limited",
4080 Get_Pragma_Arg (Arg2));
4083 Set_Is_CPP_Class (Def_Id);
4084 Set_Is_Limited_Record (Def_Id);
4086 -- Imported CPP types must not have discriminants (because C++
4087 -- classes do not have discriminants).
4089 if Has_Discriminants (Def_Id) then
4091 ("imported 'C'P'P type cannot have discriminants",
4092 First (Discriminant_Specifications
4093 (Declaration_Node (Def_Id))));
4096 -- Components of imported CPP types must not have default
4097 -- expressions because the constructor (if any) is on the
4101 Tdef : constant Node_Id :=
4102 Type_Definition (Declaration_Node (Def_Id));
4107 if Nkind (Tdef) = N_Record_Definition then
4108 Clist := Component_List (Tdef);
4111 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4112 Clist := Component_List (Record_Extension_Part (Tdef));
4115 if Present (Clist) then
4116 Comp := First (Component_Items (Clist));
4117 while Present (Comp) loop
4118 if Present (Expression (Comp)) then
4120 ("component of imported 'C'P'P type cannot have" &
4121 " default expression", Expression (Comp));
4131 ("second argument of pragma% must be object or subprogram",
4135 -- If this pragma applies to a compilation unit, then the unit, which
4136 -- is a subprogram, does not require (or allow) a body. We also do
4137 -- not need to elaborate imported procedures.
4139 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4141 Cunit : constant Node_Id := Parent (Parent (N));
4143 Set_Body_Required (Cunit, False);
4146 end Process_Import_Or_Interface;
4148 --------------------
4149 -- Process_Inline --
4150 --------------------
4152 procedure Process_Inline (Active : Boolean) is
4158 Effective : Boolean := False;
4160 procedure Make_Inline (Subp : Entity_Id);
4161 -- Subp is the defining unit name of the subprogram declaration. Set
4162 -- the flag, as well as the flag in the corresponding body, if there
4165 procedure Set_Inline_Flags (Subp : Entity_Id);
4166 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4167 -- Has_Pragma_Inline_Always for the Inline_Always case.
4169 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4170 -- Returns True if it can be determined at this stage that inlining
4171 -- is not possible, for example if the body is available and contains
4172 -- exception handlers, we prevent inlining, since otherwise we can
4173 -- get undefined symbols at link time. This function also emits a
4174 -- warning if front-end inlining is enabled and the pragma appears
4177 -- ??? is business with link symbols still valid, or does it relate
4178 -- to front end ZCX which is being phased out ???
4180 ---------------------------
4181 -- Inlining_Not_Possible --
4182 ---------------------------
4184 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4185 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4189 if Nkind (Decl) = N_Subprogram_Body then
4190 Stats := Handled_Statement_Sequence (Decl);
4191 return Present (Exception_Handlers (Stats))
4192 or else Present (At_End_Proc (Stats));
4194 elsif Nkind (Decl) = N_Subprogram_Declaration
4195 and then Present (Corresponding_Body (Decl))
4197 if Front_End_Inlining
4198 and then Analyzed (Corresponding_Body (Decl))
4200 Error_Msg_N ("pragma appears too late, ignored?", N);
4203 -- If the subprogram is a renaming as body, the body is just a
4204 -- call to the renamed subprogram, and inlining is trivially
4208 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4209 N_Subprogram_Renaming_Declaration
4215 Handled_Statement_Sequence
4216 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4219 Present (Exception_Handlers (Stats))
4220 or else Present (At_End_Proc (Stats));
4224 -- If body is not available, assume the best, the check is
4225 -- performed again when compiling enclosing package bodies.
4229 end Inlining_Not_Possible;
4235 procedure Make_Inline (Subp : Entity_Id) is
4236 Kind : constant Entity_Kind := Ekind (Subp);
4237 Inner_Subp : Entity_Id := Subp;
4240 -- Ignore if bad type, avoid cascaded error
4242 if Etype (Subp) = Any_Type then
4246 -- Ignore if all inlining is suppressed
4248 elsif Suppress_All_Inlining then
4252 -- If inlining is not possible, for now do not treat as an error
4254 elsif Inlining_Not_Possible (Subp) then
4258 -- Here we have a candidate for inlining, but we must exclude
4259 -- derived operations. Otherwise we would end up trying to inline
4260 -- a phantom declaration, and the result would be to drag in a
4261 -- body which has no direct inlining associated with it. That
4262 -- would not only be inefficient but would also result in the
4263 -- backend doing cross-unit inlining in cases where it was
4264 -- definitely inappropriate to do so.
4266 -- However, a simple Comes_From_Source test is insufficient, since
4267 -- we do want to allow inlining of generic instances which also do
4268 -- not come from source. We also need to recognize specs generated
4269 -- by the front-end for bodies that carry the pragma. Finally,
4270 -- predefined operators do not come from source but are not
4271 -- inlineable either.
4273 elsif Is_Generic_Instance (Subp)
4274 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4278 elsif not Comes_From_Source (Subp)
4279 and then Scope (Subp) /= Standard_Standard
4285 -- The referenced entity must either be the enclosing entity, or
4286 -- an entity declared within the current open scope.
4288 if Present (Scope (Subp))
4289 and then Scope (Subp) /= Current_Scope
4290 and then Subp /= Current_Scope
4293 ("argument of% must be entity in current scope", Assoc);
4297 -- Processing for procedure, operator or function. If subprogram
4298 -- is aliased (as for an instance) indicate that the renamed
4299 -- entity (if declared in the same unit) is inlined.
4301 if Is_Subprogram (Subp) then
4307 Inner_Subp := Ultimate_Alias (Inner_Subp);
4309 if In_Same_Source_Unit (Subp, Inner_Subp) then
4310 Set_Inline_Flags (Inner_Subp);
4312 Decl := Parent (Parent (Inner_Subp));
4314 if Nkind (Decl) = N_Subprogram_Declaration
4315 and then Present (Corresponding_Body (Decl))
4317 Set_Inline_Flags (Corresponding_Body (Decl));
4319 elsif Is_Generic_Instance (Subp) then
4321 -- Indicate that the body needs to be created for
4322 -- inlining subsequent calls. The instantiation node
4323 -- follows the declaration of the wrapper package
4326 if Scope (Subp) /= Standard_Standard
4328 Need_Subprogram_Instance_Body
4329 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4339 -- For a generic subprogram set flag as well, for use at the point
4340 -- of instantiation, to determine whether the body should be
4343 elsif Is_Generic_Subprogram (Subp) then
4344 Set_Inline_Flags (Subp);
4347 -- Literals are by definition inlined
4349 elsif Kind = E_Enumeration_Literal then
4352 -- Anything else is an error
4356 ("expect subprogram name for pragma%", Assoc);
4360 ----------------------
4361 -- Set_Inline_Flags --
4362 ----------------------
4364 procedure Set_Inline_Flags (Subp : Entity_Id) is
4367 Set_Is_Inlined (Subp, Sense);
4370 if not Has_Pragma_Inline (Subp) then
4371 Set_Has_Pragma_Inline (Subp, Sense);
4375 if Prag_Id = Pragma_Inline_Always then
4376 Set_Has_Pragma_Inline_Always (Subp, Sense);
4378 end Set_Inline_Flags;
4380 -- Start of processing for Process_Inline
4383 Check_No_Identifiers;
4384 Check_At_Least_N_Arguments (1);
4387 Inline_Processing_Required := True;
4391 while Present (Assoc) loop
4392 Subp_Id := Get_Pragma_Arg (Assoc);
4396 if Is_Entity_Name (Subp_Id) then
4397 Subp := Entity (Subp_Id);
4399 if Subp = Any_Id then
4401 -- If previous error, avoid cascaded errors
4409 -- For the pragma case, climb homonym chain. This is
4410 -- what implements allowing the pragma in the renaming
4411 -- case, with the result applying to the ancestors.
4413 if not From_Aspect_Specification (N) then
4414 while Present (Homonym (Subp))
4415 and then Scope (Homonym (Subp)) = Current_Scope
4417 Make_Inline (Homonym (Subp));
4418 Subp := Homonym (Subp);
4426 ("inappropriate argument for pragma%", Assoc);
4429 and then Warn_On_Redundant_Constructs
4430 and then not Suppress_All_Inlining
4432 if Inlining_Not_Possible (Subp) then
4434 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4437 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4445 ----------------------------
4446 -- Process_Interface_Name --
4447 ----------------------------
4449 procedure Process_Interface_Name
4450 (Subprogram_Def : Entity_Id;
4456 String_Val : String_Id;
4458 procedure Check_Form_Of_Interface_Name
4460 Ext_Name_Case : Boolean);
4461 -- SN is a string literal node for an interface name. This routine
4462 -- performs some minimal checks that the name is reasonable. In
4463 -- particular that no spaces or other obviously incorrect characters
4464 -- appear. This is only a warning, since any characters are allowed.
4465 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4467 ----------------------------------
4468 -- Check_Form_Of_Interface_Name --
4469 ----------------------------------
4471 procedure Check_Form_Of_Interface_Name
4473 Ext_Name_Case : Boolean)
4475 S : constant String_Id := Strval (Expr_Value_S (SN));
4476 SL : constant Nat := String_Length (S);
4481 Error_Msg_N ("interface name cannot be null string", SN);
4484 for J in 1 .. SL loop
4485 C := Get_String_Char (S, J);
4487 -- Look for dubious character and issue unconditional warning.
4488 -- Definitely dubious if not in character range.
4490 if not In_Character_Range (C)
4492 -- For all cases except CLI target,
4493 -- commas, spaces and slashes are dubious (in CLI, we use
4494 -- commas and backslashes in external names to specify
4495 -- assembly version and public key, while slashes and spaces
4496 -- can be used in names to mark nested classes and
4499 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4500 and then (Get_Character (C) = ','
4502 Get_Character (C) = '\'))
4503 or else (VM_Target /= CLI_Target
4504 and then (Get_Character (C) = ' '
4506 Get_Character (C) = '/'))
4509 ("?interface name contains illegal character",
4510 Sloc (SN) + Source_Ptr (J));
4513 end Check_Form_Of_Interface_Name;
4515 -- Start of processing for Process_Interface_Name
4518 if No (Link_Arg) then
4519 if No (Ext_Arg) then
4520 if VM_Target = CLI_Target
4521 and then Ekind (Subprogram_Def) = E_Package
4522 and then Nkind (Parent (Subprogram_Def)) =
4523 N_Package_Specification
4524 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4529 (Generic_Parent (Parent (Subprogram_Def))));
4534 elsif Chars (Ext_Arg) = Name_Link_Name then
4536 Link_Nam := Expression (Ext_Arg);
4539 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4540 Ext_Nam := Expression (Ext_Arg);
4545 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4546 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4547 Ext_Nam := Expression (Ext_Arg);
4548 Link_Nam := Expression (Link_Arg);
4551 -- Check expressions for external name and link name are static
4553 if Present (Ext_Nam) then
4554 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4555 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4557 -- Verify that external name is not the name of a local entity,
4558 -- which would hide the imported one and could lead to run-time
4559 -- surprises. The problem can only arise for entities declared in
4560 -- a package body (otherwise the external name is fully qualified
4561 -- and will not conflict).
4569 if Prag_Id = Pragma_Import then
4570 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4572 E := Entity_Id (Get_Name_Table_Info (Nam));
4574 if Nam /= Chars (Subprogram_Def)
4575 and then Present (E)
4576 and then not Is_Overloadable (E)
4577 and then Is_Immediately_Visible (E)
4578 and then not Is_Imported (E)
4579 and then Ekind (Scope (E)) = E_Package
4582 while Present (Par) loop
4583 if Nkind (Par) = N_Package_Body then
4584 Error_Msg_Sloc := Sloc (E);
4586 ("imported entity is hidden by & declared#",
4591 Par := Parent (Par);
4598 if Present (Link_Nam) then
4599 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4600 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4603 -- If there is no link name, just set the external name
4605 if No (Link_Nam) then
4606 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4608 -- For the Link_Name case, the given literal is preceded by an
4609 -- asterisk, which indicates to GCC that the given name should be
4610 -- taken literally, and in particular that no prepending of
4611 -- underlines should occur, even in systems where this is the
4617 if VM_Target = No_VM then
4618 Store_String_Char (Get_Char_Code ('*'));
4621 String_Val := Strval (Expr_Value_S (Link_Nam));
4622 Store_String_Chars (String_Val);
4624 Make_String_Literal (Sloc (Link_Nam),
4625 Strval => End_String);
4628 Set_Encoded_Interface_Name
4629 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4631 -- We allow duplicated export names in CIL, as they are always
4632 -- enclosed in a namespace that differentiates them, and overloaded
4633 -- entities are supported by the VM.
4635 if Convention (Subprogram_Def) /= Convention_CIL then
4636 Check_Duplicated_Export_Name (Link_Nam);
4638 end Process_Interface_Name;
4640 -----------------------------------------
4641 -- Process_Interrupt_Or_Attach_Handler --
4642 -----------------------------------------
4644 procedure Process_Interrupt_Or_Attach_Handler is
4645 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4646 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4647 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4650 Set_Is_Interrupt_Handler (Handler_Proc);
4652 -- If the pragma is not associated with a handler procedure within a
4653 -- protected type, then it must be for a nonprotected procedure for
4654 -- the AAMP target, in which case we don't associate a representation
4655 -- item with the procedure's scope.
4657 if Ekind (Proc_Scope) = E_Protected_Type then
4658 if Prag_Id = Pragma_Interrupt_Handler
4660 Prag_Id = Pragma_Attach_Handler
4662 Record_Rep_Item (Proc_Scope, N);
4665 end Process_Interrupt_Or_Attach_Handler;
4667 --------------------------------------------------
4668 -- Process_Restrictions_Or_Restriction_Warnings --
4669 --------------------------------------------------
4671 -- Note: some of the simple identifier cases were handled in par-prag,
4672 -- but it is harmless (and more straightforward) to simply handle all
4673 -- cases here, even if it means we repeat a bit of work in some cases.
4675 procedure Process_Restrictions_Or_Restriction_Warnings
4679 R_Id : Restriction_Id;
4684 procedure Check_Unit_Name (N : Node_Id);
4685 -- Checks unit name parameter for No_Dependence. Returns if it has
4686 -- an appropriate form, otherwise raises pragma argument error.
4688 ---------------------
4689 -- Check_Unit_Name --
4690 ---------------------
4692 procedure Check_Unit_Name (N : Node_Id) is
4694 if Nkind (N) = N_Selected_Component then
4695 Check_Unit_Name (Prefix (N));
4696 Check_Unit_Name (Selector_Name (N));
4698 elsif Nkind (N) = N_Identifier then
4703 ("wrong form for unit name for No_Dependence", N);
4705 end Check_Unit_Name;
4707 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4710 -- Ignore all Restrictions pragma in CodePeer mode
4712 if CodePeer_Mode then
4716 Check_Ada_83_Warning;
4717 Check_At_Least_N_Arguments (1);
4718 Check_Valid_Configuration_Pragma;
4721 while Present (Arg) loop
4723 Expr := Get_Pragma_Arg (Arg);
4725 -- Case of no restriction identifier present
4727 if Id = No_Name then
4728 if Nkind (Expr) /= N_Identifier then
4730 ("invalid form for restriction", Arg);
4735 (Process_Restriction_Synonyms (Expr));
4737 if R_Id not in All_Boolean_Restrictions then
4738 Error_Msg_Name_1 := Pname;
4740 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4742 -- Check for possible misspelling
4744 for J in Restriction_Id loop
4746 Rnm : constant String := Restriction_Id'Image (J);
4749 Name_Buffer (1 .. Rnm'Length) := Rnm;
4750 Name_Len := Rnm'Length;
4751 Set_Casing (All_Lower_Case);
4753 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4755 (Identifier_Casing (Current_Source_File));
4756 Error_Msg_String (1 .. Rnm'Length) :=
4757 Name_Buffer (1 .. Name_Len);
4758 Error_Msg_Strlen := Rnm'Length;
4759 Error_Msg_N -- CODEFIX
4760 ("\possible misspelling of ""~""",
4761 Get_Pragma_Arg (Arg));
4770 if Implementation_Restriction (R_Id) then
4771 Check_Restriction (No_Implementation_Restrictions, Arg);
4774 -- If this is a warning, then set the warning unless we already
4775 -- have a real restriction active (we never want a warning to
4776 -- override a real restriction).
4779 if not Restriction_Active (R_Id) then
4780 Set_Restriction (R_Id, N);
4781 Restriction_Warnings (R_Id) := True;
4784 -- If real restriction case, then set it and make sure that the
4785 -- restriction warning flag is off, since a real restriction
4786 -- always overrides a warning.
4789 Set_Restriction (R_Id, N);
4790 Restriction_Warnings (R_Id) := False;
4793 -- Check for obsolescent restrictions in Ada 2005 mode
4796 and then Ada_Version >= Ada_2005
4797 and then (R_Id = No_Asynchronous_Control
4799 R_Id = No_Unchecked_Deallocation
4801 R_Id = No_Unchecked_Conversion)
4803 Check_Restriction (No_Obsolescent_Features, N);
4806 -- A very special case that must be processed here: pragma
4807 -- Restrictions (No_Exceptions) turns off all run-time
4808 -- checking. This is a bit dubious in terms of the formal
4809 -- language definition, but it is what is intended by RM
4810 -- H.4(12). Restriction_Warnings never affects generated code
4811 -- so this is done only in the real restriction case.
4813 if R_Id = No_Exceptions and then not Warn then
4814 Scope_Suppress := (others => True);
4817 -- Case of No_Dependence => unit-name. Note that the parser
4818 -- already made the necessary entry in the No_Dependence table.
4820 elsif Id = Name_No_Dependence then
4821 Check_Unit_Name (Expr);
4823 -- All other cases of restriction identifier present
4826 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4827 Analyze_And_Resolve (Expr, Any_Integer);
4829 if R_Id not in All_Parameter_Restrictions then
4831 ("invalid restriction parameter identifier", Arg);
4833 elsif not Is_OK_Static_Expression (Expr) then
4834 Flag_Non_Static_Expr
4835 ("value must be static expression!", Expr);
4838 elsif not Is_Integer_Type (Etype (Expr))
4839 or else Expr_Value (Expr) < 0
4842 ("value must be non-negative integer", Arg);
4845 -- Restriction pragma is active
4847 Val := Expr_Value (Expr);
4849 if not UI_Is_In_Int_Range (Val) then
4851 ("pragma ignored, value too large?", Arg);
4854 -- Warning case. If the real restriction is active, then we
4855 -- ignore the request, since warning never overrides a real
4856 -- restriction. Otherwise we set the proper warning. Note that
4857 -- this circuit sets the warning again if it is already set,
4858 -- which is what we want, since the constant may have changed.
4861 if not Restriction_Active (R_Id) then
4863 (R_Id, N, Integer (UI_To_Int (Val)));
4864 Restriction_Warnings (R_Id) := True;
4867 -- Real restriction case, set restriction and make sure warning
4868 -- flag is off since real restriction always overrides warning.
4871 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4872 Restriction_Warnings (R_Id) := False;
4878 end Process_Restrictions_Or_Restriction_Warnings;
4880 ---------------------------------
4881 -- Process_Suppress_Unsuppress --
4882 ---------------------------------
4884 -- Note: this procedure makes entries in the check suppress data
4885 -- structures managed by Sem. See spec of package Sem for full
4886 -- details on how we handle recording of check suppression.
4888 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4893 In_Package_Spec : constant Boolean :=
4894 Is_Package_Or_Generic_Package (Current_Scope)
4895 and then not In_Package_Body (Current_Scope);
4897 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4898 -- Used to suppress a single check on the given entity
4900 --------------------------------
4901 -- Suppress_Unsuppress_Echeck --
4902 --------------------------------
4904 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4906 Set_Checks_May_Be_Suppressed (E);
4908 if In_Package_Spec then
4909 Push_Global_Suppress_Stack_Entry
4912 Suppress => Suppress_Case);
4915 Push_Local_Suppress_Stack_Entry
4918 Suppress => Suppress_Case);
4921 -- If this is a first subtype, and the base type is distinct,
4922 -- then also set the suppress flags on the base type.
4924 if Is_First_Subtype (E)
4925 and then Etype (E) /= E
4927 Suppress_Unsuppress_Echeck (Etype (E), C);
4929 end Suppress_Unsuppress_Echeck;
4931 -- Start of processing for Process_Suppress_Unsuppress
4934 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
4935 -- we want to generate checks for analysis purposes, as set by -gnatC
4937 if CodePeer_Mode and then Comes_From_Source (N) then
4941 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4942 -- declarative part or a package spec (RM 11.5(5)).
4944 if not Is_Configuration_Pragma then
4945 Check_Is_In_Decl_Part_Or_Package_Spec;
4948 Check_At_Least_N_Arguments (1);
4949 Check_At_Most_N_Arguments (2);
4950 Check_No_Identifier (Arg1);
4951 Check_Arg_Is_Identifier (Arg1);
4953 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
4955 if C = No_Check_Id then
4957 ("argument of pragma% is not valid check name", Arg1);
4960 if not Suppress_Case
4961 and then (C = All_Checks or else C = Overflow_Check)
4963 Opt.Overflow_Checks_Unsuppressed := True;
4966 if Arg_Count = 1 then
4968 -- Make an entry in the local scope suppress table. This is the
4969 -- table that directly shows the current value of the scope
4970 -- suppress check for any check id value.
4972 if C = All_Checks then
4974 -- For All_Checks, we set all specific predefined checks with
4975 -- the exception of Elaboration_Check, which is handled
4976 -- specially because of not wanting All_Checks to have the
4977 -- effect of deactivating static elaboration order processing.
4979 for J in Scope_Suppress'Range loop
4980 if J /= Elaboration_Check then
4981 Scope_Suppress (J) := Suppress_Case;
4985 -- If not All_Checks, and predefined check, then set appropriate
4986 -- scope entry. Note that we will set Elaboration_Check if this
4987 -- is explicitly specified.
4989 elsif C in Predefined_Check_Id then
4990 Scope_Suppress (C) := Suppress_Case;
4993 -- Also make an entry in the Local_Entity_Suppress table
4995 Push_Local_Suppress_Stack_Entry
4998 Suppress => Suppress_Case);
5000 -- Case of two arguments present, where the check is suppressed for
5001 -- a specified entity (given as the second argument of the pragma)
5004 -- This is obsolescent in Ada 2005 mode
5006 if Ada_Version >= Ada_2005 then
5007 Check_Restriction (No_Obsolescent_Features, Arg2);
5010 Check_Optional_Identifier (Arg2, Name_On);
5011 E_Id := Get_Pragma_Arg (Arg2);
5014 if not Is_Entity_Name (E_Id) then
5016 ("second argument of pragma% must be entity name", Arg2);
5025 -- Enforce RM 11.5(7) which requires that for a pragma that
5026 -- appears within a package spec, the named entity must be
5027 -- within the package spec. We allow the package name itself
5028 -- to be mentioned since that makes sense, although it is not
5029 -- strictly allowed by 11.5(7).
5032 and then E /= Current_Scope
5033 and then Scope (E) /= Current_Scope
5036 ("entity in pragma% is not in package spec (RM 11.5(7))",
5040 -- Loop through homonyms. As noted below, in the case of a package
5041 -- spec, only homonyms within the package spec are considered.
5044 Suppress_Unsuppress_Echeck (E, C);
5046 if Is_Generic_Instance (E)
5047 and then Is_Subprogram (E)
5048 and then Present (Alias (E))
5050 Suppress_Unsuppress_Echeck (Alias (E), C);
5053 -- Move to next homonym if not aspect spec case
5055 exit when From_Aspect_Specification (N);
5059 -- If we are within a package specification, the pragma only
5060 -- applies to homonyms in the same scope.
5062 exit when In_Package_Spec
5063 and then Scope (E) /= Current_Scope;
5066 end Process_Suppress_Unsuppress;
5072 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5074 if Is_Imported (E) then
5076 ("cannot export entity& that was previously imported", Arg);
5078 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5080 ("cannot export entity& that has an address clause", Arg);
5083 Set_Is_Exported (E);
5085 -- Generate a reference for entity explicitly, because the
5086 -- identifier may be overloaded and name resolution will not
5089 Generate_Reference (E, Arg);
5091 -- Deal with exporting non-library level entity
5093 if not Is_Library_Level_Entity (E) then
5095 -- Not allowed at all for subprograms
5097 if Is_Subprogram (E) then
5098 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5100 -- Otherwise set public and statically allocated
5104 Set_Is_Statically_Allocated (E);
5106 -- Warn if the corresponding W flag is set and the pragma comes
5107 -- from source. The latter may not be true e.g. on VMS where we
5108 -- expand export pragmas for exception codes associated with
5109 -- imported or exported exceptions. We do not want to generate
5110 -- a warning for something that the user did not write.
5112 if Warn_On_Export_Import
5113 and then Comes_From_Source (Arg)
5116 ("?& has been made static as a result of Export", Arg, E);
5118 ("\this usage is non-standard and non-portable", Arg);
5123 if Warn_On_Export_Import and then Is_Type (E) then
5124 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5127 if Warn_On_Export_Import and Inside_A_Generic then
5129 ("all instances of& will have the same external name?", Arg, E);
5133 ----------------------------------------------
5134 -- Set_Extended_Import_Export_External_Name --
5135 ----------------------------------------------
5137 procedure Set_Extended_Import_Export_External_Name
5138 (Internal_Ent : Entity_Id;
5139 Arg_External : Node_Id)
5141 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5145 if No (Arg_External) then
5149 Check_Arg_Is_External_Name (Arg_External);
5151 if Nkind (Arg_External) = N_String_Literal then
5152 if String_Length (Strval (Arg_External)) = 0 then
5155 New_Name := Adjust_External_Name_Case (Arg_External);
5158 elsif Nkind (Arg_External) = N_Identifier then
5159 New_Name := Get_Default_External_Name (Arg_External);
5161 -- Check_Arg_Is_External_Name should let through only identifiers and
5162 -- string literals or static string expressions (which are folded to
5163 -- string literals).
5166 raise Program_Error;
5169 -- If we already have an external name set (by a prior normal Import
5170 -- or Export pragma), then the external names must match
5172 if Present (Interface_Name (Internal_Ent)) then
5173 Check_Matching_Internal_Names : declare
5174 S1 : constant String_Id := Strval (Old_Name);
5175 S2 : constant String_Id := Strval (New_Name);
5178 -- Called if names do not match
5184 procedure Mismatch is
5186 Error_Msg_Sloc := Sloc (Old_Name);
5188 ("external name does not match that given #",
5192 -- Start of processing for Check_Matching_Internal_Names
5195 if String_Length (S1) /= String_Length (S2) then
5199 for J in 1 .. String_Length (S1) loop
5200 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5205 end Check_Matching_Internal_Names;
5207 -- Otherwise set the given name
5210 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5211 Check_Duplicated_Export_Name (New_Name);
5213 end Set_Extended_Import_Export_External_Name;
5219 procedure Set_Imported (E : Entity_Id) is
5221 -- Error message if already imported or exported
5223 if Is_Exported (E) or else Is_Imported (E) then
5225 -- Error if being set Exported twice
5227 if Is_Exported (E) then
5228 Error_Msg_NE ("entity& was previously exported", N, E);
5230 -- OK if Import/Interface case
5232 elsif Import_Interface_Present (N) then
5235 -- Error if being set Imported twice
5238 Error_Msg_NE ("entity& was previously imported", N, E);
5241 Error_Msg_Name_1 := Pname;
5243 ("\(pragma% applies to all previous entities)", N);
5245 Error_Msg_Sloc := Sloc (E);
5246 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5248 -- Here if not previously imported or exported, OK to import
5251 Set_Is_Imported (E);
5253 -- If the entity is an object that is not at the library level,
5254 -- then it is statically allocated. We do not worry about objects
5255 -- with address clauses in this context since they are not really
5256 -- imported in the linker sense.
5259 and then not Is_Library_Level_Entity (E)
5260 and then No (Address_Clause (E))
5262 Set_Is_Statically_Allocated (E);
5269 -------------------------
5270 -- Set_Mechanism_Value --
5271 -------------------------
5273 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5274 -- analyzed, since it is semantic nonsense), so we get it in the exact
5275 -- form created by the parser.
5277 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5280 Mech_Name_Id : Name_Id;
5282 procedure Bad_Class;
5283 -- Signal bad descriptor class name
5285 procedure Bad_Mechanism;
5286 -- Signal bad mechanism name
5292 procedure Bad_Class is
5294 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5297 -------------------------
5298 -- Bad_Mechanism_Value --
5299 -------------------------
5301 procedure Bad_Mechanism is
5303 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5306 -- Start of processing for Set_Mechanism_Value
5309 if Mechanism (Ent) /= Default_Mechanism then
5311 ("mechanism for & has already been set", Mech_Name, Ent);
5314 -- MECHANISM_NAME ::= value | reference | descriptor |
5317 if Nkind (Mech_Name) = N_Identifier then
5318 if Chars (Mech_Name) = Name_Value then
5319 Set_Mechanism (Ent, By_Copy);
5322 elsif Chars (Mech_Name) = Name_Reference then
5323 Set_Mechanism (Ent, By_Reference);
5326 elsif Chars (Mech_Name) = Name_Descriptor then
5327 Check_VMS (Mech_Name);
5329 -- Descriptor => Short_Descriptor if pragma was given
5331 if Short_Descriptors then
5332 Set_Mechanism (Ent, By_Short_Descriptor);
5334 Set_Mechanism (Ent, By_Descriptor);
5339 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5340 Check_VMS (Mech_Name);
5341 Set_Mechanism (Ent, By_Short_Descriptor);
5344 elsif Chars (Mech_Name) = Name_Copy then
5346 ("bad mechanism name, Value assumed", Mech_Name);
5352 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5353 -- short_descriptor (CLASS_NAME)
5354 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5356 -- Note: this form is parsed as an indexed component
5358 elsif Nkind (Mech_Name) = N_Indexed_Component then
5359 Class := First (Expressions (Mech_Name));
5361 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5362 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5363 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5364 or else Present (Next (Class))
5368 Mech_Name_Id := Chars (Prefix (Mech_Name));
5370 -- Change Descriptor => Short_Descriptor if pragma was given
5372 if Mech_Name_Id = Name_Descriptor
5373 and then Short_Descriptors
5375 Mech_Name_Id := Name_Short_Descriptor;
5379 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5380 -- short_descriptor (Class => CLASS_NAME)
5381 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5383 -- Note: this form is parsed as a function call
5385 elsif Nkind (Mech_Name) = N_Function_Call then
5386 Param := First (Parameter_Associations (Mech_Name));
5388 if Nkind (Name (Mech_Name)) /= N_Identifier
5389 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5390 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5391 or else Present (Next (Param))
5392 or else No (Selector_Name (Param))
5393 or else Chars (Selector_Name (Param)) /= Name_Class
5397 Class := Explicit_Actual_Parameter (Param);
5398 Mech_Name_Id := Chars (Name (Mech_Name));
5405 -- Fall through here with Class set to descriptor class name
5407 Check_VMS (Mech_Name);
5409 if Nkind (Class) /= N_Identifier then
5412 elsif Mech_Name_Id = Name_Descriptor
5413 and then Chars (Class) = Name_UBS
5415 Set_Mechanism (Ent, By_Descriptor_UBS);
5417 elsif Mech_Name_Id = Name_Descriptor
5418 and then Chars (Class) = Name_UBSB
5420 Set_Mechanism (Ent, By_Descriptor_UBSB);
5422 elsif Mech_Name_Id = Name_Descriptor
5423 and then Chars (Class) = Name_UBA
5425 Set_Mechanism (Ent, By_Descriptor_UBA);
5427 elsif Mech_Name_Id = Name_Descriptor
5428 and then Chars (Class) = Name_S
5430 Set_Mechanism (Ent, By_Descriptor_S);
5432 elsif Mech_Name_Id = Name_Descriptor
5433 and then Chars (Class) = Name_SB
5435 Set_Mechanism (Ent, By_Descriptor_SB);
5437 elsif Mech_Name_Id = Name_Descriptor
5438 and then Chars (Class) = Name_A
5440 Set_Mechanism (Ent, By_Descriptor_A);
5442 elsif Mech_Name_Id = Name_Descriptor
5443 and then Chars (Class) = Name_NCA
5445 Set_Mechanism (Ent, By_Descriptor_NCA);
5447 elsif Mech_Name_Id = Name_Short_Descriptor
5448 and then Chars (Class) = Name_UBS
5450 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5452 elsif Mech_Name_Id = Name_Short_Descriptor
5453 and then Chars (Class) = Name_UBSB
5455 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5457 elsif Mech_Name_Id = Name_Short_Descriptor
5458 and then Chars (Class) = Name_UBA
5460 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5462 elsif Mech_Name_Id = Name_Short_Descriptor
5463 and then Chars (Class) = Name_S
5465 Set_Mechanism (Ent, By_Short_Descriptor_S);
5467 elsif Mech_Name_Id = Name_Short_Descriptor
5468 and then Chars (Class) = Name_SB
5470 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5472 elsif Mech_Name_Id = Name_Short_Descriptor
5473 and then Chars (Class) = Name_A
5475 Set_Mechanism (Ent, By_Short_Descriptor_A);
5477 elsif Mech_Name_Id = Name_Short_Descriptor
5478 and then Chars (Class) = Name_NCA
5480 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5485 end Set_Mechanism_Value;
5487 ---------------------------
5488 -- Set_Ravenscar_Profile --
5489 ---------------------------
5491 -- The tasks to be done here are
5493 -- Set required policies
5495 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5496 -- pragma Locking_Policy (Ceiling_Locking)
5498 -- Set Detect_Blocking mode
5500 -- Set required restrictions (see System.Rident for detailed list)
5502 -- Set the No_Dependence rules
5503 -- No_Dependence => Ada.Asynchronous_Task_Control
5504 -- No_Dependence => Ada.Calendar
5505 -- No_Dependence => Ada.Execution_Time.Group_Budget
5506 -- No_Dependence => Ada.Execution_Time.Timers
5507 -- No_Dependence => Ada.Task_Attributes
5508 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5510 procedure Set_Ravenscar_Profile (N : Node_Id) is
5511 Prefix_Entity : Entity_Id;
5512 Selector_Entity : Entity_Id;
5513 Prefix_Node : Node_Id;
5517 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5519 if Task_Dispatching_Policy /= ' '
5520 and then Task_Dispatching_Policy /= 'F'
5522 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5523 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5525 -- Set the FIFO_Within_Priorities policy, but always preserve
5526 -- System_Location since we like the error message with the run time
5530 Task_Dispatching_Policy := 'F';
5532 if Task_Dispatching_Policy_Sloc /= System_Location then
5533 Task_Dispatching_Policy_Sloc := Loc;
5537 -- pragma Locking_Policy (Ceiling_Locking)
5539 if Locking_Policy /= ' '
5540 and then Locking_Policy /= 'C'
5542 Error_Msg_Sloc := Locking_Policy_Sloc;
5543 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5545 -- Set the Ceiling_Locking policy, but preserve System_Location since
5546 -- we like the error message with the run time name.
5549 Locking_Policy := 'C';
5551 if Locking_Policy_Sloc /= System_Location then
5552 Locking_Policy_Sloc := Loc;
5556 -- pragma Detect_Blocking
5558 Detect_Blocking := True;
5560 -- Set the corresponding restrictions
5562 Set_Profile_Restrictions
5563 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5565 -- Set the No_Dependence restrictions
5567 -- The following No_Dependence restrictions:
5568 -- No_Dependence => Ada.Asynchronous_Task_Control
5569 -- No_Dependence => Ada.Calendar
5570 -- No_Dependence => Ada.Task_Attributes
5571 -- are already set by previous call to Set_Profile_Restrictions.
5573 -- Set the following restrictions which were added to Ada 2005:
5574 -- No_Dependence => Ada.Execution_Time.Group_Budget
5575 -- No_Dependence => Ada.Execution_Time.Timers
5577 if Ada_Version >= Ada_2005 then
5578 Name_Buffer (1 .. 3) := "ada";
5581 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5583 Name_Buffer (1 .. 14) := "execution_time";
5586 Selector_Entity := Make_Identifier (Loc, Name_Find);
5589 Make_Selected_Component
5591 Prefix => Prefix_Entity,
5592 Selector_Name => Selector_Entity);
5594 Name_Buffer (1 .. 13) := "group_budgets";
5597 Selector_Entity := Make_Identifier (Loc, Name_Find);
5600 Make_Selected_Component
5602 Prefix => Prefix_Node,
5603 Selector_Name => Selector_Entity);
5605 Set_Restriction_No_Dependence
5607 Warn => Treat_Restrictions_As_Warnings,
5608 Profile => Ravenscar);
5610 Name_Buffer (1 .. 6) := "timers";
5613 Selector_Entity := Make_Identifier (Loc, Name_Find);
5616 Make_Selected_Component
5618 Prefix => Prefix_Node,
5619 Selector_Name => Selector_Entity);
5621 Set_Restriction_No_Dependence
5623 Warn => Treat_Restrictions_As_Warnings,
5624 Profile => Ravenscar);
5627 -- Set the following restrictions which was added to Ada 2012 (see
5629 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5631 if Ada_Version >= Ada_2012 then
5632 Name_Buffer (1 .. 6) := "system";
5635 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5637 Name_Buffer (1 .. 15) := "multiprocessors";
5640 Selector_Entity := Make_Identifier (Loc, Name_Find);
5643 Make_Selected_Component
5645 Prefix => Prefix_Entity,
5646 Selector_Name => Selector_Entity);
5648 Name_Buffer (1 .. 19) := "dispatching_domains";
5651 Selector_Entity := Make_Identifier (Loc, Name_Find);
5654 Make_Selected_Component
5656 Prefix => Prefix_Node,
5657 Selector_Name => Selector_Entity);
5659 Set_Restriction_No_Dependence
5661 Warn => Treat_Restrictions_As_Warnings,
5662 Profile => Ravenscar);
5664 end Set_Ravenscar_Profile;
5666 -- Start of processing for Analyze_Pragma
5669 -- Deal with unrecognized pragma
5671 if not Is_Pragma_Name (Pname) then
5672 if Warn_On_Unrecognized_Pragma then
5673 Error_Msg_Name_1 := Pname;
5674 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5676 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5677 if Is_Bad_Spelling_Of (Pname, PN) then
5678 Error_Msg_Name_1 := PN;
5679 Error_Msg_N -- CODEFIX
5680 ("\?possible misspelling of %!", Pragma_Identifier (N));
5689 -- Here to start processing for recognized pragma
5691 Prag_Id := Get_Pragma_Id (Pname);
5701 if Present (Pragma_Argument_Associations (N)) then
5702 Arg_Count := List_Length (Pragma_Argument_Associations (N));
5703 Arg1 := First (Pragma_Argument_Associations (N));
5705 if Present (Arg1) then
5706 Arg2 := Next (Arg1);
5708 if Present (Arg2) then
5709 Arg3 := Next (Arg2);
5711 if Present (Arg3) then
5712 Arg4 := Next (Arg3);
5718 -- An enumeration type defines the pragmas that are supported by the
5719 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5720 -- into the corresponding enumeration value for the following case.
5728 -- pragma Abort_Defer;
5730 when Pragma_Abort_Defer =>
5732 Check_Arg_Count (0);
5734 -- The only required semantic processing is to check the
5735 -- placement. This pragma must appear at the start of the
5736 -- statement sequence of a handled sequence of statements.
5738 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5739 or else N /= First (Statements (Parent (N)))
5750 -- Note: this pragma also has some specific processing in Par.Prag
5751 -- because we want to set the Ada version mode during parsing.
5753 when Pragma_Ada_83 =>
5755 Check_Arg_Count (0);
5757 -- We really should check unconditionally for proper configuration
5758 -- pragma placement, since we really don't want mixed Ada modes
5759 -- within a single unit, and the GNAT reference manual has always
5760 -- said this was a configuration pragma, but we did not check and
5761 -- are hesitant to add the check now.
5763 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5764 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5765 -- or Ada 2012 mode.
5767 if Ada_Version >= Ada_2005 then
5768 Check_Valid_Configuration_Pragma;
5771 -- Now set Ada 83 mode
5773 Ada_Version := Ada_83;
5774 Ada_Version_Explicit := Ada_Version;
5782 -- Note: this pragma also has some specific processing in Par.Prag
5783 -- because we want to set the Ada 83 version mode during parsing.
5785 when Pragma_Ada_95 =>
5787 Check_Arg_Count (0);
5789 -- We really should check unconditionally for proper configuration
5790 -- pragma placement, since we really don't want mixed Ada modes
5791 -- within a single unit, and the GNAT reference manual has always
5792 -- said this was a configuration pragma, but we did not check and
5793 -- are hesitant to add the check now.
5795 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5796 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5798 if Ada_Version >= Ada_2005 then
5799 Check_Valid_Configuration_Pragma;
5802 -- Now set Ada 95 mode
5804 Ada_Version := Ada_95;
5805 Ada_Version_Explicit := Ada_Version;
5807 ---------------------
5808 -- Ada_05/Ada_2005 --
5809 ---------------------
5812 -- pragma Ada_05 (LOCAL_NAME);
5815 -- pragma Ada_2005 (LOCAL_NAME):
5817 -- Note: these pragmas also have some specific processing in Par.Prag
5818 -- because we want to set the Ada 2005 version mode during parsing.
5820 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5826 if Arg_Count = 1 then
5827 Check_Arg_Is_Local_Name (Arg1);
5828 E_Id := Get_Pragma_Arg (Arg1);
5830 if Etype (E_Id) = Any_Type then
5834 Set_Is_Ada_2005_Only (Entity (E_Id));
5837 Check_Arg_Count (0);
5839 -- For Ada_2005 we unconditionally enforce the documented
5840 -- configuration pragma placement, since we do not want to
5841 -- tolerate mixed modes in a unit involving Ada 2005. That
5842 -- would cause real difficulties for those cases where there
5843 -- are incompatibilities between Ada 95 and Ada 2005.
5845 Check_Valid_Configuration_Pragma;
5847 -- Now set appropriate Ada mode
5850 Ada_Version := Ada_2005;
5852 Ada_Version := Ada_Version_Default;
5855 Ada_Version_Explicit := Ada_2005;
5859 ---------------------
5860 -- Ada_12/Ada_2012 --
5861 ---------------------
5864 -- pragma Ada_12 (LOCAL_NAME);
5867 -- pragma Ada_2012 (LOCAL_NAME):
5869 -- Note: these pragmas also have some specific processing in Par.Prag
5870 -- because we want to set the Ada 2012 version mode during parsing.
5872 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5878 if Arg_Count = 1 then
5879 Check_Arg_Is_Local_Name (Arg1);
5880 E_Id := Get_Pragma_Arg (Arg1);
5882 if Etype (E_Id) = Any_Type then
5886 Set_Is_Ada_2012_Only (Entity (E_Id));
5889 Check_Arg_Count (0);
5891 -- For Ada_2012 we unconditionally enforce the documented
5892 -- configuration pragma placement, since we do not want to
5893 -- tolerate mixed modes in a unit involving Ada 2012. That
5894 -- would cause real difficulties for those cases where there
5895 -- are incompatibilities between Ada 95 and Ada 2012. We could
5896 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5898 Check_Valid_Configuration_Pragma;
5900 -- Now set appropriate Ada mode
5903 Ada_Version := Ada_2012;
5905 Ada_Version := Ada_Version_Default;
5908 Ada_Version_Explicit := Ada_2012;
5912 ----------------------
5913 -- All_Calls_Remote --
5914 ----------------------
5916 -- pragma All_Calls_Remote [(library_package_NAME)];
5918 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5919 Lib_Entity : Entity_Id;
5922 Check_Ada_83_Warning;
5923 Check_Valid_Library_Unit_Pragma;
5925 if Nkind (N) = N_Null_Statement then
5929 Lib_Entity := Find_Lib_Unit_Name;
5931 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5933 if Present (Lib_Entity)
5934 and then not Debug_Flag_U
5936 if not Is_Remote_Call_Interface (Lib_Entity) then
5937 Error_Pragma ("pragma% only apply to rci unit");
5939 -- Set flag for entity of the library unit
5942 Set_Has_All_Calls_Remote (Lib_Entity);
5946 end All_Calls_Remote;
5952 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
5953 -- ARG ::= NAME | EXPRESSION
5955 -- The first two arguments are by convention intended to refer to an
5956 -- external tool and a tool-specific function. These arguments are
5959 when Pragma_Annotate => Annotate : begin
5961 Check_At_Least_N_Arguments (1);
5962 Check_Arg_Is_Identifier (Arg1);
5963 Check_No_Identifiers;
5971 -- Second unanalyzed parameter is optional
5977 while Present (Arg) loop
5978 Exp := Get_Pragma_Arg (Arg);
5981 if Is_Entity_Name (Exp) then
5984 -- For string literals, we assume Standard_String as the
5985 -- type, unless the string contains wide or wide_wide
5988 elsif Nkind (Exp) = N_String_Literal then
5989 if Has_Wide_Wide_Character (Exp) then
5990 Resolve (Exp, Standard_Wide_Wide_String);
5991 elsif Has_Wide_Character (Exp) then
5992 Resolve (Exp, Standard_Wide_String);
5994 Resolve (Exp, Standard_String);
5997 elsif Is_Overloaded (Exp) then
5999 ("ambiguous argument for pragma%", Exp);
6015 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6016 -- [, [Message =>] Static_String_EXPRESSION]);
6018 when Pragma_Assert => Assert : declare
6024 Check_At_Least_N_Arguments (1);
6025 Check_At_Most_N_Arguments (2);
6026 Check_Arg_Order ((Name_Check, Name_Message));
6027 Check_Optional_Identifier (Arg1, Name_Check);
6029 -- We treat pragma Assert as equivalent to:
6031 -- pragma Check (Assertion, condition [, msg]);
6033 -- So rewrite pragma in this manner, and analyze the result
6035 Expr := Get_Pragma_Arg (Arg1);
6037 Make_Pragma_Argument_Association (Loc,
6038 Expression => Make_Identifier (Loc, Name_Assertion)),
6040 Make_Pragma_Argument_Association (Sloc (Expr),
6041 Expression => Expr));
6043 if Arg_Count > 1 then
6044 Check_Optional_Identifier (Arg2, Name_Message);
6045 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6046 Append_To (Newa, Relocate_Node (Arg2));
6051 Chars => Name_Check,
6052 Pragma_Argument_Associations => Newa));
6056 ----------------------
6057 -- Assertion_Policy --
6058 ----------------------
6060 -- pragma Assertion_Policy (Check | Ignore)
6062 when Pragma_Assertion_Policy => Assertion_Policy : declare
6067 Check_Valid_Configuration_Pragma;
6068 Check_Arg_Count (1);
6069 Check_No_Identifiers;
6070 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6072 -- We treat pragma Assertion_Policy as equivalent to:
6074 -- pragma Check_Policy (Assertion, policy)
6076 -- So rewrite the pragma in that manner and link on to the chain
6077 -- of Check_Policy pragmas, marking the pragma as analyzed.
6079 Policy := Get_Pragma_Arg (Arg1);
6083 Chars => Name_Check_Policy,
6085 Pragma_Argument_Associations => New_List (
6086 Make_Pragma_Argument_Association (Loc,
6087 Expression => Make_Identifier (Loc, Name_Assertion)),
6089 Make_Pragma_Argument_Association (Loc,
6091 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6094 Set_Next_Pragma (N, Opt.Check_Policy_List);
6095 Opt.Check_Policy_List := N;
6096 end Assertion_Policy;
6098 ------------------------------
6099 -- Assume_No_Invalid_Values --
6100 ------------------------------
6102 -- pragma Assume_No_Invalid_Values (On | Off);
6104 when Pragma_Assume_No_Invalid_Values =>
6106 Check_Valid_Configuration_Pragma;
6107 Check_Arg_Count (1);
6108 Check_No_Identifiers;
6109 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6111 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6112 Assume_No_Invalid_Values := True;
6114 Assume_No_Invalid_Values := False;
6121 -- pragma AST_Entry (entry_IDENTIFIER);
6123 when Pragma_AST_Entry => AST_Entry : declare
6129 Check_Arg_Count (1);
6130 Check_No_Identifiers;
6131 Check_Arg_Is_Local_Name (Arg1);
6132 Ent := Entity (Get_Pragma_Arg (Arg1));
6134 -- Note: the implementation of the AST_Entry pragma could handle
6135 -- the entry family case fine, but for now we are consistent with
6136 -- the DEC rules, and do not allow the pragma, which of course
6137 -- has the effect of also forbidding the attribute.
6139 if Ekind (Ent) /= E_Entry then
6141 ("pragma% argument must be simple entry name", Arg1);
6143 elsif Is_AST_Entry (Ent) then
6145 ("duplicate % pragma for entry", Arg1);
6147 elsif Has_Homonym (Ent) then
6149 ("pragma% argument cannot specify overloaded entry", Arg1);
6153 FF : constant Entity_Id := First_Formal (Ent);
6156 if Present (FF) then
6157 if Present (Next_Formal (FF)) then
6159 ("entry for pragma% can have only one argument",
6162 elsif Parameter_Mode (FF) /= E_In_Parameter then
6164 ("entry parameter for pragma% must have mode IN",
6170 Set_Is_AST_Entry (Ent);
6178 -- pragma Asynchronous (LOCAL_NAME);
6180 when Pragma_Asynchronous => Asynchronous : declare
6188 procedure Process_Async_Pragma;
6189 -- Common processing for procedure and access-to-procedure case
6191 --------------------------
6192 -- Process_Async_Pragma --
6193 --------------------------
6195 procedure Process_Async_Pragma is
6198 Set_Is_Asynchronous (Nm);
6202 -- The formals should be of mode IN (RM E.4.1(6))
6205 while Present (S) loop
6206 Formal := Defining_Identifier (S);
6208 if Nkind (Formal) = N_Defining_Identifier
6209 and then Ekind (Formal) /= E_In_Parameter
6212 ("pragma% procedure can only have IN parameter",
6219 Set_Is_Asynchronous (Nm);
6220 end Process_Async_Pragma;
6222 -- Start of processing for pragma Asynchronous
6225 Check_Ada_83_Warning;
6226 Check_No_Identifiers;
6227 Check_Arg_Count (1);
6228 Check_Arg_Is_Local_Name (Arg1);
6230 if Debug_Flag_U then
6234 C_Ent := Cunit_Entity (Current_Sem_Unit);
6235 Analyze (Get_Pragma_Arg (Arg1));
6236 Nm := Entity (Get_Pragma_Arg (Arg1));
6238 if not Is_Remote_Call_Interface (C_Ent)
6239 and then not Is_Remote_Types (C_Ent)
6241 -- This pragma should only appear in an RCI or Remote Types
6242 -- unit (RM E.4.1(4)).
6245 ("pragma% not in Remote_Call_Interface or " &
6246 "Remote_Types unit");
6249 if Ekind (Nm) = E_Procedure
6250 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6252 if not Is_Remote_Call_Interface (Nm) then
6254 ("pragma% cannot be applied on non-remote procedure",
6258 L := Parameter_Specifications (Parent (Nm));
6259 Process_Async_Pragma;
6262 elsif Ekind (Nm) = E_Function then
6264 ("pragma% cannot be applied to function", Arg1);
6266 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6268 if Is_Record_Type (Nm) then
6270 -- A record type that is the Equivalent_Type for a remote
6271 -- access-to-subprogram type.
6273 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6276 -- A non-expanded RAS type (distribution is not enabled)
6278 N := Declaration_Node (Nm);
6281 if Nkind (N) = N_Full_Type_Declaration
6282 and then Nkind (Type_Definition (N)) =
6283 N_Access_Procedure_Definition
6285 L := Parameter_Specifications (Type_Definition (N));
6286 Process_Async_Pragma;
6288 if Is_Asynchronous (Nm)
6289 and then Expander_Active
6290 and then Get_PCS_Name /= Name_No_DSA
6292 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6297 ("pragma% cannot reference access-to-function type",
6301 -- Only other possibility is Access-to-class-wide type
6303 elsif Is_Access_Type (Nm)
6304 and then Is_Class_Wide_Type (Designated_Type (Nm))
6306 Check_First_Subtype (Arg1);
6307 Set_Is_Asynchronous (Nm);
6308 if Expander_Active then
6309 RACW_Type_Is_Asynchronous (Nm);
6313 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6321 -- pragma Atomic (LOCAL_NAME);
6323 when Pragma_Atomic =>
6324 Process_Atomic_Shared_Volatile;
6326 -----------------------
6327 -- Atomic_Components --
6328 -----------------------
6330 -- pragma Atomic_Components (array_LOCAL_NAME);
6332 -- This processing is shared by Volatile_Components
6334 when Pragma_Atomic_Components |
6335 Pragma_Volatile_Components =>
6337 Atomic_Components : declare
6344 Check_Ada_83_Warning;
6345 Check_No_Identifiers;
6346 Check_Arg_Count (1);
6347 Check_Arg_Is_Local_Name (Arg1);
6348 E_Id := Get_Pragma_Arg (Arg1);
6350 if Etype (E_Id) = Any_Type then
6356 Check_Duplicate_Pragma (E);
6358 if Rep_Item_Too_Early (E, N)
6360 Rep_Item_Too_Late (E, N)
6365 D := Declaration_Node (E);
6368 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6370 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6371 and then Nkind (D) = N_Object_Declaration
6372 and then Nkind (Object_Definition (D)) =
6373 N_Constrained_Array_Definition)
6375 -- The flag is set on the object, or on the base type
6377 if Nkind (D) /= N_Object_Declaration then
6381 Set_Has_Volatile_Components (E, Sense);
6383 if Prag_Id = Pragma_Atomic_Components then
6384 Set_Has_Atomic_Components (E, Sense);
6388 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6390 end Atomic_Components;
6392 --------------------
6393 -- Attach_Handler --
6394 --------------------
6396 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6398 when Pragma_Attach_Handler =>
6399 Check_Ada_83_Warning;
6400 Check_No_Identifiers;
6401 Check_Arg_Count (2);
6403 if No_Run_Time_Mode then
6404 Error_Msg_CRT ("Attach_Handler pragma", N);
6406 Check_Interrupt_Or_Attach_Handler;
6408 -- The expression that designates the attribute may depend on a
6409 -- discriminant, and is therefore a per- object expression, to
6410 -- be expanded in the init proc. If expansion is enabled, then
6411 -- perform semantic checks on a copy only.
6413 if Expander_Active then
6415 Temp : constant Node_Id :=
6416 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6418 Set_Parent (Temp, N);
6419 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6423 Analyze (Get_Pragma_Arg (Arg2));
6424 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6427 Process_Interrupt_Or_Attach_Handler;
6430 --------------------
6431 -- C_Pass_By_Copy --
6432 --------------------
6434 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6436 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6442 Check_Valid_Configuration_Pragma;
6443 Check_Arg_Count (1);
6444 Check_Optional_Identifier (Arg1, "max_size");
6446 Arg := Get_Pragma_Arg (Arg1);
6447 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6449 Val := Expr_Value (Arg);
6453 ("maximum size for pragma% must be positive", Arg1);
6455 elsif UI_Is_In_Int_Range (Val) then
6456 Default_C_Record_Mechanism := UI_To_Int (Val);
6458 -- If a giant value is given, Int'Last will do well enough.
6459 -- If sometime someone complains that a record larger than
6460 -- two gigabytes is not copied, we will worry about it then!
6463 Default_C_Record_Mechanism := Mechanism_Type'Last;
6471 -- pragma Check ([Name =>] Identifier,
6472 -- [Check =>] Boolean_Expression
6473 -- [,[Message =>] String_Expression]);
6475 when Pragma_Check => Check : declare
6480 -- Set True if category of assertions referenced by Name enabled
6484 Check_At_Least_N_Arguments (2);
6485 Check_At_Most_N_Arguments (3);
6486 Check_Optional_Identifier (Arg1, Name_Name);
6487 Check_Optional_Identifier (Arg2, Name_Check);
6489 if Arg_Count = 3 then
6490 Check_Optional_Identifier (Arg3, Name_Message);
6491 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6494 Check_Arg_Is_Identifier (Arg1);
6496 -- Indicate if pragma is enabled. The Original_Node reference here
6497 -- is to deal with pragma Assert rewritten as a Check pragma.
6499 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6502 Set_Pragma_Enabled (N);
6503 Set_Pragma_Enabled (Original_Node (N));
6504 Set_SCO_Pragma_Enabled (Loc);
6507 -- If expansion is active and the check is not enabled then we
6508 -- rewrite the Check as:
6510 -- if False and then condition then
6514 -- The reason we do this rewriting during semantic analysis rather
6515 -- than as part of normal expansion is that we cannot analyze and
6516 -- expand the code for the boolean expression directly, or it may
6517 -- cause insertion of actions that would escape the attempt to
6518 -- suppress the check code.
6520 -- Note that the Sloc for the if statement corresponds to the
6521 -- argument condition, not the pragma itself. The reason for this
6522 -- is that we may generate a warning if the condition is False at
6523 -- compile time, and we do not want to delete this warning when we
6524 -- delete the if statement.
6526 Expr := Get_Pragma_Arg (Arg2);
6528 if Expander_Active and then not Check_On then
6529 Eloc := Sloc (Expr);
6532 Make_If_Statement (Eloc,
6534 Make_And_Then (Eloc,
6535 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6536 Right_Opnd => Expr),
6537 Then_Statements => New_List (
6538 Make_Null_Statement (Eloc))));
6545 Analyze_And_Resolve (Expr, Any_Boolean);
6553 -- pragma Check_Name (check_IDENTIFIER);
6555 when Pragma_Check_Name =>
6556 Check_No_Identifiers;
6558 Check_Valid_Configuration_Pragma;
6559 Check_Arg_Count (1);
6560 Check_Arg_Is_Identifier (Arg1);
6563 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6566 for J in Check_Names.First .. Check_Names.Last loop
6567 if Check_Names.Table (J) = Nam then
6572 Check_Names.Append (Nam);
6579 -- pragma Check_Policy (
6580 -- [Name =>] IDENTIFIER,
6581 -- [Policy =>] POLICY_IDENTIFIER);
6583 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6585 -- Note: this is a configuration pragma, but it is allowed to appear
6588 when Pragma_Check_Policy =>
6590 Check_Arg_Count (2);
6591 Check_Optional_Identifier (Arg1, Name_Name);
6592 Check_Optional_Identifier (Arg2, Name_Policy);
6594 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6596 -- A Check_Policy pragma can appear either as a configuration
6597 -- pragma, or in a declarative part or a package spec (see RM
6598 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6599 -- followed for Check_Policy).
6601 if not Is_Configuration_Pragma then
6602 Check_Is_In_Decl_Part_Or_Package_Spec;
6605 Set_Next_Pragma (N, Opt.Check_Policy_List);
6606 Opt.Check_Policy_List := N;
6608 ---------------------
6609 -- CIL_Constructor --
6610 ---------------------
6612 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6614 -- Processing for this pragma is shared with Java_Constructor
6620 -- pragma Comment (static_string_EXPRESSION)
6622 -- Processing for pragma Comment shares the circuitry for pragma
6623 -- Ident. The only differences are that Ident enforces a limit of 31
6624 -- characters on its argument, and also enforces limitations on
6625 -- placement for DEC compatibility. Pragma Comment shares neither of
6626 -- these restrictions.
6632 -- pragma Common_Object (
6633 -- [Internal =>] LOCAL_NAME
6634 -- [, [External =>] EXTERNAL_SYMBOL]
6635 -- [, [Size =>] EXTERNAL_SYMBOL]);
6637 -- Processing for this pragma is shared with Psect_Object
6639 ------------------------
6640 -- Compile_Time_Error --
6641 ------------------------
6643 -- pragma Compile_Time_Error
6644 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6646 when Pragma_Compile_Time_Error =>
6648 Process_Compile_Time_Warning_Or_Error;
6650 --------------------------
6651 -- Compile_Time_Warning --
6652 --------------------------
6654 -- pragma Compile_Time_Warning
6655 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6657 when Pragma_Compile_Time_Warning =>
6659 Process_Compile_Time_Warning_Or_Error;
6665 when Pragma_Compiler_Unit =>
6667 Check_Arg_Count (0);
6668 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6670 -----------------------------
6671 -- Complete_Representation --
6672 -----------------------------
6674 -- pragma Complete_Representation;
6676 when Pragma_Complete_Representation =>
6678 Check_Arg_Count (0);
6680 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6682 ("pragma & must appear within record representation clause");
6685 ----------------------------
6686 -- Complex_Representation --
6687 ----------------------------
6689 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6691 when Pragma_Complex_Representation => Complex_Representation : declare
6698 Check_Arg_Count (1);
6699 Check_Optional_Identifier (Arg1, Name_Entity);
6700 Check_Arg_Is_Local_Name (Arg1);
6701 E_Id := Get_Pragma_Arg (Arg1);
6703 if Etype (E_Id) = Any_Type then
6709 if not Is_Record_Type (E) then
6711 ("argument for pragma% must be record type", Arg1);
6714 Ent := First_Entity (E);
6717 or else No (Next_Entity (Ent))
6718 or else Present (Next_Entity (Next_Entity (Ent)))
6719 or else not Is_Floating_Point_Type (Etype (Ent))
6720 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6723 ("record for pragma% must have two fields of the same "
6724 & "floating-point type", Arg1);
6727 Set_Has_Complex_Representation (Base_Type (E));
6729 -- We need to treat the type has having a non-standard
6730 -- representation, for back-end purposes, even though in
6731 -- general a complex will have the default representation
6732 -- of a record with two real components.
6734 Set_Has_Non_Standard_Rep (Base_Type (E));
6736 end Complex_Representation;
6738 -------------------------
6739 -- Component_Alignment --
6740 -------------------------
6742 -- pragma Component_Alignment (
6743 -- [Form =>] ALIGNMENT_CHOICE
6744 -- [, [Name =>] type_LOCAL_NAME]);
6746 -- ALIGNMENT_CHOICE ::=
6748 -- | Component_Size_4
6752 when Pragma_Component_Alignment => Component_AlignmentP : declare
6753 Args : Args_List (1 .. 2);
6754 Names : constant Name_List (1 .. 2) := (
6758 Form : Node_Id renames Args (1);
6759 Name : Node_Id renames Args (2);
6761 Atype : Component_Alignment_Kind;
6766 Gather_Associations (Names, Args);
6769 Error_Pragma ("missing Form argument for pragma%");
6772 Check_Arg_Is_Identifier (Form);
6774 -- Get proper alignment, note that Default = Component_Size on all
6775 -- machines we have so far, and we want to set this value rather
6776 -- than the default value to indicate that it has been explicitly
6777 -- set (and thus will not get overridden by the default component
6778 -- alignment for the current scope)
6780 if Chars (Form) = Name_Component_Size then
6781 Atype := Calign_Component_Size;
6783 elsif Chars (Form) = Name_Component_Size_4 then
6784 Atype := Calign_Component_Size_4;
6786 elsif Chars (Form) = Name_Default then
6787 Atype := Calign_Component_Size;
6789 elsif Chars (Form) = Name_Storage_Unit then
6790 Atype := Calign_Storage_Unit;
6794 ("invalid Form parameter for pragma%", Form);
6797 -- Case with no name, supplied, affects scope table entry
6801 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6803 -- Case of name supplied
6806 Check_Arg_Is_Local_Name (Name);
6808 Typ := Entity (Name);
6811 or else Rep_Item_Too_Early (Typ, N)
6815 Typ := Underlying_Type (Typ);
6818 if not Is_Record_Type (Typ)
6819 and then not Is_Array_Type (Typ)
6822 ("Name parameter of pragma% must identify record or " &
6823 "array type", Name);
6826 -- An explicit Component_Alignment pragma overrides an
6827 -- implicit pragma Pack, but not an explicit one.
6829 if not Has_Pragma_Pack (Base_Type (Typ)) then
6830 Set_Is_Packed (Base_Type (Typ), False);
6831 Set_Component_Alignment (Base_Type (Typ), Atype);
6834 end Component_AlignmentP;
6840 -- pragma Controlled (first_subtype_LOCAL_NAME);
6842 when Pragma_Controlled => Controlled : declare
6846 Check_No_Identifiers;
6847 Check_Arg_Count (1);
6848 Check_Arg_Is_Local_Name (Arg1);
6849 Arg := Get_Pragma_Arg (Arg1);
6851 if not Is_Entity_Name (Arg)
6852 or else not Is_Access_Type (Entity (Arg))
6854 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6856 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6864 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6865 -- [Entity =>] LOCAL_NAME);
6867 when Pragma_Convention => Convention : declare
6870 pragma Warnings (Off, C);
6871 pragma Warnings (Off, E);
6873 Check_Arg_Order ((Name_Convention, Name_Entity));
6874 Check_Ada_83_Warning;
6875 Check_Arg_Count (2);
6876 Process_Convention (C, E);
6879 ---------------------------
6880 -- Convention_Identifier --
6881 ---------------------------
6883 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6884 -- [Convention =>] convention_IDENTIFIER);
6886 when Pragma_Convention_Identifier => Convention_Identifier : declare
6892 Check_Arg_Order ((Name_Name, Name_Convention));
6893 Check_Arg_Count (2);
6894 Check_Optional_Identifier (Arg1, Name_Name);
6895 Check_Optional_Identifier (Arg2, Name_Convention);
6896 Check_Arg_Is_Identifier (Arg1);
6897 Check_Arg_Is_Identifier (Arg2);
6898 Idnam := Chars (Get_Pragma_Arg (Arg1));
6899 Cname := Chars (Get_Pragma_Arg (Arg2));
6901 if Is_Convention_Name (Cname) then
6902 Record_Convention_Identifier
6903 (Idnam, Get_Convention_Id (Cname));
6906 ("second arg for % pragma must be convention", Arg2);
6908 end Convention_Identifier;
6914 -- pragma CPP_Class ([Entity =>] local_NAME)
6916 when Pragma_CPP_Class => CPP_Class : declare
6921 if Warn_On_Obsolescent_Feature then
6923 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6924 " by pragma import?", N);
6928 Check_Arg_Count (1);
6929 Check_Optional_Identifier (Arg1, Name_Entity);
6930 Check_Arg_Is_Local_Name (Arg1);
6932 Arg := Get_Pragma_Arg (Arg1);
6935 if Etype (Arg) = Any_Type then
6939 if not Is_Entity_Name (Arg)
6940 or else not Is_Type (Entity (Arg))
6942 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6945 Typ := Entity (Arg);
6947 if not Is_Tagged_Type (Typ) then
6948 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6951 -- Types treated as CPP classes are treated as limited, but we
6952 -- don't require them to be declared this way. A warning is issued
6953 -- to encourage the user to declare them as limited. This is not
6954 -- an error, for compatibility reasons, because these types have
6955 -- been supported this way for some time.
6957 if not Is_Limited_Type (Typ) then
6959 ("imported 'C'P'P type should be " &
6960 "explicitly declared limited?",
6961 Get_Pragma_Arg (Arg1));
6963 ("\type will be considered limited",
6964 Get_Pragma_Arg (Arg1));
6967 Set_Is_CPP_Class (Typ);
6968 Set_Is_Limited_Record (Typ);
6969 Set_Convention (Typ, Convention_CPP);
6971 -- Imported CPP types must not have discriminants (because C++
6972 -- classes do not have discriminants).
6974 if Has_Discriminants (Typ) then
6976 ("imported 'C'P'P type cannot have discriminants",
6977 First (Discriminant_Specifications
6978 (Declaration_Node (Typ))));
6981 -- Components of imported CPP types must not have default
6982 -- expressions because the constructor (if any) is in the
6985 if Is_Incomplete_Or_Private_Type (Typ)
6986 and then No (Underlying_Type (Typ))
6988 -- It should be an error to apply pragma CPP to a private
6989 -- type if the underlying type is not visible (as it is
6990 -- for any representation item). For now, for backward
6991 -- compatibility we do nothing but we cannot check components
6992 -- because they are not available at this stage. All this code
6993 -- will be removed when we cleanup this obsolete GNAT pragma???
6999 Tdef : constant Node_Id :=
7000 Type_Definition (Declaration_Node (Typ));
7005 if Nkind (Tdef) = N_Record_Definition then
7006 Clist := Component_List (Tdef);
7008 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7009 Clist := Component_List (Record_Extension_Part (Tdef));
7012 if Present (Clist) then
7013 Comp := First (Component_Items (Clist));
7014 while Present (Comp) loop
7015 if Present (Expression (Comp)) then
7017 ("component of imported 'C'P'P type cannot have" &
7018 " default expression", Expression (Comp));
7028 ---------------------
7029 -- CPP_Constructor --
7030 ---------------------
7032 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7033 -- [, [External_Name =>] static_string_EXPRESSION ]
7034 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7036 when Pragma_CPP_Constructor => CPP_Constructor : declare
7040 Tag_Typ : Entity_Id;
7044 Check_At_Least_N_Arguments (1);
7045 Check_At_Most_N_Arguments (3);
7046 Check_Optional_Identifier (Arg1, Name_Entity);
7047 Check_Arg_Is_Local_Name (Arg1);
7049 Id := Get_Pragma_Arg (Arg1);
7050 Find_Program_Unit_Name (Id);
7052 -- If we did not find the name, we are done
7054 if Etype (Id) = Any_Type then
7058 Def_Id := Entity (Id);
7060 -- Check if already defined as constructor
7062 if Is_Constructor (Def_Id) then
7064 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7068 if Ekind (Def_Id) = E_Function
7069 and then (Is_CPP_Class (Etype (Def_Id))
7070 or else (Is_Class_Wide_Type (Etype (Def_Id))
7072 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7074 if Arg_Count >= 2 then
7075 Set_Imported (Def_Id);
7076 Set_Is_Public (Def_Id);
7077 Process_Interface_Name (Def_Id, Arg2, Arg3);
7080 Set_Has_Completion (Def_Id);
7081 Set_Is_Constructor (Def_Id);
7083 -- Imported C++ constructors are not dispatching primitives
7084 -- because in C++ they don't have a dispatch table slot.
7085 -- However, in Ada the constructor has the profile of a
7086 -- function that returns a tagged type and therefore it has
7087 -- been treated as a primitive operation during semantic
7088 -- analysis. We now remove it from the list of primitive
7089 -- operations of the type.
7091 if Is_Tagged_Type (Etype (Def_Id))
7092 and then not Is_Class_Wide_Type (Etype (Def_Id))
7094 pragma Assert (Is_Dispatching_Operation (Def_Id));
7095 Tag_Typ := Etype (Def_Id);
7097 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7098 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7102 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7103 Set_Is_Dispatching_Operation (Def_Id, False);
7106 -- For backward compatibility, if the constructor returns a
7107 -- class wide type, and we internally change the return type to
7108 -- the corresponding root type.
7110 if Is_Class_Wide_Type (Etype (Def_Id)) then
7111 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7115 ("pragma% requires function returning a 'C'P'P_Class type",
7118 end CPP_Constructor;
7124 when Pragma_CPP_Virtual => CPP_Virtual : declare
7128 if Warn_On_Obsolescent_Feature then
7130 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7139 when Pragma_CPP_Vtable => CPP_Vtable : declare
7143 if Warn_On_Obsolescent_Feature then
7145 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7154 -- pragma CPU (EXPRESSION);
7156 when Pragma_CPU => CPU : declare
7157 P : constant Node_Id := Parent (N);
7162 Check_No_Identifiers;
7163 Check_Arg_Count (1);
7167 if Nkind (P) = N_Subprogram_Body then
7168 Check_In_Main_Program;
7170 Arg := Get_Pragma_Arg (Arg1);
7171 Analyze_And_Resolve (Arg, Any_Integer);
7175 if not Is_Static_Expression (Arg) then
7176 Flag_Non_Static_Expr
7177 ("main subprogram affinity is not static!", Arg);
7180 -- If constraint error, then we already signalled an error
7182 elsif Raises_Constraint_Error (Arg) then
7185 -- Otherwise check in range
7189 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7190 -- This is the entity System.Multiprocessors.CPU_Range;
7192 Val : constant Uint := Expr_Value (Arg);
7195 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7197 Val > Expr_Value (Type_High_Bound (CPU_Id))
7200 ("main subprogram CPU is out of range", Arg1);
7206 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7210 elsif Nkind (P) = N_Task_Definition then
7211 Arg := Get_Pragma_Arg (Arg1);
7213 -- The expression must be analyzed in the special manner
7214 -- described in "Handling of Default and Per-Object
7215 -- Expressions" in sem.ads.
7217 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7219 -- Anything else is incorrect
7225 if Has_Pragma_CPU (P) then
7226 Error_Pragma ("duplicate pragma% not allowed");
7228 Set_Has_Pragma_CPU (P, True);
7230 if Nkind (P) = N_Task_Definition then
7231 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7240 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7242 when Pragma_Debug => Debug : declare
7250 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7253 if Arg_Count = 2 then
7256 Left_Opnd => Relocate_Node (Cond),
7257 Right_Opnd => Get_Pragma_Arg (Arg1));
7260 -- Rewrite into a conditional with an appropriate condition. We
7261 -- wrap the procedure call in a block so that overhead from e.g.
7262 -- use of the secondary stack does not generate execution overhead
7263 -- for suppressed conditions.
7265 Rewrite (N, Make_Implicit_If_Statement (N,
7267 Then_Statements => New_List (
7268 Make_Block_Statement (Loc,
7269 Handled_Statement_Sequence =>
7270 Make_Handled_Sequence_Of_Statements (Loc,
7271 Statements => New_List (
7272 Relocate_Node (Debug_Statement (N))))))));
7280 -- pragma Debug_Policy (Check | Ignore)
7282 when Pragma_Debug_Policy =>
7284 Check_Arg_Count (1);
7285 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7286 Debug_Pragmas_Enabled :=
7287 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7289 ---------------------
7290 -- Detect_Blocking --
7291 ---------------------
7293 -- pragma Detect_Blocking;
7295 when Pragma_Detect_Blocking =>
7297 Check_Arg_Count (0);
7298 Check_Valid_Configuration_Pragma;
7299 Detect_Blocking := True;
7301 --------------------------
7302 -- Default_Storage_Pool --
7303 --------------------------
7305 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7307 when Pragma_Default_Storage_Pool =>
7309 Check_Arg_Count (1);
7311 -- Default_Storage_Pool can appear as a configuration pragma, or
7312 -- in a declarative part or a package spec.
7314 if not Is_Configuration_Pragma then
7315 Check_Is_In_Decl_Part_Or_Package_Spec;
7318 -- Case of Default_Storage_Pool (null);
7320 if Nkind (Expression (Arg1)) = N_Null then
7321 Analyze (Expression (Arg1));
7323 -- This is an odd case, this is not really an expression, so
7324 -- we don't have a type for it. So just set the type to Empty.
7326 Set_Etype (Expression (Arg1), Empty);
7328 -- Case of Default_Storage_Pool (storage_pool_NAME);
7331 -- If it's a configuration pragma, then the only allowed
7332 -- argument is "null".
7334 if Is_Configuration_Pragma then
7335 Error_Pragma_Arg ("NULL expected", Arg1);
7338 -- The expected type for a non-"null" argument is
7339 -- Root_Storage_Pool'Class.
7342 (Get_Pragma_Arg (Arg1),
7343 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7346 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7347 -- for an access type will use this information to set the
7348 -- appropriate attributes of the access type.
7350 Default_Pool := Expression (Arg1);
7356 when Pragma_Dimension =>
7358 Check_Arg_Count (4);
7359 Check_No_Identifiers;
7360 Check_Arg_Is_Local_Name (Arg1);
7362 if not Is_Type (Arg1) then
7363 Error_Pragma ("first argument for pragma% must be subtype");
7366 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7367 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7368 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7374 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7376 when Pragma_Discard_Names => Discard_Names : declare
7381 Check_Ada_83_Warning;
7383 -- Deal with configuration pragma case
7385 if Arg_Count = 0 and then Is_Configuration_Pragma then
7386 Global_Discard_Names := True;
7389 -- Otherwise, check correct appropriate context
7392 Check_Is_In_Decl_Part_Or_Package_Spec;
7394 if Arg_Count = 0 then
7396 -- If there is no parameter, then from now on this pragma
7397 -- applies to any enumeration, exception or tagged type
7398 -- defined in the current declarative part, and recursively
7399 -- to any nested scope.
7401 Set_Discard_Names (Current_Scope, Sense);
7405 Check_Arg_Count (1);
7406 Check_Optional_Identifier (Arg1, Name_On);
7407 Check_Arg_Is_Local_Name (Arg1);
7409 E_Id := Get_Pragma_Arg (Arg1);
7411 if Etype (E_Id) = Any_Type then
7417 if (Is_First_Subtype (E)
7419 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7420 or else Ekind (E) = E_Exception
7422 Set_Discard_Names (E, Sense);
7425 ("inappropriate entity for pragma%", Arg1);
7436 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7438 when Pragma_Elaborate => Elaborate : declare
7443 -- Pragma must be in context items list of a compilation unit
7445 if not Is_In_Context_Clause then
7449 -- Must be at least one argument
7451 if Arg_Count = 0 then
7452 Error_Pragma ("pragma% requires at least one argument");
7455 -- In Ada 83 mode, there can be no items following it in the
7456 -- context list except other pragmas and implicit with clauses
7457 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7458 -- placement rule does not apply.
7460 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7462 while Present (Citem) loop
7463 if Nkind (Citem) = N_Pragma
7464 or else (Nkind (Citem) = N_With_Clause
7465 and then Implicit_With (Citem))
7470 ("(Ada 83) pragma% must be at end of context clause");
7477 -- Finally, the arguments must all be units mentioned in a with
7478 -- clause in the same context clause. Note we already checked (in
7479 -- Par.Prag) that the arguments are all identifiers or selected
7483 Outer : while Present (Arg) loop
7484 Citem := First (List_Containing (N));
7485 Inner : while Citem /= N loop
7486 if Nkind (Citem) = N_With_Clause
7487 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7489 Set_Elaborate_Present (Citem, True);
7490 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7492 -- With the pragma present, elaboration calls on
7493 -- subprograms from the named unit need no further
7494 -- checks, as long as the pragma appears in the current
7495 -- compilation unit. If the pragma appears in some unit
7496 -- in the context, there might still be a need for an
7497 -- Elaborate_All_Desirable from the current compilation
7498 -- to the named unit, so we keep the check enabled.
7500 if In_Extended_Main_Source_Unit (N) then
7501 Set_Suppress_Elaboration_Warnings
7502 (Entity (Name (Citem)));
7513 ("argument of pragma% is not with'ed unit", Arg);
7519 -- Give a warning if operating in static mode with -gnatwl
7520 -- (elaboration warnings enabled) switch set.
7522 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7524 ("?use of pragma Elaborate may not be safe", N);
7526 ("?use pragma Elaborate_All instead if possible", N);
7534 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7536 when Pragma_Elaborate_All => Elaborate_All : declare
7541 Check_Ada_83_Warning;
7543 -- Pragma must be in context items list of a compilation unit
7545 if not Is_In_Context_Clause then
7549 -- Must be at least one argument
7551 if Arg_Count = 0 then
7552 Error_Pragma ("pragma% requires at least one argument");
7555 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7556 -- have to appear at the end of the context clause, but may
7557 -- appear mixed in with other items, even in Ada 83 mode.
7559 -- Final check: the arguments must all be units mentioned in
7560 -- a with clause in the same context clause. Note that we
7561 -- already checked (in Par.Prag) that all the arguments are
7562 -- either identifiers or selected components.
7565 Outr : while Present (Arg) loop
7566 Citem := First (List_Containing (N));
7567 Innr : while Citem /= N loop
7568 if Nkind (Citem) = N_With_Clause
7569 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7571 Set_Elaborate_All_Present (Citem, True);
7572 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7574 -- Suppress warnings and elaboration checks on the named
7575 -- unit if the pragma is in the current compilation, as
7576 -- for pragma Elaborate.
7578 if In_Extended_Main_Source_Unit (N) then
7579 Set_Suppress_Elaboration_Warnings
7580 (Entity (Name (Citem)));
7589 Set_Error_Posted (N);
7591 ("argument of pragma% is not with'ed unit", Arg);
7598 --------------------
7599 -- Elaborate_Body --
7600 --------------------
7602 -- pragma Elaborate_Body [( library_unit_NAME )];
7604 when Pragma_Elaborate_Body => Elaborate_Body : declare
7605 Cunit_Node : Node_Id;
7606 Cunit_Ent : Entity_Id;
7609 Check_Ada_83_Warning;
7610 Check_Valid_Library_Unit_Pragma;
7612 if Nkind (N) = N_Null_Statement then
7616 Cunit_Node := Cunit (Current_Sem_Unit);
7617 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7619 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7622 Error_Pragma ("pragma% must refer to a spec, not a body");
7624 Set_Body_Required (Cunit_Node, True);
7625 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7627 -- If we are in dynamic elaboration mode, then we suppress
7628 -- elaboration warnings for the unit, since it is definitely
7629 -- fine NOT to do dynamic checks at the first level (and such
7630 -- checks will be suppressed because no elaboration boolean
7631 -- is created for Elaborate_Body packages).
7633 -- But in the static model of elaboration, Elaborate_Body is
7634 -- definitely NOT good enough to ensure elaboration safety on
7635 -- its own, since the body may WITH other units that are not
7636 -- safe from an elaboration point of view, so a client must
7637 -- still do an Elaborate_All on such units.
7639 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7640 -- Elaborate_Body always suppressed elab warnings.
7642 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7643 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7648 ------------------------
7649 -- Elaboration_Checks --
7650 ------------------------
7652 -- pragma Elaboration_Checks (Static | Dynamic);
7654 when Pragma_Elaboration_Checks =>
7656 Check_Arg_Count (1);
7657 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7658 Dynamic_Elaboration_Checks :=
7659 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7665 -- pragma Eliminate (
7666 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7667 -- [,[Entity =>] IDENTIFIER |
7668 -- SELECTED_COMPONENT |
7670 -- [, OVERLOADING_RESOLUTION]);
7672 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7675 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7678 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7680 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7681 -- Result_Type => result_SUBTYPE_NAME]
7683 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7684 -- SUBTYPE_NAME ::= STRING_LITERAL
7686 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7687 -- SOURCE_TRACE ::= STRING_LITERAL
7689 when Pragma_Eliminate => Eliminate : declare
7690 Args : Args_List (1 .. 5);
7691 Names : constant Name_List (1 .. 5) := (
7694 Name_Parameter_Types,
7696 Name_Source_Location);
7698 Unit_Name : Node_Id renames Args (1);
7699 Entity : Node_Id renames Args (2);
7700 Parameter_Types : Node_Id renames Args (3);
7701 Result_Type : Node_Id renames Args (4);
7702 Source_Location : Node_Id renames Args (5);
7706 Check_Valid_Configuration_Pragma;
7707 Gather_Associations (Names, Args);
7709 if No (Unit_Name) then
7710 Error_Pragma ("missing Unit_Name argument for pragma%");
7714 and then (Present (Parameter_Types)
7716 Present (Result_Type)
7718 Present (Source_Location))
7720 Error_Pragma ("missing Entity argument for pragma%");
7723 if (Present (Parameter_Types)
7725 Present (Result_Type))
7727 Present (Source_Location)
7730 ("parameter profile and source location cannot " &
7731 "be used together in pragma%");
7734 Process_Eliminate_Pragma
7748 -- [ Convention =>] convention_IDENTIFIER,
7749 -- [ Entity =>] local_NAME
7750 -- [, [External_Name =>] static_string_EXPRESSION ]
7751 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7753 when Pragma_Export => Export : declare
7757 pragma Warnings (Off, C);
7760 Check_Ada_83_Warning;
7766 Check_At_Least_N_Arguments (2);
7767 Check_At_Most_N_Arguments (4);
7768 Process_Convention (C, Def_Id);
7770 if Ekind (Def_Id) /= E_Constant then
7771 Note_Possible_Modification
7772 (Get_Pragma_Arg (Arg2), Sure => False);
7775 Process_Interface_Name (Def_Id, Arg3, Arg4);
7776 Set_Exported (Def_Id, Arg2);
7778 -- If the entity is a deferred constant, propagate the information
7779 -- to the full view, because gigi elaborates the full view only.
7781 if Ekind (Def_Id) = E_Constant
7782 and then Present (Full_View (Def_Id))
7785 Id2 : constant Entity_Id := Full_View (Def_Id);
7787 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7788 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7789 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7794 ----------------------
7795 -- Export_Exception --
7796 ----------------------
7798 -- pragma Export_Exception (
7799 -- [Internal =>] LOCAL_NAME
7800 -- [, [External =>] EXTERNAL_SYMBOL]
7801 -- [, [Form =>] Ada | VMS]
7802 -- [, [Code =>] static_integer_EXPRESSION]);
7804 when Pragma_Export_Exception => Export_Exception : declare
7805 Args : Args_List (1 .. 4);
7806 Names : constant Name_List (1 .. 4) := (
7812 Internal : Node_Id renames Args (1);
7813 External : Node_Id renames Args (2);
7814 Form : Node_Id renames Args (3);
7815 Code : Node_Id renames Args (4);
7820 if Inside_A_Generic then
7821 Error_Pragma ("pragma% cannot be used for generic entities");
7824 Gather_Associations (Names, Args);
7825 Process_Extended_Import_Export_Exception_Pragma (
7826 Arg_Internal => Internal,
7827 Arg_External => External,
7831 if not Is_VMS_Exception (Entity (Internal)) then
7832 Set_Exported (Entity (Internal), Internal);
7834 end Export_Exception;
7836 ---------------------
7837 -- Export_Function --
7838 ---------------------
7840 -- pragma Export_Function (
7841 -- [Internal =>] LOCAL_NAME
7842 -- [, [External =>] EXTERNAL_SYMBOL]
7843 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7844 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7845 -- [, [Mechanism =>] MECHANISM]
7846 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7848 -- EXTERNAL_SYMBOL ::=
7850 -- | static_string_EXPRESSION
7852 -- PARAMETER_TYPES ::=
7854 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7856 -- TYPE_DESIGNATOR ::=
7858 -- | subtype_Name ' Access
7862 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7864 -- MECHANISM_ASSOCIATION ::=
7865 -- [formal_parameter_NAME =>] MECHANISM_NAME
7867 -- MECHANISM_NAME ::=
7870 -- | Descriptor [([Class =>] CLASS_NAME)]
7872 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7874 when Pragma_Export_Function => Export_Function : declare
7875 Args : Args_List (1 .. 6);
7876 Names : constant Name_List (1 .. 6) := (
7879 Name_Parameter_Types,
7882 Name_Result_Mechanism);
7884 Internal : Node_Id renames Args (1);
7885 External : Node_Id renames Args (2);
7886 Parameter_Types : Node_Id renames Args (3);
7887 Result_Type : Node_Id renames Args (4);
7888 Mechanism : Node_Id renames Args (5);
7889 Result_Mechanism : Node_Id renames Args (6);
7893 Gather_Associations (Names, Args);
7894 Process_Extended_Import_Export_Subprogram_Pragma (
7895 Arg_Internal => Internal,
7896 Arg_External => External,
7897 Arg_Parameter_Types => Parameter_Types,
7898 Arg_Result_Type => Result_Type,
7899 Arg_Mechanism => Mechanism,
7900 Arg_Result_Mechanism => Result_Mechanism);
7901 end Export_Function;
7907 -- pragma Export_Object (
7908 -- [Internal =>] LOCAL_NAME
7909 -- [, [External =>] EXTERNAL_SYMBOL]
7910 -- [, [Size =>] EXTERNAL_SYMBOL]);
7912 -- EXTERNAL_SYMBOL ::=
7914 -- | static_string_EXPRESSION
7916 -- PARAMETER_TYPES ::=
7918 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7920 -- TYPE_DESIGNATOR ::=
7922 -- | subtype_Name ' Access
7926 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7928 -- MECHANISM_ASSOCIATION ::=
7929 -- [formal_parameter_NAME =>] MECHANISM_NAME
7931 -- MECHANISM_NAME ::=
7934 -- | Descriptor [([Class =>] CLASS_NAME)]
7936 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7938 when Pragma_Export_Object => Export_Object : declare
7939 Args : Args_List (1 .. 3);
7940 Names : constant Name_List (1 .. 3) := (
7945 Internal : Node_Id renames Args (1);
7946 External : Node_Id renames Args (2);
7947 Size : Node_Id renames Args (3);
7951 Gather_Associations (Names, Args);
7952 Process_Extended_Import_Export_Object_Pragma (
7953 Arg_Internal => Internal,
7954 Arg_External => External,
7958 ----------------------
7959 -- Export_Procedure --
7960 ----------------------
7962 -- pragma Export_Procedure (
7963 -- [Internal =>] LOCAL_NAME
7964 -- [, [External =>] EXTERNAL_SYMBOL]
7965 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7966 -- [, [Mechanism =>] MECHANISM]);
7968 -- EXTERNAL_SYMBOL ::=
7970 -- | static_string_EXPRESSION
7972 -- PARAMETER_TYPES ::=
7974 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7976 -- TYPE_DESIGNATOR ::=
7978 -- | subtype_Name ' Access
7982 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7984 -- MECHANISM_ASSOCIATION ::=
7985 -- [formal_parameter_NAME =>] MECHANISM_NAME
7987 -- MECHANISM_NAME ::=
7990 -- | Descriptor [([Class =>] CLASS_NAME)]
7992 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7994 when Pragma_Export_Procedure => Export_Procedure : declare
7995 Args : Args_List (1 .. 4);
7996 Names : constant Name_List (1 .. 4) := (
7999 Name_Parameter_Types,
8002 Internal : Node_Id renames Args (1);
8003 External : Node_Id renames Args (2);
8004 Parameter_Types : Node_Id renames Args (3);
8005 Mechanism : Node_Id renames Args (4);
8009 Gather_Associations (Names, Args);
8010 Process_Extended_Import_Export_Subprogram_Pragma (
8011 Arg_Internal => Internal,
8012 Arg_External => External,
8013 Arg_Parameter_Types => Parameter_Types,
8014 Arg_Mechanism => Mechanism);
8015 end Export_Procedure;
8021 -- pragma Export_Value (
8022 -- [Value =>] static_integer_EXPRESSION,
8023 -- [Link_Name =>] static_string_EXPRESSION);
8025 when Pragma_Export_Value =>
8027 Check_Arg_Order ((Name_Value, Name_Link_Name));
8028 Check_Arg_Count (2);
8030 Check_Optional_Identifier (Arg1, Name_Value);
8031 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8033 Check_Optional_Identifier (Arg2, Name_Link_Name);
8034 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8036 -----------------------------
8037 -- Export_Valued_Procedure --
8038 -----------------------------
8040 -- pragma Export_Valued_Procedure (
8041 -- [Internal =>] LOCAL_NAME
8042 -- [, [External =>] EXTERNAL_SYMBOL,]
8043 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8044 -- [, [Mechanism =>] MECHANISM]);
8046 -- EXTERNAL_SYMBOL ::=
8048 -- | static_string_EXPRESSION
8050 -- PARAMETER_TYPES ::=
8052 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8054 -- TYPE_DESIGNATOR ::=
8056 -- | subtype_Name ' Access
8060 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8062 -- MECHANISM_ASSOCIATION ::=
8063 -- [formal_parameter_NAME =>] MECHANISM_NAME
8065 -- MECHANISM_NAME ::=
8068 -- | Descriptor [([Class =>] CLASS_NAME)]
8070 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8072 when Pragma_Export_Valued_Procedure =>
8073 Export_Valued_Procedure : declare
8074 Args : Args_List (1 .. 4);
8075 Names : constant Name_List (1 .. 4) := (
8078 Name_Parameter_Types,
8081 Internal : Node_Id renames Args (1);
8082 External : Node_Id renames Args (2);
8083 Parameter_Types : Node_Id renames Args (3);
8084 Mechanism : Node_Id renames Args (4);
8088 Gather_Associations (Names, Args);
8089 Process_Extended_Import_Export_Subprogram_Pragma (
8090 Arg_Internal => Internal,
8091 Arg_External => External,
8092 Arg_Parameter_Types => Parameter_Types,
8093 Arg_Mechanism => Mechanism);
8094 end Export_Valued_Procedure;
8100 -- pragma Extend_System ([Name =>] Identifier);
8102 when Pragma_Extend_System => Extend_System : declare
8105 Check_Valid_Configuration_Pragma;
8106 Check_Arg_Count (1);
8107 Check_Optional_Identifier (Arg1, Name_Name);
8108 Check_Arg_Is_Identifier (Arg1);
8110 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8113 and then Name_Buffer (1 .. 4) = "aux_"
8115 if Present (System_Extend_Pragma_Arg) then
8116 if Chars (Get_Pragma_Arg (Arg1)) =
8117 Chars (Expression (System_Extend_Pragma_Arg))
8121 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8122 Error_Pragma ("pragma% conflicts with that #");
8126 System_Extend_Pragma_Arg := Arg1;
8128 if not GNAT_Mode then
8129 System_Extend_Unit := Arg1;
8133 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8137 ------------------------
8138 -- Extensions_Allowed --
8139 ------------------------
8141 -- pragma Extensions_Allowed (ON | OFF);
8143 when Pragma_Extensions_Allowed =>
8145 Check_Arg_Count (1);
8146 Check_No_Identifiers;
8147 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8149 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8150 Extensions_Allowed := True;
8151 Ada_Version := Ada_Version_Type'Last;
8154 Extensions_Allowed := False;
8155 Ada_Version := Ada_Version_Explicit;
8162 -- pragma External (
8163 -- [ Convention =>] convention_IDENTIFIER,
8164 -- [ Entity =>] local_NAME
8165 -- [, [External_Name =>] static_string_EXPRESSION ]
8166 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8168 when Pragma_External => External : declare
8172 pragma Warnings (Off, C);
8181 Check_At_Least_N_Arguments (2);
8182 Check_At_Most_N_Arguments (4);
8183 Process_Convention (C, Def_Id);
8184 Note_Possible_Modification
8185 (Get_Pragma_Arg (Arg2), Sure => False);
8186 Process_Interface_Name (Def_Id, Arg3, Arg4);
8187 Set_Exported (Def_Id, Arg2);
8190 --------------------------
8191 -- External_Name_Casing --
8192 --------------------------
8194 -- pragma External_Name_Casing (
8195 -- UPPERCASE | LOWERCASE
8196 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8198 when Pragma_External_Name_Casing => External_Name_Casing : declare
8201 Check_No_Identifiers;
8203 if Arg_Count = 2 then
8205 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8207 case Chars (Get_Pragma_Arg (Arg2)) is
8209 Opt.External_Name_Exp_Casing := As_Is;
8211 when Name_Uppercase =>
8212 Opt.External_Name_Exp_Casing := Uppercase;
8214 when Name_Lowercase =>
8215 Opt.External_Name_Exp_Casing := Lowercase;
8222 Check_Arg_Count (1);
8225 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8227 case Chars (Get_Pragma_Arg (Arg1)) is
8228 when Name_Uppercase =>
8229 Opt.External_Name_Imp_Casing := Uppercase;
8231 when Name_Lowercase =>
8232 Opt.External_Name_Imp_Casing := Lowercase;
8237 end External_Name_Casing;
8239 --------------------------
8240 -- Favor_Top_Level --
8241 --------------------------
8243 -- pragma Favor_Top_Level (type_NAME);
8245 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8246 Named_Entity : Entity_Id;
8250 Check_No_Identifiers;
8251 Check_Arg_Count (1);
8252 Check_Arg_Is_Local_Name (Arg1);
8253 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8255 -- If it's an access-to-subprogram type (in particular, not a
8256 -- subtype), set the flag on that type.
8258 if Is_Access_Subprogram_Type (Named_Entity) then
8260 Set_Can_Use_Internal_Rep (Named_Entity, False);
8263 -- Otherwise it's an error (name denotes the wrong sort of entity)
8267 ("access-to-subprogram type expected",
8268 Get_Pragma_Arg (Arg1));
8270 end Favor_Top_Level;
8276 -- pragma Fast_Math;
8278 when Pragma_Fast_Math =>
8280 Check_No_Identifiers;
8281 Check_Valid_Configuration_Pragma;
8284 ---------------------------
8285 -- Finalize_Storage_Only --
8286 ---------------------------
8288 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8290 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8291 Assoc : constant Node_Id := Arg1;
8292 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8297 Check_No_Identifiers;
8298 Check_Arg_Count (1);
8299 Check_Arg_Is_Local_Name (Arg1);
8301 Find_Type (Type_Id);
8302 Typ := Entity (Type_Id);
8305 or else Rep_Item_Too_Early (Typ, N)
8309 Typ := Underlying_Type (Typ);
8312 if not Is_Controlled (Typ) then
8313 Error_Pragma ("pragma% must specify controlled type");
8316 Check_First_Subtype (Arg1);
8318 if Finalize_Storage_Only (Typ) then
8319 Error_Pragma ("duplicate pragma%, only one allowed");
8321 elsif not Rep_Item_Too_Late (Typ, N) then
8322 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8324 end Finalize_Storage;
8326 --------------------------
8327 -- Float_Representation --
8328 --------------------------
8330 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8332 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8334 when Pragma_Float_Representation => Float_Representation : declare
8342 if Arg_Count = 1 then
8343 Check_Valid_Configuration_Pragma;
8345 Check_Arg_Count (2);
8346 Check_Optional_Identifier (Arg2, Name_Entity);
8347 Check_Arg_Is_Local_Name (Arg2);
8350 Check_No_Identifier (Arg1);
8351 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8353 if not OpenVMS_On_Target then
8354 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8356 ("?pragma% ignored (applies only to Open'V'M'S)");
8362 -- One argument case
8364 if Arg_Count = 1 then
8365 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8366 if Opt.Float_Format = 'I' then
8367 Error_Pragma ("'I'E'E'E format previously specified");
8370 Opt.Float_Format := 'V';
8373 if Opt.Float_Format = 'V' then
8374 Error_Pragma ("'V'A'X format previously specified");
8377 Opt.Float_Format := 'I';
8380 Set_Standard_Fpt_Formats;
8382 -- Two argument case
8385 Argx := Get_Pragma_Arg (Arg2);
8387 if not Is_Entity_Name (Argx)
8388 or else not Is_Floating_Point_Type (Entity (Argx))
8391 ("second argument of% pragma must be floating-point type",
8395 Ent := Entity (Argx);
8396 Digs := UI_To_Int (Digits_Value (Ent));
8398 -- Two arguments, VAX_Float case
8400 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8402 when 6 => Set_F_Float (Ent);
8403 when 9 => Set_D_Float (Ent);
8404 when 15 => Set_G_Float (Ent);
8408 ("wrong digits value, must be 6,9 or 15", Arg2);
8411 -- Two arguments, IEEE_Float case
8415 when 6 => Set_IEEE_Short (Ent);
8416 when 15 => Set_IEEE_Long (Ent);
8420 ("wrong digits value, must be 6 or 15", Arg2);
8424 end Float_Representation;
8430 -- pragma Ident (static_string_EXPRESSION)
8432 -- Note: pragma Comment shares this processing. Pragma Comment is
8433 -- identical to Ident, except that the restriction of the argument to
8434 -- 31 characters and the placement restrictions are not enforced for
8437 when Pragma_Ident | Pragma_Comment => Ident : declare
8442 Check_Arg_Count (1);
8443 Check_No_Identifiers;
8444 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8447 -- For pragma Ident, preserve DEC compatibility by requiring the
8448 -- pragma to appear in a declarative part or package spec.
8450 if Prag_Id = Pragma_Ident then
8451 Check_Is_In_Decl_Part_Or_Package_Spec;
8454 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8461 GP := Parent (Parent (N));
8463 if Nkind_In (GP, N_Package_Declaration,
8464 N_Generic_Package_Declaration)
8469 -- If we have a compilation unit, then record the ident value,
8470 -- checking for improper duplication.
8472 if Nkind (GP) = N_Compilation_Unit then
8473 CS := Ident_String (Current_Sem_Unit);
8475 if Present (CS) then
8477 -- For Ident, we do not permit multiple instances
8479 if Prag_Id = Pragma_Ident then
8480 Error_Pragma ("duplicate% pragma not permitted");
8482 -- For Comment, we concatenate the string, unless we want
8483 -- to preserve the tree structure for ASIS.
8485 elsif not ASIS_Mode then
8486 Start_String (Strval (CS));
8487 Store_String_Char (' ');
8488 Store_String_Chars (Strval (Str));
8489 Set_Strval (CS, End_String);
8493 -- In VMS, the effect of IDENT is achieved by passing
8494 -- --identification=name as a --for-linker switch.
8496 if OpenVMS_On_Target then
8499 ("--for-linker=--identification=");
8500 String_To_Name_Buffer (Strval (Str));
8501 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8503 -- Only the last processed IDENT is saved. The main
8504 -- purpose is so an IDENT associated with a main
8505 -- procedure will be used in preference to an IDENT
8506 -- associated with a with'd package.
8508 Replace_Linker_Option_String
8509 (End_String, "--for-linker=--identification=");
8512 Set_Ident_String (Current_Sem_Unit, Str);
8515 -- For subunits, we just ignore the Ident, since in GNAT these
8516 -- are not separate object files, and hence not separate units
8517 -- in the unit table.
8519 elsif Nkind (GP) = N_Subunit then
8522 -- Otherwise we have a misplaced pragma Ident, but we ignore
8523 -- this if we are in an instantiation, since it comes from
8524 -- a generic, and has no relevance to the instantiation.
8526 elsif Prag_Id = Pragma_Ident then
8527 if Instantiation_Location (Loc) = No_Location then
8528 Error_Pragma ("pragma% only allowed at outer level");
8538 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8539 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8541 when Pragma_Implemented => Implemented : declare
8542 Proc_Id : Entity_Id;
8547 Check_Arg_Count (2);
8548 Check_No_Identifiers;
8549 Check_Arg_Is_Identifier (Arg1);
8550 Check_Arg_Is_Local_Name (Arg1);
8552 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8554 -- Extract the name of the local procedure
8556 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8558 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8559 -- primitive procedure of a synchronized tagged type.
8561 if Ekind (Proc_Id) = E_Procedure
8562 and then Is_Primitive (Proc_Id)
8563 and then Present (First_Formal (Proc_Id))
8565 Typ := Etype (First_Formal (Proc_Id));
8567 if Is_Tagged_Type (Typ)
8570 -- Check for a protected, a synchronized or a task interface
8572 ((Is_Interface (Typ)
8573 and then Is_Synchronized_Interface (Typ))
8575 -- Check for a protected type or a task type that implements
8579 (Is_Concurrent_Record_Type (Typ)
8580 and then Present (Interfaces (Typ)))
8582 -- Check for a private record extension with keyword
8586 (Ekind_In (Typ, E_Record_Type_With_Private,
8587 E_Record_Subtype_With_Private)
8588 and then Synchronized_Present (Parent (Typ))))
8593 ("controlling formal must be of synchronized " &
8594 "tagged type", Arg1);
8598 -- Procedures declared inside a protected type must be accepted
8600 elsif Ekind (Proc_Id) = E_Procedure
8601 and then Is_Protected_Type (Scope (Proc_Id))
8605 -- The first argument is not a primitive procedure
8609 ("pragma % must be applied to a primitive procedure", Arg1);
8613 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8614 -- By_Protected_Procedure to the primitive procedure of a task
8617 if Chars (Arg2) = Name_By_Protected_Procedure
8618 and then Is_Interface (Typ)
8619 and then Is_Task_Interface (Typ)
8622 ("implementation kind By_Protected_Procedure cannot be " &
8623 "applied to a task interface primitive", Arg2);
8627 Record_Rep_Item (Proc_Id, N);
8630 ----------------------
8631 -- Implicit_Packing --
8632 ----------------------
8634 -- pragma Implicit_Packing;
8636 when Pragma_Implicit_Packing =>
8638 Check_Arg_Count (0);
8639 Implicit_Packing := True;
8646 -- [Convention =>] convention_IDENTIFIER,
8647 -- [Entity =>] local_NAME
8648 -- [, [External_Name =>] static_string_EXPRESSION ]
8649 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8651 when Pragma_Import =>
8652 Check_Ada_83_Warning;
8658 Check_At_Least_N_Arguments (2);
8659 Check_At_Most_N_Arguments (4);
8660 Process_Import_Or_Interface;
8662 ----------------------
8663 -- Import_Exception --
8664 ----------------------
8666 -- pragma Import_Exception (
8667 -- [Internal =>] LOCAL_NAME
8668 -- [, [External =>] EXTERNAL_SYMBOL]
8669 -- [, [Form =>] Ada | VMS]
8670 -- [, [Code =>] static_integer_EXPRESSION]);
8672 when Pragma_Import_Exception => Import_Exception : declare
8673 Args : Args_List (1 .. 4);
8674 Names : constant Name_List (1 .. 4) := (
8680 Internal : Node_Id renames Args (1);
8681 External : Node_Id renames Args (2);
8682 Form : Node_Id renames Args (3);
8683 Code : Node_Id renames Args (4);
8687 Gather_Associations (Names, Args);
8689 if Present (External) and then Present (Code) then
8691 ("cannot give both External and Code options for pragma%");
8694 Process_Extended_Import_Export_Exception_Pragma (
8695 Arg_Internal => Internal,
8696 Arg_External => External,
8700 if not Is_VMS_Exception (Entity (Internal)) then
8701 Set_Imported (Entity (Internal));
8703 end Import_Exception;
8705 ---------------------
8706 -- Import_Function --
8707 ---------------------
8709 -- pragma Import_Function (
8710 -- [Internal =>] LOCAL_NAME,
8711 -- [, [External =>] EXTERNAL_SYMBOL]
8712 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8713 -- [, [Result_Type =>] SUBTYPE_MARK]
8714 -- [, [Mechanism =>] MECHANISM]
8715 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8716 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8718 -- EXTERNAL_SYMBOL ::=
8720 -- | static_string_EXPRESSION
8722 -- PARAMETER_TYPES ::=
8724 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8726 -- TYPE_DESIGNATOR ::=
8728 -- | subtype_Name ' Access
8732 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8734 -- MECHANISM_ASSOCIATION ::=
8735 -- [formal_parameter_NAME =>] MECHANISM_NAME
8737 -- MECHANISM_NAME ::=
8740 -- | Descriptor [([Class =>] CLASS_NAME)]
8742 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8744 when Pragma_Import_Function => Import_Function : declare
8745 Args : Args_List (1 .. 7);
8746 Names : constant Name_List (1 .. 7) := (
8749 Name_Parameter_Types,
8752 Name_Result_Mechanism,
8753 Name_First_Optional_Parameter);
8755 Internal : Node_Id renames Args (1);
8756 External : Node_Id renames Args (2);
8757 Parameter_Types : Node_Id renames Args (3);
8758 Result_Type : Node_Id renames Args (4);
8759 Mechanism : Node_Id renames Args (5);
8760 Result_Mechanism : Node_Id renames Args (6);
8761 First_Optional_Parameter : Node_Id renames Args (7);
8765 Gather_Associations (Names, Args);
8766 Process_Extended_Import_Export_Subprogram_Pragma (
8767 Arg_Internal => Internal,
8768 Arg_External => External,
8769 Arg_Parameter_Types => Parameter_Types,
8770 Arg_Result_Type => Result_Type,
8771 Arg_Mechanism => Mechanism,
8772 Arg_Result_Mechanism => Result_Mechanism,
8773 Arg_First_Optional_Parameter => First_Optional_Parameter);
8774 end Import_Function;
8780 -- pragma Import_Object (
8781 -- [Internal =>] LOCAL_NAME
8782 -- [, [External =>] EXTERNAL_SYMBOL]
8783 -- [, [Size =>] EXTERNAL_SYMBOL]);
8785 -- EXTERNAL_SYMBOL ::=
8787 -- | static_string_EXPRESSION
8789 when Pragma_Import_Object => Import_Object : declare
8790 Args : Args_List (1 .. 3);
8791 Names : constant Name_List (1 .. 3) := (
8796 Internal : Node_Id renames Args (1);
8797 External : Node_Id renames Args (2);
8798 Size : Node_Id renames Args (3);
8802 Gather_Associations (Names, Args);
8803 Process_Extended_Import_Export_Object_Pragma (
8804 Arg_Internal => Internal,
8805 Arg_External => External,
8809 ----------------------
8810 -- Import_Procedure --
8811 ----------------------
8813 -- pragma Import_Procedure (
8814 -- [Internal =>] LOCAL_NAME
8815 -- [, [External =>] EXTERNAL_SYMBOL]
8816 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8817 -- [, [Mechanism =>] MECHANISM]
8818 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8820 -- EXTERNAL_SYMBOL ::=
8822 -- | static_string_EXPRESSION
8824 -- PARAMETER_TYPES ::=
8826 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8828 -- TYPE_DESIGNATOR ::=
8830 -- | subtype_Name ' Access
8834 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8836 -- MECHANISM_ASSOCIATION ::=
8837 -- [formal_parameter_NAME =>] MECHANISM_NAME
8839 -- MECHANISM_NAME ::=
8842 -- | Descriptor [([Class =>] CLASS_NAME)]
8844 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8846 when Pragma_Import_Procedure => Import_Procedure : declare
8847 Args : Args_List (1 .. 5);
8848 Names : constant Name_List (1 .. 5) := (
8851 Name_Parameter_Types,
8853 Name_First_Optional_Parameter);
8855 Internal : Node_Id renames Args (1);
8856 External : Node_Id renames Args (2);
8857 Parameter_Types : Node_Id renames Args (3);
8858 Mechanism : Node_Id renames Args (4);
8859 First_Optional_Parameter : Node_Id renames Args (5);
8863 Gather_Associations (Names, Args);
8864 Process_Extended_Import_Export_Subprogram_Pragma (
8865 Arg_Internal => Internal,
8866 Arg_External => External,
8867 Arg_Parameter_Types => Parameter_Types,
8868 Arg_Mechanism => Mechanism,
8869 Arg_First_Optional_Parameter => First_Optional_Parameter);
8870 end Import_Procedure;
8872 -----------------------------
8873 -- Import_Valued_Procedure --
8874 -----------------------------
8876 -- pragma Import_Valued_Procedure (
8877 -- [Internal =>] LOCAL_NAME
8878 -- [, [External =>] EXTERNAL_SYMBOL]
8879 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8880 -- [, [Mechanism =>] MECHANISM]
8881 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8883 -- EXTERNAL_SYMBOL ::=
8885 -- | static_string_EXPRESSION
8887 -- PARAMETER_TYPES ::=
8889 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8891 -- TYPE_DESIGNATOR ::=
8893 -- | subtype_Name ' Access
8897 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8899 -- MECHANISM_ASSOCIATION ::=
8900 -- [formal_parameter_NAME =>] MECHANISM_NAME
8902 -- MECHANISM_NAME ::=
8905 -- | Descriptor [([Class =>] CLASS_NAME)]
8907 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8909 when Pragma_Import_Valued_Procedure =>
8910 Import_Valued_Procedure : declare
8911 Args : Args_List (1 .. 5);
8912 Names : constant Name_List (1 .. 5) := (
8915 Name_Parameter_Types,
8917 Name_First_Optional_Parameter);
8919 Internal : Node_Id renames Args (1);
8920 External : Node_Id renames Args (2);
8921 Parameter_Types : Node_Id renames Args (3);
8922 Mechanism : Node_Id renames Args (4);
8923 First_Optional_Parameter : Node_Id renames Args (5);
8927 Gather_Associations (Names, Args);
8928 Process_Extended_Import_Export_Subprogram_Pragma (
8929 Arg_Internal => Internal,
8930 Arg_External => External,
8931 Arg_Parameter_Types => Parameter_Types,
8932 Arg_Mechanism => Mechanism,
8933 Arg_First_Optional_Parameter => First_Optional_Parameter);
8934 end Import_Valued_Procedure;
8940 -- pragma Independent (LOCAL_NAME);
8942 when Pragma_Independent => Independent : declare
8949 Check_Ada_83_Warning;
8951 Check_No_Identifiers;
8952 Check_Arg_Count (1);
8953 Check_Arg_Is_Local_Name (Arg1);
8954 E_Id := Get_Pragma_Arg (Arg1);
8956 if Etype (E_Id) = Any_Type then
8961 D := Declaration_Node (E);
8964 -- Check duplicate before we chain ourselves!
8966 Check_Duplicate_Pragma (E);
8968 -- Check appropriate entity
8971 if Rep_Item_Too_Early (E, N)
8973 Rep_Item_Too_Late (E, N)
8977 Check_First_Subtype (Arg1);
8980 elsif K = N_Object_Declaration
8981 or else (K = N_Component_Declaration
8982 and then Original_Record_Component (E) = E)
8984 if Rep_Item_Too_Late (E, N) then
8990 ("inappropriate entity for pragma%", Arg1);
8993 Independence_Checks.Append ((N, E));
8996 ----------------------------
8997 -- Independent_Components --
8998 ----------------------------
9000 -- pragma Atomic_Components (array_LOCAL_NAME);
9002 -- This processing is shared by Volatile_Components
9004 when Pragma_Independent_Components => Independent_Components : declare
9011 Check_Ada_83_Warning;
9013 Check_No_Identifiers;
9014 Check_Arg_Count (1);
9015 Check_Arg_Is_Local_Name (Arg1);
9016 E_Id := Get_Pragma_Arg (Arg1);
9018 if Etype (E_Id) = Any_Type then
9024 -- Check duplicate before we chain ourselves!
9026 Check_Duplicate_Pragma (E);
9028 -- Check appropriate entity
9030 if Rep_Item_Too_Early (E, N)
9032 Rep_Item_Too_Late (E, N)
9037 D := Declaration_Node (E);
9040 if (K = N_Full_Type_Declaration
9041 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9043 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9044 and then Nkind (D) = N_Object_Declaration
9045 and then Nkind (Object_Definition (D)) =
9046 N_Constrained_Array_Definition)
9048 Independence_Checks.Append ((N, E));
9051 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9053 end Independent_Components;
9055 ------------------------
9056 -- Initialize_Scalars --
9057 ------------------------
9059 -- pragma Initialize_Scalars;
9061 when Pragma_Initialize_Scalars =>
9063 Check_Arg_Count (0);
9064 Check_Valid_Configuration_Pragma;
9065 Check_Restriction (No_Initialize_Scalars, N);
9067 -- Initialize_Scalars creates false positives in CodePeer,
9068 -- so ignore this pragma in this mode.
9070 if not Restriction_Active (No_Initialize_Scalars)
9071 and then not CodePeer_Mode
9073 Init_Or_Norm_Scalars := True;
9074 Initialize_Scalars := True;
9081 -- pragma Inline ( NAME {, NAME} );
9083 when Pragma_Inline =>
9085 -- Pragma is active if inlining option is active
9087 Process_Inline (Inline_Active);
9093 -- pragma Inline_Always ( NAME {, NAME} );
9095 when Pragma_Inline_Always =>
9098 -- Pragma always active unless in CodePeer mode, since this causes
9099 -- walk order issues.
9101 if not CodePeer_Mode then
9102 Process_Inline (True);
9105 --------------------
9106 -- Inline_Generic --
9107 --------------------
9109 -- pragma Inline_Generic (NAME {, NAME});
9111 when Pragma_Inline_Generic =>
9113 Process_Generic_List;
9115 ----------------------
9116 -- Inspection_Point --
9117 ----------------------
9119 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9121 when Pragma_Inspection_Point => Inspection_Point : declare
9126 if Arg_Count > 0 then
9129 Exp := Get_Pragma_Arg (Arg);
9132 if not Is_Entity_Name (Exp)
9133 or else not Is_Object (Entity (Exp))
9135 Error_Pragma_Arg ("object name required", Arg);
9142 end Inspection_Point;
9148 -- pragma Interface (
9149 -- [ Convention =>] convention_IDENTIFIER,
9150 -- [ Entity =>] local_NAME
9151 -- [, [External_Name =>] static_string_EXPRESSION ]
9152 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9154 when Pragma_Interface =>
9161 Check_At_Least_N_Arguments (2);
9162 Check_At_Most_N_Arguments (4);
9163 Process_Import_Or_Interface;
9165 -- In Ada 2005, the permission to use Interface (a reserved word)
9166 -- as a pragma name is considered an obsolescent feature.
9168 if Ada_Version >= Ada_2005 then
9170 (No_Obsolescent_Features, Pragma_Identifier (N));
9173 --------------------
9174 -- Interface_Name --
9175 --------------------
9177 -- pragma Interface_Name (
9178 -- [ Entity =>] local_NAME
9179 -- [,[External_Name =>] static_string_EXPRESSION ]
9180 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9182 when Pragma_Interface_Name => Interface_Name : declare
9191 ((Name_Entity, Name_External_Name, Name_Link_Name));
9192 Check_At_Least_N_Arguments (2);
9193 Check_At_Most_N_Arguments (3);
9194 Id := Get_Pragma_Arg (Arg1);
9197 if not Is_Entity_Name (Id) then
9199 ("first argument for pragma% must be entity name", Arg1);
9200 elsif Etype (Id) = Any_Type then
9203 Def_Id := Entity (Id);
9206 -- Special DEC-compatible processing for the object case, forces
9207 -- object to be imported.
9209 if Ekind (Def_Id) = E_Variable then
9210 Kill_Size_Check_Code (Def_Id);
9211 Note_Possible_Modification (Id, Sure => False);
9213 -- Initialization is not allowed for imported variable
9215 if Present (Expression (Parent (Def_Id)))
9216 and then Comes_From_Source (Expression (Parent (Def_Id)))
9218 Error_Msg_Sloc := Sloc (Def_Id);
9220 ("no initialization allowed for declaration of& #",
9224 -- For compatibility, support VADS usage of providing both
9225 -- pragmas Interface and Interface_Name to obtain the effect
9226 -- of a single Import pragma.
9228 if Is_Imported (Def_Id)
9229 and then Present (First_Rep_Item (Def_Id))
9230 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9232 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9236 Set_Imported (Def_Id);
9239 Set_Is_Public (Def_Id);
9240 Process_Interface_Name (Def_Id, Arg2, Arg3);
9243 -- Otherwise must be subprogram
9245 elsif not Is_Subprogram (Def_Id) then
9247 ("argument of pragma% is not subprogram", Arg1);
9250 Check_At_Most_N_Arguments (3);
9254 -- Loop through homonyms
9257 Def_Id := Get_Base_Subprogram (Hom_Id);
9259 if Is_Imported (Def_Id) then
9260 Process_Interface_Name (Def_Id, Arg2, Arg3);
9264 exit when From_Aspect_Specification (N);
9265 Hom_Id := Homonym (Hom_Id);
9267 exit when No (Hom_Id)
9268 or else Scope (Hom_Id) /= Current_Scope;
9273 ("argument of pragma% is not imported subprogram",
9279 -----------------------
9280 -- Interrupt_Handler --
9281 -----------------------
9283 -- pragma Interrupt_Handler (handler_NAME);
9285 when Pragma_Interrupt_Handler =>
9286 Check_Ada_83_Warning;
9287 Check_Arg_Count (1);
9288 Check_No_Identifiers;
9290 if No_Run_Time_Mode then
9291 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9293 Check_Interrupt_Or_Attach_Handler;
9294 Process_Interrupt_Or_Attach_Handler;
9297 ------------------------
9298 -- Interrupt_Priority --
9299 ------------------------
9301 -- pragma Interrupt_Priority [(EXPRESSION)];
9303 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9304 P : constant Node_Id := Parent (N);
9308 Check_Ada_83_Warning;
9310 if Arg_Count /= 0 then
9311 Arg := Get_Pragma_Arg (Arg1);
9312 Check_Arg_Count (1);
9313 Check_No_Identifiers;
9315 -- The expression must be analyzed in the special manner
9316 -- described in "Handling of Default and Per-Object
9317 -- Expressions" in sem.ads.
9319 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9322 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9326 elsif Has_Pragma_Priority (P) then
9327 Error_Pragma ("duplicate pragma% not allowed");
9330 Set_Has_Pragma_Priority (P, True);
9331 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9333 end Interrupt_Priority;
9335 ---------------------
9336 -- Interrupt_State --
9337 ---------------------
9339 -- pragma Interrupt_State (
9340 -- [Name =>] INTERRUPT_ID,
9341 -- [State =>] INTERRUPT_STATE);
9343 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9344 -- INTERRUPT_STATE => System | Runtime | User
9346 -- Note: if the interrupt id is given as an identifier, then it must
9347 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9348 -- given as a static integer expression which must be in the range of
9349 -- Ada.Interrupts.Interrupt_ID.
9351 when Pragma_Interrupt_State => Interrupt_State : declare
9353 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9354 -- This is the entity Ada.Interrupts.Interrupt_ID;
9356 State_Type : Character;
9357 -- Set to 's'/'r'/'u' for System/Runtime/User
9360 -- Index to entry in Interrupt_States table
9363 -- Value of interrupt
9365 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9366 -- The first argument to the pragma
9368 Int_Ent : Entity_Id;
9369 -- Interrupt entity in Ada.Interrupts.Names
9373 Check_Arg_Order ((Name_Name, Name_State));
9374 Check_Arg_Count (2);
9376 Check_Optional_Identifier (Arg1, Name_Name);
9377 Check_Optional_Identifier (Arg2, Name_State);
9378 Check_Arg_Is_Identifier (Arg2);
9380 -- First argument is identifier
9382 if Nkind (Arg1X) = N_Identifier then
9384 -- Search list of names in Ada.Interrupts.Names
9386 Int_Ent := First_Entity (RTE (RE_Names));
9388 if No (Int_Ent) then
9389 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9391 elsif Chars (Int_Ent) = Chars (Arg1X) then
9392 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9396 Next_Entity (Int_Ent);
9399 -- First argument is not an identifier, so it must be a static
9400 -- expression of type Ada.Interrupts.Interrupt_ID.
9403 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9404 Int_Val := Expr_Value (Arg1X);
9406 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9408 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9411 ("value not in range of type " &
9412 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9418 case Chars (Get_Pragma_Arg (Arg2)) is
9419 when Name_Runtime => State_Type := 'r';
9420 when Name_System => State_Type := 's';
9421 when Name_User => State_Type := 'u';
9424 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9427 -- Check if entry is already stored
9429 IST_Num := Interrupt_States.First;
9431 -- If entry not found, add it
9433 if IST_Num > Interrupt_States.Last then
9434 Interrupt_States.Append
9435 ((Interrupt_Number => UI_To_Int (Int_Val),
9436 Interrupt_State => State_Type,
9437 Pragma_Loc => Loc));
9440 -- Case of entry for the same entry
9442 elsif Int_Val = Interrupt_States.Table (IST_Num).
9445 -- If state matches, done, no need to make redundant entry
9448 State_Type = Interrupt_States.Table (IST_Num).
9451 -- Otherwise if state does not match, error
9454 Interrupt_States.Table (IST_Num).Pragma_Loc;
9456 ("state conflicts with that given #", Arg2);
9460 IST_Num := IST_Num + 1;
9462 end Interrupt_State;
9469 -- ([Entity =>] type_LOCAL_NAME,
9470 -- [Check =>] EXPRESSION
9471 -- [,[Message =>] String_Expression]);
9473 when Pragma_Invariant => Invariant : declare
9478 pragma Unreferenced (Discard);
9482 Check_At_Least_N_Arguments (2);
9483 Check_At_Most_N_Arguments (3);
9484 Check_Optional_Identifier (Arg1, Name_Entity);
9485 Check_Optional_Identifier (Arg2, Name_Check);
9487 if Arg_Count = 3 then
9488 Check_Optional_Identifier (Arg3, Name_Message);
9489 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9492 Check_Arg_Is_Local_Name (Arg1);
9494 Type_Id := Get_Pragma_Arg (Arg1);
9495 Find_Type (Type_Id);
9496 Typ := Entity (Type_Id);
9498 if Typ = Any_Type then
9501 elsif not Ekind_In (Typ, E_Private_Type,
9502 E_Record_Type_With_Private,
9503 E_Limited_Private_Type)
9506 ("pragma% only allowed for private type", Arg1);
9509 -- Note that the type has at least one invariant, and also that
9510 -- it has inheritable invariants if we have Invariant'Class.
9512 Set_Has_Invariants (Typ);
9514 if Class_Present (N) then
9515 Set_Has_Inheritable_Invariants (Typ);
9518 -- The remaining processing is simply to link the pragma on to
9519 -- the rep item chain, for processing when the type is frozen.
9520 -- This is accomplished by a call to Rep_Item_Too_Late.
9522 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9525 ----------------------
9526 -- Java_Constructor --
9527 ----------------------
9529 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9531 -- Also handles pragma CIL_Constructor
9533 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9534 Java_Constructor : declare
9535 Convention : Convention_Id;
9539 This_Formal : Entity_Id;
9543 Check_Arg_Count (1);
9544 Check_Optional_Identifier (Arg1, Name_Entity);
9545 Check_Arg_Is_Local_Name (Arg1);
9547 Id := Get_Pragma_Arg (Arg1);
9548 Find_Program_Unit_Name (Id);
9550 -- If we did not find the name, we are done
9552 if Etype (Id) = Any_Type then
9556 -- Check wrong use of pragma in wrong VM target
9558 if VM_Target = No_VM then
9561 elsif VM_Target = CLI_Target
9562 and then Prag_Id = Pragma_Java_Constructor
9564 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9566 elsif VM_Target = JVM_Target
9567 and then Prag_Id = Pragma_CIL_Constructor
9569 Error_Pragma ("must use pragma 'Java_'Constructor");
9573 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9574 when Pragma_Java_Constructor => Convention := Convention_Java;
9575 when others => null;
9578 Hom_Id := Entity (Id);
9580 -- Loop through homonyms
9583 Def_Id := Get_Base_Subprogram (Hom_Id);
9585 -- The constructor is required to be a function
9587 if Ekind (Def_Id) /= E_Function then
9588 if VM_Target = JVM_Target then
9590 ("pragma% requires function returning a " &
9591 "'Java access type", Def_Id);
9594 ("pragma% requires function returning a " &
9595 "'C'I'L access type", Def_Id);
9599 -- Check arguments: For tagged type the first formal must be
9600 -- named "this" and its type must be a named access type
9601 -- designating a class-wide tagged type that has convention
9602 -- CIL/Java. The first formal must also have a null default
9603 -- value. For example:
9605 -- type Typ is tagged ...
9606 -- type Ref is access all Typ;
9607 -- pragma Convention (CIL, Typ);
9609 -- function New_Typ (This : Ref) return Ref;
9610 -- function New_Typ (This : Ref; I : Integer) return Ref;
9611 -- pragma Cil_Constructor (New_Typ);
9613 -- Reason: The first formal must NOT be a primitive of the
9616 -- This rule also applies to constructors of delegates used
9617 -- to interface with standard target libraries. For example:
9619 -- type Delegate is access procedure ...
9620 -- pragma Import (CIL, Delegate, ...);
9622 -- function new_Delegate
9623 -- (This : Delegate := null; ... ) return Delegate;
9625 -- For value-types this rule does not apply.
9627 if not Is_Value_Type (Etype (Def_Id)) then
9628 if No (First_Formal (Def_Id)) then
9629 Error_Msg_Name_1 := Pname;
9630 Error_Msg_N ("% function must have parameters", Def_Id);
9634 -- In the JRE library we have several occurrences in which
9635 -- the "this" parameter is not the first formal.
9637 This_Formal := First_Formal (Def_Id);
9639 -- In the JRE library we have several occurrences in which
9640 -- the "this" parameter is not the first formal. Search for
9643 if VM_Target = JVM_Target then
9644 while Present (This_Formal)
9645 and then Get_Name_String (Chars (This_Formal)) /= "this"
9647 Next_Formal (This_Formal);
9650 if No (This_Formal) then
9651 This_Formal := First_Formal (Def_Id);
9655 -- Warning: The first parameter should be named "this".
9656 -- We temporarily allow it because we have the following
9657 -- case in the Java runtime (file s-osinte.ads) ???
9659 -- function new_Thread
9660 -- (Self_Id : System.Address) return Thread_Id;
9661 -- pragma Java_Constructor (new_Thread);
9663 if VM_Target = JVM_Target
9664 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9666 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9670 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9671 Error_Msg_Name_1 := Pname;
9673 ("first formal of % function must be named `this`",
9674 Parent (This_Formal));
9676 elsif not Is_Access_Type (Etype (This_Formal)) then
9677 Error_Msg_Name_1 := Pname;
9679 ("first formal of % function must be an access type",
9680 Parameter_Type (Parent (This_Formal)));
9682 -- For delegates the type of the first formal must be a
9683 -- named access-to-subprogram type (see previous example)
9685 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9686 and then Ekind (Etype (This_Formal))
9687 /= E_Access_Subprogram_Type
9689 Error_Msg_Name_1 := Pname;
9691 ("first formal of % function must be a named access" &
9692 " to subprogram type",
9693 Parameter_Type (Parent (This_Formal)));
9695 -- Warning: We should reject anonymous access types because
9696 -- the constructor must not be handled as a primitive of the
9697 -- tagged type. We temporarily allow it because this profile
9698 -- is currently generated by cil2ada???
9700 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9701 and then not Ekind_In (Etype (This_Formal),
9703 E_General_Access_Type,
9704 E_Anonymous_Access_Type)
9706 Error_Msg_Name_1 := Pname;
9708 ("first formal of % function must be a named access" &
9710 Parameter_Type (Parent (This_Formal)));
9712 elsif Atree.Convention
9713 (Designated_Type (Etype (This_Formal))) /= Convention
9715 Error_Msg_Name_1 := Pname;
9717 if Convention = Convention_Java then
9719 ("pragma% requires convention 'Cil in designated" &
9721 Parameter_Type (Parent (This_Formal)));
9724 ("pragma% requires convention 'Java in designated" &
9726 Parameter_Type (Parent (This_Formal)));
9729 elsif No (Expression (Parent (This_Formal)))
9730 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9732 Error_Msg_Name_1 := Pname;
9734 ("pragma% requires first formal with default `null`",
9735 Parameter_Type (Parent (This_Formal)));
9739 -- Check result type: the constructor must be a function
9741 -- * a value type (only allowed in the CIL compiler)
9742 -- * an access-to-subprogram type with convention Java/CIL
9743 -- * an access-type designating a type that has convention
9746 if Is_Value_Type (Etype (Def_Id)) then
9749 -- Access-to-subprogram type with convention Java/CIL
9751 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9752 if Atree.Convention (Etype (Def_Id)) /= Convention then
9753 if Convention = Convention_Java then
9755 ("pragma% requires function returning a " &
9756 "'Java access type", Arg1);
9758 pragma Assert (Convention = Convention_CIL);
9760 ("pragma% requires function returning a " &
9761 "'C'I'L access type", Arg1);
9765 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9766 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9767 E_General_Access_Type)
9770 (Designated_Type (Etype (Def_Id))) /= Convention
9772 Error_Msg_Name_1 := Pname;
9774 if Convention = Convention_Java then
9776 ("pragma% requires function returning a named" &
9777 "'Java access type", Arg1);
9780 ("pragma% requires function returning a named" &
9781 "'C'I'L access type", Arg1);
9786 Set_Is_Constructor (Def_Id);
9787 Set_Convention (Def_Id, Convention);
9788 Set_Is_Imported (Def_Id);
9790 exit when From_Aspect_Specification (N);
9791 Hom_Id := Homonym (Hom_Id);
9793 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9795 end Java_Constructor;
9797 ----------------------
9798 -- Java_Interface --
9799 ----------------------
9801 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9803 when Pragma_Java_Interface => Java_Interface : declare
9809 Check_Arg_Count (1);
9810 Check_Optional_Identifier (Arg1, Name_Entity);
9811 Check_Arg_Is_Local_Name (Arg1);
9813 Arg := Get_Pragma_Arg (Arg1);
9816 if Etype (Arg) = Any_Type then
9820 if not Is_Entity_Name (Arg)
9821 or else not Is_Type (Entity (Arg))
9823 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9826 Typ := Underlying_Type (Entity (Arg));
9828 -- For now simply check some of the semantic constraints on the
9829 -- type. This currently leaves out some restrictions on interface
9830 -- types, namely that the parent type must be java.lang.Object.Typ
9831 -- and that all primitives of the type should be declared
9834 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9835 Error_Pragma_Arg ("pragma% requires an abstract "
9836 & "tagged type", Arg1);
9838 elsif not Has_Discriminants (Typ)
9839 or else Ekind (Etype (First_Discriminant (Typ)))
9840 /= E_Anonymous_Access_Type
9842 not Is_Class_Wide_Type
9843 (Designated_Type (Etype (First_Discriminant (Typ))))
9846 ("type must have a class-wide access discriminant", Arg1);
9854 -- pragma Keep_Names ([On => ] local_NAME);
9856 when Pragma_Keep_Names => Keep_Names : declare
9861 Check_Arg_Count (1);
9862 Check_Optional_Identifier (Arg1, Name_On);
9863 Check_Arg_Is_Local_Name (Arg1);
9865 Arg := Get_Pragma_Arg (Arg1);
9868 if Etype (Arg) = Any_Type then
9872 if not Is_Entity_Name (Arg)
9873 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
9876 ("pragma% requires a local enumeration type", Arg1);
9879 Set_Discard_Names (Entity (Arg), False);
9886 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
9888 when Pragma_License =>
9890 Check_Arg_Count (1);
9891 Check_No_Identifiers;
9892 Check_Valid_Configuration_Pragma;
9893 Check_Arg_Is_Identifier (Arg1);
9896 Sind : constant Source_File_Index :=
9897 Source_Index (Current_Sem_Unit);
9900 case Chars (Get_Pragma_Arg (Arg1)) is
9902 Set_License (Sind, GPL);
9904 when Name_Modified_GPL =>
9905 Set_License (Sind, Modified_GPL);
9907 when Name_Restricted =>
9908 Set_License (Sind, Restricted);
9910 when Name_Unrestricted =>
9911 Set_License (Sind, Unrestricted);
9914 Error_Pragma_Arg ("invalid license name", Arg1);
9922 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
9924 when Pragma_Link_With => Link_With : declare
9930 if Operating_Mode = Generate_Code
9931 and then In_Extended_Main_Source_Unit (N)
9933 Check_At_Least_N_Arguments (1);
9934 Check_No_Identifiers;
9935 Check_Is_In_Decl_Part_Or_Package_Spec;
9936 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9940 while Present (Arg) loop
9941 Check_Arg_Is_Static_Expression (Arg, Standard_String);
9943 -- Store argument, converting sequences of spaces to a
9944 -- single null character (this is one of the differences
9945 -- in processing between Link_With and Linker_Options).
9948 C : constant Char_Code := Get_Char_Code (' ');
9949 S : constant String_Id :=
9950 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
9951 L : constant Nat := String_Length (S);
9954 procedure Skip_Spaces;
9955 -- Advance F past any spaces
9961 procedure Skip_Spaces is
9963 while F <= L and then Get_String_Char (S, F) = C loop
9968 -- Start of processing for Arg_Store
9971 Skip_Spaces; -- skip leading spaces
9973 -- Loop through characters, changing any embedded
9974 -- sequence of spaces to a single null character (this
9975 -- is how Link_With/Linker_Options differ)
9978 if Get_String_Char (S, F) = C then
9981 Store_String_Char (ASCII.NUL);
9984 Store_String_Char (Get_String_Char (S, F));
9992 if Present (Arg) then
9993 Store_String_Char (ASCII.NUL);
9997 Store_Linker_Option_String (End_String);
10005 -- pragma Linker_Alias (
10006 -- [Entity =>] LOCAL_NAME
10007 -- [Target =>] static_string_EXPRESSION);
10009 when Pragma_Linker_Alias =>
10011 Check_Arg_Order ((Name_Entity, Name_Target));
10012 Check_Arg_Count (2);
10013 Check_Optional_Identifier (Arg1, Name_Entity);
10014 Check_Optional_Identifier (Arg2, Name_Target);
10015 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10016 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10018 -- The only processing required is to link this item on to the
10019 -- list of rep items for the given entity. This is accomplished
10020 -- by the call to Rep_Item_Too_Late (when no error is detected
10021 -- and False is returned).
10023 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10026 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10029 ------------------------
10030 -- Linker_Constructor --
10031 ------------------------
10033 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10035 -- Code is shared with Linker_Destructor
10037 -----------------------
10038 -- Linker_Destructor --
10039 -----------------------
10041 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10043 when Pragma_Linker_Constructor |
10044 Pragma_Linker_Destructor =>
10045 Linker_Constructor : declare
10051 Check_Arg_Count (1);
10052 Check_No_Identifiers;
10053 Check_Arg_Is_Local_Name (Arg1);
10054 Arg1_X := Get_Pragma_Arg (Arg1);
10056 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10058 if not Is_Library_Level_Entity (Proc) then
10060 ("argument for pragma% must be library level entity", Arg1);
10063 -- The only processing required is to link this item on to the
10064 -- list of rep items for the given entity. This is accomplished
10065 -- by the call to Rep_Item_Too_Late (when no error is detected
10066 -- and False is returned).
10068 if Rep_Item_Too_Late (Proc, N) then
10071 Set_Has_Gigi_Rep_Item (Proc);
10073 end Linker_Constructor;
10075 --------------------
10076 -- Linker_Options --
10077 --------------------
10079 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10081 when Pragma_Linker_Options => Linker_Options : declare
10085 Check_Ada_83_Warning;
10086 Check_No_Identifiers;
10087 Check_Arg_Count (1);
10088 Check_Is_In_Decl_Part_Or_Package_Spec;
10089 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10090 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10093 while Present (Arg) loop
10094 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10095 Store_String_Char (ASCII.NUL);
10097 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10101 if Operating_Mode = Generate_Code
10102 and then In_Extended_Main_Source_Unit (N)
10104 Store_Linker_Option_String (End_String);
10106 end Linker_Options;
10108 --------------------
10109 -- Linker_Section --
10110 --------------------
10112 -- pragma Linker_Section (
10113 -- [Entity =>] LOCAL_NAME
10114 -- [Section =>] static_string_EXPRESSION);
10116 when Pragma_Linker_Section =>
10118 Check_Arg_Order ((Name_Entity, Name_Section));
10119 Check_Arg_Count (2);
10120 Check_Optional_Identifier (Arg1, Name_Entity);
10121 Check_Optional_Identifier (Arg2, Name_Section);
10122 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10123 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10125 -- This pragma applies only to objects
10127 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10128 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10131 -- The only processing required is to link this item on to the
10132 -- list of rep items for the given entity. This is accomplished
10133 -- by the call to Rep_Item_Too_Late (when no error is detected
10134 -- and False is returned).
10136 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10139 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10146 -- pragma List (On | Off)
10148 -- There is nothing to do here, since we did all the processing for
10149 -- this pragma in Par.Prag (so that it works properly even in syntax
10152 when Pragma_List =>
10155 --------------------
10156 -- Locking_Policy --
10157 --------------------
10159 -- pragma Locking_Policy (policy_IDENTIFIER);
10161 when Pragma_Locking_Policy => declare
10165 Check_Ada_83_Warning;
10166 Check_Arg_Count (1);
10167 Check_No_Identifiers;
10168 Check_Arg_Is_Locking_Policy (Arg1);
10169 Check_Valid_Configuration_Pragma;
10170 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10171 LP := Fold_Upper (Name_Buffer (1));
10173 if Locking_Policy /= ' '
10174 and then Locking_Policy /= LP
10176 Error_Msg_Sloc := Locking_Policy_Sloc;
10177 Error_Pragma ("locking policy incompatible with policy#");
10179 -- Set new policy, but always preserve System_Location since we
10180 -- like the error message with the run time name.
10183 Locking_Policy := LP;
10185 if Locking_Policy_Sloc /= System_Location then
10186 Locking_Policy_Sloc := Loc;
10195 -- pragma Long_Float (D_Float | G_Float);
10197 when Pragma_Long_Float =>
10199 Check_Valid_Configuration_Pragma;
10200 Check_Arg_Count (1);
10201 Check_No_Identifier (Arg1);
10202 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10204 if not OpenVMS_On_Target then
10205 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10210 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10211 if Opt.Float_Format_Long = 'G' then
10212 Error_Pragma ("G_Float previously specified");
10215 Opt.Float_Format_Long := 'D';
10217 -- G_Float case (this is the default, does not need overriding)
10220 if Opt.Float_Format_Long = 'D' then
10221 Error_Pragma ("D_Float previously specified");
10224 Opt.Float_Format_Long := 'G';
10227 Set_Standard_Fpt_Formats;
10229 -----------------------
10230 -- Machine_Attribute --
10231 -----------------------
10233 -- pragma Machine_Attribute (
10234 -- [Entity =>] LOCAL_NAME,
10235 -- [Attribute_Name =>] static_string_EXPRESSION
10236 -- [, [Info =>] static_EXPRESSION] );
10238 when Pragma_Machine_Attribute => Machine_Attribute : declare
10239 Def_Id : Entity_Id;
10243 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10245 if Arg_Count = 3 then
10246 Check_Optional_Identifier (Arg3, Name_Info);
10247 Check_Arg_Is_Static_Expression (Arg3);
10249 Check_Arg_Count (2);
10252 Check_Optional_Identifier (Arg1, Name_Entity);
10253 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10254 Check_Arg_Is_Local_Name (Arg1);
10255 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10256 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10258 if Is_Access_Type (Def_Id) then
10259 Def_Id := Designated_Type (Def_Id);
10262 if Rep_Item_Too_Early (Def_Id, N) then
10266 Def_Id := Underlying_Type (Def_Id);
10268 -- The only processing required is to link this item on to the
10269 -- list of rep items for the given entity. This is accomplished
10270 -- by the call to Rep_Item_Too_Late (when no error is detected
10271 -- and False is returned).
10273 if Rep_Item_Too_Late (Def_Id, N) then
10276 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10278 end Machine_Attribute;
10285 -- (MAIN_OPTION [, MAIN_OPTION]);
10288 -- [STACK_SIZE =>] static_integer_EXPRESSION
10289 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10290 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10292 when Pragma_Main => Main : declare
10293 Args : Args_List (1 .. 3);
10294 Names : constant Name_List (1 .. 3) := (
10296 Name_Task_Stack_Size_Default,
10297 Name_Time_Slicing_Enabled);
10303 Gather_Associations (Names, Args);
10305 for J in 1 .. 2 loop
10306 if Present (Args (J)) then
10307 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10311 if Present (Args (3)) then
10312 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10316 while Present (Nod) loop
10317 if Nkind (Nod) = N_Pragma
10318 and then Pragma_Name (Nod) = Name_Main
10320 Error_Msg_Name_1 := Pname;
10321 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10332 -- pragma Main_Storage
10333 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10335 -- MAIN_STORAGE_OPTION ::=
10336 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10337 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10339 when Pragma_Main_Storage => Main_Storage : declare
10340 Args : Args_List (1 .. 2);
10341 Names : constant Name_List (1 .. 2) := (
10342 Name_Working_Storage,
10349 Gather_Associations (Names, Args);
10351 for J in 1 .. 2 loop
10352 if Present (Args (J)) then
10353 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10357 Check_In_Main_Program;
10360 while Present (Nod) loop
10361 if Nkind (Nod) = N_Pragma
10362 and then Pragma_Name (Nod) = Name_Main_Storage
10364 Error_Msg_Name_1 := Pname;
10365 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10376 -- pragma Memory_Size (NUMERIC_LITERAL)
10378 when Pragma_Memory_Size =>
10381 -- Memory size is simply ignored
10383 Check_No_Identifiers;
10384 Check_Arg_Count (1);
10385 Check_Arg_Is_Integer_Literal (Arg1);
10393 -- The only correct use of this pragma is on its own in a file, in
10394 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10395 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10396 -- check for a file containing nothing but a No_Body pragma). If we
10397 -- attempt to process it during normal semantics processing, it means
10398 -- it was misplaced.
10400 when Pragma_No_Body =>
10408 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10410 when Pragma_No_Return => No_Return : declare
10418 Check_At_Least_N_Arguments (1);
10420 -- Loop through arguments of pragma
10423 while Present (Arg) loop
10424 Check_Arg_Is_Local_Name (Arg);
10425 Id := Get_Pragma_Arg (Arg);
10428 if not Is_Entity_Name (Id) then
10429 Error_Pragma_Arg ("entity name required", Arg);
10432 if Etype (Id) = Any_Type then
10436 -- Loop to find matching procedures
10441 and then Scope (E) = Current_Scope
10443 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10446 -- Set flag on any alias as well
10448 if Is_Overloadable (E) and then Present (Alias (E)) then
10449 Set_No_Return (Alias (E));
10455 exit when From_Aspect_Specification (N);
10460 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10471 -- pragma No_Run_Time;
10473 -- Note: this pragma is retained for backwards compatibility. See
10474 -- body of Rtsfind for full details on its handling.
10476 when Pragma_No_Run_Time =>
10478 Check_Valid_Configuration_Pragma;
10479 Check_Arg_Count (0);
10481 No_Run_Time_Mode := True;
10482 Configurable_Run_Time_Mode := True;
10484 -- Set Duration to 32 bits if word size is 32
10486 if Ttypes.System_Word_Size = 32 then
10487 Duration_32_Bits_On_Target := True;
10490 -- Set appropriate restrictions
10492 Set_Restriction (No_Finalization, N);
10493 Set_Restriction (No_Exception_Handlers, N);
10494 Set_Restriction (Max_Tasks, N, 0);
10495 Set_Restriction (No_Tasking, N);
10497 ------------------------
10498 -- No_Strict_Aliasing --
10499 ------------------------
10501 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10503 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10508 Check_At_Most_N_Arguments (1);
10510 if Arg_Count = 0 then
10511 Check_Valid_Configuration_Pragma;
10512 Opt.No_Strict_Aliasing := True;
10515 Check_Optional_Identifier (Arg2, Name_Entity);
10516 Check_Arg_Is_Local_Name (Arg1);
10517 E_Id := Entity (Get_Pragma_Arg (Arg1));
10519 if E_Id = Any_Type then
10521 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10522 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10525 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10527 end No_Strict_Aliasing;
10529 -----------------------
10530 -- Normalize_Scalars --
10531 -----------------------
10533 -- pragma Normalize_Scalars;
10535 when Pragma_Normalize_Scalars =>
10536 Check_Ada_83_Warning;
10537 Check_Arg_Count (0);
10538 Check_Valid_Configuration_Pragma;
10540 -- Normalize_Scalars creates false positives in CodePeer, so
10541 -- ignore this pragma in this mode.
10543 if not CodePeer_Mode then
10544 Normalize_Scalars := True;
10545 Init_Or_Norm_Scalars := True;
10552 -- pragma Obsolescent;
10554 -- pragma Obsolescent (
10555 -- [Message =>] static_string_EXPRESSION
10556 -- [,[Version =>] Ada_05]]);
10558 -- pragma Obsolescent (
10559 -- [Entity =>] NAME
10560 -- [,[Message =>] static_string_EXPRESSION
10561 -- [,[Version =>] Ada_05]] );
10563 when Pragma_Obsolescent => Obsolescent : declare
10567 procedure Set_Obsolescent (E : Entity_Id);
10568 -- Given an entity Ent, mark it as obsolescent if appropriate
10570 ---------------------
10571 -- Set_Obsolescent --
10572 ---------------------
10574 procedure Set_Obsolescent (E : Entity_Id) is
10583 -- Entity name was given
10585 if Present (Ename) then
10587 -- If entity name matches, we are fine. Save entity in
10588 -- pragma argument, for ASIS use.
10590 if Chars (Ename) = Chars (Ent) then
10591 Set_Entity (Ename, Ent);
10592 Generate_Reference (Ent, Ename);
10594 -- If entity name does not match, only possibility is an
10595 -- enumeration literal from an enumeration type declaration.
10597 elsif Ekind (Ent) /= E_Enumeration_Type then
10599 ("pragma % entity name does not match declaration");
10602 Ent := First_Literal (E);
10606 ("pragma % entity name does not match any " &
10607 "enumeration literal");
10609 elsif Chars (Ent) = Chars (Ename) then
10610 Set_Entity (Ename, Ent);
10611 Generate_Reference (Ent, Ename);
10615 Ent := Next_Literal (Ent);
10621 -- Ent points to entity to be marked
10623 if Arg_Count >= 1 then
10625 -- Deal with static string argument
10627 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10628 S := Strval (Get_Pragma_Arg (Arg1));
10630 for J in 1 .. String_Length (S) loop
10631 if not In_Character_Range (Get_String_Char (S, J)) then
10633 ("pragma% argument does not allow wide characters",
10638 Obsolescent_Warnings.Append
10639 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10641 -- Check for Ada_05 parameter
10643 if Arg_Count /= 1 then
10644 Check_Arg_Count (2);
10647 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10650 Check_Arg_Is_Identifier (Argx);
10652 if Chars (Argx) /= Name_Ada_05 then
10653 Error_Msg_Name_2 := Name_Ada_05;
10655 ("only allowed argument for pragma% is %", Argx);
10658 if Ada_Version_Explicit < Ada_2005
10659 or else not Warn_On_Ada_2005_Compatibility
10667 -- Set flag if pragma active
10670 Set_Is_Obsolescent (Ent);
10674 end Set_Obsolescent;
10676 -- Start of processing for pragma Obsolescent
10681 Check_At_Most_N_Arguments (3);
10683 -- See if first argument specifies an entity name
10687 (Chars (Arg1) = Name_Entity
10689 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10691 N_Operator_Symbol))
10693 Ename := Get_Pragma_Arg (Arg1);
10695 -- Eliminate first argument, so we can share processing
10699 Arg_Count := Arg_Count - 1;
10701 -- No Entity name argument given
10707 if Arg_Count >= 1 then
10708 Check_Optional_Identifier (Arg1, Name_Message);
10710 if Arg_Count = 2 then
10711 Check_Optional_Identifier (Arg2, Name_Version);
10715 -- Get immediately preceding declaration
10718 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10722 -- Cases where we do not follow anything other than another pragma
10726 -- First case: library level compilation unit declaration with
10727 -- the pragma immediately following the declaration.
10729 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10731 (Defining_Entity (Unit (Parent (Parent (N)))));
10734 -- Case 2: library unit placement for package
10738 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10740 if Is_Package_Or_Generic_Package (Ent) then
10741 Set_Obsolescent (Ent);
10747 -- Cases where we must follow a declaration
10750 if Nkind (Decl) not in N_Declaration
10751 and then Nkind (Decl) not in N_Later_Decl_Item
10752 and then Nkind (Decl) not in N_Generic_Declaration
10753 and then Nkind (Decl) not in N_Renaming_Declaration
10756 ("pragma% misplaced, "
10757 & "must immediately follow a declaration");
10760 Set_Obsolescent (Defining_Entity (Decl));
10770 -- pragma Optimize (Time | Space | Off);
10772 -- The actual check for optimize is done in Gigi. Note that this
10773 -- pragma does not actually change the optimization setting, it
10774 -- simply checks that it is consistent with the pragma.
10776 when Pragma_Optimize =>
10777 Check_No_Identifiers;
10778 Check_Arg_Count (1);
10779 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10781 ------------------------
10782 -- Optimize_Alignment --
10783 ------------------------
10785 -- pragma Optimize_Alignment (Time | Space | Off);
10787 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10789 Check_No_Identifiers;
10790 Check_Arg_Count (1);
10791 Check_Valid_Configuration_Pragma;
10794 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10798 Opt.Optimize_Alignment := 'T';
10800 Opt.Optimize_Alignment := 'S';
10802 Opt.Optimize_Alignment := 'O';
10804 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10808 -- Set indication that mode is set locally. If we are in fact in a
10809 -- configuration pragma file, this setting is harmless since the
10810 -- switch will get reset anyway at the start of each unit.
10812 Optimize_Alignment_Local := True;
10813 end Optimize_Alignment;
10819 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10821 when Pragma_Ordered => Ordered : declare
10822 Assoc : constant Node_Id := Arg1;
10828 Check_No_Identifiers;
10829 Check_Arg_Count (1);
10830 Check_Arg_Is_Local_Name (Arg1);
10832 Type_Id := Get_Pragma_Arg (Assoc);
10833 Find_Type (Type_Id);
10834 Typ := Entity (Type_Id);
10836 if Typ = Any_Type then
10839 Typ := Underlying_Type (Typ);
10842 if not Is_Enumeration_Type (Typ) then
10843 Error_Pragma ("pragma% must specify enumeration type");
10846 Check_First_Subtype (Arg1);
10847 Set_Has_Pragma_Ordered (Base_Type (Typ));
10854 -- pragma Pack (first_subtype_LOCAL_NAME);
10856 when Pragma_Pack => Pack : declare
10857 Assoc : constant Node_Id := Arg1;
10861 Ignore : Boolean := False;
10864 Check_No_Identifiers;
10865 Check_Arg_Count (1);
10866 Check_Arg_Is_Local_Name (Arg1);
10868 Type_Id := Get_Pragma_Arg (Assoc);
10869 Find_Type (Type_Id);
10870 Typ := Entity (Type_Id);
10873 or else Rep_Item_Too_Early (Typ, N)
10877 Typ := Underlying_Type (Typ);
10880 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
10881 Error_Pragma ("pragma% must specify array or record type");
10884 Check_First_Subtype (Arg1);
10885 Check_Duplicate_Pragma (Typ);
10889 if Is_Array_Type (Typ) then
10890 Ctyp := Component_Type (Typ);
10892 -- Ignore pack that does nothing
10894 if Known_Static_Esize (Ctyp)
10895 and then Known_Static_RM_Size (Ctyp)
10896 and then Esize (Ctyp) = RM_Size (Ctyp)
10897 and then Addressable (Esize (Ctyp))
10902 -- Process OK pragma Pack. Note that if there is a separate
10903 -- component clause present, the Pack will be cancelled. This
10904 -- processing is in Freeze.
10906 if not Rep_Item_Too_Late (Typ, N) then
10908 -- In the context of static code analysis, we do not need
10909 -- complex front-end expansions related to pragma Pack,
10910 -- so disable handling of pragma Pack in this case.
10912 if CodePeer_Mode then
10915 -- Don't attempt any packing for VM targets. We possibly
10916 -- could deal with some cases of array bit-packing, but we
10917 -- don't bother, since this is not a typical kind of
10918 -- representation in the VM context anyway (and would not
10919 -- for example work nicely with the debugger).
10921 elsif VM_Target /= No_VM then
10922 if not GNAT_Mode then
10924 ("?pragma% ignored in this configuration");
10927 -- Normal case where we do the pack action
10931 Set_Is_Packed (Base_Type (Typ), Sense);
10932 Set_Has_Non_Standard_Rep (Base_Type (Typ), Sense);
10935 Set_Has_Pragma_Pack (Base_Type (Typ), Sense);
10937 -- Complete reset action for Aspect_Cancel case
10939 if Sense = False then
10941 -- Cancel size unless explicitly set
10943 if not Has_Size_Clause (Typ)
10944 and then not Has_Object_Size_Clause (Typ)
10946 Set_Esize (Typ, Uint_0);
10947 Set_RM_Size (Typ, Uint_0);
10948 Set_Alignment (Typ, Uint_0);
10949 Set_Packed_Array_Type (Typ, Empty);
10952 -- Reset component size unless explicitly set
10954 if not Has_Component_Size_Clause (Typ) then
10955 if Known_Static_Esize (Ctyp)
10956 and then Known_Static_RM_Size (Ctyp)
10957 and then Esize (Ctyp) = RM_Size (Ctyp)
10958 and then Addressable (Esize (Ctyp))
10961 (Base_Type (Typ), Esize (Ctyp));
10964 (Base_Type (Typ), Uint_0);
10971 -- For record types, the pack is always effective
10973 else pragma Assert (Is_Record_Type (Typ));
10974 if not Rep_Item_Too_Late (Typ, N) then
10976 -- Ignore pack request with warning in VM mode (skip warning
10977 -- if we are compiling GNAT run time library).
10979 if VM_Target /= No_VM then
10980 if not GNAT_Mode then
10982 ("?pragma% ignored in this configuration");
10985 -- Normal case of pack request active
10988 Set_Is_Packed (Base_Type (Typ), Sense);
10989 Set_Has_Pragma_Pack (Base_Type (Typ), Sense);
10990 Set_Has_Non_Standard_Rep (Base_Type (Typ), Sense);
10992 -- Complete reset action for Aspect_Cancel case
10994 if Sense = False then
10996 -- Cancel size if not explicitly given
10998 if not Has_Size_Clause (Typ)
10999 and then not Has_Object_Size_Clause (Typ)
11001 Set_Esize (Typ, Uint_0);
11002 Set_Alignment (Typ, Uint_0);
11016 -- There is nothing to do here, since we did all the processing for
11017 -- this pragma in Par.Prag (so that it works properly even in syntax
11020 when Pragma_Page =>
11027 -- pragma Passive [(PASSIVE_FORM)];
11029 -- PASSIVE_FORM ::= Semaphore | No
11031 when Pragma_Passive =>
11034 if Nkind (Parent (N)) /= N_Task_Definition then
11035 Error_Pragma ("pragma% must be within task definition");
11038 if Arg_Count /= 0 then
11039 Check_Arg_Count (1);
11040 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11043 ----------------------------------
11044 -- Preelaborable_Initialization --
11045 ----------------------------------
11047 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11049 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11054 Check_Arg_Count (1);
11055 Check_No_Identifiers;
11056 Check_Arg_Is_Identifier (Arg1);
11057 Check_Arg_Is_Local_Name (Arg1);
11058 Check_First_Subtype (Arg1);
11059 Ent := Entity (Get_Pragma_Arg (Arg1));
11061 if not (Is_Private_Type (Ent)
11063 Is_Protected_Type (Ent)
11065 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11068 ("pragma % can only be applied to private, formal derived or "
11069 & "protected type",
11073 -- Give an error if the pragma is applied to a protected type that
11074 -- does not qualify (due to having entries, or due to components
11075 -- that do not qualify).
11077 if Is_Protected_Type (Ent)
11078 and then not Has_Preelaborable_Initialization (Ent)
11081 ("protected type & does not have preelaborable " &
11082 "initialization", Ent);
11084 -- Otherwise mark the type as definitely having preelaborable
11088 Set_Known_To_Have_Preelab_Init (Ent);
11091 if Has_Pragma_Preelab_Init (Ent)
11092 and then Warn_On_Redundant_Constructs
11094 Error_Pragma ("?duplicate pragma%!");
11096 Set_Has_Pragma_Preelab_Init (Ent);
11100 --------------------
11101 -- Persistent_BSS --
11102 --------------------
11104 -- pragma Persistent_BSS [(object_NAME)];
11106 when Pragma_Persistent_BSS => Persistent_BSS : declare
11113 Check_At_Most_N_Arguments (1);
11115 -- Case of application to specific object (one argument)
11117 if Arg_Count = 1 then
11118 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11120 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11122 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11125 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11128 Ent := Entity (Get_Pragma_Arg (Arg1));
11129 Decl := Parent (Ent);
11131 if Rep_Item_Too_Late (Ent, N) then
11135 if Present (Expression (Decl)) then
11137 ("object for pragma% cannot have initialization", Arg1);
11140 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11142 ("object type for pragma% is not potentially persistent",
11146 Check_Duplicate_Pragma (Ent);
11150 Make_Linker_Section_Pragma
11151 (Ent, Sloc (N), ".persistent.bss");
11152 Insert_After (N, Prag);
11156 -- Case of use as configuration pragma with no arguments
11159 Check_Valid_Configuration_Pragma;
11160 Persistent_BSS_Mode := True;
11162 end Persistent_BSS;
11168 -- pragma Polling (ON | OFF);
11170 when Pragma_Polling =>
11172 Check_Arg_Count (1);
11173 Check_No_Identifiers;
11174 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11175 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11177 -------------------
11178 -- Postcondition --
11179 -------------------
11181 -- pragma Postcondition ([Check =>] Boolean_Expression
11182 -- [,[Message =>] String_Expression]);
11184 when Pragma_Postcondition => Postcondition : declare
11186 pragma Warnings (Off, In_Body);
11190 Check_At_Least_N_Arguments (1);
11191 Check_At_Most_N_Arguments (2);
11192 Check_Optional_Identifier (Arg1, Name_Check);
11194 -- All we need to do here is call the common check procedure,
11195 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11197 Check_Precondition_Postcondition (In_Body);
11204 -- pragma Precondition ([Check =>] Boolean_Expression
11205 -- [,[Message =>] String_Expression]);
11207 when Pragma_Precondition => Precondition : declare
11212 Check_At_Least_N_Arguments (1);
11213 Check_At_Most_N_Arguments (2);
11214 Check_Optional_Identifier (Arg1, Name_Check);
11215 Check_Precondition_Postcondition (In_Body);
11217 -- If in spec, nothing more to do. If in body, then we convert the
11218 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11219 -- this whether or not precondition checks are enabled. That works
11220 -- fine since pragma Check will do this check, and will also
11221 -- analyze the condition itself in the proper context.
11226 Chars => Name_Check,
11227 Pragma_Argument_Associations => New_List (
11228 Make_Pragma_Argument_Association (Loc,
11229 Expression => Make_Identifier (Loc, Name_Precondition)),
11231 Make_Pragma_Argument_Association (Sloc (Arg1),
11232 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11234 if Arg_Count = 2 then
11235 Append_To (Pragma_Argument_Associations (N),
11236 Make_Pragma_Argument_Association (Sloc (Arg2),
11237 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11248 -- pragma Predicate
11249 -- ([Entity =>] type_LOCAL_NAME,
11250 -- [Check =>] EXPRESSION);
11252 when Pragma_Predicate => Predicate : declare
11257 pragma Unreferenced (Discard);
11261 Check_Arg_Count (2);
11262 Check_Optional_Identifier (Arg1, Name_Entity);
11263 Check_Optional_Identifier (Arg2, Name_Check);
11265 Check_Arg_Is_Local_Name (Arg1);
11267 Type_Id := Get_Pragma_Arg (Arg1);
11268 Find_Type (Type_Id);
11269 Typ := Entity (Type_Id);
11271 if Typ = Any_Type then
11275 -- The remaining processing is simply to link the pragma on to
11276 -- the rep item chain, for processing when the type is frozen.
11277 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11278 -- mark the type as having predicates.
11280 Set_Has_Predicates (Typ);
11281 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11288 -- pragma Preelaborate [(library_unit_NAME)];
11290 -- Set the flag Is_Preelaborated of program unit name entity
11292 when Pragma_Preelaborate => Preelaborate : declare
11293 Pa : constant Node_Id := Parent (N);
11294 Pk : constant Node_Kind := Nkind (Pa);
11298 Check_Ada_83_Warning;
11299 Check_Valid_Library_Unit_Pragma;
11301 if Nkind (N) = N_Null_Statement then
11305 Ent := Find_Lib_Unit_Name;
11306 Check_Duplicate_Pragma (Ent);
11308 -- This filters out pragmas inside generic parent then
11309 -- show up inside instantiation
11312 and then not (Pk = N_Package_Specification
11313 and then Present (Generic_Parent (Pa)))
11315 if not Debug_Flag_U then
11316 Set_Is_Preelaborated (Ent, Sense);
11317 Set_Suppress_Elaboration_Warnings (Ent, Sense);
11322 ---------------------
11323 -- Preelaborate_05 --
11324 ---------------------
11326 -- pragma Preelaborate_05 [(library_unit_NAME)];
11328 -- This pragma is useable only in GNAT_Mode, where it is used like
11329 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11330 -- (otherwise it is ignored). This is used to implement AI-362 which
11331 -- recategorizes some run-time packages in Ada 2005 mode.
11333 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11338 Check_Valid_Library_Unit_Pragma;
11340 if not GNAT_Mode then
11341 Error_Pragma ("pragma% only available in GNAT mode");
11344 if Nkind (N) = N_Null_Statement then
11348 -- This is one of the few cases where we need to test the value of
11349 -- Ada_Version_Explicit rather than Ada_Version (which is always
11350 -- set to Ada_2012 in a predefined unit), we need to know the
11351 -- explicit version set to know if this pragma is active.
11353 if Ada_Version_Explicit >= Ada_2005 then
11354 Ent := Find_Lib_Unit_Name;
11355 Set_Is_Preelaborated (Ent);
11356 Set_Suppress_Elaboration_Warnings (Ent);
11358 end Preelaborate_05;
11364 -- pragma Priority (EXPRESSION);
11366 when Pragma_Priority => Priority : declare
11367 P : constant Node_Id := Parent (N);
11371 Check_No_Identifiers;
11372 Check_Arg_Count (1);
11376 if Nkind (P) = N_Subprogram_Body then
11377 Check_In_Main_Program;
11379 Arg := Get_Pragma_Arg (Arg1);
11380 Analyze_And_Resolve (Arg, Standard_Integer);
11384 if not Is_Static_Expression (Arg) then
11385 Flag_Non_Static_Expr
11386 ("main subprogram priority is not static!", Arg);
11389 -- If constraint error, then we already signalled an error
11391 elsif Raises_Constraint_Error (Arg) then
11394 -- Otherwise check in range
11398 Val : constant Uint := Expr_Value (Arg);
11402 or else Val > Expr_Value (Expression
11403 (Parent (RTE (RE_Max_Priority))))
11406 ("main subprogram priority is out of range", Arg1);
11412 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11414 -- Load an arbitrary entity from System.Tasking to make sure
11415 -- this package is implicitly with'ed, since we need to have
11416 -- the tasking run-time active for the pragma Priority to have
11420 Discard : Entity_Id;
11421 pragma Warnings (Off, Discard);
11423 Discard := RTE (RE_Task_List);
11426 -- Task or Protected, must be of type Integer
11428 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11429 Arg := Get_Pragma_Arg (Arg1);
11431 -- The expression must be analyzed in the special manner
11432 -- described in "Handling of Default and Per-Object
11433 -- Expressions" in sem.ads.
11435 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11437 if not Is_Static_Expression (Arg) then
11438 Check_Restriction (Static_Priorities, Arg);
11441 -- Anything else is incorrect
11447 if Has_Pragma_Priority (P) then
11448 Error_Pragma ("duplicate pragma% not allowed");
11450 Set_Has_Pragma_Priority (P, True);
11452 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11453 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11454 -- exp_ch9 should use this ???
11459 -----------------------------------
11460 -- Priority_Specific_Dispatching --
11461 -----------------------------------
11463 -- pragma Priority_Specific_Dispatching (
11464 -- policy_IDENTIFIER,
11465 -- first_priority_EXPRESSION,
11466 -- last_priority_EXPRESSION);
11468 when Pragma_Priority_Specific_Dispatching =>
11469 Priority_Specific_Dispatching : declare
11470 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11471 -- This is the entity System.Any_Priority;
11474 Lower_Bound : Node_Id;
11475 Upper_Bound : Node_Id;
11481 Check_Arg_Count (3);
11482 Check_No_Identifiers;
11483 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11484 Check_Valid_Configuration_Pragma;
11485 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11486 DP := Fold_Upper (Name_Buffer (1));
11488 Lower_Bound := Get_Pragma_Arg (Arg2);
11489 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11490 Lower_Val := Expr_Value (Lower_Bound);
11492 Upper_Bound := Get_Pragma_Arg (Arg3);
11493 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11494 Upper_Val := Expr_Value (Upper_Bound);
11496 -- It is not allowed to use Task_Dispatching_Policy and
11497 -- Priority_Specific_Dispatching in the same partition.
11499 if Task_Dispatching_Policy /= ' ' then
11500 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11502 ("pragma% incompatible with Task_Dispatching_Policy#");
11504 -- Check lower bound in range
11506 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11508 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11511 ("first_priority is out of range", Arg2);
11513 -- Check upper bound in range
11515 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11517 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11520 ("last_priority is out of range", Arg3);
11522 -- Check that the priority range is valid
11524 elsif Lower_Val > Upper_Val then
11526 ("last_priority_expression must be greater than" &
11527 " or equal to first_priority_expression");
11529 -- Store the new policy, but always preserve System_Location since
11530 -- we like the error message with the run-time name.
11533 -- Check overlapping in the priority ranges specified in other
11534 -- Priority_Specific_Dispatching pragmas within the same
11535 -- partition. We can only check those we know about!
11538 Specific_Dispatching.First .. Specific_Dispatching.Last
11540 if Specific_Dispatching.Table (J).First_Priority in
11541 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11542 or else Specific_Dispatching.Table (J).Last_Priority in
11543 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11546 Specific_Dispatching.Table (J).Pragma_Loc;
11548 ("priority range overlaps with "
11549 & "Priority_Specific_Dispatching#");
11553 -- The use of Priority_Specific_Dispatching is incompatible
11554 -- with Task_Dispatching_Policy.
11556 if Task_Dispatching_Policy /= ' ' then
11557 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11559 ("Priority_Specific_Dispatching incompatible "
11560 & "with Task_Dispatching_Policy#");
11563 -- The use of Priority_Specific_Dispatching forces ceiling
11566 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11567 Error_Msg_Sloc := Locking_Policy_Sloc;
11569 ("Priority_Specific_Dispatching incompatible "
11570 & "with Locking_Policy#");
11572 -- Set the Ceiling_Locking policy, but preserve System_Location
11573 -- since we like the error message with the run time name.
11576 Locking_Policy := 'C';
11578 if Locking_Policy_Sloc /= System_Location then
11579 Locking_Policy_Sloc := Loc;
11583 -- Add entry in the table
11585 Specific_Dispatching.Append
11586 ((Dispatching_Policy => DP,
11587 First_Priority => UI_To_Int (Lower_Val),
11588 Last_Priority => UI_To_Int (Upper_Val),
11589 Pragma_Loc => Loc));
11591 end Priority_Specific_Dispatching;
11597 -- pragma Profile (profile_IDENTIFIER);
11599 -- profile_IDENTIFIER => Restricted | Ravenscar
11601 when Pragma_Profile =>
11603 Check_Arg_Count (1);
11604 Check_Valid_Configuration_Pragma;
11605 Check_No_Identifiers;
11608 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11610 if Chars (Argx) = Name_Ravenscar then
11611 Set_Ravenscar_Profile (N);
11612 elsif Chars (Argx) = Name_Restricted then
11613 Set_Profile_Restrictions
11614 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11616 Error_Pragma_Arg ("& is not a valid profile", Argx);
11620 ----------------------
11621 -- Profile_Warnings --
11622 ----------------------
11624 -- pragma Profile_Warnings (profile_IDENTIFIER);
11626 -- profile_IDENTIFIER => Restricted | Ravenscar
11628 when Pragma_Profile_Warnings =>
11630 Check_Arg_Count (1);
11631 Check_Valid_Configuration_Pragma;
11632 Check_No_Identifiers;
11635 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11637 if Chars (Argx) = Name_Ravenscar then
11638 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11639 elsif Chars (Argx) = Name_Restricted then
11640 Set_Profile_Restrictions (Restricted, N, Warn => True);
11642 Error_Pragma_Arg ("& is not a valid profile", Argx);
11646 --------------------------
11647 -- Propagate_Exceptions --
11648 --------------------------
11650 -- pragma Propagate_Exceptions;
11652 -- Note: this pragma is obsolete and has no effect
11654 when Pragma_Propagate_Exceptions =>
11656 Check_Arg_Count (0);
11658 if In_Extended_Main_Source_Unit (N) then
11659 Propagate_Exceptions := True;
11666 -- pragma Psect_Object (
11667 -- [Internal =>] LOCAL_NAME,
11668 -- [, [External =>] EXTERNAL_SYMBOL]
11669 -- [, [Size =>] EXTERNAL_SYMBOL]);
11671 when Pragma_Psect_Object | Pragma_Common_Object =>
11672 Psect_Object : declare
11673 Args : Args_List (1 .. 3);
11674 Names : constant Name_List (1 .. 3) := (
11679 Internal : Node_Id renames Args (1);
11680 External : Node_Id renames Args (2);
11681 Size : Node_Id renames Args (3);
11683 Def_Id : Entity_Id;
11685 procedure Check_Too_Long (Arg : Node_Id);
11686 -- Posts message if the argument is an identifier with more
11687 -- than 31 characters, or a string literal with more than
11688 -- 31 characters, and we are operating under VMS
11690 --------------------
11691 -- Check_Too_Long --
11692 --------------------
11694 procedure Check_Too_Long (Arg : Node_Id) is
11695 X : constant Node_Id := Original_Node (Arg);
11698 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11700 ("inappropriate argument for pragma %", Arg);
11703 if OpenVMS_On_Target then
11704 if (Nkind (X) = N_String_Literal
11705 and then String_Length (Strval (X)) > 31)
11707 (Nkind (X) = N_Identifier
11708 and then Length_Of_Name (Chars (X)) > 31)
11711 ("argument for pragma % is longer than 31 characters",
11715 end Check_Too_Long;
11717 -- Start of processing for Common_Object/Psect_Object
11721 Gather_Associations (Names, Args);
11722 Process_Extended_Import_Export_Internal_Arg (Internal);
11724 Def_Id := Entity (Internal);
11726 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11728 ("pragma% must designate an object", Internal);
11731 Check_Too_Long (Internal);
11733 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11735 ("cannot use pragma% for imported/exported object",
11739 if Is_Concurrent_Type (Etype (Internal)) then
11741 ("cannot specify pragma % for task/protected object",
11745 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11747 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11749 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11752 if Ekind (Def_Id) = E_Constant then
11754 ("cannot specify pragma % for a constant", Internal);
11757 if Is_Record_Type (Etype (Internal)) then
11763 Ent := First_Entity (Etype (Internal));
11764 while Present (Ent) loop
11765 Decl := Declaration_Node (Ent);
11767 if Ekind (Ent) = E_Component
11768 and then Nkind (Decl) = N_Component_Declaration
11769 and then Present (Expression (Decl))
11770 and then Warn_On_Export_Import
11773 ("?object for pragma % has defaults", Internal);
11783 if Present (Size) then
11784 Check_Too_Long (Size);
11787 if Present (External) then
11788 Check_Arg_Is_External_Name (External);
11789 Check_Too_Long (External);
11792 -- If all error tests pass, link pragma on to the rep item chain
11794 Record_Rep_Item (Def_Id, N);
11801 -- pragma Pure [(library_unit_NAME)];
11803 when Pragma_Pure => Pure : declare
11807 Check_Ada_83_Warning;
11808 Check_Valid_Library_Unit_Pragma;
11810 if Nkind (N) = N_Null_Statement then
11814 Ent := Find_Lib_Unit_Name;
11816 Set_Has_Pragma_Pure (Ent);
11817 Set_Suppress_Elaboration_Warnings (Ent);
11824 -- pragma Pure_05 [(library_unit_NAME)];
11826 -- This pragma is useable only in GNAT_Mode, where it is used like
11827 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11828 -- it is ignored). It may be used after a pragma Preelaborate, in
11829 -- which case it overrides the effect of the pragma Preelaborate.
11830 -- This is used to implement AI-362 which recategorizes some run-time
11831 -- packages in Ada 2005 mode.
11833 when Pragma_Pure_05 => Pure_05 : declare
11838 Check_Valid_Library_Unit_Pragma;
11840 if not GNAT_Mode then
11841 Error_Pragma ("pragma% only available in GNAT mode");
11844 if Nkind (N) = N_Null_Statement then
11848 -- This is one of the few cases where we need to test the value of
11849 -- Ada_Version_Explicit rather than Ada_Version (which is always
11850 -- set to Ada_2012 in a predefined unit), we need to know the
11851 -- explicit version set to know if this pragma is active.
11853 if Ada_Version_Explicit >= Ada_2005 then
11854 Ent := Find_Lib_Unit_Name;
11855 Set_Is_Preelaborated (Ent, False);
11857 Set_Suppress_Elaboration_Warnings (Ent);
11861 -------------------
11862 -- Pure_Function --
11863 -------------------
11865 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11867 when Pragma_Pure_Function => Pure_Function : declare
11870 Def_Id : Entity_Id;
11871 Effective : Boolean := False;
11875 Check_Arg_Count (1);
11876 Check_Optional_Identifier (Arg1, Name_Entity);
11877 Check_Arg_Is_Local_Name (Arg1);
11878 E_Id := Get_Pragma_Arg (Arg1);
11880 if Error_Posted (E_Id) then
11884 -- Loop through homonyms (overloadings) of referenced entity
11886 E := Entity (E_Id);
11888 if Present (E) then
11890 Def_Id := Get_Base_Subprogram (E);
11892 if not Ekind_In (Def_Id, E_Function,
11893 E_Generic_Function,
11897 ("pragma% requires a function name", Arg1);
11900 Set_Is_Pure (Def_Id, Sense);
11902 if not Has_Pragma_Pure_Function (Def_Id) then
11903 Set_Has_Pragma_Pure_Function (Def_Id, Sense);
11904 Effective := Sense;
11907 exit when From_Aspect_Specification (N);
11909 exit when No (E) or else Scope (E) /= Current_Scope;
11912 if Sense and then not Effective
11913 and then Warn_On_Redundant_Constructs
11916 ("pragma Pure_Function on& is redundant?",
11922 --------------------
11923 -- Queuing_Policy --
11924 --------------------
11926 -- pragma Queuing_Policy (policy_IDENTIFIER);
11928 when Pragma_Queuing_Policy => declare
11932 Check_Ada_83_Warning;
11933 Check_Arg_Count (1);
11934 Check_No_Identifiers;
11935 Check_Arg_Is_Queuing_Policy (Arg1);
11936 Check_Valid_Configuration_Pragma;
11937 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11938 QP := Fold_Upper (Name_Buffer (1));
11940 if Queuing_Policy /= ' '
11941 and then Queuing_Policy /= QP
11943 Error_Msg_Sloc := Queuing_Policy_Sloc;
11944 Error_Pragma ("queuing policy incompatible with policy#");
11946 -- Set new policy, but always preserve System_Location since we
11947 -- like the error message with the run time name.
11950 Queuing_Policy := QP;
11952 if Queuing_Policy_Sloc /= System_Location then
11953 Queuing_Policy_Sloc := Loc;
11958 -----------------------
11959 -- Relative_Deadline --
11960 -----------------------
11962 -- pragma Relative_Deadline (time_span_EXPRESSION);
11964 when Pragma_Relative_Deadline => Relative_Deadline : declare
11965 P : constant Node_Id := Parent (N);
11970 Check_No_Identifiers;
11971 Check_Arg_Count (1);
11973 Arg := Get_Pragma_Arg (Arg1);
11975 -- The expression must be analyzed in the special manner described
11976 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
11978 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
11982 if Nkind (P) = N_Subprogram_Body then
11983 Check_In_Main_Program;
11987 elsif Nkind (P) = N_Task_Definition then
11990 -- Anything else is incorrect
11996 if Has_Relative_Deadline_Pragma (P) then
11997 Error_Pragma ("duplicate pragma% not allowed");
11999 Set_Has_Relative_Deadline_Pragma (P, True);
12001 if Nkind (P) = N_Task_Definition then
12002 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12005 end Relative_Deadline;
12007 ---------------------------
12008 -- Remote_Call_Interface --
12009 ---------------------------
12011 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12013 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12014 Cunit_Node : Node_Id;
12015 Cunit_Ent : Entity_Id;
12019 Check_Ada_83_Warning;
12020 Check_Valid_Library_Unit_Pragma;
12022 if Nkind (N) = N_Null_Statement then
12026 Cunit_Node := Cunit (Current_Sem_Unit);
12027 K := Nkind (Unit (Cunit_Node));
12028 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12030 if K = N_Package_Declaration
12031 or else K = N_Generic_Package_Declaration
12032 or else K = N_Subprogram_Declaration
12033 or else K = N_Generic_Subprogram_Declaration
12034 or else (K = N_Subprogram_Body
12035 and then Acts_As_Spec (Unit (Cunit_Node)))
12040 "pragma% must apply to package or subprogram declaration");
12043 Set_Is_Remote_Call_Interface (Cunit_Ent);
12044 end Remote_Call_Interface;
12050 -- pragma Remote_Types [(library_unit_NAME)];
12052 when Pragma_Remote_Types => Remote_Types : declare
12053 Cunit_Node : Node_Id;
12054 Cunit_Ent : Entity_Id;
12057 Check_Ada_83_Warning;
12058 Check_Valid_Library_Unit_Pragma;
12060 if Nkind (N) = N_Null_Statement then
12064 Cunit_Node := Cunit (Current_Sem_Unit);
12065 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12067 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12068 N_Generic_Package_Declaration)
12071 ("pragma% can only apply to a package declaration");
12074 Set_Is_Remote_Types (Cunit_Ent);
12081 -- pragma Ravenscar;
12083 when Pragma_Ravenscar =>
12085 Check_Arg_Count (0);
12086 Check_Valid_Configuration_Pragma;
12087 Set_Ravenscar_Profile (N);
12089 if Warn_On_Obsolescent_Feature then
12090 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12091 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12094 -------------------------
12095 -- Restricted_Run_Time --
12096 -------------------------
12098 -- pragma Restricted_Run_Time;
12100 when Pragma_Restricted_Run_Time =>
12102 Check_Arg_Count (0);
12103 Check_Valid_Configuration_Pragma;
12104 Set_Profile_Restrictions
12105 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12107 if Warn_On_Obsolescent_Feature then
12109 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12110 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12117 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12120 -- restriction_IDENTIFIER
12121 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12123 when Pragma_Restrictions =>
12124 Process_Restrictions_Or_Restriction_Warnings
12125 (Warn => Treat_Restrictions_As_Warnings);
12127 --------------------------
12128 -- Restriction_Warnings --
12129 --------------------------
12131 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12134 -- restriction_IDENTIFIER
12135 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12137 when Pragma_Restriction_Warnings =>
12139 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12145 -- pragma Reviewable;
12147 when Pragma_Reviewable =>
12148 Check_Ada_83_Warning;
12149 Check_Arg_Count (0);
12151 -- Call dummy debugging function rv. This is done to assist front
12152 -- end debugging. By placing a Reviewable pragma in the source
12153 -- program, a breakpoint on rv catches this place in the source,
12154 -- allowing convenient stepping to the point of interest.
12158 --------------------------
12159 -- Short_Circuit_And_Or --
12160 --------------------------
12162 when Pragma_Short_Circuit_And_Or =>
12164 Check_Arg_Count (0);
12165 Check_Valid_Configuration_Pragma;
12166 Short_Circuit_And_Or := True;
12168 -------------------
12169 -- Share_Generic --
12170 -------------------
12172 -- pragma Share_Generic (NAME {, NAME});
12174 when Pragma_Share_Generic =>
12176 Process_Generic_List;
12182 -- pragma Shared (LOCAL_NAME);
12184 when Pragma_Shared =>
12186 Process_Atomic_Shared_Volatile;
12188 --------------------
12189 -- Shared_Passive --
12190 --------------------
12192 -- pragma Shared_Passive [(library_unit_NAME)];
12194 -- Set the flag Is_Shared_Passive of program unit name entity
12196 when Pragma_Shared_Passive => Shared_Passive : declare
12197 Cunit_Node : Node_Id;
12198 Cunit_Ent : Entity_Id;
12201 Check_Ada_83_Warning;
12202 Check_Valid_Library_Unit_Pragma;
12204 if Nkind (N) = N_Null_Statement then
12208 Cunit_Node := Cunit (Current_Sem_Unit);
12209 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12211 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12212 N_Generic_Package_Declaration)
12215 ("pragma% can only apply to a package declaration");
12218 Set_Is_Shared_Passive (Cunit_Ent);
12219 end Shared_Passive;
12221 -----------------------
12222 -- Short_Descriptors --
12223 -----------------------
12225 -- pragma Short_Descriptors;
12227 when Pragma_Short_Descriptors =>
12229 Check_Arg_Count (0);
12230 Check_Valid_Configuration_Pragma;
12231 Short_Descriptors := True;
12233 ----------------------
12234 -- Source_File_Name --
12235 ----------------------
12237 -- There are five forms for this pragma:
12239 -- pragma Source_File_Name (
12240 -- [UNIT_NAME =>] unit_NAME,
12241 -- BODY_FILE_NAME => STRING_LITERAL
12242 -- [, [INDEX =>] INTEGER_LITERAL]);
12244 -- pragma Source_File_Name (
12245 -- [UNIT_NAME =>] unit_NAME,
12246 -- SPEC_FILE_NAME => STRING_LITERAL
12247 -- [, [INDEX =>] INTEGER_LITERAL]);
12249 -- pragma Source_File_Name (
12250 -- BODY_FILE_NAME => STRING_LITERAL
12251 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12252 -- [, CASING => CASING_SPEC]);
12254 -- pragma Source_File_Name (
12255 -- SPEC_FILE_NAME => STRING_LITERAL
12256 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12257 -- [, CASING => CASING_SPEC]);
12259 -- pragma Source_File_Name (
12260 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12261 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12262 -- [, CASING => CASING_SPEC]);
12264 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12266 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12267 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12268 -- only be used when no project file is used, while SFNP can only be
12269 -- used when a project file is used.
12271 -- No processing here. Processing was completed during parsing, since
12272 -- we need to have file names set as early as possible. Units are
12273 -- loaded well before semantic processing starts.
12275 -- The only processing we defer to this point is the check for
12276 -- correct placement.
12278 when Pragma_Source_File_Name =>
12280 Check_Valid_Configuration_Pragma;
12282 ------------------------------
12283 -- Source_File_Name_Project --
12284 ------------------------------
12286 -- See Source_File_Name for syntax
12288 -- No processing here. Processing was completed during parsing, since
12289 -- we need to have file names set as early as possible. Units are
12290 -- loaded well before semantic processing starts.
12292 -- The only processing we defer to this point is the check for
12293 -- correct placement.
12295 when Pragma_Source_File_Name_Project =>
12297 Check_Valid_Configuration_Pragma;
12299 -- Check that a pragma Source_File_Name_Project is used only in a
12300 -- configuration pragmas file.
12302 -- Pragmas Source_File_Name_Project should only be generated by
12303 -- the Project Manager in configuration pragmas files.
12305 -- This is really an ugly test. It seems to depend on some
12306 -- accidental and undocumented property. At the very least it
12307 -- needs to be documented, but it would be better to have a
12308 -- clean way of testing if we are in a configuration file???
12310 if Present (Parent (N)) then
12312 ("pragma% can only appear in a configuration pragmas file");
12315 ----------------------
12316 -- Source_Reference --
12317 ----------------------
12319 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12321 -- Nothing to do, all processing completed in Par.Prag, since we need
12322 -- the information for possible parser messages that are output.
12324 when Pragma_Source_Reference =>
12331 -- pragma SPARK_95;
12333 -- Note: this pragma also has some specific processing in Par.Prag
12334 -- because we want to set the SPARK 95 version mode during parsing.
12336 when Pragma_SPARK_95 =>
12338 Check_Arg_Count (0);
12339 Check_Valid_Configuration_Pragma;
12340 SPARK_Version := SPARK_95;
12341 SPARK_Mode := True;
12342 Formal_Verification_Mode := True;
12343 Set_Error_Msg_Lang ("spark");
12345 --------------------------------
12346 -- Static_Elaboration_Desired --
12347 --------------------------------
12349 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12351 when Pragma_Static_Elaboration_Desired =>
12353 Check_At_Most_N_Arguments (1);
12355 if Is_Compilation_Unit (Current_Scope)
12356 and then Ekind (Current_Scope) = E_Package
12358 Set_Static_Elaboration_Desired (Current_Scope, True);
12360 Error_Pragma ("pragma% must apply to a library-level package");
12367 -- pragma Storage_Size (EXPRESSION);
12369 when Pragma_Storage_Size => Storage_Size : declare
12370 P : constant Node_Id := Parent (N);
12374 Check_No_Identifiers;
12375 Check_Arg_Count (1);
12377 -- The expression must be analyzed in the special manner described
12378 -- in "Handling of Default Expressions" in sem.ads.
12380 Arg := Get_Pragma_Arg (Arg1);
12381 Preanalyze_Spec_Expression (Arg, Any_Integer);
12383 if not Is_Static_Expression (Arg) then
12384 Check_Restriction (Static_Storage_Size, Arg);
12387 if Nkind (P) /= N_Task_Definition then
12392 if Has_Storage_Size_Pragma (P) then
12393 Error_Pragma ("duplicate pragma% not allowed");
12395 Set_Has_Storage_Size_Pragma (P, True);
12398 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12399 -- ??? exp_ch9 should use this!
12407 -- pragma Storage_Unit (NUMERIC_LITERAL);
12409 -- Only permitted argument is System'Storage_Unit value
12411 when Pragma_Storage_Unit =>
12412 Check_No_Identifiers;
12413 Check_Arg_Count (1);
12414 Check_Arg_Is_Integer_Literal (Arg1);
12416 if Intval (Get_Pragma_Arg (Arg1)) /=
12417 UI_From_Int (Ttypes.System_Storage_Unit)
12419 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12421 ("the only allowed argument for pragma% is ^", Arg1);
12424 --------------------
12425 -- Stream_Convert --
12426 --------------------
12428 -- pragma Stream_Convert (
12429 -- [Entity =>] type_LOCAL_NAME,
12430 -- [Read =>] function_NAME,
12431 -- [Write =>] function NAME);
12433 when Pragma_Stream_Convert => Stream_Convert : declare
12435 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12436 -- Check that the given argument is the name of a local function
12437 -- of one argument that is not overloaded earlier in the current
12438 -- local scope. A check is also made that the argument is a
12439 -- function with one parameter.
12441 --------------------------------------
12442 -- Check_OK_Stream_Convert_Function --
12443 --------------------------------------
12445 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12449 Check_Arg_Is_Local_Name (Arg);
12450 Ent := Entity (Get_Pragma_Arg (Arg));
12452 if Has_Homonym (Ent) then
12454 ("argument for pragma% may not be overloaded", Arg);
12457 if Ekind (Ent) /= E_Function
12458 or else No (First_Formal (Ent))
12459 or else Present (Next_Formal (First_Formal (Ent)))
12462 ("argument for pragma% must be" &
12463 " function of one argument", Arg);
12465 end Check_OK_Stream_Convert_Function;
12467 -- Start of processing for Stream_Convert
12471 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12472 Check_Arg_Count (3);
12473 Check_Optional_Identifier (Arg1, Name_Entity);
12474 Check_Optional_Identifier (Arg2, Name_Read);
12475 Check_Optional_Identifier (Arg3, Name_Write);
12476 Check_Arg_Is_Local_Name (Arg1);
12477 Check_OK_Stream_Convert_Function (Arg2);
12478 Check_OK_Stream_Convert_Function (Arg3);
12481 Typ : constant Entity_Id :=
12482 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12483 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12484 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12487 Check_First_Subtype (Arg1);
12489 -- Check for too early or too late. Note that we don't enforce
12490 -- the rule about primitive operations in this case, since, as
12491 -- is the case for explicit stream attributes themselves, these
12492 -- restrictions are not appropriate. Note that the chaining of
12493 -- the pragma by Rep_Item_Too_Late is actually the critical
12494 -- processing done for this pragma.
12496 if Rep_Item_Too_Early (Typ, N)
12498 Rep_Item_Too_Late (Typ, N, FOnly => True)
12503 -- Return if previous error
12505 if Etype (Typ) = Any_Type
12507 Etype (Read) = Any_Type
12509 Etype (Write) = Any_Type
12516 if Underlying_Type (Etype (Read)) /= Typ then
12518 ("incorrect return type for function&", Arg2);
12521 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12523 ("incorrect parameter type for function&", Arg3);
12526 if Underlying_Type (Etype (First_Formal (Read))) /=
12527 Underlying_Type (Etype (Write))
12530 ("result type of & does not match Read parameter type",
12534 end Stream_Convert;
12536 -------------------------
12537 -- Style_Checks (GNAT) --
12538 -------------------------
12540 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12542 -- This is processed by the parser since some of the style checks
12543 -- take place during source scanning and parsing. This means that
12544 -- we don't need to issue error messages here.
12546 when Pragma_Style_Checks => Style_Checks : declare
12547 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12553 Check_No_Identifiers;
12555 -- Two argument form
12557 if Arg_Count = 2 then
12558 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12565 E_Id := Get_Pragma_Arg (Arg2);
12568 if not Is_Entity_Name (E_Id) then
12570 ("second argument of pragma% must be entity name",
12574 E := Entity (E_Id);
12580 Set_Suppress_Style_Checks (E,
12581 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12582 exit when No (Homonym (E));
12588 -- One argument form
12591 Check_Arg_Count (1);
12593 if Nkind (A) = N_String_Literal then
12597 Slen : constant Natural := Natural (String_Length (S));
12598 Options : String (1 .. Slen);
12604 C := Get_String_Char (S, Int (J));
12605 exit when not In_Character_Range (C);
12606 Options (J) := Get_Character (C);
12608 -- If at end of string, set options. As per discussion
12609 -- above, no need to check for errors, since we issued
12610 -- them in the parser.
12613 Set_Style_Check_Options (Options);
12621 elsif Nkind (A) = N_Identifier then
12622 if Chars (A) = Name_All_Checks then
12624 Set_GNAT_Style_Check_Options;
12626 Set_Default_Style_Check_Options;
12629 elsif Chars (A) = Name_On then
12630 Style_Check := True;
12632 elsif Chars (A) = Name_Off then
12633 Style_Check := False;
12643 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12645 when Pragma_Subtitle =>
12647 Check_Arg_Count (1);
12648 Check_Optional_Identifier (Arg1, Name_Subtitle);
12649 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12656 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12658 when Pragma_Suppress =>
12659 Process_Suppress_Unsuppress (True);
12665 -- pragma Suppress_All;
12667 -- The only check made here is that the pragma has no arguments.
12668 -- There are no placement rules, and the processing required (setting
12669 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12670 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12671 -- then creates and inserts a pragma Suppress (All_Checks).
12673 when Pragma_Suppress_All =>
12675 Check_Arg_Count (0);
12677 -------------------------
12678 -- Suppress_Debug_Info --
12679 -------------------------
12681 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12683 when Pragma_Suppress_Debug_Info =>
12685 Check_Arg_Count (1);
12686 Check_Optional_Identifier (Arg1, Name_Entity);
12687 Check_Arg_Is_Local_Name (Arg1);
12688 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)), Sense);
12690 ----------------------------------
12691 -- Suppress_Exception_Locations --
12692 ----------------------------------
12694 -- pragma Suppress_Exception_Locations;
12696 when Pragma_Suppress_Exception_Locations =>
12698 Check_Arg_Count (0);
12699 Check_Valid_Configuration_Pragma;
12700 Exception_Locations_Suppressed := True;
12702 -----------------------------
12703 -- Suppress_Initialization --
12704 -----------------------------
12706 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12708 when Pragma_Suppress_Initialization => Suppress_Init : declare
12714 Check_Arg_Count (1);
12715 Check_Optional_Identifier (Arg1, Name_Entity);
12716 Check_Arg_Is_Local_Name (Arg1);
12718 E_Id := Get_Pragma_Arg (Arg1);
12720 if Etype (E_Id) = Any_Type then
12724 E := Entity (E_Id);
12726 if Is_Type (E) then
12727 if Is_Incomplete_Or_Private_Type (E) then
12728 if No (Full_View (Base_Type (E))) then
12730 ("argument of pragma% cannot be an incomplete type",
12733 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12736 Set_Suppress_Init_Proc (Base_Type (E));
12741 ("pragma% requires argument that is a type name", Arg1);
12749 -- pragma System_Name (DIRECT_NAME);
12751 -- Syntax check: one argument, which must be the identifier GNAT or
12752 -- the identifier GCC, no other identifiers are acceptable.
12754 when Pragma_System_Name =>
12756 Check_No_Identifiers;
12757 Check_Arg_Count (1);
12758 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12760 -----------------------------
12761 -- Task_Dispatching_Policy --
12762 -----------------------------
12764 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12766 when Pragma_Task_Dispatching_Policy => declare
12770 Check_Ada_83_Warning;
12771 Check_Arg_Count (1);
12772 Check_No_Identifiers;
12773 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12774 Check_Valid_Configuration_Pragma;
12775 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12776 DP := Fold_Upper (Name_Buffer (1));
12778 if Task_Dispatching_Policy /= ' '
12779 and then Task_Dispatching_Policy /= DP
12781 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12783 ("task dispatching policy incompatible with policy#");
12785 -- Set new policy, but always preserve System_Location since we
12786 -- like the error message with the run time name.
12789 Task_Dispatching_Policy := DP;
12791 if Task_Dispatching_Policy_Sloc /= System_Location then
12792 Task_Dispatching_Policy_Sloc := Loc;
12801 -- pragma Task_Info (EXPRESSION);
12803 when Pragma_Task_Info => Task_Info : declare
12804 P : constant Node_Id := Parent (N);
12809 if Nkind (P) /= N_Task_Definition then
12810 Error_Pragma ("pragma% must appear in task definition");
12813 Check_No_Identifiers;
12814 Check_Arg_Count (1);
12816 Analyze_And_Resolve
12817 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12819 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12823 if Has_Task_Info_Pragma (P) then
12824 Error_Pragma ("duplicate pragma% not allowed");
12826 Set_Has_Task_Info_Pragma (P, True);
12834 -- pragma Task_Name (string_EXPRESSION);
12836 when Pragma_Task_Name => Task_Name : declare
12837 P : constant Node_Id := Parent (N);
12841 Check_No_Identifiers;
12842 Check_Arg_Count (1);
12844 Arg := Get_Pragma_Arg (Arg1);
12846 -- The expression is used in the call to Create_Task, and must be
12847 -- expanded there, not in the context of the current spec. It must
12848 -- however be analyzed to capture global references, in case it
12849 -- appears in a generic context.
12851 Preanalyze_And_Resolve (Arg, Standard_String);
12853 if Nkind (P) /= N_Task_Definition then
12857 if Has_Task_Name_Pragma (P) then
12858 Error_Pragma ("duplicate pragma% not allowed");
12860 Set_Has_Task_Name_Pragma (P, True);
12861 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12869 -- pragma Task_Storage (
12870 -- [Task_Type =>] LOCAL_NAME,
12871 -- [Top_Guard =>] static_integer_EXPRESSION);
12873 when Pragma_Task_Storage => Task_Storage : declare
12874 Args : Args_List (1 .. 2);
12875 Names : constant Name_List (1 .. 2) := (
12879 Task_Type : Node_Id renames Args (1);
12880 Top_Guard : Node_Id renames Args (2);
12886 Gather_Associations (Names, Args);
12888 if No (Task_Type) then
12890 ("missing task_type argument for pragma%");
12893 Check_Arg_Is_Local_Name (Task_Type);
12895 Ent := Entity (Task_Type);
12897 if not Is_Task_Type (Ent) then
12899 ("argument for pragma% must be task type", Task_Type);
12902 if No (Top_Guard) then
12904 ("pragma% takes two arguments", Task_Type);
12906 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12909 Check_First_Subtype (Task_Type);
12911 if Rep_Item_Too_Late (Ent, N) then
12916 --------------------------
12917 -- Thread_Local_Storage --
12918 --------------------------
12920 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12922 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
12928 Check_Arg_Count (1);
12929 Check_Optional_Identifier (Arg1, Name_Entity);
12930 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12932 Id := Get_Pragma_Arg (Arg1);
12935 if not Is_Entity_Name (Id)
12936 or else Ekind (Entity (Id)) /= E_Variable
12938 Error_Pragma_Arg ("local variable name required", Arg1);
12943 if Rep_Item_Too_Early (E, N)
12944 or else Rep_Item_Too_Late (E, N)
12949 Set_Has_Pragma_Thread_Local_Storage (E);
12950 Set_Has_Gigi_Rep_Item (E);
12951 end Thread_Local_Storage;
12957 -- pragma Time_Slice (static_duration_EXPRESSION);
12959 when Pragma_Time_Slice => Time_Slice : declare
12965 Check_Arg_Count (1);
12966 Check_No_Identifiers;
12967 Check_In_Main_Program;
12968 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
12970 if not Error_Posted (Arg1) then
12972 while Present (Nod) loop
12973 if Nkind (Nod) = N_Pragma
12974 and then Pragma_Name (Nod) = Name_Time_Slice
12976 Error_Msg_Name_1 := Pname;
12977 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12984 -- Process only if in main unit
12986 if Get_Source_Unit (Loc) = Main_Unit then
12987 Opt.Time_Slice_Set := True;
12988 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
12990 if Val <= Ureal_0 then
12991 Opt.Time_Slice_Value := 0;
12993 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
12994 Opt.Time_Slice_Value := 1_000_000_000;
12997 Opt.Time_Slice_Value :=
12998 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13007 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13009 -- TITLING_OPTION ::=
13010 -- [Title =>] STRING_LITERAL
13011 -- | [Subtitle =>] STRING_LITERAL
13013 when Pragma_Title => Title : declare
13014 Args : Args_List (1 .. 2);
13015 Names : constant Name_List (1 .. 2) := (
13021 Gather_Associations (Names, Args);
13024 for J in 1 .. 2 loop
13025 if Present (Args (J)) then
13026 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13031 ---------------------
13032 -- Unchecked_Union --
13033 ---------------------
13035 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13037 when Pragma_Unchecked_Union => Unchecked_Union : declare
13038 Assoc : constant Node_Id := Arg1;
13039 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13050 Check_No_Identifiers;
13051 Check_Arg_Count (1);
13052 Check_Arg_Is_Local_Name (Arg1);
13054 Find_Type (Type_Id);
13055 Typ := Entity (Type_Id);
13058 or else Rep_Item_Too_Early (Typ, N)
13062 Typ := Underlying_Type (Typ);
13065 if Rep_Item_Too_Late (Typ, N) then
13069 Check_First_Subtype (Arg1);
13071 -- Note remaining cases are references to a type in the current
13072 -- declarative part. If we find an error, we post the error on
13073 -- the relevant type declaration at an appropriate point.
13075 if not Is_Record_Type (Typ) then
13076 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13079 elsif Is_Tagged_Type (Typ) then
13080 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13083 elsif Is_Limited_Type (Typ) then
13085 ("Unchecked_Union must not be limited record type", Typ);
13086 Explain_Limited_Type (Typ, Typ);
13090 if not Has_Discriminants (Typ) then
13092 ("Unchecked_Union must have one discriminant", Typ);
13096 Discr := First_Discriminant (Typ);
13097 while Present (Discr) loop
13098 if No (Discriminant_Default_Value (Discr)) then
13100 ("Unchecked_Union discriminant must have default value",
13104 Next_Discriminant (Discr);
13107 Tdef := Type_Definition (Declaration_Node (Typ));
13108 Clist := Component_List (Tdef);
13110 Comp := First (Component_Items (Clist));
13111 while Present (Comp) loop
13112 Check_Component (Comp, Typ);
13116 if No (Clist) or else No (Variant_Part (Clist)) then
13118 ("Unchecked_Union must have variant part",
13123 Vpart := Variant_Part (Clist);
13125 Variant := First (Variants (Vpart));
13126 while Present (Variant) loop
13127 Check_Variant (Variant, Typ);
13132 Set_Is_Unchecked_Union (Typ, Sense);
13135 Set_Convention (Typ, Convention_C);
13138 Set_Has_Unchecked_Union (Base_Type (Typ), Sense);
13139 Set_Is_Unchecked_Union (Base_Type (Typ), Sense);
13140 end Unchecked_Union;
13142 ------------------------
13143 -- Unimplemented_Unit --
13144 ------------------------
13146 -- pragma Unimplemented_Unit;
13148 -- Note: this only gives an error if we are generating code, or if
13149 -- we are in a generic library unit (where the pragma appears in the
13150 -- body, not in the spec).
13152 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13153 Cunitent : constant Entity_Id :=
13154 Cunit_Entity (Get_Source_Unit (Loc));
13155 Ent_Kind : constant Entity_Kind :=
13160 Check_Arg_Count (0);
13162 if Operating_Mode = Generate_Code
13163 or else Ent_Kind = E_Generic_Function
13164 or else Ent_Kind = E_Generic_Procedure
13165 or else Ent_Kind = E_Generic_Package
13167 Get_Name_String (Chars (Cunitent));
13168 Set_Casing (Mixed_Case);
13169 Write_Str (Name_Buffer (1 .. Name_Len));
13170 Write_Str (" is not supported in this configuration");
13172 raise Unrecoverable_Error;
13174 end Unimplemented_Unit;
13176 ------------------------
13177 -- Universal_Aliasing --
13178 ------------------------
13180 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13182 when Pragma_Universal_Aliasing => Universal_Alias : declare
13187 Check_Arg_Count (1);
13188 Check_Optional_Identifier (Arg2, Name_Entity);
13189 Check_Arg_Is_Local_Name (Arg1);
13190 E_Id := Entity (Get_Pragma_Arg (Arg1));
13192 if E_Id = Any_Type then
13194 elsif No (E_Id) or else not Is_Type (E_Id) then
13195 Error_Pragma_Arg ("pragma% requires type", Arg1);
13198 Set_Universal_Aliasing (Implementation_Base_Type (E_Id), Sense);
13199 end Universal_Alias;
13201 --------------------
13202 -- Universal_Data --
13203 --------------------
13205 -- pragma Universal_Data [(library_unit_NAME)];
13207 when Pragma_Universal_Data =>
13210 -- If this is a configuration pragma, then set the universal
13211 -- addressing option, otherwise confirm that the pragma satisfies
13212 -- the requirements of library unit pragma placement and leave it
13213 -- to the GNAAMP back end to detect the pragma (avoids transitive
13214 -- setting of the option due to withed units).
13216 if Is_Configuration_Pragma then
13217 Universal_Addressing_On_AAMP := True;
13219 Check_Valid_Library_Unit_Pragma;
13222 if not AAMP_On_Target then
13223 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13230 -- pragma Unmodified (local_Name {, local_Name});
13232 when Pragma_Unmodified => Unmodified : declare
13233 Arg_Node : Node_Id;
13234 Arg_Expr : Node_Id;
13235 Arg_Ent : Entity_Id;
13239 Check_At_Least_N_Arguments (1);
13241 -- Loop through arguments
13244 while Present (Arg_Node) loop
13245 Check_No_Identifier (Arg_Node);
13247 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13248 -- in fact generate reference, so that the entity will have a
13249 -- reference, which will inhibit any warnings about it not
13250 -- being referenced, and also properly show up in the ali file
13251 -- as a reference. But this reference is recorded before the
13252 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13253 -- generated for this reference.
13255 Check_Arg_Is_Local_Name (Arg_Node);
13256 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13258 if Is_Entity_Name (Arg_Expr) then
13259 Arg_Ent := Entity (Arg_Expr);
13261 if not Is_Assignable (Arg_Ent) then
13263 ("pragma% can only be applied to a variable",
13266 Set_Has_Pragma_Unmodified (Arg_Ent, Sense);
13278 -- pragma Unreferenced (local_Name {, local_Name});
13280 -- or when used in a context clause:
13282 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13284 when Pragma_Unreferenced => Unreferenced : declare
13285 Arg_Node : Node_Id;
13286 Arg_Expr : Node_Id;
13287 Arg_Ent : Entity_Id;
13292 Check_At_Least_N_Arguments (1);
13294 -- Check case of appearing within context clause
13296 if Is_In_Context_Clause then
13298 -- The arguments must all be units mentioned in a with clause
13299 -- in the same context clause. Note we already checked (in
13300 -- Par.Prag) that the arguments are either identifiers or
13301 -- selected components.
13304 while Present (Arg_Node) loop
13305 Citem := First (List_Containing (N));
13306 while Citem /= N loop
13307 if Nkind (Citem) = N_With_Clause
13309 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13311 Set_Has_Pragma_Unreferenced
13314 (Library_Unit (Citem))));
13316 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13325 ("argument of pragma% is not with'ed unit", Arg_Node);
13331 -- Case of not in list of context items
13335 while Present (Arg_Node) loop
13336 Check_No_Identifier (Arg_Node);
13338 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13339 -- will in fact generate reference, so that the entity will
13340 -- have a reference, which will inhibit any warnings about
13341 -- it not being referenced, and also properly show up in the
13342 -- ali file as a reference. But this reference is recorded
13343 -- before the Has_Pragma_Unreferenced flag is set, so that
13344 -- no warning is generated for this reference.
13346 Check_Arg_Is_Local_Name (Arg_Node);
13347 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13349 if Is_Entity_Name (Arg_Expr) then
13350 Arg_Ent := Entity (Arg_Expr);
13352 -- If the entity is overloaded, the pragma applies to the
13353 -- most recent overloading, as documented. In this case,
13354 -- name resolution does not generate a reference, so it
13355 -- must be done here explicitly.
13357 if Is_Overloaded (Arg_Expr) then
13358 Generate_Reference (Arg_Ent, N);
13361 Set_Has_Pragma_Unreferenced (Arg_Ent, Sense);
13369 --------------------------
13370 -- Unreferenced_Objects --
13371 --------------------------
13373 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13375 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13376 Arg_Node : Node_Id;
13377 Arg_Expr : Node_Id;
13381 Check_At_Least_N_Arguments (1);
13384 while Present (Arg_Node) loop
13385 Check_No_Identifier (Arg_Node);
13386 Check_Arg_Is_Local_Name (Arg_Node);
13387 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13389 if not Is_Entity_Name (Arg_Expr)
13390 or else not Is_Type (Entity (Arg_Expr))
13393 ("argument for pragma% must be type or subtype", Arg_Node);
13396 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr), Sense);
13399 end Unreferenced_Objects;
13401 ------------------------------
13402 -- Unreserve_All_Interrupts --
13403 ------------------------------
13405 -- pragma Unreserve_All_Interrupts;
13407 when Pragma_Unreserve_All_Interrupts =>
13409 Check_Arg_Count (0);
13411 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13412 Unreserve_All_Interrupts := True;
13419 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13421 when Pragma_Unsuppress =>
13423 Process_Suppress_Unsuppress (False);
13425 -------------------
13426 -- Use_VADS_Size --
13427 -------------------
13429 -- pragma Use_VADS_Size;
13431 when Pragma_Use_VADS_Size =>
13433 Check_Arg_Count (0);
13434 Check_Valid_Configuration_Pragma;
13435 Use_VADS_Size := True;
13437 ---------------------
13438 -- Validity_Checks --
13439 ---------------------
13441 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13443 when Pragma_Validity_Checks => Validity_Checks : declare
13444 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13450 Check_Arg_Count (1);
13451 Check_No_Identifiers;
13453 if Nkind (A) = N_String_Literal then
13457 Slen : constant Natural := Natural (String_Length (S));
13458 Options : String (1 .. Slen);
13464 C := Get_String_Char (S, Int (J));
13465 exit when not In_Character_Range (C);
13466 Options (J) := Get_Character (C);
13469 Set_Validity_Check_Options (Options);
13477 elsif Nkind (A) = N_Identifier then
13479 if Chars (A) = Name_All_Checks then
13480 Set_Validity_Check_Options ("a");
13482 elsif Chars (A) = Name_On then
13483 Validity_Checks_On := True;
13485 elsif Chars (A) = Name_Off then
13486 Validity_Checks_On := False;
13490 end Validity_Checks;
13496 -- pragma Volatile (LOCAL_NAME);
13498 when Pragma_Volatile =>
13499 Process_Atomic_Shared_Volatile;
13501 -------------------------
13502 -- Volatile_Components --
13503 -------------------------
13505 -- pragma Volatile_Components (array_LOCAL_NAME);
13507 -- Volatile is handled by the same circuit as Atomic_Components
13513 -- pragma Warnings (On | Off);
13514 -- pragma Warnings (On | Off, LOCAL_NAME);
13515 -- pragma Warnings (static_string_EXPRESSION);
13516 -- pragma Warnings (On | Off, STRING_LITERAL);
13518 when Pragma_Warnings => Warnings : begin
13520 Check_At_Least_N_Arguments (1);
13521 Check_No_Identifiers;
13523 -- If debug flag -gnatd.i is set, pragma is ignored
13525 if Debug_Flag_Dot_I then
13529 -- Process various forms of the pragma
13532 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13535 -- One argument case
13537 if Arg_Count = 1 then
13539 -- On/Off one argument case was processed by parser
13541 if Nkind (Argx) = N_Identifier
13543 (Chars (Argx) = Name_On
13545 Chars (Argx) = Name_Off)
13549 -- One argument case must be ON/OFF or static string expr
13551 elsif not Is_Static_String_Expression (Arg1) then
13553 ("argument of pragma% must be On/Off or " &
13554 "static string expression", Arg1);
13556 -- One argument string expression case
13560 Lit : constant Node_Id := Expr_Value_S (Argx);
13561 Str : constant String_Id := Strval (Lit);
13562 Len : constant Nat := String_Length (Str);
13570 while J <= Len loop
13571 C := Get_String_Char (Str, J);
13572 OK := In_Character_Range (C);
13575 Chr := Get_Character (C);
13579 if J < Len and then Chr = '.' then
13581 C := Get_String_Char (Str, J);
13582 Chr := Get_Character (C);
13584 if not Set_Dot_Warning_Switch (Chr) then
13586 ("invalid warning switch character " &
13593 OK := Set_Warning_Switch (Chr);
13599 ("invalid warning switch character " & Chr,
13608 -- Two or more arguments (must be two)
13611 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13612 Check_At_Most_N_Arguments (2);
13620 E_Id := Get_Pragma_Arg (Arg2);
13623 -- In the expansion of an inlined body, a reference to
13624 -- the formal may be wrapped in a conversion if the
13625 -- actual is a conversion. Retrieve the real entity name.
13627 if (In_Instance_Body
13628 or else In_Inlined_Body)
13629 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13631 E_Id := Expression (E_Id);
13634 -- Entity name case
13636 if Is_Entity_Name (E_Id) then
13637 E := Entity (E_Id);
13644 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13647 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13648 and then Warn_On_Warnings_Off
13650 Warnings_Off_Pragmas.Append ((N, E));
13653 if Is_Enumeration_Type (E) then
13657 Lit := First_Literal (E);
13658 while Present (Lit) loop
13659 Set_Warnings_Off (Lit);
13660 Next_Literal (Lit);
13665 exit when No (Homonym (E));
13670 -- Error if not entity or static string literal case
13672 elsif not Is_Static_String_Expression (Arg2) then
13674 ("second argument of pragma% must be entity " &
13675 "name or static string expression", Arg2);
13677 -- String literal case
13680 String_To_Name_Buffer
13681 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13683 -- Note on configuration pragma case: If this is a
13684 -- configuration pragma, then for an OFF pragma, we
13685 -- just set Config True in the call, which is all
13686 -- that needs to be done. For the case of ON, this
13687 -- is normally an error, unless it is canceling the
13688 -- effect of a previous OFF pragma in the same file.
13689 -- In any other case, an error will be signalled (ON
13690 -- with no matching OFF).
13692 if Chars (Argx) = Name_Off then
13693 Set_Specific_Warning_Off
13694 (Loc, Name_Buffer (1 .. Name_Len),
13695 Config => Is_Configuration_Pragma);
13697 elsif Chars (Argx) = Name_On then
13698 Set_Specific_Warning_On
13699 (Loc, Name_Buffer (1 .. Name_Len), Err);
13703 ("?pragma Warnings On with no " &
13704 "matching Warnings Off",
13714 -------------------
13715 -- Weak_External --
13716 -------------------
13718 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13720 when Pragma_Weak_External => Weak_External : declare
13725 Check_Arg_Count (1);
13726 Check_Optional_Identifier (Arg1, Name_Entity);
13727 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13728 Ent := Entity (Get_Pragma_Arg (Arg1));
13730 if Rep_Item_Too_Early (Ent, N) then
13733 Ent := Underlying_Type (Ent);
13736 -- The only processing required is to link this item on to the
13737 -- list of rep items for the given entity. This is accomplished
13738 -- by the call to Rep_Item_Too_Late (when no error is detected
13739 -- and False is returned).
13741 if Rep_Item_Too_Late (Ent, N) then
13744 Set_Has_Gigi_Rep_Item (Ent);
13748 -----------------------------
13749 -- Wide_Character_Encoding --
13750 -----------------------------
13752 -- pragma Wide_Character_Encoding (IDENTIFIER);
13754 when Pragma_Wide_Character_Encoding =>
13757 -- Nothing to do, handled in parser. Note that we do not enforce
13758 -- configuration pragma placement, this pragma can appear at any
13759 -- place in the source, allowing mixed encodings within a single
13764 --------------------
13765 -- Unknown_Pragma --
13766 --------------------
13768 -- Should be impossible, since the case of an unknown pragma is
13769 -- separately processed before the case statement is entered.
13771 when Unknown_Pragma =>
13772 raise Program_Error;
13775 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13776 -- until AI is formally approved.
13778 -- Check_Order_Dependence;
13781 when Pragma_Exit => null;
13782 end Analyze_Pragma;
13784 -------------------
13785 -- Check_Enabled --
13786 -------------------
13788 function Check_Enabled (Nam : Name_Id) return Boolean is
13792 -- Loop through entries in check policy list
13794 PP := Opt.Check_Policy_List;
13796 -- If there are no specific entries that matched, then we let the
13797 -- setting of assertions govern. Note that this provides the needed
13798 -- compatibility with the RM for the cases of assertion, invariant,
13799 -- precondition, predicate, and postcondition.
13802 return Assertions_Enabled;
13804 -- Here we have an entry see if it matches
13808 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13811 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13812 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13813 when Name_On | Name_Check =>
13815 when Name_Off | Name_Ignore =>
13818 raise Program_Error;
13822 PP := Next_Pragma (PP);
13829 ---------------------------------
13830 -- Delay_Config_Pragma_Analyze --
13831 ---------------------------------
13833 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13835 return Pragma_Name (N) = Name_Interrupt_State
13837 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13838 end Delay_Config_Pragma_Analyze;
13840 -------------------------
13841 -- Get_Base_Subprogram --
13842 -------------------------
13844 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13845 Result : Entity_Id;
13848 -- Follow subprogram renaming chain
13851 while Is_Subprogram (Result)
13853 (Is_Generic_Instance (Result)
13854 or else Nkind (Parent (Declaration_Node (Result))) =
13855 N_Subprogram_Renaming_Declaration)
13856 and then Present (Alias (Result))
13858 Result := Alias (Result);
13862 end Get_Base_Subprogram;
13868 procedure Initialize is
13873 -----------------------------
13874 -- Is_Config_Static_String --
13875 -----------------------------
13877 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13879 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13880 -- This is an internal recursive function that is just like the outer
13881 -- function except that it adds the string to the name buffer rather
13882 -- than placing the string in the name buffer.
13884 ------------------------------
13885 -- Add_Config_Static_String --
13886 ------------------------------
13888 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13895 if Nkind (N) = N_Op_Concat then
13896 if Add_Config_Static_String (Left_Opnd (N)) then
13897 N := Right_Opnd (N);
13903 if Nkind (N) /= N_String_Literal then
13904 Error_Msg_N ("string literal expected for pragma argument", N);
13908 for J in 1 .. String_Length (Strval (N)) loop
13909 C := Get_String_Char (Strval (N), J);
13911 if not In_Character_Range (C) then
13913 ("string literal contains invalid wide character",
13914 Sloc (N) + 1 + Source_Ptr (J));
13918 Add_Char_To_Name_Buffer (Get_Character (C));
13923 end Add_Config_Static_String;
13925 -- Start of processing for Is_Config_Static_String
13930 return Add_Config_Static_String (Arg);
13931 end Is_Config_Static_String;
13933 -----------------------------------------
13934 -- Is_Non_Significant_Pragma_Reference --
13935 -----------------------------------------
13937 -- This function makes use of the following static table which indicates
13938 -- whether a given pragma is significant.
13940 -- -1 indicates that references in any argument position are significant
13941 -- 0 indicates that appearance in any argument is not significant
13942 -- +n indicates that appearance as argument n is significant, but all
13943 -- other arguments are not significant
13944 -- 99 special processing required (e.g. for pragma Check)
13946 Sig_Flags : constant array (Pragma_Id) of Int :=
13947 (Pragma_AST_Entry => -1,
13948 Pragma_Abort_Defer => -1,
13949 Pragma_Ada_83 => -1,
13950 Pragma_Ada_95 => -1,
13951 Pragma_Ada_05 => -1,
13952 Pragma_Ada_2005 => -1,
13953 Pragma_Ada_12 => -1,
13954 Pragma_Ada_2012 => -1,
13955 Pragma_All_Calls_Remote => -1,
13956 Pragma_Annotate => -1,
13957 Pragma_Assert => -1,
13958 Pragma_Assertion_Policy => 0,
13959 Pragma_Assume_No_Invalid_Values => 0,
13960 Pragma_Asynchronous => -1,
13961 Pragma_Atomic => 0,
13962 Pragma_Atomic_Components => 0,
13963 Pragma_Attach_Handler => -1,
13964 Pragma_Check => 99,
13965 Pragma_Check_Name => 0,
13966 Pragma_Check_Policy => 0,
13967 Pragma_CIL_Constructor => -1,
13968 Pragma_CPP_Class => 0,
13969 Pragma_CPP_Constructor => 0,
13970 Pragma_CPP_Virtual => 0,
13971 Pragma_CPP_Vtable => 0,
13973 Pragma_C_Pass_By_Copy => 0,
13974 Pragma_Comment => 0,
13975 Pragma_Common_Object => -1,
13976 Pragma_Compile_Time_Error => -1,
13977 Pragma_Compile_Time_Warning => -1,
13978 Pragma_Compiler_Unit => 0,
13979 Pragma_Complete_Representation => 0,
13980 Pragma_Complex_Representation => 0,
13981 Pragma_Component_Alignment => -1,
13982 Pragma_Controlled => 0,
13983 Pragma_Convention => 0,
13984 Pragma_Convention_Identifier => 0,
13985 Pragma_Debug => -1,
13986 Pragma_Debug_Policy => 0,
13987 Pragma_Detect_Blocking => -1,
13988 Pragma_Default_Storage_Pool => -1,
13989 Pragma_Dimension => -1,
13990 Pragma_Discard_Names => 0,
13991 Pragma_Elaborate => -1,
13992 Pragma_Elaborate_All => -1,
13993 Pragma_Elaborate_Body => -1,
13994 Pragma_Elaboration_Checks => -1,
13995 Pragma_Eliminate => -1,
13996 Pragma_Export => -1,
13997 Pragma_Export_Exception => -1,
13998 Pragma_Export_Function => -1,
13999 Pragma_Export_Object => -1,
14000 Pragma_Export_Procedure => -1,
14001 Pragma_Export_Value => -1,
14002 Pragma_Export_Valued_Procedure => -1,
14003 Pragma_Extend_System => -1,
14004 Pragma_Extensions_Allowed => -1,
14005 Pragma_External => -1,
14006 Pragma_Favor_Top_Level => -1,
14007 Pragma_External_Name_Casing => -1,
14008 Pragma_Fast_Math => -1,
14009 Pragma_Finalize_Storage_Only => 0,
14010 Pragma_Float_Representation => 0,
14011 Pragma_Ident => -1,
14012 Pragma_Implemented => -1,
14013 Pragma_Implicit_Packing => 0,
14014 Pragma_Import => +2,
14015 Pragma_Import_Exception => 0,
14016 Pragma_Import_Function => 0,
14017 Pragma_Import_Object => 0,
14018 Pragma_Import_Procedure => 0,
14019 Pragma_Import_Valued_Procedure => 0,
14020 Pragma_Independent => 0,
14021 Pragma_Independent_Components => 0,
14022 Pragma_Initialize_Scalars => -1,
14023 Pragma_Inline => 0,
14024 Pragma_Inline_Always => 0,
14025 Pragma_Inline_Generic => 0,
14026 Pragma_Inspection_Point => -1,
14027 Pragma_Interface => +2,
14028 Pragma_Interface_Name => +2,
14029 Pragma_Interrupt_Handler => -1,
14030 Pragma_Interrupt_Priority => -1,
14031 Pragma_Interrupt_State => -1,
14032 Pragma_Invariant => -1,
14033 Pragma_Java_Constructor => -1,
14034 Pragma_Java_Interface => -1,
14035 Pragma_Keep_Names => 0,
14036 Pragma_License => -1,
14037 Pragma_Link_With => -1,
14038 Pragma_Linker_Alias => -1,
14039 Pragma_Linker_Constructor => -1,
14040 Pragma_Linker_Destructor => -1,
14041 Pragma_Linker_Options => -1,
14042 Pragma_Linker_Section => -1,
14044 Pragma_Locking_Policy => -1,
14045 Pragma_Long_Float => -1,
14046 Pragma_Machine_Attribute => -1,
14048 Pragma_Main_Storage => -1,
14049 Pragma_Memory_Size => -1,
14050 Pragma_No_Return => 0,
14051 Pragma_No_Body => 0,
14052 Pragma_No_Run_Time => -1,
14053 Pragma_No_Strict_Aliasing => -1,
14054 Pragma_Normalize_Scalars => -1,
14055 Pragma_Obsolescent => 0,
14056 Pragma_Optimize => -1,
14057 Pragma_Optimize_Alignment => -1,
14058 Pragma_Ordered => 0,
14061 Pragma_Passive => -1,
14062 Pragma_Preelaborable_Initialization => -1,
14063 Pragma_Polling => -1,
14064 Pragma_Persistent_BSS => 0,
14065 Pragma_Postcondition => -1,
14066 Pragma_Precondition => -1,
14067 Pragma_Predicate => -1,
14068 Pragma_Preelaborate => -1,
14069 Pragma_Preelaborate_05 => -1,
14070 Pragma_Priority => -1,
14071 Pragma_Priority_Specific_Dispatching => -1,
14072 Pragma_Profile => 0,
14073 Pragma_Profile_Warnings => 0,
14074 Pragma_Propagate_Exceptions => -1,
14075 Pragma_Psect_Object => -1,
14077 Pragma_Pure_05 => -1,
14078 Pragma_Pure_Function => -1,
14079 Pragma_Queuing_Policy => -1,
14080 Pragma_Ravenscar => -1,
14081 Pragma_Relative_Deadline => -1,
14082 Pragma_Remote_Call_Interface => -1,
14083 Pragma_Remote_Types => -1,
14084 Pragma_Restricted_Run_Time => -1,
14085 Pragma_Restriction_Warnings => -1,
14086 Pragma_Restrictions => -1,
14087 Pragma_Reviewable => -1,
14088 Pragma_Short_Circuit_And_Or => -1,
14089 Pragma_Share_Generic => -1,
14090 Pragma_Shared => -1,
14091 Pragma_Shared_Passive => -1,
14092 Pragma_Short_Descriptors => 0,
14093 Pragma_Source_File_Name => -1,
14094 Pragma_Source_File_Name_Project => -1,
14095 Pragma_Source_Reference => -1,
14096 Pragma_SPARK_95 => -1,
14097 Pragma_Storage_Size => -1,
14098 Pragma_Storage_Unit => -1,
14099 Pragma_Static_Elaboration_Desired => -1,
14100 Pragma_Stream_Convert => -1,
14101 Pragma_Style_Checks => -1,
14102 Pragma_Subtitle => -1,
14103 Pragma_Suppress => 0,
14104 Pragma_Suppress_Exception_Locations => 0,
14105 Pragma_Suppress_All => -1,
14106 Pragma_Suppress_Debug_Info => 0,
14107 Pragma_Suppress_Initialization => 0,
14108 Pragma_System_Name => -1,
14109 Pragma_Task_Dispatching_Policy => -1,
14110 Pragma_Task_Info => -1,
14111 Pragma_Task_Name => -1,
14112 Pragma_Task_Storage => 0,
14113 Pragma_Thread_Local_Storage => 0,
14114 Pragma_Time_Slice => -1,
14115 Pragma_Title => -1,
14116 Pragma_Unchecked_Union => 0,
14117 Pragma_Unimplemented_Unit => -1,
14118 Pragma_Universal_Aliasing => -1,
14119 Pragma_Universal_Data => -1,
14120 Pragma_Unmodified => -1,
14121 Pragma_Unreferenced => -1,
14122 Pragma_Unreferenced_Objects => -1,
14123 Pragma_Unreserve_All_Interrupts => -1,
14124 Pragma_Unsuppress => 0,
14125 Pragma_Use_VADS_Size => -1,
14126 Pragma_Validity_Checks => -1,
14127 Pragma_Volatile => 0,
14128 Pragma_Volatile_Components => 0,
14129 Pragma_Warnings => -1,
14130 Pragma_Weak_External => -1,
14131 Pragma_Wide_Character_Encoding => 0,
14132 Unknown_Pragma => 0);
14134 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14143 if Nkind (P) /= N_Pragma_Argument_Association then
14147 Id := Get_Pragma_Id (Parent (P));
14148 C := Sig_Flags (Id);
14160 -- For pragma Check, the first argument is not significant,
14161 -- the second and the third (if present) arguments are
14164 when Pragma_Check =>
14166 P = First (Pragma_Argument_Associations (Parent (P)));
14169 raise Program_Error;
14173 A := First (Pragma_Argument_Associations (Parent (P)));
14174 for J in 1 .. C - 1 loop
14182 return A = P; -- is this wrong way round ???
14185 end Is_Non_Significant_Pragma_Reference;
14187 ------------------------------
14188 -- Is_Pragma_String_Literal --
14189 ------------------------------
14191 -- This function returns true if the corresponding pragma argument is a
14192 -- static string expression. These are the only cases in which string
14193 -- literals can appear as pragma arguments. We also allow a string literal
14194 -- as the first argument to pragma Assert (although it will of course
14195 -- always generate a type error).
14197 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14198 Pragn : constant Node_Id := Parent (Par);
14199 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14200 Pname : constant Name_Id := Pragma_Name (Pragn);
14206 N := First (Assoc);
14213 if Pname = Name_Assert then
14216 elsif Pname = Name_Export then
14219 elsif Pname = Name_Ident then
14222 elsif Pname = Name_Import then
14225 elsif Pname = Name_Interface_Name then
14228 elsif Pname = Name_Linker_Alias then
14231 elsif Pname = Name_Linker_Section then
14234 elsif Pname = Name_Machine_Attribute then
14237 elsif Pname = Name_Source_File_Name then
14240 elsif Pname = Name_Source_Reference then
14243 elsif Pname = Name_Title then
14246 elsif Pname = Name_Subtitle then
14252 end Is_Pragma_String_Literal;
14254 --------------------------------------
14255 -- Process_Compilation_Unit_Pragmas --
14256 --------------------------------------
14258 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14260 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14261 -- strange because it comes at the end of the unit. Rational has the
14262 -- same name for a pragma, but treats it as a program unit pragma, In
14263 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14264 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14265 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14266 -- the context clause to ensure the correct processing.
14268 if Has_Pragma_Suppress_All (N) then
14269 Prepend_To (Context_Items (N),
14270 Make_Pragma (Sloc (N),
14271 Chars => Name_Suppress,
14272 Pragma_Argument_Associations => New_List (
14273 Make_Pragma_Argument_Association (Sloc (N),
14274 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14277 -- Nothing else to do at the current time!
14279 end Process_Compilation_Unit_Pragmas;
14290 --------------------------------
14291 -- Set_Encoded_Interface_Name --
14292 --------------------------------
14294 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14295 Str : constant String_Id := Strval (S);
14296 Len : constant Int := String_Length (Str);
14301 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14304 -- Stores encoded value of character code CC. The encoding we use an
14305 -- underscore followed by four lower case hex digits.
14311 procedure Encode is
14313 Store_String_Char (Get_Char_Code ('_'));
14315 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14317 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14319 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14321 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14324 -- Start of processing for Set_Encoded_Interface_Name
14327 -- If first character is asterisk, this is a link name, and we leave it
14328 -- completely unmodified. We also ignore null strings (the latter case
14329 -- happens only in error cases) and no encoding should occur for Java or
14330 -- AAMP interface names.
14333 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14334 or else VM_Target /= No_VM
14335 or else AAMP_On_Target
14337 Set_Interface_Name (E, S);
14342 CC := Get_String_Char (Str, J);
14344 exit when not In_Character_Range (CC);
14346 C := Get_Character (CC);
14348 exit when C /= '_' and then C /= '$'
14349 and then C not in '0' .. '9'
14350 and then C not in 'a' .. 'z'
14351 and then C not in 'A' .. 'Z';
14354 Set_Interface_Name (E, S);
14362 -- Here we need to encode. The encoding we use as follows:
14363 -- three underscores + four hex digits (lower case)
14367 for J in 1 .. String_Length (Str) loop
14368 CC := Get_String_Char (Str, J);
14370 if not In_Character_Range (CC) then
14373 C := Get_Character (CC);
14375 if C = '_' or else C = '$'
14376 or else C in '0' .. '9'
14377 or else C in 'a' .. 'z'
14378 or else C in 'A' .. 'Z'
14380 Store_String_Char (CC);
14387 Set_Interface_Name (E,
14388 Make_String_Literal (Sloc (S),
14389 Strval => End_String));
14391 end Set_Encoded_Interface_Name;
14393 -------------------
14394 -- Set_Unit_Name --
14395 -------------------
14397 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14402 if Nkind (N) = N_Identifier
14403 and then Nkind (With_Item) = N_Identifier
14405 Set_Entity (N, Entity (With_Item));
14407 elsif Nkind (N) = N_Selected_Component then
14408 Change_Selected_Component_To_Expanded_Name (N);
14409 Set_Entity (N, Entity (With_Item));
14410 Set_Entity (Selector_Name (N), Entity (N));
14412 Pref := Prefix (N);
14413 Scop := Scope (Entity (N));
14414 while Nkind (Pref) = N_Selected_Component loop
14415 Change_Selected_Component_To_Expanded_Name (Pref);
14416 Set_Entity (Selector_Name (Pref), Scop);
14417 Set_Entity (Pref, Scop);
14418 Pref := Prefix (Pref);
14419 Scop := Scope (Scop);
14422 Set_Entity (Pref, Scop);