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 referencing a
414 -- subtype, does not reference a type that is not a first subtype.
416 procedure Check_In_Main_Program;
417 -- Common checks for pragmas that appear within a main program
418 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
420 procedure Check_Interrupt_Or_Attach_Handler;
421 -- Common processing for first argument of pragma Interrupt_Handler or
422 -- pragma Attach_Handler.
424 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
425 -- Check that pragma appears in a declarative part, or in a package
426 -- specification, i.e. that it does not occur in a statement sequence
429 procedure Check_No_Identifier (Arg : Node_Id);
430 -- Checks that the given argument does not have an identifier. If
431 -- an identifier is present, then an error message is issued, and
432 -- Pragma_Exit is raised.
434 procedure Check_No_Identifiers;
435 -- Checks that none of the arguments to the pragma has an identifier.
436 -- If any argument has an identifier, then an error message is issued,
437 -- and Pragma_Exit is raised.
439 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
440 -- Checks if the given argument has an identifier, and if so, requires
441 -- it to match the given identifier name. If there is a non-matching
442 -- identifier, then an error message is given and Error_Pragmas raised.
444 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
445 -- Checks if the given argument has an identifier, and if so, requires
446 -- it to match the given identifier name. If there is a non-matching
447 -- identifier, then an error message is given and Error_Pragmas raised.
448 -- In this version of the procedure, the identifier name is given as
449 -- a string with lower case letters.
451 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
452 -- Called to process a precondition or postcondition pragma. There are
455 -- The pragma appears after a subprogram spec
457 -- If the corresponding check is not enabled, the pragma is analyzed
458 -- but otherwise ignored and control returns with In_Body set False.
460 -- If the check is enabled, then the first step is to analyze the
461 -- pragma, but this is skipped if the subprogram spec appears within
462 -- a package specification (because this is the case where we delay
463 -- analysis till the end of the spec). Then (whether or not it was
464 -- analyzed), the pragma is chained to the subprogram in question
465 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
466 -- caller with In_Body set False.
468 -- The pragma appears at the start of subprogram body declarations
470 -- In this case an immediate return to the caller is made with
471 -- In_Body set True, and the pragma is NOT analyzed.
473 -- In all other cases, an error message for bad placement is given
475 procedure Check_Static_Constraint (Constr : Node_Id);
476 -- Constr is a constraint from an N_Subtype_Indication node from a
477 -- component constraint in an Unchecked_Union type. This routine checks
478 -- that the constraint is static as required by the restrictions for
481 procedure Check_Valid_Configuration_Pragma;
482 -- Legality checks for placement of a configuration pragma
484 procedure Check_Valid_Library_Unit_Pragma;
485 -- Legality checks for library unit pragmas. A special case arises for
486 -- pragmas in generic instances that come from copies of the original
487 -- library unit pragmas in the generic templates. In the case of other
488 -- than library level instantiations these can appear in contexts which
489 -- would normally be invalid (they only apply to the original template
490 -- and to library level instantiations), and they are simply ignored,
491 -- which is implemented by rewriting them as null statements.
493 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
494 -- Check an Unchecked_Union variant for lack of nested variants and
495 -- presence of at least one component. UU_Typ is the related Unchecked_
498 procedure Error_Pragma (Msg : String);
499 pragma No_Return (Error_Pragma);
500 -- Outputs error message for current pragma. The message contains a %
501 -- that will be replaced with the pragma name, and the flag is placed
502 -- on the pragma itself. Pragma_Exit is then raised.
504 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
505 pragma No_Return (Error_Pragma_Arg);
506 -- Outputs error message for current pragma. The message may contain
507 -- a % that will be replaced with the pragma name. The parameter Arg
508 -- may either be a pragma argument association, in which case the flag
509 -- is placed on the expression of this association, or an expression,
510 -- in which case the flag is placed directly on the expression. The
511 -- message is placed using Error_Msg_N, so the message may also contain
512 -- an & insertion character which will reference the given Arg value.
513 -- After placing the message, Pragma_Exit is raised.
515 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
516 pragma No_Return (Error_Pragma_Arg);
517 -- Similar to above form of Error_Pragma_Arg except that two messages
518 -- are provided, the second is a continuation comment starting with \.
520 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
521 pragma No_Return (Error_Pragma_Arg_Ident);
522 -- Outputs error message for current pragma. The message may contain
523 -- a % that will be replaced with the pragma name. The parameter Arg
524 -- must be a pragma argument association with a non-empty identifier
525 -- (i.e. its Chars field must be set), and the error message is placed
526 -- on the identifier. The message is placed using Error_Msg_N so
527 -- the message may also contain an & insertion character which will
528 -- reference the identifier. After placing the message, Pragma_Exit
531 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
532 pragma No_Return (Error_Pragma_Ref);
533 -- Outputs error message for current pragma. The message may contain
534 -- a % that will be replaced with the pragma name. The parameter Ref
535 -- must be an entity whose name can be referenced by & and sloc by #.
536 -- After placing the message, Pragma_Exit is raised.
538 function Find_Lib_Unit_Name return Entity_Id;
539 -- Used for a library unit pragma to find the entity to which the
540 -- library unit pragma applies, returns the entity found.
542 procedure Find_Program_Unit_Name (Id : Node_Id);
543 -- If the pragma is a compilation unit pragma, the id must denote the
544 -- compilation unit in the same compilation, and the pragma must appear
545 -- in the list of preceding or trailing pragmas. If it is a program
546 -- unit pragma that is not a compilation unit pragma, then the
547 -- identifier must be visible.
549 function Find_Unique_Parameterless_Procedure
551 Arg : Node_Id) return Entity_Id;
552 -- Used for a procedure pragma to find the unique parameterless
553 -- procedure identified by Name, returns it if it exists, otherwise
554 -- errors out and uses Arg as the pragma argument for the message.
556 procedure Fix_Error (Msg : in out String);
557 -- This is called prior to issuing an error message. Msg is a string
558 -- which typically contains the substring pragma. If the current pragma
559 -- comes from an aspect, each such "pragma" substring is replaced with
560 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
561 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
563 procedure Gather_Associations
565 Args : out Args_List);
566 -- This procedure is used to gather the arguments for a pragma that
567 -- permits arbitrary ordering of parameters using the normal rules
568 -- for named and positional parameters. The Names argument is a list
569 -- of Name_Id values that corresponds to the allowed pragma argument
570 -- association identifiers in order. The result returned in Args is
571 -- a list of corresponding expressions that are the pragma arguments.
572 -- Note that this is a list of expressions, not of pragma argument
573 -- associations (Gather_Associations has completely checked all the
574 -- optional identifiers when it returns). An entry in Args is Empty
575 -- on return if the corresponding argument is not present.
577 procedure GNAT_Pragma;
578 -- Called for all GNAT defined pragmas to check the relevant restriction
579 -- (No_Implementation_Pragmas).
581 function Is_Before_First_Decl
582 (Pragma_Node : Node_Id;
583 Decls : List_Id) return Boolean;
584 -- Return True if Pragma_Node is before the first declarative item in
585 -- Decls where Decls is the list of declarative items.
587 function Is_Configuration_Pragma return Boolean;
588 -- Determines if the placement of the current pragma is appropriate
589 -- for a configuration pragma.
591 function Is_In_Context_Clause return Boolean;
592 -- Returns True if pragma appears within the context clause of a unit,
593 -- and False for any other placement (does not generate any messages).
595 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
596 -- Analyzes the argument, and determines if it is a static string
597 -- expression, returns True if so, False if non-static or not String.
599 procedure Pragma_Misplaced;
600 pragma No_Return (Pragma_Misplaced);
601 -- Issue fatal error message for misplaced pragma
603 procedure Process_Atomic_Shared_Volatile;
604 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
605 -- Shared is an obsolete Ada 83 pragma, treated as being identical
606 -- in effect to pragma Atomic.
608 procedure Process_Compile_Time_Warning_Or_Error;
609 -- Common processing for Compile_Time_Error and Compile_Time_Warning
611 procedure Process_Convention
612 (C : out Convention_Id;
613 Ent : out Entity_Id);
614 -- Common processing for Convention, Interface, Import and Export.
615 -- Checks first two arguments of pragma, and sets the appropriate
616 -- convention value in the specified entity or entities. On return
617 -- C is the convention, Ent is the referenced entity.
619 procedure Process_Extended_Import_Export_Exception_Pragma
620 (Arg_Internal : Node_Id;
621 Arg_External : Node_Id;
624 -- Common processing for the pragmas Import/Export_Exception. The three
625 -- arguments correspond to the three named parameters of the pragma. An
626 -- argument is empty if the corresponding parameter is not present in
629 procedure Process_Extended_Import_Export_Object_Pragma
630 (Arg_Internal : Node_Id;
631 Arg_External : Node_Id;
633 -- Common processing for the pragmas Import/Export_Object. The three
634 -- arguments correspond to the three named parameters of the pragmas. An
635 -- argument is empty if the corresponding parameter is not present in
638 procedure Process_Extended_Import_Export_Internal_Arg
639 (Arg_Internal : Node_Id := Empty);
640 -- Common processing for all extended Import and Export pragmas. The
641 -- argument is the pragma parameter for the Internal argument. If
642 -- Arg_Internal is empty or inappropriate, an error message is posted.
643 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
644 -- set to identify the referenced entity.
646 procedure Process_Extended_Import_Export_Subprogram_Pragma
647 (Arg_Internal : Node_Id;
648 Arg_External : Node_Id;
649 Arg_Parameter_Types : Node_Id;
650 Arg_Result_Type : Node_Id := Empty;
651 Arg_Mechanism : Node_Id;
652 Arg_Result_Mechanism : Node_Id := Empty;
653 Arg_First_Optional_Parameter : Node_Id := Empty);
654 -- Common processing for all extended Import and Export pragmas applying
655 -- to subprograms. The caller omits any arguments that do not apply to
656 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
657 -- only in the Import_Function and Export_Function cases). The argument
658 -- names correspond to the allowed pragma association identifiers.
660 procedure Process_Generic_List;
661 -- Common processing for Share_Generic and Inline_Generic
663 procedure Process_Import_Or_Interface;
664 -- Common processing for Import of Interface
666 procedure Process_Inline (Active : Boolean);
667 -- Common processing for Inline and Inline_Always. The parameter
668 -- indicates if the inline pragma is active, i.e. if it should actually
669 -- cause inlining to occur.
671 procedure Process_Interface_Name
672 (Subprogram_Def : Entity_Id;
675 -- Given the last two arguments of pragma Import, pragma Export, or
676 -- pragma Interface_Name, performs validity checks and sets the
677 -- Interface_Name field of the given subprogram entity to the
678 -- appropriate external or link name, depending on the arguments given.
679 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
680 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
681 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
682 -- nor Link_Arg is present, the interface name is set to the default
683 -- from the subprogram name.
685 procedure Process_Interrupt_Or_Attach_Handler;
686 -- Common processing for Interrupt and Attach_Handler pragmas
688 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
689 -- Common processing for Restrictions and Restriction_Warnings pragmas.
690 -- Warn is True for Restriction_Warnings, or for Restrictions if the
691 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
692 -- is not set in the Restrictions case.
694 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
695 -- Common processing for Suppress and Unsuppress. The boolean parameter
696 -- Suppress_Case is True for the Suppress case, and False for the
699 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
700 -- This procedure sets the Is_Exported flag for the given entity,
701 -- checking that the entity was not previously imported. Arg is
702 -- the argument that specified the entity. A check is also made
703 -- for exporting inappropriate entities.
705 procedure Set_Extended_Import_Export_External_Name
706 (Internal_Ent : Entity_Id;
707 Arg_External : Node_Id);
708 -- Common processing for all extended import export pragmas. The first
709 -- argument, Internal_Ent, is the internal entity, which has already
710 -- been checked for validity by the caller. Arg_External is from the
711 -- Import or Export pragma, and may be null if no External parameter
712 -- was present. If Arg_External is present and is a non-null string
713 -- (a null string is treated as the default), then the Interface_Name
714 -- field of Internal_Ent is set appropriately.
716 procedure Set_Imported (E : Entity_Id);
717 -- This procedure sets the Is_Imported flag for the given entity,
718 -- checking that it is not previously exported or imported.
720 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
721 -- Mech is a parameter passing mechanism (see Import_Function syntax
722 -- for MECHANISM_NAME). This routine checks that the mechanism argument
723 -- has the right form, and if not issues an error message. If the
724 -- argument has the right form then the Mechanism field of Ent is
725 -- set appropriately.
727 procedure Set_Ravenscar_Profile (N : Node_Id);
728 -- Activate the set of configuration pragmas and restrictions that make
729 -- up the Ravenscar Profile. N is the corresponding pragma node, which
730 -- is used for error messages on any constructs that violate the
733 ---------------------
734 -- Ada_2005_Pragma --
735 ---------------------
737 procedure Ada_2005_Pragma is
739 if Ada_Version <= Ada_95 then
740 Check_Restriction (No_Implementation_Pragmas, N);
744 ---------------------
745 -- Ada_2012_Pragma --
746 ---------------------
748 procedure Ada_2012_Pragma is
750 if Ada_Version <= Ada_2005 then
751 Check_Restriction (No_Implementation_Pragmas, N);
755 --------------------------
756 -- Check_Ada_83_Warning --
757 --------------------------
759 procedure Check_Ada_83_Warning is
761 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
762 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
764 end Check_Ada_83_Warning;
766 ---------------------
767 -- Check_Arg_Count --
768 ---------------------
770 procedure Check_Arg_Count (Required : Nat) is
772 if Arg_Count /= Required then
773 Error_Pragma ("wrong number of arguments for pragma%");
777 --------------------------------
778 -- Check_Arg_Is_External_Name --
779 --------------------------------
781 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
782 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
785 if Nkind (Argx) = N_Identifier then
789 Analyze_And_Resolve (Argx, Standard_String);
791 if Is_OK_Static_Expression (Argx) then
794 elsif Etype (Argx) = Any_Type then
797 -- An interesting special case, if we have a string literal and
798 -- we are in Ada 83 mode, then we allow it even though it will
799 -- not be flagged as static. This allows expected Ada 83 mode
800 -- use of external names which are string literals, even though
801 -- technically these are not static in Ada 83.
803 elsif Ada_Version = Ada_83
804 and then Nkind (Argx) = N_String_Literal
808 -- Static expression that raises Constraint_Error. This has
809 -- already been flagged, so just exit from pragma processing.
811 elsif Is_Static_Expression (Argx) then
814 -- Here we have a real error (non-static expression)
817 Error_Msg_Name_1 := Pname;
821 "argument for pragma% must be a identifier or "
822 & "static string expression!";
825 Flag_Non_Static_Expr (Msg, Argx);
830 end Check_Arg_Is_External_Name;
832 -----------------------------
833 -- Check_Arg_Is_Identifier --
834 -----------------------------
836 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
837 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
839 if Nkind (Argx) /= N_Identifier then
841 ("argument for pragma% must be identifier", Argx);
843 end Check_Arg_Is_Identifier;
845 ----------------------------------
846 -- Check_Arg_Is_Integer_Literal --
847 ----------------------------------
849 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
850 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
852 if Nkind (Argx) /= N_Integer_Literal then
854 ("argument for pragma% must be integer literal", Argx);
856 end Check_Arg_Is_Integer_Literal;
858 -------------------------------------------
859 -- Check_Arg_Is_Library_Level_Local_Name --
860 -------------------------------------------
864 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
865 -- | library_unit_NAME
867 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
869 Check_Arg_Is_Local_Name (Arg);
871 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
872 and then Comes_From_Source (N)
875 ("argument for pragma% must be library level entity", Arg);
877 end Check_Arg_Is_Library_Level_Local_Name;
879 -----------------------------
880 -- Check_Arg_Is_Local_Name --
881 -----------------------------
885 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
886 -- | library_unit_NAME
888 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
889 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
894 if Nkind (Argx) not in N_Direct_Name
895 and then (Nkind (Argx) /= N_Attribute_Reference
896 or else Present (Expressions (Argx))
897 or else Nkind (Prefix (Argx)) /= N_Identifier)
898 and then (not Is_Entity_Name (Argx)
899 or else not Is_Compilation_Unit (Entity (Argx)))
901 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
904 -- No further check required if not an entity name
906 if not Is_Entity_Name (Argx) then
912 Ent : constant Entity_Id := Entity (Argx);
913 Scop : constant Entity_Id := Scope (Ent);
915 -- Case of a pragma applied to a compilation unit: pragma must
916 -- occur immediately after the program unit in the compilation.
918 if Is_Compilation_Unit (Ent) then
920 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
922 -- Case of pragma placed immediately after spec
924 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
927 -- Case of pragma placed immediately after body
929 elsif Nkind (Decl) = N_Subprogram_Declaration
930 and then Present (Corresponding_Body (Decl))
934 (Parent (Unit_Declaration_Node
935 (Corresponding_Body (Decl))));
937 -- All other cases are illegal
944 -- Special restricted placement rule from 10.2.1(11.8/2)
946 elsif Is_Generic_Formal (Ent)
947 and then Prag_Id = Pragma_Preelaborable_Initialization
949 OK := List_Containing (N) =
950 Generic_Formal_Declarations
951 (Unit_Declaration_Node (Scop));
953 -- Default case, just check that the pragma occurs in the scope
954 -- of the entity denoted by the name.
957 OK := Current_Scope = Scop;
962 ("pragma% argument must be in same declarative part", Arg);
966 end Check_Arg_Is_Local_Name;
968 ---------------------------------
969 -- Check_Arg_Is_Locking_Policy --
970 ---------------------------------
972 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
973 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
976 Check_Arg_Is_Identifier (Argx);
978 if not Is_Locking_Policy_Name (Chars (Argx)) then
980 ("& is not a valid locking policy name", Argx);
982 end Check_Arg_Is_Locking_Policy;
984 -------------------------
985 -- Check_Arg_Is_One_Of --
986 -------------------------
988 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
989 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
992 Check_Arg_Is_Identifier (Argx);
994 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
995 Error_Msg_Name_2 := N1;
996 Error_Msg_Name_3 := N2;
997 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
999 end Check_Arg_Is_One_Of;
1001 procedure Check_Arg_Is_One_Of
1003 N1, N2, N3 : Name_Id)
1005 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1008 Check_Arg_Is_Identifier (Argx);
1010 if Chars (Argx) /= N1
1011 and then Chars (Argx) /= N2
1012 and then Chars (Argx) /= N3
1014 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1016 end Check_Arg_Is_One_Of;
1018 procedure Check_Arg_Is_One_Of
1020 N1, N2, N3, N4 : Name_Id)
1022 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1025 Check_Arg_Is_Identifier (Argx);
1027 if Chars (Argx) /= N1
1028 and then Chars (Argx) /= N2
1029 and then Chars (Argx) /= N3
1030 and then Chars (Argx) /= N4
1032 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1034 end Check_Arg_Is_One_Of;
1036 ---------------------------------
1037 -- Check_Arg_Is_Queuing_Policy --
1038 ---------------------------------
1040 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1041 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1044 Check_Arg_Is_Identifier (Argx);
1046 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1048 ("& 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
1205 -------------------------
1206 -- Inside_Generic_Body --
1207 -------------------------
1209 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1210 S : Entity_Id := Id;
1214 and then S /= Standard_Standard
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);
1346 if not Is_First_Subtype (Entity (Argx)) then
1348 ("pragma% cannot apply to subtype", Argx);
1350 end Check_First_Subtype;
1352 ---------------------------
1353 -- Check_In_Main_Program --
1354 ---------------------------
1356 procedure Check_In_Main_Program is
1357 P : constant Node_Id := Parent (N);
1360 -- Must be at in subprogram body
1362 if Nkind (P) /= N_Subprogram_Body then
1363 Error_Pragma ("% pragma allowed only in subprogram");
1365 -- Otherwise warn if obviously not main program
1367 elsif Present (Parameter_Specifications (Specification (P)))
1368 or else not Is_Compilation_Unit (Defining_Entity (P))
1370 Error_Msg_Name_1 := Pname;
1372 ("?pragma% is only effective in main program", N);
1374 end Check_In_Main_Program;
1376 ---------------------------------------
1377 -- Check_Interrupt_Or_Attach_Handler --
1378 ---------------------------------------
1380 procedure Check_Interrupt_Or_Attach_Handler is
1381 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1382 Handler_Proc, Proc_Scope : Entity_Id;
1387 if Prag_Id = Pragma_Interrupt_Handler then
1388 Check_Restriction (No_Dynamic_Attachment, N);
1391 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1392 Proc_Scope := Scope (Handler_Proc);
1394 -- On AAMP only, a pragma Interrupt_Handler is supported for
1395 -- nonprotected parameterless procedures.
1397 if not AAMP_On_Target
1398 or else Prag_Id = Pragma_Attach_Handler
1400 if Ekind (Proc_Scope) /= E_Protected_Type then
1402 ("argument of pragma% must be protected procedure", Arg1);
1405 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1406 Error_Pragma ("pragma% must be in protected definition");
1410 if not Is_Library_Level_Entity (Proc_Scope)
1411 or else (AAMP_On_Target
1412 and then not Is_Library_Level_Entity (Handler_Proc))
1415 ("argument for pragma% must be library level entity", Arg1);
1418 -- AI05-0033: A pragma cannot appear within a generic body, because
1419 -- instance can be in a nested scope. The check that protected type
1420 -- is itself a library-level declaration is done elsewhere.
1422 -- Note: we omit this check in Codepeer mode to properly handle code
1423 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1425 if Inside_A_Generic then
1426 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1427 and then In_Package_Body (Scope (Current_Scope))
1428 and then not CodePeer_Mode
1430 Error_Pragma ("pragma% cannot be used inside a generic");
1433 end Check_Interrupt_Or_Attach_Handler;
1435 -------------------------------------------
1436 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1437 -------------------------------------------
1439 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1448 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1451 elsif Nkind_In (P, N_Package_Specification,
1456 -- Note: the following tests seem a little peculiar, because
1457 -- they test for bodies, but if we were in the statement part
1458 -- of the body, we would already have hit the handled statement
1459 -- sequence, so the only way we get here is by being in the
1460 -- declarative part of the body.
1462 elsif Nkind_In (P, N_Subprogram_Body,
1473 Error_Pragma ("pragma% is not in declarative part or package spec");
1474 end Check_Is_In_Decl_Part_Or_Package_Spec;
1476 -------------------------
1477 -- Check_No_Identifier --
1478 -------------------------
1480 procedure Check_No_Identifier (Arg : Node_Id) is
1482 if Nkind (Arg) = N_Pragma_Argument_Association
1483 and then Chars (Arg) /= No_Name
1485 Error_Pragma_Arg_Ident
1486 ("pragma% does not permit identifier& here", Arg);
1488 end Check_No_Identifier;
1490 --------------------------
1491 -- Check_No_Identifiers --
1492 --------------------------
1494 procedure Check_No_Identifiers is
1497 if Arg_Count > 0 then
1499 while Present (Arg_Node) loop
1500 Check_No_Identifier (Arg_Node);
1504 end Check_No_Identifiers;
1506 -------------------------------
1507 -- Check_Optional_Identifier --
1508 -------------------------------
1510 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1513 and then Nkind (Arg) = N_Pragma_Argument_Association
1514 and then Chars (Arg) /= No_Name
1516 if Chars (Arg) /= Id then
1517 Error_Msg_Name_1 := Pname;
1518 Error_Msg_Name_2 := Id;
1519 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1523 end Check_Optional_Identifier;
1525 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1527 Name_Buffer (1 .. Id'Length) := Id;
1528 Name_Len := Id'Length;
1529 Check_Optional_Identifier (Arg, Name_Find);
1530 end Check_Optional_Identifier;
1532 --------------------------------------
1533 -- Check_Precondition_Postcondition --
1534 --------------------------------------
1536 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1540 procedure Chain_PPC (PO : Node_Id);
1541 -- If PO is a subprogram declaration node (or a generic subprogram
1542 -- declaration node), then the precondition/postcondition applies
1543 -- to this subprogram and the processing for the pragma is completed.
1544 -- Otherwise the pragma is misplaced.
1550 procedure Chain_PPC (PO : Node_Id) is
1555 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1556 if not From_Aspect_Specification (N) then
1558 ("pragma% cannot be applied to abstract subprogram");
1560 elsif Class_Present (N) then
1565 ("aspect % requires ''Class for abstract subprogram");
1568 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1569 N_Generic_Subprogram_Declaration,
1570 N_Entry_Declaration)
1575 -- Here if we have [generic] subprogram or entry declaration
1577 if Nkind (PO) = N_Entry_Declaration then
1578 S := Defining_Entity (PO);
1580 S := Defining_Unit_Name (Specification (PO));
1583 -- Make sure we do not have the case of a precondition pragma when
1584 -- the Pre'Class aspect is present.
1586 -- We do this by looking at pragmas already chained to the entity
1587 -- since the aspect derived pragma will be put on this list first.
1589 if Pragma_Name (N) = Name_Precondition then
1590 if not From_Aspect_Specification (N) then
1591 P := Spec_PPC_List (S);
1592 while Present (P) loop
1593 if Pragma_Name (P) = Name_Precondition
1594 and then From_Aspect_Specification (P)
1595 and then Class_Present (P)
1597 Error_Msg_Sloc := Sloc (P);
1599 ("pragma% not allowed, `Pre''Class` aspect given#");
1602 P := Next_Pragma (P);
1607 -- Similarly check for Pre with inherited Pre'Class. Note that
1608 -- we cover the aspect case as well here.
1610 if Pragma_Name (N) = Name_Precondition
1611 and then not Class_Present (N)
1614 Inherited : constant Subprogram_List :=
1615 Inherited_Subprograms (S);
1619 for J in Inherited'Range loop
1620 P := Spec_PPC_List (Inherited (J));
1621 while Present (P) loop
1622 if Pragma_Name (P) = Name_Precondition
1623 and then Class_Present (P)
1625 Error_Msg_Sloc := Sloc (P);
1627 ("pragma% not allowed, `Pre''Class` "
1628 & "aspect inherited from#");
1631 P := Next_Pragma (P);
1637 -- Note: we do not analye the pragma at this point. Instead we
1638 -- delay this analysis until the end of the declarative part in
1639 -- which the pragma appears. This implements the required delay
1640 -- in this analysis, allowing forward references. The analysis
1641 -- happens at the end of Analyze_Declarations.
1643 -- Chain spec PPC pragma to list for subprogram
1645 Set_Next_Pragma (N, Spec_PPC_List (S));
1646 Set_Spec_PPC_List (S, N);
1648 -- Return indicating spec case
1654 -- Start of processing for Check_Precondition_Postcondition
1657 if not Is_List_Member (N) then
1661 -- Preanalyze message argument if present. Visibility in this
1662 -- argument is established at the point of pragma occurrence.
1664 if Arg_Count = 2 then
1665 Check_Optional_Identifier (Arg2, Name_Message);
1666 Preanalyze_Spec_Expression
1667 (Get_Pragma_Arg (Arg2), Standard_String);
1670 -- Record if pragma is enabled
1672 if Check_Enabled (Pname) then
1673 Set_Pragma_Enabled (N);
1674 Set_SCO_Pragma_Enabled (Loc);
1677 -- If we are within an inlined body, the legality of the pragma
1678 -- has been checked already.
1680 if In_Inlined_Body then
1685 -- Search prior declarations
1688 while Present (Prev (P)) loop
1691 -- If the previous node is a generic subprogram, do not go to to
1692 -- the original node, which is the unanalyzed tree: we need to
1693 -- attach the pre/postconditions to the analyzed version at this
1694 -- point. They get propagated to the original tree when analyzing
1695 -- the corresponding body.
1697 if Nkind (P) not in N_Generic_Declaration then
1698 PO := Original_Node (P);
1703 -- Skip past prior pragma
1705 if Nkind (PO) = N_Pragma then
1708 -- Skip stuff not coming from source
1710 elsif not Comes_From_Source (PO) then
1713 -- Only remaining possibility is subprogram declaration
1721 -- If we fall through loop, pragma is at start of list, so see if it
1722 -- is at the start of declarations of a subprogram body.
1724 if Nkind (Parent (N)) = N_Subprogram_Body
1725 and then List_Containing (N) = Declarations (Parent (N))
1727 if Operating_Mode /= Generate_Code
1728 or else Inside_A_Generic
1730 -- Analyze pragma expression for correctness and for ASIS use
1732 Preanalyze_Spec_Expression
1733 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1739 -- See if it is in the pragmas after a library level subprogram
1741 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1742 Chain_PPC (Unit (Parent (Parent (N))));
1746 -- If we fall through, pragma was misplaced
1749 end Check_Precondition_Postcondition;
1751 -----------------------------
1752 -- Check_Static_Constraint --
1753 -----------------------------
1755 -- Note: for convenience in writing this procedure, in addition to
1756 -- the officially (i.e. by spec) allowed argument which is always a
1757 -- constraint, it also allows ranges and discriminant associations.
1758 -- Above is not clear ???
1760 procedure Check_Static_Constraint (Constr : Node_Id) is
1762 procedure Require_Static (E : Node_Id);
1763 -- Require given expression to be static expression
1765 --------------------
1766 -- Require_Static --
1767 --------------------
1769 procedure Require_Static (E : Node_Id) is
1771 if not Is_OK_Static_Expression (E) then
1772 Flag_Non_Static_Expr
1773 ("non-static constraint not allowed in Unchecked_Union!", E);
1778 -- Start of processing for Check_Static_Constraint
1781 case Nkind (Constr) is
1782 when N_Discriminant_Association =>
1783 Require_Static (Expression (Constr));
1786 Require_Static (Low_Bound (Constr));
1787 Require_Static (High_Bound (Constr));
1789 when N_Attribute_Reference =>
1790 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1791 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1793 when N_Range_Constraint =>
1794 Check_Static_Constraint (Range_Expression (Constr));
1796 when N_Index_Or_Discriminant_Constraint =>
1800 IDC := First (Constraints (Constr));
1801 while Present (IDC) loop
1802 Check_Static_Constraint (IDC);
1810 end Check_Static_Constraint;
1812 --------------------------------------
1813 -- Check_Valid_Configuration_Pragma --
1814 --------------------------------------
1816 -- A configuration pragma must appear in the context clause of a
1817 -- compilation unit, and only other pragmas may precede it. Note that
1818 -- the test also allows use in a configuration pragma file.
1820 procedure Check_Valid_Configuration_Pragma is
1822 if not Is_Configuration_Pragma then
1823 Error_Pragma ("incorrect placement for configuration pragma%");
1825 end Check_Valid_Configuration_Pragma;
1827 -------------------------------------
1828 -- Check_Valid_Library_Unit_Pragma --
1829 -------------------------------------
1831 procedure Check_Valid_Library_Unit_Pragma is
1833 Parent_Node : Node_Id;
1834 Unit_Name : Entity_Id;
1835 Unit_Kind : Node_Kind;
1836 Unit_Node : Node_Id;
1837 Sindex : Source_File_Index;
1840 if not Is_List_Member (N) then
1844 Plist := List_Containing (N);
1845 Parent_Node := Parent (Plist);
1847 if Parent_Node = Empty then
1850 -- Case of pragma appearing after a compilation unit. In this case
1851 -- it must have an argument with the corresponding name and must
1852 -- be part of the following pragmas of its parent.
1854 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1855 if Plist /= Pragmas_After (Parent_Node) then
1858 elsif Arg_Count = 0 then
1860 ("argument required if outside compilation unit");
1863 Check_No_Identifiers;
1864 Check_Arg_Count (1);
1865 Unit_Node := Unit (Parent (Parent_Node));
1866 Unit_Kind := Nkind (Unit_Node);
1868 Analyze (Get_Pragma_Arg (Arg1));
1870 if Unit_Kind = N_Generic_Subprogram_Declaration
1871 or else Unit_Kind = N_Subprogram_Declaration
1873 Unit_Name := Defining_Entity (Unit_Node);
1875 elsif Unit_Kind in N_Generic_Instantiation then
1876 Unit_Name := Defining_Entity (Unit_Node);
1879 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1882 if Chars (Unit_Name) /=
1883 Chars (Entity (Get_Pragma_Arg (Arg1)))
1886 ("pragma% argument is not current unit name", Arg1);
1889 if Ekind (Unit_Name) = E_Package
1890 and then Present (Renamed_Entity (Unit_Name))
1892 Error_Pragma ("pragma% not allowed for renamed package");
1896 -- Pragma appears other than after a compilation unit
1899 -- Here we check for the generic instantiation case and also
1900 -- for the case of processing a generic formal package. We
1901 -- detect these cases by noting that the Sloc on the node
1902 -- does not belong to the current compilation unit.
1904 Sindex := Source_Index (Current_Sem_Unit);
1906 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1907 Rewrite (N, Make_Null_Statement (Loc));
1910 -- If before first declaration, the pragma applies to the
1911 -- enclosing unit, and the name if present must be this name.
1913 elsif Is_Before_First_Decl (N, Plist) then
1914 Unit_Node := Unit_Declaration_Node (Current_Scope);
1915 Unit_Kind := Nkind (Unit_Node);
1917 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1920 elsif Unit_Kind = N_Subprogram_Body
1921 and then not Acts_As_Spec (Unit_Node)
1925 elsif Nkind (Parent_Node) = N_Package_Body then
1928 elsif Nkind (Parent_Node) = N_Package_Specification
1929 and then Plist = Private_Declarations (Parent_Node)
1933 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1934 or else Nkind (Parent_Node) =
1935 N_Generic_Subprogram_Declaration)
1936 and then Plist = Generic_Formal_Declarations (Parent_Node)
1940 elsif Arg_Count > 0 then
1941 Analyze (Get_Pragma_Arg (Arg1));
1943 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
1945 ("name in pragma% must be enclosing unit", Arg1);
1948 -- It is legal to have no argument in this context
1954 -- Error if not before first declaration. This is because a
1955 -- library unit pragma argument must be the name of a library
1956 -- unit (RM 10.1.5(7)), but the only names permitted in this
1957 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1958 -- generic subprogram declarations or generic instantiations.
1962 ("pragma% misplaced, must be before first declaration");
1966 end Check_Valid_Library_Unit_Pragma;
1972 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
1973 Clist : constant Node_Id := Component_List (Variant);
1977 if not Is_Non_Empty_List (Component_Items (Clist)) then
1979 ("Unchecked_Union may not have empty component list",
1984 Comp := First (Component_Items (Clist));
1985 while Present (Comp) loop
1986 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
1995 procedure Error_Pragma (Msg : String) is
1996 MsgF : String := Msg;
1998 Error_Msg_Name_1 := Pname;
2000 Error_Msg_N (MsgF, N);
2004 ----------------------
2005 -- Error_Pragma_Arg --
2006 ----------------------
2008 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2009 MsgF : String := Msg;
2011 Error_Msg_Name_1 := Pname;
2013 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2015 end Error_Pragma_Arg;
2017 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2018 MsgF : String := Msg1;
2020 Error_Msg_Name_1 := Pname;
2022 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2023 Error_Pragma_Arg (Msg2, Arg);
2024 end Error_Pragma_Arg;
2026 ----------------------------
2027 -- Error_Pragma_Arg_Ident --
2028 ----------------------------
2030 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2031 MsgF : String := Msg;
2033 Error_Msg_Name_1 := Pname;
2035 Error_Msg_N (MsgF, Arg);
2037 end Error_Pragma_Arg_Ident;
2039 ----------------------
2040 -- Error_Pragma_Ref --
2041 ----------------------
2043 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2044 MsgF : String := Msg;
2046 Error_Msg_Name_1 := Pname;
2048 Error_Msg_Sloc := Sloc (Ref);
2049 Error_Msg_NE (MsgF, N, Ref);
2051 end Error_Pragma_Ref;
2053 ------------------------
2054 -- Find_Lib_Unit_Name --
2055 ------------------------
2057 function Find_Lib_Unit_Name return Entity_Id is
2059 -- Return inner compilation unit entity, for case of nested
2060 -- categorization pragmas. This happens in generic unit.
2062 if Nkind (Parent (N)) = N_Package_Specification
2063 and then Defining_Entity (Parent (N)) /= Current_Scope
2065 return Defining_Entity (Parent (N));
2067 return Current_Scope;
2069 end Find_Lib_Unit_Name;
2071 ----------------------------
2072 -- Find_Program_Unit_Name --
2073 ----------------------------
2075 procedure Find_Program_Unit_Name (Id : Node_Id) is
2076 Unit_Name : Entity_Id;
2077 Unit_Kind : Node_Kind;
2078 P : constant Node_Id := Parent (N);
2081 if Nkind (P) = N_Compilation_Unit then
2082 Unit_Kind := Nkind (Unit (P));
2084 if Unit_Kind = N_Subprogram_Declaration
2085 or else Unit_Kind = N_Package_Declaration
2086 or else Unit_Kind in N_Generic_Declaration
2088 Unit_Name := Defining_Entity (Unit (P));
2090 if Chars (Id) = Chars (Unit_Name) then
2091 Set_Entity (Id, Unit_Name);
2092 Set_Etype (Id, Etype (Unit_Name));
2094 Set_Etype (Id, Any_Type);
2096 ("cannot find program unit referenced by pragma%");
2100 Set_Etype (Id, Any_Type);
2101 Error_Pragma ("pragma% inapplicable to this unit");
2107 end Find_Program_Unit_Name;
2109 -----------------------------------------
2110 -- Find_Unique_Parameterless_Procedure --
2111 -----------------------------------------
2113 function Find_Unique_Parameterless_Procedure
2115 Arg : Node_Id) return Entity_Id
2117 Proc : Entity_Id := Empty;
2120 -- The body of this procedure needs some comments ???
2122 if not Is_Entity_Name (Name) then
2124 ("argument of pragma% must be entity name", Arg);
2126 elsif not Is_Overloaded (Name) then
2127 Proc := Entity (Name);
2129 if Ekind (Proc) /= E_Procedure
2130 or else Present (First_Formal (Proc))
2133 ("argument of pragma% must be parameterless procedure", Arg);
2138 Found : Boolean := False;
2140 Index : Interp_Index;
2143 Get_First_Interp (Name, Index, It);
2144 while Present (It.Nam) loop
2147 if Ekind (Proc) = E_Procedure
2148 and then No (First_Formal (Proc))
2152 Set_Entity (Name, Proc);
2153 Set_Is_Overloaded (Name, False);
2156 ("ambiguous handler name for pragma% ", Arg);
2160 Get_Next_Interp (Index, It);
2165 ("argument of pragma% must be parameterless procedure",
2168 Proc := Entity (Name);
2174 end Find_Unique_Parameterless_Procedure;
2180 procedure Fix_Error (Msg : in out String) is
2182 if From_Aspect_Specification (N) then
2183 for J in Msg'First .. Msg'Last - 5 loop
2184 if Msg (J .. J + 5) = "pragma" then
2185 Msg (J .. J + 5) := "aspect";
2189 if Error_Msg_Name_1 = Name_Precondition then
2190 Error_Msg_Name_1 := Name_Pre;
2191 elsif Error_Msg_Name_1 = Name_Postcondition then
2192 Error_Msg_Name_1 := Name_Post;
2197 -------------------------
2198 -- Gather_Associations --
2199 -------------------------
2201 procedure Gather_Associations
2203 Args : out Args_List)
2208 -- Initialize all parameters to Empty
2210 for J in Args'Range loop
2214 -- That's all we have to do if there are no argument associations
2216 if No (Pragma_Argument_Associations (N)) then
2220 -- Otherwise first deal with any positional parameters present
2222 Arg := First (Pragma_Argument_Associations (N));
2223 for Index in Args'Range loop
2224 exit when No (Arg) or else Chars (Arg) /= No_Name;
2225 Args (Index) := Get_Pragma_Arg (Arg);
2229 -- Positional parameters all processed, if any left, then we
2230 -- have too many positional parameters.
2232 if Present (Arg) and then Chars (Arg) = No_Name then
2234 ("too many positional associations for pragma%", Arg);
2237 -- Process named parameters if any are present
2239 while Present (Arg) loop
2240 if Chars (Arg) = No_Name then
2242 ("positional association cannot follow named association",
2246 for Index in Names'Range loop
2247 if Names (Index) = Chars (Arg) then
2248 if Present (Args (Index)) then
2250 ("duplicate argument association for pragma%", Arg);
2252 Args (Index) := Get_Pragma_Arg (Arg);
2257 if Index = Names'Last then
2258 Error_Msg_Name_1 := Pname;
2259 Error_Msg_N ("pragma% does not allow & argument", Arg);
2261 -- Check for possible misspelling
2263 for Index1 in Names'Range loop
2264 if Is_Bad_Spelling_Of
2265 (Chars (Arg), Names (Index1))
2267 Error_Msg_Name_1 := Names (Index1);
2268 Error_Msg_N -- CODEFIX
2269 ("\possible misspelling of%", Arg);
2281 end Gather_Associations;
2287 procedure GNAT_Pragma is
2289 Check_Restriction (No_Implementation_Pragmas, N);
2292 --------------------------
2293 -- Is_Before_First_Decl --
2294 --------------------------
2296 function Is_Before_First_Decl
2297 (Pragma_Node : Node_Id;
2298 Decls : List_Id) return Boolean
2300 Item : Node_Id := First (Decls);
2303 -- Only other pragmas can come before this pragma
2306 if No (Item) or else Nkind (Item) /= N_Pragma then
2309 elsif Item = Pragma_Node then
2315 end Is_Before_First_Decl;
2317 -----------------------------
2318 -- Is_Configuration_Pragma --
2319 -----------------------------
2321 -- A configuration pragma must appear in the context clause of a
2322 -- compilation unit, and only other pragmas may precede it. Note that
2323 -- the test below also permits use in a configuration pragma file.
2325 function Is_Configuration_Pragma return Boolean is
2326 Lis : constant List_Id := List_Containing (N);
2327 Par : constant Node_Id := Parent (N);
2331 -- If no parent, then we are in the configuration pragma file,
2332 -- so the placement is definitely appropriate.
2337 -- Otherwise we must be in the context clause of a compilation unit
2338 -- and the only thing allowed before us in the context list is more
2339 -- configuration pragmas.
2341 elsif Nkind (Par) = N_Compilation_Unit
2342 and then Context_Items (Par) = Lis
2349 elsif Nkind (Prg) /= N_Pragma then
2359 end Is_Configuration_Pragma;
2361 --------------------------
2362 -- Is_In_Context_Clause --
2363 --------------------------
2365 function Is_In_Context_Clause return Boolean is
2367 Parent_Node : Node_Id;
2370 if not Is_List_Member (N) then
2374 Plist := List_Containing (N);
2375 Parent_Node := Parent (Plist);
2377 if Parent_Node = Empty
2378 or else Nkind (Parent_Node) /= N_Compilation_Unit
2379 or else Context_Items (Parent_Node) /= Plist
2386 end Is_In_Context_Clause;
2388 ---------------------------------
2389 -- Is_Static_String_Expression --
2390 ---------------------------------
2392 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2393 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2396 Analyze_And_Resolve (Argx);
2397 return Is_OK_Static_Expression (Argx)
2398 and then Nkind (Argx) = N_String_Literal;
2399 end Is_Static_String_Expression;
2401 ----------------------
2402 -- Pragma_Misplaced --
2403 ----------------------
2405 procedure Pragma_Misplaced is
2407 Error_Pragma ("incorrect placement of pragma%");
2408 end Pragma_Misplaced;
2410 ------------------------------------
2411 -- Process Atomic_Shared_Volatile --
2412 ------------------------------------
2414 procedure Process_Atomic_Shared_Volatile is
2421 procedure Set_Atomic (E : Entity_Id);
2422 -- Set given type as atomic, and if no explicit alignment was given,
2423 -- set alignment to unknown, since back end knows what the alignment
2424 -- requirements are for atomic arrays. Note: this step is necessary
2425 -- for derived types.
2431 procedure Set_Atomic (E : Entity_Id) is
2433 Set_Is_Atomic (E, Sense);
2435 if Sense and then not Has_Alignment_Clause (E) then
2436 Set_Alignment (E, Uint_0);
2440 -- Start of processing for Process_Atomic_Shared_Volatile
2443 Check_Ada_83_Warning;
2444 Check_No_Identifiers;
2445 Check_Arg_Count (1);
2446 Check_Arg_Is_Local_Name (Arg1);
2447 E_Id := Get_Pragma_Arg (Arg1);
2449 if Etype (E_Id) = Any_Type then
2454 D := Declaration_Node (E);
2457 -- Check duplicate before we chain ourselves!
2459 Check_Duplicate_Pragma (E);
2461 -- Now check appropriateness of the entity
2464 if Rep_Item_Too_Early (E, N)
2466 Rep_Item_Too_Late (E, N)
2470 Check_First_Subtype (Arg1);
2473 if Prag_Id /= Pragma_Volatile then
2475 Set_Atomic (Underlying_Type (E));
2476 Set_Atomic (Base_Type (E));
2479 -- Attribute belongs on the base type. If the view of the type is
2480 -- currently private, it also belongs on the underlying type.
2482 Set_Is_Volatile (Base_Type (E), Sense);
2483 Set_Is_Volatile (Underlying_Type (E), Sense);
2485 Set_Treat_As_Volatile (E, Sense);
2486 Set_Treat_As_Volatile (Underlying_Type (E), Sense);
2488 elsif K = N_Object_Declaration
2489 or else (K = N_Component_Declaration
2490 and then Original_Record_Component (E) = E)
2492 if Rep_Item_Too_Late (E, N) then
2496 if Prag_Id /= Pragma_Volatile then
2497 Set_Is_Atomic (E, Sense);
2499 -- If the object declaration has an explicit initialization, a
2500 -- temporary may have to be created to hold the expression, to
2501 -- ensure that access to the object remain atomic.
2503 if Nkind (Parent (E)) = N_Object_Declaration
2504 and then Present (Expression (Parent (E)))
2507 Set_Has_Delayed_Freeze (E);
2510 -- An interesting improvement here. If an object of type X is
2511 -- declared atomic, and the type X is not atomic, that's a
2512 -- pity, since it may not have appropriate alignment etc. We
2513 -- can rescue this in the special case where the object and
2514 -- type are in the same unit by just setting the type as
2515 -- atomic, so that the back end will process it as atomic.
2517 Utyp := Underlying_Type (Etype (E));
2520 and then Sloc (E) > No_Location
2521 and then Sloc (Utyp) > No_Location
2523 Get_Source_File_Index (Sloc (E)) =
2524 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2526 Set_Is_Atomic (Underlying_Type (Etype (E)), Sense);
2530 Set_Is_Volatile (E);
2531 Set_Treat_As_Volatile (E);
2535 ("inappropriate entity for pragma%", Arg1);
2537 end Process_Atomic_Shared_Volatile;
2539 -------------------------------------------
2540 -- Process_Compile_Time_Warning_Or_Error --
2541 -------------------------------------------
2543 procedure Process_Compile_Time_Warning_Or_Error is
2544 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2547 Check_Arg_Count (2);
2548 Check_No_Identifiers;
2549 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2550 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2552 if Compile_Time_Known_Value (Arg1x) then
2553 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2555 Str : constant String_Id :=
2556 Strval (Get_Pragma_Arg (Arg2));
2557 Len : constant Int := String_Length (Str);
2562 Cent : constant Entity_Id :=
2563 Cunit_Entity (Current_Sem_Unit);
2565 Force : constant Boolean :=
2566 Prag_Id = Pragma_Compile_Time_Warning
2568 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2569 and then (Ekind (Cent) /= E_Package
2570 or else not In_Private_Part (Cent));
2571 -- Set True if this is the warning case, and we are in the
2572 -- visible part of a package spec, or in a subprogram spec,
2573 -- in which case we want to force the client to see the
2574 -- warning, even though it is not in the main unit.
2577 -- Loop through segments of message separated by line feeds.
2578 -- We output these segments as separate messages with
2579 -- continuation marks for all but the first.
2584 Error_Msg_Strlen := 0;
2586 -- Loop to copy characters from argument to error message
2590 exit when Ptr > Len;
2591 CC := Get_String_Char (Str, Ptr);
2594 -- Ignore wide chars ??? else store character
2596 if In_Character_Range (CC) then
2597 C := Get_Character (CC);
2598 exit when C = ASCII.LF;
2599 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2600 Error_Msg_String (Error_Msg_Strlen) := C;
2604 -- Here with one line ready to go
2606 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2608 -- If this is a warning in a spec, then we want clients
2609 -- to see the warning, so mark the message with the
2610 -- special sequence !! to force the warning. In the case
2611 -- of a package spec, we do not force this if we are in
2612 -- the private part of the spec.
2615 if Cont = False then
2616 Error_Msg_N ("<~!!", Arg1);
2619 Error_Msg_N ("\<~!!", Arg1);
2622 -- Error, rather than warning, or in a body, so we do not
2623 -- need to force visibility for client (error will be
2624 -- output in any case, and this is the situation in which
2625 -- we do not want a client to get a warning, since the
2626 -- warning is in the body or the spec private part).
2629 if Cont = False then
2630 Error_Msg_N ("<~", Arg1);
2633 Error_Msg_N ("\<~", Arg1);
2637 exit when Ptr > Len;
2642 end Process_Compile_Time_Warning_Or_Error;
2644 ------------------------
2645 -- Process_Convention --
2646 ------------------------
2648 procedure Process_Convention
2649 (C : out Convention_Id;
2650 Ent : out Entity_Id)
2656 Comp_Unit : Unit_Number_Type;
2658 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2659 -- Called if we have more than one Export/Import/Convention pragma.
2660 -- This is generally illegal, but we have a special case of allowing
2661 -- Import and Interface to coexist if they specify the convention in
2662 -- a consistent manner. We are allowed to do this, since Interface is
2663 -- an implementation defined pragma, and we choose to do it since we
2664 -- know Rational allows this combination. S is the entity id of the
2665 -- subprogram in question. This procedure also sets the special flag
2666 -- Import_Interface_Present in both pragmas in the case where we do
2667 -- have matching Import and Interface pragmas.
2669 procedure Set_Convention_From_Pragma (E : Entity_Id);
2670 -- Set convention in entity E, and also flag that the entity has a
2671 -- convention pragma. If entity is for a private or incomplete type,
2672 -- also set convention and flag on underlying type. This procedure
2673 -- also deals with the special case of C_Pass_By_Copy convention.
2675 -------------------------------
2676 -- Diagnose_Multiple_Pragmas --
2677 -------------------------------
2679 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2680 Pdec : constant Node_Id := Declaration_Node (S);
2684 function Same_Convention (Decl : Node_Id) return Boolean;
2685 -- Decl is a pragma node. This function returns True if this
2686 -- pragma has a first argument that is an identifier with a
2687 -- Chars field corresponding to the Convention_Id C.
2689 function Same_Name (Decl : Node_Id) return Boolean;
2690 -- Decl is a pragma node. This function returns True if this
2691 -- pragma has a second argument that is an identifier with a
2692 -- Chars field that matches the Chars of the current subprogram.
2694 ---------------------
2695 -- Same_Convention --
2696 ---------------------
2698 function Same_Convention (Decl : Node_Id) return Boolean is
2699 Arg1 : constant Node_Id :=
2700 First (Pragma_Argument_Associations (Decl));
2703 if Present (Arg1) then
2705 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2707 if Nkind (Arg) = N_Identifier
2708 and then Is_Convention_Name (Chars (Arg))
2709 and then Get_Convention_Id (Chars (Arg)) = C
2717 end Same_Convention;
2723 function Same_Name (Decl : Node_Id) return Boolean is
2724 Arg1 : constant Node_Id :=
2725 First (Pragma_Argument_Associations (Decl));
2733 Arg2 := Next (Arg1);
2740 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2742 if Nkind (Arg) = N_Identifier
2743 and then Chars (Arg) = Chars (S)
2752 -- Start of processing for Diagnose_Multiple_Pragmas
2757 -- Definitely give message if we have Convention/Export here
2759 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2762 -- If we have an Import or Export, scan back from pragma to
2763 -- find any previous pragma applying to the same procedure.
2764 -- The scan will be terminated by the start of the list, or
2765 -- hitting the subprogram declaration. This won't allow one
2766 -- pragma to appear in the public part and one in the private
2767 -- part, but that seems very unlikely in practice.
2771 while Present (Decl) and then Decl /= Pdec loop
2773 -- Look for pragma with same name as us
2775 if Nkind (Decl) = N_Pragma
2776 and then Same_Name (Decl)
2778 -- Give error if same as our pragma or Export/Convention
2780 if Pragma_Name (Decl) = Name_Export
2782 Pragma_Name (Decl) = Name_Convention
2784 Pragma_Name (Decl) = Pragma_Name (N)
2788 -- Case of Import/Interface or the other way round
2790 elsif Pragma_Name (Decl) = Name_Interface
2792 Pragma_Name (Decl) = Name_Import
2794 -- Here we know that we have Import and Interface. It
2795 -- doesn't matter which way round they are. See if
2796 -- they specify the same convention. If so, all OK,
2797 -- and set special flags to stop other messages
2799 if Same_Convention (Decl) then
2800 Set_Import_Interface_Present (N);
2801 Set_Import_Interface_Present (Decl);
2804 -- If different conventions, special message
2807 Error_Msg_Sloc := Sloc (Decl);
2809 ("convention differs from that given#", Arg1);
2819 -- Give message if needed if we fall through those tests
2823 ("at most one Convention/Export/Import pragma is allowed",
2826 end Diagnose_Multiple_Pragmas;
2828 --------------------------------
2829 -- Set_Convention_From_Pragma --
2830 --------------------------------
2832 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2834 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2835 -- for an overridden dispatching operation. Technically this is
2836 -- an amendment and should only be done in Ada 2005 mode. However,
2837 -- this is clearly a mistake, since the problem that is addressed
2838 -- by this AI is that there is a clear gap in the RM!
2840 if Is_Dispatching_Operation (E)
2841 and then Present (Overridden_Operation (E))
2842 and then C /= Convention (Overridden_Operation (E))
2845 ("cannot change convention for " &
2846 "overridden dispatching operation",
2850 -- Set the convention
2852 Set_Convention (E, C);
2853 Set_Has_Convention_Pragma (E);
2855 if Is_Incomplete_Or_Private_Type (E) then
2856 Set_Convention (Underlying_Type (E), C);
2857 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2860 -- A class-wide type should inherit the convention of the specific
2861 -- root type (although this isn't specified clearly by the RM).
2863 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2864 Set_Convention (Class_Wide_Type (E), C);
2867 -- If the entity is a record type, then check for special case of
2868 -- C_Pass_By_Copy, which is treated the same as C except that the
2869 -- special record flag is set. This convention is only permitted
2870 -- on record types (see AI95-00131).
2872 if Cname = Name_C_Pass_By_Copy then
2873 if Is_Record_Type (E) then
2874 Set_C_Pass_By_Copy (Base_Type (E));
2875 elsif Is_Incomplete_Or_Private_Type (E)
2876 and then Is_Record_Type (Underlying_Type (E))
2878 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2881 ("C_Pass_By_Copy convention allowed only for record type",
2886 -- If the entity is a derived boolean type, check for the special
2887 -- case of convention C, C++, or Fortran, where we consider any
2888 -- nonzero value to represent true.
2890 if Is_Discrete_Type (E)
2891 and then Root_Type (Etype (E)) = Standard_Boolean
2897 C = Convention_Fortran)
2899 Set_Nonzero_Is_True (Base_Type (E));
2901 end Set_Convention_From_Pragma;
2903 -- Start of processing for Process_Convention
2906 Check_At_Least_N_Arguments (2);
2907 Check_Optional_Identifier (Arg1, Name_Convention);
2908 Check_Arg_Is_Identifier (Arg1);
2909 Cname := Chars (Get_Pragma_Arg (Arg1));
2911 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2912 -- tested again below to set the critical flag).
2913 if Cname = Name_C_Pass_By_Copy then
2916 -- Otherwise we must have something in the standard convention list
2918 elsif Is_Convention_Name (Cname) then
2919 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
2921 -- In DEC VMS, it seems that there is an undocumented feature that
2922 -- any unrecognized convention is treated as the default, which for
2923 -- us is convention C. It does not seem so terrible to do this
2924 -- unconditionally, silently in the VMS case, and with a warning
2925 -- in the non-VMS case.
2928 if Warn_On_Export_Import and not OpenVMS_On_Target then
2930 ("?unrecognized convention name, C assumed",
2931 Get_Pragma_Arg (Arg1));
2937 Check_Optional_Identifier (Arg2, Name_Entity);
2938 Check_Arg_Is_Local_Name (Arg2);
2940 Id := Get_Pragma_Arg (Arg2);
2943 if not Is_Entity_Name (Id) then
2944 Error_Pragma_Arg ("entity name required", Arg2);
2949 -- Set entity to return
2953 -- Go to renamed subprogram if present, since convention applies to
2954 -- the actual renamed entity, not to the renaming entity. If the
2955 -- subprogram is inherited, go to parent subprogram.
2957 if Is_Subprogram (E)
2958 and then Present (Alias (E))
2960 if Nkind (Parent (Declaration_Node (E))) =
2961 N_Subprogram_Renaming_Declaration
2963 if Scope (E) /= Scope (Alias (E)) then
2965 ("cannot apply pragma% to non-local entity&#", E);
2970 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
2971 N_Private_Extension_Declaration)
2972 and then Scope (E) = Scope (Alias (E))
2976 -- Return the parent subprogram the entity was inherited from
2982 -- Check that we are not applying this to a specless body
2984 if Is_Subprogram (E)
2985 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2988 ("pragma% requires separate spec and must come before body");
2991 -- Check that we are not applying this to a named constant
2993 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
2994 Error_Msg_Name_1 := Pname;
2996 ("cannot apply pragma% to named constant!",
2997 Get_Pragma_Arg (Arg2));
2999 ("\supply appropriate type for&!", Arg2);
3002 if Ekind (E) = E_Enumeration_Literal then
3003 Error_Pragma ("enumeration literal not allowed for pragma%");
3006 -- Check for rep item appearing too early or too late
3008 if Etype (E) = Any_Type
3009 or else Rep_Item_Too_Early (E, N)
3013 E := Underlying_Type (E);
3016 if Rep_Item_Too_Late (E, N) then
3020 if Has_Convention_Pragma (E) then
3021 Diagnose_Multiple_Pragmas (E);
3023 elsif Convention (E) = Convention_Protected
3024 or else Ekind (Scope (E)) = E_Protected_Type
3027 ("a protected operation cannot be given a different convention",
3031 -- For Intrinsic, a subprogram is required
3033 if C = Convention_Intrinsic
3034 and then not Is_Subprogram (E)
3035 and then not Is_Generic_Subprogram (E)
3038 ("second argument of pragma% must be a subprogram", Arg2);
3041 -- For Stdcall, a subprogram, variable or subprogram type is required
3043 if C = Convention_Stdcall
3044 and then not Is_Subprogram (E)
3045 and then not Is_Generic_Subprogram (E)
3046 and then Ekind (E) /= E_Variable
3049 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3052 ("second argument of pragma% must be subprogram (type)",
3056 if not Is_Subprogram (E)
3057 and then not Is_Generic_Subprogram (E)
3059 Set_Convention_From_Pragma (E);
3062 Check_First_Subtype (Arg2);
3063 Set_Convention_From_Pragma (Base_Type (E));
3065 -- For subprograms, we must set the convention on the
3066 -- internally generated directly designated type as well.
3068 if Ekind (E) = E_Access_Subprogram_Type then
3069 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3073 -- For the subprogram case, set proper convention for all homonyms
3074 -- in same scope and the same declarative part, i.e. the same
3075 -- compilation unit.
3078 Comp_Unit := Get_Source_Unit (E);
3079 Set_Convention_From_Pragma (E);
3081 -- Treat a pragma Import as an implicit body, for GPS use
3083 if Prag_Id = Pragma_Import then
3084 Generate_Reference (E, Id, 'b');
3087 -- Loop through the homonyms of the pragma argument's entity
3092 exit when No (E1) or else Scope (E1) /= Current_Scope;
3094 -- Do not set the pragma on inherited operations or on formal
3097 if Comes_From_Source (E1)
3098 and then Comp_Unit = Get_Source_Unit (E1)
3099 and then not Is_Formal_Subprogram (E1)
3100 and then Nkind (Original_Node (Parent (E1))) /=
3101 N_Full_Type_Declaration
3103 if Present (Alias (E1))
3104 and then Scope (E1) /= Scope (Alias (E1))
3107 ("cannot apply pragma% to non-local entity& declared#",
3111 Set_Convention_From_Pragma (E1);
3113 if Prag_Id = Pragma_Import then
3114 Generate_Reference (E1, Id, 'b');
3118 -- For aspect case, do NOT apply to homonyms
3120 exit when From_Aspect_Specification (N);
3123 end Process_Convention;
3125 -----------------------------------------------------
3126 -- Process_Extended_Import_Export_Exception_Pragma --
3127 -----------------------------------------------------
3129 procedure Process_Extended_Import_Export_Exception_Pragma
3130 (Arg_Internal : Node_Id;
3131 Arg_External : Node_Id;
3139 if not OpenVMS_On_Target then
3141 ("?pragma% ignored (applies only to Open'V'M'S)");
3144 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3145 Def_Id := Entity (Arg_Internal);
3147 if Ekind (Def_Id) /= E_Exception then
3149 ("pragma% must refer to declared exception", Arg_Internal);
3152 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3154 if Present (Arg_Form) then
3155 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3158 if Present (Arg_Form)
3159 and then Chars (Arg_Form) = Name_Ada
3163 Set_Is_VMS_Exception (Def_Id);
3164 Set_Exception_Code (Def_Id, No_Uint);
3167 if Present (Arg_Code) then
3168 if not Is_VMS_Exception (Def_Id) then
3170 ("Code option for pragma% not allowed for Ada case",
3174 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3175 Code_Val := Expr_Value (Arg_Code);
3177 if not UI_Is_In_Int_Range (Code_Val) then
3179 ("Code option for pragma% must be in 32-bit range",
3183 Set_Exception_Code (Def_Id, Code_Val);
3186 end Process_Extended_Import_Export_Exception_Pragma;
3188 -------------------------------------------------
3189 -- Process_Extended_Import_Export_Internal_Arg --
3190 -------------------------------------------------
3192 procedure Process_Extended_Import_Export_Internal_Arg
3193 (Arg_Internal : Node_Id := Empty)
3196 if No (Arg_Internal) then
3197 Error_Pragma ("Internal parameter required for pragma%");
3200 if Nkind (Arg_Internal) = N_Identifier then
3203 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3204 and then (Prag_Id = Pragma_Import_Function
3206 Prag_Id = Pragma_Export_Function)
3212 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3215 Check_Arg_Is_Local_Name (Arg_Internal);
3216 end Process_Extended_Import_Export_Internal_Arg;
3218 --------------------------------------------------
3219 -- Process_Extended_Import_Export_Object_Pragma --
3220 --------------------------------------------------
3222 procedure Process_Extended_Import_Export_Object_Pragma
3223 (Arg_Internal : Node_Id;
3224 Arg_External : Node_Id;
3230 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3231 Def_Id := Entity (Arg_Internal);
3233 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3235 ("pragma% must designate an object", Arg_Internal);
3238 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3240 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3243 ("previous Common/Psect_Object applies, pragma % not permitted",
3247 if Rep_Item_Too_Late (Def_Id, N) then
3251 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3253 if Present (Arg_Size) then
3254 Check_Arg_Is_External_Name (Arg_Size);
3257 -- Export_Object case
3259 if Prag_Id = Pragma_Export_Object then
3260 if not Is_Library_Level_Entity (Def_Id) then
3262 ("argument for pragma% must be library level entity",
3266 if Ekind (Current_Scope) = E_Generic_Package then
3267 Error_Pragma ("pragma& cannot appear in a generic unit");
3270 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3272 ("exported object must have compile time known size",
3276 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3277 Error_Msg_N ("?duplicate Export_Object pragma", N);
3279 Set_Exported (Def_Id, Arg_Internal);
3282 -- Import_Object case
3285 if Is_Concurrent_Type (Etype (Def_Id)) then
3287 ("cannot use pragma% for task/protected object",
3291 if Ekind (Def_Id) = E_Constant then
3293 ("cannot import a constant", Arg_Internal);
3296 if Warn_On_Export_Import
3297 and then Has_Discriminants (Etype (Def_Id))
3300 ("imported value must be initialized?", Arg_Internal);
3303 if Warn_On_Export_Import
3304 and then Is_Access_Type (Etype (Def_Id))
3307 ("cannot import object of an access type?", Arg_Internal);
3310 if Warn_On_Export_Import
3311 and then Is_Imported (Def_Id)
3314 ("?duplicate Import_Object pragma", N);
3316 -- Check for explicit initialization present. Note that an
3317 -- initialization generated by the code generator, e.g. for an
3318 -- access type, does not count here.
3320 elsif Present (Expression (Parent (Def_Id)))
3323 (Original_Node (Expression (Parent (Def_Id))))
3325 Error_Msg_Sloc := Sloc (Def_Id);
3327 ("imported entities cannot be initialized (RM B.1(24))",
3328 "\no initialization allowed for & declared#", Arg1);
3330 Set_Imported (Def_Id);
3331 Note_Possible_Modification (Arg_Internal, Sure => False);
3334 end Process_Extended_Import_Export_Object_Pragma;
3336 ------------------------------------------------------
3337 -- Process_Extended_Import_Export_Subprogram_Pragma --
3338 ------------------------------------------------------
3340 procedure Process_Extended_Import_Export_Subprogram_Pragma
3341 (Arg_Internal : Node_Id;
3342 Arg_External : Node_Id;
3343 Arg_Parameter_Types : Node_Id;
3344 Arg_Result_Type : Node_Id := Empty;
3345 Arg_Mechanism : Node_Id;
3346 Arg_Result_Mechanism : Node_Id := Empty;
3347 Arg_First_Optional_Parameter : Node_Id := Empty)
3353 Ambiguous : Boolean;
3357 function Same_Base_Type
3359 Formal : Entity_Id) return Boolean;
3360 -- Determines if Ptype references the type of Formal. Note that only
3361 -- the base types need to match according to the spec. Ptype here is
3362 -- the argument from the pragma, which is either a type name, or an
3363 -- access attribute.
3365 --------------------
3366 -- Same_Base_Type --
3367 --------------------
3369 function Same_Base_Type
3371 Formal : Entity_Id) return Boolean
3373 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3377 -- Case where pragma argument is typ'Access
3379 if Nkind (Ptype) = N_Attribute_Reference
3380 and then Attribute_Name (Ptype) = Name_Access
3382 Pref := Prefix (Ptype);
3385 if not Is_Entity_Name (Pref)
3386 or else Entity (Pref) = Any_Type
3391 -- We have a match if the corresponding argument is of an
3392 -- anonymous access type, and its designated type matches the
3393 -- type of the prefix of the access attribute
3395 return Ekind (Ftyp) = E_Anonymous_Access_Type
3396 and then Base_Type (Entity (Pref)) =
3397 Base_Type (Etype (Designated_Type (Ftyp)));
3399 -- Case where pragma argument is a type name
3404 if not Is_Entity_Name (Ptype)
3405 or else Entity (Ptype) = Any_Type
3410 -- We have a match if the corresponding argument is of the type
3411 -- given in the pragma (comparing base types)
3413 return Base_Type (Entity (Ptype)) = Ftyp;
3417 -- Start of processing for
3418 -- Process_Extended_Import_Export_Subprogram_Pragma
3421 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3425 -- Loop through homonyms (overloadings) of the entity
3427 Hom_Id := Entity (Arg_Internal);
3428 while Present (Hom_Id) loop
3429 Def_Id := Get_Base_Subprogram (Hom_Id);
3431 -- We need a subprogram in the current scope
3433 if not Is_Subprogram (Def_Id)
3434 or else Scope (Def_Id) /= Current_Scope
3441 -- Pragma cannot apply to subprogram body
3443 if Is_Subprogram (Def_Id)
3444 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3448 ("pragma% requires separate spec"
3449 & " and must come before body");
3452 -- Test result type if given, note that the result type
3453 -- parameter can only be present for the function cases.
3455 if Present (Arg_Result_Type)
3456 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3460 elsif Etype (Def_Id) /= Standard_Void_Type
3462 (Pname = Name_Export_Procedure
3464 Pname = Name_Import_Procedure)
3468 -- Test parameter types if given. Note that this parameter
3469 -- has not been analyzed (and must not be, since it is
3470 -- semantic nonsense), so we get it as the parser left it.
3472 elsif Present (Arg_Parameter_Types) then
3473 Check_Matching_Types : declare
3478 Formal := First_Formal (Def_Id);
3480 if Nkind (Arg_Parameter_Types) = N_Null then
3481 if Present (Formal) then
3485 -- A list of one type, e.g. (List) is parsed as
3486 -- a parenthesized expression.
3488 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3489 and then Paren_Count (Arg_Parameter_Types) = 1
3492 or else Present (Next_Formal (Formal))
3497 Same_Base_Type (Arg_Parameter_Types, Formal);
3500 -- A list of more than one type is parsed as a aggregate
3502 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3503 and then Paren_Count (Arg_Parameter_Types) = 0
3505 Ptype := First (Expressions (Arg_Parameter_Types));
3506 while Present (Ptype) or else Present (Formal) loop
3509 or else not Same_Base_Type (Ptype, Formal)
3514 Next_Formal (Formal);
3519 -- Anything else is of the wrong form
3523 ("wrong form for Parameter_Types parameter",
3524 Arg_Parameter_Types);
3526 end Check_Matching_Types;
3529 -- Match is now False if the entry we found did not match
3530 -- either a supplied Parameter_Types or Result_Types argument
3536 -- Ambiguous case, the flag Ambiguous shows if we already
3537 -- detected this and output the initial messages.
3540 if not Ambiguous then
3542 Error_Msg_Name_1 := Pname;
3544 ("pragma% does not uniquely identify subprogram!",
3546 Error_Msg_Sloc := Sloc (Ent);
3547 Error_Msg_N ("matching subprogram #!", N);
3551 Error_Msg_Sloc := Sloc (Def_Id);
3552 Error_Msg_N ("matching subprogram #!", N);
3557 Hom_Id := Homonym (Hom_Id);
3560 -- See if we found an entry
3563 if not Ambiguous then
3564 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3566 ("pragma% cannot be given for generic subprogram");
3569 ("pragma% does not identify local subprogram");
3576 -- Import pragmas must be for imported entities
3578 if Prag_Id = Pragma_Import_Function
3580 Prag_Id = Pragma_Import_Procedure
3582 Prag_Id = Pragma_Import_Valued_Procedure
3584 if not Is_Imported (Ent) then
3586 ("pragma Import or Interface must precede pragma%");
3589 -- Here we have the Export case which can set the entity as exported
3591 -- But does not do so if the specified external name is null, since
3592 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3593 -- compatible) to request no external name.
3595 elsif Nkind (Arg_External) = N_String_Literal
3596 and then String_Length (Strval (Arg_External)) = 0
3600 -- In all other cases, set entity as exported
3603 Set_Exported (Ent, Arg_Internal);
3606 -- Special processing for Valued_Procedure cases
3608 if Prag_Id = Pragma_Import_Valued_Procedure
3610 Prag_Id = Pragma_Export_Valued_Procedure
3612 Formal := First_Formal (Ent);
3615 Error_Pragma ("at least one parameter required for pragma%");
3617 elsif Ekind (Formal) /= E_Out_Parameter then
3618 Error_Pragma ("first parameter must have mode out for pragma%");
3621 Set_Is_Valued_Procedure (Ent);
3625 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3627 -- Process Result_Mechanism argument if present. We have already
3628 -- checked that this is only allowed for the function case.
3630 if Present (Arg_Result_Mechanism) then
3631 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3634 -- Process Mechanism parameter if present. Note that this parameter
3635 -- is not analyzed, and must not be analyzed since it is semantic
3636 -- nonsense, so we get it in exactly as the parser left it.
3638 if Present (Arg_Mechanism) then
3646 -- A single mechanism association without a formal parameter
3647 -- name is parsed as a parenthesized expression. All other
3648 -- cases are parsed as aggregates, so we rewrite the single
3649 -- parameter case as an aggregate for consistency.
3651 if Nkind (Arg_Mechanism) /= N_Aggregate
3652 and then Paren_Count (Arg_Mechanism) = 1
3654 Rewrite (Arg_Mechanism,
3655 Make_Aggregate (Sloc (Arg_Mechanism),
3656 Expressions => New_List (
3657 Relocate_Node (Arg_Mechanism))));
3660 -- Case of only mechanism name given, applies to all formals
3662 if Nkind (Arg_Mechanism) /= N_Aggregate then
3663 Formal := First_Formal (Ent);
3664 while Present (Formal) loop
3665 Set_Mechanism_Value (Formal, Arg_Mechanism);
3666 Next_Formal (Formal);
3669 -- Case of list of mechanism associations given
3672 if Null_Record_Present (Arg_Mechanism) then
3674 ("inappropriate form for Mechanism parameter",
3678 -- Deal with positional ones first
3680 Formal := First_Formal (Ent);
3682 if Present (Expressions (Arg_Mechanism)) then
3683 Mname := First (Expressions (Arg_Mechanism));
3684 while Present (Mname) loop
3687 ("too many mechanism associations", Mname);
3690 Set_Mechanism_Value (Formal, Mname);
3691 Next_Formal (Formal);
3696 -- Deal with named entries
3698 if Present (Component_Associations (Arg_Mechanism)) then
3699 Massoc := First (Component_Associations (Arg_Mechanism));
3700 while Present (Massoc) loop
3701 Choice := First (Choices (Massoc));
3703 if Nkind (Choice) /= N_Identifier
3704 or else Present (Next (Choice))
3707 ("incorrect form for mechanism association",
3711 Formal := First_Formal (Ent);
3715 ("parameter name & not present", Choice);
3718 if Chars (Choice) = Chars (Formal) then
3720 (Formal, Expression (Massoc));
3722 -- Set entity on identifier (needed by ASIS)
3724 Set_Entity (Choice, Formal);
3729 Next_Formal (Formal);
3739 -- Process First_Optional_Parameter argument if present. We have
3740 -- already checked that this is only allowed for the Import case.
3742 if Present (Arg_First_Optional_Parameter) then
3743 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3745 ("first optional parameter must be formal parameter name",
3746 Arg_First_Optional_Parameter);
3749 Formal := First_Formal (Ent);
3753 ("specified formal parameter& not found",
3754 Arg_First_Optional_Parameter);
3757 exit when Chars (Formal) =
3758 Chars (Arg_First_Optional_Parameter);
3760 Next_Formal (Formal);
3763 Set_First_Optional_Parameter (Ent, Formal);
3765 -- Check specified and all remaining formals have right form
3767 while Present (Formal) loop
3768 if Ekind (Formal) /= E_In_Parameter then
3770 ("optional formal& is not of mode in!",
3771 Arg_First_Optional_Parameter, Formal);
3774 Dval := Default_Value (Formal);
3778 ("optional formal& does not have default value!",
3779 Arg_First_Optional_Parameter, Formal);
3781 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3786 ("default value for optional formal& is non-static!",
3787 Arg_First_Optional_Parameter, Formal);
3791 Set_Is_Optional_Parameter (Formal);
3792 Next_Formal (Formal);
3795 end Process_Extended_Import_Export_Subprogram_Pragma;
3797 --------------------------
3798 -- Process_Generic_List --
3799 --------------------------
3801 procedure Process_Generic_List is
3806 Check_No_Identifiers;
3807 Check_At_Least_N_Arguments (1);
3810 while Present (Arg) loop
3811 Exp := Get_Pragma_Arg (Arg);
3814 if not Is_Entity_Name (Exp)
3816 (not Is_Generic_Instance (Entity (Exp))
3818 not Is_Generic_Unit (Entity (Exp)))
3821 ("pragma% argument must be name of generic unit/instance",
3827 end Process_Generic_List;
3829 ---------------------------------
3830 -- Process_Import_Or_Interface --
3831 ---------------------------------
3833 procedure Process_Import_Or_Interface is
3839 Process_Convention (C, Def_Id);
3840 Kill_Size_Check_Code (Def_Id);
3841 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
3843 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3845 -- We do not permit Import to apply to a renaming declaration
3847 if Present (Renamed_Object (Def_Id)) then
3849 ("pragma% not allowed for object renaming", Arg2);
3851 -- User initialization is not allowed for imported object, but
3852 -- the object declaration may contain a default initialization,
3853 -- that will be discarded. Note that an explicit initialization
3854 -- only counts if it comes from source, otherwise it is simply
3855 -- the code generator making an implicit initialization explicit.
3857 elsif Present (Expression (Parent (Def_Id)))
3858 and then Comes_From_Source (Expression (Parent (Def_Id)))
3860 Error_Msg_Sloc := Sloc (Def_Id);
3862 ("no initialization allowed for declaration of& #",
3863 "\imported entities cannot be initialized (RM B.1(24))",
3867 Set_Imported (Def_Id);
3868 Process_Interface_Name (Def_Id, Arg3, Arg4);
3870 -- Note that we do not set Is_Public here. That's because we
3871 -- only want to set it if there is no address clause, and we
3872 -- don't know that yet, so we delay that processing till
3875 -- pragma Import completes deferred constants
3877 if Ekind (Def_Id) = E_Constant then
3878 Set_Has_Completion (Def_Id);
3881 -- It is not possible to import a constant of an unconstrained
3882 -- array type (e.g. string) because there is no simple way to
3883 -- write a meaningful subtype for it.
3885 if Is_Array_Type (Etype (Def_Id))
3886 and then not Is_Constrained (Etype (Def_Id))
3889 ("imported constant& must have a constrained subtype",
3894 elsif Is_Subprogram (Def_Id)
3895 or else Is_Generic_Subprogram (Def_Id)
3897 -- If the name is overloaded, pragma applies to all of the denoted
3898 -- entities in the same declarative part.
3901 while Present (Hom_Id) loop
3902 Def_Id := Get_Base_Subprogram (Hom_Id);
3904 -- Ignore inherited subprograms because the pragma will apply
3905 -- to the parent operation, which is the one called.
3907 if Is_Overloadable (Def_Id)
3908 and then Present (Alias (Def_Id))
3912 -- If it is not a subprogram, it must be in an outer scope and
3913 -- pragma does not apply.
3915 elsif not Is_Subprogram (Def_Id)
3916 and then not Is_Generic_Subprogram (Def_Id)
3920 -- Verify that the homonym is in the same declarative part (not
3921 -- just the same scope).
3923 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3924 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3929 Set_Imported (Def_Id);
3931 -- Reject an Import applied to an abstract subprogram
3933 if Is_Subprogram (Def_Id)
3934 and then Is_Abstract_Subprogram (Def_Id)
3936 Error_Msg_Sloc := Sloc (Def_Id);
3938 ("cannot import abstract subprogram& declared#",
3942 -- Special processing for Convention_Intrinsic
3944 if C = Convention_Intrinsic then
3946 -- Link_Name argument not allowed for intrinsic
3949 and then Chars (Arg3) = Name_Link_Name
3954 if Present (Arg4) then
3956 ("Link_Name argument not allowed for " &
3961 Set_Is_Intrinsic_Subprogram (Def_Id);
3963 -- If no external name is present, then check that this
3964 -- is a valid intrinsic subprogram. If an external name
3965 -- is present, then this is handled by the back end.
3968 Check_Intrinsic_Subprogram
3969 (Def_Id, Get_Pragma_Arg (Arg2));
3973 -- All interfaced procedures need an external symbol created
3974 -- for them since they are always referenced from another
3977 Set_Is_Public (Def_Id);
3979 -- Verify that the subprogram does not have a completion
3980 -- through a renaming declaration. For other completions the
3981 -- pragma appears as a too late representation.
3984 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3988 and then Nkind (Decl) = N_Subprogram_Declaration
3989 and then Present (Corresponding_Body (Decl))
3990 and then Nkind (Unit_Declaration_Node
3991 (Corresponding_Body (Decl))) =
3992 N_Subprogram_Renaming_Declaration
3994 Error_Msg_Sloc := Sloc (Def_Id);
3996 ("cannot import&, renaming already provided for " &
3997 "declaration #", N, Def_Id);
4001 Set_Has_Completion (Def_Id);
4002 Process_Interface_Name (Def_Id, Arg3, Arg4);
4005 if Is_Compilation_Unit (Hom_Id) then
4007 -- Its possible homonyms are not affected by the pragma.
4008 -- Such homonyms might be present in the context of other
4009 -- units being compiled.
4014 Hom_Id := Homonym (Hom_Id);
4018 -- When the convention is Java or CIL, we also allow Import to be
4019 -- given for packages, generic packages, exceptions, record
4020 -- components, and access to subprograms.
4022 elsif (C = Convention_Java or else C = Convention_CIL)
4024 (Is_Package_Or_Generic_Package (Def_Id)
4025 or else Ekind (Def_Id) = E_Exception
4026 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4027 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4029 Set_Imported (Def_Id);
4030 Set_Is_Public (Def_Id);
4031 Process_Interface_Name (Def_Id, Arg3, Arg4);
4033 -- Import a CPP class
4035 elsif Is_Record_Type (Def_Id)
4036 and then C = Convention_CPP
4038 -- Types treated as CPP classes are treated as limited, but we
4039 -- don't require them to be declared this way. A warning is
4040 -- issued to encourage the user to declare them as limited.
4041 -- This is not an error, for compatibility reasons, because
4042 -- these types have been supported this way for some time.
4044 if not Is_Limited_Type (Def_Id) then
4046 ("imported 'C'P'P type should be " &
4047 "explicitly declared limited?",
4048 Get_Pragma_Arg (Arg2));
4050 ("\type will be considered limited",
4051 Get_Pragma_Arg (Arg2));
4054 Set_Is_CPP_Class (Def_Id);
4055 Set_Is_Limited_Record (Def_Id);
4057 -- Imported CPP types must not have discriminants (because C++
4058 -- classes do not have discriminants).
4060 if Has_Discriminants (Def_Id) then
4062 ("imported 'C'P'P type cannot have discriminants",
4063 First (Discriminant_Specifications
4064 (Declaration_Node (Def_Id))));
4067 -- Components of imported CPP types must not have default
4068 -- expressions because the constructor (if any) is on the
4072 Tdef : constant Node_Id :=
4073 Type_Definition (Declaration_Node (Def_Id));
4078 if Nkind (Tdef) = N_Record_Definition then
4079 Clist := Component_List (Tdef);
4082 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4083 Clist := Component_List (Record_Extension_Part (Tdef));
4086 if Present (Clist) then
4087 Comp := First (Component_Items (Clist));
4088 while Present (Comp) loop
4089 if Present (Expression (Comp)) then
4091 ("component of imported 'C'P'P type cannot have" &
4092 " default expression", Expression (Comp));
4102 ("second argument of pragma% must be object or subprogram",
4106 -- If this pragma applies to a compilation unit, then the unit, which
4107 -- is a subprogram, does not require (or allow) a body. We also do
4108 -- not need to elaborate imported procedures.
4110 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4112 Cunit : constant Node_Id := Parent (Parent (N));
4114 Set_Body_Required (Cunit, False);
4117 end Process_Import_Or_Interface;
4119 --------------------
4120 -- Process_Inline --
4121 --------------------
4123 procedure Process_Inline (Active : Boolean) is
4129 Effective : Boolean := False;
4131 procedure Make_Inline (Subp : Entity_Id);
4132 -- Subp is the defining unit name of the subprogram declaration. Set
4133 -- the flag, as well as the flag in the corresponding body, if there
4136 procedure Set_Inline_Flags (Subp : Entity_Id);
4137 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4138 -- Has_Pragma_Inline_Always for the Inline_Always case.
4140 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4141 -- Returns True if it can be determined at this stage that inlining
4142 -- is not possible, for example if the body is available and contains
4143 -- exception handlers, we prevent inlining, since otherwise we can
4144 -- get undefined symbols at link time. This function also emits a
4145 -- warning if front-end inlining is enabled and the pragma appears
4148 -- ??? is business with link symbols still valid, or does it relate
4149 -- to front end ZCX which is being phased out ???
4151 ---------------------------
4152 -- Inlining_Not_Possible --
4153 ---------------------------
4155 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4156 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4160 if Nkind (Decl) = N_Subprogram_Body then
4161 Stats := Handled_Statement_Sequence (Decl);
4162 return Present (Exception_Handlers (Stats))
4163 or else Present (At_End_Proc (Stats));
4165 elsif Nkind (Decl) = N_Subprogram_Declaration
4166 and then Present (Corresponding_Body (Decl))
4168 if Front_End_Inlining
4169 and then Analyzed (Corresponding_Body (Decl))
4171 Error_Msg_N ("pragma appears too late, ignored?", N);
4174 -- If the subprogram is a renaming as body, the body is just a
4175 -- call to the renamed subprogram, and inlining is trivially
4179 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4180 N_Subprogram_Renaming_Declaration
4186 Handled_Statement_Sequence
4187 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4190 Present (Exception_Handlers (Stats))
4191 or else Present (At_End_Proc (Stats));
4195 -- If body is not available, assume the best, the check is
4196 -- performed again when compiling enclosing package bodies.
4200 end Inlining_Not_Possible;
4206 procedure Make_Inline (Subp : Entity_Id) is
4207 Kind : constant Entity_Kind := Ekind (Subp);
4208 Inner_Subp : Entity_Id := Subp;
4211 -- Ignore if bad type, avoid cascaded error
4213 if Etype (Subp) = Any_Type then
4217 -- Ignore if all inlining is suppressed
4219 elsif Suppress_All_Inlining then
4223 -- If inlining is not possible, for now do not treat as an error
4225 elsif Inlining_Not_Possible (Subp) then
4229 -- Here we have a candidate for inlining, but we must exclude
4230 -- derived operations. Otherwise we would end up trying to inline
4231 -- a phantom declaration, and the result would be to drag in a
4232 -- body which has no direct inlining associated with it. That
4233 -- would not only be inefficient but would also result in the
4234 -- backend doing cross-unit inlining in cases where it was
4235 -- definitely inappropriate to do so.
4237 -- However, a simple Comes_From_Source test is insufficient, since
4238 -- we do want to allow inlining of generic instances which also do
4239 -- not come from source. We also need to recognize specs generated
4240 -- by the front-end for bodies that carry the pragma. Finally,
4241 -- predefined operators do not come from source but are not
4242 -- inlineable either.
4244 elsif Is_Generic_Instance (Subp)
4245 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4249 elsif not Comes_From_Source (Subp)
4250 and then Scope (Subp) /= Standard_Standard
4256 -- The referenced entity must either be the enclosing entity, or
4257 -- an entity declared within the current open scope.
4259 if Present (Scope (Subp))
4260 and then Scope (Subp) /= Current_Scope
4261 and then Subp /= Current_Scope
4264 ("argument of% must be entity in current scope", Assoc);
4268 -- Processing for procedure, operator or function. If subprogram
4269 -- is aliased (as for an instance) indicate that the renamed
4270 -- entity (if declared in the same unit) is inlined.
4272 if Is_Subprogram (Subp) then
4278 Inner_Subp := Ultimate_Alias (Inner_Subp);
4280 if In_Same_Source_Unit (Subp, Inner_Subp) then
4281 Set_Inline_Flags (Inner_Subp);
4283 Decl := Parent (Parent (Inner_Subp));
4285 if Nkind (Decl) = N_Subprogram_Declaration
4286 and then Present (Corresponding_Body (Decl))
4288 Set_Inline_Flags (Corresponding_Body (Decl));
4290 elsif Is_Generic_Instance (Subp) then
4292 -- Indicate that the body needs to be created for
4293 -- inlining subsequent calls. The instantiation node
4294 -- follows the declaration of the wrapper package
4297 if Scope (Subp) /= Standard_Standard
4299 Need_Subprogram_Instance_Body
4300 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4310 -- For a generic subprogram set flag as well, for use at the point
4311 -- of instantiation, to determine whether the body should be
4314 elsif Is_Generic_Subprogram (Subp) then
4315 Set_Inline_Flags (Subp);
4318 -- Literals are by definition inlined
4320 elsif Kind = E_Enumeration_Literal then
4323 -- Anything else is an error
4327 ("expect subprogram name for pragma%", Assoc);
4331 ----------------------
4332 -- Set_Inline_Flags --
4333 ----------------------
4335 procedure Set_Inline_Flags (Subp : Entity_Id) is
4338 Set_Is_Inlined (Subp, Sense);
4341 if not Has_Pragma_Inline (Subp) then
4342 Set_Has_Pragma_Inline (Subp, Sense);
4346 if Prag_Id = Pragma_Inline_Always then
4347 Set_Has_Pragma_Inline_Always (Subp, Sense);
4349 end Set_Inline_Flags;
4351 -- Start of processing for Process_Inline
4354 Check_No_Identifiers;
4355 Check_At_Least_N_Arguments (1);
4358 Inline_Processing_Required := True;
4362 while Present (Assoc) loop
4363 Subp_Id := Get_Pragma_Arg (Assoc);
4367 if Is_Entity_Name (Subp_Id) then
4368 Subp := Entity (Subp_Id);
4370 if Subp = Any_Id then
4372 -- If previous error, avoid cascaded errors
4380 if not From_Aspect_Specification (N) then
4381 while Present (Homonym (Subp))
4382 and then Scope (Homonym (Subp)) = Current_Scope
4384 Make_Inline (Homonym (Subp));
4385 Subp := Homonym (Subp);
4393 ("inappropriate argument for pragma%", Assoc);
4396 and then Warn_On_Redundant_Constructs
4397 and then not Suppress_All_Inlining
4399 if Inlining_Not_Possible (Subp) then
4401 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4404 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4412 ----------------------------
4413 -- Process_Interface_Name --
4414 ----------------------------
4416 procedure Process_Interface_Name
4417 (Subprogram_Def : Entity_Id;
4423 String_Val : String_Id;
4425 procedure Check_Form_Of_Interface_Name
4427 Ext_Name_Case : Boolean);
4428 -- SN is a string literal node for an interface name. This routine
4429 -- performs some minimal checks that the name is reasonable. In
4430 -- particular that no spaces or other obviously incorrect characters
4431 -- appear. This is only a warning, since any characters are allowed.
4432 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4434 ----------------------------------
4435 -- Check_Form_Of_Interface_Name --
4436 ----------------------------------
4438 procedure Check_Form_Of_Interface_Name
4440 Ext_Name_Case : Boolean)
4442 S : constant String_Id := Strval (Expr_Value_S (SN));
4443 SL : constant Nat := String_Length (S);
4448 Error_Msg_N ("interface name cannot be null string", SN);
4451 for J in 1 .. SL loop
4452 C := Get_String_Char (S, J);
4454 -- Look for dubious character and issue unconditional warning.
4455 -- Definitely dubious if not in character range.
4457 if not In_Character_Range (C)
4459 -- For all cases except CLI target,
4460 -- commas, spaces and slashes are dubious (in CLI, we use
4461 -- commas and backslashes in external names to specify
4462 -- assembly version and public key, while slashes and spaces
4463 -- can be used in names to mark nested classes and
4466 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4467 and then (Get_Character (C) = ','
4469 Get_Character (C) = '\'))
4470 or else (VM_Target /= CLI_Target
4471 and then (Get_Character (C) = ' '
4473 Get_Character (C) = '/'))
4476 ("?interface name contains illegal character",
4477 Sloc (SN) + Source_Ptr (J));
4480 end Check_Form_Of_Interface_Name;
4482 -- Start of processing for Process_Interface_Name
4485 if No (Link_Arg) then
4486 if No (Ext_Arg) then
4487 if VM_Target = CLI_Target
4488 and then Ekind (Subprogram_Def) = E_Package
4489 and then Nkind (Parent (Subprogram_Def)) =
4490 N_Package_Specification
4491 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4496 (Generic_Parent (Parent (Subprogram_Def))));
4501 elsif Chars (Ext_Arg) = Name_Link_Name then
4503 Link_Nam := Expression (Ext_Arg);
4506 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4507 Ext_Nam := Expression (Ext_Arg);
4512 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4513 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4514 Ext_Nam := Expression (Ext_Arg);
4515 Link_Nam := Expression (Link_Arg);
4518 -- Check expressions for external name and link name are static
4520 if Present (Ext_Nam) then
4521 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4522 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4524 -- Verify that external name is not the name of a local entity,
4525 -- which would hide the imported one and could lead to run-time
4526 -- surprises. The problem can only arise for entities declared in
4527 -- a package body (otherwise the external name is fully qualified
4528 -- and will not conflict).
4536 if Prag_Id = Pragma_Import then
4537 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4539 E := Entity_Id (Get_Name_Table_Info (Nam));
4541 if Nam /= Chars (Subprogram_Def)
4542 and then Present (E)
4543 and then not Is_Overloadable (E)
4544 and then Is_Immediately_Visible (E)
4545 and then not Is_Imported (E)
4546 and then Ekind (Scope (E)) = E_Package
4549 while Present (Par) loop
4550 if Nkind (Par) = N_Package_Body then
4551 Error_Msg_Sloc := Sloc (E);
4553 ("imported entity is hidden by & declared#",
4558 Par := Parent (Par);
4565 if Present (Link_Nam) then
4566 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4567 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4570 -- If there is no link name, just set the external name
4572 if No (Link_Nam) then
4573 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4575 -- For the Link_Name case, the given literal is preceded by an
4576 -- asterisk, which indicates to GCC that the given name should be
4577 -- taken literally, and in particular that no prepending of
4578 -- underlines should occur, even in systems where this is the
4584 if VM_Target = No_VM then
4585 Store_String_Char (Get_Char_Code ('*'));
4588 String_Val := Strval (Expr_Value_S (Link_Nam));
4589 Store_String_Chars (String_Val);
4591 Make_String_Literal (Sloc (Link_Nam),
4592 Strval => End_String);
4595 Set_Encoded_Interface_Name
4596 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4598 -- We allow duplicated export names in CIL, as they are always
4599 -- enclosed in a namespace that differentiates them, and overloaded
4600 -- entities are supported by the VM.
4602 if Convention (Subprogram_Def) /= Convention_CIL then
4603 Check_Duplicated_Export_Name (Link_Nam);
4605 end Process_Interface_Name;
4607 -----------------------------------------
4608 -- Process_Interrupt_Or_Attach_Handler --
4609 -----------------------------------------
4611 procedure Process_Interrupt_Or_Attach_Handler is
4612 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4613 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4614 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4617 Set_Is_Interrupt_Handler (Handler_Proc);
4619 -- If the pragma is not associated with a handler procedure within a
4620 -- protected type, then it must be for a nonprotected procedure for
4621 -- the AAMP target, in which case we don't associate a representation
4622 -- item with the procedure's scope.
4624 if Ekind (Proc_Scope) = E_Protected_Type then
4625 if Prag_Id = Pragma_Interrupt_Handler
4627 Prag_Id = Pragma_Attach_Handler
4629 Record_Rep_Item (Proc_Scope, N);
4632 end Process_Interrupt_Or_Attach_Handler;
4634 --------------------------------------------------
4635 -- Process_Restrictions_Or_Restriction_Warnings --
4636 --------------------------------------------------
4638 -- Note: some of the simple identifier cases were handled in par-prag,
4639 -- but it is harmless (and more straightforward) to simply handle all
4640 -- cases here, even if it means we repeat a bit of work in some cases.
4642 procedure Process_Restrictions_Or_Restriction_Warnings
4646 R_Id : Restriction_Id;
4651 procedure Check_Unit_Name (N : Node_Id);
4652 -- Checks unit name parameter for No_Dependence. Returns if it has
4653 -- an appropriate form, otherwise raises pragma argument error.
4655 ---------------------
4656 -- Check_Unit_Name --
4657 ---------------------
4659 procedure Check_Unit_Name (N : Node_Id) is
4661 if Nkind (N) = N_Selected_Component then
4662 Check_Unit_Name (Prefix (N));
4663 Check_Unit_Name (Selector_Name (N));
4665 elsif Nkind (N) = N_Identifier then
4670 ("wrong form for unit name for No_Dependence", N);
4672 end Check_Unit_Name;
4674 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4677 -- Ignore all Restrictions pragma in CodePeer mode
4679 if CodePeer_Mode then
4683 Check_Ada_83_Warning;
4684 Check_At_Least_N_Arguments (1);
4685 Check_Valid_Configuration_Pragma;
4688 while Present (Arg) loop
4690 Expr := Get_Pragma_Arg (Arg);
4692 -- Case of no restriction identifier present
4694 if Id = No_Name then
4695 if Nkind (Expr) /= N_Identifier then
4697 ("invalid form for restriction", Arg);
4702 (Process_Restriction_Synonyms (Expr));
4704 if R_Id not in All_Boolean_Restrictions then
4705 Error_Msg_Name_1 := Pname;
4707 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4709 -- Check for possible misspelling
4711 for J in Restriction_Id loop
4713 Rnm : constant String := Restriction_Id'Image (J);
4716 Name_Buffer (1 .. Rnm'Length) := Rnm;
4717 Name_Len := Rnm'Length;
4718 Set_Casing (All_Lower_Case);
4720 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4722 (Identifier_Casing (Current_Source_File));
4723 Error_Msg_String (1 .. Rnm'Length) :=
4724 Name_Buffer (1 .. Name_Len);
4725 Error_Msg_Strlen := Rnm'Length;
4726 Error_Msg_N -- CODEFIX
4727 ("\possible misspelling of ""~""",
4728 Get_Pragma_Arg (Arg));
4737 if Implementation_Restriction (R_Id) then
4738 Check_Restriction (No_Implementation_Restrictions, Arg);
4741 -- If this is a warning, then set the warning unless we already
4742 -- have a real restriction active (we never want a warning to
4743 -- override a real restriction).
4746 if not Restriction_Active (R_Id) then
4747 Set_Restriction (R_Id, N);
4748 Restriction_Warnings (R_Id) := True;
4751 -- If real restriction case, then set it and make sure that the
4752 -- restriction warning flag is off, since a real restriction
4753 -- always overrides a warning.
4756 Set_Restriction (R_Id, N);
4757 Restriction_Warnings (R_Id) := False;
4760 -- Check for obsolescent restrictions in Ada 2005 mode
4763 and then Ada_Version >= Ada_2005
4764 and then (R_Id = No_Asynchronous_Control
4766 R_Id = No_Unchecked_Deallocation
4768 R_Id = No_Unchecked_Conversion)
4770 Check_Restriction (No_Obsolescent_Features, N);
4773 -- A very special case that must be processed here: pragma
4774 -- Restrictions (No_Exceptions) turns off all run-time
4775 -- checking. This is a bit dubious in terms of the formal
4776 -- language definition, but it is what is intended by RM
4777 -- H.4(12). Restriction_Warnings never affects generated code
4778 -- so this is done only in the real restriction case.
4780 if R_Id = No_Exceptions and then not Warn then
4781 Scope_Suppress := (others => True);
4784 -- Case of No_Dependence => unit-name. Note that the parser
4785 -- already made the necessary entry in the No_Dependence table.
4787 elsif Id = Name_No_Dependence then
4788 Check_Unit_Name (Expr);
4790 -- All other cases of restriction identifier present
4793 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4794 Analyze_And_Resolve (Expr, Any_Integer);
4796 if R_Id not in All_Parameter_Restrictions then
4798 ("invalid restriction parameter identifier", Arg);
4800 elsif not Is_OK_Static_Expression (Expr) then
4801 Flag_Non_Static_Expr
4802 ("value must be static expression!", Expr);
4805 elsif not Is_Integer_Type (Etype (Expr))
4806 or else Expr_Value (Expr) < 0
4809 ("value must be non-negative integer", Arg);
4812 -- Restriction pragma is active
4814 Val := Expr_Value (Expr);
4816 if not UI_Is_In_Int_Range (Val) then
4818 ("pragma ignored, value too large?", Arg);
4821 -- Warning case. If the real restriction is active, then we
4822 -- ignore the request, since warning never overrides a real
4823 -- restriction. Otherwise we set the proper warning. Note that
4824 -- this circuit sets the warning again if it is already set,
4825 -- which is what we want, since the constant may have changed.
4828 if not Restriction_Active (R_Id) then
4830 (R_Id, N, Integer (UI_To_Int (Val)));
4831 Restriction_Warnings (R_Id) := True;
4834 -- Real restriction case, set restriction and make sure warning
4835 -- flag is off since real restriction always overrides warning.
4838 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4839 Restriction_Warnings (R_Id) := False;
4845 end Process_Restrictions_Or_Restriction_Warnings;
4847 ---------------------------------
4848 -- Process_Suppress_Unsuppress --
4849 ---------------------------------
4851 -- Note: this procedure makes entries in the check suppress data
4852 -- structures managed by Sem. See spec of package Sem for full
4853 -- details on how we handle recording of check suppression.
4855 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4860 In_Package_Spec : constant Boolean :=
4861 Is_Package_Or_Generic_Package (Current_Scope)
4862 and then not In_Package_Body (Current_Scope);
4864 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4865 -- Used to suppress a single check on the given entity
4867 --------------------------------
4868 -- Suppress_Unsuppress_Echeck --
4869 --------------------------------
4871 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4873 Set_Checks_May_Be_Suppressed (E);
4875 if In_Package_Spec then
4876 Push_Global_Suppress_Stack_Entry
4879 Suppress => Suppress_Case);
4882 Push_Local_Suppress_Stack_Entry
4885 Suppress => Suppress_Case);
4888 -- If this is a first subtype, and the base type is distinct,
4889 -- then also set the suppress flags on the base type.
4891 if Is_First_Subtype (E)
4892 and then Etype (E) /= E
4894 Suppress_Unsuppress_Echeck (Etype (E), C);
4896 end Suppress_Unsuppress_Echeck;
4898 -- Start of processing for Process_Suppress_Unsuppress
4901 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
4902 -- we want to generate checks for analysis purposes, as set by -gnatC
4904 if CodePeer_Mode and then Comes_From_Source (N) then
4908 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4909 -- declarative part or a package spec (RM 11.5(5)).
4911 if not Is_Configuration_Pragma then
4912 Check_Is_In_Decl_Part_Or_Package_Spec;
4915 Check_At_Least_N_Arguments (1);
4916 Check_At_Most_N_Arguments (2);
4917 Check_No_Identifier (Arg1);
4918 Check_Arg_Is_Identifier (Arg1);
4920 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
4922 if C = No_Check_Id then
4924 ("argument of pragma% is not valid check name", Arg1);
4927 if not Suppress_Case
4928 and then (C = All_Checks or else C = Overflow_Check)
4930 Opt.Overflow_Checks_Unsuppressed := True;
4933 if Arg_Count = 1 then
4935 -- Make an entry in the local scope suppress table. This is the
4936 -- table that directly shows the current value of the scope
4937 -- suppress check for any check id value.
4939 if C = All_Checks then
4941 -- For All_Checks, we set all specific predefined checks with
4942 -- the exception of Elaboration_Check, which is handled
4943 -- specially because of not wanting All_Checks to have the
4944 -- effect of deactivating static elaboration order processing.
4946 for J in Scope_Suppress'Range loop
4947 if J /= Elaboration_Check then
4948 Scope_Suppress (J) := Suppress_Case;
4952 -- If not All_Checks, and predefined check, then set appropriate
4953 -- scope entry. Note that we will set Elaboration_Check if this
4954 -- is explicitly specified.
4956 elsif C in Predefined_Check_Id then
4957 Scope_Suppress (C) := Suppress_Case;
4960 -- Also make an entry in the Local_Entity_Suppress table
4962 Push_Local_Suppress_Stack_Entry
4965 Suppress => Suppress_Case);
4967 -- Case of two arguments present, where the check is suppressed for
4968 -- a specified entity (given as the second argument of the pragma)
4971 -- This is obsolescent in Ada 2005 mode
4973 if Ada_Version >= Ada_2005 then
4974 Check_Restriction (No_Obsolescent_Features, Arg2);
4977 Check_Optional_Identifier (Arg2, Name_On);
4978 E_Id := Get_Pragma_Arg (Arg2);
4981 if not Is_Entity_Name (E_Id) then
4983 ("second argument of pragma% must be entity name", Arg2);
4992 -- Enforce RM 11.5(7) which requires that for a pragma that
4993 -- appears within a package spec, the named entity must be
4994 -- within the package spec. We allow the package name itself
4995 -- to be mentioned since that makes sense, although it is not
4996 -- strictly allowed by 11.5(7).
4999 and then E /= Current_Scope
5000 and then Scope (E) /= Current_Scope
5003 ("entity in pragma% is not in package spec (RM 11.5(7))",
5007 -- Loop through homonyms. As noted below, in the case of a package
5008 -- spec, only homonyms within the package spec are considered.
5011 Suppress_Unsuppress_Echeck (E, C);
5013 if Is_Generic_Instance (E)
5014 and then Is_Subprogram (E)
5015 and then Present (Alias (E))
5017 Suppress_Unsuppress_Echeck (Alias (E), C);
5020 -- Move to next homonym if not aspect spec case
5022 exit when From_Aspect_Specification (N);
5026 -- If we are within a package specification, the pragma only
5027 -- applies to homonyms in the same scope.
5029 exit when In_Package_Spec
5030 and then Scope (E) /= Current_Scope;
5033 end Process_Suppress_Unsuppress;
5039 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5041 if Is_Imported (E) then
5043 ("cannot export entity& that was previously imported", Arg);
5045 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5047 ("cannot export entity& that has an address clause", Arg);
5050 Set_Is_Exported (E);
5052 -- Generate a reference for entity explicitly, because the
5053 -- identifier may be overloaded and name resolution will not
5056 Generate_Reference (E, Arg);
5058 -- Deal with exporting non-library level entity
5060 if not Is_Library_Level_Entity (E) then
5062 -- Not allowed at all for subprograms
5064 if Is_Subprogram (E) then
5065 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5067 -- Otherwise set public and statically allocated
5071 Set_Is_Statically_Allocated (E);
5073 -- Warn if the corresponding W flag is set and the pragma comes
5074 -- from source. The latter may not be true e.g. on VMS where we
5075 -- expand export pragmas for exception codes associated with
5076 -- imported or exported exceptions. We do not want to generate
5077 -- a warning for something that the user did not write.
5079 if Warn_On_Export_Import
5080 and then Comes_From_Source (Arg)
5083 ("?& has been made static as a result of Export", Arg, E);
5085 ("\this usage is non-standard and non-portable", Arg);
5090 if Warn_On_Export_Import and then Is_Type (E) then
5091 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5094 if Warn_On_Export_Import and Inside_A_Generic then
5096 ("all instances of& will have the same external name?", Arg, E);
5100 ----------------------------------------------
5101 -- Set_Extended_Import_Export_External_Name --
5102 ----------------------------------------------
5104 procedure Set_Extended_Import_Export_External_Name
5105 (Internal_Ent : Entity_Id;
5106 Arg_External : Node_Id)
5108 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5112 if No (Arg_External) then
5116 Check_Arg_Is_External_Name (Arg_External);
5118 if Nkind (Arg_External) = N_String_Literal then
5119 if String_Length (Strval (Arg_External)) = 0 then
5122 New_Name := Adjust_External_Name_Case (Arg_External);
5125 elsif Nkind (Arg_External) = N_Identifier then
5126 New_Name := Get_Default_External_Name (Arg_External);
5128 -- Check_Arg_Is_External_Name should let through only identifiers and
5129 -- string literals or static string expressions (which are folded to
5130 -- string literals).
5133 raise Program_Error;
5136 -- If we already have an external name set (by a prior normal Import
5137 -- or Export pragma), then the external names must match
5139 if Present (Interface_Name (Internal_Ent)) then
5140 Check_Matching_Internal_Names : declare
5141 S1 : constant String_Id := Strval (Old_Name);
5142 S2 : constant String_Id := Strval (New_Name);
5145 -- Called if names do not match
5151 procedure Mismatch is
5153 Error_Msg_Sloc := Sloc (Old_Name);
5155 ("external name does not match that given #",
5159 -- Start of processing for Check_Matching_Internal_Names
5162 if String_Length (S1) /= String_Length (S2) then
5166 for J in 1 .. String_Length (S1) loop
5167 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5172 end Check_Matching_Internal_Names;
5174 -- Otherwise set the given name
5177 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5178 Check_Duplicated_Export_Name (New_Name);
5180 end Set_Extended_Import_Export_External_Name;
5186 procedure Set_Imported (E : Entity_Id) is
5188 -- Error message if already imported or exported
5190 if Is_Exported (E) or else Is_Imported (E) then
5192 -- Error if being set Exported twice
5194 if Is_Exported (E) then
5195 Error_Msg_NE ("entity& was previously exported", N, E);
5197 -- OK if Import/Interface case
5199 elsif Import_Interface_Present (N) then
5202 -- Error if being set Imported twice
5205 Error_Msg_NE ("entity& was previously imported", N, E);
5208 Error_Msg_Name_1 := Pname;
5210 ("\(pragma% applies to all previous entities)", N);
5212 Error_Msg_Sloc := Sloc (E);
5213 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5215 -- Here if not previously imported or exported, OK to import
5218 Set_Is_Imported (E);
5220 -- If the entity is an object that is not at the library level,
5221 -- then it is statically allocated. We do not worry about objects
5222 -- with address clauses in this context since they are not really
5223 -- imported in the linker sense.
5226 and then not Is_Library_Level_Entity (E)
5227 and then No (Address_Clause (E))
5229 Set_Is_Statically_Allocated (E);
5236 -------------------------
5237 -- Set_Mechanism_Value --
5238 -------------------------
5240 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5241 -- analyzed, since it is semantic nonsense), so we get it in the exact
5242 -- form created by the parser.
5244 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5247 Mech_Name_Id : Name_Id;
5249 procedure Bad_Class;
5250 -- Signal bad descriptor class name
5252 procedure Bad_Mechanism;
5253 -- Signal bad mechanism name
5259 procedure Bad_Class is
5261 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5264 -------------------------
5265 -- Bad_Mechanism_Value --
5266 -------------------------
5268 procedure Bad_Mechanism is
5270 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5273 -- Start of processing for Set_Mechanism_Value
5276 if Mechanism (Ent) /= Default_Mechanism then
5278 ("mechanism for & has already been set", Mech_Name, Ent);
5281 -- MECHANISM_NAME ::= value | reference | descriptor |
5284 if Nkind (Mech_Name) = N_Identifier then
5285 if Chars (Mech_Name) = Name_Value then
5286 Set_Mechanism (Ent, By_Copy);
5289 elsif Chars (Mech_Name) = Name_Reference then
5290 Set_Mechanism (Ent, By_Reference);
5293 elsif Chars (Mech_Name) = Name_Descriptor then
5294 Check_VMS (Mech_Name);
5296 -- Descriptor => Short_Descriptor if pragma was given
5298 if Short_Descriptors then
5299 Set_Mechanism (Ent, By_Short_Descriptor);
5301 Set_Mechanism (Ent, By_Descriptor);
5306 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5307 Check_VMS (Mech_Name);
5308 Set_Mechanism (Ent, By_Short_Descriptor);
5311 elsif Chars (Mech_Name) = Name_Copy then
5313 ("bad mechanism name, Value assumed", Mech_Name);
5319 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5320 -- short_descriptor (CLASS_NAME)
5321 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5323 -- Note: this form is parsed as an indexed component
5325 elsif Nkind (Mech_Name) = N_Indexed_Component then
5326 Class := First (Expressions (Mech_Name));
5328 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5329 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5330 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5331 or else Present (Next (Class))
5335 Mech_Name_Id := Chars (Prefix (Mech_Name));
5337 -- Change Descriptor => Short_Descriptor if pragma was given
5339 if Mech_Name_Id = Name_Descriptor
5340 and then Short_Descriptors
5342 Mech_Name_Id := Name_Short_Descriptor;
5346 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5347 -- short_descriptor (Class => CLASS_NAME)
5348 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5350 -- Note: this form is parsed as a function call
5352 elsif Nkind (Mech_Name) = N_Function_Call then
5353 Param := First (Parameter_Associations (Mech_Name));
5355 if Nkind (Name (Mech_Name)) /= N_Identifier
5356 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5357 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5358 or else Present (Next (Param))
5359 or else No (Selector_Name (Param))
5360 or else Chars (Selector_Name (Param)) /= Name_Class
5364 Class := Explicit_Actual_Parameter (Param);
5365 Mech_Name_Id := Chars (Name (Mech_Name));
5372 -- Fall through here with Class set to descriptor class name
5374 Check_VMS (Mech_Name);
5376 if Nkind (Class) /= N_Identifier then
5379 elsif Mech_Name_Id = Name_Descriptor
5380 and then Chars (Class) = Name_UBS
5382 Set_Mechanism (Ent, By_Descriptor_UBS);
5384 elsif Mech_Name_Id = Name_Descriptor
5385 and then Chars (Class) = Name_UBSB
5387 Set_Mechanism (Ent, By_Descriptor_UBSB);
5389 elsif Mech_Name_Id = Name_Descriptor
5390 and then Chars (Class) = Name_UBA
5392 Set_Mechanism (Ent, By_Descriptor_UBA);
5394 elsif Mech_Name_Id = Name_Descriptor
5395 and then Chars (Class) = Name_S
5397 Set_Mechanism (Ent, By_Descriptor_S);
5399 elsif Mech_Name_Id = Name_Descriptor
5400 and then Chars (Class) = Name_SB
5402 Set_Mechanism (Ent, By_Descriptor_SB);
5404 elsif Mech_Name_Id = Name_Descriptor
5405 and then Chars (Class) = Name_A
5407 Set_Mechanism (Ent, By_Descriptor_A);
5409 elsif Mech_Name_Id = Name_Descriptor
5410 and then Chars (Class) = Name_NCA
5412 Set_Mechanism (Ent, By_Descriptor_NCA);
5414 elsif Mech_Name_Id = Name_Short_Descriptor
5415 and then Chars (Class) = Name_UBS
5417 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5419 elsif Mech_Name_Id = Name_Short_Descriptor
5420 and then Chars (Class) = Name_UBSB
5422 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5424 elsif Mech_Name_Id = Name_Short_Descriptor
5425 and then Chars (Class) = Name_UBA
5427 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5429 elsif Mech_Name_Id = Name_Short_Descriptor
5430 and then Chars (Class) = Name_S
5432 Set_Mechanism (Ent, By_Short_Descriptor_S);
5434 elsif Mech_Name_Id = Name_Short_Descriptor
5435 and then Chars (Class) = Name_SB
5437 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5439 elsif Mech_Name_Id = Name_Short_Descriptor
5440 and then Chars (Class) = Name_A
5442 Set_Mechanism (Ent, By_Short_Descriptor_A);
5444 elsif Mech_Name_Id = Name_Short_Descriptor
5445 and then Chars (Class) = Name_NCA
5447 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5452 end Set_Mechanism_Value;
5454 ---------------------------
5455 -- Set_Ravenscar_Profile --
5456 ---------------------------
5458 -- The tasks to be done here are
5460 -- Set required policies
5462 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5463 -- pragma Locking_Policy (Ceiling_Locking)
5465 -- Set Detect_Blocking mode
5467 -- Set required restrictions (see System.Rident for detailed list)
5469 -- Set the No_Dependence rules
5470 -- No_Dependence => Ada.Asynchronous_Task_Control
5471 -- No_Dependence => Ada.Calendar
5472 -- No_Dependence => Ada.Execution_Time.Group_Budget
5473 -- No_Dependence => Ada.Execution_Time.Timers
5474 -- No_Dependence => Ada.Task_Attributes
5475 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5477 procedure Set_Ravenscar_Profile (N : Node_Id) is
5478 Prefix_Entity : Entity_Id;
5479 Selector_Entity : Entity_Id;
5480 Prefix_Node : Node_Id;
5484 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5486 if Task_Dispatching_Policy /= ' '
5487 and then Task_Dispatching_Policy /= 'F'
5489 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5490 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5492 -- Set the FIFO_Within_Priorities policy, but always preserve
5493 -- System_Location since we like the error message with the run time
5497 Task_Dispatching_Policy := 'F';
5499 if Task_Dispatching_Policy_Sloc /= System_Location then
5500 Task_Dispatching_Policy_Sloc := Loc;
5504 -- pragma Locking_Policy (Ceiling_Locking)
5506 if Locking_Policy /= ' '
5507 and then Locking_Policy /= 'C'
5509 Error_Msg_Sloc := Locking_Policy_Sloc;
5510 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5512 -- Set the Ceiling_Locking policy, but preserve System_Location since
5513 -- we like the error message with the run time name.
5516 Locking_Policy := 'C';
5518 if Locking_Policy_Sloc /= System_Location then
5519 Locking_Policy_Sloc := Loc;
5523 -- pragma Detect_Blocking
5525 Detect_Blocking := True;
5527 -- Set the corresponding restrictions
5529 Set_Profile_Restrictions
5530 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5532 -- Set the No_Dependence restrictions
5534 -- The following No_Dependence restrictions:
5535 -- No_Dependence => Ada.Asynchronous_Task_Control
5536 -- No_Dependence => Ada.Calendar
5537 -- No_Dependence => Ada.Task_Attributes
5538 -- are already set by previous call to Set_Profile_Restrictions.
5540 -- Set the following restrictions which were added to Ada 2005:
5541 -- No_Dependence => Ada.Execution_Time.Group_Budget
5542 -- No_Dependence => Ada.Execution_Time.Timers
5544 if Ada_Version >= Ada_2005 then
5545 Name_Buffer (1 .. 3) := "ada";
5548 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5550 Name_Buffer (1 .. 14) := "execution_time";
5553 Selector_Entity := Make_Identifier (Loc, Name_Find);
5556 Make_Selected_Component
5558 Prefix => Prefix_Entity,
5559 Selector_Name => Selector_Entity);
5561 Name_Buffer (1 .. 13) := "group_budgets";
5564 Selector_Entity := Make_Identifier (Loc, Name_Find);
5567 Make_Selected_Component
5569 Prefix => Prefix_Node,
5570 Selector_Name => Selector_Entity);
5572 Set_Restriction_No_Dependence
5574 Warn => Treat_Restrictions_As_Warnings,
5575 Profile => Ravenscar);
5577 Name_Buffer (1 .. 6) := "timers";
5580 Selector_Entity := Make_Identifier (Loc, Name_Find);
5583 Make_Selected_Component
5585 Prefix => Prefix_Node,
5586 Selector_Name => Selector_Entity);
5588 Set_Restriction_No_Dependence
5590 Warn => Treat_Restrictions_As_Warnings,
5591 Profile => Ravenscar);
5594 -- Set the following restrictions which was added to Ada 2012 (see
5596 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5598 if Ada_Version >= Ada_2012 then
5599 Name_Buffer (1 .. 6) := "system";
5602 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5604 Name_Buffer (1 .. 15) := "multiprocessors";
5607 Selector_Entity := Make_Identifier (Loc, Name_Find);
5610 Make_Selected_Component
5612 Prefix => Prefix_Entity,
5613 Selector_Name => Selector_Entity);
5615 Name_Buffer (1 .. 19) := "dispatching_domains";
5618 Selector_Entity := Make_Identifier (Loc, Name_Find);
5621 Make_Selected_Component
5623 Prefix => Prefix_Node,
5624 Selector_Name => Selector_Entity);
5626 Set_Restriction_No_Dependence
5628 Warn => Treat_Restrictions_As_Warnings,
5629 Profile => Ravenscar);
5631 end Set_Ravenscar_Profile;
5633 -- Start of processing for Analyze_Pragma
5636 -- Deal with unrecognized pragma
5638 if not Is_Pragma_Name (Pname) then
5639 if Warn_On_Unrecognized_Pragma then
5640 Error_Msg_Name_1 := Pname;
5641 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5643 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5644 if Is_Bad_Spelling_Of (Pname, PN) then
5645 Error_Msg_Name_1 := PN;
5646 Error_Msg_N -- CODEFIX
5647 ("\?possible misspelling of %!", Pragma_Identifier (N));
5656 -- Here to start processing for recognized pragma
5658 Prag_Id := Get_Pragma_Id (Pname);
5667 if Present (Pragma_Argument_Associations (N)) then
5668 Arg1 := First (Pragma_Argument_Associations (N));
5670 if Present (Arg1) then
5671 Arg2 := Next (Arg1);
5673 if Present (Arg2) then
5674 Arg3 := Next (Arg2);
5676 if Present (Arg3) then
5677 Arg4 := Next (Arg3);
5683 -- Count number of arguments
5690 while Present (Arg_Node) loop
5691 Arg_Count := Arg_Count + 1;
5696 -- An enumeration type defines the pragmas that are supported by the
5697 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5698 -- into the corresponding enumeration value for the following case.
5706 -- pragma Abort_Defer;
5708 when Pragma_Abort_Defer =>
5710 Check_Arg_Count (0);
5712 -- The only required semantic processing is to check the
5713 -- placement. This pragma must appear at the start of the
5714 -- statement sequence of a handled sequence of statements.
5716 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5717 or else N /= First (Statements (Parent (N)))
5728 -- Note: this pragma also has some specific processing in Par.Prag
5729 -- because we want to set the Ada version mode during parsing.
5731 when Pragma_Ada_83 =>
5733 Check_Arg_Count (0);
5735 -- We really should check unconditionally for proper configuration
5736 -- pragma placement, since we really don't want mixed Ada modes
5737 -- within a single unit, and the GNAT reference manual has always
5738 -- said this was a configuration pragma, but we did not check and
5739 -- are hesitant to add the check now.
5741 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5742 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5743 -- or Ada 2012 mode.
5745 if Ada_Version >= Ada_2005 then
5746 Check_Valid_Configuration_Pragma;
5749 -- Now set Ada 83 mode
5751 Ada_Version := Ada_83;
5752 Ada_Version_Explicit := Ada_Version;
5760 -- Note: this pragma also has some specific processing in Par.Prag
5761 -- because we want to set the Ada 83 version mode during parsing.
5763 when Pragma_Ada_95 =>
5765 Check_Arg_Count (0);
5767 -- We really should check unconditionally for proper configuration
5768 -- pragma placement, since we really don't want mixed Ada modes
5769 -- within a single unit, and the GNAT reference manual has always
5770 -- said this was a configuration pragma, but we did not check and
5771 -- are hesitant to add the check now.
5773 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5774 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5776 if Ada_Version >= Ada_2005 then
5777 Check_Valid_Configuration_Pragma;
5780 -- Now set Ada 95 mode
5782 Ada_Version := Ada_95;
5783 Ada_Version_Explicit := Ada_Version;
5785 ---------------------
5786 -- Ada_05/Ada_2005 --
5787 ---------------------
5790 -- pragma Ada_05 (LOCAL_NAME);
5793 -- pragma Ada_2005 (LOCAL_NAME):
5795 -- Note: these pragmas also have some specific processing in Par.Prag
5796 -- because we want to set the Ada 2005 version mode during parsing.
5798 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5804 if Arg_Count = 1 then
5805 Check_Arg_Is_Local_Name (Arg1);
5806 E_Id := Get_Pragma_Arg (Arg1);
5808 if Etype (E_Id) = Any_Type then
5812 Set_Is_Ada_2005_Only (Entity (E_Id));
5815 Check_Arg_Count (0);
5817 -- For Ada_2005 we unconditionally enforce the documented
5818 -- configuration pragma placement, since we do not want to
5819 -- tolerate mixed modes in a unit involving Ada 2005. That
5820 -- would cause real difficulties for those cases where there
5821 -- are incompatibilities between Ada 95 and Ada 2005.
5823 Check_Valid_Configuration_Pragma;
5825 -- Now set appropriate Ada mode
5828 Ada_Version := Ada_2005;
5830 Ada_Version := Ada_Version_Default;
5833 Ada_Version_Explicit := Ada_2005;
5837 ---------------------
5838 -- Ada_12/Ada_2012 --
5839 ---------------------
5842 -- pragma Ada_12 (LOCAL_NAME);
5845 -- pragma Ada_2012 (LOCAL_NAME):
5847 -- Note: these pragmas also have some specific processing in Par.Prag
5848 -- because we want to set the Ada 2012 version mode during parsing.
5850 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5856 if Arg_Count = 1 then
5857 Check_Arg_Is_Local_Name (Arg1);
5858 E_Id := Get_Pragma_Arg (Arg1);
5860 if Etype (E_Id) = Any_Type then
5864 Set_Is_Ada_2012_Only (Entity (E_Id));
5867 Check_Arg_Count (0);
5869 -- For Ada_2012 we unconditionally enforce the documented
5870 -- configuration pragma placement, since we do not want to
5871 -- tolerate mixed modes in a unit involving Ada 2012. That
5872 -- would cause real difficulties for those cases where there
5873 -- are incompatibilities between Ada 95 and Ada 2012. We could
5874 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5876 Check_Valid_Configuration_Pragma;
5878 -- Now set appropriate Ada mode
5881 Ada_Version := Ada_2012;
5883 Ada_Version := Ada_Version_Default;
5886 Ada_Version_Explicit := Ada_2012;
5890 ----------------------
5891 -- All_Calls_Remote --
5892 ----------------------
5894 -- pragma All_Calls_Remote [(library_package_NAME)];
5896 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5897 Lib_Entity : Entity_Id;
5900 Check_Ada_83_Warning;
5901 Check_Valid_Library_Unit_Pragma;
5903 if Nkind (N) = N_Null_Statement then
5907 Lib_Entity := Find_Lib_Unit_Name;
5909 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5911 if Present (Lib_Entity)
5912 and then not Debug_Flag_U
5914 if not Is_Remote_Call_Interface (Lib_Entity) then
5915 Error_Pragma ("pragma% only apply to rci unit");
5917 -- Set flag for entity of the library unit
5920 Set_Has_All_Calls_Remote (Lib_Entity);
5924 end All_Calls_Remote;
5930 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
5931 -- ARG ::= NAME | EXPRESSION
5933 -- The first two arguments are by convention intended to refer to an
5934 -- external tool and a tool-specific function. These arguments are
5937 when Pragma_Annotate => Annotate : begin
5939 Check_At_Least_N_Arguments (1);
5940 Check_Arg_Is_Identifier (Arg1);
5941 Check_No_Identifiers;
5949 -- Second unanalyzed parameter is optional
5955 while Present (Arg) loop
5956 Exp := Get_Pragma_Arg (Arg);
5959 if Is_Entity_Name (Exp) then
5962 -- For string literals, we assume Standard_String as the
5963 -- type, unless the string contains wide or wide_wide
5966 elsif Nkind (Exp) = N_String_Literal then
5967 if Has_Wide_Wide_Character (Exp) then
5968 Resolve (Exp, Standard_Wide_Wide_String);
5969 elsif Has_Wide_Character (Exp) then
5970 Resolve (Exp, Standard_Wide_String);
5972 Resolve (Exp, Standard_String);
5975 elsif Is_Overloaded (Exp) then
5977 ("ambiguous argument for pragma%", Exp);
5993 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5994 -- [, [Message =>] Static_String_EXPRESSION]);
5996 when Pragma_Assert => Assert : declare
6002 Check_At_Least_N_Arguments (1);
6003 Check_At_Most_N_Arguments (2);
6004 Check_Arg_Order ((Name_Check, Name_Message));
6005 Check_Optional_Identifier (Arg1, Name_Check);
6007 -- We treat pragma Assert as equivalent to:
6009 -- pragma Check (Assertion, condition [, msg]);
6011 -- So rewrite pragma in this manner, and analyze the result
6013 Expr := Get_Pragma_Arg (Arg1);
6015 Make_Pragma_Argument_Association (Loc,
6017 Make_Identifier (Loc,
6018 Chars => Name_Assertion)),
6020 Make_Pragma_Argument_Association (Sloc (Expr),
6021 Expression => Expr));
6023 if Arg_Count > 1 then
6024 Check_Optional_Identifier (Arg2, Name_Message);
6025 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6026 Append_To (Newa, Relocate_Node (Arg2));
6031 Chars => Name_Check,
6032 Pragma_Argument_Associations => Newa));
6036 ----------------------
6037 -- Assertion_Policy --
6038 ----------------------
6040 -- pragma Assertion_Policy (Check | Ignore)
6042 when Pragma_Assertion_Policy => Assertion_Policy : declare
6047 Check_Valid_Configuration_Pragma;
6048 Check_Arg_Count (1);
6049 Check_No_Identifiers;
6050 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6052 -- We treat pragma Assertion_Policy as equivalent to:
6054 -- pragma Check_Policy (Assertion, policy)
6056 -- So rewrite the pragma in that manner and link on to the chain
6057 -- of Check_Policy pragmas, marking the pragma as analyzed.
6059 Policy := Get_Pragma_Arg (Arg1);
6063 Chars => Name_Check_Policy,
6065 Pragma_Argument_Associations => New_List (
6066 Make_Pragma_Argument_Association (Loc,
6068 Make_Identifier (Loc,
6069 Chars => Name_Assertion)),
6071 Make_Pragma_Argument_Association (Loc,
6073 Make_Identifier (Sloc (Policy),
6074 Chars => Chars (Policy))))));
6077 Set_Next_Pragma (N, Opt.Check_Policy_List);
6078 Opt.Check_Policy_List := N;
6079 end Assertion_Policy;
6081 ------------------------------
6082 -- Assume_No_Invalid_Values --
6083 ------------------------------
6085 -- pragma Assume_No_Invalid_Values (On | Off);
6087 when Pragma_Assume_No_Invalid_Values =>
6089 Check_Valid_Configuration_Pragma;
6090 Check_Arg_Count (1);
6091 Check_No_Identifiers;
6092 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6094 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6095 Assume_No_Invalid_Values := True;
6097 Assume_No_Invalid_Values := False;
6104 -- pragma AST_Entry (entry_IDENTIFIER);
6106 when Pragma_AST_Entry => AST_Entry : declare
6112 Check_Arg_Count (1);
6113 Check_No_Identifiers;
6114 Check_Arg_Is_Local_Name (Arg1);
6115 Ent := Entity (Get_Pragma_Arg (Arg1));
6117 -- Note: the implementation of the AST_Entry pragma could handle
6118 -- the entry family case fine, but for now we are consistent with
6119 -- the DEC rules, and do not allow the pragma, which of course
6120 -- has the effect of also forbidding the attribute.
6122 if Ekind (Ent) /= E_Entry then
6124 ("pragma% argument must be simple entry name", Arg1);
6126 elsif Is_AST_Entry (Ent) then
6128 ("duplicate % pragma for entry", Arg1);
6130 elsif Has_Homonym (Ent) then
6132 ("pragma% argument cannot specify overloaded entry", Arg1);
6136 FF : constant Entity_Id := First_Formal (Ent);
6139 if Present (FF) then
6140 if Present (Next_Formal (FF)) then
6142 ("entry for pragma% can have only one argument",
6145 elsif Parameter_Mode (FF) /= E_In_Parameter then
6147 ("entry parameter for pragma% must have mode IN",
6153 Set_Is_AST_Entry (Ent);
6161 -- pragma Asynchronous (LOCAL_NAME);
6163 when Pragma_Asynchronous => Asynchronous : declare
6171 procedure Process_Async_Pragma;
6172 -- Common processing for procedure and access-to-procedure case
6174 --------------------------
6175 -- Process_Async_Pragma --
6176 --------------------------
6178 procedure Process_Async_Pragma is
6181 Set_Is_Asynchronous (Nm);
6185 -- The formals should be of mode IN (RM E.4.1(6))
6188 while Present (S) loop
6189 Formal := Defining_Identifier (S);
6191 if Nkind (Formal) = N_Defining_Identifier
6192 and then Ekind (Formal) /= E_In_Parameter
6195 ("pragma% procedure can only have IN parameter",
6202 Set_Is_Asynchronous (Nm);
6203 end Process_Async_Pragma;
6205 -- Start of processing for pragma Asynchronous
6208 Check_Ada_83_Warning;
6209 Check_No_Identifiers;
6210 Check_Arg_Count (1);
6211 Check_Arg_Is_Local_Name (Arg1);
6213 if Debug_Flag_U then
6217 C_Ent := Cunit_Entity (Current_Sem_Unit);
6218 Analyze (Get_Pragma_Arg (Arg1));
6219 Nm := Entity (Get_Pragma_Arg (Arg1));
6221 if not Is_Remote_Call_Interface (C_Ent)
6222 and then not Is_Remote_Types (C_Ent)
6224 -- This pragma should only appear in an RCI or Remote Types
6225 -- unit (RM E.4.1(4)).
6228 ("pragma% not in Remote_Call_Interface or " &
6229 "Remote_Types unit");
6232 if Ekind (Nm) = E_Procedure
6233 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6235 if not Is_Remote_Call_Interface (Nm) then
6237 ("pragma% cannot be applied on non-remote procedure",
6241 L := Parameter_Specifications (Parent (Nm));
6242 Process_Async_Pragma;
6245 elsif Ekind (Nm) = E_Function then
6247 ("pragma% cannot be applied to function", Arg1);
6249 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6251 if Is_Record_Type (Nm) then
6253 -- A record type that is the Equivalent_Type for a remote
6254 -- access-to-subprogram type.
6256 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6259 -- A non-expanded RAS type (distribution is not enabled)
6261 N := Declaration_Node (Nm);
6264 if Nkind (N) = N_Full_Type_Declaration
6265 and then Nkind (Type_Definition (N)) =
6266 N_Access_Procedure_Definition
6268 L := Parameter_Specifications (Type_Definition (N));
6269 Process_Async_Pragma;
6271 if Is_Asynchronous (Nm)
6272 and then Expander_Active
6273 and then Get_PCS_Name /= Name_No_DSA
6275 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6280 ("pragma% cannot reference access-to-function type",
6284 -- Only other possibility is Access-to-class-wide type
6286 elsif Is_Access_Type (Nm)
6287 and then Is_Class_Wide_Type (Designated_Type (Nm))
6289 Check_First_Subtype (Arg1);
6290 Set_Is_Asynchronous (Nm);
6291 if Expander_Active then
6292 RACW_Type_Is_Asynchronous (Nm);
6296 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6304 -- pragma Atomic (LOCAL_NAME);
6306 when Pragma_Atomic =>
6307 Process_Atomic_Shared_Volatile;
6309 -----------------------
6310 -- Atomic_Components --
6311 -----------------------
6313 -- pragma Atomic_Components (array_LOCAL_NAME);
6315 -- This processing is shared by Volatile_Components
6317 when Pragma_Atomic_Components |
6318 Pragma_Volatile_Components =>
6320 Atomic_Components : declare
6327 Check_Ada_83_Warning;
6328 Check_No_Identifiers;
6329 Check_Arg_Count (1);
6330 Check_Arg_Is_Local_Name (Arg1);
6331 E_Id := Get_Pragma_Arg (Arg1);
6333 if Etype (E_Id) = Any_Type then
6339 Check_Duplicate_Pragma (E);
6341 if Rep_Item_Too_Early (E, N)
6343 Rep_Item_Too_Late (E, N)
6348 D := Declaration_Node (E);
6351 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6353 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6354 and then Nkind (D) = N_Object_Declaration
6355 and then Nkind (Object_Definition (D)) =
6356 N_Constrained_Array_Definition)
6358 -- The flag is set on the object, or on the base type
6360 if Nkind (D) /= N_Object_Declaration then
6364 Set_Has_Volatile_Components (E, Sense);
6366 if Prag_Id = Pragma_Atomic_Components then
6367 Set_Has_Atomic_Components (E, Sense);
6371 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6373 end Atomic_Components;
6375 --------------------
6376 -- Attach_Handler --
6377 --------------------
6379 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6381 when Pragma_Attach_Handler =>
6382 Check_Ada_83_Warning;
6383 Check_No_Identifiers;
6384 Check_Arg_Count (2);
6386 if No_Run_Time_Mode then
6387 Error_Msg_CRT ("Attach_Handler pragma", N);
6389 Check_Interrupt_Or_Attach_Handler;
6391 -- The expression that designates the attribute may depend on a
6392 -- discriminant, and is therefore a per- object expression, to
6393 -- be expanded in the init proc. If expansion is enabled, then
6394 -- perform semantic checks on a copy only.
6396 if Expander_Active then
6398 Temp : constant Node_Id :=
6399 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6401 Set_Parent (Temp, N);
6402 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6406 Analyze (Get_Pragma_Arg (Arg2));
6407 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6410 Process_Interrupt_Or_Attach_Handler;
6413 --------------------
6414 -- C_Pass_By_Copy --
6415 --------------------
6417 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6419 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6425 Check_Valid_Configuration_Pragma;
6426 Check_Arg_Count (1);
6427 Check_Optional_Identifier (Arg1, "max_size");
6429 Arg := Get_Pragma_Arg (Arg1);
6430 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6432 Val := Expr_Value (Arg);
6436 ("maximum size for pragma% must be positive", Arg1);
6438 elsif UI_Is_In_Int_Range (Val) then
6439 Default_C_Record_Mechanism := UI_To_Int (Val);
6441 -- If a giant value is given, Int'Last will do well enough.
6442 -- If sometime someone complains that a record larger than
6443 -- two gigabytes is not copied, we will worry about it then!
6446 Default_C_Record_Mechanism := Mechanism_Type'Last;
6454 -- pragma Check ([Name =>] Identifier,
6455 -- [Check =>] Boolean_Expression
6456 -- [,[Message =>] String_Expression]);
6458 when Pragma_Check => Check : declare
6463 -- Set True if category of assertions referenced by Name enabled
6467 Check_At_Least_N_Arguments (2);
6468 Check_At_Most_N_Arguments (3);
6469 Check_Optional_Identifier (Arg1, Name_Name);
6470 Check_Optional_Identifier (Arg2, Name_Check);
6472 if Arg_Count = 3 then
6473 Check_Optional_Identifier (Arg3, Name_Message);
6474 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6477 Check_Arg_Is_Identifier (Arg1);
6479 -- Indicate if pragma is enabled. The Original_Node reference here
6480 -- is to deal with pragma Assert rewritten as a Check pragma.
6482 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6485 Set_Pragma_Enabled (N);
6486 Set_Pragma_Enabled (Original_Node (N));
6487 Set_SCO_Pragma_Enabled (Loc);
6490 -- If expansion is active and the check is not enabled then we
6491 -- rewrite the Check as:
6493 -- if False and then condition then
6497 -- The reason we do this rewriting during semantic analysis rather
6498 -- than as part of normal expansion is that we cannot analyze and
6499 -- expand the code for the boolean expression directly, or it may
6500 -- cause insertion of actions that would escape the attempt to
6501 -- suppress the check code.
6503 -- Note that the Sloc for the if statement corresponds to the
6504 -- argument condition, not the pragma itself. The reason for this
6505 -- is that we may generate a warning if the condition is False at
6506 -- compile time, and we do not want to delete this warning when we
6507 -- delete the if statement.
6509 Expr := Get_Pragma_Arg (Arg2);
6511 if Expander_Active and then not Check_On then
6512 Eloc := Sloc (Expr);
6515 Make_If_Statement (Eloc,
6517 Make_And_Then (Eloc,
6518 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6519 Right_Opnd => Expr),
6520 Then_Statements => New_List (
6521 Make_Null_Statement (Eloc))));
6528 Analyze_And_Resolve (Expr, Any_Boolean);
6536 -- pragma Check_Name (check_IDENTIFIER);
6538 when Pragma_Check_Name =>
6539 Check_No_Identifiers;
6541 Check_Valid_Configuration_Pragma;
6542 Check_Arg_Count (1);
6543 Check_Arg_Is_Identifier (Arg1);
6546 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6549 for J in Check_Names.First .. Check_Names.Last loop
6550 if Check_Names.Table (J) = Nam then
6555 Check_Names.Append (Nam);
6562 -- pragma Check_Policy (
6563 -- [Name =>] IDENTIFIER,
6564 -- [Policy =>] POLICY_IDENTIFIER);
6566 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6568 -- Note: this is a configuration pragma, but it is allowed to appear
6571 when Pragma_Check_Policy =>
6573 Check_Arg_Count (2);
6574 Check_Optional_Identifier (Arg1, Name_Name);
6575 Check_Optional_Identifier (Arg2, Name_Policy);
6577 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6579 -- A Check_Policy pragma can appear either as a configuration
6580 -- pragma, or in a declarative part or a package spec (see RM
6581 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6582 -- followed for Check_Policy).
6584 if not Is_Configuration_Pragma then
6585 Check_Is_In_Decl_Part_Or_Package_Spec;
6588 Set_Next_Pragma (N, Opt.Check_Policy_List);
6589 Opt.Check_Policy_List := N;
6591 ---------------------
6592 -- CIL_Constructor --
6593 ---------------------
6595 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6597 -- Processing for this pragma is shared with Java_Constructor
6603 -- pragma Comment (static_string_EXPRESSION)
6605 -- Processing for pragma Comment shares the circuitry for pragma
6606 -- Ident. The only differences are that Ident enforces a limit of 31
6607 -- characters on its argument, and also enforces limitations on
6608 -- placement for DEC compatibility. Pragma Comment shares neither of
6609 -- these restrictions.
6615 -- pragma Common_Object (
6616 -- [Internal =>] LOCAL_NAME
6617 -- [, [External =>] EXTERNAL_SYMBOL]
6618 -- [, [Size =>] EXTERNAL_SYMBOL]);
6620 -- Processing for this pragma is shared with Psect_Object
6622 ------------------------
6623 -- Compile_Time_Error --
6624 ------------------------
6626 -- pragma Compile_Time_Error
6627 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6629 when Pragma_Compile_Time_Error =>
6631 Process_Compile_Time_Warning_Or_Error;
6633 --------------------------
6634 -- Compile_Time_Warning --
6635 --------------------------
6637 -- pragma Compile_Time_Warning
6638 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6640 when Pragma_Compile_Time_Warning =>
6642 Process_Compile_Time_Warning_Or_Error;
6648 when Pragma_Compiler_Unit =>
6650 Check_Arg_Count (0);
6651 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6653 -----------------------------
6654 -- Complete_Representation --
6655 -----------------------------
6657 -- pragma Complete_Representation;
6659 when Pragma_Complete_Representation =>
6661 Check_Arg_Count (0);
6663 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6665 ("pragma & must appear within record representation clause");
6668 ----------------------------
6669 -- Complex_Representation --
6670 ----------------------------
6672 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6674 when Pragma_Complex_Representation => Complex_Representation : declare
6681 Check_Arg_Count (1);
6682 Check_Optional_Identifier (Arg1, Name_Entity);
6683 Check_Arg_Is_Local_Name (Arg1);
6684 E_Id := Get_Pragma_Arg (Arg1);
6686 if Etype (E_Id) = Any_Type then
6692 if not Is_Record_Type (E) then
6694 ("argument for pragma% must be record type", Arg1);
6697 Ent := First_Entity (E);
6700 or else No (Next_Entity (Ent))
6701 or else Present (Next_Entity (Next_Entity (Ent)))
6702 or else not Is_Floating_Point_Type (Etype (Ent))
6703 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6706 ("record for pragma% must have two fields of the same "
6707 & "floating-point type", Arg1);
6710 Set_Has_Complex_Representation (Base_Type (E));
6712 -- We need to treat the type has having a non-standard
6713 -- representation, for back-end purposes, even though in
6714 -- general a complex will have the default representation
6715 -- of a record with two real components.
6717 Set_Has_Non_Standard_Rep (Base_Type (E));
6719 end Complex_Representation;
6721 -------------------------
6722 -- Component_Alignment --
6723 -------------------------
6725 -- pragma Component_Alignment (
6726 -- [Form =>] ALIGNMENT_CHOICE
6727 -- [, [Name =>] type_LOCAL_NAME]);
6729 -- ALIGNMENT_CHOICE ::=
6731 -- | Component_Size_4
6735 when Pragma_Component_Alignment => Component_AlignmentP : declare
6736 Args : Args_List (1 .. 2);
6737 Names : constant Name_List (1 .. 2) := (
6741 Form : Node_Id renames Args (1);
6742 Name : Node_Id renames Args (2);
6744 Atype : Component_Alignment_Kind;
6749 Gather_Associations (Names, Args);
6752 Error_Pragma ("missing Form argument for pragma%");
6755 Check_Arg_Is_Identifier (Form);
6757 -- Get proper alignment, note that Default = Component_Size on all
6758 -- machines we have so far, and we want to set this value rather
6759 -- than the default value to indicate that it has been explicitly
6760 -- set (and thus will not get overridden by the default component
6761 -- alignment for the current scope)
6763 if Chars (Form) = Name_Component_Size then
6764 Atype := Calign_Component_Size;
6766 elsif Chars (Form) = Name_Component_Size_4 then
6767 Atype := Calign_Component_Size_4;
6769 elsif Chars (Form) = Name_Default then
6770 Atype := Calign_Component_Size;
6772 elsif Chars (Form) = Name_Storage_Unit then
6773 Atype := Calign_Storage_Unit;
6777 ("invalid Form parameter for pragma%", Form);
6780 -- Case with no name, supplied, affects scope table entry
6784 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6786 -- Case of name supplied
6789 Check_Arg_Is_Local_Name (Name);
6791 Typ := Entity (Name);
6794 or else Rep_Item_Too_Early (Typ, N)
6798 Typ := Underlying_Type (Typ);
6801 if not Is_Record_Type (Typ)
6802 and then not Is_Array_Type (Typ)
6805 ("Name parameter of pragma% must identify record or " &
6806 "array type", Name);
6809 -- An explicit Component_Alignment pragma overrides an
6810 -- implicit pragma Pack, but not an explicit one.
6812 if not Has_Pragma_Pack (Base_Type (Typ)) then
6813 Set_Is_Packed (Base_Type (Typ), False);
6814 Set_Component_Alignment (Base_Type (Typ), Atype);
6817 end Component_AlignmentP;
6823 -- pragma Controlled (first_subtype_LOCAL_NAME);
6825 when Pragma_Controlled => Controlled : declare
6829 Check_No_Identifiers;
6830 Check_Arg_Count (1);
6831 Check_Arg_Is_Local_Name (Arg1);
6832 Arg := Get_Pragma_Arg (Arg1);
6834 if not Is_Entity_Name (Arg)
6835 or else not Is_Access_Type (Entity (Arg))
6837 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6839 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6847 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6848 -- [Entity =>] LOCAL_NAME);
6850 when Pragma_Convention => Convention : declare
6853 pragma Warnings (Off, C);
6854 pragma Warnings (Off, E);
6856 Check_Arg_Order ((Name_Convention, Name_Entity));
6857 Check_Ada_83_Warning;
6858 Check_Arg_Count (2);
6859 Process_Convention (C, E);
6862 ---------------------------
6863 -- Convention_Identifier --
6864 ---------------------------
6866 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6867 -- [Convention =>] convention_IDENTIFIER);
6869 when Pragma_Convention_Identifier => Convention_Identifier : declare
6875 Check_Arg_Order ((Name_Name, Name_Convention));
6876 Check_Arg_Count (2);
6877 Check_Optional_Identifier (Arg1, Name_Name);
6878 Check_Optional_Identifier (Arg2, Name_Convention);
6879 Check_Arg_Is_Identifier (Arg1);
6880 Check_Arg_Is_Identifier (Arg2);
6881 Idnam := Chars (Get_Pragma_Arg (Arg1));
6882 Cname := Chars (Get_Pragma_Arg (Arg2));
6884 if Is_Convention_Name (Cname) then
6885 Record_Convention_Identifier
6886 (Idnam, Get_Convention_Id (Cname));
6889 ("second arg for % pragma must be convention", Arg2);
6891 end Convention_Identifier;
6897 -- pragma CPP_Class ([Entity =>] local_NAME)
6899 when Pragma_CPP_Class => CPP_Class : declare
6904 if Warn_On_Obsolescent_Feature then
6906 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6907 " by pragma import?", N);
6911 Check_Arg_Count (1);
6912 Check_Optional_Identifier (Arg1, Name_Entity);
6913 Check_Arg_Is_Local_Name (Arg1);
6915 Arg := Get_Pragma_Arg (Arg1);
6918 if Etype (Arg) = Any_Type then
6922 if not Is_Entity_Name (Arg)
6923 or else not Is_Type (Entity (Arg))
6925 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6928 Typ := Entity (Arg);
6930 if not Is_Tagged_Type (Typ) then
6931 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6934 -- Types treated as CPP classes are treated as limited, but we
6935 -- don't require them to be declared this way. A warning is issued
6936 -- to encourage the user to declare them as limited. This is not
6937 -- an error, for compatibility reasons, because these types have
6938 -- been supported this way for some time.
6940 if not Is_Limited_Type (Typ) then
6942 ("imported 'C'P'P type should be " &
6943 "explicitly declared limited?",
6944 Get_Pragma_Arg (Arg1));
6946 ("\type will be considered limited",
6947 Get_Pragma_Arg (Arg1));
6950 Set_Is_CPP_Class (Typ);
6951 Set_Is_Limited_Record (Typ);
6952 Set_Convention (Typ, Convention_CPP);
6954 -- Imported CPP types must not have discriminants (because C++
6955 -- classes do not have discriminants).
6957 if Has_Discriminants (Typ) then
6959 ("imported 'C'P'P type cannot have discriminants",
6960 First (Discriminant_Specifications
6961 (Declaration_Node (Typ))));
6964 -- Components of imported CPP types must not have default
6965 -- expressions because the constructor (if any) is in the
6968 if Is_Incomplete_Or_Private_Type (Typ)
6969 and then No (Underlying_Type (Typ))
6971 -- It should be an error to apply pragma CPP to a private
6972 -- type if the underlying type is not visible (as it is
6973 -- for any representation item). For now, for backward
6974 -- compatibility we do nothing but we cannot check components
6975 -- because they are not available at this stage. All this code
6976 -- will be removed when we cleanup this obsolete GNAT pragma???
6982 Tdef : constant Node_Id :=
6983 Type_Definition (Declaration_Node (Typ));
6988 if Nkind (Tdef) = N_Record_Definition then
6989 Clist := Component_List (Tdef);
6991 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
6992 Clist := Component_List (Record_Extension_Part (Tdef));
6995 if Present (Clist) then
6996 Comp := First (Component_Items (Clist));
6997 while Present (Comp) loop
6998 if Present (Expression (Comp)) then
7000 ("component of imported 'C'P'P type cannot have" &
7001 " default expression", Expression (Comp));
7011 ---------------------
7012 -- CPP_Constructor --
7013 ---------------------
7015 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7016 -- [, [External_Name =>] static_string_EXPRESSION ]
7017 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7019 when Pragma_CPP_Constructor => CPP_Constructor : declare
7023 Tag_Typ : Entity_Id;
7027 Check_At_Least_N_Arguments (1);
7028 Check_At_Most_N_Arguments (3);
7029 Check_Optional_Identifier (Arg1, Name_Entity);
7030 Check_Arg_Is_Local_Name (Arg1);
7032 Id := Get_Pragma_Arg (Arg1);
7033 Find_Program_Unit_Name (Id);
7035 -- If we did not find the name, we are done
7037 if Etype (Id) = Any_Type then
7041 Def_Id := Entity (Id);
7043 -- Check if already defined as constructor
7045 if Is_Constructor (Def_Id) then
7047 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7051 if Ekind (Def_Id) = E_Function
7052 and then (Is_CPP_Class (Etype (Def_Id))
7053 or else (Is_Class_Wide_Type (Etype (Def_Id))
7055 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7057 if Arg_Count >= 2 then
7058 Set_Imported (Def_Id);
7059 Set_Is_Public (Def_Id);
7060 Process_Interface_Name (Def_Id, Arg2, Arg3);
7063 Set_Has_Completion (Def_Id);
7064 Set_Is_Constructor (Def_Id);
7066 -- Imported C++ constructors are not dispatching primitives
7067 -- because in C++ they don't have a dispatch table slot.
7068 -- However, in Ada the constructor has the profile of a
7069 -- function that returns a tagged type and therefore it has
7070 -- been treated as a primitive operation during semantic
7071 -- analysis. We now remove it from the list of primitive
7072 -- operations of the type.
7074 if Is_Tagged_Type (Etype (Def_Id))
7075 and then not Is_Class_Wide_Type (Etype (Def_Id))
7077 pragma Assert (Is_Dispatching_Operation (Def_Id));
7078 Tag_Typ := Etype (Def_Id);
7080 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7081 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7085 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7086 Set_Is_Dispatching_Operation (Def_Id, False);
7089 -- For backward compatibility, if the constructor returns a
7090 -- class wide type, and we internally change the return type to
7091 -- the corresponding root type.
7093 if Is_Class_Wide_Type (Etype (Def_Id)) then
7094 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7098 ("pragma% requires function returning a 'C'P'P_Class type",
7101 end CPP_Constructor;
7107 when Pragma_CPP_Virtual => CPP_Virtual : declare
7111 if Warn_On_Obsolescent_Feature then
7113 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7122 when Pragma_CPP_Vtable => CPP_Vtable : declare
7126 if Warn_On_Obsolescent_Feature then
7128 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7137 -- pragma CPU (EXPRESSION);
7139 when Pragma_CPU => CPU : declare
7140 P : constant Node_Id := Parent (N);
7145 Check_No_Identifiers;
7146 Check_Arg_Count (1);
7150 if Nkind (P) = N_Subprogram_Body then
7151 Check_In_Main_Program;
7153 Arg := Get_Pragma_Arg (Arg1);
7154 Analyze_And_Resolve (Arg, Any_Integer);
7158 if not Is_Static_Expression (Arg) then
7159 Flag_Non_Static_Expr
7160 ("main subprogram affinity is not static!", Arg);
7163 -- If constraint error, then we already signalled an error
7165 elsif Raises_Constraint_Error (Arg) then
7168 -- Otherwise check in range
7172 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7173 -- This is the entity System.Multiprocessors.CPU_Range;
7175 Val : constant Uint := Expr_Value (Arg);
7178 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7180 Val > Expr_Value (Type_High_Bound (CPU_Id))
7183 ("main subprogram CPU is out of range", Arg1);
7189 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7193 elsif Nkind (P) = N_Task_Definition then
7194 Arg := Get_Pragma_Arg (Arg1);
7196 -- The expression must be analyzed in the special manner
7197 -- described in "Handling of Default and Per-Object
7198 -- Expressions" in sem.ads.
7200 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7202 -- Anything else is incorrect
7208 if Has_Pragma_CPU (P) then
7209 Error_Pragma ("duplicate pragma% not allowed");
7211 Set_Has_Pragma_CPU (P, True);
7213 if Nkind (P) = N_Task_Definition then
7214 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7223 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7225 when Pragma_Debug => Debug : declare
7233 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7236 if Arg_Count = 2 then
7239 Left_Opnd => Relocate_Node (Cond),
7240 Right_Opnd => Get_Pragma_Arg (Arg1));
7243 -- Rewrite into a conditional with an appropriate condition. We
7244 -- wrap the procedure call in a block so that overhead from e.g.
7245 -- use of the secondary stack does not generate execution overhead
7246 -- for suppressed conditions.
7248 Rewrite (N, Make_Implicit_If_Statement (N,
7250 Then_Statements => New_List (
7251 Make_Block_Statement (Loc,
7252 Handled_Statement_Sequence =>
7253 Make_Handled_Sequence_Of_Statements (Loc,
7254 Statements => New_List (
7255 Relocate_Node (Debug_Statement (N))))))));
7263 -- pragma Debug_Policy (Check | Ignore)
7265 when Pragma_Debug_Policy =>
7267 Check_Arg_Count (1);
7268 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7269 Debug_Pragmas_Enabled :=
7270 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7272 ---------------------
7273 -- Detect_Blocking --
7274 ---------------------
7276 -- pragma Detect_Blocking;
7278 when Pragma_Detect_Blocking =>
7280 Check_Arg_Count (0);
7281 Check_Valid_Configuration_Pragma;
7282 Detect_Blocking := True;
7284 --------------------------
7285 -- Default_Storage_Pool --
7286 --------------------------
7288 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7290 when Pragma_Default_Storage_Pool =>
7292 Check_Arg_Count (1);
7294 -- Default_Storage_Pool can appear as a configuration pragma, or
7295 -- in a declarative part or a package spec.
7297 if not Is_Configuration_Pragma then
7298 Check_Is_In_Decl_Part_Or_Package_Spec;
7301 -- Case of Default_Storage_Pool (null);
7303 if Nkind (Expression (Arg1)) = N_Null then
7304 Analyze (Expression (Arg1));
7306 -- This is an odd case, this is not really an expression, so
7307 -- we don't have a type for it. So just set the type to Empty.
7309 Set_Etype (Expression (Arg1), Empty);
7311 -- Case of Default_Storage_Pool (storage_pool_NAME);
7314 -- If it's a configuration pragma, then the only allowed
7315 -- argument is "null".
7317 if Is_Configuration_Pragma then
7318 Error_Pragma_Arg ("NULL expected", Arg1);
7321 -- The expected type for a non-"null" argument is
7322 -- Root_Storage_Pool'Class.
7325 (Get_Pragma_Arg (Arg1),
7326 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7329 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7330 -- for an access type will use this information to set the
7331 -- appropriate attributes of the access type.
7333 Default_Pool := Expression (Arg1);
7339 when Pragma_Dimension =>
7341 Check_Arg_Count (4);
7342 Check_No_Identifiers;
7343 Check_Arg_Is_Local_Name (Arg1);
7345 if not Is_Type (Arg1) then
7346 Error_Pragma ("first argument for pragma% must be subtype");
7349 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7350 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7351 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7357 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7359 when Pragma_Discard_Names => Discard_Names : declare
7364 Check_Ada_83_Warning;
7366 -- Deal with configuration pragma case
7368 if Arg_Count = 0 and then Is_Configuration_Pragma then
7369 Global_Discard_Names := True;
7372 -- Otherwise, check correct appropriate context
7375 Check_Is_In_Decl_Part_Or_Package_Spec;
7377 if Arg_Count = 0 then
7379 -- If there is no parameter, then from now on this pragma
7380 -- applies to any enumeration, exception or tagged type
7381 -- defined in the current declarative part, and recursively
7382 -- to any nested scope.
7384 Set_Discard_Names (Current_Scope, Sense);
7388 Check_Arg_Count (1);
7389 Check_Optional_Identifier (Arg1, Name_On);
7390 Check_Arg_Is_Local_Name (Arg1);
7392 E_Id := Get_Pragma_Arg (Arg1);
7394 if Etype (E_Id) = Any_Type then
7400 if (Is_First_Subtype (E)
7402 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7403 or else Ekind (E) = E_Exception
7405 Set_Discard_Names (E, Sense);
7408 ("inappropriate entity for pragma%", Arg1);
7419 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7421 when Pragma_Elaborate => Elaborate : declare
7426 -- Pragma must be in context items list of a compilation unit
7428 if not Is_In_Context_Clause then
7432 -- Must be at least one argument
7434 if Arg_Count = 0 then
7435 Error_Pragma ("pragma% requires at least one argument");
7438 -- In Ada 83 mode, there can be no items following it in the
7439 -- context list except other pragmas and implicit with clauses
7440 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7441 -- placement rule does not apply.
7443 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7445 while Present (Citem) loop
7446 if Nkind (Citem) = N_Pragma
7447 or else (Nkind (Citem) = N_With_Clause
7448 and then Implicit_With (Citem))
7453 ("(Ada 83) pragma% must be at end of context clause");
7460 -- Finally, the arguments must all be units mentioned in a with
7461 -- clause in the same context clause. Note we already checked (in
7462 -- Par.Prag) that the arguments are all identifiers or selected
7466 Outer : while Present (Arg) loop
7467 Citem := First (List_Containing (N));
7468 Inner : while Citem /= N loop
7469 if Nkind (Citem) = N_With_Clause
7470 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7472 Set_Elaborate_Present (Citem, True);
7473 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7475 -- With the pragma present, elaboration calls on
7476 -- subprograms from the named unit need no further
7477 -- checks, as long as the pragma appears in the current
7478 -- compilation unit. If the pragma appears in some unit
7479 -- in the context, there might still be a need for an
7480 -- Elaborate_All_Desirable from the current compilation
7481 -- to the named unit, so we keep the check enabled.
7483 if In_Extended_Main_Source_Unit (N) then
7484 Set_Suppress_Elaboration_Warnings
7485 (Entity (Name (Citem)));
7496 ("argument of pragma% is not with'ed unit", Arg);
7502 -- Give a warning if operating in static mode with -gnatwl
7503 -- (elaboration warnings enabled) switch set.
7505 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7507 ("?use of pragma Elaborate may not be safe", N);
7509 ("?use pragma Elaborate_All instead if possible", N);
7517 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7519 when Pragma_Elaborate_All => Elaborate_All : declare
7524 Check_Ada_83_Warning;
7526 -- Pragma must be in context items list of a compilation unit
7528 if not Is_In_Context_Clause then
7532 -- Must be at least one argument
7534 if Arg_Count = 0 then
7535 Error_Pragma ("pragma% requires at least one argument");
7538 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7539 -- have to appear at the end of the context clause, but may
7540 -- appear mixed in with other items, even in Ada 83 mode.
7542 -- Final check: the arguments must all be units mentioned in
7543 -- a with clause in the same context clause. Note that we
7544 -- already checked (in Par.Prag) that all the arguments are
7545 -- either identifiers or selected components.
7548 Outr : while Present (Arg) loop
7549 Citem := First (List_Containing (N));
7550 Innr : while Citem /= N loop
7551 if Nkind (Citem) = N_With_Clause
7552 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7554 Set_Elaborate_All_Present (Citem, True);
7555 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7557 -- Suppress warnings and elaboration checks on the named
7558 -- unit if the pragma is in the current compilation, as
7559 -- for pragma Elaborate.
7561 if In_Extended_Main_Source_Unit (N) then
7562 Set_Suppress_Elaboration_Warnings
7563 (Entity (Name (Citem)));
7572 Set_Error_Posted (N);
7574 ("argument of pragma% is not with'ed unit", Arg);
7581 --------------------
7582 -- Elaborate_Body --
7583 --------------------
7585 -- pragma Elaborate_Body [( library_unit_NAME )];
7587 when Pragma_Elaborate_Body => Elaborate_Body : declare
7588 Cunit_Node : Node_Id;
7589 Cunit_Ent : Entity_Id;
7592 Check_Ada_83_Warning;
7593 Check_Valid_Library_Unit_Pragma;
7595 if Nkind (N) = N_Null_Statement then
7599 Cunit_Node := Cunit (Current_Sem_Unit);
7600 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7602 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7605 Error_Pragma ("pragma% must refer to a spec, not a body");
7607 Set_Body_Required (Cunit_Node, True);
7608 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7610 -- If we are in dynamic elaboration mode, then we suppress
7611 -- elaboration warnings for the unit, since it is definitely
7612 -- fine NOT to do dynamic checks at the first level (and such
7613 -- checks will be suppressed because no elaboration boolean
7614 -- is created for Elaborate_Body packages).
7616 -- But in the static model of elaboration, Elaborate_Body is
7617 -- definitely NOT good enough to ensure elaboration safety on
7618 -- its own, since the body may WITH other units that are not
7619 -- safe from an elaboration point of view, so a client must
7620 -- still do an Elaborate_All on such units.
7622 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7623 -- Elaborate_Body always suppressed elab warnings.
7625 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7626 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7631 ------------------------
7632 -- Elaboration_Checks --
7633 ------------------------
7635 -- pragma Elaboration_Checks (Static | Dynamic);
7637 when Pragma_Elaboration_Checks =>
7639 Check_Arg_Count (1);
7640 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7641 Dynamic_Elaboration_Checks :=
7642 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7648 -- pragma Eliminate (
7649 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7650 -- [,[Entity =>] IDENTIFIER |
7651 -- SELECTED_COMPONENT |
7653 -- [, OVERLOADING_RESOLUTION]);
7655 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7658 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7661 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7663 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7664 -- Result_Type => result_SUBTYPE_NAME]
7666 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7667 -- SUBTYPE_NAME ::= STRING_LITERAL
7669 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7670 -- SOURCE_TRACE ::= STRING_LITERAL
7672 when Pragma_Eliminate => Eliminate : declare
7673 Args : Args_List (1 .. 5);
7674 Names : constant Name_List (1 .. 5) := (
7677 Name_Parameter_Types,
7679 Name_Source_Location);
7681 Unit_Name : Node_Id renames Args (1);
7682 Entity : Node_Id renames Args (2);
7683 Parameter_Types : Node_Id renames Args (3);
7684 Result_Type : Node_Id renames Args (4);
7685 Source_Location : Node_Id renames Args (5);
7689 Check_Valid_Configuration_Pragma;
7690 Gather_Associations (Names, Args);
7692 if No (Unit_Name) then
7693 Error_Pragma ("missing Unit_Name argument for pragma%");
7697 and then (Present (Parameter_Types)
7699 Present (Result_Type)
7701 Present (Source_Location))
7703 Error_Pragma ("missing Entity argument for pragma%");
7706 if (Present (Parameter_Types)
7708 Present (Result_Type))
7710 Present (Source_Location)
7713 ("parameter profile and source location cannot " &
7714 "be used together in pragma%");
7717 Process_Eliminate_Pragma
7731 -- [ Convention =>] convention_IDENTIFIER,
7732 -- [ Entity =>] local_NAME
7733 -- [, [External_Name =>] static_string_EXPRESSION ]
7734 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7736 when Pragma_Export => Export : declare
7740 pragma Warnings (Off, C);
7743 Check_Ada_83_Warning;
7749 Check_At_Least_N_Arguments (2);
7750 Check_At_Most_N_Arguments (4);
7751 Process_Convention (C, Def_Id);
7753 if Ekind (Def_Id) /= E_Constant then
7754 Note_Possible_Modification
7755 (Get_Pragma_Arg (Arg2), Sure => False);
7758 Process_Interface_Name (Def_Id, Arg3, Arg4);
7759 Set_Exported (Def_Id, Arg2);
7761 -- If the entity is a deferred constant, propagate the information
7762 -- to the full view, because gigi elaborates the full view only.
7764 if Ekind (Def_Id) = E_Constant
7765 and then Present (Full_View (Def_Id))
7768 Id2 : constant Entity_Id := Full_View (Def_Id);
7770 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7771 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7772 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7777 ----------------------
7778 -- Export_Exception --
7779 ----------------------
7781 -- pragma Export_Exception (
7782 -- [Internal =>] LOCAL_NAME
7783 -- [, [External =>] EXTERNAL_SYMBOL]
7784 -- [, [Form =>] Ada | VMS]
7785 -- [, [Code =>] static_integer_EXPRESSION]);
7787 when Pragma_Export_Exception => Export_Exception : declare
7788 Args : Args_List (1 .. 4);
7789 Names : constant Name_List (1 .. 4) := (
7795 Internal : Node_Id renames Args (1);
7796 External : Node_Id renames Args (2);
7797 Form : Node_Id renames Args (3);
7798 Code : Node_Id renames Args (4);
7803 if Inside_A_Generic then
7804 Error_Pragma ("pragma% cannot be used for generic entities");
7807 Gather_Associations (Names, Args);
7808 Process_Extended_Import_Export_Exception_Pragma (
7809 Arg_Internal => Internal,
7810 Arg_External => External,
7814 if not Is_VMS_Exception (Entity (Internal)) then
7815 Set_Exported (Entity (Internal), Internal);
7817 end Export_Exception;
7819 ---------------------
7820 -- Export_Function --
7821 ---------------------
7823 -- pragma Export_Function (
7824 -- [Internal =>] LOCAL_NAME
7825 -- [, [External =>] EXTERNAL_SYMBOL]
7826 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7827 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7828 -- [, [Mechanism =>] MECHANISM]
7829 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7831 -- EXTERNAL_SYMBOL ::=
7833 -- | static_string_EXPRESSION
7835 -- PARAMETER_TYPES ::=
7837 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7839 -- TYPE_DESIGNATOR ::=
7841 -- | subtype_Name ' Access
7845 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7847 -- MECHANISM_ASSOCIATION ::=
7848 -- [formal_parameter_NAME =>] MECHANISM_NAME
7850 -- MECHANISM_NAME ::=
7853 -- | Descriptor [([Class =>] CLASS_NAME)]
7855 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7857 when Pragma_Export_Function => Export_Function : declare
7858 Args : Args_List (1 .. 6);
7859 Names : constant Name_List (1 .. 6) := (
7862 Name_Parameter_Types,
7865 Name_Result_Mechanism);
7867 Internal : Node_Id renames Args (1);
7868 External : Node_Id renames Args (2);
7869 Parameter_Types : Node_Id renames Args (3);
7870 Result_Type : Node_Id renames Args (4);
7871 Mechanism : Node_Id renames Args (5);
7872 Result_Mechanism : Node_Id renames Args (6);
7876 Gather_Associations (Names, Args);
7877 Process_Extended_Import_Export_Subprogram_Pragma (
7878 Arg_Internal => Internal,
7879 Arg_External => External,
7880 Arg_Parameter_Types => Parameter_Types,
7881 Arg_Result_Type => Result_Type,
7882 Arg_Mechanism => Mechanism,
7883 Arg_Result_Mechanism => Result_Mechanism);
7884 end Export_Function;
7890 -- pragma Export_Object (
7891 -- [Internal =>] LOCAL_NAME
7892 -- [, [External =>] EXTERNAL_SYMBOL]
7893 -- [, [Size =>] EXTERNAL_SYMBOL]);
7895 -- EXTERNAL_SYMBOL ::=
7897 -- | static_string_EXPRESSION
7899 -- PARAMETER_TYPES ::=
7901 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7903 -- TYPE_DESIGNATOR ::=
7905 -- | subtype_Name ' Access
7909 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7911 -- MECHANISM_ASSOCIATION ::=
7912 -- [formal_parameter_NAME =>] MECHANISM_NAME
7914 -- MECHANISM_NAME ::=
7917 -- | Descriptor [([Class =>] CLASS_NAME)]
7919 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7921 when Pragma_Export_Object => Export_Object : declare
7922 Args : Args_List (1 .. 3);
7923 Names : constant Name_List (1 .. 3) := (
7928 Internal : Node_Id renames Args (1);
7929 External : Node_Id renames Args (2);
7930 Size : Node_Id renames Args (3);
7934 Gather_Associations (Names, Args);
7935 Process_Extended_Import_Export_Object_Pragma (
7936 Arg_Internal => Internal,
7937 Arg_External => External,
7941 ----------------------
7942 -- Export_Procedure --
7943 ----------------------
7945 -- pragma Export_Procedure (
7946 -- [Internal =>] LOCAL_NAME
7947 -- [, [External =>] EXTERNAL_SYMBOL]
7948 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7949 -- [, [Mechanism =>] MECHANISM]);
7951 -- EXTERNAL_SYMBOL ::=
7953 -- | static_string_EXPRESSION
7955 -- PARAMETER_TYPES ::=
7957 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7959 -- TYPE_DESIGNATOR ::=
7961 -- | subtype_Name ' Access
7965 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7967 -- MECHANISM_ASSOCIATION ::=
7968 -- [formal_parameter_NAME =>] MECHANISM_NAME
7970 -- MECHANISM_NAME ::=
7973 -- | Descriptor [([Class =>] CLASS_NAME)]
7975 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7977 when Pragma_Export_Procedure => Export_Procedure : declare
7978 Args : Args_List (1 .. 4);
7979 Names : constant Name_List (1 .. 4) := (
7982 Name_Parameter_Types,
7985 Internal : Node_Id renames Args (1);
7986 External : Node_Id renames Args (2);
7987 Parameter_Types : Node_Id renames Args (3);
7988 Mechanism : Node_Id renames Args (4);
7992 Gather_Associations (Names, Args);
7993 Process_Extended_Import_Export_Subprogram_Pragma (
7994 Arg_Internal => Internal,
7995 Arg_External => External,
7996 Arg_Parameter_Types => Parameter_Types,
7997 Arg_Mechanism => Mechanism);
7998 end Export_Procedure;
8004 -- pragma Export_Value (
8005 -- [Value =>] static_integer_EXPRESSION,
8006 -- [Link_Name =>] static_string_EXPRESSION);
8008 when Pragma_Export_Value =>
8010 Check_Arg_Order ((Name_Value, Name_Link_Name));
8011 Check_Arg_Count (2);
8013 Check_Optional_Identifier (Arg1, Name_Value);
8014 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8016 Check_Optional_Identifier (Arg2, Name_Link_Name);
8017 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8019 -----------------------------
8020 -- Export_Valued_Procedure --
8021 -----------------------------
8023 -- pragma Export_Valued_Procedure (
8024 -- [Internal =>] LOCAL_NAME
8025 -- [, [External =>] EXTERNAL_SYMBOL,]
8026 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8027 -- [, [Mechanism =>] MECHANISM]);
8029 -- EXTERNAL_SYMBOL ::=
8031 -- | static_string_EXPRESSION
8033 -- PARAMETER_TYPES ::=
8035 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8037 -- TYPE_DESIGNATOR ::=
8039 -- | subtype_Name ' Access
8043 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8045 -- MECHANISM_ASSOCIATION ::=
8046 -- [formal_parameter_NAME =>] MECHANISM_NAME
8048 -- MECHANISM_NAME ::=
8051 -- | Descriptor [([Class =>] CLASS_NAME)]
8053 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8055 when Pragma_Export_Valued_Procedure =>
8056 Export_Valued_Procedure : declare
8057 Args : Args_List (1 .. 4);
8058 Names : constant Name_List (1 .. 4) := (
8061 Name_Parameter_Types,
8064 Internal : Node_Id renames Args (1);
8065 External : Node_Id renames Args (2);
8066 Parameter_Types : Node_Id renames Args (3);
8067 Mechanism : Node_Id renames Args (4);
8071 Gather_Associations (Names, Args);
8072 Process_Extended_Import_Export_Subprogram_Pragma (
8073 Arg_Internal => Internal,
8074 Arg_External => External,
8075 Arg_Parameter_Types => Parameter_Types,
8076 Arg_Mechanism => Mechanism);
8077 end Export_Valued_Procedure;
8083 -- pragma Extend_System ([Name =>] Identifier);
8085 when Pragma_Extend_System => Extend_System : declare
8088 Check_Valid_Configuration_Pragma;
8089 Check_Arg_Count (1);
8090 Check_Optional_Identifier (Arg1, Name_Name);
8091 Check_Arg_Is_Identifier (Arg1);
8093 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8096 and then Name_Buffer (1 .. 4) = "aux_"
8098 if Present (System_Extend_Pragma_Arg) then
8099 if Chars (Get_Pragma_Arg (Arg1)) =
8100 Chars (Expression (System_Extend_Pragma_Arg))
8104 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8105 Error_Pragma ("pragma% conflicts with that #");
8109 System_Extend_Pragma_Arg := Arg1;
8111 if not GNAT_Mode then
8112 System_Extend_Unit := Arg1;
8116 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8120 ------------------------
8121 -- Extensions_Allowed --
8122 ------------------------
8124 -- pragma Extensions_Allowed (ON | OFF);
8126 when Pragma_Extensions_Allowed =>
8128 Check_Arg_Count (1);
8129 Check_No_Identifiers;
8130 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8132 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8133 Extensions_Allowed := True;
8134 Ada_Version := Ada_Version_Type'Last;
8137 Extensions_Allowed := False;
8138 Ada_Version := Ada_Version_Explicit;
8145 -- pragma External (
8146 -- [ Convention =>] convention_IDENTIFIER,
8147 -- [ Entity =>] local_NAME
8148 -- [, [External_Name =>] static_string_EXPRESSION ]
8149 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8151 when Pragma_External => External : declare
8155 pragma Warnings (Off, C);
8164 Check_At_Least_N_Arguments (2);
8165 Check_At_Most_N_Arguments (4);
8166 Process_Convention (C, Def_Id);
8167 Note_Possible_Modification
8168 (Get_Pragma_Arg (Arg2), Sure => False);
8169 Process_Interface_Name (Def_Id, Arg3, Arg4);
8170 Set_Exported (Def_Id, Arg2);
8173 --------------------------
8174 -- External_Name_Casing --
8175 --------------------------
8177 -- pragma External_Name_Casing (
8178 -- UPPERCASE | LOWERCASE
8179 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8181 when Pragma_External_Name_Casing => External_Name_Casing : declare
8184 Check_No_Identifiers;
8186 if Arg_Count = 2 then
8188 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8190 case Chars (Get_Pragma_Arg (Arg2)) is
8192 Opt.External_Name_Exp_Casing := As_Is;
8194 when Name_Uppercase =>
8195 Opt.External_Name_Exp_Casing := Uppercase;
8197 when Name_Lowercase =>
8198 Opt.External_Name_Exp_Casing := Lowercase;
8205 Check_Arg_Count (1);
8208 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8210 case Chars (Get_Pragma_Arg (Arg1)) is
8211 when Name_Uppercase =>
8212 Opt.External_Name_Imp_Casing := Uppercase;
8214 when Name_Lowercase =>
8215 Opt.External_Name_Imp_Casing := Lowercase;
8220 end External_Name_Casing;
8222 --------------------------
8223 -- Favor_Top_Level --
8224 --------------------------
8226 -- pragma Favor_Top_Level (type_NAME);
8228 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8229 Named_Entity : Entity_Id;
8233 Check_No_Identifiers;
8234 Check_Arg_Count (1);
8235 Check_Arg_Is_Local_Name (Arg1);
8236 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8238 -- If it's an access-to-subprogram type (in particular, not a
8239 -- subtype), set the flag on that type.
8241 if Is_Access_Subprogram_Type (Named_Entity) then
8243 Set_Can_Use_Internal_Rep (Named_Entity, False);
8246 -- Otherwise it's an error (name denotes the wrong sort of entity)
8250 ("access-to-subprogram type expected",
8251 Get_Pragma_Arg (Arg1));
8253 end Favor_Top_Level;
8259 -- pragma Fast_Math;
8261 when Pragma_Fast_Math =>
8263 Check_No_Identifiers;
8264 Check_Valid_Configuration_Pragma;
8267 ---------------------------
8268 -- Finalize_Storage_Only --
8269 ---------------------------
8271 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8273 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8274 Assoc : constant Node_Id := Arg1;
8275 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8280 Check_No_Identifiers;
8281 Check_Arg_Count (1);
8282 Check_Arg_Is_Local_Name (Arg1);
8284 Find_Type (Type_Id);
8285 Typ := Entity (Type_Id);
8288 or else Rep_Item_Too_Early (Typ, N)
8292 Typ := Underlying_Type (Typ);
8295 if not Is_Controlled (Typ) then
8296 Error_Pragma ("pragma% must specify controlled type");
8299 Check_First_Subtype (Arg1);
8301 if Finalize_Storage_Only (Typ) then
8302 Error_Pragma ("duplicate pragma%, only one allowed");
8304 elsif not Rep_Item_Too_Late (Typ, N) then
8305 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8307 end Finalize_Storage;
8309 --------------------------
8310 -- Float_Representation --
8311 --------------------------
8313 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8315 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8317 when Pragma_Float_Representation => Float_Representation : declare
8325 if Arg_Count = 1 then
8326 Check_Valid_Configuration_Pragma;
8328 Check_Arg_Count (2);
8329 Check_Optional_Identifier (Arg2, Name_Entity);
8330 Check_Arg_Is_Local_Name (Arg2);
8333 Check_No_Identifier (Arg1);
8334 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8336 if not OpenVMS_On_Target then
8337 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8339 ("?pragma% ignored (applies only to Open'V'M'S)");
8345 -- One argument case
8347 if Arg_Count = 1 then
8348 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8349 if Opt.Float_Format = 'I' then
8350 Error_Pragma ("'I'E'E'E format previously specified");
8353 Opt.Float_Format := 'V';
8356 if Opt.Float_Format = 'V' then
8357 Error_Pragma ("'V'A'X format previously specified");
8360 Opt.Float_Format := 'I';
8363 Set_Standard_Fpt_Formats;
8365 -- Two argument case
8368 Argx := Get_Pragma_Arg (Arg2);
8370 if not Is_Entity_Name (Argx)
8371 or else not Is_Floating_Point_Type (Entity (Argx))
8374 ("second argument of% pragma must be floating-point type",
8378 Ent := Entity (Argx);
8379 Digs := UI_To_Int (Digits_Value (Ent));
8381 -- Two arguments, VAX_Float case
8383 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8385 when 6 => Set_F_Float (Ent);
8386 when 9 => Set_D_Float (Ent);
8387 when 15 => Set_G_Float (Ent);
8391 ("wrong digits value, must be 6,9 or 15", Arg2);
8394 -- Two arguments, IEEE_Float case
8398 when 6 => Set_IEEE_Short (Ent);
8399 when 15 => Set_IEEE_Long (Ent);
8403 ("wrong digits value, must be 6 or 15", Arg2);
8407 end Float_Representation;
8413 -- pragma Ident (static_string_EXPRESSION)
8415 -- Note: pragma Comment shares this processing. Pragma Comment is
8416 -- identical to Ident, except that the restriction of the argument to
8417 -- 31 characters and the placement restrictions are not enforced for
8420 when Pragma_Ident | Pragma_Comment => Ident : declare
8425 Check_Arg_Count (1);
8426 Check_No_Identifiers;
8427 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8430 -- For pragma Ident, preserve DEC compatibility by requiring the
8431 -- pragma to appear in a declarative part or package spec.
8433 if Prag_Id = Pragma_Ident then
8434 Check_Is_In_Decl_Part_Or_Package_Spec;
8437 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8444 GP := Parent (Parent (N));
8446 if Nkind_In (GP, N_Package_Declaration,
8447 N_Generic_Package_Declaration)
8452 -- If we have a compilation unit, then record the ident value,
8453 -- checking for improper duplication.
8455 if Nkind (GP) = N_Compilation_Unit then
8456 CS := Ident_String (Current_Sem_Unit);
8458 if Present (CS) then
8460 -- For Ident, we do not permit multiple instances
8462 if Prag_Id = Pragma_Ident then
8463 Error_Pragma ("duplicate% pragma not permitted");
8465 -- For Comment, we concatenate the string, unless we want
8466 -- to preserve the tree structure for ASIS.
8468 elsif not ASIS_Mode then
8469 Start_String (Strval (CS));
8470 Store_String_Char (' ');
8471 Store_String_Chars (Strval (Str));
8472 Set_Strval (CS, End_String);
8476 -- In VMS, the effect of IDENT is achieved by passing
8477 -- --identification=name as a --for-linker switch.
8479 if OpenVMS_On_Target then
8482 ("--for-linker=--identification=");
8483 String_To_Name_Buffer (Strval (Str));
8484 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8486 -- Only the last processed IDENT is saved. The main
8487 -- purpose is so an IDENT associated with a main
8488 -- procedure will be used in preference to an IDENT
8489 -- associated with a with'd package.
8491 Replace_Linker_Option_String
8492 (End_String, "--for-linker=--identification=");
8495 Set_Ident_String (Current_Sem_Unit, Str);
8498 -- For subunits, we just ignore the Ident, since in GNAT these
8499 -- are not separate object files, and hence not separate units
8500 -- in the unit table.
8502 elsif Nkind (GP) = N_Subunit then
8505 -- Otherwise we have a misplaced pragma Ident, but we ignore
8506 -- this if we are in an instantiation, since it comes from
8507 -- a generic, and has no relevance to the instantiation.
8509 elsif Prag_Id = Pragma_Ident then
8510 if Instantiation_Location (Loc) = No_Location then
8511 Error_Pragma ("pragma% only allowed at outer level");
8521 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8522 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8524 when Pragma_Implemented => Implemented : declare
8525 Proc_Id : Entity_Id;
8530 Check_Arg_Count (2);
8531 Check_No_Identifiers;
8532 Check_Arg_Is_Identifier (Arg1);
8533 Check_Arg_Is_Local_Name (Arg1);
8535 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8537 -- Extract the name of the local procedure
8539 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8541 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8542 -- primitive procedure of a synchronized tagged type.
8544 if Ekind (Proc_Id) = E_Procedure
8545 and then Is_Primitive (Proc_Id)
8546 and then Present (First_Formal (Proc_Id))
8548 Typ := Etype (First_Formal (Proc_Id));
8550 if Is_Tagged_Type (Typ)
8553 -- Check for a protected, a synchronized or a task interface
8555 ((Is_Interface (Typ)
8556 and then Is_Synchronized_Interface (Typ))
8558 -- Check for a protected type or a task type that implements
8562 (Is_Concurrent_Record_Type (Typ)
8563 and then Present (Interfaces (Typ)))
8565 -- Check for a private record extension with keyword
8569 (Ekind_In (Typ, E_Record_Type_With_Private,
8570 E_Record_Subtype_With_Private)
8571 and then Synchronized_Present (Parent (Typ))))
8576 ("controlling formal must be of synchronized " &
8577 "tagged type", Arg1);
8581 -- Procedures declared inside a protected type must be accepted
8583 elsif Ekind (Proc_Id) = E_Procedure
8584 and then Is_Protected_Type (Scope (Proc_Id))
8588 -- The first argument is not a primitive procedure
8592 ("pragma % must be applied to a primitive procedure", Arg1);
8596 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8597 -- By_Protected_Procedure to the primitive procedure of a task
8600 if Chars (Arg2) = Name_By_Protected_Procedure
8601 and then Is_Interface (Typ)
8602 and then Is_Task_Interface (Typ)
8605 ("implementation kind By_Protected_Procedure cannot be " &
8606 "applied to a task interface primitive", Arg2);
8610 Record_Rep_Item (Proc_Id, N);
8613 ----------------------
8614 -- Implicit_Packing --
8615 ----------------------
8617 -- pragma Implicit_Packing;
8619 when Pragma_Implicit_Packing =>
8621 Check_Arg_Count (0);
8622 Implicit_Packing := True;
8629 -- [Convention =>] convention_IDENTIFIER,
8630 -- [Entity =>] local_NAME
8631 -- [, [External_Name =>] static_string_EXPRESSION ]
8632 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8634 when Pragma_Import =>
8635 Check_Ada_83_Warning;
8641 Check_At_Least_N_Arguments (2);
8642 Check_At_Most_N_Arguments (4);
8643 Process_Import_Or_Interface;
8645 ----------------------
8646 -- Import_Exception --
8647 ----------------------
8649 -- pragma Import_Exception (
8650 -- [Internal =>] LOCAL_NAME
8651 -- [, [External =>] EXTERNAL_SYMBOL]
8652 -- [, [Form =>] Ada | VMS]
8653 -- [, [Code =>] static_integer_EXPRESSION]);
8655 when Pragma_Import_Exception => Import_Exception : declare
8656 Args : Args_List (1 .. 4);
8657 Names : constant Name_List (1 .. 4) := (
8663 Internal : Node_Id renames Args (1);
8664 External : Node_Id renames Args (2);
8665 Form : Node_Id renames Args (3);
8666 Code : Node_Id renames Args (4);
8670 Gather_Associations (Names, Args);
8672 if Present (External) and then Present (Code) then
8674 ("cannot give both External and Code options for pragma%");
8677 Process_Extended_Import_Export_Exception_Pragma (
8678 Arg_Internal => Internal,
8679 Arg_External => External,
8683 if not Is_VMS_Exception (Entity (Internal)) then
8684 Set_Imported (Entity (Internal));
8686 end Import_Exception;
8688 ---------------------
8689 -- Import_Function --
8690 ---------------------
8692 -- pragma Import_Function (
8693 -- [Internal =>] LOCAL_NAME,
8694 -- [, [External =>] EXTERNAL_SYMBOL]
8695 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8696 -- [, [Result_Type =>] SUBTYPE_MARK]
8697 -- [, [Mechanism =>] MECHANISM]
8698 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8699 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8701 -- EXTERNAL_SYMBOL ::=
8703 -- | static_string_EXPRESSION
8705 -- PARAMETER_TYPES ::=
8707 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8709 -- TYPE_DESIGNATOR ::=
8711 -- | subtype_Name ' Access
8715 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8717 -- MECHANISM_ASSOCIATION ::=
8718 -- [formal_parameter_NAME =>] MECHANISM_NAME
8720 -- MECHANISM_NAME ::=
8723 -- | Descriptor [([Class =>] CLASS_NAME)]
8725 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8727 when Pragma_Import_Function => Import_Function : declare
8728 Args : Args_List (1 .. 7);
8729 Names : constant Name_List (1 .. 7) := (
8732 Name_Parameter_Types,
8735 Name_Result_Mechanism,
8736 Name_First_Optional_Parameter);
8738 Internal : Node_Id renames Args (1);
8739 External : Node_Id renames Args (2);
8740 Parameter_Types : Node_Id renames Args (3);
8741 Result_Type : Node_Id renames Args (4);
8742 Mechanism : Node_Id renames Args (5);
8743 Result_Mechanism : Node_Id renames Args (6);
8744 First_Optional_Parameter : Node_Id renames Args (7);
8748 Gather_Associations (Names, Args);
8749 Process_Extended_Import_Export_Subprogram_Pragma (
8750 Arg_Internal => Internal,
8751 Arg_External => External,
8752 Arg_Parameter_Types => Parameter_Types,
8753 Arg_Result_Type => Result_Type,
8754 Arg_Mechanism => Mechanism,
8755 Arg_Result_Mechanism => Result_Mechanism,
8756 Arg_First_Optional_Parameter => First_Optional_Parameter);
8757 end Import_Function;
8763 -- pragma Import_Object (
8764 -- [Internal =>] LOCAL_NAME
8765 -- [, [External =>] EXTERNAL_SYMBOL]
8766 -- [, [Size =>] EXTERNAL_SYMBOL]);
8768 -- EXTERNAL_SYMBOL ::=
8770 -- | static_string_EXPRESSION
8772 when Pragma_Import_Object => Import_Object : declare
8773 Args : Args_List (1 .. 3);
8774 Names : constant Name_List (1 .. 3) := (
8779 Internal : Node_Id renames Args (1);
8780 External : Node_Id renames Args (2);
8781 Size : Node_Id renames Args (3);
8785 Gather_Associations (Names, Args);
8786 Process_Extended_Import_Export_Object_Pragma (
8787 Arg_Internal => Internal,
8788 Arg_External => External,
8792 ----------------------
8793 -- Import_Procedure --
8794 ----------------------
8796 -- pragma Import_Procedure (
8797 -- [Internal =>] LOCAL_NAME
8798 -- [, [External =>] EXTERNAL_SYMBOL]
8799 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8800 -- [, [Mechanism =>] MECHANISM]
8801 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8803 -- EXTERNAL_SYMBOL ::=
8805 -- | static_string_EXPRESSION
8807 -- PARAMETER_TYPES ::=
8809 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8811 -- TYPE_DESIGNATOR ::=
8813 -- | subtype_Name ' Access
8817 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8819 -- MECHANISM_ASSOCIATION ::=
8820 -- [formal_parameter_NAME =>] MECHANISM_NAME
8822 -- MECHANISM_NAME ::=
8825 -- | Descriptor [([Class =>] CLASS_NAME)]
8827 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8829 when Pragma_Import_Procedure => Import_Procedure : declare
8830 Args : Args_List (1 .. 5);
8831 Names : constant Name_List (1 .. 5) := (
8834 Name_Parameter_Types,
8836 Name_First_Optional_Parameter);
8838 Internal : Node_Id renames Args (1);
8839 External : Node_Id renames Args (2);
8840 Parameter_Types : Node_Id renames Args (3);
8841 Mechanism : Node_Id renames Args (4);
8842 First_Optional_Parameter : Node_Id renames Args (5);
8846 Gather_Associations (Names, Args);
8847 Process_Extended_Import_Export_Subprogram_Pragma (
8848 Arg_Internal => Internal,
8849 Arg_External => External,
8850 Arg_Parameter_Types => Parameter_Types,
8851 Arg_Mechanism => Mechanism,
8852 Arg_First_Optional_Parameter => First_Optional_Parameter);
8853 end Import_Procedure;
8855 -----------------------------
8856 -- Import_Valued_Procedure --
8857 -----------------------------
8859 -- pragma Import_Valued_Procedure (
8860 -- [Internal =>] LOCAL_NAME
8861 -- [, [External =>] EXTERNAL_SYMBOL]
8862 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8863 -- [, [Mechanism =>] MECHANISM]
8864 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8866 -- EXTERNAL_SYMBOL ::=
8868 -- | static_string_EXPRESSION
8870 -- PARAMETER_TYPES ::=
8872 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8874 -- TYPE_DESIGNATOR ::=
8876 -- | subtype_Name ' Access
8880 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8882 -- MECHANISM_ASSOCIATION ::=
8883 -- [formal_parameter_NAME =>] MECHANISM_NAME
8885 -- MECHANISM_NAME ::=
8888 -- | Descriptor [([Class =>] CLASS_NAME)]
8890 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8892 when Pragma_Import_Valued_Procedure =>
8893 Import_Valued_Procedure : declare
8894 Args : Args_List (1 .. 5);
8895 Names : constant Name_List (1 .. 5) := (
8898 Name_Parameter_Types,
8900 Name_First_Optional_Parameter);
8902 Internal : Node_Id renames Args (1);
8903 External : Node_Id renames Args (2);
8904 Parameter_Types : Node_Id renames Args (3);
8905 Mechanism : Node_Id renames Args (4);
8906 First_Optional_Parameter : Node_Id renames Args (5);
8910 Gather_Associations (Names, Args);
8911 Process_Extended_Import_Export_Subprogram_Pragma (
8912 Arg_Internal => Internal,
8913 Arg_External => External,
8914 Arg_Parameter_Types => Parameter_Types,
8915 Arg_Mechanism => Mechanism,
8916 Arg_First_Optional_Parameter => First_Optional_Parameter);
8917 end Import_Valued_Procedure;
8923 -- pragma Independent (LOCAL_NAME);
8925 when Pragma_Independent => Independent : declare
8932 Check_Ada_83_Warning;
8934 Check_No_Identifiers;
8935 Check_Arg_Count (1);
8936 Check_Arg_Is_Local_Name (Arg1);
8937 E_Id := Get_Pragma_Arg (Arg1);
8939 if Etype (E_Id) = Any_Type then
8944 D := Declaration_Node (E);
8947 -- Check duplicate before we chain ourselves!
8949 Check_Duplicate_Pragma (E);
8951 -- Check appropriate entity
8954 if Rep_Item_Too_Early (E, N)
8956 Rep_Item_Too_Late (E, N)
8960 Check_First_Subtype (Arg1);
8963 elsif K = N_Object_Declaration
8964 or else (K = N_Component_Declaration
8965 and then Original_Record_Component (E) = E)
8967 if Rep_Item_Too_Late (E, N) then
8973 ("inappropriate entity for pragma%", Arg1);
8976 Independence_Checks.Append ((N, E));
8979 ----------------------------
8980 -- Independent_Components --
8981 ----------------------------
8983 -- pragma Atomic_Components (array_LOCAL_NAME);
8985 -- This processing is shared by Volatile_Components
8987 when Pragma_Independent_Components => Independent_Components : declare
8994 Check_Ada_83_Warning;
8996 Check_No_Identifiers;
8997 Check_Arg_Count (1);
8998 Check_Arg_Is_Local_Name (Arg1);
8999 E_Id := Get_Pragma_Arg (Arg1);
9001 if Etype (E_Id) = Any_Type then
9007 -- Check duplicate before we chain ourselves!
9009 Check_Duplicate_Pragma (E);
9011 -- Check appropriate entity
9013 if Rep_Item_Too_Early (E, N)
9015 Rep_Item_Too_Late (E, N)
9020 D := Declaration_Node (E);
9023 if (K = N_Full_Type_Declaration
9024 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9026 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9027 and then Nkind (D) = N_Object_Declaration
9028 and then Nkind (Object_Definition (D)) =
9029 N_Constrained_Array_Definition)
9031 Independence_Checks.Append ((N, E));
9034 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9036 end Independent_Components;
9038 ------------------------
9039 -- Initialize_Scalars --
9040 ------------------------
9042 -- pragma Initialize_Scalars;
9044 when Pragma_Initialize_Scalars =>
9046 Check_Arg_Count (0);
9047 Check_Valid_Configuration_Pragma;
9048 Check_Restriction (No_Initialize_Scalars, N);
9050 -- Initialize_Scalars creates false positives in CodePeer,
9051 -- so ignore this pragma in this mode.
9053 if not Restriction_Active (No_Initialize_Scalars)
9054 and then not CodePeer_Mode
9056 Init_Or_Norm_Scalars := True;
9057 Initialize_Scalars := True;
9064 -- pragma Inline ( NAME {, NAME} );
9066 when Pragma_Inline =>
9068 -- Pragma is active if inlining option is active
9070 Process_Inline (Inline_Active);
9076 -- pragma Inline_Always ( NAME {, NAME} );
9078 when Pragma_Inline_Always =>
9081 -- Pragma always active unless in CodePeer mode, since this causes
9082 -- walk order issues.
9084 if not CodePeer_Mode then
9085 Process_Inline (True);
9088 --------------------
9089 -- Inline_Generic --
9090 --------------------
9092 -- pragma Inline_Generic (NAME {, NAME});
9094 when Pragma_Inline_Generic =>
9096 Process_Generic_List;
9098 ----------------------
9099 -- Inspection_Point --
9100 ----------------------
9102 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9104 when Pragma_Inspection_Point => Inspection_Point : declare
9109 if Arg_Count > 0 then
9112 Exp := Get_Pragma_Arg (Arg);
9115 if not Is_Entity_Name (Exp)
9116 or else not Is_Object (Entity (Exp))
9118 Error_Pragma_Arg ("object name required", Arg);
9125 end Inspection_Point;
9131 -- pragma Interface (
9132 -- [ Convention =>] convention_IDENTIFIER,
9133 -- [ Entity =>] local_NAME
9134 -- [, [External_Name =>] static_string_EXPRESSION ]
9135 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9137 when Pragma_Interface =>
9144 Check_At_Least_N_Arguments (2);
9145 Check_At_Most_N_Arguments (4);
9146 Process_Import_Or_Interface;
9148 -- In Ada 2005, the permission to use Interface (a reserved word)
9149 -- as a pragma name is considered an obsolescent feature.
9151 if Ada_Version >= Ada_2005 then
9153 (No_Obsolescent_Features, Pragma_Identifier (N));
9156 --------------------
9157 -- Interface_Name --
9158 --------------------
9160 -- pragma Interface_Name (
9161 -- [ Entity =>] local_NAME
9162 -- [,[External_Name =>] static_string_EXPRESSION ]
9163 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9165 when Pragma_Interface_Name => Interface_Name : declare
9174 ((Name_Entity, Name_External_Name, Name_Link_Name));
9175 Check_At_Least_N_Arguments (2);
9176 Check_At_Most_N_Arguments (3);
9177 Id := Get_Pragma_Arg (Arg1);
9180 if not Is_Entity_Name (Id) then
9182 ("first argument for pragma% must be entity name", Arg1);
9183 elsif Etype (Id) = Any_Type then
9186 Def_Id := Entity (Id);
9189 -- Special DEC-compatible processing for the object case, forces
9190 -- object to be imported.
9192 if Ekind (Def_Id) = E_Variable then
9193 Kill_Size_Check_Code (Def_Id);
9194 Note_Possible_Modification (Id, Sure => False);
9196 -- Initialization is not allowed for imported variable
9198 if Present (Expression (Parent (Def_Id)))
9199 and then Comes_From_Source (Expression (Parent (Def_Id)))
9201 Error_Msg_Sloc := Sloc (Def_Id);
9203 ("no initialization allowed for declaration of& #",
9207 -- For compatibility, support VADS usage of providing both
9208 -- pragmas Interface and Interface_Name to obtain the effect
9209 -- of a single Import pragma.
9211 if Is_Imported (Def_Id)
9212 and then Present (First_Rep_Item (Def_Id))
9213 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9215 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9219 Set_Imported (Def_Id);
9222 Set_Is_Public (Def_Id);
9223 Process_Interface_Name (Def_Id, Arg2, Arg3);
9226 -- Otherwise must be subprogram
9228 elsif not Is_Subprogram (Def_Id) then
9230 ("argument of pragma% is not subprogram", Arg1);
9233 Check_At_Most_N_Arguments (3);
9237 -- Loop through homonyms
9240 Def_Id := Get_Base_Subprogram (Hom_Id);
9242 if Is_Imported (Def_Id) then
9243 Process_Interface_Name (Def_Id, Arg2, Arg3);
9247 exit when From_Aspect_Specification (N);
9248 Hom_Id := Homonym (Hom_Id);
9250 exit when No (Hom_Id)
9251 or else Scope (Hom_Id) /= Current_Scope;
9256 ("argument of pragma% is not imported subprogram",
9262 -----------------------
9263 -- Interrupt_Handler --
9264 -----------------------
9266 -- pragma Interrupt_Handler (handler_NAME);
9268 when Pragma_Interrupt_Handler =>
9269 Check_Ada_83_Warning;
9270 Check_Arg_Count (1);
9271 Check_No_Identifiers;
9273 if No_Run_Time_Mode then
9274 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9276 Check_Interrupt_Or_Attach_Handler;
9277 Process_Interrupt_Or_Attach_Handler;
9280 ------------------------
9281 -- Interrupt_Priority --
9282 ------------------------
9284 -- pragma Interrupt_Priority [(EXPRESSION)];
9286 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9287 P : constant Node_Id := Parent (N);
9291 Check_Ada_83_Warning;
9293 if Arg_Count /= 0 then
9294 Arg := Get_Pragma_Arg (Arg1);
9295 Check_Arg_Count (1);
9296 Check_No_Identifiers;
9298 -- The expression must be analyzed in the special manner
9299 -- described in "Handling of Default and Per-Object
9300 -- Expressions" in sem.ads.
9302 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9305 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9309 elsif Has_Pragma_Priority (P) then
9310 Error_Pragma ("duplicate pragma% not allowed");
9313 Set_Has_Pragma_Priority (P, True);
9314 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9316 end Interrupt_Priority;
9318 ---------------------
9319 -- Interrupt_State --
9320 ---------------------
9322 -- pragma Interrupt_State (
9323 -- [Name =>] INTERRUPT_ID,
9324 -- [State =>] INTERRUPT_STATE);
9326 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9327 -- INTERRUPT_STATE => System | Runtime | User
9329 -- Note: if the interrupt id is given as an identifier, then it must
9330 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9331 -- given as a static integer expression which must be in the range of
9332 -- Ada.Interrupts.Interrupt_ID.
9334 when Pragma_Interrupt_State => Interrupt_State : declare
9336 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9337 -- This is the entity Ada.Interrupts.Interrupt_ID;
9339 State_Type : Character;
9340 -- Set to 's'/'r'/'u' for System/Runtime/User
9343 -- Index to entry in Interrupt_States table
9346 -- Value of interrupt
9348 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9349 -- The first argument to the pragma
9351 Int_Ent : Entity_Id;
9352 -- Interrupt entity in Ada.Interrupts.Names
9356 Check_Arg_Order ((Name_Name, Name_State));
9357 Check_Arg_Count (2);
9359 Check_Optional_Identifier (Arg1, Name_Name);
9360 Check_Optional_Identifier (Arg2, Name_State);
9361 Check_Arg_Is_Identifier (Arg2);
9363 -- First argument is identifier
9365 if Nkind (Arg1X) = N_Identifier then
9367 -- Search list of names in Ada.Interrupts.Names
9369 Int_Ent := First_Entity (RTE (RE_Names));
9371 if No (Int_Ent) then
9372 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9374 elsif Chars (Int_Ent) = Chars (Arg1X) then
9375 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9379 Next_Entity (Int_Ent);
9382 -- First argument is not an identifier, so it must be a static
9383 -- expression of type Ada.Interrupts.Interrupt_ID.
9386 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9387 Int_Val := Expr_Value (Arg1X);
9389 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9391 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9394 ("value not in range of type " &
9395 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9401 case Chars (Get_Pragma_Arg (Arg2)) is
9402 when Name_Runtime => State_Type := 'r';
9403 when Name_System => State_Type := 's';
9404 when Name_User => State_Type := 'u';
9407 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9410 -- Check if entry is already stored
9412 IST_Num := Interrupt_States.First;
9414 -- If entry not found, add it
9416 if IST_Num > Interrupt_States.Last then
9417 Interrupt_States.Append
9418 ((Interrupt_Number => UI_To_Int (Int_Val),
9419 Interrupt_State => State_Type,
9420 Pragma_Loc => Loc));
9423 -- Case of entry for the same entry
9425 elsif Int_Val = Interrupt_States.Table (IST_Num).
9428 -- If state matches, done, no need to make redundant entry
9431 State_Type = Interrupt_States.Table (IST_Num).
9434 -- Otherwise if state does not match, error
9437 Interrupt_States.Table (IST_Num).Pragma_Loc;
9439 ("state conflicts with that given #", Arg2);
9443 IST_Num := IST_Num + 1;
9445 end Interrupt_State;
9452 -- ([Entity =>] type_LOCAL_NAME,
9453 -- [Check =>] EXPRESSION
9454 -- [,[Message =>] String_Expression]);
9456 when Pragma_Invariant => Invariant : declare
9461 pragma Unreferenced (Discard);
9465 Check_At_Least_N_Arguments (2);
9466 Check_At_Most_N_Arguments (3);
9467 Check_Optional_Identifier (Arg1, Name_Entity);
9468 Check_Optional_Identifier (Arg2, Name_Check);
9470 if Arg_Count = 3 then
9471 Check_Optional_Identifier (Arg3, Name_Message);
9472 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9475 Check_Arg_Is_Local_Name (Arg1);
9477 Type_Id := Get_Pragma_Arg (Arg1);
9478 Find_Type (Type_Id);
9479 Typ := Entity (Type_Id);
9481 if Typ = Any_Type then
9484 elsif not Ekind_In (Typ, E_Private_Type,
9485 E_Record_Type_With_Private,
9486 E_Limited_Private_Type)
9489 ("pragma% only allowed for private type", Arg1);
9492 -- Note that the type has at least one invariant, and also that
9493 -- it has inheritable invariants if we have Invariant'Class.
9495 Set_Has_Invariants (Typ);
9497 if Class_Present (N) then
9498 Set_Has_Inheritable_Invariants (Typ);
9501 -- The remaining processing is simply to link the pragma on to
9502 -- the rep item chain, for processing when the type is frozen.
9503 -- This is accomplished by a call to Rep_Item_Too_Late.
9505 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9508 ----------------------
9509 -- Java_Constructor --
9510 ----------------------
9512 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9514 -- Also handles pragma CIL_Constructor
9516 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9517 Java_Constructor : declare
9518 Convention : Convention_Id;
9522 This_Formal : Entity_Id;
9526 Check_Arg_Count (1);
9527 Check_Optional_Identifier (Arg1, Name_Entity);
9528 Check_Arg_Is_Local_Name (Arg1);
9530 Id := Get_Pragma_Arg (Arg1);
9531 Find_Program_Unit_Name (Id);
9533 -- If we did not find the name, we are done
9535 if Etype (Id) = Any_Type then
9539 -- Check wrong use of pragma in wrong VM target
9541 if VM_Target = No_VM then
9544 elsif VM_Target = CLI_Target
9545 and then Prag_Id = Pragma_Java_Constructor
9547 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9549 elsif VM_Target = JVM_Target
9550 and then Prag_Id = Pragma_CIL_Constructor
9552 Error_Pragma ("must use pragma 'Java_'Constructor");
9556 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9557 when Pragma_Java_Constructor => Convention := Convention_Java;
9558 when others => null;
9561 Hom_Id := Entity (Id);
9563 -- Loop through homonyms
9566 Def_Id := Get_Base_Subprogram (Hom_Id);
9568 -- The constructor is required to be a function
9570 if Ekind (Def_Id) /= E_Function then
9571 if VM_Target = JVM_Target then
9573 ("pragma% requires function returning a " &
9574 "'Java access type", Def_Id);
9577 ("pragma% requires function returning a " &
9578 "'C'I'L access type", Def_Id);
9582 -- Check arguments: For tagged type the first formal must be
9583 -- named "this" and its type must be a named access type
9584 -- designating a class-wide tagged type that has convention
9585 -- CIL/Java. The first formal must also have a null default
9586 -- value. For example:
9588 -- type Typ is tagged ...
9589 -- type Ref is access all Typ;
9590 -- pragma Convention (CIL, Typ);
9592 -- function New_Typ (This : Ref) return Ref;
9593 -- function New_Typ (This : Ref; I : Integer) return Ref;
9594 -- pragma Cil_Constructor (New_Typ);
9596 -- Reason: The first formal must NOT be a primitive of the
9599 -- This rule also applies to constructors of delegates used
9600 -- to interface with standard target libraries. For example:
9602 -- type Delegate is access procedure ...
9603 -- pragma Import (CIL, Delegate, ...);
9605 -- function new_Delegate
9606 -- (This : Delegate := null; ... ) return Delegate;
9608 -- For value-types this rule does not apply.
9610 if not Is_Value_Type (Etype (Def_Id)) then
9611 if No (First_Formal (Def_Id)) then
9612 Error_Msg_Name_1 := Pname;
9613 Error_Msg_N ("% function must have parameters", Def_Id);
9617 -- In the JRE library we have several occurrences in which
9618 -- the "this" parameter is not the first formal.
9620 This_Formal := First_Formal (Def_Id);
9622 -- In the JRE library we have several occurrences in which
9623 -- the "this" parameter is not the first formal. Search for
9626 if VM_Target = JVM_Target then
9627 while Present (This_Formal)
9628 and then Get_Name_String (Chars (This_Formal)) /= "this"
9630 Next_Formal (This_Formal);
9633 if No (This_Formal) then
9634 This_Formal := First_Formal (Def_Id);
9638 -- Warning: The first parameter should be named "this".
9639 -- We temporarily allow it because we have the following
9640 -- case in the Java runtime (file s-osinte.ads) ???
9642 -- function new_Thread
9643 -- (Self_Id : System.Address) return Thread_Id;
9644 -- pragma Java_Constructor (new_Thread);
9646 if VM_Target = JVM_Target
9647 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9649 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9653 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9654 Error_Msg_Name_1 := Pname;
9656 ("first formal of % function must be named `this`",
9657 Parent (This_Formal));
9659 elsif not Is_Access_Type (Etype (This_Formal)) then
9660 Error_Msg_Name_1 := Pname;
9662 ("first formal of % function must be an access type",
9663 Parameter_Type (Parent (This_Formal)));
9665 -- For delegates the type of the first formal must be a
9666 -- named access-to-subprogram type (see previous example)
9668 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9669 and then Ekind (Etype (This_Formal))
9670 /= E_Access_Subprogram_Type
9672 Error_Msg_Name_1 := Pname;
9674 ("first formal of % function must be a named access" &
9675 " to subprogram type",
9676 Parameter_Type (Parent (This_Formal)));
9678 -- Warning: We should reject anonymous access types because
9679 -- the constructor must not be handled as a primitive of the
9680 -- tagged type. We temporarily allow it because this profile
9681 -- is currently generated by cil2ada???
9683 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9684 and then not Ekind_In (Etype (This_Formal),
9686 E_General_Access_Type,
9687 E_Anonymous_Access_Type)
9689 Error_Msg_Name_1 := Pname;
9691 ("first formal of % function must be a named access" &
9693 Parameter_Type (Parent (This_Formal)));
9695 elsif Atree.Convention
9696 (Designated_Type (Etype (This_Formal))) /= Convention
9698 Error_Msg_Name_1 := Pname;
9700 if Convention = Convention_Java then
9702 ("pragma% requires convention 'Cil in designated" &
9704 Parameter_Type (Parent (This_Formal)));
9707 ("pragma% requires convention 'Java in designated" &
9709 Parameter_Type (Parent (This_Formal)));
9712 elsif No (Expression (Parent (This_Formal)))
9713 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9715 Error_Msg_Name_1 := Pname;
9717 ("pragma% requires first formal with default `null`",
9718 Parameter_Type (Parent (This_Formal)));
9722 -- Check result type: the constructor must be a function
9724 -- * a value type (only allowed in the CIL compiler)
9725 -- * an access-to-subprogram type with convention Java/CIL
9726 -- * an access-type designating a type that has convention
9729 if Is_Value_Type (Etype (Def_Id)) then
9732 -- Access-to-subprogram type with convention Java/CIL
9734 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9735 if Atree.Convention (Etype (Def_Id)) /= Convention then
9736 if Convention = Convention_Java then
9738 ("pragma% requires function returning a " &
9739 "'Java access type", Arg1);
9741 pragma Assert (Convention = Convention_CIL);
9743 ("pragma% requires function returning a " &
9744 "'C'I'L access type", Arg1);
9748 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9749 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9750 E_General_Access_Type)
9753 (Designated_Type (Etype (Def_Id))) /= Convention
9755 Error_Msg_Name_1 := Pname;
9757 if Convention = Convention_Java then
9759 ("pragma% requires function returning a named" &
9760 "'Java access type", Arg1);
9763 ("pragma% requires function returning a named" &
9764 "'C'I'L access type", Arg1);
9769 Set_Is_Constructor (Def_Id);
9770 Set_Convention (Def_Id, Convention);
9771 Set_Is_Imported (Def_Id);
9773 exit when From_Aspect_Specification (N);
9774 Hom_Id := Homonym (Hom_Id);
9776 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9778 end Java_Constructor;
9780 ----------------------
9781 -- Java_Interface --
9782 ----------------------
9784 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9786 when Pragma_Java_Interface => Java_Interface : declare
9792 Check_Arg_Count (1);
9793 Check_Optional_Identifier (Arg1, Name_Entity);
9794 Check_Arg_Is_Local_Name (Arg1);
9796 Arg := Get_Pragma_Arg (Arg1);
9799 if Etype (Arg) = Any_Type then
9803 if not Is_Entity_Name (Arg)
9804 or else not Is_Type (Entity (Arg))
9806 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9809 Typ := Underlying_Type (Entity (Arg));
9811 -- For now simply check some of the semantic constraints on the
9812 -- type. This currently leaves out some restrictions on interface
9813 -- types, namely that the parent type must be java.lang.Object.Typ
9814 -- and that all primitives of the type should be declared
9817 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9818 Error_Pragma_Arg ("pragma% requires an abstract "
9819 & "tagged type", Arg1);
9821 elsif not Has_Discriminants (Typ)
9822 or else Ekind (Etype (First_Discriminant (Typ)))
9823 /= E_Anonymous_Access_Type
9825 not Is_Class_Wide_Type
9826 (Designated_Type (Etype (First_Discriminant (Typ))))
9829 ("type must have a class-wide access discriminant", Arg1);
9837 -- pragma Keep_Names ([On => ] local_NAME);
9839 when Pragma_Keep_Names => Keep_Names : declare
9844 Check_Arg_Count (1);
9845 Check_Optional_Identifier (Arg1, Name_On);
9846 Check_Arg_Is_Local_Name (Arg1);
9848 Arg := Get_Pragma_Arg (Arg1);
9851 if Etype (Arg) = Any_Type then
9855 if not Is_Entity_Name (Arg)
9856 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
9859 ("pragma% requires a local enumeration type", Arg1);
9862 Set_Discard_Names (Entity (Arg), False);
9869 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
9871 when Pragma_License =>
9873 Check_Arg_Count (1);
9874 Check_No_Identifiers;
9875 Check_Valid_Configuration_Pragma;
9876 Check_Arg_Is_Identifier (Arg1);
9879 Sind : constant Source_File_Index :=
9880 Source_Index (Current_Sem_Unit);
9883 case Chars (Get_Pragma_Arg (Arg1)) is
9885 Set_License (Sind, GPL);
9887 when Name_Modified_GPL =>
9888 Set_License (Sind, Modified_GPL);
9890 when Name_Restricted =>
9891 Set_License (Sind, Restricted);
9893 when Name_Unrestricted =>
9894 Set_License (Sind, Unrestricted);
9897 Error_Pragma_Arg ("invalid license name", Arg1);
9905 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
9907 when Pragma_Link_With => Link_With : declare
9913 if Operating_Mode = Generate_Code
9914 and then In_Extended_Main_Source_Unit (N)
9916 Check_At_Least_N_Arguments (1);
9917 Check_No_Identifiers;
9918 Check_Is_In_Decl_Part_Or_Package_Spec;
9919 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9923 while Present (Arg) loop
9924 Check_Arg_Is_Static_Expression (Arg, Standard_String);
9926 -- Store argument, converting sequences of spaces to a
9927 -- single null character (this is one of the differences
9928 -- in processing between Link_With and Linker_Options).
9931 C : constant Char_Code := Get_Char_Code (' ');
9932 S : constant String_Id :=
9933 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
9934 L : constant Nat := String_Length (S);
9937 procedure Skip_Spaces;
9938 -- Advance F past any spaces
9944 procedure Skip_Spaces is
9946 while F <= L and then Get_String_Char (S, F) = C loop
9951 -- Start of processing for Arg_Store
9954 Skip_Spaces; -- skip leading spaces
9956 -- Loop through characters, changing any embedded
9957 -- sequence of spaces to a single null character (this
9958 -- is how Link_With/Linker_Options differ)
9961 if Get_String_Char (S, F) = C then
9964 Store_String_Char (ASCII.NUL);
9967 Store_String_Char (Get_String_Char (S, F));
9975 if Present (Arg) then
9976 Store_String_Char (ASCII.NUL);
9980 Store_Linker_Option_String (End_String);
9988 -- pragma Linker_Alias (
9989 -- [Entity =>] LOCAL_NAME
9990 -- [Target =>] static_string_EXPRESSION);
9992 when Pragma_Linker_Alias =>
9994 Check_Arg_Order ((Name_Entity, Name_Target));
9995 Check_Arg_Count (2);
9996 Check_Optional_Identifier (Arg1, Name_Entity);
9997 Check_Optional_Identifier (Arg2, Name_Target);
9998 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9999 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10001 -- The only processing required is to link this item on to the
10002 -- list of rep items for the given entity. This is accomplished
10003 -- by the call to Rep_Item_Too_Late (when no error is detected
10004 -- and False is returned).
10006 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10009 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10012 ------------------------
10013 -- Linker_Constructor --
10014 ------------------------
10016 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10018 -- Code is shared with Linker_Destructor
10020 -----------------------
10021 -- Linker_Destructor --
10022 -----------------------
10024 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10026 when Pragma_Linker_Constructor |
10027 Pragma_Linker_Destructor =>
10028 Linker_Constructor : declare
10034 Check_Arg_Count (1);
10035 Check_No_Identifiers;
10036 Check_Arg_Is_Local_Name (Arg1);
10037 Arg1_X := Get_Pragma_Arg (Arg1);
10039 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10041 if not Is_Library_Level_Entity (Proc) then
10043 ("argument for pragma% must be library level entity", Arg1);
10046 -- The only processing required is to link this item on to the
10047 -- list of rep items for the given entity. This is accomplished
10048 -- by the call to Rep_Item_Too_Late (when no error is detected
10049 -- and False is returned).
10051 if Rep_Item_Too_Late (Proc, N) then
10054 Set_Has_Gigi_Rep_Item (Proc);
10056 end Linker_Constructor;
10058 --------------------
10059 -- Linker_Options --
10060 --------------------
10062 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10064 when Pragma_Linker_Options => Linker_Options : declare
10068 Check_Ada_83_Warning;
10069 Check_No_Identifiers;
10070 Check_Arg_Count (1);
10071 Check_Is_In_Decl_Part_Or_Package_Spec;
10072 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10073 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10076 while Present (Arg) loop
10077 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10078 Store_String_Char (ASCII.NUL);
10080 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10084 if Operating_Mode = Generate_Code
10085 and then In_Extended_Main_Source_Unit (N)
10087 Store_Linker_Option_String (End_String);
10089 end Linker_Options;
10091 --------------------
10092 -- Linker_Section --
10093 --------------------
10095 -- pragma Linker_Section (
10096 -- [Entity =>] LOCAL_NAME
10097 -- [Section =>] static_string_EXPRESSION);
10099 when Pragma_Linker_Section =>
10101 Check_Arg_Order ((Name_Entity, Name_Section));
10102 Check_Arg_Count (2);
10103 Check_Optional_Identifier (Arg1, Name_Entity);
10104 Check_Optional_Identifier (Arg2, Name_Section);
10105 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10106 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10108 -- This pragma applies only to objects
10110 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10111 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10114 -- The only processing required is to link this item on to the
10115 -- list of rep items for the given entity. This is accomplished
10116 -- by the call to Rep_Item_Too_Late (when no error is detected
10117 -- and False is returned).
10119 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10122 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10129 -- pragma List (On | Off)
10131 -- There is nothing to do here, since we did all the processing for
10132 -- this pragma in Par.Prag (so that it works properly even in syntax
10135 when Pragma_List =>
10138 --------------------
10139 -- Locking_Policy --
10140 --------------------
10142 -- pragma Locking_Policy (policy_IDENTIFIER);
10144 when Pragma_Locking_Policy => declare
10148 Check_Ada_83_Warning;
10149 Check_Arg_Count (1);
10150 Check_No_Identifiers;
10151 Check_Arg_Is_Locking_Policy (Arg1);
10152 Check_Valid_Configuration_Pragma;
10153 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10154 LP := Fold_Upper (Name_Buffer (1));
10156 if Locking_Policy /= ' '
10157 and then Locking_Policy /= LP
10159 Error_Msg_Sloc := Locking_Policy_Sloc;
10160 Error_Pragma ("locking policy incompatible with policy#");
10162 -- Set new policy, but always preserve System_Location since we
10163 -- like the error message with the run time name.
10166 Locking_Policy := LP;
10168 if Locking_Policy_Sloc /= System_Location then
10169 Locking_Policy_Sloc := Loc;
10178 -- pragma Long_Float (D_Float | G_Float);
10180 when Pragma_Long_Float =>
10182 Check_Valid_Configuration_Pragma;
10183 Check_Arg_Count (1);
10184 Check_No_Identifier (Arg1);
10185 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10187 if not OpenVMS_On_Target then
10188 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10193 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10194 if Opt.Float_Format_Long = 'G' then
10195 Error_Pragma ("G_Float previously specified");
10198 Opt.Float_Format_Long := 'D';
10200 -- G_Float case (this is the default, does not need overriding)
10203 if Opt.Float_Format_Long = 'D' then
10204 Error_Pragma ("D_Float previously specified");
10207 Opt.Float_Format_Long := 'G';
10210 Set_Standard_Fpt_Formats;
10212 -----------------------
10213 -- Machine_Attribute --
10214 -----------------------
10216 -- pragma Machine_Attribute (
10217 -- [Entity =>] LOCAL_NAME,
10218 -- [Attribute_Name =>] static_string_EXPRESSION
10219 -- [, [Info =>] static_EXPRESSION] );
10221 when Pragma_Machine_Attribute => Machine_Attribute : declare
10222 Def_Id : Entity_Id;
10226 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10228 if Arg_Count = 3 then
10229 Check_Optional_Identifier (Arg3, Name_Info);
10230 Check_Arg_Is_Static_Expression (Arg3);
10232 Check_Arg_Count (2);
10235 Check_Optional_Identifier (Arg1, Name_Entity);
10236 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10237 Check_Arg_Is_Local_Name (Arg1);
10238 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10239 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10241 if Is_Access_Type (Def_Id) then
10242 Def_Id := Designated_Type (Def_Id);
10245 if Rep_Item_Too_Early (Def_Id, N) then
10249 Def_Id := Underlying_Type (Def_Id);
10251 -- The only processing required is to link this item on to the
10252 -- list of rep items for the given entity. This is accomplished
10253 -- by the call to Rep_Item_Too_Late (when no error is detected
10254 -- and False is returned).
10256 if Rep_Item_Too_Late (Def_Id, N) then
10259 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10261 end Machine_Attribute;
10268 -- (MAIN_OPTION [, MAIN_OPTION]);
10271 -- [STACK_SIZE =>] static_integer_EXPRESSION
10272 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10273 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10275 when Pragma_Main => Main : declare
10276 Args : Args_List (1 .. 3);
10277 Names : constant Name_List (1 .. 3) := (
10279 Name_Task_Stack_Size_Default,
10280 Name_Time_Slicing_Enabled);
10286 Gather_Associations (Names, Args);
10288 for J in 1 .. 2 loop
10289 if Present (Args (J)) then
10290 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10294 if Present (Args (3)) then
10295 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10299 while Present (Nod) loop
10300 if Nkind (Nod) = N_Pragma
10301 and then Pragma_Name (Nod) = Name_Main
10303 Error_Msg_Name_1 := Pname;
10304 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10315 -- pragma Main_Storage
10316 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10318 -- MAIN_STORAGE_OPTION ::=
10319 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10320 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10322 when Pragma_Main_Storage => Main_Storage : declare
10323 Args : Args_List (1 .. 2);
10324 Names : constant Name_List (1 .. 2) := (
10325 Name_Working_Storage,
10332 Gather_Associations (Names, Args);
10334 for J in 1 .. 2 loop
10335 if Present (Args (J)) then
10336 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10340 Check_In_Main_Program;
10343 while Present (Nod) loop
10344 if Nkind (Nod) = N_Pragma
10345 and then Pragma_Name (Nod) = Name_Main_Storage
10347 Error_Msg_Name_1 := Pname;
10348 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10359 -- pragma Memory_Size (NUMERIC_LITERAL)
10361 when Pragma_Memory_Size =>
10364 -- Memory size is simply ignored
10366 Check_No_Identifiers;
10367 Check_Arg_Count (1);
10368 Check_Arg_Is_Integer_Literal (Arg1);
10376 -- The only correct use of this pragma is on its own in a file, in
10377 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10378 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10379 -- check for a file containing nothing but a No_Body pragma). If we
10380 -- attempt to process it during normal semantics processing, it means
10381 -- it was misplaced.
10383 when Pragma_No_Body =>
10391 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10393 when Pragma_No_Return => No_Return : declare
10401 Check_At_Least_N_Arguments (1);
10403 -- Loop through arguments of pragma
10406 while Present (Arg) loop
10407 Check_Arg_Is_Local_Name (Arg);
10408 Id := Get_Pragma_Arg (Arg);
10411 if not Is_Entity_Name (Id) then
10412 Error_Pragma_Arg ("entity name required", Arg);
10415 if Etype (Id) = Any_Type then
10419 -- Loop to find matching procedures
10424 and then Scope (E) = Current_Scope
10426 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10429 -- Set flag on any alias as well
10431 if Is_Overloadable (E) and then Present (Alias (E)) then
10432 Set_No_Return (Alias (E));
10438 exit when From_Aspect_Specification (N);
10443 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10454 -- pragma No_Run_Time;
10456 -- Note: this pragma is retained for backwards compatibility. See
10457 -- body of Rtsfind for full details on its handling.
10459 when Pragma_No_Run_Time =>
10461 Check_Valid_Configuration_Pragma;
10462 Check_Arg_Count (0);
10464 No_Run_Time_Mode := True;
10465 Configurable_Run_Time_Mode := True;
10467 -- Set Duration to 32 bits if word size is 32
10469 if Ttypes.System_Word_Size = 32 then
10470 Duration_32_Bits_On_Target := True;
10473 -- Set appropriate restrictions
10475 Set_Restriction (No_Finalization, N);
10476 Set_Restriction (No_Exception_Handlers, N);
10477 Set_Restriction (Max_Tasks, N, 0);
10478 Set_Restriction (No_Tasking, N);
10480 ------------------------
10481 -- No_Strict_Aliasing --
10482 ------------------------
10484 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10486 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10491 Check_At_Most_N_Arguments (1);
10493 if Arg_Count = 0 then
10494 Check_Valid_Configuration_Pragma;
10495 Opt.No_Strict_Aliasing := True;
10498 Check_Optional_Identifier (Arg2, Name_Entity);
10499 Check_Arg_Is_Local_Name (Arg1);
10500 E_Id := Entity (Get_Pragma_Arg (Arg1));
10502 if E_Id = Any_Type then
10504 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10505 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10508 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10510 end No_Strict_Aliasing;
10512 -----------------------
10513 -- Normalize_Scalars --
10514 -----------------------
10516 -- pragma Normalize_Scalars;
10518 when Pragma_Normalize_Scalars =>
10519 Check_Ada_83_Warning;
10520 Check_Arg_Count (0);
10521 Check_Valid_Configuration_Pragma;
10523 -- Normalize_Scalars creates false positives in CodePeer, so
10524 -- ignore this pragma in this mode.
10526 if not CodePeer_Mode then
10527 Normalize_Scalars := True;
10528 Init_Or_Norm_Scalars := True;
10535 -- pragma Obsolescent;
10537 -- pragma Obsolescent (
10538 -- [Message =>] static_string_EXPRESSION
10539 -- [,[Version =>] Ada_05]]);
10541 -- pragma Obsolescent (
10542 -- [Entity =>] NAME
10543 -- [,[Message =>] static_string_EXPRESSION
10544 -- [,[Version =>] Ada_05]] );
10546 when Pragma_Obsolescent => Obsolescent : declare
10550 procedure Set_Obsolescent (E : Entity_Id);
10551 -- Given an entity Ent, mark it as obsolescent if appropriate
10553 ---------------------
10554 -- Set_Obsolescent --
10555 ---------------------
10557 procedure Set_Obsolescent (E : Entity_Id) is
10566 -- Entity name was given
10568 if Present (Ename) then
10570 -- If entity name matches, we are fine. Save entity in
10571 -- pragma argument, for ASIS use.
10573 if Chars (Ename) = Chars (Ent) then
10574 Set_Entity (Ename, Ent);
10575 Generate_Reference (Ent, Ename);
10577 -- If entity name does not match, only possibility is an
10578 -- enumeration literal from an enumeration type declaration.
10580 elsif Ekind (Ent) /= E_Enumeration_Type then
10582 ("pragma % entity name does not match declaration");
10585 Ent := First_Literal (E);
10589 ("pragma % entity name does not match any " &
10590 "enumeration literal");
10592 elsif Chars (Ent) = Chars (Ename) then
10593 Set_Entity (Ename, Ent);
10594 Generate_Reference (Ent, Ename);
10598 Ent := Next_Literal (Ent);
10604 -- Ent points to entity to be marked
10606 if Arg_Count >= 1 then
10608 -- Deal with static string argument
10610 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10611 S := Strval (Get_Pragma_Arg (Arg1));
10613 for J in 1 .. String_Length (S) loop
10614 if not In_Character_Range (Get_String_Char (S, J)) then
10616 ("pragma% argument does not allow wide characters",
10621 Obsolescent_Warnings.Append
10622 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10624 -- Check for Ada_05 parameter
10626 if Arg_Count /= 1 then
10627 Check_Arg_Count (2);
10630 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10633 Check_Arg_Is_Identifier (Argx);
10635 if Chars (Argx) /= Name_Ada_05 then
10636 Error_Msg_Name_2 := Name_Ada_05;
10638 ("only allowed argument for pragma% is %", Argx);
10641 if Ada_Version_Explicit < Ada_2005
10642 or else not Warn_On_Ada_2005_Compatibility
10650 -- Set flag if pragma active
10653 Set_Is_Obsolescent (Ent);
10657 end Set_Obsolescent;
10659 -- Start of processing for pragma Obsolescent
10664 Check_At_Most_N_Arguments (3);
10666 -- See if first argument specifies an entity name
10670 (Chars (Arg1) = Name_Entity
10672 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10674 N_Operator_Symbol))
10676 Ename := Get_Pragma_Arg (Arg1);
10678 -- Eliminate first argument, so we can share processing
10682 Arg_Count := Arg_Count - 1;
10684 -- No Entity name argument given
10690 if Arg_Count >= 1 then
10691 Check_Optional_Identifier (Arg1, Name_Message);
10693 if Arg_Count = 2 then
10694 Check_Optional_Identifier (Arg2, Name_Version);
10698 -- Get immediately preceding declaration
10701 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10705 -- Cases where we do not follow anything other than another pragma
10709 -- First case: library level compilation unit declaration with
10710 -- the pragma immediately following the declaration.
10712 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10714 (Defining_Entity (Unit (Parent (Parent (N)))));
10717 -- Case 2: library unit placement for package
10721 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10723 if Is_Package_Or_Generic_Package (Ent) then
10724 Set_Obsolescent (Ent);
10730 -- Cases where we must follow a declaration
10733 if Nkind (Decl) not in N_Declaration
10734 and then Nkind (Decl) not in N_Later_Decl_Item
10735 and then Nkind (Decl) not in N_Generic_Declaration
10736 and then Nkind (Decl) not in N_Renaming_Declaration
10739 ("pragma% misplaced, "
10740 & "must immediately follow a declaration");
10743 Set_Obsolescent (Defining_Entity (Decl));
10753 -- pragma Optimize (Time | Space | Off);
10755 -- The actual check for optimize is done in Gigi. Note that this
10756 -- pragma does not actually change the optimization setting, it
10757 -- simply checks that it is consistent with the pragma.
10759 when Pragma_Optimize =>
10760 Check_No_Identifiers;
10761 Check_Arg_Count (1);
10762 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10764 ------------------------
10765 -- Optimize_Alignment --
10766 ------------------------
10768 -- pragma Optimize_Alignment (Time | Space | Off);
10770 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10772 Check_No_Identifiers;
10773 Check_Arg_Count (1);
10774 Check_Valid_Configuration_Pragma;
10777 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10781 Opt.Optimize_Alignment := 'T';
10783 Opt.Optimize_Alignment := 'S';
10785 Opt.Optimize_Alignment := 'O';
10787 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10791 -- Set indication that mode is set locally. If we are in fact in a
10792 -- configuration pragma file, this setting is harmless since the
10793 -- switch will get reset anyway at the start of each unit.
10795 Optimize_Alignment_Local := True;
10796 end Optimize_Alignment;
10802 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10804 when Pragma_Ordered => Ordered : declare
10805 Assoc : constant Node_Id := Arg1;
10811 Check_No_Identifiers;
10812 Check_Arg_Count (1);
10813 Check_Arg_Is_Local_Name (Arg1);
10815 Type_Id := Get_Pragma_Arg (Assoc);
10816 Find_Type (Type_Id);
10817 Typ := Entity (Type_Id);
10819 if Typ = Any_Type then
10822 Typ := Underlying_Type (Typ);
10825 if not Is_Enumeration_Type (Typ) then
10826 Error_Pragma ("pragma% must specify enumeration type");
10829 Check_First_Subtype (Arg1);
10830 Set_Has_Pragma_Ordered (Base_Type (Typ));
10837 -- pragma Pack (first_subtype_LOCAL_NAME);
10839 when Pragma_Pack => Pack : declare
10840 Assoc : constant Node_Id := Arg1;
10844 Ignore : Boolean := False;
10847 Check_No_Identifiers;
10848 Check_Arg_Count (1);
10849 Check_Arg_Is_Local_Name (Arg1);
10851 Type_Id := Get_Pragma_Arg (Assoc);
10852 Find_Type (Type_Id);
10853 Typ := Entity (Type_Id);
10856 or else Rep_Item_Too_Early (Typ, N)
10860 Typ := Underlying_Type (Typ);
10863 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
10864 Error_Pragma ("pragma% must specify array or record type");
10867 Check_First_Subtype (Arg1);
10868 Check_Duplicate_Pragma (Typ);
10872 if Is_Array_Type (Typ) then
10873 Ctyp := Component_Type (Typ);
10875 -- Ignore pack that does nothing
10877 if Known_Static_Esize (Ctyp)
10878 and then Known_Static_RM_Size (Ctyp)
10879 and then Esize (Ctyp) = RM_Size (Ctyp)
10880 and then Addressable (Esize (Ctyp))
10885 -- Process OK pragma Pack. Note that if there is a separate
10886 -- component clause present, the Pack will be cancelled. This
10887 -- processing is in Freeze.
10889 if not Rep_Item_Too_Late (Typ, N) then
10891 -- In the context of static code analysis, we do not need
10892 -- complex front-end expansions related to pragma Pack,
10893 -- so disable handling of pragma Pack in this case.
10895 if CodePeer_Mode then
10898 -- Don't attempt any packing for VM targets. We possibly
10899 -- could deal with some cases of array bit-packing, but we
10900 -- don't bother, since this is not a typical kind of
10901 -- representation in the VM context anyway (and would not
10902 -- for example work nicely with the debugger).
10904 elsif VM_Target /= No_VM then
10905 if not GNAT_Mode then
10907 ("?pragma% ignored in this configuration");
10910 -- Normal case where we do the pack action
10914 Set_Is_Packed (Base_Type (Typ), Sense);
10915 Set_Has_Non_Standard_Rep (Base_Type (Typ), Sense);
10918 Set_Has_Pragma_Pack (Base_Type (Typ), Sense);
10920 -- Complete reset action for Aspect_Cancel case
10922 if Sense = False then
10924 -- Cancel size unless explicitly set
10926 if not Has_Size_Clause (Typ)
10927 and then not Has_Object_Size_Clause (Typ)
10929 Set_Esize (Typ, Uint_0);
10930 Set_RM_Size (Typ, Uint_0);
10931 Set_Alignment (Typ, Uint_0);
10932 Set_Packed_Array_Type (Typ, Empty);
10935 -- Reset component size unless explicitly set
10937 if not Has_Component_Size_Clause (Typ) then
10938 if Known_Static_Esize (Ctyp)
10939 and then Known_Static_RM_Size (Ctyp)
10940 and then Esize (Ctyp) = RM_Size (Ctyp)
10941 and then Addressable (Esize (Ctyp))
10944 (Base_Type (Typ), Esize (Ctyp));
10947 (Base_Type (Typ), Uint_0);
10954 -- For record types, the pack is always effective
10956 else pragma Assert (Is_Record_Type (Typ));
10957 if not Rep_Item_Too_Late (Typ, N) then
10959 -- Ignore pack request with warning in VM mode (skip warning
10960 -- if we are compiling GNAT run time library).
10962 if VM_Target /= No_VM then
10963 if not GNAT_Mode then
10965 ("?pragma% ignored in this configuration");
10968 -- Normal case of pack request active
10971 Set_Is_Packed (Base_Type (Typ), Sense);
10972 Set_Has_Pragma_Pack (Base_Type (Typ), Sense);
10973 Set_Has_Non_Standard_Rep (Base_Type (Typ), Sense);
10975 -- Complete reset action for Aspect_Cancel case
10977 if Sense = False then
10979 -- Cancel size if not explicitly given
10981 if not Has_Size_Clause (Typ)
10982 and then not Has_Object_Size_Clause (Typ)
10984 Set_Esize (Typ, Uint_0);
10985 Set_Alignment (Typ, Uint_0);
10999 -- There is nothing to do here, since we did all the processing for
11000 -- this pragma in Par.Prag (so that it works properly even in syntax
11003 when Pragma_Page =>
11010 -- pragma Passive [(PASSIVE_FORM)];
11012 -- PASSIVE_FORM ::= Semaphore | No
11014 when Pragma_Passive =>
11017 if Nkind (Parent (N)) /= N_Task_Definition then
11018 Error_Pragma ("pragma% must be within task definition");
11021 if Arg_Count /= 0 then
11022 Check_Arg_Count (1);
11023 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11026 ----------------------------------
11027 -- Preelaborable_Initialization --
11028 ----------------------------------
11030 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11032 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11037 Check_Arg_Count (1);
11038 Check_No_Identifiers;
11039 Check_Arg_Is_Identifier (Arg1);
11040 Check_Arg_Is_Local_Name (Arg1);
11041 Check_First_Subtype (Arg1);
11042 Ent := Entity (Get_Pragma_Arg (Arg1));
11044 if not (Is_Private_Type (Ent)
11046 Is_Protected_Type (Ent)
11048 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11051 ("pragma % can only be applied to private, formal derived or "
11052 & "protected type",
11056 -- Give an error if the pragma is applied to a protected type that
11057 -- does not qualify (due to having entries, or due to components
11058 -- that do not qualify).
11060 if Is_Protected_Type (Ent)
11061 and then not Has_Preelaborable_Initialization (Ent)
11064 ("protected type & does not have preelaborable " &
11065 "initialization", Ent);
11067 -- Otherwise mark the type as definitely having preelaborable
11071 Set_Known_To_Have_Preelab_Init (Ent);
11074 if Has_Pragma_Preelab_Init (Ent)
11075 and then Warn_On_Redundant_Constructs
11077 Error_Pragma ("?duplicate pragma%!");
11079 Set_Has_Pragma_Preelab_Init (Ent);
11083 --------------------
11084 -- Persistent_BSS --
11085 --------------------
11087 -- pragma Persistent_BSS [(object_NAME)];
11089 when Pragma_Persistent_BSS => Persistent_BSS : declare
11096 Check_At_Most_N_Arguments (1);
11098 -- Case of application to specific object (one argument)
11100 if Arg_Count = 1 then
11101 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11103 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11105 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11108 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11111 Ent := Entity (Get_Pragma_Arg (Arg1));
11112 Decl := Parent (Ent);
11114 if Rep_Item_Too_Late (Ent, N) then
11118 if Present (Expression (Decl)) then
11120 ("object for pragma% cannot have initialization", Arg1);
11123 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11125 ("object type for pragma% is not potentially persistent",
11129 Check_Duplicate_Pragma (Ent);
11133 Make_Linker_Section_Pragma
11134 (Ent, Sloc (N), ".persistent.bss");
11135 Insert_After (N, Prag);
11139 -- Case of use as configuration pragma with no arguments
11142 Check_Valid_Configuration_Pragma;
11143 Persistent_BSS_Mode := True;
11145 end Persistent_BSS;
11151 -- pragma Polling (ON | OFF);
11153 when Pragma_Polling =>
11155 Check_Arg_Count (1);
11156 Check_No_Identifiers;
11157 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11158 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11160 -------------------
11161 -- Postcondition --
11162 -------------------
11164 -- pragma Postcondition ([Check =>] Boolean_Expression
11165 -- [,[Message =>] String_Expression]);
11167 when Pragma_Postcondition => Postcondition : declare
11169 pragma Warnings (Off, In_Body);
11173 Check_At_Least_N_Arguments (1);
11174 Check_At_Most_N_Arguments (2);
11175 Check_Optional_Identifier (Arg1, Name_Check);
11177 -- All we need to do here is call the common check procedure,
11178 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11180 Check_Precondition_Postcondition (In_Body);
11187 -- pragma Precondition ([Check =>] Boolean_Expression
11188 -- [,[Message =>] String_Expression]);
11190 when Pragma_Precondition => Precondition : declare
11195 Check_At_Least_N_Arguments (1);
11196 Check_At_Most_N_Arguments (2);
11197 Check_Optional_Identifier (Arg1, Name_Check);
11198 Check_Precondition_Postcondition (In_Body);
11200 -- If in spec, nothing more to do. If in body, then we convert the
11201 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11202 -- this whether or not precondition checks are enabled. That works
11203 -- fine since pragma Check will do this check, and will also
11204 -- analyze the condition itself in the proper context.
11209 Chars => Name_Check,
11210 Pragma_Argument_Associations => New_List (
11211 Make_Pragma_Argument_Association (Loc,
11213 Make_Identifier (Loc,
11214 Chars => Name_Precondition)),
11216 Make_Pragma_Argument_Association (Sloc (Arg1),
11217 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11219 if Arg_Count = 2 then
11220 Append_To (Pragma_Argument_Associations (N),
11221 Make_Pragma_Argument_Association (Sloc (Arg2),
11222 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11233 -- pragma Predicate
11234 -- ([Entity =>] type_LOCAL_NAME,
11235 -- [Check =>] EXPRESSION);
11237 when Pragma_Predicate => Predicate : declare
11242 pragma Unreferenced (Discard);
11246 Check_Arg_Count (2);
11247 Check_Optional_Identifier (Arg1, Name_Entity);
11248 Check_Optional_Identifier (Arg2, Name_Check);
11250 Check_Arg_Is_Local_Name (Arg1);
11252 Type_Id := Get_Pragma_Arg (Arg1);
11253 Find_Type (Type_Id);
11254 Typ := Entity (Type_Id);
11256 if Typ = Any_Type then
11260 -- The remaining processing is simply to link the pragma on to
11261 -- the rep item chain, for processing when the type is frozen.
11262 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11263 -- mark the type as having predicates.
11265 Set_Has_Predicates (Typ);
11266 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11273 -- pragma Preelaborate [(library_unit_NAME)];
11275 -- Set the flag Is_Preelaborated of program unit name entity
11277 when Pragma_Preelaborate => Preelaborate : declare
11278 Pa : constant Node_Id := Parent (N);
11279 Pk : constant Node_Kind := Nkind (Pa);
11283 Check_Ada_83_Warning;
11284 Check_Valid_Library_Unit_Pragma;
11286 if Nkind (N) = N_Null_Statement then
11290 Ent := Find_Lib_Unit_Name;
11291 Check_Duplicate_Pragma (Ent);
11293 -- This filters out pragmas inside generic parent then
11294 -- show up inside instantiation
11297 and then not (Pk = N_Package_Specification
11298 and then Present (Generic_Parent (Pa)))
11300 if not Debug_Flag_U then
11301 Set_Is_Preelaborated (Ent, Sense);
11302 Set_Suppress_Elaboration_Warnings (Ent, Sense);
11307 ---------------------
11308 -- Preelaborate_05 --
11309 ---------------------
11311 -- pragma Preelaborate_05 [(library_unit_NAME)];
11313 -- This pragma is useable only in GNAT_Mode, where it is used like
11314 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11315 -- (otherwise it is ignored). This is used to implement AI-362 which
11316 -- recategorizes some run-time packages in Ada 2005 mode.
11318 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11323 Check_Valid_Library_Unit_Pragma;
11325 if not GNAT_Mode then
11326 Error_Pragma ("pragma% only available in GNAT mode");
11329 if Nkind (N) = N_Null_Statement then
11333 -- This is one of the few cases where we need to test the value of
11334 -- Ada_Version_Explicit rather than Ada_Version (which is always
11335 -- set to Ada_2012 in a predefined unit), we need to know the
11336 -- explicit version set to know if this pragma is active.
11338 if Ada_Version_Explicit >= Ada_2005 then
11339 Ent := Find_Lib_Unit_Name;
11340 Set_Is_Preelaborated (Ent);
11341 Set_Suppress_Elaboration_Warnings (Ent);
11343 end Preelaborate_05;
11349 -- pragma Priority (EXPRESSION);
11351 when Pragma_Priority => Priority : declare
11352 P : constant Node_Id := Parent (N);
11356 Check_No_Identifiers;
11357 Check_Arg_Count (1);
11361 if Nkind (P) = N_Subprogram_Body then
11362 Check_In_Main_Program;
11364 Arg := Get_Pragma_Arg (Arg1);
11365 Analyze_And_Resolve (Arg, Standard_Integer);
11369 if not Is_Static_Expression (Arg) then
11370 Flag_Non_Static_Expr
11371 ("main subprogram priority is not static!", Arg);
11374 -- If constraint error, then we already signalled an error
11376 elsif Raises_Constraint_Error (Arg) then
11379 -- Otherwise check in range
11383 Val : constant Uint := Expr_Value (Arg);
11387 or else Val > Expr_Value (Expression
11388 (Parent (RTE (RE_Max_Priority))))
11391 ("main subprogram priority is out of range", Arg1);
11397 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11399 -- Load an arbitrary entity from System.Tasking to make sure
11400 -- this package is implicitly with'ed, since we need to have
11401 -- the tasking run-time active for the pragma Priority to have
11405 Discard : Entity_Id;
11406 pragma Warnings (Off, Discard);
11408 Discard := RTE (RE_Task_List);
11411 -- Task or Protected, must be of type Integer
11413 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11414 Arg := Get_Pragma_Arg (Arg1);
11416 -- The expression must be analyzed in the special manner
11417 -- described in "Handling of Default and Per-Object
11418 -- Expressions" in sem.ads.
11420 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11422 if not Is_Static_Expression (Arg) then
11423 Check_Restriction (Static_Priorities, Arg);
11426 -- Anything else is incorrect
11432 if Has_Pragma_Priority (P) then
11433 Error_Pragma ("duplicate pragma% not allowed");
11435 Set_Has_Pragma_Priority (P, True);
11437 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11438 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11439 -- exp_ch9 should use this ???
11444 -----------------------------------
11445 -- Priority_Specific_Dispatching --
11446 -----------------------------------
11448 -- pragma Priority_Specific_Dispatching (
11449 -- policy_IDENTIFIER,
11450 -- first_priority_EXPRESSION,
11451 -- last_priority_EXPRESSION);
11453 when Pragma_Priority_Specific_Dispatching =>
11454 Priority_Specific_Dispatching : declare
11455 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11456 -- This is the entity System.Any_Priority;
11459 Lower_Bound : Node_Id;
11460 Upper_Bound : Node_Id;
11466 Check_Arg_Count (3);
11467 Check_No_Identifiers;
11468 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11469 Check_Valid_Configuration_Pragma;
11470 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11471 DP := Fold_Upper (Name_Buffer (1));
11473 Lower_Bound := Get_Pragma_Arg (Arg2);
11474 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11475 Lower_Val := Expr_Value (Lower_Bound);
11477 Upper_Bound := Get_Pragma_Arg (Arg3);
11478 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11479 Upper_Val := Expr_Value (Upper_Bound);
11481 -- It is not allowed to use Task_Dispatching_Policy and
11482 -- Priority_Specific_Dispatching in the same partition.
11484 if Task_Dispatching_Policy /= ' ' then
11485 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11487 ("pragma% incompatible with Task_Dispatching_Policy#");
11489 -- Check lower bound in range
11491 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11493 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11496 ("first_priority is out of range", Arg2);
11498 -- Check upper bound in range
11500 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11502 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11505 ("last_priority is out of range", Arg3);
11507 -- Check that the priority range is valid
11509 elsif Lower_Val > Upper_Val then
11511 ("last_priority_expression must be greater than" &
11512 " or equal to first_priority_expression");
11514 -- Store the new policy, but always preserve System_Location since
11515 -- we like the error message with the run-time name.
11518 -- Check overlapping in the priority ranges specified in other
11519 -- Priority_Specific_Dispatching pragmas within the same
11520 -- partition. We can only check those we know about!
11523 Specific_Dispatching.First .. Specific_Dispatching.Last
11525 if Specific_Dispatching.Table (J).First_Priority in
11526 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11527 or else Specific_Dispatching.Table (J).Last_Priority in
11528 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11531 Specific_Dispatching.Table (J).Pragma_Loc;
11533 ("priority range overlaps with "
11534 & "Priority_Specific_Dispatching#");
11538 -- The use of Priority_Specific_Dispatching is incompatible
11539 -- with Task_Dispatching_Policy.
11541 if Task_Dispatching_Policy /= ' ' then
11542 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11544 ("Priority_Specific_Dispatching incompatible "
11545 & "with Task_Dispatching_Policy#");
11548 -- The use of Priority_Specific_Dispatching forces ceiling
11551 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11552 Error_Msg_Sloc := Locking_Policy_Sloc;
11554 ("Priority_Specific_Dispatching incompatible "
11555 & "with Locking_Policy#");
11557 -- Set the Ceiling_Locking policy, but preserve System_Location
11558 -- since we like the error message with the run time name.
11561 Locking_Policy := 'C';
11563 if Locking_Policy_Sloc /= System_Location then
11564 Locking_Policy_Sloc := Loc;
11568 -- Add entry in the table
11570 Specific_Dispatching.Append
11571 ((Dispatching_Policy => DP,
11572 First_Priority => UI_To_Int (Lower_Val),
11573 Last_Priority => UI_To_Int (Upper_Val),
11574 Pragma_Loc => Loc));
11576 end Priority_Specific_Dispatching;
11582 -- pragma Profile (profile_IDENTIFIER);
11584 -- profile_IDENTIFIER => Restricted | Ravenscar
11586 when Pragma_Profile =>
11588 Check_Arg_Count (1);
11589 Check_Valid_Configuration_Pragma;
11590 Check_No_Identifiers;
11593 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11595 if Chars (Argx) = Name_Ravenscar then
11596 Set_Ravenscar_Profile (N);
11597 elsif Chars (Argx) = Name_Restricted then
11598 Set_Profile_Restrictions
11599 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11601 Error_Pragma_Arg ("& is not a valid profile", Argx);
11605 ----------------------
11606 -- Profile_Warnings --
11607 ----------------------
11609 -- pragma Profile_Warnings (profile_IDENTIFIER);
11611 -- profile_IDENTIFIER => Restricted | Ravenscar
11613 when Pragma_Profile_Warnings =>
11615 Check_Arg_Count (1);
11616 Check_Valid_Configuration_Pragma;
11617 Check_No_Identifiers;
11620 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11622 if Chars (Argx) = Name_Ravenscar then
11623 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11624 elsif Chars (Argx) = Name_Restricted then
11625 Set_Profile_Restrictions (Restricted, N, Warn => True);
11627 Error_Pragma_Arg ("& is not a valid profile", Argx);
11631 --------------------------
11632 -- Propagate_Exceptions --
11633 --------------------------
11635 -- pragma Propagate_Exceptions;
11637 -- Note: this pragma is obsolete and has no effect
11639 when Pragma_Propagate_Exceptions =>
11641 Check_Arg_Count (0);
11643 if In_Extended_Main_Source_Unit (N) then
11644 Propagate_Exceptions := True;
11651 -- pragma Psect_Object (
11652 -- [Internal =>] LOCAL_NAME,
11653 -- [, [External =>] EXTERNAL_SYMBOL]
11654 -- [, [Size =>] EXTERNAL_SYMBOL]);
11656 when Pragma_Psect_Object | Pragma_Common_Object =>
11657 Psect_Object : declare
11658 Args : Args_List (1 .. 3);
11659 Names : constant Name_List (1 .. 3) := (
11664 Internal : Node_Id renames Args (1);
11665 External : Node_Id renames Args (2);
11666 Size : Node_Id renames Args (3);
11668 Def_Id : Entity_Id;
11670 procedure Check_Too_Long (Arg : Node_Id);
11671 -- Posts message if the argument is an identifier with more
11672 -- than 31 characters, or a string literal with more than
11673 -- 31 characters, and we are operating under VMS
11675 --------------------
11676 -- Check_Too_Long --
11677 --------------------
11679 procedure Check_Too_Long (Arg : Node_Id) is
11680 X : constant Node_Id := Original_Node (Arg);
11683 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11685 ("inappropriate argument for pragma %", Arg);
11688 if OpenVMS_On_Target then
11689 if (Nkind (X) = N_String_Literal
11690 and then String_Length (Strval (X)) > 31)
11692 (Nkind (X) = N_Identifier
11693 and then Length_Of_Name (Chars (X)) > 31)
11696 ("argument for pragma % is longer than 31 characters",
11700 end Check_Too_Long;
11702 -- Start of processing for Common_Object/Psect_Object
11706 Gather_Associations (Names, Args);
11707 Process_Extended_Import_Export_Internal_Arg (Internal);
11709 Def_Id := Entity (Internal);
11711 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11713 ("pragma% must designate an object", Internal);
11716 Check_Too_Long (Internal);
11718 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11720 ("cannot use pragma% for imported/exported object",
11724 if Is_Concurrent_Type (Etype (Internal)) then
11726 ("cannot specify pragma % for task/protected object",
11730 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11732 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11734 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11737 if Ekind (Def_Id) = E_Constant then
11739 ("cannot specify pragma % for a constant", Internal);
11742 if Is_Record_Type (Etype (Internal)) then
11748 Ent := First_Entity (Etype (Internal));
11749 while Present (Ent) loop
11750 Decl := Declaration_Node (Ent);
11752 if Ekind (Ent) = E_Component
11753 and then Nkind (Decl) = N_Component_Declaration
11754 and then Present (Expression (Decl))
11755 and then Warn_On_Export_Import
11758 ("?object for pragma % has defaults", Internal);
11768 if Present (Size) then
11769 Check_Too_Long (Size);
11772 if Present (External) then
11773 Check_Arg_Is_External_Name (External);
11774 Check_Too_Long (External);
11777 -- If all error tests pass, link pragma on to the rep item chain
11779 Record_Rep_Item (Def_Id, N);
11786 -- pragma Pure [(library_unit_NAME)];
11788 when Pragma_Pure => Pure : declare
11792 Check_Ada_83_Warning;
11793 Check_Valid_Library_Unit_Pragma;
11795 if Nkind (N) = N_Null_Statement then
11799 Ent := Find_Lib_Unit_Name;
11801 Set_Has_Pragma_Pure (Ent);
11802 Set_Suppress_Elaboration_Warnings (Ent);
11809 -- pragma Pure_05 [(library_unit_NAME)];
11811 -- This pragma is useable only in GNAT_Mode, where it is used like
11812 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11813 -- it is ignored). It may be used after a pragma Preelaborate, in
11814 -- which case it overrides the effect of the pragma Preelaborate.
11815 -- This is used to implement AI-362 which recategorizes some run-time
11816 -- packages in Ada 2005 mode.
11818 when Pragma_Pure_05 => Pure_05 : declare
11823 Check_Valid_Library_Unit_Pragma;
11825 if not GNAT_Mode then
11826 Error_Pragma ("pragma% only available in GNAT mode");
11829 if Nkind (N) = N_Null_Statement then
11833 -- This is one of the few cases where we need to test the value of
11834 -- Ada_Version_Explicit rather than Ada_Version (which is always
11835 -- set to Ada_2012 in a predefined unit), we need to know the
11836 -- explicit version set to know if this pragma is active.
11838 if Ada_Version_Explicit >= Ada_2005 then
11839 Ent := Find_Lib_Unit_Name;
11840 Set_Is_Preelaborated (Ent, False);
11842 Set_Suppress_Elaboration_Warnings (Ent);
11846 -------------------
11847 -- Pure_Function --
11848 -------------------
11850 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11852 when Pragma_Pure_Function => Pure_Function : declare
11855 Def_Id : Entity_Id;
11856 Effective : Boolean := False;
11860 Check_Arg_Count (1);
11861 Check_Optional_Identifier (Arg1, Name_Entity);
11862 Check_Arg_Is_Local_Name (Arg1);
11863 E_Id := Get_Pragma_Arg (Arg1);
11865 if Error_Posted (E_Id) then
11869 -- Loop through homonyms (overloadings) of referenced entity
11871 E := Entity (E_Id);
11873 if Present (E) then
11875 Def_Id := Get_Base_Subprogram (E);
11877 if not Ekind_In (Def_Id, E_Function,
11878 E_Generic_Function,
11882 ("pragma% requires a function name", Arg1);
11885 Set_Is_Pure (Def_Id, Sense);
11887 if not Has_Pragma_Pure_Function (Def_Id) then
11888 Set_Has_Pragma_Pure_Function (Def_Id, Sense);
11889 Effective := Sense;
11892 exit when From_Aspect_Specification (N);
11894 exit when No (E) or else Scope (E) /= Current_Scope;
11897 if Sense and then not Effective
11898 and then Warn_On_Redundant_Constructs
11901 ("pragma Pure_Function on& is redundant?",
11907 --------------------
11908 -- Queuing_Policy --
11909 --------------------
11911 -- pragma Queuing_Policy (policy_IDENTIFIER);
11913 when Pragma_Queuing_Policy => declare
11917 Check_Ada_83_Warning;
11918 Check_Arg_Count (1);
11919 Check_No_Identifiers;
11920 Check_Arg_Is_Queuing_Policy (Arg1);
11921 Check_Valid_Configuration_Pragma;
11922 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11923 QP := Fold_Upper (Name_Buffer (1));
11925 if Queuing_Policy /= ' '
11926 and then Queuing_Policy /= QP
11928 Error_Msg_Sloc := Queuing_Policy_Sloc;
11929 Error_Pragma ("queuing policy incompatible with policy#");
11931 -- Set new policy, but always preserve System_Location since we
11932 -- like the error message with the run time name.
11935 Queuing_Policy := QP;
11937 if Queuing_Policy_Sloc /= System_Location then
11938 Queuing_Policy_Sloc := Loc;
11943 -----------------------
11944 -- Relative_Deadline --
11945 -----------------------
11947 -- pragma Relative_Deadline (time_span_EXPRESSION);
11949 when Pragma_Relative_Deadline => Relative_Deadline : declare
11950 P : constant Node_Id := Parent (N);
11955 Check_No_Identifiers;
11956 Check_Arg_Count (1);
11958 Arg := Get_Pragma_Arg (Arg1);
11960 -- The expression must be analyzed in the special manner described
11961 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
11963 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
11967 if Nkind (P) = N_Subprogram_Body then
11968 Check_In_Main_Program;
11972 elsif Nkind (P) = N_Task_Definition then
11975 -- Anything else is incorrect
11981 if Has_Relative_Deadline_Pragma (P) then
11982 Error_Pragma ("duplicate pragma% not allowed");
11984 Set_Has_Relative_Deadline_Pragma (P, True);
11986 if Nkind (P) = N_Task_Definition then
11987 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11990 end Relative_Deadline;
11992 ---------------------------
11993 -- Remote_Call_Interface --
11994 ---------------------------
11996 -- pragma Remote_Call_Interface [(library_unit_NAME)];
11998 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
11999 Cunit_Node : Node_Id;
12000 Cunit_Ent : Entity_Id;
12004 Check_Ada_83_Warning;
12005 Check_Valid_Library_Unit_Pragma;
12007 if Nkind (N) = N_Null_Statement then
12011 Cunit_Node := Cunit (Current_Sem_Unit);
12012 K := Nkind (Unit (Cunit_Node));
12013 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12015 if K = N_Package_Declaration
12016 or else K = N_Generic_Package_Declaration
12017 or else K = N_Subprogram_Declaration
12018 or else K = N_Generic_Subprogram_Declaration
12019 or else (K = N_Subprogram_Body
12020 and then Acts_As_Spec (Unit (Cunit_Node)))
12025 "pragma% must apply to package or subprogram declaration");
12028 Set_Is_Remote_Call_Interface (Cunit_Ent);
12029 end Remote_Call_Interface;
12035 -- pragma Remote_Types [(library_unit_NAME)];
12037 when Pragma_Remote_Types => Remote_Types : declare
12038 Cunit_Node : Node_Id;
12039 Cunit_Ent : Entity_Id;
12042 Check_Ada_83_Warning;
12043 Check_Valid_Library_Unit_Pragma;
12045 if Nkind (N) = N_Null_Statement then
12049 Cunit_Node := Cunit (Current_Sem_Unit);
12050 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12052 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12053 N_Generic_Package_Declaration)
12056 ("pragma% can only apply to a package declaration");
12059 Set_Is_Remote_Types (Cunit_Ent);
12066 -- pragma Ravenscar;
12068 when Pragma_Ravenscar =>
12070 Check_Arg_Count (0);
12071 Check_Valid_Configuration_Pragma;
12072 Set_Ravenscar_Profile (N);
12074 if Warn_On_Obsolescent_Feature then
12075 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12076 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12079 -------------------------
12080 -- Restricted_Run_Time --
12081 -------------------------
12083 -- pragma Restricted_Run_Time;
12085 when Pragma_Restricted_Run_Time =>
12087 Check_Arg_Count (0);
12088 Check_Valid_Configuration_Pragma;
12089 Set_Profile_Restrictions
12090 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12092 if Warn_On_Obsolescent_Feature then
12094 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12095 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12102 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12105 -- restriction_IDENTIFIER
12106 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12108 when Pragma_Restrictions =>
12109 Process_Restrictions_Or_Restriction_Warnings
12110 (Warn => Treat_Restrictions_As_Warnings);
12112 --------------------------
12113 -- Restriction_Warnings --
12114 --------------------------
12116 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12119 -- restriction_IDENTIFIER
12120 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12122 when Pragma_Restriction_Warnings =>
12124 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12130 -- pragma Reviewable;
12132 when Pragma_Reviewable =>
12133 Check_Ada_83_Warning;
12134 Check_Arg_Count (0);
12136 -- Call dummy debugging function rv. This is done to assist front
12137 -- end debugging. By placing a Reviewable pragma in the source
12138 -- program, a breakpoint on rv catches this place in the source,
12139 -- allowing convenient stepping to the point of interest.
12143 --------------------------
12144 -- Short_Circuit_And_Or --
12145 --------------------------
12147 when Pragma_Short_Circuit_And_Or =>
12149 Check_Arg_Count (0);
12150 Check_Valid_Configuration_Pragma;
12151 Short_Circuit_And_Or := True;
12153 -------------------
12154 -- Share_Generic --
12155 -------------------
12157 -- pragma Share_Generic (NAME {, NAME});
12159 when Pragma_Share_Generic =>
12161 Process_Generic_List;
12167 -- pragma Shared (LOCAL_NAME);
12169 when Pragma_Shared =>
12171 Process_Atomic_Shared_Volatile;
12173 --------------------
12174 -- Shared_Passive --
12175 --------------------
12177 -- pragma Shared_Passive [(library_unit_NAME)];
12179 -- Set the flag Is_Shared_Passive of program unit name entity
12181 when Pragma_Shared_Passive => Shared_Passive : declare
12182 Cunit_Node : Node_Id;
12183 Cunit_Ent : Entity_Id;
12186 Check_Ada_83_Warning;
12187 Check_Valid_Library_Unit_Pragma;
12189 if Nkind (N) = N_Null_Statement then
12193 Cunit_Node := Cunit (Current_Sem_Unit);
12194 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12196 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12197 N_Generic_Package_Declaration)
12200 ("pragma% can only apply to a package declaration");
12203 Set_Is_Shared_Passive (Cunit_Ent);
12204 end Shared_Passive;
12206 -----------------------
12207 -- Short_Descriptors --
12208 -----------------------
12210 -- pragma Short_Descriptors;
12212 when Pragma_Short_Descriptors =>
12214 Check_Arg_Count (0);
12215 Check_Valid_Configuration_Pragma;
12216 Short_Descriptors := True;
12218 ----------------------
12219 -- Source_File_Name --
12220 ----------------------
12222 -- There are five forms for this pragma:
12224 -- pragma Source_File_Name (
12225 -- [UNIT_NAME =>] unit_NAME,
12226 -- BODY_FILE_NAME => STRING_LITERAL
12227 -- [, [INDEX =>] INTEGER_LITERAL]);
12229 -- pragma Source_File_Name (
12230 -- [UNIT_NAME =>] unit_NAME,
12231 -- SPEC_FILE_NAME => STRING_LITERAL
12232 -- [, [INDEX =>] INTEGER_LITERAL]);
12234 -- pragma Source_File_Name (
12235 -- BODY_FILE_NAME => STRING_LITERAL
12236 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12237 -- [, CASING => CASING_SPEC]);
12239 -- pragma Source_File_Name (
12240 -- SPEC_FILE_NAME => STRING_LITERAL
12241 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12242 -- [, CASING => CASING_SPEC]);
12244 -- pragma Source_File_Name (
12245 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12246 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12247 -- [, CASING => CASING_SPEC]);
12249 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12251 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12252 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12253 -- only be used when no project file is used, while SFNP can only be
12254 -- used when a project file is used.
12256 -- No processing here. Processing was completed during parsing, since
12257 -- we need to have file names set as early as possible. Units are
12258 -- loaded well before semantic processing starts.
12260 -- The only processing we defer to this point is the check for
12261 -- correct placement.
12263 when Pragma_Source_File_Name =>
12265 Check_Valid_Configuration_Pragma;
12267 ------------------------------
12268 -- Source_File_Name_Project --
12269 ------------------------------
12271 -- See Source_File_Name for syntax
12273 -- No processing here. Processing was completed during parsing, since
12274 -- we need to have file names set as early as possible. Units are
12275 -- loaded well before semantic processing starts.
12277 -- The only processing we defer to this point is the check for
12278 -- correct placement.
12280 when Pragma_Source_File_Name_Project =>
12282 Check_Valid_Configuration_Pragma;
12284 -- Check that a pragma Source_File_Name_Project is used only in a
12285 -- configuration pragmas file.
12287 -- Pragmas Source_File_Name_Project should only be generated by
12288 -- the Project Manager in configuration pragmas files.
12290 -- This is really an ugly test. It seems to depend on some
12291 -- accidental and undocumented property. At the very least it
12292 -- needs to be documented, but it would be better to have a
12293 -- clean way of testing if we are in a configuration file???
12295 if Present (Parent (N)) then
12297 ("pragma% can only appear in a configuration pragmas file");
12300 ----------------------
12301 -- Source_Reference --
12302 ----------------------
12304 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12306 -- Nothing to do, all processing completed in Par.Prag, since we need
12307 -- the information for possible parser messages that are output.
12309 when Pragma_Source_Reference =>
12312 --------------------------------
12313 -- Static_Elaboration_Desired --
12314 --------------------------------
12316 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12318 when Pragma_Static_Elaboration_Desired =>
12320 Check_At_Most_N_Arguments (1);
12322 if Is_Compilation_Unit (Current_Scope)
12323 and then Ekind (Current_Scope) = E_Package
12325 Set_Static_Elaboration_Desired (Current_Scope, True);
12327 Error_Pragma ("pragma% must apply to a library-level package");
12334 -- pragma Storage_Size (EXPRESSION);
12336 when Pragma_Storage_Size => Storage_Size : declare
12337 P : constant Node_Id := Parent (N);
12341 Check_No_Identifiers;
12342 Check_Arg_Count (1);
12344 -- The expression must be analyzed in the special manner described
12345 -- in "Handling of Default Expressions" in sem.ads.
12347 Arg := Get_Pragma_Arg (Arg1);
12348 Preanalyze_Spec_Expression (Arg, Any_Integer);
12350 if not Is_Static_Expression (Arg) then
12351 Check_Restriction (Static_Storage_Size, Arg);
12354 if Nkind (P) /= N_Task_Definition then
12359 if Has_Storage_Size_Pragma (P) then
12360 Error_Pragma ("duplicate pragma% not allowed");
12362 Set_Has_Storage_Size_Pragma (P, True);
12365 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12366 -- ??? exp_ch9 should use this!
12374 -- pragma Storage_Unit (NUMERIC_LITERAL);
12376 -- Only permitted argument is System'Storage_Unit value
12378 when Pragma_Storage_Unit =>
12379 Check_No_Identifiers;
12380 Check_Arg_Count (1);
12381 Check_Arg_Is_Integer_Literal (Arg1);
12383 if Intval (Get_Pragma_Arg (Arg1)) /=
12384 UI_From_Int (Ttypes.System_Storage_Unit)
12386 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12388 ("the only allowed argument for pragma% is ^", Arg1);
12391 --------------------
12392 -- Stream_Convert --
12393 --------------------
12395 -- pragma Stream_Convert (
12396 -- [Entity =>] type_LOCAL_NAME,
12397 -- [Read =>] function_NAME,
12398 -- [Write =>] function NAME);
12400 when Pragma_Stream_Convert => Stream_Convert : declare
12402 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12403 -- Check that the given argument is the name of a local function
12404 -- of one argument that is not overloaded earlier in the current
12405 -- local scope. A check is also made that the argument is a
12406 -- function with one parameter.
12408 --------------------------------------
12409 -- Check_OK_Stream_Convert_Function --
12410 --------------------------------------
12412 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12416 Check_Arg_Is_Local_Name (Arg);
12417 Ent := Entity (Get_Pragma_Arg (Arg));
12419 if Has_Homonym (Ent) then
12421 ("argument for pragma% may not be overloaded", Arg);
12424 if Ekind (Ent) /= E_Function
12425 or else No (First_Formal (Ent))
12426 or else Present (Next_Formal (First_Formal (Ent)))
12429 ("argument for pragma% must be" &
12430 " function of one argument", Arg);
12432 end Check_OK_Stream_Convert_Function;
12434 -- Start of processing for Stream_Convert
12438 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12439 Check_Arg_Count (3);
12440 Check_Optional_Identifier (Arg1, Name_Entity);
12441 Check_Optional_Identifier (Arg2, Name_Read);
12442 Check_Optional_Identifier (Arg3, Name_Write);
12443 Check_Arg_Is_Local_Name (Arg1);
12444 Check_OK_Stream_Convert_Function (Arg2);
12445 Check_OK_Stream_Convert_Function (Arg3);
12448 Typ : constant Entity_Id :=
12449 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12450 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12451 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12454 Check_First_Subtype (Arg1);
12456 -- Check for too early or too late. Note that we don't enforce
12457 -- the rule about primitive operations in this case, since, as
12458 -- is the case for explicit stream attributes themselves, these
12459 -- restrictions are not appropriate. Note that the chaining of
12460 -- the pragma by Rep_Item_Too_Late is actually the critical
12461 -- processing done for this pragma.
12463 if Rep_Item_Too_Early (Typ, N)
12465 Rep_Item_Too_Late (Typ, N, FOnly => True)
12470 -- Return if previous error
12472 if Etype (Typ) = Any_Type
12474 Etype (Read) = Any_Type
12476 Etype (Write) = Any_Type
12483 if Underlying_Type (Etype (Read)) /= Typ then
12485 ("incorrect return type for function&", Arg2);
12488 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12490 ("incorrect parameter type for function&", Arg3);
12493 if Underlying_Type (Etype (First_Formal (Read))) /=
12494 Underlying_Type (Etype (Write))
12497 ("result type of & does not match Read parameter type",
12501 end Stream_Convert;
12503 -------------------------
12504 -- Style_Checks (GNAT) --
12505 -------------------------
12507 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12509 -- This is processed by the parser since some of the style checks
12510 -- take place during source scanning and parsing. This means that
12511 -- we don't need to issue error messages here.
12513 when Pragma_Style_Checks => Style_Checks : declare
12514 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12520 Check_No_Identifiers;
12522 -- Two argument form
12524 if Arg_Count = 2 then
12525 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12532 E_Id := Get_Pragma_Arg (Arg2);
12535 if not Is_Entity_Name (E_Id) then
12537 ("second argument of pragma% must be entity name",
12541 E := Entity (E_Id);
12547 Set_Suppress_Style_Checks (E,
12548 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12549 exit when No (Homonym (E));
12555 -- One argument form
12558 Check_Arg_Count (1);
12560 if Nkind (A) = N_String_Literal then
12564 Slen : constant Natural := Natural (String_Length (S));
12565 Options : String (1 .. Slen);
12571 C := Get_String_Char (S, Int (J));
12572 exit when not In_Character_Range (C);
12573 Options (J) := Get_Character (C);
12575 -- If at end of string, set options. As per discussion
12576 -- above, no need to check for errors, since we issued
12577 -- them in the parser.
12580 Set_Style_Check_Options (Options);
12588 elsif Nkind (A) = N_Identifier then
12589 if Chars (A) = Name_All_Checks then
12591 Set_GNAT_Style_Check_Options;
12593 Set_Default_Style_Check_Options;
12596 elsif Chars (A) = Name_On then
12597 Style_Check := True;
12599 elsif Chars (A) = Name_Off then
12600 Style_Check := False;
12610 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12612 when Pragma_Subtitle =>
12614 Check_Arg_Count (1);
12615 Check_Optional_Identifier (Arg1, Name_Subtitle);
12616 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12623 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12625 when Pragma_Suppress =>
12626 Process_Suppress_Unsuppress (True);
12632 -- pragma Suppress_All;
12634 -- The only check made here is that the pragma has no arguments.
12635 -- There are no placement rules, and the processing required (setting
12636 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12637 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12638 -- then creates and inserts a pragma Suppress (All_Checks).
12640 when Pragma_Suppress_All =>
12642 Check_Arg_Count (0);
12644 -------------------------
12645 -- Suppress_Debug_Info --
12646 -------------------------
12648 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12650 when Pragma_Suppress_Debug_Info =>
12652 Check_Arg_Count (1);
12653 Check_Optional_Identifier (Arg1, Name_Entity);
12654 Check_Arg_Is_Local_Name (Arg1);
12655 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)), Sense);
12657 ----------------------------------
12658 -- Suppress_Exception_Locations --
12659 ----------------------------------
12661 -- pragma Suppress_Exception_Locations;
12663 when Pragma_Suppress_Exception_Locations =>
12665 Check_Arg_Count (0);
12666 Check_Valid_Configuration_Pragma;
12667 Exception_Locations_Suppressed := True;
12669 -----------------------------
12670 -- Suppress_Initialization --
12671 -----------------------------
12673 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12675 when Pragma_Suppress_Initialization => Suppress_Init : declare
12681 Check_Arg_Count (1);
12682 Check_Optional_Identifier (Arg1, Name_Entity);
12683 Check_Arg_Is_Local_Name (Arg1);
12685 E_Id := Get_Pragma_Arg (Arg1);
12687 if Etype (E_Id) = Any_Type then
12691 E := Entity (E_Id);
12693 if Is_Type (E) then
12694 if Is_Incomplete_Or_Private_Type (E) then
12695 if No (Full_View (Base_Type (E))) then
12697 ("argument of pragma% cannot be an incomplete type",
12700 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12703 Set_Suppress_Init_Proc (Base_Type (E));
12708 ("pragma% requires argument that is a type name", Arg1);
12716 -- pragma System_Name (DIRECT_NAME);
12718 -- Syntax check: one argument, which must be the identifier GNAT or
12719 -- the identifier GCC, no other identifiers are acceptable.
12721 when Pragma_System_Name =>
12723 Check_No_Identifiers;
12724 Check_Arg_Count (1);
12725 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12727 -----------------------------
12728 -- Task_Dispatching_Policy --
12729 -----------------------------
12731 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12733 when Pragma_Task_Dispatching_Policy => declare
12737 Check_Ada_83_Warning;
12738 Check_Arg_Count (1);
12739 Check_No_Identifiers;
12740 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12741 Check_Valid_Configuration_Pragma;
12742 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12743 DP := Fold_Upper (Name_Buffer (1));
12745 if Task_Dispatching_Policy /= ' '
12746 and then Task_Dispatching_Policy /= DP
12748 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12750 ("task dispatching policy incompatible with policy#");
12752 -- Set new policy, but always preserve System_Location since we
12753 -- like the error message with the run time name.
12756 Task_Dispatching_Policy := DP;
12758 if Task_Dispatching_Policy_Sloc /= System_Location then
12759 Task_Dispatching_Policy_Sloc := Loc;
12768 -- pragma Task_Info (EXPRESSION);
12770 when Pragma_Task_Info => Task_Info : declare
12771 P : constant Node_Id := Parent (N);
12776 if Nkind (P) /= N_Task_Definition then
12777 Error_Pragma ("pragma% must appear in task definition");
12780 Check_No_Identifiers;
12781 Check_Arg_Count (1);
12783 Analyze_And_Resolve
12784 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12786 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12790 if Has_Task_Info_Pragma (P) then
12791 Error_Pragma ("duplicate pragma% not allowed");
12793 Set_Has_Task_Info_Pragma (P, True);
12801 -- pragma Task_Name (string_EXPRESSION);
12803 when Pragma_Task_Name => Task_Name : declare
12804 P : constant Node_Id := Parent (N);
12808 Check_No_Identifiers;
12809 Check_Arg_Count (1);
12811 Arg := Get_Pragma_Arg (Arg1);
12813 -- The expression is used in the call to Create_Task, and must be
12814 -- expanded there, not in the context of the current spec. It must
12815 -- however be analyzed to capture global references, in case it
12816 -- appears in a generic context.
12818 Preanalyze_And_Resolve (Arg, Standard_String);
12820 if Nkind (P) /= N_Task_Definition then
12824 if Has_Task_Name_Pragma (P) then
12825 Error_Pragma ("duplicate pragma% not allowed");
12827 Set_Has_Task_Name_Pragma (P, True);
12828 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12836 -- pragma Task_Storage (
12837 -- [Task_Type =>] LOCAL_NAME,
12838 -- [Top_Guard =>] static_integer_EXPRESSION);
12840 when Pragma_Task_Storage => Task_Storage : declare
12841 Args : Args_List (1 .. 2);
12842 Names : constant Name_List (1 .. 2) := (
12846 Task_Type : Node_Id renames Args (1);
12847 Top_Guard : Node_Id renames Args (2);
12853 Gather_Associations (Names, Args);
12855 if No (Task_Type) then
12857 ("missing task_type argument for pragma%");
12860 Check_Arg_Is_Local_Name (Task_Type);
12862 Ent := Entity (Task_Type);
12864 if not Is_Task_Type (Ent) then
12866 ("argument for pragma% must be task type", Task_Type);
12869 if No (Top_Guard) then
12871 ("pragma% takes two arguments", Task_Type);
12873 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12876 Check_First_Subtype (Task_Type);
12878 if Rep_Item_Too_Late (Ent, N) then
12883 --------------------------
12884 -- Thread_Local_Storage --
12885 --------------------------
12887 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12889 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
12895 Check_Arg_Count (1);
12896 Check_Optional_Identifier (Arg1, Name_Entity);
12897 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12899 Id := Get_Pragma_Arg (Arg1);
12902 if not Is_Entity_Name (Id)
12903 or else Ekind (Entity (Id)) /= E_Variable
12905 Error_Pragma_Arg ("local variable name required", Arg1);
12910 if Rep_Item_Too_Early (E, N)
12911 or else Rep_Item_Too_Late (E, N)
12916 Set_Has_Pragma_Thread_Local_Storage (E);
12917 Set_Has_Gigi_Rep_Item (E);
12918 end Thread_Local_Storage;
12924 -- pragma Time_Slice (static_duration_EXPRESSION);
12926 when Pragma_Time_Slice => Time_Slice : declare
12932 Check_Arg_Count (1);
12933 Check_No_Identifiers;
12934 Check_In_Main_Program;
12935 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
12937 if not Error_Posted (Arg1) then
12939 while Present (Nod) loop
12940 if Nkind (Nod) = N_Pragma
12941 and then Pragma_Name (Nod) = Name_Time_Slice
12943 Error_Msg_Name_1 := Pname;
12944 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12951 -- Process only if in main unit
12953 if Get_Source_Unit (Loc) = Main_Unit then
12954 Opt.Time_Slice_Set := True;
12955 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
12957 if Val <= Ureal_0 then
12958 Opt.Time_Slice_Value := 0;
12960 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
12961 Opt.Time_Slice_Value := 1_000_000_000;
12964 Opt.Time_Slice_Value :=
12965 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
12974 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
12976 -- TITLING_OPTION ::=
12977 -- [Title =>] STRING_LITERAL
12978 -- | [Subtitle =>] STRING_LITERAL
12980 when Pragma_Title => Title : declare
12981 Args : Args_List (1 .. 2);
12982 Names : constant Name_List (1 .. 2) := (
12988 Gather_Associations (Names, Args);
12991 for J in 1 .. 2 loop
12992 if Present (Args (J)) then
12993 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
12998 ---------------------
12999 -- Unchecked_Union --
13000 ---------------------
13002 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13004 when Pragma_Unchecked_Union => Unchecked_Union : declare
13005 Assoc : constant Node_Id := Arg1;
13006 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13017 Check_No_Identifiers;
13018 Check_Arg_Count (1);
13019 Check_Arg_Is_Local_Name (Arg1);
13021 Find_Type (Type_Id);
13022 Typ := Entity (Type_Id);
13025 or else Rep_Item_Too_Early (Typ, N)
13029 Typ := Underlying_Type (Typ);
13032 if Rep_Item_Too_Late (Typ, N) then
13036 Check_First_Subtype (Arg1);
13038 -- Note remaining cases are references to a type in the current
13039 -- declarative part. If we find an error, we post the error on
13040 -- the relevant type declaration at an appropriate point.
13042 if not Is_Record_Type (Typ) then
13043 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13046 elsif Is_Tagged_Type (Typ) then
13047 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13050 elsif Is_Limited_Type (Typ) then
13052 ("Unchecked_Union must not be limited record type", Typ);
13053 Explain_Limited_Type (Typ, Typ);
13057 if not Has_Discriminants (Typ) then
13059 ("Unchecked_Union must have one discriminant", Typ);
13063 Discr := First_Discriminant (Typ);
13064 while Present (Discr) loop
13065 if No (Discriminant_Default_Value (Discr)) then
13067 ("Unchecked_Union discriminant must have default value",
13071 Next_Discriminant (Discr);
13074 Tdef := Type_Definition (Declaration_Node (Typ));
13075 Clist := Component_List (Tdef);
13077 Comp := First (Component_Items (Clist));
13078 while Present (Comp) loop
13079 Check_Component (Comp, Typ);
13083 if No (Clist) or else No (Variant_Part (Clist)) then
13085 ("Unchecked_Union must have variant part",
13090 Vpart := Variant_Part (Clist);
13092 Variant := First (Variants (Vpart));
13093 while Present (Variant) loop
13094 Check_Variant (Variant, Typ);
13099 Set_Is_Unchecked_Union (Typ, Sense);
13102 Set_Convention (Typ, Convention_C);
13105 Set_Has_Unchecked_Union (Base_Type (Typ), Sense);
13106 Set_Is_Unchecked_Union (Base_Type (Typ), Sense);
13107 end Unchecked_Union;
13109 ------------------------
13110 -- Unimplemented_Unit --
13111 ------------------------
13113 -- pragma Unimplemented_Unit;
13115 -- Note: this only gives an error if we are generating code, or if
13116 -- we are in a generic library unit (where the pragma appears in the
13117 -- body, not in the spec).
13119 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13120 Cunitent : constant Entity_Id :=
13121 Cunit_Entity (Get_Source_Unit (Loc));
13122 Ent_Kind : constant Entity_Kind :=
13127 Check_Arg_Count (0);
13129 if Operating_Mode = Generate_Code
13130 or else Ent_Kind = E_Generic_Function
13131 or else Ent_Kind = E_Generic_Procedure
13132 or else Ent_Kind = E_Generic_Package
13134 Get_Name_String (Chars (Cunitent));
13135 Set_Casing (Mixed_Case);
13136 Write_Str (Name_Buffer (1 .. Name_Len));
13137 Write_Str (" is not supported in this configuration");
13139 raise Unrecoverable_Error;
13141 end Unimplemented_Unit;
13143 ------------------------
13144 -- Universal_Aliasing --
13145 ------------------------
13147 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13149 when Pragma_Universal_Aliasing => Universal_Alias : declare
13154 Check_Arg_Count (1);
13155 Check_Optional_Identifier (Arg2, Name_Entity);
13156 Check_Arg_Is_Local_Name (Arg1);
13157 E_Id := Entity (Get_Pragma_Arg (Arg1));
13159 if E_Id = Any_Type then
13161 elsif No (E_Id) or else not Is_Type (E_Id) then
13162 Error_Pragma_Arg ("pragma% requires type", Arg1);
13165 Set_Universal_Aliasing (Implementation_Base_Type (E_Id), Sense);
13166 end Universal_Alias;
13168 --------------------
13169 -- Universal_Data --
13170 --------------------
13172 -- pragma Universal_Data [(library_unit_NAME)];
13174 when Pragma_Universal_Data =>
13177 -- If this is a configuration pragma, then set the universal
13178 -- addressing option, otherwise confirm that the pragma satisfies
13179 -- the requirements of library unit pragma placement and leave it
13180 -- to the GNAAMP back end to detect the pragma (avoids transitive
13181 -- setting of the option due to withed units).
13183 if Is_Configuration_Pragma then
13184 Universal_Addressing_On_AAMP := True;
13186 Check_Valid_Library_Unit_Pragma;
13189 if not AAMP_On_Target then
13190 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13197 -- pragma Unmodified (local_Name {, local_Name});
13199 when Pragma_Unmodified => Unmodified : declare
13200 Arg_Node : Node_Id;
13201 Arg_Expr : Node_Id;
13202 Arg_Ent : Entity_Id;
13206 Check_At_Least_N_Arguments (1);
13208 -- Loop through arguments
13211 while Present (Arg_Node) loop
13212 Check_No_Identifier (Arg_Node);
13214 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13215 -- in fact generate reference, so that the entity will have a
13216 -- reference, which will inhibit any warnings about it not
13217 -- being referenced, and also properly show up in the ali file
13218 -- as a reference. But this reference is recorded before the
13219 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13220 -- generated for this reference.
13222 Check_Arg_Is_Local_Name (Arg_Node);
13223 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13225 if Is_Entity_Name (Arg_Expr) then
13226 Arg_Ent := Entity (Arg_Expr);
13228 if not Is_Assignable (Arg_Ent) then
13230 ("pragma% can only be applied to a variable",
13233 Set_Has_Pragma_Unmodified (Arg_Ent, Sense);
13245 -- pragma Unreferenced (local_Name {, local_Name});
13247 -- or when used in a context clause:
13249 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13251 when Pragma_Unreferenced => Unreferenced : declare
13252 Arg_Node : Node_Id;
13253 Arg_Expr : Node_Id;
13254 Arg_Ent : Entity_Id;
13259 Check_At_Least_N_Arguments (1);
13261 -- Check case of appearing within context clause
13263 if Is_In_Context_Clause then
13265 -- The arguments must all be units mentioned in a with clause
13266 -- in the same context clause. Note we already checked (in
13267 -- Par.Prag) that the arguments are either identifiers or
13268 -- selected components.
13271 while Present (Arg_Node) loop
13272 Citem := First (List_Containing (N));
13273 while Citem /= N loop
13274 if Nkind (Citem) = N_With_Clause
13276 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13278 Set_Has_Pragma_Unreferenced
13281 (Library_Unit (Citem))));
13283 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13292 ("argument of pragma% is not with'ed unit", Arg_Node);
13298 -- Case of not in list of context items
13302 while Present (Arg_Node) loop
13303 Check_No_Identifier (Arg_Node);
13305 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13306 -- will in fact generate reference, so that the entity will
13307 -- have a reference, which will inhibit any warnings about
13308 -- it not being referenced, and also properly show up in the
13309 -- ali file as a reference. But this reference is recorded
13310 -- before the Has_Pragma_Unreferenced flag is set, so that
13311 -- no warning is generated for this reference.
13313 Check_Arg_Is_Local_Name (Arg_Node);
13314 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13316 if Is_Entity_Name (Arg_Expr) then
13317 Arg_Ent := Entity (Arg_Expr);
13319 -- If the entity is overloaded, the pragma applies to the
13320 -- most recent overloading, as documented. In this case,
13321 -- name resolution does not generate a reference, so it
13322 -- must be done here explicitly.
13324 if Is_Overloaded (Arg_Expr) then
13325 Generate_Reference (Arg_Ent, N);
13328 Set_Has_Pragma_Unreferenced (Arg_Ent, Sense);
13336 --------------------------
13337 -- Unreferenced_Objects --
13338 --------------------------
13340 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13342 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13343 Arg_Node : Node_Id;
13344 Arg_Expr : Node_Id;
13348 Check_At_Least_N_Arguments (1);
13351 while Present (Arg_Node) loop
13352 Check_No_Identifier (Arg_Node);
13353 Check_Arg_Is_Local_Name (Arg_Node);
13354 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13356 if not Is_Entity_Name (Arg_Expr)
13357 or else not Is_Type (Entity (Arg_Expr))
13360 ("argument for pragma% must be type or subtype", Arg_Node);
13363 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr), Sense);
13366 end Unreferenced_Objects;
13368 ------------------------------
13369 -- Unreserve_All_Interrupts --
13370 ------------------------------
13372 -- pragma Unreserve_All_Interrupts;
13374 when Pragma_Unreserve_All_Interrupts =>
13376 Check_Arg_Count (0);
13378 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13379 Unreserve_All_Interrupts := True;
13386 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13388 when Pragma_Unsuppress =>
13390 Process_Suppress_Unsuppress (False);
13392 -------------------
13393 -- Use_VADS_Size --
13394 -------------------
13396 -- pragma Use_VADS_Size;
13398 when Pragma_Use_VADS_Size =>
13400 Check_Arg_Count (0);
13401 Check_Valid_Configuration_Pragma;
13402 Use_VADS_Size := True;
13404 ---------------------
13405 -- Validity_Checks --
13406 ---------------------
13408 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13410 when Pragma_Validity_Checks => Validity_Checks : declare
13411 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13417 Check_Arg_Count (1);
13418 Check_No_Identifiers;
13420 if Nkind (A) = N_String_Literal then
13424 Slen : constant Natural := Natural (String_Length (S));
13425 Options : String (1 .. Slen);
13431 C := Get_String_Char (S, Int (J));
13432 exit when not In_Character_Range (C);
13433 Options (J) := Get_Character (C);
13436 Set_Validity_Check_Options (Options);
13444 elsif Nkind (A) = N_Identifier then
13446 if Chars (A) = Name_All_Checks then
13447 Set_Validity_Check_Options ("a");
13449 elsif Chars (A) = Name_On then
13450 Validity_Checks_On := True;
13452 elsif Chars (A) = Name_Off then
13453 Validity_Checks_On := False;
13457 end Validity_Checks;
13463 -- pragma Volatile (LOCAL_NAME);
13465 when Pragma_Volatile =>
13466 Process_Atomic_Shared_Volatile;
13468 -------------------------
13469 -- Volatile_Components --
13470 -------------------------
13472 -- pragma Volatile_Components (array_LOCAL_NAME);
13474 -- Volatile is handled by the same circuit as Atomic_Components
13480 -- pragma Warnings (On | Off);
13481 -- pragma Warnings (On | Off, LOCAL_NAME);
13482 -- pragma Warnings (static_string_EXPRESSION);
13483 -- pragma Warnings (On | Off, STRING_LITERAL);
13485 when Pragma_Warnings => Warnings : begin
13487 Check_At_Least_N_Arguments (1);
13488 Check_No_Identifiers;
13490 -- If debug flag -gnatd.i is set, pragma is ignored
13492 if Debug_Flag_Dot_I then
13496 -- Process various forms of the pragma
13499 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13502 -- One argument case
13504 if Arg_Count = 1 then
13506 -- On/Off one argument case was processed by parser
13508 if Nkind (Argx) = N_Identifier
13510 (Chars (Argx) = Name_On
13512 Chars (Argx) = Name_Off)
13516 -- One argument case must be ON/OFF or static string expr
13518 elsif not Is_Static_String_Expression (Arg1) then
13520 ("argument of pragma% must be On/Off or " &
13521 "static string expression", Arg1);
13523 -- One argument string expression case
13527 Lit : constant Node_Id := Expr_Value_S (Argx);
13528 Str : constant String_Id := Strval (Lit);
13529 Len : constant Nat := String_Length (Str);
13537 while J <= Len loop
13538 C := Get_String_Char (Str, J);
13539 OK := In_Character_Range (C);
13542 Chr := Get_Character (C);
13546 if J < Len and then Chr = '.' then
13548 C := Get_String_Char (Str, J);
13549 Chr := Get_Character (C);
13551 if not Set_Dot_Warning_Switch (Chr) then
13553 ("invalid warning switch character " &
13560 OK := Set_Warning_Switch (Chr);
13566 ("invalid warning switch character " & Chr,
13575 -- Two or more arguments (must be two)
13578 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13579 Check_At_Most_N_Arguments (2);
13587 E_Id := Get_Pragma_Arg (Arg2);
13590 -- In the expansion of an inlined body, a reference to
13591 -- the formal may be wrapped in a conversion if the
13592 -- actual is a conversion. Retrieve the real entity name.
13594 if (In_Instance_Body
13595 or else In_Inlined_Body)
13596 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13598 E_Id := Expression (E_Id);
13601 -- Entity name case
13603 if Is_Entity_Name (E_Id) then
13604 E := Entity (E_Id);
13611 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13614 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13615 and then Warn_On_Warnings_Off
13617 Warnings_Off_Pragmas.Append ((N, E));
13620 if Is_Enumeration_Type (E) then
13624 Lit := First_Literal (E);
13625 while Present (Lit) loop
13626 Set_Warnings_Off (Lit);
13627 Next_Literal (Lit);
13632 exit when No (Homonym (E));
13637 -- Error if not entity or static string literal case
13639 elsif not Is_Static_String_Expression (Arg2) then
13641 ("second argument of pragma% must be entity " &
13642 "name or static string expression", Arg2);
13644 -- String literal case
13647 String_To_Name_Buffer
13648 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13650 -- Note on configuration pragma case: If this is a
13651 -- configuration pragma, then for an OFF pragma, we
13652 -- just set Config True in the call, which is all
13653 -- that needs to be done. For the case of ON, this
13654 -- is normally an error, unless it is canceling the
13655 -- effect of a previous OFF pragma in the same file.
13656 -- In any other case, an error will be signalled (ON
13657 -- with no matching OFF).
13659 if Chars (Argx) = Name_Off then
13660 Set_Specific_Warning_Off
13661 (Loc, Name_Buffer (1 .. Name_Len),
13662 Config => Is_Configuration_Pragma);
13664 elsif Chars (Argx) = Name_On then
13665 Set_Specific_Warning_On
13666 (Loc, Name_Buffer (1 .. Name_Len), Err);
13670 ("?pragma Warnings On with no " &
13671 "matching Warnings Off",
13681 -------------------
13682 -- Weak_External --
13683 -------------------
13685 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13687 when Pragma_Weak_External => Weak_External : declare
13692 Check_Arg_Count (1);
13693 Check_Optional_Identifier (Arg1, Name_Entity);
13694 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13695 Ent := Entity (Get_Pragma_Arg (Arg1));
13697 if Rep_Item_Too_Early (Ent, N) then
13700 Ent := Underlying_Type (Ent);
13703 -- The only processing required is to link this item on to the
13704 -- list of rep items for the given entity. This is accomplished
13705 -- by the call to Rep_Item_Too_Late (when no error is detected
13706 -- and False is returned).
13708 if Rep_Item_Too_Late (Ent, N) then
13711 Set_Has_Gigi_Rep_Item (Ent);
13715 -----------------------------
13716 -- Wide_Character_Encoding --
13717 -----------------------------
13719 -- pragma Wide_Character_Encoding (IDENTIFIER);
13721 when Pragma_Wide_Character_Encoding =>
13724 -- Nothing to do, handled in parser. Note that we do not enforce
13725 -- configuration pragma placement, this pragma can appear at any
13726 -- place in the source, allowing mixed encodings within a single
13731 --------------------
13732 -- Unknown_Pragma --
13733 --------------------
13735 -- Should be impossible, since the case of an unknown pragma is
13736 -- separately processed before the case statement is entered.
13738 when Unknown_Pragma =>
13739 raise Program_Error;
13742 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13743 -- until AI is formally approved.
13745 -- Check_Order_Dependence;
13748 when Pragma_Exit => null;
13749 end Analyze_Pragma;
13751 -------------------
13752 -- Check_Enabled --
13753 -------------------
13755 function Check_Enabled (Nam : Name_Id) return Boolean is
13759 -- Loop through entries in check policy list
13761 PP := Opt.Check_Policy_List;
13763 -- If there are no specific entries that matched, then we let the
13764 -- setting of assertions govern. Note that this provides the needed
13765 -- compatibility with the RM for the cases of assertion, invariant,
13766 -- precondition, predicate, and postcondition.
13769 return Assertions_Enabled;
13771 -- Here we have an entry see if it matches
13775 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13778 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13779 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13780 when Name_On | Name_Check =>
13782 when Name_Off | Name_Ignore =>
13785 raise Program_Error;
13789 PP := Next_Pragma (PP);
13796 ---------------------------------
13797 -- Delay_Config_Pragma_Analyze --
13798 ---------------------------------
13800 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13802 return Pragma_Name (N) = Name_Interrupt_State
13804 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13805 end Delay_Config_Pragma_Analyze;
13807 -------------------------
13808 -- Get_Base_Subprogram --
13809 -------------------------
13811 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13812 Result : Entity_Id;
13815 -- Follow subprogram renaming chain
13818 while Is_Subprogram (Result)
13820 (Is_Generic_Instance (Result)
13821 or else Nkind (Parent (Declaration_Node (Result))) =
13822 N_Subprogram_Renaming_Declaration)
13823 and then Present (Alias (Result))
13825 Result := Alias (Result);
13829 end Get_Base_Subprogram;
13835 procedure Initialize is
13840 -----------------------------
13841 -- Is_Config_Static_String --
13842 -----------------------------
13844 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13846 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13847 -- This is an internal recursive function that is just like the outer
13848 -- function except that it adds the string to the name buffer rather
13849 -- than placing the string in the name buffer.
13851 ------------------------------
13852 -- Add_Config_Static_String --
13853 ------------------------------
13855 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13862 if Nkind (N) = N_Op_Concat then
13863 if Add_Config_Static_String (Left_Opnd (N)) then
13864 N := Right_Opnd (N);
13870 if Nkind (N) /= N_String_Literal then
13871 Error_Msg_N ("string literal expected for pragma argument", N);
13875 for J in 1 .. String_Length (Strval (N)) loop
13876 C := Get_String_Char (Strval (N), J);
13878 if not In_Character_Range (C) then
13880 ("string literal contains invalid wide character",
13881 Sloc (N) + 1 + Source_Ptr (J));
13885 Add_Char_To_Name_Buffer (Get_Character (C));
13890 end Add_Config_Static_String;
13892 -- Start of processing for Is_Config_Static_String
13897 return Add_Config_Static_String (Arg);
13898 end Is_Config_Static_String;
13900 -----------------------------------------
13901 -- Is_Non_Significant_Pragma_Reference --
13902 -----------------------------------------
13904 -- This function makes use of the following static table which indicates
13905 -- whether a given pragma is significant.
13907 -- -1 indicates that references in any argument position are significant
13908 -- 0 indicates that appearence in any argument is not significant
13909 -- +n indicates that appearence as argument n is significant, but all
13910 -- other arguments are not significant
13911 -- 99 special processing required (e.g. for pragma Check)
13913 Sig_Flags : constant array (Pragma_Id) of Int :=
13914 (Pragma_AST_Entry => -1,
13915 Pragma_Abort_Defer => -1,
13916 Pragma_Ada_83 => -1,
13917 Pragma_Ada_95 => -1,
13918 Pragma_Ada_05 => -1,
13919 Pragma_Ada_2005 => -1,
13920 Pragma_Ada_12 => -1,
13921 Pragma_Ada_2012 => -1,
13922 Pragma_All_Calls_Remote => -1,
13923 Pragma_Annotate => -1,
13924 Pragma_Assert => -1,
13925 Pragma_Assertion_Policy => 0,
13926 Pragma_Assume_No_Invalid_Values => 0,
13927 Pragma_Asynchronous => -1,
13928 Pragma_Atomic => 0,
13929 Pragma_Atomic_Components => 0,
13930 Pragma_Attach_Handler => -1,
13931 Pragma_Check => 99,
13932 Pragma_Check_Name => 0,
13933 Pragma_Check_Policy => 0,
13934 Pragma_CIL_Constructor => -1,
13935 Pragma_CPP_Class => 0,
13936 Pragma_CPP_Constructor => 0,
13937 Pragma_CPP_Virtual => 0,
13938 Pragma_CPP_Vtable => 0,
13940 Pragma_C_Pass_By_Copy => 0,
13941 Pragma_Comment => 0,
13942 Pragma_Common_Object => -1,
13943 Pragma_Compile_Time_Error => -1,
13944 Pragma_Compile_Time_Warning => -1,
13945 Pragma_Compiler_Unit => 0,
13946 Pragma_Complete_Representation => 0,
13947 Pragma_Complex_Representation => 0,
13948 Pragma_Component_Alignment => -1,
13949 Pragma_Controlled => 0,
13950 Pragma_Convention => 0,
13951 Pragma_Convention_Identifier => 0,
13952 Pragma_Debug => -1,
13953 Pragma_Debug_Policy => 0,
13954 Pragma_Detect_Blocking => -1,
13955 Pragma_Default_Storage_Pool => -1,
13956 Pragma_Dimension => -1,
13957 Pragma_Discard_Names => 0,
13958 Pragma_Elaborate => -1,
13959 Pragma_Elaborate_All => -1,
13960 Pragma_Elaborate_Body => -1,
13961 Pragma_Elaboration_Checks => -1,
13962 Pragma_Eliminate => -1,
13963 Pragma_Export => -1,
13964 Pragma_Export_Exception => -1,
13965 Pragma_Export_Function => -1,
13966 Pragma_Export_Object => -1,
13967 Pragma_Export_Procedure => -1,
13968 Pragma_Export_Value => -1,
13969 Pragma_Export_Valued_Procedure => -1,
13970 Pragma_Extend_System => -1,
13971 Pragma_Extensions_Allowed => -1,
13972 Pragma_External => -1,
13973 Pragma_Favor_Top_Level => -1,
13974 Pragma_External_Name_Casing => -1,
13975 Pragma_Fast_Math => -1,
13976 Pragma_Finalize_Storage_Only => 0,
13977 Pragma_Float_Representation => 0,
13978 Pragma_Ident => -1,
13979 Pragma_Implemented => -1,
13980 Pragma_Implicit_Packing => 0,
13981 Pragma_Import => +2,
13982 Pragma_Import_Exception => 0,
13983 Pragma_Import_Function => 0,
13984 Pragma_Import_Object => 0,
13985 Pragma_Import_Procedure => 0,
13986 Pragma_Import_Valued_Procedure => 0,
13987 Pragma_Independent => 0,
13988 Pragma_Independent_Components => 0,
13989 Pragma_Initialize_Scalars => -1,
13990 Pragma_Inline => 0,
13991 Pragma_Inline_Always => 0,
13992 Pragma_Inline_Generic => 0,
13993 Pragma_Inspection_Point => -1,
13994 Pragma_Interface => +2,
13995 Pragma_Interface_Name => +2,
13996 Pragma_Interrupt_Handler => -1,
13997 Pragma_Interrupt_Priority => -1,
13998 Pragma_Interrupt_State => -1,
13999 Pragma_Invariant => -1,
14000 Pragma_Java_Constructor => -1,
14001 Pragma_Java_Interface => -1,
14002 Pragma_Keep_Names => 0,
14003 Pragma_License => -1,
14004 Pragma_Link_With => -1,
14005 Pragma_Linker_Alias => -1,
14006 Pragma_Linker_Constructor => -1,
14007 Pragma_Linker_Destructor => -1,
14008 Pragma_Linker_Options => -1,
14009 Pragma_Linker_Section => -1,
14011 Pragma_Locking_Policy => -1,
14012 Pragma_Long_Float => -1,
14013 Pragma_Machine_Attribute => -1,
14015 Pragma_Main_Storage => -1,
14016 Pragma_Memory_Size => -1,
14017 Pragma_No_Return => 0,
14018 Pragma_No_Body => 0,
14019 Pragma_No_Run_Time => -1,
14020 Pragma_No_Strict_Aliasing => -1,
14021 Pragma_Normalize_Scalars => -1,
14022 Pragma_Obsolescent => 0,
14023 Pragma_Optimize => -1,
14024 Pragma_Optimize_Alignment => -1,
14025 Pragma_Ordered => 0,
14028 Pragma_Passive => -1,
14029 Pragma_Preelaborable_Initialization => -1,
14030 Pragma_Polling => -1,
14031 Pragma_Persistent_BSS => 0,
14032 Pragma_Postcondition => -1,
14033 Pragma_Precondition => -1,
14034 Pragma_Predicate => -1,
14035 Pragma_Preelaborate => -1,
14036 Pragma_Preelaborate_05 => -1,
14037 Pragma_Priority => -1,
14038 Pragma_Priority_Specific_Dispatching => -1,
14039 Pragma_Profile => 0,
14040 Pragma_Profile_Warnings => 0,
14041 Pragma_Propagate_Exceptions => -1,
14042 Pragma_Psect_Object => -1,
14044 Pragma_Pure_05 => -1,
14045 Pragma_Pure_Function => -1,
14046 Pragma_Queuing_Policy => -1,
14047 Pragma_Ravenscar => -1,
14048 Pragma_Relative_Deadline => -1,
14049 Pragma_Remote_Call_Interface => -1,
14050 Pragma_Remote_Types => -1,
14051 Pragma_Restricted_Run_Time => -1,
14052 Pragma_Restriction_Warnings => -1,
14053 Pragma_Restrictions => -1,
14054 Pragma_Reviewable => -1,
14055 Pragma_Short_Circuit_And_Or => -1,
14056 Pragma_Share_Generic => -1,
14057 Pragma_Shared => -1,
14058 Pragma_Shared_Passive => -1,
14059 Pragma_Short_Descriptors => 0,
14060 Pragma_Source_File_Name => -1,
14061 Pragma_Source_File_Name_Project => -1,
14062 Pragma_Source_Reference => -1,
14063 Pragma_Storage_Size => -1,
14064 Pragma_Storage_Unit => -1,
14065 Pragma_Static_Elaboration_Desired => -1,
14066 Pragma_Stream_Convert => -1,
14067 Pragma_Style_Checks => -1,
14068 Pragma_Subtitle => -1,
14069 Pragma_Suppress => 0,
14070 Pragma_Suppress_Exception_Locations => 0,
14071 Pragma_Suppress_All => -1,
14072 Pragma_Suppress_Debug_Info => 0,
14073 Pragma_Suppress_Initialization => 0,
14074 Pragma_System_Name => -1,
14075 Pragma_Task_Dispatching_Policy => -1,
14076 Pragma_Task_Info => -1,
14077 Pragma_Task_Name => -1,
14078 Pragma_Task_Storage => 0,
14079 Pragma_Thread_Local_Storage => 0,
14080 Pragma_Time_Slice => -1,
14081 Pragma_Title => -1,
14082 Pragma_Unchecked_Union => 0,
14083 Pragma_Unimplemented_Unit => -1,
14084 Pragma_Universal_Aliasing => -1,
14085 Pragma_Universal_Data => -1,
14086 Pragma_Unmodified => -1,
14087 Pragma_Unreferenced => -1,
14088 Pragma_Unreferenced_Objects => -1,
14089 Pragma_Unreserve_All_Interrupts => -1,
14090 Pragma_Unsuppress => 0,
14091 Pragma_Use_VADS_Size => -1,
14092 Pragma_Validity_Checks => -1,
14093 Pragma_Volatile => 0,
14094 Pragma_Volatile_Components => 0,
14095 Pragma_Warnings => -1,
14096 Pragma_Weak_External => -1,
14097 Pragma_Wide_Character_Encoding => 0,
14098 Unknown_Pragma => 0);
14100 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14109 if Nkind (P) /= N_Pragma_Argument_Association then
14113 Id := Get_Pragma_Id (Parent (P));
14114 C := Sig_Flags (Id);
14126 -- For pragma Check, the first argument is not significant,
14127 -- the second and the third (if present) arguments are
14130 when Pragma_Check =>
14132 P = First (Pragma_Argument_Associations (Parent (P)));
14135 raise Program_Error;
14139 A := First (Pragma_Argument_Associations (Parent (P)));
14140 for J in 1 .. C - 1 loop
14148 return A = P; -- is this wrong way round ???
14151 end Is_Non_Significant_Pragma_Reference;
14153 ------------------------------
14154 -- Is_Pragma_String_Literal --
14155 ------------------------------
14157 -- This function returns true if the corresponding pragma argument is a
14158 -- static string expression. These are the only cases in which string
14159 -- literals can appear as pragma arguments. We also allow a string literal
14160 -- as the first argument to pragma Assert (although it will of course
14161 -- always generate a type error).
14163 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14164 Pragn : constant Node_Id := Parent (Par);
14165 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14166 Pname : constant Name_Id := Pragma_Name (Pragn);
14172 N := First (Assoc);
14179 if Pname = Name_Assert then
14182 elsif Pname = Name_Export then
14185 elsif Pname = Name_Ident then
14188 elsif Pname = Name_Import then
14191 elsif Pname = Name_Interface_Name then
14194 elsif Pname = Name_Linker_Alias then
14197 elsif Pname = Name_Linker_Section then
14200 elsif Pname = Name_Machine_Attribute then
14203 elsif Pname = Name_Source_File_Name then
14206 elsif Pname = Name_Source_Reference then
14209 elsif Pname = Name_Title then
14212 elsif Pname = Name_Subtitle then
14218 end Is_Pragma_String_Literal;
14220 --------------------------------------
14221 -- Process_Compilation_Unit_Pragmas --
14222 --------------------------------------
14224 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14226 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14227 -- strange because it comes at the end of the unit. Rational has the
14228 -- same name for a pragma, but treats it as a program unit pragma, In
14229 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14230 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14231 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14232 -- the context clause to ensure the correct processing.
14234 if Has_Pragma_Suppress_All (N) then
14235 Prepend_To (Context_Items (N),
14236 Make_Pragma (Sloc (N),
14237 Chars => Name_Suppress,
14238 Pragma_Argument_Associations => New_List (
14239 Make_Pragma_Argument_Association (Sloc (N),
14241 Make_Identifier (Sloc (N),
14242 Chars => Name_All_Checks)))));
14245 -- Nothing else to do at the current time!
14247 end Process_Compilation_Unit_Pragmas;
14258 --------------------------------
14259 -- Set_Encoded_Interface_Name --
14260 --------------------------------
14262 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14263 Str : constant String_Id := Strval (S);
14264 Len : constant Int := String_Length (Str);
14269 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14272 -- Stores encoded value of character code CC. The encoding we use an
14273 -- underscore followed by four lower case hex digits.
14279 procedure Encode is
14281 Store_String_Char (Get_Char_Code ('_'));
14283 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14285 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14287 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14289 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14292 -- Start of processing for Set_Encoded_Interface_Name
14295 -- If first character is asterisk, this is a link name, and we leave it
14296 -- completely unmodified. We also ignore null strings (the latter case
14297 -- happens only in error cases) and no encoding should occur for Java or
14298 -- AAMP interface names.
14301 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14302 or else VM_Target /= No_VM
14303 or else AAMP_On_Target
14305 Set_Interface_Name (E, S);
14310 CC := Get_String_Char (Str, J);
14312 exit when not In_Character_Range (CC);
14314 C := Get_Character (CC);
14316 exit when C /= '_' and then C /= '$'
14317 and then C not in '0' .. '9'
14318 and then C not in 'a' .. 'z'
14319 and then C not in 'A' .. 'Z';
14322 Set_Interface_Name (E, S);
14330 -- Here we need to encode. The encoding we use as follows:
14331 -- three underscores + four hex digits (lower case)
14335 for J in 1 .. String_Length (Str) loop
14336 CC := Get_String_Char (Str, J);
14338 if not In_Character_Range (CC) then
14341 C := Get_Character (CC);
14343 if C = '_' or else C = '$'
14344 or else C in '0' .. '9'
14345 or else C in 'a' .. 'z'
14346 or else C in 'A' .. 'Z'
14348 Store_String_Char (CC);
14355 Set_Interface_Name (E,
14356 Make_String_Literal (Sloc (S),
14357 Strval => End_String));
14359 end Set_Encoded_Interface_Name;
14361 -------------------
14362 -- Set_Unit_Name --
14363 -------------------
14365 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14370 if Nkind (N) = N_Identifier
14371 and then Nkind (With_Item) = N_Identifier
14373 Set_Entity (N, Entity (With_Item));
14375 elsif Nkind (N) = N_Selected_Component then
14376 Change_Selected_Component_To_Expanded_Name (N);
14377 Set_Entity (N, Entity (With_Item));
14378 Set_Entity (Selector_Name (N), Entity (N));
14380 Pref := Prefix (N);
14381 Scop := Scope (Entity (N));
14382 while Nkind (Pref) = N_Selected_Component loop
14383 Change_Selected_Component_To_Expanded_Name (Pref);
14384 Set_Entity (Selector_Name (Pref), Scop);
14385 Set_Entity (Pref, Scop);
14386 Pref := Prefix (Pref);
14387 Scop := Scope (Scop);
14390 Set_Entity (Pref, Scop);