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 if not From_Aspect_Specification (N) then
4410 while Present (Homonym (Subp))
4411 and then Scope (Homonym (Subp)) = Current_Scope
4413 Make_Inline (Homonym (Subp));
4414 Subp := Homonym (Subp);
4422 ("inappropriate argument for pragma%", Assoc);
4425 and then Warn_On_Redundant_Constructs
4426 and then not Suppress_All_Inlining
4428 if Inlining_Not_Possible (Subp) then
4430 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4433 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4441 ----------------------------
4442 -- Process_Interface_Name --
4443 ----------------------------
4445 procedure Process_Interface_Name
4446 (Subprogram_Def : Entity_Id;
4452 String_Val : String_Id;
4454 procedure Check_Form_Of_Interface_Name
4456 Ext_Name_Case : Boolean);
4457 -- SN is a string literal node for an interface name. This routine
4458 -- performs some minimal checks that the name is reasonable. In
4459 -- particular that no spaces or other obviously incorrect characters
4460 -- appear. This is only a warning, since any characters are allowed.
4461 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4463 ----------------------------------
4464 -- Check_Form_Of_Interface_Name --
4465 ----------------------------------
4467 procedure Check_Form_Of_Interface_Name
4469 Ext_Name_Case : Boolean)
4471 S : constant String_Id := Strval (Expr_Value_S (SN));
4472 SL : constant Nat := String_Length (S);
4477 Error_Msg_N ("interface name cannot be null string", SN);
4480 for J in 1 .. SL loop
4481 C := Get_String_Char (S, J);
4483 -- Look for dubious character and issue unconditional warning.
4484 -- Definitely dubious if not in character range.
4486 if not In_Character_Range (C)
4488 -- For all cases except CLI target,
4489 -- commas, spaces and slashes are dubious (in CLI, we use
4490 -- commas and backslashes in external names to specify
4491 -- assembly version and public key, while slashes and spaces
4492 -- can be used in names to mark nested classes and
4495 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4496 and then (Get_Character (C) = ','
4498 Get_Character (C) = '\'))
4499 or else (VM_Target /= CLI_Target
4500 and then (Get_Character (C) = ' '
4502 Get_Character (C) = '/'))
4505 ("?interface name contains illegal character",
4506 Sloc (SN) + Source_Ptr (J));
4509 end Check_Form_Of_Interface_Name;
4511 -- Start of processing for Process_Interface_Name
4514 if No (Link_Arg) then
4515 if No (Ext_Arg) then
4516 if VM_Target = CLI_Target
4517 and then Ekind (Subprogram_Def) = E_Package
4518 and then Nkind (Parent (Subprogram_Def)) =
4519 N_Package_Specification
4520 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4525 (Generic_Parent (Parent (Subprogram_Def))));
4530 elsif Chars (Ext_Arg) = Name_Link_Name then
4532 Link_Nam := Expression (Ext_Arg);
4535 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4536 Ext_Nam := Expression (Ext_Arg);
4541 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4542 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4543 Ext_Nam := Expression (Ext_Arg);
4544 Link_Nam := Expression (Link_Arg);
4547 -- Check expressions for external name and link name are static
4549 if Present (Ext_Nam) then
4550 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4551 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4553 -- Verify that external name is not the name of a local entity,
4554 -- which would hide the imported one and could lead to run-time
4555 -- surprises. The problem can only arise for entities declared in
4556 -- a package body (otherwise the external name is fully qualified
4557 -- and will not conflict).
4565 if Prag_Id = Pragma_Import then
4566 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4568 E := Entity_Id (Get_Name_Table_Info (Nam));
4570 if Nam /= Chars (Subprogram_Def)
4571 and then Present (E)
4572 and then not Is_Overloadable (E)
4573 and then Is_Immediately_Visible (E)
4574 and then not Is_Imported (E)
4575 and then Ekind (Scope (E)) = E_Package
4578 while Present (Par) loop
4579 if Nkind (Par) = N_Package_Body then
4580 Error_Msg_Sloc := Sloc (E);
4582 ("imported entity is hidden by & declared#",
4587 Par := Parent (Par);
4594 if Present (Link_Nam) then
4595 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4596 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4599 -- If there is no link name, just set the external name
4601 if No (Link_Nam) then
4602 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4604 -- For the Link_Name case, the given literal is preceded by an
4605 -- asterisk, which indicates to GCC that the given name should be
4606 -- taken literally, and in particular that no prepending of
4607 -- underlines should occur, even in systems where this is the
4613 if VM_Target = No_VM then
4614 Store_String_Char (Get_Char_Code ('*'));
4617 String_Val := Strval (Expr_Value_S (Link_Nam));
4618 Store_String_Chars (String_Val);
4620 Make_String_Literal (Sloc (Link_Nam),
4621 Strval => End_String);
4624 Set_Encoded_Interface_Name
4625 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4627 -- We allow duplicated export names in CIL, as they are always
4628 -- enclosed in a namespace that differentiates them, and overloaded
4629 -- entities are supported by the VM.
4631 if Convention (Subprogram_Def) /= Convention_CIL then
4632 Check_Duplicated_Export_Name (Link_Nam);
4634 end Process_Interface_Name;
4636 -----------------------------------------
4637 -- Process_Interrupt_Or_Attach_Handler --
4638 -----------------------------------------
4640 procedure Process_Interrupt_Or_Attach_Handler is
4641 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4642 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4643 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4646 Set_Is_Interrupt_Handler (Handler_Proc);
4648 -- If the pragma is not associated with a handler procedure within a
4649 -- protected type, then it must be for a nonprotected procedure for
4650 -- the AAMP target, in which case we don't associate a representation
4651 -- item with the procedure's scope.
4653 if Ekind (Proc_Scope) = E_Protected_Type then
4654 if Prag_Id = Pragma_Interrupt_Handler
4656 Prag_Id = Pragma_Attach_Handler
4658 Record_Rep_Item (Proc_Scope, N);
4661 end Process_Interrupt_Or_Attach_Handler;
4663 --------------------------------------------------
4664 -- Process_Restrictions_Or_Restriction_Warnings --
4665 --------------------------------------------------
4667 -- Note: some of the simple identifier cases were handled in par-prag,
4668 -- but it is harmless (and more straightforward) to simply handle all
4669 -- cases here, even if it means we repeat a bit of work in some cases.
4671 procedure Process_Restrictions_Or_Restriction_Warnings
4675 R_Id : Restriction_Id;
4680 procedure Check_Unit_Name (N : Node_Id);
4681 -- Checks unit name parameter for No_Dependence. Returns if it has
4682 -- an appropriate form, otherwise raises pragma argument error.
4684 ---------------------
4685 -- Check_Unit_Name --
4686 ---------------------
4688 procedure Check_Unit_Name (N : Node_Id) is
4690 if Nkind (N) = N_Selected_Component then
4691 Check_Unit_Name (Prefix (N));
4692 Check_Unit_Name (Selector_Name (N));
4694 elsif Nkind (N) = N_Identifier then
4699 ("wrong form for unit name for No_Dependence", N);
4701 end Check_Unit_Name;
4703 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4706 -- Ignore all Restrictions pragma in CodePeer mode
4708 if CodePeer_Mode then
4712 Check_Ada_83_Warning;
4713 Check_At_Least_N_Arguments (1);
4714 Check_Valid_Configuration_Pragma;
4717 while Present (Arg) loop
4719 Expr := Get_Pragma_Arg (Arg);
4721 -- Case of no restriction identifier present
4723 if Id = No_Name then
4724 if Nkind (Expr) /= N_Identifier then
4726 ("invalid form for restriction", Arg);
4731 (Process_Restriction_Synonyms (Expr));
4733 if R_Id not in All_Boolean_Restrictions then
4734 Error_Msg_Name_1 := Pname;
4736 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4738 -- Check for possible misspelling
4740 for J in Restriction_Id loop
4742 Rnm : constant String := Restriction_Id'Image (J);
4745 Name_Buffer (1 .. Rnm'Length) := Rnm;
4746 Name_Len := Rnm'Length;
4747 Set_Casing (All_Lower_Case);
4749 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4751 (Identifier_Casing (Current_Source_File));
4752 Error_Msg_String (1 .. Rnm'Length) :=
4753 Name_Buffer (1 .. Name_Len);
4754 Error_Msg_Strlen := Rnm'Length;
4755 Error_Msg_N -- CODEFIX
4756 ("\possible misspelling of ""~""",
4757 Get_Pragma_Arg (Arg));
4766 if Implementation_Restriction (R_Id) then
4767 Check_Restriction (No_Implementation_Restrictions, Arg);
4770 -- If this is a warning, then set the warning unless we already
4771 -- have a real restriction active (we never want a warning to
4772 -- override a real restriction).
4775 if not Restriction_Active (R_Id) then
4776 Set_Restriction (R_Id, N);
4777 Restriction_Warnings (R_Id) := True;
4780 -- If real restriction case, then set it and make sure that the
4781 -- restriction warning flag is off, since a real restriction
4782 -- always overrides a warning.
4785 Set_Restriction (R_Id, N);
4786 Restriction_Warnings (R_Id) := False;
4789 -- Check for obsolescent restrictions in Ada 2005 mode
4792 and then Ada_Version >= Ada_2005
4793 and then (R_Id = No_Asynchronous_Control
4795 R_Id = No_Unchecked_Deallocation
4797 R_Id = No_Unchecked_Conversion)
4799 Check_Restriction (No_Obsolescent_Features, N);
4802 -- A very special case that must be processed here: pragma
4803 -- Restrictions (No_Exceptions) turns off all run-time
4804 -- checking. This is a bit dubious in terms of the formal
4805 -- language definition, but it is what is intended by RM
4806 -- H.4(12). Restriction_Warnings never affects generated code
4807 -- so this is done only in the real restriction case.
4809 if R_Id = No_Exceptions and then not Warn then
4810 Scope_Suppress := (others => True);
4813 -- Case of No_Dependence => unit-name. Note that the parser
4814 -- already made the necessary entry in the No_Dependence table.
4816 elsif Id = Name_No_Dependence then
4817 Check_Unit_Name (Expr);
4819 -- All other cases of restriction identifier present
4822 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4823 Analyze_And_Resolve (Expr, Any_Integer);
4825 if R_Id not in All_Parameter_Restrictions then
4827 ("invalid restriction parameter identifier", Arg);
4829 elsif not Is_OK_Static_Expression (Expr) then
4830 Flag_Non_Static_Expr
4831 ("value must be static expression!", Expr);
4834 elsif not Is_Integer_Type (Etype (Expr))
4835 or else Expr_Value (Expr) < 0
4838 ("value must be non-negative integer", Arg);
4841 -- Restriction pragma is active
4843 Val := Expr_Value (Expr);
4845 if not UI_Is_In_Int_Range (Val) then
4847 ("pragma ignored, value too large?", Arg);
4850 -- Warning case. If the real restriction is active, then we
4851 -- ignore the request, since warning never overrides a real
4852 -- restriction. Otherwise we set the proper warning. Note that
4853 -- this circuit sets the warning again if it is already set,
4854 -- which is what we want, since the constant may have changed.
4857 if not Restriction_Active (R_Id) then
4859 (R_Id, N, Integer (UI_To_Int (Val)));
4860 Restriction_Warnings (R_Id) := True;
4863 -- Real restriction case, set restriction and make sure warning
4864 -- flag is off since real restriction always overrides warning.
4867 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4868 Restriction_Warnings (R_Id) := False;
4874 end Process_Restrictions_Or_Restriction_Warnings;
4876 ---------------------------------
4877 -- Process_Suppress_Unsuppress --
4878 ---------------------------------
4880 -- Note: this procedure makes entries in the check suppress data
4881 -- structures managed by Sem. See spec of package Sem for full
4882 -- details on how we handle recording of check suppression.
4884 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4889 In_Package_Spec : constant Boolean :=
4890 Is_Package_Or_Generic_Package (Current_Scope)
4891 and then not In_Package_Body (Current_Scope);
4893 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4894 -- Used to suppress a single check on the given entity
4896 --------------------------------
4897 -- Suppress_Unsuppress_Echeck --
4898 --------------------------------
4900 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4902 Set_Checks_May_Be_Suppressed (E);
4904 if In_Package_Spec then
4905 Push_Global_Suppress_Stack_Entry
4908 Suppress => Suppress_Case);
4911 Push_Local_Suppress_Stack_Entry
4914 Suppress => Suppress_Case);
4917 -- If this is a first subtype, and the base type is distinct,
4918 -- then also set the suppress flags on the base type.
4920 if Is_First_Subtype (E)
4921 and then Etype (E) /= E
4923 Suppress_Unsuppress_Echeck (Etype (E), C);
4925 end Suppress_Unsuppress_Echeck;
4927 -- Start of processing for Process_Suppress_Unsuppress
4930 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
4931 -- we want to generate checks for analysis purposes, as set by -gnatC
4933 if CodePeer_Mode and then Comes_From_Source (N) then
4937 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4938 -- declarative part or a package spec (RM 11.5(5)).
4940 if not Is_Configuration_Pragma then
4941 Check_Is_In_Decl_Part_Or_Package_Spec;
4944 Check_At_Least_N_Arguments (1);
4945 Check_At_Most_N_Arguments (2);
4946 Check_No_Identifier (Arg1);
4947 Check_Arg_Is_Identifier (Arg1);
4949 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
4951 if C = No_Check_Id then
4953 ("argument of pragma% is not valid check name", Arg1);
4956 if not Suppress_Case
4957 and then (C = All_Checks or else C = Overflow_Check)
4959 Opt.Overflow_Checks_Unsuppressed := True;
4962 if Arg_Count = 1 then
4964 -- Make an entry in the local scope suppress table. This is the
4965 -- table that directly shows the current value of the scope
4966 -- suppress check for any check id value.
4968 if C = All_Checks then
4970 -- For All_Checks, we set all specific predefined checks with
4971 -- the exception of Elaboration_Check, which is handled
4972 -- specially because of not wanting All_Checks to have the
4973 -- effect of deactivating static elaboration order processing.
4975 for J in Scope_Suppress'Range loop
4976 if J /= Elaboration_Check then
4977 Scope_Suppress (J) := Suppress_Case;
4981 -- If not All_Checks, and predefined check, then set appropriate
4982 -- scope entry. Note that we will set Elaboration_Check if this
4983 -- is explicitly specified.
4985 elsif C in Predefined_Check_Id then
4986 Scope_Suppress (C) := Suppress_Case;
4989 -- Also make an entry in the Local_Entity_Suppress table
4991 Push_Local_Suppress_Stack_Entry
4994 Suppress => Suppress_Case);
4996 -- Case of two arguments present, where the check is suppressed for
4997 -- a specified entity (given as the second argument of the pragma)
5000 -- This is obsolescent in Ada 2005 mode
5002 if Ada_Version >= Ada_2005 then
5003 Check_Restriction (No_Obsolescent_Features, Arg2);
5006 Check_Optional_Identifier (Arg2, Name_On);
5007 E_Id := Get_Pragma_Arg (Arg2);
5010 if not Is_Entity_Name (E_Id) then
5012 ("second argument of pragma% must be entity name", Arg2);
5021 -- Enforce RM 11.5(7) which requires that for a pragma that
5022 -- appears within a package spec, the named entity must be
5023 -- within the package spec. We allow the package name itself
5024 -- to be mentioned since that makes sense, although it is not
5025 -- strictly allowed by 11.5(7).
5028 and then E /= Current_Scope
5029 and then Scope (E) /= Current_Scope
5032 ("entity in pragma% is not in package spec (RM 11.5(7))",
5036 -- Loop through homonyms. As noted below, in the case of a package
5037 -- spec, only homonyms within the package spec are considered.
5040 Suppress_Unsuppress_Echeck (E, C);
5042 if Is_Generic_Instance (E)
5043 and then Is_Subprogram (E)
5044 and then Present (Alias (E))
5046 Suppress_Unsuppress_Echeck (Alias (E), C);
5049 -- Move to next homonym if not aspect spec case
5051 exit when From_Aspect_Specification (N);
5055 -- If we are within a package specification, the pragma only
5056 -- applies to homonyms in the same scope.
5058 exit when In_Package_Spec
5059 and then Scope (E) /= Current_Scope;
5062 end Process_Suppress_Unsuppress;
5068 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5070 if Is_Imported (E) then
5072 ("cannot export entity& that was previously imported", Arg);
5074 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5076 ("cannot export entity& that has an address clause", Arg);
5079 Set_Is_Exported (E);
5081 -- Generate a reference for entity explicitly, because the
5082 -- identifier may be overloaded and name resolution will not
5085 Generate_Reference (E, Arg);
5087 -- Deal with exporting non-library level entity
5089 if not Is_Library_Level_Entity (E) then
5091 -- Not allowed at all for subprograms
5093 if Is_Subprogram (E) then
5094 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5096 -- Otherwise set public and statically allocated
5100 Set_Is_Statically_Allocated (E);
5102 -- Warn if the corresponding W flag is set and the pragma comes
5103 -- from source. The latter may not be true e.g. on VMS where we
5104 -- expand export pragmas for exception codes associated with
5105 -- imported or exported exceptions. We do not want to generate
5106 -- a warning for something that the user did not write.
5108 if Warn_On_Export_Import
5109 and then Comes_From_Source (Arg)
5112 ("?& has been made static as a result of Export", Arg, E);
5114 ("\this usage is non-standard and non-portable", Arg);
5119 if Warn_On_Export_Import and then Is_Type (E) then
5120 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5123 if Warn_On_Export_Import and Inside_A_Generic then
5125 ("all instances of& will have the same external name?", Arg, E);
5129 ----------------------------------------------
5130 -- Set_Extended_Import_Export_External_Name --
5131 ----------------------------------------------
5133 procedure Set_Extended_Import_Export_External_Name
5134 (Internal_Ent : Entity_Id;
5135 Arg_External : Node_Id)
5137 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5141 if No (Arg_External) then
5145 Check_Arg_Is_External_Name (Arg_External);
5147 if Nkind (Arg_External) = N_String_Literal then
5148 if String_Length (Strval (Arg_External)) = 0 then
5151 New_Name := Adjust_External_Name_Case (Arg_External);
5154 elsif Nkind (Arg_External) = N_Identifier then
5155 New_Name := Get_Default_External_Name (Arg_External);
5157 -- Check_Arg_Is_External_Name should let through only identifiers and
5158 -- string literals or static string expressions (which are folded to
5159 -- string literals).
5162 raise Program_Error;
5165 -- If we already have an external name set (by a prior normal Import
5166 -- or Export pragma), then the external names must match
5168 if Present (Interface_Name (Internal_Ent)) then
5169 Check_Matching_Internal_Names : declare
5170 S1 : constant String_Id := Strval (Old_Name);
5171 S2 : constant String_Id := Strval (New_Name);
5174 -- Called if names do not match
5180 procedure Mismatch is
5182 Error_Msg_Sloc := Sloc (Old_Name);
5184 ("external name does not match that given #",
5188 -- Start of processing for Check_Matching_Internal_Names
5191 if String_Length (S1) /= String_Length (S2) then
5195 for J in 1 .. String_Length (S1) loop
5196 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5201 end Check_Matching_Internal_Names;
5203 -- Otherwise set the given name
5206 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5207 Check_Duplicated_Export_Name (New_Name);
5209 end Set_Extended_Import_Export_External_Name;
5215 procedure Set_Imported (E : Entity_Id) is
5217 -- Error message if already imported or exported
5219 if Is_Exported (E) or else Is_Imported (E) then
5221 -- Error if being set Exported twice
5223 if Is_Exported (E) then
5224 Error_Msg_NE ("entity& was previously exported", N, E);
5226 -- OK if Import/Interface case
5228 elsif Import_Interface_Present (N) then
5231 -- Error if being set Imported twice
5234 Error_Msg_NE ("entity& was previously imported", N, E);
5237 Error_Msg_Name_1 := Pname;
5239 ("\(pragma% applies to all previous entities)", N);
5241 Error_Msg_Sloc := Sloc (E);
5242 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5244 -- Here if not previously imported or exported, OK to import
5247 Set_Is_Imported (E);
5249 -- If the entity is an object that is not at the library level,
5250 -- then it is statically allocated. We do not worry about objects
5251 -- with address clauses in this context since they are not really
5252 -- imported in the linker sense.
5255 and then not Is_Library_Level_Entity (E)
5256 and then No (Address_Clause (E))
5258 Set_Is_Statically_Allocated (E);
5265 -------------------------
5266 -- Set_Mechanism_Value --
5267 -------------------------
5269 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5270 -- analyzed, since it is semantic nonsense), so we get it in the exact
5271 -- form created by the parser.
5273 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5276 Mech_Name_Id : Name_Id;
5278 procedure Bad_Class;
5279 -- Signal bad descriptor class name
5281 procedure Bad_Mechanism;
5282 -- Signal bad mechanism name
5288 procedure Bad_Class is
5290 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5293 -------------------------
5294 -- Bad_Mechanism_Value --
5295 -------------------------
5297 procedure Bad_Mechanism is
5299 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5302 -- Start of processing for Set_Mechanism_Value
5305 if Mechanism (Ent) /= Default_Mechanism then
5307 ("mechanism for & has already been set", Mech_Name, Ent);
5310 -- MECHANISM_NAME ::= value | reference | descriptor |
5313 if Nkind (Mech_Name) = N_Identifier then
5314 if Chars (Mech_Name) = Name_Value then
5315 Set_Mechanism (Ent, By_Copy);
5318 elsif Chars (Mech_Name) = Name_Reference then
5319 Set_Mechanism (Ent, By_Reference);
5322 elsif Chars (Mech_Name) = Name_Descriptor then
5323 Check_VMS (Mech_Name);
5325 -- Descriptor => Short_Descriptor if pragma was given
5327 if Short_Descriptors then
5328 Set_Mechanism (Ent, By_Short_Descriptor);
5330 Set_Mechanism (Ent, By_Descriptor);
5335 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5336 Check_VMS (Mech_Name);
5337 Set_Mechanism (Ent, By_Short_Descriptor);
5340 elsif Chars (Mech_Name) = Name_Copy then
5342 ("bad mechanism name, Value assumed", Mech_Name);
5348 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5349 -- short_descriptor (CLASS_NAME)
5350 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5352 -- Note: this form is parsed as an indexed component
5354 elsif Nkind (Mech_Name) = N_Indexed_Component then
5355 Class := First (Expressions (Mech_Name));
5357 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5358 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5359 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5360 or else Present (Next (Class))
5364 Mech_Name_Id := Chars (Prefix (Mech_Name));
5366 -- Change Descriptor => Short_Descriptor if pragma was given
5368 if Mech_Name_Id = Name_Descriptor
5369 and then Short_Descriptors
5371 Mech_Name_Id := Name_Short_Descriptor;
5375 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5376 -- short_descriptor (Class => CLASS_NAME)
5377 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5379 -- Note: this form is parsed as a function call
5381 elsif Nkind (Mech_Name) = N_Function_Call then
5382 Param := First (Parameter_Associations (Mech_Name));
5384 if Nkind (Name (Mech_Name)) /= N_Identifier
5385 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5386 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5387 or else Present (Next (Param))
5388 or else No (Selector_Name (Param))
5389 or else Chars (Selector_Name (Param)) /= Name_Class
5393 Class := Explicit_Actual_Parameter (Param);
5394 Mech_Name_Id := Chars (Name (Mech_Name));
5401 -- Fall through here with Class set to descriptor class name
5403 Check_VMS (Mech_Name);
5405 if Nkind (Class) /= N_Identifier then
5408 elsif Mech_Name_Id = Name_Descriptor
5409 and then Chars (Class) = Name_UBS
5411 Set_Mechanism (Ent, By_Descriptor_UBS);
5413 elsif Mech_Name_Id = Name_Descriptor
5414 and then Chars (Class) = Name_UBSB
5416 Set_Mechanism (Ent, By_Descriptor_UBSB);
5418 elsif Mech_Name_Id = Name_Descriptor
5419 and then Chars (Class) = Name_UBA
5421 Set_Mechanism (Ent, By_Descriptor_UBA);
5423 elsif Mech_Name_Id = Name_Descriptor
5424 and then Chars (Class) = Name_S
5426 Set_Mechanism (Ent, By_Descriptor_S);
5428 elsif Mech_Name_Id = Name_Descriptor
5429 and then Chars (Class) = Name_SB
5431 Set_Mechanism (Ent, By_Descriptor_SB);
5433 elsif Mech_Name_Id = Name_Descriptor
5434 and then Chars (Class) = Name_A
5436 Set_Mechanism (Ent, By_Descriptor_A);
5438 elsif Mech_Name_Id = Name_Descriptor
5439 and then Chars (Class) = Name_NCA
5441 Set_Mechanism (Ent, By_Descriptor_NCA);
5443 elsif Mech_Name_Id = Name_Short_Descriptor
5444 and then Chars (Class) = Name_UBS
5446 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5448 elsif Mech_Name_Id = Name_Short_Descriptor
5449 and then Chars (Class) = Name_UBSB
5451 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5453 elsif Mech_Name_Id = Name_Short_Descriptor
5454 and then Chars (Class) = Name_UBA
5456 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5458 elsif Mech_Name_Id = Name_Short_Descriptor
5459 and then Chars (Class) = Name_S
5461 Set_Mechanism (Ent, By_Short_Descriptor_S);
5463 elsif Mech_Name_Id = Name_Short_Descriptor
5464 and then Chars (Class) = Name_SB
5466 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5468 elsif Mech_Name_Id = Name_Short_Descriptor
5469 and then Chars (Class) = Name_A
5471 Set_Mechanism (Ent, By_Short_Descriptor_A);
5473 elsif Mech_Name_Id = Name_Short_Descriptor
5474 and then Chars (Class) = Name_NCA
5476 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5481 end Set_Mechanism_Value;
5483 ---------------------------
5484 -- Set_Ravenscar_Profile --
5485 ---------------------------
5487 -- The tasks to be done here are
5489 -- Set required policies
5491 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5492 -- pragma Locking_Policy (Ceiling_Locking)
5494 -- Set Detect_Blocking mode
5496 -- Set required restrictions (see System.Rident for detailed list)
5498 -- Set the No_Dependence rules
5499 -- No_Dependence => Ada.Asynchronous_Task_Control
5500 -- No_Dependence => Ada.Calendar
5501 -- No_Dependence => Ada.Execution_Time.Group_Budget
5502 -- No_Dependence => Ada.Execution_Time.Timers
5503 -- No_Dependence => Ada.Task_Attributes
5504 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5506 procedure Set_Ravenscar_Profile (N : Node_Id) is
5507 Prefix_Entity : Entity_Id;
5508 Selector_Entity : Entity_Id;
5509 Prefix_Node : Node_Id;
5513 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5515 if Task_Dispatching_Policy /= ' '
5516 and then Task_Dispatching_Policy /= 'F'
5518 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5519 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5521 -- Set the FIFO_Within_Priorities policy, but always preserve
5522 -- System_Location since we like the error message with the run time
5526 Task_Dispatching_Policy := 'F';
5528 if Task_Dispatching_Policy_Sloc /= System_Location then
5529 Task_Dispatching_Policy_Sloc := Loc;
5533 -- pragma Locking_Policy (Ceiling_Locking)
5535 if Locking_Policy /= ' '
5536 and then Locking_Policy /= 'C'
5538 Error_Msg_Sloc := Locking_Policy_Sloc;
5539 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5541 -- Set the Ceiling_Locking policy, but preserve System_Location since
5542 -- we like the error message with the run time name.
5545 Locking_Policy := 'C';
5547 if Locking_Policy_Sloc /= System_Location then
5548 Locking_Policy_Sloc := Loc;
5552 -- pragma Detect_Blocking
5554 Detect_Blocking := True;
5556 -- Set the corresponding restrictions
5558 Set_Profile_Restrictions
5559 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5561 -- Set the No_Dependence restrictions
5563 -- The following No_Dependence restrictions:
5564 -- No_Dependence => Ada.Asynchronous_Task_Control
5565 -- No_Dependence => Ada.Calendar
5566 -- No_Dependence => Ada.Task_Attributes
5567 -- are already set by previous call to Set_Profile_Restrictions.
5569 -- Set the following restrictions which were added to Ada 2005:
5570 -- No_Dependence => Ada.Execution_Time.Group_Budget
5571 -- No_Dependence => Ada.Execution_Time.Timers
5573 if Ada_Version >= Ada_2005 then
5574 Name_Buffer (1 .. 3) := "ada";
5577 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5579 Name_Buffer (1 .. 14) := "execution_time";
5582 Selector_Entity := Make_Identifier (Loc, Name_Find);
5585 Make_Selected_Component
5587 Prefix => Prefix_Entity,
5588 Selector_Name => Selector_Entity);
5590 Name_Buffer (1 .. 13) := "group_budgets";
5593 Selector_Entity := Make_Identifier (Loc, Name_Find);
5596 Make_Selected_Component
5598 Prefix => Prefix_Node,
5599 Selector_Name => Selector_Entity);
5601 Set_Restriction_No_Dependence
5603 Warn => Treat_Restrictions_As_Warnings,
5604 Profile => Ravenscar);
5606 Name_Buffer (1 .. 6) := "timers";
5609 Selector_Entity := Make_Identifier (Loc, Name_Find);
5612 Make_Selected_Component
5614 Prefix => Prefix_Node,
5615 Selector_Name => Selector_Entity);
5617 Set_Restriction_No_Dependence
5619 Warn => Treat_Restrictions_As_Warnings,
5620 Profile => Ravenscar);
5623 -- Set the following restrictions which was added to Ada 2012 (see
5625 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5627 if Ada_Version >= Ada_2012 then
5628 Name_Buffer (1 .. 6) := "system";
5631 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5633 Name_Buffer (1 .. 15) := "multiprocessors";
5636 Selector_Entity := Make_Identifier (Loc, Name_Find);
5639 Make_Selected_Component
5641 Prefix => Prefix_Entity,
5642 Selector_Name => Selector_Entity);
5644 Name_Buffer (1 .. 19) := "dispatching_domains";
5647 Selector_Entity := Make_Identifier (Loc, Name_Find);
5650 Make_Selected_Component
5652 Prefix => Prefix_Node,
5653 Selector_Name => Selector_Entity);
5655 Set_Restriction_No_Dependence
5657 Warn => Treat_Restrictions_As_Warnings,
5658 Profile => Ravenscar);
5660 end Set_Ravenscar_Profile;
5662 -- Start of processing for Analyze_Pragma
5665 -- Deal with unrecognized pragma
5667 if not Is_Pragma_Name (Pname) then
5668 if Warn_On_Unrecognized_Pragma then
5669 Error_Msg_Name_1 := Pname;
5670 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5672 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5673 if Is_Bad_Spelling_Of (Pname, PN) then
5674 Error_Msg_Name_1 := PN;
5675 Error_Msg_N -- CODEFIX
5676 ("\?possible misspelling of %!", Pragma_Identifier (N));
5685 -- Here to start processing for recognized pragma
5687 Prag_Id := Get_Pragma_Id (Pname);
5697 if Present (Pragma_Argument_Associations (N)) then
5698 Arg_Count := List_Length (Pragma_Argument_Associations (N));
5699 Arg1 := First (Pragma_Argument_Associations (N));
5701 if Present (Arg1) then
5702 Arg2 := Next (Arg1);
5704 if Present (Arg2) then
5705 Arg3 := Next (Arg2);
5707 if Present (Arg3) then
5708 Arg4 := Next (Arg3);
5714 -- An enumeration type defines the pragmas that are supported by the
5715 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5716 -- into the corresponding enumeration value for the following case.
5724 -- pragma Abort_Defer;
5726 when Pragma_Abort_Defer =>
5728 Check_Arg_Count (0);
5730 -- The only required semantic processing is to check the
5731 -- placement. This pragma must appear at the start of the
5732 -- statement sequence of a handled sequence of statements.
5734 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5735 or else N /= First (Statements (Parent (N)))
5746 -- Note: this pragma also has some specific processing in Par.Prag
5747 -- because we want to set the Ada version mode during parsing.
5749 when Pragma_Ada_83 =>
5751 Check_Arg_Count (0);
5753 -- We really should check unconditionally for proper configuration
5754 -- pragma placement, since we really don't want mixed Ada modes
5755 -- within a single unit, and the GNAT reference manual has always
5756 -- said this was a configuration pragma, but we did not check and
5757 -- are hesitant to add the check now.
5759 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5760 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5761 -- or Ada 2012 mode.
5763 if Ada_Version >= Ada_2005 then
5764 Check_Valid_Configuration_Pragma;
5767 -- Now set Ada 83 mode
5769 Ada_Version := Ada_83;
5770 Ada_Version_Explicit := Ada_Version;
5778 -- Note: this pragma also has some specific processing in Par.Prag
5779 -- because we want to set the Ada 83 version mode during parsing.
5781 when Pragma_Ada_95 =>
5783 Check_Arg_Count (0);
5785 -- We really should check unconditionally for proper configuration
5786 -- pragma placement, since we really don't want mixed Ada modes
5787 -- within a single unit, and the GNAT reference manual has always
5788 -- said this was a configuration pragma, but we did not check and
5789 -- are hesitant to add the check now.
5791 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5792 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5794 if Ada_Version >= Ada_2005 then
5795 Check_Valid_Configuration_Pragma;
5798 -- Now set Ada 95 mode
5800 Ada_Version := Ada_95;
5801 Ada_Version_Explicit := Ada_Version;
5803 ---------------------
5804 -- Ada_05/Ada_2005 --
5805 ---------------------
5808 -- pragma Ada_05 (LOCAL_NAME);
5811 -- pragma Ada_2005 (LOCAL_NAME):
5813 -- Note: these pragmas also have some specific processing in Par.Prag
5814 -- because we want to set the Ada 2005 version mode during parsing.
5816 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5822 if Arg_Count = 1 then
5823 Check_Arg_Is_Local_Name (Arg1);
5824 E_Id := Get_Pragma_Arg (Arg1);
5826 if Etype (E_Id) = Any_Type then
5830 Set_Is_Ada_2005_Only (Entity (E_Id));
5833 Check_Arg_Count (0);
5835 -- For Ada_2005 we unconditionally enforce the documented
5836 -- configuration pragma placement, since we do not want to
5837 -- tolerate mixed modes in a unit involving Ada 2005. That
5838 -- would cause real difficulties for those cases where there
5839 -- are incompatibilities between Ada 95 and Ada 2005.
5841 Check_Valid_Configuration_Pragma;
5843 -- Now set appropriate Ada mode
5846 Ada_Version := Ada_2005;
5848 Ada_Version := Ada_Version_Default;
5851 Ada_Version_Explicit := Ada_2005;
5855 ---------------------
5856 -- Ada_12/Ada_2012 --
5857 ---------------------
5860 -- pragma Ada_12 (LOCAL_NAME);
5863 -- pragma Ada_2012 (LOCAL_NAME):
5865 -- Note: these pragmas also have some specific processing in Par.Prag
5866 -- because we want to set the Ada 2012 version mode during parsing.
5868 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5874 if Arg_Count = 1 then
5875 Check_Arg_Is_Local_Name (Arg1);
5876 E_Id := Get_Pragma_Arg (Arg1);
5878 if Etype (E_Id) = Any_Type then
5882 Set_Is_Ada_2012_Only (Entity (E_Id));
5885 Check_Arg_Count (0);
5887 -- For Ada_2012 we unconditionally enforce the documented
5888 -- configuration pragma placement, since we do not want to
5889 -- tolerate mixed modes in a unit involving Ada 2012. That
5890 -- would cause real difficulties for those cases where there
5891 -- are incompatibilities between Ada 95 and Ada 2012. We could
5892 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5894 Check_Valid_Configuration_Pragma;
5896 -- Now set appropriate Ada mode
5899 Ada_Version := Ada_2012;
5901 Ada_Version := Ada_Version_Default;
5904 Ada_Version_Explicit := Ada_2012;
5908 ----------------------
5909 -- All_Calls_Remote --
5910 ----------------------
5912 -- pragma All_Calls_Remote [(library_package_NAME)];
5914 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5915 Lib_Entity : Entity_Id;
5918 Check_Ada_83_Warning;
5919 Check_Valid_Library_Unit_Pragma;
5921 if Nkind (N) = N_Null_Statement then
5925 Lib_Entity := Find_Lib_Unit_Name;
5927 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5929 if Present (Lib_Entity)
5930 and then not Debug_Flag_U
5932 if not Is_Remote_Call_Interface (Lib_Entity) then
5933 Error_Pragma ("pragma% only apply to rci unit");
5935 -- Set flag for entity of the library unit
5938 Set_Has_All_Calls_Remote (Lib_Entity);
5942 end All_Calls_Remote;
5948 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
5949 -- ARG ::= NAME | EXPRESSION
5951 -- The first two arguments are by convention intended to refer to an
5952 -- external tool and a tool-specific function. These arguments are
5955 when Pragma_Annotate => Annotate : begin
5957 Check_At_Least_N_Arguments (1);
5958 Check_Arg_Is_Identifier (Arg1);
5959 Check_No_Identifiers;
5967 -- Second unanalyzed parameter is optional
5973 while Present (Arg) loop
5974 Exp := Get_Pragma_Arg (Arg);
5977 if Is_Entity_Name (Exp) then
5980 -- For string literals, we assume Standard_String as the
5981 -- type, unless the string contains wide or wide_wide
5984 elsif Nkind (Exp) = N_String_Literal then
5985 if Has_Wide_Wide_Character (Exp) then
5986 Resolve (Exp, Standard_Wide_Wide_String);
5987 elsif Has_Wide_Character (Exp) then
5988 Resolve (Exp, Standard_Wide_String);
5990 Resolve (Exp, Standard_String);
5993 elsif Is_Overloaded (Exp) then
5995 ("ambiguous argument for pragma%", Exp);
6011 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6012 -- [, [Message =>] Static_String_EXPRESSION]);
6014 when Pragma_Assert => Assert : declare
6020 Check_At_Least_N_Arguments (1);
6021 Check_At_Most_N_Arguments (2);
6022 Check_Arg_Order ((Name_Check, Name_Message));
6023 Check_Optional_Identifier (Arg1, Name_Check);
6025 -- We treat pragma Assert as equivalent to:
6027 -- pragma Check (Assertion, condition [, msg]);
6029 -- So rewrite pragma in this manner, and analyze the result
6031 Expr := Get_Pragma_Arg (Arg1);
6033 Make_Pragma_Argument_Association (Loc,
6034 Expression => Make_Identifier (Loc, Name_Assertion)),
6036 Make_Pragma_Argument_Association (Sloc (Expr),
6037 Expression => Expr));
6039 if Arg_Count > 1 then
6040 Check_Optional_Identifier (Arg2, Name_Message);
6041 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6042 Append_To (Newa, Relocate_Node (Arg2));
6047 Chars => Name_Check,
6048 Pragma_Argument_Associations => Newa));
6052 ----------------------
6053 -- Assertion_Policy --
6054 ----------------------
6056 -- pragma Assertion_Policy (Check | Ignore)
6058 when Pragma_Assertion_Policy => Assertion_Policy : declare
6063 Check_Valid_Configuration_Pragma;
6064 Check_Arg_Count (1);
6065 Check_No_Identifiers;
6066 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6068 -- We treat pragma Assertion_Policy as equivalent to:
6070 -- pragma Check_Policy (Assertion, policy)
6072 -- So rewrite the pragma in that manner and link on to the chain
6073 -- of Check_Policy pragmas, marking the pragma as analyzed.
6075 Policy := Get_Pragma_Arg (Arg1);
6079 Chars => Name_Check_Policy,
6081 Pragma_Argument_Associations => New_List (
6082 Make_Pragma_Argument_Association (Loc,
6083 Expression => Make_Identifier (Loc, Name_Assertion)),
6085 Make_Pragma_Argument_Association (Loc,
6087 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6090 Set_Next_Pragma (N, Opt.Check_Policy_List);
6091 Opt.Check_Policy_List := N;
6092 end Assertion_Policy;
6094 ------------------------------
6095 -- Assume_No_Invalid_Values --
6096 ------------------------------
6098 -- pragma Assume_No_Invalid_Values (On | Off);
6100 when Pragma_Assume_No_Invalid_Values =>
6102 Check_Valid_Configuration_Pragma;
6103 Check_Arg_Count (1);
6104 Check_No_Identifiers;
6105 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6107 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6108 Assume_No_Invalid_Values := True;
6110 Assume_No_Invalid_Values := False;
6117 -- pragma AST_Entry (entry_IDENTIFIER);
6119 when Pragma_AST_Entry => AST_Entry : declare
6125 Check_Arg_Count (1);
6126 Check_No_Identifiers;
6127 Check_Arg_Is_Local_Name (Arg1);
6128 Ent := Entity (Get_Pragma_Arg (Arg1));
6130 -- Note: the implementation of the AST_Entry pragma could handle
6131 -- the entry family case fine, but for now we are consistent with
6132 -- the DEC rules, and do not allow the pragma, which of course
6133 -- has the effect of also forbidding the attribute.
6135 if Ekind (Ent) /= E_Entry then
6137 ("pragma% argument must be simple entry name", Arg1);
6139 elsif Is_AST_Entry (Ent) then
6141 ("duplicate % pragma for entry", Arg1);
6143 elsif Has_Homonym (Ent) then
6145 ("pragma% argument cannot specify overloaded entry", Arg1);
6149 FF : constant Entity_Id := First_Formal (Ent);
6152 if Present (FF) then
6153 if Present (Next_Formal (FF)) then
6155 ("entry for pragma% can have only one argument",
6158 elsif Parameter_Mode (FF) /= E_In_Parameter then
6160 ("entry parameter for pragma% must have mode IN",
6166 Set_Is_AST_Entry (Ent);
6174 -- pragma Asynchronous (LOCAL_NAME);
6176 when Pragma_Asynchronous => Asynchronous : declare
6184 procedure Process_Async_Pragma;
6185 -- Common processing for procedure and access-to-procedure case
6187 --------------------------
6188 -- Process_Async_Pragma --
6189 --------------------------
6191 procedure Process_Async_Pragma is
6194 Set_Is_Asynchronous (Nm);
6198 -- The formals should be of mode IN (RM E.4.1(6))
6201 while Present (S) loop
6202 Formal := Defining_Identifier (S);
6204 if Nkind (Formal) = N_Defining_Identifier
6205 and then Ekind (Formal) /= E_In_Parameter
6208 ("pragma% procedure can only have IN parameter",
6215 Set_Is_Asynchronous (Nm);
6216 end Process_Async_Pragma;
6218 -- Start of processing for pragma Asynchronous
6221 Check_Ada_83_Warning;
6222 Check_No_Identifiers;
6223 Check_Arg_Count (1);
6224 Check_Arg_Is_Local_Name (Arg1);
6226 if Debug_Flag_U then
6230 C_Ent := Cunit_Entity (Current_Sem_Unit);
6231 Analyze (Get_Pragma_Arg (Arg1));
6232 Nm := Entity (Get_Pragma_Arg (Arg1));
6234 if not Is_Remote_Call_Interface (C_Ent)
6235 and then not Is_Remote_Types (C_Ent)
6237 -- This pragma should only appear in an RCI or Remote Types
6238 -- unit (RM E.4.1(4)).
6241 ("pragma% not in Remote_Call_Interface or " &
6242 "Remote_Types unit");
6245 if Ekind (Nm) = E_Procedure
6246 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6248 if not Is_Remote_Call_Interface (Nm) then
6250 ("pragma% cannot be applied on non-remote procedure",
6254 L := Parameter_Specifications (Parent (Nm));
6255 Process_Async_Pragma;
6258 elsif Ekind (Nm) = E_Function then
6260 ("pragma% cannot be applied to function", Arg1);
6262 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6264 if Is_Record_Type (Nm) then
6266 -- A record type that is the Equivalent_Type for a remote
6267 -- access-to-subprogram type.
6269 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6272 -- A non-expanded RAS type (distribution is not enabled)
6274 N := Declaration_Node (Nm);
6277 if Nkind (N) = N_Full_Type_Declaration
6278 and then Nkind (Type_Definition (N)) =
6279 N_Access_Procedure_Definition
6281 L := Parameter_Specifications (Type_Definition (N));
6282 Process_Async_Pragma;
6284 if Is_Asynchronous (Nm)
6285 and then Expander_Active
6286 and then Get_PCS_Name /= Name_No_DSA
6288 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6293 ("pragma% cannot reference access-to-function type",
6297 -- Only other possibility is Access-to-class-wide type
6299 elsif Is_Access_Type (Nm)
6300 and then Is_Class_Wide_Type (Designated_Type (Nm))
6302 Check_First_Subtype (Arg1);
6303 Set_Is_Asynchronous (Nm);
6304 if Expander_Active then
6305 RACW_Type_Is_Asynchronous (Nm);
6309 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6317 -- pragma Atomic (LOCAL_NAME);
6319 when Pragma_Atomic =>
6320 Process_Atomic_Shared_Volatile;
6322 -----------------------
6323 -- Atomic_Components --
6324 -----------------------
6326 -- pragma Atomic_Components (array_LOCAL_NAME);
6328 -- This processing is shared by Volatile_Components
6330 when Pragma_Atomic_Components |
6331 Pragma_Volatile_Components =>
6333 Atomic_Components : declare
6340 Check_Ada_83_Warning;
6341 Check_No_Identifiers;
6342 Check_Arg_Count (1);
6343 Check_Arg_Is_Local_Name (Arg1);
6344 E_Id := Get_Pragma_Arg (Arg1);
6346 if Etype (E_Id) = Any_Type then
6352 Check_Duplicate_Pragma (E);
6354 if Rep_Item_Too_Early (E, N)
6356 Rep_Item_Too_Late (E, N)
6361 D := Declaration_Node (E);
6364 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6366 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6367 and then Nkind (D) = N_Object_Declaration
6368 and then Nkind (Object_Definition (D)) =
6369 N_Constrained_Array_Definition)
6371 -- The flag is set on the object, or on the base type
6373 if Nkind (D) /= N_Object_Declaration then
6377 Set_Has_Volatile_Components (E, Sense);
6379 if Prag_Id = Pragma_Atomic_Components then
6380 Set_Has_Atomic_Components (E, Sense);
6384 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6386 end Atomic_Components;
6388 --------------------
6389 -- Attach_Handler --
6390 --------------------
6392 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6394 when Pragma_Attach_Handler =>
6395 Check_Ada_83_Warning;
6396 Check_No_Identifiers;
6397 Check_Arg_Count (2);
6399 if No_Run_Time_Mode then
6400 Error_Msg_CRT ("Attach_Handler pragma", N);
6402 Check_Interrupt_Or_Attach_Handler;
6404 -- The expression that designates the attribute may depend on a
6405 -- discriminant, and is therefore a per- object expression, to
6406 -- be expanded in the init proc. If expansion is enabled, then
6407 -- perform semantic checks on a copy only.
6409 if Expander_Active then
6411 Temp : constant Node_Id :=
6412 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6414 Set_Parent (Temp, N);
6415 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6419 Analyze (Get_Pragma_Arg (Arg2));
6420 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6423 Process_Interrupt_Or_Attach_Handler;
6426 --------------------
6427 -- C_Pass_By_Copy --
6428 --------------------
6430 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6432 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6438 Check_Valid_Configuration_Pragma;
6439 Check_Arg_Count (1);
6440 Check_Optional_Identifier (Arg1, "max_size");
6442 Arg := Get_Pragma_Arg (Arg1);
6443 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6445 Val := Expr_Value (Arg);
6449 ("maximum size for pragma% must be positive", Arg1);
6451 elsif UI_Is_In_Int_Range (Val) then
6452 Default_C_Record_Mechanism := UI_To_Int (Val);
6454 -- If a giant value is given, Int'Last will do well enough.
6455 -- If sometime someone complains that a record larger than
6456 -- two gigabytes is not copied, we will worry about it then!
6459 Default_C_Record_Mechanism := Mechanism_Type'Last;
6467 -- pragma Check ([Name =>] Identifier,
6468 -- [Check =>] Boolean_Expression
6469 -- [,[Message =>] String_Expression]);
6471 when Pragma_Check => Check : declare
6476 -- Set True if category of assertions referenced by Name enabled
6480 Check_At_Least_N_Arguments (2);
6481 Check_At_Most_N_Arguments (3);
6482 Check_Optional_Identifier (Arg1, Name_Name);
6483 Check_Optional_Identifier (Arg2, Name_Check);
6485 if Arg_Count = 3 then
6486 Check_Optional_Identifier (Arg3, Name_Message);
6487 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6490 Check_Arg_Is_Identifier (Arg1);
6492 -- Indicate if pragma is enabled. The Original_Node reference here
6493 -- is to deal with pragma Assert rewritten as a Check pragma.
6495 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6498 Set_Pragma_Enabled (N);
6499 Set_Pragma_Enabled (Original_Node (N));
6500 Set_SCO_Pragma_Enabled (Loc);
6503 -- If expansion is active and the check is not enabled then we
6504 -- rewrite the Check as:
6506 -- if False and then condition then
6510 -- The reason we do this rewriting during semantic analysis rather
6511 -- than as part of normal expansion is that we cannot analyze and
6512 -- expand the code for the boolean expression directly, or it may
6513 -- cause insertion of actions that would escape the attempt to
6514 -- suppress the check code.
6516 -- Note that the Sloc for the if statement corresponds to the
6517 -- argument condition, not the pragma itself. The reason for this
6518 -- is that we may generate a warning if the condition is False at
6519 -- compile time, and we do not want to delete this warning when we
6520 -- delete the if statement.
6522 Expr := Get_Pragma_Arg (Arg2);
6524 if Expander_Active and then not Check_On then
6525 Eloc := Sloc (Expr);
6528 Make_If_Statement (Eloc,
6530 Make_And_Then (Eloc,
6531 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6532 Right_Opnd => Expr),
6533 Then_Statements => New_List (
6534 Make_Null_Statement (Eloc))));
6541 Analyze_And_Resolve (Expr, Any_Boolean);
6549 -- pragma Check_Name (check_IDENTIFIER);
6551 when Pragma_Check_Name =>
6552 Check_No_Identifiers;
6554 Check_Valid_Configuration_Pragma;
6555 Check_Arg_Count (1);
6556 Check_Arg_Is_Identifier (Arg1);
6559 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6562 for J in Check_Names.First .. Check_Names.Last loop
6563 if Check_Names.Table (J) = Nam then
6568 Check_Names.Append (Nam);
6575 -- pragma Check_Policy (
6576 -- [Name =>] IDENTIFIER,
6577 -- [Policy =>] POLICY_IDENTIFIER);
6579 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6581 -- Note: this is a configuration pragma, but it is allowed to appear
6584 when Pragma_Check_Policy =>
6586 Check_Arg_Count (2);
6587 Check_Optional_Identifier (Arg1, Name_Name);
6588 Check_Optional_Identifier (Arg2, Name_Policy);
6590 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6592 -- A Check_Policy pragma can appear either as a configuration
6593 -- pragma, or in a declarative part or a package spec (see RM
6594 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6595 -- followed for Check_Policy).
6597 if not Is_Configuration_Pragma then
6598 Check_Is_In_Decl_Part_Or_Package_Spec;
6601 Set_Next_Pragma (N, Opt.Check_Policy_List);
6602 Opt.Check_Policy_List := N;
6604 ---------------------
6605 -- CIL_Constructor --
6606 ---------------------
6608 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6610 -- Processing for this pragma is shared with Java_Constructor
6616 -- pragma Comment (static_string_EXPRESSION)
6618 -- Processing for pragma Comment shares the circuitry for pragma
6619 -- Ident. The only differences are that Ident enforces a limit of 31
6620 -- characters on its argument, and also enforces limitations on
6621 -- placement for DEC compatibility. Pragma Comment shares neither of
6622 -- these restrictions.
6628 -- pragma Common_Object (
6629 -- [Internal =>] LOCAL_NAME
6630 -- [, [External =>] EXTERNAL_SYMBOL]
6631 -- [, [Size =>] EXTERNAL_SYMBOL]);
6633 -- Processing for this pragma is shared with Psect_Object
6635 ------------------------
6636 -- Compile_Time_Error --
6637 ------------------------
6639 -- pragma Compile_Time_Error
6640 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6642 when Pragma_Compile_Time_Error =>
6644 Process_Compile_Time_Warning_Or_Error;
6646 --------------------------
6647 -- Compile_Time_Warning --
6648 --------------------------
6650 -- pragma Compile_Time_Warning
6651 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6653 when Pragma_Compile_Time_Warning =>
6655 Process_Compile_Time_Warning_Or_Error;
6661 when Pragma_Compiler_Unit =>
6663 Check_Arg_Count (0);
6664 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6666 -----------------------------
6667 -- Complete_Representation --
6668 -----------------------------
6670 -- pragma Complete_Representation;
6672 when Pragma_Complete_Representation =>
6674 Check_Arg_Count (0);
6676 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6678 ("pragma & must appear within record representation clause");
6681 ----------------------------
6682 -- Complex_Representation --
6683 ----------------------------
6685 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6687 when Pragma_Complex_Representation => Complex_Representation : declare
6694 Check_Arg_Count (1);
6695 Check_Optional_Identifier (Arg1, Name_Entity);
6696 Check_Arg_Is_Local_Name (Arg1);
6697 E_Id := Get_Pragma_Arg (Arg1);
6699 if Etype (E_Id) = Any_Type then
6705 if not Is_Record_Type (E) then
6707 ("argument for pragma% must be record type", Arg1);
6710 Ent := First_Entity (E);
6713 or else No (Next_Entity (Ent))
6714 or else Present (Next_Entity (Next_Entity (Ent)))
6715 or else not Is_Floating_Point_Type (Etype (Ent))
6716 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6719 ("record for pragma% must have two fields of the same "
6720 & "floating-point type", Arg1);
6723 Set_Has_Complex_Representation (Base_Type (E));
6725 -- We need to treat the type has having a non-standard
6726 -- representation, for back-end purposes, even though in
6727 -- general a complex will have the default representation
6728 -- of a record with two real components.
6730 Set_Has_Non_Standard_Rep (Base_Type (E));
6732 end Complex_Representation;
6734 -------------------------
6735 -- Component_Alignment --
6736 -------------------------
6738 -- pragma Component_Alignment (
6739 -- [Form =>] ALIGNMENT_CHOICE
6740 -- [, [Name =>] type_LOCAL_NAME]);
6742 -- ALIGNMENT_CHOICE ::=
6744 -- | Component_Size_4
6748 when Pragma_Component_Alignment => Component_AlignmentP : declare
6749 Args : Args_List (1 .. 2);
6750 Names : constant Name_List (1 .. 2) := (
6754 Form : Node_Id renames Args (1);
6755 Name : Node_Id renames Args (2);
6757 Atype : Component_Alignment_Kind;
6762 Gather_Associations (Names, Args);
6765 Error_Pragma ("missing Form argument for pragma%");
6768 Check_Arg_Is_Identifier (Form);
6770 -- Get proper alignment, note that Default = Component_Size on all
6771 -- machines we have so far, and we want to set this value rather
6772 -- than the default value to indicate that it has been explicitly
6773 -- set (and thus will not get overridden by the default component
6774 -- alignment for the current scope)
6776 if Chars (Form) = Name_Component_Size then
6777 Atype := Calign_Component_Size;
6779 elsif Chars (Form) = Name_Component_Size_4 then
6780 Atype := Calign_Component_Size_4;
6782 elsif Chars (Form) = Name_Default then
6783 Atype := Calign_Component_Size;
6785 elsif Chars (Form) = Name_Storage_Unit then
6786 Atype := Calign_Storage_Unit;
6790 ("invalid Form parameter for pragma%", Form);
6793 -- Case with no name, supplied, affects scope table entry
6797 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6799 -- Case of name supplied
6802 Check_Arg_Is_Local_Name (Name);
6804 Typ := Entity (Name);
6807 or else Rep_Item_Too_Early (Typ, N)
6811 Typ := Underlying_Type (Typ);
6814 if not Is_Record_Type (Typ)
6815 and then not Is_Array_Type (Typ)
6818 ("Name parameter of pragma% must identify record or " &
6819 "array type", Name);
6822 -- An explicit Component_Alignment pragma overrides an
6823 -- implicit pragma Pack, but not an explicit one.
6825 if not Has_Pragma_Pack (Base_Type (Typ)) then
6826 Set_Is_Packed (Base_Type (Typ), False);
6827 Set_Component_Alignment (Base_Type (Typ), Atype);
6830 end Component_AlignmentP;
6836 -- pragma Controlled (first_subtype_LOCAL_NAME);
6838 when Pragma_Controlled => Controlled : declare
6842 Check_No_Identifiers;
6843 Check_Arg_Count (1);
6844 Check_Arg_Is_Local_Name (Arg1);
6845 Arg := Get_Pragma_Arg (Arg1);
6847 if not Is_Entity_Name (Arg)
6848 or else not Is_Access_Type (Entity (Arg))
6850 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6852 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6860 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6861 -- [Entity =>] LOCAL_NAME);
6863 when Pragma_Convention => Convention : declare
6866 pragma Warnings (Off, C);
6867 pragma Warnings (Off, E);
6869 Check_Arg_Order ((Name_Convention, Name_Entity));
6870 Check_Ada_83_Warning;
6871 Check_Arg_Count (2);
6872 Process_Convention (C, E);
6875 ---------------------------
6876 -- Convention_Identifier --
6877 ---------------------------
6879 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6880 -- [Convention =>] convention_IDENTIFIER);
6882 when Pragma_Convention_Identifier => Convention_Identifier : declare
6888 Check_Arg_Order ((Name_Name, Name_Convention));
6889 Check_Arg_Count (2);
6890 Check_Optional_Identifier (Arg1, Name_Name);
6891 Check_Optional_Identifier (Arg2, Name_Convention);
6892 Check_Arg_Is_Identifier (Arg1);
6893 Check_Arg_Is_Identifier (Arg2);
6894 Idnam := Chars (Get_Pragma_Arg (Arg1));
6895 Cname := Chars (Get_Pragma_Arg (Arg2));
6897 if Is_Convention_Name (Cname) then
6898 Record_Convention_Identifier
6899 (Idnam, Get_Convention_Id (Cname));
6902 ("second arg for % pragma must be convention", Arg2);
6904 end Convention_Identifier;
6910 -- pragma CPP_Class ([Entity =>] local_NAME)
6912 when Pragma_CPP_Class => CPP_Class : declare
6917 if Warn_On_Obsolescent_Feature then
6919 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6920 " by pragma import?", N);
6924 Check_Arg_Count (1);
6925 Check_Optional_Identifier (Arg1, Name_Entity);
6926 Check_Arg_Is_Local_Name (Arg1);
6928 Arg := Get_Pragma_Arg (Arg1);
6931 if Etype (Arg) = Any_Type then
6935 if not Is_Entity_Name (Arg)
6936 or else not Is_Type (Entity (Arg))
6938 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6941 Typ := Entity (Arg);
6943 if not Is_Tagged_Type (Typ) then
6944 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6947 -- Types treated as CPP classes are treated as limited, but we
6948 -- don't require them to be declared this way. A warning is issued
6949 -- to encourage the user to declare them as limited. This is not
6950 -- an error, for compatibility reasons, because these types have
6951 -- been supported this way for some time.
6953 if not Is_Limited_Type (Typ) then
6955 ("imported 'C'P'P type should be " &
6956 "explicitly declared limited?",
6957 Get_Pragma_Arg (Arg1));
6959 ("\type will be considered limited",
6960 Get_Pragma_Arg (Arg1));
6963 Set_Is_CPP_Class (Typ);
6964 Set_Is_Limited_Record (Typ);
6965 Set_Convention (Typ, Convention_CPP);
6967 -- Imported CPP types must not have discriminants (because C++
6968 -- classes do not have discriminants).
6970 if Has_Discriminants (Typ) then
6972 ("imported 'C'P'P type cannot have discriminants",
6973 First (Discriminant_Specifications
6974 (Declaration_Node (Typ))));
6977 -- Components of imported CPP types must not have default
6978 -- expressions because the constructor (if any) is in the
6981 if Is_Incomplete_Or_Private_Type (Typ)
6982 and then No (Underlying_Type (Typ))
6984 -- It should be an error to apply pragma CPP to a private
6985 -- type if the underlying type is not visible (as it is
6986 -- for any representation item). For now, for backward
6987 -- compatibility we do nothing but we cannot check components
6988 -- because they are not available at this stage. All this code
6989 -- will be removed when we cleanup this obsolete GNAT pragma???
6995 Tdef : constant Node_Id :=
6996 Type_Definition (Declaration_Node (Typ));
7001 if Nkind (Tdef) = N_Record_Definition then
7002 Clist := Component_List (Tdef);
7004 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7005 Clist := Component_List (Record_Extension_Part (Tdef));
7008 if Present (Clist) then
7009 Comp := First (Component_Items (Clist));
7010 while Present (Comp) loop
7011 if Present (Expression (Comp)) then
7013 ("component of imported 'C'P'P type cannot have" &
7014 " default expression", Expression (Comp));
7024 ---------------------
7025 -- CPP_Constructor --
7026 ---------------------
7028 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7029 -- [, [External_Name =>] static_string_EXPRESSION ]
7030 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7032 when Pragma_CPP_Constructor => CPP_Constructor : declare
7036 Tag_Typ : Entity_Id;
7040 Check_At_Least_N_Arguments (1);
7041 Check_At_Most_N_Arguments (3);
7042 Check_Optional_Identifier (Arg1, Name_Entity);
7043 Check_Arg_Is_Local_Name (Arg1);
7045 Id := Get_Pragma_Arg (Arg1);
7046 Find_Program_Unit_Name (Id);
7048 -- If we did not find the name, we are done
7050 if Etype (Id) = Any_Type then
7054 Def_Id := Entity (Id);
7056 -- Check if already defined as constructor
7058 if Is_Constructor (Def_Id) then
7060 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7064 if Ekind (Def_Id) = E_Function
7065 and then (Is_CPP_Class (Etype (Def_Id))
7066 or else (Is_Class_Wide_Type (Etype (Def_Id))
7068 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7070 if Arg_Count >= 2 then
7071 Set_Imported (Def_Id);
7072 Set_Is_Public (Def_Id);
7073 Process_Interface_Name (Def_Id, Arg2, Arg3);
7076 Set_Has_Completion (Def_Id);
7077 Set_Is_Constructor (Def_Id);
7079 -- Imported C++ constructors are not dispatching primitives
7080 -- because in C++ they don't have a dispatch table slot.
7081 -- However, in Ada the constructor has the profile of a
7082 -- function that returns a tagged type and therefore it has
7083 -- been treated as a primitive operation during semantic
7084 -- analysis. We now remove it from the list of primitive
7085 -- operations of the type.
7087 if Is_Tagged_Type (Etype (Def_Id))
7088 and then not Is_Class_Wide_Type (Etype (Def_Id))
7090 pragma Assert (Is_Dispatching_Operation (Def_Id));
7091 Tag_Typ := Etype (Def_Id);
7093 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7094 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7098 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7099 Set_Is_Dispatching_Operation (Def_Id, False);
7102 -- For backward compatibility, if the constructor returns a
7103 -- class wide type, and we internally change the return type to
7104 -- the corresponding root type.
7106 if Is_Class_Wide_Type (Etype (Def_Id)) then
7107 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7111 ("pragma% requires function returning a 'C'P'P_Class type",
7114 end CPP_Constructor;
7120 when Pragma_CPP_Virtual => CPP_Virtual : declare
7124 if Warn_On_Obsolescent_Feature then
7126 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7135 when Pragma_CPP_Vtable => CPP_Vtable : declare
7139 if Warn_On_Obsolescent_Feature then
7141 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7150 -- pragma CPU (EXPRESSION);
7152 when Pragma_CPU => CPU : declare
7153 P : constant Node_Id := Parent (N);
7158 Check_No_Identifiers;
7159 Check_Arg_Count (1);
7163 if Nkind (P) = N_Subprogram_Body then
7164 Check_In_Main_Program;
7166 Arg := Get_Pragma_Arg (Arg1);
7167 Analyze_And_Resolve (Arg, Any_Integer);
7171 if not Is_Static_Expression (Arg) then
7172 Flag_Non_Static_Expr
7173 ("main subprogram affinity is not static!", Arg);
7176 -- If constraint error, then we already signalled an error
7178 elsif Raises_Constraint_Error (Arg) then
7181 -- Otherwise check in range
7185 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7186 -- This is the entity System.Multiprocessors.CPU_Range;
7188 Val : constant Uint := Expr_Value (Arg);
7191 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7193 Val > Expr_Value (Type_High_Bound (CPU_Id))
7196 ("main subprogram CPU is out of range", Arg1);
7202 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7206 elsif Nkind (P) = N_Task_Definition then
7207 Arg := Get_Pragma_Arg (Arg1);
7209 -- The expression must be analyzed in the special manner
7210 -- described in "Handling of Default and Per-Object
7211 -- Expressions" in sem.ads.
7213 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7215 -- Anything else is incorrect
7221 if Has_Pragma_CPU (P) then
7222 Error_Pragma ("duplicate pragma% not allowed");
7224 Set_Has_Pragma_CPU (P, True);
7226 if Nkind (P) = N_Task_Definition then
7227 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7236 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7238 when Pragma_Debug => Debug : declare
7246 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7249 if Arg_Count = 2 then
7252 Left_Opnd => Relocate_Node (Cond),
7253 Right_Opnd => Get_Pragma_Arg (Arg1));
7256 -- Rewrite into a conditional with an appropriate condition. We
7257 -- wrap the procedure call in a block so that overhead from e.g.
7258 -- use of the secondary stack does not generate execution overhead
7259 -- for suppressed conditions.
7261 Rewrite (N, Make_Implicit_If_Statement (N,
7263 Then_Statements => New_List (
7264 Make_Block_Statement (Loc,
7265 Handled_Statement_Sequence =>
7266 Make_Handled_Sequence_Of_Statements (Loc,
7267 Statements => New_List (
7268 Relocate_Node (Debug_Statement (N))))))));
7276 -- pragma Debug_Policy (Check | Ignore)
7278 when Pragma_Debug_Policy =>
7280 Check_Arg_Count (1);
7281 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7282 Debug_Pragmas_Enabled :=
7283 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7285 ---------------------
7286 -- Detect_Blocking --
7287 ---------------------
7289 -- pragma Detect_Blocking;
7291 when Pragma_Detect_Blocking =>
7293 Check_Arg_Count (0);
7294 Check_Valid_Configuration_Pragma;
7295 Detect_Blocking := True;
7297 --------------------------
7298 -- Default_Storage_Pool --
7299 --------------------------
7301 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7303 when Pragma_Default_Storage_Pool =>
7305 Check_Arg_Count (1);
7307 -- Default_Storage_Pool can appear as a configuration pragma, or
7308 -- in a declarative part or a package spec.
7310 if not Is_Configuration_Pragma then
7311 Check_Is_In_Decl_Part_Or_Package_Spec;
7314 -- Case of Default_Storage_Pool (null);
7316 if Nkind (Expression (Arg1)) = N_Null then
7317 Analyze (Expression (Arg1));
7319 -- This is an odd case, this is not really an expression, so
7320 -- we don't have a type for it. So just set the type to Empty.
7322 Set_Etype (Expression (Arg1), Empty);
7324 -- Case of Default_Storage_Pool (storage_pool_NAME);
7327 -- If it's a configuration pragma, then the only allowed
7328 -- argument is "null".
7330 if Is_Configuration_Pragma then
7331 Error_Pragma_Arg ("NULL expected", Arg1);
7334 -- The expected type for a non-"null" argument is
7335 -- Root_Storage_Pool'Class.
7338 (Get_Pragma_Arg (Arg1),
7339 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7342 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7343 -- for an access type will use this information to set the
7344 -- appropriate attributes of the access type.
7346 Default_Pool := Expression (Arg1);
7352 when Pragma_Dimension =>
7354 Check_Arg_Count (4);
7355 Check_No_Identifiers;
7356 Check_Arg_Is_Local_Name (Arg1);
7358 if not Is_Type (Arg1) then
7359 Error_Pragma ("first argument for pragma% must be subtype");
7362 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7363 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7364 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7370 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7372 when Pragma_Discard_Names => Discard_Names : declare
7377 Check_Ada_83_Warning;
7379 -- Deal with configuration pragma case
7381 if Arg_Count = 0 and then Is_Configuration_Pragma then
7382 Global_Discard_Names := True;
7385 -- Otherwise, check correct appropriate context
7388 Check_Is_In_Decl_Part_Or_Package_Spec;
7390 if Arg_Count = 0 then
7392 -- If there is no parameter, then from now on this pragma
7393 -- applies to any enumeration, exception or tagged type
7394 -- defined in the current declarative part, and recursively
7395 -- to any nested scope.
7397 Set_Discard_Names (Current_Scope, Sense);
7401 Check_Arg_Count (1);
7402 Check_Optional_Identifier (Arg1, Name_On);
7403 Check_Arg_Is_Local_Name (Arg1);
7405 E_Id := Get_Pragma_Arg (Arg1);
7407 if Etype (E_Id) = Any_Type then
7413 if (Is_First_Subtype (E)
7415 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7416 or else Ekind (E) = E_Exception
7418 Set_Discard_Names (E, Sense);
7421 ("inappropriate entity for pragma%", Arg1);
7432 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7434 when Pragma_Elaborate => Elaborate : declare
7439 -- Pragma must be in context items list of a compilation unit
7441 if not Is_In_Context_Clause then
7445 -- Must be at least one argument
7447 if Arg_Count = 0 then
7448 Error_Pragma ("pragma% requires at least one argument");
7451 -- In Ada 83 mode, there can be no items following it in the
7452 -- context list except other pragmas and implicit with clauses
7453 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7454 -- placement rule does not apply.
7456 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7458 while Present (Citem) loop
7459 if Nkind (Citem) = N_Pragma
7460 or else (Nkind (Citem) = N_With_Clause
7461 and then Implicit_With (Citem))
7466 ("(Ada 83) pragma% must be at end of context clause");
7473 -- Finally, the arguments must all be units mentioned in a with
7474 -- clause in the same context clause. Note we already checked (in
7475 -- Par.Prag) that the arguments are all identifiers or selected
7479 Outer : while Present (Arg) loop
7480 Citem := First (List_Containing (N));
7481 Inner : while Citem /= N loop
7482 if Nkind (Citem) = N_With_Clause
7483 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7485 Set_Elaborate_Present (Citem, True);
7486 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7488 -- With the pragma present, elaboration calls on
7489 -- subprograms from the named unit need no further
7490 -- checks, as long as the pragma appears in the current
7491 -- compilation unit. If the pragma appears in some unit
7492 -- in the context, there might still be a need for an
7493 -- Elaborate_All_Desirable from the current compilation
7494 -- to the named unit, so we keep the check enabled.
7496 if In_Extended_Main_Source_Unit (N) then
7497 Set_Suppress_Elaboration_Warnings
7498 (Entity (Name (Citem)));
7509 ("argument of pragma% is not with'ed unit", Arg);
7515 -- Give a warning if operating in static mode with -gnatwl
7516 -- (elaboration warnings enabled) switch set.
7518 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7520 ("?use of pragma Elaborate may not be safe", N);
7522 ("?use pragma Elaborate_All instead if possible", N);
7530 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7532 when Pragma_Elaborate_All => Elaborate_All : declare
7537 Check_Ada_83_Warning;
7539 -- Pragma must be in context items list of a compilation unit
7541 if not Is_In_Context_Clause then
7545 -- Must be at least one argument
7547 if Arg_Count = 0 then
7548 Error_Pragma ("pragma% requires at least one argument");
7551 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7552 -- have to appear at the end of the context clause, but may
7553 -- appear mixed in with other items, even in Ada 83 mode.
7555 -- Final check: the arguments must all be units mentioned in
7556 -- a with clause in the same context clause. Note that we
7557 -- already checked (in Par.Prag) that all the arguments are
7558 -- either identifiers or selected components.
7561 Outr : while Present (Arg) loop
7562 Citem := First (List_Containing (N));
7563 Innr : while Citem /= N loop
7564 if Nkind (Citem) = N_With_Clause
7565 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7567 Set_Elaborate_All_Present (Citem, True);
7568 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7570 -- Suppress warnings and elaboration checks on the named
7571 -- unit if the pragma is in the current compilation, as
7572 -- for pragma Elaborate.
7574 if In_Extended_Main_Source_Unit (N) then
7575 Set_Suppress_Elaboration_Warnings
7576 (Entity (Name (Citem)));
7585 Set_Error_Posted (N);
7587 ("argument of pragma% is not with'ed unit", Arg);
7594 --------------------
7595 -- Elaborate_Body --
7596 --------------------
7598 -- pragma Elaborate_Body [( library_unit_NAME )];
7600 when Pragma_Elaborate_Body => Elaborate_Body : declare
7601 Cunit_Node : Node_Id;
7602 Cunit_Ent : Entity_Id;
7605 Check_Ada_83_Warning;
7606 Check_Valid_Library_Unit_Pragma;
7608 if Nkind (N) = N_Null_Statement then
7612 Cunit_Node := Cunit (Current_Sem_Unit);
7613 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7615 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7618 Error_Pragma ("pragma% must refer to a spec, not a body");
7620 Set_Body_Required (Cunit_Node, True);
7621 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7623 -- If we are in dynamic elaboration mode, then we suppress
7624 -- elaboration warnings for the unit, since it is definitely
7625 -- fine NOT to do dynamic checks at the first level (and such
7626 -- checks will be suppressed because no elaboration boolean
7627 -- is created for Elaborate_Body packages).
7629 -- But in the static model of elaboration, Elaborate_Body is
7630 -- definitely NOT good enough to ensure elaboration safety on
7631 -- its own, since the body may WITH other units that are not
7632 -- safe from an elaboration point of view, so a client must
7633 -- still do an Elaborate_All on such units.
7635 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7636 -- Elaborate_Body always suppressed elab warnings.
7638 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7639 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7644 ------------------------
7645 -- Elaboration_Checks --
7646 ------------------------
7648 -- pragma Elaboration_Checks (Static | Dynamic);
7650 when Pragma_Elaboration_Checks =>
7652 Check_Arg_Count (1);
7653 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7654 Dynamic_Elaboration_Checks :=
7655 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7661 -- pragma Eliminate (
7662 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7663 -- [,[Entity =>] IDENTIFIER |
7664 -- SELECTED_COMPONENT |
7666 -- [, OVERLOADING_RESOLUTION]);
7668 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7671 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7674 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7676 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7677 -- Result_Type => result_SUBTYPE_NAME]
7679 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7680 -- SUBTYPE_NAME ::= STRING_LITERAL
7682 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7683 -- SOURCE_TRACE ::= STRING_LITERAL
7685 when Pragma_Eliminate => Eliminate : declare
7686 Args : Args_List (1 .. 5);
7687 Names : constant Name_List (1 .. 5) := (
7690 Name_Parameter_Types,
7692 Name_Source_Location);
7694 Unit_Name : Node_Id renames Args (1);
7695 Entity : Node_Id renames Args (2);
7696 Parameter_Types : Node_Id renames Args (3);
7697 Result_Type : Node_Id renames Args (4);
7698 Source_Location : Node_Id renames Args (5);
7702 Check_Valid_Configuration_Pragma;
7703 Gather_Associations (Names, Args);
7705 if No (Unit_Name) then
7706 Error_Pragma ("missing Unit_Name argument for pragma%");
7710 and then (Present (Parameter_Types)
7712 Present (Result_Type)
7714 Present (Source_Location))
7716 Error_Pragma ("missing Entity argument for pragma%");
7719 if (Present (Parameter_Types)
7721 Present (Result_Type))
7723 Present (Source_Location)
7726 ("parameter profile and source location cannot " &
7727 "be used together in pragma%");
7730 Process_Eliminate_Pragma
7744 -- [ Convention =>] convention_IDENTIFIER,
7745 -- [ Entity =>] local_NAME
7746 -- [, [External_Name =>] static_string_EXPRESSION ]
7747 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7749 when Pragma_Export => Export : declare
7753 pragma Warnings (Off, C);
7756 Check_Ada_83_Warning;
7762 Check_At_Least_N_Arguments (2);
7763 Check_At_Most_N_Arguments (4);
7764 Process_Convention (C, Def_Id);
7766 if Ekind (Def_Id) /= E_Constant then
7767 Note_Possible_Modification
7768 (Get_Pragma_Arg (Arg2), Sure => False);
7771 Process_Interface_Name (Def_Id, Arg3, Arg4);
7772 Set_Exported (Def_Id, Arg2);
7774 -- If the entity is a deferred constant, propagate the information
7775 -- to the full view, because gigi elaborates the full view only.
7777 if Ekind (Def_Id) = E_Constant
7778 and then Present (Full_View (Def_Id))
7781 Id2 : constant Entity_Id := Full_View (Def_Id);
7783 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7784 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7785 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7790 ----------------------
7791 -- Export_Exception --
7792 ----------------------
7794 -- pragma Export_Exception (
7795 -- [Internal =>] LOCAL_NAME
7796 -- [, [External =>] EXTERNAL_SYMBOL]
7797 -- [, [Form =>] Ada | VMS]
7798 -- [, [Code =>] static_integer_EXPRESSION]);
7800 when Pragma_Export_Exception => Export_Exception : declare
7801 Args : Args_List (1 .. 4);
7802 Names : constant Name_List (1 .. 4) := (
7808 Internal : Node_Id renames Args (1);
7809 External : Node_Id renames Args (2);
7810 Form : Node_Id renames Args (3);
7811 Code : Node_Id renames Args (4);
7816 if Inside_A_Generic then
7817 Error_Pragma ("pragma% cannot be used for generic entities");
7820 Gather_Associations (Names, Args);
7821 Process_Extended_Import_Export_Exception_Pragma (
7822 Arg_Internal => Internal,
7823 Arg_External => External,
7827 if not Is_VMS_Exception (Entity (Internal)) then
7828 Set_Exported (Entity (Internal), Internal);
7830 end Export_Exception;
7832 ---------------------
7833 -- Export_Function --
7834 ---------------------
7836 -- pragma Export_Function (
7837 -- [Internal =>] LOCAL_NAME
7838 -- [, [External =>] EXTERNAL_SYMBOL]
7839 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7840 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7841 -- [, [Mechanism =>] MECHANISM]
7842 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7844 -- EXTERNAL_SYMBOL ::=
7846 -- | static_string_EXPRESSION
7848 -- PARAMETER_TYPES ::=
7850 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7852 -- TYPE_DESIGNATOR ::=
7854 -- | subtype_Name ' Access
7858 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7860 -- MECHANISM_ASSOCIATION ::=
7861 -- [formal_parameter_NAME =>] MECHANISM_NAME
7863 -- MECHANISM_NAME ::=
7866 -- | Descriptor [([Class =>] CLASS_NAME)]
7868 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7870 when Pragma_Export_Function => Export_Function : declare
7871 Args : Args_List (1 .. 6);
7872 Names : constant Name_List (1 .. 6) := (
7875 Name_Parameter_Types,
7878 Name_Result_Mechanism);
7880 Internal : Node_Id renames Args (1);
7881 External : Node_Id renames Args (2);
7882 Parameter_Types : Node_Id renames Args (3);
7883 Result_Type : Node_Id renames Args (4);
7884 Mechanism : Node_Id renames Args (5);
7885 Result_Mechanism : Node_Id renames Args (6);
7889 Gather_Associations (Names, Args);
7890 Process_Extended_Import_Export_Subprogram_Pragma (
7891 Arg_Internal => Internal,
7892 Arg_External => External,
7893 Arg_Parameter_Types => Parameter_Types,
7894 Arg_Result_Type => Result_Type,
7895 Arg_Mechanism => Mechanism,
7896 Arg_Result_Mechanism => Result_Mechanism);
7897 end Export_Function;
7903 -- pragma Export_Object (
7904 -- [Internal =>] LOCAL_NAME
7905 -- [, [External =>] EXTERNAL_SYMBOL]
7906 -- [, [Size =>] EXTERNAL_SYMBOL]);
7908 -- EXTERNAL_SYMBOL ::=
7910 -- | static_string_EXPRESSION
7912 -- PARAMETER_TYPES ::=
7914 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7916 -- TYPE_DESIGNATOR ::=
7918 -- | subtype_Name ' Access
7922 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7924 -- MECHANISM_ASSOCIATION ::=
7925 -- [formal_parameter_NAME =>] MECHANISM_NAME
7927 -- MECHANISM_NAME ::=
7930 -- | Descriptor [([Class =>] CLASS_NAME)]
7932 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7934 when Pragma_Export_Object => Export_Object : declare
7935 Args : Args_List (1 .. 3);
7936 Names : constant Name_List (1 .. 3) := (
7941 Internal : Node_Id renames Args (1);
7942 External : Node_Id renames Args (2);
7943 Size : Node_Id renames Args (3);
7947 Gather_Associations (Names, Args);
7948 Process_Extended_Import_Export_Object_Pragma (
7949 Arg_Internal => Internal,
7950 Arg_External => External,
7954 ----------------------
7955 -- Export_Procedure --
7956 ----------------------
7958 -- pragma Export_Procedure (
7959 -- [Internal =>] LOCAL_NAME
7960 -- [, [External =>] EXTERNAL_SYMBOL]
7961 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7962 -- [, [Mechanism =>] MECHANISM]);
7964 -- EXTERNAL_SYMBOL ::=
7966 -- | static_string_EXPRESSION
7968 -- PARAMETER_TYPES ::=
7970 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7972 -- TYPE_DESIGNATOR ::=
7974 -- | subtype_Name ' Access
7978 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7980 -- MECHANISM_ASSOCIATION ::=
7981 -- [formal_parameter_NAME =>] MECHANISM_NAME
7983 -- MECHANISM_NAME ::=
7986 -- | Descriptor [([Class =>] CLASS_NAME)]
7988 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7990 when Pragma_Export_Procedure => Export_Procedure : declare
7991 Args : Args_List (1 .. 4);
7992 Names : constant Name_List (1 .. 4) := (
7995 Name_Parameter_Types,
7998 Internal : Node_Id renames Args (1);
7999 External : Node_Id renames Args (2);
8000 Parameter_Types : Node_Id renames Args (3);
8001 Mechanism : Node_Id renames Args (4);
8005 Gather_Associations (Names, Args);
8006 Process_Extended_Import_Export_Subprogram_Pragma (
8007 Arg_Internal => Internal,
8008 Arg_External => External,
8009 Arg_Parameter_Types => Parameter_Types,
8010 Arg_Mechanism => Mechanism);
8011 end Export_Procedure;
8017 -- pragma Export_Value (
8018 -- [Value =>] static_integer_EXPRESSION,
8019 -- [Link_Name =>] static_string_EXPRESSION);
8021 when Pragma_Export_Value =>
8023 Check_Arg_Order ((Name_Value, Name_Link_Name));
8024 Check_Arg_Count (2);
8026 Check_Optional_Identifier (Arg1, Name_Value);
8027 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8029 Check_Optional_Identifier (Arg2, Name_Link_Name);
8030 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8032 -----------------------------
8033 -- Export_Valued_Procedure --
8034 -----------------------------
8036 -- pragma Export_Valued_Procedure (
8037 -- [Internal =>] LOCAL_NAME
8038 -- [, [External =>] EXTERNAL_SYMBOL,]
8039 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8040 -- [, [Mechanism =>] MECHANISM]);
8042 -- EXTERNAL_SYMBOL ::=
8044 -- | static_string_EXPRESSION
8046 -- PARAMETER_TYPES ::=
8048 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8050 -- TYPE_DESIGNATOR ::=
8052 -- | subtype_Name ' Access
8056 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8058 -- MECHANISM_ASSOCIATION ::=
8059 -- [formal_parameter_NAME =>] MECHANISM_NAME
8061 -- MECHANISM_NAME ::=
8064 -- | Descriptor [([Class =>] CLASS_NAME)]
8066 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8068 when Pragma_Export_Valued_Procedure =>
8069 Export_Valued_Procedure : declare
8070 Args : Args_List (1 .. 4);
8071 Names : constant Name_List (1 .. 4) := (
8074 Name_Parameter_Types,
8077 Internal : Node_Id renames Args (1);
8078 External : Node_Id renames Args (2);
8079 Parameter_Types : Node_Id renames Args (3);
8080 Mechanism : Node_Id renames Args (4);
8084 Gather_Associations (Names, Args);
8085 Process_Extended_Import_Export_Subprogram_Pragma (
8086 Arg_Internal => Internal,
8087 Arg_External => External,
8088 Arg_Parameter_Types => Parameter_Types,
8089 Arg_Mechanism => Mechanism);
8090 end Export_Valued_Procedure;
8096 -- pragma Extend_System ([Name =>] Identifier);
8098 when Pragma_Extend_System => Extend_System : declare
8101 Check_Valid_Configuration_Pragma;
8102 Check_Arg_Count (1);
8103 Check_Optional_Identifier (Arg1, Name_Name);
8104 Check_Arg_Is_Identifier (Arg1);
8106 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8109 and then Name_Buffer (1 .. 4) = "aux_"
8111 if Present (System_Extend_Pragma_Arg) then
8112 if Chars (Get_Pragma_Arg (Arg1)) =
8113 Chars (Expression (System_Extend_Pragma_Arg))
8117 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8118 Error_Pragma ("pragma% conflicts with that #");
8122 System_Extend_Pragma_Arg := Arg1;
8124 if not GNAT_Mode then
8125 System_Extend_Unit := Arg1;
8129 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8133 ------------------------
8134 -- Extensions_Allowed --
8135 ------------------------
8137 -- pragma Extensions_Allowed (ON | OFF);
8139 when Pragma_Extensions_Allowed =>
8141 Check_Arg_Count (1);
8142 Check_No_Identifiers;
8143 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8145 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8146 Extensions_Allowed := True;
8147 Ada_Version := Ada_Version_Type'Last;
8150 Extensions_Allowed := False;
8151 Ada_Version := Ada_Version_Explicit;
8158 -- pragma External (
8159 -- [ Convention =>] convention_IDENTIFIER,
8160 -- [ Entity =>] local_NAME
8161 -- [, [External_Name =>] static_string_EXPRESSION ]
8162 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8164 when Pragma_External => External : declare
8168 pragma Warnings (Off, C);
8177 Check_At_Least_N_Arguments (2);
8178 Check_At_Most_N_Arguments (4);
8179 Process_Convention (C, Def_Id);
8180 Note_Possible_Modification
8181 (Get_Pragma_Arg (Arg2), Sure => False);
8182 Process_Interface_Name (Def_Id, Arg3, Arg4);
8183 Set_Exported (Def_Id, Arg2);
8186 --------------------------
8187 -- External_Name_Casing --
8188 --------------------------
8190 -- pragma External_Name_Casing (
8191 -- UPPERCASE | LOWERCASE
8192 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8194 when Pragma_External_Name_Casing => External_Name_Casing : declare
8197 Check_No_Identifiers;
8199 if Arg_Count = 2 then
8201 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8203 case Chars (Get_Pragma_Arg (Arg2)) is
8205 Opt.External_Name_Exp_Casing := As_Is;
8207 when Name_Uppercase =>
8208 Opt.External_Name_Exp_Casing := Uppercase;
8210 when Name_Lowercase =>
8211 Opt.External_Name_Exp_Casing := Lowercase;
8218 Check_Arg_Count (1);
8221 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8223 case Chars (Get_Pragma_Arg (Arg1)) is
8224 when Name_Uppercase =>
8225 Opt.External_Name_Imp_Casing := Uppercase;
8227 when Name_Lowercase =>
8228 Opt.External_Name_Imp_Casing := Lowercase;
8233 end External_Name_Casing;
8235 --------------------------
8236 -- Favor_Top_Level --
8237 --------------------------
8239 -- pragma Favor_Top_Level (type_NAME);
8241 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8242 Named_Entity : Entity_Id;
8246 Check_No_Identifiers;
8247 Check_Arg_Count (1);
8248 Check_Arg_Is_Local_Name (Arg1);
8249 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8251 -- If it's an access-to-subprogram type (in particular, not a
8252 -- subtype), set the flag on that type.
8254 if Is_Access_Subprogram_Type (Named_Entity) then
8256 Set_Can_Use_Internal_Rep (Named_Entity, False);
8259 -- Otherwise it's an error (name denotes the wrong sort of entity)
8263 ("access-to-subprogram type expected",
8264 Get_Pragma_Arg (Arg1));
8266 end Favor_Top_Level;
8272 -- pragma Fast_Math;
8274 when Pragma_Fast_Math =>
8276 Check_No_Identifiers;
8277 Check_Valid_Configuration_Pragma;
8280 ---------------------------
8281 -- Finalize_Storage_Only --
8282 ---------------------------
8284 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8286 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8287 Assoc : constant Node_Id := Arg1;
8288 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8293 Check_No_Identifiers;
8294 Check_Arg_Count (1);
8295 Check_Arg_Is_Local_Name (Arg1);
8297 Find_Type (Type_Id);
8298 Typ := Entity (Type_Id);
8301 or else Rep_Item_Too_Early (Typ, N)
8305 Typ := Underlying_Type (Typ);
8308 if not Is_Controlled (Typ) then
8309 Error_Pragma ("pragma% must specify controlled type");
8312 Check_First_Subtype (Arg1);
8314 if Finalize_Storage_Only (Typ) then
8315 Error_Pragma ("duplicate pragma%, only one allowed");
8317 elsif not Rep_Item_Too_Late (Typ, N) then
8318 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8320 end Finalize_Storage;
8322 --------------------------
8323 -- Float_Representation --
8324 --------------------------
8326 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8328 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8330 when Pragma_Float_Representation => Float_Representation : declare
8338 if Arg_Count = 1 then
8339 Check_Valid_Configuration_Pragma;
8341 Check_Arg_Count (2);
8342 Check_Optional_Identifier (Arg2, Name_Entity);
8343 Check_Arg_Is_Local_Name (Arg2);
8346 Check_No_Identifier (Arg1);
8347 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8349 if not OpenVMS_On_Target then
8350 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8352 ("?pragma% ignored (applies only to Open'V'M'S)");
8358 -- One argument case
8360 if Arg_Count = 1 then
8361 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8362 if Opt.Float_Format = 'I' then
8363 Error_Pragma ("'I'E'E'E format previously specified");
8366 Opt.Float_Format := 'V';
8369 if Opt.Float_Format = 'V' then
8370 Error_Pragma ("'V'A'X format previously specified");
8373 Opt.Float_Format := 'I';
8376 Set_Standard_Fpt_Formats;
8378 -- Two argument case
8381 Argx := Get_Pragma_Arg (Arg2);
8383 if not Is_Entity_Name (Argx)
8384 or else not Is_Floating_Point_Type (Entity (Argx))
8387 ("second argument of% pragma must be floating-point type",
8391 Ent := Entity (Argx);
8392 Digs := UI_To_Int (Digits_Value (Ent));
8394 -- Two arguments, VAX_Float case
8396 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8398 when 6 => Set_F_Float (Ent);
8399 when 9 => Set_D_Float (Ent);
8400 when 15 => Set_G_Float (Ent);
8404 ("wrong digits value, must be 6,9 or 15", Arg2);
8407 -- Two arguments, IEEE_Float case
8411 when 6 => Set_IEEE_Short (Ent);
8412 when 15 => Set_IEEE_Long (Ent);
8416 ("wrong digits value, must be 6 or 15", Arg2);
8420 end Float_Representation;
8426 -- pragma Ident (static_string_EXPRESSION)
8428 -- Note: pragma Comment shares this processing. Pragma Comment is
8429 -- identical to Ident, except that the restriction of the argument to
8430 -- 31 characters and the placement restrictions are not enforced for
8433 when Pragma_Ident | Pragma_Comment => Ident : declare
8438 Check_Arg_Count (1);
8439 Check_No_Identifiers;
8440 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8443 -- For pragma Ident, preserve DEC compatibility by requiring the
8444 -- pragma to appear in a declarative part or package spec.
8446 if Prag_Id = Pragma_Ident then
8447 Check_Is_In_Decl_Part_Or_Package_Spec;
8450 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8457 GP := Parent (Parent (N));
8459 if Nkind_In (GP, N_Package_Declaration,
8460 N_Generic_Package_Declaration)
8465 -- If we have a compilation unit, then record the ident value,
8466 -- checking for improper duplication.
8468 if Nkind (GP) = N_Compilation_Unit then
8469 CS := Ident_String (Current_Sem_Unit);
8471 if Present (CS) then
8473 -- For Ident, we do not permit multiple instances
8475 if Prag_Id = Pragma_Ident then
8476 Error_Pragma ("duplicate% pragma not permitted");
8478 -- For Comment, we concatenate the string, unless we want
8479 -- to preserve the tree structure for ASIS.
8481 elsif not ASIS_Mode then
8482 Start_String (Strval (CS));
8483 Store_String_Char (' ');
8484 Store_String_Chars (Strval (Str));
8485 Set_Strval (CS, End_String);
8489 -- In VMS, the effect of IDENT is achieved by passing
8490 -- --identification=name as a --for-linker switch.
8492 if OpenVMS_On_Target then
8495 ("--for-linker=--identification=");
8496 String_To_Name_Buffer (Strval (Str));
8497 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8499 -- Only the last processed IDENT is saved. The main
8500 -- purpose is so an IDENT associated with a main
8501 -- procedure will be used in preference to an IDENT
8502 -- associated with a with'd package.
8504 Replace_Linker_Option_String
8505 (End_String, "--for-linker=--identification=");
8508 Set_Ident_String (Current_Sem_Unit, Str);
8511 -- For subunits, we just ignore the Ident, since in GNAT these
8512 -- are not separate object files, and hence not separate units
8513 -- in the unit table.
8515 elsif Nkind (GP) = N_Subunit then
8518 -- Otherwise we have a misplaced pragma Ident, but we ignore
8519 -- this if we are in an instantiation, since it comes from
8520 -- a generic, and has no relevance to the instantiation.
8522 elsif Prag_Id = Pragma_Ident then
8523 if Instantiation_Location (Loc) = No_Location then
8524 Error_Pragma ("pragma% only allowed at outer level");
8534 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8535 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8537 when Pragma_Implemented => Implemented : declare
8538 Proc_Id : Entity_Id;
8543 Check_Arg_Count (2);
8544 Check_No_Identifiers;
8545 Check_Arg_Is_Identifier (Arg1);
8546 Check_Arg_Is_Local_Name (Arg1);
8548 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8550 -- Extract the name of the local procedure
8552 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8554 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8555 -- primitive procedure of a synchronized tagged type.
8557 if Ekind (Proc_Id) = E_Procedure
8558 and then Is_Primitive (Proc_Id)
8559 and then Present (First_Formal (Proc_Id))
8561 Typ := Etype (First_Formal (Proc_Id));
8563 if Is_Tagged_Type (Typ)
8566 -- Check for a protected, a synchronized or a task interface
8568 ((Is_Interface (Typ)
8569 and then Is_Synchronized_Interface (Typ))
8571 -- Check for a protected type or a task type that implements
8575 (Is_Concurrent_Record_Type (Typ)
8576 and then Present (Interfaces (Typ)))
8578 -- Check for a private record extension with keyword
8582 (Ekind_In (Typ, E_Record_Type_With_Private,
8583 E_Record_Subtype_With_Private)
8584 and then Synchronized_Present (Parent (Typ))))
8589 ("controlling formal must be of synchronized " &
8590 "tagged type", Arg1);
8594 -- Procedures declared inside a protected type must be accepted
8596 elsif Ekind (Proc_Id) = E_Procedure
8597 and then Is_Protected_Type (Scope (Proc_Id))
8601 -- The first argument is not a primitive procedure
8605 ("pragma % must be applied to a primitive procedure", Arg1);
8609 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8610 -- By_Protected_Procedure to the primitive procedure of a task
8613 if Chars (Arg2) = Name_By_Protected_Procedure
8614 and then Is_Interface (Typ)
8615 and then Is_Task_Interface (Typ)
8618 ("implementation kind By_Protected_Procedure cannot be " &
8619 "applied to a task interface primitive", Arg2);
8623 Record_Rep_Item (Proc_Id, N);
8626 ----------------------
8627 -- Implicit_Packing --
8628 ----------------------
8630 -- pragma Implicit_Packing;
8632 when Pragma_Implicit_Packing =>
8634 Check_Arg_Count (0);
8635 Implicit_Packing := True;
8642 -- [Convention =>] convention_IDENTIFIER,
8643 -- [Entity =>] local_NAME
8644 -- [, [External_Name =>] static_string_EXPRESSION ]
8645 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8647 when Pragma_Import =>
8648 Check_Ada_83_Warning;
8654 Check_At_Least_N_Arguments (2);
8655 Check_At_Most_N_Arguments (4);
8656 Process_Import_Or_Interface;
8658 ----------------------
8659 -- Import_Exception --
8660 ----------------------
8662 -- pragma Import_Exception (
8663 -- [Internal =>] LOCAL_NAME
8664 -- [, [External =>] EXTERNAL_SYMBOL]
8665 -- [, [Form =>] Ada | VMS]
8666 -- [, [Code =>] static_integer_EXPRESSION]);
8668 when Pragma_Import_Exception => Import_Exception : declare
8669 Args : Args_List (1 .. 4);
8670 Names : constant Name_List (1 .. 4) := (
8676 Internal : Node_Id renames Args (1);
8677 External : Node_Id renames Args (2);
8678 Form : Node_Id renames Args (3);
8679 Code : Node_Id renames Args (4);
8683 Gather_Associations (Names, Args);
8685 if Present (External) and then Present (Code) then
8687 ("cannot give both External and Code options for pragma%");
8690 Process_Extended_Import_Export_Exception_Pragma (
8691 Arg_Internal => Internal,
8692 Arg_External => External,
8696 if not Is_VMS_Exception (Entity (Internal)) then
8697 Set_Imported (Entity (Internal));
8699 end Import_Exception;
8701 ---------------------
8702 -- Import_Function --
8703 ---------------------
8705 -- pragma Import_Function (
8706 -- [Internal =>] LOCAL_NAME,
8707 -- [, [External =>] EXTERNAL_SYMBOL]
8708 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8709 -- [, [Result_Type =>] SUBTYPE_MARK]
8710 -- [, [Mechanism =>] MECHANISM]
8711 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8712 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8714 -- EXTERNAL_SYMBOL ::=
8716 -- | static_string_EXPRESSION
8718 -- PARAMETER_TYPES ::=
8720 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8722 -- TYPE_DESIGNATOR ::=
8724 -- | subtype_Name ' Access
8728 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8730 -- MECHANISM_ASSOCIATION ::=
8731 -- [formal_parameter_NAME =>] MECHANISM_NAME
8733 -- MECHANISM_NAME ::=
8736 -- | Descriptor [([Class =>] CLASS_NAME)]
8738 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8740 when Pragma_Import_Function => Import_Function : declare
8741 Args : Args_List (1 .. 7);
8742 Names : constant Name_List (1 .. 7) := (
8745 Name_Parameter_Types,
8748 Name_Result_Mechanism,
8749 Name_First_Optional_Parameter);
8751 Internal : Node_Id renames Args (1);
8752 External : Node_Id renames Args (2);
8753 Parameter_Types : Node_Id renames Args (3);
8754 Result_Type : Node_Id renames Args (4);
8755 Mechanism : Node_Id renames Args (5);
8756 Result_Mechanism : Node_Id renames Args (6);
8757 First_Optional_Parameter : Node_Id renames Args (7);
8761 Gather_Associations (Names, Args);
8762 Process_Extended_Import_Export_Subprogram_Pragma (
8763 Arg_Internal => Internal,
8764 Arg_External => External,
8765 Arg_Parameter_Types => Parameter_Types,
8766 Arg_Result_Type => Result_Type,
8767 Arg_Mechanism => Mechanism,
8768 Arg_Result_Mechanism => Result_Mechanism,
8769 Arg_First_Optional_Parameter => First_Optional_Parameter);
8770 end Import_Function;
8776 -- pragma Import_Object (
8777 -- [Internal =>] LOCAL_NAME
8778 -- [, [External =>] EXTERNAL_SYMBOL]
8779 -- [, [Size =>] EXTERNAL_SYMBOL]);
8781 -- EXTERNAL_SYMBOL ::=
8783 -- | static_string_EXPRESSION
8785 when Pragma_Import_Object => Import_Object : declare
8786 Args : Args_List (1 .. 3);
8787 Names : constant Name_List (1 .. 3) := (
8792 Internal : Node_Id renames Args (1);
8793 External : Node_Id renames Args (2);
8794 Size : Node_Id renames Args (3);
8798 Gather_Associations (Names, Args);
8799 Process_Extended_Import_Export_Object_Pragma (
8800 Arg_Internal => Internal,
8801 Arg_External => External,
8805 ----------------------
8806 -- Import_Procedure --
8807 ----------------------
8809 -- pragma Import_Procedure (
8810 -- [Internal =>] LOCAL_NAME
8811 -- [, [External =>] EXTERNAL_SYMBOL]
8812 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8813 -- [, [Mechanism =>] MECHANISM]
8814 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8816 -- EXTERNAL_SYMBOL ::=
8818 -- | static_string_EXPRESSION
8820 -- PARAMETER_TYPES ::=
8822 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8824 -- TYPE_DESIGNATOR ::=
8826 -- | subtype_Name ' Access
8830 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8832 -- MECHANISM_ASSOCIATION ::=
8833 -- [formal_parameter_NAME =>] MECHANISM_NAME
8835 -- MECHANISM_NAME ::=
8838 -- | Descriptor [([Class =>] CLASS_NAME)]
8840 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8842 when Pragma_Import_Procedure => Import_Procedure : declare
8843 Args : Args_List (1 .. 5);
8844 Names : constant Name_List (1 .. 5) := (
8847 Name_Parameter_Types,
8849 Name_First_Optional_Parameter);
8851 Internal : Node_Id renames Args (1);
8852 External : Node_Id renames Args (2);
8853 Parameter_Types : Node_Id renames Args (3);
8854 Mechanism : Node_Id renames Args (4);
8855 First_Optional_Parameter : Node_Id renames Args (5);
8859 Gather_Associations (Names, Args);
8860 Process_Extended_Import_Export_Subprogram_Pragma (
8861 Arg_Internal => Internal,
8862 Arg_External => External,
8863 Arg_Parameter_Types => Parameter_Types,
8864 Arg_Mechanism => Mechanism,
8865 Arg_First_Optional_Parameter => First_Optional_Parameter);
8866 end Import_Procedure;
8868 -----------------------------
8869 -- Import_Valued_Procedure --
8870 -----------------------------
8872 -- pragma Import_Valued_Procedure (
8873 -- [Internal =>] LOCAL_NAME
8874 -- [, [External =>] EXTERNAL_SYMBOL]
8875 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8876 -- [, [Mechanism =>] MECHANISM]
8877 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8879 -- EXTERNAL_SYMBOL ::=
8881 -- | static_string_EXPRESSION
8883 -- PARAMETER_TYPES ::=
8885 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8887 -- TYPE_DESIGNATOR ::=
8889 -- | subtype_Name ' Access
8893 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8895 -- MECHANISM_ASSOCIATION ::=
8896 -- [formal_parameter_NAME =>] MECHANISM_NAME
8898 -- MECHANISM_NAME ::=
8901 -- | Descriptor [([Class =>] CLASS_NAME)]
8903 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8905 when Pragma_Import_Valued_Procedure =>
8906 Import_Valued_Procedure : declare
8907 Args : Args_List (1 .. 5);
8908 Names : constant Name_List (1 .. 5) := (
8911 Name_Parameter_Types,
8913 Name_First_Optional_Parameter);
8915 Internal : Node_Id renames Args (1);
8916 External : Node_Id renames Args (2);
8917 Parameter_Types : Node_Id renames Args (3);
8918 Mechanism : Node_Id renames Args (4);
8919 First_Optional_Parameter : Node_Id renames Args (5);
8923 Gather_Associations (Names, Args);
8924 Process_Extended_Import_Export_Subprogram_Pragma (
8925 Arg_Internal => Internal,
8926 Arg_External => External,
8927 Arg_Parameter_Types => Parameter_Types,
8928 Arg_Mechanism => Mechanism,
8929 Arg_First_Optional_Parameter => First_Optional_Parameter);
8930 end Import_Valued_Procedure;
8936 -- pragma Independent (LOCAL_NAME);
8938 when Pragma_Independent => Independent : declare
8945 Check_Ada_83_Warning;
8947 Check_No_Identifiers;
8948 Check_Arg_Count (1);
8949 Check_Arg_Is_Local_Name (Arg1);
8950 E_Id := Get_Pragma_Arg (Arg1);
8952 if Etype (E_Id) = Any_Type then
8957 D := Declaration_Node (E);
8960 -- Check duplicate before we chain ourselves!
8962 Check_Duplicate_Pragma (E);
8964 -- Check appropriate entity
8967 if Rep_Item_Too_Early (E, N)
8969 Rep_Item_Too_Late (E, N)
8973 Check_First_Subtype (Arg1);
8976 elsif K = N_Object_Declaration
8977 or else (K = N_Component_Declaration
8978 and then Original_Record_Component (E) = E)
8980 if Rep_Item_Too_Late (E, N) then
8986 ("inappropriate entity for pragma%", Arg1);
8989 Independence_Checks.Append ((N, E));
8992 ----------------------------
8993 -- Independent_Components --
8994 ----------------------------
8996 -- pragma Atomic_Components (array_LOCAL_NAME);
8998 -- This processing is shared by Volatile_Components
9000 when Pragma_Independent_Components => Independent_Components : declare
9007 Check_Ada_83_Warning;
9009 Check_No_Identifiers;
9010 Check_Arg_Count (1);
9011 Check_Arg_Is_Local_Name (Arg1);
9012 E_Id := Get_Pragma_Arg (Arg1);
9014 if Etype (E_Id) = Any_Type then
9020 -- Check duplicate before we chain ourselves!
9022 Check_Duplicate_Pragma (E);
9024 -- Check appropriate entity
9026 if Rep_Item_Too_Early (E, N)
9028 Rep_Item_Too_Late (E, N)
9033 D := Declaration_Node (E);
9036 if (K = N_Full_Type_Declaration
9037 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9039 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9040 and then Nkind (D) = N_Object_Declaration
9041 and then Nkind (Object_Definition (D)) =
9042 N_Constrained_Array_Definition)
9044 Independence_Checks.Append ((N, E));
9047 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9049 end Independent_Components;
9051 ------------------------
9052 -- Initialize_Scalars --
9053 ------------------------
9055 -- pragma Initialize_Scalars;
9057 when Pragma_Initialize_Scalars =>
9059 Check_Arg_Count (0);
9060 Check_Valid_Configuration_Pragma;
9061 Check_Restriction (No_Initialize_Scalars, N);
9063 -- Initialize_Scalars creates false positives in CodePeer,
9064 -- so ignore this pragma in this mode.
9066 if not Restriction_Active (No_Initialize_Scalars)
9067 and then not CodePeer_Mode
9069 Init_Or_Norm_Scalars := True;
9070 Initialize_Scalars := True;
9077 -- pragma Inline ( NAME {, NAME} );
9079 when Pragma_Inline =>
9081 -- Pragma is active if inlining option is active
9083 Process_Inline (Inline_Active);
9089 -- pragma Inline_Always ( NAME {, NAME} );
9091 when Pragma_Inline_Always =>
9094 -- Pragma always active unless in CodePeer mode, since this causes
9095 -- walk order issues.
9097 if not CodePeer_Mode then
9098 Process_Inline (True);
9101 --------------------
9102 -- Inline_Generic --
9103 --------------------
9105 -- pragma Inline_Generic (NAME {, NAME});
9107 when Pragma_Inline_Generic =>
9109 Process_Generic_List;
9111 ----------------------
9112 -- Inspection_Point --
9113 ----------------------
9115 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9117 when Pragma_Inspection_Point => Inspection_Point : declare
9122 if Arg_Count > 0 then
9125 Exp := Get_Pragma_Arg (Arg);
9128 if not Is_Entity_Name (Exp)
9129 or else not Is_Object (Entity (Exp))
9131 Error_Pragma_Arg ("object name required", Arg);
9138 end Inspection_Point;
9144 -- pragma Interface (
9145 -- [ Convention =>] convention_IDENTIFIER,
9146 -- [ Entity =>] local_NAME
9147 -- [, [External_Name =>] static_string_EXPRESSION ]
9148 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9150 when Pragma_Interface =>
9157 Check_At_Least_N_Arguments (2);
9158 Check_At_Most_N_Arguments (4);
9159 Process_Import_Or_Interface;
9161 -- In Ada 2005, the permission to use Interface (a reserved word)
9162 -- as a pragma name is considered an obsolescent feature.
9164 if Ada_Version >= Ada_2005 then
9166 (No_Obsolescent_Features, Pragma_Identifier (N));
9169 --------------------
9170 -- Interface_Name --
9171 --------------------
9173 -- pragma Interface_Name (
9174 -- [ Entity =>] local_NAME
9175 -- [,[External_Name =>] static_string_EXPRESSION ]
9176 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9178 when Pragma_Interface_Name => Interface_Name : declare
9187 ((Name_Entity, Name_External_Name, Name_Link_Name));
9188 Check_At_Least_N_Arguments (2);
9189 Check_At_Most_N_Arguments (3);
9190 Id := Get_Pragma_Arg (Arg1);
9193 if not Is_Entity_Name (Id) then
9195 ("first argument for pragma% must be entity name", Arg1);
9196 elsif Etype (Id) = Any_Type then
9199 Def_Id := Entity (Id);
9202 -- Special DEC-compatible processing for the object case, forces
9203 -- object to be imported.
9205 if Ekind (Def_Id) = E_Variable then
9206 Kill_Size_Check_Code (Def_Id);
9207 Note_Possible_Modification (Id, Sure => False);
9209 -- Initialization is not allowed for imported variable
9211 if Present (Expression (Parent (Def_Id)))
9212 and then Comes_From_Source (Expression (Parent (Def_Id)))
9214 Error_Msg_Sloc := Sloc (Def_Id);
9216 ("no initialization allowed for declaration of& #",
9220 -- For compatibility, support VADS usage of providing both
9221 -- pragmas Interface and Interface_Name to obtain the effect
9222 -- of a single Import pragma.
9224 if Is_Imported (Def_Id)
9225 and then Present (First_Rep_Item (Def_Id))
9226 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9228 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9232 Set_Imported (Def_Id);
9235 Set_Is_Public (Def_Id);
9236 Process_Interface_Name (Def_Id, Arg2, Arg3);
9239 -- Otherwise must be subprogram
9241 elsif not Is_Subprogram (Def_Id) then
9243 ("argument of pragma% is not subprogram", Arg1);
9246 Check_At_Most_N_Arguments (3);
9250 -- Loop through homonyms
9253 Def_Id := Get_Base_Subprogram (Hom_Id);
9255 if Is_Imported (Def_Id) then
9256 Process_Interface_Name (Def_Id, Arg2, Arg3);
9260 exit when From_Aspect_Specification (N);
9261 Hom_Id := Homonym (Hom_Id);
9263 exit when No (Hom_Id)
9264 or else Scope (Hom_Id) /= Current_Scope;
9269 ("argument of pragma% is not imported subprogram",
9275 -----------------------
9276 -- Interrupt_Handler --
9277 -----------------------
9279 -- pragma Interrupt_Handler (handler_NAME);
9281 when Pragma_Interrupt_Handler =>
9282 Check_Ada_83_Warning;
9283 Check_Arg_Count (1);
9284 Check_No_Identifiers;
9286 if No_Run_Time_Mode then
9287 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9289 Check_Interrupt_Or_Attach_Handler;
9290 Process_Interrupt_Or_Attach_Handler;
9293 ------------------------
9294 -- Interrupt_Priority --
9295 ------------------------
9297 -- pragma Interrupt_Priority [(EXPRESSION)];
9299 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9300 P : constant Node_Id := Parent (N);
9304 Check_Ada_83_Warning;
9306 if Arg_Count /= 0 then
9307 Arg := Get_Pragma_Arg (Arg1);
9308 Check_Arg_Count (1);
9309 Check_No_Identifiers;
9311 -- The expression must be analyzed in the special manner
9312 -- described in "Handling of Default and Per-Object
9313 -- Expressions" in sem.ads.
9315 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9318 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9322 elsif Has_Pragma_Priority (P) then
9323 Error_Pragma ("duplicate pragma% not allowed");
9326 Set_Has_Pragma_Priority (P, True);
9327 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9329 end Interrupt_Priority;
9331 ---------------------
9332 -- Interrupt_State --
9333 ---------------------
9335 -- pragma Interrupt_State (
9336 -- [Name =>] INTERRUPT_ID,
9337 -- [State =>] INTERRUPT_STATE);
9339 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9340 -- INTERRUPT_STATE => System | Runtime | User
9342 -- Note: if the interrupt id is given as an identifier, then it must
9343 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9344 -- given as a static integer expression which must be in the range of
9345 -- Ada.Interrupts.Interrupt_ID.
9347 when Pragma_Interrupt_State => Interrupt_State : declare
9349 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9350 -- This is the entity Ada.Interrupts.Interrupt_ID;
9352 State_Type : Character;
9353 -- Set to 's'/'r'/'u' for System/Runtime/User
9356 -- Index to entry in Interrupt_States table
9359 -- Value of interrupt
9361 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9362 -- The first argument to the pragma
9364 Int_Ent : Entity_Id;
9365 -- Interrupt entity in Ada.Interrupts.Names
9369 Check_Arg_Order ((Name_Name, Name_State));
9370 Check_Arg_Count (2);
9372 Check_Optional_Identifier (Arg1, Name_Name);
9373 Check_Optional_Identifier (Arg2, Name_State);
9374 Check_Arg_Is_Identifier (Arg2);
9376 -- First argument is identifier
9378 if Nkind (Arg1X) = N_Identifier then
9380 -- Search list of names in Ada.Interrupts.Names
9382 Int_Ent := First_Entity (RTE (RE_Names));
9384 if No (Int_Ent) then
9385 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9387 elsif Chars (Int_Ent) = Chars (Arg1X) then
9388 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9392 Next_Entity (Int_Ent);
9395 -- First argument is not an identifier, so it must be a static
9396 -- expression of type Ada.Interrupts.Interrupt_ID.
9399 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9400 Int_Val := Expr_Value (Arg1X);
9402 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9404 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9407 ("value not in range of type " &
9408 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9414 case Chars (Get_Pragma_Arg (Arg2)) is
9415 when Name_Runtime => State_Type := 'r';
9416 when Name_System => State_Type := 's';
9417 when Name_User => State_Type := 'u';
9420 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9423 -- Check if entry is already stored
9425 IST_Num := Interrupt_States.First;
9427 -- If entry not found, add it
9429 if IST_Num > Interrupt_States.Last then
9430 Interrupt_States.Append
9431 ((Interrupt_Number => UI_To_Int (Int_Val),
9432 Interrupt_State => State_Type,
9433 Pragma_Loc => Loc));
9436 -- Case of entry for the same entry
9438 elsif Int_Val = Interrupt_States.Table (IST_Num).
9441 -- If state matches, done, no need to make redundant entry
9444 State_Type = Interrupt_States.Table (IST_Num).
9447 -- Otherwise if state does not match, error
9450 Interrupt_States.Table (IST_Num).Pragma_Loc;
9452 ("state conflicts with that given #", Arg2);
9456 IST_Num := IST_Num + 1;
9458 end Interrupt_State;
9465 -- ([Entity =>] type_LOCAL_NAME,
9466 -- [Check =>] EXPRESSION
9467 -- [,[Message =>] String_Expression]);
9469 when Pragma_Invariant => Invariant : declare
9474 pragma Unreferenced (Discard);
9478 Check_At_Least_N_Arguments (2);
9479 Check_At_Most_N_Arguments (3);
9480 Check_Optional_Identifier (Arg1, Name_Entity);
9481 Check_Optional_Identifier (Arg2, Name_Check);
9483 if Arg_Count = 3 then
9484 Check_Optional_Identifier (Arg3, Name_Message);
9485 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9488 Check_Arg_Is_Local_Name (Arg1);
9490 Type_Id := Get_Pragma_Arg (Arg1);
9491 Find_Type (Type_Id);
9492 Typ := Entity (Type_Id);
9494 if Typ = Any_Type then
9497 elsif not Ekind_In (Typ, E_Private_Type,
9498 E_Record_Type_With_Private,
9499 E_Limited_Private_Type)
9502 ("pragma% only allowed for private type", Arg1);
9505 -- Note that the type has at least one invariant, and also that
9506 -- it has inheritable invariants if we have Invariant'Class.
9508 Set_Has_Invariants (Typ);
9510 if Class_Present (N) then
9511 Set_Has_Inheritable_Invariants (Typ);
9514 -- The remaining processing is simply to link the pragma on to
9515 -- the rep item chain, for processing when the type is frozen.
9516 -- This is accomplished by a call to Rep_Item_Too_Late.
9518 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9521 ----------------------
9522 -- Java_Constructor --
9523 ----------------------
9525 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9527 -- Also handles pragma CIL_Constructor
9529 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9530 Java_Constructor : declare
9531 Convention : Convention_Id;
9535 This_Formal : Entity_Id;
9539 Check_Arg_Count (1);
9540 Check_Optional_Identifier (Arg1, Name_Entity);
9541 Check_Arg_Is_Local_Name (Arg1);
9543 Id := Get_Pragma_Arg (Arg1);
9544 Find_Program_Unit_Name (Id);
9546 -- If we did not find the name, we are done
9548 if Etype (Id) = Any_Type then
9552 -- Check wrong use of pragma in wrong VM target
9554 if VM_Target = No_VM then
9557 elsif VM_Target = CLI_Target
9558 and then Prag_Id = Pragma_Java_Constructor
9560 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9562 elsif VM_Target = JVM_Target
9563 and then Prag_Id = Pragma_CIL_Constructor
9565 Error_Pragma ("must use pragma 'Java_'Constructor");
9569 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9570 when Pragma_Java_Constructor => Convention := Convention_Java;
9571 when others => null;
9574 Hom_Id := Entity (Id);
9576 -- Loop through homonyms
9579 Def_Id := Get_Base_Subprogram (Hom_Id);
9581 -- The constructor is required to be a function
9583 if Ekind (Def_Id) /= E_Function then
9584 if VM_Target = JVM_Target then
9586 ("pragma% requires function returning a " &
9587 "'Java access type", Def_Id);
9590 ("pragma% requires function returning a " &
9591 "'C'I'L access type", Def_Id);
9595 -- Check arguments: For tagged type the first formal must be
9596 -- named "this" and its type must be a named access type
9597 -- designating a class-wide tagged type that has convention
9598 -- CIL/Java. The first formal must also have a null default
9599 -- value. For example:
9601 -- type Typ is tagged ...
9602 -- type Ref is access all Typ;
9603 -- pragma Convention (CIL, Typ);
9605 -- function New_Typ (This : Ref) return Ref;
9606 -- function New_Typ (This : Ref; I : Integer) return Ref;
9607 -- pragma Cil_Constructor (New_Typ);
9609 -- Reason: The first formal must NOT be a primitive of the
9612 -- This rule also applies to constructors of delegates used
9613 -- to interface with standard target libraries. For example:
9615 -- type Delegate is access procedure ...
9616 -- pragma Import (CIL, Delegate, ...);
9618 -- function new_Delegate
9619 -- (This : Delegate := null; ... ) return Delegate;
9621 -- For value-types this rule does not apply.
9623 if not Is_Value_Type (Etype (Def_Id)) then
9624 if No (First_Formal (Def_Id)) then
9625 Error_Msg_Name_1 := Pname;
9626 Error_Msg_N ("% function must have parameters", Def_Id);
9630 -- In the JRE library we have several occurrences in which
9631 -- the "this" parameter is not the first formal.
9633 This_Formal := First_Formal (Def_Id);
9635 -- In the JRE library we have several occurrences in which
9636 -- the "this" parameter is not the first formal. Search for
9639 if VM_Target = JVM_Target then
9640 while Present (This_Formal)
9641 and then Get_Name_String (Chars (This_Formal)) /= "this"
9643 Next_Formal (This_Formal);
9646 if No (This_Formal) then
9647 This_Formal := First_Formal (Def_Id);
9651 -- Warning: The first parameter should be named "this".
9652 -- We temporarily allow it because we have the following
9653 -- case in the Java runtime (file s-osinte.ads) ???
9655 -- function new_Thread
9656 -- (Self_Id : System.Address) return Thread_Id;
9657 -- pragma Java_Constructor (new_Thread);
9659 if VM_Target = JVM_Target
9660 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9662 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9666 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9667 Error_Msg_Name_1 := Pname;
9669 ("first formal of % function must be named `this`",
9670 Parent (This_Formal));
9672 elsif not Is_Access_Type (Etype (This_Formal)) then
9673 Error_Msg_Name_1 := Pname;
9675 ("first formal of % function must be an access type",
9676 Parameter_Type (Parent (This_Formal)));
9678 -- For delegates the type of the first formal must be a
9679 -- named access-to-subprogram type (see previous example)
9681 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9682 and then Ekind (Etype (This_Formal))
9683 /= E_Access_Subprogram_Type
9685 Error_Msg_Name_1 := Pname;
9687 ("first formal of % function must be a named access" &
9688 " to subprogram type",
9689 Parameter_Type (Parent (This_Formal)));
9691 -- Warning: We should reject anonymous access types because
9692 -- the constructor must not be handled as a primitive of the
9693 -- tagged type. We temporarily allow it because this profile
9694 -- is currently generated by cil2ada???
9696 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9697 and then not Ekind_In (Etype (This_Formal),
9699 E_General_Access_Type,
9700 E_Anonymous_Access_Type)
9702 Error_Msg_Name_1 := Pname;
9704 ("first formal of % function must be a named access" &
9706 Parameter_Type (Parent (This_Formal)));
9708 elsif Atree.Convention
9709 (Designated_Type (Etype (This_Formal))) /= Convention
9711 Error_Msg_Name_1 := Pname;
9713 if Convention = Convention_Java then
9715 ("pragma% requires convention 'Cil in designated" &
9717 Parameter_Type (Parent (This_Formal)));
9720 ("pragma% requires convention 'Java in designated" &
9722 Parameter_Type (Parent (This_Formal)));
9725 elsif No (Expression (Parent (This_Formal)))
9726 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9728 Error_Msg_Name_1 := Pname;
9730 ("pragma% requires first formal with default `null`",
9731 Parameter_Type (Parent (This_Formal)));
9735 -- Check result type: the constructor must be a function
9737 -- * a value type (only allowed in the CIL compiler)
9738 -- * an access-to-subprogram type with convention Java/CIL
9739 -- * an access-type designating a type that has convention
9742 if Is_Value_Type (Etype (Def_Id)) then
9745 -- Access-to-subprogram type with convention Java/CIL
9747 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9748 if Atree.Convention (Etype (Def_Id)) /= Convention then
9749 if Convention = Convention_Java then
9751 ("pragma% requires function returning a " &
9752 "'Java access type", Arg1);
9754 pragma Assert (Convention = Convention_CIL);
9756 ("pragma% requires function returning a " &
9757 "'C'I'L access type", Arg1);
9761 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9762 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9763 E_General_Access_Type)
9766 (Designated_Type (Etype (Def_Id))) /= Convention
9768 Error_Msg_Name_1 := Pname;
9770 if Convention = Convention_Java then
9772 ("pragma% requires function returning a named" &
9773 "'Java access type", Arg1);
9776 ("pragma% requires function returning a named" &
9777 "'C'I'L access type", Arg1);
9782 Set_Is_Constructor (Def_Id);
9783 Set_Convention (Def_Id, Convention);
9784 Set_Is_Imported (Def_Id);
9786 exit when From_Aspect_Specification (N);
9787 Hom_Id := Homonym (Hom_Id);
9789 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9791 end Java_Constructor;
9793 ----------------------
9794 -- Java_Interface --
9795 ----------------------
9797 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9799 when Pragma_Java_Interface => Java_Interface : declare
9805 Check_Arg_Count (1);
9806 Check_Optional_Identifier (Arg1, Name_Entity);
9807 Check_Arg_Is_Local_Name (Arg1);
9809 Arg := Get_Pragma_Arg (Arg1);
9812 if Etype (Arg) = Any_Type then
9816 if not Is_Entity_Name (Arg)
9817 or else not Is_Type (Entity (Arg))
9819 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9822 Typ := Underlying_Type (Entity (Arg));
9824 -- For now simply check some of the semantic constraints on the
9825 -- type. This currently leaves out some restrictions on interface
9826 -- types, namely that the parent type must be java.lang.Object.Typ
9827 -- and that all primitives of the type should be declared
9830 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9831 Error_Pragma_Arg ("pragma% requires an abstract "
9832 & "tagged type", Arg1);
9834 elsif not Has_Discriminants (Typ)
9835 or else Ekind (Etype (First_Discriminant (Typ)))
9836 /= E_Anonymous_Access_Type
9838 not Is_Class_Wide_Type
9839 (Designated_Type (Etype (First_Discriminant (Typ))))
9842 ("type must have a class-wide access discriminant", Arg1);
9850 -- pragma Keep_Names ([On => ] local_NAME);
9852 when Pragma_Keep_Names => Keep_Names : declare
9857 Check_Arg_Count (1);
9858 Check_Optional_Identifier (Arg1, Name_On);
9859 Check_Arg_Is_Local_Name (Arg1);
9861 Arg := Get_Pragma_Arg (Arg1);
9864 if Etype (Arg) = Any_Type then
9868 if not Is_Entity_Name (Arg)
9869 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
9872 ("pragma% requires a local enumeration type", Arg1);
9875 Set_Discard_Names (Entity (Arg), False);
9882 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
9884 when Pragma_License =>
9886 Check_Arg_Count (1);
9887 Check_No_Identifiers;
9888 Check_Valid_Configuration_Pragma;
9889 Check_Arg_Is_Identifier (Arg1);
9892 Sind : constant Source_File_Index :=
9893 Source_Index (Current_Sem_Unit);
9896 case Chars (Get_Pragma_Arg (Arg1)) is
9898 Set_License (Sind, GPL);
9900 when Name_Modified_GPL =>
9901 Set_License (Sind, Modified_GPL);
9903 when Name_Restricted =>
9904 Set_License (Sind, Restricted);
9906 when Name_Unrestricted =>
9907 Set_License (Sind, Unrestricted);
9910 Error_Pragma_Arg ("invalid license name", Arg1);
9918 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
9920 when Pragma_Link_With => Link_With : declare
9926 if Operating_Mode = Generate_Code
9927 and then In_Extended_Main_Source_Unit (N)
9929 Check_At_Least_N_Arguments (1);
9930 Check_No_Identifiers;
9931 Check_Is_In_Decl_Part_Or_Package_Spec;
9932 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9936 while Present (Arg) loop
9937 Check_Arg_Is_Static_Expression (Arg, Standard_String);
9939 -- Store argument, converting sequences of spaces to a
9940 -- single null character (this is one of the differences
9941 -- in processing between Link_With and Linker_Options).
9944 C : constant Char_Code := Get_Char_Code (' ');
9945 S : constant String_Id :=
9946 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
9947 L : constant Nat := String_Length (S);
9950 procedure Skip_Spaces;
9951 -- Advance F past any spaces
9957 procedure Skip_Spaces is
9959 while F <= L and then Get_String_Char (S, F) = C loop
9964 -- Start of processing for Arg_Store
9967 Skip_Spaces; -- skip leading spaces
9969 -- Loop through characters, changing any embedded
9970 -- sequence of spaces to a single null character (this
9971 -- is how Link_With/Linker_Options differ)
9974 if Get_String_Char (S, F) = C then
9977 Store_String_Char (ASCII.NUL);
9980 Store_String_Char (Get_String_Char (S, F));
9988 if Present (Arg) then
9989 Store_String_Char (ASCII.NUL);
9993 Store_Linker_Option_String (End_String);
10001 -- pragma Linker_Alias (
10002 -- [Entity =>] LOCAL_NAME
10003 -- [Target =>] static_string_EXPRESSION);
10005 when Pragma_Linker_Alias =>
10007 Check_Arg_Order ((Name_Entity, Name_Target));
10008 Check_Arg_Count (2);
10009 Check_Optional_Identifier (Arg1, Name_Entity);
10010 Check_Optional_Identifier (Arg2, Name_Target);
10011 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10012 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10014 -- The only processing required is to link this item on to the
10015 -- list of rep items for the given entity. This is accomplished
10016 -- by the call to Rep_Item_Too_Late (when no error is detected
10017 -- and False is returned).
10019 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10022 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10025 ------------------------
10026 -- Linker_Constructor --
10027 ------------------------
10029 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10031 -- Code is shared with Linker_Destructor
10033 -----------------------
10034 -- Linker_Destructor --
10035 -----------------------
10037 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10039 when Pragma_Linker_Constructor |
10040 Pragma_Linker_Destructor =>
10041 Linker_Constructor : declare
10047 Check_Arg_Count (1);
10048 Check_No_Identifiers;
10049 Check_Arg_Is_Local_Name (Arg1);
10050 Arg1_X := Get_Pragma_Arg (Arg1);
10052 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10054 if not Is_Library_Level_Entity (Proc) then
10056 ("argument for pragma% must be library level entity", Arg1);
10059 -- The only processing required is to link this item on to the
10060 -- list of rep items for the given entity. This is accomplished
10061 -- by the call to Rep_Item_Too_Late (when no error is detected
10062 -- and False is returned).
10064 if Rep_Item_Too_Late (Proc, N) then
10067 Set_Has_Gigi_Rep_Item (Proc);
10069 end Linker_Constructor;
10071 --------------------
10072 -- Linker_Options --
10073 --------------------
10075 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10077 when Pragma_Linker_Options => Linker_Options : declare
10081 Check_Ada_83_Warning;
10082 Check_No_Identifiers;
10083 Check_Arg_Count (1);
10084 Check_Is_In_Decl_Part_Or_Package_Spec;
10085 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10086 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10089 while Present (Arg) loop
10090 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10091 Store_String_Char (ASCII.NUL);
10093 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10097 if Operating_Mode = Generate_Code
10098 and then In_Extended_Main_Source_Unit (N)
10100 Store_Linker_Option_String (End_String);
10102 end Linker_Options;
10104 --------------------
10105 -- Linker_Section --
10106 --------------------
10108 -- pragma Linker_Section (
10109 -- [Entity =>] LOCAL_NAME
10110 -- [Section =>] static_string_EXPRESSION);
10112 when Pragma_Linker_Section =>
10114 Check_Arg_Order ((Name_Entity, Name_Section));
10115 Check_Arg_Count (2);
10116 Check_Optional_Identifier (Arg1, Name_Entity);
10117 Check_Optional_Identifier (Arg2, Name_Section);
10118 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10119 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10121 -- This pragma applies only to objects
10123 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10124 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10127 -- The only processing required is to link this item on to the
10128 -- list of rep items for the given entity. This is accomplished
10129 -- by the call to Rep_Item_Too_Late (when no error is detected
10130 -- and False is returned).
10132 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10135 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10142 -- pragma List (On | Off)
10144 -- There is nothing to do here, since we did all the processing for
10145 -- this pragma in Par.Prag (so that it works properly even in syntax
10148 when Pragma_List =>
10151 --------------------
10152 -- Locking_Policy --
10153 --------------------
10155 -- pragma Locking_Policy (policy_IDENTIFIER);
10157 when Pragma_Locking_Policy => declare
10161 Check_Ada_83_Warning;
10162 Check_Arg_Count (1);
10163 Check_No_Identifiers;
10164 Check_Arg_Is_Locking_Policy (Arg1);
10165 Check_Valid_Configuration_Pragma;
10166 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10167 LP := Fold_Upper (Name_Buffer (1));
10169 if Locking_Policy /= ' '
10170 and then Locking_Policy /= LP
10172 Error_Msg_Sloc := Locking_Policy_Sloc;
10173 Error_Pragma ("locking policy incompatible with policy#");
10175 -- Set new policy, but always preserve System_Location since we
10176 -- like the error message with the run time name.
10179 Locking_Policy := LP;
10181 if Locking_Policy_Sloc /= System_Location then
10182 Locking_Policy_Sloc := Loc;
10191 -- pragma Long_Float (D_Float | G_Float);
10193 when Pragma_Long_Float =>
10195 Check_Valid_Configuration_Pragma;
10196 Check_Arg_Count (1);
10197 Check_No_Identifier (Arg1);
10198 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10200 if not OpenVMS_On_Target then
10201 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10206 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10207 if Opt.Float_Format_Long = 'G' then
10208 Error_Pragma ("G_Float previously specified");
10211 Opt.Float_Format_Long := 'D';
10213 -- G_Float case (this is the default, does not need overriding)
10216 if Opt.Float_Format_Long = 'D' then
10217 Error_Pragma ("D_Float previously specified");
10220 Opt.Float_Format_Long := 'G';
10223 Set_Standard_Fpt_Formats;
10225 -----------------------
10226 -- Machine_Attribute --
10227 -----------------------
10229 -- pragma Machine_Attribute (
10230 -- [Entity =>] LOCAL_NAME,
10231 -- [Attribute_Name =>] static_string_EXPRESSION
10232 -- [, [Info =>] static_EXPRESSION] );
10234 when Pragma_Machine_Attribute => Machine_Attribute : declare
10235 Def_Id : Entity_Id;
10239 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10241 if Arg_Count = 3 then
10242 Check_Optional_Identifier (Arg3, Name_Info);
10243 Check_Arg_Is_Static_Expression (Arg3);
10245 Check_Arg_Count (2);
10248 Check_Optional_Identifier (Arg1, Name_Entity);
10249 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10250 Check_Arg_Is_Local_Name (Arg1);
10251 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10252 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10254 if Is_Access_Type (Def_Id) then
10255 Def_Id := Designated_Type (Def_Id);
10258 if Rep_Item_Too_Early (Def_Id, N) then
10262 Def_Id := Underlying_Type (Def_Id);
10264 -- The only processing required is to link this item on to the
10265 -- list of rep items for the given entity. This is accomplished
10266 -- by the call to Rep_Item_Too_Late (when no error is detected
10267 -- and False is returned).
10269 if Rep_Item_Too_Late (Def_Id, N) then
10272 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10274 end Machine_Attribute;
10281 -- (MAIN_OPTION [, MAIN_OPTION]);
10284 -- [STACK_SIZE =>] static_integer_EXPRESSION
10285 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10286 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10288 when Pragma_Main => Main : declare
10289 Args : Args_List (1 .. 3);
10290 Names : constant Name_List (1 .. 3) := (
10292 Name_Task_Stack_Size_Default,
10293 Name_Time_Slicing_Enabled);
10299 Gather_Associations (Names, Args);
10301 for J in 1 .. 2 loop
10302 if Present (Args (J)) then
10303 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10307 if Present (Args (3)) then
10308 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10312 while Present (Nod) loop
10313 if Nkind (Nod) = N_Pragma
10314 and then Pragma_Name (Nod) = Name_Main
10316 Error_Msg_Name_1 := Pname;
10317 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10328 -- pragma Main_Storage
10329 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10331 -- MAIN_STORAGE_OPTION ::=
10332 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10333 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10335 when Pragma_Main_Storage => Main_Storage : declare
10336 Args : Args_List (1 .. 2);
10337 Names : constant Name_List (1 .. 2) := (
10338 Name_Working_Storage,
10345 Gather_Associations (Names, Args);
10347 for J in 1 .. 2 loop
10348 if Present (Args (J)) then
10349 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10353 Check_In_Main_Program;
10356 while Present (Nod) loop
10357 if Nkind (Nod) = N_Pragma
10358 and then Pragma_Name (Nod) = Name_Main_Storage
10360 Error_Msg_Name_1 := Pname;
10361 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10372 -- pragma Memory_Size (NUMERIC_LITERAL)
10374 when Pragma_Memory_Size =>
10377 -- Memory size is simply ignored
10379 Check_No_Identifiers;
10380 Check_Arg_Count (1);
10381 Check_Arg_Is_Integer_Literal (Arg1);
10389 -- The only correct use of this pragma is on its own in a file, in
10390 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10391 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10392 -- check for a file containing nothing but a No_Body pragma). If we
10393 -- attempt to process it during normal semantics processing, it means
10394 -- it was misplaced.
10396 when Pragma_No_Body =>
10404 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10406 when Pragma_No_Return => No_Return : declare
10414 Check_At_Least_N_Arguments (1);
10416 -- Loop through arguments of pragma
10419 while Present (Arg) loop
10420 Check_Arg_Is_Local_Name (Arg);
10421 Id := Get_Pragma_Arg (Arg);
10424 if not Is_Entity_Name (Id) then
10425 Error_Pragma_Arg ("entity name required", Arg);
10428 if Etype (Id) = Any_Type then
10432 -- Loop to find matching procedures
10437 and then Scope (E) = Current_Scope
10439 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10442 -- Set flag on any alias as well
10444 if Is_Overloadable (E) and then Present (Alias (E)) then
10445 Set_No_Return (Alias (E));
10451 exit when From_Aspect_Specification (N);
10456 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10467 -- pragma No_Run_Time;
10469 -- Note: this pragma is retained for backwards compatibility. See
10470 -- body of Rtsfind for full details on its handling.
10472 when Pragma_No_Run_Time =>
10474 Check_Valid_Configuration_Pragma;
10475 Check_Arg_Count (0);
10477 No_Run_Time_Mode := True;
10478 Configurable_Run_Time_Mode := True;
10480 -- Set Duration to 32 bits if word size is 32
10482 if Ttypes.System_Word_Size = 32 then
10483 Duration_32_Bits_On_Target := True;
10486 -- Set appropriate restrictions
10488 Set_Restriction (No_Finalization, N);
10489 Set_Restriction (No_Exception_Handlers, N);
10490 Set_Restriction (Max_Tasks, N, 0);
10491 Set_Restriction (No_Tasking, N);
10493 ------------------------
10494 -- No_Strict_Aliasing --
10495 ------------------------
10497 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10499 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10504 Check_At_Most_N_Arguments (1);
10506 if Arg_Count = 0 then
10507 Check_Valid_Configuration_Pragma;
10508 Opt.No_Strict_Aliasing := True;
10511 Check_Optional_Identifier (Arg2, Name_Entity);
10512 Check_Arg_Is_Local_Name (Arg1);
10513 E_Id := Entity (Get_Pragma_Arg (Arg1));
10515 if E_Id = Any_Type then
10517 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10518 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10521 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10523 end No_Strict_Aliasing;
10525 -----------------------
10526 -- Normalize_Scalars --
10527 -----------------------
10529 -- pragma Normalize_Scalars;
10531 when Pragma_Normalize_Scalars =>
10532 Check_Ada_83_Warning;
10533 Check_Arg_Count (0);
10534 Check_Valid_Configuration_Pragma;
10536 -- Normalize_Scalars creates false positives in CodePeer, so
10537 -- ignore this pragma in this mode.
10539 if not CodePeer_Mode then
10540 Normalize_Scalars := True;
10541 Init_Or_Norm_Scalars := True;
10548 -- pragma Obsolescent;
10550 -- pragma Obsolescent (
10551 -- [Message =>] static_string_EXPRESSION
10552 -- [,[Version =>] Ada_05]]);
10554 -- pragma Obsolescent (
10555 -- [Entity =>] NAME
10556 -- [,[Message =>] static_string_EXPRESSION
10557 -- [,[Version =>] Ada_05]] );
10559 when Pragma_Obsolescent => Obsolescent : declare
10563 procedure Set_Obsolescent (E : Entity_Id);
10564 -- Given an entity Ent, mark it as obsolescent if appropriate
10566 ---------------------
10567 -- Set_Obsolescent --
10568 ---------------------
10570 procedure Set_Obsolescent (E : Entity_Id) is
10579 -- Entity name was given
10581 if Present (Ename) then
10583 -- If entity name matches, we are fine. Save entity in
10584 -- pragma argument, for ASIS use.
10586 if Chars (Ename) = Chars (Ent) then
10587 Set_Entity (Ename, Ent);
10588 Generate_Reference (Ent, Ename);
10590 -- If entity name does not match, only possibility is an
10591 -- enumeration literal from an enumeration type declaration.
10593 elsif Ekind (Ent) /= E_Enumeration_Type then
10595 ("pragma % entity name does not match declaration");
10598 Ent := First_Literal (E);
10602 ("pragma % entity name does not match any " &
10603 "enumeration literal");
10605 elsif Chars (Ent) = Chars (Ename) then
10606 Set_Entity (Ename, Ent);
10607 Generate_Reference (Ent, Ename);
10611 Ent := Next_Literal (Ent);
10617 -- Ent points to entity to be marked
10619 if Arg_Count >= 1 then
10621 -- Deal with static string argument
10623 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10624 S := Strval (Get_Pragma_Arg (Arg1));
10626 for J in 1 .. String_Length (S) loop
10627 if not In_Character_Range (Get_String_Char (S, J)) then
10629 ("pragma% argument does not allow wide characters",
10634 Obsolescent_Warnings.Append
10635 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10637 -- Check for Ada_05 parameter
10639 if Arg_Count /= 1 then
10640 Check_Arg_Count (2);
10643 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10646 Check_Arg_Is_Identifier (Argx);
10648 if Chars (Argx) /= Name_Ada_05 then
10649 Error_Msg_Name_2 := Name_Ada_05;
10651 ("only allowed argument for pragma% is %", Argx);
10654 if Ada_Version_Explicit < Ada_2005
10655 or else not Warn_On_Ada_2005_Compatibility
10663 -- Set flag if pragma active
10666 Set_Is_Obsolescent (Ent);
10670 end Set_Obsolescent;
10672 -- Start of processing for pragma Obsolescent
10677 Check_At_Most_N_Arguments (3);
10679 -- See if first argument specifies an entity name
10683 (Chars (Arg1) = Name_Entity
10685 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10687 N_Operator_Symbol))
10689 Ename := Get_Pragma_Arg (Arg1);
10691 -- Eliminate first argument, so we can share processing
10695 Arg_Count := Arg_Count - 1;
10697 -- No Entity name argument given
10703 if Arg_Count >= 1 then
10704 Check_Optional_Identifier (Arg1, Name_Message);
10706 if Arg_Count = 2 then
10707 Check_Optional_Identifier (Arg2, Name_Version);
10711 -- Get immediately preceding declaration
10714 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10718 -- Cases where we do not follow anything other than another pragma
10722 -- First case: library level compilation unit declaration with
10723 -- the pragma immediately following the declaration.
10725 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10727 (Defining_Entity (Unit (Parent (Parent (N)))));
10730 -- Case 2: library unit placement for package
10734 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10736 if Is_Package_Or_Generic_Package (Ent) then
10737 Set_Obsolescent (Ent);
10743 -- Cases where we must follow a declaration
10746 if Nkind (Decl) not in N_Declaration
10747 and then Nkind (Decl) not in N_Later_Decl_Item
10748 and then Nkind (Decl) not in N_Generic_Declaration
10749 and then Nkind (Decl) not in N_Renaming_Declaration
10752 ("pragma% misplaced, "
10753 & "must immediately follow a declaration");
10756 Set_Obsolescent (Defining_Entity (Decl));
10766 -- pragma Optimize (Time | Space | Off);
10768 -- The actual check for optimize is done in Gigi. Note that this
10769 -- pragma does not actually change the optimization setting, it
10770 -- simply checks that it is consistent with the pragma.
10772 when Pragma_Optimize =>
10773 Check_No_Identifiers;
10774 Check_Arg_Count (1);
10775 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10777 ------------------------
10778 -- Optimize_Alignment --
10779 ------------------------
10781 -- pragma Optimize_Alignment (Time | Space | Off);
10783 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10785 Check_No_Identifiers;
10786 Check_Arg_Count (1);
10787 Check_Valid_Configuration_Pragma;
10790 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10794 Opt.Optimize_Alignment := 'T';
10796 Opt.Optimize_Alignment := 'S';
10798 Opt.Optimize_Alignment := 'O';
10800 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10804 -- Set indication that mode is set locally. If we are in fact in a
10805 -- configuration pragma file, this setting is harmless since the
10806 -- switch will get reset anyway at the start of each unit.
10808 Optimize_Alignment_Local := True;
10809 end Optimize_Alignment;
10815 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10817 when Pragma_Ordered => Ordered : declare
10818 Assoc : constant Node_Id := Arg1;
10824 Check_No_Identifiers;
10825 Check_Arg_Count (1);
10826 Check_Arg_Is_Local_Name (Arg1);
10828 Type_Id := Get_Pragma_Arg (Assoc);
10829 Find_Type (Type_Id);
10830 Typ := Entity (Type_Id);
10832 if Typ = Any_Type then
10835 Typ := Underlying_Type (Typ);
10838 if not Is_Enumeration_Type (Typ) then
10839 Error_Pragma ("pragma% must specify enumeration type");
10842 Check_First_Subtype (Arg1);
10843 Set_Has_Pragma_Ordered (Base_Type (Typ));
10850 -- pragma Pack (first_subtype_LOCAL_NAME);
10852 when Pragma_Pack => Pack : declare
10853 Assoc : constant Node_Id := Arg1;
10857 Ignore : Boolean := False;
10860 Check_No_Identifiers;
10861 Check_Arg_Count (1);
10862 Check_Arg_Is_Local_Name (Arg1);
10864 Type_Id := Get_Pragma_Arg (Assoc);
10865 Find_Type (Type_Id);
10866 Typ := Entity (Type_Id);
10869 or else Rep_Item_Too_Early (Typ, N)
10873 Typ := Underlying_Type (Typ);
10876 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
10877 Error_Pragma ("pragma% must specify array or record type");
10880 Check_First_Subtype (Arg1);
10881 Check_Duplicate_Pragma (Typ);
10885 if Is_Array_Type (Typ) then
10886 Ctyp := Component_Type (Typ);
10888 -- Ignore pack that does nothing
10890 if Known_Static_Esize (Ctyp)
10891 and then Known_Static_RM_Size (Ctyp)
10892 and then Esize (Ctyp) = RM_Size (Ctyp)
10893 and then Addressable (Esize (Ctyp))
10898 -- Process OK pragma Pack. Note that if there is a separate
10899 -- component clause present, the Pack will be cancelled. This
10900 -- processing is in Freeze.
10902 if not Rep_Item_Too_Late (Typ, N) then
10904 -- In the context of static code analysis, we do not need
10905 -- complex front-end expansions related to pragma Pack,
10906 -- so disable handling of pragma Pack in this case.
10908 if CodePeer_Mode then
10911 -- Don't attempt any packing for VM targets. We possibly
10912 -- could deal with some cases of array bit-packing, but we
10913 -- don't bother, since this is not a typical kind of
10914 -- representation in the VM context anyway (and would not
10915 -- for example work nicely with the debugger).
10917 elsif VM_Target /= No_VM then
10918 if not GNAT_Mode then
10920 ("?pragma% ignored in this configuration");
10923 -- Normal case where we do the pack action
10927 Set_Is_Packed (Base_Type (Typ), Sense);
10928 Set_Has_Non_Standard_Rep (Base_Type (Typ), Sense);
10931 Set_Has_Pragma_Pack (Base_Type (Typ), Sense);
10933 -- Complete reset action for Aspect_Cancel case
10935 if Sense = False then
10937 -- Cancel size unless explicitly set
10939 if not Has_Size_Clause (Typ)
10940 and then not Has_Object_Size_Clause (Typ)
10942 Set_Esize (Typ, Uint_0);
10943 Set_RM_Size (Typ, Uint_0);
10944 Set_Alignment (Typ, Uint_0);
10945 Set_Packed_Array_Type (Typ, Empty);
10948 -- Reset component size unless explicitly set
10950 if not Has_Component_Size_Clause (Typ) then
10951 if Known_Static_Esize (Ctyp)
10952 and then Known_Static_RM_Size (Ctyp)
10953 and then Esize (Ctyp) = RM_Size (Ctyp)
10954 and then Addressable (Esize (Ctyp))
10957 (Base_Type (Typ), Esize (Ctyp));
10960 (Base_Type (Typ), Uint_0);
10967 -- For record types, the pack is always effective
10969 else pragma Assert (Is_Record_Type (Typ));
10970 if not Rep_Item_Too_Late (Typ, N) then
10972 -- Ignore pack request with warning in VM mode (skip warning
10973 -- if we are compiling GNAT run time library).
10975 if VM_Target /= No_VM then
10976 if not GNAT_Mode then
10978 ("?pragma% ignored in this configuration");
10981 -- Normal case of pack request active
10984 Set_Is_Packed (Base_Type (Typ), Sense);
10985 Set_Has_Pragma_Pack (Base_Type (Typ), Sense);
10986 Set_Has_Non_Standard_Rep (Base_Type (Typ), Sense);
10988 -- Complete reset action for Aspect_Cancel case
10990 if Sense = False then
10992 -- Cancel size if not explicitly given
10994 if not Has_Size_Clause (Typ)
10995 and then not Has_Object_Size_Clause (Typ)
10997 Set_Esize (Typ, Uint_0);
10998 Set_Alignment (Typ, Uint_0);
11012 -- There is nothing to do here, since we did all the processing for
11013 -- this pragma in Par.Prag (so that it works properly even in syntax
11016 when Pragma_Page =>
11023 -- pragma Passive [(PASSIVE_FORM)];
11025 -- PASSIVE_FORM ::= Semaphore | No
11027 when Pragma_Passive =>
11030 if Nkind (Parent (N)) /= N_Task_Definition then
11031 Error_Pragma ("pragma% must be within task definition");
11034 if Arg_Count /= 0 then
11035 Check_Arg_Count (1);
11036 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11039 ----------------------------------
11040 -- Preelaborable_Initialization --
11041 ----------------------------------
11043 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11045 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11050 Check_Arg_Count (1);
11051 Check_No_Identifiers;
11052 Check_Arg_Is_Identifier (Arg1);
11053 Check_Arg_Is_Local_Name (Arg1);
11054 Check_First_Subtype (Arg1);
11055 Ent := Entity (Get_Pragma_Arg (Arg1));
11057 if not (Is_Private_Type (Ent)
11059 Is_Protected_Type (Ent)
11061 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11064 ("pragma % can only be applied to private, formal derived or "
11065 & "protected type",
11069 -- Give an error if the pragma is applied to a protected type that
11070 -- does not qualify (due to having entries, or due to components
11071 -- that do not qualify).
11073 if Is_Protected_Type (Ent)
11074 and then not Has_Preelaborable_Initialization (Ent)
11077 ("protected type & does not have preelaborable " &
11078 "initialization", Ent);
11080 -- Otherwise mark the type as definitely having preelaborable
11084 Set_Known_To_Have_Preelab_Init (Ent);
11087 if Has_Pragma_Preelab_Init (Ent)
11088 and then Warn_On_Redundant_Constructs
11090 Error_Pragma ("?duplicate pragma%!");
11092 Set_Has_Pragma_Preelab_Init (Ent);
11096 --------------------
11097 -- Persistent_BSS --
11098 --------------------
11100 -- pragma Persistent_BSS [(object_NAME)];
11102 when Pragma_Persistent_BSS => Persistent_BSS : declare
11109 Check_At_Most_N_Arguments (1);
11111 -- Case of application to specific object (one argument)
11113 if Arg_Count = 1 then
11114 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11116 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11118 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11121 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11124 Ent := Entity (Get_Pragma_Arg (Arg1));
11125 Decl := Parent (Ent);
11127 if Rep_Item_Too_Late (Ent, N) then
11131 if Present (Expression (Decl)) then
11133 ("object for pragma% cannot have initialization", Arg1);
11136 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11138 ("object type for pragma% is not potentially persistent",
11142 Check_Duplicate_Pragma (Ent);
11146 Make_Linker_Section_Pragma
11147 (Ent, Sloc (N), ".persistent.bss");
11148 Insert_After (N, Prag);
11152 -- Case of use as configuration pragma with no arguments
11155 Check_Valid_Configuration_Pragma;
11156 Persistent_BSS_Mode := True;
11158 end Persistent_BSS;
11164 -- pragma Polling (ON | OFF);
11166 when Pragma_Polling =>
11168 Check_Arg_Count (1);
11169 Check_No_Identifiers;
11170 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11171 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11173 -------------------
11174 -- Postcondition --
11175 -------------------
11177 -- pragma Postcondition ([Check =>] Boolean_Expression
11178 -- [,[Message =>] String_Expression]);
11180 when Pragma_Postcondition => Postcondition : declare
11182 pragma Warnings (Off, In_Body);
11186 Check_At_Least_N_Arguments (1);
11187 Check_At_Most_N_Arguments (2);
11188 Check_Optional_Identifier (Arg1, Name_Check);
11190 -- All we need to do here is call the common check procedure,
11191 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11193 Check_Precondition_Postcondition (In_Body);
11200 -- pragma Precondition ([Check =>] Boolean_Expression
11201 -- [,[Message =>] String_Expression]);
11203 when Pragma_Precondition => Precondition : declare
11208 Check_At_Least_N_Arguments (1);
11209 Check_At_Most_N_Arguments (2);
11210 Check_Optional_Identifier (Arg1, Name_Check);
11211 Check_Precondition_Postcondition (In_Body);
11213 -- If in spec, nothing more to do. If in body, then we convert the
11214 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11215 -- this whether or not precondition checks are enabled. That works
11216 -- fine since pragma Check will do this check, and will also
11217 -- analyze the condition itself in the proper context.
11222 Chars => Name_Check,
11223 Pragma_Argument_Associations => New_List (
11224 Make_Pragma_Argument_Association (Loc,
11225 Expression => Make_Identifier (Loc, Name_Precondition)),
11227 Make_Pragma_Argument_Association (Sloc (Arg1),
11228 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11230 if Arg_Count = 2 then
11231 Append_To (Pragma_Argument_Associations (N),
11232 Make_Pragma_Argument_Association (Sloc (Arg2),
11233 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11244 -- pragma Predicate
11245 -- ([Entity =>] type_LOCAL_NAME,
11246 -- [Check =>] EXPRESSION);
11248 when Pragma_Predicate => Predicate : declare
11253 pragma Unreferenced (Discard);
11257 Check_Arg_Count (2);
11258 Check_Optional_Identifier (Arg1, Name_Entity);
11259 Check_Optional_Identifier (Arg2, Name_Check);
11261 Check_Arg_Is_Local_Name (Arg1);
11263 Type_Id := Get_Pragma_Arg (Arg1);
11264 Find_Type (Type_Id);
11265 Typ := Entity (Type_Id);
11267 if Typ = Any_Type then
11271 -- The remaining processing is simply to link the pragma on to
11272 -- the rep item chain, for processing when the type is frozen.
11273 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11274 -- mark the type as having predicates.
11276 Set_Has_Predicates (Typ);
11277 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11284 -- pragma Preelaborate [(library_unit_NAME)];
11286 -- Set the flag Is_Preelaborated of program unit name entity
11288 when Pragma_Preelaborate => Preelaborate : declare
11289 Pa : constant Node_Id := Parent (N);
11290 Pk : constant Node_Kind := Nkind (Pa);
11294 Check_Ada_83_Warning;
11295 Check_Valid_Library_Unit_Pragma;
11297 if Nkind (N) = N_Null_Statement then
11301 Ent := Find_Lib_Unit_Name;
11302 Check_Duplicate_Pragma (Ent);
11304 -- This filters out pragmas inside generic parent then
11305 -- show up inside instantiation
11308 and then not (Pk = N_Package_Specification
11309 and then Present (Generic_Parent (Pa)))
11311 if not Debug_Flag_U then
11312 Set_Is_Preelaborated (Ent, Sense);
11313 Set_Suppress_Elaboration_Warnings (Ent, Sense);
11318 ---------------------
11319 -- Preelaborate_05 --
11320 ---------------------
11322 -- pragma Preelaborate_05 [(library_unit_NAME)];
11324 -- This pragma is useable only in GNAT_Mode, where it is used like
11325 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11326 -- (otherwise it is ignored). This is used to implement AI-362 which
11327 -- recategorizes some run-time packages in Ada 2005 mode.
11329 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11334 Check_Valid_Library_Unit_Pragma;
11336 if not GNAT_Mode then
11337 Error_Pragma ("pragma% only available in GNAT mode");
11340 if Nkind (N) = N_Null_Statement then
11344 -- This is one of the few cases where we need to test the value of
11345 -- Ada_Version_Explicit rather than Ada_Version (which is always
11346 -- set to Ada_2012 in a predefined unit), we need to know the
11347 -- explicit version set to know if this pragma is active.
11349 if Ada_Version_Explicit >= Ada_2005 then
11350 Ent := Find_Lib_Unit_Name;
11351 Set_Is_Preelaborated (Ent);
11352 Set_Suppress_Elaboration_Warnings (Ent);
11354 end Preelaborate_05;
11360 -- pragma Priority (EXPRESSION);
11362 when Pragma_Priority => Priority : declare
11363 P : constant Node_Id := Parent (N);
11367 Check_No_Identifiers;
11368 Check_Arg_Count (1);
11372 if Nkind (P) = N_Subprogram_Body then
11373 Check_In_Main_Program;
11375 Arg := Get_Pragma_Arg (Arg1);
11376 Analyze_And_Resolve (Arg, Standard_Integer);
11380 if not Is_Static_Expression (Arg) then
11381 Flag_Non_Static_Expr
11382 ("main subprogram priority is not static!", Arg);
11385 -- If constraint error, then we already signalled an error
11387 elsif Raises_Constraint_Error (Arg) then
11390 -- Otherwise check in range
11394 Val : constant Uint := Expr_Value (Arg);
11398 or else Val > Expr_Value (Expression
11399 (Parent (RTE (RE_Max_Priority))))
11402 ("main subprogram priority is out of range", Arg1);
11408 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11410 -- Load an arbitrary entity from System.Tasking to make sure
11411 -- this package is implicitly with'ed, since we need to have
11412 -- the tasking run-time active for the pragma Priority to have
11416 Discard : Entity_Id;
11417 pragma Warnings (Off, Discard);
11419 Discard := RTE (RE_Task_List);
11422 -- Task or Protected, must be of type Integer
11424 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11425 Arg := Get_Pragma_Arg (Arg1);
11427 -- The expression must be analyzed in the special manner
11428 -- described in "Handling of Default and Per-Object
11429 -- Expressions" in sem.ads.
11431 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11433 if not Is_Static_Expression (Arg) then
11434 Check_Restriction (Static_Priorities, Arg);
11437 -- Anything else is incorrect
11443 if Has_Pragma_Priority (P) then
11444 Error_Pragma ("duplicate pragma% not allowed");
11446 Set_Has_Pragma_Priority (P, True);
11448 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11449 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11450 -- exp_ch9 should use this ???
11455 -----------------------------------
11456 -- Priority_Specific_Dispatching --
11457 -----------------------------------
11459 -- pragma Priority_Specific_Dispatching (
11460 -- policy_IDENTIFIER,
11461 -- first_priority_EXPRESSION,
11462 -- last_priority_EXPRESSION);
11464 when Pragma_Priority_Specific_Dispatching =>
11465 Priority_Specific_Dispatching : declare
11466 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11467 -- This is the entity System.Any_Priority;
11470 Lower_Bound : Node_Id;
11471 Upper_Bound : Node_Id;
11477 Check_Arg_Count (3);
11478 Check_No_Identifiers;
11479 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11480 Check_Valid_Configuration_Pragma;
11481 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11482 DP := Fold_Upper (Name_Buffer (1));
11484 Lower_Bound := Get_Pragma_Arg (Arg2);
11485 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11486 Lower_Val := Expr_Value (Lower_Bound);
11488 Upper_Bound := Get_Pragma_Arg (Arg3);
11489 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11490 Upper_Val := Expr_Value (Upper_Bound);
11492 -- It is not allowed to use Task_Dispatching_Policy and
11493 -- Priority_Specific_Dispatching in the same partition.
11495 if Task_Dispatching_Policy /= ' ' then
11496 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11498 ("pragma% incompatible with Task_Dispatching_Policy#");
11500 -- Check lower bound in range
11502 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11504 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11507 ("first_priority is out of range", Arg2);
11509 -- Check upper bound in range
11511 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11513 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11516 ("last_priority is out of range", Arg3);
11518 -- Check that the priority range is valid
11520 elsif Lower_Val > Upper_Val then
11522 ("last_priority_expression must be greater than" &
11523 " or equal to first_priority_expression");
11525 -- Store the new policy, but always preserve System_Location since
11526 -- we like the error message with the run-time name.
11529 -- Check overlapping in the priority ranges specified in other
11530 -- Priority_Specific_Dispatching pragmas within the same
11531 -- partition. We can only check those we know about!
11534 Specific_Dispatching.First .. Specific_Dispatching.Last
11536 if Specific_Dispatching.Table (J).First_Priority in
11537 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11538 or else Specific_Dispatching.Table (J).Last_Priority in
11539 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11542 Specific_Dispatching.Table (J).Pragma_Loc;
11544 ("priority range overlaps with "
11545 & "Priority_Specific_Dispatching#");
11549 -- The use of Priority_Specific_Dispatching is incompatible
11550 -- with Task_Dispatching_Policy.
11552 if Task_Dispatching_Policy /= ' ' then
11553 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11555 ("Priority_Specific_Dispatching incompatible "
11556 & "with Task_Dispatching_Policy#");
11559 -- The use of Priority_Specific_Dispatching forces ceiling
11562 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11563 Error_Msg_Sloc := Locking_Policy_Sloc;
11565 ("Priority_Specific_Dispatching incompatible "
11566 & "with Locking_Policy#");
11568 -- Set the Ceiling_Locking policy, but preserve System_Location
11569 -- since we like the error message with the run time name.
11572 Locking_Policy := 'C';
11574 if Locking_Policy_Sloc /= System_Location then
11575 Locking_Policy_Sloc := Loc;
11579 -- Add entry in the table
11581 Specific_Dispatching.Append
11582 ((Dispatching_Policy => DP,
11583 First_Priority => UI_To_Int (Lower_Val),
11584 Last_Priority => UI_To_Int (Upper_Val),
11585 Pragma_Loc => Loc));
11587 end Priority_Specific_Dispatching;
11593 -- pragma Profile (profile_IDENTIFIER);
11595 -- profile_IDENTIFIER => Restricted | Ravenscar
11597 when Pragma_Profile =>
11599 Check_Arg_Count (1);
11600 Check_Valid_Configuration_Pragma;
11601 Check_No_Identifiers;
11604 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11606 if Chars (Argx) = Name_Ravenscar then
11607 Set_Ravenscar_Profile (N);
11608 elsif Chars (Argx) = Name_Restricted then
11609 Set_Profile_Restrictions
11610 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11612 Error_Pragma_Arg ("& is not a valid profile", Argx);
11616 ----------------------
11617 -- Profile_Warnings --
11618 ----------------------
11620 -- pragma Profile_Warnings (profile_IDENTIFIER);
11622 -- profile_IDENTIFIER => Restricted | Ravenscar
11624 when Pragma_Profile_Warnings =>
11626 Check_Arg_Count (1);
11627 Check_Valid_Configuration_Pragma;
11628 Check_No_Identifiers;
11631 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11633 if Chars (Argx) = Name_Ravenscar then
11634 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11635 elsif Chars (Argx) = Name_Restricted then
11636 Set_Profile_Restrictions (Restricted, N, Warn => True);
11638 Error_Pragma_Arg ("& is not a valid profile", Argx);
11642 --------------------------
11643 -- Propagate_Exceptions --
11644 --------------------------
11646 -- pragma Propagate_Exceptions;
11648 -- Note: this pragma is obsolete and has no effect
11650 when Pragma_Propagate_Exceptions =>
11652 Check_Arg_Count (0);
11654 if In_Extended_Main_Source_Unit (N) then
11655 Propagate_Exceptions := True;
11662 -- pragma Psect_Object (
11663 -- [Internal =>] LOCAL_NAME,
11664 -- [, [External =>] EXTERNAL_SYMBOL]
11665 -- [, [Size =>] EXTERNAL_SYMBOL]);
11667 when Pragma_Psect_Object | Pragma_Common_Object =>
11668 Psect_Object : declare
11669 Args : Args_List (1 .. 3);
11670 Names : constant Name_List (1 .. 3) := (
11675 Internal : Node_Id renames Args (1);
11676 External : Node_Id renames Args (2);
11677 Size : Node_Id renames Args (3);
11679 Def_Id : Entity_Id;
11681 procedure Check_Too_Long (Arg : Node_Id);
11682 -- Posts message if the argument is an identifier with more
11683 -- than 31 characters, or a string literal with more than
11684 -- 31 characters, and we are operating under VMS
11686 --------------------
11687 -- Check_Too_Long --
11688 --------------------
11690 procedure Check_Too_Long (Arg : Node_Id) is
11691 X : constant Node_Id := Original_Node (Arg);
11694 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11696 ("inappropriate argument for pragma %", Arg);
11699 if OpenVMS_On_Target then
11700 if (Nkind (X) = N_String_Literal
11701 and then String_Length (Strval (X)) > 31)
11703 (Nkind (X) = N_Identifier
11704 and then Length_Of_Name (Chars (X)) > 31)
11707 ("argument for pragma % is longer than 31 characters",
11711 end Check_Too_Long;
11713 -- Start of processing for Common_Object/Psect_Object
11717 Gather_Associations (Names, Args);
11718 Process_Extended_Import_Export_Internal_Arg (Internal);
11720 Def_Id := Entity (Internal);
11722 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11724 ("pragma% must designate an object", Internal);
11727 Check_Too_Long (Internal);
11729 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11731 ("cannot use pragma% for imported/exported object",
11735 if Is_Concurrent_Type (Etype (Internal)) then
11737 ("cannot specify pragma % for task/protected object",
11741 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11743 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11745 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11748 if Ekind (Def_Id) = E_Constant then
11750 ("cannot specify pragma % for a constant", Internal);
11753 if Is_Record_Type (Etype (Internal)) then
11759 Ent := First_Entity (Etype (Internal));
11760 while Present (Ent) loop
11761 Decl := Declaration_Node (Ent);
11763 if Ekind (Ent) = E_Component
11764 and then Nkind (Decl) = N_Component_Declaration
11765 and then Present (Expression (Decl))
11766 and then Warn_On_Export_Import
11769 ("?object for pragma % has defaults", Internal);
11779 if Present (Size) then
11780 Check_Too_Long (Size);
11783 if Present (External) then
11784 Check_Arg_Is_External_Name (External);
11785 Check_Too_Long (External);
11788 -- If all error tests pass, link pragma on to the rep item chain
11790 Record_Rep_Item (Def_Id, N);
11797 -- pragma Pure [(library_unit_NAME)];
11799 when Pragma_Pure => Pure : declare
11803 Check_Ada_83_Warning;
11804 Check_Valid_Library_Unit_Pragma;
11806 if Nkind (N) = N_Null_Statement then
11810 Ent := Find_Lib_Unit_Name;
11812 Set_Has_Pragma_Pure (Ent);
11813 Set_Suppress_Elaboration_Warnings (Ent);
11820 -- pragma Pure_05 [(library_unit_NAME)];
11822 -- This pragma is useable only in GNAT_Mode, where it is used like
11823 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11824 -- it is ignored). It may be used after a pragma Preelaborate, in
11825 -- which case it overrides the effect of the pragma Preelaborate.
11826 -- This is used to implement AI-362 which recategorizes some run-time
11827 -- packages in Ada 2005 mode.
11829 when Pragma_Pure_05 => Pure_05 : declare
11834 Check_Valid_Library_Unit_Pragma;
11836 if not GNAT_Mode then
11837 Error_Pragma ("pragma% only available in GNAT mode");
11840 if Nkind (N) = N_Null_Statement then
11844 -- This is one of the few cases where we need to test the value of
11845 -- Ada_Version_Explicit rather than Ada_Version (which is always
11846 -- set to Ada_2012 in a predefined unit), we need to know the
11847 -- explicit version set to know if this pragma is active.
11849 if Ada_Version_Explicit >= Ada_2005 then
11850 Ent := Find_Lib_Unit_Name;
11851 Set_Is_Preelaborated (Ent, False);
11853 Set_Suppress_Elaboration_Warnings (Ent);
11857 -------------------
11858 -- Pure_Function --
11859 -------------------
11861 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11863 when Pragma_Pure_Function => Pure_Function : declare
11866 Def_Id : Entity_Id;
11867 Effective : Boolean := False;
11871 Check_Arg_Count (1);
11872 Check_Optional_Identifier (Arg1, Name_Entity);
11873 Check_Arg_Is_Local_Name (Arg1);
11874 E_Id := Get_Pragma_Arg (Arg1);
11876 if Error_Posted (E_Id) then
11880 -- Loop through homonyms (overloadings) of referenced entity
11882 E := Entity (E_Id);
11884 if Present (E) then
11886 Def_Id := Get_Base_Subprogram (E);
11888 if not Ekind_In (Def_Id, E_Function,
11889 E_Generic_Function,
11893 ("pragma% requires a function name", Arg1);
11896 Set_Is_Pure (Def_Id, Sense);
11898 if not Has_Pragma_Pure_Function (Def_Id) then
11899 Set_Has_Pragma_Pure_Function (Def_Id, Sense);
11900 Effective := Sense;
11903 exit when From_Aspect_Specification (N);
11905 exit when No (E) or else Scope (E) /= Current_Scope;
11908 if Sense and then not Effective
11909 and then Warn_On_Redundant_Constructs
11912 ("pragma Pure_Function on& is redundant?",
11918 --------------------
11919 -- Queuing_Policy --
11920 --------------------
11922 -- pragma Queuing_Policy (policy_IDENTIFIER);
11924 when Pragma_Queuing_Policy => declare
11928 Check_Ada_83_Warning;
11929 Check_Arg_Count (1);
11930 Check_No_Identifiers;
11931 Check_Arg_Is_Queuing_Policy (Arg1);
11932 Check_Valid_Configuration_Pragma;
11933 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11934 QP := Fold_Upper (Name_Buffer (1));
11936 if Queuing_Policy /= ' '
11937 and then Queuing_Policy /= QP
11939 Error_Msg_Sloc := Queuing_Policy_Sloc;
11940 Error_Pragma ("queuing policy incompatible with policy#");
11942 -- Set new policy, but always preserve System_Location since we
11943 -- like the error message with the run time name.
11946 Queuing_Policy := QP;
11948 if Queuing_Policy_Sloc /= System_Location then
11949 Queuing_Policy_Sloc := Loc;
11954 -----------------------
11955 -- Relative_Deadline --
11956 -----------------------
11958 -- pragma Relative_Deadline (time_span_EXPRESSION);
11960 when Pragma_Relative_Deadline => Relative_Deadline : declare
11961 P : constant Node_Id := Parent (N);
11966 Check_No_Identifiers;
11967 Check_Arg_Count (1);
11969 Arg := Get_Pragma_Arg (Arg1);
11971 -- The expression must be analyzed in the special manner described
11972 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
11974 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
11978 if Nkind (P) = N_Subprogram_Body then
11979 Check_In_Main_Program;
11983 elsif Nkind (P) = N_Task_Definition then
11986 -- Anything else is incorrect
11992 if Has_Relative_Deadline_Pragma (P) then
11993 Error_Pragma ("duplicate pragma% not allowed");
11995 Set_Has_Relative_Deadline_Pragma (P, True);
11997 if Nkind (P) = N_Task_Definition then
11998 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12001 end Relative_Deadline;
12003 ---------------------------
12004 -- Remote_Call_Interface --
12005 ---------------------------
12007 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12009 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12010 Cunit_Node : Node_Id;
12011 Cunit_Ent : Entity_Id;
12015 Check_Ada_83_Warning;
12016 Check_Valid_Library_Unit_Pragma;
12018 if Nkind (N) = N_Null_Statement then
12022 Cunit_Node := Cunit (Current_Sem_Unit);
12023 K := Nkind (Unit (Cunit_Node));
12024 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12026 if K = N_Package_Declaration
12027 or else K = N_Generic_Package_Declaration
12028 or else K = N_Subprogram_Declaration
12029 or else K = N_Generic_Subprogram_Declaration
12030 or else (K = N_Subprogram_Body
12031 and then Acts_As_Spec (Unit (Cunit_Node)))
12036 "pragma% must apply to package or subprogram declaration");
12039 Set_Is_Remote_Call_Interface (Cunit_Ent);
12040 end Remote_Call_Interface;
12046 -- pragma Remote_Types [(library_unit_NAME)];
12048 when Pragma_Remote_Types => Remote_Types : declare
12049 Cunit_Node : Node_Id;
12050 Cunit_Ent : Entity_Id;
12053 Check_Ada_83_Warning;
12054 Check_Valid_Library_Unit_Pragma;
12056 if Nkind (N) = N_Null_Statement then
12060 Cunit_Node := Cunit (Current_Sem_Unit);
12061 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12063 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12064 N_Generic_Package_Declaration)
12067 ("pragma% can only apply to a package declaration");
12070 Set_Is_Remote_Types (Cunit_Ent);
12077 -- pragma Ravenscar;
12079 when Pragma_Ravenscar =>
12081 Check_Arg_Count (0);
12082 Check_Valid_Configuration_Pragma;
12083 Set_Ravenscar_Profile (N);
12085 if Warn_On_Obsolescent_Feature then
12086 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12087 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12090 -------------------------
12091 -- Restricted_Run_Time --
12092 -------------------------
12094 -- pragma Restricted_Run_Time;
12096 when Pragma_Restricted_Run_Time =>
12098 Check_Arg_Count (0);
12099 Check_Valid_Configuration_Pragma;
12100 Set_Profile_Restrictions
12101 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12103 if Warn_On_Obsolescent_Feature then
12105 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12106 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12113 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12116 -- restriction_IDENTIFIER
12117 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12119 when Pragma_Restrictions =>
12120 Process_Restrictions_Or_Restriction_Warnings
12121 (Warn => Treat_Restrictions_As_Warnings);
12123 --------------------------
12124 -- Restriction_Warnings --
12125 --------------------------
12127 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12130 -- restriction_IDENTIFIER
12131 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12133 when Pragma_Restriction_Warnings =>
12135 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12141 -- pragma Reviewable;
12143 when Pragma_Reviewable =>
12144 Check_Ada_83_Warning;
12145 Check_Arg_Count (0);
12147 -- Call dummy debugging function rv. This is done to assist front
12148 -- end debugging. By placing a Reviewable pragma in the source
12149 -- program, a breakpoint on rv catches this place in the source,
12150 -- allowing convenient stepping to the point of interest.
12154 --------------------------
12155 -- Short_Circuit_And_Or --
12156 --------------------------
12158 when Pragma_Short_Circuit_And_Or =>
12160 Check_Arg_Count (0);
12161 Check_Valid_Configuration_Pragma;
12162 Short_Circuit_And_Or := True;
12164 -------------------
12165 -- Share_Generic --
12166 -------------------
12168 -- pragma Share_Generic (NAME {, NAME});
12170 when Pragma_Share_Generic =>
12172 Process_Generic_List;
12178 -- pragma Shared (LOCAL_NAME);
12180 when Pragma_Shared =>
12182 Process_Atomic_Shared_Volatile;
12184 --------------------
12185 -- Shared_Passive --
12186 --------------------
12188 -- pragma Shared_Passive [(library_unit_NAME)];
12190 -- Set the flag Is_Shared_Passive of program unit name entity
12192 when Pragma_Shared_Passive => Shared_Passive : declare
12193 Cunit_Node : Node_Id;
12194 Cunit_Ent : Entity_Id;
12197 Check_Ada_83_Warning;
12198 Check_Valid_Library_Unit_Pragma;
12200 if Nkind (N) = N_Null_Statement then
12204 Cunit_Node := Cunit (Current_Sem_Unit);
12205 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12207 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12208 N_Generic_Package_Declaration)
12211 ("pragma% can only apply to a package declaration");
12214 Set_Is_Shared_Passive (Cunit_Ent);
12215 end Shared_Passive;
12217 -----------------------
12218 -- Short_Descriptors --
12219 -----------------------
12221 -- pragma Short_Descriptors;
12223 when Pragma_Short_Descriptors =>
12225 Check_Arg_Count (0);
12226 Check_Valid_Configuration_Pragma;
12227 Short_Descriptors := True;
12229 ----------------------
12230 -- Source_File_Name --
12231 ----------------------
12233 -- There are five forms for this pragma:
12235 -- pragma Source_File_Name (
12236 -- [UNIT_NAME =>] unit_NAME,
12237 -- BODY_FILE_NAME => STRING_LITERAL
12238 -- [, [INDEX =>] INTEGER_LITERAL]);
12240 -- pragma Source_File_Name (
12241 -- [UNIT_NAME =>] unit_NAME,
12242 -- SPEC_FILE_NAME => STRING_LITERAL
12243 -- [, [INDEX =>] INTEGER_LITERAL]);
12245 -- pragma Source_File_Name (
12246 -- BODY_FILE_NAME => STRING_LITERAL
12247 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12248 -- [, CASING => CASING_SPEC]);
12250 -- pragma Source_File_Name (
12251 -- SPEC_FILE_NAME => STRING_LITERAL
12252 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12253 -- [, CASING => CASING_SPEC]);
12255 -- pragma Source_File_Name (
12256 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12257 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12258 -- [, CASING => CASING_SPEC]);
12260 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12262 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12263 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12264 -- only be used when no project file is used, while SFNP can only be
12265 -- used when a project file is used.
12267 -- No processing here. Processing was completed during parsing, since
12268 -- we need to have file names set as early as possible. Units are
12269 -- loaded well before semantic processing starts.
12271 -- The only processing we defer to this point is the check for
12272 -- correct placement.
12274 when Pragma_Source_File_Name =>
12276 Check_Valid_Configuration_Pragma;
12278 ------------------------------
12279 -- Source_File_Name_Project --
12280 ------------------------------
12282 -- See Source_File_Name for syntax
12284 -- No processing here. Processing was completed during parsing, since
12285 -- we need to have file names set as early as possible. Units are
12286 -- loaded well before semantic processing starts.
12288 -- The only processing we defer to this point is the check for
12289 -- correct placement.
12291 when Pragma_Source_File_Name_Project =>
12293 Check_Valid_Configuration_Pragma;
12295 -- Check that a pragma Source_File_Name_Project is used only in a
12296 -- configuration pragmas file.
12298 -- Pragmas Source_File_Name_Project should only be generated by
12299 -- the Project Manager in configuration pragmas files.
12301 -- This is really an ugly test. It seems to depend on some
12302 -- accidental and undocumented property. At the very least it
12303 -- needs to be documented, but it would be better to have a
12304 -- clean way of testing if we are in a configuration file???
12306 if Present (Parent (N)) then
12308 ("pragma% can only appear in a configuration pragmas file");
12311 ----------------------
12312 -- Source_Reference --
12313 ----------------------
12315 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12317 -- Nothing to do, all processing completed in Par.Prag, since we need
12318 -- the information for possible parser messages that are output.
12320 when Pragma_Source_Reference =>
12323 --------------------------------
12324 -- Static_Elaboration_Desired --
12325 --------------------------------
12327 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12329 when Pragma_Static_Elaboration_Desired =>
12331 Check_At_Most_N_Arguments (1);
12333 if Is_Compilation_Unit (Current_Scope)
12334 and then Ekind (Current_Scope) = E_Package
12336 Set_Static_Elaboration_Desired (Current_Scope, True);
12338 Error_Pragma ("pragma% must apply to a library-level package");
12345 -- pragma Storage_Size (EXPRESSION);
12347 when Pragma_Storage_Size => Storage_Size : declare
12348 P : constant Node_Id := Parent (N);
12352 Check_No_Identifiers;
12353 Check_Arg_Count (1);
12355 -- The expression must be analyzed in the special manner described
12356 -- in "Handling of Default Expressions" in sem.ads.
12358 Arg := Get_Pragma_Arg (Arg1);
12359 Preanalyze_Spec_Expression (Arg, Any_Integer);
12361 if not Is_Static_Expression (Arg) then
12362 Check_Restriction (Static_Storage_Size, Arg);
12365 if Nkind (P) /= N_Task_Definition then
12370 if Has_Storage_Size_Pragma (P) then
12371 Error_Pragma ("duplicate pragma% not allowed");
12373 Set_Has_Storage_Size_Pragma (P, True);
12376 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12377 -- ??? exp_ch9 should use this!
12385 -- pragma Storage_Unit (NUMERIC_LITERAL);
12387 -- Only permitted argument is System'Storage_Unit value
12389 when Pragma_Storage_Unit =>
12390 Check_No_Identifiers;
12391 Check_Arg_Count (1);
12392 Check_Arg_Is_Integer_Literal (Arg1);
12394 if Intval (Get_Pragma_Arg (Arg1)) /=
12395 UI_From_Int (Ttypes.System_Storage_Unit)
12397 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12399 ("the only allowed argument for pragma% is ^", Arg1);
12402 --------------------
12403 -- Stream_Convert --
12404 --------------------
12406 -- pragma Stream_Convert (
12407 -- [Entity =>] type_LOCAL_NAME,
12408 -- [Read =>] function_NAME,
12409 -- [Write =>] function NAME);
12411 when Pragma_Stream_Convert => Stream_Convert : declare
12413 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12414 -- Check that the given argument is the name of a local function
12415 -- of one argument that is not overloaded earlier in the current
12416 -- local scope. A check is also made that the argument is a
12417 -- function with one parameter.
12419 --------------------------------------
12420 -- Check_OK_Stream_Convert_Function --
12421 --------------------------------------
12423 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12427 Check_Arg_Is_Local_Name (Arg);
12428 Ent := Entity (Get_Pragma_Arg (Arg));
12430 if Has_Homonym (Ent) then
12432 ("argument for pragma% may not be overloaded", Arg);
12435 if Ekind (Ent) /= E_Function
12436 or else No (First_Formal (Ent))
12437 or else Present (Next_Formal (First_Formal (Ent)))
12440 ("argument for pragma% must be" &
12441 " function of one argument", Arg);
12443 end Check_OK_Stream_Convert_Function;
12445 -- Start of processing for Stream_Convert
12449 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12450 Check_Arg_Count (3);
12451 Check_Optional_Identifier (Arg1, Name_Entity);
12452 Check_Optional_Identifier (Arg2, Name_Read);
12453 Check_Optional_Identifier (Arg3, Name_Write);
12454 Check_Arg_Is_Local_Name (Arg1);
12455 Check_OK_Stream_Convert_Function (Arg2);
12456 Check_OK_Stream_Convert_Function (Arg3);
12459 Typ : constant Entity_Id :=
12460 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12461 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12462 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12465 Check_First_Subtype (Arg1);
12467 -- Check for too early or too late. Note that we don't enforce
12468 -- the rule about primitive operations in this case, since, as
12469 -- is the case for explicit stream attributes themselves, these
12470 -- restrictions are not appropriate. Note that the chaining of
12471 -- the pragma by Rep_Item_Too_Late is actually the critical
12472 -- processing done for this pragma.
12474 if Rep_Item_Too_Early (Typ, N)
12476 Rep_Item_Too_Late (Typ, N, FOnly => True)
12481 -- Return if previous error
12483 if Etype (Typ) = Any_Type
12485 Etype (Read) = Any_Type
12487 Etype (Write) = Any_Type
12494 if Underlying_Type (Etype (Read)) /= Typ then
12496 ("incorrect return type for function&", Arg2);
12499 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12501 ("incorrect parameter type for function&", Arg3);
12504 if Underlying_Type (Etype (First_Formal (Read))) /=
12505 Underlying_Type (Etype (Write))
12508 ("result type of & does not match Read parameter type",
12512 end Stream_Convert;
12514 -------------------------
12515 -- Style_Checks (GNAT) --
12516 -------------------------
12518 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12520 -- This is processed by the parser since some of the style checks
12521 -- take place during source scanning and parsing. This means that
12522 -- we don't need to issue error messages here.
12524 when Pragma_Style_Checks => Style_Checks : declare
12525 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12531 Check_No_Identifiers;
12533 -- Two argument form
12535 if Arg_Count = 2 then
12536 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12543 E_Id := Get_Pragma_Arg (Arg2);
12546 if not Is_Entity_Name (E_Id) then
12548 ("second argument of pragma% must be entity name",
12552 E := Entity (E_Id);
12558 Set_Suppress_Style_Checks (E,
12559 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12560 exit when No (Homonym (E));
12566 -- One argument form
12569 Check_Arg_Count (1);
12571 if Nkind (A) = N_String_Literal then
12575 Slen : constant Natural := Natural (String_Length (S));
12576 Options : String (1 .. Slen);
12582 C := Get_String_Char (S, Int (J));
12583 exit when not In_Character_Range (C);
12584 Options (J) := Get_Character (C);
12586 -- If at end of string, set options. As per discussion
12587 -- above, no need to check for errors, since we issued
12588 -- them in the parser.
12591 Set_Style_Check_Options (Options);
12599 elsif Nkind (A) = N_Identifier then
12600 if Chars (A) = Name_All_Checks then
12602 Set_GNAT_Style_Check_Options;
12604 Set_Default_Style_Check_Options;
12607 elsif Chars (A) = Name_On then
12608 Style_Check := True;
12610 elsif Chars (A) = Name_Off then
12611 Style_Check := False;
12621 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12623 when Pragma_Subtitle =>
12625 Check_Arg_Count (1);
12626 Check_Optional_Identifier (Arg1, Name_Subtitle);
12627 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12634 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12636 when Pragma_Suppress =>
12637 Process_Suppress_Unsuppress (True);
12643 -- pragma Suppress_All;
12645 -- The only check made here is that the pragma has no arguments.
12646 -- There are no placement rules, and the processing required (setting
12647 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12648 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12649 -- then creates and inserts a pragma Suppress (All_Checks).
12651 when Pragma_Suppress_All =>
12653 Check_Arg_Count (0);
12655 -------------------------
12656 -- Suppress_Debug_Info --
12657 -------------------------
12659 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12661 when Pragma_Suppress_Debug_Info =>
12663 Check_Arg_Count (1);
12664 Check_Optional_Identifier (Arg1, Name_Entity);
12665 Check_Arg_Is_Local_Name (Arg1);
12666 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)), Sense);
12668 ----------------------------------
12669 -- Suppress_Exception_Locations --
12670 ----------------------------------
12672 -- pragma Suppress_Exception_Locations;
12674 when Pragma_Suppress_Exception_Locations =>
12676 Check_Arg_Count (0);
12677 Check_Valid_Configuration_Pragma;
12678 Exception_Locations_Suppressed := True;
12680 -----------------------------
12681 -- Suppress_Initialization --
12682 -----------------------------
12684 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12686 when Pragma_Suppress_Initialization => Suppress_Init : declare
12692 Check_Arg_Count (1);
12693 Check_Optional_Identifier (Arg1, Name_Entity);
12694 Check_Arg_Is_Local_Name (Arg1);
12696 E_Id := Get_Pragma_Arg (Arg1);
12698 if Etype (E_Id) = Any_Type then
12702 E := Entity (E_Id);
12704 if Is_Type (E) then
12705 if Is_Incomplete_Or_Private_Type (E) then
12706 if No (Full_View (Base_Type (E))) then
12708 ("argument of pragma% cannot be an incomplete type",
12711 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12714 Set_Suppress_Init_Proc (Base_Type (E));
12719 ("pragma% requires argument that is a type name", Arg1);
12727 -- pragma System_Name (DIRECT_NAME);
12729 -- Syntax check: one argument, which must be the identifier GNAT or
12730 -- the identifier GCC, no other identifiers are acceptable.
12732 when Pragma_System_Name =>
12734 Check_No_Identifiers;
12735 Check_Arg_Count (1);
12736 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12738 -----------------------------
12739 -- Task_Dispatching_Policy --
12740 -----------------------------
12742 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12744 when Pragma_Task_Dispatching_Policy => declare
12748 Check_Ada_83_Warning;
12749 Check_Arg_Count (1);
12750 Check_No_Identifiers;
12751 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12752 Check_Valid_Configuration_Pragma;
12753 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12754 DP := Fold_Upper (Name_Buffer (1));
12756 if Task_Dispatching_Policy /= ' '
12757 and then Task_Dispatching_Policy /= DP
12759 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12761 ("task dispatching policy incompatible with policy#");
12763 -- Set new policy, but always preserve System_Location since we
12764 -- like the error message with the run time name.
12767 Task_Dispatching_Policy := DP;
12769 if Task_Dispatching_Policy_Sloc /= System_Location then
12770 Task_Dispatching_Policy_Sloc := Loc;
12779 -- pragma Task_Info (EXPRESSION);
12781 when Pragma_Task_Info => Task_Info : declare
12782 P : constant Node_Id := Parent (N);
12787 if Nkind (P) /= N_Task_Definition then
12788 Error_Pragma ("pragma% must appear in task definition");
12791 Check_No_Identifiers;
12792 Check_Arg_Count (1);
12794 Analyze_And_Resolve
12795 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12797 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12801 if Has_Task_Info_Pragma (P) then
12802 Error_Pragma ("duplicate pragma% not allowed");
12804 Set_Has_Task_Info_Pragma (P, True);
12812 -- pragma Task_Name (string_EXPRESSION);
12814 when Pragma_Task_Name => Task_Name : declare
12815 P : constant Node_Id := Parent (N);
12819 Check_No_Identifiers;
12820 Check_Arg_Count (1);
12822 Arg := Get_Pragma_Arg (Arg1);
12824 -- The expression is used in the call to Create_Task, and must be
12825 -- expanded there, not in the context of the current spec. It must
12826 -- however be analyzed to capture global references, in case it
12827 -- appears in a generic context.
12829 Preanalyze_And_Resolve (Arg, Standard_String);
12831 if Nkind (P) /= N_Task_Definition then
12835 if Has_Task_Name_Pragma (P) then
12836 Error_Pragma ("duplicate pragma% not allowed");
12838 Set_Has_Task_Name_Pragma (P, True);
12839 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12847 -- pragma Task_Storage (
12848 -- [Task_Type =>] LOCAL_NAME,
12849 -- [Top_Guard =>] static_integer_EXPRESSION);
12851 when Pragma_Task_Storage => Task_Storage : declare
12852 Args : Args_List (1 .. 2);
12853 Names : constant Name_List (1 .. 2) := (
12857 Task_Type : Node_Id renames Args (1);
12858 Top_Guard : Node_Id renames Args (2);
12864 Gather_Associations (Names, Args);
12866 if No (Task_Type) then
12868 ("missing task_type argument for pragma%");
12871 Check_Arg_Is_Local_Name (Task_Type);
12873 Ent := Entity (Task_Type);
12875 if not Is_Task_Type (Ent) then
12877 ("argument for pragma% must be task type", Task_Type);
12880 if No (Top_Guard) then
12882 ("pragma% takes two arguments", Task_Type);
12884 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12887 Check_First_Subtype (Task_Type);
12889 if Rep_Item_Too_Late (Ent, N) then
12894 --------------------------
12895 -- Thread_Local_Storage --
12896 --------------------------
12898 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12900 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
12906 Check_Arg_Count (1);
12907 Check_Optional_Identifier (Arg1, Name_Entity);
12908 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12910 Id := Get_Pragma_Arg (Arg1);
12913 if not Is_Entity_Name (Id)
12914 or else Ekind (Entity (Id)) /= E_Variable
12916 Error_Pragma_Arg ("local variable name required", Arg1);
12921 if Rep_Item_Too_Early (E, N)
12922 or else Rep_Item_Too_Late (E, N)
12927 Set_Has_Pragma_Thread_Local_Storage (E);
12928 Set_Has_Gigi_Rep_Item (E);
12929 end Thread_Local_Storage;
12935 -- pragma Time_Slice (static_duration_EXPRESSION);
12937 when Pragma_Time_Slice => Time_Slice : declare
12943 Check_Arg_Count (1);
12944 Check_No_Identifiers;
12945 Check_In_Main_Program;
12946 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
12948 if not Error_Posted (Arg1) then
12950 while Present (Nod) loop
12951 if Nkind (Nod) = N_Pragma
12952 and then Pragma_Name (Nod) = Name_Time_Slice
12954 Error_Msg_Name_1 := Pname;
12955 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12962 -- Process only if in main unit
12964 if Get_Source_Unit (Loc) = Main_Unit then
12965 Opt.Time_Slice_Set := True;
12966 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
12968 if Val <= Ureal_0 then
12969 Opt.Time_Slice_Value := 0;
12971 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
12972 Opt.Time_Slice_Value := 1_000_000_000;
12975 Opt.Time_Slice_Value :=
12976 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
12985 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
12987 -- TITLING_OPTION ::=
12988 -- [Title =>] STRING_LITERAL
12989 -- | [Subtitle =>] STRING_LITERAL
12991 when Pragma_Title => Title : declare
12992 Args : Args_List (1 .. 2);
12993 Names : constant Name_List (1 .. 2) := (
12999 Gather_Associations (Names, Args);
13002 for J in 1 .. 2 loop
13003 if Present (Args (J)) then
13004 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13009 ---------------------
13010 -- Unchecked_Union --
13011 ---------------------
13013 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13015 when Pragma_Unchecked_Union => Unchecked_Union : declare
13016 Assoc : constant Node_Id := Arg1;
13017 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13028 Check_No_Identifiers;
13029 Check_Arg_Count (1);
13030 Check_Arg_Is_Local_Name (Arg1);
13032 Find_Type (Type_Id);
13033 Typ := Entity (Type_Id);
13036 or else Rep_Item_Too_Early (Typ, N)
13040 Typ := Underlying_Type (Typ);
13043 if Rep_Item_Too_Late (Typ, N) then
13047 Check_First_Subtype (Arg1);
13049 -- Note remaining cases are references to a type in the current
13050 -- declarative part. If we find an error, we post the error on
13051 -- the relevant type declaration at an appropriate point.
13053 if not Is_Record_Type (Typ) then
13054 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13057 elsif Is_Tagged_Type (Typ) then
13058 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13061 elsif Is_Limited_Type (Typ) then
13063 ("Unchecked_Union must not be limited record type", Typ);
13064 Explain_Limited_Type (Typ, Typ);
13068 if not Has_Discriminants (Typ) then
13070 ("Unchecked_Union must have one discriminant", Typ);
13074 Discr := First_Discriminant (Typ);
13075 while Present (Discr) loop
13076 if No (Discriminant_Default_Value (Discr)) then
13078 ("Unchecked_Union discriminant must have default value",
13082 Next_Discriminant (Discr);
13085 Tdef := Type_Definition (Declaration_Node (Typ));
13086 Clist := Component_List (Tdef);
13088 Comp := First (Component_Items (Clist));
13089 while Present (Comp) loop
13090 Check_Component (Comp, Typ);
13094 if No (Clist) or else No (Variant_Part (Clist)) then
13096 ("Unchecked_Union must have variant part",
13101 Vpart := Variant_Part (Clist);
13103 Variant := First (Variants (Vpart));
13104 while Present (Variant) loop
13105 Check_Variant (Variant, Typ);
13110 Set_Is_Unchecked_Union (Typ, Sense);
13113 Set_Convention (Typ, Convention_C);
13116 Set_Has_Unchecked_Union (Base_Type (Typ), Sense);
13117 Set_Is_Unchecked_Union (Base_Type (Typ), Sense);
13118 end Unchecked_Union;
13120 ------------------------
13121 -- Unimplemented_Unit --
13122 ------------------------
13124 -- pragma Unimplemented_Unit;
13126 -- Note: this only gives an error if we are generating code, or if
13127 -- we are in a generic library unit (where the pragma appears in the
13128 -- body, not in the spec).
13130 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13131 Cunitent : constant Entity_Id :=
13132 Cunit_Entity (Get_Source_Unit (Loc));
13133 Ent_Kind : constant Entity_Kind :=
13138 Check_Arg_Count (0);
13140 if Operating_Mode = Generate_Code
13141 or else Ent_Kind = E_Generic_Function
13142 or else Ent_Kind = E_Generic_Procedure
13143 or else Ent_Kind = E_Generic_Package
13145 Get_Name_String (Chars (Cunitent));
13146 Set_Casing (Mixed_Case);
13147 Write_Str (Name_Buffer (1 .. Name_Len));
13148 Write_Str (" is not supported in this configuration");
13150 raise Unrecoverable_Error;
13152 end Unimplemented_Unit;
13154 ------------------------
13155 -- Universal_Aliasing --
13156 ------------------------
13158 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13160 when Pragma_Universal_Aliasing => Universal_Alias : declare
13165 Check_Arg_Count (1);
13166 Check_Optional_Identifier (Arg2, Name_Entity);
13167 Check_Arg_Is_Local_Name (Arg1);
13168 E_Id := Entity (Get_Pragma_Arg (Arg1));
13170 if E_Id = Any_Type then
13172 elsif No (E_Id) or else not Is_Type (E_Id) then
13173 Error_Pragma_Arg ("pragma% requires type", Arg1);
13176 Set_Universal_Aliasing (Implementation_Base_Type (E_Id), Sense);
13177 end Universal_Alias;
13179 --------------------
13180 -- Universal_Data --
13181 --------------------
13183 -- pragma Universal_Data [(library_unit_NAME)];
13185 when Pragma_Universal_Data =>
13188 -- If this is a configuration pragma, then set the universal
13189 -- addressing option, otherwise confirm that the pragma satisfies
13190 -- the requirements of library unit pragma placement and leave it
13191 -- to the GNAAMP back end to detect the pragma (avoids transitive
13192 -- setting of the option due to withed units).
13194 if Is_Configuration_Pragma then
13195 Universal_Addressing_On_AAMP := True;
13197 Check_Valid_Library_Unit_Pragma;
13200 if not AAMP_On_Target then
13201 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13208 -- pragma Unmodified (local_Name {, local_Name});
13210 when Pragma_Unmodified => Unmodified : declare
13211 Arg_Node : Node_Id;
13212 Arg_Expr : Node_Id;
13213 Arg_Ent : Entity_Id;
13217 Check_At_Least_N_Arguments (1);
13219 -- Loop through arguments
13222 while Present (Arg_Node) loop
13223 Check_No_Identifier (Arg_Node);
13225 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13226 -- in fact generate reference, so that the entity will have a
13227 -- reference, which will inhibit any warnings about it not
13228 -- being referenced, and also properly show up in the ali file
13229 -- as a reference. But this reference is recorded before the
13230 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13231 -- generated for this reference.
13233 Check_Arg_Is_Local_Name (Arg_Node);
13234 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13236 if Is_Entity_Name (Arg_Expr) then
13237 Arg_Ent := Entity (Arg_Expr);
13239 if not Is_Assignable (Arg_Ent) then
13241 ("pragma% can only be applied to a variable",
13244 Set_Has_Pragma_Unmodified (Arg_Ent, Sense);
13256 -- pragma Unreferenced (local_Name {, local_Name});
13258 -- or when used in a context clause:
13260 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13262 when Pragma_Unreferenced => Unreferenced : declare
13263 Arg_Node : Node_Id;
13264 Arg_Expr : Node_Id;
13265 Arg_Ent : Entity_Id;
13270 Check_At_Least_N_Arguments (1);
13272 -- Check case of appearing within context clause
13274 if Is_In_Context_Clause then
13276 -- The arguments must all be units mentioned in a with clause
13277 -- in the same context clause. Note we already checked (in
13278 -- Par.Prag) that the arguments are either identifiers or
13279 -- selected components.
13282 while Present (Arg_Node) loop
13283 Citem := First (List_Containing (N));
13284 while Citem /= N loop
13285 if Nkind (Citem) = N_With_Clause
13287 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13289 Set_Has_Pragma_Unreferenced
13292 (Library_Unit (Citem))));
13294 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13303 ("argument of pragma% is not with'ed unit", Arg_Node);
13309 -- Case of not in list of context items
13313 while Present (Arg_Node) loop
13314 Check_No_Identifier (Arg_Node);
13316 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13317 -- will in fact generate reference, so that the entity will
13318 -- have a reference, which will inhibit any warnings about
13319 -- it not being referenced, and also properly show up in the
13320 -- ali file as a reference. But this reference is recorded
13321 -- before the Has_Pragma_Unreferenced flag is set, so that
13322 -- no warning is generated for this reference.
13324 Check_Arg_Is_Local_Name (Arg_Node);
13325 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13327 if Is_Entity_Name (Arg_Expr) then
13328 Arg_Ent := Entity (Arg_Expr);
13330 -- If the entity is overloaded, the pragma applies to the
13331 -- most recent overloading, as documented. In this case,
13332 -- name resolution does not generate a reference, so it
13333 -- must be done here explicitly.
13335 if Is_Overloaded (Arg_Expr) then
13336 Generate_Reference (Arg_Ent, N);
13339 Set_Has_Pragma_Unreferenced (Arg_Ent, Sense);
13347 --------------------------
13348 -- Unreferenced_Objects --
13349 --------------------------
13351 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13353 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13354 Arg_Node : Node_Id;
13355 Arg_Expr : Node_Id;
13359 Check_At_Least_N_Arguments (1);
13362 while Present (Arg_Node) loop
13363 Check_No_Identifier (Arg_Node);
13364 Check_Arg_Is_Local_Name (Arg_Node);
13365 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13367 if not Is_Entity_Name (Arg_Expr)
13368 or else not Is_Type (Entity (Arg_Expr))
13371 ("argument for pragma% must be type or subtype", Arg_Node);
13374 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr), Sense);
13377 end Unreferenced_Objects;
13379 ------------------------------
13380 -- Unreserve_All_Interrupts --
13381 ------------------------------
13383 -- pragma Unreserve_All_Interrupts;
13385 when Pragma_Unreserve_All_Interrupts =>
13387 Check_Arg_Count (0);
13389 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13390 Unreserve_All_Interrupts := True;
13397 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13399 when Pragma_Unsuppress =>
13401 Process_Suppress_Unsuppress (False);
13403 -------------------
13404 -- Use_VADS_Size --
13405 -------------------
13407 -- pragma Use_VADS_Size;
13409 when Pragma_Use_VADS_Size =>
13411 Check_Arg_Count (0);
13412 Check_Valid_Configuration_Pragma;
13413 Use_VADS_Size := True;
13415 ---------------------
13416 -- Validity_Checks --
13417 ---------------------
13419 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13421 when Pragma_Validity_Checks => Validity_Checks : declare
13422 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13428 Check_Arg_Count (1);
13429 Check_No_Identifiers;
13431 if Nkind (A) = N_String_Literal then
13435 Slen : constant Natural := Natural (String_Length (S));
13436 Options : String (1 .. Slen);
13442 C := Get_String_Char (S, Int (J));
13443 exit when not In_Character_Range (C);
13444 Options (J) := Get_Character (C);
13447 Set_Validity_Check_Options (Options);
13455 elsif Nkind (A) = N_Identifier then
13457 if Chars (A) = Name_All_Checks then
13458 Set_Validity_Check_Options ("a");
13460 elsif Chars (A) = Name_On then
13461 Validity_Checks_On := True;
13463 elsif Chars (A) = Name_Off then
13464 Validity_Checks_On := False;
13468 end Validity_Checks;
13474 -- pragma Volatile (LOCAL_NAME);
13476 when Pragma_Volatile =>
13477 Process_Atomic_Shared_Volatile;
13479 -------------------------
13480 -- Volatile_Components --
13481 -------------------------
13483 -- pragma Volatile_Components (array_LOCAL_NAME);
13485 -- Volatile is handled by the same circuit as Atomic_Components
13491 -- pragma Warnings (On | Off);
13492 -- pragma Warnings (On | Off, LOCAL_NAME);
13493 -- pragma Warnings (static_string_EXPRESSION);
13494 -- pragma Warnings (On | Off, STRING_LITERAL);
13496 when Pragma_Warnings => Warnings : begin
13498 Check_At_Least_N_Arguments (1);
13499 Check_No_Identifiers;
13501 -- If debug flag -gnatd.i is set, pragma is ignored
13503 if Debug_Flag_Dot_I then
13507 -- Process various forms of the pragma
13510 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13513 -- One argument case
13515 if Arg_Count = 1 then
13517 -- On/Off one argument case was processed by parser
13519 if Nkind (Argx) = N_Identifier
13521 (Chars (Argx) = Name_On
13523 Chars (Argx) = Name_Off)
13527 -- One argument case must be ON/OFF or static string expr
13529 elsif not Is_Static_String_Expression (Arg1) then
13531 ("argument of pragma% must be On/Off or " &
13532 "static string expression", Arg1);
13534 -- One argument string expression case
13538 Lit : constant Node_Id := Expr_Value_S (Argx);
13539 Str : constant String_Id := Strval (Lit);
13540 Len : constant Nat := String_Length (Str);
13548 while J <= Len loop
13549 C := Get_String_Char (Str, J);
13550 OK := In_Character_Range (C);
13553 Chr := Get_Character (C);
13557 if J < Len and then Chr = '.' then
13559 C := Get_String_Char (Str, J);
13560 Chr := Get_Character (C);
13562 if not Set_Dot_Warning_Switch (Chr) then
13564 ("invalid warning switch character " &
13571 OK := Set_Warning_Switch (Chr);
13577 ("invalid warning switch character " & Chr,
13586 -- Two or more arguments (must be two)
13589 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13590 Check_At_Most_N_Arguments (2);
13598 E_Id := Get_Pragma_Arg (Arg2);
13601 -- In the expansion of an inlined body, a reference to
13602 -- the formal may be wrapped in a conversion if the
13603 -- actual is a conversion. Retrieve the real entity name.
13605 if (In_Instance_Body
13606 or else In_Inlined_Body)
13607 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13609 E_Id := Expression (E_Id);
13612 -- Entity name case
13614 if Is_Entity_Name (E_Id) then
13615 E := Entity (E_Id);
13622 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13625 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13626 and then Warn_On_Warnings_Off
13628 Warnings_Off_Pragmas.Append ((N, E));
13631 if Is_Enumeration_Type (E) then
13635 Lit := First_Literal (E);
13636 while Present (Lit) loop
13637 Set_Warnings_Off (Lit);
13638 Next_Literal (Lit);
13643 exit when No (Homonym (E));
13648 -- Error if not entity or static string literal case
13650 elsif not Is_Static_String_Expression (Arg2) then
13652 ("second argument of pragma% must be entity " &
13653 "name or static string expression", Arg2);
13655 -- String literal case
13658 String_To_Name_Buffer
13659 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13661 -- Note on configuration pragma case: If this is a
13662 -- configuration pragma, then for an OFF pragma, we
13663 -- just set Config True in the call, which is all
13664 -- that needs to be done. For the case of ON, this
13665 -- is normally an error, unless it is canceling the
13666 -- effect of a previous OFF pragma in the same file.
13667 -- In any other case, an error will be signalled (ON
13668 -- with no matching OFF).
13670 if Chars (Argx) = Name_Off then
13671 Set_Specific_Warning_Off
13672 (Loc, Name_Buffer (1 .. Name_Len),
13673 Config => Is_Configuration_Pragma);
13675 elsif Chars (Argx) = Name_On then
13676 Set_Specific_Warning_On
13677 (Loc, Name_Buffer (1 .. Name_Len), Err);
13681 ("?pragma Warnings On with no " &
13682 "matching Warnings Off",
13692 -------------------
13693 -- Weak_External --
13694 -------------------
13696 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13698 when Pragma_Weak_External => Weak_External : declare
13703 Check_Arg_Count (1);
13704 Check_Optional_Identifier (Arg1, Name_Entity);
13705 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13706 Ent := Entity (Get_Pragma_Arg (Arg1));
13708 if Rep_Item_Too_Early (Ent, N) then
13711 Ent := Underlying_Type (Ent);
13714 -- The only processing required is to link this item on to the
13715 -- list of rep items for the given entity. This is accomplished
13716 -- by the call to Rep_Item_Too_Late (when no error is detected
13717 -- and False is returned).
13719 if Rep_Item_Too_Late (Ent, N) then
13722 Set_Has_Gigi_Rep_Item (Ent);
13726 -----------------------------
13727 -- Wide_Character_Encoding --
13728 -----------------------------
13730 -- pragma Wide_Character_Encoding (IDENTIFIER);
13732 when Pragma_Wide_Character_Encoding =>
13735 -- Nothing to do, handled in parser. Note that we do not enforce
13736 -- configuration pragma placement, this pragma can appear at any
13737 -- place in the source, allowing mixed encodings within a single
13742 --------------------
13743 -- Unknown_Pragma --
13744 --------------------
13746 -- Should be impossible, since the case of an unknown pragma is
13747 -- separately processed before the case statement is entered.
13749 when Unknown_Pragma =>
13750 raise Program_Error;
13753 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13754 -- until AI is formally approved.
13756 -- Check_Order_Dependence;
13759 when Pragma_Exit => null;
13760 end Analyze_Pragma;
13762 -------------------
13763 -- Check_Enabled --
13764 -------------------
13766 function Check_Enabled (Nam : Name_Id) return Boolean is
13770 -- Loop through entries in check policy list
13772 PP := Opt.Check_Policy_List;
13774 -- If there are no specific entries that matched, then we let the
13775 -- setting of assertions govern. Note that this provides the needed
13776 -- compatibility with the RM for the cases of assertion, invariant,
13777 -- precondition, predicate, and postcondition.
13780 return Assertions_Enabled;
13782 -- Here we have an entry see if it matches
13786 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13789 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13790 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13791 when Name_On | Name_Check =>
13793 when Name_Off | Name_Ignore =>
13796 raise Program_Error;
13800 PP := Next_Pragma (PP);
13807 ---------------------------------
13808 -- Delay_Config_Pragma_Analyze --
13809 ---------------------------------
13811 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13813 return Pragma_Name (N) = Name_Interrupt_State
13815 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13816 end Delay_Config_Pragma_Analyze;
13818 -------------------------
13819 -- Get_Base_Subprogram --
13820 -------------------------
13822 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13823 Result : Entity_Id;
13826 -- Follow subprogram renaming chain
13829 while Is_Subprogram (Result)
13831 (Is_Generic_Instance (Result)
13832 or else Nkind (Parent (Declaration_Node (Result))) =
13833 N_Subprogram_Renaming_Declaration)
13834 and then Present (Alias (Result))
13836 Result := Alias (Result);
13840 end Get_Base_Subprogram;
13846 procedure Initialize is
13851 -----------------------------
13852 -- Is_Config_Static_String --
13853 -----------------------------
13855 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13857 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13858 -- This is an internal recursive function that is just like the outer
13859 -- function except that it adds the string to the name buffer rather
13860 -- than placing the string in the name buffer.
13862 ------------------------------
13863 -- Add_Config_Static_String --
13864 ------------------------------
13866 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13873 if Nkind (N) = N_Op_Concat then
13874 if Add_Config_Static_String (Left_Opnd (N)) then
13875 N := Right_Opnd (N);
13881 if Nkind (N) /= N_String_Literal then
13882 Error_Msg_N ("string literal expected for pragma argument", N);
13886 for J in 1 .. String_Length (Strval (N)) loop
13887 C := Get_String_Char (Strval (N), J);
13889 if not In_Character_Range (C) then
13891 ("string literal contains invalid wide character",
13892 Sloc (N) + 1 + Source_Ptr (J));
13896 Add_Char_To_Name_Buffer (Get_Character (C));
13901 end Add_Config_Static_String;
13903 -- Start of processing for Is_Config_Static_String
13908 return Add_Config_Static_String (Arg);
13909 end Is_Config_Static_String;
13911 -----------------------------------------
13912 -- Is_Non_Significant_Pragma_Reference --
13913 -----------------------------------------
13915 -- This function makes use of the following static table which indicates
13916 -- whether a given pragma is significant.
13918 -- -1 indicates that references in any argument position are significant
13919 -- 0 indicates that appearance in any argument is not significant
13920 -- +n indicates that appearance as argument n is significant, but all
13921 -- other arguments are not significant
13922 -- 99 special processing required (e.g. for pragma Check)
13924 Sig_Flags : constant array (Pragma_Id) of Int :=
13925 (Pragma_AST_Entry => -1,
13926 Pragma_Abort_Defer => -1,
13927 Pragma_Ada_83 => -1,
13928 Pragma_Ada_95 => -1,
13929 Pragma_Ada_05 => -1,
13930 Pragma_Ada_2005 => -1,
13931 Pragma_Ada_12 => -1,
13932 Pragma_Ada_2012 => -1,
13933 Pragma_All_Calls_Remote => -1,
13934 Pragma_Annotate => -1,
13935 Pragma_Assert => -1,
13936 Pragma_Assertion_Policy => 0,
13937 Pragma_Assume_No_Invalid_Values => 0,
13938 Pragma_Asynchronous => -1,
13939 Pragma_Atomic => 0,
13940 Pragma_Atomic_Components => 0,
13941 Pragma_Attach_Handler => -1,
13942 Pragma_Check => 99,
13943 Pragma_Check_Name => 0,
13944 Pragma_Check_Policy => 0,
13945 Pragma_CIL_Constructor => -1,
13946 Pragma_CPP_Class => 0,
13947 Pragma_CPP_Constructor => 0,
13948 Pragma_CPP_Virtual => 0,
13949 Pragma_CPP_Vtable => 0,
13951 Pragma_C_Pass_By_Copy => 0,
13952 Pragma_Comment => 0,
13953 Pragma_Common_Object => -1,
13954 Pragma_Compile_Time_Error => -1,
13955 Pragma_Compile_Time_Warning => -1,
13956 Pragma_Compiler_Unit => 0,
13957 Pragma_Complete_Representation => 0,
13958 Pragma_Complex_Representation => 0,
13959 Pragma_Component_Alignment => -1,
13960 Pragma_Controlled => 0,
13961 Pragma_Convention => 0,
13962 Pragma_Convention_Identifier => 0,
13963 Pragma_Debug => -1,
13964 Pragma_Debug_Policy => 0,
13965 Pragma_Detect_Blocking => -1,
13966 Pragma_Default_Storage_Pool => -1,
13967 Pragma_Dimension => -1,
13968 Pragma_Discard_Names => 0,
13969 Pragma_Elaborate => -1,
13970 Pragma_Elaborate_All => -1,
13971 Pragma_Elaborate_Body => -1,
13972 Pragma_Elaboration_Checks => -1,
13973 Pragma_Eliminate => -1,
13974 Pragma_Export => -1,
13975 Pragma_Export_Exception => -1,
13976 Pragma_Export_Function => -1,
13977 Pragma_Export_Object => -1,
13978 Pragma_Export_Procedure => -1,
13979 Pragma_Export_Value => -1,
13980 Pragma_Export_Valued_Procedure => -1,
13981 Pragma_Extend_System => -1,
13982 Pragma_Extensions_Allowed => -1,
13983 Pragma_External => -1,
13984 Pragma_Favor_Top_Level => -1,
13985 Pragma_External_Name_Casing => -1,
13986 Pragma_Fast_Math => -1,
13987 Pragma_Finalize_Storage_Only => 0,
13988 Pragma_Float_Representation => 0,
13989 Pragma_Ident => -1,
13990 Pragma_Implemented => -1,
13991 Pragma_Implicit_Packing => 0,
13992 Pragma_Import => +2,
13993 Pragma_Import_Exception => 0,
13994 Pragma_Import_Function => 0,
13995 Pragma_Import_Object => 0,
13996 Pragma_Import_Procedure => 0,
13997 Pragma_Import_Valued_Procedure => 0,
13998 Pragma_Independent => 0,
13999 Pragma_Independent_Components => 0,
14000 Pragma_Initialize_Scalars => -1,
14001 Pragma_Inline => 0,
14002 Pragma_Inline_Always => 0,
14003 Pragma_Inline_Generic => 0,
14004 Pragma_Inspection_Point => -1,
14005 Pragma_Interface => +2,
14006 Pragma_Interface_Name => +2,
14007 Pragma_Interrupt_Handler => -1,
14008 Pragma_Interrupt_Priority => -1,
14009 Pragma_Interrupt_State => -1,
14010 Pragma_Invariant => -1,
14011 Pragma_Java_Constructor => -1,
14012 Pragma_Java_Interface => -1,
14013 Pragma_Keep_Names => 0,
14014 Pragma_License => -1,
14015 Pragma_Link_With => -1,
14016 Pragma_Linker_Alias => -1,
14017 Pragma_Linker_Constructor => -1,
14018 Pragma_Linker_Destructor => -1,
14019 Pragma_Linker_Options => -1,
14020 Pragma_Linker_Section => -1,
14022 Pragma_Locking_Policy => -1,
14023 Pragma_Long_Float => -1,
14024 Pragma_Machine_Attribute => -1,
14026 Pragma_Main_Storage => -1,
14027 Pragma_Memory_Size => -1,
14028 Pragma_No_Return => 0,
14029 Pragma_No_Body => 0,
14030 Pragma_No_Run_Time => -1,
14031 Pragma_No_Strict_Aliasing => -1,
14032 Pragma_Normalize_Scalars => -1,
14033 Pragma_Obsolescent => 0,
14034 Pragma_Optimize => -1,
14035 Pragma_Optimize_Alignment => -1,
14036 Pragma_Ordered => 0,
14039 Pragma_Passive => -1,
14040 Pragma_Preelaborable_Initialization => -1,
14041 Pragma_Polling => -1,
14042 Pragma_Persistent_BSS => 0,
14043 Pragma_Postcondition => -1,
14044 Pragma_Precondition => -1,
14045 Pragma_Predicate => -1,
14046 Pragma_Preelaborate => -1,
14047 Pragma_Preelaborate_05 => -1,
14048 Pragma_Priority => -1,
14049 Pragma_Priority_Specific_Dispatching => -1,
14050 Pragma_Profile => 0,
14051 Pragma_Profile_Warnings => 0,
14052 Pragma_Propagate_Exceptions => -1,
14053 Pragma_Psect_Object => -1,
14055 Pragma_Pure_05 => -1,
14056 Pragma_Pure_Function => -1,
14057 Pragma_Queuing_Policy => -1,
14058 Pragma_Ravenscar => -1,
14059 Pragma_Relative_Deadline => -1,
14060 Pragma_Remote_Call_Interface => -1,
14061 Pragma_Remote_Types => -1,
14062 Pragma_Restricted_Run_Time => -1,
14063 Pragma_Restriction_Warnings => -1,
14064 Pragma_Restrictions => -1,
14065 Pragma_Reviewable => -1,
14066 Pragma_Short_Circuit_And_Or => -1,
14067 Pragma_Share_Generic => -1,
14068 Pragma_Shared => -1,
14069 Pragma_Shared_Passive => -1,
14070 Pragma_Short_Descriptors => 0,
14071 Pragma_Source_File_Name => -1,
14072 Pragma_Source_File_Name_Project => -1,
14073 Pragma_Source_Reference => -1,
14074 Pragma_Storage_Size => -1,
14075 Pragma_Storage_Unit => -1,
14076 Pragma_Static_Elaboration_Desired => -1,
14077 Pragma_Stream_Convert => -1,
14078 Pragma_Style_Checks => -1,
14079 Pragma_Subtitle => -1,
14080 Pragma_Suppress => 0,
14081 Pragma_Suppress_Exception_Locations => 0,
14082 Pragma_Suppress_All => -1,
14083 Pragma_Suppress_Debug_Info => 0,
14084 Pragma_Suppress_Initialization => 0,
14085 Pragma_System_Name => -1,
14086 Pragma_Task_Dispatching_Policy => -1,
14087 Pragma_Task_Info => -1,
14088 Pragma_Task_Name => -1,
14089 Pragma_Task_Storage => 0,
14090 Pragma_Thread_Local_Storage => 0,
14091 Pragma_Time_Slice => -1,
14092 Pragma_Title => -1,
14093 Pragma_Unchecked_Union => 0,
14094 Pragma_Unimplemented_Unit => -1,
14095 Pragma_Universal_Aliasing => -1,
14096 Pragma_Universal_Data => -1,
14097 Pragma_Unmodified => -1,
14098 Pragma_Unreferenced => -1,
14099 Pragma_Unreferenced_Objects => -1,
14100 Pragma_Unreserve_All_Interrupts => -1,
14101 Pragma_Unsuppress => 0,
14102 Pragma_Use_VADS_Size => -1,
14103 Pragma_Validity_Checks => -1,
14104 Pragma_Volatile => 0,
14105 Pragma_Volatile_Components => 0,
14106 Pragma_Warnings => -1,
14107 Pragma_Weak_External => -1,
14108 Pragma_Wide_Character_Encoding => 0,
14109 Unknown_Pragma => 0);
14111 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14120 if Nkind (P) /= N_Pragma_Argument_Association then
14124 Id := Get_Pragma_Id (Parent (P));
14125 C := Sig_Flags (Id);
14137 -- For pragma Check, the first argument is not significant,
14138 -- the second and the third (if present) arguments are
14141 when Pragma_Check =>
14143 P = First (Pragma_Argument_Associations (Parent (P)));
14146 raise Program_Error;
14150 A := First (Pragma_Argument_Associations (Parent (P)));
14151 for J in 1 .. C - 1 loop
14159 return A = P; -- is this wrong way round ???
14162 end Is_Non_Significant_Pragma_Reference;
14164 ------------------------------
14165 -- Is_Pragma_String_Literal --
14166 ------------------------------
14168 -- This function returns true if the corresponding pragma argument is a
14169 -- static string expression. These are the only cases in which string
14170 -- literals can appear as pragma arguments. We also allow a string literal
14171 -- as the first argument to pragma Assert (although it will of course
14172 -- always generate a type error).
14174 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14175 Pragn : constant Node_Id := Parent (Par);
14176 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14177 Pname : constant Name_Id := Pragma_Name (Pragn);
14183 N := First (Assoc);
14190 if Pname = Name_Assert then
14193 elsif Pname = Name_Export then
14196 elsif Pname = Name_Ident then
14199 elsif Pname = Name_Import then
14202 elsif Pname = Name_Interface_Name then
14205 elsif Pname = Name_Linker_Alias then
14208 elsif Pname = Name_Linker_Section then
14211 elsif Pname = Name_Machine_Attribute then
14214 elsif Pname = Name_Source_File_Name then
14217 elsif Pname = Name_Source_Reference then
14220 elsif Pname = Name_Title then
14223 elsif Pname = Name_Subtitle then
14229 end Is_Pragma_String_Literal;
14231 --------------------------------------
14232 -- Process_Compilation_Unit_Pragmas --
14233 --------------------------------------
14235 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14237 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14238 -- strange because it comes at the end of the unit. Rational has the
14239 -- same name for a pragma, but treats it as a program unit pragma, In
14240 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14241 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14242 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14243 -- the context clause to ensure the correct processing.
14245 if Has_Pragma_Suppress_All (N) then
14246 Prepend_To (Context_Items (N),
14247 Make_Pragma (Sloc (N),
14248 Chars => Name_Suppress,
14249 Pragma_Argument_Associations => New_List (
14250 Make_Pragma_Argument_Association (Sloc (N),
14251 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14254 -- Nothing else to do at the current time!
14256 end Process_Compilation_Unit_Pragmas;
14267 --------------------------------
14268 -- Set_Encoded_Interface_Name --
14269 --------------------------------
14271 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14272 Str : constant String_Id := Strval (S);
14273 Len : constant Int := String_Length (Str);
14278 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14281 -- Stores encoded value of character code CC. The encoding we use an
14282 -- underscore followed by four lower case hex digits.
14288 procedure Encode is
14290 Store_String_Char (Get_Char_Code ('_'));
14292 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14294 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14296 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14298 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14301 -- Start of processing for Set_Encoded_Interface_Name
14304 -- If first character is asterisk, this is a link name, and we leave it
14305 -- completely unmodified. We also ignore null strings (the latter case
14306 -- happens only in error cases) and no encoding should occur for Java or
14307 -- AAMP interface names.
14310 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14311 or else VM_Target /= No_VM
14312 or else AAMP_On_Target
14314 Set_Interface_Name (E, S);
14319 CC := Get_String_Char (Str, J);
14321 exit when not In_Character_Range (CC);
14323 C := Get_Character (CC);
14325 exit when C /= '_' and then C /= '$'
14326 and then C not in '0' .. '9'
14327 and then C not in 'a' .. 'z'
14328 and then C not in 'A' .. 'Z';
14331 Set_Interface_Name (E, S);
14339 -- Here we need to encode. The encoding we use as follows:
14340 -- three underscores + four hex digits (lower case)
14344 for J in 1 .. String_Length (Str) loop
14345 CC := Get_String_Char (Str, J);
14347 if not In_Character_Range (CC) then
14350 C := Get_Character (CC);
14352 if C = '_' or else C = '$'
14353 or else C in '0' .. '9'
14354 or else C in 'a' .. 'z'
14355 or else C in 'A' .. 'Z'
14357 Store_String_Char (CC);
14364 Set_Interface_Name (E,
14365 Make_String_Literal (Sloc (S),
14366 Strval => End_String));
14368 end Set_Encoded_Interface_Name;
14370 -------------------
14371 -- Set_Unit_Name --
14372 -------------------
14374 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14379 if Nkind (N) = N_Identifier
14380 and then Nkind (With_Item) = N_Identifier
14382 Set_Entity (N, Entity (With_Item));
14384 elsif Nkind (N) = N_Selected_Component then
14385 Change_Selected_Component_To_Expanded_Name (N);
14386 Set_Entity (N, Entity (With_Item));
14387 Set_Entity (Selector_Name (N), Entity (N));
14389 Pref := Prefix (N);
14390 Scop := Scope (Entity (N));
14391 while Nkind (Pref) = N_Selected_Component loop
14392 Change_Selected_Component_To_Expanded_Name (Pref);
14393 Set_Entity (Selector_Name (Pref), Scop);
14394 Set_Entity (Pref, Scop);
14395 Pref := Prefix (Pref);
14396 Scop := Scope (Scop);
14399 Set_Entity (Pref, Scop);