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 Pragma_Exit : exception;
274 -- This exception is used to exit pragma processing completely. It is
275 -- used when an error is detected, and no further processing is
276 -- required. It is also used if an earlier error has left the tree in
277 -- a state where the pragma should not be processed.
280 -- Number of pragma argument associations
286 -- First four pragma arguments (pragma argument association nodes, or
287 -- Empty if the corresponding argument does not exist).
289 type Name_List is array (Natural range <>) of Name_Id;
290 type Args_List is array (Natural range <>) of Node_Id;
291 -- Types used for arguments to Check_Arg_Order and Gather_Associations
293 procedure Ada_2005_Pragma;
294 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
295 -- Ada 95 mode, these are implementation defined pragmas, so should be
296 -- caught by the No_Implementation_Pragmas restriction.
298 procedure Ada_2012_Pragma;
299 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
300 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
301 -- should be caught by the No_Implementation_Pragmas restriction.
303 procedure Check_Ada_83_Warning;
304 -- Issues a warning message for the current pragma if operating in Ada
305 -- 83 mode (used for language pragmas that are not a standard part of
306 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
309 procedure Check_Arg_Count (Required : Nat);
310 -- Check argument count for pragma is equal to given parameter. If not,
311 -- then issue an error message and raise Pragma_Exit.
313 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
314 -- Arg which can either be a pragma argument association, in which case
315 -- the check is applied to the expression of the association or an
316 -- expression directly.
318 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
319 -- Check that an argument has the right form for an EXTERNAL_NAME
320 -- parameter of an extended import/export pragma. The rule is that the
321 -- name must be an identifier or string literal (in Ada 83 mode) or a
322 -- static string expression (in Ada 95 mode).
324 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
325 -- Check the specified argument Arg to make sure that it is an
326 -- identifier. If not give error and raise Pragma_Exit.
328 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
329 -- Check the specified argument Arg to make sure that it is an integer
330 -- literal. If not give error and raise Pragma_Exit.
332 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
333 -- Check the specified argument Arg to make sure that it has the proper
334 -- syntactic form for a local name and meets the semantic requirements
335 -- for a local name. The local name is analyzed as part of the
336 -- processing for this call. In addition, the local name is required
337 -- to represent an entity at the library level.
339 procedure Check_Arg_Is_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.
345 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
346 -- Check the specified argument Arg to make sure that it is a valid
347 -- locking policy name. If not give error and raise Pragma_Exit.
349 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
350 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
351 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
352 -- Check the specified argument Arg to make sure that it is an
353 -- identifier whose name matches either N1 or N2 (or N3 if present).
354 -- If not then give error and raise Pragma_Exit.
356 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
357 -- Check the specified argument Arg to make sure that it is a valid
358 -- queuing policy name. If not give error and raise Pragma_Exit.
360 procedure Check_Arg_Is_Static_Expression
362 Typ : Entity_Id := Empty);
363 -- Check the specified argument Arg to make sure that it is a static
364 -- expression of the given type (i.e. it will be analyzed and resolved
365 -- using this type, which can be any valid argument to Resolve, e.g.
366 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
367 -- Typ is left Empty, then any static expression is allowed.
369 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
370 -- Check the specified argument Arg to make sure that it is a valid task
371 -- dispatching policy name. If not give error and raise Pragma_Exit.
373 procedure Check_Arg_Order (Names : Name_List);
374 -- Checks for an instance of two arguments with identifiers for the
375 -- current pragma which are not in the sequence indicated by Names,
376 -- and if so, generates a fatal message about bad order of arguments.
378 procedure Check_At_Least_N_Arguments (N : Nat);
379 -- Check there are at least N arguments present
381 procedure Check_At_Most_N_Arguments (N : Nat);
382 -- Check there are no more than N arguments present
384 procedure Check_Component
387 In_Variant_Part : Boolean := False);
388 -- Examine an Unchecked_Union component for correct use of per-object
389 -- constrained subtypes, and for restrictions on finalizable components.
390 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
391 -- should be set when Comp comes from a record variant.
393 procedure Check_Duplicate_Pragma (E : Entity_Id);
394 -- Check if a pragma of the same name as the current pragma is already
395 -- chained as a rep pragma to the given entity. If so give a message
396 -- about the duplicate, and then raise Pragma_Exit so does not return.
397 -- Also checks for delayed aspect specification node in the chain.
399 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
400 -- Nam is an N_String_Literal node containing the external name set by
401 -- an Import or Export pragma (or extended Import or Export pragma).
402 -- This procedure checks for possible duplications if this is the export
403 -- case, and if found, issues an appropriate error message.
405 procedure Check_First_Subtype (Arg : Node_Id);
406 -- Checks that Arg, whose expression is an entity name, references a
409 procedure Check_In_Main_Program;
410 -- Common checks for pragmas that appear within a main program
411 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
413 procedure Check_Interrupt_Or_Attach_Handler;
414 -- Common processing for first argument of pragma Interrupt_Handler or
415 -- pragma Attach_Handler.
417 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
418 -- Check that pragma appears in a declarative part, or in a package
419 -- specification, i.e. that it does not occur in a statement sequence
422 procedure Check_No_Identifier (Arg : Node_Id);
423 -- Checks that the given argument does not have an identifier. If
424 -- an identifier is present, then an error message is issued, and
425 -- Pragma_Exit is raised.
427 procedure Check_No_Identifiers;
428 -- Checks that none of the arguments to the pragma has an identifier.
429 -- If any argument has an identifier, then an error message is issued,
430 -- and Pragma_Exit is raised.
432 procedure Check_No_Link_Name;
433 -- Checks that no link name is specified
435 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
436 -- Checks if the given argument has an identifier, and if so, requires
437 -- it to match the given identifier name. If there is a non-matching
438 -- identifier, then an error message is given and Error_Pragmas raised.
440 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
441 -- Checks if the given argument has an identifier, and if so, requires
442 -- it to match the given identifier name. If there is a non-matching
443 -- identifier, then an error message is given and Error_Pragmas raised.
444 -- In this version of the procedure, the identifier name is given as
445 -- a string with lower case letters.
447 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
448 -- Called to process a precondition or postcondition pragma. There are
451 -- The pragma appears after a subprogram spec
453 -- If the corresponding check is not enabled, the pragma is analyzed
454 -- but otherwise ignored and control returns with In_Body set False.
456 -- If the check is enabled, then the first step is to analyze the
457 -- pragma, but this is skipped if the subprogram spec appears within
458 -- a package specification (because this is the case where we delay
459 -- analysis till the end of the spec). Then (whether or not it was
460 -- analyzed), the pragma is chained to the subprogram in question
461 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
462 -- caller with In_Body set False.
464 -- The pragma appears at the start of subprogram body declarations
466 -- In this case an immediate return to the caller is made with
467 -- In_Body set True, and the pragma is NOT analyzed.
469 -- In all other cases, an error message for bad placement is given
471 procedure Check_Static_Constraint (Constr : Node_Id);
472 -- Constr is a constraint from an N_Subtype_Indication node from a
473 -- component constraint in an Unchecked_Union type. This routine checks
474 -- that the constraint is static as required by the restrictions for
477 procedure Check_Valid_Configuration_Pragma;
478 -- Legality checks for placement of a configuration pragma
480 procedure Check_Valid_Library_Unit_Pragma;
481 -- Legality checks for library unit pragmas. A special case arises for
482 -- pragmas in generic instances that come from copies of the original
483 -- library unit pragmas in the generic templates. In the case of other
484 -- than library level instantiations these can appear in contexts which
485 -- would normally be invalid (they only apply to the original template
486 -- and to library level instantiations), and they are simply ignored,
487 -- which is implemented by rewriting them as null statements.
489 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
490 -- Check an Unchecked_Union variant for lack of nested variants and
491 -- presence of at least one component. UU_Typ is the related Unchecked_
494 procedure Error_Pragma (Msg : String);
495 pragma No_Return (Error_Pragma);
496 -- Outputs error message for current pragma. The message contains a %
497 -- that will be replaced with the pragma name, and the flag is placed
498 -- on the pragma itself. Pragma_Exit is then raised.
500 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
501 pragma No_Return (Error_Pragma_Arg);
502 -- Outputs error message for current pragma. The message may contain
503 -- a % that will be replaced with the pragma name. The parameter Arg
504 -- may either be a pragma argument association, in which case the flag
505 -- is placed on the expression of this association, or an expression,
506 -- in which case the flag is placed directly on the expression. The
507 -- message is placed using Error_Msg_N, so the message may also contain
508 -- an & insertion character which will reference the given Arg value.
509 -- After placing the message, Pragma_Exit is raised.
511 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
512 pragma No_Return (Error_Pragma_Arg);
513 -- Similar to above form of Error_Pragma_Arg except that two messages
514 -- are provided, the second is a continuation comment starting with \.
516 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
517 pragma No_Return (Error_Pragma_Arg_Ident);
518 -- Outputs error message for current pragma. The message may contain
519 -- a % that will be replaced with the pragma name. The parameter Arg
520 -- must be a pragma argument association with a non-empty identifier
521 -- (i.e. its Chars field must be set), and the error message is placed
522 -- on the identifier. The message is placed using Error_Msg_N so
523 -- the message may also contain an & insertion character which will
524 -- reference the identifier. After placing the message, Pragma_Exit
527 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
528 pragma No_Return (Error_Pragma_Ref);
529 -- Outputs error message for current pragma. The message may contain
530 -- a % that will be replaced with the pragma name. The parameter Ref
531 -- must be an entity whose name can be referenced by & and sloc by #.
532 -- After placing the message, Pragma_Exit is raised.
534 function Find_Lib_Unit_Name return Entity_Id;
535 -- Used for a library unit pragma to find the entity to which the
536 -- library unit pragma applies, returns the entity found.
538 procedure Find_Program_Unit_Name (Id : Node_Id);
539 -- If the pragma is a compilation unit pragma, the id must denote the
540 -- compilation unit in the same compilation, and the pragma must appear
541 -- in the list of preceding or trailing pragmas. If it is a program
542 -- unit pragma that is not a compilation unit pragma, then the
543 -- identifier must be visible.
545 function Find_Unique_Parameterless_Procedure
547 Arg : Node_Id) return Entity_Id;
548 -- Used for a procedure pragma to find the unique parameterless
549 -- procedure identified by Name, returns it if it exists, otherwise
550 -- errors out and uses Arg as the pragma argument for the message.
552 procedure Fix_Error (Msg : in out String);
553 -- This is called prior to issuing an error message. Msg is a string
554 -- which typically contains the substring pragma. If the current pragma
555 -- comes from an aspect, each such "pragma" substring is replaced with
556 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
557 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
559 procedure Gather_Associations
561 Args : out Args_List);
562 -- This procedure is used to gather the arguments for a pragma that
563 -- permits arbitrary ordering of parameters using the normal rules
564 -- for named and positional parameters. The Names argument is a list
565 -- of Name_Id values that corresponds to the allowed pragma argument
566 -- association identifiers in order. The result returned in Args is
567 -- a list of corresponding expressions that are the pragma arguments.
568 -- Note that this is a list of expressions, not of pragma argument
569 -- associations (Gather_Associations has completely checked all the
570 -- optional identifiers when it returns). An entry in Args is Empty
571 -- on return if the corresponding argument is not present.
573 procedure GNAT_Pragma;
574 -- Called for all GNAT defined pragmas to check the relevant restriction
575 -- (No_Implementation_Pragmas).
577 function Is_Before_First_Decl
578 (Pragma_Node : Node_Id;
579 Decls : List_Id) return Boolean;
580 -- Return True if Pragma_Node is before the first declarative item in
581 -- Decls where Decls is the list of declarative items.
583 function Is_Configuration_Pragma return Boolean;
584 -- Determines if the placement of the current pragma is appropriate
585 -- for a configuration pragma.
587 function Is_In_Context_Clause return Boolean;
588 -- Returns True if pragma appears within the context clause of a unit,
589 -- and False for any other placement (does not generate any messages).
591 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
592 -- Analyzes the argument, and determines if it is a static string
593 -- expression, returns True if so, False if non-static or not String.
595 procedure Pragma_Misplaced;
596 pragma No_Return (Pragma_Misplaced);
597 -- Issue fatal error message for misplaced pragma
599 procedure Process_Atomic_Shared_Volatile;
600 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
601 -- Shared is an obsolete Ada 83 pragma, treated as being identical
602 -- in effect to pragma Atomic.
604 procedure Process_Compile_Time_Warning_Or_Error;
605 -- Common processing for Compile_Time_Error and Compile_Time_Warning
607 procedure Process_Convention
608 (C : out Convention_Id;
609 Ent : out Entity_Id);
610 -- Common processing for Convention, Interface, Import and Export.
611 -- Checks first two arguments of pragma, and sets the appropriate
612 -- convention value in the specified entity or entities. On return
613 -- C is the convention, Ent is the referenced entity.
615 procedure Process_Extended_Import_Export_Exception_Pragma
616 (Arg_Internal : Node_Id;
617 Arg_External : Node_Id;
620 -- Common processing for the pragmas Import/Export_Exception. The three
621 -- arguments correspond to the three named parameters of the pragma. An
622 -- argument is empty if the corresponding parameter is not present in
625 procedure Process_Extended_Import_Export_Object_Pragma
626 (Arg_Internal : Node_Id;
627 Arg_External : Node_Id;
629 -- Common processing for the pragmas Import/Export_Object. The three
630 -- arguments correspond to the three named parameters of the pragmas. An
631 -- argument is empty if the corresponding parameter is not present in
634 procedure Process_Extended_Import_Export_Internal_Arg
635 (Arg_Internal : Node_Id := Empty);
636 -- Common processing for all extended Import and Export pragmas. The
637 -- argument is the pragma parameter for the Internal argument. If
638 -- Arg_Internal is empty or inappropriate, an error message is posted.
639 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
640 -- set to identify the referenced entity.
642 procedure Process_Extended_Import_Export_Subprogram_Pragma
643 (Arg_Internal : Node_Id;
644 Arg_External : Node_Id;
645 Arg_Parameter_Types : Node_Id;
646 Arg_Result_Type : Node_Id := Empty;
647 Arg_Mechanism : Node_Id;
648 Arg_Result_Mechanism : Node_Id := Empty;
649 Arg_First_Optional_Parameter : Node_Id := Empty);
650 -- Common processing for all extended Import and Export pragmas applying
651 -- to subprograms. The caller omits any arguments that do not apply to
652 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
653 -- only in the Import_Function and Export_Function cases). The argument
654 -- names correspond to the allowed pragma association identifiers.
656 procedure Process_Generic_List;
657 -- Common processing for Share_Generic and Inline_Generic
659 procedure Process_Import_Or_Interface;
660 -- Common processing for Import of Interface
662 procedure Process_Import_Predefined_Type;
663 -- Processing for completing a type with pragma Import. This is used
664 -- to declare types that match predefined C types, especially for cases
665 -- without corresponding Ada predefined type.
667 procedure Process_Inline (Active : Boolean);
668 -- Common processing for Inline and Inline_Always. The parameter
669 -- indicates if the inline pragma is active, i.e. if it should actually
670 -- cause inlining to occur.
672 procedure Process_Interface_Name
673 (Subprogram_Def : Entity_Id;
676 -- Given the last two arguments of pragma Import, pragma Export, or
677 -- pragma Interface_Name, performs validity checks and sets the
678 -- Interface_Name field of the given subprogram entity to the
679 -- appropriate external or link name, depending on the arguments given.
680 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
681 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
682 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
683 -- nor Link_Arg is present, the interface name is set to the default
684 -- from the subprogram name.
686 procedure Process_Interrupt_Or_Attach_Handler;
687 -- Common processing for Interrupt and Attach_Handler pragmas
689 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
690 -- Common processing for Restrictions and Restriction_Warnings pragmas.
691 -- Warn is True for Restriction_Warnings, or for Restrictions if the
692 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
693 -- is not set in the Restrictions case.
695 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
696 -- Common processing for Suppress and Unsuppress. The boolean parameter
697 -- Suppress_Case is True for the Suppress case, and False for the
700 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
701 -- This procedure sets the Is_Exported flag for the given entity,
702 -- checking that the entity was not previously imported. Arg is
703 -- the argument that specified the entity. A check is also made
704 -- for exporting inappropriate entities.
706 procedure Set_Extended_Import_Export_External_Name
707 (Internal_Ent : Entity_Id;
708 Arg_External : Node_Id);
709 -- Common processing for all extended import export pragmas. The first
710 -- argument, Internal_Ent, is the internal entity, which has already
711 -- been checked for validity by the caller. Arg_External is from the
712 -- Import or Export pragma, and may be null if no External parameter
713 -- was present. If Arg_External is present and is a non-null string
714 -- (a null string is treated as the default), then the Interface_Name
715 -- field of Internal_Ent is set appropriately.
717 procedure Set_Imported (E : Entity_Id);
718 -- This procedure sets the Is_Imported flag for the given entity,
719 -- checking that it is not previously exported or imported.
721 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
722 -- Mech is a parameter passing mechanism (see Import_Function syntax
723 -- for MECHANISM_NAME). This routine checks that the mechanism argument
724 -- has the right form, and if not issues an error message. If the
725 -- argument has the right form then the Mechanism field of Ent is
726 -- set appropriately.
728 procedure Set_Ravenscar_Profile (N : Node_Id);
729 -- Activate the set of configuration pragmas and restrictions that make
730 -- up the Ravenscar Profile. N is the corresponding pragma node, which
731 -- is used for error messages on any constructs that violate the
734 ---------------------
735 -- Ada_2005_Pragma --
736 ---------------------
738 procedure Ada_2005_Pragma is
740 if Ada_Version <= Ada_95 then
741 Check_Restriction (No_Implementation_Pragmas, N);
745 ---------------------
746 -- Ada_2012_Pragma --
747 ---------------------
749 procedure Ada_2012_Pragma is
751 if Ada_Version <= Ada_2005 then
752 Check_Restriction (No_Implementation_Pragmas, N);
756 --------------------------
757 -- Check_Ada_83_Warning --
758 --------------------------
760 procedure Check_Ada_83_Warning is
762 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
763 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
765 end Check_Ada_83_Warning;
767 ---------------------
768 -- Check_Arg_Count --
769 ---------------------
771 procedure Check_Arg_Count (Required : Nat) is
773 if Arg_Count /= Required then
774 Error_Pragma ("wrong number of arguments for pragma%");
778 --------------------------------
779 -- Check_Arg_Is_External_Name --
780 --------------------------------
782 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
783 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
786 if Nkind (Argx) = N_Identifier then
790 Analyze_And_Resolve (Argx, Standard_String);
792 if Is_OK_Static_Expression (Argx) then
795 elsif Etype (Argx) = Any_Type then
798 -- An interesting special case, if we have a string literal and
799 -- we are in Ada 83 mode, then we allow it even though it will
800 -- not be flagged as static. This allows expected Ada 83 mode
801 -- use of external names which are string literals, even though
802 -- technically these are not static in Ada 83.
804 elsif Ada_Version = Ada_83
805 and then Nkind (Argx) = N_String_Literal
809 -- Static expression that raises Constraint_Error. This has
810 -- already been flagged, so just exit from pragma processing.
812 elsif Is_Static_Expression (Argx) then
815 -- Here we have a real error (non-static expression)
818 Error_Msg_Name_1 := Pname;
822 "argument for pragma% must be a identifier or "
823 & "static string expression!";
826 Flag_Non_Static_Expr (Msg, Argx);
831 end Check_Arg_Is_External_Name;
833 -----------------------------
834 -- Check_Arg_Is_Identifier --
835 -----------------------------
837 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
838 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
840 if Nkind (Argx) /= N_Identifier then
842 ("argument for pragma% must be identifier", Argx);
844 end Check_Arg_Is_Identifier;
846 ----------------------------------
847 -- Check_Arg_Is_Integer_Literal --
848 ----------------------------------
850 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
851 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
853 if Nkind (Argx) /= N_Integer_Literal then
855 ("argument for pragma% must be integer literal", Argx);
857 end Check_Arg_Is_Integer_Literal;
859 -------------------------------------------
860 -- Check_Arg_Is_Library_Level_Local_Name --
861 -------------------------------------------
865 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
866 -- | library_unit_NAME
868 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
870 Check_Arg_Is_Local_Name (Arg);
872 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
873 and then Comes_From_Source (N)
876 ("argument for pragma% must be library level entity", Arg);
878 end Check_Arg_Is_Library_Level_Local_Name;
880 -----------------------------
881 -- Check_Arg_Is_Local_Name --
882 -----------------------------
886 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
887 -- | library_unit_NAME
889 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
890 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
895 if Nkind (Argx) not in N_Direct_Name
896 and then (Nkind (Argx) /= N_Attribute_Reference
897 or else Present (Expressions (Argx))
898 or else Nkind (Prefix (Argx)) /= N_Identifier)
899 and then (not Is_Entity_Name (Argx)
900 or else not Is_Compilation_Unit (Entity (Argx)))
902 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
905 -- No further check required if not an entity name
907 if not Is_Entity_Name (Argx) then
913 Ent : constant Entity_Id := Entity (Argx);
914 Scop : constant Entity_Id := Scope (Ent);
916 -- Case of a pragma applied to a compilation unit: pragma must
917 -- occur immediately after the program unit in the compilation.
919 if Is_Compilation_Unit (Ent) then
921 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
923 -- Case of pragma placed immediately after spec
925 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
928 -- Case of pragma placed immediately after body
930 elsif Nkind (Decl) = N_Subprogram_Declaration
931 and then Present (Corresponding_Body (Decl))
935 (Parent (Unit_Declaration_Node
936 (Corresponding_Body (Decl))));
938 -- All other cases are illegal
945 -- Special restricted placement rule from 10.2.1(11.8/2)
947 elsif Is_Generic_Formal (Ent)
948 and then Prag_Id = Pragma_Preelaborable_Initialization
950 OK := List_Containing (N) =
951 Generic_Formal_Declarations
952 (Unit_Declaration_Node (Scop));
954 -- Default case, just check that the pragma occurs in the scope
955 -- of the entity denoted by the name.
958 OK := Current_Scope = Scop;
963 ("pragma% argument must be in same declarative part", Arg);
967 end Check_Arg_Is_Local_Name;
969 ---------------------------------
970 -- Check_Arg_Is_Locking_Policy --
971 ---------------------------------
973 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
974 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
977 Check_Arg_Is_Identifier (Argx);
979 if not Is_Locking_Policy_Name (Chars (Argx)) then
980 Error_Pragma_Arg ("& 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;
1035 ---------------------------------
1036 -- Check_Arg_Is_Queuing_Policy --
1037 ---------------------------------
1039 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1040 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1043 Check_Arg_Is_Identifier (Argx);
1045 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1046 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1048 end Check_Arg_Is_Queuing_Policy;
1050 ------------------------------------
1051 -- Check_Arg_Is_Static_Expression --
1052 ------------------------------------
1054 procedure Check_Arg_Is_Static_Expression
1056 Typ : Entity_Id := Empty)
1058 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1061 if Present (Typ) then
1062 Analyze_And_Resolve (Argx, Typ);
1064 Analyze_And_Resolve (Argx);
1067 if Is_OK_Static_Expression (Argx) then
1070 elsif Etype (Argx) = Any_Type then
1073 -- An interesting special case, if we have a string literal and we
1074 -- are in Ada 83 mode, then we allow it even though it will not be
1075 -- flagged as static. This allows the use of Ada 95 pragmas like
1076 -- Import in Ada 83 mode. They will of course be flagged with
1077 -- warnings as usual, but will not cause errors.
1079 elsif Ada_Version = Ada_83
1080 and then Nkind (Argx) = N_String_Literal
1084 -- Static expression that raises Constraint_Error. This has already
1085 -- been flagged, so just exit from pragma processing.
1087 elsif Is_Static_Expression (Argx) then
1090 -- Finally, we have a real error
1093 Error_Msg_Name_1 := Pname;
1097 "argument for pragma% must be a static expression!";
1100 Flag_Non_Static_Expr (Msg, Argx);
1105 end Check_Arg_Is_Static_Expression;
1107 ------------------------------------------
1108 -- Check_Arg_Is_Task_Dispatching_Policy --
1109 ------------------------------------------
1111 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1112 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1115 Check_Arg_Is_Identifier (Argx);
1117 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1119 ("& is not a valid task dispatching policy name", Argx);
1121 end Check_Arg_Is_Task_Dispatching_Policy;
1123 ---------------------
1124 -- Check_Arg_Order --
1125 ---------------------
1127 procedure Check_Arg_Order (Names : Name_List) is
1130 Highest_So_Far : Natural := 0;
1131 -- Highest index in Names seen do far
1135 for J in 1 .. Arg_Count loop
1136 if Chars (Arg) /= No_Name then
1137 for K in Names'Range loop
1138 if Chars (Arg) = Names (K) then
1139 if K < Highest_So_Far then
1140 Error_Msg_Name_1 := Pname;
1142 ("parameters out of order for pragma%", Arg);
1143 Error_Msg_Name_1 := Names (K);
1144 Error_Msg_Name_2 := Names (Highest_So_Far);
1145 Error_Msg_N ("\% must appear before %", Arg);
1149 Highest_So_Far := K;
1157 end Check_Arg_Order;
1159 --------------------------------
1160 -- Check_At_Least_N_Arguments --
1161 --------------------------------
1163 procedure Check_At_Least_N_Arguments (N : Nat) is
1165 if Arg_Count < N then
1166 Error_Pragma ("too few arguments for pragma%");
1168 end Check_At_Least_N_Arguments;
1170 -------------------------------
1171 -- Check_At_Most_N_Arguments --
1172 -------------------------------
1174 procedure Check_At_Most_N_Arguments (N : Nat) is
1177 if Arg_Count > N then
1179 for J in 1 .. N loop
1181 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1184 end Check_At_Most_N_Arguments;
1186 ---------------------
1187 -- Check_Component --
1188 ---------------------
1190 procedure Check_Component
1193 In_Variant_Part : Boolean := False)
1195 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1196 Sindic : constant Node_Id :=
1197 Subtype_Indication (Component_Definition (Comp));
1198 Typ : constant Entity_Id := Etype (Comp_Id);
1200 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1201 -- Determine whether entity Id appears inside a generic body.
1202 -- Shouldn't this be in a more general place ???
1204 -------------------------
1205 -- Inside_Generic_Body --
1206 -------------------------
1208 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1213 while Present (S) and then S /= Standard_Standard loop
1214 if Ekind (S) = E_Generic_Package
1215 and then In_Package_Body (S)
1224 end Inside_Generic_Body;
1226 -- Start of processing for Check_Component
1229 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1230 -- object constraint, then the component type shall be an Unchecked_
1233 if Nkind (Sindic) = N_Subtype_Indication
1234 and then Has_Per_Object_Constraint (Comp_Id)
1235 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1238 ("component subtype subject to per-object constraint " &
1239 "must be an Unchecked_Union", Comp);
1241 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1242 -- the body of a generic unit, or within the body of any of its
1243 -- descendant library units, no part of the type of a component
1244 -- declared in a variant_part of the unchecked union type shall be of
1245 -- a formal private type or formal private extension declared within
1246 -- the formal part of the generic unit.
1248 elsif Ada_Version >= Ada_2012
1249 and then Inside_Generic_Body (UU_Typ)
1250 and then In_Variant_Part
1251 and then Is_Private_Type (Typ)
1252 and then Is_Generic_Type (Typ)
1255 ("component of Unchecked_Union cannot be of generic type", Comp);
1257 elsif Needs_Finalization (Typ) then
1259 ("component of Unchecked_Union cannot be controlled", Comp);
1261 elsif Has_Task (Typ) then
1263 ("component of Unchecked_Union cannot have tasks", Comp);
1265 end Check_Component;
1267 ----------------------------
1268 -- Check_Duplicate_Pragma --
1269 ----------------------------
1271 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1275 -- Nothing to do if this pragma comes from an aspect specification,
1276 -- since we could not be duplicating a pragma, and we dealt with the
1277 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1279 if From_Aspect_Specification (N) then
1283 -- Otherwise current pragma may duplicate previous pragma or a
1284 -- previously given aspect specification for the same pragma.
1286 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1289 Error_Msg_Name_1 := Pragma_Name (N);
1290 Error_Msg_Sloc := Sloc (P);
1292 if Nkind (P) = N_Aspect_Specification
1293 or else From_Aspect_Specification (P)
1295 Error_Msg_NE ("aspect% for & previously given#", N, E);
1297 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1302 end Check_Duplicate_Pragma;
1304 ----------------------------------
1305 -- Check_Duplicated_Export_Name --
1306 ----------------------------------
1308 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1309 String_Val : constant String_Id := Strval (Nam);
1312 -- We are only interested in the export case, and in the case of
1313 -- generics, it is the instance, not the template, that is the
1314 -- problem (the template will generate a warning in any case).
1316 if not Inside_A_Generic
1317 and then (Prag_Id = Pragma_Export
1319 Prag_Id = Pragma_Export_Procedure
1321 Prag_Id = Pragma_Export_Valued_Procedure
1323 Prag_Id = Pragma_Export_Function)
1325 for J in Externals.First .. Externals.Last loop
1326 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1327 Error_Msg_Sloc := Sloc (Externals.Table (J));
1328 Error_Msg_N ("external name duplicates name given#", Nam);
1333 Externals.Append (Nam);
1335 end Check_Duplicated_Export_Name;
1337 -------------------------
1338 -- Check_First_Subtype --
1339 -------------------------
1341 procedure Check_First_Subtype (Arg : Node_Id) is
1342 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1343 Ent : constant Entity_Id := Entity (Argx);
1346 if Is_First_Subtype (Ent) then
1349 elsif Is_Type (Ent) then
1351 ("pragma% cannot apply to subtype", Argx);
1353 elsif Is_Object (Ent) then
1355 ("pragma% cannot apply to object, requires a type", Argx);
1359 ("pragma% cannot apply to&, requires a type", Argx);
1361 end Check_First_Subtype;
1363 ---------------------------
1364 -- Check_In_Main_Program --
1365 ---------------------------
1367 procedure Check_In_Main_Program is
1368 P : constant Node_Id := Parent (N);
1371 -- Must be at in subprogram body
1373 if Nkind (P) /= N_Subprogram_Body then
1374 Error_Pragma ("% pragma allowed only in subprogram");
1376 -- Otherwise warn if obviously not main program
1378 elsif Present (Parameter_Specifications (Specification (P)))
1379 or else not Is_Compilation_Unit (Defining_Entity (P))
1381 Error_Msg_Name_1 := Pname;
1383 ("?pragma% is only effective in main program", N);
1385 end Check_In_Main_Program;
1387 ---------------------------------------
1388 -- Check_Interrupt_Or_Attach_Handler --
1389 ---------------------------------------
1391 procedure Check_Interrupt_Or_Attach_Handler is
1392 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1393 Handler_Proc, Proc_Scope : Entity_Id;
1398 if Prag_Id = Pragma_Interrupt_Handler then
1399 Check_Restriction (No_Dynamic_Attachment, N);
1402 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1403 Proc_Scope := Scope (Handler_Proc);
1405 -- On AAMP only, a pragma Interrupt_Handler is supported for
1406 -- nonprotected parameterless procedures.
1408 if not AAMP_On_Target
1409 or else Prag_Id = Pragma_Attach_Handler
1411 if Ekind (Proc_Scope) /= E_Protected_Type then
1413 ("argument of pragma% must be protected procedure", Arg1);
1416 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1417 Error_Pragma ("pragma% must be in protected definition");
1421 if not Is_Library_Level_Entity (Proc_Scope)
1422 or else (AAMP_On_Target
1423 and then not Is_Library_Level_Entity (Handler_Proc))
1426 ("argument for pragma% must be library level entity", Arg1);
1429 -- AI05-0033: A pragma cannot appear within a generic body, because
1430 -- instance can be in a nested scope. The check that protected type
1431 -- is itself a library-level declaration is done elsewhere.
1433 -- Note: we omit this check in Codepeer mode to properly handle code
1434 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1436 if Inside_A_Generic then
1437 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1438 and then In_Package_Body (Scope (Current_Scope))
1439 and then not CodePeer_Mode
1441 Error_Pragma ("pragma% cannot be used inside a generic");
1444 end Check_Interrupt_Or_Attach_Handler;
1446 -------------------------------------------
1447 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1448 -------------------------------------------
1450 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1459 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1462 elsif Nkind_In (P, N_Package_Specification,
1467 -- Note: the following tests seem a little peculiar, because
1468 -- they test for bodies, but if we were in the statement part
1469 -- of the body, we would already have hit the handled statement
1470 -- sequence, so the only way we get here is by being in the
1471 -- declarative part of the body.
1473 elsif Nkind_In (P, N_Subprogram_Body,
1484 Error_Pragma ("pragma% is not in declarative part or package spec");
1485 end Check_Is_In_Decl_Part_Or_Package_Spec;
1487 -------------------------
1488 -- Check_No_Identifier --
1489 -------------------------
1491 procedure Check_No_Identifier (Arg : Node_Id) is
1493 if Nkind (Arg) = N_Pragma_Argument_Association
1494 and then Chars (Arg) /= No_Name
1496 Error_Pragma_Arg_Ident
1497 ("pragma% does not permit identifier& here", Arg);
1499 end Check_No_Identifier;
1501 --------------------------
1502 -- Check_No_Identifiers --
1503 --------------------------
1505 procedure Check_No_Identifiers is
1508 if Arg_Count > 0 then
1510 while Present (Arg_Node) loop
1511 Check_No_Identifier (Arg_Node);
1515 end Check_No_Identifiers;
1517 ------------------------
1518 -- Check_No_Link_Name --
1519 ------------------------
1521 procedure Check_No_Link_Name is
1524 and then Chars (Arg3) = Name_Link_Name
1529 if Present (Arg4) then
1531 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1533 end Check_No_Link_Name;
1535 -------------------------------
1536 -- Check_Optional_Identifier --
1537 -------------------------------
1539 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1542 and then Nkind (Arg) = N_Pragma_Argument_Association
1543 and then Chars (Arg) /= No_Name
1545 if Chars (Arg) /= Id then
1546 Error_Msg_Name_1 := Pname;
1547 Error_Msg_Name_2 := Id;
1548 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1552 end Check_Optional_Identifier;
1554 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1556 Name_Buffer (1 .. Id'Length) := Id;
1557 Name_Len := Id'Length;
1558 Check_Optional_Identifier (Arg, Name_Find);
1559 end Check_Optional_Identifier;
1561 --------------------------------------
1562 -- Check_Precondition_Postcondition --
1563 --------------------------------------
1565 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1569 procedure Chain_PPC (PO : Node_Id);
1570 -- If PO is a subprogram declaration node (or a generic subprogram
1571 -- declaration node), then the precondition/postcondition applies
1572 -- to this subprogram and the processing for the pragma is completed.
1573 -- Otherwise the pragma is misplaced.
1579 procedure Chain_PPC (PO : Node_Id) is
1584 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1585 if not From_Aspect_Specification (N) then
1587 ("pragma% cannot be applied to abstract subprogram");
1589 elsif Class_Present (N) then
1594 ("aspect % requires ''Class for abstract subprogram");
1597 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1598 N_Generic_Subprogram_Declaration,
1599 N_Entry_Declaration)
1604 -- Here if we have [generic] subprogram or entry declaration
1606 if Nkind (PO) = N_Entry_Declaration then
1607 S := Defining_Entity (PO);
1609 S := Defining_Unit_Name (Specification (PO));
1612 -- Make sure we do not have the case of a precondition pragma when
1613 -- the Pre'Class aspect is present.
1615 -- We do this by looking at pragmas already chained to the entity
1616 -- since the aspect derived pragma will be put on this list first.
1618 if Pragma_Name (N) = Name_Precondition then
1619 if not From_Aspect_Specification (N) then
1620 P := Spec_PPC_List (S);
1621 while Present (P) loop
1622 if Pragma_Name (P) = Name_Precondition
1623 and then From_Aspect_Specification (P)
1624 and then Class_Present (P)
1626 Error_Msg_Sloc := Sloc (P);
1628 ("pragma% not allowed, `Pre''Class` aspect given#");
1631 P := Next_Pragma (P);
1636 -- Similarly check for Pre with inherited Pre'Class. Note that
1637 -- we cover the aspect case as well here.
1639 if Pragma_Name (N) = Name_Precondition
1640 and then not Class_Present (N)
1643 Inherited : constant Subprogram_List :=
1644 Inherited_Subprograms (S);
1648 for J in Inherited'Range loop
1649 P := Spec_PPC_List (Inherited (J));
1650 while Present (P) loop
1651 if Pragma_Name (P) = Name_Precondition
1652 and then Class_Present (P)
1654 Error_Msg_Sloc := Sloc (P);
1656 ("pragma% not allowed, `Pre''Class` "
1657 & "aspect inherited from#");
1660 P := Next_Pragma (P);
1666 -- Note: we do not analyze the pragma at this point. Instead we
1667 -- delay this analysis until the end of the declarative part in
1668 -- which the pragma appears. This implements the required delay
1669 -- in this analysis, allowing forward references. The analysis
1670 -- happens at the end of Analyze_Declarations.
1672 -- Chain spec PPC pragma to list for subprogram
1674 Set_Next_Pragma (N, Spec_PPC_List (S));
1675 Set_Spec_PPC_List (S, N);
1677 -- Return indicating spec case
1683 -- Start of processing for Check_Precondition_Postcondition
1686 if not Is_List_Member (N) then
1690 -- Preanalyze message argument if present. Visibility in this
1691 -- argument is established at the point of pragma occurrence.
1693 if Arg_Count = 2 then
1694 Check_Optional_Identifier (Arg2, Name_Message);
1695 Preanalyze_Spec_Expression
1696 (Get_Pragma_Arg (Arg2), Standard_String);
1699 -- Record if pragma is enabled
1701 if Check_Enabled (Pname) then
1702 Set_Pragma_Enabled (N);
1703 Set_SCO_Pragma_Enabled (Loc);
1706 -- If we are within an inlined body, the legality of the pragma
1707 -- has been checked already.
1709 if In_Inlined_Body then
1714 -- Search prior declarations
1717 while Present (Prev (P)) loop
1720 -- If the previous node is a generic subprogram, do not go to to
1721 -- the original node, which is the unanalyzed tree: we need to
1722 -- attach the pre/postconditions to the analyzed version at this
1723 -- point. They get propagated to the original tree when analyzing
1724 -- the corresponding body.
1726 if Nkind (P) not in N_Generic_Declaration then
1727 PO := Original_Node (P);
1732 -- Skip past prior pragma
1734 if Nkind (PO) = N_Pragma then
1737 -- Skip stuff not coming from source
1739 elsif not Comes_From_Source (PO) then
1742 -- Only remaining possibility is subprogram declaration
1750 -- If we fall through loop, pragma is at start of list, so see if it
1751 -- is at the start of declarations of a subprogram body.
1753 if Nkind (Parent (N)) = N_Subprogram_Body
1754 and then List_Containing (N) = Declarations (Parent (N))
1756 if Operating_Mode /= Generate_Code
1757 or else Inside_A_Generic
1759 -- Analyze pragma expression for correctness and for ASIS use
1761 Preanalyze_Spec_Expression
1762 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1768 -- See if it is in the pragmas after a library level subprogram
1770 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1771 Chain_PPC (Unit (Parent (Parent (N))));
1775 -- If we fall through, pragma was misplaced
1778 end Check_Precondition_Postcondition;
1780 -----------------------------
1781 -- Check_Static_Constraint --
1782 -----------------------------
1784 -- Note: for convenience in writing this procedure, in addition to
1785 -- the officially (i.e. by spec) allowed argument which is always a
1786 -- constraint, it also allows ranges and discriminant associations.
1787 -- Above is not clear ???
1789 procedure Check_Static_Constraint (Constr : Node_Id) is
1791 procedure Require_Static (E : Node_Id);
1792 -- Require given expression to be static expression
1794 --------------------
1795 -- Require_Static --
1796 --------------------
1798 procedure Require_Static (E : Node_Id) is
1800 if not Is_OK_Static_Expression (E) then
1801 Flag_Non_Static_Expr
1802 ("non-static constraint not allowed in Unchecked_Union!", E);
1807 -- Start of processing for Check_Static_Constraint
1810 case Nkind (Constr) is
1811 when N_Discriminant_Association =>
1812 Require_Static (Expression (Constr));
1815 Require_Static (Low_Bound (Constr));
1816 Require_Static (High_Bound (Constr));
1818 when N_Attribute_Reference =>
1819 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1820 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1822 when N_Range_Constraint =>
1823 Check_Static_Constraint (Range_Expression (Constr));
1825 when N_Index_Or_Discriminant_Constraint =>
1829 IDC := First (Constraints (Constr));
1830 while Present (IDC) loop
1831 Check_Static_Constraint (IDC);
1839 end Check_Static_Constraint;
1841 --------------------------------------
1842 -- Check_Valid_Configuration_Pragma --
1843 --------------------------------------
1845 -- A configuration pragma must appear in the context clause of a
1846 -- compilation unit, and only other pragmas may precede it. Note that
1847 -- the test also allows use in a configuration pragma file.
1849 procedure Check_Valid_Configuration_Pragma is
1851 if not Is_Configuration_Pragma then
1852 Error_Pragma ("incorrect placement for configuration pragma%");
1854 end Check_Valid_Configuration_Pragma;
1856 -------------------------------------
1857 -- Check_Valid_Library_Unit_Pragma --
1858 -------------------------------------
1860 procedure Check_Valid_Library_Unit_Pragma is
1862 Parent_Node : Node_Id;
1863 Unit_Name : Entity_Id;
1864 Unit_Kind : Node_Kind;
1865 Unit_Node : Node_Id;
1866 Sindex : Source_File_Index;
1869 if not Is_List_Member (N) then
1873 Plist := List_Containing (N);
1874 Parent_Node := Parent (Plist);
1876 if Parent_Node = Empty then
1879 -- Case of pragma appearing after a compilation unit. In this case
1880 -- it must have an argument with the corresponding name and must
1881 -- be part of the following pragmas of its parent.
1883 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1884 if Plist /= Pragmas_After (Parent_Node) then
1887 elsif Arg_Count = 0 then
1889 ("argument required if outside compilation unit");
1892 Check_No_Identifiers;
1893 Check_Arg_Count (1);
1894 Unit_Node := Unit (Parent (Parent_Node));
1895 Unit_Kind := Nkind (Unit_Node);
1897 Analyze (Get_Pragma_Arg (Arg1));
1899 if Unit_Kind = N_Generic_Subprogram_Declaration
1900 or else Unit_Kind = N_Subprogram_Declaration
1902 Unit_Name := Defining_Entity (Unit_Node);
1904 elsif Unit_Kind in N_Generic_Instantiation then
1905 Unit_Name := Defining_Entity (Unit_Node);
1908 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1911 if Chars (Unit_Name) /=
1912 Chars (Entity (Get_Pragma_Arg (Arg1)))
1915 ("pragma% argument is not current unit name", Arg1);
1918 if Ekind (Unit_Name) = E_Package
1919 and then Present (Renamed_Entity (Unit_Name))
1921 Error_Pragma ("pragma% not allowed for renamed package");
1925 -- Pragma appears other than after a compilation unit
1928 -- Here we check for the generic instantiation case and also
1929 -- for the case of processing a generic formal package. We
1930 -- detect these cases by noting that the Sloc on the node
1931 -- does not belong to the current compilation unit.
1933 Sindex := Source_Index (Current_Sem_Unit);
1935 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1936 Rewrite (N, Make_Null_Statement (Loc));
1939 -- If before first declaration, the pragma applies to the
1940 -- enclosing unit, and the name if present must be this name.
1942 elsif Is_Before_First_Decl (N, Plist) then
1943 Unit_Node := Unit_Declaration_Node (Current_Scope);
1944 Unit_Kind := Nkind (Unit_Node);
1946 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1949 elsif Unit_Kind = N_Subprogram_Body
1950 and then not Acts_As_Spec (Unit_Node)
1954 elsif Nkind (Parent_Node) = N_Package_Body then
1957 elsif Nkind (Parent_Node) = N_Package_Specification
1958 and then Plist = Private_Declarations (Parent_Node)
1962 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1963 or else Nkind (Parent_Node) =
1964 N_Generic_Subprogram_Declaration)
1965 and then Plist = Generic_Formal_Declarations (Parent_Node)
1969 elsif Arg_Count > 0 then
1970 Analyze (Get_Pragma_Arg (Arg1));
1972 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
1974 ("name in pragma% must be enclosing unit", Arg1);
1977 -- It is legal to have no argument in this context
1983 -- Error if not before first declaration. This is because a
1984 -- library unit pragma argument must be the name of a library
1985 -- unit (RM 10.1.5(7)), but the only names permitted in this
1986 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1987 -- generic subprogram declarations or generic instantiations.
1991 ("pragma% misplaced, must be before first declaration");
1995 end Check_Valid_Library_Unit_Pragma;
2001 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2002 Clist : constant Node_Id := Component_List (Variant);
2006 if not Is_Non_Empty_List (Component_Items (Clist)) then
2008 ("Unchecked_Union may not have empty component list",
2013 Comp := First (Component_Items (Clist));
2014 while Present (Comp) loop
2015 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2024 procedure Error_Pragma (Msg : String) is
2025 MsgF : String := Msg;
2027 Error_Msg_Name_1 := Pname;
2029 Error_Msg_N (MsgF, N);
2033 ----------------------
2034 -- Error_Pragma_Arg --
2035 ----------------------
2037 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2038 MsgF : String := Msg;
2040 Error_Msg_Name_1 := Pname;
2042 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2044 end Error_Pragma_Arg;
2046 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2047 MsgF : String := Msg1;
2049 Error_Msg_Name_1 := Pname;
2051 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2052 Error_Pragma_Arg (Msg2, Arg);
2053 end Error_Pragma_Arg;
2055 ----------------------------
2056 -- Error_Pragma_Arg_Ident --
2057 ----------------------------
2059 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2060 MsgF : String := Msg;
2062 Error_Msg_Name_1 := Pname;
2064 Error_Msg_N (MsgF, Arg);
2066 end Error_Pragma_Arg_Ident;
2068 ----------------------
2069 -- Error_Pragma_Ref --
2070 ----------------------
2072 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2073 MsgF : String := Msg;
2075 Error_Msg_Name_1 := Pname;
2077 Error_Msg_Sloc := Sloc (Ref);
2078 Error_Msg_NE (MsgF, N, Ref);
2080 end Error_Pragma_Ref;
2082 ------------------------
2083 -- Find_Lib_Unit_Name --
2084 ------------------------
2086 function Find_Lib_Unit_Name return Entity_Id is
2088 -- Return inner compilation unit entity, for case of nested
2089 -- categorization pragmas. This happens in generic unit.
2091 if Nkind (Parent (N)) = N_Package_Specification
2092 and then Defining_Entity (Parent (N)) /= Current_Scope
2094 return Defining_Entity (Parent (N));
2096 return Current_Scope;
2098 end Find_Lib_Unit_Name;
2100 ----------------------------
2101 -- Find_Program_Unit_Name --
2102 ----------------------------
2104 procedure Find_Program_Unit_Name (Id : Node_Id) is
2105 Unit_Name : Entity_Id;
2106 Unit_Kind : Node_Kind;
2107 P : constant Node_Id := Parent (N);
2110 if Nkind (P) = N_Compilation_Unit then
2111 Unit_Kind := Nkind (Unit (P));
2113 if Unit_Kind = N_Subprogram_Declaration
2114 or else Unit_Kind = N_Package_Declaration
2115 or else Unit_Kind in N_Generic_Declaration
2117 Unit_Name := Defining_Entity (Unit (P));
2119 if Chars (Id) = Chars (Unit_Name) then
2120 Set_Entity (Id, Unit_Name);
2121 Set_Etype (Id, Etype (Unit_Name));
2123 Set_Etype (Id, Any_Type);
2125 ("cannot find program unit referenced by pragma%");
2129 Set_Etype (Id, Any_Type);
2130 Error_Pragma ("pragma% inapplicable to this unit");
2136 end Find_Program_Unit_Name;
2138 -----------------------------------------
2139 -- Find_Unique_Parameterless_Procedure --
2140 -----------------------------------------
2142 function Find_Unique_Parameterless_Procedure
2144 Arg : Node_Id) return Entity_Id
2146 Proc : Entity_Id := Empty;
2149 -- The body of this procedure needs some comments ???
2151 if not Is_Entity_Name (Name) then
2153 ("argument of pragma% must be entity name", Arg);
2155 elsif not Is_Overloaded (Name) then
2156 Proc := Entity (Name);
2158 if Ekind (Proc) /= E_Procedure
2159 or else Present (First_Formal (Proc))
2162 ("argument of pragma% must be parameterless procedure", Arg);
2167 Found : Boolean := False;
2169 Index : Interp_Index;
2172 Get_First_Interp (Name, Index, It);
2173 while Present (It.Nam) loop
2176 if Ekind (Proc) = E_Procedure
2177 and then No (First_Formal (Proc))
2181 Set_Entity (Name, Proc);
2182 Set_Is_Overloaded (Name, False);
2185 ("ambiguous handler name for pragma% ", Arg);
2189 Get_Next_Interp (Index, It);
2194 ("argument of pragma% must be parameterless procedure",
2197 Proc := Entity (Name);
2203 end Find_Unique_Parameterless_Procedure;
2209 procedure Fix_Error (Msg : in out String) is
2211 if From_Aspect_Specification (N) then
2212 for J in Msg'First .. Msg'Last - 5 loop
2213 if Msg (J .. J + 5) = "pragma" then
2214 Msg (J .. J + 5) := "aspect";
2218 if Error_Msg_Name_1 = Name_Precondition then
2219 Error_Msg_Name_1 := Name_Pre;
2220 elsif Error_Msg_Name_1 = Name_Postcondition then
2221 Error_Msg_Name_1 := Name_Post;
2226 -------------------------
2227 -- Gather_Associations --
2228 -------------------------
2230 procedure Gather_Associations
2232 Args : out Args_List)
2237 -- Initialize all parameters to Empty
2239 for J in Args'Range loop
2243 -- That's all we have to do if there are no argument associations
2245 if No (Pragma_Argument_Associations (N)) then
2249 -- Otherwise first deal with any positional parameters present
2251 Arg := First (Pragma_Argument_Associations (N));
2252 for Index in Args'Range loop
2253 exit when No (Arg) or else Chars (Arg) /= No_Name;
2254 Args (Index) := Get_Pragma_Arg (Arg);
2258 -- Positional parameters all processed, if any left, then we
2259 -- have too many positional parameters.
2261 if Present (Arg) and then Chars (Arg) = No_Name then
2263 ("too many positional associations for pragma%", Arg);
2266 -- Process named parameters if any are present
2268 while Present (Arg) loop
2269 if Chars (Arg) = No_Name then
2271 ("positional association cannot follow named association",
2275 for Index in Names'Range loop
2276 if Names (Index) = Chars (Arg) then
2277 if Present (Args (Index)) then
2279 ("duplicate argument association for pragma%", Arg);
2281 Args (Index) := Get_Pragma_Arg (Arg);
2286 if Index = Names'Last then
2287 Error_Msg_Name_1 := Pname;
2288 Error_Msg_N ("pragma% does not allow & argument", Arg);
2290 -- Check for possible misspelling
2292 for Index1 in Names'Range loop
2293 if Is_Bad_Spelling_Of
2294 (Chars (Arg), Names (Index1))
2296 Error_Msg_Name_1 := Names (Index1);
2297 Error_Msg_N -- CODEFIX
2298 ("\possible misspelling of%", Arg);
2310 end Gather_Associations;
2316 procedure GNAT_Pragma is
2318 Check_Restriction (No_Implementation_Pragmas, N);
2321 --------------------------
2322 -- Is_Before_First_Decl --
2323 --------------------------
2325 function Is_Before_First_Decl
2326 (Pragma_Node : Node_Id;
2327 Decls : List_Id) return Boolean
2329 Item : Node_Id := First (Decls);
2332 -- Only other pragmas can come before this pragma
2335 if No (Item) or else Nkind (Item) /= N_Pragma then
2338 elsif Item = Pragma_Node then
2344 end Is_Before_First_Decl;
2346 -----------------------------
2347 -- Is_Configuration_Pragma --
2348 -----------------------------
2350 -- A configuration pragma must appear in the context clause of a
2351 -- compilation unit, and only other pragmas may precede it. Note that
2352 -- the test below also permits use in a configuration pragma file.
2354 function Is_Configuration_Pragma return Boolean is
2355 Lis : constant List_Id := List_Containing (N);
2356 Par : constant Node_Id := Parent (N);
2360 -- If no parent, then we are in the configuration pragma file,
2361 -- so the placement is definitely appropriate.
2366 -- Otherwise we must be in the context clause of a compilation unit
2367 -- and the only thing allowed before us in the context list is more
2368 -- configuration pragmas.
2370 elsif Nkind (Par) = N_Compilation_Unit
2371 and then Context_Items (Par) = Lis
2378 elsif Nkind (Prg) /= N_Pragma then
2388 end Is_Configuration_Pragma;
2390 --------------------------
2391 -- Is_In_Context_Clause --
2392 --------------------------
2394 function Is_In_Context_Clause return Boolean is
2396 Parent_Node : Node_Id;
2399 if not Is_List_Member (N) then
2403 Plist := List_Containing (N);
2404 Parent_Node := Parent (Plist);
2406 if Parent_Node = Empty
2407 or else Nkind (Parent_Node) /= N_Compilation_Unit
2408 or else Context_Items (Parent_Node) /= Plist
2415 end Is_In_Context_Clause;
2417 ---------------------------------
2418 -- Is_Static_String_Expression --
2419 ---------------------------------
2421 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2422 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2425 Analyze_And_Resolve (Argx);
2426 return Is_OK_Static_Expression (Argx)
2427 and then Nkind (Argx) = N_String_Literal;
2428 end Is_Static_String_Expression;
2430 ----------------------
2431 -- Pragma_Misplaced --
2432 ----------------------
2434 procedure Pragma_Misplaced is
2436 Error_Pragma ("incorrect placement of pragma%");
2437 end Pragma_Misplaced;
2439 ------------------------------------
2440 -- Process Atomic_Shared_Volatile --
2441 ------------------------------------
2443 procedure Process_Atomic_Shared_Volatile is
2450 procedure Set_Atomic (E : Entity_Id);
2451 -- Set given type as atomic, and if no explicit alignment was given,
2452 -- set alignment to unknown, since back end knows what the alignment
2453 -- requirements are for atomic arrays. Note: this step is necessary
2454 -- for derived types.
2460 procedure Set_Atomic (E : Entity_Id) is
2464 if not Has_Alignment_Clause (E) then
2465 Set_Alignment (E, Uint_0);
2469 -- Start of processing for Process_Atomic_Shared_Volatile
2472 Check_Ada_83_Warning;
2473 Check_No_Identifiers;
2474 Check_Arg_Count (1);
2475 Check_Arg_Is_Local_Name (Arg1);
2476 E_Id := Get_Pragma_Arg (Arg1);
2478 if Etype (E_Id) = Any_Type then
2483 D := Declaration_Node (E);
2486 -- Check duplicate before we chain ourselves!
2488 Check_Duplicate_Pragma (E);
2490 -- Now check appropriateness of the entity
2493 if Rep_Item_Too_Early (E, N)
2495 Rep_Item_Too_Late (E, N)
2499 Check_First_Subtype (Arg1);
2502 if Prag_Id /= Pragma_Volatile then
2504 Set_Atomic (Underlying_Type (E));
2505 Set_Atomic (Base_Type (E));
2508 -- Attribute belongs on the base type. If the view of the type is
2509 -- currently private, it also belongs on the underlying type.
2511 Set_Is_Volatile (Base_Type (E));
2512 Set_Is_Volatile (Underlying_Type (E));
2514 Set_Treat_As_Volatile (E);
2515 Set_Treat_As_Volatile (Underlying_Type (E));
2517 elsif K = N_Object_Declaration
2518 or else (K = N_Component_Declaration
2519 and then Original_Record_Component (E) = E)
2521 if Rep_Item_Too_Late (E, N) then
2525 if Prag_Id /= Pragma_Volatile then
2528 -- If the object declaration has an explicit initialization, a
2529 -- temporary may have to be created to hold the expression, to
2530 -- ensure that access to the object remain atomic.
2532 if Nkind (Parent (E)) = N_Object_Declaration
2533 and then Present (Expression (Parent (E)))
2535 Set_Has_Delayed_Freeze (E);
2538 -- An interesting improvement here. If an object of type X is
2539 -- declared atomic, and the type X is not atomic, that's a
2540 -- pity, since it may not have appropriate alignment etc. We
2541 -- can rescue this in the special case where the object and
2542 -- type are in the same unit by just setting the type as
2543 -- atomic, so that the back end will process it as atomic.
2545 Utyp := Underlying_Type (Etype (E));
2548 and then Sloc (E) > No_Location
2549 and then Sloc (Utyp) > No_Location
2551 Get_Source_File_Index (Sloc (E)) =
2552 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2554 Set_Is_Atomic (Underlying_Type (Etype (E)));
2558 Set_Is_Volatile (E);
2559 Set_Treat_As_Volatile (E);
2563 ("inappropriate entity for pragma%", Arg1);
2565 end Process_Atomic_Shared_Volatile;
2567 -------------------------------------------
2568 -- Process_Compile_Time_Warning_Or_Error --
2569 -------------------------------------------
2571 procedure Process_Compile_Time_Warning_Or_Error is
2572 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2575 Check_Arg_Count (2);
2576 Check_No_Identifiers;
2577 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2578 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2580 if Compile_Time_Known_Value (Arg1x) then
2581 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2583 Str : constant String_Id :=
2584 Strval (Get_Pragma_Arg (Arg2));
2585 Len : constant Int := String_Length (Str);
2590 Cent : constant Entity_Id :=
2591 Cunit_Entity (Current_Sem_Unit);
2593 Force : constant Boolean :=
2594 Prag_Id = Pragma_Compile_Time_Warning
2596 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2597 and then (Ekind (Cent) /= E_Package
2598 or else not In_Private_Part (Cent));
2599 -- Set True if this is the warning case, and we are in the
2600 -- visible part of a package spec, or in a subprogram spec,
2601 -- in which case we want to force the client to see the
2602 -- warning, even though it is not in the main unit.
2605 -- Loop through segments of message separated by line feeds.
2606 -- We output these segments as separate messages with
2607 -- continuation marks for all but the first.
2612 Error_Msg_Strlen := 0;
2614 -- Loop to copy characters from argument to error message
2618 exit when Ptr > Len;
2619 CC := Get_String_Char (Str, Ptr);
2622 -- Ignore wide chars ??? else store character
2624 if In_Character_Range (CC) then
2625 C := Get_Character (CC);
2626 exit when C = ASCII.LF;
2627 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2628 Error_Msg_String (Error_Msg_Strlen) := C;
2632 -- Here with one line ready to go
2634 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2636 -- If this is a warning in a spec, then we want clients
2637 -- to see the warning, so mark the message with the
2638 -- special sequence !! to force the warning. In the case
2639 -- of a package spec, we do not force this if we are in
2640 -- the private part of the spec.
2643 if Cont = False then
2644 Error_Msg_N ("<~!!", Arg1);
2647 Error_Msg_N ("\<~!!", Arg1);
2650 -- Error, rather than warning, or in a body, so we do not
2651 -- need to force visibility for client (error will be
2652 -- output in any case, and this is the situation in which
2653 -- we do not want a client to get a warning, since the
2654 -- warning is in the body or the spec private part).
2657 if Cont = False then
2658 Error_Msg_N ("<~", Arg1);
2661 Error_Msg_N ("\<~", Arg1);
2665 exit when Ptr > Len;
2670 end Process_Compile_Time_Warning_Or_Error;
2672 ------------------------
2673 -- Process_Convention --
2674 ------------------------
2676 procedure Process_Convention
2677 (C : out Convention_Id;
2678 Ent : out Entity_Id)
2684 Comp_Unit : Unit_Number_Type;
2686 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2687 -- Called if we have more than one Export/Import/Convention pragma.
2688 -- This is generally illegal, but we have a special case of allowing
2689 -- Import and Interface to coexist if they specify the convention in
2690 -- a consistent manner. We are allowed to do this, since Interface is
2691 -- an implementation defined pragma, and we choose to do it since we
2692 -- know Rational allows this combination. S is the entity id of the
2693 -- subprogram in question. This procedure also sets the special flag
2694 -- Import_Interface_Present in both pragmas in the case where we do
2695 -- have matching Import and Interface pragmas.
2697 procedure Set_Convention_From_Pragma (E : Entity_Id);
2698 -- Set convention in entity E, and also flag that the entity has a
2699 -- convention pragma. If entity is for a private or incomplete type,
2700 -- also set convention and flag on underlying type. This procedure
2701 -- also deals with the special case of C_Pass_By_Copy convention.
2703 -------------------------------
2704 -- Diagnose_Multiple_Pragmas --
2705 -------------------------------
2707 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2708 Pdec : constant Node_Id := Declaration_Node (S);
2712 function Same_Convention (Decl : Node_Id) return Boolean;
2713 -- Decl is a pragma node. This function returns True if this
2714 -- pragma has a first argument that is an identifier with a
2715 -- Chars field corresponding to the Convention_Id C.
2717 function Same_Name (Decl : Node_Id) return Boolean;
2718 -- Decl is a pragma node. This function returns True if this
2719 -- pragma has a second argument that is an identifier with a
2720 -- Chars field that matches the Chars of the current subprogram.
2722 ---------------------
2723 -- Same_Convention --
2724 ---------------------
2726 function Same_Convention (Decl : Node_Id) return Boolean is
2727 Arg1 : constant Node_Id :=
2728 First (Pragma_Argument_Associations (Decl));
2731 if Present (Arg1) then
2733 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2735 if Nkind (Arg) = N_Identifier
2736 and then Is_Convention_Name (Chars (Arg))
2737 and then Get_Convention_Id (Chars (Arg)) = C
2745 end Same_Convention;
2751 function Same_Name (Decl : Node_Id) return Boolean is
2752 Arg1 : constant Node_Id :=
2753 First (Pragma_Argument_Associations (Decl));
2761 Arg2 := Next (Arg1);
2768 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2770 if Nkind (Arg) = N_Identifier
2771 and then Chars (Arg) = Chars (S)
2780 -- Start of processing for Diagnose_Multiple_Pragmas
2785 -- Definitely give message if we have Convention/Export here
2787 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2790 -- If we have an Import or Export, scan back from pragma to
2791 -- find any previous pragma applying to the same procedure.
2792 -- The scan will be terminated by the start of the list, or
2793 -- hitting the subprogram declaration. This won't allow one
2794 -- pragma to appear in the public part and one in the private
2795 -- part, but that seems very unlikely in practice.
2799 while Present (Decl) and then Decl /= Pdec loop
2801 -- Look for pragma with same name as us
2803 if Nkind (Decl) = N_Pragma
2804 and then Same_Name (Decl)
2806 -- Give error if same as our pragma or Export/Convention
2808 if Pragma_Name (Decl) = Name_Export
2810 Pragma_Name (Decl) = Name_Convention
2812 Pragma_Name (Decl) = Pragma_Name (N)
2816 -- Case of Import/Interface or the other way round
2818 elsif Pragma_Name (Decl) = Name_Interface
2820 Pragma_Name (Decl) = Name_Import
2822 -- Here we know that we have Import and Interface. It
2823 -- doesn't matter which way round they are. See if
2824 -- they specify the same convention. If so, all OK,
2825 -- and set special flags to stop other messages
2827 if Same_Convention (Decl) then
2828 Set_Import_Interface_Present (N);
2829 Set_Import_Interface_Present (Decl);
2832 -- If different conventions, special message
2835 Error_Msg_Sloc := Sloc (Decl);
2837 ("convention differs from that given#", Arg1);
2847 -- Give message if needed if we fall through those tests
2851 ("at most one Convention/Export/Import pragma is allowed",
2854 end Diagnose_Multiple_Pragmas;
2856 --------------------------------
2857 -- Set_Convention_From_Pragma --
2858 --------------------------------
2860 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2862 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2863 -- for an overridden dispatching operation. Technically this is
2864 -- an amendment and should only be done in Ada 2005 mode. However,
2865 -- this is clearly a mistake, since the problem that is addressed
2866 -- by this AI is that there is a clear gap in the RM!
2868 if Is_Dispatching_Operation (E)
2869 and then Present (Overridden_Operation (E))
2870 and then C /= Convention (Overridden_Operation (E))
2873 ("cannot change convention for " &
2874 "overridden dispatching operation",
2878 -- Set the convention
2880 Set_Convention (E, C);
2881 Set_Has_Convention_Pragma (E);
2883 if Is_Incomplete_Or_Private_Type (E)
2884 and then Present (Underlying_Type (E))
2886 Set_Convention (Underlying_Type (E), C);
2887 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2890 -- A class-wide type should inherit the convention of the specific
2891 -- root type (although this isn't specified clearly by the RM).
2893 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2894 Set_Convention (Class_Wide_Type (E), C);
2897 -- If the entity is a record type, then check for special case of
2898 -- C_Pass_By_Copy, which is treated the same as C except that the
2899 -- special record flag is set. This convention is only permitted
2900 -- on record types (see AI95-00131).
2902 if Cname = Name_C_Pass_By_Copy then
2903 if Is_Record_Type (E) then
2904 Set_C_Pass_By_Copy (Base_Type (E));
2905 elsif Is_Incomplete_Or_Private_Type (E)
2906 and then Is_Record_Type (Underlying_Type (E))
2908 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2911 ("C_Pass_By_Copy convention allowed only for record type",
2916 -- If the entity is a derived boolean type, check for the special
2917 -- case of convention C, C++, or Fortran, where we consider any
2918 -- nonzero value to represent true.
2920 if Is_Discrete_Type (E)
2921 and then Root_Type (Etype (E)) = Standard_Boolean
2927 C = Convention_Fortran)
2929 Set_Nonzero_Is_True (Base_Type (E));
2931 end Set_Convention_From_Pragma;
2933 -- Start of processing for Process_Convention
2936 Check_At_Least_N_Arguments (2);
2937 Check_Optional_Identifier (Arg1, Name_Convention);
2938 Check_Arg_Is_Identifier (Arg1);
2939 Cname := Chars (Get_Pragma_Arg (Arg1));
2941 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2942 -- tested again below to set the critical flag).
2944 if Cname = Name_C_Pass_By_Copy then
2947 -- Otherwise we must have something in the standard convention list
2949 elsif Is_Convention_Name (Cname) then
2950 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
2952 -- In DEC VMS, it seems that there is an undocumented feature that
2953 -- any unrecognized convention is treated as the default, which for
2954 -- us is convention C. It does not seem so terrible to do this
2955 -- unconditionally, silently in the VMS case, and with a warning
2956 -- in the non-VMS case.
2959 if Warn_On_Export_Import and not OpenVMS_On_Target then
2961 ("?unrecognized convention name, C assumed",
2962 Get_Pragma_Arg (Arg1));
2968 Check_Optional_Identifier (Arg2, Name_Entity);
2969 Check_Arg_Is_Local_Name (Arg2);
2971 Id := Get_Pragma_Arg (Arg2);
2974 if not Is_Entity_Name (Id) then
2975 Error_Pragma_Arg ("entity name required", Arg2);
2980 -- Set entity to return
2984 -- Go to renamed subprogram if present, since convention applies to
2985 -- the actual renamed entity, not to the renaming entity. If the
2986 -- subprogram is inherited, go to parent subprogram.
2988 if Is_Subprogram (E)
2989 and then Present (Alias (E))
2991 if Nkind (Parent (Declaration_Node (E))) =
2992 N_Subprogram_Renaming_Declaration
2994 if Scope (E) /= Scope (Alias (E)) then
2996 ("cannot apply pragma% to non-local entity&#", E);
3001 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3002 N_Private_Extension_Declaration)
3003 and then Scope (E) = Scope (Alias (E))
3007 -- Return the parent subprogram the entity was inherited from
3013 -- Check that we are not applying this to a specless body
3015 if Is_Subprogram (E)
3016 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3019 ("pragma% requires separate spec and must come before body");
3022 -- Check that we are not applying this to a named constant
3024 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3025 Error_Msg_Name_1 := Pname;
3027 ("cannot apply pragma% to named constant!",
3028 Get_Pragma_Arg (Arg2));
3030 ("\supply appropriate type for&!", Arg2);
3033 if Ekind (E) = E_Enumeration_Literal then
3034 Error_Pragma ("enumeration literal not allowed for pragma%");
3037 -- Check for rep item appearing too early or too late
3039 if Etype (E) = Any_Type
3040 or else Rep_Item_Too_Early (E, N)
3044 elsif Present (Underlying_Type (E)) then
3045 E := Underlying_Type (E);
3048 if Rep_Item_Too_Late (E, N) then
3052 if Has_Convention_Pragma (E) then
3053 Diagnose_Multiple_Pragmas (E);
3055 elsif Convention (E) = Convention_Protected
3056 or else Ekind (Scope (E)) = E_Protected_Type
3059 ("a protected operation cannot be given a different convention",
3063 -- For Intrinsic, a subprogram is required
3065 if C = Convention_Intrinsic
3066 and then not Is_Subprogram (E)
3067 and then not Is_Generic_Subprogram (E)
3070 ("second argument of pragma% must be a subprogram", Arg2);
3073 -- For Stdcall, a subprogram, variable or subprogram type is required
3075 if C = Convention_Stdcall
3076 and then not Is_Subprogram (E)
3077 and then not Is_Generic_Subprogram (E)
3078 and then Ekind (E) /= E_Variable
3081 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3084 ("second argument of pragma% must be subprogram (type)",
3088 if not Is_Subprogram (E)
3089 and then not Is_Generic_Subprogram (E)
3091 Set_Convention_From_Pragma (E);
3094 Check_First_Subtype (Arg2);
3095 Set_Convention_From_Pragma (Base_Type (E));
3097 -- For subprograms, we must set the convention on the
3098 -- internally generated directly designated type as well.
3100 if Ekind (E) = E_Access_Subprogram_Type then
3101 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3105 -- For the subprogram case, set proper convention for all homonyms
3106 -- in same scope and the same declarative part, i.e. the same
3107 -- compilation unit.
3110 Comp_Unit := Get_Source_Unit (E);
3111 Set_Convention_From_Pragma (E);
3113 -- Treat a pragma Import as an implicit body, for GPS use
3115 if Prag_Id = Pragma_Import then
3116 Generate_Reference (E, Id, 'b');
3119 -- Loop through the homonyms of the pragma argument's entity
3124 exit when No (E1) or else Scope (E1) /= Current_Scope;
3126 -- Do not set the pragma on inherited operations or on formal
3129 if Comes_From_Source (E1)
3130 and then Comp_Unit = Get_Source_Unit (E1)
3131 and then not Is_Formal_Subprogram (E1)
3132 and then Nkind (Original_Node (Parent (E1))) /=
3133 N_Full_Type_Declaration
3135 if Present (Alias (E1))
3136 and then Scope (E1) /= Scope (Alias (E1))
3139 ("cannot apply pragma% to non-local entity& declared#",
3143 Set_Convention_From_Pragma (E1);
3145 if Prag_Id = Pragma_Import then
3146 Generate_Reference (E1, Id, 'b');
3150 -- For aspect case, do NOT apply to homonyms
3152 exit when From_Aspect_Specification (N);
3155 end Process_Convention;
3157 -----------------------------------------------------
3158 -- Process_Extended_Import_Export_Exception_Pragma --
3159 -----------------------------------------------------
3161 procedure Process_Extended_Import_Export_Exception_Pragma
3162 (Arg_Internal : Node_Id;
3163 Arg_External : Node_Id;
3171 if not OpenVMS_On_Target then
3173 ("?pragma% ignored (applies only to Open'V'M'S)");
3176 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3177 Def_Id := Entity (Arg_Internal);
3179 if Ekind (Def_Id) /= E_Exception then
3181 ("pragma% must refer to declared exception", Arg_Internal);
3184 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3186 if Present (Arg_Form) then
3187 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3190 if Present (Arg_Form)
3191 and then Chars (Arg_Form) = Name_Ada
3195 Set_Is_VMS_Exception (Def_Id);
3196 Set_Exception_Code (Def_Id, No_Uint);
3199 if Present (Arg_Code) then
3200 if not Is_VMS_Exception (Def_Id) then
3202 ("Code option for pragma% not allowed for Ada case",
3206 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3207 Code_Val := Expr_Value (Arg_Code);
3209 if not UI_Is_In_Int_Range (Code_Val) then
3211 ("Code option for pragma% must be in 32-bit range",
3215 Set_Exception_Code (Def_Id, Code_Val);
3218 end Process_Extended_Import_Export_Exception_Pragma;
3220 -------------------------------------------------
3221 -- Process_Extended_Import_Export_Internal_Arg --
3222 -------------------------------------------------
3224 procedure Process_Extended_Import_Export_Internal_Arg
3225 (Arg_Internal : Node_Id := Empty)
3228 if No (Arg_Internal) then
3229 Error_Pragma ("Internal parameter required for pragma%");
3232 if Nkind (Arg_Internal) = N_Identifier then
3235 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3236 and then (Prag_Id = Pragma_Import_Function
3238 Prag_Id = Pragma_Export_Function)
3244 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3247 Check_Arg_Is_Local_Name (Arg_Internal);
3248 end Process_Extended_Import_Export_Internal_Arg;
3250 --------------------------------------------------
3251 -- Process_Extended_Import_Export_Object_Pragma --
3252 --------------------------------------------------
3254 procedure Process_Extended_Import_Export_Object_Pragma
3255 (Arg_Internal : Node_Id;
3256 Arg_External : Node_Id;
3262 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3263 Def_Id := Entity (Arg_Internal);
3265 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3267 ("pragma% must designate an object", Arg_Internal);
3270 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3272 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3275 ("previous Common/Psect_Object applies, pragma % not permitted",
3279 if Rep_Item_Too_Late (Def_Id, N) then
3283 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3285 if Present (Arg_Size) then
3286 Check_Arg_Is_External_Name (Arg_Size);
3289 -- Export_Object case
3291 if Prag_Id = Pragma_Export_Object then
3292 if not Is_Library_Level_Entity (Def_Id) then
3294 ("argument for pragma% must be library level entity",
3298 if Ekind (Current_Scope) = E_Generic_Package then
3299 Error_Pragma ("pragma& cannot appear in a generic unit");
3302 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3304 ("exported object must have compile time known size",
3308 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3309 Error_Msg_N ("?duplicate Export_Object pragma", N);
3311 Set_Exported (Def_Id, Arg_Internal);
3314 -- Import_Object case
3317 if Is_Concurrent_Type (Etype (Def_Id)) then
3319 ("cannot use pragma% for task/protected object",
3323 if Ekind (Def_Id) = E_Constant then
3325 ("cannot import a constant", Arg_Internal);
3328 if Warn_On_Export_Import
3329 and then Has_Discriminants (Etype (Def_Id))
3332 ("imported value must be initialized?", Arg_Internal);
3335 if Warn_On_Export_Import
3336 and then Is_Access_Type (Etype (Def_Id))
3339 ("cannot import object of an access type?", Arg_Internal);
3342 if Warn_On_Export_Import
3343 and then Is_Imported (Def_Id)
3346 ("?duplicate Import_Object pragma", N);
3348 -- Check for explicit initialization present. Note that an
3349 -- initialization generated by the code generator, e.g. for an
3350 -- access type, does not count here.
3352 elsif Present (Expression (Parent (Def_Id)))
3355 (Original_Node (Expression (Parent (Def_Id))))
3357 Error_Msg_Sloc := Sloc (Def_Id);
3359 ("imported entities cannot be initialized (RM B.1(24))",
3360 "\no initialization allowed for & declared#", Arg1);
3362 Set_Imported (Def_Id);
3363 Note_Possible_Modification (Arg_Internal, Sure => False);
3366 end Process_Extended_Import_Export_Object_Pragma;
3368 ------------------------------------------------------
3369 -- Process_Extended_Import_Export_Subprogram_Pragma --
3370 ------------------------------------------------------
3372 procedure Process_Extended_Import_Export_Subprogram_Pragma
3373 (Arg_Internal : Node_Id;
3374 Arg_External : Node_Id;
3375 Arg_Parameter_Types : Node_Id;
3376 Arg_Result_Type : Node_Id := Empty;
3377 Arg_Mechanism : Node_Id;
3378 Arg_Result_Mechanism : Node_Id := Empty;
3379 Arg_First_Optional_Parameter : Node_Id := Empty)
3385 Ambiguous : Boolean;
3389 function Same_Base_Type
3391 Formal : Entity_Id) return Boolean;
3392 -- Determines if Ptype references the type of Formal. Note that only
3393 -- the base types need to match according to the spec. Ptype here is
3394 -- the argument from the pragma, which is either a type name, or an
3395 -- access attribute.
3397 --------------------
3398 -- Same_Base_Type --
3399 --------------------
3401 function Same_Base_Type
3403 Formal : Entity_Id) return Boolean
3405 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3409 -- Case where pragma argument is typ'Access
3411 if Nkind (Ptype) = N_Attribute_Reference
3412 and then Attribute_Name (Ptype) = Name_Access
3414 Pref := Prefix (Ptype);
3417 if not Is_Entity_Name (Pref)
3418 or else Entity (Pref) = Any_Type
3423 -- We have a match if the corresponding argument is of an
3424 -- anonymous access type, and its designated type matches the
3425 -- type of the prefix of the access attribute
3427 return Ekind (Ftyp) = E_Anonymous_Access_Type
3428 and then Base_Type (Entity (Pref)) =
3429 Base_Type (Etype (Designated_Type (Ftyp)));
3431 -- Case where pragma argument is a type name
3436 if not Is_Entity_Name (Ptype)
3437 or else Entity (Ptype) = Any_Type
3442 -- We have a match if the corresponding argument is of the type
3443 -- given in the pragma (comparing base types)
3445 return Base_Type (Entity (Ptype)) = Ftyp;
3449 -- Start of processing for
3450 -- Process_Extended_Import_Export_Subprogram_Pragma
3453 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3457 -- Loop through homonyms (overloadings) of the entity
3459 Hom_Id := Entity (Arg_Internal);
3460 while Present (Hom_Id) loop
3461 Def_Id := Get_Base_Subprogram (Hom_Id);
3463 -- We need a subprogram in the current scope
3465 if not Is_Subprogram (Def_Id)
3466 or else Scope (Def_Id) /= Current_Scope
3473 -- Pragma cannot apply to subprogram body
3475 if Is_Subprogram (Def_Id)
3476 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3480 ("pragma% requires separate spec"
3481 & " and must come before body");
3484 -- Test result type if given, note that the result type
3485 -- parameter can only be present for the function cases.
3487 if Present (Arg_Result_Type)
3488 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3492 elsif Etype (Def_Id) /= Standard_Void_Type
3494 (Pname = Name_Export_Procedure
3496 Pname = Name_Import_Procedure)
3500 -- Test parameter types if given. Note that this parameter
3501 -- has not been analyzed (and must not be, since it is
3502 -- semantic nonsense), so we get it as the parser left it.
3504 elsif Present (Arg_Parameter_Types) then
3505 Check_Matching_Types : declare
3510 Formal := First_Formal (Def_Id);
3512 if Nkind (Arg_Parameter_Types) = N_Null then
3513 if Present (Formal) then
3517 -- A list of one type, e.g. (List) is parsed as
3518 -- a parenthesized expression.
3520 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3521 and then Paren_Count (Arg_Parameter_Types) = 1
3524 or else Present (Next_Formal (Formal))
3529 Same_Base_Type (Arg_Parameter_Types, Formal);
3532 -- A list of more than one type is parsed as a aggregate
3534 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3535 and then Paren_Count (Arg_Parameter_Types) = 0
3537 Ptype := First (Expressions (Arg_Parameter_Types));
3538 while Present (Ptype) or else Present (Formal) loop
3541 or else not Same_Base_Type (Ptype, Formal)
3546 Next_Formal (Formal);
3551 -- Anything else is of the wrong form
3555 ("wrong form for Parameter_Types parameter",
3556 Arg_Parameter_Types);
3558 end Check_Matching_Types;
3561 -- Match is now False if the entry we found did not match
3562 -- either a supplied Parameter_Types or Result_Types argument
3568 -- Ambiguous case, the flag Ambiguous shows if we already
3569 -- detected this and output the initial messages.
3572 if not Ambiguous then
3574 Error_Msg_Name_1 := Pname;
3576 ("pragma% does not uniquely identify subprogram!",
3578 Error_Msg_Sloc := Sloc (Ent);
3579 Error_Msg_N ("matching subprogram #!", N);
3583 Error_Msg_Sloc := Sloc (Def_Id);
3584 Error_Msg_N ("matching subprogram #!", N);
3589 Hom_Id := Homonym (Hom_Id);
3592 -- See if we found an entry
3595 if not Ambiguous then
3596 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3598 ("pragma% cannot be given for generic subprogram");
3601 ("pragma% does not identify local subprogram");
3608 -- Import pragmas must be for imported entities
3610 if Prag_Id = Pragma_Import_Function
3612 Prag_Id = Pragma_Import_Procedure
3614 Prag_Id = Pragma_Import_Valued_Procedure
3616 if not Is_Imported (Ent) then
3618 ("pragma Import or Interface must precede pragma%");
3621 -- Here we have the Export case which can set the entity as exported
3623 -- But does not do so if the specified external name is null, since
3624 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3625 -- compatible) to request no external name.
3627 elsif Nkind (Arg_External) = N_String_Literal
3628 and then String_Length (Strval (Arg_External)) = 0
3632 -- In all other cases, set entity as exported
3635 Set_Exported (Ent, Arg_Internal);
3638 -- Special processing for Valued_Procedure cases
3640 if Prag_Id = Pragma_Import_Valued_Procedure
3642 Prag_Id = Pragma_Export_Valued_Procedure
3644 Formal := First_Formal (Ent);
3647 Error_Pragma ("at least one parameter required for pragma%");
3649 elsif Ekind (Formal) /= E_Out_Parameter then
3650 Error_Pragma ("first parameter must have mode out for pragma%");
3653 Set_Is_Valued_Procedure (Ent);
3657 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3659 -- Process Result_Mechanism argument if present. We have already
3660 -- checked that this is only allowed for the function case.
3662 if Present (Arg_Result_Mechanism) then
3663 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3666 -- Process Mechanism parameter if present. Note that this parameter
3667 -- is not analyzed, and must not be analyzed since it is semantic
3668 -- nonsense, so we get it in exactly as the parser left it.
3670 if Present (Arg_Mechanism) then
3678 -- A single mechanism association without a formal parameter
3679 -- name is parsed as a parenthesized expression. All other
3680 -- cases are parsed as aggregates, so we rewrite the single
3681 -- parameter case as an aggregate for consistency.
3683 if Nkind (Arg_Mechanism) /= N_Aggregate
3684 and then Paren_Count (Arg_Mechanism) = 1
3686 Rewrite (Arg_Mechanism,
3687 Make_Aggregate (Sloc (Arg_Mechanism),
3688 Expressions => New_List (
3689 Relocate_Node (Arg_Mechanism))));
3692 -- Case of only mechanism name given, applies to all formals
3694 if Nkind (Arg_Mechanism) /= N_Aggregate then
3695 Formal := First_Formal (Ent);
3696 while Present (Formal) loop
3697 Set_Mechanism_Value (Formal, Arg_Mechanism);
3698 Next_Formal (Formal);
3701 -- Case of list of mechanism associations given
3704 if Null_Record_Present (Arg_Mechanism) then
3706 ("inappropriate form for Mechanism parameter",
3710 -- Deal with positional ones first
3712 Formal := First_Formal (Ent);
3714 if Present (Expressions (Arg_Mechanism)) then
3715 Mname := First (Expressions (Arg_Mechanism));
3716 while Present (Mname) loop
3719 ("too many mechanism associations", Mname);
3722 Set_Mechanism_Value (Formal, Mname);
3723 Next_Formal (Formal);
3728 -- Deal with named entries
3730 if Present (Component_Associations (Arg_Mechanism)) then
3731 Massoc := First (Component_Associations (Arg_Mechanism));
3732 while Present (Massoc) loop
3733 Choice := First (Choices (Massoc));
3735 if Nkind (Choice) /= N_Identifier
3736 or else Present (Next (Choice))
3739 ("incorrect form for mechanism association",
3743 Formal := First_Formal (Ent);
3747 ("parameter name & not present", Choice);
3750 if Chars (Choice) = Chars (Formal) then
3752 (Formal, Expression (Massoc));
3754 -- Set entity on identifier (needed by ASIS)
3756 Set_Entity (Choice, Formal);
3761 Next_Formal (Formal);
3771 -- Process First_Optional_Parameter argument if present. We have
3772 -- already checked that this is only allowed for the Import case.
3774 if Present (Arg_First_Optional_Parameter) then
3775 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3777 ("first optional parameter must be formal parameter name",
3778 Arg_First_Optional_Parameter);
3781 Formal := First_Formal (Ent);
3785 ("specified formal parameter& not found",
3786 Arg_First_Optional_Parameter);
3789 exit when Chars (Formal) =
3790 Chars (Arg_First_Optional_Parameter);
3792 Next_Formal (Formal);
3795 Set_First_Optional_Parameter (Ent, Formal);
3797 -- Check specified and all remaining formals have right form
3799 while Present (Formal) loop
3800 if Ekind (Formal) /= E_In_Parameter then
3802 ("optional formal& is not of mode in!",
3803 Arg_First_Optional_Parameter, Formal);
3806 Dval := Default_Value (Formal);
3810 ("optional formal& does not have default value!",
3811 Arg_First_Optional_Parameter, Formal);
3813 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3818 ("default value for optional formal& is non-static!",
3819 Arg_First_Optional_Parameter, Formal);
3823 Set_Is_Optional_Parameter (Formal);
3824 Next_Formal (Formal);
3827 end Process_Extended_Import_Export_Subprogram_Pragma;
3829 --------------------------
3830 -- Process_Generic_List --
3831 --------------------------
3833 procedure Process_Generic_List is
3838 Check_No_Identifiers;
3839 Check_At_Least_N_Arguments (1);
3842 while Present (Arg) loop
3843 Exp := Get_Pragma_Arg (Arg);
3846 if not Is_Entity_Name (Exp)
3848 (not Is_Generic_Instance (Entity (Exp))
3850 not Is_Generic_Unit (Entity (Exp)))
3853 ("pragma% argument must be name of generic unit/instance",
3859 end Process_Generic_List;
3861 ------------------------------------
3862 -- Process_Import_Predefined_Type --
3863 ------------------------------------
3865 procedure Process_Import_Predefined_Type is
3866 Loc : constant Source_Ptr := Sloc (N);
3867 Ftyp : Node_Id := First (Predefined_Float_Types);
3872 String_To_Name_Buffer (Strval (Expression (Arg3)));
3875 while Present (Ftyp) and then Chars (Ftyp) /= Nam loop
3879 if Present (Ftyp) then
3880 -- Don't build a derived type declaration, because predefined C
3881 -- types have no declaration anywhere, so cannot really be named.
3882 -- Instead build a full type declaration, starting with an
3883 -- appropriate type definition is built
3885 if Is_Floating_Point_Type (Ftyp) then
3886 Def := Make_Floating_Point_Definition (Loc,
3887 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
3888 Make_Real_Range_Specification (Loc,
3889 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
3890 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
3893 -- Should never have a predefined type we cannot handle
3894 raise Program_Error;
3897 -- Build and insert a Full_Type_Declaration, which will be
3898 -- analyzed as soon as this list entry has been analyzed.
3900 Decl := Make_Full_Type_Declaration (Loc,
3901 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
3902 Type_Definition => Def);
3904 Insert_After (N, Decl);
3905 Mark_Rewrite_Insertion (Decl);
3908 Error_Pragma_Arg ("no matching type found for pragma%",
3911 end Process_Import_Predefined_Type;
3913 ---------------------------------
3914 -- Process_Import_Or_Interface --
3915 ---------------------------------
3917 procedure Process_Import_Or_Interface is
3923 Process_Convention (C, Def_Id);
3924 Kill_Size_Check_Code (Def_Id);
3925 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
3927 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3929 -- We do not permit Import to apply to a renaming declaration
3931 if Present (Renamed_Object (Def_Id)) then
3933 ("pragma% not allowed for object renaming", Arg2);
3935 -- User initialization is not allowed for imported object, but
3936 -- the object declaration may contain a default initialization,
3937 -- that will be discarded. Note that an explicit initialization
3938 -- only counts if it comes from source, otherwise it is simply
3939 -- the code generator making an implicit initialization explicit.
3941 elsif Present (Expression (Parent (Def_Id)))
3942 and then Comes_From_Source (Expression (Parent (Def_Id)))
3944 Error_Msg_Sloc := Sloc (Def_Id);
3946 ("no initialization allowed for declaration of& #",
3947 "\imported entities cannot be initialized (RM B.1(24))",
3951 Set_Imported (Def_Id);
3952 Process_Interface_Name (Def_Id, Arg3, Arg4);
3954 -- Note that we do not set Is_Public here. That's because we
3955 -- only want to set it if there is no address clause, and we
3956 -- don't know that yet, so we delay that processing till
3959 -- pragma Import completes deferred constants
3961 if Ekind (Def_Id) = E_Constant then
3962 Set_Has_Completion (Def_Id);
3965 -- It is not possible to import a constant of an unconstrained
3966 -- array type (e.g. string) because there is no simple way to
3967 -- write a meaningful subtype for it.
3969 if Is_Array_Type (Etype (Def_Id))
3970 and then not Is_Constrained (Etype (Def_Id))
3973 ("imported constant& must have a constrained subtype",
3978 elsif Is_Subprogram (Def_Id)
3979 or else Is_Generic_Subprogram (Def_Id)
3981 -- If the name is overloaded, pragma applies to all of the denoted
3982 -- entities in the same declarative part.
3985 while Present (Hom_Id) loop
3986 Def_Id := Get_Base_Subprogram (Hom_Id);
3988 -- Ignore inherited subprograms because the pragma will apply
3989 -- to the parent operation, which is the one called.
3991 if Is_Overloadable (Def_Id)
3992 and then Present (Alias (Def_Id))
3996 -- If it is not a subprogram, it must be in an outer scope and
3997 -- pragma does not apply.
3999 elsif not Is_Subprogram (Def_Id)
4000 and then not Is_Generic_Subprogram (Def_Id)
4004 -- The pragma does not apply to primitives of interfaces
4006 elsif Is_Dispatching_Operation (Def_Id)
4007 and then Present (Find_Dispatching_Type (Def_Id))
4008 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4012 -- Verify that the homonym is in the same declarative part (not
4013 -- just the same scope).
4015 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4016 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4021 Set_Imported (Def_Id);
4023 -- Reject an Import applied to an abstract subprogram
4025 if Is_Subprogram (Def_Id)
4026 and then Is_Abstract_Subprogram (Def_Id)
4028 Error_Msg_Sloc := Sloc (Def_Id);
4030 ("cannot import abstract subprogram& declared#",
4034 -- Special processing for Convention_Intrinsic
4036 if C = Convention_Intrinsic then
4038 -- Link_Name argument not allowed for intrinsic
4042 Set_Is_Intrinsic_Subprogram (Def_Id);
4044 -- If no external name is present, then check that this
4045 -- is a valid intrinsic subprogram. If an external name
4046 -- is present, then this is handled by the back end.
4049 Check_Intrinsic_Subprogram
4050 (Def_Id, Get_Pragma_Arg (Arg2));
4054 -- All interfaced procedures need an external symbol created
4055 -- for them since they are always referenced from another
4058 Set_Is_Public (Def_Id);
4060 -- Verify that the subprogram does not have a completion
4061 -- through a renaming declaration. For other completions the
4062 -- pragma appears as a too late representation.
4065 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4069 and then Nkind (Decl) = N_Subprogram_Declaration
4070 and then Present (Corresponding_Body (Decl))
4071 and then Nkind (Unit_Declaration_Node
4072 (Corresponding_Body (Decl))) =
4073 N_Subprogram_Renaming_Declaration
4075 Error_Msg_Sloc := Sloc (Def_Id);
4077 ("cannot import&, renaming already provided for " &
4078 "declaration #", N, Def_Id);
4082 Set_Has_Completion (Def_Id);
4083 Process_Interface_Name (Def_Id, Arg3, Arg4);
4086 if Is_Compilation_Unit (Hom_Id) then
4088 -- Its possible homonyms are not affected by the pragma.
4089 -- Such homonyms might be present in the context of other
4090 -- units being compiled.
4095 Hom_Id := Homonym (Hom_Id);
4099 -- When the convention is Java or CIL, we also allow Import to be
4100 -- given for packages, generic packages, exceptions, record
4101 -- components, and access to subprograms.
4103 elsif (C = Convention_Java or else C = Convention_CIL)
4105 (Is_Package_Or_Generic_Package (Def_Id)
4106 or else Ekind (Def_Id) = E_Exception
4107 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4108 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4110 Set_Imported (Def_Id);
4111 Set_Is_Public (Def_Id);
4112 Process_Interface_Name (Def_Id, Arg3, Arg4);
4114 -- Import a CPP class
4116 elsif Is_Record_Type (Def_Id)
4117 and then C = Convention_CPP
4119 -- Types treated as CPP classes are treated as limited, but we
4120 -- don't require them to be declared this way. A warning is issued
4121 -- to encourage the user to declare them as limited. This is not
4122 -- an error, for compatibility reasons, because these types have
4123 -- been supported this way for some time.
4125 if not Is_Limited_Type (Def_Id) then
4127 ("imported 'C'P'P type should be " &
4128 "explicitly declared limited?",
4129 Get_Pragma_Arg (Arg2));
4131 ("\type will be considered limited",
4132 Get_Pragma_Arg (Arg2));
4135 Set_Is_CPP_Class (Def_Id);
4136 Set_Is_Limited_Record (Def_Id);
4138 -- Imported CPP types must not have discriminants (because C++
4139 -- classes do not have discriminants).
4141 if Has_Discriminants (Def_Id) then
4143 ("imported 'C'P'P type cannot have discriminants",
4144 First (Discriminant_Specifications
4145 (Declaration_Node (Def_Id))));
4148 -- Components of imported CPP types must not have default
4149 -- expressions because the constructor (if any) is on the
4153 Tdef : constant Node_Id :=
4154 Type_Definition (Declaration_Node (Def_Id));
4159 if Nkind (Tdef) = N_Record_Definition then
4160 Clist := Component_List (Tdef);
4163 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4164 Clist := Component_List (Record_Extension_Part (Tdef));
4167 if Present (Clist) then
4168 Comp := First (Component_Items (Clist));
4169 while Present (Comp) loop
4170 if Present (Expression (Comp)) then
4172 ("component of imported 'C'P'P type cannot have" &
4173 " default expression", Expression (Comp));
4181 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4183 Check_Arg_Count (3);
4184 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4186 Process_Import_Predefined_Type;
4190 ("second argument of pragma% must be object, subprogram" &
4191 " or incomplete type",
4195 -- If this pragma applies to a compilation unit, then the unit, which
4196 -- is a subprogram, does not require (or allow) a body. We also do
4197 -- not need to elaborate imported procedures.
4199 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4201 Cunit : constant Node_Id := Parent (Parent (N));
4203 Set_Body_Required (Cunit, False);
4206 end Process_Import_Or_Interface;
4208 --------------------
4209 -- Process_Inline --
4210 --------------------
4212 procedure Process_Inline (Active : Boolean) is
4219 Effective : Boolean := False;
4220 -- Set True if inline has some effect, i.e. if there is at least one
4221 -- subprogram set as inlined as a result of the use of the pragma.
4223 procedure Make_Inline (Subp : Entity_Id);
4224 -- Subp is the defining unit name of the subprogram declaration. Set
4225 -- the flag, as well as the flag in the corresponding body, if there
4228 procedure Set_Inline_Flags (Subp : Entity_Id);
4229 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4230 -- Has_Pragma_Inline_Always for the Inline_Always case.
4232 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4233 -- Returns True if it can be determined at this stage that inlining
4234 -- is not possible, for example if the body is available and contains
4235 -- exception handlers, we prevent inlining, since otherwise we can
4236 -- get undefined symbols at link time. This function also emits a
4237 -- warning if front-end inlining is enabled and the pragma appears
4240 -- ??? is business with link symbols still valid, or does it relate
4241 -- to front end ZCX which is being phased out ???
4243 ---------------------------
4244 -- Inlining_Not_Possible --
4245 ---------------------------
4247 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4248 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4252 if Nkind (Decl) = N_Subprogram_Body then
4253 Stats := Handled_Statement_Sequence (Decl);
4254 return Present (Exception_Handlers (Stats))
4255 or else Present (At_End_Proc (Stats));
4257 elsif Nkind (Decl) = N_Subprogram_Declaration
4258 and then Present (Corresponding_Body (Decl))
4260 if Front_End_Inlining
4261 and then Analyzed (Corresponding_Body (Decl))
4263 Error_Msg_N ("pragma appears too late, ignored?", N);
4266 -- If the subprogram is a renaming as body, the body is just a
4267 -- call to the renamed subprogram, and inlining is trivially
4271 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4272 N_Subprogram_Renaming_Declaration
4278 Handled_Statement_Sequence
4279 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4282 Present (Exception_Handlers (Stats))
4283 or else Present (At_End_Proc (Stats));
4287 -- If body is not available, assume the best, the check is
4288 -- performed again when compiling enclosing package bodies.
4292 end Inlining_Not_Possible;
4298 procedure Make_Inline (Subp : Entity_Id) is
4299 Kind : constant Entity_Kind := Ekind (Subp);
4300 Inner_Subp : Entity_Id := Subp;
4303 -- Ignore if bad type, avoid cascaded error
4305 if Etype (Subp) = Any_Type then
4309 -- Ignore if all inlining is suppressed
4311 elsif Suppress_All_Inlining then
4315 -- If inlining is not possible, for now do not treat as an error
4317 elsif Inlining_Not_Possible (Subp) then
4321 -- Here we have a candidate for inlining, but we must exclude
4322 -- derived operations. Otherwise we would end up trying to inline
4323 -- a phantom declaration, and the result would be to drag in a
4324 -- body which has no direct inlining associated with it. That
4325 -- would not only be inefficient but would also result in the
4326 -- backend doing cross-unit inlining in cases where it was
4327 -- definitely inappropriate to do so.
4329 -- However, a simple Comes_From_Source test is insufficient, since
4330 -- we do want to allow inlining of generic instances which also do
4331 -- not come from source. We also need to recognize specs generated
4332 -- by the front-end for bodies that carry the pragma. Finally,
4333 -- predefined operators do not come from source but are not
4334 -- inlineable either.
4336 elsif Is_Generic_Instance (Subp)
4337 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4341 elsif not Comes_From_Source (Subp)
4342 and then Scope (Subp) /= Standard_Standard
4348 -- The referenced entity must either be the enclosing entity, or
4349 -- an entity declared within the current open scope.
4351 if Present (Scope (Subp))
4352 and then Scope (Subp) /= Current_Scope
4353 and then Subp /= Current_Scope
4356 ("argument of% must be entity in current scope", Assoc);
4360 -- Processing for procedure, operator or function. If subprogram
4361 -- is aliased (as for an instance) indicate that the renamed
4362 -- entity (if declared in the same unit) is inlined.
4364 if Is_Subprogram (Subp) then
4365 Inner_Subp := Ultimate_Alias (Inner_Subp);
4367 if In_Same_Source_Unit (Subp, Inner_Subp) then
4368 Set_Inline_Flags (Inner_Subp);
4370 Decl := Parent (Parent (Inner_Subp));
4372 if Nkind (Decl) = N_Subprogram_Declaration
4373 and then Present (Corresponding_Body (Decl))
4375 Set_Inline_Flags (Corresponding_Body (Decl));
4377 elsif Is_Generic_Instance (Subp) then
4379 -- Indicate that the body needs to be created for
4380 -- inlining subsequent calls. The instantiation node
4381 -- follows the declaration of the wrapper package
4384 if Scope (Subp) /= Standard_Standard
4386 Need_Subprogram_Instance_Body
4387 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4397 -- For a generic subprogram set flag as well, for use at the point
4398 -- of instantiation, to determine whether the body should be
4401 elsif Is_Generic_Subprogram (Subp) then
4402 Set_Inline_Flags (Subp);
4405 -- Literals are by definition inlined
4407 elsif Kind = E_Enumeration_Literal then
4410 -- Anything else is an error
4414 ("expect subprogram name for pragma%", Assoc);
4418 ----------------------
4419 -- Set_Inline_Flags --
4420 ----------------------
4422 procedure Set_Inline_Flags (Subp : Entity_Id) is
4425 Set_Is_Inlined (Subp);
4428 if not Has_Pragma_Inline (Subp) then
4429 Set_Has_Pragma_Inline (Subp);
4433 if Prag_Id = Pragma_Inline_Always then
4434 Set_Has_Pragma_Inline_Always (Subp);
4436 end Set_Inline_Flags;
4438 -- Start of processing for Process_Inline
4441 Check_No_Identifiers;
4442 Check_At_Least_N_Arguments (1);
4445 Inline_Processing_Required := True;
4449 while Present (Assoc) loop
4450 Subp_Id := Get_Pragma_Arg (Assoc);
4454 if Is_Entity_Name (Subp_Id) then
4455 Subp := Entity (Subp_Id);
4457 if Subp = Any_Id then
4459 -- If previous error, avoid cascaded errors
4467 -- For the pragma case, climb homonym chain. This is
4468 -- what implements allowing the pragma in the renaming
4469 -- case, with the result applying to the ancestors.
4471 if not From_Aspect_Specification (N) then
4472 while Present (Homonym (Subp))
4473 and then Scope (Homonym (Subp)) = Current_Scope
4475 Make_Inline (Homonym (Subp));
4476 Subp := Homonym (Subp);
4484 ("inappropriate argument for pragma%", Assoc);
4487 and then Warn_On_Redundant_Constructs
4488 and then not Suppress_All_Inlining
4490 if Inlining_Not_Possible (Subp) then
4492 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4495 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4503 ----------------------------
4504 -- Process_Interface_Name --
4505 ----------------------------
4507 procedure Process_Interface_Name
4508 (Subprogram_Def : Entity_Id;
4514 String_Val : String_Id;
4516 procedure Check_Form_Of_Interface_Name
4518 Ext_Name_Case : Boolean);
4519 -- SN is a string literal node for an interface name. This routine
4520 -- performs some minimal checks that the name is reasonable. In
4521 -- particular that no spaces or other obviously incorrect characters
4522 -- appear. This is only a warning, since any characters are allowed.
4523 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4525 ----------------------------------
4526 -- Check_Form_Of_Interface_Name --
4527 ----------------------------------
4529 procedure Check_Form_Of_Interface_Name
4531 Ext_Name_Case : Boolean)
4533 S : constant String_Id := Strval (Expr_Value_S (SN));
4534 SL : constant Nat := String_Length (S);
4539 Error_Msg_N ("interface name cannot be null string", SN);
4542 for J in 1 .. SL loop
4543 C := Get_String_Char (S, J);
4545 -- Look for dubious character and issue unconditional warning.
4546 -- Definitely dubious if not in character range.
4548 if not In_Character_Range (C)
4550 -- For all cases except CLI target,
4551 -- commas, spaces and slashes are dubious (in CLI, we use
4552 -- commas and backslashes in external names to specify
4553 -- assembly version and public key, while slashes and spaces
4554 -- can be used in names to mark nested classes and
4557 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4558 and then (Get_Character (C) = ','
4560 Get_Character (C) = '\'))
4561 or else (VM_Target /= CLI_Target
4562 and then (Get_Character (C) = ' '
4564 Get_Character (C) = '/'))
4567 ("?interface name contains illegal character",
4568 Sloc (SN) + Source_Ptr (J));
4571 end Check_Form_Of_Interface_Name;
4573 -- Start of processing for Process_Interface_Name
4576 if No (Link_Arg) then
4577 if No (Ext_Arg) then
4578 if VM_Target = CLI_Target
4579 and then Ekind (Subprogram_Def) = E_Package
4580 and then Nkind (Parent (Subprogram_Def)) =
4581 N_Package_Specification
4582 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4587 (Generic_Parent (Parent (Subprogram_Def))));
4592 elsif Chars (Ext_Arg) = Name_Link_Name then
4594 Link_Nam := Expression (Ext_Arg);
4597 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4598 Ext_Nam := Expression (Ext_Arg);
4603 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4604 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4605 Ext_Nam := Expression (Ext_Arg);
4606 Link_Nam := Expression (Link_Arg);
4609 -- Check expressions for external name and link name are static
4611 if Present (Ext_Nam) then
4612 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4613 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4615 -- Verify that external name is not the name of a local entity,
4616 -- which would hide the imported one and could lead to run-time
4617 -- surprises. The problem can only arise for entities declared in
4618 -- a package body (otherwise the external name is fully qualified
4619 -- and will not conflict).
4627 if Prag_Id = Pragma_Import then
4628 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4630 E := Entity_Id (Get_Name_Table_Info (Nam));
4632 if Nam /= Chars (Subprogram_Def)
4633 and then Present (E)
4634 and then not Is_Overloadable (E)
4635 and then Is_Immediately_Visible (E)
4636 and then not Is_Imported (E)
4637 and then Ekind (Scope (E)) = E_Package
4640 while Present (Par) loop
4641 if Nkind (Par) = N_Package_Body then
4642 Error_Msg_Sloc := Sloc (E);
4644 ("imported entity is hidden by & declared#",
4649 Par := Parent (Par);
4656 if Present (Link_Nam) then
4657 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4658 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4661 -- If there is no link name, just set the external name
4663 if No (Link_Nam) then
4664 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4666 -- For the Link_Name case, the given literal is preceded by an
4667 -- asterisk, which indicates to GCC that the given name should be
4668 -- taken literally, and in particular that no prepending of
4669 -- underlines should occur, even in systems where this is the
4675 if VM_Target = No_VM then
4676 Store_String_Char (Get_Char_Code ('*'));
4679 String_Val := Strval (Expr_Value_S (Link_Nam));
4680 Store_String_Chars (String_Val);
4682 Make_String_Literal (Sloc (Link_Nam),
4683 Strval => End_String);
4686 Set_Encoded_Interface_Name
4687 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4689 -- We allow duplicated export names in CIL, as they are always
4690 -- enclosed in a namespace that differentiates them, and overloaded
4691 -- entities are supported by the VM.
4693 if Convention (Subprogram_Def) /= Convention_CIL then
4694 Check_Duplicated_Export_Name (Link_Nam);
4696 end Process_Interface_Name;
4698 -----------------------------------------
4699 -- Process_Interrupt_Or_Attach_Handler --
4700 -----------------------------------------
4702 procedure Process_Interrupt_Or_Attach_Handler is
4703 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4704 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4705 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4708 Set_Is_Interrupt_Handler (Handler_Proc);
4710 -- If the pragma is not associated with a handler procedure within a
4711 -- protected type, then it must be for a nonprotected procedure for
4712 -- the AAMP target, in which case we don't associate a representation
4713 -- item with the procedure's scope.
4715 if Ekind (Proc_Scope) = E_Protected_Type then
4716 if Prag_Id = Pragma_Interrupt_Handler
4718 Prag_Id = Pragma_Attach_Handler
4720 Record_Rep_Item (Proc_Scope, N);
4723 end Process_Interrupt_Or_Attach_Handler;
4725 --------------------------------------------------
4726 -- Process_Restrictions_Or_Restriction_Warnings --
4727 --------------------------------------------------
4729 -- Note: some of the simple identifier cases were handled in par-prag,
4730 -- but it is harmless (and more straightforward) to simply handle all
4731 -- cases here, even if it means we repeat a bit of work in some cases.
4733 procedure Process_Restrictions_Or_Restriction_Warnings
4737 R_Id : Restriction_Id;
4742 procedure Check_Unit_Name (N : Node_Id);
4743 -- Checks unit name parameter for No_Dependence. Returns if it has
4744 -- an appropriate form, otherwise raises pragma argument error.
4746 ---------------------
4747 -- Check_Unit_Name --
4748 ---------------------
4750 procedure Check_Unit_Name (N : Node_Id) is
4752 if Nkind (N) = N_Selected_Component then
4753 Check_Unit_Name (Prefix (N));
4754 Check_Unit_Name (Selector_Name (N));
4756 elsif Nkind (N) = N_Identifier then
4761 ("wrong form for unit name for No_Dependence", N);
4763 end Check_Unit_Name;
4765 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4768 -- Ignore all Restrictions pragma in CodePeer mode
4770 if CodePeer_Mode then
4774 Check_Ada_83_Warning;
4775 Check_At_Least_N_Arguments (1);
4776 Check_Valid_Configuration_Pragma;
4779 while Present (Arg) loop
4781 Expr := Get_Pragma_Arg (Arg);
4783 -- Case of no restriction identifier present
4785 if Id = No_Name then
4786 if Nkind (Expr) /= N_Identifier then
4788 ("invalid form for restriction", Arg);
4793 (Process_Restriction_Synonyms (Expr));
4795 if R_Id not in All_Boolean_Restrictions then
4796 Error_Msg_Name_1 := Pname;
4798 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4800 -- Check for possible misspelling
4802 for J in Restriction_Id loop
4804 Rnm : constant String := Restriction_Id'Image (J);
4807 Name_Buffer (1 .. Rnm'Length) := Rnm;
4808 Name_Len := Rnm'Length;
4809 Set_Casing (All_Lower_Case);
4811 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4813 (Identifier_Casing (Current_Source_File));
4814 Error_Msg_String (1 .. Rnm'Length) :=
4815 Name_Buffer (1 .. Name_Len);
4816 Error_Msg_Strlen := Rnm'Length;
4817 Error_Msg_N -- CODEFIX
4818 ("\possible misspelling of ""~""",
4819 Get_Pragma_Arg (Arg));
4828 if Implementation_Restriction (R_Id) then
4829 Check_Restriction (No_Implementation_Restrictions, Arg);
4832 -- If this is a warning, then set the warning unless we already
4833 -- have a real restriction active (we never want a warning to
4834 -- override a real restriction).
4837 if not Restriction_Active (R_Id) then
4838 Set_Restriction (R_Id, N);
4839 Restriction_Warnings (R_Id) := True;
4842 -- If real restriction case, then set it and make sure that the
4843 -- restriction warning flag is off, since a real restriction
4844 -- always overrides a warning.
4847 Set_Restriction (R_Id, N);
4848 Restriction_Warnings (R_Id) := False;
4851 -- Check for obsolescent restrictions in Ada 2005 mode
4854 and then Ada_Version >= Ada_2005
4855 and then (R_Id = No_Asynchronous_Control
4857 R_Id = No_Unchecked_Deallocation
4859 R_Id = No_Unchecked_Conversion)
4861 Check_Restriction (No_Obsolescent_Features, N);
4864 -- A very special case that must be processed here: pragma
4865 -- Restrictions (No_Exceptions) turns off all run-time
4866 -- checking. This is a bit dubious in terms of the formal
4867 -- language definition, but it is what is intended by RM
4868 -- H.4(12). Restriction_Warnings never affects generated code
4869 -- so this is done only in the real restriction case.
4871 if R_Id = No_Exceptions and then not Warn then
4872 Scope_Suppress := (others => True);
4875 -- Case of No_Dependence => unit-name. Note that the parser
4876 -- already made the necessary entry in the No_Dependence table.
4878 elsif Id = Name_No_Dependence then
4879 Check_Unit_Name (Expr);
4881 -- All other cases of restriction identifier present
4884 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4885 Analyze_And_Resolve (Expr, Any_Integer);
4887 if R_Id not in All_Parameter_Restrictions then
4889 ("invalid restriction parameter identifier", Arg);
4891 elsif not Is_OK_Static_Expression (Expr) then
4892 Flag_Non_Static_Expr
4893 ("value must be static expression!", Expr);
4896 elsif not Is_Integer_Type (Etype (Expr))
4897 or else Expr_Value (Expr) < 0
4900 ("value must be non-negative integer", Arg);
4903 -- Restriction pragma is active
4905 Val := Expr_Value (Expr);
4907 if not UI_Is_In_Int_Range (Val) then
4909 ("pragma ignored, value too large?", Arg);
4912 -- Warning case. If the real restriction is active, then we
4913 -- ignore the request, since warning never overrides a real
4914 -- restriction. Otherwise we set the proper warning. Note that
4915 -- this circuit sets the warning again if it is already set,
4916 -- which is what we want, since the constant may have changed.
4919 if not Restriction_Active (R_Id) then
4921 (R_Id, N, Integer (UI_To_Int (Val)));
4922 Restriction_Warnings (R_Id) := True;
4925 -- Real restriction case, set restriction and make sure warning
4926 -- flag is off since real restriction always overrides warning.
4929 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4930 Restriction_Warnings (R_Id) := False;
4936 end Process_Restrictions_Or_Restriction_Warnings;
4938 ---------------------------------
4939 -- Process_Suppress_Unsuppress --
4940 ---------------------------------
4942 -- Note: this procedure makes entries in the check suppress data
4943 -- structures managed by Sem. See spec of package Sem for full
4944 -- details on how we handle recording of check suppression.
4946 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4951 In_Package_Spec : constant Boolean :=
4952 Is_Package_Or_Generic_Package (Current_Scope)
4953 and then not In_Package_Body (Current_Scope);
4955 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4956 -- Used to suppress a single check on the given entity
4958 --------------------------------
4959 -- Suppress_Unsuppress_Echeck --
4960 --------------------------------
4962 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4964 Set_Checks_May_Be_Suppressed (E);
4966 if In_Package_Spec then
4967 Push_Global_Suppress_Stack_Entry
4970 Suppress => Suppress_Case);
4973 Push_Local_Suppress_Stack_Entry
4976 Suppress => Suppress_Case);
4979 -- If this is a first subtype, and the base type is distinct,
4980 -- then also set the suppress flags on the base type.
4982 if Is_First_Subtype (E)
4983 and then Etype (E) /= E
4985 Suppress_Unsuppress_Echeck (Etype (E), C);
4987 end Suppress_Unsuppress_Echeck;
4989 -- Start of processing for Process_Suppress_Unsuppress
4992 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
4993 -- we want to generate checks for analysis purposes, as set by -gnatC
4995 if CodePeer_Mode and then Comes_From_Source (N) then
4999 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5000 -- declarative part or a package spec (RM 11.5(5)).
5002 if not Is_Configuration_Pragma then
5003 Check_Is_In_Decl_Part_Or_Package_Spec;
5006 Check_At_Least_N_Arguments (1);
5007 Check_At_Most_N_Arguments (2);
5008 Check_No_Identifier (Arg1);
5009 Check_Arg_Is_Identifier (Arg1);
5011 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5013 if C = No_Check_Id then
5015 ("argument of pragma% is not valid check name", Arg1);
5018 if not Suppress_Case
5019 and then (C = All_Checks or else C = Overflow_Check)
5021 Opt.Overflow_Checks_Unsuppressed := True;
5024 if Arg_Count = 1 then
5026 -- Make an entry in the local scope suppress table. This is the
5027 -- table that directly shows the current value of the scope
5028 -- suppress check for any check id value.
5030 if C = All_Checks then
5032 -- For All_Checks, we set all specific predefined checks with
5033 -- the exception of Elaboration_Check, which is handled
5034 -- specially because of not wanting All_Checks to have the
5035 -- effect of deactivating static elaboration order processing.
5037 for J in Scope_Suppress'Range loop
5038 if J /= Elaboration_Check then
5039 Scope_Suppress (J) := Suppress_Case;
5043 -- If not All_Checks, and predefined check, then set appropriate
5044 -- scope entry. Note that we will set Elaboration_Check if this
5045 -- is explicitly specified.
5047 elsif C in Predefined_Check_Id then
5048 Scope_Suppress (C) := Suppress_Case;
5051 -- Also make an entry in the Local_Entity_Suppress table
5053 Push_Local_Suppress_Stack_Entry
5056 Suppress => Suppress_Case);
5058 -- Case of two arguments present, where the check is suppressed for
5059 -- a specified entity (given as the second argument of the pragma)
5062 -- This is obsolescent in Ada 2005 mode
5064 if Ada_Version >= Ada_2005 then
5065 Check_Restriction (No_Obsolescent_Features, Arg2);
5068 Check_Optional_Identifier (Arg2, Name_On);
5069 E_Id := Get_Pragma_Arg (Arg2);
5072 if not Is_Entity_Name (E_Id) then
5074 ("second argument of pragma% must be entity name", Arg2);
5083 -- Enforce RM 11.5(7) which requires that for a pragma that
5084 -- appears within a package spec, the named entity must be
5085 -- within the package spec. We allow the package name itself
5086 -- to be mentioned since that makes sense, although it is not
5087 -- strictly allowed by 11.5(7).
5090 and then E /= Current_Scope
5091 and then Scope (E) /= Current_Scope
5094 ("entity in pragma% is not in package spec (RM 11.5(7))",
5098 -- Loop through homonyms. As noted below, in the case of a package
5099 -- spec, only homonyms within the package spec are considered.
5102 Suppress_Unsuppress_Echeck (E, C);
5104 if Is_Generic_Instance (E)
5105 and then Is_Subprogram (E)
5106 and then Present (Alias (E))
5108 Suppress_Unsuppress_Echeck (Alias (E), C);
5111 -- Move to next homonym if not aspect spec case
5113 exit when From_Aspect_Specification (N);
5117 -- If we are within a package specification, the pragma only
5118 -- applies to homonyms in the same scope.
5120 exit when In_Package_Spec
5121 and then Scope (E) /= Current_Scope;
5124 end Process_Suppress_Unsuppress;
5130 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5132 if Is_Imported (E) then
5134 ("cannot export entity& that was previously imported", Arg);
5136 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5138 ("cannot export entity& that has an address clause", Arg);
5141 Set_Is_Exported (E);
5143 -- Generate a reference for entity explicitly, because the
5144 -- identifier may be overloaded and name resolution will not
5147 Generate_Reference (E, Arg);
5149 -- Deal with exporting non-library level entity
5151 if not Is_Library_Level_Entity (E) then
5153 -- Not allowed at all for subprograms
5155 if Is_Subprogram (E) then
5156 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5158 -- Otherwise set public and statically allocated
5162 Set_Is_Statically_Allocated (E);
5164 -- Warn if the corresponding W flag is set and the pragma comes
5165 -- from source. The latter may not be true e.g. on VMS where we
5166 -- expand export pragmas for exception codes associated with
5167 -- imported or exported exceptions. We do not want to generate
5168 -- a warning for something that the user did not write.
5170 if Warn_On_Export_Import
5171 and then Comes_From_Source (Arg)
5174 ("?& has been made static as a result of Export", Arg, E);
5176 ("\this usage is non-standard and non-portable", Arg);
5181 if Warn_On_Export_Import and then Is_Type (E) then
5182 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5185 if Warn_On_Export_Import and Inside_A_Generic then
5187 ("all instances of& will have the same external name?", Arg, E);
5191 ----------------------------------------------
5192 -- Set_Extended_Import_Export_External_Name --
5193 ----------------------------------------------
5195 procedure Set_Extended_Import_Export_External_Name
5196 (Internal_Ent : Entity_Id;
5197 Arg_External : Node_Id)
5199 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5203 if No (Arg_External) then
5207 Check_Arg_Is_External_Name (Arg_External);
5209 if Nkind (Arg_External) = N_String_Literal then
5210 if String_Length (Strval (Arg_External)) = 0 then
5213 New_Name := Adjust_External_Name_Case (Arg_External);
5216 elsif Nkind (Arg_External) = N_Identifier then
5217 New_Name := Get_Default_External_Name (Arg_External);
5219 -- Check_Arg_Is_External_Name should let through only identifiers and
5220 -- string literals or static string expressions (which are folded to
5221 -- string literals).
5224 raise Program_Error;
5227 -- If we already have an external name set (by a prior normal Import
5228 -- or Export pragma), then the external names must match
5230 if Present (Interface_Name (Internal_Ent)) then
5231 Check_Matching_Internal_Names : declare
5232 S1 : constant String_Id := Strval (Old_Name);
5233 S2 : constant String_Id := Strval (New_Name);
5236 -- Called if names do not match
5242 procedure Mismatch is
5244 Error_Msg_Sloc := Sloc (Old_Name);
5246 ("external name does not match that given #",
5250 -- Start of processing for Check_Matching_Internal_Names
5253 if String_Length (S1) /= String_Length (S2) then
5257 for J in 1 .. String_Length (S1) loop
5258 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5263 end Check_Matching_Internal_Names;
5265 -- Otherwise set the given name
5268 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5269 Check_Duplicated_Export_Name (New_Name);
5271 end Set_Extended_Import_Export_External_Name;
5277 procedure Set_Imported (E : Entity_Id) is
5279 -- Error message if already imported or exported
5281 if Is_Exported (E) or else Is_Imported (E) then
5283 -- Error if being set Exported twice
5285 if Is_Exported (E) then
5286 Error_Msg_NE ("entity& was previously exported", N, E);
5288 -- OK if Import/Interface case
5290 elsif Import_Interface_Present (N) then
5293 -- Error if being set Imported twice
5296 Error_Msg_NE ("entity& was previously imported", N, E);
5299 Error_Msg_Name_1 := Pname;
5301 ("\(pragma% applies to all previous entities)", N);
5303 Error_Msg_Sloc := Sloc (E);
5304 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5306 -- Here if not previously imported or exported, OK to import
5309 Set_Is_Imported (E);
5311 -- If the entity is an object that is not at the library level,
5312 -- then it is statically allocated. We do not worry about objects
5313 -- with address clauses in this context since they are not really
5314 -- imported in the linker sense.
5317 and then not Is_Library_Level_Entity (E)
5318 and then No (Address_Clause (E))
5320 Set_Is_Statically_Allocated (E);
5327 -------------------------
5328 -- Set_Mechanism_Value --
5329 -------------------------
5331 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5332 -- analyzed, since it is semantic nonsense), so we get it in the exact
5333 -- form created by the parser.
5335 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5338 Mech_Name_Id : Name_Id;
5340 procedure Bad_Class;
5341 -- Signal bad descriptor class name
5343 procedure Bad_Mechanism;
5344 -- Signal bad mechanism name
5350 procedure Bad_Class is
5352 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5355 -------------------------
5356 -- Bad_Mechanism_Value --
5357 -------------------------
5359 procedure Bad_Mechanism is
5361 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5364 -- Start of processing for Set_Mechanism_Value
5367 if Mechanism (Ent) /= Default_Mechanism then
5369 ("mechanism for & has already been set", Mech_Name, Ent);
5372 -- MECHANISM_NAME ::= value | reference | descriptor |
5375 if Nkind (Mech_Name) = N_Identifier then
5376 if Chars (Mech_Name) = Name_Value then
5377 Set_Mechanism (Ent, By_Copy);
5380 elsif Chars (Mech_Name) = Name_Reference then
5381 Set_Mechanism (Ent, By_Reference);
5384 elsif Chars (Mech_Name) = Name_Descriptor then
5385 Check_VMS (Mech_Name);
5387 -- Descriptor => Short_Descriptor if pragma was given
5389 if Short_Descriptors then
5390 Set_Mechanism (Ent, By_Short_Descriptor);
5392 Set_Mechanism (Ent, By_Descriptor);
5397 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5398 Check_VMS (Mech_Name);
5399 Set_Mechanism (Ent, By_Short_Descriptor);
5402 elsif Chars (Mech_Name) = Name_Copy then
5404 ("bad mechanism name, Value assumed", Mech_Name);
5410 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5411 -- short_descriptor (CLASS_NAME)
5412 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5414 -- Note: this form is parsed as an indexed component
5416 elsif Nkind (Mech_Name) = N_Indexed_Component then
5417 Class := First (Expressions (Mech_Name));
5419 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5420 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5421 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5422 or else Present (Next (Class))
5426 Mech_Name_Id := Chars (Prefix (Mech_Name));
5428 -- Change Descriptor => Short_Descriptor if pragma was given
5430 if Mech_Name_Id = Name_Descriptor
5431 and then Short_Descriptors
5433 Mech_Name_Id := Name_Short_Descriptor;
5437 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5438 -- short_descriptor (Class => CLASS_NAME)
5439 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5441 -- Note: this form is parsed as a function call
5443 elsif Nkind (Mech_Name) = N_Function_Call then
5444 Param := First (Parameter_Associations (Mech_Name));
5446 if Nkind (Name (Mech_Name)) /= N_Identifier
5447 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5448 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5449 or else Present (Next (Param))
5450 or else No (Selector_Name (Param))
5451 or else Chars (Selector_Name (Param)) /= Name_Class
5455 Class := Explicit_Actual_Parameter (Param);
5456 Mech_Name_Id := Chars (Name (Mech_Name));
5463 -- Fall through here with Class set to descriptor class name
5465 Check_VMS (Mech_Name);
5467 if Nkind (Class) /= N_Identifier then
5470 elsif Mech_Name_Id = Name_Descriptor
5471 and then Chars (Class) = Name_UBS
5473 Set_Mechanism (Ent, By_Descriptor_UBS);
5475 elsif Mech_Name_Id = Name_Descriptor
5476 and then Chars (Class) = Name_UBSB
5478 Set_Mechanism (Ent, By_Descriptor_UBSB);
5480 elsif Mech_Name_Id = Name_Descriptor
5481 and then Chars (Class) = Name_UBA
5483 Set_Mechanism (Ent, By_Descriptor_UBA);
5485 elsif Mech_Name_Id = Name_Descriptor
5486 and then Chars (Class) = Name_S
5488 Set_Mechanism (Ent, By_Descriptor_S);
5490 elsif Mech_Name_Id = Name_Descriptor
5491 and then Chars (Class) = Name_SB
5493 Set_Mechanism (Ent, By_Descriptor_SB);
5495 elsif Mech_Name_Id = Name_Descriptor
5496 and then Chars (Class) = Name_A
5498 Set_Mechanism (Ent, By_Descriptor_A);
5500 elsif Mech_Name_Id = Name_Descriptor
5501 and then Chars (Class) = Name_NCA
5503 Set_Mechanism (Ent, By_Descriptor_NCA);
5505 elsif Mech_Name_Id = Name_Short_Descriptor
5506 and then Chars (Class) = Name_UBS
5508 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5510 elsif Mech_Name_Id = Name_Short_Descriptor
5511 and then Chars (Class) = Name_UBSB
5513 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5515 elsif Mech_Name_Id = Name_Short_Descriptor
5516 and then Chars (Class) = Name_UBA
5518 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5520 elsif Mech_Name_Id = Name_Short_Descriptor
5521 and then Chars (Class) = Name_S
5523 Set_Mechanism (Ent, By_Short_Descriptor_S);
5525 elsif Mech_Name_Id = Name_Short_Descriptor
5526 and then Chars (Class) = Name_SB
5528 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5530 elsif Mech_Name_Id = Name_Short_Descriptor
5531 and then Chars (Class) = Name_A
5533 Set_Mechanism (Ent, By_Short_Descriptor_A);
5535 elsif Mech_Name_Id = Name_Short_Descriptor
5536 and then Chars (Class) = Name_NCA
5538 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5543 end Set_Mechanism_Value;
5545 ---------------------------
5546 -- Set_Ravenscar_Profile --
5547 ---------------------------
5549 -- The tasks to be done here are
5551 -- Set required policies
5553 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5554 -- pragma Locking_Policy (Ceiling_Locking)
5556 -- Set Detect_Blocking mode
5558 -- Set required restrictions (see System.Rident for detailed list)
5560 -- Set the No_Dependence rules
5561 -- No_Dependence => Ada.Asynchronous_Task_Control
5562 -- No_Dependence => Ada.Calendar
5563 -- No_Dependence => Ada.Execution_Time.Group_Budget
5564 -- No_Dependence => Ada.Execution_Time.Timers
5565 -- No_Dependence => Ada.Task_Attributes
5566 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5568 procedure Set_Ravenscar_Profile (N : Node_Id) is
5569 Prefix_Entity : Entity_Id;
5570 Selector_Entity : Entity_Id;
5571 Prefix_Node : Node_Id;
5575 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5577 if Task_Dispatching_Policy /= ' '
5578 and then Task_Dispatching_Policy /= 'F'
5580 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5581 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5583 -- Set the FIFO_Within_Priorities policy, but always preserve
5584 -- System_Location since we like the error message with the run time
5588 Task_Dispatching_Policy := 'F';
5590 if Task_Dispatching_Policy_Sloc /= System_Location then
5591 Task_Dispatching_Policy_Sloc := Loc;
5595 -- pragma Locking_Policy (Ceiling_Locking)
5597 if Locking_Policy /= ' '
5598 and then Locking_Policy /= 'C'
5600 Error_Msg_Sloc := Locking_Policy_Sloc;
5601 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5603 -- Set the Ceiling_Locking policy, but preserve System_Location since
5604 -- we like the error message with the run time name.
5607 Locking_Policy := 'C';
5609 if Locking_Policy_Sloc /= System_Location then
5610 Locking_Policy_Sloc := Loc;
5614 -- pragma Detect_Blocking
5616 Detect_Blocking := True;
5618 -- Set the corresponding restrictions
5620 Set_Profile_Restrictions
5621 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5623 -- Set the No_Dependence restrictions
5625 -- The following No_Dependence restrictions:
5626 -- No_Dependence => Ada.Asynchronous_Task_Control
5627 -- No_Dependence => Ada.Calendar
5628 -- No_Dependence => Ada.Task_Attributes
5629 -- are already set by previous call to Set_Profile_Restrictions.
5631 -- Set the following restrictions which were added to Ada 2005:
5632 -- No_Dependence => Ada.Execution_Time.Group_Budget
5633 -- No_Dependence => Ada.Execution_Time.Timers
5635 if Ada_Version >= Ada_2005 then
5636 Name_Buffer (1 .. 3) := "ada";
5639 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5641 Name_Buffer (1 .. 14) := "execution_time";
5644 Selector_Entity := Make_Identifier (Loc, Name_Find);
5647 Make_Selected_Component
5649 Prefix => Prefix_Entity,
5650 Selector_Name => Selector_Entity);
5652 Name_Buffer (1 .. 13) := "group_budgets";
5655 Selector_Entity := Make_Identifier (Loc, Name_Find);
5658 Make_Selected_Component
5660 Prefix => Prefix_Node,
5661 Selector_Name => Selector_Entity);
5663 Set_Restriction_No_Dependence
5665 Warn => Treat_Restrictions_As_Warnings,
5666 Profile => Ravenscar);
5668 Name_Buffer (1 .. 6) := "timers";
5671 Selector_Entity := Make_Identifier (Loc, Name_Find);
5674 Make_Selected_Component
5676 Prefix => Prefix_Node,
5677 Selector_Name => Selector_Entity);
5679 Set_Restriction_No_Dependence
5681 Warn => Treat_Restrictions_As_Warnings,
5682 Profile => Ravenscar);
5685 -- Set the following restrictions which was added to Ada 2012 (see
5687 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5689 if Ada_Version >= Ada_2012 then
5690 Name_Buffer (1 .. 6) := "system";
5693 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5695 Name_Buffer (1 .. 15) := "multiprocessors";
5698 Selector_Entity := Make_Identifier (Loc, Name_Find);
5701 Make_Selected_Component
5703 Prefix => Prefix_Entity,
5704 Selector_Name => Selector_Entity);
5706 Name_Buffer (1 .. 19) := "dispatching_domains";
5709 Selector_Entity := Make_Identifier (Loc, Name_Find);
5712 Make_Selected_Component
5714 Prefix => Prefix_Node,
5715 Selector_Name => Selector_Entity);
5717 Set_Restriction_No_Dependence
5719 Warn => Treat_Restrictions_As_Warnings,
5720 Profile => Ravenscar);
5722 end Set_Ravenscar_Profile;
5724 -- Start of processing for Analyze_Pragma
5727 -- The following code is a defense against recursion. Not clear that
5728 -- this can happen legitimately, but perhaps some error situations
5729 -- can cause it, and we did see this recursion during testing.
5731 if Analyzed (N) then
5734 Set_Analyzed (N, True);
5737 -- Deal with unrecognized pragma
5739 if not Is_Pragma_Name (Pname) then
5740 if Warn_On_Unrecognized_Pragma then
5741 Error_Msg_Name_1 := Pname;
5742 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5744 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5745 if Is_Bad_Spelling_Of (Pname, PN) then
5746 Error_Msg_Name_1 := PN;
5747 Error_Msg_N -- CODEFIX
5748 ("\?possible misspelling of %!", Pragma_Identifier (N));
5757 -- Here to start processing for recognized pragma
5759 Prag_Id := Get_Pragma_Id (Pname);
5769 if Present (Pragma_Argument_Associations (N)) then
5770 Arg_Count := List_Length (Pragma_Argument_Associations (N));
5771 Arg1 := First (Pragma_Argument_Associations (N));
5773 if Present (Arg1) then
5774 Arg2 := Next (Arg1);
5776 if Present (Arg2) then
5777 Arg3 := Next (Arg2);
5779 if Present (Arg3) then
5780 Arg4 := Next (Arg3);
5786 -- An enumeration type defines the pragmas that are supported by the
5787 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5788 -- into the corresponding enumeration value for the following case.
5796 -- pragma Abort_Defer;
5798 when Pragma_Abort_Defer =>
5800 Check_Arg_Count (0);
5802 -- The only required semantic processing is to check the
5803 -- placement. This pragma must appear at the start of the
5804 -- statement sequence of a handled sequence of statements.
5806 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5807 or else N /= First (Statements (Parent (N)))
5818 -- Note: this pragma also has some specific processing in Par.Prag
5819 -- because we want to set the Ada version mode during parsing.
5821 when Pragma_Ada_83 =>
5823 Check_Arg_Count (0);
5825 -- We really should check unconditionally for proper configuration
5826 -- pragma placement, since we really don't want mixed Ada modes
5827 -- within a single unit, and the GNAT reference manual has always
5828 -- said this was a configuration pragma, but we did not check and
5829 -- are hesitant to add the check now.
5831 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5832 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5833 -- or Ada 2012 mode.
5835 if Ada_Version >= Ada_2005 then
5836 Check_Valid_Configuration_Pragma;
5839 -- Now set Ada 83 mode
5841 Ada_Version := Ada_83;
5842 Ada_Version_Explicit := Ada_Version;
5850 -- Note: this pragma also has some specific processing in Par.Prag
5851 -- because we want to set the Ada 83 version mode during parsing.
5853 when Pragma_Ada_95 =>
5855 Check_Arg_Count (0);
5857 -- We really should check unconditionally for proper configuration
5858 -- pragma placement, since we really don't want mixed Ada modes
5859 -- within a single unit, and the GNAT reference manual has always
5860 -- said this was a configuration pragma, but we did not check and
5861 -- are hesitant to add the check now.
5863 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5864 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5866 if Ada_Version >= Ada_2005 then
5867 Check_Valid_Configuration_Pragma;
5870 -- Now set Ada 95 mode
5872 Ada_Version := Ada_95;
5873 Ada_Version_Explicit := Ada_Version;
5875 ---------------------
5876 -- Ada_05/Ada_2005 --
5877 ---------------------
5880 -- pragma Ada_05 (LOCAL_NAME);
5883 -- pragma Ada_2005 (LOCAL_NAME):
5885 -- Note: these pragmas also have some specific processing in Par.Prag
5886 -- because we want to set the Ada 2005 version mode during parsing.
5888 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5894 if Arg_Count = 1 then
5895 Check_Arg_Is_Local_Name (Arg1);
5896 E_Id := Get_Pragma_Arg (Arg1);
5898 if Etype (E_Id) = Any_Type then
5902 Set_Is_Ada_2005_Only (Entity (E_Id));
5905 Check_Arg_Count (0);
5907 -- For Ada_2005 we unconditionally enforce the documented
5908 -- configuration pragma placement, since we do not want to
5909 -- tolerate mixed modes in a unit involving Ada 2005. That
5910 -- would cause real difficulties for those cases where there
5911 -- are incompatibilities between Ada 95 and Ada 2005.
5913 Check_Valid_Configuration_Pragma;
5915 -- Now set appropriate Ada mode
5917 Ada_Version := Ada_2005;
5918 Ada_Version_Explicit := Ada_2005;
5922 ---------------------
5923 -- Ada_12/Ada_2012 --
5924 ---------------------
5927 -- pragma Ada_12 (LOCAL_NAME);
5930 -- pragma Ada_2012 (LOCAL_NAME):
5932 -- Note: these pragmas also have some specific processing in Par.Prag
5933 -- because we want to set the Ada 2012 version mode during parsing.
5935 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5941 if Arg_Count = 1 then
5942 Check_Arg_Is_Local_Name (Arg1);
5943 E_Id := Get_Pragma_Arg (Arg1);
5945 if Etype (E_Id) = Any_Type then
5949 Set_Is_Ada_2012_Only (Entity (E_Id));
5952 Check_Arg_Count (0);
5954 -- For Ada_2012 we unconditionally enforce the documented
5955 -- configuration pragma placement, since we do not want to
5956 -- tolerate mixed modes in a unit involving Ada 2012. That
5957 -- would cause real difficulties for those cases where there
5958 -- are incompatibilities between Ada 95 and Ada 2012. We could
5959 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5961 Check_Valid_Configuration_Pragma;
5963 -- Now set appropriate Ada mode
5965 Ada_Version := Ada_2012;
5966 Ada_Version_Explicit := Ada_2012;
5970 ----------------------
5971 -- All_Calls_Remote --
5972 ----------------------
5974 -- pragma All_Calls_Remote [(library_package_NAME)];
5976 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5977 Lib_Entity : Entity_Id;
5980 Check_Ada_83_Warning;
5981 Check_Valid_Library_Unit_Pragma;
5983 if Nkind (N) = N_Null_Statement then
5987 Lib_Entity := Find_Lib_Unit_Name;
5989 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5991 if Present (Lib_Entity)
5992 and then not Debug_Flag_U
5994 if not Is_Remote_Call_Interface (Lib_Entity) then
5995 Error_Pragma ("pragma% only apply to rci unit");
5997 -- Set flag for entity of the library unit
6000 Set_Has_All_Calls_Remote (Lib_Entity);
6004 end All_Calls_Remote;
6010 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6011 -- ARG ::= NAME | EXPRESSION
6013 -- The first two arguments are by convention intended to refer to an
6014 -- external tool and a tool-specific function. These arguments are
6017 when Pragma_Annotate => Annotate : begin
6019 Check_At_Least_N_Arguments (1);
6020 Check_Arg_Is_Identifier (Arg1);
6021 Check_No_Identifiers;
6029 -- Second unanalyzed parameter is optional
6035 while Present (Arg) loop
6036 Exp := Get_Pragma_Arg (Arg);
6039 if Is_Entity_Name (Exp) then
6042 -- For string literals, we assume Standard_String as the
6043 -- type, unless the string contains wide or wide_wide
6046 elsif Nkind (Exp) = N_String_Literal then
6047 if Has_Wide_Wide_Character (Exp) then
6048 Resolve (Exp, Standard_Wide_Wide_String);
6049 elsif Has_Wide_Character (Exp) then
6050 Resolve (Exp, Standard_Wide_String);
6052 Resolve (Exp, Standard_String);
6055 elsif Is_Overloaded (Exp) then
6057 ("ambiguous argument for pragma%", Exp);
6073 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6074 -- [, [Message =>] Static_String_EXPRESSION]);
6076 when Pragma_Assert => Assert : declare
6082 Check_At_Least_N_Arguments (1);
6083 Check_At_Most_N_Arguments (2);
6084 Check_Arg_Order ((Name_Check, Name_Message));
6085 Check_Optional_Identifier (Arg1, Name_Check);
6087 -- We treat pragma Assert as equivalent to:
6089 -- pragma Check (Assertion, condition [, msg]);
6091 -- So rewrite pragma in this manner, and analyze the result
6093 Expr := Get_Pragma_Arg (Arg1);
6095 Make_Pragma_Argument_Association (Loc,
6096 Expression => Make_Identifier (Loc, Name_Assertion)),
6098 Make_Pragma_Argument_Association (Sloc (Expr),
6099 Expression => Expr));
6101 if Arg_Count > 1 then
6102 Check_Optional_Identifier (Arg2, Name_Message);
6103 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6104 Append_To (Newa, Relocate_Node (Arg2));
6109 Chars => Name_Check,
6110 Pragma_Argument_Associations => Newa));
6114 ----------------------
6115 -- Assertion_Policy --
6116 ----------------------
6118 -- pragma Assertion_Policy (Check | Ignore)
6120 when Pragma_Assertion_Policy => Assertion_Policy : declare
6125 Check_Valid_Configuration_Pragma;
6126 Check_Arg_Count (1);
6127 Check_No_Identifiers;
6128 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6130 -- We treat pragma Assertion_Policy as equivalent to:
6132 -- pragma Check_Policy (Assertion, policy)
6134 -- So rewrite the pragma in that manner and link on to the chain
6135 -- of Check_Policy pragmas, marking the pragma as analyzed.
6137 Policy := Get_Pragma_Arg (Arg1);
6141 Chars => Name_Check_Policy,
6143 Pragma_Argument_Associations => New_List (
6144 Make_Pragma_Argument_Association (Loc,
6145 Expression => Make_Identifier (Loc, Name_Assertion)),
6147 Make_Pragma_Argument_Association (Loc,
6149 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6152 Set_Next_Pragma (N, Opt.Check_Policy_List);
6153 Opt.Check_Policy_List := N;
6154 end Assertion_Policy;
6156 ------------------------------
6157 -- Assume_No_Invalid_Values --
6158 ------------------------------
6160 -- pragma Assume_No_Invalid_Values (On | Off);
6162 when Pragma_Assume_No_Invalid_Values =>
6164 Check_Valid_Configuration_Pragma;
6165 Check_Arg_Count (1);
6166 Check_No_Identifiers;
6167 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6169 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6170 Assume_No_Invalid_Values := True;
6172 Assume_No_Invalid_Values := False;
6179 -- pragma AST_Entry (entry_IDENTIFIER);
6181 when Pragma_AST_Entry => AST_Entry : declare
6187 Check_Arg_Count (1);
6188 Check_No_Identifiers;
6189 Check_Arg_Is_Local_Name (Arg1);
6190 Ent := Entity (Get_Pragma_Arg (Arg1));
6192 -- Note: the implementation of the AST_Entry pragma could handle
6193 -- the entry family case fine, but for now we are consistent with
6194 -- the DEC rules, and do not allow the pragma, which of course
6195 -- has the effect of also forbidding the attribute.
6197 if Ekind (Ent) /= E_Entry then
6199 ("pragma% argument must be simple entry name", Arg1);
6201 elsif Is_AST_Entry (Ent) then
6203 ("duplicate % pragma for entry", Arg1);
6205 elsif Has_Homonym (Ent) then
6207 ("pragma% argument cannot specify overloaded entry", Arg1);
6211 FF : constant Entity_Id := First_Formal (Ent);
6214 if Present (FF) then
6215 if Present (Next_Formal (FF)) then
6217 ("entry for pragma% can have only one argument",
6220 elsif Parameter_Mode (FF) /= E_In_Parameter then
6222 ("entry parameter for pragma% must have mode IN",
6228 Set_Is_AST_Entry (Ent);
6236 -- pragma Asynchronous (LOCAL_NAME);
6238 when Pragma_Asynchronous => Asynchronous : declare
6246 procedure Process_Async_Pragma;
6247 -- Common processing for procedure and access-to-procedure case
6249 --------------------------
6250 -- Process_Async_Pragma --
6251 --------------------------
6253 procedure Process_Async_Pragma is
6256 Set_Is_Asynchronous (Nm);
6260 -- The formals should be of mode IN (RM E.4.1(6))
6263 while Present (S) loop
6264 Formal := Defining_Identifier (S);
6266 if Nkind (Formal) = N_Defining_Identifier
6267 and then Ekind (Formal) /= E_In_Parameter
6270 ("pragma% procedure can only have IN parameter",
6277 Set_Is_Asynchronous (Nm);
6278 end Process_Async_Pragma;
6280 -- Start of processing for pragma Asynchronous
6283 Check_Ada_83_Warning;
6284 Check_No_Identifiers;
6285 Check_Arg_Count (1);
6286 Check_Arg_Is_Local_Name (Arg1);
6288 if Debug_Flag_U then
6292 C_Ent := Cunit_Entity (Current_Sem_Unit);
6293 Analyze (Get_Pragma_Arg (Arg1));
6294 Nm := Entity (Get_Pragma_Arg (Arg1));
6296 if not Is_Remote_Call_Interface (C_Ent)
6297 and then not Is_Remote_Types (C_Ent)
6299 -- This pragma should only appear in an RCI or Remote Types
6300 -- unit (RM E.4.1(4)).
6303 ("pragma% not in Remote_Call_Interface or " &
6304 "Remote_Types unit");
6307 if Ekind (Nm) = E_Procedure
6308 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6310 if not Is_Remote_Call_Interface (Nm) then
6312 ("pragma% cannot be applied on non-remote procedure",
6316 L := Parameter_Specifications (Parent (Nm));
6317 Process_Async_Pragma;
6320 elsif Ekind (Nm) = E_Function then
6322 ("pragma% cannot be applied to function", Arg1);
6324 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6326 if Is_Record_Type (Nm) then
6328 -- A record type that is the Equivalent_Type for a remote
6329 -- access-to-subprogram type.
6331 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6334 -- A non-expanded RAS type (distribution is not enabled)
6336 N := Declaration_Node (Nm);
6339 if Nkind (N) = N_Full_Type_Declaration
6340 and then Nkind (Type_Definition (N)) =
6341 N_Access_Procedure_Definition
6343 L := Parameter_Specifications (Type_Definition (N));
6344 Process_Async_Pragma;
6346 if Is_Asynchronous (Nm)
6347 and then Expander_Active
6348 and then Get_PCS_Name /= Name_No_DSA
6350 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6355 ("pragma% cannot reference access-to-function type",
6359 -- Only other possibility is Access-to-class-wide type
6361 elsif Is_Access_Type (Nm)
6362 and then Is_Class_Wide_Type (Designated_Type (Nm))
6364 Check_First_Subtype (Arg1);
6365 Set_Is_Asynchronous (Nm);
6366 if Expander_Active then
6367 RACW_Type_Is_Asynchronous (Nm);
6371 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6379 -- pragma Atomic (LOCAL_NAME);
6381 when Pragma_Atomic =>
6382 Process_Atomic_Shared_Volatile;
6384 -----------------------
6385 -- Atomic_Components --
6386 -----------------------
6388 -- pragma Atomic_Components (array_LOCAL_NAME);
6390 -- This processing is shared by Volatile_Components
6392 when Pragma_Atomic_Components |
6393 Pragma_Volatile_Components =>
6395 Atomic_Components : declare
6402 Check_Ada_83_Warning;
6403 Check_No_Identifiers;
6404 Check_Arg_Count (1);
6405 Check_Arg_Is_Local_Name (Arg1);
6406 E_Id := Get_Pragma_Arg (Arg1);
6408 if Etype (E_Id) = Any_Type then
6414 Check_Duplicate_Pragma (E);
6416 if Rep_Item_Too_Early (E, N)
6418 Rep_Item_Too_Late (E, N)
6423 D := Declaration_Node (E);
6426 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6428 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6429 and then Nkind (D) = N_Object_Declaration
6430 and then Nkind (Object_Definition (D)) =
6431 N_Constrained_Array_Definition)
6433 -- The flag is set on the object, or on the base type
6435 if Nkind (D) /= N_Object_Declaration then
6439 Set_Has_Volatile_Components (E);
6441 if Prag_Id = Pragma_Atomic_Components then
6442 Set_Has_Atomic_Components (E);
6446 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6448 end Atomic_Components;
6450 --------------------
6451 -- Attach_Handler --
6452 --------------------
6454 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6456 when Pragma_Attach_Handler =>
6457 Check_Ada_83_Warning;
6458 Check_No_Identifiers;
6459 Check_Arg_Count (2);
6461 if No_Run_Time_Mode then
6462 Error_Msg_CRT ("Attach_Handler pragma", N);
6464 Check_Interrupt_Or_Attach_Handler;
6466 -- The expression that designates the attribute may depend on a
6467 -- discriminant, and is therefore a per- object expression, to
6468 -- be expanded in the init proc. If expansion is enabled, then
6469 -- perform semantic checks on a copy only.
6471 if Expander_Active then
6473 Temp : constant Node_Id :=
6474 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6476 Set_Parent (Temp, N);
6477 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6481 Analyze (Get_Pragma_Arg (Arg2));
6482 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6485 Process_Interrupt_Or_Attach_Handler;
6488 --------------------
6489 -- C_Pass_By_Copy --
6490 --------------------
6492 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6494 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6500 Check_Valid_Configuration_Pragma;
6501 Check_Arg_Count (1);
6502 Check_Optional_Identifier (Arg1, "max_size");
6504 Arg := Get_Pragma_Arg (Arg1);
6505 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6507 Val := Expr_Value (Arg);
6511 ("maximum size for pragma% must be positive", Arg1);
6513 elsif UI_Is_In_Int_Range (Val) then
6514 Default_C_Record_Mechanism := UI_To_Int (Val);
6516 -- If a giant value is given, Int'Last will do well enough.
6517 -- If sometime someone complains that a record larger than
6518 -- two gigabytes is not copied, we will worry about it then!
6521 Default_C_Record_Mechanism := Mechanism_Type'Last;
6529 -- pragma Check ([Name =>] Identifier,
6530 -- [Check =>] Boolean_Expression
6531 -- [,[Message =>] String_Expression]);
6533 when Pragma_Check => Check : declare
6538 -- Set True if category of assertions referenced by Name enabled
6542 Check_At_Least_N_Arguments (2);
6543 Check_At_Most_N_Arguments (3);
6544 Check_Optional_Identifier (Arg1, Name_Name);
6545 Check_Optional_Identifier (Arg2, Name_Check);
6547 if Arg_Count = 3 then
6548 Check_Optional_Identifier (Arg3, Name_Message);
6549 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6552 Check_Arg_Is_Identifier (Arg1);
6554 -- Indicate if pragma is enabled. The Original_Node reference here
6555 -- is to deal with pragma Assert rewritten as a Check pragma.
6557 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6560 Set_Pragma_Enabled (N);
6561 Set_Pragma_Enabled (Original_Node (N));
6562 Set_SCO_Pragma_Enabled (Loc);
6565 -- If expansion is active and the check is not enabled then we
6566 -- rewrite the Check as:
6568 -- if False and then condition then
6572 -- The reason we do this rewriting during semantic analysis rather
6573 -- than as part of normal expansion is that we cannot analyze and
6574 -- expand the code for the boolean expression directly, or it may
6575 -- cause insertion of actions that would escape the attempt to
6576 -- suppress the check code.
6578 -- Note that the Sloc for the if statement corresponds to the
6579 -- argument condition, not the pragma itself. The reason for this
6580 -- is that we may generate a warning if the condition is False at
6581 -- compile time, and we do not want to delete this warning when we
6582 -- delete the if statement.
6584 Expr := Get_Pragma_Arg (Arg2);
6586 if Expander_Active and then not Check_On then
6587 Eloc := Sloc (Expr);
6590 Make_If_Statement (Eloc,
6592 Make_And_Then (Eloc,
6593 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6594 Right_Opnd => Expr),
6595 Then_Statements => New_List (
6596 Make_Null_Statement (Eloc))));
6603 Analyze_And_Resolve (Expr, Any_Boolean);
6611 -- pragma Check_Name (check_IDENTIFIER);
6613 when Pragma_Check_Name =>
6614 Check_No_Identifiers;
6616 Check_Valid_Configuration_Pragma;
6617 Check_Arg_Count (1);
6618 Check_Arg_Is_Identifier (Arg1);
6621 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6624 for J in Check_Names.First .. Check_Names.Last loop
6625 if Check_Names.Table (J) = Nam then
6630 Check_Names.Append (Nam);
6637 -- pragma Check_Policy (
6638 -- [Name =>] IDENTIFIER,
6639 -- [Policy =>] POLICY_IDENTIFIER);
6641 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6643 -- Note: this is a configuration pragma, but it is allowed to appear
6646 when Pragma_Check_Policy =>
6648 Check_Arg_Count (2);
6649 Check_Optional_Identifier (Arg1, Name_Name);
6650 Check_Optional_Identifier (Arg2, Name_Policy);
6652 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6654 -- A Check_Policy pragma can appear either as a configuration
6655 -- pragma, or in a declarative part or a package spec (see RM
6656 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6657 -- followed for Check_Policy).
6659 if not Is_Configuration_Pragma then
6660 Check_Is_In_Decl_Part_Or_Package_Spec;
6663 Set_Next_Pragma (N, Opt.Check_Policy_List);
6664 Opt.Check_Policy_List := N;
6666 ---------------------
6667 -- CIL_Constructor --
6668 ---------------------
6670 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6672 -- Processing for this pragma is shared with Java_Constructor
6678 -- pragma Comment (static_string_EXPRESSION)
6680 -- Processing for pragma Comment shares the circuitry for pragma
6681 -- Ident. The only differences are that Ident enforces a limit of 31
6682 -- characters on its argument, and also enforces limitations on
6683 -- placement for DEC compatibility. Pragma Comment shares neither of
6684 -- these restrictions.
6690 -- pragma Common_Object (
6691 -- [Internal =>] LOCAL_NAME
6692 -- [, [External =>] EXTERNAL_SYMBOL]
6693 -- [, [Size =>] EXTERNAL_SYMBOL]);
6695 -- Processing for this pragma is shared with Psect_Object
6697 ------------------------
6698 -- Compile_Time_Error --
6699 ------------------------
6701 -- pragma Compile_Time_Error
6702 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6704 when Pragma_Compile_Time_Error =>
6706 Process_Compile_Time_Warning_Or_Error;
6708 --------------------------
6709 -- Compile_Time_Warning --
6710 --------------------------
6712 -- pragma Compile_Time_Warning
6713 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6715 when Pragma_Compile_Time_Warning =>
6717 Process_Compile_Time_Warning_Or_Error;
6723 when Pragma_Compiler_Unit =>
6725 Check_Arg_Count (0);
6726 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6728 -----------------------------
6729 -- Complete_Representation --
6730 -----------------------------
6732 -- pragma Complete_Representation;
6734 when Pragma_Complete_Representation =>
6736 Check_Arg_Count (0);
6738 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6740 ("pragma & must appear within record representation clause");
6743 ----------------------------
6744 -- Complex_Representation --
6745 ----------------------------
6747 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6749 when Pragma_Complex_Representation => Complex_Representation : declare
6756 Check_Arg_Count (1);
6757 Check_Optional_Identifier (Arg1, Name_Entity);
6758 Check_Arg_Is_Local_Name (Arg1);
6759 E_Id := Get_Pragma_Arg (Arg1);
6761 if Etype (E_Id) = Any_Type then
6767 if not Is_Record_Type (E) then
6769 ("argument for pragma% must be record type", Arg1);
6772 Ent := First_Entity (E);
6775 or else No (Next_Entity (Ent))
6776 or else Present (Next_Entity (Next_Entity (Ent)))
6777 or else not Is_Floating_Point_Type (Etype (Ent))
6778 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6781 ("record for pragma% must have two fields of the same "
6782 & "floating-point type", Arg1);
6785 Set_Has_Complex_Representation (Base_Type (E));
6787 -- We need to treat the type has having a non-standard
6788 -- representation, for back-end purposes, even though in
6789 -- general a complex will have the default representation
6790 -- of a record with two real components.
6792 Set_Has_Non_Standard_Rep (Base_Type (E));
6794 end Complex_Representation;
6796 -------------------------
6797 -- Component_Alignment --
6798 -------------------------
6800 -- pragma Component_Alignment (
6801 -- [Form =>] ALIGNMENT_CHOICE
6802 -- [, [Name =>] type_LOCAL_NAME]);
6804 -- ALIGNMENT_CHOICE ::=
6806 -- | Component_Size_4
6810 when Pragma_Component_Alignment => Component_AlignmentP : declare
6811 Args : Args_List (1 .. 2);
6812 Names : constant Name_List (1 .. 2) := (
6816 Form : Node_Id renames Args (1);
6817 Name : Node_Id renames Args (2);
6819 Atype : Component_Alignment_Kind;
6824 Gather_Associations (Names, Args);
6827 Error_Pragma ("missing Form argument for pragma%");
6830 Check_Arg_Is_Identifier (Form);
6832 -- Get proper alignment, note that Default = Component_Size on all
6833 -- machines we have so far, and we want to set this value rather
6834 -- than the default value to indicate that it has been explicitly
6835 -- set (and thus will not get overridden by the default component
6836 -- alignment for the current scope)
6838 if Chars (Form) = Name_Component_Size then
6839 Atype := Calign_Component_Size;
6841 elsif Chars (Form) = Name_Component_Size_4 then
6842 Atype := Calign_Component_Size_4;
6844 elsif Chars (Form) = Name_Default then
6845 Atype := Calign_Component_Size;
6847 elsif Chars (Form) = Name_Storage_Unit then
6848 Atype := Calign_Storage_Unit;
6852 ("invalid Form parameter for pragma%", Form);
6855 -- Case with no name, supplied, affects scope table entry
6859 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6861 -- Case of name supplied
6864 Check_Arg_Is_Local_Name (Name);
6866 Typ := Entity (Name);
6869 or else Rep_Item_Too_Early (Typ, N)
6873 Typ := Underlying_Type (Typ);
6876 if not Is_Record_Type (Typ)
6877 and then not Is_Array_Type (Typ)
6880 ("Name parameter of pragma% must identify record or " &
6881 "array type", Name);
6884 -- An explicit Component_Alignment pragma overrides an
6885 -- implicit pragma Pack, but not an explicit one.
6887 if not Has_Pragma_Pack (Base_Type (Typ)) then
6888 Set_Is_Packed (Base_Type (Typ), False);
6889 Set_Component_Alignment (Base_Type (Typ), Atype);
6892 end Component_AlignmentP;
6898 -- pragma Controlled (first_subtype_LOCAL_NAME);
6900 when Pragma_Controlled => Controlled : declare
6904 Check_No_Identifiers;
6905 Check_Arg_Count (1);
6906 Check_Arg_Is_Local_Name (Arg1);
6907 Arg := Get_Pragma_Arg (Arg1);
6909 if not Is_Entity_Name (Arg)
6910 or else not Is_Access_Type (Entity (Arg))
6912 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6914 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6922 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6923 -- [Entity =>] LOCAL_NAME);
6925 when Pragma_Convention => Convention : declare
6928 pragma Warnings (Off, C);
6929 pragma Warnings (Off, E);
6931 Check_Arg_Order ((Name_Convention, Name_Entity));
6932 Check_Ada_83_Warning;
6933 Check_Arg_Count (2);
6934 Process_Convention (C, E);
6937 ---------------------------
6938 -- Convention_Identifier --
6939 ---------------------------
6941 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6942 -- [Convention =>] convention_IDENTIFIER);
6944 when Pragma_Convention_Identifier => Convention_Identifier : declare
6950 Check_Arg_Order ((Name_Name, Name_Convention));
6951 Check_Arg_Count (2);
6952 Check_Optional_Identifier (Arg1, Name_Name);
6953 Check_Optional_Identifier (Arg2, Name_Convention);
6954 Check_Arg_Is_Identifier (Arg1);
6955 Check_Arg_Is_Identifier (Arg2);
6956 Idnam := Chars (Get_Pragma_Arg (Arg1));
6957 Cname := Chars (Get_Pragma_Arg (Arg2));
6959 if Is_Convention_Name (Cname) then
6960 Record_Convention_Identifier
6961 (Idnam, Get_Convention_Id (Cname));
6964 ("second arg for % pragma must be convention", Arg2);
6966 end Convention_Identifier;
6972 -- pragma CPP_Class ([Entity =>] local_NAME)
6974 when Pragma_CPP_Class => CPP_Class : declare
6979 if Warn_On_Obsolescent_Feature then
6981 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6982 " by pragma import?", N);
6986 Check_Arg_Count (1);
6987 Check_Optional_Identifier (Arg1, Name_Entity);
6988 Check_Arg_Is_Local_Name (Arg1);
6990 Arg := Get_Pragma_Arg (Arg1);
6993 if Etype (Arg) = Any_Type then
6997 if not Is_Entity_Name (Arg)
6998 or else not Is_Type (Entity (Arg))
7000 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7003 Typ := Entity (Arg);
7005 if not Is_Tagged_Type (Typ) then
7006 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7009 -- Types treated as CPP classes are treated as limited, but we
7010 -- don't require them to be declared this way. A warning is issued
7011 -- to encourage the user to declare them as limited. This is not
7012 -- an error, for compatibility reasons, because these types have
7013 -- been supported this way for some time.
7015 if not Is_Limited_Type (Typ) then
7017 ("imported 'C'P'P type should be " &
7018 "explicitly declared limited?",
7019 Get_Pragma_Arg (Arg1));
7021 ("\type will be considered limited",
7022 Get_Pragma_Arg (Arg1));
7025 Set_Is_CPP_Class (Typ);
7026 Set_Is_Limited_Record (Typ);
7027 Set_Convention (Typ, Convention_CPP);
7029 -- Imported CPP types must not have discriminants (because C++
7030 -- classes do not have discriminants).
7032 if Has_Discriminants (Typ) then
7034 ("imported 'C'P'P type cannot have discriminants",
7035 First (Discriminant_Specifications
7036 (Declaration_Node (Typ))));
7039 -- Components of imported CPP types must not have default
7040 -- expressions because the constructor (if any) is in the
7043 if Is_Incomplete_Or_Private_Type (Typ)
7044 and then No (Underlying_Type (Typ))
7046 -- It should be an error to apply pragma CPP to a private
7047 -- type if the underlying type is not visible (as it is
7048 -- for any representation item). For now, for backward
7049 -- compatibility we do nothing but we cannot check components
7050 -- because they are not available at this stage. All this code
7051 -- will be removed when we cleanup this obsolete GNAT pragma???
7057 Tdef : constant Node_Id :=
7058 Type_Definition (Declaration_Node (Typ));
7063 if Nkind (Tdef) = N_Record_Definition then
7064 Clist := Component_List (Tdef);
7066 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7067 Clist := Component_List (Record_Extension_Part (Tdef));
7070 if Present (Clist) then
7071 Comp := First (Component_Items (Clist));
7072 while Present (Comp) loop
7073 if Present (Expression (Comp)) then
7075 ("component of imported 'C'P'P type cannot have" &
7076 " default expression", Expression (Comp));
7086 ---------------------
7087 -- CPP_Constructor --
7088 ---------------------
7090 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7091 -- [, [External_Name =>] static_string_EXPRESSION ]
7092 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7094 when Pragma_CPP_Constructor => CPP_Constructor : declare
7098 Tag_Typ : Entity_Id;
7102 Check_At_Least_N_Arguments (1);
7103 Check_At_Most_N_Arguments (3);
7104 Check_Optional_Identifier (Arg1, Name_Entity);
7105 Check_Arg_Is_Local_Name (Arg1);
7107 Id := Get_Pragma_Arg (Arg1);
7108 Find_Program_Unit_Name (Id);
7110 -- If we did not find the name, we are done
7112 if Etype (Id) = Any_Type then
7116 Def_Id := Entity (Id);
7118 -- Check if already defined as constructor
7120 if Is_Constructor (Def_Id) then
7122 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7126 if Ekind (Def_Id) = E_Function
7127 and then (Is_CPP_Class (Etype (Def_Id))
7128 or else (Is_Class_Wide_Type (Etype (Def_Id))
7130 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7132 if Arg_Count >= 2 then
7133 Set_Imported (Def_Id);
7134 Set_Is_Public (Def_Id);
7135 Process_Interface_Name (Def_Id, Arg2, Arg3);
7138 Set_Has_Completion (Def_Id);
7139 Set_Is_Constructor (Def_Id);
7141 -- Imported C++ constructors are not dispatching primitives
7142 -- because in C++ they don't have a dispatch table slot.
7143 -- However, in Ada the constructor has the profile of a
7144 -- function that returns a tagged type and therefore it has
7145 -- been treated as a primitive operation during semantic
7146 -- analysis. We now remove it from the list of primitive
7147 -- operations of the type.
7149 if Is_Tagged_Type (Etype (Def_Id))
7150 and then not Is_Class_Wide_Type (Etype (Def_Id))
7152 pragma Assert (Is_Dispatching_Operation (Def_Id));
7153 Tag_Typ := Etype (Def_Id);
7155 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7156 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7160 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7161 Set_Is_Dispatching_Operation (Def_Id, False);
7164 -- For backward compatibility, if the constructor returns a
7165 -- class wide type, and we internally change the return type to
7166 -- the corresponding root type.
7168 if Is_Class_Wide_Type (Etype (Def_Id)) then
7169 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7173 ("pragma% requires function returning a 'C'P'P_Class type",
7176 end CPP_Constructor;
7182 when Pragma_CPP_Virtual => CPP_Virtual : declare
7186 if Warn_On_Obsolescent_Feature then
7188 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7197 when Pragma_CPP_Vtable => CPP_Vtable : declare
7201 if Warn_On_Obsolescent_Feature then
7203 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7212 -- pragma CPU (EXPRESSION);
7214 when Pragma_CPU => CPU : declare
7215 P : constant Node_Id := Parent (N);
7220 Check_No_Identifiers;
7221 Check_Arg_Count (1);
7225 if Nkind (P) = N_Subprogram_Body then
7226 Check_In_Main_Program;
7228 Arg := Get_Pragma_Arg (Arg1);
7229 Analyze_And_Resolve (Arg, Any_Integer);
7233 if not Is_Static_Expression (Arg) then
7234 Flag_Non_Static_Expr
7235 ("main subprogram affinity is not static!", Arg);
7238 -- If constraint error, then we already signalled an error
7240 elsif Raises_Constraint_Error (Arg) then
7243 -- Otherwise check in range
7247 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7248 -- This is the entity System.Multiprocessors.CPU_Range;
7250 Val : constant Uint := Expr_Value (Arg);
7253 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7255 Val > Expr_Value (Type_High_Bound (CPU_Id))
7258 ("main subprogram CPU is out of range", Arg1);
7264 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7268 elsif Nkind (P) = N_Task_Definition then
7269 Arg := Get_Pragma_Arg (Arg1);
7271 -- The expression must be analyzed in the special manner
7272 -- described in "Handling of Default and Per-Object
7273 -- Expressions" in sem.ads.
7275 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7277 -- Anything else is incorrect
7283 if Has_Pragma_CPU (P) then
7284 Error_Pragma ("duplicate pragma% not allowed");
7286 Set_Has_Pragma_CPU (P, True);
7288 if Nkind (P) = N_Task_Definition then
7289 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7298 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7300 when Pragma_Debug => Debug : declare
7308 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7311 if Arg_Count = 2 then
7314 Left_Opnd => Relocate_Node (Cond),
7315 Right_Opnd => Get_Pragma_Arg (Arg1));
7318 -- Rewrite into a conditional with an appropriate condition. We
7319 -- wrap the procedure call in a block so that overhead from e.g.
7320 -- use of the secondary stack does not generate execution overhead
7321 -- for suppressed conditions.
7323 Rewrite (N, Make_Implicit_If_Statement (N,
7325 Then_Statements => New_List (
7326 Make_Block_Statement (Loc,
7327 Handled_Statement_Sequence =>
7328 Make_Handled_Sequence_Of_Statements (Loc,
7329 Statements => New_List (
7330 Relocate_Node (Debug_Statement (N))))))));
7338 -- pragma Debug_Policy (Check | Ignore)
7340 when Pragma_Debug_Policy =>
7342 Check_Arg_Count (1);
7343 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7344 Debug_Pragmas_Enabled :=
7345 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7347 -----------------------------
7348 -- Default_Component_Value --
7349 -----------------------------
7351 when Pragma_Default_Component_Value => declare
7357 Check_Arg_Count (2);
7358 Check_Arg_Is_Local_Name (Arg1);
7360 Arg := Get_Pragma_Arg (Arg1);
7363 if Etype (Arg) = Any_Type then
7367 if not Is_Entity_Name (Arg)
7368 or else not Is_Array_Type (Entity (Arg))
7370 Error_Pragma_Arg ("pragma% requires an array type", Arg1);
7373 Check_First_Subtype (Arg1);
7376 Check_Duplicate_Pragma (E);
7378 -- Check for rep item too early or too late, but skip this if
7379 -- the pragma comes from the corresponding aspect, since we do
7380 -- not need the checks, and more importantly, the pragma is on
7381 -- the rep item chain alreay, and must not be put there twice!
7383 if not From_Aspect_Specification (N) then
7384 if Rep_Item_Too_Early (E, N)
7386 Rep_Item_Too_Late (E, N)
7392 -- Analyze the default value
7394 Arg := Get_Pragma_Arg (Arg2);
7395 Analyze_And_Resolve (Arg, Component_Type (E));
7397 if not Is_OK_Static_Expression (Arg) then
7398 Flag_Non_Static_Expr
7399 ("non-static expression not allowed for " &
7400 "Default_Component_Value",
7405 -- Set the flag on the root type and then check for Rep_Item too
7406 -- early or too late, the latter call chains the pragma onto the
7409 Set_Has_Default_Component_Value (Base_Type (E));
7416 when Pragma_Default_Value => declare
7424 Check_Arg_Count (2);
7425 Check_Arg_Is_Local_Name (Arg1);
7427 Arg := Get_Pragma_Arg (Arg1);
7430 if Etype (Arg) = Any_Type then
7434 if not Is_Entity_Name (Arg)
7435 or else not Is_Scalar_Type (Entity (Arg))
7437 Error_Pragma_Arg ("pragma% requires a scalar type", Arg1);
7440 Check_First_Subtype (Arg1);
7443 Check_Duplicate_Pragma (E);
7445 -- Check for rep item too early or too late, but skip this if
7446 -- the pragma comes from the corresponding aspect, since we do
7447 -- not need the checks, and more importantly, the pragma is on
7448 -- the rep item chain alreay, and must not be put there twice!
7450 if not From_Aspect_Specification (N) then
7451 if Rep_Item_Too_Early (E, N)
7453 Rep_Item_Too_Late (E, N)
7459 -- Analyze the default value. Note that we must do that after
7460 -- checking for Rep_Item_Too_Late since this resolution will
7461 -- freeze the type involved.
7463 Arg := Get_Pragma_Arg (Arg2);
7464 Analyze_And_Resolve (Arg, E);
7466 if not Is_OK_Static_Expression (Arg) then
7467 Flag_Non_Static_Expr
7468 ("non-static expression not allowed for Default_Value",
7473 -- Set the flag on the root type and then check for Rep_Item too
7474 -- early or too late, the latter call chains the pragma onto the
7477 Set_Has_Default_Value (Base_Type (E));
7480 ---------------------
7481 -- Detect_Blocking --
7482 ---------------------
7484 -- pragma Detect_Blocking;
7486 when Pragma_Detect_Blocking =>
7488 Check_Arg_Count (0);
7489 Check_Valid_Configuration_Pragma;
7490 Detect_Blocking := True;
7492 --------------------------
7493 -- Default_Storage_Pool --
7494 --------------------------
7496 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7498 when Pragma_Default_Storage_Pool =>
7500 Check_Arg_Count (1);
7502 -- Default_Storage_Pool can appear as a configuration pragma, or
7503 -- in a declarative part or a package spec.
7505 if not Is_Configuration_Pragma then
7506 Check_Is_In_Decl_Part_Or_Package_Spec;
7509 -- Case of Default_Storage_Pool (null);
7511 if Nkind (Expression (Arg1)) = N_Null then
7512 Analyze (Expression (Arg1));
7514 -- This is an odd case, this is not really an expression, so
7515 -- we don't have a type for it. So just set the type to Empty.
7517 Set_Etype (Expression (Arg1), Empty);
7519 -- Case of Default_Storage_Pool (storage_pool_NAME);
7522 -- If it's a configuration pragma, then the only allowed
7523 -- argument is "null".
7525 if Is_Configuration_Pragma then
7526 Error_Pragma_Arg ("NULL expected", Arg1);
7529 -- The expected type for a non-"null" argument is
7530 -- Root_Storage_Pool'Class.
7533 (Get_Pragma_Arg (Arg1),
7534 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7537 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7538 -- for an access type will use this information to set the
7539 -- appropriate attributes of the access type.
7541 Default_Pool := Expression (Arg1);
7547 when Pragma_Dimension =>
7549 Check_Arg_Count (4);
7550 Check_No_Identifiers;
7551 Check_Arg_Is_Local_Name (Arg1);
7553 if not Is_Type (Arg1) then
7554 Error_Pragma ("first argument for pragma% must be subtype");
7557 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7558 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7559 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7565 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7567 when Pragma_Discard_Names => Discard_Names : declare
7572 Check_Ada_83_Warning;
7574 -- Deal with configuration pragma case
7576 if Arg_Count = 0 and then Is_Configuration_Pragma then
7577 Global_Discard_Names := True;
7580 -- Otherwise, check correct appropriate context
7583 Check_Is_In_Decl_Part_Or_Package_Spec;
7585 if Arg_Count = 0 then
7587 -- If there is no parameter, then from now on this pragma
7588 -- applies to any enumeration, exception or tagged type
7589 -- defined in the current declarative part, and recursively
7590 -- to any nested scope.
7592 Set_Discard_Names (Current_Scope);
7596 Check_Arg_Count (1);
7597 Check_Optional_Identifier (Arg1, Name_On);
7598 Check_Arg_Is_Local_Name (Arg1);
7600 E_Id := Get_Pragma_Arg (Arg1);
7602 if Etype (E_Id) = Any_Type then
7608 if (Is_First_Subtype (E)
7610 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7611 or else Ekind (E) = E_Exception
7613 Set_Discard_Names (E);
7616 ("inappropriate entity for pragma%", Arg1);
7627 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7629 when Pragma_Elaborate => Elaborate : declare
7634 -- Pragma must be in context items list of a compilation unit
7636 if not Is_In_Context_Clause then
7640 -- Must be at least one argument
7642 if Arg_Count = 0 then
7643 Error_Pragma ("pragma% requires at least one argument");
7646 -- In Ada 83 mode, there can be no items following it in the
7647 -- context list except other pragmas and implicit with clauses
7648 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7649 -- placement rule does not apply.
7651 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7653 while Present (Citem) loop
7654 if Nkind (Citem) = N_Pragma
7655 or else (Nkind (Citem) = N_With_Clause
7656 and then Implicit_With (Citem))
7661 ("(Ada 83) pragma% must be at end of context clause");
7668 -- Finally, the arguments must all be units mentioned in a with
7669 -- clause in the same context clause. Note we already checked (in
7670 -- Par.Prag) that the arguments are all identifiers or selected
7674 Outer : while Present (Arg) loop
7675 Citem := First (List_Containing (N));
7676 Inner : while Citem /= N loop
7677 if Nkind (Citem) = N_With_Clause
7678 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7680 Set_Elaborate_Present (Citem, True);
7681 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7683 -- With the pragma present, elaboration calls on
7684 -- subprograms from the named unit need no further
7685 -- checks, as long as the pragma appears in the current
7686 -- compilation unit. If the pragma appears in some unit
7687 -- in the context, there might still be a need for an
7688 -- Elaborate_All_Desirable from the current compilation
7689 -- to the named unit, so we keep the check enabled.
7691 if In_Extended_Main_Source_Unit (N) then
7692 Set_Suppress_Elaboration_Warnings
7693 (Entity (Name (Citem)));
7704 ("argument of pragma% is not with'ed unit", Arg);
7710 -- Give a warning if operating in static mode with -gnatwl
7711 -- (elaboration warnings enabled) switch set.
7713 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7715 ("?use of pragma Elaborate may not be safe", N);
7717 ("?use pragma Elaborate_All instead if possible", N);
7725 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7727 when Pragma_Elaborate_All => Elaborate_All : declare
7732 Check_Ada_83_Warning;
7734 -- Pragma must be in context items list of a compilation unit
7736 if not Is_In_Context_Clause then
7740 -- Must be at least one argument
7742 if Arg_Count = 0 then
7743 Error_Pragma ("pragma% requires at least one argument");
7746 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7747 -- have to appear at the end of the context clause, but may
7748 -- appear mixed in with other items, even in Ada 83 mode.
7750 -- Final check: the arguments must all be units mentioned in
7751 -- a with clause in the same context clause. Note that we
7752 -- already checked (in Par.Prag) that all the arguments are
7753 -- either identifiers or selected components.
7756 Outr : while Present (Arg) loop
7757 Citem := First (List_Containing (N));
7758 Innr : while Citem /= N loop
7759 if Nkind (Citem) = N_With_Clause
7760 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7762 Set_Elaborate_All_Present (Citem, True);
7763 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7765 -- Suppress warnings and elaboration checks on the named
7766 -- unit if the pragma is in the current compilation, as
7767 -- for pragma Elaborate.
7769 if In_Extended_Main_Source_Unit (N) then
7770 Set_Suppress_Elaboration_Warnings
7771 (Entity (Name (Citem)));
7780 Set_Error_Posted (N);
7782 ("argument of pragma% is not with'ed unit", Arg);
7789 --------------------
7790 -- Elaborate_Body --
7791 --------------------
7793 -- pragma Elaborate_Body [( library_unit_NAME )];
7795 when Pragma_Elaborate_Body => Elaborate_Body : declare
7796 Cunit_Node : Node_Id;
7797 Cunit_Ent : Entity_Id;
7800 Check_Ada_83_Warning;
7801 Check_Valid_Library_Unit_Pragma;
7803 if Nkind (N) = N_Null_Statement then
7807 Cunit_Node := Cunit (Current_Sem_Unit);
7808 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7810 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7813 Error_Pragma ("pragma% must refer to a spec, not a body");
7815 Set_Body_Required (Cunit_Node, True);
7816 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7818 -- If we are in dynamic elaboration mode, then we suppress
7819 -- elaboration warnings for the unit, since it is definitely
7820 -- fine NOT to do dynamic checks at the first level (and such
7821 -- checks will be suppressed because no elaboration boolean
7822 -- is created for Elaborate_Body packages).
7824 -- But in the static model of elaboration, Elaborate_Body is
7825 -- definitely NOT good enough to ensure elaboration safety on
7826 -- its own, since the body may WITH other units that are not
7827 -- safe from an elaboration point of view, so a client must
7828 -- still do an Elaborate_All on such units.
7830 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7831 -- Elaborate_Body always suppressed elab warnings.
7833 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7834 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7839 ------------------------
7840 -- Elaboration_Checks --
7841 ------------------------
7843 -- pragma Elaboration_Checks (Static | Dynamic);
7845 when Pragma_Elaboration_Checks =>
7847 Check_Arg_Count (1);
7848 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7849 Dynamic_Elaboration_Checks :=
7850 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7856 -- pragma Eliminate (
7857 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7858 -- [,[Entity =>] IDENTIFIER |
7859 -- SELECTED_COMPONENT |
7861 -- [, OVERLOADING_RESOLUTION]);
7863 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7866 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7869 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7871 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7872 -- Result_Type => result_SUBTYPE_NAME]
7874 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7875 -- SUBTYPE_NAME ::= STRING_LITERAL
7877 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7878 -- SOURCE_TRACE ::= STRING_LITERAL
7880 when Pragma_Eliminate => Eliminate : declare
7881 Args : Args_List (1 .. 5);
7882 Names : constant Name_List (1 .. 5) := (
7885 Name_Parameter_Types,
7887 Name_Source_Location);
7889 Unit_Name : Node_Id renames Args (1);
7890 Entity : Node_Id renames Args (2);
7891 Parameter_Types : Node_Id renames Args (3);
7892 Result_Type : Node_Id renames Args (4);
7893 Source_Location : Node_Id renames Args (5);
7897 Check_Valid_Configuration_Pragma;
7898 Gather_Associations (Names, Args);
7900 if No (Unit_Name) then
7901 Error_Pragma ("missing Unit_Name argument for pragma%");
7905 and then (Present (Parameter_Types)
7907 Present (Result_Type)
7909 Present (Source_Location))
7911 Error_Pragma ("missing Entity argument for pragma%");
7914 if (Present (Parameter_Types)
7916 Present (Result_Type))
7918 Present (Source_Location)
7921 ("parameter profile and source location cannot " &
7922 "be used together in pragma%");
7925 Process_Eliminate_Pragma
7939 -- [ Convention =>] convention_IDENTIFIER,
7940 -- [ Entity =>] local_NAME
7941 -- [, [External_Name =>] static_string_EXPRESSION ]
7942 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7944 when Pragma_Export => Export : declare
7948 pragma Warnings (Off, C);
7951 Check_Ada_83_Warning;
7957 Check_At_Least_N_Arguments (2);
7958 Check_At_Most_N_Arguments (4);
7959 Process_Convention (C, Def_Id);
7961 if Ekind (Def_Id) /= E_Constant then
7962 Note_Possible_Modification
7963 (Get_Pragma_Arg (Arg2), Sure => False);
7966 Process_Interface_Name (Def_Id, Arg3, Arg4);
7967 Set_Exported (Def_Id, Arg2);
7969 -- If the entity is a deferred constant, propagate the information
7970 -- to the full view, because gigi elaborates the full view only.
7972 if Ekind (Def_Id) = E_Constant
7973 and then Present (Full_View (Def_Id))
7976 Id2 : constant Entity_Id := Full_View (Def_Id);
7978 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7979 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7980 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7985 ----------------------
7986 -- Export_Exception --
7987 ----------------------
7989 -- pragma Export_Exception (
7990 -- [Internal =>] LOCAL_NAME
7991 -- [, [External =>] EXTERNAL_SYMBOL]
7992 -- [, [Form =>] Ada | VMS]
7993 -- [, [Code =>] static_integer_EXPRESSION]);
7995 when Pragma_Export_Exception => Export_Exception : declare
7996 Args : Args_List (1 .. 4);
7997 Names : constant Name_List (1 .. 4) := (
8003 Internal : Node_Id renames Args (1);
8004 External : Node_Id renames Args (2);
8005 Form : Node_Id renames Args (3);
8006 Code : Node_Id renames Args (4);
8011 if Inside_A_Generic then
8012 Error_Pragma ("pragma% cannot be used for generic entities");
8015 Gather_Associations (Names, Args);
8016 Process_Extended_Import_Export_Exception_Pragma (
8017 Arg_Internal => Internal,
8018 Arg_External => External,
8022 if not Is_VMS_Exception (Entity (Internal)) then
8023 Set_Exported (Entity (Internal), Internal);
8025 end Export_Exception;
8027 ---------------------
8028 -- Export_Function --
8029 ---------------------
8031 -- pragma Export_Function (
8032 -- [Internal =>] LOCAL_NAME
8033 -- [, [External =>] EXTERNAL_SYMBOL]
8034 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8035 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8036 -- [, [Mechanism =>] MECHANISM]
8037 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8039 -- EXTERNAL_SYMBOL ::=
8041 -- | static_string_EXPRESSION
8043 -- PARAMETER_TYPES ::=
8045 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8047 -- TYPE_DESIGNATOR ::=
8049 -- | subtype_Name ' Access
8053 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8055 -- MECHANISM_ASSOCIATION ::=
8056 -- [formal_parameter_NAME =>] MECHANISM_NAME
8058 -- MECHANISM_NAME ::=
8061 -- | Descriptor [([Class =>] CLASS_NAME)]
8063 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8065 when Pragma_Export_Function => Export_Function : declare
8066 Args : Args_List (1 .. 6);
8067 Names : constant Name_List (1 .. 6) := (
8070 Name_Parameter_Types,
8073 Name_Result_Mechanism);
8075 Internal : Node_Id renames Args (1);
8076 External : Node_Id renames Args (2);
8077 Parameter_Types : Node_Id renames Args (3);
8078 Result_Type : Node_Id renames Args (4);
8079 Mechanism : Node_Id renames Args (5);
8080 Result_Mechanism : Node_Id renames Args (6);
8084 Gather_Associations (Names, Args);
8085 Process_Extended_Import_Export_Subprogram_Pragma (
8086 Arg_Internal => Internal,
8087 Arg_External => External,
8088 Arg_Parameter_Types => Parameter_Types,
8089 Arg_Result_Type => Result_Type,
8090 Arg_Mechanism => Mechanism,
8091 Arg_Result_Mechanism => Result_Mechanism);
8092 end Export_Function;
8098 -- pragma Export_Object (
8099 -- [Internal =>] LOCAL_NAME
8100 -- [, [External =>] EXTERNAL_SYMBOL]
8101 -- [, [Size =>] EXTERNAL_SYMBOL]);
8103 -- EXTERNAL_SYMBOL ::=
8105 -- | static_string_EXPRESSION
8107 -- PARAMETER_TYPES ::=
8109 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8111 -- TYPE_DESIGNATOR ::=
8113 -- | subtype_Name ' Access
8117 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8119 -- MECHANISM_ASSOCIATION ::=
8120 -- [formal_parameter_NAME =>] MECHANISM_NAME
8122 -- MECHANISM_NAME ::=
8125 -- | Descriptor [([Class =>] CLASS_NAME)]
8127 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8129 when Pragma_Export_Object => Export_Object : declare
8130 Args : Args_List (1 .. 3);
8131 Names : constant Name_List (1 .. 3) := (
8136 Internal : Node_Id renames Args (1);
8137 External : Node_Id renames Args (2);
8138 Size : Node_Id renames Args (3);
8142 Gather_Associations (Names, Args);
8143 Process_Extended_Import_Export_Object_Pragma (
8144 Arg_Internal => Internal,
8145 Arg_External => External,
8149 ----------------------
8150 -- Export_Procedure --
8151 ----------------------
8153 -- pragma Export_Procedure (
8154 -- [Internal =>] LOCAL_NAME
8155 -- [, [External =>] EXTERNAL_SYMBOL]
8156 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8157 -- [, [Mechanism =>] MECHANISM]);
8159 -- EXTERNAL_SYMBOL ::=
8161 -- | static_string_EXPRESSION
8163 -- PARAMETER_TYPES ::=
8165 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8167 -- TYPE_DESIGNATOR ::=
8169 -- | subtype_Name ' Access
8173 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8175 -- MECHANISM_ASSOCIATION ::=
8176 -- [formal_parameter_NAME =>] MECHANISM_NAME
8178 -- MECHANISM_NAME ::=
8181 -- | Descriptor [([Class =>] CLASS_NAME)]
8183 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8185 when Pragma_Export_Procedure => Export_Procedure : declare
8186 Args : Args_List (1 .. 4);
8187 Names : constant Name_List (1 .. 4) := (
8190 Name_Parameter_Types,
8193 Internal : Node_Id renames Args (1);
8194 External : Node_Id renames Args (2);
8195 Parameter_Types : Node_Id renames Args (3);
8196 Mechanism : Node_Id renames Args (4);
8200 Gather_Associations (Names, Args);
8201 Process_Extended_Import_Export_Subprogram_Pragma (
8202 Arg_Internal => Internal,
8203 Arg_External => External,
8204 Arg_Parameter_Types => Parameter_Types,
8205 Arg_Mechanism => Mechanism);
8206 end Export_Procedure;
8212 -- pragma Export_Value (
8213 -- [Value =>] static_integer_EXPRESSION,
8214 -- [Link_Name =>] static_string_EXPRESSION);
8216 when Pragma_Export_Value =>
8218 Check_Arg_Order ((Name_Value, Name_Link_Name));
8219 Check_Arg_Count (2);
8221 Check_Optional_Identifier (Arg1, Name_Value);
8222 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8224 Check_Optional_Identifier (Arg2, Name_Link_Name);
8225 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8227 -----------------------------
8228 -- Export_Valued_Procedure --
8229 -----------------------------
8231 -- pragma Export_Valued_Procedure (
8232 -- [Internal =>] LOCAL_NAME
8233 -- [, [External =>] EXTERNAL_SYMBOL,]
8234 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8235 -- [, [Mechanism =>] MECHANISM]);
8237 -- EXTERNAL_SYMBOL ::=
8239 -- | static_string_EXPRESSION
8241 -- PARAMETER_TYPES ::=
8243 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8245 -- TYPE_DESIGNATOR ::=
8247 -- | subtype_Name ' Access
8251 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8253 -- MECHANISM_ASSOCIATION ::=
8254 -- [formal_parameter_NAME =>] MECHANISM_NAME
8256 -- MECHANISM_NAME ::=
8259 -- | Descriptor [([Class =>] CLASS_NAME)]
8261 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8263 when Pragma_Export_Valued_Procedure =>
8264 Export_Valued_Procedure : declare
8265 Args : Args_List (1 .. 4);
8266 Names : constant Name_List (1 .. 4) := (
8269 Name_Parameter_Types,
8272 Internal : Node_Id renames Args (1);
8273 External : Node_Id renames Args (2);
8274 Parameter_Types : Node_Id renames Args (3);
8275 Mechanism : Node_Id renames Args (4);
8279 Gather_Associations (Names, Args);
8280 Process_Extended_Import_Export_Subprogram_Pragma (
8281 Arg_Internal => Internal,
8282 Arg_External => External,
8283 Arg_Parameter_Types => Parameter_Types,
8284 Arg_Mechanism => Mechanism);
8285 end Export_Valued_Procedure;
8291 -- pragma Extend_System ([Name =>] Identifier);
8293 when Pragma_Extend_System => Extend_System : declare
8296 Check_Valid_Configuration_Pragma;
8297 Check_Arg_Count (1);
8298 Check_Optional_Identifier (Arg1, Name_Name);
8299 Check_Arg_Is_Identifier (Arg1);
8301 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8304 and then Name_Buffer (1 .. 4) = "aux_"
8306 if Present (System_Extend_Pragma_Arg) then
8307 if Chars (Get_Pragma_Arg (Arg1)) =
8308 Chars (Expression (System_Extend_Pragma_Arg))
8312 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8313 Error_Pragma ("pragma% conflicts with that #");
8317 System_Extend_Pragma_Arg := Arg1;
8319 if not GNAT_Mode then
8320 System_Extend_Unit := Arg1;
8324 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8328 ------------------------
8329 -- Extensions_Allowed --
8330 ------------------------
8332 -- pragma Extensions_Allowed (ON | OFF);
8334 when Pragma_Extensions_Allowed =>
8336 Check_Arg_Count (1);
8337 Check_No_Identifiers;
8338 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8340 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8341 Extensions_Allowed := True;
8342 Ada_Version := Ada_Version_Type'Last;
8345 Extensions_Allowed := False;
8346 Ada_Version := Ada_Version_Explicit;
8353 -- pragma External (
8354 -- [ Convention =>] convention_IDENTIFIER,
8355 -- [ Entity =>] local_NAME
8356 -- [, [External_Name =>] static_string_EXPRESSION ]
8357 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8359 when Pragma_External => External : declare
8363 pragma Warnings (Off, C);
8372 Check_At_Least_N_Arguments (2);
8373 Check_At_Most_N_Arguments (4);
8374 Process_Convention (C, Def_Id);
8375 Note_Possible_Modification
8376 (Get_Pragma_Arg (Arg2), Sure => False);
8377 Process_Interface_Name (Def_Id, Arg3, Arg4);
8378 Set_Exported (Def_Id, Arg2);
8381 --------------------------
8382 -- External_Name_Casing --
8383 --------------------------
8385 -- pragma External_Name_Casing (
8386 -- UPPERCASE | LOWERCASE
8387 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8389 when Pragma_External_Name_Casing => External_Name_Casing : declare
8392 Check_No_Identifiers;
8394 if Arg_Count = 2 then
8396 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8398 case Chars (Get_Pragma_Arg (Arg2)) is
8400 Opt.External_Name_Exp_Casing := As_Is;
8402 when Name_Uppercase =>
8403 Opt.External_Name_Exp_Casing := Uppercase;
8405 when Name_Lowercase =>
8406 Opt.External_Name_Exp_Casing := Lowercase;
8413 Check_Arg_Count (1);
8416 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8418 case Chars (Get_Pragma_Arg (Arg1)) is
8419 when Name_Uppercase =>
8420 Opt.External_Name_Imp_Casing := Uppercase;
8422 when Name_Lowercase =>
8423 Opt.External_Name_Imp_Casing := Lowercase;
8428 end External_Name_Casing;
8430 --------------------------
8431 -- Favor_Top_Level --
8432 --------------------------
8434 -- pragma Favor_Top_Level (type_NAME);
8436 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8437 Named_Entity : Entity_Id;
8441 Check_No_Identifiers;
8442 Check_Arg_Count (1);
8443 Check_Arg_Is_Local_Name (Arg1);
8444 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8446 -- If it's an access-to-subprogram type (in particular, not a
8447 -- subtype), set the flag on that type.
8449 if Is_Access_Subprogram_Type (Named_Entity) then
8450 Set_Can_Use_Internal_Rep (Named_Entity, False);
8452 -- Otherwise it's an error (name denotes the wrong sort of entity)
8456 ("access-to-subprogram type expected",
8457 Get_Pragma_Arg (Arg1));
8459 end Favor_Top_Level;
8465 -- pragma Fast_Math;
8467 when Pragma_Fast_Math =>
8469 Check_No_Identifiers;
8470 Check_Valid_Configuration_Pragma;
8473 ---------------------------
8474 -- Finalize_Storage_Only --
8475 ---------------------------
8477 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8479 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8480 Assoc : constant Node_Id := Arg1;
8481 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8486 Check_No_Identifiers;
8487 Check_Arg_Count (1);
8488 Check_Arg_Is_Local_Name (Arg1);
8490 Find_Type (Type_Id);
8491 Typ := Entity (Type_Id);
8494 or else Rep_Item_Too_Early (Typ, N)
8498 Typ := Underlying_Type (Typ);
8501 if not Is_Controlled (Typ) then
8502 Error_Pragma ("pragma% must specify controlled type");
8505 Check_First_Subtype (Arg1);
8507 if Finalize_Storage_Only (Typ) then
8508 Error_Pragma ("duplicate pragma%, only one allowed");
8510 elsif not Rep_Item_Too_Late (Typ, N) then
8511 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8513 end Finalize_Storage;
8515 --------------------------
8516 -- Float_Representation --
8517 --------------------------
8519 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8521 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8523 when Pragma_Float_Representation => Float_Representation : declare
8531 if Arg_Count = 1 then
8532 Check_Valid_Configuration_Pragma;
8534 Check_Arg_Count (2);
8535 Check_Optional_Identifier (Arg2, Name_Entity);
8536 Check_Arg_Is_Local_Name (Arg2);
8539 Check_No_Identifier (Arg1);
8540 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8542 if not OpenVMS_On_Target then
8543 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8545 ("?pragma% ignored (applies only to Open'V'M'S)");
8551 -- One argument case
8553 if Arg_Count = 1 then
8554 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8555 if Opt.Float_Format = 'I' then
8556 Error_Pragma ("'I'E'E'E format previously specified");
8559 Opt.Float_Format := 'V';
8562 if Opt.Float_Format = 'V' then
8563 Error_Pragma ("'V'A'X format previously specified");
8566 Opt.Float_Format := 'I';
8569 Set_Standard_Fpt_Formats;
8571 -- Two argument case
8574 Argx := Get_Pragma_Arg (Arg2);
8576 if not Is_Entity_Name (Argx)
8577 or else not Is_Floating_Point_Type (Entity (Argx))
8580 ("second argument of% pragma must be floating-point type",
8584 Ent := Entity (Argx);
8585 Digs := UI_To_Int (Digits_Value (Ent));
8587 -- Two arguments, VAX_Float case
8589 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8591 when 6 => Set_F_Float (Ent);
8592 when 9 => Set_D_Float (Ent);
8593 when 15 => Set_G_Float (Ent);
8597 ("wrong digits value, must be 6,9 or 15", Arg2);
8600 -- Two arguments, IEEE_Float case
8604 when 6 => Set_IEEE_Short (Ent);
8605 when 15 => Set_IEEE_Long (Ent);
8609 ("wrong digits value, must be 6 or 15", Arg2);
8613 end Float_Representation;
8619 -- pragma Ident (static_string_EXPRESSION)
8621 -- Note: pragma Comment shares this processing. Pragma Comment is
8622 -- identical to Ident, except that the restriction of the argument to
8623 -- 31 characters and the placement restrictions are not enforced for
8626 when Pragma_Ident | Pragma_Comment => Ident : declare
8631 Check_Arg_Count (1);
8632 Check_No_Identifiers;
8633 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8636 -- For pragma Ident, preserve DEC compatibility by requiring the
8637 -- pragma to appear in a declarative part or package spec.
8639 if Prag_Id = Pragma_Ident then
8640 Check_Is_In_Decl_Part_Or_Package_Spec;
8643 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8650 GP := Parent (Parent (N));
8652 if Nkind_In (GP, N_Package_Declaration,
8653 N_Generic_Package_Declaration)
8658 -- If we have a compilation unit, then record the ident value,
8659 -- checking for improper duplication.
8661 if Nkind (GP) = N_Compilation_Unit then
8662 CS := Ident_String (Current_Sem_Unit);
8664 if Present (CS) then
8666 -- For Ident, we do not permit multiple instances
8668 if Prag_Id = Pragma_Ident then
8669 Error_Pragma ("duplicate% pragma not permitted");
8671 -- For Comment, we concatenate the string, unless we want
8672 -- to preserve the tree structure for ASIS.
8674 elsif not ASIS_Mode then
8675 Start_String (Strval (CS));
8676 Store_String_Char (' ');
8677 Store_String_Chars (Strval (Str));
8678 Set_Strval (CS, End_String);
8682 -- In VMS, the effect of IDENT is achieved by passing
8683 -- --identification=name as a --for-linker switch.
8685 if OpenVMS_On_Target then
8688 ("--for-linker=--identification=");
8689 String_To_Name_Buffer (Strval (Str));
8690 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8692 -- Only the last processed IDENT is saved. The main
8693 -- purpose is so an IDENT associated with a main
8694 -- procedure will be used in preference to an IDENT
8695 -- associated with a with'd package.
8697 Replace_Linker_Option_String
8698 (End_String, "--for-linker=--identification=");
8701 Set_Ident_String (Current_Sem_Unit, Str);
8704 -- For subunits, we just ignore the Ident, since in GNAT these
8705 -- are not separate object files, and hence not separate units
8706 -- in the unit table.
8708 elsif Nkind (GP) = N_Subunit then
8711 -- Otherwise we have a misplaced pragma Ident, but we ignore
8712 -- this if we are in an instantiation, since it comes from
8713 -- a generic, and has no relevance to the instantiation.
8715 elsif Prag_Id = Pragma_Ident then
8716 if Instantiation_Location (Loc) = No_Location then
8717 Error_Pragma ("pragma% only allowed at outer level");
8727 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8728 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8730 when Pragma_Implemented => Implemented : declare
8731 Proc_Id : Entity_Id;
8736 Check_Arg_Count (2);
8737 Check_No_Identifiers;
8738 Check_Arg_Is_Identifier (Arg1);
8739 Check_Arg_Is_Local_Name (Arg1);
8741 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8743 -- Extract the name of the local procedure
8745 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8747 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8748 -- primitive procedure of a synchronized tagged type.
8750 if Ekind (Proc_Id) = E_Procedure
8751 and then Is_Primitive (Proc_Id)
8752 and then Present (First_Formal (Proc_Id))
8754 Typ := Etype (First_Formal (Proc_Id));
8756 if Is_Tagged_Type (Typ)
8759 -- Check for a protected, a synchronized or a task interface
8761 ((Is_Interface (Typ)
8762 and then Is_Synchronized_Interface (Typ))
8764 -- Check for a protected type or a task type that implements
8768 (Is_Concurrent_Record_Type (Typ)
8769 and then Present (Interfaces (Typ)))
8771 -- Check for a private record extension with keyword
8775 (Ekind_In (Typ, E_Record_Type_With_Private,
8776 E_Record_Subtype_With_Private)
8777 and then Synchronized_Present (Parent (Typ))))
8782 ("controlling formal must be of synchronized " &
8783 "tagged type", Arg1);
8787 -- Procedures declared inside a protected type must be accepted
8789 elsif Ekind (Proc_Id) = E_Procedure
8790 and then Is_Protected_Type (Scope (Proc_Id))
8794 -- The first argument is not a primitive procedure
8798 ("pragma % must be applied to a primitive procedure", Arg1);
8802 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8803 -- By_Protected_Procedure to the primitive procedure of a task
8806 if Chars (Arg2) = Name_By_Protected_Procedure
8807 and then Is_Interface (Typ)
8808 and then Is_Task_Interface (Typ)
8811 ("implementation kind By_Protected_Procedure cannot be " &
8812 "applied to a task interface primitive", Arg2);
8816 Record_Rep_Item (Proc_Id, N);
8819 ----------------------
8820 -- Implicit_Packing --
8821 ----------------------
8823 -- pragma Implicit_Packing;
8825 when Pragma_Implicit_Packing =>
8827 Check_Arg_Count (0);
8828 Implicit_Packing := True;
8835 -- [Convention =>] convention_IDENTIFIER,
8836 -- [Entity =>] local_NAME
8837 -- [, [External_Name =>] static_string_EXPRESSION ]
8838 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8840 when Pragma_Import =>
8841 Check_Ada_83_Warning;
8847 Check_At_Least_N_Arguments (2);
8848 Check_At_Most_N_Arguments (4);
8849 Process_Import_Or_Interface;
8851 ----------------------
8852 -- Import_Exception --
8853 ----------------------
8855 -- pragma Import_Exception (
8856 -- [Internal =>] LOCAL_NAME
8857 -- [, [External =>] EXTERNAL_SYMBOL]
8858 -- [, [Form =>] Ada | VMS]
8859 -- [, [Code =>] static_integer_EXPRESSION]);
8861 when Pragma_Import_Exception => Import_Exception : declare
8862 Args : Args_List (1 .. 4);
8863 Names : constant Name_List (1 .. 4) := (
8869 Internal : Node_Id renames Args (1);
8870 External : Node_Id renames Args (2);
8871 Form : Node_Id renames Args (3);
8872 Code : Node_Id renames Args (4);
8876 Gather_Associations (Names, Args);
8878 if Present (External) and then Present (Code) then
8880 ("cannot give both External and Code options for pragma%");
8883 Process_Extended_Import_Export_Exception_Pragma (
8884 Arg_Internal => Internal,
8885 Arg_External => External,
8889 if not Is_VMS_Exception (Entity (Internal)) then
8890 Set_Imported (Entity (Internal));
8892 end Import_Exception;
8894 ---------------------
8895 -- Import_Function --
8896 ---------------------
8898 -- pragma Import_Function (
8899 -- [Internal =>] LOCAL_NAME,
8900 -- [, [External =>] EXTERNAL_SYMBOL]
8901 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8902 -- [, [Result_Type =>] SUBTYPE_MARK]
8903 -- [, [Mechanism =>] MECHANISM]
8904 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8905 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8907 -- EXTERNAL_SYMBOL ::=
8909 -- | static_string_EXPRESSION
8911 -- PARAMETER_TYPES ::=
8913 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8915 -- TYPE_DESIGNATOR ::=
8917 -- | subtype_Name ' Access
8921 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8923 -- MECHANISM_ASSOCIATION ::=
8924 -- [formal_parameter_NAME =>] MECHANISM_NAME
8926 -- MECHANISM_NAME ::=
8929 -- | Descriptor [([Class =>] CLASS_NAME)]
8931 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8933 when Pragma_Import_Function => Import_Function : declare
8934 Args : Args_List (1 .. 7);
8935 Names : constant Name_List (1 .. 7) := (
8938 Name_Parameter_Types,
8941 Name_Result_Mechanism,
8942 Name_First_Optional_Parameter);
8944 Internal : Node_Id renames Args (1);
8945 External : Node_Id renames Args (2);
8946 Parameter_Types : Node_Id renames Args (3);
8947 Result_Type : Node_Id renames Args (4);
8948 Mechanism : Node_Id renames Args (5);
8949 Result_Mechanism : Node_Id renames Args (6);
8950 First_Optional_Parameter : Node_Id renames Args (7);
8954 Gather_Associations (Names, Args);
8955 Process_Extended_Import_Export_Subprogram_Pragma (
8956 Arg_Internal => Internal,
8957 Arg_External => External,
8958 Arg_Parameter_Types => Parameter_Types,
8959 Arg_Result_Type => Result_Type,
8960 Arg_Mechanism => Mechanism,
8961 Arg_Result_Mechanism => Result_Mechanism,
8962 Arg_First_Optional_Parameter => First_Optional_Parameter);
8963 end Import_Function;
8969 -- pragma Import_Object (
8970 -- [Internal =>] LOCAL_NAME
8971 -- [, [External =>] EXTERNAL_SYMBOL]
8972 -- [, [Size =>] EXTERNAL_SYMBOL]);
8974 -- EXTERNAL_SYMBOL ::=
8976 -- | static_string_EXPRESSION
8978 when Pragma_Import_Object => Import_Object : declare
8979 Args : Args_List (1 .. 3);
8980 Names : constant Name_List (1 .. 3) := (
8985 Internal : Node_Id renames Args (1);
8986 External : Node_Id renames Args (2);
8987 Size : Node_Id renames Args (3);
8991 Gather_Associations (Names, Args);
8992 Process_Extended_Import_Export_Object_Pragma (
8993 Arg_Internal => Internal,
8994 Arg_External => External,
8998 ----------------------
8999 -- Import_Procedure --
9000 ----------------------
9002 -- pragma Import_Procedure (
9003 -- [Internal =>] LOCAL_NAME
9004 -- [, [External =>] EXTERNAL_SYMBOL]
9005 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9006 -- [, [Mechanism =>] MECHANISM]
9007 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9009 -- EXTERNAL_SYMBOL ::=
9011 -- | static_string_EXPRESSION
9013 -- PARAMETER_TYPES ::=
9015 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9017 -- TYPE_DESIGNATOR ::=
9019 -- | subtype_Name ' Access
9023 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9025 -- MECHANISM_ASSOCIATION ::=
9026 -- [formal_parameter_NAME =>] MECHANISM_NAME
9028 -- MECHANISM_NAME ::=
9031 -- | Descriptor [([Class =>] CLASS_NAME)]
9033 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9035 when Pragma_Import_Procedure => Import_Procedure : declare
9036 Args : Args_List (1 .. 5);
9037 Names : constant Name_List (1 .. 5) := (
9040 Name_Parameter_Types,
9042 Name_First_Optional_Parameter);
9044 Internal : Node_Id renames Args (1);
9045 External : Node_Id renames Args (2);
9046 Parameter_Types : Node_Id renames Args (3);
9047 Mechanism : Node_Id renames Args (4);
9048 First_Optional_Parameter : Node_Id renames Args (5);
9052 Gather_Associations (Names, Args);
9053 Process_Extended_Import_Export_Subprogram_Pragma (
9054 Arg_Internal => Internal,
9055 Arg_External => External,
9056 Arg_Parameter_Types => Parameter_Types,
9057 Arg_Mechanism => Mechanism,
9058 Arg_First_Optional_Parameter => First_Optional_Parameter);
9059 end Import_Procedure;
9061 -----------------------------
9062 -- Import_Valued_Procedure --
9063 -----------------------------
9065 -- pragma Import_Valued_Procedure (
9066 -- [Internal =>] LOCAL_NAME
9067 -- [, [External =>] EXTERNAL_SYMBOL]
9068 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9069 -- [, [Mechanism =>] MECHANISM]
9070 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9072 -- EXTERNAL_SYMBOL ::=
9074 -- | static_string_EXPRESSION
9076 -- PARAMETER_TYPES ::=
9078 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9080 -- TYPE_DESIGNATOR ::=
9082 -- | subtype_Name ' Access
9086 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9088 -- MECHANISM_ASSOCIATION ::=
9089 -- [formal_parameter_NAME =>] MECHANISM_NAME
9091 -- MECHANISM_NAME ::=
9094 -- | Descriptor [([Class =>] CLASS_NAME)]
9096 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9098 when Pragma_Import_Valued_Procedure =>
9099 Import_Valued_Procedure : declare
9100 Args : Args_List (1 .. 5);
9101 Names : constant Name_List (1 .. 5) := (
9104 Name_Parameter_Types,
9106 Name_First_Optional_Parameter);
9108 Internal : Node_Id renames Args (1);
9109 External : Node_Id renames Args (2);
9110 Parameter_Types : Node_Id renames Args (3);
9111 Mechanism : Node_Id renames Args (4);
9112 First_Optional_Parameter : Node_Id renames Args (5);
9116 Gather_Associations (Names, Args);
9117 Process_Extended_Import_Export_Subprogram_Pragma (
9118 Arg_Internal => Internal,
9119 Arg_External => External,
9120 Arg_Parameter_Types => Parameter_Types,
9121 Arg_Mechanism => Mechanism,
9122 Arg_First_Optional_Parameter => First_Optional_Parameter);
9123 end Import_Valued_Procedure;
9129 -- pragma Independent (LOCAL_NAME);
9131 when Pragma_Independent => Independent : declare
9138 Check_Ada_83_Warning;
9140 Check_No_Identifiers;
9141 Check_Arg_Count (1);
9142 Check_Arg_Is_Local_Name (Arg1);
9143 E_Id := Get_Pragma_Arg (Arg1);
9145 if Etype (E_Id) = Any_Type then
9150 D := Declaration_Node (E);
9153 -- Check duplicate before we chain ourselves!
9155 Check_Duplicate_Pragma (E);
9157 -- Check appropriate entity
9160 if Rep_Item_Too_Early (E, N)
9162 Rep_Item_Too_Late (E, N)
9166 Check_First_Subtype (Arg1);
9169 elsif K = N_Object_Declaration
9170 or else (K = N_Component_Declaration
9171 and then Original_Record_Component (E) = E)
9173 if Rep_Item_Too_Late (E, N) then
9179 ("inappropriate entity for pragma%", Arg1);
9182 Independence_Checks.Append ((N, E));
9185 ----------------------------
9186 -- Independent_Components --
9187 ----------------------------
9189 -- pragma Atomic_Components (array_LOCAL_NAME);
9191 -- This processing is shared by Volatile_Components
9193 when Pragma_Independent_Components => Independent_Components : declare
9200 Check_Ada_83_Warning;
9202 Check_No_Identifiers;
9203 Check_Arg_Count (1);
9204 Check_Arg_Is_Local_Name (Arg1);
9205 E_Id := Get_Pragma_Arg (Arg1);
9207 if Etype (E_Id) = Any_Type then
9213 -- Check duplicate before we chain ourselves!
9215 Check_Duplicate_Pragma (E);
9217 -- Check appropriate entity
9219 if Rep_Item_Too_Early (E, N)
9221 Rep_Item_Too_Late (E, N)
9226 D := Declaration_Node (E);
9229 if (K = N_Full_Type_Declaration
9230 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9232 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9233 and then Nkind (D) = N_Object_Declaration
9234 and then Nkind (Object_Definition (D)) =
9235 N_Constrained_Array_Definition)
9237 Independence_Checks.Append ((N, E));
9240 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9242 end Independent_Components;
9244 ------------------------
9245 -- Initialize_Scalars --
9246 ------------------------
9248 -- pragma Initialize_Scalars;
9250 when Pragma_Initialize_Scalars =>
9252 Check_Arg_Count (0);
9253 Check_Valid_Configuration_Pragma;
9254 Check_Restriction (No_Initialize_Scalars, N);
9256 -- Initialize_Scalars creates false positives in CodePeer,
9257 -- so ignore this pragma in this mode.
9259 if not Restriction_Active (No_Initialize_Scalars)
9260 and then not CodePeer_Mode
9262 Init_Or_Norm_Scalars := True;
9263 Initialize_Scalars := True;
9270 -- pragma Inline ( NAME {, NAME} );
9272 when Pragma_Inline =>
9274 -- Pragma is active if inlining option is active
9276 Process_Inline (Inline_Active);
9282 -- pragma Inline_Always ( NAME {, NAME} );
9284 when Pragma_Inline_Always =>
9287 -- Pragma always active unless in CodePeer mode, since this causes
9288 -- walk order issues.
9290 if not CodePeer_Mode then
9291 Process_Inline (True);
9294 --------------------
9295 -- Inline_Generic --
9296 --------------------
9298 -- pragma Inline_Generic (NAME {, NAME});
9300 when Pragma_Inline_Generic =>
9302 Process_Generic_List;
9304 ----------------------
9305 -- Inspection_Point --
9306 ----------------------
9308 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9310 when Pragma_Inspection_Point => Inspection_Point : declare
9315 if Arg_Count > 0 then
9318 Exp := Get_Pragma_Arg (Arg);
9321 if not Is_Entity_Name (Exp)
9322 or else not Is_Object (Entity (Exp))
9324 Error_Pragma_Arg ("object name required", Arg);
9331 end Inspection_Point;
9337 -- pragma Interface (
9338 -- [ Convention =>] convention_IDENTIFIER,
9339 -- [ Entity =>] local_NAME
9340 -- [, [External_Name =>] static_string_EXPRESSION ]
9341 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9343 when Pragma_Interface =>
9350 Check_At_Least_N_Arguments (2);
9351 Check_At_Most_N_Arguments (4);
9352 Process_Import_Or_Interface;
9354 -- In Ada 2005, the permission to use Interface (a reserved word)
9355 -- as a pragma name is considered an obsolescent feature.
9357 if Ada_Version >= Ada_2005 then
9359 (No_Obsolescent_Features, Pragma_Identifier (N));
9362 --------------------
9363 -- Interface_Name --
9364 --------------------
9366 -- pragma Interface_Name (
9367 -- [ Entity =>] local_NAME
9368 -- [,[External_Name =>] static_string_EXPRESSION ]
9369 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9371 when Pragma_Interface_Name => Interface_Name : declare
9380 ((Name_Entity, Name_External_Name, Name_Link_Name));
9381 Check_At_Least_N_Arguments (2);
9382 Check_At_Most_N_Arguments (3);
9383 Id := Get_Pragma_Arg (Arg1);
9386 if not Is_Entity_Name (Id) then
9388 ("first argument for pragma% must be entity name", Arg1);
9389 elsif Etype (Id) = Any_Type then
9392 Def_Id := Entity (Id);
9395 -- Special DEC-compatible processing for the object case, forces
9396 -- object to be imported.
9398 if Ekind (Def_Id) = E_Variable then
9399 Kill_Size_Check_Code (Def_Id);
9400 Note_Possible_Modification (Id, Sure => False);
9402 -- Initialization is not allowed for imported variable
9404 if Present (Expression (Parent (Def_Id)))
9405 and then Comes_From_Source (Expression (Parent (Def_Id)))
9407 Error_Msg_Sloc := Sloc (Def_Id);
9409 ("no initialization allowed for declaration of& #",
9413 -- For compatibility, support VADS usage of providing both
9414 -- pragmas Interface and Interface_Name to obtain the effect
9415 -- of a single Import pragma.
9417 if Is_Imported (Def_Id)
9418 and then Present (First_Rep_Item (Def_Id))
9419 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9421 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9425 Set_Imported (Def_Id);
9428 Set_Is_Public (Def_Id);
9429 Process_Interface_Name (Def_Id, Arg2, Arg3);
9432 -- Otherwise must be subprogram
9434 elsif not Is_Subprogram (Def_Id) then
9436 ("argument of pragma% is not subprogram", Arg1);
9439 Check_At_Most_N_Arguments (3);
9443 -- Loop through homonyms
9446 Def_Id := Get_Base_Subprogram (Hom_Id);
9448 if Is_Imported (Def_Id) then
9449 Process_Interface_Name (Def_Id, Arg2, Arg3);
9453 exit when From_Aspect_Specification (N);
9454 Hom_Id := Homonym (Hom_Id);
9456 exit when No (Hom_Id)
9457 or else Scope (Hom_Id) /= Current_Scope;
9462 ("argument of pragma% is not imported subprogram",
9468 -----------------------
9469 -- Interrupt_Handler --
9470 -----------------------
9472 -- pragma Interrupt_Handler (handler_NAME);
9474 when Pragma_Interrupt_Handler =>
9475 Check_Ada_83_Warning;
9476 Check_Arg_Count (1);
9477 Check_No_Identifiers;
9479 if No_Run_Time_Mode then
9480 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9482 Check_Interrupt_Or_Attach_Handler;
9483 Process_Interrupt_Or_Attach_Handler;
9486 ------------------------
9487 -- Interrupt_Priority --
9488 ------------------------
9490 -- pragma Interrupt_Priority [(EXPRESSION)];
9492 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9493 P : constant Node_Id := Parent (N);
9497 Check_Ada_83_Warning;
9499 if Arg_Count /= 0 then
9500 Arg := Get_Pragma_Arg (Arg1);
9501 Check_Arg_Count (1);
9502 Check_No_Identifiers;
9504 -- The expression must be analyzed in the special manner
9505 -- described in "Handling of Default and Per-Object
9506 -- Expressions" in sem.ads.
9508 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9511 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9515 elsif Has_Pragma_Priority (P) then
9516 Error_Pragma ("duplicate pragma% not allowed");
9519 Set_Has_Pragma_Priority (P, True);
9520 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9522 end Interrupt_Priority;
9524 ---------------------
9525 -- Interrupt_State --
9526 ---------------------
9528 -- pragma Interrupt_State (
9529 -- [Name =>] INTERRUPT_ID,
9530 -- [State =>] INTERRUPT_STATE);
9532 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9533 -- INTERRUPT_STATE => System | Runtime | User
9535 -- Note: if the interrupt id is given as an identifier, then it must
9536 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9537 -- given as a static integer expression which must be in the range of
9538 -- Ada.Interrupts.Interrupt_ID.
9540 when Pragma_Interrupt_State => Interrupt_State : declare
9542 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9543 -- This is the entity Ada.Interrupts.Interrupt_ID;
9545 State_Type : Character;
9546 -- Set to 's'/'r'/'u' for System/Runtime/User
9549 -- Index to entry in Interrupt_States table
9552 -- Value of interrupt
9554 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9555 -- The first argument to the pragma
9557 Int_Ent : Entity_Id;
9558 -- Interrupt entity in Ada.Interrupts.Names
9562 Check_Arg_Order ((Name_Name, Name_State));
9563 Check_Arg_Count (2);
9565 Check_Optional_Identifier (Arg1, Name_Name);
9566 Check_Optional_Identifier (Arg2, Name_State);
9567 Check_Arg_Is_Identifier (Arg2);
9569 -- First argument is identifier
9571 if Nkind (Arg1X) = N_Identifier then
9573 -- Search list of names in Ada.Interrupts.Names
9575 Int_Ent := First_Entity (RTE (RE_Names));
9577 if No (Int_Ent) then
9578 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9580 elsif Chars (Int_Ent) = Chars (Arg1X) then
9581 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9585 Next_Entity (Int_Ent);
9588 -- First argument is not an identifier, so it must be a static
9589 -- expression of type Ada.Interrupts.Interrupt_ID.
9592 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9593 Int_Val := Expr_Value (Arg1X);
9595 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9597 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9600 ("value not in range of type " &
9601 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9607 case Chars (Get_Pragma_Arg (Arg2)) is
9608 when Name_Runtime => State_Type := 'r';
9609 when Name_System => State_Type := 's';
9610 when Name_User => State_Type := 'u';
9613 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9616 -- Check if entry is already stored
9618 IST_Num := Interrupt_States.First;
9620 -- If entry not found, add it
9622 if IST_Num > Interrupt_States.Last then
9623 Interrupt_States.Append
9624 ((Interrupt_Number => UI_To_Int (Int_Val),
9625 Interrupt_State => State_Type,
9626 Pragma_Loc => Loc));
9629 -- Case of entry for the same entry
9631 elsif Int_Val = Interrupt_States.Table (IST_Num).
9634 -- If state matches, done, no need to make redundant entry
9637 State_Type = Interrupt_States.Table (IST_Num).
9640 -- Otherwise if state does not match, error
9643 Interrupt_States.Table (IST_Num).Pragma_Loc;
9645 ("state conflicts with that given #", Arg2);
9649 IST_Num := IST_Num + 1;
9651 end Interrupt_State;
9658 -- ([Entity =>] type_LOCAL_NAME,
9659 -- [Check =>] EXPRESSION
9660 -- [,[Message =>] String_Expression]);
9662 when Pragma_Invariant => Invariant : declare
9667 pragma Unreferenced (Discard);
9671 Check_At_Least_N_Arguments (2);
9672 Check_At_Most_N_Arguments (3);
9673 Check_Optional_Identifier (Arg1, Name_Entity);
9674 Check_Optional_Identifier (Arg2, Name_Check);
9676 if Arg_Count = 3 then
9677 Check_Optional_Identifier (Arg3, Name_Message);
9678 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9681 Check_Arg_Is_Local_Name (Arg1);
9683 Type_Id := Get_Pragma_Arg (Arg1);
9684 Find_Type (Type_Id);
9685 Typ := Entity (Type_Id);
9687 if Typ = Any_Type then
9690 elsif not Ekind_In (Typ, E_Private_Type,
9691 E_Record_Type_With_Private,
9692 E_Limited_Private_Type)
9695 ("pragma% only allowed for private type", Arg1);
9698 -- Note that the type has at least one invariant, and also that
9699 -- it has inheritable invariants if we have Invariant'Class.
9701 Set_Has_Invariants (Typ);
9703 if Class_Present (N) then
9704 Set_Has_Inheritable_Invariants (Typ);
9707 -- The remaining processing is simply to link the pragma on to
9708 -- the rep item chain, for processing when the type is frozen.
9709 -- This is accomplished by a call to Rep_Item_Too_Late.
9711 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9714 ----------------------
9715 -- Java_Constructor --
9716 ----------------------
9718 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9720 -- Also handles pragma CIL_Constructor
9722 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9723 Java_Constructor : declare
9724 Convention : Convention_Id;
9728 This_Formal : Entity_Id;
9732 Check_Arg_Count (1);
9733 Check_Optional_Identifier (Arg1, Name_Entity);
9734 Check_Arg_Is_Local_Name (Arg1);
9736 Id := Get_Pragma_Arg (Arg1);
9737 Find_Program_Unit_Name (Id);
9739 -- If we did not find the name, we are done
9741 if Etype (Id) = Any_Type then
9745 -- Check wrong use of pragma in wrong VM target
9747 if VM_Target = No_VM then
9750 elsif VM_Target = CLI_Target
9751 and then Prag_Id = Pragma_Java_Constructor
9753 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9755 elsif VM_Target = JVM_Target
9756 and then Prag_Id = Pragma_CIL_Constructor
9758 Error_Pragma ("must use pragma 'Java_'Constructor");
9762 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9763 when Pragma_Java_Constructor => Convention := Convention_Java;
9764 when others => null;
9767 Hom_Id := Entity (Id);
9769 -- Loop through homonyms
9772 Def_Id := Get_Base_Subprogram (Hom_Id);
9774 -- The constructor is required to be a function
9776 if Ekind (Def_Id) /= E_Function then
9777 if VM_Target = JVM_Target then
9779 ("pragma% requires function returning a " &
9780 "'Java access type", Def_Id);
9783 ("pragma% requires function returning a " &
9784 "'C'I'L access type", Def_Id);
9788 -- Check arguments: For tagged type the first formal must be
9789 -- named "this" and its type must be a named access type
9790 -- designating a class-wide tagged type that has convention
9791 -- CIL/Java. The first formal must also have a null default
9792 -- value. For example:
9794 -- type Typ is tagged ...
9795 -- type Ref is access all Typ;
9796 -- pragma Convention (CIL, Typ);
9798 -- function New_Typ (This : Ref) return Ref;
9799 -- function New_Typ (This : Ref; I : Integer) return Ref;
9800 -- pragma Cil_Constructor (New_Typ);
9802 -- Reason: The first formal must NOT be a primitive of the
9805 -- This rule also applies to constructors of delegates used
9806 -- to interface with standard target libraries. For example:
9808 -- type Delegate is access procedure ...
9809 -- pragma Import (CIL, Delegate, ...);
9811 -- function new_Delegate
9812 -- (This : Delegate := null; ... ) return Delegate;
9814 -- For value-types this rule does not apply.
9816 if not Is_Value_Type (Etype (Def_Id)) then
9817 if No (First_Formal (Def_Id)) then
9818 Error_Msg_Name_1 := Pname;
9819 Error_Msg_N ("% function must have parameters", Def_Id);
9823 -- In the JRE library we have several occurrences in which
9824 -- the "this" parameter is not the first formal.
9826 This_Formal := First_Formal (Def_Id);
9828 -- In the JRE library we have several occurrences in which
9829 -- the "this" parameter is not the first formal. Search for
9832 if VM_Target = JVM_Target then
9833 while Present (This_Formal)
9834 and then Get_Name_String (Chars (This_Formal)) /= "this"
9836 Next_Formal (This_Formal);
9839 if No (This_Formal) then
9840 This_Formal := First_Formal (Def_Id);
9844 -- Warning: The first parameter should be named "this".
9845 -- We temporarily allow it because we have the following
9846 -- case in the Java runtime (file s-osinte.ads) ???
9848 -- function new_Thread
9849 -- (Self_Id : System.Address) return Thread_Id;
9850 -- pragma Java_Constructor (new_Thread);
9852 if VM_Target = JVM_Target
9853 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9855 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9859 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9860 Error_Msg_Name_1 := Pname;
9862 ("first formal of % function must be named `this`",
9863 Parent (This_Formal));
9865 elsif not Is_Access_Type (Etype (This_Formal)) then
9866 Error_Msg_Name_1 := Pname;
9868 ("first formal of % function must be an access type",
9869 Parameter_Type (Parent (This_Formal)));
9871 -- For delegates the type of the first formal must be a
9872 -- named access-to-subprogram type (see previous example)
9874 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9875 and then Ekind (Etype (This_Formal))
9876 /= E_Access_Subprogram_Type
9878 Error_Msg_Name_1 := Pname;
9880 ("first formal of % function must be a named access" &
9881 " to subprogram type",
9882 Parameter_Type (Parent (This_Formal)));
9884 -- Warning: We should reject anonymous access types because
9885 -- the constructor must not be handled as a primitive of the
9886 -- tagged type. We temporarily allow it because this profile
9887 -- is currently generated by cil2ada???
9889 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9890 and then not Ekind_In (Etype (This_Formal),
9892 E_General_Access_Type,
9893 E_Anonymous_Access_Type)
9895 Error_Msg_Name_1 := Pname;
9897 ("first formal of % function must be a named access" &
9899 Parameter_Type (Parent (This_Formal)));
9901 elsif Atree.Convention
9902 (Designated_Type (Etype (This_Formal))) /= Convention
9904 Error_Msg_Name_1 := Pname;
9906 if Convention = Convention_Java then
9908 ("pragma% requires convention 'Cil in designated" &
9910 Parameter_Type (Parent (This_Formal)));
9913 ("pragma% requires convention 'Java in designated" &
9915 Parameter_Type (Parent (This_Formal)));
9918 elsif No (Expression (Parent (This_Formal)))
9919 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9921 Error_Msg_Name_1 := Pname;
9923 ("pragma% requires first formal with default `null`",
9924 Parameter_Type (Parent (This_Formal)));
9928 -- Check result type: the constructor must be a function
9930 -- * a value type (only allowed in the CIL compiler)
9931 -- * an access-to-subprogram type with convention Java/CIL
9932 -- * an access-type designating a type that has convention
9935 if Is_Value_Type (Etype (Def_Id)) then
9938 -- Access-to-subprogram type with convention Java/CIL
9940 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9941 if Atree.Convention (Etype (Def_Id)) /= Convention then
9942 if Convention = Convention_Java then
9944 ("pragma% requires function returning a " &
9945 "'Java access type", Arg1);
9947 pragma Assert (Convention = Convention_CIL);
9949 ("pragma% requires function returning a " &
9950 "'C'I'L access type", Arg1);
9954 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9955 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9956 E_General_Access_Type)
9959 (Designated_Type (Etype (Def_Id))) /= Convention
9961 Error_Msg_Name_1 := Pname;
9963 if Convention = Convention_Java then
9965 ("pragma% requires function returning a named" &
9966 "'Java access type", Arg1);
9969 ("pragma% requires function returning a named" &
9970 "'C'I'L access type", Arg1);
9975 Set_Is_Constructor (Def_Id);
9976 Set_Convention (Def_Id, Convention);
9977 Set_Is_Imported (Def_Id);
9979 exit when From_Aspect_Specification (N);
9980 Hom_Id := Homonym (Hom_Id);
9982 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9984 end Java_Constructor;
9986 ----------------------
9987 -- Java_Interface --
9988 ----------------------
9990 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9992 when Pragma_Java_Interface => Java_Interface : declare
9998 Check_Arg_Count (1);
9999 Check_Optional_Identifier (Arg1, Name_Entity);
10000 Check_Arg_Is_Local_Name (Arg1);
10002 Arg := Get_Pragma_Arg (Arg1);
10005 if Etype (Arg) = Any_Type then
10009 if not Is_Entity_Name (Arg)
10010 or else not Is_Type (Entity (Arg))
10012 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10015 Typ := Underlying_Type (Entity (Arg));
10017 -- For now simply check some of the semantic constraints on the
10018 -- type. This currently leaves out some restrictions on interface
10019 -- types, namely that the parent type must be java.lang.Object.Typ
10020 -- and that all primitives of the type should be declared
10023 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10024 Error_Pragma_Arg ("pragma% requires an abstract "
10025 & "tagged type", Arg1);
10027 elsif not Has_Discriminants (Typ)
10028 or else Ekind (Etype (First_Discriminant (Typ)))
10029 /= E_Anonymous_Access_Type
10031 not Is_Class_Wide_Type
10032 (Designated_Type (Etype (First_Discriminant (Typ))))
10035 ("type must have a class-wide access discriminant", Arg1);
10037 end Java_Interface;
10043 -- pragma Keep_Names ([On => ] local_NAME);
10045 when Pragma_Keep_Names => Keep_Names : declare
10050 Check_Arg_Count (1);
10051 Check_Optional_Identifier (Arg1, Name_On);
10052 Check_Arg_Is_Local_Name (Arg1);
10054 Arg := Get_Pragma_Arg (Arg1);
10057 if Etype (Arg) = Any_Type then
10061 if not Is_Entity_Name (Arg)
10062 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10065 ("pragma% requires a local enumeration type", Arg1);
10068 Set_Discard_Names (Entity (Arg), False);
10075 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10077 when Pragma_License =>
10079 Check_Arg_Count (1);
10080 Check_No_Identifiers;
10081 Check_Valid_Configuration_Pragma;
10082 Check_Arg_Is_Identifier (Arg1);
10085 Sind : constant Source_File_Index :=
10086 Source_Index (Current_Sem_Unit);
10089 case Chars (Get_Pragma_Arg (Arg1)) is
10091 Set_License (Sind, GPL);
10093 when Name_Modified_GPL =>
10094 Set_License (Sind, Modified_GPL);
10096 when Name_Restricted =>
10097 Set_License (Sind, Restricted);
10099 when Name_Unrestricted =>
10100 Set_License (Sind, Unrestricted);
10103 Error_Pragma_Arg ("invalid license name", Arg1);
10111 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10113 when Pragma_Link_With => Link_With : declare
10119 if Operating_Mode = Generate_Code
10120 and then In_Extended_Main_Source_Unit (N)
10122 Check_At_Least_N_Arguments (1);
10123 Check_No_Identifiers;
10124 Check_Is_In_Decl_Part_Or_Package_Spec;
10125 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10129 while Present (Arg) loop
10130 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10132 -- Store argument, converting sequences of spaces to a
10133 -- single null character (this is one of the differences
10134 -- in processing between Link_With and Linker_Options).
10136 Arg_Store : declare
10137 C : constant Char_Code := Get_Char_Code (' ');
10138 S : constant String_Id :=
10139 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10140 L : constant Nat := String_Length (S);
10143 procedure Skip_Spaces;
10144 -- Advance F past any spaces
10150 procedure Skip_Spaces is
10152 while F <= L and then Get_String_Char (S, F) = C loop
10157 -- Start of processing for Arg_Store
10160 Skip_Spaces; -- skip leading spaces
10162 -- Loop through characters, changing any embedded
10163 -- sequence of spaces to a single null character (this
10164 -- is how Link_With/Linker_Options differ)
10167 if Get_String_Char (S, F) = C then
10170 Store_String_Char (ASCII.NUL);
10173 Store_String_Char (Get_String_Char (S, F));
10181 if Present (Arg) then
10182 Store_String_Char (ASCII.NUL);
10186 Store_Linker_Option_String (End_String);
10194 -- pragma Linker_Alias (
10195 -- [Entity =>] LOCAL_NAME
10196 -- [Target =>] static_string_EXPRESSION);
10198 when Pragma_Linker_Alias =>
10200 Check_Arg_Order ((Name_Entity, Name_Target));
10201 Check_Arg_Count (2);
10202 Check_Optional_Identifier (Arg1, Name_Entity);
10203 Check_Optional_Identifier (Arg2, Name_Target);
10204 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10205 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10207 -- The only processing required is to link this item on to the
10208 -- list of rep items for the given entity. This is accomplished
10209 -- by the call to Rep_Item_Too_Late (when no error is detected
10210 -- and False is returned).
10212 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10215 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10218 ------------------------
10219 -- Linker_Constructor --
10220 ------------------------
10222 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10224 -- Code is shared with Linker_Destructor
10226 -----------------------
10227 -- Linker_Destructor --
10228 -----------------------
10230 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10232 when Pragma_Linker_Constructor |
10233 Pragma_Linker_Destructor =>
10234 Linker_Constructor : declare
10240 Check_Arg_Count (1);
10241 Check_No_Identifiers;
10242 Check_Arg_Is_Local_Name (Arg1);
10243 Arg1_X := Get_Pragma_Arg (Arg1);
10245 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10247 if not Is_Library_Level_Entity (Proc) then
10249 ("argument for pragma% must be library level entity", Arg1);
10252 -- The only processing required is to link this item on to the
10253 -- list of rep items for the given entity. This is accomplished
10254 -- by the call to Rep_Item_Too_Late (when no error is detected
10255 -- and False is returned).
10257 if Rep_Item_Too_Late (Proc, N) then
10260 Set_Has_Gigi_Rep_Item (Proc);
10262 end Linker_Constructor;
10264 --------------------
10265 -- Linker_Options --
10266 --------------------
10268 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10270 when Pragma_Linker_Options => Linker_Options : declare
10274 Check_Ada_83_Warning;
10275 Check_No_Identifiers;
10276 Check_Arg_Count (1);
10277 Check_Is_In_Decl_Part_Or_Package_Spec;
10278 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10279 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10282 while Present (Arg) loop
10283 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10284 Store_String_Char (ASCII.NUL);
10286 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10290 if Operating_Mode = Generate_Code
10291 and then In_Extended_Main_Source_Unit (N)
10293 Store_Linker_Option_String (End_String);
10295 end Linker_Options;
10297 --------------------
10298 -- Linker_Section --
10299 --------------------
10301 -- pragma Linker_Section (
10302 -- [Entity =>] LOCAL_NAME
10303 -- [Section =>] static_string_EXPRESSION);
10305 when Pragma_Linker_Section =>
10307 Check_Arg_Order ((Name_Entity, Name_Section));
10308 Check_Arg_Count (2);
10309 Check_Optional_Identifier (Arg1, Name_Entity);
10310 Check_Optional_Identifier (Arg2, Name_Section);
10311 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10312 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10314 -- This pragma applies only to objects
10316 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10317 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10320 -- The only processing required is to link this item on to the
10321 -- list of rep items for the given entity. This is accomplished
10322 -- by the call to Rep_Item_Too_Late (when no error is detected
10323 -- and False is returned).
10325 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10328 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10335 -- pragma List (On | Off)
10337 -- There is nothing to do here, since we did all the processing for
10338 -- this pragma in Par.Prag (so that it works properly even in syntax
10341 when Pragma_List =>
10344 --------------------
10345 -- Locking_Policy --
10346 --------------------
10348 -- pragma Locking_Policy (policy_IDENTIFIER);
10350 when Pragma_Locking_Policy => declare
10354 Check_Ada_83_Warning;
10355 Check_Arg_Count (1);
10356 Check_No_Identifiers;
10357 Check_Arg_Is_Locking_Policy (Arg1);
10358 Check_Valid_Configuration_Pragma;
10359 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10360 LP := Fold_Upper (Name_Buffer (1));
10362 if Locking_Policy /= ' '
10363 and then Locking_Policy /= LP
10365 Error_Msg_Sloc := Locking_Policy_Sloc;
10366 Error_Pragma ("locking policy incompatible with policy#");
10368 -- Set new policy, but always preserve System_Location since we
10369 -- like the error message with the run time name.
10372 Locking_Policy := LP;
10374 if Locking_Policy_Sloc /= System_Location then
10375 Locking_Policy_Sloc := Loc;
10384 -- pragma Long_Float (D_Float | G_Float);
10386 when Pragma_Long_Float =>
10388 Check_Valid_Configuration_Pragma;
10389 Check_Arg_Count (1);
10390 Check_No_Identifier (Arg1);
10391 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10393 if not OpenVMS_On_Target then
10394 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10399 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10400 if Opt.Float_Format_Long = 'G' then
10401 Error_Pragma ("G_Float previously specified");
10404 Opt.Float_Format_Long := 'D';
10406 -- G_Float case (this is the default, does not need overriding)
10409 if Opt.Float_Format_Long = 'D' then
10410 Error_Pragma ("D_Float previously specified");
10413 Opt.Float_Format_Long := 'G';
10416 Set_Standard_Fpt_Formats;
10418 -----------------------
10419 -- Machine_Attribute --
10420 -----------------------
10422 -- pragma Machine_Attribute (
10423 -- [Entity =>] LOCAL_NAME,
10424 -- [Attribute_Name =>] static_string_EXPRESSION
10425 -- [, [Info =>] static_EXPRESSION] );
10427 when Pragma_Machine_Attribute => Machine_Attribute : declare
10428 Def_Id : Entity_Id;
10432 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10434 if Arg_Count = 3 then
10435 Check_Optional_Identifier (Arg3, Name_Info);
10436 Check_Arg_Is_Static_Expression (Arg3);
10438 Check_Arg_Count (2);
10441 Check_Optional_Identifier (Arg1, Name_Entity);
10442 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10443 Check_Arg_Is_Local_Name (Arg1);
10444 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10445 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10447 if Is_Access_Type (Def_Id) then
10448 Def_Id := Designated_Type (Def_Id);
10451 if Rep_Item_Too_Early (Def_Id, N) then
10455 Def_Id := Underlying_Type (Def_Id);
10457 -- The only processing required is to link this item on to the
10458 -- list of rep items for the given entity. This is accomplished
10459 -- by the call to Rep_Item_Too_Late (when no error is detected
10460 -- and False is returned).
10462 if Rep_Item_Too_Late (Def_Id, N) then
10465 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10467 end Machine_Attribute;
10474 -- (MAIN_OPTION [, MAIN_OPTION]);
10477 -- [STACK_SIZE =>] static_integer_EXPRESSION
10478 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10479 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10481 when Pragma_Main => Main : declare
10482 Args : Args_List (1 .. 3);
10483 Names : constant Name_List (1 .. 3) := (
10485 Name_Task_Stack_Size_Default,
10486 Name_Time_Slicing_Enabled);
10492 Gather_Associations (Names, Args);
10494 for J in 1 .. 2 loop
10495 if Present (Args (J)) then
10496 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10500 if Present (Args (3)) then
10501 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10505 while Present (Nod) loop
10506 if Nkind (Nod) = N_Pragma
10507 and then Pragma_Name (Nod) = Name_Main
10509 Error_Msg_Name_1 := Pname;
10510 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10521 -- pragma Main_Storage
10522 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10524 -- MAIN_STORAGE_OPTION ::=
10525 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10526 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10528 when Pragma_Main_Storage => Main_Storage : declare
10529 Args : Args_List (1 .. 2);
10530 Names : constant Name_List (1 .. 2) := (
10531 Name_Working_Storage,
10538 Gather_Associations (Names, Args);
10540 for J in 1 .. 2 loop
10541 if Present (Args (J)) then
10542 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10546 Check_In_Main_Program;
10549 while Present (Nod) loop
10550 if Nkind (Nod) = N_Pragma
10551 and then Pragma_Name (Nod) = Name_Main_Storage
10553 Error_Msg_Name_1 := Pname;
10554 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10565 -- pragma Memory_Size (NUMERIC_LITERAL)
10567 when Pragma_Memory_Size =>
10570 -- Memory size is simply ignored
10572 Check_No_Identifiers;
10573 Check_Arg_Count (1);
10574 Check_Arg_Is_Integer_Literal (Arg1);
10582 -- The only correct use of this pragma is on its own in a file, in
10583 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10584 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10585 -- check for a file containing nothing but a No_Body pragma). If we
10586 -- attempt to process it during normal semantics processing, it means
10587 -- it was misplaced.
10589 when Pragma_No_Body =>
10597 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10599 when Pragma_No_Return => No_Return : declare
10607 Check_At_Least_N_Arguments (1);
10609 -- Loop through arguments of pragma
10612 while Present (Arg) loop
10613 Check_Arg_Is_Local_Name (Arg);
10614 Id := Get_Pragma_Arg (Arg);
10617 if not Is_Entity_Name (Id) then
10618 Error_Pragma_Arg ("entity name required", Arg);
10621 if Etype (Id) = Any_Type then
10625 -- Loop to find matching procedures
10630 and then Scope (E) = Current_Scope
10632 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10635 -- Set flag on any alias as well
10637 if Is_Overloadable (E) and then Present (Alias (E)) then
10638 Set_No_Return (Alias (E));
10644 exit when From_Aspect_Specification (N);
10649 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10660 -- pragma No_Run_Time;
10662 -- Note: this pragma is retained for backwards compatibility. See
10663 -- body of Rtsfind for full details on its handling.
10665 when Pragma_No_Run_Time =>
10667 Check_Valid_Configuration_Pragma;
10668 Check_Arg_Count (0);
10670 No_Run_Time_Mode := True;
10671 Configurable_Run_Time_Mode := True;
10673 -- Set Duration to 32 bits if word size is 32
10675 if Ttypes.System_Word_Size = 32 then
10676 Duration_32_Bits_On_Target := True;
10679 -- Set appropriate restrictions
10681 Set_Restriction (No_Finalization, N);
10682 Set_Restriction (No_Exception_Handlers, N);
10683 Set_Restriction (Max_Tasks, N, 0);
10684 Set_Restriction (No_Tasking, N);
10686 ------------------------
10687 -- No_Strict_Aliasing --
10688 ------------------------
10690 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10692 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10697 Check_At_Most_N_Arguments (1);
10699 if Arg_Count = 0 then
10700 Check_Valid_Configuration_Pragma;
10701 Opt.No_Strict_Aliasing := True;
10704 Check_Optional_Identifier (Arg2, Name_Entity);
10705 Check_Arg_Is_Local_Name (Arg1);
10706 E_Id := Entity (Get_Pragma_Arg (Arg1));
10708 if E_Id = Any_Type then
10710 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10711 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10714 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10716 end No_Strict_Aliasing;
10718 -----------------------
10719 -- Normalize_Scalars --
10720 -----------------------
10722 -- pragma Normalize_Scalars;
10724 when Pragma_Normalize_Scalars =>
10725 Check_Ada_83_Warning;
10726 Check_Arg_Count (0);
10727 Check_Valid_Configuration_Pragma;
10729 -- Normalize_Scalars creates false positives in CodePeer, so
10730 -- ignore this pragma in this mode.
10732 if not CodePeer_Mode then
10733 Normalize_Scalars := True;
10734 Init_Or_Norm_Scalars := True;
10741 -- pragma Obsolescent;
10743 -- pragma Obsolescent (
10744 -- [Message =>] static_string_EXPRESSION
10745 -- [,[Version =>] Ada_05]]);
10747 -- pragma Obsolescent (
10748 -- [Entity =>] NAME
10749 -- [,[Message =>] static_string_EXPRESSION
10750 -- [,[Version =>] Ada_05]] );
10752 when Pragma_Obsolescent => Obsolescent : declare
10756 procedure Set_Obsolescent (E : Entity_Id);
10757 -- Given an entity Ent, mark it as obsolescent if appropriate
10759 ---------------------
10760 -- Set_Obsolescent --
10761 ---------------------
10763 procedure Set_Obsolescent (E : Entity_Id) is
10772 -- Entity name was given
10774 if Present (Ename) then
10776 -- If entity name matches, we are fine. Save entity in
10777 -- pragma argument, for ASIS use.
10779 if Chars (Ename) = Chars (Ent) then
10780 Set_Entity (Ename, Ent);
10781 Generate_Reference (Ent, Ename);
10783 -- If entity name does not match, only possibility is an
10784 -- enumeration literal from an enumeration type declaration.
10786 elsif Ekind (Ent) /= E_Enumeration_Type then
10788 ("pragma % entity name does not match declaration");
10791 Ent := First_Literal (E);
10795 ("pragma % entity name does not match any " &
10796 "enumeration literal");
10798 elsif Chars (Ent) = Chars (Ename) then
10799 Set_Entity (Ename, Ent);
10800 Generate_Reference (Ent, Ename);
10804 Ent := Next_Literal (Ent);
10810 -- Ent points to entity to be marked
10812 if Arg_Count >= 1 then
10814 -- Deal with static string argument
10816 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10817 S := Strval (Get_Pragma_Arg (Arg1));
10819 for J in 1 .. String_Length (S) loop
10820 if not In_Character_Range (Get_String_Char (S, J)) then
10822 ("pragma% argument does not allow wide characters",
10827 Obsolescent_Warnings.Append
10828 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10830 -- Check for Ada_05 parameter
10832 if Arg_Count /= 1 then
10833 Check_Arg_Count (2);
10836 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10839 Check_Arg_Is_Identifier (Argx);
10841 if Chars (Argx) /= Name_Ada_05 then
10842 Error_Msg_Name_2 := Name_Ada_05;
10844 ("only allowed argument for pragma% is %", Argx);
10847 if Ada_Version_Explicit < Ada_2005
10848 or else not Warn_On_Ada_2005_Compatibility
10856 -- Set flag if pragma active
10859 Set_Is_Obsolescent (Ent);
10863 end Set_Obsolescent;
10865 -- Start of processing for pragma Obsolescent
10870 Check_At_Most_N_Arguments (3);
10872 -- See if first argument specifies an entity name
10876 (Chars (Arg1) = Name_Entity
10878 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10880 N_Operator_Symbol))
10882 Ename := Get_Pragma_Arg (Arg1);
10884 -- Eliminate first argument, so we can share processing
10888 Arg_Count := Arg_Count - 1;
10890 -- No Entity name argument given
10896 if Arg_Count >= 1 then
10897 Check_Optional_Identifier (Arg1, Name_Message);
10899 if Arg_Count = 2 then
10900 Check_Optional_Identifier (Arg2, Name_Version);
10904 -- Get immediately preceding declaration
10907 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10911 -- Cases where we do not follow anything other than another pragma
10915 -- First case: library level compilation unit declaration with
10916 -- the pragma immediately following the declaration.
10918 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10920 (Defining_Entity (Unit (Parent (Parent (N)))));
10923 -- Case 2: library unit placement for package
10927 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10929 if Is_Package_Or_Generic_Package (Ent) then
10930 Set_Obsolescent (Ent);
10936 -- Cases where we must follow a declaration
10939 if Nkind (Decl) not in N_Declaration
10940 and then Nkind (Decl) not in N_Later_Decl_Item
10941 and then Nkind (Decl) not in N_Generic_Declaration
10942 and then Nkind (Decl) not in N_Renaming_Declaration
10945 ("pragma% misplaced, "
10946 & "must immediately follow a declaration");
10949 Set_Obsolescent (Defining_Entity (Decl));
10959 -- pragma Optimize (Time | Space | Off);
10961 -- The actual check for optimize is done in Gigi. Note that this
10962 -- pragma does not actually change the optimization setting, it
10963 -- simply checks that it is consistent with the pragma.
10965 when Pragma_Optimize =>
10966 Check_No_Identifiers;
10967 Check_Arg_Count (1);
10968 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10970 ------------------------
10971 -- Optimize_Alignment --
10972 ------------------------
10974 -- pragma Optimize_Alignment (Time | Space | Off);
10976 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10978 Check_No_Identifiers;
10979 Check_Arg_Count (1);
10980 Check_Valid_Configuration_Pragma;
10983 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10987 Opt.Optimize_Alignment := 'T';
10989 Opt.Optimize_Alignment := 'S';
10991 Opt.Optimize_Alignment := 'O';
10993 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10997 -- Set indication that mode is set locally. If we are in fact in a
10998 -- configuration pragma file, this setting is harmless since the
10999 -- switch will get reset anyway at the start of each unit.
11001 Optimize_Alignment_Local := True;
11002 end Optimize_Alignment;
11008 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11010 when Pragma_Ordered => Ordered : declare
11011 Assoc : constant Node_Id := Arg1;
11017 Check_No_Identifiers;
11018 Check_Arg_Count (1);
11019 Check_Arg_Is_Local_Name (Arg1);
11021 Type_Id := Get_Pragma_Arg (Assoc);
11022 Find_Type (Type_Id);
11023 Typ := Entity (Type_Id);
11025 if Typ = Any_Type then
11028 Typ := Underlying_Type (Typ);
11031 if not Is_Enumeration_Type (Typ) then
11032 Error_Pragma ("pragma% must specify enumeration type");
11035 Check_First_Subtype (Arg1);
11036 Set_Has_Pragma_Ordered (Base_Type (Typ));
11043 -- pragma Pack (first_subtype_LOCAL_NAME);
11045 when Pragma_Pack => Pack : declare
11046 Assoc : constant Node_Id := Arg1;
11050 Ignore : Boolean := False;
11053 Check_No_Identifiers;
11054 Check_Arg_Count (1);
11055 Check_Arg_Is_Local_Name (Arg1);
11057 Type_Id := Get_Pragma_Arg (Assoc);
11058 Find_Type (Type_Id);
11059 Typ := Entity (Type_Id);
11062 or else Rep_Item_Too_Early (Typ, N)
11066 Typ := Underlying_Type (Typ);
11069 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11070 Error_Pragma ("pragma% must specify array or record type");
11073 Check_First_Subtype (Arg1);
11074 Check_Duplicate_Pragma (Typ);
11078 if Is_Array_Type (Typ) then
11079 Ctyp := Component_Type (Typ);
11081 -- Ignore pack that does nothing
11083 if Known_Static_Esize (Ctyp)
11084 and then Known_Static_RM_Size (Ctyp)
11085 and then Esize (Ctyp) = RM_Size (Ctyp)
11086 and then Addressable (Esize (Ctyp))
11091 -- Process OK pragma Pack. Note that if there is a separate
11092 -- component clause present, the Pack will be cancelled. This
11093 -- processing is in Freeze.
11095 if not Rep_Item_Too_Late (Typ, N) then
11097 -- In the context of static code analysis, we do not need
11098 -- complex front-end expansions related to pragma Pack,
11099 -- so disable handling of pragma Pack in this case.
11101 if CodePeer_Mode then
11104 -- Don't attempt any packing for VM targets. We possibly
11105 -- could deal with some cases of array bit-packing, but we
11106 -- don't bother, since this is not a typical kind of
11107 -- representation in the VM context anyway (and would not
11108 -- for example work nicely with the debugger).
11110 elsif VM_Target /= No_VM then
11111 if not GNAT_Mode then
11113 ("?pragma% ignored in this configuration");
11116 -- Normal case where we do the pack action
11120 Set_Is_Packed (Base_Type (Typ));
11121 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11124 Set_Has_Pragma_Pack (Base_Type (Typ));
11128 -- For record types, the pack is always effective
11130 else pragma Assert (Is_Record_Type (Typ));
11131 if not Rep_Item_Too_Late (Typ, N) then
11133 -- Ignore pack request with warning in VM mode (skip warning
11134 -- if we are compiling GNAT run time library).
11136 if VM_Target /= No_VM then
11137 if not GNAT_Mode then
11139 ("?pragma% ignored in this configuration");
11142 -- Normal case of pack request active
11145 Set_Is_Packed (Base_Type (Typ));
11146 Set_Has_Pragma_Pack (Base_Type (Typ));
11147 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11159 -- There is nothing to do here, since we did all the processing for
11160 -- this pragma in Par.Prag (so that it works properly even in syntax
11163 when Pragma_Page =>
11170 -- pragma Passive [(PASSIVE_FORM)];
11172 -- PASSIVE_FORM ::= Semaphore | No
11174 when Pragma_Passive =>
11177 if Nkind (Parent (N)) /= N_Task_Definition then
11178 Error_Pragma ("pragma% must be within task definition");
11181 if Arg_Count /= 0 then
11182 Check_Arg_Count (1);
11183 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11186 ----------------------------------
11187 -- Preelaborable_Initialization --
11188 ----------------------------------
11190 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11192 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11197 Check_Arg_Count (1);
11198 Check_No_Identifiers;
11199 Check_Arg_Is_Identifier (Arg1);
11200 Check_Arg_Is_Local_Name (Arg1);
11201 Check_First_Subtype (Arg1);
11202 Ent := Entity (Get_Pragma_Arg (Arg1));
11204 if not (Is_Private_Type (Ent)
11206 Is_Protected_Type (Ent)
11208 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11211 ("pragma % can only be applied to private, formal derived or "
11212 & "protected type",
11216 -- Give an error if the pragma is applied to a protected type that
11217 -- does not qualify (due to having entries, or due to components
11218 -- that do not qualify).
11220 if Is_Protected_Type (Ent)
11221 and then not Has_Preelaborable_Initialization (Ent)
11224 ("protected type & does not have preelaborable " &
11225 "initialization", Ent);
11227 -- Otherwise mark the type as definitely having preelaborable
11231 Set_Known_To_Have_Preelab_Init (Ent);
11234 if Has_Pragma_Preelab_Init (Ent)
11235 and then Warn_On_Redundant_Constructs
11237 Error_Pragma ("?duplicate pragma%!");
11239 Set_Has_Pragma_Preelab_Init (Ent);
11243 --------------------
11244 -- Persistent_BSS --
11245 --------------------
11247 -- pragma Persistent_BSS [(object_NAME)];
11249 when Pragma_Persistent_BSS => Persistent_BSS : declare
11256 Check_At_Most_N_Arguments (1);
11258 -- Case of application to specific object (one argument)
11260 if Arg_Count = 1 then
11261 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11263 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11265 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11268 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11271 Ent := Entity (Get_Pragma_Arg (Arg1));
11272 Decl := Parent (Ent);
11274 if Rep_Item_Too_Late (Ent, N) then
11278 if Present (Expression (Decl)) then
11280 ("object for pragma% cannot have initialization", Arg1);
11283 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11285 ("object type for pragma% is not potentially persistent",
11289 Check_Duplicate_Pragma (Ent);
11292 Make_Linker_Section_Pragma
11293 (Ent, Sloc (N), ".persistent.bss");
11294 Insert_After (N, Prag);
11297 -- Case of use as configuration pragma with no arguments
11300 Check_Valid_Configuration_Pragma;
11301 Persistent_BSS_Mode := True;
11303 end Persistent_BSS;
11309 -- pragma Polling (ON | OFF);
11311 when Pragma_Polling =>
11313 Check_Arg_Count (1);
11314 Check_No_Identifiers;
11315 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11316 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11318 -------------------
11319 -- Postcondition --
11320 -------------------
11322 -- pragma Postcondition ([Check =>] Boolean_Expression
11323 -- [,[Message =>] String_Expression]);
11325 when Pragma_Postcondition => Postcondition : declare
11327 pragma Warnings (Off, In_Body);
11331 Check_At_Least_N_Arguments (1);
11332 Check_At_Most_N_Arguments (2);
11333 Check_Optional_Identifier (Arg1, Name_Check);
11335 -- All we need to do here is call the common check procedure,
11336 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11338 Check_Precondition_Postcondition (In_Body);
11345 -- pragma Precondition ([Check =>] Boolean_Expression
11346 -- [,[Message =>] String_Expression]);
11348 when Pragma_Precondition => Precondition : declare
11353 Check_At_Least_N_Arguments (1);
11354 Check_At_Most_N_Arguments (2);
11355 Check_Optional_Identifier (Arg1, Name_Check);
11356 Check_Precondition_Postcondition (In_Body);
11358 -- If in spec, nothing more to do. If in body, then we convert the
11359 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11360 -- this whether or not precondition checks are enabled. That works
11361 -- fine since pragma Check will do this check, and will also
11362 -- analyze the condition itself in the proper context.
11367 Chars => Name_Check,
11368 Pragma_Argument_Associations => New_List (
11369 Make_Pragma_Argument_Association (Loc,
11370 Expression => Make_Identifier (Loc, Name_Precondition)),
11372 Make_Pragma_Argument_Association (Sloc (Arg1),
11373 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11375 if Arg_Count = 2 then
11376 Append_To (Pragma_Argument_Associations (N),
11377 Make_Pragma_Argument_Association (Sloc (Arg2),
11378 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11389 -- pragma Predicate
11390 -- ([Entity =>] type_LOCAL_NAME,
11391 -- [Check =>] EXPRESSION);
11393 when Pragma_Predicate => Predicate : declare
11398 pragma Unreferenced (Discard);
11402 Check_Arg_Count (2);
11403 Check_Optional_Identifier (Arg1, Name_Entity);
11404 Check_Optional_Identifier (Arg2, Name_Check);
11406 Check_Arg_Is_Local_Name (Arg1);
11408 Type_Id := Get_Pragma_Arg (Arg1);
11409 Find_Type (Type_Id);
11410 Typ := Entity (Type_Id);
11412 if Typ = Any_Type then
11416 -- The remaining processing is simply to link the pragma on to
11417 -- the rep item chain, for processing when the type is frozen.
11418 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11419 -- mark the type as having predicates.
11421 Set_Has_Predicates (Typ);
11422 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11429 -- pragma Preelaborate [(library_unit_NAME)];
11431 -- Set the flag Is_Preelaborated of program unit name entity
11433 when Pragma_Preelaborate => Preelaborate : declare
11434 Pa : constant Node_Id := Parent (N);
11435 Pk : constant Node_Kind := Nkind (Pa);
11439 Check_Ada_83_Warning;
11440 Check_Valid_Library_Unit_Pragma;
11442 if Nkind (N) = N_Null_Statement then
11446 Ent := Find_Lib_Unit_Name;
11447 Check_Duplicate_Pragma (Ent);
11449 -- This filters out pragmas inside generic parent then
11450 -- show up inside instantiation
11453 and then not (Pk = N_Package_Specification
11454 and then Present (Generic_Parent (Pa)))
11456 if not Debug_Flag_U then
11457 Set_Is_Preelaborated (Ent);
11458 Set_Suppress_Elaboration_Warnings (Ent);
11463 ---------------------
11464 -- Preelaborate_05 --
11465 ---------------------
11467 -- pragma Preelaborate_05 [(library_unit_NAME)];
11469 -- This pragma is useable only in GNAT_Mode, where it is used like
11470 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11471 -- (otherwise it is ignored). This is used to implement AI-362 which
11472 -- recategorizes some run-time packages in Ada 2005 mode.
11474 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11479 Check_Valid_Library_Unit_Pragma;
11481 if not GNAT_Mode then
11482 Error_Pragma ("pragma% only available in GNAT mode");
11485 if Nkind (N) = N_Null_Statement then
11489 -- This is one of the few cases where we need to test the value of
11490 -- Ada_Version_Explicit rather than Ada_Version (which is always
11491 -- set to Ada_2012 in a predefined unit), we need to know the
11492 -- explicit version set to know if this pragma is active.
11494 if Ada_Version_Explicit >= Ada_2005 then
11495 Ent := Find_Lib_Unit_Name;
11496 Set_Is_Preelaborated (Ent);
11497 Set_Suppress_Elaboration_Warnings (Ent);
11499 end Preelaborate_05;
11505 -- pragma Priority (EXPRESSION);
11507 when Pragma_Priority => Priority : declare
11508 P : constant Node_Id := Parent (N);
11512 Check_No_Identifiers;
11513 Check_Arg_Count (1);
11517 if Nkind (P) = N_Subprogram_Body then
11518 Check_In_Main_Program;
11520 Arg := Get_Pragma_Arg (Arg1);
11521 Analyze_And_Resolve (Arg, Standard_Integer);
11525 if not Is_Static_Expression (Arg) then
11526 Flag_Non_Static_Expr
11527 ("main subprogram priority is not static!", Arg);
11530 -- If constraint error, then we already signalled an error
11532 elsif Raises_Constraint_Error (Arg) then
11535 -- Otherwise check in range
11539 Val : constant Uint := Expr_Value (Arg);
11543 or else Val > Expr_Value (Expression
11544 (Parent (RTE (RE_Max_Priority))))
11547 ("main subprogram priority is out of range", Arg1);
11553 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11555 -- Load an arbitrary entity from System.Tasking to make sure
11556 -- this package is implicitly with'ed, since we need to have
11557 -- the tasking run-time active for the pragma Priority to have
11561 Discard : Entity_Id;
11562 pragma Warnings (Off, Discard);
11564 Discard := RTE (RE_Task_List);
11567 -- Task or Protected, must be of type Integer
11569 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11570 Arg := Get_Pragma_Arg (Arg1);
11572 -- The expression must be analyzed in the special manner
11573 -- described in "Handling of Default and Per-Object
11574 -- Expressions" in sem.ads.
11576 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11578 if not Is_Static_Expression (Arg) then
11579 Check_Restriction (Static_Priorities, Arg);
11582 -- Anything else is incorrect
11588 if Has_Pragma_Priority (P) then
11589 Error_Pragma ("duplicate pragma% not allowed");
11591 Set_Has_Pragma_Priority (P, True);
11593 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11594 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11595 -- exp_ch9 should use this ???
11600 -----------------------------------
11601 -- Priority_Specific_Dispatching --
11602 -----------------------------------
11604 -- pragma Priority_Specific_Dispatching (
11605 -- policy_IDENTIFIER,
11606 -- first_priority_EXPRESSION,
11607 -- last_priority_EXPRESSION);
11609 when Pragma_Priority_Specific_Dispatching =>
11610 Priority_Specific_Dispatching : declare
11611 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11612 -- This is the entity System.Any_Priority;
11615 Lower_Bound : Node_Id;
11616 Upper_Bound : Node_Id;
11622 Check_Arg_Count (3);
11623 Check_No_Identifiers;
11624 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11625 Check_Valid_Configuration_Pragma;
11626 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11627 DP := Fold_Upper (Name_Buffer (1));
11629 Lower_Bound := Get_Pragma_Arg (Arg2);
11630 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11631 Lower_Val := Expr_Value (Lower_Bound);
11633 Upper_Bound := Get_Pragma_Arg (Arg3);
11634 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11635 Upper_Val := Expr_Value (Upper_Bound);
11637 -- It is not allowed to use Task_Dispatching_Policy and
11638 -- Priority_Specific_Dispatching in the same partition.
11640 if Task_Dispatching_Policy /= ' ' then
11641 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11643 ("pragma% incompatible with Task_Dispatching_Policy#");
11645 -- Check lower bound in range
11647 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11649 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11652 ("first_priority is out of range", Arg2);
11654 -- Check upper bound in range
11656 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11658 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11661 ("last_priority is out of range", Arg3);
11663 -- Check that the priority range is valid
11665 elsif Lower_Val > Upper_Val then
11667 ("last_priority_expression must be greater than" &
11668 " or equal to first_priority_expression");
11670 -- Store the new policy, but always preserve System_Location since
11671 -- we like the error message with the run-time name.
11674 -- Check overlapping in the priority ranges specified in other
11675 -- Priority_Specific_Dispatching pragmas within the same
11676 -- partition. We can only check those we know about!
11679 Specific_Dispatching.First .. Specific_Dispatching.Last
11681 if Specific_Dispatching.Table (J).First_Priority in
11682 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11683 or else Specific_Dispatching.Table (J).Last_Priority in
11684 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11687 Specific_Dispatching.Table (J).Pragma_Loc;
11689 ("priority range overlaps with "
11690 & "Priority_Specific_Dispatching#");
11694 -- The use of Priority_Specific_Dispatching is incompatible
11695 -- with Task_Dispatching_Policy.
11697 if Task_Dispatching_Policy /= ' ' then
11698 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11700 ("Priority_Specific_Dispatching incompatible "
11701 & "with Task_Dispatching_Policy#");
11704 -- The use of Priority_Specific_Dispatching forces ceiling
11707 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11708 Error_Msg_Sloc := Locking_Policy_Sloc;
11710 ("Priority_Specific_Dispatching incompatible "
11711 & "with Locking_Policy#");
11713 -- Set the Ceiling_Locking policy, but preserve System_Location
11714 -- since we like the error message with the run time name.
11717 Locking_Policy := 'C';
11719 if Locking_Policy_Sloc /= System_Location then
11720 Locking_Policy_Sloc := Loc;
11724 -- Add entry in the table
11726 Specific_Dispatching.Append
11727 ((Dispatching_Policy => DP,
11728 First_Priority => UI_To_Int (Lower_Val),
11729 Last_Priority => UI_To_Int (Upper_Val),
11730 Pragma_Loc => Loc));
11732 end Priority_Specific_Dispatching;
11738 -- pragma Profile (profile_IDENTIFIER);
11740 -- profile_IDENTIFIER => Restricted | Ravenscar
11742 when Pragma_Profile =>
11744 Check_Arg_Count (1);
11745 Check_Valid_Configuration_Pragma;
11746 Check_No_Identifiers;
11749 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11751 if Chars (Argx) = Name_Ravenscar then
11752 Set_Ravenscar_Profile (N);
11753 elsif Chars (Argx) = Name_Restricted then
11754 Set_Profile_Restrictions
11755 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11757 Error_Pragma_Arg ("& is not a valid profile", Argx);
11761 ----------------------
11762 -- Profile_Warnings --
11763 ----------------------
11765 -- pragma Profile_Warnings (profile_IDENTIFIER);
11767 -- profile_IDENTIFIER => Restricted | Ravenscar
11769 when Pragma_Profile_Warnings =>
11771 Check_Arg_Count (1);
11772 Check_Valid_Configuration_Pragma;
11773 Check_No_Identifiers;
11776 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11778 if Chars (Argx) = Name_Ravenscar then
11779 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11780 elsif Chars (Argx) = Name_Restricted then
11781 Set_Profile_Restrictions (Restricted, N, Warn => True);
11783 Error_Pragma_Arg ("& is not a valid profile", Argx);
11787 --------------------------
11788 -- Propagate_Exceptions --
11789 --------------------------
11791 -- pragma Propagate_Exceptions;
11793 -- Note: this pragma is obsolete and has no effect
11795 when Pragma_Propagate_Exceptions =>
11797 Check_Arg_Count (0);
11799 if In_Extended_Main_Source_Unit (N) then
11800 Propagate_Exceptions := True;
11807 -- pragma Psect_Object (
11808 -- [Internal =>] LOCAL_NAME,
11809 -- [, [External =>] EXTERNAL_SYMBOL]
11810 -- [, [Size =>] EXTERNAL_SYMBOL]);
11812 when Pragma_Psect_Object | Pragma_Common_Object =>
11813 Psect_Object : declare
11814 Args : Args_List (1 .. 3);
11815 Names : constant Name_List (1 .. 3) := (
11820 Internal : Node_Id renames Args (1);
11821 External : Node_Id renames Args (2);
11822 Size : Node_Id renames Args (3);
11824 Def_Id : Entity_Id;
11826 procedure Check_Too_Long (Arg : Node_Id);
11827 -- Posts message if the argument is an identifier with more
11828 -- than 31 characters, or a string literal with more than
11829 -- 31 characters, and we are operating under VMS
11831 --------------------
11832 -- Check_Too_Long --
11833 --------------------
11835 procedure Check_Too_Long (Arg : Node_Id) is
11836 X : constant Node_Id := Original_Node (Arg);
11839 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11841 ("inappropriate argument for pragma %", Arg);
11844 if OpenVMS_On_Target then
11845 if (Nkind (X) = N_String_Literal
11846 and then String_Length (Strval (X)) > 31)
11848 (Nkind (X) = N_Identifier
11849 and then Length_Of_Name (Chars (X)) > 31)
11852 ("argument for pragma % is longer than 31 characters",
11856 end Check_Too_Long;
11858 -- Start of processing for Common_Object/Psect_Object
11862 Gather_Associations (Names, Args);
11863 Process_Extended_Import_Export_Internal_Arg (Internal);
11865 Def_Id := Entity (Internal);
11867 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11869 ("pragma% must designate an object", Internal);
11872 Check_Too_Long (Internal);
11874 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11876 ("cannot use pragma% for imported/exported object",
11880 if Is_Concurrent_Type (Etype (Internal)) then
11882 ("cannot specify pragma % for task/protected object",
11886 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11888 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11890 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11893 if Ekind (Def_Id) = E_Constant then
11895 ("cannot specify pragma % for a constant", Internal);
11898 if Is_Record_Type (Etype (Internal)) then
11904 Ent := First_Entity (Etype (Internal));
11905 while Present (Ent) loop
11906 Decl := Declaration_Node (Ent);
11908 if Ekind (Ent) = E_Component
11909 and then Nkind (Decl) = N_Component_Declaration
11910 and then Present (Expression (Decl))
11911 and then Warn_On_Export_Import
11914 ("?object for pragma % has defaults", Internal);
11924 if Present (Size) then
11925 Check_Too_Long (Size);
11928 if Present (External) then
11929 Check_Arg_Is_External_Name (External);
11930 Check_Too_Long (External);
11933 -- If all error tests pass, link pragma on to the rep item chain
11935 Record_Rep_Item (Def_Id, N);
11942 -- pragma Pure [(library_unit_NAME)];
11944 when Pragma_Pure => Pure : declare
11948 Check_Ada_83_Warning;
11949 Check_Valid_Library_Unit_Pragma;
11951 if Nkind (N) = N_Null_Statement then
11955 Ent := Find_Lib_Unit_Name;
11957 Set_Has_Pragma_Pure (Ent);
11958 Set_Suppress_Elaboration_Warnings (Ent);
11965 -- pragma Pure_05 [(library_unit_NAME)];
11967 -- This pragma is useable only in GNAT_Mode, where it is used like
11968 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11969 -- it is ignored). It may be used after a pragma Preelaborate, in
11970 -- which case it overrides the effect of the pragma Preelaborate.
11971 -- This is used to implement AI-362 which recategorizes some run-time
11972 -- packages in Ada 2005 mode.
11974 when Pragma_Pure_05 => Pure_05 : declare
11979 Check_Valid_Library_Unit_Pragma;
11981 if not GNAT_Mode then
11982 Error_Pragma ("pragma% only available in GNAT mode");
11985 if Nkind (N) = N_Null_Statement then
11989 -- This is one of the few cases where we need to test the value of
11990 -- Ada_Version_Explicit rather than Ada_Version (which is always
11991 -- set to Ada_2012 in a predefined unit), we need to know the
11992 -- explicit version set to know if this pragma is active.
11994 if Ada_Version_Explicit >= Ada_2005 then
11995 Ent := Find_Lib_Unit_Name;
11996 Set_Is_Preelaborated (Ent, False);
11998 Set_Suppress_Elaboration_Warnings (Ent);
12002 -------------------
12003 -- Pure_Function --
12004 -------------------
12006 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12008 when Pragma_Pure_Function => Pure_Function : declare
12011 Def_Id : Entity_Id;
12012 Effective : Boolean := False;
12016 Check_Arg_Count (1);
12017 Check_Optional_Identifier (Arg1, Name_Entity);
12018 Check_Arg_Is_Local_Name (Arg1);
12019 E_Id := Get_Pragma_Arg (Arg1);
12021 if Error_Posted (E_Id) then
12025 -- Loop through homonyms (overloadings) of referenced entity
12027 E := Entity (E_Id);
12029 if Present (E) then
12031 Def_Id := Get_Base_Subprogram (E);
12033 if not Ekind_In (Def_Id, E_Function,
12034 E_Generic_Function,
12038 ("pragma% requires a function name", Arg1);
12041 Set_Is_Pure (Def_Id);
12043 if not Has_Pragma_Pure_Function (Def_Id) then
12044 Set_Has_Pragma_Pure_Function (Def_Id);
12048 exit when From_Aspect_Specification (N);
12050 exit when No (E) or else Scope (E) /= Current_Scope;
12054 and then Warn_On_Redundant_Constructs
12057 ("pragma Pure_Function on& is redundant?",
12063 --------------------
12064 -- Queuing_Policy --
12065 --------------------
12067 -- pragma Queuing_Policy (policy_IDENTIFIER);
12069 when Pragma_Queuing_Policy => declare
12073 Check_Ada_83_Warning;
12074 Check_Arg_Count (1);
12075 Check_No_Identifiers;
12076 Check_Arg_Is_Queuing_Policy (Arg1);
12077 Check_Valid_Configuration_Pragma;
12078 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12079 QP := Fold_Upper (Name_Buffer (1));
12081 if Queuing_Policy /= ' '
12082 and then Queuing_Policy /= QP
12084 Error_Msg_Sloc := Queuing_Policy_Sloc;
12085 Error_Pragma ("queuing policy incompatible with policy#");
12087 -- Set new policy, but always preserve System_Location since we
12088 -- like the error message with the run time name.
12091 Queuing_Policy := QP;
12093 if Queuing_Policy_Sloc /= System_Location then
12094 Queuing_Policy_Sloc := Loc;
12099 -----------------------
12100 -- Relative_Deadline --
12101 -----------------------
12103 -- pragma Relative_Deadline (time_span_EXPRESSION);
12105 when Pragma_Relative_Deadline => Relative_Deadline : declare
12106 P : constant Node_Id := Parent (N);
12111 Check_No_Identifiers;
12112 Check_Arg_Count (1);
12114 Arg := Get_Pragma_Arg (Arg1);
12116 -- The expression must be analyzed in the special manner described
12117 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12119 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12123 if Nkind (P) = N_Subprogram_Body then
12124 Check_In_Main_Program;
12128 elsif Nkind (P) = N_Task_Definition then
12131 -- Anything else is incorrect
12137 if Has_Relative_Deadline_Pragma (P) then
12138 Error_Pragma ("duplicate pragma% not allowed");
12140 Set_Has_Relative_Deadline_Pragma (P, True);
12142 if Nkind (P) = N_Task_Definition then
12143 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12146 end Relative_Deadline;
12148 ---------------------------
12149 -- Remote_Call_Interface --
12150 ---------------------------
12152 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12154 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12155 Cunit_Node : Node_Id;
12156 Cunit_Ent : Entity_Id;
12160 Check_Ada_83_Warning;
12161 Check_Valid_Library_Unit_Pragma;
12163 if Nkind (N) = N_Null_Statement then
12167 Cunit_Node := Cunit (Current_Sem_Unit);
12168 K := Nkind (Unit (Cunit_Node));
12169 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12171 if K = N_Package_Declaration
12172 or else K = N_Generic_Package_Declaration
12173 or else K = N_Subprogram_Declaration
12174 or else K = N_Generic_Subprogram_Declaration
12175 or else (K = N_Subprogram_Body
12176 and then Acts_As_Spec (Unit (Cunit_Node)))
12181 "pragma% must apply to package or subprogram declaration");
12184 Set_Is_Remote_Call_Interface (Cunit_Ent);
12185 end Remote_Call_Interface;
12191 -- pragma Remote_Types [(library_unit_NAME)];
12193 when Pragma_Remote_Types => Remote_Types : declare
12194 Cunit_Node : Node_Id;
12195 Cunit_Ent : Entity_Id;
12198 Check_Ada_83_Warning;
12199 Check_Valid_Library_Unit_Pragma;
12201 if Nkind (N) = N_Null_Statement then
12205 Cunit_Node := Cunit (Current_Sem_Unit);
12206 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12208 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12209 N_Generic_Package_Declaration)
12212 ("pragma% can only apply to a package declaration");
12215 Set_Is_Remote_Types (Cunit_Ent);
12222 -- pragma Ravenscar;
12224 when Pragma_Ravenscar =>
12226 Check_Arg_Count (0);
12227 Check_Valid_Configuration_Pragma;
12228 Set_Ravenscar_Profile (N);
12230 if Warn_On_Obsolescent_Feature then
12231 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12232 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12235 -------------------------
12236 -- Restricted_Run_Time --
12237 -------------------------
12239 -- pragma Restricted_Run_Time;
12241 when Pragma_Restricted_Run_Time =>
12243 Check_Arg_Count (0);
12244 Check_Valid_Configuration_Pragma;
12245 Set_Profile_Restrictions
12246 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12248 if Warn_On_Obsolescent_Feature then
12250 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12251 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12258 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12261 -- restriction_IDENTIFIER
12262 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12264 when Pragma_Restrictions =>
12265 Process_Restrictions_Or_Restriction_Warnings
12266 (Warn => Treat_Restrictions_As_Warnings);
12268 --------------------------
12269 -- Restriction_Warnings --
12270 --------------------------
12272 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12275 -- restriction_IDENTIFIER
12276 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12278 when Pragma_Restriction_Warnings =>
12280 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12286 -- pragma Reviewable;
12288 when Pragma_Reviewable =>
12289 Check_Ada_83_Warning;
12290 Check_Arg_Count (0);
12292 -- Call dummy debugging function rv. This is done to assist front
12293 -- end debugging. By placing a Reviewable pragma in the source
12294 -- program, a breakpoint on rv catches this place in the source,
12295 -- allowing convenient stepping to the point of interest.
12299 --------------------------
12300 -- Short_Circuit_And_Or --
12301 --------------------------
12303 when Pragma_Short_Circuit_And_Or =>
12305 Check_Arg_Count (0);
12306 Check_Valid_Configuration_Pragma;
12307 Short_Circuit_And_Or := True;
12309 -------------------
12310 -- Share_Generic --
12311 -------------------
12313 -- pragma Share_Generic (NAME {, NAME});
12315 when Pragma_Share_Generic =>
12317 Process_Generic_List;
12323 -- pragma Shared (LOCAL_NAME);
12325 when Pragma_Shared =>
12327 Process_Atomic_Shared_Volatile;
12329 --------------------
12330 -- Shared_Passive --
12331 --------------------
12333 -- pragma Shared_Passive [(library_unit_NAME)];
12335 -- Set the flag Is_Shared_Passive of program unit name entity
12337 when Pragma_Shared_Passive => Shared_Passive : declare
12338 Cunit_Node : Node_Id;
12339 Cunit_Ent : Entity_Id;
12342 Check_Ada_83_Warning;
12343 Check_Valid_Library_Unit_Pragma;
12345 if Nkind (N) = N_Null_Statement then
12349 Cunit_Node := Cunit (Current_Sem_Unit);
12350 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12352 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12353 N_Generic_Package_Declaration)
12356 ("pragma% can only apply to a package declaration");
12359 Set_Is_Shared_Passive (Cunit_Ent);
12360 end Shared_Passive;
12362 -----------------------
12363 -- Short_Descriptors --
12364 -----------------------
12366 -- pragma Short_Descriptors;
12368 when Pragma_Short_Descriptors =>
12370 Check_Arg_Count (0);
12371 Check_Valid_Configuration_Pragma;
12372 Short_Descriptors := True;
12374 ----------------------
12375 -- Source_File_Name --
12376 ----------------------
12378 -- There are five forms for this pragma:
12380 -- pragma Source_File_Name (
12381 -- [UNIT_NAME =>] unit_NAME,
12382 -- BODY_FILE_NAME => STRING_LITERAL
12383 -- [, [INDEX =>] INTEGER_LITERAL]);
12385 -- pragma Source_File_Name (
12386 -- [UNIT_NAME =>] unit_NAME,
12387 -- SPEC_FILE_NAME => STRING_LITERAL
12388 -- [, [INDEX =>] INTEGER_LITERAL]);
12390 -- pragma Source_File_Name (
12391 -- BODY_FILE_NAME => STRING_LITERAL
12392 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12393 -- [, CASING => CASING_SPEC]);
12395 -- pragma Source_File_Name (
12396 -- SPEC_FILE_NAME => STRING_LITERAL
12397 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12398 -- [, CASING => CASING_SPEC]);
12400 -- pragma Source_File_Name (
12401 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12402 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12403 -- [, CASING => CASING_SPEC]);
12405 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12407 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12408 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12409 -- only be used when no project file is used, while SFNP can only be
12410 -- used when a project file is used.
12412 -- No processing here. Processing was completed during parsing, since
12413 -- we need to have file names set as early as possible. Units are
12414 -- loaded well before semantic processing starts.
12416 -- The only processing we defer to this point is the check for
12417 -- correct placement.
12419 when Pragma_Source_File_Name =>
12421 Check_Valid_Configuration_Pragma;
12423 ------------------------------
12424 -- Source_File_Name_Project --
12425 ------------------------------
12427 -- See Source_File_Name for syntax
12429 -- No processing here. Processing was completed during parsing, since
12430 -- we need to have file names set as early as possible. Units are
12431 -- loaded well before semantic processing starts.
12433 -- The only processing we defer to this point is the check for
12434 -- correct placement.
12436 when Pragma_Source_File_Name_Project =>
12438 Check_Valid_Configuration_Pragma;
12440 -- Check that a pragma Source_File_Name_Project is used only in a
12441 -- configuration pragmas file.
12443 -- Pragmas Source_File_Name_Project should only be generated by
12444 -- the Project Manager in configuration pragmas files.
12446 -- This is really an ugly test. It seems to depend on some
12447 -- accidental and undocumented property. At the very least it
12448 -- needs to be documented, but it would be better to have a
12449 -- clean way of testing if we are in a configuration file???
12451 if Present (Parent (N)) then
12453 ("pragma% can only appear in a configuration pragmas file");
12456 ----------------------
12457 -- Source_Reference --
12458 ----------------------
12460 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12462 -- Nothing to do, all processing completed in Par.Prag, since we need
12463 -- the information for possible parser messages that are output.
12465 when Pragma_Source_Reference =>
12468 --------------------------------
12469 -- Static_Elaboration_Desired --
12470 --------------------------------
12472 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12474 when Pragma_Static_Elaboration_Desired =>
12476 Check_At_Most_N_Arguments (1);
12478 if Is_Compilation_Unit (Current_Scope)
12479 and then Ekind (Current_Scope) = E_Package
12481 Set_Static_Elaboration_Desired (Current_Scope, True);
12483 Error_Pragma ("pragma% must apply to a library-level package");
12490 -- pragma Storage_Size (EXPRESSION);
12492 when Pragma_Storage_Size => Storage_Size : declare
12493 P : constant Node_Id := Parent (N);
12497 Check_No_Identifiers;
12498 Check_Arg_Count (1);
12500 -- The expression must be analyzed in the special manner described
12501 -- in "Handling of Default Expressions" in sem.ads.
12503 Arg := Get_Pragma_Arg (Arg1);
12504 Preanalyze_Spec_Expression (Arg, Any_Integer);
12506 if not Is_Static_Expression (Arg) then
12507 Check_Restriction (Static_Storage_Size, Arg);
12510 if Nkind (P) /= N_Task_Definition then
12515 if Has_Storage_Size_Pragma (P) then
12516 Error_Pragma ("duplicate pragma% not allowed");
12518 Set_Has_Storage_Size_Pragma (P, True);
12521 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12522 -- ??? exp_ch9 should use this!
12530 -- pragma Storage_Unit (NUMERIC_LITERAL);
12532 -- Only permitted argument is System'Storage_Unit value
12534 when Pragma_Storage_Unit =>
12535 Check_No_Identifiers;
12536 Check_Arg_Count (1);
12537 Check_Arg_Is_Integer_Literal (Arg1);
12539 if Intval (Get_Pragma_Arg (Arg1)) /=
12540 UI_From_Int (Ttypes.System_Storage_Unit)
12542 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12544 ("the only allowed argument for pragma% is ^", Arg1);
12547 --------------------
12548 -- Stream_Convert --
12549 --------------------
12551 -- pragma Stream_Convert (
12552 -- [Entity =>] type_LOCAL_NAME,
12553 -- [Read =>] function_NAME,
12554 -- [Write =>] function NAME);
12556 when Pragma_Stream_Convert => Stream_Convert : declare
12558 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12559 -- Check that the given argument is the name of a local function
12560 -- of one argument that is not overloaded earlier in the current
12561 -- local scope. A check is also made that the argument is a
12562 -- function with one parameter.
12564 --------------------------------------
12565 -- Check_OK_Stream_Convert_Function --
12566 --------------------------------------
12568 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12572 Check_Arg_Is_Local_Name (Arg);
12573 Ent := Entity (Get_Pragma_Arg (Arg));
12575 if Has_Homonym (Ent) then
12577 ("argument for pragma% may not be overloaded", Arg);
12580 if Ekind (Ent) /= E_Function
12581 or else No (First_Formal (Ent))
12582 or else Present (Next_Formal (First_Formal (Ent)))
12585 ("argument for pragma% must be" &
12586 " function of one argument", Arg);
12588 end Check_OK_Stream_Convert_Function;
12590 -- Start of processing for Stream_Convert
12594 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12595 Check_Arg_Count (3);
12596 Check_Optional_Identifier (Arg1, Name_Entity);
12597 Check_Optional_Identifier (Arg2, Name_Read);
12598 Check_Optional_Identifier (Arg3, Name_Write);
12599 Check_Arg_Is_Local_Name (Arg1);
12600 Check_OK_Stream_Convert_Function (Arg2);
12601 Check_OK_Stream_Convert_Function (Arg3);
12604 Typ : constant Entity_Id :=
12605 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12606 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12607 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12610 Check_First_Subtype (Arg1);
12612 -- Check for too early or too late. Note that we don't enforce
12613 -- the rule about primitive operations in this case, since, as
12614 -- is the case for explicit stream attributes themselves, these
12615 -- restrictions are not appropriate. Note that the chaining of
12616 -- the pragma by Rep_Item_Too_Late is actually the critical
12617 -- processing done for this pragma.
12619 if Rep_Item_Too_Early (Typ, N)
12621 Rep_Item_Too_Late (Typ, N, FOnly => True)
12626 -- Return if previous error
12628 if Etype (Typ) = Any_Type
12630 Etype (Read) = Any_Type
12632 Etype (Write) = Any_Type
12639 if Underlying_Type (Etype (Read)) /= Typ then
12641 ("incorrect return type for function&", Arg2);
12644 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12646 ("incorrect parameter type for function&", Arg3);
12649 if Underlying_Type (Etype (First_Formal (Read))) /=
12650 Underlying_Type (Etype (Write))
12653 ("result type of & does not match Read parameter type",
12657 end Stream_Convert;
12659 -------------------------
12660 -- Style_Checks (GNAT) --
12661 -------------------------
12663 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12665 -- This is processed by the parser since some of the style checks
12666 -- take place during source scanning and parsing. This means that
12667 -- we don't need to issue error messages here.
12669 when Pragma_Style_Checks => Style_Checks : declare
12670 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12676 Check_No_Identifiers;
12678 -- Two argument form
12680 if Arg_Count = 2 then
12681 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12688 E_Id := Get_Pragma_Arg (Arg2);
12691 if not Is_Entity_Name (E_Id) then
12693 ("second argument of pragma% must be entity name",
12697 E := Entity (E_Id);
12703 Set_Suppress_Style_Checks (E,
12704 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12705 exit when No (Homonym (E));
12711 -- One argument form
12714 Check_Arg_Count (1);
12716 if Nkind (A) = N_String_Literal then
12720 Slen : constant Natural := Natural (String_Length (S));
12721 Options : String (1 .. Slen);
12727 C := Get_String_Char (S, Int (J));
12728 exit when not In_Character_Range (C);
12729 Options (J) := Get_Character (C);
12731 -- If at end of string, set options. As per discussion
12732 -- above, no need to check for errors, since we issued
12733 -- them in the parser.
12736 Set_Style_Check_Options (Options);
12744 elsif Nkind (A) = N_Identifier then
12745 if Chars (A) = Name_All_Checks then
12747 Set_GNAT_Style_Check_Options;
12749 Set_Default_Style_Check_Options;
12752 elsif Chars (A) = Name_On then
12753 Style_Check := True;
12755 elsif Chars (A) = Name_Off then
12756 Style_Check := False;
12766 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12768 when Pragma_Subtitle =>
12770 Check_Arg_Count (1);
12771 Check_Optional_Identifier (Arg1, Name_Subtitle);
12772 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12779 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12781 when Pragma_Suppress =>
12782 Process_Suppress_Unsuppress (True);
12788 -- pragma Suppress_All;
12790 -- The only check made here is that the pragma has no arguments.
12791 -- There are no placement rules, and the processing required (setting
12792 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12793 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12794 -- then creates and inserts a pragma Suppress (All_Checks).
12796 when Pragma_Suppress_All =>
12798 Check_Arg_Count (0);
12800 -------------------------
12801 -- Suppress_Debug_Info --
12802 -------------------------
12804 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12806 when Pragma_Suppress_Debug_Info =>
12808 Check_Arg_Count (1);
12809 Check_Optional_Identifier (Arg1, Name_Entity);
12810 Check_Arg_Is_Local_Name (Arg1);
12811 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
12813 ----------------------------------
12814 -- Suppress_Exception_Locations --
12815 ----------------------------------
12817 -- pragma Suppress_Exception_Locations;
12819 when Pragma_Suppress_Exception_Locations =>
12821 Check_Arg_Count (0);
12822 Check_Valid_Configuration_Pragma;
12823 Exception_Locations_Suppressed := True;
12825 -----------------------------
12826 -- Suppress_Initialization --
12827 -----------------------------
12829 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12831 when Pragma_Suppress_Initialization => Suppress_Init : declare
12837 Check_Arg_Count (1);
12838 Check_Optional_Identifier (Arg1, Name_Entity);
12839 Check_Arg_Is_Local_Name (Arg1);
12841 E_Id := Get_Pragma_Arg (Arg1);
12843 if Etype (E_Id) = Any_Type then
12847 E := Entity (E_Id);
12849 if Is_Type (E) then
12850 if Is_Incomplete_Or_Private_Type (E) then
12851 if No (Full_View (Base_Type (E))) then
12853 ("argument of pragma% cannot be an incomplete type",
12856 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12859 Set_Suppress_Init_Proc (Base_Type (E));
12864 ("pragma% requires argument that is a type name", Arg1);
12872 -- pragma System_Name (DIRECT_NAME);
12874 -- Syntax check: one argument, which must be the identifier GNAT or
12875 -- the identifier GCC, no other identifiers are acceptable.
12877 when Pragma_System_Name =>
12879 Check_No_Identifiers;
12880 Check_Arg_Count (1);
12881 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12883 -----------------------------
12884 -- Task_Dispatching_Policy --
12885 -----------------------------
12887 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12889 when Pragma_Task_Dispatching_Policy => declare
12893 Check_Ada_83_Warning;
12894 Check_Arg_Count (1);
12895 Check_No_Identifiers;
12896 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12897 Check_Valid_Configuration_Pragma;
12898 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12899 DP := Fold_Upper (Name_Buffer (1));
12901 if Task_Dispatching_Policy /= ' '
12902 and then Task_Dispatching_Policy /= DP
12904 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12906 ("task dispatching policy incompatible with policy#");
12908 -- Set new policy, but always preserve System_Location since we
12909 -- like the error message with the run time name.
12912 Task_Dispatching_Policy := DP;
12914 if Task_Dispatching_Policy_Sloc /= System_Location then
12915 Task_Dispatching_Policy_Sloc := Loc;
12924 -- pragma Task_Info (EXPRESSION);
12926 when Pragma_Task_Info => Task_Info : declare
12927 P : constant Node_Id := Parent (N);
12932 if Nkind (P) /= N_Task_Definition then
12933 Error_Pragma ("pragma% must appear in task definition");
12936 Check_No_Identifiers;
12937 Check_Arg_Count (1);
12939 Analyze_And_Resolve
12940 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12942 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12946 if Has_Task_Info_Pragma (P) then
12947 Error_Pragma ("duplicate pragma% not allowed");
12949 Set_Has_Task_Info_Pragma (P, True);
12957 -- pragma Task_Name (string_EXPRESSION);
12959 when Pragma_Task_Name => Task_Name : declare
12960 P : constant Node_Id := Parent (N);
12964 Check_No_Identifiers;
12965 Check_Arg_Count (1);
12967 Arg := Get_Pragma_Arg (Arg1);
12969 -- The expression is used in the call to Create_Task, and must be
12970 -- expanded there, not in the context of the current spec. It must
12971 -- however be analyzed to capture global references, in case it
12972 -- appears in a generic context.
12974 Preanalyze_And_Resolve (Arg, Standard_String);
12976 if Nkind (P) /= N_Task_Definition then
12980 if Has_Task_Name_Pragma (P) then
12981 Error_Pragma ("duplicate pragma% not allowed");
12983 Set_Has_Task_Name_Pragma (P, True);
12984 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12992 -- pragma Task_Storage (
12993 -- [Task_Type =>] LOCAL_NAME,
12994 -- [Top_Guard =>] static_integer_EXPRESSION);
12996 when Pragma_Task_Storage => Task_Storage : declare
12997 Args : Args_List (1 .. 2);
12998 Names : constant Name_List (1 .. 2) := (
13002 Task_Type : Node_Id renames Args (1);
13003 Top_Guard : Node_Id renames Args (2);
13009 Gather_Associations (Names, Args);
13011 if No (Task_Type) then
13013 ("missing task_type argument for pragma%");
13016 Check_Arg_Is_Local_Name (Task_Type);
13018 Ent := Entity (Task_Type);
13020 if not Is_Task_Type (Ent) then
13022 ("argument for pragma% must be task type", Task_Type);
13025 if No (Top_Guard) then
13027 ("pragma% takes two arguments", Task_Type);
13029 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13032 Check_First_Subtype (Task_Type);
13034 if Rep_Item_Too_Late (Ent, N) then
13039 --------------------------
13040 -- Thread_Local_Storage --
13041 --------------------------
13043 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13045 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13051 Check_Arg_Count (1);
13052 Check_Optional_Identifier (Arg1, Name_Entity);
13053 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13055 Id := Get_Pragma_Arg (Arg1);
13058 if not Is_Entity_Name (Id)
13059 or else Ekind (Entity (Id)) /= E_Variable
13061 Error_Pragma_Arg ("local variable name required", Arg1);
13066 if Rep_Item_Too_Early (E, N)
13067 or else Rep_Item_Too_Late (E, N)
13072 Set_Has_Pragma_Thread_Local_Storage (E);
13073 Set_Has_Gigi_Rep_Item (E);
13074 end Thread_Local_Storage;
13080 -- pragma Time_Slice (static_duration_EXPRESSION);
13082 when Pragma_Time_Slice => Time_Slice : declare
13088 Check_Arg_Count (1);
13089 Check_No_Identifiers;
13090 Check_In_Main_Program;
13091 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13093 if not Error_Posted (Arg1) then
13095 while Present (Nod) loop
13096 if Nkind (Nod) = N_Pragma
13097 and then Pragma_Name (Nod) = Name_Time_Slice
13099 Error_Msg_Name_1 := Pname;
13100 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13107 -- Process only if in main unit
13109 if Get_Source_Unit (Loc) = Main_Unit then
13110 Opt.Time_Slice_Set := True;
13111 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13113 if Val <= Ureal_0 then
13114 Opt.Time_Slice_Value := 0;
13116 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13117 Opt.Time_Slice_Value := 1_000_000_000;
13120 Opt.Time_Slice_Value :=
13121 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13130 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13132 -- TITLING_OPTION ::=
13133 -- [Title =>] STRING_LITERAL
13134 -- | [Subtitle =>] STRING_LITERAL
13136 when Pragma_Title => Title : declare
13137 Args : Args_List (1 .. 2);
13138 Names : constant Name_List (1 .. 2) := (
13144 Gather_Associations (Names, Args);
13147 for J in 1 .. 2 loop
13148 if Present (Args (J)) then
13149 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13154 ---------------------
13155 -- Unchecked_Union --
13156 ---------------------
13158 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13160 when Pragma_Unchecked_Union => Unchecked_Union : declare
13161 Assoc : constant Node_Id := Arg1;
13162 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13173 Check_No_Identifiers;
13174 Check_Arg_Count (1);
13175 Check_Arg_Is_Local_Name (Arg1);
13177 Find_Type (Type_Id);
13178 Typ := Entity (Type_Id);
13181 or else Rep_Item_Too_Early (Typ, N)
13185 Typ := Underlying_Type (Typ);
13188 if Rep_Item_Too_Late (Typ, N) then
13192 Check_First_Subtype (Arg1);
13194 -- Note remaining cases are references to a type in the current
13195 -- declarative part. If we find an error, we post the error on
13196 -- the relevant type declaration at an appropriate point.
13198 if not Is_Record_Type (Typ) then
13199 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13202 elsif Is_Tagged_Type (Typ) then
13203 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13206 elsif Is_Limited_Type (Typ) then
13208 ("Unchecked_Union must not be limited record type", Typ);
13209 Explain_Limited_Type (Typ, Typ);
13213 if not Has_Discriminants (Typ) then
13215 ("Unchecked_Union must have one discriminant", Typ);
13219 Discr := First_Discriminant (Typ);
13220 while Present (Discr) loop
13221 if No (Discriminant_Default_Value (Discr)) then
13223 ("Unchecked_Union discriminant must have default value",
13227 Next_Discriminant (Discr);
13230 Tdef := Type_Definition (Declaration_Node (Typ));
13231 Clist := Component_List (Tdef);
13233 Comp := First (Component_Items (Clist));
13234 while Present (Comp) loop
13235 Check_Component (Comp, Typ);
13239 if No (Clist) or else No (Variant_Part (Clist)) then
13241 ("Unchecked_Union must have variant part",
13246 Vpart := Variant_Part (Clist);
13248 Variant := First (Variants (Vpart));
13249 while Present (Variant) loop
13250 Check_Variant (Variant, Typ);
13255 Set_Is_Unchecked_Union (Typ);
13256 Set_Convention (Typ, Convention_C);
13257 Set_Has_Unchecked_Union (Base_Type (Typ));
13258 Set_Is_Unchecked_Union (Base_Type (Typ));
13259 end Unchecked_Union;
13261 ------------------------
13262 -- Unimplemented_Unit --
13263 ------------------------
13265 -- pragma Unimplemented_Unit;
13267 -- Note: this only gives an error if we are generating code, or if
13268 -- we are in a generic library unit (where the pragma appears in the
13269 -- body, not in the spec).
13271 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13272 Cunitent : constant Entity_Id :=
13273 Cunit_Entity (Get_Source_Unit (Loc));
13274 Ent_Kind : constant Entity_Kind :=
13279 Check_Arg_Count (0);
13281 if Operating_Mode = Generate_Code
13282 or else Ent_Kind = E_Generic_Function
13283 or else Ent_Kind = E_Generic_Procedure
13284 or else Ent_Kind = E_Generic_Package
13286 Get_Name_String (Chars (Cunitent));
13287 Set_Casing (Mixed_Case);
13288 Write_Str (Name_Buffer (1 .. Name_Len));
13289 Write_Str (" is not supported in this configuration");
13291 raise Unrecoverable_Error;
13293 end Unimplemented_Unit;
13295 ------------------------
13296 -- Universal_Aliasing --
13297 ------------------------
13299 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13301 when Pragma_Universal_Aliasing => Universal_Alias : declare
13306 Check_Arg_Count (1);
13307 Check_Optional_Identifier (Arg2, Name_Entity);
13308 Check_Arg_Is_Local_Name (Arg1);
13309 E_Id := Entity (Get_Pragma_Arg (Arg1));
13311 if E_Id = Any_Type then
13313 elsif No (E_Id) or else not Is_Type (E_Id) then
13314 Error_Pragma_Arg ("pragma% requires type", Arg1);
13317 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13318 end Universal_Alias;
13320 --------------------
13321 -- Universal_Data --
13322 --------------------
13324 -- pragma Universal_Data [(library_unit_NAME)];
13326 when Pragma_Universal_Data =>
13329 -- If this is a configuration pragma, then set the universal
13330 -- addressing option, otherwise confirm that the pragma satisfies
13331 -- the requirements of library unit pragma placement and leave it
13332 -- to the GNAAMP back end to detect the pragma (avoids transitive
13333 -- setting of the option due to withed units).
13335 if Is_Configuration_Pragma then
13336 Universal_Addressing_On_AAMP := True;
13338 Check_Valid_Library_Unit_Pragma;
13341 if not AAMP_On_Target then
13342 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13349 -- pragma Unmodified (local_Name {, local_Name});
13351 when Pragma_Unmodified => Unmodified : declare
13352 Arg_Node : Node_Id;
13353 Arg_Expr : Node_Id;
13354 Arg_Ent : Entity_Id;
13358 Check_At_Least_N_Arguments (1);
13360 -- Loop through arguments
13363 while Present (Arg_Node) loop
13364 Check_No_Identifier (Arg_Node);
13366 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13367 -- in fact generate reference, so that the entity will have a
13368 -- reference, which will inhibit any warnings about it not
13369 -- being referenced, and also properly show up in the ali file
13370 -- as a reference. But this reference is recorded before the
13371 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13372 -- generated for this reference.
13374 Check_Arg_Is_Local_Name (Arg_Node);
13375 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13377 if Is_Entity_Name (Arg_Expr) then
13378 Arg_Ent := Entity (Arg_Expr);
13380 if not Is_Assignable (Arg_Ent) then
13382 ("pragma% can only be applied to a variable",
13385 Set_Has_Pragma_Unmodified (Arg_Ent);
13397 -- pragma Unreferenced (local_Name {, local_Name});
13399 -- or when used in a context clause:
13401 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13403 when Pragma_Unreferenced => Unreferenced : declare
13404 Arg_Node : Node_Id;
13405 Arg_Expr : Node_Id;
13406 Arg_Ent : Entity_Id;
13411 Check_At_Least_N_Arguments (1);
13413 -- Check case of appearing within context clause
13415 if Is_In_Context_Clause then
13417 -- The arguments must all be units mentioned in a with clause
13418 -- in the same context clause. Note we already checked (in
13419 -- Par.Prag) that the arguments are either identifiers or
13420 -- selected components.
13423 while Present (Arg_Node) loop
13424 Citem := First (List_Containing (N));
13425 while Citem /= N loop
13426 if Nkind (Citem) = N_With_Clause
13428 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13430 Set_Has_Pragma_Unreferenced
13433 (Library_Unit (Citem))));
13435 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13444 ("argument of pragma% is not with'ed unit", Arg_Node);
13450 -- Case of not in list of context items
13454 while Present (Arg_Node) loop
13455 Check_No_Identifier (Arg_Node);
13457 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13458 -- will in fact generate reference, so that the entity will
13459 -- have a reference, which will inhibit any warnings about
13460 -- it not being referenced, and also properly show up in the
13461 -- ali file as a reference. But this reference is recorded
13462 -- before the Has_Pragma_Unreferenced flag is set, so that
13463 -- no warning is generated for this reference.
13465 Check_Arg_Is_Local_Name (Arg_Node);
13466 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13468 if Is_Entity_Name (Arg_Expr) then
13469 Arg_Ent := Entity (Arg_Expr);
13471 -- If the entity is overloaded, the pragma applies to the
13472 -- most recent overloading, as documented. In this case,
13473 -- name resolution does not generate a reference, so it
13474 -- must be done here explicitly.
13476 if Is_Overloaded (Arg_Expr) then
13477 Generate_Reference (Arg_Ent, N);
13480 Set_Has_Pragma_Unreferenced (Arg_Ent);
13488 --------------------------
13489 -- Unreferenced_Objects --
13490 --------------------------
13492 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13494 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13495 Arg_Node : Node_Id;
13496 Arg_Expr : Node_Id;
13500 Check_At_Least_N_Arguments (1);
13503 while Present (Arg_Node) loop
13504 Check_No_Identifier (Arg_Node);
13505 Check_Arg_Is_Local_Name (Arg_Node);
13506 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13508 if not Is_Entity_Name (Arg_Expr)
13509 or else not Is_Type (Entity (Arg_Expr))
13512 ("argument for pragma% must be type or subtype", Arg_Node);
13515 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13518 end Unreferenced_Objects;
13520 ------------------------------
13521 -- Unreserve_All_Interrupts --
13522 ------------------------------
13524 -- pragma Unreserve_All_Interrupts;
13526 when Pragma_Unreserve_All_Interrupts =>
13528 Check_Arg_Count (0);
13530 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13531 Unreserve_All_Interrupts := True;
13538 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13540 when Pragma_Unsuppress =>
13542 Process_Suppress_Unsuppress (False);
13544 -------------------
13545 -- Use_VADS_Size --
13546 -------------------
13548 -- pragma Use_VADS_Size;
13550 when Pragma_Use_VADS_Size =>
13552 Check_Arg_Count (0);
13553 Check_Valid_Configuration_Pragma;
13554 Use_VADS_Size := True;
13556 ---------------------
13557 -- Validity_Checks --
13558 ---------------------
13560 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13562 when Pragma_Validity_Checks => Validity_Checks : declare
13563 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13569 Check_Arg_Count (1);
13570 Check_No_Identifiers;
13572 if Nkind (A) = N_String_Literal then
13576 Slen : constant Natural := Natural (String_Length (S));
13577 Options : String (1 .. Slen);
13583 C := Get_String_Char (S, Int (J));
13584 exit when not In_Character_Range (C);
13585 Options (J) := Get_Character (C);
13588 Set_Validity_Check_Options (Options);
13596 elsif Nkind (A) = N_Identifier then
13598 if Chars (A) = Name_All_Checks then
13599 Set_Validity_Check_Options ("a");
13601 elsif Chars (A) = Name_On then
13602 Validity_Checks_On := True;
13604 elsif Chars (A) = Name_Off then
13605 Validity_Checks_On := False;
13609 end Validity_Checks;
13615 -- pragma Volatile (LOCAL_NAME);
13617 when Pragma_Volatile =>
13618 Process_Atomic_Shared_Volatile;
13620 -------------------------
13621 -- Volatile_Components --
13622 -------------------------
13624 -- pragma Volatile_Components (array_LOCAL_NAME);
13626 -- Volatile is handled by the same circuit as Atomic_Components
13632 -- pragma Warnings (On | Off);
13633 -- pragma Warnings (On | Off, LOCAL_NAME);
13634 -- pragma Warnings (static_string_EXPRESSION);
13635 -- pragma Warnings (On | Off, STRING_LITERAL);
13637 when Pragma_Warnings => Warnings : begin
13639 Check_At_Least_N_Arguments (1);
13640 Check_No_Identifiers;
13642 -- If debug flag -gnatd.i is set, pragma is ignored
13644 if Debug_Flag_Dot_I then
13648 -- Process various forms of the pragma
13651 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13654 -- One argument case
13656 if Arg_Count = 1 then
13658 -- On/Off one argument case was processed by parser
13660 if Nkind (Argx) = N_Identifier
13662 (Chars (Argx) = Name_On
13664 Chars (Argx) = Name_Off)
13668 -- One argument case must be ON/OFF or static string expr
13670 elsif not Is_Static_String_Expression (Arg1) then
13672 ("argument of pragma% must be On/Off or " &
13673 "static string expression", Arg1);
13675 -- One argument string expression case
13679 Lit : constant Node_Id := Expr_Value_S (Argx);
13680 Str : constant String_Id := Strval (Lit);
13681 Len : constant Nat := String_Length (Str);
13689 while J <= Len loop
13690 C := Get_String_Char (Str, J);
13691 OK := In_Character_Range (C);
13694 Chr := Get_Character (C);
13698 if J < Len and then Chr = '.' then
13700 C := Get_String_Char (Str, J);
13701 Chr := Get_Character (C);
13703 if not Set_Dot_Warning_Switch (Chr) then
13705 ("invalid warning switch character " &
13712 OK := Set_Warning_Switch (Chr);
13718 ("invalid warning switch character " & Chr,
13727 -- Two or more arguments (must be two)
13730 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13731 Check_At_Most_N_Arguments (2);
13739 E_Id := Get_Pragma_Arg (Arg2);
13742 -- In the expansion of an inlined body, a reference to
13743 -- the formal may be wrapped in a conversion if the
13744 -- actual is a conversion. Retrieve the real entity name.
13746 if (In_Instance_Body
13747 or else In_Inlined_Body)
13748 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13750 E_Id := Expression (E_Id);
13753 -- Entity name case
13755 if Is_Entity_Name (E_Id) then
13756 E := Entity (E_Id);
13763 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13766 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13767 and then Warn_On_Warnings_Off
13769 Warnings_Off_Pragmas.Append ((N, E));
13772 if Is_Enumeration_Type (E) then
13776 Lit := First_Literal (E);
13777 while Present (Lit) loop
13778 Set_Warnings_Off (Lit);
13779 Next_Literal (Lit);
13784 exit when No (Homonym (E));
13789 -- Error if not entity or static string literal case
13791 elsif not Is_Static_String_Expression (Arg2) then
13793 ("second argument of pragma% must be entity " &
13794 "name or static string expression", Arg2);
13796 -- String literal case
13799 String_To_Name_Buffer
13800 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13802 -- Note on configuration pragma case: If this is a
13803 -- configuration pragma, then for an OFF pragma, we
13804 -- just set Config True in the call, which is all
13805 -- that needs to be done. For the case of ON, this
13806 -- is normally an error, unless it is canceling the
13807 -- effect of a previous OFF pragma in the same file.
13808 -- In any other case, an error will be signalled (ON
13809 -- with no matching OFF).
13811 if Chars (Argx) = Name_Off then
13812 Set_Specific_Warning_Off
13813 (Loc, Name_Buffer (1 .. Name_Len),
13814 Config => Is_Configuration_Pragma);
13816 elsif Chars (Argx) = Name_On then
13817 Set_Specific_Warning_On
13818 (Loc, Name_Buffer (1 .. Name_Len), Err);
13822 ("?pragma Warnings On with no " &
13823 "matching Warnings Off",
13833 -------------------
13834 -- Weak_External --
13835 -------------------
13837 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13839 when Pragma_Weak_External => Weak_External : declare
13844 Check_Arg_Count (1);
13845 Check_Optional_Identifier (Arg1, Name_Entity);
13846 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13847 Ent := Entity (Get_Pragma_Arg (Arg1));
13849 if Rep_Item_Too_Early (Ent, N) then
13852 Ent := Underlying_Type (Ent);
13855 -- The only processing required is to link this item on to the
13856 -- list of rep items for the given entity. This is accomplished
13857 -- by the call to Rep_Item_Too_Late (when no error is detected
13858 -- and False is returned).
13860 if Rep_Item_Too_Late (Ent, N) then
13863 Set_Has_Gigi_Rep_Item (Ent);
13867 -----------------------------
13868 -- Wide_Character_Encoding --
13869 -----------------------------
13871 -- pragma Wide_Character_Encoding (IDENTIFIER);
13873 when Pragma_Wide_Character_Encoding =>
13876 -- Nothing to do, handled in parser. Note that we do not enforce
13877 -- configuration pragma placement, this pragma can appear at any
13878 -- place in the source, allowing mixed encodings within a single
13883 --------------------
13884 -- Unknown_Pragma --
13885 --------------------
13887 -- Should be impossible, since the case of an unknown pragma is
13888 -- separately processed before the case statement is entered.
13890 when Unknown_Pragma =>
13891 raise Program_Error;
13894 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13895 -- until AI is formally approved.
13897 -- Check_Order_Dependence;
13900 when Pragma_Exit => null;
13901 end Analyze_Pragma;
13903 -------------------
13904 -- Check_Enabled --
13905 -------------------
13907 function Check_Enabled (Nam : Name_Id) return Boolean is
13911 -- Loop through entries in check policy list
13913 PP := Opt.Check_Policy_List;
13915 -- If there are no specific entries that matched, then we let the
13916 -- setting of assertions govern. Note that this provides the needed
13917 -- compatibility with the RM for the cases of assertion, invariant,
13918 -- precondition, predicate, and postcondition.
13921 return Assertions_Enabled;
13923 -- Here we have an entry see if it matches
13927 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13930 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13931 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13932 when Name_On | Name_Check =>
13934 when Name_Off | Name_Ignore =>
13937 raise Program_Error;
13941 PP := Next_Pragma (PP);
13948 ---------------------------------
13949 -- Delay_Config_Pragma_Analyze --
13950 ---------------------------------
13952 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13954 return Pragma_Name (N) = Name_Interrupt_State
13956 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13957 end Delay_Config_Pragma_Analyze;
13959 -------------------------
13960 -- Get_Base_Subprogram --
13961 -------------------------
13963 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13964 Result : Entity_Id;
13967 -- Follow subprogram renaming chain
13970 while Is_Subprogram (Result)
13972 (Is_Generic_Instance (Result)
13973 or else Nkind (Parent (Declaration_Node (Result))) =
13974 N_Subprogram_Renaming_Declaration)
13975 and then Present (Alias (Result))
13977 Result := Alias (Result);
13981 end Get_Base_Subprogram;
13987 procedure Initialize is
13992 -----------------------------
13993 -- Is_Config_Static_String --
13994 -----------------------------
13996 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13998 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13999 -- This is an internal recursive function that is just like the outer
14000 -- function except that it adds the string to the name buffer rather
14001 -- than placing the string in the name buffer.
14003 ------------------------------
14004 -- Add_Config_Static_String --
14005 ------------------------------
14007 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14014 if Nkind (N) = N_Op_Concat then
14015 if Add_Config_Static_String (Left_Opnd (N)) then
14016 N := Right_Opnd (N);
14022 if Nkind (N) /= N_String_Literal then
14023 Error_Msg_N ("string literal expected for pragma argument", N);
14027 for J in 1 .. String_Length (Strval (N)) loop
14028 C := Get_String_Char (Strval (N), J);
14030 if not In_Character_Range (C) then
14032 ("string literal contains invalid wide character",
14033 Sloc (N) + 1 + Source_Ptr (J));
14037 Add_Char_To_Name_Buffer (Get_Character (C));
14042 end Add_Config_Static_String;
14044 -- Start of processing for Is_Config_Static_String
14049 return Add_Config_Static_String (Arg);
14050 end Is_Config_Static_String;
14052 -----------------------------------------
14053 -- Is_Non_Significant_Pragma_Reference --
14054 -----------------------------------------
14056 -- This function makes use of the following static table which indicates
14057 -- whether a given pragma is significant.
14059 -- -1 indicates that references in any argument position are significant
14060 -- 0 indicates that appearance in any argument is not significant
14061 -- +n indicates that appearance as argument n is significant, but all
14062 -- other arguments are not significant
14063 -- 99 special processing required (e.g. for pragma Check)
14065 Sig_Flags : constant array (Pragma_Id) of Int :=
14066 (Pragma_AST_Entry => -1,
14067 Pragma_Abort_Defer => -1,
14068 Pragma_Ada_83 => -1,
14069 Pragma_Ada_95 => -1,
14070 Pragma_Ada_05 => -1,
14071 Pragma_Ada_2005 => -1,
14072 Pragma_Ada_12 => -1,
14073 Pragma_Ada_2012 => -1,
14074 Pragma_All_Calls_Remote => -1,
14075 Pragma_Annotate => -1,
14076 Pragma_Assert => -1,
14077 Pragma_Assertion_Policy => 0,
14078 Pragma_Assume_No_Invalid_Values => 0,
14079 Pragma_Asynchronous => -1,
14080 Pragma_Atomic => 0,
14081 Pragma_Atomic_Components => 0,
14082 Pragma_Attach_Handler => -1,
14083 Pragma_Check => 99,
14084 Pragma_Check_Name => 0,
14085 Pragma_Check_Policy => 0,
14086 Pragma_CIL_Constructor => -1,
14087 Pragma_CPP_Class => 0,
14088 Pragma_CPP_Constructor => 0,
14089 Pragma_CPP_Virtual => 0,
14090 Pragma_CPP_Vtable => 0,
14092 Pragma_C_Pass_By_Copy => 0,
14093 Pragma_Comment => 0,
14094 Pragma_Common_Object => -1,
14095 Pragma_Compile_Time_Error => -1,
14096 Pragma_Compile_Time_Warning => -1,
14097 Pragma_Compiler_Unit => 0,
14098 Pragma_Complete_Representation => 0,
14099 Pragma_Complex_Representation => 0,
14100 Pragma_Component_Alignment => -1,
14101 Pragma_Controlled => 0,
14102 Pragma_Convention => 0,
14103 Pragma_Convention_Identifier => 0,
14104 Pragma_Debug => -1,
14105 Pragma_Debug_Policy => 0,
14106 Pragma_Default_Value => -1,
14107 Pragma_Default_Component_Value => -1,
14108 Pragma_Detect_Blocking => -1,
14109 Pragma_Default_Storage_Pool => -1,
14110 Pragma_Dimension => -1,
14111 Pragma_Discard_Names => 0,
14112 Pragma_Elaborate => -1,
14113 Pragma_Elaborate_All => -1,
14114 Pragma_Elaborate_Body => -1,
14115 Pragma_Elaboration_Checks => -1,
14116 Pragma_Eliminate => -1,
14117 Pragma_Export => -1,
14118 Pragma_Export_Exception => -1,
14119 Pragma_Export_Function => -1,
14120 Pragma_Export_Object => -1,
14121 Pragma_Export_Procedure => -1,
14122 Pragma_Export_Value => -1,
14123 Pragma_Export_Valued_Procedure => -1,
14124 Pragma_Extend_System => -1,
14125 Pragma_Extensions_Allowed => -1,
14126 Pragma_External => -1,
14127 Pragma_Favor_Top_Level => -1,
14128 Pragma_External_Name_Casing => -1,
14129 Pragma_Fast_Math => -1,
14130 Pragma_Finalize_Storage_Only => 0,
14131 Pragma_Float_Representation => 0,
14132 Pragma_Ident => -1,
14133 Pragma_Implemented => -1,
14134 Pragma_Implicit_Packing => 0,
14135 Pragma_Import => +2,
14136 Pragma_Import_Exception => 0,
14137 Pragma_Import_Function => 0,
14138 Pragma_Import_Object => 0,
14139 Pragma_Import_Procedure => 0,
14140 Pragma_Import_Valued_Procedure => 0,
14141 Pragma_Independent => 0,
14142 Pragma_Independent_Components => 0,
14143 Pragma_Initialize_Scalars => -1,
14144 Pragma_Inline => 0,
14145 Pragma_Inline_Always => 0,
14146 Pragma_Inline_Generic => 0,
14147 Pragma_Inspection_Point => -1,
14148 Pragma_Interface => +2,
14149 Pragma_Interface_Name => +2,
14150 Pragma_Interrupt_Handler => -1,
14151 Pragma_Interrupt_Priority => -1,
14152 Pragma_Interrupt_State => -1,
14153 Pragma_Invariant => -1,
14154 Pragma_Java_Constructor => -1,
14155 Pragma_Java_Interface => -1,
14156 Pragma_Keep_Names => 0,
14157 Pragma_License => -1,
14158 Pragma_Link_With => -1,
14159 Pragma_Linker_Alias => -1,
14160 Pragma_Linker_Constructor => -1,
14161 Pragma_Linker_Destructor => -1,
14162 Pragma_Linker_Options => -1,
14163 Pragma_Linker_Section => -1,
14165 Pragma_Locking_Policy => -1,
14166 Pragma_Long_Float => -1,
14167 Pragma_Machine_Attribute => -1,
14169 Pragma_Main_Storage => -1,
14170 Pragma_Memory_Size => -1,
14171 Pragma_No_Return => 0,
14172 Pragma_No_Body => 0,
14173 Pragma_No_Run_Time => -1,
14174 Pragma_No_Strict_Aliasing => -1,
14175 Pragma_Normalize_Scalars => -1,
14176 Pragma_Obsolescent => 0,
14177 Pragma_Optimize => -1,
14178 Pragma_Optimize_Alignment => -1,
14179 Pragma_Ordered => 0,
14182 Pragma_Passive => -1,
14183 Pragma_Preelaborable_Initialization => -1,
14184 Pragma_Polling => -1,
14185 Pragma_Persistent_BSS => 0,
14186 Pragma_Postcondition => -1,
14187 Pragma_Precondition => -1,
14188 Pragma_Predicate => -1,
14189 Pragma_Preelaborate => -1,
14190 Pragma_Preelaborate_05 => -1,
14191 Pragma_Priority => -1,
14192 Pragma_Priority_Specific_Dispatching => -1,
14193 Pragma_Profile => 0,
14194 Pragma_Profile_Warnings => 0,
14195 Pragma_Propagate_Exceptions => -1,
14196 Pragma_Psect_Object => -1,
14198 Pragma_Pure_05 => -1,
14199 Pragma_Pure_Function => -1,
14200 Pragma_Queuing_Policy => -1,
14201 Pragma_Ravenscar => -1,
14202 Pragma_Relative_Deadline => -1,
14203 Pragma_Remote_Call_Interface => -1,
14204 Pragma_Remote_Types => -1,
14205 Pragma_Restricted_Run_Time => -1,
14206 Pragma_Restriction_Warnings => -1,
14207 Pragma_Restrictions => -1,
14208 Pragma_Reviewable => -1,
14209 Pragma_Short_Circuit_And_Or => -1,
14210 Pragma_Share_Generic => -1,
14211 Pragma_Shared => -1,
14212 Pragma_Shared_Passive => -1,
14213 Pragma_Short_Descriptors => 0,
14214 Pragma_Source_File_Name => -1,
14215 Pragma_Source_File_Name_Project => -1,
14216 Pragma_Source_Reference => -1,
14217 Pragma_Storage_Size => -1,
14218 Pragma_Storage_Unit => -1,
14219 Pragma_Static_Elaboration_Desired => -1,
14220 Pragma_Stream_Convert => -1,
14221 Pragma_Style_Checks => -1,
14222 Pragma_Subtitle => -1,
14223 Pragma_Suppress => 0,
14224 Pragma_Suppress_Exception_Locations => 0,
14225 Pragma_Suppress_All => -1,
14226 Pragma_Suppress_Debug_Info => 0,
14227 Pragma_Suppress_Initialization => 0,
14228 Pragma_System_Name => -1,
14229 Pragma_Task_Dispatching_Policy => -1,
14230 Pragma_Task_Info => -1,
14231 Pragma_Task_Name => -1,
14232 Pragma_Task_Storage => 0,
14233 Pragma_Thread_Local_Storage => 0,
14234 Pragma_Time_Slice => -1,
14235 Pragma_Title => -1,
14236 Pragma_Unchecked_Union => 0,
14237 Pragma_Unimplemented_Unit => -1,
14238 Pragma_Universal_Aliasing => -1,
14239 Pragma_Universal_Data => -1,
14240 Pragma_Unmodified => -1,
14241 Pragma_Unreferenced => -1,
14242 Pragma_Unreferenced_Objects => -1,
14243 Pragma_Unreserve_All_Interrupts => -1,
14244 Pragma_Unsuppress => 0,
14245 Pragma_Use_VADS_Size => -1,
14246 Pragma_Validity_Checks => -1,
14247 Pragma_Volatile => 0,
14248 Pragma_Volatile_Components => 0,
14249 Pragma_Warnings => -1,
14250 Pragma_Weak_External => -1,
14251 Pragma_Wide_Character_Encoding => 0,
14252 Unknown_Pragma => 0);
14254 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14263 if Nkind (P) /= N_Pragma_Argument_Association then
14267 Id := Get_Pragma_Id (Parent (P));
14268 C := Sig_Flags (Id);
14280 -- For pragma Check, the first argument is not significant,
14281 -- the second and the third (if present) arguments are
14284 when Pragma_Check =>
14286 P = First (Pragma_Argument_Associations (Parent (P)));
14289 raise Program_Error;
14293 A := First (Pragma_Argument_Associations (Parent (P)));
14294 for J in 1 .. C - 1 loop
14302 return A = P; -- is this wrong way round ???
14305 end Is_Non_Significant_Pragma_Reference;
14307 ------------------------------
14308 -- Is_Pragma_String_Literal --
14309 ------------------------------
14311 -- This function returns true if the corresponding pragma argument is a
14312 -- static string expression. These are the only cases in which string
14313 -- literals can appear as pragma arguments. We also allow a string literal
14314 -- as the first argument to pragma Assert (although it will of course
14315 -- always generate a type error).
14317 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14318 Pragn : constant Node_Id := Parent (Par);
14319 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14320 Pname : constant Name_Id := Pragma_Name (Pragn);
14326 N := First (Assoc);
14333 if Pname = Name_Assert then
14336 elsif Pname = Name_Export then
14339 elsif Pname = Name_Ident then
14342 elsif Pname = Name_Import then
14345 elsif Pname = Name_Interface_Name then
14348 elsif Pname = Name_Linker_Alias then
14351 elsif Pname = Name_Linker_Section then
14354 elsif Pname = Name_Machine_Attribute then
14357 elsif Pname = Name_Source_File_Name then
14360 elsif Pname = Name_Source_Reference then
14363 elsif Pname = Name_Title then
14366 elsif Pname = Name_Subtitle then
14372 end Is_Pragma_String_Literal;
14374 --------------------------------------
14375 -- Process_Compilation_Unit_Pragmas --
14376 --------------------------------------
14378 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14380 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14381 -- strange because it comes at the end of the unit. Rational has the
14382 -- same name for a pragma, but treats it as a program unit pragma, In
14383 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14384 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14385 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14386 -- the context clause to ensure the correct processing.
14388 if Has_Pragma_Suppress_All (N) then
14389 Prepend_To (Context_Items (N),
14390 Make_Pragma (Sloc (N),
14391 Chars => Name_Suppress,
14392 Pragma_Argument_Associations => New_List (
14393 Make_Pragma_Argument_Association (Sloc (N),
14394 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14397 -- Nothing else to do at the current time!
14399 end Process_Compilation_Unit_Pragmas;
14410 --------------------------------
14411 -- Set_Encoded_Interface_Name --
14412 --------------------------------
14414 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14415 Str : constant String_Id := Strval (S);
14416 Len : constant Int := String_Length (Str);
14421 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14424 -- Stores encoded value of character code CC. The encoding we use an
14425 -- underscore followed by four lower case hex digits.
14431 procedure Encode is
14433 Store_String_Char (Get_Char_Code ('_'));
14435 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14437 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14439 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14441 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14444 -- Start of processing for Set_Encoded_Interface_Name
14447 -- If first character is asterisk, this is a link name, and we leave it
14448 -- completely unmodified. We also ignore null strings (the latter case
14449 -- happens only in error cases) and no encoding should occur for Java or
14450 -- AAMP interface names.
14453 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14454 or else VM_Target /= No_VM
14455 or else AAMP_On_Target
14457 Set_Interface_Name (E, S);
14462 CC := Get_String_Char (Str, J);
14464 exit when not In_Character_Range (CC);
14466 C := Get_Character (CC);
14468 exit when C /= '_' and then C /= '$'
14469 and then C not in '0' .. '9'
14470 and then C not in 'a' .. 'z'
14471 and then C not in 'A' .. 'Z';
14474 Set_Interface_Name (E, S);
14482 -- Here we need to encode. The encoding we use as follows:
14483 -- three underscores + four hex digits (lower case)
14487 for J in 1 .. String_Length (Str) loop
14488 CC := Get_String_Char (Str, J);
14490 if not In_Character_Range (CC) then
14493 C := Get_Character (CC);
14495 if C = '_' or else C = '$'
14496 or else C in '0' .. '9'
14497 or else C in 'a' .. 'z'
14498 or else C in 'A' .. 'Z'
14500 Store_String_Char (CC);
14507 Set_Interface_Name (E,
14508 Make_String_Literal (Sloc (S),
14509 Strval => End_String));
14511 end Set_Encoded_Interface_Name;
14513 -------------------
14514 -- Set_Unit_Name --
14515 -------------------
14517 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14522 if Nkind (N) = N_Identifier
14523 and then Nkind (With_Item) = N_Identifier
14525 Set_Entity (N, Entity (With_Item));
14527 elsif Nkind (N) = N_Selected_Component then
14528 Change_Selected_Component_To_Expanded_Name (N);
14529 Set_Entity (N, Entity (With_Item));
14530 Set_Entity (Selector_Name (N), Entity (N));
14532 Pref := Prefix (N);
14533 Scop := Scope (Entity (N));
14534 while Nkind (Pref) = N_Selected_Component loop
14535 Change_Selected_Component_To_Expanded_Name (Pref);
14536 Set_Entity (Selector_Name (Pref), Scop);
14537 Set_Entity (Pref, Scop);
14538 Pref := Prefix (Pref);
14539 Scop := Scope (Scop);
14542 Set_Entity (Pref, Scop);